17std::optional<Ref> internal_function_of_axiom(
const Axiom* axiom, Ref meta_args, Ref args) {
18 auto& world = axiom->world();
19 auto name = axiom->sym().str();
24 auto replacement = world.external(world.sym(name));
26 auto spec_fun = world.app(replacement, meta_args);
28 return world.app(ds_fun, args);
36 if (
auto i = rewritten.find(def); i != rewritten.end())
return i->second;
38 rewritten[def] = new_def;
39 return rewritten[def];
44 auto [
mem,
M, N] = mat_ax->args<3>();
45 auto [m, k, l, w] = mat_ax->decurry()->args<4>();
49 if (ext_fun && (w_lit && *w_lit == 64)) {
51 auto fun_app =
world().
app(ds_fun, {
mem, m, k, l,
M, N});
56 if (
auto outer_app = def->isa<
App>()) {
57 if (
auto inner_app = outer_app->callee()->isa<
App>()) {
58 if (
auto axiom = inner_app->callee()->isa<
Axiom>()) {
59 if (
auto internal_function = internal_function_of_axiom(axiom, inner_app->arg(), outer_app->arg())) {
60 world().DLOG(
"lower matrix axiom {} in {} : {}", *axiom->sym(), def, def->
type());
61 world().DLOG(
"lower matrix axiom using: {} : {}", *internal_function, (*internal_function)->type());
62 return *internal_function;
static std::optional< T > isa(Ref def)
Helper class to retrieve Infer::arg if present.
Ref app(Ref callee, Ref arg)
Def * external(Sym name)
Lookup by name.
Ref rewrite(Ref) override
custom rewrite function memoized version of rewrite_
const Def * op_cps2ds_dep(const Def *f)
void find_and_replace(std::string &str, std::string_view what, std::string_view repl)
Replaces all occurrences of what with repl.