InstructionSimplify.h revision 81a0dc911586c77421c2255aa417dc9b350b9e20
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 22namespace 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 /// SimplifyMulInst - Given operands for a Mul, see if we can 39 /// fold the result. If not, this returns null. 40 Value *SimplifyMulInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 41 const DominatorTree *DT = 0); 42 43 /// SimplifySDivInst - Given operands for an SDiv, see if we can 44 /// fold the result. If not, this returns null. 45 Value *SimplifySDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 46 const DominatorTree *DT = 0); 47 48 /// SimplifyUDivInst - Given operands for a UDiv, see if we can 49 /// fold the result. If not, this returns null. 50 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 51 const DominatorTree *DT = 0); 52 53 /// SimplifyFDivInst - Given operands for an FDiv, see if we can 54 /// fold the result. If not, this returns null. 55 Value *SimplifyFDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 56 const DominatorTree *DT = 0); 57 58 /// SimplifyShlInst - Given operands for a Shl, see if we can 59 /// fold the result. If not, this returns null. 60 Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, 61 const TargetData *TD = 0, const DominatorTree *DT = 0); 62 63 /// SimplifyLShrInst - Given operands for a LShr, see if we can 64 /// fold the result. If not, this returns null. 65 Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, 66 const TargetData *TD = 0, const DominatorTree *DT=0); 67 68 /// SimplifyAShrInst - Given operands for a AShr, see if we can 69 /// fold the result. If not, this returns null. 70 Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, 71 const TargetData *TD = 0, 72 const DominatorTree *DT = 0); 73 74 /// SimplifyAndInst - Given operands for an And, see if we can 75 /// fold the result. If not, this returns null. 76 Value *SimplifyAndInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 77 const DominatorTree *DT = 0); 78 79 /// SimplifyOrInst - Given operands for an Or, see if we can 80 /// fold the result. If not, this returns null. 81 Value *SimplifyOrInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 82 const DominatorTree *DT = 0); 83 84 /// SimplifyXorInst - Given operands for a Xor, see if we can 85 /// fold the result. If not, this returns null. 86 Value *SimplifyXorInst(Value *LHS, Value *RHS, const TargetData *TD = 0, 87 const DominatorTree *DT = 0); 88 89 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can 90 /// fold the result. If not, this returns null. 91 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, 92 const TargetData *TD = 0, 93 const DominatorTree *DT = 0); 94 95 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can 96 /// fold the result. If not, this returns null. 97 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, 98 const TargetData *TD = 0, 99 const DominatorTree *DT = 0); 100 101 /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold 102 /// the result. If not, this returns null. 103 Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, 104 const TargetData *TD = 0, 105 const DominatorTree *DT = 0); 106 107 /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can 108 /// fold the result. If not, this returns null. 109 Value *SimplifyGEPInst(Value * const *Ops, unsigned NumOps, 110 const TargetData *TD = 0, const DominatorTree *DT = 0); 111 112 //=== Helper functions for higher up the class hierarchy. 113 114 115 /// SimplifyCmpInst - Given operands for a CmpInst, see if we can 116 /// fold the result. If not, this returns null. 117 Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, 118 const TargetData *TD = 0, const DominatorTree *DT = 0); 119 120 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can 121 /// fold the result. If not, this returns null. 122 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, 123 const TargetData *TD = 0, const DominatorTree *DT = 0); 124 125 /// SimplifyInstruction - See if we can compute a simplified version of this 126 /// instruction. If not, this returns null. 127 Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0, 128 const DominatorTree *DT = 0); 129 130 131 /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then 132 /// delete the From instruction. In addition to a basic RAUW, this does a 133 /// recursive simplification of the updated instructions. This catches 134 /// things where one simplification exposes other opportunities. This only 135 /// simplifies and deletes scalar operations, it does not change the CFG. 136 /// 137 void ReplaceAndSimplifyAllUses(Instruction *From, Value *To, 138 const TargetData *TD = 0, 139 const DominatorTree *DT = 0); 140} // end namespace llvm 141 142#endif 143 144