2009-09-10 23:07:18 +00:00
|
|
|
//===-- ConstantFolding.h - Fold instructions into constants --------------===//
|
2005-10-27 16:00:10 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-27 16:00:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-11-23 10:16:18 +00:00
|
|
|
// This file declares routines for folding instructions into constants when all
|
|
|
|
// operands are constants, for example "sub i32 1, 0" -> "1".
|
2009-09-10 23:07:18 +00:00
|
|
|
//
|
|
|
|
// 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 16:00:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-01-30 23:47:35 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
|
|
|
|
#define LLVM_ANALYSIS_CONSTANTFOLDING_H
|
2005-10-27 16:00:10 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-01-30 23:47:35 +00:00
|
|
|
class Constant;
|
|
|
|
class ConstantExpr;
|
|
|
|
class Instruction;
|
|
|
|
class TargetData;
|
2011-12-01 03:08:23 +00:00
|
|
|
class TargetLibraryInfo;
|
2007-01-30 23:47:35 +00:00
|
|
|
class Function;
|
2007-12-10 22:53:04 +00:00
|
|
|
class Type;
|
2011-07-19 13:32:40 +00:00
|
|
|
template<typename T>
|
|
|
|
class ArrayRef;
|
2005-10-27 16:00:10 +00:00
|
|
|
|
2010-11-23 10:16:18 +00:00
|
|
|
/// ConstantFoldInstruction - Try to constant fold the specified instruction.
|
|
|
|
/// If successful, the constant result is returned, if not, null is returned.
|
|
|
|
/// Note that this fails if not all of the operands are constant. Otherwise,
|
|
|
|
/// this function can only fail when attempting to fold instructions like loads
|
|
|
|
/// and stores, which have no constant expression form.
|
2011-12-01 03:08:23 +00:00
|
|
|
Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0,
|
|
|
|
const TargetLibraryInfo *TLI = 0);
|
2007-01-30 23:47:35 +00:00
|
|
|
|
2008-05-25 20:56:15 +00: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 22:00:06 +00:00
|
|
|
Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
|
2011-12-01 03:08:23 +00:00
|
|
|
const TargetData *TD = 0,
|
|
|
|
const TargetLibraryInfo *TLI = 0);
|
2008-05-25 20:56:15 +00:00
|
|
|
|
2007-01-30 23:47:35 +00: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.
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
|
2011-07-19 13:32:40 +00:00
|
|
|
ArrayRef<Constant *> Ops,
|
2011-12-01 03:08:23 +00:00
|
|
|
const TargetData *TD = 0,
|
|
|
|
const TargetLibraryInfo *TLI = 0);
|
2007-12-10 22:53:04 +00:00
|
|
|
|
|
|
|
/// 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-09 23:06:58 +00:00
|
|
|
Constant *LHS, Constant *RHS,
|
2011-12-01 03:08:23 +00:00
|
|
|
const TargetData *TD = 0,
|
|
|
|
const TargetLibraryInfo *TLI = 0);
|
2007-01-30 23:47:35 +00:00
|
|
|
|
2011-09-05 06:52:48 +00:00
|
|
|
/// ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue
|
|
|
|
/// instruction with the specified operands and indices. The constant result is
|
|
|
|
/// returned if successful; if not, null is returned.
|
|
|
|
Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
|
|
|
|
ArrayRef<unsigned> Idxs);
|
|
|
|
|
2009-10-22 06:25:11 +00: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-30 23:47:35 +00: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 16:36:26 +00:00
|
|
|
Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
|
2012-01-24 05:43:50 +00:00
|
|
|
|
|
|
|
/// ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr
|
|
|
|
/// indices (with an *implied* zero pointer index that is not in the list),
|
|
|
|
/// return the constant value being addressed by a virtual load, or null if
|
|
|
|
/// something is funny and we can't decide.
|
|
|
|
Constant *ConstantFoldLoadThroughGEPIndices(Constant *C,
|
|
|
|
ArrayRef<Constant*> Indices);
|
|
|
|
|
2005-10-27 16:00:10 +00:00
|
|
|
/// canConstantFoldCallTo - Return true if its even possible to fold a call to
|
|
|
|
/// the specified function.
|
2008-01-31 01:05:10 +00:00
|
|
|
bool canConstantFoldCallTo(const Function *F);
|
2005-10-27 16:00:10 +00:00
|
|
|
|
|
|
|
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
|
|
|
|
/// with the specified arguments, returning null if unsuccessful.
|
2011-12-01 03:08:23 +00:00
|
|
|
Constant *ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands,
|
|
|
|
const TargetLibraryInfo *TLI = 0);
|
2005-10-27 16:00:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 23:47:35 +00:00
|
|
|
#endif
|