blob: 6d36d5eb1e37dfdd251e53a80d2bbaa8f14eb3db [file] [log] [blame]
Owen Anderson2bc29dc2009-06-30 00:48:55 +00001//===-- 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//===----------------------------------------------------------------------===//
Owen Anderson52170072009-06-30 17:06:46 +00009//
10// This file declares LLVMContext, a container of "global" state in LLVM, such
11// as the global type and constant uniquing tables.
12//
13//===----------------------------------------------------------------------===//
Owen Anderson2bc29dc2009-06-30 00:48:55 +000014
15#ifndef LLVM_LLVMCONTEXT_H
16#define LLVM_LLVMCONTEXT_H
17
Owen Anderson2bc29dc2009-06-30 00:48:55 +000018namespace llvm {
19
Benjamin Kramer12ddd402009-08-11 17:45:13 +000020class LLVMContextImpl;
Chris Lattner08113472009-12-29 09:01:33 +000021class StringRef;
22template <typename T> class SmallVectorImpl;
Dan Gohman82a47e92009-10-06 17:43:57 +000023
Owen Anderson52170072009-06-30 17:06:46 +000024/// 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.
Benjamin Kramer12ddd402009-08-11 17:45:13 +000029class LLVMContext {
Owen Anderson1d0be152009-08-13 21:58:54 +000030 // DO NOT IMPLEMENT
31 LLVMContext(LLVMContext&);
32 void operator=(LLVMContext&);
Dan Gohman82a47e92009-10-06 17:43:57 +000033
Benjamin Kramer12ddd402009-08-11 17:45:13 +000034public:
Chris Lattner08113472009-12-29 09:01:33 +000035 LLVMContextImpl *const pImpl;
Owen Anderson2bc29dc2009-06-30 00:48:55 +000036 LLVMContext();
37 ~LLVMContext();
Chris Lattner08113472009-12-29 09:01:33 +000038
39 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
40 /// This ID is uniqued across modules in the current LLVMContext.
41 unsigned getMDKindID(StringRef Name) const;
42
43 /// getMDKindNames - Populate client supplied SmallVector with the name for
44 /// custom metadata IDs registered in this LLVMContext. ID #0 is not used,
45 /// so it is filled in as an empty string.
46 void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
Owen Anderson2bc29dc2009-06-30 00:48:55 +000047};
48
Chris Lattner08113472009-12-29 09:01:33 +000049/// getGlobalContext - Returns a global context. This is for LLVM clients that
50/// only care about operating on a single thread.
51extern LLVMContext &getGlobalContext();
Owen Andersondb47ed02009-06-30 23:39:59 +000052
Owen Anderson2bc29dc2009-06-30 00:48:55 +000053}
54
55#endif