Build Status | Coverage | Documentation |
---|---|---|
Note: Usage of this package requires
julia >= 1.6
.
] add Mixtape
Mixtape.jl
is a static method overlay and optimization tool which operates during Julia type inference. It allows you to (precisely) insert semantic-intruding changes to lowered code (e.g. replace CodeInfo
, pre-optimize CodeInfo
, and create other forms of static analysis tools on uninferred CodeInfo
) before optimization. It also allows you to customize the optimization pipeline -- allowing users to write semantic-preserving passes on Core.Compiler.IRCode which operate after inference.
Note:
Mixtape.jl
manages its own code cache and execution engine through LLVM.jl and GPUCompiler.jl -- so it is less part of Julia's native pipeline, and closer to a separate compiler pipeline. In the future, parts ofMixtape.jl
may be integrated or otherwise exposed as standard APIs with the compiler.
In many respects, it is similar to Cassette.jl -- but it is completely static.
Note: the architecture for this package can be found in many other places. The interested reader might look at KernelCompiler.jl, Enzyme.jl, the Julia frontend to brutus, and the compiler interface in GPUCompiler.jl to understand this a bit better.
When in doubt, don't be afraid of typeinfer.jl and Julia's SSA form IR!
using Mixtape
using Mixtape: jit, emit, @load_abi
import Mixtape: CompilationContext,
allow,
transform,
optimize!
Mixtape.jl
exports a set of interfaces which allows you to interact with aspects of Julia's type inference to modify the lowered code of method instances before placement into a runtime cache. This code can then be executed as part of a self-managed code generation pipeline. This code generation pipeline works through the LLVM.jl and GPUCompiler.jl infrastructure.
In other words, you can futz with stuff without refactoring the stuff.
The interfaces are well-documented (if experimental).
This package pairs well with CodeInfoTools.jl.
Now easy as 1, 2, 3!
A few upsides!
- Completely static -- does not rely on recursive pollution of the call stack (see: the overdub issue).
- Transforms operate pre-type inference -- all semantic-intruding changes happen before type inference runs on the lowered method body.
Mixtape.jl
manages its own code cache -- and doesn't interact with the native runtime system (see above).
A few downsides...
Mixtape.jl
uses a custom execution engine throughGPUCompiler.jl
-- code which causesGPUCompiler.jl
to fail will also causeMixtape.jl
to fail. In practice, this means you can't use the pipeline on dispatch tuples withUnion{As...}
orAny
-- you must specify a non-dynamic type.