Skip to content

Commit 7eb09a7

Browse files
authored
[CIR][cir-translate] Support specifying target for cir-translate (#1186)
This PR adds a new command line option `--target` to our tool `cir-translate`. The concrete behaviour of it also depends on the triple and data layout in the CIR module. See the table in code comments for details. The default triple is `x86_64-unknown-linux-gnu` currently. Some tests are updated with triple and DLTI attribute eliminated (replaced by an option in RUN line). But still some tests remain unchanged, primarily because they use `cir-opt` instead.
1 parent 34b3af2 commit 7eb09a7

12 files changed

+234
-24
lines changed

clang/test/CIR/Lowering/address-space.cir

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll
1+
// RUN: cir-translate %s -cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering -o %t.ll
22
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
33

44
!s32i = !cir.int<s, 32>
55

6-
module attributes {
7-
cir.triple = "spirv64-unknown-unknown",
8-
dlti.dl_spec = #dlti.dl_spec<i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, i64 = dense<64> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, "dlti.endianness" = "little", "dlti.global_memory_space" = 1 : ui64>
9-
} {
6+
module {
107
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
118
// LLVM: @addrspace1 = addrspace(1) global i32
129

clang/test/CIR/Lowering/data-member.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// RUN: cir-opt -cir-to-llvm -o - %s | FileCheck -check-prefix=MLIR %s
2-
// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o - %s | FileCheck -check-prefix=LLVM %s
2+
// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - %s | FileCheck -check-prefix=LLVM %s
33

44
!s32i = !cir.int<s, 32>
55
!s64i = !cir.int<s, 64>
66
!structT = !cir.struct<struct "Point" {!cir.int<s, 32>, !cir.int<s, 32>, !cir.int<s, 32>}>
77

88
module @test attributes {
99
cir.triple = "x86_64-unknown-linux-gnu",
10-
llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
10+
dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, !llvm.ptr<270> = dense<32> : vector<4xi64>, f64 = dense<64> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, "dlti.stack_alignment" = 128 : i64, "dlti.endianness" = "little">
1111
} {
1212
cir.global external @pt_member = #cir.data_member<1> : !cir.data_member<!s32i in !structT>
1313
// MLIR: llvm.mlir.global external @pt_member(4 : i64) {addr_space = 0 : i32} : i64

clang/test/CIR/Lowering/exceptions.cir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll
1+
// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll
22
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
33

44
!s32i = !cir.int<s, 32>
@@ -8,7 +8,7 @@
88
!u8i = !cir.int<u, 8>
99
!void = !cir.void
1010

11-
module @"try-catch.cpp" attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>, cir.triple = "x86_64-unknown-linux-gnu", dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>, #dlti.dl_entry<"dlti.endianness", "little">>} {
11+
module @"try-catch.cpp" attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>} {
1212
cir.global "private" constant external @_ZTIi : !cir.ptr<!u8i>
1313
cir.global "private" constant external @_ZTIPKc : !cir.ptr<!u8i>
1414
cir.func private @_Z8divisionii(!s32i, !s32i) -> !cir.double

clang/test/CIR/Tools/cir-translate-triple.cir

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-translate --cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.ll
2+
// RUN: FileCheck %s -input-file %t.ll -check-prefix=LLVM
3+
4+
module {
5+
cir.func @foo() {
6+
cir.return
7+
}
8+
}
9+
10+
// LLVM-DAG: target triple = "x86_64-unknown-linux-gnu"
11+
// LLVM-DAG: target datalayout = "{{.*}}"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: cir-translate --cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.x86.ll
2+
// RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86
3+
// RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll
4+
// RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64
5+
// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll
6+
// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT
7+
8+
module attributes {
9+
cir.triple = "spirv64-unknown-unknown",
10+
dlti.dl_spec = #dlti.dl_spec<"dlti.global_memory_space" = 7 : ui64>
11+
} {
12+
cir.func @foo() {
13+
cir.return
14+
}
15+
}
16+
17+
// X86-NOT: target datalayout = "G7"
18+
// X86-DAG: target triple = "x86_64-unknown-linux-gnu"
19+
20+
// SPIRV64-NOT: target datalayout = "G7"
21+
// SPIRV64-DAG: target triple = "spirv64-unknown-unknown"
22+
23+
// DEFAULT-DAG: target datalayout = "G7"
24+
// DEFAULT-DAG: target triple = "spirv64-unknown-unknown"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: cir-translate --cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.x86.ll
2+
// RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86
3+
// RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll
4+
// RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64
5+
// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll
6+
// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT
7+
8+
module attributes {
9+
cir.triple = "spirv64-unknown-unknown"
10+
} {
11+
cir.func @foo() {
12+
cir.return
13+
}
14+
}
15+
16+
// X86-DAG: target triple = "x86_64-unknown-linux-gnu"
17+
// X86-DAG: target datalayout = "{{.*}}"
18+
19+
// SPIRV64-DAG: target triple = "spirv64-unknown-unknown"
20+
// SPIRV64-DAG: target datalayout = "{{.*}}"
21+
22+
// DEFAULT-DAG: target triple = "spirv64-unknown-unknown"
23+
// DEFAULT-DAG: target datalayout = "{{.*}}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: cir-translate -verify-diagnostics --cir-to-llvmir --target foobar --disable-cc-lowering %s 2>&1
2+
3+
// expected-error@below {{invalid target triple 'foobar'}}
4+
module {
5+
cir.func @foo() {
6+
cir.return
7+
}
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: cir-translate --cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.x86.ll
2+
// RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86
3+
// RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll
4+
// RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64
5+
// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll
6+
// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT
7+
8+
module attributes {
9+
dlti.dl_spec = #dlti.dl_spec<"dlti.global_memory_space" = 7 : ui64>
10+
} {
11+
cir.func @foo() {
12+
cir.return
13+
}
14+
}
15+
16+
// X86-NOT: target datalayout = "G7"
17+
// X86-DAG: target triple = "x86_64-unknown-linux-gnu"
18+
19+
// SPIRV64-NOT: target datalayout = "G7"
20+
// SPIRV64-DAG: target triple = "spirv64-unknown-unknown"
21+
22+
// DEFAULT-NOT: target datalayout = "G7"
23+
// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: cir-translate --cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.x86.ll
2+
// RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86
3+
// RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll
4+
// RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64
5+
// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll
6+
// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT
7+
8+
module {
9+
cir.func @foo() {
10+
cir.return
11+
}
12+
}
13+
14+
// X86-DAG: target triple = "x86_64-unknown-linux-gnu"
15+
// X86-DAG: target datalayout = "{{.*}}"
16+
17+
// SPIRV64-DAG: target triple = "spirv64-unknown-unknown"
18+
// SPIRV64-DAG: target datalayout = "{{.*}}"
19+
20+
// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu"
21+
// DEFAULT-DAG: target datalayout = "{{.*}}"

0 commit comments

Comments
 (0)