diff options
author | Chris Lattner <sabre@nondot.org> | 2008-01-03 16:56:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-01-03 16:56:04 +0000 |
commit | 0665e1f3e15c79d9548cb74f63effcfd4366cb44 (patch) | |
tree | 2baebb551c76111bd2b65ca9fd97b8ac109abbec /docs/ProgrammersManual.html | |
parent | 6bbcc679829f62e02661987ff33cfd23fb199ab5 (diff) | |
download | external_llvm-0665e1f3e15c79d9548cb74f63effcfd4366cb44.zip external_llvm-0665e1f3e15c79d9548cb74f63effcfd4366cb44.tar.gz external_llvm-0665e1f3e15c79d9548cb74f63effcfd4366cb44.tar.bz2 |
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
Diffstat (limited to 'docs/ProgrammersManual.html')
-rw-r--r-- | docs/ProgrammersManual.html | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 66bca9b..7bec1b9 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -103,6 +103,8 @@ complex example</a> </li> the same way</a> </li> <li><a href="#iterate_chains">Iterating over def-use & use-def chains</a> </li> + <li><a href="#iterate_preds">Iterating over predecessors & +successors of blocks</a></li> </ul> </li> <li><a href="#simplechanges">Making simple changes</a> @@ -1536,7 +1538,7 @@ the last line of the last example,</p> <div class="doc_code"> <pre> -Instruction* pinst = &*i; +Instruction *pinst = &*i; </pre> </div> @@ -1544,7 +1546,7 @@ Instruction* pinst = &*i; <div class="doc_code"> <pre> -Instruction* pinst = i; +Instruction *pinst = i; </pre> </div> @@ -1612,8 +1614,7 @@ class OurFunctionPass : public FunctionPass { href="#CallInst">CallInst</a>>(&*i)) { // <i>We know we've encountered a call instruction, so we</i> // <i>need to determine if it's a call to the</i> - // <i>function pointed to by m_func or not</i> - + // <i>function pointed to by m_func or not.</i> if (callInst->getCalledFunction() == targetFunc) ++callCounter; } @@ -1622,7 +1623,7 @@ class OurFunctionPass : public FunctionPass { } private: - unsigned callCounter; + unsigned callCounter; }; </pre> </div> @@ -1674,7 +1675,7 @@ of <tt>F</tt>:</p> <div class="doc_code"> <pre> -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 <tt>Instruction</tt>):</p> <div class="doc_code"> <pre> -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; // <i>...</i> } </pre> @@ -1710,6 +1711,36 @@ for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) </div> +<!--_______________________________________________________________________--> +<div class="doc_subsubsection"> + <a name="iterate_preds">Iterating over predecessors & +successors of blocks</a> +</div> + +<div class="doc_text"> + +<p>Iterating over the predecessors and successors of a block is quite easy +with the routines defined in <tt>"llvm/Support/CFG.h"</tt>. Just use code like +this to iterate over all predecessors of BB:</p> + +<div class="doc_code"> +<pre> +#include "llvm/Support/CFG.h" +BasicBlock *BB = ...; + +for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { + BasicBlock *Pred = *PI; + // <i>...</i> +} +</pre> +</div> + +<p>Similarly, to iterate over successors use +succ_iterator/succ_begin/succ_end.</p> + +</div> + + <!-- ======================================================================= --> <div class="doc_subsection"> <a name="simplechanges">Making simple changes</a> |