Skip to content

Make rc_for_type() pass Type arg by reference instead of value - #14024

Open
Firestar99 wants to merge 2 commits into
bytecodealliance:mainfrom
Firestar99:rc_for_type_by_ref
Open

Make rc_for_type() pass Type arg by reference instead of value#14024
Firestar99 wants to merge 2 commits into
bytecodealliance:mainfrom
Firestar99:rc_for_type_by_ref

Conversation

@Firestar99

Copy link
Copy Markdown
Contributor

This PR changes trait MachInst:

- fn rc_for_type(ty: Type) -> CodegenResult<(&'static [RegClass], &'static [Type])>;
+ fn rc_for_type(ty: &Type) -> CodegenResult<(&[RegClass], &[Type])>;

This change is trivial to support from all call sites, and allows implementors to:

- I8 => Ok((&[RegClass::Int], &[I8])),
- I16 => Ok((&[RegClass::Int], &[I16])),
- I32 => Ok((&[RegClass::Int], &[I32])),
- I64 => Ok((&[RegClass::Int], &[I64])),
- F32 => Ok((&[RegClass::Float], &[F32])),
- F64 => Ok((&[RegClass::Float], &[F64])),
+ I8 | I16 | I32 | I64 => Ok((&[RegClass::Int], core::slice::from_ref(ty))),
+ F32 | F64 => Ok((&[RegClass::Float], core::slice::from_ref(ty))),

Not sure how overall valuable this patch is. This function has just been annoying to implement for SSA-style IRs, where RegClass doesn't matter and it's just returning whatever type was passed.

@Firestar99
Firestar99 requested review from a team as code owners July 30, 2026 13:33
@Firestar99
Firestar99 requested review from fitzgen and removed request for a team July 30, 2026 13:33
@fitzgen

fitzgen commented Jul 30, 2026

Copy link
Copy Markdown
Member

This function has just been annoying to implement for SSA-style IRs, where RegClass doesn't matter and it's just returning whatever type was passed.

Can you clarify what you are doing here? Are you adding an SSA-style IR as a new backend to Cranelift?

@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants