Add feature for future libgccjit 12 release
This commit is contained in:
parent
d69ada6bf3
commit
4d7de81199
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]
|
||||
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so", "libgccjit12.so"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -78,12 +78,21 @@ jobs:
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
|
||||
|
||||
- name: Build
|
||||
if: matrix.libgccjit_version != 'libgccjit12.so'
|
||||
run: |
|
||||
./prepare_build.sh
|
||||
./build.sh
|
||||
cargo test
|
||||
./clean_all.sh
|
||||
|
||||
- name: Build
|
||||
if: matrix.libgccjit_version == 'libgccjit12.so'
|
||||
run: |
|
||||
./prepare_build.sh
|
||||
./build.sh --no-default-features
|
||||
cargo test --no-default-features
|
||||
./clean_all.sh
|
||||
|
||||
- name: Prepare dependencies
|
||||
run: |
|
||||
git config --global user.email "user@example.com"
|
||||
@ -98,6 +107,7 @@ jobs:
|
||||
args: --release
|
||||
|
||||
- name: Test
|
||||
if: matrix.libgccjit_version != 'libgccjit12.so'
|
||||
run: |
|
||||
# Enable backtraces for easier debugging
|
||||
export RUST_BACKTRACE=1
|
||||
@ -107,3 +117,15 @@ jobs:
|
||||
export RUN_RUNS=2
|
||||
|
||||
./test.sh --release
|
||||
|
||||
- name: Test
|
||||
if: matrix.libgccjit_version == 'libgccjit12.so'
|
||||
run: |
|
||||
# Enable backtraces for easier debugging
|
||||
export RUST_BACKTRACE=1
|
||||
|
||||
# Reduce amount of benchmark runs as they are slow
|
||||
export COMPILE_RUNS=2
|
||||
export RUN_RUNS=2
|
||||
|
||||
./test.sh --release --no-default-features
|
||||
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -41,7 +41,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gccjit"
|
||||
version = "1.0.0"
|
||||
source = "git+https://github.com/antoyo/gccjit.rs#f24e1f49d99430941d8a747275b41c9a7930e049"
|
||||
source = "git+https://github.com/antoyo/gccjit.rs#6c2af0cf733a26740f01a7c679afc20431165a54"
|
||||
dependencies = [
|
||||
"gccjit_sys",
|
||||
]
|
||||
@ -49,7 +49,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gccjit_sys"
|
||||
version = "0.0.1"
|
||||
source = "git+https://github.com/antoyo/gccjit.rs#f24e1f49d99430941d8a747275b41c9a7930e049"
|
||||
source = "git+https://github.com/antoyo/gccjit.rs#6c2af0cf733a26740f01a7c679afc20431165a54"
|
||||
dependencies = [
|
||||
"libc 0.1.12",
|
||||
]
|
||||
|
@ -13,6 +13,10 @@ name = "lang_tests"
|
||||
path = "tests/lib.rs"
|
||||
harness = false
|
||||
|
||||
[features]
|
||||
default = ["master"]
|
||||
master = ["gccjit/master"]
|
||||
|
||||
[dependencies]
|
||||
gccjit = { git = "https://github.com/antoyo/gccjit.rs" }
|
||||
|
||||
|
23
build.sh
23
build.sh
@ -6,6 +6,8 @@ set -e
|
||||
codegen_channel=debug
|
||||
sysroot_channel=debug
|
||||
|
||||
flags=
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--release)
|
||||
@ -16,6 +18,15 @@ while [[ $# -gt 0 ]]; do
|
||||
sysroot_channel=release
|
||||
shift
|
||||
;;
|
||||
--no-default-features)
|
||||
flags="$flags --no-default-features"
|
||||
shift
|
||||
;;
|
||||
--features)
|
||||
shift
|
||||
flags="$flags --features $1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
@ -33,21 +44,13 @@ fi
|
||||
export LD_LIBRARY_PATH="$GCC_PATH"
|
||||
export LIBRARY_PATH="$GCC_PATH"
|
||||
|
||||
features=
|
||||
|
||||
if [[ "$1" == "--features" ]]; then
|
||||
shift
|
||||
features="--features $1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$codegen_channel" == "release" ]]; then
|
||||
export CHANNEL='release'
|
||||
CARGO_INCREMENTAL=1 cargo rustc --release $features
|
||||
CARGO_INCREMENTAL=1 cargo rustc --release $flags
|
||||
else
|
||||
echo $LD_LIBRARY_PATH
|
||||
export CHANNEL='debug'
|
||||
cargo rustc $features
|
||||
cargo rustc $flags
|
||||
fi
|
||||
|
||||
source config.sh
|
||||
|
@ -93,6 +93,7 @@ fn main() {
|
||||
|
||||
println!("{:?}", std::intrinsics::caller_location());
|
||||
|
||||
#[cfg(feature="master")]
|
||||
unsafe {
|
||||
test_simd();
|
||||
}
|
||||
@ -104,6 +105,7 @@ fn main() {
|
||||
println!("End");
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_simd() {
|
||||
let x = _mm_setzero_si128();
|
||||
@ -131,6 +133,7 @@ unsafe fn test_simd() {
|
||||
assert_eq!(mask1, 1);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_slli_si128() {
|
||||
#[rustfmt::skip]
|
||||
@ -158,6 +161,7 @@ unsafe fn test_mm_slli_si128() {
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_movemask_epi8() {
|
||||
#[rustfmt::skip]
|
||||
@ -171,6 +175,7 @@ unsafe fn test_mm_movemask_epi8() {
|
||||
assert_eq!(r, 0b10100100_00100101);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "avx2")]
|
||||
unsafe fn test_mm256_movemask_epi8() {
|
||||
let a = _mm256_set1_epi8(-1);
|
||||
@ -179,6 +184,7 @@ unsafe fn test_mm256_movemask_epi8() {
|
||||
assert_eq!(r, e);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_add_epi8() {
|
||||
let a = _mm_setr_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
@ -194,6 +200,7 @@ unsafe fn test_mm_add_epi8() {
|
||||
assert_eq_m128i(r, e);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_add_pd() {
|
||||
let a = _mm_setr_pd(1.0, 2.0);
|
||||
@ -202,12 +209,14 @@ unsafe fn test_mm_add_pd() {
|
||||
assert_eq_m128d(r, _mm_setr_pd(6.0, 12.0));
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
fn assert_eq_m128i(x: std::arch::x86_64::__m128i, y: std::arch::x86_64::__m128i) {
|
||||
unsafe {
|
||||
assert_eq!(std::mem::transmute::<_, [u8; 16]>(x), std::mem::transmute::<_, [u8; 16]>(y));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
|
||||
if _mm_movemask_pd(_mm_cmpeq_pd(a, b)) != 0b11 {
|
||||
@ -215,12 +224,14 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_cvtsi128_si64() {
|
||||
let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0]));
|
||||
assert_eq!(r, 5);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse4.1")]
|
||||
unsafe fn test_mm_cvtepi8_epi16() {
|
||||
let a = _mm_set1_epi8(10);
|
||||
@ -233,6 +244,7 @@ unsafe fn test_mm_cvtepi8_epi16() {
|
||||
assert_eq_m128i(r, e);
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
#[target_feature(enable = "sse4.1")]
|
||||
unsafe fn test_mm_extract_epi8() {
|
||||
#[rustfmt::skip]
|
||||
@ -246,7 +258,7 @@ unsafe fn test_mm_extract_epi8() {
|
||||
assert_eq!(r2, 3);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[cfg(all(feature="master", target_arch = "x86_64"))]
|
||||
#[target_feature(enable = "sse2")]
|
||||
unsafe fn test_mm_insert_epi16() {
|
||||
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
|
@ -301,6 +301,15 @@ fn function_ptr_call(&mut self, func_ptr: RValue<'gcc>, args: &[RValue<'gcc>], _
|
||||
result.to_rvalue()
|
||||
}
|
||||
else {
|
||||
#[cfg(not(feature="master"))]
|
||||
if gcc_func.get_param_count() == 0 {
|
||||
// FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
|
||||
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &[]));
|
||||
}
|
||||
else {
|
||||
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
|
||||
}
|
||||
#[cfg(feature="master")]
|
||||
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
|
||||
// Return dummy value when not having return value.
|
||||
let result = current_func.new_local(None, self.isize_type, "dummyValueThatShouldNeverBeUsed");
|
||||
@ -1287,6 +1296,7 @@ fn instrprof_increment(&mut self, _fn_name: RValue<'gcc>, _hash: RValue<'gcc>, _
|
||||
}
|
||||
|
||||
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
|
||||
#[cfg(feature="master")]
|
||||
pub fn shuffle_vector(&mut self, v1: RValue<'gcc>, v2: RValue<'gcc>, mask: RValue<'gcc>) -> RValue<'gcc> {
|
||||
let struct_type = mask.get_type().is_struct().expect("mask of struct type");
|
||||
|
||||
@ -1361,6 +1371,11 @@ pub fn shuffle_vector(&mut self, v1: RValue<'gcc>, v2: RValue<'gcc>, mask: RValu
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature="master"))]
|
||||
pub fn shuffle_vector(&mut self, _v1: RValue<'gcc>, _v2: RValue<'gcc>, _mask: RValue<'gcc>) -> RValue<'gcc> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcc, 'tcx> StaticBuilderMethods for Builder<'a, 'gcc, 'tcx> {
|
||||
|
@ -2,6 +2,20 @@
|
||||
|
||||
use crate::context::CodegenCx;
|
||||
|
||||
#[cfg(not(feature="master"))]
|
||||
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
|
||||
match name {
|
||||
"llvm.x86.xgetbv" => {
|
||||
let gcc_name = "__builtin_trap";
|
||||
let func = cx.context.get_builtin_function(gcc_name);
|
||||
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
|
||||
return func;
|
||||
},
|
||||
_ => unimplemented!("unsupported LLVM intrinsic {}", name),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
|
||||
let gcc_name = match name {
|
||||
"llvm.x86.xgetbv" => "__builtin_ia32_xgetbv",
|
||||
|
@ -154,6 +154,7 @@ macro_rules! require_simd {
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
if name == sym::simd_insert {
|
||||
require!(
|
||||
in_elem == arg_tys[2],
|
||||
@ -213,6 +214,8 @@ macro_rules! require_simd {
|
||||
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
|
||||
return Ok(bx.context.new_bitcast(None, result, vector.get_type()));
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
if name == sym::simd_extract {
|
||||
require!(
|
||||
ret_ty == in_elem,
|
||||
@ -503,6 +506,7 @@ macro_rules! arith_unary {
|
||||
simd_neg: Int => neg, Float => fneg;
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
|
||||
let lhs = args[0].immediate();
|
||||
let rhs = args[1].immediate();
|
||||
|
11
src/lib.rs
11
src/lib.rs
@ -299,10 +299,17 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
|
||||
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
|
||||
},
|
||||
)
|
||||
.filter(|feature| {
|
||||
.filter(|_feature| {
|
||||
// TODO(antoyo): implement a way to get enabled feature in libgccjit.
|
||||
// Probably using the equivalent of __builtin_cpu_supports.
|
||||
feature.contains("sse") || feature.contains("avx")
|
||||
#[cfg(feature="master")]
|
||||
{
|
||||
_feature.contains("sse") || _feature.contains("avx")
|
||||
}
|
||||
#[cfg(not(feature="master"))]
|
||||
{
|
||||
false
|
||||
}
|
||||
/*
|
||||
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512gfni,
|
||||
avx512ifma, avx512pf, avx512vaes, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpclmulqdq,
|
||||
|
@ -125,6 +125,7 @@ fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
|
||||
.collect();
|
||||
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
|
||||
if packed {
|
||||
#[cfg(feature="master")]
|
||||
typ.set_packed();
|
||||
}
|
||||
self.struct_types.borrow_mut().insert(types, typ);
|
||||
@ -217,6 +218,7 @@ pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed:
|
||||
.collect();
|
||||
typ.set_fields(None, &fields);
|
||||
if packed {
|
||||
#[cfg(feature="master")]
|
||||
typ.as_type().set_packed();
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ fn type_from_unsigned_integer(&self, i: Integer) -> Type<'gcc> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
pub fn type_int_from_ty(&self, t: ty::IntTy) -> Type<'gcc> {
|
||||
match t {
|
||||
ty::IntTy::Isize => self.type_isize(),
|
||||
@ -36,6 +37,7 @@ pub fn type_int_from_ty(&self, t: ty::IntTy) -> Type<'gcc> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="master")]
|
||||
pub fn type_uint_from_ty(&self, t: ty::UintTy) -> Type<'gcc> {
|
||||
match t {
|
||||
ty::UintTy::Usize => self.type_isize(),
|
||||
|
129
test.sh
129
test.sh
@ -14,22 +14,79 @@ fi
|
||||
export LD_LIBRARY_PATH="$GCC_PATH"
|
||||
export LIBRARY_PATH="$GCC_PATH"
|
||||
|
||||
features=
|
||||
flags=
|
||||
gcc_master_branch=1
|
||||
channel="debug"
|
||||
func=all
|
||||
|
||||
if [[ "$1" == "--features" ]]; then
|
||||
shift
|
||||
features="--features $1"
|
||||
shift
|
||||
fi
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--release)
|
||||
codegen_channel=release
|
||||
shift
|
||||
;;
|
||||
--release-sysroot)
|
||||
sysroot_channel=release
|
||||
shift
|
||||
;;
|
||||
--no-default-features)
|
||||
gcc_master_branch=0
|
||||
flags="$flags --no-default-features"
|
||||
shift
|
||||
;;
|
||||
--features)
|
||||
shift
|
||||
flags="$flags --features $1"
|
||||
shift
|
||||
;;
|
||||
--release)
|
||||
channel="release"
|
||||
shift
|
||||
;;
|
||||
"--test-rustc")
|
||||
func=test_rustc
|
||||
shift
|
||||
;;
|
||||
|
||||
if [[ "$1" == "--release" ]]; then
|
||||
"--test-libcore")
|
||||
func=test_libcore
|
||||
shift
|
||||
;;
|
||||
|
||||
"--clean-ui-tests")
|
||||
func=clean_ui_tests
|
||||
shift
|
||||
;;
|
||||
|
||||
"--std-tests")
|
||||
func=std_tests
|
||||
shift
|
||||
;;
|
||||
|
||||
"--extended-tests")
|
||||
func=extended_sysroot_tests
|
||||
shift
|
||||
;;
|
||||
|
||||
"--build-sysroot")
|
||||
func=build_sysroot
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $channel == "release" ]]; then
|
||||
export CHANNEL='release'
|
||||
CARGO_INCREMENTAL=1 cargo rustc --release $features
|
||||
CARGO_INCREMENTAL=1 cargo rustc --release $flags
|
||||
shift
|
||||
else
|
||||
echo $LD_LIBRARY_PATH
|
||||
export CHANNEL='debug'
|
||||
cargo rustc $features
|
||||
cargo rustc $flags
|
||||
fi
|
||||
|
||||
if [[ "$1" == "--build" ]]; then
|
||||
@ -78,7 +135,11 @@ function std_tests() {
|
||||
$RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
|
||||
|
||||
echo "[AOT] std_example"
|
||||
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE
|
||||
std_flags="--cfg feature=\"master\""
|
||||
if (( $gcc_master_branch == 0 )); then
|
||||
std_flags=""
|
||||
fi
|
||||
$RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE $std_flags
|
||||
$RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE
|
||||
|
||||
echo "[AOT] subslice-patterns-const-eval"
|
||||
@ -122,6 +183,10 @@ function test_libcore() {
|
||||
#hyperfine --runs ${RUN_RUNS:-10} ./target/out/mod_bench{,_inline} ./target/out/mod_bench_llvm_*
|
||||
|
||||
function extended_sysroot_tests() {
|
||||
if (( $gcc_master_branch == 0 )); then
|
||||
return
|
||||
fi
|
||||
|
||||
pushd rand
|
||||
cargo clean
|
||||
echo "[TEST] rust-random/rand"
|
||||
@ -208,38 +273,14 @@ function clean_ui_tests() {
|
||||
find rust/build/x86_64-unknown-linux-gnu/test/ui/ -name stamp -exec rm -rf {} \;
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"--test-rustc")
|
||||
test_rustc
|
||||
;;
|
||||
function all() {
|
||||
clean
|
||||
mini_tests
|
||||
build_sysroot
|
||||
std_tests
|
||||
test_libcore
|
||||
extended_sysroot_tests
|
||||
test_rustc
|
||||
}
|
||||
|
||||
"--test-libcore")
|
||||
test_libcore
|
||||
;;
|
||||
|
||||
"--clean-ui-tests")
|
||||
clean_ui_tests
|
||||
;;
|
||||
|
||||
"--std-tests")
|
||||
std_tests
|
||||
;;
|
||||
|
||||
"--extended-tests")
|
||||
extended_sysroot_tests
|
||||
;;
|
||||
|
||||
"--build-sysroot")
|
||||
build_sysroot
|
||||
;;
|
||||
|
||||
*)
|
||||
clean
|
||||
mini_tests
|
||||
build_sysroot
|
||||
std_tests
|
||||
test_libcore
|
||||
extended_sysroot_tests
|
||||
test_rustc
|
||||
;;
|
||||
esac
|
||||
$func
|
||||
|
Loading…
Reference in New Issue
Block a user