-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[TableGen] Use heterogenous lookups with std::map (NFC) #115810
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
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_heterogenous_DiagsInGroup
Nov 12, 2024
Merged
[TableGen] Use heterogenous lookups with std::map (NFC) #115810
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_heterogenous_DiagsInGroup
Nov 12, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string. This patch introduces alias: using DiagsInGroup = std::map<std::string, GroupInfo, std::less<>>; because the raw type is a bit mouthful.
Member
|
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesHeterogenous lookups allow us to call find with StringRef, avoiding a This patch introduces alias: using DiagsInGroup = std::map<std::string, GroupInfo, std::less<>>; because the raw type is a bit mouthful. Full diff: https://github.com/llvm/llvm-project/pull/115810.diff 1 Files Affected:
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 34e2e8f47ae71a..52198a32b1bb08 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -153,11 +153,13 @@ static bool diagGroupBeforeByName(const Record *LHS, const Record *RHS) {
RHS->getValueAsString("GroupName");
}
+using DiagsInGroupTy = std::map<std::string, GroupInfo, std::less<>>;
+
/// Invert the 1-[0/1] mapping of diags to group into a one to many
/// mapping of groups to diags in the group.
static void groupDiagnostics(ArrayRef<const Record *> Diags,
ArrayRef<const Record *> DiagGroups,
- std::map<std::string, GroupInfo> &DiagsInGroup) {
+ DiagsInGroupTy &DiagsInGroup) {
for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
const Record *R = Diags[i];
@@ -256,14 +258,14 @@ class InferPedantic {
DiagGroupParentMap &DiagGroupParents;
ArrayRef<const Record *> Diags;
const std::vector<const Record *> DiagGroups;
- std::map<std::string, GroupInfo> &DiagsInGroup;
+ DiagsInGroupTy &DiagsInGroup;
DenseSet<const Record *> DiagsSet;
GMap GroupCount;
public:
InferPedantic(DiagGroupParentMap &DiagGroupParents,
ArrayRef<const Record *> Diags,
ArrayRef<const Record *> DiagGroups,
- std::map<std::string, GroupInfo> &DiagsInGroup)
+ DiagsInGroupTy &DiagsInGroup)
: DiagGroupParents(DiagGroupParents), Diags(Diags),
DiagGroups(DiagGroups), DiagsInGroup(DiagsInGroup) {}
@@ -1426,7 +1428,7 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
ArrayRef<const Record *> DiagGroups =
Records.getAllDerivedDefinitions("DiagGroup");
- std::map<std::string, GroupInfo> DiagsInGroup;
+ DiagsInGroupTy DiagsInGroup;
groupDiagnostics(Diags, DiagGroups, DiagsInGroup);
DiagCategoryIDMap CategoryIDs(Records);
@@ -1549,7 +1551,7 @@ static std::string getDiagCategoryEnum(StringRef name) {
/// }
/// \endcode
///
-static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
+static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
RecordVec &GroupsInPedantic, raw_ostream &OS) {
OS << "static const int16_t DiagSubGroups[] = {\n"
<< " /* Empty */ -1,\n";
@@ -1601,7 +1603,7 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
/// };
/// \endcode
///
-static void emitDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
+static void emitDiagArrays(DiagsInGroupTy &DiagsInGroup,
RecordVec &DiagsInPedantic, raw_ostream &OS) {
OS << "static const int16_t DiagArrays[] = {\n"
<< " /* Empty */ -1,\n";
@@ -1653,7 +1655,7 @@ static void emitDiagGroupNames(const StringToOffsetTable &GroupNames,
/// static const char DiagGroupNames[];
/// #endif
/// \endcode
-static void emitAllDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
+static void emitAllDiagArrays(DiagsInGroupTy &DiagsInGroup,
RecordVec &DiagsInPedantic,
RecordVec &GroupsInPedantic,
const StringToOffsetTable &GroupNames,
@@ -1680,7 +1682,7 @@ static void emitAllDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
/// {/* deprecated */ 1981,/* DiagArray1 */ 348, /* DiagSubGroup3 */ 9},
/// #endif
/// \endcode
-static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
+static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
RecordVec &DiagsInPedantic,
RecordVec &GroupsInPedantic,
const StringToOffsetTable &GroupNames,
@@ -1782,7 +1784,7 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
ArrayRef<const Record *> DiagGroups =
Records.getAllDerivedDefinitions("DiagGroup");
- std::map<std::string, GroupInfo> DiagsInGroup;
+ DiagsInGroupTy DiagsInGroup;
groupDiagnostics(Diags, DiagGroups, DiagsInGroup);
// All extensions are implicitly in the "pedantic" group. Record the
@@ -1856,11 +1858,11 @@ namespace docs {
namespace {
bool isRemarkGroup(const Record *DiagGroup,
- const std::map<std::string, GroupInfo> &DiagsInGroup) {
+ const DiagsInGroupTy &DiagsInGroup) {
bool AnyRemarks = false, AnyNonRemarks = false;
std::function<void(StringRef)> Visit = [&](StringRef GroupName) {
- auto &GroupInfo = DiagsInGroup.find(std::string(GroupName))->second;
+ auto &GroupInfo = DiagsInGroup.find(GroupName)->second;
for (const Record *Diag : GroupInfo.DiagsInGroup)
(isRemark(*Diag) ? AnyRemarks : AnyNonRemarks) = true;
for (const auto &Name : GroupInfo.SubGroups)
@@ -1880,13 +1882,12 @@ std::string getDefaultSeverity(const Record *Diag) {
Diag->getValueAsDef("DefaultSeverity")->getValueAsString("Name"));
}
-std::set<std::string>
-getDefaultSeverities(const Record *DiagGroup,
- const std::map<std::string, GroupInfo> &DiagsInGroup) {
+std::set<std::string> getDefaultSeverities(const Record *DiagGroup,
+ const DiagsInGroupTy &DiagsInGroup) {
std::set<std::string> States;
std::function<void(StringRef)> Visit = [&](StringRef GroupName) {
- auto &GroupInfo = DiagsInGroup.find(std::string(GroupName))->second;
+ auto &GroupInfo = DiagsInGroup.find(GroupName)->second;
for (const Record *Diag : GroupInfo.DiagsInGroup)
States.insert(getDefaultSeverity(Diag));
for (const auto &Name : GroupInfo.SubGroups)
@@ -1940,7 +1941,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
DiagGroupParentMap DGParentMap(Records);
- std::map<std::string, GroupInfo> DiagsInGroup;
+ DiagsInGroupTy DiagsInGroup;
groupDiagnostics(Diags, DiagGroups, DiagsInGroup);
// Compute the set of diagnostics that are in -Wpedantic.
|
nikic
approved these changes
Nov 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
This patch introduces alias:
using DiagsInGroup = std::map<std::string, GroupInfo, std::less<>>;
because the raw type is a bit mouthful.