@@ -85,9 +85,9 @@ std::string llvm::getQualifiedName(const Record *R) {
8585
8686// / getTarget - Return the current instance of the Target class.
8787// /
88- CodeGenTarget::CodeGenTarget (RecordKeeper &records)
88+ CodeGenTarget::CodeGenTarget (const RecordKeeper &records)
8989 : Records(records), CGH(records), Intrinsics(records) {
90- std::vector< Record *> Targets = Records.getAllDerivedDefinitions (" Target" );
90+ ArrayRef< const Record *> Targets = Records.getAllDerivedDefinitions (" Target" );
9191 if (Targets.size () == 0 )
9292 PrintFatalError (" No 'Target' subclasses defined!" );
9393 if (Targets.size () != 1 )
@@ -223,11 +223,6 @@ std::optional<CodeGenRegisterClass *> CodeGenTarget::getSuperRegForSubReg(
223223 return Candidates[0 ];
224224}
225225
226- void CodeGenTarget::ReadRegAltNameIndices () const {
227- RegAltNameIndices = Records.getAllDerivedDefinitions (" RegAltNameIndex" );
228- llvm::sort (RegAltNameIndices, LessRecord ());
229- }
230-
231226// / getRegisterByName - If there is a register with the specific AsmName,
232227// / return it.
233228const CodeGenRegister *CodeGenTarget::getRegisterByName (StringRef Name) const {
@@ -271,12 +266,13 @@ CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
271266}
272267
273268void CodeGenTarget::ReadInstructions () const {
274- std::vector<Record *> Insts = Records.getAllDerivedDefinitions (" Instruction" );
269+ ArrayRef<const Record *> Insts =
270+ Records.getAllDerivedDefinitions (" Instruction" );
275271 if (Insts.size () <= 2 )
276272 PrintFatalError (" No 'Instruction' subclasses defined!" );
277273
278274 // Parse the instructions defined in the .td file.
279- for (Record *R : Insts) {
275+ for (const Record *R : Insts) {
280276 Instructions[R] = std::make_unique<CodeGenInstruction>(R);
281277 if (Instructions[R]->isVariableLengthEncoding ())
282278 HasVariableLengthEncodings = true ;
@@ -286,7 +282,7 @@ void CodeGenTarget::ReadInstructions() const {
286282static const CodeGenInstruction *GetInstByName (
287283 const char *Name,
288284 const DenseMap<const Record *, std::unique_ptr<CodeGenInstruction>> &Insts,
289- RecordKeeper &Records) {
285+ const RecordKeeper &Records) {
290286 const Record *Rec = Records.getDef (Name);
291287
292288 const auto I = Insts.find (Rec);
@@ -358,9 +354,8 @@ void CodeGenTarget::reverseBitsForLittleEndianEncoding() {
358354 if (!isLittleEndianEncoding ())
359355 return ;
360356
361- std::vector<Record *> Insts =
362- Records.getAllDerivedDefinitions (" InstructionEncoding" );
363- for (Record *R : Insts) {
357+ for (const Record *R :
358+ Records.getAllDerivedDefinitions (" InstructionEncoding" )) {
364359 if (R->getValueAsString (" Namespace" ) == " TargetOpcode" ||
365360 R->getValueAsBit (" isPseudo" ))
366361 continue ;
@@ -383,11 +378,15 @@ void CodeGenTarget::reverseBitsForLittleEndianEncoding() {
383378 NewBits[middle] = BI->getBit (middle);
384379 }
385380
386- BitsInit *NewBI = BitsInit::get (Records, NewBits);
381+ RecordKeeper &MutableRC = const_cast <RecordKeeper &>(Records);
382+ BitsInit *NewBI = BitsInit::get (MutableRC, NewBits);
387383
388- // Update the bits in reversed order so that emitInstrOpBits will get the
389- // correct endianness.
390- R->getValue (" Inst" )->setValue (NewBI);
384+ // Update the bits in reversed order so that emitters will get the correct
385+ // endianness.
386+ // FIXME: Eliminate mutation of TG records by creating a helper function
387+ // to reverse bits and maintain a cache instead of mutating records.
388+ Record *MutableR = const_cast <Record *>(R);
389+ MutableR->getValue (" Inst" )->setValue (NewBI);
391390 }
392391}
393392
0 commit comments