[llvm-branch-commits] [llvm-branch] r133508 - /llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp

Chris Lattner sabre at nondot.org
Mon Jun 20 23:43:50 PDT 2011


Author: lattner
Date: Tue Jun 21 01:43:50 2011
New Revision: 133508

URL: http://llvm.org/viewvc/llvm-project?rev=133508&view=rev
Log:
fix value enumerator to emit types in an order that llvm-dis will 
actually be able to produce them: deterministically bottom up except for
structs, which can be forward ref'd.

Modified:
    llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp

Modified: llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=133508&r1=133507&r2=133508&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/Bitcode/Writer/ValueEnumerator.cpp Tue Jun 21 01:43:50 2011
@@ -322,14 +322,21 @@
   if (TypeID)
     return;
 
-  // First time we saw this type, add it.
-  Types.push_back(Ty);
-  TypeID = Types.size();
-
-  // Enumerate subtypes.
+  // Mark the type as being visited so that we don't recursively visit it.  This
+  // only matters for struct types, but doesn't hurt anything else.
+  TypeID = ~0U;
+  
+  // Enumerate all of the subtypes before we enumerate this type.  This ensures
+  // that the type will be enumerated in an order that can be directly built.
   for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
        I != E; ++I)
     EnumerateType(*I);
+  
+  // Add this type now that its contents are all happily enumerated.
+  Types.push_back(Ty);
+  
+  // Note, can't use TypeID reference here as the map may have reallocated.
+  TypeMap[Ty] = Types.size();
 }
 
 // Enumerate the types for the specified value.  If the value is a constant,





More information about the llvm-branch-commits mailing list