[llvm] [Instrumentation] Support `MachineFunction` in `OptNoneInstrumentation` (PR #115471)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 06:20:30 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: None (paperchalice)
<details>
<summary>Changes</summary>
Support `MachineFunction` in `OptNoneInstrumentation`, also add `isRequired` to all necessary passes.
---
Full diff: https://github.com/llvm/llvm-project/pull/115471.diff
15 Files Affected:
- (modified) llvm/include/llvm/CodeGen/FinalizeISel.h (+1)
- (modified) llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h (+1)
- (modified) llvm/include/llvm/CodeGen/MIRPrinter.h (+2)
- (modified) llvm/include/llvm/CodeGen/MachineVerifier.h (+1)
- (modified) llvm/include/llvm/CodeGen/PHIElimination.h (+1)
- (modified) llvm/include/llvm/CodeGen/RegAllocFast.h (+2)
- (modified) llvm/include/llvm/CodeGen/SelectionDAGISel.h (+1)
- (modified) llvm/lib/CodeGen/EarlyIfConversion.cpp (-3)
- (modified) llvm/lib/CodeGen/MachineCSE.cpp (-3)
- (modified) llvm/lib/CodeGen/MachineLICM.cpp (-3)
- (modified) llvm/lib/CodeGen/OptimizePHIs.cpp (-3)
- (modified) llvm/lib/CodeGen/StackColoring.cpp (-3)
- (modified) llvm/lib/CodeGen/TailDuplication.cpp (-3)
- (modified) llvm/lib/Passes/StandardInstrumentations.cpp (+9-7)
- (added) llvm/test/CodeGen/X86/optnone.mir (+20)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/FinalizeISel.h b/llvm/include/llvm/CodeGen/FinalizeISel.h
index 117140417e2c2c..b2c28e330126fc 100644
--- a/llvm/include/llvm/CodeGen/FinalizeISel.h
+++ b/llvm/include/llvm/CodeGen/FinalizeISel.h
@@ -16,6 +16,7 @@ namespace llvm {
class FinalizeISelPass : public PassInfoMixin<FinalizeISelPass> {
public:
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
+ static bool isRequired() { return true; }
};
} // namespace llvm
diff --git a/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h b/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h
index bf5225d3e99a54..b02667d5c6699d 100644
--- a/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h
+++ b/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h
@@ -17,6 +17,7 @@ class LocalStackSlotAllocationPass
: public PassInfoMixin<LocalStackSlotAllocationPass> {
public:
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
+ static bool isRequired() { return true; }
};
} // namespace llvm
diff --git a/llvm/include/llvm/CodeGen/MIRPrinter.h b/llvm/include/llvm/CodeGen/MIRPrinter.h
index 85bd674c56a60c..37d9f8ff502db0 100644
--- a/llvm/include/llvm/CodeGen/MIRPrinter.h
+++ b/llvm/include/llvm/CodeGen/MIRPrinter.h
@@ -31,6 +31,7 @@ class PrintMIRPreparePass : public PassInfoMixin<PrintMIRPreparePass> {
public:
PrintMIRPreparePass(raw_ostream &OS = errs()) : OS(OS) {}
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
};
class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
@@ -40,6 +41,7 @@ class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
PrintMIRPass(raw_ostream &OS = errs()) : OS(OS) {}
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
};
/// Print LLVM IR using the MIR serialization format to the given output stream.
diff --git a/llvm/include/llvm/CodeGen/MachineVerifier.h b/llvm/include/llvm/CodeGen/MachineVerifier.h
index bfd0681fb79545..9d82b5417c927e 100644
--- a/llvm/include/llvm/CodeGen/MachineVerifier.h
+++ b/llvm/include/llvm/CodeGen/MachineVerifier.h
@@ -21,6 +21,7 @@ class MachineVerifierPass : public PassInfoMixin<MachineVerifierPass> {
: Banner(Banner) {}
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
};
} // namespace llvm
diff --git a/llvm/include/llvm/CodeGen/PHIElimination.h b/llvm/include/llvm/CodeGen/PHIElimination.h
index 3a1a4c5c6133f8..d3c884b8413c7a 100644
--- a/llvm/include/llvm/CodeGen/PHIElimination.h
+++ b/llvm/include/llvm/CodeGen/PHIElimination.h
@@ -17,6 +17,7 @@ class PHIEliminationPass : public PassInfoMixin<PHIEliminationPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
};
} // namespace llvm
diff --git a/llvm/include/llvm/CodeGen/RegAllocFast.h b/llvm/include/llvm/CodeGen/RegAllocFast.h
index 440264a06ae89e..b2ca9e10bf4647 100644
--- a/llvm/include/llvm/CodeGen/RegAllocFast.h
+++ b/llvm/include/llvm/CodeGen/RegAllocFast.h
@@ -50,6 +50,8 @@ class RegAllocFastPass : public PassInfoMixin<RegAllocFastPass> {
void printPipeline(raw_ostream &OS,
function_ref<StringRef(StringRef)> MapClassName2PassName);
+
+ static bool isRequired() { return true; }
};
} // namespace llvm
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index 32b2ea48179f47..f99ec4651009a0 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -551,6 +551,7 @@ class SelectionDAGISelPass : public PassInfoMixin<SelectionDAGISelPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
+ static bool isRequired() { return true; }
};
}
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 3e73995846176e..b95516f616e0f1 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -1119,9 +1119,6 @@ bool EarlyIfConverter::run(MachineFunction &MF) {
PreservedAnalyses
EarlyIfConverterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
MachineLoopInfo &LI = MFAM.getResult<MachineLoopAnalysis>(MF);
MachineTraceMetrics &MTM = MFAM.getResult<MachineTraceMetricsAnalysis>(MF);
diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp
index 8e9fcccff77645..0a547050e91a8a 100644
--- a/llvm/lib/CodeGen/MachineCSE.cpp
+++ b/llvm/lib/CodeGen/MachineCSE.cpp
@@ -957,9 +957,6 @@ PreservedAnalyses MachineCSEPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
MFPropsModifier _(*this, MF);
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
MachineBlockFrequencyInfo &MBFI =
MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp
index 7ea07862b839d0..005dc42fe8dec8 100644
--- a/llvm/lib/CodeGen/MachineLICM.cpp
+++ b/llvm/lib/CodeGen/MachineLICM.cpp
@@ -1763,9 +1763,6 @@ bool MachineLICMImpl::isTgtHotterThanSrc(MachineBasicBlock *SrcBlock,
template <typename DerivedT, bool PreRegAlloc>
PreservedAnalyses MachineLICMBasePass<DerivedT, PreRegAlloc>::run(
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
bool Changed = MachineLICMImpl(PreRegAlloc, nullptr, &MFAM).run(MF);
if (!Changed)
return PreservedAnalyses::all();
diff --git a/llvm/lib/CodeGen/OptimizePHIs.cpp b/llvm/lib/CodeGen/OptimizePHIs.cpp
index cccc368e56e40d..569b6b2f769c00 100644
--- a/llvm/lib/CodeGen/OptimizePHIs.cpp
+++ b/llvm/lib/CodeGen/OptimizePHIs.cpp
@@ -81,9 +81,6 @@ INITIALIZE_PASS(OptimizePHIsLegacy, DEBUG_TYPE,
PreservedAnalyses OptimizePHIsPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
OptimizePHIs OP;
if (!OP.run(MF))
return PreservedAnalyses::all();
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 0be31d5db11ae2..0305bdce26f731 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -1193,9 +1193,6 @@ bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {
PreservedAnalyses StackColoringPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
StackColoring SC(&MFAM.getResult<SlotIndexesAnalysis>(MF));
if (SC.run(MF))
return PreservedAnalyses::none();
diff --git a/llvm/lib/CodeGen/TailDuplication.cpp b/llvm/lib/CodeGen/TailDuplication.cpp
index b698ca675b65e2..a50cdcfa7cc60e 100644
--- a/llvm/lib/CodeGen/TailDuplication.cpp
+++ b/llvm/lib/CodeGen/TailDuplication.cpp
@@ -110,9 +110,6 @@ PreservedAnalyses TailDuplicatePassBase<DerivedT, PreRegAlloc>::run(
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
MFPropsModifier _(static_cast<DerivedT &>(*this), MF);
- if (MF.getFunction().hasOptNone())
- return PreservedAnalyses::all();
-
auto *MBPI = &MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
auto *PSI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
.getCachedResult<ProfileSummaryAnalysis>(
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index d4866a025c1b48..5a3bf8884cd542 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1048,14 +1048,16 @@ void OptNoneInstrumentation::registerCallbacks(
}
bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
- const auto *F = unwrapIR<Function>(IR);
- if (!F) {
- if (const auto *L = unwrapIR<Loop>(IR))
- F = L->getHeader()->getParent();
- }
- bool ShouldRun = !(F && F->hasOptNone());
+ bool ShouldRun = true;
+ if (const auto *F = unwrapIR<Function>(IR))
+ ShouldRun = !F->hasOptNone();
+ else if (const auto *L = unwrapIR<Loop>(IR))
+ ShouldRun = !L->getHeader()->getParent()->hasOptNone();
+ else if (const auto *MF = unwrapIR<MachineFunction>(IR))
+ ShouldRun = !MF->getFunction().hasOptNone();
+
if (!ShouldRun && DebugLogging) {
- errs() << "Skipping pass " << PassID << " on " << F->getName()
+ errs() << "Skipping pass " << PassID << " on " << getIRName(IR)
<< " due to optnone attribute\n";
}
return ShouldRun;
diff --git a/llvm/test/CodeGen/X86/optnone.mir b/llvm/test/CodeGen/X86/optnone.mir
new file mode 100644
index 00000000000000..ae572cd6c3a50e
--- /dev/null
+++ b/llvm/test/CodeGen/X86/optnone.mir
@@ -0,0 +1,20 @@
+# RUN: llc -passes=machine-cse -debug-pass-manager %s -o - 2>&1 | FileCheck %s
+
+# CHECK: Skipping pass MachineCSEPass on test_optnone due to optnone attribute
+# CHECK: Running pass: MachineCSEPass on test_opt
+--- |
+ define void @test_optnone() noinline optnone { ret void }
+ define void @test_opt() { ret void }
+...
+---
+name: test_optnone
+body: |
+ bb.0:
+ RET64
+...
+---
+name: test_opt
+body: |
+ bb.0:
+ RET64
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/115471
More information about the llvm-commits
mailing list