<div dir="ltr"><div>Hi everyone,</div><div>I am a LLVM newbie. I need to write a machinefunction pass for my project. This should be an analyzer of the machine code to do some profiling. I have written a couple of function passes for front end, but it seems they are completely different. I searched through forum and llvm documents, but couldn't find anything useful or questions were unanswered. Can anyone reference me to any material on how to do that or help me with my roblem.</div><div><br></div><div>I have created a folder in: lib/Transform and put my pass in it.</div><div>I am writing a simple pass like this:</div><div><br></div><div>using namespace llvm;</div><div><br></div><div>namespace {</div><div><span class="" style="white-space:pre">    </span></div><div>    struct analyzer : public MachineFunctionPass {</div><div><span class="" style="white-space:pre">        </span>static char ID; </div><div><span class="" style="white-space:pre">  </span>analyzer() : MachineFunctionPass(ID) {}<span class="" style="white-space:pre">   </span>   <span class="" style="white-space:pre">      </span></div><div><span class="" style="white-space:pre">   </span></div><div><span class="" style="white-space:pre">   </span>virtual bool runOnMachineFunction(MachineFunction &MF) {<span class="" style="white-space:pre">                                              </span></div><div><span class="" style="white-space:pre">           </span>errs() << "hello " ;</div><div><span class="" style="white-space:pre">       </span></div><div><span class="" style="white-space:pre">           </span>return false;<span class="" style="white-space:pre">             </span></div><div><span class="" style="white-space:pre">   </span>}</div><div>  };</div><div>}</div><div>char analyzer::ID = 0;</div><div>static RegisterPass<analyzer> X("analyzer", "WAW analyzer");</div><div><br></div><div>I make it successfully. But when I load it for my test code I get this error:</div><div><br></div><div><div>Pass 'WAW analyzer' is not initialized.</div><div>Verify if there is a pass dependency cycle.</div><div>Required Passes:</div><div>opt: /llvm/llvm-3.7/lib/IR/LegacyPassManager.cpp:635: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed.</div><div>.....</div></div><div><br></div><div>I don't know how to solve it? Do we have to run machinefunction passes with OPT command? Is this correct to put machinefunction pass in an external folder or do we have to change some llvm built-in files? </div><div><br></div><div>Regards,<br></div><div>Fami</div><div><br></div></div>