LLVM API Documentation

ConstantFolding.h

Go to the documentation of this file.
00001 //===-- ConstantFolding.h - Analyze constant folding possibilities --------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This family of functions determines the possibility of performing constant
00011 // folding.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
00016 #define LLVM_ANALYSIS_CONSTANTFOLDING_H
00017 
00018 namespace llvm {
00019   class Constant;
00020   class ConstantExpr;
00021   class Instruction;
00022   class TargetData;
00023   class Function;
00024   class Type;
00025 
00026 /// ConstantFoldInstruction - Attempt to constant fold the specified
00027 /// instruction.  If successful, the constant result is returned, if not, null
00028 /// is returned.  Note that this function can only fail when attempting to fold
00029 /// instructions like loads and stores, which have no constant expression form.
00030 ///
00031 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
00032 
00033 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
00034 /// using the specified TargetData.  If successful, the constant result is
00035 /// result is returned, if not, null is returned.
00036 Constant *ConstantFoldConstantExpression(ConstantExpr *CE,
00037                                          const TargetData *TD);
00038 
00039 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
00040 /// specified operands.  If successful, the constant result is returned, if not,
00041 /// null is returned.  Note that this function can fail when attempting to 
00042 /// fold instructions like loads and stores, which have no constant expression 
00043 /// form.
00044 ///
00045 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
00046                                    Constant*const * Ops, unsigned NumOps,
00047                                    const TargetData *TD = 0);
00048 
00049 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
00050 /// instruction (icmp/fcmp) with the specified operands.  If it fails, it
00051 /// returns a constant expression of the specified operands.
00052 ///
00053 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
00054                                           Constant*const * Ops, unsigned NumOps,
00055                                           const TargetData *TD = 0);
00056 
00057 
00058 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
00059 /// getelementptr constantexpr, return the constant value being addressed by the
00060 /// constant expression, or null if something is funny and we can't decide.
00061 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
00062   
00063 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
00064 /// the specified function.
00065 bool canConstantFoldCallTo(const Function *F);
00066 
00067 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
00068 /// with the specified arguments, returning null if unsuccessful.
00069 Constant *
00070 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
00071 }
00072 
00073 #endif