Skip to content

Commit a374b25

Browse files
authored
[NFC][TableGen] Migrate IfDef/Namespace emitter from MLIR to LLVM (#161744)
1 parent 17c73c3 commit a374b25

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include "CppGenUtilities.h"
1111
#include "mlir/TableGen/AttrOrTypeDef.h"
1212
#include "mlir/TableGen/Class.h"
13-
#include "mlir/TableGen/CodeGenHelpers.h"
1413
#include "mlir/TableGen/Format.h"
1514
#include "mlir/TableGen/GenInfo.h"
1615
#include "mlir/TableGen/Interfaces.h"
1716
#include "llvm/ADT/StringSet.h"
1817
#include "llvm/Support/CommandLine.h"
18+
#include "llvm/TableGen/CodeGenHelpers.h"
1919
#include "llvm/TableGen/Error.h"
2020
#include "llvm/TableGen/TableGenBackend.h"
2121

@@ -71,14 +71,14 @@ class DefGen {
7171

7272
void emitDecl(raw_ostream &os) const {
7373
if (storageCls && def.genStorageClass()) {
74-
NamespaceEmitter ns(os, def.getStorageNamespace());
74+
llvm::NamespaceEmitter ns(os, def.getStorageNamespace());
7575
os << "struct " << def.getStorageClassName() << ";\n";
7676
}
7777
defCls.writeDeclTo(os);
7878
}
7979
void emitDef(raw_ostream &os) const {
8080
if (storageCls && def.genStorageClass()) {
81-
NamespaceEmitter ns(os, def.getStorageNamespace());
81+
llvm::NamespaceEmitter ns(os, def.getStorageNamespace());
8282
storageCls->writeDeclTo(os); // everything is inline
8383
}
8484
defCls.writeDefTo(os);
@@ -850,7 +850,7 @@ class AsmPrinter;
850850

851851
bool DefGenerator::emitDecls(StringRef selectedDialect) {
852852
emitSourceFileHeader((defType + "Def Declarations").str(), os);
853-
IfDefScope scope("GET_" + defType.upper() + "DEF_CLASSES", os);
853+
llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_CLASSES");
854854

855855
// Output the common "header".
856856
os << typeDefDeclHeader;
@@ -860,7 +860,7 @@ bool DefGenerator::emitDecls(StringRef selectedDialect) {
860860
if (defs.empty())
861861
return false;
862862
{
863-
NamespaceEmitter nsEmitter(os, defs.front().getDialect());
863+
DialectNamespaceEmitter nsEmitter(os, defs.front().getDialect());
864864

865865
// Declare all the def classes first (in case they reference each other).
866866
for (const AttrOrTypeDef &def : defs) {
@@ -892,7 +892,7 @@ bool DefGenerator::emitDecls(StringRef selectedDialect) {
892892
//===----------------------------------------------------------------------===//
893893

894894
void DefGenerator::emitTypeDefList(ArrayRef<AttrOrTypeDef> defs) {
895-
IfDefScope scope("GET_" + defType.upper() + "DEF_LIST", os);
895+
llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_LIST");
896896
auto interleaveFn = [&](const AttrOrTypeDef &def) {
897897
os << def.getDialect().getCppNamespace() << "::" << def.getCppClassName();
898898
};
@@ -1083,11 +1083,11 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
10831083
return false;
10841084
emitTypeDefList(defs);
10851085

1086-
IfDefScope scope("GET_" + defType.upper() + "DEF_CLASSES", os);
1086+
llvm::IfDefEmitter scope(os, "GET_" + defType.upper() + "DEF_CLASSES");
10871087
emitParsePrintDispatch(defs);
10881088
for (const AttrOrTypeDef &def : defs) {
10891089
{
1090-
NamespaceEmitter ns(os, def.getDialect());
1090+
DialectNamespaceEmitter ns(os, def.getDialect());
10911091
DefGen gen(def);
10921092
gen.emitDef(os);
10931093
}
@@ -1102,7 +1102,7 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
11021102

11031103
// Emit the default parser/printer for Attributes if the dialect asked for it.
11041104
if (isAttrGenerator && firstDialect.useDefaultAttributePrinterParser()) {
1105-
NamespaceEmitter nsEmitter(os, firstDialect);
1105+
DialectNamespaceEmitter nsEmitter(os, firstDialect);
11061106
if (firstDialect.isExtensible()) {
11071107
os << llvm::formatv(dialectDefaultAttrPrinterParserDispatch,
11081108
firstDialect.getCppClassName(),
@@ -1116,7 +1116,7 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
11161116

11171117
// Emit the default parser/printer for Types if the dialect asked for it.
11181118
if (!isAttrGenerator && firstDialect.useDefaultTypePrinterParser()) {
1119-
NamespaceEmitter nsEmitter(os, firstDialect);
1119+
DialectNamespaceEmitter nsEmitter(os, firstDialect);
11201120
if (firstDialect.isExtensible()) {
11211121
os << llvm::formatv(dialectDefaultTypePrinterParserDispatch,
11221122
firstDialect.getCppClassName(),

mlir/tools/mlir-tblgen/DialectGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static const char *const discardableAttrHelperDecl = R"(
242242
static void emitDialectDecl(Dialect &dialect, raw_ostream &os) {
243243
// Emit all nested namespaces.
244244
{
245-
NamespaceEmitter nsEmitter(os, dialect);
245+
DialectNamespaceEmitter nsEmitter(os, dialect);
246246

247247
// Emit the start of the decl.
248248
std::string cppName = dialect.getCppClassName();
@@ -358,7 +358,7 @@ static void emitDialectDef(Dialect &dialect, const RecordKeeper &records,
358358
<< "::" << cppClassName << ")\n";
359359

360360
// Emit all nested namespaces.
361-
NamespaceEmitter nsEmitter(os, dialect);
361+
DialectNamespaceEmitter nsEmitter(os, dialect);
362362

363363
/// Build the list of dependent dialects.
364364
std::string dependentDialectRegistrations;

mlir/tools/mlir-tblgen/OmpOpGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static bool verifyDecls(const RecordKeeper &records, raw_ostream &) {
342342
/// structures according to the `clauses` argument of each definition deriving
343343
/// from `OpenMP_Op`.
344344
static bool genClauseOps(const RecordKeeper &records, raw_ostream &os) {
345-
mlir::tblgen::NamespaceEmitter ns(os, "mlir::omp");
345+
llvm::NamespaceEmitter ns(os, "mlir::omp");
346346
for (const Record *clause : records.getAllDerivedDefinitions("OpenMP_Clause"))
347347
genClauseOpsStruct(clause, os);
348348

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/Support/ErrorHandling.h"
3737
#include "llvm/Support/Signals.h"
3838
#include "llvm/Support/raw_ostream.h"
39+
#include "llvm/TableGen/CodeGenHelpers.h"
3940
#include "llvm/TableGen/Error.h"
4041
#include "llvm/TableGen/Record.h"
4142
#include "llvm/TableGen/TableGenBackend.h"
@@ -4855,7 +4856,7 @@ static void emitOpClassDecls(const RecordKeeper &records,
48554856
}
48564857

48574858
// Emit the op class declarations.
4858-
IfDefScope scope("GET_OP_CLASSES", os);
4859+
IfDefEmitter scope(os, "GET_OP_CLASSES");
48594860
if (defs.empty())
48604861
return;
48614862
StaticVerifierFunctionEmitter staticVerifierEmitter(os, records);
@@ -4898,7 +4899,7 @@ static bool emitOpDecls(const RecordKeeper &records, raw_ostream &os) {
48984899
return false;
48994900

49004901
Dialect dialect = Operator(defs.front()).getDialect();
4901-
NamespaceEmitter ns(os, dialect);
4902+
DialectNamespaceEmitter ns(os, dialect);
49024903

49034904
const char *const opRegistrationHook =
49044905
"void register{0}Operations{1}({2}::{0} *dialect);\n";
@@ -4921,7 +4922,7 @@ static void emitOpDefShard(const RecordKeeper &records,
49214922
std::string shardGuard = "GET_OP_DEFS_";
49224923
std::string indexStr = std::to_string(shardIndex);
49234924
shardGuard += indexStr;
4924-
IfDefScope scope(shardGuard, os);
4925+
IfDefEmitter scope(os, shardGuard);
49254926

49264927
// Emit the op registration hook in the first shard.
49274928
const char *const opRegistrationHook =
@@ -4962,14 +4963,14 @@ static bool emitOpDefs(const RecordKeeper &records, raw_ostream &os) {
49624963
// If no shard was requested, emit the regular op list and class definitions.
49634964
if (shardedDefs.size() == 1) {
49644965
{
4965-
IfDefScope scope("GET_OP_LIST", os);
4966+
IfDefEmitter scope(os, "GET_OP_LIST");
49664967
interleave(
49674968
defs, os,
49684969
[&](const Record *def) { os << Operator(def).getQualCppClassName(); },
49694970
",\n");
49704971
}
49714972
{
4972-
IfDefScope scope("GET_OP_CLASSES", os);
4973+
IfDefEmitter scope(os, "GET_OP_CLASSES");
49734974
emitOpClassDefs(records, defs, os);
49744975
}
49754976
return false;

mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ using mlir::tblgen::EnumCase;
5050
using mlir::tblgen::EnumInfo;
5151
using mlir::tblgen::NamedAttribute;
5252
using mlir::tblgen::NamedTypeConstraint;
53-
using mlir::tblgen::NamespaceEmitter;
5453
using mlir::tblgen::Operator;
5554

5655
//===----------------------------------------------------------------------===//
@@ -261,7 +260,7 @@ static void emitInterfaceDecl(const Availability &availability,
261260
std::string(formatv("{0}Traits", interfaceName));
262261

263262
StringRef cppNamespace = availability.getInterfaceClassNamespace();
264-
NamespaceEmitter nsEmitter(os, cppNamespace);
263+
llvm::NamespaceEmitter nsEmitter(os, cppNamespace);
265264
os << "class " << interfaceName << ";\n\n";
266265

267266
// Emit the traits struct containing the concept and model declarations.

0 commit comments

Comments
 (0)