Fix the name of the include guard to match the filename.
[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 /// NoFolder - Create "constants" (actually, values) with no folding.
32 class NoFolder {
33 public:
34
35   //===--------------------------------------------------------------------===//
36   // Binary Operators
37   //===--------------------------------------------------------------------===//
38
39   Value *CreateAdd(Constant *LHS, Constant *RHS) const {
40     return BinaryOperator::CreateAdd(LHS, RHS);
41   }
42   Value *CreateSub(Constant *LHS, Constant *RHS) const {
43     return BinaryOperator::CreateSub(LHS, RHS);
44   }
45   Value *CreateMul(Constant *LHS, Constant *RHS) const {
46     return BinaryOperator::CreateMul(LHS, RHS);
47   }
48   Value *CreateUDiv(Constant *LHS, Constant *RHS) const {
49     return BinaryOperator::CreateUDiv(LHS, RHS);
50   }
51   Value *CreateSDiv(Constant *LHS, Constant *RHS) const {
52     return BinaryOperator::CreateSDiv(LHS, RHS);
53   }
54   Value *CreateFDiv(Constant *LHS, Constant *RHS) const {
55     return BinaryOperator::CreateFDiv(LHS, RHS);
56   }
57   Value *CreateURem(Constant *LHS, Constant *RHS) const {
58     return BinaryOperator::CreateURem(LHS, RHS);
59   }
60   Value *CreateSRem(Constant *LHS, Constant *RHS) const {
61     return BinaryOperator::CreateSRem(LHS, RHS);
62   }
63   Value *CreateFRem(Constant *LHS, Constant *RHS) const {
64     return BinaryOperator::CreateFRem(LHS, RHS);
65   }
66   Value *CreateShl(Constant *LHS, Constant *RHS) const {
67     return BinaryOperator::CreateShl(LHS, RHS);
68   }
69   Value *CreateLShr(Constant *LHS, Constant *RHS) const {
70     return BinaryOperator::CreateLShr(LHS, RHS);
71   }
72   Value *CreateAShr(Constant *LHS, Constant *RHS) const {
73     return BinaryOperator::CreateAShr(LHS, RHS);
74   }
75   Value *CreateAnd(Constant *LHS, Constant *RHS) const {
76     return BinaryOperator::CreateAnd(LHS, RHS);
77   }
78   Value *CreateOr(Constant *LHS, Constant *RHS) const {
79     return BinaryOperator::CreateOr(LHS, RHS);
80   }
81   Value *CreateXor(Constant *LHS, Constant *RHS) const {
82     return BinaryOperator::CreateXor(LHS, RHS);
83   }
84
85   Value *CreateBinOp(Instruction::BinaryOps Opc,
86                      Constant *LHS, Constant *RHS) const {
87     return BinaryOperator::Create(Opc, LHS, RHS);
88   }
89
90   //===--------------------------------------------------------------------===//
91   // Unary Operators
92   //===--------------------------------------------------------------------===//
93
94   Value *CreateNeg(Constant *C) const {
95     return BinaryOperator::CreateNeg(C);
96   }
97   Value *CreateNot(Constant *C) const {
98     return BinaryOperator::CreateNot(C);
99   }
100
101   //===--------------------------------------------------------------------===//
102   // Memory Instructions
103   //===--------------------------------------------------------------------===//
104
105   Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
106                                 unsigned NumIdx) const {
107     return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
108   }
109   Value *CreateGetElementPtr(Constant *C, Value* const *IdxList,
110                              unsigned NumIdx) const {
111     return GetElementPtrInst::Create(C, IdxList, IdxList+NumIdx);
112   }
113
114   //===--------------------------------------------------------------------===//
115   // Cast/Conversion Operators
116   //===--------------------------------------------------------------------===//
117
118   Value *CreateCast(Instruction::CastOps Op, Constant *C,
119                     const Type *DestTy) const {
120     return CastInst::Create(Op, C, DestTy);
121   }
122   Value *CreateIntCast(Constant *C, const Type *DestTy,
123                        bool isSigned) const {
124     return CastInst::CreateIntegerCast(C, DestTy, isSigned);
125   }
126
127   //===--------------------------------------------------------------------===//
128   // Compare Instructions
129   //===--------------------------------------------------------------------===//
130
131   Value *CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
132     return new ICmpInst(P, LHS, RHS);
133   }
134   Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
135     return new FCmpInst(P, LHS, RHS);
136   }
137   Value *CreateVICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
138     return new VICmpInst(P, LHS, RHS);
139   }
140   Value *CreateVFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
141     return new VFCmpInst(P, LHS, RHS);
142   }
143
144   //===--------------------------------------------------------------------===//
145   // Other Instructions
146   //===--------------------------------------------------------------------===//
147
148   Value *CreateSelect(Constant *C, Constant *True, Constant *False) const {
149     return SelectInst::Create(C, True, False);
150   }
151
152   Value *CreateExtractElement(Constant *Vec, Constant *Idx) const {
153     return new ExtractElementInst(Vec, Idx);
154   }
155
156   Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
157                              Constant *Idx) const {
158     return InsertElementInst::Create(Vec, NewElt, Idx);
159   }
160
161   Value *CreateShuffleVector(Constant *V1, Constant *V2, Constant *Mask) const {
162     return new ShuffleVectorInst(V1, V2, Mask);
163   }
164
165   Value *CreateExtractValue(Constant *Agg, const unsigned *IdxList,
166                             unsigned NumIdx) const {
167     return ExtractValueInst::Create(Agg, IdxList, IdxList+NumIdx);
168   }
169
170   Value *CreateInsertValue(Constant *Agg, Constant *Val,
171                            const unsigned *IdxList, unsigned NumIdx) const {
172     return InsertValueInst::Create(Agg, Val, IdxList, IdxList+NumIdx);
173   }
174 };
175
176 }
177
178 #endif