X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FProgrammersManual.html;h=bacb0d6b81bf0946016ae4ac59c1f4ea2b4abb4d;hb=1ce764e083e8e9cf0014ef589f6b54e13cc2e4e6;hp=58ad5a1bce5f1cee41da7c42eef5618e4657e3ac;hpb=986e0c952fa0d15a08683bd5de5d1024f5f417e7;p=oota-llvm.git diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 58ad5a1bce5..bacb0d6b81b 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -24,6 +24,10 @@ dyn_cast<> templates
+ +Other useful references + |
+ +
-static Statistic<> NumXForms("mypassname\t- The # of times I did stuff"); +static Statistic<> NumXForms("mypassname", "The # of times I did stuff");
The Statistic template can emulate just about any data-type, but if you @@ -419,7 +504,7 @@ a report that looks like this:
49 cee - Number of setcc instruction eliminated 532 gcse - Number of loads removed 2919 gcse - Number of instructions removed - 86 indvars - Number of cannonical indvars added + 86 indvars - Number of canonical indvars added 87 indvars - Number of aux indvars removed 25 instcombine - Number of dead inst eliminate 434 instcombine - Number of insts combined @@ -492,7 +577,7 @@ contains:
// func is a pointer to a Function instance - for(Function::iterator i = func->begin(), e = func->end(); i != e; ++i) { + for (Function::iterator i = func->begin(), e = func->end(); i != e; ++i) { // print out the name of the basic block if it has one, and then the // number of instructions that it contains @@ -505,7 +590,7 @@ contains: Note that i can be used as if it were a pointer for the purposes of invoking member functions of the Instruction class. This is because the indirection operator is overloaded for the iterator -classes. In the above code, the expression i->size() is +classes. In the above code, the expression i->size() is exactly equivalent to (*i).size() just like you'd expect. @@ -520,7 +605,7 @@ that prints out each instruction in a BasicBlock:Of course, this example is strictly pedagogical, because it'd be much @@ -638,8 +713,8 @@ more complex example// blk is a pointer to a BasicBlock instance - for(BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) + for (BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) // the next statement works since operator<<(ostream&,...) // is overloaded for Instruction& cerr << *i << "\n"; @@ -557,7 +642,7 @@ stderr (Note: Dereferencing an InstIterator yields an #include "llvm/Support/InstIterator.h" ... // Suppose F is a ptr to a function -for(inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) +for (inst_iterator i = inst_begin(F), e = inst_end(F); i != e; ++i) cerr << **i << "\n";@@ -604,16 +689,6 @@ is semantically equivalent toInstruction* pinst = i;-Caveat emptor: The above syntax works only when you're not -working with dyn_cast. The template definition of dyn_cast isn't implemented to handle this yet, so you'll -still need the following in order for things to work properly: - --BasicBlock::iterator bbi = ...; -BranchInst* b = dyn_cast<BranchInst>(&*bbi); -- It's also possible to turn a class pointer into the corresponding iterator. Usually, this conversion is quite inexpensive. The following code snippet illustrates use of the conversion constructors @@ -625,7 +700,7 @@ over some structure: void printNextInstruction(Instruction* inst) { BasicBlock::iterator it(inst); ++it; // after this line, it refers to the instruction after *inst. - if(it != inst->getParent()->end()) cerr << *it << "\n"; + if (it != inst->getParent()->end()) cerr << *it << "\n"; }
You may have noticed that the previous example was a bit +oversimplified in that it did not deal with call sites generated by +'invoke' instructions. In this, and in other situations, you may find +that you want to treat CallInsts and InvokeInsts the +same way, even though their most-specific common base class is +Instruction, which includes lots of less closely-related +things. For these cases, LLVM provides a handy wrapper class called CallSite +. It is essentially a wrapper around an Instruction +pointer, with some methods that provide functionality common to +CallInsts and InvokeInsts.
+ +This class is supposed to have "value semantics". So it should be +passed by value, not by reference; it should not be dynamically +allocated or deallocated using operator new or operator +delete. It is efficiently copyable, assignable and constructable, +with costs equivalents to that of a bare pointer. (You will notice, if +you look at its definition, that it has only a single data member.)
+ +Function* F = ...; -for(Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i) { - if(Instruction* Inst = dyn_cast<Instruction>(*i)) { +for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i) { + if (Instruction *Inst = dyn_cast<Instruction>(*i)) { cerr << "F is used in instruction:\n"; cerr << *Inst << "\n"; } @@ -720,7 +820,7 @@ to iterate over all of the values that a particular instruction usesInstruction* pi = ...; -for(User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) { +for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) { Value* v = *i; ... } @@ -803,10 +903,10 @@ that BasicBlock, and a newly-created instruction we wish to insert before *pi, we do the following:-BasicBlock* pb = ...; -Instruction* pi = ...; -Instruction* newInst = new Instruction(...); -pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb + BasicBlock *pb = ...; + Instruction *pi = ...; + Instruction *newInst = new Instruction(...); + pb->getInstList().insert(pi, newInst); // inserts newInst before pi in pb@@ -817,9 +917,9 @@ instruction list: the instruction list of the enclosing basic block. Thus, we could have accomplished the same thing as the above code without being given a BasicBlock by doing:-Instruction* pi = ...; -Instruction* newInst = new Instruction(...); -pi->getParent()->getInstList().insert(pi, newInst); + Instruction *pi = ...; + Instruction *newInst = new Instruction(...); + pi->getParent()->getInstList().insert(pi, newInst);In fact, this sequence of steps occurs so frequently that the Instruction class and Instruction-derived classes @@ -866,8 +966,7 @@ For example:
Replacing individual instructions
Including "llvm/Transforms/Utils/BasicBlockUtils.h -" permits use of two very useful replace functions: +href="/doxygen/BasicBlockUtils_8h-source.html">llvm/Transforms/Utils/BasicBlockUtils.h" permits use of two very useful replace functions: ReplaceInstWithValue and ReplaceInstWithInst.
AllocaInst* instToReplace = ...; -ReplaceInstWithValue(*instToReplace->getParent(), instToReplace, +BasicBlock::iterator ii(instToReplace); +ReplaceInstWithValue(instToReplace->getParent()->getInstList(), ii, Constant::getNullValue(PointerType::get(Type::IntTy)));@@ -894,8 +994,9 @@ instruction. The following example illustrates the replacement of one
AllocaInst* instToReplace = ...; -ReplaceInstWithInst(*instToReplace->getParent(), instToReplace, - new AllocaInst(Type::IntTy, 0, "ptrToReplacedInt"); +BasicBlock::iterator ii(instToReplace); +ReplaceInstWithInst(instToReplace->getParent()->getInstList(), ii, + new AllocaInst(Type::IntTy, 0, "ptrToReplacedInt"));
-
+
-Returns true if the instruction has side effects, i.e. it is a call, +Returns true if the instruction writes to memory, i.e. it is a call, free, invoke, or store.
@@ -1171,7 +1272,7 @@ into a BasicBlock), and it has no name.
\end{itemize}
Returns the list of BasicBlocks. This is -neccesary to use when you need to update the list or perform a complex action +necessary to use when you need to update the list or perform a complex action that doesn't have a forwarding method.
@@ -1408,12 +1509,12 @@ These are forwarding methods that make it easy to access the contents of a
Returns the list of Arguments. This is -neccesary to use when you need to update the list or perform a complex action +necessary to use when you need to update the list or perform a complex action that doesn't have a forwarding method.
-
+
Returns the entry BasicBlock for the function. Because the entry block for the function is always the first block, @@ -1426,26 +1527,10 @@ This traverses the Type of the Function and returns the return type of the function, or the FunctionType of the actual function.
- -
- -Return true if the Function has a symbol table allocated to it and if -there is at least one entry in it.
-
Return a pointer to the SymbolTable for this -Function or a null pointer if one has not been allocated (because there -are no named values in the function).
- -
- -Return a pointer to the SymbolTable for this -Function or allocate a new SymbolTable if one is not already around. This -should only be used when adding elements to the SymbolTable, so that empty symbol tables are -not left laying around.
+Function.
@@ -1540,7 +1625,7 @@ list.
Returns the list of Functions. This is -neccesary to use when you need to update the list or perform a complex action +necessary to use when you need to update the list or perform a complex action that doesn't have a forwarding method.
@@ -1558,32 +1643,17 @@ list.
Returns the list of GlobalVariables. -This is neccesary to use when you need to update the list or perform a complex +This is necessary to use when you need to update the list or perform a complex action that doesn't have a forwarding method.
- -Return true if the Module has a symbol table allocated to it and if -there is at least one entry in it.
-
-Return a pointer to the SymbolTable for this -Module or a null pointer if one has not been allocated (because there -are no named values in the function).
- -
- -Return a pointer to the SymbolTable for this -Module or allocate a new SymbolTable if one is not already around. This -should only be used when adding elements to the SymbolTable, so that empty symbol tables are -not left laying around.
+Return a reference to the SymbolTable for +this Module.
@@ -1639,39 +1709,39 @@ ConstantArray etc for representing the various types of Constants.
- -\subsection{Important Subclasses of Constant} -\begin{itemize} +
+
-\subsection{Derived Types} -\begin{itemize} +