[clang] [clang-tools-extra] [lld] [lldb] [llvm] Rework the `Option` library to reduce dynamic relocations (PR #119198)

2024-12-10 Thread Chandler Carruth via cfe-commits

@@ -53,10 +53,8 @@ class OptTable {
 public:
   /// Entry for a single option instance in the option data table.
   struct Info {
-/// A null terminated array of prefix strings to apply to name while
-/// matching.
-ArrayRef Prefixes;
-StringLiteral PrefixedName;
+unsigned PrefixesOffset;

chandlerc wrote:

FWIW, I put together a simple abstraction here: 
https://github.com/llvm/llvm-project/pull/119488

Happy for suggestions on a stronger one, a different API, etc.

My preference would be to land independently and then connect. But if you'd 
like to see one or the other land first and roll in, let me know.

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


[clang] cc1a2ea - [AArch64] Implement FP8 SVE intrinsics for widening conversions (#118123)

2024-12-10 Thread via cfe-commits
Author: Momchil Velikov
Date: 2024-12-10T13:32:05Z
New Revision: cc1a2ea61e3f8e790125b10d9ec4e7d179156ddf

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

LOG: [AArch64] Implement FP8 SVE intrinsics for widening conversions (#118123)

This patch adds the following intrinsics:
* 8-bit floating-point convert to half-precision and BFloat16.

  // Variants are also available for: _bf16
  svfloat16_t svcvt1_f16[_mf8]_fpm(svmfloat8_t zn, fpm_t fpm);
  svfloat16_t svcvt2_f16[_mf8]_fpm(svmfloat8_t zn, fpm_t fpm);

* 8-bit floating-point convert to half-precision and BFloat16 (top).

  // Variants are also available for: _bf16
  svfloat16_t svcvtlt1_f16[_mf8]_fpm(svmfloat8_t zn, fpm_t fpm);
  svfloat16_t svcvtlt2_f16[_mf8]_fpm(svmfloat8_t zn, fpm_t fpm);

Added: 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvt.c
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c
llvm/test/CodeGen/AArch64/fp8-sve-cvt-cvtlt.ll

Modified: 
clang/include/clang/Basic/arm_sve.td
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
llvm/lib/Target/AArch64/SVEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 9b8a8546b072c0..7b8ecf29a9de6e 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2430,12 +2430,12 @@ let SVETargetGuard = InvalidMode, SMETargetGuard = 
"sme2,fp8" in {
   def FSCALE_X4 : Inst<"svscale[_{d}_x4]", "444.x", "fhd", MergeNone, 
"aarch64_sme_fp8_scale_x4", [IsStreaming],[]>;
 
   // Convert from FP8 to half-precision/BFloat16 multi-vector
-  def SVF1CVT : Inst<"svcvt1_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt1_x2", [IsStreaming, SetsFPMR], []>;
-  def SVF2CVT : Inst<"svcvt2_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt2_x2", [IsStreaming, SetsFPMR], []>;
+  def SVF1CVT_X2 : Inst<"svcvt1_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt1_x2", [IsStreaming, SetsFPMR], []>;
+  def SVF2CVT_X2 : Inst<"svcvt2_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt2_x2", [IsStreaming, SetsFPMR], []>;
 
   // Convert from FP8 to deinterleaved half-precision/BFloat16 multi-vector
-  def SVF1CVTL : Inst<"svcvtl1_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl1_x2",  [IsStreaming, SetsFPMR], []>;
-  def SVF2CVTL : Inst<"svcvtl2_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl2_x2",  [IsStreaming, SetsFPMR], []>;
+  def SVF1CVTL_X2 : Inst<"svcvtl1_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl1_x2",  [IsStreaming, SetsFPMR], []>;
+  def SVF2CVTL_X2 : Inst<"svcvtl2_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl2_x2",  [IsStreaming, SetsFPMR], []>;
 }
 
 let SVETargetGuard = "sve2p1", SMETargetGuard = "sme2" in {
@@ -2451,3 +2451,15 @@ let SVETargetGuard = "sve2,faminmax", SMETargetGuard = 
"sme2,faminmax" in {
   defm SVAMIN : SInstZPZZ<"svamin", "hfd", "aarch64_sve_famin", 
"aarch64_sve_famin_u">;
   defm SVAMAX : SInstZPZZ<"svamax", "hfd", "aarch64_sve_famax", 
"aarch64_sve_famax_u">;
 }
+
+let SVETargetGuard = "sve2,fp8", SMETargetGuard = "sme2,fp8" in {
+  // SVE FP8 widening conversions
+
+  // 8-bit floating-point convert to BFloat16/Float16
+  def SVF1CVT : SInst<"svcvt1_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt1", [VerifyRuntimeMode, SetsFPMR]>;
+  def SVF2CVT : SInst<"svcvt2_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt2", [VerifyRuntimeMode, SetsFPMR]>;
+
+  // 8-bit floating-point convert to BFloat16/Float16 (top)
+  def SVF1CVTLT : SInst<"svcvtlt1_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt1", [VerifyRuntimeMode, SetsFPMR]>;
+  def SVF2CVTLT : SInst<"svcvtlt2_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt2", [VerifyRuntimeMode, SetsFPMR]>;
+}

diff  --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvt.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvt.c
new file mode 100644
index 00..c026b8aa216f32
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvt.c
@@ -0,0 +1,173 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1-triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sve2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-10 Thread via cfe-commits
zmodem wrote:

> I've put it up on Dropbox

I looked at Builtins.cpp.obj and compared to the one in my build dir. They're 
very similar, in particular the string table is there in both files, and looks 
identical. I don't really have any more ideas for debugging this.

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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-12-10 Thread Alex Voicu via cfe-commits

@@ -225,7 +225,9 @@ ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty, 
bool Variadic,
 // Records with non-trivial destructors/copy-constructors should not be
 // passed by value.
 if (auto RAA = getRecordArgABI(Ty, getCXXABI()))
-  return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
+  return getNaturalAlignIndirect(
+  Ty, getContext().getTargetAddressSpace(LangAS::Default),
+  RAA == CGCXXABI::RAA_DirectInMemory);

AlexVlx wrote:

This is not intended to alter current behaviour, as without this patch non 
aliased indirect args wouldn't carry an AS, so it's just dealing with the 
interface extension for `getIndirect` / `getNaturalAlignIndirect`.

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


[clang] [clang][bytecode] Check vector element types for eligibility (PR #119385)

2024-12-10 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/119385

Like we do in ExprConstant.cpp.

>From 003dd9075216766af2b717e5cfd5f38fba15d6ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 10 Dec 2024 15:12:28 +0100
Subject: [PATCH] [clang][bytecode] Check vector element types for eligibility

Like we do in ExprConstant.cpp.
---
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 29 +++
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  |  5 
 2 files changed, 34 insertions(+)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index c9cd113287557b..7ba0faff252530 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -222,6 +222,35 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, 
QualType T,
 IsToType))
 return false;
 
+  if (const auto *VT = T->getAs()) {
+const ASTContext &ASTCtx = S.getASTContext();
+QualType EltTy = VT->getElementType();
+unsigned NElts = VT->getNumElements();
+unsigned EltSize =
+VT->isExtVectorBoolType() ? 1 : ASTCtx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % ASTCtx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  const Expr *E = S.Current->getExpr(OpPC);
+  S.FFDiag(E, diag::note_constexpr_bit_cast_invalid_vector)
+  << QualType(VT, 0) << EltSize << NElts << ASTCtx.getCharWidth();
+  return false;
+}
+
+if (EltTy->isRealFloatingType() &&
+&ASTCtx.getFloatTypeSemantics(EltTy) == &APFloat::x87DoubleExtended()) 
{
+  // The layout for x86_fp80 vectors seems to be handled very 
inconsistently
+  // by both clang and LLVM, so for now we won't allow bit_casts involving
+  // it in a constexpr context.
+  const Expr *E = S.Current->getExpr(OpPC);
+  S.FFDiag(E, diag::note_constexpr_bit_cast_unsupported_type) << EltTy;
+  return false;
+}
+  }
+
   return true;
 }
 
diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp 
b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
index e99ab3904c339c..8a5bef635b8fde 100644
--- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp
+++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
@@ -502,3 +502,8 @@ namespace OversizedBitField {

  // ref-note {{constexpr bit_cast involving bit-field is not yet supported}}
 #endif
 }
+
+typedef bool bool9 __attribute__((ext_vector_type(9)));
+// both-error@+2 {{constexpr variable 'bad_bool9_to_short' must be initialized 
by a constant expression}}
+// both-note@+1 {{bit_cast involving type 'bool 
__attribute__((ext_vector_type(9)))' (vector of 9 'bool' values) is not allowed 
in a constant expression; element size 1 * element count 9 is not a multiple of 
the byte size 8}}
+constexpr unsigned short bad_bool9_to_short = __builtin_bit_cast(unsigned 
short, bool9{1,1,0,1,0,1,0,1,0});

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


[clang] [analyzer] Don't assume third iteration in loops (PR #119388)

2024-12-10 Thread Donát Nagy via cfe-commits
NagyDonat wrote:

The difference between this PR and my earlier PR 
https://github.com/llvm/llvm-project/pull/109804 "Suppress out of bounds 
reports after weak loop assumptions" is:
| This PR | Earlier PR |
| :---: | :---: |
| affects all checkers | only affects ArrayBoundV2 |
| doesn't traverse unjustified paths | only suppresses reports after traversing 
the paths |
| only discards assuming third or later iteration | also suppresses reports 
after assuming zero iterations |

Slightly offtopic remark: I'm planning to create a separate commit to filter 
out branches where the analyzer assumes that 0 iterations happen in a loop 
(with an opaque condition). I'll probably put that logic behind an analyzer 
option (e.g. `assume-min-iterations` where I suggest 1 as the sane default 
value), because there is probably user demand for a pedantic analysis mode that 
aggressively assumes that loops can have 0 iterations. (This PR doesn't 
introduce an analyzer option, because I don't think that "I want the analyzer 
to assume that 3+ iterations can happen" is something that the users would want 
to use.)

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


[clang] [libcxx] [libcxx] Support for using timespec_get (PR #117362)

2024-12-10 Thread Louis Dionne via cfe-commits
ldionne wrote:

Gentle ping

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


[clang] [clang][bytecode][NFC] Avoid calling ASTContext::getTypeSize() (PR #119392)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

In the case of primitive arrays, we can do this once and reuse the value for 
all elements.

---
Full diff: https://github.com/llvm/llvm-project/pull/119392.diff


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+20-20) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index c9cd113287557b..3a056acff14a7f 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -33,8 +33,9 @@ using namespace clang::interp;
 //bytes to/from the buffer.
 
 /// Used to iterate over pointer fields.
-using DataFunc = llvm::function_ref;
+using DataFunc =
+llvm::function_ref;
 
 #define BITCAST_TYPE_SWITCH(Expr, B)   
\
   do { 
\
@@ -85,21 +86,25 @@ static bool enumerateData(const Pointer &P, const Context 
&Ctx, Bits Offset,
   assert(FieldDesc);
 
   // Primitives.
-  if (FieldDesc->isPrimitive())
-return F(P, FieldDesc->getPrimType(), Offset, /*PackedBools=*/false);
+  if (FieldDesc->isPrimitive()) {
+Bits FullBitWidth =
+Bits(Ctx.getASTContext().getTypeSize(FieldDesc->getType()));
+return F(P, FieldDesc->getPrimType(), Offset, FullBitWidth,
+ /*PackedBools=*/false);
+  }
 
   // Primitive arrays.
   if (FieldDesc->isPrimitiveArray()) {
 QualType ElemType = FieldDesc->getElemQualType();
-size_t ElemSizeInBits = Ctx.getASTContext().getTypeSize(ElemType);
+Bits ElemSize = Bits(Ctx.getASTContext().getTypeSize(ElemType));
 PrimType ElemT = *Ctx.classify(ElemType);
 // Special case, since the bools here are packed.
 bool PackedBools = FieldDesc->getType()->isExtVectorBoolType();
 unsigned NumElems = FieldDesc->getNumElems();
 bool Ok = true;
 for (unsigned I = P.getIndex(); I != NumElems; ++I) {
-  Ok = Ok && F(P.atIndex(I), ElemT, Offset, PackedBools);
-  Offset += PackedBools ? 1 : ElemSizeInBits;
+  Ok = Ok && F(P.atIndex(I), ElemT, Offset, ElemSize, PackedBools);
+  Offset += PackedBools ? Bits(1) : ElemSize;
   if (Offset >= BitsToRead)
 break;
 }
@@ -109,10 +114,10 @@ static bool enumerateData(const Pointer &P, const Context 
&Ctx, Bits Offset,
   // Composite arrays.
   if (FieldDesc->isCompositeArray()) {
 QualType ElemType = FieldDesc->getElemQualType();
-size_t ElemSizeInBits = Ctx.getASTContext().getTypeSize(ElemType);
+Bits ElemSize = Bits(Ctx.getASTContext().getTypeSize(ElemType));
 for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
   enumerateData(P.atIndex(I).narrow(), Ctx, Offset, BitsToRead, F);
-  Offset += ElemSizeInBits;
+  Offset += ElemSize;
   if (Offset >= BitsToRead)
 break;
 }
@@ -233,16 +238,14 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
 
   return enumeratePointerFields(
   FromPtr, Ctx, Buffer.size(),
-  [&](const Pointer &P, PrimType T, Bits BitOffset,
+  [&](const Pointer &P, PrimType T, Bits BitOffset, Bits FullBitWidth,
   bool PackedBools) -> bool {
-CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(P.getType());
-Bits BitWidth = Bits(ASTCtx.toBits(ObjectReprChars));
-Bits FullBitWidth = BitWidth;
+Bits BitWidth = FullBitWidth;
 
-if (const FieldDecl *FD = P.getField(); FD && FD->isBitField()) {
+if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
   BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
(unsigned)FullBitWidth.getQuantity()));
-} else if (T == PT_Bool && PackedBools)
+else if (T == PT_Bool && PackedBools)
   BitWidth = Bits(1);
 
 if (BitWidth.isZero())
@@ -261,8 +264,7 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
 }
 
 assert(P.isInitialized());
-auto Buff =
-std::make_unique(ObjectReprChars.getQuantity());
+auto Buff = std::make_unique(FullBitWidth.roundToBytes());
 // Work around floating point types that contain unused padding bytes.
 // This is really just `long double` on x86, which is the only
 // fundamental type with padding bytes.
@@ -357,11 +359,9 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr 
OpPC,
   ASTCtx.getTargetInfo().isLittleEndian() ? Endian::Little : Endian::Big;
   bool Success = enumeratePointerFields(
   ToPtr, S.getContext(), Buffer.size(),
-  [&](const Pointer &P, PrimType T, Bits BitOffset,
+  [&](const Pointer &P, PrimType T, Bits BitOffset, Bits FullBitWidth,
   bool PackedBools) -> bool {
 QualType PtrType = P.getType();
-CharUnits ObjectReprChars = ASTCtx.getTypeSizeInChars(P

[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-12-10 Thread Sam Elliott via cfe-commits
lenary wrote:

> > @rzinsly do you need someone to commit this?
> 
> Yes, please.

Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. Otherwise 
the commit will be from the github hidden email which we don't use in LLVM. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.



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


[clang] [clang][ExprConst] Move vector diagnostics to checkBitCastConstexprEl… (PR #119366)

2024-12-10 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr closed 
https://github.com/llvm/llvm-project/pull/119366
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2024-12-10 Thread Alex Voicu via cfe-commits

@@ -800,7 +800,9 @@ static ABIArgInfo classifyExpandedType(SwiftAggLowering 
&lowering,
   if (lowering.empty()) {
 return ABIArgInfo::getIgnore();
   } else if (lowering.shouldPassIndirectly(forReturn)) {
-return ABIArgInfo::getIndirect(alignmentForIndirect, /*byval*/ false);
+return ABIArgInfo::getIndirect(alignmentForIndirect,
+   /*AddrSpace*/ 0,
+   /*byval*/ false);

AlexVlx wrote:

I did not intend to alter behaviour here, but merely to adopt the changed 
interface. There's no easy way to use she LangAS::Default -> Target mapping 
here in this helper function, hence the hardcoding to 0.

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-10 Thread via cfe-commits
yronglin wrote:

> LGTM
> 
> I'm a little concerned this is going to lead to other crashes due to exposing 
> more codepaths to "invalid" decls. But it seems like it's doing the right 
> thing in the given cases.

Yeah, if the PR breaks clang, I'll revert it quickly.

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


[clang] e6ba345 - [X86][AVX10.2] Add comments for the avx10_2copyintrin.h file (#119238)

2024-12-10 Thread via cfe-commits
Author: Mikołaj Piróg
Date: 2024-12-10T21:49:28+08:00
New Revision: e6ba3452ab086cf24725f3587709150b686d4b05

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

LOG: [X86][AVX10.2] Add comments for the avx10_2copyintrin.h file (#119238)

As in title

Added: 


Modified: 
clang/lib/Headers/avx10_2copyintrin.h

Removed: 




diff  --git a/clang/lib/Headers/avx10_2copyintrin.h 
b/clang/lib/Headers/avx10_2copyintrin.h
index 7fc31190781d91..76b8f8ced540d3 100644
--- a/clang/lib/Headers/avx10_2copyintrin.h
+++ b/clang/lib/Headers/avx10_2copyintrin.h
@@ -19,11 +19,43 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(128)))
 
+/// Constructs a 128-bit integer vector, setting the lower 32 bits to the
+///lower 32 bits of the parameter \a __A; the upper bits are zeoroed.
+///
+/// \code{.operation}
+/// result[31:0] := __A[31:0]
+/// result[MAX:32] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  VMOVD  instruction.
+///
+/// \param __A
+///A 128-bit integer vector.
+/// \returns A 128-bit integer vector. The lower 32 bits are copied from the
+///parameter \a __A; the upper bits are zeroed.
 static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi32(__m128i __A) {
   return (__m128i)__builtin_shufflevector(
   (__v4si)__A, (__v4si)_mm_setzero_si128(), 0, 4, 4, 4);
 }
 
+/// Constructs a 128-bit integer vector, setting the lower 16 bits to the
+///lower 16 bits of the parameter \a __A; the upper bits are zeoroed.
+///
+/// \code{.operation}
+/// result[15:0] := __A[15:0]
+/// result[MAX:16] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the  VMOVW  instruction.
+///
+/// \param __A
+///A 128-bit integer vector.
+/// \returns A 128-bit integer vector. The lower 16 bits are copied from the
+///parameter \a __A; the upper bits are zeroed.
 static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi16(__m128i __A) {
   return (__m128i)__builtin_shufflevector(
   (__v8hi)__A, (__v8hi)_mm_setzero_si128(), 0, 8, 8, 8, 8, 8, 8, 8);



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


[clang] [X86][AVX10.2] Add comments for the avx10_2copyintrin.h file (PR #119238)

2024-12-10 Thread via cfe-commits
github-actions[bot] wrote:



@mikolaj-pirog Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [X86][AVX10.2] Add comments for the avx10_2copyintrin.h file (PR #119238)

2024-12-10 Thread Phoebe Wang via cfe-commits
https://github.com/phoebewang closed 
https://github.com/llvm/llvm-project/pull/119238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c5ab70c - [WebAssembly] Add `-i128:128` to the `datalayout` string. (#119204)

2024-12-10 Thread via cfe-commits
Author: Dan Gohman
Date: 2024-12-10T09:21:58-08:00
New Revision: c5ab70c508457eaece5d7ff4ab79a2f90bc67f06

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

LOG: [WebAssembly] Add `-i128:128` to the `datalayout` string. (#119204)

Clang [defaults to aligning `__int128_t` to 16 bytes], while LLVM
`datalayout` strings [default to aligning `i128` to 8 bytes]. Wasm is
currently using the defaults for both, so it's inconsistent. Fix this by
adding `-i128:128` to Wasm's `datalayout` string so that it aligns
`i128` to 16 bytes too.

This is similar to
[llvm/llvm-project@dbad963](https://github.com/llvm/llvm-project/commit/dbad963a69fd7b16c6838f81b61167fbf00a413c)
for SPARC.

This fixes rust-lang/rust#133991; see that issue for further discussion.

[defaults to aligning `__int128_t` to 16 bytes]:
https://github.com/llvm/llvm-project/blob/f8b4182f076f8fe55f9d5f617b5a25008a77b22f/clang/lib/Basic/TargetInfo.cpp#L77
[default to aligning `i128` to 8 bytes]:
https://llvm.org/docs/LangRef.html#langref-datalayout

Added: 
llvm/test/CodeGen/WebAssembly/data-align.ll

Modified: 
clang/lib/Basic/Targets/WebAssembly.h
clang/test/CodeGen/target-data.c
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/test/CodeGen/WebAssembly/multi-return.ll
llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index 1cae72e58e08ba..6ce2bb00e5f2a6 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -183,11 +183,12 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
const TargetOptions &Opts)
   : WebAssemblyTargetInfo(T, Opts) {
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
-  "S128-ni:1:10:20");
-else
   resetDataLayout(
-  "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
+  "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
+  "S128-ni:1:10:20");
+else
+  resetDataLayout("e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
+  "S128-ni:1:10:20");
   }
 
 protected:
@@ -207,11 +208,12 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
 PtrDiffType = SignedLong;
 IntPtrType = SignedLong;
 if (T.isOSEmscripten())
-  resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-"
-  "S128-ni:1:10:20");
-else
   resetDataLayout(
-  "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20");
+  "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-"
+  "S128-ni:1:10:20");
+else
+  resetDataLayout("e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-"
+  "S128-ni:1:10:20");
   }
 
 protected:

diff  --git a/clang/test/CodeGen/target-data.c 
b/clang/test/CodeGen/target-data.c
index 2c758567faa1f6..71eb849433ed40 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -108,11 +108,11 @@
 
 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
-// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY32: target datalayout = 
"e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
-// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
+// WEBASSEMBLY64: target datalayout = 
"e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20"
 
 // RUN: %clang_cc1 -triple lanai-unknown-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=LANAI

diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index d54176a7878b5a..06e62bf7f9f757 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5559,7 +5559,8 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, 
StringRef TT) {
 return Res;
   }
 
-  if (T.isSPARC() || (T.isMIPS64() && !DL.contains("m:m")) || T.isPPC64()) {
+  if (T.isSPARC() || (T.isMIPS64() && !DL.contains("m:m")) || T.isPPC64() ||
+  T.isWasm()) {
 // Mips64 with o32 ABI did not add "-i128:128".
 // Add "-i128:128"
 std::string I64 = "-i64:64";

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 8ec72d5c47833a..9c95d730480f91 100644
--- a/llvm/lib/Target/WebAssembly/Web

[clang] 0fb0617 - [clang][bytecode] Check vector element types for eligibility (#119385)

2024-12-10 Thread via cfe-commits
Author: Timm Baeder
Date: 2024-12-10T17:56:48+01:00
New Revision: 0fb06172f14110daa45bed8ae4c153967c9365dc

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

LOG: [clang][bytecode] Check vector element types for eligibility (#119385)

Like we do in ExprConstant.cpp.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/test/AST/ByteCode/builtin-bit-cast.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index c9cd113287557b..7ba0faff252530 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -222,6 +222,35 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, 
QualType T,
 IsToType))
 return false;
 
+  if (const auto *VT = T->getAs()) {
+const ASTContext &ASTCtx = S.getASTContext();
+QualType EltTy = VT->getElementType();
+unsigned NElts = VT->getNumElements();
+unsigned EltSize =
+VT->isExtVectorBoolType() ? 1 : ASTCtx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % ASTCtx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  const Expr *E = S.Current->getExpr(OpPC);
+  S.FFDiag(E, diag::note_constexpr_bit_cast_invalid_vector)
+  << QualType(VT, 0) << EltSize << NElts << ASTCtx.getCharWidth();
+  return false;
+}
+
+if (EltTy->isRealFloatingType() &&
+&ASTCtx.getFloatTypeSemantics(EltTy) == &APFloat::x87DoubleExtended()) 
{
+  // The layout for x86_fp80 vectors seems to be handled very 
inconsistently
+  // by both clang and LLVM, so for now we won't allow bit_casts involving
+  // it in a constexpr context.
+  const Expr *E = S.Current->getExpr(OpPC);
+  S.FFDiag(E, diag::note_constexpr_bit_cast_unsupported_type) << EltTy;
+  return false;
+}
+  }
+
   return true;
 }
 

diff  --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp 
b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
index e99ab3904c339c..8a5bef635b8fde 100644
--- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp
+++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
@@ -502,3 +502,8 @@ namespace OversizedBitField {

  // ref-note {{constexpr bit_cast involving bit-field is not yet supported}}
 #endif
 }
+
+typedef bool bool9 __attribute__((ext_vector_type(9)));
+// both-error@+2 {{constexpr variable 'bad_bool9_to_short' must be initialized 
by a constant expression}}
+// both-note@+1 {{bit_cast involving type 'bool 
__attribute__((ext_vector_type(9)))' (vector of 9 'bool' values) is not allowed 
in a constant expression; element size 1 * element count 9 is not a multiple of 
the byte size 8}}
+constexpr unsigned short bad_bool9_to_short = __builtin_bit_cast(unsigned 
short, bool9{1,1,0,1,0,1,0,1,0});



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


[clang-tools-extra] [clang-tidy][NFC] reorder cmake source file (PR #119374)

2024-12-10 Thread via cfe-commits
EugeneZelenko wrote:

Did you look on `CMakeLists.txt` files in other directories? Just in case :-)

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


[clang] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (PR #119117)

2024-12-10 Thread Tom Stellard via cfe-commits
https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/119117

>From 5d13b69039fab7c5960288cead18dc76f5d01f4f Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 5 Dec 2024 15:01:27 +
Subject: [PATCH 1/5] [clang][perf-training] Fix profiling with
 -DCLANG_BOLT=perf

This fixes the llvm-support build that generates the profile data.
However, I'm wondering if maybe we should disable llvm-suppot and
only run hello-world with -DCLANG_BOLT=perf.  The bolt optimizations
with perf only give about a 3% performance increase (although maybe
with hw counters this would be better) and it takes a very long
time to convert all the perf profiles to the fdata format.
---
 clang/utils/perf-training/bolt.lit.cfg| 22 +++
 .../perf-training/llvm-support/build.test |  4 ++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clang/utils/perf-training/bolt.lit.cfg 
b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..04b18975275495 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,21 +8,32 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf "
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf"
 
 if clang_bolt_mode == "instrument":
 perf_wrapper = ""
 clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-perf_wrapper += " --lbr -- "
+perf_wrapper += " --lbr --"
 elif clang_bolt_mode == "perf":
-perf_wrapper += " -- "
+perf_wrapper += " --"
 else:
 assert 0, "Unsupported CLANG_BOLT_MODE variable"
 
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
 lit.util.which(clang_binary, config.clang_tools_dir)
 ).replace("\\", "/")
+config.clang = f'{perf_wrapper} {clang_nowrapper}'
+
+# We need to limit the number of build jobs with perf in order to avoid this
+# error:
+# 
+# | Permission error mapping pages.
+# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
+# | or try again with a smaller value of -m/--mmap_pages.
+ninja_args = ""
+if clang_bolt_mode != "instrument":
+ninja_args = "-j1"
 
 config.name = "Clang Perf Training"
 config.suffixes = [
@@ -52,3 +63,6 @@ config.substitutions.append(("%test_root", 
config.test_exec_root))
 config.substitutions.append(('%cmake_generator', config.cmake_generator))
 config.substitutions.append(('%cmake', config.cmake_exe))
 config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_cmake_compiler_launcher', 
perf_wrapper.replace(' ', ';')))
+config.substitutions.append(('%nowrapper_clang', clang_nowrapper))
+config.substitutions.append(('%ninja_args', ninja_args))
diff --git a/clang/utils/perf-training/llvm-support/build.test 
b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..1f4d76502a3757 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir 
-DCMAKE_CXX_COMPILER_LAUNCHER="%perf_cmake_compiler_launcher" 
-DCMAKE_C_COMPILER="%nowrapper_clang" -DCMAKE_CXX_COMPILER="%nowrapper_clang" 
-DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
+RUN: %cmake --build %t %ninja_args -v --target LLVMSupport

>From 9aa48ac20e931d8192cecfec6ef789ea936fa6ff Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 9 Dec 2024 19:23:40 +
Subject: [PATCH 2/5] Revert "[clang][perf-training] Fix profiling with
 -DCLANG_BOLT=perf"

This reverts commit 5d13b69039fab7c5960288cead18dc76f5d01f4f.
---
 clang/utils/perf-training/bolt.lit.cfg| 22 ---
 .../perf-training/llvm-support/build.test |  4 ++--
 2 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/clang/utils/perf-training/bolt.lit.cfg 
b/clang/utils/perf-training/bolt.lit.cfg
index 04b18975275495..1d0cf9a8a17a8e 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,32 +8,21 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf"
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py 
perf "
 
 if clang_bolt_mode == "instrument":
 perf_wrapper = ""
 clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-perf_wrapper += " --lbr --"
+perf_wrapper += " --lbr -- "
 elif clang_bolt_mode == "perf":
-perf_wrapper += " --"
+perf_wrapper += " -- "
 else:
 assert 0, "Un

[clang] [llvm] [WebAssembly] Add `-i128:128` to the `datalayout` string. (PR #119204)

2024-12-10 Thread Dan Gohman via cfe-commits
https://github.com/sunfishcode closed 
https://github.com/llvm/llvm-project/pull/119204
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Darwin][Driver][clang] Prioritise command line args over `DEFAULT_SYSROOT` (PR #115993)

2024-12-10 Thread Steven Wu via cfe-commits
https://github.com/cachemeifyoucan approved this pull request.

LGTM

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


[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)

2024-12-10 Thread Chris B via cfe-commits
https://github.com/llvm-beanz approved this pull request.


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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread via cfe-commits
https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/117904

>From 1703aa62cfe35538aedbacb28e907535e838248c Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Fri, 20 Sep 2024 01:41:29 -0500
Subject: [PATCH 1/5] Support for dispatch construct (Sema & Codegen) support.
 Support for clauses depend, novariants & nocontext.

---
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/OpenMPKinds.h   |   6 +
 clang/include/clang/Sema/SemaOpenMP.h |   7 +
 clang/lib/Basic/OpenMPKinds.cpp   |   5 +
 clang/lib/CodeGen/CGStmt.cpp  |   2 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   4 +
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Sema/SemaOpenMP.cpp | 301 ++-
 clang/test/OpenMP/dispatch_codegen.cpp| 359 ++
 clang/test/OpenMP/dispatch_unsupported.c  |   7 -
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   6 +
 11 files changed, 687 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/OpenMP/dispatch_codegen.cpp
 delete mode 100644 clang/test/OpenMP/dispatch_unsupported.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8495884dcd058f..81b876f9fd85c5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11774,6 +11774,9 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def warn_omp_dispatch_clause_novariants_nocontext : Warning<
+  "only 'novariants' clause is supported when 'novariants' & 'nocontext' 
clauses occur on the same dispatch construct">,
+  InGroup;
 def err_openmp_vla_in_task_untied : Error<
   "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
 def warn_omp_unterminated_declare_target : Warning<
diff --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index 900ad6ca6d66f6..7579fab43dbb19 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -269,6 +269,12 @@ bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind);
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
+/// Checks if the specified directive is a dispatch-kind directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a dispatch-like directive like 'omp
+/// dispatch', otherwise - false.
+bool isOpenMPDispatchDirective(OpenMPDirectiveKind DKind);
+
 /// Checks if the specified directive is a target code offload directive.
 /// \param DKind Specified directive.
 /// \return true - the directive is a target code offload directive like
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..80cee9e7583051 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1462,6 +1462,13 @@ class SemaOpenMP : public SemaBase {
: OMPDeclareVariantScopes.back().TI;
   }
 
+  StmtResult transformDispatchDirective(OpenMPDirectiveKind Kind,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion,
+ArrayRef Clauses,
+Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc);
+
   /// The current `omp begin/end declare variant` scopes.
   SmallVector OMPDeclareVariantScopes;
 
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..44ee63df46adb5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -621,6 +621,11 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind 
DKind) {
  llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
 }
 
+bool clang::isOpenMPDispatchDirective(OpenMPDirectiveKind DKind) {
+  return DKind == OMPD_dispatch ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
+}
+
 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
   return DKind == OMPD_target ||
  llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 698baf853507f4..f3eedb79844378 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -417,7 +417,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 EmitOMPInteropDirective(cast(*S));
 break;
   case Stmt::OMPDispatchDirectiveClass:
-CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
+   

[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-12-10 Thread Craig Topper via cfe-commits
topperc wrote:

I should have a fix for the buildbot failure in a few minutes

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


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits

@@ -1270,77 +1270,21 @@ exit:
 ; MODULE: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; MODULE: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; MODULE: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; MODULE: attributes #[[ATTR4]] = { "kernel" }
-; MODULE: attributes #[[ATTR5]] = { nosync memory(none) }
+; MODULE: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }
+; MODULE: attributes #[[ATTR5]] = { "kernel" }
+; MODULE: attributes #[[ATTR6]] = { nosync memory(none) }
 ;.
 ; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CGSCC: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; CGSCC: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; CGSCC: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; CGSCC: attributes #[[ATTR4]] = { "kernel" }
-; CGSCC: attributes #[[ATTR5]] = { nosync memory(none) }
+; CGSCC: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }

AlexMaclean wrote:

The problem is that OpenMP seems to need to be able to draw a distinction 
between OpenMP kernels and nvvm kernels. For example here it seems like OpenMP 
only wants to look at "kernel" not "nvvm.kernel". As a result it seems like 
these attributes cannot be easily unified. 
https://github.com/llvm/llvm-project/blob/c835b48a4d72227b174bcd86f071238a1583803a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp#L5932-L5938

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


[clang] [CIR] Cleanup: mlirContext and astContext (PR #119450)

2024-12-10 Thread Shoaib Meenai via cfe-commits
https://github.com/smeenai approved this pull request.

LGTM

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


[clang] [test][AArch64] Fix test in non-writeable dir (PR #119448)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jordan Rupprecht (rupprecht)


Changes

cc1a2ea61e3f8e790125b10d9ec4e7d179156ddf adds a test which can fail if the 
output directory is not writeable. Following the pattern of other tests in this 
package, use `-o -` to print the IR to stdout instead of to a file.

---
Full diff: https://github.com/llvm/llvm-project/pull/119448.diff


1 Files Affected:

- (modified) clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c (+1-1) 


``diff
diff --git a/clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c 
b/clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c
index aafd42f798d935..2e94c2314f1824 100644
--- a/clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c
+++ b/clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c
@@ -1,6 +1,6 @@
 // REQUIRES: aarch64-registered-target
 
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -verify 
-emit-llvm %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -verify 
-emit-llvm -o - %s
 
 #include 
 

``




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


[clang] [NFC] Updating Debug Info generation for 'this' (PR #119445)

2024-12-10 Thread David Blaikie via cfe-commits
dwblaikie wrote:

any chance you could A/B test this on a bootstrap of clang, for instance? To 
help validate that this really is NFC/dead code?

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


[clang] [CIR] Cleanup: mlirContext and astContext (PR #119450)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: David Olsen (dkolsen-pgi)


Changes

ClangIR CodeGen code uses both `mlir::MLIRContext` and `clang::ASTContext` 
objects extensively.  Refering to either of those as just "context" can be 
confusing.

Change the names of all variables, parameters, and fields in 
`clang/lib/CIR/CodeGen` that refer to `MLIRContext` or an `ASTContext` to be 
either `mlirContext` or `astContext`.

This change is only the renaming of variables/parameters/fields.  There are no 
behavior changes.  So there are no new tests or changes to existing tests.  
This change mimics a recent change in the ClangIR incubator repository.

---
Full diff: https://github.com/llvm/llvm-project/pull/119450.diff


6 Files Affected:

- (modified) clang/include/clang/CIR/CIRGenerator.h (+3-3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+7-6) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+3-3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+8-6) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.h (+1-1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+6-6) 


``diff
diff --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index c8ca7e4bfa7285..414eba80b88b8f 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -37,14 +37,14 @@ namespace cir {
 class CIRGenerator : public clang::ASTConsumer {
   virtual void anchor();
   clang::DiagnosticsEngine &diags;
-  clang::ASTContext *astCtx;
+  clang::ASTContext *astContext;
   // Only used for debug info.
   llvm::IntrusiveRefCntPtr fs;
 
   const clang::CodeGenOptions &codeGenOpts;
 
 protected:
-  std::unique_ptr mlirCtx;
+  std::unique_ptr mlirContext;
   std::unique_ptr cgm;
 
 public:
@@ -52,7 +52,7 @@ class CIRGenerator : public clang::ASTConsumer {
llvm::IntrusiveRefCntPtr fs,
const clang::CodeGenOptions &cgo);
   ~CIRGenerator() override;
-  void Initialize(clang::ASTContext &astCtx) override;
+  void Initialize(clang::ASTContext &astContext) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
   mlir::ModuleOp getModule() const;
 };
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index e7c9512dcd3de8..0db24c3b41d18d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -25,13 +25,14 @@
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
-   clang::ASTContext &astctx,
+CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
+   clang::ASTContext &astContext,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
-  diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
+: builder(mlirContext, *this), astContext(astContext),
+  langOpts(astContext.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&mlirContext))},
+  diags(diags), target(astContext.getTargetInfo()), genTypes(*this) {
 
   // Initialize cached types
   SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
@@ -48,7 +49,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
 
 mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
   assert(cLoc.isValid() && "expected valid source location");
-  const SourceManager &sm = astCtx.getSourceManager();
+  const SourceManager &sm = astContext.getSourceManager();
   PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
   StringRef filename = pLoc.getFilename();
   return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h 
b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 397e501fd4e873..1c7ed63773900a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -41,7 +41,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenModule &operator=(CIRGenModule &) = delete;
 
 public:
-  CIRGenModule(mlir::MLIRContext &context, clang::ASTContext &astctx,
+  CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
const clang::CodeGenOptions &cgo,
clang::DiagnosticsEngine &diags);
 
@@ -51,7 +51,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenBuilderTy builder;
 
   /// Hold Clang AST information.
-  clang::ASTContext &astCtx;
+  clang::ASTContext &astContext;
 
   const clang::LangOptions &langOpts;
 
@@ -67,7 +67,7 @@ class CIRGenModule : public CIRGenTypeCache {
 public:
   mlir::ModuleOp getModule() const { return theModule; }
   CIRGenBuilderTy &getBuilder() { return builder; }
-  clang::ASTContext &getASTContext() const { return astCtx; }

[clang] 7eb73b9 - [CIR] Cleanup: mlirContext and astContext (#119450)

2024-12-10 Thread via cfe-commits
Author: David Olsen
Date: 2024-12-10T13:46:07-08:00
New Revision: 7eb73b95cb336cde14d5c755a09cd880bd3d5df9

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

LOG: [CIR] Cleanup: mlirContext and astContext (#119450)

ClangIR CodeGen code uses both `mlir::MLIRContext` and
`clang::ASTContext` objects extensively. Refering to either of those as
just "context" can be confusing.

Change the names of all variables, parameters, and fields in
`clang/lib/CIR/CodeGen` that refer to `MLIRContext` or an `ASTContext`
to be either `mlirContext` or `astContext`.

This change is only the renaming of variables/parameters/fields. There
are no behavior changes. So there are no new tests or changes to
existing tests. This change mimics a recent change in the ClangIR
incubator repository.

Added: 


Modified: 
clang/include/clang/CIR/CIRGenerator.h
clang/lib/CIR/CodeGen/CIRGenModule.cpp
clang/lib/CIR/CodeGen/CIRGenModule.h
clang/lib/CIR/CodeGen/CIRGenTypes.cpp
clang/lib/CIR/CodeGen/CIRGenTypes.h
clang/lib/CIR/CodeGen/CIRGenerator.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index c8ca7e4bfa7285..414eba80b88b8f 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -37,14 +37,14 @@ namespace cir {
 class CIRGenerator : public clang::ASTConsumer {
   virtual void anchor();
   clang::DiagnosticsEngine &diags;
-  clang::ASTContext *astCtx;
+  clang::ASTContext *astContext;
   // Only used for debug info.
   llvm::IntrusiveRefCntPtr fs;
 
   const clang::CodeGenOptions &codeGenOpts;
 
 protected:
-  std::unique_ptr mlirCtx;
+  std::unique_ptr mlirContext;
   std::unique_ptr cgm;
 
 public:
@@ -52,7 +52,7 @@ class CIRGenerator : public clang::ASTConsumer {
llvm::IntrusiveRefCntPtr fs,
const clang::CodeGenOptions &cgo);
   ~CIRGenerator() override;
-  void Initialize(clang::ASTContext &astCtx) override;
+  void Initialize(clang::ASTContext &astContext) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
   mlir::ModuleOp getModule() const;
 };

diff  --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index e7c9512dcd3de8..0db24c3b41d18d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -25,13 +25,14 @@
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
-   clang::ASTContext &astctx,
+CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
+   clang::ASTContext &astContext,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
-  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
-  diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
+: builder(mlirContext, *this), astContext(astContext),
+  langOpts(astContext.getLangOpts()),
+  theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&mlirContext))},
+  diags(diags), target(astContext.getTargetInfo()), genTypes(*this) {
 
   // Initialize cached types
   SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
@@ -48,7 +49,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
 
 mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
   assert(cLoc.isValid() && "expected valid source location");
-  const SourceManager &sm = astCtx.getSourceManager();
+  const SourceManager &sm = astContext.getSourceManager();
   PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
   StringRef filename = pLoc.getFilename();
   return mlir::FileLineColLoc::get(builder.getStringAttr(filename),

diff  --git a/clang/lib/CIR/CodeGen/CIRGenModule.h 
b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 397e501fd4e873..1c7ed63773900a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -41,7 +41,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenModule &operator=(CIRGenModule &) = delete;
 
 public:
-  CIRGenModule(mlir::MLIRContext &context, clang::ASTContext &astctx,
+  CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
const clang::CodeGenOptions &cgo,
clang::DiagnosticsEngine &diags);
 
@@ -51,7 +51,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenBuilderTy builder;
 
   /// Hold Clang AST information.
-  clang::ASTContext &astCtx;
+  clang::ASTContext &astContext;
 
   const clang::LangOptions &langOpts;
 
@@ -67,7 +67,7 @@ class CIRGenModule : public CIRGenTypeCache {
 public:
   

[clang-tools-extra] Add new tool: clang-read-diagnostics (PR #118522)

2024-12-10 Thread Yuxuan Chen via cfe-commits
https://github.com/yuxuanchen1997 closed 
https://github.com/llvm/llvm-project/pull/118522
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] C++ Templates: Refactor and fix `TransformLambdaExpr`'s mishandling of TypeLocs (PR #78801)

2024-12-10 Thread Yuxuan Chen via cfe-commits
https://github.com/yuxuanchen1997 closed 
https://github.com/llvm/llvm-project/pull/78801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 54ca1c4 - [clang-format] Fix idempotent format of hash in macro body (#118513)

2024-12-10 Thread via cfe-commits
Author: Owen Pan
Date: 2024-12-10T16:47:21-08:00
New Revision: 54ca1c4212e7ff3df880adb1a04dc3d41c033681

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

LOG: [clang-format] Fix idempotent format of hash in macro body (#118513)

Fixes #118334.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c182aaf0876d1b..de7e261b21d303 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -512,7 +512,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   break;
 do {
   NextTok = Tokens->getNextToken();
-} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));
+} while (!NextTok->HasUnescapedNewline && NextTok->isNot(tok::eof));
 
 while (NextTok->is(tok::comment))
   NextTok = Tokens->getNextToken();

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 93e1bbffe806fa..eeb857a914b1a2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5724,6 +5724,24 @@ TEST_F(FormatTest, HashInMacroDefinition) {
getLLVMStyleWithColumns(22));
 
   verifyFormat("#define A void # ## #", getLLVMStyleWithColumns(22));
+
+#if 0
+  // FIXME: The correct format is:
+  verifyFormat("{\n"
+   "  {\n"
+   "#define GEN_ID(_x) char *_x{#_x}\n"
+   "GEN_ID(one);\n"
+   "  }\n"
+   "}");
+#endif
+  verifyFormat("{\n"
+   "  {\n"
+   "#define GEN_ID(_x) \\\n"
+   "  char *_x { #_x }\n"
+   "GEN_ID(one);\n"
+   "  }\n"
+   "}",
+   getGoogleStyle());
 }
 
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 9db3187ac44e70..38658fcb0e9990 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3346,6 +3346,25 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
   EXPECT_BRACE_KIND(Tokens[13], BK_Block);
 
+  Tokens = annotate("{\n"
+"  {\n"
+"#define GEN_ID(_x) char *_x{#_x}\n"
+"GEN_ID(one);\n"
+"  }\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_brace, TT_BlockLBrace);
+  EXPECT_BRACE_KIND(Tokens[0], BK_Block);
+  EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_BlockLBrace);
+  EXPECT_BRACE_KIND(Tokens[1], BK_Block);
+#if 0
+  // FIXME:
+  EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[14], BK_BracedInit);
+#endif
+  EXPECT_BRACE_KIND(Tokens[20], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[21], BK_Block);
+
   Tokens = annotate("a = class extends goog.a {};",
 getGoogleStyle(FormatStyle::LK_JavaScript));
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;



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


[clang] [clang-format] Fix idempotent format of hash in macro body (PR #118513)

2024-12-10 Thread Owen Pan via cfe-commits
https://github.com/owenca closed 
https://github.com/llvm/llvm-project/pull/118513
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][NFC] Refactor suspend emit logic in coroutine codegen (PR #73564)

2024-12-10 Thread Yuxuan Chen via cfe-commits
https://github.com/yuxuanchen1997 closed 
https://github.com/llvm/llvm-project/pull/73564
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-12-10 Thread Yuxuan Chen via cfe-commits

@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema 
&S, VarDecl *CoroPromise,
 return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null(
-  BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", 
CoroHandle);
+if (!SubExpr)
+  return nullptr;
+if (auto *E = dyn_cast(SubExpr)) {
+  // This happens when await_suspend return type is not trivially
+  // destructible. This doesn't happen for the permitted return types of
+  // such function. Diagnose it later.
+  return cast_or_null(E->getSubExpr());
+} else {
+  return cast_or_null(SubExpr);
+}

yuxuanchen1997 wrote:

I still want to fix this. Let me rebase and revive it. 

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-12-10 Thread Yuxuan Chen via cfe-commits
https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/85684

>From b843c2f71a1a43cb897b557f783d60c6bf26f687 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 18 Mar 2024 10:45:20 -0700
Subject: [PATCH] Check if Coroutine await_suspend type returns the right type

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Sema/SemaCoroutine.cpp  | 119 +-
 clang/test/SemaCXX/coroutines.cpp |  28 -
 4 files changed, 111 insertions(+), 41 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6e179ca9d6904..f7b44e5e65641c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -48,6 +48,9 @@ C++ Specific Potentially Breaking Changes
 - Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
   This error can be disabled via `-Wno-strict-primary-template-shadow` for 
compatibility with previous versions of clang.
 
+- Clang now emits errors for coroutine `await_suspend` functions whose return 
type is not
+  one of `void`, `bool`, or `std::coroutine_handle`.
+
 ABI Changes in This Version
 ---
 - Fixed Microsoft name mangling of implicitly defined variables used for thread
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fc727cef9cd835..796b3d9d5e1190 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11707,7 +11707,7 @@ def err_coroutine_promise_new_requires_nothrow : Error<
 def note_coroutine_promise_call_implicitly_required : Note<
   "call to %0 implicitly required by coroutine function here">;
 def err_await_suspend_invalid_return_type : Error<
-  "return type of 'await_suspend' is required to be 'void' or 'bool' (have %0)"
+  "return type of 'await_suspend' is required to be 'void', 'bool', or 
'std::coroutine_handle' (have %0)"
 >;
 def note_await_ready_no_bool_conversion : Note<
   "return type of 'await_ready' is required to be contextually convertible to 
'bool'"
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 736632857efc36..2e81a83b62df51 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -137,12 +137,8 @@ static QualType lookupPromiseType(Sema &S, const 
FunctionDecl *FD,
   return PromiseType;
 }
 
-/// Look up the std::coroutine_handle.
-static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType,
-  SourceLocation Loc) {
-  if (PromiseType.isNull())
-return QualType();
-
+static ClassTemplateDecl *lookupCoroutineHandleTemplate(Sema &S,
+SourceLocation Loc) {
   NamespaceDecl *CoroNamespace = S.getStdNamespace();
   assert(CoroNamespace && "Should already be diagnosed");
 
@@ -151,18 +147,32 @@ static QualType lookupCoroutineHandleType(Sema &S, 
QualType PromiseType,
   if (!S.LookupQualifiedName(Result, CoroNamespace)) {
 S.Diag(Loc, diag::err_implied_coroutine_type_not_found)
 << "std::coroutine_handle";
-return QualType();
+return nullptr;
   }
 
-  ClassTemplateDecl *CoroHandle = Result.getAsSingle();
+  auto *CoroHandle = Result.getAsSingle();
+
   if (!CoroHandle) {
 Result.suppressDiagnostics();
 // We found something weird. Complain about the first thing we found.
 NamedDecl *Found = *Result.begin();
 S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle);
-return QualType();
+return nullptr;
   }
 
+  return CoroHandle;
+}
+
+/// Look up the std::coroutine_handle.
+static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType,
+  SourceLocation Loc) {
+  if (PromiseType.isNull())
+return QualType();
+
+  ClassTemplateDecl *CoroHandle = lookupCoroutineHandleTemplate(S, Loc);
+  if (!CoroHandle)
+return QualType();
+
   // Form template argument list for coroutine_handle.
   TemplateArgumentListInfo Args(Loc, Loc);
   Args.addArgument(TemplateArgumentLoc(
@@ -331,16 +341,12 @@ static ExprResult buildMemberCall(Sema &S, Expr *Base, 
SourceLocation Loc,
 // coroutine.
 static Expr *maybeTailCall(Sema &S, QualType RetType, Expr *E,
SourceLocation Loc) {
-  if (RetType->isReferenceType())
-return nullptr;
+  assert(!RetType->isReferenceType() &&
+ "Should have diagnosed reference types.");
   Type const *T = RetType.getTypePtr();
   if (!T->isClassType() && !T->isStructureType())
 return nullptr;
 
-  // FIXME: Add convertability check to coroutine_handle<>. Possibly via
-  // EvaluateBinaryTypeTrait(BTT_IsConvertible, ...) which is at the moment
-  // a private function in SemaExprCXX.cpp
-
   ExprResult AddressExpr = b

[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -1270,77 +1270,21 @@ exit:
 ; MODULE: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; MODULE: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; MODULE: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; MODULE: attributes #[[ATTR4]] = { "kernel" }
-; MODULE: attributes #[[ATTR5]] = { nosync memory(none) }
+; MODULE: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }
+; MODULE: attributes #[[ATTR5]] = { "kernel" }
+; MODULE: attributes #[[ATTR6]] = { nosync memory(none) }
 ;.
 ; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CGSCC: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; CGSCC: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; CGSCC: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; CGSCC: attributes #[[ATTR4]] = { "kernel" }
-; CGSCC: attributes #[[ATTR5]] = { nosync memory(none) }
+; CGSCC: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }

shiltian wrote:

Yes, as the comment pointed out. Only OpenMP target regions are marked as 
`kernel`. Nothing else.

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


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits

@@ -324,14 +326,15 @@ MaybeAlign getAlign(const Function &F, unsigned Index) {
   F.getAttributes().getAttributes(Index).getStackAlignment())
 return StackAlign;
 
-  // If that is missing, check the legacy nvvm metadata
-  std::vector Vs;
-  bool retval = findAllNVVMAnnotation(&F, "align", Vs);
-  if (!retval)
-return std::nullopt;
-  for (unsigned V : Vs)
-if ((V >> 16) == Index)
-  return Align(V & 0x);
+  // check the legacy nvvm metadata only for the return value since llvm does
+  // not support stackalign attribute for this.
+  if (Index == 0) {
+std::vector Vs;
+if (findAllNVVMAnnotation(&F, "align", Vs))

AlexMaclean wrote:

Yea, I agree the NVVM annotation APIs could be cleaned up significantly, 
hopefully this work will remove the need for them altogether though.

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


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -1270,77 +1270,21 @@ exit:
 ; MODULE: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; MODULE: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; MODULE: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; MODULE: attributes #[[ATTR4]] = { "kernel" }
-; MODULE: attributes #[[ATTR5]] = { nosync memory(none) }
+; MODULE: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }
+; MODULE: attributes #[[ATTR5]] = { "kernel" }
+; MODULE: attributes #[[ATTR6]] = { nosync memory(none) }
 ;.
 ; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CGSCC: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; CGSCC: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; CGSCC: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; CGSCC: attributes #[[ATTR4]] = { "kernel" }
-; CGSCC: attributes #[[ATTR5]] = { nosync memory(none) }
+; CGSCC: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }

shiltian wrote:

Theoretically yes, but I don't see how that works in the current compilation 
pipeline. However, both CUDA and OpenMP kernels could reside in the same LLVM 
module at link time.

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


[clang] [ubsan] Don't merge non-trap handlers if -ubsan-unique-traps or not optimized (PR #119302)

2024-12-10 Thread Thurston Dang via cfe-commits
https://github.com/thurstond closed 
https://github.com/llvm/llvm-project/pull/119302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [XRay][RISCV] RISCV support for XRay (PR #117368)

2024-12-10 Thread Craig Topper via cfe-commits
https://github.com/topperc approved this pull request.

LGTM

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


[clang] UncountedLocalVarsChecker and UncheckedLocalVarsChecker should recognize signletons. (PR #119339)

2024-12-10 Thread Rashmi Mudduluru via cfe-commits
https://github.com/t-rasmud approved this pull request.


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


[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qiongsi Wu (qiongsiwu)


Changes

A few recent changes are causing build breaks when `-DLLVM_ENABLE_MODULES=ON` 
(such as 834dfd23155351c9885eddf7b9664f7697326946 and 
7dfdca1961aadc75ca397818bfb9bd32f1879248). 

This PR makes the required updates so that clang/llvm builds when 
`-DLLVM_ENABLE_MODULES=ON`. 

---
Full diff: https://github.com/llvm/llvm-project/pull/119473.diff


9 Files Affected:

- (modified) clang/include/clang/Support/Compiler.h (-2) 
- (modified) clang/include/module.modulemap (+4-1) 
- (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h (+1) 
- (modified) llvm/include/llvm/IR/NVVMIntrinsicFlags.h (+2) 
- (modified) llvm/include/llvm/Support/Memory.h (+1) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+1) 
- (modified) llvm/include/module.modulemap (+1) 
- (modified) llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt (+1) 
- (modified) llvm/unittests/tools/llvm-profgen/CMakeLists.txt (+1) 


``diff
diff --git a/clang/include/clang/Support/Compiler.h 
b/clang/include/clang/Support/Compiler.h
index 13582b899dc2a6..0cba1ad7331682 100644
--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -14,8 +14,6 @@
 #ifndef CLANG_SUPPORT_COMPILER_H
 #define CLANG_SUPPORT_COMPILER_H
 
-#include "llvm/Support/Compiler.h"
-
 /// CLANG_ABI is the main export/visibility macro to mark something as
 /// explicitly exported when clang is built as a shared library with everything
 /// else that is unannotated having hidden visibility.
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index b399f0beee59a1..e9218c715147b0 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -115,7 +115,7 @@ module Clang_Diagnostics {
   module Driver { header "clang/Driver/DriverDiagnostic.h" export * }
   module Frontend { header "clang/Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "clang/Lex/LexDiagnostic.h" export * }
-  module Parse { header "clang/Parse/ParseDiagnostic.h" export * }
+  module Parse { header "clang/Basic/DiagnosticParse.h" export * }
   module Serialization { header 
"clang/Serialization/SerializationDiagnostic.h" export * }
   module Refactoring { header 
"clang/Tooling/Refactoring/RefactoringDiagnostic.h" export * }
 }
@@ -186,6 +186,9 @@ module Clang_StaticAnalyzer_Frontend {
 module Clang_Testing {
   requires cplusplus
   umbrella "clang/Testing"
+
+  textual header "clang/Testing/TestLanguage.def"
+
   module * { export * }
 }
 
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h 
b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 3c936b93865045..bd25f6c30ebf1f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 #define LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Error.h"
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h 
b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
index 43dde42bbbd620..dfb6e857b3a6ad 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_IR_NVVMINTRINSICFLAGS_H
 #define LLVM_IR_NVVMINTRINSICFLAGS_H
 
+#include 
+
 namespace llvm {
 namespace nvvm {
 
diff --git a/llvm/include/llvm/Support/Memory.h 
b/llvm/include/llvm/Support/Memory.h
index c02a3cc14dc7de..a587f2a8542b2e 100644
--- a/llvm/include/llvm/Support/Memory.h
+++ b/llvm/include/llvm/Support/Memory.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Support/DataTypes.h"
 #include 
+#include 
 
 namespace llvm {
 
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 1311329821828f..11836e87d1b208 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Bitset.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/llvm/include/module.modulemap b/llvm/include/module.modulemap
index b00da6d7cd28c7..ac7bd257cbb422 100644
--- a/llvm/include/module.modulemap
+++ b/llvm/include/module.modulemap
@@ -346,6 +346,7 @@ extern module LLVM_Extern_Utils_DataTypes 
"module.extern.modulemap"
 // TargetParser module before building the TargetParser module itself.
 module TargetParserGen {
   module AArch64TargetParserDef {
+textual header "llvm/TargetParser/AArch64CPUFeatures.inc"
 header "llvm/TargetParser/AArch64TargetParser.h"
 extern module LLVM_Extern_TargetParser_Gen "module.extern.modulemap"
 export *
diff --git a/llvm/tools/llvm-jitli

[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-10 Thread Qiongsi Wu via cfe-commits
https://github.com/qiongsiwu converted_to_draft 
https://github.com/llvm/llvm-project/pull/119473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Qiongsi Wu (qiongsiwu)


Changes

A few recent changes are causing build breaks when `-DLLVM_ENABLE_MODULES=ON` 
(such as 834dfd23155351c9885eddf7b9664f7697326946 and 
7dfdca1961aadc75ca397818bfb9bd32f1879248). 

This PR makes the required updates so that clang/llvm builds when 
`-DLLVM_ENABLE_MODULES=ON`. 

---
Full diff: https://github.com/llvm/llvm-project/pull/119473.diff


9 Files Affected:

- (modified) clang/include/clang/Support/Compiler.h (-2) 
- (modified) clang/include/module.modulemap (+4-1) 
- (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h (+1) 
- (modified) llvm/include/llvm/IR/NVVMIntrinsicFlags.h (+2) 
- (modified) llvm/include/llvm/Support/Memory.h (+1) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+1) 
- (modified) llvm/include/module.modulemap (+1) 
- (modified) llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt (+1) 
- (modified) llvm/unittests/tools/llvm-profgen/CMakeLists.txt (+1) 


``diff
diff --git a/clang/include/clang/Support/Compiler.h 
b/clang/include/clang/Support/Compiler.h
index 13582b899dc2a6..0cba1ad7331682 100644
--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -14,8 +14,6 @@
 #ifndef CLANG_SUPPORT_COMPILER_H
 #define CLANG_SUPPORT_COMPILER_H
 
-#include "llvm/Support/Compiler.h"
-
 /// CLANG_ABI is the main export/visibility macro to mark something as
 /// explicitly exported when clang is built as a shared library with everything
 /// else that is unannotated having hidden visibility.
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index b399f0beee59a1..e9218c715147b0 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -115,7 +115,7 @@ module Clang_Diagnostics {
   module Driver { header "clang/Driver/DriverDiagnostic.h" export * }
   module Frontend { header "clang/Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "clang/Lex/LexDiagnostic.h" export * }
-  module Parse { header "clang/Parse/ParseDiagnostic.h" export * }
+  module Parse { header "clang/Basic/DiagnosticParse.h" export * }
   module Serialization { header 
"clang/Serialization/SerializationDiagnostic.h" export * }
   module Refactoring { header 
"clang/Tooling/Refactoring/RefactoringDiagnostic.h" export * }
 }
@@ -186,6 +186,9 @@ module Clang_StaticAnalyzer_Frontend {
 module Clang_Testing {
   requires cplusplus
   umbrella "clang/Testing"
+
+  textual header "clang/Testing/TestLanguage.def"
+
   module * { export * }
 }
 
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h 
b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 3c936b93865045..bd25f6c30ebf1f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 #define LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Error.h"
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h 
b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
index 43dde42bbbd620..dfb6e857b3a6ad 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_IR_NVVMINTRINSICFLAGS_H
 #define LLVM_IR_NVVMINTRINSICFLAGS_H
 
+#include 
+
 namespace llvm {
 namespace nvvm {
 
diff --git a/llvm/include/llvm/Support/Memory.h 
b/llvm/include/llvm/Support/Memory.h
index c02a3cc14dc7de..a587f2a8542b2e 100644
--- a/llvm/include/llvm/Support/Memory.h
+++ b/llvm/include/llvm/Support/Memory.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Support/DataTypes.h"
 #include 
+#include 
 
 namespace llvm {
 
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 1311329821828f..11836e87d1b208 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Bitset.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/llvm/include/module.modulemap b/llvm/include/module.modulemap
index b00da6d7cd28c7..ac7bd257cbb422 100644
--- a/llvm/include/module.modulemap
+++ b/llvm/include/module.modulemap
@@ -346,6 +346,7 @@ extern module LLVM_Extern_Utils_DataTypes 
"module.extern.modulemap"
 // TargetParser module before building the TargetParser module itself.
 module TargetParserGen {
   module AArch64TargetParserDef {
+textual header "llvm/TargetParser/AArch64CPUFeatures.inc"
 header "llvm/TargetParser/AArch64TargetParser.h"
 extern module LLVM_Extern_TargetParser_Gen "module.extern.modulemap"
 export *
diff --git a/llvm/tools/llv

[clang-tools-extra] [clang-tidy]detecting conversion directly by `make_unique` and `make_shared` in bugprone-optional-value-conversion (PR #119371)

2024-12-10 Thread Congcong Cai via cfe-commits
HerrCai0907 wrote:

> Can the logic for implementing this also be used to address 
> https://github.com/llvm/llvm-project/issues/86447#issuecomment-2016943524?

I think this kind model of stl can be reused in other check. but i have no idea 
to make it more generic.

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


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits

@@ -5022,6 +5022,69 @@ bool llvm::UpgradeDebugInfo(Module &M) {
   return Modified;
 }
 
+bool static upgradeSingleNVVMAnnotation(GlobalValue *GV, StringRef K,
+const Metadata *V) {
+  if (K == "kernel") {
+assert(mdconst::extract(V)->getZExtValue() == 1);
+cast(GV)->addFnAttr("nvvm.kernel");
+return true;
+  }
+  if (K == "align") {
+const uint64_t AlignBits = 
mdconst::extract(V)->getZExtValue();
+const unsigned Idx = (AlignBits >> 16);
+const Align StackAlign = Align(AlignBits & 0x);

AlexMaclean wrote:

Fixed

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


[clang] [llvm] [AArch64] Implement intrinsics for FP8 FCVT/FCVTN/BFCVT (PR #118025)

2024-12-10 Thread via cfe-commits
https://github.com/SpencerAbson updated 
https://github.com/llvm/llvm-project/pull/118025

>From 65b749f27ddf7d7987423effe8c7b15b702c59f4 Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Sun, 24 Nov 2024 18:38:36 +
Subject: [PATCH 1/2] [AArch64] Implement intrinsics for FP8 FCVT/FCVTN/BFCVT

---
 clang/include/clang/Basic/arm_sve.td  |  6 ++
 .../fp8-intrinsics/acle_sme2_fp8_cvt.c| 64 +++
 .../acle_sme2_fp8_cvt.c   | 12 +++-
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 17 +
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  8 +--
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 15 -
 .../AArch64/sme2-fp8-intrinsics-cvt.ll| 52 +++
 7 files changed, 166 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 7b8ecf29a9de6e..30dc5c55d411ab 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2436,6 +2436,12 @@ let SVETargetGuard = InvalidMode, SMETargetGuard = 
"sme2,fp8" in {
   // Convert from FP8 to deinterleaved half-precision/BFloat16 multi-vector
   def SVF1CVTL_X2 : Inst<"svcvtl1_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl1_x2",  [IsStreaming, SetsFPMR], []>;
   def SVF2CVTL_X2 : Inst<"svcvtl2_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl2_x2",  [IsStreaming, SetsFPMR], []>;
+
+  // Convert from single/half/bfloat multivector to FP8
+  def SVFCVT_X2 : Inst<"svcvt_mf8[_{d}_x2]_fpm", "~2>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt_x2", [IsStreaming, SetsFPMR], []>;
+  def SVFCVT_X4 : Inst<"svcvt_mf8[_{d}_x4]_fpm", "~4>", "f",  MergeNone, 
"aarch64_sve_fp8_cvt_x4", [IsOverloadNone, IsStreaming, SetsFPMR], []>;
+  // interleaved
+  def SVFCVTN_X4 : Inst<"svcvtn_mf8[_{d}_x4]_fpm", "~4>", "f", MergeNone, 
"aarch64_sve_fp8_cvtn_x4", [IsOverloadNone, IsStreaming, SetsFPMR], []>;
 }
 
 let SVETargetGuard = "sve2p1", SMETargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
index 13609f034da336..ae2e780f84cfe3 100644
--- a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
@@ -16,6 +16,70 @@
 #define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
 #endif
 
+// CHECK-LABEL: @test_cvt_f16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvt.x2.nxv8f16( [[ZN_COERCE0:%.*]], 
 [[ZN_COERCE1:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z15test_cvt_f16_x213svfloat16x2_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvt.x2.nxv8f16( [[ZN_COERCE0:%.*]], 
 [[ZN_COERCE1:%.*]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svmfloat8_t test_cvt_f16_x2(svfloat16x2_t zn, fpm_t fpmr)  __arm_streaming {
+  return SVE_ACLE_FUNC(svcvt_mf8,_f16_x2,_fpm)(zn, fpmr);
+}
+
+// CHECK-LABEL: @test_cvt_f32_x4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvt.x4( [[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  [[ZN_COERCE2:%.*]],  [[ZN_COERCE3:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z15test_cvt_f32_x413svfloat32x4_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvt.x4( [[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  [[ZN_COERCE2:%.*]],  [[ZN_COERCE3:%.*]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svmfloat8_t test_cvt_f32_x4(svfloat32x4_t zn, fpm_t fpmr)  __arm_streaming {
+  return SVE_ACLE_FUNC(svcvt_mf8,_f32_x4,_fpm)(zn, fpmr);
+}
+
+// CHECK-LABEL: @test_cvtn_f32_x4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvtn.x4( [[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  [[ZN_COERCE2:%.*]], 
 [[ZN_COERCE3:%.*]])
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z16test_cvtn_f32_x413svfloat32x4_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fp8.cvtn.x4( [[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  [[ZN_COERCE2:%.*]], 
 [[ZN_COERCE3:%.*]])
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svmfloat8_t test_cvtn_f32_x4(svfloat32x4_t zn, fpm_t fpmr)  __arm_streaming {
+  return SVE_ACLE_FUNC(svcvtn_mf8,_f32_x4,_fpm)(zn, fpmr);
+}
+
+// CHECK-LABEL: @test_cvt_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64

[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-10 Thread Michael Spencer via cfe-commits

@@ -14,8 +14,6 @@
 #ifndef CLANG_SUPPORT_COMPILER_H
 #define CLANG_SUPPORT_COMPILER_H
 
-#include "llvm/Support/Compiler.h"

Bigcheese wrote:

The include of this file needs to move to Attr.h, module imports can't be in a 
namespace, so putting the include in Attrs.inc is wrong.

You should also add a new top level module for the Support directory.

`module Clang_Support { requires cplusplus umbrella "clang/Support" module * { 
export * } }`

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


[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2024-12-10 Thread Tom Honermann via cfe-commits
https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/105738

>From d5c7035fd0c007e9833150a3d1b0a86d8744aa5d Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Thu, 22 Aug 2024 09:44:56 -0700
Subject: [PATCH 1/2] [Clang] Match MSVC handling of duplicate header search
 paths in Microsoft compatibility modes.

Clang has historically matched GCC's behavior for header search path order
and pruning of duplicate paths. That traditional behavior is to order user
search paths before system search paths, to ignore user search paths that
duplicate a (later) system search path, and to ignore search paths that
duplicate an earlier search path of the same user/system kind. This differs
from MSVC and can result in inconsistent header file resolution for `#include`
directives.

MSVC orders header search paths as follows:
1) Paths specified by the `/I` and `/external:I` options are processed in
   the order that they appear. Paths specified by `/I` that duplicate a path
   specified by `/external:I` are ignored regardless of the order of the
   options. Paths specified by `/I` that duplicate a path from a prior `/I`
   option are ignored. Paths specified by `/external:I` that duplicate a
   path from a later `/external:I` option are ignored.
2) Paths specified by `/external:env` are processed in the order that they
   appear. Paths that duplicate a path from a `/I` or `/external:I` option
   are ignored regardless of the order of the options. Paths that duplicate a
   path from a prior `/external:env` option or an earlier path from the same
   `/external:env` option are ignored.
3) Paths specified by the `INCLUDE` environment variable are processed in
   the order they appear. Paths that duplicate a path from a `/I`,
   `/external:I`, or `/external:env` option are ignored. Paths that
   duplicate an earlier path in the `INCLUDE` environment variable are
   ignored.
4) Paths specified by the `EXTERNAL_INCLUDE` environment variable are
   processed in the order they appear. Paths that duplicate a path from a
   `/I`, `/external:I`, or `/external:env` option are ignored. Paths that
   duplicate a path from the `INCLUDE` environment variable are ignored.
   Paths that duplicate an earlier path in the `EXTERNAL_INCLUDE
   environment variable are ignored.

Prior to this change, Clang handled the `/external:I` and `/external:env`
options and the paths present in the `INCLUDE` and `EXTERNAL_INCLUDE`
environment variables as though they were specified with the `-isystem` option.
The GCC behavior described above then lead to a command line such as
`/external:I dir1 /Idir2` having a header search order of `dir2` followed by
`dir1`; contrary to MSVC behavior.

This change adds support for the MSVC external path concept for both the `clang`
and `clang-cl` drivers with the following option syntax. These options match the
MSVC behavior described above for both drivers.
 clangclang-cl
  ---
 -iexternal  /external:I 
 -iexternal-env= /external:env:
Paths specified by these options are still treated as system paths. That is,
whether warnings are issued in header files found via these paths remains
subject to use of the `-Wsystem-headers` and `-Wno-system-headers` options.
In the future, it would make sense to add a separate option that matches the
MSVC `/external:Wn` option to control such warnings.

The MSVC behavior described above implies that (system) paths present in the
`INCLUDE` and `EXTERNAL_INCLUDE` environment variables do not suppress matching
user paths specified via `/I`. This contrasts with GCC's behavior of suppressing
user paths that match a system path regardless of how each is specified. Since
the `clang-cl` driver maps paths from the `INCLUDE` and `EXTERNAL_INCLUDE`
environment variable to `-internal-isystem`, matching MSVC behavior requires
suppressing that aspect of the GCC behavior. With this change, system paths
will no longer suppress user paths when the `-fms-compatibility` option is
explicitly or implicitly enabled. This will affect header search path ordering
for options like `-isystem` when duplicate user paths are present. Should
motivation arise for preserving such suppression of user paths when compiling
with `-fms-compatibility` enabled, it would make sense to introduce a new
option for the `clang-cl` driver to map paths in these environment variabless
to that would match MSVC behavior without impacting other system path options.
---
 clang/docs/ReleaseNotes.rst   |  38 ++
 clang/include/clang/Driver/Options.td |  17 +-
 clang/include/clang/Driver/ToolChain.h|  11 +-
 clang/include/clang/Lex/HeaderSearchOptions.h |  10 +
 clang/lib/Driver/Driver.cpp   |   4 +-
 clang/lib/Driver/ToolChain.cpp|  45 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  15 +-
 clang/lib/Driver/ToolChai

[clang] Fix a cmake error when using the Xcode generator. (PR #119403)

2024-12-10 Thread Paul Bowen-Huggett via cfe-commits
https://github.com/paulhuggett edited 
https://github.com/llvm/llvm-project/pull/119403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2024-12-10 Thread via cfe-commits
https://github.com/cor3ntin approved this pull request.

LGTM

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


[clang] [llvm] [AArch64] Add Neon FP8 conversion intrinsics (PR #119033)

2024-12-10 Thread Momchil Velikov via cfe-commits
https://github.com/momchil-velikov edited 
https://github.com/llvm/llvm-project/pull/119033
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add Neon FP8 conversion intrinsics (PR #119033)

2024-12-10 Thread Momchil Velikov via cfe-commits
https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/119033

>From a83b190b25f01843922530d9e409cfb9c0a86c18 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 6 Dec 2024 13:09:23 +
Subject: [PATCH 1/4] [AArch64] Refactor implementation of FP8 types (NFC)

* The FP8 scalar type (`__mfp8`) was described as a vector type
* The FP8 vector types were described/assumed to have
  integer element type (the element type ought to be `__mfp8`),
* Add support for `m` type specifier (denoting `__mfp8`)
  in `DecodeTypeFromStr` and create SVE builtin prototypes using
  the specifier, instead of `int8_t`.
---
 clang/include/clang/AST/Type.h|  5 +++
 .../clang/Basic/AArch64SVEACLETypes.def   | 24 +---
 clang/lib/AST/ASTContext.cpp  | 37 +++
 clang/lib/AST/ItaniumMangle.cpp   |  5 +++
 clang/lib/AST/Type.cpp|  4 +-
 clang/lib/CodeGen/CodeGenTypes.cpp| 13 +--
 clang/lib/CodeGen/Targets/AArch64.cpp |  7 +++-
 clang/utils/TableGen/SveEmitter.cpp   |  4 +-
 8 files changed, 76 insertions(+), 23 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 6fd6c73a516f08..626cfea56a47db 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2518,6 +2518,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isFloat32Type() const;
   bool isDoubleType() const;
   bool isBFloat16Type() const;
+  bool isMFloat8Type() const;
   bool isFloat128Type() const;
   bool isIbm128Type() const;
   bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
@@ -8532,6 +8533,10 @@ inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isMFloat8Type() const {
+  return isSpecificBuiltinType(BuiltinType::MFloat8);
+}
+
 inline bool Type::isFloat128Type() const {
   return isSpecificBuiltinType(BuiltinType::Float128);
 }
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 063cac1f4a58ee..6b704b386536c9 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -57,6 +57,11 @@
 //  - IsBF true for vector of brain float elements.
 
//===--===//
 
+#ifndef SVE_SCALAR_TYPE
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
+  SVE_TYPE(Name, Id, SingletonId)
+#endif
+
 #ifndef SVE_VECTOR_TYPE
 #define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
   SVE_TYPE(Name, Id, SingletonId)
@@ -72,6 +77,11 @@
   SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, true)
 #endif
 
+#ifndef SVE_VECTOR_TYPE_MFLOAT
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, false)
+#endif
+
 #ifndef SVE_VECTOR_TYPE_FLOAT
 #define SVE_VECTOR_TYPE_FLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
   SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, true, false)
@@ -125,8 +135,7 @@ SVE_VECTOR_TYPE_FLOAT("__SVFloat64_t", "__SVFloat64_t", 
SveFloat64, SveFloat64Ty
 
 SVE_VECTOR_TYPE_BFLOAT("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, 
SveBFloat16Ty, 8, 16, 1)
 
-// This is a 8 bits opaque type.
-SVE_VECTOR_TYPE_INT("__SVMfloat8_t", "__SVMfloat8_t",  SveMFloat8, 
SveMFloat8Ty, 16, 8, 1, false)
+SVE_VECTOR_TYPE_MFLOAT("__SVMfloat8_t", "__SVMfloat8_t",  SveMFloat8, 
SveMFloat8Ty, 16, 8, 1)
 
 //
 // x2
@@ -148,7 +157,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x2_t", 
"svfloat64x2_t", SveFloat64x2, Sv
 
 SVE_VECTOR_TYPE_BFLOAT("__clang_svbfloat16x2_t", "svbfloat16x2_t", 
SveBFloat16x2, SveBFloat16x2Ty, 8, 16, 2)
 
-SVE_VECTOR_TYPE_INT("__clang_svmfloat8x2_t", "svmfloat8x2_t", SveMFloat8x2, 
SveMFloat8x2Ty, 16, 8, 2, false)
+SVE_VECTOR_TYPE_MFLOAT("__clang_svmfloat8x2_t", "svmfloat8x2_t", SveMFloat8x2, 
SveMFloat8x2Ty, 16, 8, 2)
 
 //
 // x3
@@ -170,7 +179,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x3_t", 
"svfloat64x3_t", SveFloat64x3, Sv
 
 SVE_VECTOR_TYPE_BFLOAT("__clang_svbfloat16x3_t", "svbfloat16x3_t", 
SveBFloat16x3, SveBFloat16x3Ty, 8, 16, 3)
 
-SVE_VECTOR_TYPE_INT("__clang_svmfloat8x3_t", "svmfloat8x3_t", SveMFloat8x3, 
SveMFloat8x3Ty, 16, 8, 3, false)
+SVE_VECTOR_TYPE_MFLOAT("__clang_svmfloat8x3_t", "svmfloat8x3_t", SveMFloat8x3, 
SveMFloat8x3Ty, 16, 8, 3)
 
 //
 // x4
@@ -192,7 +201,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x4_t", 
"svfloat64x4_t", SveFloat64x4, Sv
 
 SVE_VECTOR_TYPE_BFLOAT("__clang_svbfloat16x4_t", "svbfloat16x4_t", 
SveBFloat16x4, SveBFloat16x4Ty, 8, 16, 4)
 
-SVE_VECTOR_TYPE_INT("__clang_svmfloat8x4_t", "svmfloat8x4_t", SveMFloat8x4, 
SveMFloat8x4T

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: 天音あめ (amane-ame)


Changes

An empty expansion should be valid, like `echo 'A()' | clang-format 
--style='{Macros: [A(x)=x]}'`
See #119258.

---
Full diff: https://github.com/llvm/llvm-project/pull/119428.diff


1 Files Affected:

- (modified) clang/lib/Format/MacroExpander.cpp (+4) 


``diff
diff --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index fd2a16894d643d..ed9e51dfbfef1f 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID,
   if (Result.size() > 1) {
 ++Result[0]->MacroCtx->StartOfExpansion;
 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion;
+  } else {
+// If the macro expansion is empty, mark the start and end
+Result[0]->MacroCtx->StartOfExpansion = 1;
+Result[0]->MacroCtx->EndOfExpansion = 1;
   }
   return Result;
 }

``




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


[clang] 1a5e18a - [HLSL] Do not print details in IR for target extension types (#115971)

2024-12-10 Thread via cfe-commits
Author: Joshua Batista
Date: 2024-12-10T10:07:30-08:00
New Revision: 1a5e18a492481ff48ca764c8f7d08d231d922382

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

LOG: [HLSL] Do not print details in IR for target extension types (#115971)

This PR changes how target extension types are printed when they are
emitted as IR.
This prevents repetitive phrases like "struct = type {...}" from being
repeated over and over in the outputted IR.
Additionally, it should allow opt to not crash when parsing the DXIL
output.

Fixes [#114131](https://github.com/llvm/llvm-project/issues/114131)

Added: 


Modified: 
clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl
clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl

clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
clang/test/CodeGenHLSL/resource-bindings.hlsl
llvm/lib/IR/AsmWriter.cpp
llvm/unittests/IR/TypesTest.cpp

Removed: 




diff  --git 
a/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl
index 1e8aae588fc33d..85face8eaeb6c8 100644
--- a/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl
@@ -18,7 +18,8 @@ struct MyStruct {
 // DXIL: %"class.hlsl::AppendStructuredBuffer.9" = type { 
target("dx.RawBuffer", <3 x i32>, 1, 0)
 // DXIL: %"class.hlsl::AppendStructuredBuffer.10" = type { 
target("dx.RawBuffer", <2 x half>, 1, 0)
 // DXIL: %"class.hlsl::AppendStructuredBuffer.11" = type { 
target("dx.RawBuffer", <3 x float>, 1, 0)
-// DXIL: %"class.hlsl::AppendStructuredBuffer.12" = type { 
target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x 
i8] }, 1, 0)
+// DXIL: %"class.hlsl::AppendStructuredBuffer.12" = type { 
target("dx.RawBuffer", %struct.MyStruct, 1, 0)
+// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }
 
 AppendStructuredBuffer BufI16;
 AppendStructuredBuffer BufU16;

diff  --git 
a/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl
index f8574c6460d4e1..5ed9e9ad8160ff 100644
--- a/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl
@@ -18,7 +18,8 @@ struct MyStruct {
 // DXIL: %"class.hlsl::ConsumeStructuredBuffer.9" = type { 
target("dx.RawBuffer", <3 x i32>, 1, 0)
 // DXIL: %"class.hlsl::ConsumeStructuredBuffer.10" = type { 
target("dx.RawBuffer", <2 x half>, 1, 0)
 // DXIL: %"class.hlsl::ConsumeStructuredBuffer.11" = type { 
target("dx.RawBuffer", <3 x float>, 1, 0)
-// DXIL: %"class.hlsl::ConsumeStructuredBuffer.12" = type { 
target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x 
i8] }, 1, 0)
+// DXIL: %"class.hlsl::ConsumeStructuredBuffer.12" = type { 
target("dx.RawBuffer", %struct.MyStruct, 1, 0)
+// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }
 
 ConsumeStructuredBuffer BufI16;
 ConsumeStructuredBuffer BufU16;

diff  --git 
a/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
 
b/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
index 7057988de24b34..68d626de689f2e 100644
--- 
a/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
+++ 
b/clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
@@ -18,7 +18,7 @@ struct MyStruct {
 // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.9" = type { 
target("dx.RawBuffer", <3 x i32>, 1, 1) }
 // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.10" = type { 
target("dx.RawBuffer", <2 x half>, 1, 1) }
 // DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.11" = type { 
target("dx.RawBuffer", <3 x float>, 1, 1) }
-// DXIL: %"class.hlsl::RasterizerOrderedStructuredBuffer.12" = type { 
target("dx.RawBuffer", %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x 
i8] }, 1, 1) }
+// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }
 
 RasterizerOrderedStructuredBuffer BufI16;
 RasterizerOrderedStructuredBuffer BufU16;

diff  --git a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl 
b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
index 7de62a363eedb5..fda034ce7f2034 100644
--- a/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
@@ -3,7 +3,8 @@
 using handle_float_t = __hlsl_resource_t [[hlsl::resource_class(UAV)]] 
[[hlsl::contained_type(float)]];

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-10 Thread via cfe-commits
https://github.com/amane-ame created 
https://github.com/llvm/llvm-project/pull/119428

An empty expansion should be valid, like `echo 'A()' | clang-format 
--style='{Macros: [A(x)=x]}'`
See #119258.

From 3a4c1a924faef3a7a09126694fcb943bd7083451 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Wed, 11 Dec 2024 02:13:43 +0800
Subject: [PATCH] Fix crashes when the macro expansion is empty

---
 clang/lib/Format/MacroExpander.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index fd2a16894d643d..ed9e51dfbfef1f 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID,
   if (Result.size() > 1) {
 ++Result[0]->MacroCtx->StartOfExpansion;
 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion;
+  } else {
+// If the macro expansion is empty, mark the start and end
+Result[0]->MacroCtx->StartOfExpansion = 1;
+Result[0]->MacroCtx->EndOfExpansion = 1;
   }
   return Result;
 }

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


[clang] [llvm] [AArch64] Add Neon FP8 conversion intrinsics (PR #119033)

2024-12-10 Thread Momchil Velikov via cfe-commits
momchil-velikov wrote:

- added the tests
- fixed calls to the wrong LLVM intrinsic

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


[clang] [llvm] [AArch64] Implement FP8 SVE Intrinsics for narrowing conversions (PR #118124)

2024-12-10 Thread Momchil Velikov via cfe-commits
https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/118124

>From 6f268d4a80a8994855c99679ce1c66c11be8e357 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 25 Nov 2024 09:47:41 +
Subject: [PATCH] [AArch64] Implement FP8 SVE Intrinsics for narrowing
 conversions

* Half-precision and BFloat16 convert, narrow, and interleave to 8-bit 
floating-point.

  // Variant is also available for: _bf16_x2
  svmfloat8_t svcvtn_mf8[_f16_x2]_fpm(svfloat16x2_t zn, fpm_t fpm);

* Single-precision convert, narrow, and interleave to 8-bit floating-point (top 
and bottom).

  svmfloat8_t svcvtnt_mf8[_f32_x2]_fpm(svmfloat8_t zd, svfloat32x2_t zn, fpm_t 
fpm);
  svmfloat8_t svcvtnb_mf8[_f32_x2]_fpm(svfloat32x2_t zn, fpm_t fpm);
---
 clang/include/clang/Basic/arm_sve.td  |   7 ++
 .../fp8-intrinsics/acle_sve2_fp8_cvtn.c   | 101 ++
 .../aarch64-sve2-intrinsics/acle_sve2_fp8.c   |  11 +-
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  14 +++
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td |   9 +-
 llvm/lib/Target/AArch64/SVEInstrFormats.td|  37 ++-
 llvm/test/CodeGen/AArch64/fp8-sve-cvtn.ll |  49 +
 7 files changed, 222 insertions(+), 6 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
 create mode 100644 llvm/test/CodeGen/AArch64/fp8-sve-cvtn.ll

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 7b8ecf29a9de6e..d467720fc5c61f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2462,4 +2462,11 @@ let SVETargetGuard = "sve2,fp8", SMETargetGuard = 
"sme2,fp8" in {
   // 8-bit floating-point convert to BFloat16/Float16 (top)
   def SVF1CVTLT : SInst<"svcvtlt1_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt1", [VerifyRuntimeMode, SetsFPMR]>;
   def SVF2CVTLT : SInst<"svcvtlt2_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt2", [VerifyRuntimeMode, SetsFPMR]>;
+
+  // BFloat16/Float16 convert, narrow and interleave to 8-bit floating-point
+  def SVFCVTN : SInst<"svcvtn_mf8[_{d}_x2]_fpm", "~2>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtn", [VerifyRuntimeMode, SetsFPMR]>;
+
+  // Single-precision convert, narrow and interleave to 8-bit floating-point 
(top and bottom)
+  def SVFCVTNB : SInst<"svcvtnb_mf8[_f32_x2]_fpm", "~2>",  "f", MergeNone, 
"aarch64_sve_fp8_cvtnb", [VerifyRuntimeMode, SetsFPMR]>;
+  def SVFCVTNT : SInst<"svcvtnt_mf8[_f32_x2]_fpm", "~~2>", "f", MergeNone, 
"aarch64_sve_fp8_cvtnt", [VerifyRuntimeMode, SetsFPMR]>;
 }
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
new file mode 100644
index 00..ed5b0ce02af4bd
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
@@ -0,0 +1,101 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1-triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sve2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CHECK-CXX
+
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-triple 
aarch64-none-linux-gnu -target-feature +sme -target-feature +sme2 
-target-feature +fp8 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt 
-S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -triple 
aarch64-none-linux-gnu -target-feature +sve -target-feature +sve2 
-target-feature +fp8 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt 
-S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CHECK-CXX
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sve2 -target-feature +fp8 -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +fp8 -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#ifdef __ARM_FEATURE_SME
+#include 
+#else
+#include 
+#endif
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+#ifdef __ARM_FEATURE_SME
+#define STREAMING __arm_streaming
+#else
+#define STREAMING
+#endif
+
+// CHECK-LABEL: define dso_local  @test_svcvtn_f8_bf16(
+// CHECK-SAME:  [[ZN_ZM_COERCE0:%.*]],  [[ZN_ZM_COERCE1:%.*]], i64 noundef [[FPM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i6

[clang] [llvm] Support for dispatch construct (Sema & Codegen) support. (PR #117904)

2024-12-10 Thread via cfe-commits
https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/117904

>From 1703aa62cfe35538aedbacb28e907535e838248c Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Fri, 20 Sep 2024 01:41:29 -0500
Subject: [PATCH 1/3] Support for dispatch construct (Sema & Codegen) support.
 Support for clauses depend, novariants & nocontext.

---
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/OpenMPKinds.h   |   6 +
 clang/include/clang/Sema/SemaOpenMP.h |   7 +
 clang/lib/Basic/OpenMPKinds.cpp   |   5 +
 clang/lib/CodeGen/CGStmt.cpp  |   2 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   4 +
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Sema/SemaOpenMP.cpp | 301 ++-
 clang/test/OpenMP/dispatch_codegen.cpp| 359 ++
 clang/test/OpenMP/dispatch_unsupported.c  |   7 -
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   6 +
 11 files changed, 687 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/OpenMP/dispatch_codegen.cpp
 delete mode 100644 clang/test/OpenMP/dispatch_unsupported.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8495884dcd058f..81b876f9fd85c5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11774,6 +11774,9 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def warn_omp_dispatch_clause_novariants_nocontext : Warning<
+  "only 'novariants' clause is supported when 'novariants' & 'nocontext' 
clauses occur on the same dispatch construct">,
+  InGroup;
 def err_openmp_vla_in_task_untied : Error<
   "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
 def warn_omp_unterminated_declare_target : Warning<
diff --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index 900ad6ca6d66f6..7579fab43dbb19 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -269,6 +269,12 @@ bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind);
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
+/// Checks if the specified directive is a dispatch-kind directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a dispatch-like directive like 'omp
+/// dispatch', otherwise - false.
+bool isOpenMPDispatchDirective(OpenMPDirectiveKind DKind);
+
 /// Checks if the specified directive is a target code offload directive.
 /// \param DKind Specified directive.
 /// \return true - the directive is a target code offload directive like
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..80cee9e7583051 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1462,6 +1462,13 @@ class SemaOpenMP : public SemaBase {
: OMPDeclareVariantScopes.back().TI;
   }
 
+  StmtResult transformDispatchDirective(OpenMPDirectiveKind Kind,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion,
+ArrayRef Clauses,
+Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc);
+
   /// The current `omp begin/end declare variant` scopes.
   SmallVector OMPDeclareVariantScopes;
 
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..44ee63df46adb5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -621,6 +621,11 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind 
DKind) {
  llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
 }
 
+bool clang::isOpenMPDispatchDirective(OpenMPDirectiveKind DKind) {
+  return DKind == OMPD_dispatch ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
+}
+
 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
   return DKind == OMPD_target ||
  llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 698baf853507f4..f3eedb79844378 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -417,7 +417,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 EmitOMPInteropDirective(cast(*S));
 break;
   case Stmt::OMPDispatchDirectiveClass:
-CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
+   

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-10 Thread via cfe-commits
github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr 
*,
+  SemaOpenMP *, bool);
+
+/// cloneAssociatedStmt() function is for cloning the Associated Statement
+/// present with a Directive and then modifying it. By this we avoid modifying
+/// the original Associated Statement.
+static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
+  SemaOpenMP *SemaPtr, bool NoContext) {
+  if (auto *AssocStmt = dyn_cast(StmtP)) {
+CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
+auto *AssocExpr = dyn_cast(AssocExprStmt);
+Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
+Context, AssocExpr, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(NewCallOrPseudoObjOrBinExpr));
+for (unsigned I : llvm::seq(CDecl->getNumParams())) {
+  if (I != CDecl->getContextParamPosition())
+NewDecl->setParam(I, CDecl->getParam(I));
+  else
+NewDecl->setContextParam(I, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
+  Captures.push_back(Capture);
+for (Expr *CaptureInit : AssocStmt->capture_inits())
+  CaptureInits.push_back(CaptureInit);
+auto *NewStmt = CapturedStmt::Create(
+Context, AssocStmt->getCapturedStmt(),
+AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
+const_cast(AssocStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(nullptr);
+}
+
+/// replaceWithNewTraitsOrDirectCall() is for transforming the call traits.
+/// Call traits associated with a function call are removed and replaced with
+/// a direct call. For clause "nocontext" only, the direct call is then
+/// modified to have call traits for a non-dispatch variant.
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
+  Expr *AssocExpr,
+  SemaOpenMP *SemaPtr,
+  bool NoContext) {
+  BinaryOperator *BinaryCopyOpr = nullptr;
+  bool IsBinaryOp = false;
+  Expr *PseudoObjExprOrCall = AssocExpr;
+  if (auto *BinOprExpr = dyn_cast(AssocExpr)) {
+IsBinaryOp = true;
+BinaryCopyOpr = BinaryOperator::Create(
+Context, BinOprExpr->getLHS(), BinOprExpr->getRHS(),
+BinOprExpr->getOpcode(), BinOprExpr->getType(),
+BinOprExpr->getValueKind(), BinOprExpr->getObjectKind(),
+BinOprExpr->getOperatorLoc(), FPOptionsOverride());
+PseudoObjExprOrCall = BinaryCopyOpr->getRHS();
+  }
+
+  Expr *CallWithoutInvariants = PseudoObjExprOrCall;
+  // Change PseudoObjectExpr to a direct call
+  if (auto *PseudoObjExpr = dyn_cast(PseudoObjExprOrCall))
+CallWithoutInvariants = *((PseudoObjExpr->semantics_begin()) - 1);
+
+  Expr *FinalCall = CallWithoutInvariants; // For noinvariants clause
+  if (NoContext) {
+// example to explain the changes done for "nocontext" clause:
+//
+// #pragma omp declare variant(foo_variant_dispatch)
+//  match(construct = {dispatch})
+// #pragma omp declare variant(foo_variant_allCond)
+// match(user = {condition(1)})
+// ...
+// #pragma omp dispatch nocontext(cond_true)
+// foo(i, j); // with traits: CodeGen call to
+// foo_variant_dispatch(i,j)
+// dispatch construct is changed to:
+// if (cond_true) {
+//foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
+// } else {
+//   #pragma omp dispatch
+//   foo(i,j)  // with traits: CodeGen call to foo_variant_dispatch(i,j)
+// }
+
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+auto *CallExprWithinStmt = cast(CallWithoutInvariants);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = Cal

[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -10520,11 +10794,22 @@ StmtResult 
SemaOpenMP::ActOnOpenMPSectionDirective(Stmt *AStmt,
  DSAStack->isCancelRegion());
 }
 
+/// PseudoObjectExpr is a Trait for dispatch containing the
+/// function and its variant. Returning only the function.
+static Expr *RemovePseudoObjectExpr(Expr *PseudoObjExprOrDirectCall) {

shiltian wrote:

```suggestion
static Expr *removePseudoObjectExpr(Expr *PseudoObjExprOrDirectCall) {
```

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr 
*,
+  SemaOpenMP *, bool);
+
+/// cloneAssociatedStmt() function is for cloning the Associated Statement
+/// present with a Directive and then modifying it. By this we avoid modifying
+/// the original Associated Statement.
+static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
+  SemaOpenMP *SemaPtr, bool NoContext) {
+  if (auto *AssocStmt = dyn_cast(StmtP)) {
+CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
+auto *AssocExpr = dyn_cast(AssocExprStmt);
+Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
+Context, AssocExpr, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(NewCallOrPseudoObjOrBinExpr));
+for (unsigned I : llvm::seq(CDecl->getNumParams())) {
+  if (I != CDecl->getContextParamPosition())
+NewDecl->setParam(I, CDecl->getParam(I));
+  else
+NewDecl->setContextParam(I, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
+  Captures.push_back(Capture);
+for (Expr *CaptureInit : AssocStmt->capture_inits())
+  CaptureInits.push_back(CaptureInit);
+auto *NewStmt = CapturedStmt::Create(
+Context, AssocStmt->getCapturedStmt(),
+AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
+const_cast(AssocStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(nullptr);
+}
+
+/// replaceWithNewTraitsOrDirectCall() is for transforming the call traits.
+/// Call traits associated with a function call are removed and replaced with
+/// a direct call. For clause "nocontext" only, the direct call is then
+/// modified to have call traits for a non-dispatch variant.
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
+  Expr *AssocExpr,
+  SemaOpenMP *SemaPtr,
+  bool NoContext) {
+  BinaryOperator *BinaryCopyOpr = nullptr;
+  bool IsBinaryOp = false;
+  Expr *PseudoObjExprOrCall = AssocExpr;
+  if (auto *BinOprExpr = dyn_cast(AssocExpr)) {
+IsBinaryOp = true;
+BinaryCopyOpr = BinaryOperator::Create(
+Context, BinOprExpr->getLHS(), BinOprExpr->getRHS(),
+BinOprExpr->getOpcode(), BinOprExpr->getType(),
+BinOprExpr->getValueKind(), BinOprExpr->getObjectKind(),
+BinOprExpr->getOperatorLoc(), FPOptionsOverride());
+PseudoObjExprOrCall = BinaryCopyOpr->getRHS();
+  }
+
+  Expr *CallWithoutInvariants = PseudoObjExprOrCall;
+  // Change PseudoObjectExpr to a direct call
+  if (auto *PseudoObjExpr = dyn_cast(PseudoObjExprOrCall))
+CallWithoutInvariants = *((PseudoObjExpr->semantics_begin()) - 1);
+
+  Expr *FinalCall = CallWithoutInvariants; // For noinvariants clause
+  if (NoContext) {
+// example to explain the changes done for "nocontext" clause:
+//
+// #pragma omp declare variant(foo_variant_dispatch)
+//  match(construct = {dispatch})
+// #pragma omp declare variant(foo_variant_allCond)
+// match(user = {condition(1)})
+// ...
+// #pragma omp dispatch nocontext(cond_true)
+// foo(i, j); // with traits: CodeGen call to
+// foo_variant_dispatch(i,j)
+// dispatch construct is changed to:
+// if (cond_true) {
+//foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
+// } else {
+//   #pragma omp dispatch
+//   foo(i,j)  // with traits: CodeGen call to foo_variant_dispatch(i,j)
+// }
+
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+auto *CallExprWithinStmt = cast(CallWithoutInvariants);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = Cal

[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr 
*,
+  SemaOpenMP *, bool);
+
+/// cloneAssociatedStmt() function is for cloning the Associated Statement
+/// present with a Directive and then modifying it. By this we avoid modifying
+/// the original Associated Statement.
+static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
+  SemaOpenMP *SemaPtr, bool NoContext) {
+  if (auto *AssocStmt = dyn_cast(StmtP)) {
+CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
+auto *AssocExpr = dyn_cast(AssocExprStmt);
+Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
+Context, AssocExpr, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(NewCallOrPseudoObjOrBinExpr));
+for (unsigned I : llvm::seq(CDecl->getNumParams())) {
+  if (I != CDecl->getContextParamPosition())
+NewDecl->setParam(I, CDecl->getParam(I));
+  else
+NewDecl->setContextParam(I, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
+  Captures.push_back(Capture);
+for (Expr *CaptureInit : AssocStmt->capture_inits())
+  CaptureInits.push_back(CaptureInit);
+auto *NewStmt = CapturedStmt::Create(
+Context, AssocStmt->getCapturedStmt(),
+AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
+const_cast(AssocStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(nullptr);
+}
+
+/// replaceWithNewTraitsOrDirectCall() is for transforming the call traits.
+/// Call traits associated with a function call are removed and replaced with
+/// a direct call. For clause "nocontext" only, the direct call is then
+/// modified to have call traits for a non-dispatch variant.
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
+  Expr *AssocExpr,
+  SemaOpenMP *SemaPtr,
+  bool NoContext) {
+  BinaryOperator *BinaryCopyOpr = nullptr;
+  bool IsBinaryOp = false;
+  Expr *PseudoObjExprOrCall = AssocExpr;
+  if (auto *BinOprExpr = dyn_cast(AssocExpr)) {
+IsBinaryOp = true;
+BinaryCopyOpr = BinaryOperator::Create(
+Context, BinOprExpr->getLHS(), BinOprExpr->getRHS(),
+BinOprExpr->getOpcode(), BinOprExpr->getType(),
+BinOprExpr->getValueKind(), BinOprExpr->getObjectKind(),
+BinOprExpr->getOperatorLoc(), FPOptionsOverride());
+PseudoObjExprOrCall = BinaryCopyOpr->getRHS();
+  }
+
+  Expr *CallWithoutInvariants = PseudoObjExprOrCall;
+  // Change PseudoObjectExpr to a direct call
+  if (auto *PseudoObjExpr = dyn_cast(PseudoObjExprOrCall))
+CallWithoutInvariants = *((PseudoObjExpr->semantics_begin()) - 1);
+
+  Expr *FinalCall = CallWithoutInvariants; // For noinvariants clause
+  if (NoContext) {
+// example to explain the changes done for "nocontext" clause:
+//
+// #pragma omp declare variant(foo_variant_dispatch)
+//  match(construct = {dispatch})
+// #pragma omp declare variant(foo_variant_allCond)
+// match(user = {condition(1)})
+// ...
+// #pragma omp dispatch nocontext(cond_true)
+// foo(i, j); // with traits: CodeGen call to
+// foo_variant_dispatch(i,j)
+// dispatch construct is changed to:
+// if (cond_true) {
+//foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
+// } else {
+//   #pragma omp dispatch
+//   foo(i,j)  // with traits: CodeGen call to foo_variant_dispatch(i,j)
+// }
+
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+auto *CallExprWithinStmt = cast(CallWithoutInvariants);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = Cal

[clang] [HLSL] Move `_init_resource_bindings` to entry point functions (PR #119311)

2024-12-10 Thread Chris B via cfe-commits
llvm-beanz wrote:

Is this the right solution, or should we be doing something to force the 
constructor function to be generated. I'm a little worried that we have one 
path for initializing some types of globals and a different approach for other 
globals.

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits
https://github.com/shiltian edited 
https://github.com/llvm/llvm-project/pull/117904
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Artem Belevich via cfe-commits

@@ -302,6 +299,19 @@ void NVPTXTargetCodeGenInfo::addNVVMMetadata(
   llvm::ConstantAsMetadata::get(GV), llvm::MDString::get(Ctx, Name),
   llvm::ConstantAsMetadata::get(
   llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), Operand))};
+  // Append metadata to nvvm.annotations
+  MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
+}
+
+void NVPTXTargetCodeGenInfo::addNVVMGridConstantMetadata(
+llvm::GlobalValue *GV, const SmallVectorImpl &GridConstantArgs) {
+  llvm::Module *M = GV->getParent();
+  llvm::LLVMContext &Ctx = M->getContext();
+
+  // Get "nvvm.annotations" metadata node
+  llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata("nvvm.annotations");

Artem-B wrote:

> For this MR I want to lay down the framework

SGTM. We don't have to it all at once.

> Specifically for grid_constant can we just upgrade to the existing readonly 
> parameter attribute?

That would be even better. No custom attributes *and* we can take advantage of 
local copy avoidance without explicit user annotations. Sounds like a win-win 
to me. I can't think of a reason not to do that.

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -7209,8 +7482,9 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, 
Scope *Scope,
 Exprs.erase(Exprs.begin() + BestIdx);
   } while (!VMIs.empty());
 
-  if (!NewCall.isUsable())
+  if (!NewCall.isUsable()) {
 return Call;
+  }

shiltian wrote:

unrelated

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -10556,15 +10841,18 @@ 
SemaOpenMP::ActOnOpenMPDispatchDirective(ArrayRef Clauses,
 E = E->IgnoreParenCasts()->IgnoreImplicit();
 
 if (auto *BO = dyn_cast(E)) {
-  if (BO->getOpcode() == BO_Assign)
+  if (BO->getOpcode() == BO_Assign) {
 TargetCall = getDirectCallExpr(BO->getRHS());
+  }
 } else {
   if (auto *COCE = dyn_cast(E))
 if (COCE->getOperator() == OO_Equal)
   TargetCall = getDirectCallExpr(COCE->getArg(1));
-  if (!TargetCall)
+  if (!TargetCall) {
 TargetCall = getDirectCallExpr(E);
+  }
 }
+

shiltian wrote:

unrelated changes

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5979,6 +6241,17 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
   OMPExecutableDirective::getSingleClause(Clauses))
 BindKind = BC->getBindKind();
 
+  if ((Kind == OMPD_dispatch) && (Clauses.size() > 0)) {

shiltian wrote:

```suggestion
  if ((Kind == OMPD_dispatch) && (!Clauses.empty())) {
```

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr 
*,
+  SemaOpenMP *, bool);
+
+/// cloneAssociatedStmt() function is for cloning the Associated Statement
+/// present with a Directive and then modifying it. By this we avoid modifying
+/// the original Associated Statement.
+static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
+  SemaOpenMP *SemaPtr, bool NoContext) {
+  if (auto *AssocStmt = dyn_cast(StmtP)) {
+CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
+auto *AssocExpr = dyn_cast(AssocExprStmt);
+Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
+Context, AssocExpr, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(NewCallOrPseudoObjOrBinExpr));
+for (unsigned I : llvm::seq(CDecl->getNumParams())) {
+  if (I != CDecl->getContextParamPosition())
+NewDecl->setParam(I, CDecl->getParam(I));
+  else
+NewDecl->setContextParam(I, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
+  Captures.push_back(Capture);
+for (Expr *CaptureInit : AssocStmt->capture_inits())
+  CaptureInits.push_back(CaptureInit);
+auto *NewStmt = CapturedStmt::Create(
+Context, AssocStmt->getCapturedStmt(),
+AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
+const_cast(AssocStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(nullptr);
+}
+
+/// replaceWithNewTraitsOrDirectCall() is for transforming the call traits.
+/// Call traits associated with a function call are removed and replaced with
+/// a direct call. For clause "nocontext" only, the direct call is then
+/// modified to have call traits for a non-dispatch variant.
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context,
+  Expr *AssocExpr,
+  SemaOpenMP *SemaPtr,
+  bool NoContext) {
+  BinaryOperator *BinaryCopyOpr = nullptr;
+  bool IsBinaryOp = false;
+  Expr *PseudoObjExprOrCall = AssocExpr;
+  if (auto *BinOprExpr = dyn_cast(AssocExpr)) {
+IsBinaryOp = true;
+BinaryCopyOpr = BinaryOperator::Create(
+Context, BinOprExpr->getLHS(), BinOprExpr->getRHS(),
+BinOprExpr->getOpcode(), BinOprExpr->getType(),
+BinOprExpr->getValueKind(), BinOprExpr->getObjectKind(),
+BinOprExpr->getOperatorLoc(), FPOptionsOverride());
+PseudoObjExprOrCall = BinaryCopyOpr->getRHS();
+  }
+
+  Expr *CallWithoutInvariants = PseudoObjExprOrCall;
+  // Change PseudoObjectExpr to a direct call
+  if (auto *PseudoObjExpr = dyn_cast(PseudoObjExprOrCall))
+CallWithoutInvariants = *((PseudoObjExpr->semantics_begin()) - 1);
+
+  Expr *FinalCall = CallWithoutInvariants; // For noinvariants clause
+  if (NoContext) {
+// example to explain the changes done for "nocontext" clause:
+//
+// #pragma omp declare variant(foo_variant_dispatch)
+//  match(construct = {dispatch})
+// #pragma omp declare variant(foo_variant_allCond)
+// match(user = {condition(1)})
+// ...
+// #pragma omp dispatch nocontext(cond_true)
+// foo(i, j); // with traits: CodeGen call to
+// foo_variant_dispatch(i,j)
+// dispatch construct is changed to:
+// if (cond_true) {
+//foo(i,j) // with traits: CodeGen call to foo_variant_allCond(i,j)
+// } else {
+//   #pragma omp dispatch
+//   foo(i,j)  // with traits: CodeGen call to foo_variant_dispatch(i,j)
+// }
+
+// Convert StmtResult to a CallExpr before calling ActOnOpenMPCall()
+auto *CallExprWithinStmt = cast(CallWithoutInvariants);
+int NumArgs = CallExprWithinStmt->getNumArgs();
+clang::Expr **Args = Cal

[clang] dc04d41 - SystemZ: Add support for __builtin_setjmp and __builtin_longjmp. (#119257)

2024-12-10 Thread via cfe-commits
Author: anoopkg6
Date: 2024-12-10T19:50:51+01:00
New Revision: dc04d414df9c243bb90d7cfc683a632a2c032c62

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

LOG: SystemZ: Add support for __builtin_setjmp and __builtin_longjmp. (#119257)

This pr includes fixes for original pr##116642.
Implementation for __builtin_setjmp and __builtin_longjmp for SystemZ..

Added: 
clang/test/CodeGen/SystemZ/builtin-setjmp-logjmp.c
llvm/test/CodeGen/SystemZ/builtin-longjmp.ll
llvm/test/CodeGen/SystemZ/builtin-setjmp-alloca.ll
llvm/test/CodeGen/SystemZ/builtin-setjmp-spills.ll
llvm/test/CodeGen/SystemZ/builtin-setjmp.ll

Modified: 
clang/lib/Basic/Targets/SystemZ.h
clang/lib/CodeGen/CGBuiltin.cpp
llvm/docs/ExceptionHandling.rst
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/lib/Target/SystemZ/SystemZISelLowering.h
llvm/lib/Target/SystemZ/SystemZInstrInfo.td
llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
llvm/lib/Target/SystemZ/SystemZOperators.td
llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp
llvm/lib/Target/SystemZ/SystemZRegisterInfo.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 98637f230b69cc..04e00bac644765 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -248,6 +248,8 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
 return RegNo < 4 ? 6 + RegNo : -1;
   }
 
+  bool hasSjLjLowering() const override { return true; }
+
   std::pair hardwareInterferenceSizes() const override {
 return std::make_pair(256, 256);
   }

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c2e983eebebc10..49a4c1ecc825e7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4860,6 +4860,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 // Buffer is a void**.
 Address Buf = EmitPointerWithAlignment(E->getArg(0));
 
+if (getTarget().getTriple().getArch() == llvm::Triple::systemz) {
+  // On this target, the back end fills in the context buffer completely.
+  // It doesn't really matter if the frontend stores to the buffer before
+  // calling setjmp, the back-end is going to overwrite them anyway.
+  Function *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp);
+  return RValue::get(Builder.CreateCall(F, Buf.emitRawPointer(*this)));
+}
+
 // Store the frame pointer to the setjmp buffer.
 Value *FrameAddr = Builder.CreateCall(
 CGM.getIntrinsic(Intrinsic::frameaddress, AllocaInt8PtrTy),

diff  --git a/clang/test/CodeGen/SystemZ/builtin-setjmp-logjmp.c 
b/clang/test/CodeGen/SystemZ/builtin-setjmp-logjmp.c
new file mode 100644
index 00..898891fa182ea4
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/builtin-setjmp-logjmp.c
@@ -0,0 +1,26 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple s390x-linux -emit-llvm -o - %s | FileCheck %s
+
+void *buf[20];
+
+// CHECK-LABEL: define dso_local void @foo(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.eh.sjlj.setjmp(ptr @buf)
+// CHECK-NEXT:ret void
+//
+void foo()
+{
+  __builtin_setjmp (buf);
+}
+
+// CHECK-LABEL: define dso_local void @foo1(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:call void @llvm.eh.sjlj.longjmp(ptr @buf)
+// CHECK-NEXT:unreachable
+//
+void foo1()
+{
+  __builtin_longjmp (buf, 1);
+}

diff  --git a/llvm/docs/ExceptionHandling.rst b/llvm/docs/ExceptionHandling.rst
index c2afb25c6ccd47..bb72e5a71a77bf 100644
--- a/llvm/docs/ExceptionHandling.rst
+++ b/llvm/docs/ExceptionHandling.rst
@@ -374,10 +374,12 @@ overall functioning of this intrinsic is compatible with 
the GCC
 to interoperate.
 
 The single parameter is a pointer to a five word buffer in which the calling
-context is saved. The front end places the frame pointer in the first word, and
-the target implementation of this intrinsic should place the destination 
address
-for a `llvm.eh.sjlj.longjmp`_ in the second word. The following three words are
-available for use in a target-specific manner.
+context is saved. The format and contents of the buffer are target-specific.
+On certain targets (ARM, PowerPC, VE, X86), the front end places the 
+frame pointer in the first word and the stack pointer in the third word, 
+while the target implementation of this intrinsic fills in the remaining 
+words.  On other targets (SystemZ), saving the calling context to the buffer 
+is left completely to the target implementat

[clang] [llvm] SystemZ: Add support for __builtin_setjmp and __builtin_longjmp. (PR #119257)

2024-12-10 Thread Ulrich Weigand via cfe-commits
https://github.com/uweigand closed 
https://github.com/llvm/llvm-project/pull/119257
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread via cfe-commits
https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/117904

>From 1703aa62cfe35538aedbacb28e907535e838248c Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Fri, 20 Sep 2024 01:41:29 -0500
Subject: [PATCH 1/4] Support for dispatch construct (Sema & Codegen) support.
 Support for clauses depend, novariants & nocontext.

---
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/OpenMPKinds.h   |   6 +
 clang/include/clang/Sema/SemaOpenMP.h |   7 +
 clang/lib/Basic/OpenMPKinds.cpp   |   5 +
 clang/lib/CodeGen/CGStmt.cpp  |   2 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp|   4 +
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Sema/SemaOpenMP.cpp | 301 ++-
 clang/test/OpenMP/dispatch_codegen.cpp| 359 ++
 clang/test/OpenMP/dispatch_unsupported.c  |   7 -
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   6 +
 11 files changed, 687 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/OpenMP/dispatch_codegen.cpp
 delete mode 100644 clang/test/OpenMP/dispatch_unsupported.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8495884dcd058f..81b876f9fd85c5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11774,6 +11774,9 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def warn_omp_dispatch_clause_novariants_nocontext : Warning<
+  "only 'novariants' clause is supported when 'novariants' & 'nocontext' 
clauses occur on the same dispatch construct">,
+  InGroup;
 def err_openmp_vla_in_task_untied : Error<
   "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
 def warn_omp_unterminated_declare_target : Warning<
diff --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index 900ad6ca6d66f6..7579fab43dbb19 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -269,6 +269,12 @@ bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind);
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
+/// Checks if the specified directive is a dispatch-kind directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a dispatch-like directive like 'omp
+/// dispatch', otherwise - false.
+bool isOpenMPDispatchDirective(OpenMPDirectiveKind DKind);
+
 /// Checks if the specified directive is a target code offload directive.
 /// \param DKind Specified directive.
 /// \return true - the directive is a target code offload directive like
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..80cee9e7583051 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1462,6 +1462,13 @@ class SemaOpenMP : public SemaBase {
: OMPDeclareVariantScopes.back().TI;
   }
 
+  StmtResult transformDispatchDirective(OpenMPDirectiveKind Kind,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion,
+ArrayRef Clauses,
+Stmt *AStmt, SourceLocation StartLoc,
+SourceLocation EndLoc);
+
   /// The current `omp begin/end declare variant` scopes.
   SmallVector OMPDeclareVariantScopes;
 
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..44ee63df46adb5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -621,6 +621,11 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind 
DKind) {
  llvm::is_contained(getLeafConstructs(DKind), OMPD_parallel);
 }
 
+bool clang::isOpenMPDispatchDirective(OpenMPDirectiveKind DKind) {
+  return DKind == OMPD_dispatch ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
+}
+
 bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
   return DKind == OMPD_target ||
  llvm::is_contained(getLeafConstructs(DKind), OMPD_target);
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 698baf853507f4..f3eedb79844378 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -417,7 +417,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S, 
ArrayRef Attrs) {
 EmitOMPInteropDirective(cast(*S));
 break;
   case Stmt::OMPDispatchDirectiveClass:
-CGM.ErrorUnsupported(S, "OpenMP dispatch directive");
+   

[clang] [HLSL] Move `_init_resource_bindings` to entry point functions (PR #119311)

2024-12-10 Thread Helena Kotas via cfe-commits
https://github.com/hekota converted_to_draft 
https://github.com/llvm/llvm-project/pull/119311
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #118580)

2024-12-10 Thread Chris B via cfe-commits

@@ -9272,6 +9272,8 @@ def err_typecheck_expect_scalar_or_vector : Error<
   "a vector of such type is required">;
 def err_typecheck_expect_any_scalar_or_vector : Error<
   "invalid operand of type %0 where a scalar or vector is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<

llvm-beanz wrote:

Do we need a new unique diagnostic for this or should we be using 
`err_typecheck_expect_any_scalar_or_vector` or 
`err_typecheck_expect_scalar_or_vector`?

In general we should try not to add unique diagnostics unless there really 
isn't an existing one that works.

In looking at this more closely I'm not sure we should have added 
`err_typecheck_expect_any_scalar_or_vector`, as we've basically added two 
_extremely similar_ diagnostics that probably should be combined.

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


[clang] [HLSL] Move `_init_resource_bindings` to entry point functions (PR #119311)

2024-12-10 Thread Helena Kotas via cfe-commits
hekota wrote:

> Is this the right solution, or should we be doing something to force the 
> constructor function to be generated? I'm a little worried that we have one 
> path for initializing some types of globals and a different approach for 
> other globals.

I'll see if I can move creation of the `cbuffer` global variable right after it 
is declared and that should get captured by the module init. We might still 
need to generate the body of the resource init function later in codegen.

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMLAL/FMLALL (Indexed) (PR #118549)

2024-12-10 Thread via cfe-commits
CarolineConcatto wrote:

I will wait you merge the previous patch to have a look on this one again later!

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


[clang] [llvm] [Clang][OpenMP] Support for dispatch construct (Sema & Codegen) support (PR #117904)

2024-12-10 Thread Shilei Tian via cfe-commits

@@ -5965,6 +5967,266 @@ static bool teamsLoopCanBeParallelFor(Stmt *AStmt, Sema 
&SemaRef) {
   return Checker.teamsLoopCanBeParallelFor();
 }
 
+static Expr *getInitialExprFromCapturedExpr(Expr *Cond) {
+
+  Expr *SubExpr = Cond->IgnoreParenImpCasts();
+
+  if (auto *DeclRef = dyn_cast(SubExpr)) {
+if (auto *CapturedExprDecl =
+dyn_cast(DeclRef->getDecl())) {
+
+  // Retrieve the initial expression from the captured expression
+  return CapturedExprDecl->getInit();
+}
+  }
+  return nullptr;
+}
+
+static Expr *replaceWithNewTraitsOrDirectCall(const ASTContext &Context, Expr 
*,
+  SemaOpenMP *, bool);
+
+/// cloneAssociatedStmt() function is for cloning the Associated Statement
+/// present with a Directive and then modifying it. By this we avoid modifying
+/// the original Associated Statement.
+static StmtResult cloneAssociatedStmt(const ASTContext &Context, Stmt *StmtP,
+  SemaOpenMP *SemaPtr, bool NoContext) {
+  if (auto *AssocStmt = dyn_cast(StmtP)) {
+CapturedDecl *CDecl = AssocStmt->getCapturedDecl();
+Stmt *AssocExprStmt = AssocStmt->getCapturedStmt();
+auto *AssocExpr = dyn_cast(AssocExprStmt);
+Expr *NewCallOrPseudoObjOrBinExpr = replaceWithNewTraitsOrDirectCall(
+Context, AssocExpr, SemaPtr, NoContext);
+
+// Copy Current Captured Decl to a New Captured Decl for noting the
+// Annotation
+CapturedDecl *NewDecl =
+CapturedDecl::Create(const_cast(Context),
+ CDecl->getDeclContext(), CDecl->getNumParams());
+NewDecl->setBody(static_cast(NewCallOrPseudoObjOrBinExpr));
+for (unsigned I : llvm::seq(CDecl->getNumParams())) {
+  if (I != CDecl->getContextParamPosition())
+NewDecl->setParam(I, CDecl->getParam(I));
+  else
+NewDecl->setContextParam(I, CDecl->getContextParam());
+}
+
+// Create a New Captured Stmt containing the New Captured Decl
+SmallVector Captures;
+SmallVector CaptureInits;
+for (const CapturedStmt::Capture &Capture : AssocStmt->captures())
+  Captures.push_back(Capture);
+for (Expr *CaptureInit : AssocStmt->capture_inits())
+  CaptureInits.push_back(CaptureInit);
+auto *NewStmt = CapturedStmt::Create(
+Context, AssocStmt->getCapturedStmt(),
+AssocStmt->getCapturedRegionKind(), Captures, CaptureInits, NewDecl,
+const_cast(AssocStmt->getCapturedRecordDecl()));
+
+return NewStmt;
+  }
+  return static_cast(nullptr);

shiltian wrote:

I'm confused by this return. Why do you want to cast a `nullptr` to a `Stmt *`, 
and then implicit cast it to `StmtResult`?

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


[clang] [llvm] [DebugInfo] Place local ODR-uniqued types in decl DISubprograms (PR #119001)

2024-12-10 Thread David Blaikie via cfe-commits
dwblaikie wrote:

> > Maybe it's too big/complex a problem to try to think about, and incremental 
> > development should overrule here - but may be worth thinking about?
> 
> Urgh. I'll admit that I hadn't thought that far ahead, I just wanted to get 
> the patch-series going again now that the root problem is identified.
> 
> The DWARF in the existing patch series [0] seems to take a similar direction 
> to this patch, of putting information into declarations where possible. Have 
> a look at the check-lines for 
> llvm/test/DebugInfo/Generic/lexical-block-static-var.ll: 

> the static-local variables are defined and given a location inside 
> DW_TAG_lexical_blocks within the abstract definitions of functions, 

Ah, fair enough, because the subprogram will contian a list of these local 
types, then the local type's scope will be a (potentially series of) lexical 
scope - so the lexical scopes are preserved? That's OK-ish, at least not as 
problematic as I was imagining. (rest of the discussion below here is just 
discussion - this point ^ is enough to satisfy my concerns for this patch 
direction, at least)

> and then there are some other DW_TAG_lexical_blocks inside the inlined 
> instances. It's not clear to me how the inlined-lexical-blocks refer back to 
> the abstract ones.

Yeah, that's probably missing - the ideal would be the inlined/concrete 
non-inlined instance's lexical blocks should have abstract_origins that refer 
to the abstract lexical blocks.

> Given that the ODR-uniquing issue was only found experimentally in-the-field, 
> I think we have to accept the incremental approach and discover problems by 
> experience.

Not sure I follow this.

> Stepping back slightly: I think the ODR-uniquing of these types is directly 
> opposed to scope-precision: reducing the number of type definitions down to 
> one _necessarily_ means discarding the extra locality information about where 
> it's scoped in different function instances.

Not sure I follow this either - I think that if each concrete lexical scope 
references the abstract ones, we could emit correct abstract origins to get the 
local static variables and types to be scoped appropriately in the resulting 
DWARF/for the consumer.

GCC does this: https://godbolt.org/z/Khrzdq1Wx

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


[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-12-10 Thread LLVM Continuous Integration via cfe-commits
llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-expensive-checks-debian` running on `gribozavr4` while 
building `clang,llvm` at step 6 "test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/16/builds/10433


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM :: 
CodeGen/RISCV/stack-clash-prologue-nounwind.ll' FAILED 
Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc 
-mtriple=riscv64 -mattr=+m -O2 < 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll
| /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll
 -check-prefix=RV64I
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=riscv64 
-mattr=+m -O2
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck 
/b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll
 -check-prefix=RV64I

# After Prologue/Epilogue Insertion & Frame Finalization
# Machine code for function f2: NoPHIs, TracksLiveness, NoVRegs, 
TiedOpsRewritten, TracksDebugUserValues
Frame Objects:
  fi#0: size=65536, align=1, at location [SP-65536]
  fi#1: size=8, align=8, at location [SP-65552]

bb.0.entry:
  successors: %bb.1(0x8000); %bb.1(100.00%)

  $x10 = frame-setup LUI 16
  $x6 = frame-setup SUB $x2, killed $x10
  frame-setup CFI_INSTRUCTION def_cfa $x6, 65536
  $x7 = frame-setup LUI 1

bb.1.entry:
; predecessors: %bb.1, %bb.0
  successors: %bb.2(0x4000), %bb.1(0x4000); %bb.2(50.00%), %bb.1(50.00%)

  $x2 = frame-setup SUB $x2, $x7
  frame-setup SD $x0, $x2, 0
  frame-setup BNE $x2, $x6, %bb.1

bb.2.entry:
; predecessors: %bb.1

  frame-setup CFI_INSTRUCTION def_cfa_register $x2
  $x2 = frame-setup ADDI $x2, -16
  frame-setup CFI_INSTRUCTION def_cfa_offset 65552
  renamable $x10 = ADDI $x0, 3
  SB killed renamable $x10, $x2, 16 :: (volatile store (s8) into %ir.a)
  renamable $x10 = LBU $x2, 16 :: (volatile load (s8) from %ir.a)
  $x11 = frame-destroy LUI 16
  $x11 = frame-destroy ADDIW killed $x11, 16
  $x2 = frame-destroy ADD $x2, killed $x11
  frame-destroy CFI_INSTRUCTION def_cfa_offset 0
  PseudoRET implicit $x10

# End machine code for function f2.

*** Bad machine code: Using an undefined physical register ***
- function:f2
...

```



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


[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)

2024-12-10 Thread Zhengxing li via cfe-commits
https://github.com/lizhengxing updated 
https://github.com/llvm/llvm-project/pull/117781

>From e66f451e1db4c321acbfac578fa57f286af2fe27 Mon Sep 17 00:00:00 2001
From: Zhengxing Li 
Date: Wed, 13 Nov 2024 10:54:16 -0800
Subject: [PATCH 1/4] [HLSL] Implement SV_GroupThreadId semantic

Support SV_GroupThreadId attribute.
Translate it into dx.thread.id.in.group in clang codeGen.

Fixes: #70122
---
 clang/include/clang/Basic/Attr.td |  7 
 clang/include/clang/Basic/AttrDocs.td | 11 +++
 clang/include/clang/Sema/SemaHLSL.h   |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  5 +++
 clang/lib/Parse/ParseHLSL.cpp |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++
 clang/lib/Sema/SemaHLSL.cpp   | 10 ++
 .../semantics/SV_GroupThreadID.hlsl   | 32 +++
 .../SemaHLSL/Semantics/entry_parameter.hlsl   | 13 +---
 .../Semantics/invalid_entry_parameter.hlsl| 22 +
 .../Semantics/valid_entry_parameter.hlsl  | 25 +++
 11 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupThreadID.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 17fc36fbe2ac8c..90d2a2056fe1ba 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4651,6 +4651,13 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
+def HLSLSV_GroupThreadID: HLSLAnnotationAttr {
+  let Spellings = [HLSLAnnotation<"SV_GroupThreadID">];
+  let Subjects = SubjectList<[ParmVar, Field]>;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLSV_GroupThreadIDDocs];
+}
+
 def HLSLSV_GroupID: HLSLAnnotationAttr {
   let Spellings = [HLSLAnnotation<"SV_GroupID">];
   let Subjects = SubjectList<[ParmVar, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 7a82b8fa320590..fdad4c9a3ea191 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7941,6 +7941,17 @@ randomized.
   }];
 }
 
+def HLSLSV_GroupThreadIDDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``SV_GroupThreadID`` semantic, when applied to an input parameter, 
specifies which
+individual thread within a thread group is executing in. This attribute is
+only supported in compute shaders.
+
+The full documentation is available here: 
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid
+  }];
+}
+
 def HLSLSV_GroupIDDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index ee685d95c96154..f4cd11f423a84a 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase {
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
+  void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL);
   void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
   void handleShaderAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 2c293523fca8ca..19db7faddaeac0 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
&B,
 CGM.getIntrinsic(getThreadIdIntrinsic());
 return buildVectorInput(B, ThreadIDIntrinsic, Ty);
   }
+  if (D.hasAttr()) {
+llvm::Function *GroupThreadIDIntrinsic =
+CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group);
+return buildVectorInput(B, GroupThreadIDIntrinsic, Ty);
+  }
   if (D.hasAttr()) {
 llvm::Function *GroupIDIntrinsic = 
CGM.getIntrinsic(Intrinsic::dx_group_id);
 return buildVectorInput(B, GroupIDIntrinsic, Ty);
diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp
index 4de342b63ed802..443bf2b9ec626a 100644
--- a/clang/lib/Parse/ParseHLSL.cpp
+++ b/clang/lib/Parse/ParseHLSL.cpp
@@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,
   case ParsedAttr::UnknownAttribute:
 Diag(Loc, diag::err_unknown_hlsl_semantic) << II;
 return;
+  case ParsedAttr::AT_HLSLSV_GroupThreadID:
   case ParsedAttr::AT_HLSLSV_GroupID:
   case ParsedAttr::AT_HLSLSV_GroupIndex:
   case ParsedAttr::AT_HLSLSV_DispatchThreadID:
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 4fd8ef6dbebf84..5d7ee097383771 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7114,6 +7114,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const Parsed

[clang] ffb19f4 - [CIR] Infrastructure: class CIRGenBuilderTy; cache CIR types (#119037)

2024-12-10 Thread via cfe-commits
Author: David Olsen
Date: 2024-12-10T11:29:48-08:00
New Revision: ffb19f4018e38ba7ff034b78914d5a8d2890a603

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

LOG: [CIR] Infrastructure: class CIRGenBuilderTy; cache CIR types (#119037)

Small infrastructure and background changes to ClangIR.

Create class `CIRGenBuilderTy` and its base class `CIRBaseBuilderTy`.
These are mostly empty for now, except for what is inherited from
`mlir::OpBuilder`. But they will fill up quickly as more ClangIR code
gen is upstreamed. `CIRGenModule` and `CIRGenTypes` are changed to use
`CIRGenBuilderTy`.

Add cached types to struct `CIRGenTypeCache` for the integral types that
are currently supported. Initialize those cached types in the
`CIRGenModule` constructor. The first uses of those types (well, one of
them) is in `CIRGenTypes::convertType`.

Have `CIRGenTypes::convertType` cache its results in a map from
`clang::Type` to `mlir::Type`, saving it from having to convert the same
type again and again.

There are no new tests or changed tests in this commit. There are no
changes to behavior, just improvements to how the existing behavior is
implemented.

Added: 
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/lib/CIR/CodeGen/CIRGenBuilder.h

Modified: 
clang/lib/CIR/CodeGen/CIRGenModule.cpp
clang/lib/CIR/CodeGen/CIRGenModule.h
clang/lib/CIR/CodeGen/CIRGenTypeCache.h
clang/lib/CIR/CodeGen/CIRGenTypes.cpp
clang/lib/CIR/CodeGen/CIRGenTypes.h

Removed: 




diff  --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
new file mode 100644
index 00..75ae74e926fbc6
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -0,0 +1,25 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
+#define LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
+
+#include "mlir/IR/Builders.h"
+
+namespace cir {
+
+class CIRBaseBuilderTy : public mlir::OpBuilder {
+
+public:
+  CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
+  : mlir::OpBuilder(&mlirContext) {}
+};
+
+} // namespace cir
+
+#endif

diff  --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h 
b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
new file mode 100644
index 00..92115778518d4a
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -0,0 +1,28 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENBUILDER_H
+#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENBUILDER_H
+
+#include "CIRGenTypeCache.h"
+
+#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
+
+namespace clang::CIRGen {
+
+class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
+  const CIRGenTypeCache &typeCache;
+
+public:
+  CIRGenBuilderTy(mlir::MLIRContext &mlirContext, const CIRGenTypeCache &tc)
+  : CIRBaseBuilderTy(mlirContext), typeCache(tc) {}
+};
+
+} // namespace clang::CIRGen
+
+#endif

diff  --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index b44f66493254f2..e7c9512dcd3de8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -29,9 +29,22 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
clang::ASTContext &astctx,
const clang::CodeGenOptions &cgo,
DiagnosticsEngine &diags)
-: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
+: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
   theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
-  diags(diags), target(astCtx.getTargetInfo()), genTypes(*this) {}
+  diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
+
+  // Initialize cached types
+  SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
+  SInt16Ty = cir::IntType::get(&getMLIRContext(), 16, /*isSigned=*/true);
+  SInt32Ty = cir::IntType::get(&getMLIRContext(), 32, /*isSigned=*/true);
+  SInt64Ty = cir::IntType::get(&getM

[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits

@@ -1270,77 +1270,21 @@ exit:
 ; MODULE: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; MODULE: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; MODULE: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; MODULE: attributes #[[ATTR4]] = { "kernel" }
-; MODULE: attributes #[[ATTR5]] = { nosync memory(none) }
+; MODULE: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }
+; MODULE: attributes #[[ATTR5]] = { "kernel" }
+; MODULE: attributes #[[ATTR6]] = { nosync memory(none) }
 ;.
 ; CGSCC: attributes #[[ATTR0]] = { "llvm.assume"="ompx_aligned_barrier" }
 ; CGSCC: attributes #[[ATTR1:[0-9]+]] = { convergent nocallback nounwind }
 ; CGSCC: attributes #[[ATTR2:[0-9]+]] = { convergent nocallback nofree 
nounwind willreturn }
 ; CGSCC: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind 
willreturn memory(inaccessiblemem: write) }
-; CGSCC: attributes #[[ATTR4]] = { "kernel" }
-; CGSCC: attributes #[[ATTR5]] = { nosync memory(none) }
+; CGSCC: attributes #[[ATTR4]] = { "kernel" "nvvm.kernel" }

AlexMaclean wrote:

Unfortunately, I think we do. "kernel" is really more like "OpenMP kernel" and 
the semantics for this do not seem to be a perfect match for "nvvm.kernel". For 
example, `@multiple_blocks_functions_non_kernel_effects_2` in this test has 
"kernel" but is not an nvvm kernel. I'm vary unfamiliar with the OpenMP 
semantics so I thought keeping it separate would be the safest approach, it 
also may be clearest to have a common "nvvm.*" prefix for all attributes 
currently represented as nvvm.annotations. 

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


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Artem Belevich via cfe-commits

@@ -5022,6 +5022,69 @@ bool llvm::UpgradeDebugInfo(Module &M) {
   return Modified;
 }
 
+bool static upgradeSingleNVVMAnnotation(GlobalValue *GV, StringRef K,
+const Metadata *V) {
+  if (K == "kernel") {
+assert(mdconst::extract(V)->getZExtValue() == 1);

Artem-B wrote:

Assert should not be used here as it's not an LLVM error. It's an input error 
and should be diagnosed (or accepted/ignored). Considering that the value is a 
flag, and not very useful one at that (I don't think `kernel 0` is ever 
actually used, it would be OK to accept a non-zero value as "it's a kernel" and 
zero as "not a kernel".

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


[clang] [llvm] Revert "[PAC][ELF][AArch64] Support signed personality function pointer" (PR #119331)

2024-12-10 Thread LLVM Continuous Integration via cfe-commits
llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lld-x86_64-win` running on 
`as-worker-93` while building `clang,llvm` at step 7 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/146/builds/1803


Here is the relevant piece of the build log for the reference

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM-Unit :: Support/./SupportTests.exe/38/87' 
FAILED 
Script(shard):
--
GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-21236-38-87.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=38 
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe 
--gtest_filter=ProgramEnvTest.CreateProcessLongPath
--
C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): 
error: Expected equality of these values:
  0
  RC
Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): 
error: fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied



C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160
Expected equality of these values:
  0
  RC
Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163
fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied







```



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


[clang] Cache SanitizerArgs in Clang driver (NFC) (PR #119442)

2024-12-10 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created 
https://github.com/llvm/llvm-project/pull/119442

The name getSanitizerArgs seems to mislead callers that this is a cheap 
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.

>From fdcd8a22e13f0feb665b76a801dbdd31fe9354f5 Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Fri, 6 Dec 2024 23:13:17 +0100
Subject: [PATCH] Cache SanitizerArgs in Clang driver (NFC)

The name getSanitizerArgs seems to mislead callers that this is a cheap
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  9 +
 clang/lib/Driver/ToolChains/CommonArgs.h   |  2 ++
 clang/lib/Driver/ToolChains/FreeBSD.cpp|  6 --
 clang/lib/Driver/ToolChains/Fuchsia.cpp| 10 +-
 clang/lib/Driver/ToolChains/Gnu.cpp|  7 +--
 clang/lib/Driver/ToolChains/Hexagon.cpp|  9 ++---
 clang/lib/Driver/ToolChains/NetBSD.cpp |  7 ---
 clang/lib/Driver/ToolChains/OpenBSD.cpp|  6 --
 clang/lib/Driver/ToolChains/Solaris.cpp|  6 +++---
 9 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03dbdc27975b42..6702032172ddd3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1384,6 +1384,7 @@ void tools::addAsNeededOption(const ToolChain &TC,
 
 void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
  const llvm::opt::ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
@@ -1410,18 +1411,18 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
+  !TC.getTriple().isMusl() && SanArgs.needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
 static void
 collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  SmallVectorImpl &SharedRuntimes,
  SmallVectorImpl &StaticRuntimes,
  SmallVectorImpl &NonWholeStaticRuntimes,
  SmallVectorImpl &HelperStaticRuntimes,
  SmallVectorImpl &RequiredSymbols) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
 if (SanArgs.needsAsanRt()) {
@@ -1555,12 +1556,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 // Should be called before we add system libraries (C++ ABI, libstdc++/libc++,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   SmallVector SharedRuntimes, StaticRuntimes,
   NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
   if (SanArgs.linkRuntimes()) {
-collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
+collectSanitizerRuntimes(TC, Args, SanArgs, SharedRuntimes, StaticRuntimes,
  NonWholeStaticRuntimes, HelperStaticRuntimes,
  RequiredSymbols);
   }
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index b6ddd99b872798..de2d143b904790 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -38,10 +38,12 @@ void addLinkerCompressDebugSectionsOption(const ToolChain 
&TC,
 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
 
 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 void linkSanitizerRuntimeDeps(const ToolChain &TC,
   const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 3d744bc087f467..c78f4e26a2f107 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/Fre

[clang] Cache SanitizerArgs in Clang driver (NFC) (PR #119442)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Puchert (aaronpuchert)


Changes

The name getSanitizerArgs seems to mislead callers that this is a cheap 
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.

---
Full diff: https://github.com/llvm/llvm-project/pull/119442.diff


9 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5-4) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.h (+2) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+5-5) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+5-2) 
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+6-3) 
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+4-3) 
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+3-3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03dbdc27975b42..6702032172ddd3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1384,6 +1384,7 @@ void tools::addAsNeededOption(const ToolChain &TC,
 
 void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
  const llvm::opt::ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
@@ -1410,18 +1411,18 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
+  !TC.getTriple().isMusl() && SanArgs.needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
 static void
 collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  SmallVectorImpl &SharedRuntimes,
  SmallVectorImpl &StaticRuntimes,
  SmallVectorImpl &NonWholeStaticRuntimes,
  SmallVectorImpl &HelperStaticRuntimes,
  SmallVectorImpl &RequiredSymbols) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
 if (SanArgs.needsAsanRt()) {
@@ -1555,12 +1556,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 // Should be called before we add system libraries (C++ ABI, libstdc++/libc++,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   SmallVector SharedRuntimes, StaticRuntimes,
   NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
   if (SanArgs.linkRuntimes()) {
-collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
+collectSanitizerRuntimes(TC, Args, SanArgs, SharedRuntimes, StaticRuntimes,
  NonWholeStaticRuntimes, HelperStaticRuntimes,
  RequiredSymbols);
   }
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index b6ddd99b872798..de2d143b904790 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -38,10 +38,12 @@ void addLinkerCompressDebugSectionsOption(const ToolChain 
&TC,
 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
 
 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 void linkSanitizerRuntimeDeps(const ToolChain &TC,
   const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 3d744bc087f467..c78f4e26a2f107 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -283,7 +283,9 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   D.getLTOMode() == LTOK_Thin);
   }
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  const SanitizerArgs &SanArgs = ToolChai

[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits

@@ -5022,6 +5022,69 @@ bool llvm::UpgradeDebugInfo(Module &M) {
   return Modified;
 }
 
+bool static upgradeSingleNVVMAnnotation(GlobalValue *GV, StringRef K,
+const Metadata *V) {
+  if (K == "kernel") {
+assert(mdconst::extract(V)->getZExtValue() == 1);
+cast(GV)->addFnAttr("nvvm.kernel");

AlexMaclean wrote:

Some annotations (such as "texture") are applied to global variables, not 
functions. I cannot unconditionally cast to a Function until confirming the 
annotation kind.

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


[clang] Cache SanitizerArgs in Clang driver (NFC) (PR #119442)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Aaron Puchert (aaronpuchert)


Changes

The name getSanitizerArgs seems to mislead callers that this is a cheap 
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.

---
Full diff: https://github.com/llvm/llvm-project/pull/119442.diff


9 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5-4) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.h (+2) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+5-5) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+5-2) 
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+6-3) 
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+4-3) 
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+3-3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03dbdc27975b42..6702032172ddd3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1384,6 +1384,7 @@ void tools::addAsNeededOption(const ToolChain &TC,
 
 void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
  const llvm::opt::ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
@@ -1410,18 +1411,18 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
+  !TC.getTriple().isMusl() && SanArgs.needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
 static void
 collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  SmallVectorImpl &SharedRuntimes,
  SmallVectorImpl &StaticRuntimes,
  SmallVectorImpl &NonWholeStaticRuntimes,
  SmallVectorImpl &HelperStaticRuntimes,
  SmallVectorImpl &RequiredSymbols) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
 if (SanArgs.needsAsanRt()) {
@@ -1555,12 +1556,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 // Should be called before we add system libraries (C++ ABI, libstdc++/libc++,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   SmallVector SharedRuntimes, StaticRuntimes,
   NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
   if (SanArgs.linkRuntimes()) {
-collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
+collectSanitizerRuntimes(TC, Args, SanArgs, SharedRuntimes, StaticRuntimes,
  NonWholeStaticRuntimes, HelperStaticRuntimes,
  RequiredSymbols);
   }
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index b6ddd99b872798..de2d143b904790 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -38,10 +38,12 @@ void addLinkerCompressDebugSectionsOption(const ToolChain 
&TC,
 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
 
 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 void linkSanitizerRuntimeDeps(const ToolChain &TC,
   const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 3d744bc087f467..c78f4e26a2f107 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -283,7 +283,9 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   D.getLTOMode() == LTOK_Thin);
   }
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  const SanitizerArgs &SanArgs = T

[clang] Cache SanitizerArgs in Clang driver (NFC) (PR #119442)

2024-12-10 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-backend-hexagon

Author: Aaron Puchert (aaronpuchert)


Changes

The name getSanitizerArgs seems to mislead callers that this is a cheap 
function, but it extracts the SanitizerArgs each time it is called.

So we try to reuse it a bit more.

---
Full diff: https://github.com/llvm/llvm-project/pull/119442.diff


9 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5-4) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.h (+2) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+5-5) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+5-2) 
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+6-3) 
- (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+4-3) 
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+4-2) 
- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+3-3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03dbdc27975b42..6702032172ddd3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1384,6 +1384,7 @@ void tools::addAsNeededOption(const ToolChain &TC,
 
 void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
  const llvm::opt::ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
   // Force linking against the system libraries sanitizers depends on
   // (see PR15823 why this is necessary).
@@ -1410,18 +1411,18 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())
+  !TC.getTriple().isMusl() && SanArgs.needsMsanRt())
 CmdArgs.push_back("-lresolv");
 }
 
 static void
 collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  SmallVectorImpl &SharedRuntimes,
  SmallVectorImpl &StaticRuntimes,
  SmallVectorImpl &NonWholeStaticRuntimes,
  SmallVectorImpl &HelperStaticRuntimes,
  SmallVectorImpl &RequiredSymbols) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
 if (SanArgs.needsAsanRt()) {
@@ -1555,12 +1556,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 // Should be called before we add system libraries (C++ ABI, libstdc++/libc++,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
+ const SanitizerArgs &SanArgs,
  ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
   SmallVector SharedRuntimes, StaticRuntimes,
   NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
   if (SanArgs.linkRuntimes()) {
-collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
+collectSanitizerRuntimes(TC, Args, SanArgs, SharedRuntimes, StaticRuntimes,
  NonWholeStaticRuntimes, HelperStaticRuntimes,
  RequiredSymbols);
   }
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index b6ddd99b872798..de2d143b904790 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -38,10 +38,12 @@ void addLinkerCompressDebugSectionsOption(const ToolChain 
&TC,
 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
 
 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 void linkSanitizerRuntimeDeps(const ToolChain &TC,
   const llvm::opt::ArgList &Args,
+  const SanitizerArgs &SanArgs,
   llvm::opt::ArgStringList &CmdArgs);
 
 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 3d744bc087f467..c78f4e26a2f107 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -283,7 +283,9 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   D.getLTOMode() == LTOK_Thin);
   }
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  const SanitizerArgs &SanArgs 

[clang] [CIR] Infrastructure: class CIRGenBuilderTy; cache CIR types (PR #119037)

2024-12-10 Thread David Olsen via cfe-commits
https://github.com/dkolsen-pgi closed 
https://github.com/llvm/llvm-project/pull/119037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [NVPTX] Add NVVMUpgradeAnnotations pass to cleanup legacy annotations (PR #119261)

2024-12-10 Thread Alex MacLean via cfe-commits
https://github.com/AlexMaclean edited 
https://github.com/llvm/llvm-project/pull/119261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (PR #116432)

2024-12-10 Thread Paul Osmialowski via cfe-commits
https://github.com/pawosm-arm updated 
https://github.com/llvm/llvm-project/pull/116432

>From d19c8ea5e02ad92c1f89b129cd8fe2fd3cf1d4e3 Mon Sep 17 00:00:00 2001
From: Paul Osmialowski 
Date: Tue, 3 Dec 2024 12:41:15 +
Subject: [PATCH] [clang][driver] When -fveclib=ArmPL flag is in use, always
 link against libamath

Using `-fveclib=ArmPL` without libamath likely effects in the
link-time errors.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 33 ++
 clang/lib/Driver/ToolChains/MSVC.cpp   |  6 
 clang/test/Driver/fveclib.c| 17 +++
 flang/test/Driver/fveclib.f90  | 17 +++
 4 files changed, 73 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 8d977149e62485..a0d77f254bd8c3 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -490,6 +490,39 @@ void tools::AddLinkerInputs(const ToolChain &TC, const 
InputInfoList &Inputs,
 else
   A.renderAsInput(Args, CmdArgs);
   }
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+const llvm::Triple &Triple = TC.getTriple();
+StringRef V = A->getValue();
+if (V == "ArmPL" && (Triple.isOSLinux() || Triple.isOSDarwin())) {
+  // To support -fveclib=ArmPL we need to link against libamath. Some of 
the
+  // libamath functions depend on libm, at the same time, libamath exports
+  // its own implementation of some of the libm functions. These are faster
+  // and potentially less accurate implementations, hence we need to be
+  // careful what is being linked in. Since here we are interested only in
+  // the subset of libamath functions that is covered by the veclib
+  // mappings, we need to prioritize libm functions by putting -lm before
+  // -lamath (and then -lm again, to fulfill libamath requirements).
+  //
+  // Therefore we need to do the following:
+  //
+  // 1. On Linux, link only when actually needed.
+  //
+  // 2. Prefer libm functions over libamath.
+  //
+  // 3. Link against libm to resolve libamath dependencies.
+  //
+  if (Triple.isOSLinux()) {
+CmdArgs.push_back(Args.MakeArgString("--push-state"));
+CmdArgs.push_back(Args.MakeArgString("--as-needed"));
+  }
+  CmdArgs.push_back(Args.MakeArgString("-lm"));
+  CmdArgs.push_back(Args.MakeArgString("-lamath"));
+  CmdArgs.push_back(Args.MakeArgString("-lm"));
+  if (Triple.isOSLinux())
+CmdArgs.push_back(Args.MakeArgString("--pop-state"));
+  addArchSpecificRPath(TC, Args, CmdArgs);
+}
+  }
 }
 
 void tools::addLinkerCompressDebugSectionsOption(
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 80799d1e715f07..752c2e2751ab67 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -84,6 +84,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   else if (TC.getTriple().isWindowsArm64EC())
 CmdArgs.push_back("-machine:arm64ec");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+StringRef V = A->getValue();
+if (V == "ArmPL")
+  CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
   !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index 09a12c2327137c..7d0985c4dd4f48 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -112,3 +112,20 @@
 /* Verify no warning when math-errno is re-enabled for a different veclib 
(that does not imply -fno-math-errno). */
 // RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -fmath-errno 
-fveclib=LIBMVEC %s 2>&1 | FileCheck --check-prefix=CHECK-REPEAT-VECLIB %s
 // CHECK-REPEAT-VECLIB-NOT: math errno enabled
+
+/// Verify that vectorized routines library is being linked in.
+// RUN: %clang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-LINUX %s
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s -lamath 2>&1 
| FileCheck --check-prefix=CHECK-LINKING-AMATH-BEFORE-ARMPL-LINUX %s
+// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-DARWIN %s
+// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s -lamath 2>&1 
| FileCheck --check-prefix=CHECK-LINKING-AMATH-BEFORE-ARMPL-DARWIN %s
+// CHECK-LINKING-ARMPL-LINUX: "--push-state" "--as-needed" "-lm" "-lamath" 
"-lm" "--pop-state"
+// CHECK-LINKING-ARMPL-DARWIN: "-lm" "-lamath" "-lm"
+// CHECK-LINKING-ARMPL-MSV

[clang] Cache SanitizerArgs in Clang driver (NFC) (PR #119442)

2024-12-10 Thread via cfe-commits
https://github.com/Alexizx0078 approved this pull request.


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


[clang] [llvm] [HLSL] Add implicit resource element type concepts to AST (PR #116413)

2024-12-10 Thread Joshua Batista via cfe-commits

@@ -5720,8 +5720,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
   case UTT_IsTypedResourceElementCompatible:
 assert(Self.getLangOpts().HLSL &&
"typed resource element compatible types are an HLSL-only feature");
-if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
- diag::err_incomplete_type))
+if (T->isIncompleteType())

bob80905 wrote:

Consider `RWBuffer > r8;`
If we left the old condition as it was, then in evaluating the outer RWBuffer, 
we'd need to require that the inner element type `TemplatedBuffer` is a 
complete type. It is not yet, however. But we don't need to require that the 
element type is complete, because the type trait already rejects incomplete 
types. 
Requiring that condition caused assertion errors IIRC when recursing into 
deeper element types that aren't yet complete. Types would attempt to be 
completed earlier than necessary. This is unnecessary since the type trait 
itself will return false on incomplete types.
"The only allowed types are builtin types or vectors (which are builtin), any 
incomplete type is guaranteed to not conform to the concept."

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


[clang] [NFC] Cleanup comments in HLSLExternalSemaSource.cpp (PR #119444)

2024-12-10 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Joshua Batista (bob80905)


Changes

Cleaning up some comments that @bogner pointed out were unpolished.

---
Full diff: https://github.com/llvm/llvm-project/pull/119444.diff


1 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 29672658525403..9eda5e59053e7a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -851,7 +851,7 @@ static Expr *constructTypedBufferConstraintExpr(Sema &S, 
SourceLocation NameLoc,
 TemplateTypeParmDecl *T) {
   ASTContext &Context = S.getASTContext();
 
-  // Obtain the QualType for 'unsigned long'
+  // Obtain the QualType for 'bool'
   QualType BoolTy = Context.BoolTy;
 
   // Create a QualType that points to this TemplateTypeParmDecl

``




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


[clang-tools-extra] [clang-tidy][NFC] reorder cmake source file (PR #119374)

2024-12-10 Thread Carlos Galvez via cfe-commits
https://github.com/carlosgalvezp approved this pull request.


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


  1   2   3   4   >