llvm.org GIT mirror llvm / 2bc29dc
Add LLVMContext, which will eventually be used as a container for privatizing a lot of (currently) global state, including the constant and type uniquing tables. For now, just make it a wrapper around the existing APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74488 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
4 changed file(s) with 562 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LLVMCONTEXT_H
10 #define LLVM_LLVMCONTEXT_H
11
12 #include "llvm/Support/DataTypes.h"
13 #include
14 #include
15
16 namespace llvm {
17
18 class LLVMContextImpl;
19 class Constant;
20 class ConstantInt;
21 class ConstantPointerNull;
22 class ConstantStruct;
23 class ConstantAggregateZero;
24 class ConstantArray;
25 class ConstantFP;
26 class ConstantVector;
27 class IntegerType;
28 class PointerType;
29 class StructType;
30 class ArrayType;
31 class VectorType;
32 class Type;
33 class APInt;
34 class APFloat;
35 class Value;
36
37 class LLVMContext {
38 LLVMContextImpl* pImpl;
39 public:
40 LLVMContext();
41 ~LLVMContext();
42
43 // ConstantInt accessors
44 ConstantInt* getConstantIntTrue();
45 ConstantInt* getConstantIntFalse();
46 ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
47 bool isSigned = false);
48 ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
49 ConstantInt* getConstantInt(const APInt& V);
50 Constant* getConstantInt(const Type* Ty, const APInt& V);
51 ConstantInt* getAllOnesConstantInt(const Type* Ty);
52
53 // ConstantPointerNull accessors
54 ConstantPointerNull* getConstantPointerNull(const PointerType* T);
55
56 // ConstantStruct accessors
57 Constant* getConstantStruct(const StructType* T,
58 const std::vector& V);
59 Constant* getConstantStruct(const std::vector& V,
60 bool Packed = false);
61 Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
62 bool Packed = false);
63
64 // ConstantAggregateZero accessors
65 ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
66
67 // ConstantArray accessors
68 Constant* getConstantArray(const ArrayType* T,
69 const std::vector& V);
70 Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
71 unsigned NumVals);
72 Constant* getConstantArray(const std::string& Initializer,
73 bool AddNull = false);
74
75 // ConstantExpr accessors
76 Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
77 Constant* getConstantExprTrunc(Constant* C, const Type* Ty);
78 Constant* getConstantExprSExt(Constant* C, const Type* Ty);
79 Constant* getConstantExprZExt(Constant* C, const Type* Ty);
80 Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty);
81 Constant* getConstantExprFPExtend(Constant* C, const Type* Ty);
82 Constant* getConstantExprUIToFP(Constant* C, const Type* Ty);
83 Constant* getConstantExprSIToFP(Constant* C, const Type* Ty);
84 Constant* getConstantExprFPToUI(Constant* C, const Type* Ty);
85 Constant* getConstantExprFPToSI(Constant* C, const Type* Ty);
86 Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty);
87 Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty);
88 Constant* getConstantExprBitCast(Constant* C, const Type* Ty);
89 Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty);
90 Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty);
91 Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty);
92 Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty);
93 Constant* getConstantExprPointerCast(Constant* C, const Type* Ty);
94 Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty,
95 bool isSigned);
96 Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
97 Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
98 Constant* getConstantExprAlignOf(const Type* Ty);
99 Constant* getConstantExprCompare(unsigned short pred,
100 Constant* C1, Constant* C2);
101 Constant* getConstantExprNeg(Constant* C);
102 Constant* getConstantExprFNeg(Constant* C);
103 Constant* getConstantExprNot(Constant* C);
104 Constant* getConstantExprAdd(Constant* C1, Constant* C2);
105 Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
106 Constant* getConstantExprSub(Constant* C1, Constant* C2);
107 Constant* getConstantExprFSub(Constant* C1, Constant* C2);
108 Constant* getConstantExprMul(Constant* C1, Constant* C2);
109 Constant* getConstantExprFMul(Constant* C1, Constant* C2);
110 Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
111 Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
112 Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
113 Constant* getConstantExprURem(Constant* C1, Constant* C2);
114 Constant* getConstantExprSRem(Constant* C1, Constant* C2);
115 Constant* getConstantExprFRem(Constant* C1, Constant* C2);
116 Constant* getConstantExprAnd(Constant* C1, Constant* C2);
117 Constant* getConstantExprOr(Constant* C1, Constant* C2);
118 Constant* getConstantExprXor(Constant* C1, Constant* C2);
119 Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
120 Constant* RHS);
121 Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
122 Constant* RHS);
123 Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
124 Constant* RHS);
125 Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
126 Constant* RHS);
127 Constant* getConstantExprShl(Constant* C1, Constant* C2);
128 Constant* getConstantExprLShr(Constant* C1, Constant* C2);
129 Constant* getConstantExprAShr(Constant* C1, Constant* C2);
130 Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList,
131 unsigned NumIdx);
132 Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList,
133 unsigned NumIdx);
134 Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
135 Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
136 Constant* Idx);
137 Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
138 Constant* Mask);
139 Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList,
140 unsigned NumIdx);
141 Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
142 const unsigned* IdxList,
143 unsigned NumIdx);
144 Constant* getZeroValueForNegation(const Type* Ty);
145
146 // ConstantFP accessors
147 ConstantFP* getConstantFP(const APFloat& V);
148 Constant* getConstantFP(const Type* Ty, double V);
149 ConstantFP* getConstantFPNegativeZero(const Type* Ty);
150
151 // ConstantVector accessors
152 Constant* getConstantVector(const VectorType* T,
153 const std::vector& V);
154 Constant* getConstantVector(const std::vector& V);
155 Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
156 ConstantVector* getConstantVectorAllOnes(const VectorType* Ty);
157 };
158
159 }
160
161 #endif
1313 Instructions.cpp
1414 IntrinsicInst.cpp
1515 LeakDetector.cpp
16 LLVMContext.cpp
1617 Mangler.cpp
1718 Module.cpp
1819 ModuleProvider.cpp
0 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/LLVMContext.h"
10 #include "llvm/Constants.h"
11 #include "LLVMContextImpl.h"
12
13 using namespace llvm;
14
15 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
16 LLVMContext::~LLVMContext() { delete pImpl; }
17
18 // ConstantInt accessors.
19 ConstantInt* LLVMContext::getConstantIntTrue() {
20 return ConstantInt::getTrue();
21 }
22
23 ConstantInt* LLVMContext::getConstantIntFalse() {
24 return ConstantInt::getFalse();
25 }
26
27 ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
28 bool isSigned) {
29 return ConstantInt::get(Ty, V, isSigned);
30 }
31
32 ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
33 int64_t V) {
34 return ConstantInt::getSigned(Ty, V);
35 }
36
37 ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
38 return ConstantInt::get(V);
39 }
40
41 Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
42 return ConstantInt::get(Ty, V);
43 }
44
45 ConstantInt* LLVMContext::getAllOnesConstantInt(const Type* Ty) {
46 return ConstantInt::getAllOnesValue(Ty);
47 }
48
49
50 // ConstantPointerNull accessors.
51 ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
52 return ConstantPointerNull::get(T);
53 }
54
55
56 // ConstantStruct accessors.
57 Constant* LLVMContext::getConstantStruct(const StructType* T,
58 const std::vector& V) {
59 return ConstantStruct::get(T, V);
60 }
61
62 Constant* LLVMContext::getConstantStruct(const std::vector& V,
63 bool Packed) {
64 return ConstantStruct::get(V, Packed);
65 }
66
67 Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
68 unsigned NumVals, bool Packed) {
69 return ConstantStruct::get(Vals, NumVals, Packed);
70 }
71
72
73 // ConstantAggregateZero accessors.
74 ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
75 return ConstantAggregateZero::get(Ty);
76 }
77
78
79 // ConstantArray accessors.
80 Constant* LLVMContext::getConstantArray(const ArrayType* T,
81 const std::vector& V) {
82 return ConstantArray::get(T, V);
83 }
84
85 Constant* LLVMContext::getConstantArray(const ArrayType* T,
86 Constant* const* Vals,
87 unsigned NumVals) {
88 return ConstantArray::get(T, Vals, NumVals);
89 }
90
91 Constant* LLVMContext::getConstantArray(const std::string& Initializer,
92 bool AddNull) {
93 return ConstantArray::get(Initializer, AddNull);
94 }
95
96
97 // ConstantExpr accessors.
98 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
99 Constant* C2) {
100 return ConstantExpr::get(Opcode, C1, C2);
101 }
102
103 Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
104 return ConstantExpr::getTrunc(C, Ty);
105 }
106
107 Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
108 return ConstantExpr::getSExt(C, Ty);
109 }
110
111 Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
112 return ConstantExpr::getZExt(C, Ty);
113 }
114
115 Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
116 return ConstantExpr::getFPTrunc(C, Ty);
117 }
118
119 Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
120 return ConstantExpr::getFPExtend(C, Ty);
121 }
122
123 Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
124 return ConstantExpr::getUIToFP(C, Ty);
125 }
126
127 Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
128 return ConstantExpr::getSIToFP(C, Ty);
129 }
130
131 Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
132 return ConstantExpr::getFPToUI(C, Ty);
133 }
134
135 Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
136 return ConstantExpr::getFPToSI(C, Ty);
137 }
138
139 Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
140 return ConstantExpr::getPtrToInt(C, Ty);
141 }
142
143 Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
144 return ConstantExpr::getIntToPtr(C, Ty);
145 }
146
147 Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
148 return ConstantExpr::getBitCast(C, Ty);
149 }
150
151 Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
152 const Type* Ty) {
153 return ConstantExpr::getCast(ops, C, Ty);
154 }
155
156 Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
157 const Type* Ty) {
158 return ConstantExpr::getZExtOrBitCast(C, Ty);
159 }
160
161 Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
162 const Type* Ty) {
163 return ConstantExpr::getSExtOrBitCast(C, Ty);
164 }
165
166 Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
167 const Type* Ty) {
168 return ConstantExpr::getTruncOrBitCast(C, Ty);
169 }
170
171 Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
172 return ConstantExpr::getPointerCast(C, Ty);
173 }
174
175 Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
176 bool isSigned) {
177 return ConstantExpr::getIntegerCast(C, Ty, isSigned);
178 }
179
180 Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
181 return ConstantExpr::getFPCast(C, Ty);
182 }
183
184 Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
185 Constant* V2) {
186 return ConstantExpr::getSelect(C, V1, V2);
187 }
188
189 Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
190 return ConstantExpr::getAlignOf(Ty);
191 }
192
193 Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
194 Constant* C1, Constant* C2) {
195 return ConstantExpr::getCompare(pred, C1, C2);
196 }
197
198 Constant* LLVMContext::getConstantExprNeg(Constant* C) {
199 return ConstantExpr::getNeg(C);
200 }
201
202 Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
203 return ConstantExpr::getFNeg(C);
204 }
205
206 Constant* LLVMContext::getConstantExprNot(Constant* C) {
207 return ConstantExpr::getNot(C);
208 }
209
210 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
211 return ConstantExpr::getAdd(C1, C2);
212 }
213
214 Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
215 return ConstantExpr::getFAdd(C1, C2);
216 }
217
218 Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
219 return ConstantExpr::getSub(C1, C2);
220 }
221
222 Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
223 return ConstantExpr::getFSub(C1, C2);
224 }
225
226 Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
227 return ConstantExpr::getMul(C1, C2);
228 }
229
230 Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
231 return ConstantExpr::getFMul(C1, C2);
232 }
233
234 Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
235 return ConstantExpr::getUDiv(C1, C2);
236 }
237
238 Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
239 return ConstantExpr::getSDiv(C1, C2);
240 }
241
242 Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
243 return ConstantExpr::getFDiv(C1, C2);
244 }
245
246 Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
247 return ConstantExpr::getURem(C1, C2);
248 }
249
250 Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
251 return ConstantExpr::getSRem(C1, C2);
252 }
253
254 Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
255 return ConstantExpr::getFRem(C1, C2);
256 }
257
258 Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
259 return ConstantExpr::getAnd(C1, C2);
260 }
261
262 Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
263 return ConstantExpr::getOr(C1, C2);
264 }
265
266 Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
267 return ConstantExpr::getXor(C1, C2);
268 }
269
270 Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
271 Constant* RHS) {
272 return ConstantExpr::getICmp(pred, LHS, RHS);
273 }
274
275 Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
276 Constant* RHS) {
277 return ConstantExpr::getFCmp(pred, LHS, RHS);
278 }
279
280 Constant* LLVMContext::getConstantExprVICmp(unsigned short pred, Constant* LHS,
281 Constant* RHS) {
282 return ConstantExpr::getVICmp(pred, LHS, RHS);
283 }
284
285 Constant* LLVMContext::getConstantExprVFCmp(unsigned short pred, Constant* LHS,
286 Constant* RHS) {
287 return ConstantExpr::getVFCmp(pred, LHS, RHS);
288 }
289
290 Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
291 return ConstantExpr::getShl(C1, C2);
292 }
293
294 Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
295 return ConstantExpr::getLShr(C1, C2);
296 }
297
298 Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
299 return ConstantExpr::getAShr(C1, C2);
300 }
301
302 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
303 Constant* const* IdxList,
304 unsigned NumIdx) {
305 return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
306 }
307
308 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
309 Value* const* IdxList,
310 unsigned NumIdx) {
311 return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
312 }
313
314 Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
315 Constant* Idx) {
316 return ConstantExpr::getExtractElement(Vec, Idx);
317 }
318
319 Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
320 Constant* Elt,
321 Constant* Idx) {
322 return ConstantExpr::getInsertElement(Vec, Elt, Idx);
323 }
324
325 Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
326 Constant* Mask) {
327 return ConstantExpr::getShuffleVector(V1, V2, Mask);
328 }
329
330 Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
331 const unsigned* IdxList,
332 unsigned NumIdx) {
333 return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
334 }
335
336 Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
337 const unsigned* IdxList,
338 unsigned NumIdx) {
339 return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
340 }
341
342 Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
343 return ConstantExpr::getZeroValueForNegationExpr(Ty);
344 }
345
346
347 // ConstantFP accessors.
348 ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
349 return ConstantFP::get(V);
350 }
351
352 Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
353 return ConstantFP::get(Ty, V);
354 }
355
356 ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
357 return ConstantFP::getNegativeZero(Ty);
358 }
359
360
361 // ConstantVector accessors.
362 Constant* LLVMContext::getConstantVector(const VectorType* T,
363 const std::vector& V) {
364 return ConstantVector::get(T, V);
365 }
366
367 Constant* LLVMContext::getConstantVector(const std::vector& V) {
368 return ConstantVector::get(V);
369 }
370
371 Constant* LLVMContext::getConstantVector(Constant* const* Vals,
372 unsigned NumVals) {
373 return ConstantVector::get(Vals, NumVals);
374 }
375
376 ConstantVector* LLVMContext::getConstantVectorAllOnes(const VectorType* Ty) {
377 return ConstantVector::getAllOnesValue(Ty);
378 }
0 //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LLVMCONTEXT_IMPL_H
10 #define LLVM_LLVMCONTEXT_IMPL_H
11
12 namespace llvm {
13 class LLVMContextImpl {
14
15 };
16
17 }
18
19 #endif