X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FProgrammersManual.html;h=716d364ed5699a2c73ca2c84ca93dbf3aee094be;hb=9eb698b96d8b753b2f5025baae0712167cf7fb03;hp=66bca9b7757dc8dc122be4a12aa86ab434a098ec;hpb=10d64b95a121e69dbd70f7ed9fa660085f13f779;p=oota-llvm.git diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 66bca9b7757..716d364ed56 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 @@ -1482,8 +1484,8 @@ small example that shows how to dump all instructions in a function to the stand #include "llvm/Support/InstIterator.h" // F is a pointer to a Function instance -for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) - llvm::cerr << *i << "\n"; +for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) + llvm::cerr << *I << "\n"; @@ -1495,7 +1497,10 @@ F, all you would need to do is something like:

     std::set<Instruction*> worklist;
    -worklist.insert(inst_begin(F), inst_end(F));
    +// or better yet, SmallPtrSet<Instruction*, 64> worklist;
    +
    +for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
    +   worklist.insert(&*I);
     
    @@ -1536,7 +1541,7 @@ the last line of the last example,

    -Instruction* pinst = &*i;
    +Instruction *pinst = &*i;
     
    @@ -1544,7 +1549,7 @@ Instruction* pinst = &*i;
    -Instruction* pinst = i;
    +Instruction *pinst = i;
     
    @@ -1612,8 +1617,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 +1626,7 @@ class OurFunctionPass : public FunctionPass { } private: - unsigned callCounter; + unsigned callCounter; }; @@ -1674,7 +1678,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 +1698,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 +1714,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.

    + +
    + +
    Making simple changes @@ -1883,9 +1917,7 @@ erase function to remove your instruction. For example:

     Instruction *I = .. ;
    -BasicBlock *BB = I->getParent();
    -
    -BB->getInstList().erase(I);
    +I->eraseFromParent();