-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[AMDGPU][SplitModule] Handle !callees metadata #108802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -482,6 +482,29 @@ void SplitGraph::Node::visitAllDependencies( | |
} | ||
} | ||
|
||
/// Checks if \p I has MD_callees and if it does, parse it and put the function | ||
/// in \p Callees. | ||
/// | ||
/// \returns true if there was metadata and it was parsed correctly. false if | ||
/// there was no MD or if it contained unknown entries and parsing failed. | ||
/// If this returns false, \p Callees will contain incomplete information | ||
/// and must not be used. | ||
static bool handleCalleesMD(const Instruction &I, | ||
SetVector<Function *> &Callees) { | ||
auto *MD = I.getMetadata(LLVMContext::MD_callees); | ||
if (!MD) | ||
return false; | ||
|
||
for (const auto &Op : MD->operands()) { | ||
Function *Callee = mdconst::extract_or_null<Function>(Op); | ||
if (!Callee) | ||
return false; | ||
jmmartinez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Callees.insert(Callee); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void SplitGraph::buildGraph(CallGraph &CG) { | ||
SplitModuleTimer SMT("buildGraph", "graph construction"); | ||
LLVM_DEBUG( | ||
|
@@ -519,28 +542,38 @@ void SplitGraph::buildGraph(CallGraph &CG) { | |
Fn.printAsOperand(dbgs()); | ||
dbgs() << " - analyzing function\n"); | ||
|
||
bool HasIndirectCall = false; | ||
SetVector<Function *> KnownCallees; | ||
bool HasUnknownIndirectCall = false; | ||
for (const auto &Inst : instructions(Fn)) { | ||
// look at all calls without a direct callee. | ||
if (const auto *CB = dyn_cast<CallBase>(&Inst); | ||
CB && !CB->getCalledFunction()) { | ||
// inline assembly can be ignored, unless InlineAsmIsIndirectCall is | ||
// true. | ||
if (CB->isInlineAsm()) { | ||
LLVM_DEBUG(dbgs() << " found inline assembly\n"); | ||
continue; | ||
} | ||
|
||
// everything else is handled conservatively. | ||
HasIndirectCall = true; | ||
break; | ||
const auto *CB = dyn_cast<CallBase>(&Inst); | ||
if (!CB || CB->getCalledFunction()) | ||
continue; | ||
|
||
// inline assembly can be ignored, unless InlineAsmIsIndirectCall is | ||
// true. | ||
if (CB->isInlineAsm()) { | ||
LLVM_DEBUG(dbgs() << " found inline assembly\n"); | ||
continue; | ||
} | ||
|
||
if (handleCalleesMD(Inst, KnownCallees)) | ||
continue; | ||
// If we failed to parse any !callees MD, or some was missing, | ||
// the entire KnownCallees list is now unreliable. | ||
Comment on lines
+562
to
+563
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like the verifier is missing validation on callees entries? You shouldn't really have to worry about parsing it |
||
KnownCallees.clear(); | ||
|
||
// Everything else is handled conservatively. If we fall into the | ||
// conservative case don't bother analyzing further. | ||
HasUnknownIndirectCall = true; | ||
break; | ||
} | ||
|
||
if (HasIndirectCall) { | ||
if (HasUnknownIndirectCall) { | ||
LLVM_DEBUG(dbgs() << " indirect call found\n"); | ||
FnsWithIndirectCalls.push_back(&Fn); | ||
} | ||
} else if (!KnownCallees.empty()) | ||
DirectCallees.insert(KnownCallees.begin(), KnownCallees.end()); | ||
} | ||
|
||
Node &N = getNode(Cache, Fn); | ||
|
69 changes: 69 additions & 0 deletions
69
llvm/test/tools/llvm-split/AMDGPU/kernels-dependency-indirect-callee-md.ll
This file contains hidden or 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,69 @@ | ||
; RUN: sed -s 's/_MD_/, !callees !{ptr @CallCandidate0}/' %s | llvm-split -o %t -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 | ||
|
||
; RUN: sed -s 's/_MD_//g' %s | llvm-split -o %t-nomd -j 3 -mtriple amdgcn-amd-amdhsa | ||
; RUN: llvm-dis -o - %t-nomd0 | FileCheck --check-prefix=CHECK-NOMD0 --implicit-check-not=define %s | ||
; RUN: llvm-dis -o - %t-nomd1 | FileCheck --check-prefix=CHECK-NOMD1 --implicit-check-not=define %s | ||
; RUN: llvm-dis -o - %t-nomd2 | FileCheck --check-prefix=CHECK-NOMD2 --implicit-check-not=define %s | ||
|
||
; CHECK0: define internal void @HelperC | ||
; CHECK0: define amdgpu_kernel void @C | ||
|
||
; CHECK1: define hidden void @CallCandidate1 | ||
; CHECK1: define internal void @HelperB | ||
; CHECK1: define amdgpu_kernel void @B | ||
|
||
; CHECK2: define internal void @HelperA | ||
; CHECK2: define hidden void @CallCandidate0 | ||
; CHECK2: define amdgpu_kernel void @A | ||
|
||
; CHECK-NOMD0: define internal void @HelperC | ||
; CHECK-NOMD0: define amdgpu_kernel void @C | ||
|
||
; CHECK-NOMD1: define internal void @HelperB | ||
; CHECK-NOMD1: define amdgpu_kernel void @B | ||
|
||
; CHECK-NOMD2: define internal void @HelperA | ||
; CHECK-NOMD2: define hidden void @CallCandidate0 | ||
; CHECK-NOMD2: define hidden void @CallCandidate1 | ||
; CHECK-NOMD2: define amdgpu_kernel void @A | ||
|
||
@addrthief = global [2 x ptr] [ptr @CallCandidate0, ptr @CallCandidate1] | ||
|
||
define internal void @HelperA(ptr %call) { | ||
call void %call() _MD_ | ||
ret void | ||
} | ||
|
||
define internal void @CallCandidate0() { | ||
ret void | ||
} | ||
|
||
define internal void @CallCandidate1() { | ||
ret void | ||
} | ||
|
||
define internal void @HelperB() { | ||
ret void | ||
} | ||
|
||
define internal void @HelperC() { | ||
ret void | ||
} | ||
|
||
define amdgpu_kernel void @A(ptr %call) { | ||
call void @HelperA(ptr %call) | ||
ret void | ||
} | ||
|
||
define amdgpu_kernel void @B() { | ||
call void @HelperB() | ||
ret void | ||
} | ||
|
||
define amdgpu_kernel void @C() { | ||
call void @HelperC() | ||
ret void | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still think the call graph analysis should be handling this
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it land as is or do you want me to try changing the CG first?
I'm not sure if that'd need a RFC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can start with it here, but I've always found it to be a flaw. It's also busted for the CGInSCC order with aliases (which I guess we're now less dependent on)