[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)

2025-04-02 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134035

>From 8826cbf1cceed6078d1cecbc12e3061d91924bd2 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 2 Apr 2025 11:45:24 +0700
Subject: [PATCH 1/4] llvm-reduce: Change function return types if function is
 not called

Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.
---
 ...reduce-values-to-return-new-return-type.ll | 95 +++
 .../llvm-reduce/reduce-values-to-return.ll| 20 +++-
 .../deltas/ReduceValuesToReturn.cpp   |  7 +-
 3 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 
llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll

diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
new file mode 100644
index 0..9ddbbe3def44f
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
@@ -0,0 +1,95 @@
+; Test that llvm-reduce can move intermediate values by inserting
+; early returns when the function already has a different return type
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=RESULT %s < %t
+
+
+@gv = global i32 0, align 4
+@ptr_array = global [2 x ptr] [ptr 
@inst_to_return_has_different_type_but_no_func_call_use,
+   ptr @multiple_callsites_wrong_return_type]
+
+; Should rewrite this return from i64 to i32 since the function has no
+; uses.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_no_func_call_use(
+; RESULT-LABEL: define i32 
@inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+; RESULT-NEXT: %load = load i32, ptr %arg, align 4
+; RESULT-NEXT: ret i32 %load
+define i64 @inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @callsite_different_type_unused_0(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-NEXT: %load = load i32, ptr %arg
+; RESULT-NEXT: store i32 %load, ptr @gv
+; RESULT-NEXT: ret i64 0
+define void @callsite_different_type_unused_0(ptr %arg) {
+  %unused0 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
+  %unused1 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr null)
+  ret void
+}
+
+; TODO: Could rewrite this return from i64 to i32 since the callsite is unused.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT: ret i64 0
+define i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg) 
{
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @multiple_callsites_wrong_return_type(
+; RESULT-LABEL: define i64 @multiple_callsites_wrong_return_type(
+; RESULT: ret i64 0
+define i64 @multiple_callsites_wrong_return_type(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @unused_with_wrong_return_types(
+; RESULT-LABEL: define i64 @unused_with_wrong_return_types(
+; RESULT-NEXT: %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr 
%arg)
+; RESULT-NEXT: ret i64 %unused0
+define void @unused_with_wrong_return_types(ptr %arg) {
+  %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused1 = call i32 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused2 = call ptr @multiple_callsites_wrong_return_type(ptr %arg)
+  ret void
+}
+
+; INTERESTING-LABEL: @multiple_returns_wrong_return_type(
+; INTERESTING: %load0 = load i32,
+
+; RESULT-LABEL: define i32 @multiple_returns_wrong_return_type(
+; RESULT: ret i32
+; RESULT: ret i32
+; RESULT: ret i32
+define i32 @multiple_returns_wrong_return_type(ptr %arg, i1 %cond, i32 %arg2) {
+entry:
+  br i1 %cond, label %bb0, label %bb1
+
+bb0:
+  %load0 = load i32, ptr %arg
+  store i32 %load0, ptr @gv
+  ret i32 234
+
+bb1:
+  ret i32 %arg2
+
+bb2:
+  ret i32 34
+}
+
+; INTERESTING-LABEL: @call_multiple_returns_wrong_return_type(
+; RESULT-LABEL: define <2 x i32> @call_multiple_returns_wrong_return_type(
+; RESULT-NEXT: %unused = call <2 x i32> @multiple_returns_wrong_return_type(
+; RESULT-NEXT: ret <2 x i32> %unused
+define void @call_multiple_returns_wrong_return_type

[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)

2025-04-02 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134035

>From c6252c5dc0d1326a139c73a75b2a7892d0670ad0 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 2 Apr 2025 11:45:24 +0700
Subject: [PATCH 1/4] llvm-reduce: Change function return types if function is
 not called

Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.
---
 ...reduce-values-to-return-new-return-type.ll | 95 +++
 .../llvm-reduce/reduce-values-to-return.ll| 20 +++-
 .../deltas/ReduceValuesToReturn.cpp   |  7 +-
 3 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 
llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll

diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
new file mode 100644
index 0..9ddbbe3def44f
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
@@ -0,0 +1,95 @@
+; Test that llvm-reduce can move intermediate values by inserting
+; early returns when the function already has a different return type
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=RESULT %s < %t
+
+
+@gv = global i32 0, align 4
+@ptr_array = global [2 x ptr] [ptr 
@inst_to_return_has_different_type_but_no_func_call_use,
+   ptr @multiple_callsites_wrong_return_type]
+
+; Should rewrite this return from i64 to i32 since the function has no
+; uses.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_no_func_call_use(
+; RESULT-LABEL: define i32 
@inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+; RESULT-NEXT: %load = load i32, ptr %arg, align 4
+; RESULT-NEXT: ret i32 %load
+define i64 @inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @callsite_different_type_unused_0(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-NEXT: %load = load i32, ptr %arg
+; RESULT-NEXT: store i32 %load, ptr @gv
+; RESULT-NEXT: ret i64 0
+define void @callsite_different_type_unused_0(ptr %arg) {
+  %unused0 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
+  %unused1 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr null)
+  ret void
+}
+
+; TODO: Could rewrite this return from i64 to i32 since the callsite is unused.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT: ret i64 0
+define i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg) 
{
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @multiple_callsites_wrong_return_type(
+; RESULT-LABEL: define i64 @multiple_callsites_wrong_return_type(
+; RESULT: ret i64 0
+define i64 @multiple_callsites_wrong_return_type(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @unused_with_wrong_return_types(
+; RESULT-LABEL: define i64 @unused_with_wrong_return_types(
+; RESULT-NEXT: %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr 
%arg)
+; RESULT-NEXT: ret i64 %unused0
+define void @unused_with_wrong_return_types(ptr %arg) {
+  %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused1 = call i32 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused2 = call ptr @multiple_callsites_wrong_return_type(ptr %arg)
+  ret void
+}
+
+; INTERESTING-LABEL: @multiple_returns_wrong_return_type(
+; INTERESTING: %load0 = load i32,
+
+; RESULT-LABEL: define i32 @multiple_returns_wrong_return_type(
+; RESULT: ret i32
+; RESULT: ret i32
+; RESULT: ret i32
+define i32 @multiple_returns_wrong_return_type(ptr %arg, i1 %cond, i32 %arg2) {
+entry:
+  br i1 %cond, label %bb0, label %bb1
+
+bb0:
+  %load0 = load i32, ptr %arg
+  store i32 %load0, ptr @gv
+  ret i32 234
+
+bb1:
+  ret i32 %arg2
+
+bb2:
+  ret i32 34
+}
+
+; INTERESTING-LABEL: @call_multiple_returns_wrong_return_type(
+; RESULT-LABEL: define <2 x i32> @call_multiple_returns_wrong_return_type(
+; RESULT-NEXT: %unused = call <2 x i32> @multiple_returns_wrong_return_type(
+; RESULT-NEXT: ret <2 x i32> %unused
+define void @call_multiple_returns_wrong_return_type

[llvm-branch-commits] [libcxx] [libc++][C++03] Remove code that is not used in C++03 (PR #134045)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)


Changes



---

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


308 Files Affected:

- (modified) libcxx/include/__cxx03/__algorithm/equal.h (-59) 
- (modified) libcxx/include/__cxx03/__algorithm/for_each.h (-15) 
- (modified) libcxx/include/__cxx03/__algorithm/is_permutation.h (-53) 
- (modified) libcxx/include/__cxx03/__algorithm/iterator_operations.h (-25) 
- (modified) libcxx/include/__cxx03/__algorithm/make_projected.h (-29) 
- (modified) libcxx/include/__cxx03/__algorithm/max.h (-15) 
- (modified) libcxx/include/__cxx03/__algorithm/min.h (-15) 
- (modified) libcxx/include/__cxx03/__algorithm/minmax.h (-19) 
- (modified) libcxx/include/__cxx03/__algorithm/mismatch.h (-46) 
- (modified) libcxx/include/__cxx03/__algorithm/search.h (-9) 
- (modified) libcxx/include/__cxx03/__algorithm/shuffle.h (+1-10) 
- (modified) libcxx/include/__cxx03/__algorithm/simd_utils.h (+1-5) 
- (modified) libcxx/include/__cxx03/__algorithm/sort.h (-22) 
- (modified) libcxx/include/__cxx03/__algorithm/three_way_comp_ref_type.h (-48) 
- (modified) 
libcxx/include/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h (-38) 
- (modified) libcxx/include/__cxx03/__algorithm/unwrap_iter.h (-8) 
- (modified) libcxx/include/__cxx03/__algorithm/unwrap_range.h (-51) 
- (modified) libcxx/include/__cxx03/__atomic/aliases.h (-25) 
- (modified) libcxx/include/__cxx03/__atomic/atomic.h (-134) 
- (modified) libcxx/include/__cxx03/__atomic/atomic_base.h (-8) 
- (modified) libcxx/include/__cxx03/__atomic/atomic_flag.h (-5) 
- (modified) libcxx/include/__cxx03/__atomic/atomic_init.h (-4) 
- (modified) libcxx/include/__cxx03/__atomic/cxx_atomic_impl.h (-8) 
- (modified) libcxx/include/__cxx03/__atomic/memory_order.h (-25) 
- (modified) libcxx/include/__cxx03/__bit/countl.h (-14) 
- (modified) libcxx/include/__cxx03/__bit/countr.h (-14) 
- (modified) libcxx/include/__cxx03/__bit/popcount.h (-26) 
- (modified) libcxx/include/__cxx03/__bit/rotate.h (-14) 
- (modified) libcxx/include/__cxx03/__bit_reference (+1-30) 
- (modified) libcxx/include/__cxx03/__chrono/duration.h (+2-125) 
- (modified) libcxx/include/__cxx03/__chrono/system_clock.h (-9) 
- (modified) libcxx/include/__cxx03/__chrono/time_point.h (-36) 
- (modified) libcxx/include/__cxx03/__config (+18-130) 
- (modified) libcxx/include/__cxx03/__configuration/language.h (-19) 
- (modified) libcxx/include/__cxx03/__debug_utils/randomize_range.h (+1-3) 
- (modified) libcxx/include/__cxx03/__exception/operations.h (-3) 
- (modified) libcxx/include/__cxx03/__functional/binary_function.h (-11) 
- (modified) libcxx/include/__cxx03/__functional/binary_negate.h (-4) 
- (modified) libcxx/include/__cxx03/__functional/bind.h (-226) 
- (modified) libcxx/include/__cxx03/__functional/binder1st.h (-4) 
- (modified) libcxx/include/__cxx03/__functional/binder2nd.h (-4) 
- (modified) libcxx/include/__cxx03/__functional/hash.h (-33) 
- (modified) libcxx/include/__cxx03/__functional/identity.h (-20) 
- (modified) libcxx/include/__cxx03/__functional/mem_fun_ref.h (-4) 
- (modified) libcxx/include/__cxx03/__functional/operations.h (-328) 
- (modified) libcxx/include/__cxx03/__functional/pointer_to_binary_function.h 
(-4) 
- (modified) libcxx/include/__cxx03/__functional/pointer_to_unary_function.h 
(-4) 
- (modified) libcxx/include/__cxx03/__functional/reference_wrapper.h (-58) 
- (modified) libcxx/include/__cxx03/__functional/unary_function.h (-11) 
- (modified) libcxx/include/__cxx03/__functional/unary_negate.h (-4) 
- (modified) libcxx/include/__cxx03/__functional/weak_result_type.h (-22) 
- (modified) libcxx/include/__cxx03/__fwd/array.h (-8) 
- (modified) libcxx/include/__cxx03/__fwd/complex.h (-16) 
- (modified) libcxx/include/__cxx03/__fwd/pair.h (-10) 
- (modified) libcxx/include/__cxx03/__fwd/string.h (-33) 
- (modified) libcxx/include/__cxx03/__fwd/tuple.h (-26) 
- (modified) libcxx/include/__cxx03/__hash_table (-161) 
- (modified) libcxx/include/__cxx03/__iterator/access.h (-41) 
- (modified) libcxx/include/__cxx03/__iterator/advance.h (-127) 
- (modified) libcxx/include/__cxx03/__iterator/back_insert_iterator.h (-13) 
- (modified) libcxx/include/__cxx03/__iterator/bounded_iter.h (-24) 
- (modified) libcxx/include/__cxx03/__iterator/cpp17_iterator_concepts.h (-149) 
- (modified) libcxx/include/__cxx03/__iterator/distance.h (-47) 
- (modified) libcxx/include/__cxx03/__iterator/front_insert_iterator.h (-13) 
- (modified) libcxx/include/__cxx03/__iterator/insert_iterator.h (-19) 
- (modified) libcxx/include/__cxx03/__iterator/istream_iterator.h (-13) 
- (modified) libcxx/include/__cxx03/__iterator/istreambuf_iterator.h (-13) 
- (modified) libcxx/include/__cxx03/__iterator/iterator_traits.h (-272) 
- (modified) libcxx/include/__cxx03/__iterator/move_iterator.h (-153) 
- (modified) libcxx/include/__cxx03/__iterator/next.h (-42) 
- (modified) libc

[llvm-branch-commits] [libcxx] [libc++][C++03] Remove macros that expand to nothing (PR #134046)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)


Changes



---

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


230 Files Affected:

- (modified) libcxx/include/__cxx03/__algorithm/adjacent_find.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/all_of.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/any_of.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/binary_search.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/comp.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/comp_ref_type.h (+6-7) 
- (modified) libcxx/include/__cxx03/__algorithm/copy.h (+9-15) 
- (modified) libcxx/include/__cxx03/__algorithm/copy_backward.h (+7-12) 
- (modified) libcxx/include/__cxx03/__algorithm/copy_if.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/copy_move_common.h (+4-6) 
- (modified) libcxx/include/__cxx03/__algorithm/copy_n.h (+2-4) 
- (modified) libcxx/include/__cxx03/__algorithm/count.h (+4-4) 
- (modified) libcxx/include/__cxx03/__algorithm/count_if.h (+1-2) 
- (modified) libcxx/include/__cxx03/__algorithm/equal.h (+4-4) 
- (modified) libcxx/include/__cxx03/__algorithm/equal_range.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/fill.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/fill_n.h (+5-9) 
- (modified) libcxx/include/__cxx03/__algorithm/find.h (+10-13) 
- (modified) libcxx/include/__cxx03/__algorithm/find_end.h (+6-6) 
- (modified) libcxx/include/__cxx03/__algorithm/find_first_of.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/find_if.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/find_if_not.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/find_segment_if.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/for_each.h (+1-2) 
- (modified) libcxx/include/__cxx03/__algorithm/for_each_segment.h (+1-2) 
- (modified) libcxx/include/__cxx03/__algorithm/generate.h (+1-2) 
- (modified) libcxx/include/__cxx03/__algorithm/generate_n.h (+1-2) 
- (modified) libcxx/include/__cxx03/__algorithm/half_positive.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/includes.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/is_heap.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/is_heap_until.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/is_partitioned.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/is_permutation.h (+7-7) 
- (modified) libcxx/include/__cxx03/__algorithm/is_sorted.h (+2-3) 
- (modified) libcxx/include/__cxx03/__algorithm/is_sorted_until.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/iter_swap.h (+1-3) 
- (modified) libcxx/include/__cxx03/__algorithm/iterator_operations.h (+14-15) 
- (modified) libcxx/include/__cxx03/__algorithm/lexicographical_compare.h 
(+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/lower_bound.h (+5-5) 
- (modified) libcxx/include/__cxx03/__algorithm/make_heap.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/make_projected.h (+5-7) 
- (modified) libcxx/include/__cxx03/__algorithm/max.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/max_element.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/merge.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/min.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/min_element.h (+4-5) 
- (modified) libcxx/include/__cxx03/__algorithm/minmax.h (+2-2) 
- (modified) libcxx/include/__cxx03/__algorithm/minmax_element.h (+5-6) 
- (modified) libcxx/include/__cxx03/__algorithm/mismatch.h (+7-7) 
- (modified) libcxx/include/__cxx03/__algorithm/move.h (+9-16) 
- (modified) libcxx/include/__cxx03/__algorithm/move_backward.h (+7-11) 
- (modified) libcxx/include/__cxx03/__algorithm/next_permutation.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/none_of.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/nth_element.h (+5-5) 
- (modified) libcxx/include/__cxx03/__algorithm/partial_sort.h (+4-4) 
- (modified) libcxx/include/__cxx03/__algorithm/partial_sort_copy.h (+3-3) 
- (modified) libcxx/include/__cxx03/__algorithm/partition.h (+4-4) 
- (modified) libcxx/include/__cxx03/__algorithm/partition_copy.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/partition_point.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/pop_heap.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/prev_permutation.h (+3-4) 
- (modified) libcxx/include/__cxx03/__algorithm/push_heap.h (+4-5) 
- (modified) libcxx/include/__cxx03/__algorithm/remove.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/remove_copy.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/remove_copy_if.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/remove_if.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/replace.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algorithm/replace_copy.h (+1-1) 
- (modified) libcxx/include/__cxx03/__algo

[llvm-branch-commits] [libcxx] [libc++][C++03] Remove code that is not used in C++03 (PR #134045)

2025-04-02 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions ,h -- 
libcxx/include/__cxx03/__algorithm/equal.h 
libcxx/include/__cxx03/__algorithm/for_each.h 
libcxx/include/__cxx03/__algorithm/is_permutation.h 
libcxx/include/__cxx03/__algorithm/iterator_operations.h 
libcxx/include/__cxx03/__algorithm/make_projected.h 
libcxx/include/__cxx03/__algorithm/max.h 
libcxx/include/__cxx03/__algorithm/min.h 
libcxx/include/__cxx03/__algorithm/minmax.h 
libcxx/include/__cxx03/__algorithm/mismatch.h 
libcxx/include/__cxx03/__algorithm/search.h 
libcxx/include/__cxx03/__algorithm/shuffle.h 
libcxx/include/__cxx03/__algorithm/simd_utils.h 
libcxx/include/__cxx03/__algorithm/sort.h 
libcxx/include/__cxx03/__algorithm/three_way_comp_ref_type.h 
libcxx/include/__cxx03/__algorithm/uniform_random_bit_generator_adaptor.h 
libcxx/include/__cxx03/__algorithm/unwrap_iter.h 
libcxx/include/__cxx03/__algorithm/unwrap_range.h 
libcxx/include/__cxx03/__atomic/aliases.h 
libcxx/include/__cxx03/__atomic/atomic.h 
libcxx/include/__cxx03/__atomic/atomic_base.h 
libcxx/include/__cxx03/__atomic/atomic_flag.h 
libcxx/include/__cxx03/__atomic/atomic_init.h 
libcxx/include/__cxx03/__atomic/cxx_atomic_impl.h 
libcxx/include/__cxx03/__atomic/memory_order.h 
libcxx/include/__cxx03/__bit/countl.h libcxx/include/__cxx03/__bit/countr.h 
libcxx/include/__cxx03/__bit/popcount.h libcxx/include/__cxx03/__bit/rotate.h 
libcxx/include/__cxx03/__bit_reference 
libcxx/include/__cxx03/__chrono/duration.h 
libcxx/include/__cxx03/__chrono/system_clock.h 
libcxx/include/__cxx03/__chrono/time_point.h libcxx/include/__cxx03/__config 
libcxx/include/__cxx03/__configuration/language.h 
libcxx/include/__cxx03/__debug_utils/randomize_range.h 
libcxx/include/__cxx03/__exception/operations.h 
libcxx/include/__cxx03/__functional/binary_function.h 
libcxx/include/__cxx03/__functional/binary_negate.h 
libcxx/include/__cxx03/__functional/bind.h 
libcxx/include/__cxx03/__functional/binder1st.h 
libcxx/include/__cxx03/__functional/binder2nd.h 
libcxx/include/__cxx03/__functional/hash.h 
libcxx/include/__cxx03/__functional/identity.h 
libcxx/include/__cxx03/__functional/mem_fun_ref.h 
libcxx/include/__cxx03/__functional/operations.h 
libcxx/include/__cxx03/__functional/pointer_to_binary_function.h 
libcxx/include/__cxx03/__functional/pointer_to_unary_function.h 
libcxx/include/__cxx03/__functional/reference_wrapper.h 
libcxx/include/__cxx03/__functional/unary_function.h 
libcxx/include/__cxx03/__functional/unary_negate.h 
libcxx/include/__cxx03/__functional/weak_result_type.h 
libcxx/include/__cxx03/__fwd/array.h libcxx/include/__cxx03/__fwd/complex.h 
libcxx/include/__cxx03/__fwd/pair.h libcxx/include/__cxx03/__fwd/string.h 
libcxx/include/__cxx03/__fwd/tuple.h libcxx/include/__cxx03/__hash_table 
libcxx/include/__cxx03/__iterator/access.h 
libcxx/include/__cxx03/__iterator/advance.h 
libcxx/include/__cxx03/__iterator/back_insert_iterator.h 
libcxx/include/__cxx03/__iterator/bounded_iter.h 
libcxx/include/__cxx03/__iterator/cpp17_iterator_concepts.h 
libcxx/include/__cxx03/__iterator/distance.h 
libcxx/include/__cxx03/__iterator/front_insert_iterator.h 
libcxx/include/__cxx03/__iterator/insert_iterator.h 
libcxx/include/__cxx03/__iterator/istream_iterator.h 
libcxx/include/__cxx03/__iterator/istreambuf_iterator.h 
libcxx/include/__cxx03/__iterator/iterator_traits.h 
libcxx/include/__cxx03/__iterator/move_iterator.h 
libcxx/include/__cxx03/__iterator/next.h 
libcxx/include/__cxx03/__iterator/ostream_iterator.h 
libcxx/include/__cxx03/__iterator/ostreambuf_iterator.h 
libcxx/include/__cxx03/__iterator/prev.h 
libcxx/include/__cxx03/__iterator/reverse_iterator.h 
libcxx/include/__cxx03/__iterator/wrap_iter.h libcxx/include/__cxx03/__locale 
libcxx/include/__cxx03/__locale_dir/locale_base_api/ibm.h 
libcxx/include/__cxx03/__math/hypot.h 
libcxx/include/__cxx03/__memory/addressof.h 
libcxx/include/__cxx03/__memory/aligned_alloc.h 
libcxx/include/__cxx03/__memory/allocate_at_least.h 
libcxx/include/__cxx03/__memory/allocator.h 
libcxx/include/__cxx03/__memory/allocator_arg_t.h 
libcxx/include/__cxx03/__memory/allocator_traits.h 
libcxx/include/__cxx03/__memory/assume_aligned.h 
libcxx/include/__cxx03/__memory/auto_ptr.h 
libcxx/include/__cxx03/__memory/compressed_pair.h 
libcxx/include/__cxx03/__memory/construct_at.h 
libcxx/include/__cxx03/__memory/pointer_traits.h 
libcxx/include/__cxx03/__memory/raw_storage_iterator.h 
libcxx/include/__cxx03/__memory/shared_ptr.h 
libcxx/include/__cxx03/__memory/swap_allocator.h 
libcxx/include/__cxx03/__memory/temp_value.h 
libcxx/include/__cxx03/__memory/uninitialized_algorithms.h 
libcxx/include/__cxx03/__memory/unique_ptr.h 
libcxx/include/__cxx03/__memory/uses_allocator.h 
libcxx/include/__cxx03/__mutex/once_flag.h 
libcxx/include/__cxx03/__mutex/tag_types.h 

[llvm-branch-commits] [libcxx] [libc++][C++03] Remove macros that expand to nothing (PR #134046)

2025-04-02 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions ,h -- 
libcxx/include/__cxx03/__algorithm/adjacent_find.h 
libcxx/include/__cxx03/__algorithm/all_of.h 
libcxx/include/__cxx03/__algorithm/any_of.h 
libcxx/include/__cxx03/__algorithm/binary_search.h 
libcxx/include/__cxx03/__algorithm/comp.h 
libcxx/include/__cxx03/__algorithm/comp_ref_type.h 
libcxx/include/__cxx03/__algorithm/copy.h 
libcxx/include/__cxx03/__algorithm/copy_backward.h 
libcxx/include/__cxx03/__algorithm/copy_if.h 
libcxx/include/__cxx03/__algorithm/copy_move_common.h 
libcxx/include/__cxx03/__algorithm/copy_n.h 
libcxx/include/__cxx03/__algorithm/count.h 
libcxx/include/__cxx03/__algorithm/count_if.h 
libcxx/include/__cxx03/__algorithm/equal.h 
libcxx/include/__cxx03/__algorithm/equal_range.h 
libcxx/include/__cxx03/__algorithm/fill.h 
libcxx/include/__cxx03/__algorithm/fill_n.h 
libcxx/include/__cxx03/__algorithm/find.h 
libcxx/include/__cxx03/__algorithm/find_end.h 
libcxx/include/__cxx03/__algorithm/find_first_of.h 
libcxx/include/__cxx03/__algorithm/find_if.h 
libcxx/include/__cxx03/__algorithm/find_if_not.h 
libcxx/include/__cxx03/__algorithm/find_segment_if.h 
libcxx/include/__cxx03/__algorithm/for_each.h 
libcxx/include/__cxx03/__algorithm/for_each_segment.h 
libcxx/include/__cxx03/__algorithm/generate.h 
libcxx/include/__cxx03/__algorithm/generate_n.h 
libcxx/include/__cxx03/__algorithm/half_positive.h 
libcxx/include/__cxx03/__algorithm/includes.h 
libcxx/include/__cxx03/__algorithm/is_heap.h 
libcxx/include/__cxx03/__algorithm/is_heap_until.h 
libcxx/include/__cxx03/__algorithm/is_partitioned.h 
libcxx/include/__cxx03/__algorithm/is_permutation.h 
libcxx/include/__cxx03/__algorithm/is_sorted.h 
libcxx/include/__cxx03/__algorithm/is_sorted_until.h 
libcxx/include/__cxx03/__algorithm/iter_swap.h 
libcxx/include/__cxx03/__algorithm/iterator_operations.h 
libcxx/include/__cxx03/__algorithm/lexicographical_compare.h 
libcxx/include/__cxx03/__algorithm/lower_bound.h 
libcxx/include/__cxx03/__algorithm/make_heap.h 
libcxx/include/__cxx03/__algorithm/make_projected.h 
libcxx/include/__cxx03/__algorithm/max.h 
libcxx/include/__cxx03/__algorithm/max_element.h 
libcxx/include/__cxx03/__algorithm/merge.h 
libcxx/include/__cxx03/__algorithm/min.h 
libcxx/include/__cxx03/__algorithm/min_element.h 
libcxx/include/__cxx03/__algorithm/minmax.h 
libcxx/include/__cxx03/__algorithm/minmax_element.h 
libcxx/include/__cxx03/__algorithm/mismatch.h 
libcxx/include/__cxx03/__algorithm/move.h 
libcxx/include/__cxx03/__algorithm/move_backward.h 
libcxx/include/__cxx03/__algorithm/next_permutation.h 
libcxx/include/__cxx03/__algorithm/none_of.h 
libcxx/include/__cxx03/__algorithm/nth_element.h 
libcxx/include/__cxx03/__algorithm/partial_sort.h 
libcxx/include/__cxx03/__algorithm/partial_sort_copy.h 
libcxx/include/__cxx03/__algorithm/partition.h 
libcxx/include/__cxx03/__algorithm/partition_copy.h 
libcxx/include/__cxx03/__algorithm/partition_point.h 
libcxx/include/__cxx03/__algorithm/pop_heap.h 
libcxx/include/__cxx03/__algorithm/prev_permutation.h 
libcxx/include/__cxx03/__algorithm/push_heap.h 
libcxx/include/__cxx03/__algorithm/remove.h 
libcxx/include/__cxx03/__algorithm/remove_copy.h 
libcxx/include/__cxx03/__algorithm/remove_copy_if.h 
libcxx/include/__cxx03/__algorithm/remove_if.h 
libcxx/include/__cxx03/__algorithm/replace.h 
libcxx/include/__cxx03/__algorithm/replace_copy.h 
libcxx/include/__cxx03/__algorithm/replace_copy_if.h 
libcxx/include/__cxx03/__algorithm/replace_if.h 
libcxx/include/__cxx03/__algorithm/reverse.h 
libcxx/include/__cxx03/__algorithm/reverse_copy.h 
libcxx/include/__cxx03/__algorithm/rotate.h 
libcxx/include/__cxx03/__algorithm/rotate_copy.h 
libcxx/include/__cxx03/__algorithm/search.h 
libcxx/include/__cxx03/__algorithm/search_n.h 
libcxx/include/__cxx03/__algorithm/set_difference.h 
libcxx/include/__cxx03/__algorithm/set_intersection.h 
libcxx/include/__cxx03/__algorithm/set_symmetric_difference.h 
libcxx/include/__cxx03/__algorithm/set_union.h 
libcxx/include/__cxx03/__algorithm/shuffle.h 
libcxx/include/__cxx03/__algorithm/sift_down.h 
libcxx/include/__cxx03/__algorithm/sort.h 
libcxx/include/__cxx03/__algorithm/sort_heap.h 
libcxx/include/__cxx03/__algorithm/swap_ranges.h 
libcxx/include/__cxx03/__algorithm/transform.h 
libcxx/include/__cxx03/__algorithm/unique.h 
libcxx/include/__cxx03/__algorithm/unique_copy.h 
libcxx/include/__cxx03/__algorithm/unwrap_iter.h 
libcxx/include/__cxx03/__algorithm/unwrap_range.h 
libcxx/include/__cxx03/__algorithm/upper_bound.h 
libcxx/include/__cxx03/__atomic/atomic.h 
libcxx/include/__cxx03/__atomic/atomic_base.h 
libcxx/include/__cxx03/__atomic/atomic_flag.h 
libcxx/include/__cxx03/__atomic/cxx_atomic_impl.h 
libcxx/include/__cxx03/__atomic/to_gcc_order.h 
libcxx/include/__cxx03/__bit/blsr.h libcxx/

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/7] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [clang] [clang] NFC: introduce UnsignedOrNone as a replacement for std::optional (PR #134142)

2025-04-02 Thread Younan Zhang via llvm-branch-commits

https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/134142
___
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] [clang] NFC: introduce UnsignedOrNone as a replacement for std::optional (PR #134142)

2025-04-02 Thread Younan Zhang via llvm-branch-commits

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

One question otherwise LGTM!

https://github.com/llvm/llvm-project/pull/134142
___
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] [clang] NFC: introduce UnsignedOrNone as a replacement for std::optional (PR #134142)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits


@@ -13343,28 +13344,25 @@ class Sema final : public SemaBase {
   /// The current index into pack expansion arguments that will be
   /// used for substitution of parameter packs.
   ///
-  /// The pack expansion index will be -1 to indicate that parameter packs
+  /// The pack expansion index will be none to indicate that parameter packs
   /// should be instantiated as themselves. Otherwise, the index specifies
   /// which argument within the parameter pack will be used for substitution.
-  int ArgumentPackSubstitutionIndex;
+  UnsignedOrNone ArgPackSubstIndex;
 
   /// RAII object used to change the argument pack substitution index
   /// within a \c Sema object.
   ///
-  /// See \c ArgumentPackSubstitutionIndex for more information.
-  class ArgumentPackSubstitutionIndexRAII {
+  /// See \c ArgPackSubstIndex for more information.
+  class ArgPackSubstIndexRAII {

mizvekov wrote:

Yep pretty much, it also made changing everything easier. There were lots of 
instances where we were storing this in a variable named in the shorter style, 
so hopefully it's more consistent now.

https://github.com/llvm/llvm-project/pull/134142
___
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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/6] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [clang] release/20.x: [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863) (PR #134194)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/134194

Backport dcc2182bc

Requested by: @zyn0217

>From 235cb3d75d0fc80860c493520a584242c609393d Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 3 Apr 2025 11:15:42 +0800
Subject: [PATCH] [Clang] Fix a lambda pattern comparison mismatch after
 ecc7e6ce4 (#133863)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In ecc7e6ce4, we tried to inspect the `LambdaScopeInfo` on stack to
recover the instantiating lambda captures. However, there was a mismatch
in how we compared the pattern declarations of lambdas: the constraint
instantiation used a tailored `getPatternFunctionDecl()` which is
localized in SemaLambda that finds the very primal template declaration
of a lambda, while `FunctionDecl::getTemplateInstantiationPattern` finds
the latest template pattern of a lambda. This difference causes issues
when lambdas are nested, as we always want the primary template
declaration.

This corrects that by moving `Sema::addInstantiatedCapturesToScope` from
SemaConcept to SemaLambda, allowing it to use the localized version of
`getPatternFunctionDecl`.

It is also worth exploring to coalesce the implementation of
`getPatternFunctionDecl` with
`FunctionDecl::getTemplateInstantiationPattern`. But I’m leaving that
for the future, as I’d like to backport this fix (ecc7e6ce4 made the
issue more visible in clang 20, sorry!), and changing Sema’s ABI would
not be suitable in that regards. Hence, no release note.

Fixes https://github.com/llvm/llvm-project/issues/133719

(cherry picked from commit dcc2182bce3d2ef0e0a991664c51b4b3bfcf7197)
---
 clang/lib/Sema/SemaConcept.cpp  | 69 -
 clang/lib/Sema/SemaLambda.cpp   | 68 
 clang/test/SemaTemplate/concepts-lambda.cpp | 15 +
 3 files changed, 83 insertions(+), 69 deletions(-)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index a7b609f7f3ce4..8adebccde042c 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -702,75 +702,6 @@ bool Sema::CheckConstraintSatisfaction(const Expr 
*ConstraintExpr,
   .isInvalid();
 }
 
-bool Sema::addInstantiatedCapturesToScope(
-FunctionDecl *Function, const FunctionDecl *PatternDecl,
-LocalInstantiationScope &Scope,
-const MultiLevelTemplateArgumentList &TemplateArgs) {
-  const auto *LambdaClass = cast(Function)->getParent();
-  const auto *LambdaPattern = cast(PatternDecl)->getParent();
-
-  unsigned Instantiated = 0;
-
-  // FIXME: This is a workaround for not having deferred lambda body
-  // instantiation.
-  // When transforming a lambda's body, if we encounter another call to a
-  // nested lambda that contains a constraint expression, we add all of the
-  // outer lambda's instantiated captures to the current instantiation scope to
-  // facilitate constraint evaluation. However, these captures don't appear in
-  // the CXXRecordDecl until after the lambda expression is rebuilt, so we
-  // pull them out from the corresponding LSI.
-  LambdaScopeInfo *InstantiatingScope = nullptr;
-  if (LambdaPattern->capture_size() && !LambdaClass->capture_size()) {
-for (FunctionScopeInfo *Scope : llvm::reverse(FunctionScopes)) {
-  auto *LSI = dyn_cast(Scope);
-  if (!LSI ||
-  LSI->CallOperator->getTemplateInstantiationPattern() != PatternDecl)
-continue;
-  InstantiatingScope = LSI;
-  break;
-}
-assert(InstantiatingScope);
-  }
-
-  auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
-  unsigned Index) {
-ValueDecl *CapturedVar =
-InstantiatingScope ? InstantiatingScope->Captures[Index].getVariable()
-   : LambdaClass->getCapture(Index)->getCapturedVar();
-assert(CapturedVar->isInitCapture());
-Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
-  };
-
-  for (const LambdaCapture &CapturePattern : LambdaPattern->captures()) {
-if (!CapturePattern.capturesVariable()) {
-  Instantiated++;
-  continue;
-}
-ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
-
-if (!CapturedPattern->isInitCapture()) {
-  Instantiated++;
-  continue;
-}
-
-if (!CapturedPattern->isParameterPack()) {
-  AddSingleCapture(CapturedPattern, Instantiated++);
-} else {
-  Scope.MakeInstantiatedLocalArgPack(CapturedPattern);
-  SmallVector Unexpanded;
-  SemaRef.collectUnexpandedParameterPacks(
-  dyn_cast(CapturedPattern)->getInit(), Unexpanded);
-  auto NumArgumentsInExpansion =
-  getNumArgumentsInExpansionFromUnexpanded(Unexpanded, TemplateArgs);
-  if (!NumArgumentsInExpansion)
-continue;
-  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg)
-AddSingleCapture(CapturedPattern, Instantiated++);
-}
-  }
-  return false;
-}
-
 bool Sema::SetupConstraintScope

[llvm-branch-commits] [lldb] release/20.x: [lldb] Use correct path for lldb-server executable (#131519) (PR #134072)

2025-04-02 Thread Yuval Deutscher via llvm-branch-commits

yuvald-sweet-security wrote:

Thank you, I wanted this to be backported but wasn't sure how to do it :)

https://github.com/llvm/llvm-project/pull/134072
___
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] [lldb] release/20.x: [lldb] Respect LaunchInfo::SetExecutable in ProcessLauncherPosixFork (#133093) (PR #134079)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:

@JDevlieghere What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/134079
___
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] [lldb] release/20.x: [lldb] Respect LaunchInfo::SetExecutable in ProcessLauncherPosixFork (#133093) (PR #134079)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/134079

Backport 39e7efe1e4304544289d8d1b45f4d04d11b4a791

Requested by: @DavidSpickett

>From d32562d7837235d74350122575fc451a9573b4fa Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 27 Mar 2025 12:44:56 +0100
Subject: [PATCH] [lldb] Respect LaunchInfo::SetExecutable in
 ProcessLauncherPosixFork (#133093)

Using argv[0] for this was incorrect. I'm ignoring LaunchInfo::SetArg0,
as that's what darwin and windows launchers do (they use the first
element of the args vector instead).

I picked up the funny unit test re-exec method from the llvm unit tests.

(cherry picked from commit 39e7efe1e4304544289d8d1b45f4d04d11b4a791)
---
 .../Host/posix/ProcessLauncherPosixFork.cpp   |  8 +++-
 lldb/unittests/Host/HostTest.cpp  | 43 ++-
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp 
b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
index 7d856954684c4..903b18b10976c 100644
--- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -94,6 +94,7 @@ struct ForkLaunchInfo {
   bool debug;
   bool disable_aslr;
   std::string wd;
+  std::string executable;
   const char **argv;
   Environment::Envp envp;
   std::vector actions;
@@ -194,7 +195,8 @@ struct ForkLaunchInfo {
   }
 
   // Execute.  We should never return...
-  execve(info.argv[0], const_cast(info.argv), info.envp);
+  execve(info.executable.c_str(), const_cast(info.argv),
+ info.envp);
 
 #if defined(__linux__)
   if (errno == ETXTBSY) {
@@ -207,7 +209,8 @@ struct ForkLaunchInfo {
 // Since this state should clear up quickly, wait a while and then give it
 // one more go.
 usleep(5);
-execve(info.argv[0], const_cast(info.argv), info.envp);
+execve(info.executable.c_str(), const_cast(info.argv),
+   info.envp);
   }
 #endif
 
@@ -246,6 +249,7 @@ ForkLaunchInfo::ForkLaunchInfo(const ProcessLaunchInfo 
&info)
   debug(info.GetFlags().Test(eLaunchFlagDebug)),
   disable_aslr(info.GetFlags().Test(eLaunchFlagDisableASLR)),
   wd(info.GetWorkingDirectory().GetPath()),
+  executable(info.GetExecutableFile().GetPath()),
   argv(info.GetArguments().GetConstArgumentVector()),
   envp(FixupEnvironment(info.GetEnvironment())),
   actions(MakeForkActions(info)) {}
diff --git a/lldb/unittests/Host/HostTest.cpp b/lldb/unittests/Host/HostTest.cpp
index a1d8a3b7f485a..ed1df6de001ea 100644
--- a/lldb/unittests/Host/HostTest.cpp
+++ b/lldb/unittests/Host/HostTest.cpp
@@ -7,12 +7,24 @@
 
//===--===//
 
 #include "lldb/Host/Host.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
 #include "lldb/Utility/ProcessInfo.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace lldb_private;
 using namespace llvm;
 
+// From TestMain.cpp.
+extern const char *TestMainArgv0;
+
+static cl::opt test_arg("test-arg");
+
 TEST(Host, WaitStatusFormat) {
   EXPECT_EQ("W01", formatv("{0:g}", WaitStatus{WaitStatus::Exit, 1}).str());
   EXPECT_EQ("X02", formatv("{0:g}", WaitStatus{WaitStatus::Signal, 2}).str());
@@ -45,4 +57,33 @@ TEST(Host, ProcessInstanceInfoCumulativeSystemTimeIsValid) {
   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
   info.SetCumulativeSystemTime(ProcessInstanceInfo::timespec{1, 0});
   EXPECT_TRUE(info.CumulativeSystemTimeIsValid());
-}
\ No newline at end of file
+}
+
+TEST(Host, LaunchProcessSetsArgv0) {
+  SubsystemRAII subsystems;
+
+  static constexpr StringLiteral TestArgv0 = "HelloArgv0";
+  if (test_arg != 0) {
+// In subprocess
+if (TestMainArgv0 != TestArgv0) {
+  errs() << formatv("Got '{0}' for argv[0]\n", TestMainArgv0);
+  exit(1);
+}
+exit(0);
+  }
+
+  ProcessLaunchInfo info;
+  info.SetExecutableFile(
+  FileSpec(llvm::sys::fs::getMainExecutable(TestMainArgv0, &test_arg)),
+  /*add_exe_file_as_first_arg=*/false);
+  info.GetArguments().AppendArgument("HelloArgv0");
+  info.GetArguments().AppendArgument(
+  "--gtest_filter=Host.LaunchProcessSetsArgv0");
+  info.GetArguments().AppendArgument("--test-arg=47");
+  std::promise exit_status;
+  info.SetMonitorProcessCallback([&](lldb::pid_t pid, int signal, int status) {
+exit_status.set_value(status);
+  });
+  ASSERT_THAT_ERROR(Host::LaunchProcess(info).takeError(), Succeeded());
+  ASSERT_THAT(exit_status.get_future().get(), 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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/2] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)

redstar wrote:

For ED- and PR-type records, this field specifies the amount of space (in 
multiples of 16-byte quadwords) that the Binder will reserve at the origin of 
an element.
It's required, and the documentation needs an update.

https://github.com/llvm/llvm-project/pull/133799
___
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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/3] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/4] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

mtrofin wrote:

### Merge activity

* **Apr 2, 9:11 PM EDT**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/134011).


https://github.com/llvm/llvm-project/pull/134011
___
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] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)

2025-04-02 Thread Kazu Hirata via llvm-branch-commits

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

LGTM.

https://github.com/llvm/llvm-project/pull/134011
___
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] Bump version to 20.1.3 (PR #134187)

2025-04-02 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/134187

None

>From 664a6a71f316447595f5c69025b3484ec7fd77cc Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Wed, 2 Apr 2025 18:19:30 -0700
Subject: [PATCH] Bump version to 20.1.3

---
 cmake/Modules/LLVMVersion.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/Modules/LLVMVersion.cmake b/cmake/Modules/LLVMVersion.cmake
index 49cdc04707eb7..980fbbbfb1f8f 100644
--- a/cmake/Modules/LLVMVersion.cmake
+++ b/cmake/Modules/LLVMVersion.cmake
@@ -7,7 +7,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
   set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
-  set(LLVM_VERSION_PATCH 2)
+  set(LLVM_VERSION_PATCH 3)
 endif()
 if(NOT DEFINED LLVM_VERSION_SUFFIX)
   set(LLVM_VERSION_SUFFIX)

___
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] [clang] resugar decltype of MemberExpr (PR #132448)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132448

>From 022799a62f0c3018168db688ee234c9bda208d12 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sun, 16 Mar 2025 13:44:04 -0300
Subject: [PATCH] [clang] resugar decltype of MemberExpr

This keeps around the resugared DeclType for MemberExpr,
which is otherwise partially lost as the expression type
removes top level references.

This helps 'decltype' resugaring work without any loss
of information.
---
 clang/include/clang/AST/Expr.h| 33 ---
 clang/include/clang/AST/Stmt.h|  4 ++
 clang/include/clang/Sema/Sema.h   |  6 ++-
 clang/lib/AST/ASTImporter.cpp |  3 +-
 clang/lib/AST/Expr.cpp| 50 ++-
 clang/lib/Analysis/BodyFarm.cpp   |  2 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/Sema/SemaExpr.cpp   | 19 +++--
 clang/lib/Sema/SemaExprMember.cpp | 25 +++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++--
 clang/lib/Sema/SemaTemplate.cpp   | 11 +
 clang/lib/Sema/SemaType.cpp   |  2 +-
 clang/lib/Serialization/ASTReaderStmt.cpp |  9 +++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  4 ++
 clang/test/Sema/Resugar/resugar-expr.cpp  |  3 +-
 15 files changed, 129 insertions(+), 53 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e92f6696027f9..53afd206073ab 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3263,7 +3263,7 @@ class MemberExpr final
 : public Expr,
   private llvm::TrailingObjects {
+TemplateArgumentLoc, QualType> {
   friend class ASTReader;
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
@@ -3304,13 +3304,23 @@ class MemberExpr final
 return MemberExprBits.HasTemplateKWAndArgsInfo;
   }
 
+  size_t numTrailingObjects(OverloadToken) const {
+return getNumTemplateArgs();
+  }
+
+  size_t numTrailingObjects(OverloadToken) const {
+return HasResugaredDeclType();
+  }
+
+  static bool needsDeclTypeStorage(ValueDecl *VD, QualType DeclType);
+
   MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
  const DeclarationNameInfo &NameInfo,
  const TemplateArgumentListInfo *TemplateArgs,
  const TemplateArgumentList *Deduced, QualType T, ExprValueKind VK,
- ExprObjectKind OK, NonOdrUseReason NOUR);
+ QualType DeclType, ExprObjectKind OK, NonOdrUseReason NOUR);
   MemberExpr(EmptyShell Empty)
   : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
 
@@ -3322,7 +3332,7 @@ class MemberExpr final
  DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo,
  const TemplateArgumentListInfo *TemplateArgs,
  const TemplateArgumentList *Deduced, QualType T, ExprValueKind VK,
- ExprObjectKind OK, NonOdrUseReason NOUR);
+ QualType DeclType, ExprObjectKind OK, NonOdrUseReason NOUR);
 
   /// Create an implicit MemberExpr, with no location, qualifier, template
   /// arguments, and so on. Suitable only for non-static member access.
@@ -,14 +3343,15 @@ class MemberExpr final
 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
   SourceLocation(), MemberDecl,
   DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
-  DeclarationNameInfo(), nullptr, /*Deduced=*/{}, T, VK, OK,
-  NOUR_None);
+  DeclarationNameInfo(), nullptr, /*Deduced=*/{}, T, VK,
+  QualType(), OK, NOUR_None);
   }
 
   static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
  bool HasFoundDecl,
  bool HasTemplateKWAndArgsInfo,
- unsigned NumTemplateArgs);
+ unsigned NumTemplateArgs,
+ bool HasResugaredDeclType);
 
   void setBase(Expr *E) { Base = E; }
   Expr *getBase() const { return cast(Base); }
@@ -3351,6 +3362,16 @@ class MemberExpr final
   /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D);
+  void recomputeDependency();
+
+  bool HasResugaredDeclType() const {
+return MemberExprBits.HasResugaredDeclType;
+  }
+  QualType getDeclType() const {
+return HasResugaredDeclType() ? *getTrailingObjects()
+  : MemberDecl->getType();
+  }
+  void setDeclType(QualType T);
 
   /// Retrieves the declaration found by lookup.
   DeclAccessPair getFoundDecl() const {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/includ

[llvm-branch-commits] [clang] WIP: [clang] Template Specialization Resugaring - Expressions (PR #132446)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132446

>From d226c8d46bda83e50de2b6fc1e9887251728b7b4 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 30 May 2022 01:46:31 +0200
Subject: [PATCH] WIP: [clang] Template Specialization Resugaring - Expressions

This adds some additional users of the resugaring transform,
around expressions. This makes function calls work for example.

While probably not the largest patch in the series,
this could use some further splitting up.

Differential Revision: https://reviews.llvm.org/D137200
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/SemaChecking.cpp   |  15 +-
 clang/lib/Sema/SemaCoroutine.cpp  |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   |   1 +
 clang/lib/Sema/SemaDeclCXX.cpp|  14 +-
 clang/lib/Sema/SemaExpr.cpp   |  30 ++-
 clang/lib/Sema/SemaExprMember.cpp | 130 +-
 clang/lib/Sema/SemaHLSL.cpp   |   3 +-
 clang/lib/Sema/SemaInit.cpp   |   5 +-
 clang/lib/Sema/SemaOverload.cpp   |  87 +--
 clang/lib/Sema/SemaTemplate.cpp   | 110 +
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  15 +-
 clang/lib/Sema/TreeTransform.h|   4 +-
 .../test/AST/ast-dump-for-range-lifetime.cpp  |  66 ++---
 clang/test/Analysis/cast-value-notes.cpp  |  38 +--
 clang/test/Analysis/cast-value-state-dump.cpp |   6 +-
 .../Analysis/lifetime-extended-regions.cpp|   8 +-
 .../CXX/class.derived/class.abstract/p3.cpp   |   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|   4 +-
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg4xx.cpp |   8 +-
 clang/test/CXX/drs/cwg6xx.cpp |   2 +-
 .../test/Misc/diag-template-diffing-cxx11.cpp |   6 +-
 clang/test/Sema/Resugar/resugar-expr.cpp  | 227 ++
 clang/test/SemaTemplate/attributes.cpp|   3 +-
 clang/unittests/Tooling/StencilTest.cpp   |   3 +-
 27 files changed, 635 insertions(+), 173 deletions(-)
 create mode 100644 clang/test/Sema/Resugar/resugar-expr.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c68f31ccab528..5ac183deec4d0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8756,7 +8756,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow,
  SourceLocation OpLoc,
- const CXXScopeSpec &SS, FieldDecl *Field,
+ const NestedNameSpecifierLoc &NNS,
+ FieldDecl *Field, QualType FieldType,
  DeclAccessPair FoundDecl,
  const DeclarationNameInfo 
&MemberNameInfo);
 
@@ -8767,7 +8768,8 @@ class Sema final : public SemaBase {
   const CXXScopeSpec &SS, SourceLocation nameLoc,
   IndirectFieldDecl *indirectField,
   DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none),
-  Expr *baseObjectExpr = nullptr, SourceLocation opLoc = SourceLocation());
+  Expr *baseObjectExpr = nullptr, const Type *BaseType = nullptr,
+  SourceLocation opLoc = SourceLocation());
 
 private:
   void CheckMemberAccessOfNoDeref(const MemberExpr *E);
@@ -13999,6 +14001,16 @@ class Sema final : public SemaBase {
FunctionDecl *Spaceship);
 
   QualType resugar(const NestedNameSpecifier *NNS, QualType T);
+  QualType resugar(const NestedNameSpecifier *NNS, NamedDecl *ND,
+   ArrayRef Args, QualType T);
+  QualType resugar(NamedDecl *ND, ArrayRef Args, QualType T);
+  QualType resugar(const Type *Base, const NestedNameSpecifier *FieldNNS,
+   QualType T);
+  QualType resugar(const Type *Base, const NestedNameSpecifier *FieldNNS,
+   NamedDecl *ND, ArrayRef Args, QualType T);
+  QualType resugar(const Type *Base, QualType T);
+  QualType resugar(const Type *Base, NamedDecl *ND,
+   ArrayRef Args, QualType T);
 
   /// Performs template instantiation for all implicit template
   /// instantiations we have seen until this point.
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index db61af1495793..974bf3b018c09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -649,9 +649,11 @@ struct BuiltinDumpStructGenerator {
   if (!FD || FD->isUnnamedBitField() || FD->isAnonymousStructOrUnion())
 continue;
 
+  QualType FieldType = FD->getType();
+
   llvm::SmallString<20> Format = llvm::StringRef("%s%s %s ");
   llvm::SmallVector Args = {FieldIndentArg,
-   getTypeString(FD->getType()),
+   

[llvm-branch-commits] [clang] [clang-tools-extra] [lldb] [clang] Template Specialization Resugaring - TypeDecl (PR #132441)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132441

>From 0793555771f9855a12c267eb4f2de1341a8556d1 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 30 May 2022 01:46:31 +0200
Subject: [PATCH] [clang] Template Specialization Resugaring - TypeDecl

This is the introductory patch for a larger work which
intends to solve the long standing C++ issue with losing
type sugar when acessing template specializations.

The well known example here is specializing a template
with `std::string`, but getting diagnostics related to
`std::basic_string` instead.

This implements a transform which, upon member access,
propagates type sugar from the naming context into the
accessed entity.

It also implements a single use of this transform,
resugaring access to TypeDecls.

For more details and discussion see:
https://discourse.llvm.org/t/rfc-improving-diagnostics-with-template-specialization-resugaring/64294

This is ready for review, although maybe not finished and
there is some more stuff that could be done either here
or in follow ups.

* Its worth exploring if a global resugaring cache is
  worthwhile, besides the current operational cache.
  A global cache would be more expensive to index, so there
  is a tradeoff, and maybe should be used of the whole
  result of the operation, while keeping the existing
  cache for sub-results.
* It would be ideal if the transform could live in ASTContext
  instead of Sema. There are a few dependencies that would
  have to be tackled.
  * Template arguments deduced for partial specializations.
  * Some kinds of type adjustments currently require Sema.

Differential Revision: https://reviews.llvm.org/D127695
---
 .../readability/QualifiedAutoCheck.cpp|   2 +-
 clang/include/clang/AST/ASTContext.h  |  13 +-
 clang/include/clang/AST/Type.h|  11 +-
 clang/include/clang/Sema/Sema.h   |   8 +-
 clang/lib/AST/ASTContext.cpp  |  17 +-
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |   5 +-
 clang/lib/Sema/SemaCoroutine.cpp  |   1 +
 clang/lib/Sema/SemaDecl.cpp   |   9 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   2 +-
 clang/lib/Sema/SemaTemplate.cpp   | 735 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   6 +-
 clang/lib/Sema/SemaType.cpp   |  10 +-
 ...openmp-begin-declare-variant_reference.cpp |   4 +-
 clang/test/AST/ast-dump-template-name.cpp |   8 +-
 clang/test/CXX/temp/temp.param/p15-cxx0x.cpp  |   4 +-
 clang/test/Sema/Resugar/resugar-types.cpp | 209 +
 .../iterator/TestIteratorFromStdModule.py |   6 +-
 17 files changed, 1004 insertions(+), 46 deletions(-)
 create mode 100644 clang/test/Sema/Resugar/resugar-types.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
index e843c593a92cc..679fbd75d2479 100644
--- a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
@@ -126,7 +126,7 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder 
*Finder) {
   auto UnlessFunctionType = 
unless(hasUnqualifiedDesugaredType(functionType()));
   auto IsAutoDeducedToPointer = [](const auto &...InnerMatchers) {
 return autoType(hasDeducedType(
-hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...);
+hasCanonicalType(pointerType(pointee(InnerMatchers...);
   };
 
   Finder->addMatcher(
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index d2529fbba68e0..a7d318d894811 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1319,8 +1319,6 @@ class ASTContext : public RefCountedBase {
 
   QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
 
-  QualType getPipeType(QualType T, bool ReadOnly) const;
-
 public:
   /// Return the uniqued reference to the type for an address space
   /// qualified type with the specified type and address space.
@@ -1500,6 +1498,9 @@ class ASTContext : public RefCountedBase {
   /// blocks.
   QualType getBlockDescriptorType() const;
 
+  // Return a pipe type for the specified type.
+  QualType getPipeType(QualType T, bool ReadOnly) const;
+
   /// Return a read_only pipe type for the specified type.
   QualType getReadPipeType(QualType T) const;
 
@@ -1897,10 +1898,10 @@ class ASTContext : public RefCountedBase {
   /// C++11 decltype.
   QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
 
-  QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr,
-   bool FullySubstituted = false,
-   ArrayRef Expansions = {},
-   int Index = -1) const;
+  QualType getPackIndexingType(
+  QualType Pattern, Expr *IndexExpr, bool FullySubstituted = false,
+  ArrayRef Expan

[llvm-branch-commits] [clang] [clang] resugar decltype of DeclRefExpr (PR #132447)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132447

>From 6b9e8d13fa1bd6a6583eab3eef74833b023f1d06 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 14 Mar 2025 19:41:38 -0300
Subject: [PATCH] [clang] resugar decltype of DeclRefExpr

This keeps around the resugared DeclType for DeclRefExpr,
which is otherwise partially lost as the expression type
removes top level references.

This helps 'decltype' resugaring work without any loss
of information.
---
 clang/include/clang/AST/Expr.h| 32 +++--
 clang/include/clang/AST/Stmt.h|  2 +
 clang/include/clang/Sema/Sema.h   | 20 +++---
 clang/lib/AST/ASTImporter.cpp |  3 +-
 clang/lib/AST/Expr.cpp| 82 +++
 clang/lib/CodeGen/CGExpr.cpp  |  4 +-
 clang/lib/Sema/SemaChecking.cpp   |  3 +-
 clang/lib/Sema/SemaDeclCXX.cpp| 19 +++---
 clang/lib/Sema/SemaExpr.cpp   | 81 +++---
 clang/lib/Sema/SemaOpenMP.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   | 25 ---
 clang/lib/Sema/SemaSYCL.cpp   |  2 +-
 clang/lib/Sema/SemaTemplate.cpp   | 13 
 clang/lib/Sema/SemaType.cpp   |  9 ++-
 clang/lib/Sema/TreeTransform.h|  5 +-
 clang/lib/Serialization/ASTReaderStmt.cpp |  8 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  6 +-
 clang/test/Sema/Resugar/resugar-expr.cpp  |  6 +-
 18 files changed, 201 insertions(+), 130 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 2ba787ac6df55..e92f6696027f9 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1266,7 +1266,7 @@ class DeclRefExpr final
 : public Expr,
   private llvm::TrailingObjects {
+TemplateArgumentLoc, QualType> {
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
   friend TrailingObjects;
@@ -1292,17 +1292,27 @@ class DeclRefExpr final
 return hasTemplateKWAndArgsInfo();
   }
 
+  size_t numTrailingObjects(OverloadToken) const {
+return getNumTemplateArgs();
+  }
+
+  size_t numTrailingObjects(OverloadToken) const {
+return HasResugaredDeclType();
+  }
+
   /// Test whether there is a distinct FoundDecl attached to the end of
   /// this DRE.
   bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
 
+  static bool needsDeclTypeStorage(ValueDecl *VD, QualType DeclType);
+
   DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
   SourceLocation TemplateKWLoc, ValueDecl *D,
   bool RefersToEnclosingVariableOrCapture,
   const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
   const TemplateArgumentListInfo *TemplateArgs,
   const TemplateArgumentList *ConvertedArgs, QualType T,
-  ExprValueKind VK, NonOdrUseReason NOUR);
+  ExprValueKind VK, QualType DeclType, NonOdrUseReason NOUR);
 
   /// Construct an empty declaration reference expression.
   explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
@@ -1318,7 +1328,8 @@ class DeclRefExpr final
   Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
  SourceLocation TemplateKWLoc, ValueDecl *D,
  bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
- QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
+ QualType T, ExprValueKind VK, QualType DeclType = QualType(),
+ NamedDecl *FoundD = nullptr,
  const TemplateArgumentListInfo *TemplateArgs = nullptr,
  const TemplateArgumentList *ConvertedArgs = nullptr,
  NonOdrUseReason NOUR = NOUR_None);
@@ -1328,7 +1339,7 @@ class DeclRefExpr final
  SourceLocation TemplateKWLoc, ValueDecl *D,
  bool RefersToEnclosingVariableOrCapture,
  const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
- NamedDecl *FoundD = nullptr,
+ QualType DeclType = QualType(), NamedDecl *FoundD = nullptr,
  const TemplateArgumentListInfo *TemplateArgs = nullptr,
  const TemplateArgumentList *ConvertedArgs = nullptr,
  NonOdrUseReason NOUR = NOUR_None);
@@ -1337,11 +1348,22 @@ class DeclRefExpr final
   static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
   bool HasFoundDecl,
   bool HasTemplateKWAndArgsInfo,
-  unsigned NumTemplateArgs);
+  unsigned NumTemplateArgs,
+  bool HasResugaredDeclType);
 
   ValueDecl *getDecl() { return D; }
   const ValueDecl *getDecl() const { return D; }
   void setDecl(ValueDecl *NewD);
+  void recomputeDependency();
+
+  bool HasResugaredDeclType() const {
+return DeclRefExprBits.HasResugaredDeclType;
+  }
+  QualType getDeclTyp

[llvm-branch-commits] [clang] release/20.x: [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863) (PR #134194)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport dcc2182bc

Requested by: @zyn0217

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (-69) 
- (modified) clang/lib/Sema/SemaLambda.cpp (+68) 
- (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+15) 


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index a7b609f7f3ce4..8adebccde042c 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -702,75 +702,6 @@ bool Sema::CheckConstraintSatisfaction(const Expr 
*ConstraintExpr,
   .isInvalid();
 }
 
-bool Sema::addInstantiatedCapturesToScope(
-FunctionDecl *Function, const FunctionDecl *PatternDecl,
-LocalInstantiationScope &Scope,
-const MultiLevelTemplateArgumentList &TemplateArgs) {
-  const auto *LambdaClass = cast(Function)->getParent();
-  const auto *LambdaPattern = cast(PatternDecl)->getParent();
-
-  unsigned Instantiated = 0;
-
-  // FIXME: This is a workaround for not having deferred lambda body
-  // instantiation.
-  // When transforming a lambda's body, if we encounter another call to a
-  // nested lambda that contains a constraint expression, we add all of the
-  // outer lambda's instantiated captures to the current instantiation scope to
-  // facilitate constraint evaluation. However, these captures don't appear in
-  // the CXXRecordDecl until after the lambda expression is rebuilt, so we
-  // pull them out from the corresponding LSI.
-  LambdaScopeInfo *InstantiatingScope = nullptr;
-  if (LambdaPattern->capture_size() && !LambdaClass->capture_size()) {
-for (FunctionScopeInfo *Scope : llvm::reverse(FunctionScopes)) {
-  auto *LSI = dyn_cast(Scope);
-  if (!LSI ||
-  LSI->CallOperator->getTemplateInstantiationPattern() != PatternDecl)
-continue;
-  InstantiatingScope = LSI;
-  break;
-}
-assert(InstantiatingScope);
-  }
-
-  auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
-  unsigned Index) {
-ValueDecl *CapturedVar =
-InstantiatingScope ? InstantiatingScope->Captures[Index].getVariable()
-   : LambdaClass->getCapture(Index)->getCapturedVar();
-assert(CapturedVar->isInitCapture());
-Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
-  };
-
-  for (const LambdaCapture &CapturePattern : LambdaPattern->captures()) {
-if (!CapturePattern.capturesVariable()) {
-  Instantiated++;
-  continue;
-}
-ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
-
-if (!CapturedPattern->isInitCapture()) {
-  Instantiated++;
-  continue;
-}
-
-if (!CapturedPattern->isParameterPack()) {
-  AddSingleCapture(CapturedPattern, Instantiated++);
-} else {
-  Scope.MakeInstantiatedLocalArgPack(CapturedPattern);
-  SmallVector Unexpanded;
-  SemaRef.collectUnexpandedParameterPacks(
-  dyn_cast(CapturedPattern)->getInit(), Unexpanded);
-  auto NumArgumentsInExpansion =
-  getNumArgumentsInExpansionFromUnexpanded(Unexpanded, TemplateArgs);
-  if (!NumArgumentsInExpansion)
-continue;
-  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg)
-AddSingleCapture(CapturedPattern, Instantiated++);
-}
-  }
-  return false;
-}
-
 bool Sema::SetupConstraintScope(
 FunctionDecl *FD, std::optional> TemplateArgs,
 const MultiLevelTemplateArgumentList &MLTAL,
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ceb32ee15dfa3..981856fbf25a7 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2389,6 +2389,74 @@ static FunctionDecl *getPatternFunctionDecl(FunctionDecl 
*FD) {
   return FTD->getTemplatedDecl();
 }
 
+bool Sema::addInstantiatedCapturesToScope(
+FunctionDecl *Function, const FunctionDecl *PatternDecl,
+LocalInstantiationScope &Scope,
+const MultiLevelTemplateArgumentList &TemplateArgs) {
+  const auto *LambdaClass = cast(Function)->getParent();
+  const auto *LambdaPattern = cast(PatternDecl)->getParent();
+
+  unsigned Instantiated = 0;
+
+  // FIXME: This is a workaround for not having deferred lambda body
+  // instantiation.
+  // When transforming a lambda's body, if we encounter another call to a
+  // nested lambda that contains a constraint expression, we add all of the
+  // outer lambda's instantiated captures to the current instantiation scope to
+  // facilitate constraint evaluation. However, these captures don't appear in
+  // the CXXRecordDecl until after the lambda expression is rebuilt, so we
+  // pull them out from the corresponding LSI.
+  LambdaScopeInfo *InstantiatingScope = nullptr;
+  if (LambdaPattern->capture_size() && !LambdaClass->capture_size()) {
+for (FunctionScopeInfo *Scope : llvm::reverse(FunctionScopes)) {
+  auto *LSI = dyn_cast(Scope

[llvm-branch-commits] Extract SipHash implementation into a header. (PR #134197)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc created https://github.com/llvm/llvm-project/pull/134197

This is so that we'll be able to use it in compiler-rt as well.
Dependencies on LLVM Support were removed from the header by restoring
code from the original SipHash implementation.



___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530


___
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] Extract SipHash implementation into a header. (PR #134197)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Peter Collingbourne (pcc)


Changes

This is so that we'll be able to use it in compiler-rt as well.
Dependencies on LLVM Support were removed from the header by restoring
code from the original SipHash implementation.


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


4 Files Affected:

- (modified) llvm/lib/Support/CMakeLists.txt (+5) 
- (modified) llvm/lib/Support/SipHash.cpp (+1-130) 
- (modified) llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn (+1) 
- (added) third-party/siphash/include/siphash/SipHash.h (+161) 


``diff
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 2754c97fce6c1..1b18eb7c6346b 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -368,3 +368,8 @@ if(LLVM_WITH_Z3)
 ${Z3_INCLUDE_DIR}
 )
 endif()
+
+target_include_directories(LLVMSupport SYSTEM
+  PRIVATE
+  ${LLVM_THIRD_PARTY_DIR}/siphash/include
+  )
diff --git a/llvm/lib/Support/SipHash.cpp b/llvm/lib/Support/SipHash.cpp
index 68545913a4f59..682e9231c776f 100644
--- a/llvm/lib/Support/SipHash.cpp
+++ b/llvm/lib/Support/SipHash.cpp
@@ -15,9 +15,9 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"
+#include "siphash/SipHash.h"
 #include 
 
 using namespace llvm;
@@ -25,135 +25,6 @@ using namespace support;
 
 #define DEBUG_TYPE "llvm-siphash"
 
-// Lightly adapted from the SipHash reference C implementation:
-//   https://github.com/veorq/SipHash
-// by Jean-Philippe Aumasson and Daniel J. Bernstein
-
-#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b
-
-#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)
-
-namespace {
-
-/// Computes a SipHash value
-///
-/// \param in: pointer to input data (read-only)
-/// \param inlen: input data length in bytes (any size_t value)
-/// \param k: reference to the key data 16-byte array (read-only)
-/// \returns output data, must be 8 or 16 bytes
-///
-template 
-void siphash(const unsigned char *in, uint64_t inlen,
- const unsigned char (&k)[16], unsigned char (&out)[outlen]) {
-
-  const unsigned char *ni = (const unsigned char *)in;
-  const unsigned char *kk = (const unsigned char *)k;
-
-  static_assert(outlen == 8 || outlen == 16, "result should be 8 or 16 bytes");
-
-  uint64_t v0 = UINT64_C(0x736f6d6570736575);
-  uint64_t v1 = UINT64_C(0x646f72616e646f6d);
-  uint64_t v2 = UINT64_C(0x6c7967656e657261);
-  uint64_t v3 = UINT64_C(0x7465646279746573);
-  uint64_t k0 = endian::read64le(kk);
-  uint64_t k1 = endian::read64le(kk + 8);
-  uint64_t m;
-  int i;
-  const unsigned char *end = ni + inlen - (inlen % sizeof(uint64_t));
-  const int left = inlen & 7;
-  uint64_t b = ((uint64_t)inlen) << 56;
-  v3 ^= k1;
-  v2 ^= k0;
-  v1 ^= k1;
-  v0 ^= k0;
-
-  if (outlen == 16)
-v1 ^= 0xee;
-
-  for (; ni != end; ni += 8) {
-m = endian::read64le(ni);
-v3 ^= m;
-
-for (i = 0; i < cROUNDS; ++i)
-  SIPROUND;
-
-v0 ^= m;
-  }
-
-  switch (left) {
-  case 7:
-b |= ((uint64_t)ni[6]) << 48;
-LLVM_FALLTHROUGH;
-  case 6:
-b |= ((uint64_t)ni[5]) << 40;
-LLVM_FALLTHROUGH;
-  case 5:
-b |= ((uint64_t)ni[4]) << 32;
-LLVM_FALLTHROUGH;
-  case 4:
-b |= ((uint64_t)ni[3]) << 24;
-LLVM_FALLTHROUGH;
-  case 3:
-b |= ((uint64_t)ni[2]) << 16;
-LLVM_FALLTHROUGH;
-  case 2:
-b |= ((uint64_t)ni[1]) << 8;
-LLVM_FALLTHROUGH;
-  case 1:
-b |= ((uint64_t)ni[0]);
-break;
-  case 0:
-break;
-  }
-
-  v3 ^= b;
-
-  for (i = 0; i < c

[llvm-branch-commits] [llvm] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)

2025-04-02 Thread Kazu Hirata via llvm-branch-commits

https://github.com/kazutakahirata edited 
https://github.com/llvm/llvm-project/pull/134011
___
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] [clang] Template Specialization Resugaring - Template Type Alias (PR #132442)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132442

>From 9d5d42820a4998e0e3eb74f7301aa34dca55b890 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 30 May 2022 01:46:31 +0200
Subject: [PATCH] [clang] Template Specialization Resugaring - Template Type
 Alias

This implements an additional user of the resugaring transform:
the pattern of template type aliases.

For more details and discussion see:
https://discourse.llvm.org/t/rfc-improving-diagnostics-with-template-specialization-resugaring/64294

Differential Revision: https://reviews.llvm.org/D137199
---
 clang/include/clang/Sema/Sema.h   |  3 +-
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  3 +-
 clang/lib/Sema/SemaCoroutine.cpp  |  4 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  6 ++-
 clang/lib/Sema/SemaTemplate.cpp   | 43 +++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 +-
 clang/lib/Sema/TreeTransform.h|  3 +-
 clang/test/AST/ast-dump-template-decls.cpp|  4 +-
 clang/test/Sema/Resugar/resugar-types.cpp |  6 +--
 9 files changed, 44 insertions(+), 31 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 945ff5e2c2ca6..42a7bf75c3bfc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11509,7 +11509,8 @@ class Sema final : public SemaBase {
 
   void NoteAllFoundTemplates(TemplateName Name);
 
-  QualType CheckTemplateIdType(TemplateName Template,
+  QualType CheckTemplateIdType(const NestedNameSpecifier *NNS,
+   TemplateName Template,
SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs);
 
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp 
b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 1085639dcb355..1c7dff35bb8af 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -907,7 +907,8 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
 
   // We were able to resolve the template name to an actual template.
   // Build an appropriate nested-name-specifier.
-  QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
+  QualType T = CheckTemplateIdType(SS.getScopeRep(), Template, TemplateNameLoc,
+   TemplateArgs);
   if (T.isNull())
 return true;
 
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 75364a3b2c8b5..8dffbca7463dd 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -90,7 +90,7 @@ static QualType lookupPromiseType(Sema &S, const FunctionDecl 
*FD,
 
   // Build the template-id.
   QualType CoroTrait =
-  S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args);
+  S.CheckTemplateIdType(nullptr, TemplateName(CoroTraits), KwLoc, Args);
   if (CoroTrait.isNull())
 return QualType();
   if (S.RequireCompleteType(KwLoc, CoroTrait,
@@ -169,7 +169,7 @@ static QualType lookupCoroutineHandleType(Sema &S, QualType 
PromiseType,
 
   // Build the template-id.
   QualType CoroHandleType =
-  S.CheckTemplateIdType(TemplateName(CoroHandle), Loc, Args);
+  S.CheckTemplateIdType(nullptr, TemplateName(CoroHandle), Loc, Args);
   if (CoroHandleType.isNull())
 return QualType();
   if (S.RequireCompleteType(Loc, CoroHandleType,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 928bf47285490..8a9ad3271ec26 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1140,7 +1140,8 @@ static bool lookupStdTypeTraitMember(Sema &S, 
LookupResult &TraitMemberLookup,
   }
 
   // Build the template-id.
-  QualType TraitTy = S.CheckTemplateIdType(TemplateName(TraitTD), Loc, Args);
+  QualType TraitTy =
+  S.CheckTemplateIdType(nullptr, TemplateName(TraitTD), Loc, Args);
   if (TraitTy.isNull())
 return true;
   if (!S.isCompleteType(Loc, TraitTy)) {
@@ -12163,7 +12164,8 @@ QualType Sema::BuildStdInitializerList(QualType 
Element, SourceLocation Loc) {

Context.getTrivialTypeSourceInfo(Element,
 Loc)));
 
-  QualType T = CheckTemplateIdType(TemplateName(StdInitializerList), Loc, 
Args);
+  QualType T =
+  CheckTemplateIdType(nullptr, TemplateName(StdInitializerList), Loc, 
Args);
   if (T.isNull())
 return QualType();
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5652b4548895a..673551bd97f3e 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3827,7 +3827,8 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
-static QualType builtinCommonTypeImpl(Sema &S, TemplateName BaseTemplate,
+static QualType builtinCommonTypeImpl(Sema &S, const NestedNameSpecifier *NNS,
+ 

[llvm-branch-commits] [clang] [clang] resugar decltype of MemberExpr (PR #132448)

2025-04-02 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/132448

>From 022799a62f0c3018168db688ee234c9bda208d12 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sun, 16 Mar 2025 13:44:04 -0300
Subject: [PATCH] [clang] resugar decltype of MemberExpr

This keeps around the resugared DeclType for MemberExpr,
which is otherwise partially lost as the expression type
removes top level references.

This helps 'decltype' resugaring work without any loss
of information.
---
 clang/include/clang/AST/Expr.h| 33 ---
 clang/include/clang/AST/Stmt.h|  4 ++
 clang/include/clang/Sema/Sema.h   |  6 ++-
 clang/lib/AST/ASTImporter.cpp |  3 +-
 clang/lib/AST/Expr.cpp| 50 ++-
 clang/lib/Analysis/BodyFarm.cpp   |  2 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/Sema/SemaExpr.cpp   | 19 +++--
 clang/lib/Sema/SemaExprMember.cpp | 25 +++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++--
 clang/lib/Sema/SemaTemplate.cpp   | 11 +
 clang/lib/Sema/SemaType.cpp   |  2 +-
 clang/lib/Serialization/ASTReaderStmt.cpp |  9 +++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  4 ++
 clang/test/Sema/Resugar/resugar-expr.cpp  |  3 +-
 15 files changed, 129 insertions(+), 53 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e92f6696027f9..53afd206073ab 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3263,7 +3263,7 @@ class MemberExpr final
 : public Expr,
   private llvm::TrailingObjects {
+TemplateArgumentLoc, QualType> {
   friend class ASTReader;
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
@@ -3304,13 +3304,23 @@ class MemberExpr final
 return MemberExprBits.HasTemplateKWAndArgsInfo;
   }
 
+  size_t numTrailingObjects(OverloadToken) const {
+return getNumTemplateArgs();
+  }
+
+  size_t numTrailingObjects(OverloadToken) const {
+return HasResugaredDeclType();
+  }
+
+  static bool needsDeclTypeStorage(ValueDecl *VD, QualType DeclType);
+
   MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
  const DeclarationNameInfo &NameInfo,
  const TemplateArgumentListInfo *TemplateArgs,
  const TemplateArgumentList *Deduced, QualType T, ExprValueKind VK,
- ExprObjectKind OK, NonOdrUseReason NOUR);
+ QualType DeclType, ExprObjectKind OK, NonOdrUseReason NOUR);
   MemberExpr(EmptyShell Empty)
   : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
 
@@ -3322,7 +3332,7 @@ class MemberExpr final
  DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo,
  const TemplateArgumentListInfo *TemplateArgs,
  const TemplateArgumentList *Deduced, QualType T, ExprValueKind VK,
- ExprObjectKind OK, NonOdrUseReason NOUR);
+ QualType DeclType, ExprObjectKind OK, NonOdrUseReason NOUR);
 
   /// Create an implicit MemberExpr, with no location, qualifier, template
   /// arguments, and so on. Suitable only for non-static member access.
@@ -,14 +3343,15 @@ class MemberExpr final
 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
   SourceLocation(), MemberDecl,
   DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
-  DeclarationNameInfo(), nullptr, /*Deduced=*/{}, T, VK, OK,
-  NOUR_None);
+  DeclarationNameInfo(), nullptr, /*Deduced=*/{}, T, VK,
+  QualType(), OK, NOUR_None);
   }
 
   static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
  bool HasFoundDecl,
  bool HasTemplateKWAndArgsInfo,
- unsigned NumTemplateArgs);
+ unsigned NumTemplateArgs,
+ bool HasResugaredDeclType);
 
   void setBase(Expr *E) { Base = E; }
   Expr *getBase() const { return cast(Base); }
@@ -3351,6 +3362,16 @@ class MemberExpr final
   /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
   ValueDecl *getMemberDecl() const { return MemberDecl; }
   void setMemberDecl(ValueDecl *D);
+  void recomputeDependency();
+
+  bool HasResugaredDeclType() const {
+return MemberExprBits.HasResugaredDeclType;
+  }
+  QualType getDeclType() const {
+return HasResugaredDeclType() ? *getTrailingObjects()
+  : MemberDecl->getType();
+  }
+  void setDeclType(QualType T);
 
   /// Retrieves the declaration found by lookup.
   DeclAccessPair getFoundDecl() const {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/includ

[llvm-branch-commits] [llvm] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

mtrofin wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134192?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134192** https://app.graphite.dev/github/pr/llvm/llvm-project/134192?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134192?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134012** https://app.graphite.dev/github/pr/llvm/llvm-project/134012?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134011** https://app.graphite.dev/github/pr/llvm/llvm-project/134011?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133992** https://app.graphite.dev/github/pr/llvm/llvm-project/133992?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/134192
___
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] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin created 
https://github.com/llvm/llvm-project/pull/134192

None

>From aab3649d9d72c9f708603b3849055e1aba8f375d Mon Sep 17 00:00:00 2001
From: Mircea Trofin 
Date: Wed, 2 Apr 2025 18:39:14 -0700
Subject: [PATCH] [ctxprof] Support for "move" semantics for the contextual
 root

---
 .../Transforms/Utils/FunctionImportUtils.h| 25 
 llvm/lib/Transforms/IPO/FunctionImport.cpp| 17 +++
 .../Transforms/Utils/FunctionImportUtils.cpp  | 29 ++-
 .../ThinLTO/X86/ctxprof-separate-module.ll| 22 --
 4 files changed, 69 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h 
b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
index 6d83b615d5f13..98e2fd37a0f25 100644
--- a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
@@ -97,29 +97,14 @@ class FunctionImportGlobalProcessing {
   /// linkage for a required promotion of a local to global scope.
   GlobalValue::LinkageTypes getLinkage(const GlobalValue *SGV, bool DoPromote);
 
+  /// The symbols with these names are moved to a different module and should 
be
+  /// promoted to external linkage where they are defined.
+  DenseSet SymbolsToMove;
+
 public:
   FunctionImportGlobalProcessing(Module &M, const ModuleSummaryIndex &Index,
  SetVector *GlobalsToImport,
- bool ClearDSOLocalOnDeclarations)
-  : M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
-ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
-// If we have a ModuleSummaryIndex but no function to import,
-// then this is the primary module being compiled in a ThinLTO
-// backend compilation, and we need to see if it has functions that
-// may be exported to another backend compilation.
-if (!GlobalsToImport)
-  HasExportedFunctions = ImportIndex.hasExportedFunctions(M);
-
-#ifndef NDEBUG
-SmallVector Vec;
-// First collect those in the llvm.used set.
-collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/false);
-// Next collect those in the llvm.compiler.used set.
-collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/true);
-Used = {llvm::from_range, Vec};
-#endif
-  }
-
+ bool ClearDSOLocalOnDeclarations);
   void run();
 };
 
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp 
b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 3d9fb7b12b5d5..a389021ce27cf 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -182,6 +182,15 @@ static cl::opt CtxprofMoveRootsToOwnModule(
  "their own module."),
 cl::Hidden, cl::init(false));
 
+cl::list MoveSymbolName(
+"thinlto-move-symbols",
+cl::desc(
+"Move the symbols with the given name. This will delete these symbols "
+"wherever they are originally defined, and make sure their "
+"linkage is External where they are imported. It is meant to be "
+"used with the name of contextual profiling roots."),
+cl::Hidden);
+
 namespace llvm {
 extern cl::opt EnableMemProfContextDisambiguation;
 }
@@ -1858,6 +1867,14 @@ Expected FunctionImporter::importFunctions(
   LLVM_DEBUG(dbgs() << "Starting import for Module "
 << DestModule.getModuleIdentifier() << "\n");
   unsigned ImportedCount = 0, ImportedGVCount = 0;
+  // Before carrying out any imports, see if this module defines functions in
+  // MoveSymbolName. If it does, delete them here (but leave the declaration).
+  // The function will be imported elsewhere, as extenal linkage, and the
+  // destination doesn't yet have its definition.
+  for (const auto &N : MoveSymbolName)
+if (auto *F = DestModule.getFunction(N))
+  if (!F->isDeclaration())
+F->deleteBody();
 
   IRMover Mover(DestModule);
 
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp 
b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index ae1af943bc11c..e59c8eb7244fa 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -24,6 +24,31 @@ static cl::opt UseSourceFilenameForPromotedLocals(
  "This requires that the source filename has a unique name / "
  "path to avoid name collisions."));
 
+extern cl::list MoveSymbolName;
+
+FunctionImportGlobalProcessing::FunctionImportGlobalProcessing(
+Module &M, const ModuleSummaryIndex &Index,
+SetVector *GlobalsToImport, bool 
ClearDSOLocalOnDeclarations)
+: M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
+  ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
+  // If we have a ModuleSummaryIndex but no function to import,
+  // then this is the primary module being compiled in a ThinLTO
+  // backend compilation, and we need to see if it has functions that

[llvm-branch-commits] [llvm] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin edited 
https://github.com/llvm/llvm-project/pull/134192
___
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] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin edited 
https://github.com/llvm/llvm-project/pull/134192
___
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] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lto

Author: Mircea Trofin (mtrofin)


Changes

This PR finishes what PR #133992 started.

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


4 Files Affected:

- (modified) llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h (+5-20) 
- (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+18) 
- (modified) llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (+28-1) 
- (modified) llvm/test/ThinLTO/X86/ctxprof-separate-module.ll (+19-3) 


``diff
diff --git a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h 
b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
index 6d83b615d5f13..28ba20bc18cf9 100644
--- a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
@@ -97,29 +97,14 @@ class FunctionImportGlobalProcessing {
   /// linkage for a required promotion of a local to global scope.
   GlobalValue::LinkageTypes getLinkage(const GlobalValue *SGV, bool DoPromote);
 
+  /// The symbols with these names are moved to a different module and should 
be
+  /// promoted to external linkage where they are defined.
+  DenseSet SymbolsToMove;
+
 public:
   FunctionImportGlobalProcessing(Module &M, const ModuleSummaryIndex &Index,
  SetVector *GlobalsToImport,
- bool ClearDSOLocalOnDeclarations)
-  : M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
-ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
-// If we have a ModuleSummaryIndex but no function to import,
-// then this is the primary module being compiled in a ThinLTO
-// backend compilation, and we need to see if it has functions that
-// may be exported to another backend compilation.
-if (!GlobalsToImport)
-  HasExportedFunctions = ImportIndex.hasExportedFunctions(M);
-
-#ifndef NDEBUG
-SmallVector Vec;
-// First collect those in the llvm.used set.
-collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/false);
-// Next collect those in the llvm.compiler.used set.
-collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/true);
-Used = {llvm::from_range, Vec};
-#endif
-  }
-
+ bool ClearDSOLocalOnDeclarations);
   void run();
 };
 
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp 
b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 3d9fb7b12b5d5..50100a63cf407 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -182,6 +182,15 @@ static cl::opt CtxprofMoveRootsToOwnModule(
  "their own module."),
 cl::Hidden, cl::init(false));
 
+cl::list MoveSymbolGUID(
+"thinlto-move-symbols",
+cl::desc(
+"Move the symbols with the given name. This will delete these symbols "
+"wherever they are originally defined, and make sure their "
+"linkage is External where they are imported. It is meant to be "
+"used with the name of contextual profiling roots."),
+cl::Hidden);
+
 namespace llvm {
 extern cl::opt EnableMemProfContextDisambiguation;
 }
@@ -1858,6 +1867,15 @@ Expected FunctionImporter::importFunctions(
   LLVM_DEBUG(dbgs() << "Starting import for Module "
 << DestModule.getModuleIdentifier() << "\n");
   unsigned ImportedCount = 0, ImportedGVCount = 0;
+  // Before carrying out any imports, see if this module defines functions in
+  // MoveSymbolGUID. If it does, delete them here (but leave the declaration).
+  // The function will be imported elsewhere, as extenal linkage, and the
+  // destination doesn't yet have its definition.
+  DenseSet MoveSymbolGUIDSet;
+  MoveSymbolGUIDSet.insert_range(MoveSymbolGUID);
+  for (auto &F : DestModule)
+if (!F.isDeclaration() && MoveSymbolGUIDSet.contains(F.getGUID()))
+  F.deleteBody();
 
   IRMover Mover(DestModule);
 
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp 
b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index ae1af943bc11c..81e461e28df17 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -24,6 +24,31 @@ static cl::opt UseSourceFilenameForPromotedLocals(
  "This requires that the source filename has a unique name / "
  "path to avoid name collisions."));
 
+extern cl::list MoveSymbolGUID;
+
+FunctionImportGlobalProcessing::FunctionImportGlobalProcessing(
+Module &M, const ModuleSummaryIndex &Index,
+SetVector *GlobalsToImport, bool 
ClearDSOLocalOnDeclarations)
+: M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
+  ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
+  // If we have a ModuleSummaryIndex but no function to import,
+  // then this is the primary module being compiled in a ThinLTO
+  // backend compilation, and we need to see if it has functions that
+  // may be exported to another backend compi

[llvm-branch-commits] [llvm] [ctxprof] Support for "move" semantics for the contextual root (PR #134192)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin ready_for_review 
https://github.com/llvm/llvm-project/pull/134192
___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,115 @@
+#include 

pcc wrote:

Done

https://github.com/llvm/llvm-project/pull/133530
___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits

pcc wrote:

> We cannot introduce BSD-licensed code to compiler-rt. Please see [my comment 
> for more 
> details](https://github.com/llvm/llvm-project/pull/133530#discussion_r2021952691).

Thanks, resolved by switching to SipHash. 
https://github.com/llvm/llvm-project/pull/134197 extracts the existing SipHash 
implementation into a header that can be included here.

https://github.com/llvm/llvm-project/pull/133530
___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,115 @@
+#include 
+
+#define XXH_INLINE_ALL
+#define XXH_NO_STDLIB
+#define XXH_memcpy __builtin_memcpy
+#define XXH_memset __builtin_memset
+#define XXH_memcmp __builtin_memcmp
+#include "../xxhash.h"
+
+// EmuPAC implements runtime emulation of PAC instructions. If the current
+// CPU supports PAC, EmuPAC uses real PAC instructions. Otherwise, it uses the
+// emulation, which is effectively an implementation of PAC with an IMPDEF
+// hashing scheme based on XXH128.
+//
+// The purpose of the emulation is to allow programs to be built to be portable
+// to machines without PAC support, with some performance loss and increased
+// probability of false positives (due to not being able to portably determine
+// the VA size), while being functionally almost equivalent to running on a
+// machine with PAC support. One example of a use case is if PAC is used in
+// production as a security mitigation, but the testing environment is
+// heterogeneous (i.e. some machines lack PAC support). In this case we would
+// like the testing machines to be able to detect issues resulting
+// from the use of PAC instructions that would affect production by running
+// tests. This can be achieved by building test binaries with EmuPAC and
+// production binaries with real PAC.
+//
+// The emulation assumes that the VA size is at most 48 bits. The architecture
+// as of ARMv8.2, which was the last architecture version in which PAC was not
+// mandatory, permitted VA size up to 52 bits via ARMv8.2-LVA, but we are
+// unaware of an ARMv8.2 CPU that implemented ARMv8.2-LVA.
+
+const uint64_t kMaxVASize = 48;
+const uint64_t kPACMask = ((1ULL << 55) - 1) & ~((1ULL << kMaxVASize) - 1);
+const uint64_t kTTBR1Mask = 1ULL << 55;
+
+// Determine whether PAC is supported without accessing memory. This utilizes
+// the XPACLRI instruction which will copy bit 55 of x30 into at least bit 54 
if
+// PAC is supported and acts as a NOP if PAC is not supported.
+static _Bool pac_supported() {
+  register uintptr_t x30 __asm__("x30") = 1ULL << 55;
+  __asm__ __volatile__("xpaclri" : "+r"(x30));
+  return x30 & (1ULL << 54);
+}
+
+// This asm snippet is used to force the creation of a frame record when
+// calling the EmuPAC functions. This is important because the EmuPAC functions
+// may crash if an auth failure is detected and may be unwound past using a
+// frame pointer based unwinder.
+#ifdef __GCC_HAVE_DWARF2_CFI_ASM
+#define frame_pointer_wrap(sym) \
+  "stp x29, x30, [sp, #-16]!\n" \
+  ".cfi_def_cfa_offset 16\n" \
+  "mov x29, sp\n" \
+  ".cfi_def_cfa w29, 16\n" \
+  ".cfi_offset w30, -8\n" \
+  ".cfi_offset w29, -16\n" \
+  "bl " #sym "\n" \
+  ".cfi_def_cfa wsp, 16\n" \
+  "ldp x29, x30, [sp], #16\n" \
+  ".cfi_def_cfa_offset 0\n" \
+  ".cfi_restore w30\n" \
+  ".cfi_restore w29\n" \
+  "ret"
+#else
+#define frame_pointer_wrap(sym) \
+  "stp x29, x30, [sp, #-16]!\n" \
+  "mov x29, sp\n" \
+  "bl " #sym "\n" \
+  "ldp x29, x30, [sp], #16\n" \
+  "ret"
+#endif
+
+uint64_t __emupac_pacda_impl(uint64_t ptr, uint64_t disc) {
+  if (pac_supported()) {
+__asm__ __volatile__(".arch_extension pauth\npacda %0, %1"
+ : "+r"(ptr)
+ : "r"(disc));
+return ptr;
+  }
+  if (ptr & kTTBR1Mask) {
+if ((ptr & kPACMask) != kPACMask) {
+  return ptr | kPACMask;
+}
+  } else {
+if (ptr & kPACMask) {
+  return ptr & ~kPACMask;
+}
+  }
+  uint64_t hash = XXH3_64bits_withSeed(&ptr, 8, disc);
+  return (ptr & ~kPACMask) | (hash & kPACMask);
+}
+
+__attribute__((naked)) uint64_t __emupac_pacda(uint64_t ptr, uint64_t disc) {
+  __asm__(frame_pointer_wrap(__emupac_pacda_impl));
+}
+
+uint64_t __emupac_autda_impl(uint64_t ptr, uint64_t disc) {
+  if (pac_supported()) {

pcc wrote:

We haven't noticed codegen issues like this in our internal testing (other than 
the performance hit which is expected).

https://github.com/llvm/llvm-project/pull/133530
___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits


@@ -0,0 +1,7343 @@
+/*
+ * xxHash - Extremely Fast Hash algorithm
+ * Header File
+ * Copyright (C) 2012-2023 Yann Collet
+ *
+ * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)

pcc wrote:

Understood, I've uploaded a new change that replaces the hash with SipHash.

Unfortunately SipHash is subtantially slower than xxhash and led to a ~3.5x 
slowdown (vs native PAC instructions) on the benchmark cited in my original RFC 
(and BLAKE3 isn't header only which would make it substantially harder to 
integrate here). Hopefully the performance hit doesn't turn out to be a problem 
here.

https://github.com/llvm/llvm-project/pull/133530
___
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] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-02 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/133530
___
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] Extract SipHash implementation into a header. (PR #134197)

2025-04-02 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 3ef9bf0d07bbae11f8f7bf65eec37e72a21695dd 
7d7b3bee7e0d317d33244fbc2d97c113df8c3b52 --extensions cpp -- 
llvm/lib/Support/SipHash.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Support/SipHash.cpp b/llvm/lib/Support/SipHash.cpp
index 682e9231c7..86dad66420 100644
--- a/llvm/lib/Support/SipHash.cpp
+++ b/llvm/lib/Support/SipHash.cpp
@@ -12,12 +12,12 @@
 
//===--===//
 
 #include "llvm/Support/SipHash.h"
+#include "siphash/SipHash.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Endian.h"
-#include "siphash/SipHash.h"
 #include 
 
 using namespace llvm;

``




https://github.com/llvm/llvm-project/pull/134197
___
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] release/20.x: [Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863) (PR #134194)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/134194
___
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] [DAG][AArch64] Handle truncated buildvectors to allow and(subvector(anyext)) fold. (PR #133915)

2025-04-02 Thread David Green via llvm-branch-commits


@@ -7166,7 +7166,8 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
 
   // if (and x, c) is known to be zero, return 0
   unsigned BitWidth = VT.getScalarSizeInBits();
-  ConstantSDNode *N1C = isConstOrConstSplat(N1);
+  ConstantSDNode *N1C =
+  isConstOrConstSplat(N1, /*AllowUndef*/ false, /*AllowTrunc*/ true);

davemgreen wrote:

> AllowTrunc means the input constant is truncated. But we don't promise 
> zero-extension, I think, so the high bits could be anything. Therefore any 
> comparison that checks those high bits is broken. The check on 7491 is most 
> suspect in this respect, but 7346/7353 is also slightly suspect.

Checking for a mask (either via isMask with a shorter ScalarWidth or by 
checking == 0x as in 7491) would check that the top bits are 0. 
(MatchBSwapHWordLow also only handles scalars). So they should be OK, and 
truncating the constant should just make it is more likely to match in cases 
where the top bits are non-zero.

It would be a good idea to try and protect against future uses not realizing 
that the constant had been truncated, so a optional sounds like a good 
idea.

https://github.com/llvm/llvm-project/pull/133915
___
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] [DAG][AArch64] Handle truncated buildvectors to allow and(subvector(anyext)) fold. (PR #133915)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: David Green (davemgreen)


Changes

This fold was not handling the extended BUILDVECTORs that we see when i8/i16 
are not legal types. Using isConstOrConstSplat(N1, false, true) allows it to 
match truncated constants. The other changes are to make sure that truncated 
values in N1C are treated correctly, the fold we are mostly interested in is
```
  if (N0.getOpcode() == ISD::EXTRACT_SUBVECTOR && N0.hasOneUse() 
&& N1C &&
  ISD::isExtOpcode(N0.getOperand(0).getOpcode())) {
```

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


8 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+8-5) 
- (modified) llvm/test/CodeGen/AArch64/aarch64-neon-vector-insert-uaddlv.ll 
(+4-8) 
- (modified) llvm/test/CodeGen/AArch64/bitcast-extend.ll (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/ctlz.ll (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/ctpop.ll (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/itofp.ll (+31-59) 
- (modified) llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll (+8-15) 
- (modified) llvm/test/CodeGen/AArch64/vector-fcvt.ll (+12-24) 


``diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index dc5c5f38e3bd8..a0969fe575d00 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7166,7 +7166,10 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
 
   // if (and x, c) is known to be zero, return 0
   unsigned BitWidth = VT.getScalarSizeInBits();
-  ConstantSDNode *N1C = isConstOrConstSplat(N1);
+  std::optional N1C;
+  if (ConstantSDNode *C1 =
+  isConstOrConstSplat(N1, /*AllowUndef*/ false, /*AllowTrunc*/ true))
+N1C = C1->getAPIntValue().zextOrTrunc(BitWidth);
   if (N1C && DAG.MaskedValueIsZero(SDValue(N, 0), APInt::getAllOnes(BitWidth)))
 return DAG.getConstant(0, DL, VT);
 
@@ -7197,7 +7200,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
 SDValue N0Op0 = N0.getOperand(0);
 EVT SrcVT = N0Op0.getValueType();
 unsigned SrcBitWidth = SrcVT.getScalarSizeInBits();
-APInt Mask = ~N1C->getAPIntValue();
+APInt Mask = ~*N1C;
 Mask = Mask.trunc(SrcBitWidth);
 
 // fold (and (any_ext V), c) -> (zero_ext V) if 'and' only clears top bits.
@@ -7205,7 +7208,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
   return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, N0Op0);
 
 // fold (and (any_ext V), c) -> (zero_ext (and (trunc V), c)) if 
profitable.
-if (N1C->getAPIntValue().countLeadingZeros() >= (BitWidth - SrcBitWidth) &&
+if (N1C->countLeadingZeros() >= (BitWidth - SrcBitWidth) &&
 TLI.isTruncateFree(VT, SrcVT) && TLI.isZExtFree(SrcVT, VT) &&
 TLI.isTypeDesirableForOp(ISD::AND, SrcVT) &&
 TLI.isNarrowingProfitable(N, VT, SrcVT))
@@ -7350,7 +7353,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
 SDValue Extendee = Ext->getOperand(0);
 
 unsigned ScalarWidth = Extendee.getValueType().getScalarSizeInBits();
-if (N1C->getAPIntValue().isMask(ScalarWidth) &&
+if (N1C->isMask(ScalarWidth) &&
 (!LegalOperations || TLI.isOperationLegal(ISD::ZERO_EXTEND, ExtVT))) {
   //(and (extract_subvector (zext|anyext|sext v) _) iN_mask)
   // => (extract_subvector (iN_zeroext v))
@@ -7488,7 +7491,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
   }
 
   // fold (and (or (srl N, 8), (shl N, 8)), 0x) -> (srl (bswap N), const)
-  if (N1C && N1C->getAPIntValue() == 0x && N0.getOpcode() == ISD::OR) {
+  if (N1C && *N1C == 0x && N0.getOpcode() == ISD::OR) {
 if (SDValue BSwap = MatchBSwapHWordLow(N0.getNode(), N0.getOperand(0),
N0.getOperand(1), false))
   return BSwap;
diff --git a/llvm/test/CodeGen/AArch64/aarch64-neon-vector-insert-uaddlv.ll 
b/llvm/test/CodeGen/AArch64/aarch64-neon-vector-insert-uaddlv.ll
index 412f39f8adc1b..f37767291ca14 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-neon-vector-insert-uaddlv.ll
+++ b/llvm/test/CodeGen/AArch64/aarch64-neon-vector-insert-uaddlv.ll
@@ -282,8 +282,7 @@ define void @insert_vec_v16i8_uaddlv_from_v8i8(ptr %0) {
 ; CHECK-NEXT:uaddlv.8b h1, v0
 ; CHECK-NEXT:stp q0, q0, [x0, #32]
 ; CHECK-NEXT:mov.b v2[0], v1[0]
-; CHECK-NEXT:zip1.8b v2, v2, v2
-; CHECK-NEXT:bic.4h v2, #255, lsl #8
+; CHECK-NEXT:ushll.8h v2, v2, #0
 ; CHECK-NEXT:ushll.4s v2, v2, #0
 ; CHECK-NEXT:ucvtf.4s v2, v2
 ; CHECK-NEXT:stp q2, q0, [x0]
@@ -305,8 +304,7 @@ define void @insert_vec_v8i8_uaddlv_from_v8i8(ptr %0) {
 ; CHECK-NEXT:stp xzr, xzr, [x0, #16]
 ; CHECK-NEXT:uaddlv.8b h1, v0
 ; CHECK-NEXT:mov.b v0[0], v1[0]
-; CHECK-NEXT:zip1.8b v0, v0, v0
-; CHECK-NEXT:bic.4h v0, #255, lsl #8
+; CHECK-NEXT:ushll.8h v0, v0, #0
 ; CHECK-NEXT:ushll.4s v0, v0, #0
 ; CHECK-NEXT:ucvtf.4s v0, v0
 ; CHECK-NEXT:str q0, [x0]
@@ -436,8 +434,7 @@ define void @insert_

[llvm-branch-commits] [libcxx] [libc++][C++03] Remove code that is not used in C++03 (PR #134045)

2025-04-02 Thread Louis Dionne via llvm-branch-commits

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

LGTM, please update the commit message to explain what's being done and this is 
part of the frozen header RFC. Thanks!

https://github.com/llvm/llvm-project/pull/134045
___
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++][C++03] Remove macros that expand to nothing (PR #134046)

2025-04-02 Thread Louis Dionne via llvm-branch-commits

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

Same comment about commit message, please make it self-standing.

https://github.com/llvm/llvm-project/pull/134046
___
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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Fangrui Song via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;

MaskRay wrote:

`= 0` and make the default ctor defaulted `= default;`

https://github.com/llvm/llvm-project/pull/133799
___
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] [LoopInterchange] Improve profitability check for vectorization (PR #133672)

2025-04-02 Thread Ryotaro Kasuga via llvm-branch-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/133672

>From 1a1c1f61a8cb179443d782127c157695bd21f6cc Mon Sep 17 00:00:00 2001
From: Ryotaro Kasuga 
Date: Thu, 27 Mar 2025 10:45:26 +
Subject: [PATCH] [LoopInterchange] Improve profitability check for
 vectorization

The vectorization profitability has a process to check whether a given
loop can be vectorized or not. Since the process is conservative, a loop
that can be vectorized may be deemed not to be possible. This can
trigger unnecessary exchanges.
This patch improves the profitability decision by mitigating such
misjudgments. Before this patch, we considered a loop to be vectorizable
only when there are no loop carried dependencies with the IV of the
loop. However, a loop carried dependency doesn't prevent vectorization
if the distance is positive. This patch makes the vectorization check
more accurate by allowing a loop with the positive dependency. Note that
it is difficult to make a complete decision whether a loop can be
vectorized or not. To achieve this, we must check the vector width and
the distance of dependency.
---
 .../lib/Transforms/Scalar/LoopInterchange.cpp | 128 ++
 .../profitability-vectorization-heuristic.ll  |   8 +-
 2 files changed, 106 insertions(+), 30 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp 
b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 1dccba4cfa7b8..078da53c52b52 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -17,8 +17,8 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
 #include "llvm/Analysis/LoopCacheAnalysis.h"
 #include "llvm/Analysis/LoopInfo.h"
@@ -80,6 +80,21 @@ enum class RuleTy {
   ForVectorization,
 };
 
+/// Store the information about if corresponding direction vector was negated
+/// by normalization or not. This is necessary to restore the original one from
+/// a row of a dependency matrix, because we only manage normalized direction
+/// vectors and duplicate vectors are eliminated. So there may be both original
+/// and negated vectors for a single entry (a row of dependency matrix). E.g.,
+/// if there are two direction vectors `[< =]` and `[> =]`, the later one will
+/// be converted to the same as former one by normalization, so only `[< =]`
+/// would be retained in the final result.
+struct NegatedStatus {
+  bool Original = false;
+  bool Negated = false;
+
+  bool isNonNegativeDir(char Dir) const;
+};
+
 } // end anonymous namespace
 
 // Minimum loop depth supported.
@@ -126,9 +141,10 @@ static void printDepMatrix(CharMatrix &DepMatrix) {
 }
 #endif
 
-static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
- Loop *L, DependenceInfo *DI,
- ScalarEvolution *SE,
+static bool populateDependencyMatrix(CharMatrix &DepMatrix,
+ std::vector &NegStatusVec,
+ unsigned Level, Loop *L,
+ DependenceInfo *DI, ScalarEvolution *SE,
  OptimizationRemarkEmitter *ORE) {
   using ValueVector = SmallVector;
 
@@ -167,7 +183,9 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, 
unsigned Level,
 return false;
   }
   ValueVector::iterator I, IE, J, JE;
-  StringSet<> Seen;
+
+  // Manage all found direction vectors. and map it to the index of DepMatrix.
+  StringMap Seen;
 
   for (I = MemInstr.begin(), IE = MemInstr.end(); I != IE; ++I) {
 for (J = I, JE = MemInstr.end(); J != JE; ++J) {
@@ -182,7 +200,8 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, 
unsigned Level,
 assert(D->isOrdered() && "Expected an output, flow or anti dep.");
 // If the direction vector is negative, normalize it to
 // make it non-negative.
-if (D->normalize(SE))
+bool Normalized = D->normalize(SE);
+if (Normalized)
   LLVM_DEBUG(dbgs() << "Negative dependence vector normalized.\n");
 LLVM_DEBUG(StringRef DepType =
D->isFlow() ? "flow" : D->isAnti() ? "anti" : "output";
@@ -214,8 +233,17 @@ static bool populateDependencyMatrix(CharMatrix 
&DepMatrix, unsigned Level,
 }
 
 // Make sure we only add unique entries to the dependency matrix.
-if (Seen.insert(StringRef(Dep.data(), Dep.size())).second)
+unsigned Index = DepMatrix.size();
+auto [Ite, Inserted] =
+Seen.try_emplace(StringRef(Dep.data(), Dep.size()), Index);
+if (Inserted) {
   DepMatrix.push_back(Dep);
+  NegStatusVec.push_back(NegatedStatus{});
+} else
+  Index = Ite->second;
+
+

[llvm-branch-commits] [lldb] release/20.x: [lldb] Use correct path for lldb-server executable (#131519) (PR #134072)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/134072
___
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] [lldb] release/20.x: [lldb] Use correct path for lldb-server executable (#131519) (PR #134072)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (llvmbot)


Changes

Backport 945c494e2c3c078e26ff521ef3e9455e0ff764ac

Requested by: @DavidSpickett

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


1 Files Affected:

- (modified) lldb/tools/lldb-server/lldb-platform.cpp (+11-7) 


``diff
diff --git a/lldb/tools/lldb-server/lldb-platform.cpp 
b/lldb/tools/lldb-server/lldb-platform.cpp
index 880b45b989b9c..51174a0f443c3 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -31,6 +31,7 @@
 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/HostGetOpt.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Host/MainLoop.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Host/Socket.h"
@@ -256,8 +257,9 @@ static void 
client_handle(GDBRemoteCommunicationServerPlatform &platform,
   printf("Disconnected.\n");
 }
 
-static Status spawn_process(const char *progname, const Socket *conn_socket,
-uint16_t gdb_port, const lldb_private::Args &args,
+static Status spawn_process(const char *progname, const FileSpec &prog,
+const Socket *conn_socket, uint16_t gdb_port,
+const lldb_private::Args &args,
 const std::string &log_file,
 const StringRef log_channels, MainLoop &main_loop) 
{
   Status error;
@@ -267,9 +269,10 @@ static Status spawn_process(const char *progname, const 
Socket *conn_socket,
 
   ProcessLaunchInfo launch_info;
 
-  FileSpec self_spec(progname, FileSpec::Style::native);
-  launch_info.SetExecutableFile(self_spec, true);
+  launch_info.SetExecutableFile(prog, false);
+  launch_info.SetArg0(progname);
   Args &self_args = launch_info.GetArguments();
+  self_args.AppendArgument(progname);
   self_args.AppendArgument(llvm::StringRef("platform"));
   self_args.AppendArgument(llvm::StringRef("--child-platform-fd"));
   self_args.AppendArgument(llvm::to_string(shared_socket.GetSendableFD()));
@@ -551,9 +554,10 @@ int main_platform(int argc, char *argv[]) {
 log_channels, &main_loop,
 &platform_handles](std::unique_ptr sock_up) {
   printf("Connection established.\n");
-  Status error = spawn_process(progname, sock_up.get(),
-   gdbserver_port, inferior_arguments,
-   log_file, log_channels, main_loop);
+  Status error = spawn_process(
+  progname, HostInfo::GetProgramFileSpec(), sock_up.get(),
+  gdbserver_port, inferior_arguments, log_file, log_channels,
+  main_loop);
   if (error.Fail()) {
 Log *log = GetLog(LLDBLog::Platform);
 LLDB_LOGF(log, "spawn_process failed: %s", error.AsCString());

``




https://github.com/llvm/llvm-project/pull/134072
___
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] [LoopInterchange] Improve profitability check for vectorization (PR #133672)

2025-04-02 Thread Ryotaro Kasuga via llvm-branch-commits


@@ -80,6 +80,21 @@ enum class RuleTy {
   ForVectorization,
 };
 
+/// Store the information about if corresponding direction vector was negated

kasuga-fj wrote:

> I think duplicated direction vectors are always allowed. They don't add new 
> or different information, so it shouldn't effect the interpretation of the 
> dependence analysis in any way. The only thing that it affects is processing 
> the same information again and again, so the only benefit of making them 
> unique is to avoid that.

I agree with this, and am only concerned about the compile time degradation. So 
I will try to compare the difference of the number of entries with or without 
making them unique. Thank you for your opinion!

https://github.com/llvm/llvm-project/pull/133672
___
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] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133997)

2025-04-02 Thread Ilya Biryukov via llvm-branch-commits

https://github.com/ilya-biryukov approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/133997
___
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] [LoopInterchange] Improve profitability check for vectorization (PR #133672)

2025-04-02 Thread Sjoerd Meijer via llvm-branch-commits


@@ -80,6 +80,21 @@ enum class RuleTy {
   ForVectorization,
 };
 
+/// Store the information about if corresponding direction vector was negated

sjoerdmeijer wrote:

I think duplicated direction vectors are always allowed. They don't add new or 
different information, so it shouldn't effect the interpretation of the 
dependence analysis in any way. The only thing that it affects is processing 
the same information again and again, so the only benefit of making them unique 
is to avoid that. But if keeping all entries makes the logic easier, there is a 
good reason to not make them unique. I think adding all the state here 
complicates things, and if a simple map of original to negated helps, you've 
certainly got my vote to simplify this. 

https://github.com/llvm/llvm-project/pull/133672
___
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] [llvm] [Coverage] Improve performance of propagating Counter of Expansions (PR #122589)

2025-04-02 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/122589
___
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/20.x: [TailDuplicator] Determine if computed gotos using `blockaddress` (#132536) (PR #133082)

2025-04-02 Thread via llvm-branch-commits

dianqk wrote:

> This introduces an ABI change, I think. It modifies `isIndirectBranch` and 
> removes ` isComputedGoto`

Although I could add a deprecation warning, this might also be considered an 
"ABI" break, so I removed these changes.

https://github.com/llvm/llvm-project/pull/133082
___
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/20.x: Avoid a race condition in opt-viewer/optrecord (#131214) (PR #134058)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/134058
___
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/20.x: Avoid a race condition in opt-viewer/optrecord (#131214) (PR #134058)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:

@serge-sans-paille What do you think about merging this PR to the release 
branch?

https://github.com/llvm/llvm-project/pull/134058
___
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] [llvm] [Coverage] Improve performance of propagating Counter of Expansions (PR #122589)

2025-04-02 Thread NAKAMURA Takumi via llvm-branch-commits


@@ -707,13 +707,16 @@ TEST_P(CoverageMappingTest, expansion_gets_first_counter) 
{
   addCMR(Counter::getCounter(2), "foo", 1, 1, 20, 1);
   addExpansionCMR("bar", "foo", 3, 3, 3, 3);
 
-  writeAndReadCoverageRegions();
-  ASSERT_EQ(1u, OutputFunctions.size());
-  OutputFunctionCoverageData &Output = OutputFunctions.back();
+  ProfileWriter.addRecord({"func", 0x1234, {1, 2, 4}}, Err);
+  EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
+
+  auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
+  ASSERT_EQ(1u, std::distance(FunctionRecords.begin(), FunctionRecords.end()));
 
-  ASSERT_EQ(CounterMappingRegion::ExpansionRegion, Output.Regions[2].Kind);
-  ASSERT_EQ(Counter::getCounter(2), Output.Regions[2].Count);
-  ASSERT_EQ(3U, Output.Regions[2].LineStart);
+  const auto &CR = (*FunctionRecords.begin()).CountedRegions;
+  ASSERT_EQ(CounterMappingRegion::ExpansionRegion, CR[2].Kind);
+  ASSERT_EQ(4u, CR[2].ExecutionCount);
+  ASSERT_EQ(3U, CR[2].LineStart);

chapuni wrote:

This should work w/o this change. May I split out or migrate this in advance?

https://github.com/llvm/llvm-project/pull/122589
___
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/20.x: [TailDuplicator] Determine if computed gotos using `blockaddress` (#132536) (PR #133082)

2025-04-02 Thread via llvm-branch-commits

https://github.com/dianqk updated 
https://github.com/llvm/llvm-project/pull/133082

>From 6a8abf2eb3fae7cd8da3ca3f0d97c3baa06f518e Mon Sep 17 00:00:00 2001
From: dianqk 
Date: Wed, 26 Mar 2025 21:27:43 +0800
Subject: [PATCH] [TailDuplicator] Determine if computed gotos using
 `blockaddress` (#132536)

Using `blockaddress` should be more reliable than determining if an
operand comes from a jump table index.

Alternative: Add the `MachineInstr::MIFlag::ComputedGoto` flag when
lowering `indirectbr`. But I don't think this approach is suitable to
backport.

(cherry picked from commit 66f158d91803875de63d8f2a437ce8ecb22c4141)
---
 llvm/include/llvm/CodeGen/MachineBasicBlock.h |   9 +
 llvm/lib/CodeGen/TailDuplicator.cpp   |   2 +-
 .../CodeGen/X86/tail-dup-computed-goto.mir| 265 +-
 3 files changed, 198 insertions(+), 78 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h 
b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 0b803a9724742..11efb2f656a7a 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -311,6 +311,15 @@ class MachineBasicBlock
   const MachineFunction *getParent() const { return xParent; }
   MachineFunction *getParent() { return xParent; }
 
+  /// Returns true if the original IR terminator is an `indirectbr`. This
+  /// typically corresponds to a `goto` in C, rather than jump tables.
+  bool terminatorIsComputedGoto() const {
+return back().isIndirectBranch() &&
+   llvm::all_of(successors(), [](const MachineBasicBlock *Succ) {
+ return Succ->isIRBlockAddressTaken();
+   });
+  }
+
   using instr_iterator = Instructions::iterator;
   using const_instr_iterator = Instructions::const_iterator;
   using reverse_instr_iterator = Instructions::reverse_iterator;
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp 
b/llvm/lib/CodeGen/TailDuplicator.cpp
index 21f75458c90f3..b0de3c322ddd0 100644
--- a/llvm/lib/CodeGen/TailDuplicator.cpp
+++ b/llvm/lib/CodeGen/TailDuplicator.cpp
@@ -604,7 +604,7 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple,
   bool HasComputedGoto = false;
   if (!TailBB.empty()) {
 HasIndirectbr = TailBB.back().isIndirectBranch();
-HasComputedGoto = TailBB.back().isComputedGoto();
+HasComputedGoto = TailBB.terminatorIsComputedGoto();
   }
 
   if (HasIndirectbr && PreRegAlloc)
diff --git a/llvm/test/CodeGen/X86/tail-dup-computed-goto.mir 
b/llvm/test/CodeGen/X86/tail-dup-computed-goto.mir
index a472dc67d8d51..17de405928d37 100644
--- a/llvm/test/CodeGen/X86/tail-dup-computed-goto.mir
+++ b/llvm/test/CodeGen/X86/tail-dup-computed-goto.mir
@@ -2,15 +2,27 @@
 # RUN: llc -mtriple=x86_64-unknown-linux-gnu -run-pass=early-tailduplication 
-tail-dup-pred-size=1 -tail-dup-succ-size=1 %s -o - | FileCheck %s
 # Check that only the computed goto is not be restrict by tail-dup-pred-size 
and tail-dup-succ-size.
 --- |
+  @computed_goto.dispatch = constant [5 x ptr] [ptr null, ptr 
blockaddress(@computed_goto, %bb1), ptr blockaddress(@computed_goto, %bb2), ptr 
blockaddress(@computed_goto, %bb3), ptr blockaddress(@computed_goto, %bb4)]
   declare i64 @f0()
   declare i64 @f1()
   declare i64 @f2()
   declare i64 @f3()
   declare i64 @f4()
   declare i64 @f5()
-  @computed_goto.dispatch = external global [5 x ptr]
-  define void @computed_goto() { ret void }
+  define void @computed_goto() {
+start:
+  ret void
+bb1:
+  ret void
+bb2:
+  ret void
+bb3:
+  ret void
+bb4:
+  ret void
+  }
   define void @jump_table() { ret void }
+  define void @jump_table_pic() { ret void }
 ...
 ---
 name:computed_goto
@@ -23,98 +35,88 @@ body: |
   ; CHECK-NEXT:   ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, 
implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK-NEXT:   CALL64pcrel32 target-flags(x86-plt) @f0, csr_64, implicit 
$rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
   ; CHECK-NEXT:   ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def 
dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
-  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64 = COPY $rax
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gr64_nosp = COPY $rax
   ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:gr64_nosp = COPY [[COPY]]
-  ; CHECK-NEXT:   [[COPY2:%[0-9]+]]:gr64_nosp = COPY [[COPY1]]
-  ; CHECK-NEXT:   JMP64m $noreg, 8, [[COPY1]], @computed_goto.dispatch, $noreg
+  ; CHECK-NEXT:   JMP64m $noreg, 8, [[COPY]], @computed_goto.dispatch, $noreg
   ; CHECK-NEXT: {{  $}}
-  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT: bb.1.bb1 (ir-block-address-taken %ir-block.bb1):
   ; CHECK-NEXT:   successors: %bb.1(0x2000), %bb.2(0x2000), 
%bb.3(0x2000), %bb.4(0x2000)
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT:   ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, 
implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK-NE

[llvm-branch-commits] [lldb] release/20.x: [lldb] Respect LaunchInfo::SetExecutable in ProcessLauncherPosixFork (#133093) (PR #134079)

2025-04-02 Thread David Spickett via llvm-branch-commits

DavidSpickett wrote:

My justification for this: this is 1 part (2nd part is 
https://github.com/llvm/llvm-project/pull/134072) of fixing 
https://github.com/llvm/llvm-project/issues/132024. Which was a bug introduced 
in lldb 20.

https://github.com/llvm/llvm-project/pull/134079
___
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] [lldb] release/20.x: [lldb] Use correct path for lldb-server executable (#131519) (PR #134072)

2025-04-02 Thread David Spickett via llvm-branch-commits

DavidSpickett wrote:

> I think it's fine, but I believe you'll also need 
> https://github.com/llvm/llvm-project/pull/133093 for this to make a 
> difference.

Thanks for pointing that out, I've reproduced the issue and confirmed that we 
need both changes.

https://github.com/llvm/llvm-project/pull/134079 for the second change.

https://github.com/llvm/llvm-project/pull/134072
___
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/20.x: [GlobalMerge][PPC] Don't merge globals in llvm.metadata section (#131801) (PR #134052)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:

@amy-kwan What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/134052
___
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] [llvm] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)

2025-04-02 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/133996
___
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] llvm-reduce: Change function return types if function is not called (PR #134035)

2025-04-02 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/134035

Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.

>From a413a5294d82f0c9d87ff2b0cbd42fae9484c43f Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 2 Apr 2025 11:45:24 +0700
Subject: [PATCH] llvm-reduce: Change function return types if function is not
 called

Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.
---
 ...reduce-values-to-return-new-return-type.ll | 95 +++
 .../deltas/ReduceValuesToReturn.cpp   |  7 +-
 2 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 
llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll

diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
new file mode 100644
index 0..9ddbbe3def44f
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
@@ -0,0 +1,95 @@
+; Test that llvm-reduce can move intermediate values by inserting
+; early returns when the function already has a different return type
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=RESULT %s < %t
+
+
+@gv = global i32 0, align 4
+@ptr_array = global [2 x ptr] [ptr 
@inst_to_return_has_different_type_but_no_func_call_use,
+   ptr @multiple_callsites_wrong_return_type]
+
+; Should rewrite this return from i64 to i32 since the function has no
+; uses.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_no_func_call_use(
+; RESULT-LABEL: define i32 
@inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+; RESULT-NEXT: %load = load i32, ptr %arg, align 4
+; RESULT-NEXT: ret i32 %load
+define i64 @inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @callsite_different_type_unused_0(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-NEXT: %load = load i32, ptr %arg
+; RESULT-NEXT: store i32 %load, ptr @gv
+; RESULT-NEXT: ret i64 0
+define void @callsite_different_type_unused_0(ptr %arg) {
+  %unused0 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
+  %unused1 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr null)
+  ret void
+}
+
+; TODO: Could rewrite this return from i64 to i32 since the callsite is unused.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT: ret i64 0
+define i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg) 
{
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @multiple_callsites_wrong_return_type(
+; RESULT-LABEL: define i64 @multiple_callsites_wrong_return_type(
+; RESULT: ret i64 0
+define i64 @multiple_callsites_wrong_return_type(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @unused_with_wrong_return_types(
+; RESULT-LABEL: define i64 @unused_with_wrong_return_types(
+; RESULT-NEXT: %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr 
%arg)
+; RESULT-NEXT: ret i64 %unused0
+define void @unused_with_wrong_return_types(ptr %arg) {
+  %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused1 = call i32 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused2 = call ptr @multiple_callsites_wrong_return_type(ptr %arg)
+  ret void
+}
+
+; INTERESTING-LABEL: @multiple_returns_wrong_return_type(
+; INTERESTING: %load0 = load i32,
+
+; RESULT-LABEL: define i32 @multiple_returns_wrong_return_type(
+; RESULT: ret i32
+; RESULT: ret i32
+; RESULT: ret i32
+define i32 @multiple_returns_wrong_return_type(ptr %arg, i1 %cond, i32 %arg2) {
+entry:
+  br i1 %cond, label %bb0, label %bb1
+
+bb0:
+  %load0 = load i32, ptr %arg
+  store i32 %load0, ptr @gv
+  ret i32 234
+
+bb1:
+

[llvm-branch-commits] [lldb] release/20.x: [lldb] Use correct path for lldb-server executable (#131519) (PR #134072)

2025-04-02 Thread Pavel Labath via llvm-branch-commits

labath wrote:

I think it's fine, but I believe you'll also need #133093 for this to make a 
difference.

https://github.com/llvm/llvm-project/pull/134072
___
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] adbf46d - Revert "Enable unnecessary-virtual-specifier by default (#133265)"

2025-04-02 Thread via llvm-branch-commits

Author: Nikolas Klauser
Date: 2025-04-02T17:53:29+02:00
New Revision: adbf46d2b5b226452eee71825dd26b4414617f7d

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

LOG: Revert "Enable unnecessary-virtual-specifier by default (#133265)"

This reverts commit 4007de00a0574141695ace7a8d34aaf740a2c2e4.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
clang/test/CXX/class/p2-0x.cpp
clang/test/SemaCXX/MicrosoftExtensions.cpp
clang/test/SemaCXX/warn-final-dtor-non-final-class.cpp
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 16e1cd4dade8b..09f423ad4b4bd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -377,12 +377,13 @@ def CXX11WarnSuggestOverride : 
DiagGroup<"suggest-override">;
 def WarnUnnecessaryVirtualSpecifier : 
DiagGroup<"unnecessary-virtual-specifier"> {
   code Documentation = [{
 Warns when a ``final`` class contains a virtual method (including virtual
-destructors) that does not override anything. Since ``final`` classes cannot be
-subclassed, their methods cannot be overridden, so there is no point to
-introducing new ``virtual`` methods.
+destructors). Since ``final`` classes cannot be subclassed, their methods
+cannot be overridden, and hence the ``virtual`` specifier is useless.
 
 The warning also detects virtual methods in classes whose destructor is
 ``final``, for the same reason.
+
+The warning does not fire on virtual methods which are also marked 
``override``.
   }];
 }
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2306cb4d7cac4..10568a5ee87fc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2733,7 +2733,7 @@ def note_final_dtor_non_final_class_silence : Note<
   "mark %0 as '%select{final|sealed}1' to silence this warning">;
 def warn_unnecessary_virtual_specifier : Warning<
   "virtual method %0 is inside a 'final' class and can never be overridden">,
-  InGroup;
+  InGroup, DefaultIgnore;
 
 // C++11 attributes
 def err_repeat_attribute : Error<"%0 attribute cannot be repeated">;

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
index 106091b240af6..4209db14eaa52 100644
--- 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
+++ 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor 
-verify %s -Wno-unnecessary-virtual-specifier
+// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor 
-verify %s
 
 #include "mock-types.h"
 

diff  --git a/clang/test/CXX/class/p2-0x.cpp b/clang/test/CXX/class/p2-0x.cpp
index 2043486457baf..5b39e0ada7e2c 100644
--- a/clang/test/CXX/class/p2-0x.cpp
+++ b/clang/test/CXX/class/p2-0x.cpp
@@ -28,7 +28,7 @@ struct C : A { }; // expected-error {{base 'A' is marked 
'final'}}
 
 namespace Test4 {
 
-struct A final { virtual void func() = 0; }; // expected-warning {{abstract 
class is marked 'final'}} expected-note {{unimplemented pure virtual method 
'func' in 'A'}} expected-warning {{virtual method 'func' is inside a 'final' 
class}}}
+struct A final { virtual void func() = 0; }; // expected-warning {{abstract 
class is marked 'final'}} expected-note {{unimplemented pure virtual method 
'func' in 'A'}}
 struct B { virtual void func() = 0; }; // expected-note {{unimplemented pure 
virtual method 'func' in 'C'}}
 
 struct C final : B { }; // expected-warning {{abstract class is marked 
'final'}}

diff  --git a/clang/test/SemaCXX/MicrosoftExtensions.cpp 
b/clang/test/SemaCXX/MicrosoftExtensions.cpp
index 9f6939c1681c9..7454a01158f6b 100644
--- a/clang/test/SemaCXX/MicrosoftExtensions.cpp
+++ b/clang/test/SemaCXX/MicrosoftExtensions.cpp
@@ -470,7 +470,6 @@ struct InheritFromSealed : SealedType {};
 class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 
'sealed' to silence this warning}}
 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
 virtual ~SealedDestructor() sealed; // expected-warning {{class with 
destructor marked 'sealed' cannot be inherited from}}
-  // expected-warning@-1 {{virtual method 
'~SealedDestructor' is inside a 'final' class}}
 };
 
 // expected-warning@+1 {

[llvm-branch-commits] [llvm] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lto

Author: Mircea Trofin (mtrofin)


Changes



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


1 Files Affected:

- (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+14-12) 


``diff
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp 
b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index faa052bb4d5b6..ae3b45a11996e 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -497,6 +497,13 @@ static const char 
*getFailureName(FunctionImporter::ImportFailureReason Reason);
 
 /// Determine the list of imports and exports for each module.
 class ModuleImportsManager {
+  void computeImportForFunction(
+  const FunctionSummary &Summary, unsigned Threshold,
+  const GVSummaryMapTy &DefinedGVSummaries,
+  SmallVectorImpl &Worklist, GlobalsImporter &GVImporter,
+  FunctionImporter::ImportMapTy &ImportList,
+  FunctionImporter::ImportThresholdsTy &ImportThresholds);
+
 protected:
   function_ref
   IsPrevailing;
@@ -851,14 +858,11 @@ getFailureName(FunctionImporter::ImportFailureReason 
Reason) {
 /// Compute the list of functions to import for a given caller. Mark these
 /// imported functions and the symbols they reference in their source module as
 /// exported from their source module.
-static void computeImportForFunction(
-const FunctionSummary &Summary, const ModuleSummaryIndex &Index,
-const unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries,
-function_ref
-isPrevailing,
+void ModuleImportsManager::computeImportForFunction(
+const FunctionSummary &Summary, const unsigned Threshold,
+const GVSummaryMapTy &DefinedGVSummaries,
 SmallVectorImpl &Worklist, GlobalsImporter &GVImporter,
 FunctionImporter::ImportMapTy &ImportList,
-DenseMap *ExportLists,
 FunctionImporter::ImportThresholdsTy &ImportThresholds) {
   GVImporter.onImportingSummary(Summary);
   static int ImportCount = 0;
@@ -1063,9 +1067,8 @@ void ModuleImportsManager::computeImportForModule(
   // Skip import for global variables
   continue;
 LLVM_DEBUG(dbgs() << "Initialize import for " << VI << "\n");
-computeImportForFunction(*FuncSummary, Index, ImportInstrLimit,
- DefinedGVSummaries, IsPrevailing, Worklist, GVI,
- ImportList, ExportLists, ImportThresholds);
+computeImportForFunction(*FuncSummary, ImportInstrLimit, 
DefinedGVSummaries,
+ Worklist, GVI, ImportList, ImportThresholds);
   }
 
   // Process the newly imported functions and add callees to the worklist.
@@ -1075,9 +1078,8 @@ void ModuleImportsManager::computeImportForModule(
 auto Threshold = std::get<1>(GVInfo);
 
 if (auto *FS = dyn_cast(Summary))
-  computeImportForFunction(*FS, Index, Threshold, DefinedGVSummaries,
-   IsPrevailing, Worklist, GVI, ImportList,
-   ExportLists, ImportThresholds);
+  computeImportForFunction(*FS, Threshold, DefinedGVSummaries, Worklist,
+   GVI, ImportList, ImportThresholds);
   }
 
   // Print stats about functions considered but rejected for importing

``




https://github.com/llvm/llvm-project/pull/134011
___
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] [LV] Reduce register usage for scaled reductions (PR #133090)

2025-04-02 Thread Sam Tebbs via llvm-branch-commits

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

>From 9a9164fce2a7fe1d602fd24cf9a9026b06190f31 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Wed, 26 Mar 2025 14:01:59 +
Subject: [PATCH 1/5] [LV] Reduce register usage for scaled reductions

---
 .../Transforms/Vectorize/LoopVectorize.cpp|  24 +-
 .../Transforms/Vectorize/VPRecipeBuilder.h|   3 +-
 llvm/lib/Transforms/Vectorize/VPlan.h |  14 +-
 .../partial-reduce-dot-product-neon.ll| 118 --
 .../AArch64/partial-reduce-dot-product.ll | 344 +-
 5 files changed, 282 insertions(+), 221 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 1dbcbdbe083fe..400a510be308b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5019,10 +5019,23 @@ calculateRegisterUsage(VPlan &Plan, 
ArrayRef VFs,
 // even in the scalar case.
 RegUsage[ClassID] += 1;
   } else {
+// The output from scaled phis and scaled reductions actually have
+// fewer lanes than the VF.
+auto VF = VFs[J];
+if (auto *ReductionR = dyn_cast(R))
+  VF = VF.divideCoefficientBy(ReductionR->getVFScaleFactor());
+else if (auto *PartialReductionR =
+ dyn_cast(R))
+  VF = VF.divideCoefficientBy(PartialReductionR->getScaleFactor());
+if (VF != VFs[J])
+  LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J]
+<< " to " << VF << " for ";
+ R->dump(););
+
 for (VPValue *DefV : R->definedValues()) {
   Type *ScalarTy = TypeInfo.inferScalarType(DefV);
   unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
-  RegUsage[ClassID] += GetRegUsage(ScalarTy, VFs[J]);
+  RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
 }
   }
 }
@@ -8951,8 +8964,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
   if (isa(Instr) || isa(Instr))
 return tryToWidenMemory(Instr, Operands, Range);
 
-  if (getScalingForReduction(Instr))
-return tryToCreatePartialReduction(Instr, Operands);
+  if (auto ScaleFactor = getScalingForReduction(Instr))
+return tryToCreatePartialReduction(Instr, Operands, ScaleFactor.value());
 
   if (!shouldWiden(Instr, Range))
 return nullptr;
@@ -8976,7 +8989,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
 
 VPRecipeBase *
 VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
- ArrayRef Operands) {
+ ArrayRef Operands,
+ unsigned ScaleFactor) {
   assert(Operands.size() == 2 &&
  "Unexpected number of operands for partial reduction");
 
@@ -9009,7 +9023,7 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction 
*Reduction,
 BinOp = Builder.createSelect(Mask, BinOp, Zero, Reduction->getDebugLoc());
   }
   return new VPPartialReductionRecipe(ReductionOpcode, BinOp, Accumulator,
-  Reduction);
+  ScaleFactor, Reduction);
 }
 
 void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h 
b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
index 334cfbad8bd7c..fd0064a34c4c9 100644
--- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
+++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
@@ -178,7 +178,8 @@ class VPRecipeBuilder {
   /// Create and return a partial reduction recipe for a reduction instruction
   /// along with binary operation and reduction phi operands.
   VPRecipeBase *tryToCreatePartialReduction(Instruction *Reduction,
-ArrayRef Operands);
+ArrayRef Operands,
+unsigned ScaleFactor);
 
   /// Set the recipe created for given ingredient.
   void setRecipe(Instruction *I, VPRecipeBase *R) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 37e0a176ab1cc..376526e804b4b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2033,6 +2033,8 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
   /// Generate the phi/select nodes.
   void execute(VPTransformState &State) override;
 
+  unsigned getVFScaleFactor() const { return VFScaleFactor; }
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   /// Print the recipe.
   void print(raw_ostream &O, const Twine &Indent,
@@ -2063,17 +2065,19 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
 /// scalar value.
 class VPPart

[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)

2025-04-02 Thread Sam Tebbs via llvm-branch-commits




SamTebbs33 wrote:

Good idea, done.

https://github.com/llvm/llvm-project/pull/133090
___
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] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133998)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/133998

Backport 65ee2813f9f9a8cd11c5e9ea372da7d12867b52f

Requested by: @cor3ntin

>From 81e0cf124e5ba336311139917c0e5c80d51e7479 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 24 Mar 2025 17:42:33 +0100
Subject: [PATCH] [clang] Do not infer lifetimebound for functions with void
 return type (#131997)

Fixes: https://github.com/llvm/llvm-project/issues/126231
Also found in : https://github.com/microsoft/STL/issues/5271

(cherry picked from commit 65ee2813f9f9a8cd11c5e9ea372da7d12867b52f)
---
 clang/lib/Sema/SemaAttr.cpp  |  5 +
 clang/test/Sema/GH126231.cpp | 18 ++
 2 files changed, 23 insertions(+)
 create mode 100644 clang/test/Sema/GH126231.cpp

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 6907fa91e28c2..27b5eb5f2c773 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -14,6 +14,7 @@
 #include "CheckExprLifetime.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Preprocessor.h"
@@ -219,6 +220,10 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl 
*Record) {
 void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   if (FD->getNumParams() == 0)
 return;
+  // Skip void returning functions (except constructors). This can occur in
+  // cases like 'as_const'.
+  if (!isa(FD) && FD->getReturnType()->isVoidType())
+return;
 
   if (unsigned BuiltinID = FD->getBuiltinID()) {
 // Add lifetime attribute to std::move, std::fowrard et al.
diff --git a/clang/test/Sema/GH126231.cpp b/clang/test/Sema/GH126231.cpp
new file mode 100644
index 0..d10fc79c3b628
--- /dev/null
+++ b/clang/test/Sema/GH126231.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-ignored-attributes -Wno-unused-value 
-verify %s
+// expected-no-diagnostics
+namespace std {
+template 
+constexpr const T& as_const(T&) noexcept;
+
+// We need two declarations to see the error for some reason.
+template  void as_const(const T&&) noexcept = delete;
+template  void as_const(const T&&) noexcept;
+}
+
+namespace GH126231 {
+
+void test() {
+int a = 1;
+std::as_const(a);
+}
+}

___
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/20.x: [GlobalMerge][PPC] Don't merge globals in llvm.metadata section (#131801) (PR #134052)

2025-04-02 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/134052

Backport 9356091a98c24718572f99b51553838ed664b67a

Requested by: @nikic

>From 542310684354c41f148b8b74f8d4ab6247d85b62 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Wed, 2 Apr 2025 16:40:53 +0800
Subject: [PATCH] [GlobalMerge][PPC] Don't merge globals in llvm.metadata
 section (#131801)

The llvm.metadata section is not emitted and has special semantics. We
should not merge globals in it, similarly to how we already skip merging
of `llvm.xyz` globals.

Fixes https://github.com/llvm/llvm-project/issues/131394.

(cherry picked from commit 9356091a98c24718572f99b51553838ed664b67a)
---
 llvm/lib/CodeGen/GlobalMerge.cpp| 3 ++-
 llvm/test/CodeGen/PowerPC/global-merge-llvm-metadata.ll | 9 +
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/global-merge-llvm-metadata.ll

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 5993fc939a08a..b4650a4851c3c 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -711,7 +711,8 @@ bool GlobalMergeImpl::run(Module &M) {
   continue;
 
 // Ignore all 'special' globals.
-if (GV.getName().starts_with("llvm.") || 
GV.getName().starts_with(".llvm."))
+if (GV.getName().starts_with("llvm.") ||
+GV.getName().starts_with(".llvm.") || Section == "llvm.metadata")
   continue;
 
 // Ignore all "required" globals:
diff --git a/llvm/test/CodeGen/PowerPC/global-merge-llvm-metadata.ll 
b/llvm/test/CodeGen/PowerPC/global-merge-llvm-metadata.ll
new file mode 100644
index 0..7db092e13afeb
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/global-merge-llvm-metadata.ll
@@ -0,0 +1,9 @@
+; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+
+@index = global i32 0, align 4
+@.str = private unnamed_addr constant [1 x i8] zeroinitializer, section 
"llvm.metadata"
+@.str.1 = private unnamed_addr constant [7 x i8] c"test.c\00", section 
"llvm.metadata" 
+@llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] 
[{ ptr, ptr, ptr, i32, ptr } { ptr @index, ptr @.str, ptr @.str.1, i32 1, ptr 
null }], section "llvm.metadata"
+
+; CHECK-NOT: .set
+; CHECK-NOT: _MergedGlobals

___
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] [DAG][AArch64] Handle truncated buildvectors to allow and(subvector(anyext)) fold. (PR #133915)

2025-04-02 Thread Simon Pilgrim via llvm-branch-commits


@@ -7166,7 +7166,8 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
 
   // if (and x, c) is known to be zero, return 0
   unsigned BitWidth = VT.getScalarSizeInBits();
-  ConstantSDNode *N1C = isConstOrConstSplat(N1);
+  ConstantSDNode *N1C =
+  isConstOrConstSplat(N1, /*AllowUndef*/ false, /*AllowTrunc*/ true);

RKSimon wrote:

we could replace this with something like:
```cpp
std::optional N1C;
if (ConstantSDNode *C1 = isConstOrConstSplat(N1, /*AllowUndef*/ false, 
/*AllowTrunc*/ true))
  N1C = C1->getAPIntValue().zextOrTrunc(BitWidth);
```
WDYT?

https://github.com/llvm/llvm-project/pull/133915
___
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] [llvm] [Coverage] Improve performance of propagating Counter of Expansions (PR #122589)

2025-04-02 Thread NAKAMURA Takumi via llvm-branch-commits

https://github.com/chapuni edited 
https://github.com/llvm/llvm-project/pull/122589
___
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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() {
 }
 
 namespace {
+// A GOFFSymbol holds all the data required for writing an ESD record.
+class GOFFSymbol {
+public:
+  std::string Name;
+  uint32_t EsdId;
+  uint32_t ParentEsdId;
+  uint64_t Offset = 0; // Offset of the symbol into the section. LD only.
+   // Offset is only 32 bit, the larger type is used to
+   // enable error checking.
+  GOFF::ESDSymbolType SymbolType;
+  GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder;
+
+  GOFF::BehavioralAttributes BehavAttrs;
+  GOFF::SymbolFlags SymbolFlags;
+  uint32_t SortKey = 0;
+  uint32_t SectionLength = 0;
+  uint32_t ADAEsdId = 0;
+  uint32_t EASectionEDEsdId = 0;
+  uint32_t EASectionOffset = 0;
+  uint8_t FillByteValue = 0;
+
+  GOFFSymbol() : EsdId(0), ParentEsdId(0) {}
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0),
+SymbolType(GOFF::ESD_ST_SectionDefinition) {
+BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const EDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_ElementDefinition) {
+this->NameSpace = Attr.NameSpace;
+// TODO Do we need/should set the "mangled" flag?
+SymbolFlags.setFillBytePresence(1);
+SymbolFlags.setReservedQwords(Attr.ReservedQwords);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setRmode(Attr.Rmode);
+BehavAttrs.setTextStyle(Attr.TextStyle);
+BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm);
+BehavAttrs.setLoadingBehavior(Attr.LoadBehavior);
+BehavAttrs.setAlignment(Attr.Alignment);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const LDAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_LabelDefinition) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setBindingStrength(Attr.BindingStrength);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+  }
+
+  GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID,
+ const PRAttr &Attr)
+  : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID),
+SymbolType(GOFF::ESD_ST_PartReference) {
+this->NameSpace = Attr.NameSpace;
+SymbolFlags.setRenameable(Attr.IsRenamable);
+BehavAttrs.setExecutable(Attr.Executable);
+BehavAttrs.setAlignment(Attr.Alignment);
+BehavAttrs.setAmode(Attr.Amode);
+BehavAttrs.setLinkageType(Attr.Linkage);
+BehavAttrs.setBindingScope(Attr.BindingScope);
+BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity);
+BehavAttrs.setReadOnly(Attr.IsReadOnly);
+  }
+};
+
 class GOFFWriter {
   GOFFOstream OS;
   [[maybe_unused]] MCAssembler &Asm;
 
+  /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes.
+  GOFFSymbolMapper SymbolMapper;
+
+  /// Counter for symbol id's.
+  uint32_t EsdIdCounter = 0;
+
+  /// Id's of some special symbols.
+  uint32_t RootSDEsdId = 0;
+  uint32_t ADAEsdId = 0;
+
   void writeHeader();
+  void writeSymbol(const GOFFSymbol &Symbol);
   void writeEnd();
 
+  GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+  uint32_t ParentEsdId);
+  GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr,
+  uint32_t ParentEsdId);
+
+  void defineRootSymbol(const MCSectionGOFF *Text);
+  void defineSectionSymbols(const MCSectionGOFF &Section);
+  void defineSymbols();
+
 public:
   GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm);
   uint64_t writeObject();
 };
 } // namespace
 
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
-: OS(OS), Asm(Asm) {}
+: OS(OS), Asm(Asm), SymbolMapper(Asm) {}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr,
+uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr,
+uint32_t Par

[llvm-branch-commits] [llvm] [SPARC][MC] Add tests for VIS family instructions (PR #130967)

2025-04-02 Thread via llvm-branch-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/130967

>From e2e0d44800b65a8fbddd6234c2ee9f83af92d7da Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Wed, 12 Mar 2025 21:14:42 +0700
Subject: [PATCH 1/4] Add missing NO-VIS lines

Created using spr 1.3.5
---
 llvm/test/MC/Sparc/sparc-vis.s | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/llvm/test/MC/Sparc/sparc-vis.s b/llvm/test/MC/Sparc/sparc-vis.s
index bf01da19293d0..bed901b6a7272 100644
--- a/llvm/test/MC/Sparc/sparc-vis.s
+++ b/llvm/test/MC/Sparc/sparc-vis.s
@@ -199,28 +199,39 @@ fcmpeq16 %f0, %f2, %o0
 ! VIS: fcmpeq32 %f0, %f2, %o0  ! encoding: 
[0x91,0xb0,0x05,0xc2]
 fcmpeq32 %f0, %f2, %o0
 
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge8 %o0, %o1, %o2 ! encoding: 
[0x95,0xb2,0x00,0x09]
 edge8 %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge8l %o0, %o1, %o2! encoding: 
[0x95,0xb2,0x00,0x49]
 edge8l %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge16 %o0, %o1, %o2! encoding: 
[0x95,0xb2,0x00,0x89]
 edge16 %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge16l %o0, %o1, %o2   ! encoding: 
[0x95,0xb2,0x00,0xc9]
 edge16l %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge32 %o0, %o1, %o2! encoding: 
[0x95,0xb2,0x01,0x09]
 edge32 %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: edge32l %o0, %o1, %o2   ! encoding: 
[0x95,0xb2,0x01,0x49]
 edge32l %o0, %o1, %o2
 
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: pdist %f0, %f2, %f4 ! encoding: 
[0x89,0xb0,0x07,0xc2]
 pdist %f0, %f2, %f4
 
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: array8 %o0, %o1, %o2! encoding: 
[0x95,0xb2,0x02,0x09]
 array8 %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: array16 %o0, %o1, %o2   ! encoding: 
[0x95,0xb2,0x02,0x49]
 array16 %o0, %o1, %o2
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: array32 %o0, %o1, %o2   ! encoding: 
[0x95,0xb2,0x02,0x89]
 array32 %o0, %o1, %o2
 
+! NO-VIS: error: instruction requires a CPU feature not currently enabled
 ! VIS: shutdown! encoding: 
[0x81,0xb0,0x10,0x00]
 shutdown

>From b98295fcdaa9fc1d6a839956c304dd5a7d31cc24 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Wed, 12 Mar 2025 22:27:36 +0700
Subject: [PATCH 2/4] Fix typo in comment

Created using spr 1.3.5
---
 llvm/lib/Target/Sparc/SparcInstrVIS.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/Sparc/SparcInstrVIS.td 
b/llvm/lib/Target/Sparc/SparcInstrVIS.td
index 6d0f12da3afcf..fbf56ae22cd30 100644
--- a/llvm/lib/Target/Sparc/SparcInstrVIS.td
+++ b/llvm/lib/Target/Sparc/SparcInstrVIS.td
@@ -7,7 +7,7 @@
 
//===--===//
 //
 // This file contains instruction formats, definitions and patterns needed for
-// VIS, VIS II, VIS II instructions on SPARC.
+// VIS, VIS II, VIS III instructions on SPARC.
 
//===--===//
 
 // VIS Instruction Format.

>From 618c4853f63fa60bd6d6d0e9ec69d6149e2b2137 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Sun, 23 Mar 2025 20:51:40 +0700
Subject: [PATCH 3/4] Apply suggestions

Created using spr 1.3.5
---
 llvm/lib/Target/Sparc/SparcInstrFormats.td | 4 ++--
 llvm/lib/Target/Sparc/SparcInstrInfo.td| 3 ++-
 llvm/lib/Target/Sparc/SparcInstrVIS.td | 2 +-
 llvm/test/MC/Sparc/sparc-vis.s | 2 +-
 llvm/test/MC/Sparc/sparc-vis2.s| 2 +-
 llvm/test/MC/Sparc/sparc-vis3.s| 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/Sparc/SparcInstrFormats.td 
b/llvm/lib/Target/Sparc/SparcInstrFormats.td
index 7d32cd8e5671b..3ddb485923fcc 100644
--- a/llvm/lib/Target/Sparc/SparcInstrFormats.td
+++ b/llvm/lib/Target/Sparc/SparcInstrFormats.td
@@ -205,7 +205,7 @@ class F3_3c opVal, bits<6> op3val, bits<9> opfval, 
dag outs, dag ins,
 class F3_3_siam opVal, bits<6> op3val, bits<9> opfval, dag outs, dag 
ins,
string asmstr, list pattern, InstrItinClass itin = NoItinerary>
: F3 {
-  bits<3> siam_mode;
+  bits<3> uimm3;
 
   let op = opVal;
   let op3= op3val;
@@ -213,7 +213,7 @@ class F3_3_siam opVal, bits<6> op3val, bits<9> 
opfval, dag outs, dag ins
   let rs1= 0;
   let Inst{13-5} = opfval;   // fp opcode
   let Inst{4-3}  = 0;
-  let Inst{2-0}  = siam_mode;
+  let Inst{2-0}  = uimm3;
 }
 
 // 

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits

https://github.com/redstar updated 
https://github.com/llvm/llvm-project/pull/133799

>From 77c230f82a61769714bee98b2e848820850d9cb5 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 24 Mar 2025 16:26:19 -0400
Subject: [PATCH 1/5] [GOFF] Add writing of section symbols

The GOFF format uses symbol definitions to represent sections and
symbols. Introducing a section can require up to 3 symbol definitions.
However, most of these details are not needed by the AsmPrinter.
To mapped from a section (a MCSectionGOFF) to the symbol definitions,
a new class called MCGOFFSymbolMapper is used. The same information
can also be used by the assembly output, which justifies this
centralized approach. Writing the mapped symbols is then straight
forward.
---
 llvm/include/llvm/BinaryFormat/GOFF.h |  85 +++
 llvm/include/llvm/MC/MCGOFFSymbolMapper.h | 148 +++
 llvm/lib/MC/CMakeLists.txt|   1 +
 llvm/lib/MC/GOFFObjectWriter.cpp  | 290 +++---
 llvm/lib/MC/MCGOFFSymbolMapper.cpp| 203 +++
 llvm/lib/MC/MCObjectFileInfo.cpp  |   2 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |   2 +-
 llvm/test/MC/GOFF/section.ll  |  73 ++
 8 files changed, 765 insertions(+), 39 deletions(-)
 create mode 100644 llvm/include/llvm/MC/MCGOFFSymbolMapper.h
 create mode 100644 llvm/lib/MC/MCGOFFSymbolMapper.cpp
 create mode 100644 llvm/test/MC/GOFF/section.ll

diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h 
b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8..43d80e0c247e9 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,
+// offset 41, for the definition.
+struct SymbolFlags {
+  Flags SymFlags;
+
+#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) 
\
+  void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); }  
\
+  TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); }
+
+  GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1)
+  GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1)
+  GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1)
+  GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1)
+  GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3)
+
+#undef GOFF_SYMBOL_FLAG
+
+constexpr operator uint8_t() const { return static_cast(SymFlags); }
+};
+
+// Structure for the behavioral attributes. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=record-external-symbol-definition-behavioral-attributes
+// for the definition.
+struct BehavioralAttributes {
+  Flags Attr[10];
+
+#define GOFF_BEHAVIORAL_ATTRIBUTE(NAME, TYPE, ATTRIDX, BITINDEX, LENGTH)   
\
+  void set##NAME(TYPE Val) { Attr[ATTRIDX].set(BITINDEX, LENGTH, Val); } 
\
+  TYPE get##NAME() const { return Attr[ATTRIDX].get(BITINDEX, LENGTH); }
+
+  GOFF_BEHAVIORAL_ATTRIBUTE(Amode, GOFF::ESDAmode, 0, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Rmode, GOFF::ESDRmode, 1, 0, 8)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TextStyle, GOFF::ESDTextStyle, 2, 0, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingAlgorithm, GOFF::ESDBindingAlgorithm, 2, 4,
+4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(TaskingBehavior, GOFF::ESDTaskingBehavior, 3, 0, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(ReadOnly, bool, 3, 4, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(Executable, GOFF::ESDExecutable, 3, 5, 3)
+  GOFF_BEHAVIORAL_ATTRIBUTE(DuplicateSymbolSeverity,
+GOFF::ESDDuplicateSymbolSeverity, 4, 2, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(BindingStrength, GOFF::ESDBindingStrength, 4, 4, 4)
+  GOFF_BEHAVIORAL_ATTRIBUTE(LoadingBehavior, GOFF::ESDLoadingBehavior, 5, 0, 2)
+  GOFF_BEHAVIORAL_ATTRIBUTE(COMMON, bool, 5, 2, 1)
+  GOFF_BEHAVIORAL_ATTRIBUTE(IndirectReference

[llvm-branch-commits] [llvm] [ctxprof] Don't import roots elsewhere (PR #134012)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin ready_for_review 
https://github.com/llvm/llvm-project/pull/134012
___
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] [ctxprof] Don't import roots elsewhere (PR #134012)

2025-04-02 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Mircea Trofin (mtrofin)


Changes

Block a context root from being imported by its callers. 

Suppose that happened. Its caller - usually a message pump - inlines its copy 
of the root. Then it (the root) and whatever it calls will be the 
non-contextually optimized callee versions.

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


2 Files Affected:

- (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+17) 
- (modified) llvm/test/ThinLTO/X86/ctxprof-separate-module.ll (+21-3) 


``diff
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp 
b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index ae3b45a11996e..4415ed55ad9f3 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -516,6 +516,7 @@ class ModuleImportsManager {
   const ModuleSummaryIndex &Index,
   DenseMap *ExportLists = 
nullptr)
   : IsPrevailing(IsPrevailing), Index(Index), ExportLists(ExportLists) {}
+  virtual bool canImport(ValueInfo VI) { return true; }
 
 public:
   virtual ~ModuleImportsManager() = default;
@@ -544,6 +545,10 @@ class WorkloadImportsManager : public ModuleImportsManager 
{
   // determine if a module's import list should be done by the base
   // ModuleImportsManager or by us.
   StringMap> Workloads;
+  // Track the roots to avoid importing them due to other callers. We want 
there
+  // to be only one variant, for which we optimize according to the contextual
+  // profile.
+  DenseSet Roots;
 
   void
   computeImportForModule(const GVSummaryMapTy &DefinedGVSummaries,
@@ -782,12 +787,15 @@ class WorkloadImportsManager : public 
ModuleImportsManager {
   }
   auto &Set = Workloads[RootDefiningModule];
   Root.getContainedGuids(ContainedGUIDs);
+  Roots.insert(RootVI);
   for (auto Guid : ContainedGUIDs)
 if (auto VI = Index.getValueInfo(Guid))
   Set.insert(VI);
 }
   }
 
+  bool canImport(ValueInfo VI) override { return !Roots.contains(VI); }
+
 public:
   WorkloadImportsManager(
   function_ref
@@ -885,6 +893,15 @@ void ModuleImportsManager::computeImportForFunction(
   continue;
 }
 
+if (!canImport(VI)) {
+  LLVM_DEBUG(
+  dbgs() << "Skipping over " << VI.getGUID()
+ << " because its import is handled in a different module.");
+  assert(VI.getSummaryList().size() == 1 &&
+ "The root was expected to be an external symbol");
+  continue;
+}
+
 auto GetBonusMultiplier = [](CalleeInfo::HotnessType Hotness) -> float {
   if (Hotness == CalleeInfo::HotnessType::Hot)
 return ImportHotMultiplier;
diff --git a/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll 
b/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll
index c7891d336cc89..391fe21a1b638 100644
--- a/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll
+++ b/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll
@@ -1,3 +1,4 @@
+; REQUIRES: asserts
 ; Test workload based importing via -thinlto-pgo-ctx-prof with moving the whole
 ; graph to a new module.
 ; Use external linkage symbols so we don't depend on module paths which are
@@ -10,19 +11,25 @@
 ;
 ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m1.ll -o 
%t/m1.bc
 ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m2.ll -o 
%t/m2.bc
+; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m3.ll -o 
%t/m3.bc
 ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen 
%t/6019442868614718803.ll -o %t/6019442868614718803.bc
 
 ; RUN: llvm-ctxprof-util fromYAML --input %t/ctxprof.yaml --output 
%t/ctxprof.bitstream
-; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc %t/6019442868614718803.bc 
-thinlto-move-ctxprof-trees \
+; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc %t/m3.bc %t/6019442868614718803.bc 
-thinlto-move-ctxprof-trees \
 ; RUN:  -o %t/result.o -save-temps \
 ; RUN:  -use-ctx-profile=%t/ctxprof.bitstream \
 ; RUN:  -r %t/m1.bc,m1_f1,plx \
-; RUN:  -r %t/m2.bc,m2_f1,plx
-; RUN: llvm-dis %t/result.o.3.3.import.bc -o - | FileCheck %s
+; RUN:  -r %t/m2.bc,m2_f1,plx \
+; RUN:  -r %t/m3.bc,m1_f1 \
+; RUN:  -r %t/m3.bc,m3_f1,plx -debug-only=function-import 2>&1 | FileCheck %s 
--check-prefix=ABSENT-MSG
+; RUN: llvm-dis %t/result.o.4.3.import.bc -o - | FileCheck %s
+; RUN: llvm-dis %t/result.o.3.3.import.bc -o - | FileCheck %s 
--check-prefix=ABSENT
 ;
 ;
 ; CHECK: m1_f1()
 ; CHECK: m2_f1()
+; ABSENT: declare void @m1_f1()
+; ABSENT-MSG: Skipping over 6019442868614718803 because its import is handled 
in a different module.
 ;
 ;--- ctxprof.yaml
 Contexts: 
@@ -51,6 +58,17 @@ define dso_local void @m2_f1() {
   ret void
 }
 
+;--- m3.ll
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-linux-gnu"
+
+declare void @m1_f1()
+
+define dso_local void @m3_f1() {
+  call void @m1_f1()
+  ret void
+}
+
 ;--- 6019442868614718803.ll
 target datalayout = 
"e-

[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;

redstar wrote:

Changed.

https://github.com/llvm/llvm-project/pull/133799
___
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] [ctxprof] Don't import roots elsewhere (PR #134012)

2025-04-02 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin edited 
https://github.com/llvm/llvm-project/pull/134012
___
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] [GOFF] Add writing of section symbols (PR #133799)

2025-04-02 Thread Kai Nacke via llvm-branch-commits


@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t {
   SK_PPA1 = 2,
   SK_PPA2 = 4,
 };
+
+// The standard System/390 convention is to name the high-order (leftmost) bit
+// in a byte as bit zero. The Flags type helps to set bits in byte according
+// to this numeration order.
+class Flags {
+  uint8_t Val;
+
+  constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t 
Value,
+uint8_t OldValue) {
+uint8_t Pos = 8 - BitIndex - Length;
+uint8_t Mask = ((1 << Length) - 1) << Pos;
+Value = Value << Pos;
+return (OldValue & ~Mask) | Value;
+  }
+
+public:
+  constexpr Flags() : Val(0) {}
+  constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value)
+  : Val(bits(BitIndex, Length, Value, 0)) {}
+
+  template 
+  constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) {
+Val = bits(BitIndex, Length, static_cast(NewValue), Val);
+  }
+
+  template 
+  constexpr T get(uint8_t BitIndex, uint8_t Length) const {
+return static_cast((Val >> (8 - BitIndex - Length)) &
+  ((1 << Length) - 1));
+  }
+
+  constexpr operator uint8_t() const { return Val; }
+};
+
+// Structure for the flag field of a symbol. See
+// 
https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record,

redstar wrote:

Changed.

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