Return ConstantVector to 2.5 API.
[oota-llvm.git] / include / llvm / LLVMContext.h
1 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares LLVMContext, a container of "global" state in LLVM, such
11 // as the global type and constant uniquing tables.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <vector>
20 #include <string>
21
22 namespace llvm {
23
24 class APFloat;
25 class APInt;
26 class ArrayType;
27 class Constant;
28 class ConstantAggregateZero;
29 class ConstantArray;
30 class ConstantFP;
31 class ConstantInt;
32 class ConstantPointerNull;
33 class ConstantStruct;
34 class ConstantVector;
35 class FunctionType;
36 class IntegerType;
37 class LLVMContextImpl;
38 class MDNode;
39 class MDString;
40 class OpaqueType;
41 class PointerType;
42 class StringRef;
43 class StructType;
44 class Type;
45 class UndefValue;
46 class Use;
47 class Value;
48 class VectorType;
49
50 /// This is an important class for using LLVM in a threaded context.  It
51 /// (opaquely) owns and manages the core "global" data of LLVM's core 
52 /// infrastructure, including the type and constant uniquing tables.
53 /// LLVMContext itself provides no locking guarantees, so you should be careful
54 /// to have one context per thread.
55 class LLVMContext {
56   LLVMContextImpl* pImpl;
57   
58   friend class ConstantInt;
59   friend class ConstantFP;
60   friend class ConstantStruct;
61   friend class ConstantArray;
62   friend class ConstantVector;
63 public:
64   LLVMContext();
65   ~LLVMContext();
66   
67   // Constant accessors
68   Constant* getNullValue(const Type* Ty);
69   
70   /// @returns the value for an integer constant of the given type that has all
71   /// its bits set to true.
72   /// @brief Get the all ones value
73   Constant* getAllOnesValue(const Type* Ty);
74   
75   // UndefValue accessors
76   UndefValue* getUndef(const Type* Ty);
77   
78   // ConstantInt accessors
79   ConstantInt* getTrue();
80   ConstantInt* getFalse();
81   
82   // ConstantPointerNull accessors
83   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
84                               
85   // ConstantAggregateZero accessors
86   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
87                              
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,
108                                        bool isSigned);
109   Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
110   Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
111   
112   /// getAlignOf constant expr - computes the alignment of a type in a target
113   /// independent way (Note: the return type is an i32; Note: assumes that i8
114   /// is byte aligned).
115   ///
116   Constant* getConstantExprAlignOf(const Type* Ty);
117   Constant* getConstantExprCompare(unsigned short pred,
118                                    Constant* C1, Constant* C2);
119   Constant* getConstantExprNeg(Constant* C);
120   Constant* getConstantExprFNeg(Constant* C);
121   Constant* getConstantExprNot(Constant* C);
122   Constant* getConstantExprAdd(Constant* C1, Constant* C2);
123   Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
124   Constant* getConstantExprSub(Constant* C1, Constant* C2);
125   Constant* getConstantExprFSub(Constant* C1, Constant* C2);
126   Constant* getConstantExprMul(Constant* C1, Constant* C2);
127   Constant* getConstantExprFMul(Constant* C1, Constant* C2);
128   Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
129   Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
130   Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
131   Constant* getConstantExprURem(Constant* C1, Constant* C2);
132   Constant* getConstantExprSRem(Constant* C1, Constant* C2);
133   Constant* getConstantExprFRem(Constant* C1, Constant* C2);
134   Constant* getConstantExprAnd(Constant* C1, Constant* C2);
135   Constant* getConstantExprOr(Constant* C1, Constant* C2);
136   Constant* getConstantExprXor(Constant* C1, Constant* C2);
137   Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
138                                 Constant* RHS);
139   Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
140                                 Constant* RHS);
141   Constant* getConstantExprShl(Constant* C1, Constant* C2);
142   Constant* getConstantExprLShr(Constant* C1, Constant* C2);
143   Constant* getConstantExprAShr(Constant* C1, Constant* C2);
144   Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList, 
145                                          unsigned NumIdx);
146   Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList, 
147                                           unsigned NumIdx);
148   Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
149   Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
150                                          Constant* Idx);
151   Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
152                                          Constant* Mask);
153   Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList, 
154                                         unsigned NumIdx);
155   Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
156                                        const unsigned* IdxList,
157                                        unsigned NumIdx);
158
159   /// getSizeOf constant expr - computes the size of a type in a target
160   /// independent way (Note: the return type is an i64).
161   ///
162   Constant* getConstantExprSizeOf(const Type* Ty);
163   
164   // MDNode accessors
165   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
166   
167   // MDString accessors
168   MDString* getMDString(const StringRef &Str);
169   
170   // FunctionType accessors
171   FunctionType* getFunctionType(const Type* Result, bool isVarArg);
172   FunctionType* getFunctionType(const Type* Result,
173                                 const std::vector<const Type*>& Params,
174                                 bool isVarArg);
175                                 
176   // IntegerType accessors
177   const IntegerType* getIntegerType(unsigned NumBits);
178   
179   // OpaqueType accessors
180   OpaqueType* getOpaqueType();
181   
182   // StructType accessors
183   StructType* getStructType(bool isPacked=false);
184   StructType* getStructType(const std::vector<const Type*>& Params,
185                             bool isPacked = false);
186   StructType* getStructType(const Type* type, ...);
187   
188   // ArrayType accessors
189   ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
190   
191   // PointerType accessors
192   PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
193   PointerType* getPointerTypeUnqual(const Type* ElementType);
194   
195   // VectorType accessors
196   VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
197   VectorType* getVectorTypeInteger(const VectorType* VTy);
198   VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
199   VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
200   
201   // Other helpers
202   /// @brief Create a result type for fcmp/icmp
203   const Type* makeCmpResultType(const Type* opnd_type);
204   
205   // Methods for erasing constants
206   void erase(MDString *M);
207   void erase(MDNode *M);
208   void erase(ConstantAggregateZero *Z);
209 };
210
211 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
212 extern LLVMContext& getGlobalContext();
213
214 }
215
216 #endif