about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml24
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml4
-rwxr-xr-xbuild.sh23
-rw-r--r--example/std_example.rs14
-rw-r--r--src/builder.rs15
-rw-r--r--src/intrinsic/llvm.rs14
-rw-r--r--src/intrinsic/simd.rs4
-rw-r--r--src/lib.rs11
-rw-r--r--src/type_.rs2
-rw-r--r--src/type_of.rs2
-rwxr-xr-xtest.sh135
12 files changed, 189 insertions, 63 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 337837c40bf..8ebdabe8261 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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
diff --git a/Cargo.lock b/Cargo.lock
index f66c9874269..c5315e2392e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index 21f0bfbf69d..86278b46983 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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" }
 
diff --git a/build.sh b/build.sh
index 230ab7b6d42..44eb240715c 100755
--- a/build.sh
+++ b/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
diff --git a/example/std_example.rs b/example/std_example.rs
index 722666f7e16..31069058aea 100644
--- a/example/std_example.rs
+++ b/example/std_example.rs
@@ -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);
diff --git a/src/builder.rs b/src/builder.rs
index a4616d8673e..6f24abaea8a 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -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");
@@ -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");
 
@@ -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> {
diff --git a/src/intrinsic/llvm.rs b/src/intrinsic/llvm.rs
index bc8e99428ed..4b41b0ba6e7 100644
--- a/src/intrinsic/llvm.rs
+++ b/src/intrinsic/llvm.rs
@@ -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",
diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs
index b8c6038896d..f1167bc3a3b 100644
--- a/src/intrinsic/simd.rs
+++ b/src/intrinsic/simd.rs
@@ -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],
@@ -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,
@@ -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();
diff --git a/src/lib.rs b/src/lib.rs
index a8029f0425a..31d3a5ab299 100644
--- a/src/lib.rs
+++ b/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,
diff --git a/src/type_.rs b/src/type_.rs
index d65649ecfa3..db2b5ea8ab2 100644
--- a/src/type_.rs
+++ b/src/type_.rs
@@ -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);
@@ -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();
         }
     }
diff --git a/src/type_of.rs b/src/type_of.rs
index c6d6f91a742..adcae9c16c3 100644
--- a/src/type_of.rs
+++ b/src/type_of.rs
@@ -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(),
@@ -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(),
diff --git a/test.sh b/test.sh
index 1d2fbd0a24c..5a8e4f9c0ad 100755
--- a/test.sh
+++ b/test.sh
@@ -14,22 +14,79 @@ fi
 export LD_LIBRARY_PATH="$GCC_PATH"
 export LIBRARY_PATH="$GCC_PATH"
 
-features=
-
-if [[ "$1" == "--features" ]]; then
-    shift
-    features="--features $1"
-    shift
-fi
-
-if [[ "$1" == "--release" ]]; then
+flags=
+gcc_master_branch=1
+channel="debug"
+func=all
+
+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
+            ;;
+
+        "--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
-        ;;
-
-    "--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
+function all() {
+    clean
+    mini_tests
+    build_sysroot
+    std_tests
+    test_libcore
+    extended_sysroot_tests
+    test_rustc
+}
+
+$func