Attribute Macro llvm_plugin::plugin

source ·
#[plugin]
Available on crate feature macros only.
Expand description

Macro for defining a new LLVM plugin.

This macro must be used on a function, and needs a name and version parameters.

The annotated function will be used as the plugin’s entrypoint, and must take a PassBuilder as argument.

§Warning

This macro should be used on cdylib crates only. Also, since it generates an export symbol, it should be used once for the whole dylib being compiled.

§Example

#[llvm_plugin::plugin(name = "plugin_name", version = "0.1")]
fn plugin_registrar(builder: &mut PassBuilder) {
    builder.add_module_pipeline_parsing_callback(|name, pass_manager| {
        // add passes to the pass manager
    });

    builder.add_module_analysis_registration_callback(|analysis_manager| {
        // register analyses to the analysis manager
    });
}