]> granicus.if.org Git - clang/commitdiff
Port memory barriers intrinsics to AArch64
authorYi Kong <Yi.Kong@arm.com>
Thu, 17 Jul 2014 10:52:06 +0000 (10:52 +0000)
committerYi Kong <Yi.Kong@arm.com>
Thu, 17 Jul 2014 10:52:06 +0000 (10:52 +0000)
Memory barrier __builtin_arm_[dmb, dsb, isb] intrinsics are required to
implement their corresponding ACLE and MSVC intrinsics.

This patch ports ARM dmb, dsb, isb intrinsic to AArch64.

Requires LLVM r213247.

Differential Revision: http://reviews.llvm.org/D4521

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213250 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/BuiltinsAArch64.def
lib/Sema/SemaChecking.cpp
test/CodeGen/builtins-arm64.c
test/Sema/builtins-arm64.c

index 76dddadb8009e952d5eb114ac6e8ef8b3b0f5a62..695ecf9da5f8313e925c3690c92d2382a9455bd7 100644 (file)
@@ -45,4 +45,9 @@ BUILTIN(__builtin_arm_crc32cw, "UiUiUi", "nc")
 BUILTIN(__builtin_arm_crc32d, "UiUiLUi", "nc")
 BUILTIN(__builtin_arm_crc32cd, "UiUiLUi", "nc")
 
+// Memory barrier
+BUILTIN(__builtin_arm_dmb, "vUi", "nc")
+BUILTIN(__builtin_arm_dsb, "vUi", "nc")
+BUILTIN(__builtin_arm_isb, "vUi", "nc")
+
 #undef BUILTIN
index 976f3a696dfb3b2d89febcb9f8ace1b73fce075a..7a23797d477f795875858bbe8ee45a80e828f0c2 100644 (file)
@@ -645,7 +645,18 @@ bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
   if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
     return true;
 
-  return false;
+  // For intrinsics which take an immediate value as part of the instruction,
+  // range check them here.
+  unsigned i = 0, l = 0, u = 0;
+  switch (BuiltinID) {
+  default: return false;
+  case AArch64::BI__builtin_arm_dmb:
+  case AArch64::BI__builtin_arm_dsb:
+  case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
+  }
+
+  // FIXME: VFP Intrinsics should error if VFP not present.
+  return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
 }
 
 bool Sema::CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
index 8614be0592b6da36542b7061cb1b4de829b8d412..cfa11812279325393e68bcebb269bff87c1e3a7b 100644 (file)
@@ -23,3 +23,9 @@ void hints() {
   __builtin_arm_sev();    //CHECK: call {{.*}} @llvm.aarch64.hint(i32 4)
   __builtin_arm_sevl();   //CHECK: call {{.*}} @llvm.aarch64.hint(i32 5)
 }
+
+void barriers() {
+  __builtin_arm_dmb(1);  //CHECK: call {{.*}} @llvm.aarch64.dmb(i32 1)
+  __builtin_arm_dsb(2);  //CHECK: call {{.*}} @llvm.aarch64.dsb(i32 2)
+  __builtin_arm_isb(3);  //CHECK: call {{.*}} @llvm.aarch64.isb(i32 3)
+}
index f2bdc9dea2b37f4cce456ce82a4c3aa68575a7b3..113f4fc302da324e2f702902ba007a72ded25f15 100644 (file)
@@ -16,3 +16,9 @@ void test_clear_cache_voids(void *start, void *end) {
 void test_clear_cache_no_args() {
   __clear_cache(); // expected-error {{too few arguments to function call}}
 }
+
+void test_memory_barriers() {
+  __builtin_arm_dmb(16); // expected-error {{argument should be a value from 0 to 15}}
+  __builtin_arm_dsb(17); // expected-error {{argument should be a value from 0 to 15}}
+  __builtin_arm_isb(18); // expected-error {{argument should be a value from 0 to 15}}
+}