-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Use const members of StringToOffsetTable
#105824
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
Conversation
jurahul
commented
Aug 23, 2024
- After the table is populated and emitted as a string, we do not expect any modifications to the table. So use const reference and const members to access the table from that point on.
- After the table is populated and emitted as a string, we do not expect any modifications to the table. So use const reference and const members to access the table from that point on.
@llvm/pr-subscribers-clang Author: Rahul Joshi (jurahul) Changes
Full diff: https://github.com/llvm/llvm-project/pull/105824.diff 2 Files Affected:
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b290530444d2ab..6ca24a8c74b2ff 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1634,7 +1634,7 @@ static void emitDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
/// \000\020#pragma-messages\t#warnings\020CFString-literal"
/// };
/// \endcode
-static void emitDiagGroupNames(StringToOffsetTable &GroupNames,
+static void emitDiagGroupNames(const StringToOffsetTable &GroupNames,
raw_ostream &OS) {
OS << "static const char DiagGroupNames[] = {\n";
GroupNames.EmitString(OS);
@@ -1656,7 +1656,7 @@ static void emitDiagGroupNames(StringToOffsetTable &GroupNames,
static void emitAllDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
RecordVec &DiagsInPedantic,
RecordVec &GroupsInPedantic,
- StringToOffsetTable &GroupNames,
+ const StringToOffsetTable &GroupNames,
raw_ostream &OS) {
OS << "\n#ifdef GET_DIAG_ARRAYS\n";
emitDiagArrays(DiagsInGroup, DiagsInPedantic, OS);
@@ -1683,7 +1683,8 @@ static void emitAllDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
RecordVec &DiagsInPedantic,
RecordVec &GroupsInPedantic,
- StringToOffsetTable &GroupNames, raw_ostream &OS) {
+ const StringToOffsetTable &GroupNames,
+ raw_ostream &OS) {
unsigned MaxLen = 0;
for (auto const &I: DiagsInGroup)
@@ -1705,7 +1706,7 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
OS << I.first << " */, ";
// Store a pascal-style length byte at the beginning of the string.
std::string Name = char(I.first.size()) + I.first;
- OS << GroupNames.GetOrAddStringOffset(Name, false) << ", ";
+ OS << *GroupNames.GetStringOffset(Name) << ", ";
// Special handling for 'pedantic'.
const bool IsPedantic = I.first == "pedantic";
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 5035ef52707f4e..98d0231d3055c2 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2871,7 +2871,7 @@ static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info,
static void
emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
const AsmMatcherInfo &Info, StringRef ClassName,
- StringToOffsetTable &StringTable,
+ const StringToOffsetTable &StringTable,
unsigned MaxMnemonicIndex, unsigned MaxFeaturesIndex,
bool HasMnemonicFirst, const Record &AsmParser) {
unsigned MaxMask = 0;
@@ -2924,8 +2924,8 @@ emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
// Store a pascal-style length byte in the mnemonic.
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.lower();
- OS << StringTable.GetOrAddStringOffset(LenMnemonic, false) << " /* "
- << II.Mnemonic << " */, ";
+ OS << *StringTable.GetStringOffset(LenMnemonic) << " /* " << II.Mnemonic
+ << " */, ";
OS << OMI.OperandMask;
OS << " /* ";
@@ -3554,8 +3554,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
// Store a pascal-style length byte in the mnemonic.
std::string LenMnemonic =
char(MI->Mnemonic.size()) + MI->Mnemonic.lower();
- OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false)
- << " /* " << MI->Mnemonic << " */, " << Target.getInstNamespace()
+ OS << " { " << *StringTable.GetStringOffset(LenMnemonic) << " /* "
+ << MI->Mnemonic << " */, " << Target.getInstNamespace()
<< "::" << MI->getResultInst()->TheDef->getName() << ", "
<< MI->ConversionFnKind << ", ";
|
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.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/3089 Here is the relevant piece of the build log for the reference:
|
…d30a1ccd0 Local branch amd-gfx 56dd30a Merged main:b6603e1bf11dee4761e49af6581c8b8f074b705d into amd-gfx:3ab64ddfc135 Remote branch main 1193f7d [NFC] Use const members of `StringToOffsetTable` (llvm#105824)