Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ log = { version = "0.4.28", default-features = false }
clap = { version = "4.5.48", default-features = false, features = ["std", "derive"] }
clap_complete = "4.5.58"
hashbrown = { version = "0.17", default-features = false }
capstone = { version = "0.14.0", default-features = false, features = ['full', 'arch_x86', 'arch_riscv', 'arch_arm64', 'arch_sysz'] }
capstone = { version = "0.14.0", default-features = false, features = ['full', 'arch_x86', 'arch_riscv', 'arch_arm64', 'arch_sysz', 'arch_arm'] }
smallvec = { version = "1.15.1", features = ["union"] }
tracing = { version = "0.1.41", default-features = false }
bitflags = "2.9.4"
Expand Down
3 changes: 2 additions & 1 deletion cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ unwind = ["gimli"]
# If no ISA targets are explicitly enabled, the ISA target for the host machine is enabled.
x86 = []
arm64 = []
arm32 = []
s390x = []
riscv64 = []
pulley = [
Expand All @@ -109,7 +110,7 @@ all-arch = ["all-native-arch", "pulley"]

# Option to enable all architectures that correspond to an actual native target
# (that is, exclude Pulley).
all-native-arch = ["x86", "arm64", "s390x", "riscv64"]
all-native-arch = ["x86", "arm64", "s390x", "riscv64", "arm32"]

# For dependent crates that want to serialize some parts of cranelift
enable-serde = [
Expand Down
11 changes: 11 additions & 0 deletions cranelift/codegen/meta/src/isa/arm32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::cdsl::isa::TargetIsa;
use crate::cdsl::settings::SettingGroupBuilder;

pub(crate) fn define() -> TargetIsa {
let settings = SettingGroupBuilder::new("arm32");

// ARM32-specific settings can be added here in the future.
// For now, we start with an empty settings group.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cg_clif would at the very least need the thumb2 (use thumb2 rather than the original thumb) and thumb-mode (actually use thumb rather than arm instructions) settings to match LLVM. And the current backend you wrote should error when either is not set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about the erroring part, do you have specific names for the flags in mind so that they are more easily compatible with cg_clif?

@cpetig cpetig Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess other settings are has_fp32, has_fp64, has_dsp, has_cbz, has_it, hwfloat_abi.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can select between thumb and arm on a per-function basis in LLVM and Rust, so changing the target triple is not the only way of choosing thumb mode. #[instruction_set(arm::t32)] lowers to what is effectively #[target_feature(enable = "thumb-mode")] in the LLVM backend of rustc. And a couple of rustc targets also use target_features: "+thumb-mode" in the target spec.


TargetIsa::new("arm32", settings.build())
}
6 changes: 6 additions & 0 deletions cranelift/codegen/meta/src/isa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::cdsl::isa::TargetIsa;
use std::fmt;

mod arm32;
mod arm64;
mod pulley;
mod riscv64;
Expand All @@ -13,6 +14,7 @@ pub(crate) mod x86;
pub enum Isa {
X86,
Arm64,
Arm32,
S390x,
Riscv64,
Pulley32,
Expand All @@ -31,6 +33,7 @@ impl Isa {
/// Creates isa target from arch.
pub fn from_arch(arch: &str) -> Option<Self> {
match arch {
"arm" => Some(Isa::Arm32),
"aarch64" => Some(Isa::Arm64),
"s390x" => Some(Isa::S390x),
x if ["x86_64", "i386", "i586", "i686"].contains(&x) => Some(Isa::X86),
Expand All @@ -46,6 +49,7 @@ impl Isa {
&[
Isa::X86,
Isa::Arm64,
Isa::Arm32,
Isa::S390x,
Isa::Riscv64,
Isa::Pulley32,
Expand All @@ -60,6 +64,7 @@ impl fmt::Display for Isa {
match *self {
Isa::X86 => write!(f, "x86"),
Isa::Arm64 => write!(f, "arm64"),
Isa::Arm32 => write!(f, "arm32"),
Isa::S390x => write!(f, "s390x"),
Isa::Riscv64 => write!(f, "riscv64"),
Isa::Pulley32 => write!(f, "pulley32"),
Expand All @@ -73,6 +78,7 @@ pub(crate) fn define(isas: &[Isa]) -> Vec<TargetIsa> {
.map(|isa| match isa {
Isa::X86 => x86::define(),
Isa::Arm64 => arm64::define(),
Isa::Arm32 => arm32::define(),
Isa::S390x => s390x::define(),
Isa::Riscv64 => riscv64::define(),
Isa::Pulley32 | Isa::Pulley64 => pulley::define(),
Expand Down
16 changes: 16 additions & 0 deletions cranelift/codegen/meta/src/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub fn get_isle_compilations(
// Directories for lowering backends.
let src_isa_x64 = codegen_crate_dir.join("src").join("isa").join("x64");
let src_isa_aarch64 = codegen_crate_dir.join("src").join("isa").join("aarch64");
let src_isa_arm32 = codegen_crate_dir.join("src").join("isa").join("arm32");
let src_isa_s390x = codegen_crate_dir.join("src").join("isa").join("s390x");
let src_isa_risc_v = codegen_crate_dir.join("src").join("isa").join("riscv64");
#[cfg(feature = "pulley")]
Expand Down Expand Up @@ -229,6 +230,21 @@ pub fn get_isle_compilations(
.concat(),
untracked_inputs: vec![numerics_isle.clone(), clif_lower_isle.clone()],
},
// The ARM32 instruction selector.
IsleCompilation {
name: "arm32".to_string(),
output: gen_dir.join("isle_arm32.rs"),
tracked_inputs: [
vec![prelude_isle.clone(), prelude_lower_isle.clone()],
spec_inputs(&[]),
vec![
src_isa_arm32.join("inst.isle"),
src_isa_arm32.join("lower.isle"),
],
]
.concat(),
untracked_inputs: vec![numerics_isle.clone(), clif_lower_isle.clone()],
},
// The s390x instruction selector.
IsleCompilation {
name: "s390x".to_string(),
Expand Down
Loading
Loading