From 8d161cba0bdf9272d6276ac1d4868151536e784c Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 27 Feb 2024 13:49:43 +0000 Subject: [PATCH] Fix remaining build failures with GCC 8.3 When compiling for GCC 8.x (< 8.4), SFINAE is disabled for iterator_range constructor causing ambiguous resolution to construct an OperandRange from a MutableOperatorRange, even in the presence of a static_cast. This adds an explicit conversion method to lift the ambiguity. Tested with a full MLIR build with GCC 8.3. --- mlir/include/mlir/IR/ValueRange.h | 3 +++ .../Transforms/OwnershipBasedBufferDeallocation.cpp | 4 ++-- .../Transforms/BufferDeallocationOpInterfaceImpl.cpp | 2 +- mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp | 2 +- mlir/lib/IR/OperationSupport.cpp | 7 ++++++- mlir/lib/Transforms/Utils/CFGToSCF.cpp | 3 +-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h index 51262e2d78716..4b421c08d8418 100644 --- a/mlir/include/mlir/IR/ValueRange.h +++ b/mlir/include/mlir/IR/ValueRange.h @@ -155,6 +155,9 @@ class MutableOperandRange { /// Returns if the current range is empty. bool empty() const { return size() == 0; } + /// Explicit conversion to an OperandRange. + OperandRange getAsOperandRange() const; + /// Allow implicit conversion to an OperandRange. operator OperandRange() const; diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp index 0a7494c86d86f..c9fd110d48d9a 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp @@ -956,13 +956,13 @@ BufferDeallocation::handleInterface(RegionBranchTerminatorOpInterface op) { SmallVector updatedOwnerships; auto result = deallocation_impl::insertDeallocOpForReturnLike( - state, op, OperandRange(operands), updatedOwnerships); + state, op, operands.getAsOperandRange(), updatedOwnerships); if (failed(result) || !*result) return result; // Add an additional operand for every MemRef for the ownership indicator. if (!funcWithoutDynamicOwnership) { - SmallVector newOperands{OperandRange(operands)}; + SmallVector newOperands{operands.getAsOperandRange()}; newOperands.append(updatedOwnerships.begin(), updatedOwnerships.end()); operands.assign(newOperands); } diff --git a/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp b/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp index 9423af2542690..0dc357c2298fa 100644 --- a/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp +++ b/mlir/lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp @@ -84,7 +84,7 @@ struct CondBranchOpInterface DenseMap &mapping) -> DeallocOp { SmallVector toRetain; state.getMemrefsToRetain(condBr->getBlock(), target, - OperandRange(destOperands), toRetain); + destOperands.getAsOperandRange(), toRetain); SmallVector adaptedConditions( llvm::map_range(conditions, conditionModifier)); auto deallocOp = builder.create( diff --git a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp index a85532b2f755a..223d728b0b27d 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp @@ -149,7 +149,7 @@ static LinalgOp fuse(OpBuilder &b, LinalgOp producer, SmallVector resultTypes; resultTypes.reserve(producer->getNumResults()); int64_t firstInitOperandIdx = - static_cast(producerDpsInits).getBeginOperandIndex(); + producerDpsInits.getAsOperandRange().getBeginOperandIndex(); for (int64_t i = 0, e = producer->getNumResults(); i < e; ++i) { resultTypes.push_back(clonedShapes[firstInitOperandIdx + i].getType()); } diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index a168fe30ba8a4..a72ccb9ca490c 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -497,9 +497,14 @@ void MutableOperandRange::clear() { } } +/// Explicit conversion to an OperandRange. +OperandRange MutableOperandRange::getAsOperandRange() const { + return owner->getOperands().slice(start, length); +} + /// Allow implicit conversion to an OperandRange. MutableOperandRange::operator OperandRange() const { - return owner->getOperands().slice(start, length); + return getAsOperandRange(); } MutableOperandRange::operator MutableArrayRef() const { diff --git a/mlir/lib/Transforms/Utils/CFGToSCF.cpp b/mlir/lib/Transforms/Utils/CFGToSCF.cpp index f2998b4047e20..eefdf1d4e393a 100644 --- a/mlir/lib/Transforms/Utils/CFGToSCF.cpp +++ b/mlir/lib/Transforms/Utils/CFGToSCF.cpp @@ -1183,8 +1183,7 @@ static FailureOr> transformToStructuredCFBranches( auto builder = OpBuilder::atBlockTerminator(user->getBlock()); LogicalResult result = interface.createStructuredBranchRegionTerminatorOp( user->getLoc(), builder, structuredCondOp, user, - static_cast( - getMutableSuccessorOperands(user->getBlock(), 0))); + getMutableSuccessorOperands(user->getBlock(), 0).getAsOperandRange()); if (failed(result)) return failure(); user->erase();