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   class LLVMContext;
00026 
00027 /// ConstantFoldInstruction - Attempt to constant fold the specified
00028 /// instruction.  If successful, the constant result is returned, if not, null
00029 /// is returned.  Note that this function can only fail when attempting to fold
00030 /// instructions like loads and stores, which have no constant expression form.
00031 ///
00032 Constant *ConstantFoldInstruction(Instruction *I, LLVMContext &Context,
00033                                   const TargetData *TD = 0);
00034 
00035 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
00036 /// using the specified TargetData.  If successful, the constant result is
00037 /// result is returned, if not, null is returned.
00038 Constant *ConstantFoldConstantExpression(ConstantExpr *CE, LLVMContext &Context,
00039                                          const TargetData *TD = 0);
00040 
00041 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
00042 /// specified operands.  If successful, the constant result is returned, if not,
00043 /// null is returned.  Note that this function can fail when attempting to 
00044 /// fold instructions like loads and stores, which have no constant expression 
00045 /// form.
00046 ///
00047 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
00048                                    Constant*const * Ops, unsigned NumOps,
00049                                    LLVMContext &Context,
00050                                    const TargetData *TD = 0);
00051 
00052 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
00053 /// instruction (icmp/fcmp) with the specified operands.  If it fails, it
00054 /// returns a constant expression of the specified operands.
00055 ///
00056 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
00057                                           Constant*const * Ops, unsigned NumOps,
00058                                           LLVMContext &Context,
00059                                           const TargetData *TD = 0);
00060 
00061 
00062 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
00063 /// getelementptr constantexpr, return the constant value being addressed by the
00064 /// constant expression, or null if something is funny and we can't decide.
00065 Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE,
00066                                                  LLVMContext &Context);
00067   
00068 /// canConstantFoldCallTo - Return true if its even possible to fold a call to
00069 /// the specified function.
00070 bool canConstantFoldCallTo(const Function *F);
00071 
00072 /// ConstantFoldCall - Attempt to constant fold a call to the specified function
00073 /// with the specified arguments, returning null if unsuccessful.
00074 Constant *
00075 ConstantFoldCall(Function *F, Constant* const* Operands, unsigned NumOperands);
00076 }
00077 
00078 #endif