I have a pointer to a basic block and am iterating thru its predecessor blocks. I want to get a pointer to the predecessor block. How do I do it. I am using following code and it given compile time errors. error: cannot convert 'llvm::const_pred_iterator' to 'const llvm::BasicBlock*' in initialization const BasicBlock *b = PH->getParent(); // process all pred block of the current block for (const_pred_iterator pr=pred_begin(b), esc=pred_end(b); pr!=esc; ++pr) { const BasicBlock *p = pr; // ************error line ****************
Cameron Zwarich
2011-Jan-31 04:35 UTC
[LLVMdev] How to convert an iterator to an object pointer
On 2011-01-30, at 8:04 PM, Surinder wrote:> I have a pointer to a basic block and am iterating thru its > predecessor blocks. I want to get a pointer to the predecessor block. > How do I do it. I am using following code and it given compile time > errors. > > error: cannot convert 'llvm::const_pred_iterator' to 'const > llvm::BasicBlock*' in initialization > > const BasicBlock *b = PH->getParent(); > // process all pred block of the current block > for (const_pred_iterator pr=pred_begin(b), esc=pred_end(b); pr!=esc; ++pr) > { const BasicBlock *p = pr; // ************error line ****************Try using *pr instead. Cameron
Lang Hames
2011-Jan-31 04:36 UTC
[LLVMdev] How to convert an iterator to an object pointer
Hi Surinder, You'll need to dereference your iterator to get a pointer: const BasicBlock *p = *pr; Cheers, Lang. On Mon, Jan 31, 2011 at 3:04 PM, Surinder <surifilms at gmail.com> wrote:> I have a pointer to a basic block and am iterating thru its > predecessor blocks. I want to get a pointer to the predecessor block. > How do I do it. I am using following code and it given compile time > errors. > > error: cannot convert 'llvm::const_pred_iterator' to 'const > llvm::BasicBlock*' in initialization > > const BasicBlock *b = PH->getParent(); > // process all pred block of the current block > for (const_pred_iterator pr=pred_begin(b), esc=pred_end(b); pr!=esc; > ++pr) > { const BasicBlock *p = pr; // ************error line > **************** > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110131/f521ce61/attachment.html>
Thanks. *p=*pr; works. I am passing *p to dominates function of dominator tree and it does not like *pr, but is happy with *p. On Mon, Jan 31, 2011 at 3:36 PM, Lang Hames <lhames at gmail.com> wrote:> Hi Surinder, > You'll need to dereference your iterator to get a pointer: > const BasicBlock *p = *pr; > Cheers, > Lang. > On Mon, Jan 31, 2011 at 3:04 PM, Surinder <surifilms at gmail.com> wrote: >> >> I have a pointer to a basic block and am iterating thru its >> predecessor blocks. I want to get a pointer to the predecessor block. >> How do I do it. I am using following code and it given compile time >> errors. >> >> error: cannot convert 'llvm::const_pred_iterator' to 'const >> llvm::BasicBlock*' in initialization >> >> const BasicBlock *b = PH->getParent(); >> // process all pred block of the current block >> for (const_pred_iterator pr=pred_begin(b), esc=pred_end(b); pr!=esc; >> ++pr) >> { const BasicBlock *p = pr; // ************error line >> **************** >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >