Move some constant folding logic for loads out of instcombine into
[oota-llvm.git] / include / llvm / Analysis / ConstantFolding.h
1 //===-- ConstantFolding.h - Fold instructions into constants --------------===//
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 constants.
11 //
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
15 // dependency issues.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
20 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
21
22 namespace llvm {
23   class Constant;
24   class ConstantExpr;
25   class Instruction;
26   class TargetData;
27   class Function;
28   class Type;
29   class LLVMContext;
30
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.
35 ///
36 Constant *ConstantFoldInstruction(Instruction *I, LLVMContext &Context,
37                                   const TargetData *TD = 0);
38
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);
44
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 
49 /// form.
50 ///
51 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
52                                    Constant*const * Ops, unsigned NumOps,
53                                    LLVMContext &Context,
54                                    const TargetData *TD = 0);
55
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.
59 ///
60 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
61                                           Constant*const * Ops, unsigned NumOps,
62                                           LLVMContext &Context,
63                                           const TargetData *TD = 0);
64
65 /// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
66 /// produce if it is constant and determinable.  If this is not determinable,
67 /// return null.
68 Constant *ConstantFoldLoadFromConstPtr(Constant *C, const TargetData *TD = 0);
69
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);
74   
75 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
76 /// the specified function.
77 bool canConstantFoldCallTo(const Function *F);
78
79 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
80 /// with the specified arguments, returning null if unsuccessful.
81 Constant *
82 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
83 }
84
85 #endif