[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Thank you for your patience! There are still a few comments not done from the 
previous round.

In D150083#4655528 , @owenpan wrote:

> See also D153228 .

Would this patch have a similar performance issue?




Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:73
+  Tok = Tok->Next;
+  if (!Tok->Next->is(tok::identifier)) {
+// If we hit any other kind of token, just bail. It's unusual/illegal.





Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:93
+  const auto SortOrderMax = Style.ObjCPropertyAttributeOrder.size();
+  const auto SortIndex = [&](const StringRef &Needle) -> unsigned {
+auto I = SortOrderMap.find(Needle);





Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:143
+const SourceManager &SourceMgr, const AdditionalKeywords &Keywords,
+tooling::Replacements &Fixes, const FormatToken *const Tok) const {
+  // Expect `property` to be the very next token or else just bail early.





Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:185
+
+for (const auto *Tok = First; Tok && Tok != Last && Tok->Next;
+ Tok = Tok->Next) {





Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:113
+
+  // Deduplicate the attributes.
+  Indices.erase(std::unique(Indices.begin(), Indices.end(),

jaredgrubb wrote:
> owenpan wrote:
> > Is it valid in Objective-C to have duplicate attributes?
> It's silly, but clang doesn't seem to care. I tried this, so duplicate was 
> ok, but contradiction was flagged:
> ```
> @property (strong, nonatomic, nonatomic) X *X;   // duplicate, but no error
> @property (strong, nonatomic, weak) Y *y;   // error: Property attributes 
> 'strong' and 'weak' are mutually exclusive
> ```
> 
> I wasn't sure whether to do this, but went that way since that's what "sort 
> include files" did. However, it seems like an odd corner case so I'd be ok 
> removing this uniquing if you prefer.
We should keep the duplicates if clang accepts them. What happens to e.g. 
`@property(x=a, y=b, x=a, y=c)`?



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:184
+  for (AnnotatedLine *Line : AnnotatedLines) {
+if (!Line->Affected || Line->InPPDirective)
+  continue;

jaredgrubb wrote:
> owenpan wrote:
> > Why not `InPPDirective`?
> I copy-pasted this from `LeftRightQualifierAlignmentFixer::analyze`, which I 
> used as a template since I'm still getting used to the codebase. I wasn't 
> sure whether this was important, so I left it in. But I don't think I have a 
> good reason. 
> 
> I've added a new test case `SortsInPPDirective` that spot-checks some macro 
> definition examples (which did fail unless this `Line->InPPDirective` check 
> was removed, as expected.).
What about `Line->Type != LT_ObjCProperty` I suggested?



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:190
+  continue;
+
+const auto *Last = Line->Last;

jaredgrubb wrote:
> owenpan wrote:
> > Must `@property` be the first non-comment tokens of an unwrapped line in 
> > Objective-C? And at most one `@property` per line?
> I can't think of any token that should precede a `@property`. Aka, I don't 
> think there are any `__attribute__` that can fill that slot. 
> 
> You could have `@optional` or `@required` floating around between 
> property/method declarations. I've added a test-case for a `@property` that 
> is preceded by these tokens and proved that the reordering is handled 
> correctly.
> 
> As for multiple properties in one line, I've never seen a codebase with that. 
> clang-format does split them already.
I asked the questions because if yes, we could move on to the next line before 
hitting the last token of the current line.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

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


[clang] [flang] [Flang][Clang] Add support for frame pointers in Flang (PR #72146)

2023-11-15 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

Could you add some tests? In e.g. "driver-help.f90" we merely test that a flag 
is visible.

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


[clang] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (PR #72016)

2023-11-15 Thread Balázs Kéri via cfe-commits

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

The change is OK, automated tests show a failure but it is in an unrelated test.

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


[clang] 9a9933f - [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (#72234)

2023-11-15 Thread via cfe-commits

Author: Michael Buch
Date: 2023-11-15T08:16:24Z
New Revision: 9a9933fae23249fbf6cf5b3c090e630f578b7f98

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

LOG: [llvm][DebugInfo] DWARFv5: static data members declarations are 
DW_TAG_variable (#72234)

This patch adds the LLVM-side infrastructure to implement DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

The clang-side of this patch will simply construct the DIDerivedType
with a different DW_TAG.

Added: 
llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm-c/DebugInfo.h
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/Verifier.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..a201cf03c22f711 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1681,7 +1681,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
+  llvm::dwarf::DW_TAG_member, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;

diff  --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 5924294708cc354..61659d514b520e5 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -785,14 +785,14 @@ LLVMMetadataRef LLVMDIBuilderCreateMemberType(
  * \param Type Type of the static member.
  * \param FlagsFlags to encode member attribute, e.g. private.
  * \param ConstantVal  Const initializer of the member.
+ * \param Tag  DWARF tag of the static member.
  * \param AlignInBits  Member alignment.
  */
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
-uint32_t AlignInBits);
+unsigned Tag, uint32_t AlignInBits);
 
 /**
  * Create debugging information entry for a pointer to member.

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index ecd6dd7b0a4f822..2be133e85e8c1e4 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -376,11 +376,12 @@ namespace llvm {
 /// \param Ty Type of the static member.
 /// \param Flags  Flags to encode member attribute, e.g. private.
 /// \param ValConst initializer of the member.
+/// \param TagDWARF tag of the static member.
 /// \param AlignInBits  Member alignment.
 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
   DIFile *File, unsigned LineNo,
   DIType *Ty, DINode::DIFlags Flags,
-  Constant *Val,
+  Constant *Val, unsigned Tag,
   uint32_t AlignInBits = 0);
 
 /// Create debugging information entry for Objective-C

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17f8a880f6..58a7e07d9b58d86 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -405,12 +405,11 @@ DIDerivedType *
 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
   unsigned LineNumber, DIType *Ty,
   DINode::DIFlags Flags, llvm::Constant *Val,
-  uint32_t AlignInBits) {
+  unsigned Tag, uint32_t AlignInBits) {
   Flags |= DINode::FlagStaticMember;
-  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
-LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
-AlignInBits, 0, std::nullopt, Flags,
-getConstantOrNull(Val));
+  return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
+getNonCompileUnitScope(Scope), Ty, 0, AlignInBits,
+0

[clang] [llvm] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-15 Thread Michael Buch via cfe-commits

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


[clang-tools-extra] [clang] [flang] [compiler-rt] [llvm] [libc] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72235

>From c0db61f318f50a1cf219c69af9c6b624b05c9da1 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 13 Nov 2023 09:48:39 +
Subject: [PATCH] [clang][DebugInfo] DWARFv5: static data members declarations
 are DW_TAG_variable

This patch implements the DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

This will simplify LLDB's handling of static data
members greatly in the long term since we no longer
need to differentiate non-static from static data
member declarations using non-portable heuristics.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++--
 .../debug-info-static-inline-member.cpp   |  4 +--
 .../CodeGenCXX/debug-info-static-member.cpp   | 36 ---
 3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..f3de91d4a39ebee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1679,9 +1679,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   StringRef VName = Var->getName();
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  llvm::DIDerivedType *GV =
+  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
+  Flags, /* Val */ nullptr, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index bfb7ad6b80fabf3..f2d4d9408a8297a 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -1,5 +1,5 @@
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited 
%s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
 
 enum class Enum : int {
   VAL = -1
diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 578995801c6400b..a2d25e98ed1cb62 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,7 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-5 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF5 %s
+// RUN: %clangxx -target x86_64-windows-msvc -g -gdwarf-4 %s -emit-llvm -S -o 
- | FileCheck --check-prefixes=CHECK,DWARF4 %s
 // PR14471
 
 // CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -39,17 +40,20 @@ class C
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF4: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF5: !DIDerivedType(tag: DW_TAG_variable, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"static_d

[flang] [clang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM :)

Thank you for addressing my comments.

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


[clang] [flang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread Andrzej Warzyński via cfe-commits


@@ -303,6 +323,9 @@ bool CodeGenAction::beginSourceFileAction() {
   Fortran::parser::Program &parseTree{*ci.getParsing().parseTree()};
   lb.lower(parseTree, ci.getInvocation().getSemanticsContext());
 
+  // Add dependent libraries
+  addDepdendentLibs(*mlirModule, ci);

banach-space wrote:

Apologies, I thought that this was 
[FrontendAction::beginSourceFile](https://github.com/banach-space/llvm-project/blob/d0b00b2c494b44fd1da7964b9334633215765c7f/flang/lib/Frontend/FrontendAction.cpp#L38)
 rather than `CodeGenAction::beginSourceFileAction()`.

I think that keeping it here is fine. Like you said, the ordering in this case 
doesn't matter that much.

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


[clang] [flang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread Andrzej Warzyński via cfe-commits

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


[flang] [clang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,15 @@
+! DEFINE: %{triple} =
+! DEFINE: %{run} = %flang_fc1 -emit-mlir -triple %{triple} 
--dependent-lib=libtest %s -o - 2>&1 | FileCheck %s
+! REDEFINE: %{triple} = aarch64-pc-windows-msvc
+! RUN: %{run}
+! REDEFINE: %{triple} = x86_64-pc-windows-msvc
+! RUN: %{run}
+! REDEFINE: %{triple} = x86_64-linux-unknown-gnu
+! RUN: not %{run} --check-prefixes=CHECK-NOWIN
+! REDEFINE: %{triple} = aarch64-apple-darwin
+! RUN: not %{run} --check-prefixes=CHECK-NOWIN

banach-space wrote:

I see what you meant about readability - indeed debatable 😅 . Here's an idea 
how to improve it a bit:

```suggestion
! DEFINE: %{triple} =
! DEFINE: %{compile} = %flang_fc1 -emit-mlir -triple %{triple} 
--dependent-lib=libtest %s -o - 2>&1

! REDEFINE: %{triple} = aarch64-pc-windows-msvc
! RUN: %{compile}  | FileCheck %s

! REDEFINE: %{triple} = x86_64-pc-windows-msvc
! RUN: %{compile}  | FileCheck %s

! REDEFINE: %{triple} = x86_64-linux-unknown-gnu
! RUN: not %{compile}  | FileCheck %s --check-prefixes=CHECK-NOWIN

! REDEFINE: %{triple} = aarch64-apple-darwin
! RUN: not %{compile}  | FileCheck %s --check-prefixes=CHECK-NOWIN
```
(separating the compiler invocation from the FileCheck invocation as two 
logically seperate things).

This is a "nit" - I am happy with this test as long as the functionality is 
verified (it is).

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


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

BTW, it may be simpler and more efficient to use a set (e.g. `llvm::SmallSet`) 
for `Indices`, especially if we don't need/want to handle duplicate attributes 
that have a value. (See D150083#inline-1551778 
.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

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


[clang] [llvm] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-15 Thread Michael Buch via cfe-commits

Michael137 wrote:

Looks like the OCaml bindings are using the C-API that was changed in this PR. 
Will make a follow-up fix for those

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


[clang] 8e8bad7 - Revert "[llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (#72234)"

2023-11-15 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2023-11-15T08:50:16Z
New Revision: 8e8bad70e6db0b04198c025bef9acccfd06f36f0

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

LOG: Revert "[llvm][DebugInfo] DWARFv5: static data members declarations are 
DW_TAG_variable (#72234)"

This reverts commit 9a9933fae23249fbf6cf5b3c090e630f578b7f98.

The OCaml bindings were using `LLVMDIBuilderCreateStaticMemberType`,
causing the API change in `9a9933fae23249fbf6cf5b3c090e630f578b7f98`
to break buildbots that built the bindings. Revert until we figure out
whether to fixup the bindings or just not change the C-API

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm-c/DebugInfo.h
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/Verifier.cpp

Removed: 
llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a201cf03c22f711..04ca02cfe858579 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1681,8 +1681,7 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
-  llvm::dwarf::DW_TAG_member, Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;

diff  --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 61659d514b520e5..5924294708cc354 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -785,14 +785,14 @@ LLVMMetadataRef LLVMDIBuilderCreateMemberType(
  * \param Type Type of the static member.
  * \param FlagsFlags to encode member attribute, e.g. private.
  * \param ConstantVal  Const initializer of the member.
- * \param Tag  DWARF tag of the static member.
  * \param AlignInBits  Member alignment.
  */
-LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef
+LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
-unsigned Tag, uint32_t AlignInBits);
+uint32_t AlignInBits);
 
 /**
  * Create debugging information entry for a pointer to member.

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index 2be133e85e8c1e4..ecd6dd7b0a4f822 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -376,12 +376,11 @@ namespace llvm {
 /// \param Ty Type of the static member.
 /// \param Flags  Flags to encode member attribute, e.g. private.
 /// \param ValConst initializer of the member.
-/// \param TagDWARF tag of the static member.
 /// \param AlignInBits  Member alignment.
 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
   DIFile *File, unsigned LineNo,
   DIType *Ty, DINode::DIFlags Flags,
-  Constant *Val, unsigned Tag,
+  Constant *Val,
   uint32_t AlignInBits = 0);
 
 /// Create debugging information entry for Objective-C

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 58a7e07d9b58d86..1ce8c17f8a880f6 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -405,11 +405,12 @@ DIDerivedType *
 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
   unsigned LineNumber, DIType *Ty,
   DINode::DIFlags Flags, llvm::Constant *Val,
-  unsigned Tag, uint32_t AlignInBits) {
+  uint32_t AlignInBits) {
   Flags |= DINode::FlagStaticMember;
-  return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
-getNonCompileUnitScope(Scope), Ty, 0, AlignInBits,
-0, std::nullopt, Flags, getConstantOrNull(Val));
+  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
+ 

[clang] [Clang][RISCV] Introduce tuple types for RVV bfloat16 (PR #72216)

2023-11-15 Thread via cfe-commits

kda wrote:

This commit seems to be breaking Sanitizer buildbots:
https://lab.llvm.org/buildbot/#/builders/168/builds/16824
https://lab.llvm.org/buildbot/#/builders/74/builds/23531
https://lab.llvm.org/buildbot/#/builders/5/builds/38325


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


[llvm] [clang-tools-extra] [clang] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

2023-11-15 Thread via cfe-commits

https://github.com/LWenH updated https://github.com/llvm/llvm-project/pull/70778

>From a42f48a44c614f2c996f3f4cb0561e2f7ab35d6f Mon Sep 17 00:00:00 2001
From: LWenH <924105...@qq.com>
Date: Tue, 31 Oct 2023 16:33:41 +0800
Subject: [PATCH 1/7] add pre commit test for later mcp patch

---
 llvm/test/CodeGen/RISCV/machine-cp.mir | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/llvm/test/CodeGen/RISCV/machine-cp.mir 
b/llvm/test/CodeGen/RISCV/machine-cp.mir
index f3674f89cd918b4..9c04abf492a1475 100644
--- a/llvm/test/CodeGen/RISCV/machine-cp.mir
+++ b/llvm/test/CodeGen/RISCV/machine-cp.mir
@@ -9,6 +9,10 @@
   entry:
 ret void
   }
+  define void @bar() {
+  entry:
+ret void
+  }
 ...
 ---
 name:foo
@@ -21,6 +25,7 @@ body: |
 ; RV32-NEXT: renamable $v4_v5_v6_v7_v8_v9_v10_v11 = COPY killed renamable 
$v0_v1_v2_v3_v4_v5_v6_v7
 ; RV32-NEXT: renamable $v28 = COPY renamable $v8, implicit killed 
$v28_v29_v30, implicit-def $v28_v29_v30
 ; RV32-NEXT: PseudoRET implicit $v28
+;
 ; RV64-LABEL: name: foo
 ; RV64: liveins: $v28_v29_v30, $v8_v9, $v1
 ; RV64-NEXT: {{  $}}
@@ -32,3 +37,32 @@ body: |
 renamable $v28 = COPY renamable $v8, implicit killed $v28_v29_v30, 
implicit-def $v28_v29_v30
 PseudoRET implicit $v28
 ...
+---
+name:bar
+body: |
+  bb.0.entry:
+liveins: $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, 
$x16, $x17, $x28, $x29, $x30, $x31
+; RV32-LABEL: name: bar
+; RV32: liveins: $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, 
$x15, $x16, $x17, $x28, $x29, $x30, $x31
+; RV32-NEXT: {{  $}}
+; RV32-NEXT: $v0 = COPY renamable $v8
+; RV32-NEXT: renamable $v14m2 = PseudoVLE32_V_M2_MASK undef renamable 
$v14m2, renamable $x15, $v0, -1, 5 /* e32 */, 1 /* ta, mu */, implicit $vl, 
implicit $vtype
+; RV32-NEXT: early-clobber renamable $v9 = PseudoVMSLE_VI_M2 killed 
renamable $v10m2, -1, -1, 5 /* e32 */, implicit $vl, implicit $vtype
+; RV32-NEXT: $v0 = COPY killed renamable $v8
+; RV32-NEXT: PseudoVSE32_V_M2_MASK killed renamable $v14m2, renamable $x9, 
$v0, -1, 5 /* e32 */, implicit $vl, implicit $vtype
+;
+; RV64-LABEL: name: bar
+; RV64: liveins: $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, 
$x15, $x16, $x17, $x28, $x29, $x30, $x31
+; RV64-NEXT: {{  $}}
+; RV64-NEXT: $v0 = COPY renamable $v8
+; RV64-NEXT: renamable $v14m2 = PseudoVLE32_V_M2_MASK undef renamable 
$v14m2, renamable $x15, $v0, -1, 5 /* e32 */, 1 /* ta, mu */, implicit $vl, 
implicit $vtype
+; RV64-NEXT: early-clobber renamable $v9 = PseudoVMSLE_VI_M2 killed 
renamable $v10m2, -1, -1, 5 /* e32 */, implicit $vl, implicit $vtype
+; RV64-NEXT: $v0 = COPY killed renamable $v8
+; RV64-NEXT: PseudoVSE32_V_M2_MASK killed renamable $v14m2, renamable $x9, 
$v0, -1, 5 /* e32 */, implicit $vl, implicit $vtype
+$v0 = COPY killed renamable $v9; example.cpp:14:22
+$v0 = COPY renamable $v8; example.cpp:12:25
+renamable $v14m2 = PseudoVLE32_V_M2_MASK undef renamable $v14m2, renamable 
$x15, $v0, -1, 5, 1, implicit $vl, implicit $vtype; example.cpp:12:25
+early-clobber renamable $v9 = PseudoVMSLE_VI_M2 killed renamable $v10m2, 
-1, -1, 5, implicit $vl, implicit $vtype; example.cpp:9:22
+$v0 = COPY killed renamable $v8; example.cpp:12:22
+PseudoVSE32_V_M2_MASK killed renamable $v14m2, renamable $x9, $v0, -1, 5, 
implicit $vl, implicit $vtype; example.cpp:12:22
+...

>From 516d95d53b00d1478aca2ad3f180eb6a3dc3d24b Mon Sep 17 00:00:00 2001
From: LWenH <924105...@qq.com>
Date: Tue, 31 Oct 2023 17:39:04 +0800
Subject: [PATCH 2/7] mcp: further enhance chance for reduncdant copy removal

---
 llvm/lib/CodeGen/MachineCopyPropagation.cpp | 25 +
 llvm/test/CodeGen/RISCV/machine-cp.mir  |  2 --
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp 
b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index a032b31a1fc7c62..b0640b48121febd 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -719,6 +719,7 @@ void 
MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
   LLVM_DEBUG(dbgs() << "MCP: ForwardCopyPropagateBlock " << MBB.getName()
 << "\n");
 
+  const MachineInstr *LastMI = nullptr;
   for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) {
 // Analyze copies (which don't overlap themselves).
 std::optional CopyOperands =
@@ -735,6 +736,27 @@ void 
MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
 MCRegister Def = RegDef.asMCReg();
 MCRegister Src = RegSrc.asMCReg();
 
+// Target may lost some opportunity to further remove the redundant
+// copy instruction, consider the following sequence:
+// L1: r0 = COPY r9 <- TrackMI
+// L2: r0 = COPY r8 <- Track

[clang] [clang-tools-extra] [llvm] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

2023-11-15 Thread via cfe-commits

LWenH wrote:

Resolve conflict test file:  
```
 /llvm/test/CodeGen/AMDGPU/load-constant-i1.ll
```

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


[clang] fix: compatible C++ empty record with align UB with gcc (PR #72197)

2023-11-15 Thread via cfe-commits

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


[clang-tools-extra] [compiler-rt] [llvm] [clang] [flang] [mlir] [mlir] Verify non-negative `offset` and `size` (PR #72059)

2023-11-15 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph approved this pull request.

Nice, thanks!

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


[clang] [Clang][RISCV] Introduce tuple types for RVV bfloat16 (PR #72216)

2023-11-15 Thread antoine moynault via cfe-commits

antmox wrote:

This also broke several aarch64 bots:
https://lab.llvm.org/buildbot/#/builders/245/builds/16676
https://lab.llvm.org/buildbot/#/builders/188/builds/37969
https://lab.llvm.org/buildbot/#/builders/198/builds/6244
https://lab.llvm.org/buildbot/#/builders/176/builds/6987
https://lab.llvm.org/buildbot/#/builders/186/builds/13185
https://lab.llvm.org/buildbot/#/builders/183/builds/17354


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


[llvm] [flang] [clang-tools-extra] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread via cfe-commits

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


[flang] [clang] [llvm] [clang-tools-extra] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread via cfe-commits


@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");

jeanPerier wrote:

Prefer emitting a Fortran fatal runtime error here.

Can be done as:
```
Terminator terminator{__FILE__, __LINE__};
if (error != 0)
  terminator.Crash("getlogin_r returned error %d", error);
```
or simply
```
Terminator terminator{__FILE__, __LINE__};
RUNTIME_CHECK(terminator, error == 0);
```

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


[clang-tools-extra] [llvm] [flang] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread via cfe-commits


@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");
+
+  // Trim space from right/end
+  int i = str.size();
+  while (' ' == str[--i]) {
+str[i] = 0;
+  }
+  strncpy(reinterpret_cast(arg), str.data(), length);
+}

jeanPerier wrote:

I think you also need to pad the result argument with blanks for all the 
characters of the result that were not filled with the login  (including the 
copied `0` terminator)  (if it was copied).
Padding with blanks is the usual Fortran convention for INTENT(OUT) string 
passed to intrinsics, GETLOG does not mention it, but I tested with gfortran 
and it does pad with blanks.

Example on some system I am called `jp`

```
  character(10) :: string
  string = "ZZ"
  call getlog(string)
  write(*, "(AA)") string, "X"
end
```
outputs  `jpX`, so the 8 characters after the login name were padded 
with blanks.

Maybe you could share and re-use the copyBufferAndPad logic at:
https://github.com/llvm/llvm-project/blob/1b781ee9284ded54aabd88690a726b615c29cc2d/flang/runtime/time-intrinsic.cpp#L282

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


[clang-tools-extra] [llvm] [clang] [flang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread via cfe-commits

https://github.com/jeanPerier commented:

Thanks a lot for the update and addressing my previous comments!

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


[clang] [flang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread via cfe-commits


@@ -13,6 +13,44 @@
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include 
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+#include  // wcstombs_s
+#include  // wchar_t cast to LPWSTR
+#pragma comment(lib, "Advapi32.lib") // Link Advapi32.lib for GetUserName
+#define LOGIN_NAME_MAX UNLEN
+
+inline int getlogin_r(char *buf, size_t bufSize) {
+  wchar_t w_username[UNLEN + 1];
+  DWORD nameLen = UNLEN + 1;
+
+  if (GetUserNameW(w_username, &nameLen)) {
+// Convert the wchar_t string to a regular C string using wcstombs_s
+if (wcstombs_s(nullptr, buf, sizeof(w_username), w_username, _TRUNCATE) !=
+0) {
+  // Conversion failed
+  return -1;
+}
+return (buf[0] == 0 ? -1 : 0);
+  } else {
+return -1;
+  }
+  return -1;
+}
+
+#elif _REENTRANT || _POSIX_C_SOURCE >= 199506L
+// System is posix-compliant and has getlogin_r
+#include 
+#else
+// System is not posix-compliant
+inline int getlogin_r(char *buf, size_t bufsize) { return -1; }

jeanPerier wrote:

Actually, it seems the gfortran extension for getlog says that: 
https://gcc.gnu.org/onlinedocs/gcc-4.2.4/gfortran/GETLOG.html

> On systems where the getlogin(3) function is not implemented, this will 
> return a blank string

So I think the fallback version could still return zero and set the buffer to 
blanks.

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


[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread via cfe-commits

https://github.com/mohammed-nurulhoque created 
https://github.com/llvm/llvm-project/pull/72364

When the last clobbering write for a load doesn't cover the whole load (example 
below). AnalyzeLoadAvailability would give up. 
This emits  temporary byte-sized loads that cover the original load, then run 
AnalyzeLoadAvailability  on each and reconstruct the load value.

```
  define i32 @f(i8* %P)
%b2 = getelementptr inbounds i8, i8* %P, i64 1
store i8 0, i8* %b2, align 1
store i8 0, i8* %P, align 1
%s1 = bitcast i8* %P to i16*
%L = load i16, i16* %s1, align 4
```

>From 41a9dbd39fbb866e7fc090f82d58ee6364a7cfda Mon Sep 17 00:00:00 2001
From: "Mohammed.NurulHoque" 
Date: Wed, 27 Apr 2022 09:42:37 +0100
Subject: [PATCH] split load to bytes and run analyzeloadavailability per byte
 to deduce load value

---
 .../optimization-remark-extra-analysis.c  |   3 +-
 llvm/include/llvm/Transforms/Scalar/GVN.h |   1 +
 llvm/lib/Transforms/Scalar/GVN.cpp| 105 ++-
 .../BasicAA/2003-02-26-AccessSizeTest.ll  |  12 +-
 .../TypeBasedAliasAnalysis/precedence.ll  |   5 +-
 .../GVN/2009-11-12-MemDepMallocBitCast.ll |   6 +-
 .../GVN/no_speculative_loads_with_asan.ll |  20 +--
 .../GVN/opt-remarks-multiple-users.ll |   3 +
 .../GVN/opt-remarks-non-dominating.ll |   3 +
 .../Transforms/GVN/split-load-assertion.ll| 166 ++
 .../NewGVN/no_speculative_loads_with_asan.ll  |  96 +-
 11 files changed, 348 insertions(+), 72 deletions(-)
 create mode 100644 llvm/test/Transforms/GVN/split-load-assertion.ll

diff --git a/clang/test/Frontend/optimization-remark-extra-analysis.c 
b/clang/test/Frontend/optimization-remark-extra-analysis.c
index 1a8415e69cff9ba..5af30bd0d3c35b3 100644
--- a/clang/test/Frontend/optimization-remark-extra-analysis.c
+++ b/clang/test/Frontend/optimization-remark-extra-analysis.c
@@ -6,6 +6,7 @@
 int foo(int *x, int *y) {
   int a = *x;
   *y = 2;
-  // expected-remark@+1 {{load of type i32 not eliminated}}
+  // expected-remark@+2 {{load of type i32 not eliminated}}
+  // expected-remark@+1 {{load of type i8 not eliminated}}
   return a + *x;
 }
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h 
b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 4ba9b74ccb005d4..4052c0d618d173d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -314,6 +314,7 @@ class GVNPass : public PassInfoMixin {
 
   // Helper functions of redundant load elimination
   bool processLoad(LoadInst *L);
+  bool splitAndprocessLoad(LoadInst *L);
   bool processNonLocalLoad(LoadInst *L);
   bool processAssumeIntrinsic(AssumeInst *II);
 
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 5e58af0edc1556f..f64508a8319197f 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -112,6 +112,7 @@ static cl::opt
 GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
 cl::init(false));
 static cl::opt GVNEnableMemDep("enable-gvn-memdep", cl::init(true));
+static cl::opt GVNEnableSplitLoad("enable-split-load", cl::init(true));
 
 static cl::opt MaxNumDeps(
 "gvn-max-num-deps", cl::Hidden, cl::init(100),
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, 
Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4
+//
+// The last clobbering write for the load is (3) but it doesn't cover the whole
+// read. So AnalyzeLoadAvailability would give up.
+// This function emit temporary byte-sized loads that cover the original load,
+// so that any last write covers the read. We run AnalyzeLoadAvailability on
+// each byte to try to construct the load as a constant.
+bool GVNPass::splitAndprocessLoad(LoadInst *L) {
+  if (L->isAtomic())
+return false;
+
+  Type *LTy = L->getType();
+  if (!LTy->isIntegerTy())
+return false;
+
+  unsigned BW = LTy->getIntegerBitWidth();
+  if (BW % 8)
+return false;
+
+  IntegerType *ByteTy = IntegerType::getInt8Ty(LTy->getContext());
+  Type *BytePtrTy = PointerType::get(ByteTy, L->getPointerAddressSpace());
+  BitCastInst *Base = new BitCastInst(L->getPointerOperand(), BytePtrTy, "", 
L);
+
+  // we update this byte by byte as we deduce the load value
+  APInt ConstructedValue = APInt::getZero(BW);
+
+  for (unsigned i=0; i(Offset), "", L);
+LoadInst *ByteLoad = new LoadInst(ByteTy, GEP, "", L);
+ByteLoad->setDebugLoc(L->getDebugLoc());
+
+auto CleanupTmps = [&]() {
+  MD->removeInstruction(ByteLoad);
+  ByteLoad->eraseFromParent();
+  GEP->eraseFromParent();
+};
+
+ 

[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: None (mohammed-nurulhoque)


Changes

When the last clobbering write for a load doesn't cover the whole load (example 
below). AnalyzeLoadAvailability would give up. 
This emits  temporary byte-sized loads that cover the original load, then run 
AnalyzeLoadAvailability  on each and reconstruct the load value.

```
  define i32 @f(i8* %P)
%b2 = getelementptr inbounds i8, i8* %P, i64 1
store i8 0, i8* %b2, align 1
store i8 0, i8* %P, align 1
%s1 = bitcast i8* %P to i16*
%L = load i16, i16* %s1, align 4
```

---

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


11 Files Affected:

- (modified) clang/test/Frontend/optimization-remark-extra-analysis.c (+2-1) 
- (modified) llvm/include/llvm/Transforms/Scalar/GVN.h (+1) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+104-1) 
- (modified) llvm/test/Analysis/BasicAA/2003-02-26-AccessSizeTest.ll (+6-6) 
- (modified) llvm/test/Analysis/TypeBasedAliasAnalysis/precedence.ll (+2-3) 
- (modified) llvm/test/Transforms/GVN/2009-11-12-MemDepMallocBitCast.ll (+3-3) 
- (modified) llvm/test/Transforms/GVN/no_speculative_loads_with_asan.ll (+7-13) 
- (modified) llvm/test/Transforms/GVN/opt-remarks-multiple-users.ll (+3) 
- (modified) llvm/test/Transforms/GVN/opt-remarks-non-dominating.ll (+3) 
- (added) llvm/test/Transforms/GVN/split-load-assertion.ll (+166) 
- (modified) llvm/test/Transforms/NewGVN/no_speculative_loads_with_asan.ll 
(+51-45) 


``diff
diff --git a/clang/test/Frontend/optimization-remark-extra-analysis.c 
b/clang/test/Frontend/optimization-remark-extra-analysis.c
index 1a8415e69cff9ba..5af30bd0d3c35b3 100644
--- a/clang/test/Frontend/optimization-remark-extra-analysis.c
+++ b/clang/test/Frontend/optimization-remark-extra-analysis.c
@@ -6,6 +6,7 @@
 int foo(int *x, int *y) {
   int a = *x;
   *y = 2;
-  // expected-remark@+1 {{load of type i32 not eliminated}}
+  // expected-remark@+2 {{load of type i32 not eliminated}}
+  // expected-remark@+1 {{load of type i8 not eliminated}}
   return a + *x;
 }
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h 
b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 4ba9b74ccb005d4..4052c0d618d173d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -314,6 +314,7 @@ class GVNPass : public PassInfoMixin {
 
   // Helper functions of redundant load elimination
   bool processLoad(LoadInst *L);
+  bool splitAndprocessLoad(LoadInst *L);
   bool processNonLocalLoad(LoadInst *L);
   bool processAssumeIntrinsic(AssumeInst *II);
 
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 5e58af0edc1556f..f64508a8319197f 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -112,6 +112,7 @@ static cl::opt
 GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
 cl::init(false));
 static cl::opt GVNEnableMemDep("enable-gvn-memdep", cl::init(true));
+static cl::opt GVNEnableSplitLoad("enable-split-load", cl::init(true));
 
 static cl::opt MaxNumDeps(
 "gvn-max-num-deps", cl::Hidden, cl::init(100),
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, 
Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4
+//
+// The last clobbering write for the load is (3) but it doesn't cover the whole
+// read. So AnalyzeLoadAvailability would give up.
+// This function emit temporary byte-sized loads that cover the original load,
+// so that any last write covers the read. We run AnalyzeLoadAvailability on
+// each byte to try to construct the load as a constant.
+bool GVNPass::splitAndprocessLoad(LoadInst *L) {
+  if (L->isAtomic())
+return false;
+
+  Type *LTy = L->getType();
+  if (!LTy->isIntegerTy())
+return false;
+
+  unsigned BW = LTy->getIntegerBitWidth();
+  if (BW % 8)
+return false;
+
+  IntegerType *ByteTy = IntegerType::getInt8Ty(LTy->getContext());
+  Type *BytePtrTy = PointerType::get(ByteTy, L->getPointerAddressSpace());
+  BitCastInst *Base = new BitCastInst(L->getPointerOperand(), BytePtrTy, "", 
L);
+
+  // we update this byte by byte as we deduce the load value
+  APInt ConstructedValue = APInt::getZero(BW);
+
+  for (unsigned i=0; i(Offset), "", L);
+LoadInst *ByteLoad = new LoadInst(ByteTy, GEP, "", L);
+ByteLoad->setDebugLoc(L->getDebugLoc());
+
+auto CleanupTmps = [&]() {
+  MD->removeInstruction(ByteLoad);
+  ByteLoad->eraseFromParent();
+  GEP->eraseFromParent();
+};
+
+MemDepResult ByteDep = MD->getDep

[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (mohammed-nurulhoque)


Changes

When the last clobbering write for a load doesn't cover the whole load (example 
below). AnalyzeLoadAvailability would give up. 
This emits  temporary byte-sized loads that cover the original load, then run 
AnalyzeLoadAvailability  on each and reconstruct the load value.

```
  define i32 @f(i8* %P)
%b2 = getelementptr inbounds i8, i8* %P, i64 1
store i8 0, i8* %b2, align 1
store i8 0, i8* %P, align 1
%s1 = bitcast i8* %P to i16*
%L = load i16, i16* %s1, align 4
```

---

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


11 Files Affected:

- (modified) clang/test/Frontend/optimization-remark-extra-analysis.c (+2-1) 
- (modified) llvm/include/llvm/Transforms/Scalar/GVN.h (+1) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+104-1) 
- (modified) llvm/test/Analysis/BasicAA/2003-02-26-AccessSizeTest.ll (+6-6) 
- (modified) llvm/test/Analysis/TypeBasedAliasAnalysis/precedence.ll (+2-3) 
- (modified) llvm/test/Transforms/GVN/2009-11-12-MemDepMallocBitCast.ll (+3-3) 
- (modified) llvm/test/Transforms/GVN/no_speculative_loads_with_asan.ll (+7-13) 
- (modified) llvm/test/Transforms/GVN/opt-remarks-multiple-users.ll (+3) 
- (modified) llvm/test/Transforms/GVN/opt-remarks-non-dominating.ll (+3) 
- (added) llvm/test/Transforms/GVN/split-load-assertion.ll (+166) 
- (modified) llvm/test/Transforms/NewGVN/no_speculative_loads_with_asan.ll 
(+51-45) 


``diff
diff --git a/clang/test/Frontend/optimization-remark-extra-analysis.c 
b/clang/test/Frontend/optimization-remark-extra-analysis.c
index 1a8415e69cff9ba..5af30bd0d3c35b3 100644
--- a/clang/test/Frontend/optimization-remark-extra-analysis.c
+++ b/clang/test/Frontend/optimization-remark-extra-analysis.c
@@ -6,6 +6,7 @@
 int foo(int *x, int *y) {
   int a = *x;
   *y = 2;
-  // expected-remark@+1 {{load of type i32 not eliminated}}
+  // expected-remark@+2 {{load of type i32 not eliminated}}
+  // expected-remark@+1 {{load of type i8 not eliminated}}
   return a + *x;
 }
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h 
b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 4ba9b74ccb005d4..4052c0d618d173d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -314,6 +314,7 @@ class GVNPass : public PassInfoMixin {
 
   // Helper functions of redundant load elimination
   bool processLoad(LoadInst *L);
+  bool splitAndprocessLoad(LoadInst *L);
   bool processNonLocalLoad(LoadInst *L);
   bool processAssumeIntrinsic(AssumeInst *II);
 
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 5e58af0edc1556f..f64508a8319197f 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -112,6 +112,7 @@ static cl::opt
 GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre",
 cl::init(false));
 static cl::opt GVNEnableMemDep("enable-gvn-memdep", cl::init(true));
+static cl::opt GVNEnableSplitLoad("enable-split-load", cl::init(true));
 
 static cl::opt MaxNumDeps(
 "gvn-max-num-deps", cl::Hidden, cl::init(100),
@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, 
Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4
+//
+// The last clobbering write for the load is (3) but it doesn't cover the whole
+// read. So AnalyzeLoadAvailability would give up.
+// This function emit temporary byte-sized loads that cover the original load,
+// so that any last write covers the read. We run AnalyzeLoadAvailability on
+// each byte to try to construct the load as a constant.
+bool GVNPass::splitAndprocessLoad(LoadInst *L) {
+  if (L->isAtomic())
+return false;
+
+  Type *LTy = L->getType();
+  if (!LTy->isIntegerTy())
+return false;
+
+  unsigned BW = LTy->getIntegerBitWidth();
+  if (BW % 8)
+return false;
+
+  IntegerType *ByteTy = IntegerType::getInt8Ty(LTy->getContext());
+  Type *BytePtrTy = PointerType::get(ByteTy, L->getPointerAddressSpace());
+  BitCastInst *Base = new BitCastInst(L->getPointerOperand(), BytePtrTy, "", 
L);
+
+  // we update this byte by byte as we deduce the load value
+  APInt ConstructedValue = APInt::getZero(BW);
+
+  for (unsigned i=0; i(Offset), "", L);
+LoadInst *ByteLoad = new LoadInst(ByteTy, GEP, "", L);
+ByteLoad->setDebugLoc(L->getDebugLoc());
+
+auto CleanupTmps = [&]() {
+  MD->removeInstruction(ByteLoad);
+  ByteLoad->eraseFromParent();
+  GEP->eraseFromParent();
+};
+
+MemDepResult ByteDep = MD->getDependency(

[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 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 dedf2c6bb5193652f6ad7d9ff9e676624c2485b7 
41a9dbd39fbb866e7fc090f82d58ee6364a7cfda -- 
clang/test/Frontend/optimization-remark-extra-analysis.c 
llvm/include/llvm/Transforms/Scalar/GVN.h llvm/lib/Transforms/Scalar/GVN.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index f64508a831..fc0b49bcd9 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2163,10 +2163,10 @@ bool GVNPass::splitAndprocessLoad(LoadInst *L) {
   // we update this byte by byte as we deduce the load value
   APInt ConstructedValue = APInt::getZero(BW);
 
-  for (unsigned i=0; i(Offset), "", L);
+ByteTy, Base, ArrayRef(Offset), "", L);
 LoadInst *ByteLoad = new LoadInst(ByteTy, GEP, "", L);
 ByteLoad->setDebugLoc(L->getDebugLoc());
 
@@ -2186,22 +2186,21 @@ bool GVNPass::splitAndprocessLoad(LoadInst *L) {
 }
 
 auto ByteRes = AnalyzeLoadAvailability(ByteLoad, ByteDep, GEP);
-// If it doesn't reduce to a constant, give up. Creating the value at 
runtime by
-// shifting the bytes is not worth it to remove a load.
-if (ByteRes &&
-  (ByteRes->isMemIntrinValue() ||
-   (ByteRes->isSimpleValue() &&
-(isa(ByteRes->getSimpleValue()) ||
- isa(ByteRes->getSimpleValue()) {
-Value *V = ByteRes->MaterializeAdjustedValue(ByteLoad, ByteLoad, 
*this);
-ConstantInt *ByteConst = dyn_cast(V);
-if (!ByteConst) {
-  // replace undef with 0. This helps optimize cases where some bits of
-  // load are constant integer, and some are undef. So we can optimize
-  // the load to a particular integer.
-  ByteConst = ConstantInt::get(ByteTy, 0);
-}
-ConstructedValue.insertBits(ByteConst->getValue(), 8*i);
+// If it doesn't reduce to a constant, give up. Creating the value at
+// runtime by shifting the bytes is not worth it to remove a load.
+if (ByteRes && (ByteRes->isMemIntrinValue() ||
+(ByteRes->isSimpleValue() &&
+ (isa(ByteRes->getSimpleValue()) ||
+  isa(ByteRes->getSimpleValue()) {
+  Value *V = ByteRes->MaterializeAdjustedValue(ByteLoad, ByteLoad, *this);
+  ConstantInt *ByteConst = dyn_cast(V);
+  if (!ByteConst) {
+// replace undef with 0. This helps optimize cases where some bits of
+// load are constant integer, and some are undef. So we can optimize
+// the load to a particular integer.
+ByteConst = ConstantInt::get(ByteTy, 0);
+  }
+  ConstructedValue.insertBits(ByteConst->getValue(), 8 * i);
 } else {
   LLVM_DEBUG(dbgs() << "GVN split load: byte " << i
 << " did not reduce to a constant. Giving up");

``




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


[clang] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (PR #72367)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD created https://github.com/llvm/llvm-project/pull/72367

This reverts commit 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d. #72216 

This commit broke the multiple buildbots, looks like the extension in 
`NUM_PREDEF_TYPE_IDS` might have broken some inheriting usages, causing 
indeterminate results for the compiler. Investigating the issue now.

>From 778651c915af68710d3a7d39cdfa010f1bc8edf8 Mon Sep 17 00:00:00 2001
From: eopXD 
Date: Wed, 15 Nov 2023 01:57:51 -0800
Subject: [PATCH] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16
 (#72216)"

This reverts commit 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d.
---
 clang/include/clang/Basic/RISCVVTypes.def | 56 ---
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 .../clang/Support/RISCVVIntrinsicUtils.h  |  5 +-
 clang/lib/Support/RISCVVIntrinsicUtils.cpp|  3 -
 .../rvv-intrinsic-datatypes.cpp   | 55 --
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 +-
 6 files changed, 4 insertions(+), 121 deletions(-)

diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 6620de8ad50e01e..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,62 +452,6 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
-//===- BFloat16 tuple types 
-===//
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
-   1, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
-   1, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
-   1, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
-   1, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
-   1, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
-   1, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
-   1, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
-   2, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
-   2, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
-   2, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
-   2, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
-   2, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
-   2, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
-   2, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
-   4, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
-   4, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
-   4, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
-   4, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
-   4, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
-   4, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
-   4, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
-   8, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
-   8, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
-   8, 16, 4)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
-   16, 16, 2)
-
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9044c46fc671963..5c32fbc079c9a65 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum P

[clang] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (PR #72367)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Yueh-Ting (eop) Chen (eopXD)


Changes

This reverts commit 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d. #72216 

This commit broke the multiple buildbots, looks like the extension in 
`NUM_PREDEF_TYPE_IDS` might have broken some inheriting usages, causing 
indeterminate results for the compiler. Investigating the issue now.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/RISCVVTypes.def (-56) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1-1) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+2-3) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (-3) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp 
(-55) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+1-3) 


``diff
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 6620de8ad50e01e..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,62 +452,6 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
-//===- BFloat16 tuple types 
-===//
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
-   1, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
-   1, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
-   1, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
-   1, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
-   1, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
-   1, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
-   1, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
-   2, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
-   2, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
-   2, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
-   2, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
-   2, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
-   2, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
-   2, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
-   4, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
-   4, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
-   4, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
-   4, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
-   4, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
-   4, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
-   4, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
-   8, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
-   8, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
-   8, 16, 4)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
-   16, 16, 2)
-
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9044c46fc671963..5c32fbc079c9a65 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 

[clang] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (PR #72367)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yueh-Ting (eop) Chen (eopXD)


Changes

This reverts commit 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d. #72216 

This commit broke the multiple buildbots, looks like the extension in 
`NUM_PREDEF_TYPE_IDS` might have broken some inheriting usages, causing 
indeterminate results for the compiler. Investigating the issue now.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/RISCVVTypes.def (-56) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1-1) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+2-3) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (-3) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp 
(-55) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+1-3) 


``diff
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 6620de8ad50e01e..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,62 +452,6 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
-//===- BFloat16 tuple types 
-===//
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
-   1, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
-   1, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
-   1, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
-   1, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
-   1, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
-   1, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
-   1, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
-   2, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
-   2, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
-   2, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
-   2, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
-   2, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
-   2, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
-   2, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
-   4, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
-   4, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
-   4, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
-   4, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
-   4, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
-   4, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
-   4, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
-   8, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
-   8, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
-   8, 16, 4)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
-   16, 16, 2)
-
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9044c46fc671963..5c32fbc079c9a65 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 600;
+co

[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-15 Thread Utkarsh Saxena via cfe-commits

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


[clang] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (PR #72367)

2023-11-15 Thread antoine moynault via cfe-commits

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


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


[clang] 5107a47 - Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (#72367)

2023-11-15 Thread via cfe-commits

Author: Yueh-Ting (eop) Chen
Date: 2023-11-15T18:05:07+08:00
New Revision: 5107a47fee9c95489d3743a53e9578407b0e3656

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

LOG: Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" 
(#72367)

This reverts commit 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d. #72216 

This commit broke the multiple buildbots, looks like the extension in
`NUM_PREDEF_TYPE_IDS` might have broken some inheriting usages, causing
indeterminate results for the compiler. Investigating the issue now.

Added: 


Modified: 
clang/include/clang/Basic/RISCVVTypes.def
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Support/RISCVVIntrinsicUtils.cpp

clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 6620de8ad50e01e..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,62 +452,6 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
-//===- BFloat16 tuple types 
-===//
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
-   1, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
-   1, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
-   1, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
-   1, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
-   1, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
-   1, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
-   1, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
-   2, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
-   2, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
-   2, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
-   2, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
-   2, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
-   2, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
-   2, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
-   4, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
-   4, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
-   4, 16, 4)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
-   4, 16, 5)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
-   4, 16, 6)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
-   4, 16, 7)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
-   4, 16, 8)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
-   8, 16, 2)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
-   8, 16, 3)
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
-   8, 16, 4)
-
-RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
-   16, 16, 2)
-
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9044c46fc671963..5c32fbc079c9a65 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/

[clang] Revert "[Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)" (PR #72367)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

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


[clang] 0f7f8db - [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (#72016)

2023-11-15 Thread via cfe-commits

Author: Ben Shi
Date: 2023-11-15T18:17:32+08:00
New Revision: 0f7f8dbcf5ec06cb1ea8912ffd234523f60a61be

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

LOG: [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in 
SimpleStreamChecker (#72016)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
clang/test/Analysis/stream-non-posix-function.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
index 32d95e944195390..2ac9f65c9793f45 100644
--- a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
@@ -90,7 +90,7 @@ class SimpleStreamChecker : public Checkerhttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (PR #72016)

2023-11-15 Thread Ben Shi via cfe-commits

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


[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD created https://github.com/llvm/llvm-project/pull/72370

This PR attempts to recommit the PR (#72216) with a safe-bounded TypeID that 
will not cause indeterminate results for the compiler.

>From 78e3ab20f5e527563b7645635b7147fdda8ba4b9 Mon Sep 17 00:00:00 2001
From: "Yueh-Ting (eop) Chen" 
Date: Wed, 15 Nov 2023 13:50:14 +0800
Subject: [PATCH 1/2] [Clang][RISCV] Introduce tuple types for RVV bfloat16
 (#72216)

The first commit extends the capacity from the compiler infrastructure,
and the second commit continues the effort in #71140 to introduce tuple
types for bfloat16.
---
 clang/include/clang/Basic/RISCVVTypes.def | 56 +++
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 .../clang/Support/RISCVVIntrinsicUtils.h  |  5 +-
 clang/lib/Support/RISCVVIntrinsicUtils.cpp|  3 +
 .../rvv-intrinsic-datatypes.cpp   | 55 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 +-
 6 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index af44cdcd53e5bd0..6620de8ad50e01e 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
+//===- BFloat16 tuple types 
-===//
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
+   1, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
+   1, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
+   1, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
+   1, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
+   1, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
+   1, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
+   1, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
+   2, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
+   2, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
+   2, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
+   2, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
+   2, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
+   2, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
+   2, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
+   4, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
+   4, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
+   4, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
+   4, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
+   4, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
+   4, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
+   4, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
+   8, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
+   8, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
+   8, 16, 4)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
+   16, 16, 2)
+
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5c32fbc079c9a65..9044c46fc671963 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs

[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Yueh-Ting (eop) Chen (eopXD)


Changes

This PR attempts to recommit the PR (#72216) with a safe-bounded TypeID 
that will not cause indeterminate results for the compiler.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/RISCVVTypes.def (+56) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1-1) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+3-2) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+3) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp 
(+55) 
- (modified) clang/utils/TableGen/RISCVVEmitter.cpp (+3-1) 


``diff
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index af44cdcd53e5bd0..6620de8ad50e01e 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
+//===- BFloat16 tuple types 
-===//
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
+   1, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
+   1, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
+   1, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
+   1, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
+   1, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
+   1, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
+   1, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
+   2, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
+   2, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
+   2, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
+   2, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
+   2, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
+   2, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
+   2, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
+   4, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
+   4, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
+   4, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
+   4, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
+   4, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
+   4, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
+   4, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
+   8, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
+   8, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
+   8, 16, 4)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
+   16, 16, 2)
+
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5c32fbc079c9a65..fdd64f2abbe9375 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 500;
+const unsigned NUM_PREDEF_TYPE_IDS = 502;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the 

[clang] da90fd7 - Reland "[llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (#72234)"

2023-11-15 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2023-11-15T10:26:35Z
New Revision: da90fd75241d5b149fd307e3eeae84f7317d9d9b

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

LOG: Reland "[llvm][DebugInfo] DWARFv5: static data members declarations are 
DW_TAG_variable (#72234)"

This was reverted because it broke the OCaml LLVM bindings.
Relanding the original patch but without changing the C-API.
They'll continue to work just fine as they do today. If in the
future there is a need to pass a new tag to the C-API for creating
static members, then we'll make the change to the OCaml bindings
at that time.

Original commit message:
"""
This patch adds the LLVM-side infrastructure to implement DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

The clang-side of this patch will simply construct the DIDerivedType
with a different DW_TAG.
"""

Added: 
llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/Verifier.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..a201cf03c22f711 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1681,7 +1681,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
+  llvm::dwarf::DW_TAG_member, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;

diff  --git a/llvm/include/llvm/IR/DIBuilder.h 
b/llvm/include/llvm/IR/DIBuilder.h
index ecd6dd7b0a4f822..2be133e85e8c1e4 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -376,11 +376,12 @@ namespace llvm {
 /// \param Ty Type of the static member.
 /// \param Flags  Flags to encode member attribute, e.g. private.
 /// \param ValConst initializer of the member.
+/// \param TagDWARF tag of the static member.
 /// \param AlignInBits  Member alignment.
 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
   DIFile *File, unsigned LineNo,
   DIType *Ty, DINode::DIFlags Flags,
-  Constant *Val,
+  Constant *Val, unsigned Tag,
   uint32_t AlignInBits = 0);
 
 /// Create debugging information entry for Objective-C

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17f8a880f6..58a7e07d9b58d86 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -405,12 +405,11 @@ DIDerivedType *
 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
   unsigned LineNumber, DIType *Ty,
   DINode::DIFlags Flags, llvm::Constant *Val,
-  uint32_t AlignInBits) {
+  unsigned Tag, uint32_t AlignInBits) {
   Flags |= DINode::FlagStaticMember;
-  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
-LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
-AlignInBits, 0, std::nullopt, Flags,
-getConstantOrNull(Val));
+  return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
+getNonCompileUnitScope(Scope), Ty, 0, AlignInBits,
+0, std::nullopt, Flags, getConstantOrNull(Val));
 }
 
 DIDerivedType *

diff  --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 390a27c4bc0c4dd..bb6d612638310f9 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1315,17 +1315,15 @@ LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef 
Builder, const char *Name,
   return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
 }
 
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,

[clang] [llvm] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Nikita Popov via cfe-commits

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

I don't like the overall approach of assembling this from individual byte-sized 
loads here. What I would expect to see is more something along these lines: If 
we find a clobbering store that a) only clobbers some subset of the loaded 
bytes and b) stores a constant, then try to find the next clobbering store from 
there, and continue doing this until we have found all the bytes being loaded.

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


[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Nikita Popov via cfe-commits

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


[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Nikita Popov via cfe-commits


@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, 
Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4

nikic wrote:

```suggestion
// define i32 @f(ptr %P)
// 1:  %b2 = getelementptr inbounds i8, ptr %P, i64 1
// 2:  store i8 0, ptr %b2, align 1
// 3:  store i8 0, ptr %P, align 1
// 5:  %L = load i16, ptr %P, align 4
```

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


[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Nikita Popov via cfe-commits


@@ -2128,6 +2129,105 @@ static void patchAndReplaceAllUsesWith(Instruction *I, 
Value *Repl) {
   I->replaceAllUsesWith(Repl);
 }
 
+// split load to single byte loads and check if the value can be deduced
+//
+// Example:
+// define i32 @f(i8* %P)
+// 1:  %b2 = getelementptr inbounds i8, i8* %P, i64 1
+// 2:  store i8 0, i8* %b2, align 1
+// 3:  store i8 0, i8* %P, align 1
+// 4:  %s1 = bitcast i8* %P to i16*
+// 5:  %L = load i16, i16* %s1, align 4
+//
+// The last clobbering write for the load is (3) but it doesn't cover the whole
+// read. So AnalyzeLoadAvailability would give up.
+// This function emit temporary byte-sized loads that cover the original load,
+// so that any last write covers the read. We run AnalyzeLoadAvailability on
+// each byte to try to construct the load as a constant.
+bool GVNPass::splitAndprocessLoad(LoadInst *L) {
+  if (L->isAtomic())
+return false;
+
+  Type *LTy = L->getType();
+  if (!LTy->isIntegerTy())
+return false;
+
+  unsigned BW = LTy->getIntegerBitWidth();
+  if (BW % 8)
+return false;
+
+  IntegerType *ByteTy = IntegerType::getInt8Ty(LTy->getContext());
+  Type *BytePtrTy = PointerType::get(ByteTy, L->getPointerAddressSpace());
+  BitCastInst *Base = new BitCastInst(L->getPointerOperand(), BytePtrTy, "", 
L);

nikic wrote:

Not necessary with opaque pointers.

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


[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72235

>From a933f170dcbdbaf76f93a15cdb1c1148d78a82e8 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 13 Nov 2023 09:48:39 +
Subject: [PATCH] [clang][DebugInfo] DWARFv5: static data members declarations
 are DW_TAG_variable

This patch implements the DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

This will simplify LLDB's handling of static data
members greatly in the long term since we no longer
need to differentiate non-static from static data
member declarations using non-portable heuristics.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  9 +++--
 .../debug-info-static-inline-member.cpp   |  4 +--
 .../CodeGenCXX/debug-info-static-member.cpp   | 36 ---
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a201cf03c22f711..f3de91d4a39ebee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1679,10 +1679,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
   StringRef VName = Var->getName();
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
-  llvm::dwarf::DW_TAG_member, Align);
+  llvm::DIDerivedType *GV =
+  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
+  Flags, /* Val */ nullptr, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index bfb7ad6b80fabf3..f2d4d9408a8297a 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -1,5 +1,5 @@
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited 
%s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
 
 enum class Enum : int {
   VAL = -1
diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 578995801c6400b..a2d25e98ed1cb62 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,7 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-5 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF5 %s
+// RUN: %clangxx -target x86_64-windows-msvc -g -gdwarf-4 %s -emit-llvm -S -o 
- | FileCheck --check-prefixes=CHECK,DWARF4 %s
 // PR14471
 
 // CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -39,17 +40,20 @@ class C
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF4: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF5: !DIDerivedType(tag: DW_TAG_variable, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_T

[llvm] [clang] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Nikita Popov via cfe-commits


@@ -0,0 +1,166 @@
+; RUN: opt -S -O3 < %s

nikic wrote:

GVN tests should use `-passes=gvn` only, not `-O3`.

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


[clang] [llvm] split load to bytes to deduce load value (PR #72364)

2023-11-15 Thread Sergey Kachkov via cfe-commits

skachkov-sc wrote:

I think we should also check this optimization for non-byte stores, e.g.
```
define i32 @f(ptr %ptr)
%ptr1 = getelementptr inbounds i8, ptr %ptr, i64 2
store i16 0, ptr %ptr, align 2
store i16 0, ptr %ptr1, align 2
%L = load i32, ptr %ptr, align 4
```
GVN should optimize the case when 1-byte load location is fully covered with 
2-byte store and extract the required byte from stored value, but it's good to 
check if reconstruction of 4-byte %L can be simplified after.

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


[llvm] [clang] [clang-tools-extra] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

2023-11-15 Thread via cfe-commits


@@ -163,7 +163,8 @@ class CopyTracker {
 
   /// Clobber a single register, removing it from the tracker's copy maps.
   void clobberRegister(MCRegister Reg, const TargetRegisterInfo &TRI,
-   const TargetInstrInfo &TII, bool UseCopyInstr) {
+   const TargetInstrInfo &TII, bool UseCopyInstr,
+   bool CleanUp = false) {

qcolombet wrote:

Could you add a comment for the `CleanUp` argument?

In particular, we need to make it clear why and when this argument needs to be 
set to true.
Without any explanation, I would expect that we need to actually set it to true 
all the time.

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


[clang] [llvm] [clang-tools-extra] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

2023-11-15 Thread via cfe-commits


@@ -784,18 +813,33 @@ void 
MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
 // %xmm2 = copy %xmm0
 // ...
 // %xmm2 = copy %xmm9
-Tracker.clobberRegister(Def, *TRI, *TII, UseCopyInstr);
+
+// While we do need to clobber the register here, simply clobbering it
+// is not sufficient. We also need to remove the COPY record pair for
+// 'Def' in the tracker. Failing to do so might cause the target to 
miss
+// some opportunities to eliminate redundant copy instructions.
+
+// Consider the following sequence:
+// L1: r0 = COPY r9 <- TrackMI
+// L2: r0 = COPY r8 <- TrackMI
+// L3: use r0   <- Remove L2 from MaybeDeadCopies
+// L4: early-clobber r9 <- Invalid L2 from Tracker
+// L5: r0 = COPY r8 <- Miss remove chance
+// L6: use r0   <- Miss remove L5 chance

qcolombet wrote:

Rewrite this comment to explain what will happen now.
Not what was happening before this patch.

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


[clang] faa3a5e - [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (#72235)

2023-11-15 Thread via cfe-commits

Author: Michael Buch
Date: 2023-11-15T11:01:39Z
New Revision: faa3a5ea9ae481da757dab1c95c589e2d5645982

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

LOG: [clang][DebugInfo] DWARFv5: static data members declarations are 
DW_TAG_variable (#72235)

This patch implements the DWARFv5 issue 161118.1: "DW_TAG for C++ static
data members".

This will simplify LLDB's handling of static data members greatly in the
long term since we no longer need to differentiate non-static from
static data member declarations using non-portable heuristics.

Depends on:
* https://github.com/llvm/llvm-project/pull/72234

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
clang/test/CodeGenCXX/debug-info-static-member.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a201cf03c22f711..f3de91d4a39ebee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1679,10 +1679,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
   StringRef VName = Var->getName();
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
-  llvm::dwarf::DW_TAG_member, Align);
+  llvm::DIDerivedType *GV =
+  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
+  Flags, /* Val */ nullptr, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;

diff  --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index bfb7ad6b80fabf3..f2d4d9408a8297a 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -1,5 +1,5 @@
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited 
%s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
 
 enum class Enum : int {
   VAL = -1

diff  --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 578995801c6400b..a2d25e98ed1cb62 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,7 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-5 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF5 %s
+// RUN: %clangxx -target x86_64-windows-msvc -g -gdwarf-4 %s -emit-llvm -S -o 
- | FileCheck --check-prefixes=CHECK,DWARF4 %s
 // PR14471
 
 // CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -39,17 +40,20 @@ class C
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF4: !D

[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-15 Thread Michael Buch via cfe-commits

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


[flang] [clang] [Flang][Clang] Add support for frame pointers in Flang (PR #72146)

2023-11-15 Thread Radu Salavat via cfe-commits

https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/72146

>From 0b0f02eab4dc02adf79461bc865be6f7580938cf Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Mon, 13 Nov 2023 17:49:06 +
Subject: [PATCH 1/3] [Flang][Clang] Add support for frame pointers in Flang

---
 clang/include/clang/Driver/Options.td |  14 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 133 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 ++
 clang/lib/Driver/ToolChains/CommonArgs.h  |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |  19 +++
 .../include/flang/Frontend/CodeGenOptions.def |   1 +
 flang/include/flang/Frontend/CodeGenOptions.h |  23 +++
 flang/include/flang/Tools/CrossToolHelpers.h  |   2 +
 flang/lib/Frontend/CompilerInvocation.cpp |  13 ++
 flang/lib/Frontend/FrontendActions.cpp|   5 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 13 files changed, 222 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..bf99786d017b318 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3147,7 +3147,8 @@ def fno_ms_compatibility : Flag<["-"], 
"fno-ms-compatibility">, Group,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
+def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group,
+  Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
   LangOpts<"CXXOperatorNames">, Default,
   NegFlag>;
 
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Omit the frame pointer from functions that don't need it. "
   "Some stack unwinding cases, such as profilers and sanitizers, may prefer 
specifying -fno-omit-frame-pointer. "
   "On many targets, -O1 and higher omit the frame pointer by default. "
@@ -6752,10 +6754,7 @@ def new_struct_path_tbaa : Flag<["-"], 
"new-struct-path-tbaa">,
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">,
   MarshallingInfoString>;
-def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
-  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
-  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
-  MarshallingInfoEnum, "None">;
+
 def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
   HelpText<"Use IEEE 754 quadruple-precision for long double">,
   MarshallingInfoFlag>;
@@ -7368,6 +7367,11 @@ def pic_level : Separate<["-"], "pic-level">,
 def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
+  
+def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
+  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
+  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
+  MarshallingInfoEnum, "None">;
 
 } // let Visibility = [CC1Option, FC1Option]
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..3273bd1d2c0c6fa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -409,139 +409,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
-  switch (Triple.getArch()){
-  default:
-return false;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-// ARM Darwin targets require a frame pointer to be always present to aid
-// offline debugging via backtraces.
-return Triple.isOSDarwin();
-  }
-}
-
-static bool useFramePointerForTargetByDefault(const ArgList &Args,
-  const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
-return true;
-
-  if (Triple.isAndroid()) {
-switch (Triple.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::riscv64:
-  return true;
-default:
-  break;
-}
-  }
-
-  switch (Triple.getArch()) {
-  case llvm::Triple::xcore:
-  case llvm::Triple::wasm32:
-  case llvm::Triple::wasm64:
-  case llvm::Triple::msp430:
-// XCore never wants frame pointers, regardless of OS.
-// WebAssembly never wants

[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-11-15 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/71953

>From 79c05d1f8554d5a4469b9501b61b47863f086ffa Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Fri, 10 Nov 2023 13:40:31 +
Subject: [PATCH 1/2] Add SME2 builtins for pfalse and ptrue

Extend pfalse and ptrue builtins with svcount_t return types
to be enabled for sve2p1 and sme2
---
 clang/include/clang/Basic/arm_sve.td  |  7 ++--
 clang/lib/Sema/Sema.cpp   |  3 +-
 .../acle_sme2_ptrue_pfalse_attr.c | 34 +++
 3 files changed, 41 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ptrue_pfalse_attr.c

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 3d4c2129565903d..eccf87ac94abb3f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1861,8 +1861,6 @@ def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", 
MergeNone, "aarch64_sv
 
 let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
-def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
-def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
 
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;
@@ -1981,6 +1979,11 @@ def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", 
"QcQsQiQl", MergeNone, "aarch64_sv
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
+  def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
+}
+
 

 // SME2
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d7d8d2eaa37e1d6..e4f6a291a869c27 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2084,7 +2084,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
   llvm::StringMap CallerFeatureMap;
   Context.getFunctionFeatureMap(CallerFeatureMap, FD);
   if (!Builtin::evaluateRequiredTargetFeatures(
-  "sve", CallerFeatureMap))
+  "sve", CallerFeatureMap) && !Builtin::evaluateRequiredTargetFeatures(
+  "sme", CallerFeatureMap))
 Diag(D->getLocation(), diag::err_sve_vector_in_non_sve_target) << Ty;
 }
   };
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ptrue_pfalse_attr.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ptrue_pfalse_attr.c
new file mode 100644
index 000..90d9434d87cf4a0
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ptrue_pfalse_attr.c
@@ -0,0 +1,34 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+// CHECK-LABEL: @test_svptrue_c8_attr(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svptrue_c8_attrv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svptrue_c8_attr(void) __arm_streaming {
+  return svptrue_c8();
+}
+
+// CHECK-LABEL: @test_svptrue_c(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z14test_svptrue_cv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.convert.from.svbool.taarch64.svcountt( 
zeroinitializer)
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svptrue_c(void) __arm_streaming {
+  return svpfalse_c();
+}

>From 00cbdbc4fcc3f523238d5082b3636fab2d1224f6 Mon Sep 17

[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-11-15 Thread Matthew Devereau via cfe-commits


@@ -0,0 +1,34 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+// CHECK-LABEL: @test_svptrue_c8_attr(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svptrue_c8_attrv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call target("aarch64.svcount") 
@llvm.aarch64.sve.ptrue.c8()
+// CPP-CHECK-NEXT:ret target("aarch64.svcount") [[TMP0]]
+//
+svcount_t test_svptrue_c8_attr(void) __arm_streaming {

MDevereau wrote:

As discussed we might be missing an HasSVE2p1OrSME2 target guard which is 
currently stopping me from doing this in this patch

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


[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-11-15 Thread Matthew Devereau via cfe-commits


@@ -1981,6 +1979,11 @@ def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", 
"QcQsQiQl", MergeNone, "aarch64_sv
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
+  def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;

MDevereau wrote:

Done

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


[clang] Add SME2 builtins for pfalse and ptrue (PR #71953)

2023-11-15 Thread Matthew Devereau via cfe-commits

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-15 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Is there any actual difference now between these and the HIP/OpenCL flavors 
> other than dropping the language from the name?

Yes, these directly copy the GNU functions and names. The OpenCL / HIP ones use 
a different format.

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-15 Thread Joseph Huber via cfe-commits


@@ -798,6 +798,13 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
   Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
 
+  // Define macros for the clang atomic scopes.
+  Builder.defineMacro("__MEMORY_SCOPE_SYSTEM", "0");
+  Builder.defineMacro("__MEMORY_SCOPE_DEVICE", "1");
+  Builder.defineMacro("__MEMORY_SCOPE_WRKGRP", "2");
+  Builder.defineMacro("__MEMORY_SCOPE_WVFRNT", "3");
+  Builder.defineMacro("__MEMORY_SCOPE_SINGLE", "4");
+

jhuber6 wrote:

We could, though I might need to think of some better names. It's difficult to 
cover all the cases people might need. I think that cleanup would best be done 
in a follow-up patch.

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-15 Thread Joseph Huber via cfe-commits


@@ -205,6 +220,56 @@ class AtomicScopeHIPModel : public AtomicScopeModel {
   }
 };
 
+/// Defines the generic atomic scope model.
+class AtomicScopeGenericModel : public AtomicScopeModel {
+public:
+  /// The enum values match predefined built-in macros __ATOMIC_SCOPE_*.
+  enum ID {
+System = 0,
+Device = 1,
+Workgroup = 2,
+Wavefront = 3,
+Single = 4,
+Last = Single
+  };
+
+  AtomicScopeGenericModel() = default;
+
+  SyncScope map(unsigned S) const override {
+switch (static_cast(S)) {
+case Device:
+  return SyncScope::DeviceScope;
+case System:
+  return SyncScope::SystemScope;
+case Workgroup:
+  return SyncScope::WorkgroupScope;
+case Wavefront:
+  return SyncScope::WavefrontScope;
+case Single:
+  return SyncScope::SingleScope;
+}
+llvm_unreachable("Invalid language sync scope value");

jhuber6 wrote:

Mostly just copying the existing code for this, but we have semantic checks to 
ensure that the value is valid. So there's no chance that a user will actually 
get to specify anything different from the macros provided.

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-15 Thread Joseph Huber via cfe-commits


@@ -54,6 +59,16 @@ enum class SyncScope {
 
 inline llvm::StringRef getAsString(SyncScope S) {

jhuber6 wrote:

I think it's because this is for AST printing purposes, while the backend 
strings vary per target.

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-15 Thread Joseph Huber via cfe-commits


@@ -904,6 +904,32 @@ BUILTIN(__atomic_signal_fence, "vi", "n")
 BUILTIN(__atomic_always_lock_free, "bzvCD*", "nE")
 BUILTIN(__atomic_is_lock_free, "bzvCD*", "nE")
 
+// GNU atomic builtins with atomic scopes.
+ATOMIC_BUILTIN(__scoped_atomic_load, "v.", "t")

jhuber6 wrote:

Naming things is hard, we could do
```
__atomic_scoped_load
__scoped_atomic_load
__atomic_load_scoped
```
Unsure which is the best.

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


[flang] [libcxx] [lldb] [compiler-rt] [libc] [clang] [clang-tools-extra] [llvm] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-11-15 Thread Aaron Ballman via cfe-commits

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


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2023-11-15 Thread Björn Schäpers via cfe-commits

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


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


[clang] c3329b1 - [clang][Interp][NFC] Limit Pointer::isArrayElement() to actual arrays

2023-11-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-11-15T13:40:16+01:00
New Revision: c3329b1cac3158bba62aab14d648b9dc615f8c67

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

LOG: [clang][Interp][NFC] Limit Pointer::isArrayElement() to actual arrays

Similar to what we do in isArrayRoot() - only return true here if the
Pointee is actually of array type.

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 843bcad16b5d1e3..a8f6e62fa76d356 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -279,7 +279,7 @@ class Pointer {
 return getFieldDesc()->isUnknownSizeArray();
   }
   /// Checks if the pointer points to an array.
-  bool isArrayElement() const { return Base != Offset; }
+  bool isArrayElement() const { return inArray() && Base != Offset; }
   /// Pointer points directly to a block.
   bool isRoot() const {
 return (Base == 0 || Base == RootPtrMark) && Offset == 0;



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


[lldb] [mlir] [openmp] [libc] [clang] [libcxx] [flang] [llvm] [clang-tools-extra] GlobalISel: Guard return in llvm::getIConstantSplatVal (PR #71989)

2023-11-15 Thread via cfe-commits


@@ -1116,9 +1116,9 @@ std::optional
 llvm::getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI) 
{
   if (auto SplatValAndReg =
   getAnyConstantSplat(Reg, MRI, /* AllowUndef */ false)) {
-std::optional ValAndVReg =
-getIConstantVRegValWithLookThrough(SplatValAndReg->VReg, MRI);
-return ValAndVReg->Value;
+if (std::optional ValAndVReg =

qcolombet wrote:

@changpeng 
A comment here would be nice.
E.g., "Even if the value is a splat constant, it may not be an integer one."

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


[flang] [clang-tools-extra] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits

https://github.com/PAX-12-WU updated 
https://github.com/llvm/llvm-project/pull/70917

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 1/6] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e5538..cfe5dcd141e9821 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31a4..830df7ad006b54a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec6289390545479..1c212ef61697cd5 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb79..d199d5e387b8648 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571b..6b2f313e227a196 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {

[mlir] [clang] [llvm] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-15 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68565

>From 83e20904c206980285c4ee9d0227706803147654 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 01/12] [AArch64][SME] Remove immediate argument restriction
 for svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, since the instructions
take an immediate vector number. However, we emit 0 as the immediate
for the instruction no matter what, and instead modify the base register.

This patch removes that restriction on the argument, so that the
argument can be a non-immediate. If an appropriate immediate was
passed to the builtin then CGBuiltin passes that directly to the LLVM
intrinsic, otherwise it modifies the base register as is existing
behaviour.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 45 
 .../aarch64-sme-intrinsics/acle_sme_ldr.c | 71 ---
 .../aarch64-sme-intrinsics/acle_sme_str.c | 51 -
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 10 +--
 .../CostModel/ARM/unaligned_double_load.ll| 59 +++
 .../CodeGen/AArch64/sme-intrinsics-loads.ll   | 33 +++--
 7 files changed, 165 insertions(+), 106 deletions(-)
 create mode 100644 llvm/test/Analysis/CostModel/ARM/unaligned_double_load.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 09309a3937fb613..8444aea8c8ac4b6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9815,6 +9815,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   return Store;
 }
 
+Value *CodeGenFunction::EmitTileslice(Value *Offset, Value *Base) {
+  llvm::Value *CastOffset = Builder.CreateIntCast(Offset, Int64Ty, false);
+  return Builder.CreateAdd(Base, CastOffset, "tileslice");
+}
+
 Value *CodeGenFunction::EmitSMELd1St1(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
@@ -9870,18 +9875,34 @@ Value *CodeGenFunction::EmitSMEZero(const SVETypeFlags 
&TypeFlags,
 Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
-  if (Ops.size() == 3) {
-Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
-llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-
-llvm::Value *VecNum = Ops[2];
-llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
-
-Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(
-Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true), "tileslice");
-Ops.erase(&Ops[2]);
-  }
+  if (Ops.size() == 2) {
+// Intrinsics without a vecnum also use this function, so just provide 0
+Ops.push_back(Ops[1]);
+Ops[1] = Builder.getInt32(0);
+  } else {
+int Imm = -1;
+if (ConstantInt* C = dyn_cast(Ops[2]))
+  if (C->getZExtValue() <= 15)
+  Imm = C->getZExtValue();
+
+if (Imm != -1) {
+  Ops[2] = Ops[1];
+  Ops[1] = Builder.getInt32(Imm);
+} else {
+  Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
+  llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
+
+  llvm::Value *VecNum = Ops[2];
+  llvm::Value *MulVL = Builder.CreateMul(
+  CntsbCall,
+  VecNum,
+  "mulvl");
+
+  Ops[2] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
+  Ops[1] = Builder.getInt32(0);
+  Ops[0] = Builder.CreateIntCast(EmitTileslice(Ops[0], VecNum), Int32Ty, 
false);
+}
+   }
   Function *F = CGM.getIntrinsic(IntID, {});
   return Builder.CreateCall(F, Ops);
 }
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index e85c47072f2df80..8e07cf1d11c19b2 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -6,57 +6,46 @@
 
 #include 
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z18test_svldr_vnum_zajPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-CXX-NEXT:ret void
+// CHECK-C-LABEL: @test_svldr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svldr_vnum_zaj

[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2023-11-15 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> So, while it's possible to create a combined option, using a separate option 
> also makes sense. Do we generally try to avoid creating new command-line 
> options?

Looking again, I see they are different and unrelated. I don't really 
understand why we have amdgpu-waitcnt-forcezero, I'm not sure I've ever used 
it. I always expected it to behave like this flag.



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


[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD updated https://github.com/llvm/llvm-project/pull/72370

>From 78e3ab20f5e527563b7645635b7147fdda8ba4b9 Mon Sep 17 00:00:00 2001
From: "Yueh-Ting (eop) Chen" 
Date: Wed, 15 Nov 2023 13:50:14 +0800
Subject: [PATCH 1/3] [Clang][RISCV] Introduce tuple types for RVV bfloat16
 (#72216)

The first commit extends the capacity from the compiler infrastructure,
and the second commit continues the effort in #71140 to introduce tuple
types for bfloat16.
---
 clang/include/clang/Basic/RISCVVTypes.def | 56 +++
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 .../clang/Support/RISCVVIntrinsicUtils.h  |  5 +-
 clang/lib/Support/RISCVVIntrinsicUtils.cpp|  3 +
 .../rvv-intrinsic-datatypes.cpp   | 55 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 +-
 6 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index af44cdcd53e5bd0..6620de8ad50e01e 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
+//===- BFloat16 tuple types 
-===//
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
+   1, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
+   1, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
+   1, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
+   1, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
+   1, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
+   1, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
+   1, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
+   2, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
+   2, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
+   2, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
+   2, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
+   2, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
+   2, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
+   2, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
+   4, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
+   4, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
+   4, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
+   4, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
+   4, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
+   4, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
+   4, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
+   8, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
+   8, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
+   8, 16, 4)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
+   16, 16, 2)
+
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5c32fbc079c9a65..9044c46fc671963 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 500;
+const unsigned NUM_PREDE

[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD updated https://github.com/llvm/llvm-project/pull/72370

>From 78e3ab20f5e527563b7645635b7147fdda8ba4b9 Mon Sep 17 00:00:00 2001
From: "Yueh-Ting (eop) Chen" 
Date: Wed, 15 Nov 2023 13:50:14 +0800
Subject: [PATCH 1/3] [Clang][RISCV] Introduce tuple types for RVV bfloat16
 (#72216)

The first commit extends the capacity from the compiler infrastructure,
and the second commit continues the effort in #71140 to introduce tuple
types for bfloat16.
---
 clang/include/clang/Basic/RISCVVTypes.def | 56 +++
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 .../clang/Support/RISCVVIntrinsicUtils.h  |  5 +-
 clang/lib/Support/RISCVVIntrinsicUtils.cpp|  3 +
 .../rvv-intrinsic-datatypes.cpp   | 55 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 +-
 6 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index af44cdcd53e5bd0..6620de8ad50e01e 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
+//===- BFloat16 tuple types 
-===//
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
+   1, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
+   1, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
+   1, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
+   1, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
+   1, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
+   1, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
+   1, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
+   2, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
+   2, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
+   2, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
+   2, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
+   2, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
+   2, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
+   2, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
+   4, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
+   4, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
+   4, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
+   4, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
+   4, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
+   4, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
+   4, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
+   8, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
+   8, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
+   8, 16, 4)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
+   16, 16, 2)
+
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5c32fbc079c9a65..9044c46fc671963 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 500;
+const unsigned NUM_PREDE

[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread Yueh-Ting Chen via cfe-commits

eopXD wrote:

@antmox The test case failure should be resolved with the latest commit. Its 
not any indeterminate result detected by CI, just that I missed an update to 
the test case that is expecting deterministic TypeID.

If CI passed, based on previous approval, should be good and safe to land it.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-15 Thread Utkarsh Saxena via cfe-commits


@@ -15811,6 +15813,32 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+// Return whether FD is `promise_type::get_return_object`.
+bool isGetReturnObject(FunctionDecl *FD) {
+  if (!FD->getDeclName().isIdentifier() ||
+  !FD->getName().equals("get_return_object") || !FD->param_empty())
+return false;
+  CXXMethodDecl *MD = dyn_cast(FD);
+  if (!MD || !MD->isCXXInstanceMember())
+return false;
+  RecordDecl *PromiseType = MD->getParent();
+  return PromiseType && PromiseType->getDeclName().isIdentifier() &&

usx95 wrote:

Don't know what was I thinking. Thanks.

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


[clang-tools-extra] [clang-tidy] Add new modernize-string-find-startswith check (PR #72385)

2023-11-15 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank created 
https://github.com/llvm/llvm-project/pull/72385

Matchers are copied over from abseil-string-find-startswith, only the error 
message is different and suggests `std::{string|string_view}::starts_with` 
instead of the Abseil equivalent.

>From 5e5a2bac0f7373e6b1830fddc609e97dc61df9d4 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 15 Nov 2023 01:13:10 -0800
Subject: [PATCH] [clang-tidy] Add new modernize-string-find-startswith check

Matchers are copied over from abseil-string-find-startswith, only the error
message is different and suggests `std::{string|string_view}::starts_with`
instead of the Abseil equivalent.
---
 .../abseil/StringFindStartswithCheck.h|   5 +-
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/StringFindStartswithCheck.cpp   | 111 ++
 .../modernize/StringFindStartswithCheck.h |  41 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 ++
 .../checks/abseil/string-find-startswith.rst  |   4 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../modernize/string-find-startswith.rst  |  32 +
 .../abseil/string-find-startswith.cpp |   2 +-
 .../modernize/string-find-startswith.cpp  |  77 
 11 files changed, 283 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/string-find-startswith.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/string-find-startswith.cpp

diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
index 923b5caece5439b..5019b7000f1d062 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
@@ -21,7 +21,6 @@ namespace clang::tidy::abseil {
 
 // Find string.find(...) == 0 comparisons and suggest replacing with 
StartsWith.
 // FIXME(niko): Add similar check for EndsWith
-// FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
 class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+// Prefer modernize-string-find-startswith when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 
 private:
   const std::vector StringLikeClasses;
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..541f58304119856 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTidyModernizeModule
   ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
+  StringFindStartswithCheck.cpp
   TypeTraitsCheck.cpp
   UnaryStaticAssertCheck.cpp
   UseAutoCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..1fcbff79ddc6f96 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
+#include "StringFindStartswithCheck.h"
 #include "TypeTraitsCheck.h"
 #include "UnaryStaticAssertCheck.h"
 #include "UseAutoCheck.h"
@@ -66,6 +67,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-string-find-startswith");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
 "modernize-raw-string-literal");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
new file mode 100644
index 000..7b992d77d0e7bb5
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
@@ -0,0 +1,111 @@
+//===--- StringFindStartswithCheck.cpp - clang-tidy 
---

[clang-tools-extra] [clang-tidy] Add new modernize-string-find-startswith check (PR #72385)

2023-11-15 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 2060bfcdc7eb704647c64bf925cdceb94c1f535f 
5e5a2bac0f7373e6b1830fddc609e97dc61df9d4 -- 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.h 
clang-tools-extra/test/clang-tidy/checkers/modernize/string-find-startswith.cpp 
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-startswith.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
index 7b992d77d0..74f59b9fce 100644
--- a/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
@@ -92,7 +92,7 @@ void StringFindStartswithCheck::check(const 
MatchFinder::MatchResult &Result) {
   Context.getLangOpts());
 
   const auto ReplacementCode = (Neg ? "!" : "") + HaystackExprCode +
-   ".starts_with(" + NeedleExprCode + ")";
+   ".starts_with(" + NeedleExprCode + ")";
 
   diag(ComparisonExpr->getBeginLoc(),
"use starts_with "

``




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


[clang-tools-extra] [llvm] [clang] Dont alter cold function alignment unless using Os (PR #72387)

2023-11-15 Thread Phil Camp via cfe-commits

https://github.com/FlameTop created 
https://github.com/llvm/llvm-project/pull/72387

This PR alters the behaviour of function alignment for functions marked as 
'cold'. Currently functions marked with a ‘cold’ attribute are also set as 
optimize by size. Optimize by size alters the function alignment from default. 
This interferes with code replacement features on our targets. This PR allows 
cold functions to maintain their default alignment except when optimize by size 
is explicitly used.

>From 49dd8a3a61ce29e71c3dcc81358c260dc2e37912 Mon Sep 17 00:00:00 2001
From: Phil Camp 
Date: Wed, 15 Nov 2023 13:12:33 +
Subject: [PATCH] Dont alter cold function alignment unless Os used

---
 clang/lib/CodeGen/CodeGenModule.cpp  |  3 ++
 clang/test/CodeGen/cold-align.cpp| 32 +
 llvm/include/llvm/IR/Attributes.td   |  1 +
 llvm/lib/CodeGen/MachineFunction.cpp |  3 +-
 llvm/test/CodeGen/X86/cold-align.ll  | 52 
 5 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/cold-align.cpp
 create mode 100644 llvm/test/CodeGen/X86/cold-align.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 75355282878f2f3..447748bf7fa90fb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2409,6 +2409,9 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!ShouldAddOptNone)
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
+  // dont alter alignment if not optimizing for size
+  if (!CodeGenOpts.OptimizeSize)
+B.addAttribute("keepalign", "true");
 }
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::Hot);
diff --git a/clang/test/CodeGen/cold-align.cpp 
b/clang/test/CodeGen/cold-align.cpp
new file mode 100644
index 000..93564d181d65d96
--- /dev/null
+++ b/clang/test/CodeGen/cold-align.cpp
@@ -0,0 +1,32 @@
+// Dont alter function alignment if marked cold
+//
+// Cold attribute marks functions as also optimize for size. This normally 
collapses the
+// default function alignment. This can interfere with edit&continue 
effectiveness.
+//
+// RUN: %clang -O2 -S -emit-llvm %s -o - | FileCheck %s -check-prefixes TWO
+// RUN: %clang -Os -S -emit-llvm %s -o - | FileCheck %s -check-prefixes 
SIZE
+
+class Dismissed
+{
+public:
+  __attribute__((cold)) void Chilly();
+void Temparate();
+  __attribute__((hot))  void Sizzle();
+};
+void Dismissed::Chilly(){};
+void Dismissed::Temparate(){};
+void Dismissed::Sizzle(){};
+
+// TWO: attributes #0 = {
+// TWO: "keepalign"="true"
+// TWO: attributes #1 = {
+// TWO-NOT: "keepalign"="true"
+// TWO: attributes #2 = {
+// TWO-NOT: "keepalign"="true"
+
+// SIZE: attributes #0 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #1 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #2 = {
+// SIZE-NOT: "keepalign"="true"
\ No newline at end of file
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index fc38e68ad273b6b..30844f566786c37 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -332,6 +332,7 @@ def NoJumpTables : StrBoolAttr<"no-jump-tables">;
 def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">;
 def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
 def UseSampleProfile : StrBoolAttr<"use-sample-profile">;
+def KeepAlign: StrBoolAttr<"keepalign">;
 
 def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>;
 def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>;
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp 
b/llvm/lib/CodeGen/MachineFunction.cpp
index 07eb0ba7f45c2e3..ab5392a05fc019b 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -214,7 +214,8 @@ void MachineFunction::init() {
 
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
   // FIXME: Use Function::hasOptSize().
-  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
+  if ((!F.hasFnAttribute(Attribute::OptimizeForSize)) ||
+ (F.getFnAttribute("keepalign").getValueAsBool()))
 Alignment = std::max(Alignment,
  STI->getTargetLowering()->getPrefFunctionAlignment());
 
diff --git a/llvm/test/CodeGen/X86/cold-align.ll 
b/llvm/test/CodeGen/X86/cold-align.ll
new file mode 100644
index 000..ab1f393dfa561ab
--- /dev/null
+++ b/llvm/test/CodeGen/X86/cold-align.ll
@@ -0,0 +1,52 @@
+;  Dont alter function alignment if marked cold
+;
+;  Cold attribute marks functions as also optimize for size. This normally 
collapses the
+;  default function alignment. This can interfere with edit&continue 
effectiveness.
+;
+;
+;  RUN: llc -O2 <%s | FileCheck %s -check-prefixes TWO
+;
+;  TWO: .globl _ZN9Dismissed6ChillyEv
+;  TWO-NEXT: .p2align 4, 0x90
+;  TWO: .globl _ZN9

[llvm] [clang] [clang-tools-extra] Dont alter cold function alignment unless using Os (PR #72387)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Phil Camp (FlameTop)


Changes

This PR alters the behaviour of function alignment for functions marked as 
'cold'. Currently functions marked with a ‘cold’ attribute are also set as 
optimize by size. Optimize by size alters the function alignment from default. 
This interferes with code replacement features on our targets. This PR allows 
cold functions to maintain their default alignment except when optimize by size 
is explicitly used.

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


5 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+3) 
- (added) clang/test/CodeGen/cold-align.cpp (+32) 
- (modified) llvm/include/llvm/IR/Attributes.td (+1) 
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+2-1) 
- (added) llvm/test/CodeGen/X86/cold-align.ll (+52) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f1b900be74b2cdf..450729937740934 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2410,6 +2410,9 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!ShouldAddOptNone)
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
+  // dont alter alignment if not optimizing for size
+  if (!CodeGenOpts.OptimizeSize)
+B.addAttribute("keepalign", "true");
 }
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::Hot);
diff --git a/clang/test/CodeGen/cold-align.cpp 
b/clang/test/CodeGen/cold-align.cpp
new file mode 100644
index 000..93564d181d65d96
--- /dev/null
+++ b/clang/test/CodeGen/cold-align.cpp
@@ -0,0 +1,32 @@
+// Dont alter function alignment if marked cold
+//
+// Cold attribute marks functions as also optimize for size. This normally 
collapses the
+// default function alignment. This can interfere with edit&continue 
effectiveness.
+//
+// RUN: %clang -O2 -S -emit-llvm %s -o - | FileCheck %s -check-prefixes TWO
+// RUN: %clang -Os -S -emit-llvm %s -o - | FileCheck %s -check-prefixes 
SIZE
+
+class Dismissed
+{
+public:
+  __attribute__((cold)) void Chilly();
+void Temparate();
+  __attribute__((hot))  void Sizzle();
+};
+void Dismissed::Chilly(){};
+void Dismissed::Temparate(){};
+void Dismissed::Sizzle(){};
+
+// TWO: attributes #0 = {
+// TWO: "keepalign"="true"
+// TWO: attributes #1 = {
+// TWO-NOT: "keepalign"="true"
+// TWO: attributes #2 = {
+// TWO-NOT: "keepalign"="true"
+
+// SIZE: attributes #0 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #1 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #2 = {
+// SIZE-NOT: "keepalign"="true"
\ No newline at end of file
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index fc38e68ad273b6b..30844f566786c37 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -332,6 +332,7 @@ def NoJumpTables : StrBoolAttr<"no-jump-tables">;
 def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">;
 def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
 def UseSampleProfile : StrBoolAttr<"use-sample-profile">;
+def KeepAlign: StrBoolAttr<"keepalign">;
 
 def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>;
 def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>;
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp 
b/llvm/lib/CodeGen/MachineFunction.cpp
index 07eb0ba7f45c2e3..ab5392a05fc019b 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -214,7 +214,8 @@ void MachineFunction::init() {
 
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
   // FIXME: Use Function::hasOptSize().
-  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
+  if ((!F.hasFnAttribute(Attribute::OptimizeForSize)) ||
+ (F.getFnAttribute("keepalign").getValueAsBool()))
 Alignment = std::max(Alignment,
  STI->getTargetLowering()->getPrefFunctionAlignment());
 
diff --git a/llvm/test/CodeGen/X86/cold-align.ll 
b/llvm/test/CodeGen/X86/cold-align.ll
new file mode 100644
index 000..ab1f393dfa561ab
--- /dev/null
+++ b/llvm/test/CodeGen/X86/cold-align.ll
@@ -0,0 +1,52 @@
+;  Dont alter function alignment if marked cold
+;
+;  Cold attribute marks functions as also optimize for size. This normally 
collapses the
+;  default function alignment. This can interfere with edit&continue 
effectiveness.
+;
+;
+;  RUN: llc -O2 <%s | FileCheck %s -check-prefixes TWO
+;
+;  TWO: .globl _ZN9Dismissed6ChillyEv
+;  TWO-NEXT: .p2align 4, 0x90
+;  TWO: .globl _ZN9Dismissed9TemparateEv
+;  TWO-NEXT: .p2align 4, 0x90
+;  TWO: .globl _ZN9Dismissed6SizzleEv
+;  TWO-NEXT: .p2align 4, 0x90
+
+; ModuleID = 'cold-align.cpp'
+source_filename = "cold-align.cpp"
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:6

[clang-tools-extra] [llvm] [clang] Dont alter cold function alignment unless using Os (PR #72387)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Phil Camp (FlameTop)


Changes

This PR alters the behaviour of function alignment for functions marked as 
'cold'. Currently functions marked with a ‘cold’ attribute are also set as 
optimize by size. Optimize by size alters the function alignment from default. 
This interferes with code replacement features on our targets. This PR allows 
cold functions to maintain their default alignment except when optimize by size 
is explicitly used.

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


5 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+3) 
- (added) clang/test/CodeGen/cold-align.cpp (+32) 
- (modified) llvm/include/llvm/IR/Attributes.td (+1) 
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+2-1) 
- (added) llvm/test/CodeGen/X86/cold-align.ll (+52) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f1b900be74b2cdf..450729937740934 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2410,6 +2410,9 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!ShouldAddOptNone)
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
+  // dont alter alignment if not optimizing for size
+  if (!CodeGenOpts.OptimizeSize)
+B.addAttribute("keepalign", "true");
 }
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::Hot);
diff --git a/clang/test/CodeGen/cold-align.cpp 
b/clang/test/CodeGen/cold-align.cpp
new file mode 100644
index 000..93564d181d65d96
--- /dev/null
+++ b/clang/test/CodeGen/cold-align.cpp
@@ -0,0 +1,32 @@
+// Dont alter function alignment if marked cold
+//
+// Cold attribute marks functions as also optimize for size. This normally 
collapses the
+// default function alignment. This can interfere with edit&continue 
effectiveness.
+//
+// RUN: %clang -O2 -S -emit-llvm %s -o - | FileCheck %s -check-prefixes TWO
+// RUN: %clang -Os -S -emit-llvm %s -o - | FileCheck %s -check-prefixes 
SIZE
+
+class Dismissed
+{
+public:
+  __attribute__((cold)) void Chilly();
+void Temparate();
+  __attribute__((hot))  void Sizzle();
+};
+void Dismissed::Chilly(){};
+void Dismissed::Temparate(){};
+void Dismissed::Sizzle(){};
+
+// TWO: attributes #0 = {
+// TWO: "keepalign"="true"
+// TWO: attributes #1 = {
+// TWO-NOT: "keepalign"="true"
+// TWO: attributes #2 = {
+// TWO-NOT: "keepalign"="true"
+
+// SIZE: attributes #0 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #1 = {
+// SIZE-NOT: "keepalign"="true"
+// SIZE: attributes #2 = {
+// SIZE-NOT: "keepalign"="true"
\ No newline at end of file
diff --git a/llvm/include/llvm/IR/Attributes.td 
b/llvm/include/llvm/IR/Attributes.td
index fc38e68ad273b6b..30844f566786c37 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -332,6 +332,7 @@ def NoJumpTables : StrBoolAttr<"no-jump-tables">;
 def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">;
 def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
 def UseSampleProfile : StrBoolAttr<"use-sample-profile">;
+def KeepAlign: StrBoolAttr<"keepalign">;
 
 def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>;
 def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>;
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp 
b/llvm/lib/CodeGen/MachineFunction.cpp
index 07eb0ba7f45c2e3..ab5392a05fc019b 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -214,7 +214,8 @@ void MachineFunction::init() {
 
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
   // FIXME: Use Function::hasOptSize().
-  if (!F.hasFnAttribute(Attribute::OptimizeForSize))
+  if ((!F.hasFnAttribute(Attribute::OptimizeForSize)) ||
+ (F.getFnAttribute("keepalign").getValueAsBool()))
 Alignment = std::max(Alignment,
  STI->getTargetLowering()->getPrefFunctionAlignment());
 
diff --git a/llvm/test/CodeGen/X86/cold-align.ll 
b/llvm/test/CodeGen/X86/cold-align.ll
new file mode 100644
index 000..ab1f393dfa561ab
--- /dev/null
+++ b/llvm/test/CodeGen/X86/cold-align.ll
@@ -0,0 +1,52 @@
+;  Dont alter function alignment if marked cold
+;
+;  Cold attribute marks functions as also optimize for size. This normally 
collapses the
+;  default function alignment. This can interfere with edit&continue 
effectiveness.
+;
+;
+;  RUN: llc -O2 <%s | FileCheck %s -check-prefixes TWO
+;
+;  TWO: .globl _ZN9Dismissed6ChillyEv
+;  TWO-NEXT: .p2align 4, 0x90
+;  TWO: .globl _ZN9Dismissed9TemparateEv
+;  TWO-NEXT: .p2align 4, 0x90
+;  TWO: .globl _ZN9Dismissed6SizzleEv
+;  TWO-NEXT: .p2align 4, 0x90
+
+; ModuleID = 'cold-align.cpp'
+source_filename = "cold-align.cpp"
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p27

[llvm] [clang] [clang-tools-extra] Dont alter cold function alignment unless using Os (PR #72387)

2023-11-15 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 2060bfcdc7eb704647c64bf925cdceb94c1f535f 
effbfe02b71638fe49dfc09423663f9077c4cc41 -- clang/test/CodeGen/cold-align.cpp 
clang/lib/CodeGen/CodeGenModule.cpp llvm/lib/CodeGen/MachineFunction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp 
b/llvm/lib/CodeGen/MachineFunction.cpp
index ab5392a05f..9303ca787e 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -215,7 +215,7 @@ void MachineFunction::init() {
   // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
   // FIXME: Use Function::hasOptSize().
   if ((!F.hasFnAttribute(Attribute::OptimizeForSize)) ||
- (F.getFnAttribute("keepalign").getValueAsBool()))
+  (F.getFnAttribute("keepalign").getValueAsBool()))
 Alignment = std::max(Alignment,
  STI->getTargetLowering()->getPrefFunctionAlignment());
 

``




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


[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-15 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan created 
https://github.com/llvm/llvm-project/pull/72389

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

>From 2550d96acc9ce134b4f7359af0c75e3bd3146484 Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Wed, 15 Nov 2023 13:46:54 +
Subject: [PATCH] [APINotes] Upstream APINotesManager

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
---
 .../include/clang/APINotes/APINotesManager.h  | 163 ++
 clang/include/clang/APINotes/Types.h  |   3 +
 .../clang/Basic/DiagnosticCommonKinds.td  |  13 +
 clang/include/clang/Basic/LangOptions.def |   2 +
 clang/include/clang/Basic/Module.h|   3 +
 clang/include/clang/Basic/SourceMgrAdapter.h  |  85 
 clang/lib/APINotes/APINotesManager.cpp| 469 ++
 clang/lib/APINotes/CMakeLists.txt |   1 +
 clang/lib/Basic/CMakeLists.txt|   1 +
 clang/lib/Basic/SourceMgrAdapter.cpp  | 136 +
 10 files changed, 876 insertions(+)
 create mode 100644 clang/include/clang/APINotes/APINotesManager.h
 create mode 100644 clang/include/clang/Basic/SourceMgrAdapter.h
 create mode 100644 clang/lib/APINotes/APINotesManager.cpp
 create mode 100644 clang/lib/Basic/SourceMgrAdapter.cpp

diff --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
new file mode 100644
index 000..d82d1fa2d544a1d
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -0,0 +1,163 @@
+//===--- APINotesManager.h - Manage API Notes Files -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+#define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+class DirectoryEntry;
+class FileEntry;
+class LangOptions;
+class SourceManager;
+
+namespace api_notes {
+
+class APINotesReader;
+
+/// The API notes manager helps find API notes associated with declarations.
+///
+/// API notes are externally-provided annotations for declarations that can
+/// introduce new attributes (covering availability, nullability of
+/// parameters/results, and so on) for specific declarations without directly
+/// modifying the headers that contain those declarations.
+///
+/// The API notes manager is responsible for finding and loading the
+/// external API notes files that correspond to a given header. Its primary
+/// operation is \c findAPINotes(), which finds the API notes reader that
+/// provides information about the declarations at that location.
+class APINotesManager {
+  using ReaderEntry = llvm::PointerUnion;
+
+  SourceManager &SM;
+
+  /// Whether to implicitly search for API notes files based on the
+  /// source file from which an entity was declared.
+  bool ImplicitAPINotes;
+
+  /// The Swift version to use when interpreting versioned API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// API notes readers for the current module.
+  ///
+  /// There can be up to two of these, one for public headers and one
+  /// for private headers.
+  APINotesReader *CurrentModuleReaders[2] = {nullptr, nullptr};
+
+  /// A mapping from header file directories to the API notes reader for
+  /// that directory, or a redirection to another directory entry that may
+  /// have more information, or NULL to indicate that there is no API notes
+  /// reader for this directory.
+  llvm::DenseMap Readers;
+
+  /// Load the API notes associated with the given file, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(FileEntryRef APINotesFile);
+
+  /// Load the API notes associated with the given buffer, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(StringRef Buffer);
+
+  /// Load the given API notes file for the given header directory.
+  ///
+  /// \param HeaderDir The directory at which we
+  ///
+  /// \returns true if an error occurred.
+  bool loadAPINotes(const DirectoryEntry *HeaderDir, FileEntryRef 
APINotesFile);
+
+  /// Look f

[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Egor Zhdan (egorzhdan)


Changes

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

---

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


10 Files Affected:

- (added) clang/include/clang/APINotes/APINotesManager.h (+163) 
- (modified) clang/include/clang/APINotes/Types.h (+3) 
- (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+13) 
- (modified) clang/include/clang/Basic/LangOptions.def (+2) 
- (modified) clang/include/clang/Basic/Module.h (+3) 
- (added) clang/include/clang/Basic/SourceMgrAdapter.h (+85) 
- (added) clang/lib/APINotes/APINotesManager.cpp (+469) 
- (modified) clang/lib/APINotes/CMakeLists.txt (+1) 
- (modified) clang/lib/Basic/CMakeLists.txt (+1) 
- (added) clang/lib/Basic/SourceMgrAdapter.cpp (+136) 


``diff
diff --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
new file mode 100644
index 000..d82d1fa2d544a1d
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -0,0 +1,163 @@
+//===--- APINotesManager.h - Manage API Notes Files -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+#define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+class DirectoryEntry;
+class FileEntry;
+class LangOptions;
+class SourceManager;
+
+namespace api_notes {
+
+class APINotesReader;
+
+/// The API notes manager helps find API notes associated with declarations.
+///
+/// API notes are externally-provided annotations for declarations that can
+/// introduce new attributes (covering availability, nullability of
+/// parameters/results, and so on) for specific declarations without directly
+/// modifying the headers that contain those declarations.
+///
+/// The API notes manager is responsible for finding and loading the
+/// external API notes files that correspond to a given header. Its primary
+/// operation is \c findAPINotes(), which finds the API notes reader that
+/// provides information about the declarations at that location.
+class APINotesManager {
+  using ReaderEntry = llvm::PointerUnion;
+
+  SourceManager &SM;
+
+  /// Whether to implicitly search for API notes files based on the
+  /// source file from which an entity was declared.
+  bool ImplicitAPINotes;
+
+  /// The Swift version to use when interpreting versioned API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// API notes readers for the current module.
+  ///
+  /// There can be up to two of these, one for public headers and one
+  /// for private headers.
+  APINotesReader *CurrentModuleReaders[2] = {nullptr, nullptr};
+
+  /// A mapping from header file directories to the API notes reader for
+  /// that directory, or a redirection to another directory entry that may
+  /// have more information, or NULL to indicate that there is no API notes
+  /// reader for this directory.
+  llvm::DenseMap Readers;
+
+  /// Load the API notes associated with the given file, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(FileEntryRef APINotesFile);
+
+  /// Load the API notes associated with the given buffer, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(StringRef Buffer);
+
+  /// Load the given API notes file for the given header directory.
+  ///
+  /// \param HeaderDir The directory at which we
+  ///
+  /// \returns true if an error occurred.
+  bool loadAPINotes(const DirectoryEntry *HeaderDir, FileEntryRef 
APINotesFile);
+
+  /// Look for API notes in the given directory.
+  ///
+  /// This might find either a binary or source API notes.
+  OptionalFileEntryRef findAPINotesFile(DirectoryEntryRef Directory,
+StringRef FileName,
+bool WantPublic = true);
+
+  /// Attempt to load API notes for the given framework.
+  ///
+  /// \param FrameworkPath The path to the framework.
+  /// \param Public Whether to load the public API not

[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-11-15 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added a comment.

In D144006#4656728 , @jmorse wrote:

> Hi,
>
> Just to note that we've been seeing LTO crashes as a result of 
> rG3b449bd46a11a 
>  (now 
> reverted on trunk), which @StephenTozer has kindly reduced down to:
>
>   https://gist.github.com/jmorse/b0248c3c9f9195487ffd7c7431a8d15e
>
> Which triggers the assertion: DwarfDebug.cpp:2335: virtual void 
> llvm::DwarfDebug::endFunctionImpl(const llvm::MachineFunction *): Assertion 
> `LScopes.getAbstractScopesList().size() == NumAbstractSubprograms && 
> "getOrCreateAbstractScope() inserted an abstract subprogram scope"' failed. 
> If you revert-the-revert rG6beddd668 
>  that is.
>
> I haven't familiarised myself with this patch series (while greatly 
> appreciating that it exists!), so perhaps this is already obvious but: This 
> particular assertion is a check that no additional lexical scopes are 
> discovered during DWARF emission that weren't found during the earlier 
> building of the lexical-scopes-map, which enumerates all 
> scopes/inlining-chains for all instructions' DebugLocs. If any more 
> unexpectedly appear after that, I believe there's a risk that a container for 
> lexical scopes gets reallocated, causing random crashes. I see there are now 
> types in the retainedNodes field for DISubprograms with "scope" fields (EDIT: 
> !53 in the reproducer), I imagine that the discovery of those lexical scopes 
> which weren't reachable from instructions might be causing the assertion.

I appreciate your help! Can I ask you how to reproduce that crash? When I run 
llc or llvm-lto on the gist, the assertion is triggered

  Assertion failed: (((LinkageName.empty() || DeclLinkageName.empty()) || 
LinkageName == DeclLinkageName) && "decl has a linkage name and it is 
different"), function applySubprogramDefinitionAttributes, file DwarfUnit.cpp, 
line 1222.

that persists even with this commit reverted. Are you sure that the reproducer 
was correctly reduced?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144006/new/

https://reviews.llvm.org/D144006

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


[PATCH] D158824: [RISCV][MC] MC layer support for xcvmem and xcvelw extensions

2023-11-15 Thread Liao Chunyu via Phabricator via cfe-commits
liaolucy updated this revision to Diff 558107.
liaolucy added a comment.

1. use a custom parser to parse Register-Register load/store
2. Rebase

Thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158824/new/

https://reviews.llvm.org/D158824

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/corev/XCVelw-invalid.s
  llvm/test/MC/RISCV/corev/XCVelw-valid.s
  llvm/test/MC/RISCV/corev/XCVmem-invalid.s
  llvm/test/MC/RISCV/corev/XCVmem-valid.s
  llvm/unittests/Support/RISCVISAInfoTest.cpp

Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -712,7 +712,9 @@
 xcvalu  1.0
 xcvbi   1.0
 xcvbitmanip 1.0
+xcvelw  1.0
 xcvmac  1.0
+xcvmem  1.0
 xcvsimd 1.0
 xsfcie  1.0
 xsfvcp  1.0
Index: llvm/test/MC/RISCV/corev/XCVmem-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/corev/XCVmem-valid.s
@@ -0,0 +1,247 @@
+# RUN: llvm-mc -triple=riscv32 --mattr=+xcvmem -show-encoding %s \
+# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INSTR
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+xcvmem < %s \
+# RUN: | llvm-objdump --mattr=+xcvmem -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-INSTR %s
+# RUN: not llvm-mc -triple riscv32 %s 2>&1 \
+# RUN: | FileCheck -check-prefix=CHECK-NO-EXT %s
+
+cv.lb t0, (t1), 0
+# CHECK-INSTR: cv.lb t0, (t1), 0
+# CHECK-ENCODING: [0x8b,0x02,0x03,0x00]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lb a0, (a1), 2047
+# CHECK-INSTR: cv.lb a0, (a1), 2047
+# CHECK-ENCODING: [0x0b,0x85,0xf5,0x7f]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lb t0, (t1), t2
+# CHECK-INSTR: cv.lb t0, (t1), t2
+# CHECK-ENCODING: [0xab,0x32,0x73,0x00]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lb a0, (a1), a2
+# CHECK-INSTR: cv.lb a0, (a1), a2
+# CHECK-ENCODING: [0x2b,0xb5,0xc5,0x00]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lb t0, t2(t1)
+# CHECK-INSTR: cv.lb t0, t2(t1)
+# CHECK-ENCODING: [0xab,0x32,0x73,0x08]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lb a0, a2(a1)
+# CHECK-INSTR: cv.lb a0, a2(a1)
+# CHECK-ENCODING: [0x2b,0xb5,0xc5,0x08]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu t0, (t1), 0
+# CHECK-INSTR: cv.lbu t0, (t1), 0
+# CHECK-ENCODING: [0x8b,0x42,0x03,0x00]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu a0, (a1), 2047
+# CHECK-INSTR: cv.lbu a0, (a1), 2047
+# CHECK-ENCODING: [0x0b,0xc5,0xf5,0x7f]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu t0, (t1), t2
+# CHECK-INSTR: cv.lbu t0, (t1), t2
+# CHECK-ENCODING: [0xab,0x32,0x73,0x10]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu a0, (a1), a2
+# CHECK-INSTR: cv.lbu a0, (a1), a2
+# CHECK-ENCODING: [0x2b,0xb5,0xc5,0x10]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu t0, t2(t1)
+# CHECK-INSTR: cv.lbu t0, t2(t1)
+# CHECK-ENCODING: [0xab,0x32,0x73,0x18]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lbu a0, a2(a1)
+# CHECK-INSTR: cv.lbu a0, a2(a1)
+# CHECK-ENCODING: [0x2b,0xb5,0xc5,0x18]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lh t0, (t1), 0
+# CHECK-INSTR: cv.lh t0, (t1), 0
+# CHECK-ENCODING: [0x8b,0x12,0x03,0x00]
+# CHECK-NO-EXT: instruction requires the following: 'XCVmem' (CORE-V Post-incrementing Load & Store){{$}}
+
+cv.lh a0, (a1), 2047
+# CHECK-INSTR: cv.lh a0, (a1), 2047
+# CHECK-ENCODING: [0x0b,0x95,0xf5,0x7f]
+# CHECK-NO-EXT: instruction requir

[mlir] [llvm] [clang] [llvm] Improve implementation of StringRef::find_last_of and cie (PR #71865)

2023-11-15 Thread via cfe-commits


@@ -274,6 +278,23 @@ StringRef::size_type 
StringRef::find_first_not_of(StringRef Chars,
 /// Note: O(size() + Chars.size())
 StringRef::size_type StringRef::find_last_of(StringRef Chars,
  size_t From) const {
+#ifdef __SSE2__
+  if (Chars.size() == 2) {
+__m128i Needle0 = _mm_set1_epi8(Chars[0]);
+__m128i Needle1 = _mm_set1_epi8(Chars[1]);
+size_type Sz = std::min(From, Length);
+do {
+  Sz = Sz < 16 ? 0 : Sz - 16;
+  __m128i Buffer = _mm_loadu_si128((const __m128i *)(Data + Sz));
+  unsigned Mask = _mm_movemask_epi8(_mm_or_si128(
+  _mm_cmpeq_epi8(Buffer, Needle0), _mm_cmpeq_epi8(Buffer, Needle1)));
+  if (Mask != 0) {
+return Sz + sizeof(Mask) * CHAR_BIT - llvm::countl_zero(Mask);
+  }
+} while (Sz);
+return npos;
+  }
+#endif

serge-sans-paille wrote:

I don't think using https://github.com/xtensor-stack/xsimd is an option :-) And 
https://en.cppreference.com/w/cpp/experimental/simd/simd is still not a thing 
:-/

We already have some bits of SSE2 in clang and llvm. OK to factor this in a 
function.

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


[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)

2023-11-15 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added a comment.

In D144006#4656399 , @aeubanks wrote:

> In D144006#4656383 , @dzhidzhoev 
> wrote:
>
>> In D144006#4656371 , @aeubanks 
>> wrote:
>>
>>> Is there any issue with mixing IR built with 
>>> `LLVMContext::enableDebugTypeODRUniquing()` and without? I'm suspecting 
>>> that ThinLTO is mixing Rust and Clang IR which set that differently.
>>
>> Apparently, it's an issue with ThinLTO that might be caused by a change in 
>> MetadataLoader https://github.com/llvm/llvm-project/pull/68986.
>> Is there a way to get a repro like this one 
>> https://bugs.chromium.org/p/chromium/issues/detail?id=1487910#c3 if it's not 
>> too complicated?
>
> I've shared the repro tar with your commit email address, sorry it's so big. 
> I tried linking again with the revert and now it looks like the debug info 
> verifier is firing instead. Do you also need a repro tar with everything 
> built with the revert?

Thank you so much! I think that's enough.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144006/new/

https://reviews.llvm.org/D144006

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


[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-15 Thread antoine moynault via cfe-commits

antmox wrote:

@eopXD
tested successfully, no failure with this commit 

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


[flang] [clang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-15 Thread David Truby via cfe-commits

https://github.com/DavidTruby updated 
https://github.com/llvm/llvm-project/pull/72121

>From cfd46a8825aa34b3e513d898ceb57f4e48e78faf Mon Sep 17 00:00:00 2001
From: David Truby 
Date: Mon, 13 Nov 2023 14:48:44 +
Subject: [PATCH 1/3] [flang] Add depdendent-lib option to flang -fc1 on
 Windows

This patch adds a --depdendent-lib option to flang -fc1 on Windows to
embed library link options into the object file. This is needed to
properly select the Windows CRT to link against.
---
 clang/include/clang/Driver/Options.td |  8 ---
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp | 23 +++
 flang/lib/Frontend/FrontendActions.cpp| 23 +++
 flang/test/Driver/dependent-lib.f90   |  7 ++
 flang/test/Driver/driver-help.f90 |  1 +
 6 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/dependent-lib.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..c7eb52145f614b4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6796,9 +6796,6 @@ def vectorize_loops : Flag<["-"], "vectorize-loops">,
 def vectorize_slp : Flag<["-"], "vectorize-slp">,
   HelpText<"Run the SLP vectorization passes">,
   MarshallingInfoFlag>;
-def dependent_lib : Joined<["--"], "dependent-lib=">,
-  HelpText<"Add dependent library">,
-  MarshallingInfoStringVector>;
 def linker_option : Joined<["--"], "linker-option=">,
   HelpText<"Add linker option">,
   MarshallingInfoStringVector>;
@@ -7369,6 +7366,11 @@ def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
 
+
+def dependent_lib : Joined<["--"], "dependent-lib=">,
+  HelpText<"Add dependent library">,
+  MarshallingInfoStringVector>;
+
 } // let Visibility = [CC1Option, FC1Option]
 
 let Visibility = [CC1Option] in {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index a3c39bda10667be..b86bb88610a9a4a 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -70,6 +70,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// The format used for serializing remarks (default: YAML)
   std::string OptRecordFormat;
 
+  /// Options to add to the linker for the object file
+  std::vector DependentLibs;
+
   // The RemarkKind enum class and OptRemark struct are identical to what Clang
   // has
   // TODO: Share with clang instead of re-implementing here
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 334da3ac287e3bf..cb4f2d6a6225205 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1054,6 +1054,27 @@ static bool parseVScaleArgs(CompilerInvocation &invoc, 
llvm::opt::ArgList &args,
   return true;
 }
 
+static bool parseLinkerOptionsArgs(CompilerInvocation &invoc,
+   llvm::opt::ArgList &args,
+   clang::DiagnosticsEngine &diags) {
+  llvm::Triple triple = llvm::Triple(invoc.getTargetOpts().triple);
+
+  // TODO: support --dependent-lib on other platforms when MLIR supports
+  //   !llvm.dependent.lib
+  if (args.hasArg(clang::driver::options::OPT_dependent_lib) &&
+  !triple.isOSWindows()) {
+const unsigned diagID =
+diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "--dependent-lib is only supported on Windows");
+diags.Report(diagID);
+return false;
+  }
+
+  invoc.getCodeGenOpts().DependentLibs =
+  args.getAllArgValues(clang::driver::options::OPT_dependent_lib);
+  return true;
+}
+
 bool CompilerInvocation::createFromArgs(
 CompilerInvocation &res, llvm::ArrayRef commandLineArgs,
 clang::DiagnosticsEngine &diags, const char *argv0) {
@@ -1163,6 +1184,8 @@ bool CompilerInvocation::createFromArgs(
 
   success &= parseVScaleArgs(res, args, diags);
 
+  success &= parseLinkerOptionsArgs(res, args, diags);
+
   // Set the string to be used as the return value of the COMPILER_OPTIONS
   // intrinsic of iso_fortran_env. This is either passed in from the parent
   // compiler driver invocation with an environment variable, or failing that
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index d7ca7b66584dd52..8df966571bc39ab 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -203,6 +203,26 @@ static void setMLIRDataLayout(mlir::ModuleOp &mlirModule,
   mlirModule->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
 }
 
+static void addDepdendentLibs(mlir::ModuleOp &mlirModule,
+  CompilerInstance &ci) {
+  const std::vector &libs =
+  ci.getInvocation

[clang] [lldb] Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (PR #71780)

2023-11-15 Thread via cfe-commits

zmodem wrote:

We're seeing crashes after this. Here is a reproducer: 
https://bugs.chromium.org/p/chromium/issues/detail?id=1502489#c1

Please consider reverting if it can't be fixed quickly (I had a look, but it 
seems there are some dependent changes on top).

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


[clang] 33b5158 - Replace usage of StringRef::find_last_of with a string literal of size one by the equivalent char literal

2023-11-15 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-11-15T15:01:36+01:00
New Revision: 33b51588c5d51995909f1f0be0b47b1708dac4fa

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

LOG: Replace usage of StringRef::find_last_of with a string literal of size one 
by the equivalent char literal

Added: 


Modified: 
clang/lib/Driver/ToolChains/ZOS.cpp
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/ZOS.cpp 
b/clang/lib/Driver/ToolChains/ZOS.cpp
index a7d6f030f3850a5..96dbf602e7c1fc9 100644
--- a/clang/lib/Driver/ToolChains/ZOS.cpp
+++ b/clang/lib/Driver/ToolChains/ZOS.cpp
@@ -143,7 +143,7 @@ void zos::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 StringRef OutputName = Output.getFilename();
 // Strip away the last file suffix in presence from output name and add
 // a new .x suffix.
-size_t Suffix = OutputName.find_last_of(".");
+size_t Suffix = OutputName.find_last_of('.');
 const char *SideDeckName =
 Args.MakeArgString(OutputName.substr(0, Suffix) + ".x");
 CmdArgs.push_back("-x");

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index d03820f5f9e6c93..7b5dc3795b0227f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -102,7 +102,7 @@ void 
AMDGPUPrintfRuntimeBindingImpl::getConversionSpecifiers(
 bool ArgDump = false;
 StringRef CurFmt = Fmt.substr(PrevFmtSpecifierIdx,
   CurFmtSpecifierIdx - PrevFmtSpecifierIdx);
-size_t pTag = CurFmt.find_last_of("%");
+size_t pTag = CurFmt.find_last_of('%');
 if (pTag != StringRef::npos) {
   ArgDump = true;
   while (pTag && CurFmt[--pTag] == '%') {

diff  --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp 
b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index d6354876b558744..ae9e801f8f50b84 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -163,7 +163,7 @@ lookupBuiltin(StringRef DemangledCall,
   // the information after angle brackets and return type removed.
   if (BuiltinName.find('<') && BuiltinName.back() == '>') {
 BuiltinName = BuiltinName.substr(0, BuiltinName.find('<'));
-BuiltinName = BuiltinName.substr(BuiltinName.find_last_of(" ") + 1);
+BuiltinName = BuiltinName.substr(BuiltinName.find_last_of(' ') + 1);
   }
 
   // Check if the extracted name begins with "__spirv_ImageSampleExplicitLod"

diff  --git a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp 
b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
index fe668130d4e2dbc..b6f4f3cc1869edb 100644
--- a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
+++ b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
@@ -83,7 +83,7 @@ lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, 
SMLoc loc) {
 
   // Pop the last line from the buffer string.
   auto popLastLine = [&]() -> std::optional {
-size_t newlineOffset = buffer.find_last_of("\n");
+size_t newlineOffset = buffer.find_last_of('\n');
 if (newlineOffset == StringRef::npos)
   return std::nullopt;
 StringRef lastLine = buffer.drop_front(newlineOffset).trim();



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


[flang] [clang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits


@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");
+
+  // Trim space from right/end
+  int i = str.size();
+  while (' ' == str[--i]) {
+str[i] = 0;
+  }

PAX-12-WU wrote:

Done, replaced by copyBufferAndPad

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


[flang] [clang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits


@@ -13,6 +13,44 @@
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include 
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+#include  // wcstombs_s
+#include  // wchar_t cast to LPWSTR
+#pragma comment(lib, "Advapi32.lib") // Link Advapi32.lib for GetUserName
+#define LOGIN_NAME_MAX UNLEN
+
+inline int getlogin_r(char *buf, size_t bufSize) {
+  wchar_t w_username[UNLEN + 1];
+  DWORD nameLen = UNLEN + 1;
+
+  if (GetUserNameW(w_username, &nameLen)) {
+// Convert the wchar_t string to a regular C string using wcstombs_s
+if (wcstombs_s(nullptr, buf, sizeof(w_username), w_username, _TRUNCATE) !=
+0) {
+  // Conversion failed
+  return -1;
+}
+return (buf[0] == 0 ? -1 : 0);
+  } else {
+return -1;
+  }
+  return -1;
+}
+
+#elif _REENTRANT || _POSIX_C_SOURCE >= 199506L
+// System is posix-compliant and has getlogin_r
+#include 
+#else
+// System is not posix-compliant
+inline int getlogin_r(char *buf, size_t bufsize) { return -1; }

PAX-12-WU wrote:

Good suggestion!

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


[flang] [clang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits


@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");

PAX-12-WU wrote:

Done

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


[clang-tools-extra] [clang-tidy] Add new modernize-string-find-startswith check (PR #72385)

2023-11-15 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/72385

>From 58e1392e140f0d5b932fce683a07fb799ef6b89f Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 15 Nov 2023 01:13:10 -0800
Subject: [PATCH] [clang-tidy] Add new modernize-string-find-startswith check

Matchers are copied over from abseil-string-find-startswith, only the error
message is different and suggests `std::{string|string_view}::starts_with`
instead of the Abseil equivalent.
---
 .../abseil/StringFindStartswithCheck.h|   5 +-
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/StringFindStartswithCheck.cpp   | 111 ++
 .../modernize/StringFindStartswithCheck.h |  41 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 ++
 .../checks/abseil/string-find-startswith.rst  |   4 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../modernize/string-find-startswith.rst  |  32 +
 .../abseil/string-find-startswith.cpp |   2 +-
 .../modernize/string-find-startswith.cpp  |  77 
 11 files changed, 283 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/string-find-startswith.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/string-find-startswith.cpp

diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
index 923b5caece5439b..5019b7000f1d062 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
@@ -21,7 +21,6 @@ namespace clang::tidy::abseil {
 
 // Find string.find(...) == 0 comparisons and suggest replacing with 
StartsWith.
 // FIXME(niko): Add similar check for EndsWith
-// FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
 class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+// Prefer modernize-string-find-startswith when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 
 private:
   const std::vector StringLikeClasses;
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..541f58304119856 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTidyModernizeModule
   ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
+  StringFindStartswithCheck.cpp
   TypeTraitsCheck.cpp
   UnaryStaticAssertCheck.cpp
   UseAutoCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..1fcbff79ddc6f96 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
+#include "StringFindStartswithCheck.h"
 #include "TypeTraitsCheck.h"
 #include "UnaryStaticAssertCheck.h"
 #include "UseAutoCheck.h"
@@ -66,6 +67,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-string-find-startswith");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
 "modernize-raw-string-literal");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
new file mode 100644
index 000..74f59b9fcea1982
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
@@ -0,0 +1,111 @@
+//===--- StringFindStartswithCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-Lice

[clang] [llvm] [flang] [clang-tools-extra] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits


@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");
+
+  // Trim space from right/end
+  int i = str.size();
+  while (' ' == str[--i]) {
+str[i] = 0;
+  }
+  strncpy(reinterpret_cast(arg), str.data(), length);
+}

PAX-12-WU wrote:

I have moved copyBufferAndPad out of anonymous namespace and define it in 
header file. Now I (and anyone in the  future) can use it by including the 
header file.

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


[compiler-rt] [clang-tools-extra] [llvm] [flang] [clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-15 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 01/21] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/li

[clang] [clang][Analyzer][NFC] Use condition type for comparison in several checkers (PR #72358)

2023-11-15 Thread Balázs Kéri via cfe-commits

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


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


[clang] [clang-tools-extra] [llvm] [flang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-15 Thread Yi Wu via cfe-commits

https://github.com/PAX-12-WU updated 
https://github.com/llvm/llvm-project/pull/70917

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 1/6] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e5538..cfe5dcd141e9821 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31a4..830df7ad006b54a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec6289390545479..1c212ef61697cd5 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb79..d199d5e387b8648 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571b..6b2f313e227a196 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {

[clang] [llvm] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-15 Thread Paul T Robinson via cfe-commits

https://github.com/pogo59 commented:

@adrian-prantl We do have a pretty strong guarantee of compatibility in the 
llvm-c API. A new parameter pretty much means you need to define a new function.

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


[clang-tools-extra] [clang-tidy] Add new modernize-string-find-startswith check (PR #72385)

2023-11-15 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add new modernize-string-find-startswith check (PR #72385)

2023-11-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Nicolas van Kempen (nicovank)


Changes

Matchers are copied over from abseil-string-find-startswith, only the error 
message is different and suggests `std::{string|string_view}::starts_with` 
instead of the Abseil equivalent.

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


11 Files Affected:

- (modified) clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
(+4-1) 
- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+3) 
- (added) clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
(+111) 
- (added) clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.h 
(+41) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+8) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst (+4) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/modernize/string-find-startswith.rst 
(+32) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-startswith.cpp 
(+1-1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/string-find-startswith.cpp 
(+77) 


``diff
diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
index 923b5caece5439b..5019b7000f1d062 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
@@ -21,7 +21,6 @@ namespace clang::tidy::abseil {
 
 // Find string.find(...) == 0 comparisons and suggest replacing with 
StartsWith.
 // FIXME(niko): Add similar check for EndsWith
-// FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
 class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+// Prefer modernize-string-find-startswith when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 
 private:
   const std::vector StringLikeClasses;
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..541f58304119856 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTidyModernizeModule
   ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
+  StringFindStartswithCheck.cpp
   TypeTraitsCheck.cpp
   UnaryStaticAssertCheck.cpp
   UseAutoCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..1fcbff79ddc6f96 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
+#include "StringFindStartswithCheck.h"
 #include "TypeTraitsCheck.h"
 #include "UnaryStaticAssertCheck.h"
 #include "UseAutoCheck.h"
@@ -66,6 +67,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-string-find-startswith");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
 "modernize-raw-string-literal");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
new file mode 100644
index 000..74f59b9fcea1982
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/StringFindStartswithCheck.cpp
@@ -0,0 +1,111 @@
+//===--- StringFindStartswithCheck.cpp - clang-tidy 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "StringFindStartswithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lex

  1   2   3   4   5   6   >