Add a flag to the struct type finder to collect only those types which have
authorBill Wendling <isanbard@gmail.com>
Sat, 21 Apr 2012 23:59:16 +0000 (23:59 +0000)
committerBill Wendling <isanbard@gmail.com>
Sat, 21 Apr 2012 23:59:16 +0000 (23:59 +0000)
names. This saves collecting types we normally don't care about.

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

include/llvm/Module.h
lib/Linker/LinkModules.cpp
lib/VMCore/Module.cpp

index b9c98814f15947eae9bd00ab1bf6d93aecd57e0b..570b1bc7b450416b20fd7b22c0f3f8593546e4ce 100644 (file)
@@ -303,7 +303,8 @@ public:
 
   /// findUsedStructTypes - Walk the entire module and find all of the
   /// struct types that are in use, returning them in a vector.
-  void findUsedStructTypes(std::vector<StructType*> &StructTypes) const;
+  void findUsedStructTypes(std::vector<StructType*> &StructTypes,
+                           bool OnlyNamed = false) const;
   
   /// getTypeByName - Return the type with the specified name, or null if there
   /// is none by that name.
index 765fcc88235b23822a00cc9a24a0c8e01f019fa5..630289b2bdcd07801be1719c85280b801d42ef92 100644 (file)
@@ -595,12 +595,12 @@ void ModuleLinker::computeTypeMapping() {
   // example.  When the source module got loaded into the same LLVMContext, if
   // it had the same type, it would have been renamed to "%foo.42 = { i32 }".
   std::vector<StructType*> SrcStructTypes;
-  SrcM->findUsedStructTypes(SrcStructTypes);
+  SrcM->findUsedStructTypes(SrcStructTypes, true);
   SmallPtrSet<StructType*, 32> SrcStructTypesSet(SrcStructTypes.begin(),
                                                  SrcStructTypes.end());
 
   std::vector<StructType*> DstStructTypes;
-  DstM->findUsedStructTypes(DstStructTypes);
+  DstM->findUsedStructTypes(DstStructTypes, true);
   SmallPtrSet<StructType*, 32> DstStructTypesSet(DstStructTypes.begin(),
                                                  DstStructTypes.end());
 
index 3c67191e09c2d570563dc6142e8db9a645384968..24c2707b5438085ae9f6bd67811ded15fd6f9a2f 100644 (file)
@@ -483,9 +483,10 @@ namespace {
     DenseSet<Type*> VisitedTypes;
     
     std::vector<StructType*> &StructTypes;
+    bool OnlyNamed;
   public:
-    TypeFinder(std::vector<StructType*> &structTypes)
-      : StructTypes(structTypes) {}
+    TypeFinder(std::vector<StructType*> &structTypes, bool onlyNamed)
+      : StructTypes(structTypes), OnlyNamed(onlyNamed) {}
     
     void run(const Module &M) {
       // Get types from global variables.
@@ -545,7 +546,8 @@ namespace {
       
       // If this is a structure or opaque type, add a name for the type.
       if (StructType *STy = dyn_cast<StructType>(Ty))
-        StructTypes.push_back(STy);
+        if (!OnlyNamed || STy->hasName())
+          StructTypes.push_back(STy);
       
       // Recursively walk all contained types.
       for (Type::subtype_iterator I = Ty->subtype_begin(),
@@ -590,6 +592,7 @@ namespace {
   };
 } // end anonymous namespace
 
-void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes) const {
-  TypeFinder(StructTypes).run(*this);
+void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes,
+                                 bool OnlyNamed) const {
+  TypeFinder(StructTypes, OnlyNamed).run(*this);
 }