"ret (constexpr)" can't be folded into a Constant. Add a method to
[oota-llvm.git] / include / llvm / Analysis / ConstantFolding.h
1 //===-- ConstantFolding.h - Analyze constant folding possibilities --------===//
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 family of functions determines the possibility of performing constant
11 // folding.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
16 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
17
18 namespace llvm {
19   class Constant;
20   class ConstantExpr;
21   class Instruction;
22   class TargetData;
23   class Function;
24   class Type;
25
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.
30 ///
31 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
32
33 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
34 /// using the specified TargetData.  If successful, the constant result is
35 /// result is returned, if not, null is returned.
36 Constant *ConstantFoldConstantExpression(ConstantExpr *CE,
37                                          const TargetData *TD);
38
39 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
40 /// specified operands.  If successful, the constant result is returned, if not,
41 /// null is returned.  Note that this function can fail when attempting to 
42 /// fold instructions like loads and stores, which have no constant expression 
43 /// form.
44 ///
45 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
46                                    Constant*const * Ops, unsigned NumOps,
47                                    const TargetData *TD = 0);
48
49 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
50 /// instruction (icmp/fcmp) with the specified operands.  If it fails, it
51 /// returns a constant expression of the specified operands.
52 ///
53 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
54                                           Constant*const * Ops, unsigned NumOps,
55                                           const TargetData *TD = 0);
56
57
58 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
59 /// getelementptr constantexpr, return the constant value being addressed by the
60 /// constant expression, or null if something is funny and we can't decide.
61 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
62   
63 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
64 /// the specified function.
65 bool canConstantFoldCallTo(const Function *F);
66
67 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
68 /// with the specified arguments, returning null if unsuccessful.
69 Constant *
70 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
71 }
72
73 #endif