Michael McCracken
2004-Aug-27 00:56 UTC
[LLVMdev] Help getting condition of branch instructions in pass
Hi, this is a bit of a newbie question: I am trying to discover, given a block with a conditional and its successors, which condition (T/F) each successor applies to. There's almost identical code in CFGPrinter.cpp, but where it gets called in GraphWriter.h, the child_iterator type is a pretty hairy thing, so I still don't quite understand how to get one from a BasicBlock in my own code... Is there a simpler way to do it without getting into all that? -mike
Chris Lattner
2004-Aug-27 07:24 UTC
[LLVMdev] Help getting condition of branch instructions in pass
On Thu, 26 Aug 2004, Michael McCracken wrote:> Hi, this is a bit of a newbie question: > > I am trying to discover, given a block with a conditional and its > successors, which condition (T/F) each successor applies to.If you #include "llvm/Support/CFG.h", you will be provided with succ_ and pred_iterator's. You can grep the sourcebase to see how these are used. Alternatively, you can get successor information like this: BasicBlock *BB = ... if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) if (BI->isConditional()) { Value *Cond = BI->getCondition(); BasicBlock *TrueDest = BI->getSuccessor(0); BasicBlock *FalseDest = BI->getSuccessor(1); ... } Using succ_iterator would look like this, which works for all basic blocks, but does not give you any special information about branches: for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) { BasicBlock *ASuccessor = *SI; ... } -Chris -- http://llvm.org/ http://nondot.org/sabre/
Possibly Parallel Threads
- crash problem when using IndirectBrInst to replace BranchInst
- crash problem when using IndirectBrInst to replace BranchInst
- [LLVMdev] [PATCH / PROPOSAL] bitcode encoding that is ~15% smaller for large bitcode files...
- [LLVMdev] [PATCH / PROPOSAL] bitcode encoding that is ~15% smaller for large bitcode files...
- [LLVMdev] BackedgeTakenCount calculation for fortran loops and DragonEgg gfortran-4.6