mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-11 04:30:52 +00:00
Implement support for globally unique constants. Constants no longer live
in a module or method local pool, they are global to the llvm system. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@419 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
20b0010030
commit
3e22bed211
@ -9,7 +9,6 @@
|
|||||||
#define LLVM_CONSTPOOLVALS_H
|
#define LLVM_CONSTPOOLVALS_H
|
||||||
|
|
||||||
#include "llvm/User.h"
|
#include "llvm/User.h"
|
||||||
#include "llvm/SymTabValue.h"
|
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -21,38 +20,17 @@ class StructType;
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
class ConstPoolVal : public User {
|
class ConstPoolVal : public User {
|
||||||
SymTabValue *Parent;
|
|
||||||
|
|
||||||
friend class ValueHolder<ConstPoolVal, SymTabValue, SymTabValue>;
|
|
||||||
inline void setParent(SymTabValue *parent) {
|
|
||||||
Parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline ConstPoolVal(const Type *Ty, const string &Name = "")
|
inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
|
||||||
: User(Ty, Value::ConstantVal, Name) { Parent = 0; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Specialize setName to handle symbol table majik...
|
// Specialize setName to handle symbol table majik...
|
||||||
virtual void setName(const string &name);
|
virtual void setName(const string &name, SymbolTable *ST = 0);
|
||||||
|
|
||||||
// Static constructor to create a '0' constant of arbitrary type...
|
|
||||||
static ConstPoolVal *getNullConstant(const Type *Ty);
|
|
||||||
|
|
||||||
// clone() - Create a copy of 'this' value that is identical in all ways
|
|
||||||
// except the following:
|
|
||||||
// * The value has no parent
|
|
||||||
// * The value has no name
|
|
||||||
//
|
|
||||||
virtual ConstPoolVal *clone() const = 0;
|
|
||||||
|
|
||||||
virtual string getStrValue() const = 0;
|
virtual string getStrValue() const = 0;
|
||||||
virtual bool equals(const ConstPoolVal *V) const = 0;
|
|
||||||
|
|
||||||
inline const SymTabValue *getParent() const { return Parent; }
|
// Static constructor to get a '0' constant of arbitrary type...
|
||||||
inline SymTabValue *getParent() { return Parent; }
|
static ConstPoolVal *getNullConstant(const Type *Ty);
|
||||||
inline const Value *getParentV() const { return Parent->getSTVParent(); }
|
|
||||||
inline Value *getParentV() { return Parent->getSTVParent(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -66,22 +44,20 @@ public:
|
|||||||
//
|
//
|
||||||
class ConstPoolBool : public ConstPoolVal {
|
class ConstPoolBool : public ConstPoolVal {
|
||||||
bool Val;
|
bool Val;
|
||||||
ConstPoolBool(const ConstPoolBool &CP);
|
ConstPoolBool(const ConstPoolBool &); // DO NOT IMPLEMENT
|
||||||
|
ConstPoolBool(bool V);
|
||||||
public:
|
public:
|
||||||
ConstPoolBool(const Type *Ty, bool V, const string &Name = "");
|
static ConstPoolBool *True, *False; // The True & False values
|
||||||
ConstPoolBool(bool V, const string &Name = "");
|
|
||||||
|
// Factory objects - Return objects of the specified value
|
||||||
|
static ConstPoolBool *get(bool Value) { return Value ? True : False; }
|
||||||
|
static ConstPoolBool *get(const Type *Ty, bool Value) { return get(Value); }
|
||||||
|
|
||||||
|
// inverted - Return the opposite value of the current value.
|
||||||
|
inline ConstPoolBool *inverted() const { return (this==True) ? False : True; }
|
||||||
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }
|
|
||||||
|
|
||||||
inline bool getValue() const { return Val; }
|
inline bool getValue() const { return Val; }
|
||||||
|
|
||||||
// setValue - Be careful... if there is more than one 'use' of this node, then
|
|
||||||
// they will ALL see the value that you set...
|
|
||||||
//
|
|
||||||
inline void setValue(bool v) { Val = v; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -95,19 +71,16 @@ protected:
|
|||||||
int64_t Signed;
|
int64_t Signed;
|
||||||
uint64_t Unsigned;
|
uint64_t Unsigned;
|
||||||
} Val;
|
} Val;
|
||||||
ConstPoolInt(const ConstPoolInt &CP);
|
ConstPoolInt(const ConstPoolInt &); // DO NOT IMPLEMENT
|
||||||
|
ConstPoolInt(const Type *Ty, uint64_t V);
|
||||||
public:
|
public:
|
||||||
ConstPoolInt(const Type *Ty, int64_t V, const string &Name = "");
|
|
||||||
ConstPoolInt(const Type *Ty, uint64_t V, const string &Name = "");
|
|
||||||
|
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
// equalsInt - Provide a helper method that can be used to determine if the
|
// equalsInt - Provide a helper method that can be used to determine if the
|
||||||
// constant contained within is equal to a constant. This only works for very
|
// constant contained within is equal to a constant. This only works for very
|
||||||
// small values, because this is all that can be represented with all types.
|
// small values, because this is all that can be represented with all types.
|
||||||
//
|
//
|
||||||
bool equalsInt(unsigned char V) const {
|
bool equalsInt(unsigned char V) const {
|
||||||
assert(V <= 127 && "equals: Can only be used with very small constants!");
|
assert(V <= 127 &&
|
||||||
|
"equals: Can only be used with very small positive constants!");
|
||||||
return Val.Unsigned == V;
|
return Val.Unsigned == V;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +95,11 @@ public:
|
|||||||
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
|
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
|
||||||
//
|
//
|
||||||
class ConstPoolSInt : public ConstPoolInt {
|
class ConstPoolSInt : public ConstPoolInt {
|
||||||
ConstPoolSInt(const ConstPoolSInt &CP) : ConstPoolInt(CP) {}
|
ConstPoolSInt(const ConstPoolSInt &); // DO NOT IMPLEMENT
|
||||||
|
protected:
|
||||||
|
ConstPoolSInt(const Type *Ty, int64_t V);
|
||||||
public:
|
public:
|
||||||
ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
|
static ConstPoolSInt *get(const Type *Ty, int64_t V);
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
|
|
||||||
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
|
|
||||||
@ -139,11 +112,11 @@ public:
|
|||||||
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
|
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
|
||||||
//
|
//
|
||||||
class ConstPoolUInt : public ConstPoolInt {
|
class ConstPoolUInt : public ConstPoolInt {
|
||||||
ConstPoolUInt(const ConstPoolUInt &CP) : ConstPoolInt(CP) {}
|
ConstPoolUInt(const ConstPoolUInt &); // DO NOT IMPLEMENT
|
||||||
|
protected:
|
||||||
|
ConstPoolUInt(const Type *Ty, uint64_t V);
|
||||||
public:
|
public:
|
||||||
ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
|
static ConstPoolUInt *get(const Type *Ty, uint64_t V);
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
|
|
||||||
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
|
|
||||||
@ -157,48 +130,30 @@ public:
|
|||||||
//
|
//
|
||||||
class ConstPoolFP : public ConstPoolVal {
|
class ConstPoolFP : public ConstPoolVal {
|
||||||
double Val;
|
double Val;
|
||||||
ConstPoolFP(const ConstPoolFP &CP);
|
ConstPoolFP(const ConstPoolFP &); // DO NOT IMPLEMENT
|
||||||
|
protected:
|
||||||
|
ConstPoolFP(const Type *Ty, double V);
|
||||||
public:
|
public:
|
||||||
ConstPoolFP(const Type *Ty, double V, const string &Name = "");
|
static ConstPoolFP *get(const Type *Ty, double V);
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
static bool isValueValidForType(const Type *Ty, double V);
|
static bool isValueValidForType(const Type *Ty, double V);
|
||||||
inline double getValue() const { return Val; }
|
inline double getValue() const { return Val; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===---------------------------------------------------------------------------
|
|
||||||
// ConstPoolType - Type Declarations
|
|
||||||
//
|
|
||||||
class ConstPoolType : public ConstPoolVal {
|
|
||||||
const Type *Val;
|
|
||||||
ConstPoolType(const ConstPoolType &CPT);
|
|
||||||
public:
|
|
||||||
ConstPoolType(const Type *V, const string &Name = "");
|
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
|
|
||||||
virtual string getStrValue() const;
|
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
inline const Type *getValue() const { return Val; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//===---------------------------------------------------------------------------
|
//===---------------------------------------------------------------------------
|
||||||
// ConstPoolArray - Constant Array Declarations
|
// ConstPoolArray - Constant Array Declarations
|
||||||
//
|
//
|
||||||
class ConstPoolArray : public ConstPoolVal {
|
class ConstPoolArray : public ConstPoolVal {
|
||||||
ConstPoolArray(const ConstPoolArray &CPT);
|
ConstPoolArray(const ConstPoolArray &); // DO NOT IMPLEMENT
|
||||||
|
protected:
|
||||||
|
ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
|
||||||
public:
|
public:
|
||||||
ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V,
|
static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);
|
||||||
const string &Name = "");
|
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
inline const vector<Use> &getValues() const { return Operands; }
|
inline const vector<Use> &getValues() const { return Operands; }
|
||||||
};
|
};
|
||||||
@ -208,14 +163,14 @@ public:
|
|||||||
// ConstPoolStruct - Constant Struct Declarations
|
// ConstPoolStruct - Constant Struct Declarations
|
||||||
//
|
//
|
||||||
class ConstPoolStruct : public ConstPoolVal {
|
class ConstPoolStruct : public ConstPoolVal {
|
||||||
ConstPoolStruct(const ConstPoolStruct &CPT);
|
ConstPoolStruct(const ConstPoolStruct &); // DO NOT IMPLEMENT
|
||||||
|
protected:
|
||||||
|
ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
|
||||||
public:
|
public:
|
||||||
ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V,
|
static ConstPoolStruct *get(const StructType *T,
|
||||||
const string &Name = "");
|
const vector<ConstPoolVal*> &V);
|
||||||
|
|
||||||
virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
|
|
||||||
virtual string getStrValue() const;
|
virtual string getStrValue() const;
|
||||||
virtual bool equals(const ConstPoolVal *V) const;
|
|
||||||
|
|
||||||
inline const vector<Use> &getValues() const { return Operands; }
|
inline const vector<Use> &getValues() const { return Operands; }
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user