// The set of opaque types is the composite module.
DenseSet<StructType *> OpaqueStructTypes;
- // The set of identified but non opaque structures in the composite module.
- DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
-
- public:
- void addNonOpaque(StructType *Ty);
- void switchToNonOpaque(StructType *Ty);
- void addOpaque(StructType *Ty);
- StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
- bool hasType(StructType *Ty);
- };
-
+ // The set of identified but non opaque structures in the composite module.\r
+ DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;\r
+\r
+ // Map between structure type name and instance. Used in findNonOpaque\r
+ // to correctly map imported global variable type during ThinLTO import\r
+ // phase.\r
+ DenseMap<StringRef, StructType *> NonOpaqueStructNameMap;\r
+\r
+ public:\r
+ void addNonOpaque(StructType *Ty);\r
+ void switchToNonOpaque(StructType *Ty);\r
+ void addOpaque(StructType *Ty);\r
+ StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked,\r
+ StringRef Name);\r
+ bool hasType(StructType *Ty);\r
+ };\r
+\r
IRMover(Module &M);
typedef std::function<void(GlobalValue &)> ValueAdder;
return *Entry = Ty;
}
- if (StructType *OldT =
- DstStructTypesSet.findNonOpaque(ElementTypes, IsPacked)) {
+ if (StructType *OldT = DstStructTypesSet.findNonOpaque(
+ ElementTypes, IsPacked, STy->getName())) {
STy->setName("");
return *Entry = OldT;
}
Expected<Constant *> IRLinker::linkGlobalValueProto(GlobalValue *SGV,
bool ForAlias) {
GlobalValue *DGV = getLinkedToGlobal(SGV);
-
bool ShouldLink = shouldLink(DGV, *SGV);
// just missing from map
void IRMover::IdentifiedStructTypeSet::addNonOpaque(StructType *Ty) {
assert(!Ty->isOpaque());
+ if (Ty->hasName())
+ NonOpaqueStructNameMap.insert({getTypeNamePrefix(Ty->getName()), Ty});
+
NonOpaqueStructTypes.insert(Ty);
}
void IRMover::IdentifiedStructTypeSet::switchToNonOpaque(StructType *Ty) {
- assert(!Ty->isOpaque());
- NonOpaqueStructTypes.insert(Ty);
+ addNonOpaque(Ty);
bool Removed = OpaqueStructTypes.erase(Ty);
(void)Removed;
assert(Removed);
StructType *
IRMover::IdentifiedStructTypeSet::findNonOpaque(ArrayRef<Type *> ETypes,
- bool IsPacked) {
+ bool IsPacked, StringRef Name) {
IRMover::StructTypeKeyInfo::KeyTy Key(ETypes, IsPacked);
auto I = NonOpaqueStructTypes.find_as(Key);
- return I == NonOpaqueStructTypes.end() ? nullptr : *I;
+ if (I == NonOpaqueStructTypes.end())
+ return nullptr;
+ auto NI = NonOpaqueStructNameMap.find(getTypeNamePrefix(Name));
+ if (NI != NonOpaqueStructNameMap.end() &&
+ IRMover::StructTypeKeyInfo::KeyTy((*NI).second) == Key)
+ return (*NI).second;
+ return *I;
}
bool IRMover::IdentifiedStructTypeSet::hasType(StructType *Ty) {
--- /dev/null
+%struct.Baz = type { i64, i64, %struct.Foo }\r
+%struct.Foo = type { i64, i64 }\r
+\r
+@baz = global %struct.Baz zeroinitializer\r
--- /dev/null
+; RUN: llvm-link --initial-module=%s %p/Inputs/struct-mapping.ll -S -o - | FileCheck %s\r
+\r
+; Here we check that new type mapping algorithm correctly mapped type of internal\r
+; member of struct.Baz to struct.Foo. Without it we'd map that type to struct.Bar, because\r
+; it is recursively isomorphic to struct.Foo and is defined first in source file.\r
+; CHECK: %struct.Baz = type { i64, i64, %struct.Foo }\r
+\r
+%struct.Bar = type { i64, i64 }\r
+%struct.Foo = type { i64, i64 }\r
+\r
+@bar = global %struct.Bar zeroinitializer\r
+@foo = global %struct.Foo zeroinitializer\r
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
cl::value_desc("filename"));
+static cl::opt<std::string>
+ InitialModule("initial-module",
+ cl::desc("Link to existing destination module"), cl::init(""),
+ cl::value_desc("filename"));
+
static cl::opt<bool>
Internalize("internalize", cl::desc("Internalize linked symbols"));
if (!DisableDITypeMap)
Context.enableDebugTypeODRUniquing();
- auto Composite = make_unique<Module>("llvm-link", Context);
+ auto Composite = InitialModule.empty()
+ ? make_unique<Module>("llvm-link", Context)
+ : loadFile(argv[0], InitialModule, Context);
Linker L(*Composite);
unsigned Flags = Linker::Flags::None;