2009-09-11 01:07:18 +02:00
|
|
|
//===-- ConstantFolding.h - Fold instructions into constants --------------===//
|
2005-10-27 18:00:10 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-27 18:00:10 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-09-11 01:07:18 +02:00
|
|
|
// This file declares routines for folding instructions into constants.
|
|
|
|
//
|
|
|
|
// Also, to supplement the basic VMCore ConstantExpr simplifications,
|
|
|
|
// this file declares some additional folding routines that can make use of
|
|
|
|
// TargetData information. These functions cannot go in VMCore due to library
|
|
|
|
// dependency issues.
|
2005-10-27 18:00:10 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-01-31 00:47:35 +01:00
|
|
|
#ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
|
|
|
|
#define LLVM_ANALYSIS_CONSTANTFOLDING_H
|
2005-10-27 18:00:10 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-01-31 00:47:35 +01:00
|
|
|
class Constant;
|
|
|
|
class ConstantExpr;
|
|
|
|
class Instruction;
|
|
|
|
class TargetData;
|
|
|
|
class Function;
|
2007-12-10 23:53:04 +01:00
|
|
|
class Type;
|
2005-10-27 18:00:10 +02:00
|
|
|
|
2007-01-31 00:47:35 +01:00
|
|
|
/// ConstantFoldInstruction - Attempt to constant fold the specified
|
|
|
|
/// instruction. If successful, the constant result is returned, if not, null
|
|
|
|
/// is returned. Note that this function can only fail when attempting to fold
|
|
|
|
/// instructions like loads and stores, which have no constant expression form.
|
|
|
|
///
|
2009-11-06 05:27:31 +01:00
|
|
|
Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0);
|
2007-01-31 00:47:35 +01:00
|
|
|
|
2008-05-25 22:56:15 +02:00
|
|
|
/// ConstantFoldConstantExpression - Attempt to fold the constant expression
|
|
|
|
/// using the specified TargetData. If successful, the constant result is
|
|
|
|
/// result is returned, if not, null is returned.
|
2010-02-08 23:00:06 +01:00
|
|
|
Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
|
2009-06-02 23:48:15 +02:00
|
|
|
const TargetData *TD = 0);
|
2008-05-25 22:56:15 +02:00
|
|
|
|
2007-01-31 00:47:35 +01:00
|
|
|
/// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
|
|
|
|
/// specified operands. If successful, the constant result is returned, if not,
|
|
|
|
/// null is returned. Note that this function can fail when attempting to
|
|
|
|
/// fold instructions like loads and stores, which have no constant expression
|
|
|
|
/// form.
|
|
|
|
///
|
2007-12-10 23:53:04 +01:00
|
|
|
Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
|
2009-11-06 05:27:31 +01:00
|
|
|
Constant *const *Ops, unsigned NumOps,
|
2007-12-10 23:53:04 +01:00
|
|
|
const TargetData *TD = 0);
|
|
|
|
|
|
|
|
/// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
|
|
|
|
/// instruction (icmp/fcmp) with the specified operands. If it fails, it
|
|
|
|
/// returns a constant expression of the specified operands.
|
|
|
|
///
|
|
|
|
Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
|
2009-11-10 00:06:58 +01:00
|
|
|
Constant *LHS, Constant *RHS,
|
2007-12-10 23:53:04 +01:00
|
|
|
const TargetData *TD = 0);
|
2007-01-31 00:47:35 +01:00
|
|
|
|
2009-10-22 08:25:11 +02:00
|
|
|
/// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
|
|
|
|
/// produce if it is constant and determinable. If this is not determinable,
|
|
|
|
/// return null.
|
|
|
|
Constant *ConstantFoldLoadFromConstPtr(Constant *C, const TargetData *TD = 0);
|
2007-01-31 00:47:35 +01:00
|
|
|
|
|
|
|
/// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
|
|
|
|
/// getelementptr constantexpr, return the constant value being addressed by the
|
|
|
|
/// constant expression, or null if something is funny and we can't decide.
|
2009-10-05 18:36:26 +02:00
|
|
|
Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
|
2007-01-31 00:47:35 +01:00
|
|
|
|
2005-10-27 18:00:10 +02:00
|
|
|
/// canConstantFoldCallTo - Return true if its even possible to fold a call to
|
|
|
|
/// the specified function.
|
2008-01-31 02:05:10 +01:00
|
|
|
bool canConstantFoldCallTo(const Function *F);
|
2005-10-27 18:00:10 +02:00
|
|
|
|
|
|
|
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
|
|
|
|
/// with the specified arguments, returning null if unsuccessful.
|
2007-01-31 00:12:47 +01:00
|
|
|
Constant *
|
2009-11-06 05:27:31 +01:00
|
|
|
ConstantFoldCall(Function *F, Constant *const *Operands, unsigned NumOperands);
|
2005-10-27 18:00:10 +02:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:47:35 +01:00
|
|
|
#endif
|