[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time zone get_info(local_time). (PR #89537)
https://github.com/mordante created https://github.com/llvm/llvm-project/pull/89537 Implements parts of: - P0355 Extending to Calendars and Time Zones >From ed7053e22620924b6bc18a46cfd6d7201afab3fe 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 time zone get_info(local_time). Implements parts of: - P0355 Extending to Calendars and Time Zones --- libcxx/include/__chrono/time_zone.h |7 + libcxx/include/chrono |3 + libcxx/src/time_zone.cpp | 175 +++ .../chrono.nodiscard_extensions.verify.cpp|2 + .../get_info.local_time.pass.cpp | 1302 + 5 files changed, 1489 insertions(+) create mode 100644 libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.local_time.pass.cpp diff --git a/libcxx/include/__chrono/time_zone.h b/libcxx/include/__chrono/time_zone.h index 799602c1cdbaf0..3ea03683ccc187 100644 --- a/libcxx/include/__chrono/time_zone.h +++ b/libcxx/include/__chrono/time_zone.h @@ -17,6 +17,7 @@ #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) # include <__chrono/duration.h> +# include <__chrono/local_info.h> # include <__chrono/sys_info.h> # include <__chrono/system_clock.h> # include <__compare/strong_order.h> @@ -63,12 +64,18 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone { return __get_info(chrono::time_point_cast(__time)); } + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_info get_info(const local_time<_Duration>& __time) const { +return __get_info(chrono::time_point_cast(__time)); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const noexcept { return *__impl_; } private: [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept; [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info __get_info(sys_seconds __time) const; + [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info __get_info(local_seconds __time) const; unique_ptr<__impl> __impl_; }; diff --git a/libcxx/include/chrono b/libcxx/include/chrono index 96a3e92faa81f2..4d8398af1a108f 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -763,6 +763,9 @@ class time_zone { template sys_info get_info(const sys_time& st) const; + + template + local_info get_info(const local_time& tp) const; }; bool operator==(const time_zone& x, const time_zone& y) noexcept; // C++20 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept; // C++20 diff --git a/libcxx/src/time_zone.cpp b/libcxx/src/time_zone.cpp index 928f3d2855e456..24c22859080e10 100644 --- a/libcxx/src/time_zone.cpp +++ b/libcxx/src/time_zone.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "include/tzdb/time_zone_private.h" @@ -903,6 +904,180 @@ time_zone::__get_info(sys_seconds __time) const { std::__throw_runtime_error("tzdb: corrupt db"); } +enum class __position { + __beginning, + __middle, + __end, +}; + +// Determines the position of "__time" inside "__info". +// +// The code picks an arbitrary value to determine the "middle" +// - Every time that is more than the threshold from a boundary, or +// - Every value that is at the boundary sys_seconds::min() or +// sys_seconds::max(). +// +// If not in the middle, it returns __beginning or __end. +[[nodiscard]] static __position __get_position(sys_seconds __time, const sys_info __info) { + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( + __time >= __info.begin && __time < __info.end, "A value outside the range's position can't be determined."); + + using _Tp = sys_seconds::rep; + // Africa/Freetown has a 4 day "zone" + // Africa/Freetown Fri Sep 1 00:59:59 1939 UT = Thu Aug 31 23:59:59 1939 -01 isdst=0 gmtoff=-3600 + // Africa/Freetown Fri Sep 1 01:00:00 1939 UT = Fri Sep 1 00:20:00 1939 -0040 isdst=1 gmtoff=-2400 + // Africa/Freetown Tue Sep 5 00:39:59 1939 UT = Mon Sep 4 23:59:59 1939 -0040 isdst=1 gmtoff=-2400 + // Africa/Freetown Tue Sep 5 00:40:00 1939 UT = Mon Sep 4 23:40:00 1939 -01 isdst=0 gmtoff=-3600 + // + // Originally used a one week threshold, but due to this switched to 1 day. + // This seems to work in practice. + // + // TODO TZDB Evaluate the proper threshold. + constexpr _Tp __threshold = 24 * 3600; + + _Tp __upper = std::__add_sat(__info.begin.time_since_epoch().count(), __threshold); + if (__time >= __info.begin && __time.time_since_epoch().count() < __upper) +return __info.begin != sys_seconds::min() ? __position::__beginning : __position::__middle; + + _Tp __lower = std::__sub_sat(__info.end.time_since_epoch().count(), __threshold); + if (__time < __info.end && __time.time_since_epoch().count() >= __lower) +return __info.end != sys_seconds::max() ? __position::__end : __position::__middle; + + return __position:
[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time zone get_info(local_time). (PR #89537)
llvmbot wrote: @llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) Changes Implements parts of: - P0355 Extending to Calendars and Time Zones --- Patch is 63.94 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/89537.diff 5 Files Affected: - (modified) libcxx/include/__chrono/time_zone.h (+7) - (modified) libcxx/include/chrono (+3) - (modified) libcxx/src/time_zone.cpp (+175) - (modified) libcxx/test/libcxx/diagnostics/chrono.nodiscard_extensions.verify.cpp (+2) - (added) libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.local_time.pass.cpp (+1302) ``diff diff --git a/libcxx/include/__chrono/time_zone.h b/libcxx/include/__chrono/time_zone.h index 799602c1cdbaf0..3ea03683ccc187 100644 --- a/libcxx/include/__chrono/time_zone.h +++ b/libcxx/include/__chrono/time_zone.h @@ -17,6 +17,7 @@ #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) # include <__chrono/duration.h> +# include <__chrono/local_info.h> # include <__chrono/sys_info.h> # include <__chrono/system_clock.h> # include <__compare/strong_order.h> @@ -63,12 +64,18 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone { return __get_info(chrono::time_point_cast(__time)); } + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_info get_info(const local_time<_Duration>& __time) const { +return __get_info(chrono::time_point_cast(__time)); + } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const noexcept { return *__impl_; } private: [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept; [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info __get_info(sys_seconds __time) const; + [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info __get_info(local_seconds __time) const; unique_ptr<__impl> __impl_; }; diff --git a/libcxx/include/chrono b/libcxx/include/chrono index 96a3e92faa81f2..4d8398af1a108f 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -763,6 +763,9 @@ class time_zone { template sys_info get_info(const sys_time& st) const; + + template + local_info get_info(const local_time& tp) const; }; bool operator==(const time_zone& x, const time_zone& y) noexcept; // C++20 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept; // C++20 diff --git a/libcxx/src/time_zone.cpp b/libcxx/src/time_zone.cpp index 928f3d2855e456..24c22859080e10 100644 --- a/libcxx/src/time_zone.cpp +++ b/libcxx/src/time_zone.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "include/tzdb/time_zone_private.h" @@ -903,6 +904,180 @@ time_zone::__get_info(sys_seconds __time) const { std::__throw_runtime_error("tzdb: corrupt db"); } +enum class __position { + __beginning, + __middle, + __end, +}; + +// Determines the position of "__time" inside "__info". +// +// The code picks an arbitrary value to determine the "middle" +// - Every time that is more than the threshold from a boundary, or +// - Every value that is at the boundary sys_seconds::min() or +// sys_seconds::max(). +// +// If not in the middle, it returns __beginning or __end. +[[nodiscard]] static __position __get_position(sys_seconds __time, const sys_info __info) { + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( + __time >= __info.begin && __time < __info.end, "A value outside the range's position can't be determined."); + + using _Tp = sys_seconds::rep; + // Africa/Freetown has a 4 day "zone" + // Africa/Freetown Fri Sep 1 00:59:59 1939 UT = Thu Aug 31 23:59:59 1939 -01 isdst=0 gmtoff=-3600 + // Africa/Freetown Fri Sep 1 01:00:00 1939 UT = Fri Sep 1 00:20:00 1939 -0040 isdst=1 gmtoff=-2400 + // Africa/Freetown Tue Sep 5 00:39:59 1939 UT = Mon Sep 4 23:59:59 1939 -0040 isdst=1 gmtoff=-2400 + // Africa/Freetown Tue Sep 5 00:40:00 1939 UT = Mon Sep 4 23:40:00 1939 -01 isdst=0 gmtoff=-3600 + // + // Originally used a one week threshold, but due to this switched to 1 day. + // This seems to work in practice. + // + // TODO TZDB Evaluate the proper threshold. + constexpr _Tp __threshold = 24 * 3600; + + _Tp __upper = std::__add_sat(__info.begin.time_since_epoch().count(), __threshold); + if (__time >= __info.begin && __time.time_since_epoch().count() < __upper) +return __info.begin != sys_seconds::min() ? __position::__beginning : __position::__middle; + + _Tp __lower = std::__sub_sat(__info.end.time_since_epoch().count(), __threshold); + if (__time < __info.end && __time.time_since_epoch().count() >= __lower) +return __info.end != sys_seconds::max() ? __position::__end : __position::__middle; + + return __position::__middle; +} + +[[nodiscard]] static local_info +__get_info(local_seconds __local_time, const sys_info& __first, const sys_info& __second) { + std::chrono::local_seconds __end_first{__first.end.time_since_epoch()
[llvm-branch-commits] [llvm] release/18.x: [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) (PR #89546)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/89546 Backport 6309440c218778db027306826993e484eab2be17 Requested by: @dtcxzyw >From 6aa164f0a24b2f68a2983fab3e37b130c643247b Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 21 Apr 2024 22:41:32 +0800 Subject: [PATCH] [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) Fixes #89516 (cherry picked from commit 6309440c218778db027306826993e484eab2be17) --- .../InstCombine/InstCombineSelect.cpp | 2 +- .../Transforms/InstCombine/select-divrem.ll | 17 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 9f220ec003ec33..8cc7901cbac7fa 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2606,7 +2606,7 @@ static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC, // %cnd = icmp slt i32 %rem, 0 // %add = add i32 %rem, %n // %sel = select i1 %cnd, i32 %add, i32 %rem - if (match(TrueVal, m_Add(m_Value(RemRes), m_Value(Remainder))) && + if (match(TrueVal, m_Add(m_Specific(RemRes), m_Value(Remainder))) && match(RemRes, m_SRem(m_Value(Op), m_Specific(Remainder))) && IC.isKnownToBeAPowerOfTwo(Remainder, /*OrZero*/ true) && FalseVal == RemRes) diff --git a/llvm/test/Transforms/InstCombine/select-divrem.ll b/llvm/test/Transforms/InstCombine/select-divrem.ll index f007c53359ca5a..e0c460c37451db 100644 --- a/llvm/test/Transforms/InstCombine/select-divrem.ll +++ b/llvm/test/Transforms/InstCombine/select-divrem.ll @@ -343,3 +343,20 @@ define i32 @rem_euclid_pow2_false_arm_folded(i32 %n) { %res = select i1 %nonneg, i32 %rem, i32 1 ret i32 %res } + +define i8 @pr89516(i8 %n, i8 %x) { +; CHECK-LABEL: @pr89516( +; CHECK-NEXT:[[COND:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT:[[POW2:%.*]] = shl nuw i8 1, [[N:%.*]] +; CHECK-NEXT:[[SREM:%.*]] = srem i8 1, [[POW2]] +; CHECK-NEXT:[[ADD:%.*]] = select i1 [[COND]], i8 [[POW2]], i8 0 +; CHECK-NEXT:[[RES:%.*]] = add nuw i8 [[SREM]], [[ADD]] +; CHECK-NEXT:ret i8 [[RES]] +; + %cond = icmp slt i8 %x, 0 + %pow2 = shl nuw i8 1, %n + %srem = srem i8 1, %pow2 + %add = add nuw i8 %srem, %pow2 + %res = select i1 %cond, i8 %add, i8 %srem + ret i8 %res +} ___ 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] release/18.x: [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) (PR #89546)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/89546 ___ 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] release/18.x: [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) (PR #89546)
llvmbot wrote: @nikic What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/89546 ___ 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] release/18.x: [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) (PR #89546)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms Author: None (llvmbot) Changes Backport 6309440c218778db027306826993e484eab2be17 Requested by: @dtcxzyw --- Full diff: https://github.com/llvm/llvm-project/pull/89546.diff 2 Files Affected: - (modified) llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp (+1-1) - (modified) llvm/test/Transforms/InstCombine/select-divrem.ll (+17) ``diff diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 9f220ec003ec33..8cc7901cbac7fa 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2606,7 +2606,7 @@ static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC, // %cnd = icmp slt i32 %rem, 0 // %add = add i32 %rem, %n // %sel = select i1 %cnd, i32 %add, i32 %rem - if (match(TrueVal, m_Add(m_Value(RemRes), m_Value(Remainder))) && + if (match(TrueVal, m_Add(m_Specific(RemRes), m_Value(Remainder))) && match(RemRes, m_SRem(m_Value(Op), m_Specific(Remainder))) && IC.isKnownToBeAPowerOfTwo(Remainder, /*OrZero*/ true) && FalseVal == RemRes) diff --git a/llvm/test/Transforms/InstCombine/select-divrem.ll b/llvm/test/Transforms/InstCombine/select-divrem.ll index f007c53359ca5a..e0c460c37451db 100644 --- a/llvm/test/Transforms/InstCombine/select-divrem.ll +++ b/llvm/test/Transforms/InstCombine/select-divrem.ll @@ -343,3 +343,20 @@ define i32 @rem_euclid_pow2_false_arm_folded(i32 %n) { %res = select i1 %nonneg, i32 %rem, i32 1 ret i32 %res } + +define i8 @pr89516(i8 %n, i8 %x) { +; CHECK-LABEL: @pr89516( +; CHECK-NEXT:[[COND:%.*]] = icmp slt i8 [[X:%.*]], 0 +; CHECK-NEXT:[[POW2:%.*]] = shl nuw i8 1, [[N:%.*]] +; CHECK-NEXT:[[SREM:%.*]] = srem i8 1, [[POW2]] +; CHECK-NEXT:[[ADD:%.*]] = select i1 [[COND]], i8 [[POW2]], i8 0 +; CHECK-NEXT:[[RES:%.*]] = add nuw i8 [[SREM]], [[ADD]] +; CHECK-NEXT:ret i8 [[RES]] +; + %cond = icmp slt i8 %x, 0 + %pow2 = shl nuw i8 1, %n + %srem = srem i8 1, %pow2 + %add = add nuw i8 %srem, %pow2 + %res = select i1 %cond, i8 %add, i8 %srem + ret i8 %res +} `` https://github.com/llvm/llvm-project/pull/89546 ___ 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] [flang] [flang][OpenMP] Support tasks' implicit firstprivate DSA (PR #85989)
https://github.com/kiranchandramohan edited https://github.com/llvm/llvm-project/pull/85989 ___ 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] [flang] [flang][OpenMP] Support tasks' implicit firstprivate DSA (PR #85989)
@@ -2012,34 +2012,87 @@ void OmpAttributeVisitor::Post(const parser::Name &name) { } } } -std::vector defaultDSASymbols; + +// Implicitly determined DSAs +// OMP 5.2 5.1.1 - Variables Referenced in a Construct +Symbol *lastDeclSymbol = nullptr; +std::optional prevDSA; for (int dirDepth{0}; dirDepth < (int)dirContext_.size(); ++dirDepth) { DirContext &dirContext = dirContext_[dirDepth]; - bool hasDataSharingAttr{false}; + std::optional dsa; + for (auto symMap : dirContext.objectWithDSA) { // if the `symbol` already has a data-sharing attribute if (symMap.first->name() == name.symbol->name()) { - hasDataSharingAttr = true; + dsa = symMap.second; break; } } - if (hasDataSharingAttr) { -if (defaultDSASymbols.size()) - symbol = &MakeAssocSymbol(symbol->name(), *defaultDSASymbols.back(), + + // When handling each implicit rule, either a new private symbol is + // declared or the last declared symbol is used. + // In the latter case, it's necessary to insert a new symbol in the scope + // being processed, associated with the last declared symbol, to avoid + // "inheriting" the enclosing context's symbol and its flags. kiranchandramohan wrote: Can you expand the `latter case`? On a first look it feels like we should be OK with just inheriting the enclosing context's symbol and its flags. Probably you have to say something like we have to create a new symbol to capture the fact that although we are using the last declared symbol its datasharing attribute could be different in this scope and give an example. https://github.com/llvm/llvm-project/pull/85989 ___ 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] [flang] [flang][OpenMP] Support tasks' implicit firstprivate DSA (PR #85989)
https://github.com/kiranchandramohan approved this pull request. LG. Nice work. https://github.com/llvm/llvm-project/pull/85989 ___ 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] release/18.x: [GlobalISel] Fix fewerElementsVectorPhi to insert after G_PHIs (#87927) (PR #89240)
AtariDreams wrote: @arsenm I do not have commit perms https://github.com/llvm/llvm-project/pull/89240 ___ 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] release/18.x: [AArch64] Remove invalid uabdl patterns. (#89272) (PR #89380)
AtariDreams wrote: @arsenm @nikic What do you think about this? https://github.com/llvm/llvm-project/pull/89380 ___ 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] release/18.x: [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) (PR #89546)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/89546 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits