llvm.org GIT mirror llvm / d9788e9
Partial revert of r222986. The explicit set of destination types is not fully redundant when lazy loading since the TypeFinder will not find types used only in function bodies. This keeps the logic to drop the name of mapped types since it still helps with avoiding further renaming. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223043 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
3 changed file(s) with 44 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
4545 private:
4646 void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
4747 Module *Composite;
48 SmallPtrSet IdentifiedStructTypes;
4849 DiagnosticHandlerFunction DiagnosticHandler;
4950 };
5051
5757 SmallPtrSet DstResolvedOpaqueTypes;
5858
5959 public:
60 TypeMapTy() {}
61
60 TypeMapTy(TypeSet &Set) : DstStructTypesSet(Set) {}
61
62 TypeSet &DstStructTypesSet;
6263 /// Indicate that the specified type in the destination module is conceptually
6364 /// equivalent to the specified type in the source module.
6465 void addTypeMapping(Type *DstTy, Type *SrcTy);
224225 }
225226
226227 Type *TypeMapTy::get(Type *Ty) {
228 #ifndef NDEBUG
229 for (auto &Pair : MappedTypes) {
230 assert(!(Pair.first != Ty && Pair.second == Ty) &&
231 "mapping to a source type");
232 }
233 #endif
234
227235 // If we already have an entry for this type, return it.
228236 Type **Entry = &MappedTypes[Ty];
229237 if (*Entry)
309317 if (STy->isOpaque()) {
310318 // A named structure type from src module is used. Add it to the Set of
311319 // identified structs in the destination module.
320 DstStructTypesSet.insert(STy);
312321 return *Entry = STy;
313322 }
314323
316325 StructType *DTy = StructType::create(STy->getContext());
317326 // A new identified structure type was created. Add it to the set of
318327 // identified structs in the destination module.
328 DstStructTypesSet.insert(DTy);
319329 *Entry = DTy;
320330
321331 SmallVector ElementTypes;
401411 Linker::DiagnosticHandlerFunction DiagnosticHandler;
402412
403413 public:
404 ModuleLinker(Module *dstM, Module *srcM,
414 ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM,
405415 Linker::DiagnosticHandlerFunction DiagnosticHandler)
406 : DstM(dstM), SrcM(srcM),
416 : DstM(dstM), SrcM(srcM), TypeMap(Set),
407417 ValMaterializer(TypeMap, DstM, LazilyLinkFunctions),
408418 DiagnosticHandler(DiagnosticHandler) {}
409419
815825 // we prefer to take the '%C' version. So we are then left with both
816826 // '%C.1' and '%C' being used for the same types. This leads to some
817827 // variables using one type and some using the other.
818 if (!SrcStructTypesSet.count(DST))
828 if (!SrcStructTypesSet.count(DST) && TypeMap.DstStructTypesSet.count(DST))
819829 TypeMap.addTypeMapping(DST, ST);
820830 }
821831
15771587 void Linker::init(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
15781588 this->Composite = M;
15791589 this->DiagnosticHandler = DiagnosticHandler;
1590
1591 TypeFinder StructTypes;
1592 StructTypes.run(*M, true);
1593 IdentifiedStructTypes.insert(StructTypes.begin(), StructTypes.end());
15801594 }
15811595
15821596 Linker::Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
15981612 }
15991613
16001614 bool Linker::linkInModule(Module *Src) {
1601 ModuleLinker TheLinker(Composite, Src, DiagnosticHandler);
1615 ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src,
1616 DiagnosticHandler);
16021617 return TheLinker.run();
16031618 }
16041619
0 ; RUN: llvm-as %s -o %t.bc
1 ; RUN: llvm-link -S %t.bc -o - | FileCheck %s
2 ; RUN: llvm-link -S %s -o - | FileCheck %s
3
4 ; Test that we don't try to map %C.0 and C and then try to map %C to a new type.
5 ; This used to happen when lazy loading since we wouldn't then identify %C
6 ; as a destination type until it was too late.
7
8 ; CHECK: %C.0 = type { %B }
9 ; CHECK-NEXT: %B = type { %A }
10 ; CHECK-NEXT: %A = type { i8 }
11 ; CHECK-NEXT: %C = type { %B }
12
13 %A = type { i8 }
14 %B = type { %A }
15 %C = type { %B }
16 %C.0 = type { %B }
17 define void @f1() {
18 getelementptr %C* null, i64 0, i32 0, i32 0
19 ret void
20 }
21 @g1 = external global %C.0