Make MTE intrinsics available in function scope too.
Followup from D133359.
Reviewed By: dmgreen
Differential Revision: https://reviews.llvm.org/D136062
TARGET_BUILTIN(__builtin_arm_crc32cd, "UiUiWUi", "nc", "crc")
// Memory Tagging Extensions (MTE)
-BUILTIN(__builtin_arm_irg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_addg, "v*v*Ui", "t")
-BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t")
-BUILTIN(__builtin_arm_ldg, "v*v*", "t")
-BUILTIN(__builtin_arm_stg, "vv*", "t")
-BUILTIN(__builtin_arm_subp, "Uiv*v*", "t")
+TARGET_BUILTIN(__builtin_arm_irg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_addg, "v*v*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_gmi, "Uiv*Ui", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_ldg, "v*v*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_stg, "vv*", "t", "mte")
+TARGET_BUILTIN(__builtin_arm_subp, "Uiv*v*", "t", "mte")
// Memory Operations
-BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "")
+TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", "mte,mops")
// Memory barrier
BUILTIN(__builtin_arm_dmb, "vUi", "nc")
#define __arm_wsrf64(sysreg, v) __arm_wsr64(sysreg, __builtin_bit_cast(uint64_t, v))
/* Memory Tagging Extensions (MTE) Intrinsics */
-#if defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
+#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE
#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)
#define __arm_mte_exclude_tag(__ptr, __excluded) __builtin_arm_gmi(__ptr, __excluded)
#define __arm_mte_get_tag(__ptr) __builtin_arm_ldg(__ptr)
#define __arm_mte_set_tag(__ptr) __builtin_arm_stg(__ptr)
#define __arm_mte_ptrdiff(__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
-#endif
/* Memory Operations Intrinsics */
-#if defined(__ARM_FEATURE_MOPS) && __ARM_FEATURE_MOPS && defined(__ARM_FEATURE_MEMORY_TAGGING) && __ARM_FEATURE_MEMORY_TAGGING
#define __arm_mops_memset_tag(__tagged_address, __value, __size) \
__builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
#endif
// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -target-feature +mops -target-feature +mte -w -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-MOPS %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -target-feature +mops -Wno-implicit-function-declaration -w -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-NOMOPS %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -Wno-implicit-function-declaration -target-feature +mte -w -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-NOMOPS %s
-// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -Wno-implicit-function-declaration -w -S -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -target-feature +mops -Wno-implicit-function-declaration -w -S -emit-llvm -o - %s 2>&1 | FileCheck --check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -Wno-implicit-function-declaration -target-feature +mte -w -S -emit-llvm -o - %s 2>&1 | FileCheck --check-prefix=CHECK-NOMOPS %s
+// RUN: not %clang_cc1 -triple aarch64-arm-unknown-eabi -Wno-int-conversion -Wno-implicit-function-declaration -w -S -emit-llvm -o - %s 2>&1 | FileCheck --check-prefix=CHECK-NOMOPS %s
#include <arm_acle.h>
#include <stddef.h>
// CHECK-LABEL: @bzero_0(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
+// CHECK-NOMOPS: '__builtin_arm_mops_memset_tag' needs target feature mte,mops
void *bzero_0(void *dst) {
return __arm_mops_memset_tag(dst, 0, 0);
}
// CHECK-LABEL: @bzero_1(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *bzero_1(void *dst) {
return __arm_mops_memset_tag(dst, 0, 1);
}
// CHECK-LABEL: @bzero_10(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *bzero_10(void *dst) {
return __arm_mops_memset_tag(dst, 0, 10);
}
// CHECK-LABEL: @bzero_10000(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *bzero_10000(void *dst) {
return __arm_mops_memset_tag(dst, 0, 10000);
}
// CHECK-LABEL: @bzero_n(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *bzero_n(void *dst, size_t size) {
return __arm_mops_memset_tag(dst, 0, size);
}
// CHECK-LABEL: @memset_0(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *memset_0(void *dst, int value) {
return __arm_mops_memset_tag(dst, value, 0);
}
// CHECK-LABEL: @memset_1(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *memset_1(void *dst, int value) {
return __arm_mops_memset_tag(dst, value, 1);
}
// CHECK-LABEL: @memset_10(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *memset_10(void *dst, int value) {
return __arm_mops_memset_tag(dst, value, 10);
}
// CHECK-LABEL: @memset_10000(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *memset_10000(void *dst, int value) {
return __arm_mops_memset_tag(dst, value, 10000);
}
// CHECK-LABEL: @memset_n(
// CHECK-MOPS: @llvm.aarch64.mops.memset.tag
-// CHECK-NOMOPS-NOT: @llvm.aarch64.mops.memset.tag
void *memset_n(void *dst, int value, size_t size) {
return __arm_mops_memset_tag(dst, value, size);
}
// Test memory tagging extension intrinsics
// RUN: %clang_cc1 -triple aarch64-none-linux-eabi -target-feature +mte -O3 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-eabi -DMTE -O3 -S -emit-llvm -o - %s | FileCheck %s
#include <stddef.h>
#include <arm_acle.h>
+#ifdef MTE
+#define attribute __attribute__((target("mte")))
+#else
+#define attribute
+#endif
+
// CHECK-LABEL: define{{.*}} ptr @create_tag1
+attribute
int *create_tag1(int *a, unsigned b) {
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
}
// CHECK-LABEL: define{{.*}} ptr @create_tag2
+attribute
short *create_tag2(short *a, unsigned b) {
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
}
// CHECK-LABEL: define{{.*}} ptr @create_tag3
+attribute
char *create_tag3(char *a, unsigned b) {
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call ptr @llvm.aarch64.irg(ptr %a, i64 [[T1]])
}
// CHECK-LABEL: define{{.*}} ptr @increment_tag1
+attribute
char *increment_tag1(char *a) {
// CHECK: call ptr @llvm.aarch64.addg(ptr %a, i64 3)
return __arm_mte_increment_tag(a,3);
}
// CHECK-LABEL: define{{.*}} ptr @increment_tag2
+attribute
short *increment_tag2(short *a) {
// CHECK: [[T1:%[0-9]+]] = tail call ptr @llvm.aarch64.addg(ptr %a, i64 3)
return __arm_mte_increment_tag(a,3);
}
// CHECK-LABEL: define{{.*}} i32 @exclude_tag
+attribute
unsigned exclude_tag(int *a, unsigned m) {
// CHECK: [[T0:%[0-9]+]] = zext i32 %m to i64
// CHECK: [[T2:%[0-9]+]] = tail call i64 @llvm.aarch64.gmi(ptr %a, i64 [[T0]])
}
// CHECK-LABEL: define{{.*}} ptr @get_tag1
+attribute
int *get_tag1(int *a) {
// CHECK: [[T1:%[0-9]+]] = tail call ptr @llvm.aarch64.ldg(ptr %a, ptr %a)
return __arm_mte_get_tag(a);
}
// CHECK-LABEL: define{{.*}} ptr @get_tag2
+attribute
short *get_tag2(short *a) {
// CHECK: [[T1:%[0-9]+]] = tail call ptr @llvm.aarch64.ldg(ptr %a, ptr %a)
return __arm_mte_get_tag(a);
}
// CHECK-LABEL: define{{.*}} void @set_tag1
+attribute
void set_tag1(int *a) {
// CHECK: tail call void @llvm.aarch64.stg(ptr %a, ptr %a)
__arm_mte_set_tag(a);
}
// CHECK-LABEL: define{{.*}} i64 @subtract_pointers
+attribute
ptrdiff_t subtract_pointers(int *a, int *b) {
// CHECK: [[T2:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(ptr %a, ptr %b)
// CHECK: ret i64 [[T2]]
}
// CHECK-LABEL: define{{.*}} i64 @subtract_pointers_null_1
+attribute
ptrdiff_t subtract_pointers_null_1(int *a) {
// CHECK: [[T1:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(ptr %a, ptr null)
// CHECK: ret i64 [[T1]]
}
// CHECK-LABEL: define{{.*}} i64 @subtract_pointers_null_2
+attribute
ptrdiff_t subtract_pointers_null_2(int *a) {
// CHECK: [[T1:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(ptr null, ptr %a)
// CHECK: ret i64 [[T1]]
// Check arithmetic promotion on return type
// CHECK-LABEL: define{{.*}} i32 @subtract_pointers4
+attribute
int subtract_pointers4(void* a, void *b) {
// CHECK: [[T0:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(ptr %a, ptr %b)
// CHECK-NEXT: %cmp = icmp slt i64 [[T0]], 1
// RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -fsyntax-only -verify
// RUN: %clang_cc1 -triple arm64-arm-eabi %s -target-feature +mte -x c++ -fsyntax-only -verify
+// RUN: %clang_cc1 -triple arm64-arm-eabi %s -DNO_MTE -x c++ -S -emit-llvm -verify
#include <stddef.h>
#include <arm_acle.h>
+#ifndef NO_MTE
int *create_tag1(int a, unsigned b) {
// expected-error@+1 {{first argument of MTE builtin function must be a pointer ('int' invalid)}}
return __arm_mte_create_random_tag(a,b);
return __arm_mte_ptrdiff(nullptr, nullptr);
}
#endif
+
+#else
+int *create_tag1(int *a, unsigned b) {
+ // expected-error@+1 {{'__builtin_arm_irg' needs target feature mte}}
+ return __arm_mte_create_random_tag(a,b);
+}
+#endif
\ No newline at end of file