-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LLVM][TableGen] Change RegisterInfoEmitter to use const RecordKeeper #109237
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arsenm
approved these changes
Sep 20, 2024
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesChange RegisterInfoEmitter to use const RecordKeeper. This is a part of effort to have better const correctness in TableGen backends: Full diff: https://github.com/llvm/llvm-project/pull/109237.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
index a7f3977300b302..21a98674701d41 100644
--- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
@@ -56,12 +56,12 @@ static cl::opt<bool>
namespace {
class RegisterInfoEmitter {
- RecordKeeper &Records;
+ const RecordKeeper &Records;
const CodeGenTarget Target;
CodeGenRegBank &RegBank;
public:
- RegisterInfoEmitter(RecordKeeper &R)
+ RegisterInfoEmitter(const RecordKeeper &R)
: Records(R), Target(R), RegBank(Target.getRegBank()) {
RegBank.computeDerivedInfo();
}
@@ -445,7 +445,7 @@ void RegisterInfoEmitter::EmitRegMappingTables(
continue;
DefInit *DI = cast<DefInit>(V->getValue());
- Record *Alias = DI->getDef();
+ const Record *Alias = DI->getDef();
const auto &AliasIter = llvm::lower_bound(
DwarfRegNums, Alias, [](const DwarfRegNumsMapPair &A, const Record *B) {
return LessRecordRegister()(A.first, B);
@@ -1659,17 +1659,16 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
OS << "}\n\n";
// Emit CalleeSavedRegs information.
- std::vector<Record *> CSRSets =
+ ArrayRef<const Record *> CSRSets =
Records.getAllDerivedDefinitions("CalleeSavedRegs");
- for (unsigned i = 0, e = CSRSets.size(); i != e; ++i) {
- Record *CSRSet = CSRSets[i];
+ for (const Record *CSRSet : CSRSets) {
const SetTheory::RecVec *Regs = RegBank.getSets().expand(CSRSet);
assert(Regs && "Cannot expand CalleeSavedRegs instance");
// Emit the *_SaveList list of callee-saved registers.
OS << "static const MCPhysReg " << CSRSet->getName() << "_SaveList[] = { ";
- for (unsigned r = 0, re = Regs->size(); r != re; ++r)
- OS << getQualifiedName((*Regs)[r]) << ", ";
+ for (const Record *Reg : *Regs)
+ OS << getQualifiedName(Reg) << ", ";
OS << "0 };\n";
// Emit the *_RegMask bit mask of call-preserved registers.
@@ -1677,22 +1676,20 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
// Check for an optional OtherPreserved set.
// Add those registers to RegMask, but not to SaveList.
- if (DagInit *OPDag =
+ if (const DagInit *OPDag =
dyn_cast<DagInit>(CSRSet->getValueInit("OtherPreserved"))) {
SetTheory::RecSet OPSet;
RegBank.getSets().evaluate(OPDag, OPSet, CSRSet->getLoc());
- Covered |= RegBank.computeCoveredRegisters(
- ArrayRef<const Record *>(OPSet.begin(), OPSet.end()));
+ Covered |= RegBank.computeCoveredRegisters(OPSet.getArrayRef());
}
// Add all constant physical registers to the preserved mask:
SetTheory::RecSet ConstantSet;
- for (auto &Reg : RegBank.getRegisters()) {
+ for (const auto &Reg : RegBank.getRegisters()) {
if (Reg.Constant)
ConstantSet.insert(Reg.TheDef);
}
- Covered |= RegBank.computeCoveredRegisters(
- ArrayRef<const Record *>(ConstantSet.begin(), ConstantSet.end()));
+ Covered |= RegBank.computeCoveredRegisters(ConstantSet.getArrayRef());
OS << "static const uint32_t " << CSRSet->getName() << "_RegMask[] = { ";
printBitVectorAsHex(OS, Covered, 32);
@@ -1704,7 +1701,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
<< "::getRegMasks() const {\n";
if (!CSRSets.empty()) {
OS << " static const uint32_t *const Masks[] = {\n";
- for (Record *CSRSet : CSRSets)
+ for (const Record *CSRSet : CSRSets)
OS << " " << CSRSet->getName() << "_RegMask,\n";
OS << " };\n";
OS << " return ArrayRef(Masks);\n";
@@ -1784,7 +1781,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
<< "::getRegMaskNames() const {\n";
if (!CSRSets.empty()) {
OS << " static const char *Names[] = {\n";
- for (Record *CSRSet : CSRSets)
+ for (const Record *CSRSet : CSRSets)
OS << " " << '"' << CSRSet->getName() << '"' << ",\n";
OS << " };\n";
OS << " return ArrayRef(Names);\n";
|
xgupta
pushed a commit
to xgupta/llvm-project
that referenced
this pull request
Oct 4, 2024
…llvm#109237) Change RegisterInfoEmitter 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change RegisterInfoEmitter 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