Revert "Fix overly aggressive type merging."
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 27 Nov 2014 17:01:10 +0000 (17:01 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 27 Nov 2014 17:01:10 +0000 (17:01 +0000)
This reverts commit r222727, which causes LTO bootstrap failures.

Last passing @ r222698:
http://lab.llvm.org:8080/green/job/clang-Rlto_master_build/532/

First failing @ r222843:
http://lab.llvm.org:8080/green/job/clang-Rlto_master_build/533/

Internal bootstraps pointed at a much narrower range: r222725 is
passing, and r222731 is failing.

LTO crashes while handling libclang.dylib:
http://lab.llvm.org:8080/green/job/clang-Rlto_master_build/533/consoleFull#-158682280549ba4694-19c4-4d7e-bec5-911270d8a58c

    GEP is not of right type for indices!
      %InfoObj.i.i = getelementptr inbounds %"class.llvm::OnDiskIterableChainedHashTable"* %.lcssa, i64 0, i32 0, i32 4, !dbg !123627
     %"class.clang::serialization::reader::ASTIdentifierLookupTrait" = type { %"class.clang::ASTReader.31859"*, %"class.clang::serialization::ModuleFile.31870"*, %"class.clang::IdentifierInfo"* }LLVM ERROR: Broken function found, compilation aborted!
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

Looks like the new algorithm doesn't merge types aggressively enough.

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

lib/Linker/LinkModules.cpp
test/Linker/Inputs/type-unique-opaque.ll [deleted file]
test/Linker/type-unique-opaque.ll [deleted file]

index 76daed250d32870eca7aecd62e77e44e92849fca..f1f4a51f78c7a23c6424ab82b60f8f4b12f573de 100644 (file)
@@ -96,23 +96,12 @@ private:
 void TypeMapTy::addTypeMapping(Type *DstTy, Type *SrcTy) {
   // Check to see if these types are recursively isomorphic and establish a
   // mapping between them if so.
-  if (areTypesIsomorphic(DstTy, SrcTy)) {
-    SpeculativeTypes.clear();
-    return;
-  }
-
-  // Oops, they aren't isomorphic. Just discard this request by rolling out
-  // any speculative mappings we've established.
-  unsigned Removed = 0;
-  for (unsigned I = 0, E = SpeculativeTypes.size(); I != E; ++I) {
-    Type *SrcTy = SpeculativeTypes[I];
-    auto Iter = MappedTypes.find(SrcTy);
-    auto *DstTy = dyn_cast<StructType>(Iter->second);
-    if (DstTy && DstResolvedOpaqueTypes.erase(DstTy))
-      Removed++;
-    MappedTypes.erase(Iter);
+  if (!areTypesIsomorphic(DstTy, SrcTy)) {
+    // Oops, they aren't isomorphic.  Just discard this request by rolling out
+    // any speculative mappings we've established.
+    for (unsigned i = 0, e = SpeculativeTypes.size(); i != e; ++i)
+      MappedTypes.erase(SpeculativeTypes[i]);
   }
-  SrcDefinitionsToResolve.resize(SrcDefinitionsToResolve.size() - Removed);
   SpeculativeTypes.clear();
 }
 
@@ -148,14 +137,14 @@ bool TypeMapTy::areTypesIsomorphic(Type *DstTy, Type *SrcTy) {
 
     // Mapping a non-opaque source type to an opaque dest.  If this is the first
     // type that we're mapping onto this destination type then we succeed.  Keep
-    // the dest, but fill it in later. If this is the second (different) type
-    // that we're trying to map onto the same opaque type then we fail.
+    // the dest, but fill it in later.  This doesn't need to be speculative.  If
+    // this is the second (different) type that we're trying to map onto the
+    // same opaque type then we fail.
     if (cast<StructType>(DstTy)->isOpaque()) {
       // We can only map one source type onto the opaque destination type.
       if (!DstResolvedOpaqueTypes.insert(cast<StructType>(DstTy)).second)
         return false;
       SrcDefinitionsToResolve.push_back(SSTy);
-      SpeculativeTypes.push_back(SrcTy);
       Entry = DstTy;
       return true;
     }
diff --git a/test/Linker/Inputs/type-unique-opaque.ll b/test/Linker/Inputs/type-unique-opaque.ll
deleted file mode 100644 (file)
index 872b601..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-%t = type { i8 }
-%t2 = type { %t*, i16 }
-
-define %t2* @f() {
-  ret %t2* null
-}
diff --git a/test/Linker/type-unique-opaque.ll b/test/Linker/type-unique-opaque.ll
deleted file mode 100644 (file)
index b4f6966..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-; RUN: llvm-link -S %s %p/Inputs/type-unique-opaque.ll | FileCheck %s
-
-; Test that a failed attempt at merging %u2 and %t2 (for the other file) will
-; not cause %u and %t to get merged.
-
-; CHECK: %u = type opaque
-; CHECK: define %u* @g() {
-
-%u = type opaque
-%u2 = type { %u*, i8 }
-
-declare %u2* @f()
-
-define %u* @g() {
-  ret %u* null
-}