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 = bufferization::DeallocOp::create(
91 builder, 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 arith::AndIOp::create(builder, condBr.getLoc(), cond,
119 condBr.getCondition());
122 DeallocOp elseTakenDeallocOp = insertDeallocForBranch(
123 condBr.getFalseDest(), condBr.getFalseDestOperandsMutable(),
125 Value trueVal = arith::ConstantOp::create(builder, condBr.getLoc(),
126 builder.getBoolAttr(true));
127 Value negation = arith::XOrIOp::create(
128 builder, condBr.getLoc(), trueVal, condBr.getCondition());
129 return arith::AndIOp::create(builder, condBr.getLoc(), cond,
138 thenTakenDeallocOp.getRetained());
140 for (
Value val : elseTakenDeallocOp.getRetained()) {
141 if (thenValues.contains(val))
142 commonValues.insert(val);
145 for (
Value retained : commonValues) {
146 state.resetOwnerships(retained, condBr->getBlock());
147 Value combinedOwnership = arith::SelectOp::create(
148 builder, condBr.getLoc(), condBr.getCondition(),
149 thenMapping[retained], elseMapping[retained]);
150 state.updateOwnership(retained, combinedOwnership, condBr->getBlock());
153 return condBr.getOperation();
162 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.