llvm.org GIT mirror llvm / cc92828
CodeGen/Passes: Pass MachineFunction as functor arg; NFC Passing a MachineFunction as argument is more natural and avoids an unnecessary round-trip through the logic determining the correct Subtarget because MachineFunction already has a reference anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285039 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 3 years ago
4 changed file(s) with 18 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1919
2020 namespace llvm {
2121
22 class Function;
2322 class FunctionPass;
23 class MachineFunction;
2424 class MachineFunctionPass;
2525 class ModulePass;
2626 class Pass;
214214 /// IfConverter - This pass performs machine code if conversion.
215215 extern char &IfConverterID;
216216
217 FunctionPass *createIfConverter(std::function Ftor);
217 FunctionPass *createIfConverter(
218 std::function Ftor);
218219
219220 /// MachineBlockPlacement - This pass places basic blocks based on branch
220221 /// probabilities.
325326 extern char &UnpackMachineBundlesID;
326327
327328 FunctionPass *
328 createUnpackMachineBundles(std::functionFunction &)> Ftor);
329 createUnpackMachineBundles(std::functionMachineFunction &)> Ftor);
329330
330331 /// FinalizeMachineBundles - This pass finalize machine instruction
331332 /// bundles (created earlier, e.g. during pre-RA scheduling).
183183 bool PreRegAlloc;
184184 bool MadeChange;
185185 int FnNum;
186 std::functionFunction &)> PredicateFtor;
186 std::functionMachineFunction &)> PredicateFtor;
187187
188188 public:
189189 static char ID;
190 IfConverter(std::functionFunction &)> Ftor = nullptr)
190 IfConverter(std::functionMachineFunction &)> Ftor = nullptr)
191191 : MachineFunctionPass(ID), FnNum(-1), PredicateFtor(std::move(Ftor)) {
192192 initializeIfConverterPass(*PassRegistry::getPassRegistry());
193193 }
320320 INITIALIZE_PASS_END(IfConverter, "if-converter", "If Converter", false, false)
321321
322322 bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
323 if (skipFunction(*MF.getFunction()) ||
324 (PredicateFtor && !PredicateFtor(*MF.getFunction())))
323 if (skipFunction(*MF.getFunction()) || (PredicateFtor && !PredicateFtor(MF)))
325324 return false;
326325
327326 const TargetSubtargetInfo &ST = MF.getSubtarget();
22942293 }
22952294
22962295 FunctionPass *
2297 llvm::createIfConverter(std::functionFunction &)> Ftor) {
2296 llvm::createIfConverter(std::functionMachineFunction &)> Ftor) {
22982297 return new IfConverter(std::move(Ftor));
22992298 }
2323 class UnpackMachineBundles : public MachineFunctionPass {
2424 public:
2525 static char ID; // Pass identification
26 UnpackMachineBundles(std::function Ftor = nullptr)
26 UnpackMachineBundles(
27 std::function Ftor = nullptr)
2728 : MachineFunctionPass(ID), PredicateFtor(std::move(Ftor)) {
2829 initializeUnpackMachineBundlesPass(*PassRegistry::getPassRegistry());
2930 }
3132 bool runOnMachineFunction(MachineFunction &MF) override;
3233
3334 private:
34 std::functionFunction &)> PredicateFtor;
35 std::functionMachineFunction &)> PredicateFtor;
3536 };
3637 } // end anonymous namespace
3738
4142 "Unpack machine instruction bundles", false, false)
4243
4344 bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) {
44 if (PredicateFtor && !PredicateFtor(*MF.getFunction()))
45 if (PredicateFtor && !PredicateFtor(MF))
4546 return false;
4647
4748 bool Changed = false;
7778 }
7879
7980 FunctionPass *
80 llvm::createUnpackMachineBundles(std::function Ftor) {
81 llvm::createUnpackMachineBundles(
82 std::function Ftor) {
8183 return new UnpackMachineBundles(std::move(Ftor));
8284 }
8385
442442 return this->TM->getSubtarget(F).restrictIT();
443443 }));
444444
445 addPass(createIfConverter([this](const Function &F) {
446 return !this->TM->getSubtarget(F).isThumb1Only();
445 addPass(createIfConverter([](const MachineFunction &MF) {
446 return !MF.getSubtarget().isThumb1Only();
447447 }));
448448 }
449449 addPass(createThumb2ITBlockPass());
453453 addPass(createThumb2SizeReductionPass());
454454
455455 // Constant island pass work on unbundled instructions.
456 addPass(createUnpackMachineBundles([this](const Function &F) {
457 return this->TM->getSubtarget(F).isThumb2();
456 addPass(createUnpackMachineBundles([](const MachineFunction &MF) {
457 return MF.getSubtarget().isThumb2();
458458 }));
459459
460460 // Don't optimize barriers at -O0.