[llvm] [GlobalISel] Allow customizing instruction-select pass (PR #95724)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 07:26:18 PDT 2024


================
@@ -49,8 +49,8 @@ class InstructionSelect : public MachineFunctionPass {
         MachineFunctionProperties::Property::Selected);
   }
 
-  InstructionSelect(CodeGenOptLevel OL);
-  InstructionSelect();
+  InstructionSelect(CodeGenOptLevel OL = CodeGenOptLevel::Default,
+                    char &PassID = ID);
----------------
darkbuck wrote:

> Do you have a follow up / example of how you would use this to specify the dependencies? I don't this is enough to make InstructionSelect usable from subclasses

Unfortunately, I work on an out-of-tree target and cannot share them now. The basic idea is similar to what we did on RegBankSelect. After, we derive a target-specific instruction select and add additional dependencies. For example,

```
class XXXInstructionSelect  final : public InstructionSelect {
public:
  static char ID;

  XXXInstructionSelect(CodeGenOptLevel OL = CodeGenOptLevel::Default);
  void getAnalysisUsage(AnalysisUsage &AU) const override {
    AU.addRequired<ExtraAnalysisPass>();
    InstructionSelect::getAnalysisUsage(AU);
  }
  void runOnMachineFunction(MachineFunction &MF) override {
    auto *ExtraAInfo = getAnalysis<>();
    // So far, pass that ExtraInfo through MachineFunctionInfo as the pass manager interface is not exposed to InstructionSelector. This workaround could be removed once we expose legacy or new PM interface into InstructionSelector. But this workaround works so far.
    auto *MFInfo = get<XXXMachineFunctionInfo>();
    MFInfo->setExtraAInfo(ExtraAInfo);
    Changed = InstructionSelect::runOnMachineFunction(MF);
    MFInfo->clearExtraInfo();
    return Changed;
  }
};
```

https://github.com/llvm/llvm-project/pull/95724


More information about the llvm-commits mailing list