<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I have a pre instruction selection pass that is registered by calling addPass from Target::addPreISel. This works fine - it runs at the appropriate point in the pipeline and does what it is supposed to.<br><br></div>I would like to call the pass from opt in order to write some test cases in IR. Unfortunately I'm missing something - despite a determined attempt to do what other passes do, mine doesn't show up in opt. With variables renamed, the pass amounts to:<br><br>#define DEBUG_TYPE "my-pass"<br>#define EXAMPLE_NAME "A longer description of my pass"<br><br>namespace {<br>class MyExample : public FunctionPass {<br>public:<br>  static char ID;<br>  MyExample() : FunctionPass(ID) {<br>    initializeMyExamplePass(*PassRegistry::getPassRegistry());<br>  }<br><br>  bool runOnFunction(Function &) override;<br>  StringRef getPassName() const override { return EXAMPLE_NAME; }<br><br>  void getAnalysisUsage(AnalysisUsage &AU) const override {<br>    AU.addRequired<DominatorTreeWrapperPass>();<br>    AU.addRequired<LoopInfoWrapperPass>();<br>    AU.addRequired<ScalarEvolutionWrapperPass>();<br>  }<br>};<br>} // namespace                                                                                                                                                                                                     <br>char MyExample::ID = 0;<br><br>INITIALIZE_PASS_BEGIN(MyExample, DEBUG_TYPE, EXAMPLE_NAME, false, false)<br>INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)<br>INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)<br>INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)<br>INITIALIZE_PASS_END(MyExample, DEBUG_TYPE, EXAMPLE_NAME, false, false)<br><br>FunctionPass *llvm::createMyExamplePass() { return new MyExample(); }<br><br></div><div>I think the problem is that addPreISel isn't called by opt, so the constructor is never run and the pass never added to the list. This is somewhat confirmed by the following hack:<br><br> static struct once_t {<br>  once_t() { createMyExamplePass(); }<br>} unused_variable;<br><br></div><div>which creates an instance of the pass then immediately throws it away, in which case opt will let me run the pass as desired.<br><br></div><div>So while I have a workaround, said workaround looks absurd - what's the correct way to use this API?<br><br></div><div>Thanks!<br><br></div><div>Jon<br><br></div></div></div></div>