r366322 - [AArch64] Add support for Transactional Memory Extension (TME)
Momchil Velikov via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 06:23:27 PDT 2019
Author: chill
Date: Wed Jul 17 06:23:27 2019
New Revision: 366322
URL: http://llvm.org/viewvc/llvm-project?rev=366322&view=rev
Log:
[AArch64] Add support for Transactional Memory Extension (TME)
TME is a future architecture technology, documented in
https://developer.arm.com/architectures/cpu-architecture/a-profile/exploration-tools
https://developer.arm.com/docs/ddi0601/a
More about the future architectures:
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/new-technologies-for-the-arm-a-profile-architecture
This patch adds support for the TME instructions TSTART, TTEST, TCOMMIT, and
TCANCEL and the target feature/arch extension "tme".
It also implements TME builtin functions, defined in ACLE Q2 2019
(https://developer.arm.com/docs/101028/latest)
Patch by Javed Absar and Momchil Velikov
Differential Revision: https://reviews.llvm.org/D64416
Added:
cfe/trunk/test/CodeGen/aarch64-tme-tcancel-arg.cpp
cfe/trunk/test/CodeGen/aarch64-tme.c
cfe/trunk/test/Sema/aarch64-tme-errors.c
cfe/trunk/test/Sema/aarch64-tme-tcancel-const-error.c
cfe/trunk/test/Sema/aarch64-tme-tcancel-range-error.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
cfe/trunk/lib/Basic/Targets/AArch64.cpp
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/Headers/arm_acle.h
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAArch64.def?rev=366322&r1=366321&r2=366322&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def Wed Jul 17 06:23:27 2019
@@ -91,6 +91,12 @@ LANGBUILTIN(__sevl, "v", "", ALL_MS_L
// Misc
BUILTIN(__builtin_sponentry, "v*", "c")
+// Transactional Memory Extension
+BUILTIN(__builtin_arm_tstart, "WUi", "nj")
+BUILTIN(__builtin_arm_tcommit, "v", "n")
+BUILTIN(__builtin_arm_tcancel, "vWUIi", "nr")
+BUILTIN(__builtin_arm_ttest, "WUi", "nc")
+
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=366322&r1=366321&r2=366322&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp Wed Jul 17 06:23:27 2019
@@ -219,6 +219,9 @@ void AArch64TargetInfo::getTargetDefines
if (HasMTE)
Builder.defineMacro("__ARM_FEATURE_MEMORY_TAGGING", "1");
+ if (HasTME)
+ Builder.defineMacro("__ARM_FEATURE_TME", "1");
+
if ((FPU & NeonMode) && HasFP16FML)
Builder.defineMacro("__ARM_FEATURE_FP16FML", "1");
@@ -270,6 +273,7 @@ bool AArch64TargetInfo::handleTargetFeat
HasDotProd = false;
HasFP16FML = false;
HasMTE = false;
+ HasTME = false;
ArchKind = llvm::AArch64::ArchKind::ARMV8A;
for (const auto &Feature : Features) {
@@ -301,6 +305,8 @@ bool AArch64TargetInfo::handleTargetFeat
HasFP16FML = true;
if (Feature == "+mte")
HasMTE = true;
+ if (Feature == "+tme")
+ HasTME = true;
}
setDataLayout();
Modified: cfe/trunk/lib/Basic/Targets/AArch64.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.h?rev=366322&r1=366321&r2=366322&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AArch64.h (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.h Wed Jul 17 06:23:27 2019
@@ -35,6 +35,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64Tar
bool HasDotProd;
bool HasFP16FML;
bool HasMTE;
+ bool HasTME;
llvm::AArch64::ArchKind ArchKind;
Modified: cfe/trunk/lib/Headers/arm_acle.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/arm_acle.h?rev=366322&r1=366321&r2=366322&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/arm_acle.h (original)
+++ cfe/trunk/lib/Headers/arm_acle.h Wed Jul 17 06:23:27 2019
@@ -613,7 +613,7 @@ __jcvt(double __a) {
#define __arm_wsr64(sysreg, v) __builtin_arm_wsr64(sysreg, v)
#define __arm_wsrp(sysreg, v) __builtin_arm_wsrp(sysreg, v)
-// Memory Tagging Extensions (MTE) Intrinsics
+/* Memory Tagging Extensions (MTE) Intrinsics */
#if __ARM_FEATURE_MEMORY_TAGGING
#define __arm_mte_create_random_tag(__ptr, __mask) __builtin_arm_irg(__ptr, __mask)
#define __arm_mte_increment_tag(__ptr, __tag_offset) __builtin_arm_addg(__ptr, __tag_offset)
@@ -623,6 +623,28 @@ __jcvt(double __a) {
#define __arm_mte_ptrdiff(__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
#endif
+/* Transactional Memory Extension (TME) Intrinsics */
+#if __ARM_FEATURE_TME
+
+#define _TMFAILURE_REASON 0x00007fffu
+#define _TMFAILURE_RTRY 0x00008000u
+#define _TMFAILURE_CNCL 0x00010000u
+#define _TMFAILURE_MEM 0x00020000u
+#define _TMFAILURE_IMP 0x00040000u
+#define _TMFAILURE_ERR 0x00080000u
+#define _TMFAILURE_SIZE 0x00100000u
+#define _TMFAILURE_NEST 0x00200000u
+#define _TMFAILURE_DBG 0x00400000u
+#define _TMFAILURE_INT 0x00800000u
+#define _TMFAILURE_TRIVIAL 0x01000000u
+
+#define __tstart() __builtin_arm_tstart()
+#define __tcommit() __builtin_arm_tcommit()
+#define __tcancel(__arg) __builtin_arm_tcancel(__arg)
+#define __ttest() __builtin_arm_ttest()
+
+#endif /* __ARM_FEATURE_TME */
+
#if defined(__cplusplus)
}
#endif
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=366322&r1=366321&r2=366322&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jul 17 06:23:27 2019
@@ -1928,6 +1928,7 @@ bool Sema::CheckAArch64BuiltinFunctionCa
case AArch64::BI__builtin_arm_dmb:
case AArch64::BI__builtin_arm_dsb:
case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
+ case AArch64::BI__builtin_arm_tcancel: l = 0; u = 65535; break;
}
return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
Added: cfe/trunk/test/CodeGen/aarch64-tme-tcancel-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/aarch64-tme-tcancel-arg.cpp?rev=366322&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/aarch64-tme-tcancel-arg.cpp (added)
+++ cfe/trunk/test/CodeGen/aarch64-tme-tcancel-arg.cpp Wed Jul 17 06:23:27 2019
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -S -emit-llvm %s -o - | FileCheck %s
+
+#define A -1
+constexpr int f() { return 65536; }
+
+void t_cancel() {
+ __builtin_arm_tcancel(f() + A);
+}
+
+// CHECK: call void @llvm.aarch64.tcancel(i64 65535)
Added: cfe/trunk/test/CodeGen/aarch64-tme.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/aarch64-tme.c?rev=366322&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/aarch64-tme.c (added)
+++ cfe/trunk/test/CodeGen/aarch64-tme.c Wed Jul 17 06:23:27 2019
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -DUSE_ACLE -triple aarch64-eabi -target-feature +tme -S -emit-llvm %s -o - | FileCheck %s
+
+#ifdef USE_ACLE
+#include "arm_acle.h"
+void test_tme_funcs() {
+ __tstart();
+ (void)__ttest();
+ __tcommit();
+ __tcancel(0x789a);
+}
+#else
+void test_tme_funcs() {
+ __builtin_arm_tstart();
+ (void)__builtin_arm_ttest();
+ __builtin_arm_tcommit();
+ __builtin_arm_tcancel(0x789a);
+}
+#endif
+// CHECK: call i64 @llvm.aarch64.tstart()
+// CHECK: call i64 @llvm.aarch64.ttest()
+// CHECK: call void @llvm.aarch64.tcommit()
+// CHECK: call void @llvm.aarch64.tcancel(i64 30874)
+
+// CHECK: declare i64 @llvm.aarch64.tstart() #1
+// CHECK: declare i64 @llvm.aarch64.ttest() #1
+// CHECK: declare void @llvm.aarch64.tcommit() #1
+// CHECK: declare void @llvm.aarch64.tcancel(i64 immarg) #2
+
+#ifdef __ARM_FEATURE_TME
+void arm_feature_tme_defined() {}
+#endif
+// CHECK: define void @arm_feature_tme_defined()
+
+// CHECK: attributes #1 = { nounwind }
+// CHECK: attributes #2 = { noreturn nounwind }
Added: cfe/trunk/test/Sema/aarch64-tme-errors.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/aarch64-tme-errors.c?rev=366322&view=auto
==============================================================================
--- cfe/trunk/test/Sema/aarch64-tme-errors.c (added)
+++ cfe/trunk/test/Sema/aarch64-tme-errors.c Wed Jul 17 06:23:27 2019
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -verify %s
+
+#include "arm_acle.h"
+
+void test_no_tme_funcs() {
+ __tstart(); // expected-warning{{implicit declaration of function '__tstart'}}
+ __builtin_tstart(); // expected-error{{use of unknown builtin '__builtin_tstart'}}
+}
Added: cfe/trunk/test/Sema/aarch64-tme-tcancel-const-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/aarch64-tme-tcancel-const-error.c?rev=366322&view=auto
==============================================================================
--- cfe/trunk/test/Sema/aarch64-tme-tcancel-const-error.c (added)
+++ cfe/trunk/test/Sema/aarch64-tme-tcancel-const-error.c Wed Jul 17 06:23:27 2019
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -verify %s
+void t_cancel(unsigned short u) {
+ __builtin_arm_tcancel(u); // expected-error{{argument to '__builtin_arm_tcancel' must be a constant integer}}
+}
Added: cfe/trunk/test/Sema/aarch64-tme-tcancel-range-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/aarch64-tme-tcancel-range-error.c?rev=366322&view=auto
==============================================================================
--- cfe/trunk/test/Sema/aarch64-tme-tcancel-range-error.c (added)
+++ cfe/trunk/test/Sema/aarch64-tme-tcancel-range-error.c Wed Jul 17 06:23:27 2019
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -verify %s
+void t_cancel() {
+ __builtin_arm_tcancel(0x12345u); // expected-error{{argument value 74565 is outside the valid range [0, 65535]}}
+}
More information about the cfe-commits
mailing list