diff options
author | Teresa Johnson <tejohnson@google.com> | 2023-05-06 07:14:56 -0700 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2023-05-08 08:02:21 -0700 |
commit | 176889868024d98db032842bc47b416997d9e349 (patch) | |
tree | 7468cc29a11423938b46cc00c87bf38a460baaa3 /llvm/test/ThinLTO | |
parent | efd0b42171e9b3536d02becbbf3738ded2adbcb3 (diff) | |
download | llvm-176889868024d98db032842bc47b416997d9e349.zip llvm-176889868024d98db032842bc47b416997d9e349.tar.gz llvm-176889868024d98db032842bc47b416997d9e349.tar.bz2 |
[MemProf] Control availability of hot/cold operator new from LTO link
Adds an LTO option to indicate that whether we are linking with an
allocator that supports hot/cold operator new interfaces. If not,
at the start of the LTO backends any existing memprof hot/cold
attributes are removed from the IR, and we also remove memprof metadata
so that post-LTO inlining doesn't add any new attributes.
This is done via setting a new flag in the module summary index. It is
important to communicate via the index to the LTO backends so that
distributed ThinLTO handles this correctly, as they are invoked by
separate clang processes and the combined index is how we communicate
information from the LTO link. Specifically, for distributed ThinLTO the
LTO related processes look like:
```
# Thin link:
$ lld --thinlto-index-only obj1.o ... objN.o -llib ...
# ThinLTO backends:
$ clang -x ir obj1.o -fthinlto-index=obj1.o.thinlto.bc -c -O2
...
$ clang -x ir objN.o -fthinlto-index=objN.o.thinlto.bc -c -O2
```
It is during the thin link (lld --thinlto-index-only) that we have
visibility into linker dependences and want to be able to pass the new
option via -Wl,-supports-hot-cold-new. This will be recorded in the
summary indexes created for the distributed backend processes
(*.thinlto.bc) and queried from there, so that we don't need to know
during those individual clang backends what allocation library was
linked. Since in-process ThinLTO and regular LTO also use a combined
index, for consistency we query the flag out of the index in all LTO
backends.
Additionally, when the LTO option is disabled, exit early from the
MemProfContextDisambiguation handling performed during LTO, as this is
unnecessary.
Depends on D149117 and D149192.
Differential Revision: https://reviews.llvm.org/D149215
Diffstat (limited to 'llvm/test/ThinLTO')
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-basic.ll | 2 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll | 2 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll | 1 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll | 2 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-indirectcall.ll | 2 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-inlined.ll | 2 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-inlined2.ll | 1 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll | 57 |
8 files changed, 69 insertions, 0 deletions
diff --git a/llvm/test/ThinLTO/X86/memprof-basic.ll b/llvm/test/ThinLTO/X86/memprof-basic.ll index ac3119f..0d46683 100644 --- a/llvm/test/ThinLTO/X86/memprof-basic.ll +++ b/llvm/test/ThinLTO/X86/memprof-basic.ll @@ -36,6 +36,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ ; RUN: -r=%t.o,sleep, \ @@ -55,6 +56,7 @@ ;; Try again but with distributed ThinLTO ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -thinlto-distributed-indexes \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ diff --git a/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll b/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll index 55aab192..5bc2f30 100644 --- a/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll +++ b/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll @@ -58,6 +58,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ ; RUN: -r=%t.o,sleep, \ @@ -78,6 +79,7 @@ ;; Try again but with distributed ThinLTO ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -thinlto-distributed-indexes \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ diff --git a/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll b/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll index b77df88..13d2036 100644 --- a/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll +++ b/llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll @@ -95,6 +95,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_Z1Db,plx \ ; RUN: -r=%t.o,_Z1Cb,plx \ diff --git a/llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll b/llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll index 25e974e..9a72ae4 100644 --- a/llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll +++ b/llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll @@ -51,6 +51,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ ; RUN: -r=%t.o,sleep, \ @@ -65,6 +66,7 @@ ;; Try again but with distributed ThinLTO ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -thinlto-distributed-indexes \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ diff --git a/llvm/test/ThinLTO/X86/memprof-indirectcall.ll b/llvm/test/ThinLTO/X86/memprof-indirectcall.ll index 8b9b64f..7627395 100644 --- a/llvm/test/ThinLTO/X86/memprof-indirectcall.ll +++ b/llvm/test/ThinLTO/X86/memprof-indirectcall.ll @@ -56,6 +56,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,sleep, \ ; RUN: -r=%t.o,_Znam, \ @@ -78,6 +79,7 @@ ;; Try again but with distributed ThinLTO ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -thinlto-distributed-indexes \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ diff --git a/llvm/test/ThinLTO/X86/memprof-inlined.ll b/llvm/test/ThinLTO/X86/memprof-inlined.ll index bc537a5..feb9c94 100644 --- a/llvm/test/ThinLTO/X86/memprof-inlined.ll +++ b/llvm/test/ThinLTO/X86/memprof-inlined.ll @@ -46,6 +46,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ ; RUN: -r=%t.o,sleep, \ @@ -67,6 +68,7 @@ ;; Try again but with distributed ThinLTO ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -thinlto-distributed-indexes \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_ZdaPv, \ diff --git a/llvm/test/ThinLTO/X86/memprof-inlined2.ll b/llvm/test/ThinLTO/X86/memprof-inlined2.ll index 02baf9f..9f67849 100644 --- a/llvm/test/ThinLTO/X86/memprof-inlined2.ll +++ b/llvm/test/ThinLTO/X86/memprof-inlined2.ll @@ -44,6 +44,7 @@ ; RUN: opt -thinlto-bc %s >%t.o ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ ; RUN: -r=%t.o,main,plx \ ; RUN: -r=%t.o,_Z3barv,plx \ ; RUN: -r=%t.o,_Z3bazv,plx \ diff --git a/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll b/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll new file mode 100644 index 0000000..9e69377 --- /dev/null +++ b/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll @@ -0,0 +1,57 @@ +;; Test that passing -supports-hot-cold-new to the LTO link allows context +;; disambiguation to proceed, and also prevents memprof metadata and attributes +;; from being removed from the LTO backend, and vice versa without passing +;; -supports-hot-cold-new. + +;; First check with -supports-hot-cold-new. +; RUN: opt -thinlto-bc %s >%t.o +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -supports-hot-cold-new \ +; RUN: -r=%t.o,main,plx \ +; RUN: -r=%t.o,_Znam, \ +; RUN: -memprof-dump-ccg \ +; RUN: -save-temps \ +; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP +; DUMP: Callsite Context Graph: + +; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s --check-prefix=IR +; IR: !memprof {{.*}} !callsite +; IR: "memprof"="cold" + +;; Next check without -supports-hot-cold-new, we should not perform +;; context disambiguation, and we should strip memprof metadata and +;; attributes before optimization. +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ +; RUN: -r=%t.o,main,plx \ +; RUN: -r=%t.o,_Znam, \ +; RUN: -memprof-dump-ccg \ +; RUN: -save-temps \ +; RUN: -o %t.out 2>&1 | FileCheck %s --allow-empty \ +; RUN: --implicit-check-not "Callsite Context Graph:" + +; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s \ +; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \ +; RUN: --implicit-check-not "memprof"="cold" + +source_filename = "memprof-supports-hot-cold-new.ll" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define i32 @main() #0 { +entry: + %call = call ptr @_Znam(i64 0), !memprof !0, !callsite !5 + %call2 = call ptr @_Znam(i64 0) #1 + ret i32 0 +} + +declare ptr @_Znam(i64) + +attributes #0 = { noinline optnone } +attributes #1 = { "memprof"="cold" } + +!0 = !{!1, !3} +!1 = !{!2, !"notcold"} +!2 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414} +!3 = !{!4, !"cold"} +!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178} +!5 = !{i64 9086428284934609951} |