I am attempting to add instructions before and after all loops. To do this, I've added a simple function as follows: void addToAllLoops(Loop * IL) { addToAllLoops(IL); BasicBlock * PH = IL->getLoopPreheader(); Instruction *InstrCallPre = new CallInst(PrintLoopBegin, "", PH->getPrev()); return; } The function added is trivial: void printloopbegin() { fprintf (stderr,"Loop Beginning\n"); } The function is called from runOnFunction() as follows: PrintLoopBegin = F.getParent()->getOrInsertFunction("printloopbegin", Type::VoidTy, NULL); for (LoopInfo::iterator IL = LI->begin(), E = LI->end(); IL!= E; ++IL) addToAllLoops(*IL); Unfortunately, compiling with this results in an "Illegal instruction (core dumped)." Is PrintLoopBegin defined in the wrong place (should it be in the addToAllLoops() function somehow)? What about the method of attempting to insert the instruction right before the Preheader by doing getLoopPreheader()->getPrev() ? Thanks, Sean
Please ignore the previous email; I can't believe the stupid coding errors I made. ---------- Forwarded message ---------- From: Sean Peisert <peisert at gmail.com> Date: Aug 12, 2005 5:28 PM Subject: Adding instructions to loop To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu>, Chris Lattner <sabre at nondot.org> I am attempting to add instructions before and after all loops. To do this, I've added a simple function as follows: void addToAllLoops(Loop * IL) { addToAllLoops(IL); BasicBlock * PH = IL->getLoopPreheader(); Instruction *InstrCallPre = new CallInst(PrintLoopBegin, "", PH->getPrev()); return; } The function added is trivial: void printloopbegin() { fprintf (stderr,"Loop Beginning\n"); } The function is called from runOnFunction() as follows: PrintLoopBegin = F.getParent()->getOrInsertFunction("printloopbegin", Type::VoidTy, NULL); for (LoopInfo::iterator IL = LI->begin(), E = LI->end(); IL!= E; ++IL) addToAllLoops(*IL); Unfortunately, compiling with this results in an "Illegal instruction (core dumped)." Is PrintLoopBegin defined in the wrong place (should it be in the addToAllLoops() function somehow)? What about the method of attempting to insert the instruction right before the Preheader by doing getLoopPreheader()->getPrev() ? Thanks, Sean
Seemingly Similar Threads
- How to make ScalarEvolution recompute SCEV values?
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] hoisting problem.
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*