17 #define GEN_PASS_DEF_RECONCILEUNREALIZEDCASTS
18 #include "mlir/Conversion/Passes.h.inc"
40 struct UnrealizedConversionCastPassthrough
55 visitStack.push_back(op);
57 while (!visitStack.empty()) {
58 UnrealizedConversionCastOp current = visitStack.pop_back_val();
59 auto users = current->getUsers();
63 if (
auto other = dyn_cast<UnrealizedConversionCastOp>(user)) {
64 if (other.getInputs() != current.getOutputs())
66 op,
"mismatching values propagation");
72 if (
auto other = dyn_cast<UnrealizedConversionCastOp>(user))
73 visitStack.push_back(other);
82 bool isCycle = current.getResultTypes() == op.getInputs().getTypes();
84 if (isLive && !isCycle)
86 "live unrealized conversion cast");
88 bool isExitNode = users.empty() || isLive;
91 exitNodes.insert(current);
93 intermediateNodes.insert(current);
98 for (UnrealizedConversionCastOp exitNode : exitNodes)
99 rewriter.
replaceOp(exitNode, op.getInputs());
102 for (UnrealizedConversionCastOp castOp : intermediateNodes)
110 struct ReconcileUnrealizedCasts
111 :
public impl::ReconcileUnrealizedCastsBase<ReconcileUnrealizedCasts> {
112 ReconcileUnrealizedCasts() =
default;
114 void runOnOperation()
override {
118 target.addIllegalOp<UnrealizedConversionCastOp>();
120 std::move(patterns))))
129 patterns.
add<UnrealizedConversionCastPassthrough>(patterns.
getContext());
133 return std::make_unique<ReconcileUnrealizedCasts>();
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
Operation is the basic unit of execution within MLIR.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
Include the generated interface declarations.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
void populateReconcileUnrealizedCastsPatterns(RewritePatternSet &patterns)
Populates patterns with rewrite patterns that eliminate noop unrealized_conversion_cast operation seq...
std::unique_ptr< Pass > createReconcileUnrealizedCastsPass()
Creates a pass that eliminates noop unrealized_conversion_cast operation sequences.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...