Skip to content

Commit 7605200

Browse files
committed
[profcheck] Exclude naked functions from profcheck
1 parent 9349a10 commit 7605200

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Transforms/Utils/ProfileVerify.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,26 @@ class ProfileInjector {
6565
ProfileInjector(Function &F, FunctionAnalysisManager &FAM) : F(F), FAM(FAM) {}
6666
bool inject();
6767
};
68+
69+
bool isAsmOnly(const Function &F) {
70+
if (!F.hasFnAttribute(Attribute::AttrKind::Naked))
71+
return false;
72+
for (const auto &BB : F)
73+
for (const auto &I : drop_end(BB.instructionsWithoutDebug())) {
74+
const auto *CB = dyn_cast<CallBase>(&I);
75+
if (!CB || !CB->isInlineAsm())
76+
return false;
77+
}
78+
return true;
79+
}
6880
} // namespace
6981

7082
// FIXME: currently this injects only for terminators. Select isn't yet
7183
// supported.
7284
bool ProfileInjector::inject() {
85+
// skip purely asm functions
86+
if (isAsmOnly(F))
87+
return false;
7388
// Get whatever branch probability info can be derived from the given IR -
7489
// whether it has or not metadata. The main intention for this pass is to
7590
// ensure that other passes don't drop or "forget" to update MD_prof. We do
@@ -176,6 +191,10 @@ PreservedAnalyses ProfileInjectorPass::run(Function &F,
176191

177192
PreservedAnalyses ProfileVerifierPass::run(Function &F,
178193
FunctionAnalysisManager &FAM) {
194+
// skip purely asm functions
195+
if (isAsmOnly(F))
196+
return PreservedAnalyses::all();
197+
179198
const auto EntryCount = F.getEntryCount(/*AllowSynthetic=*/true);
180199
if (!EntryCount) {
181200
auto *MD = F.getMetadata(LLVMContext::MD_prof);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: opt -passes=prof-inject %s -S -o - | FileCheck %s
2+
; RUN: opt -passes=prof-verify %s --disable-output
3+
4+
5+
define void @bar(i1 %c) #0 {
6+
ret void
7+
}
8+
9+
attributes #0 = { naked }
10+
; CHECK-NOT: !prof

0 commit comments

Comments
 (0)