llvm.org GIT mirror llvm / f416d72
IR: Add 'distinct' MDNodes to bitcode and assembly Propagate whether `MDNode`s are 'distinct' through the other types of IR (assembly and bitcode). This adds the `distinct` keyword to assembly. Currently, no one actually calls `MDNode::getDistinct()`, so these nodes only get created for: - self-references, which are never uniqued, and - nodes whose operands are replaced that hit a uniquing collision. The concept of distinct nodes is still not quite first-class, since distinct-ness doesn't yet survive across `MapMetadata()`. Part of PR22111. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225474 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
20 changed file(s) with 110 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
28472847
28482848 !{ !"test\00", i32 10}
28492849
2850 Metadata nodes that aren't uniqued use the ``distinct`` keyword. For example:
2851
2852 .. code-block:: llvm
2853
2854 !0 = distinct !{!"test\00", i32 10}
2855
28502856 A :ref:`named metadata ` is a collection of
28512857 metadata nodes, which can be looked up in the module symbol table. For
28522858 example:
139139 METADATA_VALUE = 2, // VALUE: [type num, value num]
140140 METADATA_NODE = 3, // NODE: [n x md num]
141141 METADATA_NAME = 4, // STRING: [values]
142 // 5 is unused.
142 METADATA_DISTINCT_NODE = 5, // DISTINCT_NODE: [n x md num]
143143 METADATA_KIND = 6, // [n x [id, name]]
144144 // 7 is unused.
145145 METADATA_OLD_NODE = 8, // OLD_NODE: [n x (type num, value num)]
654654 KEYWORD(x);
655655 KEYWORD(blockaddress);
656656
657 // Metadata types.
658 KEYWORD(distinct);
659
657660 // Use-list order directives.
658661 KEYWORD(uselistorder);
659662 KEYWORD(uselistorder_bb);
617617 if (Lex.getKind() == lltok::Type)
618618 return TokError("unexpected type in metadata definition");
619619
620 bool IsDistinct = EatIfPresent(lltok::kw_distinct);
620621 if (ParseToken(lltok::exclaim, "Expected '!' here") ||
621 ParseMDNode(Init))
622 ParseMDNode(Init, IsDistinct))
622623 return true;
623624
624625 // See if this was forward referenced, if so, handle it.
29442945 return false;
29452946 }
29462947
2947 bool LLParser::ParseMDNode(MDNode *&MD) {
2948 bool LLParser::ParseMDNode(MDNode *&MD, bool IsDistinct) {
29482949 SmallVector Elts;
29492950 if (ParseMDNodeVector(Elts))
29502951 return true;
29512952
2952 MD = MDNode::get(Context, Elts);
2953 if (IsDistinct)
2954 MD = MDNode::getDistinct(Context, Elts);
2955 else
2956 MD = MDNode::get(Context, Elts);
29532957 return false;
29542958 }
29552959
388388 bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
389389 bool ParseValueAsMetadata(Metadata *&MD, PerFunctionState *PFS);
390390 bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
391 bool ParseMDNode(MDNode *&MD);
391 bool ParseMDNode(MDNode *&MD, bool IsDistinct = false);
392392 bool ParseMDNodeVector(SmallVectorImpl &MDs);
393393 bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
394394
181181 kw_extractelement, kw_insertelement, kw_shufflevector,
182182 kw_extractvalue, kw_insertvalue, kw_blockaddress,
183183
184 // Metadata types.
185 kw_distinct,
186
184187 // Use-list order directives.
185188 kw_uselistorder, kw_uselistorder_bb,
186189
11051105 // Read a record.
11061106 Record.clear();
11071107 unsigned Code = Stream.readRecord(Entry.ID, Record);
1108 bool IsDistinct = false;
11081109 switch (Code) {
11091110 default: // Default behavior: ignore.
11101111 break;
11951196 NextMDValueNo++);
11961197 break;
11971198 }
1199 case bitc::METADATA_DISTINCT_NODE:
1200 IsDistinct = true;
1201 // fallthrough...
11981202 case bitc::METADATA_NODE: {
11991203 SmallVector Elts;
12001204 Elts.reserve(Record.size());
12011205 for (unsigned ID : Record)
12021206 Elts.push_back(ID ? MDValueList.getValueFwdRef(ID - 1) : nullptr);
1203 MDValueList.AssignValue(MDNode::get(Context, Elts), NextMDValueNo++);
1207 MDValueList.AssignValue(IsDistinct ? MDNode::getDistinct(Context, Elts)
1208 : MDNode::get(Context, Elts),
1209 NextMDValueNo++);
12041210 break;
12051211 }
12061212 case bitc::METADATA_STRING: {
772772 assert(!isa(MD) && "Unexpected function-local metadata");
773773 Record.push_back(VE.getMetadataID(MD) + 1);
774774 }
775 Stream.EmitRecord(bitc::METADATA_NODE, Record);
775 Stream.EmitRecord(N->isDistinct() ? bitc::METADATA_DISTINCT_NODE
776 : bitc::METADATA_NODE,
777 Record);
776778 Record.clear();
777779 }
778780
12521252 TypePrinting *TypePrinter,
12531253 SlotTracker *Machine,
12541254 const Module *Context) {
1255 if (Node->isDistinct())
1256 Out << "distinct ";
12551257 Out << "!{";
12561258 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {
12571259 const Metadata *MD = Node->getOperand(mi);
0 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
1 ; RUN: verify-uselistorder %s
2
3 !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
4
5 !0 = !{}
6 !1 = !{} ; This should merge with !0.
7 !2 = !{!0}
8 !3 = !{!0} ; This should merge with !2.
9 !4 = distinct !{}
10 !5 = distinct !{}
11 !6 = distinct !{!0}
12 !7 = distinct !{!0}
13 !8 = distinct !{!8}
14 !9 = distinct !{!9}
15 !10 = !{!10} ; This should become distinct.
16
17 ; CHECK: !named = !{!0, !0, !1, !1, !2, !3, !4, !5, !6, !7, !8}
18 ; CHECK: !0 = !{}
19 ; CHECK-NEXT: !1 = !{!0}
20 ; CHECK-NEXT: !2 = distinct !{}
21 ; CHECK-NEXT: !3 = distinct !{}
22 ; CHECK-NEXT: !4 = distinct !{!0}
23 ; CHECK-NEXT: !5 = distinct !{!0}
24 ; CHECK-NEXT: !6 = distinct !{!6}
25 ; CHECK-NEXT: !7 = distinct !{!7}
26 ; CHECK-NEXT: !8 = distinct !{!8}
27 ; CHECK-NOT: !
3535 attributes #1 = { nounwind uwtable }
3636
3737 ; CHECK: !0 = !{!1}
38 ; CHECK: !1 = !{!1, !2, !"hello: %c"}
39 ; CHECK: !2 = !{!2, !"hello"}
38 ; CHECK: !1 = distinct !{!1, !2, !"hello: %c"}
39 ; CHECK: !2 = distinct !{!2, !"hello"}
4040 ; CHECK: !3 = !{!4}
41 ; CHECK: !4 = !{!4, !2, !"hello: %a"}
41 ; CHECK: !4 = distinct !{!4, !2, !"hello: %a"}
4242 ; CHECK: !5 = !{!4, !1}
4343
4646 attributes #0 = { nounwind uwtable }
4747
4848 !0 = !{!1}
49 !1 = !{!1, !2, !"hello: %a"}
50 !2 = !{!2, !"hello"}
49 !1 = distinct !{!1, !2, !"hello: %a"}
50 !2 = distinct !{!2, !"hello"}
5151 !3 = !{!4, !6}
52 !4 = !{!4, !5, !"hello2: %a"}
53 !5 = !{!5, !"hello2"}
54 !6 = !{!6, !5, !"hello2: %b"}
52 !4 = distinct !{!4, !5, !"hello2: %a"}
53 !5 = distinct !{!5, !"hello2"}
54 !6 = distinct !{!6, !5, !"hello2: %b"}
5555 !7 = !{!4}
5656 !8 = !{!6}
5757
5858 ; CHECK: !0 = !{!1, !3}
59 ; CHECK: !1 = !{!1, !2, !"hello2: %a"}
60 ; CHECK: !2 = !{!2, !"hello2"}
61 ; CHECK: !3 = !{!3, !2, !"hello2: %b"}
59 ; CHECK: !1 = distinct !{!1, !2, !"hello2: %a"}
60 ; CHECK: !2 = distinct !{!2, !"hello2"}
61 ; CHECK: !3 = distinct !{!3, !2, !"hello2: %b"}
6262 ; CHECK: !4 = !{!1}
6363 ; CHECK: !5 = !{!3}
6464 ; CHECK: !6 = !{!7, !9, !10}
65 ; CHECK: !7 = !{!7, !8, !"hello2: %a"}
66 ; CHECK: !8 = !{!8, !"hello2"}
67 ; CHECK: !9 = !{!9, !8, !"hello2: %b"}
68 ; CHECK: !10 = !{!10, !11, !"hello: %a"}
69 ; CHECK: !11 = !{!11, !"hello"}
65 ; CHECK: !7 = distinct !{!7, !8, !"hello2: %a"}
66 ; CHECK: !8 = distinct !{!8, !"hello2"}
67 ; CHECK: !9 = distinct !{!9, !8, !"hello2: %b"}
68 ; CHECK: !10 = distinct !{!10, !11, !"hello: %a"}
69 ; CHECK: !11 = distinct !{!11, !"hello"}
7070 ; CHECK: !12 = !{!7}
7171 ; CHECK: !13 = !{!9, !10}
7272 ; CHECK: !14 = !{!9}
7373 ; CHECK: !15 = !{!7, !10}
7474 ; CHECK: !16 = !{!10}
7575 ; CHECK: !17 = !{!18, !20}
76 ; CHECK: !18 = !{!18, !19, !"hello2: %a"}
77 ; CHECK: !19 = !{!19, !"hello2"}
78 ; CHECK: !20 = !{!20, !19, !"hello2: %b"}
76 ; CHECK: !18 = distinct !{!18, !19, !"hello2: %a"}
77 ; CHECK: !19 = distinct !{!19, !"hello2"}
78 ; CHECK: !20 = distinct !{!20, !19, !"hello2: %b"}
7979 ; CHECK: !21 = !{!18, !10}
8080 ; CHECK: !22 = !{!20}
8181 ; CHECK: !23 = !{!20, !10}
6464 attributes #0 = { nounwind uwtable }
6565
6666 ; CHECK: !0 = !{!1}
67 ; CHECK: !1 = !{!1, !2, !"hello: %a"}
68 ; CHECK: !2 = !{!2, !"hello"}
67 ; CHECK: !1 = distinct !{!1, !2, !"hello: %a"}
68 ; CHECK: !2 = distinct !{!2, !"hello"}
6969 ; CHECK: !3 = !{!4, !6}
70 ; CHECK: !4 = !{!4, !5, !"hello2: %a"}
71 ; CHECK: !5 = !{!5, !"hello2"}
72 ; CHECK: !6 = !{!6, !5, !"hello2: %b"}
70 ; CHECK: !4 = distinct !{!4, !5, !"hello2: %a"}
71 ; CHECK: !5 = distinct !{!5, !"hello2"}
72 ; CHECK: !6 = distinct !{!6, !5, !"hello2: %b"}
7373 ; CHECK: !7 = !{!4}
7474 ; CHECK: !8 = !{!6}
7575
7171 ; CHECK: }
7272
7373 ; CHECK: !0 = !{!1}
74 ; CHECK: !1 = !{!1, !2, !"hello: %c"}
75 ; CHECK: !2 = !{!2, !"hello"}
74 ; CHECK: !1 = distinct !{!1, !2, !"hello: %c"}
75 ; CHECK: !2 = distinct !{!2, !"hello"}
7676 ; CHECK: !3 = !{!4}
77 ; CHECK: !4 = !{!4, !2, !"hello: %a"}
77 ; CHECK: !4 = distinct !{!4, !2, !"hello: %a"}
7878 ; CHECK: !5 = !{!6, !8}
79 ; CHECK: !6 = !{!6, !7, !"hello: %c"}
80 ; CHECK: !7 = !{!7, !"hello"}
81 ; CHECK: !8 = !{!8, !9, !"foo: %c"}
82 ; CHECK: !9 = !{!9, !"foo"}
79 ; CHECK: !6 = distinct !{!6, !7, !"hello: %c"}
80 ; CHECK: !7 = distinct !{!7, !"hello"}
81 ; CHECK: !8 = distinct !{!8, !9, !"foo: %c"}
82 ; CHECK: !9 = distinct !{!9, !"foo"}
8383 ; CHECK: !10 = !{!11, !12}
84 ; CHECK: !11 = !{!11, !7, !"hello: %a"}
85 ; CHECK: !12 = !{!12, !9, !"foo: %a"}
84 ; CHECK: !11 = distinct !{!11, !7, !"hello: %a"}
85 ; CHECK: !12 = distinct !{!12, !9, !"foo: %a"}
8686 ; CHECK: !13 = !{!8}
8787 ; CHECK: !14 = !{!12}
8888 ; CHECK: !15 = !{!16, !18}
89 ; CHECK: !16 = !{!16, !17, !"hello2: %a"}
90 ; CHECK: !17 = !{!17, !"hello2"}
91 ; CHECK: !18 = !{!18, !17, !"hello2: %b"}
89 ; CHECK: !16 = distinct !{!16, !17, !"hello2: %a"}
90 ; CHECK: !17 = distinct !{!17, !"hello2"}
91 ; CHECK: !18 = distinct !{!18, !17, !"hello2: %b"}
9292 ; CHECK: !19 = !{!16}
9393 ; CHECK: !20 = !{!18}
9494
114114 ret i16 %res.0.lcssa
115115 }
116116
117 ; CHECK: !0 = !{!0, !1}
117 ; CHECK: !0 = distinct !{!0, !1}
118118 ; CHECK: !1 = !{!"llvm.loop.unroll.disable"}
119119
137137 !10 = !{!"llvm.loop.unroll.count", i32 2}
138138
139139
140 ; CHECK: ![[LOOP_1]] = !{![[LOOP_1]], ![[VEC_ENABLE:.*]], ![[WIDTH_8:.*]], ![[UNROLL_DISABLE:.*]]}
140 ; CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[VEC_ENABLE:.*]], ![[WIDTH_8:.*]], ![[UNROLL_DISABLE:.*]]}
141141 ; CHECK: ![[VEC_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}
142142 ; CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}
143143 ; CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
144 ; CHECK: ![[LOOP_2]] = !{![[LOOP_2]], ![[UNROLL_FULL:.*]]}
144 ; CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[UNROLL_FULL:.*]]}
145145 ; CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
146 ; CHECK: ![[LOOP_3]] = !{![[LOOP_3]], ![[UNROLL_DISABLE:.*]]}
147 ; CHECK: ![[LOOP_4]] = !{![[LOOP_4]], ![[UNROLL_DISABLE:.*]]}
148 ; CHECK: ![[LOOP_5]] = !{![[LOOP_5]], ![[UNROLL_DISABLE:.*]]}
146 ; CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNROLL_DISABLE:.*]]}
147 ; CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[UNROLL_DISABLE:.*]]}
148 ; CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_DISABLE:.*]]}
3838 }
3939
4040 ; Now, we check for the Hint metadata
41 ; CHECK: [[vect]] = !{[[vect]], [[width:![0-9]+]], [[unroll:![0-9]+]]}
41 ; CHECK: [[vect]] = distinct !{[[vect]], [[width:![0-9]+]], [[unroll:![0-9]+]]}
4242 ; CHECK: [[width]] = !{!"llvm.loop.vectorize.width", i32 1}
4343 ; CHECK: [[unroll]] = !{!"llvm.loop.interleave.count", i32 1}
44 ; CHECK: [[scalar]] = !{[[scalar]], [[width]], [[unroll]]}
44 ; CHECK: [[scalar]] = distinct !{[[scalar]], [[width]], [[unroll]]}
4545
6767
6868 attributes #0 = { nounwind readonly ssp uwtable "fp-contract-model"="standard" "no-frame-pointer-elim" "no-frame-pointer-elim-non-leaf" "realign-stack" "relocation-model"="pic" "ssp-buffers-size"="8" }
6969
70 ; CHECK: !0 = !{!0, !1, !2}
70 ; CHECK: !0 = distinct !{!0, !1, !2}
7171 ; CHECK: !1 = !{!"llvm.loop.vectorize.width", i32 1}
7272 ; CHECK: !2 = !{!"llvm.loop.interleave.count", i32 1}
73 ; CHECK: !3 = !{!3, !1, !2}
73 ; CHECK: !3 = distinct !{!3, !1, !2}
7474
7575 !0 = !{!0, !1}
7676 !1 = !{!"llvm.loop.vectorize.width", i32 1}
5252 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'words) . font-lock-keyword-face)
5353 ;; Aggregate ops
5454 `(,(regexp-opt '("extractvalue" "insertvalue") 'words) . font-lock-keyword-face)
55 ;; Metadata types
56 `(,(regexp-opt '("distinct") 'words) . font-lock-keyword-face)
5557 ;; Use-list order directives
5658 `(,(regexp-opt '("uselistorder" "uselistorder_bb") 'words) . font-lock-keyword-face)
5759
4040 syn keyword llvmKeyword arm_aapcscc arm_apcscc asm atomic available_externally
4141 syn keyword llvmKeyword blockaddress byval c catch cc ccc cleanup coldcc common
4242 syn keyword llvmKeyword constant datalayout declare default define deplibs
43 syn keyword llvmKeyword dllexport dllimport except extern_weak external
43 syn keyword llvmKeyword distinct dllexport dllimport except extern_weak external
4444 syn keyword llvmKeyword externally_initialized fastcc filter gc global hidden
4545 syn keyword llvmKeyword initialexec inlinehint inreg intel_ocl_bicc inteldialect
4646 syn keyword llvmKeyword internal linkonce linkonce_odr localdynamic localexec