diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2015-04-01 12:54:25 +0000 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2015-04-01 12:54:25 +0000 |
commit | 3a610ebf1e7c44309880b2bd7ec9325d3f1db0bd (patch) | |
tree | dcda64cd90746e94d74abf2688919bd2928a3680 /clang/test | |
parent | 57c85f53baf9ea6c14a7f4af52cda2624470cbed (diff) | |
download | bcm5719-llvm-3a610ebf1e7c44309880b2bd7ec9325d3f1db0bd.tar.gz bcm5719-llvm-3a610ebf1e7c44309880b2bd7ec9325d3f1db0bd.zip |
[SystemZ] Support transactional execution on zEC12
The zEC12 provides the transactional-execution facility. This is exposed
to users via a set of builtin routines on other compilers. This patch
adds clang support to enable those builtins. In partciular, the patch:
- enables the transactional-execution feature by default on zEC12
- allows to override presence of that feature via the -mhtm/-mno-htm options
- adds a predefined macro __HTM__ if the feature is enabled
- adds support for the transactional-execution GCC builtins
- adds Sema checking to verify the __builtin_tabort abort code
- adds the s390intrin.h header file (for GCC compatibility)
- adds s390 sections to the htmintrin.h and htmxlintrin.h header files
Since this is first use of target-specific intrinsics on the platform,
the patch creates the include/clang/Basic/BuiltinsSystemZ.def file and
hooks it up in TargetBuiltins.h and lib/Basic/Targets.cpp.
An associated LLVM patch adds the required LLVM IR intrinsics.
For reference, the transactional-execution instructions are documented
in the z/Architecture Principles of Operation for the zEC12:
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/download/DZ9ZR009.pdf
The associated builtins are documented in the GCC manual:
http://gcc.gnu.org/onlinedocs/gcc/S_002f390-System-z-Built-in-Functions.html
The htmxlintrin.h intrinsics provided for compatibility with the IBM XL
compiler are documented in the "z/OS XL C/C++ Programming Guide".
llvm-svn: 233804
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/builtins-systemz-error.c | 9 | ||||
-rw-r--r-- | clang/test/CodeGen/builtins-systemz.c | 144 | ||||
-rw-r--r-- | clang/test/Driver/systemz-features.cpp | 15 | ||||
-rw-r--r-- | clang/test/Preprocessor/predefined-arch-macros.c | 27 |
4 files changed, 195 insertions, 0 deletions
diff --git a/clang/test/CodeGen/builtins-systemz-error.c b/clang/test/CodeGen/builtins-systemz-error.c new file mode 100644 index 00000000000..73431b0a320 --- /dev/null +++ b/clang/test/CodeGen/builtins-systemz-error.c @@ -0,0 +1,9 @@ +// REQUIRES: systemz-registered-target +// RUN: %clang_cc1 -target-cpu zEC12 -triple s390x-unknown-unknown \ +// RUN: -Wall -Wno-unused -Werror -fsyntax-only -verify %s + +void test1(void) { + __builtin_tabort (0); // expected-error {{invalid transaction abort code}} + __builtin_tabort (255); // expected-error {{invalid transaction abort code}} +} + diff --git a/clang/test/CodeGen/builtins-systemz.c b/clang/test/CodeGen/builtins-systemz.c new file mode 100644 index 00000000000..f5de7009acb --- /dev/null +++ b/clang/test/CodeGen/builtins-systemz.c @@ -0,0 +1,144 @@ +// REQUIRES: systemz-registered-target +// RUN: %clang_cc1 -target-cpu zEC12 -triple s390x-ibm-linux -Wall -Wno-unused -Werror -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -target-cpu zEC12 -triple s390x-ibm-linux -Wall -Wno-unused -Werror -emit-llvm -x c++ %s -o - | FileCheck %s + +#include <stdint.h> +#include <htmintrin.h> + +int global = 0; +uint64_t g; +struct __htm_tdb global_tdb; + +void test_htm1(struct __htm_tdb *tdb, int reg, int *mem, uint64_t *mem64) { +// CHECK-LABEL: test_htm1 + + __builtin_tbegin ((void *)0); +// CHECK: call i32 @llvm.s390.tbegin(i8* null, i32 65292) + __builtin_tbegin ((void *)0x12345678); +// CHECK: call i32 @llvm.s390.tbegin(i8* inttoptr (i64 305419896 to i8*), i32 65292) + __builtin_tbegin (tdb); +// CHECK: call i32 @llvm.s390.tbegin(i8* %{{.*}}, i32 65292) + __builtin_tbegin (&global_tdb); +// CHECK: call i32 @llvm.s390.tbegin(i8* getelementptr inbounds (%struct.__htm_tdb, %struct.__htm_tdb* @global_tdb, i32 0, i32 0), i32 65292) + + __builtin_tbegin_nofloat ((void *)0); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* null, i32 65292) + __builtin_tbegin_nofloat ((void *)0x12345678); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* inttoptr (i64 305419896 to i8*), i32 65292) + __builtin_tbegin_nofloat (tdb); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* %{{.*}}, i32 65292) + __builtin_tbegin_nofloat (&global_tdb); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* getelementptr inbounds (%struct.__htm_tdb, %struct.__htm_tdb* @global_tdb, i32 0, i32 0), i32 65292) + + __builtin_tbegin_retry ((void *)0, 6); +// CHECK: call i32 @llvm.s390.tbegin(i8* null, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry ((void *)0x12345678, 6); +// CHECK: call i32 @llvm.s390.tbegin(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry (tdb, 6); +// CHECK: call i32 @llvm.s390.tbegin(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry (&global_tdb, 6); +// CHECK: call i32 @llvm.s390.tbegin(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + + __builtin_tbegin_retry_nofloat ((void *)0, 6); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* null, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry_nofloat ((void *)0x12345678, 6); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry_nofloat (tdb, 6); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tbegin_retry_nofloat (&global_tdb, 6); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* %{{.*}}, i32 65292) +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + + __builtin_tbeginc (); +// CHECK: call void @llvm.s390.tbeginc(i8* null, i32 65288) + + __builtin_tabort (256); +// CHECK: call void @llvm.s390.tabort(i64 256) + __builtin_tabort (-1); +// CHECK: call void @llvm.s390.tabort(i64 -1) + __builtin_tabort (reg); +// CHECK: call void @llvm.s390.tabort(i64 %{{.*}}) + + __builtin_tend(); +// CHECK: call i32 @llvm.s390.tend() + + int n = __builtin_tx_nesting_depth(); +// CHECK: call i32 @llvm.s390.etnd() + + __builtin_non_tx_store (mem64, 0); +// CHECK: call void @llvm.s390.ntstg(i64 0, i64* %{{.*}}) + const uint64_t val_var = 0x1122334455667788; + __builtin_non_tx_store (mem64, val_var); +// CHECK: call void @llvm.s390.ntstg(i64 1234605616436508552, i64* %{{.*}}) + __builtin_non_tx_store (mem64, (uint64_t)reg); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* %{{.*}}) + __builtin_non_tx_store (mem64, g); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* %{{.*}}) + __builtin_non_tx_store ((uint64_t *)0, 0); +// CHECK: call void @llvm.s390.ntstg(i64 0, i64* null) + __builtin_non_tx_store ((uint64_t *)0x12345678, 0); +// CHECK: call void @llvm.s390.ntstg(i64 0, i64* inttoptr (i64 305419896 to i64*)) + __builtin_non_tx_store (&g, 23); +// CHECK: call void @llvm.s390.ntstg(i64 23, i64* @g) + __builtin_non_tx_store (&g, reg); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* @g) + __builtin_non_tx_store (&g, *mem); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* @g) + __builtin_non_tx_store (&g, global); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* @g) + + __builtin_tx_assist (0); +// CHECK: call void @llvm.s390.ppa.txassist(i32 0) + __builtin_tx_assist (1); +// CHECK: call void @llvm.s390.ppa.txassist(i32 1) + __builtin_tx_assist (reg); +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tx_assist (*mem); +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) + __builtin_tx_assist (global); +// CHECK: call void @llvm.s390.ppa.txassist(i32 %{{.*}}) +} + +#include <htmxlintrin.h> + +void test_htmxl1(void) { +// CHECK-LABEL: test_htmxl1 + + struct __htm_tdb tdb_struct; + void * const tdb = &tdb_struct; + long result; + unsigned char code; + + result = __TM_simple_begin (); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* null, i32 65292) + result = __TM_begin (tdb); +// CHECK: call i32 @llvm.s390.tbegin.nofloat(i8* %{{.*}}, i32 65292) + result = __TM_end (); +// CHECK: call i32 @llvm.s390.tend() + __TM_abort (); +// CHECK: call void @llvm.s390.tabort(i64 256) + __TM_named_abort (42); +// CHECK: call void @llvm.s390.tabort(i64 %{{.*}}) + __TM_non_transactional_store (&g, 42); +// CHECK: call void @llvm.s390.ntstg(i64 %{{.*}}, i64* %{{.*}}) + result = __TM_nesting_depth (tdb); +// CHECK: call i32 @llvm.s390.etnd() + + result = __TM_is_user_abort (tdb); + result = __TM_is_named_user_abort (tdb, &code); + result = __TM_is_illegal (tdb); + result = __TM_is_footprint_exceeded (tdb); + result = __TM_is_nested_too_deep (tdb); + result = __TM_is_conflict (tdb); + result = __TM_is_failure_persistent (result); + result = __TM_failure_address (tdb); + result = __TM_failure_code (tdb); +} + diff --git a/clang/test/Driver/systemz-features.cpp b/clang/test/Driver/systemz-features.cpp new file mode 100644 index 00000000000..25937d1cdce --- /dev/null +++ b/clang/test/Driver/systemz-features.cpp @@ -0,0 +1,15 @@ + +// RUN: %clang -target s390x-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-DEFAULT %s +// CHECK-DEFAULT-NOT: "-target-feature" "+transactional-execution" +// CHECK-DEFAULT-NOT: "-target-feature" "-transactional-execution" + +// RUN: %clang -target s390x-unknown-linux-gnu %s -mhtm -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-HTM %s +// RUN: %clang -target s390x-unknown-linux-gnu %s -mno-htm -mhtm -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-HTM %s +// CHECK-HTM: "-target-feature" "+transactional-execution" +// CHECK-HTM-NOT: "-target-feature" "-transactional-execution" + +// RUN: %clang -target s390x-unknown-linux-gnu %s -mno-htm -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOHTM %s +// RUN: %clang -target s390x-unknown-linux-gnu %s -mhtm -mno-htm -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOHTM %s +// CHECK-NOHTM: "-target-feature" "-transactional-execution" +// CHECK-NOHTM-NOT: "-target-feature" "+transactional-execution" + diff --git a/clang/test/Preprocessor/predefined-arch-macros.c b/clang/test/Preprocessor/predefined-arch-macros.c index 6e3743da951..9fee3b62940 100644 --- a/clang/test/Preprocessor/predefined-arch-macros.c +++ b/clang/test/Preprocessor/predefined-arch-macros.c @@ -1675,3 +1675,30 @@ // // CHECK_PPC_CRYPTO_M64: #define __CRYPTO__ // + +// Begin SystemZ/GCC/Linux tests ---------------- +// +// RUN: %clang -march=z10 -E -dM %s -o - 2>&1 \ +// RUN: -target s390x-unknown-linux \ +// RUN: | FileCheck %s -check-prefix=CHECK_SYSTEMZ_Z10 +// +// CHECK_SYSTEMZ_Z10: #define __LONG_DOUBLE_128__ 1 +// CHECK_SYSTEMZ_Z10: #define __s390__ 1 +// CHECK_SYSTEMZ_Z10: #define __s390x__ 1 +// CHECK_SYSTEMZ_Z10: #define __zarch__ 1 +// +// RUN: %clang -march=zEC12 -E -dM %s -o - 2>&1 \ +// RUN: -target s390x-unknown-linux \ +// RUN: | FileCheck %s -check-prefix=CHECK_SYSTEMZ_ZEC12 +// +// CHECK_SYSTEMZ_ZEC12: #define __HTM__ 1 +// CHECK_SYSTEMZ_ZEC12: #define __LONG_DOUBLE_128__ 1 +// CHECK_SYSTEMZ_ZEC12: #define __s390__ 1 +// CHECK_SYSTEMZ_ZEC12: #define __s390x__ 1 +// CHECK_SYSTEMZ_ZEC12: #define __zarch__ 1 +// +// RUN: %clang -mhtm -E -dM %s -o - 2>&1 \ +// RUN: -target s390x-unknown-linux \ +// RUN: | FileCheck %s -check-prefix=CHECK_SYSTEMZ_HTM +// +// CHECK_SYSTEMZ_HTM: #define __HTM__ 1 |