llvm.org GIT mirror llvm / fd406f1
Revert r112091, "Remap metadata attached to instructions when remapping individual ...", which depends on r111922, which I am reverting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112157 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
5 changed file(s) with 17 addition(s) and 55 deletion(s). Raw diff Collapse all Expand all
10041004 // the Source function as operands. Loop through all of the operands of the
10051005 // functions and patch them up to point to the local versions...
10061006 //
1007 // This is the same as RemapInstruction, except that it avoids remapping
1008 // instruction and basic block operands.
1009 //
10101007 for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB)
1011 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
1012 // Remap operands.
1008 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
10131009 for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
10141010 OI != OE; ++OI)
10151011 if (!isa(*OI) && !isa(*OI))
10161012 *OI = MapValue(*OI, ValueMap);
1017
1018 // Remap attached metadata.
1019 SmallVector, 4> MDs;
1020 I->getAllMetadata(MDs);
1021 for (SmallVectorImpl >::iterator
1022 MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) {
1023 Value *Old = MI->second;
1024 if (!isa(Old) && !isa(Old)) {
1025 Value *New = MapValue(Old, ValueMap);
1026 if (New != Old)
1027 I->setMetadata(MI->first, cast(New));
1028 }
1029 }
1030 }
10311013
10321014 // There is no need to map the arguments anymore.
10331015 for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
131131 NewNMD->addOperand(cast(MapValue(NMD.getOperand(i), VMap)));
132132 }
133133
134 // Update metadata attach with instructions.
135 for (Module::iterator MI = New->begin(), ME = New->end(); MI != ME; ++MI)
136 for (Function::iterator FI = MI->begin(), FE = MI->end();
137 FI != FE; ++FI)
138 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
139 BI != BE; ++BI) {
140 SmallVector, 4 > MDs;
141 BI->getAllMetadata(MDs);
142 for (SmallVector, 4>::iterator
143 MDI = MDs.begin(), MDE = MDs.end(); MDI != MDE; ++MDI) {
144 Value *MappedValue = MapValue(MDI->second, VMap);
145 if (MDI->second != MappedValue && MappedValue)
146 BI->setMetadata(MDI->first, cast(MappedValue));
147 }
148 }
134149 return New;
135150 }
146146 /// current values into those specified by VMap.
147147 ///
148148 void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap) {
149 // Remap operands.
150149 for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) {
151150 Value *V = MapValue(*op, VMap);
152151 assert(V && "Referenced value not in value map!");
153152 *op = V;
154153 }
154 }
155155
156 // Remap attached metadata.
157 SmallVector, 4> MDs;
158 I->getAllMetadata(MDs);
159 for (SmallVectorImpl >::iterator
160 MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) {
161 Value *Old = MI->second;
162 Value *New = MapValue(Old, VMap);
163 if (New != Old)
164 I->setMetadata(MI->first, cast(New));
165 }
166 }
+0
-15
test/Linker/metadata-a.ll less more
None ; RUN: llvm-link %s %p/metadata-b.ll -S -o - | FileCheck %s
1
2 ; CHECK: define void @foo(i32 %a)
3 ; CHECK: ret void, !attach !0, !also !{i32 %a}
4 ; CHECK: define void @goo(i32 %b)
5 ; CHECK: ret void, !attach !1, !and !{i32 %b}
6 ; CHECK: !0 = metadata !{i32 524334, void (i32)* @foo}
7 ; CHECK: !1 = metadata !{i32 524334, void (i32)* @goo}
8
9 define void @foo(i32 %a) nounwind {
10 entry:
11 ret void, !attach !0, !also !{ i32 %a }
12 }
13
14 !0 = metadata !{i32 524334, void (i32)* @foo}
+0
-9
test/Linker/metadata-b.ll less more
None ; This file is for use with metadata-a.ll
1 ; RUN: true
2
3 define void @goo(i32 %b) nounwind {
4 entry:
5 ret void, !attach !0, !and !{ i32 %b }
6 }
7
8 !0 = metadata !{i32 524334, void (i32)* @goo}