Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Interfaces/ControlFlowInterfaces.cpp
Show All 15 Lines | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "mlir/Interfaces/ControlFlowInterfaces.cpp.inc" | #include "mlir/Interfaces/ControlFlowInterfaces.cpp.inc" | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// BranchOpInterface | // BranchOpInterface | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
/// Erase an operand from a branch operation that is used as a successor | |||||
/// operand. 'operandIndex' is the operand within 'operands' to be erased. | |||||
void mlir::detail::eraseBranchSuccessorOperand(OperandRange operands, | |||||
unsigned operandIndex, | |||||
Operation *op) { | |||||
assert(operandIndex < operands.size() && | |||||
"invalid index for successor operands"); | |||||
// Erase the operand from the operation. | |||||
size_t fullOperandIndex = operands.getBeginOperandIndex() + operandIndex; | |||||
op->eraseOperand(fullOperandIndex); | |||||
// If this operation has an OperandSegmentSizeAttr, keep it up to date. | |||||
auto operandSegmentAttr = | |||||
op->getAttrOfType<DenseElementsAttr>("operand_segment_sizes"); | |||||
if (!operandSegmentAttr) | |||||
return; | |||||
// Find the segment containing the full operand index and decrement it. | |||||
// TODO: This seems like a general utility that could be added somewhere. | |||||
SmallVector<int32_t, 4> values(operandSegmentAttr.getValues<int32_t>()); | |||||
unsigned currentSize = 0; | |||||
for (unsigned i = 0, e = values.size(); i != e; ++i) { | |||||
currentSize += values[i]; | |||||
if (fullOperandIndex < currentSize) { | |||||
--values[i]; | |||||
break; | |||||
} | |||||
} | |||||
op->setAttr("operand_segment_sizes", | |||||
DenseIntElementsAttr::get(operandSegmentAttr.getType(), values)); | |||||
} | |||||
/// Returns the `BlockArgument` corresponding to operand `operandIndex` in some | /// Returns the `BlockArgument` corresponding to operand `operandIndex` in some | ||||
/// successor if 'operandIndex' is within the range of 'operands', or None if | /// successor if 'operandIndex' is within the range of 'operands', or None if | ||||
/// `operandIndex` isn't a successor operand index. | /// `operandIndex` isn't a successor operand index. | ||||
Optional<BlockArgument> mlir::detail::getBranchSuccessorArgument( | Optional<BlockArgument> mlir::detail::getBranchSuccessorArgument( | ||||
Optional<OperandRange> operands, unsigned operandIndex, Block *successor) { | Optional<OperandRange> operands, unsigned operandIndex, Block *successor) { | ||||
// Check that the operands are valid. | // Check that the operands are valid. | ||||
if (!operands || operands->empty()) | if (!operands || operands->empty()) | ||||
return llvm::None; | return llvm::None; | ||||
Show All 37 Lines |