Skip to content

Commit b5ea23b

Browse files
OrestChuraMaxim-Doronin
authored andcommitted
Fix MLIR-TblGen to fix KW issues (#1)
* - fixed uninitialized array declaration in `mlir-tblgen/OpFormatGen.cpp` - fixed creating `void` methods returning value in `mlir-tblgen/OpInterfacesGen.cpp` * Apply comment on OpInterfacesGen.cpp by nikita-kud
1 parent 54baca7 commit b5ea23b

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
840840
}
841841
} else {
842842
body << " ::mlir::OpAsmParser::UnresolvedOperand " << name
843-
<< "RawOperands[1];\n"
843+
<< "RawOperands[1] = { };\n"
844844
<< " ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
845845
<< name << "Operands(" << name << "RawOperands);";
846846
}
@@ -877,7 +877,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
877877
if (lengthKind != ArgumentLengthKind::Single)
878878
body << " ::llvm::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
879879
else
880-
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name)
880+
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1] = {{ };\n", name)
881881
<< llvm::formatv(
882882
" ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
883883
name);

mlir/tools/mlir-tblgen/OpInterfacesGen.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,18 @@ static void emitInterfaceDefMethods(StringRef interfaceQualName,
179179
raw_ostream &os, bool isOpInterface) {
180180
for (auto &method : interface.getMethods()) {
181181
emitInterfaceMethodDoc(method, os);
182-
emitCPPType(method.getReturnType(), os);
182+
auto returnType = method.getReturnType();
183+
emitCPPType(returnType, os);
183184
os << interfaceQualName << "::";
184185
emitMethodNameAndArgs(method, os, valueType, /*addThisArg=*/false,
185186
/*addConst=*/!isOpInterface);
186187

187188
// Forward to the method on the concrete operation type.
188-
os << " {\n return " << implValue << "->" << method.getName() << '(';
189+
os << " {\n ";
190+
if (returnType != "void") {
191+
os << "return ";
192+
}
193+
os << implValue << "->" << method.getName() << '(';
189194
if (!method.isStatic()) {
190195
os << implValue << ", ";
191196
os << (isOpInterface ? "getOperation()" : "*this");
@@ -345,7 +350,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
345350

346351
for (auto &method : interface.getMethods()) {
347352
os << "template<typename " << valueTemplate << ">\n";
348-
emitCPPType(method.getReturnType(), os);
353+
auto returnType = method.getReturnType();
354+
emitCPPType(returnType, os);
349355
os << "detail::" << interface.getName() << "InterfaceTraits::Model<"
350356
<< valueTemplate << ">::";
351357
emitMethodNameAndArgs(method, os, valueType,
@@ -364,10 +370,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
364370
}
365371

366372
// Forward to the method on the concrete operation type.
367-
if (method.isStatic())
368-
os << "return " << valueTemplate << "::";
369-
else
370-
os << tblgen::tgfmt("return $_self.", &nonStaticMethodFmt);
373+
if (returnType != "void") {
374+
os << "return ";
375+
}
376+
377+
if (method.isStatic()) {
378+
os << valueTemplate << "::";
379+
} else {
380+
os << tblgen::tgfmt("$_self.", &nonStaticMethodFmt);
381+
}
371382

372383
// Add the arguments to the call.
373384
os << method.getName() << '(';
@@ -379,7 +390,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
379390

380391
for (auto &method : interface.getMethods()) {
381392
os << "template<typename " << valueTemplate << ">\n";
382-
emitCPPType(method.getReturnType(), os);
393+
auto returnType = method.getReturnType();
394+
emitCPPType(returnType, os);
383395
os << "detail::" << interface.getName() << "InterfaceTraits::FallbackModel<"
384396
<< valueTemplate << ">::";
385397
emitMethodNameAndArgs(method, os, valueType,
@@ -388,11 +400,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
388400
os << " {\n ";
389401

390402
// Forward to the method on the concrete Model implementation.
391-
if (method.isStatic())
392-
os << "return " << valueTemplate << "::";
393-
else
394-
os << "return static_cast<const " << valueTemplate << " *>(impl)->";
403+
if (returnType != "void") {
404+
os << "return ";
405+
}
395406

407+
if (method.isStatic()) {
408+
os << valueTemplate << "::";
409+
} else {
410+
os << "static_cast<const " << valueTemplate << " *>(impl)->";
411+
}
396412
// Add the arguments to the call.
397413
os << method.getName() << '(';
398414
if (!method.isStatic())
@@ -430,7 +446,7 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
430446
if (!method.isStatic())
431447
os << " const";
432448

433-
os << " {\n";
449+
os << " {\n ";
434450

435451
// Use the empty context for static methods.
436452
tblgen::FmtContext ctx;
@@ -533,7 +549,7 @@ void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) {
533549
<< "struct " << interfaceTraitsName << " {\n";
534550
emitConceptDecl(interface);
535551
emitModelDecl(interface);
536-
os << "};";
552+
os << "};\n";
537553

538554
// Emit the derived trait for the interface.
539555
os << "template <typename " << valueTemplate << ">\n";

0 commit comments

Comments
 (0)