diff --git a/llvm/include/llvm/Linker/IRMover.h b/llvm/include/llvm/Linker/IRMover.h --- a/llvm/include/llvm/Linker/IRMover.h +++ b/llvm/include/llvm/Linker/IRMover.h @@ -12,6 +12,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FunctionExtras.h" +#include "llvm/ADT/iterator_range.h" #include namespace llvm { @@ -58,6 +59,27 @@ void addOpaque(StructType *Ty); StructType *findNonOpaque(ArrayRef ETypes, bool IsPacked); bool hasType(StructType *Ty); + + using const_non_opaque_iterator = + decltype(NonOpaqueStructTypes)::const_iterator; + const_non_opaque_iterator begin_non_opaque() const { + return NonOpaqueStructTypes.begin(); + } + const_non_opaque_iterator end_non_opaque() const { + return NonOpaqueStructTypes.end(); + } + llvm::iterator_range range_non_opaque() { + return llvm::make_range(begin_non_opaque(), end_non_opaque()); + } + + using const_opaque_iterator = decltype(OpaqueStructTypes)::const_iterator; + const_opaque_iterator begin_opaque() const { + return OpaqueStructTypes.begin(); + } + const_opaque_iterator end_opaque() const { return OpaqueStructTypes.end(); } + llvm::iterator_range range_opaque() { + return llvm::make_range(begin_opaque(), end_opaque()); + } }; IRMover(Module &M); diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Function.h" #include "llvm/IR/GVMaterializer.h" @@ -55,7 +56,14 @@ public: TypeMapTy(IRMover::IdentifiedStructTypeSet &DstStructTypesSet) - : DstStructTypesSet(DstStructTypesSet) {} + : DstStructTypesSet(DstStructTypesSet) { + // Existing destination types are mapped to themselves as they are already + // available. + for (StructType *OpaqueSTy : DstStructTypesSet.range_opaque()) + MappedTypes[OpaqueSTy] = OpaqueSTy; + for (StructType *NonOpaqueSTy : DstStructTypesSet.range_non_opaque()) + MappedTypes[NonOpaqueSTy] = NonOpaqueSTy; + } IRMover::IdentifiedStructTypeSet &DstStructTypesSet; /// Indicate that the specified type in the destination module is conceptually