[llvm] r222986 - Change how we keep track of which types are in the dest module.

Rafael Espindola rafael.espindola at gmail.com
Sun Nov 30 20:15:59 PST 2014


Author: rafael
Date: Sun Nov 30 22:15:59 2014
New Revision: 222986

URL: http://llvm.org/viewvc/llvm-project?rev=222986&view=rev
Log:
Change how we keep track of which types are in the dest module.

Instead of keeping an explicit set, just drop the names of types we choose
to map to some other type.

This has the advantage that the name of the unused will not cause the context
to rename types on module read.

Modified:
    llvm/trunk/include/llvm/Linker/Linker.h
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/test/Linker/type-unique-dst-types.ll

Modified: llvm/trunk/include/llvm/Linker/Linker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/Linker.h?rev=222986&r1=222985&r2=222986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Linker/Linker.h (original)
+++ llvm/trunk/include/llvm/Linker/Linker.h Sun Nov 30 22:15:59 2014
@@ -46,7 +46,6 @@ public:
 private:
   void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
   Module *Composite;
-  SmallPtrSet<StructType *, 32> IdentifiedStructTypes;
   DiagnosticHandlerFunction DiagnosticHandler;
 };
 

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=222986&r1=222985&r2=222986&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sun Nov 30 22:15:59 2014
@@ -58,9 +58,8 @@ class TypeMapTy : public ValueMapTypeRem
   SmallPtrSet<StructType*, 16> DstResolvedOpaqueTypes;
 
 public:
-  TypeMapTy(TypeSet &Set) : DstStructTypesSet(Set) {}
+  TypeMapTy() {}
 
-  TypeSet &DstStructTypesSet;
   /// Indicate that the specified type in the destination module is conceptually
   /// equivalent to the specified type in the source module.
   void addTypeMapping(Type *DstTy, Type *SrcTy);
@@ -111,6 +110,11 @@ void TypeMapTy::addTypeMapping(Type *Dst
                                    SpeculativeDstOpaqueTypes.size());
     for (StructType *Ty : SpeculativeDstOpaqueTypes)
       DstResolvedOpaqueTypes.erase(Ty);
+  } else {
+    for (Type *Ty : SpeculativeTypes)
+      if (auto *STy = dyn_cast<StructType>(Ty))
+        if (STy->hasName())
+          STy->setName("");
   }
   SpeculativeTypes.clear();
   SpeculativeDstOpaqueTypes.clear();
@@ -306,7 +310,6 @@ Type *TypeMapTy::get(Type *Ty) {
   if (STy->isOpaque()) {
     // A named structure type from src module is used. Add it to the Set of
     // identified structs in the destination module.
-    DstStructTypesSet.insert(STy);
     return *Entry = STy;
   }
 
@@ -314,7 +317,6 @@ Type *TypeMapTy::get(Type *Ty) {
   StructType *DTy = StructType::create(STy->getContext());
   // A new identified structure type was created. Add it to the set of
   // identified structs in the destination module.
-  DstStructTypesSet.insert(DTy);
   *Entry = DTy;
 
   SmallVector<Type*, 4> ElementTypes;
@@ -400,9 +402,9 @@ class ModuleLinker {
   Linker::DiagnosticHandlerFunction DiagnosticHandler;
 
 public:
-  ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM,
+  ModuleLinker(Module *dstM, Module *srcM,
                Linker::DiagnosticHandlerFunction DiagnosticHandler)
-      : DstM(dstM), SrcM(srcM), TypeMap(Set),
+      : DstM(dstM), SrcM(srcM),
         ValMaterializer(TypeMap, DstM, LazilyLinkFunctions),
         DiagnosticHandler(DiagnosticHandler) {}
 
@@ -814,7 +816,7 @@ void ModuleLinker::computeTypeMapping()
       // we prefer to take the '%C' version. So we are then left with both
       // '%C.1' and '%C' being used for the same types. This leads to some
       // variables using one type and some using the other.
-      if (!SrcStructTypesSet.count(DST) && TypeMap.DstStructTypesSet.count(DST))
+      if (!SrcStructTypesSet.count(DST))
         TypeMap.addTypeMapping(DST, ST);
   }
 
@@ -1576,10 +1578,6 @@ bool ModuleLinker::run() {
 void Linker::init(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
   this->Composite = M;
   this->DiagnosticHandler = DiagnosticHandler;
-
-  TypeFinder StructTypes;
-  StructTypes.run(*M, true);
-  IdentifiedStructTypes.insert(StructTypes.begin(), StructTypes.end());
 }
 
 Linker::Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
@@ -1601,8 +1599,7 @@ void Linker::deleteModule() {
 }
 
 bool Linker::linkInModule(Module *Src) {
-  ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
-                         DiagnosticHandler);
+  ModuleLinker TheLinker(Composite, Src, DiagnosticHandler);
   return TheLinker.run();
 }
 

Modified: llvm/trunk/test/Linker/type-unique-dst-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-dst-types.ll?rev=222986&r1=222985&r2=222986&view=diff
==============================================================================
--- llvm/trunk/test/Linker/type-unique-dst-types.ll (original)
+++ llvm/trunk/test/Linker/type-unique-dst-types.ll Sun Nov 30 22:15:59 2014
@@ -9,7 +9,10 @@
 
 ; CHECK: %A = type { %B }
 ; CHECK-NEXT: %B = type { i8 }
-; CHECK-NEXT: %A.11.1 = type opaque
+
+; CHECK: @g3 = external global %A
+; CHECK: @g1 = external global %A
+; CHECK: @g2 = external global %A
 
 %A = type { %B }
 %B = type { i8 }





More information about the llvm-commits mailing list