43548407f681cb55970bee424ed206476f1b0aae
[oota-llvm.git] / include / llvm / LLVMContext.h
1 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares LLVMContext, a container of "global" state in LLVM, such
11 // as the global type and constant uniquing tables.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
17
18 namespace llvm {
19
20 class LLVMContextImpl;
21 class StringRef;
22 template <typename T> class SmallVectorImpl;
23
24 /// This is an important class for using LLVM in a threaded context.  It
25 /// (opaquely) owns and manages the core "global" data of LLVM's core 
26 /// infrastructure, including the type and constant uniquing tables.
27 /// LLVMContext itself provides no locking guarantees, so you should be careful
28 /// to have one context per thread.
29 class LLVMContext {
30   // DO NOT IMPLEMENT
31   LLVMContext(LLVMContext&);
32   void operator=(LLVMContext&);
33
34 public:
35   LLVMContextImpl *const pImpl;
36   LLVMContext();
37   ~LLVMContext();
38   
39   // Pinned metadata names, which always have the same value.  This is a
40   // compile-time performance optimization, not a correctness optimization.
41   enum {
42     MD_dbg = 1   // "dbg" -> 1.
43   };
44   
45   /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
46   /// This ID is uniqued across modules in the current LLVMContext.
47   unsigned getMDKindID(StringRef Name) const;
48   
49   /// getMDKindNames - Populate client supplied SmallVector with the name for
50   /// custom metadata IDs registered in this LLVMContext.   ID #0 is not used,
51   /// so it is filled in as an empty string.
52   void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
53   
54   /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
55   /// when problems with inline asm are detected by the backend.  The first
56   /// argument is a function pointer (of type SourceMgr::DiagHandlerTy) and the
57   /// second is a context pointer that gets passed into the DiagHandler.
58   ///
59   /// LLVMContext doesn't take ownership or interpreter either of these
60   /// pointers.
61   void setInlineAsmDiagnosticHandler(void *DiagHandler, void *DiagContext = 0);
62
63   /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
64   /// setInlineAsmDiagnosticHandler.
65   void *getInlineAsmDiagnosticHandler() const;
66
67   /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
68   /// setInlineAsmDiagnosticHandler.
69   void *getInlineAsmDiagnosticContext() const;
70   
71 };
72
73 /// getGlobalContext - Returns a global context.  This is for LLVM clients that
74 /// only care about operating on a single thread.
75 extern LLVMContext &getGlobalContext();
76
77 }
78
79 #endif