[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/122726

>From b61110999596363bafdc94904356840febfcfaa5 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Tue, 14 Jan 2025 14:00:48 +0100
Subject: [PATCH 1/4] [WIP][Modules] Delay deserialization of preferred_name
 attribute at record level.

---
 clang/include/clang/Serialization/ASTReader.h | 18 
 .../clang/Serialization/ASTRecordReader.h | 10 ++
 clang/lib/Serialization/ASTReader.cpp |  5 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 91 ++-
 clang/lib/Serialization/ASTWriter.cpp | 19 +++-
 clang/test/Modules/preferred_name.cppm| 12 ++-
 6 files changed, 142 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 9f978762a6fb6b..4fd51eabe701ba 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1205,6 +1205,23 @@ class ASTReader
   /// been completed.
   std::deque PendingDeclContextInfos;
 
+  /// Deserialization of some attributes must be deferred since they refer
+  /// to themselves in their type (e.g., preferred_name attribute refers to the
+  /// typedef that refers back to the template specialization of the template
+  /// that the attribute is attached to).
+  /// More attributes that store TypeSourceInfo might be potentially affected,
+  /// see https://github.com/llvm/llvm-project/issues/56490 for details.
+  struct DeferredAttribute {
+uint64_t RecordIdx;
+// Decl to attach a deferred attribute to.
+Decl *ParentDecl;
+  };
+
+  /// The collection of Decls that have been loaded but some of their 
attributes
+  /// have been deferred, paired with the index inside the record pointing
+  /// at the skipped attribute.
+  SmallVector PendingDeferredAttributes;
+
   template 
   using DuplicateObjCDecls = std::pair;
 
@@ -1551,6 +1568,7 @@ class ASTReader
   void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
   void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
   unsigned PreviousGeneration = 0);
+  void loadDeferredAttribute(const DeferredAttribute &DA);
 
   RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
   uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h 
b/clang/include/clang/Serialization/ASTRecordReader.h
index 2561418b78ca7f..b1572ecef9028c 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -337,6 +337,12 @@ class ASTRecordReader
   /// Reads attributes from the current stream position, advancing Idx.
   void readAttributes(AttrVec &Attrs);
 
+  /// Reads one attribute from the current stream position, advancing Idx.
+  Attr *readOrDeferAttr(Decl *D);
+
+  /// Reads attributes from the current stream position, advancing Idx.
+  void readOrDeferAttributes(AttrVec &Attrs, Decl *D);
+
   /// Read an BTFTypeTagAttr object.
   BTFTypeTagAttr *readBTFTypeTagAttr() {
 return cast(readAttr());
@@ -355,6 +361,10 @@ class ASTRecordReader
   SwitchCase *getSwitchCaseWithID(unsigned ID) {
 return Reader->getSwitchCaseWithID(ID);
   }
+
+private:
+  Attr *readOrDeferAttrImpl(Decl *D);
+  void readOrDeferAttributesImpl(AttrVec &Attrs, Decl *D);
 };
 
 /// Helper class that saves the current stream position and
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b53f99732cacce..57d1d4d696290d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();
+
 // For each decl chain that we wanted to complete while deserializing, mark
 // it as "still needs to be completed".
 for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index dee5169ae5723a..043bed8dc7f382 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -612,7 +612,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 
   if (HasAttrs) {
 AttrVec Attrs;
-Record.readAttributes(Attrs);
+Record.readOrDeferAttributes(Attrs, D);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
@@ -3118,13 +3118,18 @@ class AttrReader {
 return Reader.readVersionTuple();
   }
 
+  void skipInts(unsigned N) { Reader.skipInts(N); }
+
+

[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread Clement Courbet via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

legrosbuffle wrote:

I don't think clang-reorder-fields is supposed to depend on stuff from 
`clang-tidy` ?

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -3240,6 +3244,7 @@ def PreferredName : InheritableAttr {
   let InheritEvenIfAlreadyPresent = 1;
   let MeaningfulToClassTemplateDefinition = 1;
   let TemplateDependent = 1;
+  let DeferDeserialization = 1;

ChuanqiXu9 wrote:

Maybe it is better to add comment here to explain why we want to defer 
PreferredName.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -3159,13 +3164,36 @@ Attr *ASTRecordReader::readAttr() {
   return New;
 }
 
-/// Reads attributes from the current stream position.
-void ASTRecordReader::readAttributes(AttrVec &Attrs) {
+/// Reads attributes from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+void ASTRecordReader::readAttributes(AttrVec &Attrs, Decl *D) {
   for (unsigned I = 0, E = readInt(); I != E; ++I)
-if (auto *A = readAttr())
+if (auto *A = readOrDeferAttrFor(D))
   Attrs.push_back(A);
 }
 
+
+/// Reads one attribute from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+Attr *ASTRecordReader::readOrDeferAttrFor(Decl *D) {
+  AttrReader Record(*this);
+  unsigned SkipCount = Record.readInt();
+  if (!SkipCount)
+return readAttr();

ChuanqiXu9 wrote:

Now it assumes that `readAttr()` should be called after the skip bit. Then the 
caller has more responsibility. I feel it better to skip it in `readAttr` and 
not read here.

e.g.,
```suggestion
  unsigned SkipCount = Record.peekInt();
  if (!SkipCount)
return readAttr();
```

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

LGTM basically.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -713,6 +713,10 @@ class Attr {
   // attribute may be documented under multiple categories, more than one
   // Documentation entry may be listed.
   list Documentation;
+  // Set to true if deserialization of this attribute must be deferred until 
+  // the parent Decl is fully deserialized (during header module file
+  // deserialization).

ChuanqiXu9 wrote:

It reads better if we can give an example to describe when we want to defer it.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();

ChuanqiXu9 wrote:

```suggestion
// Load the delayed preferred name attributes.
while (!PendingDeferredAttributes.empty()) {
  auto DeferredAttributes = std::move(PendingDeferredAttributes);
  for (DeferredAttribute &DA : DeferredAttribute)
loadDeferredAttribute(DA);
}
```

Technically, it is possible to update `PendingDeferredAttributes` during 
`loadDeferredAttribute()`.

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Björn Pettersson via cfe-commits


@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make
+// sure the table is sorted.

bjope wrote:

The context for "the table" is a bit unclear here.
Maybe something like
  "... to make sure tables based on Diagnostic IDs are partitioned/sorted based 
on DiagID."

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/123060

>From 005a730b72be1305c67f886d9a473273d7318d99 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Wed, 15 Jan 2025 12:19:58 +
Subject: [PATCH 1/4] [clang][refactor] Refactor
 `findNextTokenIncludingComments`

We have two copies of the same code in clang-tidy and
clang-reorder-fields, and those are extremenly similar to
`Lexer::findNextToken`, so just add an extra agument to the latter.
---
 .../ReorderFieldsAction.cpp   | 34 ++-
 .../modernize/ConcatNestedNamespacesCheck.cpp |  2 +-
 .../clang-tidy/modernize/UseOverrideCheck.cpp |  5 ++-
 .../clang-tidy/utils/LexerUtils.cpp   | 23 -
 .../clang-tidy/utils/LexerUtils.h |  4 ++-
 clang/include/clang/Lex/Lexer.h   |  3 +-
 clang/lib/Lex/Lexer.cpp   |  4 ++-
 7 files changed, 14 insertions(+), 61 deletions(-)

diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index 80ee31368fe9a5..40c96f92254e42 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -118,35 +118,6 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
@@ -154,11 +125,12 @@ static SourceLocation 
getEndOfTrailingComment(SourceLocation Loc,
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   }
   return Loc;
 }
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index d24b613015d8ee..b4f54d02fc3362 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -59,7 +59,7 @@ SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
   // Back from '}' to conditional '// namespace xxx'
   SourceLocation Loc = front()->getRBraceLoc();
   std::optional Tok =
-  utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   if (!Tok)
 return getDefaultNamespaceBackRange();
   if (Tok->getKind() != tok::TokenKind::comment)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index fd5bd9f0b181b1..6191ebfbfb01f0 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -229,9 +229,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult 
&Result) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-std::optional NextToken =
-utils::lexer::findNextTokenIncludingComments(
-Tok.getEndLoc(), Sources, getLangOpts());
+std::optional NextToken = Lexer::findNextToken(
+Tok.getEndLoc(), Sources, getLangOpts(), /*IncludeComments*/ true);
 if (NextToken.has_value()) {
   Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(

[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

2025-01-16 Thread via cfe-commits

goldsteinn wrote:

``

> Works well on Linux, generally seems fine although I still think it's worth 
> considering splitting out "getting-changes" into a separate shared code-base 
> to avoid dealing with details of calling diff for different version control 
> system here.

Think lukel97 also tested on MacOS.

I see where you're coming from regarding the split, although still feel quite 
strongly that features that don't make it into the mainline project have a high 
risk of becoming derelict.

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 6affc1837537a802531a5394535f1f0b7ca865cb 
66acd22f1de097e23eaafe7e5fe20168727f9d82 --extensions cpp,h -- 
clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp 
clang-tools-extra/clang-tidy/utils/LexerUtils.h clang/include/clang/Lex/Lexer.h 
clang/lib/Lex/Lexer.cpp clang/unittests/Lex/LexerTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/Lex/LexerTest.cpp 
b/clang/unittests/Lex/LexerTest.cpp
index 7b05844589..c897998cab 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -635,8 +635,9 @@ TEST_F(LexerTest, FindNextTokenIncludingComments) {
 GeneratedByNextToken.push_back(getSourceText(*T, *T));
 Loc = T->getLocation();
   }
-  EXPECT_THAT(GeneratedByNextToken, ElementsAre("abcd", "=", "0", ";", "// A 
comment.", "int",
-"xyz", "=", "abcd", ";"));
+  EXPECT_THAT(GeneratedByNextToken,
+  ElementsAre("abcd", "=", "0", ";", "// A comment.", "int", "xyz",
+  "=", "abcd", ";"));
 }
 
 TEST_F(LexerTest, CreatedFIDCountForPredefinedBuffer) {

``




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


[libclc] [libclc] Move smoothstep to CLC and optimize its codegen (PR #123183)

2025-01-16 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/123183

This commit moves the implementation of the smoothstep function to the CLC 
library, whilst optimizing the codegen.

This commit also adds support for 'half' versions of smoothstep, which were 
previously missing.

The CLC smoothstep implementation now keeps everything in vectors, rather than 
recursively splitting vectors by half down to the scalar base form. This should 
result in more optimal codegen across the board.

This commit also removes some non-standard overloads of smoothstep with mixed 
types, such as 'double smoothstep(float, float, float)'. There aren't any 
mixed-(element )type versions of smoothstep as far as I can see:

gentype smoothstep(gentype edge0, gentype edge1, gentype x)
gentypef smoothstep(float edge0, float edge1, gentypef x)
gentyped smoothstep(double edge0, double edge1, gentyped x)
gentypeh smoothstep(half edge0, half edge1, gentypeh x)

The CLC library only defines the first type, for simplicity; the OpenCL layer 
is responsible for handling the scalar/scalar/vector forms. Note that the 
scalar/scalar/vector forms now splat the scalars to the vector type, rather 
than recursively split vectors as before. The macro that used to 'vectorize' 
smoothstep in this way has been moved out of the shared clcmacro.h header as it 
was only used for the smoothstep builtin.

Note that the CLC clamp function is now built for both SPIR-V targets. This is 
to help build the CLC smoothstep function for the Mesa SPIR-V target.

>From 1f2c46420036ecf79c04084c3b97b26c5bfc1868 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 16 Jan 2025 10:34:31 +
Subject: [PATCH] [libclc] Move smoothstep to CLC and optimize its codegen

This commit moves the implementation of the smoothstep function to the
CLC library, whilst optimizing the codegen.

This commit also adds support for 'half' versions of smoothstep, which
were previously missing.

The CLC smoothstep implementation now keeps everything in vectors,
rather than recursively splitting vectors by half down to the scalar
base form. This should result in more optimal codegen across the board.

This commit also removes some non-standard overloads of smoothstep with
mixed types, such as 'double smoothstep(float, float, float)'. There
aren't any mixed-(element )type versions of smoothstep as far as I can
see:

gentype smoothstep(gentype edge0, gentype edge1, gentype x)
gentypef smoothstep(float edge0, float edge1, gentypef x)
gentyped smoothstep(double edge0, double edge1, gentyped x)
gentypeh smoothstep(half edge0, half edge1, gentypeh x)

The CLC library only defines the first type, for simplicity; the OpenCL
layer is responsible for handling the scalar/scalar/vector forms. Note
that the scalar/scalar/vector forms now splat the scalars to the vector
type, rather than recursively split vectors as before. The macro that
used to 'vectorize' smoothstep in this way has been moved out of the
shared clcmacro.h header as it was only used for the smoothstep builtin.

Note that the CLC clamp function is now built for both SPIR-V targets.
This is to help build the CLC smoothstep function for the Mesa SPIR-V
target.
---
 libclc/clc/include/clc/clcmacro.h | 23 ---
 .../clc/include/clc/common/clc_smoothstep.h   | 11 
 .../clc/include/clc/common/clc_smoothstep.inc |  3 +
 libclc/clc/include/clc/shared/clc_clamp.h |  7 --
 libclc/clc/lib/clspv/SOURCES  |  1 +
 libclc/clc/lib/generic/SOURCES|  1 +
 .../clc/lib/generic/common/clc_smoothstep.cl  | 52 +++
 libclc/clc/lib/spirv/SOURCES  |  2 +
 libclc/clc/lib/spirv64/SOURCES|  2 +
 libclc/generic/lib/common/smoothstep.cl   | 66 +--
 10 files changed, 118 insertions(+), 50 deletions(-)
 create mode 100644 libclc/clc/include/clc/common/clc_smoothstep.h
 create mode 100644 libclc/clc/include/clc/common/clc_smoothstep.inc
 create mode 100644 libclc/clc/lib/generic/common/clc_smoothstep.cl

diff --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index c6583749eca661..3c3a69f4f848bb 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -102,29 +102,6 @@
   FUNCTION(x.hi, y.hi, z.hi)); 
\
   }
 
-#define _CLC_V_S_S_V_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE,
\
-   ARG2_TYPE, ARG3_TYPE)   
\
-  DECLSPEC RET_TYPE##2 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##2 z) {
\
-return (RET_TYPE##2)(FUNCTION(x, y, z.lo), FUNCTION(x, y, z.hi));  
\
-  }
\
-   
\
-  DECLSPEC RET_TYPE##3 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##3 z) {
\
-re

[libclc] [libclc] Move smoothstep to CLC and optimize its codegen (PR #123183)

2025-01-16 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

Here's an example of the difference in LLVM IR for `smoothstep(double16, 
double16, double16)`: https://godbolt.org/z/P9sM3Wjjn



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


[libclc] [libclc] Move smoothstep to CLC and optimize its codegen (PR #123183)

2025-01-16 Thread Fraser Cormack via cfe-commits


@@ -0,0 +1,52 @@
+/*

frasercrmck wrote:

I wasn't sure if the AMD copyright still applies to this copied file, so I kept 
it.

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


[clang-tools-extra] [clang-tidy][modernize] Replace memmove/memcpy with std::copy (PR #122940)

2025-01-16 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

> @kadircet Does the file need further changes from what I've already added?

probably yes, it'd be great if you can just run 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/TidyFastChecks.py
 to generate the edits

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


[clang] [clang] [ARM] Explicitly enable NEON for Windows/Darwin targets (PR #122095)

2025-01-16 Thread Martin Storsjö via cfe-commits


@@ -659,13 +659,21 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
+bool Generic = true;
 if (!ForAS) {
   std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
+  if (CPU != "generic")
+Generic = false;
   llvm::ARM::ArchKind ArchKind =
   arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
   FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
   (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
 }
+if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&

mstorsjo wrote:

Almost; `clang -target armv7-apple-darwin` will return `"generic"` above, and 
we'll need to add in NEON explicitly to it. However `armv7-windows` will get a 
default CPU of `cortex-a9` which has NEON (and more). This case isn't 
necessarily something we need to preserve much about, but a case of 
`armv7s-apple-darwin` does get hit by one of the testcases, and `armv7s` does 
also get a specific CPU (`swift`) which also has got NEON and FP16 - and the 
distinction from that is picked up by an existing testcase.

So only for the cases where `arm::getARMTargetCPU()` doesn't return a specific 
CPU for this arch/OS target combo, we hit the "generic" case, where we want to 
add in reasonable defaults.

Yes, the fact that Android has its own check further above, means that it 
doesn't hit the `arm::getARMTargetCPU()` case, and doesn't pick up defaults 
from there (where it can add more core specific things like FP16 etc) - and 
indeed, I'm trying to avoid changing anything wrt that, even if it probably 
could work with this new codepath as well.

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


[libclc] [libclc] Move smoothstep to CLC and optimize its codegen (PR #123183)

2025-01-16 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang] Deprecate __is_referenceable (PR #123185)

2025-01-16 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/123185

See #123078


>From c060b496d53002ce263ae43bd74153b2a89aca99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 16 Jan 2025 12:19:03 +0100
Subject: [PATCH] [Clang] Deprecate __is_referenceable

---
 clang/docs/LanguageExtensions.rst |  2 +-
 clang/docs/ReleaseNotes.rst   | 11 ---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2eb0777dbdc6c8..3aabb4f87fe9b8 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1697,7 +1697,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_referenceable`` (C++, GNU, Microsoft, Embarcadero):
   Returns true if a type is referenceable, and false otherwise. A referenceable
   type is a type that's either an object type, a reference type, or an 
unqualified
-  function type.
+  function type. This trait is deprecated and will be removed in Clang 21.
 * ``__is_rvalue_reference`` (C++, Embarcadero)
 * ``__is_same`` (C++, Embarcadero)
 * ``__is_same_as`` (GCC): Synonym for ``__is_same``.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6be841035db18..e2c148820d9ef8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -93,6 +93,11 @@ C++ Specific Potentially Breaking Changes
   few users and can be written as ``__is_same(__remove_cv(T), 
decltype(nullptr))``,
   which GCC supports as well.
 
+- The type trait builtin ``__is_referenceable`` has been deprecated, since it 
has
+  very few users and all the type traits that could benefit from it in the
+  standard library already have their own bespoke builtins. It will be removed 
in
+  Clang 21.
+
 - Clang will now correctly diagnose as ill-formed a constant expression where 
an
   enum without a fixed underlying type is set to a value outside the range of
   the enumeration's values.
@@ -310,7 +315,7 @@ C++23 Feature Support
 
 - Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now 
fully
   supports `P2718R0 Lifetime extension in range-based for loops 
`_.
-  
+
 - ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
 
 C++20 Feature Support
@@ -715,7 +720,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate 
initialization (#101957).
 
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class
   defined a defaulted comparison operator (#GH116270).
 
   .. code-block:: c++
@@ -934,7 +939,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
   friend declarations. (#GH113324)
 - Fix a crash caused by incorrect argument position in merging deduced 
template arguments. (#GH113659)
-- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072) 
+- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072)
 - Fixed a null pointer dereference issue when heuristically computing 
``sizeof...(pack)`` expressions. (#GH81436)
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda

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


[clang] [Clang] Deprecate __is_referenceable (PR #123185)

2025-01-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikolas Klauser (philnik777)


Changes

See #123078


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


2 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1-1) 
- (modified) clang/docs/ReleaseNotes.rst (+8-3) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2eb0777dbdc6c8..3aabb4f87fe9b8 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1697,7 +1697,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_referenceable`` (C++, GNU, Microsoft, Embarcadero):
   Returns true if a type is referenceable, and false otherwise. A referenceable
   type is a type that's either an object type, a reference type, or an 
unqualified
-  function type.
+  function type. This trait is deprecated and will be removed in Clang 21.
 * ``__is_rvalue_reference`` (C++, Embarcadero)
 * ``__is_same`` (C++, Embarcadero)
 * ``__is_same_as`` (GCC): Synonym for ``__is_same``.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6be841035db18..e2c148820d9ef8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -93,6 +93,11 @@ C++ Specific Potentially Breaking Changes
   few users and can be written as ``__is_same(__remove_cv(T), 
decltype(nullptr))``,
   which GCC supports as well.
 
+- The type trait builtin ``__is_referenceable`` has been deprecated, since it 
has
+  very few users and all the type traits that could benefit from it in the
+  standard library already have their own bespoke builtins. It will be removed 
in
+  Clang 21.
+
 - Clang will now correctly diagnose as ill-formed a constant expression where 
an
   enum without a fixed underlying type is set to a value outside the range of
   the enumeration's values.
@@ -310,7 +315,7 @@ C++23 Feature Support
 
 - Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now 
fully
   supports `P2718R0 Lifetime extension in range-based for loops 
`_.
-  
+
 - ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
 
 C++20 Feature Support
@@ -715,7 +720,7 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate 
initialization (#101957).
 
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class
   defined a defaulted comparison operator (#GH116270).
 
   .. code-block:: c++
@@ -934,7 +939,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
   friend declarations. (#GH113324)
 - Fix a crash caused by incorrect argument position in merging deduced 
template arguments. (#GH113659)
-- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072) 
+- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072)
 - Fixed a null pointer dereference issue when heuristically computing 
``sizeof...(pack)`` expressions. (#GH81436)
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda

``




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


[clang] [nfc][analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-16 Thread Gábor Horváth via cfe-commits


@@ -0,0 +1,72 @@
+//===-- MemSpaces.cpp -*- C++ 
-*--//
+//
+// 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
+//
+//===--===//
+//
+// This file defines getters and setters for the memory space trait which
+// associates memory regions with memory spaces in the program state. It also
+// defines the MemSpacesMap which maps memory regions to memory spaces.
+//
+// These functions keep the following invariants over the MemSpacesMap:
+// 1. (Temporary as an intermediate step) Memory space traits are only
+//mapped for memory regions that have an unknown memory space
+// 2. Only base memory regions are mapped in the trait
+// 3. Memory regions which have no mapping in the trait are assumed to be
+//unknown; no memory region is allowed to be mapped to an unknown memory
+//space in the trait;
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemSpaces.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include 
+
+REGISTER_MAP_WITH_PROGRAMSTATE(MemSpacesMap, const clang::ento::MemRegion *,
+   const clang::ento::MemSpaceRegion *)
+
+namespace clang {
+namespace ento {
+namespace memspace {
+
+// Canonicalize to base, in case of subregions, we don't want base regions and
+// subregions to have different memory spaces
+[[nodiscard]] static const MemRegion *
+canonicalizeMemRegion(const MemRegion *MR) {
+  return MR->getBaseRegion();
+}
+
+ProgramStateRef setMemSpaceTrait(ProgramStateRef State, const MemRegion *MR,
+ const MemSpaceRegion *MS) {
+  MR = canonicalizeMemRegion(MR);
+
+  // For now, this should only be called to update the trait for memory regions
+  // that have an unknown memory spaces since we assume everywhere else that 
the
+  // memory space trait is set only for unknown memory spaces (setting this 
info
+  // otherwise would go unused).
+  assert(isa(MR->getMemorySpace()));
+
+  // Shouldn't use the memory space trait to associate UnknownSpaceRegion with
+  // an already UnknownSpaceRegion
+  assert(!isa(MS));
+
+  ProgramStateRef NewState = State->set(MR, MS);
+  return NewState;
+}
+
+const MemSpaceRegion *getMemSpace(ProgramStateRef State, const MemRegion *MR) {
+  MR = canonicalizeMemRegion(MR);
+
+  const MemSpaceRegion *const *Result = State->get(MR);

Xazax-hun wrote:

Hmm, I am not sure how expensive these lookups are. Maybe we could do it only 
for UnknownSpaceRegion?

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


[clang] [nfc][analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-16 Thread Gábor Horváth via cfe-commits

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


[clang] [nfc][analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-16 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun commented:

I like the direction of this PR but at the same time it makes memspaces a bit 
more error prone to use. Do you think we could find a way to prevent using 
`isa` on memspaces?

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread Alexander Shaposhnikov via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

alexander-shaposhnikov wrote:

yeah, i think it's not worth it (adding a dependency on clang-tidy for the sake 
of findNextTokenIncludingComments seems like overkill).

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread Alexander Shaposhnikov via cfe-commits

https://github.com/alexander-shaposhnikov approved this pull request.

lgtm

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


[clang] [llvm] [Pipelines] Move IPSCCP after inliner pipeline (PR #96620)

2025-01-16 Thread via cfe-commits

joshua-arch1 wrote:

Are you testing your patch on LTO? Before applying your patch, the function is 
split into two patches:
```
00071270 <_QMbrute_forcePdigits_2.specialized.1>:
00074630 <_QMbrute_forcePdigits_2.specialized.5>:
```
With your patch, it exhibits the same behavior. Do you know how I can get the 
same behavior as gcc where digits_2 is split into eight parts?


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


[clang] [Clang][Arch] Disable mve.fp when explicit -mfpu option (PR #123028)

2025-01-16 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 commented:

Was there any tests that need changing/updating for this? If we don't have 
tests for this it might be worth adding some.

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


[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)

2025-01-16 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> > Is there any hope of upgrading MSVC? I know you were looking at that, but 
> > not sure what progress happened there.
> 
> I didn't go through with it and was hoping you would be able to find a 
> work-around. I'll start talking to people to try and do a stop-gap update to 
> a later version of VS2019 and let you know if/when we have deployed it. (I 
> will be updating our upstream build bot as well at the same time).

What really baffles me is that LLVM itself should already be hitting this MSVC 
bug in serious ways starting with 
https://github.com/llvm/llvm-project/commit/381405fafe9d48d29c777e7680902d0943834859

That commit removed the only real workaround I know of from a *much* larger 
string table in the core of LLVM. What I can't figure out is why that string 
table compiles successfully but these don't. You all don't have any failing 
tests like `llvm/test/CodeGen/ARM/ldstrex.ll` or 
`llvm/test/Bitcode/arm-intrinsics.ll`?

Or any workaround patches to `llvm/lib/IR/Intrinsics.cpp`?

And line 18226-ish of the generated file `include/llvm/IR/IntrinsicImpl.inc`, 
you have `  98568, // llvm.arm.ldrex`? (Or if not that exact number, something 
larger than 64k...)

Mostly the above is for my curiosity to try and understand why the file in LLVM 
works despite all these in Clang not working

I can basically revert parts of the above commit and make some other tablegen 
changes and I *should* be able to work around this if necessary. But it will 
make the above LLVM file and all these parts of Clang a bit slower to compile, 
sadly for all builds. So I'd like to avoid that if there is a reasonable way to 
upgrade. But if folks need to keep using this release series of MSVC, then we 
should somewhat systematically avoid risking this miscompile, even in the one 
place where it seems to work today.

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


[clang] 3a9380f - [Multilib] Custom flags processing for library selection (#110659)

2025-01-16 Thread via cfe-commits

Author: Victor Campos
Date: 2025-01-16T09:35:56Z
New Revision: 3a9380f21d05eb8ced03349c8c503dc911f22621

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

LOG: [Multilib] Custom flags processing for library selection (#110659)

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

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

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

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch is comprised
of the core processing of these flags.

- Custom flags in the command-line are read and forwarded to the
multilib system. If multiple flag values are present for the same flag
declaration, the last one wins. Default flag values are inserted for
flag declarations for which no value was given.
- Feed `MacroDefines` back into the driver. Each item `` in the
`MacroDefines` list is formatted as `-D`.

Library variants should list their requirement on one or more custom
flags like they do for any other flag. The new command-line option is
passed as-is to the multilib system, therefore it should be listed in
the format `-fmultilib-flag=`.

Moreover, a variant that does not specify a requirement on any
particular flag can be matched against any value of that flag.

If the user specifies `-fmultilib-flag=` with a name that is
invalid, but close enough to any valid flag value name in terms of edit
distance, a suggesting error is shown:
```
error: unsupported option '-fmultilib-flag=invalidname'; did you mean 
'-fmultilib-flag=validname'?
```
The candidate with the smallest edit distance is chosen for the
suggestion, up to a certain maximum value (implementation detail), after
which a non-suggesting error is shown instead:
```
error: unsupported option '-fmultilib-flag=invalidname'
```

Added: 
clang/test/Driver/baremetal-multilib-custom-flags.yaml

Modified: 
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Multilib.h
clang/include/clang/Driver/ToolChain.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Multilib.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/BareMetal.h

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index e2eec58ba99d36..f4a52cc529b79c 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -491,7 +491,7 @@ class Driver {
   /// ArgList.
   llvm::opt::InputArgList ParseArgStrings(ArrayRef Args,
   bool UseDriverMode,
-  bool &ContainsError);
+  bool &ContainsError) const;
 
   /// BuildInputs - Construct the list of inputs and their types from
   /// the given arguments.

diff  --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 0a533ed2804e25..fc071ef48ca0f9 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -168,9 +168,18 @@ class MultilibSet {
   const_iterator begin() const { return Multilibs.begin(); }
   const_iterator end() const { return Multilibs.end(); }
 
+  /// Process custom flags from \p Flags and returns an expanded flags list and
+  /// a list of macro defines.
+  /// Returns a pair where:
+  ///  - first: the new flags list including custom flags after processing.
+  ///  - second: the extra macro defines to be fed to the driver.
+  std::pair>
+  processCustomFlags(const Driver &D, const Multilib::flags_list &Flags) const;
+
   /// Select compatible variants, \returns false if none are compatible
   bool select(const Driver &D, const Multilib::flags_list &Flags,
-  llvm::SmallVectorImpl &) const;
+  llvm::SmallVectorImpl &,
+  llvm::SmallVector * = nullptr) const;
 
   unsigned size() const { return Multilibs.size(); }
 

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 701a1d25ca4c8d..7d1d8feebf35e3 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -686,6 +686,13 @@ class ToolChain {
   /// Add warning options that need to be passed to cc1 for this target.
   virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const

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

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

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/123060

>From 005a730b72be1305c67f886d9a473273d7318d99 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Wed, 15 Jan 2025 12:19:58 +
Subject: [PATCH 1/5] [clang][refactor] Refactor
 `findNextTokenIncludingComments`

We have two copies of the same code in clang-tidy and
clang-reorder-fields, and those are extremenly similar to
`Lexer::findNextToken`, so just add an extra agument to the latter.
---
 .../ReorderFieldsAction.cpp   | 34 ++-
 .../modernize/ConcatNestedNamespacesCheck.cpp |  2 +-
 .../clang-tidy/modernize/UseOverrideCheck.cpp |  5 ++-
 .../clang-tidy/utils/LexerUtils.cpp   | 23 -
 .../clang-tidy/utils/LexerUtils.h |  4 ++-
 clang/include/clang/Lex/Lexer.h   |  3 +-
 clang/lib/Lex/Lexer.cpp   |  4 ++-
 7 files changed, 14 insertions(+), 61 deletions(-)

diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index 80ee31368fe9a5..40c96f92254e42 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -118,35 +118,6 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
@@ -154,11 +125,12 @@ static SourceLocation 
getEndOfTrailingComment(SourceLocation Loc,
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   }
   return Loc;
 }
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index d24b613015d8ee..b4f54d02fc3362 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -59,7 +59,7 @@ SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
   // Back from '}' to conditional '// namespace xxx'
   SourceLocation Loc = front()->getRBraceLoc();
   std::optional Tok =
-  utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   if (!Tok)
 return getDefaultNamespaceBackRange();
   if (Tok->getKind() != tok::TokenKind::comment)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index fd5bd9f0b181b1..6191ebfbfb01f0 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -229,9 +229,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult 
&Result) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-std::optional NextToken =
-utils::lexer::findNextTokenIncludingComments(
-Tok.getEndLoc(), Sources, getLangOpts());
+std::optional NextToken = Lexer::findNextToken(
+Tok.getEndLoc(), Sources, getLangOpts(), /*IncludeComments*/ true);
 if (NextToken.has_value()) {
   Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(

[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-01-16 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> @ChuanqiXu9 are you able to have a look?

Sorry, I can't test and take a deeper look on windows. From 
https://discourse.llvm.org/t/driver-volunteer-wanted-for-modules-support-in-driver-for-mac-ubuntu-and-windows/83768/13,
 I think you can CC people there or calling again there.

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


[clang] [clang] [ARM] Explicitly enable NEON for Windows/Darwin targets (PR #122095)

2025-01-16 Thread David Spickett via cfe-commits


@@ -659,13 +659,21 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : 
ArchArgFPUKind;
 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
   } else {
+bool Generic = true;
 if (!ForAS) {
   std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
+  if (CPU != "generic")
+Generic = false;
   llvm::ARM::ArchKind ArchKind =
   arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
   FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
   (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
 }
+if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&

DavidSpickett wrote:

So the logic for the "generic" check is that `clang -target windows` will be 
using cpu generic, fine. If you were specifying the CPU of a real target 
device, then presumably that would have Neon and Clang would know that anyway.

Only if you're doing something strange with a CPU that's never had iOS or 
Windows run on it, only then does this code not apply. But given that it's a 
strange use case, it's best to leave it alone and just take the user's intent 
literally.

Correct?

Also I note that Android does not do this generic CPU check. I don't think 
making it do that should be part of this PR, and so, while I think this code is 
spaghetti, I wouldn't try to merge them here. Probably wouldn't break anything, 
but probably isn't zero chance.

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


[clang] [clang] [ARM] Explicitly enable NEON for Windows/Darwin targets (PR #122095)

2025-01-16 Thread David Spickett via cfe-commits

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

My understanding is that:
* This PR does not conflict with what the Debian patch does.
* It in fact will fix a bug in the Debian build.
* This does not change the behaviour of an unmodified Clang from a user's 
perspective, therefore we do not need to release note this.

On that basis, LGTM.

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


[clang] [clang] [ARM] Explicitly enable NEON for Windows/Darwin targets (PR #122095)

2025-01-16 Thread David Spickett via cfe-commits

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


[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-16 Thread Sjoerd Meijer via cfe-commits


@@ -323,9 +321,10 @@ bfloat16x8_t test_vcvtq_low_bf16_f32(float32x4_t a) {
 // CHECK-A64-NEXT:  entry:
 // CHECK-A64-NEXT:[[TMP0:%.*]] = bitcast <8 x bfloat> [[INACTIVE:%.*]] to 
<16 x i8>
 // CHECK-A64-NEXT:[[TMP1:%.*]] = bitcast <4 x float> [[A:%.*]] to <16 x i8>
-// CHECK-A64-NEXT:[[VCVTQ_HIGH_BF16_F322_I:%.*]] = call <8 x bfloat> 
@llvm.aarch64.neon.bfcvtn2(<8 x bfloat> [[INACTIVE]], <4 x float> [[A]])
-// CHECK-A64-NEXT:[[VCVTQ_HIGH_BF16_F323_I:%.*]] = bitcast <8 x bfloat> 
[[VCVTQ_HIGH_BF16_F322_I]] to <16 x i8>
-// CHECK-A64-NEXT:ret <8 x bfloat> [[VCVTQ_HIGH_BF16_F322_I]]
+// CHECK-A64-NEXT:[[TMP2:%.*]] = shufflevector <8 x bfloat> [[INACTIVE]], 
<8 x bfloat> poison, <4 x i32> 
+// CHECK-A64-NEXT:[[TMP3:%.*]] = fptrunc <4 x float> [[A]] to <4 x bfloat>
+// CHECK-A64-NEXT:[[TMP4:%.*]] = shufflevector <4 x bfloat> [[TMP2]], <4 x 
bfloat> [[TMP3]], <8 x i32> 

sjoerdmeijer wrote:

I am not sure I am following what the result TMP4 represents here: it is an 8 
element vector,
where the first 4 elements come from INACTIVE, and the other 4 elements the 
truncated floats. Is that right? How does that match up with "BFCVTN2 
instruction writes the results to the upper half of the destination vector 
without affecting the other bits in the register"?

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


[clang] [llvm] [IR] Convert from nocapture to captures(none) (PR #123181)

2025-01-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)


Changes

This PR removes the old `nocapture` attribute, replacing it with the new 
`captures` attribute introduced in 
https://github.com/llvm/llvm-project/pull/116990. This change is intended to be 
essentially NFC, replacing existing uses of `nocapture` with `captures(none)` 
without adding any new analysis capabilities. Making use of non-`none` values 
is left for a followup.

Some notes:
 * `nocapture` will be upgraded to `captures(none)` by the bitcode reader.
 * `nocapture` will also be upgraded by the textual IR reader. This is to make 
it easier to use old IR files and somewhat reduce the test churn in this PR.
 * Helper APIs like `doesNotCapture()` will check for `captures(none)`.
 * MLIR import will convert `captures(none)` into an `llvm.nocapture` 
attribute. The representation in the LLVM IR dialect should be updated 
separately.

---

Patch is 1.86 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123181.diff


374 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+3-1) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5) 
- (modified) 
clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+1-1) 
- (modified) clang/test/CodeGen/PowerPC/aix-vaargs.c (+2-2) 
- (modified) clang/test/CodeGen/SystemZ/systemz-inline-asm.c (+1-1) 
- (modified) clang/test/CodeGen/X86/ms-x86-intrinsics.c (+2-2) 
- (modified) clang/test/CodeGen/arm-cmse-attr.c (+2-2) 
- (modified) clang/test/CodeGen/arm-vfp16-arguments.c (+1-1) 
- (modified) clang/test/CodeGen/arm-vfp16-arguments2.cpp (+5-5) 
- (modified) clang/test/CodeGen/attr-counted-by-pr110385.c (+18-9) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+138-138) 
- (modified) clang/test/CodeGen/isfpclass.c (+1-1) 
- (modified) clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c (+9-9) 
- (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+7-7) 
- (modified) clang/test/CodeGen/mips-vector-return.c (+3-3) 
- (modified) clang/test/CodeGen/mips64-nontrivial-return.cpp (+1-1) 
- (modified) clang/test/CodeGen/ms-intrinsics-other.c (+38-38) 
- (modified) clang/test/CodeGen/ms-intrinsics.c (+153-153) 
- (modified) clang/test/CodeGen/nofpclass.c (+2-2) 
- (modified) clang/test/CodeGen/sanitize-metadata-nosanitize.c (+21-4) 
- (modified) clang/test/CodeGen/struct-copy.c (+1-1) 
- (modified) clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp (+1-1) 
- (modified) clang/test/CodeGen/transparent-union-type.c (+3-3) 
- (modified) clang/test/CodeGen/union-tbaa1.c (+1-1) 
- (modified) clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu (+11-11) 
- (modified) clang/test/CodeGenCXX/bitfield-ir.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/inline-then-fold-variadics.cpp (+16-16) 
- (modified) clang/test/CodeGenCXX/noescape.cpp (+15-15) 
- (modified) clang/test/CodeGenCXX/wasm-args-returns.cpp (+1-1) 
- (modified) clang/test/CodeGenHLSL/inline-functions.hlsl (+1-1) 
- (modified) clang/test/CodeGenObjC/noescape.m (+13-13) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (+12-12) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-call-kernel.cl (+1-1) 
- (modified) 
clang/test/CodeGenOpenCL/atomic-builtins-default-to-device-scope.cl (+34-34) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl (+7-6) 
- (modified) clang/test/CodeGenOpenCL/kernel-param-alignment.cl (+6-6) 
- (modified) clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl (+7-7) 
- (modified) clang/test/CodeGenOpenCL/preserve_vec3.cl (+9-9) 
- (modified) clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp (+1-1) 
- (modified) clang/test/OpenMP/barrier_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/bug54082.c (+8-8) 
- (modified) llvm/docs/LangRef.rst (+8-26) 
- (modified) llvm/docs/ReleaseNotes.md (+2) 
- (modified) llvm/include/llvm/AsmParser/LLToken.h (+2-1) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+8-7) 
- (modified) llvm/include/llvm/IR/Attributes.h (+1) 
- (modified) llvm/include/llvm/IR/Attributes.td (-3) 
- (modified) llvm/include/llvm/IR/InstrTypes.h (+5-7) 
- (modified) llvm/include/llvm/Support/ModRef.h (+17) 
- (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+7-3) 
- (modified) llvm/lib/AsmParser/LLLexer.cpp (+1) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+6) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+12-3) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (-2) 
- (modified) llvm/lib/IR/Attributes.cpp (+4-1) 
- (modified) llvm/lib/IR/Function.cpp (+1-1) 
- (modified) llvm/lib/IR/Instructions.cpp (+19) 
- (modified) llvm/lib/Target/DirectX/DXILPrepare.cpp (-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/SpillUtils.cpp (+2-2) 
- (modified

[clang] [llvm] [IR] Convert from nocapture to captures(none) (PR #123181)

2025-01-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-hexagon

@llvm/pr-subscribers-backend-aarch64

Author: Nikita Popov (nikic)


Changes

This PR removes the old `nocapture` attribute, replacing it with the new 
`captures` attribute introduced in 
https://github.com/llvm/llvm-project/pull/116990. This change is intended to be 
essentially NFC, replacing existing uses of `nocapture` with `captures(none)` 
without adding any new analysis capabilities. Making use of non-`none` values 
is left for a followup.

Some notes:
 * `nocapture` will be upgraded to `captures(none)` by the bitcode reader.
 * `nocapture` will also be upgraded by the textual IR reader. This is to make 
it easier to use old IR files and somewhat reduce the test churn in this PR.
 * Helper APIs like `doesNotCapture()` will check for `captures(none)`.
 * MLIR import will convert `captures(none)` into an `llvm.nocapture` 
attribute. The representation in the LLVM IR dialect should be updated 
separately.

---

Patch is 1.86 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123181.diff


374 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+3-1) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5) 
- (modified) 
clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+1-1) 
- (modified) clang/test/CodeGen/PowerPC/aix-vaargs.c (+2-2) 
- (modified) clang/test/CodeGen/SystemZ/systemz-inline-asm.c (+1-1) 
- (modified) clang/test/CodeGen/X86/ms-x86-intrinsics.c (+2-2) 
- (modified) clang/test/CodeGen/arm-cmse-attr.c (+2-2) 
- (modified) clang/test/CodeGen/arm-vfp16-arguments.c (+1-1) 
- (modified) clang/test/CodeGen/arm-vfp16-arguments2.cpp (+5-5) 
- (modified) clang/test/CodeGen/attr-counted-by-pr110385.c (+18-9) 
- (modified) clang/test/CodeGen/attr-counted-by.c (+138-138) 
- (modified) clang/test/CodeGen/isfpclass.c (+1-1) 
- (modified) clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c (+9-9) 
- (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+7-7) 
- (modified) clang/test/CodeGen/mips-vector-return.c (+3-3) 
- (modified) clang/test/CodeGen/mips64-nontrivial-return.cpp (+1-1) 
- (modified) clang/test/CodeGen/ms-intrinsics-other.c (+38-38) 
- (modified) clang/test/CodeGen/ms-intrinsics.c (+153-153) 
- (modified) clang/test/CodeGen/nofpclass.c (+2-2) 
- (modified) clang/test/CodeGen/sanitize-metadata-nosanitize.c (+21-4) 
- (modified) clang/test/CodeGen/struct-copy.c (+1-1) 
- (modified) clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp (+1-1) 
- (modified) clang/test/CodeGen/transparent-union-type.c (+3-3) 
- (modified) clang/test/CodeGen/union-tbaa1.c (+1-1) 
- (modified) clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu (+11-11) 
- (modified) clang/test/CodeGenCXX/bitfield-ir.cpp (+6-6) 
- (modified) clang/test/CodeGenCXX/inline-then-fold-variadics.cpp (+16-16) 
- (modified) clang/test/CodeGenCXX/noescape.cpp (+15-15) 
- (modified) clang/test/CodeGenCXX/wasm-args-returns.cpp (+1-1) 
- (modified) clang/test/CodeGenHLSL/inline-functions.hlsl (+1-1) 
- (modified) clang/test/CodeGenObjC/noescape.m (+13-13) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl (+12-12) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-call-kernel.cl (+1-1) 
- (modified) 
clang/test/CodeGenOpenCL/atomic-builtins-default-to-device-scope.cl (+34-34) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl (+7-6) 
- (modified) clang/test/CodeGenOpenCL/kernel-param-alignment.cl (+6-6) 
- (modified) clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl (+7-7) 
- (modified) clang/test/CodeGenOpenCL/preserve_vec3.cl (+9-9) 
- (modified) clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp (+1-1) 
- (modified) clang/test/OpenMP/barrier_codegen.cpp (+1-1) 
- (modified) clang/test/OpenMP/bug54082.c (+8-8) 
- (modified) llvm/docs/LangRef.rst (+8-26) 
- (modified) llvm/docs/ReleaseNotes.md (+2) 
- (modified) llvm/include/llvm/AsmParser/LLToken.h (+2-1) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+8-7) 
- (modified) llvm/include/llvm/IR/Attributes.h (+1) 
- (modified) llvm/include/llvm/IR/Attributes.td (-3) 
- (modified) llvm/include/llvm/IR/InstrTypes.h (+5-7) 
- (modified) llvm/include/llvm/Support/ModRef.h (+17) 
- (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+7-3) 
- (modified) llvm/lib/AsmParser/LLLexer.cpp (+1) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+6) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+12-3) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (-2) 
- (modified) llvm/lib/IR/Attributes.cpp (+4-1) 
- (modified) llvm/lib/IR/Function.cpp (+1-1) 
- (modified) llvm/lib/IR/Instructions.cpp (+19) 
- (modified) llvm/lib/Target/DirectX/DXILPrepare.cpp (-1) 
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+2-2) 
- (modified) llvm/lib/Transform

[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

2025-01-16 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/112792

>From 802764e879862541e205ba1a070824b71d2fef9a Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Thu, 17 Oct 2024 17:31:24 -0500
Subject: [PATCH 01/17] [emacs][clang-format] Add elisp API for clang-format on
 git diffs

New proposed function `clang-format-git-diffs`.

It is the same as calling `clang-format-region` on all diffs between
the content of a buffer-file and the content of the file at git
revision HEAD. This is essentially the same thing as:
`git-clang-format -f {filename}`
If the current buffer is saved.

The motivation is many project (LLVM included) both have code that is
non-compliant with there clang-format style and disallow unrelated
format diffs in PRs. This means users can't just run
`clang-format-buffer` on the buffer they are working on, and need to
manually go through all the regions by hand to get them
formatted. This is both an error prone and annoying workflow.
---
 clang/tools/clang-format/clang-format.el | 159 ---
 1 file changed, 144 insertions(+), 15 deletions(-)

diff --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index fb943b7b722f8a..d3f874de41c550 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -146,18 +146,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ 
coding."
 (lambda (byte &optional _quality _coding-system)
   (byte-to-position (1+ byte)
 
-;;;###autoload
-(defun clang-format-region (start end &optional style assume-file-name)
-  "Use clang-format to format the code between START and END according to 
STYLE.
-If called interactively uses the region or the current statement if there is no
-no active region. If no STYLE is given uses `clang-format-style'. Use
-ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given
-uses the function `buffer-file-name'."
-  (interactive
-   (if (use-region-p)
-   (list (region-beginning) (region-end))
- (list (point) (point
-
+(defun clang-format--git-diffs-get-diff-lines (file-orig file-new)
+  "Return all line regions that contain diffs between FILE-ORIG and
+FILE-NEW.  If there is no diff 'nil' is returned. Otherwise the
+return is a 'list' of lines in the format '--lines=:'
+which can be passed directly to 'clang-format'"
+  ;; Temporary buffer for output of diff.
+  (with-temp-buffer
+(let ((status (call-process
+   "diff"
+   nil
+   (current-buffer)
+   nil
+   ;; Binary diff has different behaviors that we
+   ;; aren't interested in.
+   "-a"
+   ;; Printout changes as only the line groups.
+   "--changed-group-format=--lines=%dF:%dL "
+   ;; Ignore unchanged content.
+   "--unchanged-group-format="
+   file-orig
+   file-new
+   )
+  )
+  (stderr (concat (if (zerop (buffer-size)) "" ": ")
+  (buffer-substring-no-properties
+   (point-min) (line-end-position)
+  (when (stringp status)
+(error "(diff killed by signal %s%s)" status stderr))
+  (unless (= status 0)
+(unless (= status 1)
+  (error "(diff returned unsuccessfully %s%s)" status stderr)))
+
+
+  (if (= status 0)
+  ;; Status == 0 -> no Diff.
+  nil
+(progn
+  ;; Split "--lines=:... --lines=:" output to
+  ;; a list for return.
+  (s-split
+   " "
+   (string-trim
+(buffer-substring-no-properties
+ (point-min) (point-max)
+
+(defun clang-format--git-diffs-get-git-head-file ()
+  "Returns a temporary file with the content of 'buffer-file-name' at
+git revision HEAD. If the current buffer is either not a file or not
+in a git repo, this results in an error"
+  ;; Needs current buffer to be a file
+  (unless (buffer-file-name)
+(error "Buffer is not visiting a file"))
+  ;; Need to be able to find version control (git) root
+  (unless (vc-root-dir)
+(error "File not known to git"))
+  ;; Need version control to in fact be git
+  (unless (string-equal (vc-backend (buffer-file-name)) "Git")
+(error "Not using git"))
+
+  (let ((tmpfile-git-head (make-temp-file 
"clang-format-tmp-git-head-content")))
+;; Get filename relative to git root
+(let ((git-file-name (substring
+  (expand-file-name (buffer-file-name))
+  (string-width (expand-file-name (vc-root-dir)))
+  nil)))
+  (let ((status (call-process
+ "git"
+ nil
+ `(:file, tmpfile-git-head)
+ nil
+ "show" (concat "HEAD:" git-file-nam

[libclc] [libclc] Move smoothstep to CLC and optimize its codegen (PR #123183)

2025-01-16 Thread Fraser Cormack via cfe-commits

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


[libclc] b7e2014 - [libclc] Move smoothstep to CLC and optimize its codegen (#123183)

2025-01-16 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-01-16T11:44:09Z
New Revision: b7e20147ad7c29f9624d2a071bd348a7acd63461

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

LOG: [libclc] Move smoothstep to CLC and optimize its codegen (#123183)

This commit moves the implementation of the smoothstep function to the
CLC library, whilst optimizing the codegen.

This commit also adds support for 'half' versions of smoothstep, which
were previously missing.

The CLC smoothstep implementation now keeps everything in vectors,
rather than recursively splitting vectors by half down to the scalar
base form. This should result in more optimal codegen across the board.

This commit also removes some non-standard overloads of smoothstep with
mixed types, such as 'double smoothstep(float, float, float)'. There
aren't any mixed-(element )type versions of smoothstep as far as I can
see:

gentype smoothstep(gentype edge0, gentype edge1, gentype x)
gentypef smoothstep(float edge0, float edge1, gentypef x)
gentyped smoothstep(double edge0, double edge1, gentyped x)
gentypeh smoothstep(half edge0, half edge1, gentypeh x)

The CLC library only defines the first type, for simplicity; the OpenCL
layer is responsible for handling the scalar/scalar/vector forms. Note
that the scalar/scalar/vector forms now splat the scalars to the vector
type, rather than recursively split vectors as before. The macro that
used to 'vectorize' smoothstep in this way has been moved out of the
shared clcmacro.h header as it was only used for the smoothstep builtin.

Note that the CLC clamp function is now built for both SPIR-V targets.
This is to help build the CLC smoothstep function for the Mesa SPIR-V
target.

Added: 
libclc/clc/include/clc/common/clc_smoothstep.h
libclc/clc/include/clc/common/clc_smoothstep.inc
libclc/clc/lib/generic/common/clc_smoothstep.cl

Modified: 
libclc/clc/include/clc/clcmacro.h
libclc/clc/include/clc/shared/clc_clamp.h
libclc/clc/lib/clspv/SOURCES
libclc/clc/lib/generic/SOURCES
libclc/clc/lib/spirv/SOURCES
libclc/clc/lib/spirv64/SOURCES
libclc/generic/lib/common/smoothstep.cl

Removed: 




diff  --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index c6583749eca661..3c3a69f4f848bb 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -102,29 +102,6 @@
   FUNCTION(x.hi, y.hi, z.hi)); 
\
   }
 
-#define _CLC_V_S_S_V_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE,
\
-   ARG2_TYPE, ARG3_TYPE)   
\
-  DECLSPEC RET_TYPE##2 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##2 z) {
\
-return (RET_TYPE##2)(FUNCTION(x, y, z.lo), FUNCTION(x, y, z.hi));  
\
-  }
\
-   
\
-  DECLSPEC RET_TYPE##3 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##3 z) {
\
-return (RET_TYPE##3)(FUNCTION(x, y, z.x), FUNCTION(x, y, z.y), 
\
- FUNCTION(x, y, z.z)); 
\
-  }
\
-   
\
-  DECLSPEC RET_TYPE##4 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##4 z) {
\
-return (RET_TYPE##4)(FUNCTION(x, y, z.lo), FUNCTION(x, y, z.hi));  
\
-  }
\
-   
\
-  DECLSPEC RET_TYPE##8 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##8 z) {
\
-return (RET_TYPE##8)(FUNCTION(x, y, z.lo), FUNCTION(x, y, z.hi));  
\
-  }
\
-   
\
-  DECLSPEC RET_TYPE##16 FUNCTION(ARG1_TYPE x, ARG2_TYPE y, ARG3_TYPE##16 z) {  
\
-return (RET_TYPE##16)(FUNCTION(x, y, z.lo), FUNCTION(x, y, z.hi)); 
\
-  }
-
 #define _CLC_V_V_VP_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE, 
\
   ADDR_SPACE, ARG2_TYPE)   
\
   DECLSPEC __CLC_XCONCAT(RET_TYPE, 2)  
\

diff  --git a/libclc/clc/include/clc/common/clc_smoothstep.h 
b/libclc/clc/include/clc/common/clc_smoothstep.h
new file mode 100644
index 00..fa212245e07946
--- /dev/null
+++ b/libclc/clc/include/clc/common/clc_smoothstep.h
@@ -0,0 +1,11 @@
+#ifndef __CLC_COMMON_CLC_SMOOTHSTEP_H__
+#define

[clang] [Clang] Deprecate __is_referenceable (PR #123185)

2025-01-16 Thread via cfe-commits

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

LGTM

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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (PR #123193)

2025-01-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang-driver

Author: Chyaka (liliumShade)


Changes

XiangShan-KunMingHu is the third generation of Open-source high-performance 
RISC-V processor developed by Beijing Institute of Open Source Chip (BOSC) , 
and its latest version is V2R2.

The KunMingHu manual is now available at 
https://github.com/OpenXiangShan/XiangShan-User-Guide/releases.
It will be updated on the official XiangShan documentation site: 
https://docs.xiangshan.cc/zh-cn/latest

You can find the corresponding ISA extension from the XiangShan Github 
repository: 
https://github.com/OpenXiangShan/XiangShan/blob/master/src/main/scala/xiangshan/Parameters.scala

If you want to track the latest performance data of KunMingHu, please check 
XiangShan Biweekly: https://docs.xiangshan.cc/zh-cn/latest/blog

This PR adds the processor definition for KunMingHu V2R2, developed by the XSCC 
team https://github.com/orgs/OpenXiangShan/teams/xscc.

The scheduling model for XiangShan-KunMingHu V2R2 will be submitted in a 
subsequent PR.

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


4 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+47) 
- (modified) clang/test/Misc/target-invalid-cpu-note/riscv.c (+2) 
- (modified) llvm/docs/ReleaseNotes.md (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+31) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index e97b6940662d9f..b9b27eec61c6f3 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,53 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zic64b" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbop" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ziccif" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicclsm" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ziccrse" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicntr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicond" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zacas" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zfh" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zks" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvfh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl128b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smcsrind"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smdbltrp"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smmpm"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smnpm"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smrnmi"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+smstateen"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+sscsrind"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ssdbltrp"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+sspm"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ssstrict"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "-zawrs" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "-ziccamoa" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "-zihintntl" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-abi" "lp64d"
+
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=spacemit-x60 | FileCheck 
-check-prefix=MCPU-SPACEMIT-X60 %s
 // MCPU-SPACEMIT-X60: "-nostdsysteminc" "-target-cpu" "spacemit-x60"
 // MCPU-SPACEMIT-X60-SAME: "-target

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (PR #123193)

2025-01-16 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/123193
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits

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

LGTM

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


[clang] [llvm] [Pipelines] Move IPSCCP after inliner pipeline (PR #96620)

2025-01-16 Thread via cfe-commits

sihuan wrote:

@joshua-arch1 
I tested this patch on LTO and it is consistent with what you describe. 
With the `-flto` option enabled is that `digits_2` has two specializations 
whether the patch is applied or not.
However with LTO enabled, LLVM performance is comparable to GCC (in terms of 
number of instructions ). Here are some figures:
> on x86_64 ArchLinux
> via `perf stat ./exchange2_r 0`

| Compiler | Instructions |
|||
| gfortran  O3 (archlinux gcc-fortran 14.2.1+r134+gab884fffe3fc-2)| 
54,865,827,741 |
| gfortran  O3 lto (archlinux gcc-fortran 14.2.1+r134+gab884fffe3fc-2)| 
54,186,161,980 |
| flang O3 (#62d44fbd) | 107,953,750,439  |
| flang O3 lto (#62d44fbd) | 53,391,922,257  |
| flang O3 (patched #62d44fbd) | 53,146,581,727 |
| flang O3 lto (patched #62d44fbd) | 53,391,760,016 |

When using LTO, I don't think there is a problem that performance is worse than 
GCC, so this patch is not specific to LTO.


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


[clang] [flang] Revert "Revert "[Flang][Driver] Add a flag to control zero initializa… (PR #123097)

2025-01-16 Thread via cfe-commits

jeanPerier wrote:

+1 with @tarunprabhu testing suggestion. I am not opposed adding the flag to 
bbc, but it should really not be the root cause of the issue.

In the failing log, you can see that semantics mistook `y(1)` for a call ( the 
FIR output contains a `fir.call @_QPy(%0)`). This indeed indicates that 
something likely went wrong with the module file and that `y` was not read from 
it as expected. So it doe not look like a random setting of the 
`InitGlobalZero` issue, but a module file issue. I have no idea why your patch 
exposed it. I am guessing it may already have randomly failed and we do not 
know it because no flang committers had done a patch at the same time, so 
nobody probably investigated it.

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


[clang] [Clang][AArch64]Make Tuple Size Optional for svluti4_lane Intrinsics (PR #123197)

2025-01-16 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov approved this pull request.


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


[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

2025-01-16 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

> I see also some problems in test cases

@VyacheslavLevytskyy the SPIRV test case failures are not related to my change. 
They are also failing on main.

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

cor3ntin wrote:

Agreed actually, thanks

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


[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

2025-01-16 Thread Vyacheslav Levytskyy via cfe-commits

VyacheslavLevytskyy wrote:

> > I see also some problems in test cases
> 
> @VyacheslavLevytskyy the SPIRV test case failures are not related to my 
> change. They are also failing on main.

I will check now. For one the reason is clear, 
https://github.com/llvm/llvm-project/pull/123191

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits


@@ -3159,13 +3164,36 @@ Attr *ASTRecordReader::readAttr() {
   return New;
 }
 
-/// Reads attributes from the current stream position.
-void ASTRecordReader::readAttributes(AttrVec &Attrs) {
+/// Reads attributes from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+void ASTRecordReader::readAttributes(AttrVec &Attrs, Decl *D) {
   for (unsigned I = 0, E = readInt(); I != E; ++I)
-if (auto *A = readAttr())
+if (auto *A = readOrDeferAttrFor(D))
   Attrs.push_back(A);
 }
 
+
+/// Reads one attribute from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+Attr *ASTRecordReader::readOrDeferAttrFor(Decl *D) {
+  AttrReader Record(*this);
+  unsigned SkipCount = Record.readInt();
+  if (!SkipCount)
+return readAttr();

VitaNuo wrote:

Makes sense! However, I also had to reorder the fields to write the attribute 
kind before the skip count, since some code paths depend on reading the 
(absent) attribute kind first and exiting the `readAtrr` function.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/122726

>From b61110999596363bafdc94904356840febfcfaa5 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Tue, 14 Jan 2025 14:00:48 +0100
Subject: [PATCH 1/5] [WIP][Modules] Delay deserialization of preferred_name
 attribute at record level.

---
 clang/include/clang/Serialization/ASTReader.h | 18 
 .../clang/Serialization/ASTRecordReader.h | 10 ++
 clang/lib/Serialization/ASTReader.cpp |  5 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 91 ++-
 clang/lib/Serialization/ASTWriter.cpp | 19 +++-
 clang/test/Modules/preferred_name.cppm| 12 ++-
 6 files changed, 142 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 9f978762a6fb6b..4fd51eabe701ba 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1205,6 +1205,23 @@ class ASTReader
   /// been completed.
   std::deque PendingDeclContextInfos;
 
+  /// Deserialization of some attributes must be deferred since they refer
+  /// to themselves in their type (e.g., preferred_name attribute refers to the
+  /// typedef that refers back to the template specialization of the template
+  /// that the attribute is attached to).
+  /// More attributes that store TypeSourceInfo might be potentially affected,
+  /// see https://github.com/llvm/llvm-project/issues/56490 for details.
+  struct DeferredAttribute {
+uint64_t RecordIdx;
+// Decl to attach a deferred attribute to.
+Decl *ParentDecl;
+  };
+
+  /// The collection of Decls that have been loaded but some of their 
attributes
+  /// have been deferred, paired with the index inside the record pointing
+  /// at the skipped attribute.
+  SmallVector PendingDeferredAttributes;
+
   template 
   using DuplicateObjCDecls = std::pair;
 
@@ -1551,6 +1568,7 @@ class ASTReader
   void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
   void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
   unsigned PreviousGeneration = 0);
+  void loadDeferredAttribute(const DeferredAttribute &DA);
 
   RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
   uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h 
b/clang/include/clang/Serialization/ASTRecordReader.h
index 2561418b78ca7f..b1572ecef9028c 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -337,6 +337,12 @@ class ASTRecordReader
   /// Reads attributes from the current stream position, advancing Idx.
   void readAttributes(AttrVec &Attrs);
 
+  /// Reads one attribute from the current stream position, advancing Idx.
+  Attr *readOrDeferAttr(Decl *D);
+
+  /// Reads attributes from the current stream position, advancing Idx.
+  void readOrDeferAttributes(AttrVec &Attrs, Decl *D);
+
   /// Read an BTFTypeTagAttr object.
   BTFTypeTagAttr *readBTFTypeTagAttr() {
 return cast(readAttr());
@@ -355,6 +361,10 @@ class ASTRecordReader
   SwitchCase *getSwitchCaseWithID(unsigned ID) {
 return Reader->getSwitchCaseWithID(ID);
   }
+
+private:
+  Attr *readOrDeferAttrImpl(Decl *D);
+  void readOrDeferAttributesImpl(AttrVec &Attrs, Decl *D);
 };
 
 /// Helper class that saves the current stream position and
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b53f99732cacce..57d1d4d696290d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();
+
 // For each decl chain that we wanted to complete while deserializing, mark
 // it as "still needs to be completed".
 for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index dee5169ae5723a..043bed8dc7f382 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -612,7 +612,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 
   if (HasAttrs) {
 AttrVec Attrs;
-Record.readAttributes(Attrs);
+Record.readOrDeferAttributes(Attrs, D);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
@@ -3118,13 +3118,18 @@ class AttrReader {
 return Reader.readVersionTuple();
   }
 
+  void skipInts(unsigned N) { Reader.skipInts(N); }
+
+

[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits


@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();

VitaNuo wrote:

Thanks. The original snippet seems more concise though, so it might be 
preferable to stick to it for now. 

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


[clang] [Clang][AArch64]Make Tuple Size Optional for svluti4_lane Intrinsics (PR #123197)

2025-01-16 Thread via cfe-commits

https://github.com/CarolineConcatto created 
https://github.com/llvm/llvm-project/pull/123197

The svluti4_lane intrinsic currently requires the tuple size to be specified in 
the intrinsic name when using a tuple type input.

According to the ACLE specification, the svluti4_lane intrinsic with a tuple 
type input, such as:

svint16_t svluti4_lane[_s16_x2(svint16x2_t table, svuint8_t indices, uint64_t 
imm_idx);

should allow the tuple size of the input type to be optional.

>From 632e1fbd6b429e276c4f289599631fb431b50ce5 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Thu, 16 Jan 2025 12:52:45 +
Subject: [PATCH] [Clang][AArch64]Make Tuple Size Optional for svluti4_lane
 Intrinsics

The svluti4_lane intrinsic currently requires the tuple size to be specified
in the intrinsic name when using a tuple type input.

According to the ACLE specification, the svluti4_lane intrinsic with a tuple
type input, such as:

svint16_t svluti4_lane[_s16_x2(svint16x2_t table, svuint8_t indices, uint64_t 
imm_idx);

should allow the tuple size of the input type to be optional.
---
 clang/include/clang/Basic/arm_sve.td  |   4 +-
 .../AArch64/sve2-intrinsics/acle_sve2_luti.c  |  36 ++--
 .../acle_sve2_imm_lane.cpp| 194 +-
 3 files changed, 117 insertions(+), 117 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 47f1754aeb6299..ac1c139b209434 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1954,13 +1954,13 @@ let SVETargetGuard = "sve2,lut", SMETargetGuard = 
"sme2,lut" in {
   def SVLUTI4_B : SInst<"svluti4_lane[_{d}]", "dd[i", "cUc", MergeNone, 
"aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_1>]>;
   def SVLUTI4_H : SInst<"svluti4_lane[_{d}]", "dd[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
 
-  def SVLUTI4_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane_x2", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
+  def SVLUTI4_x2 : SInst<"svluti4_lane[_{d}_x2]", "d2.d[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane_x2", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
 }
 
 let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = "sme2,lut,bf16" in {
   def SVLUTI2_BF16 : SInst<"svluti2_lane[_{d}]", "dd[i", "b", MergeNone, 
"aarch64_sve_luti2_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_BF16 : SInst<"svluti4_lane[_{d}]", "dd[i", "b", MergeNone, 
"aarch64_sve_luti4_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
-  def SVLUTI4_BF16_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "b", 
MergeNone, "aarch64_sve_luti4_lane_x2", [ VerifyRuntimeMode], [ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_BF16_x2 : SInst<"svluti4_lane[_{d}_x2]", "d2.d[i", "b", 
MergeNone, "aarch64_sve_luti4_lane_x2", [ VerifyRuntimeMode], [ImmCheck<2, 
ImmCheck0_3>]>;
 }
 
 

diff --git a/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c 
b/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
index 4b3f97d13c7eb1..82e318a7460c20 100644
--- a/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
+++ b/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
@@ -19,9 +19,9 @@
 
 #ifdef SVE_OVERLOADED_FORMS
 // A simple used,unused... macro, long enough to represent any SVE builtin.
-#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
 #else
-#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
 #endif
 
 // SME-CHECK-LABEL: @test_svluti2_lane_s8(
@@ -39,7 +39,7 @@
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint8_t test_svluti2_lane_s8(svint8_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_s8,)(table, indices, 0);
+return SVE_ACLE_FUNC(svluti2_lane,_s8)(table, indices, 0);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_u8(
@@ -57,7 +57,7 @@ svint8_t test_svluti2_lane_s8(svint8_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svuint8_t test_svluti2_lane_u8(svuint8_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_u8,)(table, indices, 3);
+return SVE_ACLE_FUNC(svluti2_lane,_u8)(table, indices, 3);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_s16(
@@ -75,7 +75,7 @@ svuint8_t test_svluti2_lane_u8(svuint8_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint16_t test_svluti2_lane_s16(svint16_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_s16,)(table, indices, 0);
+return SVE_ACLE_FUNC(svluti2_lane,_s16)(table, indices, 0);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_u16(
@@ -93,7 +93,7 @@ svint16_t test_svluti2_lane_s16(svint16_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svuint16_t test_sv

[clang] [Clang][AArch64]Make Tuple Size Optional for svluti4_lane Intrinsics (PR #123197)

2025-01-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (CarolineConcatto)


Changes

The svluti4_lane intrinsic currently requires the tuple size to be specified in 
the intrinsic name when using a tuple type input.

According to the ACLE specification, the svluti4_lane intrinsic with a tuple 
type input, such as:

svint16_t svluti4_lane[_s16_x2(svint16x2_t table, svuint8_t indices, uint64_t 
imm_idx);

should allow the tuple size of the input type to be optional.

---

Patch is 33.25 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123197.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+2-2) 
- (modified) clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c 
(+18-18) 
- (modified) clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_imm_lane.cpp 
(+97-97) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 47f1754aeb6299..ac1c139b209434 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1954,13 +1954,13 @@ let SVETargetGuard = "sve2,lut", SMETargetGuard = 
"sme2,lut" in {
   def SVLUTI4_B : SInst<"svluti4_lane[_{d}]", "dd[i", "cUc", MergeNone, 
"aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_1>]>;
   def SVLUTI4_H : SInst<"svluti4_lane[_{d}]", "dd[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
 
-  def SVLUTI4_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane_x2", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
+  def SVLUTI4_x2 : SInst<"svluti4_lane[_{d}_x2]", "d2.d[i", "sUsh", MergeNone, 
"aarch64_sve_luti4_lane_x2", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
 }
 
 let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = "sme2,lut,bf16" in {
   def SVLUTI2_BF16 : SInst<"svluti2_lane[_{d}]", "dd[i", "b", MergeNone, 
"aarch64_sve_luti2_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_BF16 : SInst<"svluti4_lane[_{d}]", "dd[i", "b", MergeNone, 
"aarch64_sve_luti4_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>;
-  def SVLUTI4_BF16_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "b", 
MergeNone, "aarch64_sve_luti4_lane_x2", [ VerifyRuntimeMode], [ImmCheck<2, 
ImmCheck0_3>]>;
+  def SVLUTI4_BF16_x2 : SInst<"svluti4_lane[_{d}_x2]", "d2.d[i", "b", 
MergeNone, "aarch64_sve_luti4_lane_x2", [ VerifyRuntimeMode], [ImmCheck<2, 
ImmCheck0_3>]>;
 }
 
 

diff --git a/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c 
b/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
index 4b3f97d13c7eb1..82e318a7460c20 100644
--- a/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
+++ b/clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_luti.c
@@ -19,9 +19,9 @@
 
 #ifdef SVE_OVERLOADED_FORMS
 // A simple used,unused... macro, long enough to represent any SVE builtin.
-#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
 #else
-#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
 #endif
 
 // SME-CHECK-LABEL: @test_svluti2_lane_s8(
@@ -39,7 +39,7 @@
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint8_t test_svluti2_lane_s8(svint8_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_s8,)(table, indices, 0);
+return SVE_ACLE_FUNC(svluti2_lane,_s8)(table, indices, 0);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_u8(
@@ -57,7 +57,7 @@ svint8_t test_svluti2_lane_s8(svint8_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svuint8_t test_svluti2_lane_u8(svuint8_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_u8,)(table, indices, 3);
+return SVE_ACLE_FUNC(svluti2_lane,_u8)(table, indices, 3);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_s16(
@@ -75,7 +75,7 @@ svuint8_t test_svluti2_lane_u8(svuint8_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint16_t test_svluti2_lane_s16(svint16_t table, svuint8_t indices) MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_s16,)(table, indices, 0);
+return SVE_ACLE_FUNC(svluti2_lane,_s16)(table, indices, 0);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_u16(
@@ -93,7 +93,7 @@ svint16_t test_svluti2_lane_s16(svint16_t table, svuint8_t 
indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svuint16_t test_svluti2_lane_u16(svuint16_t table, svuint8_t indices) 
MODE_ATTR{
-return SVE_ACLE_FUNC(svluti2_lane,_u16,)(table, indices, 7);
+return SVE_ACLE_FUNC(svluti2_lane,_u16)(table, indices, 7);
 }
 
 // SME-CHECK-LABEL: @test_svluti2_lane_f16(
@@ -111,7 +111,7 @@ svuint16_t test_svluti2_lane_u16(svuint16_t table, 
svuint8_t indices) MODE_ATTR{
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svfloat16_t test_svluti2_lane_f16(svfloat16_t table, svuint8_t indices) 
MO

[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/120321

>From 1ad62a9a136a5ae80c880459472a88517afe75a4 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 17 Dec 2024 22:48:04 +0100
Subject: [PATCH 1/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

When building with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON with a recent
libstdc++ (e.g. from gcc 13.3.0) the testcase
clang/test/Misc/warning-flags-tree.c fail with the message:

+ diagtool tree --internal
.../include/c++/13.3.0/bits/stl_algo.h:2013:
In function:
_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator,
const _Tp &, _Compare) [_ForwardIterator = const
diagtool::DiagnosticRecord *, _Tp = diagtool::DiagnosticRecord, _Compare
= bool (*)(const diagtool::DiagnosticRecord &, const
diagtool::DiagnosticRecord &)]

Error: elements in iterator range [first, last) are not partitioned by the
predicate __comp and value __val.

Objects involved in the operation:
iterator "first" @ 0x7ffea8ef2fd8 {
}
iterator "last" @ 0x7ffea8ef2fd0 {
}

The reason for this error is that std::lower_bound is called on
BuiltinDiagnosticsByID without it being entirely sorted. Calling
std::lower_bound If the range is not sorted, the behavior of this
function is undefined. This is detected when building with expensive
checks.

To make BuiltinDiagnosticsByID sorted we need to slightly change the
order the inc-files are included.
---
 clang/tools/diagtool/DiagnosticNames.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/tools/diagtool/DiagnosticNames.cpp 
b/clang/tools/diagtool/DiagnosticNames.cpp
index eb90f082437b33..215087b9004959 100644
--- a/clang/tools/diagtool/DiagnosticNames.cpp
+++ b/clang/tools/diagtool/DiagnosticNames.cpp
@@ -23,15 +23,14 @@ llvm::ArrayRef 
diagtool::getBuiltinDiagnosticsByName() {
   return llvm::ArrayRef(BuiltinDiagnosticsByName);
 }
 
-
 // FIXME: Is it worth having two tables, especially when this one can get
 // out of sync easily?
+// clang-format off
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  
\
  SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) 
\
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
-#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
 #include "clang/Basic/DiagnosticSerializationKinds.inc"
@@ -39,12 +38,14 @@ static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #include "clang/Basic/DiagnosticParseKinds.inc"
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticCommentKinds.inc"
+#include "clang/Basic/DiagnosticCrossTUKinds.inc"
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
 #include "clang/Basic/DiagnosticInstallAPIKinds.inc"
 #undef DIAG
 };
+// clang-format on
 
 static bool orderByID(const DiagnosticRecord &Left,
   const DiagnosticRecord &Right) {

>From 4cedc90e9b26e5d48d53df463e8650d8a726e1d5 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 7 Jan 2025 15:59:16 +0100
Subject: [PATCH 2/3] [diagtool] Make the BuiltinDiagnosticsByID table sorted

Extracted the includes into a wrapper header file DiagnosticIDs.inc.
Added is_sorted assert.
---
 clang/include/clang/Basic/DiagnosticIDs.inc | 31 +
 clang/lib/Basic/DiagnosticIDs.cpp   | 48 ++---
 clang/tools/diagtool/DiagnosticNames.cpp| 23 --
 3 files changed, 42 insertions(+), 60 deletions(-)
 create mode 100644 clang/include/clang/Basic/DiagnosticIDs.inc

diff --git a/clang/include/clang/Basic/DiagnosticIDs.inc 
b/clang/include/clang/Basic/DiagnosticIDs.inc
new file mode 100644
index 00..69a7c03d39dff0
--- /dev/null
+++ b/clang/include/clang/Basic/DiagnosticIDs.inc
@@ -0,0 +1,31 @@
+//===--- DiagnosticIDs.inc --*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+///
+/// \file
+/// Defines the Diagnostic IDs in ID sorted order.
+///
+//===--===//
+
+// Turn off clang-format, as the order of the includes are important to make
+// sure the table is sorted.
+
+// clang-format off
+#include "clang/Basic/DiagnosticCommonKinds.inc"
+#include "clang/Basic/DiagnosticDriverKinds.inc"
+#include "clang/Basic/DiagnosticFrontendKinds.inc"
+#include "clang/Basic/DiagnosticSerializationKinds.inc"
+#include "cla

[clang] [Clang] Deprecate __is_referenceable (PR #123185)

2025-01-16 Thread Aaron Ballman via cfe-commits

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

LGTM but please add the details back to the commit message before landing 
(makes code archeology easier on us in the future).

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -83,6 +83,9 @@ class ASTRecordReader
   /// Returns the current value in this record, without advancing.
   uint64_t peekInt() { return Record[Idx]; }
 
+  /// Returns the next value in this record, without advancing.
+  uint64_t peekNextInt() { return Record[Idx + 1]; }

ChuanqiXu9 wrote:

```suggestion
  uint64_t peekInts(unsigned N) { return Record[Idx + N]; }
```
nit:

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


[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

2025-01-16 Thread Vyacheslav Levytskyy via cfe-commits

VyacheslavLevytskyy wrote:

> > > I see also some problems in test cases
> > 
> > 
> > @VyacheslavLevytskyy the SPIRV test case failures are not related to my 
> > change. They are also failing on main.
> 
> I will check now. For one the reason is clear, #123191

I can't reproduce two other fails on different environments, including actually 
Github Actions, so it maybe that after you rebase to `main` we will see all 
green now.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits

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

LGTM with nits.

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


[clang] [llvm] [Intrinsics][AArch64] Add intrinsic to mask off aliasing vector lanes (PR #117007)

2025-01-16 Thread Sam Tebbs via cfe-commits


@@ -567,6 +567,9 @@ std::string SDNode::getOperationName(const SelectionDAG *G) 
const {
   case ISD::EXPERIMENTAL_VECTOR_HISTOGRAM:
 return "histogram";
 
+  case ISD::EXPERIMENTAL_ALIAS_LANE_MASK:
+return "alias_mask";

SamTebbs33 wrote:

Done.

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits


@@ -3118,18 +3120,27 @@ class AttrReader {
 return Reader.readVersionTuple();
   }
 
+  void skipInts(unsigned N) { Reader.skipInts(N); }
+
+  unsigned getCurrentIdx() { return Reader.getIdx(); }
+
   OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); }
 
   template  T *readDeclAs() { return Reader.readDeclAs(); }
 };
 }
 
+/// Reads one attribute from the current stream position, advancing Idx.
 Attr *ASTRecordReader::readAttr() {
   AttrReader Record(*this);
   auto V = Record.readInt();
   if (!V)
 return nullptr;
 
+  // Read and ignore the skip count, since attribute deserialization is not
+  // deferred on this pass.
+  Record.readInt();

ChuanqiXu9 wrote:

nit: skipInt();

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Chuanqi Xu via cfe-commits

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


[clang] [diagtool] Make the BuiltinDiagnosticsByID table sorted (PR #120321)

2025-01-16 Thread kadir çetinkaya via cfe-commits

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

thanks!

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


[clang] [llvm] [Intrinsics][AArch64] Add intrinsic to mask off aliasing vector lanes (PR #117007)

2025-01-16 Thread Sam Tebbs via cfe-commits

SamTebbs33 wrote:

> If you want to upgrade the whilewr intrinsics (which I think sounds OK to 
> me), then it will need auto-update code something like in 
> https://github.com/llvm/llvm-project/pull/120363/files#diff-0c0305d510a076cef711c006c1d9fd78c95cade1f597d21ee46fd753e6982316.
>  It might be good to separate that out into a separate patch too, to keep 
> things managable.

Thanks for that. I've removed them and am no longer seeing the extra `xtn` 
instruction that I was before so it looks like those changes are actually 
unnecessary anyway!

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


[clang] [lldb] [AST] Add OriginalDC argument to ExternalASTSource::FindExternalVisibleDeclsByName (PR #123152)

2025-01-16 Thread Nikita Popov via cfe-commits

nikic wrote:

Compile-time looks fine on this one: 
https://llvm-compile-time-tracker.com/compare.php?from=8fb29ba287d72392bd7900c33d2a8d2149126dbe&to=fd734a392a094a573ee7fe587b9fc5f616f92a9a&stat=instructions:u

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


[clang] [lldb] [C++20] [Modules] Support module level lookup (PR #122887)

2025-01-16 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Looks like this change has some compile-time impact even if modules are not 
> used: 
> https://llvm-compile-time-tracker.com/compare.php?from=edc02351dd11cc4a39b7c541b26b71c6f36c8e55&to=7201cae106260aeb3e97d5291ff30f05076a&stat=instructions:u
>  It seems to add about 0.5% to C++ compilations.
> 
> cc @AaronBallman on the process here. I find it a bit concerning that big 
> changes get landed without approval to make it into the LLVM 20 release. This 
> is not how things are supposed to work.

We generally trust the maintainer's discretion but prefer there to be review 
before committing 
(https://llvm.org/docs/CodeReview.html#must-code-be-reviewed-prior-to-being-committed).
 In this case, @ChuanqiXu9 is the expert in the area and is the one who 
primarily reviews all modules patches anyway, so I'm inclined to trust his 
judgement.

> I want to land this in 20.x and give it some baking times so that we can find 
> issues in it if any.

FWIW, if we feel the need for it to have baking time, we usually would do that 
*after* the branch. (We get significant testing from community stakeholders 
like Google, Intel, etc because they pull from top of tree and test a bunch of 
their massive internal code bases on it.) If there are problems with the patch, 
pulling it out of the branch is more work and impacts folks like the release 
managers. If it were me, I probably would have waited to land this one, but I 
also don't think we need a process-related revert either.

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


[clang] [llvm] [Intrinsics][AArch64] Add intrinsic to mask off aliasing vector lanes (PR #117007)

2025-01-16 Thread Sam Tebbs via cfe-commits


@@ -2033,6 +2041,25 @@ bool 
AArch64TargetLowering::shouldExpandGetActiveLaneMask(EVT ResVT,
   return false;
 }
 
+bool AArch64TargetLowering::shouldExpandGetAliasLaneMask(

SamTebbs33 wrote:

It certainly can. Done.

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


[clang] [lldb] [C++20] [Modules] Support module level lookup (PR #122887)

2025-01-16 Thread Nikita Popov via cfe-commits

nikic wrote:

Thanks for the context! "I'm landing this without approval because I'm the 
maintainer for this component" is a lot less scary than "I'm landing this 
without approval because there's no time to wait on a review".

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


[clang] [clang] Emit @llvm.assume before streaming_compatible functions when the streaming mode is known (PR #121917)

2025-01-16 Thread Nicholas Guy via cfe-commits

NickGuy-Arm wrote:

> The assumption cache mechanism is used by a number of passes...

@efriedma-quic @aemerson ping



> I'm not sure it's correct to mark int_aarch64_sme_in_streaming_mode 
> IntrNoMem...

That's fair, I had mistakenly assumed `IntrNoMem` to mean "I don't touch 
memory". I'll put up a separate PR to change it to use `IntrReadMem` shortly.

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Sam Elliott via cfe-commits


@@ -1448,3 +1448,18 @@ def FeatureTaggedGlobals : 
SubtargetFeature<"tagged-globals",
 "AllowTaggedGlobals",
 "true", "Use an instruction sequence for taking the address of a global "
 "that allows a memory tag in the upper address bits">;
+
+def FeatureVendorMIPSCMove : SubtargetFeature<"xmipscmove", 
"HasVendorMIPSCMove",
+   "true", "Using CCMov",
+   [Feature64Bit]>;

lenary wrote:

It would be better if this and `def FeatureVendorMIPSLoadStorePairs` both used 
`RISCVExtension`. I think this means some changes to the functions on 
riscvsubtarget too, it should be clear to follow from the other vendor 
extensions. This will also have a knock-on effect on some other tests, 
especially relating to RISCVISAInfo (and also some in clang iirc), but this is 
for the better - it means the compiler can show it supports your extensions 😄 

Please may you also put these definitions beside the other vendor extensions, 
rather than at the end with these codegen options? The section starts somewhere 
around line 1020, and you'll see each vendor's extensions are with each other.

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Sam Elliott via cfe-commits




lenary wrote:

Please can you undo these whitespace changes, given you're not really making 
changes to this file

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Sam Elliott via cfe-commits

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Sam Elliott via cfe-commits

https://github.com/lenary commented:

Some small notes, the one about using RISCVExtension will probably have the 
most knock-on work (run both the llvm and the clang test suites after that 
change, to see where that info gets to)

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Jessica Clarke via cfe-commits


@@ -62,6 +62,15 @@ static cl::opt RISCVMinimumJumpTableEntries(
 "riscv-min-jump-table-entries", cl::Hidden,
 cl::desc("Set minimum number of entries to use a jump table on RISCV"));
 
+static cl::opt
+UseLoadStorePairsOpt("riscv-load-store-pairs",

jrtc27 wrote:

I worry that this name is going to get confused with Zilsd

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/122726

>From b61110999596363bafdc94904356840febfcfaa5 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Tue, 14 Jan 2025 14:00:48 +0100
Subject: [PATCH 1/7] [WIP][Modules] Delay deserialization of preferred_name
 attribute at record level.

---
 clang/include/clang/Serialization/ASTReader.h | 18 
 .../clang/Serialization/ASTRecordReader.h | 10 ++
 clang/lib/Serialization/ASTReader.cpp |  5 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 91 ++-
 clang/lib/Serialization/ASTWriter.cpp | 19 +++-
 clang/test/Modules/preferred_name.cppm| 12 ++-
 6 files changed, 142 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 9f978762a6fb6b..4fd51eabe701ba 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1205,6 +1205,23 @@ class ASTReader
   /// been completed.
   std::deque PendingDeclContextInfos;
 
+  /// Deserialization of some attributes must be deferred since they refer
+  /// to themselves in their type (e.g., preferred_name attribute refers to the
+  /// typedef that refers back to the template specialization of the template
+  /// that the attribute is attached to).
+  /// More attributes that store TypeSourceInfo might be potentially affected,
+  /// see https://github.com/llvm/llvm-project/issues/56490 for details.
+  struct DeferredAttribute {
+uint64_t RecordIdx;
+// Decl to attach a deferred attribute to.
+Decl *ParentDecl;
+  };
+
+  /// The collection of Decls that have been loaded but some of their 
attributes
+  /// have been deferred, paired with the index inside the record pointing
+  /// at the skipped attribute.
+  SmallVector PendingDeferredAttributes;
+
   template 
   using DuplicateObjCDecls = std::pair;
 
@@ -1551,6 +1568,7 @@ class ASTReader
   void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
   void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
   unsigned PreviousGeneration = 0);
+  void loadDeferredAttribute(const DeferredAttribute &DA);
 
   RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
   uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h 
b/clang/include/clang/Serialization/ASTRecordReader.h
index 2561418b78ca7f..b1572ecef9028c 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -337,6 +337,12 @@ class ASTRecordReader
   /// Reads attributes from the current stream position, advancing Idx.
   void readAttributes(AttrVec &Attrs);
 
+  /// Reads one attribute from the current stream position, advancing Idx.
+  Attr *readOrDeferAttr(Decl *D);
+
+  /// Reads attributes from the current stream position, advancing Idx.
+  void readOrDeferAttributes(AttrVec &Attrs, Decl *D);
+
   /// Read an BTFTypeTagAttr object.
   BTFTypeTagAttr *readBTFTypeTagAttr() {
 return cast(readAttr());
@@ -355,6 +361,10 @@ class ASTRecordReader
   SwitchCase *getSwitchCaseWithID(unsigned ID) {
 return Reader->getSwitchCaseWithID(ID);
   }
+
+private:
+  Attr *readOrDeferAttrImpl(Decl *D);
+  void readOrDeferAttributesImpl(AttrVec &Attrs, Decl *D);
 };
 
 /// Helper class that saves the current stream position and
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b53f99732cacce..57d1d4d696290d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();
+
 // For each decl chain that we wanted to complete while deserializing, mark
 // it as "still needs to be completed".
 for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index dee5169ae5723a..043bed8dc7f382 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -612,7 +612,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 
   if (HasAttrs) {
 AttrVec Attrs;
-Record.readAttributes(Attrs);
+Record.readOrDeferAttributes(Attrs, D);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
@@ -3118,13 +3118,18 @@ class AttrReader {
 return Reader.readVersionTuple();
   }
 
+  void skipInts(unsigned N) { Reader.skipInts(N); }
+
+

[clang] [Wunsafe-buffer-usage] Fix false positive when const sized array is indexed by const evaluatable expressions (PR #119340)

2025-01-16 Thread Nico Weber via cfe-commits

nico wrote:

This makes clang assert on many inputs. Here's a repro:

[repro.zip](https://github.com/user-attachments/files/18440860/repro.zip)

```
% ./input_file_parsers-161259.sh
...
Assertion failed: (!isValueDependent() && "Expression evaluator can't be called 
on a dependent expression."), function EvaluateAsInt, file ExprConstant.cpp, 
line 16671.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /Users/thakis/src/llvm-project/out/gn/bin/clang -cc1 
-triple x86_64-unknown-linux-gnu -emit-obj --crel -disable-free 
-clear-ast-before-backend -main-file-name input_file_parsers.cc 
-mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition 
-fmerge-all-constants -fno-delete-null-pointer-checks -mframe-pointer=all 
-relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases 
-funwind-tables=2 -target-cpu x86-64 -target-feature +sse3 -tune-cpu generic 
-debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb 
-ggnu-pubnames -gsimple-template-names=simple -mllvm -generate-arange-section 
-debug-forward-template-params -fdebug-compilation-dir=. -split-dwarf-file 
tmp.dwo -split-dwarf-output tmp.dwo -mllvm 
-crash-diagnostics-dir=../../tools/clang/crashreports -ffunction-sections 
-fdata-sections -fno-unique-section-names -fcoverage-compilation-dir=. 
-nostdinc++ -O2 -std=c++20 -fdeprecated-macro -ferror-limit 19 
-fvisibility=hidden -fvisibility-inlines-hidden -fwrapv -pthread 
-stack-protector 1 -ftrivial-auto-var-init=pattern -fno-rtti 
-fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf 
-fno-sized-deallocation -Qn -fcolor-diagnostics -vectorize-loops -vectorize-slp 
-fuse-ctor-homing -mllvm -instcombine-lower-dbg-declare=0 -mllvm 
-split-threshold-for-reg-with-hint=0 -fcomplete-member-pointers -faddrsig -x 
c++ input_file_parsers-161259.cpp -Wno-gnu-line-marker -Wunsafe-buffer-usage
1.   parser at end of file
```


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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits

https://github.com/VitaNuo updated 
https://github.com/llvm/llvm-project/pull/122726

>From b61110999596363bafdc94904356840febfcfaa5 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Tue, 14 Jan 2025 14:00:48 +0100
Subject: [PATCH 1/3] [WIP][Modules] Delay deserialization of preferred_name
 attribute at record level.

---
 clang/include/clang/Serialization/ASTReader.h | 18 
 .../clang/Serialization/ASTRecordReader.h | 10 ++
 clang/lib/Serialization/ASTReader.cpp |  5 +
 clang/lib/Serialization/ASTReaderDecl.cpp | 91 ++-
 clang/lib/Serialization/ASTWriter.cpp | 19 +++-
 clang/test/Modules/preferred_name.cppm| 12 ++-
 6 files changed, 142 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 9f978762a6fb6b..4fd51eabe701ba 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1205,6 +1205,23 @@ class ASTReader
   /// been completed.
   std::deque PendingDeclContextInfos;
 
+  /// Deserialization of some attributes must be deferred since they refer
+  /// to themselves in their type (e.g., preferred_name attribute refers to the
+  /// typedef that refers back to the template specialization of the template
+  /// that the attribute is attached to).
+  /// More attributes that store TypeSourceInfo might be potentially affected,
+  /// see https://github.com/llvm/llvm-project/issues/56490 for details.
+  struct DeferredAttribute {
+uint64_t RecordIdx;
+// Decl to attach a deferred attribute to.
+Decl *ParentDecl;
+  };
+
+  /// The collection of Decls that have been loaded but some of their 
attributes
+  /// have been deferred, paired with the index inside the record pointing
+  /// at the skipped attribute.
+  SmallVector PendingDeferredAttributes;
+
   template 
   using DuplicateObjCDecls = std::pair;
 
@@ -1551,6 +1568,7 @@ class ASTReader
   void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
   void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
   unsigned PreviousGeneration = 0);
+  void loadDeferredAttribute(const DeferredAttribute &DA);
 
   RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
   uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h 
b/clang/include/clang/Serialization/ASTRecordReader.h
index 2561418b78ca7f..b1572ecef9028c 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -337,6 +337,12 @@ class ASTRecordReader
   /// Reads attributes from the current stream position, advancing Idx.
   void readAttributes(AttrVec &Attrs);
 
+  /// Reads one attribute from the current stream position, advancing Idx.
+  Attr *readOrDeferAttr(Decl *D);
+
+  /// Reads attributes from the current stream position, advancing Idx.
+  void readOrDeferAttributes(AttrVec &Attrs, Decl *D);
+
   /// Read an BTFTypeTagAttr object.
   BTFTypeTagAttr *readBTFTypeTagAttr() {
 return cast(readAttr());
@@ -355,6 +361,10 @@ class ASTRecordReader
   SwitchCase *getSwitchCaseWithID(unsigned ID) {
 return Reader->getSwitchCaseWithID(ID);
   }
+
+private:
+  Attr *readOrDeferAttrImpl(Decl *D);
+  void readOrDeferAttributesImpl(AttrVec &Attrs, Decl *D);
 };
 
 /// Helper class that saves the current stream position and
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b53f99732cacce..57d1d4d696290d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10079,6 +10079,11 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
+// Load the delayed preferred name attributes.
+for (unsigned I = 0; I != PendingDeferredAttributes.size(); ++I)
+  loadDeferredAttribute(PendingDeferredAttributes[I]);
+PendingDeferredAttributes.clear();
+
 // For each decl chain that we wanted to complete while deserializing, mark
 // it as "still needs to be completed".
 for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index dee5169ae5723a..043bed8dc7f382 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -612,7 +612,7 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 
   if (HasAttrs) {
 AttrVec Attrs;
-Record.readAttributes(Attrs);
+Record.readOrDeferAttributes(Attrs, D);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
@@ -3118,13 +3118,18 @@ class AttrReader {
 return Reader.readVersionTuple();
   }
 
+  void skipInts(unsigned N) { Reader.skipInts(N); }
+
+

[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

cor3ntin wrote:

We can do that, right?

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

cor3ntin wrote:

```suggestion
  std::optional Tok =
  findNextTokenIncludingComments(Loc, SM, LangOpts);
```

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


[clang] [Sema] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123158)

2025-01-16 Thread Nikita Popov via cfe-commits

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


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


[clang] [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123157)

2025-01-16 Thread Nikita Popov via cfe-commits

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


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


[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123156)

2025-01-16 Thread Nikita Popov via cfe-commits

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


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


[clang] [Clang] Correct the order of substituted arguments in CTAD alias guides (PR #123022)

2025-01-16 Thread via cfe-commits

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


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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-16 Thread via cfe-commits


@@ -118,47 +118,19 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
   const LangOptions &LangOpts) {
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments=*/true);

cor3ntin wrote:

```suggestion
Tok = findNextTokenIncludingComments(Loc, SM, LangOpts);
```

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


[clang] fd4f94d - [Clang] Correct the order of substituted arguments in CTAD alias guides (#123022)

2025-01-16 Thread via cfe-commits

Author: Younan Zhang
Date: 2025-01-16T16:37:57+08:00
New Revision: fd4f94ddbf0c0f0c9d0185e6036fe51de5ab2ef3

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

LOG: [Clang] Correct the order of substituted arguments in CTAD alias guides 
(#123022)

We missed a case of type constraints referencing deduced template
parameters when constructing a deduction guide for the type alias. This
patch fixes the issue by swapping the order of constructing 'template
arguments not appearing in the type alias parameters' and 'template
arguments that are not yet deduced'.

Fixes https://github.com/llvm/llvm-project/issues/122134

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeductionGuide.cpp
clang/test/SemaTemplate/deduction-guide.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6ac91f43e66d8b..f6be841035db18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -950,6 +950,8 @@ Bug Fixes to C++ Support
 - Clang now identifies unexpanded parameter packs within the type constraint 
on a non-type template parameter. (#GH88866)
 - Fixed an issue while resolving type of expression indexing into a pack of 
values of non-dependent type (#GH121242)
 - Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in 
the trailing return type of the lambda (#GH121274)
+- Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
+  constraints are applied. (#GH122134)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index d42c3765aa534f..5f813ba3a597a3 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -996,7 +996,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   F->getTemplateParameters()->size());
 
   // FIXME: DeduceTemplateArguments stops immediately at the first
-  // non-deducible template argument. However, this doesn't seem to casue
+  // non-deducible template argument. However, this doesn't seem to cause
   // issues for practice cases, we probably need to extend it to continue
   // performing deduction for rest of arguments to align with the C++
   // standard.
@@ -1053,25 +1053,6 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
   }
   unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
-  //   ...followed by the template parameters of f that were not deduced
-  //   (including their default template arguments)
-  for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
-auto *TP = F->getTemplateParameters()->getParam(FTemplateParamIdx);
-MultiLevelTemplateArgumentList Args;
-Args.setKind(TemplateSubstitutionKind::Rewrite);
-// We take a shortcut here, it is ok to reuse the
-// TemplateArgsForBuildingFPrime.
-Args.addOuterTemplateArguments(TemplateArgsForBuildingFPrime);
-NamedDecl *NewParam = transformTemplateParameter(
-SemaRef, F->getDeclContext(), TP, Args, FPrimeTemplateParams.size(),
-getDepthAndIndex(TP).first);
-FPrimeTemplateParams.push_back(NewParam);
-
-assert(TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull() &&
-   "The argument must be null before setting");
-TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
-Context.getInjectedTemplateArg(NewParam);
-  }
 
   // To form a deduction guide f' from f, we leverage clang's instantiation
   // mechanism, we construct a template argument list where the template
@@ -1080,24 +1061,21 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
   // f, this ensures all template parameter occurrences are updated
   // correctly.
   //
-  // The template argument list is formed from the `DeducedArgs`, two parts:
-  //  1) appeared template parameters of alias: transfrom the deduced
-  //  template argument;
-  //  2) non-deduced template parameters of f: rebuild a
-  //  template argument;
+  // The template argument list is formed, in order, from
+  //   1) For the template parameters of the alias, the corresponding deduced
+  //  template arguments
+  //   2) For the non-deduced template parameters of f. the
+  //  (rebuilt) template arguments corresponding.
   //
-  // 2) has been built already (when rebuilding the new template
-  // parameters), we now perform 1).
+  // Note: the non-deduced template arguments of `f` might refer to arguments
+  // deduced in 1), as in a type constraint.
   MultiLevelTemplateArgumentList Args;
   Args.setKind(TemplateSubstitutionKind::Rewrite);
   Args.addOuterTemplateArg

[clang] [Clang] Correct the order of substituted arguments in CTAD alias guides (PR #123022)

2025-01-16 Thread Younan Zhang via cfe-commits

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


[clang] [Modules] Delay deserialization of preferred_name attribute at r… (PR #122726)

2025-01-16 Thread Viktoriia Bakalova via cfe-commits


@@ -3159,13 +3164,36 @@ Attr *ASTRecordReader::readAttr() {
   return New;
 }
 
-/// Reads attributes from the current stream position.
-void ASTRecordReader::readAttributes(AttrVec &Attrs) {
+/// Reads attributes from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+void ASTRecordReader::readAttributes(AttrVec &Attrs, Decl *D) {
   for (unsigned I = 0, E = readInt(); I != E; ++I)
-if (auto *A = readAttr())
+if (auto *A = readOrDeferAttrFor(D))
   Attrs.push_back(A);
 }
 
+
+/// Reads one attribute from the current stream position, advancing Idx.
+/// For some attributes (where type depends on itself recursively), defer
+/// reading the attribute until the type has been read.
+Attr *ASTRecordReader::readOrDeferAttrFor(Decl *D) {
+  AttrReader Record(*this);
+  unsigned SkipCount = Record.readInt();
+  if (!SkipCount)
+return readAttr();

VitaNuo wrote:

Ah nice idea. I didn't realize `peekInt()` is an option.

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-01-16 Thread Sharadh Rajaraman via cfe-commits

sharadhr wrote:

@ChuanqiXu9 are you able to have a look? 

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


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

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

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


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

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

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


[clang] 226a9d7 - Add documentation for Multilib custom flags (#114998)

2025-01-16 Thread via cfe-commits

Author: Victor Campos
Date: 2025-01-16T09:53:04Z
New Revision: 226a9d73eee1d36526428806c1204f82b2c1f6cd

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

LOG: Add documentation for Multilib custom flags (#114998)

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

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

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

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch updates the
documentation.

Added: 


Modified: 
clang/docs/Multilib.rst

Removed: 




diff  --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index 7637d0db9565b8..d36b73dce68cd9 100644
--- a/clang/docs/Multilib.rst
+++ b/clang/docs/Multilib.rst
@@ -122,6 +122,73 @@ subclass and a suitable base multilib variant is present 
then the
 It is the responsibility of layered multilib authors to ensure that headers and
 libraries in each layer are complete enough to mask any incompatibilities.
 
+Multilib custom flags
+=
+
+Introduction
+
+
+The multilib mechanism supports library variants that correspond to target,
+code generation or language command-line flags. Examples include ``--target``,
+``-mcpu``, ``-mfpu``, ``-mbranch-protection``, ``-fno-rtti``. However, some 
library
+variants are particular to features that do not correspond to any command-line
+option. Multithreading and semihosting, for instance, have no associated
+compiler option.
+
+In order to support the selection of variants for which no compiler option
+exists, the multilib specification includes the concept of *custom flags*.
+These flags have no impact on code generation and are only used in the multilib
+processing.
+
+Multilib custom flags follow this format in the driver invocation:
+
+::
+
+  -fmultilib-flag=
+
+They are fed into the multilib system alongside the remaining flags.
+
+Custom flag declarations
+
+
+Custom flags can be declared in the YAML file under the *Flags* section.
+
+.. code-block:: yaml
+
+  Flags:
+  - Name: multithreaded
+Values:
+- Name: no-multithreaded
+  MacroDefines: [__SINGLE_THREAD__]
+- Name: multithreaded
+Default: no-multithreaded
+
+* Name: the name to categorize a flag.
+* Values: a list of flag Values (defined below).
+* Default: it specifies the name of the value this flag should take if not
+  specified in the command-line invocation. It must be one value from the 
Values
+  field.
+
+Each flag *Value* is defined as:
+
+* Name: name of the value. This is the string to be used in
+  ``-fmultilib-flag=``.
+* MacroDefines: a list of strings to be used as macro definitions. Each string
+  is fed into the driver as ``-D``.
+
+The namespace of flag values is common across all flags. This means that flag
+value names must be unique.
+
+Usage of custom flags in the *Variants* specifications
+--
+
+Library variants should list their requirement on one or more custom flags like
+they do for any other flag. Each requirement must be listed as
+``-fmultilib-flag=``.
+
+A variant that does not specify a requirement on one particular flag can be
+matched against any value of that flag.
+
 Stability
 =
 
@@ -222,6 +289,23 @@ For a more comprehensive example see
 # Flags is a list of one or more strings.
 Flags: [--target=thumbv7m-none-eabi]
 
+  # Custom flag declarations. Each item is a 
diff erent declaration.
+  Flags:
+# Name of the flag
+  - Name: multithreaded
+# List of custom flag values
+Values:
+  # Name of the custom flag value. To be used in -fmultilib-flag=.
+- Name: no-multithreaded
+  # Macro definitions. Useful for defining extra macros for building the
+  # associated library variant(s).
+  MacroDefines: [__SINGLE_THREAD__]
+- Name: multithreaded
+# Default flag value. If no value for this flag declaration is used in the
+# command-line, the multilib system will use this one. Must be equal to one
+# of the flag value names from this flag declaration.
+Default: no-multithreaded
+
 Design principles
 =
 



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

[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Craig Topper via cfe-commits


@@ -0,0 +1,82 @@
+//===-- RISCVInstrInfoXMips.td -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file describes the vendor extensions defined by MIPS.
+//
+//===--===//
+
+//===--===//
+
+// MIPS extensions
+//===--===//
+
+let Predicates = [HasVendorMIPSCMove], hasSideEffects = 0, mayLoad = 0, 
mayStore = 0, DecoderNamespace = "Xmipscomve" in {
+def CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd),
+(ins GPR:$rs1, GPR:$rs2, GPR:$rs3),
+"mips.ccmov", "$rd, $rs2, $rs1, $rs3">,
+   Sched<[]>;
+}
+
+let Predicates = [HasVendorMIPSCMove] in {
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$rs2), (XLenVT 0))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$x), (XLenVT simm12_plus1:$y))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, (ADDI GPR:$x, (NegImm simm12_plus1:$y)), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, (XOR GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$rs2), (XLenVT 0))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$x), (XLenVT simm12_plus1:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (ADDI GPR:$x, (NegImm simm12_plus1:$y)), GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (XOR GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setuge (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLTU GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setge (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLT GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setle (XLenVT GPR:$y), (XLenVT GPR:$x))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLT GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT GPR:$rs2), (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+}
+
+let Predicates = [HasVendorMIPSLoadStorePairs], hasSideEffects = 0, 
DecoderNamespace = "Xmipslsp" in {
+def LWP : LWPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, 
uimm7_lsb00:$imm7),
+"mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">,
+Sched<[WriteLDW, WriteLDW, ReadMemBase]> {
+let mayLoad = 1;
+let mayStore = 0;
+}
+def LDP : LDPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, 
uimm7_lsb000:$imm7),
+"mips.ldp", "$rd1, $rd2, ${imm7}(${rs1})">,
+Sched<[WriteLDD, WriteLDD, ReadMemBase]> {
+let mayLoad = 1;
+let mayStore = 0;
+}
+def SWP : SWPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, 
uimm7_lsb00:$imm7),
+"mips.swp", "$rs2, $rs3, ${imm7}(${rs1})">,
+Sched<[WriteSTW, ReadStoreData, ReadStoreData, 
ReadMemBase]> {
+let mayLoad = 0;

topperc wrote:

Body should be indentede 2 spaces

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Craig Topper via cfe-commits


@@ -1448,3 +1448,18 @@ def FeatureTaggedGlobals : 
SubtargetFeature<"tagged-globals",
 "AllowTaggedGlobals",
 "true", "Use an instruction sequence for taking the address of a global "
 "that allows a memory tag in the upper address bits">;
+
+def FeatureVendorMIPSCMove : SubtargetFeature<"xmipscmove", 
"HasVendorMIPSCMove",
+   "true", "Using CCMov",
+   [Feature64Bit]>;
+def HasVendorMIPSCMove

topperc wrote:

I think I would rather see this split into `HasVendorMIPSCMove` for assembler, 
and `UseCCMovInsn` for isel patterns.

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Craig Topper via cfe-commits


@@ -1448,3 +1448,18 @@ def FeatureTaggedGlobals : 
SubtargetFeature<"tagged-globals",
 "AllowTaggedGlobals",
 "true", "Use an instruction sequence for taking the address of a global "
 "that allows a memory tag in the upper address bits">;
+
+def FeatureVendorMIPSCMove : SubtargetFeature<"xmipscmove", 
"HasVendorMIPSCMove",

topperc wrote:

FeatureVendorMIPSCMove -> FeatureVendorXMIPSCMove so it matches the name of the 
extension

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Craig Topper via cfe-commits


@@ -0,0 +1,82 @@
+//===-- RISCVInstrInfoXMips.td -*- tablegen 
-*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file describes the vendor extensions defined by MIPS.
+//
+//===--===//
+
+//===--===//
+
+// MIPS extensions
+//===--===//
+
+let Predicates = [HasVendorMIPSCMove], hasSideEffects = 0, mayLoad = 0, 
mayStore = 0, DecoderNamespace = "Xmipscomve" in {
+def CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd),
+(ins GPR:$rs1, GPR:$rs2, GPR:$rs3),
+"mips.ccmov", "$rd, $rs2, $rs1, $rs3">,
+   Sched<[]>;
+}
+
+let Predicates = [HasVendorMIPSCMove] in {
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$rs2), (XLenVT 0))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$x), (XLenVT simm12_plus1:$y))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, (ADDI GPR:$x, (NegImm simm12_plus1:$y)), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setne (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, (XOR GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$rs2), (XLenVT 0))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$x), (XLenVT simm12_plus1:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (ADDI GPR:$x, (NegImm simm12_plus1:$y)), GPR:$rs3)>;
+def : Pat<(select (XLenVT (seteq (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (XOR GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setuge (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLTU GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setge (XLenVT GPR:$x), (XLenVT GPR:$y))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLT GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT (setle (XLenVT GPR:$y), (XLenVT GPR:$x))),
+  (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)),
+  (CCMOV GPR:$rs1, (SLT GPR:$x, GPR:$y), GPR:$rs3)>;
+def : Pat<(select (XLenVT GPR:$rs2), (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)),
+  (CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
+}
+
+let Predicates = [HasVendorMIPSLoadStorePairs], hasSideEffects = 0, 
DecoderNamespace = "Xmipslsp" in {
+def LWP : LWPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, 
uimm7_lsb00:$imm7),
+"mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">,
+Sched<[WriteLDW, WriteLDW, ReadMemBase]> {
+let mayLoad = 1;
+let mayStore = 0;
+}
+def LDP : LDPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, 
uimm7_lsb000:$imm7),
+"mips.ldp", "$rd1, $rd2, ${imm7}(${rs1})">,
+Sched<[WriteLDD, WriteLDD, ReadMemBase]> {
+let mayLoad = 1;
+let mayStore = 0;
+}
+def SWP : SWPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, 
uimm7_lsb00:$imm7),
+"mips.swp", "$rs2, $rs3, ${imm7}(${rs1})">,
+Sched<[WriteSTW, ReadStoreData, ReadStoreData, 
ReadMemBase]> {
+let mayLoad = 0;
+let mayStore = 1;
+}
+def SDP : SDPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, 
uimm7_lsb000:$imm7),
+"mips.sdp", "$rs2, $rs3, ${imm7}(${rs1})">,
+Sched<[WriteSTD, ReadStoreData, ReadStoreData, 
ReadMemBase]> {
+let mayLoad = 0;

topperc wrote:

Body should be indented 2 spaces

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


[clang] [flang] Revert "Revert "[Flang][Driver] Add a flag to control zero initializa… (PR #123097)

2025-01-16 Thread Kiran Chandramohan via cfe-commits

kiranchandramohan wrote:

Thanks @jeanPerier @tarunprabhu. I have created 
https://github.com/llvm/llvm-project/pull/123215 to use a temporary directory 
for the test.

I will keep the bbc option in this patch as well.

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-16 Thread Craig Topper via cfe-commits


@@ -109,6 +109,21 @@ def uimm7_lsb00 : RISCVOp,
   }];
 }
 
+// A 7-bit unsigned immediate where the least significant three bits are zero.

topperc wrote:

This should be defned in Mips specific file if that's the only place it is used.

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


  1   2   3   4   5   >