64 struct CondBranchOpInterface
65 :
public BufferDeallocationOpInterface::ExternalModel<CondBranchOpInterface,
70 auto condBr = cast<cf::CondBranchOp>(op);
75 if (failed(state.getMemrefsAndConditionsToDeallocate(
76 builder, condBr.getLoc(), condBr->getBlock(), memrefs, conditions)))
81 auto insertDeallocForBranch =
83 const std::function<
Value(
Value)> &conditionModifier,
86 state.getMemrefsToRetain(condBr->getBlock(), target,
87 destOperands.getAsOperandRange(), toRetain);
89 llvm::map_range(conditions, conditionModifier));
90 auto deallocOp = builder.create<bufferization::DeallocOp>(
91 condBr.getLoc(), memrefs, adaptedConditions, toRetain);
92 state.resetOwnerships(deallocOp.getRetained(), condBr->getBlock());
93 for (
auto [retained, ownership] : llvm::zip(
94 deallocOp.getRetained(), deallocOp.getUpdatedConditions())) {
95 state.updateOwnership(retained, ownership, condBr->getBlock());
96 mapping[retained] = ownership;
100 replacements.push_back(operand.get());
102 assert(mapping.contains(operand.get()) &&
103 "Should be contained at this point");
104 ownerships.push_back(mapping[operand.get()]);
107 replacements.append(ownerships);
108 destOperands.assign(replacements);
115 DeallocOp thenTakenDeallocOp = insertDeallocForBranch(
116 condBr.getTrueDest(), condBr.getTrueDestOperandsMutable(),
118 return builder.create<arith::AndIOp>(condBr.getLoc(), cond,
119 condBr.getCondition());
122 DeallocOp elseTakenDeallocOp = insertDeallocForBranch(
123 condBr.getFalseDest(), condBr.getFalseDestOperandsMutable(),
125 Value trueVal = builder.create<arith::ConstantOp>(
126 condBr.getLoc(), builder.getBoolAttr(true));
127 Value negation = builder.create<arith::XOrIOp>(
128 condBr.getLoc(), trueVal, condBr.getCondition());
129 return builder.create<arith::AndIOp>(condBr.getLoc(), cond, negation);
137 thenTakenDeallocOp.getRetained().end());
139 for (
Value val : elseTakenDeallocOp.getRetained()) {
140 if (thenValues.contains(val))
141 commonValues.insert(val);
144 for (
Value retained : commonValues) {
145 state.resetOwnerships(retained, condBr->getBlock());
146 Value combinedOwnership = builder.create<arith::SelectOp>(
147 condBr.getLoc(), condBr.getCondition(), thenMapping[retained],
148 elseMapping[retained]);
149 state.updateOwnership(retained, combinedOwnership, condBr->getBlock());
152 return condBr.getOperation();
161 CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx);
static llvm::ManagedStatic< PassManagerOptions > options
Block represents an ordered list of Operations.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
This class provides a mutable adaptor for a range of operands.
This class helps build Operations.
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
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.
This class collects all the state that we need to perform the buffer deallocation pass with associate...
void registerBufferDeallocationOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.
Options for BufferDeallocationOpInterface-based buffer deallocation.