@@ -92,7 +92,7 @@ class CompressInstEmitter {
92
92
// Integer immediate value.
93
93
int64_t Imm;
94
94
// Physical register.
95
- Record *Reg;
95
+ const Record *Reg;
96
96
} Data;
97
97
// Tied operand index within the instruction.
98
98
int TiedOpIdx = -1 ;
@@ -103,7 +103,7 @@ class CompressInstEmitter {
103
103
// The destination instruction to transform to.
104
104
CodeGenInstruction Dest;
105
105
// Required target features to enable pattern.
106
- std::vector<Record *> PatReqFeatures;
106
+ std::vector<const Record *> PatReqFeatures;
107
107
// Maps operands in the Source Instruction to
108
108
// the corresponding Dest instruction operand.
109
109
IndexedMap<OpData> SourceOperandMap;
@@ -112,38 +112,40 @@ class CompressInstEmitter {
112
112
IndexedMap<OpData> DestOperandMap;
113
113
114
114
bool IsCompressOnly;
115
- CompressPat (CodeGenInstruction &S, CodeGenInstruction &D,
116
- std::vector<Record *> RF, IndexedMap<OpData> &SourceMap,
115
+ CompressPat (const CodeGenInstruction &S, const CodeGenInstruction &D,
116
+ std::vector<const Record *> RF, IndexedMap<OpData> &SourceMap,
117
117
IndexedMap<OpData> &DestMap, bool IsCompressOnly)
118
118
: Source(S), Dest(D), PatReqFeatures(RF), SourceOperandMap(SourceMap),
119
119
DestOperandMap (DestMap), IsCompressOnly(IsCompressOnly) {}
120
120
};
121
121
enum EmitterType { Compress, Uncompress, CheckCompress };
122
- RecordKeeper &Records;
123
- CodeGenTarget Target;
122
+ const RecordKeeper &Records;
123
+ const CodeGenTarget Target;
124
124
SmallVector<CompressPat, 4 > CompressPatterns;
125
125
126
- void addDagOperandMapping (Record *Rec, DagInit *Dag, CodeGenInstruction &Inst,
126
+ void addDagOperandMapping (const Record *Rec, const DagInit *Dag,
127
+ const CodeGenInstruction &Inst,
127
128
IndexedMap<OpData> &OperandMap, bool IsSourceInst);
128
- void evaluateCompressPat (Record *Compress);
129
+ void evaluateCompressPat (const Record *Compress);
129
130
void emitCompressInstEmitter (raw_ostream &OS, EmitterType EType);
130
131
bool validateTypes (const Record *DagOpType, const Record *InstOpType,
131
132
bool IsSourceInst);
132
133
bool validateRegister (const Record *Reg, const Record *RegClass);
133
- void createDagOperandMapping (Record *Rec, StringMap<unsigned > &SourceOperands,
134
+ void createDagOperandMapping (const Record *Rec,
135
+ StringMap<unsigned > &SourceOperands,
134
136
StringMap<unsigned > &DestOperands,
135
- DagInit *SourceDag, DagInit *DestDag,
137
+ const DagInit *SourceDag, const DagInit *DestDag,
136
138
IndexedMap<OpData> &SourceOperandMap);
137
139
138
- void createInstOperandMapping (Record *Rec, DagInit *SourceDag,
139
- DagInit *DestDag,
140
+ void createInstOperandMapping (const Record *Rec, const DagInit *SourceDag,
141
+ const DagInit *DestDag,
140
142
IndexedMap<OpData> &SourceOperandMap,
141
143
IndexedMap<OpData> &DestOperandMap,
142
144
StringMap<unsigned > &SourceOperands,
143
- CodeGenInstruction &DestInst);
145
+ const CodeGenInstruction &DestInst);
144
146
145
147
public:
146
- CompressInstEmitter (RecordKeeper &R) : Records(R), Target(R) {}
148
+ CompressInstEmitter (const RecordKeeper &R) : Records(R), Target(R) {}
147
149
148
150
void run (raw_ostream &OS);
149
151
};
@@ -156,7 +158,7 @@ bool CompressInstEmitter::validateRegister(const Record *Reg,
156
158
" RegClass record should be a RegisterClass" );
157
159
const CodeGenRegisterClass &RC = Target.getRegisterClass (RegClass);
158
160
const CodeGenRegister *R = Target.getRegisterByName (Reg->getName ().lower ());
159
- assert (( R != nullptr ) && " Register not defined!!" );
161
+ assert (R != nullptr && " Register not defined!!" );
160
162
return RC.contains (R);
161
163
}
162
164
@@ -199,8 +201,9 @@ bool CompressInstEmitter::validateTypes(const Record *DagOpType,
199
201
// / operands and fixed registers it expects the Dag operand type to be contained
200
202
// / in the instantiated instruction operand type. For immediate operands and
201
203
// / immediates no validation checks are enforced at pattern validation time.
202
- void CompressInstEmitter::addDagOperandMapping (Record *Rec, DagInit *Dag,
203
- CodeGenInstruction &Inst,
204
+ void CompressInstEmitter::addDagOperandMapping (const Record *Rec,
205
+ const DagInit *Dag,
206
+ const CodeGenInstruction &Inst,
204
207
IndexedMap<OpData> &OperandMap,
205
208
bool IsSourceInst) {
206
209
// TiedCount keeps track of the number of operands skipped in Inst
@@ -218,7 +221,7 @@ void CompressInstEmitter::addDagOperandMapping(Record *Rec, DagInit *Dag,
218
221
TiedCount++;
219
222
continue ;
220
223
}
221
- if (DefInit *DI = dyn_cast<DefInit>(Dag->getArg (I - TiedCount))) {
224
+ if (const DefInit *DI = dyn_cast<DefInit>(Dag->getArg (I - TiedCount))) {
222
225
if (DI->getDef ()->isSubClassOf (" Register" )) {
223
226
// Check if the fixed register belongs to the Register class.
224
227
if (!validateRegister (DI->getDef (), Inst.Operands [I].Rec ))
@@ -267,7 +270,7 @@ void CompressInstEmitter::addDagOperandMapping(Record *Rec, DagInit *Dag,
267
270
}
268
271
269
272
// Verify the Dag operand count is enough to build an instruction.
270
- static bool verifyDagOpCount (CodeGenInstruction &Inst, DagInit *Dag,
273
+ static bool verifyDagOpCount (const CodeGenInstruction &Inst, const DagInit *Dag,
271
274
bool IsSource) {
272
275
if (Dag->getNumArgs () == Inst.Operands .size ())
273
276
return true ;
@@ -297,7 +300,7 @@ static bool verifyDagOpCount(CodeGenInstruction &Inst, DagInit *Dag,
297
300
return true ;
298
301
}
299
302
300
- static bool validateArgsTypes (Init *Arg1, Init *Arg2) {
303
+ static bool validateArgsTypes (const Init *Arg1, const Init *Arg2) {
301
304
return cast<DefInit>(Arg1)->getDef () == cast<DefInit>(Arg2)->getDef ();
302
305
}
303
306
@@ -307,9 +310,9 @@ static bool validateArgsTypes(Init *Arg1, Init *Arg2) {
307
310
// mapping $rs1 --> 0, $rs2 ---> 1. If the operand appears twice in the (tied)
308
311
// same Dag we use the last occurrence for indexing.
309
312
void CompressInstEmitter::createDagOperandMapping (
310
- Record *Rec, StringMap<unsigned > &SourceOperands,
311
- StringMap<unsigned > &DestOperands, DagInit *SourceDag, DagInit *DestDag ,
312
- IndexedMap<OpData> &SourceOperandMap) {
313
+ const Record *Rec, StringMap<unsigned > &SourceOperands,
314
+ StringMap<unsigned > &DestOperands, const DagInit *SourceDag ,
315
+ const DagInit *DestDag, IndexedMap<OpData> &SourceOperandMap) {
313
316
for (unsigned I = 0 ; I < DestDag->getNumArgs (); ++I) {
314
317
// Skip fixed immediates and registers, they were handled in
315
318
// addDagOperandMapping.
@@ -354,9 +357,9 @@ void CompressInstEmitter::createDagOperandMapping(
354
357
// / output instructions. Validate that operands defined in the input are
355
358
// / used in the output pattern while populating the maps.
356
359
void CompressInstEmitter::createInstOperandMapping (
357
- Record *Rec, DagInit *SourceDag, DagInit *DestDag,
360
+ const Record *Rec, const DagInit *SourceDag, const DagInit *DestDag,
358
361
IndexedMap<OpData> &SourceOperandMap, IndexedMap<OpData> &DestOperandMap,
359
- StringMap<unsigned > &SourceOperands, CodeGenInstruction &DestInst) {
362
+ StringMap<unsigned > &SourceOperands, const CodeGenInstruction &DestInst) {
360
363
// TiedCount keeps track of the number of operands skipped in Inst
361
364
// operands list to get to the corresponding Dag operand.
362
365
unsigned TiedCount = 0 ;
@@ -423,14 +426,14 @@ void CompressInstEmitter::createInstOperandMapping(
423
426
// / and generate warning.
424
427
// / - Immediate operand type in Dag Input differs from the corresponding Source
425
428
// / Instruction type and generate a warning.
426
- void CompressInstEmitter::evaluateCompressPat (Record *Rec) {
429
+ void CompressInstEmitter::evaluateCompressPat (const Record *Rec) {
427
430
// Validate input Dag operands.
428
431
DagInit *SourceDag = Rec->getValueAsDag (" Input" );
429
432
assert (SourceDag && " Missing 'Input' in compress pattern!" );
430
433
LLVM_DEBUG (dbgs () << " Input: " << *SourceDag << " \n " );
431
434
432
435
// Checking we are transforming from compressed to uncompressed instructions.
433
- Record *SourceOperator = SourceDag->getOperatorAsDef (Rec->getLoc ());
436
+ const Record *SourceOperator = SourceDag->getOperatorAsDef (Rec->getLoc ());
434
437
CodeGenInstruction SourceInst (SourceOperator);
435
438
verifyDagOpCount (SourceInst, SourceDag, true );
436
439
@@ -439,7 +442,7 @@ void CompressInstEmitter::evaluateCompressPat(Record *Rec) {
439
442
assert (DestDag && " Missing 'Output' in compress pattern!" );
440
443
LLVM_DEBUG (dbgs () << " Output: " << *DestDag << " \n " );
441
444
442
- Record *DestOperator = DestDag->getOperatorAsDef (Rec->getLoc ());
445
+ const Record *DestOperator = DestDag->getOperatorAsDef (Rec->getLoc ());
443
446
CodeGenInstruction DestInst (DestOperator);
444
447
verifyDagOpCount (DestInst, DestDag, false );
445
448
@@ -475,9 +478,9 @@ void CompressInstEmitter::evaluateCompressPat(Record *Rec) {
475
478
DestOperandMap, SourceOperands, DestInst);
476
479
477
480
// Get the target features for the CompressPat.
478
- std::vector<Record *> PatReqFeatures;
479
- std::vector<Record *> RF = Rec->getValueAsListOfDefs (" Predicates" );
480
- copy_if (RF, std::back_inserter (PatReqFeatures), [](Record *R) {
481
+ std::vector<const Record *> PatReqFeatures;
482
+ std::vector<const Record *> RF = Rec->getValueAsListOfConstDefs (" Predicates" );
483
+ copy_if (RF, std::back_inserter (PatReqFeatures), [](const Record *R) {
481
484
return R->getValueAsBit (" AssemblerMatcherPredicate" );
482
485
});
483
486
@@ -489,8 +492,8 @@ void CompressInstEmitter::evaluateCompressPat(Record *Rec) {
489
492
static void
490
493
getReqFeatures (std::set<std::pair<bool , StringRef>> &FeaturesSet,
491
494
std::set<std::set<std::pair<bool , StringRef>>> &AnyOfFeatureSets,
492
- const std::vector< Record *> & ReqFeatures) {
493
- for (auto & R : ReqFeatures) {
495
+ ArrayRef< const Record *> ReqFeatures) {
496
+ for (const Record * R : ReqFeatures) {
494
497
const DagInit *D = R->getValueAsDag (" AssemblerCondDag" );
495
498
std::string CombineType = D->getOperator ()->getAsString ();
496
499
if (CombineType != " any_of" && CombineType != " all_of" )
@@ -542,8 +545,8 @@ static unsigned getPredicates(DenseMap<const Record *, unsigned> &PredicateMap,
542
545
return 0 ;
543
546
}
544
547
545
- static void printPredicates (const std::vector <const Record *> & Predicates,
546
- StringRef Name, raw_ostream &OS) {
548
+ static void printPredicates (ArrayRef <const Record *> Predicates, StringRef Name ,
549
+ raw_ostream &OS) {
547
550
for (unsigned I = 0 ; I < Predicates.size (); ++I) {
548
551
StringRef Pred = Predicates[I]->getValueAsString (Name);
549
552
OS << " case " << I + 1 << " : {\n "
@@ -565,7 +568,7 @@ static void mergeCondAndCode(raw_ostream &CombinedStream, StringRef CondStr,
565
568
566
569
void CompressInstEmitter::emitCompressInstEmitter (raw_ostream &OS,
567
570
EmitterType EType) {
568
- Record *AsmWriter = Target.getAsmWriter ();
571
+ const Record *AsmWriter = Target.getAsmWriter ();
569
572
if (!AsmWriter->getValueAsInt (" PassSubtarget" ))
570
573
PrintFatalError (AsmWriter->getLoc (),
571
574
" 'PassSubtarget' is false. SubTargetInfo object is needed "
@@ -683,9 +686,10 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
683
686
getReqFeatures (FeaturesSet, AnyOfFeatureSets, CompressPat.PatReqFeatures );
684
687
685
688
// Add Dest instruction required features.
686
- std::vector<Record *> ReqFeatures;
687
- std::vector<Record *> RF = Dest.TheDef ->getValueAsListOfDefs (" Predicates" );
688
- copy_if (RF, std::back_inserter (ReqFeatures), [](Record *R) {
689
+ std::vector<const Record *> ReqFeatures;
690
+ std::vector<const Record *> RF =
691
+ Dest.TheDef ->getValueAsListOfConstDefs (" Predicates" );
692
+ copy_if (RF, std::back_inserter (ReqFeatures), [](const Record *R) {
689
693
return R->getValueAsBit (" AssemblerMatcherPredicate" );
690
694
});
691
695
getReqFeatures (FeaturesSet, AnyOfFeatureSets, ReqFeatures);
@@ -738,7 +742,7 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
738
742
<< " ).getImm() == " << SourceOperandMap[OpNo].Data .Imm << " ) &&\n " ;
739
743
break ;
740
744
case OpData::Reg: {
741
- Record *Reg = SourceOperandMap[OpNo].Data .Reg ;
745
+ const Record *Reg = SourceOperandMap[OpNo].Data .Reg ;
742
746
CondStream.indent (6 )
743
747
<< " (MI.getOperand(" << OpNo << " ).isReg()) &&\n "
744
748
<< " (MI.getOperand(" << OpNo << " ).getReg() == " << TargetName
@@ -827,7 +831,7 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
827
831
case OpData::Reg: {
828
832
if (CompressOrUncompress) {
829
833
// Fixed register has been validated at pattern validation time.
830
- Record *Reg = DestOperandMap[OpNo].Data .Reg ;
834
+ const Record *Reg = DestOperandMap[OpNo].Data .Reg ;
831
835
CodeStream.indent (6 )
832
836
<< " OutInst.addOperand(MCOperand::createReg(" << TargetName
833
837
<< " ::" << Reg->getName () << " ));\n " ;
@@ -891,11 +895,9 @@ void CompressInstEmitter::emitCompressInstEmitter(raw_ostream &OS,
891
895
}
892
896
893
897
void CompressInstEmitter::run (raw_ostream &OS) {
894
- std::vector<Record *> Insts = Records.getAllDerivedDefinitions (" CompressPat" );
895
-
896
898
// Process the CompressPat definitions, validating them as we do so.
897
- for (unsigned I = 0 , E = Insts. size (); I != E; ++I )
898
- evaluateCompressPat (Insts[I] );
899
+ for (const Record *Pat : Records. getAllDerivedDefinitions ( " CompressPat " ) )
900
+ evaluateCompressPat (Pat );
899
901
900
902
// Emit file header.
901
903
emitSourceFileHeader (" Compress instruction Source Fragment" , OS, Records);
0 commit comments