Greetinigs, I am extending llc to include runtime checks for calls (in X86). So a call 'call target' is altered to look like this: [some check] jne error_function call target I've done this by implementing a MachineFunctionPass that is instantiated and added to the PassManager in X86TargetMachine::addPreRegAlloc. In order to create the jne-instruction I need some BasicBlock that contains the error routine. So I tried to create a ModulePass to insert some basic block e. g. in the beginning of the program, to use it for the jne-instruction. Unfortunately, llc then produces the error llc: PassManager.cpp:1597: virtual void llvm::ModulePass::assignPassManager(llvm::PMStack&, llvm::PassManagerType): Assertion `!PMS.empty() && "Unable to find appropriate Pass Manager"' failed. Adding a MachineFunctionPass the same way works fine. I've read here on the mailing list that some Pass dependencies cause this error, but I have no dependencies specified. How do I get the ModulePass to run? Is a ModulePass the right way to accomplish my aim, altogether? One more question concerning passes: Clearly, inserting a jne-instruction changes control flow, so the CFG is not up to date after the pass. Do I set AnalysisUsage in getAnalysisUsage to preserve nothing? In that case, is the CFG updated automatically by LLVM or do I need to apply the changes during the Pass not only the the MachineFunction, but also the the CFG? -Artjom -- View this message in context: http://www.nabble.com/code-altering-Passes-for-llc-tp24778261p24778261.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Aug 2, 2009, at 7:09 AM, Artjom Kochtchi wrote:> > Greetinigs, > > I am extending llc to include runtime checks for calls (in X86). So > a call > 'call target' is altered to look like this: > > [some check] > jne error_function > call target > > I've done this by implementing a MachineFunctionPass that is > instantiated > and added to the PassManager in X86TargetMachine::addPreRegAlloc. > > In order to create the jne-instruction I need some BasicBlock that > contains > the error routine. So I tried to create a ModulePass to insert some > basic > block e. g. in the beginning of the program, to use it for the > jne-instruction. Unfortunately, llc then produces the error > > llc: PassManager.cpp:1597: > virtual void llvm::ModulePass::assignPassManager(llvm::PMStack&, > llvm::PassManagerType): > Assertion `!PMS.empty() && "Unable to find appropriate Pass > Manager"' > failed. > > Adding a MachineFunctionPass the same way works fine. I've read here > on the > mailing list that some Pass dependencies cause this error, but I > have no > dependencies specified. > > How do I get the ModulePass to run? Is a ModulePass the right way to > accomplish my aim, altogether?You don't need a ModulePass to modify a CFG. A MachineFunctionPass is fine for this. The actual problem may be that your pass doesn't preserve some Analysis that CodeGen is using. Since CodeGen is function-oriented, ModulePasses cannot be freely scheduled.> > One more question concerning passes: > Clearly, inserting a jne-instruction changes control flow, so the > CFG is not > up to date after the pass. Do I set AnalysisUsage in > getAnalysisUsage to > preserve nothing? In that case, is the CFG updated automatically by > LLVM or > do I need to apply the changes during the Pass not only the the > MachineFunction, but also the the CFG?The default if you don't override getAnalysisUsage is that everything is considered clobbered. With a MachineFunctionPass, you can modify the MachineFunction (including the MachineBasicBlock CFG), but you shouldn't modify the LLVM IR Function. Dan
Dan Gohman-2 wrote:> > You don't need a ModulePass to modify a CFG. A MachineFunctionPass > is fine for this. >Well, okay. But I need to insert some BasicBlock that contains the error handling (that the runtime check jumpts to on failure). Just putting another MachineBasicBlock at the beginning of some arbitrary MachineFunction doesn't seem to be the right way to go, does it? -- View this message in context: http://www.nabble.com/code-altering-Passes-for-llc-tp24778261p24788337.html Sent from the LLVM - Dev mailing list archive at Nabble.com.