@@ -78,16 +78,6 @@ struct OrderMap {
78
78
79
79
} // end anonymous namespace
80
80
81
- // / Look for a value that might be wrapped as metadata, e.g. a value in a
82
- // / metadata operand. Returns nullptr for a non-wrapped input value if
83
- // / OnlyWrapped is true, or it returns the input value as-is if false.
84
- static const Value *skipMetadataWrapper (const Value *V, bool OnlyWrapped) {
85
- if (const auto *MAV = dyn_cast<MetadataAsValue>(V))
86
- if (const auto *VAM = dyn_cast<ValueAsMetadata>(MAV->getMetadata ()))
87
- return VAM->getValue ();
88
- return OnlyWrapped ? nullptr : V;
89
- }
90
-
91
81
static void orderValue (const Value *V, OrderMap &OM) {
92
82
if (OM.lookup (V).first )
93
83
return ;
@@ -139,16 +129,25 @@ static OrderMap orderModule(const Module &M) {
139
129
// these before global values, as these will be read before setting the
140
130
// global values' initializers. The latter matters for constants which have
141
131
// uses towards other constants that are used as initializers.
132
+ auto orderConstantValue = [&OM](const Value *V) {
133
+ if ((isa<Constant>(V) && !isa<GlobalValue>(V)) || isa<InlineAsm>(V))
134
+ orderValue (V, OM);
135
+ };
142
136
for (const Function &F : M) {
143
137
if (F.isDeclaration ())
144
138
continue ;
145
139
for (const BasicBlock &BB : F)
146
140
for (const Instruction &I : BB)
147
141
for (const Value *V : I.operands ()) {
148
- if (const Value *Op = skipMetadataWrapper (V, true )) {
149
- if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) ||
150
- isa<InlineAsm>(*Op))
151
- orderValue (Op, OM);
142
+ if (const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
143
+ if (const auto *VAM =
144
+ dyn_cast<ValueAsMetadata>(MAV->getMetadata ())) {
145
+ orderConstantValue (VAM->getValue ());
146
+ } else if (const auto *AL =
147
+ dyn_cast<DIArgList>(MAV->getMetadata ())) {
148
+ for (const auto *VAM : AL->getArgs ())
149
+ orderConstantValue (VAM->getValue ());
150
+ }
152
151
}
153
152
}
154
153
}
@@ -448,10 +447,17 @@ ValueEnumerator::ValueEnumerator(const Module &M,
448
447
continue ;
449
448
}
450
449
451
- // Local metadata is enumerated during function-incorporation.
452
- if (isa<LocalAsMetadata>(MD->getMetadata ()) ||
453
- isa<DIArgList>(MD->getMetadata ()))
450
+ // Local metadata is enumerated during function-incorporation, but
451
+ // any ConstantAsMetadata arguments in a DIArgList should be examined
452
+ // now.
453
+ if (isa<LocalAsMetadata>(MD->getMetadata ()))
454
+ continue ;
455
+ if (auto *AL = dyn_cast<DIArgList>(MD->getMetadata ())) {
456
+ for (auto *VAM : AL->getArgs ())
457
+ if (isa<ConstantAsMetadata>(VAM))
458
+ EnumerateMetadata (&F, VAM);
454
459
continue ;
460
+ }
455
461
456
462
EnumerateMetadata (&F, MD->getMetadata ());
457
463
}
@@ -620,6 +626,11 @@ void ValueEnumerator::EnumerateFunctionLocalMetadata(
620
626
EnumerateFunctionLocalMetadata (getMetadataFunctionID (&F), Local);
621
627
}
622
628
629
+ void ValueEnumerator::EnumerateFunctionLocalListMetadata (
630
+ const Function &F, const DIArgList *ArgList) {
631
+ EnumerateFunctionLocalListMetadata (getMetadataFunctionID (&F), ArgList);
632
+ }
633
+
623
634
void ValueEnumerator::dropFunctionFromMetadata (
624
635
MetadataMapType::value_type &FirstMD) {
625
636
SmallVector<const MDNode *, 64 > Worklist;
@@ -730,7 +741,7 @@ const MDNode *ValueEnumerator::enumerateMetadataImpl(unsigned F, const Metadata
730
741
return nullptr ;
731
742
}
732
743
733
- // / EnumerateFunctionLocalMetadataa - Incorporate function-local metadata
744
+ // / EnumerateFunctionLocalMetadata - Incorporate function-local metadata
734
745
// / information reachable from the metadata.
735
746
void ValueEnumerator::EnumerateFunctionLocalMetadata (
736
747
unsigned F, const LocalAsMetadata *Local) {
@@ -750,6 +761,39 @@ void ValueEnumerator::EnumerateFunctionLocalMetadata(
750
761
EnumerateValue (Local->getValue ());
751
762
}
752
763
764
+ // / EnumerateFunctionLocalListMetadata - Incorporate function-local metadata
765
+ // / information reachable from the metadata.
766
+ void ValueEnumerator::EnumerateFunctionLocalListMetadata (
767
+ unsigned F, const DIArgList *ArgList) {
768
+ assert (F && " Expected a function" );
769
+
770
+ // Check to see if it's already in!
771
+ MDIndex &Index = MetadataMap[ArgList];
772
+ if (Index.ID ) {
773
+ assert (Index.F == F && " Expected the same function" );
774
+ return ;
775
+ }
776
+
777
+ for (ValueAsMetadata *VAM : ArgList->getArgs ()) {
778
+ if (isa<LocalAsMetadata>(VAM)) {
779
+ assert (MetadataMap.count (VAM) &&
780
+ " LocalAsMetadata should be enumerated before DIArgList" );
781
+ assert (MetadataMap[VAM].F == F &&
782
+ " Expected LocalAsMetadata in the same function" );
783
+ } else {
784
+ assert (isa<ConstantAsMetadata>(VAM) &&
785
+ " Expected LocalAsMetadata or ConstantAsMetadata" );
786
+ assert (ValueMap.count (VAM->getValue ()) &&
787
+ " Constant should be enumerated beforeDIArgList" );
788
+ EnumerateMetadata (F, VAM);
789
+ }
790
+ }
791
+
792
+ MDs.push_back (ArgList);
793
+ Index.F = F;
794
+ Index.ID = MDs.size ();
795
+ }
796
+
753
797
static unsigned getMetadataTypeOrder (const Metadata *MD) {
754
798
// Strings are emitted in bulk and must come first.
755
799
if (isa<MDString>(MD))
@@ -1072,7 +1116,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
1072
1116
// DIArgList entries must come after function-local metadata, as it is not
1073
1117
// possible to forward-reference them.
1074
1118
for (const DIArgList *ArgList : ArgListMDVector)
1075
- EnumerateMetadata (& F, ArgList);
1119
+ EnumerateFunctionLocalListMetadata ( F, ArgList);
1076
1120
}
1077
1121
1078
1122
void ValueEnumerator::purgeFunction () {
0 commit comments