Index: llvm/include/llvm/CodeGen/GlobalISel/Localizer.h =================================================================== --- llvm/include/llvm/CodeGen/GlobalISel/Localizer.h +++ llvm/include/llvm/CodeGen/GlobalISel/Localizer.h @@ -42,6 +42,10 @@ static char ID; private: + /// An input function to decide if the pass should run or not + /// on the given MachineFunction. + std::function DoNotRunPass; + /// MRI contains all the register class/bank information that this /// pass uses and updates. MachineRegisterInfo *MRI; @@ -72,6 +76,7 @@ public: Localizer(); + Localizer(std::function); StringRef getPassName() const override { return "Localizer"; } Index: llvm/lib/CodeGen/GlobalISel/Localizer.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/Localizer.cpp +++ llvm/lib/CodeGen/GlobalISel/Localizer.cpp @@ -29,7 +29,11 @@ "Move/duplicate certain instructions close to their use", false, false) -Localizer::Localizer() : MachineFunctionPass(ID) { } +Localizer::Localizer(std::function F) + : MachineFunctionPass(ID), DoNotRunPass(F) {} + +Localizer::Localizer() + : Localizer([](const MachineFunction &) { return false; }) {} void Localizer::init(MachineFunction &MF) { MRI = &MF.getRegInfo(); @@ -212,6 +216,10 @@ MachineFunctionProperties::Property::FailedISel)) return false; + // Don't run the pass if the target asked so. + if (DoNotRunPass(MF)) + return false; + LLVM_DEBUG(dbgs() << "Localize instructions for: " << MF.getName() << '\n'); init(MF);