21 #include "llvm/ADT/SetOperations.h"
22 #include "llvm/ADT/SmallString.h"
35 Block *placementBlock,
44 if (startOperation->
getBlock() != placementBlock) {
47 startOperation = opInPlacementBlock ? opInPlacementBlock
51 return startOperation;
59 void BufferPlacementAllocs::build(
Operation *op) {
60 op->
walk([&](MemoryEffectOpInterface opInterface) {
63 opInterface.getEffects(effects);
67 effects, std::back_inserter(allocateResultEffects),
70 return isa<MemoryEffects::Allocate>(it.
getEffect()) && value &&
71 isa<OpResult>(value) &&
77 if (allocateResultEffects.size() != 1)
80 Value allocValue = allocateResultEffects[0].getValue();
86 allocs.push_back(std::make_tuple(allocValue, *dealloc));
97 : aliases(op), allocs(op), liveness(op) {}
103 FailureOr<memref::GlobalOp>
106 auto type = cast<RankedTensorType>(constantOp.getType());
107 auto moduleOp = constantOp->getParentOfType<ModuleOp>();
114 auto globalOp = dyn_cast<memref::GlobalOp>(&op);
117 if (!globalOp.getInitialValue().has_value())
119 uint64_t opAlignment = globalOp.getAlignment().value_or(0);
120 Attribute initialValue = globalOp.getInitialValue().value();
121 if (opAlignment == alignment && initialValue == constantOp.getValue())
127 OpBuilder globalBuilder(moduleOp.getContext());
132 llvm::raw_svector_ostream os(buf);
133 interleave(type.getShape(), os,
"x");
134 os <<
"x" << type.getElementType();
137 IntegerAttr memrefAlignment =
142 auto memrefType = cast<MemRefType>(typeConverter.
convertType(type));
145 auto global = globalBuilder.
create<memref::GlobalOp>(
146 constantOp.getLoc(), (Twine(
"__constant_") + os.str()).str(),
149 cast<ElementsAttr>(constantOp.getValue()),
152 symbolTable.
insert(global);
155 global->moveBefore(&moduleOp.front());
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
Operation * findAncestorOpInBlock(Operation &op)
Returns 'op' if 'op' lies in this block, or otherwise finds the ancestor operation of 'op' that lies ...
Operation * getTerminator()
Get the terminator operation of this block.
StringAttr getStringAttr(const Twine &bytes)
This class represents liveness information on block level.
Operation * getStartOperation(Value value) const
Gets the start operation for the given value.
Represents an analysis for computing liveness information from a given top-level operation.
const LivenessBlockInfo * getLiveness(Block *block) const
Gets liveness info (if any) for the block.
This is a builder type that keeps local references to arguments.
Builder & setMemorySpace(Attribute newMemorySpace)
This class helps build Operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Operation is the basic unit of execution within MLIR.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
Block * getBlock()
Returns the operation block that contains this operation.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
iterator_range< OpIterator > getOps()
This class represents a specific instance of an effect.
Resource * getResource() const
Return the resource that the effect applies to.
EffectT * getEffect() const
Return the effect being applied.
Value getValue() const
Return the value the effect is applied on, or nullptr if there isn't a known value being affected.
static AutomaticAllocationScopeResource * get()
Returns a unique instance for the given effect class.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
static Operation * getStartOperation(Value allocValue, Block *placementBlock, const Liveness &liveness)
Get the start operation to place the given alloc value within the specified placement block.
BufferPlacementAllocs(Operation *op)
Initializes the internal list by discovering all supported allocation nodes.
A helper type converter class that automatically populates the relevant materializations and type con...
FailureOr< memref::GlobalOp > getGlobalFor(arith::ConstantOp constantOp, uint64_t alignment, Attribute memorySpace={})
std::optional< Operation * > findDealloc(Value allocValue)
Finds a single dealloc operation for the given allocated value.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...