llvm.org GIT mirror llvm / 74195b2
Utils: Add mapping for uniqued MDLocations Still doesn't handle distinct ones. Part of PR21433. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225914 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
3 changed file(s) with 60 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
218218 return false;
219219 }
220220
221 static Metadata *cloneMDTuple(const UniquableMDNode *Node,
222 ValueToValueMapTy &VM, RemapFlags Flags,
221 static Metadata *cloneMDTuple(const MDTuple *Node, ValueToValueMapTy &VM,
222 RemapFlags Flags,
223223 ValueMapTypeRemapper *TypeMapper,
224224 ValueMaterializer *Materializer) {
225225 SmallVector Elts;
231231 return MDTuple::get(Node->getContext(), Elts);
232232 }
233233
234 static Metadata *cloneMDLocation(const MDLocation *Node, ValueToValueMapTy &VM,
235 RemapFlags Flags,
236 ValueMapTypeRemapper *TypeMapper,
237 ValueMaterializer *Materializer) {
238 return MDLocation::get(
239 Node->getContext(), Node->getLine(), Node->getColumn(),
240 mapMetadataOp(Node->getScope(), VM, Flags, TypeMapper, Materializer),
241 mapMetadataOp(Node->getInlinedAt(), VM, Flags, TypeMapper, Materializer));
242 }
243
234244 /// \brief Map a uniqued MDNode.
235245 ///
236246 /// Uniqued nodes may not need to be recreated (they may map to themselves).
253263 }
254264
255265 // At least one operand needs remapping.
256 Metadata *NewMD = cloneMDTuple(Node, VM, Flags, TypeMapper, Materializer);
266 Metadata *NewMD;
267 switch (Node->getMetadataID()) {
268 default:
269 llvm_unreachable("Invalid UniquableMDNode subclass");
270 #define HANDLE_UNIQUABLE_LEAF(CLASS) \
271 case Metadata::CLASS##Kind: \
272 NewMD = \
273 clone##CLASS(cast(Node), VM, Flags, TypeMapper, Materializer); \
274 break;
275 #include "llvm/IR/Metadata.def"
276 }
257277 Dummy->replaceAllUsesWith(NewMD);
258278 MDNode::deleteTemporary(Dummy);
259279 return mapToMetadata(VM, Node, NewMD);
0 !named = !{!0, !1, !2, !3, !4, !5, !6, !7}
1
2 !0 = !{} ; Use this as a scope.
3 !1 = !MDLocation(line: 3, column: 7, scope: !0)
4 !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
5 !3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
6 !4 = distinct !{} ; Test actual remapping.
7 !5 = !MDLocation(line: 3, column: 7, scope: !4)
8 !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
9 !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
0 ; RUN: llvm-link %s %S/Inputs/mdlocation.ll -o - -S | FileCheck %s
1
2 ; Test that MDLocations are remapped properly.
3
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}
6
7 ; CHECK: !0 = !{}
8 ; CHECK-NEXT: !1 = !MDLocation(line: 3, column: 7, scope: !0)
9 ; CHECK-NEXT: !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
10 ; CHECK-NEXT: !3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
11 ; CHECK-NEXT: !4 = distinct !{}
12 ; CHECK-NEXT: !5 = !MDLocation(line: 3, column: 7, scope: !4)
13 ; CHECK-NEXT: !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
14 ; 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)
19 !0 = !{} ; Use this as a scope.
20 !1 = !MDLocation(line: 3, column: 7, scope: !0)
21 !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
22 !3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
23 !4 = distinct !{} ; Test actual remapping.
24 !5 = !MDLocation(line: 3, column: 7, scope: !4)
25 !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
26 !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)