llvm.org GIT mirror llvm / ea93373
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146932 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
2 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
557557 TypeMap.addTypeMapping(DGV->getType(), I->getType());
558558 }
559559
560 // Incorporate types by name, scanning all the types in the source module.
561 // At this point, the destination module may have a type "%foo = { i32 }" for
562 // example. When the source module got loaded into the same LLVMContext, if
563 // it had the same type, it would have been renamed to "%foo.42 = { i32 }".
564 // Though it isn't required for correctness, attempt to link these up to clean
565 // up the IR.
566 std::vector SrcStructTypes;
567 SrcM->findUsedStructTypes(SrcStructTypes);
568
569 for (unsigned i = 0, e = SrcStructTypes.size(); i != e; ++i) {
570 StructType *ST = SrcStructTypes[i];
571 if (!ST->hasName()) continue;
572
573 // Check to see if there is a dot in the name followed by a digit.
574 size_t DotPos = ST->getName().rfind('.');
575 if (DotPos == 0 || DotPos == StringRef::npos ||
576 ST->getName().back() == '.' || !isdigit(ST->getName()[DotPos+1]))
577 continue;
578
579 // Check to see if the destination module has a struct with the prefix name.
580 if (StructType *DST = DstM->getTypeByName(ST->getName().substr(0, DotPos)))
581 TypeMap.addTypeMapping(DST, ST);
582 }
583
584
560585 // Don't bother incorporating aliases, they aren't generally typed well.
561586
562587 // Now that we have discovered all of the type equivalences, get a body for
0 ; RUN: echo "%X = type { i32 } @G2 = global %X { i32 4 }" > %t.ll
1 ; RUN: llvm-link %s %t.ll -S | FileCheck %s
2 ; PR11464
3
4 %X = type { i32 }
5 @G = global %X { i32 4 }
6
7
8 ; CHECK: @G = global %X { i32 4 }
9 ; CHECK: @G2 = global %X { i32 4 }