[llvm] [LLVM][TableGen] Change CallingConvEmitter to use const RecordKeeper (PR #108955)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 05:23:40 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/108955
>From b7614ed2cd781f83e797c1dadef368f1ccc16180 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 17 Sep 2024 03:48:09 -0700
Subject: [PATCH] [LLVM][TableGen] Change CallingConvEmitter to use const
RecordKeeper
---
llvm/include/llvm/TableGen/Record.h | 9 +++--
llvm/lib/TableGen/Record.cpp | 2 +-
llvm/utils/TableGen/CallingConvEmitter.cpp | 45 ++++++++++++----------
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index c9e01e3f221bad..2560302132bea0 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -2035,7 +2035,7 @@ class RecordKeeper {
}
/// Start timing a phase. Automatically stops any previous phase timer.
- void startTimer(StringRef Name);
+ void startTimer(StringRef Name) const;
/// Stop timing a phase.
void stopTimer();
@@ -2109,12 +2109,13 @@ class RecordKeeper {
mutable std::map<std::string, std::vector<Record *>> ClassRecordsMap;
GlobalMap ExtraGlobals;
+ // TODO: Move timing related code out of RecordKeeper.
// These members are for the phase timing feature. We need a timer group,
// the last timer started, and a flag to say whether the last timer
// is the special "backend overall timer."
- TimerGroup *TimingGroup = nullptr;
- Timer *LastTimer = nullptr;
- bool BackendTimer = false;
+ mutable TimerGroup *TimingGroup = nullptr;
+ mutable Timer *LastTimer = nullptr;
+ mutable bool BackendTimer = false;
/// The internal uniquer implementation of the RecordKeeper.
std::unique_ptr<detail::RecordKeeperImpl> Impl;
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 97ae0b092b81b1..a10884d15516a5 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -3219,7 +3219,7 @@ Init *RecordKeeper::getNewAnonymousName() {
// These functions implement the phase timing facility. Starting a timer
// when one is already running stops the running one.
-void RecordKeeper::startTimer(StringRef Name) {
+void RecordKeeper::startTimer(StringRef Name) const {
if (TimingGroup) {
if (LastTimer && LastTimer->isRunning()) {
LastTimer->stopTimer();
diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index 6a3030bfc1b7e3..8876bb3ad31e19 100644
--- a/llvm/utils/TableGen/CallingConvEmitter.cpp
+++ b/llvm/utils/TableGen/CallingConvEmitter.cpp
@@ -22,7 +22,7 @@ using namespace llvm;
namespace {
class CallingConvEmitter {
- RecordKeeper &Records;
+ const RecordKeeper &Records;
unsigned Counter = 0u;
std::string CurrentAction;
bool SwiftAction = false;
@@ -32,13 +32,13 @@ class CallingConvEmitter {
std::map<std::string, std::set<std::string>> DelegateToMap;
public:
- explicit CallingConvEmitter(RecordKeeper &R) : Records(R) {}
+ explicit CallingConvEmitter(const RecordKeeper &R) : Records(R) {}
void run(raw_ostream &o);
private:
- void EmitCallingConv(Record *CC, raw_ostream &O);
- void EmitAction(Record *Action, unsigned Indent, raw_ostream &O);
+ void EmitCallingConv(const Record *CC, raw_ostream &O);
+ void EmitAction(const Record *Action, unsigned Indent, raw_ostream &O);
void EmitArgRegisterLists(raw_ostream &O);
};
} // End anonymous namespace
@@ -46,13 +46,14 @@ class CallingConvEmitter {
void CallingConvEmitter::run(raw_ostream &O) {
emitSourceFileHeader("Calling Convention Implementation Fragment", O);
- std::vector<Record *> CCs = Records.getAllDerivedDefinitions("CallingConv");
+ ArrayRef<const Record *> CCs =
+ Records.getAllDerivedDefinitions("CallingConv");
// Emit prototypes for all of the non-custom CC's so that they can forward ref
// each other.
Records.startTimer("Emit prototypes");
O << "#ifndef GET_CC_REGISTER_LISTS\n\n";
- for (Record *CC : CCs) {
+ for (const Record *CC : CCs) {
if (!CC->getValueAsBit("Custom")) {
unsigned Pad = CC->getName().size();
if (CC->getValueAsBit("Entry")) {
@@ -71,7 +72,7 @@ void CallingConvEmitter::run(raw_ostream &O) {
// Emit each non-custom calling convention description in full.
Records.startTimer("Emit full descriptions");
- for (Record *CC : CCs) {
+ for (const Record *CC : CCs) {
if (!CC->getValueAsBit("Custom")) {
EmitCallingConv(CC, O);
}
@@ -82,8 +83,8 @@ void CallingConvEmitter::run(raw_ostream &O) {
O << "\n#endif // CC_REGISTER_LIST\n";
}
-void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
- ListInit *CCActions = CC->getValueAsListInit("Actions");
+void CallingConvEmitter::EmitCallingConv(const Record *CC, raw_ostream &O) {
+ const ListInit *CCActions = CC->getValueAsListInit("Actions");
Counter = 0;
CurrentAction = CC->getName().str();
@@ -106,7 +107,7 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
<< std::string(Pad, ' ') << "ISD::ArgFlagsTy ArgFlags, CCState &State) {\n";
// Emit all of the actions, in order.
for (unsigned i = 0, e = CCActions->size(); i != e; ++i) {
- Record *Action = CCActions->getElementAsRecord(i);
+ const Record *Action = CCActions->getElementAsRecord(i);
SwiftAction =
llvm::any_of(Action->getSuperClasses(),
[](const std::pair<Record *, SMRange> &Class) {
@@ -122,7 +123,7 @@ void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
O << "}\n";
}
-void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
+void CallingConvEmitter::EmitAction(const Record *Action, unsigned Indent,
raw_ostream &O) {
std::string IndentStr = std::string(Indent, ' ');
@@ -150,14 +151,14 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
O << IndentStr << "}\n";
} else {
if (Action->isSubClassOf("CCDelegateTo")) {
- Record *CC = Action->getValueAsDef("CC");
+ const Record *CC = Action->getValueAsDef("CC");
O << IndentStr << "if (!" << CC->getName()
<< "(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))\n"
<< IndentStr << " return false;\n";
DelegateToMap[CurrentAction].insert(CC->getName().str());
} else if (Action->isSubClassOf("CCAssignToReg") ||
Action->isSubClassOf("CCAssignToRegAndStack")) {
- ListInit *RegList = Action->getValueAsListInit("RegList");
+ const ListInit *RegList = Action->getValueAsListInit("RegList");
if (RegList->size() == 1) {
std::string Name = getQualifiedName(RegList->getElementAsRecord(0));
O << IndentStr << "if (MCRegister Reg = State.AllocateReg(" << Name
@@ -210,8 +211,9 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
O << IndentStr << " return false;\n";
O << IndentStr << "}\n";
} else if (Action->isSubClassOf("CCAssignToRegWithShadow")) {
- ListInit *RegList = Action->getValueAsListInit("RegList");
- ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList");
+ const ListInit *RegList = Action->getValueAsListInit("RegList");
+ const ListInit *ShadowRegList =
+ Action->getValueAsListInit("ShadowRegList");
if (!ShadowRegList->empty() && ShadowRegList->size() != RegList->size())
PrintFatalError(Action->getLoc(),
"Invalid length of list of shadowed registers");
@@ -278,7 +280,8 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
} else if (Action->isSubClassOf("CCAssignToStackWithShadow")) {
int Size = Action->getValueAsInt("Size");
int Align = Action->getValueAsInt("Align");
- ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList");
+ const ListInit *ShadowRegList =
+ Action->getValueAsListInit("ShadowRegList");
unsigned ShadowRegListNumber = ++Counter;
@@ -297,7 +300,7 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
<< Counter << ", LocVT, LocInfo));\n";
O << IndentStr << "return false;\n";
} else if (Action->isSubClassOf("CCPromoteToType")) {
- Record *DestTy = Action->getValueAsDef("DestTy");
+ const Record *DestTy = Action->getValueAsDef("DestTy");
MVT::SimpleValueType DestVT = getValueType(DestTy);
O << IndentStr << "LocVT = " << getEnumName(DestVT) << ";\n";
if (MVT(DestVT).isFloatingPoint()) {
@@ -311,7 +314,7 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
<< IndentStr << " LocInfo = CCValAssign::AExt;\n";
}
} else if (Action->isSubClassOf("CCPromoteToUpperBitsInType")) {
- Record *DestTy = Action->getValueAsDef("DestTy");
+ const Record *DestTy = Action->getValueAsDef("DestTy");
MVT::SimpleValueType DestVT = getValueType(DestTy);
O << IndentStr << "LocVT = " << getEnumName(DestVT) << ";\n";
if (MVT(DestVT).isFloatingPoint()) {
@@ -327,17 +330,17 @@ void CallingConvEmitter::EmitAction(Record *Action, unsigned Indent,
<< IndentStr << " LocInfo = CCValAssign::AExtUpper;\n";
}
} else if (Action->isSubClassOf("CCBitConvertToType")) {
- Record *DestTy = Action->getValueAsDef("DestTy");
+ const Record *DestTy = Action->getValueAsDef("DestTy");
O << IndentStr << "LocVT = " << getEnumName(getValueType(DestTy))
<< ";\n";
O << IndentStr << "LocInfo = CCValAssign::BCvt;\n";
} else if (Action->isSubClassOf("CCTruncToType")) {
- Record *DestTy = Action->getValueAsDef("DestTy");
+ const Record *DestTy = Action->getValueAsDef("DestTy");
O << IndentStr << "LocVT = " << getEnumName(getValueType(DestTy))
<< ";\n";
O << IndentStr << "LocInfo = CCValAssign::Trunc;\n";
} else if (Action->isSubClassOf("CCPassIndirect")) {
- Record *DestTy = Action->getValueAsDef("DestTy");
+ const Record *DestTy = Action->getValueAsDef("DestTy");
O << IndentStr << "LocVT = " << getEnumName(getValueType(DestTy))
<< ";\n";
O << IndentStr << "LocInfo = CCValAssign::Indirect;\n";
More information about the llvm-commits
mailing list