[llvm-commits] [bug_122] CVS: llvm/include/llvm/Type.def Type.h Value.h AbstractTypeUser.h DerivedTypes.h
LLVM
llvm at cs.uiuc.edu
Sun May 16 18:56:00 PDT 2004
Changes in directory llvm/include/llvm:
Type.def updated: 1.6 -> 1.6.8.1
Type.h updated: 1.42 -> 1.42.2.1
Value.h updated: 1.50 -> 1.50.4.1
AbstractTypeUser.h updated: 1.19 -> 1.19.4.1
DerivedTypes.h updated: 1.56 -> 1.56.2.1
---
Log message:
Changes to make Type not derive from Value. A new "PrintableItem" class was
created to contain the remaining common functionality between Value and
Type. The PATypeHolder implementation was taken out of Type.h.
---
Diffs of the changes: (+59 -117)
Index: llvm/include/llvm/Type.def
diff -u llvm/include/llvm/Type.def:1.6 llvm/include/llvm/Type.def:1.6.8.1
--- llvm/include/llvm/Type.def:1.6 Tue Nov 11 16:41:30 2003
+++ llvm/include/llvm/Type.def Sun May 16 18:56:20 2004
@@ -44,7 +44,6 @@
HANDLE_PRIM_TYPE(ULong , 8)
HANDLE_PRIM_TYPE(Float , 4)
HANDLE_PRIM_TYPE(Double, 8)
-HANDLE_PRIM_TYPE(Type , 0)
HANDLE_PRIM_TYPE(Label , 0)
Index: llvm/include/llvm/Type.h
diff -u llvm/include/llvm/Type.h:1.42 llvm/include/llvm/Type.h:1.42.2.1
--- llvm/include/llvm/Type.h:1.42 Fri Mar 26 15:43:12 2004
+++ llvm/include/llvm/Type.h Sun May 16 18:56:20 2004
@@ -33,13 +33,17 @@
#ifndef LLVM_TYPE_H
#define LLVM_TYPE_H
-#include "llvm/Value.h"
+#include "llvm/PrintableItem.h"
+#include "llvm/AbstractTypeUser.h"
#include "Support/GraphTraits.h"
#include "Support/iterator"
+#include "Support/Casting.h"
#include <vector>
namespace llvm {
+class Value;
+class SymbolTable;
class DerivedType;
class FunctionType;
class ArrayType;
@@ -47,7 +51,7 @@
class StructType;
class OpaqueType;
-struct Type : public Value {
+struct Type : public PrintableItem {
///===-------------------------------------------------------------------===//
/// Definitions of all of the base types for the Type system. Based on this
/// value, you can cast to a "DerivedType" subclass (see DerivedTypes.h)
@@ -55,22 +59,19 @@
/// Type::getPrimitiveType function, or else things will break!
///
enum PrimitiveID {
- VoidTyID = 0 , BoolTyID, // 0, 1: Basics...
- UByteTyID , SByteTyID, // 2, 3: 8 bit types...
- UShortTyID , ShortTyID, // 4, 5: 16 bit types...
- UIntTyID , IntTyID, // 6, 7: 32 bit types...
- ULongTyID , LongTyID, // 8, 9: 64 bit types...
+ VoidTyID = 0 , BoolTyID, // 0, 1: Basics
+ UByteTyID , SByteTyID, // 2, 3: 8 bit types
+ UShortTyID , ShortTyID, // 4, 5: 16 bit types
+ UIntTyID , IntTyID, // 6, 7: 32 bit types
+ ULongTyID , LongTyID, // 8, 9: 64 bit types
+ FloatTyID , DoubleTyID, // 10,11: Floating point types
+ LabelTyID , // 12 : Labels
- FloatTyID , DoubleTyID, // 10,11: Floating point types...
-
- TypeTyID, // 12 : Type definitions
- LabelTyID , // 13 : Labels...
-
- // Derived types... see DerivedTypes.h file...
+ // Derived types... see DerivedTypes.h file
// Make sure FirstDerivedTyID stays up to date!!!
- FunctionTyID , StructTyID, // Functions... Structs...
- ArrayTyID , PointerTyID, // Array... pointer...
- OpaqueTyID, // Opaque type instances...
+ FunctionTyID , StructTyID, // 13,14: Functions,Structs
+ ArrayTyID , PointerTyID, // 15,16: Array,Pointer
+ OpaqueTyID, // 17 : Opaque type instances
//PackedTyID , // SIMD 'packed' format... TODO
//...
@@ -93,14 +94,9 @@
const Type *getForwardedTypeInternal() const;
protected:
/// ctor is protected, so only subclasses can create Type objects...
- Type(const std::string &Name, PrimitiveID id);
+ Type(PrimitiveID id);
virtual ~Type() {}
- /// setName - Associate the name with this type in the symbol table, but don't
- /// set the local name to be equal specified name.
- ///
- virtual void setName(const std::string &Name, SymbolTable *ST = 0);
-
/// Types can become nonabstract later, if they are refined.
///
inline void setAbstract(bool Val) { Abstract = Val; }
@@ -194,7 +190,7 @@
/// isFirstClassType - Return true if the value is holdable in a register.
inline bool isFirstClassType() const {
- return (ID != VoidTyID && ID < TypeTyID) || ID == PointerTyID;
+ return (ID != VoidTyID && ID < LabelTyID) || ID == PointerTyID;
}
/// isSized - Return true if it makes sense to take the size of this type. To
@@ -202,8 +198,8 @@
/// TargetData subsystem to do this.
///
bool isSized() const {
- return ID != VoidTyID && ID != TypeTyID &&
- ID != FunctionTyID && ID != LabelTyID && ID != OpaqueTyID;
+ return ID != VoidTyID && ID != FunctionTyID &&
+ ID != LabelTyID && ID != OpaqueTyID;
}
/// getPrimitiveSize - Return the basic size of this type if it is a primative
@@ -229,6 +225,10 @@
return getForwardedTypeInternal();
}
+ /// Compatibility function to make Type work like Value. The type of a Type is
+ /// of course "this".
+ inline const Type *getType() const { return this; }
+
//===--------------------------------------------------------------------===//
// Type Iteration support
//
@@ -268,13 +268,11 @@
*LongTy , *ULongTy;
static Type *FloatTy, *DoubleTy;
- static Type *TypeTy , *LabelTy;
+ static Type* LabelTy;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Type *T) { return true; }
- static inline bool classof(const Value *V) {
- return V->getValueType() == Value::TypeVal;
- }
+ static inline bool classof(const Value *V) { return false; }
#include "llvm/Type.def"
@@ -301,62 +299,13 @@
if (--RefCount == 0)
RefCountIsZero();
}
+
private:
virtual void RefCountIsZero() const {
abort(); // only on derived types!
}
};
-
-//===----------------------------------------------------------------------===//
-// Define some inline methods for the AbstractTypeUser.h:PATypeHandle class.
-// These are defined here because they MUST be inlined, yet are dependent on
-// the definition of the Type class. Of course Type derives from Value, which
-// contains an AbstractTypeUser instance, so there is no good way to factor out
-// the code. Hence this bit of uglyness.
-//
-// In the long term, Type should not derive from Value, allowing
-// AbstractTypeUser.h to #include Type.h, allowing us to eliminate this
-// nastyness entirely.
-//
-inline void PATypeHandle::addUser() {
- assert(Ty && "Type Handle has a null type!");
- if (Ty->isAbstract())
- Ty->addAbstractTypeUser(User);
-}
-inline void PATypeHandle::removeUser() {
- if (Ty->isAbstract())
- Ty->removeAbstractTypeUser(User);
-}
-
-inline void PATypeHandle::removeUserFromConcrete() {
- if (!Ty->isAbstract())
- Ty->removeAbstractTypeUser(User);
-}
-
-// Define inline methods for PATypeHolder...
-
-inline void PATypeHolder::addRef() {
- if (Ty->isAbstract())
- Ty->addRef();
-}
-
-inline void PATypeHolder::dropRef() {
- if (Ty->isAbstract())
- Ty->dropRef();
-}
-
-/// get - This implements the forwarding part of the union-find algorithm for
-/// abstract types. Before every access to the Type*, we check to see if the
-/// type we are pointing to is forwarding to a new type. If so, we drop our
-/// reference to the type.
-///
-inline const Type* PATypeHolder::get() const {
- const Type *NewTy = Ty->getForwardedType();
- if (!NewTy) return Ty;
- return *const_cast<PATypeHolder*>(this) = NewTy;
-}
-
//===----------------------------------------------------------------------===//
Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.50 llvm/include/llvm/Value.h:1.50.4.1
--- llvm/include/llvm/Value.h:1.50 Thu Feb 26 02:08:38 2004
+++ llvm/include/llvm/Value.h Sun May 16 18:56:20 2004
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
//
// This file defines the very important Value class. This is subclassed by a
-// bunch of other important classes, like Instruction, Function, Type, etc...
+// bunch of other important classes, like Instruction, Function, etc...
//
// This file also defines the Use<> template for users of value.
//
@@ -17,14 +17,12 @@
#ifndef LLVM_VALUE_H
#define LLVM_VALUE_H
-#include "llvm/AbstractTypeUser.h"
+#include "llvm/Type.h"
#include "llvm/Use.h"
-#include "Support/Casting.h"
#include <iostream>
namespace llvm {
-class Type;
class Constant;
class Argument;
class Instruction;
@@ -41,9 +39,8 @@
/// Value - The base class of all values computed by a program that may be used
/// as operands to other values.
///
-struct Value {
+struct Value : public PrintableItem {
enum ValueTy {
- TypeVal, // This is an instance of Type
ConstantVal, // This is an instance of Constant
ArgumentVal, // This is an instance of Argument
InstructionVal, // This is an instance of Instruction
@@ -64,10 +61,6 @@
Value(const Type *Ty, ValueTy vty, const std::string &name = "");
virtual ~Value();
- /// dump - Support for debugging, callable in GDB: V->dump()
- //
- virtual void dump() const;
-
/// print - Implement operator<< on Value...
///
virtual void print(std::ostream &O) const = 0;
@@ -76,13 +69,23 @@
///
inline const Type *getType() const { return Ty; }
- // All values can potentially be named...
- inline bool hasName() const { return !Name.empty(); }
- inline const std::string &getName() const { return Name; }
-
+ /// This method sets the Value's name. The SymbolTable argument is
+ /// always ignored but provided because subclasses may wish to install
+ /// the NamedItem into a symbol table any time it is given a name.
+ /// @brief Set the NamedItem's name.
virtual void setName(const std::string &name, SymbolTable * = 0) {
Name = name;
}
+
+ /// Determine if the Value has a name or not. It is legal for
+ /// a NamedItem to have an empty name.
+ /// @brief Determine if the Value has a name.
+ inline bool hasName() const { return !Name.empty(); }
+
+ /// Obtain the name of the Value, which might be empty.
+ /// @returns the name of the Value.
+ /// @brief Get the Value's name.
+ inline const std::string &getName() const { return Name; }
/// getValueType - Return the immediate subclass of this Value.
///
@@ -129,19 +132,6 @@
void killUse(Use &U) { Uses.remove(&U); }
};
-inline std::ostream &operator<<(std::ostream &OS, const Value *V) {
- if (V == 0)
- OS << "<null> value!\n";
- else
- V->print(OS);
- return OS;
-}
-
-inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
- V.print(OS);
- return OS;
-}
-
inline User *UseListIteratorWrapper::operator*() const {
return Super::operator*().getUser();
@@ -174,9 +164,6 @@
// isa - Provide some specializations of isa so that we don't have to include
// the subtype header files to test to see if the value is a subclass...
//
-template <> inline bool isa_impl<Type, Value>(const Value &Val) {
- return Val.getValueType() == Value::TypeVal;
-}
template <> inline bool isa_impl<Constant, Value>(const Value &Val) {
return Val.getValueType() == Value::ConstantVal;
}
Index: llvm/include/llvm/AbstractTypeUser.h
diff -u llvm/include/llvm/AbstractTypeUser.h:1.19 llvm/include/llvm/AbstractTypeUser.h:1.19.4.1
--- llvm/include/llvm/AbstractTypeUser.h:1.19 Thu Feb 26 01:24:08 2004
+++ llvm/include/llvm/AbstractTypeUser.h Sun May 16 18:56:20 2004
@@ -73,10 +73,10 @@
const Type *Ty;
AbstractTypeUser * const User;
- // These functions are defined at the bottom of Type.h. See the comment there
- // for justification.
+ // These functions are defined at the top of Type.cpp.
void addUser();
void removeUser();
+
public:
// ctor - Add use to type if abstract. Note that Ty must not be null
inline PATypeHandle(const Type *ty, AbstractTypeUser *user)
@@ -128,6 +128,7 @@
};
+
/// PATypeHolder - Holder class for a potentially abstract type. This uses
/// efficient union-find techniques to handle dynamic type resolution. Unless
/// you need to do custom processing when types are resolved, you should always
@@ -146,7 +147,12 @@
~PATypeHolder() { dropRef(); }
operator const Type *() const { return get(); }
- const Type *get() const;
+ /// This implements the forwarding part of the union-find algorithm for
+ /// abstract types. Before every access to the Type*, we check to see if the
+ /// type we are pointing to is forwarding to a new type. If so, we drop our
+ /// reference to the type.
+ ///
+ const Type* get() const;
// operator-> - Allow user to dereference handle naturally...
const Type *operator->() const { return get(); }
@@ -166,9 +172,10 @@
private:
void addRef();
- void dropRef();
+ void dropRef() ;
};
} // End llvm namespace
+// vim: sw=2
#endif
Index: llvm/include/llvm/DerivedTypes.h
diff -u llvm/include/llvm/DerivedTypes.h:1.56 llvm/include/llvm/DerivedTypes.h:1.56.2.1
--- llvm/include/llvm/DerivedTypes.h:1.56 Sun Apr 4 20:25:21 2004
+++ llvm/include/llvm/DerivedTypes.h Sun May 16 18:56:20 2004
@@ -18,7 +18,7 @@
#ifndef LLVM_DERIVED_TYPES_H
#define LLVM_DERIVED_TYPES_H
-#include "llvm/Type.h"
+#include "llvm/Value.h"
namespace llvm {
@@ -35,7 +35,7 @@
mutable std::vector<AbstractTypeUser *> AbstractTypeUsers;
protected:
- DerivedType(PrimitiveID id) : Type("", id) {}
+ DerivedType(PrimitiveID id) : Type(id) {}
~DerivedType() {
assert(AbstractTypeUsers.empty());
}
@@ -88,7 +88,7 @@
///
void refineAbstractTypeTo(const Type *NewType);
- void dump() const { Value::dump(); }
+ void dump() const { Type::dump(); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const DerivedType *T) { return true; }
More information about the llvm-commits
mailing list