When resolving upreferences, if multiple uprefs will be resolved to the same
authorChris Lattner <sabre@nondot.org>
Mon, 9 Feb 2004 18:53:54 +0000 (18:53 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 9 Feb 2004 18:53:54 +0000 (18:53 +0000)
type at the same time, resolve the upreferences to each other before resolving
it to the outer type.  This shaves off some time from the testcase in PR224, from
25.41s -> 21.72s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11241 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/llvmAsmParser.y

index ad431d03887d7357fdc1d45736bd077a683dae8b..a1ad18ad88e2afe18555bc6bccf6cdd5750bc45a 100644 (file)
@@ -626,6 +626,13 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
   UR_OUT("Type '" << Ty->getDescription() << 
          "' newly formed.  Resolving upreferences.\n" <<
          UpRefs.size() << " upreferences active!\n");
   UR_OUT("Type '" << Ty->getDescription() << 
          "' newly formed.  Resolving upreferences.\n" <<
          UpRefs.size() << " upreferences active!\n");
+
+  // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
+  // to zero), we resolve them all together before we resolve them to Ty.  At
+  // the end of the loop, if there is anything to resolve to Ty, it will be in
+  // this variable.
+  OpaqueType *TypeToResolve = 0;
+
   for (unsigned i = 0; i != UpRefs.size(); ++i) {
     UR_OUT("  UR#" << i << " - TypeContains(" << Ty->getDescription() << ", " 
           << UpRefs[i].second->getDescription() << ") = " 
   for (unsigned i = 0; i != UpRefs.size(); ++i) {
     UR_OUT("  UR#" << i << " - TypeContains(" << Ty->getDescription() << ", " 
           << UpRefs[i].second->getDescription() << ") = " 
@@ -636,18 +643,29 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
       UpRefs[i].LastContainedTy = Ty;
       UR_OUT("  Uplevel Ref Level = " << Level << "\n");
       if (Level == 0) {                     // Upreference should be resolved! 
       UpRefs[i].LastContainedTy = Ty;
       UR_OUT("  Uplevel Ref Level = " << Level << "\n");
       if (Level == 0) {                     // Upreference should be resolved! 
-       UR_OUT("  * Resolving upreference for "
-               << UpRefs[i].second->getDescription() << "\n";
-              std::string OldName = UpRefs[i].UpRefTy->getDescription());
-       UpRefs[i].UpRefTy->refineAbstractTypeTo(Ty);
-       UR_OUT("  * Type '" << OldName << "' refined upreference to: "
-              << (const void*)Ty << ", " << Ty->getDescription() << "\n");
+        if (!TypeToResolve) {
+          TypeToResolve = UpRefs[i].UpRefTy;
+        } else {
+          UR_OUT("  * Resolving upreference for "
+                 << UpRefs[i].second->getDescription() << "\n";
+                 std::string OldName = UpRefs[i].UpRefTy->getDescription());
+          UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
+          UR_OUT("  * Type '" << OldName << "' refined upreference to: "
+                 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
+        }
        UpRefs.erase(UpRefs.begin()+i);     // Remove from upreference list...
         --i;                                // Do not skip the next element...
       }
     }
   }
 
        UpRefs.erase(UpRefs.begin()+i);     // Remove from upreference list...
         --i;                                // Do not skip the next element...
       }
     }
   }
 
+  if (TypeToResolve) {
+    UR_OUT("  * Resolving upreference for "
+           << UpRefs[i].second->getDescription() << "\n";
+           std::string OldName = UpRefs[i].UpRefTy->getDescription());
+    TypeToResolve->refineAbstractTypeTo(Ty);
+  }
+
   return Ty;
 }
 
   return Ty;
 }