aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-13 14:03:36 +0000
committerChris Lattner <sabre@nondot.org>2003-10-13 14:03:36 +0000
commit1825009ba8133992c103102556d32a25aa524d0c (patch)
tree0aef8c45c6f152ef39798965dc2848a868db663c /lib/VMCore
parent236f6463715e9fdceedf47a4d414c4c40b1b6338 (diff)
downloadexternal_llvm-1825009ba8133992c103102556d32a25aa524d0c.zip
external_llvm-1825009ba8133992c103102556d32a25aa524d0c.tar.gz
external_llvm-1825009ba8133992c103102556d32a25aa524d0c.tar.bz2
Avoid creating lots of pointless opaque types, with short lifetimes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9076 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Type.cpp59
1 files changed, 37 insertions, 22 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 4f6359a..2a3d126 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -401,6 +401,43 @@ OpaqueType::OpaqueType() : DerivedType(OpaqueTyID) {
}
+// getAlwaysOpaqueTy - This function returns an opaque type. It doesn't matter
+// _which_ opaque type it is, but the opaque type must never get resolved.
+//
+static Type *getAlwaysOpaqueTy() {
+ static Type *AlwaysOpaqueTy = OpaqueType::get();
+ static PATypeHolder Holder(AlwaysOpaqueTy);
+ return AlwaysOpaqueTy;
+}
+
+
+//===----------------------------------------------------------------------===//
+// dropAllTypeUses methods - These methods eliminate any possibly recursive type
+// references from a derived type. The type must remain abstract, so we make
+// sure to use an always opaque type as an argument.
+//
+
+void FunctionType::dropAllTypeUses() {
+ ResultType = getAlwaysOpaqueTy();
+ ParamTys.clear();
+}
+
+void ArrayType::dropAllTypeUses() {
+ ElementType = getAlwaysOpaqueTy();
+}
+
+void StructType::dropAllTypeUses() {
+ ETypes.clear();
+ ETypes.push_back(PATypeHandle(getAlwaysOpaqueTy(), this));
+}
+
+void PointerType::dropAllTypeUses() {
+ ElementType = getAlwaysOpaqueTy();
+}
+
+
+
+
// isTypeAbstract - This is a recursive function that walks a type hierarchy
// calculating whether or not a type is abstract. Worst case it will have to do
// a lot of traversing if you have some whacko opaque types, but in most cases,
@@ -651,12 +688,6 @@ FunctionType *FunctionType::get(const Type *ReturnType,
return MT;
}
-void FunctionType::dropAllTypeUses() {
- ResultType = OpaqueType::get();
- ParamTys.clear();
-}
-
-
//===----------------------------------------------------------------------===//
// Array Type Factory...
//
@@ -701,13 +732,6 @@ ArrayType *ArrayType::get(const Type *ElementType, unsigned NumElements) {
return AT;
}
-void ArrayType::dropAllTypeUses() {
- ElementType = OpaqueType::get();
-}
-
-
-
-
//===----------------------------------------------------------------------===//
// Struct Type Factory...
//
@@ -755,11 +779,6 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes) {
return ST;
}
-void StructType::dropAllTypeUses() {
- ETypes.clear();
- ETypes.push_back(PATypeHandle(OpaqueType::get(), this));
-}
-
//===----------------------------------------------------------------------===//
@@ -806,10 +825,6 @@ PointerType *PointerType::get(const Type *ValueType) {
return PT;
}
-void PointerType::dropAllTypeUses() {
- ElementType = OpaqueType::get();
-}
-
void debug_type_tables() {
FunctionTypes.dump();
ArrayTypes.dump();