Skip to content

Commit fe63669

Browse files
authored
[Instrumentation] Support MachineFunction in OptNoneInstrumentation (#115471)
Support `MachineFunction` in `OptNoneInstrumentation`, also add `isRequired` to all necessary passes.
1 parent b83399e commit fe63669

15 files changed

+38
-25
lines changed

llvm/include/llvm/CodeGen/FinalizeISel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace llvm {
1616
class FinalizeISelPass : public PassInfoMixin<FinalizeISelPass> {
1717
public:
1818
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
19+
static bool isRequired() { return true; }
1920
};
2021

2122
} // namespace llvm

llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class LocalStackSlotAllocationPass
1717
: public PassInfoMixin<LocalStackSlotAllocationPass> {
1818
public:
1919
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
20+
static bool isRequired() { return true; }
2021
};
2122

2223
} // namespace llvm

llvm/include/llvm/CodeGen/MIRPrinter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PrintMIRPreparePass : public PassInfoMixin<PrintMIRPreparePass> {
3131
public:
3232
PrintMIRPreparePass(raw_ostream &OS = errs()) : OS(OS) {}
3333
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM);
34+
static bool isRequired() { return true; }
3435
};
3536

3637
class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
@@ -40,6 +41,7 @@ class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
4041
PrintMIRPass(raw_ostream &OS = errs()) : OS(OS) {}
4142
PreservedAnalyses run(MachineFunction &MF,
4243
MachineFunctionAnalysisManager &MFAM);
44+
static bool isRequired() { return true; }
4345
};
4446

4547
/// Print LLVM IR using the MIR serialization format to the given output stream.

llvm/include/llvm/CodeGen/MachineVerifier.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MachineVerifierPass : public PassInfoMixin<MachineVerifierPass> {
2121
: Banner(Banner) {}
2222
PreservedAnalyses run(MachineFunction &MF,
2323
MachineFunctionAnalysisManager &MFAM);
24+
static bool isRequired() { return true; }
2425
};
2526

2627
} // namespace llvm

llvm/include/llvm/CodeGen/PHIElimination.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class PHIEliminationPass : public PassInfoMixin<PHIEliminationPass> {
1717
public:
1818
PreservedAnalyses run(MachineFunction &MF,
1919
MachineFunctionAnalysisManager &MFAM);
20+
static bool isRequired() { return true; }
2021
};
2122

2223
} // namespace llvm

llvm/include/llvm/CodeGen/RegAllocFast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class RegAllocFastPass : public PassInfoMixin<RegAllocFastPass> {
5050

5151
void printPipeline(raw_ostream &OS,
5252
function_ref<StringRef(StringRef)> MapClassName2PassName);
53+
54+
static bool isRequired() { return true; }
5355
};
5456

5557
} // namespace llvm

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ class SelectionDAGISelPass : public PassInfoMixin<SelectionDAGISelPass> {
551551
public:
552552
PreservedAnalyses run(MachineFunction &MF,
553553
MachineFunctionAnalysisManager &MFAM);
554+
static bool isRequired() { return true; }
554555
};
555556
}
556557

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,6 @@ bool EarlyIfConverter::run(MachineFunction &MF) {
11191119
PreservedAnalyses
11201120
EarlyIfConverterPass::run(MachineFunction &MF,
11211121
MachineFunctionAnalysisManager &MFAM) {
1122-
if (MF.getFunction().hasOptNone())
1123-
return PreservedAnalyses::all();
1124-
11251122
MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
11261123
MachineLoopInfo &LI = MFAM.getResult<MachineLoopAnalysis>(MF);
11271124
MachineTraceMetrics &MTM = MFAM.getResult<MachineTraceMetricsAnalysis>(MF);

llvm/lib/CodeGen/MachineCSE.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,6 @@ PreservedAnalyses MachineCSEPass::run(MachineFunction &MF,
957957
MachineFunctionAnalysisManager &MFAM) {
958958
MFPropsModifier _(*this, MF);
959959

960-
if (MF.getFunction().hasOptNone())
961-
return PreservedAnalyses::all();
962-
963960
MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
964961
MachineBlockFrequencyInfo &MBFI =
965962
MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,6 @@ bool MachineLICMImpl::isTgtHotterThanSrc(MachineBasicBlock *SrcBlock,
17641764
template <typename DerivedT, bool PreRegAlloc>
17651765
PreservedAnalyses MachineLICMBasePass<DerivedT, PreRegAlloc>::run(
17661766
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
1767-
if (MF.getFunction().hasOptNone())
1768-
return PreservedAnalyses::all();
1769-
17701767
bool Changed = MachineLICMImpl(PreRegAlloc, nullptr, &MFAM).run(MF);
17711768
if (!Changed)
17721769
return PreservedAnalyses::all();

llvm/lib/CodeGen/OptimizePHIs.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ INITIALIZE_PASS(OptimizePHIsLegacy, DEBUG_TYPE,
8181

8282
PreservedAnalyses OptimizePHIsPass::run(MachineFunction &MF,
8383
MachineFunctionAnalysisManager &MFAM) {
84-
if (MF.getFunction().hasOptNone())
85-
return PreservedAnalyses::all();
86-
8784
OptimizePHIs OP;
8885
if (!OP.run(MF))
8986
return PreservedAnalyses::all();

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,9 +1193,6 @@ bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {
11931193

11941194
PreservedAnalyses StackColoringPass::run(MachineFunction &MF,
11951195
MachineFunctionAnalysisManager &MFAM) {
1196-
if (MF.getFunction().hasOptNone())
1197-
return PreservedAnalyses::all();
1198-
11991196
StackColoring SC(&MFAM.getResult<SlotIndexesAnalysis>(MF));
12001197
if (SC.run(MF))
12011198
return PreservedAnalyses::none();

llvm/lib/CodeGen/TailDuplication.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ PreservedAnalyses TailDuplicatePassBase<DerivedT, PreRegAlloc>::run(
110110
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
111111
MFPropsModifier _(static_cast<DerivedT &>(*this), MF);
112112

113-
if (MF.getFunction().hasOptNone())
114-
return PreservedAnalyses::all();
115-
116113
auto *MBPI = &MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
117114
auto *PSI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
118115
.getCachedResult<ProfileSummaryAnalysis>(

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,14 +1048,16 @@ void OptNoneInstrumentation::registerCallbacks(
10481048
}
10491049

10501050
bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
1051-
const auto *F = unwrapIR<Function>(IR);
1052-
if (!F) {
1053-
if (const auto *L = unwrapIR<Loop>(IR))
1054-
F = L->getHeader()->getParent();
1055-
}
1056-
bool ShouldRun = !(F && F->hasOptNone());
1051+
bool ShouldRun = true;
1052+
if (const auto *F = unwrapIR<Function>(IR))
1053+
ShouldRun = !F->hasOptNone();
1054+
else if (const auto *L = unwrapIR<Loop>(IR))
1055+
ShouldRun = !L->getHeader()->getParent()->hasOptNone();
1056+
else if (const auto *MF = unwrapIR<MachineFunction>(IR))
1057+
ShouldRun = !MF->getFunction().hasOptNone();
1058+
10571059
if (!ShouldRun && DebugLogging) {
1058-
errs() << "Skipping pass " << PassID << " on " << F->getName()
1060+
errs() << "Skipping pass " << PassID << " on " << getIRName(IR)
10591061
<< " due to optnone attribute\n";
10601062
}
10611063
return ShouldRun;

llvm/test/CodeGen/X86/optnone.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# RUN: llc -passes=machine-cse -debug-pass-manager %s -o - 2>&1 | FileCheck %s
2+
3+
# CHECK: Skipping pass MachineCSEPass on test_optnone due to optnone attribute
4+
# CHECK: Running pass: MachineCSEPass on test_opt
5+
--- |
6+
define void @test_optnone() noinline optnone { ret void }
7+
define void @test_opt() { ret void }
8+
...
9+
---
10+
name: test_optnone
11+
body: |
12+
bb.0:
13+
RET64
14+
...
15+
---
16+
name: test_opt
17+
body: |
18+
bb.0:
19+
RET64
20+
...

0 commit comments

Comments
 (0)