Skip to content

Commit 2e1bd7f

Browse files
committed
Address review comments
1 parent 9d978ca commit 2e1bd7f

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

llvm/include/llvm/Frontend/Directive/Spelling.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Spelling.h ------------------------------------------------ C++ -*-===//
1+
//===-------------------------------------------------------------- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/iterator_range.h"
1313

1414
#include <limits>
15+
#include <tuple>
1516

1617
namespace llvm::directive {
1718

@@ -21,13 +22,11 @@ struct VersionRange {
2122
// in the maximum range.
2223
int Min = 0;
2324
int Max = MaxValue;
24-
};
2525

26-
inline bool operator<(const VersionRange &A, const VersionRange &B) {
27-
if (A.Min != B.Min)
28-
return A.Min < B.Min;
29-
return A.Max < B.Max;
30-
}
26+
bool operator<(const VersionRange &R) const {
27+
return std::tie(Min, Max) < std::tie(R.Min, R.Max);
28+
}
29+
};
3130

3231
struct Spelling {
3332
StringRef Name;

llvm/include/llvm/TableGen/DirectiveEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Versioned {
116116

117117
class Spelling : public Versioned {
118118
public:
119-
using Value = llvm::directive::Spelling;
119+
using Value = directive::Spelling;
120120

121121
Spelling(const Record *Def) : Def(Def) {}
122122

llvm/lib/Frontend/Directive/Spelling.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Spelling.cpp ---------------------------------------------- C++ -*-===//
1+
//===-------------------------------------------------------------- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,13 +13,14 @@
1313

1414
#include <cassert>
1515

16-
static bool Contains(llvm::directive::VersionRange V, int P) {
16+
using namespace llvm;
17+
18+
static bool Contains(directive::VersionRange V, int P) {
1719
return V.Min <= P && P <= V.Max;
1820
}
1921

2022
llvm::StringRef llvm::directive::FindName(
21-
llvm::iterator_range<const llvm::directive::Spelling *> Range,
22-
unsigned Version) {
23+
llvm::iterator_range<const directive::Spelling *> Range, unsigned Version) {
2324
assert(llvm::isInt<8 * sizeof(int)>(Version) && "Version value out of range");
2425

2526
int V = Version;

llvm/test/TableGen/directive1.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
355355
// IMPL-NEXT: case TDLC_clauseb:
356356
// IMPL-NEXT: return "clauseb";
357357
// IMPL-NEXT: case TDLC_clausec: {
358-
// IMPL-NEXT: static const llvm::directive::Spelling TDLC_clausec_spellings[] = {
358+
// IMPL-NEXT: static constexpr llvm::directive::Spelling TDLC_clausec_spellings[] = {
359359
// IMPL-NEXT: {"clausec", {0, 2147483647}},
360360
// IMPL-NEXT: {"ccccccc", {0, 2147483647}},
361361
// IMPL-NEXT: };

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,6 @@ static std::vector<Spelling::Value>
387387
orderSpellings(ArrayRef<Spelling::Value> Spellings) {
388388
std::vector<Spelling::Value> List(Spellings.begin(), Spellings.end());
389389

390-
// There are two intertwined orderings: (1) the order between spellings
391-
// (used here), and (2) the order between a spelling and a version (used
392-
// at runtime).
393-
// Define order (2) as such that the first A that is not less than V
394-
// will be the selected spelling given V. Specifically,
395-
// V <(2) A <=> V < A.Min
396-
// A <(2) V <=> A.Max < V
397-
//
398-
// The orders have to be compatible, i.e.
399-
// A <(2) V and !(V <(2) B) => A <(1) B, and
400-
// !(A <(2) v) and V <(2) B => A <(1) B
401-
// In other words, the transitive closure of (2) must contain (1).
402390
llvm::stable_sort(List,
403391
[](const Spelling::Value &A, const Spelling::Value &B) {
404392
return A.Versions < B.Versions;
@@ -421,16 +409,16 @@ static void generateGetName(ArrayRef<const Record *> Records, raw_ostream &OS,
421409
BaseRecord Rec(R);
422410
std::string Ident = getIdentifierName(R, Prefix);
423411
OS << " case " << Ident << ":";
424-
auto Spellings(orderSpellings(Rec.getSpellings()));
412+
std::vector<Spelling::Value> Spellings(orderSpellings(Rec.getSpellings()));
425413
assert(Spellings.size() != 0 && "No spellings for this item");
426414
if (Spellings.size() == 1) {
427415
OS << "\n";
428416
OS << " return \"" << Spellings.front().Name << "\";\n";
429417
} else {
430418
OS << " {\n";
431419
std::string SpellingsName = Ident + "_spellings";
432-
OS << " static const llvm::directive::Spelling " << SpellingsName
433-
<< "[] = {\n";
420+
OS << " static constexpr llvm::directive::Spelling "
421+
<< SpellingsName << "[] = {\n";
434422
for (auto &S : Spellings) {
435423
OS << " {\"" << S.Name << "\", {" << S.Versions.Min << ", "
436424
<< S.Versions.Max << "}},\n";
@@ -484,11 +472,10 @@ static void generateGetKind(ArrayRef<const Record *> Records, raw_ostream &OS,
484472

485473
for (auto &[Name, Versions] : Rec.getSpellings()) {
486474
OS << " .Case(\"" << Name << "\", {" << Ident << ", ";
487-
if (Versions.Min == All.Min && Versions.Max == All.Max) {
475+
if (Versions.Min == All.Min && Versions.Max == All.Max)
488476
OS << "All})\n";
489-
} else {
477+
else
490478
OS << "{" << Versions.Min << ", " << Versions.Max << "}})\n";
491-
}
492479
}
493480
}
494481
OS << " .Default({" << DefaultName << ", All});\n";

0 commit comments

Comments
 (0)