Fix up header comments to make Chris happy.
[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 LLVMContextImpl;
25 class Constant;
26 class ConstantInt;
27 class ConstantPointerNull;
28 class ConstantStruct;
29 class ConstantAggregateZero;
30 class ConstantArray;
31 class ConstantFP;
32 class ConstantVector;
33 class IntegerType;
34 class PointerType;
35 class StructType;
36 class ArrayType;
37 class VectorType;
38 class Type;
39 class APInt;
40 class APFloat;
41 class Value;
42
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.
48 class LLVMContext {
49   LLVMContextImpl* pImpl;
50 public:
51   LLVMContext();
52   ~LLVMContext();
53   
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);
63   
64   // ConstantPointerNull accessors
65   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
66   
67   // ConstantStruct accessors
68   Constant* getConstantStruct(const StructType* T,
69                               const std::vector<Constant*>& V);
70   Constant* getConstantStruct(const std::vector<Constant*>& V,
71                               bool Packed = false);
72   Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
73                               bool Packed = false);
74                               
75   // ConstantAggregateZero accessors
76   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
77   
78   // ConstantArray accessors
79   Constant* getConstantArray(const ArrayType* T,
80                              const std::vector<Constant*>& V);
81   Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
82                              unsigned NumVals);
83   Constant* getConstantArray(const std::string& Initializer,
84                              bool AddNull = false);
85                              
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,
106                                        bool isSigned);
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,
131                                 Constant* RHS);
132   Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
133                                 Constant* RHS);
134   Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
135                                  Constant* RHS);
136   Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
137                                  Constant* RHS);
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, 
142                                          unsigned NumIdx);
143   Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList, 
144                                           unsigned NumIdx);
145   Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
146   Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
147                                          Constant* Idx);
148   Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
149                                          Constant* Mask);
150   Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList, 
151                                         unsigned NumIdx);
152   Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
153                                        const unsigned* IdxList,
154                                        unsigned NumIdx);
155   Constant* getZeroValueForNegation(const Type* Ty);
156   
157   // ConstantFP accessors
158   ConstantFP* getConstantFP(const APFloat& V);
159   Constant* getConstantFP(const Type* Ty, double V);
160   ConstantFP* getConstantFPNegativeZero(const Type* Ty);
161   
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);
168 };
169
170 }
171
172 #endif