1 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares LLVMContext, a container of "global" state in LLVM, such
11 // as the global type and constant uniquing tables.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
20 class LLVMContextImpl;
25 template <typename T> class SmallVectorImpl;
27 /// This is an important class for using LLVM in a threaded context. It
28 /// (opaquely) owns and manages the core "global" data of LLVM's core
29 /// infrastructure, including the type and constant uniquing tables.
30 /// LLVMContext itself provides no locking guarantees, so you should be careful
31 /// to have one context per thread.
34 LLVMContextImpl *const pImpl;
38 // Pinned metadata names, which always have the same value. This is a
39 // compile-time performance optimization, not a correctness optimization.
42 MD_tbaa = 1, // "tbaa"
43 MD_prof = 2, // "prof"
44 MD_fpaccuracy = 3 // "fpaccuracy"
47 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
48 /// This ID is uniqued across modules in the current LLVMContext.
49 unsigned getMDKindID(StringRef Name) const;
51 /// getMDKindNames - Populate client supplied SmallVector with the name for
52 /// custom metadata IDs registered in this LLVMContext.
53 void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
56 typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
59 /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
60 /// when problems with inline asm are detected by the backend. The first
61 /// argument is a function pointer and the second is a context pointer that
62 /// gets passed into the DiagHandler.
64 /// LLVMContext doesn't take ownership or interpret either of these
66 void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
67 void *DiagContext = 0);
69 /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
70 /// setInlineAsmDiagnosticHandler.
71 InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const;
73 /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
74 /// setInlineAsmDiagnosticHandler.
75 void *getInlineAsmDiagnosticContext() const;
78 /// emitError - Emit an error message to the currently installed error handler
79 /// with optional location information. This function returns, so code should
80 /// be prepared to drop the erroneous construct on the floor and "not crash".
81 /// The generated code need not be correct. The error message will be
82 /// implicitly prefixed with "error: " and should not end with a ".".
83 void emitError(unsigned LocCookie, StringRef ErrorStr);
84 void emitError(const Instruction *I, StringRef ErrorStr);
85 void emitError(StringRef ErrorStr);
89 LLVMContext(LLVMContext&);
90 void operator=(LLVMContext&);
92 /// addModule - Register a module as being instantiated in this context. If
93 /// the context is deleted, the module will be deleted as well.
94 void addModule(Module*);
96 /// removeModule - Unregister a module from this context.
97 void removeModule(Module*);
99 // Module needs access to the add/removeModule methods.
103 /// getGlobalContext - Returns a global context. This is for LLVM clients that
104 /// only care about operating on a single thread.
105 extern LLVMContext &getGlobalContext();