r343824 - [COFF, ARM64] Add __getReg intrinsic
Mandeep Singh Grang via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 4 15:32:42 PDT 2018
Author: mgrang
Date: Thu Oct 4 15:32:42 2018
New Revision: 343824
URL: http://llvm.org/viewvc/llvm-project?rev=343824&view=rev
Log:
[COFF, ARM64] Add __getReg intrinsic
Reviewers: rnk, mstorsjo, compnerd, TomTan, haripul, javed.absar, efriedma
Reviewed By: efriedma
Subscribers: peter.smith, efriedma, kristof.beyls, chrib, cfe-commits
Differential Revision: https://reviews.llvm.org/D52838
Added:
cfe/trunk/test/Sema/builtins-microsoft-arm64.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
Modified: cfe/trunk/include/clang/Basic/BuiltinsAArch64.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAArch64.def?rev=343824&r1=343823&r2=343824&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsAArch64.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAArch64.def Thu Oct 4 15:32:42 2018
@@ -104,6 +104,7 @@ TARGET_HEADER_BUILTIN(_InterlockedOr64,
TARGET_HEADER_BUILTIN(_InterlockedXor64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
#undef BUILTIN
#undef LANGBUILTIN
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=343824&r1=343823&r2=343824&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Oct 4 15:32:42 2018
@@ -6576,6 +6576,23 @@ Value *CodeGenFunction::EmitAArch64Built
return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr");
}
+ if (BuiltinID == AArch64::BI__getReg) {
+ APSInt Value;
+ if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
+ llvm_unreachable("Sema will ensure that the parameter is constant");
+
+ LLVMContext &Context = CGM.getLLVMContext();
+ std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
+
+ llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
+ llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+ llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+
+ llvm::Value *F =
+ CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+ return Builder.CreateCall(F, Metadata);
+ }
+
if (BuiltinID == AArch64::BI__builtin_arm_clrex) {
Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex);
return Builder.CreateCall(F);
Modified: cfe/trunk/lib/Headers/intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=343824&r1=343823&r2=343824&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/intrin.h (original)
+++ cfe/trunk/lib/Headers/intrin.h Thu Oct 4 15:32:42 2018
@@ -865,6 +865,13 @@ __nop(void) {
#endif
/*----------------------------------------------------------------------------*\
+|* MS AArch64 specific
+\*----------------------------------------------------------------------------*/
+#if defined(__aarch64__)
+unsigned __int64 __getReg(int);
+#endif
+
+/*----------------------------------------------------------------------------*\
|* Privileged intrinsics
\*----------------------------------------------------------------------------*/
#if defined(__i386__) || defined(__x86_64__)
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=343824&r1=343823&r2=343824&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Oct 4 15:32:42 2018
@@ -1749,6 +1749,9 @@ bool Sema::CheckAArch64BuiltinFunctionCa
BuiltinID == AArch64::BI__builtin_arm_wsrp)
return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
+ if (BuiltinID == AArch64::BI__getReg)
+ return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
+
if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
return true;
Modified: cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c?rev=343824&r1=343823&r2=343824&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/arm64-microsoft-intrinsics.c Thu Oct 4 15:32:42 2018
@@ -66,3 +66,15 @@ void check_ReadWriteBarrier() {
// CHECK-MSVC: fence syncscope("singlethread")
// CHECK-LINUX: error: implicit declaration of function '_ReadWriteBarrier'
+
+unsigned __int64 check__getReg() {
+ unsigned volatile __int64 reg;
+ reg = __getReg(18);
+ reg = __getReg(31);
+ return reg;
+}
+
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !2)
+// CHECK-MSVC: call i64 @llvm.read_register.i64(metadata !3)
+// CHECK-MSVC: !2 = !{!"x18"}
+// CHECK-MSVC: !3 = !{!"sp"}
Added: cfe/trunk/test/Sema/builtins-microsoft-arm64.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins-microsoft-arm64.c?rev=343824&view=auto
==============================================================================
--- cfe/trunk/test/Sema/builtins-microsoft-arm64.c (added)
+++ cfe/trunk/test/Sema/builtins-microsoft-arm64.c Thu Oct 4 15:32:42 2018
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple arm64-windows -fsyntax-only -verify \
+// RUN: -fms-compatibility -ffreestanding -fms-compatibility-version=17.00 %s
+
+#include <intrin.h>
+
+void check__getReg() {
+ __getReg(-1); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+ __getReg(32); // expected-error-re {{argument value {{.*}} is outside the valid range}}
+}
More information about the cfe-commits
mailing list