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
18 #include "llvm/Support/DataTypes.h"
24 class LLVMContextImpl;
27 class ConstantPointerNull;
29 class ConstantAggregateZero;
48 /// This is an important class for using LLVM in a threaded context. It
49 /// (opaquely) owns and manages the core "global" data of LLVM's core
50 /// infrastructure, including the type and constant uniquing tables.
51 /// LLVMContext itself provides no locking guarantees, so you should be careful
52 /// to have one context per thread.
54 LLVMContextImpl* pImpl;
60 Constant* getNullValue(const Type* Ty);
61 Constant* getAllOnesValue(const Type* Ty);
63 // UndefValue accessors
64 UndefValue* getUndef(const Type* Ty);
66 // ConstantInt accessors
67 ConstantInt* getConstantIntTrue();
68 ConstantInt* getConstantIntFalse();
69 Constant* getConstantInt(const Type* Ty, uint64_t V,
70 bool isSigned = false);
71 ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
72 bool isSigned = false);
73 ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
74 ConstantInt* getConstantInt(const APInt& V);
75 Constant* getConstantInt(const Type* Ty, const APInt& V);
76 ConstantInt* getConstantIntAllOnesValue(const Type* Ty);
78 // ConstantPointerNull accessors
79 ConstantPointerNull* getConstantPointerNull(const PointerType* T);
81 // ConstantStruct accessors
82 Constant* getConstantStruct(const StructType* T,
83 const std::vector<Constant*>& V);
84 Constant* getConstantStruct(const std::vector<Constant*>& V,
86 Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
89 // ConstantAggregateZero accessors
90 ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
92 // ConstantArray accessors
93 Constant* getConstantArray(const ArrayType* T,
94 const std::vector<Constant*>& V);
95 Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
97 Constant* getConstantArray(const std::string& Initializer,
100 // ConstantExpr accessors
101 Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
102 Constant* getConstantExprTrunc(Constant* C, const Type* Ty);
103 Constant* getConstantExprSExt(Constant* C, const Type* Ty);
104 Constant* getConstantExprZExt(Constant* C, const Type* Ty);
105 Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty);
106 Constant* getConstantExprFPExtend(Constant* C, const Type* Ty);
107 Constant* getConstantExprUIToFP(Constant* C, const Type* Ty);
108 Constant* getConstantExprSIToFP(Constant* C, const Type* Ty);
109 Constant* getConstantExprFPToUI(Constant* C, const Type* Ty);
110 Constant* getConstantExprFPToSI(Constant* C, const Type* Ty);
111 Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty);
112 Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty);
113 Constant* getConstantExprBitCast(Constant* C, const Type* Ty);
114 Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty);
115 Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty);
116 Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty);
117 Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty);
118 Constant* getConstantExprPointerCast(Constant* C, const Type* Ty);
119 Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty,
121 Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
122 Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
123 Constant* getConstantExprAlignOf(const Type* Ty);
124 Constant* getConstantExprCompare(unsigned short pred,
125 Constant* C1, Constant* C2);
126 Constant* getConstantExprNeg(Constant* C);
127 Constant* getConstantExprFNeg(Constant* C);
128 Constant* getConstantExprNot(Constant* C);
129 Constant* getConstantExprAdd(Constant* C1, Constant* C2);
130 Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
131 Constant* getConstantExprSub(Constant* C1, Constant* C2);
132 Constant* getConstantExprFSub(Constant* C1, Constant* C2);
133 Constant* getConstantExprMul(Constant* C1, Constant* C2);
134 Constant* getConstantExprFMul(Constant* C1, Constant* C2);
135 Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
136 Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
137 Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
138 Constant* getConstantExprURem(Constant* C1, Constant* C2);
139 Constant* getConstantExprSRem(Constant* C1, Constant* C2);
140 Constant* getConstantExprFRem(Constant* C1, Constant* C2);
141 Constant* getConstantExprAnd(Constant* C1, Constant* C2);
142 Constant* getConstantExprOr(Constant* C1, Constant* C2);
143 Constant* getConstantExprXor(Constant* C1, Constant* C2);
144 Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
146 Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
148 Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
150 Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
152 Constant* getConstantExprShl(Constant* C1, Constant* C2);
153 Constant* getConstantExprLShr(Constant* C1, Constant* C2);
154 Constant* getConstantExprAShr(Constant* C1, Constant* C2);
155 Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList,
157 Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList,
159 Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
160 Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
162 Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
164 Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList,
166 Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
167 const unsigned* IdxList,
169 Constant* getConstantExprSizeOf(const Type* Ty);
170 Constant* getZeroValueForNegation(const Type* Ty);
172 // ConstantFP accessors
173 ConstantFP* getConstantFP(const APFloat& V);
174 Constant* getConstantFP(const Type* Ty, double V);
175 ConstantFP* getConstantFPNegativeZero(const Type* Ty);
177 // ConstantVector accessors
178 Constant* getConstantVector(const VectorType* T,
179 const std::vector<Constant*>& V);
180 Constant* getConstantVector(const std::vector<Constant*>& V);
181 Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
182 ConstantVector* getConstantVectorAllOnesValue(const VectorType* Ty);
185 MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
187 // MDString accessors
188 MDString* getMDString(const char *StrBegin, const char *StrEnd);
189 MDString* getMDString(const std::string &Str);
191 // FunctionType accessors
192 FunctionType* getFunctionType(const Type* Result, bool isVarArg);
193 FunctionType* getFunctionType(const Type* Result,
194 const std::vector<const Type*>& Params,
197 // IntegerType accessors
198 const IntegerType* getIntegerType(unsigned NumBits);
200 // OpaqueType accessors
201 OpaqueType* getOpaqueType();
203 // StructType accessors
204 StructType* getStructType(bool isPacked=false);
205 StructType* getStructType(const std::vector<const Type*>& Params,
206 bool isPacked = false);
208 // ArrayType accessors
209 ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
211 // PointerType accessors
212 PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
213 PointerType* getPointerTypeUnqual(const Type* ElementType);
215 // VectorType accessors
216 VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
217 VectorType* getVectorTypeInteger(const VectorType* VTy);
218 VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
219 VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
222 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
223 extern LLVMContext& getGlobalContext();