[llvm-branch-commits] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/DavidSpickett approved this pull request. LGTM Looking forward to the other things we can do once there is only GitHub to think about. https://github.com/llvm/llvm-project/pull/143481 ___ 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] [CI] Cleanup buildkite test report script (PR #143480)
https://github.com/DavidSpickett approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/143480 ___ 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] [CI] Refactor out some early exits in compute_projects (PR #143478)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143478 ___ 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] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143481 ___ 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] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143481 ___ 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] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143481 ___ 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: [llvm-rc] Allow ALT on non-virtkey accelerators (#143374) (PR #143496)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/143496 ___ 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: [llvm-rc] Allow ALT on non-virtkey accelerators (#143374) (PR #143496)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/143496 Backport 77347d6513de6a6f5dee8ade76e0a0ad1552c12b Requested by: @mstorsjo >From 131293d552947fa64facc1ed9441f74027579b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 10 Jun 2025 10:23:19 +0300 Subject: [PATCH] [llvm-rc] Allow ALT on non-virtkey accelerators (#143374) While https://learn.microsoft.com/en-us/windows/win32/menurc/accelerators-resource specifies that ALT only applies to virtkeys, this doesn't seem to be the case in reality. https://learn.microsoft.com/en-us/windows/win32/menurc/using-keyboard-accelerators contains an example that uses this combination: "B", ID_ACCEL5, ALT ; ALT_SHIFT+B Also Microsoft also includes such cases in their repo of test cases: https://github.com/microsoft/Windows-classic-samples/blob/263dd514ad215d0a40d1ec44b4df84b30ec11dcf/Samples/Win7Samples/begin/sdkdiff/sdkdiff.rc#L161-L164 Also MS rc.exe doesn't warn/error about this. However if applying SHIFT or CONTROL on a non-virtkey accelerator, MS rc.exe does produce this warning: warning RC4203 : SHIFT or CONTROL used without VIRTKEY Hence, keep the checks for SHIFT and CONTROL, but remove the checks for ALT, which seems to have been incorrect. This fixes one aspect of https://github.com/llvm/llvm-project/issues/143157. (cherry picked from commit 77347d6513de6a6f5dee8ade76e0a0ad1552c12b) --- .../llvm-rc/Inputs/tag-accelerators-ascii-alt.rc | 4 .../test/tools/llvm-rc/Inputs/tag-accelerators.rc | 1 + llvm/test/tools/llvm-rc/tag-accelerators.test | 15 +-- llvm/tools/llvm-rc/ResourceFileWriter.cpp | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 llvm/test/tools/llvm-rc/Inputs/tag-accelerators-ascii-alt.rc diff --git a/llvm/test/tools/llvm-rc/Inputs/tag-accelerators-ascii-alt.rc b/llvm/test/tools/llvm-rc/Inputs/tag-accelerators-ascii-alt.rc deleted file mode 100644 index 363263bfe4cf2..0 --- a/llvm/test/tools/llvm-rc/Inputs/tag-accelerators-ascii-alt.rc +++ /dev/null @@ -1,4 +0,0 @@ -2 ACCELERATORS { - "A", 15, ASCII, ALT -} - diff --git a/llvm/test/tools/llvm-rc/Inputs/tag-accelerators.rc b/llvm/test/tools/llvm-rc/Inputs/tag-accelerators.rc index 90e7f926cc087..bcfc35bdeab68 100644 --- a/llvm/test/tools/llvm-rc/Inputs/tag-accelerators.rc +++ b/llvm/test/tools/llvm-rc/Inputs/tag-accelerators.rc @@ -110,5 +110,6 @@ LANGUAGE 5, 1 "7", 71, VIRTKEY, NOINVERT, CONTROL, SHIFT, ALT "^j", 72, ASCII "^j", 73, ASCII, NOINVERT + "A", 15, ASCII, ALT } diff --git a/llvm/test/tools/llvm-rc/tag-accelerators.test b/llvm/test/tools/llvm-rc/tag-accelerators.test index 336727f617687..4f44aebc75011 100644 --- a/llvm/test/tools/llvm-rc/tag-accelerators.test +++ b/llvm/test/tools/llvm-rc/tag-accelerators.test @@ -37,7 +37,7 @@ ; ACCELERATORS-NEXT: Version (major): 0 ; ACCELERATORS-NEXT: Version (minor): 0 ; ACCELERATORS-NEXT: Characteristics: 0 -; ACCELERATORS-NEXT: Data size: 592 +; ACCELERATORS-NEXT: Data size: 600 ; ACCELERATORS-NEXT: Data: ( ; ACCELERATORS-NEXT: : 2A00 01002A00 0100 |..*...*.| ; ACCELERATORS-NEXT: 0010: 02002A00 0200 03002A00 0300 |..*...*.| @@ -75,7 +75,8 @@ ; ACCELERATORS-NEXT: 0210: 15003700 4200 0F003700 4300 |..7.B.7.C...| ; ACCELERATORS-NEXT: 0220: 1B003700 4400 17003700 4500 |..7.D.7.E...| ; ACCELERATORS-NEXT: 0230: 1D003700 4600 1F003700 4700 |..7.F.7.G...| -; ACCELERATORS-NEXT: 0240: 0A00 4800 82000A00 4900 |H...I...| +; ACCELERATORS-NEXT: 0240: 0A00 4800 02000A00 4900 |H...I...| +; ACCELERATORS-NEXT: 0250: 90004100 0F00|..A.| ; ACCELERATORS-NEXT: ) @@ -94,19 +95,13 @@ ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2 ; ASCII2: llvm-rc: Error in ACCELERATORS statement (ID 2): -; ASCII2-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators +; ASCII2-NEXT: Accelerator ID 15: Can only apply SHIFT or CONTROL to VIRTKEY accelerators ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3 ; ASCII3: llvm-rc: Error in ACCELERATORS statement (ID 2): -; ASCII3-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators - - -; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4 - -; ASCII4: llvm-rc: Error in ACCELERATORS statement (ID 2): -; ASCII4-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators +; ASCII3-NEXT: Accelerator ID 15: Can only apply SHIFT or CONTROL to VIRTKEY accelerators ; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accel
[llvm-branch-commits] [llvm] release/20.x: [llvm-rc] Allow ALT on non-virtkey accelerators (#143374) (PR #143496)
llvmbot wrote: @cjacek What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/143496 ___ 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] [CI] Refactor out some early exits in compute_projects (PR #143478)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143478 ___ 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] [CI] Cleanup buildkite test report script (PR #143480)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143480 >From 4a2932807356182b03566460492a2dc17c023a85 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Mon, 9 Jun 2025 22:45:18 -0700 Subject: [PATCH] update Created using spr 1.3.6 --- .ci/generate-buildkite-pipeline-premerge | 131 --- 1 file changed, 131 deletions(-) delete mode 100755 .ci/generate-buildkite-pipeline-premerge diff --git a/.ci/generate-buildkite-pipeline-premerge b/.ci/generate-buildkite-pipeline-premerge deleted file mode 100755 index 5e5f916f35b72..0 --- a/.ci/generate-buildkite-pipeline-premerge +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash -#===--===## -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===--===## - -# -# This file generates a Buildkite pipeline that triggers the various CI jobs for -# the LLVM project during pre-commit CI. -# -# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format. -# -# As this outputs a yaml file, it's possible to log messages to stderr or -# prefix with "#". - - -set -eu -set -o pipefail - -# Environment variables script works with: - -# Set by buildkite -: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=} -: ${BUILDKITE_COMMIT:=} -: ${BUILDKITE_BRANCH:=} -# Fetch origin to have an up to date merge base for the diff. -git fetch origin -# List of files affected by this commit -: ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)} -# Filter rules for generic windows tests -: ${WINDOWS_AGENTS:='{"queue": "windows"}'} -# Filter rules for generic linux tests -: ${LINUX_AGENTS:='{"queue": "linux"}'} - -reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" -if [[ "${reviewID}" != "" ]]; then - buildMessage="https://llvm.org/${reviewID}"; -else - buildMessage="Push to branch ${BUILDKITE_BRANCH}" -fi - -cat <&2 -echo "$MODIFIED_FILES" >&2 -modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u) -echo "Directories modified:" >&2 -echo "$modified_dirs" >&2 - -# Project specific pipelines. - -# If libc++ or one of the runtimes directories changed. -if echo "$modified_dirs" | grep -q -E "^(libcxx|libcxxabi|libunwind|runtimes|cmake)$"; then - cat
[llvm-branch-commits] [llvm] [CI] Cleanup buildkite test report script (PR #143480)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143480 >From 4a2932807356182b03566460492a2dc17c023a85 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Mon, 9 Jun 2025 22:45:18 -0700 Subject: [PATCH] update Created using spr 1.3.6 --- .ci/generate-buildkite-pipeline-premerge | 131 --- 1 file changed, 131 deletions(-) delete mode 100755 .ci/generate-buildkite-pipeline-premerge diff --git a/.ci/generate-buildkite-pipeline-premerge b/.ci/generate-buildkite-pipeline-premerge deleted file mode 100755 index 5e5f916f35b72..0 --- a/.ci/generate-buildkite-pipeline-premerge +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash -#===--===## -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===--===## - -# -# This file generates a Buildkite pipeline that triggers the various CI jobs for -# the LLVM project during pre-commit CI. -# -# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format. -# -# As this outputs a yaml file, it's possible to log messages to stderr or -# prefix with "#". - - -set -eu -set -o pipefail - -# Environment variables script works with: - -# Set by buildkite -: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=} -: ${BUILDKITE_COMMIT:=} -: ${BUILDKITE_BRANCH:=} -# Fetch origin to have an up to date merge base for the diff. -git fetch origin -# List of files affected by this commit -: ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)} -# Filter rules for generic windows tests -: ${WINDOWS_AGENTS:='{"queue": "windows"}'} -# Filter rules for generic linux tests -: ${LINUX_AGENTS:='{"queue": "linux"}'} - -reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" -if [[ "${reviewID}" != "" ]]; then - buildMessage="https://llvm.org/${reviewID}"; -else - buildMessage="Push to branch ${BUILDKITE_BRANCH}" -fi - -cat <&2 -echo "$MODIFIED_FILES" >&2 -modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u) -echo "Directories modified:" >&2 -echo "$modified_dirs" >&2 - -# Project specific pipelines. - -# If libc++ or one of the runtimes directories changed. -if echo "$modified_dirs" | grep -q -E "^(libcxx|libcxxabi|libunwind|runtimes|cmake)$"; then - cat
[llvm-branch-commits] [llvm] [CI] Cleanup buildkite test report script (PR #143480)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143480 >From 4a2932807356182b03566460492a2dc17c023a85 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Mon, 9 Jun 2025 22:45:18 -0700 Subject: [PATCH] update Created using spr 1.3.6 --- .ci/generate-buildkite-pipeline-premerge | 131 --- 1 file changed, 131 deletions(-) delete mode 100755 .ci/generate-buildkite-pipeline-premerge diff --git a/.ci/generate-buildkite-pipeline-premerge b/.ci/generate-buildkite-pipeline-premerge deleted file mode 100755 index 5e5f916f35b72..0 --- a/.ci/generate-buildkite-pipeline-premerge +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash -#===--===## -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===--===## - -# -# This file generates a Buildkite pipeline that triggers the various CI jobs for -# the LLVM project during pre-commit CI. -# -# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format. -# -# As this outputs a yaml file, it's possible to log messages to stderr or -# prefix with "#". - - -set -eu -set -o pipefail - -# Environment variables script works with: - -# Set by buildkite -: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=} -: ${BUILDKITE_COMMIT:=} -: ${BUILDKITE_BRANCH:=} -# Fetch origin to have an up to date merge base for the diff. -git fetch origin -# List of files affected by this commit -: ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)} -# Filter rules for generic windows tests -: ${WINDOWS_AGENTS:='{"queue": "windows"}'} -# Filter rules for generic linux tests -: ${LINUX_AGENTS:='{"queue": "linux"}'} - -reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" -if [[ "${reviewID}" != "" ]]; then - buildMessage="https://llvm.org/${reviewID}"; -else - buildMessage="Push to branch ${BUILDKITE_BRANCH}" -fi - -cat <&2 -echo "$MODIFIED_FILES" >&2 -modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u) -echo "Directories modified:" >&2 -echo "$modified_dirs" >&2 - -# Project specific pipelines. - -# If libc++ or one of the runtimes directories changed. -if echo "$modified_dirs" | grep -q -E "^(libcxx|libcxxabi|libunwind|runtimes|cmake)$"; then - cat
[llvm-branch-commits] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143481 ___ 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] [CI] Refactor out some early exits in compute_projects (PR #143478)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143478 ___ 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] [CI] Cleanup buildkite test report script (PR #143480)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143480 >From 4a2932807356182b03566460492a2dc17c023a85 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Mon, 9 Jun 2025 22:45:18 -0700 Subject: [PATCH] update Created using spr 1.3.6 --- .ci/generate-buildkite-pipeline-premerge | 131 --- 1 file changed, 131 deletions(-) delete mode 100755 .ci/generate-buildkite-pipeline-premerge diff --git a/.ci/generate-buildkite-pipeline-premerge b/.ci/generate-buildkite-pipeline-premerge deleted file mode 100755 index 5e5f916f35b72..0 --- a/.ci/generate-buildkite-pipeline-premerge +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash -#===--===## -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===--===## - -# -# This file generates a Buildkite pipeline that triggers the various CI jobs for -# the LLVM project during pre-commit CI. -# -# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format. -# -# As this outputs a yaml file, it's possible to log messages to stderr or -# prefix with "#". - - -set -eu -set -o pipefail - -# Environment variables script works with: - -# Set by buildkite -: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=} -: ${BUILDKITE_COMMIT:=} -: ${BUILDKITE_BRANCH:=} -# Fetch origin to have an up to date merge base for the diff. -git fetch origin -# List of files affected by this commit -: ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)} -# Filter rules for generic windows tests -: ${WINDOWS_AGENTS:='{"queue": "windows"}'} -# Filter rules for generic linux tests -: ${LINUX_AGENTS:='{"queue": "linux"}'} - -reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')" -if [[ "${reviewID}" != "" ]]; then - buildMessage="https://llvm.org/${reviewID}"; -else - buildMessage="Push to branch ${BUILDKITE_BRANCH}" -fi - -cat <&2 -echo "$MODIFIED_FILES" >&2 -modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u) -echo "Directories modified:" >&2 -echo "$modified_dirs" >&2 - -# Project specific pipelines. - -# If libc++ or one of the runtimes directories changed. -if echo "$modified_dirs" | grep -q -E "^(libcxx|libcxxabi|libunwind|runtimes|cmake)$"; then - cat
[llvm-branch-commits] [CI] Use Github Native Groups in monolithic-* scripts (PR #143481)
https://github.com/Endilll approved this pull request. It would be nice to give them properly formatted names (e.g. `Ninja Runtimes (Clang modules)`), because when I wrote them, the context I expected them to be seen was local editor with lengthy log file opened. Now it's going to be in UI. https://github.com/llvm/llvm-project/pull/143481 ___ 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] [AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis (PR #142778)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/142778 >From ecde1e11361f5400e820cb117d6c62100906f5b6 Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Wed, 4 Jun 2025 09:48:02 -0400 Subject: [PATCH] [AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis This is used in a bunch of memory-related transforms. For SWDEV-516125. --- .../SelectionDAGAddressAnalysis.cpp | 6 ++-- .../AMDGPU/ptradd-sdag-optimizations.ll | 28 ++- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp index f2ab88851b780..da92aaa860b2b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp @@ -231,6 +231,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, } break; case ISD::ADD: +case ISD::PTRADD: if (auto *C = dyn_cast(Base->getOperand(1))) { Offset += C->getSExtValue(); Base = DAG.getTargetLoweringInfo().unwrapAddress(Base->getOperand(0)); @@ -259,7 +260,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, break; } - if (Base->getOpcode() == ISD::ADD) { + if (Base->isAnyAdd()) { // TODO: The following code appears to be needless as it just // bails on some Ptrs early, reducing the cases where we // find equivalence. We should be able to remove this. @@ -282,8 +283,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, } // Check if Index Offset pattern -if (Index->getOpcode() != ISD::ADD || -!isa(Index->getOperand(1))) +if (!Index->isAnyAdd() || !isa(Index->getOperand(1))) return BaseIndexOffset(PotentialBase, Index, Offset, IsIndexSignExt); Offset += cast(Index->getOperand(1))->getSExtValue(); diff --git a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll index d3242905ada64..2e76033a480f4 100644 --- a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll +++ b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll @@ -130,26 +130,14 @@ define amdgpu_kernel void @llvm_amdgcn_queue_ptr(ptr addrspace(1) %ptr) #0 { ; Taken from memcpy-param-combinations.ll, tests PTRADD handling in ; SelectionDAGAddressAnalysis. define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) { -; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1: -; GFX942_PTRADD: ; %bb.0: ; %entry -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX942_PTRADD-NEXT:global_load_dwordx2 v[4:5], v[2:3], off -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[4:5], off -; GFX942_PTRADD-NEXT:global_load_dwordx2 v[2:3], v[2:3], off offset:8 -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[2:3], off offset:8 -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:s_setpc_b64 s[30:31] -; -; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1: -; GFX942_LEGACY: ; %bb.0: ; %entry -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX942_LEGACY-NEXT:global_load_dwordx4 v[2:5], v[2:3], off -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) -; GFX942_LEGACY-NEXT:global_store_dwordx4 v[0:1], v[2:5], off -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) -; GFX942_LEGACY-NEXT:s_setpc_b64 s[30:31] +; GFX942-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942: ; %bb.0: ; %entry +; GFX942-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942-NEXT:global_load_dwordx4 v[2:5], v[2:3], off +; GFX942-NEXT:s_waitcnt vmcnt(0) +; GFX942-NEXT:global_store_dwordx4 v[0:1], v[2:5], off +; GFX942-NEXT:s_waitcnt vmcnt(0) +; GFX942-NEXT:s_setpc_b64 s[30:31] entry: tail call void @llvm.memcpy.p1.p4.i64(ptr addrspace(1) noundef nonnull align 1 %dst, ptr addrspace(4) noundef nonnull align 1 %src, i64 16, i1 false) ret void ___ 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] [AMDGPU][SDAG] Add test for ISD::PTRADD handling in SelectionDAGAddressAnalysis (PR #142777)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/142777 >From 14a92fd23d064b7e057dd52c7580876ec19b6013 Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Wed, 4 Jun 2025 09:30:34 -0400 Subject: [PATCH] [AMDGPU][SDAG] Add test for ISD::PTRADD handling in SelectionDAGAddressAnalysis Pre-committing test to show improvements in a follow-up PR. --- .../AMDGPU/ptradd-sdag-optimizations.ll | 28 +++ 1 file changed, 28 insertions(+) diff --git a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll index b78dea1684545..d3242905ada64 100644 --- a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll +++ b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll @@ -126,3 +126,31 @@ define amdgpu_kernel void @llvm_amdgcn_queue_ptr(ptr addrspace(1) %ptr) #0 { store volatile i64 %dispatch.id, ptr addrspace(1) %ptr ret void } + +; Taken from memcpy-param-combinations.ll, tests PTRADD handling in +; SelectionDAGAddressAnalysis. +define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) { +; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942_PTRADD: ; %bb.0: ; %entry +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942_PTRADD-NEXT:global_load_dwordx2 v[4:5], v[2:3], off +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[4:5], off +; GFX942_PTRADD-NEXT:global_load_dwordx2 v[2:3], v[2:3], off offset:8 +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[2:3], off offset:8 +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:s_setpc_b64 s[30:31] +; +; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942_LEGACY: ; %bb.0: ; %entry +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942_LEGACY-NEXT:global_load_dwordx4 v[2:5], v[2:3], off +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) +; GFX942_LEGACY-NEXT:global_store_dwordx4 v[0:1], v[2:5], off +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) +; GFX942_LEGACY-NEXT:s_setpc_b64 s[30:31] +entry: + tail call void @llvm.memcpy.p1.p4.i64(ptr addrspace(1) noundef nonnull align 1 %dst, ptr addrspace(4) noundef nonnull align 1 %src, i64 16, i1 false) + ret void +} ___ 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] [AMDGPU][SDAG] Add test for ISD::PTRADD handling in SelectionDAGAddressAnalysis (PR #142777)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/142777 >From 14a92fd23d064b7e057dd52c7580876ec19b6013 Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Wed, 4 Jun 2025 09:30:34 -0400 Subject: [PATCH] [AMDGPU][SDAG] Add test for ISD::PTRADD handling in SelectionDAGAddressAnalysis Pre-committing test to show improvements in a follow-up PR. --- .../AMDGPU/ptradd-sdag-optimizations.ll | 28 +++ 1 file changed, 28 insertions(+) diff --git a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll index b78dea1684545..d3242905ada64 100644 --- a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll +++ b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll @@ -126,3 +126,31 @@ define amdgpu_kernel void @llvm_amdgcn_queue_ptr(ptr addrspace(1) %ptr) #0 { store volatile i64 %dispatch.id, ptr addrspace(1) %ptr ret void } + +; Taken from memcpy-param-combinations.ll, tests PTRADD handling in +; SelectionDAGAddressAnalysis. +define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) { +; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942_PTRADD: ; %bb.0: ; %entry +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942_PTRADD-NEXT:global_load_dwordx2 v[4:5], v[2:3], off +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[4:5], off +; GFX942_PTRADD-NEXT:global_load_dwordx2 v[2:3], v[2:3], off offset:8 +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[2:3], off offset:8 +; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) +; GFX942_PTRADD-NEXT:s_setpc_b64 s[30:31] +; +; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942_LEGACY: ; %bb.0: ; %entry +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942_LEGACY-NEXT:global_load_dwordx4 v[2:5], v[2:3], off +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) +; GFX942_LEGACY-NEXT:global_store_dwordx4 v[0:1], v[2:5], off +; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) +; GFX942_LEGACY-NEXT:s_setpc_b64 s[30:31] +entry: + tail call void @llvm.memcpy.p1.p4.i64(ptr addrspace(1) noundef nonnull align 1 %dst, ptr addrspace(4) noundef nonnull align 1 %src, i64 16, i1 false) + ret void +} ___ 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] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
@@ -2627,6 +2629,93 @@ SDValue DAGCombiner::foldSubToAvg(SDNode *N, const SDLoc &DL) { return SDValue(); } +/// Try to fold a pointer arithmetic node. +/// This needs to be done separately from normal addition, because pointer +/// addition is not commutative. +SDValue DAGCombiner::visitPTRADD(SDNode *N) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT PtrVT = N0.getValueType(); + EVT IntVT = N1.getValueType(); + SDLoc DL(N); + + // This is already ensured by an assert in SelectionDAG::getNode(). Several + // combines here depend on this assumption. + assert(PtrVT == IntVT && + "PTRADD with different operand types is not supported"); + + // fold (ptradd undef, y) -> undef + if (N0.isUndef()) +return N0; + + // fold (ptradd x, undef) -> undef + if (N1.isUndef()) +return DAG.getUNDEF(PtrVT); + + // fold (ptradd x, 0) -> x + if (isNullConstant(N1)) +return N0; + + // fold (ptradd 0, x) -> x + if (isNullConstant(N0)) ritter-x2a wrote: I've now added the explicit condition for this fold. https://github.com/llvm/llvm-project/pull/142739 ___ 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] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/142739 >From 30bb17d1019285e8937d1c640023c33d5e7c32cf Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Wed, 4 Jun 2025 03:32:32 -0400 Subject: [PATCH 1/5] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines This patch focuses on generic DAG combines, plus an AMDGPU-target-specific one that is closely connected. The generic DAG combine is based on a part of PR #105669 by @rgwott, which was adapted from work by @jrtc27, @arichardson, @davidchisnall in the CHERI/Morello LLVM tree. I added some parts and removed several disjuncts from the reassociation condition: - `isNullConstant(X)`, since there are address spaces where 0 is a perfectly normal value that shouldn't be treated specially, - `(YIsConstant && ZOneUse)` and `(N0OneUse && ZOneUse && !ZIsConstant)`, since they cause regressions in AMDGPU. For SWDEV-516125. --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 92 - llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 49 + llvm/lib/Target/AMDGPU/SIISelLowering.h | 1 + .../AMDGPU/ptradd-sdag-optimizations.ll | 194 ++ 4 files changed, 201 insertions(+), 135 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index aba3c0f80a024..e57e8eb8799e2 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -419,6 +419,7 @@ namespace { SDValue visitADDLike(SDNode *N); SDValue visitADDLikeCommutative(SDValue N0, SDValue N1, SDNode *LocReference); +SDValue visitPTRADD(SDNode *N); SDValue visitSUB(SDNode *N); SDValue visitADDSAT(SDNode *N); SDValue visitSUBSAT(SDNode *N); @@ -1138,7 +1139,7 @@ bool DAGCombiner::reassociationCanBreakAddressingModePattern(unsigned Opc, return true; } - if (Opc != ISD::ADD) + if (Opc != ISD::ADD && Opc != ISD::PTRADD) return false; auto *C2 = dyn_cast(N1); @@ -1858,6 +1859,7 @@ SDValue DAGCombiner::visit(SDNode *N) { case ISD::TokenFactor:return visitTokenFactor(N); case ISD::MERGE_VALUES: return visitMERGE_VALUES(N); case ISD::ADD:return visitADD(N); + case ISD::PTRADD: return visitPTRADD(N); case ISD::SUB:return visitSUB(N); case ISD::SADDSAT: case ISD::UADDSAT:return visitADDSAT(N); @@ -2627,6 +2629,93 @@ SDValue DAGCombiner::foldSubToAvg(SDNode *N, const SDLoc &DL) { return SDValue(); } +/// Try to fold a pointer arithmetic node. +/// This needs to be done separately from normal addition, because pointer +/// addition is not commutative. +SDValue DAGCombiner::visitPTRADD(SDNode *N) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT PtrVT = N0.getValueType(); + EVT IntVT = N1.getValueType(); + SDLoc DL(N); + + // This is already ensured by an assert in SelectionDAG::getNode(). Several + // combines here depend on this assumption. + assert(PtrVT == IntVT && + "PTRADD with different operand types is not supported"); + + // fold (ptradd undef, y) -> undef + if (N0.isUndef()) +return N0; + + // fold (ptradd x, undef) -> undef + if (N1.isUndef()) +return DAG.getUNDEF(PtrVT); + + // fold (ptradd x, 0) -> x + if (isNullConstant(N1)) +return N0; + + // fold (ptradd 0, x) -> x + if (isNullConstant(N0)) +return N1; + + if (N0.getOpcode() == ISD::PTRADD && + !reassociationCanBreakAddressingModePattern(ISD::PTRADD, DL, N, N0, N1)) { +SDValue X = N0.getOperand(0); +SDValue Y = N0.getOperand(1); +SDValue Z = N1; +bool N0OneUse = N0.hasOneUse(); +bool YIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Y); +bool ZIsConstant = DAG.isConstantIntBuildVectorOrConstantInt(Z); + +// (ptradd (ptradd x, y), z) -> (ptradd x, (add y, z)) if: +// * y is a constant and (ptradd x, y) has one use; or +// * y and z are both constants. +if ((YIsConstant && N0OneUse) || (YIsConstant && ZIsConstant)) { + SDNodeFlags Flags; + // If both additions in the original were NUW, the new ones are as well. + if (N->getFlags().hasNoUnsignedWrap() && + N0->getFlags().hasNoUnsignedWrap()) +Flags |= SDNodeFlags::NoUnsignedWrap; + SDValue Add = DAG.getNode(ISD::ADD, DL, IntVT, {Y, Z}, Flags); + AddToWorklist(Add.getNode()); + return DAG.getMemBasePlusOffset(X, Add, DL, Flags); +} + +// TODO: There is another possible fold here that was proven useful. +// It would be this: +// +// (ptradd (ptradd x, y), z) -> (ptradd (ptradd x, z), y) if: +// * (ptradd x, y) has one use; and +// * y is a constant; and +// * z is not a constant. +// +// In some cases, specifically in AArch64's FEAT_CPA, it exposes the +// opportunity to select more complex instructions such as SUBPT and +// MSUBPT. H
[llvm-branch-commits] [llvm] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
@@ -2627,6 +2629,93 @@ SDValue DAGCombiner::foldSubToAvg(SDNode *N, const SDLoc &DL) { return SDValue(); } +/// Try to fold a pointer arithmetic node. +/// This needs to be done separately from normal addition, because pointer +/// addition is not commutative. +SDValue DAGCombiner::visitPTRADD(SDNode *N) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT PtrVT = N0.getValueType(); + EVT IntVT = N1.getValueType(); + SDLoc DL(N); + + // This is already ensured by an assert in SelectionDAG::getNode(). Several + // combines here depend on this assumption. + assert(PtrVT == IntVT && + "PTRADD with different operand types is not supported"); + + // fold (ptradd undef, y) -> undef + if (N0.isUndef()) ritter-x2a wrote: I've added some in the `ptradd-sdag-undef-poison.ll` test. Can't have them diff nicely like the other tests because the folds are already enabled on trunk, but I did verify that additions are generated if the folds are disabled again. We obviously need to ignore the undef deprecator github action for this test (or should I limit it to poison?). https://github.com/llvm/llvm-project/pull/142739 ___ 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] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [llvm] [llvm] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.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-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.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-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [clang] [llvm] [llvm] Introduce callee_type metadata (PR #87573)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87573 >From a8a5848885e12c771f12cfa33b4dbc6a0272e925 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:04 -0700 Subject: [PATCH 01/19] Update clang/lib/CodeGen/CodeGenModule.cpp Cleaner if checks. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e19bbee996f58..ff1586d2fa8ab 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2711,7 +2711,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, void CodeGenModule::CreateFunctionTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. - if (!(CodeGenOpts.CallGraphSection && CB && CB->isIndirectCall())) + if (!CodeGenOpts.CallGraphSection || !CB || !CB->isIndirectCall()) return; auto *MD = CreateMetadataIdentifierGeneralized(QT); >From 019b2ca5e1c263183ed114e0b967b4e77b4a17a8 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:31 -0700 Subject: [PATCH 02/19] Update clang/lib/CodeGen/CodeGenModule.cpp Update the comments as suggested. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ff1586d2fa8ab..5635a87d2358a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2680,9 +2680,9 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, bool EmittedMDIdGeneralized = false; if (CodeGenOpts.CallGraphSection && (!F->hasLocalLinkage() || - F->getFunction().hasAddressTaken(nullptr, /* IgnoreCallbackUses */ true, -/* IgnoreAssumeLikeCalls */ true, -/* IgnoreLLVMUsed */ false))) { + F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/ true, +/*IgnoreAssumeLikeCalls=*/ true, +/*IgnoreLLVMUsed=*/ false))) { F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType())); EmittedMDIdGeneralized = true; } >From 99242900c51778abd4b7e7f4361b09202b7abcda Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 29 Apr 2024 11:53:40 -0700 Subject: [PATCH 03/19] dyn_cast to isa Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 526a63b24ff83..45033ced1d834 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5713,8 +5713,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) { if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) { // Type id metadata is set only for C/C++ contexts. -if (dyn_cast(FD) || dyn_cast(FD) || -dyn_cast(FD)) { +if (isa(FD) || isa(FD) || +isa(FD)) { CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke); } } >From 24882b15939b781bcf28d87fdf4f6e8834b6cfde Mon Sep 17 00:00:00 2001 From: prabhukr Date: Tue, 10 Dec 2024 14:54:27 -0800 Subject: [PATCH 04/19] Address review comments. Break llvm and clang patches. Created using spr 1.3.6-beta.1 --- llvm/lib/IR/Verifier.cpp | 7 +++ llvm/test/Verifier/operand-bundles.ll | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 0ad7ba555bfad..b72672e7b8e56 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3707,10 +3707,9 @@ void Verifier::visitCallBase(CallBase &Call) { if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) visitIntrinsicCall(ID, Call); - // Verify that a callsite has at most one "deopt", at most one "funclet", at - // most one "gc-transition", at most one "cfguardtarget", at most one "type", - // at most one "preallocated" operand bundle, and at most one "ptrauth" - // operand bundle. + // Verify that a callsite has at most one operand bundle for each of the + // following: "deopt", "funclet", "gc-transition", "cfguardtarget", "type", + // "preallocated", and "ptrauth". bool FoundDeoptBundle = false, FoundFuncletBundle = false, FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, FoundPreallocatedBundle = false, FoundGCLiveBundle = false, diff --git a/llvm/test/Verifier/operand-bundles.ll b/llvm/t
[llvm-branch-commits] [clang] [clang] Introduce CallGraphSection option (PR #117037)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117037 >From 6a12be2c5b60a95a06875b0b2c4f14228d1fa882 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 12 Mar 2025 23:30:01 + Subject: [PATCH] Fix EOF newlines. Created using spr 1.3.6-beta.1 --- clang/test/Driver/call-graph-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/call-graph-section.c b/clang/test/Driver/call-graph-section.c index 108446729d857..5832aa6754137 100644 --- a/clang/test/Driver/call-graph-section.c +++ b/clang/test/Driver/call-graph-section.c @@ -2,4 +2,4 @@ // RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s // CALL-GRAPH-SECTION: "-fcall-graph-section" -// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" \ No newline at end of file +// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
@@ -218,9 +222,12 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + ReversePostOrderTraversal RPOT(&F); svkeerthy wrote: Yeah. Also, the current MLInliner considers only reachable blocks (tests have some examples). This check ensures parity, and it makes sense to consider only reachable blocks in general. If we need the embedding of an unreachable block, it can still be obtained by directly invoking `getBBVector()`. https://github.com/llvm/llvm-project/pull/143476 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
llvmbot wrote: @llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) Changes Call continuation logic relies on assumptions about fall-through origin: - the branch is external to the function, - fall-through start is at the beginning of the block, - the block is not an entry point or a landing pad. Leverage trace information to explicitly check whether the origin is a return instruction, and defer to checks above only in case of DSO-external branch source. This covers both regular and BAT cases, addressing call continuation fall-through undercounting in the latter mode. Depends on #143289. Test Plan: updated callcont-fallthru.s --- Full diff: https://github.com/llvm/llvm-project/pull/143295.diff 5 Files Affected: - (modified) bolt/include/bolt/Profile/BoltAddressTranslation.h (+2-1) - (modified) bolt/include/bolt/Profile/DataAggregator.h (+9-3) - (modified) bolt/lib/Profile/BoltAddressTranslation.cpp (+8-2) - (modified) bolt/lib/Profile/DataAggregator.cpp (+41-30) - (modified) bolt/test/X86/callcont-fallthru.s (+40-32) ``diff diff --git a/bolt/include/bolt/Profile/BoltAddressTranslation.h b/bolt/include/bolt/Profile/BoltAddressTranslation.h index fcc578f35e322..917531964e9b6 100644 --- a/bolt/include/bolt/Profile/BoltAddressTranslation.h +++ b/bolt/include/bolt/Profile/BoltAddressTranslation.h @@ -103,7 +103,8 @@ class BoltAddressTranslation { /// otherwise. std::optional getFallthroughsInTrace(uint64_t FuncAddress, uint64_t From, - uint64_t To) const; + uint64_t To, + bool IsReturn) const; /// If available, fetch the address of the hot part linked to the cold part /// at \p Address. Return 0 otherwise. diff --git a/bolt/include/bolt/Profile/DataAggregator.h b/bolt/include/bolt/Profile/DataAggregator.h index 10d96fbeca3e2..96969cf53baca 100644 --- a/bolt/include/bolt/Profile/DataAggregator.h +++ b/bolt/include/bolt/Profile/DataAggregator.h @@ -132,6 +132,9 @@ class DataAggregator : public DataReader { /// and use them later for processing and assigning profile. std::unordered_map TraceMap; std::vector> Traces; + /// Pre-populated addresses of returns, coming from pre-aggregated data or + /// disassembly. Used to disambiguate call-continuation fall-throughs. + std::unordered_set Returns; std::unordered_map BasicSamples; std::vector MemSamples; @@ -204,8 +207,8 @@ class DataAggregator : public DataReader { /// Return a vector of offsets corresponding to a trace in a function /// if the trace is valid, std::nullopt otherwise. std::optional, 16>> - getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace, - uint64_t Count) const; + getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace, uint64_t Count, + bool IsReturn) const; /// Record external entry into the function \p BF. /// @@ -265,11 +268,14 @@ class DataAggregator : public DataReader { uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds); + /// Checks if \p Addr corresponds to a return instruction. + bool checkReturn(uint64_t Addr); + /// Register a \p Branch. bool doBranch(uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds); /// Register a trace between two LBR entries supplied in execution order. - bool doTrace(const Trace &Trace, uint64_t Count); + bool doTrace(const Trace &Trace, uint64_t Count, bool IsReturn); /// Parser helpers /// Return false if we exhausted our parser buffer and finished parsing diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp b/bolt/lib/Profile/BoltAddressTranslation.cpp index a253522e4fb15..732229b52c221 100644 --- a/bolt/lib/Profile/BoltAddressTranslation.cpp +++ b/bolt/lib/Profile/BoltAddressTranslation.cpp @@ -511,8 +511,8 @@ uint64_t BoltAddressTranslation::translate(uint64_t FuncAddress, std::optional BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress, - uint64_t From, - uint64_t To) const { + uint64_t From, uint64_t To, + bool IsReturn) const { SmallVector, 16> Res; // Filter out trivial case @@ -530,6 +530,12 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress, auto FromIter = Map.upper_bound(From); if (FromIter == Map.begin()) return Res; + + // For fall-throughs originating at returns, go back one entry to cover call + // site. + if (IsReturn) +--FromIter; + // Skip instruction entries, to create fallthroughs we are only interested in // BB boundaries do { diff --git a/bolt/lib/Profile/DataA
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
llvmbot wrote: @llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) Changes Intel's Architectural LBR supports capturing branch type information as part of LBR stack (SDM Vol 3B, part 2, October 2024): ``` 20.1.3.2 Branch Types The IA32_LBR_x_INFO.BR_TYPE and IA32_LER_INFO.BR_TYPE fields encode the branch types as shown in Table 20-3. Table 20-3. IA32_LBR_x_INFO and IA32_LER_INFO Branch Type Encodings Encoding | Branch Type B | COND 0001B | NEAR_IND_JMP 0010B | NEAR_REL_JMP 0011B | NEAR_IND_CALL 0100B | NEAR_REL_CALL 0101B | NEAR_RET 011xB | Reserved 1xxxB | OTHER_BRANCH For a list of branch operations that fall into the categories above, see Table 20-2. Table 20-2. Branch Type Filtering Details Branch Type | Operations Recorded COND | Jcc, J*CXZ, and LOOP* NEAR_IND_JMP | JMP r/m* NEAR_REL_JMP | JMP rel* NEAR_IND_CALL | CALL r/m* NEAR_REL_CALL | CALL rel* (excluding CALLs to the next sequential IP) NEAR_RET | RET (0C3H) OTHER_BRANCH | JMP/CALL ptr*, JMP/CALL m*, RET (0C8H), SYS*, interrupts, exceptions (other than debug exceptions), IRET, INT3, INTn, INTO, TSX Abort, EENTER, ERESUME, EEXIT, AEX, INIT, SIPI, RSM ``` Linux kernel can preserve branch type when `save_type` is enabled, even if the CPU does not support Architectural LBR: https://github.com/torvalds/linux/blob/f09079bd04a924c72d555cd97942d5f8d7eca98c/tools/perf/Documentation/perf-record.txt#L457-L460 > - save_type: save branch type during sampling in case binary is not available later. For the platforms with Intel Arch LBR support (12th-Gen+ client or 4th-Gen Xeon+ server), the save branch type is unconditionally enabled when the taken branch stack sampling is enabled. This information is needed to disambiguate external returns (from DSO/JIT) to an entry point or a landing pad, when BOLT can't disassemble the branch source. This patch adds new pre-aggregated trace type (R). Test Plan: updated callcont-fallthru.s --- Full diff: https://github.com/llvm/llvm-project/pull/143296.diff 4 Files Affected: - (modified) bolt/include/bolt/Profile/DataAggregator.h (+6-1) - (modified) bolt/lib/Profile/DataAggregator.cpp (+9-2) - (modified) bolt/test/X86/callcont-fallthru.s (+13) - (modified) bolt/test/link_fdata.py (+2-2) ``diff diff --git a/bolt/include/bolt/Profile/DataAggregator.h b/bolt/include/bolt/Profile/DataAggregator.h index 96969cf53baca..ae66c58e127cd 100644 --- a/bolt/include/bolt/Profile/DataAggregator.h +++ b/bolt/include/bolt/Profile/DataAggregator.h @@ -109,6 +109,7 @@ class DataAggregator : public DataReader { static constexpr const uint64_t BR_ONLY = -1ULL; static constexpr const uint64_t FT_ONLY = -1ULL; static constexpr const uint64_t FT_EXTERNAL_ORIGIN = -2ULL; +static constexpr const uint64_t BR_EXTERNAL_RETURN = -3ULL; uint64_t Branch; uint64_t From; @@ -388,7 +389,7 @@ class DataAggregator : public DataReader { /// File format syntax: /// E /// S - /// T + /// [TR] /// B /// [Ff] /// @@ -403,6 +404,7 @@ class DataAggregator : public DataReader { /// jump to the block /// T - an aggregated trace: branch from to with a fall-through /// to + /// R - an aggregated trace originating at a return /// /// - build id of the object containing the address. We can skip it for /// the main binary and use "X" for an unknown object. This will save some @@ -532,6 +534,9 @@ inline raw_ostream &operator<<(raw_ostream &OS, case DataAggregator::Trace::FT_ONLY: case DataAggregator::Trace::FT_EXTERNAL_ORIGIN: break; + case DataAggregator::Trace::BR_EXTERNAL_RETURN: +OS << "0 -> "; +break; default: OS << Twine::utohexstr(T.Branch) << " -> "; } diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 11d282e98413b..c28dd6e57f8e4 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -1194,6 +1194,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() { INVALID = 0, EVENT_NAME,// E TRACE, // T +RETURN,// R SAMPLE,// S BRANCH,// B FT,// F @@ -1224,6 +1225,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() { Type = StringSwitch(Str) .Case("T", TRACE) + .Case("R", RETURN) .Case("S", SAMPLE) .Case("E", EVENT_NAME) .Case("B", BRANCH) @@ -1237,7 +1239,7 @@ std::error_code DataAggregator::parseAggregatedLBREntry() { } using SSI = StringSwitch; -AddrNum = SSI(Str).Case("T", 3).Case("S", 1).Case("E", 0).Default(2); +AddrNum = SSI(Str).Cases("T", "R", 3).Case("S", 1).Case("E", 0).Default(2); CounterNum = SSI(Str).Case("B", 2).Case("E", 0).Default(1); } @@ -1295,8 +1297,13 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143295 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143296 ___ 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] MSP430: Stop using setCmpLibcallCC (PR #142708)
https://github.com/asl approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/142708 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -142,6 +142,10 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings svkeerthy wrote: Done https://github.com/llvm/llvm-project/pull/143479 ___ 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] [DLCov] Origin-Tracking: Collect symbolized stack traces (PR #143591)
https://github.com/SLTozer edited https://github.com/llvm/llvm-project/pull/143591 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -186,6 +186,20 @@ MLInlineAdvisor::MLInlineAdvisor( EdgeCount += getLocalCalls(KVP.first->getFunction()); } NodeCount = AllNodes.size(); + + if (auto IR2VecVocabResult = MAM.getCachedResult(M)) { +if (!IR2VecVocabResult->isValid()) { + M.getContext().emitError("IR2VecVocabAnalysis is not valid"); + return; +} +// Add the IR2Vec features to the feature map +auto IR2VecDim = IR2VecVocabResult->getDimension(); +FeatureMap.push_back( +TensorSpec::createSpec("callee_embedding", {IR2VecDim})); +FeatureMap.push_back( +TensorSpec::createSpec("caller_embedding", {IR2VecDim})); +UseIR2Vec = true; svkeerthy wrote: Okay. Done. https://github.com/llvm/llvm-project/pull/143479 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143479 >From b40003fb48e9c135dd1b1a06ba10f3cc2cd81d64 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 05:40:38 + Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner --- .../Analysis/FunctionPropertiesAnalysis.h | 26 ++- llvm/include/llvm/Analysis/InlineAdvisor.h| 3 + .../llvm/Analysis/InlineModelFeatureMaps.h| 8 +- llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 + .../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++- llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++ llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++- .../FunctionPropertiesAnalysisTest.cpp| 179 +++--- 8 files changed, 360 insertions(+), 35 deletions(-) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h index babb6d9d6cf0c..06dbfc35a5294 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h @@ -15,6 +15,7 @@ #define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/IR2Vec.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Compiler.h" @@ -32,17 +33,19 @@ class FunctionPropertiesInfo { void updateAggregateStats(const Function &F, const LoopInfo &LI); void reIncludeBB(const BasicBlock &BB); + ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0); + std::optional IR2VecVocab; + public: LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, -const LoopInfo &LI); +const LoopInfo &LI, +const IR2VecVocabResult *VocabResult); LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM); - bool operator==(const FunctionPropertiesInfo &FPI) const { -return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0; - } + bool operator==(const FunctionPropertiesInfo &FPI) const; bool operator!=(const FunctionPropertiesInfo &FPI) const { return !(*this == FPI); @@ -137,6 +140,19 @@ class FunctionPropertiesInfo { int64_t CallReturnsVectorPointerCount = 0; int64_t CallWithManyArgumentsCount = 0; int64_t CallWithPointerArgumentCount = 0; + + const ir2vec::Embedding &getFunctionEmbedding() const { +return FunctionEmbedding; + } + + const std::optional &getIR2VecVocab() const { +return IR2VecVocab; + } + + // Helper intended to be useful for unittests + void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) { +FunctionEmbedding = Embedding; + } }; // Analysis pass @@ -192,7 +208,7 @@ class FunctionPropertiesUpdater { DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const; - DenseSet Successors; + DenseSet Successors, CallUsers; // Edges we might potentially need to remove from the dominator tree. SmallVector DomTreeUpdates; diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 9d15136e81d10..d2cad4717cbdb 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public AnalysisInfoMixin { }; Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); } + +private: + static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM); }; /// Printer pass for the InlineAdvisorAnalysis results. diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h index 961d5091bf9f3..a166621243cad 100644 --- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h +++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h @@ -142,6 +142,12 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings +// Dimensions of embeddings are not known in the compile time (until vocab is +// read). Hence macros cannot be used here. + callee_embedding, + caller_embedding, + NumberOfFeatures }; // clang-format on @@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) { constexpr size_t NumberOfFeatures = static_cast(FeatureIndex::NumberOfFeatures); -LLVM_ABI extern const std::vector FeatureMap; +LLVM_ABI extern std::vector FeatureMap; LLVM_ABI extern const char *const DecisionName; LLVM_ABI extern const TensorSpec InlineDecisionSpec; diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h b/llvm/include/llvm/Analysis/MLInlineAdvisor.h index 580dd5e95d760..8262dd0846ede 100644 --- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h +++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h @@
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143200 >From c200f67b92e6b6b3c79d5dcf17a5aa2105871de7 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Fri, 6 Jun 2025 20:32:32 + Subject: [PATCH] Vocab changes1 --- llvm/include/llvm/Analysis/IR2Vec.h| 11 ++ llvm/lib/Analysis/IR2Vec.cpp | 82 +-- llvm/unittests/Analysis/IR2VecTest.cpp | 137 ++--- 3 files changed, 164 insertions(+), 66 deletions(-) diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 8bf21b0e75d67..de67955d85d7c 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -31,7 +31,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/IR/PassManager.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/JSON.h" #include namespace llvm { @@ -43,6 +45,7 @@ class Function; class Type; class Value; class raw_ostream; +class LLVMContext; /// IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware. /// Symbolic embeddings capture the "syntactic" and "statistical correlation" @@ -53,6 +56,11 @@ class raw_ostream; enum class IR2VecKind { Symbolic }; namespace ir2vec { + +extern cl::opt OpcWeight; +extern cl::opt TypeWeight; +extern cl::opt ArgWeight; + /// Embedding is a datatype that wraps std::vector. It provides /// additional functionality for arithmetic and comparison operations. /// It is meant to be used *like* std::vector but is more restrictive @@ -226,10 +234,13 @@ class IR2VecVocabResult { class IR2VecVocabAnalysis : public AnalysisInfoMixin { ir2vec::Vocab Vocabulary; Error readVocabulary(); + void emitError(Error Err, LLVMContext &Ctx); public: static AnalysisKey Key; IR2VecVocabAnalysis() = default; + explicit IR2VecVocabAnalysis(const ir2vec::Vocab &Vocab); + explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab); using Result = IR2VecVocabResult; Result run(Module &M, ModuleAnalysisManager &MAM); }; diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 25ce35d4ace37..0f7303c1b0917 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -16,13 +16,11 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" -#include "llvm/Support/JSON.h" #include "llvm/Support/MemoryBuffer.h" using namespace llvm; @@ -33,6 +31,8 @@ using namespace ir2vec; STATISTIC(VocabMissCounter, "Number of lookups to entites not present in the vocabulary"); +namespace llvm { +namespace ir2vec { static cl::OptionCategory IR2VecCategory("IR2Vec Options"); // FIXME: Use a default vocab when not specified @@ -40,18 +40,17 @@ static cl::opt VocabFile("ir2vec-vocab-path", cl::Optional, cl::desc("Path to the vocabulary file for IR2Vec"), cl::init(""), cl::cat(IR2VecCategory)); -static cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, -cl::init(1.0), -cl::desc("Weight for opcode embeddings"), -cl::cat(IR2VecCategory)); -static cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, - cl::init(0.5), - cl::desc("Weight for type embeddings"), - cl::cat(IR2VecCategory)); -static cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, -cl::init(0.2), -cl::desc("Weight for argument embeddings"), -cl::cat(IR2VecCategory)); +cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, cl::init(1.0), + cl::desc("Weight for opcode embeddings"), + cl::cat(IR2VecCategory)); +cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, cl::init(0.5), + cl::desc("Weight for type embeddings"), + cl::cat(IR2VecCategory)); +cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, cl::init(0.2), + cl::desc("Weight for argument embeddings"), + cl::cat(IR2VecCategory)); +} // namespace ir2vec +} // namespace llvm AnalysisKey IR2VecVocabAnalysis::Key; @@ -251,9 +250,9 @@ bool IR2VecVocabResult::invalidate( // by auto-generating a default vocabulary during the build time. Error IR2VecVocabAnalysis::readVocabulary() { auto BufOrError = MemoryBuffer::getFileOrSTDIN(VocabFile, /*IsText=*/true); - if (!BufOrError) { + if (!BufOrError) return createFileError(VocabFile, BufOrError.getError()); - } + auto Content = BufOrError.get()->getBuffer(); json::Path::Roo
[llvm-branch-commits] [llvm] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143476 >From 716f3d2db74a7d3f21cfaf1340e62425c16d5fe1 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 04:49:59 + Subject: [PATCH] reachable BB --- llvm/lib/Analysis/IR2Vec.cpp | 13 +--- llvm/test/Analysis/IR2Vec/dbg-inst.ll| 13 llvm/test/Analysis/IR2Vec/unreachable.ll | 42 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Analysis/IR2Vec/dbg-inst.ll create mode 100644 llvm/test/Analysis/IR2Vec/unreachable.ll diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 0f7303c1b0917..fa38c35796a0e 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -13,7 +13,9 @@ #include "llvm/Analysis/IR2Vec.h" +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" @@ -190,7 +192,8 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) const { void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { Embedding BBVector(Dimension, 0); - for (const auto &I : BB) { + // We consider only the non-debug and non-pseudo instructions + for (const auto &I : BB.instructionsWithoutDebug()) { Embedding InstVector(Dimension, 0); const auto OpcVec = lookupVocab(I.getOpcodeName()); @@ -215,9 +218,11 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + for (const BasicBlock *BB : depth_first(&F)) { +computeEmbeddings(*BB); +FuncVector += BBVecMap[BB]; } } diff --git a/llvm/test/Analysis/IR2Vec/dbg-inst.ll b/llvm/test/Analysis/IR2Vec/dbg-inst.ll new file mode 100644 index 0..0f486b0ba6a52 --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/dbg-inst.ll @@ -0,0 +1,13 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define void @bar2(ptr %foo) { + store i32 0, ptr %foo, align 4 + tail call void @llvm.dbg.value(metadata !{}, i64 0, metadata !{}, metadata !{}) + ret void +} + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone + +; CHECK: Instruction vectors: +; CHECK-NEXT: Instruction: store i32 0, ptr %foo, align 4 [ 7.00 8.00 9.00 ] +; CHECK-NEXT: Instruction: ret void [ 0.00 0.00 0.00 ] diff --git a/llvm/test/Analysis/IR2Vec/unreachable.ll b/llvm/test/Analysis/IR2Vec/unreachable.ll new file mode 100644 index 0..370fe6881d6ce --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/unreachable.ll @@ -0,0 +1,42 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define dso_local i32 @abc(i32 noundef %a, i32 noundef %b) #0 { +entry: + %retval = alloca i32, align 4 + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + store i32 %a, ptr %a.addr, align 4 + store i32 %b, ptr %b.addr, align 4 + %0 = load i32, ptr %a.addr, align 4 + %1 = load i32, ptr %b.addr, align 4 + %cmp = icmp sgt i32 %0, %1 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + %2 = load i32, ptr %b.addr, align 4 + store i32 %2, ptr %retval, align 4 + br label %return + +if.else: ; preds = %entry + %3 = load i32, ptr %a.addr, align 4 + store i32 %3, ptr %retval, align 4 + br label %return + +unreachable: ; Unreachable + store i32 0, ptr %retval, align 4 + br label %return + +return: ; preds = %if.else, %if.then + %4 = load i32, ptr %retval, align 4 + ret i32 %4 +} + +; CHECK: Basic block vectors: +; CHECK-NEXT: Basic block: entry: +; CHECK-NEXT: [ 25.00 32.00 39.00 ] +; CHECK-NEXT: Basic block: if.then: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: if.else: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: return: +; CHECK-NEXT: [ 4.00 5.00 6.00 ] ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -294,8 +294,8 @@ Error IR2VecVocabAnalysis::readVocabulary() { return Error::success(); } -IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab &&Vocabulary) -: Vocabulary(std::move(Vocabulary)) {} +IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab Vocabulary) +: Vocabulary(Vocabulary) {} svkeerthy wrote: Yes, moved it to earlier PR (#143200) https://github.com/llvm/llvm-project/pull/143479 ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143476 >From 716f3d2db74a7d3f21cfaf1340e62425c16d5fe1 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 04:49:59 + Subject: [PATCH] reachable BB --- llvm/lib/Analysis/IR2Vec.cpp | 13 +--- llvm/test/Analysis/IR2Vec/dbg-inst.ll| 13 llvm/test/Analysis/IR2Vec/unreachable.ll | 42 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Analysis/IR2Vec/dbg-inst.ll create mode 100644 llvm/test/Analysis/IR2Vec/unreachable.ll diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 0f7303c1b0917..fa38c35796a0e 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -13,7 +13,9 @@ #include "llvm/Analysis/IR2Vec.h" +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" @@ -190,7 +192,8 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) const { void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { Embedding BBVector(Dimension, 0); - for (const auto &I : BB) { + // We consider only the non-debug and non-pseudo instructions + for (const auto &I : BB.instructionsWithoutDebug()) { Embedding InstVector(Dimension, 0); const auto OpcVec = lookupVocab(I.getOpcodeName()); @@ -215,9 +218,11 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + for (const BasicBlock *BB : depth_first(&F)) { +computeEmbeddings(*BB); +FuncVector += BBVecMap[BB]; } } diff --git a/llvm/test/Analysis/IR2Vec/dbg-inst.ll b/llvm/test/Analysis/IR2Vec/dbg-inst.ll new file mode 100644 index 0..0f486b0ba6a52 --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/dbg-inst.ll @@ -0,0 +1,13 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define void @bar2(ptr %foo) { + store i32 0, ptr %foo, align 4 + tail call void @llvm.dbg.value(metadata !{}, i64 0, metadata !{}, metadata !{}) + ret void +} + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone + +; CHECK: Instruction vectors: +; CHECK-NEXT: Instruction: store i32 0, ptr %foo, align 4 [ 7.00 8.00 9.00 ] +; CHECK-NEXT: Instruction: ret void [ 0.00 0.00 0.00 ] diff --git a/llvm/test/Analysis/IR2Vec/unreachable.ll b/llvm/test/Analysis/IR2Vec/unreachable.ll new file mode 100644 index 0..370fe6881d6ce --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/unreachable.ll @@ -0,0 +1,42 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define dso_local i32 @abc(i32 noundef %a, i32 noundef %b) #0 { +entry: + %retval = alloca i32, align 4 + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + store i32 %a, ptr %a.addr, align 4 + store i32 %b, ptr %b.addr, align 4 + %0 = load i32, ptr %a.addr, align 4 + %1 = load i32, ptr %b.addr, align 4 + %cmp = icmp sgt i32 %0, %1 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + %2 = load i32, ptr %b.addr, align 4 + store i32 %2, ptr %retval, align 4 + br label %return + +if.else: ; preds = %entry + %3 = load i32, ptr %a.addr, align 4 + store i32 %3, ptr %retval, align 4 + br label %return + +unreachable: ; Unreachable + store i32 0, ptr %retval, align 4 + br label %return + +return: ; preds = %if.else, %if.then + %4 = load i32, ptr %retval, align 4 + ret i32 %4 +} + +; CHECK: Basic block vectors: +; CHECK-NEXT: Basic block: entry: +; CHECK-NEXT: [ 25.00 32.00 39.00 ] +; CHECK-NEXT: Basic block: if.then: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: if.else: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: return: +; CHECK-NEXT: [ 4.00 5.00 6.00 ] ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143479 >From b40003fb48e9c135dd1b1a06ba10f3cc2cd81d64 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 05:40:38 + Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner --- .../Analysis/FunctionPropertiesAnalysis.h | 26 ++- llvm/include/llvm/Analysis/InlineAdvisor.h| 3 + .../llvm/Analysis/InlineModelFeatureMaps.h| 8 +- llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 + .../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++- llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++ llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++- .../FunctionPropertiesAnalysisTest.cpp| 179 +++--- 8 files changed, 360 insertions(+), 35 deletions(-) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h index babb6d9d6cf0c..06dbfc35a5294 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h @@ -15,6 +15,7 @@ #define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/IR2Vec.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Compiler.h" @@ -32,17 +33,19 @@ class FunctionPropertiesInfo { void updateAggregateStats(const Function &F, const LoopInfo &LI); void reIncludeBB(const BasicBlock &BB); + ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0); + std::optional IR2VecVocab; + public: LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, -const LoopInfo &LI); +const LoopInfo &LI, +const IR2VecVocabResult *VocabResult); LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM); - bool operator==(const FunctionPropertiesInfo &FPI) const { -return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0; - } + bool operator==(const FunctionPropertiesInfo &FPI) const; bool operator!=(const FunctionPropertiesInfo &FPI) const { return !(*this == FPI); @@ -137,6 +140,19 @@ class FunctionPropertiesInfo { int64_t CallReturnsVectorPointerCount = 0; int64_t CallWithManyArgumentsCount = 0; int64_t CallWithPointerArgumentCount = 0; + + const ir2vec::Embedding &getFunctionEmbedding() const { +return FunctionEmbedding; + } + + const std::optional &getIR2VecVocab() const { +return IR2VecVocab; + } + + // Helper intended to be useful for unittests + void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) { +FunctionEmbedding = Embedding; + } }; // Analysis pass @@ -192,7 +208,7 @@ class FunctionPropertiesUpdater { DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const; - DenseSet Successors; + DenseSet Successors, CallUsers; // Edges we might potentially need to remove from the dominator tree. SmallVector DomTreeUpdates; diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 9d15136e81d10..d2cad4717cbdb 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public AnalysisInfoMixin { }; Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); } + +private: + static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM); }; /// Printer pass for the InlineAdvisorAnalysis results. diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h index 961d5091bf9f3..a166621243cad 100644 --- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h +++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h @@ -142,6 +142,12 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings +// Dimensions of embeddings are not known in the compile time (until vocab is +// read). Hence macros cannot be used here. + callee_embedding, + caller_embedding, + NumberOfFeatures }; // clang-format on @@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) { constexpr size_t NumberOfFeatures = static_cast(FeatureIndex::NumberOfFeatures); -LLVM_ABI extern const std::vector FeatureMap; +LLVM_ABI extern std::vector FeatureMap; LLVM_ABI extern const char *const DecisionName; LLVM_ABI extern const TensorSpec InlineDecisionSpec; diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h b/llvm/include/llvm/Analysis/MLInlineAdvisor.h index 580dd5e95d760..8262dd0846ede 100644 --- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h +++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h @@
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM (PR #143593)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/143593 None >From c6f681d4eb307ca5f8859b3e4e7605fc2fa8441c Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:21 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM --- llvm/include/llvm/IR/Instruction.h | 2 +- llvm/lib/CodeGen/BranchFolding.cpp | 7 +++ llvm/lib/IR/Instruction.cpp| 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index 10fc9c1298607..1d22bdb0c3f43 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -507,7 +507,7 @@ class Instruction : public User, LLVM_ABI bool extractProfTotalWeight(uint64_t &TotalVal) const; /// Set the debug location information for this instruction. - void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } + void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc).getCopied(); } /// Return the debug location for this node as a DebugLoc. const DebugLoc &getDebugLoc() const { return DbgLoc; } diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index e0f7466ceacff..47fc0ec7549e0 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -42,6 +42,7 @@ #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Function.h" @@ -933,7 +934,13 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB, // Sort by hash value so that blocks with identical end sequences sort // together. +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + // If origin-tracking is enabled then MergePotentialElt is no longer a POD + // type, so we need std::sort instead. + std::sort(MergePotentials.begin(), MergePotentials.end()); +#else array_pod_sort(MergePotentials.begin(), MergePotentials.end()); +#endif // Walk through equivalence sets looking for actual exact matches. while (MergePotentials.size() > 1) { diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 109d516c61b7c..123bc7ecce01a 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -1375,7 +1375,7 @@ void Instruction::copyMetadata(const Instruction &SrcInst, setMetadata(MD.first, MD.second); } if (WL.empty() || WLS.count(LLVMContext::MD_dbg)) -setDebugLoc(SrcInst.getDebugLoc()); +setDebugLoc(SrcInst.getDebugLoc().getCopied()); } Instruction *Instruction::clone() const { ___ 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] [DLCov] Origin-Tracking: Add debugify support (PR #143594)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/143594 None >From 4786afd40d73ade22952ca43af1164c6f9545679 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:36 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Add debugify support --- llvm/lib/Transforms/Utils/Debugify.cpp | 77 ++--- llvm/utils/llvm-original-di-preservation.py | 22 +++--- 2 files changed, 80 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index 729813a92f516..a9a66baf5571f 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -15,7 +15,10 @@ #include "llvm/Transforms/Utils/Debugify.h" #include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Config/config.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/InstIterator.h" @@ -28,6 +31,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" #include +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// We need the Signals header to operate on stacktraces if we're using DebugLoc +// origin-tracking. +#include "llvm/Support/Signals.h" +#endif #define DEBUG_TYPE "debugify" @@ -59,6 +67,49 @@ cl::opt DebugifyLevel( raw_ostream &dbg() { return Quiet ? nulls() : errs(); } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// These maps refer to addresses in this instance of LLVM, so we can reuse them +// everywhere - therefore, we store them at file scope. +static DenseMap SymbolizedAddrs; +static DenseSet UnsymbolizedAddrs; + +std::string symbolizeStackTrace(const Instruction *I) { + // We flush the set of unsymbolized addresses at the latest possible moment, + // i.e. now. + if (!UnsymbolizedAddrs.empty()) { +sys::symbolizeAddresses(UnsymbolizedAddrs, SymbolizedAddrs); +UnsymbolizedAddrs.clear(); + } + auto OriginStackTraces = I->getDebugLoc().getOriginStackTraces(); + std::string Result; + raw_string_ostream OS(Result); + for (size_t TraceIdx = 0; TraceIdx < OriginStackTraces.size(); ++TraceIdx) { +if (TraceIdx != 0) + OS << "\n"; +auto &[Depth, StackTrace] = OriginStackTraces[TraceIdx]; +for (int Frame = 0; Frame < Depth; ++Frame) { + assert(SymbolizedAddrs.contains(StackTrace[Frame]) && + "Expected each address to have been symbolized."); + OS << right_justify(formatv("#{0}", Frame).str(), std::log10(Depth) + 2) + << ' ' << SymbolizedAddrs[StackTrace[Frame]]; +} + } + return Result; +} +void collectStackAddresses(Instruction &I) { + auto &OriginStackTraces = I.getDebugLoc().getOriginStackTraces(); + for (auto &[Depth, StackTrace] : OriginStackTraces) { +for (int Frame = 0; Frame < Depth; ++Frame) { + void *Addr = StackTrace[Frame]; + if (!SymbolizedAddrs.contains(Addr)) +UnsymbolizedAddrs.insert(Addr); +} + } +} +#else +void collectStackAddresses(Instruction &I) {} +#endif // LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + uint64_t getAllocSizeInBits(Module &M, Type *Ty) { return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0; } @@ -379,6 +430,8 @@ bool llvm::collectDebugInfoMetadata(Module &M, LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n'); DebugInfoBeforePass.InstToDelete.insert({&I, &I}); +// Track the addresses to symbolize, if the feature is enabled. +collectStackAddresses(I); DebugInfoBeforePass.DILocations.insert({&I, hasLoc(I)}); } } @@ -454,14 +507,20 @@ static bool checkInstructions(const DebugInstMap &DILocsBefore, auto BBName = BB->hasName() ? BB->getName() : "no-name"; auto InstName = Instruction::getOpcodeName(Instr->getOpcode()); +auto CreateJSONBugEntry = [&](const char *Action) { + Bugs.push_back(llvm::json::Object({ +{"metadata", "DILocation"}, {"fn-name", FnName.str()}, +{"bb-name", BBName.str()}, {"instr", InstName}, {"action", Action}, +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +{"origin", symbolizeStackTrace(Instr)}, +#endif + })); +}; + auto InstrIt = DILocsBefore.find(Instr); if (InstrIt == DILocsBefore.end()) { if (ShouldWriteIntoJSON) -Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"}, - {"fn-name", FnName.str()}, - {"bb-name", BBName.str()}, - {"instr", InstName}, - {"action", "not-generate"}})); +CreateJSONBugEntry("not-generate"); else dbg() << "WARNING: " << NameOfWrappedPass << " did not generate DILocation for " << *Instr @@ -474,11 +533,7 @@ static bool checkInstructions(const DebugInstMap &D
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: SymbolizeAddresses (PR #143591)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/143591 None >From d10a102637f2dcb215039df2cb248131c6a715ce Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 19:58:09 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: SymbolizeAddresses --- llvm/include/llvm/Support/Signals.h | 40 + llvm/lib/Support/Signals.cpp | 116 +++ llvm/lib/Support/Unix/Signals.inc| 15 llvm/lib/Support/Windows/Signals.inc | 5 ++ 4 files changed, 176 insertions(+) diff --git a/llvm/include/llvm/Support/Signals.h b/llvm/include/llvm/Support/Signals.h index 6ce26acdd458e..a6f99d8bbdc95 100644 --- a/llvm/include/llvm/Support/Signals.h +++ b/llvm/include/llvm/Support/Signals.h @@ -14,7 +14,9 @@ #ifndef LLVM_SUPPORT_SIGNALS_H #define LLVM_SUPPORT_SIGNALS_H +#include "llvm/Config/llvm-config.h" #include "llvm/Support/Compiler.h" +#include #include #include @@ -22,6 +24,22 @@ namespace llvm { class StringRef; class raw_ostream; +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// Typedefs that are convenient but only used by the stack-trace-collection code +// added if DebugLoc origin-tracking is enabled. +template struct DenseMapInfo; +template class DenseSet; +namespace detail { +template struct DenseMapPair; +} +template +class DenseMap; +using AddressSet = DenseSet>; +using SymbolizedAddressMap = +DenseMap, + detail::DenseMapPair>; +#endif + namespace sys { /// This function runs all the registered interrupt handlers, including the @@ -57,6 +75,28 @@ LLVM_ABI void DisableSystemDialogsOnCrash(); ///specified, the entire frame is printed. LLVM_ABI void PrintStackTrace(raw_ostream &OS, int Depth = 0); +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#ifdef NDEBUG +#error DebugLoc origin-tracking should not be enabled in Release builds. +#endif +/// Populates the given array with a stack trace of the current program, up to +/// MaxDepth frames. Returns the number of frames returned, which will be +/// inserted into \p StackTrace from index 0. All entries after the returned +/// depth will be unmodified. NB: This is only intended to be used for +/// introspection of LLVM by Debugify, will not be enabled in release builds, +/// and should not be relied on for other purposes. +template +int getStackTrace(std::array &StackTrace); + +/// Takes a set of \p Addresses, symbolizes them and stores the result in the +/// provided \p SymbolizedAddresses map. +/// NB: This is only intended to be used for introspection of LLVM by +/// Debugify, will not be enabled in release builds, and should not be relied +/// on for other purposes. +void symbolizeAddresses(AddressSet &Addresses, +SymbolizedAddressMap &SymbolizedAddresses); +#endif + // Run all registered signal handlers. LLVM_ABI void RunSignalHandlers(); diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index 9f9030e79d104..50b0d6e78ddd1 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -253,6 +253,122 @@ static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, return true; } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +void sys::symbolizeAddresses(AddressSet &Addresses, + SymbolizedAddressMap &SymbolizedAddresses) { + assert(!DisableSymbolicationFlag && !getenv(DisableSymbolizationEnv) && + "Debugify origin stacktraces require symbolization to be enabled."); + + // Convert Set of Addresses to ordered list. + SmallVector AddressList(Addresses.begin(), Addresses.end()); + if (AddressList.empty()) +return; + int NumAddresses = AddressList.size(); + llvm::sort(AddressList); + + // Use llvm-symbolizer tool to symbolize the stack traces. First look for it + // alongside our binary, then in $PATH. + ErrorOr LLVMSymbolizerPathOrErr = std::error_code(); + if (const char *Path = getenv(LLVMSymbolizerPathEnv)) { +LLVMSymbolizerPathOrErr = sys::findProgramByName(Path); + } + if (!LLVMSymbolizerPathOrErr) +LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer"); + assert(!!LLVMSymbolizerPathOrErr && + "Debugify origin stacktraces require llvm-symbolizer."); + const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr; + + // Try to guess the main executable name, since we don't have argv0 available + // here. + std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); + + BumpPtrAllocator Allocator; + StringSaver StrPool(Allocator); + std::vector Modules(NumAddresses, nullptr); + std::vector Offsets(NumAddresses, 0); + if (!findModulesAndOffsets(AddressList.data(), NumAddresses, Modules.data(), + Offsets.data(), MainExecutableName.c_str(), + StrPool)) +return; + int InputFD; + SmallString<32> InputFile, OutputFile; + sys::fs::createTemporaryFile("symbolizer-input", "", InputFD, InputFil
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Core implementation (PR #143592)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/143592 None >From 8ff21d6e7630b0407931712eb652e0416ce661d8 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:00:51 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Core implementation --- llvm/include/llvm/IR/DebugLoc.h | 62 + llvm/lib/IR/DebugLoc.cpp| 22 +++- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h index c3d0fb80354a4..bc890dd671a81 100644 --- a/llvm/include/llvm/IR/DebugLoc.h +++ b/llvm/include/llvm/IR/DebugLoc.h @@ -27,6 +27,21 @@ namespace llvm { class Function; #if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + struct DbgLocOrigin { +static constexpr unsigned long MaxDepth = 16; +using StackTracesTy = +SmallVector>, 0>; +StackTracesTy StackTraces; +DbgLocOrigin(bool ShouldCollectTrace); +void addTrace(); +const StackTracesTy &getOriginStackTraces() const { return StackTraces; }; + }; +#else + struct DbgLocOrigin { +DbgLocOrigin(bool) {} + }; +#endif // Used to represent different "kinds" of DebugLoc, expressing that the // instruction it is part of is either normal and should contain a valid // DILocation, or otherwise describing the reason why the instruction does @@ -55,22 +70,29 @@ namespace llvm { Temporary }; - // Extends TrackingMDNodeRef to also store a DebugLocKind, allowing Debugify - // to ignore intentionally-empty DebugLocs. - class DILocAndCoverageTracking : public TrackingMDNodeRef { + // Extends TrackingMDNodeRef to also store a DebugLocKind and Origin, + // allowing Debugify to ignore intentionally-empty DebugLocs and display the + // code responsible for generating unintentionally-empty DebugLocs. + // Currently we only need to track the Origin of this DILoc when using a + // DebugLoc that is not annotated (i.e. has DebugLocKind::Normal) and has a + // null DILocation, so only collect the origin stacktrace in those cases. + class DILocAndCoverageTracking : public TrackingMDNodeRef, + public DbgLocOrigin { public: DebugLocKind Kind; // Default constructor for empty DebugLocs. DILocAndCoverageTracking() -: TrackingMDNodeRef(nullptr), Kind(DebugLocKind::Normal) {} -// Valid or nullptr MDNode*, normal DebugLocKind. +: TrackingMDNodeRef(nullptr), DbgLocOrigin(true), + Kind(DebugLocKind::Normal) {} +// Valid or nullptr MDNode*, no annotative DebugLocKind. DILocAndCoverageTracking(const MDNode *Loc) -: TrackingMDNodeRef(const_cast(Loc)), +: TrackingMDNodeRef(const_cast(Loc)), DbgLocOrigin(!Loc), Kind(DebugLocKind::Normal) {} LLVM_ABI DILocAndCoverageTracking(const DILocation *Loc); // Explicit DebugLocKind, which always means a nullptr MDNode*. DILocAndCoverageTracking(DebugLocKind Kind) -: TrackingMDNodeRef(nullptr), Kind(Kind) {} +: TrackingMDNodeRef(nullptr), + DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {} }; template <> struct simplify_type { using SimpleType = MDNode *; @@ -142,6 +164,32 @@ namespace llvm { static inline DebugLoc getDropped() { return DebugLoc(); } #endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +DebugLoc(DebugLocKind Kind) : Loc(Kind) {} +DebugLocKind getKind() const { return Loc.Kind; } +#endif + +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#if !LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#error Cannot enable DebugLoc origin-tracking without coverage-tracking! +#endif + +const DbgLocOrigin::StackTracesTy &getOriginStackTraces() const { + return Loc.getOriginStackTraces(); +} +DebugLoc getCopied() const { + DebugLoc NewDL = *this; + NewDL.Loc.addTrace(); + return NewDL; +} +#else +DebugLoc getCopied() const { return *this; } +#endif + +static DebugLoc getTemporary(); +static DebugLoc getUnknown(); +static DebugLoc getLineZero(); + /// Get the underlying \a DILocation. /// /// \pre !*this or \c isa(getAsMDNode()). diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp index 0e65ddcec8934..05aad5d393547 100644 --- a/llvm/lib/IR/DebugLoc.cpp +++ b/llvm/lib/IR/DebugLoc.cpp @@ -9,11 +9,31 @@ #include "llvm/IR/DebugLoc.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfo.h" + +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#include "llvm/Support/Signals.h" + +namespace llvm { +DbgLocOrigin::DbgLocOrigin(bool ShouldCollectTrace) { + if (ShouldCollectTrace) { +auto &[Depth, StackTrace] = StackTraces.emplace_back(); +Depth = sys::getStackTrace(StackTrace); + } +} +void DbgLocOrigin::addTrace() { + if (StackTraces.empty()) +return; + auto &[Depth, StackTrace] = StackTraces.emplace_back(); + Dept
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/143295 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/143295 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -199,6 +199,29 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock &BB, #undef CHECK_OPERAND } } + + if (IR2VecVocab) { +// We instantiate the IR2Vec embedder each time, as having an unique +// pointer to the embedder as member of the class would make it +// non-copyable. Instantiating the embedder in itself is not costly. +auto EmbOrErr = ir2vec::Embedder::create(IR2VecKind::Symbolic, svkeerthy wrote: Yes, we can do that. I'll put up a patch to remove it. https://github.com/llvm/llvm-project/pull/143479 ___ 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] MSP430: Stop using setCmpLibcallCC (PR #142708)
arsenm wrote: ping https://github.com/llvm/llvm-project/pull/142708 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143296 ___ 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-tools-extra] Release/20.x clangd modules (PR #143647)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/143647 >From eabe027feb43511d2d2709df5b88367a2cb622d5 Mon Sep 17 00:00:00 2001 From: fleeting-xx Date: Thu, 5 Jun 2025 20:33:11 -0500 Subject: [PATCH 1/2] [clangd] [Modules] Fix to correctly handle module dependencies (#142828) This is a re-application of llvm/llvm-project#142090 without the unit test changes. A subsequent PR will follow that adds a unit test for module dependencies. - Fix dangling string references in the return value of getAllRequiredModules() - Change a couple of calls in getOrBuildModuleFile() to use the loop variable instead of the ModuleName parameter. --- clang-tools-extra/clangd/ModulesBuilder.cpp | 18 ++-- clang-tools-extra/clangd/ProjectModules.h | 2 +- .../clangd/ScanningProjectModules.cpp | 6 +- .../clangd/test/module_dependencies.test | 96 +++ 4 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 clang-tools-extra/clangd/test/module_dependencies.test diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..2d2f0f6374486 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -360,9 +360,9 @@ void ModuleFileCache::remove(StringRef ModuleName) { /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName) { - llvm::SmallVector ModuleNames; + llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { @@ -373,7 +373,7 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); -ModuleNames.push_back(ModuleName); +ModuleNames.push_back(ModuleName.str()); }; VisitDeps(ModuleName, VisitDeps); @@ -418,13 +418,13 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( // Get Required modules in topological order. auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName); for (llvm::StringRef ReqModuleName : ReqModuleNames) { -if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName)) +if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName)) continue; if (auto Cached = Cache.getModule(ReqModuleName)) { if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles, TFS.view(std::nullopt))) { -log("Reusing module {0} from {1}", ModuleName, +log("Reusing module {0} from {1}", ReqModuleName, Cached->getModuleFilePath()); BuiltModuleFiles.addModuleFile(std::move(Cached)); continue; @@ -432,14 +432,16 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( Cache.remove(ReqModuleName); } +std::string ReqFileName = +MDB.getSourceForModuleName(ReqModuleName); llvm::Expected MF = buildModuleFile( -ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles); +ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles); if (llvm::Error Err = MF.takeError()) return Err; -log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath()); +log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath()); auto BuiltModuleFile = std::make_shared(std::move(*MF)); -Cache.add(ModuleName, BuiltModuleFile); +Cache.add(ReqModuleName, BuiltModuleFile); BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile)); } diff --git a/clang-tools-extra/clangd/ProjectModules.h b/clang-tools-extra/clangd/ProjectModules.h index 48d52ac9deb89..5296508e0584d 100644 --- a/clang-tools-extra/clangd/ProjectModules.h +++ b/clang-tools-extra/clangd/ProjectModules.h @@ -42,7 +42,7 @@ class ProjectModules { llvm::unique_function; virtual std::vector getRequiredModules(PathRef File) = 0; - virtual PathRef + virtual std::string getSourceForModuleName(llvm::StringRef ModuleName, PathRef RequiredSrcFile = PathRef()) = 0; diff --git a/clang-tools-extra/clangd/ScanningProjectModules.cpp b/clang-tools-extra/clangd/ScanningProjectModules.cpp index e4dc11c1c2895..859aba3673dc4 100644 --- a/clang-tools-extra/clangd/ScanningProjectModules.cpp +++ b/clang-tools-extra/clangd/ScanningProjectModules.cpp @@ -66,7 +66,7 @@ class ModuleDependencyScanner { /// /// TODO: We should handle the case that there are multiple source files /// declaring the same module. - PathRef getSourceForModuleName(llvm::StringRef ModuleName) const; + s
[llvm-branch-commits] [llvm] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
@@ -193,7 +196,8 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) const { void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { Embedding BBVector(Dimension, 0); - for (const auto &I : BB) { + // We consider only the non-debug and non-pseudo instructions + for (const auto &I : BB.instructionsWithoutDebug()) { svkeerthy wrote: Right. We just want to ensure we consider only non-debug, non-pseudo instructions. Some of the old ll files in tests still have debug instructions. https://github.com/llvm/llvm-project/pull/143476 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143295 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/143296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/143296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/143296 ___ 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] [DLCov] Origin-Tracking: SymbolizeAddresses (PR #143591)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143591 >From b2ecf5ed0da6fd3e03192ae921680b7576c12365 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 19:58:09 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: SymbolizeAddresses --- llvm/include/llvm/Support/Signals.h | 40 + llvm/lib/Support/Signals.cpp | 116 +++ llvm/lib/Support/Unix/Signals.inc| 15 llvm/lib/Support/Windows/Signals.inc | 5 ++ 4 files changed, 176 insertions(+) diff --git a/llvm/include/llvm/Support/Signals.h b/llvm/include/llvm/Support/Signals.h index 6ce26acdd458e..a6f99d8bbdc95 100644 --- a/llvm/include/llvm/Support/Signals.h +++ b/llvm/include/llvm/Support/Signals.h @@ -14,7 +14,9 @@ #ifndef LLVM_SUPPORT_SIGNALS_H #define LLVM_SUPPORT_SIGNALS_H +#include "llvm/Config/llvm-config.h" #include "llvm/Support/Compiler.h" +#include #include #include @@ -22,6 +24,22 @@ namespace llvm { class StringRef; class raw_ostream; +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// Typedefs that are convenient but only used by the stack-trace-collection code +// added if DebugLoc origin-tracking is enabled. +template struct DenseMapInfo; +template class DenseSet; +namespace detail { +template struct DenseMapPair; +} +template +class DenseMap; +using AddressSet = DenseSet>; +using SymbolizedAddressMap = +DenseMap, + detail::DenseMapPair>; +#endif + namespace sys { /// This function runs all the registered interrupt handlers, including the @@ -57,6 +75,28 @@ LLVM_ABI void DisableSystemDialogsOnCrash(); ///specified, the entire frame is printed. LLVM_ABI void PrintStackTrace(raw_ostream &OS, int Depth = 0); +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#ifdef NDEBUG +#error DebugLoc origin-tracking should not be enabled in Release builds. +#endif +/// Populates the given array with a stack trace of the current program, up to +/// MaxDepth frames. Returns the number of frames returned, which will be +/// inserted into \p StackTrace from index 0. All entries after the returned +/// depth will be unmodified. NB: This is only intended to be used for +/// introspection of LLVM by Debugify, will not be enabled in release builds, +/// and should not be relied on for other purposes. +template +int getStackTrace(std::array &StackTrace); + +/// Takes a set of \p Addresses, symbolizes them and stores the result in the +/// provided \p SymbolizedAddresses map. +/// NB: This is only intended to be used for introspection of LLVM by +/// Debugify, will not be enabled in release builds, and should not be relied +/// on for other purposes. +void symbolizeAddresses(AddressSet &Addresses, +SymbolizedAddressMap &SymbolizedAddresses); +#endif + // Run all registered signal handlers. LLVM_ABI void RunSignalHandlers(); diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index 9f9030e79d104..50b0d6e78ddd1 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -253,6 +253,122 @@ static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, return true; } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +void sys::symbolizeAddresses(AddressSet &Addresses, + SymbolizedAddressMap &SymbolizedAddresses) { + assert(!DisableSymbolicationFlag && !getenv(DisableSymbolizationEnv) && + "Debugify origin stacktraces require symbolization to be enabled."); + + // Convert Set of Addresses to ordered list. + SmallVector AddressList(Addresses.begin(), Addresses.end()); + if (AddressList.empty()) +return; + int NumAddresses = AddressList.size(); + llvm::sort(AddressList); + + // Use llvm-symbolizer tool to symbolize the stack traces. First look for it + // alongside our binary, then in $PATH. + ErrorOr LLVMSymbolizerPathOrErr = std::error_code(); + if (const char *Path = getenv(LLVMSymbolizerPathEnv)) { +LLVMSymbolizerPathOrErr = sys::findProgramByName(Path); + } + if (!LLVMSymbolizerPathOrErr) +LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer"); + assert(!!LLVMSymbolizerPathOrErr && + "Debugify origin stacktraces require llvm-symbolizer."); + const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr; + + // Try to guess the main executable name, since we don't have argv0 available + // here. + std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); + + BumpPtrAllocator Allocator; + StringSaver StrPool(Allocator); + std::vector Modules(NumAddresses, nullptr); + std::vector Offsets(NumAddresses, 0); + if (!findModulesAndOffsets(AddressList.data(), NumAddresses, Modules.data(), + Offsets.data(), MainExecutableName.c_str(), + StrPool)) +return; + int InputFD; + SmallString<32> InputFile, OutputFile; + sys::fs::createTemporaryFile("symbolizer-input", "", InputFD, InputFile); +
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: SymbolizeAddresses (PR #143591)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143591 >From b2ecf5ed0da6fd3e03192ae921680b7576c12365 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 19:58:09 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: SymbolizeAddresses --- llvm/include/llvm/Support/Signals.h | 40 + llvm/lib/Support/Signals.cpp | 116 +++ llvm/lib/Support/Unix/Signals.inc| 15 llvm/lib/Support/Windows/Signals.inc | 5 ++ 4 files changed, 176 insertions(+) diff --git a/llvm/include/llvm/Support/Signals.h b/llvm/include/llvm/Support/Signals.h index 6ce26acdd458e..a6f99d8bbdc95 100644 --- a/llvm/include/llvm/Support/Signals.h +++ b/llvm/include/llvm/Support/Signals.h @@ -14,7 +14,9 @@ #ifndef LLVM_SUPPORT_SIGNALS_H #define LLVM_SUPPORT_SIGNALS_H +#include "llvm/Config/llvm-config.h" #include "llvm/Support/Compiler.h" +#include #include #include @@ -22,6 +24,22 @@ namespace llvm { class StringRef; class raw_ostream; +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// Typedefs that are convenient but only used by the stack-trace-collection code +// added if DebugLoc origin-tracking is enabled. +template struct DenseMapInfo; +template class DenseSet; +namespace detail { +template struct DenseMapPair; +} +template +class DenseMap; +using AddressSet = DenseSet>; +using SymbolizedAddressMap = +DenseMap, + detail::DenseMapPair>; +#endif + namespace sys { /// This function runs all the registered interrupt handlers, including the @@ -57,6 +75,28 @@ LLVM_ABI void DisableSystemDialogsOnCrash(); ///specified, the entire frame is printed. LLVM_ABI void PrintStackTrace(raw_ostream &OS, int Depth = 0); +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#ifdef NDEBUG +#error DebugLoc origin-tracking should not be enabled in Release builds. +#endif +/// Populates the given array with a stack trace of the current program, up to +/// MaxDepth frames. Returns the number of frames returned, which will be +/// inserted into \p StackTrace from index 0. All entries after the returned +/// depth will be unmodified. NB: This is only intended to be used for +/// introspection of LLVM by Debugify, will not be enabled in release builds, +/// and should not be relied on for other purposes. +template +int getStackTrace(std::array &StackTrace); + +/// Takes a set of \p Addresses, symbolizes them and stores the result in the +/// provided \p SymbolizedAddresses map. +/// NB: This is only intended to be used for introspection of LLVM by +/// Debugify, will not be enabled in release builds, and should not be relied +/// on for other purposes. +void symbolizeAddresses(AddressSet &Addresses, +SymbolizedAddressMap &SymbolizedAddresses); +#endif + // Run all registered signal handlers. LLVM_ABI void RunSignalHandlers(); diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index 9f9030e79d104..50b0d6e78ddd1 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -253,6 +253,122 @@ static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, return true; } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +void sys::symbolizeAddresses(AddressSet &Addresses, + SymbolizedAddressMap &SymbolizedAddresses) { + assert(!DisableSymbolicationFlag && !getenv(DisableSymbolizationEnv) && + "Debugify origin stacktraces require symbolization to be enabled."); + + // Convert Set of Addresses to ordered list. + SmallVector AddressList(Addresses.begin(), Addresses.end()); + if (AddressList.empty()) +return; + int NumAddresses = AddressList.size(); + llvm::sort(AddressList); + + // Use llvm-symbolizer tool to symbolize the stack traces. First look for it + // alongside our binary, then in $PATH. + ErrorOr LLVMSymbolizerPathOrErr = std::error_code(); + if (const char *Path = getenv(LLVMSymbolizerPathEnv)) { +LLVMSymbolizerPathOrErr = sys::findProgramByName(Path); + } + if (!LLVMSymbolizerPathOrErr) +LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer"); + assert(!!LLVMSymbolizerPathOrErr && + "Debugify origin stacktraces require llvm-symbolizer."); + const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr; + + // Try to guess the main executable name, since we don't have argv0 available + // here. + std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); + + BumpPtrAllocator Allocator; + StringSaver StrPool(Allocator); + std::vector Modules(NumAddresses, nullptr); + std::vector Offsets(NumAddresses, 0); + if (!findModulesAndOffsets(AddressList.data(), NumAddresses, Modules.data(), + Offsets.data(), MainExecutableName.c_str(), + StrPool)) +return; + int InputFD; + SmallString<32> InputFile, OutputFile; + sys::fs::createTemporaryFile("symbolizer-input", "", InputFD, InputFile); +
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Add debugify support (PR #143594)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143594 >From c973e73b792cc1440af7c9001a0ddcfef94a9e21 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:36 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Add debugify support --- llvm/lib/Transforms/Utils/Debugify.cpp | 77 ++--- llvm/utils/llvm-original-di-preservation.py | 22 +++--- 2 files changed, 80 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index 729813a92f516..a9a66baf5571f 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -15,7 +15,10 @@ #include "llvm/Transforms/Utils/Debugify.h" #include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Config/config.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/InstIterator.h" @@ -28,6 +31,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" #include +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// We need the Signals header to operate on stacktraces if we're using DebugLoc +// origin-tracking. +#include "llvm/Support/Signals.h" +#endif #define DEBUG_TYPE "debugify" @@ -59,6 +67,49 @@ cl::opt DebugifyLevel( raw_ostream &dbg() { return Quiet ? nulls() : errs(); } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// These maps refer to addresses in this instance of LLVM, so we can reuse them +// everywhere - therefore, we store them at file scope. +static DenseMap SymbolizedAddrs; +static DenseSet UnsymbolizedAddrs; + +std::string symbolizeStackTrace(const Instruction *I) { + // We flush the set of unsymbolized addresses at the latest possible moment, + // i.e. now. + if (!UnsymbolizedAddrs.empty()) { +sys::symbolizeAddresses(UnsymbolizedAddrs, SymbolizedAddrs); +UnsymbolizedAddrs.clear(); + } + auto OriginStackTraces = I->getDebugLoc().getOriginStackTraces(); + std::string Result; + raw_string_ostream OS(Result); + for (size_t TraceIdx = 0; TraceIdx < OriginStackTraces.size(); ++TraceIdx) { +if (TraceIdx != 0) + OS << "\n"; +auto &[Depth, StackTrace] = OriginStackTraces[TraceIdx]; +for (int Frame = 0; Frame < Depth; ++Frame) { + assert(SymbolizedAddrs.contains(StackTrace[Frame]) && + "Expected each address to have been symbolized."); + OS << right_justify(formatv("#{0}", Frame).str(), std::log10(Depth) + 2) + << ' ' << SymbolizedAddrs[StackTrace[Frame]]; +} + } + return Result; +} +void collectStackAddresses(Instruction &I) { + auto &OriginStackTraces = I.getDebugLoc().getOriginStackTraces(); + for (auto &[Depth, StackTrace] : OriginStackTraces) { +for (int Frame = 0; Frame < Depth; ++Frame) { + void *Addr = StackTrace[Frame]; + if (!SymbolizedAddrs.contains(Addr)) +UnsymbolizedAddrs.insert(Addr); +} + } +} +#else +void collectStackAddresses(Instruction &I) {} +#endif // LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + uint64_t getAllocSizeInBits(Module &M, Type *Ty) { return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0; } @@ -379,6 +430,8 @@ bool llvm::collectDebugInfoMetadata(Module &M, LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n'); DebugInfoBeforePass.InstToDelete.insert({&I, &I}); +// Track the addresses to symbolize, if the feature is enabled. +collectStackAddresses(I); DebugInfoBeforePass.DILocations.insert({&I, hasLoc(I)}); } } @@ -454,14 +507,20 @@ static bool checkInstructions(const DebugInstMap &DILocsBefore, auto BBName = BB->hasName() ? BB->getName() : "no-name"; auto InstName = Instruction::getOpcodeName(Instr->getOpcode()); +auto CreateJSONBugEntry = [&](const char *Action) { + Bugs.push_back(llvm::json::Object({ +{"metadata", "DILocation"}, {"fn-name", FnName.str()}, +{"bb-name", BBName.str()}, {"instr", InstName}, {"action", Action}, +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +{"origin", symbolizeStackTrace(Instr)}, +#endif + })); +}; + auto InstrIt = DILocsBefore.find(Instr); if (InstrIt == DILocsBefore.end()) { if (ShouldWriteIntoJSON) -Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"}, - {"fn-name", FnName.str()}, - {"bb-name", BBName.str()}, - {"instr", InstName}, - {"action", "not-generate"}})); +CreateJSONBugEntry("not-generate"); else dbg() << "WARNING: " << NameOfWrappedPass << " did not generate DILocation for " << *Instr @@ -474,11 +533,7 @@ static bool checkInstructions(const DebugInstMap &DILocsB
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Add debugify support (PR #143594)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143594 >From c973e73b792cc1440af7c9001a0ddcfef94a9e21 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:36 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Add debugify support --- llvm/lib/Transforms/Utils/Debugify.cpp | 77 ++--- llvm/utils/llvm-original-di-preservation.py | 22 +++--- 2 files changed, 80 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index 729813a92f516..a9a66baf5571f 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -15,7 +15,10 @@ #include "llvm/Transforms/Utils/Debugify.h" #include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Config/config.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/InstIterator.h" @@ -28,6 +31,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/JSON.h" #include +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// We need the Signals header to operate on stacktraces if we're using DebugLoc +// origin-tracking. +#include "llvm/Support/Signals.h" +#endif #define DEBUG_TYPE "debugify" @@ -59,6 +67,49 @@ cl::opt DebugifyLevel( raw_ostream &dbg() { return Quiet ? nulls() : errs(); } +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +// These maps refer to addresses in this instance of LLVM, so we can reuse them +// everywhere - therefore, we store them at file scope. +static DenseMap SymbolizedAddrs; +static DenseSet UnsymbolizedAddrs; + +std::string symbolizeStackTrace(const Instruction *I) { + // We flush the set of unsymbolized addresses at the latest possible moment, + // i.e. now. + if (!UnsymbolizedAddrs.empty()) { +sys::symbolizeAddresses(UnsymbolizedAddrs, SymbolizedAddrs); +UnsymbolizedAddrs.clear(); + } + auto OriginStackTraces = I->getDebugLoc().getOriginStackTraces(); + std::string Result; + raw_string_ostream OS(Result); + for (size_t TraceIdx = 0; TraceIdx < OriginStackTraces.size(); ++TraceIdx) { +if (TraceIdx != 0) + OS << "\n"; +auto &[Depth, StackTrace] = OriginStackTraces[TraceIdx]; +for (int Frame = 0; Frame < Depth; ++Frame) { + assert(SymbolizedAddrs.contains(StackTrace[Frame]) && + "Expected each address to have been symbolized."); + OS << right_justify(formatv("#{0}", Frame).str(), std::log10(Depth) + 2) + << ' ' << SymbolizedAddrs[StackTrace[Frame]]; +} + } + return Result; +} +void collectStackAddresses(Instruction &I) { + auto &OriginStackTraces = I.getDebugLoc().getOriginStackTraces(); + for (auto &[Depth, StackTrace] : OriginStackTraces) { +for (int Frame = 0; Frame < Depth; ++Frame) { + void *Addr = StackTrace[Frame]; + if (!SymbolizedAddrs.contains(Addr)) +UnsymbolizedAddrs.insert(Addr); +} + } +} +#else +void collectStackAddresses(Instruction &I) {} +#endif // LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + uint64_t getAllocSizeInBits(Module &M, Type *Ty) { return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0; } @@ -379,6 +430,8 @@ bool llvm::collectDebugInfoMetadata(Module &M, LLVM_DEBUG(dbgs() << " Collecting info for inst: " << I << '\n'); DebugInfoBeforePass.InstToDelete.insert({&I, &I}); +// Track the addresses to symbolize, if the feature is enabled. +collectStackAddresses(I); DebugInfoBeforePass.DILocations.insert({&I, hasLoc(I)}); } } @@ -454,14 +507,20 @@ static bool checkInstructions(const DebugInstMap &DILocsBefore, auto BBName = BB->hasName() ? BB->getName() : "no-name"; auto InstName = Instruction::getOpcodeName(Instr->getOpcode()); +auto CreateJSONBugEntry = [&](const char *Action) { + Bugs.push_back(llvm::json::Object({ +{"metadata", "DILocation"}, {"fn-name", FnName.str()}, +{"bb-name", BBName.str()}, {"instr", InstName}, {"action", Action}, +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +{"origin", symbolizeStackTrace(Instr)}, +#endif + })); +}; + auto InstrIt = DILocsBefore.find(Instr); if (InstrIt == DILocsBefore.end()) { if (ShouldWriteIntoJSON) -Bugs.push_back(llvm::json::Object({{"metadata", "DILocation"}, - {"fn-name", FnName.str()}, - {"bb-name", BBName.str()}, - {"instr", InstName}, - {"action", "not-generate"}})); +CreateJSONBugEntry("not-generate"); else dbg() << "WARNING: " << NameOfWrappedPass << " did not generate DILocation for " << *Instr @@ -474,11 +533,7 @@ static bool checkInstructions(const DebugInstMap &DILocsB
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM (PR #143593)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143593 >From eff0813afb187a5bba4f59d63120d9dd131a3a67 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:21 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM --- llvm/include/llvm/IR/Instruction.h | 2 +- llvm/lib/CodeGen/BranchFolding.cpp | 7 +++ llvm/lib/IR/Instruction.cpp| 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index 10fc9c1298607..1d22bdb0c3f43 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -507,7 +507,7 @@ class Instruction : public User, LLVM_ABI bool extractProfTotalWeight(uint64_t &TotalVal) const; /// Set the debug location information for this instruction. - void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } + void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc).getCopied(); } /// Return the debug location for this node as a DebugLoc. const DebugLoc &getDebugLoc() const { return DbgLoc; } diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index e0f7466ceacff..47fc0ec7549e0 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -42,6 +42,7 @@ #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Function.h" @@ -933,7 +934,13 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB, // Sort by hash value so that blocks with identical end sequences sort // together. +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + // If origin-tracking is enabled then MergePotentialElt is no longer a POD + // type, so we need std::sort instead. + std::sort(MergePotentials.begin(), MergePotentials.end()); +#else array_pod_sort(MergePotentials.begin(), MergePotentials.end()); +#endif // Walk through equivalence sets looking for actual exact matches. while (MergePotentials.size() > 1) { diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 109d516c61b7c..123bc7ecce01a 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -1375,7 +1375,7 @@ void Instruction::copyMetadata(const Instruction &SrcInst, setMetadata(MD.first, MD.second); } if (WL.empty() || WLS.count(LLVMContext::MD_dbg)) -setDebugLoc(SrcInst.getDebugLoc()); +setDebugLoc(SrcInst.getDebugLoc().getCopied()); } Instruction *Instruction::clone() const { ___ 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] [DLCov] Origin-Tracking: Core implementation (PR #143592)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143592 >From 6ade803aa6c7e0137e4e572d379238a9d1fc202e Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:00:51 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Core implementation --- llvm/include/llvm/IR/DebugLoc.h | 49 - llvm/lib/IR/DebugLoc.cpp| 22 ++- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h index c3d0fb80354a4..1930199607204 100644 --- a/llvm/include/llvm/IR/DebugLoc.h +++ b/llvm/include/llvm/IR/DebugLoc.h @@ -27,6 +27,21 @@ namespace llvm { class Function; #if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + struct DbgLocOrigin { +static constexpr unsigned long MaxDepth = 16; +using StackTracesTy = +SmallVector>, 0>; +StackTracesTy StackTraces; +DbgLocOrigin(bool ShouldCollectTrace); +void addTrace(); +const StackTracesTy &getOriginStackTraces() const { return StackTraces; }; + }; +#else + struct DbgLocOrigin { +DbgLocOrigin(bool) {} + }; +#endif // Used to represent different "kinds" of DebugLoc, expressing that the // instruction it is part of is either normal and should contain a valid // DILocation, or otherwise describing the reason why the instruction does @@ -55,22 +70,29 @@ namespace llvm { Temporary }; - // Extends TrackingMDNodeRef to also store a DebugLocKind, allowing Debugify - // to ignore intentionally-empty DebugLocs. - class DILocAndCoverageTracking : public TrackingMDNodeRef { + // Extends TrackingMDNodeRef to also store a DebugLocKind and Origin, + // allowing Debugify to ignore intentionally-empty DebugLocs and display the + // code responsible for generating unintentionally-empty DebugLocs. + // Currently we only need to track the Origin of this DILoc when using a + // DebugLoc that is not annotated (i.e. has DebugLocKind::Normal) and has a + // null DILocation, so only collect the origin stacktrace in those cases. + class DILocAndCoverageTracking : public TrackingMDNodeRef, + public DbgLocOrigin { public: DebugLocKind Kind; // Default constructor for empty DebugLocs. DILocAndCoverageTracking() -: TrackingMDNodeRef(nullptr), Kind(DebugLocKind::Normal) {} -// Valid or nullptr MDNode*, normal DebugLocKind. +: TrackingMDNodeRef(nullptr), DbgLocOrigin(true), + Kind(DebugLocKind::Normal) {} +// Valid or nullptr MDNode*, no annotative DebugLocKind. DILocAndCoverageTracking(const MDNode *Loc) -: TrackingMDNodeRef(const_cast(Loc)), +: TrackingMDNodeRef(const_cast(Loc)), DbgLocOrigin(!Loc), Kind(DebugLocKind::Normal) {} LLVM_ABI DILocAndCoverageTracking(const DILocation *Loc); // Explicit DebugLocKind, which always means a nullptr MDNode*. DILocAndCoverageTracking(DebugLocKind Kind) -: TrackingMDNodeRef(nullptr), Kind(Kind) {} +: TrackingMDNodeRef(nullptr), + DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {} }; template <> struct simplify_type { using SimpleType = MDNode *; @@ -142,6 +164,19 @@ namespace llvm { static inline DebugLoc getDropped() { return DebugLoc(); } #endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +const DbgLocOrigin::StackTracesTy &getOriginStackTraces() const { + return Loc.getOriginStackTraces(); +} +DebugLoc getCopied() const { + DebugLoc NewDL = *this; + NewDL.Loc.addTrace(); + return NewDL; +} +#else +DebugLoc getCopied() const { return *this; } +#endif + /// Get the underlying \a DILocation. /// /// \pre !*this or \c isa(getAsMDNode()). diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp index 0e65ddcec8934..05aad5d393547 100644 --- a/llvm/lib/IR/DebugLoc.cpp +++ b/llvm/lib/IR/DebugLoc.cpp @@ -9,11 +9,31 @@ #include "llvm/IR/DebugLoc.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfo.h" + +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#include "llvm/Support/Signals.h" + +namespace llvm { +DbgLocOrigin::DbgLocOrigin(bool ShouldCollectTrace) { + if (ShouldCollectTrace) { +auto &[Depth, StackTrace] = StackTraces.emplace_back(); +Depth = sys::getStackTrace(StackTrace); + } +} +void DbgLocOrigin::addTrace() { + if (StackTraces.empty()) +return; + auto &[Depth, StackTrace] = StackTraces.emplace_back(); + Depth = sys::getStackTrace(StackTrace); +} +} // namespace llvm +#endif + using namespace llvm; #if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L) -: TrackingMDNodeRef(const_cast(L)), +: TrackingMDNodeRef(const_cast(L)), DbgLocOrigin(!L), Kind(DebugLocKind::Normal) {} #endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
[llvm-branch-commits] [llvm] [DLCov] Origin-Tracking: Core implementation (PR #143592)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143592 >From 6ade803aa6c7e0137e4e572d379238a9d1fc202e Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:00:51 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Core implementation --- llvm/include/llvm/IR/DebugLoc.h | 49 - llvm/lib/IR/DebugLoc.cpp| 22 ++- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h index c3d0fb80354a4..1930199607204 100644 --- a/llvm/include/llvm/IR/DebugLoc.h +++ b/llvm/include/llvm/IR/DebugLoc.h @@ -27,6 +27,21 @@ namespace llvm { class Function; #if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + struct DbgLocOrigin { +static constexpr unsigned long MaxDepth = 16; +using StackTracesTy = +SmallVector>, 0>; +StackTracesTy StackTraces; +DbgLocOrigin(bool ShouldCollectTrace); +void addTrace(); +const StackTracesTy &getOriginStackTraces() const { return StackTraces; }; + }; +#else + struct DbgLocOrigin { +DbgLocOrigin(bool) {} + }; +#endif // Used to represent different "kinds" of DebugLoc, expressing that the // instruction it is part of is either normal and should contain a valid // DILocation, or otherwise describing the reason why the instruction does @@ -55,22 +70,29 @@ namespace llvm { Temporary }; - // Extends TrackingMDNodeRef to also store a DebugLocKind, allowing Debugify - // to ignore intentionally-empty DebugLocs. - class DILocAndCoverageTracking : public TrackingMDNodeRef { + // Extends TrackingMDNodeRef to also store a DebugLocKind and Origin, + // allowing Debugify to ignore intentionally-empty DebugLocs and display the + // code responsible for generating unintentionally-empty DebugLocs. + // Currently we only need to track the Origin of this DILoc when using a + // DebugLoc that is not annotated (i.e. has DebugLocKind::Normal) and has a + // null DILocation, so only collect the origin stacktrace in those cases. + class DILocAndCoverageTracking : public TrackingMDNodeRef, + public DbgLocOrigin { public: DebugLocKind Kind; // Default constructor for empty DebugLocs. DILocAndCoverageTracking() -: TrackingMDNodeRef(nullptr), Kind(DebugLocKind::Normal) {} -// Valid or nullptr MDNode*, normal DebugLocKind. +: TrackingMDNodeRef(nullptr), DbgLocOrigin(true), + Kind(DebugLocKind::Normal) {} +// Valid or nullptr MDNode*, no annotative DebugLocKind. DILocAndCoverageTracking(const MDNode *Loc) -: TrackingMDNodeRef(const_cast(Loc)), +: TrackingMDNodeRef(const_cast(Loc)), DbgLocOrigin(!Loc), Kind(DebugLocKind::Normal) {} LLVM_ABI DILocAndCoverageTracking(const DILocation *Loc); // Explicit DebugLocKind, which always means a nullptr MDNode*. DILocAndCoverageTracking(DebugLocKind Kind) -: TrackingMDNodeRef(nullptr), Kind(Kind) {} +: TrackingMDNodeRef(nullptr), + DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {} }; template <> struct simplify_type { using SimpleType = MDNode *; @@ -142,6 +164,19 @@ namespace llvm { static inline DebugLoc getDropped() { return DebugLoc(); } #endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +const DbgLocOrigin::StackTracesTy &getOriginStackTraces() const { + return Loc.getOriginStackTraces(); +} +DebugLoc getCopied() const { + DebugLoc NewDL = *this; + NewDL.Loc.addTrace(); + return NewDL; +} +#else +DebugLoc getCopied() const { return *this; } +#endif + /// Get the underlying \a DILocation. /// /// \pre !*this or \c isa(getAsMDNode()). diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp index 0e65ddcec8934..05aad5d393547 100644 --- a/llvm/lib/IR/DebugLoc.cpp +++ b/llvm/lib/IR/DebugLoc.cpp @@ -9,11 +9,31 @@ #include "llvm/IR/DebugLoc.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfo.h" + +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING +#include "llvm/Support/Signals.h" + +namespace llvm { +DbgLocOrigin::DbgLocOrigin(bool ShouldCollectTrace) { + if (ShouldCollectTrace) { +auto &[Depth, StackTrace] = StackTraces.emplace_back(); +Depth = sys::getStackTrace(StackTrace); + } +} +void DbgLocOrigin::addTrace() { + if (StackTraces.empty()) +return; + auto &[Depth, StackTrace] = StackTraces.emplace_back(); + Depth = sys::getStackTrace(StackTrace); +} +} // namespace llvm +#endif + using namespace llvm; #if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L) -: TrackingMDNodeRef(const_cast(L)), +: TrackingMDNodeRef(const_cast(L)), DbgLocOrigin(!L), Kind(DebugLocKind::Normal) {} #endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -20,33 +21,102 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include using namespace llvm; +using namespace testing; namespace llvm { LLVM_ABI extern cl::opt EnableDetailedFunctionProperties; LLVM_ABI extern cl::opt BigBasicBlockInstructionThreshold; LLVM_ABI extern cl::opt MediumBasicBlockInstrutionThreshold; +LLVM_ABI extern cl::opt ir2vec::OpcWeight; +LLVM_ABI extern cl::opt ir2vec::TypeWeight; +LLVM_ABI extern cl::opt ir2vec::ArgWeight; } // namespace llvm namespace { class FunctionPropertiesAnalysisTest : public testing::Test { public: FunctionPropertiesAnalysisTest() { +createTestVocabulary(1); +MAM.registerPass([&] { return IR2VecVocabAnalysis(Vocabulary); }); +MAM.registerPass([&] { return PassInstrumentationAnalysis(); }); +FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); }); FAM.registerPass([&] { return DominatorTreeAnalysis(); }); FAM.registerPass([&] { return LoopAnalysis(); }); FAM.registerPass([&] { return PassInstrumentationAnalysis(); }); + +ir2vec::OpcWeight = 1.0; +ir2vec::TypeWeight = 1.0; +ir2vec::ArgWeight = 1.0; + } + +private: + float OriginalOpcWeight = ir2vec::OpcWeight; + float OriginalTypeWeight = ir2vec::TypeWeight; + float OriginalArgWeight = ir2vec::ArgWeight; + + void createTestVocabulary(unsigned Dim) { +Vocabulary["add"] = ir2vec::Embedding(Dim, 0.1); svkeerthy wrote: Currently the constructor of vocab analysis could only take in Vocabulary map and not JSON. It has to be via flags if we need to use JSON. This design of constructor would help in later patches where vocab map would be autogenerated during the build time. https://github.com/llvm/llvm-project/pull/143479 ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143476 >From 173c3b1479f50923429d02e7cd666d3d033f0d65 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 04:49:59 + Subject: [PATCH] reachable BB --- llvm/lib/Analysis/IR2Vec.cpp | 13 +--- llvm/test/Analysis/IR2Vec/dbg-inst.ll| 13 llvm/test/Analysis/IR2Vec/unreachable.ll | 42 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Analysis/IR2Vec/dbg-inst.ll create mode 100644 llvm/test/Analysis/IR2Vec/unreachable.ll diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 0f7303c1b0917..fa38c35796a0e 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -13,7 +13,9 @@ #include "llvm/Analysis/IR2Vec.h" +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" @@ -190,7 +192,8 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) const { void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { Embedding BBVector(Dimension, 0); - for (const auto &I : BB) { + // We consider only the non-debug and non-pseudo instructions + for (const auto &I : BB.instructionsWithoutDebug()) { Embedding InstVector(Dimension, 0); const auto OpcVec = lookupVocab(I.getOpcodeName()); @@ -215,9 +218,11 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + for (const BasicBlock *BB : depth_first(&F)) { +computeEmbeddings(*BB); +FuncVector += BBVecMap[BB]; } } diff --git a/llvm/test/Analysis/IR2Vec/dbg-inst.ll b/llvm/test/Analysis/IR2Vec/dbg-inst.ll new file mode 100644 index 0..0f486b0ba6a52 --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/dbg-inst.ll @@ -0,0 +1,13 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define void @bar2(ptr %foo) { + store i32 0, ptr %foo, align 4 + tail call void @llvm.dbg.value(metadata !{}, i64 0, metadata !{}, metadata !{}) + ret void +} + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone + +; CHECK: Instruction vectors: +; CHECK-NEXT: Instruction: store i32 0, ptr %foo, align 4 [ 7.00 8.00 9.00 ] +; CHECK-NEXT: Instruction: ret void [ 0.00 0.00 0.00 ] diff --git a/llvm/test/Analysis/IR2Vec/unreachable.ll b/llvm/test/Analysis/IR2Vec/unreachable.ll new file mode 100644 index 0..370fe6881d6ce --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/unreachable.ll @@ -0,0 +1,42 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define dso_local i32 @abc(i32 noundef %a, i32 noundef %b) #0 { +entry: + %retval = alloca i32, align 4 + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + store i32 %a, ptr %a.addr, align 4 + store i32 %b, ptr %b.addr, align 4 + %0 = load i32, ptr %a.addr, align 4 + %1 = load i32, ptr %b.addr, align 4 + %cmp = icmp sgt i32 %0, %1 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + %2 = load i32, ptr %b.addr, align 4 + store i32 %2, ptr %retval, align 4 + br label %return + +if.else: ; preds = %entry + %3 = load i32, ptr %a.addr, align 4 + store i32 %3, ptr %retval, align 4 + br label %return + +unreachable: ; Unreachable + store i32 0, ptr %retval, align 4 + br label %return + +return: ; preds = %if.else, %if.then + %4 = load i32, ptr %retval, align 4 + ret i32 %4 +} + +; CHECK: Basic block vectors: +; CHECK-NEXT: Basic block: entry: +; CHECK-NEXT: [ 25.00 32.00 39.00 ] +; CHECK-NEXT: Basic block: if.then: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: if.else: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: return: +; CHECK-NEXT: [ 4.00 5.00 6.00 ] ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143479 >From 5d7a2b0f4e15da7c4322954bda4bf0e9a3795a66 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 05:40:38 + Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner --- .../Analysis/FunctionPropertiesAnalysis.h | 26 ++- llvm/include/llvm/Analysis/InlineAdvisor.h| 3 + .../llvm/Analysis/InlineModelFeatureMaps.h| 8 +- llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 + .../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++- llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++ llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++- .../FunctionPropertiesAnalysisTest.cpp| 179 +++--- 8 files changed, 360 insertions(+), 35 deletions(-) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h index babb6d9d6cf0c..06dbfc35a5294 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h @@ -15,6 +15,7 @@ #define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/IR2Vec.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Compiler.h" @@ -32,17 +33,19 @@ class FunctionPropertiesInfo { void updateAggregateStats(const Function &F, const LoopInfo &LI); void reIncludeBB(const BasicBlock &BB); + ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0); + std::optional IR2VecVocab; + public: LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, -const LoopInfo &LI); +const LoopInfo &LI, +const IR2VecVocabResult *VocabResult); LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM); - bool operator==(const FunctionPropertiesInfo &FPI) const { -return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0; - } + bool operator==(const FunctionPropertiesInfo &FPI) const; bool operator!=(const FunctionPropertiesInfo &FPI) const { return !(*this == FPI); @@ -137,6 +140,19 @@ class FunctionPropertiesInfo { int64_t CallReturnsVectorPointerCount = 0; int64_t CallWithManyArgumentsCount = 0; int64_t CallWithPointerArgumentCount = 0; + + const ir2vec::Embedding &getFunctionEmbedding() const { +return FunctionEmbedding; + } + + const std::optional &getIR2VecVocab() const { +return IR2VecVocab; + } + + // Helper intended to be useful for unittests + void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) { +FunctionEmbedding = Embedding; + } }; // Analysis pass @@ -192,7 +208,7 @@ class FunctionPropertiesUpdater { DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const; - DenseSet Successors; + DenseSet Successors, CallUsers; // Edges we might potentially need to remove from the dominator tree. SmallVector DomTreeUpdates; diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 9d15136e81d10..d2cad4717cbdb 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public AnalysisInfoMixin { }; Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); } + +private: + static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM); }; /// Printer pass for the InlineAdvisorAnalysis results. diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h index 961d5091bf9f3..a166621243cad 100644 --- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h +++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h @@ -142,6 +142,12 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings +// Dimensions of embeddings are not known in the compile time (until vocab is +// read). Hence macros cannot be used here. + callee_embedding, + caller_embedding, + NumberOfFeatures }; // clang-format on @@ -154,7 +160,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) { constexpr size_t NumberOfFeatures = static_cast(FeatureIndex::NumberOfFeatures); -LLVM_ABI extern const std::vector FeatureMap; +LLVM_ABI extern std::vector FeatureMap; LLVM_ABI extern const char *const DecisionName; LLVM_ABI extern const TensorSpec InlineDecisionSpec; diff --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h b/llvm/include/llvm/Analysis/MLInlineAdvisor.h index 580dd5e95d760..8262dd0846ede 100644 --- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h +++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h @@
[llvm-branch-commits] [clang-tools-extra] Release/20.x clangd modules (PR #143647)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/143647 Backport https://github.com/llvm/llvm-project/pull/142828 manually This is helpful to avoid crashes in clangd. >From 31fab1b1c7564955f94fb64aa0603125c8366a11 Mon Sep 17 00:00:00 2001 From: fleeting-xx Date: Thu, 5 Jun 2025 20:33:11 -0500 Subject: [PATCH 1/2] [clangd] [Modules] Fix to correctly handle module dependencies (#142828) This is a re-application of llvm/llvm-project#142090 without the unit test changes. A subsequent PR will follow that adds a unit test for module dependencies. - Fix dangling string references in the return value of getAllRequiredModules() - Change a couple of calls in getOrBuildModuleFile() to use the loop variable instead of the ModuleName parameter. @ChuanqiXu9 for review --- clang-tools-extra/clangd/ModulesBuilder.cpp | 18 ++-- .../clangd/test/module_dependencies.test | 96 +++ 2 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 clang-tools-extra/clangd/test/module_dependencies.test diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..4a2a8c6623fa9 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -360,9 +360,9 @@ void ModuleFileCache::remove(StringRef ModuleName) { /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName) { - llvm::SmallVector ModuleNames; + llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { @@ -373,7 +373,7 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); -ModuleNames.push_back(ModuleName); +ModuleNames.push_back(ModuleName.str()); }; VisitDeps(ModuleName, VisitDeps); @@ -418,13 +418,13 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( // Get Required modules in topological order. auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName); for (llvm::StringRef ReqModuleName : ReqModuleNames) { -if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName)) +if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName)) continue; if (auto Cached = Cache.getModule(ReqModuleName)) { if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles, TFS.view(std::nullopt))) { -log("Reusing module {0} from {1}", ModuleName, +log("Reusing module {0} from {1}", ReqModuleName, Cached->getModuleFilePath()); BuiltModuleFiles.addModuleFile(std::move(Cached)); continue; @@ -432,14 +432,16 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( Cache.remove(ReqModuleName); } +std::string ReqFileName = +MDB.getSourceForModuleName(ReqModuleName, RequiredSource); llvm::Expected MF = buildModuleFile( -ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles); +ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles); if (llvm::Error Err = MF.takeError()) return Err; -log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath()); +log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath()); auto BuiltModuleFile = std::make_shared(std::move(*MF)); -Cache.add(ModuleName, BuiltModuleFile); +Cache.add(ReqModuleName, BuiltModuleFile); BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile)); } diff --git a/clang-tools-extra/clangd/test/module_dependencies.test b/clang-tools-extra/clangd/test/module_dependencies.test new file mode 100644 index 0..1023b2363c9fa --- /dev/null +++ b/clang-tools-extra/clangd/test/module_dependencies.test @@ -0,0 +1,96 @@ +# A smoke test to check that a simple dependency chain for modules can work. +# +# FIXME: This fails on the Windows ARM64 build server. Not entirely sure why as it has been tested on +#an ARM64 Windows VM and appears to work there. +# UNSUPPORTED: host=aarch64-pc-windows-msvc +# +# RUN: rm -fr %t +# RUN: mkdir -p %t +# RUN: split-file %s %t +# +# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp +# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json +# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp +# +# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..." +# (with the extra slash in the f
[llvm-branch-commits] [clang-tools-extra] Release/20.x clangd modules (PR #143647)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Chuanqi Xu (ChuanqiXu9) Changes Backport https://github.com/llvm/llvm-project/pull/142828 manually This is helpful to avoid crashes in clangd. --- Full diff: https://github.com/llvm/llvm-project/pull/143647.diff 2 Files Affected: - (modified) clang-tools-extra/clangd/ModulesBuilder.cpp (+10-8) - (added) clang-tools-extra/clangd/test/module_dependencies.test (+95) ``diff diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..4a2a8c6623fa9 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -360,9 +360,9 @@ void ModuleFileCache::remove(StringRef ModuleName) { /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName) { - llvm::SmallVector ModuleNames; + llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { @@ -373,7 +373,7 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); -ModuleNames.push_back(ModuleName); +ModuleNames.push_back(ModuleName.str()); }; VisitDeps(ModuleName, VisitDeps); @@ -418,13 +418,13 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( // Get Required modules in topological order. auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName); for (llvm::StringRef ReqModuleName : ReqModuleNames) { -if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName)) +if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName)) continue; if (auto Cached = Cache.getModule(ReqModuleName)) { if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles, TFS.view(std::nullopt))) { -log("Reusing module {0} from {1}", ModuleName, +log("Reusing module {0} from {1}", ReqModuleName, Cached->getModuleFilePath()); BuiltModuleFiles.addModuleFile(std::move(Cached)); continue; @@ -432,14 +432,16 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( Cache.remove(ReqModuleName); } +std::string ReqFileName = +MDB.getSourceForModuleName(ReqModuleName, RequiredSource); llvm::Expected MF = buildModuleFile( -ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles); +ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles); if (llvm::Error Err = MF.takeError()) return Err; -log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath()); +log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath()); auto BuiltModuleFile = std::make_shared(std::move(*MF)); -Cache.add(ModuleName, BuiltModuleFile); +Cache.add(ReqModuleName, BuiltModuleFile); BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile)); } diff --git a/clang-tools-extra/clangd/test/module_dependencies.test b/clang-tools-extra/clangd/test/module_dependencies.test new file mode 100644 index 0..79306a73da435 --- /dev/null +++ b/clang-tools-extra/clangd/test/module_dependencies.test @@ -0,0 +1,95 @@ +# A smoke test to check that a simple dependency chain for modules can work. +# +# FIXME: The test fails on Windows; see comments on https://github.com/llvm/llvm-project/pull/142828 +# UNSUPPORTED: system-windows +# +# RUN: rm -fr %t +# RUN: mkdir -p %t +# RUN: split-file %s %t +# +# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp +# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json +# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp +# +# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..." +# (with the extra slash in the front), so we add it here. +# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc +# +# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \ +# RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc + +#--- A-frag.cppm +export module A:frag; +export void printA() {} + +#--- A.cppm +export module A; +export import :frag; + +#--- Use.cpp +import A; +void foo() { +print +} + +#--- compile_commands.json.tmpl +[ +{ + "directory": "DIR", + "command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp", + "file": "DIR/Use.cpp" +}, +
[llvm-branch-commits] [clang-tools-extra] Release/20.x clangd modules (PR #143647)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Chuanqi Xu (ChuanqiXu9) Changes Backport https://github.com/llvm/llvm-project/pull/142828 manually This is helpful to avoid crashes in clangd. --- Full diff: https://github.com/llvm/llvm-project/pull/143647.diff 2 Files Affected: - (modified) clang-tools-extra/clangd/ModulesBuilder.cpp (+10-8) - (added) clang-tools-extra/clangd/test/module_dependencies.test (+95) ``diff diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..4a2a8c6623fa9 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -360,9 +360,9 @@ void ModuleFileCache::remove(StringRef ModuleName) { /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName) { - llvm::SmallVector ModuleNames; + llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { @@ -373,7 +373,7 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); -ModuleNames.push_back(ModuleName); +ModuleNames.push_back(ModuleName.str()); }; VisitDeps(ModuleName, VisitDeps); @@ -418,13 +418,13 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( // Get Required modules in topological order. auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName); for (llvm::StringRef ReqModuleName : ReqModuleNames) { -if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName)) +if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName)) continue; if (auto Cached = Cache.getModule(ReqModuleName)) { if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles, TFS.view(std::nullopt))) { -log("Reusing module {0} from {1}", ModuleName, +log("Reusing module {0} from {1}", ReqModuleName, Cached->getModuleFilePath()); BuiltModuleFiles.addModuleFile(std::move(Cached)); continue; @@ -432,14 +432,16 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile( Cache.remove(ReqModuleName); } +std::string ReqFileName = +MDB.getSourceForModuleName(ReqModuleName, RequiredSource); llvm::Expected MF = buildModuleFile( -ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles); +ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles); if (llvm::Error Err = MF.takeError()) return Err; -log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath()); +log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath()); auto BuiltModuleFile = std::make_shared(std::move(*MF)); -Cache.add(ModuleName, BuiltModuleFile); +Cache.add(ReqModuleName, BuiltModuleFile); BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile)); } diff --git a/clang-tools-extra/clangd/test/module_dependencies.test b/clang-tools-extra/clangd/test/module_dependencies.test new file mode 100644 index 0..79306a73da435 --- /dev/null +++ b/clang-tools-extra/clangd/test/module_dependencies.test @@ -0,0 +1,95 @@ +# A smoke test to check that a simple dependency chain for modules can work. +# +# FIXME: The test fails on Windows; see comments on https://github.com/llvm/llvm-project/pull/142828 +# UNSUPPORTED: system-windows +# +# RUN: rm -fr %t +# RUN: mkdir -p %t +# RUN: split-file %s %t +# +# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp +# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json +# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp +# +# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..." +# (with the extra slash in the front), so we add it here. +# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc +# +# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \ +# RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc + +#--- A-frag.cppm +export module A:frag; +export void printA() {} + +#--- A.cppm +export module A; +export import :frag; + +#--- Use.cpp +import A; +void foo() { +print +} + +#--- compile_commands.json.tmpl +[ +{ + "directory": "DIR", + "command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp", + "file": "DIR/Use.cpp" +}, +{ + "
[llvm-branch-commits] [clang] release/20.x: [clang-repl] Fix error recovery while PTU cleanup (#127467) (PR #142445)
anutosh491 wrote: cc @DavidSpickett , I executed a cherry pick on my patch to move it into the next release. Haven't had the time to go through the issue you discovered on Windows but is this all we want ? Or should I change something here ? https://github.com/llvm/llvm-project/pull/142445 ___ 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] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
github-actions[bot] wrote: :warning: undef deprecator found issues in your code. :warning: You can test this locally with the following command: ``bash git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD llvm/test/CodeGen/AMDGPU/ptradd-sdag-undef-poison.ll llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp llvm/lib/Target/AMDGPU/SIISelLowering.cpp llvm/lib/Target/AMDGPU/SIISelLowering.h llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll `` The following files introduce new uses of undef: - llvm/test/CodeGen/AMDGPU/ptradd-sdag-undef-poison.ll [Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields `undef`. You should use `poison` values for placeholders instead. In tests, avoid using `undef` and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead. For example, this is considered a bad practice: ```llvm define void @fn() { ... br i1 undef, ... } ``` Please use the following instead: ```llvm define void @fn(i1 %cond) { ... br i1 %cond, ... } ``` Please refer to the [Undefined Behavior Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information. https://github.com/llvm/llvm-project/pull/142739 ___ 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-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -0,0 +1,25 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, ilovepi wrote: Matching the property and the name after should be OK, though not ideal. IIRC the JSON we emit from readobj isn't sorted by key, so maybe there is a setting in the JSON builder? Or maybe it's because it uses a JSON stream? I can't quite recall, but it may be worth looking at other subprojects to see how they deal with the issue. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Explicitly check for returns when extending call continuation profile (PR #143295)
https://github.com/aaupov ready_for_review https://github.com/llvm/llvm-project/pull/143295 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT] Support pre-aggregated returns (PR #143296)
https://github.com/aaupov ready_for_review https://github.com/llvm/llvm-project/pull/143296 ___ 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] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM (PR #143593)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/143593 >From eff0813afb187a5bba4f59d63120d9dd131a3a67 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Tue, 10 Jun 2025 20:02:21 +0100 Subject: [PATCH] [DLCov] Origin-Tracking: Handle origin-tracking elsewhere in LLVM --- llvm/include/llvm/IR/Instruction.h | 2 +- llvm/lib/CodeGen/BranchFolding.cpp | 7 +++ llvm/lib/IR/Instruction.cpp| 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index 10fc9c1298607..1d22bdb0c3f43 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -507,7 +507,7 @@ class Instruction : public User, LLVM_ABI bool extractProfTotalWeight(uint64_t &TotalVal) const; /// Set the debug location information for this instruction. - void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } + void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc).getCopied(); } /// Return the debug location for this node as a DebugLoc. const DebugLoc &getDebugLoc() const { return DbgLoc; } diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index e0f7466ceacff..47fc0ec7549e0 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -42,6 +42,7 @@ #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/Config/llvm-config.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/Function.h" @@ -933,7 +934,13 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB, // Sort by hash value so that blocks with identical end sequences sort // together. +#if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING + // If origin-tracking is enabled then MergePotentialElt is no longer a POD + // type, so we need std::sort instead. + std::sort(MergePotentials.begin(), MergePotentials.end()); +#else array_pod_sort(MergePotentials.begin(), MergePotentials.end()); +#endif // Walk through equivalence sets looking for actual exact matches. while (MergePotentials.size() > 1) { diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 109d516c61b7c..123bc7ecce01a 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -1375,7 +1375,7 @@ void Instruction::copyMetadata(const Instruction &SrcInst, setMetadata(MD.first, MD.second); } if (WL.empty() || WLS.count(LLVMContext::MD_dbg)) -setDebugLoc(SrcInst.getDebugLoc()); +setDebugLoc(SrcInst.getDebugLoc().getCopied()); } Instruction *Instruction::clone() const { ___ 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] [DLCov] Origin-Tracking: Collect stack traces in DebugLoc (PR #143592)
https://github.com/SLTozer edited https://github.com/llvm/llvm-project/pull/143592 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143479 >From 579c3c03fa1117382c810c8d322f5d83689d79dc Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 05:40:38 + Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner --- .../Analysis/FunctionPropertiesAnalysis.h | 26 ++- llvm/include/llvm/Analysis/IR2Vec.h | 2 +- llvm/include/llvm/Analysis/InlineAdvisor.h| 3 + .../llvm/Analysis/InlineModelFeatureMaps.h| 6 +- llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 + .../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++- llvm/lib/Analysis/IR2Vec.cpp | 4 +- llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++ llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++- .../FunctionPropertiesAnalysisTest.cpp| 179 +++--- 10 files changed, 361 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h index babb6d9d6cf0c..06dbfc35a5294 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h @@ -15,6 +15,7 @@ #define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/IR2Vec.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Compiler.h" @@ -32,17 +33,19 @@ class FunctionPropertiesInfo { void updateAggregateStats(const Function &F, const LoopInfo &LI); void reIncludeBB(const BasicBlock &BB); + ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0); + std::optional IR2VecVocab; + public: LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, -const LoopInfo &LI); +const LoopInfo &LI, +const IR2VecVocabResult *VocabResult); LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM); - bool operator==(const FunctionPropertiesInfo &FPI) const { -return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0; - } + bool operator==(const FunctionPropertiesInfo &FPI) const; bool operator!=(const FunctionPropertiesInfo &FPI) const { return !(*this == FPI); @@ -137,6 +140,19 @@ class FunctionPropertiesInfo { int64_t CallReturnsVectorPointerCount = 0; int64_t CallWithManyArgumentsCount = 0; int64_t CallWithPointerArgumentCount = 0; + + const ir2vec::Embedding &getFunctionEmbedding() const { +return FunctionEmbedding; + } + + const std::optional &getIR2VecVocab() const { +return IR2VecVocab; + } + + // Helper intended to be useful for unittests + void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) { +FunctionEmbedding = Embedding; + } }; // Analysis pass @@ -192,7 +208,7 @@ class FunctionPropertiesUpdater { DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const; - DenseSet Successors; + DenseSet Successors, CallUsers; // Edges we might potentially need to remove from the dominator tree. SmallVector DomTreeUpdates; diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 3a6f47ded8ca4..9acffb996283c 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public AnalysisInfoMixin { public: static AnalysisKey Key; IR2VecVocabAnalysis() = default; - explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab); + explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab); using Result = IR2VecVocabResult; Result run(Module &M, ModuleAnalysisManager &MAM); }; diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 9d15136e81d10..d2cad4717cbdb 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public AnalysisInfoMixin { }; Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); } + +private: + static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM); }; /// Printer pass for the InlineAdvisorAnalysis results. diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h index 961d5091bf9f3..91d3378565fc5 100644 --- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h +++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h @@ -142,6 +142,10 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings + callee_embedding, + caller_embedding, + NumberOfFeatures }; // clang-format on @@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143479 >From 579c3c03fa1117382c810c8d322f5d83689d79dc Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 05:40:38 + Subject: [PATCH] [MLIniner][IR2Vec] Integrating IR2Vec with MLInliner --- .../Analysis/FunctionPropertiesAnalysis.h | 26 ++- llvm/include/llvm/Analysis/IR2Vec.h | 2 +- llvm/include/llvm/Analysis/InlineAdvisor.h| 3 + .../llvm/Analysis/InlineModelFeatureMaps.h| 6 +- llvm/include/llvm/Analysis/MLInlineAdvisor.h | 1 + .../Analysis/FunctionPropertiesAnalysis.cpp | 115 ++- llvm/lib/Analysis/IR2Vec.cpp | 4 +- llvm/lib/Analysis/InlineAdvisor.cpp | 29 +++ llvm/lib/Analysis/MLInlineAdvisor.cpp | 34 +++- .../FunctionPropertiesAnalysisTest.cpp| 179 +++--- 10 files changed, 361 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h index babb6d9d6cf0c..06dbfc35a5294 100644 --- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h +++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h @@ -15,6 +15,7 @@ #define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/IR2Vec.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Compiler.h" @@ -32,17 +33,19 @@ class FunctionPropertiesInfo { void updateAggregateStats(const Function &F, const LoopInfo &LI); void reIncludeBB(const BasicBlock &BB); + ir2vec::Embedding FunctionEmbedding = ir2vec::Embedding(0.0); + std::optional IR2VecVocab; + public: LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, -const LoopInfo &LI); +const LoopInfo &LI, +const IR2VecVocabResult *VocabResult); LLVM_ABI static FunctionPropertiesInfo getFunctionPropertiesInfo(Function &F, FunctionAnalysisManager &FAM); - bool operator==(const FunctionPropertiesInfo &FPI) const { -return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0; - } + bool operator==(const FunctionPropertiesInfo &FPI) const; bool operator!=(const FunctionPropertiesInfo &FPI) const { return !(*this == FPI); @@ -137,6 +140,19 @@ class FunctionPropertiesInfo { int64_t CallReturnsVectorPointerCount = 0; int64_t CallWithManyArgumentsCount = 0; int64_t CallWithPointerArgumentCount = 0; + + const ir2vec::Embedding &getFunctionEmbedding() const { +return FunctionEmbedding; + } + + const std::optional &getIR2VecVocab() const { +return IR2VecVocab; + } + + // Helper intended to be useful for unittests + void setFunctionEmbeddingForTest(const ir2vec::Embedding &Embedding) { +FunctionEmbedding = Embedding; + } }; // Analysis pass @@ -192,7 +208,7 @@ class FunctionPropertiesUpdater { DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const; - DenseSet Successors; + DenseSet Successors, CallUsers; // Edges we might potentially need to remove from the dominator tree. SmallVector DomTreeUpdates; diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 3a6f47ded8ca4..9acffb996283c 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -239,7 +239,7 @@ class IR2VecVocabAnalysis : public AnalysisInfoMixin { public: static AnalysisKey Key; IR2VecVocabAnalysis() = default; - explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab); + explicit IR2VecVocabAnalysis(ir2vec::Vocab Vocab); using Result = IR2VecVocabResult; Result run(Module &M, ModuleAnalysisManager &MAM); }; diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 9d15136e81d10..d2cad4717cbdb 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -331,6 +331,9 @@ class InlineAdvisorAnalysis : public AnalysisInfoMixin { }; Result run(Module &M, ModuleAnalysisManager &MAM) { return Result(M, MAM); } + +private: + static bool initializeIR2VecVocab(Module &M, ModuleAnalysisManager &MAM); }; /// Printer pass for the InlineAdvisorAnalysis results. diff --git a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h index 961d5091bf9f3..91d3378565fc5 100644 --- a/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h +++ b/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h @@ -142,6 +142,10 @@ enum class FeatureIndex : size_t { INLINE_FEATURE_ITERATOR(POPULATE_INDICES) #undef POPULATE_INDICES +// IR2Vec embeddings + callee_embedding, + caller_embedding, + NumberOfFeatures }; // clang-format on @@ -154,7 +158,7 @@ inlineCostFeatureToMlFeature(InlineCostFeatu
[llvm-branch-commits] [llvm] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/svkeerthy updated https://github.com/llvm/llvm-project/pull/143476 >From cd2cdf560d4ffd9171a1104cbc12586bd06f5542 Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Tue, 10 Jun 2025 04:49:59 + Subject: [PATCH] reachable BB --- llvm/lib/Analysis/IR2Vec.cpp | 13 +--- llvm/test/Analysis/IR2Vec/dbg-inst.ll| 13 llvm/test/Analysis/IR2Vec/unreachable.ll | 42 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Analysis/IR2Vec/dbg-inst.ll create mode 100644 llvm/test/Analysis/IR2Vec/unreachable.ll diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 1d17acad56463..4a5218e040b49 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -13,7 +13,9 @@ #include "llvm/Analysis/IR2Vec.h" +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" @@ -190,7 +192,8 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) const { void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { Embedding BBVector(Dimension, 0); - for (const auto &I : BB) { + // We consider only the non-debug and non-pseudo instructions + for (const auto &I : BB.instructionsWithoutDebug()) { Embedding InstVector(Dimension, 0); const auto OpcVec = lookupVocab(I.getOpcodeName()); @@ -215,9 +218,11 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + for (const BasicBlock *BB : depth_first(&F)) { +computeEmbeddings(*BB); +FuncVector += BBVecMap[BB]; } } diff --git a/llvm/test/Analysis/IR2Vec/dbg-inst.ll b/llvm/test/Analysis/IR2Vec/dbg-inst.ll new file mode 100644 index 0..0f486b0ba6a52 --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/dbg-inst.ll @@ -0,0 +1,13 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define void @bar2(ptr %foo) { + store i32 0, ptr %foo, align 4 + tail call void @llvm.dbg.value(metadata !{}, i64 0, metadata !{}, metadata !{}) + ret void +} + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone + +; CHECK: Instruction vectors: +; CHECK-NEXT: Instruction: store i32 0, ptr %foo, align 4 [ 7.00 8.00 9.00 ] +; CHECK-NEXT: Instruction: ret void [ 0.00 0.00 0.00 ] diff --git a/llvm/test/Analysis/IR2Vec/unreachable.ll b/llvm/test/Analysis/IR2Vec/unreachable.ll new file mode 100644 index 0..370fe6881d6ce --- /dev/null +++ b/llvm/test/Analysis/IR2Vec/unreachable.ll @@ -0,0 +1,42 @@ +; RUN: opt -passes='print' -o /dev/null -ir2vec-vocab-path=%S/Inputs/dummy_3D_vocab.json %s 2>&1 | FileCheck %s + +define dso_local i32 @abc(i32 noundef %a, i32 noundef %b) #0 { +entry: + %retval = alloca i32, align 4 + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + store i32 %a, ptr %a.addr, align 4 + store i32 %b, ptr %b.addr, align 4 + %0 = load i32, ptr %a.addr, align 4 + %1 = load i32, ptr %b.addr, align 4 + %cmp = icmp sgt i32 %0, %1 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + %2 = load i32, ptr %b.addr, align 4 + store i32 %2, ptr %retval, align 4 + br label %return + +if.else: ; preds = %entry + %3 = load i32, ptr %a.addr, align 4 + store i32 %3, ptr %retval, align 4 + br label %return + +unreachable: ; Unreachable + store i32 0, ptr %retval, align 4 + br label %return + +return: ; preds = %if.else, %if.then + %4 = load i32, ptr %retval, align 4 + ret i32 %4 +} + +; CHECK: Basic block vectors: +; CHECK-NEXT: Basic block: entry: +; CHECK-NEXT: [ 25.00 32.00 39.00 ] +; CHECK-NEXT: Basic block: if.then: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: if.else: +; CHECK-NEXT: [ 11.00 13.00 15.00 ] +; CHECK-NEXT: Basic block: return: +; CHECK-NEXT: [ 4.00 5.00 6.00 ] ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
@@ -218,9 +222,12 @@ void SymbolicEmbedder::computeEmbeddings(const BasicBlock &BB) const { void SymbolicEmbedder::computeEmbeddings() const { if (F.isDeclaration()) return; - for (const auto &BB : F) { -computeEmbeddings(BB); -FuncVector += BBVecMap[&BB]; + + // Consider only the basic blocks that are reachable from entry + ReversePostOrderTraversal RPOT(&F); svkeerthy wrote: Thanks. Seems like constructing RPO is costly. Changed it to DF Traversal. https://github.com/llvm/llvm-project/pull/143476 ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/mtrofin approved this pull request. https://github.com/llvm/llvm-project/pull/143476 ___ 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] [IR2Vec] Consider only reachable BBs and non-debug instructions (PR #143476)
https://github.com/mtrofin edited https://github.com/llvm/llvm-project/pull/143476 ___ 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] [GISelValueTracking] Add test case for G_PTRTOINT (PR #139608)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/139608 ___ 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] [CI] Refactor out some early exits in compute_projects (PR #143478)
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/143478 ___ 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-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -0,0 +1,108 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +class MyClass {}; + +void myFunction(int Param); + +namespace NestedNamespace { +} // namespace NestedNamespace + +// FIXME: Global variables are not mapped or serialized. +static int Global; + +enum Color { + RED, + GREEN, + BLUE = 5 +}; + +typedef int MyTypedef; + +// CHECK: { +// CHECK-NEXT:"Enums": [ +// CHECK-NEXT: { +// CHECK-NEXT:"Location": { +// CHECK-NEXT: "Filename": "{{.*}}namespace.cpp", +// CHECK-NEXT: "LineNumber": 15 +// CHECK-NEXT:}, +// CHECK-NEXT:"Members": [ +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "RED", +// CHECK-NEXT:"Value": "0" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "GREEN", +// CHECK-NEXT:"Value": "1" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "BLUE", +// CHECK-NEXT:"ValueExpr": "5" +// CHECK-NEXT: } +// CHECK-NEXT:], +// CHECK-NEXT:"Name": "Color", +// CHECK-NEXT:"Scoped": false, +// CHECK-NEXT:"USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: } +// CHECK-NEXT:], +// CHECK-NEXT: "Functions": [ +// CHECK-NEXT: { +// CHECK-NEXT: "IsStatic": false, +// CHECK-NEXT: "Name": "myFunction", +// CHECK-NEXT: "Params": [ +// CHECK-NEXT: { +// CHECK-NEXT: "Name": "Param", +// CHECK-NEXT: "Type": "int" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "ReturnType": { +// CHECK-NEXT: "IsBuiltIn": false, +// CHECK-NEXT: "IsTemplate": false, +// CHECK-NEXT: "Name": "void", +// CHECK-NEXT: "QualName": "void", +// CHECK-NEXT: "USR": "" ilovepi wrote: Hmm, we're probably updating the wrong data structure/copy. Booleans should serialize fine. It could also be that we're doing something silly in a copy constructor or using a bad initializer list. https://github.com/llvm/llvm-project/pull/143209 ___ 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] [AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis (PR #142778)
https://github.com/ritter-x2a updated https://github.com/llvm/llvm-project/pull/142778 >From ecde1e11361f5400e820cb117d6c62100906f5b6 Mon Sep 17 00:00:00 2001 From: Fabian Ritter Date: Wed, 4 Jun 2025 09:48:02 -0400 Subject: [PATCH] [AMDGPU][SDAG] Handle ISD::PTRADD in SelectionDAGAddressAnalysis This is used in a bunch of memory-related transforms. For SWDEV-516125. --- .../SelectionDAGAddressAnalysis.cpp | 6 ++-- .../AMDGPU/ptradd-sdag-optimizations.ll | 28 ++- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp index f2ab88851b780..da92aaa860b2b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp @@ -231,6 +231,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, } break; case ISD::ADD: +case ISD::PTRADD: if (auto *C = dyn_cast(Base->getOperand(1))) { Offset += C->getSExtValue(); Base = DAG.getTargetLoweringInfo().unwrapAddress(Base->getOperand(0)); @@ -259,7 +260,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, break; } - if (Base->getOpcode() == ISD::ADD) { + if (Base->isAnyAdd()) { // TODO: The following code appears to be needless as it just // bails on some Ptrs early, reducing the cases where we // find equivalence. We should be able to remove this. @@ -282,8 +283,7 @@ static BaseIndexOffset matchLSNode(const LSBaseSDNode *N, } // Check if Index Offset pattern -if (Index->getOpcode() != ISD::ADD || -!isa(Index->getOperand(1))) +if (!Index->isAnyAdd() || !isa(Index->getOperand(1))) return BaseIndexOffset(PotentialBase, Index, Offset, IsIndexSignExt); Offset += cast(Index->getOperand(1))->getSExtValue(); diff --git a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll index d3242905ada64..2e76033a480f4 100644 --- a/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll +++ b/llvm/test/CodeGen/AMDGPU/ptradd-sdag-optimizations.ll @@ -130,26 +130,14 @@ define amdgpu_kernel void @llvm_amdgcn_queue_ptr(ptr addrspace(1) %ptr) #0 { ; Taken from memcpy-param-combinations.ll, tests PTRADD handling in ; SelectionDAGAddressAnalysis. define void @memcpy_p1_p4_sz16_align_1_1(ptr addrspace(1) align 1 %dst, ptr addrspace(4) align 1 readonly %src) { -; GFX942_PTRADD-LABEL: memcpy_p1_p4_sz16_align_1_1: -; GFX942_PTRADD: ; %bb.0: ; %entry -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX942_PTRADD-NEXT:global_load_dwordx2 v[4:5], v[2:3], off -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[4:5], off -; GFX942_PTRADD-NEXT:global_load_dwordx2 v[2:3], v[2:3], off offset:8 -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:global_store_dwordx2 v[0:1], v[2:3], off offset:8 -; GFX942_PTRADD-NEXT:s_waitcnt vmcnt(0) -; GFX942_PTRADD-NEXT:s_setpc_b64 s[30:31] -; -; GFX942_LEGACY-LABEL: memcpy_p1_p4_sz16_align_1_1: -; GFX942_LEGACY: ; %bb.0: ; %entry -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX942_LEGACY-NEXT:global_load_dwordx4 v[2:5], v[2:3], off -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) -; GFX942_LEGACY-NEXT:global_store_dwordx4 v[0:1], v[2:5], off -; GFX942_LEGACY-NEXT:s_waitcnt vmcnt(0) -; GFX942_LEGACY-NEXT:s_setpc_b64 s[30:31] +; GFX942-LABEL: memcpy_p1_p4_sz16_align_1_1: +; GFX942: ; %bb.0: ; %entry +; GFX942-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GFX942-NEXT:global_load_dwordx4 v[2:5], v[2:3], off +; GFX942-NEXT:s_waitcnt vmcnt(0) +; GFX942-NEXT:global_store_dwordx4 v[0:1], v[2:5], off +; GFX942-NEXT:s_waitcnt vmcnt(0) +; GFX942-NEXT:s_setpc_b64 s[30:31] entry: tail call void @llvm.memcpy.p1.p4.i64(ptr addrspace(1) noundef nonnull align 1 %dst, ptr addrspace(4) noundef nonnull align 1 %src, i64 16, i1 false) ret void ___ 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] [SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (part 2) (PR #143103)
@@ -1881,6 +1881,11 @@ LLVM_ABI SDValue peekThroughExtractSubvectors(SDValue V); /// If \p V is not a truncation, it is returned as-is. LLVM_ABI SDValue peekThroughTruncates(SDValue V); +/// Recursively peek through INSERT_VECTOR_ELT nodes, returning the source +/// vector operand of \p V, as long as \p V is an does INSERT_VECTOR_ELT RKSimon wrote: `is an INSERT_VECTOR_ELT` https://github.com/llvm/llvm-project/pull/143103 ___ 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] [SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (part 2) (PR #143103)
@@ -1881,6 +1881,11 @@ LLVM_ABI SDValue peekThroughExtractSubvectors(SDValue V); /// If \p V is not a truncation, it is returned as-is. LLVM_ABI SDValue peekThroughTruncates(SDValue V); +/// Recursively peek through INSERT_VECTOR_ELT nodes, returning the source +/// vector operand of \p V, as long as \p V is an does INSERT_VECTOR_ELT +/// operation that do not insert into any of the demanded vector elts. +LLVM_ABI SDValue peekThroughInsertVectorElt(SDValue V, APInt DemandedElts); RKSimon wrote: `const APInt &DemandedElts` (in case vector count > 64) https://github.com/llvm/llvm-project/pull/143103 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -186,6 +186,20 @@ MLInlineAdvisor::MLInlineAdvisor( EdgeCount += getLocalCalls(KVP.first->getFunction()); } NodeCount = AllNodes.size(); + + if (auto IR2VecVocabResult = MAM.getCachedResult(M)) { +if (!IR2VecVocabResult->isValid()) { + M.getContext().emitError("IR2VecVocabAnalysis is not valid"); + return; +} +// Add the IR2Vec features to the feature map +auto IR2VecDim = IR2VecVocabResult->getDimension(); +FeatureMap.push_back( +TensorSpec::createSpec("callee_embedding", {IR2VecDim})); +FeatureMap.push_back( +TensorSpec::createSpec("caller_embedding", {IR2VecDim})); +UseIR2Vec = true; mtrofin wrote: nit: if it makes sense, you could have `const UseIR2Vec` and init it in the ctor based on `MAM.getCachedResult`. Then here, if the result isn't valid, splat the error. main value is readability - the bool flag would say it's set once. https://github.com/llvm/llvm-project/pull/143479 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -199,6 +199,29 @@ void FunctionPropertiesInfo::updateForBB(const BasicBlock &BB, #undef CHECK_OPERAND } } + + if (IR2VecVocab) { +// We instantiate the IR2Vec embedder each time, as having an unique +// pointer to the embedder as member of the class would make it +// non-copyable. Instantiating the embedder in itself is not costly. +auto EmbOrErr = ir2vec::Embedder::create(IR2VecKind::Symbolic, mtrofin wrote: separate patch, but we can do away with `create` returning Error, right? https://github.com/llvm/llvm-project/pull/143479 ___ 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] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
@@ -53,7 +56,12 @@ class raw_ostream; enum class IR2VecKind { Symbolic }; namespace ir2vec { -/// Embedding is a datavtype that wraps std::vector. It provides + +LLVM_ABI extern cl::opt OpcWeight; svkeerthy wrote: #136623 adds LLVM_ABI tags to some globals and externs in Analysis. Removing it for now. Can be added later if necessary. https://github.com/llvm/llvm-project/pull/143200 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
@@ -294,8 +294,8 @@ Error IR2VecVocabAnalysis::readVocabulary() { return Error::success(); } -IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab &&Vocabulary) -: Vocabulary(std::move(Vocabulary)) {} +IR2VecVocabAnalysis::IR2VecVocabAnalysis(Vocab Vocabulary) +: Vocabulary(Vocabulary) {} mtrofin wrote: why? can this change be made in a precursor PR? https://github.com/llvm/llvm-project/pull/143479 ___ 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] [MLGO][IR2Vec] Integrating IR2Vec with MLInliner (PR #143479)
https://github.com/mtrofin edited https://github.com/llvm/llvm-project/pull/143479 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits