aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-12-20 00:12:26 +0000
committerChris Lattner <sabre@nondot.org>2011-12-20 00:12:26 +0000
commit9eb3f00406abcb3498b3e5e702eb69a9612a88bc (patch)
treed384951f52e15c158911bbd06807f4f5366ad076 /llvm/lib/Linker/LinkModules.cpp
parent070e1a7643354fb83017ba0b1e18e435f544b320 (diff)
downloadllvm-9eb3f00406abcb3498b3e5e702eb69a9612a88bc.zip
llvm-9eb3f00406abcb3498b3e5e702eb69a9612a88bc.tar.gz
llvm-9eb3f00406abcb3498b3e5e702eb69a9612a88bc.tar.bz2
Now that PR11464 is fixed, reapply the patch to fix PR11464,
merging types by name when we can. We still don't guarantee type name linkage but we do it when obviously the right thing to do. This makes LTO type names easier to read, for example. llvm-svn: 146932
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 7706b90..4f6013e 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -558,6 +558,31 @@ void ModuleLinker::computeTypeMapping() {
TypeMap.addTypeMapping(DGV->getType(), I->getType());
}
+ // Incorporate types by name, scanning all the types in the source module.
+ // At this point, the destination module may have a type "%foo = { i32 }" for
+ // 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 }".
+ // Though it isn't required for correctness, attempt to link these up to clean
+ // up the IR.
+ std::vector<StructType*> SrcStructTypes;
+ SrcM->findUsedStructTypes(SrcStructTypes);
+
+ for (unsigned i = 0, e = SrcStructTypes.size(); i != e; ++i) {
+ StructType *ST = SrcStructTypes[i];
+ if (!ST->hasName()) continue;
+
+ // Check to see if there is a dot in the name followed by a digit.
+ size_t DotPos = ST->getName().rfind('.');
+ if (DotPos == 0 || DotPos == StringRef::npos ||
+ ST->getName().back() == '.' || !isdigit(ST->getName()[DotPos+1]))
+ continue;
+
+ // Check to see if the destination module has a struct with the prefix name.
+ if (StructType *DST = DstM->getTypeByName(ST->getName().substr(0, DotPos)))
+ TypeMap.addTypeMapping(DST, ST);
+ }
+
+
// Don't bother incorporating aliases, they aren't generally typed well.
// Now that we have discovered all of the type equivalences, get a body for