-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[ctx_prof] API to get the instrumentation of a BB #105468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,4 +132,26 @@ TEST_F(CtxProfAnalysisTest, GetCallsiteIDNegativeTest) { | |
EXPECT_EQ(IndIns, nullptr); | ||
} | ||
|
||
TEST_F(CtxProfAnalysisTest, GetBBIDTest) { | ||
ModulePassManager MPM; | ||
MPM.addPass(PGOInstrumentationGen(PGOInstrumentationType::CTXPROF)); | ||
EXPECT_FALSE(MPM.run(*M, MAM).areAllPreserved()); | ||
auto *F = M->getFunction("foo"); | ||
ASSERT_NE(F, nullptr); | ||
std::map<std::string, int> BBNameAndID; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a test and doesn't matter much, but should we more carefully choose the container here? It doesn't seem like the iteration order matters, so something like |
||
|
||
for (auto &BB : *F) { | ||
auto *Ins = CtxProfAnalysis::getBBInstrumentation(BB); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly type this instruction? |
||
if (Ins) | ||
BBNameAndID[BB.getName().str()] = | ||
static_cast<int>(Ins->getIndex()->getZExtValue()); | ||
else | ||
BBNameAndID[BB.getName().str()] = -1; | ||
} | ||
|
||
EXPECT_THAT(BBNameAndID, | ||
testing::UnorderedElementsAre( | ||
testing::Pair("", 0), testing::Pair("yes", 1), | ||
testing::Pair("no", -1), testing::Pair("exit", -1))); | ||
} | ||
} // namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think explicitly typing
Instruction
would improve readability a bit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why, this is a typical iteration pattern for BBs (doing a very naive search though llvm/lib for either patterns - i.e.
for (auto &I : BB)
orfor (Instruction &I : BB)
reveals about the same nr of instances.