-//===-- llvm/Constants.h - Constant class subclass definitions ---*- C++ -*--=//
+//===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
//
// This file contains the declarations for the subclasses of Constant, which
// represent the different type of constant pool values
#ifndef LLVM_CONSTANTS_H
#define LLVM_CONSTANTS_H
-#include <assert.h>
-
#include "llvm/Constant.h"
#include "Support/DataTypes.h"
template<class ConstantClass, class TypeClass, class ValType>
struct ConstantCreator;
+template<class ConstantClass, class TypeClass>
+struct ConvertConstantType;
+
//===---------------------------------------------------------------------------
/// ConstantIntegral - Shared superclass of boolean and integer constants.
///
static ConstantInt *get(const Type *Ty, unsigned char V);
+ /// getRawValue - return the underlying value of this constant as a 64-bit
+ /// unsigned integer value.
+ ///
+ inline uint64_t getRawValue() const { return Val.Unsigned; }
+
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
virtual bool isNullValue() const { return Val.Unsigned == 0; }
ConstantSInt(const Type *Ty, int64_t V);
public:
/// get() - Static factory methods - Return objects of the specified value
+ ///
static ConstantSInt *get(const Type *Ty, int64_t V);
/// isValueValidForType - return true if Ty is big enough to represent V.
+ ///
static bool isValueValidForType(const Type *Ty, int64_t V);
/// getValue - return the underlying value of this constant.
+ ///
inline int64_t getValue() const { return Val.Signed; }
virtual bool isAllOnesValue() const { return getValue() == -1; }
}
/// Methods for support type inquiry through isa, cast, and dyn_cast:
+ ///
static inline bool classof(const ConstantSInt *) { return true; }
static bool classof(const Constant *CPV); // defined in Constants.cpp
static inline bool classof(const Value *V) {
ConstantUInt(const Type *Ty, uint64_t V);
public:
/// get() - Static factory methods - Return objects of the specified value
+ ///
static ConstantUInt *get(const Type *Ty, uint64_t V);
/// isValueValidForType - return true if Ty is big enough to represent V.
+ ///
static bool isValueValidForType(const Type *Ty, uint64_t V);
/// getValue - return the underlying value of this constant.
+ ///
inline uint64_t getValue() const { return Val.Unsigned; }
/// isMaxValue - Return true if this is the largest value that may be
ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
protected:
ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
- void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantArray *get(const ArrayType *T, const std::vector<Constant*> &);
}
virtual void destroyConstant();
- virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+ bool DisableChecking = false);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantArray *) { return true; }
ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
protected:
ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
- void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantStruct *get(const StructType *T,
}
virtual void destroyConstant();
- virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+ bool DisableChecking = false);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantStruct *) { return true; }
ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
protected:
ConstantPointerNull(const PointerType *T) : ConstantPointer(T) {}
- void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
public:
}
virtual void destroyConstant();
- virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+ bool DisableChecking = false);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantPointerRef *) { return true; }
unsigned iType; // Operation type (an Instruction opcode)
friend struct ConstantCreator<ConstantExpr,Type,
std::pair<unsigned, std::vector<Constant*> > >;
+ friend struct ConvertConstantType<ConstantExpr, Type>;
protected:
// Cast creation ctor
// GEP instruction creation ctor
ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
const Type *DestTy);
- void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
+
+ // These private methods are used by the type resolution code to create
+ // ConstantExprs in intermediate forms.
+ static Constant *getTy(const Type *Ty, unsigned Opcode,
+ Constant *C1, Constant *C2);
+ static Constant *getShiftTy(const Type *Ty,
+ unsigned Opcode, Constant *C1, Constant *C2);
+ static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
+ const std::vector<Constant*> &IdxList);
public:
// Static methods to construct a ConstantExpr of different kinds. Note that
// expression into something simpler if possible.
/// Cast constant expr
+ ///
static Constant *getCast(Constant *C, const Type *Ty);
/// Binary constant expr - Use with binary operators...
- static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
+ ///
+ static Constant *get(unsigned Opcode, Constant *C1, Constant *C2) {
+ return getTy(C1->getType(), Opcode, C1, C2);
+ }
/// getShift - Return a shift left or shift right constant expr
- static Constant *getShift(unsigned Opcode, Constant *C1, Constant *C2);
+ ///
+ static Constant *getShift(unsigned Opcode, Constant *C1, Constant *C2) {
+ return getShiftTy(C1->getType(), Opcode, C1, C2);
+ }
/// Getelementptr form...
+ ///
static Constant *getGetElementPtr(Constant *C,
const std::vector<Constant*> &IdxList);
virtual bool isConstantExpr() const { return true; }
virtual void destroyConstant();
- virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+ bool DisableChecking = false);
/// Override methods to provide more type information...
inline Constant *getOperand(unsigned i) {