2003-09-30 18:37:50 +00:00
|
|
|
//===-- ConstantHandling.h - Stuff for manipulating constants ---*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-09-07 16:29:18 +00:00
|
|
|
// WARNING: These operators may return a null object if I don't know how to
|
|
|
|
// perform the specified operation on the specified constant types.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-01-12 20:48:11 +00:00
|
|
|
#ifndef CONSTANTHANDLING_H
|
|
|
|
#define CONSTANTHANDLING_H
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-28 19:55:58 +00:00
|
|
|
#include "llvm/Constants.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Type.h"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2001-11-01 05:55:13 +00:00
|
|
|
class PointerType;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2003-11-17 19:05:17 +00:00
|
|
|
struct ConstRules {
|
|
|
|
ConstRules() {}
|
2001-09-09 21:00:23 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
// Binary Operators...
|
2002-05-03 21:40:37 +00:00
|
|
|
virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *sub(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *div(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0;
|
2002-07-30 16:24:25 +00:00
|
|
|
virtual Constant *op_and(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *op_xor(const Constant *V1, const Constant *V2) const = 0;
|
2002-05-06 03:01:37 +00:00
|
|
|
virtual Constant *shl(const Constant *V1, const Constant *V2) const = 0;
|
|
|
|
virtual Constant *shr(const Constant *V1, const Constant *V2) const = 0;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
virtual ConstantBool *lessthan(const Constant *V1,
|
|
|
|
const Constant *V2) const = 0;
|
2003-11-17 20:19:35 +00:00
|
|
|
virtual ConstantBool *equalto(const Constant *V1,
|
|
|
|
const Constant *V2) const = 0;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-21 19:10:33 +00:00
|
|
|
// Casting operators. ick
|
2001-12-03 22:26:30 +00:00
|
|
|
virtual ConstantBool *castToBool (const Constant *V) const = 0;
|
|
|
|
virtual ConstantSInt *castToSByte (const Constant *V) const = 0;
|
|
|
|
virtual ConstantUInt *castToUByte (const Constant *V) const = 0;
|
|
|
|
virtual ConstantSInt *castToShort (const Constant *V) const = 0;
|
|
|
|
virtual ConstantUInt *castToUShort(const Constant *V) const = 0;
|
|
|
|
virtual ConstantSInt *castToInt (const Constant *V) const = 0;
|
|
|
|
virtual ConstantUInt *castToUInt (const Constant *V) const = 0;
|
|
|
|
virtual ConstantSInt *castToLong (const Constant *V) const = 0;
|
|
|
|
virtual ConstantUInt *castToULong (const Constant *V) const = 0;
|
|
|
|
virtual ConstantFP *castToFloat (const Constant *V) const = 0;
|
|
|
|
virtual ConstantFP *castToDouble(const Constant *V) const = 0;
|
2003-04-17 19:22:47 +00:00
|
|
|
virtual Constant *castToPointer(const Constant *V,
|
|
|
|
const PointerType *Ty) const = 0;
|
2001-12-03 22:26:30 +00:00
|
|
|
|
|
|
|
inline Constant *castTo(const Constant *V, const Type *Ty) const {
|
2001-07-21 19:10:33 +00:00
|
|
|
switch (Ty->getPrimitiveID()) {
|
|
|
|
case Type::BoolTyID: return castToBool(V);
|
|
|
|
case Type::UByteTyID: return castToUByte(V);
|
|
|
|
case Type::SByteTyID: return castToSByte(V);
|
|
|
|
case Type::UShortTyID: return castToUShort(V);
|
|
|
|
case Type::ShortTyID: return castToShort(V);
|
|
|
|
case Type::UIntTyID: return castToUInt(V);
|
|
|
|
case Type::IntTyID: return castToInt(V);
|
|
|
|
case Type::ULongTyID: return castToULong(V);
|
|
|
|
case Type::LongTyID: return castToLong(V);
|
|
|
|
case Type::FloatTyID: return castToFloat(V);
|
|
|
|
case Type::DoubleTyID: return castToDouble(V);
|
2003-11-16 20:21:15 +00:00
|
|
|
case Type::PointerTyID:
|
|
|
|
return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
|
2001-07-21 19:10:33 +00:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-17 19:05:17 +00:00
|
|
|
// ConstRules::get - Return an instance of ConstRules for the specified
|
|
|
|
// constant operands.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2004-01-12 20:43:44 +00:00
|
|
|
static ConstRules &get(const Constant *V1, const Constant *V2);
|
2003-04-17 19:22:47 +00:00
|
|
|
private:
|
2001-06-06 20:29:01 +00:00
|
|
|
ConstRules(const ConstRules &); // Do not implement
|
|
|
|
ConstRules &operator=(const ConstRules &); // Do not implement
|
|
|
|
};
|
|
|
|
|
2001-06-27 23:31:34 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implement higher level instruction folding type instructions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-05-06 17:54:50 +00:00
|
|
|
// Constant fold various types of instruction...
|
|
|
|
Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy);
|
|
|
|
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
|
|
|
|
const Constant *V2);
|
2003-04-17 19:22:47 +00:00
|
|
|
Constant *ConstantFoldGetElementPtr(const Constant *C,
|
|
|
|
const std::vector<Constant*> &IdxList);
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|