Trait LlvmFunctionAnalysis

Source
pub trait LlvmFunctionAnalysis {
    type Result;

    // Required methods
    fn run_analysis(
        &self,
        module: &FunctionValue<'_>,
        manager: &FunctionAnalysisManager,
    ) -> Self::Result;
    fn id() -> AnalysisKey;
}
Expand description

Trait to use for implementing an analysis pass on an LLVM function.

An analysis pass is not allowed to mutate the LLVM IR.

Required Associated Types§

Source

type Result

Result of the successful execution of this pass by the pass manager.

This data can be queried by passes through a FunctionAnalysisManager.

Required Methods§

Source

fn run_analysis( &self, module: &FunctionValue<'_>, manager: &FunctionAnalysisManager, ) -> Self::Result

Entrypoint for the pass.

The given analysis manager allows the pass to query the pass manager for the result of specific analysis passes.

The returned result will be moved into a Box before being given to the pass manager. This one will then add it to its internal cache, to avoid unnecessary calls to this entrypoint.

Source

fn id() -> AnalysisKey

Identifier for the analysis type.

This ID must be unique for each registered analysis type.

§Warning

The LLVM toolchain (e.g. opt, lld) often registers builtin analysis types during execution of passes. These builtin analyses always use the address of global static variables as IDs, to prevent collisions.

To make sure your custom analysis types don’t collide with the builtin ones used by the LLVM tool that loads your plugin, you should use static variables’ addresses as well.

§Example
fn id() -> AnalysisKey {
    static ID: u8 = 0;
    &ID
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§