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§
sourcefn extension(&self) -> ExtensionId
fn extension(&self) -> ExtensionId
The ExtensionId for which this extension will lower ExtensionOp
s and
CustomTypes.
Note that a CodegenExtsMap will only delegate to a single
CodegenExtension
per ExtensionId.
sourcefn llvm_type(
&self,
context: &TypingSession<'c, H>,
hugr_type: &CustomType,
) -> Result<BasicTypeEnum<'c>>
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
.
Provided Methods§
sourcefn supported_consts(&self) -> HashSet<TypeId>
fn supported_consts(&self) -> HashSet<TypeId>
The TypeIds for which dyn CustomConsts should be passed to Self::load_constant.
Defaults to an empty set.
sourcefn load_constant(
&self,
context: &mut EmitFuncContext<'c, H>,
konst: &dyn CustomConst,
) -> Result<Option<BasicValueEnum<'c>>>
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
CodegenExtension
s.