Merge commit '2e8386e9fb3506cef991d04f8b3bc78f9a0c2630' into subtree-update_cg_gcc_2023-11-17

This commit is contained in:
Antoni Boucher 2023-11-19 13:42:13 -05:00
parent a6493c1f65
commit 75fce09751
14 changed files with 104 additions and 41 deletions

View File

@ -99,8 +99,10 @@ jobs:
- name: Build - name: Build
run: | run: |
./y.sh prepare --only-libcore ./y.sh prepare --only-libcore
./y.sh build # TODO: remove --features master when it is back to the default.
cargo test ./y.sh build --features master
# TODO: remove --features master when it is back to the default.
cargo test --features master
./clean_all.sh ./clean_all.sh
- name: Prepare dependencies - name: Prepare dependencies
@ -121,7 +123,8 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
./test.sh --release --clean --build-sysroot ${{ matrix.commands }} # TODO: remove --features master when it is back to the default.
./test.sh --features master --release --clean --build-sysroot ${{ matrix.commands }}
duplicates: duplicates:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -21,11 +21,14 @@ jobs:
libgccjit_version: libgccjit_version:
- gcc: "libgccjit.so" - gcc: "libgccjit.so"
artifacts_branch: "master" artifacts_branch: "master"
# TODO: switch back to --no-default-features in the case of libgccjit 12 when the default is to enable
# master again.
extra: "--features master"
- gcc: "libgccjit_without_int128.so" - gcc: "libgccjit_without_int128.so"
artifacts_branch: "master-without-128bit-integers" artifacts_branch: "master-without-128bit-integers"
extra: "--features master"
- gcc: "libgccjit12.so" - gcc: "libgccjit12.so"
artifacts_branch: "gcc12" artifacts_branch: "gcc12"
extra: "--no-default-features"
# FIXME(antoyo): we need to set GCC_EXEC_PREFIX so that the linker can find the linker plugin. # FIXME(antoyo): we need to set GCC_EXEC_PREFIX so that the linker can find the linker plugin.
# Not sure why it's not found otherwise. # Not sure why it's not found otherwise.
env_extra: "TEST_FLAGS='-Cpanic=abort -Zpanic-abort-tests' GCC_EXEC_PREFIX=/usr/lib/gcc/" env_extra: "TEST_FLAGS='-Cpanic=abort -Zpanic-abort-tests' GCC_EXEC_PREFIX=/usr/lib/gcc/"

View File

@ -114,8 +114,10 @@ jobs:
- name: Build - name: Build
run: | run: |
./y.sh prepare --only-libcore --cross ./y.sh prepare --only-libcore --cross
./y.sh build --target-triple m68k-unknown-linux-gnu # TODO: remove --features master when it is back to the default.
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test ./y.sh build --target-triple m68k-unknown-linux-gnu --features master
# TODO: remove --features master when it is back to the default.
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test --features master
./clean_all.sh ./clean_all.sh
- name: Prepare dependencies - name: Prepare dependencies
@ -136,4 +138,5 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
./test.sh --release --clean --build-sysroot ${{ matrix.commands }} # TODO: remove --features master when it is back to the default.
./test.sh --release --features master --clean --build-sysroot ${{ matrix.commands }}

View File

@ -78,8 +78,10 @@ jobs:
- name: Build - name: Build
run: | run: |
./y.sh prepare --only-libcore ./y.sh prepare --only-libcore
EMBED_LTO_BITCODE=1 ./y.sh build --release --release-sysroot # TODO: remove --features master when it is back to the default.
cargo test EMBED_LTO_BITCODE=1 ./y.sh build --release --release-sysroot --features master
# TODO: remove --features master when it is back to the default.
cargo test --features master
./clean_all.sh ./clean_all.sh
- name: Prepare dependencies - name: Prepare dependencies
@ -102,4 +104,5 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
EMBED_LTO_BITCODE=1 ./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} # TODO: remove --features master when it is back to the default.
EMBED_LTO_BITCODE=1 ./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} --features master

View File

@ -92,8 +92,10 @@ jobs:
- name: Build - name: Build
run: | run: |
./y.sh prepare --only-libcore ./y.sh prepare --only-libcore
./y.sh build --release --release-sysroot # TODO: remove `--features master` when it is back to the default.
cargo test ./y.sh build --release --release-sysroot --features master
# TODO: remove --features master when it is back to the default.
cargo test --features master
- name: Clean - name: Clean
if: ${{ !matrix.cargo_runner }} if: ${{ !matrix.cargo_runner }}
@ -111,12 +113,14 @@ jobs:
uses: actions-rs/cargo@v1.0.3 uses: actions-rs/cargo@v1.0.3
with: with:
command: build command: build
args: --release # TODO: remove `--features master` when it is back to the default.
args: --release --features master
- name: Run tests - name: Run tests
if: ${{ !matrix.cargo_runner }} if: ${{ !matrix.cargo_runner }}
run: | run: |
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore # TODO: remove `--features master` when it is back to the default.
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore --features master
- name: Run stdarch tests - name: Run stdarch tests
if: ${{ !matrix.cargo_runner }} if: ${{ !matrix.cargo_runner }}

4
Cargo.lock generated
View File

@ -74,7 +74,7 @@ dependencies = [
[[package]] [[package]]
name = "gccjit" name = "gccjit"
version = "1.0.0" version = "1.0.0"
source = "git+https://github.com/antoyo/gccjit.rs#c52a218f5529321285b4489e5562a00e5428e033" source = "git+https://github.com/antoyo/gccjit.rs#6e290f25b1d1edab5ae9ace486fd2dc8c08d6421"
dependencies = [ dependencies = [
"gccjit_sys", "gccjit_sys",
] ]
@ -82,7 +82,7 @@ dependencies = [
[[package]] [[package]]
name = "gccjit_sys" name = "gccjit_sys"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/antoyo/gccjit.rs#c52a218f5529321285b4489e5562a00e5428e033" source = "git+https://github.com/antoyo/gccjit.rs#6e290f25b1d1edab5ae9ace486fd2dc8c08d6421"
dependencies = [ dependencies = [
"libc", "libc",
] ]

View File

@ -28,3 +28,7 @@ fi
# Copy files to sysroot # Copy files to sysroot
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/ mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/ cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
# Copy the source files to the sysroot (Rust for Linux needs this).
source_dir=sysroot/lib/rustlib/src/rust
mkdir -p $source_dir
cp -r sysroot_src/library/ $source_dir

View File

@ -194,6 +194,12 @@ fn build_sysroot(
copier, copier,
)?; )?;
// Copy the source files to the sysroot (Rust for Linux needs this).
let sysroot_src_path = "sysroot/lib/rustlib/src/rust";
fs::create_dir_all(&sysroot_src_path)
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_src_path, error))?;
run_command(&[&"cp", &"-r", &"sysroot_src/library/", &sysroot_src_path], None)?;
Ok(()) Ok(())
} }

View File

@ -38,3 +38,5 @@ tests/ui/target-feature/missing-plusminus.rs
tests/ui/sse2.rs tests/ui/sse2.rs
tests/ui/codegen/issue-79865-llvm-miscompile.rs tests/ui/codegen/issue-79865-llvm-miscompile.rs
tests/ui/intrinsics/intrinsics-integer.rs tests/ui/intrinsics/intrinsics-integer.rs
tests/ui/std-backtrace.rs
tests/ui/mir/alignment/packed.rs

View File

@ -1,6 +1,6 @@
From 7bcd24ec6d4a96121874cb1ae5a23ea274aeff34 Mon Sep 17 00:00:00 2001 From a5663265f797a43c502915c356fe7899c16cee92 Mon Sep 17 00:00:00 2001
From: None <none@example.com> From: None <none@example.com>
Date: Thu, 19 Oct 2023 13:12:51 -0400 Date: Sat, 18 Nov 2023 10:50:36 -0500
Subject: [PATCH] [core] Disable portable-simd test Subject: [PATCH] [core] Disable portable-simd test
--- ---
@ -8,18 +8,18 @@ Subject: [PATCH] [core] Disable portable-simd test
1 file changed, 2 deletions(-) 1 file changed, 2 deletions(-)
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 5814ed4..194ad4c 100644 index d0a119c..76fdece 100644
--- a/library/core/tests/lib.rs --- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs
@@ -90,7 +90,6 @@ @@ -89,7 +89,6 @@
#![feature(never_type)]
#![feature(unwrap_infallible)] #![feature(unwrap_infallible)]
#![feature(pointer_byte_offsets)]
#![feature(pointer_is_aligned)] #![feature(pointer_is_aligned)]
-#![feature(portable_simd)] -#![feature(portable_simd)]
#![feature(ptr_metadata)] #![feature(ptr_metadata)]
#![feature(lazy_cell)] #![feature(lazy_cell)]
#![feature(unsized_tuple_coercion)] #![feature(unsized_tuple_coercion)]
@@ -157,7 +156,6 @@ mod pin; @@ -155,7 +154,6 @@ mod pin;
mod pin_macro; mod pin_macro;
mod ptr; mod ptr;
mod result; mod result;
@ -28,5 +28,5 @@ index 5814ed4..194ad4c 100644
mod str; mod str;
mod str_lossy; mod str_lossy;
-- --
2.42.0 2.42.1

View File

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "nightly-2023-10-21" channel = "nightly-2023-11-17"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"] components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

View File

@ -3,7 +3,6 @@ use std::env;
use std::time::Instant; use std::time::Instant;
use gccjit::{ use gccjit::{
Context,
FunctionType, FunctionType,
GlobalKind, GlobalKind,
}; };
@ -18,8 +17,9 @@ use rustc_codegen_ssa::mono_item::MonoItemExt;
use rustc_codegen_ssa::traits::DebugInfoMethods; use rustc_codegen_ssa::traits::DebugInfoMethods;
use rustc_session::config::DebugInfo; use rustc_session::config::DebugInfo;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::PanicStrategy;
use crate::{LockedTargetInfo, gcc_util}; use crate::{LockedTargetInfo, gcc_util, new_context};
use crate::GccContext; use crate::GccContext;
use crate::builder::Builder; use crate::builder::Builder;
use crate::context::CodegenCx; use crate::context::CodegenCx;
@ -88,20 +88,18 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, target_info): (Symbol, LockedTargetInfo)) -> ModuleCodegen<GccContext> { fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, target_info): (Symbol, LockedTargetInfo)) -> ModuleCodegen<GccContext> {
let cgu = tcx.codegen_unit(cgu_name); let cgu = tcx.codegen_unit(cgu_name);
// Instantiate monomorphizations without filling out definitions yet... // Instantiate monomorphizations without filling out definitions yet...
let context = Context::default(); let context = new_context(&tcx);
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
context.add_command_line_option("-fexceptions"); context.add_command_line_option("-fexceptions");
context.add_driver_option("-fexceptions"); context.add_driver_option("-fexceptions");
}
let disabled_features: HashSet<_> = tcx.sess.opts.cg.target_feature.split(',') let disabled_features: HashSet<_> = tcx.sess.opts.cg.target_feature.split(',')
.filter(|feature| feature.starts_with('-')) .filter(|feature| feature.starts_with('-'))
.map(|string| &string[1..]) .map(|string| &string[1..])
.collect(); .collect();
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
context.add_command_line_option("-masm=intel");
}
if !disabled_features.contains("avx") && tcx.sess.target.arch == "x86_64" { if !disabled_features.contains("avx") && tcx.sess.target.arch == "x86_64" {
// NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for // NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for
// SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead. // SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead.

View File

@ -76,6 +76,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
a >> b a >> b
} }
} }
else if a_type.is_vector() && a_type.is_vector() {
a >> b
}
else if a_native && !b_native { else if a_native && !b_native {
self.gcc_lshr(a, self.gcc_int_cast(b, a_type)) self.gcc_lshr(a, self.gcc_int_cast(b, a_type))
} }
@ -144,7 +147,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
fn additive_operation(&self, operation: BinaryOp, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> { fn additive_operation(&self, operation: BinaryOp, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> {
let a_type = a.get_type(); let a_type = a.get_type();
let b_type = b.get_type(); let b_type = b.get_type();
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) { if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)) || (a_type.is_vector() && b_type.is_vector()) {
if a_type != b_type { if a_type != b_type {
if a_type.is_vector() { if a_type.is_vector() {
// Vector types need to be bitcast. // Vector types need to be bitcast.
@ -158,6 +161,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
self.context.new_binary_op(None, operation, a_type, a, b) self.context.new_binary_op(None, operation, a_type, a, b)
} }
else { else {
debug_assert!(a_type.dyncast_array().is_some());
debug_assert!(b_type.dyncast_array().is_some());
let signed = a_type.is_compatible_with(self.i128_type); let signed = a_type.is_compatible_with(self.i128_type);
let func_name = let func_name =
match (operation, signed) { match (operation, signed) {
@ -189,10 +194,12 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
fn multiplicative_operation(&self, operation: BinaryOp, operation_name: &str, signed: bool, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> { fn multiplicative_operation(&self, operation: BinaryOp, operation_name: &str, signed: bool, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
let a_type = a.get_type(); let a_type = a.get_type();
let b_type = b.get_type(); let b_type = b.get_type();
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) { if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)) || (a_type.is_vector() && b_type.is_vector()) {
self.context.new_binary_op(None, operation, a_type, a, b) self.context.new_binary_op(None, operation, a_type, a, b)
} }
else { else {
debug_assert!(a_type.dyncast_array().is_some());
debug_assert!(b_type.dyncast_array().is_some());
let sign = let sign =
if signed { if signed {
"" ""
@ -337,6 +344,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
pub fn operation_with_overflow(&self, func_name: &str, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) { pub fn operation_with_overflow(&self, func_name: &str, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
let a_type = lhs.get_type(); let a_type = lhs.get_type();
let b_type = rhs.get_type(); let b_type = rhs.get_type();
debug_assert!(a_type.dyncast_array().is_some());
debug_assert!(b_type.dyncast_array().is_some());
let param_a = self.context.new_parameter(None, a_type, "a"); let param_a = self.context.new_parameter(None, a_type, "a");
let param_b = self.context.new_parameter(None, b_type, "b"); let param_b = self.context.new_parameter(None, b_type, "b");
let result_field = self.context.new_field(None, a_type, "result"); let result_field = self.context.new_field(None, a_type, "result");
@ -496,7 +505,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
pub fn gcc_xor(&self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> { pub fn gcc_xor(&self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
let a_type = a.get_type(); let a_type = a.get_type();
let b_type = b.get_type(); let b_type = b.get_type();
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) { if a_type.is_vector() && b_type.is_vector() {
let b = self.bitcast_if_needed(b, a_type);
a ^ b
}
else if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
a ^ b a ^ b
} }
else { else {
@ -527,6 +540,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
a << b a << b
} }
} }
else if a_type.is_vector() && a_type.is_vector() {
a << b
}
else if a_native && !b_native { else if a_native && !b_native {
self.gcc_shl(a, self.gcc_int_cast(b, a_type)) self.gcc_shl(a, self.gcc_int_cast(b, a_type))
} }
@ -690,6 +706,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let a_native = self.is_native_int_type_or_bool(a_type); let a_native = self.is_native_int_type_or_bool(a_type);
let b_native = self.is_native_int_type_or_bool(b_type); let b_native = self.is_native_int_type_or_bool(b_type);
if a_type.is_vector() && b_type.is_vector() { if a_type.is_vector() && b_type.is_vector() {
let b = self.bitcast_if_needed(b, a_type);
self.context.new_binary_op(None, operation, a_type, a, b) self.context.new_binary_op(None, operation, a_type, a, b)
} }
else if a_native && b_native { else if a_native && b_native {
@ -748,6 +765,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
return self.context.new_cast(None, value, dest_typ); return self.context.new_cast(None, value, dest_typ);
} }
debug_assert!(value_type.dyncast_array().is_some());
let name_suffix = let name_suffix =
match self.type_kind(dest_typ) { match self.type_kind(dest_typ) {
TypeKind::Float => "tisf", TypeKind::Float => "tisf",
@ -781,6 +799,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
return self.context.new_cast(None, value, dest_typ); return self.context.new_cast(None, value, dest_typ);
} }
debug_assert!(value_type.dyncast_array().is_some());
let name_suffix = let name_suffix =
match self.type_kind(value_type) { match self.type_kind(value_type) {
TypeKind::Float => "sfti", TypeKind::Float => "sfti",

View File

@ -39,6 +39,8 @@ extern crate rustc_errors;
extern crate rustc_fluent_macro; extern crate rustc_fluent_macro;
extern crate rustc_fs_util; extern crate rustc_fs_util;
extern crate rustc_hir; extern crate rustc_hir;
#[cfg(feature="master")]
extern crate rustc_interface;
extern crate rustc_macros; extern crate rustc_macros;
extern crate rustc_metadata; extern crate rustc_metadata;
extern crate rustc_middle; extern crate rustc_middle;
@ -86,7 +88,7 @@ use std::sync::atomic::Ordering;
use gccjit::{Context, OptimizationLevel}; use gccjit::{Context, OptimizationLevel};
#[cfg(feature="master")] #[cfg(feature="master")]
use gccjit::TargetInfo; use gccjit::{TargetInfo, Version};
#[cfg(not(feature="master"))] #[cfg(not(feature="master"))]
use gccjit::CType; use gccjit::CType;
use errors::LTONotSupported; use errors::LTONotSupported;
@ -244,17 +246,33 @@ impl CodegenBackend for GccCodegenBackend {
} }
} }
fn new_context<'gcc, 'tcx>(tcx: &TyCtxt<'tcx>) -> Context<'gcc> {
let context = Context::default();
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
context.add_command_line_option("-masm=intel");
}
#[cfg(feature="master")]
{
let version = Version::get();
let version = format!("{}.{}.{}", version.major, version.minor, version.patch);
context.set_output_ident(&format!("rustc version {} with libgccjit {}",
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
version,
));
}
// TODO(antoyo): check if this should only be added when using -Cforce-unwind-tables=n.
context.add_command_line_option("-fno-asynchronous-unwind-tables");
context
}
impl ExtraBackendMethods for GccCodegenBackend { impl ExtraBackendMethods for GccCodegenBackend {
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module { fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module {
let mut mods = GccContext { let mut mods = GccContext {
context: Context::default(), context: new_context(&tcx),
should_combine_object_files: false, should_combine_object_files: false,
temp_dir: None, temp_dir: None,
}; };
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
mods.context.add_command_line_option("-masm=intel");
}
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); } unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
mods mods
} }