Skip to content

Commit 84807e9

Browse files
committed
[NFC][TableGen] Emit empty lines after/before namespace scope
Emit empty line after a namespace scope is opened and before its closed. Adjust DirectiveEmitter code empty line emission in response to this to avoid lot of unit test changes.
1 parent 0c707c9 commit 84807e9

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string>
2121

2222
namespace llvm {
23+
2324
// Simple RAII helper for emitting ifdef-undef-endif scope.
2425
class IfDefEmitter {
2526
public:
@@ -57,15 +58,15 @@ class NamespaceEmitter {
5758
NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
5859
: Name(trim(NameUntrimmed).str()), OS(OS) {
5960
if (!Name.empty())
60-
OS << "namespace " << Name << " {\n";
61+
OS << "namespace " << Name << " {\n\n";
6162
}
6263

6364
~NamespaceEmitter() { close(); }
6465

6566
// Explicit function to close the namespace scopes.
6667
void close() {
6768
if (!Closed && !Name.empty())
68-
OS << "} // namespace " << Name << "\n";
69+
OS << "\n} // namespace " << Name << "\n";
6970
Closed = true;
7071
}
7172

llvm/test/TableGen/directive1.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
6161
// CHECK-NEXT: #include <utility>
6262
// CHECK-EMPTY:
6363
// CHECK-NEXT: namespace llvm {
64+
// CHECK-EMPTY:
6465
// CHECK-NEXT: namespace tdl {
6566
// CHECK-EMPTY:
6667
// CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
@@ -176,6 +177,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
176177
// CHECK-NEXT: template <> struct enum_iteration_traits<tdl::Clause> {
177178
// CHECK-NEXT: static constexpr bool is_iterable = true;
178179
// CHECK-NEXT: };
180+
// CHECK-EMPTY:
179181
// CHECK-NEXT: } // namespace llvm
180182
// CHECK-EMPTY:
181183
// CHECK-NEXT: #endif // LLVM_Tdl_INC

llvm/test/TableGen/directive2.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
5454
// CHECK-NEXT: #include <utility>
5555
// CHECK-EMPTY:
5656
// CHECK-NEXT: namespace llvm {
57+
// CHECK-EMPTY:
5758
// CHECK-NEXT: namespace tdl {
5859
// CHECK-EMPTY:
5960
// CHECK-NEXT: enum class Association {
@@ -132,6 +133,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
132133
// CHECK-NEXT: LLVM_ABI Association getDirectiveAssociation(Directive D);
133134
// CHECK-NEXT: LLVM_ABI Category getDirectiveCategory(Directive D);
134135
// CHECK-NEXT: LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);
136+
// CHECK-EMPTY:
135137
// CHECK-NEXT: } // namespace tdl
136138
// CHECK-EMPTY:
137139
// CHECK-NEXT: template <> struct enum_iteration_traits<tdl::Association> {
@@ -149,6 +151,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
149151
// CHECK-NEXT: template <> struct enum_iteration_traits<tdl::Clause> {
150152
// CHECK-NEXT: static constexpr bool is_iterable = true;
151153
// CHECK-NEXT: };
154+
// CHECK-EMPTY:
152155
// CHECK-NEXT: } // namespace llvm
153156
// CHECK-EMPTY:
154157
// CHECK-NEXT: #endif // LLVM_Tdl_INC

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ static void generateEnumExports(ArrayRef<const Record *> Records,
8181
std::string N = getIdentifierName(R, Prefix);
8282
OS << "constexpr auto " << N << " = " << Enum << "::" << N << ";\n";
8383
}
84+
OS << "\n";
8485
}
8586

8687
// Generate enum class. Entries are emitted in the order in which they appear
8788
// in the `Records` vector.
8889
static void generateEnumClass(ArrayRef<const Record *> Records, raw_ostream &OS,
8990
StringRef Enum, StringRef Prefix,
9091
bool ExportEnums) {
91-
OS << "\n";
9292
OS << "enum class " << Enum << " {\n";
9393
if (!Records.empty()) {
9494
std::string N;
@@ -104,17 +104,15 @@ static void generateEnumClass(ArrayRef<const Record *> Records, raw_ostream &OS,
104104
OS << "};\n";
105105
OS << "\n";
106106
OS << "static constexpr std::size_t " << Enum
107-
<< "_enumSize = " << Records.size() << ";\n";
107+
<< "_enumSize = " << Records.size() << ";\n\n";
108108

109109
// Make the enum values available in the defined namespace. This allows us to
110110
// write something like Enum_X if we have a `using namespace <CppNamespace>`.
111111
// At the same time we do not loose the strong type guarantees of the enum
112112
// class, that is we cannot pass an unsigned as Directive without an explicit
113113
// cast.
114-
if (ExportEnums) {
115-
OS << "\n";
114+
if (ExportEnums)
116115
generateEnumExports(Records, OS, Enum, Prefix);
117-
}
118116
}
119117

120118
// Generate enum class with values corresponding to different bit positions.
@@ -127,7 +125,6 @@ static void generateEnumBitmask(ArrayRef<const Record *> Records,
127125
StringRef Type = Records.size() <= 32 ? "uint32_t" : "uint64_t";
128126
StringRef TypeSuffix = Records.size() <= 32 ? "U" : "ULL";
129127

130-
OS << "\n";
131128
OS << "enum class " << Enum << " : " << Type << " {\n";
132129
std::string LastName;
133130
for (auto [I, R] : llvm::enumerate(Records)) {
@@ -138,17 +135,15 @@ static void generateEnumBitmask(ArrayRef<const Record *> Records,
138135
OS << "};\n";
139136
OS << "\n";
140137
OS << "static constexpr std::size_t " << Enum
141-
<< "_enumSize = " << Records.size() << ";\n";
138+
<< "_enumSize = " << Records.size() << ";\n\n";
142139

143140
// Make the enum values available in the defined namespace. This allows us to
144141
// write something like Enum_X if we have a `using namespace <CppNamespace>`.
145142
// At the same time we do not loose the strong type guarantees of the enum
146143
// class, that is we cannot pass an unsigned as Directive without an explicit
147144
// cast.
148-
if (ExportEnums) {
149-
OS << "\n";
145+
if (ExportEnums)
150146
generateEnumExports(Records, OS, Enum, Prefix);
151-
}
152147
}
153148

154149
// Generate enums for values that clauses can take.
@@ -170,7 +165,6 @@ static void generateClauseEnumVal(ArrayRef<const Record *> Records,
170165
return;
171166
}
172167

173-
OS << "\n";
174168
OS << "enum class " << Enum << " {\n";
175169
for (const EnumVal Val : ClauseVals)
176170
OS << " " << Val.getRecordName() << "=" << Val.getValue() << ",\n";
@@ -182,6 +176,7 @@ static void generateClauseEnumVal(ArrayRef<const Record *> Records,
182176
OS << "constexpr auto " << CV->getName() << " = " << Enum
183177
<< "::" << CV->getName() << ";\n";
184178
}
179+
OS << "\n";
185180
EnumHelperFuncs += (Twine("LLVM_ABI ") + Twine(Enum) + Twine(" get") +
186181
Twine(Enum) + Twine("(StringRef Str);\n"))
187182
.str();
@@ -284,7 +279,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
284279
NamespaceEmitter DirLangNS(OS, DirLang.getCppNamespace());
285280

286281
if (DirLang.hasEnableBitmaskEnumInNamespace())
287-
OS << "\nLLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n";
282+
OS << "LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n\n";
288283

289284
// Emit Directive associations
290285
std::vector<const Record *> Associations;
@@ -315,7 +310,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
315310
generateClauseEnumVal(DirLang.getClauses(), OS, DirLang, EnumHelperFuncs);
316311

317312
// Generic function signatures
318-
OS << "\n";
319313
OS << "// Enumeration helper functions\n";
320314

321315
OS << "LLVM_ABI std::pair<Directive, directive::VersionRange> get" << Lang
@@ -353,10 +347,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
353347
OS << "LLVM_ABI Association getDirectiveAssociation(Directive D);\n";
354348
OS << "LLVM_ABI Category getDirectiveCategory(Directive D);\n";
355349
OS << "LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);\n";
356-
if (EnumHelperFuncs.length() > 0) {
357-
OS << EnumHelperFuncs;
358-
OS << "\n";
359-
}
350+
OS << EnumHelperFuncs;
360351

361352
DirLangNS.close();
362353

mlir/test/mlir-tblgen/cpp-class-comments.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def A_SomeOp1 : Op<A_Dialect, "some_op1", []>{
3636

3737
let cppNamespace = "OP1";
3838
// OP: namespace OP1
39+
// OP-EMPTY:
3940
// OP-NEXT: /// Some Op1 summary line1
4041
// OP-NEXT: /// summary line2
4142
// OP-NEXT: /// Some Op1 description
@@ -97,13 +98,15 @@ def EncodingTrait : AttrInterface<"EncodingTrait"> {
9798
let methods = [
9899
];
99100
// ATTR-INTERFACE: namespace mlir::a::traits {
101+
// ATTR-INTERFACE-EMPTY:
100102
// ATTR-INTERFACE-NEXT: /// Common trait for all layouts.
101103
// ATTR-INTERFACE-NEXT: class EncodingTrait;
102104
}
103105

104106
def SimpleEncodingTrait : AttrInterface<"SimpleEncodingTrait"> {
105107
let cppNamespace = "a::traits";
106108
// ATTR-INTERFACE: namespace a::traits {
109+
// ATTR-INTERFACE-EMPTY:
107110
// ATTR-INTERFACE-NEXT: class SimpleEncodingTrait;
108111
}
109112

@@ -114,6 +117,7 @@ def SimpleOpInterface : OpInterface<"SimpleOpInterface"> {
114117
Simple Op Interface description
115118
}];
116119
// OP-INTERFACE: namespace a::traits {
120+
// OP-INTERFACE-EMPTY:
117121
// OP-INTERFACE-NEXT: /// Simple Op Interface description
118122
// OP-INTERFACE-NEXT: class SimpleOpInterface;
119123
}

0 commit comments

Comments
 (0)