[LLVMdev] insertions with inst_iterators?
Bill Wendling
wendling at apple.com
Mon Aug 29 12:52:00 PDT 2011
On Aug 29, 2011, at 12:38 PM, ret val wrote:
> I am looping through all instructions in a Function and depending on
> what I found I may or may not insert code. Despite the fact that I'm
> only actually inserting *before* instruction I have a infinite loop
> when I do something like below. For awhile it was simple enough to
> just increment i enough times but now I need something better.
>
> for(inst_iterator i = inst_begin(F); i != inst_end(F); ++i) {
> ...
> // possible insertions of unknown size
> ...
> }
>
> I tried storing the storing the initial iterator and reverting back to
> it(along with storing the next element) and I am still left with a
> infinite loop. I see some discussion online about weather insertions
> with iterators in C++ is allowed period, so what is the correct way to
> do something like this in LLVM? This must be a common problem.
>
Have you tried this?
for(inst_iterator i = inst_begin(F); i != inst_end(F); ) {
Instruction *Inst = *i++;
...
// possible insertions of unknown size
...
}
?
-bw
More information about the llvm-dev
mailing list