20#include "llvm/ADT/ScopeExit.h"
21#include "llvm/ADT/SmallVectorExtras.h"
30#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.cpp.inc"
37#define DEBUG_TYPE "bufferizable-op-interface"
45 if (
auto bufferizableOp =
options.dynCastBufferizableOp(op))
51Region *AnalysisState::getEnclosingRepetitiveRegion(
55 if (
auto iter = enclosingRepetitiveRegionCache.find_as(op);
56 iter != enclosingRepetitiveRegionCache.end())
58 return enclosingRepetitiveRegionCache[op] =
62Region *AnalysisState::getEnclosingRepetitiveRegion(
64 if (
auto iter = enclosingRepetitiveRegionCache.find_as(value);
65 iter != enclosingRepetitiveRegionCache.end())
71 SmallVector<Region *> visitedRegions;
73 visitedRegions.push_back(region);
78 enclosingRepetitiveRegionCache[value] = region;
79 for (Region *r : visitedRegions)
80 enclosingRepetitiveRegionCache[r] = region;
84Region *AnalysisState::getEnclosingRepetitiveRegion(
86 if (
auto iter = enclosingRepetitiveRegionCache.find_as(block);
87 iter != enclosingRepetitiveRegionCache.end())
91 Operation *op =
nullptr;
94 SmallVector<Region *> visitedRegions;
101 enclosingRepetitiveRegionCache[block] = region;
102 for (Region *r : visitedRegions)
103 enclosingRepetitiveRegionCache[r] = region;
107bool AnalysisState::insideMutuallyExclusiveRegions(
Operation *op0,
109 auto key = std::make_pair(op0, op1);
110 if (
auto iter = insideMutuallyExclusiveRegionsCache.find(key);
111 iter != insideMutuallyExclusiveRegionsCache.end())
115 insideMutuallyExclusiveRegionsCache[key] =
result;
116 insideMutuallyExclusiveRegionsCache[std::make_pair(op1, op0)] =
result;
120void AnalysisState::resetCache() {
121 enclosingRepetitiveRegionCache.clear();
122 insideMutuallyExclusiveRegionsCache.clear();
133Region *bufferization::getNextEnclosingRepetitiveRegion(
144 const BufferizationOptions &
options) {
147 if (bufferizableOp &&
150 "expected that all parallel regions are also repetitive regions");
159 if (
auto opResult = llvm::dyn_cast<OpResult>(value))
160 return opResult.getDefiningOp();
161 return llvm::cast<BlockArgument>(value).getOwner()->
getParentOp();
167FailureOr<Value> bufferization::allocateTensorForShapedValue(
169 const BufferizationOptions &
options,
const BufferizationState &state,
172 if (llvm::isa<MemRefType>(shapedValue.
getType())) {
173 tensor = ToTensorOp::create(
176 }
else if (llvm::isa<UnrankedTensorType>(shapedValue.
getType()) ||
177 llvm::isa<UnrankedMemRefType>(shapedValue.
getType())) {
179 ->
emitError(
"copying of unranked tensors is not implemented");
181 auto tensorType = llvm::cast<TensorLikeType>(
tensor.getType());
185 auto rankedTensorType = dyn_cast<RankedTensorType>(tensorType);
186 if (!
copy && rankedTensorType) {
189 bool reifiedShapes =
false;
190 if (llvm::isa<RankedTensorType>(shapedValue.
getType()) &&
191 llvm::isa<OpResult>(shapedValue)) {
195 reifiedShapes =
true;
197 resultDims[llvm::cast<OpResult>(shapedValue).getResultNumber()];
198 for (
const auto &dim :
enumerate(rankedTensorType.getShape())) {
199 if (ShapedType::isDynamic(dim.value())) {
200 dynamicSizes.push_back(
213 auto allocTensorOp = AllocTensorOp::create(
b, loc, tensorType, dynamicSizes,
218 return allocTensorOp.getResult();
220 if (
failed(copyBufferType))
223 std::optional<Attribute> memorySpace;
224 if (
auto copyMemRefType = dyn_cast<BaseMemRefType>(*copyBufferType))
225 memorySpace = copyMemRefType.getMemorySpace();
228 options.defaultMemorySpaceFn(cast<TensorLikeType>(tensorType));
229 if (memorySpace.has_value())
230 allocTensorOp.setMemorySpaceAttr(memorySpace.value());
231 return allocTensorOp.getResult();
234LogicalResult BufferizableOpInterface::resolveTensorOpOperandConflicts(
236 const BufferizationState &bufferizationState) {
246 Type operandType = opOperand.get().getType();
247 if (!llvm::isa<TensorLikeType>(operandType))
249 if (analysisState.isInPlace(opOperand))
251 if (llvm::isa<UnrankedTensorType>(operandType))
252 return op->
emitError(
"copying of unranked tensors is not implemented");
254 AliasingValueList aliasingValues =
255 analysisState.getAliasingValues(opOperand);
256 if (aliasingValues.getNumAliases() == 1 &&
257 isa<OpResult>(aliasingValues.getAliases()[0].value) &&
258 !analysisState.bufferizesToMemoryWrite(opOperand) &&
260 .getAliasingOpOperands(aliasingValues.getAliases()[0].value)
261 .getNumAliases() == 1 &&
262 !isa<UnrankedTensorType>(
263 aliasingValues.getAliases()[0].value.getType())) {
270 Value value = aliasingValues.getAliases()[0].value;
271 outOfPlaceValues.push_back(value);
272 if (!analysisState.canOmitTensorCopy(opOperand))
273 copiedOpValues.insert(value);
276 outOfPlaceOpOperands.push_back(&opOperand);
277 if (!analysisState.canOmitTensorCopy(opOperand))
278 copiedOpOperands.insert(&opOperand);
284 for (
OpOperand *opOperand : outOfPlaceOpOperands) {
285 FailureOr<Value>
copy = allocateTensorForShapedValue(
286 rewriter, op->
getLoc(), opOperand->get(), analysisState.getOptions(),
287 bufferizationState, copiedOpOperands.contains(opOperand));
295 for (
Value value : outOfPlaceValues) {
296 FailureOr<Value>
copy = allocateTensorForShapedValue(
297 rewriter, op->
getLoc(), value, analysisState.getOptions(),
298 bufferizationState, copiedOpValues.count(value));
305 if (use->getOwner() ==
copy->getDefiningOp())
309 if (isa<tensor::DimOp>(use->getOwner()))
322bool OpFilter::isOpAllowed(
Operation *op)
const {
324 bool isAllowed = !hasAllowRule();
325 for (
const Entry &entry : entries) {
326 bool filterResult = entry.fn(op);
327 switch (entry.type) {
329 isAllowed |= filterResult;
349 mlir::Type elementType,
351 int64_t dynamicOffset = ShapedType::kDynamic;
353 auto stridedLayout = StridedLayoutAttr::get(elementType.
getContext(),
354 dynamicOffset, dynamicStrides);
355 return MemRefType::get(
shape, elementType, stridedLayout, memorySpace);
361 unsigned int bufferAlignment) {
363 if (bufferAlignment != 0)
364 return memref::AllocOp::create(
b, loc, type, dynShape,
365 b.getI64IntegerAttr(bufferAlignment))
367 return memref::AllocOp::create(
b, loc, type, dynShape).getResult();
373 memref::CopyOp::create(
b, loc, from, to);
381 if (!isa<BaseMemRefType>(dest) || !isa<BaseMemRefType>(value.
getType()) ||
382 !memref::CastOp::areCastCompatible(value.
getType(), dest))
384 return memref::CastOp::create(
b, loc, dest, value).getResult();
389defaultFunctionArgTypeConverter(TensorLikeType type,
Attribute memorySpace,
391 const BufferizationOptions &
options) {
392 if (
auto tensorType = mlir::dyn_cast<TensorType>(type)) {
393 return cast<BufferLikeType>(
394 bufferization::getMemRefTypeWithFullyDynamicLayout(tensorType,
399 return options.unknownTypeConverterFn(type, memorySpace,
options);
403defaultUnknownTypeConverter(TensorLikeType tensorType,
Attribute memorySpace,
404 const BufferizationOptions &
options) {
405 return cast<BufferLikeType>(
406 bufferization::getMemRefTypeWithFullyDynamicLayout(
407 cast<TensorType>(tensorType), memorySpace));
412FailureOr<BufferLikeType>
413defaultReconcileBufferTypeMismatch(BufferLikeType x, BufferLikeType y,
414 const BufferizationOptions &) {
415 const auto xMemRef = cast<BaseMemRefType>(x);
416 const auto yMemRef = cast<BaseMemRefType>(y);
418 if (xMemRef.getMemorySpace() != yMemRef.getMemorySpace())
421 if (isa<UnrankedMemRefType>(xMemRef)) {
426 return cast<BufferLikeType>(::getMemRefTypeWithFullyDynamicLayout(
427 xMemRef.getShape(), xMemRef.getElementType(), xMemRef.getMemorySpace()));
433BufferizationOptions::BufferizationOptions()
434 : allocationFn(defaultCreateAlloc), memCpyFn(defaultCreateMemCpy),
435 castFn(defaultCreateCast),
436 functionArgTypeConverterFn(defaultFunctionArgTypeConverter),
437 unknownTypeConverterFn(defaultUnknownTypeConverter),
438 reconcileBufferTypeMismatchFn(defaultReconcileBufferTypeMismatch) {}
440bool BufferizationOptions::isOpAllowed(
Operation *op)
const {
443 bool isFuncBoundaryOp = isa_and_nonnull<func::FuncDialect>(op->
getDialect());
444 if (!bufferizeFunctionBoundaries && isFuncBoundaryOp)
447 return opFilter.isOpAllowed(op);
450BufferizableOpInterface
451BufferizationOptions::dynCastBufferizableOp(
Operation *op)
const {
452 if (!isOpAllowed(op))
454 auto bufferizableOp = dyn_cast<BufferizableOpInterface>(op);
457 return bufferizableOp;
460BufferizableOpInterface
461BufferizationOptions::dynCastBufferizableOp(
Value value)
const {
465void BufferizationOptions::setFunctionBoundaryTypeConversion(
466 LayoutMapOption layoutMapOption) {
467 functionArgTypeConverterFn = [=](TensorLikeType type, Attribute memorySpace,
469 const BufferizationOptions &
options) {
470 if (
auto tensorType = mlir::dyn_cast<TensorType>(type)) {
471 if (layoutMapOption == LayoutMapOption::IdentityLayoutMap)
472 return cast<BufferLikeType>(
473 bufferization::getMemRefTypeWithStaticIdentityLayout(tensorType,
475 return cast<BufferLikeType>(
476 bufferization::getMemRefTypeWithFullyDynamicLayout(tensorType,
481 return options.unknownTypeConverterFn(type, memorySpace,
options);
483 inferFunctionResultLayout =
484 layoutMapOption == LayoutMapOption::InferLayoutMap;
492 if (
auto bbArg = llvm::dyn_cast<BlockArgument>(value)) {
493 b.setInsertionPointToStart(bbArg.getOwner());
501AliasingOpOperandList AnalysisState::getAliasingOpOperands(
Value value)
const {
503 if (
auto bufferizableOp = getOptions().dynCastBufferizableOp(op))
504 return bufferizableOp.getAliasingOpOperands(value, *
this);
507 return detail::unknownGetAliasingOpOperands(value);
512AliasingValueList AnalysisState::getAliasingValues(
OpOperand &opOperand)
const {
513 if (
auto bufferizableOp =
514 getOptions().dynCastBufferizableOp(opOperand.
getOwner()))
515 return bufferizableOp.getAliasingValues(opOperand, *
this);
518 return detail::unknownGetAliasingValues(opOperand);
523bool AnalysisState::bufferizesToMemoryRead(
OpOperand &opOperand)
const {
524 if (
auto bufferizableOp =
525 getOptions().dynCastBufferizableOp(opOperand.
getOwner()))
526 return bufferizableOp.bufferizesToMemoryRead(opOperand, *
this);
535bool AnalysisState::bufferizesToMemoryWrite(
OpOperand &opOperand)
const {
536 if (
auto bufferizableOp =
537 getOptions().dynCastBufferizableOp(opOperand.
getOwner()))
538 return bufferizableOp.bufferizesToMemoryWrite(opOperand, *
this);
547bool AnalysisState::bufferizesToAliasOnly(
OpOperand &opOperand)
const {
548 if (
auto bufferizableOp =
549 getOptions().dynCastBufferizableOp(opOperand.
getOwner()))
550 return bufferizableOp.bufferizesToAliasOnly(opOperand, *
this);
557bool AnalysisState::bufferizesToMemoryWrite(
Value value)
const {
558 auto opResult = llvm::dyn_cast<OpResult>(value);
561 auto bufferizableOp = getOptions().dynCastBufferizableOp(value);
564 return bufferizableOp.resultBufferizesToMemoryWrite(opResult, *
this);
570bool AnalysisState::isValueRead(
Value value)
const {
571 assert(llvm::isa<TensorLikeType>(value.
getType()) &&
572 "expected TensorLikeType");
573 SmallVector<OpOperand *> workingSet;
575 for (OpOperand &use : value.
getUses())
576 workingSet.push_back(&use);
578 while (!workingSet.empty()) {
579 OpOperand *uMaybeReading = workingSet.pop_back_val();
580 if (!visited.insert(uMaybeReading).second)
584 if (bufferizesToAliasOnly(*uMaybeReading))
585 for (AliasingValue alias : getAliasingValues(*uMaybeReading))
586 for (OpOperand &use : alias.value.getUses())
587 workingSet.push_back(&use);
588 if (bufferizesToMemoryRead(*uMaybeReading))
600llvm::SetVector<Value> AnalysisState::findValueInReverseUseDefChain(
602 TraversalConfig config,
603 llvm::DenseSet<OpOperand *> *visitedOpOperands)
const {
604 llvm::DenseSet<Value> visited;
605 llvm::SetVector<Value>
result, workingSet;
606 workingSet.insert(opOperand->
get());
608 if (visitedOpOperands)
609 visitedOpOperands->insert(opOperand);
611 while (!workingSet.empty()) {
612 Value value = workingSet.pop_back_val();
614 if (!config.revisitAlreadyVisitedValues && visited.contains(value)) {
616 if (config.alwaysIncludeLeaves)
620 visited.insert(value);
622 if (condition(value)) {
627 if (!config.followUnknownOps && !
options.dynCastBufferizableOp(value)) {
630 if (config.alwaysIncludeLeaves)
635 AliasingOpOperandList aliases = getAliasingOpOperands(value);
636 if (aliases.getNumAliases() == 0) {
639 if (config.alwaysIncludeLeaves)
644 for (AliasingOpOperand a : aliases) {
645 if (config.followEquivalentOnly &&
646 a.relation != BufferRelation::Equivalent) {
649 if (config.alwaysIncludeLeaves)
654 if (config.followInPlaceOnly && !isInPlace(*a.opOperand)) {
657 if (config.alwaysIncludeLeaves)
662 if (config.followSameTypeOrCastsOnly &&
663 a.opOperand->get().getType() != value.
getType() &&
667 if (config.alwaysIncludeLeaves)
672 workingSet.insert(a.opOperand->get());
673 if (visitedOpOperands)
674 visitedOpOperands->insert(a.opOperand);
682llvm::SetVector<Value>
683AnalysisState::findDefinitions(
OpOperand *opOperand)
const {
684 TraversalConfig config;
685 config.alwaysIncludeLeaves =
false;
686 return findValueInReverseUseDefChain(
687 opOperand, [&](Value v) {
return this->bufferizesToMemoryWrite(v); },
696 for (
const BufferizationOptions::AnalysisStateInitFn &fn :
701bool AnalysisState::canOmitTensorCopy(
OpOperand &opOperand)
const {
703 if (hasUndefinedContents(&opOperand))
708 if (bufferizesToMemoryWrite(opOperand) && !bufferizesToMemoryRead(opOperand))
712 AliasingValueList aliases = getAliasingValues(opOperand);
713 if (!bufferizesToMemoryRead(opOperand) &&
714 llvm::none_of(aliases,
715 [&](AliasingValue a) {
return isValueRead(a.value); }))
722bool AnalysisState::isInPlace(
OpOperand &opOperand)
const {
724 if (isa<ToBufferOp>(opOperand.
getOwner()))
729 return !bufferizesToMemoryWrite(opOperand);
732bool AnalysisState::areEquivalentBufferizedValues(
Value v1,
Value v2)
const {
738bool AnalysisState::areAliasingBufferizedValues(
Value v1,
Value v2)
const {
744bool AnalysisState::hasUndefinedContents(
OpOperand *opOperand)
const {
750 const BufferizationOptions &
options,
751 const BufferizationState &state) {
753 auto tensorType = llvm::dyn_cast<TensorLikeType>(value.
getType());
754 assert(tensorType &&
"unexpected non-tensor type");
758 if (
auto toTensorOp = value.
getDefiningOp<bufferization::ToTensorOp>())
759 return toTensorOp.getBuffer();
768 return bufferization::ToBufferOp::create(rewriter, value.
getLoc(),
775 const BufferizationOptions &
options) {
778 FailureOr<Value> casted =
options.castFn(
b, loc, type, buffer);
780 return emitError(loc) <<
"cannot cast a buffer of type " << buffer.
getType()
786FailureOr<BufferLikeType>
787bufferization::getBufferType(
Value value,
const BufferizationOptions &
options,
788 const BufferizationState &state) {
794FailureOr<BufferLikeType>
795bufferization::getBufferType(
Value value,
const BufferizationOptions &
options,
796 const BufferizationState &state,
798 assert(llvm::isa<TensorLikeType>(value.
getType()) &&
799 "unexpected non-tensor type");
800 invocationStack.push_back(value);
801 llvm::scope_exit popFromStack([&]() { invocationStack.pop_back(); });
805 auto bufferizableOp =
options.dynCastBufferizableOp(op);
807 return bufferizableOp.getBufferType(value,
options, state, invocationStack);
811 options.defaultMemorySpaceFn(cast<TensorLikeType>(value.
getType()));
812 if (!memSpace.has_value())
813 return op->emitError(
"could not infer memory space");
815 return options.unknownTypeConverterFn(cast<TensorLikeType>(value.
getType()),
819bool bufferization::hasTensorSemantics(
Operation *op) {
820 if (
auto bufferizableOp = dyn_cast<BufferizableOpInterface>(op))
821 return bufferizableOp.hasTensorSemantics();
822 return detail::defaultHasTensorSemantics(op);
825void bufferization::replaceOpWithBufferizedValues(
RewriterBase &rewriter,
829 "expected one value per OpResult");
836 if (llvm::isa<TensorLikeType>(opResult.getType())) {
839 assert(llvm::isa<BufferLikeType>(
replacement.getType()) &&
840 "tensor op result should be replaced with a buffer value");
859bufferization::getMemRefTypeWithFullyDynamicLayout(
TensorType tensorType,
862 if (
auto unrankedTensorType =
863 llvm::dyn_cast<UnrankedTensorType>(tensorType)) {
864 return UnrankedMemRefType::get(unrankedTensorType.getElementType(),
869 return ::getMemRefTypeWithFullyDynamicLayout(
876bufferization::getMemRefTypeWithStaticIdentityLayout(
TensorType tensorType,
879 if (
auto unrankedTensorType =
880 llvm::dyn_cast<UnrankedTensorType>(tensorType)) {
881 return UnrankedMemRefType::get(unrankedTensorType.getElementType(),
886 auto rankedTensorType = llvm::cast<RankedTensorType>(tensorType);
887 MemRefLayoutAttrInterface layout = {};
888 return MemRefType::get(rankedTensorType.getShape(),
889 rankedTensorType.getElementType(), layout,
897bool bufferization::detail::defaultResultBufferizesToMemoryWrite(
899 auto bufferizableOp = cast<BufferizableOpInterface>(opResult.
getDefiningOp());
900 AliasingOpOperandList opOperands =
901 bufferizableOp.getAliasingOpOperands(opResult, state);
905 if (opOperands.getAliases().empty())
910 if (llvm::any_of(opOperands, [&](AliasingOpOperand alias) {
911 return state.bufferizesToMemoryWrite(*alias.opOperand);
944 auto isMemoryWriteInsideOp = [&](
Value v) {
948 return state.bufferizesToMemoryWrite(v);
950 TraversalConfig config;
951 config.alwaysIncludeLeaves =
false;
952 for (AliasingOpOperand alias : opOperands) {
954 .findValueInReverseUseDefChain(alias.opOperand,
955 isMemoryWriteInsideOp, config)
964AliasingOpOperandList bufferization::detail::defaultGetAliasingOpOperands(
969 if (!llvm::isa<TensorLikeType>(opOperand.
get().
getType()))
971 AliasingValueList aliasingValues = state.getAliasingValues(opOperand);
972 for (
const auto &it : aliasingValues)
973 if (it.value == value)
974 result.emplace_back(&opOperand, it.relation, it.isDefinite);
976 return AliasingOpOperandList(std::move(
result));
979FailureOr<BufferLikeType> bufferization::detail::defaultGetBufferType(
981 const BufferizationState &bufferizationState,
983 assert(llvm::isa<TensorType>(value.
getType()) &&
"expected tensor type");
984 auto tensorType = cast<TensorType>(value.
getType());
990 <<
"cannot bufferize value of type " << tensorType
991 <<
": element type " << elementType
992 <<
" is not a valid memref element type";
995 if (llvm::isa<BlockArgument>(value)) {
996 return options.unknownTypeConverterFn(cast<TensorLikeType>(tensorType),
1002 auto opResult = llvm::cast<OpResult>(value);
1004 AliasingOpOperandList aliases = analysisState.getAliasingOpOperands(opResult);
1005 if (aliases.getNumAliases() > 0 &&
1006 aliases.getAliases()[0].relation == BufferRelation::Equivalent) {
1009 Value equivalentOperand = aliases.getAliases().front().opOperand->get();
1017 options.defaultMemorySpaceFn(cast<TensorLikeType>(tensorType));
1018 if (!memSpace.has_value())
1019 return op->
emitError(
"could not infer memory space");
1021 return options.unknownTypeConverterFn(cast<TensorLikeType>(tensorType),
1025bool bufferization::detail::defaultIsRepetitiveRegion(
1026 BufferizableOpInterface bufferizableOp,
unsigned index) {
1027 assert(index < bufferizableOp->getNumRegions() &&
"invalid region index");
1028 auto regionInterface =
1029 dyn_cast<RegionBranchOpInterface>(bufferizableOp.getOperation());
1030 if (!regionInterface)
1032 return regionInterface.isRepetitiveRegion(
index);
1035AliasingOpOperandList
1036bufferization::detail::unknownGetAliasingOpOperands(
Value value) {
1039 if (
auto bbArg = dyn_cast<BlockArgument>(value))
1040 if (bbArg.getOwner() != &bbArg.getOwner()->getParent()->getBlocks().front())
1046 AliasingOpOperandList r;
1048 if (isa<TensorLikeType>(operand.get().getType()))
1049 r.addAlias({&operand, BufferRelation::Unknown,
false});
1054bufferization::detail::unknownGetAliasingValues(
OpOperand &opOperand) {
1059 AliasingValueList r;
1061 if (llvm::isa<TensorLikeType>(
result.getType()))
1062 r.addAlias({
result, BufferRelation::Unknown,
false});
1066 if (isa<TensorLikeType>(bbArg.getType()))
1067 r.addAlias({bbArg, BufferRelation::Unknown,
false});
1071bool bufferization::detail::defaultHasTensorSemantics(
Operation *op) {
1072 auto isaTensor = [](
Type t) {
return isa<TensorLikeType>(t); };
1074 return any_of(r.getBlocks(), [&](Block &b) {
1075 return any_of(b.getArguments(), [&](BlockArgument bbArg) {
1076 return isaTensor(bbArg.getType());
1080 if (hasTensorBlockArgument)
1088FailureOr<BaseMemRefType>
1089bufferization::detail::asMemRefType(FailureOr<BufferLikeType> bufferType) {
1092 return cast<BaseMemRefType>(*bufferType);
1095bool bufferization::detail::typesMatchAfterBufferization(
Operation &op,
1098 return mlir::succeeded(
1099 cast<TensorLikeType>(
tensor.getType())
1100 .verifyCompatibleBufferType(cast<BufferLikeType>(buffer.
getType()),
1101 [&]() { return op.emitError(); }));
static void setInsertionPointAfter(OpBuilder &b, Value value)
static bool isRepetitiveRegion(Region *region, const BufferizationOptions &options)
static void copy(Location loc, Value dst, Value src, Value size, OpBuilder &builder)
Copies the given number of bytes from src to dst pointers.
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
static bool isaTensor(Type t)
static llvm::ManagedStatic< PassManagerOptions > options
static RankedTensorType getBufferType(const SparseTensorType &stt, bool needTmpCOO)
#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME)
static Operation * getOwnerOfValue(Value value)
Base class for generic analysis states.
AnalysisState(LatticeAnchor anchor)
Create the analysis state on the given lattice anchor.
Attributes are known-constant values of operations.
This class provides a shared interface for ranked and unranked memref types.
static bool isValidElementType(Type type)
Return true if the specified element type is ok in a memref.
This class represents an argument of a Block.
Block represents an ordered list of Operations.
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
IRValueT get() const
Return the current value being used by this operand.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
This class represents an operand of an operation.
This is a value defined by a result of an operation.
Operation is the basic unit of execution within MLIR.
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
Block * getBlock()
Returns the operation block that contains this operation.
Location getLoc()
The source location the operation was defined or derived from.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MutableArrayRef< OpOperand > getOpOperands()
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
operand_type_range getOperandTypes()
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
result_type_range getResultTypes()
bool isAncestor(Operation *other)
Return true if this operation is an ancestor of the other operation.
result_range getOpResults()
Region * getParentRegion()
Returns the region to which the instruction belongs.
unsigned getNumResults()
Return the number of results held by this operation.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Region * getParentRegion()
Return the region containing this region or nullptr if the region is attached to a top-level operatio...
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
This class represents a collection of SymbolTables.
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
ArrayRef< int64_t > getShape() const
Returns the shape of this tensor type.
Type getElementType() const
Returns the element type of this tensor type.
This class provides an efficient unique identifier for a specific C++ type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
This class provides an abstraction over the different types of ranges over Values.
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.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Location getLoc() const
Return the location of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Region * getParentRegion()
Return the Region in which this Value is defined.
Operation * getOwner() const
Return the owner of this operand.
void populateDynamicDimSizes(OpBuilder &b, Location loc, Value shapedValue, SmallVector< Value > &dynamicDims)
Populate dynamicDims with tensor::DimOp / memref::DimOp results for all dynamic dimensions of the giv...
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Type getTensorTypeFromMemRefType(Type type)
Return an unranked/ranked tensor type for the given unranked/ranked memref type.
Include the generated interface declarations.
LogicalResult reifyResultShapes(OpBuilder &b, Operation *op, ReifiedRankedShapedTypeDims &reifiedReturnShapes)
Reify the shape of the result of an operation (typically in terms of the shape of its operands).
bool insideMutuallyExclusiveRegions(Operation *a, Operation *b)
Return true if a and b are in mutually exclusive regions as per RegionBranchOpInterface.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Region * getEnclosingRepetitiveRegion(Operation *op)
Return the first enclosing region of the given op that may be executed repetitively as per RegionBran...
SmallVector< SmallVector< OpFoldResult > > ReifiedRankedShapedTypeDims
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...