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