Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
shallow = true
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/21.1-2025-08-01
url = https://github.com/fineg74/llvm-project.git
branch = l0RTL
shallow = true
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# the resulting rustc being unable to compile for the disabled architectures.
#
# To add support for new targets, see https://rustc-dev-guide.rust-lang.org/building/new-target.html.
#llvm.targets = "AArch64;AMDGPU;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
#llvm.targets = "AArch64;AMDGPU;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SPIRV;SystemZ;WebAssembly;X86"

# LLVM experimental targets to build support for. These targets are specified in
# the same format as above, but since these targets are experimental, they are
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
CanonAbi::GpuKernel => match &sess.target.arch {
Arch::AmdGpu => llvm::AmdgpuKernel,
Arch::Nvptx64 => llvm::PtxKernel,
Arch::SpirV => llvm::SpirKernel,
arch => panic!("Architecture {arch} does not support GpuKernel calling convention"),
},
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub(crate) enum CallConv {
Msp430Intr = 69,
X86_ThisCall = 70,
PtxKernel = 71,
SpirKernel = 76,
X86_64_SysV = 78,
X86_64_Win64 = 79,
X86_VectorCall = 80,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const OPTIONAL_COMPONENTS: &[&str] = &[
"csky",
"mips",
"powerpc",
"spirv",
"systemz",
"webassembly",
"msp430",
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ pub fn initialize_available_targets() {
LLVMInitializePowerPCAsmPrinter,
LLVMInitializePowerPCAsmParser
);
init_target!(
llvm_component = "spirv",
LLVMInitializeSPIRVTargetInfo,
LLVMInitializeSPIRVTarget,
LLVMInitializeSPIRVTargetMC,
LLVMInitializeSPIRVAsmPrinter
);
init_target!(
llvm_component = "systemz",
LLVMInitializeSystemZTargetInfo,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod riscv;
mod s390x;
mod sparc;
mod sparc64;
mod spirv;
mod wasm;
mod x86;
mod x86_64;
Expand Down Expand Up @@ -702,7 +703,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
Arch::RiscV32 | Arch::RiscV64 => riscv::compute_abi_info(cx, self),
Arch::Wasm32 | Arch::Wasm64 => wasm::compute_abi_info(cx, self),
Arch::Bpf => bpf::compute_abi_info(cx, self),
arch @ (Arch::SpirV | Arch::Other(_)) => {
Arch::SpirV => spirv::compute_abi_info(cx, self),
arch @ Arch::Other(_) => {
panic!("no lowering implemented for {arch}")
}
}
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_target/src/callconv/spirv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use rustc_abi::{HasDataLayout, TyAbiInterface};

use crate::callconv::{ArgAbi, FnAbi};

fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout,
{
ret.extend_integer_width_to(32);
}

fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout,
{
if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
arg.make_indirect();
return;
}
arg.extend_integer_width_to(32);
}

pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
}

for arg in fn_abi.args.iter_mut() {
if arg.is_ignore() {
continue;
}
classify_arg(cx, arg);
}
}
6 changes: 5 additions & 1 deletion compiler/rustc_target/src/spec/abi_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl AbiMap {
Arch::Msp430 => ArchKind::Msp430,
Arch::Nvptx64 => ArchKind::Nvptx,
Arch::RiscV32 | Arch::RiscV64 => ArchKind::Riscv,
Arch::SpirV => ArchKind::Spirv,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure I agree with SPIRV being SpirV in the Arch but let's be consistent here. The ArchKind::Riscv deviation was not an intentional choice, if memory serves.

Suggested change
Arch::SpirV => ArchKind::Spirv,
Arch::SpirV => ArchKind::SpirV,

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd go with Spirv everywhere then. But that'd have to be fixed in the "upstream" PR as well.

Arch::X86 => ArchKind::X86,
Arch::X86_64 => ArchKind::X86_64,
_ => ArchKind::Other,
Expand Down Expand Up @@ -131,7 +132,9 @@ impl AbiMap {

/* gpu */
(ExternAbi::PtxKernel, ArchKind::Nvptx) => CanonAbi::GpuKernel,
(ExternAbi::GpuKernel, ArchKind::Amdgpu | ArchKind::Nvptx) => CanonAbi::GpuKernel,
(ExternAbi::GpuKernel, ArchKind::Amdgpu | ArchKind::Nvptx | ArchKind::Spirv) => {
CanonAbi::GpuKernel
}
(ExternAbi::PtxKernel | ExternAbi::GpuKernel, _) => return AbiMapping::Invalid,

/* x86 */
Expand Down Expand Up @@ -203,6 +206,7 @@ enum ArchKind {
LoongArch,
Msp430,
Nvptx,
Spirv,
Riscv,
X86,
X86_64,
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,9 @@ supported_targets! {

("amdgcn-amd-amdhsa", amdgcn_amd_amdhsa),

("spirv64-intel-unknown", spirv64_intel_unknown),
("spirv-unknown-vulkan1.3", spirv_unknown_vulkan1_3),

("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
("xtensa-esp32-espidf", xtensa_esp32_espidf),
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
Expand Down Expand Up @@ -1995,6 +1998,7 @@ crate::target_spec_enum! {
VexOs = "vexos",
VisionOs = "visionos",
Vita = "vita",
Vulkan = "vulkan",
VxWorks = "vxworks",
Wasi = "wasi",
WatchOs = "watchos",
Expand Down Expand Up @@ -2919,8 +2923,8 @@ impl Target {
);
check_eq!(
self.is_like_gpu,
self.arch == Arch::Nvptx64 || self.arch == Arch::AmdGpu,
"`is_like_gpu` must be set if and only if `target` is `nvptx64` or `amdgcn`"
self.arch == Arch::AmdGpu || self.arch == Arch::Nvptx64 || self.arch == Arch::SpirV,
"`is_like_gpu` must be set if and only if `target` is `amdgcn`, `nvptx64`, or `spirv`"
);
check_eq!(
self.is_like_windows,
Expand Down Expand Up @@ -3271,6 +3275,7 @@ impl Target {
fn can_use_os_unknown(&self) -> bool {
self.llvm_target == "wasm32-unknown-unknown"
|| self.llvm_target == "wasm64-unknown-unknown"
|| self.llvm_target == "spirv64-intel-unknown"
|| (self.env == Env::Sgx && self.vendor == "fortanix")
}

Expand Down
36 changes: 36 additions & 0 deletions compiler/rustc_target/src/spec/targets/spirv64_intel_unknown.rs
Copy link
Member Author

@karolzwolak karolzwolak Jan 23, 2026

Choose a reason for hiding this comment

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

Will have to verify stuff in here, for now I just copied from the vulkan triple and changed the data layout.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::spec::{Arch, LinkerFlavor, Os, PanicStrategy, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
Target {
llvm_target: "spirv64-intel-unknown".into(),
metadata: TargetMetadata {
description: Some("SPIR-V with Intel GPU extensions".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 64,
data_layout: "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1-P9-A0".into(),
arch: Arch::SpirV,
options: TargetOptions {
os: Os::Unknown,
vendor: "intel".into(),
linker_flavor: LinkerFlavor::Llbc,
max_atomic_width: Some(32),
panic_strategy: PanicStrategy::Abort,
// Allow `cdylib` crate type.
dynamic_linking: true,
obj_is_bitcode: true,
only_cdylib: true,
dll_prefix: "".into(),
dll_suffix: ".spvt".into(),
is_like_gpu: true,
// The LLVM backend does not support stack canaries for this target
supports_stack_protector: false,

// Static initializers must not have cycles on this target
static_initializer_must_be_acyclic: true,
..Default::default()
},
}
}
36 changes: 36 additions & 0 deletions compiler/rustc_target/src/spec/targets/spirv_unknown_vulkan1_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::spec::{Arch, LinkerFlavor, Os, PanicStrategy, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
Target {
llvm_target: "spirv-unknown-vulkan1.3".into(),
metadata: TargetMetadata {
description: Some("Vulkan 1.3".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 64,
data_layout: "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G10".into(),
arch: Arch::SpirV,
options: TargetOptions {
os: Os::Vulkan,
vendor: "unknown".into(),
linker_flavor: LinkerFlavor::Llbc,
max_atomic_width: Some(32),
panic_strategy: PanicStrategy::Abort,
// Allow `cdylib` crate type.
dynamic_linking: true,
obj_is_bitcode: true,
only_cdylib: true,
dll_prefix: "".into(),
dll_suffix: ".spvt".into(),
is_like_gpu: true,
// The LLVM backend does not support stack canaries for this target
supports_stack_protector: false,

// Static initializers must not have cycles on this target
static_initializer_must_be_acyclic: true,
..Default::default()
},
}
}
3 changes: 2 additions & 1 deletion library/compiler-builtins/compiler-builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn main() {
|| (target.triple.contains("sgx") && target.triple.contains("fortanix"))
|| target.triple.contains("-none")
|| target.triple.contains("nvptx")
|| target.triple.contains("spirv")
|| target.triple.contains("uefi")
|| target.triple.contains("xous")
{
Expand Down Expand Up @@ -67,7 +68,7 @@ fn main() {
// Don't use a C compiler for these targets:
//
// * nvptx - everything is bitcode, not compatible with mixed C/Rust
if !target.arch.contains("nvptx") {
if !target.arch.contains("nvptx") && !target.arch.contains("spirv") {
#[cfg(feature = "c")]
c::compile(&llvm_target, &target);
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ffi/va_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ impl<'f> VaList<'f> {

// Checks (via an assert in `compiler/rustc_ty_utils/src/abi.rs`) that the C ABI for the current
// target correctly implements `rustc_pass_indirectly_in_non_rustic_abis`.
#[cfg(not(target_arch = "spirv"))]
Copy link
Member

Choose a reason for hiding this comment

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

I should comment on the "upstream" PR because this is present from there.

Copy link
Member Author

Choose a reason for hiding this comment

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

btw support for variadics in spirv functions landed recently llvm/llvm-project#175076

const _: () = {
#[repr(C)]
#[rustc_pass_indirectly_in_non_rustic_abis]
Expand Down
10 changes: 8 additions & 2 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl Step for Llvm {
Some(s) => s,
None => {
"AArch64;AMDGPU;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;\
Sparc;SystemZ;WebAssembly;X86"
Sparc;SPIRV;SystemZ;WebAssembly;X86"
}
};

Expand Down Expand Up @@ -1050,9 +1050,15 @@ impl Step for OmpOffload {
.profile(profile)
.env("LLVM_CONFIG_REAL", &host_llvm_config)
.define("LLVM_ENABLE_ASSERTIONS", "ON")
.define("LLVM_ENABLE_RUNTIMES", "openmp;offload")
.define("LLVM_ENABLE_RUNTIMES", "openmp;offload;libsycl")
.define("LLVM_RUNTIME_TARGETS", "spirv64-intel-unknown")
.define("LIBOMPTARGET_PLUGINS_TO_BUILD", "level_zero")
.define("RUNTIMES_spirv64-intel-unknown_LLVM_ENABLE_RUNTIMES", "openmp")
.define("LLVM_INCLUDE_TESTS", "OFF")
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
.define("CMAKE_C_COMPILER", "clang")
.define("CMAKE_CXX_COMPILER", "clang++")
.define("OFFLOAD_INCLUDE_TESTS", "OFF")
.define("OPENMP_STANDALONE_BUILD", "ON")
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
.define("LLVM_DIR", llvm_cmake_dir);
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ impl Cargo {
let target = self.target;
let compiler = self.compiler;

if target.contains("spirv") {
return self;
}

// Dealing with rpath here is a little special, so let's go into some
// detail. First off, `-rpath` is a linker option on Unix platforms
// which adds to the runtime dynamic loader path when looking for
Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
"thumbv7r-none-eabi",
"thumbv7r-none-eabihf",
"thumbv8r-none-eabihf",
"spirv-unknown-vulkan1.3",
"spirv64-intel-unknown",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down Expand Up @@ -249,6 +251,10 @@ than building it.
continue;
}

if target.contains("spirv") {
continue;
}

// skip check for cross-targets
if skip_target_sanity && target != &build.host_target {
continue;
Expand Down Expand Up @@ -357,7 +363,7 @@ than building it.
}
}

if (target.contains("-none-") || target.contains("nvptx"))
if (target.contains("-none-") || target.contains("nvptx") || target.contains("spirv"))
&& build.no_std(*target) == Some(false)
{
panic!("All the *-none-* and nvptx* targets are no-std targets")
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/utils/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ pub fn fill_target_compiler(build: &mut Build, target: TargetSelection) {
cfg.compiler(cc);
}

if target.contains("spirv") {
return;
}

let compiler = cfg.get_compiler();
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
ar
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub fn use_host_linker(target: TargetSelection) -> bool {
!(target.contains("emscripten")
|| target.contains("wasm32")
|| target.contains("nvptx")
|| target.contains("spirv")
|| target.contains("fortanix")
|| target.contains("fuchsia")
|| target.contains("bpf")
Expand Down
3 changes: 2 additions & 1 deletion src/build_helper/src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
pub fn target_supports_std(target_tuple: &str) -> bool {
!(target_tuple.contains("-none")
|| target_tuple.contains("nvptx")
|| target_tuple.contains("switch"))
|| target_tuple.contains("switch")
|| target_tuple.contains("spirv"))
}
3 changes: 2 additions & 1 deletion src/ci/docker/scripts/build-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set -ex
source shared.sh

# Try to keep the LLVM version here in sync with src/ci/scripts/install-clang.sh
LLVM=llvmorg-21.1.0-rc2
#LLVM=llvmorg-21.1.0-rc2
LLVM=9e78d8a4fb0739455ecdfd1751b347fbd7038c13

mkdir llvm-project
cd llvm-project
Expand Down
Loading
Loading