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 — Type
StaticHashA 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 — Type
SymbolicContextA compiler context for symbolic computation, defined on an algebra.
Finch.get_algebra — Function
get_algebra(ctx)get the algebra used in the current context
Finch.get_static_hash — Function
get_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 — Function
prove(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 — Function
simplify(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 — Type
ScopeContextA context for managing variable bindings and tensor modes.
Finch.get_binding — Function
get_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 — Function
has_binding(ctx, var)Check if a variable is bound in the context.
Finch.set_binding! — Function
set_binding!(ctx, var, val)Set the binding of a variable in the context.
Finch.set_declared! — Function
set_declared!(ctx, var, val, op)Mark a tensor variable as declared in the context.
Finch.set_frozen! — Function
set_frozen!(ctx, var, val)Mark a tensor variable as frozen in the context.
Finch.set_thawed! — Function
set_thawed!(ctx, var, val, op)Mark a tensor variable as thawed in the context.
Finch.get_tensor_mode — Function
get_tensor_mode(ctx, var)Get the mode of a tensor variable in the context.
Finch.open_scope — Function
open_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 — Type
NamespaceA namespace for managing variable names and aesthetic fresh variable generation.
Finch.JuliaContext — Type
JuliaContextA context for compiling Julia code, managing side effects, parallelism, and variable names in the generated code of the executing environment.
Finch.push_preamble! — Function
push_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! — Function
push_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 — Function
get_task(ctx)Get the task which will execute code in this context
Finch.freshen — Function
freshen(ctx, tags...)Return a fresh variable in the current context named after Symbol(tags...)
Finch.contain — Function
contain(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 — Type
FinchCompilerThe core compiler for Finch, lowering canonicalized Finch IR to Julia code.
Finch.get_result — Function
get_result(ctx)Return a variable which evaluates to the result of the program which should be returned to the user.
Finch.get_mode_flag — Function
get_mode_flag(ctx)Return the mode flag given in @finch mode = ?.