Skip to content

Commit f88d050

Browse files
SchrodingerZhuLancern
authored andcommitted
[gccjit] add unary testing (#38)
1 parent 49f527f commit f88d050

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

src/Translation/TranslateToGCCJIT.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,15 @@ static gcc_jit_rvalue *translateAtomicOrdering(GCCJITTranslation &trans,
731731
case AtomicOrdering::SeqCst:
732732
gccMemOrder = __ATOMIC_SEQ_CST;
733733
break;
734+
#ifdef __clang__
735+
#pragma clang diagnostic push
736+
#pragma clang diagnostic ignored "-Wcovered-switch-default"
737+
#endif
734738
default:
735739
llvm_unreachable("unknown atomic ordering");
740+
#ifdef __clang__
741+
#pragma clang diagnostic pop
742+
#endif
736743
}
737744

738745
gcc_jit_type *gccMemOrderType =

test/compile/atomic.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module @test attributes {
6666
^entry(%arg0 : !gccjit.lvalue<!ppi32>, %arg1 : !gccjit.lvalue<!pi32>):
6767
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
6868
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!pi32> to !pi32
69-
// CHECK: (void)__atomic_store_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (int)0);
69+
// CHECK: (void)__atomic_store_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (int)0);
7070
gccjit.atomic.store relaxed (%0 : !ppi32, %1 : !pi32)
7171
gccjit.return
7272
}
@@ -96,7 +96,7 @@ module @test attributes {
9696
^entry(%arg0 : !gccjit.lvalue<!ppi32>, %arg1 : !gccjit.lvalue<!pi32>):
9797
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
9898
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!pi32> to !pi32
99-
// CHECK: %{{.+}} = bitcast(__atomic_fetch_add_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (int)0), __int32_t *);
99+
// CHECK: %{{.+}} = bitcast(__atomic_fetch_add_8 (((volatile void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (int)0), __int32_t *);
100100
%2 = gccjit.atomic.rmw relaxed fetch_add (%0 : !ppi32, %1 : !pi32) : !pi32
101101
gccjit.return %2 : !pi32
102102
}
@@ -129,7 +129,7 @@ module @test attributes {
129129
%0 = gccjit.as_rvalue %arg0 : !gccjit.lvalue<!ppi32> to !ppi32
130130
%1 = gccjit.as_rvalue %arg1 : !gccjit.lvalue<!ppi32> to !ppi32
131131
%2 = gccjit.as_rvalue %arg2 : !gccjit.lvalue<!pi32> to !pi32
132-
// CHECK: %{{.+}} = __atomic_compare_exchange_8 (((volatile void *)%{{.+}}), ((volatile const void *)%{{.+}}), (bitcast(%{{.+}}, long long)), (bool)1, (int)4, (int)0);
132+
// CHECK: %{{.+}} = __atomic_compare_exchange_8 (((volatile void *)%{{.+}}), ((volatile const void *)%{{.+}}), (bitcast(%{{.+}}, {{long long|long}})), (bool)1, (int)4, (int)0);
133133
%3 = gccjit.atomic.cmpxchg weak success(acq_rel) failure(relaxed) (%0 : !ppi32, %1 : !ppi32, %2 : !pi32) : !bool
134134
gccjit.return %3 : !bool
135135
}

test/compile/unary.mlir

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %gccjit-translate -o %t.gimple %s -mlir-to-gccjit-gimple
2+
// RUN: %filecheck --input-file=%t.gimple %s --check-prefix=CHECK-GIMPLE
3+
!i32 = !gccjit.int<int32_t>
4+
!var32 = !gccjit.lvalue<!i32>
5+
!bool = !gccjit.int<bool>
6+
!varbool = !gccjit.lvalue<!bool>
7+
!float = !gccjit.fp<float>
8+
!varfloat = !gccjit.lvalue<!float>
9+
module @unary_testing {
10+
gccjit.func exported @unary_minus(!i32) -> !i32 {
11+
^body(%arg0: !var32):
12+
// CHECK-GIMPLE: %[[LOAD:[0-9]+]] = %arg0;
13+
%0 = gccjit.as_rvalue %arg0 : !var32 to !i32
14+
// CHECK-GIMPLE: %[[RET:[0-9]+]] = -(%[[LOAD]]);
15+
%1 = gccjit.unary minus (%0 : !i32) : !i32
16+
// CHECK-GIMPLE: return %[[RET]];
17+
gccjit.return %1 : !i32
18+
}
19+
gccjit.func exported @unary_minus_lv(!i32) -> !i32 {
20+
^body(%arg0: !var32):
21+
// CHECK-GIMPLE: %[[RET:[0-9]+]] = -(%arg0);
22+
// CHECK-GIMPLE: return %[[RET]];
23+
%0 = gccjit.unary minus (%arg0 : !var32) : !i32
24+
gccjit.return %0 : !i32
25+
}
26+
gccjit.func exported @unary_bitwise_negate(!i32) -> !i32 {
27+
^body(%arg0: !var32):
28+
// CHECK: return ~(%arg0);
29+
%0 = gccjit.expr lazy {
30+
%1 = gccjit.unary bitwise_negate (%arg0 : !var32) : !i32
31+
gccjit.return %1 : !i32
32+
} : !i32
33+
gccjit.return %0 : !i32
34+
}
35+
gccjit.func exported @unary_logical_negate(!bool) -> !bool {
36+
^body(%arg0: !varbool):
37+
// CHECK: return !(%arg0);
38+
%0 = gccjit.expr lazy {
39+
%1 = gccjit.unary logical_negate (%arg0 : !varbool) : !bool
40+
gccjit.return %1 : !bool
41+
} : !bool
42+
gccjit.return %0 : !bool
43+
}
44+
gccjit.func exported @unary_abs(!float) -> !float {
45+
^body(%arg0: !varfloat):
46+
// CHECK: return abs (%arg0);
47+
%0 = gccjit.expr lazy {
48+
%1 = gccjit.unary abs (%arg0 : !varfloat) : !float
49+
gccjit.return %1 : !float
50+
} : !float
51+
gccjit.return %0 : !float
52+
}
53+
}

0 commit comments

Comments
 (0)