Skip to content

Commit

Permalink
pr: Implement expresion inlining.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Jan 14, 2025
1 parent d1b896b commit faa7708
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion lib/vast/Conversion/Parser/ToParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VAST_UNRELAX_WARNINGS
#include "vast/Conversion/TypeConverters/TypeConvertingPattern.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/Terminator.hpp"

#include "vast/Dialect/Parser/Ops.hpp"
#include "vast/Dialect/Parser/Types.hpp"
Expand Down Expand Up @@ -493,13 +494,46 @@ namespace vast::conv {
}
};

struct ExprConversion
: parser_conversion_pattern_base< hl::ExprOp >
{
using op_t = hl::ExprOp;
using base = parser_conversion_pattern_base< op_t >;
using base::base;

using adaptor_t = typename op_t::Adaptor;

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

auto yield = terminator< hl::ValueYieldOp >::get(*body);
VAST_PATTERN_CHECK(yield, "Expected yield in: {0}", op);

rewriter.inlineBlockBefore(body, op);
rewriter.replaceOp(op, yield.op().getResult());
rewriter.eraseOp(yield.op());

return mlir::success();
}

static void legalize(parser_conversion_config &cfg) {
cfg.target.addLegalOp< mlir::UnrealizedConversionCastOp >();
}
};

using operation_conversions = util::type_list<
ToNoParse< hl::ConstantOp >,
ToNoParse< hl::ImplicitCastOp >,
ToNoParse< hl::CmpOp>, ToNoParse< hl::FCmpOp >,
ExprConversion,
FuncConversion,
ParamConversion,
// DeclRefConversion,
DeclRefConversion,
ReturnConversion,
CallConversion
>;
Expand Down

0 comments on commit faa7708

Please sign in to comment.