1 //===-- InstructionSimplify.h - Fold instructions into simpler forms ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
20 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
81 //=== Helper functions for higher up the class hierarchy.
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);
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);
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);
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.
106 void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
107 const TargetData *TD = 0,
108 const DominatorTree *DT = 0);
109 } // end namespace llvm