[llvm] [LLVM][TableGen] Change CallingConvEmitter to use const RecordKeeper (PR #108955)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 03:50:05 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/108955
Change CallingConvEmitter to use const RecordKeeper.
>From a11738741667e2d9997e6c5fb180c605ee6c5cd5 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/utils/TableGen/CallingConvEmitter.cpp | 52 ++++++++++++----------
1 file changed, 29 insertions(+), 23 deletions(-)
diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index 6a3030bfc1b7e3..b238610861b7c6 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,17 @@ 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");
+
+ // TOOD: Factor out timer support out of RecordKeeper.
+ RecordKeeper &MutableRC = const_cast<RecordKeeper &>(Records);
+ MutableRC.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")) {
@@ -70,8 +74,8 @@ void CallingConvEmitter::run(raw_ostream &O) {
}
// Emit each non-custom calling convention description in full.
- Records.startTimer("Emit full descriptions");
- for (Record *CC : CCs) {
+ MutableRC.startTimer("Emit full descriptions");
+ for (const Record *CC : CCs) {
if (!CC->getValueAsBit("Custom")) {
EmitCallingConv(CC, O);
}
@@ -82,8 +86,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 +110,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 +126,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 +154,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 +214,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 +283,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 +303,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 +317,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 +333,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