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;
47 /// This is an important class for using LLVM in a threaded context. It
48 /// (opaquely) owns and manages the core "global" data of LLVM's core
49 /// infrastructure, including the type and constant uniquing tables.
50 /// LLVMContext itself provides no locking guarantees, so you should be careful
51 /// to have one context per thread.
53 LLVMContextImpl* pImpl;
59 Constant* getNullValue(const Type* Ty);
60 Constant* getAllOnesValue(const Type* Ty);
62 // UndefValue accessors
63 UndefValue* getUndef(const Type* Ty);
65 // ConstantInt accessors
66 ConstantInt* getConstantIntTrue();
67 ConstantInt* getConstantIntFalse();
68 ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
69 bool isSigned = false);
70 ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
71 ConstantInt* getConstantInt(const APInt& V);
72 Constant* getConstantInt(const Type* Ty, const APInt& V);
73 ConstantInt* getAllOnesConstantInt(const Type* Ty);
75 // ConstantPointerNull accessors
76 ConstantPointerNull* getConstantPointerNull(const PointerType* T);
78 // ConstantStruct accessors
79 Constant* getConstantStruct(const StructType* T,
80 const std::vector<Constant*>& V);
81 Constant* getConstantStruct(const std::vector<Constant*>& V,
83 Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
86 // ConstantAggregateZero accessors
87 ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
89 // ConstantArray accessors
90 Constant* getConstantArray(const ArrayType* T,
91 const std::vector<Constant*>& V);
92 Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
94 Constant* getConstantArray(const std::string& Initializer,
95 bool AddNull = false);
97 // ConstantExpr accessors
98 Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
99 Constant* getConstantExprTrunc(Constant* C, const Type* Ty);
100 Constant* getConstantExprSExt(Constant* C, const Type* Ty);
101 Constant* getConstantExprZExt(Constant* C, const Type* Ty);
102 Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty);
103 Constant* getConstantExprFPExtend(Constant* C, const Type* Ty);
104 Constant* getConstantExprUIToFP(Constant* C, const Type* Ty);
105 Constant* getConstantExprSIToFP(Constant* C, const Type* Ty);
106 Constant* getConstantExprFPToUI(Constant* C, const Type* Ty);
107 Constant* getConstantExprFPToSI(Constant* C, const Type* Ty);
108 Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty);
109 Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty);
110 Constant* getConstantExprBitCast(Constant* C, const Type* Ty);
111 Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty);
112 Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty);
113 Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty);
114 Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty);
115 Constant* getConstantExprPointerCast(Constant* C, const Type* Ty);
116 Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty,
118 Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
119 Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
120 Constant* getConstantExprAlignOf(const Type* Ty);
121 Constant* getConstantExprCompare(unsigned short pred,
122 Constant* C1, Constant* C2);
123 Constant* getConstantExprNeg(Constant* C);
124 Constant* getConstantExprFNeg(Constant* C);
125 Constant* getConstantExprNot(Constant* C);
126 Constant* getConstantExprAdd(Constant* C1, Constant* C2);
127 Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
128 Constant* getConstantExprSub(Constant* C1, Constant* C2);
129 Constant* getConstantExprFSub(Constant* C1, Constant* C2);
130 Constant* getConstantExprMul(Constant* C1, Constant* C2);
131 Constant* getConstantExprFMul(Constant* C1, Constant* C2);
132 Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
133 Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
134 Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
135 Constant* getConstantExprURem(Constant* C1, Constant* C2);
136 Constant* getConstantExprSRem(Constant* C1, Constant* C2);
137 Constant* getConstantExprFRem(Constant* C1, Constant* C2);
138 Constant* getConstantExprAnd(Constant* C1, Constant* C2);
139 Constant* getConstantExprOr(Constant* C1, Constant* C2);
140 Constant* getConstantExprXor(Constant* C1, Constant* C2);
141 Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
143 Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
145 Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
147 Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
149 Constant* getConstantExprShl(Constant* C1, Constant* C2);
150 Constant* getConstantExprLShr(Constant* C1, Constant* C2);
151 Constant* getConstantExprAShr(Constant* C1, Constant* C2);
152 Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList,
154 Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList,
156 Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
157 Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
159 Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
161 Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList,
163 Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
164 const unsigned* IdxList,
166 Constant* getZeroValueForNegation(const Type* Ty);
168 // ConstantFP accessors
169 ConstantFP* getConstantFP(const APFloat& V);
170 Constant* getConstantFP(const Type* Ty, double V);
171 ConstantFP* getConstantFPNegativeZero(const Type* Ty);
173 // ConstantVector accessors
174 Constant* getConstantVector(const VectorType* T,
175 const std::vector<Constant*>& V);
176 Constant* getConstantVector(const std::vector<Constant*>& V);
177 Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
178 ConstantVector* getConstantVectorAllOnes(const VectorType* Ty);
181 MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
183 // FunctionType accessors
184 FunctionType* getFunctionType(const Type* Result,
185 const std::vector<const Type*>& Params,
188 // IntegerType accessors
189 const IntegerType* getIntegerType(unsigned NumBits);
191 // OpaqueType accessors
192 OpaqueType* getOpaqueType();
194 // StructType accessors
195 StructType* getStructType(bool isPacked=false);
196 StructType* getStructType(const std::vector<const Type*>& Params,
197 bool isPacked = false);
199 // ArrayType accessors
200 ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
202 // PointerType accessors
203 PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
204 PointerType* getPointerTypeUnqual(const Type* ElementType);
206 // VectorType accessors
207 VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
208 VectorType* getVectorTypeInteger(const VectorType* VTy);
209 VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
210 VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
213 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
214 extern LLVMContext& getGlobalContext();