Skip to content

Add feature for future libgccjit 12 release #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2022
Merged
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
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "[email protected]"
Expand All @@ -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
Expand All @@ -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 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
23 changes: 13 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -e
codegen_channel=debug
sysroot_channel=debug

flags=

while [[ $# -gt 0 ]]; do
case $1 in
--release)
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn main() {

println!("{:?}", std::intrinsics::caller_location());

#[cfg(feature="master")]
unsafe {
test_simd();
}
Expand All @@ -104,6 +105,7 @@ fn main() {
println!("End");
}

#[cfg(feature="master")]
#[target_feature(enable = "sse2")]
unsafe fn test_simd() {
let x = _mm_setzero_si128();
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -202,25 +209,29 @@ 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 {
panic!("{:?} != {:?}", a, b);
}
}

#[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);
Expand All @@ -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]
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
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");
Expand Down Expand Up @@ -1287,6 +1296,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
}

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");

Expand Down Expand Up @@ -1361,6 +1371,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
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> {
Expand Down
14 changes: 14 additions & 0 deletions src/intrinsic/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ use gccjit::Function;

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",
Expand Down
4 changes: 4 additions & 0 deletions src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
));
}

#[cfg(feature="master")]
if name == sym::simd_insert {
require!(
in_elem == arg_tys[2],
Expand Down Expand Up @@ -213,6 +214,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
// 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,
Expand Down Expand Up @@ -503,6 +506,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
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();
Expand Down
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
.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);
Expand Down Expand Up @@ -217,6 +218,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
.collect();
typ.set_fields(None, &fields);
if packed {
#[cfg(feature="master")]
typ.as_type().set_packed();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
}

#[cfg(feature="master")]
pub fn type_int_from_ty(&self, t: ty::IntTy) -> Type<'gcc> {
match t {
ty::IntTy::Isize => self.type_isize(),
Expand All @@ -36,6 +37,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
}

#[cfg(feature="master")]
pub fn type_uint_from_ty(&self, t: ty::UintTy) -> Type<'gcc> {
match t {
ty::UintTy::Usize => self.type_isize(),
Expand Down
Loading