[llvm-branch-commits] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-11 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/95129

This patch is a functional change.
https://discourse.llvm.org/t/analyzer-rfc-taming-z3-query-times/79520

As a result of this patch, individual Z3 queries in refutation will be
bound by 300ms. Every report equivalence class will be processed in
at most 1 second.

The heuristic should have only really marginal observable impact -
except for the cases when we had big report eqclasses with long-running
(15s) Z3 queries, where previously CSA effectively halted.
After this patch, CSA will tackle such extreme cases as well.



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


[llvm-branch-commits] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balazs Benics (steakhal)


Changes

This patch is a functional change.
https://discourse.llvm.org/t/analyzer-rfc-taming-z3-query-times/79520

As a result of this patch, individual Z3 queries in refutation will be
bound by 300ms. Every report equivalence class will be processed in
at most 1 second.

The heuristic should have only really marginal observable impact -
except for the cases when we had big report eqclasses with long-running
(15s) Z3 queries, where previously CSA effectively halted.
After this patch, CSA will tackle such extreme cases as well.


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


6 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def (+13) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h 
(+32-8) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+10-2) 
- (modified) clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp (+52-11) 
- (modified) clang/test/Analysis/analyzer-config.c (+2) 
- (modified) clang/unittests/StaticAnalyzer/Z3CrosscheckOracleTest.cpp 
(+100-16) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index f008c9c581d95..201153c886966 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -184,6 +184,19 @@ ANALYZER_OPTION(bool, ShouldCrosscheckWithZ3, 
"crosscheck-with-z3",
 "constraint manager backend.",
 false)
 
+ANALYZER_OPTION(
+unsigned, Z3CrosscheckTimeoutThreshold,
+"crosscheck-with-z3-timeout-threshold",
+"Set a timeout for individual Z3 queries in milliseconds. "
+"Set 0 for no timeout.", 300)
+
+ANALYZER_OPTION(
+unsigned, Z3CrosscheckRLimitThreshold,
+"crosscheck-with-z3-rlimit-threshold",
+"Set the Z3 resource limit threshold. This sets a deterministic cutoff "
+"point for Z3 queries, as longer queries usually consume more resources. "
+"Set 0 for unlimited.", 400'000)
+
 ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile,
 "report-in-main-source-file",
 "Whether or not the diagnostic report should be always "
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
index 3ec59e3037363..524337d378aef 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
@@ -25,8 +25,11 @@ class Z3CrosscheckVisitor final : public BugReporterVisitor {
 public:
   struct Z3Result {
 std::optional IsSAT = std::nullopt;
+unsigned Z3QueryTimeMilliseconds = 0;
+unsigned UsedRLimit = 0;
   };
-  explicit Z3CrosscheckVisitor(Z3CrosscheckVisitor::Z3Result &Result);
+  Z3CrosscheckVisitor(Z3CrosscheckVisitor::Z3Result &Result,
+  const AnalyzerOptions &Opts);
 
   void Profile(llvm::FoldingSetNodeID &ID) const override;
 
@@ -44,21 +47,42 @@ class Z3CrosscheckVisitor final : public BugReporterVisitor 
{
   /// Holds the constraints in a given path.
   ConstraintMap Constraints;
   Z3Result &Result;
+  const AnalyzerOptions &Opts;
 };
 
 /// The oracle will decide if a report should be accepted or rejected based on
-/// the results of the Z3 solver.
+/// the results of the Z3 solver and the statistics of the queries of a report
+/// equivalenece class.
 class Z3CrosscheckOracle {
 public:
+  explicit Z3CrosscheckOracle(const AnalyzerOptions &Opts) : Opts(Opts) {}
   enum Z3Decision {
-AcceptReport, // The report was SAT.
-RejectReport, // The report was UNSAT or UNDEF.
+AcceptReport,  // The report was SAT.
+RejectReport,  // The report was UNSAT or UNDEF.
+RejectEQClass, // The heuristic suggests to skip the current eqclass.
   };
 
-  /// Makes a decision for accepting or rejecting the report based on the
-  /// result of the corresponding Z3 query.
-  static Z3Decision
-  interpretQueryResult(const Z3CrosscheckVisitor::Z3Result &Query);
+  /// Updates the internal state with the new Z3Result and makes a decision how
+  /// to proceed:
+  /// - Accept the report if the Z3Result was SAT.
+  /// - Suggest dropping the report equvalence class based on the accumulated
+  ///   statistics.
+  /// - Otherwise, reject the report if the Z3Result was UNSAT or UNDEF.
+  ///
+  /// Conditions for dropping the equivalence class:
+  /// - Accumulative time spent in Z3 checks is more than 700ms in the eqclass.
+  /// - Hit the 300ms query timeout in the report eqclass.
+  /// - Hit the 400'000 rlimit in the report eqclass.
+  ///
+  /// Refer to
+  /// https://discourse.llvm.org/t/analyzer-rfc-taming-z3-query-times/79520 to
+  /// see why this heuristic was chosen.
+  Z3Decis

[llvm-branch-commits] [clang] 721d2cf - Revert "Revert "[llvm][IR] Extend BranchWeightMetadata to track provenance of…"

2024-06-11 Thread via llvm-branch-commits

Author: Paul Kirth
Date: 2024-06-11T09:08:39-07:00
New Revision: 721d2cf442610e564543f64b98566096b65ccd90

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

LOG: Revert "Revert "[llvm][IR] Extend BranchWeightMetadata to track provenance 
of…"

This reverts commit 607afa0b6375e4837fef298a798f5534e783d777.

Added: 


Modified: 
clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
llvm/docs/BranchWeightMetadata.rst
llvm/include/llvm/IR/MDBuilder.h
llvm/include/llvm/IR/ProfDataUtils.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/IR/Instruction.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/MDBuilder.cpp
llvm/lib/IR/Metadata.cpp
llvm/lib/IR/ProfDataUtils.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/LoopPeel.cpp
llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
llvm/test/Transforms/LowerExpectIntrinsic/expect-with-probability.ll
llvm/test/Transforms/LowerExpectIntrinsic/expect_nonboolean.ll
llvm/test/Transforms/LowerExpectIntrinsic/phi_merge.ll
llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll
llvm/test/Transforms/LowerExpectIntrinsic/phi_tern.ll
llvm/test/Transforms/LowerExpectIntrinsic/phi_unexpect.ll
llvm/test/Transforms/PhaseOrdering/AArch64/hoist-runtime-checks.ll

Removed: 




diff  --git a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp 
b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
index fb236aeb982e0..81d9334356520 100644
--- a/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
+++ b/clang/test/CodeGenCXX/attr-likelihood-if-vs-builtin-expect.cpp
@@ -221,5 +221,5 @@ void tu2(int &i) {
   }
 }
 
-// CHECK: [[BW_LIKELY]] = !{!"branch_weights", i32 2000, i32 1}
-// CHECK: [[BW_UNLIKELY]] = !{!"branch_weights", i32 1, i32 2000}
+// CHECK: [[BW_LIKELY]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
+// CHECK: [[BW_UNLIKELY]] = !{!"branch_weights", !"expected", i32 1, i32 2000}

diff  --git a/llvm/docs/BranchWeightMetadata.rst 
b/llvm/docs/BranchWeightMetadata.rst
index 522f37cdad4fc..62204753e29b0 100644
--- a/llvm/docs/BranchWeightMetadata.rst
+++ b/llvm/docs/BranchWeightMetadata.rst
@@ -28,11 +28,14 @@ Supported Instructions
 
 Metadata is only assigned to the conditional branches. There are two extra
 operands for the true and the false branch.
+We optionally track if the metadata was added by ``__builtin_expect`` or
+``__builtin_expect_with_probability`` with an optional field ``!"expected"``.
 
 .. code-block:: none
 
   !0 = !{
 !"branch_weights",
+[ !"expected", ]
 i32 ,
 i32 
   }
@@ -47,6 +50,7 @@ is always case #0).
 
   !0 = !{
 !"branch_weights",
+[ !"expected", ]
 i32 
 [ , i32  ... ]
   }
@@ -60,6 +64,7 @@ Branch weights are assigned to every destination.
 
   !0 = !{
 !"branch_weights",
+[ !"expected", ]
 i32 
 [ , i32  ... ]
   }
@@ -75,6 +80,7 @@ block and entry counts which may not be accurate with 
sampling.
 
   !0 = !{
 !"branch_weights",
+[ !"expected", ]
 i32 
   }
 
@@ -95,6 +101,7 @@ is used.
 
   !0 = !{
 !"branch_weights",
+[ !"expected", ]
 i32 
 [ , i32  ]
   }

diff  --git a/llvm/include/llvm/IR/MDBuilder.h 
b/llvm/include/llvm/IR/MDBuilder.h
index 3265589b7c8df..e02ec8f5a3d8b 100644
--- a/llvm/include/llvm/IR/MDBuilder.h
+++ b/llvm/include/llvm/IR/MDBuilder.h
@@ -59,7 +59,11 @@ class MDBuilder {
   //===--===//
 
   /// Return metadata containing two branch weights.
-  MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
+  /// @param TrueWeight the weight of the true branch
+  /// @param FalseWeight the weight of the false branch
+  /// @param Do these weights come from __builtin_expect*
+  MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight,
+  bool IsExpected = false);
 
   /// Return metadata containing two branch weights, with significant bias
   /// towards `true` destination.
@@ -70,7 +74,10 @@ class MDBuilder {
   MDNode *createUnlikelyBranchWeights();
 
   /// Return metadata containing a number of branch weights.
-  MDNode *createBranchWeights(ArrayRef Weights);
+  

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds zoned_time deduction guides. (PR #95139)

2024-06-11 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/95139

Completes
- LWG3232 Inconsistency in zoned_time  deduction guides
- LWG3294 zoned_time  deduction guides misinterprets stringchar*

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones

>From 2d255301fcb3ade2b4a39810355c070b659f3b21 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Adds zoned_time deduction guides.

Completes
- LWG3232 Inconsistency in zoned_time  deduction guides
- LWG3294 zoned_time  deduction guides misinterprets stringchar*

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
---
 libcxx/docs/Status/Cxx20Issues.csv|   4 +-
 libcxx/include/__chrono/zoned_time.h  |  28 ++
 .../time.zone.zonedtime/deduction.pass.cpp| 285 ++
 3 files changed, 315 insertions(+), 2 deletions(-)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.zonedtime/deduction.pass.cpp

diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index 5051a2089c98e..a288d1add33e2 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -167,7 +167,7 @@
 "`3218 `__","Modifier for ``%d``\  parse flag does 
not match POSIX and ``format``\  specification","Belfast","","","|chrono| 
|format|"
 "`3224 `__","``zoned_time``\  constructor from 
``TimeZonePtr``\  does not specify initialization of ``tp_``\ 
","Belfast","|Complete|","19.0","|chrono|"
 "`3230 `__","Format specifier ``%y/%Y``\  is 
missing locale alternative versions","Belfast","|Complete|","16.0","|chrono| 
|format|"
-"`3232 `__","Inconsistency in ``zoned_time``\  
deduction guides","Belfast","","","|chrono|"
+"`3232 `__","Inconsistency in ``zoned_time``\  
deduction guides","Belfast","|Complete|","19.0","|chrono|"
 "`3222 `__","P0574R1 introduced preconditions on 
non-existent parameters","Belfast","",""
 "`3221 `__","Result of ``year_month``\  arithmetic 
with ``months``\  is ambiguous","Belfast","|Complete|","8.0"
 "`3235 `__","``parse``\  manipulator without 
abbreviation is not callable","Belfast","",""
@@ -225,7 +225,7 @@
 "`3286 `__","``ranges::size``\  is not required to 
be valid after a call to ``ranges::begin``\  on an input 
range","Prague","|Complete|","15.0","|ranges|"
 "`3291 `__","``iota_view::iterator``\  has the 
wrong ``iterator_category``\ ","Prague","|Complete|","15.0","|ranges|"
 "`3292 `__","``iota_view``\  is 
under-constrained","Prague","|Complete|","15.0","|ranges|"
-"`3294 `__","``zoned_time``\  deduction guides 
misinterprets ``string``\ /``char*``\ ","Prague","","","|chrono|"
+"`3294 `__","``zoned_time``\  deduction guides 
misinterprets ``string``\ /``char*``\ ","Prague","|Complete|","19.0","|chrono|"
 "`3296 `__","Inconsistent default argument for 
``basic_regex<>::assign``\ ","Prague","|Complete|",""
 "`3299 `__","Pointers don't need customized 
iterator behavior","Prague","|Complete|","15.0","|ranges|"
 "`3300 `__","Non-array ``ssize``\  overload is 
underconstrained","Prague","|Nothing To Do|",""
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index 169efb8e9d6f3..33e0ac0603a6e 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -25,6 +25,8 @@
 #  include <__config>
 #  include <__fwd/string_view.h>
 #  include <__type_traits/common_type.h>
+#  include <__type_traits/conditional.h>
+#  include <__type_traits/remove_cvref.h>
 #  include <__utility/move.h>
 
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -176,6 +178,32 @@ class zoned_time {
   sys_time __tp_;
 };
 
+zoned_time() -> zoned_time;
+
+template 
+zoned_time(sys_time<_Duration>) -> zoned_time>;
+
+template 
+using __time_zone_representation =
+conditional_t,
+  const time_zone*,
+  remove_cvref_t<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&) -> zoned_time>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = 
choose::earliest)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
 } // namespace chrono
 
 #  endif // _LIBCPP_STD_VER >= 20 &

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds zoned_time deduction guides. (PR #95139)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)


Changes

Completes
- LWG3232 Inconsistency in zoned_time  deduction guides
- LWG3294 zoned_time  deduction guides misinterprets stringchar*

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones

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


3 Files Affected:

- (modified) libcxx/docs/Status/Cxx20Issues.csv (+2-2) 
- (modified) libcxx/include/__chrono/zoned_time.h (+28) 
- (added) libcxx/test/std/time/time.zone/time.zone.zonedtime/deduction.pass.cpp 
(+285) 


``diff
diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index 5051a2089c98e..a288d1add33e2 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -167,7 +167,7 @@
 "`3218 `__","Modifier for ``%d``\  parse flag does 
not match POSIX and ``format``\  specification","Belfast","","","|chrono| 
|format|"
 "`3224 `__","``zoned_time``\  constructor from 
``TimeZonePtr``\  does not specify initialization of ``tp_``\ 
","Belfast","|Complete|","19.0","|chrono|"
 "`3230 `__","Format specifier ``%y/%Y``\  is 
missing locale alternative versions","Belfast","|Complete|","16.0","|chrono| 
|format|"
-"`3232 `__","Inconsistency in ``zoned_time``\  
deduction guides","Belfast","","","|chrono|"
+"`3232 `__","Inconsistency in ``zoned_time``\  
deduction guides","Belfast","|Complete|","19.0","|chrono|"
 "`3222 `__","P0574R1 introduced preconditions on 
non-existent parameters","Belfast","",""
 "`3221 `__","Result of ``year_month``\  arithmetic 
with ``months``\  is ambiguous","Belfast","|Complete|","8.0"
 "`3235 `__","``parse``\  manipulator without 
abbreviation is not callable","Belfast","",""
@@ -225,7 +225,7 @@
 "`3286 `__","``ranges::size``\  is not required to 
be valid after a call to ``ranges::begin``\  on an input 
range","Prague","|Complete|","15.0","|ranges|"
 "`3291 `__","``iota_view::iterator``\  has the 
wrong ``iterator_category``\ ","Prague","|Complete|","15.0","|ranges|"
 "`3292 `__","``iota_view``\  is 
under-constrained","Prague","|Complete|","15.0","|ranges|"
-"`3294 `__","``zoned_time``\  deduction guides 
misinterprets ``string``\ /``char*``\ ","Prague","","","|chrono|"
+"`3294 `__","``zoned_time``\  deduction guides 
misinterprets ``string``\ /``char*``\ ","Prague","|Complete|","19.0","|chrono|"
 "`3296 `__","Inconsistent default argument for 
``basic_regex<>::assign``\ ","Prague","|Complete|",""
 "`3299 `__","Pointers don't need customized 
iterator behavior","Prague","|Complete|","15.0","|ranges|"
 "`3300 `__","Non-array ``ssize``\  overload is 
underconstrained","Prague","|Nothing To Do|",""
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index 169efb8e9d6f3..33e0ac0603a6e 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -25,6 +25,8 @@
 #  include <__config>
 #  include <__fwd/string_view.h>
 #  include <__type_traits/common_type.h>
+#  include <__type_traits/conditional.h>
+#  include <__type_traits/remove_cvref.h>
 #  include <__utility/move.h>
 
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -176,6 +178,32 @@ class zoned_time {
   sys_time __tp_;
 };
 
+zoned_time() -> zoned_time;
+
+template 
+zoned_time(sys_time<_Duration>) -> zoned_time>;
+
+template 
+using __time_zone_representation =
+conditional_t,
+  const time_zone*,
+  remove_cvref_t<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&) -> zoned_time>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = 
choose::earliest)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
+template 
+zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
+-> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
+
 } // namespace chrono
 
 #  endif // _LIBCPP_STD_VER >= 20 && 
!defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.zonedtime/deduction.pass.cpp 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/deduction.pass.cpp
new file mode 100644
index 0..b64dbebd235b1
--- /dev/null
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/deduction.pass.cpp
@@ -0,0 +1,285 @@
+//===

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements zoned_time's operator==. (PR #95140)

2024-06-11 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/95140

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1614R2 The Mothership has Landed

>From 86dc932d92a960a102a60801419c8d0624f197aa Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements zoned_time's operator==.

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1614R2 The Mothership has Landed
---
 libcxx/docs/Status/SpaceshipProjects.csv  |  4 +-
 libcxx/include/__chrono/zoned_time.h  |  6 ++
 libcxx/include/chrono |  4 ++
 .../eq.pass.cpp   | 71 +++
 4 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp

diff --git a/libcxx/docs/Status/SpaceshipProjects.csv 
b/libcxx/docs/Status/SpaceshipProjects.csv
index 128b23b0c2c74..74441dcdea496 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -140,7 +140,7 @@ Section,Description,Dependencies,Assignee,Complete
 "| `[class.slice.overview] `_
 | `[slice.ops] `_",| `slice 
`_,None,Hristo Hristov,|Complete|
 - `5.12 Clause 27: Time library 
`_
-| `[time.syn] `_,|,None,Mark de Wever,|In Progress|
+| `[time.syn] `_,|,None,Mark de Wever,|Complete|
 | `[time.duration.comparisons] 
`_, `chrono::duration 
`_, None, Hristo Hristov, |Complete|
 | `[time.point.comparisons] `_, 
`chrono::time_point `_, None, Hristo Hristov, 
|Complete|
 "| `[time.cal.day.nonmembers] `_
@@ -172,7 +172,7 @@ Section,Description,Dependencies,Assignee,Complete
 | `year_month_weekday `_
 | `year_month_weekday_last `_",None,Hristo 
Hristov,|Complete|
 `[time.zone.nonmembers] 
`_,"`chrono::time_zone`",,Mark de 
Wever,|Complete|
-`[time.zone.zonedtime.nonmembers] 
`_,"`chrono::zoned_time`",A 
 implementation,Mark de Wever,|In Progress|
+`[time.zone.zonedtime.nonmembers] 
`_,"`chrono::zoned_time`",,Mark
 de Wever,|Complete|
 `[time.zone.leap.nonmembers] 
`_,"`chrono::time_leap_seconds`",,Mark
 de Wever,|Complete|
 `[time.zone.link.nonmembers] 
`_,"`chrono::time_zone_link`",,Mark
 de Wever,|Complete|
 - `5.13 Clause 28: Localization library 
`_
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index 33e0ac0603a6e..db5e67135d844 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -204,6 +204,12 @@ template 
 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
 -> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
 
+template 
+_LIBCPP_HIDE_FROM_ABI bool
+operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const 
zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
+  return __lhs.get_time_zone() == __rhs.get_time_zone() && 
__lhs.get_sys_time() == __rhs.get_sys_time();
+}
+
 } // namespace chrono
 
 #  endif // _LIBCPP_STD_VER >= 20 && 
!defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 026e920342e1e..df7ebf45bd907 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -793,6 +793,10 @@ template struct zoned_traits;
 template 
  // C++20
 class zoned_time;
 
+template  
  // C++20
+  bool operator==(const zoned_time& x,
+  const zoned_time& y);
+
 // [time.zone.leap], leap second support
 class leap_second {
  // C++20
 public:
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
new file mode 100644
index 0..2ccb060d24ee6
--- /dev/null
+++ 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
@@ -0,0 +1,71 @@
+//===--===//
+//
+// Part of the LLVM Project, under the 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements zoned_time's operator==. (PR #95140)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)


Changes

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1614R2 The Mothership has Landed

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


4 Files Affected:

- (modified) libcxx/docs/Status/SpaceshipProjects.csv (+2-2) 
- (modified) libcxx/include/__chrono/zoned_time.h (+6) 
- (modified) libcxx/include/chrono (+4) 
- (added) 
libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
 (+71) 


``diff
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv 
b/libcxx/docs/Status/SpaceshipProjects.csv
index 128b23b0c2c74..74441dcdea496 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -140,7 +140,7 @@ Section,Description,Dependencies,Assignee,Complete
 "| `[class.slice.overview] `_
 | `[slice.ops] `_",| `slice 
`_,None,Hristo Hristov,|Complete|
 - `5.12 Clause 27: Time library 
`_
-| `[time.syn] `_,|,None,Mark de Wever,|In Progress|
+| `[time.syn] `_,|,None,Mark de Wever,|Complete|
 | `[time.duration.comparisons] 
`_, `chrono::duration 
`_, None, Hristo Hristov, |Complete|
 | `[time.point.comparisons] `_, 
`chrono::time_point `_, None, Hristo Hristov, 
|Complete|
 "| `[time.cal.day.nonmembers] `_
@@ -172,7 +172,7 @@ Section,Description,Dependencies,Assignee,Complete
 | `year_month_weekday `_
 | `year_month_weekday_last `_",None,Hristo 
Hristov,|Complete|
 `[time.zone.nonmembers] 
`_,"`chrono::time_zone`",,Mark de 
Wever,|Complete|
-`[time.zone.zonedtime.nonmembers] 
`_,"`chrono::zoned_time`",A 
 implementation,Mark de Wever,|In Progress|
+`[time.zone.zonedtime.nonmembers] 
`_,"`chrono::zoned_time`",,Mark
 de Wever,|Complete|
 `[time.zone.leap.nonmembers] 
`_,"`chrono::time_leap_seconds`",,Mark
 de Wever,|Complete|
 `[time.zone.link.nonmembers] 
`_,"`chrono::time_zone_link`",,Mark
 de Wever,|Complete|
 - `5.13 Clause 28: Localization library 
`_
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index 33e0ac0603a6e..db5e67135d844 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -204,6 +204,12 @@ template 
 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
 -> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
 
+template 
+_LIBCPP_HIDE_FROM_ABI bool
+operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const 
zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
+  return __lhs.get_time_zone() == __rhs.get_time_zone() && 
__lhs.get_sys_time() == __rhs.get_sys_time();
+}
+
 } // namespace chrono
 
 #  endif // _LIBCPP_STD_VER >= 20 && 
!defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 026e920342e1e..df7ebf45bd907 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -793,6 +793,10 @@ template struct zoned_traits;
 template 
  // C++20
 class zoned_time;
 
+template  
  // C++20
+  bool operator==(const zoned_time& x,
+  const zoned_time& y);
+
 // [time.zone.leap], leap second support
 class leap_second {
  // C++20
 public:
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
new file mode 100644
index 0..2ccb060d24ee6
--- /dev/null
+++ 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.nonmembers/eq.pass.cpp
@@ -0,0 +1,71 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: has-unix-headers
+// 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements zoned_seconds typedef. (PR #95141)

2024-06-11 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/95141

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones

>From e12d4507b0cad67dec69aa8d683fb0c5aca82939 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements zoned_seconds typedef.

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
---
 libcxx/include/__chrono/zoned_time.h | 2 ++
 libcxx/include/chrono| 2 ++
 libcxx/modules/std/chrono.inc| 2 --
 .../time.zone/time.zone.zonedtime/types.compile.pass.cpp | 5 +
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index db5e67135d844..d9518ce0a8313 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -204,6 +204,8 @@ template 
 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
 -> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
 
+using zoned_seconds = zoned_time;
+
 template 
 _LIBCPP_HIDE_FROM_ABI bool
 operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const 
zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index df7ebf45bd907..9a6159cf2c4ab 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -793,6 +793,8 @@ template struct zoned_traits;
 template 
  // C++20
 class zoned_time;
 
+using zoned_seconds = zoned_time; 
  // C++20
+
 template  
  // C++20
   bool operator==(const zoned_time& x,
   const zoned_time& y);
diff --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index 89fe7284eb694..3ba3c46150c9c 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -233,9 +233,7 @@ export namespace std {
 // [time.zone.zonedtime], class template zoned_time
 using std::chrono::zoned_time;
 
-#if 0
 using std::chrono::zoned_seconds;
-#endif // if 0
 
 // [time.zone.leap], leap second support
 using std::chrono::leap_second;
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
index f2b198249e73d..91e37d0d02897 100644
--- a/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
@@ -23,6 +23,8 @@
 //zoned_time& operator=(const zoned_time&) = default;
 //
 //  };
+//
+// using zoned_seconds = zoned_time;
 
 #include 
 #include 
@@ -57,3 +59,6 @@ 
static_assert(!std::is_copy_constructible_v>>);
 static_assert(!std::is_copy_assignable_v>>);
 static_assert(!std::is_move_assignable_v>>);
+
+// using zoned_seconds = zoned_time;
+static_assert(std::same_as>);

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements zoned_seconds typedef. (PR #95141)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)


Changes

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones

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


4 Files Affected:

- (modified) libcxx/include/__chrono/zoned_time.h (+2) 
- (modified) libcxx/include/chrono (+2) 
- (modified) libcxx/modules/std/chrono.inc (-2) 
- (modified) 
libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp (+5) 


``diff
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
index db5e67135d844..d9518ce0a8313 100644
--- a/libcxx/include/__chrono/zoned_time.h
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -204,6 +204,8 @@ template 
 zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = 
choose::earliest)
 -> zoned_time, 
__time_zone_representation<_TimeZonePtrOrName>>;
 
+using zoned_seconds = zoned_time;
+
 template 
 _LIBCPP_HIDE_FROM_ABI bool
 operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const 
zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index df7ebf45bd907..9a6159cf2c4ab 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -793,6 +793,8 @@ template struct zoned_traits;
 template 
  // C++20
 class zoned_time;
 
+using zoned_seconds = zoned_time; 
  // C++20
+
 template  
  // C++20
   bool operator==(const zoned_time& x,
   const zoned_time& y);
diff --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index 89fe7284eb694..3ba3c46150c9c 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -233,9 +233,7 @@ export namespace std {
 // [time.zone.zonedtime], class template zoned_time
 using std::chrono::zoned_time;
 
-#if 0
 using std::chrono::zoned_seconds;
-#endif // if 0
 
 // [time.zone.leap], leap second support
 using std::chrono::leap_second;
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp 
b/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
index f2b198249e73d..91e37d0d02897 100644
--- a/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
+++ b/libcxx/test/std/time/time.zone/time.zone.zonedtime/types.compile.pass.cpp
@@ -23,6 +23,8 @@
 //zoned_time& operator=(const zoned_time&) = default;
 //
 //  };
+//
+// using zoned_seconds = zoned_time;
 
 #include 
 #include 
@@ -57,3 +59,6 @@ 
static_assert(!std::is_copy_constructible_v>>);
 static_assert(!std::is_copy_assignable_v>>);
 static_assert(!std::is_move_assignable_v>>);
+
+// using zoned_seconds = zoned_time;
+static_assert(std::same_as>);

``




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


[llvm-branch-commits] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung created 
https://github.com/llvm/llvm-project/pull/95156



Test Plan: tbd



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


[llvm-branch-commits] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: shaw young (shawbyoung)


Changes



Test Plan: tbd


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


2 Files Affected:

- (modified) bolt/lib/Profile/StaleProfileMatching.cpp (+14-2) 
- (modified) llvm/include/llvm/Transforms/Utils/SampleProfileInference.h (+2-1) 


``diff
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp 
b/bolt/lib/Profile/StaleProfileMatching.cpp
index 5969f4b9bcbc1..41afa6b4bbb19 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -51,6 +51,12 @@ cl::opt
   cl::desc("Infer counts from stale profile data."),
   cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
 
+cl::opt MatchedProfileThreshold(
+"matched-profile-threshold",
+cl::desc("Percentage threshold of matched execution counts at which stale "
+ "profile inference is executed."),
+cl::init(5), cl::Hidden, cl::cat(BoltOptCategory));
+
 cl::opt StaleMatchingMaxFuncSize(
 "stale-matching-max-func-size",
 cl::desc("The maximum size of a function to consider for inference."),
@@ -451,6 +457,7 @@ void matchWeightsByHashes(BinaryContext &BC,
   if (Matcher.isHighConfidenceMatch(BinHash, YamlHash)) {
 ++BC.Stats.NumMatchedBlocks;
 BC.Stats.MatchedSampleCount += YamlBB.ExecCount;
+Func.MatchedExecCount += YamlBB.ExecCount;
 LLVM_DEBUG(dbgs() << "  exact match\n");
   } else {
 LLVM_DEBUG(dbgs() << "  loose match\n");
@@ -592,10 +599,15 @@ void preprocessUnreachableBlocks(FlowFunction &Func) {
 /// Decide if stale profile matching can be applied for a given function.
 /// Currently we skip inference for (very) large instances and for instances
 /// having "unexpected" control flow (e.g., having no sink basic blocks).
-bool canApplyInference(const FlowFunction &Func) {
+bool canApplyInference(const FlowFunction &Func,
+   const yaml::bolt::BinaryFunctionProfile &YamlBF) {
   if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize)
 return false;
 
+  if (Func.MatchedExecCount / YamlBF.ExecCount >=
+  opts::MatchedProfileThreshold / 100)
+return false;
+
   bool HasExitBlocks = llvm::any_of(
   Func.Blocks, [&](const FlowBlock &Block) { return Block.isExit(); });
   if (!HasExitBlocks)
@@ -756,7 +768,7 @@ bool YAMLProfileReader::inferStaleProfile(
   preprocessUnreachableBlocks(Func);
 
   // Check if profile inference can be applied for the instance.
-  if (!canApplyInference(Func))
+  if (!canApplyInference(Func, YamlBF))
 return false;
 
   // Apply the profile inference algorithm.
diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h 
b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
index 70a80b91405d0..c654715c0ae9f 100644
--- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
+++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
@@ -58,7 +58,8 @@ struct FlowFunction {
   std::vector Jumps;
   /// The index of the entry block.
   uint64_t Entry{0};
-  uint64_t Sink{UINT64_MAX};
+  // Matched execution count for the function.
+  uint64_t MatchedExecCount{0};
 };
 
 /// Various thresholds and options controlling the behavior of the profile

``




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


[llvm-branch-commits] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung edited 
https://github.com/llvm/llvm-project/pull/95156
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Updated CommandLineArgumentReference.md (PR #95160)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung created 
https://github.com/llvm/llvm-project/pull/95160



Test Plan: tbd



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


[llvm-branch-commits] Updated CommandLineArgumentReference.md (PR #95160)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: shaw young (shawbyoung)


Changes



Test Plan: tbd


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


1 Files Affected:

- (modified) bolt/docs/CommandLineArgumentReference.md (+12-1) 


``diff
diff --git a/bolt/docs/CommandLineArgumentReference.md 
b/bolt/docs/CommandLineArgumentReference.md
index 8887d1f5d5bd4..bdc1d9dfd735c 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -614,6 +614,17 @@
 
 - `--lite-threshold-pct=`
 
+  Threshold (in percent) of matched profile at which stale profile inference is
+  applied to functions. Argument corresponds to the sum of matched execution
+  counts of function blocks divided by the sum of execution counts of function
+  blocks. E.g if the sum of a function blocks' execution counts is 100, the sum
+  of the function blocks' matched execution counts is 10, and the argument is 
15
+  (15%), profile inference will not be applied to that function. A higher
+  threshold will correlate with fewer functions to process in cases of stale
+  profile. Default set to %5.
+
+- `--matched-profile-threshold=`
+
   Threshold (in percent) for selecting functions to process in lite mode. 
Higher
   threshold means fewer functions to process. E.g threshold of 90 means only 
top
   10 percent of functions with profile will be processed.
@@ -1161,4 +1172,4 @@
 
 - `--print-options`
 
-  Print non-default options after command line parsing
\ No newline at end of file
+  Print non-default options after command line parsing

``




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


[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/95156

>From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 11 Jun 2024 11:43:13 -0700
Subject: [PATCH] Summary: Functions with little exact matching

Created using spr 1.3.4
---
 bolt/docs/CommandLineArgumentReference.md | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/bolt/docs/CommandLineArgumentReference.md 
b/bolt/docs/CommandLineArgumentReference.md
index 8887d1f5d5bd4..bdc1d9dfd735c 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -614,6 +614,17 @@
 
 - `--lite-threshold-pct=`
 
+  Threshold (in percent) of matched profile at which stale profile inference is
+  applied to functions. Argument corresponds to the sum of matched execution
+  counts of function blocks divided by the sum of execution counts of function
+  blocks. E.g if the sum of a function blocks' execution counts is 100, the sum
+  of the function blocks' matched execution counts is 10, and the argument is 
15
+  (15%), profile inference will not be applied to that function. A higher
+  threshold will correlate with fewer functions to process in cases of stale
+  profile. Default set to %5.
+
+- `--matched-profile-threshold=`
+
   Threshold (in percent) for selecting functions to process in lite mode. 
Higher
   threshold means fewer functions to process. E.g threshold of 90 means only 
top
   10 percent of functions with profile will be processed.
@@ -1161,4 +1172,4 @@
 
 - `--print-options`
 
-  Print non-default options after command line parsing
\ No newline at end of file
+  Print non-default options after command line parsing

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


[llvm-branch-commits] Updated CommandLineArgumentReference.md (PR #95160)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung closed 
https://github.com/llvm/llvm-project/pull/95160
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Anton Korobeynikov via llvm-branch-commits

asl wrote:

@ahmedbougacha Anything left here? I think it is good to go after the two 
changes mentioned above. We can deal with cross-endian things afterwards as 
soon as we will have tests & buildbots 


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


[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

2024-06-11 Thread via llvm-branch-commits


@@ -0,0 +1,233 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// This header is unguarded on purpose. This header is an implementation 
detail of move_only_function.h
+// and generates multiple versions of std::move_only_function
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/move_only_function_common.h>
+#include <__type_traits/is_trivially_destructible.h>
+#include <__utility/exchange.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <__utility/pointer_int_pair.h>
+#include <__utility/small_buffer.h>
+#include <__utility/swap.h>
+#include 
+#include 
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_IN_MOVE_ONLY_FUNCTION_H
+#  error This header should only be included from move_only_function.h
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV&
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT false
+#endif
+
+#define _LIBCPP_MOVE_ONLY_FUNCTION_CVREF _LIBCPP_MOVE_ONLY_FUNCTION_CV 
_LIBCPP_MOVE_ONLY_FUNCTION_REF
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef _LIBCPP_ABI_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI [[_Clang::__trivial_abi__]]
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#endif
+
+template 
+class move_only_function;
+
+template 
+class _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI move_only_function<_ReturnT(
+_ArgTypes...) _LIBCPP_MOVE_ONLY_FUNCTION_CVREF 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT)> {
+private:
+  static constexpr size_t __buffer_size_  = 3 * sizeof(void*);
+  static constexpr size_t __buffer_alignment_ = alignof(void*);
+  using _BufferT  = __small_buffer<__buffer_size_, 
__buffer_alignment_>;
+
+  using _TrivialVTable= _MoveOnlyFunctionTrivialVTable<_BufferT, _ReturnT, 
_ArgTypes...>;
+  using _NonTrivialVTable = _MoveOnlyFunctionNonTrivialVTable<_BufferT, 
_ReturnT, _ArgTypes...>;
+
+  template 
+  static constexpr _TrivialVTable __trivial_vtable_ = {
+  .__call_ = [](_BufferT& __buffer, _ArgTypes... __args) 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) -> _ReturnT {
+return std::invoke_r<_ReturnT>(
+static_cast<_Functor 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS>(*__buffer.__get<_Functor>()),
+std::forward<_ArgTypes>(__args)...);
+  }};
+
+  template 
+  static constexpr _NonTrivialVTable __non_trivial_vtable_{
+  __trivial_vtable_<_Functor>,
+  [](_BufferT& __buffer) noexcept -> void {
+std::destroy_at(__buffer.__get<_Functor>());
+__buffer.__dealloc<_Functor>();
+  },
+  };
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI __pointer_bool_pair 
__get_vptr() {
+if constexpr (_BufferT::__fits_in_buffer<_Functor> && 
is_trivially_destructible_v<_Functor>) {
+  return {&__trivial_vtable_<_Functor>, false};
+} else {
+  return {&__non_trivial_vtable_<_Functor>, true};
+}
+  }
+
+  template 
+  static constexpr bool __is_callable_from = [] {
+using _DVT = decay_t<_VT>;
+if (_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) {
+  return is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_CVREF, _ArgTypes...> &&
+ is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+} else {
+  return is_invocable_r_v<_ReturnT, _DVT _LIBCPP_MOVE_ONLY_FUNCTION_CVREF, 
_ArgTypes...> &&
+ is_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+}
+  }();
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
+static_assert(is_constructible_v, _Func>);
+
+using _StoredFunc = decay_t<_Func>;
+__vtable_ = __get_vptr<_StoredFunc>();
+__buffer_.__construct<_StoredFunc>(std::forward<_Args>(__args)...);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void __reset() {
+if (__vtable_.__get_value())

huixie90 wrote:

So far the conclusion was that this `bool` is used to optimise the destructor 
for trivially destructible types, to save one vtable ptr indirection, at the 
cost of code complexity and some pointer pokery in other operations like 
`operator()`. And the cost is debatable

[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

2024-06-11 Thread Nikolas Klauser via llvm-branch-commits


@@ -0,0 +1,233 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// This header is unguarded on purpose. This header is an implementation 
detail of move_only_function.h
+// and generates multiple versions of std::move_only_function
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/move_only_function_common.h>
+#include <__type_traits/is_trivially_destructible.h>
+#include <__utility/exchange.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <__utility/pointer_int_pair.h>
+#include <__utility/small_buffer.h>
+#include <__utility/swap.h>
+#include 
+#include 
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_IN_MOVE_ONLY_FUNCTION_H
+#  error This header should only be included from move_only_function.h
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV&
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT false
+#endif
+
+#define _LIBCPP_MOVE_ONLY_FUNCTION_CVREF _LIBCPP_MOVE_ONLY_FUNCTION_CV 
_LIBCPP_MOVE_ONLY_FUNCTION_REF
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef _LIBCPP_ABI_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI [[_Clang::__trivial_abi__]]
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#endif
+
+template 
+class move_only_function;
+
+template 
+class _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI move_only_function<_ReturnT(
+_ArgTypes...) _LIBCPP_MOVE_ONLY_FUNCTION_CVREF 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT)> {
+private:
+  static constexpr size_t __buffer_size_  = 3 * sizeof(void*);
+  static constexpr size_t __buffer_alignment_ = alignof(void*);
+  using _BufferT  = __small_buffer<__buffer_size_, 
__buffer_alignment_>;
+
+  using _TrivialVTable= _MoveOnlyFunctionTrivialVTable<_BufferT, _ReturnT, 
_ArgTypes...>;
+  using _NonTrivialVTable = _MoveOnlyFunctionNonTrivialVTable<_BufferT, 
_ReturnT, _ArgTypes...>;
+
+  template 
+  static constexpr _TrivialVTable __trivial_vtable_ = {
+  .__call_ = [](_BufferT& __buffer, _ArgTypes... __args) 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) -> _ReturnT {
+return std::invoke_r<_ReturnT>(
+static_cast<_Functor 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS>(*__buffer.__get<_Functor>()),
+std::forward<_ArgTypes>(__args)...);
+  }};
+
+  template 
+  static constexpr _NonTrivialVTable __non_trivial_vtable_{
+  __trivial_vtable_<_Functor>,
+  [](_BufferT& __buffer) noexcept -> void {
+std::destroy_at(__buffer.__get<_Functor>());
+__buffer.__dealloc<_Functor>();
+  },
+  };
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI __pointer_bool_pair 
__get_vptr() {
+if constexpr (_BufferT::__fits_in_buffer<_Functor> && 
is_trivially_destructible_v<_Functor>) {
+  return {&__trivial_vtable_<_Functor>, false};
+} else {
+  return {&__non_trivial_vtable_<_Functor>, true};
+}
+  }
+
+  template 
+  static constexpr bool __is_callable_from = [] {
+using _DVT = decay_t<_VT>;
+if (_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) {
+  return is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_CVREF, _ArgTypes...> &&
+ is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+} else {
+  return is_invocable_r_v<_ReturnT, _DVT _LIBCPP_MOVE_ONLY_FUNCTION_CVREF, 
_ArgTypes...> &&
+ is_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+}
+  }();
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
+static_assert(is_constructible_v, _Func>);
+
+using _StoredFunc = decay_t<_Func>;
+__vtable_ = __get_vptr<_StoredFunc>();
+__buffer_.__construct<_StoredFunc>(std::forward<_Args>(__args)...);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void __reset() {
+if (__vtable_.__get_value())

philnik777 wrote:

The main thing I'm objecting to currently is Eric's behaviour. He's showing 
zero evidence for his claims while being extremely patronizing to the point of 
being insulting [1] and claiming he's got knowledge of other's mental states 
which he obviously has no access 

[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/95156

>From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 11 Jun 2024 11:43:13 -0700
Subject: [PATCH 1/2] Summary: Functions with little exact matching

Created using spr 1.3.4
---
 bolt/docs/CommandLineArgumentReference.md | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/bolt/docs/CommandLineArgumentReference.md 
b/bolt/docs/CommandLineArgumentReference.md
index 8887d1f5d5bd4..bdc1d9dfd735c 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -614,6 +614,17 @@
 
 - `--lite-threshold-pct=`
 
+  Threshold (in percent) of matched profile at which stale profile inference is
+  applied to functions. Argument corresponds to the sum of matched execution
+  counts of function blocks divided by the sum of execution counts of function
+  blocks. E.g if the sum of a function blocks' execution counts is 100, the sum
+  of the function blocks' matched execution counts is 10, and the argument is 
15
+  (15%), profile inference will not be applied to that function. A higher
+  threshold will correlate with fewer functions to process in cases of stale
+  profile. Default set to %5.
+
+- `--matched-profile-threshold=`
+
   Threshold (in percent) for selecting functions to process in lite mode. 
Higher
   threshold means fewer functions to process. E.g threshold of 90 means only 
top
   10 percent of functions with profile will be processed.
@@ -1161,4 +1172,4 @@
 
 - `--print-options`
 
-  Print non-default options after command line parsing
\ No newline at end of file
+  Print non-default options after command line parsing

>From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001
From: shaw young <58664393+shawbyo...@users.noreply.github.com>
Date: Tue, 11 Jun 2024 14:32:40 -0700
Subject: [PATCH 2/2] Update SampleProfileInference.h

---
 llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h 
b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
index c654715c0ae9f..9ccbd0fa88f3d 100644
--- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
+++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
@@ -58,6 +58,7 @@ struct FlowFunction {
   std::vector Jumps;
   /// The index of the entry block.
   uint64_t Entry{0};
+  uint64_t Sink{UINT64_MAX};
   // Matched execution count for the function.
   uint64_t MatchedExecCount{0};
 };

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


[llvm-branch-commits] [llvm] [BOLT] Drop high discrepancy profiles in matching (PR #95156)

2024-06-11 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/95156

>From aa441dc0163d3d0f63de1e4dd1fa359180f82f1f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 11 Jun 2024 11:43:13 -0700
Subject: [PATCH 1/3] Summary: Functions with little exact matching

Created using spr 1.3.4
---
 bolt/docs/CommandLineArgumentReference.md | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/bolt/docs/CommandLineArgumentReference.md 
b/bolt/docs/CommandLineArgumentReference.md
index 8887d1f5d5bd4..bdc1d9dfd735c 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -614,6 +614,17 @@
 
 - `--lite-threshold-pct=`
 
+  Threshold (in percent) of matched profile at which stale profile inference is
+  applied to functions. Argument corresponds to the sum of matched execution
+  counts of function blocks divided by the sum of execution counts of function
+  blocks. E.g if the sum of a function blocks' execution counts is 100, the sum
+  of the function blocks' matched execution counts is 10, and the argument is 
15
+  (15%), profile inference will not be applied to that function. A higher
+  threshold will correlate with fewer functions to process in cases of stale
+  profile. Default set to %5.
+
+- `--matched-profile-threshold=`
+
   Threshold (in percent) for selecting functions to process in lite mode. 
Higher
   threshold means fewer functions to process. E.g threshold of 90 means only 
top
   10 percent of functions with profile will be processed.
@@ -1161,4 +1172,4 @@
 
 - `--print-options`
 
-  Print non-default options after command line parsing
\ No newline at end of file
+  Print non-default options after command line parsing

>From 46fa37a054a129ca36e7b6ae126273e40fddea98 Mon Sep 17 00:00:00 2001
From: shaw young <58664393+shawbyo...@users.noreply.github.com>
Date: Tue, 11 Jun 2024 14:32:40 -0700
Subject: [PATCH 2/3] Update SampleProfileInference.h

---
 llvm/include/llvm/Transforms/Utils/SampleProfileInference.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h 
b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
index c654715c0ae9f..9ccbd0fa88f3d 100644
--- a/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
+++ b/llvm/include/llvm/Transforms/Utils/SampleProfileInference.h
@@ -58,6 +58,7 @@ struct FlowFunction {
   std::vector Jumps;
   /// The index of the entry block.
   uint64_t Entry{0};
+  uint64_t Sink{UINT64_MAX};
   // Matched execution count for the function.
   uint64_t MatchedExecCount{0};
 };

>From d532514257feb5e86232e76c437c99a41d5f2cea Mon Sep 17 00:00:00 2001
From: shaw young <58664393+shawbyo...@users.noreply.github.com>
Date: Tue, 11 Jun 2024 14:39:28 -0700
Subject: [PATCH 3/3] Update StaleProfileMatching.cpp

---
 bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp 
b/bolt/lib/Profile/StaleProfileMatching.cpp
index 41afa6b4bbb19..47335163263a4 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -604,8 +604,8 @@ bool canApplyInference(const FlowFunction &Func,
   if (Func.Blocks.size() > opts::StaleMatchingMaxFuncSize)
 return false;
 
-  if (Func.MatchedExecCount / YamlBF.ExecCount >=
-  opts::MatchedProfileThreshold / 100)
+  if ((double)Func.MatchedExecCount / YamlBF.ExecCount >=
+  opts::MatchedProfileThreshold / 100.0)
 return false;
 
   bool HasExitBlocks = llvm::any_of(

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/94394

>From 1e9a3fde97d907c3cd6be33db91d1c18c7236ffb Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Tue, 4 Jun 2024 12:41:47 -0700
Subject: [PATCH 1/5] [Support] Reformat SipHash.cpp to match libSupport.

While there, give it our usual file header and an acknowledgement,
and remove the imported README.md.SipHash.
---
 llvm/lib/Support/README.md.SipHash | 126 --
 llvm/lib/Support/SipHash.cpp   | 264 ++---
 2 files changed, 129 insertions(+), 261 deletions(-)
 delete mode 100644 llvm/lib/Support/README.md.SipHash

diff --git a/llvm/lib/Support/README.md.SipHash 
b/llvm/lib/Support/README.md.SipHash
deleted file mode 100644
index 4de3cd1854681..0
--- a/llvm/lib/Support/README.md.SipHash
+++ /dev/null
@@ -1,126 +0,0 @@
-# SipHash
-
-[![License:
-CC0-1.0](https://licensebuttons.net/l/zero/1.0/80x15.png)](http://creativecommons.org/publicdomain/zero/1.0/)
-
-[![License: 
MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
-
-
-SipHash is a family of pseudorandom functions (PRFs) optimized for speed on 
short messages.
-This is the reference C code of SipHash: portable, simple, optimized for 
clarity and debugging.
-
-SipHash was designed in 2012 by [Jean-Philippe Aumasson](https://aumasson.jp)
-and [Daniel J. Bernstein](https://cr.yp.to) as a defense against [hash-flooding
-DoS attacks](https://aumasson.jp/siphash/siphashdos_29c3_slides.pdf).
-
-SipHash is:
-
-* *Simpler and faster* on short messages than previous cryptographic
-algorithms, such as MACs based on universal hashing.
-
-* *Competitive in performance* with insecure non-cryptographic algorithms, 
such as [fhhash](https://github.com/cbreeden/fxhash).
-
-* *Cryptographically secure*, with no sign of weakness despite multiple 
[cryptanalysis](https://eprint.iacr.org/2019/865) 
[projects](https://eprint.iacr.org/2019/865) by leading cryptographers.
-
-* *Battle-tested*, with successful integration in OSs (Linux kernel, OpenBSD,
-FreeBSD, FreeRTOS), languages (Perl, Python, Ruby, etc.), libraries (OpenSSL 
libcrypto,
-Sodium, etc.) and applications (Wireguard, Redis, etc.).
-
-As a secure pseudorandom function (a.k.a. keyed hash function), SipHash can 
also be used as a secure message authentication code (MAC).
-But SipHash is *not a hash* in the sense of general-purpose key-less hash 
function such as BLAKE3 or SHA-3.
-SipHash should therefore always be used with a secret key in order to be 
secure.
-
-
-## Variants
-
-The default SipHash is *SipHash-2-4*: it takes a 128-bit key, does 2 
compression
-rounds, 4 finalization rounds, and returns a 64-bit tag.
-
-Variants can use a different number of rounds. For example, we proposed 
*SipHash-4-8* as a conservative version.
-
-The following versions are not described in the paper but were designed and 
analyzed to fulfill applications' needs:
-
-* *SipHash-128* returns a 128-bit tag instead of 64-bit. Versions with 
specified number of rounds are SipHash-2-4-128, SipHash4-8-128, and so on.
-
-* *HalfSipHash* works with 32-bit words instead of 64-bit, takes a 64-bit key,
-and returns 32-bit or 64-bit tags. For example, HalfSipHash-2-4-32 has 2
-compression rounds, 4 finalization rounds, and returns a 32-bit tag.
-
-
-## Security
-
-(Half)SipHash-*c*-*d* with *c* ≥ 2 and *d* ≥ 4 is expected to provide the 
maximum PRF
-security for any function with the same key and output size.
-
-The standard PRF security goal allow the attacker access to the output of 
SipHash on messages chosen adaptively by the attacker.
-
-Security is limited by the key size (128 bits for SipHash), such that
-attackers searching 2*s* keys have chance 2*s*−128 of 
finding
-the SipHash key. 
-Security is also limited by the output size. In particular, when
-SipHash is used as a MAC, an attacker who blindly tries 2*s* tags 
will
-succeed with probability 2*s*-*t*, if *t* is that tag's bit size.
-
-
-## Research
-
-* [Research paper](https://www.aumasson.jp/siphash/siphash.pdf) "SipHash: a 
fast short-input PRF" (accepted at INDOCRYPT 2012)
-* [Slides](https://cr.yp.to/talks/2012.12.12/slides.pdf) of the presentation 
of SipHash at INDOCRYPT 2012 (Bernstein)
-* [Slides](https://www.aumasson.jp/siphash/siphash_slides.pdf) of the 
presentation of SipHash at the DIAC workshop (Aumasson)
-
-
-## Usage
-
-Running
-
-```sh
-  make
-```
-
-will build tests for 
-
-* SipHash-2-4-64
-* SipHash-2-4-128
-* HalfSipHash-2-4-32
-* HalfSipHash-2-4-64
-
-
-```C
-  ./test
-```
-
-verifies 64 test vectors, and
-
-```C
-  ./debug
-```
-
-does the same and prints intermediate values.
-
-The code can be adapted to implement SipHash-*c*-*d*, the version of SipHash
-with *c* compression rounds and *d* finalization rounds, by defining `cROUNDS`
-or `dROUNDS` when compiling.  This can be done with `-D` command line arguments
-to many compilers such as below.
-
-```sh
-gcc -Wall --

[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits


@@ -1,185 +1,149 @@
-/*
-   SipHash reference C implementation
-
-   Copyright (c) 2012-2022 Jean-Philippe Aumasson
-   
-   Copyright (c) 2012-2014 Daniel J. Bernstein 
-
-   To the extent possible under law, the author(s) have dedicated all copyright
-   and related and neighboring rights to this software to the public domain
-   worldwide. This software is distributed without any warranty.
-
-   You should have received a copy of the CC0 Public Domain Dedication along
-   with
-   this software. If not, see
-   .
- */
-
-#include "siphash.h"
-#include 
-#include 
-#include 
-
-/* default: SipHash-2-4 */
-#ifndef cROUNDS
-#define cROUNDS 2
-#endif
-#ifndef dROUNDS
-#define dROUNDS 4
-#endif
+//===--- SipHash.cpp - An ABI-stable string hash 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
+#include "llvm/Support/Compiler.h"
+#include 
 
-#define U32TO8_LE(p, v)
\
-(p)[0] = (uint8_t)((v));   
\
-(p)[1] = (uint8_t)((v) >> 8);  
\
-(p)[2] = (uint8_t)((v) >> 16); 
\
-(p)[3] = (uint8_t)((v) >> 24);
+// Lightly adapted from the SipHash reference C implementation:
+//   https://github.com/veorq/SipHash
+// by Jean-Philippe Aumasson and Daniel J. Bernstein
 
-#define U64TO8_LE(p, v)
\
-U32TO8_LE((p), (uint32_t)((v)));   
\
-U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
+#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b

ahmedbougacha wrote:

This, I'm a little more inclined to keep the macros as close to original as 
possible, it being the core of the function.  It could help to name the 
function `ROTL` to match the original;  we can turn the whole block into a 
function as well.  I don't feel strongly either way, let me know which you 
prefer.

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


[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits


@@ -1,185 +1,149 @@
-/*
-   SipHash reference C implementation
-
-   Copyright (c) 2012-2022 Jean-Philippe Aumasson
-   
-   Copyright (c) 2012-2014 Daniel J. Bernstein 
-
-   To the extent possible under law, the author(s) have dedicated all copyright
-   and related and neighboring rights to this software to the public domain
-   worldwide. This software is distributed without any warranty.
-
-   You should have received a copy of the CC0 Public Domain Dedication along
-   with
-   this software. If not, see
-   .
- */
-
-#include "siphash.h"
-#include 
-#include 
-#include 
-
-/* default: SipHash-2-4 */
-#ifndef cROUNDS
-#define cROUNDS 2
-#endif
-#ifndef dROUNDS
-#define dROUNDS 4
-#endif
+//===--- SipHash.cpp - An ABI-stable string hash 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
+#include "llvm/Support/Compiler.h"
+#include 
 
-#define U32TO8_LE(p, v)
\
-(p)[0] = (uint8_t)((v));   
\
-(p)[1] = (uint8_t)((v) >> 8);  
\
-(p)[2] = (uint8_t)((v) >> 16); 
\
-(p)[3] = (uint8_t)((v) >> 24);
+// Lightly adapted from the SipHash reference C implementation:
+//   https://github.com/veorq/SipHash
+// by Jean-Philippe Aumasson and Daniel J. Bernstein
 
-#define U64TO8_LE(p, v)
\
-U32TO8_LE((p), (uint32_t)((v)));   
\
-U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
+#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
 
 #define U8TO64_LE(p)   
\
-(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) |
\
- ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | 
\
- ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | 
\
- ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
+  (((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) |  
\
+   ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) |   
\
+   ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) |   
\
+   ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
 
 #define SIPROUND   
\
-do {   
\
-v0 += v1;  
\
-v1 = ROTL(v1, 13); 
\
-v1 ^= v0;  
\
-v0 = ROTL(v0, 32); 
\
-v2 += v3;  
\
-v3 = ROTL(v3, 16); 
\
-v3 ^= v2;  
\
-v0 += v3;  
\
-v3 = ROTL(v3, 21); 
\
-v3 ^= v0;  
\
-v2 += v1;  
\
-v1 = ROTL(v1, 17); 
\
-v1 ^= v2;  
\
-v2 = ROTL(v2, 32); 
\
-} while (0)
-
-#ifdef DEBUG_SIPHASH
-#include 
-
-#define TRACE  
\
-do {   
\
-printf("(%3zu) v0 %016" PRIx64 "\n", inlen, v0);   
\
-printf("(%3zu) v1 %016" PRIx64 "\n", inlen, v1);   
\
-printf("(%3zu) v2 %016" PRIx64 "\n", inlen, v2);   
\
-printf("(%3zu) v3 %016" PRIx64 "\n", inlen, v3);   
\
-} while (0)
-#else
-#define TRACE
-#endif
-
-/*
-Computes a SipHash value
-*in: pointer to input data (read-only)
-inlen: input data length in bytes (any size_t value)
-*k: pointer to the key data (read-only), must be 16 bytes 
-*out: pointer to output data (write-only), outlen bytes must be allocated
-o

[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits

ahmedbougacha wrote:

I think this version should work on BE hosts, but that's only by thinking 
through the code.  Only the bots will tell us one way or another ;)

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


[llvm-branch-commits] [llvm] [Support] Add SipHash-based 16-bit ptrauth stable hash. (PR #93902)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93902

>From bf413d68cff5ad963c43bb584590908bf03bc3ce Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Tue, 4 Jun 2024 12:36:33 -0700
Subject: [PATCH] [Support] Add SipHash-based 16-bit ptrauth stable hash.

This finally wraps the now-lightly-modified SipHash C reference
implementation, for the main interface we need (16-bit ptrauth
discriminators).

This intentionally doesn't expose a raw interface beyond that to
encourage others to carefully consider their use.

The exact algorithm is the little-endian interpretation of the
non-doubled (i.e. 64-bit) result of applying a SipHash-2-4 using the
constant seed `b5d4c9eb79104a796fec8b1b428781d4` (big-endian), with the
result reduced by modulo to the range of non-zero discriminators (i.e.
`(rawHash % 65535) + 1`).

By "stable" we mean that the result of this hash algorithm will the same
across different compiler versions and target platforms.

The 16-bit hashes are used extensively for the AArch64 ptrauth ABI,
because AArch64 can efficiently load a 16-bit immediate into the high
bits of a register without disturbing the remainder of the value, which
serves as a nice blend operation.

16 bits is also sufficiently compact to not inflate a loader relocation.
We disallow zero to guarantee a different discriminator from the places
in the ABI that use a constant zero.

Co-Authored-By: John McCall 
---
 llvm/include/llvm/Support/SipHash.h| 39 ++
 llvm/lib/Support/SipHash.cpp   | 35 +++
 llvm/unittests/Support/CMakeLists.txt  |  1 +
 llvm/unittests/Support/SipHashTest.cpp | 33 ++
 4 files changed, 108 insertions(+)
 create mode 100644 llvm/include/llvm/Support/SipHash.h
 create mode 100644 llvm/unittests/Support/SipHashTest.cpp

diff --git a/llvm/include/llvm/Support/SipHash.h 
b/llvm/include/llvm/Support/SipHash.h
new file mode 100644
index 0..91447b2344eeb
--- /dev/null
+++ b/llvm/include/llvm/Support/SipHash.h
@@ -0,0 +1,39 @@
+//===--- SipHash.h - An ABI-stable string SipHash ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// A family of ABI-stable string hash algorithms based on SipHash, currently
+// used to compute ptrauth discriminators.
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_SIPHASH_H
+#define LLVM_SUPPORT_SIPHASH_H
+
+#include 
+
+namespace llvm {
+class StringRef;
+
+/// Compute a stable non-zero 16-bit hash of the given string.
+///
+/// The exact algorithm is the little-endian interpretation of the
+/// non-doubled (i.e. 64-bit) result of applying a SipHash-2-4 using
+/// a specific seed value which can be found in the source.
+/// This 64-bit result is truncated to a non-zero 16-bit value.
+///
+/// We use a 16-bit discriminator because ARM64 can efficiently load
+/// a 16-bit immediate into the high bits of a register without disturbing
+/// the remainder of the value, which serves as a nice blend operation.
+/// 16 bits is also sufficiently compact to not inflate a loader relocation.
+/// We disallow zero to guarantee a different discriminator from the places
+/// in the ABI that use a constant zero.
+uint16_t getPointerAuthStableSipHash(StringRef S);
+
+} // end namespace llvm
+
+#endif
diff --git a/llvm/lib/Support/SipHash.cpp b/llvm/lib/Support/SipHash.cpp
index ef882ae4d8745..b1b4bede7637d 100644
--- a/llvm/lib/Support/SipHash.cpp
+++ b/llvm/lib/Support/SipHash.cpp
@@ -5,10 +5,23 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
+//
+//  This file implements an ABI-stable string hash based on SipHash, used to
+//  compute ptrauth discriminators.
+//
+//===--===//
 
+#include "llvm/Support/SipHash.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
 #include 
 
+using namespace llvm;
+
+#define DEBUG_TYPE "llvm-siphash"
+
 // Lightly adapted from the SipHash reference C implementation by
 // Jean-Philippe Aumasson and Daniel J. Bernstein.
 
@@ -133,3 +146,25 @@ static inline ResultTy siphash(const unsigned char *in, 
uint64_t inlen,
 
   return firstHalf | (ResultTy(secondHalf) << (sizeof(ResultTy) == 8 ? 0 : 
64));
 }
+
+//===--- LLVM-specific wrapper around siphash.
+
+/// Compute an ABI-stable 16-bit hash of the given string.
+uint16_t llvm::getPointerAuthStableSipHash(StringRef Str) {
+  static const uint8_t K[16] = {0xb5, 0xd4, 0xc9, 0xeb, 0x79, 0x10, 0x4a, 0x79,
+   

[llvm-branch-commits] [llvm] [Support] Integrate SipHash.cpp into libSupport. (PR #94394)

2024-06-11 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha edited 
https://github.com/llvm/llvm-project/pull/94394
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

2024-06-11 Thread via llvm-branch-commits


@@ -0,0 +1,233 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// This header is unguarded on purpose. This header is an implementation 
detail of move_only_function.h
+// and generates multiple versions of std::move_only_function
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/move_only_function_common.h>
+#include <__type_traits/is_trivially_destructible.h>
+#include <__utility/exchange.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <__utility/pointer_int_pair.h>
+#include <__utility/small_buffer.h>
+#include <__utility/swap.h>
+#include 
+#include 
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_IN_MOVE_ONLY_FUNCTION_H
+#  error This header should only be included from move_only_function.h
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV&
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT false
+#endif
+
+#define _LIBCPP_MOVE_ONLY_FUNCTION_CVREF _LIBCPP_MOVE_ONLY_FUNCTION_CV 
_LIBCPP_MOVE_ONLY_FUNCTION_REF
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef _LIBCPP_ABI_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI [[_Clang::__trivial_abi__]]
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#endif
+
+template 
+class move_only_function;
+
+template 
+class _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI move_only_function<_ReturnT(
+_ArgTypes...) _LIBCPP_MOVE_ONLY_FUNCTION_CVREF 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT)> {
+private:
+  static constexpr size_t __buffer_size_  = 3 * sizeof(void*);
+  static constexpr size_t __buffer_alignment_ = alignof(void*);
+  using _BufferT  = __small_buffer<__buffer_size_, 
__buffer_alignment_>;
+
+  using _TrivialVTable= _MoveOnlyFunctionTrivialVTable<_BufferT, _ReturnT, 
_ArgTypes...>;
+  using _NonTrivialVTable = _MoveOnlyFunctionNonTrivialVTable<_BufferT, 
_ReturnT, _ArgTypes...>;
+
+  template 
+  static constexpr _TrivialVTable __trivial_vtable_ = {
+  .__call_ = [](_BufferT& __buffer, _ArgTypes... __args) 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) -> _ReturnT {
+return std::invoke_r<_ReturnT>(
+static_cast<_Functor 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS>(*__buffer.__get<_Functor>()),
+std::forward<_ArgTypes>(__args)...);
+  }};
+
+  template 
+  static constexpr _NonTrivialVTable __non_trivial_vtable_{
+  __trivial_vtable_<_Functor>,
+  [](_BufferT& __buffer) noexcept -> void {
+std::destroy_at(__buffer.__get<_Functor>());
+__buffer.__dealloc<_Functor>();
+  },
+  };
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI __pointer_bool_pair 
__get_vptr() {
+if constexpr (_BufferT::__fits_in_buffer<_Functor> && 
is_trivially_destructible_v<_Functor>) {
+  return {&__trivial_vtable_<_Functor>, false};
+} else {
+  return {&__non_trivial_vtable_<_Functor>, true};
+}
+  }
+
+  template 
+  static constexpr bool __is_callable_from = [] {
+using _DVT = decay_t<_VT>;
+if (_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) {
+  return is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_CVREF, _ArgTypes...> &&
+ is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+} else {
+  return is_invocable_r_v<_ReturnT, _DVT _LIBCPP_MOVE_ONLY_FUNCTION_CVREF, 
_ArgTypes...> &&
+ is_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+}
+  }();
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
+static_assert(is_constructible_v, _Func>);
+
+using _StoredFunc = decay_t<_Func>;
+__vtable_ = __get_vptr<_StoredFunc>();
+__buffer_.__construct<_StoredFunc>(std::forward<_Args>(__args)...);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void __reset() {
+if (__vtable_.__get_value())

EricWF wrote:

@philnik777 It seems we're having trouble communicating. I'm happy to meet with 
you over video chat, hopefully that can clear up any miscommunications.

I promise there is no malice or ill-intent. 

The comment about "killing your darlings" is  honest advice. Perhaps the

[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

2024-06-11 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,233 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// This header is unguarded on purpose. This header is an implementation 
detail of move_only_function.h
+// and generates multiple versions of std::move_only_function
+
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/move_only_function_common.h>
+#include <__type_traits/is_trivially_destructible.h>
+#include <__utility/exchange.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <__utility/pointer_int_pair.h>
+#include <__utility/small_buffer.h>
+#include <__utility/swap.h>
+#include 
+#include 
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_IN_MOVE_ONLY_FUNCTION_H
+#  error This header should only be included from move_only_function.h
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_CV
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV&
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS 
_LIBCPP_MOVE_ONLY_FUNCTION_CV _LIBCPP_MOVE_ONLY_FUNCTION_REF
+#endif
+
+#ifndef _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT false
+#endif
+
+#define _LIBCPP_MOVE_ONLY_FUNCTION_CVREF _LIBCPP_MOVE_ONLY_FUNCTION_CV 
_LIBCPP_MOVE_ONLY_FUNCTION_REF
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#ifdef _LIBCPP_ABI_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI [[_Clang::__trivial_abi__]]
+#else
+#  define _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI
+#endif
+
+template 
+class move_only_function;
+
+template 
+class _LIBCPP_MOVE_ONLY_FUNCTION_TRIVIAL_ABI move_only_function<_ReturnT(
+_ArgTypes...) _LIBCPP_MOVE_ONLY_FUNCTION_CVREF 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT)> {
+private:
+  static constexpr size_t __buffer_size_  = 3 * sizeof(void*);
+  static constexpr size_t __buffer_alignment_ = alignof(void*);
+  using _BufferT  = __small_buffer<__buffer_size_, 
__buffer_alignment_>;
+
+  using _TrivialVTable= _MoveOnlyFunctionTrivialVTable<_BufferT, _ReturnT, 
_ArgTypes...>;
+  using _NonTrivialVTable = _MoveOnlyFunctionNonTrivialVTable<_BufferT, 
_ReturnT, _ArgTypes...>;
+
+  template 
+  static constexpr _TrivialVTable __trivial_vtable_ = {
+  .__call_ = [](_BufferT& __buffer, _ArgTypes... __args) 
noexcept(_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) -> _ReturnT {
+return std::invoke_r<_ReturnT>(
+static_cast<_Functor 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS>(*__buffer.__get<_Functor>()),
+std::forward<_ArgTypes>(__args)...);
+  }};
+
+  template 
+  static constexpr _NonTrivialVTable __non_trivial_vtable_{
+  __trivial_vtable_<_Functor>,
+  [](_BufferT& __buffer) noexcept -> void {
+std::destroy_at(__buffer.__get<_Functor>());
+__buffer.__dealloc<_Functor>();
+  },
+  };
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI __pointer_bool_pair 
__get_vptr() {
+if constexpr (_BufferT::__fits_in_buffer<_Functor> && 
is_trivially_destructible_v<_Functor>) {
+  return {&__trivial_vtable_<_Functor>, false};
+} else {
+  return {&__non_trivial_vtable_<_Functor>, true};
+}
+  }
+
+  template 
+  static constexpr bool __is_callable_from = [] {
+using _DVT = decay_t<_VT>;
+if (_LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT) {
+  return is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_CVREF, _ArgTypes...> &&
+ is_nothrow_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+} else {
+  return is_invocable_r_v<_ReturnT, _DVT _LIBCPP_MOVE_ONLY_FUNCTION_CVREF, 
_ArgTypes...> &&
+ is_invocable_r_v<_ReturnT, _DVT 
_LIBCPP_MOVE_ONLY_FUNCTION_INVOKE_QUALS, _ArgTypes...>;
+}
+  }();
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {
+static_assert(is_constructible_v, _Func>);
+
+using _StoredFunc = decay_t<_Func>;
+__vtable_ = __get_vptr<_StoredFunc>();
+__buffer_.__construct<_StoredFunc>(std::forward<_Args>(__args)...);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void __reset() {
+if (__vtable_.__get_value())

ldionne wrote:

> I've provided a complete & test-passing implementation to compare against. 
> It's the baseline I used for this review. I'm confident my results are 
> repeatable.

Sorry, I'm trying to follow the discussion after the fact but I can't find 
where you posted that implem

[llvm-branch-commits] [clang-doc][cmake] Copy assets to build directory (PR #95185)

2024-06-11 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/95185

While we copy the asset files, like index.js, into the
correct location in the install step, tests do not have
access to those resources in the build directory.

This patch copies the contents of the clang-doc/assets
directory into the build folder, so that they can be
used in testing.



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


[llvm-branch-commits] [clang-doc][cmake] Copy assets to build directory (PR #95185)

2024-06-11 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)


Changes

While we copy the asset files, like index.js, into the
correct location in the install step, tests do not have
access to those resources in the build directory.

This patch copies the contents of the clang-doc/assets
directory into the build folder, so that they can be
used in testing.


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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/tool/CMakeLists.txt (+8) 


``diff
diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index fb8317b272932..c2425747562b9 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,3 +25,11 @@ install(FILES ../assets/clang-doc-default-stylesheet.css
 install(FILES ../assets/index.js
   DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
   COMPONENT clang-doc)
+
+add_custom_target(copy-clang-doc-assets
+  COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different 
"${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang"
+  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets"
+  COMMENT "Copying Clang-Doc Assets"
+  )
+set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER 
"Clang-Doc/Assets")
+add_dependencies(clang-doc copy-clang-doc-assets)

``




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


[llvm-branch-commits] [clang-doc][cmake] Copy assets to build directory (PR #95185)

2024-06-11 Thread Paul Kirth via llvm-branch-commits

ilovepi wrote:

@petrhosek I'm pretty sure there's a better way to spell this, but I think we 
need something similar to properly test clang-doc w/o an install step.

cc: @PeterChou1 

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


[llvm-branch-commits] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-11 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


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


[llvm-branch-commits] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-11 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


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