Skip to content

Commit

Permalink
conv:hltollcf: Handle core::SelectOp.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkorenc committed May 16, 2024
1 parent 5a32e69 commit 4d709f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/vast/Conversion/FromHL/ToLLCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,40 @@ namespace vast::conv
}
};

template< typename op_t, typename trg_t >
struct replace_scope : base_pattern< op_t >
{
using parent_t = base_pattern< op_t >;
using parent_t::parent_t;


mlir::LogicalResult matchAndRewrite(
op_t op,
typename op_t::Adaptor ops,
conversion_rewriter &rewriter) const override
{
auto new_scope = rewriter.create< trg_t >( op.getLoc(), ops.getOperands() );
auto &front_block = new_scope.getBody().emplaceBlock();
rewriter.inlineRegionBefore(op.getBody(), &front_block);

rewriter.replaceOp(op, new_scope);
return mlir::success();
}

static void legalize( conversion_target &trg )
{
trg.addIllegalOp< op_t >();
trg.addLegalOp< trg_t >();
}
};

using cf_patterns = util::make_list<
if_op
, while_op
, for_op
, replace< hl::ReturnOp, ll::ReturnOp >
, replace< core::ImplicitReturnOp, ll::ReturnOp >
, replace_scope< core::ScopeOp, ll::Scope >
>;

} // namespace pattern
Expand Down

0 comments on commit 4d709f9

Please sign in to comment.