I want access to all basic blocks of function in a loop, so I used the following code:
bool parallel::runOnLoop(Loop *L, LPPassManager &LPM) { for (Function::iterator bi= func->begin(); bi != func->end(); bi++){ // } }
Are you modifying anything within this code (especially changes that add/remove basic blocks or change their Terminator instructions)? Depending on what you’re doing, you may be invalidating the basic block iterator bi.
Yes, I change them, so what should I do for another loops?
I don’t really know what you should do since I don’t know what your code does. All I know is that it’s changing the function’s control-flow graph.
If you’re not modifying the structure of the loops in the function, then you can probably just fix the problem by using a worklist-style algorithm. First loop through the basic blocks in the function and record in a std::vector<> or std::set<> (or some other C++ container) the set of basic blocks that you want to change. After you do that, you can iterate through all the basic blocks in the container and start making modifications to them.
That will fix any iterator invalidation occurring with the for() loop. That may work, but if I had been writing this pass, I would probably have made it a FunctionPass to ensure that the CFG changes don’t confuse the PassManager.
LoopPass manager is walking loop nest while invoking each loop pass on a given loop. If you update structure of loops then you need to let loop pass manager know.
I used std::vector<> but i get same error, I can’t use FunctionPass
There must be a good reason.
In any case, see LPPassManager (it is a FunctionPass :), which provides simple hooks to record deletion/creation of loops. If that does not work for you, you’ll have to update LPPassManager to meet your needs.
John Criswell <criswell <at> illinois.edu> writes:
hi all,
I want access to all basic blocks of function in a loop, so I used
the following code:bool parallel::runOnLoop(Loop *L, LPPassManager
&LPM)
{
for (Function::iterator bi= func->begin(); bi !=
func->end(); bi++){
//
}
}
Are you modifying anything within this code (especially changes that
add/remove basic blocks or change their Terminator instructions)?
Depending on what you're doing, you may be invalidating the basic
block iterator bi.
-- John T.
Hello, I am getting same opt Stack dump error frequently as well. Also trying to
access basic blocks in runOnBasicBlock(BasicBlock &BB). This is at the 4th line
with errs():
Instruction* current = BB.getTerminator();
errs() << "\n last: "<<*current<<"\n";
Instruction* prev = current->getPrevNode();
errs()<<*prev<<"\n";
What can be the cause?