[llvm] [TableGen][NFC] Refactor/deduplicate emitAction. (PR #137434)

Jason Eckhardt via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 05:54:38 PDT 2025


================
@@ -125,6 +126,56 @@ void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) {
 
 void CallingConvEmitter::emitAction(const Record *Action, indent Indent,
                                     raw_ostream &O) {
+
+  auto EmitRegList = [&](const ListInit *RL, const StringRef RLName) {
+    O << Indent << "static const MCPhysReg " << RLName << "[] = {\n";
+    O << Indent << "  ";
+    ListSeparator LS;
+    for (const Init *V : RL->getValues())
+      O << LS << getQualifiedName(dyn_cast<DefInit>(V)->getDef());
+    O << "\n" << Indent << "};\n";
+  };
+
+  auto EmitAllocateReg = [&](ArrayRef<const ListInit *> RegLists,
+                             ArrayRef<std::string> RLNames) {
+    SmallVector<std::string> Parms;
+    if (RegLists[0]->size() == 1) {
+      for (const ListInit *LI : RegLists)
+        Parms.push_back(getQualifiedName(LI->getElementAsRecord(0)));
+    } else {
+      for (const std::string &S : RLNames)
+        Parms.push_back(S + utostr(++Counter));
+      for (const auto [Idx, LI] : enumerate(RegLists))
+        EmitRegList(LI, Parms[Idx]);
+    }
+    O << formatv("{0}if (MCRegister Reg = State.AllocateReg({1})) {{\n", Indent,
+                 make_range(Parms.begin(), Parms.end()));
+    O << Indent << "  State.addLoc(CCValAssign::getReg(ValNo, ValVT, "
+      << "Reg, LocVT, LocInfo));\n";
+  };
+
+  auto EmitAllocateStack = [&](bool EmitOffset = false) {
+    int Size = Action->getValueAsInt("Size");
+    int Align = Action->getValueAsInt("Align");
+    if (EmitOffset)
+      O << Indent << "int64_t Offset" << ++Counter << " = ";
+    else
+      O << Indent << "  (void)";
+    O << "State.AllocateStack(";
+
+    std::string Fmt = "  State.getMachineFunction().getDataLayout()."
----------------
nvjle wrote:

Yes it can, done.

https://github.com/llvm/llvm-project/pull/137434


More information about the llvm-commits mailing list