X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FProgrammersManual.html;h=e8d81a25061daa2db8d873767113226f2c1b5b2e;hb=09aa3f0ef35d9241c92439d74b8d5e9a81d814c2;hp=6c0f87e1e694fe6dd85fb568385ef4d226030470;hpb=302da1e736ef5723560188c57adcff865f2fa13e;p=oota-llvm.git diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 6c0f87e1e69..e8d81a25061 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -2,6 +2,7 @@ "http://www.w3.org/TR/html4/strict.dtd"> + LLVM Programmer's Manual @@ -28,6 +29,13 @@ @@ -1474,6 +2282,257 @@ ReplaceInstWithValue, ReplaceInstWithInst --> + +
+ Deleting GlobalVariables +
+ +
+ +

Deleting a global variable from a module is just as easy as deleting an +Instruction. First, you must have a pointer to the global variable that you wish + to delete. You use this pointer to erase it from its parent, the module. + For example:

+ +
+
+GlobalVariable *GV = .. ;
+
+GV->eraseFromParent();
+
+
+ +
+ + +
+ How to Create Types +
+ +
+ +

In generating IR, you may need some complex types. If you know these types +statically, you can use TypeBuilder<...>::get(), defined +in llvm/Support/TypeBuilder.h, to retrieve them. TypeBuilder +has two forms depending on whether you're building types for cross-compilation +or native library use. TypeBuilder<T, true> requires +that T be independent of the host environment, meaning that it's built +out of types from +the llvm::types +namespace and pointers, functions, arrays, etc. built of +those. TypeBuilder<T, false> additionally allows native C types +whose size may depend on the host compiler. For example,

+ +
+
+FunctionType *ft = TypeBuilder<types::i<8>(types::i<32>*), true>::get();
+
+
+ +

is easier to read and write than the equivalent

+ +
+
+std::vector<const Type*> params;
+params.push_back(PointerType::getUnqual(Type::Int32Ty));
+FunctionType *ft = FunctionType::get(Type::Int8Ty, params, false);
+
+
+ +

See the class +comment for more details.

+ +
+ + +
+ Threads and LLVM +
+ + +
+

+This section describes the interaction of the LLVM APIs with multithreading, +both on the part of client applications, and in the JIT, in the hosted +application. +

+ +

+Note that LLVM's support for multithreading is still relatively young. Up +through version 2.5, the execution of threaded hosted applications was +supported, but not threaded client access to the APIs. While this use case is +now supported, clients must adhere to the guidelines specified below to +ensure proper operation in multithreaded mode. +

+ +

+Note that, on Unix-like platforms, LLVM requires the presence of GCC's atomic +intrinsics in order to support threaded operation. If you need a +multhreading-capable LLVM on a platform without a suitably modern system +compiler, consider compiling LLVM and LLVM-GCC in single-threaded mode, and +using the resultant compiler to build a copy of LLVM with multithreading +support. +

+
+ + +
+ Entering and Exiting Multithreaded Mode +
+ +
+ +

+In order to properly protect its internal data structures while avoiding +excessive locking overhead in the single-threaded case, the LLVM must intialize +certain data structures necessary to provide guards around its internals. To do +so, the client program must invoke llvm_start_multithreaded() before +making any concurrent LLVM API calls. To subsequently tear down these +structures, use the llvm_stop_multithreaded() call. You can also use +the llvm_is_multithreaded() call to check the status of multithreaded +mode. +

+ +

+Note that both of these calls must be made in isolation. That is to +say that no other LLVM API calls may be executing at any time during the +execution of llvm_start_multithreaded() or llvm_stop_multithreaded +. It's is the client's responsibility to enforce this isolation. +

+ +

+The return value of llvm_start_multithreaded() indicates the success or +failure of the initialization. Failure typically indicates that your copy of +LLVM was built without multithreading support, typically because GCC atomic +intrinsics were not found in your system compiler. In this case, the LLVM API +will not be safe for concurrent calls. However, it will be safe for +hosting threaded applications in the JIT, though care +must be taken to ensure that side exits and the like do not accidentally +result in concurrent LLVM API calls. +

+
+ + +
+ Ending Execution with llvm_shutdown() +
+ +
+

+When you are done using the LLVM APIs, you should call llvm_shutdown() +to deallocate memory used for internal structures. This will also invoke +llvm_stop_multithreaded() if LLVM is operating in multithreaded mode. +As such, llvm_shutdown() requires the same isolation guarantees as +llvm_stop_multithreaded(). +

+ +

+Note that, if you use scope-based shutdown, you can use the +llvm_shutdown_obj class, which calls llvm_shutdown() in its +destructor. +

+ + +
+ Lazy Initialization with ManagedStatic +
+ +
+

+ManagedStatic is a utility class in LLVM used to implement static +initialization of static resources, such as the global type tables. Before the +invocation of llvm_shutdown(), it implements a simple lazy +initialization scheme. Once llvm_start_multithreaded() returns, +however, it uses double-checked locking to implement thread-safe lazy +initialization. +

+ +

+Note that, because no other threads are allowed to issue LLVM API calls before +llvm_start_multithreaded() returns, it is possible to have +ManagedStatics of llvm::sys::Mutexs. +

+ +

+The llvm_acquire_global_lock() and llvm_release_global_lock +APIs provide access to the global lock used to implement the double-checked +locking for lazy initialization. These should only be used internally to LLVM, +and only if you know what you're doing! +

+
+ + +
+ Achieving Isolation with LLVMContext +
+ +
+

+LLVMContext is an opaque class in the LLVM API which clients can use +to operate multiple, isolated instances of LLVM concurrently within the same +address space. For instance, in a hypothetical compile-server, the compilation +of an individual translation unit is conceptually independent from all the +others, and it would be desirable to be able to compile incoming translation +units concurrently on independent server threads. Fortunately, +LLVMContext exists to enable just this kind of scenario! +

+ +

+Conceptually, LLVMContext provides isolation. Every LLVM entity +(Modules, Values, Types, Constants, etc.) +in LLVM's in-memory IR belongs to an LLVMContext. Entities in +different contexts cannot interact with each other: Modules in +different contexts cannot be linked together, Functions cannot be added +to Modules in different contexts, etc. What this means is that is is +safe to compile on multiple threads simultaneously, as long as no two threads +operate on entities within the same context. +

+ +

+In practice, very few places in the API require the explicit specification of a +LLVMContext, other than the Type creation/lookup APIs. +Because every Type carries a reference to its owning context, most +other entities can determine what context they belong to by looking at their +own Type. If you are adding new entities to LLVM IR, please try to +maintain this interface design. +

+ +

+For clients that do not require the benefits of isolation, LLVM +provides a convenience API getGlobalContext(). This returns a global, +lazily initialized LLVMContext that may be used in situations where +isolation is not a concern. +

+
+ + +
+ Threads and the JIT +
+ +
+

+LLVM's "eager" JIT compiler is safe to use in threaded programs. Multiple +threads can call ExecutionEngine::getPointerToFunction() or +ExecutionEngine::runFunction() concurrently, and multiple threads can +run code output by the JIT concurrently. The user must still ensure that only +one thread accesses IR in a given LLVMContext while another thread +might be modifying it. One way to do that is to always hold the JIT lock while +accessing IR outside the JIT (the JIT modifies the IR by adding +CallbackVHs). Another way is to only +call getPointerToFunction() from the LLVMContext's thread. +

+ +

When the JIT is configured to compile lazily (using +ExecutionEngine::DisableLazyCompilation(false)), there is currently a +race condition in +updating call sites after a function is lazily-jitted. It's still possible to +use the lazy JIT in a threaded program if you ensure that only one thread at a +time can call any particular lazy stub and that the JIT lock guards any IR +access, but we suggest using only the eager JIT in threaded programs. +

+
+
Advanced Topics @@ -1508,7 +2567,7 @@ recursive types and late resolution of opaque types makes the situation very difficult to handle. Fortunately, for the most part, our implementation makes most clients able to be completely unaware of the nasty internal details. The primary case where clients are exposed to the inner workings of it are when -building a recursive type. In addition to this case, the LLVM bytecode reader, +building a recursive type. In addition to this case, the LLVM bitcode reader, assembly parser, and linker also have to be aware of the inner workings of this system.

@@ -1552,8 +2611,8 @@ To build this, use the following LLVM APIs: // Create the initial outer struct PATypeHolder StructTy = OpaqueType::get(); std::vector<const Type*> Elts; -Elts.push_back(PointerType::get(StructTy)); -Elts.push_back(Type::IntTy); +Elts.push_back(PointerType::getUnqual(StructTy)); +Elts.push_back(Type::Int32Ty); StructType *NewSTy = StructType::get(Elts); // At this point, NewSTy = "{ opaque*, i32 }". Tell VMCore that @@ -1573,7 +2632,7 @@ MyModule->addTypeName("mylist", NewSTy); This code shows the basic approach used to build recursive types: build a non-recursive type using 'opaque', then use type unification to close the cycle. The type unification step is performed by the refineAbstractTypeTo method, which is +href="#refineAbstractTypeTo">refineAbstractTypeTo
method, which is described next. After that, we describe the PATypeHolder class.

@@ -1641,12 +2700,8 @@ Type is maintained by PATypeHolder objects.

Some data structures need more to perform more complex updates when types get -resolved. The SymbolTable class, for example, needs -move and potentially merge type planes in its representation when a pointer -changes.

- -

-To support this, a class can derive from the AbstractTypeUser class. This class +resolved. To support this, a class can derive from the AbstractTypeUser class. +This class allows it to get callbacks when certain types are resolved. To register to get callbacks for a particular type, the DerivedType::{add/remove}AbstractTypeUser methods can be called on a type. Note that these methods only work for @@ -1658,183 +2713,265 @@ objects) can never be refined.

- The SymbolTable class + The ValueSymbolTable and + TypeSymbolTable classes
-

This class provides a symbol table that the The +ValueSymbolTable class provides a symbol table that the Function and -Module classes use for naming definitions. The symbol table can -provide a name for any Value. -SymbolTable is an abstract data type. It hides the data it contains -and provides access to it through a controlled interface.

+Module classes use for naming value definitions. The symbol table +can provide a name for any Value. +The +TypeSymbolTable class is used by the Module class to store +names for types.

Note that the SymbolTable class should not be directly accessed by most clients. It should only be used when iteration over the symbol table names themselves are required, which is very special purpose. Note that not all LLVM -Values have names, and those without names (i.e. they have +Values have names, and those without names (i.e. they have an empty name) do not exist in the symbol table.

-

To use the SymbolTable well, you need to understand the -structure of the information it holds. The class contains two -std::map objects. The first, pmap, is a map of -Type* to maps of name (std::string) to Value*. -Thus, Values are stored in two-dimensions and accessed by Type and -name.

+

These symbol tables support iteration over the values/types in the symbol +table with begin/end/iterator and supports querying to see if a +specific name is in the symbol table (with lookup). The +ValueSymbolTable class exposes no public mutator methods, instead, +simply call setName on a value, which will autoinsert it into the +appropriate symbol table. For types, use the Module::addTypeName method to +insert entries into the symbol table.

-

The interface of this class provides three basic types of operations: -

    -
  1. Accessors. Accessors provide read-only access to information - such as finding a value for a name with the - lookup method.
  2. -
  3. Mutators. Mutators allow the user to add information to the - SymbolTable with methods like - insert.
  4. -
  5. Iterators. Iterators allow the user to traverse the content - of the symbol table in well defined ways, such as the method - plane_begin.
  6. -
+
-

Accessors

-
-
Value* lookup(const Type* Ty, const std::string& name) const: -
-
The lookup method searches the type plane given by the - Ty parameter for a Value with the provided name. - If a suitable Value is not found, null is returned.
- -
bool isEmpty() const:
-
This function returns true if both the value and types maps are - empty
-
-

Mutators

-
-
void insert(Value *Val):
-
This method adds the provided value to the symbol table. The Value must - have both a name and a type which are extracted and used to place the value - in the correct type plane under the value's name.
- -
void insert(const std::string& Name, Value *Val):
-
Inserts a constant or type into the symbol table with the specified - name. There can be a many to one mapping between names and constants - or types.
- -
void remove(Value* Val):
-
This method removes a named value from the symbol table. The - type and name of the Value are extracted from \p N and used to - lookup the Value in the correct type plane. If the Value is - not in the symbol table, this method silently ignores the - request.
- -
Value* remove(const std::string& Name, Value *Val):
-
Remove a constant or type with the specified name from the - symbol table.
- -
Value *remove(const value_iterator& It):
-
Removes a specific value from the symbol table. - Returns the removed value.
- -
bool strip():
-
This method will strip the symbol table of its names leaving - the type and values.
- -
void clear():
-
Empty the symbol table completely.
-
-

Iteration

-

The following functions describe three types of iterators you can obtain -the beginning or end of the sequence for both const and non-const. It is -important to keep track of the different kinds of iterators. There are -three idioms worth pointing out:

- - - - - - - - - - - -
UnitsIteratorIdiom
Planes Of name/Value mapsPI

-for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
-     PE = ST.plane_end(); PI != PE; ++PI ) {
-  PI->first  // This is the Type* of the plane
-  PI->second // This is the SymbolTable::ValueMap of name/Value pairs
-}
-    
name/Value pairs in a planeVI

-for (SymbolTable::value_const_iterator VI = ST.value_begin(SomeType),
-     VE = ST.value_end(SomeType); VI != VE; ++VI ) {
-  VI->first  // This is the name of the Value
-  VI->second // This is the Value* value associated with the name
-}
-    
+ + -

Using the recommended iterator names and idioms will help you avoid -making mistakes. Of particular note, make sure that whenever you use -value_begin(SomeType) that you always compare the resulting iterator -with value_end(SomeType) not value_end(SomeOtherType) or else you -will loop infinitely.

+
+

The +User class provides a basis for expressing the ownership of User +towards other +Values. The +Use helper class is employed to do the bookkeeping and to facilitate O(1) +addition and removal.

-
+ + + +
+

+A subclass of User can choose between incorporating its Use objects +or refer to them out-of-line by means of a pointer. A mixed variant +(some Uses inline others hung off) is impractical and breaks the invariant +that the Use objects belonging to the same User form a contiguous array. +

+
+ +

+We have 2 different layouts in the User (sub)classes: +

    +
  • Layout a) +The Use object(s) are inside (resp. at fixed offset) of the User +object and there are a fixed number of them.

    + +
  • Layout b) +The Use object(s) are referenced by a pointer to an +array from the User object and there may be a variable +number of them.

    +
+

+As of v2.4 each layout still possesses a direct pointer to the +start of the array of Uses. Though not mandatory for layout a), +we stick to this redundancy for the sake of simplicity. +The User object also stores the number of Use objects it +has. (Theoretically this information can also be calculated +given the scheme presented below.)

+

+Special forms of allocation operators (operator new) +enforce the following memory layouts:

+ +
    +
  • Layout a) is modelled by prepending the User object by the Use[] array.

    + +
    +...---.---.---.---.-------...
    +  | P | P | P | P | User
    +'''---'---'---'---'-------'''
    +
    + +
  • Layout b) is modelled by pointing at the Use[] array.

    +
    +.-------...
    +| User
    +'-------'''
    +    |
    +    v
    +    .---.---.---.---...
    +    | P | P | P | P |
    +    '---'---'---'---'''
    +
    +
+(In the above figures 'P' stands for the Use** that + is stored in each Use object in the member Use::Prev) + + + -
plane_iterator plane_begin():
-
Get an iterator that starts at the beginning of the type planes. - The iterator will iterate over the Type/ValueMap pairs in the - type planes.
+
+

+Since the Use objects are deprived of the direct (back)pointer to +their User objects, there must be a fast and exact method to +recover it. This is accomplished by the following scheme:

+
-
plane_const_iterator plane_begin() const:
-
Get a const_iterator that starts at the beginning of the type - planes. The iterator will iterate over the Type/ValueMap pairs - in the type planes.
+A bit-encoding in the 2 LSBits (least significant bits) of the Use::Prev allows to find the +start of the User object: +
    +
  • 00 —> binary digit 0
  • +
  • 01 —> binary digit 1
  • +
  • 10 —> stop and calculate (s)
  • +
  • 11 —> full stop (S)
  • +
+

+Given a Use*, all we have to do is to walk till we get +a stop and we either have a User immediately behind or +we have to walk to the next stop picking up digits +and calculating the offset:

+
+.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.----------------
+| 1 | s | 1 | 0 | 1 | 0 | s | 1 | 1 | 0 | s | 1 | 1 | s | 1 | S | User (or User*)
+'---'---'---'---'---'---'---'---'---'---'---'---'---'---'---'---'----------------
+    |+15                |+10            |+6         |+3     |+1
+    |                   |               |           |       |__>
+    |                   |               |           |__________>
+    |                   |               |______________________>
+    |                   |______________________________________>
+    |__________________________________________________________>
+
+

+Only the significant number of bits need to be stored between the +stops, so that the worst case is 20 memory accesses when there are +1000 Use objects associated with a User.

-
plane_iterator plane_end():
-
Get an iterator at the end of the type planes. This serves as - the marker for end of iteration over the type planes.
+ + -
plane_const_iterator plane_end() const:
-
Get a const_iterator at the end of the type planes. This serves as - the marker for end of iteration over the type planes.
+
+

+The following literate Haskell fragment demonstrates the concept:

+
-
value_iterator value_begin(const Type *Typ):
-
Get an iterator that starts at the beginning of a type plane. - The iterator will iterate over the name/value pairs in the type plane. - Note: The type plane must already exist before using this.
+
+
+> import Test.QuickCheck
+> 
+> digits :: Int -> [Char] -> [Char]
+> digits 0 acc = '0' : acc
+> digits 1 acc = '1' : acc
+> digits n acc = digits (n `div` 2) $ digits (n `mod` 2) acc
+> 
+> dist :: Int -> [Char] -> [Char]
+> dist 0 [] = ['S']
+> dist 0 acc = acc
+> dist 1 acc = let r = dist 0 acc in 's' : digits (length r) r
+> dist n acc = dist (n - 1) $ dist 1 acc
+> 
+> takeLast n ss = reverse $ take n $ reverse ss
+> 
+> test = takeLast 40 $ dist 20 []
+> 
+
+
+

+Printing <test> gives: "1s100000s11010s10100s1111s1010s110s11s1S"

+

+The reverse algorithm computes the length of the string just by examining +a certain prefix:

-
value_const_iterator value_begin(const Type *Typ) const:
-
Get a const_iterator that starts at the beginning of a type plane. - The iterator will iterate over the name/value pairs in the type plane. - Note: The type plane must already exist before using this.
+
+
+> pref :: [Char] -> Int
+> pref "S" = 1
+> pref ('s':'1':rest) = decode 2 1 rest
+> pref (_:rest) = 1 + pref rest
+> 
+> decode walk acc ('0':rest) = decode (walk + 1) (acc * 2) rest
+> decode walk acc ('1':rest) = decode (walk + 1) (acc * 2 + 1) rest
+> decode walk acc _ = walk + acc
+> 
+
+
+

+Now, as expected, printing <pref test> gives 40.

+

+We can quickCheck this with following property:

-
value_iterator value_end(const Type *Typ):
-
Get an iterator to the end of a type plane. This serves as the marker - for end of iteration of the type plane. - Note: The type plane must already exist before using this.
+
+
+> testcase = dist 2000 []
+> testcaseLength = length testcase
+> 
+> identityProp n = n > 0 && n <= testcaseLength ==> length arr == pref arr
+>     where arr = takeLast n testcase
+> 
+
+
+

+As expected <quickCheck identityProp> gives:

-
value_const_iterator value_end(const Type *Typ) const:
-
Get a const_iterator to the end of a type plane. This serves as the - marker for end of iteration of the type plane. - Note: the type plane must already exist before using this.
+
+*Main> quickCheck identityProp
+OK, passed 100 tests.
+
+

+Let's be a bit more exhaustive:

-
plane_const_iterator find(const Type* Typ ) const:
-
This method returns a plane_const_iterator for iteration over - the type planes starting at a specific plane, given by \p Ty.
+
+
+> 
+> deepCheck p = check (defaultConfig { configMaxTest = 500 }) p
+> 
+
+
+

+And here is the result of <deepCheck identityProp>:

-
plane_iterator find( const Type* Typ :
-
This method returns a plane_iterator for iteration over the - type planes starting at a specific plane, given by \p Ty.
+
+*Main> deepCheck identityProp
+OK, passed 500 tests.
+
-
+ + +

+To maintain the invariant that the 2 LSBits of each Use** in Use +never change after being set up, setters of Use::Prev must re-tag the +new Use** on every modification. Accordingly getters must strip the +tag bits.

+

+For layout b) instead of the User we find a pointer (User* with LSBit set). +Following this pointer brings us to the User. A portable trick ensures +that the first bytes of User (if interpreted as a pointer) never has +the LSBit set. (Portability is relying on the fact that all known compilers place the +vptr in the first word of the instances.)

+
- + @@ -1875,15 +3012,15 @@ the lib/VMCore directory.

    -
  • bool isInteger() const: Returns true for any integer type.
  • +
  • bool isIntegerTy() const: Returns true for any integer type.
  • -
  • bool isFloatingPoint(): Return true if this is one of the two +
  • bool isFloatingPointTy(): Return true if this is one of the five floating point types.
  • bool isAbstract(): Return true if the type is abstract (contains @@ -1897,7 +3034,7 @@ the lib/VMCore directory.

    @@ -1929,18 +3066,18 @@ the lib/VMCore directory.

    PointerType
    Subclass of SequentialType for pointer types.
    -
    PackedType
    -
    Subclass of SequentialType for packed (vector) types. A - packed type is similar to an ArrayType but is distinguished because it is - a first class type wherease ArrayType is not. Packed types are used for +
    VectorType
    +
    Subclass of SequentialType for vector types. A + vector type is similar to an ArrayType but is distinguished because it is + a first class type whereas ArrayType is not. Vector types are used for vector operations and are usually small vectors of of an integer or floating point type.
    StructType
    Subclass of DerivedTypes for struct types.
    -
    FunctionType
    +
    FunctionType
    Subclass of DerivedTypes for function types.
      -
    • bool isVarArg() const: Returns true if its a vararg +
    • bool isVarArg() const: Returns true if it's a vararg function
    • const Type * getReturnType() const: Returns the return type of the function.
    • @@ -1961,12 +3098,141 @@ the lib/VMCore directory.

    + + + + + +
    + +

    #include "llvm/Module.h"
    doxygen info: +Module Class

    + +

    The Module class represents the top level structure present in LLVM +programs. An LLVM module is effectively either a translation unit of the +original program or a combination of several translation units merged by the +linker. The Module class keeps track of a list of Functions, a list of GlobalVariables, and a SymbolTable. Additionally, it contains a few +helpful member functions that try to make common operations easy.

    + +
    + + + + +
    + +
      +
    • Module::Module(std::string name = "")
    • +
    + +

    Constructing a Module is easy. You can optionally +provide a name for it (probably based on the name of the translation unit).

    + +
      +
    • Module::iterator - Typedef for function list iterator
      + Module::const_iterator - Typedef for const_iterator.
      + + begin(), end() + size(), empty() + +

      These are forwarding methods that make it easy to access the contents of + a Module object's Function + list.

    • + +
    • Module::FunctionListType &getFunctionList() + +

      Returns the list of Functions. This is + necessary to use when you need to update the list or perform a complex + action that doesn't have a forwarding method.

      + +

    • +
    + +
    + +
      +
    • Module::global_iterator - Typedef for global variable list iterator
      + + Module::const_global_iterator - Typedef for const_iterator.
      + + global_begin(), global_end() + global_size(), global_empty() + +

      These are forwarding methods that make it easy to access the contents of + a Module object's GlobalVariable list.

    • + +
    • Module::GlobalListType &getGlobalList() + +

      Returns the list of GlobalVariables. This is necessary to + use when you need to update the list or perform a complex action that + doesn't have a forwarding method.

      + +

    • +
    + +
    + + + +
    + +
      +
    • Function *getFunction(const std::string + &Name, const FunctionType *Ty) + +

      Look up the specified function in the Module SymbolTable. If it does not exist, return + null.

    • + +
    • Function *getOrInsertFunction(const + std::string &Name, const FunctionType *T) + +

      Look up the specified function in the Module SymbolTable. If it does not exist, add an + external declaration for the function and return it.

    • + +
    • std::string getTypeName(const Type *Ty) + +

      If there is at least one entry in the SymbolTable for the specified Type, return it. Otherwise return the empty + string.

    • + +
    • bool addTypeName(const std::string &Name, const Type *Ty) + +

      Insert an entry in the SymbolTable + mapping Name to Ty. If there is already an entry for this + name, true is returned and the SymbolTable is not modified.

    • +
    + +
    + + -
    +

    #include "llvm/Value.h"
    @@ -2002,7 +3268,7 @@ method. In addition, all LLVM values can be named. The "name" of the

    -

    The name of this instruction is "foo". NOTE +

    The name of this instruction is "foo". NOTE that the name of any value may be missing (an empty string), so names should ONLY be used for debugging (making the source code easier to read, debugging printouts), they should not be used to keep track of values or map @@ -2029,7 +3295,7 @@ simplifies the representation and makes it easier to manipulate.

    • Value::use_iterator - Typedef for iterator over the use-list
      - Value::use_const_iterator - Typedef for const_iterator over + Value::const_use_iterator - Typedef for const_iterator over the use-list
      unsigned use_size() - Returns the number of users of the value.
      @@ -2210,99 +3476,74 @@ in all ways to the original except that the instruction has no parent and it has no name

    -
    - - - - -
    - -

    #include "llvm/BasicBlock.h"
    -doxygen info: BasicBlock -Class
    -Superclass: Value

    - -

    This class represents a single entry multiple exit section of the code, -commonly known as a basic block by the compiler community. The -BasicBlock class maintains a list of Instructions, which form the body of the block. -Matching the language definition, the last element of this list of instructions -is always a terminator instruction (a subclass of the TerminatorInst class).

    - -

    In addition to tracking the list of instructions that make up the block, the -BasicBlock class also keeps track of the Function that it is embedded into.

    - -

    Note that BasicBlocks themselves are Values, because they are referenced by instructions -like branches and can go in the switch tables. BasicBlocks have type -label.

    - -
    - - - - -
    - -
      - -
    • BasicBlock(const std::string &Name = "", Function *Parent = 0) - -

      The BasicBlock constructor is used to create new basic blocks for -insertion into a function. The constructor optionally takes a name for the new -block, and a Function to insert it into. If -the Parent parameter is specified, the new BasicBlock is -automatically inserted at the end of the specified Function, if not specified, the BasicBlock must be -manually inserted into the Function.

    • - -
    • BasicBlock::iterator - Typedef for instruction list iterator
      -BasicBlock::const_iterator - Typedef for const_iterator.
      -begin(), end(), front(), back(), -size(), empty() -STL-style functions for accessing the instruction list. - -

      These methods and typedefs are forwarding functions that have the same -semantics as the standard library methods of the same names. These methods -expose the underlying instruction list of a basic block in a way that is easy to -manipulate. To get the full complement of container operations (including -operations to update the list), you must use the getInstList() -method.

    • - -
    • BasicBlock::InstListType &getInstList() - -

      This method is used to get access to the underlying container that actually -holds the Instructions. This method must be used when there isn't a forwarding -function in the BasicBlock class for the operation that you would like -to perform. Because there are no forwarding functions for "updating" -operations, you need to use this if you want to update the contents of a -BasicBlock.

    • +
    -
  • Function *getParent() + + -

    Returns a pointer to Function the block is -embedded into, or a null pointer if it is homeless.

  • +
    -
  • TerminatorInst *getTerminator() +

    Constant represents a base class for different types of constants. It +is subclassed by ConstantInt, ConstantArray, etc. for representing +the various types of Constants. GlobalValue is also +a subclass, which represents the address of a global variable or function. +

    -

    Returns a pointer to the terminator instruction that appears at the end of -the BasicBlock. If there is no terminator instruction, or if the last -instruction in the block is not a terminator, then a null pointer is -returned.

  • +
    + +
    Important Subclasses of Constant
    +
    +
      +
    • ConstantInt : This subclass of Constant represents an integer constant of + any width. +
        +
      • const APInt& getValue() const: Returns the underlying + value of this constant, an APInt value.
      • +
      • int64_t getSExtValue() const: Converts the underlying APInt + value to an int64_t via sign extension. If the value (not the bit width) + of the APInt is too large to fit in an int64_t, an assertion will result. + For this reason, use of this method is discouraged.
      • +
      • uint64_t getZExtValue() const: Converts the underlying APInt + value to a uint64_t via zero extension. IF the value (not the bit width) + of the APInt is too large to fit in a uint64_t, an assertion will result. + For this reason, use of this method is discouraged.
      • +
      • static ConstantInt* get(const APInt& Val): Returns the + ConstantInt object that represents the value provided by Val. + The type is implied as the IntegerType that corresponds to the bit width + of Val.
      • +
      • static ConstantInt* get(const Type *Ty, uint64_t Val): + Returns the ConstantInt object that represents the value provided by + Val for integer type Ty.
      • +
      +
    • +
    • ConstantFP : This class represents a floating point constant. +
        +
      • double getValue() const: Returns the underlying value of + this constant.
      • +
      +
    • +
    • ConstantArray : This represents a constant array. +
        +
      • const std::vector<Use> &getValues() const: Returns + a vector of component constants that makeup this array.
      • +
      +
    • +
    • ConstantStruct : This represents a constant struct. +
        +
      • const std::vector<Use> &getValues() const: Returns + a vector of component constants that makeup this array.
      • +
      +
    • +
    • GlobalValue : This represents either a global variable or a function. In + either case, the value is a constant fixed address (after linking). +
    -
    +
    The GlobalValue class @@ -2388,7 +3629,7 @@ Superclasses: GlobalValue, Value

    The Function class represents a single procedure in LLVM. It is -actually one of the more complex classes in the LLVM heirarchy because it must +actually one of the more complex classes in the LLVM hierarchy because it must keep track of a large amount of data. The Function class keeps track of a list of BasicBlocks, a list of formal Arguments, and a @@ -2397,7 +3638,7 @@ of a list of BasicBlocks, a list of formal

    The list of BasicBlocks is the most commonly used part of Function objects. The list imposes an implicit ordering of the blocks in the function, which indicate how the code will be -layed out by the backend. Additionally, the first BasicBlock is the implicit entry node for the Function. It is not legal in LLVM to explicitly branch to this initial block. There are no implicit exit nodes, and in fact there may be multiple exit @@ -2443,13 +3684,13 @@ is its address (after linking) which is guaranteed to be constant.

    create and what type of linkage the function should have. The FunctionType argument specifies the formal arguments and return value for the function. The same - FunctionType value can be used to + FunctionType value can be used to create multiple functions. The Parent argument specifies the Module in which the function is defined. If this argument is provided, the function will automatically be inserted into that module's list of functions.

    -
  • bool isExternal() +
  • bool isDeclaration()

    Return whether or not the Function has a body defined. If the function is "external", it does not have a body, and thus must be resolved @@ -2527,7 +3768,7 @@ Superclasses: GlobalValue, User, Value

    -

    Global variables are represented with the (suprise suprise) +

    Global variables are represented with the (surprise surprise) GlobalVariable class. Like functions, GlobalVariables are also subclasses of GlobalValue, and as such are always referenced by their address (global values must live in memory, so their @@ -2555,11 +3796,12 @@ never change at runtime).

    Create a new global variable of the specified type. If isConstant is true then the global variable will be marked as unchanging for the program. The Linkage parameter specifies the type of - linkage (internal, external, weak, linkonce, appending) for the variable. If - the linkage is InternalLinkage, WeakLinkage, or LinkOnceLinkage,  then - the resultant global variable will have internal linkage. AppendingLinkage - concatenates together all instances (in different translation units) of the - variable into a single variable but is only applicable to arrays.  See + linkage (internal, external, weak, linkonce, appending) for the variable. + If the linkage is InternalLinkage, WeakAnyLinkage, WeakODRLinkage, + LinkOnceAnyLinkage or LinkOnceODRLinkage,  then the resultant + global variable will have internal linkage. AppendingLinkage concatenates + together all instances (in different translation units) of the variable + into a single variable but is only applicable to arrays.  See the LLVM Language Reference for further details on linkage types. Optionally an initializer, a name, and the module to put the variable into may be specified for the global variable as @@ -2576,202 +3818,104 @@ never change at runtime).

  • Constant *getInitializer() -

    Returns the intial value for a GlobalVariable. It is not legal +

    Returns the initial value for a GlobalVariable. It is not legal to call this method if there is no initializer.

+

#include "llvm/Module.h"
doxygen info: -Module Class

+href="/doxygen/BasicBlock_8h-source.html">llvm/BasicBlock.h"
+doxygen info: BasicBlock +Class
+Superclass: Value

-

The Module class represents the top level structure present in LLVM -programs. An LLVM module is effectively either a translation unit of the -original program or a combination of several translation units merged by the -linker. The Module class keeps track of a list of Functions, a list of GlobalVariables, and a SymbolTable. Additionally, it contains a few -helpful member functions that try to make common operations easy.

+

This class represents a single entry multiple exit section of the code, +commonly known as a basic block by the compiler community. The +BasicBlock class maintains a list of Instructions, which form the body of the block. +Matching the language definition, the last element of this list of instructions +is always a terminator instruction (a subclass of the TerminatorInst class).

+ +

In addition to tracking the list of instructions that make up the block, the +BasicBlock class also keeps track of the Function that it is embedded into.

+ +

Note that BasicBlocks themselves are Values, because they are referenced by instructions +like branches and can go in the switch tables. BasicBlocks have type +label.

- -
    -
  • Module::Module(std::string name = "")
  • -
- -

Constructing a Module is easy. You can optionally -provide a name for it (probably based on the name of the translation unit).

- -
    -
  • Module::iterator - Typedef for function list iterator
    - Module::const_iterator - Typedef for const_iterator.
    - - begin(), end() - size(), empty() - -

    These are forwarding methods that make it easy to access the contents of - a Module object's Function - list.

  • - -
  • Module::FunctionListType &getFunctionList() - -

    Returns the list of Functions. This is - necessary to use when you need to update the list or perform a complex - action that doesn't have a forwarding method.

    - -

  • -
- -
- -
    -
  • Module::global_iterator - Typedef for global variable list iterator
    - - Module::const_global_iterator - Typedef for const_iterator.
    - - global_begin(), global_end() - global_size(), global_empty() - -

    These are forwarding methods that make it easy to access the contents of - a Module object's GlobalVariable list.

  • - -
  • Module::GlobalListType &getGlobalList() - -

    Returns the list of GlobalVariables. This is necessary to - use when you need to update the list or perform a complex action that - doesn't have a forwarding method.

    - -

  • -
- -
-
    -
  • SymbolTable *getSymbolTable() -

    Return a reference to the SymbolTable - for this Module.

    +
  • BasicBlock(const std::string &Name = "", Function *Parent = 0) -

  • -
+

The BasicBlock constructor is used to create new basic blocks for +insertion into a function. The constructor optionally takes a name for the new +block, and a Function to insert it into. If +the Parent parameter is specified, the new BasicBlock is +automatically inserted at the end of the specified Function, if not specified, the BasicBlock must be +manually inserted into the Function.

-
+
  • BasicBlock::iterator - Typedef for instruction list iterator
    +BasicBlock::const_iterator - Typedef for const_iterator.
    +begin(), end(), front(), back(), +size(), empty() +STL-style functions for accessing the instruction list. -
      -
    • Function *getFunction(const std::string - &Name, const FunctionType *Ty) +

      These methods and typedefs are forwarding functions that have the same +semantics as the standard library methods of the same names. These methods +expose the underlying instruction list of a basic block in a way that is easy to +manipulate. To get the full complement of container operations (including +operations to update the list), you must use the getInstList() +method.

    • -

      Look up the specified function in the Module SymbolTable. If it does not exist, return - null.

      +
    • BasicBlock::InstListType &getInstList() -
    • Function *getOrInsertFunction(const - std::string &Name, const FunctionType *T) +

      This method is used to get access to the underlying container that actually +holds the Instructions. This method must be used when there isn't a forwarding +function in the BasicBlock class for the operation that you would like +to perform. Because there are no forwarding functions for "updating" +operations, you need to use this if you want to update the contents of a +BasicBlock.

    • -

      Look up the specified function in the Module SymbolTable. If it does not exist, add an - external declaration for the function and return it.

      +
    • Function *getParent() -
    • std::string getTypeName(const Type *Ty) +

      Returns a pointer to Function the block is +embedded into, or a null pointer if it is homeless.

    • -

      If there is at least one entry in the SymbolTable for the specified Type, return it. Otherwise return the empty - string.

      +
    • TerminatorInst *getTerminator() -
    • bool addTypeName(const std::string &Name, const Type *Ty) +

      Returns a pointer to the terminator instruction that appears at the end of +the BasicBlock. If there is no terminator instruction, or if the last +instruction in the block is not a terminator, then a null pointer is +returned.

    • -

      Insert an entry in the SymbolTable - mapping Name to Ty. If there is already an entry for this - name, true is returned and the SymbolTable is not modified.

  • - - - -
    - -

    Constant represents a base class for different types of constants. It -is subclassed by ConstantInt, ConstantArray, etc. for representing -the various types of Constants.

    - -
    - - - -
    -
    - -
    Important Subclasses of Constant
    -
    -
      -
    • ConstantInt : This subclass of Constant represents an integer constant of - any width, including boolean (1 bit integer). -
        -
      • int64_t getSExtValue() const: Returns the underlying value of - this constant as a sign extended signed integer value.
      • -
      • uint64_t getZExtValue() const: Returns the underlying value - of this constant as a zero extended unsigned integer value.
      • -
      • static ConstantInt* get(const Type *Ty, uint64_t Val): - Returns the ConstantInt object that represents the value provided by - Val for integer type Ty.
      • -
      -
    • -
    • ConstantFP : This class represents a floating point constant. -
        -
      • double getValue() const: Returns the underlying value of - this constant.
      • -
      -
    • -
        -
      • bool getValue() const: Returns the underlying value of this - constant.
      • -
      - -
    • ConstantArray : This represents a constant array. -
        -
      • const std::vector<Use> &getValues() const: Returns - a vector of component constants that makeup this array.
      • -
      -
    • -
    • ConstantStruct : This represents a constant struct. -
        -
      • const std::vector<Use> &getValues() const: Returns - a vector of component constants that makeup this array.
      • -
      -
    • -
    • GlobalValue : This represents either a global variable or a function. In - either case, the value is a constant fixed address (after linking). -
    • -
    -
    The Argument class @@ -2789,9 +3933,9 @@ arguments. An argument has a pointer to the parent Function.


    Valid CSS! + src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"> Valid HTML 4.01! + src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Strict"> Dinakar Dhurjati and Chris Lattner