[llvm] r316449 - [TableGen] Simplify some of the subtarget emission by removing code that avoids printing commas at the end of arrays and enums.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 08:50:53 PDT 2017
Author: ctopper
Date: Tue Oct 24 08:50:53 2017
New Revision: 316449
URL: http://llvm.org/viewvc/llvm-project?rev=316449&view=rev
Log:
[TableGen] Simplify some of the subtarget emission by removing code that avoids printing commas at the end of arrays and enums.
The C++ standard allows for trailing commas. We already do this in many other emitters.
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=316449&r1=316448&r2=316449&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SubtargetEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/SubtargetEmitter.cpp Tue Oct 24 08:50:53 2017
@@ -142,15 +142,12 @@ void SubtargetEmitter::Enumeration(raw_o
OS << "enum {\n";
// For each record
- for (unsigned i = 0; i < N;) {
+ for (unsigned i = 0; i < N; ++i) {
// Next record
Record *Def = DefList[i];
// Get and emit name
- OS << " " << Def->getName() << " = " << i;
- if (++i < N) OS << ",";
-
- OS << "\n";
+ OS << " " << Def->getName() << " = " << i << ",\n";
}
// Close enumeration and namespace
@@ -203,15 +200,8 @@ unsigned SubtargetEmitter::FeatureKeyVal
OS << " " << Target << "::" << ImpliesList[j]->getName();
if (++j < M) OS << ",";
}
- OS << " }";
-
- OS << " }";
+ OS << " } },\n";
++NumFeatures;
-
- // Depending on 'if more in the list' emit comma
- if ((i + 1) < N) OS << ",";
-
- OS << "\n";
}
// End feature table
@@ -236,10 +226,7 @@ unsigned SubtargetEmitter::CPUKeyValues(
<< "SubTypeKV[] = {\n";
// For each processor
- for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
- // Next processor
- Record *Processor = ProcessorList[i];
-
+ for (Record *Processor : ProcessorList) {
StringRef Name = Processor->getValueAsString("Name");
const std::vector<Record*> &FeatureList =
Processor->getValueAsListOfDefs("Features");
@@ -254,15 +241,8 @@ unsigned SubtargetEmitter::CPUKeyValues(
OS << " " << Target << "::" << FeatureList[j]->getName();
if (++j < M) OS << ",";
}
- OS << " }";
-
// The { } is for the "implies" section of this data structure.
- OS << ", { } }";
-
- // Depending on 'if more in the list' emit comma
- if (++i < N) OS << ",";
-
- OS << "\n";
+ OS << " }, { } },\n";
}
// End processor table
@@ -600,12 +580,10 @@ void SubtargetEmitter::EmitProcessorProp
void SubtargetEmitter::EmitProcessorResources(const CodeGenProcModel &ProcModel,
raw_ostream &OS) {
- char Sep = ProcModel.ProcResourceDefs.empty() ? ' ' : ',';
-
OS << "\n// {Name, NumUnits, SuperIdx, IsBuffered}\n";
OS << "static const llvm::MCProcResourceDesc "
<< ProcModel.ModelName << "ProcResources" << "[] = {\n"
- << " {DBGFIELD(\"InvalidUnit\") 0, 0, 0}" << Sep << "\n";
+ << " {DBGFIELD(\"InvalidUnit\") 0, 0, 0},\n";
for (unsigned i = 0, e = ProcModel.ProcResourceDefs.size(); i < e; ++i) {
Record *PRDef = ProcModel.ProcResourceDefs[i];
@@ -630,13 +608,11 @@ void SubtargetEmitter::EmitProcessorReso
NumUnits = PRDef->getValueAsInt("NumUnits");
}
// Emit the ProcResourceDesc
- if (i+1 == e)
- Sep = ' ';
OS << " {DBGFIELD(\"" << PRDef->getName() << "\") ";
if (PRDef->getName().size() < 15)
OS.indent(15 - PRDef->getName().size());
OS << NumUnits << ", " << SuperIdx << ", "
- << BufferSize << "}" << Sep << " // #" << i+1;
+ << BufferSize << "}, // #" << i+1;
if (SuperDef)
OS << ", Super=" << SuperDef->getName();
OS << "\n";
@@ -1131,10 +1107,8 @@ void SubtargetEmitter::EmitSchedClassTab
<< ", " << format("%2d", MCDesc.WriteLatencyIdx)
<< ", " << MCDesc.NumWriteLatencyEntries
<< ", " << format("%2d", MCDesc.ReadAdvanceIdx)
- << ", " << MCDesc.NumReadAdvanceEntries << "}";
- if (SCIdx + 1 < SCEnd)
- OS << ',';
- OS << " // #" << SCIdx << '\n';
+ << ", " << MCDesc.NumReadAdvanceEntries
+ << "}, // #" << SCIdx << '\n';
}
OS << "}; // " << PI->ModelName << "SchedClasses\n";
}
@@ -1205,21 +1179,13 @@ void SubtargetEmitter::EmitProcessorLook
<< Target << "ProcSchedKV[] = {\n";
// For each processor
- for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
- // Next processor
- Record *Processor = ProcessorList[i];
-
+ for (Record *Processor : ProcessorList) {
StringRef Name = Processor->getValueAsString("Name");
const std::string &ProcModelName =
SchedModels.getModelForProc(Processor).ModelName;
// Emit as { "cpu", procinit },
- OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " }";
-
- // Depending on ''if more in the list'' emit comma
- if (++i < N) OS << ",";
-
- OS << "\n";
+ OS << " { \"" << Name << "\", (const void *)&" << ProcModelName << " },\n";
}
// End processor table
More information about the llvm-commits
mailing list