Skip to content

Commit 4d7de81

Browse files
committed
Add feature for future libgccjit 12 release
1 parent d69ada6 commit 4d7de81

File tree

12 files changed

+189
-63
lines changed

12 files changed

+189
-63
lines changed

.github/workflows/ci.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]
14+
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so", "libgccjit12.so"]
1515

1616
steps:
1717
- uses: actions/checkout@v2
@@ -78,12 +78,21 @@ jobs:
7878
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
7979

8080
- name: Build
81+
if: matrix.libgccjit_version != 'libgccjit12.so'
8182
run: |
8283
./prepare_build.sh
8384
./build.sh
8485
cargo test
8586
./clean_all.sh
8687
88+
- name: Build
89+
if: matrix.libgccjit_version == 'libgccjit12.so'
90+
run: |
91+
./prepare_build.sh
92+
./build.sh --no-default-features
93+
cargo test --no-default-features
94+
./clean_all.sh
95+
8796
- name: Prepare dependencies
8897
run: |
8998
git config --global user.email "[email protected]"
@@ -98,6 +107,7 @@ jobs:
98107
args: --release
99108

100109
- name: Test
110+
if: matrix.libgccjit_version != 'libgccjit12.so'
101111
run: |
102112
# Enable backtraces for easier debugging
103113
export RUST_BACKTRACE=1
@@ -107,3 +117,15 @@ jobs:
107117
export RUN_RUNS=2
108118
109119
./test.sh --release
120+
121+
- name: Test
122+
if: matrix.libgccjit_version == 'libgccjit12.so'
123+
run: |
124+
# Enable backtraces for easier debugging
125+
export RUST_BACKTRACE=1
126+
127+
# Reduce amount of benchmark runs as they are slow
128+
export COMPILE_RUNS=2
129+
export RUN_RUNS=2
130+
131+
./test.sh --release --no-default-features

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ name = "lang_tests"
1313
path = "tests/lib.rs"
1414
harness = false
1515

16+
[features]
17+
default = ["master"]
18+
master = ["gccjit/master"]
19+
1620
[dependencies]
1721
gccjit = { git = "https://github.com/antoyo/gccjit.rs" }
1822

build.sh

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set -e
66
codegen_channel=debug
77
sysroot_channel=debug
88

9+
flags=
10+
911
while [[ $# -gt 0 ]]; do
1012
case $1 in
1113
--release)
@@ -16,6 +18,15 @@ while [[ $# -gt 0 ]]; do
1618
sysroot_channel=release
1719
shift
1820
;;
21+
--no-default-features)
22+
flags="$flags --no-default-features"
23+
shift
24+
;;
25+
--features)
26+
shift
27+
flags="$flags --features $1"
28+
shift
29+
;;
1930
*)
2031
echo "Unknown option $1"
2132
exit 1
@@ -33,21 +44,13 @@ fi
3344
export LD_LIBRARY_PATH="$GCC_PATH"
3445
export LIBRARY_PATH="$GCC_PATH"
3546

36-
features=
37-
38-
if [[ "$1" == "--features" ]]; then
39-
shift
40-
features="--features $1"
41-
shift
42-
fi
43-
4447
if [[ "$codegen_channel" == "release" ]]; then
4548
export CHANNEL='release'
46-
CARGO_INCREMENTAL=1 cargo rustc --release $features
49+
CARGO_INCREMENTAL=1 cargo rustc --release $flags
4750
else
4851
echo $LD_LIBRARY_PATH
4952
export CHANNEL='debug'
50-
cargo rustc $features
53+
cargo rustc $flags
5154
fi
5255

5356
source config.sh

example/std_example.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn main() {
9393

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

96+
#[cfg(feature="master")]
9697
unsafe {
9798
test_simd();
9899
}
@@ -104,6 +105,7 @@ fn main() {
104105
println!("End");
105106
}
106107

108+
#[cfg(feature="master")]
107109
#[target_feature(enable = "sse2")]
108110
unsafe fn test_simd() {
109111
let x = _mm_setzero_si128();
@@ -131,6 +133,7 @@ unsafe fn test_simd() {
131133
assert_eq!(mask1, 1);
132134
}
133135

136+
#[cfg(feature="master")]
134137
#[target_feature(enable = "sse2")]
135138
unsafe fn test_mm_slli_si128() {
136139
#[rustfmt::skip]
@@ -158,6 +161,7 @@ unsafe fn test_mm_slli_si128() {
158161
}
159162

160163

164+
#[cfg(feature="master")]
161165
#[target_feature(enable = "sse2")]
162166
unsafe fn test_mm_movemask_epi8() {
163167
#[rustfmt::skip]
@@ -171,6 +175,7 @@ unsafe fn test_mm_movemask_epi8() {
171175
assert_eq!(r, 0b10100100_00100101);
172176
}
173177

178+
#[cfg(feature="master")]
174179
#[target_feature(enable = "avx2")]
175180
unsafe fn test_mm256_movemask_epi8() {
176181
let a = _mm256_set1_epi8(-1);
@@ -179,6 +184,7 @@ unsafe fn test_mm256_movemask_epi8() {
179184
assert_eq!(r, e);
180185
}
181186

187+
#[cfg(feature="master")]
182188
#[target_feature(enable = "sse2")]
183189
unsafe fn test_mm_add_epi8() {
184190
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() {
194200
assert_eq_m128i(r, e);
195201
}
196202

203+
#[cfg(feature="master")]
197204
#[target_feature(enable = "sse2")]
198205
unsafe fn test_mm_add_pd() {
199206
let a = _mm_setr_pd(1.0, 2.0);
@@ -202,25 +209,29 @@ unsafe fn test_mm_add_pd() {
202209
assert_eq_m128d(r, _mm_setr_pd(6.0, 12.0));
203210
}
204211

212+
#[cfg(feature="master")]
205213
fn assert_eq_m128i(x: std::arch::x86_64::__m128i, y: std::arch::x86_64::__m128i) {
206214
unsafe {
207215
assert_eq!(std::mem::transmute::<_, [u8; 16]>(x), std::mem::transmute::<_, [u8; 16]>(y));
208216
}
209217
}
210218

219+
#[cfg(feature="master")]
211220
#[target_feature(enable = "sse2")]
212221
pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
213222
if _mm_movemask_pd(_mm_cmpeq_pd(a, b)) != 0b11 {
214223
panic!("{:?} != {:?}", a, b);
215224
}
216225
}
217226

227+
#[cfg(feature="master")]
218228
#[target_feature(enable = "sse2")]
219229
unsafe fn test_mm_cvtsi128_si64() {
220230
let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0]));
221231
assert_eq!(r, 5);
222232
}
223233

234+
#[cfg(feature="master")]
224235
#[target_feature(enable = "sse4.1")]
225236
unsafe fn test_mm_cvtepi8_epi16() {
226237
let a = _mm_set1_epi8(10);
@@ -233,6 +244,7 @@ unsafe fn test_mm_cvtepi8_epi16() {
233244
assert_eq_m128i(r, e);
234245
}
235246

247+
#[cfg(feature="master")]
236248
#[target_feature(enable = "sse4.1")]
237249
unsafe fn test_mm_extract_epi8() {
238250
#[rustfmt::skip]
@@ -246,7 +258,7 @@ unsafe fn test_mm_extract_epi8() {
246258
assert_eq!(r2, 3);
247259
}
248260

249-
#[cfg(target_arch = "x86_64")]
261+
#[cfg(all(feature="master", target_arch = "x86_64"))]
250262
#[target_feature(enable = "sse2")]
251263
unsafe fn test_mm_insert_epi16() {
252264
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);

src/builder.rs

+15
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
301301
result.to_rvalue()
302302
}
303303
else {
304+
#[cfg(not(feature="master"))]
305+
if gcc_func.get_param_count() == 0 {
306+
// FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
307+
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &[]));
308+
}
309+
else {
310+
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
311+
}
312+
#[cfg(feature="master")]
304313
self.block.add_eval(None, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
305314
// Return dummy value when not having return value.
306315
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> {
12871296
}
12881297

12891298
impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
1299+
#[cfg(feature="master")]
12901300
pub fn shuffle_vector(&mut self, v1: RValue<'gcc>, v2: RValue<'gcc>, mask: RValue<'gcc>) -> RValue<'gcc> {
12911301
let struct_type = mask.get_type().is_struct().expect("mask of struct type");
12921302

@@ -1361,6 +1371,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
13611371
result
13621372
}
13631373
}
1374+
1375+
#[cfg(not(feature="master"))]
1376+
pub fn shuffle_vector(&mut self, _v1: RValue<'gcc>, _v2: RValue<'gcc>, _mask: RValue<'gcc>) -> RValue<'gcc> {
1377+
unimplemented!();
1378+
}
13641379
}
13651380

13661381
impl<'a, 'gcc, 'tcx> StaticBuilderMethods for Builder<'a, 'gcc, 'tcx> {

src/intrinsic/llvm.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ use gccjit::Function;
22

33
use crate::context::CodegenCx;
44

5+
#[cfg(not(feature="master"))]
6+
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
7+
match name {
8+
"llvm.x86.xgetbv" => {
9+
let gcc_name = "__builtin_trap";
10+
let func = cx.context.get_builtin_function(gcc_name);
11+
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
12+
return func;
13+
},
14+
_ => unimplemented!("unsupported LLVM intrinsic {}", name),
15+
}
16+
}
17+
18+
#[cfg(feature="master")]
519
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
620
let gcc_name = match name {
721
"llvm.x86.xgetbv" => "__builtin_ia32_xgetbv",

src/intrinsic/simd.rs

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
154154
));
155155
}
156156

157+
#[cfg(feature="master")]
157158
if name == sym::simd_insert {
158159
require!(
159160
in_elem == arg_tys[2],
@@ -213,6 +214,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
213214
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
214215
return Ok(bx.context.new_bitcast(None, result, vector.get_type()));
215216
}
217+
218+
#[cfg(feature="master")]
216219
if name == sym::simd_extract {
217220
require!(
218221
ret_ty == in_elem,
@@ -503,6 +506,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
503506
simd_neg: Int => neg, Float => fneg;
504507
}
505508

509+
#[cfg(feature="master")]
506510
if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
507511
let lhs = args[0].immediate();
508512
let rhs = args[1].immediate();

src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,17 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
299299
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
300300
},
301301
)
302-
.filter(|feature| {
302+
.filter(|_feature| {
303303
// TODO(antoyo): implement a way to get enabled feature in libgccjit.
304304
// Probably using the equivalent of __builtin_cpu_supports.
305-
feature.contains("sse") || feature.contains("avx")
305+
#[cfg(feature="master")]
306+
{
307+
_feature.contains("sse") || _feature.contains("avx")
308+
}
309+
#[cfg(not(feature="master"))]
310+
{
311+
false
312+
}
306313
/*
307314
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512gfni,
308315
avx512ifma, avx512pf, avx512vaes, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpclmulqdq,

src/type_.rs

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
125125
.collect();
126126
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
127127
if packed {
128+
#[cfg(feature="master")]
128129
typ.set_packed();
129130
}
130131
self.struct_types.borrow_mut().insert(types, typ);
@@ -217,6 +218,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
217218
.collect();
218219
typ.set_fields(None, &fields);
219220
if packed {
221+
#[cfg(feature="master")]
220222
typ.as_type().set_packed();
221223
}
222224
}

src/type_of.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2525
}
2626
}
2727

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

40+
#[cfg(feature="master")]
3941
pub fn type_uint_from_ty(&self, t: ty::UintTy) -> Type<'gcc> {
4042
match t {
4143
ty::UintTy::Usize => self.type_isize(),

0 commit comments

Comments
 (0)