X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FProgrammersManual.html;h=d74a645558c95b4eef25664f7cba9201ed5a32a3;hb=4a12de72b050f9276d2027fc9f7a29fc30af5cec;hp=e3f91a2af64733d221cb13696f63bdce69f3c12c;hpb=e15192b36bb5e99838d3f70bf79f7b8bed7a75b9;p=oota-llvm.git diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index e3f91a2af64..d74a645558c 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
  • @@ -147,6 +149,8 @@ with another Value
  • Ending execution with llvm_shutdown()
  • Lazy initialization with ManagedStatic
  • +
  • Achieving Isolation with LLVMContext
  • +
  • Threads and the JIT
  • @@ -646,6 +650,21 @@ on when the name is specified. This allows, for example, all debug information for instruction scheduling to be enabled with -debug-type=InstrSched, even if the source lives in multiple files.

    +

    The DEBUG_WITH_TYPE macro is also available for situations where you +would like to set DEBUG_TYPE, but only for one specific DEBUG +statement. It takes an additional first parameter, which is the type to use. For +example, the preceding example could be written as:

    + + +
    +
    +DEBUG_WITH_TYPE("", errs() << "No debug type\n");
    +DEBUG_WITH_TYPE("foo", errs() << "'foo' debug type\n");
    +DEBUG_WITH_TYPE("bar", errs() << "'bar' debug type\n"));
    +DEBUG_WITH_TYPE("", errs() << "No debug type (2)\n");
    +
    +
    + @@ -1474,6 +1493,23 @@ inserted into the map) that it needs internally.

    + +
    + "llvm/ADT/ValueMap.h" +
    + +
    + +

    +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> @@ -1550,7 +1586,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 @@ -1559,6 +1595,25 @@ the number of set bits to be high (IE a dense set).

    + +
    + SmallBitVector +
    + +
    +

    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 @@ -1638,7 +1693,7 @@ an example that prints the name of a BasicBlock and the number of for (Function::iterator i = func->begin(), e = func->end(); i != e; ++i) // Print out the name of the basic block if it has one, and then the // number of instructions that it contains - llvm::cerr << "Basic block (name=" << i->getName() << ") has " + errs() << "Basic block (name=" << i->getName() << ") has " << i->size() << " instructions.\n";
    @@ -1671,14 +1726,14 @@ a BasicBlock:

    for (BasicBlock::iterator i = blk->begin(), e = blk->end(); i != e; ++i) // The next statement works since operator<<(ostream&,...) // is overloaded for Instruction& - llvm::cerr << *i << "\n"; + errs() << *i << "\n";

    However, this isn't really the best way to print out the contents of a BasicBlock! Since the ostream operators are overloaded for virtually anything you'll care about, you could have just invoked the print routine on the -basic block itself: llvm::cerr << *blk << "\n";.

    +basic block itself: errs() << *blk << "\n";.

    @@ -1704,7 +1759,7 @@ small example that shows how to dump all instructions in a function to the stand // F is a pointer to a Function instance for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) - llvm::cerr << *I << "\n"; + errs() << *I << "\n"; @@ -1783,7 +1838,7 @@ without actually obtaining it via iteration over some structure:

    void printNextInstruction(Instruction* inst) { BasicBlock::iterator it(inst); ++it; // After this line, it refers to the instruction after *inst - if (it != inst->getParent()->end()) llvm::cerr << *it << "\n"; + if (it != inst->getParent()->end()) errs() << *it << "\n"; } @@ -1901,8 +1956,8 @@ Function *F = ...; for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i) if (Instruction *Inst = dyn_cast<Instruction>(*i)) { - llvm::cerr << "F is used in instruction:\n"; - llvm::cerr << *Inst << "\n"; + errs() << "F is used in instruction:\n"; + errs() << *Inst << "\n"; } @@ -2332,9 +2387,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.

    @@ -2387,6 +2442,78 @@ 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 @@ -2872,9 +2999,9 @@ the lib/VMCore directory.