1 //===-- ConstantFolding.h - Fold instructions into constants --------------===//
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 constants.
12 // Also, to supplement the basic VMCore ConstantExpr simplifications,
13 // this file declares some additional folding routines that can make use of
14 // TargetData information. These functions cannot go in VMCore due to library
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
20 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
31 /// ConstantFoldInstruction - Attempt to constant fold the specified
32 /// instruction. If successful, the constant result is returned, if not, null
33 /// is returned. Note that this function can only fail when attempting to fold
34 /// instructions like loads and stores, which have no constant expression form.
36 Constant *ConstantFoldInstruction(Instruction *I, LLVMContext &Context,
37 const TargetData *TD = 0);
39 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
40 /// using the specified TargetData. If successful, the constant result is
41 /// result is returned, if not, null is returned.
42 Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext &Context,
43 const TargetData *TD = 0);
45 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
46 /// specified operands. If successful, the constant result is returned, if not,
47 /// null is returned. Note that this function can fail when attempting to
48 /// fold instructions like loads and stores, which have no constant expression
51 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
52 Constant*const * Ops, unsigned NumOps,
54 const TargetData *TD = 0);
56 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
57 /// instruction (icmp/fcmp) with the specified operands. If it fails, it
58 /// returns a constant expression of the specified operands.
60 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
61 Constant*const * Ops, unsigned NumOps,
63 const TargetData *TD = 0);
65 /// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
66 /// produce if it is constant and determinable. If this is not determinable,
68 Constant *ConstantFoldLoadFromConstPtr(Constant *C, const TargetData *TD = 0);
70 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
71 /// getelementptr constantexpr, return the constant value being addressed by the
72 /// constant expression, or null if something is funny and we can't decide.
73 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
75 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
76 /// the specified function.
77 bool canConstantFoldCallTo(const Function *F);
79 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
80 /// with the specified arguments, returning null if unsuccessful.
82 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);