-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AMDGPU][SplitModule] Allow non-kernels to be treated as roots (#95902)
I initially assumed only kernels could be roots, but that is wrong. A function with no callers also needs to be a root to ensure it is correctly handled. They're very rare because we usually internalize everything, and internal functions with no callers would be deleted. When they are present, we need to also consider their dependencies and act accordingly. Previously, we could put a function "by default" in P0, but it could call another function with internal linkage defined in another module which was of course incorrect. Fixes SWDEV-467695
- Loading branch information
Showing
7 changed files
with
294 additions
and
112 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
llvm/test/tools/llvm-split/AMDGPU/address-taken-externalize-with-call.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
llvm/test/tools/llvm-split/AMDGPU/debug-non-kernel-root.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; RUN: llvm-split -o %t %s -j 2 -mtriple amdgcn-amd-amdhsa -debug 2>&1 | FileCheck %s --implicit-check-not="[root]" | ||
; REQUIRES: asserts | ||
|
||
; func_3 is never directly called, it needs to be considered | ||
; as a root to handle this module correctly. | ||
|
||
; CHECK: [root] kernel_1 | ||
; CHECK-NEXT: [dependency] func_1 | ||
; CHECK-NEXT: [dependency] func_2 | ||
; CHECK-NEXT: [root] func_3 | ||
; CHECK-NEXT: [dependency] func_2 | ||
|
||
define amdgpu_kernel void @kernel_1() { | ||
entry: | ||
call void @func_1() | ||
ret void | ||
} | ||
|
||
define linkonce_odr hidden void @func_1() { | ||
entry: | ||
%call = call i32 @func_2() | ||
ret void | ||
} | ||
|
||
define linkonce_odr hidden i32 @func_2() #0 { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
define void @func_3() { | ||
entry: | ||
%call = call i32 @func_2() | ||
ret void | ||
} | ||
|
||
attributes #0 = { noinline optnone } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
llvm/test/tools/llvm-split/AMDGPU/non-kernels-dependencies.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
; RUN: llvm-split -o %t %s -j 3 -mtriple amdgcn-amd-amdhsa | ||
; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=CHECK0 --implicit-check-not=DEFINE %s | ||
; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=CHECK1 --implicit-check-not=DEFINE %s | ||
; RUN: llvm-dis -o - %t2 | FileCheck --check-prefix=CHECK2 --implicit-check-not=DEFINE %s | ||
|
||
; 3 functions with each their own dependencies should go into 3 | ||
; distinct partitions. | ||
|
||
; CHECK0: define void @C | ||
; CHECK0: define internal void @HelperC | ||
|
||
; CHECK1: define void @B | ||
; CHECK1: define internal void @HelperB | ||
|
||
; CHECK2: define void @A | ||
; CHECK2: define internal void @HelperA | ||
|
||
|
||
define void @A() { | ||
call void @HelperA() | ||
ret void | ||
} | ||
|
||
define internal void @HelperA() { | ||
ret void | ||
} | ||
|
||
define void @B() { | ||
call void @HelperB() | ||
ret void | ||
} | ||
|
||
define internal void @HelperB() { | ||
ret void | ||
} | ||
|
||
define void @C() { | ||
call void @HelperC() | ||
ret void | ||
} | ||
|
||
define internal void @HelperC() { | ||
ret void | ||
} |
72 changes: 72 additions & 0 deletions
72
llvm/test/tools/llvm-split/AMDGPU/non-kernels-dependency-indirect.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
; RUN: llvm-split -o %t %s -j 3 -mtriple amdgcn-amd-amdhsa | ||
; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=CHECK0 --implicit-check-not=DEFINE %s | ||
; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=CHECK1 --implicit-check-not=DEFINE %s | ||
; RUN: llvm-dis -o - %t2 | FileCheck --check-prefix=CHECK2 --implicit-check-not=DEFINE %s | ||
|
||
; We have 4 function: | ||
; - Each function has an internal helper | ||
; - @A and @B's helpers does an indirect call. | ||
; | ||
; For non-kernels, indirect calls shouldn't matter, so | ||
; @CallCandidate doesn't have to be in A/B's partition, unlike | ||
; in the corresponding tests for kernels where it has to. | ||
|
||
; CHECK0: define hidden void @HelperA | ||
; CHECK0: define hidden void @HelperB | ||
; CHECK0: define internal void @HelperC | ||
; CHECK0: define internal void @HelperD | ||
; CHECK0: define void @A | ||
; CHECK0: define void @B | ||
|
||
; CHECK1: define internal void @HelperD | ||
; CHECK1: define void @D | ||
|
||
; CHECK2: define hidden void @CallCandidate | ||
; CHECK2: define internal void @HelperC | ||
; CHECK2: define void @C | ||
|
||
@addrthief = global [3 x ptr] [ptr @HelperA, ptr @HelperB, ptr @CallCandidate] | ||
|
||
define internal void @HelperA(ptr %call) { | ||
call void %call() | ||
ret void | ||
} | ||
|
||
define internal void @HelperB(ptr %call) { | ||
call void @HelperC() | ||
call void %call() | ||
call void @HelperD() | ||
ret void | ||
} | ||
|
||
define internal void @CallCandidate() { | ||
ret void | ||
} | ||
|
||
define internal void @HelperC() { | ||
ret void | ||
} | ||
|
||
define internal void @HelperD() { | ||
ret void | ||
} | ||
|
||
define void @A(ptr %call) { | ||
call void @HelperA(ptr %call) | ||
ret void | ||
} | ||
|
||
define void @B(ptr %call) { | ||
call void @HelperB(ptr %call) | ||
ret void | ||
} | ||
|
||
define void @C() { | ||
call void @HelperC() | ||
ret void | ||
} | ||
|
||
define void @D() { | ||
call void @HelperD() | ||
ret void | ||
} |