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;
26 template <typename T> class SmallVectorImpl;
28 /// This is an important class for using LLVM in a threaded context. It
29 /// (opaquely) owns and manages the core "global" data of LLVM's core
30 /// infrastructure, including the type and constant uniquing tables.
31 /// LLVMContext itself provides no locking guarantees, so you should be careful
32 /// to have one context per thread.
35 LLVMContextImpl *const pImpl;
39 // Pinned metadata names, which always have the same value. This is a
40 // compile-time performance optimization, not a correctness optimization.
43 MD_tbaa = 1, // "tbaa"
44 MD_prof = 2, // "prof"
45 MD_fpmath = 3, // "fpmath"
46 MD_range = 4, // "range"
47 MD_tbaa_struct = 5 // "tbaa.struct"
50 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
51 /// This ID is uniqued across modules in the current LLVMContext.
52 unsigned getMDKindID(StringRef Name) const;
54 /// getMDKindNames - Populate client supplied SmallVector with the name for
55 /// custom metadata IDs registered in this LLVMContext.
56 void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
59 typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
62 /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
63 /// when problems with inline asm are detected by the backend. The first
64 /// argument is a function pointer and the second is a context pointer that
65 /// gets passed into the DiagHandler.
67 /// LLVMContext doesn't take ownership or interpret either of these
69 void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
70 void *DiagContext = 0);
72 /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
73 /// setInlineAsmDiagnosticHandler.
74 InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const;
76 /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
77 /// setInlineAsmDiagnosticHandler.
78 void *getInlineAsmDiagnosticContext() const;
81 /// emitError - Emit an error message to the currently installed error handler
82 /// with optional location information. This function returns, so code should
83 /// be prepared to drop the erroneous construct on the floor and "not crash".
84 /// The generated code need not be correct. The error message will be
85 /// implicitly prefixed with "error: " and should not end with a ".".
86 void emitError(unsigned LocCookie, const Twine &ErrorStr);
87 void emitError(const Instruction *I, const Twine &ErrorStr);
88 void emitError(const Twine &ErrorStr);
92 LLVMContext(LLVMContext&);
93 void operator=(LLVMContext&);
95 /// addModule - Register a module as being instantiated in this context. If
96 /// the context is deleted, the module will be deleted as well.
97 void addModule(Module*);
99 /// removeModule - Unregister a module from this context.
100 void removeModule(Module*);
102 // Module needs access to the add/removeModule methods.
106 /// getGlobalContext - Returns a global context. This is for LLVM clients that
107 /// only care about operating on a single thread.
108 extern LLVMContext &getGlobalContext();