[llvm-commits] CVS: llvm/lib/VMCore/Type.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Oct 13 09:04:01 PDT 2003
Changes in directory llvm/lib/VMCore:
Type.cpp updated: 1.75 -> 1.76
---
Log message:
Avoid creating lots of pointless opaque types, with short lifetimes
---
Diffs of the changes: (+37 -22)
Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.75 llvm/lib/VMCore/Type.cpp:1.76
--- llvm/lib/VMCore/Type.cpp:1.75 Fri Oct 10 12:54:14 2003
+++ llvm/lib/VMCore/Type.cpp Mon Oct 13 09:03:36 2003
@@ -401,6 +401,43 @@
}
+// 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 @@
return MT;
}
-void FunctionType::dropAllTypeUses() {
- ResultType = OpaqueType::get();
- ParamTys.clear();
-}
-
-
//===----------------------------------------------------------------------===//
// Array Type Factory...
//
@@ -701,13 +732,6 @@
return AT;
}
-void ArrayType::dropAllTypeUses() {
- ElementType = OpaqueType::get();
-}
-
-
-
-
//===----------------------------------------------------------------------===//
// Struct Type Factory...
//
@@ -755,11 +779,6 @@
return ST;
}
-void StructType::dropAllTypeUses() {
- ETypes.clear();
- ETypes.push_back(PATypeHandle(OpaqueType::get(), this));
-}
-
//===----------------------------------------------------------------------===//
@@ -804,10 +823,6 @@
std::cerr << "Derived new type: " << *PT << "\n";
#endif
return PT;
-}
-
-void PointerType::dropAllTypeUses() {
- ElementType = OpaqueType::get();
}
void debug_type_tables() {
More information about the llvm-commits
mailing list