Skip to content

Commit

Permalink
pr: Pass a hl::FuncOp instead of a name to `parser_conversion_patte…
Browse files Browse the repository at this point in the history
…rn_base`.
  • Loading branch information
frabert authored and xlauko committed Jan 31, 2025
1 parent be4330c commit 369a3b6
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/vast/Conversion/Parser/ToParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,17 @@ namespace vast::conv {
: base(mctx), models(models)
{}

static std::optional< function_model > get_model(
const function_models &models, string_ref name
) {
if (auto kv = models.find(name); kv != models.end()) {
static std::optional< function_model >
get_model(const function_models &models, hl::FuncOp func) {
if (auto kv = models.find(func.getSymName()); kv != models.end()) {
return kv->second;
}

return std::nullopt;
}

std::optional< function_model > get_model(string_ref name) const {
return get_model(models, name);
std::optional< function_model > get_model(hl::FuncOp func) const {
return get_model(models, func);
}

const function_models &models;
Expand Down Expand Up @@ -494,7 +493,7 @@ namespace vast::conv {
op_t op, adaptor_t adaptor, conversion_rewriter &rewriter
) const override {
auto func = op->getParentOfType< hl::FuncOp >();
auto model = get_model(func.getSymName());
auto model = get_model(func);

auto rty = model
? model->get_return_type(rewriter.getContext())
Expand Down Expand Up @@ -534,7 +533,7 @@ namespace vast::conv {
logical_result matchAndRewrite(
op_t op, adaptor_t adaptor, conversion_rewriter &rewriter
) const override {
auto tc = function_type_converter(*rewriter.getContext(), get_model(op.getSymName()));
auto tc = function_type_converter(*rewriter.getContext(), get_model(op));
if (auto func_op = mlir::dyn_cast< core::function_op_interface >(op.getOperation())) {
return this->replace(func_op, rewriter, tc);
}
Expand All @@ -545,9 +544,8 @@ namespace vast::conv {
static void legalize(parser_conversion_config &cfg) {
cfg.target.addLegalOp< mlir::UnrealizedConversionCastOp >();
cfg.target.addDynamicallyLegalOp< op_t >([models = cfg.models](op_t op) {
return function_type_converter(
*op.getContext(), get_model(models, op.getSymName())
).isLegal(op.getFunctionType());
return function_type_converter(*op.getContext(), get_model(models, op))
.isLegal(op.getFunctionType());
});
}
};
Expand Down

0 comments on commit 369a3b6

Please sign in to comment.