xref: /aosp_15_r20/external/llvm/include/llvm/Analysis/InstructionSimplify.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- InstructionSimplify.h - Fold instrs into simpler forms --*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file declares routines for folding instructions into simpler forms
11*9880d681SAndroid Build Coastguard Worker // that do not require creating new instructions.  This does constant folding
12*9880d681SAndroid Build Coastguard Worker // ("add i32 1, 1" -> "2") but can also handle non-constant operands, either
13*9880d681SAndroid Build Coastguard Worker // returning a constant ("and i32 %x, 0" -> "0") or an already existing value
14*9880d681SAndroid Build Coastguard Worker // ("and i32 %x, %x" -> "%x").  If the simplification is also an instruction
15*9880d681SAndroid Build Coastguard Worker // then it dominates the original instruction.
16*9880d681SAndroid Build Coastguard Worker //
17*9880d681SAndroid Build Coastguard Worker // These routines implicitly resolve undef uses. The easiest way to be safe when
18*9880d681SAndroid Build Coastguard Worker // using these routines to obtain simplified values for existing instructions is
19*9880d681SAndroid Build Coastguard Worker // to always replace all uses of the instructions with the resulting simplified
20*9880d681SAndroid Build Coastguard Worker // values. This will prevent other code from seeing the same undef uses and
21*9880d681SAndroid Build Coastguard Worker // resolving them to different values.
22*9880d681SAndroid Build Coastguard Worker //
23*9880d681SAndroid Build Coastguard Worker // These routines are designed to tolerate moderately incomplete IR, such as
24*9880d681SAndroid Build Coastguard Worker // instructions that are not connected to basic blocks yet. However, they do
25*9880d681SAndroid Build Coastguard Worker // require that all the IR that they encounter be valid. In particular, they
26*9880d681SAndroid Build Coastguard Worker // require that all non-constant values be defined in the same function, and the
27*9880d681SAndroid Build Coastguard Worker // same call context of that function (and not split between caller and callee
28*9880d681SAndroid Build Coastguard Worker // contexts of a directly recursive call, for example).
29*9880d681SAndroid Build Coastguard Worker //
30*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
33*9880d681SAndroid Build Coastguard Worker #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
34*9880d681SAndroid Build Coastguard Worker 
35*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/User.h"
36*9880d681SAndroid Build Coastguard Worker 
37*9880d681SAndroid Build Coastguard Worker namespace llvm {
38*9880d681SAndroid Build Coastguard Worker   template<typename T>
39*9880d681SAndroid Build Coastguard Worker   class ArrayRef;
40*9880d681SAndroid Build Coastguard Worker   class AssumptionCache;
41*9880d681SAndroid Build Coastguard Worker   class DominatorTree;
42*9880d681SAndroid Build Coastguard Worker   class Instruction;
43*9880d681SAndroid Build Coastguard Worker   class DataLayout;
44*9880d681SAndroid Build Coastguard Worker   class FastMathFlags;
45*9880d681SAndroid Build Coastguard Worker   class TargetLibraryInfo;
46*9880d681SAndroid Build Coastguard Worker   class Type;
47*9880d681SAndroid Build Coastguard Worker   class Value;
48*9880d681SAndroid Build Coastguard Worker 
49*9880d681SAndroid Build Coastguard Worker   /// SimplifyAddInst - Given operands for an Add, see if we can
50*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
51*9880d681SAndroid Build Coastguard Worker   Value *SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
52*9880d681SAndroid Build Coastguard Worker                          const DataLayout &DL,
53*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
54*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
55*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
56*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
57*9880d681SAndroid Build Coastguard Worker 
58*9880d681SAndroid Build Coastguard Worker   /// SimplifySubInst - Given operands for a Sub, see if we can
59*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
60*9880d681SAndroid Build Coastguard Worker   Value *SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
61*9880d681SAndroid Build Coastguard Worker                          const DataLayout &DL,
62*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
63*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
64*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
65*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker   /// Given operands for an FAdd, see if we can fold the result.  If not, this
68*9880d681SAndroid Build Coastguard Worker   /// returns null.
69*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF,
70*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
71*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
72*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
73*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
74*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
75*9880d681SAndroid Build Coastguard Worker 
76*9880d681SAndroid Build Coastguard Worker   /// Given operands for an FSub, see if we can fold the result.  If not, this
77*9880d681SAndroid Build Coastguard Worker   /// returns null.
78*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF,
79*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
80*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
81*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
82*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
83*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
84*9880d681SAndroid Build Coastguard Worker 
85*9880d681SAndroid Build Coastguard Worker   /// Given operands for an FMul, see if we can fold the result.  If not, this
86*9880d681SAndroid Build Coastguard Worker   /// returns null.
87*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF,
88*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
89*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
90*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
91*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
92*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker   /// SimplifyMulInst - Given operands for a Mul, see if we can
95*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
96*9880d681SAndroid Build Coastguard Worker   Value *SimplifyMulInst(Value *LHS, Value *RHS, const DataLayout &DL,
97*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
98*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
99*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
100*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
101*9880d681SAndroid Build Coastguard Worker 
102*9880d681SAndroid Build Coastguard Worker   /// SimplifySDivInst - Given operands for an SDiv, see if we can
103*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
104*9880d681SAndroid Build Coastguard Worker   Value *SimplifySDivInst(Value *LHS, Value *RHS, const DataLayout &DL,
105*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
106*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
107*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
108*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
109*9880d681SAndroid Build Coastguard Worker 
110*9880d681SAndroid Build Coastguard Worker   /// SimplifyUDivInst - Given operands for a UDiv, see if we can
111*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
112*9880d681SAndroid Build Coastguard Worker   Value *SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout &DL,
113*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
114*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
115*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
116*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
117*9880d681SAndroid Build Coastguard Worker 
118*9880d681SAndroid Build Coastguard Worker   /// SimplifyFDivInst - Given operands for an FDiv, see if we can
119*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
120*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF,
121*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
122*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
123*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
124*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
125*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
126*9880d681SAndroid Build Coastguard Worker 
127*9880d681SAndroid Build Coastguard Worker   /// SimplifySRemInst - Given operands for an SRem, see if we can
128*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
129*9880d681SAndroid Build Coastguard Worker   Value *SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout &DL,
130*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
131*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
132*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
133*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
134*9880d681SAndroid Build Coastguard Worker 
135*9880d681SAndroid Build Coastguard Worker   /// SimplifyURemInst - Given operands for a URem, see if we can
136*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
137*9880d681SAndroid Build Coastguard Worker   Value *SimplifyURemInst(Value *LHS, Value *RHS, const DataLayout &DL,
138*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
139*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
140*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
141*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
142*9880d681SAndroid Build Coastguard Worker 
143*9880d681SAndroid Build Coastguard Worker   /// SimplifyFRemInst - Given operands for an FRem, see if we can
144*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
145*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF,
146*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
147*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
148*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
149*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
150*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
151*9880d681SAndroid Build Coastguard Worker 
152*9880d681SAndroid Build Coastguard Worker   /// SimplifyShlInst - Given operands for a Shl, see if we can
153*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
154*9880d681SAndroid Build Coastguard Worker   Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
155*9880d681SAndroid Build Coastguard Worker                          const DataLayout &DL,
156*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
157*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
158*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
159*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
160*9880d681SAndroid Build Coastguard Worker 
161*9880d681SAndroid Build Coastguard Worker   /// SimplifyLShrInst - Given operands for a LShr, see if we can
162*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
163*9880d681SAndroid Build Coastguard Worker   Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact,
164*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
165*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
166*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
167*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
168*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
169*9880d681SAndroid Build Coastguard Worker 
170*9880d681SAndroid Build Coastguard Worker   /// SimplifyAShrInst - Given operands for a AShr, see if we can
171*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
172*9880d681SAndroid Build Coastguard Worker   Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
173*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
174*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
175*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
176*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
177*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
178*9880d681SAndroid Build Coastguard Worker 
179*9880d681SAndroid Build Coastguard Worker   /// SimplifyAndInst - Given operands for an And, see if we can
180*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
181*9880d681SAndroid Build Coastguard Worker   Value *SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout &DL,
182*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
183*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
184*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
185*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
186*9880d681SAndroid Build Coastguard Worker 
187*9880d681SAndroid Build Coastguard Worker   /// SimplifyOrInst - Given operands for an Or, see if we can
188*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
189*9880d681SAndroid Build Coastguard Worker   Value *SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout &DL,
190*9880d681SAndroid Build Coastguard Worker                         const TargetLibraryInfo *TLI = nullptr,
191*9880d681SAndroid Build Coastguard Worker                         const DominatorTree *DT = nullptr,
192*9880d681SAndroid Build Coastguard Worker                         AssumptionCache *AC = nullptr,
193*9880d681SAndroid Build Coastguard Worker                         const Instruction *CxtI = nullptr);
194*9880d681SAndroid Build Coastguard Worker 
195*9880d681SAndroid Build Coastguard Worker   /// SimplifyXorInst - Given operands for a Xor, see if we can
196*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
197*9880d681SAndroid Build Coastguard Worker   Value *SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout &DL,
198*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
199*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
200*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
201*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
202*9880d681SAndroid Build Coastguard Worker 
203*9880d681SAndroid Build Coastguard Worker   /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
204*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
205*9880d681SAndroid Build Coastguard Worker   Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
206*9880d681SAndroid Build Coastguard Worker                           const DataLayout &DL,
207*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
208*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
209*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
210*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
211*9880d681SAndroid Build Coastguard Worker 
212*9880d681SAndroid Build Coastguard Worker   /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
213*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
214*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
215*9880d681SAndroid Build Coastguard Worker                           FastMathFlags FMF, const DataLayout &DL,
216*9880d681SAndroid Build Coastguard Worker                           const TargetLibraryInfo *TLI = nullptr,
217*9880d681SAndroid Build Coastguard Worker                           const DominatorTree *DT = nullptr,
218*9880d681SAndroid Build Coastguard Worker                           AssumptionCache *AC = nullptr,
219*9880d681SAndroid Build Coastguard Worker                           const Instruction *CxtI = nullptr);
220*9880d681SAndroid Build Coastguard Worker 
221*9880d681SAndroid Build Coastguard Worker   /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
222*9880d681SAndroid Build Coastguard Worker   /// the result.  If not, this returns null.
223*9880d681SAndroid Build Coastguard Worker   Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
224*9880d681SAndroid Build Coastguard Worker                             const DataLayout &DL,
225*9880d681SAndroid Build Coastguard Worker                             const TargetLibraryInfo *TLI = nullptr,
226*9880d681SAndroid Build Coastguard Worker                             const DominatorTree *DT = nullptr,
227*9880d681SAndroid Build Coastguard Worker                             AssumptionCache *AC = nullptr,
228*9880d681SAndroid Build Coastguard Worker                             const Instruction *CxtI = nullptr);
229*9880d681SAndroid Build Coastguard Worker 
230*9880d681SAndroid Build Coastguard Worker   /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
231*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
232*9880d681SAndroid Build Coastguard Worker   Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
233*9880d681SAndroid Build Coastguard Worker                          const DataLayout &DL,
234*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
235*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
236*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
237*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
238*9880d681SAndroid Build Coastguard Worker 
239*9880d681SAndroid Build Coastguard Worker   /// SimplifyInsertValueInst - Given operands for an InsertValueInst, see if we
240*9880d681SAndroid Build Coastguard Worker   /// can fold the result.  If not, this returns null.
241*9880d681SAndroid Build Coastguard Worker   Value *SimplifyInsertValueInst(Value *Agg, Value *Val,
242*9880d681SAndroid Build Coastguard Worker                                  ArrayRef<unsigned> Idxs, const DataLayout &DL,
243*9880d681SAndroid Build Coastguard Worker                                  const TargetLibraryInfo *TLI = nullptr,
244*9880d681SAndroid Build Coastguard Worker                                  const DominatorTree *DT = nullptr,
245*9880d681SAndroid Build Coastguard Worker                                  AssumptionCache *AC = nullptr,
246*9880d681SAndroid Build Coastguard Worker                                  const Instruction *CxtI = nullptr);
247*9880d681SAndroid Build Coastguard Worker 
248*9880d681SAndroid Build Coastguard Worker   /// \brief Given operands for an ExtractValueInst, see if we can fold the
249*9880d681SAndroid Build Coastguard Worker   /// result.  If not, this returns null.
250*9880d681SAndroid Build Coastguard Worker   Value *SimplifyExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
251*9880d681SAndroid Build Coastguard Worker                                   const DataLayout &DL,
252*9880d681SAndroid Build Coastguard Worker                                   const TargetLibraryInfo *TLI = nullptr,
253*9880d681SAndroid Build Coastguard Worker                                   const DominatorTree *DT = nullptr,
254*9880d681SAndroid Build Coastguard Worker                                   AssumptionCache *AC = nullptr,
255*9880d681SAndroid Build Coastguard Worker                                   const Instruction *CxtI = nullptr);
256*9880d681SAndroid Build Coastguard Worker 
257*9880d681SAndroid Build Coastguard Worker   /// \brief Given operands for an ExtractElementInst, see if we can fold the
258*9880d681SAndroid Build Coastguard Worker   /// result.  If not, this returns null.
259*9880d681SAndroid Build Coastguard Worker   Value *SimplifyExtractElementInst(Value *Vec, Value *Idx,
260*9880d681SAndroid Build Coastguard Worker                                     const DataLayout &DL,
261*9880d681SAndroid Build Coastguard Worker                                     const TargetLibraryInfo *TLI = nullptr,
262*9880d681SAndroid Build Coastguard Worker                                     const DominatorTree *DT = nullptr,
263*9880d681SAndroid Build Coastguard Worker                                     AssumptionCache *AC = nullptr,
264*9880d681SAndroid Build Coastguard Worker                                     const Instruction *CxtI = nullptr);
265*9880d681SAndroid Build Coastguard Worker 
266*9880d681SAndroid Build Coastguard Worker   /// SimplifyTruncInst - Given operands for an TruncInst, see if we can fold
267*9880d681SAndroid Build Coastguard Worker   /// the result.  If not, this returns null.
268*9880d681SAndroid Build Coastguard Worker   Value *SimplifyTruncInst(Value *Op, Type *Ty, const DataLayout &DL,
269*9880d681SAndroid Build Coastguard Worker                            const TargetLibraryInfo *TLI = nullptr,
270*9880d681SAndroid Build Coastguard Worker                            const DominatorTree *DT = nullptr,
271*9880d681SAndroid Build Coastguard Worker                            AssumptionCache *AC = nullptr,
272*9880d681SAndroid Build Coastguard Worker                            const Instruction *CxtI = nullptr);
273*9880d681SAndroid Build Coastguard Worker 
274*9880d681SAndroid Build Coastguard Worker   //=== Helper functions for higher up the class hierarchy.
275*9880d681SAndroid Build Coastguard Worker 
276*9880d681SAndroid Build Coastguard Worker 
277*9880d681SAndroid Build Coastguard Worker   /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
278*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
279*9880d681SAndroid Build Coastguard Worker   Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
280*9880d681SAndroid Build Coastguard Worker                          const DataLayout &DL,
281*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
282*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
283*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
284*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
285*9880d681SAndroid Build Coastguard Worker 
286*9880d681SAndroid Build Coastguard Worker   /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
287*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
288*9880d681SAndroid Build Coastguard Worker   Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
289*9880d681SAndroid Build Coastguard Worker                        const DataLayout &DL,
290*9880d681SAndroid Build Coastguard Worker                        const TargetLibraryInfo *TLI = nullptr,
291*9880d681SAndroid Build Coastguard Worker                        const DominatorTree *DT = nullptr,
292*9880d681SAndroid Build Coastguard Worker                        AssumptionCache *AC = nullptr,
293*9880d681SAndroid Build Coastguard Worker                        const Instruction *CxtI = nullptr);
294*9880d681SAndroid Build Coastguard Worker   /// SimplifyFPBinOp - Given operands for a BinaryOperator, see if we can
295*9880d681SAndroid Build Coastguard Worker   /// fold the result.  If not, this returns null.
296*9880d681SAndroid Build Coastguard Worker   /// In contrast to SimplifyBinOp, try to use FastMathFlag when folding the
297*9880d681SAndroid Build Coastguard Worker   /// result. In case we don't need FastMathFlags, simply fall to SimplifyBinOp.
298*9880d681SAndroid Build Coastguard Worker   Value *SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS,
299*9880d681SAndroid Build Coastguard Worker                          const FastMathFlags &FMF, const DataLayout &DL,
300*9880d681SAndroid Build Coastguard Worker                          const TargetLibraryInfo *TLI = nullptr,
301*9880d681SAndroid Build Coastguard Worker                          const DominatorTree *DT = nullptr,
302*9880d681SAndroid Build Coastguard Worker                          AssumptionCache *AC = nullptr,
303*9880d681SAndroid Build Coastguard Worker                          const Instruction *CxtI = nullptr);
304*9880d681SAndroid Build Coastguard Worker 
305*9880d681SAndroid Build Coastguard Worker   /// \brief Given a function and iterators over arguments, see if we can fold
306*9880d681SAndroid Build Coastguard Worker   /// the result.
307*9880d681SAndroid Build Coastguard Worker   ///
308*9880d681SAndroid Build Coastguard Worker   /// If this call could not be simplified returns null.
309*9880d681SAndroid Build Coastguard Worker   Value *SimplifyCall(Value *V, User::op_iterator ArgBegin,
310*9880d681SAndroid Build Coastguard Worker                       User::op_iterator ArgEnd, const DataLayout &DL,
311*9880d681SAndroid Build Coastguard Worker                       const TargetLibraryInfo *TLI = nullptr,
312*9880d681SAndroid Build Coastguard Worker                       const DominatorTree *DT = nullptr,
313*9880d681SAndroid Build Coastguard Worker                       AssumptionCache *AC = nullptr,
314*9880d681SAndroid Build Coastguard Worker                       const Instruction *CxtI = nullptr);
315*9880d681SAndroid Build Coastguard Worker 
316*9880d681SAndroid Build Coastguard Worker   /// \brief Given a function and set of arguments, see if we can fold the
317*9880d681SAndroid Build Coastguard Worker   /// result.
318*9880d681SAndroid Build Coastguard Worker   ///
319*9880d681SAndroid Build Coastguard Worker   /// If this call could not be simplified returns null.
320*9880d681SAndroid Build Coastguard Worker   Value *SimplifyCall(Value *V, ArrayRef<Value *> Args, const DataLayout &DL,
321*9880d681SAndroid Build Coastguard Worker                       const TargetLibraryInfo *TLI = nullptr,
322*9880d681SAndroid Build Coastguard Worker                       const DominatorTree *DT = nullptr,
323*9880d681SAndroid Build Coastguard Worker                       AssumptionCache *AC = nullptr,
324*9880d681SAndroid Build Coastguard Worker                       const Instruction *CxtI = nullptr);
325*9880d681SAndroid Build Coastguard Worker 
326*9880d681SAndroid Build Coastguard Worker   /// SimplifyInstruction - See if we can compute a simplified version of this
327*9880d681SAndroid Build Coastguard Worker   /// instruction.  If not, this returns null.
328*9880d681SAndroid Build Coastguard Worker   Value *SimplifyInstruction(Instruction *I, const DataLayout &DL,
329*9880d681SAndroid Build Coastguard Worker                              const TargetLibraryInfo *TLI = nullptr,
330*9880d681SAndroid Build Coastguard Worker                              const DominatorTree *DT = nullptr,
331*9880d681SAndroid Build Coastguard Worker                              AssumptionCache *AC = nullptr);
332*9880d681SAndroid Build Coastguard Worker 
333*9880d681SAndroid Build Coastguard Worker   /// \brief Replace all uses of 'I' with 'SimpleV' and simplify the uses
334*9880d681SAndroid Build Coastguard Worker   /// recursively.
335*9880d681SAndroid Build Coastguard Worker   ///
336*9880d681SAndroid Build Coastguard Worker   /// This first performs a normal RAUW of I with SimpleV. It then recursively
337*9880d681SAndroid Build Coastguard Worker   /// attempts to simplify those users updated by the operation. The 'I'
338*9880d681SAndroid Build Coastguard Worker   /// instruction must not be equal to the simplified value 'SimpleV'.
339*9880d681SAndroid Build Coastguard Worker   ///
340*9880d681SAndroid Build Coastguard Worker   /// The function returns true if any simplifications were performed.
341*9880d681SAndroid Build Coastguard Worker   bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
342*9880d681SAndroid Build Coastguard Worker                                      const TargetLibraryInfo *TLI = nullptr,
343*9880d681SAndroid Build Coastguard Worker                                      const DominatorTree *DT = nullptr,
344*9880d681SAndroid Build Coastguard Worker                                      AssumptionCache *AC = nullptr);
345*9880d681SAndroid Build Coastguard Worker 
346*9880d681SAndroid Build Coastguard Worker   /// \brief Recursively attempt to simplify an instruction.
347*9880d681SAndroid Build Coastguard Worker   ///
348*9880d681SAndroid Build Coastguard Worker   /// This routine uses SimplifyInstruction to simplify 'I', and if successful
349*9880d681SAndroid Build Coastguard Worker   /// replaces uses of 'I' with the simplified value. It then recurses on each
350*9880d681SAndroid Build Coastguard Worker   /// of the users impacted. It returns true if any simplifications were
351*9880d681SAndroid Build Coastguard Worker   /// performed.
352*9880d681SAndroid Build Coastguard Worker   bool recursivelySimplifyInstruction(Instruction *I,
353*9880d681SAndroid Build Coastguard Worker                                       const TargetLibraryInfo *TLI = nullptr,
354*9880d681SAndroid Build Coastguard Worker                                       const DominatorTree *DT = nullptr,
355*9880d681SAndroid Build Coastguard Worker                                       AssumptionCache *AC = nullptr);
356*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
357*9880d681SAndroid Build Coastguard Worker 
358*9880d681SAndroid Build Coastguard Worker #endif
359*9880d681SAndroid Build Coastguard Worker 
360