Skip to content

Commit 974fa85

Browse files
authored
[clang][TableGen] Change RISCVVEmitter to use const RecordKeeper (#108502)
Change RISCVVEmitter to use const RecordKeeper. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent a4b1617 commit 974fa85

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

clang/utils/TableGen/RISCVVEmitter.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ class SemaSignatureTable {
9595

9696
class RVVEmitter {
9797
private:
98-
RecordKeeper &Records;
98+
const RecordKeeper &Records;
9999
RVVTypeCache TypeCache;
100100

101101
public:
102-
RVVEmitter(RecordKeeper &R) : Records(R) {}
102+
RVVEmitter(const RecordKeeper &R) : Records(R) {}
103103

104104
/// Emit riscv_vector.h
105105
void createHeader(raw_ostream &o);
@@ -554,8 +554,7 @@ void RVVEmitter::createCodeGen(raw_ostream &OS) {
554554
void RVVEmitter::createRVVIntrinsics(
555555
std::vector<std::unique_ptr<RVVIntrinsic>> &Out,
556556
std::vector<SemaRecord> *SemaRecords) {
557-
std::vector<Record *> RV = Records.getAllDerivedDefinitions("RVVBuiltin");
558-
for (auto *R : RV) {
557+
for (const Record *R : Records.getAllDerivedDefinitions("RVVBuiltin")) {
559558
StringRef Name = R->getValueAsString("Name");
560559
StringRef SuffixProto = R->getValueAsString("Suffix");
561560
StringRef OverloadedName = R->getValueAsString("OverloadedName");
@@ -565,10 +564,10 @@ void RVVEmitter::createRVVIntrinsics(
565564
bool HasMasked = R->getValueAsBit("HasMasked");
566565
bool HasMaskedOffOperand = R->getValueAsBit("HasMaskedOffOperand");
567566
bool HasVL = R->getValueAsBit("HasVL");
568-
Record *MPSRecord = R->getValueAsDef("MaskedPolicyScheme");
567+
const Record *MPSRecord = R->getValueAsDef("MaskedPolicyScheme");
569568
auto MaskedPolicyScheme =
570569
static_cast<PolicyScheme>(MPSRecord->getValueAsInt("Value"));
571-
Record *UMPSRecord = R->getValueAsDef("UnMaskedPolicyScheme");
570+
const Record *UMPSRecord = R->getValueAsDef("UnMaskedPolicyScheme");
572571
auto UnMaskedPolicyScheme =
573572
static_cast<PolicyScheme>(UMPSRecord->getValueAsInt("Value"));
574573
std::vector<int64_t> Log2LMULList = R->getValueAsListOfInts("Log2LMUL");
@@ -752,9 +751,7 @@ void RVVEmitter::createRVVIntrinsics(
752751
}
753752

754753
void RVVEmitter::printHeaderCode(raw_ostream &OS) {
755-
std::vector<Record *> RVVHeaders =
756-
Records.getAllDerivedDefinitions("RVVHeader");
757-
for (auto *R : RVVHeaders) {
754+
for (const Record *R : Records.getAllDerivedDefinitions("RVVHeader")) {
758755
StringRef HeaderCodeStr = R->getValueAsString("HeaderCode");
759756
OS << HeaderCodeStr.str();
760757
}
@@ -822,19 +819,19 @@ void RVVEmitter::createSema(raw_ostream &OS) {
822819
}
823820

824821
namespace clang {
825-
void EmitRVVHeader(RecordKeeper &Records, raw_ostream &OS) {
822+
void EmitRVVHeader(const RecordKeeper &Records, raw_ostream &OS) {
826823
RVVEmitter(Records).createHeader(OS);
827824
}
828825

829-
void EmitRVVBuiltins(RecordKeeper &Records, raw_ostream &OS) {
826+
void EmitRVVBuiltins(const RecordKeeper &Records, raw_ostream &OS) {
830827
RVVEmitter(Records).createBuiltins(OS);
831828
}
832829

833-
void EmitRVVBuiltinCG(RecordKeeper &Records, raw_ostream &OS) {
830+
void EmitRVVBuiltinCG(const RecordKeeper &Records, raw_ostream &OS) {
834831
RVVEmitter(Records).createCodeGen(OS);
835832
}
836833

837-
void EmitRVVBuiltinSema(RecordKeeper &Records, raw_ostream &OS) {
834+
void EmitRVVBuiltinSema(const RecordKeeper &Records, raw_ostream &OS) {
838835
RVVEmitter(Records).createSema(OS);
839836
}
840837

clang/utils/TableGen/TableGenBackends.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ void EmitMveBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
146146
void EmitMveBuiltinAliases(const llvm::RecordKeeper &Records,
147147
llvm::raw_ostream &OS);
148148

149-
void EmitRVVHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
150-
void EmitRVVBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
151-
void EmitRVVBuiltinCG(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
152-
void EmitRVVBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
149+
void EmitRVVHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
150+
void EmitRVVBuiltins(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
151+
void EmitRVVBuiltinCG(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
152+
void EmitRVVBuiltinSema(const llvm::RecordKeeper &Records,
153+
llvm::raw_ostream &OS);
153154

154155
void EmitCdeHeader(const llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
155156
void EmitCdeBuiltinDef(const llvm::RecordKeeper &Records,

0 commit comments

Comments
 (0)