MLIR: lib/Interfaces/SubsetOpInterface.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12

13 #include "mlir/Interfaces/SubsetOpInterface.cpp.inc"

14

15 using namespace mlir;

16

18 auto dstOp = dyn_cast(op);

19 assert(dstOp && "getDestination must be implemented for non-DPS ops");

20 assert(

21 dstOp.getNumDpsInits() == 1 &&

22 "getDestination must be implemented for ops with 0 or more than 1 init");

23 return *dstOp.getDpsInitOperand(0);

24 }

25

27 auto dstOp = dyn_cast(op);

28 assert(dstOp && "getUpdatedDestination must be implemented for non-DPS ops");

29 auto insertionOp = cast(op);

30 return dstOp.getTiedOpResult(&insertionOp.getDestinationOperand());

31 }

32

36 assert(isa(op) &&

37 "expected SubsetInsertionOpInterface");

38 if (!candidate.getDefiningOp())

39 return false;

40 return cast(op).operatesOnEquivalentSubset(

41 candidate.getDefiningOp(), equivalenceFn);

42 }

43

45 Operation *op, SubsetOpInterface candidate,

47 auto subsetOp = cast(op);

48 FailureOr slice =

49 subsetOp.getAccessedHyperrectangularSlice();

50 assert(succeeded(slice) &&

51 "operatesOnEquivalentSubset must be implemented if "

52 "getAccessedHyperrectangularSlice is not implemented");

53 FailureOr otherSlice =

54 candidate.getAccessedHyperrectangularSlice();

55 if (failed(otherSlice))

56 return false;

57 if (!equivalenceFn(subsetOp.getTensorContainer(),

58 candidate.getTensorContainer()))

59 return false;

61 op->getContext(), *slice, *otherSlice);

62 return succeeded(equivalent) && *equivalent;

63 }

64

66 Operation *op, SubsetOpInterface candidate,

68 auto subsetOp = cast(op);

69 FailureOr slice =

70 subsetOp.getAccessedHyperrectangularSlice();

71 assert(succeeded(slice) &&

72 "defaultOperatesOnDisjointSubset must be implemented if "

73 "getAccessedHyperrectangularSlice is not implemented");

74 FailureOr otherSlice =

75 candidate.getAccessedHyperrectangularSlice();

76 if (failed(otherSlice))

77 return false;

78 if (!equivalenceFn(subsetOp.getTensorContainer(),

79 candidate.getTensorContainer()))

80 return false;

82 op->getContext(), *slice, *otherSlice);

83 return succeeded(overlapping) && !*overlapping;

84 }

85

87 if (auto insertionOp = dyn_cast<::mlir::SubsetInsertionOpInterface>(op))

88 return insertionOp.getDestinationOperand().get();

89 return cast<::mlir::SubsetExtractionOpInterface>(op).getSourceOperand().get();

90 }

91

93 if (!(isa(op.getOperation()) ^

94 isa(op.getOperation())))

95 return op->emitOpError(

96 "SubsetOpInterface ops must implement either "

97 "SubsetExtractionOpInterface or SubsetInsertionOpInterface");

98 return success();

99 }

100

101 LogicalResult

103 if (op->getNumResults() != 1)

104 return op->emitOpError(

105 "SubsetExtractionOpInterface ops must have one result");

106 return success();

107 }

This class represents an operand of an operation.

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

Operation is the basic unit of execution within MLIR.

MLIRContext * getContext()

Return the context this operation is associated with.

static FailureOr< bool > areEquivalentSlices(MLIRContext *ctx, HyperrectangularSlice slice1, HyperrectangularSlice slice2)

Return "true" if the given slices are guaranteed to be equivalent.

static FailureOr< bool > areOverlappingSlices(MLIRContext *ctx, HyperrectangularSlice slice1, HyperrectangularSlice slice2)

Return "true" if the given slices are guaranteed to be overlapping.

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

Operation * getDefiningOp() const

If this value is the result of an operation, return the operation that defines it.

LogicalResult verifySubsetExtractionOpInterface(SubsetExtractionOpInterface op)

Verify SubsetExtractionOpInterface.

bool defaultOperatesOnDisjointSubset(Operation *op, SubsetOpInterface candidate, function_ref< bool(Value, Value)> equivalenceFn)

Default implementation of SubsetOpInterface::operatesOnDisjointSubset.

bool defaultOperatesOnEquivalentSubset(Operation *op, SubsetOpInterface candidate, function_ref< bool(Value, Value)> equivalenceFn)

Default implementation of SubsetOpInterface::operatesOnEquivalentSubset.

Value getTensorContainer(Operation *op)

Return the container that the given subset op is operating on.

OpResult defaultGetUpdatedDestination(Operation *op)

Return the updated destination result of the op if it implements the DestinationStyleOpInterface.

LogicalResult verifySubsetOpInterface(SubsetOpInterface op)

Verify SubsetOpInterface.

bool defaultIsEquivalentSubset(Operation *op, Value candidate, function_ref< bool(Value, Value)> equivalenceFn)

Default implementation of SubsetInsertionOpInterface::isEquivalentSubset.

OpOperand & defaultGetDestinationOperand(Operation *op)

Return the destination/"init" operand of the op if it implements the DestinationStyleOpInterface and ...

Include the generated interface declarations.