23 #include "llvm/ADT/SetOperations.h"
24 #include "llvm/ADT/SmallString.h"
37 Block *placementBlock,
46 if (startOperation->
getBlock() != placementBlock) {
49 startOperation = opInPlacementBlock ? opInPlacementBlock
53 return startOperation;
61 void BufferPlacementAllocs::build(
Operation *op) {
62 op->
walk([&](MemoryEffectOpInterface opInterface) {
65 opInterface.getEffects(effects);
69 effects, std::back_inserter(allocateResultEffects),
72 return isa<MemoryEffects::Allocate>(it.
getEffect()) && value &&
73 isa<OpResult>(value) &&
79 if (allocateResultEffects.size() != 1)
82 Value allocValue = allocateResultEffects[0].getValue();
88 allocs.push_back(std::make_tuple(allocValue, *dealloc));
99 : aliases(op), allocs(op), liveness(op) {}
105 FailureOr<memref::GlobalOp>
108 auto type = cast<RankedTensorType>(constantOp.getType());
109 auto moduleOp = constantOp->getParentOfType<ModuleOp>();
116 auto globalOp = dyn_cast<memref::GlobalOp>(&op);
119 if (!globalOp.getInitialValue().has_value())
121 uint64_t opAlignment = globalOp.getAlignment().value_or(0);
122 Attribute initialValue = globalOp.getInitialValue().value();
123 if (opAlignment == alignment && initialValue == constantOp.getValue())
129 OpBuilder globalBuilder(moduleOp.getContext());
134 llvm::raw_svector_ostream os(buf);
135 interleave(type.getShape(), os,
"x");
136 os <<
"x" << type.getElementType();
139 IntegerAttr memrefAlignment =
148 auto global = globalBuilder.
create<memref::GlobalOp>(
149 constantOp.getLoc(), (Twine(
"__constant_") + os.str()).str(),
152 cast<ElementsAttr>(constantOp.getValue()),
155 symbolTable.
insert(global);
158 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.
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.
BaseMemRefType getMemRefTypeWithStaticIdentityLayout(TensorType tensorType, Attribute memorySpace=nullptr)
Return a MemRef type with a static identity layout (i.e., no layout map).
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...