Skip to content

Commit a36d314

Browse files
[AArch64] Add support for Transactional Memory Extension (TME)
Re-commit r366322 after some fixes 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) Differential Revision: https://reviews.llvm.org/D64416 Patch by Javed Absar and Momchil Velikov llvm-svn: 367428
1 parent 10dd296 commit a36d314

File tree

20 files changed

+326
-13
lines changed

20 files changed

+326
-13
lines changed

clang/include/clang/Basic/BuiltinsAArch64.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ LANGBUILTIN(__sevl, "v", "", ALL_MS_LANGUAGES)
9191
// Misc
9292
BUILTIN(__builtin_sponentry, "v*", "c")
9393

94+
// Transactional Memory Extension
95+
BUILTIN(__builtin_arm_tstart, "WUi", "nj")
96+
BUILTIN(__builtin_arm_tcommit, "v", "n")
97+
BUILTIN(__builtin_arm_tcancel, "vWUIi", "n")
98+
BUILTIN(__builtin_arm_ttest, "WUi", "nc")
99+
94100
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
95101
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
96102
TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
216216
if (HasMTE)
217217
Builder.defineMacro("__ARM_FEATURE_MEMORY_TAGGING", "1");
218218

219+
if (HasTME)
220+
Builder.defineMacro("__ARM_FEATURE_TME", "1");
221+
219222
if ((FPU & NeonMode) && HasFP16FML)
220223
Builder.defineMacro("__ARM_FEATURE_FP16FML", "1");
221224

@@ -267,6 +270,7 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
267270
HasDotProd = false;
268271
HasFP16FML = false;
269272
HasMTE = false;
273+
HasTME = false;
270274
ArchKind = llvm::AArch64::ArchKind::ARMV8A;
271275

272276
for (const auto &Feature : Features) {
@@ -298,6 +302,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
298302
HasFP16FML = true;
299303
if (Feature == "+mte")
300304
HasMTE = true;
305+
if (Feature == "+tme")
306+
HasTME = true;
301307
}
302308

303309
setDataLayout();

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
3535
bool HasDotProd;
3636
bool HasFP16FML;
3737
bool HasMTE;
38+
bool HasTME;
3839

3940
llvm::AArch64::ArchKind ArchKind;
4041

clang/lib/Headers/arm_acle.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ __jcvt(double __a) {
613613
#define __arm_wsr64(sysreg, v) __builtin_arm_wsr64(sysreg, v)
614614
#define __arm_wsrp(sysreg, v) __builtin_arm_wsrp(sysreg, v)
615615

616-
// Memory Tagging Extensions (MTE) Intrinsics
616+
/* Memory Tagging Extensions (MTE) Intrinsics */
617617
#if __ARM_FEATURE_MEMORY_TAGGING
618618
#define __arm_mte_create_random_tag(__ptr, __mask) __builtin_arm_irg(__ptr, __mask)
619619
#define __arm_mte_increment_tag(__ptr, __tag_offset) __builtin_arm_addg(__ptr, __tag_offset)
@@ -623,6 +623,28 @@ __jcvt(double __a) {
623623
#define __arm_mte_ptrdiff(__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
624624
#endif
625625

626+
/* Transactional Memory Extension (TME) Intrinsics */
627+
#if __ARM_FEATURE_TME
628+
629+
#define _TMFAILURE_REASON 0x00007fffu
630+
#define _TMFAILURE_RTRY 0x00008000u
631+
#define _TMFAILURE_CNCL 0x00010000u
632+
#define _TMFAILURE_MEM 0x00020000u
633+
#define _TMFAILURE_IMP 0x00040000u
634+
#define _TMFAILURE_ERR 0x00080000u
635+
#define _TMFAILURE_SIZE 0x00100000u
636+
#define _TMFAILURE_NEST 0x00200000u
637+
#define _TMFAILURE_DBG 0x00400000u
638+
#define _TMFAILURE_INT 0x00800000u
639+
#define _TMFAILURE_TRIVIAL 0x01000000u
640+
641+
#define __tstart() __builtin_arm_tstart()
642+
#define __tcommit() __builtin_arm_tcommit()
643+
#define __tcancel(__arg) __builtin_arm_tcancel(__arg)
644+
#define __ttest() __builtin_arm_ttest()
645+
646+
#endif /* __ARM_FEATURE_TME */
647+
626648
#if defined(__cplusplus)
627649
}
628650
#endif

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,7 @@ bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
19321932
case AArch64::BI__builtin_arm_dmb:
19331933
case AArch64::BI__builtin_arm_dsb:
19341934
case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
1935+
case AArch64::BI__builtin_arm_tcancel: l = 0; u = 65535; break;
19351936
}
19361937

19371938
return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);

clang/test/CodeGen/aarch64-tme.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -S -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -DUSE_ACLE -triple aarch64-eabi -target-feature +tme -S -emit-llvm %s -o - | FileCheck %s
3+
4+
#define A -1
5+
constexpr int f() { return 65536; }
6+
7+
#ifdef USE_ACLE
8+
#include "arm_acle.h"
9+
void test_tme_funcs() {
10+
__tstart();
11+
(void)__ttest();
12+
__tcommit();
13+
__tcancel(0x789a);
14+
__tcancel(f() + A);
15+
}
16+
#else
17+
void test_tme_funcs() {
18+
__builtin_arm_tstart();
19+
(void)__builtin_arm_ttest();
20+
__builtin_arm_tcommit();
21+
__builtin_arm_tcancel(0x789a);
22+
__builtin_arm_tcancel(f() + A);
23+
}
24+
#endif
25+
// CHECK: call i64 @llvm.aarch64.tstart()
26+
// CHECK: call i64 @llvm.aarch64.ttest()
27+
// CHECK: call void @llvm.aarch64.tcommit()
28+
// CHECK: call void @llvm.aarch64.tcancel(i64 30874)
29+
// CHECK: call void @llvm.aarch64.tcancel(i64 65535)
30+
31+
// CHECK: declare i64 @llvm.aarch64.tstart() #1
32+
// CHECK: declare i64 @llvm.aarch64.ttest() #1
33+
// CHECK: declare void @llvm.aarch64.tcommit() #1
34+
// CHECK: declare void @llvm.aarch64.tcancel(i64 immarg) #1
35+
36+
#ifdef __ARM_FEATURE_TME
37+
extern "C" void arm_feature_tme_defined() {}
38+
#endif
39+
// CHECK: define void @arm_feature_tme_defined()
40+
41+
// CHECK: attributes #1 = { nounwind }
42+

clang/test/Sema/aarch64-tme-errors.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -triple aarch64-eabi -verify %s
2+
3+
#include "arm_acle.h"
4+
5+
void test_no_tme_funcs() {
6+
__tstart(); // expected-warning{{implicit declaration of function '__tstart'}}
7+
__builtin_tstart(); // expected-error{{use of unknown builtin '__builtin_tstart'}}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -verify %s
2+
void t_cancel_const(unsigned short u) {
3+
__builtin_arm_tcancel(u); // expected-error{{argument to '__builtin_arm_tcancel' must be a constant integer}}
4+
}
5+
6+
// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +tme -verify %s
7+
void t_cancel_range() {
8+
__builtin_arm_tcancel(0x12345u); // expected-error{{argument value 74565 is outside the valid range [0, 65535]}}
9+
}

llvm/include/llvm/IR/IntrinsicsAArch64.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,18 @@ def int_aarch64_settag_zero : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty],
733733
def int_aarch64_stgp : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty, llvm_i64_ty],
734734
[IntrWriteMem, IntrArgMemOnly, NoCapture<0>, WriteOnly<0>]>;
735735
}
736+
737+
// Transactional Memory Extension (TME) Intrinsics
738+
let TargetPrefix = "aarch64" in {
739+
def int_aarch64_tstart : GCCBuiltin<"__builtin_arm_tstart">,
740+
Intrinsic<[llvm_i64_ty]>;
741+
742+
def int_aarch64_tcommit : GCCBuiltin<"__builtin_arm_tcommit">, Intrinsic<[]>;
743+
744+
def int_aarch64_tcancel : GCCBuiltin<"__builtin_arm_tcancel">,
745+
Intrinsic<[], [llvm_i64_ty], [ImmArg<0>]>;
746+
747+
def int_aarch64_ttest : GCCBuiltin<"__builtin_arm_ttest">,
748+
Intrinsic<[llvm_i64_ty], [],
749+
[IntrNoMem, IntrHasSideEffects]>;
750+
}

llvm/include/llvm/Support/AArch64TargetParser.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ AARCH64_ARCH_EXT_NAME("memtag", AArch64::AEK_MTE, "+mte", "-mte"
7979
AARCH64_ARCH_EXT_NAME("ssbs", AArch64::AEK_SSBS, "+ssbs", "-ssbs")
8080
AARCH64_ARCH_EXT_NAME("sb", AArch64::AEK_SB, "+sb", "-sb")
8181
AARCH64_ARCH_EXT_NAME("predres", AArch64::AEK_PREDRES, "+predres", "-predres")
82+
AARCH64_ARCH_EXT_NAME("tme", AArch64::AEK_TME, "+tme", "-tme")
8283
#undef AARCH64_ARCH_EXT_NAME
8384

8485
#ifndef AARCH64_CPU_NAME

0 commit comments

Comments
 (0)