@@ -43,6 +43,8 @@ using namespace llvm;
43
43
44
44
namespace {
45
45
46
+ using FeatureMapTy = DenseMap<const Record *, unsigned >;
47
+
46
48
// / Sorting predicate to sort record pointers by their
47
49
// / FieldName field.
48
50
struct LessRecordFieldFieldName {
@@ -81,22 +83,22 @@ class SubtargetEmitter {
81
83
};
82
84
83
85
CodeGenTarget TGT;
84
- RecordKeeper &Records;
86
+ const RecordKeeper &Records;
85
87
CodeGenSchedModels &SchedModels;
86
88
std::string Target;
87
89
88
- void Enumeration (raw_ostream &OS, DenseMap<Record *, unsigned > &FeatureMap );
90
+ FeatureMapTy Enumeration (raw_ostream &OS);
89
91
void EmitSubtargetInfoMacroCalls (raw_ostream &OS);
90
- unsigned FeatureKeyValues (raw_ostream &OS,
91
- const DenseMap<Record *, unsigned > &FeatureMap);
92
- unsigned CPUKeyValues (raw_ostream &OS,
93
- const DenseMap<Record *, unsigned > &FeatureMap);
94
- void FormItineraryStageString (const std::string &Names, Record *ItinData,
95
- std::string &ItinString, unsigned &NStages);
96
- void FormItineraryOperandCycleString (Record *ItinData,
92
+ unsigned FeatureKeyValues (raw_ostream &OS, const FeatureMapTy &FeatureMap);
93
+ unsigned CPUKeyValues (raw_ostream &OS, const FeatureMapTy &FeatureMap);
94
+ void FormItineraryStageString (const std::string &Names,
95
+ const Record *ItinData, std::string &ItinString,
96
+ unsigned &NStages);
97
+ void FormItineraryOperandCycleString (const Record *ItinData,
97
98
std::string &ItinString,
98
99
unsigned &NOperandCycles);
99
- void FormItineraryBypassString (const std::string &Names, Record *ItinData,
100
+ void FormItineraryBypassString (const std::string &Names,
101
+ const Record *ItinData,
100
102
std::string &ItinString,
101
103
unsigned NOperandCycles);
102
104
void EmitStageAndOperandCycleData (
@@ -139,7 +141,7 @@ class SubtargetEmitter {
139
141
void ParseFeaturesFunction (raw_ostream &OS);
140
142
141
143
public:
142
- SubtargetEmitter (RecordKeeper &R)
144
+ SubtargetEmitter (const RecordKeeper &R)
143
145
: TGT(R), Records(R), SchedModels(TGT.getSchedModels()),
144
146
Target (TGT.getName()) {}
145
147
@@ -151,16 +153,13 @@ class SubtargetEmitter {
151
153
//
152
154
// Enumeration - Emit the specified class as an enumeration.
153
155
//
154
- void SubtargetEmitter::Enumeration (raw_ostream &OS,
155
- DenseMap<Record *, unsigned > &FeatureMap) {
156
- // Get all records of class and sort
157
- std::vector<Record *> DefList =
156
+ FeatureMapTy SubtargetEmitter::Enumeration (raw_ostream &OS) {
157
+ ArrayRef<const Record *> DefList =
158
158
Records.getAllDerivedDefinitions (" SubtargetFeature" );
159
- llvm::sort (DefList, LessRecord ());
160
159
161
160
unsigned N = DefList.size ();
162
161
if (N == 0 )
163
- return ;
162
+ return FeatureMapTy () ;
164
163
if (N + 1 > MAX_SUBTARGET_FEATURES)
165
164
PrintFatalError (
166
165
" Too many subtarget features! Bump MAX_SUBTARGET_FEATURES." );
@@ -170,10 +169,11 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS,
170
169
// Open enumeration.
171
170
OS << " enum {\n " ;
172
171
172
+ FeatureMapTy FeatureMap;
173
173
// For each record
174
174
for (unsigned i = 0 ; i < N; ++i) {
175
175
// Next record
176
- Record *Def = DefList[i];
176
+ const Record *Def = DefList[i];
177
177
178
178
// Get and emit name
179
179
OS << " " << Def->getName () << " = " << i << " ,\n " ;
@@ -188,10 +188,12 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS,
188
188
// Close enumeration and namespace
189
189
OS << " };\n " ;
190
190
OS << " } // end namespace " << Target << " \n " ;
191
+ return FeatureMap;
191
192
}
192
193
193
- static void printFeatureMask (raw_ostream &OS, RecVec &FeatureList,
194
- const DenseMap<Record *, unsigned > &FeatureMap) {
194
+ static void printFeatureMask (raw_ostream &OS,
195
+ ArrayRef<const Record *> FeatureList,
196
+ const FeatureMapTy &FeatureMap) {
195
197
std::array<uint64_t , MAX_SUBTARGET_WORDS> Mask = {};
196
198
for (const Record *Feature : FeatureList) {
197
199
unsigned Bit = FeatureMap.lookup (Feature);
@@ -212,7 +214,7 @@ static void printFeatureMask(raw_ostream &OS, RecVec &FeatureList,
212
214
void SubtargetEmitter::EmitSubtargetInfoMacroCalls (raw_ostream &OS) {
213
215
OS << " \n #ifdef GET_SUBTARGETINFO_MACRO\n " ;
214
216
215
- std::vector<Record *> FeatureList =
217
+ std::vector<const Record *> FeatureList =
216
218
Records.getAllDerivedDefinitions (" SubtargetFeature" );
217
219
llvm::sort (FeatureList, LessRecordFieldFieldName ());
218
220
@@ -250,11 +252,10 @@ void SubtargetEmitter::EmitSubtargetInfoMacroCalls(raw_ostream &OS) {
250
252
// FeatureKeyValues - Emit data of all the subtarget features. Used by the
251
253
// command line.
252
254
//
253
- unsigned SubtargetEmitter::FeatureKeyValues (
254
- raw_ostream &OS, const DenseMap<Record *, unsigned > &FeatureMap) {
255
- const RecordKeeper &RCConst = Records;
255
+ unsigned SubtargetEmitter::FeatureKeyValues (raw_ostream &OS,
256
+ const FeatureMapTy &FeatureMap) {
256
257
std::vector<const Record *> FeatureList =
257
- RCConst .getAllDerivedDefinitions (" SubtargetFeature" );
258
+ Records .getAllDerivedDefinitions (" SubtargetFeature" );
258
259
259
260
// Remove features with empty name.
260
261
llvm::erase_if (FeatureList, [](const Record *Rec) {
@@ -300,11 +301,10 @@ unsigned SubtargetEmitter::FeatureKeyValues(
300
301
// CPUKeyValues - Emit data of all the subtarget processors. Used by command
301
302
// line.
302
303
//
303
- unsigned
304
- SubtargetEmitter::CPUKeyValues (raw_ostream &OS,
305
- const DenseMap<Record *, unsigned > &FeatureMap) {
304
+ unsigned SubtargetEmitter::CPUKeyValues (raw_ostream &OS,
305
+ const FeatureMapTy &FeatureMap) {
306
306
// Gather and sort processor information
307
- std::vector<Record *> ProcessorList =
307
+ std::vector<const Record *> ProcessorList =
308
308
Records.getAllDerivedDefinitions (" Processor" );
309
309
llvm::sort (ProcessorList, LessRecordFieldName ());
310
310
@@ -318,7 +318,7 @@ SubtargetEmitter::CPUKeyValues(raw_ostream &OS,
318
318
<< " extern const llvm::SubtargetSubTypeKV " << Target
319
319
<< " SubTypeKV[] = {\n " ;
320
320
321
- for (Record *Processor : ProcessorList) {
321
+ for (const Record *Processor : ProcessorList) {
322
322
StringRef Name = Processor->getValueAsString (" Name" );
323
323
RecVec FeatureList = Processor->getValueAsListOfDefs (" Features" );
324
324
RecVec TuneFeatureList = Processor->getValueAsListOfDefs (" TuneFeatures" );
@@ -349,11 +349,11 @@ SubtargetEmitter::CPUKeyValues(raw_ostream &OS,
349
349
// of stages.
350
350
//
351
351
void SubtargetEmitter::FormItineraryStageString (const std::string &Name,
352
- Record *ItinData,
352
+ const Record *ItinData,
353
353
std::string &ItinString,
354
354
unsigned &NStages) {
355
355
// Get states list
356
- RecVec StageList = ItinData->getValueAsListOfDefs (" Stages" );
356
+ ConstRecVec StageList = ItinData->getValueAsListOfConstDefs (" Stages" );
357
357
358
358
// For each stage
359
359
unsigned N = NStages = StageList.size ();
@@ -395,7 +395,7 @@ void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
395
395
// number of operands that has cycles specified.
396
396
//
397
397
void SubtargetEmitter::FormItineraryOperandCycleString (
398
- Record *ItinData, std::string &ItinString, unsigned &NOperandCycles) {
398
+ const Record *ItinData, std::string &ItinString, unsigned &NOperandCycles) {
399
399
// Get operand cycle list
400
400
std::vector<int64_t > OperandCycleList =
401
401
ItinData->getValueAsListOfInts (" OperandCycles" );
@@ -411,10 +411,10 @@ void SubtargetEmitter::FormItineraryOperandCycleString(
411
411
}
412
412
413
413
void SubtargetEmitter::FormItineraryBypassString (const std::string &Name,
414
- Record *ItinData,
414
+ const Record *ItinData,
415
415
std::string &ItinString,
416
416
unsigned NOperandCycles) {
417
- RecVec BypassList = ItinData->getValueAsListOfDefs (" Bypasses" );
417
+ ConstRecVec BypassList = ItinData->getValueAsListOfConstDefs (" Bypasses" );
418
418
unsigned N = BypassList.size ();
419
419
unsigned i = 0 ;
420
420
ListSeparator LS;
@@ -511,7 +511,7 @@ void SubtargetEmitter::EmitStageAndOperandCycleData(
511
511
SchedClassIdx < SchedClassEnd; ++SchedClassIdx) {
512
512
513
513
// Next itinerary data
514
- Record *ItinData = ProcModel.ItinDefList [SchedClassIdx];
514
+ const Record *ItinData = ProcModel.ItinDefList [SchedClassIdx];
515
515
516
516
// Get string and stage count
517
517
std::string ItinStageString;
@@ -746,7 +746,7 @@ SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
746
746
// Add entries to the cost table.
747
747
for (const CodeGenRegisterCost &RC : RF.Costs ) {
748
748
OS << " { " ;
749
- Record *Rec = RC.RCDef ;
749
+ const Record *Rec = RC.RCDef ;
750
750
if (Rec->getValue (" Namespace" ))
751
751
OS << Rec->getValueAsString (" Namespace" ) << " ::" ;
752
752
OS << Rec->getName () << " RegClassID, " << RC.Cost << " , "
@@ -843,7 +843,7 @@ void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
843
843
int BufferSize = PRDef->getValueAsInt (" BufferSize" );
844
844
if (PRDef->isSubClassOf (" ProcResGroup" )) {
845
845
RecVec ResUnits = PRDef->getValueAsListOfDefs (" Resources" );
846
- for (Record *RU : ResUnits) {
846
+ for (const Record *RU : ResUnits) {
847
847
NumUnits += RU->getValueAsInt (" NumUnits" );
848
848
SubUnitsOffset += RU->getValueAsInt (" NumUnits" );
849
849
}
@@ -1279,7 +1279,7 @@ void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
1279
1279
if (ValidWrites.empty ())
1280
1280
WriteIDs.push_back (0 );
1281
1281
else {
1282
- for (Record *VW : ValidWrites) {
1282
+ for (const Record *VW : ValidWrites) {
1283
1283
unsigned WriteID = SchedModels.getSchedRWIdx (VW, /* IsRead=*/ false );
1284
1284
assert (WriteID != 0 &&
1285
1285
" Expected a valid SchedRW in the list of ValidWrites" );
@@ -1548,16 +1548,12 @@ void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) {
1548
1548
EmitProcessorModels (OS);
1549
1549
}
1550
1550
1551
- static void emitPredicateProlog (RecordKeeper &Records, raw_ostream &OS) {
1551
+ static void emitPredicateProlog (const RecordKeeper &Records, raw_ostream &OS) {
1552
1552
std::string Buffer;
1553
1553
raw_string_ostream Stream (Buffer);
1554
1554
1555
- // Collect all the PredicateProlog records and print them to the output
1556
- // stream.
1557
- std::vector<Record *> Prologs =
1558
- Records.getAllDerivedDefinitions (" PredicateProlog" );
1559
- llvm::sort (Prologs, LessRecord ());
1560
- for (Record *P : Prologs)
1555
+ // Print all PredicateProlog records to the output stream.
1556
+ for (const Record *P : Records.getAllDerivedDefinitions (" PredicateProlog" ))
1561
1557
Stream << P->getValueAsString (" Code" ) << ' \n ' ;
1562
1558
1563
1559
OS << Buffer;
@@ -1878,9 +1874,8 @@ void SubtargetEmitter::emitGetMacroFusions(const std::string &ClassName,
1878
1874
// Produces a subtarget specific function for parsing
1879
1875
// the subtarget features string.
1880
1876
void SubtargetEmitter::ParseFeaturesFunction (raw_ostream &OS) {
1881
- std::vector< Record *> Features =
1877
+ ArrayRef< const Record *> Features =
1882
1878
Records.getAllDerivedDefinitions (" SubtargetFeature" );
1883
- llvm::sort (Features, LessRecord ());
1884
1879
1885
1880
OS << " // ParseSubtargetFeatures - Parses features string setting specified\n "
1886
1881
<< " // subtarget options.\n "
@@ -1904,7 +1899,7 @@ void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS) {
1904
1899
OS << " InitMCProcessorInfo(CPU, TuneCPU, FS);\n "
1905
1900
<< " const FeatureBitset &Bits = getFeatureBits();\n " ;
1906
1901
1907
- for (Record *R : Features) {
1902
+ for (const Record *R : Features) {
1908
1903
// Next record
1909
1904
StringRef Instance = R->getName ();
1910
1905
StringRef Value = R->getValueAsString (" Value" );
@@ -1995,28 +1990,20 @@ void SubtargetEmitter::run(raw_ostream &OS) {
1995
1990
OS << " \n #ifdef GET_SUBTARGETINFO_ENUM\n " ;
1996
1991
OS << " #undef GET_SUBTARGETINFO_ENUM\n\n " ;
1997
1992
1998
- DenseMap<Record *, unsigned > FeatureMap;
1999
-
2000
1993
OS << " namespace llvm {\n " ;
2001
- Enumeration (OS, FeatureMap );
1994
+ auto FeatureMap = Enumeration (OS);
2002
1995
OS << " } // end namespace llvm\n\n " ;
2003
1996
OS << " #endif // GET_SUBTARGETINFO_ENUM\n\n " ;
2004
1997
2005
1998
EmitSubtargetInfoMacroCalls (OS);
2006
1999
2007
2000
OS << " namespace llvm {\n " ;
2008
- #if 0
2009
- OS << "namespace {\n";
2010
- #endif
2011
2001
unsigned NumFeatures = FeatureKeyValues (OS, FeatureMap);
2012
2002
OS << " \n " ;
2013
2003
EmitSchedModel (OS);
2014
2004
OS << " \n " ;
2015
2005
unsigned NumProcs = CPUKeyValues (OS, FeatureMap);
2016
2006
OS << " \n " ;
2017
- #if 0
2018
- OS << "} // end anonymous namespace\n\n";
2019
- #endif
2020
2007
2021
2008
// MCInstrInfo initialization routine.
2022
2009
emitGenMCSubtargetInfo (OS);
0 commit comments