Author: Albion Fung Date: 2021-09-23T23:38:59-05:00 New Revision: 840afbde48e90213028174fdba715e10aa39dd85
URL: https://github.com/llvm/llvm-project/commit/840afbde48e90213028174fdba715e10aa39dd85 DIFF: https://github.com/llvm/llvm-project/commit/840afbde48e90213028174fdba715e10aa39dd85.diff LOG: [PowerPC] SemaChecking for darn family of builtins The __darn family of builtins are only available on Pwr9, and only __darn_32 is available on both 64 and 32 bit, while the rest are only available on 64 bit. The patch adds sema checking for these builtins and separate the __darn_32's 32 bit test cases. Differential revision: https://reviews.llvm.org/D110282 Added: Modified: clang/lib/Sema/SemaChecking.cpp clang/test/CodeGen/builtins-ppc-xlcompat-darn.c clang/test/CodeGen/builtins-ppc-xlcompat-error.c clang/test/CodeGen/builtins-ppc.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 5cc968c133ce3..0310e10f93704 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3295,6 +3295,8 @@ static bool isPPC_64Builtin(unsigned BuiltinID) { case PPC::BI__builtin_ppc_insert_exp: case PPC::BI__builtin_ppc_extract_sig: case PPC::BI__builtin_ppc_addex: + case PPC::BI__builtin_darn: + case PPC::BI__builtin_darn_raw: return true; } return false; @@ -3478,6 +3480,11 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, case PPC::BI__builtin_altivec_vcntmbw: case PPC::BI__builtin_altivec_vcntmbd: return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1); + case PPC::BI__builtin_darn: + case PPC::BI__builtin_darn_raw: + case PPC::BI__builtin_darn_32: + return SemaFeatureCheck(*this, TheCall, "isa-v30-instructions", + diag::err_ppc_builtin_only_on_arch, "9"); #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \ case PPC::BI__builtin_##Name: \ return SemaBuiltinPPCMMACall(TheCall, Types); diff --git a/clang/test/CodeGen/builtins-ppc-xlcompat-darn.c b/clang/test/CodeGen/builtins-ppc-xlcompat-darn.c index edf0bf3b8557b..779a635e4d35b 100644 --- a/clang/test/CodeGen/builtins-ppc-xlcompat-darn.c +++ b/clang/test/CodeGen/builtins-ppc-xlcompat-darn.c @@ -1,10 +1,13 @@ // REQUIRES: powerpc-registered-target // RUN: %clang_cc1 -triple powerpc64-unknown-unknown \ -// RUN: -emit-llvm %s -o - -target-cpu pwr9 | FileCheck %s +// RUN: -emit-llvm %s -o - -target-cpu pwr9 | \ +// RUN: FileCheck %s --check-prefix=CHECK-64 // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \ -// RUN: -emit-llvm %s -o - -target-cpu pwr9 | FileCheck %s +// RUN: -emit-llvm %s -o - -target-cpu pwr9 | \ +// RUN: FileCheck %s --check-prefix=CHECK-64 // RUN: %clang_cc1 -triple powerpc64-unknown-aix \ -// RUN: -emit-llvm %s -o - -target-cpu pwr9 | FileCheck %s +// RUN: -emit-llvm %s -o - -target-cpu pwr9 | \ +// RUN: FileCheck %s --check-prefix=CHECK-64 // RUN: %clang_cc1 -triple powerpc-unknown-unknown \ // RUN: -emit-llvm %s -o - -target-cpu pwr9 | FileCheck %s // RUN: %clang_cc1 -triple powerpcle-unknown-unknown \ @@ -15,21 +18,23 @@ // The darn class of builtins are Power 9 and up and only darn_32 works in // 32 bit mode. -// CHECK-LABEL: @testdarn( -// CHECK: [[TMP0:%.*]] = call i64 @llvm.ppc.darn() -// CHECK-NEXT: ret i64 [[TMP0]] +#ifdef __PPC64__ +// CHECK-64-LABEL: @testdarn( +// CHECK-64: [[TMP0:%.*]] = call i64 @llvm.ppc.darn() +// CHECK-64-NEXT: ret i64 [[TMP0]] // long long testdarn(void) { return __darn(); } -// CHECK-LABEL: @testdarn_raw( -// CHECK: [[TMP0:%.*]] = call i64 @llvm.ppc.darnraw() -// CHECK-NEXT: ret i64 [[TMP0]] +// CHECK-64-LABEL: @testdarn_raw( +// CHECK-64: [[TMP0:%.*]] = call i64 @llvm.ppc.darnraw() +// CHECK-64-NEXT: ret i64 [[TMP0]] // long long testdarn_raw(void) { return __darn_raw(); } +#endif // CHECK-LABEL: @testdarn_32( // CHECK: [[TMP0:%.*]] = call i32 @llvm.ppc.darn32() diff --git a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c index 28bf2e4df8d66..4d5ab184e9a79 100644 --- a/clang/test/CodeGen/builtins-ppc-xlcompat-error.c +++ b/clang/test/CodeGen/builtins-ppc-xlcompat-error.c @@ -96,6 +96,14 @@ long long testdivde(long long dividend, long long divisor) { unsigned long long testdivdeu(unsigned long long dividend, unsigned long long divisor) { return __divdeu(dividend, divisor); //expected-error {{this builtin is only available on 64-bit targets}} } + +int test_darn() { + return __darn(); //expected-error {{this builtin is only available on 64-bit targets}} +} + +int test_darn_raw() { + return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}} +} #endif unsigned long test_mfspr(void) { diff --git a/clang/test/CodeGen/builtins-ppc.c b/clang/test/CodeGen/builtins-ppc.c index 190dafdef83e6..89c2df45a9f56 100644 --- a/clang/test/CodeGen/builtins-ppc.c +++ b/clang/test/CodeGen/builtins-ppc.c @@ -36,16 +36,3 @@ void test_builtin_ppc_flm() { // CHECK: call double @llvm.ppc.setflm(double %1) res = __builtin_setflm(res); } - -void test_builtin_ppc_darn() { - volatile long res; - volatile int x; - // CHECK: call i64 @llvm.ppc.darn() - res = __builtin_darn(); - - // CHECK: call i64 @llvm.ppc.darnraw() - res = __builtin_darn_raw(); - - // CHECK: call i32 @llvm.ppc.darn32() - x = __builtin_darn_32(); -} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits