MLIR: lib/Analysis/SliceWalk.cpp Source File (original) (raw)

3

4 using namespace mlir;

5

8

10 llvm::SmallDenseSet<Value, 16> seenValues;

11 while (!workList.empty()) {

12

13 Value current = workList.pop_back_val();

14

15

16 if (!seenValues.insert(current).second)

17 continue;

18

19

22 return continuation;

24 continue;

25

27

28 workList.append(continuation.getNextValues().begin(),

30 }

31

33 }

34

35

36

40 unsigned operandNumber) {

42

43

46 auto *it = llvm::find_if(successors, [&successor](RegionSuccessor curr) {

48 });

49 return it != successors.end();

50 };

51

52

55 regionOp.getEntrySuccessorRegions(operandAttributes, successors);

56 if (isContained(successors, successor)) {

57 OperandRange operands = regionOp.getEntrySuccessorOperands(successor);

58 predecessorOperands.push_back(operands[operandNumber]);

59 }

60

61

62 for (Region &region : regionOp->getRegions()) {

63 for (Block &block : region) {

64 auto terminatorOp =

65 dyn_cast(block.getTerminator());

66 if (!terminatorOp)

67 continue;

70 terminatorOp.getSuccessorRegions(operandAttributes, successors);

71 if (isContained(successors, successor)) {

72 OperandRange operands = terminatorOp.getSuccessorOperands(successor);

73 predecessorOperands.push_back(operands[operandNumber]);

74 }

75 }

76 }

77

78 return predecessorOperands;

79 }

80

81

82

83 static std::optional<SmallVector>

86

87

90 Block *predecessor = *it;

91 auto branchOp = dyn_cast(predecessor->getTerminator());

92 if (!branchOp)

93 return std::nullopt;

95 branchOp.getSuccessorOperands(it.getSuccessorIndex());

96

97

99 predecessorOperands.push_back(operand);

100 }

101

102 return predecessorOperands;

103 }

104

105 std::optional<SmallVector>

107 if (OpResult opResult = dyn_cast(value)) {

108 if (auto selectOp = opResult.getDefiningOp())

110 {selectOp.getTrueValue(), selectOp.getFalseValue()});

111 auto regionOp = opResult.getDefiningOp();

112

113

114 if (!regionOp)

115 return std::nullopt;

116

119 regionOp, region, opResult.getResultNumber());

120 return predecessorOperands;

121 }

122

123 auto blockArg = cast(value);

124 Block *block = blockArg.getOwner();

125

127 if (auto regionBranchOp =

128 dyn_cast(block->getParentOp())) {

131 regionBranchOp, region, blockArg.getArgNumber());

132 return predecessorOperands;

133 }

134

135

136 return std::nullopt;

137 }

138

139

141 }

static std::optional< SmallVector< Value > > getBlockPredecessorOperands(BlockArgument blockArg)

Returns the predecessor branch operands that match blockArg, or nullopt if some of the predecessor te...

static SmallVector< Value > getRegionPredecessorOperands(RegionBranchOpInterface regionOp, RegionSuccessor successor, unsigned operandNumber)

Returns the operands from all predecessor regions that match operandNumber for the successor region w...

This class represents an argument of a Block.

Block * getOwner() const

Returns the block that owns this argument.

unsigned getArgNumber() const

Returns the number of this argument.

Block represents an ordered list of Operations.

pred_iterator pred_begin()

Operation * getTerminator()

Get the terminator operation of this block.

bool isEntryBlock()

Return if this block is the entry block in the parent region.

Operation * getParentOp()

Returns the closest surrounding operation that contains this block.

This is a value defined by a result of an operation.

This class implements the operand iterators for the Operation class.

This class represents a successor of a region.

Region * getSuccessor() const

Return the given region successor.

This class contains a list of basic blocks and a link to the parent operation it is attached to.

This class models how operands are forwarded to block arguments in control flow.

This class provides an abstraction over the different types of ranges over Values.

This class represents an instance of an SSA value in the MLIR system, representing a computable value...

A class to signal how to proceed with the walk of the backward slice:

bool wasInterrupted() const

Returns true if the walk was interrupted.

bool wasAdvancedTo() const

Returns true if the walk was advanced to user-specified values.

static WalkContinuation skip()

Creates a continuation that advances the walk without adding any predecessor values to the work list.

mlir::ArrayRef< mlir::Value > getNextValues() const

Returns the next values to continue the walk with.

bool wasSkipped() const

Returns true if the walk was skipped.

Include the generated interface declarations.

std::optional< SmallVector< Value > > getControlFlowPredecessors(Value value)

Computes a vector of all control predecessors of value.

WalkContinuation walkSlice(mlir::ValueRange rootValues, WalkCallback walkCallback)

Walks the slice starting from the rootValues using a depth-first traversal.