9 #ifndef MLIR_DIALECT_BUFFERIZATION_IR_UNSTRUCTUREDCONTROLFLOW_H_
10 #define MLIR_DIALECT_BUFFERIZATION_IR_UNSTRUCTUREDCONTROLFLOW_H_
20 namespace bufferization {
31 template <
typename ConcreteModel,
typename ConcreteOp>
33 :
public BufferizableOpInterface::ExternalModel<ConcreteModel, ConcreteOp> {
35 FailureOr<BaseMemRefType>
41 if (isa<OpResult>(value))
50 auto tensorType = cast<TensorType>(value.
getType());
57 if (llvm::find(invocationStack, opOperand->get()) !=
58 invocationStack.end())
64 dyn_cast<BaseMemRefType>(opOperand->get().getType())) {
66 callerType = memrefType;
68 FailureOr<BaseMemRefType> maybeCallerType =
71 if (failed(maybeCallerType))
73 callerType = *maybeCallerType;
78 bufferType = callerType;
82 if (bufferType == callerType)
89 if (
auto rankedTensorType = dyn_cast<RankedTensorType>(tensorType)) {
91 "expected ranked memrefs");
93 rankedTensorType.getShape()}) &&
94 "expected same shape");
97 "expected unranked memrefs");
102 return op->
emitOpError(
"incoming operands of block argument have "
103 "inconsistent memory spaces");
110 return op->
emitOpError(
"could not infer buffer type of block argument");
137 template <
typename ConcreteModel,
typename ConcreteOp>
139 :
public BufferizableOpInterface::ExternalModel<ConcreteModel, ConcreteOp> {
143 auto branchOp = cast<BranchOpInterface>(op);
148 Block *block = it.value();
151 "produced operands not supported");
155 int64_t firstOperandIndex =
157 int64_t lastOperandIndex =
159 bool matchingDestination = operandNumber >= firstOperandIndex &&
160 operandNumber < lastOperandIndex;
163 if (!matchingDestination)
167 block->
getArgument(operandNumber - firstOperandIndex);
static llvm::ManagedStatic< PassManagerOptions > options
This class provides a shared interface for ranked and unranked memref types.
ArrayRef< int64_t > getShape() const
Returns the shape of this memref type.
Attribute getMemorySpace() const
Returns the memory space in which data referred to by this memref resides.
bool hasRank() const
Returns if this type is ranked, i.e. it has a known number of dimensions.
This class represents an argument of a Block.
Block * getOwner() const
Returns the block that owns this argument.
Block represents an ordered list of Operations.
BlockArgument getArgument(unsigned i)
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
This class represents an operand of an operation.
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
Operation is the basic unit of execution within MLIR.
SuccessorRange getSuccessors()
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class models how operands are forwarded to block arguments in control flow.
unsigned getProducedOperandCount() const
Returns the amount of operands that are produced internally by the operation.
OperandRange getForwardedOperands() const
Get the range of operands that are simply forwarded to the successor.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
AnalysisState provides a variety of helper functions for dealing with tensor values.
SmallVector< OpOperand * > getCallerOpOperands(BlockArgument bbArg)
Return a list of operands that are forwarded to the given block argument.
FailureOr< BaseMemRefType > defaultGetBufferType(Value value, const BufferizationOptions &options, SmallVector< Value > &invocationStack)
This is the default implementation of BufferizableOpInterface::getBufferType.
FailureOr< BaseMemRefType > getBufferType(Value value, const BufferizationOptions &options)
Return the buffer type for a given Value (tensor) after bufferization without bufferizing any IR.
BaseMemRefType getMemRefTypeWithFullyDynamicLayout(TensorType tensorType, Attribute memorySpace=nullptr)
Return a MemRef type with fully dynamic layout.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Include the generated interface declarations.
A template that provides a default implementation of getAliasingValues for ops that implement the Bra...
AliasingValueList getAliasingValues(Operation *op, OpOperand &opOperand, const AnalysisState &state) const
Options for BufferizableOpInterface-based bufferization.
A template that provides a default implementation of getAliasingOpOperands for ops that support unstr...
FailureOr< BaseMemRefType > getBufferType(Operation *op, Value value, const BufferizationOptions &options, SmallVector< Value > &invocationStack) const
AliasingOpOperandList getAliasingBranchOpOperands(Operation *op, BlockArgument bbArg, const AnalysisState &state) const
Assuming that bbArg is a block argument of a block that belongs to the given op, return all OpOperand...