llvm.org GIT mirror llvm / 68ee48f
Utils: Handle remapping distinct MDLocations Part of PR21433. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225921 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
3 changed file(s) with 46 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
184184 ValueMapTypeRemapper *TypeMapper,
185185 ValueMaterializer *Materializer,
186186 bool IsDistinct) {
187 // Distinct MDTuples have their own code path.
188 assert(!IsDistinct && "Unexpected distinct tuple");
189 (void)IsDistinct;
190
187191 SmallVector Elts;
188192 Elts.reserve(Node->getNumOperands());
189193 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I)
190194 Elts.push_back(mapMetadataOp(Node->getOperand(I), VM, Flags, TypeMapper,
191195 Materializer));
192196
193 return (IsDistinct ? MDTuple::getDistinct : MDTuple::get)(Node->getContext(),
194 Elts);
197 return MDTuple::get(Node->getContext(), Elts);
195198 }
196199
197200 static Metadata *cloneMDLocation(const MDLocation *Node, ValueToValueMapTy &VM,
229232 ValueMaterializer *Materializer) {
230233 assert(Node->isDistinct() && "Expected distinct node");
231234
232 // Create the node first so it's available for cyclical references.
233 SmallVector EmptyOps(Node->getNumOperands());
234 MDTuple *NewMD = MDTuple::getDistinct(Node->getContext(), EmptyOps);
235 mapToMetadata(VM, Node, NewMD);
236
237 // Fix the operands.
238 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I)
239 NewMD->replaceOperandWith(I, mapMetadataOp(Node->getOperand(I), VM, Flags,
240 TypeMapper, Materializer));
241
242 return NewMD;
235 // Optimization for MDTuples.
236 if (isa(Node)) {
237 // Create the node first so it's available for cyclical references.
238 SmallVector EmptyOps(Node->getNumOperands());
239 MDTuple *NewMD = MDTuple::getDistinct(Node->getContext(), EmptyOps);
240 mapToMetadata(VM, Node, NewMD);
241
242 // Fix the operands.
243 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I)
244 NewMD->replaceOperandWith(I, mapMetadataOp(Node->getOperand(I), VM, Flags,
245 TypeMapper, Materializer));
246
247 return NewMD;
248 }
249
250 // In general we need a dummy node, since whether the operands are null can
251 // affect the size of the node.
252 std::unique_ptr Dummy(
253 MDNode::getTemporary(Node->getContext(), None));
254 mapToMetadata(VM, Node, Dummy.get());
255 Metadata *NewMD = cloneMDNode(Node, VM, Flags, TypeMapper, Materializer,
256 /* IsDistinct */ true);
257 Dummy->replaceAllUsesWith(NewMD);
258 return mapToMetadata(VM, Node, NewMD);
243259 }
244260
245261 /// \brief Check whether a uniqued node needs to be remapped.
None !named = !{!0, !1, !2, !3, !4, !5, !6, !7}
0 !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
11
22 !0 = !{} ; Use this as a scope.
33 !1 = !MDLocation(line: 3, column: 7, scope: !0)
77 !5 = !MDLocation(line: 3, column: 7, scope: !4)
88 !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
99 !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
10 ; Test distinct nodes.
11 !8 = distinct !MDLocation(line: 3, column: 7, scope: !0)
12 !9 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !8)
11
22 ; Test that MDLocations are remapped properly.
33
4 ; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !0, !1, !2, !3, !8, !9, !10, !11}
5 !named = !{!0, !1, !2, !3, !4, !5, !6, !7}
4 ; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !0, !1, !2, !3, !10, !11, !12, !13, !14, !15}
5 !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
66
77 ; CHECK: !0 = !{}
88 ; CHECK-NEXT: !1 = !MDLocation(line: 3, column: 7, scope: !0)
1212 ; CHECK-NEXT: !5 = !MDLocation(line: 3, column: 7, scope: !4)
1313 ; CHECK-NEXT: !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
1414 ; CHECK-NEXT: !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
15 ; CHECK-NEXT: !8 = distinct !{}
16 ; CHECK-NEXT: !9 = !MDLocation(line: 3, column: 7, scope: !8)
17 ; CHECK-NEXT: !10 = !MDLocation(line: 3, column: 7, scope: !8, inlinedAt: !9)
18 ; CHECK-NEXT: !11 = !MDLocation(line: 3, column: 7, scope: !8, inlinedAt: !10)
15 ; CHECK-NEXT: !8 = distinct !MDLocation(line: 3, column: 7, scope: !0)
16 ; CHECK-NEXT: !9 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !8)
17 ; CHECK-NEXT: !10 = distinct !{}
18 ; CHECK-NEXT: !11 = !MDLocation(line: 3, column: 7, scope: !10)
19 ; CHECK-NEXT: !12 = !MDLocation(line: 3, column: 7, scope: !10, inlinedAt: !11)
20 ; CHECK-NEXT: !13 = !MDLocation(line: 3, column: 7, scope: !10, inlinedAt: !12)
21 ; CHECK-NEXT: !14 = distinct !MDLocation(line: 3, column: 7, scope: !0)
22 ; CHECK-NEXT: !15 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !14)
1923 !0 = !{} ; Use this as a scope.
2024 !1 = !MDLocation(line: 3, column: 7, scope: !0)
2125 !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
2428 !5 = !MDLocation(line: 3, column: 7, scope: !4)
2529 !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
2630 !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
31 ; Test distinct nodes.
32 !8 = distinct !MDLocation(line: 3, column: 7, scope: !0)
33 !9 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !8)