[Mlir-commits] [mlir] a6ae695 - [MLIR][NFC] Adopt use of BlockRange in place of ArrayRef<Block *>

Rahul Joshi llvmlistbot at llvm.org
Wed Sep 23 09:22:21 PDT 2020


Author: Rahul Joshi
Date: 2020-09-23T09:21:54-07:00
New Revision: a6ae6950173a01c8a620a5664fcfb18816d152e7

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

LOG: [MLIR][NFC] Adopt use of BlockRange in place of ArrayRef<Block *>

- Use BlockRange in ODS generated builders as well as other places throughout the code

Differential Revision: https://reviews.llvm.org/D87955

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
    mlir/include/mlir/IR/OperationSupport.h
    mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
    mlir/lib/IR/OperationSupport.cpp
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
index 514ecf943d9c..86de4038b71b 100644
--- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
+++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
@@ -771,7 +771,7 @@ def PDLInterp_SwitchAttributeOp
 
   let builders = [
     OpBuilder<"Value attribute, ArrayRef<Attribute> caseValues,"
-              "Block *defaultDest, ArrayRef<Block *> dests", [{
+              "Block *defaultDest, BlockRange dests", [{
     build($_builder, $_state, attribute, $_builder.getArrayAttr(caseValues),
           defaultDest, dests);
   }]>];
@@ -804,7 +804,7 @@ def PDLInterp_SwitchOperandCountOp
 
   let builders = [
     OpBuilder<"Value operation, ArrayRef<int32_t> counts, "
-              "Block *defaultDest, ArrayRef<Block *> dests", [{
+              "Block *defaultDest, BlockRange dests", [{
     build($_builder, $_state, operation, $_builder.getI32VectorAttr(counts),
           defaultDest, dests);
   }]>];
@@ -838,7 +838,7 @@ def PDLInterp_SwitchOperationNameOp
 
   let builders = [
     OpBuilder<"Value operation, ArrayRef<OperationName> names, "
-              "Block *defaultDest, ArrayRef<Block *> dests", [{
+              "Block *defaultDest, BlockRange dests", [{
       auto stringNames = llvm::to_vector<8>(llvm::map_range(names,
           [](OperationName name) { return name.getStringRef(); }));
       build($_builder, $_state, operation, $_builder.getStrArrayAttr(stringNames),
@@ -874,7 +874,7 @@ def PDLInterp_SwitchResultCountOp
 
   let builders = [
     OpBuilder<"Value operation, ArrayRef<int32_t> counts, Block *defaultDest, "
-              "ArrayRef<Block *> dests", [{
+              "BlockRange dests", [{
     build($_builder, $_state, operation, $_builder.getI32VectorAttr(counts),
           defaultDest, dests);
   }]>];
@@ -906,7 +906,7 @@ def PDLInterp_SwitchTypeOp : PDLInterp_SwitchOp<"switch_type", [NoSideEffect]> {
 
   let builders = [
     OpBuilder<"Value edge, TypeRange types, Block *defaultDest, "
-              "ArrayRef<Block *> dests", [{
+              "BlockRange dests", [{
       build($_builder, $_state, edge, $_builder.getTypeArrayAttr(types),
             defaultDest, dests);
     }]>,

diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 11e85f20af44..e1e34f8da6c6 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -15,6 +15,7 @@
 #define MLIR_IR_OPERATION_SUPPORT_H
 
 #include "mlir/IR/Attributes.h"
+#include "mlir/IR/BlockSupport.h"
 #include "mlir/IR/Identifier.h"
 #include "mlir/IR/Location.h"
 #include "mlir/IR/TypeRange.h"
@@ -28,8 +29,6 @@
 #include <memory>
 
 namespace mlir {
-class Block;
-class BlockRange;
 class Dialect;
 class Operation;
 struct OperationState;
@@ -364,8 +363,8 @@ struct OperationState {
   OperationState(Location location, OperationName name);
 
   OperationState(Location location, StringRef name, ValueRange operands,
-                 ArrayRef<Type> types, ArrayRef<NamedAttribute> attributes,
-                 ArrayRef<Block *> successors = {},
+                 TypeRange types, ArrayRef<NamedAttribute> attributes,
+                 BlockRange successors = {},
                  MutableArrayRef<std::unique_ptr<Region>> regions = {});
 
   void addOperands(ValueRange newOperands);

diff  --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
index 223adf47ab2e..887def35f791 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
@@ -60,9 +60,10 @@ static LogicalResult encodeInstructionInto(SmallVectorImpl<uint32_t> &binary,
 /// readable to human, we perform depth-first CFG traversal and delay the
 /// serialization of the merge block and the continue block, if exists, until
 /// after all other blocks have been processed.
-static LogicalResult visitInPrettyBlockOrder(
-    Block *headerBlock, function_ref<LogicalResult(Block *)> blockHandler,
-    bool skipHeader = false, ArrayRef<Block *> skipBlocks = {}) {
+static LogicalResult
+visitInPrettyBlockOrder(Block *headerBlock,
+                        function_ref<LogicalResult(Block *)> blockHandler,
+                        bool skipHeader = false, BlockRange skipBlocks = {}) {
   llvm::df_iterator_default_set<Block *, 4> doneBlocks;
   doneBlocks.insert(skipBlocks.begin(), skipBlocks.end());
 

diff  --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index 69aea3bfcf19..1ba50f6839d5 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -169,9 +169,9 @@ OperationState::OperationState(Location location, OperationName name)
     : location(location), name(name) {}
 
 OperationState::OperationState(Location location, StringRef name,
-                               ValueRange operands, ArrayRef<Type> types,
+                               ValueRange operands, TypeRange types,
                                ArrayRef<NamedAttribute> attributes,
-                               ArrayRef<Block *> successors,
+                               BlockRange successors,
                                MutableArrayRef<std::unique_ptr<Region>> regions)
     : location(location), name(name, location->getContext()),
       operands(operands.begin(), operands.end()),

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 18b5d26d880c..2b05e25be267 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -1420,8 +1420,8 @@ void OpEmitter::buildParamList(SmallVectorImpl<OpMethodParameter> &paramList,
 
   /// Insert parameters for each successor.
   for (const NamedSuccessor &succ : op.getSuccessors()) {
-    StringRef type = succ.isVariadic() ? "::llvm::ArrayRef<::mlir::Block *>"
-                                       : "::mlir::Block *";
+    StringRef type =
+        succ.isVariadic() ? "::mlir::BlockRange" : "::mlir::Block *";
     paramList.emplace_back(type, succ.name);
   }
 
@@ -1888,12 +1888,14 @@ void OpEmitter::genSuccessorVerifier(OpMethodBody &body) {
     if (successor.constraint.getPredicate().isNull())
       continue;
 
-    body << "    for (::mlir::Block *successor : ";
-    body << formatv(successor.isVariadic()
-                        ? "{0}()"
-                        : "::llvm::ArrayRef<::mlir::Block *>({0}())",
-                    successor.name);
-    body << ") {\n";
+    if (successor.isVariadic()) {
+      body << formatv("    for (::mlir::Block *successor : {0}()) {\n",
+                      successor.name);
+    } else {
+      body << "    {\n";
+      body << formatv("      ::mlir::Block *successor = {0}();\n",
+                      successor.name);
+    }
     auto constraint = tgfmt(successor.constraint.getConditionTemplate(),
                             &verifyCtx.withSelf("successor"))
                           .str();


        


More information about the Mlir-commits mailing list