hopefully unbreak the build by making this-> explicit for dependent
[oota-llvm.git] / include / llvm / Support / NoFolder.h
1 //======-- llvm/Support/NoFolder.h - Constant folding helper -*- 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 defines the NoFolder class, a helper for IRBuilder.  It provides
11 // IRBuilder with a set of methods for creating unfolded constants.  This is
12 // useful for learners trying to understand how LLVM IR works, and who don't
13 // want details to be hidden by the constant folder.  For general constant
14 // creation and folding, use ConstantExpr and the routines in
15 // llvm/Analysis/ConstantFolding.h.
16 //
17 // Note: since it is not actually possible to create unfolded constants, this
18 // class returns values rather than constants.  The values do not have names,
19 // even if names were provided to IRBuilder, which may be confusing.
20 //
21 //===----------------------------------------------------------------------===//
22
23 #ifndef LLVM_SUPPORT_NOFOLDER_H
24 #define LLVM_SUPPORT_NOFOLDER_H
25
26 #include "llvm/Constants.h"
27 #include "llvm/Instructions.h"
28
29 namespace llvm {
30
31 class LLVMContext;
32
33 /// NoFolder - Create "constants" (actually, values) with no folding.
34 class NoFolder {
35 public:
36   explicit NoFolder(LLVMContext &) {}
37
38   //===--------------------------------------------------------------------===//
39   // Binary Operators
40   //===--------------------------------------------------------------------===//
41
42   Value *CreateAdd(Constant *LHS, Constant *RHS) const {
43     return BinaryOperator::CreateAdd(LHS, RHS);
44   }
45   Value *CreateNSWAdd(Constant *LHS, Constant *RHS) const {
46     return BinaryOperator::CreateNSWAdd(LHS, RHS);
47   }
48   Value *CreateFAdd(Constant *LHS, Constant *RHS) const {
49     return BinaryOperator::CreateFAdd(LHS, RHS);
50   }
51   Value *CreateSub(Constant *LHS, Constant *RHS) const {
52     return BinaryOperator::CreateSub(LHS, RHS);
53   }
54   Value *CreateFSub(Constant *LHS, Constant *RHS) const {
55     return BinaryOperator::CreateFSub(LHS, RHS);
56   }
57   Value *CreateMul(Constant *LHS, Constant *RHS) const {
58     return BinaryOperator::CreateMul(LHS, RHS);
59   }
60   Value *CreateFMul(Constant *LHS, Constant *RHS) const {
61     return BinaryOperator::CreateFMul(LHS, RHS);
62   }
63   Value *CreateUDiv(Constant *LHS, Constant *RHS) const {
64     return BinaryOperator::CreateUDiv(LHS, RHS);
65   }
66   Value *CreateSDiv(Constant *LHS, Constant *RHS) const {
67     return BinaryOperator::CreateSDiv(LHS, RHS);
68   }
69   Value *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
70     return BinaryOperator::CreateExactSDiv(LHS, RHS);
71   }
72   Value *CreateFDiv(Constant *LHS, Constant *RHS) const {
73     return BinaryOperator::CreateFDiv(LHS, RHS);
74   }
75   Value *CreateURem(Constant *LHS, Constant *RHS) const {
76     return BinaryOperator::CreateURem(LHS, RHS);
77   }
78   Value *CreateSRem(Constant *LHS, Constant *RHS) const {
79     return BinaryOperator::CreateSRem(LHS, RHS);
80   }
81   Value *CreateFRem(Constant *LHS, Constant *RHS) const {
82     return BinaryOperator::CreateFRem(LHS, RHS);
83   }
84   Value *CreateShl(Constant *LHS, Constant *RHS) const {
85     return BinaryOperator::CreateShl(LHS, RHS);
86   }
87   Value *CreateLShr(Constant *LHS, Constant *RHS) const {
88     return BinaryOperator::CreateLShr(LHS, RHS);
89   }
90   Value *CreateAShr(Constant *LHS, Constant *RHS) const {
91     return BinaryOperator::CreateAShr(LHS, RHS);
92   }
93   Value *CreateAnd(Constant *LHS, Constant *RHS) const {
94     return BinaryOperator::CreateAnd(LHS, RHS);
95   }
96   Value *CreateOr(Constant *LHS, Constant *RHS) const {
97     return BinaryOperator::CreateOr(LHS, RHS);
98   }
99   Value *CreateXor(Constant *LHS, Constant *RHS) const {
100     return BinaryOperator::CreateXor(LHS, RHS);
101   }
102
103   Value *CreateBinOp(Instruction::BinaryOps Opc,
104                      Constant *LHS, Constant *RHS) const {
105     return BinaryOperator::Create(Opc, LHS, RHS);
106   }
107
108   //===--------------------------------------------------------------------===//
109   // Unary Operators
110   //===--------------------------------------------------------------------===//
111
112   Value *CreateNeg(Constant *C) const {
113     return BinaryOperator::CreateNeg(C);
114   }
115   Value *CreateNot(Constant *C) const {
116     return BinaryOperator::CreateNot(C);
117   }
118
119   //===--------------------------------------------------------------------===//
120   // Memory Instructions
121   //===--------------------------------------------------------------------===//
122
123   Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
124                                 unsigned NumIdx) const {
125     return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
126   }
127   Value *CreateGetElementPtr(Constant *C, Value* const *IdxList,
128                              unsigned NumIdx) const {
129     return GetElementPtrInst::Create(C, IdxList, IdxList+NumIdx);
130   }
131
132   Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
133                                         unsigned NumIdx) const {
134     return ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx);
135   }
136   Value *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
137                                      unsigned NumIdx) const {
138     return GetElementPtrInst::CreateInBounds(C, IdxList, IdxList+NumIdx);
139   }
140
141   //===--------------------------------------------------------------------===//
142   // Cast/Conversion Operators
143   //===--------------------------------------------------------------------===//
144
145   Value *CreateCast(Instruction::CastOps Op, Constant *C,
146                     const Type *DestTy) const {
147     return CastInst::Create(Op, C, DestTy);
148   }
149   Value *CreateIntCast(Constant *C, const Type *DestTy,
150                        bool isSigned) const {
151     return CastInst::CreateIntegerCast(C, DestTy, isSigned);
152   }
153
154   //===--------------------------------------------------------------------===//
155   // Compare Instructions
156   //===--------------------------------------------------------------------===//
157
158   Value *CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
159     return new ICmpInst(P, LHS, RHS);
160   }
161   Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
162     return new FCmpInst(P, LHS, RHS);
163   }
164
165   //===--------------------------------------------------------------------===//
166   // Other Instructions
167   //===--------------------------------------------------------------------===//
168
169   Value *CreateSelect(Constant *C, Constant *True, Constant *False) const {
170     return SelectInst::Create(C, True, False);
171   }
172
173   Value *CreateExtractElement(Constant *Vec, Constant *Idx) const {
174     return new ExtractElementInst(Vec, Idx);
175   }
176
177   Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
178                              Constant *Idx) const {
179     return InsertElementInst::Create(Vec, NewElt, Idx);
180   }
181
182   Value *CreateShuffleVector(Constant *V1, Constant *V2, Constant *Mask) const {
183     return new ShuffleVectorInst(V1, V2, Mask);
184   }
185
186   Value *CreateExtractValue(Constant *Agg, const unsigned *IdxList,
187                             unsigned NumIdx) const {
188     return ExtractValueInst::Create(Agg, IdxList, IdxList+NumIdx);
189   }
190
191   Value *CreateInsertValue(Constant *Agg, Constant *Val,
192                            const unsigned *IdxList, unsigned NumIdx) const {
193     return InsertValueInst::Create(Agg, Val, IdxList, IdxList+NumIdx);
194   }
195 };
196
197 }
198
199 #endif