Skip to content

Commit 02277d1

Browse files
jpienaarakadutta
authored andcommitted
[mlir][tblgen] Avoid compilation failure (llvm#161545)
This would have failed during compilation post generation later, trim and use raw string literals to avoid such failures. Probably a few more places where similar failures could occur, but this was unexpected failure user ran into.
1 parent f734896 commit 02277d1

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

mlir/tools/mlir-tblgen/PassGen.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class {0}Base : public {1} {
195195
}
196196
::llvm::StringRef getArgument() const override { return "{2}"; }
197197
198-
::llvm::StringRef getDescription() const override { return "{3}"; }
198+
::llvm::StringRef getDescription() const override { return R"PD({3})PD"; }
199199
200200
/// Returns the derived pass name.
201201
static constexpr ::llvm::StringLiteral getPassName() {
@@ -271,9 +271,9 @@ static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) {
271271
os.indent(2) << "::mlir::Pass::"
272272
<< (opt.isListOption() ? "ListOption" : "Option");
273273

274-
os << formatv(R"(<{0}> {1}{{*this, "{2}", ::llvm::cl::desc("{3}"))",
274+
os << formatv(R"(<{0}> {1}{{*this, "{2}", ::llvm::cl::desc(R"PO({3})PO"))",
275275
opt.getType(), opt.getCppVariableName(), opt.getArgument(),
276-
opt.getDescription());
276+
opt.getDescription().trim());
277277
if (std::optional<StringRef> defaultVal = opt.getDefaultValue())
278278
os << ", ::llvm::cl::init(" << defaultVal << ")";
279279
if (std::optional<StringRef> additionalFlags = opt.getAdditionalFlags())
@@ -285,9 +285,10 @@ static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) {
285285
/// Emit the declarations for each of the pass statistics.
286286
static void emitPassStatisticDecls(const Pass &pass, raw_ostream &os) {
287287
for (const PassStatistic &stat : pass.getStatistics()) {
288-
os << formatv(" ::mlir::Pass::Statistic {0}{{this, \"{1}\", \"{2}\"};\n",
289-
stat.getCppVariableName(), stat.getName(),
290-
stat.getDescription());
288+
os << formatv(
289+
" ::mlir::Pass::Statistic {0}{{this, \"{1}\", R\"PS({2})PS\"};\n",
290+
stat.getCppVariableName(), stat.getName(),
291+
stat.getDescription().trim());
291292
}
292293
}
293294

@@ -320,7 +321,7 @@ static void emitPassDefs(const Pass &pass, raw_ostream &os) {
320321

321322
os << "namespace impl {\n";
322323
os << formatv(baseClassBegin, passName, pass.getBaseClass(),
323-
pass.getArgument(), pass.getSummary(),
324+
pass.getArgument(), pass.getSummary().trim(),
324325
dependentDialectRegistrations);
325326

326327
if (ArrayRef<PassOption> options = pass.getOptions(); !options.empty()) {
@@ -393,7 +394,7 @@ class {0}Base : public {1} {
393394
}
394395
::llvm::StringRef getArgument() const override { return "{2}"; }
395396
396-
::llvm::StringRef getDescription() const override { return "{3}"; }
397+
::llvm::StringRef getDescription() const override { return R"PD({3})PD"; }
397398
398399
/// Returns the derived pass name.
399400
static constexpr ::llvm::StringLiteral getPassName() {
@@ -439,7 +440,7 @@ static void emitOldPassDecl(const Pass &pass, raw_ostream &os) {
439440
"\n ");
440441
}
441442
os << formatv(oldPassDeclBegin, defName, pass.getBaseClass(),
442-
pass.getArgument(), pass.getSummary(),
443+
pass.getArgument(), pass.getSummary().trim(),
443444
dependentDialectRegistrations);
444445
emitPassOptionDecls(pass, os);
445446
emitPassStatisticDecls(pass, os);

mlir/unittests/TableGen/passes.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ def TestPassWithOptions : Pass<"test"> {
1919

2020
let options = [
2121
Option<"testOption", "testOption", "int", "0", "Test option">,
22-
ListOption<"testListOption", "test-list-option", "int64_t",
23-
"Test list option">
22+
// Testing the output of multi-line description. This would fail compilation
23+
// if not properly handled.
24+
ListOption<"testListOption", "test-list-option", "int64_t", [{
25+
Test
26+
list option}]>
2427
];
2528
}
2629

0 commit comments

Comments
 (0)