Use ArrayRef in ConstantFoldInstOperands and ConstantFoldCall.
[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 when all
11 // operands are constants, for example "sub i32 1, 0" -> "1".
12 //
13 // Also, to supplement the basic VMCore ConstantExpr simplifications,
14 // this file declares some additional folding routines that can make use of
15 // TargetData information. These functions cannot go in VMCore due to library
16 // dependency issues.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
21 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
22
23 namespace llvm {
24   class Constant;
25   class ConstantExpr;
26   class Instruction;
27   class TargetData;
28   class Function;
29   class Type;
30   template<typename T>
31   class ArrayRef;
32
33 /// ConstantFoldInstruction - Try to constant fold the specified instruction.
34 /// If successful, the constant result is returned, if not, null is returned.
35 /// Note that this fails if not all of the operands are constant.  Otherwise,
36 /// this function can only fail when attempting to fold instructions like loads
37 /// and stores, which have no constant expression form.
38 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
39
40 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
41 /// using the specified TargetData.  If successful, the constant result is
42 /// result is returned, if not, null is returned.
43 Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
44                                          const TargetData *TD = 0);
45
46 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
47 /// specified operands.  If successful, the constant result is returned, if not,
48 /// null is returned.  Note that this function can fail when attempting to 
49 /// fold instructions like loads and stores, which have no constant expression 
50 /// form.
51 ///
52 Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
53                                    ArrayRef<Constant *> Ops,
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 *LHS, Constant *RHS,
62                                           const TargetData *TD = 0);
63
64 /// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
65 /// produce if it is constant and determinable.  If this is not determinable,
66 /// return null.
67 Constant *ConstantFoldLoadFromConstPtr(Constant *C, const TargetData *TD = 0);
68
69 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
70 /// getelementptr constantexpr, return the constant value being addressed by the
71 /// constant expression, or null if something is funny and we can't decide.
72 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
73   
74 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
75 /// the specified function.
76 bool canConstantFoldCallTo(const Function *F);
77
78 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
79 /// with the specified arguments, returning null if unsuccessful.
80 Constant *
81 ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands);
82 }
83
84 #endif