Clarify that InstructionSimplify only returns values that dominate the
[oota-llvm.git] / include / llvm / Analysis / InstructionSimplify.h
1 //===-- InstructionSimplify.h - Fold instructions into simpler forms ------===//
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 routines for folding instructions into simpler forms
11 // that do not require creating new instructions.  This does constant folding
12 // ("add i32 1, 1" -> "2") but can also handle non-constant operands, either
13 // returning a constant ("and i32 %x, 0" -> "0") or an already existing value
14 // ("and i32 %x, %x" -> "%x").  If the simplification is also an instruction
15 // then it dominates the original instruction.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
20 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
21
22 namespace llvm {
23   class DominatorTree;
24   class Instruction;
25   class Value;
26   class TargetData;
27
28   /// SimplifyAddInst - Given operands for an Add, see if we can
29   /// fold the result.  If not, this returns null.
30   Value *SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
31                          const TargetData *TD = 0, const DominatorTree *DT = 0);
32
33   /// SimplifySubInst - Given operands for a Sub, see if we can
34   /// fold the result.  If not, this returns null.
35   Value *SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
36                          const TargetData *TD = 0, const DominatorTree *DT = 0);
37
38   /// SimplifyAndInst - Given operands for an And, see if we can
39   /// fold the result.  If not, this returns null.
40   Value *SimplifyAndInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
41                          const DominatorTree *DT = 0);
42
43   /// SimplifyMulInst - Given operands for a Mul, see if we can
44   /// fold the result.  If not, this returns null.
45   Value *SimplifyMulInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
46                          const DominatorTree *DT = 0);
47
48   /// SimplifyOrInst - Given operands for an Or, see if we can
49   /// fold the result.  If not, this returns null.
50   Value *SimplifyOrInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
51                         const DominatorTree *DT = 0);
52
53   /// SimplifyXorInst - Given operands for a Xor, see if we can
54   /// fold the result.  If not, this returns null.
55   Value *SimplifyXorInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
56                          const DominatorTree *DT = 0);
57
58   /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
59   /// fold the result.  If not, this returns null.
60   Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
61                           const TargetData *TD = 0,
62                           const DominatorTree *DT = 0);
63
64   /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
65   /// fold the result.  If not, this returns null.
66   Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
67                           const TargetData *TD = 0,
68                           const DominatorTree *DT = 0);
69
70   /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
71   /// the result.  If not, this returns null.
72   Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
73                             const TargetData *TD = 0,
74                             const DominatorTree *DT = 0);
75
76   /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
77   /// fold the result.  If not, this returns null.
78   Value *SimplifyGEPInst(Value * const *Ops, unsigned NumOps,
79                          const TargetData *TD = 0, const DominatorTree *DT = 0);
80
81   //=== Helper functions for higher up the class hierarchy.
82
83
84   /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
85   /// fold the result.  If not, this returns null.
86   Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
87                          const TargetData *TD = 0, const DominatorTree *DT = 0);
88
89   /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
90   /// fold the result.  If not, this returns null.
91   Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
92                        const TargetData *TD = 0, const DominatorTree *DT = 0);
93
94   /// SimplifyInstruction - See if we can compute a simplified version of this
95   /// instruction.  If not, this returns null.
96   Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0,
97                              const DominatorTree *DT = 0);
98
99
100   /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then
101   /// delete the From instruction.  In addition to a basic RAUW, this does a
102   /// recursive simplification of the updated instructions.  This catches
103   /// things where one simplification exposes other opportunities.  This only
104   /// simplifies and deletes scalar operations, it does not change the CFG.
105   ///
106   void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
107                                  const TargetData *TD = 0,
108                                  const DominatorTree *DT = 0);
109 } // end namespace llvm
110
111 #endif
112