[llvm] Users/paschalis mpeis/bolt link fdata nolbr (PR #113157)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 05:02:56 PDT 2024


https://github.com/paschalis-mpeis created https://github.com/llvm/llvm-project/pull/113157

[BOLT] link_fdata support for hardcoded offsets in no-LBR
    
Allow using hardcoded offsets to blocks, eg:
```
// RUN: link_fdata --no-lbr ...
// FDATA: 1 foo 0 10
```
    
For LBR mode this was already supported. See for example:
- tail-duplication-complex.s

>From 55a40d3e50733de59a60cfe80f9a69ff6b8486cd Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 15 Oct 2024 09:51:52 +0100
Subject: [PATCH 1/2] link_fdata does not support hardcoded offsets in no-LBR
 mode

For example, the below fails as the script tries to match it with the
LBR mode:

```
// RUN: link_fdata --no-lbr ...
// FDATA: 1 foo 0 10
```
---
 bolt/test/AArch64/fdata-nolbr.s | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 bolt/test/AArch64/fdata-nolbr.s

diff --git a/bolt/test/AArch64/fdata-nolbr.s b/bolt/test/AArch64/fdata-nolbr.s
new file mode 100644
index 00000000000000..5bb655f0f94cbd
--- /dev/null
+++ b/bolt/test/AArch64/fdata-nolbr.s
@@ -0,0 +1,18 @@
+# Check that using link_fdata tool in non-lbr mode allows using hardcoded
+# addresses for basic block offsets.
+
+# REQUIRES: system-linux
+
+# RUN: %clang %cflags -o %t %s
+# RUN: %clang %s %cflags -Wl,-q -o %t
+# RUN: not link_fdata --no-lbr %s %t %t.fdata 2>&1 | FileCheck %s
+
+  .text
+  .globl  foo
+  .type foo, %function
+foo:
+# FDATA: 1 foo 0 10
+    ret
+
+# Currently does not work on non-lbr mode.
+# CHECK: AssertionError: ERROR: wrong format/whitespaces must be escaped

>From 3d5a9248256f0c4bc8aef3bcddf8caf29aaee608 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Tue, 15 Oct 2024 18:05:41 +0100
Subject: [PATCH 2/2] [BOLT] link_fdata support for hardcoded offsets in no-LBR

Allow using hardcoded offsets to blocks, eg:
```
// RUN: link_fdata --no-lbr ...
// FDATA: 1 foo 0 10
```

For LBR mode this was already supported. See for example:
- tail-duplication-complex.s
---
 bolt/test/AArch64/fdata-nolbr.s | 7 ++++---
 bolt/test/link_fdata.py         | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/bolt/test/AArch64/fdata-nolbr.s b/bolt/test/AArch64/fdata-nolbr.s
index 5bb655f0f94cbd..5d7c0a4014986e 100644
--- a/bolt/test/AArch64/fdata-nolbr.s
+++ b/bolt/test/AArch64/fdata-nolbr.s
@@ -5,7 +5,8 @@
 
 # RUN: %clang %cflags -o %t %s
 # RUN: %clang %s %cflags -Wl,-q -o %t
-# RUN: not link_fdata --no-lbr %s %t %t.fdata 2>&1 | FileCheck %s
+# RUN: link_fdata --no-lbr %s %t %t.fdata
+# RUN: cat %t.fdata | FileCheck %s
 
   .text
   .globl  foo
@@ -14,5 +15,5 @@ foo:
 # FDATA: 1 foo 0 10
     ret
 
-# Currently does not work on non-lbr mode.
-# CHECK: AssertionError: ERROR: wrong format/whitespaces must be escaped
+# CHECK: no_lbr
+# CHECK-NEXT: 1 foo 0 10
diff --git a/bolt/test/link_fdata.py b/bolt/test/link_fdata.py
index 3837e394ccc87b..613d58248bb052 100755
--- a/bolt/test/link_fdata.py
+++ b/bolt/test/link_fdata.py
@@ -58,7 +58,7 @@
         fdata_match = fdata_pat.match(profile_line)
         preagg_match = preagg_pat.match(profile_line)
         nolbr_match = nolbr_pat.match(profile_line)
-        if fdata_match:
+        if fdata_match and not (nolbr_match and args.no_lbr):
             src_dst, execnt, mispred = fdata_match.groups()
             # Split by whitespaces not preceded by a backslash (negative lookbehind)
             chunks = re.split(r"(?<!\\) +", src_dst)



More information about the llvm-commits mailing list