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;
24 template <typename T> class SmallVectorImpl;
26 /// This is an important class for using LLVM in a threaded context. It
27 /// (opaquely) owns and manages the core "global" data of LLVM's core
28 /// infrastructure, including the type and constant uniquing tables.
29 /// LLVMContext itself provides no locking guarantees, so you should be careful
30 /// to have one context per thread.
33 LLVMContextImpl *const pImpl;
37 // Pinned metadata names, which always have the same value. This is a
38 // compile-time performance optimization, not a correctness optimization.
43 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
44 /// This ID is uniqued across modules in the current LLVMContext.
45 unsigned getMDKindID(StringRef Name) const;
47 /// getMDKindNames - Populate client supplied SmallVector with the name for
48 /// custom metadata IDs registered in this LLVMContext.
49 void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
51 /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
52 /// when problems with inline asm are detected by the backend. The first
53 /// argument is a function pointer (of type SourceMgr::DiagHandlerTy) and the
54 /// second is a context pointer that gets passed into the DiagHandler.
56 /// LLVMContext doesn't take ownership or interpreter either of these
58 void setInlineAsmDiagnosticHandler(void *DiagHandler, void *DiagContext = 0);
60 /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
61 /// setInlineAsmDiagnosticHandler.
62 void *getInlineAsmDiagnosticHandler() const;
64 /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
65 /// setInlineAsmDiagnosticHandler.
66 void *getInlineAsmDiagnosticContext() const;
69 /// emitError - Emit an error message to the currently installed error handler
70 /// with optional location information. This function returns, so code should
71 /// be prepared to drop the erroneous construct on the floor and "not crash".
72 /// The generated code need not be correct. The error message will be
73 /// implicitly prefixed with "error: " and should not end with a ".".
74 void emitError(unsigned LocCookie, StringRef ErrorStr);
75 void emitError(const Instruction *I, StringRef ErrorStr);
76 void emitError(StringRef ErrorStr);
80 LLVMContext(LLVMContext&);
81 void operator=(LLVMContext&);
83 /// addModule - Register a module as being instantiated in this context. If
84 /// the context is deleted, the module will be deleted as well.
85 void addModule(Module*);
87 /// removeModule - Unregister a module from this context.
88 void removeModule(Module*);
90 // Module needs access to the add/removeModule methods.
94 /// getGlobalContext - Returns a global context. This is for LLVM clients that
95 /// only care about operating on a single thread.
96 extern LLVMContext &getGlobalContext();