Compiler Internals
Finch has several compiler modules with separate interfaces.
SymbolicContexts
SymbolicContexts are used to represent the symbolic information of a program. They are used to reason about the bounds of loops and the symbolic information of the program, and are defined on an algebra
Finch.StaticHash
— TypeStaticHash
A hash function which is static, i.e. the hashes are the same when objects are hashed in the same order. The hash is used to memoize the results of simplification and proof rules.
Finch.SymbolicContext
— TypeSymbolicContext
A compiler context for symbolic computation, defined on an algebra.
Finch.get_algebra
— Functionget_algebra(ctx)
get the algebra used in the current context
Finch.get_static_hash
— Functionget_static_hash(ctx)
Return an object which can be called as a hash function. The hashes are the same when objects are hashed in the same order.
Finch.prove
— Functionprove(ctx, root; verbose = false)
use the rules in ctx
to attempt to prove that the program root
is true. Return false if the program cannot be shown to be true.
Finch.simplify
— Functionsimplify(ctx, node)
simplify the program node
using the rules in ctx
ScopeContexts
ScopeContexts are used to represent the scope of a program. They are used to reason about values bound to variables and also the modes of tensor variables.
Finch.ScopeContext
— TypeScopeContext
A context for managing variable bindings and tensor modes.
Finch.get_binding
— Functionget_binding(ctx, var)
Get the binding of a variable in the context.
get_binding(ctx, var, val)
Get the binding of a variable in the context, or return a default value.
Finch.has_binding
— Functionhas_binding(ctx, var)
Check if a variable is bound in the context.
Finch.set_binding!
— Functionset_binding!(ctx, var, val)
Set the binding of a variable in the context.
Finch.set_declared!
— Functionset_declared!(ctx, var, val, op)
Mark a tensor variable as declared in the context.
Finch.set_frozen!
— Functionset_frozen!(ctx, var, val)
Mark a tensor variable as frozen in the context.
Finch.set_thawed!
— Functionset_thawed!(ctx, var, val, op)
Mark a tensor variable as thawed in the context.
Finch.get_tensor_mode
— Functionget_tensor_mode(ctx, var)
Get the mode of a tensor variable in the context.
Finch.open_scope
— Functionopen_scope(f, ctx)
Call the function f(ctx_2)
in a new scope ctx_2
.
JuliaContexts
JuliaContexts are used to represent the execution environment of a program, including variables and tasks. They are used to generate code.
Finch.Namespace
— TypeNamespace
A namespace for managing variable names and aesthetic fresh variable generation.
Finch.JuliaContext
— TypeJuliaContext
A context for compiling Julia code, managing side effects, parallelism, and variable names in the generated code of the executing environment.
Finch.push_preamble!
— Functionpush_preamble!(ctx, thunk)
Push the thunk onto the preamble in the currently executing context. The preamble will be evaluated before the code returned by the given function in the context.
Finch.push_epilogue!
— Functionpush_epilogue!(ctx, thunk)
Push the thunk onto the epilogue in the currently executing context. The epilogue will be evaluated after the code returned by the given function in the context.
Finch.get_task
— Functionget_task(ctx)
Get the task which will execute code in this context
Finch.freshen
— Functionfreshen(ctx, tags...)
Return a fresh variable in the current context named after Symbol(tags...)
Finch.contain
— Functioncontain(f, ctx)
Call f on a subcontext of ctx
and return the result. Variable bindings, preambles, and epilogues defined in the subcontext will not escape the call to contain.
AbstractCompiler
The AbstractCompiler interface requires all of the functionality of the above contexts, as well as the following two methods:
Finch.FinchCompiler
— TypeFinchCompiler
The core compiler for Finch, lowering canonicalized Finch IR to Julia code.
Finch.get_result
— Functionget_result(ctx)
Return a variable which evaluates to the result of the program which should be returned to the user.
Finch.get_mode_flag
— Functionget_mode_flag(ctx)
Return the mode flag given in @finch mode = ?
.