From 2e438ca03b69ce199f9d567fc5e4ca028d1018c4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 3 Jan 2008 16:56:04 +0000 Subject: [PATCH] add info on walking preds/succs of a block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45537 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 47 ++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 66bca9b7757..7bec1b964dc 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -103,6 +103,8 @@ complex example the same way
  • Iterating over def-use & use-def chains
  • +
  • Iterating over predecessors & +successors of blocks
  • Making simple changes @@ -1536,7 +1538,7 @@ the last line of the last example,

    -Instruction* pinst = &*i;
    +Instruction *pinst = &*i;
     
    @@ -1544,7 +1546,7 @@ Instruction* pinst = &*i;
    -Instruction* pinst = i;
    +Instruction *pinst = i;
     
    @@ -1612,8 +1614,7 @@ class OurFunctionPass : public FunctionPass { href="#CallInst">CallInst>(&*i)) { // We know we've encountered a call instruction, so we // need to determine if it's a call to the - // function pointed to by m_func or not - + // function pointed to by m_func or not. if (callInst->getCalledFunction() == targetFunc) ++callCounter; } @@ -1622,7 +1623,7 @@ class OurFunctionPass : public FunctionPass { } private: - unsigned callCounter; + unsigned callCounter; }; @@ -1674,7 +1675,7 @@ of F:

    -Function* F = ...;
    +Function *F = ...;
     
     for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i)
       if (Instruction *Inst = dyn_cast<Instruction>(*i)) {
    @@ -1694,10 +1695,10 @@ the particular Instruction):

    -Instruction* pi = ...;
    +Instruction *pi = ...;
     
     for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) {
    -  Value* v = *i;
    +  Value *v = *i;
       // ...
     }
     
    @@ -1710,6 +1711,36 @@ for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i)
    + + + +
    + +

    Iterating over the predecessors and successors of a block is quite easy +with the routines defined in "llvm/Support/CFG.h". Just use code like +this to iterate over all predecessors of BB:

    + +
    +
    +#include "llvm/Support/CFG.h"
    +BasicBlock *BB = ...;
    +
    +for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
    +  BasicBlock *Pred = *PI;
    +  // ...
    +}
    +
    +
    + +

    Similarly, to iterate over successors use +succ_iterator/succ_begin/succ_end.

    + +
    + +