[Lldb-commits] [clang] [libcxxabi] [flang] [clang-tools-extra] [compiler-rt] [mlir] [lldb] [llvm] [mlir][complex] Prevent underflow in complex.abs (PR #76316)

2024-01-25 Thread Kai Sasaki via lldb-commits

https://github.com/Lewuathe updated 
https://github.com/llvm/llvm-project/pull/76316

>From a5810363e546da073543cb2d62cceb956c46b2e6 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Fri, 15 Dec 2023 15:53:54 +0900
Subject: [PATCH 1/2] [mlir][complex] Prevent underflow in complex.abs

---
 .../ComplexToStandard/ComplexToStandard.cpp   |  56 ++---
 .../convert-to-standard.mlir  | 115 ++
 .../ComplexToStandard/full-conversion.mlir|  25 +++-
 .../Dialect/Complex/CPU/correctness.mlir  |  38 ++
 4 files changed, 194 insertions(+), 40 deletions(-)

diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp 
b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index bf753c7062f366..7c1db57b55f996 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -26,29 +26,57 @@ namespace mlir {
 using namespace mlir;
 
 namespace {
+// The algorithm is listed in https://dl.acm.org/doi/pdf/10.1145/363717.363780.
 struct AbsOpConversion : public OpConversionPattern {
   using OpConversionPattern::OpConversionPattern;
 
   LogicalResult
   matchAndRewrite(complex::AbsOp op, OpAdaptor adaptor,
   ConversionPatternRewriter &rewriter) const override {
-auto loc = op.getLoc();
-auto type = op.getType();
+mlir::ImplicitLocOpBuilder b(op.getLoc(), rewriter);
 
 arith::FastMathFlagsAttr fmf = op.getFastMathFlagsAttr();
 
-Value real =
-rewriter.create(loc, type, adaptor.getComplex());
-Value imag =
-rewriter.create(loc, type, adaptor.getComplex());
-Value realSqr =
-rewriter.create(loc, real, real, fmf.getValue());
-Value imagSqr =
-rewriter.create(loc, imag, imag, fmf.getValue());
-Value sqNorm =
-rewriter.create(loc, realSqr, imagSqr, fmf.getValue());
-
-rewriter.replaceOpWithNewOp(op, sqNorm);
+Type elementType = op.getType();
+Value arg = adaptor.getComplex();
+
+Value zero =
+b.create(elementType, b.getZeroAttr(elementType));
+Value one = b.create(elementType,
+b.getFloatAttr(elementType, 1.0));
+
+Value real = b.create(elementType, arg);
+Value imag = b.create(elementType, arg);
+
+Value realIsZero =
+b.create(arith::CmpFPredicate::OEQ, real, zero);
+Value imagIsZero =
+b.create(arith::CmpFPredicate::OEQ, imag, zero);
+
+// Real > Imag
+Value imagDivReal = b.create(imag, real, fmf.getValue());
+Value imagSq =
+b.create(imagDivReal, imagDivReal, fmf.getValue());
+Value imagSqPlusOne = b.create(imagSq, one, fmf.getValue());
+Value imagSqrt = b.create(imagSqPlusOne, fmf.getValue());
+Value absImag = b.create(imagSqrt, real, fmf.getValue());
+
+// Real <= Imag
+Value realDivImag = b.create(real, imag, fmf.getValue());
+Value realSq =
+b.create(realDivImag, realDivImag, fmf.getValue());
+Value realSqPlusOne = b.create(realSq, one, fmf.getValue());
+Value realSqrt = b.create(realSqPlusOne, fmf.getValue());
+Value absReal = b.create(realSqrt, imag, fmf.getValue());
+
+rewriter.replaceOpWithNewOp(
+op, realIsZero, imag,
+b.create(
+imagIsZero, real,
+b.create(
+b.create(arith::CmpFPredicate::OGT, real, imag),
+absImag, absReal)));
+
 return success();
   }
 };
diff --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir 
b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index 3af28150fd5c3f..1028c9aae92c05 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -7,13 +7,28 @@ func.func @complex_abs(%arg: complex) -> f32 {
   %abs = complex.abs %arg: complex
   return %abs : f32
 }
+
+// CHECK: %[[ZERO:.*]] = arith.constant 0.00e+00 : f32
+// CHECK: %[[ONE:.*]] = arith.constant 1.00e+00 : f32
 // CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex
 // CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex
-// CHECK-DAG: %[[REAL_SQ:.*]] = arith.mulf %[[REAL]], %[[REAL]] : f32
-// CHECK-DAG: %[[IMAG_SQ:.*]] = arith.mulf %[[IMAG]], %[[IMAG]] : f32
-// CHECK: %[[SQ_NORM:.*]] = arith.addf %[[REAL_SQ]], %[[IMAG_SQ]] : f32
-// CHECK: %[[NORM:.*]] = math.sqrt %[[SQ_NORM]] : f32
-// CHECK: return %[[NORM]] : f32
+// CHECK: %[[IS_REAL_ZERO:.*]] = arith.cmpf oeq, %[[REAL]], %[[ZERO]] : f32
+// CHECK: %[[IS_IMAG_ZERO:.*]] = arith.cmpf oeq, %[[IMAG]], %[[ZERO]] : f32
+// CHECK: %[[IMAG_DIV_REAL:.*]] = arith.divf %[[IMAG]], %[[REAL]] : f32
+// CHECK: %[[IMAG_SQ:.*]] = arith.mulf %[[IMAG_DIV_REAL]], %[[IMAG_DIV_REAL]] 
: f32
+// CHECK: %[[IMAG_SQ_PLUS_ONE:.*]] = arith.addf %[[IMAG_SQ]], %[[ONE]] : f32
+// CHECK: %[[IMAG_SQRT:.*]] = math.sqrt %[[IMAG_SQ_PLUS_ONE]] : f32
+// CHECK: %[[ABS_IMAG:.*]] = arith.mulf %[[IMAG_SQRT]], %[[REAL]]

[Lldb-commits] [libcxx] [llvm] [clang-tools-extra] [lld] [openmp] [lldb] [mlir] [flang] [libunwind] [libcxxabi] [compiler-rt] [libc] [clang] [clang] static operators should evaluate object argument (P

2024-01-25 Thread Tianlan Zhou via lldb-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/15] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..a6c81f467fbe01c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..19406ff174dea14 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..a580c635998510f 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c95..42de125e7489911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCal

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

2024-01-25 Thread Hristo Hristov via lldb-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/6] 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 fd882bafe19a517..237a63022d55ff5 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 f80b1f6b663f045..c45aa3c510072e4 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 513988d08036ca6..6e58e752191ea5d 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 9a64cdb489119d9..00489d971c296c2 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_

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

2024-01-25 Thread Hristo Hristov via lldb-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/6] 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

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

2024-01-25 Thread Hristo Hristov via lldb-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/5] 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

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

2024-01-25 Thread Hristo Hristov via lldb-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/4] 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

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

2024-01-25 Thread Hristo Hristov via lldb-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/3] 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 fd882bafe19a517..237a63022d55ff5 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 f80b1f6b663f045..c45aa3c510072e4 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 513988d08036ca6..6e58e752191ea5d 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 9a64cdb489119d9..00489d971c296c2 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_

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

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

https://github.com/Zingam 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_CHAR8_

[Lldb-commits] [libunwind] [llvm] [libcxx] [clang] [flang] [openmp] [mlir] [compiler-rt] [clang-tools-extra] [lld] [lldb] [libc] [libcxxabi] [clang] static operators should evaluate object argument (P

2024-01-25 Thread Tianlan Zhou via lldb-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/15] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..a6c81f467fbe01c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..19406ff174dea14 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..a580c635998510f 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c95..42de125e7489911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCal

[Lldb-commits] [libcxx] [libcxxabi] [lld] [clang-tools-extra] [lldb] [clang] [llvm] [compiler-rt] [mlir] [libc] [flang] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-25 Thread via lldb-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From c4d28f82e108f9f12ccd0375e2a3502025b8c1e8 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 1/4] [clang-format] Add ShortReturnTypeLength option.

---
 clang/docs/ClangFormatStyleOptions.rst |  8 
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h|  8 
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ac9a0b70ed5daa4..3255ceb0aba75b4 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4994,6 +4994,14 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeLength:
+
+**ShortReturnTypeLength** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  short return types. This configures the character limit for a type to be
+  regarded as short. Note that this isn't the length of the type itself,
+  but the column where it finishes. I.e. it includes indentation, etc.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be1594376..04bf5cd4e768f34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1131,6 +1131,7 @@ clang-format
 - Add ``BreakAdjacentStringLiterals`` option.
 - Add ``ObjCPropertyAttributeOrder`` which can be used to sort ObjC property
   attributes (like ``nonatomic, strong, nullable``).
+- Add ``ShortReturnTypeLength`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 5ffd63ee73fc361..f94d68f2cf2a853 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3928,6 +3928,13 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  /// short return types. This configures the character limit for a type to be
+  /// regarded as short. Note that this isn't the length of the type itself,
+  /// but the column where it finishes. I.e. it includes indentation, etc.
+  /// \version 18
+  unsigned ShortReturnTypeLength;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4890,6 +4897,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeLength == R.ShortReturnTypeLength &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505b..bc0748ec52e6769 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeLength) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff5ed6c306f383b..20ffbeef7e9a6e9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1083,6 +1083,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeLength", Style.ShortReturnTypeLength);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1554,6 +1555,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 

[Lldb-commits] [libcxx] [libcxxabi] [clang-tools-extra] [clang] [lld] [lldb] [libunwind] [llvm] [compiler-rt] [mlir] [libc] [openmp] [flang] [clang] static operators should evaluate object argument (P

2024-01-25 Thread Tianlan Zhou via lldb-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/15] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *C

[Lldb-commits] [libcxx] [clang] [clang-tools-extra] [lld] [libunwind] [lldb] [llvm] [compiler-rt] [mlir] [libc] [libclc] [flang] [mlir][python] Fix generation of Python bindings for `async` dialect (P

2024-01-25 Thread Abhishek Kulkarni via lldb-commits

https://github.com/adk9 edited https://github.com/llvm/llvm-project/pull/75960
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lld] [clang-tools-extra] [mlir] [compiler-rt] [clang] [flang] [libclc] [libunwind] [llvm] [libcxx] [libc] [mlir][python] Fix generation of python bindings for `async` dialect (P

2024-01-25 Thread Abhishek Kulkarni via lldb-commits

https://github.com/adk9 edited https://github.com/llvm/llvm-project/pull/75960
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lld] [clang-tools-extra] [mlir] [compiler-rt] [clang] [flang] [libclc] [libunwind] [llvm] [libcxx] [libc] [mlir][python] Fix generation of python bindings for async dialect (PR

2024-01-25 Thread Abhishek Kulkarni via lldb-commits

https://github.com/adk9 updated https://github.com/llvm/llvm-project/pull/75960

>From a43ef7289cd7f5353fc4b365566011b93879e8f6 Mon Sep 17 00:00:00 2001
From: Abhishek Kulkarni 
Date: Tue, 19 Dec 2023 10:50:26 -0800
Subject: [PATCH] Fix generation of python bindings for async dialect

---
 .../mlir/Dialect/Async/IR/CMakeLists.txt  |  1 +
 mlir/python/CMakeLists.txt|  9 ++--
 .../mlir/dialects/async_dialect/__init__.py   |  2 +-
 mlir/test/python/dialects/async_dialect.py| 16 ++-
 .../mlir/python/BUILD.bazel   | 47 +++
 5 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/mlir/include/mlir/Dialect/Async/IR/CMakeLists.txt 
b/mlir/include/mlir/Dialect/Async/IR/CMakeLists.txt
index ebbf2df760faa4..2525eee2a34ec9 100644
--- a/mlir/include/mlir/Dialect/Async/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Async/IR/CMakeLists.txt
@@ -1,2 +1,3 @@
+set(LLVM_TARGET_DEFINITIONS AsyncOps.td)
 add_mlir_dialect(AsyncOps async)
 add_mlir_doc(AsyncOps AsyncDialect Dialects/ -gen-dialect-doc)
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 41d91cf6778338..550465f6e37467 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -72,7 +72,7 @@ declare_mlir_dialect_python_bindings(
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
   TD_FILE dialects/AsyncOps.td
   SOURCES_GLOB dialects/async_dialect/*.py
-  DIALECT_NAME async_dialect)
+  DIALECT_NAME async)
 
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
@@ -522,7 +522,7 @@ 
declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind
 
 declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
   MODULE_NAME _mlirAsyncPasses
-  ADD_TO_PARENT MLIRPythonSources.Dialects.async_dialect
+  ADD_TO_PARENT MLIRPythonSources.Dialects.async
   ROOT_DIR "${PYTHON_SOURCE_DIR}"
   SOURCES
 AsyncPasses.cpp
@@ -664,11 +664,10 @@ if(NOT LLVM_ENABLE_IDE)
 COMPONENT mlir-python-sources
   )
 endif()
-
-
+# 
###
 # The fully assembled package of modules.
 # This must come last.
-
+# 
###
 
 add_mlir_python_modules(MLIRPythonModules
   ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/mlir_core/mlir"
diff --git a/mlir/python/mlir/dialects/async_dialect/__init__.py 
b/mlir/python/mlir/dialects/async_dialect/__init__.py
index dcf9d6cb2638f6..6a5ecfc20956cf 100644
--- a/mlir/python/mlir/dialects/async_dialect/__init__.py
+++ b/mlir/python/mlir/dialects/async_dialect/__init__.py
@@ -2,4 +2,4 @@
 #  See https://llvm.org/LICENSE.txt for license information.
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-from .._async_dialect_ops_gen import *
+from .._async_ops_gen import *
diff --git a/mlir/test/python/dialects/async_dialect.py 
b/mlir/test/python/dialects/async_dialect.py
index f6181cc76118ed..13e3c42e57c21e 100644
--- a/mlir/test/python/dialects/async_dialect.py
+++ b/mlir/test/python/dialects/async_dialect.py
@@ -1,7 +1,8 @@
 # RUN: %PYTHON %s | FileCheck %s
 
 from mlir.ir import *
-import mlir.dialects.async_dialect
+from mlir.dialects import arith
+import mlir.dialects.async_dialect as async_dialect
 import mlir.dialects.async_dialect.passes
 from mlir.passmanager import *
 
@@ -11,6 +12,19 @@ def run(f):
 f()
 
 
+# CHECK-LABEL: TEST: testCreateGroupOp
+@run
+def testCreateGroupOp():
+with Context() as ctx, Location.unknown():
+module = Module.create()
+with InsertionPoint(module.body):
+i32 = IntegerType.get_signless(32)
+group_size = arith.ConstantOp(i32, 4)
+async_dialect.create_group(group_size)
+# CHECK: %0 = "arith.constant"() <{value = 4 : i32}> : () -> 
i32
+# CHECK: %1 = "async.create_group"(%0) : (i32) -> !async.group
+print(module)
+
 def testAsyncPass():
 with Context() as context:
 PassManager.parse("any(async-to-async-runtime)")
diff --git a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel 
b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel
index 049098b158f294..18e84ac7b68103 100644
--- a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel
@@ -331,6 +331,53 @@ filegroup(
 ],
 )
 
+##---##
+# Async dialect.
+##---##
+
+gentbl_filegroup(
+name = "AsyncOpsPyGen",
+tbl_outs = [
+(
+[
+"-gen-python-enum-bindings",
+"-bind-dialect=async",
+],
+"mlir/dialect

[Lldb-commits] [flang] [clang-tools-extra] [libcxx] [libc] [llvm] [lld] [lldb] [clang] [compiler-rt] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/5] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df10..2d6986d145483b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d224168416..0e87cbe8ce81219 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89bab..18edcd05ea85c9f 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516aef..e56f787e824f24a 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f72453..525ea6df3643ca6 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Tripl

[Lldb-commits] [flang] [clang-tools-extra] [libcxx] [libc] [llvm] [lld] [lldb] [clang] [compiler-rt] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/4] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df10..2d6986d145483b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d224168416..0e87cbe8ce81219 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89bab..18edcd05ea85c9f 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516aef..e56f787e824f24a 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f72453..525ea6df3643ca6 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Tripl

[Lldb-commits] [lldb] [lldb][progress][NFC] Add unit test for progress reports (PR #79533)

2024-01-25 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)


Changes

This test is being added as a way to check the behaviour of how progress events 
are broadcasted when reports are started and ended with the current 
implementation of progress reports. Here we're mainly checking and ensuring 
that the current behaviour is that progress events are broadcasted individually 
and placed in the event queue in order of their creation.

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


2 Files Affected:

- (modified) lldb/unittests/Core/CMakeLists.txt (+1) 
- (added) lldb/unittests/Core/ProgressReportTest.cpp (+105) 


``diff
diff --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index b3cddd150635b15..d40c357e3f463be 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBCoreTests
   FormatEntityTest.cpp
   MangledTest.cpp
   ModuleSpecTest.cpp
+  ProgressReportTest.cpp
   RichManglingContextTest.cpp
   SourceLocationSpecTest.cpp
   SourceManagerTest.cpp
diff --git a/lldb/unittests/Core/ProgressReportTest.cpp 
b/lldb/unittests/Core/ProgressReportTest.cpp
new file mode 100644
index 000..bdc168c9e077dd5
--- /dev/null
+++ b/lldb/unittests/Core/ProgressReportTest.cpp
@@ -0,0 +1,105 @@
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/Listener.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+class ProgressReportTest : public ::testing::Test {
+public:
+  void SetUp() override {
+FileSystem::Initialize();
+HostInfo::Initialize();
+PlatformMacOSX::Initialize();
+Debugger::Initialize(nullptr);
+  }
+  void TearDown() override {
+Debugger::Terminate();
+PlatformMacOSX::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+  }
+};
+} // namespace
+TEST_F(ProgressReportTest, TestReportCreation) {
+  std::chrono::milliseconds timeout(100);
+
+  // Set up the debugger, make sure that was done properly
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  // Get the debugger's broadcaster
+  Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
+
+  // Create a listener, make sure it can receive events and that it's
+  // listening to the correct broadcast bit
+  ListenerSP listener_sp = Listener::MakeListener("progress-listener");
+
+  listener_sp->StartListeningForEvents(&broadcaster,
+   Debugger::eBroadcastBitProgress);
+  EXPECT_TRUE(
+  broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
+
+  EventSP event_sp;
+  const ProgressEventData *data;
+
+  // Scope this for RAII on the progress objects
+  // Create progress reports and check that their respective events for having
+  // started are broadcasted
+  {
+Progress progress1("Progress report 1", "Starting report 1");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 1");
+
+Progress progress2("Progress report 2", "Starting report 2");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 2");
+
+Progress progress3("Progress report 3", "Starting report 3");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+ASSERT_TRUE(event_sp);
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 3");
+
+std::this_thread::sleep_for(timeout);
+  }
+
+  // Progress report objects should be destroyed at this point so
+  // get each report from the queue and check that they've been
+  // destroyed in reverse order
+  std::this_thread::sleep_for(timeout);
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetTitle(), "Progress report 3");
+  ASSERT_TRUE(data->GetCompleted());
+
+  std::this_thread::sleep_for(timeout);
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetTitle(), "Progress report 2");
+  ASSERT_TRUE(data->GetCompleted());
+
+  std::this_thread::sleep_for(timeout);
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+
+  ASSERT_EQ(data->GetTitle

[Lldb-commits] [llvm] [openmp] [flang] [mlir] [lldb] [mlir][Vector] Add patterns for efficient i4 -> i8 conversion emulation (PR #79494)

2024-01-25 Thread Diego Caballero via lldb-commits

https://github.com/dcaballe updated 
https://github.com/llvm/llvm-project/pull/79494

>From b8fb65dd1e65c36cfb2104e5f35179faa6011552 Mon Sep 17 00:00:00 2001
From: Diego Caballero 
Date: Thu, 25 Jan 2024 02:39:14 +
Subject: [PATCH] [mlir][Vector] Add patterns for efficient i4 -> i8 conversion
 emulation

This PR adds new patterns to improve the generated vector code for the
emulation of any conversion that have to go through an i4 -> i8 type
extension (only signed extensions are supported for now). This will
impact any i4 -> i8/i16/i32/i64 signed extensions as well as sitofp i4
-> f8/f16/f32/f64.

The asm code generated for the supported cases is significantly better
after this PR for both x86 and aarch64.
---
 .../Transforms/VectorEmulateNarrowType.cpp| 176 --
 .../Vector/vector-rewrite-narrow-types.mlir   |  33 
 2 files changed, 189 insertions(+), 20 deletions(-)

diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp 
b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
index a4a72754ccc250..8abd34fd246224 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
@@ -642,9 +642,9 @@ struct BitCastRewriter {
 
   BitCastRewriter(VectorType sourceVectorType, VectorType targetVectorType);
 
-  /// Verify that the preconditions for the rewrite are met.
-  LogicalResult precondition(PatternRewriter &rewriter,
- VectorType preconditionVectorType, Operation *op);
+  /// Verify that general preconditions for the rewrite are met.
+  LogicalResult commonPrecondition(PatternRewriter &rewriter,
+   VectorType preconditionType, Operation *op);
 
   /// Precompute the metadata for the rewrite.
   SmallVector
@@ -652,9 +652,9 @@ struct BitCastRewriter {
 
   /// Rewrite one step of the sequence:
   ///   `(shuffle -> and -> shiftright -> shiftleft -> or)`.
-  Value rewriteStep(PatternRewriter &rewriter, Location loc, Value 
initialValue,
-Value runningResult,
-const BitCastRewriter::Metadata &metadata);
+  Value genericRewriteStep(PatternRewriter &rewriter, Location loc,
+   Value initialValue, Value runningResult,
+   const BitCastRewriter::Metadata &metadata);
 
 private:
   /// Underlying enumerator that encodes the provenance of the bits in the each
@@ -719,21 +719,57 @@ BitCastRewriter::BitCastRewriter(VectorType 
sourceVectorType,
   LDBG("\n" << enumerator.sourceElementRanges);
 }
 
-LogicalResult BitCastRewriter::precondition(PatternRewriter &rewriter,
-VectorType precondition,
-Operation *op) {
-  if (precondition.getRank() != 1 || precondition.isScalable())
+/// Verify that the precondition type meets the common preconditions for any
+/// conversion.
+static LogicalResult commonConversionPrecondition(PatternRewriter &rewriter,
+  VectorType preconditionType,
+  Operation *op) {
+  if (!preconditionType || preconditionType.getRank() != 1 ||
+  preconditionType.isScalable())
 return rewriter.notifyMatchFailure(op, "scalable or >1-D vector");
 
   // TODO: consider relaxing this restriction in the future if we find ways
   // to really work with subbyte elements across the MLIR/LLVM boundary.
-  int64_t resultBitwidth = precondition.getElementTypeBitWidth();
+  unsigned resultBitwidth = preconditionType.getElementTypeBitWidth();
   if (resultBitwidth % 8 != 0)
 return rewriter.notifyMatchFailure(op, "bitwidth is not k * 8");
 
   return success();
 }
 
+LogicalResult BitCastRewriter::commonPrecondition(PatternRewriter &rewriter,
+  VectorType preconditionType,
+  Operation *op) {
+  if (!enumerator.sourceVectorType || !enumerator.targetVectorType)
+return rewriter.notifyMatchFailure(op, "types are not vector");
+
+  return commonConversionPrecondition(rewriter, preconditionType, op);
+}
+
+/// Verify that source and destination element types meet the precondition for
+/// the supported aligned conversion cases. Alignment means that the either the
+/// source element type is multiple of the destination element type or the 
other
+/// way around.
+///
+/// NOTE: This method assumes that common conversion preconditions are met.
+static LogicalResult alignedConversionPrecondition(PatternRewriter &rewriter,
+   VectorType srcType,
+   VectorType dstType,
+   Operation *op) {
+  if (!srcType || !dstType)
+return rewriter.notifyMatchFailure(op, "Not a supported aligned case");
+  unsigned s

[Lldb-commits] [lldb] [lldb][progress][NFC] Add unit test for progress reports (PR #79533)

2024-01-25 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova created 
https://github.com/llvm/llvm-project/pull/79533

This test is being added as a way to check the behaviour of how progress events 
are broadcasted when reports are started and ended with the current 
implementation of progress reports. Here we're mainly checking and ensuring 
that the current behaviour is that progress events are broadcasted individually 
and placed in the event queue in order of their creation.

>From 9274bcd897cd3ecdb3a842bc72ee660ba335aa57 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Thu, 25 Jan 2024 16:40:42 -0800
Subject: [PATCH] [lldb][progress][NFC] Add unit test for progress reports

This test is being added as a way to check the behaviour of how progress
events are broadcasted when reports are started and ended with the
current implementation of progress reports. Here we're mainly checking
and ensuring that the current behaviour is that progress events are
broadcasted individually and placed in the event queue in order of
their creation.
---
 lldb/unittests/Core/CMakeLists.txt |   1 +
 lldb/unittests/Core/ProgressReportTest.cpp | 105 +
 2 files changed, 106 insertions(+)
 create mode 100644 lldb/unittests/Core/ProgressReportTest.cpp

diff --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index b3cddd150635b15..d40c357e3f463be 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBCoreTests
   FormatEntityTest.cpp
   MangledTest.cpp
   ModuleSpecTest.cpp
+  ProgressReportTest.cpp
   RichManglingContextTest.cpp
   SourceLocationSpecTest.cpp
   SourceManagerTest.cpp
diff --git a/lldb/unittests/Core/ProgressReportTest.cpp 
b/lldb/unittests/Core/ProgressReportTest.cpp
new file mode 100644
index 000..bdc168c9e077dd5
--- /dev/null
+++ b/lldb/unittests/Core/ProgressReportTest.cpp
@@ -0,0 +1,105 @@
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/Listener.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+class ProgressReportTest : public ::testing::Test {
+public:
+  void SetUp() override {
+FileSystem::Initialize();
+HostInfo::Initialize();
+PlatformMacOSX::Initialize();
+Debugger::Initialize(nullptr);
+  }
+  void TearDown() override {
+Debugger::Terminate();
+PlatformMacOSX::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+  }
+};
+} // namespace
+TEST_F(ProgressReportTest, TestReportCreation) {
+  std::chrono::milliseconds timeout(100);
+
+  // Set up the debugger, make sure that was done properly
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  // Get the debugger's broadcaster
+  Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
+
+  // Create a listener, make sure it can receive events and that it's
+  // listening to the correct broadcast bit
+  ListenerSP listener_sp = Listener::MakeListener("progress-listener");
+
+  listener_sp->StartListeningForEvents(&broadcaster,
+   Debugger::eBroadcastBitProgress);
+  EXPECT_TRUE(
+  broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
+
+  EventSP event_sp;
+  const ProgressEventData *data;
+
+  // Scope this for RAII on the progress objects
+  // Create progress reports and check that their respective events for having
+  // started are broadcasted
+  {
+Progress progress1("Progress report 1", "Starting report 1");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 1");
+
+Progress progress2("Progress report 2", "Starting report 2");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 2");
+
+Progress progress3("Progress report 3", "Starting report 3");
+EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+ASSERT_TRUE(event_sp);
+
+data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
+ASSERT_EQ(data->GetDetails(), "Starting report 3");
+
+std::this_thread::sleep_for(timeout);
+  }
+
+  // Progress report objects should be destroyed at this point so
+  // get each report from the queue and check that they've been
+  // destroyed in reverse order
+  std::this_thread::sleep_for(timeout);
+  EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
+  data = ProgressEventData::GetEventDataFromEvent

[Lldb-commits] [clang] [clang-tools-extra] [llvm] [flang] [mlir] [lldb] [mlir][complex] Prevent underflow in complex.abs (PR #76316)

2024-01-25 Thread Kai Sasaki via lldb-commits

https://github.com/Lewuathe updated 
https://github.com/llvm/llvm-project/pull/76316

>From a5810363e546da073543cb2d62cceb956c46b2e6 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Fri, 15 Dec 2023 15:53:54 +0900
Subject: [PATCH 1/2] [mlir][complex] Prevent underflow in complex.abs

---
 .../ComplexToStandard/ComplexToStandard.cpp   |  56 ++---
 .../convert-to-standard.mlir  | 115 ++
 .../ComplexToStandard/full-conversion.mlir|  25 +++-
 .../Dialect/Complex/CPU/correctness.mlir  |  38 ++
 4 files changed, 194 insertions(+), 40 deletions(-)

diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp 
b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index bf753c7062f366..7c1db57b55f996 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -26,29 +26,57 @@ namespace mlir {
 using namespace mlir;
 
 namespace {
+// The algorithm is listed in https://dl.acm.org/doi/pdf/10.1145/363717.363780.
 struct AbsOpConversion : public OpConversionPattern {
   using OpConversionPattern::OpConversionPattern;
 
   LogicalResult
   matchAndRewrite(complex::AbsOp op, OpAdaptor adaptor,
   ConversionPatternRewriter &rewriter) const override {
-auto loc = op.getLoc();
-auto type = op.getType();
+mlir::ImplicitLocOpBuilder b(op.getLoc(), rewriter);
 
 arith::FastMathFlagsAttr fmf = op.getFastMathFlagsAttr();
 
-Value real =
-rewriter.create(loc, type, adaptor.getComplex());
-Value imag =
-rewriter.create(loc, type, adaptor.getComplex());
-Value realSqr =
-rewriter.create(loc, real, real, fmf.getValue());
-Value imagSqr =
-rewriter.create(loc, imag, imag, fmf.getValue());
-Value sqNorm =
-rewriter.create(loc, realSqr, imagSqr, fmf.getValue());
-
-rewriter.replaceOpWithNewOp(op, sqNorm);
+Type elementType = op.getType();
+Value arg = adaptor.getComplex();
+
+Value zero =
+b.create(elementType, b.getZeroAttr(elementType));
+Value one = b.create(elementType,
+b.getFloatAttr(elementType, 1.0));
+
+Value real = b.create(elementType, arg);
+Value imag = b.create(elementType, arg);
+
+Value realIsZero =
+b.create(arith::CmpFPredicate::OEQ, real, zero);
+Value imagIsZero =
+b.create(arith::CmpFPredicate::OEQ, imag, zero);
+
+// Real > Imag
+Value imagDivReal = b.create(imag, real, fmf.getValue());
+Value imagSq =
+b.create(imagDivReal, imagDivReal, fmf.getValue());
+Value imagSqPlusOne = b.create(imagSq, one, fmf.getValue());
+Value imagSqrt = b.create(imagSqPlusOne, fmf.getValue());
+Value absImag = b.create(imagSqrt, real, fmf.getValue());
+
+// Real <= Imag
+Value realDivImag = b.create(real, imag, fmf.getValue());
+Value realSq =
+b.create(realDivImag, realDivImag, fmf.getValue());
+Value realSqPlusOne = b.create(realSq, one, fmf.getValue());
+Value realSqrt = b.create(realSqPlusOne, fmf.getValue());
+Value absReal = b.create(realSqrt, imag, fmf.getValue());
+
+rewriter.replaceOpWithNewOp(
+op, realIsZero, imag,
+b.create(
+imagIsZero, real,
+b.create(
+b.create(arith::CmpFPredicate::OGT, real, imag),
+absImag, absReal)));
+
 return success();
   }
 };
diff --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir 
b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index 3af28150fd5c3f..1028c9aae92c05 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -7,13 +7,28 @@ func.func @complex_abs(%arg: complex) -> f32 {
   %abs = complex.abs %arg: complex
   return %abs : f32
 }
+
+// CHECK: %[[ZERO:.*]] = arith.constant 0.00e+00 : f32
+// CHECK: %[[ONE:.*]] = arith.constant 1.00e+00 : f32
 // CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex
 // CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex
-// CHECK-DAG: %[[REAL_SQ:.*]] = arith.mulf %[[REAL]], %[[REAL]] : f32
-// CHECK-DAG: %[[IMAG_SQ:.*]] = arith.mulf %[[IMAG]], %[[IMAG]] : f32
-// CHECK: %[[SQ_NORM:.*]] = arith.addf %[[REAL_SQ]], %[[IMAG_SQ]] : f32
-// CHECK: %[[NORM:.*]] = math.sqrt %[[SQ_NORM]] : f32
-// CHECK: return %[[NORM]] : f32
+// CHECK: %[[IS_REAL_ZERO:.*]] = arith.cmpf oeq, %[[REAL]], %[[ZERO]] : f32
+// CHECK: %[[IS_IMAG_ZERO:.*]] = arith.cmpf oeq, %[[IMAG]], %[[ZERO]] : f32
+// CHECK: %[[IMAG_DIV_REAL:.*]] = arith.divf %[[IMAG]], %[[REAL]] : f32
+// CHECK: %[[IMAG_SQ:.*]] = arith.mulf %[[IMAG_DIV_REAL]], %[[IMAG_DIV_REAL]] 
: f32
+// CHECK: %[[IMAG_SQ_PLUS_ONE:.*]] = arith.addf %[[IMAG_SQ]], %[[ONE]] : f32
+// CHECK: %[[IMAG_SQRT:.*]] = math.sqrt %[[IMAG_SQ_PLUS_ONE]] : f32
+// CHECK: %[[ABS_IMAG:.*]] = arith.mulf %[[IMAG_SQRT]], %[[REAL]]

[Lldb-commits] [lldb] [lldb][libc++] Adds system_clock data formatters. (PR #78609)

2024-01-25 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

I commented out the two tests that are failing on macOS temporarily so you'd 
have a chance to look at this.  If you don't have access to macOS (I assume 
this is working on Linux or whatever), @Michael137 or I can look into it.  
Thanks.  

```
commit ba45ad160e3f329aeb02c19eaf18af27fa423d85
Author: Jason Molenda 
Date:   Thu Jan 25 16:30:14 2024 -0800

Temporarily disable two libcxx chrono formatter tests
```

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


[Lldb-commits] [lldb] ba45ad1 - Temporarily disable two libcxx chrono formatter tests

2024-01-25 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2024-01-25T16:30:14-08:00
New Revision: ba45ad160e3f329aeb02c19eaf18af27fa423d85

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

LOG: Temporarily disable two libcxx chrono formatter tests

On macOS, the formatter is printing signed values as
unsigned, it seems, and the tests are expecting correctly
signed values.  These tests were added in
https://github.com/llvm/llvm-project/pull/78609

Added: 


Modified: 

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
index a90fb828d121a7f..9706f9e94e922f1 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py
@@ -54,16 +54,17 @@ def test_with_run_command(self):
 substrs=["ss_0 = date/time=1970-01-01T00:00:00Z timestamp=0 s"],
 )
 
-self.expect(
-"frame variable ss_neg_date_time",
-substrs=[
-"ss_neg_date_time = date/time=-32767-01-01T00:00:00Z 
timestamp=-1096193779200 s"
-],
-)
-self.expect(
-"frame variable ss_neg_seconds",
-substrs=["ss_neg_seconds = timestamp=-1096193779201 s"],
-)
+# FIXME disabled temporarily, macOS is printing this as an unsigned?
+#self.expect(
+#"frame variable ss_neg_date_time",
+#substrs=[
+#"ss_neg_date_time = date/time=-32767-01-01T00:00:00Z 
timestamp=-1096193779200 s"
+#],
+#)
+#self.expect(
+#"frame variable ss_neg_seconds",
+#substrs=["ss_neg_seconds = timestamp=-1096193779201 s"],
+#)
 
 self.expect(
 "frame variable ss_pos_date_time",
@@ -76,10 +77,11 @@ def test_with_run_command(self):
 substrs=["ss_pos_seconds = timestamp=971890963200 s"],
 )
 
-self.expect(
-"frame variable ss_min",
-substrs=["ss_min = timestamp=-9223372036854775808 s"],
-)
+# FIXME disabled temporarily, macOS is printing this as an unsigned?
+#self.expect(
+#"frame variable ss_min",
+#substrs=["ss_min = timestamp=-9223372036854775808 s"],
+#)
 self.expect(
 "frame variable ss_max",
 substrs=["ss_max = timestamp=9223372036854775807 s"],



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


[Lldb-commits] [clang-tools-extra] [lldb] [lld] [libc] [clang] [llvm] [libcxx] [flang] [compiler-rt] [mlir] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-25 Thread via lldb-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From c4d28f82e108f9f12ccd0375e2a3502025b8c1e8 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 1/4] [clang-format] Add ShortReturnTypeLength option.

---
 clang/docs/ClangFormatStyleOptions.rst |  8 
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h|  8 
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ac9a0b70ed5daa..3255ceb0aba75b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4994,6 +4994,14 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeLength:
+
+**ShortReturnTypeLength** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  short return types. This configures the character limit for a type to be
+  regarded as short. Note that this isn't the length of the type itself,
+  but the column where it finishes. I.e. it includes indentation, etc.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be159437..04bf5cd4e768f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1131,6 +1131,7 @@ clang-format
 - Add ``BreakAdjacentStringLiterals`` option.
 - Add ``ObjCPropertyAttributeOrder`` which can be used to sort ObjC property
   attributes (like ``nonatomic, strong, nullable``).
+- Add ``ShortReturnTypeLength`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 5ffd63ee73fc36..f94d68f2cf2a85 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3928,6 +3928,13 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When AlwaysBreakAfterReturnType is None, line breaks are prevented after
+  /// short return types. This configures the character limit for a type to be
+  /// regarded as short. Note that this isn't the length of the type itself,
+  /// but the column where it finishes. I.e. it includes indentation, etc.
+  /// \version 18
+  unsigned ShortReturnTypeLength;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4890,6 +4897,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeLength == R.ShortReturnTypeLength &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..bc0748ec52e676 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeLength) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff5ed6c306f383..20ffbeef7e9a6e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1083,6 +1083,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeLength", Style.ShortReturnTypeLength);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1554,6 +1555,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language)

[Lldb-commits] [lldb] [lldb][libc++] Adds system_clock data formatters. (PR #78609)

2024-01-25 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

@mordante I'm seeing failures on the macOS bots (and on my desktop) with 
TestDataFormatterLibcxxChrono.py, the test

self.expect(
"frame variable ss_neg_date_time",
substrs=[
"ss_neg_date_time = date/time=-32767-01-01T00:00:00Z 
timestamp=-1096193779200 s"
],
)

but we're getting an unsigned timestamp from lldb instead:

```
(lldb) fr v ss_neg_date_time
(std::chrono::sys_seconds) ss_neg_date_time = date/time=-32767-01-01T00:00:00Z 
timestamp=18446742977515772416 s
```

so the test fails, from the `%ld` formater in 
formatters::LibcxxChronoSysSecondsSummaryProvider I suppose.  Both of these are 
formattings of the value 0xff00c5c25a00, I'm honestly not sure why it's 
formatted as an unsigned value on macOS for me, I'm guessing it isn't on linux 
or some platform?  

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


[Lldb-commits] [libcxx] [llvm] [clang-tools-extra] [clang] [lldb] [flang] [openmp] [libc] [mlir] [BOLT] Deduplicate equal offsets in BAT (PR #76905)

2024-01-25 Thread Amir Ayupov via lldb-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/76905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [llvm] [clang-tools-extra] [clang] [lldb] [flang] [openmp] [libc] [mlir] [BOLT] Deduplicate equal offsets in BAT (PR #76905)

2024-01-25 Thread Amir Ayupov via lldb-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/76905
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFCI] Change BreakpointIDList::FindBreakpointID to BreakpointIDList::Contains (PR #79517)

2024-01-25 Thread Jason Molenda via lldb-commits

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

LGTM.

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


[Lldb-commits] [lldb] [lldb][NFCI] Change BreakpointIDList::FindBreakpointID to BreakpointIDList::Contains (PR #79517)

2024-01-25 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)


Changes

`FindBreakpointID` take a BreakpointID and a pointer to a size_t (so you can 
get position information). It returns a bool to indicate whether the id was 
found in the list or not.

There are 2 callers of this currently and neither one actually uses the 
position information, so I removed it. After that, I renamed it to Contains to 
more accurately reflect the intent. Additionally, I changed the argument type 
from a reference to a value (because BreakpointID is just a wrapper around 2 
integers, copies are cheap).

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


5 Files Affected:

- (modified) lldb/include/lldb/Breakpoint/BreakpointID.h (+4) 
- (modified) lldb/include/lldb/Breakpoint/BreakpointIDList.h (+1-2) 
- (modified) lldb/source/Breakpoint/BreakpointIDList.cpp (+4-12) 
- (modified) lldb/source/Commands/CommandObjectBreakpoint.cpp (+2-3) 
- (modified) lldb/source/Commands/CommandObjectProcess.cpp (+1-3) 


``diff
diff --git a/lldb/include/lldb/Breakpoint/BreakpointID.h 
b/lldb/include/lldb/Breakpoint/BreakpointID.h
index a62323061b75823..093966d0cf5db30 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointID.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointID.h
@@ -26,6 +26,10 @@ class BreakpointID {
 
   virtual ~BreakpointID();
 
+  bool operator==(BreakpointID rhs) const {
+return m_break_id == rhs.m_break_id && m_location_id == rhs.m_location_id;
+  }
+
   lldb::break_id_t GetBreakpointID() const { return m_break_id; }
 
   lldb::break_id_t GetLocationID() const { return m_location_id; }
diff --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h 
b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index ddf85dd78cf2e0c..f2eaa60d954136f 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
@@ -42,8 +42,7 @@ class BreakpointIDList {
 
   bool AddBreakpointID(BreakpointID bp_id);
 
-  // TODO: This should take a const BreakpointID.
-  bool FindBreakpointID(BreakpointID &bp_id, size_t *position) const;
+  bool Contains(BreakpointID bp_id) const;
 
   // Returns a pair consisting of the beginning and end of a breakpoint
   // ID range expression.  If the input string is not a valid specification,
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp 
b/lldb/source/Breakpoint/BreakpointIDList.cpp
index 5904647314bc0c7..851d074e7535880 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -15,6 +15,8 @@
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/StreamString.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -48,18 +50,8 @@ bool BreakpointIDList::AddBreakpointID(BreakpointID bp_id) {
// return true.
 }
 
-bool BreakpointIDList::FindBreakpointID(BreakpointID &bp_id,
-size_t *position) const {
-  for (size_t i = 0; i < m_breakpoint_ids.size(); ++i) {
-BreakpointID tmp_id = m_breakpoint_ids[i];
-if (tmp_id.GetBreakpointID() == bp_id.GetBreakpointID() &&
-tmp_id.GetLocationID() == bp_id.GetLocationID()) {
-  *position = i;
-  return true;
-}
-  }
-
-  return false;
+bool BreakpointIDList::Contains(BreakpointID bp_id) const {
+  return llvm::is_contained(m_breakpoint_ids, bp_id);
 }
 
 //  This function takes OLD_ARGS, which is usually the result of breaking the
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp 
b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 1661d5d9b743e27..3fdf5cd3cd43d2d 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -1485,9 +1485,8 @@ class CommandObjectBreakpointDelete : public 
CommandObjectParsed {
   for (auto breakpoint_sp : breakpoints.Breakpoints()) {
 if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
   BreakpointID bp_id(breakpoint_sp->GetID());
-  size_t pos = 0;
-  if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
-valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
+  if (!excluded_bp_ids.Contains(bp_id))
+valid_bp_ids.AddBreakpointID(bp_id);
 }
   }
   if (valid_bp_ids.GetSize() == 0) {
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp 
b/lldb/source/Commands/CommandObjectProcess.cpp
index 6dc7648f872df8f..c7b874d19793770 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -646,9 +646,7 @@ class CommandObjectProcessContinue : public 
CommandObjectParsed {
   for (size_t loc_idx = 0; loc_idx < num_locations; loc_idx++) {
 BreakpointLocationSP loc_sp = bp_sp->GetLocationAtIndex(loc_idx);
 tmp_id.SetBreakpointLocationID(loc_idx);
-size_t position = 0;
-if (!with_locs.FindBreak

[Lldb-commits] [lldb] [lldb][NFCI] Change BreakpointIDList::FindBreakpointID to BreakpointIDList::Contains (PR #79517)

2024-01-25 Thread Alex Langford via lldb-commits

https://github.com/bulbazord created 
https://github.com/llvm/llvm-project/pull/79517

`FindBreakpointID` take a BreakpointID and a pointer to a size_t (so you can 
get position information). It returns a bool to indicate whether the id was 
found in the list or not.

There are 2 callers of this currently and neither one actually uses the 
position information, so I removed it. After that, I renamed it to Contains to 
more accurately reflect the intent. Additionally, I changed the argument type 
from a reference to a value (because BreakpointID is just a wrapper around 2 
integers, copies are cheap).

>From 74632b472c384d45ba7fd4eeca018b77b4142f61 Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Thu, 25 Jan 2024 14:56:35 -0800
Subject: [PATCH] [lldb][NFCI] Change BreakpointIDList::FindBreakpointID to
 BreakpointIDList::Contains

`FindBreakpointID` take a BreakpointID and a pointer to a size_t (so you
can get position information). It returns a bool to indicate whether the
id was found in the list or not.

There are 2 callers of this currently and neither one actually uses the
position information, so I removed it. After that, I renamed it to
Contains to more accurately reflect the intent. Additionally, I changed
the argument type from a reference to a value (because BreakpointID is
just a wrapper around 2 integers, copies are cheap).
---
 lldb/include/lldb/Breakpoint/BreakpointID.h  |  4 
 lldb/include/lldb/Breakpoint/BreakpointIDList.h  |  3 +--
 lldb/source/Breakpoint/BreakpointIDList.cpp  | 16 
 lldb/source/Commands/CommandObjectBreakpoint.cpp |  5 ++---
 lldb/source/Commands/CommandObjectProcess.cpp|  4 +---
 5 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Breakpoint/BreakpointID.h 
b/lldb/include/lldb/Breakpoint/BreakpointID.h
index a62323061b75823..093966d0cf5db30 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointID.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointID.h
@@ -26,6 +26,10 @@ class BreakpointID {
 
   virtual ~BreakpointID();
 
+  bool operator==(BreakpointID rhs) const {
+return m_break_id == rhs.m_break_id && m_location_id == rhs.m_location_id;
+  }
+
   lldb::break_id_t GetBreakpointID() const { return m_break_id; }
 
   lldb::break_id_t GetLocationID() const { return m_location_id; }
diff --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h 
b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index ddf85dd78cf2e0c..f2eaa60d954136f 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
@@ -42,8 +42,7 @@ class BreakpointIDList {
 
   bool AddBreakpointID(BreakpointID bp_id);
 
-  // TODO: This should take a const BreakpointID.
-  bool FindBreakpointID(BreakpointID &bp_id, size_t *position) const;
+  bool Contains(BreakpointID bp_id) const;
 
   // Returns a pair consisting of the beginning and end of a breakpoint
   // ID range expression.  If the input string is not a valid specification,
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp 
b/lldb/source/Breakpoint/BreakpointIDList.cpp
index 5904647314bc0c7..851d074e7535880 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -15,6 +15,8 @@
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/StreamString.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -48,18 +50,8 @@ bool BreakpointIDList::AddBreakpointID(BreakpointID bp_id) {
// return true.
 }
 
-bool BreakpointIDList::FindBreakpointID(BreakpointID &bp_id,
-size_t *position) const {
-  for (size_t i = 0; i < m_breakpoint_ids.size(); ++i) {
-BreakpointID tmp_id = m_breakpoint_ids[i];
-if (tmp_id.GetBreakpointID() == bp_id.GetBreakpointID() &&
-tmp_id.GetLocationID() == bp_id.GetLocationID()) {
-  *position = i;
-  return true;
-}
-  }
-
-  return false;
+bool BreakpointIDList::Contains(BreakpointID bp_id) const {
+  return llvm::is_contained(m_breakpoint_ids, bp_id);
 }
 
 //  This function takes OLD_ARGS, which is usually the result of breaking the
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp 
b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 1661d5d9b743e27..3fdf5cd3cd43d2d 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -1485,9 +1485,8 @@ class CommandObjectBreakpointDelete : public 
CommandObjectParsed {
   for (auto breakpoint_sp : breakpoints.Breakpoints()) {
 if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
   BreakpointID bp_id(breakpoint_sp->GetID());
-  size_t pos = 0;
-  if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
-valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
+  if (!excluded_bp_ids.Contains(bp_id))
+valid_bp_ids.AddBreakpointID(bp_id);
 }

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

2024-01-25 Thread via lldb-commits

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


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

2024-01-25 Thread via lldb-commits


@@ -491,17 +491,38 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
+   "Not truncating.");
+assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
+BaseIV = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);

ayalz wrote:

Ah, ResultTy should be reset to TruncTy here, so that Step will be truncated to 
the updated type of BaseIV, rather than its original type. (Or reset right 
after the asserts, so that both truncations use ResultTy.) Wonder about test 
coverage if all pass?

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


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

2024-01-25 Thread via lldb-commits

https://github.com/ayalz commented:

Missing an update of ResultTy, and possibly some test(s)?

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


[Lldb-commits] [compiler-rt] [lld] [lldb] [clang] [libcxx] [llvm] [libcxxabi] [mlir] [flang] [clang-tools-extra] [libc] [libclc] [ELF] Add internal InputFile (PR #78944)

2024-01-25 Thread Andrew Ng via lldb-commits




nga888 wrote:

Sorry for the delay to reply but I've been more busy of late. I can confirm 
that it was a downstream code path which was calling `getFile()` for a 
`SyntheticSection` that was causing the assertion. This downstream code was 
effectively ignoring any "internal" sections based on the return from 
`getFile()`. It now first filters out sections of type `SyntheticSection` to 
avoid the assertion.

Even though there's no upstream code path that hits this issue, I think 
updating that comment and `getFile()` would be worthwhile to avoid any 
confusion.

Thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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/8] [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

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

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


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");

fhahn wrote:

Updated, thanks!

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


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

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


@@ -491,19 +491,41 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
 HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
   }
 
+  // Truncate base induction if needed.
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");

fhahn wrote:

Updated and also separate into 2 separate asserts.

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


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

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


@@ -491,19 +491,41 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
 HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
   }
 
+  // Truncate base induction if needed.

fhahn wrote:

Done, thanks! (missed originally)

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


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

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

https://github.com/fhahn commented:

Missed comments should be addressed now, seems I missed them in the GitHub UI 
somehow

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


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

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


@@ -491,19 +491,41 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
 HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
   }
 
+  // Truncate base induction if needed.
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");
+auto *T = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(T, IP);
+BaseIV = T;

fhahn wrote:

Adjusted, thanks!

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


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

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


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");
+auto *T = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(T, IP);
+BaseIV = T;
+  }
+
+  // Truncate step if needed.
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);

fhahn wrote:

Moved, thanks!

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


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

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


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);

fhahn wrote:

Updated, thanks!

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


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

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

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


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

2024-01-25 Thread via lldb-commits


@@ -982,6 +1037,92 @@ 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");
+

ayalz wrote:

nit: empty line intentional?

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


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

2024-01-25 Thread via lldb-commits

https://github.com/ayalz commented:

Few last minor comments.

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


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

2024-01-25 Thread via lldb-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:

Well, the term `clone()` refers to "w/o-remapping-operands" when applied to 
recipes - as a virtual method rather than a static cloneR() function - so may 
seem natural if applied as such to their containing VPBB's and regions. The 
exception is VPlan::clone() which also takes care of remapping the operands. To 
better indicate when operands are remapped and when not, perhaps 
`unmappedClone()` and `mappedClone()` could be used instead, or `clone()` for 
w/o remapping, and, say, `VPlan::duplicate()` for w/ remapping (or vise versa).

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


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

2024-01-25 Thread via lldb-commits


@@ -982,6 +1037,92 @@ 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 Old2NewVPValues;
+
+  // Clone blocks.
+  VPBlockBase *NewPreheader = cloneVPB(Preheader);
+  const auto &[NewEntry, __] = cloneSESE(getEntry());

ayalz wrote:

Consistency nit: use Preheader and Entry, or getPreheader() and getEntry().

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


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

2024-01-25 Thread via lldb-commits


@@ -982,6 +1037,92 @@ 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 Old2NewVPValues;
+
+  // Clone blocks.
+  VPBlockBase *NewPreheader = cloneVPB(Preheader);
+  const auto &[NewEntry, __] = cloneSESE(getEntry());
+
+  // Create VPlan, clone live-ins and remap operands in the cloned blocks.
+  auto *NewPlan =
+  new VPlan(cast(NewPreheader), 
cast(NewEntry));
+  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());
+  // else NewTripCount will be created and inserted into Old2NewVPValues when
+  // TripCount is cloned. In any case NewPlan->TripCount is updated below.
+
+  remapOperands(Preheader, NewPreheader, Old2NewVPValues);
+  remapOperands(Entry, NewEntry, Old2NewVPValues);
+
+  // Clone live-outs.
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+
+  // Initialize remaining fields of cloned VPlan.
+  NewEntry->setPlan(NewPlan);
+  NewPreheader->setPlan(NewPlan);

ayalz wrote:

```suggestion
```
taken care of when constructing NewPlan.

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


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

2024-01-25 Thread via lldb-commits


@@ -982,6 +1037,92 @@ 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 Old2NewVPValues;

ayalz wrote:

nit: can define below when starting to deal with values.

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


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

2024-01-25 Thread via lldb-commits


@@ -982,6 +1037,92 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,

ayalz wrote:

Should `remapOperands()` be a lambda inside VPlan::clone()?

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


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

2024-01-25 Thread via lldb-commits

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


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

2024-01-25 Thread Florian Hahn via lldb-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/8] [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

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

2024-01-25 Thread via lldb-commits


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);

ayalz wrote:

```suggestion
```
Suffice to define StepTy later, when dealing with the truncation of Step. Here 
we're dealing with truncating BaseIV, and may be good to define its 
current/original type instead (using "BaseIVTy" may be confusing or deserves 
updating due to changing BaseIV and its type).

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


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

2024-01-25 Thread via lldb-commits


@@ -491,19 +491,41 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
 HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
   }
 
+  // Truncate base induction if needed.
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");
+auto *T = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(T, IP);
+BaseIV = T;

ayalz wrote:

There's no real need in `T`, and more consistent to simply redefine BaseIV = 
new ... (..., BaseIV, ...), again, as in the proposal above?

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


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

2024-01-25 Thread via lldb-commits

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


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

2024-01-25 Thread via lldb-commits


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");

ayalz wrote:

```suggestion
   TypeInfo.inferScalarType(BaseIV)->isIntegerTy() && "Truncation 
requires an integer");
```
this should assert that the truncation of BaseIV is valid, independent of Step. 
As in the proposal above, which uses ResultTy.

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


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

2024-01-25 Thread via lldb-commits

https://github.com/ayalz commented:

Some comments still seem relevant, trying to further clarify.

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


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

2024-01-25 Thread via lldb-commits


@@ -491,17 +491,39 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
 
 static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
 ScalarEvolution &SE, Instruction *TruncI,
-Type *IVTy, VPValue *StartV,
-VPValue *Step) {
+VPValue *StartV, VPValue *Step) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   auto IP = HeaderVPBB->getFirstNonPhi();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
-  Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
-  VPValue *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
-   TruncI ? TruncI->getType() : nullptr);
-HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
+  VPSingleDefRecipe *BaseIV = CanonicalIV;
+  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+HeaderVPBB->insert(BaseIV, IP);
+  }
+
+  // Truncate base induction if needed.
+  VPTypeAnalysis TypeInfo(SE.getContext());
+  Type *StepTy = TypeInfo.inferScalarType(Step);
+  if (TruncI) {
+Type *TruncTy = TruncI->getType();
+assert(TypeInfo.inferScalarType(BaseIV)->getScalarSizeInBits() >
+   TruncTy->getScalarSizeInBits() &&
+   StepTy->isIntegerTy() && "Truncation requires an integer step");
+auto *T = new VPScalarCastRecipe(Instruction::Trunc, BaseIV, TruncTy);
+HeaderVPBB->insert(T, IP);
+BaseIV = T;
+  }
+
+  // Truncate step if needed.
+  Type *ResultTy = TypeInfo.inferScalarType(BaseIV);

ayalz wrote:

Define StepTy here?

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


[Lldb-commits] [llvm] [libcxxabi] [flang] [libc] [compiler-rt] [openmp] [lld] [clang] [libunwind] [mlir] [lldb] [libcxx] [clang-tools-extra] [clang] static operators should evaluate object argument (P

2024-01-25 Thread Shafik Yaghmour via lldb-commits

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


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


[Lldb-commits] [clang-tools-extra] [llvm] [libc] [clang] [libcxx] [lldb] [lld] [flang] [compiler-rt] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

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


[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)

2024-01-25 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)


Changes

There are 3 ways to create an EventDataBytes object: (const char *), 
(llvm::StringRef), and (const void *, size_t len). All of these cases can be 
handled under `llvm::StringRef`. Additionally, this allows us to remove the 
otherwise unused `SetBytes`, `SwapBytes`, and `SetBytesFromCString` methods.

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


4 Files Affected:

- (modified) lldb/include/lldb/Utility/Event.h (-10) 
- (modified) lldb/source/API/SBEvent.cpp (+2-1) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+5-5) 
- (modified) lldb/source/Utility/Event.cpp (+1-29) 


``diff
diff --git a/lldb/include/lldb/Utility/Event.h 
b/lldb/include/lldb/Utility/Event.h
index 3de0401191caa7f..461d711b8c3f2c4 100644
--- a/lldb/include/lldb/Utility/Event.h
+++ b/lldb/include/lldb/Utility/Event.h
@@ -60,12 +60,8 @@ class EventDataBytes : public EventData {
   // Constructors
   EventDataBytes();
 
-  EventDataBytes(const char *cstr);
-
   EventDataBytes(llvm::StringRef str);
 
-  EventDataBytes(const void *src, size_t src_len);
-
   ~EventDataBytes() override;
 
   // Member functions
@@ -77,12 +73,6 @@ class EventDataBytes : public EventData {
 
   size_t GetByteSize() const;
 
-  void SetBytes(const void *src, size_t src_len);
-
-  void SwapBytes(std::string &new_bytes);
-
-  void SetBytesFromCString(const char *cstr);
-
   // Static functions
   static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr);
 
diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp
index f12df2939420d63..cc611449e25099a 100644
--- a/lldb/source/API/SBEvent.cpp
+++ b/lldb/source/API/SBEvent.cpp
@@ -24,7 +24,8 @@ using namespace lldb_private;
 SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }
 
 SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
-: m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
+: m_event_sp(new Event(
+  event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len,
   m_opaque_ptr(m_event_sp.get()) {
   LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
 }
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index eb42b9eb6cb6a57..4a06027501a898b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1089,7 +1089,8 @@ Status ProcessGDBRemote::DoAttachToProcessWithID(
   const int packet_len =
   ::snprintf(packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid);
   SetID(attach_pid);
-  auto data_sp = std::make_shared(packet, packet_len);
+  auto data_sp =
+  std::make_shared(llvm::StringRef(packet, 
packet_len));
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 } else
   SetExitStatus(-1, error.AsCString());
@@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName(
endian::InlHostByteOrder(),
endian::InlHostByteOrder());
 
-  auto data_sp = 
std::make_shared(packet.GetString().data(),
-  packet.GetSize());
+  auto data_sp = std::make_shared(packet.GetString());
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 
 } else
@@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() {
 return error;
   }
 
-  auto data_sp = std::make_shared(
-  continue_packet.GetString().data(), continue_packet.GetSize());
+  auto data_sp =
+  std::make_shared(continue_packet.GetString());
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 
   if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {
diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp
index cac118182c75da3..863167e56bce6f5 100644
--- a/lldb/source/Utility/Event.cpp
+++ b/lldb/source/Utility/Event.cpp
@@ -111,17 +111,7 @@ void EventData::Dump(Stream *s) const { 
s->PutCString("Generic Event Data"); }
 
 EventDataBytes::EventDataBytes() : m_bytes() {}
 
-EventDataBytes::EventDataBytes(const char *cstr) : m_bytes() {
-  SetBytesFromCString(cstr);
-}
-
-EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes() {
-  SetBytes(str.data(), str.size());
-}
-
-EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() {
-  SetBytes(src, src_len);
-}
+EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes(str.str()) {}
 
 EventDataBytes::~EventDataBytes() = default;
 
@@ -147,20 +137,6 @@ const void *EventDataBytes::GetBytes() const {
 
 size_t EventDataBytes::GetByteSize() const { return m_bytes.size(); }
 
-void EventDataBytes::SetBytes(const void *src, size_t src_len) {
-  if (src != nullptr &

[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)

2024-01-25 Thread Alex Langford via lldb-commits

https://github.com/bulbazord created 
https://github.com/llvm/llvm-project/pull/79508

There are 3 ways to create an EventDataBytes object: (const char *), 
(llvm::StringRef), and (const void *, size_t len). All of these cases can be 
handled under `llvm::StringRef`. Additionally, this allows us to remove the 
otherwise unused `SetBytes`, `SwapBytes`, and `SetBytesFromCString` methods.

>From 670abd2507ee45258801a759646b475a0db8e49c Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Thu, 25 Jan 2024 13:45:24 -0800
Subject: [PATCH] [lldb][NFCI] Constrain EventDataBytes creation

There are 3 ways to create an EventDataBytes object: (const char *),
(llvm::StringRef), and (const void *, size_t len). All of these cases
can be handled under `llvm::StringRef`. Additionally, this allows us to
remove the otherwise unused `SetBytes`, `SwapBytes`, and
`SetBytesFromCString` methods.
---
 lldb/include/lldb/Utility/Event.h | 10 ---
 lldb/source/API/SBEvent.cpp   |  3 +-
 .../Process/gdb-remote/ProcessGDBRemote.cpp   | 10 +++
 lldb/source/Utility/Event.cpp | 30 +--
 4 files changed, 8 insertions(+), 45 deletions(-)

diff --git a/lldb/include/lldb/Utility/Event.h 
b/lldb/include/lldb/Utility/Event.h
index 3de0401191caa7..461d711b8c3f2c 100644
--- a/lldb/include/lldb/Utility/Event.h
+++ b/lldb/include/lldb/Utility/Event.h
@@ -60,12 +60,8 @@ class EventDataBytes : public EventData {
   // Constructors
   EventDataBytes();
 
-  EventDataBytes(const char *cstr);
-
   EventDataBytes(llvm::StringRef str);
 
-  EventDataBytes(const void *src, size_t src_len);
-
   ~EventDataBytes() override;
 
   // Member functions
@@ -77,12 +73,6 @@ class EventDataBytes : public EventData {
 
   size_t GetByteSize() const;
 
-  void SetBytes(const void *src, size_t src_len);
-
-  void SwapBytes(std::string &new_bytes);
-
-  void SetBytesFromCString(const char *cstr);
-
   // Static functions
   static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr);
 
diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp
index f12df2939420d6..cc611449e25099 100644
--- a/lldb/source/API/SBEvent.cpp
+++ b/lldb/source/API/SBEvent.cpp
@@ -24,7 +24,8 @@ using namespace lldb_private;
 SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }
 
 SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
-: m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
+: m_event_sp(new Event(
+  event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len,
   m_opaque_ptr(m_event_sp.get()) {
   LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
 }
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index eb42b9eb6cb6a5..4a06027501a898 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1089,7 +1089,8 @@ Status ProcessGDBRemote::DoAttachToProcessWithID(
   const int packet_len =
   ::snprintf(packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid);
   SetID(attach_pid);
-  auto data_sp = std::make_shared(packet, packet_len);
+  auto data_sp =
+  std::make_shared(llvm::StringRef(packet, 
packet_len));
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 } else
   SetExitStatus(-1, error.AsCString());
@@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName(
endian::InlHostByteOrder(),
endian::InlHostByteOrder());
 
-  auto data_sp = 
std::make_shared(packet.GetString().data(),
-  packet.GetSize());
+  auto data_sp = std::make_shared(packet.GetString());
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 
 } else
@@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() {
 return error;
   }
 
-  auto data_sp = std::make_shared(
-  continue_packet.GetString().data(), continue_packet.GetSize());
+  auto data_sp =
+  std::make_shared(continue_packet.GetString());
   m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
 
   if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {
diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp
index cac118182c75da..863167e56bce6f 100644
--- a/lldb/source/Utility/Event.cpp
+++ b/lldb/source/Utility/Event.cpp
@@ -111,17 +111,7 @@ void EventData::Dump(Stream *s) const { 
s->PutCString("Generic Event Data"); }
 
 EventDataBytes::EventDataBytes() : m_bytes() {}
 
-EventDataBytes::EventDataBytes(const char *cstr) : m_bytes() {
-  SetBytesFromCString(cstr);
-}
-
-EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes() {
-  SetBytes(str.data(), str.size());
-}
-
-EventDataBytes::EventDa

[Lldb-commits] [clang-tools-extra] [llvm] [libc] [clang] [libcxx] [lldb] [lld] [libunwind] [flang] [mlir] [compiler-rt] [ELF] Implement R_RISCV_TLSDESC for RISC-V (PR #79239)

2024-01-25 Thread Fangrui Song via lldb-commits

https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/79239
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [clang] [libc] [compiler-rt] [clang-tools-extra] [llvm] [lld] [lldb] [libcxx] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> Got it, okay, thanks.
> 
> Since this change only applies to `--target=nvptx64-nvidia-cuda`, fine by me. 
> Thanks for putting up with our scrutiny. :)

No problem, I probably should've have been  clearer in my commit messages.

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


[Lldb-commits] [flang] [clang] [libunwind] [libc] [mlir] [compiler-rt] [lld] [clang-tools-extra] [llvm] [lldb] [libcxx] [ELF] Implement R_RISCV_TLSDESC for RISC-V (PR #79239)

2024-01-25 Thread Fangrui Song via lldb-commits

MaskRay wrote:

"""
This branch is out-of-date with the base branch
Merge the latest changes from main into this branch.
This merge commit will be associated with ...
"""

Hmm. rebase + `spr diff` cannot fix it. I'll merge this manually.

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


[Lldb-commits] [flang] [clang] [libunwind] [libc] [mlir] [compiler-rt] [lld] [clang-tools-extra] [llvm] [lldb] [libcxx] [ELF] Implement R_RISCV_TLSDESC for RISC-V (PR #79239)

2024-01-25 Thread Fangrui Song via lldb-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79239

>From 3725fa4eac3d3d946289d7eb7213f3a1751a2770 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 17:58:07 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp| 158 +
 lld/ELF/Relocations.cpp   |  25 ++--
 lld/test/ELF/riscv-tlsdesc-gd-mixed.s |  26 
 lld/test/ELF/riscv-tlsdesc-relax.s| 125 +
 lld/test/ELF/riscv-tlsdesc.s  | 192 ++
 5 files changed, 492 insertions(+), 34 deletions(-)
 create mode 100644 lld/test/ELF/riscv-tlsdesc-gd-mixed.s
 create mode 100644 lld/test/ELF/riscv-tlsdesc-relax.s
 create mode 100644 lld/test/ELF/riscv-tlsdesc.s

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index d7d3d3e47814971..67d7e2562e9b178 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -61,6 +61,7 @@ enum Op {
   AUIPC = 0x17,
   JALR = 0x67,
   LD = 0x3003,
+  LUI = 0x37,
   LW = 0x2003,
   SRLI = 0x5013,
   SUB = 0x4033,
@@ -73,6 +74,7 @@ enum Reg {
   X_T0 = 5,
   X_T1 = 6,
   X_T2 = 7,
+  X_A0 = 10,
   X_T3 = 28,
 };
 
@@ -102,6 +104,26 @@ static uint32_t setLO12_S(uint32_t insn, uint32_t imm) {
  (extractBits(imm, 4, 0) << 7);
 }
 
+namespace {
+struct SymbolAnchor {
+  uint64_t offset;
+  Defined *d;
+  bool end; // true for the anchor of st_value+st_size
+};
+} // namespace
+
+struct elf::RISCVRelaxAux {
+  // This records symbol start and end offsets which will be adjusted according
+  // to the nearest relocDeltas element.
+  SmallVector anchors;
+  // For relocations[i], the actual offset is r_offset - (i ? relocDeltas[i-1] 
:
+  // 0).
+  std::unique_ptr relocDeltas;
+  // For relocations[i], the actual type is relocTypes[i].
+  std::unique_ptr relocTypes;
+  SmallVector writes;
+};
+
 RISCV::RISCV() {
   copyRel = R_RISCV_COPY;
   pltRel = R_RISCV_JUMP_SLOT;
@@ -119,6 +141,7 @@ RISCV::RISCV() {
 tlsGotRel = R_RISCV_TLS_TPREL32;
   }
   gotRel = symbolicRel;
+  tlsDescRel = R_RISCV_TLSDESC;
 
   // .got[0] = _DYNAMIC
   gotHeaderEntriesNum = 1;
@@ -187,6 +210,8 @@ int64_t RISCV::getImplicitAddend(const uint8_t *buf, 
RelType type) const {
   case R_RISCV_JUMP_SLOT:
 // These relocations are defined as not having an implicit addend.
 return 0;
+  case R_RISCV_TLSDESC:
+return config->is64 ? read64le(buf + 8) : read32le(buf + 4);
   }
 }
 
@@ -295,6 +320,12 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol 
&s,
   case R_RISCV_PCREL_LO12_I:
   case R_RISCV_PCREL_LO12_S:
 return R_RISCV_PC_INDIRECT;
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+  case R_RISCV_TLSDESC_ADD_LO12:
+return R_TLSDESC_PC;
+  case R_RISCV_TLSDESC_CALL:
+return R_TLSDESC_CALL;
   case R_RISCV_TLS_GD_HI20:
 return R_TLSGD_PC;
   case R_RISCV_TLS_GOT_HI20:
@@ -419,6 +450,7 @@ void RISCV::relocate(uint8_t *loc, const Relocation &rel, 
uint64_t val) const {
 
   case R_RISCV_GOT_HI20:
   case R_RISCV_PCREL_HI20:
+  case R_RISCV_TLSDESC_HI20:
   case R_RISCV_TLS_GD_HI20:
   case R_RISCV_TLS_GOT_HI20:
   case R_RISCV_TPREL_HI20:
@@ -430,6 +462,8 @@ void RISCV::relocate(uint8_t *loc, const Relocation &rel, 
uint64_t val) const {
   }
 
   case R_RISCV_PCREL_LO12_I:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+  case R_RISCV_TLSDESC_ADD_LO12:
   case R_RISCV_TPREL_LO12_I:
   case R_RISCV_LO12_I: {
 uint64_t hi = (val + 0x800) >> 12;
@@ -513,29 +547,113 @@ void RISCV::relocate(uint8_t *loc, const Relocation 
&rel, uint64_t val) const {
 break;
 
   case R_RISCV_RELAX:
-return; // Ignored (for now)
-
+return;
+  case R_RISCV_TLSDESC:
+// The addend is stored in the second word.
+if (config->is64)
+  write64le(loc + 8, val);
+else
+  write32le(loc + 4, val);
+break;
   default:
 llvm_unreachable("unknown relocation");
   }
 }
 
+static void tlsdescToIe(uint8_t *loc, const Relocation &rel, uint64_t val) {
+  switch (rel.type) {
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+write32le(loc, 0x0013); // nop
+return;
+  case R_RISCV_TLSDESC_ADD_LO12:
+write32le(loc, utype(AUIPC, X_A0, hi20(val))); // auipc a0,
+return;
+  case R_RISCV_TLSDESC_CALL:
+if (config->is64)
+  write32le(loc, itype(LD, X_A0, X_A0, lo12(val))); // ld a0,(a0)
+else
+  write32le(loc, itype(LW, X_A0, X_A0, lo12(val))); // lw a0,(a0)
+return;
+  default:
+llvm_unreachable("unsupported relocation for TLSDESC to IE relaxation");
+  }
+}
+
+static void tlsdescToLe(uint8_t *loc, const Relocation &rel, uint64_t val) {
+  switch (rel.type) {
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+write32le(loc, 0x0013); // nop
+return;
+  case R_RISCV_TLSDESC

[Lldb-commits] [flang] [libc] [compiler-rt] [clang] [clang-tools-extra] [llvm] [libcxx] [lld] [lldb] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Justin Lebar via lldb-commits

jlebar wrote:

Got it, okay, thanks.

Since this change only applies to `--target=nvptx64-nvidia-cuda`, fine by me.  
Thanks for putting up with our scrutiny.  :)

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


[Lldb-commits] [lld] [lldb] [libcxx] [compiler-rt] [clang-tools-extra] [llvm] [libc] [clang] [flang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> I...think I understand.
> 
> Is the output of this compilation step a cubin, then?

Yes, it will spit out a simple `cubin` instead of a fatbinary. The NVIDIA 
toolchain is much worse about this stuff than the AMD one, but in general it 
works. You can check with `-###` or whatever like in 
https://godbolt.org/z/zWf5jezYP.

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


[Lldb-commits] [lld] [lldb] [libcxx] [compiler-rt] [clang-tools-extra] [llvm] [libc] [clang] [flang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Justin Lebar via lldb-commits

jlebar wrote:

I...think I understand.

Is the output of this compilation step a cubin, then?

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


[Lldb-commits] [lld] [lldb] [libcxx] [compiler-rt] [clang-tools-extra] [llvm] [libc] [clang] [flang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> > This method of compilation is not like CUDA, so we can't target all the 
> > GPUs at the same time.
> 
> Can you clarify for me -- what are you compiling where it's impossible to 
> target multiple GPUs in the binary? I'm confused because Art is understanding 
> that it's not CUDA, but we're modifying the CUDA driver here?

The idea is to simply compile C / C++ code directly targeting NVPTX rather than 
going through offloading languages like CUDA or OpenMP. This is more or less 
what cross-compiling is. We specify `--target=nvptx64-nvidia-cuda` which 
instructs the compiler to cross-compile the C / C++ targeting NVPTX. This 
results in a workflow that is very close to compiling a standard executable by 
design. This is mostly related to my work on the LLVM C library for GPUs [which 
I did a talk on that goes in more 
detail](https://www.youtube.com/watch?v=_LLGc48GYHc)

Right now, with the LLVM `libc` infrastructure I can do the following on my AMD 
GPU.

```
#include 
int main() { puts("Hello World!"); }
```
And compile it and run it more or less.
```
$ clang hello.c --target=amdgcn-amd-amdhsa -mcpu=native -flto -lc crt1.o
$ amdhsa_loader a.out
Hello World!
```
This works with AMD currently, and I want it to work for NVPTX so I can remove 
some ugly, annoying code in the `libc` project. This is how I'm running unit 
tests targeting the GPU in that project, which needs to run on the user's GPU. 
I'd rather just use `-march=native` than detect it manually in CMake.

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


[Lldb-commits] [lld] [lldb] [clang-tools-extra] [clang] [libcxx] [libc] [flang] [llvm] [compiler-rt] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Justin Lebar via lldb-commits

jlebar wrote:

> This method of compilation is not like CUDA, so we can't target all the GPUs 
> at the same time. 

Can you clarify for me -- what are you compiling where it's impossible to 
target multiple GPUs in the binary?  I'm confused because Art is understanding 
that it's not CUDA, but we're modifying the CUDA driver here?

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


[Lldb-commits] [lld] [lldb] [clang-tools-extra] [clang] [libcxx] [libc] [flang] [llvm] [compiler-rt] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Artem Belevich via lldb-commits

https://github.com/Artem-B approved this pull request.

LGTM, as we can only handle a single GPU target during compilation.


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


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

2024-01-25 Thread Florian Hahn via lldb-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];

fhahn wrote:

Added, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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) {

fhahn wrote:

I am not sure, the reason for keeping it static here is that it would only be 
useful in combination with operand remapping, having it as member of the API 
may be a bit error prone.

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


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

2024-01-25 Thread Florian Hahn via lldb-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

fhahn wrote:

Updated, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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;

fhahn wrote:

Not needed in the latest version, removed, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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;

fhahn wrote:

Not in the latest version, removed, thanks!

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


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

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


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

fhahn wrote:

Changed to `llvm_unreachable`, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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());

fhahn wrote:

Added, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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();

fhahn wrote:

Reordered as suggested, thanks! 

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


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

2024-01-25 Thread Florian Hahn via lldb-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);

fhahn wrote:

Updated as suggested and renamed, thanks!

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


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

2024-01-25 Thread Florian Hahn via lldb-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;
+

fhahn wrote:

Removed, thanks!

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


[Lldb-commits] [clang] [lld] [llvm] [libc] [flang] [libcxx] [compiler-rt] [clang-tools-extra] [lldb] [-Wunsafe-buffer-usage] Fix AST matcher of UUCAddAssignGadget (PR #79392)

2024-01-25 Thread via lldb-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/79392

>From dcc2b0c07681b57dbd5a82ce83f5166bb3b9ee09 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Wed, 24 Jan 2024 15:02:55 -0800
Subject: [PATCH] [-Wunsafe-buffer-usage] Fix AST matcher of UUCAddAssignGadget

We are not interested in nonpointers being added to.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 7df706beb22662c..9046491c9e86536 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1081,11 +1081,16 @@ class UUCAddAssignGadget : public FixableGadget {
   }
 
   static Matcher matcher() {
+// clang-format off
 return stmt(isInUnspecifiedUntypedContext(expr(ignoringImpCasts(
 binaryOperator(hasOperatorName("+="),
-   hasLHS(declRefExpr(toSupportedVariable())),
+   hasLHS(
+declRefExpr(
+  hasPointerType(),
+  toSupportedVariable())),
hasRHS(expr().bind(OffsetTag)))
 .bind(UUCAddAssignTag);
+// clang-format on
   }
 
   virtual std::optional getFixits(const Strategy &S) const override;

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


[Lldb-commits] [flang] [clang] [clang-tools-extra] [llvm] [compiler-rt] [libcxx] [libc] [lldb] [lld] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> > This method of compilation is not like CUDA, so we can't target all the 
> > GPUs at the same time.
> 
> I think this is the key fact I was missing. If the patch is only for a 
> standalone compilation which does not do multi-GPU compilation in principle, 
> then your approach makes sense.
> 
> I was arguing from the normal offloading which does have ability to target 
> multiple GPUs.

Yes, this is more similar to OpenCL or just regular CPU compilation where we 
have a single job that creates a simple executable, terminal application style. 
So given a single target, the desire is to "pick me the one that will work on 
the default CUDA device without me needing to check." type thing.

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


[Lldb-commits] [flang] [clang] [clang-tools-extra] [llvm] [compiler-rt] [libcxx] [libc] [lldb] [lld] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread via lldb-commits


@@ -276,7 +276,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,

ZijunZhaoCCK wrote:

Some cases like 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenOpenCL/amdgpu-alignment.cl#L3

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


[Lldb-commits] [libcxx] [flang] [lldb] [clang] [clang-tools-extra] [lld] [llvm] [compiler-rt] [libc] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Artem Belevich via lldb-commits

Artem-B wrote:

> This method of compilation is not like CUDA, so we can't target all the GPUs 
> at the same time.

I think this is the key fact I was missing. If the patch is only for a 
standalone compilation which does not do multi-GPU compilation in principle, 
then your approach makes sense.

I was arguing from the normal offloading which does have ability to target 
multiple GPUs.


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


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

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

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

>From 13a26e8e7440c3b501730b22588af393a3e543cd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 6 Jul 2023 08:07:45 +0100
Subject: [PATCH 1/3] [VPlan] Implement cloning of VPlans.

This patch implements cloning for VPlans and recipes. Cloning is used in
the epilogue vectorization path, to clone the VPlan for the main vector
loop. This means we won't re-use a VPlan when executing the VPlan for
the epilogue vector loop, which in turn will enable us to perform
optimizations based on UF & VF.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|   2 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   | 124 
 llvm/lib/Transforms/Vectorize/VPlan.h | 182 ++
 .../Transforms/Vectorize/VPlanTest.cpp|   2 +
 4 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c..9ffd44d59ffc6d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();
 const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan(
 EPI.MainLoopVF, EPI.MainLoopUF, BestMainPlan, MainILV, DT, true);
 ++LoopsVectorized;
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f7..99b2a3bd59a64d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =
+  new VPRegionBlock(NewEntry, Old2New[Exiting], getName(), isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewR);
+  return NewR;
+}
+
 void VPRegionBlock::dropAllReferences(VPValue *NewValue) {
   for (VPBlockBase *Block : vp_depth_first_shallow(Entry))
 // Drop all references in VPBasicBlocks and replace all uses with
@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+  return NewPlan;
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 
 Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 

[Lldb-commits] [clang] [clang-tools-extra] [lldb] [libc] [libcxx] [lld] [llvm] [flang] [compiler-rt] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> > I think the semantics of native on other architectures are clear enough 
> > here.
> 
> I don't think we have the same idea about that. Let's spell it out, so 
> there's no confusion.
> 
> [GCC 
> manual](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-march-16) 
> says:
> 
> > Using -march=native enables all instruction subsets supported by the local 
> > machine (hence the result might not run on different machines)
> 
> The way I read it "all instruction subsets supported by the local machine" 
> would be what all-GPUs strategy would do. The binary is expected to run on 
> all GPU architecture variants available on the machine.
> 
> Granted, gcc was not written with GPUs in mind, but it's a good baseline for 
> establishing existing conventions for the meaning of `-march=native`.

This more or less depends on what your definition of "local machine" is when it 
comes to a system augmented with GPUs. The verbiage of "**The** local machine" 
implies an assumption that there is only one, which I personally find 
consistent with just selecting the first GPU found on the system. There is 
ambiguity in how we should treat this in the case of multiple GPUs, but that's 
what the warning message is for. it informs the user that the "native" 
architecture is somewhat ambiguous and that the first one was selected.

Further, our current default makes sense, because it corresponds to Device ID 
zero in CUDA, which means that unless you change the environment via 
`CUDA_VISIBLE_DEVICES` or something, it will work on the default device.

So, in the case there is one device, the behavior is consistent with 
`-march=native`. In the case where there are two, we make an implicit decision 
to target the first GPU and inform the user. This method of compilation is not 
like CUDA, so we can't target all the GPUs at the same time. This will be 
useful in cases where we want to write code that simply targets a GPU that will 
"work". We have CMake code around LLVM already to do this, so it would be nice 
to get rid of that.

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


[Lldb-commits] [clang] [clang-tools-extra] [lldb] [libc] [libcxx] [lld] [llvm] [flang] [compiler-rt] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread Fangrui Song via lldb-commits


@@ -276,7 +276,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,

MaskRay wrote:

I wonder why we need this addition. This is not mentioned in the description.

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


[Lldb-commits] [libc] [lld] [flang] [libcxx] [clang] [clang-tools-extra] [compiler-rt] [llvm] [lldb] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread Fangrui Song via lldb-commits


@@ -255,7 +255,7 @@ class Triple {
 Cygnus,
 CoreCLR,
 Simulator, // Simulator variants of other systems, e.g., Apple's iOS
-MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
+MacABI,// Mac Catalyst variant of Apple's iOS deployment target.

MaskRay wrote:

Revert this difference? You can ignore clang-format reports.

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


[Lldb-commits] [clang] [lld] [llvm] [libc] [flang] [libcxx] [compiler-rt] [clang-tools-extra] [lldb] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread Fangrui Song via lldb-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/78655
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [lld] [llvm] [libc] [flang] [libcxx] [compiler-rt] [clang-tools-extra] [lldb] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread Fangrui Song via lldb-commits


@@ -1443,15 +1443,17 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain &TC = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat =
+  Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+

MaskRay wrote:

(the prevailing code style does not insert a blank line in this case. )

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


[Lldb-commits] [clang] [lld] [llvm] [libc] [flang] [libcxx] [compiler-rt] [clang-tools-extra] [lldb] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Artem Belevich via lldb-commits

Artem-B wrote:

> I think the semantics of native on other architectures are clear enough here.

I don't think we have the same idea about that. Let's spell it out, so there's 
no confusion.

[GCC 
manual](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-march-16) 
says:
> Using -march=native enables all instruction subsets supported by the local 
> machine (hence the result might not run on different machines)

The way I read it "all instruction subsets supported by the local machine" 
would be what all-GPUs strategy would do. The binary is expected to run on all 
GPU architecture variants available on the machine.

Granted, gcc was not written with GPUs in mind, but it's a good baseline for 
establishing existing conventions for the meaning of `-march=native`.

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


[Lldb-commits] [lldb] [mlir] [libcxx] [lld] [flang] [libc] [clang] [llvm] [libunwind] [clang-tools-extra] [compiler-rt] [Driver, CodeGen] Support -mtls-dialect= (PR #79256)

2024-01-25 Thread Fangrui Song via lldb-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79256

>From be08e64c2c1f433b017185ce78525ad097e609be Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 21:37:04 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Basic/CodeGenOptions.def |  3 +++
 clang/include/clang/Driver/Options.td|  5 +
 clang/lib/CodeGen/BackendUtil.cpp|  1 +
 clang/lib/Driver/ToolChains/Clang.cpp| 23 
 clang/test/CodeGen/RISCV/tls-dialect.c   | 13 +++
 clang/test/Driver/tls-dialect.c  | 19 
 6 files changed, 64 insertions(+)
 create mode 100644 clang/test/CodeGen/RISCV/tls-dialect.c
 create mode 100644 clang/test/Driver/tls-dialect.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 2f2e45d5cf63df..7c0bfe32849614 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -369,6 +369,9 @@ ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibr
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Whether to enable TLSDESC. AArch64 enables TLSDESC regardless of this 
value.
+CODEGENOPT(EnableTLSDESC, 1, 0)
+
 /// Bit size of immediate TLS offsets (0 == use the default).
 VALUE_CODEGENOPT(TLSSize, 8, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748faca..773bc1dcda01d5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4419,6 +4419,8 @@ def mtls_size_EQ : Joined<["-"], "mtls-size=">, 
Group,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 
256TB, needs -mcmodel=large)">,
   MarshallingInfoInt>;
+def mtls_dialect_EQ : Joined<["-"], "mtls-dialect=">, Group,
+  Flags<[TargetSpecific]>, HelpText<"Which thread-local storage dialect to use 
for dynamic accesses of TLS variables">;
 def mimplicit_it_EQ : Joined<["-"], "mimplicit-it=">, Group;
 def mdefault_build_attributes : Joined<["-"], "mdefault-build-attributes">, 
Group;
 def mno_default_build_attributes : Joined<["-"], 
"mno-default-build-attributes">, Group;
@@ -7066,6 +7068,9 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
   MarshallingInfoEnum, "Enabled">;
 
+def enable_tlsdesc : Flag<["-"], "enable-tlsdesc">,
+  MarshallingInfoFlag>;
+
 } // let Visibility = [CC1Option]
 
 
//===--===//
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc17..7877e20d77f772 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -401,6 +401,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.UniqueBasicBlockSectionNames =
   CodeGenOpts.UniqueBasicBlockSectionNames;
   Options.TLSSize = CodeGenOpts.TLSSize;
+  Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5dc614e11aab59..93fd579eb92ba5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5822,6 +5822,29 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ)) {
+StringRef V = A->getValue();
+bool SupportedArgument = false, EnableTLSDESC = false;
+bool Unsupported = !Triple.isOSBinFormatELF();
+if (Triple.isRISCV()) {
+  SupportedArgument = V == "desc" || V == "trad";
+  EnableTLSDESC = V == "desc";
+} else if (Triple.isX86()) {
+  SupportedArgument = V == "gnu";
+} else {
+  Unsupported = true;
+}
+if (Unsupported) {
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << A->getSpelling() << TripleStr;
+} else if (!SupportedArgument) {
+  D.Diag(diag::err_drv_unsupported_option_argument_for_target)
+  << A->getSpelling() << V << TripleStr;
+} else if (EnableTLSDESC) {
+  CmdArgs.push_back("-enable-tlsdesc");
+}
+  }
+
   // Add the target cpu
   std::string CPU = getCPUName(D, Args, Triple, /*FromAs*/ false);
   if (!CPU.empty()) {
diff --git a/clang/test/CodeGen/RISCV

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

2024-01-25 Thread Bryce Wilson via lldb-commits

Bryce-MW wrote:

I think the fail on Windows is not related. Hopefully a merge fixes it...

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


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

2024-01-25 Thread Bryce Wilson via lldb-commits

https://github.com/Bryce-MW updated 
https://github.com/llvm/llvm-project/pull/77964

>From d4c312b9dbf447d0a53dda0e6cdc482bd908430b Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Fri, 12 Jan 2024 16:01:32 -0600
Subject: [PATCH 01/15] [X86] Use RORX over SHR imm

---
 llvm/lib/Target/X86/X86InstrShiftRotate.td |  78 ++
 llvm/test/CodeGen/X86/atomic-unordered.ll  |   3 +-
 llvm/test/CodeGen/X86/bmi2.ll  |   6 +-
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll  |   3 +-
 llvm/test/CodeGen/X86/pr35636.ll   |   4 +-
 llvm/test/CodeGen/X86/vector-trunc-ssat.ll | 116 ++---
 6 files changed, 143 insertions(+), 67 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrShiftRotate.td 
b/llvm/lib/Target/X86/X86InstrShiftRotate.td
index f951894db1890cd..238e8e9b6e97f30 100644
--- a/llvm/lib/Target/X86/X86InstrShiftRotate.td
+++ b/llvm/lib/Target/X86/X86InstrShiftRotate.td
@@ -879,6 +879,26 @@ let Predicates = [HasBMI2, HasEGPR, In64BitMode] in {
   defm SHLX64 : bmi_shift<"shlx{q}", GR64, i64mem, "_EVEX">, T8, PD, REX_W, 
EVEX;
 }
 
+
+def immle16_8 : ImmLeaf;
+def immle32_8 : ImmLeaf;
+def immle64_8 : ImmLeaf;
+def immle32_16 : ImmLeaf;
+def immle64_16 : ImmLeaf;
+def immle64_32 : ImmLeaf;
+
 let Predicates = [HasBMI2] in {
   // Prefer RORX which is non-destructive and doesn't update EFLAGS.
   let AddedComplexity = 10 in {
@@ -891,6 +911,64 @@ let Predicates = [HasBMI2] in {
   (RORX32ri GR32:$src, (ROT32L2R_imm8 imm:$shamt))>;
 def : Pat<(rotl GR64:$src, (i8 imm:$shamt)),
   (RORX64ri GR64:$src, (ROT64L2R_imm8 imm:$shamt))>;
+
+// A right shift by less than a smaller register size that is then
+// truncated to that register size can be replaced by RORX to
+// preserve flags with the same execution cost
+
+def : Pat<(i8 (trunc (srl GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR16:$src, (i8 immle16_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri (INSERT_SUBREG (i32 (IMPLICIT_DEF)), 
GR16:$src, sub_16bit), imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR32:$src, (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra GR64:$src, (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR32:$src, (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32ri GR32:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra GR64:$src, (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc (srl GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+def : Pat<(i32 (trunc (sra GR64:$src, (i8 immle64_32:$shamt,
+  (EXTRACT_SUBREG (RORX64ri GR64:$src, imm:$shamt), sub_32bit)>;
+
+
+// Can't expand the load
+def : Pat<(i8 (trunc (srl (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi32 addr:$src), (i8 immle32_8:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (srl (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+def : Pat<(i8 (trunc (sra (loadi64 addr:$src), (i8 immle64_8:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_8bit)>;
+
+
+def : Pat<(i16 (trunc (srl (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi32 addr:$src), (i8 immle32_16:$shamt,
+  (EXTRACT_SUBREG (RORX32mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (srl (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+def : Pat<(i16 (trunc (sra (loadi64 addr:$src), (i8 immle64_16:$shamt,
+  (EXTRACT_SUBREG (RORX64mi addr:$src, imm:$shamt), sub_16bit)>;
+
+def : Pat<(i32 (trunc (

[Lldb-commits] [llvm] [lld] [libc] [lldb] [flang] [compiler-rt] [clang] [clang-tools-extra] [libcxx] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-25 Thread via lldb-commits

pirama-arumuga-nainar wrote:

@llvm/clang-vendors Adding clang vendors.  FYI, this change expands error 
reporting on invalid version numbers to all target triples (This was previously 
restricted to Android triples).  This can have potential downstream impact.  
Please review/test and let us know if this breaks any valid usages.

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


[Lldb-commits] [libunwind] [clang] [lld] [libcxx] [flang] [mlir] [compiler-rt] [libc] [clang-tools-extra] [llvm] [lldb] [Driver, CodeGen] Support -mtls-dialect= (PR #79256)

2024-01-25 Thread Paul Kirth via lldb-commits

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

LGTM

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


[Lldb-commits] [clang] [lld] [libcxx] [flang] [compiler-rt] [libc] [clang-tools-extra] [llvm] [lldb] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

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

jhuber6 wrote:

> User confusion is only part of the issue here. With any single GPU choice we 
> would still potentially produce a nonworking binary, if our GPU choice does 
> not match what the user wants.
>
> "all GPUs" has the advantage of always producing the binary that's guaranteed 
> to work. Granted, in the case of multiple GPUs it comes with the compilation 
> time overhead, but I think it's a better trade-off than compiling faster, but 
> not working. If the overhead is unacceptable, then we can tweak the build, 
> but in that case, the user may as well just specify the desired architectures 
> explicitly.

I think the semantics of `native` on other architectures are clear enough here. 
This combined with the fact that using `-march=native` will error out in the 
case of no GPUs available, or give a warning if more than one GPU is available, 
should be sufficiently clear what it's doing. This obviously falls apart if you 
compile with `-march=native` and then move it off of the system you compiled it 
for, but the same applies for standard x64 binaries I feel.

Realistically, very, very few casual users are going to be using direct NVPTX 
targeting. The current use-case is for building tests directly for the GPU 
without needing to handle calling `amdgpu-arch` and `nvptx-arch` manually in 
CMake. If I had this in, then I could simplify a lot of CMake code in my `libc` 
project by just letting the compiler handle the autodetection. Then one less 
random program dependency is removed from the build process. AMDGPU already has 
`-mcpu=native` so I'd like NVPTX to match if possible.

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


[Lldb-commits] [clang-tools-extra] [libc] [llvm] [compiler-rt] [lld] [libcxx] [lldb] [flang] [clang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Artem Belevich via lldb-commits

Artem-B wrote:

> This is what we already do for `--offload-arch=native` on CUDA, but this is 
> somewhat tangential. I've updated this patch to present the warning in the 
> case of multiply GPUs being detected, so I don't think there's a concern here 
> with the user being confused. If they have two GPUs, the warning will tell 
> them which one it's using with the correct `sm_` value to specify it manually 
> if they so wish. 

User confusion is only part of the issue here. With any single GPU choice we 
would still potentially produce a nonworking binary, if our GPU choice does not 
match what the user wants.

"all GPUs" has the advantage of always producing the binary that's guaranteed 
to work. Granted, in the case of multiple GPUs it comes with the compilation 
time overhead, but I think it's a better trade-off than compiling faster, but 
not working. If the overhead is unacceptable, *then* we can tweak the build, 
but in that case, the user may as well just specify the desired architectures 
explicitly.

> If there is only one GPU on the system, it should be obvious that it's going 
> to be targeted.
This case works the same with either approach.


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


[Lldb-commits] [compiler-rt] [flang] [libcxx] [libunwind] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [libc] [lld] [ELF] Implement R_RISCV_TLSDESC for RISC-V (PR #79239)

2024-01-25 Thread Fangrui Song via lldb-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/79239

>From 3725fa4eac3d3d946289d7eb7213f3a1751a2770 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Tue, 23 Jan 2024 17:58:07 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp| 158 +
 lld/ELF/Relocations.cpp   |  25 ++--
 lld/test/ELF/riscv-tlsdesc-gd-mixed.s |  26 
 lld/test/ELF/riscv-tlsdesc-relax.s| 125 +
 lld/test/ELF/riscv-tlsdesc.s  | 192 ++
 5 files changed, 492 insertions(+), 34 deletions(-)
 create mode 100644 lld/test/ELF/riscv-tlsdesc-gd-mixed.s
 create mode 100644 lld/test/ELF/riscv-tlsdesc-relax.s
 create mode 100644 lld/test/ELF/riscv-tlsdesc.s

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index d7d3d3e4781497..67d7e2562e9b17 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -61,6 +61,7 @@ enum Op {
   AUIPC = 0x17,
   JALR = 0x67,
   LD = 0x3003,
+  LUI = 0x37,
   LW = 0x2003,
   SRLI = 0x5013,
   SUB = 0x4033,
@@ -73,6 +74,7 @@ enum Reg {
   X_T0 = 5,
   X_T1 = 6,
   X_T2 = 7,
+  X_A0 = 10,
   X_T3 = 28,
 };
 
@@ -102,6 +104,26 @@ static uint32_t setLO12_S(uint32_t insn, uint32_t imm) {
  (extractBits(imm, 4, 0) << 7);
 }
 
+namespace {
+struct SymbolAnchor {
+  uint64_t offset;
+  Defined *d;
+  bool end; // true for the anchor of st_value+st_size
+};
+} // namespace
+
+struct elf::RISCVRelaxAux {
+  // This records symbol start and end offsets which will be adjusted according
+  // to the nearest relocDeltas element.
+  SmallVector anchors;
+  // For relocations[i], the actual offset is r_offset - (i ? relocDeltas[i-1] 
:
+  // 0).
+  std::unique_ptr relocDeltas;
+  // For relocations[i], the actual type is relocTypes[i].
+  std::unique_ptr relocTypes;
+  SmallVector writes;
+};
+
 RISCV::RISCV() {
   copyRel = R_RISCV_COPY;
   pltRel = R_RISCV_JUMP_SLOT;
@@ -119,6 +141,7 @@ RISCV::RISCV() {
 tlsGotRel = R_RISCV_TLS_TPREL32;
   }
   gotRel = symbolicRel;
+  tlsDescRel = R_RISCV_TLSDESC;
 
   // .got[0] = _DYNAMIC
   gotHeaderEntriesNum = 1;
@@ -187,6 +210,8 @@ int64_t RISCV::getImplicitAddend(const uint8_t *buf, 
RelType type) const {
   case R_RISCV_JUMP_SLOT:
 // These relocations are defined as not having an implicit addend.
 return 0;
+  case R_RISCV_TLSDESC:
+return config->is64 ? read64le(buf + 8) : read32le(buf + 4);
   }
 }
 
@@ -295,6 +320,12 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol 
&s,
   case R_RISCV_PCREL_LO12_I:
   case R_RISCV_PCREL_LO12_S:
 return R_RISCV_PC_INDIRECT;
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+  case R_RISCV_TLSDESC_ADD_LO12:
+return R_TLSDESC_PC;
+  case R_RISCV_TLSDESC_CALL:
+return R_TLSDESC_CALL;
   case R_RISCV_TLS_GD_HI20:
 return R_TLSGD_PC;
   case R_RISCV_TLS_GOT_HI20:
@@ -419,6 +450,7 @@ void RISCV::relocate(uint8_t *loc, const Relocation &rel, 
uint64_t val) const {
 
   case R_RISCV_GOT_HI20:
   case R_RISCV_PCREL_HI20:
+  case R_RISCV_TLSDESC_HI20:
   case R_RISCV_TLS_GD_HI20:
   case R_RISCV_TLS_GOT_HI20:
   case R_RISCV_TPREL_HI20:
@@ -430,6 +462,8 @@ void RISCV::relocate(uint8_t *loc, const Relocation &rel, 
uint64_t val) const {
   }
 
   case R_RISCV_PCREL_LO12_I:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+  case R_RISCV_TLSDESC_ADD_LO12:
   case R_RISCV_TPREL_LO12_I:
   case R_RISCV_LO12_I: {
 uint64_t hi = (val + 0x800) >> 12;
@@ -513,29 +547,113 @@ void RISCV::relocate(uint8_t *loc, const Relocation 
&rel, uint64_t val) const {
 break;
 
   case R_RISCV_RELAX:
-return; // Ignored (for now)
-
+return;
+  case R_RISCV_TLSDESC:
+// The addend is stored in the second word.
+if (config->is64)
+  write64le(loc + 8, val);
+else
+  write32le(loc + 4, val);
+break;
   default:
 llvm_unreachable("unknown relocation");
   }
 }
 
+static void tlsdescToIe(uint8_t *loc, const Relocation &rel, uint64_t val) {
+  switch (rel.type) {
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+write32le(loc, 0x0013); // nop
+return;
+  case R_RISCV_TLSDESC_ADD_LO12:
+write32le(loc, utype(AUIPC, X_A0, hi20(val))); // auipc a0,
+return;
+  case R_RISCV_TLSDESC_CALL:
+if (config->is64)
+  write32le(loc, itype(LD, X_A0, X_A0, lo12(val))); // ld a0,(a0)
+else
+  write32le(loc, itype(LW, X_A0, X_A0, lo12(val))); // lw a0,(a0)
+return;
+  default:
+llvm_unreachable("unsupported relocation for TLSDESC to IE relaxation");
+  }
+}
+
+static void tlsdescToLe(uint8_t *loc, const Relocation &rel, uint64_t val) {
+  switch (rel.type) {
+  case R_RISCV_TLSDESC_HI20:
+  case R_RISCV_TLSDESC_LOAD_LO12:
+write32le(loc, 0x0013); // nop
+return;
+  case R_RISCV_TLSDESC_A

  1   2   >