Skip to content

Commit db1fb85

Browse files
committed
Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiser
Add initial support for m68k This patch series adds initial support for m68k making use of the new M68k backend introduced with LLVM-13. Additional changes will be needed to be able to actually use the backend for this target.
2 parents e71925a + 5d22b1a commit db1fb85

File tree

18 files changed

+196
-2
lines changed

18 files changed

+196
-2
lines changed

compiler/rustc_llvm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn main() {
7676
"aarch64",
7777
"amdgpu",
7878
"avr",
79+
"m68k",
7980
"mips",
8081
"powerpc",
8182
"systemz",

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ void LLVMRustAddLastExtensionPasses(
201201
#define SUBTARGET_AVR
202202
#endif
203203

204+
#ifdef LLVM_COMPONENT_M68k
205+
#define SUBTARGET_M68K SUBTARGET(M68k)
206+
#else
207+
#define SUBTARGET_M68K
208+
#endif
209+
204210
#ifdef LLVM_COMPONENT_MIPS
205211
#define SUBTARGET_MIPS SUBTARGET(Mips)
206212
#else
@@ -248,6 +254,7 @@ void LLVMRustAddLastExtensionPasses(
248254
SUBTARGET_ARM \
249255
SUBTARGET_AARCH64 \
250256
SUBTARGET_AVR \
257+
SUBTARGET_M68K \
251258
SUBTARGET_MIPS \
252259
SUBTARGET_PPC \
253260
SUBTARGET_SYSTEMZ \

compiler/rustc_llvm/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ pub fn initialize_available_targets() {
9090
LLVMInitializeAVRAsmPrinter,
9191
LLVMInitializeAVRAsmParser
9292
);
93+
init_target!(
94+
llvm_component = "m68k",
95+
LLVMInitializeM68kTargetInfo,
96+
LLVMInitializeM68kTarget,
97+
LLVMInitializeM68kTargetMC,
98+
LLVMInitializeM68kAsmPrinter,
99+
LLVMInitializeM68kAsmParser
100+
);
93101
init_target!(
94102
llvm_component = "mips",
95103
LLVMInitializeMipsTargetInfo,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::abi::call::{ArgAbi, FnAbi};
2+
3+
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
4+
if ret.layout.is_aggregate() {
5+
ret.make_indirect();
6+
} else {
7+
ret.extend_integer_width_to(32);
8+
}
9+
}
10+
11+
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
12+
if arg.layout.is_aggregate() {
13+
arg.make_indirect_byval();
14+
} else {
15+
arg.extend_integer_width_to(32);
16+
}
17+
}
18+
19+
pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
20+
if !fn_abi.ret.is_ignore() {
21+
classify_ret(&mut fn_abi.ret);
22+
}
23+
24+
for arg in &mut fn_abi.args {
25+
if arg.is_ignore() {
26+
continue;
27+
}
28+
classify_arg(arg);
29+
}
30+
}

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod arm;
99
mod avr;
1010
mod bpf;
1111
mod hexagon;
12+
mod m68k;
1213
mod mips;
1314
mod mips64;
1415
mod msp430;
@@ -656,6 +657,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
656657
"amdgpu" => amdgpu::compute_abi_info(cx, self),
657658
"arm" => arm::compute_abi_info(cx, self),
658659
"avr" => avr::compute_abi_info(self),
660+
"m68k" => m68k::compute_abi_info(self),
659661
"mips" => mips::compute_abi_info(cx, self),
660662
"mips64" => mips64::compute_abi_info(cx, self),
661663
"powerpc" => powerpc::compute_abi_info(self),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let mut base = super::linux_base::opts();
6+
base.max_atomic_width = Some(32);
7+
8+
Target {
9+
llvm_target: "m68k-unknown-linux-gnu".to_string(),
10+
pointer_width: 32,
11+
data_layout: "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16".to_string(),
12+
arch: "m68k".to_string(),
13+
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base },
14+
}
15+
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ supported_targets! {
742742
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
743743
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
744744
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
745+
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
745746
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
746747
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),
747748
("mips64el-unknown-linux-gnuabi64", mips64el_unknown_linux_gnuabi64),

config.toml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ changelog-seen = 2
103103
# the same format as above, but since these targets are experimental, they are
104104
# not built by default and the experimental Rust compilation targets that depend
105105
# on them will not work unless the user opts in to building them.
106-
#experimental-targets = "AVR"
106+
#experimental-targets = "AVR;M68k"
107107

108108
# Cap the number of parallel linker invocations when compiling LLVM.
109109
# This can be useful when building LLVM with debug info, which significantly

library/std/src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ pub mod consts {
879879
/// - x86_64
880880
/// - arm
881881
/// - aarch64
882+
/// - m68k
882883
/// - mips
883884
/// - mips64
884885
/// - powerpc

library/std/src/os/linux/raw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
2727
#[cfg(any(
2828
target_arch = "x86",
2929
target_arch = "le32",
30+
target_arch = "m68k",
3031
target_arch = "powerpc",
3132
target_arch = "sparc",
3233
target_arch = "arm",

0 commit comments

Comments
 (0)