diff --git a/llvm/include/llvm/Transforms/Utils/ValueMapper.h b/llvm/include/llvm/Transforms/Utils/ValueMapper.h --- a/llvm/include/llvm/Transforms/Utils/ValueMapper.h +++ b/llvm/include/llvm/Transforms/Utils/ValueMapper.h @@ -158,8 +158,7 @@ /// Returns a MappingContextID that can be used with the various schedule*() /// API to switch in a different value map on-the-fly. unsigned - registerAlternateMappingContext(ValueToValueMapTy &VM, - ValueMaterializer *Materializer = nullptr); + registerAlternateMappingContext(ValueMaterializer *Materializer = nullptr); /// Add to the current \a RemapFlags. /// 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 @@ -393,7 +393,6 @@ /// due to the use of Value handles which the Linker doesn't actually need, /// but this allows us to reuse the ValueMapper code. ValueToValueMapTy ValueMap; - ValueToValueMapTy IndirectSymbolValueMap; DenseSet ValuesToLink; std::vector Worklist; @@ -529,8 +528,8 @@ SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport), Mapper(ValueMap, RF_ReuseAndMutateDistinctMDs | RF_IgnoreMissingLocals, &TypeMap, &GValMaterializer), - IndirectSymbolMCID(Mapper.registerAlternateMappingContext( - IndirectSymbolValueMap, &LValMaterializer)) { + IndirectSymbolMCID( + Mapper.registerAlternateMappingContext(&LValMaterializer)) { ValueMap.getMDMap() = std::move(SharedMDs); for (GlobalValue *GV : ValuesToLink) maybeAdd(GV); @@ -990,10 +989,6 @@ auto I = ValueMap.find(SGV); if (I != ValueMap.end()) return cast(I->second); - - I = IndirectSymbolValueMap.find(SGV); - if (I != IndirectSymbolValueMap.end()) - return cast(I->second); } if (!ShouldLink && ForIndirectSymbol) @@ -1470,8 +1465,7 @@ Worklist.pop_back(); // Already mapped. - if (ValueMap.find(GV) != ValueMap.end() || - IndirectSymbolValueMap.find(GV) != IndirectSymbolValueMap.end()) + if (ValueMap.find(GV) != ValueMap.end()) continue; assert(!GV->isDeclaration()); diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -96,27 +96,14 @@ } Data; }; -struct MappingContext { - ValueToValueMapTy *VM; - ValueMaterializer *Materializer = nullptr; - - /// Construct a MappingContext with a value map and materializer. - explicit MappingContext(ValueToValueMapTy &VM, - ValueMaterializer *Materializer = nullptr) - : VM(&VM), Materializer(Materializer) {} -}; - class Mapper { friend class MDNodeMapper; -#ifndef NDEBUG - DenseSet AlreadyScheduled; -#endif - RemapFlags Flags; ValueMapTypeRemapper *TypeMapper; + ValueToValueMapTy &VM; unsigned CurrentMCID = 0; - SmallVector MCs; + SmallVector MCs; SmallVector Worklist; SmallVector DelayedBBs; SmallVector AppendingInits; @@ -124,8 +111,7 @@ public: Mapper(ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer) - : Flags(Flags), TypeMapper(TypeMapper), - MCs(1, MappingContext(VM, Materializer)) {} + : Flags(Flags), TypeMapper(TypeMapper), VM(VM), MCs(1, Materializer) {} /// ValueMapper should explicitly call \a flush() before destruction. ~Mapper() { assert(!hasWorkToDo() && "Expected to be flushed"); } @@ -133,9 +119,8 @@ bool hasWorkToDo() const { return !Worklist.empty(); } unsigned - registerAlternateMappingContext(ValueToValueMapTy &VM, - ValueMaterializer *Materializer = nullptr) { - MCs.push_back(MappingContext(VM, Materializer)); + registerAlternateMappingContext(ValueMaterializer *Materializer = nullptr) { + MCs.push_back(Materializer); return MCs.size() - 1; } @@ -174,8 +159,8 @@ bool IsOldCtorDtor, ArrayRef NewMembers); - ValueToValueMapTy &getVM() { return *MCs[CurrentMCID].VM; } - ValueMaterializer *getMaterializer() { return MCs[CurrentMCID].Materializer; } + ValueToValueMapTy &getVM() { return VM; } + ValueMaterializer *getMaterializer() { return MCs[CurrentMCID]; } Value *mapBlockAddress(const BlockAddress &BA); @@ -1038,7 +1023,6 @@ void Mapper::scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MCID) { - assert(AlreadyScheduled.insert(&GV).second && "Should not reschedule"); assert(MCID < MCs.size() && "Invalid mapping context"); WorklistEntry WE; @@ -1054,7 +1038,6 @@ bool IsOldCtorDtor, ArrayRef NewMembers, unsigned MCID) { - assert(AlreadyScheduled.insert(&GV).second && "Should not reschedule"); assert(MCID < MCs.size() && "Invalid mapping context"); WorklistEntry WE; @@ -1070,7 +1053,6 @@ void Mapper::scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, Constant &Target, unsigned MCID) { - assert(AlreadyScheduled.insert(&GIS).second && "Should not reschedule"); assert(MCID < MCs.size() && "Invalid mapping context"); WorklistEntry WE; @@ -1082,7 +1064,6 @@ } void Mapper::scheduleRemapFunction(Function &F, unsigned MCID) { - assert(AlreadyScheduled.insert(&F).second && "Should not reschedule"); assert(MCID < MCs.size() && "Invalid mapping context"); WorklistEntry WE; @@ -1126,9 +1107,8 @@ ValueMapper::~ValueMapper() { delete getAsMapper(pImpl); } unsigned -ValueMapper::registerAlternateMappingContext(ValueToValueMapTy &VM, - ValueMaterializer *Materializer) { - return getAsMapper(pImpl)->registerAlternateMappingContext(VM, Materializer); +ValueMapper::registerAlternateMappingContext(ValueMaterializer *Materializer) { + return getAsMapper(pImpl)->registerAlternateMappingContext(Materializer); } void ValueMapper::addFlags(RemapFlags Flags) { diff --git a/llvm/test/Linker/global-alias-value-map.ll b/llvm/test/Linker/global-alias-value-map.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Linker/global-alias-value-map.ll @@ -0,0 +1,16 @@ +; RUN: llvm-link %s -o /dev/null + +@gv0 = constant i8* bitcast (void ()* @function to i8*) + +@alias = alias i32, getelementptr (i32, i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @gv1, i32 0, i32 0), i32 0) + +@gv1 = constant <{ i32, i32 }> <{ i32 0, i32 trunc (i64 sub (i64 ptrtoint (<{ i32, i32 }>* @gv2 to i64), i64 ptrtoint (i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @gv1, i32 0, i32 0) to i64)) to i32)}> + +@gv2 = constant <{ i32, i32 }> <{ i32 0, i32 0 }> + +define linkonce_odr hidden void @function() { + %1 = call i8** @external(i32* @alias) + ret void +} + +declare i8** @external(i32*)