Give these files top-level comments that describe the current code.
[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
66 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
67 /// getelementptr constantexpr, return the constant value being addressed by the
68 /// constant expression, or null if something is funny and we can't decide.
69 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE,
70                                                  LLVMContext &Context);
71   
72 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
73 /// the specified function.
74 bool canConstantFoldCallTo(const Function *F);
75
76 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
77 /// with the specified arguments, returning null if unsuccessful.
78 Constant *
79 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
80 }
81
82 #endif