[Mlir-commits] [mlir] a134ccb - [mlir][DeclarativeParser] Move operand type resolution into a functor to

River Riddle llvmlistbot at llvm.org
Thu Feb 13 00:04:10 PST 2020


Author: River Riddle
Date: 2020-02-12T23:56:07-08:00
New Revision: a134ccbbebe6e4e7cfd11a5583a7e1786a22505a

URL: https://github.com/llvm/llvm-project/commit/a134ccbbebe6e4e7cfd11a5583a7e1786a22505a
DIFF: https://github.com/llvm/llvm-project/commit/a134ccbbebe6e4e7cfd11a5583a7e1786a22505a.diff

LOG: [mlir][DeclarativeParser] Move operand type resolution into a functor to
share code.

This reduces the duplication for the two different cases.

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/OpFormatGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 22e834f4caa5..91918e099c81 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -498,22 +498,25 @@ void OperationFormat::genParserTypeResolution(Operator &op,
   if (hasAllOperands) {
     body << "  if (parser.resolveOperands(allOperands, ";
 
+    auto emitOperandType = [&](int idx) {
+      if (Optional<int> val = operandTypes[idx].getBuilderIdx())
+        body << "ArrayRef<Type>(odsBuildableType" << *val << ")";
+      else if (Optional<StringRef> var = operandTypes[idx].getVariable())
+        body << *var << "Types";
+      else
+        body << op.getOperand(idx).name << "Types";
+    };
+
     // Group all of the operand types together to perform the resolution all at
     // once. Use llvm::concat to perform the merge. llvm::concat does not allow
     // the case of a single range, so guard it here.
     if (op.getNumOperands() > 1) {
       body << "llvm::concat<const Type>(";
-      interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
-        if (Optional<int> val = operandTypes[i].getBuilderIdx())
-          body << "ArrayRef<Type>(odsBuildableType" << *val << ")";
-        else if (Optional<StringRef> var = operandTypes[i].getVariable())
-          body << *var << "Types";
-        else
-          body << op.getOperand(i).name << "Types";
-      });
+      interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body,
+                      emitOperandType);
       body << ")";
     } else {
-      body << op.operand_begin()->name << "Types";
+      emitOperandType(/*idx=*/0);
     }
 
     body << ", allOperandLoc, result.operands))\n"


        


More information about the Mlir-commits mailing list