Skip to content

Commit aaf5c6a

Browse files
OrestChurahrotuna
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 f7ca856 commit aaf5c6a

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
@@ -751,7 +751,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
751751
}
752752
} else {
753753
body << " ::mlir::OpAsmParser::OperandType " << name
754-
<< "RawOperands[1];\n"
754+
<< "RawOperands[1] = { };\n"
755755
<< " ::llvm::ArrayRef<::mlir::OpAsmParser::OperandType> " << name
756756
<< "Operands(" << name << "RawOperands);";
757757
}
@@ -788,7 +788,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op,
788788
if (lengthKind != ArgumentLengthKind::Single)
789789
body << " ::mlir::SmallVector<::mlir::Type, 1> " << name << "Types;\n";
790790
else
791-
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name)
791+
body << llvm::formatv(" ::mlir::Type {0}RawTypes[1] = {{ };\n", name)
792792
<< llvm::formatv(
793793
" ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n",
794794
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");
@@ -283,7 +288,8 @@ void InterfaceGenerator::emitModelDecl(const Interface &interface) {
283288
void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
284289
for (auto &method : interface.getMethods()) {
285290
os << "template<typename " << valueTemplate << ">\n";
286-
emitCPPType(method.getReturnType(), os);
291+
auto returnType = method.getReturnType();
292+
emitCPPType(returnType, os);
287293
os << "detail::" << interface.getName() << "InterfaceTraits::Model<"
288294
<< valueTemplate << ">::";
289295
emitMethodNameAndArgs(method, os, valueType,
@@ -302,10 +308,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
302308
}
303309

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

310321
// Add the arguments to the call.
311322
os << method.getName() << '(';
@@ -317,7 +328,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
317328

318329
for (auto &method : interface.getMethods()) {
319330
os << "template<typename " << valueTemplate << ">\n";
320-
emitCPPType(method.getReturnType(), os);
331+
auto returnType = method.getReturnType();
332+
emitCPPType(returnType, os);
321333
os << "detail::" << interface.getName() << "InterfaceTraits::FallbackModel<"
322334
<< valueTemplate << ">::";
323335
emitMethodNameAndArgs(method, os, valueType,
@@ -326,11 +338,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
326338
os << " {\n ";
327339

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

371-
os << " {\n";
387+
os << " {\n ";
372388

373389
// Use the empty context for static methods.
374390
tblgen::FmtContext ctx;
@@ -443,7 +459,7 @@ void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) {
443459
<< "struct " << interfaceTraitsName << " {\n";
444460
emitConceptDecl(interface);
445461
emitModelDecl(interface);
446-
os << "};";
462+
os << "};\n";
447463

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

0 commit comments

Comments
 (0)