[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#79283 (PR #80068)

2024-02-07 Thread Fangrui Song via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/80068
___
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] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread via llvm-branch-commits

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

resolves llvm/llvm-project#80961

>From 362665f0dcc28a378e6610ae3cdd73dc79e6b272 Mon Sep 17 00:00:00 2001
From: Mariya Podchishchaeva 
Date: Tue, 6 Feb 2024 15:57:35 +0300
Subject: [PATCH] [clang] Fix unexpected `-Wconstant-logical-operand` in C23
 (#80724)

C23 has `bool`, but logical operators still return int. Check that
we're not in C to avoid false-positive -Wconstant-logical-operand.

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

(cherry picked from commit a18e92d020b895b712175a3b13a3d021608115a7)
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/lib/Sema/SemaExpr.cpp|  2 +-
 clang/test/Sema/warn-int-in-bool-context.c | 11 +++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b05c72c7f2c3eb..95d44951ae7ee6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,10 @@ Bug Fixes in This Version
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
 
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+  for logical operators in C23.
+  Fixes (`#64356 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4efcb359035576..0d9c087ed0cd19 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14062,7 +14062,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
 Expr::EvalResult EVResult;
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
-  if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+  if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)
diff --git a/clang/test/Sema/warn-int-in-bool-context.c 
b/clang/test/Sema/warn-int-in-bool-context.c
index 0c94ebb391f3c5..99f3db9f8d41a7 100644
--- a/clang/test/Sema/warn-int-in-bool-context.c
+++ b/clang/test/Sema/warn-int-in-bool-context.c
@@ -72,3 +72,14 @@ int test(int a, unsigned b, enum num n) {
   // Don't warn in macros.
   return SHIFT(1, a);
 }
+
+int GH64356(int arg) {
+  if ((arg == 1) && (1 == 1)) return 1;
+return 0;
+
+  if ((64 > 32) && (32 < 64))
+return 2;
+
+  if ((1 == 1) && (arg == 1)) return 1;
+return 0;
+}

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


[llvm-branch-commits] [clang] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/80962
___
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] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/80962
___
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] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

resolves llvm/llvm-project#80961

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/test/Sema/warn-int-in-bool-context.c (+11) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b05c72c7f2c3eb..95d44951ae7ee6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,10 @@ Bug Fixes in This Version
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
 
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+  for logical operators in C23.
+  Fixes (`#64356 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4efcb359035576..0d9c087ed0cd19 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14062,7 +14062,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
 Expr::EvalResult EVResult;
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
-  if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+  if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)
diff --git a/clang/test/Sema/warn-int-in-bool-context.c 
b/clang/test/Sema/warn-int-in-bool-context.c
index 0c94ebb391f3c5..99f3db9f8d41a7 100644
--- a/clang/test/Sema/warn-int-in-bool-context.c
+++ b/clang/test/Sema/warn-int-in-bool-context.c
@@ -72,3 +72,14 @@ int test(int a, unsigned b, enum num n) {
   // Don't warn in macros.
   return SHIFT(1, a);
 }
+
+int GH64356(int arg) {
+  if ((arg == 1) && (1 == 1)) return 1;
+return 0;
+
+  if ((64 > 32) && (32 < 64))
+return 2;
+
+  if ((1 == 1) && (arg == 1)) return 1;
+return 0;
+}

``




https://github.com/llvm/llvm-project/pull/80962
___
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] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread Aaron Ballman via llvm-branch-commits

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

LGTM!

https://github.com/llvm/llvm-project/pull/80962
___
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] PR for llvm/llvm-project#80844 (PR #80846)

2024-02-07 Thread Kerry McLaughlin via llvm-branch-commits

https://github.com/kmclaughlin-arm approved this pull request.

LGTM. This fix is a low risk change which I think should be included in the 
release branch.

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


[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#81000 (PR #81003)

2024-02-07 Thread via llvm-branch-commits

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

resolves llvm/llvm-project#81000

>From a2bc254a372fe1942dc97957aeef50ba088f6534 Mon Sep 17 00:00:00 2001
From: David CARLIER 
Date: Wed, 24 Jan 2024 23:07:32 +
Subject: [PATCH] [compiler-rt] remove hexdump interception. (#79378)

a freebsd dev member reported a symbol conflict and intercepting this
had little value anyway.

(cherry picked from commit 16a1ef86cbc5e6c829919ec6c73325413b0cd21b)
---
 .../sanitizer_common_interceptors.inc | 15 
 .../sanitizer_platform_interceptors.h |  1 -
 .../TestCases/FreeBSD/hexdump.cc  | 23 ---
 3 files changed, 39 deletions(-)
 delete mode 100644 
compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 1b56bebac64e6..3ecdb55cdbf72 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10218,20 +10218,6 @@ INTERCEPTOR(int, __xuname, int size, void *utsname) {
 #define INIT___XUNAME
 #endif
 
-#if SANITIZER_INTERCEPT_HEXDUMP
-INTERCEPTOR(void, hexdump, const void *ptr, int length, const char *header, 
int flags) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, hexdump, ptr, length, header, flags);
-  COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, length);
-  COMMON_INTERCEPTOR_READ_RANGE(ctx, header, internal_strlen(header) + 1);
-  REAL(hexdump)(ptr, length, header, flags);
-}
-
-#define INIT_HEXDUMP COMMON_INTERCEPT_FUNCTION(hexdump);
-#else
-#define INIT_HEXDUMP
-#endif
-
 #if SANITIZER_INTERCEPT_ARGP_PARSE
 INTERCEPTOR(int, argp_parse, const struct argp *argp, int argc, char **argv,
 unsigned flags, int *arg_index, void *input) {
@@ -10581,7 +10567,6 @@ static void InitializeCommonInterceptors() {
   INIT_PROCCTL
   INIT_UNAME;
   INIT___XUNAME;
-  INIT_HEXDUMP;
   INIT_ARGP_PARSE;
   INIT_CPUSET_GETAFFINITY;
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 0ce4e9351bc1d..de55c736d0e14 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -596,7 +596,6 @@
 #define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
 #define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
 #define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
-#define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
 #define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc 
b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc
deleted file mode 100644
index e07650d64102a..0
--- a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-// RUN: %clangxx -O0 -g %s -o %t -lutil && %run %t 2>&1 | FileCheck %s
-
-#include 
-#include 
-#include 
-#include 
-
-int main(void) {
-  printf("hexdump");
-  char *line;
-  size_t lineno = 0, len;
-  const char *delim = "#";
-  FILE *fp = fopen("/etc/fstab", "r");
-  assert(fp);
-  line = fparseln(fp, &len, &lineno, delim, 0);
-  hexdump(line, len, nullptr, 0);
-  free(line);
-  fclose(fp);
-  assert(lineno != 0);
-  assert(len > 0);
-
-  return 0;
-}

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


[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#81000 (PR #81003)

2024-02-07 Thread via llvm-branch-commits

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


[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#81000 (PR #81003)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:

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

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


[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#81000 (PR #81003)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (llvmbot)


Changes

resolves llvm/llvm-project#81000

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


3 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
(-15) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
(-1) 
- (removed) compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc 
(-23) 


``diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc 
b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 1b56bebac64e68..3ecdb55cdbf72f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -10218,20 +10218,6 @@ INTERCEPTOR(int, __xuname, int size, void *utsname) {
 #define INIT___XUNAME
 #endif
 
-#if SANITIZER_INTERCEPT_HEXDUMP
-INTERCEPTOR(void, hexdump, const void *ptr, int length, const char *header, 
int flags) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, hexdump, ptr, length, header, flags);
-  COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, length);
-  COMMON_INTERCEPTOR_READ_RANGE(ctx, header, internal_strlen(header) + 1);
-  REAL(hexdump)(ptr, length, header, flags);
-}
-
-#define INIT_HEXDUMP COMMON_INTERCEPT_FUNCTION(hexdump);
-#else
-#define INIT_HEXDUMP
-#endif
-
 #if SANITIZER_INTERCEPT_ARGP_PARSE
 INTERCEPTOR(int, argp_parse, const struct argp *argp, int argc, char **argv,
 unsigned flags, int *arg_index, void *input) {
@@ -10581,7 +10567,6 @@ static void InitializeCommonInterceptors() {
   INIT_PROCCTL
   INIT_UNAME;
   INIT___XUNAME;
-  INIT_HEXDUMP;
   INIT_ARGP_PARSE;
   INIT_CPUSET_GETAFFINITY;
 
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 0ce4e9351bc1da..de55c736d0e144 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -596,7 +596,6 @@
 #define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
 #define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
 #define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
-#define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
 #define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc 
b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc
deleted file mode 100644
index e07650d64102a4..00
--- a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/hexdump.cc
+++ /dev/null
@@ -1,23 +0,0 @@
-// RUN: %clangxx -O0 -g %s -o %t -lutil && %run %t 2>&1 | FileCheck %s
-
-#include 
-#include 
-#include 
-#include 
-
-int main(void) {
-  printf("hexdump");
-  char *line;
-  size_t lineno = 0, len;
-  const char *delim = "#";
-  FILE *fp = fopen("/etc/fstab", "r");
-  assert(fp);
-  line = fparseln(fp, &len, &lineno, delim, 0);
-  hexdump(line, len, nullptr, 0);
-  free(line);
-  fclose(fp);
-  assert(lineno != 0);
-  assert(len > 0);
-
-  return 0;
-}

``




https://github.com/llvm/llvm-project/pull/81003
___
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] PR for llvm/llvm-project#80961 (PR #80962)

2024-02-07 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/80962

>From 8cc6c5ae8fe649b05abdaf299f04f8ac05a36b58 Mon Sep 17 00:00:00 2001
From: Mariya Podchishchaeva 
Date: Tue, 6 Feb 2024 15:57:35 +0300
Subject: [PATCH] [clang] Fix unexpected `-Wconstant-logical-operand` in C23
 (#80724)

C23 has `bool`, but logical operators still return int. Check that
we're not in C to avoid false-positive -Wconstant-logical-operand.

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

(cherry picked from commit a18e92d020b895b712175a3b13a3d021608115a7)
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/lib/Sema/SemaExpr.cpp|  2 +-
 clang/test/Sema/warn-int-in-bool-context.c | 11 +++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b05c72c7f2c3eb..95d44951ae7ee6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,10 @@ Bug Fixes in This Version
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
 
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+  for logical operators in C23.
+  Fixes (`#64356 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4efcb359035576..0d9c087ed0cd19 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14062,7 +14062,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult 
&LHS, ExprResult &RHS,
 Expr::EvalResult EVResult;
 if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
   llvm::APSInt Result = EVResult.Val.getInt();
-  if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+  if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
   (Result != 0 && Result != 1)) {
 Diag(Loc, diag::warn_logical_instead_of_bitwise)
diff --git a/clang/test/Sema/warn-int-in-bool-context.c 
b/clang/test/Sema/warn-int-in-bool-context.c
index 0c94ebb391f3c5..99f3db9f8d41a7 100644
--- a/clang/test/Sema/warn-int-in-bool-context.c
+++ b/clang/test/Sema/warn-int-in-bool-context.c
@@ -72,3 +72,14 @@ int test(int a, unsigned b, enum num n) {
   // Don't warn in macros.
   return SHIFT(1, a);
 }
+
+int GH64356(int arg) {
+  if ((arg == 1) && (1 == 1)) return 1;
+return 0;
+
+  if ((64 > 32) && (32 < 64))
+return 2;
+
+  if ((1 == 1) && (arg == 1)) return 1;
+return 0;
+}

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


[llvm-branch-commits] [compiler-rt] PR for llvm/llvm-project#80604 (PR #80605)

2024-02-07 Thread Dimitry Andric via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/80605
___
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 fixes for release/18.x (PR #80772)

2024-02-07 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/80772

>From e54eaf5a5136628ae8f2bc00c6d769b33dd2c0f0 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 3 Feb 2024 21:37:46 -0800
Subject: [PATCH 1/4] [workflows] Stop using the build-test-llvm-project action
 (#80580)

This action is really just a wrapper around cmake and ninja. It doesn't
add any value to the builds, and I don't think we need it now that there
are reusable workflows.

(cherry picked from commit d25022bb689b9bf48a24c0ae6c29c1d3c2f32823)
---
 .github/workflows/llvm-project-tests.yml | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 91d0b258394ef..79a382bfa4f9a 100644
--- a/.github/workflows/llvm-project-tests.yml
+++ b/.github/workflows/llvm-project-tests.yml
@@ -98,14 +98,23 @@ jobs:
   key: ${{ matrix.os }}
   variant: sccache
   - name: Build and Test
-uses: llvm/actions/build-test-llvm-project@main
 env:
   # Workaround for 
https://github.com/actions/virtual-environments/issues/5900.
   # This should be a no-op for non-mac OSes
   PKG_CONFIG_PATH: 
/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig//12
-with:
-  cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_INCLUDE_TESTS=OFF 
-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ${{ 
inputs.extra_cmake_args }}'
-  build_target: '${{ inputs.build_target }}'
+shell: bash
+run: |
+  cmake -G Ninja \
+-B build \
+-S llvm \
+-DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" \
+-DCMAKE_BUILD_TYPE=Release \
+-DLLVM_ENABLE_ASSERTIONS=ON \
+-DLLDB_INCLUDE_TESTS=OFF \
+-DCMAKE_C_COMPILER_LAUNCHER=sccache \
+-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
+${{ inputs.extra_cmake_args }}
+  ninja -C build '${{ inputs.build_target }}'
 
   - name: Build and Test libclc
 if: "!startsWith(matrix.os, 'windows') && contains(inputs.projects, 
'libclc')"

>From ff2405a632eeb0d9356108c5fd0d86afdbe4d163 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 5 Feb 2024 16:44:11 -0800
Subject: [PATCH 2/4] [workflows] Fix lldb-tests and libclc-tests (#80751)

This was broken by d25022bb689b9bf48a24c0ae6c29c1d3c2f32823, which
caused the workflow to pass an empty string to ninja as the target. The
'all' target is probably not the right target for these tests, but this
is what the behavior was before
d25022bb689b9bf48a24c0ae6c29c1d3c2f32823.

(cherry picked from commit 792d928e15aa30c8b686eff465598ceea0b03891)
---
 .github/workflows/libclc-tests.yml   | 1 -
 .github/workflows/lldb-tests.yml | 1 -
 .github/workflows/llvm-project-tests.yml | 3 ++-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/libclc-tests.yml 
b/.github/workflows/libclc-tests.yml
index 29d050db2f12c..23192f776a985 100644
--- a/.github/workflows/libclc-tests.yml
+++ b/.github/workflows/libclc-tests.yml
@@ -36,5 +36,4 @@ jobs:
 name: Test libclc
 uses: ./.github/workflows/llvm-project-tests.yml
 with:
-  build_target: ''
   projects: clang;libclc
diff --git a/.github/workflows/lldb-tests.yml b/.github/workflows/lldb-tests.yml
index ef5d7c7d581b7..6bb9721956258 100644
--- a/.github/workflows/lldb-tests.yml
+++ b/.github/workflows/lldb-tests.yml
@@ -36,5 +36,4 @@ jobs:
 name: Build lldb
 uses: ./.github/workflows/llvm-project-tests.yml
 with:
-  build_target: ''
   projects: clang;lldb
diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 79a382bfa4f9a..0e361bfb77fe4 100644
--- a/.github/workflows/llvm-project-tests.yml
+++ b/.github/workflows/llvm-project-tests.yml
@@ -22,8 +22,9 @@ on:
   workflow_call:
 inputs:
   build_target:
-required: true
+required: false
 type: string
+default: "all"
 
   projects:
 required: true

>From 4929f87c3f9e320cb89af2ce2f5dbe27f69851ac Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 5 Feb 2024 09:46:19 -0800
Subject: [PATCH 3/4] [workflows] Use /mnt as the build directory on Linux
 (#80583)

There is more space available on /mnt (~56G) than on / (~30G), and we
are starting to see some of the CI jobs run out of disk space on Linux.

(cherry picked from commit 1a6426067fb33a8a789978f6e229108787a041be)
---
 .github/workflows/llvm-project-tests.yml | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 0e361bfb77fe4..3bc7bd4957fa6 100644
--- a/.github/workflows/llvm-project-tests.yml
+++

[llvm-branch-commits] [clang] PR for llvm/llvm-project#80619 (PR #80620)

2024-02-07 Thread Dmitri Gribenko via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/80620
___
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] [NFC]Refactor (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 created 
https://github.com/llvm/llvm-project/pull/81024

None


___
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] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function for re-use (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function for re-use (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81024
___
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] [18.x][Docs] Add release note about Clang-defined target OS macros (PR #80044)

2024-02-07 Thread Zixu Wang via llvm-branch-commits

https://github.com/zixu-w updated 
https://github.com/llvm/llvm-project/pull/80044

>From f28a33baa2c1457c4e1eca8f484c59a655132f95 Mon Sep 17 00:00:00 2001
From: Zixu Wang <9819235+zix...@users.noreply.github.com>
Date: Tue, 30 Jan 2024 09:30:20 -0800
Subject: [PATCH] [Docs] Add release note about Clang-defined target OS macros
 (#79879)

(cherry picked from commit b40d5b1b08564d23d5e0769892ebbc32447b2987)
---
 clang/docs/ReleaseNotes.rst | 25 +
 1 file changed, 25 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 060bc7669b72a5..cc75ed6bdc5ea3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -171,6 +171,22 @@ AST Dumping Potentially Breaking Changes
   "qualType": "foo"
 }
 
+Clang Frontend Potentially Breaking Changes
+---
+- Target OS macros extension
+  A new Clang extension (see :ref:`here `) is enabled for
+  Darwin (Apple platform) targets. Clang now defines ``TARGET_OS_*`` macros for
+  these targets, which could break existing code bases with improper checks for
+  the ``TARGET_OS_`` macros. For example, existing checks might fail to include
+  the ``TargetConditionals.h`` header from Apple SDKs and therefore leaving the
+  macros undefined and guarded code unexercised.
+
+  Affected code should be checked to see if it's still intended for the 
specific
+  target and fixed accordingly.
+
+  The extension can be turned off by the option 
``-fno-define-target-os-macros``
+  as a workaround.
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -344,6 +360,15 @@ New Compiler Flags
   (like other functions) with respect to visibility attributes, pragmas and
   options (e.g ``--fvisibility=``).
 
+.. _target_os_detail:
+
+* ``-fdefine-target-os-macros`` and its complement
+  ``-fno-define-target-os-macros``. Enables or disables the Clang extension to
+  provide built-in definitions of a list of ``TARGET_OS_*`` macros based on the
+  target triple.
+
+  The extension is enabled by default for Darwin (Apple platform) targets.
+
 Deprecated Compiler Flags
 -
 

___
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] [18.x][Docs] Add release note about Clang-defined target OS macros (PR #80044)

2024-02-07 Thread Zixu Wang via llvm-branch-commits

zixu-w wrote:

> Looks like this patch caused the documentation build to fail.

Fixed. Thanks for checking @tstellar !

https://github.com/llvm/llvm-project/pull/80044
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -857,11 +857,7 @@ void VPlan::execute(VPTransformState *State) {
 Phi = cast(State->get(R.getVPSingleValue(), 0));
   } else {
 auto *WidenPhi = cast(&R);
-// TODO: Split off the case that all users of a pointer phi are scalar
-// from the VPWidenPointerInductionRecipe.
-if (WidenPhi->onlyScalarsGenerated(State->VF.isScalable()))
-  continue;
-
+assert(!WidenPhi->onlyScalarsGenerated(State->VF.isScalable()));

fhahn wrote:

Added, thanks!

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -537,6 +542,30 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, 
ScalarEvolution &SE) {
   bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
   VPBasicBlock::iterator InsertPt = HeaderVPBB->getFirstNonPhi();
   for (VPRecipeBase &Phi : HeaderVPBB->phis()) {

fhahn wrote:

Added a comment, thanks!

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -489,6 +490,23 @@ Value *VPInstruction::generateInstruction(VPTransformState 
&State,
 
 return ReducedPartRdx;
   }
+  case VPInstruction::PtrAdd: {
+if (vputils::onlyFirstLaneUsed(this)) {
+  auto *P = Builder.CreatePtrAdd(
+  State.get(getOperand(0), VPIteration(Part, 0)),
+  State.get(getOperand(1), VPIteration(Part, 0)), Name);
+  State.set(this, P, VPIteration(Part, 0));
+} else {
+  for (unsigned Lane = 0; Lane != State.VF.getKnownMinValue(); ++Lane) {
+Value *P = Builder.CreatePtrAdd(
+State.get(getOperand(0), VPIteration(Part, Lane)),
+State.get(getOperand(1), VPIteration(Part, Lane)), Name);
+
+State.set(this, P, VPIteration(Part, Lane));
+  }
+}
+return nullptr;

fhahn wrote:

Updated to split into generate for scalars (per lane, possibly optimizing 
depending on onlyFirstLaneUseD) and generate for vectors (per-part)

Some of it could be done separately or as part of 
https://github.com/llvm/llvm-project/pull/80271, but would be good to agree on 
the overall structure first then land separately as makes sense.

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -546,9 +575,10 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, 
ScalarEvolution &SE) {
   continue;
 
 const InductionDescriptor &ID = WideIV->getInductionDescriptor();
-VPValue *Steps = createScalarIVSteps(Plan, ID, SE, WideIV->getTruncInst(),
- WideIV->getStartValue(),
- WideIV->getStepValue(), InsertPt);
+VPValue *Steps = createScalarIVSteps(
+Plan, ID.getKind(), SE, WideIV->getTruncInst(), 
WideIV->getStartValue(),
+WideIV->getStepValue(), ID.getInductionOpcode(), InsertPt,
+dyn_cast_or_null(ID.getInductionBinOp()));

fhahn wrote:

Adjusted, thanks! Can spli off moving induction opcode field separately.

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -2503,6 +2504,12 @@ class VPDerivedIVRecipe : public VPSingleDefRecipe {
 dyn_cast_or_null(IndDesc.getInductionBinOp()),
 Start, CanonicalIV, Step) {}
 
+  VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, VPValue *Start,
+VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
+FPMathOperator *FPBinOp)

fhahn wrote:

Made the private one public and removed this one here, thanks!

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -515,6 +533,8 @@ void VPInstruction::execute(VPTransformState &State) {
 State.Builder.setFastMathFlags(getFastMathFlags());
   for (unsigned Part = 0; Part < State.UF; ++Part) {
 Value *GeneratedValue = generateInstruction(State, Part);
+if (!GeneratedValue)
+  continue;
 if (!hasResult())
   continue;

fhahn wrote:

Completely reworked this, the check for !GeneratedValue is gone now

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -537,6 +542,30 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, 
ScalarEvolution &SE) {
   bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
   VPBasicBlock::iterator InsertPt = HeaderVPBB->getFirstNonPhi();
   for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
+if (auto *PtrIV = dyn_cast(&Phi)) {
+  if (!PtrIV->onlyScalarsGenerated(Plan.hasScalableVF()))
+continue;
+
+  const InductionDescriptor &ID = PtrIV->getInductionDescriptor();
+  VPValue *StartV = Plan.getVPValueOrAddLiveIn(
+  ConstantInt::get(ID.getStep()->getType(), 0));
+  VPValue *StepV = PtrIV->getOperand(1);
+  VPRecipeBase *Steps =

fhahn wrote:

Will do separately, thanks!

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -489,15 +489,18 @@ void VPlanTransforms::removeDeadRecipes(VPlan &Plan) {
   }
 }
 
-static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
+static VPValue *createScalarIVSteps(VPlan &Plan,
+InductionDescriptor::InductionKind Kind,
 ScalarEvolution &SE, Instruction *TruncI,
 VPValue *StartV, VPValue *Step,
-VPBasicBlock::iterator IP) {
+Instruction::BinaryOps InductionOpcode,
+VPBasicBlock::iterator IP,
+FPMathOperator *FPBinOp = nullptr) {
   VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
   VPSingleDefRecipe *BaseIV = CanonicalIV;
-  if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step)) {
-BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step);
+  if (!CanonicalIV->isCanonical(Kind, StartV, Step)) {
+BaseIV = new VPDerivedIVRecipe(Kind, StartV, CanonicalIV, Step, FPBinOp);

fhahn wrote:

Yes, can split off!

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -515,6 +533,8 @@ void VPInstruction::execute(VPTransformState &State) {
 State.Builder.setFastMathFlags(getFastMathFlags());
   for (unsigned Part = 0; Part < State.UF; ++Part) {
 Value *GeneratedValue = generateInstruction(State, Part);
+if (!GeneratedValue)
+  continue;
 if (!hasResult())
   continue;
 assert(GeneratedValue && "generateInstruction must produce a value");

fhahn wrote:

Reworked now, the check for !GeneratedValue is gone now

https://github.com/llvm/llvm-project/pull/80273
___
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] [VPlan] Explicitly handle scalar pointer inductions. (PR #80273)

2024-02-07 Thread Florian Hahn via llvm-branch-commits


@@ -537,6 +542,30 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, 
ScalarEvolution &SE) {
   bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
   VPBasicBlock::iterator InsertPt = HeaderVPBB->getFirstNonPhi();
   for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
+if (auto *PtrIV = dyn_cast(&Phi)) {
+  if (!PtrIV->onlyScalarsGenerated(Plan.hasScalableVF()))
+continue;
+
+  const InductionDescriptor &ID = PtrIV->getInductionDescriptor();
+  VPValue *StartV = Plan.getVPValueOrAddLiveIn(
+  ConstantInt::get(ID.getStep()->getType(), 0));

fhahn wrote:

The start value of the pointer induction is the pointer base, but here we need 
the start value for the generate offsets.

https://github.com/llvm/llvm-project/pull/80273
___
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] [InstrProf] (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 created 
https://github.com/llvm/llvm-project/pull/81051

None


___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81051
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81051
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits


@@ -1628,6 +1664,17 @@ TEST(SymtabTest, instr_prof_symtab_module_test) {
 EXPECT_EQ(StringRef(PGOName), PGOFuncName);
 EXPECT_THAT(PGOFuncName.str(), EndsWith(Funcs[I].str()));
   }
+
+  StringRef VTables[] = {"ExternalGV", "PrivateGV"};
+  for (size_t I = 0; I < std::size(VTables); I++) {
+GlobalVariable *GV =
+M->getGlobalVariable(VTables[I], /* AllowInternal=*/true);
+
+std::string IRPGOName = getIRPGOObjectName(*GV);
+EXPECT_EQ(IRPGOName, ProfSymtab.getFuncOrVarName(
+ IndexedInstrProf::ComputeHash(IRPGOName)));
+EXPECT_EQ(VTables[I], getParsedIRPGOFuncName(IRPGOName).second);

minglotus-6 wrote:

An NFC patch (https://github.com/llvm/llvm-project/pull/81054) was created to 
generalize the function name.

https://github.com/llvm/llvm-project/pull/81051
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 ready_for_review 
https://github.com/llvm/llvm-project/pull/81051
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-pgo

Author: Mingming Liu (minglotus-6)


Changes

* The parent patch is https://github.com/llvm/llvm-project/pull/81024

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


3 Files Affected:

- (modified) llvm/include/llvm/ProfileData/InstrProf.h (+28) 
- (modified) llvm/lib/ProfileData/InstrProf.cpp (+79-41) 
- (modified) llvm/unittests/ProfileData/InstrProfTest.cpp (+47) 


``diff
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 6cdceae5eeb96..d5d3c7f6b4b34 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -198,6 +198,15 @@ std::string getPGOFuncName(StringRef RawFuncName,
 /// called from LTO optimization passes.
 std::string getIRPGOFuncName(const Function &F, bool InLTO = false);
 
+/// Returns the PGO object name. This function has some special handling
+/// when called in LTO optimization:
+/// - In LTO mode, returns the name in `PGONameMetadata` if exists, otherwise
+/// returns the IRPGO name as if the GO has non-local linkage.
+/// - In non-LTO mode, returns the IRPGO name as it is.
+/// More rationale in the comment of function implementation.
+std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO = false,
+   MDNode *PGONameMetadata = nullptr);
+
 /// \return the filename and the function name parsed from the output of
 /// \c getIRPGOFuncName()
 std::pair getParsedIRPGOFuncName(StringRef 
IRPGOFuncName);
@@ -487,8 +496,25 @@ class InstrProfSymtab {
 return "** External Symbol **";
   }
 
+  // Returns the canonical name of the given PGOName by stripping the names
+  // suffixes that begins with ".". If MayHaveUniqueSuffix is true, ".__uniq."
+  // suffix is kept in the canonical name.
+  StringRef getCanonicalName(StringRef PGOName, bool MayHaveUniqueSuffix);
+
+  // Add the function into the symbol table, by creating the following
+  // map entries:
+  // - 
+  // - 
+  // - 
+  // - 
+  // - (instrprof_error::malformed,
@@ -665,6 +692,7 @@ void InstrProfSymtab::finalizeSymtab() {
   if (Sorted)
 return;
   llvm::sort(MD5NameMap, less_first());
+  llvm::sort(MD5VTableMap, less_first());
   llvm::sort(MD5FuncMap, less_first());
   llvm::sort(AddrToMD5Map, less_first());
   AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 91e79e8b2e9ad..3b05faf0cc5d3 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -325,21 +325,20 @@ static std::optional 
lookupPGONameFromMetadata(MDNode *MD) {
   return {};
 }
 
-// Returns the PGO object name. This function has some special handling
-// when called in LTO optimization. The following only applies when calling in
-// LTO passes (when \c InLTO is true): LTO's internalization privatizes many
-// global linkage symbols. This happens after value profile annotation, but
-// those internal linkage functions should not have a source prefix.
-// Additionally, for ThinLTO mode, exported internal functions are promoted
-// and renamed. We need to ensure that the original internal PGO name is
-// used when computing the GUID that is compared against the profiled GUIDs.
-// To differentiate compiler generated internal symbols from original ones,
-// PGOFuncName meta data are created and attached to the original internal
-// symbols in the value profile annotation step
-// (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta
-// data, its original linkage must be non-internal.
-static std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO,
-  MDNode *PGONameMetadata) {
+std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO,
+   MDNode *PGONameMetadata) {
+  // The following only applies when calling in
+  // LTO passes (when \c InLTO is true): LTO's internalization privatizes many
+  // global linkage symbols. This happens after value profile annotation, but
+  // those internal linkage functions should not have a source prefix.
+  // Additionally, for ThinLTO mode, exported internal functions are promoted
+  // and renamed. We need to ensure that the original internal PGO name is
+  // used when computing the GUID that is compared against the profiled GUIDs.
+  // To differentiate compiler generated internal symbols from original ones,
+  // PGOFuncName meta data are created and attached to the original internal
+  // symbols in the value profile annotation step
+  // (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the 
meta
+  // data, its original linkage must be non-internal.
   if (!InLTO) {
 auto FileName = getStrippedSourceFileName(GO);
 return getIRPGONameForGlobalObject(GO, GO.getLinkage(), FileName);
@@ -481,7 +480,9 @@ Error InstrProfSymtab::creat

[llvm-branch-commits] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Teresa Johnson via llvm-branch-commits


@@ -1260,6 +1260,8 @@ void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef VDs,
uint64_t Sum, InstrProfValueKind ValueKind,
uint32_t MaxMDCount) {
+  if (VDs.empty())

teresajohnson wrote:

Oh, is this because you no longer check the "NumPromoted == NumVals" case?

https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Teresa Johnson via llvm-branch-commits


@@ -1260,6 +1260,8 @@ void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef VDs,
uint64_t Sum, InstrProfValueKind ValueKind,
uint32_t MaxMDCount) {
+  if (VDs.empty())

teresajohnson wrote:

Why this change?

https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Teresa Johnson via llvm-branch-commits


@@ -287,7 +290,18 @@ uint32_t IndirectCallPromoter::tryToPromote(
 NumOfPGOICallPromotion++;
 NumPromoted++;
   }
-  return NumPromoted;
+
+  const bool Changed = (NumPromoted != 0);

teresajohnson wrote:

Just return false early if NumPromoted is 0 (then Changed can be removed and 
just return true at the end further below).

https://github.com/llvm/llvm-project/pull/80762
___
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 fixes for release/18.x (PR #80772)

2024-02-07 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/80772

>From aa9e739cf5d6ea362fdbc28ec97bcf71e81fa3b7 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 3 Feb 2024 21:37:46 -0800
Subject: [PATCH 1/4] [workflows] Stop using the build-test-llvm-project action
 (#80580)

This action is really just a wrapper around cmake and ninja. It doesn't
add any value to the builds, and I don't think we need it now that there
are reusable workflows.

(cherry picked from commit d25022bb689b9bf48a24c0ae6c29c1d3c2f32823)
---
 .github/workflows/llvm-project-tests.yml | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 91d0b258394ef..79a382bfa4f9a 100644
--- a/.github/workflows/llvm-project-tests.yml
+++ b/.github/workflows/llvm-project-tests.yml
@@ -98,14 +98,23 @@ jobs:
   key: ${{ matrix.os }}
   variant: sccache
   - name: Build and Test
-uses: llvm/actions/build-test-llvm-project@main
 env:
   # Workaround for 
https://github.com/actions/virtual-environments/issues/5900.
   # This should be a no-op for non-mac OSes
   PKG_CONFIG_PATH: 
/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig//12
-with:
-  cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLDB_INCLUDE_TESTS=OFF 
-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ${{ 
inputs.extra_cmake_args }}'
-  build_target: '${{ inputs.build_target }}'
+shell: bash
+run: |
+  cmake -G Ninja \
+-B build \
+-S llvm \
+-DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" \
+-DCMAKE_BUILD_TYPE=Release \
+-DLLVM_ENABLE_ASSERTIONS=ON \
+-DLLDB_INCLUDE_TESTS=OFF \
+-DCMAKE_C_COMPILER_LAUNCHER=sccache \
+-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
+${{ inputs.extra_cmake_args }}
+  ninja -C build '${{ inputs.build_target }}'
 
   - name: Build and Test libclc
 if: "!startsWith(matrix.os, 'windows') && contains(inputs.projects, 
'libclc')"

>From 559243a4a1e9f583cd3143c3301bbb692fc289f9 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 5 Feb 2024 16:44:11 -0800
Subject: [PATCH 2/4] [workflows] Fix lldb-tests and libclc-tests (#80751)

This was broken by d25022bb689b9bf48a24c0ae6c29c1d3c2f32823, which
caused the workflow to pass an empty string to ninja as the target. The
'all' target is probably not the right target for these tests, but this
is what the behavior was before
d25022bb689b9bf48a24c0ae6c29c1d3c2f32823.

(cherry picked from commit 792d928e15aa30c8b686eff465598ceea0b03891)
---
 .github/workflows/libclc-tests.yml   | 1 -
 .github/workflows/lldb-tests.yml | 1 -
 .github/workflows/llvm-project-tests.yml | 3 ++-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/libclc-tests.yml 
b/.github/workflows/libclc-tests.yml
index 29d050db2f12c..23192f776a985 100644
--- a/.github/workflows/libclc-tests.yml
+++ b/.github/workflows/libclc-tests.yml
@@ -36,5 +36,4 @@ jobs:
 name: Test libclc
 uses: ./.github/workflows/llvm-project-tests.yml
 with:
-  build_target: ''
   projects: clang;libclc
diff --git a/.github/workflows/lldb-tests.yml b/.github/workflows/lldb-tests.yml
index ef5d7c7d581b7..6bb9721956258 100644
--- a/.github/workflows/lldb-tests.yml
+++ b/.github/workflows/lldb-tests.yml
@@ -36,5 +36,4 @@ jobs:
 name: Build lldb
 uses: ./.github/workflows/llvm-project-tests.yml
 with:
-  build_target: ''
   projects: clang;lldb
diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 79a382bfa4f9a..0e361bfb77fe4 100644
--- a/.github/workflows/llvm-project-tests.yml
+++ b/.github/workflows/llvm-project-tests.yml
@@ -22,8 +22,9 @@ on:
   workflow_call:
 inputs:
   build_target:
-required: true
+required: false
 type: string
+default: "all"
 
   projects:
 required: true

>From f2bf335ecf8a56c0d87cfbd8999226db8d9f43d2 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 5 Feb 2024 09:46:19 -0800
Subject: [PATCH 3/4] [workflows] Use /mnt as the build directory on Linux
 (#80583)

There is more space available on /mnt (~56G) than on / (~30G), and we
are starting to see some of the CI jobs run out of disk space on Linux.

(cherry picked from commit 1a6426067fb33a8a789978f6e229108787a041be)
---
 .github/workflows/llvm-project-tests.yml | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/llvm-project-tests.yml 
b/.github/workflows/llvm-project-tests.yml
index 0e361bfb77fe4..3bc7bd4957fa6 100644
--- a/.github/workflows/llvm-project-tests.yml
+++

[llvm-branch-commits] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function (PR #81024)

2024-02-07 Thread Teresa Johnson via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC] (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/80762

>From 2a03c530e775faa79d2e800a38a4228b38dfea35 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Wed, 7 Feb 2024 18:20:51 -0800
Subject: [PATCH] resolve review feedback

Created using spr 1.3.4
---
 .../Instrumentation/IndirectCallPromotion.cpp | 20 +++
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp 
b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 6a44a32bb34dc9..23a7c6a20aecbc 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -291,17 +291,21 @@ bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
 NumPromoted++;
   }
 
-  const bool Changed = (NumPromoted != 0);
+  if (NumPromoted == 0)
+return false;
 
-  if (Changed) {
-CB.setMetadata(LLVMContext::MD_prof, nullptr);
+  // Adjust the MD.prof metadata. First delete the old one.
+  CB.setMetadata(LLVMContext::MD_prof, nullptr);
 
-if (TotalCount != 0)
-  annotateValueSite(*F.getParent(), CB, 
ICallProfDataRef.slice(NumPromoted),
-TotalCount, IPVK_IndirectCallTarget, NumCandidates);
-  }
+  assert(NumPromoted <= ICallProfDataRef.size() &&
+ "Number of promoted functions should not be greater than the number "
+ "of values in profile metadata");
+  // Annotate the remaining value profiles if counter is not zero.
+  if (TotalCount != 0)
+annotateValueSite(*F.getParent(), CB, ICallProfDataRef.slice(NumPromoted),
+  TotalCount, IPVK_IndirectCallTarget, NumCandidates);
 
-  return Changed;
+  return true;
 }
 
 // Traverse all the indirect-call callsite and get the value profile

___
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] [NFC] (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC] (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits


@@ -287,7 +290,18 @@ uint32_t IndirectCallPromoter::tryToPromote(
 NumOfPGOICallPromotion++;
 NumPromoted++;
   }
-  return NumPromoted;
+
+  const bool Changed = (NumPromoted != 0);

minglotus-6 wrote:

done.

https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC] (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits


@@ -1260,6 +1260,8 @@ void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef VDs,
uint64_t Sum, InstrProfValueKind ValueKind,
uint32_t MaxMDCount) {
+  if (VDs.empty())

minglotus-6 wrote:

yes, the check `NumPromoted == NumVals` is removed so `NumVals` doesn't need to 
be passed as an argument to `tryToPromoteWithFuncCmp`.
- `NumVals == ICallProfDataRef.size()` is [always 
true](https://github.com/llvm/llvm-project/blob/0d7f232baf6103529844c8977324bd45b21ad923/llvm/lib/Analysis/IndirectCallPromotionAnalysis.cpp#L98),
 and `NumPromoted <= NumVals` is also true, so 
`ICallProfDataRef.slice(NumPromoted)` still returns a valid ArrayRef after the 
check is removed.

On a second thought, when `if(TotalCount != 0)` is true, it's also guaranteed 
`ICallProfDataRef.slice(NumPromoted)` is not empty so that 
`ICallProfDataRef.slice(NumPromoted)` returns a valid ArrayRef. Added an assert 
(`assert(NumPromoted <= ICallProfDataRef.size()`) just to make the condition 
that `.slice` relies on more explicit.

https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC] (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 ready_for_review 
https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function (PR #81024)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 ready_for_review 
https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC] (PR #80762)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-pgo

Author: Mingming Liu (minglotus-6)


Changes



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


3 Files Affected:

- (modified) llvm/include/llvm/ProfileData/InstrProf.h (+2) 
- (modified) llvm/lib/ProfileData/InstrProf.cpp (+2) 
- (modified) llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp 
(+28-21) 


``diff
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 248f62c7a81059..6cdceae5eeb960 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -277,6 +277,8 @@ void annotateValueSite(Module &M, Instruction &Inst,
uint32_t MaxMDCount = 3);
 
 /// Same as the above interface but using an ArrayRef, as well as \p Sum.
+/// This function will not annotate !prof metadata on the instruction if the
+/// referenced array is empty.
 void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef VDs, uint64_t Sum,
InstrProfValueKind ValueKind, uint32_t MaxMDCount);
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 1d8b0a1aca95f2..91e79e8b2e9add 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1260,6 +1260,8 @@ void annotateValueSite(Module &M, Instruction &Inst,
ArrayRef VDs,
uint64_t Sum, InstrProfValueKind ValueKind,
uint32_t MaxMDCount) {
+  if (VDs.empty())
+return;
   LLVMContext &Ctx = M.getContext();
   MDBuilder MDHelper(Ctx);
   SmallVector Vals;
diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp 
b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 7344fea1751719..23a7c6a20aecbc 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -136,11 +136,13 @@ class IndirectCallPromoter {
   const CallBase &CB, const ArrayRef &ValueDataRef,
   uint64_t TotalCount, uint32_t NumCandidates);
 
-  // Promote a list of targets for one indirect-call callsite. Return
-  // the number of promotions.
-  uint32_t tryToPromote(CallBase &CB,
-const std::vector &Candidates,
-uint64_t &TotalCount);
+  // Promote a list of targets for one indirect-call callsite by comparing
+  // indirect callee with functions. Returns true if there are IR
+  // transformations and false otherwise.
+  bool tryToPromoteWithFuncCmp(
+  CallBase &CB, const std::vector &Candidates,
+  uint64_t TotalCount, ArrayRef ICallProfDataRef,
+  uint32_t NumCandidates);
 
 public:
   IndirectCallPromoter(Function &Func, InstrProfSymtab *Symtab, bool SamplePGO,
@@ -273,9 +275,10 @@ CallBase &llvm::pgo::promoteIndirectCall(CallBase &CB, 
Function *DirectCallee,
 }
 
 // Promote indirect-call to conditional direct-call for one callsite.
-uint32_t IndirectCallPromoter::tryToPromote(
+bool IndirectCallPromoter::tryToPromoteWithFuncCmp(
 CallBase &CB, const std::vector &Candidates,
-uint64_t &TotalCount) {
+uint64_t TotalCount, ArrayRef ICallProfDataRef,
+uint32_t NumCandidates) {
   uint32_t NumPromoted = 0;
 
   for (const auto &C : Candidates) {
@@ -287,7 +290,22 @@ uint32_t IndirectCallPromoter::tryToPromote(
 NumOfPGOICallPromotion++;
 NumPromoted++;
   }
-  return NumPromoted;
+
+  if (NumPromoted == 0)
+return false;
+
+  // Adjust the MD.prof metadata. First delete the old one.
+  CB.setMetadata(LLVMContext::MD_prof, nullptr);
+
+  assert(NumPromoted <= ICallProfDataRef.size() &&
+ "Number of promoted functions should not be greater than the number "
+ "of values in profile metadata");
+  // Annotate the remaining value profiles if counter is not zero.
+  if (TotalCount != 0)
+annotateValueSite(*F.getParent(), CB, ICallProfDataRef.slice(NumPromoted),
+  TotalCount, IPVK_IndirectCallTarget, NumCandidates);
+
+  return true;
 }
 
 // Traverse all the indirect-call callsite and get the value profile
@@ -305,19 +323,8 @@ bool 
IndirectCallPromoter::processFunction(ProfileSummaryInfo *PSI) {
   continue;
 auto PromotionCandidates = getPromotionCandidatesForCallSite(
 *CB, ICallProfDataRef, TotalCount, NumCandidates);
-uint32_t NumPromoted = tryToPromote(*CB, PromotionCandidates, TotalCount);
-if (NumPromoted == 0)
-  continue;
-
-Changed = true;
-// Adjust the MD.prof metadata. First delete the old one.
-CB->setMetadata(LLVMContext::MD_prof, nullptr);
-// If all promoted, we don't need the MD.prof metadata.
-if (TotalCount == 0 || NumPromoted == NumVals)
-  continue;
-// Otherwise we need update with the un-promoted records back.
-annotateValueSite(*F.getParent(), *CB, ICallProfDataRef.s

[llvm-branch-commits] [NFC]Extract the heuristic to find vtable for an indirect call into a helper function (PR #81024)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Mingming Liu (minglotus-6)


Changes

* This way the helper function could be re-used by indirect-call-promotion pass 
to find out the vtable for an indirect call and extract the value profiles if 
any.
* The parent patch is https://github.com/llvm/llvm-project/pull/80762


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


1 Files Affected:

- (modified) llvm/include/llvm/Analysis/IndirectCallVisitor.h (+36-27) 


``diff
diff --git a/llvm/include/llvm/Analysis/IndirectCallVisitor.h 
b/llvm/include/llvm/Analysis/IndirectCallVisitor.h
index c8429e52bee96..5969241a179ea 100644
--- a/llvm/include/llvm/Analysis/IndirectCallVisitor.h
+++ b/llvm/include/llvm/Analysis/IndirectCallVisitor.h
@@ -28,6 +28,38 @@ struct PGOIndirectCallVisitor : public 
InstVisitor {
   std::vector ProfiledAddresses;
   PGOIndirectCallVisitor(InstructionType Type) : Type(Type) {}
 
+  // Given an indirect call instruction, try to find the the following pattern
+  //
+  // %vtable = load ptr, ptr %obj
+  // %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1
+  // %2 = load ptr, ptr %vfn
+  // $call = tail call i32 %2
+  //
+  // A heuristic is used to find the address feeding instructions.
+  static Instruction *tryGetVTableInstruction(CallBase *CB) {
+assert(CB != nullptr && "Caller guaranteed");
+LoadInst *LI = dyn_cast(CB->getCalledOperand());
+
+if (LI != nullptr) {
+  Value *FuncPtr = LI->getPointerOperand(); // GEP (or bitcast)
+  Value *VTablePtr = FuncPtr->stripInBoundsConstantOffsets();
+  // FIXME: Add support in the frontend so LLVM type intrinsics are
+  // emitted without LTO. This way, added intrinsics could filter
+  // non-vtable instructions and reduce instrumentation overhead.
+  // Since a non-vtable profiled address is not within the address
+  // range of vtable objects, it's stored as zero in indexed profiles.
+  // A pass that looks up symbol with an zero hash will (almost) always
+  // find nullptr and skip the actual transformation (e.g., comparison
+  // of symbols). So the performance overhead from non-vtable profiled
+  // address is negligible if exists at all. Comparing loaded address
+  // with symbol address guarantees correctness.
+  if (VTablePtr != nullptr && isa(VTablePtr)) {
+return cast(VTablePtr);
+  }
+}
+return nullptr;
+  }
+
   void visitCallBase(CallBase &Call) {
 if (Call.isIndirectCall()) {
   IndirectCalls.push_back(&Call);
@@ -35,33 +67,10 @@ struct PGOIndirectCallVisitor : public 
InstVisitor {
   if (Type != InstructionType::kVTableVal)
 return;
 
-  LoadInst *LI = dyn_cast(Call.getCalledOperand());
-  // The code pattern to look for
-  //
-  // %vtable = load ptr, ptr %b
-  // %vfn = getelementptr inbounds ptr, ptr %vtable, i64 1
-  // %2 = load ptr, ptr %vfn
-  // %call = tail call i32 %2(ptr %b)
-  //
-  // %vtable is the vtable address value to profile, and
-  // %2 is the indirect call target address to profile.
-  if (LI != nullptr) {
-Value *Ptr = LI->getPointerOperand();
-Value *VTablePtr = Ptr->stripInBoundsConstantOffsets();
-// This is a heuristic to find address feeding instructions.
-// FIXME: Add support in the frontend so LLVM type intrinsics are
-// emitted without LTO. This way, added intrinsics could filter
-// non-vtable instructions and reduce instrumentation overhead.
-// Since a non-vtable profiled address is not within the address
-// range of vtable objects, it's stored as zero in indexed profiles.
-// A pass that looks up symbol with an zero hash will (almost) always
-// find nullptr and skip the actual transformation (e.g., comparison
-// of symbols). So the performance overhead from non-vtable profiled
-// address is negligible if exists at all. Comparing loaded address
-// with symbol address guarantees correctness.
-if (VTablePtr != nullptr && isa(VTablePtr)) {
-  ProfiledAddresses.push_back(cast(VTablePtr));
-}
+  Instruction *VPtr =
+  PGOIndirectCallVisitor::tryGetVTableInstruction(&Call);
+  if (VPtr) {
+ProfiledAddresses.push_back(VPtr);
   }
 }
   }

``




https://github.com/llvm/llvm-project/pull/81024
___
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] [NFC] (PR #80762)

2024-02-07 Thread Teresa Johnson via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [NFC][IndirectCallProm] Refactor function-based conditional devirtualization and indirect call value profile update into one helper function (PR #80762)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/80762
___
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] [libunwind] PR for llvm/llvm-project#81084 (PR #81085)

2024-02-07 Thread via llvm-branch-commits

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

resolves llvm/llvm-project#81084

>From e6c6fe1a84fff2014be2b8f91f8905f109a15f0f Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 8 Feb 2024 09:15:53 +0800
Subject: [PATCH] MIPS/libunwind: Use -mfp64 if compiler is FPXX (#68521)

Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is
that, FP64 and FP32 have different way to save/restore FPRs. If
libunwind is built as FPXX, we have no idea which one should we use.

It's not due to the code bug, but rather the nature of FPXX.
FPXX is an ABI which uses only a common subset of FR=1(FP64) and FR=0
(FP32).
So that FPXX binaries can link with both FP64 and FP32 ones, aka.
FPXX + FP32 -> FP32
FPXX + FP64 -> FP64

While for libunwind, we should save/restore all of FPRs. If we use FPXX,
we can only save/restore a common subset of FPRs, instead of superset.

If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are
FP32.

So if the compiler is FPXX, which is the default value of most
toolchain, let's switch it to FP64.

Co-authored-by: YunQiang Su 
(cherry picked from commit 4520b478d2512b0f39764e0464dcb4cb961845b5)
---
 libunwind/CMakeLists.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index bb1b052f61d875..806d5a783ec39c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -96,6 +97,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -179,6 +194,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

___
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] [libunwind] PR for llvm/llvm-project#81084 (PR #81085)

2024-02-07 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81085
___
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] [libunwind] PR for llvm/llvm-project#81084 (PR #81085)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/81085
___
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] [libunwind] PR for llvm/llvm-project#81084 (PR #81085)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: None (llvmbot)


Changes

resolves llvm/llvm-project#81084

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


1 Files Affected:

- (modified) libunwind/CMakeLists.txt (+19) 


``diff
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index bb1b052f61d875..806d5a783ec39c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH 
"${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
 "Specify path to libc++ source.")
 
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 
#===
 # Setup CMake Options
@@ -96,6 +97,20 @@ endif()
 option(LIBUNWIND_HIDE_SYMBOLS
   "Do not export any symbols from the static library." 
${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
 
+# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
+# 
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
+check_symbol_exists(__mips_hard_float "" __MIPSHF)
+check_symbol_exists(_ABIO32 "" __MIPS_O32)
+if (__MIPSHF AND __MIPS_O32)
+  file(WRITE 
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+"#if __mips_fpr != 0\n"
+"# error\n"
+"#endif\n")
+  try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
+${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
+CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
+endif()
+
 
#===
 # Configure System
 
#===
@@ -179,6 +194,10 @@ if (WIN32)
   add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
 endif()
 
+if (MIPS_FPABI_FPXX)
+  add_compile_flags(-mfp64)
+endif()
+
 # Get feature flags.
 # Exceptions
 # Catches C++ exceptions only and tells the compiler to assume that extern C

``




https://github.com/llvm/llvm-project/pull/81085
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81051


___
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] [libunwind] PR for llvm/llvm-project#81084 (PR #81085)

2024-02-07 Thread Fangrui Song via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/81085
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81051

>From a3cb7002be9d7efe9f7678911da9dd68b561b785 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Wed, 7 Feb 2024 22:18:50 -0800
Subject: [PATCH] fixup

---
 llvm/include/llvm/ProfileData/InstrProf.h| 11 +
 llvm/lib/ProfileData/InstrProf.cpp   | 42 ++--
 llvm/tools/llvm-profdata/llvm-profdata.cpp   |  2 +-
 llvm/unittests/ProfileData/InstrProfTest.cpp | 10 ++---
 4 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index d5d3c7f6b4b34..6e799cf8aa273 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -198,18 +198,9 @@ std::string getPGOFuncName(StringRef RawFuncName,
 /// called from LTO optimization passes.
 std::string getIRPGOFuncName(const Function &F, bool InLTO = false);
 
-/// Returns the PGO object name. This function has some special handling
-/// when called in LTO optimization:
-/// - In LTO mode, returns the name in `PGONameMetadata` if exists, otherwise
-/// returns the IRPGO name as if the GO has non-local linkage.
-/// - In non-LTO mode, returns the IRPGO name as it is.
-/// More rationale in the comment of function implementation.
-std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO = false,
-   MDNode *PGONameMetadata = nullptr);
-
 /// \return the filename and the function name parsed from the output of
 /// \c getIRPGOFuncName()
-std::pair getParsedIRPGOFuncName(StringRef 
IRPGOFuncName);
+std::pair getParsedIRPGOName(StringRef IRPGOName);
 
 /// Return the name of the global variable used to store a function
 /// name in PGO instrumentation. \c FuncName is the IRPGO function name
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 3b05faf0cc5d3..c280454fdeb1e 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -325,20 +325,21 @@ static std::optional 
lookupPGONameFromMetadata(MDNode *MD) {
   return {};
 }
 
-std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO,
-   MDNode *PGONameMetadata) {
-  // The following only applies when calling in
-  // LTO passes (when \c InLTO is true): LTO's internalization privatizes many
-  // global linkage symbols. This happens after value profile annotation, but
-  // those internal linkage functions should not have a source prefix.
-  // Additionally, for ThinLTO mode, exported internal functions are promoted
-  // and renamed. We need to ensure that the original internal PGO name is
-  // used when computing the GUID that is compared against the profiled GUIDs.
-  // To differentiate compiler generated internal symbols from original ones,
-  // PGOFuncName meta data are created and attached to the original internal
-  // symbols in the value profile annotation step
-  // (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the 
meta
-  // data, its original linkage must be non-internal.
+// Returns the PGO object name. This function has some special handling
+// when called in LTO optimization. The following only applies when calling in
+// LTO passes (when \c InLTO is true): LTO's internalization privatizes many
+// global linkage symbols. This happens after value profile annotation, but
+// those internal linkage functions should not have a source prefix.
+// Additionally, for ThinLTO mode, exported internal functions are promoted
+// and renamed. We need to ensure that the original internal PGO name is
+// used when computing the GUID that is compared against the profiled GUIDs.
+// To differentiate compiler generated internal symbols from original ones,
+// PGOFuncName meta data are created and attached to the original internal
+// symbols in the value profile annotation step
+// (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta
+// data, its original linkage must be non-internal.
+static std::string getIRPGOObjectName(const GlobalObject &GO, bool InLTO,
+  MDNode *PGONameMetadata) {
   if (!InLTO) {
 auto FileName = getStrippedSourceFileName(GO);
 return getIRPGONameForGlobalObject(GO, GO.getLinkage(), FileName);
@@ -390,13 +391,12 @@ std::string getPGOName(const GlobalVariable &V, bool 
InLTO) {
   return getIRPGOObjectName(V, InLTO, nullptr /* PGONameMetadata */);
 }
 
-// See getIRPGOFuncName() for a discription of the format.
-std::pair
-getParsedIRPGOFuncName(StringRef IRPGOFuncName) {
-  auto [FileName, FuncName] = IRPGOFuncName.split(';');
-  if (FuncName.empty())
-return std::make_pair(StringRef(), IRPGOFuncName);
-  return std::make_pair(FileName, FuncName);
+// See getIRPGOObjectName() for a discription of the format.
+std::pair getParsedIRPGOName(StringRef IRPGOName) {
+  auto [FileName, MangledName] = IRPGOName.split(kGl

[llvm-branch-commits] [llvm] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-07 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81051

>From 58f8fdbc9d2862a2579aece6c313bd19b4329e34 Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Wed, 7 Feb 2024 23:07:36 -0800
Subject: [PATCH] [InstrProf] Add vtables with type metadata into symtab to
 look it up with GUID

---
 llvm/include/llvm/ProfileData/InstrProf.h| 19 
 llvm/lib/ProfileData/InstrProf.cpp   | 94 ++--
 llvm/unittests/ProfileData/InstrProfTest.cpp | 47 ++
 3 files changed, 132 insertions(+), 28 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 53108a093bf4d..6e799cf8aa273 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -487,8 +487,25 @@ class InstrProfSymtab {
 return "** External Symbol **";
   }
 
+  // Returns the canonical name of the given PGOName by stripping the names
+  // suffixes that begins with ".". If MayHaveUniqueSuffix is true, ".__uniq."
+  // suffix is kept in the canonical name.
+  StringRef getCanonicalName(StringRef PGOName, bool MayHaveUniqueSuffix);
+
+  // Add the function into the symbol table, by creating the following
+  // map entries:
+  // - 
+  // - 
+  // - 
+  // - 
+  // - (instrprof_error::malformed,
@@ -665,6 +683,7 @@ void InstrProfSymtab::finalizeSymtab() {
   if (Sorted)
 return;
   llvm::sort(MD5NameMap, less_first());
+  llvm::sort(MD5VTableMap, less_first());
   llvm::sort(MD5FuncMap, less_first());
   llvm::sort(AddrToMD5Map, less_first());
   AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 9ebcba10c860f..edd6bf2c2971d 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -480,7 +480,9 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
 Types.clear();
 G.getMetadata(LLVMContext::MD_type, Types);
 if (!Types.empty()) {
-  MD5VTableMap.emplace_back(G.getGUID(), &G);
+  if (Error E = addVTableWithName(
+  G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+return E;
 }
   }
   Sorted = false;
@@ -488,6 +490,30 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+ StringRef VTablePGOName) {
+  if (Error E = addVTableName(VTablePGOName))
+return E;
+
+  MD5VTableMap.emplace_back(GlobalValue::getGUID(VTablePGOName), &VTable);
+
+  // NOTE: `-funique-internal-linkage-names` doesn't uniqufy vtables, so no
+  // need to check ".__uniq."
+
+  // If a local-linkage vtable is promoted to have external linkage in ThinLTO,
+  // it will have `.llvm.` in its name. Use the name before externalization.
+  StringRef CanonicalName =
+  getCanonicalName(VTablePGOName, /* MayHaveUniqueSuffix= */ false);
+  if (CanonicalName != VTablePGOName) {
+if (Error E = addVTableName(CanonicalName))
+  return E;
+
+MD5VTableMap.emplace_back(GlobalValue::getGUID(CanonicalName), &VTable);
+  }
+
+  return Error::success();
+}
+
 /// \c NameStrings is a string composed of one of more possibly encoded
 /// sub-strings. The substrings are separated by 0 or more zero bytes. This
 /// method decodes the string and calls `NameCallback` for each substring.
@@ -560,35 +586,50 @@ Error 
InstrProfSymtab::initVTableNamesFromCompressedStrings(
   std::bind(&InstrProfSymtab::addVTableName, this, std::placeholders::_1));
 }
 
-Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
-  if (Error E = addFuncName(PGOFuncName))
-return E;
-  MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
+StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName,
+bool MayHaveUniqueSuffix) {
+  size_t pos = 0;
   // In ThinLTO, local function may have been promoted to global and have
   // suffix ".llvm." added to the function name. We need to add the
   // stripped function name to the symbol table so that we can find a match
   // from profile.
   //
-  // We may have other suffixes similar as ".llvm." which are needed to
-  // be stripped before the matching, but ".__uniq." suffix which is used
-  // to differentiate internal linkage functions in different modules
-  // should be kept. Now this is the only suffix with the pattern ".xxx"
-  // which is kept before matching.
-  const std::string UniqSuffix = ".__uniq.";
-  auto pos = PGOFuncName.find(UniqSuffix);
-  // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
-  // search '.' from the beginning.
-  if (pos != std::string::npos)
-pos += UniqSuffix.length();
-  else
-pos = 0;
-  pos = PGOFuncName.find('.', pos);
-  if (pos != std::string::npos && pos != 0) {
-StringRef OtherFuncName = PGOFuncName.substr(0,

[llvm-branch-commits] [clang] PR for llvm/llvm-project#80628 (PR #81096)

2024-02-07 Thread via llvm-branch-commits

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

resolves llvm/llvm-project#80628

>From 6ca7c502d1e196603d838950909b00734319280c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 7 Feb 2024 21:35:43 -0800
Subject: [PATCH] [clang-format] Fix a regression in dumping the config
 (#80628)

Commit d813af73f70f addressed a regression introduced by commit
3791b3fca6ea
but caused `clang-format -dump-config` to "hang".

This patch reverts changes to ClangFormat.cpp by both commits and
reworks the cleanup.

Fixes #80621.

(cherry picked from commit 8f6e13e6da84510c8321717860fd506e12118514)
---
 clang/test/Format/dump-config-objc-stdin.m |  3 ++
 clang/test/Format/verbose.cpp  | 10 +
 clang/tools/clang-format/ClangFormat.cpp   | 49 +++---
 3 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/clang/test/Format/dump-config-objc-stdin.m 
b/clang/test/Format/dump-config-objc-stdin.m
index b22ff7b3328ca..d81711a84d79b 100644
--- a/clang/test/Format/dump-config-objc-stdin.m
+++ b/clang/test/Format/dump-config-objc-stdin.m
@@ -1,5 +1,8 @@
+// RUN: clang-format -assume-filename=foo.m -dump-config | FileCheck %s
+
 // RUN: clang-format -dump-config - < %s | FileCheck %s
 
 // CHECK: Language: ObjC
+
 @interface Foo
 @end
diff --git a/clang/test/Format/verbose.cpp b/clang/test/Format/verbose.cpp
index dd625e3f67e55..4ab03d8f62aef 100644
--- a/clang/test/Format/verbose.cpp
+++ b/clang/test/Format/verbose.cpp
@@ -1,12 +1,6 @@
-// RUN: clang-format %s  2> %t.stderr
+// RUN: clang-format -verbose 2> %t.stderr
 // RUN: not grep "Formatting" %t.stderr
-// RUN: clang-format %s -verbose 2> %t.stderr
-// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
-// RUN: clang-format %s -verbose=false 2> %t.stderr
-// RUN: not grep "Formatting" %t.stderr
-
-int a;
-// RUN: clang-format %s  2> %t.stderr
+// RUN: clang-format %s 2> %t.stderr
 // RUN: not grep "Formatting" %t.stderr
 // RUN: clang-format %s -verbose 2> %t.stderr
 // RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 5ee6092bb9bb7..e122cea50f726 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -399,7 +399,8 @@ class ClangFormatDiagConsumer : public DiagnosticConsumer {
 };
 
 // Returns true on error.
-static bool format(StringRef FileName, bool IsSTDIN) {
+static bool format(StringRef FileName) {
+  const bool IsSTDIN = FileName == "-";
   if (!OutputXML && Inplace && IsSTDIN) {
 errs() << "error: cannot use -i when reading from stdin.\n";
 return false;
@@ -545,24 +546,25 @@ static void PrintVersion(raw_ostream &OS) {
 }
 
 // Dump the configuration.
-static int dumpConfig(bool IsSTDIN) {
+static int dumpConfig() {
   std::unique_ptr Code;
-
-  // `FileNames` must have at least "-" in it even if no file was specified.
-  assert(!FileNames.empty());
-
-  // Read in the code in case the filename alone isn't enough to detect the
-  // language.
-  ErrorOr> CodeOrErr =
-  MemoryBuffer::getFileOrSTDIN(FileNames[0]);
-  if (std::error_code EC = CodeOrErr.getError()) {
-llvm::errs() << EC.message() << "\n";
-return 1;
+  // We can't read the code to detect the language if there's no file name.
+  if (!FileNames.empty()) {
+// Read in the code in case the filename alone isn't enough to detect the
+// language.
+ErrorOr> CodeOrErr =
+MemoryBuffer::getFileOrSTDIN(FileNames[0]);
+if (std::error_code EC = CodeOrErr.getError()) {
+  llvm::errs() << EC.message() << "\n";
+  return 1;
+}
+Code = std::move(CodeOrErr.get());
   }
-  Code = std::move(CodeOrErr.get());
-
   llvm::Expected FormatStyle =
-  clang::format::getStyle(Style, IsSTDIN ? AssumeFileName : FileNames[0],
+  clang::format::getStyle(Style,
+  FileNames.empty() || FileNames[0] == "-"
+  ? AssumeFileName
+  : FileNames[0],
   FallbackStyle, Code ? Code->getBuffer() : "");
   if (!FormatStyle) {
 llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
@@ -682,11 +684,8 @@ int main(int argc, const char **argv) {
 return 0;
   }
 
-  if (FileNames.empty())
-FileNames.push_back("-");
-
   if (DumpConfig)
-return dumpConfig(FileNames[0] == "-");
+return dumpConfig();
 
   if (!Files.empty()) {
 std::ifstream ExternalFileOfFiles{std::string(Files)};
@@ -699,7 +698,10 @@ int main(int argc, const char **argv) {
 errs() << "Clang-formating " << LineNo << " files\n";
   }
 
-  if (FileNames.size() != 1 &&
+  if (FileNames.empty())
+return clang::format::format("-");
+
+  if (FileNames.size() > 1 &&
   (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
 errs() << "error: -offset, -length and -lines can only be used for "
   "single fi

[llvm-branch-commits] [clang] PR for llvm/llvm-project#80628 (PR #81096)

2024-02-07 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81096
___
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] PR for llvm/llvm-project#80628 (PR #81096)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/81096
___
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] PR for llvm/llvm-project#80628 (PR #81096)

2024-02-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (llvmbot)


Changes

resolves llvm/llvm-project#80628

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


3 Files Affected:

- (modified) clang/test/Format/dump-config-objc-stdin.m (+3) 
- (modified) clang/test/Format/verbose.cpp (+2-8) 
- (modified) clang/tools/clang-format/ClangFormat.cpp (+25-24) 


``diff
diff --git a/clang/test/Format/dump-config-objc-stdin.m 
b/clang/test/Format/dump-config-objc-stdin.m
index b22ff7b3328caa..d81711a84d79bf 100644
--- a/clang/test/Format/dump-config-objc-stdin.m
+++ b/clang/test/Format/dump-config-objc-stdin.m
@@ -1,5 +1,8 @@
+// RUN: clang-format -assume-filename=foo.m -dump-config | FileCheck %s
+
 // RUN: clang-format -dump-config - < %s | FileCheck %s
 
 // CHECK: Language: ObjC
+
 @interface Foo
 @end
diff --git a/clang/test/Format/verbose.cpp b/clang/test/Format/verbose.cpp
index dd625e3f67e55d..4ab03d8f62aefc 100644
--- a/clang/test/Format/verbose.cpp
+++ b/clang/test/Format/verbose.cpp
@@ -1,12 +1,6 @@
-// RUN: clang-format %s  2> %t.stderr
+// RUN: clang-format -verbose 2> %t.stderr
 // RUN: not grep "Formatting" %t.stderr
-// RUN: clang-format %s -verbose 2> %t.stderr
-// RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
-// RUN: clang-format %s -verbose=false 2> %t.stderr
-// RUN: not grep "Formatting" %t.stderr
-
-int a;
-// RUN: clang-format %s  2> %t.stderr
+// RUN: clang-format %s 2> %t.stderr
 // RUN: not grep "Formatting" %t.stderr
 // RUN: clang-format %s -verbose 2> %t.stderr
 // RUN: grep -E "Formatting (.*)verbose.cpp(.*)" %t.stderr
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 5ee6092bb9bb7f..e122cea50f7268 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -399,7 +399,8 @@ class ClangFormatDiagConsumer : public DiagnosticConsumer {
 };
 
 // Returns true on error.
-static bool format(StringRef FileName, bool IsSTDIN) {
+static bool format(StringRef FileName) {
+  const bool IsSTDIN = FileName == "-";
   if (!OutputXML && Inplace && IsSTDIN) {
 errs() << "error: cannot use -i when reading from stdin.\n";
 return false;
@@ -545,24 +546,25 @@ static void PrintVersion(raw_ostream &OS) {
 }
 
 // Dump the configuration.
-static int dumpConfig(bool IsSTDIN) {
+static int dumpConfig() {
   std::unique_ptr Code;
-
-  // `FileNames` must have at least "-" in it even if no file was specified.
-  assert(!FileNames.empty());
-
-  // Read in the code in case the filename alone isn't enough to detect the
-  // language.
-  ErrorOr> CodeOrErr =
-  MemoryBuffer::getFileOrSTDIN(FileNames[0]);
-  if (std::error_code EC = CodeOrErr.getError()) {
-llvm::errs() << EC.message() << "\n";
-return 1;
+  // We can't read the code to detect the language if there's no file name.
+  if (!FileNames.empty()) {
+// Read in the code in case the filename alone isn't enough to detect the
+// language.
+ErrorOr> CodeOrErr =
+MemoryBuffer::getFileOrSTDIN(FileNames[0]);
+if (std::error_code EC = CodeOrErr.getError()) {
+  llvm::errs() << EC.message() << "\n";
+  return 1;
+}
+Code = std::move(CodeOrErr.get());
   }
-  Code = std::move(CodeOrErr.get());
-
   llvm::Expected FormatStyle =
-  clang::format::getStyle(Style, IsSTDIN ? AssumeFileName : FileNames[0],
+  clang::format::getStyle(Style,
+  FileNames.empty() || FileNames[0] == "-"
+  ? AssumeFileName
+  : FileNames[0],
   FallbackStyle, Code ? Code->getBuffer() : "");
   if (!FormatStyle) {
 llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
@@ -682,11 +684,8 @@ int main(int argc, const char **argv) {
 return 0;
   }
 
-  if (FileNames.empty())
-FileNames.push_back("-");
-
   if (DumpConfig)
-return dumpConfig(FileNames[0] == "-");
+return dumpConfig();
 
   if (!Files.empty()) {
 std::ifstream ExternalFileOfFiles{std::string(Files)};
@@ -699,7 +698,10 @@ int main(int argc, const char **argv) {
 errs() << "Clang-formating " << LineNo << " files\n";
   }
 
-  if (FileNames.size() != 1 &&
+  if (FileNames.empty())
+return clang::format::format("-");
+
+  if (FileNames.size() > 1 &&
   (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
 errs() << "error: -offset, -length and -lines can only be used for "
   "single file.\n";
@@ -709,14 +711,13 @@ int main(int argc, const char **argv) {
   unsigned FileNo = 1;
   bool Error = false;
   for (const auto &FileName : FileNames) {
-const bool IsSTDIN = FileName == "-";
-if (!IsSTDIN && isIgnored(FileName))
+if (isIgnored(FileName))
   continue;
 if (Verbose) {
   errs() << "Formatting [" << FileNo++ << "/" << FileNames.size() << "] "
  << FileName << "\n";
 }
-Error |= cla