[llvm] r329173 - [Tablegen] Slightly refactor method SubtargetEmitter::EmitExtraProcessorInfo.

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 04:53:13 PDT 2018


Author: adibiagio
Date: Wed Apr  4 04:53:13 2018
New Revision: 329173

URL: http://llvm.org/viewvc/llvm-project?rev=329173&view=rev
Log:
[Tablegen] Slightly refactor method SubtargetEmitter::EmitExtraProcessorInfo.

This patch moves most of the logic from EmitExtraProcessorInfo to a couple of
helper functions. No functional change intended.

Modified:
    llvm/trunk/utils/TableGen/SubtargetEmitter.cpp

Modified: llvm/trunk/utils/TableGen/SubtargetEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/SubtargetEmitter.cpp?rev=329173&r1=329172&r2=329173&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SubtargetEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/SubtargetEmitter.cpp Wed Apr  4 04:53:13 2018
@@ -90,7 +90,10 @@ class SubtargetEmitter {
   void EmitItineraries(raw_ostream &OS,
                        std::vector<std::vector<InstrItinerary>>
                          &ProcItinLists);
-  void EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, raw_ostream &OS);
+  unsigned EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
+                                  raw_ostream &OS);
+  void EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
+                              raw_ostream &OS);
   void EmitProcessorProp(raw_ostream &OS, const Record *R, StringRef Name,
                          char Separator);
   void EmitProcessorResourceSubUnits(const CodeGenProcModel &ProcModel,
@@ -605,12 +608,29 @@ void SubtargetEmitter::EmitProcessorReso
   OS << "};\n";
 }
 
-void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
-                                              raw_ostream &OS) {
+static void EmitRegisterFileInfo(const CodeGenProcModel &ProcModel,
+                                 unsigned NumRegisterFiles,
+                                 unsigned NumCostEntries, raw_ostream &OS) {
+  if (NumRegisterFiles)
+    OS << ProcModel.ModelName << "RegisterFiles,\n  " << (1 + NumRegisterFiles);
+  else
+    OS << "nullptr,\n  0,\n  ";
+
+  OS << ", // Number of register files.\n  ";
+  if (NumCostEntries)
+    OS << ProcModel.ModelName << "RegisterCosts,\n  ";
+  else
+    OS << "nullptr, \n";
+  OS << NumCostEntries << " // Number of register cost entries.\n";
+}
+
+unsigned
+SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
+                                         raw_ostream &OS) {
   if (llvm::all_of(ProcModel.RegisterFiles, [](const CodeGenRegisterFile &RF) {
         return RF.hasDefaultCosts();
       }))
-    return;
+    return 0;
 
   // Print the RegisterCost table first.
   OS << "\n// {RegisterClassID, Register Cost}\n";
@@ -650,14 +670,25 @@ void SubtargetEmitter::EmitExtraProcesso
   }
   OS << "};\n";
 
+  return CostTblIndex;
+}
+
+void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel,
+                                              raw_ostream &OS) {
+  // Generate a table of register file descriptors (one entry per each user
+  // defined register file), and a table of register costs.
+  unsigned NumCostEntries = EmitRegisterFileTables(ProcModel, OS);
+
   // Now generate a table for the extra processor info.
   OS << "\nstatic const llvm::MCExtraProcessorInfo " << ProcModel.ModelName
-     << "ExtraInfo = {\n  " << ProcModel.ModelName << "RegisterFiles,\n  "
-     << (1 + ProcModel.RegisterFiles.size())
-     << ", // Number of register files.\n  "
-     << ProcModel.ModelName << "RegisterCosts,\n  " << CostTblIndex
-     << " // Number of register cost entries.\n"
-     << "};\n";
+     << "ExtraInfo = {\n  ";
+
+  // Add information related to the register files (i.e. where to find register
+  // file descriptors and register costs).
+  EmitRegisterFileInfo(ProcModel, ProcModel.RegisterFiles.size(),
+                       NumCostEntries, OS);
+
+  OS << "};\n";
 }
 
 void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,




More information about the llvm-commits mailing list