@@ -81,6 +81,11 @@ collectPfmCounters(const RecordKeeper &Records) {
8181 " duplicate ResourceName " + ResourceName);
8282 AddPfmCounterName (IssueCounter);
8383 }
84+
85+ for (const Record *ValidationCounter :
86+ Def->getValueAsListOfDefs (" ValidationCounters" ))
87+ AddPfmCounterName (ValidationCounter);
88+
8489 AddPfmCounterName (Def->getValueAsDef (" CycleCounter" ));
8590 AddPfmCounterName (Def->getValueAsDef (" UopsCounter" ));
8691 }
@@ -100,6 +105,17 @@ ExegesisEmitter::ExegesisEmitter(RecordKeeper &RK)
100105 Target = std::string (Targets[0 ]->getName ());
101106}
102107
108+ struct ValidationCounterInfo {
109+ int64_t EventNumber;
110+ StringRef EventName;
111+ unsigned PfmCounterID;
112+ };
113+
114+ bool EventNumberLess (const ValidationCounterInfo &LHS,
115+ const ValidationCounterInfo &RHS) {
116+ return LHS.EventNumber < RHS.EventNumber ;
117+ }
118+
103119void ExegesisEmitter::emitPfmCountersInfo (const Record &Def,
104120 unsigned &IssueCountersTableOffset,
105121 raw_ostream &OS) const {
@@ -109,6 +125,31 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
109125 Def.getValueAsDef (" UopsCounter" )->getValueAsString (" Counter" );
110126 const size_t NumIssueCounters =
111127 Def.getValueAsListOfDefs (" IssueCounters" ).size ();
128+ const size_t NumValidationCounters =
129+ Def.getValueAsListOfDefs (" ValidationCounters" ).size ();
130+
131+ // Emit Validation Counters Array
132+ if (NumValidationCounters != 0 ) {
133+ std::vector<ValidationCounterInfo> ValidationCounters;
134+ ValidationCounters.reserve (NumValidationCounters);
135+ for (const Record *ValidationCounter :
136+ Def.getValueAsListOfDefs (" ValidationCounters" )) {
137+ ValidationCounters.push_back (
138+ {ValidationCounter->getValueAsDef (" EventType" )
139+ ->getValueAsInt (" EventNumber" ),
140+ ValidationCounter->getValueAsDef (" EventType" )->getName (),
141+ getPfmCounterId (ValidationCounter->getValueAsString (" Counter" ))});
142+ }
143+ std::sort (ValidationCounters.begin (), ValidationCounters.end (),
144+ EventNumberLess);
145+ OS << " \n static const std::pair<ValidationEvent, const char*> " << Target
146+ << Def.getName () << " ValidationCounters[] = {\n " ;
147+ for (const ValidationCounterInfo &VCI : ValidationCounters) {
148+ OS << " { " << VCI.EventName << " , " << Target << " PfmCounterNames["
149+ << VCI.PfmCounterID << " ]},\n " ;
150+ }
151+ OS << " };\n " ;
152+ }
112153
113154 OS << " \n static const PfmCountersInfo " << Target << Def.getName ()
114155 << " = {\n " ;
@@ -129,10 +170,17 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
129170
130171 // Issue Counters
131172 if (NumIssueCounters == 0 )
132- OS << " nullptr, // No issue counters. \n 0 \n " ;
173+ OS << " nullptr, 0, // No issue counters\n " ;
133174 else
134175 OS << " " << Target << " PfmIssueCounters + " << IssueCountersTableOffset
135- << " , " << NumIssueCounters << " // Issue counters.\n " ;
176+ << " , " << NumIssueCounters << " , // Issue counters.\n " ;
177+
178+ // Validation Counters
179+ if (NumValidationCounters == 0 )
180+ OS << " nullptr, 0 // No validation counters.\n " ;
181+ else
182+ OS << " " << Target << Def.getName () << " ValidationCounters, "
183+ << NumValidationCounters << " // Validation counters.\n " ;
136184
137185 OS << " };\n " ;
138186 IssueCountersTableOffset += NumIssueCounters;
0 commit comments