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