-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MC] Use StringTable for MCSchedClassDesc names #137012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ unsigned StringToOffsetTable::GetOrAddStringOffset(StringRef Str, | |
} | ||
|
||
void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS, const Twine &Name, | ||
const Twine &Indent) const { | ||
const Twine &Indent, | ||
StringRef Linkage) const { | ||
OS << formatv(R"( | ||
#ifdef __GNUC__ | ||
#pragma GCC diagnostic push | ||
|
@@ -78,10 +79,10 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS, const Twine &Name, | |
#pragma GCC diagnostic pop | ||
#endif | ||
|
||
{0}static constexpr llvm::StringTable {1} = | ||
{0}{2} constexpr llvm::StringTable {1} = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we renumber 1 and 2 and swap the args to formatv()? Just that its easier to follow if they are in increasing order to the extent possible, |
||
{0} {1}Storage; | ||
)", | ||
Indent, Name); | ||
Indent, Name, Linkage); | ||
} | ||
|
||
void StringToOffsetTable::EmitString(raw_ostream &O) const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
#include "llvm/Support/raw_ostream.h" | ||
#include "llvm/TableGen/Error.h" | ||
#include "llvm/TableGen/Record.h" | ||
#include "llvm/TableGen/StringToOffsetTable.h" | ||
#include "llvm/TableGen/TableGenBackend.h" | ||
#include "llvm/TargetParser/SubtargetFeature.h" | ||
#include <algorithm> | ||
|
@@ -1430,6 +1431,7 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables, | |
OS << "}; // " << Target << "ReadAdvanceTable\n"; | ||
|
||
// Emit a SchedClass table for each processor. | ||
StringToOffsetTable NameTable; | ||
for (const auto &[Idx, Proc] : enumerate(SchedModels.procModels())) { | ||
if (!Proc.hasInstrSchedModel()) | ||
continue; | ||
|
@@ -1446,14 +1448,17 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables, | |
// name and position. | ||
assert(SchedModels.getSchedClass(0).Name == "NoInstrModel" && | ||
"invalid class not first"); | ||
OS << " {DBGFIELD(\"InvalidSchedClass\") " | ||
unsigned NameOffset = NameTable.GetOrAddStringOffset("InvalidSchedClass"); | ||
OS << " {DBGFIELD(" << NameOffset << " /* InvalidSchedClass */) " | ||
<< MCSchedClassDesc::InvalidNumMicroOps | ||
<< ", false, false, false, 0, 0, 0, 0, 0, 0},\n"; | ||
|
||
for (unsigned SCIdx = 1, SCEnd = SCTab.size(); SCIdx != SCEnd; ++SCIdx) { | ||
MCSchedClassDesc &MCDesc = SCTab[SCIdx]; | ||
const CodeGenSchedClass &SchedClass = SchedModels.getSchedClass(SCIdx); | ||
OS << " {DBGFIELD(\"" << SchedClass.Name << "\") "; | ||
NameOffset = NameTable.GetOrAddStringOffset(SchedClass.Name); | ||
OS << " {DBGFIELD(" << NameOffset << " /* " << SchedClass.Name | ||
<< " */) "; | ||
if (SchedClass.Name.size() < 18) | ||
OS.indent(18 - SchedClass.Name.size()); | ||
OS << MCDesc.NumMicroOps << ", " << (MCDesc.BeginGroup ? "true" : "false") | ||
|
@@ -1468,6 +1473,14 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables, | |
} | ||
OS << "}; // " << Proc.ModelName << "SchedClasses\n"; | ||
} | ||
|
||
OS << "\n#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)\n"; | ||
NameTable.EmitStringTableDef(OS, Target + "NameTable", /*Indent=*/"", | ||
"extern"); | ||
OS << "\n#else\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C++ raw string might make this easier to read |
||
OS << "\nextern constexpr llvm::StringTable " << Target | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that could also be the cause of the link failure seen above |
||
<< "NameTable = \"\";\n"; | ||
OS << "\n#endif\n"; | ||
} | ||
|
||
void SubtargetEmitter::emitProcessorModels(raw_ostream &OS) { | ||
|
@@ -1952,9 +1965,9 @@ void SubtargetEmitter::emitGenMCSubtargetInfo(raw_ostream &OS) { | |
<< " const MCWriteProcResEntry *WPR,\n" | ||
<< " const MCWriteLatencyEntry *WL,\n" | ||
<< " const MCReadAdvanceEntry *RA, const InstrStage *IS,\n" | ||
<< " const unsigned *OC, const unsigned *FP) :\n" | ||
<< " const unsigned *OC, const unsigned *FP, StringTable NT) :\n" | ||
<< " MCSubtargetInfo(TT, CPU, TuneCPU, FS, PN, PF, PD,\n" | ||
<< " WPR, WL, RA, IS, OC, FP) { }\n\n" | ||
<< " WPR, WL, RA, IS, OC, FP, NT) { }\n\n" | ||
<< " unsigned resolveVariantSchedClass(unsigned SchedClass,\n" | ||
<< " const MCInst *MI, const MCInstrInfo *MCII,\n" | ||
<< " unsigned CPUID) const override {\n" | ||
|
@@ -2059,7 +2072,7 @@ void SubtargetEmitter::run(raw_ostream &OS) { | |
<< "ForwardingPaths"; | ||
} else | ||
OS << "nullptr, nullptr, nullptr"; | ||
OS << ");\n}\n\n"; | ||
OS << ", " << Target << "NameTable);\n}\n\n"; | ||
|
||
OS << "} // end namespace llvm\n\n"; | ||
|
||
|
@@ -2159,6 +2172,8 @@ void SubtargetEmitter::run(raw_ostream &OS) { | |
OS << "extern const unsigned " << Target << "ForwardingPaths[];\n"; | ||
} | ||
|
||
OS << "extern const llvm::StringTable " << Target << "NameTable;\n"; | ||
|
||
OS << ClassName << "::" << ClassName << "(const Triple &TT, StringRef CPU, " | ||
<< "StringRef TuneCPU, StringRef FS)\n"; | ||
|
||
|
@@ -2190,7 +2205,7 @@ void SubtargetEmitter::run(raw_ostream &OS) { | |
<< "ForwardingPaths"; | ||
} else | ||
OS << "nullptr, nullptr, nullptr"; | ||
OS << ") {}\n\n"; | ||
OS << ", " << Target << "NameTable) {}\n\n"; | ||
|
||
emitSchedModelHelpers(ClassName, OS); | ||
emitHwModeCheck(ClassName, OS); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we guard this def as well with
if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
? And in the constructor, assert that theNT
passed is empty() in non-assert builds optionally?