Skip to content

Commit f48cd43

Browse files
Kureelanza
authored andcommitted
[CIR][Lowering] use cir.int type in LIT tests (#266)
Here is the promised patch that adds proper type conversion to CIR -> MLIR conversion. I tried to keep the changes minimum but the existing implementation doesn't use `TypeConverter`. This should not have any functional changes except for one tiny fix that registers the `cf` dialect, which should allow `goto.mlir` to pass. Happy to break the PR into two if requested.
1 parent bc24a71 commit f48cd43

File tree

9 files changed

+278
-270
lines changed

9 files changed

+278
-270
lines changed

clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp

Lines changed: 163 additions & 153 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
2-
// RUN: cir-opt %s -cir-to-mlir -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
32

43
module {
54
cir.func @foo() {
@@ -10,15 +9,7 @@ module {
109

1110
// MLIR: module {
1211
// MLIR-NEXT: func @foo() {
13-
// MLIR-NEXT: = memref.alloca() {alignment = 16 : i64} : memref<10xi32>
12+
// MLIR-NEXT: = memref.alloca() {alignment = 16 : i64} : memref<memref<10xi32>>
1413
// MLIR-NEXT: return
1514
// MLIR-NEXT: }
1615
// MLIR-NEXT: }
17-
18-
// LLVM: = alloca i32, i64 10, align 16
19-
// LLVM-NEXT: = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } undef, ptr %1, 0
20-
// LLVM-NEXT: = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %2, ptr %1, 1
21-
// LLVM-NEXT: = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %3, i64 0, 2
22-
// LLVM-NEXT: = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %4, i64 10, 3, 0
23-
// LLVM-NEXT: = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %5, i64 1, 4, 0
24-
// LLVM-NEXT: ret void

clang/test/CIR/Lowering/ThroughMLIR/binop-unsigned-int.cir

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
3+
!u32i = !cir.int<u, 32>
34

45
module {
56
cir.func @foo() {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["a", init] {alignment = 4 : i64}
7-
%1 = cir.alloca i32, cir.ptr <i32>, ["b", init] {alignment = 4 : i64}
8-
%2 = cir.alloca i32, cir.ptr <i32>, ["x", init] {alignment = 4 : i64}
9-
%3 = cir.const(2 : i32) : i32 cir.store %3, %0 : i32, cir.ptr <i32>
10-
%4 = cir.const(1 : i32) : i32 cir.store %4, %1 : i32, cir.ptr <i32>
11-
%5 = cir.load %0 : cir.ptr <i32>, i32
12-
%6 = cir.load %1 : cir.ptr <i32>, i32
13-
%7 = cir.binop(mul, %5, %6) : i32
14-
cir.store %7, %2 : i32, cir.ptr <i32>
15-
%8 = cir.load %2 : cir.ptr <i32>, i32
16-
%9 = cir.load %1 : cir.ptr <i32>, i32
17-
%10 = cir.binop(div, %8, %9) : i32
18-
cir.store %10, %2 : i32, cir.ptr <i32>
19-
%11 = cir.load %2 : cir.ptr <i32>, i32
20-
%12 = cir.load %1 : cir.ptr <i32>, i32
21-
%13 = cir.binop(rem, %11, %12) : i32
22-
cir.store %13, %2 : i32, cir.ptr <i32>
23-
%14 = cir.load %2 : cir.ptr <i32>, i32
24-
%15 = cir.load %1 : cir.ptr <i32>, i32
25-
%16 = cir.binop(add, %14, %15) : i32
26-
cir.store %16, %2 : i32, cir.ptr <i32>
27-
%17 = cir.load %2 : cir.ptr <i32>, i32
28-
%18 = cir.load %1 : cir.ptr <i32>, i32
29-
%19 = cir.binop(sub, %17, %18) : i32
30-
cir.store %19, %2 : i32, cir.ptr <i32>
7+
%0 = cir.alloca !u32i, cir.ptr <!u32i>, ["a", init] {alignment = 4 : i64}
8+
%1 = cir.alloca !u32i, cir.ptr <!u32i>, ["b", init] {alignment = 4 : i64}
9+
%2 = cir.alloca !u32i, cir.ptr <!u32i>, ["x", init] {alignment = 4 : i64}
10+
%3 = cir.const(#cir.int<2> : !u32i) : !u32i cir.store %3, %0 : !u32i, cir.ptr <!u32i>
11+
%4 = cir.const(#cir.int<1> : !u32i) : !u32i cir.store %4, %1 : !u32i, cir.ptr <!u32i>
12+
%5 = cir.load %0 : cir.ptr <!u32i>, !u32i
13+
%6 = cir.load %1 : cir.ptr <!u32i>, !u32i
14+
%7 = cir.binop(mul, %5, %6) : !u32i
15+
cir.store %7, %2 : !u32i, cir.ptr <!u32i>
16+
%8 = cir.load %2 : cir.ptr <!u32i>, !u32i
17+
%9 = cir.load %1 : cir.ptr <!u32i>, !u32i
18+
%10 = cir.binop(div, %8, %9) : !u32i
19+
cir.store %10, %2 : !u32i, cir.ptr <!u32i>
20+
%11 = cir.load %2 : cir.ptr <!u32i>, !u32i
21+
%12 = cir.load %1 : cir.ptr <!u32i>, !u32i
22+
%13 = cir.binop(rem, %11, %12) : !u32i
23+
cir.store %13, %2 : !u32i, cir.ptr <!u32i>
24+
%14 = cir.load %2 : cir.ptr <!u32i>, !u32i
25+
%15 = cir.load %1 : cir.ptr <!u32i>, !u32i
26+
%16 = cir.binop(add, %14, %15) : !u32i
27+
cir.store %16, %2 : !u32i, cir.ptr <!u32i>
28+
%17 = cir.load %2 : cir.ptr <!u32i>, !u32i
29+
%18 = cir.load %1 : cir.ptr <!u32i>, !u32i
30+
%19 = cir.binop(sub, %17, %18) : !u32i
31+
cir.store %19, %2 : !u32i, cir.ptr <!u32i>
3132
// should move to cir.shift, which only accepts
3233
// CIR types.
33-
// %20 = cir.load %2 : cir.ptr <i32>, i32
34-
// %21 = cir.load %1 : cir.ptr <i32>, i32
35-
// %22 = cir.binop(shr, %20, %21) : i32
36-
// cir.store %22, %2 : i32, cir.ptr <i32>
37-
// %23 = cir.load %2 : cir.ptr <i32>, i32
38-
// %24 = cir.load %1 : cir.ptr <i32>, i32
39-
// %25 = cir.binop(shl, %23, %24) : i32
40-
// cir.store %25, %2 : i32, cir.ptr <i32>
41-
%26 = cir.load %2 : cir.ptr <i32>, i32
42-
%27 = cir.load %1 : cir.ptr <i32>, i32
43-
%28 = cir.binop(and, %26, %27) : i32
44-
cir.store %28, %2 : i32, cir.ptr <i32>
45-
%29 = cir.load %2 : cir.ptr <i32>, i32
46-
%30 = cir.load %1 : cir.ptr <i32>, i32
47-
%31 = cir.binop(xor, %29, %30) : i32
48-
cir.store %31, %2 : i32, cir.ptr <i32>
49-
%32 = cir.load %2 : cir.ptr <i32>, i32
50-
%33 = cir.load %1 : cir.ptr <i32>, i32
51-
%34 = cir.binop(or, %32, %33) : i32
52-
cir.store %34, %2 : i32, cir.ptr <i32>
34+
// %20 = cir.load %2 : cir.ptr <!u32i>, !u32i
35+
// %21 = cir.load %1 : cir.ptr <!u32i>, !u32i
36+
// %22 = cir.binop(shr, %20, %21) : !u32i
37+
// cir.store %22, %2 : !u32i, cir.ptr <!u32i>
38+
// %23 = cir.load %2 : cir.ptr <!u32i>, !u32i
39+
// %24 = cir.load %1 : cir.ptr <!u32i>, !u32i
40+
// %25 = cir.binop(shl, %23, %24) : !u32i
41+
// cir.store %25, %2 : !u32i, cir.ptr <!u32i>
42+
%26 = cir.load %2 : cir.ptr <!u32i>, !u32i
43+
%27 = cir.load %1 : cir.ptr <!u32i>, !u32i
44+
%28 = cir.binop(and, %26, %27) : !u32i
45+
cir.store %28, %2 : !u32i, cir.ptr <!u32i>
46+
%29 = cir.load %2 : cir.ptr <!u32i>, !u32i
47+
%30 = cir.load %1 : cir.ptr <!u32i>, !u32i
48+
%31 = cir.binop(xor, %29, %30) : !u32i
49+
cir.store %31, %2 : !u32i, cir.ptr <!u32i>
50+
%32 = cir.load %2 : cir.ptr <!u32i>, !u32i
51+
%33 = cir.load %1 : cir.ptr <!u32i>, !u32i
52+
%34 = cir.binop(or, %32, %33) : !u32i
53+
cir.store %34, %2 : !u32i, cir.ptr <!u32i>
5354
cir.return
5455
}
5556
}

clang/test/CIR/Lowering/ThroughMLIR/cmp.cir

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!s32i = !cir.int<s, 32>
45
module {
56
cir.func @foo() {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["a"] {alignment = 4 : i64}
7-
%1 = cir.alloca i32, cir.ptr <i32>, ["b"] {alignment = 4 : i64}
7+
%0 = cir.alloca !s32i, cir.ptr <!s32i>, ["a"] {alignment = 4 : i64}
8+
%1 = cir.alloca !s32i, cir.ptr <!s32i>, ["b"] {alignment = 4 : i64}
89
%2 = cir.alloca f32, cir.ptr <f32>, ["c"] {alignment = 4 : i64}
910
%3 = cir.alloca f32, cir.ptr <f32>, ["d"] {alignment = 4 : i64}
1011
%4 = cir.alloca !cir.bool, cir.ptr <!cir.bool>, ["e"] {alignment = 1 : i64}
11-
%5 = cir.load %0 : cir.ptr <i32>, i32
12-
%6 = cir.load %1 : cir.ptr <i32>, i32
13-
%7 = cir.cmp(gt, %5, %6) : i32, !cir.bool
14-
%8 = cir.load %0 : cir.ptr <i32>, i32
15-
%9 = cir.load %1 : cir.ptr <i32>, i32
16-
%10 = cir.cmp(eq, %8, %9) : i32, !cir.bool
17-
%11 = cir.load %0 : cir.ptr <i32>, i32
18-
%12 = cir.load %1 : cir.ptr <i32>, i32
19-
%13 = cir.cmp(lt, %11, %12) : i32, !cir.bool
20-
%14 = cir.load %0 : cir.ptr <i32>, i32
21-
%15 = cir.load %1 : cir.ptr <i32>, i32
22-
%16 = cir.cmp(ge, %14, %15) : i32, !cir.bool
23-
%17 = cir.load %0 : cir.ptr <i32>, i32
24-
%18 = cir.load %1 : cir.ptr <i32>, i32
25-
%19 = cir.cmp(ne, %17, %18) : i32, !cir.bool
26-
%20 = cir.load %0 : cir.ptr <i32>, i32
27-
%21 = cir.load %1 : cir.ptr <i32>, i32
28-
%22 = cir.cmp(le, %20, %21) : i32, !cir.bool
12+
%5 = cir.load %0 : cir.ptr <!s32i>, !s32i
13+
%6 = cir.load %1 : cir.ptr <!s32i>, !s32i
14+
%7 = cir.cmp(gt, %5, %6) : !s32i, !cir.bool
15+
%8 = cir.load %0 : cir.ptr <!s32i>, !s32i
16+
%9 = cir.load %1 : cir.ptr <!s32i>, !s32i
17+
%10 = cir.cmp(eq, %8, %9) : !s32i, !cir.bool
18+
%11 = cir.load %0 : cir.ptr <!s32i>, !s32i
19+
%12 = cir.load %1 : cir.ptr <!s32i>, !s32i
20+
%13 = cir.cmp(lt, %11, %12) : !s32i, !cir.bool
21+
%14 = cir.load %0 : cir.ptr <!s32i>, !s32i
22+
%15 = cir.load %1 : cir.ptr <!s32i>, !s32i
23+
%16 = cir.cmp(ge, %14, %15) : !s32i, !cir.bool
24+
%17 = cir.load %0 : cir.ptr <!s32i>, !s32i
25+
%18 = cir.load %1 : cir.ptr <!s32i>, !s32i
26+
%19 = cir.cmp(ne, %17, %18) : !s32i, !cir.bool
27+
%20 = cir.load %0 : cir.ptr <!s32i>, !s32i
28+
%21 = cir.load %1 : cir.ptr <!s32i>, !s32i
29+
%22 = cir.cmp(le, %20, %21) : !s32i, !cir.bool
2930
%23 = cir.load %2 : cir.ptr <f32>, f32
3031
%24 = cir.load %3 : cir.ptr <f32>, f32
3132
%25 = cir.cmp(gt, %23, %24) : f32, !cir.bool

clang/test/CIR/Lowering/ThroughMLIR/goto.cir

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
// RUN: cir-opt %s -canonicalize -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -canonicalize -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!u32i = !cir.int<u, 32>
45
module {
56
cir.func @foo() {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["b", init] {alignment = 4 : i64}
7-
%1 = cir.const(1 : i32) : i32
8-
cir.store %1, %0 : i32, cir.ptr <i32>
7+
%0 = cir.alloca !u32i, cir.ptr <!u32i>, ["b", init] {alignment = 4 : i64}
8+
%1 = cir.const(#cir.int<1> : !u32i) : !u32i
9+
cir.store %1, %0 : !u32i, cir.ptr <!u32i>
910
cir.br ^bb2
1011
^bb1: // no predecessors
11-
%2 = cir.load %0 : cir.ptr <i32>, i32
12-
%3 = cir.const(1 : i32) : i32
13-
%4 = cir.binop(add, %2, %3) : i32
14-
cir.store %4, %0 : i32, cir.ptr <i32>
12+
%2 = cir.load %0 : cir.ptr <!u32i>, !u32i
13+
%3 = cir.const(#cir.int<1> : !u32i) : !u32i
14+
%4 = cir.binop(add, %2, %3) : !u32i
15+
cir.store %4, %0 : !u32i, cir.ptr <!u32i>
1516
cir.br ^bb2
1617
^bb2: // 2 preds: ^bb0, ^bb1
17-
%5 = cir.load %0 : cir.ptr <i32>, i32
18-
%6 = cir.const(2 : i32) : i32
19-
%7 = cir.binop(add, %5, %6) : i32
20-
cir.store %7, %0 : i32, cir.ptr <i32>
18+
%5 = cir.load %0 : cir.ptr <!u32i>, !u32i
19+
%6 = cir.const(#cir.int<2> : !u32i) : !u32i
20+
%7 = cir.binop(add, %5, %6) : !u32i
21+
cir.store %7, %0 : !u32i, cir.ptr <!u32i>
2122
cir.return
2223
}
2324
}

clang/test/CIR/Lowering/ThroughMLIR/memref.cir

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!u32i = !cir.int<u, 32>
45
module {
5-
cir.func @foo() -> i32 {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["x", init] {alignment = 4 : i64}
7-
%1 = cir.const(1 : i32) : i32
8-
cir.store %1, %0 : i32, cir.ptr <i32>
9-
%2 = cir.load %0 : cir.ptr <i32>, i32
10-
cir.return %2 : i32
6+
cir.func @foo() -> !u32i {
7+
%0 = cir.alloca !u32i, cir.ptr <!u32i>, ["x", init] {alignment = 4 : i64}
8+
%1 = cir.const(#cir.int<1> : !u32i) : !u32i
9+
cir.store %1, %0 : !u32i, cir.ptr <!u32i>
10+
%2 = cir.load %0 : cir.ptr <!u32i>, !u32i
11+
cir.return %2 : !u32i
1112
}
1213
}
1314

clang/test/CIR/Lowering/ThroughMLIR/scope.cir

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!u32i = !cir.int<u, 32>
45
module {
56
cir.func @foo() {
67
cir.scope {
7-
%0 = cir.alloca i32, cir.ptr <i32>, ["a", init] {alignment = 4 : i64}
8-
%1 = cir.const(4 : i32) : i32
9-
cir.store %1, %0 : i32, cir.ptr <i32>
8+
%0 = cir.alloca !u32i, cir.ptr <!u32i>, ["a", init] {alignment = 4 : i64}
9+
%1 = cir.const(#cir.int<4> : !u32i) : !u32i
10+
cir.store %1, %0 : !u32i, cir.ptr <!u32i>
1011
}
1112
cir.return
1213
}

clang/test/CIR/Lowering/ThroughMLIR/unary-inc-dec.cir

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!s32i = !cir.int<s, 32>
45
module {
56
cir.func @foo() {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["a", init] {alignment = 4 : i64}
7-
%1 = cir.alloca i32, cir.ptr <i32>, ["b", init] {alignment = 4 : i64}
8-
%2 = cir.const(2 : i32) : i32
9-
cir.store %2, %0 : i32, cir.ptr <i32>
10-
cir.store %2, %1 : i32, cir.ptr <i32>
7+
%0 = cir.alloca !s32i, cir.ptr <!s32i>, ["a", init] {alignment = 4 : i64}
8+
%1 = cir.alloca !s32i, cir.ptr <!s32i>, ["b", init] {alignment = 4 : i64}
9+
%2 = cir.const(#cir.int<2> : !s32i) : !s32i
10+
cir.store %2, %0 : !s32i, cir.ptr <!s32i>
11+
cir.store %2, %1 : !s32i, cir.ptr <!s32i>
1112

12-
%3 = cir.load %0 : cir.ptr <i32>, i32
13-
%4 = cir.unary(inc, %3) : i32, i32
14-
cir.store %4, %0 : i32, cir.ptr <i32>
13+
%3 = cir.load %0 : cir.ptr <!s32i>, !s32i
14+
%4 = cir.unary(inc, %3) : !s32i, !s32i
15+
cir.store %4, %0 : !s32i, cir.ptr <!s32i>
1516

16-
%5 = cir.load %1 : cir.ptr <i32>, i32
17-
%6 = cir.unary(dec, %5) : i32, i32
18-
cir.store %6, %1 : i32, cir.ptr <i32>
17+
%5 = cir.load %1 : cir.ptr <!s32i>, !s32i
18+
%6 = cir.unary(dec, %5) : !s32i, !s32i
19+
cir.store %6, %1 : !s32i, cir.ptr <!s32i>
1920
cir.return
2021
}
2122
}

clang/test/CIR/Lowering/ThroughMLIR/unary-plus-minus.cir

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// RUN: cir-opt %s -cir-to-mlir -o - | FileCheck %s -check-prefix=MLIR
22
// RUN: cir-opt %s -cir-to-mlir -cir-mlir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
33

4+
!s32i = !cir.int<s, 32>
45
module {
56
cir.func @foo() {
6-
%0 = cir.alloca i32, cir.ptr <i32>, ["a", init] {alignment = 4 : i64}
7-
%1 = cir.alloca i32, cir.ptr <i32>, ["b", init] {alignment = 4 : i64}
8-
%2 = cir.const(2 : i32) : i32
9-
cir.store %2, %0 : i32, cir.ptr <i32>
10-
cir.store %2, %1 : i32, cir.ptr <i32>
7+
%0 = cir.alloca !s32i, cir.ptr <!s32i>, ["a", init] {alignment = 4 : i64}
8+
%1 = cir.alloca !s32i, cir.ptr <!s32i>, ["b", init] {alignment = 4 : i64}
9+
%2 = cir.const(#cir.int<2> : !s32i) : !s32i
10+
cir.store %2, %0 : !s32i, cir.ptr <!s32i>
11+
cir.store %2, %1 : !s32i, cir.ptr <!s32i>
1112

12-
%3 = cir.load %0 : cir.ptr <i32>, i32
13-
%4 = cir.unary(plus, %3) : i32, i32
14-
cir.store %4, %0 : i32, cir.ptr <i32>
13+
%3 = cir.load %0 : cir.ptr <!s32i>, !s32i
14+
%4 = cir.unary(plus, %3) : !s32i, !s32i
15+
cir.store %4, %0 : !s32i, cir.ptr <!s32i>
1516

16-
%5 = cir.load %1 : cir.ptr <i32>, i32
17-
%6 = cir.unary(minus, %5) : i32, i32
18-
cir.store %6, %1 : i32, cir.ptr <i32>
17+
%5 = cir.load %1 : cir.ptr <!s32i>, !s32i
18+
%6 = cir.unary(minus, %5) : !s32i, !s32i
19+
cir.store %6, %1 : !s32i, cir.ptr <!s32i>
1920
cir.return
2021
}
2122
}

0 commit comments

Comments
 (0)