From d46575f1908b1fb9950e610a1f36733893ad44b1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 21 Apr 2012 23:59:16 +0000 Subject: [PATCH] Add a flag to the struct type finder to collect only those types which have 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 | 3 ++- lib/Linker/LinkModules.cpp | 4 ++-- lib/VMCore/Module.cpp | 13 ++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/llvm/Module.h b/include/llvm/Module.h index b9c98814f15..570b1bc7b45 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -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 &StructTypes) const; + void findUsedStructTypes(std::vector &StructTypes, + bool OnlyNamed = false) const; /// getTypeByName - Return the type with the specified name, or null if there /// is none by that name. diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 765fcc88235..630289b2bdc 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -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 SrcStructTypes; - SrcM->findUsedStructTypes(SrcStructTypes); + SrcM->findUsedStructTypes(SrcStructTypes, true); SmallPtrSet SrcStructTypesSet(SrcStructTypes.begin(), SrcStructTypes.end()); std::vector DstStructTypes; - DstM->findUsedStructTypes(DstStructTypes); + DstM->findUsedStructTypes(DstStructTypes, true); SmallPtrSet DstStructTypesSet(DstStructTypes.begin(), DstStructTypes.end()); diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 3c67191e09c..24c2707b543 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -483,9 +483,10 @@ namespace { DenseSet VisitedTypes; std::vector &StructTypes; + bool OnlyNamed; public: - TypeFinder(std::vector &structTypes) - : StructTypes(structTypes) {} + TypeFinder(std::vector &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(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 &StructTypes) const { - TypeFinder(StructTypes).run(*this); +void Module::findUsedStructTypes(std::vector &StructTypes, + bool OnlyNamed) const { + TypeFinder(StructTypes, OnlyNamed).run(*this); } -- 2.34.1