Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><title>LLVM Programmer's Manual</title></head> |
| 3 | |
| 4 | <body bgcolor=white> |
| 5 | |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 6 | <table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0> |
| 7 | <tr><td> <font size=+3 color="#EEEEFF" face="Georgia,Palatino,Times,Roman"><b>LLVM Programmer's Manual</b></font></td> |
| 8 | </tr></table> |
| 9 | |
| 10 | <ol> |
| 11 | <li><a href="#introduction">Introduction</a> |
| 12 | <li><a href="#general">General Information</a> |
| 13 | <ul> |
| 14 | <li><a href="#stl">The C++ Standard Template Library</a> |
| 15 | <li>The isa<>, cast<> and dyn_cast<> templates |
| 16 | </ul> |
Chris Lattner | a30ed38 | 2002-09-06 16:33:54 +0000 | [diff] [blame^] | 17 | <li><a href="#coreclasses">The Core LLVM Class Heirarchy Reference</a> |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 18 | <ul> |
| 19 | <li><a href="#Value">The <tt>Value</tt> class</a> |
| 20 | <ul> |
| 21 | <li><a href="#User">The <tt>User</tt> class</a> |
| 22 | <ul> |
| 23 | <li><a href="#Instruction">The <tt>Instruction</tt> class</a> |
| 24 | <ul> |
| 25 | <li> |
| 26 | <li> |
| 27 | </ul> |
| 28 | <li><a href="#GlobalValue">The <tt>GlobalValue</tt> class</a> |
| 29 | <ul> |
| 30 | <li><a href="#BasicBlock">The <tt>BasicBlock</tt> class</a> |
| 31 | <li><a href="#Function">The <tt>Function</tt> class</a> |
| 32 | <li><a href="#GlobalVariable">The <tt>GlobalVariable</tt> class</a> |
| 33 | </ul> |
| 34 | <li><a href="#Module">The <tt>Module</tt> class</a> |
| 35 | <li><a href="#Constant">The <tt>Constant</tt> class</a> |
| 36 | <ul> |
| 37 | <li> |
| 38 | <li> |
| 39 | </ul> |
| 40 | </ul> |
| 41 | <li><a href="#Type">The <tt>Type</tt> class</a> |
| 42 | <li><a href="#Argument">The <tt>Argument</tt> class</a> |
| 43 | </ul> |
| 44 | <li>The <tt>SymbolTable</tt> class |
| 45 | <li>The <tt>ilist</tt> and <tt>iplist</tt> classes |
| 46 | <ul> |
| 47 | <li>Creating, inserting, moving and deleting from LLVM lists |
| 48 | </ul> |
| 49 | <li>Important iterator invalidation semantics to be aware of |
| 50 | </ul> |
| 51 | |
| 52 | <!-- |
| 53 | III. Useful things to know about the LLVM source base: |
| 54 | |
| 55 | III.1 Useful links that introduce the STL |
| 56 | III.2 isa<>, cast<>, dyn_cast<> |
| 57 | III.3 Makefiles, useful options |
| 58 | III.4 How to use opt & analyze to debug stuff |
| 59 | III.5 How to write a regression test |
| 60 | III.6 DEBUG() and Statistics (-debug & -stats) |
| 61 | III.7 The -time-passes option |
| 62 | III.8 ... more as needed ... |
| 63 | |
| 64 | --> |
| 65 | |
| 66 | <p><b>Written by <a href="mailto:dhurjati@cs.uiuc.edu">Dinakar Dhurjati</a> |
| 67 | and <a href="mailto:sabre@nondot.org">Chris Lattner</a></b><p> |
| 68 | </ol> |
| 69 | |
| 70 | |
| 71 | <!-- *********************************************************************** --> |
| 72 | <table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0> |
| 73 | <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b> |
| 74 | <a name="introduction">Introduction |
| 75 | </b></font></td></tr></table><ul> |
| 76 | <!-- *********************************************************************** --> |
| 77 | |
| 78 | This document is meant to hi-light some of the important classes and interfaces |
| 79 | available in the LLVM source-base. This manual is not indended to explain what |
| 80 | LLVM is, how it works, and what LLVM code looks like. It assumes that you know |
| 81 | the basics of LLVM and are interested in writing transformations or otherwise |
| 82 | analyzing or manipulating the code.<p> |
| 83 | |
| 84 | This document should get you oriented so that you can find your way in the |
| 85 | continuously growing source code that makes up the LLVM infrastructure. Note |
| 86 | that this manual is not intended to serve as a replacement for reading the |
| 87 | source code, so if you think there should be a method in one of these classes to |
| 88 | do something, but it's not listed, check the source. Links to the <a |
| 89 | href="/doxygen/">doxygen</a> sources are provided to make this as easy as |
| 90 | possible.<p> |
| 91 | |
| 92 | The first section of this document describes general information that is useful |
| 93 | to know when working in the LLVM infrastructure, and the second describes the |
| 94 | Core LLVM classes. In the future this manual will be extended with information |
| 95 | describing how to use extension libraries, such as dominator information, CFG |
| 96 | traversal routines, and useful utilities like the <tt><a |
| 97 | href="/doxygen/InstVisitor_8h-source.html">InstVisitor</a></tt> template.<p> |
| 98 | |
| 99 | |
| 100 | <!-- *********************************************************************** --> |
| 101 | </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0> |
| 102 | <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b> |
| 103 | <a name="general">General Information |
| 104 | </b></font></td></tr></table><ul> |
| 105 | <!-- *********************************************************************** --> |
| 106 | |
| 107 | This section contains general information that is useful if you are working in |
| 108 | the LLVM source-base, but that isn't specific to any particular API.<p> |
| 109 | |
| 110 | |
| 111 | <!-- ======================================================================= --> |
| 112 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 113 | <tr><td> </td><td width="100%"> |
| 114 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 115 | <a name="stl">The C++ Standard Template Library</a> |
| 116 | </b></font></td></tr></table><ul> |
| 117 | |
| 118 | LLVM makes heavy use of the C++ Standard Template Library (STL), perhaps much |
| 119 | more than you are used to, or have seen before. Because of this, you might want |
| 120 | to do a little background reading in the techniques used and capabilities of the |
| 121 | library. There are many good pages that discuss the STL, and several books on |
| 122 | the subject that you can get, so it will not be discussed in this document.<p> |
| 123 | |
| 124 | Here are some useful links:<p> |
| 125 | <ol> |
| 126 | <li><a href="http://www.dinkumware.com/htm_cpl/index.html">Dinkumware C++ |
| 127 | Library reference</a> - an excellent reference for the STL and other parts of |
| 128 | the standard C++ library.<br> |
| 129 | |
| 130 | <li><a href="http://www.parashift.com/c++-faq-lite/">C++ Frequently Asked |
| 131 | Questions</a> |
| 132 | |
| 133 | <li><a href="http://www.sgi.com/tech/stl/">SGI's STL Programmer's Guide</a> - |
| 134 | Contains a useful <a |
| 135 | href="http://www.sgi.com/tech/stl/stl_introduction.html">Introduction to the |
| 136 | STL</a>. |
| 137 | |
| 138 | <li><a href="http://www.research.att.com/~bs/C++.html">Bjarne Stroustrup's C++ |
| 139 | Page</a> |
| 140 | |
| 141 | </ol><p> |
| 142 | |
| 143 | You are also encouraged to take a look at the <a |
| 144 | href="CodingStandards.html">LLVM Coding Standards</a> guide which focuses on how |
| 145 | to write maintainable code more than where to put your curly braces.<p> |
| 146 | |
| 147 | |
| 148 | |
| 149 | <!-- *********************************************************************** --> |
| 150 | </ul><table width="100%" bgcolor="#330077" border=0 cellpadding=4 cellspacing=0> |
| 151 | <tr><td align=center><font color="#EEEEFF" size=+2 face="Georgia,Palatino"><b> |
Chris Lattner | a30ed38 | 2002-09-06 16:33:54 +0000 | [diff] [blame^] | 152 | <a name="coreclasses">The Core LLVM Class Heirarchy Reference |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 153 | </b></font></td></tr></table><ul> |
| 154 | <!-- *********************************************************************** --> |
| 155 | |
| 156 | The Core LLVM classes are the primary means of representing the program being |
| 157 | inspected or transformed. The core LLVM classes are defined in header files in |
| 158 | the <tt>include/llvm/</tt> directory, and implemented in the <tt>lib/VMCore</tt> |
| 159 | directory.<p> |
| 160 | |
| 161 | |
| 162 | <!-- ======================================================================= --> |
| 163 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 164 | <tr><td> </td><td width="100%"> |
| 165 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 166 | <a name="Value">The <tt>Value</tt> class</a> |
| 167 | </b></font></td></tr></table><ul> |
| 168 | |
| 169 | <tt>#include "<a href="/doxygen/Value_8h-source.html">llvm/Value.h</a>"</tt></b><br> |
| 170 | doxygen info: <a href="/doxygen/classValue.html">Value Class</a><p> |
| 171 | |
| 172 | |
| 173 | The <tt>Value</tt> class is the most important class in LLVM Source base. It |
| 174 | represents a typed value that may be used (among other things) as an operand to |
| 175 | an instruction. There are many different types of <tt>Value</tt>s, such as <a |
| 176 | href="#Constant"><tt>Constant</tt></a>s, <a |
| 177 | href="#Argument"><tt>Argument</tt></a>s, and even <a |
| 178 | href="#Instruction"><tt>Instruction</tt></a>s and <a |
| 179 | href="#Function"><tt>Function</tt></a>s are <tt>Value</tt>s.<p> |
| 180 | |
| 181 | A particular <tt>Value</tt> may be used many times in the LLVM representation |
| 182 | for a program. For example, an incoming argument to a function (represented |
| 183 | with an instance of the <a href="#Argument">Argument</a> class) is "used" by |
| 184 | every instruction in the function that references the argument. To keep track |
| 185 | of this relationship, the <tt>Value</tt> class keeps a list of all of the <a |
| 186 | href="#User"><tt>User</tt></a>s that is using it (the <a |
| 187 | href="#User"><tt>User</tt></a> class is a base class for all nodes in the LLVM |
| 188 | graph that can refer to <tt>Value</tt>s). This use list is how LLVM represents |
| 189 | def-use information in the program, and is accessable through the <tt>use_</tt>* |
| 190 | methods, shown below.<p> |
| 191 | |
| 192 | Because LLVM is a typed representation, every LLVM <tt>Value</tt> is typed, and |
| 193 | this <a href="#Type">Type</a> is available through the <tt>getType()</tt> |
| 194 | method. <a name="#nameWarning">In addition, all LLVM values can be named. The |
| 195 | "name" of the <tt>Value</tt> is symbolic string printed in the LLVM code:<p> |
| 196 | |
| 197 | <pre> |
| 198 | %<b>foo</b> = add int 1, 2 |
| 199 | </pre> |
| 200 | |
| 201 | The name of this instruction is "foo". <b>NOTE</b> that the name of any value |
| 202 | may be missing (an empty string), so names should <b>ONLY</b> be used for |
| 203 | debugging (making the source code easier to read, debugging printouts), they |
| 204 | should not be used to keep track of values or map between them. For this |
| 205 | purpose, use a <tt>std::map</tt> of pointers to the <tt>Value</tt> itself |
| 206 | instead.<p> |
| 207 | |
| 208 | One important aspect of LLVM is that there is no distinction between an SSA |
| 209 | variable and the operation that produces it. Because of this, any reference to |
| 210 | the value produced by an instruction (or the value available as an incoming |
| 211 | argument, for example) is represented as a direct pointer to the class that |
| 212 | represents this value. Although this may take some getting used to, it |
| 213 | simplifies the representation and makes it easier to manipulate.<p> |
| 214 | |
| 215 | |
| 216 | <!-- _______________________________________________________________________ --> |
| 217 | </ul><h4><a name="m_Value"><hr size=0>Important Public Members of |
| 218 | the <tt>Value</tt> class</h4><ul> |
| 219 | |
| 220 | <li><tt>Value::use_iterator</tt> - Typedef for iterator over the use-list<br> |
| 221 | <tt>Value::use_const_iterator</tt> |
| 222 | - Typedef for const_iterator over the use-list<br> |
| 223 | <tt>unsigned use_size()</tt> - Returns the number of users of the value.<br> |
| 224 | <tt>bool use_empty()</tt> - Returns true if there are no users.<br> |
| 225 | <tt>use_iterator use_begin()</tt> |
| 226 | - Get an iterator to the start of the use-list.<br> |
| 227 | <tt>use_iterator use_end()</tt> |
| 228 | - Get an iterator to the end of the use-list.<br> |
| 229 | <tt><a href="#User">User</a> *use_back()</tt> |
| 230 | - Returns the last element in the list.<p> |
| 231 | |
| 232 | These methods are the interface to access the def-use information in LLVM. As with all other iterators in LLVM, the naming conventions follow the conventions defined by the <a href="#stl">STL</a>.<p> |
| 233 | |
| 234 | <li><tt><a href="#Type">Type</a> *getType() const</tt><p> |
| 235 | This method returns the Type of the Value. |
| 236 | |
| 237 | <li><tt>bool hasName() const</tt><br> |
| 238 | <tt>std::string getName() const</tt><br> |
| 239 | <tt>void setName(const std::string &Name)</tt><p> |
| 240 | |
| 241 | This family of methods is used to access and assign a name to a <tt>Value</tt>, |
| 242 | be aware of the <a href="#nameWarning">precaution above</a>.<p> |
| 243 | |
| 244 | |
| 245 | <li><tt>void replaceAllUsesWith(Value *V)</tt><p> |
| 246 | |
| 247 | This method traverses the use list of a <tt>Value</tt> changing all <a |
| 248 | href="#User"><tt>User</tt>'s</a> of the current value to refer to "<tt>V</tt>" |
| 249 | instead. For example, if you detect that an instruction always produces a |
| 250 | constant value (for example through constant folding), you can replace all uses |
| 251 | of the instruction with the constant like this:<p> |
| 252 | |
| 253 | <pre> |
| 254 | Inst->replaceAllUsesWith(ConstVal); |
| 255 | </pre><p> |
| 256 | |
| 257 | |
| 258 | |
| 259 | <!-- ======================================================================= --> |
| 260 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 261 | <tr><td> </td><td width="100%"> |
| 262 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 263 | <a name="User">The <tt>User</tt> class</a> |
| 264 | </b></font></td></tr></table><ul> |
| 265 | |
| 266 | <tt>#include "<a href="/doxygen/User_8h-source.html">llvm/User.h</a>"</tt></b><br> |
| 267 | doxygen info: <a href="/doxygen/classUser.html">User Class</a><br> |
| 268 | Superclass: <a href="#Value"><tt>Value</tt></a><p> |
| 269 | |
| 270 | |
| 271 | The <tt>User</tt> class is the common base class of all LLVM nodes that may |
| 272 | refer to <a href="#Value"><tt>Value</tt></a>s. It exposes a list of "Operands" |
| 273 | that are all of the <a href="#Value"><tt>Value</tt></a>s that the User is |
| 274 | referring to. The <tt>User</tt> class itself is a subclass of |
| 275 | <tt>Value</tt>.<p> |
| 276 | |
| 277 | The operands of a <tt>User</tt> point directly to the LLVM <a |
| 278 | href="#Value"><tt>Value</tt></a> that it refers to. Because LLVM uses Static |
| 279 | Single Assignment (SSA) form, there can only be one definition referred to, |
| 280 | allowing this direct connection. This connection provides the use-def |
| 281 | information in LLVM.<p> |
| 282 | |
| 283 | <!-- _______________________________________________________________________ --> |
| 284 | </ul><h4><a name="m_User"><hr size=0>Important Public Members of |
| 285 | the <tt>User</tt> class</h4><ul> |
| 286 | |
| 287 | The <tt>User</tt> class exposes the operand list in two ways: through an index |
| 288 | access interface and through an iterator based interface.<p> |
| 289 | |
| 290 | <li><tt>Value *getOperand(unsigned i)</tt><br> |
| 291 | <tt>unsigned getNumOperands()</tt><p> |
| 292 | |
| 293 | These two methods expose the operands of the <tt>User</tt> in a convenient form |
| 294 | for direct access.<p> |
| 295 | |
| 296 | <li><tt>User::op_iterator</tt> - Typedef for iterator over the operand list<br> |
| 297 | <tt>User::op_const_iterator</tt> |
| 298 | <tt>use_iterator op_begin()</tt> |
| 299 | - Get an iterator to the start of the operand list.<br> |
| 300 | <tt>use_iterator op_end()</tt> |
| 301 | - Get an iterator to the end of the operand list.<p> |
| 302 | |
| 303 | Together, these methods make up the iterator based interface to the operands of |
| 304 | a <tt>User</tt>.<p> |
| 305 | |
| 306 | |
| 307 | |
| 308 | <!-- ======================================================================= --> |
| 309 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 310 | <tr><td> </td><td width="100%"> |
| 311 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 312 | <a name="Instruction">The <tt>Instruction</tt> class</a> |
| 313 | </b></font></td></tr></table><ul> |
| 314 | |
| 315 | <tt>#include "<a |
| 316 | href="/doxygen/Instruction_8h-source.html">llvm/Instruction.h</a>"</tt></b><br> |
| 317 | doxygen info: <a href="/doxygen/classInstruction.html">Instruction Class</a><br> |
| 318 | Superclasses: <a href="#User"><tt>User</tt></a>, <a |
| 319 | href="#Value"><tt>Value</tt></a><p> |
| 320 | |
| 321 | The <tt>Instruction</tt> class is the common base class for all LLVM |
| 322 | instructions. It provides only a few methods, but is a very commonly used |
| 323 | class. The primary data tracked by the <tt>Instruction</tt> class itself is the |
| 324 | opcode (instruction type) and the parent <a |
| 325 | href="#BasicBlock"><tt>BasicBlock</tt></a> the <tt>Instruction</tt> is embedded |
| 326 | into. To represent a specific type of instruction, one of many subclasses of |
| 327 | <tt>Instruction</tt> are used.<p> |
| 328 | |
| 329 | Because the <tt>Instruction</tt> class subclasses the <a |
| 330 | href="#User"><tt>User</tt></a> class, its operands can be accessed in the same |
| 331 | way as for other <a href="#User"><tt>User</tt></a>s (with the |
| 332 | <tt>getOperand()</tt>/<tt>getNumOperands()</tt> and |
| 333 | <tt>op_begin()</tt>/<tt>op_end()</tt> methods).<p> |
| 334 | |
| 335 | |
| 336 | <!-- _______________________________________________________________________ --> |
| 337 | </ul><h4><a name="m_Instruction"><hr size=0>Important Public Members of |
| 338 | the <tt>Instruction</tt> class</h4><ul> |
| 339 | |
| 340 | <li><tt><a href="#BasicBlock">BasicBlock</a> *getParent()</tt><p> |
| 341 | |
| 342 | Returns the <a href="#BasicBlock"><tt>BasicBlock</tt></a> that this |
| 343 | <tt>Instruction</tt> is embedded into.<p> |
| 344 | |
| 345 | <li><tt>bool hasSideEffects()</tt><p> |
| 346 | |
| 347 | Returns true if the instruction has side effects, i.e. it is a <tt>call</tt>, |
| 348 | <tt>free</tt>, <tt>invoke</tt>, or <tt>store</tt>.<p> |
| 349 | |
| 350 | <li><tt>unsigned getOpcode()</tt><p> |
| 351 | |
| 352 | Returns the opcode for the <tt>Instruction</tt>.<p> |
| 353 | |
| 354 | <!-- |
| 355 | |
| 356 | \subsection{Subclasses of Instruction :} |
| 357 | \begin{itemize} |
| 358 | <li>BinaryOperator : This subclass of Instruction defines a general interface to the all the instructions involvong binary operators in LLVM. |
| 359 | \begin{itemize} |
| 360 | <li><tt>bool swapOperands()</tt>: Exchange the two operands to this instruction. If the instruction cannot be reversed (i.e. if it's a Div), it returns true. |
| 361 | \end{itemize} |
| 362 | <li>TerminatorInst : This subclass of Instructions defines an interface for all instructions that can terminate a BasicBlock. |
| 363 | \begin{itemize} |
| 364 | <li> <tt>unsigned getNumSuccessors()</tt>: Returns the number of successors for this terminator instruction. |
| 365 | <li><tt>BasicBlock *getSuccessor(unsigned i)</tt>: As the name suggests returns the ith successor BasicBlock. |
| 366 | <li><tt>void setSuccessor(unsigned i, BasicBlock *B)</tt>: sets BasicBlock B as the ith succesor to this terminator instruction. |
| 367 | \end{itemize} |
| 368 | |
| 369 | <li>PHINode : This represents the PHI instructions in the SSA form. |
| 370 | \begin{itemize} |
| 371 | <li><tt> unsigned getNumIncomingValues()</tt>: Returns the number of incoming edges to this PHI node. |
| 372 | <li><tt> Value *getIncomingValue(unsigned i)</tt>: Returns the ith incoming Value. |
| 373 | <li><tt>void setIncomingValue(unsigned i, Value *V)</tt>: Sets the ith incoming Value as V |
| 374 | <li><tt>BasicBlock *getIncomingBlock(unsigned i)</tt>: Returns the Basic Block corresponding to the ith incoming Value. |
| 375 | <li><tt> void addIncoming(Value *D, BasicBlock *BB)</tt>: |
| 376 | Add an incoming value to the end of the PHI list |
| 377 | <li><tt> int getBasicBlockIndex(const BasicBlock *BB) const</tt>: |
| 378 | Returns the first index of the specified basic block in the value list for this PHI. Returns -1 if no instance. |
| 379 | \end{itemize} |
| 380 | <li>CastInst : In LLVM all casts have to be done through explicit cast instructions. CastInst defines the interface to the cast instructions. |
| 381 | <li>CallInst : This defines an interface to the call instruction in LLVM. ARguments to the function are nothing but operands of the instruction. |
| 382 | \begin{itemize} |
| 383 | <li>: <tt>Function *getCalledFunction()</tt>: Returns a handle to the function that is being called by this Function. |
| 384 | \end{itemize} |
| 385 | <li>LoadInst, StoreInst, GetElemPtrInst : These subclasses represent load, store and getelementptr instructions in LLVM. |
| 386 | \begin{itemize} |
| 387 | <li><tt>Value * getPointerOperand ()</tt>: Returns the Pointer Operand which is typically the 0th operand. |
| 388 | \end{itemize} |
| 389 | <li>BranchInst : This is a subclass of TerminatorInst and defines the interface for conditional and unconditional branches in LLVM. |
| 390 | \begin{itemize} |
| 391 | <li><tt>bool isConditional()</tt>: Returns true if the branch is a conditional branch else returns false |
| 392 | <li> <tt>Value *getCondition()</tt>: Returns the condition if it is a conditional branch else returns null. |
| 393 | <li> <tt>void setUnconditionalDest(BasicBlock *Dest)</tt>: Changes the current branch to an unconditional one targetting the specified block. |
| 394 | \end{itemize} |
| 395 | |
| 396 | \end{itemize} |
| 397 | |
| 398 | --> |
| 399 | |
| 400 | |
| 401 | <!-- ======================================================================= --> |
| 402 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 403 | <tr><td> </td><td width="100%"> |
| 404 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 405 | <a name="BasicBlock">The <tt>BasicBlock</tt> class</a> |
| 406 | </b></font></td></tr></table><ul> |
| 407 | |
| 408 | <tt>#include "<a |
| 409 | href="/doxygen/BasicBlock_8h-source.html">llvm/BasicBlock.h</a>"</tt></b><br> |
| 410 | doxygen info: <a href="/doxygen/classBasicBlock.html">BasicBlock Class</a><br> |
| 411 | Superclass: <a href="#Value"><tt>Value</tt></a><p> |
| 412 | |
| 413 | |
| 414 | This class represents a single entry multiple exit section of the code, commonly |
| 415 | known as a basic block by the compiler community. The <tt>BasicBlock</tt> class |
| 416 | maintains a list of <a href="#Instruction"><tt>Instruction</tt></a>s, which form |
| 417 | the body of the block. Matching the language definition, the last element of |
| 418 | this list of instructions is always a terminator instruction (a subclass of the |
| 419 | <a href="#TerminatorInst"><tt>TerminatorInst</tt></a> class).<p> |
| 420 | |
| 421 | In addition to tracking the list of instructions that make up the block, the |
| 422 | <tt>BasicBlock</tt> class also keeps track of the <a |
| 423 | href="#Function"><tt>Function</tt></a> that it is embedded into.<p> |
| 424 | |
| 425 | Note that <tt>BasicBlock</tt>s themselves are <a |
| 426 | href="#Value"><tt>Value</tt></a>s, because they are referenced by instructions |
| 427 | like branches and can go in the switch tables. <tt>BasicBlock</tt>s have type |
| 428 | <tt>label</tt>.<p> |
| 429 | |
| 430 | |
| 431 | <!-- _______________________________________________________________________ --> |
| 432 | </ul><h4><a name="m_BasicBlock"><hr size=0>Important Public Members of |
| 433 | the <tt>BasicBlock</tt> class</h4><ul> |
| 434 | |
| 435 | <li><tt>BasicBlock(const std::string &Name = "", <a |
| 436 | href="#Function">Function</a> *Parent = 0)</tt><p> |
| 437 | |
| 438 | The <tt>BasicBlock</tt> constructor is used to create new basic blocks for |
| 439 | insertion into a function. The constructor simply takes a name for the new |
| 440 | block, and optionally a <a href="#Function"><tt>Function</tt></a> to insert it |
| 441 | into. If the <tt>Parent</tt> parameter is specified, the new |
| 442 | <tt>BasicBlock</tt> is automatically inserted at the end of the specified <a |
| 443 | href="#Function"><tt>Function</tt></a>, if not specified, the BasicBlock must be |
| 444 | manually inserted into the <a href="#Function"><tt>Function</tt></a>.<p> |
| 445 | |
| 446 | <li><tt>BasicBlock::iterator</tt> - Typedef for instruction list iterator<br> |
| 447 | <tt>BasicBlock::const_iterator</tt> - Typedef for const_iterator.<br> |
| 448 | <tt>begin()</tt>, <tt>end()</tt>, <tt>front()</tt>, <tt>back()</tt>, |
| 449 | <tt>size()</tt>, <tt>empty()</tt>, <tt>rbegin()</tt>, <tt>rend()</tt><p> |
| 450 | |
| 451 | These methods and typedefs are forwarding functions that have the same semantics |
| 452 | as the standard library methods of the same names. These methods expose the |
| 453 | underlying instruction list of a basic block in a way that is easy to |
| 454 | manipulate. To get the full complement of container operations (including |
| 455 | operations to update the list), you must use the <tt>getInstList()</tt> |
| 456 | method.<p> |
| 457 | |
| 458 | <li><tt>BasicBlock::InstListType &getInstList()</tt><p> |
| 459 | |
| 460 | This method is used to get access to the underlying container that actually |
| 461 | holds the Instructions. This method must be used when there isn't a forwarding |
| 462 | function in the <tt>BasicBlock</tt> class for the operation that you would like |
| 463 | to perform. Because there are no forwarding functions for "updating" |
| 464 | operations, you need to use this if you want to update the contents of a |
| 465 | <tt>BasicBlock</tt>.<p> |
| 466 | |
| 467 | <li><tt><A href="#Function">Function</a> *getParent()</tt><p> |
| 468 | |
| 469 | Returns a pointer to <a href="#Function"><tt>Function</tt></a> the block is |
| 470 | embedded into, or a null pointer if it is homeless.<p> |
| 471 | |
| 472 | <li><tt><a href="#TerminatorInst">TerminatorInst</a> *getTerminator()</tt><p> |
| 473 | |
| 474 | Returns a pointer to the terminator instruction that appears at the end of the |
| 475 | <tt>BasicBlock</tt>. If there is no terminator instruction, or if the last |
| 476 | instruction in the block is not a terminator, then a null pointer is |
| 477 | returned.<p> |
| 478 | |
| 479 | |
| 480 | <!-- ======================================================================= --> |
| 481 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 482 | <tr><td> </td><td width="100%"> |
| 483 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 484 | <a name="GlobalValue">The <tt>GlobalValue</tt> class</a> |
| 485 | </b></font></td></tr></table><ul> |
| 486 | |
| 487 | <tt>#include "<a |
| 488 | href="/doxygen/GlobalValue_8h-source.html">llvm/GlobalValue.h</a>"</tt></b><br> |
| 489 | doxygen info: <a href="/doxygen/classGlobalValue.html">GlobalValue Class</a><br> |
| 490 | Superclasses: <a href="#User"><tt>User</tt></a>, <a |
| 491 | href="#Value"><tt>Value</tt></a><p> |
| 492 | |
| 493 | Global values (<A href="#GlobalVariable"><tt>GlobalVariable</tt></a>s or <a |
| 494 | href="#Function"><tt>Function</tt></a>s) are the only LLVM values that are |
| 495 | visible in the bodies of all <a href="#Function"><tt>Function</tt></a>s. |
| 496 | Because they are visible at global scope, they are also subject to linking with |
| 497 | other globals defined in different translation units. To control the linking |
| 498 | process, <tt>GlobalValue</tt>s know their linkage rules. Specifically, |
| 499 | <tt>GlobalValue</tt>s know whether they have internal or external linkage.<p> |
| 500 | |
| 501 | If a <tt>GlobalValue</tt> has internal linkage (equivalent to being |
| 502 | <tt>static</tt> in C), it is not visible to code outside the current translation |
| 503 | unit, and does not participate in linking. If it has external linkage, it is |
| 504 | visible to external code, and does participate in linking. In addition to |
| 505 | linkage information, <tt>GlobalValue</tt>s keep track of which <a |
| 506 | href="#Module"><tt>Module</tt></a> they are currently part of.<p> |
| 507 | |
| 508 | Because <tt>GlobalValue</tt>s are memory objects, they are always referred to by |
| 509 | their address. As such, the <a href="#Type"><tt>Type</tt></a> of a global is |
| 510 | always a pointer to its contents. This is explained in the LLVM Language |
| 511 | Reference Manual.<p> |
| 512 | |
| 513 | |
| 514 | <!-- _______________________________________________________________________ --> |
| 515 | </ul><h4><a name="m_GlobalValue"><hr size=0>Important Public Members of |
| 516 | the <tt>GlobalValue</tt> class</h4><ul> |
| 517 | |
| 518 | <li><tt>bool hasInternalLinkage() const</tt><br> |
| 519 | <tt>bool hasExternalLinkage() const</tt><br> |
| 520 | <tt>void setInternalLinkage(bool HasInternalLinkage)</tt><p> |
| 521 | |
| 522 | These methods manipulate the linkage characteristics of the |
| 523 | <tt>GlobalValue</tt>.<p> |
| 524 | |
| 525 | <li><tt><a href="#Module">Module</a> *getParent()</tt><p> |
| 526 | |
| 527 | This returns the <a href="#Module"><tt>Module</tt></a> that the GlobalValue is |
| 528 | currently embedded into.<p> |
| 529 | |
| 530 | |
| 531 | |
| 532 | <!-- ======================================================================= --> |
| 533 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 534 | <tr><td> </td><td width="100%"> |
| 535 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 536 | <a name="Function">The <tt>Function</tt> class</a> |
| 537 | </b></font></td></tr></table><ul> |
| 538 | |
| 539 | <tt>#include "<a |
| 540 | href="/doxygen/Function_8h-source.html">llvm/Function.h</a>"</tt></b><br> |
| 541 | doxygen info: <a href="/doxygen/classFunction.html">Function Class</a><br> |
| 542 | Superclasses: <a href="#GlobalValue"><tt>GlobalValue</tt></a>, <a |
| 543 | href="#User"><tt>User</tt></a>, <a href="#Value"><tt>Value</tt></a><p> |
| 544 | |
| 545 | The <tt>Function</tt> class represents a single procedure in LLVM. It is |
| 546 | actually one of the more complex classes in the LLVM heirarchy because it must |
| 547 | keep track of a large amount of data. The <tt>Function</tt> class keeps track |
| 548 | of a list of <a href="#BasicBlock"><tt>BasicBlock</tt></a>s, a list of formal <a |
| 549 | href="#Argument"><tt>Argument</tt></a>s, and a <a |
| 550 | href="#SymbolTable"><tt>SymbolTable</tt></a>.<p> |
| 551 | |
| 552 | The list of <a href="#BasicBlock"><tt>BasicBlock</tt></a>s is the most commonly |
| 553 | used part of <tt>Function</tt> objects. The list imposes an implicit ordering |
| 554 | of the blocks in the function, which indicate how the code will be layed out by |
| 555 | the backend. Additionally, the first <a |
| 556 | href="#BasicBlock"><tt>BasicBlock</tt></a> is the implicit entry node for the |
| 557 | <tt>Function</tt>. It is not legal in LLVM explicitly branch to this initial |
| 558 | block. There are no implicit exit nodes, and in fact there may be multiple exit |
| 559 | nodes from a single <tt>Function</tt>. If the <a |
| 560 | href="#BasicBlock"><tt>BasicBlock</tt></a> list is empty, this indicates that |
| 561 | the <tt>Function</tt> is actually a function declaration: the actual body of the |
| 562 | function hasn't been linked in yet.<p> |
| 563 | |
| 564 | In addition to a list of <a href="#BasicBlock"><tt>BasicBlock</tt></a>s, the |
| 565 | <tt>Function</tt> class also keeps track of the list of formal <a |
| 566 | href="#Argument"><tt>Argument</tt></a>s that the function receives. This |
| 567 | container manages the lifetime of the <a href="#Argument"><tt>Argument</tt></a> |
| 568 | nodes, just like the <a href="#BasicBlock"><tt>BasicBlock</tt></a> list does for |
| 569 | the <a href="#BasicBlock"><tt>BasicBlock</tt></a>s.<p> |
| 570 | |
| 571 | The <a href="#SymbolTable"><tt>SymbolTable</tt></a> is a very rarely used LLVM |
| 572 | feature that is only used when you have to look up a value by name. Aside from |
| 573 | that, the <a href="#SymbolTable"><tt>SymbolTable</tt></a> is used internally to |
| 574 | make sure that there are not conflicts between the names of <a |
| 575 | href="#Instruction"><tt>Instruction</tt></a>s, <a |
| 576 | href="#BasicBlock"><tt>BasicBlock</tt></a>s, or <a |
| 577 | href="#Argument"><tt>Argument</tt></a>s in the function body.<p> |
| 578 | |
| 579 | |
| 580 | <!-- _______________________________________________________________________ --> |
| 581 | </ul><h4><a name="m_Function"><hr size=0>Important Public Members of |
| 582 | the <tt>Function</tt> class</h4><ul> |
| 583 | |
| 584 | <li><tt>Function(const <a href="#FunctionType">FunctionType</a> *Ty, bool isInternal, const std::string &N = "")</tt><p> |
| 585 | |
| 586 | Constructor used when you need to create new <tt>Function</tt>s to add the the |
| 587 | program. The constructor must specify the type of the function to create and |
| 588 | whether or not it should start out with internal or external linkage.<p> |
| 589 | |
| 590 | <li><tt>bool isExternal()</tt><p> |
| 591 | |
| 592 | Return whether or not the <tt>Function</tt> has a body defined. If the function |
| 593 | is "external", it does not have a body, and thus must be resolved by linking |
| 594 | with a function defined in a different translation unit.<p> |
| 595 | |
| 596 | |
| 597 | <li><tt>Function::iterator</tt> - Typedef for basic block list iterator<br> |
| 598 | <tt>Function::const_iterator</tt> - Typedef for const_iterator.<br> |
| 599 | <tt>begin()</tt>, <tt>end()</tt>, <tt>front()</tt>, <tt>back()</tt>, |
| 600 | <tt>size()</tt>, <tt>empty()</tt>, <tt>rbegin()</tt>, <tt>rend()</tt><p> |
| 601 | |
| 602 | These are forwarding methods that make it easy to access the contents of a |
| 603 | <tt>Function</tt> object's <a href="#BasicBlock"><tt>BasicBlock</tt></a> |
| 604 | list.<p> |
| 605 | |
| 606 | <li><tt>Function::BasicBlockListType &getBasicBlockList()</tt><p> |
| 607 | |
| 608 | Returns the list of <a href="#BasicBlock"><tt>BasicBlock</tt></a>s. This is |
| 609 | neccesary to use when you need to update the list or perform a complex action |
| 610 | that doesn't have a forwarding method.<p> |
| 611 | |
| 612 | |
| 613 | <li><tt>Function::aiterator</tt> - Typedef for the argument list iterator<br> |
| 614 | <tt>Function::const_aiterator</tt> - Typedef for const_iterator.<br> |
| 615 | <tt>abegin()</tt>, <tt>aend()</tt>, <tt>afront()</tt>, <tt>aback()</tt>, |
| 616 | <tt>asize()</tt>, <tt>aempty()</tt>, <tt>arbegin()</tt>, <tt>arend()</tt><p> |
| 617 | |
| 618 | These are forwarding methods that make it easy to access the contents of a |
| 619 | <tt>Function</tt> object's <a href="#Argument"><tt>Argument</tt></a> list.<p> |
| 620 | |
| 621 | <li><tt>Function::ArgumentListType &getArgumentList()</tt><p> |
| 622 | |
| 623 | Returns the list of <a href="#Argument"><tt>Argument</tt></a>s. This is |
| 624 | neccesary to use when you need to update the list or perform a complex action |
| 625 | that doesn't have a forwarding method.<p> |
| 626 | |
| 627 | |
| 628 | |
| 629 | <li><tt><a href="#BasicBlock">BasicBlock</a> &getEntryNode()</tt><p> |
| 630 | |
| 631 | Returns the entry <a href="#BasicBlock"><tt>BasicBlock</tt></a> for the |
| 632 | function. Because the entry block for the function is always the first block, |
| 633 | this returns the first block of the <tt>Function</tt>.<p> |
| 634 | |
| 635 | <li><tt><a href="#Type">Type</a> *getReturnType()</tt><br> |
| 636 | <tt><a href="#FunctionType">FunctionType</a> *getFunctionType()</tt><p> |
| 637 | |
| 638 | This traverses the <a href="#Type"><tt>Type</tt></a> of the <tt>Function</tt> |
| 639 | and returns the return type of the function, or the <a |
| 640 | href="#FunctionType"><tt>FunctionType</tt></a> of the actual function.<p> |
| 641 | |
| 642 | |
| 643 | <li><tt>bool hasSymbolTable() const</tt><p> |
| 644 | |
| 645 | Return true if the <tt>Function</tt> has a symbol table allocated to it and if |
| 646 | there is at least one entry in it.<p> |
| 647 | |
| 648 | <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTable()</tt><p> |
| 649 | |
| 650 | Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this |
| 651 | <tt>Function</tt> or a null pointer if one has not been allocated (because there |
| 652 | are no named values in the function).<p> |
| 653 | |
| 654 | <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTableSure()</tt><p> |
| 655 | |
| 656 | Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this |
| 657 | <tt>Function</tt> or allocate a new <a |
| 658 | href="#SymbolTable"><tt>SymbolTable</tt></a> if one is not already around. This |
| 659 | should only be used when adding elements to the <a |
| 660 | href="#SymbolTable"><tt>SymbolTable</tt></a>, so that empty symbol tables are |
| 661 | not left laying around.<p> |
| 662 | |
| 663 | |
| 664 | |
| 665 | <!-- ======================================================================= --> |
| 666 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 667 | <tr><td> </td><td width="100%"> |
| 668 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 669 | <a name="GlobalVariable">The <tt>GlobalVariable</tt> class</a> |
| 670 | </b></font></td></tr></table><ul> |
| 671 | |
| 672 | <tt>#include "<a |
| 673 | href="/doxygen/GlobalVariable_8h-source.html">llvm/GlobalVariable.h</a>"</tt></b><br> |
| 674 | doxygen info: <a href="/doxygen/classGlobalVariable.html">GlobalVariable Class</a><br> |
| 675 | Superclasses: <a href="#GlobalValue"><tt>GlobalValue</tt></a>, <a |
| 676 | href="#User"><tt>User</tt></a>, <a href="#Value"><tt>Value</tt></a><p> |
| 677 | |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 678 | Global variables are represented with the (suprise suprise) |
| 679 | <tt>GlobalVariable</tt> class. Like functions, <tt>GlobalVariable</tt>s are |
| 680 | also subclasses of <a href="#GlobalValue"><tt>GlobalValue</tt></a>, and as such |
| 681 | are always referenced by their address (global values must live in memory, so |
| 682 | their "name" refers to their address). Global variables may have an initial |
| 683 | value (which must be a <a href="#Constant"><tt>Constant</tt></a>), and if they |
| 684 | have an initializer, they may be marked as "constant" themselves (indicating |
| 685 | that their contents never change at runtime).<p> |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 686 | |
| 687 | |
| 688 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 689 | </ul><h4><a name="m_GlobalVariable"><hr size=0>Important Public Members of the |
| 690 | <tt>GlobalVariable</tt> class</h4><ul> |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 691 | |
| 692 | <li><tt>GlobalVariable(const <a href="#Type">Type</a> *Ty, bool isConstant, bool |
| 693 | isInternal, <a href="#Constant">Constant</a> *Initializer = 0, const std::string |
| 694 | &Name = "")</tt><p> |
| 695 | |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 696 | Create a new global variable of the specified type. If <tt>isConstant</tt> is |
| 697 | true then the global variable will be marked as unchanging for the program, and |
| 698 | if <tt>isInternal</tt> is true the resultant global variable will have internal |
| 699 | linkage. Optionally an initializer and name may be specified for the global variable as well.<p> |
| 700 | |
| 701 | |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 702 | <li><tt>bool isConstant() const</tt><p> |
| 703 | |
| 704 | Returns true if this is a global variable is known not to be modified at |
| 705 | runtime.<p> |
| 706 | |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 707 | |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 708 | <li><tt>bool hasInitializer()</tt><p> |
| 709 | |
| 710 | Returns true if this <tt>GlobalVariable</tt> has an intializer.<p> |
| 711 | |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 712 | |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 713 | <li><tt><a href="#Constant">Constant</a> *getInitializer()</tt><p> |
| 714 | |
Chris Lattner | 0377de4 | 2002-09-06 14:50:55 +0000 | [diff] [blame] | 715 | Returns the intial value for a <tt>GlobalVariable</tt>. It is not legal to call |
| 716 | this method if there is no initializer.<p> |
| 717 | |
| 718 | |
| 719 | <!-- ======================================================================= --> |
| 720 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 721 | <tr><td> </td><td width="100%"> |
| 722 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 723 | <a name="Module">The <tt>Module</tt> class</a> |
| 724 | </b></font></td></tr></table><ul> |
| 725 | |
| 726 | <tt>#include "<a |
| 727 | href="/doxygen/Module_8h-source.html">llvm/Module.h</a>"</tt></b><br> |
| 728 | doxygen info: <a href="/doxygen/classModule.html">Module Class</a><p> |
| 729 | |
| 730 | The <tt>Module</tt> class represents the top level structure present in LLVM |
| 731 | programs. An LLVM module is effectively either a translation unit of the |
| 732 | original program or a combination of several translation units merged by the |
| 733 | linker. The <tt>Module</tt> class keeps track of a list of <a |
| 734 | href="#Function"><tt>Function</tt></a>s, a list of <a |
| 735 | href="#GlobalVariable"><tt>GlobalVariable</tt></a>s, and a <a |
| 736 | href="#SymbolTable"><tt>SymbolTable</tt></a>. Additionally, it contains a few |
| 737 | helpful member functions that try to make common operations easy.<p> |
| 738 | |
| 739 | |
| 740 | <!-- _______________________________________________________________________ --> |
| 741 | </ul><h4><a name="m_Module"><hr size=0>Important Public Members of the |
| 742 | <tt>Module</tt> class</h4><ul> |
| 743 | |
| 744 | <li><tt>Module::iterator</tt> - Typedef for function list iterator<br> |
| 745 | <tt>Module::const_iterator</tt> - Typedef for const_iterator.<br> |
| 746 | <tt>begin()</tt>, <tt>end()</tt>, <tt>front()</tt>, <tt>back()</tt>, |
| 747 | <tt>size()</tt>, <tt>empty()</tt>, <tt>rbegin()</tt>, <tt>rend()</tt><p> |
| 748 | |
| 749 | These are forwarding methods that make it easy to access the contents of a |
| 750 | <tt>Module</tt> object's <a href="#Function"><tt>Function</tt></a> |
| 751 | list.<p> |
| 752 | |
| 753 | <li><tt>Module::FunctionListType &getFunctionList()</tt><p> |
| 754 | |
| 755 | Returns the list of <a href="#Function"><tt>Function</tt></a>s. This is |
| 756 | neccesary to use when you need to update the list or perform a complex action |
| 757 | that doesn't have a forwarding method.<p> |
| 758 | |
| 759 | <!-- Global Variable --> |
| 760 | <hr size=0> |
| 761 | |
| 762 | <li><tt>Module::giterator</tt> - Typedef for global variable list iterator<br> |
| 763 | <tt>Module::const_giterator</tt> - Typedef for const_iterator.<br> |
| 764 | <tt>gbegin()</tt>, <tt>gend()</tt>, <tt>gfront()</tt>, <tt>gback()</tt>, |
| 765 | <tt>gsize()</tt>, <tt>gempty()</tt>, <tt>grbegin()</tt>, <tt>grend()</tt><p> |
| 766 | |
| 767 | These are forwarding methods that make it easy to access the contents of a |
| 768 | <tt>Module</tt> object's <a href="#GlobalVariable"><tt>GlobalVariable</tt></a> |
| 769 | list.<p> |
| 770 | |
| 771 | <li><tt>Module::GlobalListType &getGlobalList()</tt><p> |
| 772 | |
| 773 | Returns the list of <a href="#GlobalVariable"><tt>GlobalVariable</tt></a>s. |
| 774 | This is neccesary to use when you need to update the list or perform a complex |
| 775 | action that doesn't have a forwarding method.<p> |
| 776 | |
| 777 | |
| 778 | <!-- Symbol table stuff --> |
| 779 | <hr size=0> |
| 780 | |
| 781 | <li><tt>bool hasSymbolTable() const</tt><p> |
| 782 | |
| 783 | Return true if the <tt>Module</tt> has a symbol table allocated to it and if |
| 784 | there is at least one entry in it.<p> |
| 785 | |
| 786 | <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTable()</tt><p> |
| 787 | |
| 788 | Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this |
| 789 | <tt>Module</tt> or a null pointer if one has not been allocated (because there |
| 790 | are no named values in the function).<p> |
| 791 | |
| 792 | <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTableSure()</tt><p> |
| 793 | |
| 794 | Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this |
| 795 | <tt>Module</tt> or allocate a new <a |
| 796 | href="#SymbolTable"><tt>SymbolTable</tt></a> if one is not already around. This |
| 797 | should only be used when adding elements to the <a |
| 798 | href="#SymbolTable"><tt>SymbolTable</tt></a>, so that empty symbol tables are |
| 799 | not left laying around.<p> |
| 800 | |
| 801 | |
| 802 | <!-- Convenience methods --> |
| 803 | <hr size=0> |
| 804 | |
| 805 | <li><tt><a href="#Function">Function</a> *getFunction(const std::string &Name, const <a href="#FunctionType">FunctionType</a> *Ty)</tt><p> |
| 806 | |
| 807 | Look up the specified function in the <tt>Module</tt> <a |
| 808 | href="#SymbolTable"><tt>SymbolTable</tt></a>. If it does not exist, return |
| 809 | <tt>null</tt>.<p> |
| 810 | |
| 811 | |
| 812 | <li><tt><a href="#Function">Function</a> *getOrInsertFunction(const std::string |
| 813 | &Name, const <a href="#FunctionType">FunctionType</a> *T)</tt><p> |
| 814 | |
| 815 | Look up the specified function in the <tt>Module</tt> <a |
| 816 | href="#SymbolTable"><tt>SymbolTable</tt></a>. If it does not exist, add an |
| 817 | external declaration for the function and return it.<p> |
| 818 | |
| 819 | |
| 820 | <li><tt>std::string getTypeName(const <a href="#Type">Type</a> *Ty)</tt><p> |
| 821 | |
| 822 | If there is at least one entry in the <a |
| 823 | href="#SymbolTable"><tt>SymbolTable</tt></a> for the specified <a |
| 824 | href="#Type"><tt>Type</tt></a>, return it. Otherwise return the empty |
| 825 | string.<p> |
| 826 | |
| 827 | |
| 828 | <li><tt>bool addTypeName(const std::string &Name, const <a href="#Type">Type</a> |
| 829 | *Ty)</tt><p> |
| 830 | |
| 831 | Insert an entry in the <a href="#SymbolTable"><tt>SymbolTable</tt></a> mapping |
| 832 | <tt>Name</tt> to <tt>Ty</tt>. If there is already an entry for this name, true |
| 833 | is returned and the <a href="#SymbolTable"><tt>SymbolTable</tt></a> is not |
| 834 | modified.<p> |
| 835 | |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 836 | |
| 837 | <!-- ======================================================================= --> |
| 838 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 839 | <tr><td> </td><td width="100%"> |
| 840 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 841 | <a name="Constant">The <tt>Constant</tt> class and subclasses</a> |
| 842 | </b></font></td></tr></table><ul> |
| 843 | |
| 844 | Constant represents a base class for different types of constants. It is |
| 845 | subclassed by ConstantBool, ConstantInt, ConstantSInt, ConstantUInt, |
| 846 | ConstantArray etc for representing the various types of Constants.<p> |
| 847 | |
| 848 | |
| 849 | <!-- _______________________________________________________________________ --> |
| 850 | </ul><h4><a name="m_Value"><hr size=0>Important Public Methods</h4><ul> |
| 851 | |
| 852 | <li><tt>bool isConstantExpr()</tt>: Returns true if it is a ConstantExpr |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | \subsection{Important Subclasses of Constant} |
| 858 | \begin{itemize} |
| 859 | <li>ConstantSInt : This subclass of Constant represents a signed integer constant. |
| 860 | \begin{itemize} |
| 861 | <li><tt>int64_t getValue () const</tt>: Returns the underlying value of this constant. |
| 862 | \end{itemize} |
| 863 | <li>ConstantUInt : This class represents an unsigned integer. |
| 864 | \begin{itemize} |
| 865 | <li><tt>uint64_t getValue () const</tt>: Returns the underlying value of this constant. |
| 866 | \end{itemize} |
| 867 | <li>ConstantFP : This class represents a floating point constant. |
| 868 | \begin{itemize} |
| 869 | <li><tt>double getValue () const</tt>: Returns the underlying value of this constant. |
| 870 | \end{itemize} |
| 871 | <li>ConstantBool : This represents a boolean constant. |
| 872 | \begin{itemize} |
| 873 | <li><tt>bool getValue () const</tt>: Returns the underlying value of this constant. |
| 874 | \end{itemize} |
| 875 | <li>ConstantArray : This represents a constant array. |
| 876 | \begin{itemize} |
| 877 | <li><tt>const std::vector<Use> &getValues() const</tt>: Returns a Vecotr of component constants that makeup this array. |
| 878 | \end{itemize} |
| 879 | <li>ConstantStruct : This represents a constant struct. |
| 880 | \begin{itemize} |
| 881 | <li><tt>const std::vector<Use> &getValues() const</tt>: Returns a Vecotr of component constants that makeup this array. |
| 882 | \end{itemize} |
| 883 | <li>ConstantPointerRef : This represents a constant pointer value that is initialized to point to a global value, which lies at a constant fixed address. |
| 884 | \begin{itemize} |
| 885 | <li><tt>GlobalValue *getValue()</tt>: Returns the global value to which this pointer is pointing to. |
| 886 | \end{itemize} |
| 887 | \end{itemize} |
| 888 | |
| 889 | |
| 890 | <!-- ======================================================================= --> |
| 891 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 892 | <tr><td> </td><td width="100%"> |
| 893 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 894 | <a name="Type">The <tt>Type</tt> class and Derived Types</a> |
| 895 | </b></font></td></tr></table><ul> |
| 896 | |
| 897 | Type as noted earlier is also a subclass of a Value class. Any primitive |
| 898 | type (like int, short etc) in LLVM is an instance of Type Class. All |
| 899 | other types are instances of subclasses of type like FunctionType, |
| 900 | ArrayType etc. DerivedType is the interface for all such dervied types |
| 901 | including FunctionType, ArrayType, PointerType, StructType. Types can have |
| 902 | names. They can be recursive (StructType). There exists exactly one instance |
| 903 | of any type structure at a time. This allows using pointer equality of Type *s for comparing types. |
| 904 | |
| 905 | <!-- _______________________________________________________________________ --> |
| 906 | </ul><h4><a name="m_Value"><hr size=0>Important Public Methods</h4><ul> |
| 907 | |
| 908 | <li><tt>PrimitiveID getPrimitiveID () const</tt>: Returns the base type of the type. |
| 909 | <li><tt> bool isSigned () const</tt>: Returns whether an integral numeric type is signed. This is true for SByteTy, ShortTy, IntTy, LongTy. Note that this is not true for Float and Double. |
| 910 | <li><tt>bool isUnsigned () const</tt>: Returns whether a numeric type is unsigned. This is not quite the complement of isSigned... nonnumeric types return false as they do with isSigned. This returns true for UByteTy, UShortTy, UIntTy, and ULongTy. |
| 911 | <li><tt> bool isInteger () const</tt>: Equilivent to isSigned() || isUnsigned(), but with only a single virtual function invocation. |
| 912 | <li><tt>bool isIntegral () const</tt>: Returns true if this is an integral type, which is either Bool type or one of the Integer types. |
| 913 | |
| 914 | <li><tt>bool isFloatingPoint ()</tt>: Return true if this is one of the two floating point types. |
| 915 | <li><tt>bool isRecursive () const</tt>: Returns rue if the type graph contains a cycle. |
| 916 | <li><tt>isLosslesslyConvertableTo (const Type *Ty) const</tt>: Return true if this type can be converted to 'Ty' without any reinterpretation of bits. For example, uint to int. |
| 917 | <li><tt>bool isPrimitiveType () const</tt>: Returns true if it is a primitive type. |
| 918 | <li><tt>bool isDerivedType () const</tt>: Returns true if it is a derived type. |
| 919 | <li><tt>const Type * getContainedType (unsigned i) const</tt>: |
| 920 | This method is used to implement the type iterator. For derived types, this returns the types 'contained' in the derived type, returning 0 when 'i' becomes invalid. This allows the user to iterate over the types in a struct, for example, really easily. |
| 921 | <li><tt>unsigned getNumContainedTypes () const</tt>: Return the number of types in the derived type. |
| 922 | |
| 923 | |
| 924 | |
| 925 | \subsection{Derived Types} |
| 926 | \begin{itemize} |
| 927 | <li>SequentialType : This is subclassed by ArrayType and PointerType |
| 928 | \begin{itemize} |
| 929 | <li><tt>const Type * getElementType () const</tt>: Returns the type of each of the elements in the sequential type. |
| 930 | \end{itemize} |
| 931 | <li>ArrayType : This is a subclass of SequentialType and defines interface for array types. |
| 932 | \begin{itemize} |
| 933 | <li><tt>unsigned getNumElements () const</tt>: Returns the number of elements in the array. |
| 934 | \end{itemize} |
| 935 | <li>PointerType : Subclass of SequentialType for pointer types. |
| 936 | <li>StructType : subclass of DerivedTypes for struct types |
| 937 | <li>FunctionType : subclass of DerivedTypes for function types. |
| 938 | \begin{itemize} |
| 939 | |
| 940 | <li><tt>bool isVarArg () const</tt>: Returns true if its a vararg function |
| 941 | <li><tt> const Type * getReturnType () const</tt>: Returns the return type of the function. |
| 942 | <li><tt> const ParamTypes &getParamTypes () const</tt>: Returns a vector of parameter types. |
| 943 | <li><tt>const Type * getParamType (unsigned i)</tt>: Returns the type of the ith parameter. |
| 944 | <li><tt> const unsigned getNumParams () const</tt>: Returns the number of formal parameters. |
| 945 | \end{itemize} |
| 946 | \end{itemize} |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | <!-- ======================================================================= --> |
| 952 | </ul><table width="100%" bgcolor="#441188" border=0 cellpadding=4 cellspacing=0> |
| 953 | <tr><td> </td><td width="100%"> |
| 954 | <font color="#EEEEFF" face="Georgia,Palatino"><b> |
| 955 | <a name="Argument">The <tt>Argument</tt> class</a> |
| 956 | </b></font></td></tr></table><ul> |
| 957 | |
| 958 | This subclass of Value defines the interface for incoming formal arguments to a |
| 959 | function. A Function maitanis a list of its formal arguments. An argument has a |
| 960 | pointer to the parent Function. |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | <!-- *********************************************************************** --> |
| 966 | </ul> |
| 967 | <!-- *********************************************************************** --> |
| 968 | |
| 969 | <hr><font size-1> |
| 970 | <address>By: <a href="mailto:dhurjati@cs.uiuc.edu">Dinakar Dhurjati</a> and |
| 971 | <a href="mailto:sabre@nondot.org">Chris Lattner</a></address> |
| 972 | <!-- Created: Tue Aug 6 15:00:33 CDT 2002 --> |
| 973 | <!-- hhmts start --> |
Chris Lattner | a30ed38 | 2002-09-06 16:33:54 +0000 | [diff] [blame^] | 974 | Last modified: Fri Sep 6 11:21:49 CDT 2002 |
Chris Lattner | 9355b47 | 2002-09-06 02:50:58 +0000 | [diff] [blame] | 975 | <!-- hhmts end --> |
| 976 | </font></body></html> |