[llvm-commits] [parallel] CVS: llvm/include/llvm/AbstractTypeUser.h BasicBlock.h Constants.h DerivedTypes.h Function.h Instruction.h Intrinsics.h ModuleProvider.h Type.h Value.h iMemory.h iOther.h iPHINode.h iTerminators.h
Misha Brukman
brukman at cs.uiuc.edu
Mon Mar 1 17:59:10 PST 2004
Changes in directory llvm/include/llvm:
AbstractTypeUser.h updated: 1.18 -> 1.18.2.1
BasicBlock.h updated: 1.36 -> 1.36.2.1
Constants.h updated: 1.38 -> 1.38.2.1
DerivedTypes.h updated: 1.49.2.1 -> 1.49.2.2
Function.h updated: 1.49 -> 1.49.4.1
Instruction.h updated: 1.50 -> 1.50.2.1
Intrinsics.h updated: 1.15.2.1 -> 1.15.2.2
ModuleProvider.h updated: 1.8 -> 1.8.2.1
Type.h updated: 1.37 -> 1.37.4.1
Value.h updated: 1.49 -> 1.49.2.1
iMemory.h updated: 1.43 -> 1.43.4.1
iOther.h updated: 1.43 -> 1.43.4.1
iPHINode.h updated: 1.15 -> 1.15.4.1
iTerminators.h updated: 1.37.4.2 -> 1.37.4.3
---
Log message:
Merge from trunk
---
Diffs of the changes: (+403 -332)
Index: llvm/include/llvm/AbstractTypeUser.h
diff -u llvm/include/llvm/AbstractTypeUser.h:1.18 llvm/include/llvm/AbstractTypeUser.h:1.18.2.1
--- llvm/include/llvm/AbstractTypeUser.h:1.18 Tue Dec 23 17:25:21 2003
+++ llvm/include/llvm/AbstractTypeUser.h Mon Mar 1 17:57:19 2004
@@ -44,7 +44,7 @@
class AbstractTypeUser {
protected:
- virtual ~AbstractTypeUser() {} // Derive from me
+ virtual ~AbstractTypeUser(); // Derive from me
public:
/// refineAbstractType - The callback method invoked when an abstract type is
Index: llvm/include/llvm/BasicBlock.h
diff -u llvm/include/llvm/BasicBlock.h:1.36 llvm/include/llvm/BasicBlock.h:1.36.2.1
--- llvm/include/llvm/BasicBlock.h:1.36 Wed Jan 14 22:37:10 2004
+++ llvm/include/llvm/BasicBlock.h Mon Mar 1 17:57:19 2004
@@ -67,13 +67,14 @@
typedef std::reverse_iterator<iterator> reverse_iterator;
/// BasicBlock ctor - If the function parameter is specified, the basic block
- /// is automatically inserted at the end of the function.
+ /// is automatically inserted at either the end of the function (if
+ /// InsertBefore is null), or before the specified basic block.
///
- BasicBlock(const std::string &Name = "", Function *Parent = 0);
-
/// BasicBlock ctor - If the InsertBefore parameter is specified, the basic
/// block is automatically inserted right before the specified block.
- BasicBlock(const std::string &Name, BasicBlock *InsertBefore);
+ ///
+ BasicBlock(const std::string &Name = "", Function *Parent = 0,
+ BasicBlock *InsertBefore = 0);
~BasicBlock();
// Specialize setName to take care of symbol table majik
@@ -131,13 +132,6 @@
static inline bool classof(const Value *V) {
return V->getValueType() == Value::BasicBlockVal;
}
-
- /// hasConstantReferences() - This predicate is true if there is a
- /// reference to this basic block in the constant pool for this method. For
- /// example, if a block is reached through a switch table, that table resides
- /// in the constant pool, and the basic block is reference from it.
- ///
- bool hasConstantReferences() const;
/// dropAllReferences() - This function causes all the subinstructions to "let
/// go" of all references that they are maintaining. This allows one to
Index: llvm/include/llvm/Constants.h
diff -u llvm/include/llvm/Constants.h:1.38 llvm/include/llvm/Constants.h:1.38.2.1
--- llvm/include/llvm/Constants.h:1.38 Wed Jan 14 11:06:21 2004
+++ llvm/include/llvm/Constants.h Mon Mar 1 17:57:19 2004
@@ -258,7 +258,8 @@
///
class ConstantFP : public Constant {
double Val;
- friend struct ConstantCreator<ConstantFP, Type, double>;
+ friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
+ friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
protected:
ConstantFP(const Type *Ty, double V);
@@ -271,8 +272,34 @@
inline double getValue() const { return Val; }
/// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue.
- virtual bool isNullValue() const { return Val == 0; }
+ /// getNullValue. Don't depend on == for doubles to tell us it's zero, it
+ /// considers -0.0 to be null as well as 0.0. :(
+ virtual bool isNullValue() const {
+ union {
+ double V;
+ uint64_t I;
+ } T;
+ T.V = Val;
+ return T.I == 0;
+ }
+
+ /// isExactlyValue - We don't rely on operator== working on double values, as
+ /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
+ /// As such, this method can be used to do an exact bit-for-bit comparison of
+ /// two floating point values.
+ bool isExactlyValue(double V) const {
+ union {
+ double V;
+ uint64_t I;
+ } T1;
+ T1.V = Val;
+ union {
+ double V;
+ uint64_t I;
+ } T2;
+ T2.V = V;
+ return T1.I == T2.I;
+ }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantFP *) { return true; }
@@ -282,6 +309,36 @@
}
};
+//===---------------------------------------------------------------------------
+/// ConstantAggregateZero - All zero aggregate value
+///
+class ConstantAggregateZero : public Constant {
+ friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
+ ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
+protected:
+ ConstantAggregateZero(const Type *Ty) : Constant(Ty) {}
+public:
+ /// get() - static factory method for creating a null aggregate. It is
+ /// illegal to call this method with a non-aggregate type.
+ static Constant *get(const Type *Ty);
+
+ /// isNullValue - Return true if this is the value that would be returned by
+ /// getNullValue.
+ virtual bool isNullValue() const { return true; }
+
+ virtual void destroyConstant();
+ 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 ConstantAggregateZero *) { return true; }
+ static bool classof(const Constant *CPV);
+ static inline bool classof(const Value *V) {
+ return isa<Constant>(V) && classof(cast<Constant>(V));
+ }
+};
+
//===---------------------------------------------------------------------------
/// ConstantArray - Constant Array Declarations
@@ -294,8 +351,8 @@
ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
public:
/// get() - Static factory methods - Return objects of the specified value
- static ConstantArray *get(const ArrayType *T, const std::vector<Constant*> &);
- static ConstantArray *get(const std::string &Initializer);
+ static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
+ static Constant *get(const std::string &Initializer);
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
@@ -318,19 +375,9 @@
inline const std::vector<Use> &getValues() const { return Operands; }
/// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue.
- virtual bool isNullValue() const {
- // FIXME: This should be made to be MUCH faster. Just check against well
- // known null value!
- if (getNumOperands()) {
- const Constant *First = cast<Constant>(getOperand(0));
- if (!First->isNullValue()) return false;
- for (unsigned i = 1, e = getNumOperands(); i != e; ++i)
- if (cast<Constant>(getOperand(i)) != First)
- return false;
- }
- return true;
- }
+ /// getNullValue. This always returns false because zero arrays are always
+ /// created as ConstantAggregateZero objects.
+ virtual bool isNullValue() const { return false; }
virtual void destroyConstant();
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
@@ -356,8 +403,7 @@
ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
public:
/// get() - Static factory methods - Return objects of the specified value
- static ConstantStruct *get(const StructType *T,
- const std::vector<Constant*> &V);
+ static Constant *get(const StructType *T, const std::vector<Constant*> &V);
/// getType() specialization - Reduce amount of casting...
inline const StructType *getType() const {
@@ -369,14 +415,10 @@
inline const std::vector<Use> &getValues() const { return Operands; }
/// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue.
+ /// getNullValue. This always returns false because zero structs are always
+ /// created as ConstantAggregateZero objects.
virtual bool isNullValue() const {
- // FIXME: This should be made to be MUCH faster. Just check against well
- // known null value!
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (!cast<Constant>(getOperand(i))->isNullValue())
- return false;
- return true;
+ return false;
}
virtual void destroyConstant();
Index: llvm/include/llvm/DerivedTypes.h
diff -u llvm/include/llvm/DerivedTypes.h:1.49.2.1 llvm/include/llvm/DerivedTypes.h:1.49.2.2
--- llvm/include/llvm/DerivedTypes.h:1.49.2.1 Fri Feb 6 12:40:35 2004
+++ llvm/include/llvm/DerivedTypes.h Mon Mar 1 17:57:19 2004
@@ -19,7 +19,6 @@
#define LLVM_DERIVED_TYPES_H
#include "llvm/Type.h"
-#include <vector>
namespace llvm {
@@ -30,20 +29,13 @@
class PointerValType;
class DerivedType : public Type, public AbstractTypeUser {
- /// RefCount - This counts the number of PATypeHolders that are pointing to
- /// this type. When this number falls to zero, if the type is abstract and
- /// has no AbstractTypeUsers, the type is deleted.
- ///
- mutable unsigned RefCount;
-
// AbstractTypeUsers - Implement a list of the users that need to be notified
// if I am a type, and I get resolved into a more concrete type.
//
- ///// FIXME: kill mutable nonsense when Types are not const
mutable std::vector<AbstractTypeUser *> AbstractTypeUsers;
protected:
- DerivedType(PrimitiveID id) : Type("", id), RefCount(0) {}
+ DerivedType(PrimitiveID id) : Type("", id) {}
~DerivedType() {
assert(AbstractTypeUsers.empty());
}
@@ -54,10 +46,17 @@
///
void notifyUsesThatTypeBecameConcrete();
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses() = 0;
+ /// dropAllTypeUses - When this (abstract) type is resolved to be equal to
+ /// another (more concrete) type, we must eliminate all references to other
+ /// types, to avoid some circular reference problems.
+ ///
+ void dropAllTypeUses();
+
+ void RefCountIsZero() const {
+ if (AbstractTypeUsers.empty())
+ delete this;
+ }
+
public:
@@ -66,45 +65,29 @@
// are managed by (add|remove)AbstractTypeUser. See comments in
// AbstractTypeUser.h for more information.
- // addAbstractTypeUser - Notify an abstract type that there is a new user of
- // it. This function is called primarily by the PATypeHandle class.
- //
+ /// addAbstractTypeUser - Notify an abstract type that there is a new user of
+ /// it. This function is called primarily by the PATypeHandle class.
+ ///
void addAbstractTypeUser(AbstractTypeUser *U) const {
assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
AbstractTypeUsers.push_back(U);
}
- // removeAbstractTypeUser - Notify an abstract type that a user of the class
- // no longer has a handle to the type. This function is called primarily by
- // the PATypeHandle class. When there are no users of the abstract type, it
- // is annihilated, because there is no way to get a reference to it ever
- // again.
- //
+ /// removeAbstractTypeUser - Notify an abstract type that a user of the class
+ /// no longer has a handle to the type. This function is called primarily by
+ /// the PATypeHandle class. When there are no users of the abstract type, it
+ /// is annihilated, because there is no way to get a reference to it ever
+ /// again.
+ ///
void removeAbstractTypeUser(AbstractTypeUser *U) const;
- // refineAbstractTypeTo - This function is used to when it is discovered that
- // the 'this' abstract type is actually equivalent to the NewType specified.
- // This causes all users of 'this' to switch to reference the more concrete
- // type NewType and for 'this' to be deleted.
- //
+ /// refineAbstractTypeTo - This function is used to when it is discovered that
+ /// the 'this' abstract type is actually equivalent to the NewType specified.
+ /// This causes all users of 'this' to switch to reference the more concrete
+ /// type NewType and for 'this' to be deleted.
+ ///
void refineAbstractTypeTo(const Type *NewType);
- void addRef() const {
- assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
- ++RefCount;
- }
-
- void dropRef() const {
- assert(isAbstract() && "Cannot drop a refernce to a non-abstract type!");
- assert(RefCount && "No objects are currently referencing this object!");
-
- // If this is the last PATypeHolder using this object, and there are no
- // PATypeHandles using it, the type is dead, delete it now.
- if (--RefCount == 0 && AbstractTypeUsers.empty())
- delete this;
- }
-
-
void dump() const { Value::dump(); }
// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -118,56 +101,46 @@
};
-
-
-struct FunctionType : public DerivedType {
- typedef std::vector<PATypeHandle> ParamTypes;
+/// FunctionType - Class to represent function types
+///
+class FunctionType : public DerivedType {
friend class TypeMap<FunctionValType, FunctionType>;
-private:
- PATypeHandle ResultType;
- ParamTypes ParamTys;
bool isVarArgs;
FunctionType(const FunctionType &); // Do not implement
const FunctionType &operator=(const FunctionType &); // Do not implement
protected:
- // This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class FunctionType' only
- // defines private constructors and has no friends
-
- // Private ctor - Only can be created by a static member...
+ /// This should really be private, but it squelches a bogus warning
+ /// from GCC to make them protected: warning: `class FunctionType' only
+ /// defines private constructors and has no friends
+ ///
+ /// Private ctor - Only can be created by a static member...
+ ///
FunctionType(const Type *Result, const std::vector<const Type*> &Params,
bool IsVarArgs);
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses();
-
public:
/// FunctionType::get - This static method is the primary way of constructing
/// a FunctionType
+ ///
static FunctionType *get(const Type *Result,
const std::vector<const Type*> &Params,
bool isVarArg);
inline bool isVarArg() const { return isVarArgs; }
- inline const Type *getReturnType() const { return ResultType; }
- inline const ParamTypes &getParamTypes() const { return ParamTys; }
+ inline const Type *getReturnType() const { return ContainedTys[0]; }
- // Parameter type accessors...
- const Type *getParamType(unsigned i) const { return ParamTys[i]; }
-
- // getNumParams - Return the number of fixed parameters this function type
- // requires. This does not consider varargs.
- //
- unsigned getNumParams() const { return ParamTys.size(); }
+ typedef std::vector<PATypeHandle>::const_iterator param_iterator;
+ param_iterator param_begin() const { return ContainedTys.begin()+1; }
+ param_iterator param_end() const { return ContainedTys.end(); }
+ // Parameter type accessors...
+ const Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
- virtual const Type *getContainedType(unsigned i) const {
- return i == 0 ? ResultType.get() : ParamTys[i-1].get();
- }
- virtual unsigned getNumContainedTypes() const { return ParamTys.size()+1; }
+ /// getNumParams - Return the number of fixed parameters this function type
+ /// requires. This does not consider varargs.
+ ///
+ unsigned getNumParams() const { return ContainedTys.size()-1; }
// Implement the AbstractTypeUser interface.
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
@@ -184,16 +157,16 @@
};
-// CompositeType - Common super class of ArrayType, StructType, and PointerType
-//
+/// CompositeType - Common super class of ArrayType, StructType, and PointerType
+///
class CompositeType : public DerivedType {
protected:
inline CompositeType(PrimitiveID id) : DerivedType(id) { }
public:
- // getTypeAtIndex - Given an index value into the type, return the type of the
- // element.
- //
+ /// getTypeAtIndex - Given an index value into the type, return the type of
+ /// the element.
+ ///
virtual const Type *getTypeAtIndex(const Value *V) const = 0;
virtual bool indexValid(const Value *V) const = 0;
@@ -210,44 +183,43 @@
};
-struct StructType : public CompositeType {
+/// StructType - Class to represent struct types
+///
+class StructType : public CompositeType {
friend class TypeMap<StructValType, StructType>;
- typedef std::vector<PATypeHandle> ElementTypes;
-
-private:
- ElementTypes ETypes; // Element types of struct
-
StructType(const StructType &); // Do not implement
const StructType &operator=(const StructType &); // Do not implement
protected:
- // This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class StructType' only
- // defines private constructors and has no friends
-
- // Private ctor - Only can be created by a static member...
+ /// This should really be private, but it squelches a bogus warning
+ /// from GCC to make them protected: warning: `class StructType' only
+ /// defines private constructors and has no friends
+ ///
+ /// Private ctor - Only can be created by a static member...
+ ///
StructType(const std::vector<const Type*> &Types);
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses();
-
public:
/// StructType::get - This static method is the primary way to create a
/// StructType.
+ ///
static StructType *get(const std::vector<const Type*> &Params);
- inline const ElementTypes &getElementTypes() const { return ETypes; }
-
- virtual const Type *getContainedType(unsigned i) const {
- return ETypes[i].get();
+ // Iterator access to the elements
+ typedef std::vector<PATypeHandle>::const_iterator element_iterator;
+ element_iterator element_begin() const { return ContainedTys.begin(); }
+ element_iterator element_end() const { return ContainedTys.end(); }
+
+ // Random access to the elements
+ unsigned getNumElements() const { return ContainedTys.size(); }
+ const Type *getElementType(unsigned N) const {
+ assert(N < ContainedTys.size() && "Element number out of range!");
+ return ContainedTys[N];
}
- virtual unsigned getNumContainedTypes() const { return ETypes.size(); }
- // getTypeAtIndex - Given an index value into the type, return the type of the
- // element. For a structure type, this must be a constant value...
- //
+ /// getTypeAtIndex - Given an index value into the type, return the type of
+ /// the element. For a structure type, this must be a constant value...
+ ///
virtual const Type *getTypeAtIndex(const Value *V) const ;
virtual bool indexValid(const Value *V) const;
@@ -266,35 +238,29 @@
};
-// SequentialType - This is the superclass of the array and pointer type
-// classes. Both of these represent "arrays" in memory. The array type
-// represents a specifically sized array, pointer types are unsized/unknown size
-// arrays. SequentialType holds the common features of both, which stem from
-// the fact that both lay their components out in memory identically.
-//
+/// SequentialType - This is the superclass of the array and pointer type
+/// classes. Both of these represent "arrays" in memory. The array type
+/// represents a specifically sized array, pointer types are unsized/unknown
+/// size arrays. SequentialType holds the common features of both, which stem
+/// from the fact that both lay their components out in memory identically.
+///
class SequentialType : public CompositeType {
SequentialType(const SequentialType &); // Do not implement!
const SequentialType &operator=(const SequentialType &); // Do not implement!
protected:
- PATypeHandle ElementType;
-
- SequentialType(PrimitiveID TID, const Type *ElType)
- : CompositeType(TID), ElementType(PATypeHandle(ElType, this)) {
+ SequentialType(PrimitiveID TID, const Type *ElType) : CompositeType(TID) {
+ ContainedTys.reserve(1);
+ ContainedTys.push_back(PATypeHandle(ElType, this));
}
public:
- inline const Type *getElementType() const { return ElementType; }
+ inline const Type *getElementType() const { return ContainedTys[0]; }
- virtual const Type *getContainedType(unsigned i) const {
- return ElementType.get();
- }
- virtual unsigned getNumContainedTypes() const { return 1; }
-
- // getTypeAtIndex - Given an index value into the type, return the type of the
- // element. For sequential types, there is only one subtype...
- //
+ /// getTypeAtIndex - Given an index value into the type, return the type of
+ /// the element. For sequential types, there is only one subtype...
+ ///
virtual const Type *getTypeAtIndex(const Value *V) const {
- return ElementType.get();
+ return ContainedTys[0];
}
virtual bool indexValid(const Value *V) const {
return V->getType()->isInteger();
@@ -312,6 +278,8 @@
};
+/// ArrayType - Class to represent array types
+///
class ArrayType : public SequentialType {
friend class TypeMap<ArrayValType, ArrayType>;
unsigned NumElements;
@@ -319,21 +287,18 @@
ArrayType(const ArrayType &); // Do not implement
const ArrayType &operator=(const ArrayType &); // Do not implement
protected:
- // This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class ArrayType' only
- // defines private constructors and has no friends
-
- // Private ctor - Only can be created by a static member...
+ /// This should really be private, but it squelches a bogus warning
+ /// from GCC to make them protected: warning: `class ArrayType' only
+ /// defines private constructors and has no friends
+ ///
+ /// Private ctor - Only can be created by a static member...
+ ///
ArrayType(const Type *ElType, unsigned NumEl);
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses();
-
public:
/// ArrayType::get - This static method is the primary way to construct an
/// ArrayType
+ ///
static ArrayType *get(const Type *ElementType, unsigned NumElements);
inline unsigned getNumElements() const { return NumElements; }
@@ -353,7 +318,8 @@
};
-
+/// PointerType - Class to represent pointers
+///
class PointerType : public SequentialType {
friend class TypeMap<PointerValType, PointerType>;
PointerType(const PointerType &); // Do not implement
@@ -366,10 +332,6 @@
// Private ctor - Only can be created by a static member...
PointerType(const Type *ElType);
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses();
public:
/// PointerType::get - This is the only way to construct a new pointer type.
static PointerType *get(const Type *ElementType);
@@ -389,26 +351,22 @@
};
+/// OpaqueType - Class to represent abstract types
+///
class OpaqueType : public DerivedType {
OpaqueType(const OpaqueType &); // DO NOT IMPLEMENT
const OpaqueType &operator=(const OpaqueType &); // DO NOT IMPLEMENT
protected:
- // This should really be private, but it squelches a bogus warning
- // from GCC to make them protected: warning: `class OpaqueType' only
- // defines private constructors and has no friends
-
- // Private ctor - Only can be created by a static member...
+ /// This should really be private, but it squelches a bogus warning
+ /// from GCC to make them protected: warning: `class OpaqueType' only
+ /// defines private constructors and has no friends
+ ///
+ /// Private ctor - Only can be created by a static member...
OpaqueType();
- // dropAllTypeUses - When this (abstract) type is resolved to be equal to
- // another (more concrete) type, we must eliminate all references to other
- // types, to avoid some circular reference problems.
- virtual void dropAllTypeUses() {
- // FIXME: THIS IS NOT AN ABSTRACT TYPE USER!
- } // No type uses
-
public:
- // OpaqueType::get - Static factory method for the OpaqueType class...
+ /// OpaqueType::get - Static factory method for the OpaqueType class...
+ ///
static OpaqueType *get() {
return new OpaqueType(); // All opaque types are distinct
}
@@ -430,50 +388,6 @@
return isa<Type>(V) && classof(cast<Type>(V));
}
};
-
-
-// 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.
-//
-inline void PATypeHandle::addUser() {
- assert(Ty && "Type Handle has a null type!");
- if (Ty->isAbstract())
- cast<DerivedType>(Ty)->addAbstractTypeUser(User);
-}
-inline void PATypeHandle::removeUser() {
- if (Ty->isAbstract())
- cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
-}
-
-inline void PATypeHandle::removeUserFromConcrete() {
- if (!Ty->isAbstract())
- cast<DerivedType>(Ty)->removeAbstractTypeUser(User);
-}
-
-// Define inline methods for PATypeHolder...
-
-inline void PATypeHolder::addRef() {
- if (Ty->isAbstract())
- cast<DerivedType>(Ty)->addRef();
-}
-
-inline void PATypeHolder::dropRef() {
- if (Ty->isAbstract())
- cast<DerivedType>(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;
-}
} // End llvm namespace
Index: llvm/include/llvm/Function.h
diff -u llvm/include/llvm/Function.h:1.49 llvm/include/llvm/Function.h:1.49.4.1
--- llvm/include/llvm/Function.h:1.49 Tue Nov 11 16:41:29 2003
+++ llvm/include/llvm/Function.h Mon Mar 1 17:57:19 2004
@@ -21,6 +21,7 @@
#include "llvm/GlobalValue.h"
#include "llvm/BasicBlock.h"
#include "llvm/Argument.h"
+#include "Support/Annotation.h"
namespace llvm {
@@ -44,7 +45,7 @@
static iplist<Argument> &getList(Function *F);
};
-class Function : public GlobalValue {
+class Function : public GlobalValue, public Annotable {
public:
typedef iplist<Argument> ArgumentListType;
typedef iplist<BasicBlock> BasicBlockListType;
@@ -61,7 +62,6 @@
typedef std::reverse_iterator<aiterator> reverse_aiterator;
private:
-
// Important things that make up a function!
BasicBlockListType BasicBlocks; // The basic blocks
ArgumentListType ArgumentList; // The formal arguments
@@ -90,8 +90,8 @@
const Type *getReturnType() const; // Return the type of the ret val
const FunctionType *getFunctionType() const; // Return the FunctionType for me
- /// isExternal - Is the body of this function unknown? (the basic block list
- /// is empty if so) this is true for external functions, defined as forward
+ /// isExternal - Is the body of this function unknown? (The basic block list
+ /// is empty if so.) This is true for external functions, defined as forward
/// "declare"ations
///
virtual bool isExternal() const { return BasicBlocks.empty(); }
@@ -108,6 +108,7 @@
/// deleteBody - This method deletes the body of the function, and converts
/// the linkage to external.
+ ///
void deleteBody() {
dropAllReferences();
setLinkage(ExternalLinkage);
@@ -196,8 +197,8 @@
/// viewCFGOnly - This function is meant for use from the debugger. It works
/// just like viewCFG, but it does not include the contents of basic blocks
- /// into the nodes, just the label. If you are only interested in the CFG t
- /// his can make the graph smaller.
+ /// into the nodes, just the label. If you are only interested in the CFG
+ /// this can make the graph smaller.
///
void viewCFGOnly() const;
@@ -211,7 +212,7 @@
/// go" of all references that they are maintaining. This allows one to
/// 'delete' a whole module at a time, even though there may be circular
/// references... first all references are dropped, and all use counts go to
- /// zero. Then everything is delete'd for real. Note that no operations are
+ /// zero. Then everything is deleted for real. Note that no operations are
/// valid on an object that has "dropped all references", except operator
/// delete.
///
Index: llvm/include/llvm/Instruction.h
diff -u llvm/include/llvm/Instruction.h:1.50 llvm/include/llvm/Instruction.h:1.50.2.1
--- llvm/include/llvm/Instruction.h:1.50 Mon Jan 12 17:18:06 2004
+++ llvm/include/llvm/Instruction.h Mon Mar 1 17:57:19 2004
@@ -16,6 +16,7 @@
#define LLVM_INSTRUCTION_H
#include "llvm/User.h"
+#include "Support/Annotation.h"
namespace llvm {
@@ -25,7 +26,7 @@
template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
typename SubClass> class SymbolTableListTraits;
-class Instruction : public User {
+class Instruction : public User, public Annotable {
BasicBlock *Parent;
Instruction *Prev, *Next; // Next and Prev links for our intrusive linked list
Index: llvm/include/llvm/Intrinsics.h
diff -u llvm/include/llvm/Intrinsics.h:1.15.2.1 llvm/include/llvm/Intrinsics.h:1.15.2.2
--- llvm/include/llvm/Intrinsics.h:1.15.2.1 Mon Feb 2 16:32:05 2004
+++ llvm/include/llvm/Intrinsics.h Mon Mar 1 17:57:19 2004
@@ -31,6 +31,15 @@
va_end, // Used to implement the va_end macro in C
va_copy, // Used to implement the va_copy macro in C
+ // Code generator intrinsics...
+ returnaddress, // Yields the return address of a dynamic call frame
+ frameaddress, // Yields the frame address of a dynamic call frame
+
+ // Standard libc functions...
+ memcpy, // Copy non-overlapping memory blocks
+ memmove, // Copy potentially overlapping memory blocks
+ memset, // Fill memory with a byte value
+
// Setjmp/Longjmp intrinsics...
setjmp, // Used to represent a setjmp call in C
longjmp, // Used to represent a longjmp call in C
@@ -47,6 +56,8 @@
// Parallelism/atomicity/synchronization intrinsics...
join,
+ // Standard libm functions...
+
//===------------------------------------------------------------------===//
// This section defines intrinsic functions used to represent Alpha
// instructions...
Index: llvm/include/llvm/ModuleProvider.h
diff -u llvm/include/llvm/ModuleProvider.h:1.8 llvm/include/llvm/ModuleProvider.h:1.8.2.1
--- llvm/include/llvm/ModuleProvider.h:1.8 Mon Dec 29 20:44:04 2003
+++ llvm/include/llvm/ModuleProvider.h Mon Mar 1 17:57:19 2004
@@ -35,15 +35,18 @@
///
Module* getModule() { return TheModule; }
- /// materializeFunction - make sure the given function is fully read.
+ /// materializeFunction - make sure the given function is fully read. Note
+ /// that this can throw an exception if the module is corrupt!
///
virtual void materializeFunction(Function *F) = 0;
/// materializeModule - make sure the entire Module has been completely read.
+ /// Note that this can throw an exception if the module is corrupt!
///
- Module* materializeModule();
+ virtual Module* materializeModule() = 0;
/// releaseModule - no longer delete the Module* when provider is destroyed.
+ /// Note that this can throw an exception if the module is corrupt!
///
virtual Module* releaseModule() {
// Since we're losing control of this Module, we must hand it back complete
@@ -64,6 +67,7 @@
TheModule = M;
}
void materializeFunction(Function *F) {}
+ Module* materializeModule() { return TheModule; }
};
} // End llvm namespace
Index: llvm/include/llvm/Type.h
diff -u llvm/include/llvm/Type.h:1.37 llvm/include/llvm/Type.h:1.37.4.1
--- llvm/include/llvm/Type.h:1.37 Tue Nov 11 16:41:30 2003
+++ llvm/include/llvm/Type.h Mon Mar 1 17:57:19 2004
@@ -36,6 +36,7 @@
#include "llvm/Value.h"
#include "Support/GraphTraits.h"
#include "Support/iterator"
+#include <vector>
namespace llvm {
@@ -82,6 +83,13 @@
unsigned UID; // The unique ID number for this class
bool Abstract; // True if type contains an OpaqueType
+ /// RefCount - This counts the number of PATypeHolders that are pointing to
+ /// this type. When this number falls to zero, if the type is abstract and
+ /// has no AbstractTypeUsers, the type is deleted. This is only sensical for
+ /// derived types.
+ ///
+ mutable unsigned RefCount;
+
const Type *getForwardedTypeInternal() const;
protected:
/// ctor is protected, so only subclasses can create Type objects...
@@ -101,11 +109,22 @@
///
bool isTypeAbstract();
+ unsigned getRefCount() const { return RefCount; }
+
/// ForwardType - This field is used to implement the union find scheme for
/// abstract types. When types are refined to other types, this field is set
/// to the more refined type. Only abstract types can be forwarded.
mutable const Type *ForwardType;
+ /// ContainedTys - The list of types contained by this one. For example, this
+ /// includes the arguments of a function type, the elements of the structure,
+ /// the pointee of a pointer, etc. Note that keeping this vector in the Type
+ /// class wastes some space for types that do not contain anything (such as
+ /// primitive types). However, keeping it here allows the subtype_* members
+ /// to be implemented MUCH more efficiently, and dynamically very few types do
+ /// not contain any elements (most are derived).
+ std::vector<PATypeHandle> ContainedTys;
+
public:
virtual void print(std::ostream &O) const;
@@ -132,7 +151,7 @@
/// isSigned - Return whether an integral numeric type is signed. This is
/// true for SByteTy, ShortTy, IntTy, LongTy. Note that this is not true for
/// Float and Double.
- //
+ ///
virtual bool isSigned() const { return 0; }
/// isUnsigned - Return whether a numeric type is unsigned. This is not quite
@@ -204,22 +223,22 @@
//===--------------------------------------------------------------------===//
// Type Iteration support
//
- class TypeIterator;
- typedef TypeIterator subtype_iterator;
- inline subtype_iterator subtype_begin() const; // DEFINED BELOW
- inline subtype_iterator subtype_end() const; // DEFINED BELOW
+ typedef std::vector<PATypeHandle>::const_iterator subtype_iterator;
+ subtype_iterator subtype_begin() const { return ContainedTys.begin(); }
+ subtype_iterator subtype_end() const { return ContainedTys.end(); }
/// getContainedType - This method is used to implement the type iterator
/// (defined a the end of the file). For derived types, this returns the
/// types 'contained' in the derived type.
///
- virtual const Type *getContainedType(unsigned i) const {
- assert(0 && "No contained types!");
- return 0;
+ const Type *getContainedType(unsigned i) const {
+ assert(i < ContainedTys.size() && "Index out of range!");
+ return ContainedTys[i];
}
- /// getNumContainedTypes - Return the number of types in the derived type
- virtual unsigned getNumContainedTypes() const { return 0; }
+ /// getNumContainedTypes - Return the number of types in the derived type.
+ ///
+ unsigned getNumContainedTypes() const { return ContainedTys.size(); }
//===--------------------------------------------------------------------===//
// Static members exported by the Type class itself. Useful for getting
@@ -250,49 +269,88 @@
#include "llvm/Type.def"
+ // Virtual methods used by callbacks below. These should only be implemented
+ // in the DerivedType class.
+ virtual void addAbstractTypeUser(AbstractTypeUser *U) const {
+ abort(); // Only on derived types!
+ }
+ virtual void removeAbstractTypeUser(AbstractTypeUser *U) const {
+ abort(); // Only on derived types!
+ }
+
+ void addRef() const {
+ assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
+ ++RefCount;
+ }
+
+ void dropRef() const {
+ assert(isAbstract() && "Cannot drop a refernce to a non-abstract type!");
+ assert(RefCount && "No objects are currently referencing this object!");
+
+ // If this is the last PATypeHolder using this object, and there are no
+ // PATypeHandles using it, the type is dead, delete it now.
+ if (--RefCount == 0)
+ RefCountIsZero();
+ }
private:
- class TypeIterator : public bidirectional_iterator<const Type, ptrdiff_t> {
- const Type * const Ty;
- unsigned Idx;
-
- typedef TypeIterator _Self;
- public:
- TypeIterator(const Type *ty, unsigned idx) : Ty(ty), Idx(idx) {}
- ~TypeIterator() {}
-
- const _Self &operator=(const _Self &RHS) {
- assert(Ty == RHS.Ty && "Cannot assign from different types!");
- Idx = RHS.Idx;
- return *this;
- }
-
- bool operator==(const _Self& x) const { return Idx == x.Idx; }
- bool operator!=(const _Self& x) const { return !operator==(x); }
-
- pointer operator*() const { return Ty->getContainedType(Idx); }
- pointer operator->() const { return operator*(); }
-
- _Self& operator++() { ++Idx; return *this; } // Preincrement
- _Self operator++(int) { // Postincrement
- _Self tmp = *this; ++*this; return tmp;
- }
-
- _Self& operator--() { --Idx; return *this; } // Predecrement
- _Self operator--(int) { // Postdecrement
- _Self tmp = *this; --*this; return tmp;
- }
- };
+ virtual void RefCountIsZero() const {
+ abort(); // only on derived types!
+ }
+
};
-inline Type::TypeIterator Type::subtype_begin() const {
- return TypeIterator(this, 0);
+//===----------------------------------------------------------------------===//
+// 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);
}
-inline Type::TypeIterator Type::subtype_end() const {
- return TypeIterator(this, getNumContainedTypes());
+// 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;
+}
+
+
+//===----------------------------------------------------------------------===//
// Provide specializations of GraphTraits to be able to treat a type as a
// graph of sub types...
Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.49 llvm/include/llvm/Value.h:1.49.2.1
--- llvm/include/llvm/Value.h:1.49 Sat Jan 10 15:40:29 2004
+++ llvm/include/llvm/Value.h Mon Mar 1 17:57:19 2004
@@ -19,7 +19,6 @@
#include "llvm/AbstractTypeUser.h"
#include "llvm/Use.h"
-#include "Support/Annotation.h"
#include "Support/Casting.h"
#include <iostream>
@@ -42,7 +41,7 @@
/// Value - The base class of all values computed by a program that may be used
/// as operands to other values.
///
-struct Value : public Annotable { // Values are annotable
+struct Value {
enum ValueTy {
TypeVal, // This is an instance of Type
ConstantVal, // This is an instance of Constant
Index: llvm/include/llvm/iMemory.h
diff -u llvm/include/llvm/iMemory.h:1.43 llvm/include/llvm/iMemory.h:1.43.4.1
--- llvm/include/llvm/iMemory.h:1.43 Sun Nov 16 14:21:15 2003
+++ llvm/include/llvm/iMemory.h Mon Mar 1 17:57:19 2004
@@ -24,35 +24,36 @@
//===----------------------------------------------------------------------===//
// AllocationInst Class
//===----------------------------------------------------------------------===//
-//
-// AllocationInst - This class is the common base class of MallocInst and
-// AllocaInst.
-//
+
+/// AllocationInst - This class is the common base class of MallocInst and
+/// AllocaInst.
+///
class AllocationInst : public Instruction {
protected:
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
const std::string &Name = "", Instruction *InsertBefore = 0);
public:
- // isArrayAllocation - Return true if there is an allocation size parameter
- // to the allocation instruction that is not 1.
- //
+ /// isArrayAllocation - Return true if there is an allocation size parameter
+ /// to the allocation instruction that is not 1.
+ ///
bool isArrayAllocation() const;
- // getArraySize - Get the number of element allocated, for a simple allocation
- // of a single element, this will return a constant 1 value.
- //
+ /// getArraySize - Get the number of element allocated, for a simple
+ /// allocation of a single element, this will return a constant 1 value.
+ ///
inline const Value *getArraySize() const { return Operands[0]; }
inline Value *getArraySize() { return Operands[0]; }
- // getType - Overload to return most specific pointer type...
+ /// getType - Overload to return most specific pointer type
+ ///
inline const PointerType *getType() const {
return reinterpret_cast<const PointerType*>(Instruction::getType());
}
- // getAllocatedType - Return the type that is being allocated by the
- // instruction.
- //
+ /// getAllocatedType - Return the type that is being allocated by the
+ /// instruction.
+ ///
const Type *getAllocatedType() const;
virtual Instruction *clone() const = 0;
@@ -73,6 +74,8 @@
// MallocInst Class
//===----------------------------------------------------------------------===//
+/// MallocInst - an instruction to allocated memory on the heap
+///
class MallocInst : public AllocationInst {
MallocInst(const MallocInst &MI);
public:
@@ -99,6 +102,8 @@
// AllocaInst Class
//===----------------------------------------------------------------------===//
+/// AllocaInst - an instruction to allocate memory on the stack
+///
class AllocaInst : public AllocationInst {
AllocaInst(const AllocaInst &);
public:
@@ -125,6 +130,8 @@
// FreeInst Class
//===----------------------------------------------------------------------===//
+/// FreeInst - an instruction to deallocate memory
+///
struct FreeInst : public Instruction {
FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
@@ -147,6 +154,8 @@
// LoadInst Class
//===----------------------------------------------------------------------===//
+/// LoadInst - an instruction for reading from memory
+///
class LoadInst : public Instruction {
LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) {
Volatile = LI.isVolatile();
@@ -161,6 +170,7 @@
/// isVolatile - Return true if this is a load from a volatile memory
/// location.
+ ///
bool isVolatile() const { return Volatile; }
/// setVolatile - Specify whether this is a volatile load or not.
@@ -190,6 +200,8 @@
// StoreInst Class
//===----------------------------------------------------------------------===//
+/// StoreInst - an instruction for storing to memory
+///
class StoreInst : public Instruction {
StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store) {
Volatile = SI.isVolatile();
@@ -206,6 +218,7 @@
/// isVolatile - Return true if this is a load from a volatile memory
/// location.
+ ///
bool isVolatile() const { return Volatile; }
/// setVolatile - Specify whether this is a volatile load or not.
@@ -235,6 +248,9 @@
// GetElementPtrInst Class
//===----------------------------------------------------------------------===//
+/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
+/// access elements of arrays and structs
+///
class GetElementPtrInst : public Instruction {
GetElementPtrInst(const GetElementPtrInst &EPI)
: Instruction(reinterpret_cast<const Type*>(EPI.getType()), GetElementPtr) {
@@ -262,12 +278,8 @@
const std::vector<Value*> &Indices,
bool AllowStructLeaf = false);
- inline op_iterator idx_begin() {
- return op_begin()+1;
- }
- inline const_op_iterator idx_begin() const {
- return op_begin()+1;
- }
+ inline op_iterator idx_begin() { return op_begin()+1; }
+ inline const_op_iterator idx_begin() const { return op_begin()+1; }
inline op_iterator idx_end() { return op_end(); }
inline const_op_iterator idx_end() const { return op_end(); }
Index: llvm/include/llvm/iOther.h
diff -u llvm/include/llvm/iOther.h:1.43 llvm/include/llvm/iOther.h:1.43.4.1
--- llvm/include/llvm/iOther.h:1.43 Sun Dec 7 23:29:33 2003
+++ llvm/include/llvm/iOther.h Mon Mar 1 17:57:19 2004
@@ -56,6 +56,9 @@
// CallInst Class
//===----------------------------------------------------------------------===//
+/// CallInst - This class represents a function call, abstracting a target
+/// machine's calling convention.
+///
class CallInst : public Instruction {
CallInst(const CallInst &CI);
public:
@@ -63,10 +66,10 @@
const std::string &Name = "", Instruction *InsertBefore = 0);
// Alternate CallInst ctors w/ no actuals & one actual, respectively.
- CallInst(Value *F, const std::string &Name = "",
- Instruction *InsertBefore = 0);
+ CallInst(Value *F, const std::string &Name = "",
+ Instruction *InsertBefore = 0);
CallInst(Value *F, Value *Actual, const std::string& Name = "",
- Instruction* InsertBefore = 0);
+ Instruction *InsertBefore = 0);
virtual Instruction *clone() const { return new CallInst(*this); }
bool mayWriteToMemory() const { return true; }
@@ -95,8 +98,8 @@
// ShiftInst Class
//===----------------------------------------------------------------------===//
-// ShiftInst - This class represents left and right shift instructions.
-//
+/// ShiftInst - This class represents left and right shift instructions.
+///
class ShiftInst : public Instruction {
ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
Operands.reserve(2);
Index: llvm/include/llvm/iPHINode.h
diff -u llvm/include/llvm/iPHINode.h:1.15 llvm/include/llvm/iPHINode.h:1.15.4.1
--- llvm/include/llvm/iPHINode.h:1.15 Sun Nov 16 14:21:15 2003
+++ llvm/include/llvm/iPHINode.h Mon Mar 1 17:57:19 2004
@@ -38,11 +38,12 @@
virtual Instruction *clone() const { return new PHINode(*this); }
- /// getNumIncomingValues - Return the number of incoming edges the PHI node
- /// has
+ /// getNumIncomingValues - Return the number of incoming edges
+ ///
unsigned getNumIncomingValues() const { return Operands.size()/2; }
/// getIncomingValue - Return incoming value #x
+ ///
Value *getIncomingValue(unsigned i) const {
assert(i*2 < Operands.size() && "Invalid value number!");
return Operands[i*2];
@@ -56,6 +57,7 @@
}
/// getIncomingBlock - Return incoming basic block #x
+ ///
BasicBlock *getIncomingBlock(unsigned i) const {
assert(i*2+1 < Operands.size() && "Invalid value number!");
return reinterpret_cast<BasicBlock*>(Operands[i*2+1].get());
@@ -69,6 +71,7 @@
}
/// addIncoming - Add an incoming value to the end of the PHI list
+ ///
void addIncoming(Value *D, BasicBlock *BB) {
assert(getType() == D->getType() &&
"All operands to PHI node must be the same type as the PHI node!");
Index: llvm/include/llvm/iTerminators.h
diff -u llvm/include/llvm/iTerminators.h:1.37.4.2 llvm/include/llvm/iTerminators.h:1.37.4.3
--- llvm/include/llvm/iTerminators.h:1.37.4.2 Sat Feb 7 17:53:57 2004
+++ llvm/include/llvm/iTerminators.h Mon Mar 1 17:57:19 2004
@@ -21,9 +21,9 @@
namespace llvm {
//===---------------------------------------------------------------------------
-// ReturnInst - Return a value (possibly void), from a function. Execution does
-// not continue in this function any longer.
-//
+/// ReturnInst - Return a value (possibly void), from a function. Execution
+/// does not continue in this function any longer.
+///
class ReturnInst : public TerminatorInst {
ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret) {
if (RI.Operands.size()) {
@@ -83,8 +83,8 @@
};
//===---------------------------------------------------------------------------
-// BranchInst - Conditional or Unconditional Branch instruction.
-//
+/// BranchInst - Conditional or Unconditional Branch instruction.
+///
class BranchInst : public TerminatorInst {
BranchInst(const BranchInst &BI);
public:
@@ -190,8 +190,8 @@
//===---------------------------------------------------------------------------
-// SwitchInst - Multiway switch
-//
+/// SwitchInst - Multiway switch
+///
class SwitchInst : public TerminatorInst {
// Operand[0] = Value to switch on
// Operand[1] = Default basic block destination
@@ -215,6 +215,36 @@
return cast<BasicBlock>(Operands[1].get());
}
+ /// getNumCases - return the number of 'cases' in this switch instruction.
+ /// Note that case #0 is always the default case.
+ unsigned getNumCases() const {
+ return Operands.size()/2;
+ }
+
+ /// getCaseValue - Return the specified case value. Note that case #0, the
+ /// default destination, does not have a case value.
+ Constant *getCaseValue(unsigned i) {
+ assert(i && i < getNumCases() && "Illegal case value to get!");
+ return getSuccessorValue(i);
+ }
+
+ /// getCaseValue - Return the specified case value. Note that case #0, the
+ /// default destination, does not have a case value.
+ const Constant *getCaseValue(unsigned i) const {
+ assert(i && i < getNumCases() && "Illegal case value to get!");
+ return getSuccessorValue(i);
+ }
+
+ /// findCaseValue - Search all of the case values for the specified constant.
+ /// If it is explicitly handled, return the case number of it, otherwise
+ /// return 0 to indicate that it is handled by the default handler.
+ unsigned findCaseValue(const Constant *C) const {
+ for (unsigned i = 1, e = getNumCases(); i != e; ++i)
+ if (getCaseValue(i) == C)
+ return i;
+ return 0;
+ }
+
/// addCase - Add an entry to the switch instruction...
///
void addCase(Constant *OnVal, BasicBlock *Dest);
@@ -261,10 +291,9 @@
}
};
-
//===---------------------------------------------------------------------------
-// InvokeInst - Invoke instruction
-//
+/// InvokeInst - Invoke instruction
+///
class InvokeInst : public TerminatorInst {
InvokeInst(const InvokeInst &BI);
public:
@@ -298,10 +327,10 @@
inline BasicBlock *getNormalDest() {
return cast<BasicBlock>(Operands[1].get());
}
- inline const BasicBlock *getExceptionalDest() const {
+ inline const BasicBlock *getUnwindDest() const {
return cast<BasicBlock>(Operands[2].get());
}
- inline BasicBlock *getExceptionalDest() {
+ inline BasicBlock *getUnwindDest() {
return cast<BasicBlock>(Operands[2].get());
}
@@ -309,17 +338,17 @@
Operands[1] = reinterpret_cast<Value*>(B);
}
- inline void setExceptionalDest(BasicBlock *B){
+ inline void setUnwindDest(BasicBlock *B){
Operands[2] = reinterpret_cast<Value*>(B);
}
virtual const BasicBlock *getSuccessor(unsigned i) const {
assert(i < 2 && "Successor # out of range for invoke!");
- return i == 0 ? getNormalDest() : getExceptionalDest();
+ return i == 0 ? getNormalDest() : getUnwindDest();
}
inline BasicBlock *getSuccessor(unsigned i) {
assert(i < 2 && "Successor # out of range for invoke!");
- return i == 0 ? getNormalDest() : getExceptionalDest();
+ return i == 0 ? getNormalDest() : getUnwindDest();
}
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
More information about the llvm-commits
mailing list