summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-20 19:13:28 +0000
committerChris Lattner <sabre@nondot.org>2001-07-20 19:13:28 +0000
commit85b1f151134a51c3481837ee49cff24505c0c54e (patch)
tree7add0fb159f30a9ef741c3b1c038da155854cdb9
parentc9bdc871cac72ee367475419ad3d7d5f352c0365 (diff)
downloadbcm5719-llvm-85b1f151134a51c3481837ee49cff24505c0c54e.tar.gz
bcm5719-llvm-85b1f151134a51c3481837ee49cff24505c0c54e.zip
Add new base class ConstPoolInt, useful for dealing with integral constants
llvm-svn: 209
-rw-r--r--llvm/include/llvm/ConstPoolVals.h57
1 files changed, 46 insertions, 11 deletions
diff --git a/llvm/include/llvm/ConstPoolVals.h b/llvm/include/llvm/ConstPoolVals.h
index ff7baf5b404..aa2e2ff4809 100644
--- a/llvm/include/llvm/ConstPoolVals.h
+++ b/llvm/include/llvm/ConstPoolVals.h
@@ -28,10 +28,11 @@ class ConstPoolVal : public User {
Parent = parent;
}
-public:
+protected:
inline ConstPoolVal(const Type *Ty, const string &Name = "")
: User(Ty, Value::ConstantVal, Name) { Parent = 0; }
+public:
// Specialize setName to handle symbol table majik...
virtual void setName(const string &name);
@@ -84,40 +85,74 @@ public:
//===---------------------------------------------------------------------------
+// ConstPoolInt - Superclass of ConstPoolSInt & ConstPoolUInt, to make dealing
+// with integral constants easier.
+//
+class ConstPoolInt : public ConstPoolVal {
+protected:
+ union {
+ int64_t Signed;
+ uint64_t Unsigned;
+ } Val;
+ ConstPoolInt(const ConstPoolInt &CP);
+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;
+
+ // equals - 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
+ // small values, because this is all that can be represented with all types.
+ //
+ bool equals(unsigned char V) {
+ assert(V <= 127 && "equals: Can only be used with very small constants!");
+ return Val.Unsigned == V;
+ }
+
+ // isIntegral - Equilivent to isSigned() || isUnsigned, but with only a single
+ // virtual function invocation.
+ //
+ virtual bool isIntegral() const { return 1; }
+
+ // ConstPoolInt::get static method: return a constant pool int with the
+ // specified value. as above, we work only with very small values here.
+ //
+ static ConstPoolInt *get(const Type *Ty, unsigned char V);
+};
+
+
+//===---------------------------------------------------------------------------
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
//
-class ConstPoolSInt : public ConstPoolVal {
- int64_t Val;
- ConstPoolSInt(const ConstPoolSInt &CP);
+class ConstPoolSInt : public ConstPoolInt {
+ ConstPoolSInt(const ConstPoolSInt &CP) : ConstPoolInt(CP) {}
public:
ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");
virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }
virtual string getStrValue() const;
- virtual bool equals(const ConstPoolVal *V) const;
static bool isValueValidForType(const Type *Ty, int64_t V);
- inline int64_t getValue() const { return Val; }
+ inline int64_t getValue() const { return Val.Signed; }
};
//===---------------------------------------------------------------------------
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
//
-class ConstPoolUInt : public ConstPoolVal {
- uint64_t Val;
- ConstPoolUInt(const ConstPoolUInt &CP);
+class ConstPoolUInt : public ConstPoolInt {
+ ConstPoolUInt(const ConstPoolUInt &CP) : ConstPoolInt(CP) {}
public:
ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");
virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }
virtual string getStrValue() const;
- virtual bool equals(const ConstPoolVal *V) const;
static bool isValueValidForType(const Type *Ty, uint64_t V);
- inline uint64_t getValue() const { return Val; }
+ inline uint64_t getValue() const { return Val.Unsigned; }
};
OpenPOWER on IntegriCloud