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
24 /// SimplifyAddInst - Given operands for an Add, see if we can
25 /// fold the result. If not, this returns null.
26 Value *SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
27 const TargetData *TD = 0);
29 /// SimplifyAndInst - Given operands for an And, see if we can
30 /// fold the result. If not, this returns null.
31 Value *SimplifyAndInst(Value *LHS, Value *RHS,
32 const TargetData *TD = 0);
34 /// SimplifyOrInst - Given operands for an Or, see if we can
35 /// fold the result. If not, this returns null.
36 Value *SimplifyOrInst(Value *LHS, Value *RHS,
37 const TargetData *TD = 0);
39 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
40 /// fold the result. If not, this returns null.
41 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
42 const TargetData *TD = 0);
44 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
45 /// fold the result. If not, this returns null.
46 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
47 const TargetData *TD = 0);
49 /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
50 /// the result. If not, this returns null.
51 Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
52 const TargetData *TD = 0);
54 /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
55 /// fold the result. If not, this returns null.
56 Value *SimplifyGEPInst(Value * const *Ops, unsigned NumOps,
57 const TargetData *TD = 0);
59 //=== Helper functions for higher up the class hierarchy.
62 /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
63 /// fold the result. If not, this returns null.
64 Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
65 const TargetData *TD = 0);
67 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
68 /// fold the result. If not, this returns null.
69 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
70 const TargetData *TD = 0);
72 /// SimplifyInstruction - See if we can compute a simplified version of this
73 /// instruction. If not, this returns null.
74 Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0);
77 /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then
78 /// delete the From instruction. In addition to a basic RAUW, this does a
79 /// recursive simplification of the updated instructions. This catches
80 /// things where one simplification exposes other opportunities. This only
81 /// simplifies and deletes scalar operations, it does not change the CFG.
83 void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
84 const TargetData *TD = 0);
85 } // end namespace llvm