Get rid of the Pass+Context magic.
[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   class LLVMContext;
26
27 /// ConstantFoldInstruction - Attempt to constant fold the specified
28 /// instruction.  If successful, the constant result is returned, if not, null
29 /// is returned.  Note that this function can only fail when attempting to fold
30 /// instructions like loads and stores, which have no constant expression form.
31 ///
32 Constant *ConstantFoldInstruction(Instruction *I, LLVMContext &Context,
33                                   const TargetData *TD = 0);
34
35 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
36 /// using the specified TargetData.  If successful, the constant result is
37 /// result is returned, if not, null is returned.
38 Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext &Context,
39                                          const TargetData *TD = 0);
40
41 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
42 /// specified operands.  If successful, the constant result is returned, if not,
43 /// null is returned.  Note that this function can fail when attempting to 
44 /// fold instructions like loads and stores, which have no constant expression 
45 /// form.
46 ///
47 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
48                                    Constant*const * Ops, unsigned NumOps,
49                                    LLVMContext &Context,
50                                    const TargetData *TD = 0);
51
52 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
53 /// instruction (icmp/fcmp) with the specified operands.  If it fails, it
54 /// returns a constant expression of the specified operands.
55 ///
56 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
57                                           Constant*const * Ops, unsigned NumOps,
58                                           LLVMContext &Context,
59                                           const TargetData *TD = 0);
60
61
62 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
63 /// getelementptr constantexpr, return the constant value being addressed by the
64 /// constant expression, or null if something is funny and we can't decide.
65 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE,
66                                                  LLVMContext &Context);
67   
68 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
69 /// the specified function.
70 bool canConstantFoldCallTo(const Function *F);
71
72 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
73 /// with the specified arguments, returning null if unsuccessful.
74 Constant *
75 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
76 }
77
78 #endif