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 that
11 // do not require creating new instructions. For example, this does constant
12 // folding, and can handle identities like (X&0)->0.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
17 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
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);
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,
33 const TargetData *TD = 0);
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,
38 const TargetData *TD = 0);
40 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
41 /// fold the result. If not, this returns null.
42 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
43 const TargetData *TD = 0);
45 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
46 /// fold the result. If not, this returns null.
47 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
48 const TargetData *TD = 0);
50 /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
51 /// the result. If not, this returns null.
52 Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
53 const TargetData *TD = 0);
55 /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
56 /// fold the result. If not, this returns null.
57 Value *SimplifyGEPInst(Value * const *Ops, unsigned NumOps,
58 const TargetData *TD = 0);
60 //=== Helper functions for higher up the class hierarchy.
63 /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
64 /// fold the result. If not, this returns null.
65 Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
66 const TargetData *TD = 0);
68 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
69 /// fold the result. If not, this returns null.
70 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
71 const TargetData *TD = 0);
73 /// SimplifyInstruction - See if we can compute a simplified version of this
74 /// instruction. If not, this returns null.
75 /// WARNING: If called on unreachable code, an instruction may be reported
76 /// to simplify to itself.
77 Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0,
78 const DominatorTree *DT = 0);
81 /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then
82 /// delete the From instruction. In addition to a basic RAUW, this does a
83 /// recursive simplification of the updated instructions. This catches
84 /// things where one simplification exposes other opportunities. This only
85 /// simplifies and deletes scalar operations, it does not change the CFG.
87 void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
88 const TargetData *TD = 0,
89 const DominatorTree *DT = 0);
90 } // end namespace llvm