diff --git a/llvm/include/llvm/CodeGen/FinalizeISel.h b/llvm/include/llvm/CodeGen/FinalizeISel.h index 117140417e2c2..b2c28e330126f 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 { 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 bf5225d3e99a5..b02667d5c6699 100644 --- a/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h +++ b/llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h @@ -17,6 +17,7 @@ class LocalStackSlotAllocationPass : public PassInfoMixin { 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 85bd674c56a60..37d9f8ff502db 100644 --- a/llvm/include/llvm/CodeGen/MIRPrinter.h +++ b/llvm/include/llvm/CodeGen/MIRPrinter.h @@ -31,6 +31,7 @@ class PrintMIRPreparePass : public PassInfoMixin { public: PrintMIRPreparePass(raw_ostream &OS = errs()) : OS(OS) {} PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM); + static bool isRequired() { return true; } }; class PrintMIRPass : public PassInfoMixin { @@ -40,6 +41,7 @@ class PrintMIRPass : public PassInfoMixin { 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 bfd0681fb7954..9d82b5417c927 100644 --- a/llvm/include/llvm/CodeGen/MachineVerifier.h +++ b/llvm/include/llvm/CodeGen/MachineVerifier.h @@ -21,6 +21,7 @@ class MachineVerifierPass : public PassInfoMixin { : 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 3a1a4c5c6133f..d3c884b8413c7 100644 --- a/llvm/include/llvm/CodeGen/PHIElimination.h +++ b/llvm/include/llvm/CodeGen/PHIElimination.h @@ -17,6 +17,7 @@ class PHIEliminationPass : public PassInfoMixin { 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 440264a06ae89..b2ca9e10bf464 100644 --- a/llvm/include/llvm/CodeGen/RegAllocFast.h +++ b/llvm/include/llvm/CodeGen/RegAllocFast.h @@ -50,6 +50,8 @@ class RegAllocFastPass : public PassInfoMixin { void printPipeline(raw_ostream &OS, function_ref 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 32b2ea48179f4..f99ec4651009a 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h @@ -551,6 +551,7 @@ class SelectionDAGISelPass : public PassInfoMixin { 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 3e73995846176..b95516f616e0f 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(MF); MachineLoopInfo &LI = MFAM.getResult(MF); MachineTraceMetrics &MTM = MFAM.getResult(MF); diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp index 8e9fcccff7764..0a547050e91a8 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(MF); MachineBlockFrequencyInfo &MBFI = MFAM.getResult(MF); diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp index 7ea07862b839d..005dc42fe8dec 100644 --- a/llvm/lib/CodeGen/MachineLICM.cpp +++ b/llvm/lib/CodeGen/MachineLICM.cpp @@ -1763,9 +1763,6 @@ bool MachineLICMImpl::isTgtHotterThanSrc(MachineBasicBlock *SrcBlock, template PreservedAnalyses MachineLICMBasePass::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 cccc368e56e40..569b6b2f769c0 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 0be31d5db11ae..0305bdce26f73 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(MF)); if (SC.run(MF)) return PreservedAnalyses::none(); diff --git a/llvm/lib/CodeGen/TailDuplication.cpp b/llvm/lib/CodeGen/TailDuplication.cpp index b698ca675b65e..a50cdcfa7cc60 100644 --- a/llvm/lib/CodeGen/TailDuplication.cpp +++ b/llvm/lib/CodeGen/TailDuplication.cpp @@ -110,9 +110,6 @@ PreservedAnalyses TailDuplicatePassBase::run( MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) { MFPropsModifier _(static_cast(*this), MF); - if (MF.getFunction().hasOptNone()) - return PreservedAnalyses::all(); - auto *MBPI = &MFAM.getResult(MF); auto *PSI = MFAM.getResult(MF) .getCachedResult( diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index d4866a025c1b4..5a3bf8884cd54 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(IR); - if (!F) { - if (const auto *L = unwrapIR(IR)) - F = L->getHeader()->getParent(); - } - bool ShouldRun = !(F && F->hasOptNone()); + bool ShouldRun = true; + if (const auto *F = unwrapIR(IR)) + ShouldRun = !F->hasOptNone(); + else if (const auto *L = unwrapIR(IR)) + ShouldRun = !L->getHeader()->getParent()->hasOptNone(); + else if (const auto *MF = unwrapIR(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 0000000000000..ae572cd6c3a50 --- /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 +...