diff --git a/mlir/lib/Transforms/BufferPlacement.cpp b/mlir/lib/Transforms/BufferPlacement.cpp --- a/mlir/lib/Transforms/BufferPlacement.cpp +++ b/mlir/lib/Transforms/BufferPlacement.cpp @@ -296,7 +296,9 @@ if (!dominators.dominates(definingBlock, blockArg.getOwner())) { toProcess.emplace_back(blockArg, blockArg.getParentBlock()); blockArgsToFree.insert(blockArg); - } else if (visitedBlockArgs.insert({blockArg, definingBlock}).second) + } else if (visitedBlockArgs + .insert(std::make_tuple(blockArg, definingBlock)) + .second) toProcess.emplace_back(blockArg, definingBlock); } }; @@ -328,13 +330,12 @@ // Get the terminator and the value that will be passed to our // argument. Operation *terminator = (*it)->getTerminator(); - auto successorOperand = - cast(terminator) - .getMutableSuccessorOperands(it.getSuccessorIndex()) - .getValue() - .slice(blockArg.getArgNumber(), 1); - Value sourceValue = ((OperandRange)successorOperand)[0]; - + auto branchInterface = cast(terminator); + // Convert the mutable operand range to an immutable range and query the + // associated source value. + Value sourceValue = + branchInterface.getSuccessorOperands(it.getSuccessorIndex()) + .getValue()[blockArg.getArgNumber()]; // Create a new alloc at the current location of the terminator. auto memRefType = sourceValue.getType().cast(); OpBuilder builder(terminator); @@ -354,7 +355,10 @@ auto alloc = builder.create(terminator->getLoc(), memRefType, dynamicOperands); // Wire new alloc and successor operand. - successorOperand.assign(alloc); + branchInterface.getMutableSuccessorOperands(it.getSuccessorIndex()) + .getValue() + .slice(blockArg.getArgNumber(), 1) + .assign(alloc); // Create a new copy operation that copies to contents of the old // allocation to the new one. builder.create(terminator->getLoc(), sourceValue, diff --git a/mlir/lib/Transforms/CMakeLists.txt b/mlir/lib/Transforms/CMakeLists.txt --- a/mlir/lib/Transforms/CMakeLists.txt +++ b/mlir/lib/Transforms/CMakeLists.txt @@ -30,6 +30,7 @@ LINK_LIBS PUBLIC MLIRAffineOps MLIRAnalysis + MLIRLinalgOps MLIRLoopLikeInterface MLIRSCF MLIRPass