Skip to content

Commit

Permalink
pr: Implement reconcile parser casts conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Jan 15, 2025
1 parent 2dfb27c commit a3de5c1
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions lib/vast/Conversion/Parser/ReconcileCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ VAST_RELAX_WARNINGS
VAST_UNRELAX_WARNINGS

#include "PassesDetails.hpp"
#include "Utils.hpp"

#include "vast/Conversion/Common/Mixins.hpp"
#include "vast/Conversion/Common/Patterns.hpp"
Expand All @@ -20,9 +21,42 @@ namespace vast::conv {

namespace pattern {

using cast_conversions = util::type_list<
// Casts
>;
struct UnrealizedCastConversion
: one_to_one_conversion_pattern< mlir::UnrealizedConversionCastOp, pr::Cast >
{
using op_t = mlir::UnrealizedConversionCastOp;
using base = one_to_one_conversion_pattern< mlir::UnrealizedConversionCastOp, pr::Cast >;
using base::base;

using adaptor_t = typename op_t::Adaptor;

logical_result matchAndRewrite(
op_t op, adaptor_t adaptor, conversion_rewriter &rewriter
) const override {
if (op.getNumOperands() != 1) {
return mlir::failure();
}

auto src = mlir::dyn_cast< mlir::UnrealizedConversionCastOp >(op.getOperand(0).getDefiningOp());

if (!src || src.getNumOperands() != 1) {
return mlir::failure();
}

if (pr::is_parser_type(src.getOperand(0).getType())) {
rewriter.replaceOpWithNewOp< pr::Cast >(op, op.getType(0), src.getOperand(0));
return mlir::success();
}

return mlir::success();
}

static void legalize(base_conversion_config &cfg) {
cfg.target.addLegalOp< pr::Cast >();
}
};

using cast_conversions = util::type_list< UnrealizedCastConversion >;

} // namespace pattern

Expand Down

0 comments on commit a3de5c1

Please sign in to comment.