[clang] Hexagon builtins (PR #114412)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 08:04:44 PDT 2024
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/114412 at github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/114412
>From 8fc295989d876b32542860ca3ed73a7f8e6b42e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 31 Oct 2024 14:51:52 +0100
Subject: [PATCH 1/2] [clang][bytecode][NFC] Use const auto* for Type cast
result
---
clang/lib/AST/ByteCode/Program.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index 0da518ec92afae..04e0b1884e3d6b 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -399,10 +399,10 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
}
// Arrays.
- if (const auto ArrayType = Ty->getAsArrayTypeUnsafe()) {
+ if (const auto *ArrayType = Ty->getAsArrayTypeUnsafe()) {
QualType ElemTy = ArrayType->getElementType();
// Array of well-known bounds.
- if (auto CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
+ if (const auto *CAT = dyn_cast<ConstantArrayType>(ArrayType)) {
size_t NumElems = CAT->getZExtSize();
if (std::optional<PrimType> T = Ctx.classify(ElemTy)) {
// Arrays of primitives.
>From 44832e920fe0e02b37307a5c13816852b0051748 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 31 Oct 2024 16:00:31 +0100
Subject: [PATCH 2/2] [clang][bytecode] Add more checks to _ai32_* builtins
They are called in a few different forms that we don't support.
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 15 +++++++++------
clang/test/CodeGen/builtins-hexagon.c | 1 +
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b00d2a1768b6b7..a5cffad63c509e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1253,7 +1253,7 @@ static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
- if (!Call->getArg(0)->getType()->isIntegerType() ||
+ if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
!Call->getArg(1)->getType()->isIntegerType())
return false;
@@ -1285,7 +1285,9 @@ static bool interp__builtin_ia32_bzhi(InterpState &S, CodePtr OpPC,
const Function *Func,
const CallExpr *Call) {
QualType CallType = Call->getType();
- if (!CallType->isIntegerType())
+ if (Call->getNumArgs() != 0 || !Call->getArg(0)->getType()->isIntegerType() ||
+ !Call->getArg(1)->getType()->isIntegerType() ||
+ !CallType->isIntegerType())
return false;
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
@@ -1310,7 +1312,7 @@ static bool interp__builtin_ia32_lzcnt(InterpState &S, CodePtr OpPC,
const Function *Func,
const CallExpr *Call) {
QualType CallType = Call->getType();
- if (!CallType->isIntegerType())
+ if (!CallType->isIntegerType() || Call->getArg(0)->getType()->isIntegerType())
return false;
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1323,7 +1325,8 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, CodePtr OpPC,
const Function *Func,
const CallExpr *Call) {
QualType CallType = Call->getType();
- if (!CallType->isIntegerType())
+ if (!CallType->isIntegerType() ||
+ !Call->getArg(0)->getType()->isIntegerType())
return false;
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1335,7 +1338,7 @@ static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
- if (!Call->getArg(0)->getType()->isIntegerType() ||
+ if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
!Call->getArg(1)->getType()->isIntegerType())
return false;
@@ -1360,7 +1363,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
- if (!Call->getArg(0)->getType()->isIntegerType() ||
+ if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
!Call->getArg(1)->getType()->isIntegerType())
return false;
diff --git a/clang/test/CodeGen/builtins-hexagon.c b/clang/test/CodeGen/builtins-hexagon.c
index 52073f27ae70f5..94984cafba5385 100644
--- a/clang/test/CodeGen/builtins-hexagon.c
+++ b/clang/test/CodeGen/builtins-hexagon.c
@@ -1,5 +1,6 @@
// REQUIRES: hexagon-registered-target
// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 -target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 -target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - | FileCheck %s -fexperimental-new-constant-interpreter
void test() {
int v64 __attribute__((__vector_size__(64)));
More information about the cfe-commits
mailing list