Skip to content

Commit e70c8bb

Browse files
OrestChuranikita-kud
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 33998fa commit e70c8bb

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
820820
}
821821
} else {
822822
body << " ::mlir::OpAsmParser::UnresolvedOperand " << name
823-
<< "RawOperands[1];\n"
823+
<< "RawOperands[1] = { };\n"
824824
<< " ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> "
825825
<< name << "Operands(" << name << "RawOperands);";
826826
}
@@ -857,7 +857,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
857857
if (lengthKind != ArgumentLengthKind::Single)
858858
body << " ::llvm::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
859859
else
860-
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name)
860+
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1] = {{ };\n", name)
861861
<< llvm::formatv(
862862
" ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
863863
name);

mlir/tools/mlir-tblgen/OpInterfacesGen.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,20 @@ static void emitInterfaceDef(const Interface &interface, StringRef valueType,
167167
// Insert the method definitions.
168168
bool isOpInterface = isa<OpInterface>(interface);
169169
for (auto &method : interface.getMethods()) {
170-
emitCPPType(method.getReturnType(), os);
170+
auto returnType = method.getReturnType();
171+
emitCPPType(returnType, os);
171172
if (!cppNamespace.empty())
172173
os << cppNamespace << "::";
173174
os << interfaceName << "::";
174175
emitMethodNameAndArgs(method, os, valueType, /*addThisArg=*/false,
175176
/*addConst=*/!isOpInterface);
176177

177178
// Forward to the method on the concrete operation type.
178-
os << " {\n return getImpl()->" << method.getName() << '(';
179+
os << " {\n ";
180+
if (returnType != "void") {
181+
os << "return ";
182+
}
183+
os << "getImpl()->" << method.getName() << '(';
179184
if (!method.isStatic()) {
180185
os << "getImpl(), ";
181186
os << (isOpInterface ? "getOperation()" : "*this");
@@ -284,7 +289,8 @@ void InterfaceGenerator::emitModelDecl(const Interface &interface) {
284289
void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
285290
for (auto &method : interface.getMethods()) {
286291
os << "template<typename " << valueTemplate << ">\n";
287-
emitCPPType(method.getReturnType(), os);
292+
auto returnType = method.getReturnType();
293+
emitCPPType(returnType, os);
288294
os << "detail::" << interface.getName() << "InterfaceTraits::Model<"
289295
<< valueTemplate << ">::";
290296
emitMethodNameAndArgs(method, os, valueType,
@@ -303,10 +309,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
303309
}
304310

305311
// Forward to the method on the concrete operation type.
306-
if (method.isStatic())
307-
os << "return " << valueTemplate << "::";
308-
else
309-
os << tblgen::tgfmt("return $_self.", &nonStaticMethodFmt);
312+
if (returnType != "void") {
313+
os << "return ";
314+
}
315+
316+
if (method.isStatic()) {
317+
os << valueTemplate << "::";
318+
} else {
319+
os << tblgen::tgfmt("$_self.", &nonStaticMethodFmt);
320+
}
310321

311322
// Add the arguments to the call.
312323
os << method.getName() << '(';
@@ -318,7 +329,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
318329

319330
for (auto &method : interface.getMethods()) {
320331
os << "template<typename " << valueTemplate << ">\n";
321-
emitCPPType(method.getReturnType(), os);
332+
auto returnType = method.getReturnType();
333+
emitCPPType(returnType, os);
322334
os << "detail::" << interface.getName() << "InterfaceTraits::FallbackModel<"
323335
<< valueTemplate << ">::";
324336
emitMethodNameAndArgs(method, os, valueType,
@@ -327,11 +339,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
327339
os << " {\n ";
328340

329341
// Forward to the method on the concrete Model implementation.
330-
if (method.isStatic())
331-
os << "return " << valueTemplate << "::";
332-
else
333-
os << "return static_cast<const " << valueTemplate << " *>(impl)->";
334-
342+
if (returnType != "void") {
343+
os << "return ";
344+
}
345+
346+
if (method.isStatic()) {
347+
os << valueTemplate << "::";
348+
} else {
349+
os << "static_cast<const " << valueTemplate << " *>(impl)->";
350+
}
335351
// Add the arguments to the call.
336352
os << method.getName() << '(';
337353
if (!method.isStatic())
@@ -369,7 +385,7 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
369385
if (!method.isStatic())
370386
os << " const";
371387

372-
os << " {\n";
388+
os << " {\n ";
373389

374390
// Use the empty context for static methods.
375391
tblgen::FmtContext ctx;
@@ -447,7 +463,7 @@ void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) {
447463
<< "struct " << interfaceTraitsName << " {\n";
448464
emitConceptDecl(interface);
449465
emitModelDecl(interface);
450-
os << "};";
466+
os << "};\n";
451467

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

0 commit comments

Comments
 (0)