[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits

https://github.com/isuckatcs updated 
https://github.com/llvm/llvm-project/pull/70053

>From 7cca7a3a6d969318fb8531751f75bb41715c7475 Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Sat, 30 Sep 2023 17:05:02 +0200
Subject: [PATCH 1/4] cleanup

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 20 
 clang/lib/AST/Interp/ByteCodeExprGen.h   | 20 
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1b33c69b93aa4b9..8d18698df60c2c1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -816,22 +816,18 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
 const ArrayInitLoopExpr *E) {
   assert(Initializing);
   assert(!DiscardResult);
+
+  // We visit the common opaque expression here once so we have its value
+  // cached.
+  if (!this->discard(E->getCommonExpr()))
+return false;
+
   // TODO: This compiles to quite a lot of bytecode if the array is larger.
   //   Investigate compiling this to a loop.
-
   const Expr *SubExpr = E->getSubExpr();
-  const Expr *CommonExpr = E->getCommonExpr();
   size_t Size = E->getArraySize().getZExtValue();
   std::optional ElemT = classify(SubExpr->getType());
 
-  // If the common expression is an opaque expression, we visit it
-  // here once so we have its value cached.
-  // FIXME: This might be necessary (or useful) for all expressions.
-  if (isa(CommonExpr)) {
-if (!this->discard(CommonExpr))
-  return false;
-  }
-
   // So, every iteration, we execute an assignment here
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
@@ -882,13 +878,13 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 return false;
 
   // Here the local variable is created but the value is removed from the 
stack,
-  // so we put it back, because the caller might need it.
+  // so we put it back if the caller needs it.
   if (!DiscardResult) {
 if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
   return false;
   }
 
-  // FIXME: Ideally the cached value should be cleaned up later.
+  // This is cleaned up when the local variable is destroyed.
   OpaqueExprs.insert({E, *LocalIndex});
 
   return true;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 83986d3dd579ed6..774d0b25f4ad56d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -360,6 +360,7 @@ template  class LocalScope : public 
VariableScope {
 if (!Idx)
   return;
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
   }
 
   /// Overriden to support explicit destruction.
@@ -368,6 +369,7 @@ template  class LocalScope : public 
VariableScope {
   return;
 this->emitDestructors();
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
 this->Idx = std::nullopt;
   }
 
@@ -389,10 +391,28 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =
+llvm::dyn_cast_or_null(Local.Desc->asExpr());
+OVE && this->Ctx->OpaqueExprs.contains(OVE)) {
+  this->Ctx->OpaqueExprs.erase(OVE);
+};
+  }
+
   /// Index of the scope in the chain.
   std::optional Idx;
 };

>From 39f10263f95b60441bb6df032f0e89fa57fe153e Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Wed, 24 Jan 2024 18:19:16 +0100
Subject: [PATCH 2/4] addressed comments

---
 clang/lib/AST/Interp/ByteCodeExprGen.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 774d0b25f4ad56d..8a5f644c227ffc0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)
   : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
 
   // Expression visitors - result returned on interp stack.
@@ -241,8 +241,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
llvm::function_ref D

[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits


@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)

isuckatcs wrote:

It was probably the autoformat from my editor then. I removed both format 
changes.

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


[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-25 Thread Pavel Iliin via cfe-commits

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

LGTM, thanks for additinal FMV tests!

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


[clang] [clang-tools-extra] [llvm] [clang] Add test for CWG472 (PR #67948)

2024-01-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 43e46c5 - [clang] Add test for CWG472 (#67948)

2024-01-25 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-01-25T19:00:17+04:00
New Revision: 43e46c546a1f0c7c3e436104a974560c6a2e5188

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

LOG: [clang] Add test for CWG472 (#67948)

https://cplusplus.github.io/CWG/issues/472.html
It has drafting status, but I think CWG has reached consesus on the
behavior.
Related: #16602

Added: 


Modified: 
clang/test/CXX/drs/dr4xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index aa7a41b95ccd85..2f11c92f86aca3 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -1055,6 +1055,23 @@ namespace dr471 { // dr471: 2.8
   //   expected-note@#dr471-G-using {{declared private here}}
 }
 
+namespace dr472 { // dr472: no drafting
+struct B {
+  int i; // #dr472-i
+};
+struct I : protected B {}; // #dr472-struct-I
+struct D : public I {
+  void f(I *ip) {
+ip->i = 0;
+// expected-error@-1 {{'i' is a protected member of 'dr472::B'}}
+//   expected-note@#dr472-struct-I {{constrained by protected inheritance 
here}}
+//   expected-note@#dr472-i {{member is declared here}}
+B *bp = ip;
+bp->i = 5;
+  }
+};
+}
+
 namespace dr474 { // dr474: 3.4
   namespace N {
 struct S {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c9d21f096a34c6..3e13a4d89ef989 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2872,7 +2872,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/472.html";>472
 drafting
 Casting across protected inheritance
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/473.html";>473



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


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits

https://github.com/isuckatcs updated 
https://github.com/llvm/llvm-project/pull/70053

>From 7cca7a3a6d969318fb8531751f75bb41715c7475 Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Sat, 30 Sep 2023 17:05:02 +0200
Subject: [PATCH 1/4] cleanup

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 20 
 clang/lib/AST/Interp/ByteCodeExprGen.h   | 20 
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1b33c69b93aa4b9..8d18698df60c2c1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -816,22 +816,18 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
 const ArrayInitLoopExpr *E) {
   assert(Initializing);
   assert(!DiscardResult);
+
+  // We visit the common opaque expression here once so we have its value
+  // cached.
+  if (!this->discard(E->getCommonExpr()))
+return false;
+
   // TODO: This compiles to quite a lot of bytecode if the array is larger.
   //   Investigate compiling this to a loop.
-
   const Expr *SubExpr = E->getSubExpr();
-  const Expr *CommonExpr = E->getCommonExpr();
   size_t Size = E->getArraySize().getZExtValue();
   std::optional ElemT = classify(SubExpr->getType());
 
-  // If the common expression is an opaque expression, we visit it
-  // here once so we have its value cached.
-  // FIXME: This might be necessary (or useful) for all expressions.
-  if (isa(CommonExpr)) {
-if (!this->discard(CommonExpr))
-  return false;
-  }
-
   // So, every iteration, we execute an assignment here
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
@@ -882,13 +878,13 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 return false;
 
   // Here the local variable is created but the value is removed from the 
stack,
-  // so we put it back, because the caller might need it.
+  // so we put it back if the caller needs it.
   if (!DiscardResult) {
 if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
   return false;
   }
 
-  // FIXME: Ideally the cached value should be cleaned up later.
+  // This is cleaned up when the local variable is destroyed.
   OpaqueExprs.insert({E, *LocalIndex});
 
   return true;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 83986d3dd579ed6..774d0b25f4ad56d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -360,6 +360,7 @@ template  class LocalScope : public 
VariableScope {
 if (!Idx)
   return;
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
   }
 
   /// Overriden to support explicit destruction.
@@ -368,6 +369,7 @@ template  class LocalScope : public 
VariableScope {
   return;
 this->emitDestructors();
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
 this->Idx = std::nullopt;
   }
 
@@ -389,10 +391,28 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =
+llvm::dyn_cast_or_null(Local.Desc->asExpr());
+OVE && this->Ctx->OpaqueExprs.contains(OVE)) {
+  this->Ctx->OpaqueExprs.erase(OVE);
+};
+  }
+
   /// Index of the scope in the chain.
   std::optional Idx;
 };

>From 39f10263f95b60441bb6df032f0e89fa57fe153e Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Wed, 24 Jan 2024 18:19:16 +0100
Subject: [PATCH 2/4] addressed comments

---
 clang/lib/AST/Interp/ByteCodeExprGen.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 774d0b25f4ad56d..8a5f644c227ffc0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)
   : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
 
   // Expression visitors - result returned on interp stack.
@@ -241,8 +241,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
llvm::function_ref D

[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandros Lamprineas (labrinea)


Changes

Adds tests showing that we select function version according to the highest 
feature priority. This will make the changes introduced by #79316 more 
evident.

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


1 Files Affected:

- (modified) clang/test/CodeGen/attr-target-version.c (+68-2) 


``diff
diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91da..feb6c094ab62b1a 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,10 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
+inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
+inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
+inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +363,38 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK:   resolver_else24:
+// CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
+// CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
+// CHECK:   resolver_return25:
+// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK:   resolver_else26:
+// CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
+// CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
+// CHECK:   resolver_return27:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK:   resolver_else28:
+// CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
+// CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
+// CHECK:   resolver_return29:
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +652,34 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MdotprodMaes
+// CHECK-SAME: () #[[ATTR6]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 13
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-SAME: () #[[ATTR7]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 14
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 15
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 16
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_inline.default
 // CHECK-SAME: () #[[ATTR2]] {
 // CHECK-NEXT:  entry:
@@ -624,7 +688,7 @@ int hoo(void) {
 //
 // CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@fmv_d._Msb
-// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-SAME: () #[[ATTR26:[0-9]+]] {
 // CHECK-NEXT:  entr

[clang] [NFC][FMV] Add tests to demonstrate feature priorities. (PR #79455)

2024-01-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/79455

Adds tests showing that we select function version according to the highest 
feature priority. This will make the changes introduced by #79316 more evident.

>From 07719ca748ad94e3c458293e46538491d771cc00 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 25 Jan 2024 14:09:06 +
Subject: [PATCH] [NFC][FMV] Add tests to demonstrate feature priorities.

Adds tests showing that we select function version according
to the highest feature priority. This will make the changes
introduced by #79316 more evident.
---
 clang/test/CodeGen/attr-target-version.c | 70 +++-
 1 file changed, 68 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGen/attr-target-version.c 
b/clang/test/CodeGen/attr-target-version.c
index 89279852a8c91da..feb6c094ab62b1a 100644
--- a/clang/test/CodeGen/attr-target-version.c
+++ b/clang/test/CodeGen/attr-target-version.c
@@ -36,6 +36,10 @@ inline int 
__attribute__((target_version("sve2-aes+sve2-sha3"))) fmv_inline(void
 inline int __attribute__((target_version("sve2+sve2-pmull128+sve2-bitperm"))) 
fmv_inline(void) { return 9; }
 inline int __attribute__((target_version("sve2-sm4+memtag2"))) 
fmv_inline(void) { return 10; }
 inline int __attribute__((target_version("memtag3+rcpc3+mops"))) 
fmv_inline(void) { return 11; }
+inline int __attribute__((target_version("aes+dotprod"))) fmv_inline(void) { 
return 13; }
+inline int __attribute__((target_version("simd+fp16fml"))) fmv_inline(void) { 
return 14; }
+inline int __attribute__((target_version("fp+sm4"))) fmv_inline(void) { return 
15; }
+inline int __attribute__((target_version("lse+rdm"))) fmv_inline(void) { 
return 16; }
 inline int __attribute__((target_version("default"))) fmv_inline(void) { 
return 3; }
 
 __attribute__((target_version("ls64"))) int fmv_e(void);
@@ -359,6 +363,38 @@ int hoo(void) {
 // CHECK:   resolver_return21:
 // CHECK-NEXT:ret ptr @fmv_inline._Mdpb2Mjscvt
 // CHECK:   resolver_else22:
+// CHECK-NEXT:[[TMP48:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP49:%.*]] = and i64 [[TMP48]], 16400
+// CHECK-NEXT:[[TMP50:%.*]] = icmp eq i64 [[TMP49]], 16400
+// CHECK-NEXT:[[TMP51:%.*]] = and i1 true, [[TMP50]]
+// CHECK-NEXT:br i1 [[TMP51]], label [[RESOLVER_RETURN23:%.*]], label 
[[RESOLVER_ELSE24:%.*]]
+// CHECK:   resolver_return23:
+// CHECK-NEXT:ret ptr @fmv_inline._MdotprodMaes
+// CHECK:   resolver_else24:
+// CHECK-NEXT:[[TMP52:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP53:%.*]] = and i64 [[TMP52]], 8
+// CHECK-NEXT:[[TMP54:%.*]] = icmp eq i64 [[TMP53]], 8
+// CHECK-NEXT:[[TMP55:%.*]] = and i1 true, [[TMP54]]
+// CHECK-NEXT:br i1 [[TMP55]], label [[RESOLVER_RETURN25:%.*]], label 
[[RESOLVER_ELSE26:%.*]]
+// CHECK:   resolver_return25:
+// CHECK-NEXT:ret ptr @fmv_inline._Mfp16fmlMsimd
+// CHECK:   resolver_else26:
+// CHECK-NEXT:[[TMP56:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP57:%.*]] = and i64 [[TMP56]], 32
+// CHECK-NEXT:[[TMP58:%.*]] = icmp eq i64 [[TMP57]], 32
+// CHECK-NEXT:[[TMP59:%.*]] = and i1 true, [[TMP58]]
+// CHECK-NEXT:br i1 [[TMP59]], label [[RESOLVER_RETURN27:%.*]], label 
[[RESOLVER_ELSE28:%.*]]
+// CHECK:   resolver_return27:
+// CHECK-NEXT:ret ptr @fmv_inline._Msm4Mfp
+// CHECK:   resolver_else28:
+// CHECK-NEXT:[[TMP60:%.*]] = load i64, ptr @__aarch64_cpu_features, align 
8
+// CHECK-NEXT:[[TMP61:%.*]] = and i64 [[TMP60]], 192
+// CHECK-NEXT:[[TMP62:%.*]] = icmp eq i64 [[TMP61]], 192
+// CHECK-NEXT:[[TMP63:%.*]] = and i1 true, [[TMP62]]
+// CHECK-NEXT:br i1 [[TMP63]], label [[RESOLVER_RETURN29:%.*]], label 
[[RESOLVER_ELSE30:%.*]]
+// CHECK:   resolver_return29:
+// CHECK-NEXT:ret ptr @fmv_inline._MrdmMlse
+// CHECK:   resolver_else30:
 // CHECK-NEXT:ret ptr @fmv_inline.default
 //
 //
@@ -616,6 +652,34 @@ int hoo(void) {
 //
 //
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MdotprodMaes
+// CHECK-SAME: () #[[ATTR6]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 13
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Mfp16fmlMsimd
+// CHECK-SAME: () #[[ATTR7]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 14
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._Msm4Mfp
+// CHECK-SAME: () #[[ATTR24:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 15
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@fmv_inline._MrdmMlse
+// CHECK-SAME: () #[[ATTR25:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 16
+//
+//
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: define {{[^@]+}}@f

[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)

tbaederr wrote:

Yeah but clang-format shouldn't touch those lines since you didn't touch them 
either.

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


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits

https://github.com/isuckatcs updated 
https://github.com/llvm/llvm-project/pull/70053

>From 7cca7a3a6d969318fb8531751f75bb41715c7475 Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Sat, 30 Sep 2023 17:05:02 +0200
Subject: [PATCH 1/3] cleanup

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 20 
 clang/lib/AST/Interp/ByteCodeExprGen.h   | 20 
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1b33c69b93aa4b..8d18698df60c2c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -816,22 +816,18 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
 const ArrayInitLoopExpr *E) {
   assert(Initializing);
   assert(!DiscardResult);
+
+  // We visit the common opaque expression here once so we have its value
+  // cached.
+  if (!this->discard(E->getCommonExpr()))
+return false;
+
   // TODO: This compiles to quite a lot of bytecode if the array is larger.
   //   Investigate compiling this to a loop.
-
   const Expr *SubExpr = E->getSubExpr();
-  const Expr *CommonExpr = E->getCommonExpr();
   size_t Size = E->getArraySize().getZExtValue();
   std::optional ElemT = classify(SubExpr->getType());
 
-  // If the common expression is an opaque expression, we visit it
-  // here once so we have its value cached.
-  // FIXME: This might be necessary (or useful) for all expressions.
-  if (isa(CommonExpr)) {
-if (!this->discard(CommonExpr))
-  return false;
-  }
-
   // So, every iteration, we execute an assignment here
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
@@ -882,13 +878,13 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 return false;
 
   // Here the local variable is created but the value is removed from the 
stack,
-  // so we put it back, because the caller might need it.
+  // so we put it back if the caller needs it.
   if (!DiscardResult) {
 if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
   return false;
   }
 
-  // FIXME: Ideally the cached value should be cleaned up later.
+  // This is cleaned up when the local variable is destroyed.
   OpaqueExprs.insert({E, *LocalIndex});
 
   return true;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 83986d3dd579ed..774d0b25f4ad56 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -360,6 +360,7 @@ template  class LocalScope : public 
VariableScope {
 if (!Idx)
   return;
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
   }
 
   /// Overriden to support explicit destruction.
@@ -368,6 +369,7 @@ template  class LocalScope : public 
VariableScope {
   return;
 this->emitDestructors();
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
+removeStoredOpaqueValues();
 this->Idx = std::nullopt;
   }
 
@@ -389,10 +391,28 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =
+llvm::dyn_cast_or_null(Local.Desc->asExpr());
+OVE && this->Ctx->OpaqueExprs.contains(OVE)) {
+  this->Ctx->OpaqueExprs.erase(OVE);
+};
+  }
+
   /// Index of the scope in the chain.
   std::optional Idx;
 };

>From 39f10263f95b60441bb6df032f0e89fa57fe153e Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Wed, 24 Jan 2024 18:19:16 +0100
Subject: [PATCH 2/3] addressed comments

---
 clang/lib/AST/Interp/ByteCodeExprGen.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 774d0b25f4ad56..8a5f644c227ffc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)
   : Emitter(Ctx, P, Args...), Ctx(Ctx), P(P) {}
 
   // Expression visitors - result returned on interp stack.
@@ -241,8 +241,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
llvm::function_ref Direct,

[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits

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


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread via cfe-commits


@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)

isuckatcs wrote:

This is how our clang-format config wants this to look like. If I add a 
white-space there it will no longer conform to our formatting standards.

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


[clang] [libc] [llvm] [lldb] [clang-tools-extra] [lld] [flang] [compiler-rt] [libcxx] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -2694,6 +2852,9 @@ class VPlan {
   /// been modeled in VPlan directly.
   DenseMap SCEVToExpansion;
 
+  /// Construct an uninitialized VPlan, should be used for cloning only.
+  explicit VPlan() = default;
+

ayalz wrote:

Is it really needed? (See above)

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


[libc] [clang] [lldb] [flang] [clang-tools-extra] [libcxx] [llvm] [lld] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -982,6 +1037,94 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+
+  // Clone live-ins.
+  SmallVector NewLiveIns;
+  for (VPValue *OldLiveIn : VPLiveInsToFree) {
+VPValue *NewLiveIn = new VPValue(OldLiveIn->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLiveIn);
+Old2NewVPValues[OldLiveIn] = NewLiveIn;
+  }
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+NewPlan->BackedgeTakenCount = new VPValue();
+Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount;
+  }
+  assert(TripCount && "trip count must be set");
+  if (TripCount->isLiveIn())
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());

ayalz wrote:

// else NewTripCount will be created and inserted into `Old2NewVPValues` when 
`TripCount` is cloned. In any case `NewPlan->TripCount` is updated below.

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


[clang-tools-extra] [flang] [libcxx] [llvm] [lldb] [lld] [clang] [compiler-rt] [libc] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -982,6 +1037,94 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+
+  // Clone live-ins.
+  SmallVector NewLiveIns;

ayalz wrote:

Is `NewLiveIns` needed?

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


[clang] [libc] [clang-tools-extra] [compiler-rt] [flang] [llvm] [libcxx] [lld] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -614,6 +614,61 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
   printSuccessors(O, Indent);
 }
 #endif
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks);
+
+static VPBlockBase *cloneVPB(VPBlockBase *BB) {
+  if (auto *VPBB = dyn_cast(BB)) {
+auto *NewBlock = new VPBasicBlock(VPBB->getName());
+for (VPRecipeBase &R : *VPBB)
+  NewBlock->appendRecipe(R.clone());
+return NewBlock;
+  }
+
+  auto *VPR = cast(BB);
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;

ayalz wrote:

Is `Old2NewVPValues` needed here?

Hopefully `Old2NewVPBlocks` will not be needed either, doing instead something 
like:
```
  auto [NewEntry, NewExiting] = cloneSESE(VPR->getEntry());
```


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


[lld] [llvm] [clang] [libc] [compiler-rt] [libcxx] [flang] [lldb] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -614,6 +614,61 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
   printSuccessors(O, Indent);
 }
 #endif
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks);
+
+static VPBlockBase *cloneVPB(VPBlockBase *BB) {
+  if (auto *VPBB = dyn_cast(BB)) {
+auto *NewBlock = new VPBasicBlock(VPBB->getName());
+for (VPRecipeBase &R : *VPBB)
+  NewBlock->appendRecipe(R.clone());
+return NewBlock;
+  }
+
+  auto *VPR = cast(BB);
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;
+  cloneCFG(VPR->getEntry(), Old2NewVPBlocks);
+  VPBlockBase *NewEntry = Old2NewVPBlocks[VPR->getEntry()];
+  auto *NewRegion =
+  new VPRegionBlock(NewEntry, Old2NewVPBlocks[VPR->getExiting()],
+VPR->getName(), VPR->isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewRegion);
+  return NewRegion;
+}
+
+// Clone the CFG for all nodes reachable from \p Entry, this includes cloning
+// the blocks and their recipes. Operands of cloned recipes will NOT be 
updated.
+// Remapping of operands must be done separately.
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks) {
+  ReversePostOrderTraversal> 
RPOT(
+  Entry);
+  for (VPBlockBase *BB : RPOT) {
+VPBlockBase *NewBB = cloneVPB(BB);
+for (VPBlockBase *Pred : BB->getPredecessors())
+  VPBlockUtils::connectBlocks(Old2NewVPBlocks[Pred], NewBB);
+
+Old2NewVPBlocks[BB] = NewBB;
+  }
+
+#if !defined(NDEBUG)
+  // Verify that the order of predecessors and successors matches in the cloned
+  // version.
+  ReversePostOrderTraversal>
+  NewRPOT(Old2NewVPBlocks[Entry]);
+  for (const auto &[OldBB, NewBB] : zip(RPOT, NewRPOT)) {
+for (const auto &[OldPred, NewPred] :
+ zip(OldBB->getPredecessors(), NewBB->getPredecessors()))
+  assert(NewPred == Old2NewVPBlocks[OldPred] && "Different predecessors");
+
+for (const auto &[OldSucc, NewSucc] :
+ zip(OldBB->successors(), NewBB->successors()))
+  assert(NewSucc == Old2NewVPBlocks[OldSucc] && "Different successors");
+  }
+#endif

ayalz wrote:

Return `Old2NewVPBlocks[Entry]` along with (the last) `NewBB`, or along with 
`Old2NewVPBlocks[Exit]` where Exit = *RPOT->end()?

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


[clang-tools-extra] [clang] [llvm] [compiler-rt] [libcxx] [flang] [lld] [lldb] [libc] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -982,6 +1037,94 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();

ayalz wrote:

Perhaps blocks should be clones first, then values cloned and remapped. I.e.,
```
  auto *NewPreheader = getPreheader().clone(); // Currently a disconnected VPBB.
  auto [NewEntry, _ ] = cloneSESE(getEntry());
  auto *NewPlan = new VPlan(NewPreheader, NewEntry);
```

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


[lldb] [lld] [compiler-rt] [libc] [libcxx] [flang] [llvm] [clang] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -982,6 +1037,94 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
+  DenseMap &Old2NewVPValues) {
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
+   "blocks must have the same number of recipes");
+
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+  assert(OldR.getNumOperands() == NewR.getNumOperands() &&
+ "recipes must have the same number of operands");
+  assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
+ "recipes must define the same number of operands");
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+}
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+NewR.setOperand(I, NewOp);
+  }
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2NewVPBlocks;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+
+  // Clone live-ins.
+  SmallVector NewLiveIns;
+  for (VPValue *OldLiveIn : VPLiveInsToFree) {
+VPValue *NewLiveIn = new VPValue(OldLiveIn->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLiveIn);
+Old2NewVPValues[OldLiveIn] = NewLiveIn;
+  }
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+NewPlan->BackedgeTakenCount = new VPValue();
+Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount;
+  }
+  assert(TripCount && "trip count must be set");
+  if (TripCount->isLiveIn())
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+
+  // Clone blocks.
+  cloneCFG(Preheader, Old2NewVPBlocks);
+  cloneCFG(getEntry(), Old2NewVPBlocks);
+
+  auto *NewPreheader = cast(Old2NewVPBlocks[Preheader]);
+  remapOperands(Preheader, NewPreheader, Old2NewVPValues);
+  auto *NewEntry = cast(Old2NewVPBlocks[Entry]);
+  remapOperands(Entry, NewEntry, Old2NewVPValues);
+
+  // Clone live-outs.
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+
+  // Initialize fields of cloned VPlan.
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPreheader;
+  NewEntry->setPlan(NewPlan);
+  NewPreheader->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  // TODO: Adjust names.
+  NewPlan->Name = Name;
+  NewPlan->TripCount = Old2NewVPValues[TripCount];

ayalz wrote:

nit: can assert that Old2NewVPValues contains TripCount.

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


[libc] [clang-tools-extra] [flang] [llvm] [lldb] [clang] [libcxx] [compiler-rt] [lld] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -1594,6 +1657,13 @@ class VPWidenPHIRecipe : public VPHeaderPHIRecipe {
   addOperand(Start);
   }
 
+  VPRecipeBase *clone() override {
+auto *Res = new VPWidenPHIRecipe(cast(getUnderlyingInstr()),

ayalz wrote:

Better mark it unreachable than have untested dead code, potentially 
misconsidered live?

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


[clang-tools-extra] [clang] [llvm] [libc] [flang] [lld] [lldb] [libcxx] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -614,6 +614,61 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
   printSuccessors(O, Indent);
 }
 #endif
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks);

ayalz wrote:

This cloning is recursive, so perhaps more accurately called `cloneHCFG()`.
It also clones a (maximal(*)) SESE region, so could be called `cloneSESE()`, 
and return a pair of VPB's - the new entry and new exit? Could 
`Old2NewVPBlocks` map be internal to the function, rather than an in/out 
parameter?

(*) There are currently two callees: the top-level of VPlan consisting of the 
vector-loop-preheader - loop-region - middle-block, and the internal CFG of a 
region from its entry/header to its exit(ing)/latch.

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


[libcxx] [clang] [lldb] [lld] [libc] [clang-tools-extra] [flang] [llvm] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-25 Thread via cfe-commits


@@ -614,6 +614,61 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
   printSuccessors(O, Indent);
 }
 #endif
+static void cloneCFG(VPBlockBase *Entry,
+ DenseMap &Old2NewVPBlocks);
+
+static VPBlockBase *cloneVPB(VPBlockBase *BB) {

ayalz wrote:

`cloneVPB()` seems to better fit as a virtual method `VPBlockBase::clone()`?

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


[clang] ee15e2b - [clang] Silence warning when building with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: ee15e2bd32a4677c40d927c732b26d33f88d7865

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

LOG: [clang] Silence warning when building with MSVC targetting x86

This fixes:
```
[3786/6996] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\AttrDocTable.cpp.obj
C:\git\llvm-project\clang\lib\AST\AttrDocTable.cpp(24): warning C4018: '<': 
signed/unsigned mismatch
```

Added: 


Modified: 
clang/lib/AST/AttrDocTable.cpp

Removed: 




diff  --git a/clang/lib/AST/AttrDocTable.cpp b/clang/lib/AST/AttrDocTable.cpp
index df7e3d63a6c355a..56a143b9ed29be6 100644
--- a/clang/lib/AST/AttrDocTable.cpp
+++ b/clang/lib/AST/AttrDocTable.cpp
@@ -21,7 +21,7 @@ static const llvm::StringRef AttrDoc[] = {
 };
 
 llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
-  if (K < std::size(AttrDoc))
+  if (K < (int)std::size(AttrDoc))
 return AttrDoc[K];
   return "";
 }



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


[clang-tools-extra] f33f5a0 - [clangd] Silence warning when compiling with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: f33f5a04e9feeb9b473694825d84da8322f87df9

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

LOG: [clangd] Silence warning when compiling with MSVC targetting x86

This fixes:
```
[5240/6995] Building CXX object 
tools\clang\tools\extra\clangd\CMakeFiles\obj.clangDaemon.dir\InlayHints.cpp.obj
C:\git\llvm-project\clang-tools-extra\clangd\InlayHints.cpp(1098): warning 
C4018: '<': signed/unsigned mismatch
```

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 5722ca8f66eb720..c7dce041474a1c8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -1095,7 +1095,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   if (auto *Def = Callee->getDefinition()) {
 auto I = std::distance(Callee->param_begin(),
llvm::find(Callee->parameters(), P));
-if (I < Callee->getNumParams()) {
+if (I < (int)Callee->getNumParams()) {
   return Def->getParamDecl(I);
 }
   }



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


[clang] 419d6ea - [clang] Silence warning when compiling with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: 419d6ea135dd205e1eaab368a58ae14f9f52f699

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

LOG: [clang] Silence warning when compiling with MSVC targetting x86

This fixes:
```
[3963/6996] Building CXX object 
tools\clang\lib\CodeGen\CMakeFiles\obj.clangCodeGen.dir\CGExpr.cpp.obj
C:\git\llvm-project\clang\lib\CodeGen\CGExpr.cpp(3808): warning C4018: '<=': 
signed/unsigned mismatch
```

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index c5f6b6d3a99f0b2..9196c953145b214 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3805,7 +3805,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
-  if (TrapBBs.size() <= CheckHandlerID)
+  if ((int)TrapBBs.size() <= CheckHandlerID)
 TrapBBs.resize(CheckHandlerID + 1);
 
   llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID];



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


[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread Timm Baeder via cfe-commits

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


[clang-tools-extra] [libcxx] [flang] [lldb] [llvm] [libunwind] [compiler-rt] [lld] [libc] [clang] [X86] Use RORX over SHR imm (PR #77964)

2024-01-25 Thread Simon Pilgrim via cfe-commits


@@ -4216,6 +4217,97 @@ MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(unsigned 
ROpc, unsigned MOpc,
   return CNode;
 }
 
+// When the consumer of a right shift (arithmetic or logical) wouldn't notice
+// the difference if the instruction was a rotate right instead (because the
+// bits shifted in are truncated away), the shift can be replaced by the RORX
+// instruction from BMI2. This doesn't set flags and can output to a different
+// register. However, this increases code size in most cases, and doesn't leave
+// the high bits in a useful state. There may be other situations where this
+// transformation is profitable given those conditions, but currently the
+// transformation is only made when it likely avoids spilling flags.
+bool X86DAGToDAGISel::rightShiftUncloberFlags(SDNode *N) {

RKSimon wrote:

typo: rightShiftUncloberFlags -> rightShiftUnclobberFlags

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


[libc] [lld] [clang-tools-extra] [libcxx] [libunwind] [compiler-rt] [lldb] [flang] [llvm] [clang] [X86] Use RORX over SHR imm (PR #77964)

2024-01-25 Thread Simon Pilgrim via cfe-commits

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


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


[libunwind] [clang-tools-extra] [libc] [flang] [lldb] [lld] [compiler-rt] [libcxx] [llvm] [clang] [X86] Use RORX over SHR imm (PR #77964)

2024-01-25 Thread Simon Pilgrim via cfe-commits


@@ -4216,6 +4217,97 @@ MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(unsigned 
ROpc, unsigned MOpc,
   return CNode;
 }
 
+// When the consumer of a right shift (arithmetic or logical) wouldn't notice
+// the difference if the instruction was a rotate right instead (because the
+// bits shifted in are truncated away), the shift can be replaced by the RORX
+// instruction from BMI2. This doesn't set flags and can output to a different
+// register. However, this increases code size in most cases, and doesn't leave
+// the high bits in a useful state. There may be other situations where this
+// transformation is profitable given those conditions, but currently the
+// transformation is only made when it likely avoids spilling flags.
+bool X86DAGToDAGISel::rightShiftUncloberFlags(SDNode *N) {
+  EVT VT = N->getValueType(0);
+
+  // Target has to have BMI2 for RORX
+  if (!Subtarget->hasBMI2())
+return false;
+
+  // Only handle scalar shifts.
+  if (VT.isVector())
+return false;
+
+  unsigned OpSize;
+  if (VT == MVT::i64)
+OpSize = 64;
+  else if (VT == MVT::i32)
+OpSize = 32;
+  else if (VT == MVT::i16)
+OpSize = 16;
+  else if (VT == MVT::i8)
+return false; // i8 shift can't be truncated.
+  else
+llvm_unreachable("Unexpected shift size");
+
+  unsigned TruncateSize = 0;
+  // This only works when the result is truncated.
+  for (const SDNode *User : N->uses()) {
+auto name = User->getOperationName(CurDAG);

RKSimon wrote:

unused variable

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


[clang] [libunwind] [libcxx] [flang] [compiler-rt] [clang-tools-extra] [libc] [lldb] [llvm] [lld] [X86] Use RORX over SHR imm (PR #77964)

2024-01-25 Thread Simon Pilgrim via cfe-commits


@@ -4216,6 +4217,97 @@ MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(unsigned 
ROpc, unsigned MOpc,
   return CNode;
 }
 
+// When the consumer of a right shift (arithmetic or logical) wouldn't notice
+// the difference if the instruction was a rotate right instead (because the
+// bits shifted in are truncated away), the shift can be replaced by the RORX
+// instruction from BMI2. This doesn't set flags and can output to a different
+// register. However, this increases code size in most cases, and doesn't leave
+// the high bits in a useful state. There may be other situations where this
+// transformation is profitable given those conditions, but currently the
+// transformation is only made when it likely avoids spilling flags.
+bool X86DAGToDAGISel::rightShiftUncloberFlags(SDNode *N) {
+  EVT VT = N->getValueType(0);
+
+  // Target has to have BMI2 for RORX
+  if (!Subtarget->hasBMI2())
+return false;
+
+  // Only handle scalar shifts.
+  if (VT.isVector())
+return false;
+
+  unsigned OpSize;
+  if (VT == MVT::i64)
+OpSize = 64;
+  else if (VT == MVT::i32)
+OpSize = 32;
+  else if (VT == MVT::i16)
+OpSize = 16;
+  else if (VT == MVT::i8)
+return false; // i8 shift can't be truncated.
+  else
+llvm_unreachable("Unexpected shift size");
+
+  unsigned TruncateSize = 0;
+  // This only works when the result is truncated.
+  for (const SDNode *User : N->uses()) {
+auto name = User->getOperationName(CurDAG);
+if (!User->isMachineOpcode() ||
+User->getMachineOpcode() != TargetOpcode::EXTRACT_SUBREG)
+  return false;
+EVT TuncateType = User->getValueType(0);
+if (TuncateType == MVT::i32)
+  TruncateSize = std::max(TruncateSize, 32U);
+else if (TuncateType == MVT::i16)
+  TruncateSize = std::max(TruncateSize, 16U);
+else if (TuncateType == MVT::i8)
+  TruncateSize = std::max(TruncateSize, 8U);
+else
+  return false;
+  }
+  if (TruncateSize >= OpSize)
+return false;
+
+  // The shift must be by an immediate that wouldn't expose the zero or sign
+  // extended result.
+  auto *ShiftAmount = dyn_cast(N->getOperand(1));
+  if (!ShiftAmount || ShiftAmount->getZExtValue() > OpSize - TruncateSize)
+return false;
+
+  // Only make the replacement when it avoids clobbering used flags. This is a
+  // similar heuristic as used in the conversion to LEA, namely looking at the
+  // operand for an instruction that creates flags where those flags are used.
+  // This will have both false positives and false negatives. Ideally, both of
+  // these happen later on. Perhaps in copy to flags lowering or in register
+  // allocation.
+  bool MightClobberFlags = false;
+  SDNode *Input = N->getOperand(0).getNode();
+  for (auto Use : Input->uses()) {
+if (Use->getOpcode() == ISD::CopyToReg) {
+  auto *RegisterNode =
+  dyn_cast(Use->getOperand(1).getNode());
+  if (RegisterNode && RegisterNode->getReg() == X86::EFLAGS) {
+MightClobberFlags = true;
+break;
+  }
+}
+  }
+  if (!MightClobberFlags)
+return false;

RKSimon wrote:

Is this correct? The logic appears to be flipped.

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


[libc] [clang-tools-extra] [llvm] [compiler-rt] [clang] [lldb] [lld] [flang] [libcxx] [libunwind] [X86] Use RORX over SHR imm (PR #77964)

2024-01-25 Thread Simon Pilgrim via cfe-commits

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2024-01-25 Thread kleines Filmröllchen via cfe-commits

kleinesfilmroellchen wrote:

> It's sad that there's not a single codepath that would handle all these, but 
> maybe the perfect is the enemy of the good here.

The code duplication was my reason for looking at the common path. If you're 
fine with duplicating the code I will go ahead and do that.

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


[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

In C++, we get a ComplexToBool cast, but we might not in C.

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


4 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+65-53) 
- (modified) clang/lib/AST/Interp/ByteCodeExprGen.h (+1) 
- (modified) clang/test/AST/Interp/c.c (+4) 
- (modified) clang/test/AST/Interp/complex.cpp (+2) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 24a33c32df14042..ab543bd6f3a6e16 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -231,60 +231,11 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 
   case CK_IntegralComplexToBoolean:
   case CK_FloatingComplexToBoolean: {
-std::optional ElemT =
-classifyComplexElementType(SubExpr->getType());
-if (!ElemT)
-  return false;
-// We emit the expression (__real(E) != 0 || __imag(E) != 0)
-// for us, that means (bool)E[0] || (bool)E[1]
+if (DiscardResult)
+  return this->discard(SubExpr);
 if (!this->visit(SubExpr))
   return false;
-if (!this->emitConstUint8(0, CE))
-  return false;
-if (!this->emitArrayElemPtrUint8(CE))
-  return false;
-if (!this->emitLoadPop(*ElemT, CE))
-  return false;
-if (*ElemT == PT_Float) {
-  if (!this->emitCastFloatingIntegral(PT_Bool, CE))
-return false;
-} else {
-  if (!this->emitCast(*ElemT, PT_Bool, CE))
-return false;
-}
-
-// We now have the bool value of E[0] on the stack.
-LabelTy LabelTrue = this->getLabel();
-if (!this->jumpTrue(LabelTrue))
-  return false;
-
-if (!this->emitConstUint8(1, CE))
-  return false;
-if (!this->emitArrayElemPtrPopUint8(CE))
-  return false;
-if (!this->emitLoadPop(*ElemT, CE))
-  return false;
-if (*ElemT == PT_Float) {
-  if (!this->emitCastFloatingIntegral(PT_Bool, CE))
-return false;
-} else {
-  if (!this->emitCast(*ElemT, PT_Bool, CE))
-return false;
-}
-// Leave the boolean value of E[1] on the stack.
-LabelTy EndLabel = this->getLabel();
-this->jump(EndLabel);
-
-this->emitLabel(LabelTrue);
-if (!this->emitPopPtr(CE))
-  return false;
-if (!this->emitConstBool(true, CE))
-  return false;
-
-this->fallthrough(EndLabel);
-this->emitLabel(EndLabel);
-
-return true;
+return this->emitComplexBoolCast(SubExpr);
   }
 
   case CK_IntegralComplexToReal:
@@ -1906,8 +1857,15 @@ bool ByteCodeExprGen::visitInitializer(const 
Expr *E) {
 template 
 bool ByteCodeExprGen::visitBool(const Expr *E) {
   std::optional T = classify(E->getType());
-  if (!T)
+  if (!T) {
+// Convert complex values to bool.
+if (E->getType()->isAnyComplexType()) {
+  if (!this->visit(E))
+return false;
+  return this->emitComplexBoolCast(E);
+}
 return false;
+  }
 
   if (!this->visit(E))
 return false;
@@ -2997,6 +2955,60 @@ bool ByteCodeExprGen::emitComplexReal(const 
Expr *SubExpr) {
   return true;
 }
 
+template 
+bool ByteCodeExprGen::emitComplexBoolCast(const Expr *E) {
+  assert(!DiscardResult);
+  PrimType ElemT = classifyComplexElementType(E->getType());
+  // We emit the expression (__real(E) != 0 || __imag(E) != 0)
+  // for us, that means (bool)E[0] || (bool)E[1]
+  if (!this->emitConstUint8(0, E))
+return false;
+  if (!this->emitArrayElemPtrUint8(E))
+return false;
+  if (!this->emitLoadPop(ElemT, E))
+return false;
+  if (ElemT == PT_Float) {
+if (!this->emitCastFloatingIntegral(PT_Bool, E))
+  return false;
+  } else {
+if (!this->emitCast(ElemT, PT_Bool, E))
+  return false;
+  }
+
+  // We now have the bool value of E[0] on the stack.
+  LabelTy LabelTrue = this->getLabel();
+  if (!this->jumpTrue(LabelTrue))
+return false;
+
+  if (!this->emitConstUint8(1, E))
+return false;
+  if (!this->emitArrayElemPtrPopUint8(E))
+return false;
+  if (!this->emitLoadPop(ElemT, E))
+return false;
+  if (ElemT == PT_Float) {
+if (!this->emitCastFloatingIntegral(PT_Bool, E))
+  return false;
+  } else {
+if (!this->emitCast(ElemT, PT_Bool, E))
+  return false;
+  }
+  // Leave the boolean value of E[1] on the stack.
+  LabelTy EndLabel = this->getLabel();
+  this->jump(EndLabel);
+
+  this->emitLabel(LabelTrue);
+  if (!this->emitPopPtr(E))
+return false;
+  if (!this->emitConstBool(true, E))
+return false;
+
+  this->fallthrough(EndLabel);
+  this->emitLabel(EndLabel);
+
+  return true;
+}
+
 /// When calling this, we have a pointer of the local-to-destroy
 /// on the stack.
 /// Emit destruction of record types (or arrays of record types).
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 63ea8292b587675..aafd78adf6a5311 100644
--- a/clang/lib/AST/Interp

[clang] [clang][Interp] Handle complex values in visitBool() (PR #79452)

2024-01-25 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/79452

In C++, we get a ComplexToBool cast, but we might not in C.

>From b207bff4cda462869bcf8547e44d23e5b8fc5e94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 25 Jan 2024 15:20:52 +0100
Subject: [PATCH] [clang][Interp] Handle complex values in visitBool()

In C++, we get a ComplexToBool cast, but we might not in C.
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 118 +--
 clang/lib/AST/Interp/ByteCodeExprGen.h   |   1 +
 clang/test/AST/Interp/c.c|   4 +
 clang/test/AST/Interp/complex.cpp|   2 +
 4 files changed, 72 insertions(+), 53 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 24a33c32df14042..ab543bd6f3a6e16 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -231,60 +231,11 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 
   case CK_IntegralComplexToBoolean:
   case CK_FloatingComplexToBoolean: {
-std::optional ElemT =
-classifyComplexElementType(SubExpr->getType());
-if (!ElemT)
-  return false;
-// We emit the expression (__real(E) != 0 || __imag(E) != 0)
-// for us, that means (bool)E[0] || (bool)E[1]
+if (DiscardResult)
+  return this->discard(SubExpr);
 if (!this->visit(SubExpr))
   return false;
-if (!this->emitConstUint8(0, CE))
-  return false;
-if (!this->emitArrayElemPtrUint8(CE))
-  return false;
-if (!this->emitLoadPop(*ElemT, CE))
-  return false;
-if (*ElemT == PT_Float) {
-  if (!this->emitCastFloatingIntegral(PT_Bool, CE))
-return false;
-} else {
-  if (!this->emitCast(*ElemT, PT_Bool, CE))
-return false;
-}
-
-// We now have the bool value of E[0] on the stack.
-LabelTy LabelTrue = this->getLabel();
-if (!this->jumpTrue(LabelTrue))
-  return false;
-
-if (!this->emitConstUint8(1, CE))
-  return false;
-if (!this->emitArrayElemPtrPopUint8(CE))
-  return false;
-if (!this->emitLoadPop(*ElemT, CE))
-  return false;
-if (*ElemT == PT_Float) {
-  if (!this->emitCastFloatingIntegral(PT_Bool, CE))
-return false;
-} else {
-  if (!this->emitCast(*ElemT, PT_Bool, CE))
-return false;
-}
-// Leave the boolean value of E[1] on the stack.
-LabelTy EndLabel = this->getLabel();
-this->jump(EndLabel);
-
-this->emitLabel(LabelTrue);
-if (!this->emitPopPtr(CE))
-  return false;
-if (!this->emitConstBool(true, CE))
-  return false;
-
-this->fallthrough(EndLabel);
-this->emitLabel(EndLabel);
-
-return true;
+return this->emitComplexBoolCast(SubExpr);
   }
 
   case CK_IntegralComplexToReal:
@@ -1906,8 +1857,15 @@ bool ByteCodeExprGen::visitInitializer(const 
Expr *E) {
 template 
 bool ByteCodeExprGen::visitBool(const Expr *E) {
   std::optional T = classify(E->getType());
-  if (!T)
+  if (!T) {
+// Convert complex values to bool.
+if (E->getType()->isAnyComplexType()) {
+  if (!this->visit(E))
+return false;
+  return this->emitComplexBoolCast(E);
+}
 return false;
+  }
 
   if (!this->visit(E))
 return false;
@@ -2997,6 +2955,60 @@ bool ByteCodeExprGen::emitComplexReal(const 
Expr *SubExpr) {
   return true;
 }
 
+template 
+bool ByteCodeExprGen::emitComplexBoolCast(const Expr *E) {
+  assert(!DiscardResult);
+  PrimType ElemT = classifyComplexElementType(E->getType());
+  // We emit the expression (__real(E) != 0 || __imag(E) != 0)
+  // for us, that means (bool)E[0] || (bool)E[1]
+  if (!this->emitConstUint8(0, E))
+return false;
+  if (!this->emitArrayElemPtrUint8(E))
+return false;
+  if (!this->emitLoadPop(ElemT, E))
+return false;
+  if (ElemT == PT_Float) {
+if (!this->emitCastFloatingIntegral(PT_Bool, E))
+  return false;
+  } else {
+if (!this->emitCast(ElemT, PT_Bool, E))
+  return false;
+  }
+
+  // We now have the bool value of E[0] on the stack.
+  LabelTy LabelTrue = this->getLabel();
+  if (!this->jumpTrue(LabelTrue))
+return false;
+
+  if (!this->emitConstUint8(1, E))
+return false;
+  if (!this->emitArrayElemPtrPopUint8(E))
+return false;
+  if (!this->emitLoadPop(ElemT, E))
+return false;
+  if (ElemT == PT_Float) {
+if (!this->emitCastFloatingIntegral(PT_Bool, E))
+  return false;
+  } else {
+if (!this->emitCast(ElemT, PT_Bool, E))
+  return false;
+  }
+  // Leave the boolean value of E[1] on the stack.
+  LabelTy EndLabel = this->getLabel();
+  this->jump(EndLabel);
+
+  this->emitLabel(LabelTrue);
+  if (!this->emitPopPtr(E))
+return false;
+  if (!this->emitConstBool(true, E))
+return false;
+
+  this->fallthrough(EndLabel);
+  this->emitLabel(EndLabel);
+
+  return true;
+}
+
 /// When calling this, we have a pointer of the local-to-destroy
 /// on the stack.
 /// 

[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2024-01-25 Thread kleines Filmröllchen via cfe-commits


@@ -211,10 +214,12 @@ class IncludeInserter {
   // include path of non-verbatim header will not be shortened.
   IncludeInserter(StringRef FileName, StringRef Code,
   const format::FormatStyle &Style, StringRef BuildDir,
-  HeaderSearch *HeaderSearchInfo)
+  HeaderSearch *HeaderSearchInfo, HeaderFilter QuotedHeaders,

kleinesfilmroellchen wrote:

I'm not sure how much difference that makes. The ArrayRef usage is based on 
other code I've seen around, and while the config lives for a while, the 
IncludeInserter is only briefly used to add an include.

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


[clang-tools-extra] [clangd] Attempt to fix https://github.com/clangd/clangd/issues/1536 (PR #79448)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Tor Shepherd (torshepherd)


Changes

This PR attempts to fix [1536.](https://github.com/clangd/clangd/issues/1536). 
See in the unit tests, when all quick fixes are of the same `code`, 
`isPreferred` will be true. However, this doesn't seem to change the behavior 
in vscode:

![image](https://github.com/llvm/llvm-project/assets/49597791/1d8236c3-3e43-4260-b655-d33d6cac6e42)


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


3 Files Affected:

- (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+41-37) 
- (modified) 
clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test (+2) 
- (modified) clang-tools-extra/clangd/test/fixits-codeaction.test (+2) 


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9..5fbd09fdcfdf42 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -27,7 +27,9 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Allocator.h"
@@ -117,10 +119,9 @@ CodeAction toCodeAction(const Fix &F, const URIForFile 
&File,
 Edit.textDocument = VersionedTextDocumentIdentifier{{File}, Version};
 for (const auto &E : F.Edits)
   Edit.edits.push_back(
-  {E.range, E.newText,
-   SupportChangeAnnotation ? E.annotationId : ""});
+  {E.range, E.newText, SupportChangeAnnotation ? E.annotationId : ""});
 if (SupportChangeAnnotation) {
-  for (const auto &[AID, Annotation]: F.Annotations)
+  for (const auto &[AID, Annotation] : F.Annotations)
 Action.edit->changeAnnotations[AID] = Annotation;
 }
   }
@@ -861,24 +862,24 @@ void ClangdLSPServer::onRename(const RenameParams &Params,
   if (!Server->getDraft(File))
 return Reply(llvm::make_error(
 "onRename called for non-added file", ErrorCode::InvalidParams));
-  Server->rename(File, Params.position, Params.newName, Opts.Rename,
- [File, Params, Reply = std::move(Reply),
-  this](llvm::Expected R) mutable {
-   if (!R)
- return Reply(R.takeError());
-   if (auto Err = validateEdits(*Server, R->GlobalChanges))
- return Reply(std::move(Err));
-   WorkspaceEdit Result;
-   // FIXME: use documentChanges if SupportDocumentChanges is
-   // true.
-   Result.changes.emplace();
-   for (const auto &Rep : R->GlobalChanges) {
- (*Result
-   .changes)[URI::createFile(Rep.first()).toString()] =
- Rep.second.asTextEdits();
-   }
-   Reply(Result);
- });
+  Server->rename(
+  File, Params.position, Params.newName, Opts.Rename,
+  [File, Params, Reply = std::move(Reply),
+   this](llvm::Expected R) mutable {
+if (!R)
+  return Reply(R.takeError());
+if (auto Err = validateEdits(*Server, R->GlobalChanges))
+  return Reply(std::move(Err));
+WorkspaceEdit Result;
+// FIXME: use documentChanges if SupportDocumentChanges is
+// true.
+Result.changes.emplace();
+for (const auto &Rep : R->GlobalChanges) {
+  (*Result.changes)[URI::createFile(Rep.first()).toString()] =
+  Rep.second.asTextEdits();
+}
+Reply(Result);
+  });
 }
 
 void ClangdLSPServer::onDocumentDidClose(
@@ -1014,7 +1015,7 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams 
&Params,
   std::map ToLSPDiags;
   ClangdServer::CodeActionInputs Inputs;
 
-  for (const auto& LSPDiag : Params.context.diagnostics) {
+  for (const auto &LSPDiag : Params.context.diagnostics) {
 if (auto DiagRef = getDiagRef(File.file(), LSPDiag)) {
   ToLSPDiags[*DiagRef] = LSPDiag;
   Inputs.Diagnostics.push_back(*DiagRef);
@@ -1023,13 +1024,9 @@ void ClangdLSPServer::onCodeAction(const 
CodeActionParams &Params,
   Inputs.File = File.file();
   Inputs.Selection = Params.range;
   Inputs.RequestedActionKinds = Params.context.only;
-  Inputs.TweakFilter = [this](const Tweak &T) {
-return Opts.TweakFilter(T);
-  };
-  auto CB = [this,
- Reply = std::move(Reply),
- ToLSPDiags = std::move(ToLSPDiags), File,
- Selection = Params.range](
+  Inputs.TweakFilter = [this](const Tweak &T) { return Opts.TweakFilter(T); };
+  auto CB = [this, Reply = std::move(Reply), ToLSPDiags = 
std::move(ToLSPDiags),
+ File, Selection = Params.range](
 llvm::Expected Fixits) mutable 
{
 if (!Fixits)
 

[clang-tools-extra] [clangd] Attempt to fix https://github.com/clangd/clangd/issues/1536 (PR #79448)

2024-01-25 Thread via cfe-commits

github-actions[bot] wrote:

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

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

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

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

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

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

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

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


[clang-tools-extra] [clangd] Attempt to fix https://github.com/clangd/clangd/issues/1536 (PR #79448)

2024-01-25 Thread Tor Shepherd via cfe-commits

https://github.com/torshepherd created 
https://github.com/llvm/llvm-project/pull/79448

This PR attempts to fix [1536.](https://github.com/clangd/clangd/issues/1536). 
See in the unit tests, when all quick fixes are of the same `code`, 
`isPreferred` will be true. However, this doesn't seem to change the behavior 
in vscode:

![image](https://github.com/llvm/llvm-project/assets/49597791/1d8236c3-3e43-4260-b655-d33d6cac6e42)


>From 6bb871f64073132683bab2318c228a4ef7723c8e Mon Sep 17 00:00:00 2001
From: Tor Shepherd 
Date: Wed, 24 Jan 2024 23:43:52 -0500
Subject: [PATCH 1/2] second try

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 78 ++--
 1 file changed, 41 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9b..5fbd09fdcfdf420 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -27,7 +27,9 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Allocator.h"
@@ -117,10 +119,9 @@ CodeAction toCodeAction(const Fix &F, const URIForFile 
&File,
 Edit.textDocument = VersionedTextDocumentIdentifier{{File}, Version};
 for (const auto &E : F.Edits)
   Edit.edits.push_back(
-  {E.range, E.newText,
-   SupportChangeAnnotation ? E.annotationId : ""});
+  {E.range, E.newText, SupportChangeAnnotation ? E.annotationId : ""});
 if (SupportChangeAnnotation) {
-  for (const auto &[AID, Annotation]: F.Annotations)
+  for (const auto &[AID, Annotation] : F.Annotations)
 Action.edit->changeAnnotations[AID] = Annotation;
 }
   }
@@ -861,24 +862,24 @@ void ClangdLSPServer::onRename(const RenameParams &Params,
   if (!Server->getDraft(File))
 return Reply(llvm::make_error(
 "onRename called for non-added file", ErrorCode::InvalidParams));
-  Server->rename(File, Params.position, Params.newName, Opts.Rename,
- [File, Params, Reply = std::move(Reply),
-  this](llvm::Expected R) mutable {
-   if (!R)
- return Reply(R.takeError());
-   if (auto Err = validateEdits(*Server, R->GlobalChanges))
- return Reply(std::move(Err));
-   WorkspaceEdit Result;
-   // FIXME: use documentChanges if SupportDocumentChanges is
-   // true.
-   Result.changes.emplace();
-   for (const auto &Rep : R->GlobalChanges) {
- (*Result
-   .changes)[URI::createFile(Rep.first()).toString()] =
- Rep.second.asTextEdits();
-   }
-   Reply(Result);
- });
+  Server->rename(
+  File, Params.position, Params.newName, Opts.Rename,
+  [File, Params, Reply = std::move(Reply),
+   this](llvm::Expected R) mutable {
+if (!R)
+  return Reply(R.takeError());
+if (auto Err = validateEdits(*Server, R->GlobalChanges))
+  return Reply(std::move(Err));
+WorkspaceEdit Result;
+// FIXME: use documentChanges if SupportDocumentChanges is
+// true.
+Result.changes.emplace();
+for (const auto &Rep : R->GlobalChanges) {
+  (*Result.changes)[URI::createFile(Rep.first()).toString()] =
+  Rep.second.asTextEdits();
+}
+Reply(Result);
+  });
 }
 
 void ClangdLSPServer::onDocumentDidClose(
@@ -1014,7 +1015,7 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams 
&Params,
   std::map ToLSPDiags;
   ClangdServer::CodeActionInputs Inputs;
 
-  for (const auto& LSPDiag : Params.context.diagnostics) {
+  for (const auto &LSPDiag : Params.context.diagnostics) {
 if (auto DiagRef = getDiagRef(File.file(), LSPDiag)) {
   ToLSPDiags[*DiagRef] = LSPDiag;
   Inputs.Diagnostics.push_back(*DiagRef);
@@ -1023,13 +1024,9 @@ void ClangdLSPServer::onCodeAction(const 
CodeActionParams &Params,
   Inputs.File = File.file();
   Inputs.Selection = Params.range;
   Inputs.RequestedActionKinds = Params.context.only;
-  Inputs.TweakFilter = [this](const Tweak &T) {
-return Opts.TweakFilter(T);
-  };
-  auto CB = [this,
- Reply = std::move(Reply),
- ToLSPDiags = std::move(ToLSPDiags), File,
- Selection = Params.range](
+  Inputs.TweakFilter = [this](const Tweak &T) { return Opts.TweakFilter(T); };
+  auto CB = [this, Reply = std::move(Reply), ToLSPDiags = 
std::move(ToLSPDiags),
+ File, Selection = Params.range](
 llvm::Expected Fixits) mutable 
{
 if (!Fixits)
   return Reply(Fixits.takeError());
@@ -1038,27

[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2024-01-25 Thread kleines Filmröllchen via cfe-commits


@@ -296,6 +296,19 @@ struct Fragment {
 // ::). All nested namespaces are affected as well.
 // Affects availability of the AddUsing tweak.
 std::vector> FullyQualifiedNamespaces;
+
+/// List of regexes for headers that should always be included with a
+/// ""-style include. By default, and in case of a conflict with
+/// AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and
+/// AngledHeaders), system headers use <> and non-system headers use "".
+/// These can match any suffix of the header file in question.

kleinesfilmroellchen wrote:

We're matching against the spelling; at least in SerenityOS this is a necessary 
distinction: Naming a same-directory header via `"Widget.h"` will result in 
quotes, but naming the same header via an "absolute" path like 
`` should get you an angled include.

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


[libcxx] [clang] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-25 Thread Erich Keane via cfe-commits

erichkeane wrote:

>As I understood the author, more time was needed to prepare the tests and the 
>fix. I just tried to bring the tip of the tree to a good state soon (our 
>internal release process was blocked on this) without putting any pressure on 
>the author.

Typically when the author is engaging fairly quickly and only needs a short 
time (he had already identified the problem and only had process-related 
concerns), it is preferred to be understanding/polite and give them time to 
work on it.

While I am sympathetic to your internal processes, it seems to me that they 
should be more tolerant of a ToT that is not particularly stable, as is the 
case with Clang.

> With the standard as is, `B(A)` should be a better match because of 
> [[over.ics.list]p(7.1)](https://wg21.link/over.ics.list#7.1), it is an Exact 
> Match, and `B(std::vector)` is a user defined conversion.
> 
> With the current CWG2311 fix, the call to `B(A)` is an Exact Match because 
> it's an `A` prvalue.
> 
> In either case, `B(A)` should unambiguously be chosen over 
> `B(std::vector)` given `{ A() }` as an initializer.
> 
> https://github.com/llvm/llvm-project/blob/7b11c08c664863fbcd7a3058179b0af3de5d28e4/clang/lib/Sema/SemaOverload.cpp#L1593
> 
> ^ This line is the issue: `isCopyConstructor()` checks only for lvalue 
> reference copy constructors, and the move constructor is selected (i.e., if 
> you force a copy constructor to be called instead, it works: 
> https://godbolt.org/z/rGEsPdMx8).
> 
> There is no reason to check for copy constructors here. Removing 
> `Constructor->isCopyConstructor() &&` fixes the issue (`B(A)` is chosen, and 
> all existing tests still pass)
> 
> @cor3ntin I have some extra test cases I would want to add too. Should I make 
> a new pull request? Or are we going to reopen this one and target llvm 19?

If you haven't already, you can re-open this one.  However, you'll ALSO have to 
make a 'differential' PR against 18.x so that this can be fixed there too.

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


[lld] [flang] [llvm] [clang] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-01-25 Thread Konstantin Zhuravlyov via cfe-commits


@@ -49,6 +49,11 @@ constexpr uint32_t VersionMajorV5 = 1;
 /// HSA metadata minor version for code object V5.
 constexpr uint32_t VersionMinorV5 = 2;
 
+/// HSA metadata major version for code object V6.
+constexpr uint32_t VersionMajorV6 = 1;
+/// HSA metadata minor version for code object V6.
+constexpr uint32_t VersionMinorV6 = 3;

kzhuravl wrote:

@AlexVlx, this "HSA Metadata" is AMD-specific "HSA Metadata", so it is not part 
of the HSA standards. Maybe updating the comment to mention it is AMD-specific 
should be done.

I'd also prefer to not update the metadata version unless we change it.

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


[clang] [llvm] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-25 Thread Sam Tebbs via cfe-commits




SamTebbs33 wrote:

Agreed. I tried moving it to Support but that introduced a dependency cycle, so 
I re-implemented some of the SMEAttributes logic in-place instead.

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


[clang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/79373

>From 145b7bc932ce3ffa46545cd7af29b1c93981429c Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Wed, 24 Jan 2024 15:34:00 -0600
Subject: [PATCH 1/3] [NVPTX] Add support for -march=native in standalone NVPTX

Summary:
We support `--target=nvptx64-nvidia-cuda` as a way to target the NVPTX
architecture from standard CPU. This patch simply uses the existing
support for handling `--offload-arch=native` to also apply to the
standalone toolchain.
---
 clang/lib/Driver/ToolChains/Cuda.cpp   | 61 +-
 clang/lib/Driver/ToolChains/Cuda.h | 10 ++--
 clang/test/Driver/nvptx-cuda-system-arch.c |  5 ++
 3 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 1462576ca870e6..6215c43b5fc96b 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -738,9 +738,18 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if (!DAL->hasArg(options::OPT_march_EQ))
+  if (!DAL->hasArg(options::OPT_march_EQ)) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
+  } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr)
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << getArchName() << llvm::toString(GPUsOrErr.takeError()) << 
"-march";
+else
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
+Args.MakeArgString(GPUsOrErr->front()));
+  }
 
   return DAL;
 }
@@ -783,6 +792,31 @@ void NVPTXToolChain::adjustDebugInfoKind(
   }
 }
 
+Expected>
+NVPTXToolChain::getSystemGPUArchs(const ArgList &Args) const {
+  // Detect NVIDIA GPUs availible on the system.
+  std::string Program;
+  if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
+Program = A->getValue();
+  else
+Program = GetProgramPath("nvptx-arch");
+
+  auto StdoutOrErr = executeToolChainProgram(Program);
+  if (!StdoutOrErr)
+return StdoutOrErr.takeError();
+
+  SmallVector GPUArchs;
+  for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
+if (!Arch.empty())
+  GPUArchs.push_back(Arch.str());
+
+  if (GPUArchs.empty())
+return llvm::createStringError(std::error_code(),
+   "No NVIDIA GPU detected in the system");
+
+  return std::move(GPUArchs);
+}
+
 /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary,
 /// which isn't properly a linker but nonetheless performs the step of 
stitching
 /// together object files from the assembler into a single blob.
@@ -948,31 +982,6 @@ CudaToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
   return DAL;
 }
 
-Expected>
-CudaToolChain::getSystemGPUArchs(const ArgList &Args) const {
-  // Detect NVIDIA GPUs availible on the system.
-  std::string Program;
-  if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
-Program = A->getValue();
-  else
-Program = GetProgramPath("nvptx-arch");
-
-  auto StdoutOrErr = executeToolChainProgram(Program);
-  if (!StdoutOrErr)
-return StdoutOrErr.takeError();
-
-  SmallVector GPUArchs;
-  for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
-if (!Arch.empty())
-  GPUArchs.push_back(Arch.str());
-
-  if (GPUArchs.empty())
-return llvm::createStringError(std::error_code(),
-   "No NVIDIA GPU detected in the system");
-
-  return std::move(GPUArchs);
-}
-
 Tool *NVPTXToolChain::buildAssembler() const {
   return new tools::NVPTX::Assembler(*this);
 }
diff --git a/clang/lib/Driver/ToolChains/Cuda.h 
b/clang/lib/Driver/ToolChains/Cuda.h
index 8a053f3393e120..43c17ba7c0ba03 100644
--- a/clang/lib/Driver/ToolChains/Cuda.h
+++ b/clang/lib/Driver/ToolChains/Cuda.h
@@ -168,6 +168,11 @@ class LLVM_LIBRARY_VISIBILITY NVPTXToolChain : public 
ToolChain {
   unsigned GetDefaultDwarfVersion() const override { return 2; }
   unsigned getMaxDwarfVersion() const override { return 2; }
 
+  /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
+  /// if unable to find one.
+  virtual Expected>
+  getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
+
   CudaInstallationDetector CudaInstallation;
 
 protected:
@@ -223,11 +228,6 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public 
NVPTXToolChain {
 
   const ToolChain &HostTC;
 
-  /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
-  /// if unable to find one.
-  virtual Expected>
-  getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
-
 protected:
   Tool *buildAssembler() const override; // ptxas
   Tool *buildLinker() const override;//

[clang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/79373

>From 145b7bc932ce3ffa46545cd7af29b1c93981429c Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Wed, 24 Jan 2024 15:34:00 -0600
Subject: [PATCH 1/2] [NVPTX] Add support for -march=native in standalone NVPTX

Summary:
We support `--target=nvptx64-nvidia-cuda` as a way to target the NVPTX
architecture from standard CPU. This patch simply uses the existing
support for handling `--offload-arch=native` to also apply to the
standalone toolchain.
---
 clang/lib/Driver/ToolChains/Cuda.cpp   | 61 +-
 clang/lib/Driver/ToolChains/Cuda.h | 10 ++--
 clang/test/Driver/nvptx-cuda-system-arch.c |  5 ++
 3 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 1462576ca870e6f..6215c43b5fc96bd 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -738,9 +738,18 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if (!DAL->hasArg(options::OPT_march_EQ))
+  if (!DAL->hasArg(options::OPT_march_EQ)) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
+  } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr)
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << getArchName() << llvm::toString(GPUsOrErr.takeError()) << 
"-march";
+else
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
+Args.MakeArgString(GPUsOrErr->front()));
+  }
 
   return DAL;
 }
@@ -783,6 +792,31 @@ void NVPTXToolChain::adjustDebugInfoKind(
   }
 }
 
+Expected>
+NVPTXToolChain::getSystemGPUArchs(const ArgList &Args) const {
+  // Detect NVIDIA GPUs availible on the system.
+  std::string Program;
+  if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
+Program = A->getValue();
+  else
+Program = GetProgramPath("nvptx-arch");
+
+  auto StdoutOrErr = executeToolChainProgram(Program);
+  if (!StdoutOrErr)
+return StdoutOrErr.takeError();
+
+  SmallVector GPUArchs;
+  for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
+if (!Arch.empty())
+  GPUArchs.push_back(Arch.str());
+
+  if (GPUArchs.empty())
+return llvm::createStringError(std::error_code(),
+   "No NVIDIA GPU detected in the system");
+
+  return std::move(GPUArchs);
+}
+
 /// CUDA toolchain.  Our assembler is ptxas, and our "linker" is fatbinary,
 /// which isn't properly a linker but nonetheless performs the step of 
stitching
 /// together object files from the assembler into a single blob.
@@ -948,31 +982,6 @@ CudaToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
   return DAL;
 }
 
-Expected>
-CudaToolChain::getSystemGPUArchs(const ArgList &Args) const {
-  // Detect NVIDIA GPUs availible on the system.
-  std::string Program;
-  if (Arg *A = Args.getLastArg(options::OPT_nvptx_arch_tool_EQ))
-Program = A->getValue();
-  else
-Program = GetProgramPath("nvptx-arch");
-
-  auto StdoutOrErr = executeToolChainProgram(Program);
-  if (!StdoutOrErr)
-return StdoutOrErr.takeError();
-
-  SmallVector GPUArchs;
-  for (StringRef Arch : llvm::split((*StdoutOrErr)->getBuffer(), "\n"))
-if (!Arch.empty())
-  GPUArchs.push_back(Arch.str());
-
-  if (GPUArchs.empty())
-return llvm::createStringError(std::error_code(),
-   "No NVIDIA GPU detected in the system");
-
-  return std::move(GPUArchs);
-}
-
 Tool *NVPTXToolChain::buildAssembler() const {
   return new tools::NVPTX::Assembler(*this);
 }
diff --git a/clang/lib/Driver/ToolChains/Cuda.h 
b/clang/lib/Driver/ToolChains/Cuda.h
index 8a053f3393e1206..43c17ba7c0ba03d 100644
--- a/clang/lib/Driver/ToolChains/Cuda.h
+++ b/clang/lib/Driver/ToolChains/Cuda.h
@@ -168,6 +168,11 @@ class LLVM_LIBRARY_VISIBILITY NVPTXToolChain : public 
ToolChain {
   unsigned GetDefaultDwarfVersion() const override { return 2; }
   unsigned getMaxDwarfVersion() const override { return 2; }
 
+  /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
+  /// if unable to find one.
+  virtual Expected>
+  getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
+
   CudaInstallationDetector CudaInstallation;
 
 protected:
@@ -223,11 +228,6 @@ class LLVM_LIBRARY_VISIBILITY CudaToolChain : public 
NVPTXToolChain {
 
   const ToolChain &HostTC;
 
-  /// Uses nvptx-arch tool to get arch of the system GPU. Will return error
-  /// if unable to find one.
-  virtual Expected>
-  getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
-
 protected:
   Tool *buildAssembler() const override; // ptxas
   Tool *buildLinker() const override;  

[clang] Add option -fstdlib-hardening= (PR #78763)

2024-01-25 Thread Louis Dionne via cfe-commits


@@ -851,6 +851,28 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   Twine(getClangFullCPPVersion()) + "\"");
 
   // Initialize language-specific preprocessor defines.
+  if (LangOpts.getStdlibHardeningMode()) {
+const char *StdlibHardeningStr;
+
+switch (LangOpts.getStdlibHardeningMode()) {
+case clang::LangOptions::STDLIB_HARDENING_MODE_NOT_SPECIFIED:
+  llvm_unreachable("Unexpected libc++ hardening mode value");
+case clang::LangOptions::STDLIB_HARDENING_MODE_NONE:
+  StdlibHardeningStr = "_STDLIB_HARDENING_MODE_NONE";

ldionne wrote:

The macros used by libc++ are `_LIBCPP_HARDENING_MODE`, 
`_LIBCPP_HARDENING_MODE_NONE` & al. While the naming of the clang option should 
use the "any standard library" terminology, the actual macros we set must be 
the libc++ ones. If libstdc++ had something similar in the future, we would 
switch to:

```c++
if (LangOpts.getStdlibHardeningMode()) {
  if (stdlib is libc++) {
set-macros-for-libcxx;
  } else {
set-macros-for-libstdcxx;
  }
}
```

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


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits

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

LGTM with latest changes.

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


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits


@@ -4266,19 +4285,140 @@ bool 
InstCombinerImpl::tryToSinkInstruction(Instruction *I,
 
   // Perform salvaging without the clones, then sink the clones.
   if (!DIIClones.empty()) {
-// RemoveDIs: pass in empty vector of DPValues until we get to 
instrumenting
-// this pass.
-SmallVector DummyDPValues;
-salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, DummyDPValues);
+salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, {});
 // The clones are in reverse order of original appearance, reverse again to
 // maintain the original order.
 for (auto &DIIClone : llvm::reverse(DIIClones)) {
   DIIClone->insertBefore(&*InsertPos);
   LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n');
 }
   }
+}
 
-  return true;
+void InstCombinerImpl::tryToSinkInstructionDPValues(
+Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
+BasicBlock *DestBlock, SmallVectorImpl &DPValues) {
+  // Implementation of tryToSinkInstructionDbgValues, but for the DPValue of
+  // variable assignments rather than dbg.values.
+
+  // Fetch all DPValues not already in the destination.
+  SmallVector DPValuesToSalvage;
+  for (auto &DPV : DPValues)
+if (DPV->getParent() != DestBlock)
+  DPValuesToSalvage.push_back(DPV);
+
+  // Fetch a second collection, of DPValues in the source block that we're 
going
+  // to sink.
+  SmallVector DPValuesToSink;
+  for (DPValue *DPV : DPValuesToSalvage)
+if (DPV->getParent() == SrcBlock)
+  DPValuesToSink.push_back(DPV);
+
+  // Sort DPValues according to their position in the block. This is a partial

SLTozer wrote:

I actually thinking about the performance of removing all the 
filtermap/duplicate detection logic and just iterating over getDbgValueRange() 
to determine whether A or B comes first when they're attached to the same 
instruction - I submitted a quick test to the compile time tracker[0] though 
and it looks like it's neutral for most cases and a slowdown in the bad case 
(testing specifically with RemoveDIs enabled), so I'm happy with this approach.
[0] 
http://llvm-compile-time-tracker.com/compare.php?from=319280746b199b35c49798383b6dd4c01286c5ff&to=c29a7ff328a4148aabd7e147f2bfc04e9801fcb6&stat=instructions:u

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


[clang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I think I'm with Art on this one.
> 
> > > Problem #2 [...] The arch=native will create a working configuration, but 
> > > would build more than necessary.
> > 
> > 
> > It will target the first GPU it finds. We could maybe change the behavior 
> > to detect the newest, but the idea is just to target the user's system.
> 
> OK, but I think this is worse.
> 
> Now it's basically always incorrect to ship a build system which uses 
> arch=native, because the people running the build might very reasonably have 
> multiple GPUs in their system, and which GPU clang picks is unspecified.

It's not unspecified per-se, it just picks the one the CUDA driver assigned to 
ID zero, so it will correspond to the layman using a default device if loaded 
into CUDA.

The AMDGPU version has a warning when multiple GPUs are found. I should 
probably add the same thing here as it would make this explicit.
 
> But we all know people are going to do it anyway.
> 
> Given that this feature cannot correctly be used with a build system, and 
> given that 99.99% of invocations of clang are from a build system that the 
> user running the build did not write, it seems to me that we should not add a 
> feature that is such a footgun when used with a build system.
> 
> (A non-CUDA C++ file compiled with march=native will almost surely run on 
> your computer, whereas this won't, and it's unpredictable whether or not it 
> will, depending on the order the nvidia driver returns GPUs in. So there's no 
> good analogy here.)
> 
> If we were going to add this, I think we should compile for all the GPUs in 
> your system, like Art had assumed. I think that's better, but it has other 
> problems, like slow builds and also the fact that your graphics GPU is likely 
> less powerful than your compute GPU, so now compilation is going to fail 
> because you're e.g. using tensorcores and compiling for a GPU that doesn't 
> have them. So again you can't really use arch=native in a build system, even 
> if you say "requires an sm80 GPU", because really the requirement is "has an 
> sm80 GPU and no others in the machine".

We already do this for CUDA with `--offload-arch=native`. This handling is for 
targeting NVPTX directly, similar to OpenCL. That means there is no concept of 
multiple device passes, there can only be a single target architecture just 
like compiling standard C++ code. I'd like to have `-march=native` because it 
makes it easier to just build something that works for testing purposes, and 
it's consistent with all the other native handling, since the NVPTX target is 
the only one that doesn't support it to my knowledge.

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


[clang] [analyzer] Avoid a crash in a debug printout function (PR #79446)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (NagyDonat)


Changes

Previously the function `RangeConstraintManager::printValue()` crashed when it 
encountered an empty rangeset (because `RangeSet::getBitwidth()` and 
`RangeSet::isUnsigned()` assert that the rangeset is not empty). This commit 
adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and during 
manual debugging), the impacts of this commit are very limited.

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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+6-2) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..cc1cad1e002cdf 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,8 +3270,12 @@ void RangeConstraintManager::printJson(raw_ostream &Out, 
ProgramStateRef State,
 void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef 
State,
 SymbolRef Sym) {
   const RangeSet RS = getRange(State, Sym);
-  Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
-  RS.dump(Out);
+  if (RS.isEmpty()) {
+Out << "";
+  } else {
+Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+RS.dump(Out);
+  }
 }
 
 static std::string toString(const SymbolRef &Sym) {

``




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


[clang] [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (PR #79109)

2024-01-25 Thread Chen Zheng via cfe-commits

chenzheng1030 wrote:

Patch updated.

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


[clang] [analyzer] Avoid a crash in a debug printout function (PR #79446)

2024-01-25 Thread via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/79446

Previously the function `RangeConstraintManager::printValue()` crashed when it 
encountered an empty rangeset (because `RangeSet::getBitwidth()` and 
`RangeSet::isUnsigned()` assert that the rangeset is not empty). This commit 
adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and during 
manual debugging), the impacts of this commit are very limited.

>From 2a1bb37fef538ecfde67f10c50df07100cc3b69a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Thu, 25 Jan 2024 14:13:03 +0100
Subject: [PATCH] [analyzer] Avoid a crash in a debug printout function

Previously the function `RangeConstraintManager::printValue()` crashed
when it encountered an empty rangeset (because `RangeSet::getBitwidth()`
and `RangeSet::isUnsigned()` assert that the rangeset is not empty).
This commit adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and
during manual debugging), the impacts of this commit are very limited.
---
 clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..cc1cad1e002cdf 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,8 +3270,12 @@ void RangeConstraintManager::printJson(raw_ostream &Out, 
ProgramStateRef State,
 void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef 
State,
 SymbolRef Sym) {
   const RangeSet RS = getRange(State, Sym);
-  Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
-  RS.dump(Out);
+  if (RS.isEmpty()) {
+Out << "";
+  } else {
+Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+RS.dump(Out);
+  }
 }
 
 static std::string toString(const SymbolRef &Sym) {

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


[clang] [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (PR #79109)

2024-01-25 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/79109

>From 014b10f43e2d3f8564940e21033cee77c3c0c10e Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic 
Date: Tue, 23 Jan 2024 03:25:01 -0500
Subject: [PATCH 1/2] [PowerPC] Diagnose invalid combination with Altivec, VSX
 and soft-float

---
 clang/lib/Basic/Targets/PPC.cpp  | 43 
 clang/test/CodeGen/PowerPC/attr-target-ppc.c |  3 ++
 clang/test/Driver/ppc-dependent-options.cpp  | 15 +++
 3 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b..1341bf8b99c506 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -442,19 +442,44 @@ void PPCTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   //   _CALL_DARWIN
 }
 
-// Handle explicit options being passed to the compiler here: if we've
-// explicitly turned off vsx and turned on any of:
-// - power8-vector
-// - direct-move
-// - float128
-// - power9-vector
-// - paired-vector-memops
-// - mma
-// - power10-vector
+// Handle explicit options being passed to the compiler here:
+// - if we've explicitly turned off vsx and turned on any of:
+//   - power8-vector
+//   - direct-move
+//   - float128
+//   - power9-vector
+//   - paired-vector-memops
+//   - mma
+//   - power10-vector
+// - if we've explicitly turned on vsx and turned off altivec.
+// - if we've explicitly turned on soft-float and altivec.
 // then go ahead and error since the customer has expressed an incompatible
 // set of options.
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
  const std::vector &FeaturesVec) {
+  // Cannot allow soft-float with Altivec.
+  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
+  llvm::is_contained(FeaturesVec, "+altivec")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
+   << "-maltivec";
+return false;
+  }
+
+  // Cannot allow soft-float with VSX.
+  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
+  llvm::is_contained(FeaturesVec, "+vsx")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
+   << "-mvsx";
+return false;
+  }
+
+  // Cannot allow VSX with no Altivec.
+  if (llvm::is_contained(FeaturesVec, "+vsx") &&
+  llvm::is_contained(FeaturesVec, "-altivec")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-mvsx"
+   << "-mno-altivec";
+return false;
+  }
 
   // vsx was not explicitly turned off.
   if (!llvm::is_contained(FeaturesVec, "-vsx"))
diff --git a/clang/test/CodeGen/PowerPC/attr-target-ppc.c 
b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
index d2901748b37cb9..f185a0e6f49a05 100644
--- a/clang/test/CodeGen/PowerPC/attr-target-ppc.c
+++ b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
@@ -1,4 +1,7 @@
 // RUN: not %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm %s -o -
 
 long __attribute__((target("power8-vector,no-vsx"))) foo (void) { return 0; }  
// expected-error {{option '-mpower8-vector' cannot be specified with 
'-mno-vsx'}}
+long __attribute__((target("no-altivec,vsx"))) foo2(void) { return 0; }
// expected-error {{option '-mvsx' cannot be specified with '-mno-altivec'}}
+long __attribute__((target("no-hard-float,altivec"))) foo3(void) { return 0; } 
// expected-error {{option '-msoft-float' cannot be specified with '-maltivec'}}
+long __attribute__((target("no-hard-float,vsx"))) foo3(void) { return 0; } // 
expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
 
diff --git a/clang/test/Driver/ppc-dependent-options.cpp 
b/clang/test/Driver/ppc-dependent-options.cpp
index 65c40e9ce70f65..8286422185cad6 100644
--- a/clang/test/Driver/ppc-dependent-options.cpp
+++ b/clang/test/Driver/ppc-dependent-options.cpp
@@ -78,6 +78,18 @@
 // RUN: -mcpu=power10 -std=c++11 -mno-vsx -mpower10-vector %s 2>&1 | \
 // RUN: FileCheck %s -check-prefix=CHECK-NVSX-P10V
 
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -mvsx -mno-altivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-NALTI-VSX
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -maltivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-ALTI
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -114,3 +126,6 @@ static_assert(false, "Neither enabled");
 // CHECK-NVSX-MMA: error: option '-mmma' cannot be specified with '-mno-vsx'
 // CHECK-NVSX: Neither enabled
 // CHECK-VSX: VSX enabled
+// CHECK-NALTI-VSX: error: option '-mvsx' cannot be sp

[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)

2024-01-25 Thread James Y Knight via cfe-commits

jyknight wrote:

Does this cause an ABI incompatibility? E.g. if we have a case where an 
existing object calls copyStruct on a given object (which presumably has its 
own internal mutex), and a newly compiled object file calls `__atomic_load` on 
the same object, implemented with its own internal mutex, the operations won't 
be atomic w.r.t. each-other.

I don't know enough about ObjC codegen stuff to be able to say if there are 
mitigating factors that make this OK (e.g. if it's all within one TU?).

Sidenote: please avoid rebase, amend, and force-pushing, because it makes it 
hard to review what's been changed -- instead, just keep adding more commits to 
your pull-request branch.


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


[clang] [AMDGPU][GFX12] Add tests for unsupported builtins (PR #78729)

2024-01-25 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd updated 
https://github.com/llvm/llvm-project/pull/78729

>From 56cf06f1b530d5ec62de1cc3818bf2f76dfd Mon Sep 17 00:00:00 2001
From: Mariusz Sikora 
Date: Fri, 19 Jan 2024 16:29:46 +0100
Subject: [PATCH] [AMDGPU][GFX12] Add tests for unsupported builtins

__builtin_amdgcn_mfma* and __builtin_amdgcn_smfmac*
---
 .../builtins-amdgcn-gfx12-err.cl  | 86 ++-
 1 file changed, 85 insertions(+), 1 deletion(-)

diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
index bcaea9a2482d186..f91fea17145102a 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
@@ -4,10 +4,94 @@
 
 typedef unsigned int uint;
 
-kernel void test_builtins_amdgcn_gws_insts(uint a, uint b) {
+#pragma OPENCL EXTENSION cl_khr_fp64:enable
+
+typedef float  v2f   __attribute__((ext_vector_type(2)));
+typedef float  v4f   __attribute__((ext_vector_type(4)));
+typedef float  v16f  __attribute__((ext_vector_type(16)));
+typedef float  v32f  __attribute__((ext_vector_type(32)));
+typedef half   v4h   __attribute__((ext_vector_type(4)));
+typedef half   v8h   __attribute__((ext_vector_type(8)));
+typedef half   v16h  __attribute__((ext_vector_type(16)));
+typedef half   v32h  __attribute__((ext_vector_type(32)));
+typedef intv2i   __attribute__((ext_vector_type(2)));
+typedef intv4i   __attribute__((ext_vector_type(4)));
+typedef intv16i  __attribute__((ext_vector_type(16)));
+typedef intv32i  __attribute__((ext_vector_type(32)));
+typedef short  v2s   __attribute__((ext_vector_type(2)));
+typedef short  v4s   __attribute__((ext_vector_type(4)));
+typedef short  v8s   __attribute__((ext_vector_type(8)));
+typedef short  v16s  __attribute__((ext_vector_type(16)));
+typedef short  v32s  __attribute__((ext_vector_type(32)));
+typedef double v4d   __attribute__((ext_vector_type(4)));
+
+void builtin_test_unsupported(double a_double, float a_float,
+  int a_int, long  a_long,
+  v4d a_v4d,
+  v2s a_v2s, v4s a_v4s, v8s a_v8s,
+  v2i a_v2i, v4i a_v4i, v16i a_v16i, v32i a_v32i,
+  v2f a_v2f, v4f a_v4f, v16f a_v16f, v32f  a_v32f,
+  v4h a_v4h, v8h a_v8h,
+
+  uint a, uint b) {
+
   __builtin_amdgcn_ds_gws_init(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_init' needs target feature gws}}
   __builtin_amdgcn_ds_gws_barrier(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_barrier' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_v(a); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_v' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_br(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_br' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_p(a); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_p' needs target feature gws}}
+
+  a_v32f = __builtin_amdgcn_mfma_f32_32x32x1f32(a_float, a_float, a_v32f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x1f32' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_16x16x1f32(a_float, a_float, a_v16f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x1f32' needs target 
feature mai-insts}}
+  a_v4f =  __builtin_amdgcn_mfma_f32_4x4x1f32(a_float, a_float, a_v4f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_4x4x1f32' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_32x32x2f32(a_float, a_float, a_v16f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x2f32' needs target 
feature mai-insts}}
+  a_v4f =  __builtin_amdgcn_mfma_f32_16x16x4f32(a_float, a_float, a_v4f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x4f32' needs target 
feature mai-insts}}
+  a_v32f = __builtin_amdgcn_mfma_f32_32x32x4f16(a_v4h, a_v4h, a_v32f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x4f16' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_16x16x4f16(a_v4h, a_v4h, a_v16f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x4f16' needs target 
feature mai-insts}}
+  a_v4f = __builtin_amdgcn_mfma_f32_4x4x4f16(a_v4h, a_v4h, a_v4f, 0, 0, 0); // 
expected-error {{'__builtin_amdgcn_mfma_f32_4x4x4f16' needs target feature 
mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_32x32x8f16(a_v4h, a_v4h, a_v16f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x8f16' needs target 
feature mai-insts}}
+  a_v4f = __builtin_amdgcn_mfma_f32_16x16x16f16(a_v4h, a_v4h, a_v4f, 0, 0, 0); 
// expected-error {{'__builtin_amdgcn_mfma_f32_16x16x16f16' needs target 
feature mai-insts}}
+  a_v32i = __builtin_amdgcn_mfma_i32_32x32x4i8(a_int, a_int, a_v32i, 0, 0, 0); 
// expected-error {{'__builtin_amdgcn_mfma_i32_32x32x4i8' needs 

[clang] cd0b005 - [clang][Interp][NFC] Add some working _Complex tests

2024-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-01-25T14:21:59+01:00
New Revision: cd0b0055a730e55f2f14f35172e05dc27642f8ce

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

LOG: [clang][Interp][NFC] Add some working _Complex tests

Added: 


Modified: 
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 99c0dd141d0b77..836ea552adac86 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -8,6 +8,11 @@ constexpr _Complex double z1 = {1.0, 2.0};
 static_assert(__real(z1) == 1.0, "");
 static_assert(__imag(z1) == 2.0, "");
 
+static_assert(&__imag z1 == &__real z1 + 1, "");
+static_assert((*(&__imag z1)) == __imag z1, "");
+static_assert((*(&__real z1)) == __real z1, "");
+
+
 constexpr double setter() {
   _Complex float d = {1.0, 2.0};
 



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


[libc] [flang] [libunwind] [libcxx] [clang-tools-extra] [compiler-rt] [lldb] [clang] [llvm] [mlir] [lld] Reland: [libc++][format] P2637R3: Member visit (std::basic_format_arg) #76449 (PR #79032)

2024-01-25 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/79032

>From e03452fda84a5284420bba1913299b68caabb6cd Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Mon, 22 Jan 2024 20:35:00 +0200
Subject: [PATCH 1/2] Revert "Revert "[libc++][format] P2637R3: Member `visit`
 (`std::basic_format_arg`) (#76449)""

This reverts commit 02f95b77515fe18ed1076b94cbb850ea0cf3c77e.
---
 libcxx/docs/ReleaseNotes/18.rst   |   1 +
 libcxx/docs/Status/Cxx2cPapers.csv|   2 +-
 libcxx/docs/Status/FormatIssues.csv   |   2 +-
 libcxx/include/__config   |   6 +
 libcxx/include/__format/format_arg.h  | 109 +-
 libcxx/include/__format/format_context.h  |  33 +-
 libcxx/include/format |   2 +-
 .../format.arg/visit.pass.cpp | 333 
 .../format.arg/visit.return_type.pass.cpp | 369 ++
 .../visit_format_arg.deprecated.verify.cpp|  38 ++
 .../format.arg/visit_format_arg.pass.cpp  |   6 +-
 .../format.arguments/format.args/get.pass.cpp |  48 ++-
 libcxx/test/support/test_basic_format_arg.h   |  20 +-
 libcxx/test/support/test_macros.h |   5 +
 .../generate_feature_test_macro_components.py |   1 +
 15 files changed, 927 insertions(+), 48 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fd882bafe19a51..237a63022d55ff 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -79,6 +79,7 @@ Implemented Papers
 - P1759R6 - Native handles and file streams
 - P2868R3 - Remove Deprecated ``std::allocator`` Typedef From C++26
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P2637R3 - Member ``visit``
 - P2447R6 - ``span`` over initializer list
 
 
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index f80b1f6b663f04..c45aa3c510072e 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -17,7 +17,7 @@
 "`P0792R14 `__","LWG","``function_ref``: a 
type-erased callable reference","Varna June 2023","","",""
 "`P2874R2 `__","LWG","Mandating Annex D Require No 
More","Varna June 2023","","",""
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
-"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","|Partial|","18.0",""
+"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","|Complete|","18.0",""
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
 "`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
diff --git a/libcxx/docs/Status/FormatIssues.csv 
b/libcxx/docs/Status/FormatIssues.csv
index 513988d08036ca..6e58e752191ea5 100644
--- a/libcxx/docs/Status/FormatIssues.csv
+++ b/libcxx/docs/Status/FormatIssues.csv
@@ -16,7 +16,7 @@ Number,Name,Standard,Assignee,Status,First released version
 "`P2693R1 `__","Formatting ``thread::id`` and 
``stacktrace``","C++23","Mark de Wever","|In Progress|"
 "`P2510R3 `__","Formatting pointers","C++26","Mark 
de Wever","|Complete|",17.0
 "`P2757R3 `__","Type-checking format 
args","C++26","","",
-"`P2637R3 `__","Member ``visit``","C++26","","",
+"`P2637R3 `__","Member ``visit``","C++26","Hristo 
Hristov","|Complete|",18.0
 "`P2905R2 `__","Runtime format strings","C++26 
DR","Mark de Wever","|Complete|",18.0
 "`P2918R2 `__","Runtime format strings 
II","C++26","Mark de Wever","|Complete|",18.0
 "`P2909R4 `__","Fix formatting of code units as 
integers (Dude, where’s my ``char``?)","C++26 DR","Mark de 
Wever","|Complete|",18.0
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 9a64cdb489119d..00489d971c296c 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -995,6 +995,12 @@ typedef __char32_t char32_t;
 #define _LIBCPP_DEPRECATED_IN_CXX23
 #  endif
 
+#  if _LIBCPP_STD_VER >= 26
+#define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
+#  else
+#define _LIBCPP_DEPRECATED_IN_CXX26
+#  endif
+
 #  if !defined(_LIBCPP_HAS_NO_C

[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-25 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat approved this pull request.

Thanks, LGTM~

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


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From d4ca5c2fcb87f424be23efc4513df491403c3811 Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 1/7] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a..46fa9eece3747a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 52de421b998481105e5522a04ad9e39a4a6cbb82

[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-25 Thread Brandon Wu via cfe-commits


@@ -380,14 +380,14 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 OverloadedName += "_" + OverloadedSuffixStr.str();
 
   // clang built-in function name, e.g. __builtin_rvv_vadd.
-  std::string BuiltinName = "__builtin_rvv_" + std::string(Record.Name);
+  std::string BuiltinName = std::string(Record.Name);
 
   RVVIntrinsic::updateNamesAndPolicy(IsMasked, HasPolicy, Name, BuiltinName,
  OverloadedName, PolicyAttrs,
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  uint32_t Index = IntrinsicList.size();
+  uint16_t Index = IntrinsicList.size();

4vtomat wrote:

I've added an assertion for checking whether intrinsics overflow.

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-25 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/77487

>From 84ea759c43d8e9cb450d95d00fd802be622153a2 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Sun, 7 Jan 2024 18:10:59 -0800
Subject: [PATCH 1/2] [RISCV][clang] Optimize memory usage of intrinsic lookup
 table

This patch optimize:
  1. Reduce string size of RVVIntrinsicDef.
  2. Reduce the type size of the index of intrinsics.

I use valgrind --tool=massif to analyze a simple program:
```
#include 
vint32m1_t test(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}
```
and before optimization, the peak memory usage is 15.68MB,
after optimization, the peak memory usage is 13.69MB.
---
 clang/include/clang/Support/RISCVVIntrinsicUtils.h |  6 --
 clang/lib/Sema/SemaRISCVVectorLookup.cpp   | 13 +++--
 clang/lib/Support/RISCVVIntrinsicUtils.cpp |  5 -
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index c525d3443331e0b..7e20f022c28b551 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }
+  llvm::StringRef getOverloadedName() const {
+return "__riscv_" + OverloadedName;
+  }
   bool hasMaskedOffOperand() const { return HasMaskedOffOperand; }
   bool hasVL() const { return HasVL; }
   bool hasPolicy() const { return Scheme != PolicyScheme::SchemeNone; }
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 3ed3e6195441893..e9523871e9cd1fb 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector Indexes;
+  SmallVector Indexes;
 };
 
 } // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap Intrinsics;
+  StringMap Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap OverloadIntrinsics;
 
@@ -380,14 +380,14 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 OverloadedName += "_" + OverloadedSuffixStr.str();
 
   // clang built-in function name, e.g. __builtin_rvv_vadd.
-  std::string BuiltinName = "__builtin_rvv_" + std::string(Record.Name);
+  std::string BuiltinName = std::string(Record.Name);
 
   RVVIntrinsic::updateNamesAndPolicy(IsMasked, HasPolicy, Name, BuiltinName,
  OverloadedName, PolicyAttrs,
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  uint32_t Index = IntrinsicList.size();
+  uint16_t Index = IntrinsicList.size();
   IntrinsicList.push_back({BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.
@@ -452,7 +452,8 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 RVVIntrinsicDecl->addAttr(OverloadableAttr::CreateImplicit(Context));
 
   // Setup alias to __builtin_rvv_*
-  IdentifierInfo &IntrinsicII = PP.getIdentifierTable().get(IDef.BuiltinName);
+  IdentifierInfo &IntrinsicII =
+  PP.getIdentifierTable().get("__builtin_rvv_" + IDef.BuiltinName);
   RVVIntrinsicDecl->addAttr(
   BuiltinAliasAttr::CreateImplicit(S.Context, &IntrinsicII));
 
@@ -463,7 +464,7 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 bool RISCVIntrinsicManagerImpl::CreateIntrinsicIfFound(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP) {
-  StringRef Name = II->getName();
+  StringRef Name = II->getName().substr(8);
 
   // Lookup the function name from the overload intrinsics first.
   auto OvIItr = OverloadIntrinsics.find(Name);
diff --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp 
b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index 2de977a3dc720bd..7d2a2d7e826f9cd 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1150,11 +1150,6 @@ void RVVIntrinsic::updateNamesAndPolicy(
 OverloadedName += suffix;
   };
 
-  // This follows the naming guideline under riscv-c-api-doc to add the
-  // `__riscv_` suffix for all RVV intrinsics.
-  Name = "__riscv_" + Name;
-  OverloadedName = 

[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread via cfe-commits

NagyDonat wrote:

Yes, the "common big set of arguments" is an annoying problem. Perhaps you 
could consider my solution in core.BitwiseShift where I introduced a 
"validator" class that holds all the common arguments as data members, so 
instead of helper functions you have helper methods that can all access the 
common arguments. (The checker callback constructs a validator, and calls its 
"main" method, which will call the others as needed)

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


[clang] f4ed7f8 - [clang][Parse][NFC] Make a local variable const

2024-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-01-25T13:29:39+01:00
New Revision: f4ed7f8d0a3830d05e53476fc64966e871bf9454

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

LOG: [clang][Parse][NFC] Make a local variable const

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index ea79917cfc8e9e1..82fe12170f6660a 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2362,7 +2362,7 @@ void Parser::HandleMemberFunctionDeclDelays(Declarator 
&DeclaratorInfo,
   if (!NeedLateParse) {
 // Look ahead to see if there are any default args
 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx) {
-  auto Param = cast(FTI.Params[ParamIdx].Param);
+  const auto *Param = cast(FTI.Params[ParamIdx].Param);
   if (Param->hasUnparsedDefaultArg()) {
 NeedLateParse = true;
 break;



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


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits


@@ -431,6 +442,17 @@ namespace deduction_after_explicit_pack {
 i(0, 1, 2, 3, 4, 5); // expected-error {{no match}}
   }
 
+  template 
+  void bar(args_tag, type_identity_t..., int mid, 
type_identity_t...) {}

spaits wrote:

It could work. It would cost only condition being removed. I deliberately put 
in the condition that disables this. Should I enable it?

I think enabling it would be standard compliant, but I played it safe and stuck 
to the example seen in the issue.  

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


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread Balázs Kéri via cfe-commits

balazske wrote:

My concern was the addition of many small functions that are used only from few 
other `eval*` calls and are relatively special. And all of these need a common 
big set of arguments like `StreamSym`, `CE`, `Call`. The build of states for 
success and failure cases in the thing that is really special for the calls.
But I can make another solution with "helper" functions.

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


[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits

mrexodia wrote:

> I haven't checked closely yet, but it seems like you need to add tests.

Could you provide some guidance on what kind of tests to add and how to 
actually run them locally? First I wanted to get the builtkite job to be green, 
but it seems to be failing on some unrelated test where LLD cannot be found.

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


[llvm] [flang] [libc] [libcxx] [clang] [mlir] [clang-tools-extra] [openmp] [libcxxabi] [compiler-rt] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -21471,6 +21471,53 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG &DAG,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  Value.getOpcode() != ISD::TRUNCATE ||
+  ValueVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3))
+return SDValue();
+
+  assert(ST->getOffset().isUndef() && "undef offset expected");
+  SDLoc DL(ST);
+  auto WideVT = EVT::getVectorVT(
+  *DAG.getContext(),
+  Value->getOperand(0).getValueType().getVectorElementType(), 4);
+  SDValue UndefVector = DAG.getUNDEF(WideVT);
+  SDValue WideTrunc = DAG.getNode(
+  ISD::INSERT_SUBVECTOR, DL, WideVT,
+  {UndefVector, Value->getOperand(0), DAG.getVectorIdxConstant(0, DL)});
+  SDValue Cast = DAG.getNode(
+  ISD::BITCAST, DL, WideVT.getSizeInBits() == 64 ? MVT::v8i8 : MVT::v16i8,
+  WideTrunc);
+
+  MachineFunction &MF = DAG.getMachineFunction();
+  SDValue Chain = ST->getChain();
+  MachineMemOperand *MMO = ST->getMemOperand();
+  unsigned IdxScale = WideVT.getScalarSizeInBits() / 8;
+  SDValue E2 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(2 * IdxScale, DL, MVT::i64));
+  TypeSize Offset2 = TypeSize::getFixed(2);
+  SDValue Ptr2 = DAG.getMemBasePlusOffset(ST->getBasePtr(), Offset2, DL);
+  Chain = DAG.getStore(Chain, DL, E2, Ptr2, MF.getMachineMemOperand(MMO, 2, 
1));
+
+  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(1 * IdxScale, DL, MVT::i64));
+  TypeSize Offset1 = TypeSize::getFixed(1);
+  SDValue Ptr1 = DAG.getMemBasePlusOffset(ST->getBasePtr(), Offset1, DL);
+  Chain = DAG.getStore(Chain, DL, E1, Ptr1, MF.getMachineMemOperand(MMO, 1, 
1));
+
+  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(0, DL, MVT::i64));
+  Chain = DAG.getStore(Chain, DL, E0, ST->getBasePtr(), ST->getMemOperand());

fhahn wrote:

Updated, thanks!

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


[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits


@@ -40,6 +41,7 @@ using namespace llvm;
 namespace lld::wasm {
 static std::unique_ptr createLTO() {
   lto::Config c;
+  c.EmbedCmdArgs = commonContext().cmdArgs;

mrexodia wrote:

I changed all the `commonContext()` to `context()` (or the `ctx` variable 
directly where possible). Feel free to reopen the discussion if you think it 
needs another revision.

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


[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits

https://github.com/mrexodia updated 
https://github.com/llvm/llvm-project/pull/79390

>From 67280cb8a77931271e685f7c92718d45cfea69a8 Mon Sep 17 00:00:00 2001
From: Duncan Ogilvie 
Date: Thu, 25 Jan 2024 00:08:49 +0100
Subject: [PATCH] Embed the command line arguments during LTO

---
 clang/lib/CodeGen/BackendUtil.cpp|  3 +-
 lld/COFF/Driver.cpp  |  1 +
 lld/COFF/LTO.cpp |  3 +-
 lld/Common/CommonLinkerContext.cpp   |  9 ++
 lld/ELF/Driver.cpp   |  1 +
 lld/ELF/LTO.cpp  |  3 +-
 lld/MachO/Driver.cpp |  1 +
 lld/MachO/LTO.cpp|  3 +-
 lld/MinGW/Driver.cpp |  1 +
 lld/include/lld/Common/CommonLinkerContext.h |  3 ++
 lld/wasm/Driver.cpp  |  1 +
 lld/wasm/LTO.cpp |  2 ++
 llvm/include/llvm/LTO/Config.h   |  2 +-
 llvm/include/llvm/LTO/LTOBackend.h   |  6 ++--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp| 14 ++
 llvm/lib/LTO/LTO.cpp |  3 +-
 llvm/lib/LTO/LTOBackend.cpp  | 29 ++--
 llvm/lib/LTO/LTOCodeGenerator.cpp|  3 +-
 18 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc173..71aee18e63574e8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1208,6 +1208,7 @@ static void runThinLTOBackend(
   Conf.CPU = TOpts.CPU;
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
+  Conf.EmbedCmdArgs = CGOpts.CmdArgs;
   Conf.RelocModel = CGOpts.RelocationModel;
   std::optional OptLevelOrNone =
   CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
@@ -1269,7 +1270,7 @@ static void runThinLTOBackend(
   if (Error E =
   thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
   ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  /* ModuleMap */ nullptr)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index e0afb6b18805b2e..941e6851c1bd4c5 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1447,6 +1447,7 @@ void LinkerDriver::linkerMain(ArrayRef 
argsArr) {
   // Parse command line options.
   ArgParser parser(ctx);
   opt::InputArgList args = parser.parse(argsArr);
+  ctx.storeCmdArgs(args);
 
   // Initialize time trace profiler.
   config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq);
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 7df931911213672..26f5d42e847def9 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -52,8 +52,7 @@ lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : ctx.config.mllvmOpts)
-c.MllvmArgs.emplace_back(C.str());
+  c.EmbedCmdArgs = context().cmdArgs;
 
   // Always emit a section per function/datum with LTO. LLVM LTO should get 
most
   // of the benefit of linker GC, but there are still opportunities for ICF.
diff --git a/lld/Common/CommonLinkerContext.cpp 
b/lld/Common/CommonLinkerContext.cpp
index 12f56bc10ec9631..57aae8fd0a703d8 100644
--- a/lld/Common/CommonLinkerContext.cpp
+++ b/lld/Common/CommonLinkerContext.cpp
@@ -37,6 +37,15 @@ CommonLinkerContext::~CommonLinkerContext() {
   lctx = nullptr;
 }
 
+void CommonLinkerContext::storeCmdArgs(const llvm::opt::ArgList &args) {
+  cmdArgs.clear();
+  for (const llvm::opt::Arg *arg : args) {
+StringRef str(args.getArgString(arg->getIndex()));
+cmdArgs.insert(cmdArgs.end(), str.begin(), str.end());
+cmdArgs.push_back('\0');
+  }
+}
+
 CommonLinkerContext &lld::commonContext() {
   assert(lctx);
   return *lctx;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index f4b7d1c9d5b9736..e760247f5ad9b0c 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -573,6 +573,7 @@ constexpr const char *saveTempsValues[] = {
 void LinkerDriver::linkerMain(ArrayRef argsArr) {
   ELFOptTable parser;
   opt::InputArgList args = parser.parse(argsArr.slice(1));
+  context().storeCmdArgs(args);
 
   // Interpret these flags early because error()/warn() depend on them.
   errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index c39c6e6ea74ba33..02882865727be89 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -54,8 +54,7 @@ static lto::Config createConfig() {
   // LLD supports the new relocations and address-significance tables.
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : 

[llvm] [flang] [libc] [libcxx] [clang] [mlir] [clang-tools-extra] [openmp] [libcxxabi] [compiler-rt] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78637

>From efd07e93aed51049ad3783c701284617ae446330 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 17 Jan 2024 11:11:59 +
Subject: [PATCH 1/7] [AArch64] Combine store (trunc X to <3 x i8>) to sequence
 of ST1.b.

Improve codegen for (trunc X to <3 x i8>) by converting it to a sequence
of 3 ST1.b, but first converting the truncate operand to either v8i8 or
v16i8, extracting the lanes for the truncate results and storing them.

At the moment, there are almost no cases in which such vector operations
will be generated automatically. The motivating case is non-power-of-2
SLP vectorization: https://github.com/llvm/llvm-project/pull/77790
---
 .../Target/AArch64/AArch64ISelLowering.cpp| 50 +++
 .../AArch64/vec3-loads-ext-trunc-stores.ll| 33 +---
 2 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 8a6f1dc7487bae..4be78f61fe7b65 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -21318,6 +21318,53 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG &DAG,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  ST->getOriginalAlign() >= 4 || Value.getOpcode() != ISD::TRUNCATE ||
+  ValueVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3))
+return SDValue();
+
+  SDLoc DL(ST);
+  auto WideVT = EVT::getVectorVT(
+  *DAG.getContext(),
+  Value->getOperand(0).getValueType().getVectorElementType(), 4);
+  SDValue UndefVector = DAG.getUNDEF(WideVT);
+  SDValue WideTrunc = DAG.getNode(
+  ISD::INSERT_SUBVECTOR, DL, WideVT,
+  {UndefVector, Value->getOperand(0), DAG.getVectorIdxConstant(0, DL)});
+  SDValue Cast = DAG.getNode(
+  ISD::BITCAST, DL, WideVT.getSizeInBits() == 64 ? MVT::v8i8 : MVT::v16i8,
+  WideTrunc);
+
+  SDValue Chain = ST->getChain();
+  SDValue E2 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(8, DL, MVT::i64));
+
+  SDValue Ptr2 =
+  DAG.getMemBasePlusOffset(ST->getBasePtr(), TypeSize::getFixed(2), DL);
+  Chain = DAG.getStore(Chain, DL, E2, Ptr2, ST->getPointerInfo(),
+   ST->getOriginalAlign());
+
+  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(4, DL, MVT::i64));
+
+  SDValue Ptr1 =
+  DAG.getMemBasePlusOffset(ST->getBasePtr(), TypeSize::getFixed(1), DL);
+  Chain = DAG.getStore(Chain, DL, E1, Ptr1, ST->getPointerInfo(),
+   ST->getOriginalAlign());
+  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(0, DL, MVT::i64));
+  Chain = DAG.getStore(Chain, DL, E0, ST->getBasePtr(), ST->getPointerInfo(),
+   ST->getOriginalAlign());
+
+  return Chain;
+}
+
 static SDValue performSTORECombine(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI,
SelectionDAG &DAG,
@@ -21333,6 +21380,9 @@ static SDValue performSTORECombine(SDNode *N,
 return EltVT == MVT::f32 || EltVT == MVT::f64;
   };
 
+  if (SDValue Res = combineI8TruncStore(ST, DAG, Subtarget))
+return Res;
+
   // If this is an FP_ROUND followed by a store, fold this into a truncating
   // store. We can do this even if this is already a truncstore.
   // We purposefully don't care about legality of the nodes here as we know
diff --git a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll 
b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
index 9eeb194409df6f..60639ea91fbaa1 100644
--- a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
+++ b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
@@ -154,17 +154,12 @@ define <3 x i32> @load_v3i32(ptr %src) {
 define void @store_trunc_from_64bits(ptr %src, ptr %dst) {
 ; CHECK-LABEL: store_trunc_from_64bits:
 ; CHECK:   ; %bb.0: ; %entry
-; CHECK-NEXT:sub sp, sp, #16
-; CHECK-NEXT:.cfi_def_cfa_offset 16
-; CHECK-NEXT:ldr s0, [x0]
-; CHECK-NEXT:ldrh w8, [x0, #4]
-; CHECK-NEXT:mov.h v0[2], w8
-; CHECK-NEXT:xtn.8b v0, v0
-; CHECK-NEXT:str s0, [sp, #12]
-; CHECK-NEXT:ldrh w9, [sp, #12]
-; CHECK-NEXT:strb w8, [x1, #2]
-; CHECK-NEXT:strh w9, [x1]
-; CHECK-NEXT:add sp, sp, #16
+; CHECK-NEXT:add x8, x0, #4
+; CHECK-NEXT:ld1r.4h { v0 }, [x8]
+; CHECK-NEXT:ldr w8, [x0]
+; CHECK-NEXT:strb w8, [x1]
+; CHECK-NEX

[clang] [Coverage] Map regions from system headers (PR #76950)

2024-01-25 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

Seems this causes the crash with `-fcoverage-mcdc -mllvm 
-system-headers-coverage`. Investigating.
See also #78920.

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


[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread via cfe-commits


@@ -860,7 +841,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
 }
 if (Feature == "+dit")
   HasDIT = true;
-if (Feature == "+cccp")
+if (Feature == "+ccpp")

ostannard wrote:

Again, does this need a test?

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


[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread via cfe-commits


@@ -741,7 +722,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
 
 if (Feature == "+neon" || Feature == "+fp-armv8")
   FPU |= NeonMode;
-if (Feature == "+jscvt") {
+if (Feature == "+jsconv") {

ostannard wrote:

This looks like bug fix which would make a functional difference, does it need 
a test?

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


[libcxx] [lld] [lldb] [flang] [compiler-rt] [llvm] [libcxxabi] [libclc] [clang] [libc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -498,10 +498,34 @@ static VPValue *createScalarIVSteps(VPlan &Plan, const 
InductionDescriptor &ID,
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
   Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;

fhahn wrote:

Updated, thanks! This works well now with the refactoring in this patch. IVTy 
removed.

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


[libclc] [libcxx] [libcxxabi] [llvm] [clang-tools-extra] [flang] [libc] [compiler-rt] [lldb] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -1469,6 +1461,52 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+static bool isUniformAcrossVFsAndUFs(VPScalarCastRecipe *C) {
+  return C->isDefinedOutsideVectorRegions() ||
+ isa(C->getOperand(0)) ||
+ isa(C->getOperand(0));
+}
+
+Value *VPScalarCastRecipe ::generate(VPTransformState &State, unsigned Part) {
+  assert(vputils::onlyFirstLaneUsed(this) &&
+ "Codegen only implemented for first lane.");
+  switch (Opcode) {
+  case Instruction::SExt:
+  case Instruction::ZExt:

fhahn wrote:

Yep, could remove if preferred, but `State.Builder.CreateCast` generically 
supports any cast

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


[llvm] [flang] [libc] [lld] [libclc] [libcxx] [lldb] [clang] [clang-tools-extra] [libcxxabi] [compiler-rt] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn commented:

Comments should be addressed and title & description updated, thanks!

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


[compiler-rt] [lldb] [flang] [libc] [libcxxabi] [llvm] [lld] [libcxx] [clang] [libclc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {

fhahn wrote:

VPDerivedIVRecipe getScalarType would be good to remove, will do as follow-up.

`VPWidenIntOrFpInductionRecipe's` trunc drives truncating the start value and 
step, effectively creating a narrow phi. I'll check to see if this can also be 
modeled with the new recipe.

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


[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

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


[libc] [compiler-rt] [libclc] [lldb] [clang-tools-extra] [flang] [libcxx] [libcxxabi] [llvm] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -1469,6 +1461,52 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+static bool isUniformAcrossVFsAndUFs(VPScalarCastRecipe *C) {

fhahn wrote:

Added comment + TODO, thanks!

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


[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 1/6] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415e..d5985224488 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a5..d71b07039944500 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e2..423504e8f7e05e7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransform

[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

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


[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread Alexey Bataev via cfe-commits


@@ -19520,6 +19520,13 @@ static bool actOnOMPReductionKindClause(
   bool FirstIter = true;
   for (Expr *RefExpr : VarList) {
 assert(RefExpr && "nullptr expr in OpenMP reduction clause.");
+if (ClauseKind == OMPC_reduction &&
+RD.RedModifier == OMPC_REDUCTION_inscan && RefExpr->isTypeDependent()) 
{
+  S.Diag(RefExpr->getExprLoc(),
+ diag::err_omp_inscan_reduction_on_template_type);
+  continue;
+}
+

alexey-bataev wrote:

This is definetely wrong, templates should be supported

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


[libc] [compiler-rt] [libclc] [lldb] [clang-tools-extra] [flang] [libcxx] [libcxxabi] [llvm] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

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


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread Balazs Benics via cfe-commits

steakhal wrote:

> I'm seconding the suggestions of @steakhal, and in particular I agree with
> 
> > I'd also advise against using more callables bundled with CallDescriptions. 
> > They make debugging code more difficult, as the control-flow would become 
> > also data-dependent. I'd suggest other ways to generalize.
> 
> Instead of creating this shared framework that calls different callbacks 
> depending on the checked function, consider keeping separate top-level 
> evaluator functions that rely on a shared set of smaller tool-like helper 
> functions.

One more not about composability.
In general, `addTransition` calls don't compose, thus limits reusability.
For example, `preReadWrite` should be reusable from other precondition 
handlers, such that the new one can just call `preReadWrite` and then do some 
other more specialized checks. However, once a handler calls `addTransition` we 
are done. We no longer can simply wrap it, aka. compose with other 
functionalities.
Consequently, I'd suggest to have some common pattern, such as return state 
pointers, or NULL if an error was reported. And leave the `addTransition` to 
the caller - if they chose to call it.

`eval*` handlers are more difficult to compose, given that they also need to 
bind the return value and apply their sideffects, but I believe we could 
achieve similar objectives there too (thus, have refined, composable handlers, 
combined in useful ways).

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


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread via cfe-commits

NagyDonat wrote:

I'm seconding the suggestions of @steakhal, and in particular I agree with
> I'd also advise against using more callables bundled with CallDescriptions. 
> They make debugging code more difficult, as the control-flow would become 
> also data-dependent. I'd suggest other ways to generalize.

Instead of creating this shared framework that calls different callbacks 
depending on the checked function, consider keeping separate top-level 
evaluator functions that rely on a shared set of smaller tool-like helper 
functions.

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


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From d4ca5c2fcb87f424be23efc4513df491403c3811 Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 1/6] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a0..46fa9eece3747a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 52de421b998481105e5522a04ad9e39a4a6cbb

[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread Saiyedul Islam via cfe-commits


@@ -12,28 +12,6 @@
 
 void foo() {}
 
-template 

saiislam wrote:

How was this test case working till now when templates were not supported in 
scan?

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


[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-25 Thread via cfe-commits

martinboehme wrote:

> > You mean the publicness of `getResultObjectLocation()`?
> 
> Yeah, I was wondering if it would be more user friendly if something like 
> `State.Env.get(Expr);` would automatically recognize 
> that the user actually wants the result location and returned that without 
> the user having to consider this special case explicitly.

Thanks, I understand now.

I see the attraction, but I think it would dilute the semantics of 
`get>`. Currently, this method may only be called 
on glvalues, and that makes it very clear what it will return -- as a glvalue 
_is a_ storage location.

Extending `get>` to do what 
`getResultObjectLocation()` does today means that it would become permissible 
to call this method on prvalues (of record type), and the semantics of what 
this operation does would be quite different from what it does on glvalues, and 
more involved -- because it would now be returning the storage location of a 
_different_ AST node (the result object), and connecting the AST node for the 
result object to the prvalue is not entirely trivial.

I think it would therefore be better to make this difference in semantics clear 
by separating out the "get the result object location for a record prvalue" 
operation into a separate method.

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-25 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 2a0b02a285203228944d5dd206f968e776757993 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Frontend/TextDiagnostic.h |  18 +-
 clang/include/clang/Lex/Preprocessor.h|  10 +
 clang/lib/Frontend/TextDiagnostic.cpp | 211 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   2 +-
 clang/lib/Lex/Preprocessor.cpp|  24 ++
 clang/test/Frontend/diagnostic-pipe.c |   9 +
 7 files changed, 262 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/Frontend/diagnostic-pipe.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..6f5fe2049e242fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -97,6 +97,8 @@ Attribute Changes in Clang
 
 Improvements to Clang's diagnostics
 ---
+- Clang now applies syntax highlighting to the code snippets it
+  prints.
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..a2fe8ae995423b9 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
@@ -33,14 +34,22 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  const Preprocessor *PP;
 
 public:
-  TextDiagnostic(raw_ostream &OS,
- const LangOptions &LangOpts,
- DiagnosticOptions *DiagOpts);
+  TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+ DiagnosticOptions *DiagOpts, const Preprocessor *PP = 
nullptr);
 
   ~TextDiagnostic() override;
 
+  struct StyleRange {
+unsigned Start;
+unsigned End;
+enum llvm::raw_ostream::Colors Color;
+StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
+: Start(S), End(E), Color(C){};
+  };
+
   /// Print the diagonstic level to a raw_ostream.
   ///
   /// This is a static helper that handles colorizing the level and formatting
@@ -104,7 +113,8 @@ class TextDiagnostic : public DiagnosticRenderer {
ArrayRef Hints);
 
   void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
-   unsigned LineNo);
+   unsigned LineNo, unsigned DisplayLineNo,
+   ArrayRef Styles);
 
   void emitParseableFixits(ArrayRef Hints, const SourceManager &SM);
 };
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 2d9c53cdf5bde8e..9d0d53129a12dd9 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -284,6 +284,13 @@ class Preprocessor {
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
 
+  /// Returns a pointer into the given file's buffer that's guaranteed
+  /// to be between tokens. The returned pointer is always before \p Start.
+  /// The maximum distance betweenthe returned pointer and \p Start is
+  /// limited by a constant value, but also an implementation detail.
+  /// If no such check point exists, \c nullptr is returned.
+  const char *getCheckPoint(FileID FID, const char *Start) const;
+
 private:
   /// The code-completion handler.
   CodeCompletionHandler *CodeComplete = nullptr;
@@ -311,6 +318,9 @@ class Preprocessor {
   /// The import path for named module that we're currently processing.
   SmallVector, 2> 
NamedModuleImportPath;
 
+  llvm::DenseMap> CheckPoints;
+  unsigned CheckPointCounter = 0;
+
   /// Whether the import is an `@import` or a standard c++ modules import.
   bool IsAtImport = false;
 
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 779dead5d058d1a..291d71f6db61f17 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -41,6 +42,14 @@ static const enum raw_ostream::Colors fatalColor = 
raw_ostream::RED;
 static const enum raw_ostream::Colors savedColor =
   raw_ostream::SAVEDCOLOR;
 
+// Magenta is taken for 'warning'. Red is already 'error' and 'c

[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -389,10 +390,29 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =

tbaederr wrote:

```suggestion
if (const auto *OVE =
```

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


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)

tbaederr wrote:

This and the next one are irrelevant whitespace changes.

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


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -389,10 +390,29 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =
+llvm::dyn_cast_if_present(Local.Desc->asExpr())) {
+  if (auto it = this->Ctx->OpaqueExprs.find(OVE);

tbaederr wrote:

```suggestion
  if (auto It = this->Ctx->OpaqueExprs.find(OVE);
```

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


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

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


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits


@@ -44,7 +47,9 @@ class BugSuppression {
   using CachedRanges =
   llvm::SmallVector;
 
-  llvm::DenseMap CachedSuppressionLocations;
+  llvm::DenseMap CachedSuppressionLocations{};
+
+  ASTContext &ACtx;

steakhal wrote:

```suggestion
  llvm::DenseMap CachedSuppressionLocations;

  const ASTContext &ACtx;
```

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


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits


@@ -27,6 +28,8 @@ class PathDiagnosticLocation;
 
 class BugSuppression {
 public:
+  BugSuppression(ASTContext &ACtx) : ACtx(ACtx) {}

steakhal wrote:

```suggestion
  explicit BugSuppression(const ASTContext &ACtx) : ACtx(ACtx) {}
```

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


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

I only have minor nits. No objections.

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


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits


@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// perviously we substitute the pack here in a similar fashion as seen
+// above with the trailing parameter packs. The main difference here is
+// that, in this case we are not processing all of the remaining
+// arguments. We are only process as many arguments as much we have in
+// the already deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;

spaits wrote:

I think it could be. In that case that every template packs that are needed by 
the dependent name are all expanded. For example this could happen when we use 
explicitly specified template arguments.

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


<    1   2   3   4   5   6   >