Fix include guards so they exactly match file names.
[oota-llvm.git] / include / llvm / IR / 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_IR_LLVMCONTEXT_H
16 #define LLVM_IR_LLVMCONTEXT_H
17
18 #include "llvm/Support/Compiler.h"
19
20 namespace llvm {
21
22 class LLVMContextImpl;
23 class StringRef;
24 class Twine;
25 class Instruction;
26 class Module;
27 class SMDiagnostic;
28 template <typename T> class SmallVectorImpl;
29
30 /// This is an important class for using LLVM in a threaded context.  It
31 /// (opaquely) owns and manages the core "global" data of LLVM's core 
32 /// infrastructure, including the type and constant uniquing tables.
33 /// LLVMContext itself provides no locking guarantees, so you should be careful
34 /// to have one context per thread.
35 class LLVMContext {
36 public:
37   LLVMContextImpl *const pImpl;
38   LLVMContext();
39   ~LLVMContext();
40   
41   // Pinned metadata names, which always have the same value.  This is a
42   // compile-time performance optimization, not a correctness optimization.
43   enum {
44     MD_dbg = 0,  // "dbg"
45     MD_tbaa = 1, // "tbaa"
46     MD_prof = 2,  // "prof"
47     MD_fpmath = 3,  // "fpmath"
48     MD_range = 4, // "range"
49     MD_tbaa_struct = 5 // "tbaa.struct"
50   };
51   
52   /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
53   /// This ID is uniqued across modules in the current LLVMContext.
54   unsigned getMDKindID(StringRef Name) const;
55   
56   /// getMDKindNames - Populate client supplied SmallVector with the name for
57   /// custom metadata IDs registered in this LLVMContext.
58   void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
59   
60   
61   typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context,
62                                 unsigned LocCookie);
63   
64   /// setDiagnosticHandler - This method sets a handler that is invoked
65   /// when problems are detected by the backend.  The first argument is a
66   /// function pointer and the second is a context pointer that gets passed
67   /// into the DiagHandler.
68   ///
69   /// LLVMContext doesn't take ownership or interpret either of these
70   /// pointers.
71   void setDiagnosticHandler(DiagHandlerTy DiagHandler, void *DiagContext = 0);
72
73   /// getDiagnosticHandler - Return the diagnostic handler set by
74   /// setDiagnosticHandler.
75   DiagHandlerTy getDiagnosticHandler() const;
76
77   /// getDiagnosticContext - Return the diagnostic context set by
78   /// setDiagnosticHandler.
79   void *getDiagnosticContext() const;
80   
81   /// FIXME: Temporary copies of the old names; to be removed as soon as
82   /// clang switches to the new ones.
83   typedef DiagHandlerTy InlineAsmDiagHandlerTy;
84   void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
85                                      void *DiagContext = 0) {
86     setDiagnosticHandler(DiagHandler, DiagContext);
87   }
88   InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const {
89     return getDiagnosticHandler();
90   }
91   void *getInlineAsmDiagnosticContext() const {
92     return getDiagnosticContext();
93   }
94   
95   /// emitError - Emit an error message to the currently installed error handler
96   /// with optional location information.  This function returns, so code should
97   /// be prepared to drop the erroneous construct on the floor and "not crash".
98   /// The generated code need not be correct.  The error message will be
99   /// implicitly prefixed with "error: " and should not end with a ".".
100   void emitError(unsigned LocCookie, const Twine &ErrorStr);
101   void emitError(const Instruction *I, const Twine &ErrorStr);
102   void emitError(const Twine &ErrorStr);
103
104   /// emitWarning - This is similar to emitError but it emits a warning instead
105   /// of an error.
106   void emitWarning(unsigned LocCookie, const Twine &ErrorStr);
107   void emitWarning(const Instruction *I, const Twine &ErrorStr);
108   void emitWarning(const Twine &ErrorStr);
109
110 private:
111   LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
112   void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
113
114   /// addModule - Register a module as being instantiated in this context.  If
115   /// the context is deleted, the module will be deleted as well.
116   void addModule(Module*);
117   
118   /// removeModule - Unregister a module from this context.
119   void removeModule(Module*);
120   
121   // Module needs access to the add/removeModule methods.
122   friend class Module;
123 };
124
125 /// getGlobalContext - Returns a global context.  This is for LLVM clients that
126 /// only care about operating on a single thread.
127 extern LLVMContext &getGlobalContext();
128
129 }
130
131 #endif