Trait hugr_llvm::custom::CodegenExtension

source ·
pub trait CodegenExtension<'c, H> {
    // Required methods
    fn extension(&self) -> ExtensionId;
    fn llvm_type(
        &self,
        context: &TypingSession<'c, H>,
        hugr_type: &CustomType,
    ) -> Result<BasicTypeEnum<'c>>;
    fn emitter<'a>(
        &'a self,
        context: &'a mut EmitFuncContext<'c, H>,
    ) -> Box<dyn EmitOp<'c, CustomOp, H> + 'a>;

    // Provided methods
    fn supported_consts(&self) -> HashSet<TypeId> { ... }
    fn load_constant(
        &self,
        context: &mut EmitFuncContext<'c, H>,
        konst: &dyn CustomConst,
    ) -> Result<Option<BasicValueEnum<'c>>> { ... }
}
Expand description

The extension point for lowering HUGR Extensions to LLVM.

Required Methods§

source

fn extension(&self) -> ExtensionId

The ExtensionId for which this extension will lower ExtensionOps and CustomTypes.

Note that a CodegenExtsMap will only delegate to a single CodegenExtension per ExtensionId.

source

fn llvm_type( &self, context: &TypingSession<'c, H>, hugr_type: &CustomType, ) -> Result<BasicTypeEnum<'c>>

Return the type of the given CustomType, which will have an extension that matches Self.

source

fn emitter<'a>( &'a self, context: &'a mut EmitFuncContext<'c, H>, ) -> Box<dyn EmitOp<'c, CustomOp, H> + 'a>

Return an emitter that will be asked to emit CustomOps that have an extension that matches Self.

Provided Methods§

source

fn supported_consts(&self) -> HashSet<TypeId>

The TypeIds for which dyn CustomConsts should be passed to Self::load_constant.

Defaults to an empty set.

source

fn load_constant( &self, context: &mut EmitFuncContext<'c, H>, konst: &dyn CustomConst, ) -> Result<Option<BasicValueEnum<'c>>>

Emit instructions to materialise konst. konst will have a TypeId that matches self.supported_consts.

If the result is Ok(None), CodegenExtsMap may try other CodegenExtensions.

Implementors§