summaryrefslogtreecommitdiff
path: root/lib/VMCore/Type.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-08-28 04:09:24 +0000
committerChris Lattner <sabre@nondot.org>2010-08-28 04:09:24 +0000
commit61c70e98ac3c7504d31dd9bc81c4e9cb998e9984 (patch)
tree05263a360b43d09ed99dacdf6d402ce50deb32d7 /lib/VMCore/Type.cpp
parent5f88af537637831451ff9ffa08c597e05e7dc9fb (diff)
downloadllvm-61c70e98ac3c7504d31dd9bc81c4e9cb998e9984.tar.gz
llvm-61c70e98ac3c7504d31dd9bc81c4e9cb998e9984.tar.bz2
llvm-61c70e98ac3c7504d31dd9bc81c4e9cb998e9984.tar.xz
remove unions from LLVM IR. They are severely buggy and not
being actively maintained, improved, or extended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112356 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Type.cpp')
-rw-r--r--lib/VMCore/Type.cpp133
1 files changed, 6 insertions, 127 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 0c9b0eaf56..c55e626783 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -50,7 +50,7 @@ void AbstractTypeUser::setType(Value *V, const Type *NewTy) {
/// Because of the way Type subclasses are allocated, this function is necessary
/// to use the correct kind of "delete" operator to deallocate the Type object.
-/// Some type objects (FunctionTy, StructTy, UnionTy) allocate additional space
+/// Some type objects (FunctionTy, StructTy) allocate additional space
/// after the space for their derived type to hold the contained types array of
/// PATypeHandles. Using this allocation scheme means all the PATypeHandles are
/// allocated with the type object, decreasing allocations and eliminating the
@@ -66,8 +66,7 @@ void Type::destroy() const {
// Structures and Functions allocate their contained types past the end of
// the type object itself. These need to be destroyed differently than the
// other types.
- if (this->isFunctionTy() || this->isStructTy() ||
- this->isUnionTy()) {
+ if (this->isFunctionTy() || this->isStructTy()) {
// First, make sure we destruct any PATypeHandles allocated by these
// subclasses. They must be manually destructed.
for (unsigned i = 0; i < NumContainedTys; ++i)
@@ -77,10 +76,10 @@ void Type::destroy() const {
// to delete this as an array of char.
if (this->isFunctionTy())
static_cast<const FunctionType*>(this)->FunctionType::~FunctionType();
- else if (this->isStructTy())
+ else {
+ assert(isStructTy());
static_cast<const StructType*>(this)->StructType::~StructType();
- else
- static_cast<const UnionType*>(this)->UnionType::~UnionType();
+ }
// Finally, remove the memory as an array deallocation of the chars it was
// constructed from.
@@ -234,7 +233,7 @@ bool Type::isSizedDerivedType() const {
if (const VectorType *PTy = dyn_cast<VectorType>(this))
return PTy->getElementType()->isSized();
- if (!this->isStructTy() && !this->isUnionTy())
+ if (!this->isStructTy())
return false;
// Okay, our struct is sized if all of the elements are...
@@ -319,31 +318,6 @@ const Type *StructType::getTypeAtIndex(unsigned Idx) const {
}
-bool UnionType::indexValid(const Value *V) const {
- // Union indexes require 32-bit integer constants.
- if (V->getType()->isIntegerTy(32))
- if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
- return indexValid(CU->getZExtValue());
- return false;
-}
-
-bool UnionType::indexValid(unsigned V) const {
- return V < NumContainedTys;
-}
-
-// getTypeAtIndex - Given an index value into the type, return the type of the
-// element. For a structure type, this must be a constant value...
-//
-const Type *UnionType::getTypeAtIndex(const Value *V) const {
- unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
- return getTypeAtIndex(Idx);
-}
-
-const Type *UnionType::getTypeAtIndex(unsigned Idx) const {
- assert(indexValid(Idx) && "Invalid structure index!");
- return ContainedTys[Idx];
-}
-
//===----------------------------------------------------------------------===//
// Primitive 'Type' data
//===----------------------------------------------------------------------===//
@@ -507,23 +481,6 @@ StructType::StructType(LLVMContext &C,
setAbstract(isAbstract);
}
-UnionType::UnionType(LLVMContext &C,const Type* const* Types, unsigned NumTypes)
- : CompositeType(C, UnionTyID) {
- ContainedTys = reinterpret_cast<PATypeHandle*>(this + 1);
- NumContainedTys = NumTypes;
- bool isAbstract = false;
- for (unsigned i = 0; i < NumTypes; ++i) {
- assert(Types[i] && "<null> type for union field!");
- assert(isValidElementType(Types[i]) &&
- "Invalid type for union element!");
- new (&ContainedTys[i]) PATypeHandle(Types[i], this);
- isAbstract |= Types[i]->isAbstract();
- }
-
- // Calculate whether or not this type is abstract
- setAbstract(isAbstract);
-}
-
ArrayType::ArrayType(const Type *ElType, uint64_t NumEl)
: SequentialType(ArrayTyID, ElType) {
NumElements = NumEl;
@@ -711,15 +668,6 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
return true;
}
- if (const UnionType *UTy = dyn_cast<UnionType>(Ty)) {
- const UnionType *UTy2 = cast<UnionType>(Ty2);
- if (UTy->getNumElements() != UTy2->getNumElements()) return false;
- for (unsigned i = 0, e = UTy2->getNumElements(); i != e; ++i)
- if (!TypesEqual(UTy->getElementType(i), UTy2->getElementType(i), EqTypes))
- return false;
- return true;
- }
-
if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
const ArrayType *ATy2 = cast<ArrayType>(Ty2);
return ATy->getNumElements() == ATy2->getNumElements() &&
@@ -987,60 +935,6 @@ bool StructType::isValidElementType(const Type *ElemTy) {
//===----------------------------------------------------------------------===//
-// Union Type Factory...
-//
-
-UnionType *UnionType::get(const Type* const* Types, unsigned NumTypes) {
- assert(NumTypes > 0 && "union must have at least one member type!");
- UnionValType UTV(Types, NumTypes);
- UnionType *UT = 0;
-
- LLVMContextImpl *pImpl = Types[0]->getContext().pImpl;
-
- UT = pImpl->UnionTypes.get(UTV);
-
- if (!UT) {
- // Value not found. Derive a new type!
- UT = (UnionType*) operator new(sizeof(UnionType) +
- sizeof(PATypeHandle) * NumTypes);
- new (UT) UnionType(Types[0]->getContext(), Types, NumTypes);
- pImpl->UnionTypes.add(UTV, UT);
- }
-#ifdef DEBUG_MERGE_TYPES
- DEBUG(dbgs() << "Derived new type: " << *UT << "\n");
-#endif
- return UT;
-}
-
-UnionType *UnionType::get(const Type *type, ...) {
- va_list ap;
- SmallVector<const llvm::Type*, 8> UnionFields;
- va_start(ap, type);
- while (type) {
- UnionFields.push_back(type);
- type = va_arg(ap, llvm::Type*);
- }
- unsigned NumTypes = UnionFields.size();
- assert(NumTypes > 0 && "union must have at least one member type!");
- return llvm::UnionType::get(&UnionFields[0], NumTypes);
-}
-
-bool UnionType::isValidElementType(const Type *ElemTy) {
- return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
- !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
-}
-
-int UnionType::getElementTypeIndex(const Type *ElemTy) const {
- int index = 0;
- for (UnionType::element_iterator I = element_begin(), E = element_end();
- I != E; ++I, ++index) {
- if (ElemTy == *I) return index;
- }
-
- return -1;
-}
-
-//===----------------------------------------------------------------------===//
// Pointer Type Factory...
//
@@ -1291,21 +1185,6 @@ void StructType::typeBecameConcrete(const DerivedType *AbsTy) {
// concrete - this could potentially change us from an abstract type to a
// concrete type.
//
-void UnionType::refineAbstractType(const DerivedType *OldType,
- const Type *NewType) {
- LLVMContextImpl *pImpl = OldType->getContext().pImpl;
- pImpl->UnionTypes.RefineAbstractType(this, OldType, NewType);
-}
-
-void UnionType::typeBecameConcrete(const DerivedType *AbsTy) {
- LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
- pImpl->UnionTypes.TypeBecameConcrete(this, AbsTy);
-}
-
-// refineAbstractType - Called when a contained type is found to be more
-// concrete - this could potentially change us from an abstract type to a
-// concrete type.
-//
void PointerType::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
LLVMContextImpl *pImpl = OldType->getContext().pImpl;