llvm.org GIT mirror llvm / 1565077
Remap metadata attached to global variables. Fix for PR32577. Global variables may have !associated metadata, which includes a reference to another global. It needs remapping. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302203 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 2 years ago
2 changed file(s) with 23 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
120120
121121 void addFlags(RemapFlags Flags);
122122
123 void remapGlobalObjectMetadata(GlobalObject &GO);
124
123125 Value *mapValue(const Value *V);
124126 void remapInstruction(Instruction *I);
125127 void remapFunction(Function &F);
801803 switch (E.Kind) {
802804 case WorklistEntry::MapGlobalInit:
803805 E.Data.GVInit.GV->setInitializer(mapConstant(E.Data.GVInit.Init));
806 remapGlobalObjectMetadata(*E.Data.GVInit.GV);
804807 break;
805808 case WorklistEntry::MapAppendingVar: {
806809 unsigned PrefixSize = AppendingInits.size() - E.AppendingGVNumNewMembers;
891894 I->mutateType(TypeMapper->remapType(I->getType()));
892895 }
893896
897 void Mapper::remapGlobalObjectMetadata(GlobalObject &GO) {
898 SmallVector, 8> MDs;
899 GO.getAllMetadata(MDs);
900 GO.clearMetadata();
901 for (const auto &I : MDs)
902 GO.addMetadata(I.first, *cast(mapMetadata(I.second)));
903 }
904
894905 void Mapper::remapFunction(Function &F) {
895906 // Remap the operands.
896907 for (Use &Op : F.operands())
898909 Op = mapValue(Op);
899910
900911 // Remap the metadata attachments.
901 SmallVector, 8> MDs;
902 F.getAllMetadata(MDs);
903 F.clearMetadata();
904 for (const auto &I : MDs)
905 F.addMetadata(I.first, *cast(mapMetadata(I.second)));
912 remapGlobalObjectMetadata(F);
906913
907914 // Remap the argument types.
908915 if (TypeMapper)
0 ; RUN: llvm-link %s -S | FileCheck %s
1
2 ; CHECK-DAG: @a = global i32 0
3 ; CHECK-DAG: @b = global i32 0, !associated !0
4
5 ; CHECK-DAG: !0 = !{i32* @b}
6
7 @a = global i32 0
8 @b = global i32 0, !associated !0
9
10 !0 = !{i32* @b}