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;
43 /// This is an important class for using LLVM in a threaded context. It
44 /// (opaquely) owns and manages the core "global" data of LLVM's core
45 /// infrastructure, including the type and constant uniquing tables.
46 /// LLVMContext itself provides no locking guarantees, so you should be careful
47 /// to have one context per thread.
49 LLVMContextImpl* pImpl;
54 // ConstantInt accessors
55 ConstantInt* getConstantIntTrue();
56 ConstantInt* getConstantIntFalse();
57 ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
58 bool isSigned = false);
59 ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
60 ConstantInt* getConstantInt(const APInt& V);
61 Constant* getConstantInt(const Type* Ty, const APInt& V);
62 ConstantInt* getAllOnesConstantInt(const Type* Ty);
64 // ConstantPointerNull accessors
65 ConstantPointerNull* getConstantPointerNull(const PointerType* T);
67 // ConstantStruct accessors
68 Constant* getConstantStruct(const StructType* T,
69 const std::vector<Constant*>& V);
70 Constant* getConstantStruct(const std::vector<Constant*>& V,
72 Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
75 // ConstantAggregateZero accessors
76 ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
78 // ConstantArray accessors
79 Constant* getConstantArray(const ArrayType* T,
80 const std::vector<Constant*>& V);
81 Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
83 Constant* getConstantArray(const std::string& Initializer,
84 bool AddNull = false);
86 // ConstantExpr accessors
87 Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
88 Constant* getConstantExprTrunc(Constant* C, const Type* Ty);
89 Constant* getConstantExprSExt(Constant* C, const Type* Ty);
90 Constant* getConstantExprZExt(Constant* C, const Type* Ty);
91 Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty);
92 Constant* getConstantExprFPExtend(Constant* C, const Type* Ty);
93 Constant* getConstantExprUIToFP(Constant* C, const Type* Ty);
94 Constant* getConstantExprSIToFP(Constant* C, const Type* Ty);
95 Constant* getConstantExprFPToUI(Constant* C, const Type* Ty);
96 Constant* getConstantExprFPToSI(Constant* C, const Type* Ty);
97 Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty);
98 Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty);
99 Constant* getConstantExprBitCast(Constant* C, const Type* Ty);
100 Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty);
101 Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty);
102 Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty);
103 Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty);
104 Constant* getConstantExprPointerCast(Constant* C, const Type* Ty);
105 Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty,
107 Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
108 Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
109 Constant* getConstantExprAlignOf(const Type* Ty);
110 Constant* getConstantExprCompare(unsigned short pred,
111 Constant* C1, Constant* C2);
112 Constant* getConstantExprNeg(Constant* C);
113 Constant* getConstantExprFNeg(Constant* C);
114 Constant* getConstantExprNot(Constant* C);
115 Constant* getConstantExprAdd(Constant* C1, Constant* C2);
116 Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
117 Constant* getConstantExprSub(Constant* C1, Constant* C2);
118 Constant* getConstantExprFSub(Constant* C1, Constant* C2);
119 Constant* getConstantExprMul(Constant* C1, Constant* C2);
120 Constant* getConstantExprFMul(Constant* C1, Constant* C2);
121 Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
122 Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
123 Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
124 Constant* getConstantExprURem(Constant* C1, Constant* C2);
125 Constant* getConstantExprSRem(Constant* C1, Constant* C2);
126 Constant* getConstantExprFRem(Constant* C1, Constant* C2);
127 Constant* getConstantExprAnd(Constant* C1, Constant* C2);
128 Constant* getConstantExprOr(Constant* C1, Constant* C2);
129 Constant* getConstantExprXor(Constant* C1, Constant* C2);
130 Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
132 Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
134 Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
136 Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
138 Constant* getConstantExprShl(Constant* C1, Constant* C2);
139 Constant* getConstantExprLShr(Constant* C1, Constant* C2);
140 Constant* getConstantExprAShr(Constant* C1, Constant* C2);
141 Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList,
143 Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList,
145 Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
146 Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
148 Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
150 Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList,
152 Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
153 const unsigned* IdxList,
155 Constant* getZeroValueForNegation(const Type* Ty);
157 // ConstantFP accessors
158 ConstantFP* getConstantFP(const APFloat& V);
159 Constant* getConstantFP(const Type* Ty, double V);
160 ConstantFP* getConstantFPNegativeZero(const Type* Ty);
162 // ConstantVector accessors
163 Constant* getConstantVector(const VectorType* T,
164 const std::vector<Constant*>& V);
165 Constant* getConstantVector(const std::vector<Constant*>& V);
166 Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
167 ConstantVector* getConstantVectorAllOnes(const VectorType* Ty);