1 //===-- ConstantFolding.h - Analyze constant folding possibilities --------===//
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 family of functions determines the possibility of performing constant
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
16 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
26 /// ConstantFoldInstruction - Attempt to constant fold the specified
27 /// instruction. If successful, the constant result is returned, if not, null
28 /// is returned. Note that this function can only fail when attempting to fold
29 /// instructions like loads and stores, which have no constant expression form.
31 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
33 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
34 /// specified operands. If successful, the constant result is returned, if not,
35 /// null is returned. Note that this function can fail when attempting to
36 /// fold instructions like loads and stores, which have no constant expression
39 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
40 Constant*const * Ops, unsigned NumOps,
41 const TargetData *TD = 0);
43 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
44 /// instruction (icmp/fcmp) with the specified operands. If it fails, it
45 /// returns a constant expression of the specified operands.
47 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
48 Constant*const * Ops, unsigned NumOps,
49 const TargetData *TD = 0);
52 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
53 /// getelementptr constantexpr, return the constant value being addressed by the
54 /// constant expression, or null if something is funny and we can't decide.
55 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
57 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
58 /// the specified function.
59 bool canConstantFoldCallTo(Function *F);
61 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
62 /// with the specified arguments, returning null if unsuccessful.
64 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);