[clang] d1a3396 - [Driver][ARM] Disable unsupported features when nofp arch extension is used

2020-07-29 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2020-07-29T14:13:22+01:00
New Revision: d1a3396bfbc6fd6df927f2864c18d86e742cabff

URL: 
https://github.com/llvm/llvm-project/commit/d1a3396bfbc6fd6df927f2864c18d86e742cabff
DIFF: 
https://github.com/llvm/llvm-project/commit/d1a3396bfbc6fd6df927f2864c18d86e742cabff.diff

LOG: [Driver][ARM] Disable unsupported features when nofp arch extension is used

A list of target features is disabled when there is no hardware
floating-point support. This is the case when one of the following
options is passed to clang:

 - -mfloat-abi=soft
 - -mfpu=none

This option list is missing, however, the extension "+nofp" that can be
specified in -march flags, such as "-march=armv8-a+nofp".

This patch also disables unsupported target features when nofp is passed
to -march.

Differential Revision: https://reviews.llvm.org/D82948

Added: 
clang/test/Driver/arm-nofp-disabled-features.c

Modified: 
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/CodeGen/arm-bf16-softfloat.c
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/ARMTargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index afe896b4a65b..d74d5db0c083 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -73,14 +73,15 @@ static unsigned getARMFPUFeatures(const Driver &D, const 
Arg *A,
 }
 
 // Decode ARM features from string like +[no]featureA+[no]featureB+...
-static bool DecodeARMFeatures(const Driver &D, StringRef text,
-  StringRef CPU, llvm::ARM::ArchKind ArchKind,
-  std::vector &Features) {
+static bool DecodeARMFeatures(const Driver &D, StringRef text, StringRef CPU,
+  llvm::ARM::ArchKind ArchKind,
+  std::vector &Features,
+  unsigned &ArgFPUID) {
   SmallVector Split;
   text.split(Split, StringRef("+"), -1, false);
 
   for (StringRef Feature : Split) {
-if (!appendArchExtFeatures(CPU, ArchKind, Feature, Features))
+if (!appendArchExtFeatures(CPU, ArchKind, Feature, Features, ArgFPUID))
   return false;
   }
   return true;
@@ -102,14 +103,14 @@ static void DecodeARMFeaturesFromCPU(const Driver &D, 
StringRef CPU,
 static void checkARMArchName(const Driver &D, const Arg *A, const ArgList 
&Args,
  llvm::StringRef ArchName, llvm::StringRef CPUName,
  std::vector &Features,
- const llvm::Triple &Triple) {
+ const llvm::Triple &Triple, unsigned &ArgFPUID) {
   std::pair Split = ArchName.split("+");
 
   std::string MArch = arm::getARMArch(ArchName, Triple);
   llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(MArch);
   if (ArchKind == llvm::ARM::ArchKind::INVALID ||
-  (Split.second.size() && !DecodeARMFeatures(
-D, Split.second, CPUName, ArchKind, Features)))
+  (Split.second.size() && !DecodeARMFeatures(D, Split.second, CPUName,
+ ArchKind, Features, 
ArgFPUID)))
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
@@ -117,15 +118,15 @@ static void checkARMArchName(const Driver &D, const Arg 
*A, const ArgList &Args,
 static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args,
 llvm::StringRef CPUName, llvm::StringRef ArchName,
 std::vector &Features,
-const llvm::Triple &Triple) {
+const llvm::Triple &Triple, unsigned &ArgFPUID) {
   std::pair Split = CPUName.split("+");
 
   std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
   llvm::ARM::ArchKind ArchKind =
 arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
   if (ArchKind == llvm::ARM::ArchKind::INVALID ||
-  (Split.second.size() && !DecodeARMFeatures(
-D, Split.second, CPU, ArchKind, Features)))
+  (Split.second.size() &&
+   !DecodeARMFeatures(D, Split.second, CPU, ArchKind, Features, ArgFPUID)))
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
@@ -347,6 +348,8 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
   StringRef ArchName;
   StringRef CPUName;
+  unsigned ArchArgFPUID = llvm::ARM::FK_INVALID;
+  unsigned CPUArgFPUID = llvm::ARM::FK_INVALID;
 
   // Check -mcpu. ClangAs gives preference to -Wa,-mcpu=.
   if (WaCPU) {
@@ -364,14 +367,14 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   D.Diag(clang::diag::warn_drv_unused_argument)
   << ArchArg->getAsString(Args);
 ArchName = StringRe

[clang] 71bf6dd - [Driver][ARM] Fix testcase that should only run on ARM

2020-07-29 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2020-07-29T14:35:14+01:00
New Revision: 71bf6dd682c03c8c29a365f602f5168d44757abe

URL: 
https://github.com/llvm/llvm-project/commit/71bf6dd682c03c8c29a365f602f5168d44757abe
DIFF: 
https://github.com/llvm/llvm-project/commit/71bf6dd682c03c8c29a365f602f5168d44757abe.diff

LOG: [Driver][ARM] Fix testcase that should only run on ARM

Fix testcase introduced in d1a3396bfbc6fd6df927f2864c18d86e742cabff.

Added: 


Modified: 
clang/test/CodeGen/arm-bf16-softfloat.c

Removed: 




diff  --git a/clang/test/CodeGen/arm-bf16-softfloat.c 
b/clang/test/CodeGen/arm-bf16-softfloat.c
index 3ff4f465223c..1792a1e3c9ce 100644
--- a/clang/test/CodeGen/arm-bf16-softfloat.c
+++ b/clang/test/CodeGen/arm-bf16-softfloat.c
@@ -1,3 +1,4 @@
+// REQUIRES: arm-registered-target
 // RUN: not %clang -target arm-arm-none-eabi -march=armv8-a+bf16 
-mfloat-abi=soft -c %s -o %t 2>&1 | FileCheck %s
 // RUN: not %clang -target arm-arm-none-eabi -march=armv8-a+bf16 -mfpu=none -c 
%s -o %t 2>&1 | FileCheck %s
 // RUN: not %clang -target arm-arm-none-eabi -march=armv8-a+bf16+nofp -c %s -o 
%t 2>&1 | FileCheck %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1b090db - [ARM] Improve diagnostics message when Neon is unsupported

2020-06-24 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2020-06-24T10:20:26+01:00
New Revision: 1b090db0df47f3ebf6acab0316180267e6b96f43

URL: 
https://github.com/llvm/llvm-project/commit/1b090db0df47f3ebf6acab0316180267e6b96f43
DIFF: 
https://github.com/llvm/llvm-project/commit/1b090db0df47f3ebf6acab0316180267e6b96f43.diff

LOG: [ARM] Improve diagnostics message when Neon is unsupported

Summary:
Whenever Neon is not supported, a generic message is printed:

  error: "NEON support not enabled"

Followed by a series of other error messages that are not useful once
the first one is printed.

This patch gives a more precise message in the case where Neon is
unsupported because an invalid float ABI was specified: the soft float
ABI.

  error: "NEON intrinsics not available with the soft-float ABI. Please
  use -mfloat-abi=softfp or -mfloat-abi=hard"

This message is the same one that GCC gives, so it is also making their
diagnostics more compatible with each other.

Also, by rearranging preprocessor directives, these "unsupported" error
messages are now the only ones printed out, which is also GCC's
behaviour.

Differential Revision: https://reviews.llvm.org/D81847

Added: 


Modified: 
clang/utils/TableGen/NeonEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index 813a0c8afe8d..d5bf59ef04ad 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -2312,9 +2312,14 @@ void NeonEmitter::run(raw_ostream &OS) {
   OS << "#ifndef __ARM_NEON_H\n";
   OS << "#define __ARM_NEON_H\n\n";
 
+  OS << "#ifndef __ARM_FP\n";
+  OS << "#error \"NEON intrinsics not available with the soft-float ABI. "
+"Please use -mfloat-abi=softfp or -mfloat-abi=hard\"\n";
+  OS << "#else\n\n";
+
   OS << "#if !defined(__ARM_NEON)\n";
   OS << "#error \"NEON support not enabled\"\n";
-  OS << "#endif\n\n";
+  OS << "#else\n\n";
 
   OS << "#include \n\n";
 
@@ -2404,6 +2409,8 @@ void NeonEmitter::run(raw_ostream &OS) {
 
   OS << "\n";
   OS << "#undef __ai\n\n";
+  OS << "#endif /* if !defined(__ARM_NEON) */\n";
+  OS << "#endif /* ifndef __ARM_FP */\n";
   OS << "#endif /* __ARM_NEON_H */\n";
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Corprocessor Instrinsics (PR #75440)

2023-12-18 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Corprocessor Instrinsics (PR #75440)

2023-12-18 Thread Victor Campos via cfe-commits


@@ -752,10 +752,57 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_mte_ptrdiff(__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
 
 /* Memory Operations Intrinsics */
-#define __arm_mops_memset_tag(__tagged_address, __value, __size)\
+#define __arm_mops_memset_tag(__tagged_address, __value, __size)   
\

vhscampos wrote:

This whitespace change looks unrelated. Can you please put it in a different 
pull request?

https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Corprocessor Instrinsics (PR #75440)

2023-12-18 Thread Victor Campos via cfe-commits

https://github.com/vhscampos requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Corprocessor Instrinsics (PR #75440)

2023-12-18 Thread Victor Campos via cfe-commits

vhscampos wrote:

There are some typos in the commit message and in the PR title.

https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-09 Thread Victor Campos via cfe-commits

https://github.com/vhscampos approved this pull request.

LGTM. Thanks

https://github.com/llvm/llvm-project/pull/75440
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78297)

2024-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/78297

None

>From 5306cac319986b110638148cb28b2a0f4a4b1ce4 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 18 Sep 2023 13:21:28 +0100
Subject: [PATCH] [NFC][Clang][Headers] Update refs to ACLE in comments

Change-Id: I6769b28b734bfb16e9e33db38c3182351a83dae7
---
 clang/lib/Headers/arm_acle.h | 70 +++-
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 9aae2285aeb1d8..9cd34948e3c535 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -4,6 +4,13 @@
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
+ * The Arm C Language Extensions specifications can be found in the following
+ * link: https://github.com/ARM-software/acle/releases
+ *
+ * The ACLE section numbers are subject to change. When consulting the
+ * specifications, it is recommended to search using section titles if
+ * the section numbers look outdated.
+ *
  *===---===
  */
 
@@ -20,8 +27,8 @@
 extern "C" {
 #endif
 
-/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
-/* 8.3 Memory barriers */
+/* 7 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
+/* 7.3 Memory barriers */
 #if !__has_builtin(__dmb)
 #define __dmb(i) __builtin_arm_dmb(i)
 #endif
@@ -32,7 +39,7 @@ extern "C" {
 #define __isb(i) __builtin_arm_isb(i)
 #endif
 
-/* 8.4 Hints */
+/* 7.4 Hints */
 
 #if !__has_builtin(__wfi)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__wfi(void) {
@@ -68,7 +75,7 @@ static __inline__ void __attribute__((__always_inline__, 
__nodebug__)) __yield(v
 #define __dbg(t) __builtin_arm_dbg(t)
 #endif
 
-/* 8.5 Swap */
+/* 7.5 Swap */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __swp(uint32_t __x, volatile uint32_t *__p) {
   uint32_t v;
@@ -78,8 +85,8 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   return v;
 }
 
-/* 8.6 Memory prefetch intrinsics */
-/* 8.6.1 Data prefetch */
+/* 7.6 Memory prefetch intrinsics */
+/* 7.6.1 Data prefetch */
 #define __pld(addr) __pldx(0, 0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -90,7 +97,7 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
 #endif
 
-/* 8.6.2 Instruction prefetch */
+/* 7.6.2 Instruction prefetch */
 #define __pli(addr) __plix(0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -101,15 +108,15 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
 #endif
 
-/* 8.7 NOP */
+/* 7.7 NOP */
 #if !defined(_MSC_VER) || !defined(__aarch64__)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__nop(void) {
   __builtin_arm_nop();
 }
 #endif
 
-/* 9 DATA-PROCESSING INTRINSICS */
-/* 9.2 Miscellaneous data-processing intrinsics */
+/* 8 DATA-PROCESSING INTRINSICS */
+/* 8.2 Miscellaneous data-processing intrinsics */
 /* ROR */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __ror(uint32_t __x, uint32_t __y) {
@@ -248,9 +255,7 @@ __rbitl(unsigned long __t) {
 #endif
 }
 
-/*
- * 9.3 16-bit multiplications
- */
+/* 8.3 16-bit multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
 __smulbb(int32_t __a, int32_t __b) {
@@ -279,18 +284,18 @@ __smulwt(int32_t __a, int32_t __b) {
 #endif
 
 /*
- * 9.4 Saturating intrinsics
+ * 8.4 Saturating intrinsics
  *
  * FIXME: Change guard to their corresponding __ARM_FEATURE flag when Q flag
  * intrinsics are implemented and the flag is enabled.
  */
-/* 9.4.1 Width-specified saturation intrinsics */
+/* 8.4.1 Width-specified saturation intrinsics */
 #if defined(__ARM_FEATURE_SAT) && __ARM_FEATURE_SAT
 #define __ssat(x, y) __builtin_arm_ssat(x, y)
 #define __usat(x, y) __builtin_arm_usat(x, y)
 #endif
 
-/* 9.4.2 Saturating addition and subtraction intrinsics */
+/* 8.4.2 Saturating addition and subtraction intrinsics */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __qadd(int32_t __t, int32_t __v) {
@@ -308,7 +313,7 @@ __qdbl(int32_t __t) {
 }
 #endif
 
-/* 9.4.3 Accumultating multiplications */
+/* 8.4.3 Accumultating multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
@@ -337,13 +342,13 @@ __smlawt(int32_t __a, int32_t __b, int32_t __c) {
 #endif
 
 
-/* 9.5.4 Parallel 16-bit saturation */
+/* 8.5.4 Parallel 16-bit saturation */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 #define __

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78297)

2024-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/78297
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/78305

None

>From 9a72dd14c75670bcfb2de73754f5366d792b99cc Mon Sep 17 00:00:00 2001
From: Max Iyengar 
Date: Mon, 18 Sep 2023 13:21:28 +0100
Subject: [PATCH] [NFC][Clang][Headers] Update refs to ACLE in comments

---
 clang/lib/Headers/arm_acle.h | 70 +++-
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 9aae2285aeb1d82..9cd34948e3c535c 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -4,6 +4,13 @@
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
+ * The Arm C Language Extensions specifications can be found in the following
+ * link: https://github.com/ARM-software/acle/releases
+ *
+ * The ACLE section numbers are subject to change. When consulting the
+ * specifications, it is recommended to search using section titles if
+ * the section numbers look outdated.
+ *
  *===---===
  */
 
@@ -20,8 +27,8 @@
 extern "C" {
 #endif
 
-/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
-/* 8.3 Memory barriers */
+/* 7 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
+/* 7.3 Memory barriers */
 #if !__has_builtin(__dmb)
 #define __dmb(i) __builtin_arm_dmb(i)
 #endif
@@ -32,7 +39,7 @@ extern "C" {
 #define __isb(i) __builtin_arm_isb(i)
 #endif
 
-/* 8.4 Hints */
+/* 7.4 Hints */
 
 #if !__has_builtin(__wfi)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__wfi(void) {
@@ -68,7 +75,7 @@ static __inline__ void __attribute__((__always_inline__, 
__nodebug__)) __yield(v
 #define __dbg(t) __builtin_arm_dbg(t)
 #endif
 
-/* 8.5 Swap */
+/* 7.5 Swap */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __swp(uint32_t __x, volatile uint32_t *__p) {
   uint32_t v;
@@ -78,8 +85,8 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   return v;
 }
 
-/* 8.6 Memory prefetch intrinsics */
-/* 8.6.1 Data prefetch */
+/* 7.6 Memory prefetch intrinsics */
+/* 7.6.1 Data prefetch */
 #define __pld(addr) __pldx(0, 0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -90,7 +97,7 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
 #endif
 
-/* 8.6.2 Instruction prefetch */
+/* 7.6.2 Instruction prefetch */
 #define __pli(addr) __plix(0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -101,15 +108,15 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
 #endif
 
-/* 8.7 NOP */
+/* 7.7 NOP */
 #if !defined(_MSC_VER) || !defined(__aarch64__)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__nop(void) {
   __builtin_arm_nop();
 }
 #endif
 
-/* 9 DATA-PROCESSING INTRINSICS */
-/* 9.2 Miscellaneous data-processing intrinsics */
+/* 8 DATA-PROCESSING INTRINSICS */
+/* 8.2 Miscellaneous data-processing intrinsics */
 /* ROR */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __ror(uint32_t __x, uint32_t __y) {
@@ -248,9 +255,7 @@ __rbitl(unsigned long __t) {
 #endif
 }
 
-/*
- * 9.3 16-bit multiplications
- */
+/* 8.3 16-bit multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
 __smulbb(int32_t __a, int32_t __b) {
@@ -279,18 +284,18 @@ __smulwt(int32_t __a, int32_t __b) {
 #endif
 
 /*
- * 9.4 Saturating intrinsics
+ * 8.4 Saturating intrinsics
  *
  * FIXME: Change guard to their corresponding __ARM_FEATURE flag when Q flag
  * intrinsics are implemented and the flag is enabled.
  */
-/* 9.4.1 Width-specified saturation intrinsics */
+/* 8.4.1 Width-specified saturation intrinsics */
 #if defined(__ARM_FEATURE_SAT) && __ARM_FEATURE_SAT
 #define __ssat(x, y) __builtin_arm_ssat(x, y)
 #define __usat(x, y) __builtin_arm_usat(x, y)
 #endif
 
-/* 9.4.2 Saturating addition and subtraction intrinsics */
+/* 8.4.2 Saturating addition and subtraction intrinsics */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __qadd(int32_t __t, int32_t __v) {
@@ -308,7 +313,7 @@ __qdbl(int32_t __t) {
 }
 #endif
 
-/* 9.4.3 Accumultating multiplications */
+/* 8.4.3 Accumultating multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
@@ -337,13 +342,13 @@ __smlawt(int32_t __a, int32_t __b, int32_t __c) {
 #endif
 
 
-/* 9.5.4 Parallel 16-bit saturation */
+/* 8.5.4 Parallel 16-bit saturation */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 #define __ssat16(x, y) __builtin_arm_ssat16(x, y)
 #define __us

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/78305

>From bc6d669367ff399fddfb9b1bbc2fdc8effbfc408 Mon Sep 17 00:00:00 2001
From: Max Iyengar 
Date: Mon, 18 Sep 2023 13:21:28 +0100
Subject: [PATCH] [NFC][Clang][Headers] Update refs to ACLE in comments

---
 clang/lib/Headers/arm_acle.h | 70 +++-
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 9aae2285aeb1d8..9cd34948e3c535 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -4,6 +4,13 @@
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
+ * The Arm C Language Extensions specifications can be found in the following
+ * link: https://github.com/ARM-software/acle/releases
+ *
+ * The ACLE section numbers are subject to change. When consulting the
+ * specifications, it is recommended to search using section titles if
+ * the section numbers look outdated.
+ *
  *===---===
  */
 
@@ -20,8 +27,8 @@
 extern "C" {
 #endif
 
-/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
-/* 8.3 Memory barriers */
+/* 7 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
+/* 7.3 Memory barriers */
 #if !__has_builtin(__dmb)
 #define __dmb(i) __builtin_arm_dmb(i)
 #endif
@@ -32,7 +39,7 @@ extern "C" {
 #define __isb(i) __builtin_arm_isb(i)
 #endif
 
-/* 8.4 Hints */
+/* 7.4 Hints */
 
 #if !__has_builtin(__wfi)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__wfi(void) {
@@ -68,7 +75,7 @@ static __inline__ void __attribute__((__always_inline__, 
__nodebug__)) __yield(v
 #define __dbg(t) __builtin_arm_dbg(t)
 #endif
 
-/* 8.5 Swap */
+/* 7.5 Swap */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __swp(uint32_t __x, volatile uint32_t *__p) {
   uint32_t v;
@@ -78,8 +85,8 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   return v;
 }
 
-/* 8.6 Memory prefetch intrinsics */
-/* 8.6.1 Data prefetch */
+/* 7.6 Memory prefetch intrinsics */
+/* 7.6.1 Data prefetch */
 #define __pld(addr) __pldx(0, 0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -90,7 +97,7 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
 #endif
 
-/* 8.6.2 Instruction prefetch */
+/* 7.6.2 Instruction prefetch */
 #define __pli(addr) __plix(0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -101,15 +108,15 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
 #endif
 
-/* 8.7 NOP */
+/* 7.7 NOP */
 #if !defined(_MSC_VER) || !defined(__aarch64__)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__nop(void) {
   __builtin_arm_nop();
 }
 #endif
 
-/* 9 DATA-PROCESSING INTRINSICS */
-/* 9.2 Miscellaneous data-processing intrinsics */
+/* 8 DATA-PROCESSING INTRINSICS */
+/* 8.2 Miscellaneous data-processing intrinsics */
 /* ROR */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __ror(uint32_t __x, uint32_t __y) {
@@ -248,9 +255,7 @@ __rbitl(unsigned long __t) {
 #endif
 }
 
-/*
- * 9.3 16-bit multiplications
- */
+/* 8.3 16-bit multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
 __smulbb(int32_t __a, int32_t __b) {
@@ -279,18 +284,18 @@ __smulwt(int32_t __a, int32_t __b) {
 #endif
 
 /*
- * 9.4 Saturating intrinsics
+ * 8.4 Saturating intrinsics
  *
  * FIXME: Change guard to their corresponding __ARM_FEATURE flag when Q flag
  * intrinsics are implemented and the flag is enabled.
  */
-/* 9.4.1 Width-specified saturation intrinsics */
+/* 8.4.1 Width-specified saturation intrinsics */
 #if defined(__ARM_FEATURE_SAT) && __ARM_FEATURE_SAT
 #define __ssat(x, y) __builtin_arm_ssat(x, y)
 #define __usat(x, y) __builtin_arm_usat(x, y)
 #endif
 
-/* 9.4.2 Saturating addition and subtraction intrinsics */
+/* 8.4.2 Saturating addition and subtraction intrinsics */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __qadd(int32_t __t, int32_t __v) {
@@ -308,7 +313,7 @@ __qdbl(int32_t __t) {
 }
 #endif
 
-/* 9.4.3 Accumultating multiplications */
+/* 8.4.3 Accumultating multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
@@ -337,13 +342,13 @@ __smlawt(int32_t __a, int32_t __b, int32_t __c) {
 #endif
 
 
-/* 9.5.4 Parallel 16-bit saturation */
+/* 8.5.4 Parallel 16-bit saturation */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 #define __ssat16(x, y) __builtin_arm_ssat16(x, y)
 #define __usat16(x, 

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Victor Campos via cfe-commits

https://github.com/vhscampos ready_for_review 
https://github.com/llvm/llvm-project/pull/78305
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #66662)

2024-01-17 Thread Victor Campos via cfe-commits

vhscampos wrote:

I've addressed your comments, but I don't have permissions to edit this PR 
directly. Thus I've created a new pull request: 
https://github.com/llvm/llvm-project/pull/78305

Can you please have a look? Thanks

https://github.com/llvm/llvm-project/pull/2
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Victor Campos via cfe-commits

vhscampos wrote:

Tagging @voltur01 for review

https://github.com/llvm/llvm-project/pull/78305
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/78305
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9d1ff78 - [AArch64] Add support for the Cortex-X3 CPU

2022-11-09 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2022-11-09T11:33:48Z
New Revision: 9d1ff787e5c2b19e19e5475b9c36f4e5c2a07d23

URL: 
https://github.com/llvm/llvm-project/commit/9d1ff787e5c2b19e19e5475b9c36f4e5c2a07d23
DIFF: 
https://github.com/llvm/llvm-project/commit/9d1ff787e5c2b19e19e5475b9c36f4e5c2a07d23.diff

LOG: [AArch64] Add support for the Cortex-X3 CPU

Cortex-X3 is an Armv9-A AArch64 CPU.

This patch introduces support for Cortex-X3.

Technical Reference Manual: 
https://developer.arm.com/documentation/101593/latest

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D136589

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Driver/aarch64-mcpu.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/lib/Support/Host.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0d464e9fb7d51..774b575b52609 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -744,11 +744,11 @@ Arm and AArch64 Support in Clang
 - ``-march`` values for targeting armv2, armv2A, armv3 and armv3M have been 
removed.
   Their presence gave the impression that Clang can correctly generate code for
   them, which it cannot.
-- Add driver and tuning support for Neoverse V2 via the flag 
``-mcpu=neoverse-v2``.
-  Native detection is also supported via ``-mcpu=native``.
 - Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
 
   * Arm Cortex-A715 (cortex-a715).
+  * Arm Cortex-X3 (cortex-x3).
+  * Arm Neoverse V2 (neoverse-v2)
 
 Floating Point Support in Clang
 ---

diff  --git a/clang/test/Driver/aarch64-mcpu.c 
b/clang/test/Driver/aarch64-mcpu.c
index b40c579acdf00..d0f898357570a 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -41,6 +41,8 @@
 // CORTEXX1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x1"
 // RUN: %clang -target aarch64 -mcpu=cortex-x1c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXX1C %s
 // CORTEXX1C: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x1c"
+// RUN: %clang -target aarch64 -mcpu=cortex-x3 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXX3 %s
+// CORTEXX3: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x3"
 // RUN: %clang -target aarch64 -mcpu=cortex-a78  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXA78 %s
 // CORTEXA78: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a78"
 // RUN: %clang -target aarch64 -mcpu=cortex-a78c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A78C %s

diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 1d7d89ebb1eb0..f48a54d452f68 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, 
apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, 
kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, 
thunderxt83, tsv110, a64fx, carmel, ampere1, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-a715, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, cortex-x3, neoverse-e1, neoverse-n1, neoverse-n2, 
neoverse-512tvb, neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, 
apple-a9, apple-a10, apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, 
apple-a16, apple-m1, apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, 
grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #66662)

2023-09-19 Thread Victor Campos via cfe-commits


@@ -20,8 +20,8 @@
 extern "C" {

vhscampos wrote:

Thanks @Blue-Dot for the patch. I agree with @kbeyls that it would be a good 
idea.

https://github.com/llvm/llvm-project/pull/2
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d77cba6 - [Clang][DebugInfo] Emit narrower base types for structured binding declarations that bind to struct bitfields

2023-08-16 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2023-08-16T10:45:01+01:00
New Revision: d77cba6d474ab8ce5ece126499522de414c8089c

URL: 
https://github.com/llvm/llvm-project/commit/d77cba6d474ab8ce5ece126499522de414c8089c
DIFF: 
https://github.com/llvm/llvm-project/commit/d77cba6d474ab8ce5ece126499522de414c8089c.diff

LOG: [Clang][DebugInfo] Emit narrower base types for structured binding 
declarations that bind to struct bitfields

In cases where a structured binding declaration is made to a struct with
bitfields:

struct A {
  unsigned int x : 16;
  unsigned int y : 16;
} g;

auto [a, b] = g; // structured binding declaration

Clang assigns the 'unsigned int' DWARF base type to 'a' and 'b' because
this is their deduced C++ type in the structured binding declaration.

However, their actual type in memory is 'unsigned short' as they have 16
bits allocated for each.

This is a problem for debug information consumers: if the debug
information for 'a' has the 'unsigned int' base type, a debugger will
assume it has 4 bytes, whereas it actually has a length of 2, resulting
in a read (or write) past its length.

This patch mimics GCC's behaviour: in case of structured bindings to
bitfields, the binding declaration's DWARF base type is of the target's
integer type with the same bitwidth as the bitfield.

If no suitable integer type is found in the target, no debug information
is emitted anymore in order to prevent wrong debug output.

Reviewed By: tmatheson

Differential Revision: https://reviews.llvm.org/D157479

Added: 
clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index f049a682cfed6f..54e31bec0cc5bc 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4744,6 +4744,40 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
VarDecl *VD,
   return D;
 }
 
+llvm::DIType *CGDebugInfo::CreateBindingDeclType(const BindingDecl *BD) {
+  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
+
+  // If the declaration is bound to a bitfield struct field, its type may have 
a
+  // size that is 
diff erent from its deduced declaration type's.
+  if (const MemberExpr *ME = dyn_cast(BD->getBinding())) {
+if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl())) {
+  if (FD->isBitField()) {
+ASTContext &Context = CGM.getContext();
+const CGRecordLayout &RL =
+CGM.getTypes().getCGRecordLayout(FD->getParent());
+const CGBitFieldInfo &Info = RL.getBitFieldInfo(FD);
+
+// Find an integer type with the same bitwidth as the bitfield size. If
+// no suitable type is present in the target, give up on producing 
debug
+// information as it would be wrong. It is certainly possible to 
produce
+// correct debug info, but the logic isn't currently implemented.
+uint64_t BitfieldSizeInBits = Info.Size;
+QualType IntTy =
+Context.getIntTypeForBitwidth(BitfieldSizeInBits, Info.IsSigned);
+if (IntTy.isNull())
+  return nullptr;
+Qualifiers Quals = BD->getType().getQualifiers();
+QualType FinalTy = Context.getQualifiedType(IntTy, Quals);
+llvm::DIType *Ty = getOrCreateType(FinalTy, Unit);
+assert(Ty);
+return Ty;
+  }
+}
+  }
+
+  return getOrCreateType(BD->getType(), Unit);
+}
+
 llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
 llvm::Value *Storage,
 std::optional ArgNo,
@@ -4758,8 +4792,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   if (isa(BD->getBinding()))
 return nullptr;
 
-  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
-  llvm::DIType *Ty = getOrCreateType(BD->getType(), Unit);
+  llvm::DIType *Ty = CreateBindingDeclType(BD);
 
   // If there is no debug info for this type then do not emit debug info
   // for this variable.
@@ -4785,6 +4818,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   unsigned Column = getColumnNumber(BD->getLocation());
   StringRef Name = BD->getName();
   auto *Scope = cast(LexicalBlockStack.back());
+  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
   // Create the descriptor for the variable.
   llvm::DILocalVariable *D = DBuilder.createAutoVariable(
   Scope, Name, Unit, Line, Ty, CGM.getLangOpts().Optimize,
@@ -4800,6 +4834,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   const uint64_t fieldOffset = layout.getFieldOffset(fieldIndex);
 
   if (fieldOffset != 0) {
+// Currently if the field offset is not a multiple of byte, the 
produced
+// location would not be acc

[clang] dbeb3d0 - Add missing vrnd intrinsics

2023-09-11 Thread Victor Campos via cfe-commits

Author: Max Iyengar
Date: 2023-09-11T12:59:18+01:00
New Revision: dbeb3d029d8e3120668288a284d0babeb81545fd

URL: 
https://github.com/llvm/llvm-project/commit/dbeb3d029d8e3120668288a284d0babeb81545fd
DIFF: 
https://github.com/llvm/llvm-project/commit/dbeb3d029d8e3120668288a284d0babeb81545fd.diff

LOG: Add missing vrnd intrinsics

This patch adds 8 missing intrinsics as specified in the Arm ACLE document 
section 2.12.1.1 : [[ 
https://arm-software.github.io/acle/neon_intrinsics/advsimd.html#rounding-3 | 
https://arm-software.github.io/acle/neon_intrinsics/advsimd.html#rounding-3]]

The intrinsics implemented are:

  - vrnd32z_f64
  - vrnd32zq_f64
  - vrnd64z_f64
  - vrnd64zq_f64
  - vrnd32x_f64
  - vrnd32xq_f64
  - vrnd64x_f64
  - vrnd64xq_f64

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D158626

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-v8.5a-neon-frint3264-intrinsic.c
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/test/CodeGen/AArch64/v8.5a-neon-frint3264-intrinsic.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ba3764d2f778e86..9cb7e0981384b0b 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1232,6 +1232,11 @@ def FRINT32X_S32 : SInst<"vrnd32x", "..", "fQf">;
 def FRINT32Z_S32 : SInst<"vrnd32z", "..", "fQf">;
 def FRINT64X_S32 : SInst<"vrnd64x", "..", "fQf">;
 def FRINT64Z_S32 : SInst<"vrnd64z", "..", "fQf">;
+
+def FRINT32X_S64 : SInst<"vrnd32x", "..", "dQd">;
+def FRINT32Z_S64 : SInst<"vrnd32z", "..", "dQd">;
+def FRINT64X_S64 : SInst<"vrnd64x", "..", "dQd">;
+def FRINT64Z_S64 : SInst<"vrnd64z", "..", "dQd">;
 }
 
 


diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index df0c4cc6354d0f2..27e4eb630356412 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6430,13 +6430,21 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP2(vrhadd_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | 
UnsignedAlts),
   NEONMAP2(vrhaddq_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | 
UnsignedAlts),
   NEONMAP1(vrnd32x_f32, aarch64_neon_frint32x, Add1ArgType),
+  NEONMAP1(vrnd32x_f64, aarch64_neon_frint32x, Add1ArgType),
   NEONMAP1(vrnd32xq_f32, aarch64_neon_frint32x, Add1ArgType),
+  NEONMAP1(vrnd32xq_f64, aarch64_neon_frint32x, Add1ArgType),
   NEONMAP1(vrnd32z_f32, aarch64_neon_frint32z, Add1ArgType),
+  NEONMAP1(vrnd32z_f64, aarch64_neon_frint32z, Add1ArgType),
   NEONMAP1(vrnd32zq_f32, aarch64_neon_frint32z, Add1ArgType),
+  NEONMAP1(vrnd32zq_f64, aarch64_neon_frint32z, Add1ArgType),
   NEONMAP1(vrnd64x_f32, aarch64_neon_frint64x, Add1ArgType),
+  NEONMAP1(vrnd64x_f64, aarch64_neon_frint64x, Add1ArgType),
   NEONMAP1(vrnd64xq_f32, aarch64_neon_frint64x, Add1ArgType),
+  NEONMAP1(vrnd64xq_f64, aarch64_neon_frint64x, Add1ArgType),
   NEONMAP1(vrnd64z_f32, aarch64_neon_frint64z, Add1ArgType),
+  NEONMAP1(vrnd64z_f64, aarch64_neon_frint64z, Add1ArgType),
   NEONMAP1(vrnd64zq_f32, aarch64_neon_frint64z, Add1ArgType),
+  NEONMAP1(vrnd64zq_f64, aarch64_neon_frint64z, Add1ArgType),
   NEONMAP0(vrndi_v),
   NEONMAP0(vrndiq_v),
   NEONMAP2(vrshl_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | 
UnsignedAlts),
@@ -11798,25 +11806,33 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return EmitNeonCall(CGM.getIntrinsic(Int, HalfTy), Ops, "vrndz");
   }
   case NEON::BI__builtin_neon_vrnd32x_f32:
-  case NEON::BI__builtin_neon_vrnd32xq_f32: {
+  case NEON::BI__builtin_neon_vrnd32xq_f32:
+  case NEON::BI__builtin_neon_vrnd32x_f64:
+  case NEON::BI__builtin_neon_vrnd32xq_f64: {
 Ops.push_back(EmitScalarExpr(E->getArg(0)));
 Int = Intrinsic::aarch64_neon_frint32x;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnd32x");
   }
   case NEON::BI__builtin_neon_vrnd32z_f32:
-  case NEON::BI__builtin_neon_vrnd32zq_f32: {
+  case NEON::BI__builtin_neon_vrnd32zq_f32:
+  case NEON::BI__builtin_neon_vrnd32z_f64:
+  case NEON::BI__builtin_neon_vrnd32zq_f64: {
 Ops.push_back(EmitScalarExpr(E->getArg(0)));
 Int = Intrinsic::aarch64_neon_frint32z;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnd32z");
   }
   case NEON::BI__builtin_neon_vrnd64x_f32:
-  case NEON::BI__builtin_neon_vrnd64xq_f32: {
+  case NEON::BI__builtin_neon_vrnd64xq_f32:
+  case NEON::BI__builtin_neon_vrnd64x_f64:
+  case NEON::BI__builtin_neon_vrnd64xq_f64: {
 Ops.push_back(EmitScalarExpr(E->getArg(0)));
 Int = Intrinsic::aarch64_neon_frint64x;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnd64x");
   }
   case NEON::BI__builtin_neon_vrnd64z_f32:
-  case NEON::BI__b

[clang] [AArch64][Clang] Implement ACLE rintn intrinsics (PR #66112)

2023-09-14 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/66112
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dcf11c5 - [ARM][AArch64] Complex addition Neon intrinsics for Armv8.3-A

2019-12-02 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2019-12-02T14:38:39Z
New Revision: dcf11c5e86cee94ec649a7a31c5dd259f60579d6

URL: 
https://github.com/llvm/llvm-project/commit/dcf11c5e86cee94ec649a7a31c5dd259f60579d6
DIFF: 
https://github.com/llvm/llvm-project/commit/dcf11c5e86cee94ec649a7a31c5dd259f60579d6.diff

LOG: [ARM][AArch64] Complex addition Neon intrinsics for Armv8.3-A

Summary:
Add support for vcadd_* family of intrinsics. This set of intrinsics is
available in Armv8.3-A.

The fp16 versions require the FP16 extension, which has been available
(opt-in) since Armv8.2-A.

Reviewers: t.p.northover

Reviewed By: t.p.northover

Subscribers: t.p.northover, kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D70862

Added: 
clang/test/CodeGen/aarch64-neon-vcadd.c
clang/test/CodeGen/arm-neon-vcadd.c
llvm/test/CodeGen/AArch64/neon-vcadd.ll
llvm/test/CodeGen/ARM/neon-vcadd.ll

Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/ARM.h
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/ARM/ARMInstrNEON.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index b5e395c8103f..a4dc21b64311 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1673,3 +1673,21 @@ let ArchGuard = "defined(__ARM_FEATURE_FP16FML) && 
defined(__aarch64__)" in {
   def VFMLAL_LANEQ_HIGH : SOpInst<"vfmlal_laneq_high", "(F>)(F>)F(FQ)I", 
"hQh", OP_FMLAL_LN_Hi>;
   def VFMLSL_LANEQ_HIGH : SOpInst<"vfmlsl_laneq_high", "(F>)(F>)F(FQ)I", 
"hQh", OP_FMLSL_LN_Hi>;
 }
+
+// v8.3-A Vector complex addition intrinsics
+let ArchGuard = "defined(__ARM_FEATURE_COMPLEX) && 
defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)" in {
+  def VCADD_ROT90_FP16   : SInst<"vcadd_rot90", "...", "h">;
+  def VCADD_ROT270_FP16  : SInst<"vcadd_rot270", "...", "h">;
+  def VCADDQ_ROT90_FP16  : SInst<"vcaddq_rot90", "QQQ", "h">;
+  def VCADDQ_ROT270_FP16 : SInst<"vcaddq_rot270", "QQQ", "h">;
+}
+let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)" in {
+  def VCADD_ROT90   : SInst<"vcadd_rot90", "...", "f">;
+  def VCADD_ROT270  : SInst<"vcadd_rot270", "...", "f">;
+  def VCADDQ_ROT90  : SInst<"vcaddq_rot90", "QQQ", "f">;
+  def VCADDQ_ROT270 : SInst<"vcaddq_rot270", "QQQ", "f">;
+}
+let ArchGuard = "defined(__ARM_FEATURE_COMPLEX) && defined(__aarch64__)" in {
+  def VCADDQ_ROT90_FP64  : SInst<"vcaddq_rot90", "QQQ", "d">;
+  def VCADDQ_ROT270_FP64 : SInst<"vcaddq_rot270", "QQQ", "d">;
+}
\ No newline at end of file

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5214f7c30ee0..cba3e3ada7ea 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -158,6 +158,7 @@ void AArch64TargetInfo::getTargetDefinesARMV82A(const 
LangOptions &Opts,
 
 void AArch64TargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
+  Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 437a77afdc99..be088e81cffe 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -580,6 +580,13 @@ void ARMTargetInfo::getTargetDefinesARMV82A(const 
LangOptions &Opts,
   getTargetDefinesARMV81A(Opts, Builder);
 }
 
+void ARMTargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  // Also include the ARMv8.2-A defines
+  Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
+  getTargetDefinesARMV82A(Opts, Builder);
+}
+
 void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   // Target identification.
@@ -809,6 +816,11 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case llvm::ARM::ArchKind::ARMV8_2A:
 getTargetDefinesARMV82A(Opts, Builder);
 break;
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+getTargetDefinesARMV83A(Opts, Builder);
+break;
   }
 }
 

diff  --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index ce87a6265934..9696a4404589 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -148,9 +148,10 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
 
   void getTargetDefinesARMV81

[clang] [NFC] Fix arm_acle.h title headers (PR #82624)

2024-02-22 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/82624

Fix some title headers to align them with the actual ACLE document.

>From 30c1dca1d5a25bd4124ec3cb2ef7b6f681773ea0 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 22 Feb 2024 14:32:56 +
Subject: [PATCH] [NFC] Fix arm_acle.h title headers

Fix some title headers to align them with the actual ACLE document.
---
 clang/lib/Headers/arm_acle.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 9cd34948e3c535..6e557eda1dddca 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -313,7 +313,7 @@ __qdbl(int32_t __t) {
 }
 #endif
 
-/* 8.4.3 Accumultating multiplications */
+/* 8.4.3 Accumulating multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
@@ -545,7 +545,7 @@ __usub16(uint16x2_t __a, uint16x2_t __b) {
 }
 #endif
 
-/* 8.5.10 Parallel 16-bit multiplications */
+/* 8.5.10 Parallel 16-bit multiplication */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlad(int16x2_t __a, int16x2_t __b, int32_t __c) {
@@ -748,7 +748,7 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_wsrf(sysreg, v) __arm_wsr(sysreg, __builtin_bit_cast(uint32_t, 
v))
 #define __arm_wsrf64(sysreg, v) __arm_wsr64(sysreg, 
__builtin_bit_cast(uint64_t, v))
 
-/* 10.3 Memory Tagging Extensions (MTE) Intrinsics */
+/* 10.3 MTE intrinsics */
 #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)
@@ -757,7 +757,7 @@ __arm_st64bv0(void *__addr, data512_t __value) {
 #define __arm_mte_set_tag(__ptr) __builtin_arm_stg(__ptr)
 #define __arm_mte_ptrdiff(__ptra, __ptrb) __builtin_arm_subp(__ptra, __ptrb)
 
-/* 18 Memory Operations Intrinsics */
+/* 18 memcpy family of operations intrinsics - MOPS */
 #define __arm_mops_memset_tag(__tagged_address, __value, __size)\
   __builtin_arm_mops_memset_tag(__tagged_address, __value, __size)
 #endif

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][NFC] Fix arm_acle.h title headers (PR #82624)

2024-02-22 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/82624
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-02-22 Thread Victor Campos via cfe-commits

vhscampos wrote:

Fixed @jwestwood921 's comments in #82624 

https://github.com/llvm/llvm-project/pull/78305
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ee3e016 - [Clang][ARM] Define __VFP_FP__ macro unconditionally

2021-04-21 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2021-04-21T15:03:59+01:00
New Revision: ee3e01627ff876ef2225d691fc4d0a127c4abc78

URL: 
https://github.com/llvm/llvm-project/commit/ee3e01627ff876ef2225d691fc4d0a127c4abc78
DIFF: 
https://github.com/llvm/llvm-project/commit/ee3e01627ff876ef2225d691fc4d0a127c4abc78.diff

LOG: [Clang][ARM] Define __VFP_FP__ macro unconditionally

Clang only defines __VFP_FP__ when the FPU is enabled. However, gcc
defines it unconditionally.

This patch aligns Clang with gcc.

Reviewed By: peter.smith, rengolin

Differential Revision: https://reviews.llvm.org/D100372

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.cpp
clang/test/Preprocessor/arm-target-features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index a2c96ad12a76..542c90fe153d 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -755,8 +755,12 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // Note, this is always on in gcc, even though it doesn't make sense.
   Builder.defineMacro("__APCS_32__");
 
+  // __VFP_FP__ means that the floating-point format is VFP, not that a 
hardware
+  // FPU is present. Moreover, the VFP format is the only one supported by
+  // clang. For these reasons, this macro is always defined.
+  Builder.defineMacro("__VFP_FP__");
+
   if (FPUModeIsVFP((FPUMode)FPU)) {
-Builder.defineMacro("__VFP_FP__");
 if (FPU & VFP2FPU)
   Builder.defineMacro("__ARM_VFPV2__");
 if (FPU & VFP3FPU)

diff  --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 9f375162e6ab..5fd1654c9a98 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -141,6 +141,11 @@
 // CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
 // CHECK-V7S: #define __ARM_FP 0xe
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=soft -x c 
-E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=softfp -x 
c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=hard -x c 
-E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// CHECK-VFP-FP: #define __VFP_FP__ 1
+
 // RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck 
-match-full-lines --check-prefix=CHECK-V8-BAREHF %s
 // CHECK-V8-BAREHF: #define __ARMEL__ 1
 // CHECK-V8-BAREHF: #define __ARM_ARCH 8



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3550e24 - [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-10-11 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2021-10-11T17:44:09+01:00
New Revision: 3550e242fad672696da361f7ddadf53a41114dfd

URL: 
https://github.com/llvm/llvm-project/commit/3550e242fad672696da361f7ddadf53a41114dfd
DIFF: 
https://github.com/llvm/llvm-project/commit/3550e242fad672696da361f7ddadf53a41114dfd.diff

LOG: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

armv9-a, armv9.1-a and armv9.2-a can be targeted using the -march option
both in ARM and AArch64.

 - Armv9-A maps to Armv8.5-A.
 - Armv9.1-A maps to Armv8.6-A.
 - Armv9.2-A maps to Armv8.7-A.
 - The SVE2 extension is enabled by default on these architectures.
 - The cryptographic extensions are disabled by default on these
 architectures.

The Armv9-A architecture is described in the Arm® Architecture Reference
Manual Supplement Armv9, for Armv9-A architecture profile
(https://developer.arm.com/documentation/ddi0608/latest).

Reviewed By: SjoerdMeijer

Differential Revision: https://reviews.llvm.org/D109517

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/test/Driver/aarch64-cpus.c
clang/test/Driver/arm-cortex-cpus.c
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/arm-target-features.c
llvm/include/llvm/ADT/Triple.h
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/ARMTargetParser.def
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Support/ARMTargetParser.cpp
llvm/lib/Support/Triple.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/test/MC/AArch64/SME/directives-negative.s
llvm/test/MC/AArch64/SME/directives.s
llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
llvm/test/MC/AArch64/SVE2/directive-arch.s
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 2b5bf34a7b23f..c11608d9b06a8 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -40,6 +40,17 @@ const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
 #include "clang/Basic/BuiltinsAArch64.def"
 };
 
+static StringRef getArchVersionString(llvm::AArch64::ArchKind Kind) {
+  switch (Kind) {
+  case llvm::AArch64::ArchKind::ARMV9A:
+  case llvm::AArch64::ArchKind::ARMV9_1A:
+  case llvm::AArch64::ArchKind::ARMV9_2A:
+return "9";
+  default:
+return "8";
+  }
+}
+
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : TargetInfo(Triple), ABI("aapcs") {
@@ -203,6 +214,24 @@ void AArch64TargetInfo::getTargetDefinesARMV87A(const 
LangOptions &Opts,
   getTargetDefinesARMV86A(Opts, Builder);
 }
 
+void AArch64TargetInfo::getTargetDefinesARMV9A(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  // Armv9-A maps to Armv8.5-A
+  getTargetDefinesARMV85A(Opts, Builder);
+}
+
+void AArch64TargetInfo::getTargetDefinesARMV91A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  // Armv9.1-A maps to Armv8.6-A
+  getTargetDefinesARMV86A(Opts, Builder);
+}
+
+void AArch64TargetInfo::getTargetDefinesARMV92A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  // Armv9.2-A maps to Armv8.7-A
+  getTargetDefinesARMV87A(Opts, Builder);
+}
+
 void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   // Target identification.
@@ -227,7 +256,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH", "8");
+  Builder.defineMacro("__ARM_ARCH", getArchVersionString(ArchKind));
   Builder.defineMacro("__ARM_ARCH_PROFILE", "'A'");
 
   Builder.defineMacro("__ARM_64BIT_STATE", "1");
@@ -405,6 +434,15 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case llvm::AArch64::ArchKind::ARMV8_7A:
 getTargetDefinesARMV87A(Opts, Builder);
 break;
+  case llvm::AArch64::ArchKind::ARMV9A:
+getTargetDefinesARMV9A(Opts, Builder);
+break;
+  case llvm::AArch64::ArchKind::ARMV9_1A:
+getTargetDefinesARMV91A(Opts, Builder);
+break;
+  case llvm::AArch64::ArchKind::ARMV9_2A:
+getTargetDefinesARMV92A(Opts, Builder);
+break;
 

[clang] 3e7cf33 - [docs] List support for Armv9-A, Armv9.1-A and Armv9.2-A in LLVM and Clang

2021-10-12 Thread Victor Campos via cfe-commits

Author: Victor Campos
Date: 2021-10-12T08:41:07+01:00
New Revision: 3e7cf33a83764514bd613dfb5b1a0bb36f13e69a

URL: 
https://github.com/llvm/llvm-project/commit/3e7cf33a83764514bd613dfb5b1a0bb36f13e69a
DIFF: 
https://github.com/llvm/llvm-project/commit/3e7cf33a83764514bd613dfb5b1a0bb36f13e69a.diff

LOG: [docs] List support for Armv9-A, Armv9.1-A and Armv9.2-A in LLVM and Clang

Reviewed By: pratlucas

Differential Revision: https://reviews.llvm.org/D110241

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ebbf1eb63636..950e9fe726285 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -83,6 +83,12 @@ Modified Compiler Flags
   - RISC-V SiFive S54 (``sifive-s54``).
   - RISC-V SiFive S76 (``sifive-s76``).
 
+- Support has been added for the following architectures (``-march`` 
identifiers in parentheses):
+
+  - Armv9-A (``armv9-a``).
+  - Armv9.1-A (``armv9.1-a``).
+  - Armv9.2-A (``armv9.2-a``).
+
 Removed Compiler Flags
 -
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 46627c2000679..4bac29cb1cd1c 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -73,12 +73,12 @@ Changes to TableGen
 Changes to the AArch64 Backend
 --
 
-* ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the ARM Backend
 --
 
-During this release ...
+* Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.
 
 Changes to the MIPS Target
 --



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-10-25 Thread Victor Campos via cfe-commits

https://github.com/vhscampos ready_for_review 
https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;

vhscampos wrote:

Fixed

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;
+using CustomFlagDeclarationPtr = std::shared_ptr;
+
+struct CustomFlagValueDetail {
+  std::string Name;
+  std::optional> ExtraBuildArgs;
+  CustomFlagDeclarationPtr Decl;
+};
+
+struct CustomFlagDeclaration {
+  std::string Name;
+  SmallVector ValueList;
+  size_t DefaultValueIdx = ~0UL;

vhscampos wrote:

Fixed

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -259,11 +266,69 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail 
&V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io,
+  custom_flag::CustomFlagDeclarationPtr &V,
+  llvm::SmallSet &NameSet) {
+assert(!V);
+V = std::make_shared();
+io.mapRequired("Name", V->Name);
+io.mapRequired("Values", V->ValueList, NameSet);
+std::string DefaultValueName;
+io.mapRequired("Default", DefaultValueName);
+
+for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) {
+  Value.Decl = V;
+  if (Value.Name == DefaultValueName) {
+assert(V->DefaultValueIdx == ~0UL);
+V->DefaultValueIdx = Idx;
+  }
+}
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagDeclarationPtr &V,
+  llvm::SmallSet &) {
+if (V->Name.empty())
+  return "custom flag requires a name";
+if (V->ValueList.empty())
+  return "custom flag must have at least one value";
+if (V->DefaultValueIdx >= V->ValueList.size())
+  return "custom flag must have a default value";
+if (llvm::any_of(V->ValueList, [&V](const auto &Value) {
+  return !Value.Decl || Value.Decl != V;
+}))
+  return "custom flag value missing reference to its custom flag "
+ "declaration";

vhscampos wrote:

Fixed

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-05 Thread Victor Campos via cfe-commits

vhscampos wrote:

Created PR to amend `Multilib.rst`: 
https://github.com/llvm/llvm-project/pull/114998

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-05 Thread Victor Campos via cfe-commits

vhscampos wrote:

Thanks @smithp35. Before any of the PRs is merged, I will update the 
descriptions to make them more self-contained.

Furthermore, `Multilib.rst` must indeed be updated. Will do it.

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From e194bdad39ea7f719e1a133eca94f9ce6ef3e881 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH 1/2] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  30 +++-
 clang/lib/Driver/Multilib.cpp |  80 +--
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 230 insertions(+), 13 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..333b1d2b555bd9 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;
+using CustomFlagDeclarationPtr = std::shared_ptr;
+
+struct CustomFlagValueDetail {
+  std::string Name;
+  std::optional> ExtraBuildArgs;
+  CustomFlagDeclarationPtr Decl;
+};
+
+struct CustomFlagDeclaration {
+  std::string Name;
+  SmallVector ValueList;
+  size_t DefaultValueIdx = ~0UL;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
-  MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  MultilibSet(
+  multilib_list &&Multilibs, SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = 
{})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index c56417c6f6d0b0..81fe97517b0f91 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -11,7 +11,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
@@ -205,13 +205,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagDeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -259,11 +266,69 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail 
&V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+

[clang] [Clang][Driver] Add option to provide path for multilib's YAML config file (PR #109640)

2024-09-23 Thread Victor Campos via cfe-commits

vhscampos wrote:

LGTM from the Arm target perspective, but not sure about the impact on the 
workflow of other targets. I suggest this waits for others' reviews.

https://github.com/llvm/llvm-project/pull/109640
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ADT] Simplify SmallSet (PR #109412)

2024-09-24 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/109412

>From 3877c9933c9ac5d0c6b40fe63421624f4ea5c5a9 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 20 Sep 2024 11:43:18 +0100
Subject: [PATCH] [ADT] Simplify SmallSet

- Remove dependence on `STLExtras.h`.
- Remove unused header inclusions.
- Make `count` use `contains` for deduplication.
- Replace hand-written linear scans on Vector by `std::find`.
---
 clang/lib/Basic/TargetID.cpp |  1 +
 llvm/include/llvm/ADT/SmallSet.h | 37 +++-
 2 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 3c06d9bad1dc0d..fa1bfec2aacb9c 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/TargetID.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/TargetParser.h"
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 630c98504261aa..8d7511bf0bc8d9 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -16,14 +16,10 @@
 
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/type_traits.h"
 #include 
 #include 
 #include 
-#include 
 #include 
 
 namespace llvm {
@@ -139,10 +135,6 @@ class SmallSet {
   SmallVector Vector;
   std::set Set;
 
-  using VIterator = typename SmallVector::const_iterator;
-  using SIterator = typename std::set::const_iterator;
-  using mutable_iterator = typename SmallVector::iterator;
-
   // In small mode SmallPtrSet uses linear search for the elements, so it is
   // not a good idea to choose this value too high. You may consider using a
   // DenseSet<> instead if you expect many elements in the set.
@@ -163,13 +155,7 @@ class SmallSet {
   }
 
   /// count - Return 1 if the element is in the set, 0 otherwise.
-  size_type count(const T &V) const {
-if (isSmall()) {
-  // Since the collection is small, just do a linear search.
-  return vfind(V) == Vector.end() ? 0 : 1;
-}
-return Set.count(V);
-  }
+  size_type count(const T &V) const { return contains(V) ? 1 : 0; }
 
   /// insert - Insert an element into the set if it isn't already there.
   /// Returns a pair. The first value of it is an iterator to the inserted
@@ -181,7 +167,7 @@ class SmallSet {
   return std::make_pair(const_iterator(I), Inserted);
 }
 
-VIterator I = vfind(V);
+auto I = std::find(Vector.begin(), Vector.end(), V);
 if (I != Vector.end())// Don't reinsert if it already exists.
   return std::make_pair(const_iterator(I), false);
 if (Vector.size() < N) {
@@ -206,11 +192,11 @@ class SmallSet {
   bool erase(const T &V) {
 if (!isSmall())
   return Set.erase(V);
-for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V) {
-Vector.erase(I);
-return true;
-  }
+auto I = std::find(Vector.begin(), Vector.end(), V);
+if (I != Vector.end()) {
+  Vector.erase(I);
+  return true;
+}
 return false;
   }
 
@@ -234,19 +220,12 @@ class SmallSet {
   /// Check if the SmallSet contains the given element.
   bool contains(const T &V) const {
 if (isSmall())
-  return vfind(V) != Vector.end();
+  return std::find(Vector.begin(), Vector.end(), V) != Vector.end();
 return Set.find(V) != Set.end();
   }
 
 private:
   bool isSmall() const { return Set.empty(); }
-
-  VIterator vfind(const T &V) const {
-for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V)
-return I;
-return Vector.end();
-  }
 };
 
 /// If this set is of pointer values, transparently switch over to using

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ADT][NFC] Simplify SmallSet (PR #109412)

2024-09-24 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/109412
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ADT][NFC] Simplify SmallSet (PR #109412)

2024-09-26 Thread Victor Campos via cfe-commits

vhscampos wrote:

Thanks for the investigation @nikic . I'll have a patch restoring `vfind` with 
an explanatory comment tomorrow.

https://github.com/llvm/llvm-project/pull/109412
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ADT] Simplify SmallSet (PR #109412)

2024-09-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/109412
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ADT] Simplify SmallSet (PR #109412)

2024-09-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/109412

>From 58c88d6fee0f1aa486201189bbe67cea7da2d25e Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 9 Aug 2024 13:51:52 +0100
Subject: [PATCH 1/2] [ADT] Style and nit fixes in SmallSet

---
 llvm/include/llvm/ADT/SmallSet.h | 43 
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index a16e8ac6f07552..630c98504261aa 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -46,24 +46,24 @@ class SmallSetIterator
 VecIterTy VecIter;
   };
 
-  bool isSmall;
+  bool IsSmall;
 
 public:
-  SmallSetIterator(SetIterTy SetIter) : SetIter(SetIter), isSmall(false) {}
+  SmallSetIterator(SetIterTy SetIter) : SetIter(SetIter), IsSmall(false) {}
 
-  SmallSetIterator(VecIterTy VecIter) : VecIter(VecIter), isSmall(true) {}
+  SmallSetIterator(VecIterTy VecIter) : VecIter(VecIter), IsSmall(true) {}
 
   // Spell out destructor, copy/move constructor and assignment operators for
   // MSVC STL, where set::const_iterator is not trivially copy 
constructible.
   ~SmallSetIterator() {
-if (isSmall)
+if (IsSmall)
   VecIter.~VecIterTy();
 else
   SetIter.~SetIterTy();
   }
 
-  SmallSetIterator(const SmallSetIterator &Other) : isSmall(Other.isSmall) {
-if (isSmall)
+  SmallSetIterator(const SmallSetIterator &Other) : IsSmall(Other.IsSmall) {
+if (IsSmall)
   VecIter = Other.VecIter;
 else
   // Use placement new, to make sure SetIter is properly constructed, even
@@ -71,8 +71,8 @@ class SmallSetIterator
   new (&SetIter) SetIterTy(Other.SetIter);
   }
 
-  SmallSetIterator(SmallSetIterator &&Other) : isSmall(Other.isSmall) {
-if (isSmall)
+  SmallSetIterator(SmallSetIterator &&Other) : IsSmall(Other.IsSmall) {
+if (IsSmall)
   VecIter = std::move(Other.VecIter);
 else
   // Use placement new, to make sure SetIter is properly constructed, even
@@ -83,11 +83,11 @@ class SmallSetIterator
   SmallSetIterator& operator=(const SmallSetIterator& Other) {
 // Call destructor for SetIter, so it gets properly destroyed if it is
 // not trivially destructible in case we are setting VecIter.
-if (!isSmall)
+if (!IsSmall)
   SetIter.~SetIterTy();
 
-isSmall = Other.isSmall;
-if (isSmall)
+IsSmall = Other.IsSmall;
+if (IsSmall)
   VecIter = Other.VecIter;
 else
   new (&SetIter) SetIterTy(Other.SetIter);
@@ -97,11 +97,11 @@ class SmallSetIterator
   SmallSetIterator& operator=(SmallSetIterator&& Other) {
 // Call destructor for SetIter, so it gets properly destroyed if it is
 // not trivially destructible in case we are setting VecIter.
-if (!isSmall)
+if (!IsSmall)
   SetIter.~SetIterTy();
 
-isSmall = Other.isSmall;
-if (isSmall)
+IsSmall = Other.IsSmall;
+if (IsSmall)
   VecIter = std::move(Other.VecIter);
 else
   new (&SetIter) SetIterTy(std::move(Other.SetIter));
@@ -109,22 +109,22 @@ class SmallSetIterator
   }
 
   bool operator==(const SmallSetIterator &RHS) const {
-if (isSmall != RHS.isSmall)
+if (IsSmall != RHS.IsSmall)
   return false;
-if (isSmall)
+if (IsSmall)
   return VecIter == RHS.VecIter;
 return SetIter == RHS.SetIter;
   }
 
   SmallSetIterator &operator++() { // Preincrement
-if (isSmall)
-  VecIter++;
+if (IsSmall)
+  ++VecIter;
 else
-  SetIter++;
+  ++SetIter;
 return *this;
   }
 
-  const T &operator*() const { return isSmall ? *VecIter : *SetIter; }
+  const T &operator*() const { return IsSmall ? *VecIter : *SetIter; }
 };
 
 /// SmallSet - This maintains a set of unique values, optimizing for the case
@@ -167,9 +167,8 @@ class SmallSet {
 if (isSmall()) {
   // Since the collection is small, just do a linear search.
   return vfind(V) == Vector.end() ? 0 : 1;
-} else {
-  return Set.count(V);
 }
+return Set.count(V);
   }
 
   /// insert - Insert an element into the set if it isn't already there.

>From 3d83c5456c35f891aefa65f7cc6b37795af99c32 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 20 Sep 2024 11:43:18 +0100
Subject: [PATCH 2/2] [ADT] Simplify SmallSet

- Remove dependence on `STLExtras.h`.
- Remove unused header inclusions.
- Make `count` use `contains` for deduplication.
- Replace hand-written linear scans on Vector by `std::find`.
---
 clang/lib/Basic/TargetID.cpp |  1 +
 llvm/include/llvm/ADT/SmallSet.h | 37 +++-
 2 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 3c06d9bad1dc0d..fa1bfec2aacb9c 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Basic/Targ

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-10-24 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From e194bdad39ea7f719e1a133eca94f9ce6ef3e881 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  30 +++-
 clang/lib/Driver/Multilib.cpp |  80 +--
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 230 insertions(+), 13 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..333b1d2b555bd9 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;
+using CustomFlagDeclarationPtr = std::shared_ptr;
+
+struct CustomFlagValueDetail {
+  std::string Name;
+  std::optional> ExtraBuildArgs;
+  CustomFlagDeclarationPtr Decl;
+};
+
+struct CustomFlagDeclaration {
+  std::string Name;
+  SmallVector ValueList;
+  size_t DefaultValueIdx = ~0UL;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
-  MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  MultilibSet(
+  multilib_list &&Multilibs, SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = 
{})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index c56417c6f6d0b0..81fe97517b0f91 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -11,7 +11,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
@@ -205,13 +205,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagDeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -259,11 +266,69 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail 
&V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From 4c9756a323f67dbe5fbdb45cf2ddb5f97adad18d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  28 +++-
 clang/lib/Driver/Multilib.cpp |  73 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 223 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..69d0b9b31714ff 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+using DeclarationPtr = std::shared_ptr;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> DriverArgs;
+  DeclarationPtr Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..0d7d590a0eed8b 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -255,11 +263,63 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("DriverArgs", V.DriverArgs);
+  }
+  static std::string validate(IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm::ya

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From e194bdad39ea7f719e1a133eca94f9ce6ef3e881 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH 1/3] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  30 +++-
 clang/lib/Driver/Multilib.cpp |  80 +--
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 230 insertions(+), 13 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..333b1d2b555bd9 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;
+using CustomFlagDeclarationPtr = std::shared_ptr;
+
+struct CustomFlagValueDetail {
+  std::string Name;
+  std::optional> ExtraBuildArgs;
+  CustomFlagDeclarationPtr Decl;
+};
+
+struct CustomFlagDeclaration {
+  std::string Name;
+  SmallVector ValueList;
+  size_t DefaultValueIdx = ~0UL;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
-  MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  MultilibSet(
+  multilib_list &&Multilibs, SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = 
{})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index c56417c6f6d0b0..81fe97517b0f91 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -11,7 +11,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
@@ -205,13 +205,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagDeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -259,11 +266,69 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail 
&V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Use shared_ptr in the Compilation class (PR #116406)

2024-11-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/116406

This patch replaces uses of raw pointers by shared_ptrs in the Driver's 
Compilation class.

The manual memory management which was done before this patch could be error 
prone. Plus, code is now simpler.

>From 6291206f06c524951ba0d9f444cc75293de41015 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 15 Nov 2024 16:15:04 +
Subject: [PATCH] [clang][Driver] Use shared_ptr in the Compilation class

This patch replaces uses of raw pointers by shared_ptrs in the Driver's
Compilation class.

The manual memory management which was done before this patch could be
error prone. Plus, code is now simpler.
---
 clang/include/clang/Driver/Compilation.h |  6 ++--
 clang/lib/Driver/Compilation.cpp | 41 
 2 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/Driver/Compilation.h 
b/clang/include/clang/Driver/Compilation.h
index 36ae85c4245143..cceb0c8a4466ba 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -61,11 +61,11 @@ class Compilation {
   OrderedOffloadingToolchains;
 
   /// The original (untranslated) input argument list.
-  llvm::opt::InputArgList *Args;
+  std::shared_ptr Args;
 
   /// The driver translated arguments. Note that toolchains may perform their
   /// own argument translation.
-  llvm::opt::DerivedArgList *TranslatedArgs;
+  std::shared_ptr TranslatedArgs;
 
   /// The list of actions we've created via MakeAction.  This is not accessible
   /// to consumers; it's here just to manage ownership.
@@ -100,7 +100,7 @@ class Compilation {
   return false;
 }
   };
-  std::map TCArgs;
+  std::map> TCArgs;
 
   /// Temporary files which should be removed on exit.
   llvm::opt::ArgStringList TempFiles;
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..0fd60f9e80bd37 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -47,14 +47,6 @@ Compilation::~Compilation() {
   // the file names might be derived from the input arguments.
   if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
 CleanupFileList(TempFiles);
-
-  delete TranslatedArgs;
-  delete Args;
-
-  // Free any derived arg lists.
-  for (auto Arg : TCArgs)
-if (Arg.second != TranslatedArgs)
-  delete Arg.second;
 }
 
 const DerivedArgList &
@@ -63,41 +55,39 @@ Compilation::getArgsForToolChain(const ToolChain *TC, 
StringRef BoundArch,
   if (!TC)
 TC = &DefaultToolChain;
 
-  DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
+  std::shared_ptr &Entry =
+  TCArgs[{TC, BoundArch, DeviceOffloadKind}];
   if (!Entry) {
 SmallVector AllocatedArgs;
-DerivedArgList *OpenMPArgs = nullptr;
+std::shared_ptr OpenMPArgs;
 // Translate OpenMP toolchain arguments provided via the -Xopenmp-target 
flags.
 if (DeviceOffloadKind == Action::OFK_OpenMP) {
   const ToolChain *HostTC = getSingleOffloadToolChain();
   bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
-  OpenMPArgs = TC->TranslateOpenMPTargetArgs(
-  *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
+  OpenMPArgs.reset(TC->TranslateOpenMPTargetArgs(
+  *TranslatedArgs, SameTripleAsHost, AllocatedArgs));
 }
 
-DerivedArgList *NewDAL = nullptr;
+std::shared_ptr NewDAL;
 if (!OpenMPArgs) {
-  NewDAL = TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
-  DeviceOffloadKind, &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
 } else {
-  NewDAL = TC->TranslateXarchArgs(*OpenMPArgs, BoundArch, 
DeviceOffloadKind,
-  &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*OpenMPArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
   if (!NewDAL)
 NewDAL = OpenMPArgs;
-  else
-delete OpenMPArgs;
 }
 
 if (!NewDAL) {
-  Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
+  Entry.reset(
+  TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind));
   if (!Entry)
 Entry = TranslatedArgs;
 } else {
-  Entry = TC->TranslateArgs(*NewDAL, BoundArch, DeviceOffloadKind);
+  Entry.reset(TC->TranslateArgs(*NewDAL, BoundArch, DeviceOffloadKind));
   if (!Entry)
-Entry = NewDAL;
-  else
-delete NewDAL;
+Entry = std::shared_ptr(NewDAL);
 }
 
 // Add allocated arguments to the final DAL.
@@ -290,9 +280,6 @@ void Compilation::initCompilationForDiagnostics() {
 
   // Force re-creation of the toolchain Args, otherwise our modifications just
   // above will have no effect.
-  for (auto Arg : TCArgs)
-  

[clang] [clang][Driver] Use shared_ptr in the Compilation class (PR #116406)

2024-11-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/116406

>From bfd7a4cd935c45b84d270b12d1989531d4522732 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 15 Nov 2024 16:15:04 +
Subject: [PATCH 1/2] [clang][Driver] Use shared_ptr in the Compilation class

This patch replaces uses of raw pointers by shared_ptrs in the Driver's
Compilation class.

The manual memory management which was done before this patch could be
error prone. Plus, code is now simpler.
---
 clang/include/clang/Driver/Compilation.h | 11 +++---
 clang/lib/Driver/Compilation.cpp | 44 +---
 clang/lib/Driver/Driver.cpp  |  6 ++--
 3 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/clang/include/clang/Driver/Compilation.h 
b/clang/include/clang/Driver/Compilation.h
index 36ae85c4245143..db44d2bb68d693 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -61,11 +61,11 @@ class Compilation {
   OrderedOffloadingToolchains;
 
   /// The original (untranslated) input argument list.
-  llvm::opt::InputArgList *Args;
+  std::shared_ptr Args;
 
   /// The driver translated arguments. Note that toolchains may perform their
   /// own argument translation.
-  llvm::opt::DerivedArgList *TranslatedArgs;
+  std::shared_ptr TranslatedArgs;
 
   /// The list of actions we've created via MakeAction.  This is not accessible
   /// to consumers; it's here just to manage ownership.
@@ -100,7 +100,7 @@ class Compilation {
   return false;
 }
   };
-  std::map TCArgs;
+  std::map> TCArgs;
 
   /// Temporary files which should be removed on exit.
   llvm::opt::ArgStringList TempFiles;
@@ -134,8 +134,9 @@ class Compilation {
 
 public:
   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
-  llvm::opt::InputArgList *Args,
-  llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError);
+  std::shared_ptr Args,
+  std::shared_ptr TranslatedArgs,
+  bool ContainsError);
   ~Compilation();
 
   const Driver &getDriver() const { return TheDriver; }
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..b8025d6a46f2e6 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -33,7 +33,8 @@ using namespace driver;
 using namespace llvm::opt;
 
 Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
- InputArgList *_Args, DerivedArgList *_TranslatedArgs,
+ std::shared_ptr _Args,
+ std::shared_ptr _TranslatedArgs,
  bool ContainsError)
 : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
   TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) {
@@ -47,14 +48,6 @@ Compilation::~Compilation() {
   // the file names might be derived from the input arguments.
   if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
 CleanupFileList(TempFiles);
-
-  delete TranslatedArgs;
-  delete Args;
-
-  // Free any derived arg lists.
-  for (auto Arg : TCArgs)
-if (Arg.second != TranslatedArgs)
-  delete Arg.second;
 }
 
 const DerivedArgList &
@@ -63,41 +56,39 @@ Compilation::getArgsForToolChain(const ToolChain *TC, 
StringRef BoundArch,
   if (!TC)
 TC = &DefaultToolChain;
 
-  DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
+  std::shared_ptr &Entry =
+  TCArgs[{TC, BoundArch, DeviceOffloadKind}];
   if (!Entry) {
 SmallVector AllocatedArgs;
-DerivedArgList *OpenMPArgs = nullptr;
+std::shared_ptr OpenMPArgs;
 // Translate OpenMP toolchain arguments provided via the -Xopenmp-target 
flags.
 if (DeviceOffloadKind == Action::OFK_OpenMP) {
   const ToolChain *HostTC = getSingleOffloadToolChain();
   bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
-  OpenMPArgs = TC->TranslateOpenMPTargetArgs(
-  *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
+  OpenMPArgs.reset(TC->TranslateOpenMPTargetArgs(
+  *TranslatedArgs, SameTripleAsHost, AllocatedArgs));
 }
 
-DerivedArgList *NewDAL = nullptr;
+std::shared_ptr NewDAL;
 if (!OpenMPArgs) {
-  NewDAL = TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
-  DeviceOffloadKind, &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
 } else {
-  NewDAL = TC->TranslateXarchArgs(*OpenMPArgs, BoundArch, 
DeviceOffloadKind,
-  &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*OpenMPArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
   if (!NewDAL)
 NewDAL = OpenMPArgs;
-  else
-delete OpenMPArgs;
   

[clang] [clang][Driver] Use shared_ptr in the Compilation class (PR #116406)

2024-11-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/116406

>From bfd7a4cd935c45b84d270b12d1989531d4522732 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 15 Nov 2024 16:15:04 +
Subject: [PATCH] [clang][Driver] Use shared_ptr in the Compilation class

This patch replaces uses of raw pointers by shared_ptrs in the Driver's
Compilation class.

The manual memory management which was done before this patch could be
error prone. Plus, code is now simpler.
---
 clang/include/clang/Driver/Compilation.h | 11 +++---
 clang/lib/Driver/Compilation.cpp | 44 +---
 clang/lib/Driver/Driver.cpp  |  6 ++--
 3 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/clang/include/clang/Driver/Compilation.h 
b/clang/include/clang/Driver/Compilation.h
index 36ae85c4245143..db44d2bb68d693 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -61,11 +61,11 @@ class Compilation {
   OrderedOffloadingToolchains;
 
   /// The original (untranslated) input argument list.
-  llvm::opt::InputArgList *Args;
+  std::shared_ptr Args;
 
   /// The driver translated arguments. Note that toolchains may perform their
   /// own argument translation.
-  llvm::opt::DerivedArgList *TranslatedArgs;
+  std::shared_ptr TranslatedArgs;
 
   /// The list of actions we've created via MakeAction.  This is not accessible
   /// to consumers; it's here just to manage ownership.
@@ -100,7 +100,7 @@ class Compilation {
   return false;
 }
   };
-  std::map TCArgs;
+  std::map> TCArgs;
 
   /// Temporary files which should be removed on exit.
   llvm::opt::ArgStringList TempFiles;
@@ -134,8 +134,9 @@ class Compilation {
 
 public:
   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
-  llvm::opt::InputArgList *Args,
-  llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError);
+  std::shared_ptr Args,
+  std::shared_ptr TranslatedArgs,
+  bool ContainsError);
   ~Compilation();
 
   const Driver &getDriver() const { return TheDriver; }
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..b8025d6a46f2e6 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -33,7 +33,8 @@ using namespace driver;
 using namespace llvm::opt;
 
 Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
- InputArgList *_Args, DerivedArgList *_TranslatedArgs,
+ std::shared_ptr _Args,
+ std::shared_ptr _TranslatedArgs,
  bool ContainsError)
 : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args),
   TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) {
@@ -47,14 +48,6 @@ Compilation::~Compilation() {
   // the file names might be derived from the input arguments.
   if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles)
 CleanupFileList(TempFiles);
-
-  delete TranslatedArgs;
-  delete Args;
-
-  // Free any derived arg lists.
-  for (auto Arg : TCArgs)
-if (Arg.second != TranslatedArgs)
-  delete Arg.second;
 }
 
 const DerivedArgList &
@@ -63,41 +56,39 @@ Compilation::getArgsForToolChain(const ToolChain *TC, 
StringRef BoundArch,
   if (!TC)
 TC = &DefaultToolChain;
 
-  DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
+  std::shared_ptr &Entry =
+  TCArgs[{TC, BoundArch, DeviceOffloadKind}];
   if (!Entry) {
 SmallVector AllocatedArgs;
-DerivedArgList *OpenMPArgs = nullptr;
+std::shared_ptr OpenMPArgs;
 // Translate OpenMP toolchain arguments provided via the -Xopenmp-target 
flags.
 if (DeviceOffloadKind == Action::OFK_OpenMP) {
   const ToolChain *HostTC = getSingleOffloadToolChain();
   bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
-  OpenMPArgs = TC->TranslateOpenMPTargetArgs(
-  *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
+  OpenMPArgs.reset(TC->TranslateOpenMPTargetArgs(
+  *TranslatedArgs, SameTripleAsHost, AllocatedArgs));
 }
 
-DerivedArgList *NewDAL = nullptr;
+std::shared_ptr NewDAL;
 if (!OpenMPArgs) {
-  NewDAL = TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
-  DeviceOffloadKind, &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*TranslatedArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
 } else {
-  NewDAL = TC->TranslateXarchArgs(*OpenMPArgs, BoundArch, 
DeviceOffloadKind,
-  &AllocatedArgs);
+  NewDAL.reset(TC->TranslateXarchArgs(*OpenMPArgs, BoundArch,
+  DeviceOffloadKind, &AllocatedArgs));
   if (!NewDAL)
 NewDAL = OpenMPArgs;
-  else
-delete OpenMPArgs;
 }

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-12-11 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From 3914f0f5afbc8549dbc3557b70abb21f96be2db7 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH 1/2] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  28 +++-
 clang/lib/Driver/Multilib.cpp |  73 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 223 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..69d0b9b31714ff 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+using DeclarationPtr = std::shared_ptr;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> DriverArgs;
+  DeclarationPtr Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..0d7d590a0eed8b 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -255,11 +263,63 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("DriverArgs", V.DriverArgs);
+  }
+  static std::string validate(IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-12-11 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-12-10 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110657

>From 4c9756a323f67dbe5fbdb45cf2ddb5f97adad18d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH 1/2] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  28 +++-
 clang/lib/Driver/Multilib.cpp |  73 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 223 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..69d0b9b31714ff 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+using DeclarationPtr = std::shared_ptr;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> DriverArgs;
+  DeclarationPtr Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..0d7d590a0eed8b 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -255,11 +263,63 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("DriverArgs", V.DriverArgs);
+  }
+  static std::string validate(IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm

[clang] Fix test of `-print-multi-flags-experimental` in case of multilib custom flags (PR #123577)

2025-01-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/123577

The test was failing in the case where a `multilib.yaml` file was present in 
the installation. This is because the presence of a multilib YAML file leads to 
the diagnosing of validity of the multilib custom flags.

This patch fixes the test by creating a new YAML file with multilib custom 
flags to be used by the test.

>From 51819f2931c1495d6fc0085a041b27810120df7c Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 17 Jan 2025 17:01:14 +
Subject: [PATCH] Fix test of `-print-multi-flags-experimental` in case of
 multilib custom flags

The test was failing in the case where a `multilib.yaml` file was
present in the installation. This is because the presence of a multilib
YAML file leads to the diagnosing of validity of the multilib custom
flags.

This patch fixes the test by creating a new YAML file with multilib
custom flags to be used by the test.
---
 .../Inputs/multilib/multilib-custom-flags.yaml  | 13 +
 clang/test/Driver/print-multi-selection-flags.c |  4 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/Inputs/multilib/multilib-custom-flags.yaml

diff --git a/clang/test/Driver/Inputs/multilib/multilib-custom-flags.yaml 
b/clang/test/Driver/Inputs/multilib/multilib-custom-flags.yaml
new file mode 100644
index 00..153680bce7b866
--- /dev/null
+++ b/clang/test/Driver/Inputs/multilib/multilib-custom-flags.yaml
@@ -0,0 +1,13 @@
+MultilibVersion: 1.0
+
+Variants:
+
+Mappings:
+
+Flags:
+- Name: flag
+  Values:
+  - Name: foo
+  - Name: bar
+  Default: foo
+...
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index cf9522aa068524..5a35ae374f0113 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -91,8 +91,8 @@
 // CHECK-RV32E-ORDER: -mabi=ilp32e
 // CHECK-RV32E-ORDER: 
-march=rv32e{{[0-9]+p[0-9]+}}_c{{[0-9]+p[0-9]+}}_zicsr{{[0-9]+p[0-9]+}}
 
-// RUN: %clang -print-multi-flags-experimental --target=armv8m.main-none-eabi 
-fmultilib-flag=foo -fmultilib-flag=bar | FileCheck 
--check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-ARM-MULTILIB-CUSTOM-FLAG %s
-// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-eabi 
-fmultilib-flag=foo -fmultilib-flag=bar | FileCheck 
--check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-AARCH64-MULTILIB-CUSTOM-FLAG 
%s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/multilib-custom-flags.yaml 
-print-multi-flags-experimental --target=armv8m.main-none-eabi 
-fmultilib-flag=foo -fmultilib-flag=bar | FileCheck 
--check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-ARM-MULTILIB-CUSTOM-FLAG %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/multilib-custom-flags.yaml 
-print-multi-flags-experimental --target=aarch64-none-eabi 
-fmultilib-flag=foo -fmultilib-flag=bar | FileCheck 
--check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-AARCH64-MULTILIB-CUSTOM-FLAG 
%s
 // CHECK-ARM-MULTILIB-CUSTOM-FLAG: --target=thumbv8m.main-unknown-none-eabi
 // CHECK-AARCH64-MULTILIB-CUSTOM-FLAG: --target=aarch64-unknown-none-eabi
 // CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=foo

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix test of `-print-multi-flags-experimental` in case of multilib custom flags (PR #123577)

2025-01-20 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/123577
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Multilib] Custom flags YAML parsing" (PR #122722)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/122722

Reverts llvm/llvm-project#110657

It seems that this patch is causing the sanitizer bot to fail. Reverting while 
I investigate

>From ad6c95a7c6e5e8d376225b42a3a71d5663aa7942 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 15:07:18 +
Subject: [PATCH] Revert "[Multilib] Custom flags YAML parsing (#110657)"

This reverts commit d98ced1a9d641539d5bbb287bd16378ba3f5dba9.
---
 clang/include/clang/Driver/Multilib.h |  28 +---
 clang/lib/Driver/Multilib.cpp |  73 ++
 ...remetal-multilib-custom-flags-parsing.yaml | 133 --
 3 files changed, 11 insertions(+), 223 deletions(-)
 delete mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1dab45c062aeec..dbed70f4f9008f 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,25 +101,6 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
-namespace custom_flag {
-struct Declaration;
-using DeclarationPtr = std::shared_ptr;
-
-struct ValueDetail {
-  std::string Name;
-  std::optional> MacroDefines;
-  DeclarationPtr Decl;
-};
-
-struct Declaration {
-  std::string Name;
-  SmallVector ValueList;
-  std::optional DefaultValueIdx;
-};
-
-static constexpr StringRef Prefix = "-fmultilib-flag=";
-} // namespace custom_flag
-
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -139,18 +120,15 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  SmallVector FlagMatchers;
-  SmallVector CustomFlagDecls;
+  std::vector FlagMatchers;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  SmallVector &&FlagMatchers = {},
-  SmallVector &&CustomFlagDecls = {})
-  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
-CustomFlagDecls(std::move(CustomFlagDecls)) {}
+  std::vector &&FlagMatchers = {})
+  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index b4b5dbd1bdb5e3..0207e0f2eb2ded 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,7 +10,6 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -202,20 +201,13 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  SmallVector Groups;
-  SmallVector Multilibs;
-  SmallVector FlagMatchers;
-  SmallVector CustomFlagDeclarations;
+  std::vector Groups;
+  std::vector Multilibs;
+  std::vector FlagMatchers;
 };
 
 } // end anonymous namespace
 
-LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
-LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
-LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
-LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
-LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
-
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -263,63 +255,11 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
-template <>
-struct llvm::yaml::MappingContextTraits> {
-  static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
-  llvm::SmallSet &) {
-io.mapRequired("Name", V.Name);
-io.mapOptional("MacroDefines", V.MacroDefines);
-  }
-  static std::string validate(IO &io, custom_flag::ValueDetail &V,
-  llvm::SmallSet &NameSet) {
-if (V.Name.empty())
-  return "custom flag value requires a name";
-if (!NameSet.insert(V.Name).second)
-  return "duplicate custom flag value name: \"" + V.Name + "\"";
-return {};
-  }
-};
-
-template <>
-struct llvm::yaml::MappingContextTraits> {
-  static void mapping(llvm::yaml::IO &io, custom_flag::DeclarationPtr &V,
-  llvm::SmallSet &NameSet) {
-assert(!V);
-V = std::make_shared();
-io.mapRequired("Name", V->Name);
-io.mapRequired("Values", V->ValueList, NameSet);
-std::string DefaultValueName;
-io.mapRequired("Default", DefaultValueName);
-
-for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) {
-  Value.Decl = V;
-  if (Value.Name == DefaultValueName) {
-assert(!V->DefaultValueIdx);
-V->DefaultValueIdx = Idx;
-  }
-}
-  }
-  static std::string validate(IO &io, custom_flag:

[clang] Revert "[Multilib] Custom flags YAML parsing" (PR #122722)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/122722
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Add -fmultilib-flag command-line option (PR #110658)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110659
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Add -fmultilib-flag command-line option (PR #110658)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/110658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2025-01-13 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-14 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110659

>From 16aa4a010c22288ba363e4ab680a38fe0b6a327d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 13:51:52 +
Subject: [PATCH 1/8] [Multilib] Custom flags YAML parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
---
 clang/include/clang/Driver/Multilib.h |  33 -
 clang/lib/Driver/Multilib.cpp | 109 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 264 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..0a533ed2804e25 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,30 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> MacroDefines;
+  Declaration *Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+
+  Declaration() = default;
+  Declaration(const Declaration &);
+  Declaration(Declaration &&);
+  Declaration &operator=(const Declaration &);
+  Declaration &operator=(Declaration &&);
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +144,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..ccf747e90cb2ca 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerializati

[clang] [Multilib] Custom flags YAML parsing (PR #122903)

2025-01-14 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/122903

This patch is the first step to extend the current multilib system to support 
the selection of library variants which do not correspond to existing 
command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or 
language options such as `--target`, `-mcpu`, `-mfpu`, `-mbranch-protection`. 
However, some library variants are particular to features that do not 
correspond to any command-line options. Examples include variants for 
multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider these 
features in library selection. This particular patch comprises a new section in 
`multilib.yaml` to declare flags for which no option exists. Henceforth this 
sort of flag will be called `custom flag` for clarity.

The `multilib.yaml` file will have a new section called Flags which contains 
the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not specified in 
the command-line invocation. It must be one value from the Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is the 
string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro definitions. 
Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags that have 
a most commonly used value.

The namespace of flag values is common across all flags. This means that flag 
values must be unique.

>From 16aa4a010c22288ba363e4ab680a38fe0b6a327d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 13:51:52 +
Subject: [PATCH] [Multilib] Custom flags YAML parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
---
 clang/include/clang/Driver/Multilib.h |  33 -
 clang/lib/Driver/Multilib.cpp | 109 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 264 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed7

[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2025-01-14 Thread Victor Campos via cfe-commits

vhscampos wrote:

I've reverted this patch because apparently Clang driver does not meld well 
with `std::shared_ptr`: memory leaks due to custom allocators I think. Thus 
I've redone the part to use raw pointers instead: 
https://github.com/llvm/llvm-project/pull/122903

https://github.com/llvm/llvm-project/pull/110657
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #122903)

2025-01-14 Thread Victor Campos via cfe-commits

vhscampos wrote:

This has been redone to use raw pointers instead, as shared_ptr apparently 
don't work well in the Clang driver due to custom allocators.

Functionally it's exactly the same patch.

https://github.com/llvm/llvm-project/pull/122903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/110659
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags YAML parsing (PR #122903)

2025-01-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/122903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110659

>From 16aa4a010c22288ba363e4ab680a38fe0b6a327d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 13:51:52 +
Subject: [PATCH 1/8] [Multilib] Custom flags YAML parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
---
 clang/include/clang/Driver/Multilib.h |  33 -
 clang/lib/Driver/Multilib.cpp | 109 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 264 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..0a533ed2804e25 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,30 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> MacroDefines;
+  Declaration *Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+
+  Declaration() = default;
+  Declaration(const Declaration &);
+  Declaration(Declaration &&);
+  Declaration &operator=(const Declaration &);
+  Declaration &operator=(Declaration &&);
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +144,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..ccf747e90cb2ca 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerializati

[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/110659
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add documentation for Multilib custom flags (PR #114998)

2025-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/114998

>From 16aa4a010c22288ba363e4ab680a38fe0b6a327d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 13:51:52 +
Subject: [PATCH 01/12] [Multilib] Custom flags YAML parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
---
 clang/include/clang/Driver/Multilib.h |  33 -
 clang/lib/Driver/Multilib.cpp | 109 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 264 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..0a533ed2804e25 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,30 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> MacroDefines;
+  Declaration *Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+
+  Declaration() = default;
+  Declaration(const Declaration &);
+  Declaration(Declaration &&);
+  Declaration &operator=(const Declaration &);
+  Declaration &operator=(Declaration &&);
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +144,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..ccf747e90cb2ca 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerializa

[clang] Add documentation for Multilib custom flags (PR #114998)

2025-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/114998
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add documentation for Multilib custom flags (PR #114998)

2025-01-16 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/114998
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-03-31 Thread Victor Campos via cfe-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/133716

The CXX module initializer function, which is called at program startup, needs 
to be tagged with Pointer Authentication and Branch Target Identification marks 
whenever relevant.

Before this patch, in CPUs set up for PACBTI execution, the function wasn't 
protected with return address signing and no BTI instruction was inserted at 
the start of it, thus leading to an execution fault.

This patch fixes the issue by marking the function with the function attributes 
related to PAC and BTI if relevant.

>From bb649666995a2642c5eea944e55c0a38503ed7bf Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 28 Mar 2025 15:55:07 +
Subject: [PATCH] Mark CXX module initializer with PACBTI attributes

The CXX module initializer function, which is called at program startup,
needs to be tagged with Pointer Authentication and Branch Target
Identification marks whenever relevant.

Before this patch, in CPUs set up for PACBTI execution, the function
wasn't protected with return address signing and no BTI instruction was
inserted at the start of it, thus leading to an execution fault.

This patch fixes the issue by marking the function with the function
attributes related to PAC and BTI if relevant.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  6 
 .../cxx20-module-initializer-pacbti.cpp   | 32 +++
 2 files changed, 38 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a01fa157c2b26..0366e3977b812 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
 Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+  getTarget().getTargetOpts().CPU)) {
+TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
+  }
+
   // We are done with the inits.
   AllImports.clear();
   PrioritizedCXXGlobalInits.clear();
diff --git a/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp 
b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
new file mode 100644
index 0..7ebaa5e8f349e
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -mbranch-target-enforce 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s
+
+// CHECK: define void @_ZGIW3foo() #0
+// CHECK-BTI: attributes #0 = { nounwind "branch-target-enforcement" }
+// CHECK-PAC: attributes #0 = { nounwind "sign-return-address"="non-leaf" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-ALL: attributes #0 = { nounwind "sign-return-address"="all" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="all" "sign-return-address-key"="a_key" }
+
+module;
+
+export module foo;
+
+export void func();

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][ARM]Ensure both -mno-unaligned-access and -munaligned-access are passed to multilib selection logic (PR #134099)

2025-04-03 Thread Victor Campos via cfe-commits

https://github.com/vhscampos approved this pull request.

LGTM. Please wait for @smithp35 's approval too.

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-04-04 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/133716

>From bb649666995a2642c5eea944e55c0a38503ed7bf Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 28 Mar 2025 15:55:07 +
Subject: [PATCH 1/2] Mark CXX module initializer with PACBTI attributes

The CXX module initializer function, which is called at program startup,
needs to be tagged with Pointer Authentication and Branch Target
Identification marks whenever relevant.

Before this patch, in CPUs set up for PACBTI execution, the function
wasn't protected with return address signing and no BTI instruction was
inserted at the start of it, thus leading to an execution fault.

This patch fixes the issue by marking the function with the function
attributes related to PAC and BTI if relevant.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  6 
 .../cxx20-module-initializer-pacbti.cpp   | 32 +++
 2 files changed, 38 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a01fa157c2b26..0366e3977b812 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
 Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+  getTarget().getTargetOpts().CPU)) {
+TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
+  }
+
   // We are done with the inits.
   AllImports.clear();
   PrioritizedCXXGlobalInits.clear();
diff --git a/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp 
b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
new file mode 100644
index 0..7ebaa5e8f349e
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -mbranch-target-enforce 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s
+
+// CHECK: define void @_ZGIW3foo() #0
+// CHECK-BTI: attributes #0 = { nounwind "branch-target-enforcement" }
+// CHECK-PAC: attributes #0 = { nounwind "sign-return-address"="non-leaf" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-ALL: attributes #0 = { nounwind "sign-return-address"="all" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="all" "sign-return-address-key"="a_key" }
+
+module;
+
+export module foo;
+
+export void func();

>From 6d23613662051546c0de1a1c9c0814147b47b425 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 4 Apr 2025 10:15:58 +0100
Subject: [PATCH 2/2] - Change patch to use existing function. - Modify
 setTargetAttributes function to work even without a function   declaration.

---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  7 +--
 clang/lib/CodeGen/Targets/ARM.cpp | 13 +++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 0366e3977b812..50b1bdde88d07 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -793,6 +793,7 @@ void CodeGenModule::E

[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-04-04 Thread Victor Campos via cfe-commits


@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
 Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+  getTarget().getTargetOpts().CPU)) {
+TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));

vhscampos wrote:

Thanks. I'll make the required changes to use `setTargetAttributes`.

https://github.com/llvm/llvm-project/pull/133716
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-04-04 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/133716

>From bb649666995a2642c5eea944e55c0a38503ed7bf Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 28 Mar 2025 15:55:07 +
Subject: [PATCH 1/3] Mark CXX module initializer with PACBTI attributes

The CXX module initializer function, which is called at program startup,
needs to be tagged with Pointer Authentication and Branch Target
Identification marks whenever relevant.

Before this patch, in CPUs set up for PACBTI execution, the function
wasn't protected with return address signing and no BTI instruction was
inserted at the start of it, thus leading to an execution fault.

This patch fixes the issue by marking the function with the function
attributes related to PAC and BTI if relevant.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  6 
 .../cxx20-module-initializer-pacbti.cpp   | 32 +++
 2 files changed, 38 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a01fa157c2b26..0366e3977b812 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
 Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+  getTarget().getTargetOpts().CPU)) {
+TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
+  }
+
   // We are done with the inits.
   AllImports.clear();
   PrioritizedCXXGlobalInits.clear();
diff --git a/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp 
b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
new file mode 100644
index 0..7ebaa5e8f349e
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -mbranch-target-enforce 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s
+
+// CHECK: define void @_ZGIW3foo() #0
+// CHECK-BTI: attributes #0 = { nounwind "branch-target-enforcement" }
+// CHECK-PAC: attributes #0 = { nounwind "sign-return-address"="non-leaf" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-ALL: attributes #0 = { nounwind "sign-return-address"="all" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="all" "sign-return-address-key"="a_key" }
+
+module;
+
+export module foo;
+
+export void func();

>From 6d23613662051546c0de1a1c9c0814147b47b425 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 4 Apr 2025 10:15:58 +0100
Subject: [PATCH 2/3] - Change patch to use existing function. - Modify
 setTargetAttributes function to work even without a function   declaration.

---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  7 +--
 clang/lib/CodeGen/Targets/ARM.cpp | 13 +++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 0366e3977b812..50b1bdde88d07 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -793,6 +793,7 @@ void CodeGenModule::E

[clang] [Clang][ARM]Ensure both -mno-unaligned-access and -munaligned-access are passed to multilib selection logic (PR #134099)

2025-04-03 Thread Victor Campos via cfe-commits

https://github.com/vhscampos closed 
https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-02 Thread Victor Campos via cfe-commits


@@ -69,9 +69,15 @@
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi | FileCheck 
--check-prefix=CHECK-NO-UNALIGNED-ACCESS %s

vhscampos wrote:

Add a line also for aarch64 and no option to test the default case

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-02 Thread Victor Campos via cfe-commits


@@ -69,9 +69,15 @@
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi | FileCheck 
--check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access 
| FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
 // CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
 
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -munaligned-access | 
FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf | FileCheck 
--check-prefix=CHECK-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -munaligned-access | 
FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s

vhscampos wrote:

Add a line for aarch64 and no option, to test the default alignment case

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-02 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-02 Thread Victor Campos via cfe-commits


@@ -69,9 +69,15 @@
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi | FileCheck 
--check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access 
| FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
 // CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
 
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -munaligned-access | 
FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf | FileCheck 
--check-prefix=CHECK-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -munaligned-access | 
FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s

vhscampos wrote:

Please ignore

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-02 Thread Victor Campos via cfe-commits


@@ -69,9 +69,15 @@
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi | FileCheck 
--check-prefix=CHECK-NO-UNALIGNED-ACCESS %s

vhscampos wrote:

Please ignore.

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-04 Thread Victor Campos via cfe-commits

https://github.com/vhscampos edited 
https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Bypass alignment option based on architecture features instead of command-line flags (PR #134099)

2025-04-05 Thread Victor Campos via cfe-commits

https://github.com/vhscampos commented:

Review of the commit msg:
- Add some categories to the title, like [Clang][ARM]
- The new solution still uses the command-line options (inside the function 
`getARMTargetFeatures`). However it also takes into account the architecture in 
order to determine the alignment access policy.
- I think "bypass" is the wrong term. One correct term I believe could be "pass 
along", as in "Clang passes along the options to the multilib system".

https://github.com/llvm/llvm-project/pull/134099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Mark CXX module initializer with PACBTI attributes (PR #133716)

2025-04-07 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/133716

>From bb649666995a2642c5eea944e55c0a38503ed7bf Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 28 Mar 2025 15:55:07 +
Subject: [PATCH 1/4] Mark CXX module initializer with PACBTI attributes

The CXX module initializer function, which is called at program startup,
needs to be tagged with Pointer Authentication and Branch Target
Identification marks whenever relevant.

Before this patch, in CPUs set up for PACBTI execution, the function
wasn't protected with return address signing and no BTI instruction was
inserted at the start of it, thus leading to an execution fault.

This patch fixes the issue by marking the function with the function
attributes related to PAC and BTI if relevant.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  6 
 .../cxx20-module-initializer-pacbti.cpp   | 32 +++
 2 files changed, 38 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a01fa157c2b26..0366e3977b812 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -818,6 +818,12 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
 Fn->addFnAttr("device-init");
   }
 
+  if (getTarget().isBranchProtectionSupportedArch(
+  getTarget().getTargetOpts().CPU)) {
+TargetInfo::BranchProtectionInfo BPI(getLangOpts());
+getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
+  }
+
   // We are done with the inits.
   AllImports.clear();
   PrioritizedCXXGlobalInits.clear();
diff --git a/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp 
b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
new file mode 100644
index 0..7ebaa5e8f349e
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -mbranch-target-enforce 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s
+
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi 
-emit-module-interface -target-feature +pacbti -msign-return-address=all 
-mbranch-target-enforce -std=c++20 %s -o %t.pcm
+// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm 
-emit-llvm -o - | \
+// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s
+
+// CHECK: define void @_ZGIW3foo() #0
+// CHECK-BTI: attributes #0 = { nounwind "branch-target-enforcement" }
+// CHECK-PAC: attributes #0 = { nounwind "sign-return-address"="non-leaf" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-ALL: attributes #0 = { nounwind "sign-return-address"="all" 
"sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
+// CHECK-PAC-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" 
"sign-return-address"="all" "sign-return-address-key"="a_key" }
+
+module;
+
+export module foo;
+
+export void func();

>From 6d23613662051546c0de1a1c9c0814147b47b425 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 4 Apr 2025 10:15:58 +0100
Subject: [PATCH 2/4] - Change patch to use existing function. - Modify
 setTargetAttributes function to work even without a function   declaration.

---
 clang/lib/CodeGen/CGDeclCXX.cpp   |  7 +--
 clang/lib/CodeGen/Targets/ARM.cpp | 13 +++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 0366e3977b812..50b1bdde88d07 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -793,6 +793,7 @@ void CodeGenModule::E