Skip to content

Commit

Permalink
[MLIR][NFC] Adopt use of BlockRange in place of ArrayRef<Block *>
Browse files Browse the repository at this point in the history
- Use BlockRange in ODS generated builders as well as other places throughout the code

Differential Revision: https://reviews.llvm.org/D87955
  • Loading branch information
jurahul committed Sep 23, 2020
1 parent f6aceb7 commit a6ae695
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
10 changes: 5 additions & 5 deletions mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
Expand Up @@ -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);
}]>];
Expand Down Expand Up @@ -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);
}]>];
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}]>];
Expand Down Expand Up @@ -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);
}]>,
Expand Down
7 changes: 3 additions & 4 deletions mlir/include/mlir/IR/OperationSupport.h
Expand Up @@ -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"
Expand All @@ -28,8 +29,6 @@
#include <memory>

namespace mlir {
class Block;
class BlockRange;
class Dialect;
class Operation;
struct OperationState;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/IR/OperationSupport.cpp
Expand Up @@ -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()),
Expand Down
18 changes: 10 additions & 8 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a6ae695

Please sign in to comment.