[llvm-commits] CVS: llvm/www/docs/ProgrammersManual.html

Joel Stanley jstanley at cs.uiuc.edu
Wed Sep 11 15:52:01 PDT 2002


Changes in directory llvm/www/docs:

ProgrammersManual.html updated: 1.19 -> 1.20

---
Log message:


---
Diffs of the changes:

Index: llvm/www/docs/ProgrammersManual.html
diff -u llvm/www/docs/ProgrammersManual.html:1.19 llvm/www/docs/ProgrammersManual.html:1.20
--- llvm/www/docs/ProgrammersManual.html:1.19	Tue Sep 10 10:20:46 2002
+++ llvm/www/docs/ProgrammersManual.html	Wed Sep 11 15:50:04 2002
@@ -543,6 +543,45 @@
 </ul><h4><a name="iterate_chains"><hr size=0>Iterating over def-use &
 use-def chains</h4><ul>
 
+Frequently, we might have an instance of the <a
+href="/doxygen/classValue.html">Value Class</a> and we want to
+determine which <tt>User</tt>s use the <tt>Value</tt>.  The list of
+all <tt>User</tt>s of a particular <tt>Value</tt> is called a
+<i>def-use</i> chain.  For example, let's say we have a
+<tt>Function*</tt> named <tt>F</tt> to a particular function
+<tt>foo</tt>. Finding all of the instructions that <i>use</i>
+<tt>foo</tt> is as simple as iterating over the <i>def-use</i> chain of
+<tt>F</tt>:
+
+<pre>
+Function* F = ...;
+
+for(Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i) {
+    if(Instruction* i = dyn_cast<Instruction>(*i)) {
+        cerr << "F is used in instruction:\n\t";
+        cerr << *i << "\n";
+    }
+}
+</pre>
+
+Alternately, it's common to have an instance of the <a
+href="/doxygen/classUser.html">User Class</a> and need to know what
+<tt>Value</tt>s are used by it.  The list of all <tt>Value</tt>s used
+by a <tt>User</tt> is known as a <i>use-def</i> chain.  Instances of
+class <tt>Instruction</tt> are common <tt>User</tt>s, so we might want
+to iterate over all of the values that a particular instruction uses
+(that is, the operands of the particular <tt>Instruction</tt>):
+
+<pre>
+Instruction* pi = ...;
+
+for(User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) {
+    Value* v = i->get();
+    ...
+}
+</pre>
+    
+
 <!--
   def-use chains ("finding all users of"): Value::use_begin/use_end
   use-def chains ("finding all values used"): User::op_begin/op_end [op=operand]
@@ -1389,6 +1428,6 @@
 <a href="mailto:sabre at nondot.org">Chris Lattner</a></address>
 <!-- Created: Tue Aug  6 15:00:33 CDT 2002 -->
 <!-- hhmts start -->
-Last modified: Tue Sep 10 10:19:56 CDT 2002
+Last modified: Wed Sep 11 15:48:49 CDT 2002
 <!-- hhmts end -->
 </font></body></html>





More information about the llvm-commits mailing list