8c3e2eff9634b6fe0908a22b00f9773a587559dc
[oota-llvm.git] / include / llvm / 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_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <vector>
20 #include <string>
21
22 namespace llvm {
23
24 class APFloat;
25 class APInt;
26 class ArrayType;
27 class Constant;
28 class ConstantAggregateZero;
29 class ConstantArray;
30 class ConstantFP;
31 class ConstantInt;
32 class ConstantPointerNull;
33 class ConstantStruct;
34 class ConstantVector;
35 class FunctionType;
36 class IntegerType;
37 class LLVMContextImpl;
38 class MDNode;
39 class MDString;
40 class OpaqueType;
41 class PointerType;
42 class StringRef;
43 class StructType;
44 class Type;
45 class UndefValue;
46 class Use;
47 class Value;
48 class VectorType;
49
50 /// This is an important class for using LLVM in a threaded context.  It
51 /// (opaquely) owns and manages the core "global" data of LLVM's core 
52 /// infrastructure, including the type and constant uniquing tables.
53 /// LLVMContext itself provides no locking guarantees, so you should be careful
54 /// to have one context per thread.
55 class LLVMContext {
56   LLVMContextImpl* pImpl;
57   
58   friend class ConstantInt;
59   friend class ConstantFP;
60   friend class ConstantStruct;
61   friend class ConstantArray;
62   friend class ConstantVector;
63 public:
64   LLVMContext();
65   ~LLVMContext();
66   
67   // Constant accessors
68   Constant* getNullValue(const Type* Ty);
69   
70   /// @returns the value for an integer constant of the given type that has all
71   /// its bits set to true.
72   /// @brief Get the all ones value
73   Constant* getAllOnesValue(const Type* Ty);
74   
75   // UndefValue accessors
76   UndefValue* getUndef(const Type* Ty);
77   
78   // ConstantInt accessors
79   ConstantInt* getTrue();
80   ConstantInt* getFalse();
81   
82   // ConstantPointerNull accessors
83   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
84                               
85   // ConstantAggregateZero accessors
86   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
87                              
88   // MDNode accessors
89   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
90   
91   // MDString accessors
92   MDString* getMDString(const StringRef &Str);
93   
94   // FunctionType accessors
95   FunctionType* getFunctionType(const Type* Result, bool isVarArg);
96   FunctionType* getFunctionType(const Type* Result,
97                                 const std::vector<const Type*>& Params,
98                                 bool isVarArg);
99                                 
100   // IntegerType accessors
101   const IntegerType* getIntegerType(unsigned NumBits);
102   
103   // OpaqueType accessors
104   OpaqueType* getOpaqueType();
105   
106   // StructType accessors
107   StructType* getStructType(bool isPacked=false);
108   StructType* getStructType(const std::vector<const Type*>& Params,
109                             bool isPacked = false);
110   StructType* getStructType(const Type* type, ...);
111   
112   // ArrayType accessors
113   ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
114   
115   // PointerType accessors
116   PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
117   PointerType* getPointerTypeUnqual(const Type* ElementType);
118   
119   // VectorType accessors
120   VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
121   VectorType* getVectorTypeInteger(const VectorType* VTy);
122   VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
123   VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
124   
125   // Other helpers
126   /// @brief Create a result type for fcmp/icmp
127   const Type* makeCmpResultType(const Type* opnd_type);
128   
129   // Methods for erasing constants
130   void erase(MDString *M);
131   void erase(MDNode *M);
132   void erase(ConstantAggregateZero *Z);
133 };
134
135 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
136 extern LLVMContext& getGlobalContext();
137
138 }
139
140 #endif