kkm
kkm

Reputation: 43

llvm basic block predecessors llvm pred_iterator out of range

I'm trying to iterator over the predecessors of a basic block and I'm getting using the following code:

for (::llvm::PredIterator PI = pred_begin(post_block); PI != pred_end(post_block); PI++)
{
    ::llvm::BasicBlock *pred = *PI;
    if (pred != exec_block)
    { ...

In the line with the if statement, I'm getting the following error:

In instantiation of ‘llvm::PredIterator<Ptr, USE_iterator>::reference llvm::PredIterator<Ptr, USE_iterator>::operator*() const [with Ptr = llvm::BasicBlock; USE_iterator = llvm::Value::use_iterator_impl<llvm::Use>; llvm::PredIterator<Ptr, USE_iterator>::reference = llvm::BasicBlock*]’:LLVMTC.cpp:1489:31:  
required from here /usr/local/include/llvm/Support/CFG.h:56:5: error: ‘const class llvm::Value::use_iterator_impl<llvm::Use>’ has no member named ‘atEnd’
 assert(!It.atEnd() && "pred_iterator out of range!");

Does anyone have any ideas what might be causing this problem? I'm basing my code off of: http://llvm.org/docs/ProgrammersManual.html#iterating-over-predecessors-successors-of-blocks.

Thanks!

Upvotes: 1

Views: 1091

Answers (2)

gkso
gkso

Reputation: 533

I've been looking though the svn history, Since LLVM 3.5, CFG.h has been moved from include/llvm/Support to include/llvm/IR. So you may want to use the following

#include "llvm/IR/CFG.h"

instead of

#include "llvm/Support/CFG.h"

Upvotes: 0

jtv
jtv

Reputation: 118

First it's important to address the difference between your approach and the one in the example you're referencing.

In the example, they're define an instance of the pred_iterator type, rather than the PredIterator class you've used, which is defined as

typedef PredIterator<BasicBlock, Value::user_iterator> pred_iterator

and then using the calling pred_begin which returns an instance of pred_iterator(BB) where BB is the basic block you pass.

In your case, you're creating an instance of the PredIterator class and assigning it to the BB pointer, then attempting to dereference upon which it hits this assert:

inline reference operator*() const {
    assert(!It.atEnd() && "pred_iterator out of range!");
    return cast<TerminatorInst>(*It)->getParent();
}

As an initial solution it might be helpful to try and completely mimic the method used by the example, and then if you still need to use your method, try and diagnose the problem by observing how the typing for PredIterator is defined.

Upvotes: 0

Related Questions