X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FProgrammersManual.html;h=e8d81a25061daa2db8d873767113226f2c1b5b2e;hb=09aa3f0ef35d9241c92439d74b8d5e9a81d814c2;hp=68367de0bff9ea045220df40570b6f84f0d558b1;hpb=8040cd3cfd7b87661c08ca916daf355593dd8ffa;p=oota-llvm.git diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 68367de0bff..e8d81a25061 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -83,6 +83,7 @@ option
  • "llvm/ADT/StringMap.h"
  • "llvm/ADT/IndexedMap.h"
  • "llvm/ADT/DenseMap.h"
  • +
  • "llvm/ADT/ValueMap.h"
  • <map>
  • Other Map-Like Container Options
  • @@ -93,6 +94,7 @@ option
  • BitVector-like containers
  • @@ -148,6 +150,7 @@ with another Value
  • Ending execution with llvm_shutdown()
  • Lazy initialization with ManagedStatic
  • Achieving Isolation with LLVMContext
  • +
  • Threads and the JIT
  • @@ -266,9 +269,9 @@ can get, so it will not be discussed in this document.

      -
    1. Dinkumware C++ Library -reference - an excellent reference for the STL and other parts of the -standard C++ library.
    2. +
    3. Dinkumware +C++ Library reference - an excellent reference for the STL and other parts +of the standard C++ library.
    4. C++ In a Nutshell - This is an O'Reilly book in the making. It has a decent Standard Library @@ -306,8 +309,6 @@ to write maintainable code more than where to put your curly braces.

        -
      1. CVS -Branch and Tag Primer
      2. Using static and shared libraries across platforms
      @@ -454,8 +455,8 @@ StringMap class which is used extensively in LLVM and Clang.

      may have embedded null characters. Therefore, they cannot simply take a const char *, and taking a const std::string& requires clients to perform a heap allocation which is usually unnecessary. Instead, -many LLVM APIs use a const StringRef& or a const -Twine& for passing strings efficiently.

      +many LLVM APIs use a StringRef or a const Twine& for +passing strings efficiently.

      @@ -474,19 +475,17 @@ on std:string, but does not require heap allocation.

      an std::string, or explicitly with a character pointer and length. For example, the StringRef find function is declared as:

      -
      - iterator find(const StringRef &Key); -
      +
      +  iterator find(StringRef Key);
      +

      and clients can call it using any one of:

      -
      -
      +
         Map.find("foo");                 // Lookup "foo"
         Map.find(std::string("bar"));    // Lookup "bar"
         Map.find(StringRef("\0baz", 4)); // Lookup "\0baz"
       
      -

      Similarly, APIs which need to return a string may return a StringRef instance, which can be used directly or converted to an std::string @@ -496,7 +495,8 @@ for more information.

      You should rarely use the StringRef class directly, because it contains pointers to external memory it is not generally safe to store an instance of the -class (unless you know that the external storage will not be freed).

      +class (unless you know that the external storage will not be freed). StringRef is +small and pervasive enough in LLVM that it should always be passed by value.

      @@ -522,7 +522,7 @@ lightweight rope< which points to temporary (stack allocated) objects. Twines can be implicitly constructed as the result of the plus operator applied to strings (i.e., a C strings, an std::string, or a StringRef). The twine delays the -actual concatentation of strings until it is actually required, at which point +actual concatenation of strings until it is actually required, at which point it can be efficiently rendered directly into a character array. This avoids unnecessary heap allocation involved in constructing the temporary results of string concatenation. See @@ -1095,7 +1095,7 @@ in the default manner.

      -

      ilists have another speciality that must be considered. To be a good +

      ilists have another specialty that must be considered. To be a good citizen in the C++ ecosystem, it needs to support the standard container operations, such as begin and end iterators, etc. Also, the operator-- must work correctly on the end iterator in the @@ -1208,14 +1208,14 @@ and erasing, but does not support iteration.

      -

      SmallPtrSet has all the advantages of SmallSet (and a SmallSet of pointers is -transparently implemented with a SmallPtrSet), but also supports iterators. If +

      SmallPtrSet has all the advantages of SmallSet (and a SmallSet of pointers is +transparently implemented with a SmallPtrSet), but also supports iterators. If more than 'N' insertions are performed, a single quadratically probed hash table is allocated and grows as needed, providing extremely efficient access (constant time insertion/deleting/queries with low constant factors) and is very stingy with malloc traffic.

      -

      Note that, unlike std::set, the iterators of SmallPtrSet are invalidated +

      Note that, unlike std::set, the iterators of SmallPtrSet are invalidated whenever an insertion occurs. Also, the values visited by the iterators are not visited in sorted order.

      @@ -1434,7 +1434,7 @@ to the key string for a value.

      The StringMap is very fast for several reasons: quadratic probing is very cache efficient for lookups, the hash value of strings in buckets is not -recomputed when lookup up an element, StringMap rarely has to touch the +recomputed when looking up an element, StringMap rarely has to touch the memory for unrelated objects when looking up a value (even when hash collisions happen), hash table growth does not recompute the hash values for strings already in the table, and each pair in the map is store in a single allocation @@ -1490,6 +1490,23 @@ inserted into the map) that it needs internally.

      + +
      + +
      + +

      +ValueMap is a wrapper around a DenseMap mapping +Value*s (or subclasses) to another type. When a Value is deleted or RAUW'ed, +ValueMap will update itself so the new version of the key is mapped to the same +value, just as if the key were a WeakVH. You can configure exactly how this +happens, and what else happens on these two events, by passing +a Config parameter to the ValueMap template.

      + +
      +
      <map> @@ -1566,7 +1583,7 @@ please don't use it.

      -

      The BitVector container provides a fixed size set of bits for manipulation. +

      The BitVector container provides a dynamic size set of bits for manipulation. It supports individual bit setting/testing, as well as set operations. The set operations take time O(size of bitvector), but operations are performed one word at a time, instead of one bit at a time. This makes the BitVector very fast for @@ -1575,6 +1592,25 @@ the number of set bits to be high (IE a dense set).

      + + + +
      +

      The SmallBitVector container provides the same interface as BitVector, but +it is optimized for the case where only a small number of bits, less than +25 or so, are needed. It also transparently supports larger bit counts, but +slightly less efficiently than a plain BitVector, so SmallBitVector should +only be used when larger counts are rare. +

      + +

      +At this time, SmallBitVector does not support set operations (and, or, xor), +and its operator[] does not provide an assignable lvalue. +

      +
      +
      SparseBitVector @@ -1804,6 +1840,21 @@ void printNextInstruction(Instruction* inst) {
      +

      Unfortunately, these implicit conversions come at a cost; they prevent +these iterators from conforming to standard iterator conventions, and thus +from being usable with standard algorithms and containers. For example, they +prevent the following code, where B is a BasicBlock, +from compiling:

      + +
      +
      +  llvm::SmallVector<llvm::Instruction *, 16>(B->begin(), B->end());
      +
      +
      + +

      Because of this, these implicit conversions may be removed some day, +and operator* changed to return a pointer instead of a reference.

      +
      @@ -1923,7 +1974,11 @@ for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i -

      Alternately, it's common to have an instance of the Note that dereferencing a Value::use_iterator is not a very cheap +operation. Instead of performing *i above several times, consider +doing it only once in the loop body and reusing its result.

      + +

      Alternatively, it's common to have an instance of the User Class and need to know what Values are used by it. The list of all Values used by a User is known as a use-def chain. Instances of class @@ -1942,10 +1997,13 @@ for (User::op_iterator i = pi->op_begin(), e = pi->op_end(); i != e; ++i) - +

      Declaring objects as const is an important tool of enforcing +mutation free algorithms (such as analyses, etc.). For this purpose above +iterators come in constant flavors as Value::const_use_iterator +and Value::const_op_iterator. They automatically arise when +calling use/op_begin() on const Value*s or +const User*s respectively. Upon dereferencing, they return +const Use*s. Otherwise the above patterns remain unchanged.

      @@ -2348,9 +2406,9 @@ 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. +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.

      @@ -2447,6 +2505,34 @@ isolation is not a concern.

      + + + +
      +

      +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 @@ -2932,9 +3018,9 @@ 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 @@ -2991,7 +3077,7 @@ the lib/VMCore directory.

        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.
        • @@ -3209,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.