MLIR: lib/Dialect/ControlFlow/Transforms/BufferDeallocationOpInterfaceImpl.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

16

17 using namespace mlir;

19

21

22 namespace {

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64 struct CondBranchOpInterface

65 : public BufferDeallocationOpInterface::ExternalModel<CondBranchOpInterface,

66 cf::CondBranchOp> {

70 auto condBr = castcf::CondBranchOp(op);

71

72

73

75 if (failed(state.getMemrefsAndConditionsToDeallocate(

76 builder, condBr.getLoc(), condBr->getBlock(), memrefs, conditions)))

77 return failure();

78

79

80

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.createbufferization::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;

97 }

99 for (OpOperand &operand : destOperands) {

100 replacements.push_back(operand.get());

101 if (isMemref(operand.get())) {

102 assert(mapping.contains(operand.get()) &&

103 "Should be contained at this point");

104 ownerships.push_back(mapping[operand.get()]);

105 }

106 }

107 replacements.append(ownerships);

108 destOperands.assign(replacements);

109 return deallocOp;

110 };

111

112

113

115 DeallocOp thenTakenDeallocOp = insertDeallocForBranch(

116 condBr.getTrueDest(), condBr.getTrueDestOperandsMutable(),

117 [&](Value cond) {

118 return builder.createarith::AndIOp(condBr.getLoc(), cond,

119 condBr.getCondition());

120 },

121 thenMapping);

122 DeallocOp elseTakenDeallocOp = insertDeallocForBranch(

123 condBr.getFalseDest(), condBr.getFalseDestOperandsMutable(),

124 [&](Value cond) {

125 Value trueVal = builder.createarith::ConstantOp(

126 condBr.getLoc(), builder.getBoolAttr(true));

127 Value negation = builder.createarith::XOrIOp(

128 condBr.getLoc(), trueVal, condBr.getCondition());

129 return builder.createarith::AndIOp(condBr.getLoc(), cond, negation);

130 },

131 elseMapping);

132

133

134

135

137 thenTakenDeallocOp.getRetained());

139 for (Value val : elseTakenDeallocOp.getRetained()) {

140 if (thenValues.contains(val))

141 commonValues.insert(val);

142 }

143

144 for (Value retained : commonValues) {

145 state.resetOwnerships(retained, condBr->getBlock());

146 Value combinedOwnership = builder.createarith::SelectOp(

147 condBr.getLoc(), condBr.getCondition(), thenMapping[retained],

148 elseMapping[retained]);

149 state.updateOwnership(retained, combinedOwnership, condBr->getBlock());

150 }

151

152 return condBr.getOperation();

153 }

154 };

155

156 }

157

161 CondBranchOp::attachInterface(*ctx);

162 });

163 }

static bool isMemref(Value v)

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 &registry)

Include the generated interface declarations.

Options for BufferDeallocationOpInterface-based buffer deallocation.