-
Notifications
You must be signed in to change notification settings - Fork 750
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
[ESIMD] Aggressively inline every function called by ESIMD kernel #3261
Changes from 5 commits
7ca0143
bdc5947
6a257fe
faf152a
10c0715
e11aaa2
2e1b1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
; RUN: opt -LowerESIMD -S < %s | FileCheck %s | ||
|
||
; This test checks that LowerESIMD pass sets the 'alwaysinline' | ||
; attribute for all the functions called from ESIMD kernels. | ||
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. There is no ESIMD specifics in the test, and LowerESIMD will add the attr to any non-kernel function it meets. Could you update the comment please? 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. I think there are still implicit ESIMD-specifics since we intend to run the LowerESIMD pass only on the ESIMD code. I fixed the comment. |
||
|
||
define spir_kernel void @EsimdKernel1() { | ||
; CHECK: @EsimdKernel1( | ||
; CHECK-NEXT: call void @foo() | ||
; CHECK-NEXT: call void @bar() | ||
call void @foo() | ||
call void @bar() | ||
ret void | ||
} | ||
|
||
define spir_kernel void @EsimdKernel2() { | ||
; CHECK: @EsimdKernel2( | ||
; CHECK-NEXT: call void @foobar() | ||
call void @foobar() | ||
ret void | ||
} | ||
|
||
define spir_func void @foo() { | ||
; CHECK: @foo() #[[ATTR:[0-9]+]] | ||
ret void | ||
} | ||
|
||
define spir_func void @bar() { | ||
; CHECK: @bar() #[[ATTR]] | ||
; CHECK-NEXT: call void @foobar | ||
call void @foobar() | ||
ret void | ||
} | ||
|
||
define spir_func void @foobar() { | ||
; CHECK: @foobar() #[[ATTR]] | ||
ret void | ||
} | ||
|
||
; CHECK: attributes #[[ATTR]] = { alwaysinline } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
#include "llvm/Support/SystemUtils.h" | ||
#include "llvm/Support/WithColor.h" | ||
#include "llvm/Transforms/IPO.h" | ||
#include "llvm/Transforms/IPO/AlwaysInliner.h" | ||
#include "llvm/Transforms/IPO/GlobalDCE.h" | ||
#include "llvm/Transforms/InstCombine/InstCombine.h" | ||
#include "llvm/Transforms/Scalar.h" | ||
|
@@ -668,40 +669,17 @@ static string_vector saveResultSymbolsLists(string_vector &ResSymbolsLists, | |
} \ | ||
} | ||
|
||
// Helper function for creating Inliner pass. | ||
// The approach is taken from opt tool. | ||
static Pass *createFunctionInliningPassHelper() { | ||
if (OptLevelO0) | ||
return createFunctionInliningPass(0, 0, false); | ||
|
||
if (OptLevelO1) | ||
return createFunctionInliningPass(1, 0, false); | ||
|
||
if (OptLevelO2) | ||
return createFunctionInliningPass(2, 0, false); | ||
|
||
if (OptLevelOs) | ||
return createFunctionInliningPass(2, 1, false); | ||
|
||
if (OptLevelOz) | ||
return createFunctionInliningPass(2, 2, false); | ||
|
||
if (OptLevelO3) | ||
return createFunctionInliningPass(3, 0, false); | ||
|
||
return createFunctionInliningPass(); | ||
} | ||
|
||
// When ESIMD code was separated from the regular SYCL code, | ||
// we can safely process ESIMD part. | ||
// TODO: support options like -debug-pass, -print-[before|after], and others | ||
static void LowerEsimdConstructs(Module &M) { | ||
legacy::PassManager MPM; | ||
MPM.add(createSYCLLowerESIMDPass()); | ||
if (!OptLevelO0) { | ||
// Inlining and SROA passes are required to make | ||
// ESIMD/accessor_gather_scatter.cpp test work. | ||
MPM.add(createFunctionInliningPassHelper()); | ||
// LowerESIMD pass sets 'alwaysinline' attribute to all the functions | ||
// in the call graph for every ESIMD kernel, which is later consumed | ||
// by AlwaysInliner pass. | ||
DenisBakhvalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MPM.add(createAlwaysInlinerLegacyPass()); | ||
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. @robertcox-github, is it a fair assumption, that there is no point in scheduling a regular inliner pass if we set |
||
MPM.add(createSROAPass()); | ||
} | ||
MPM.add(createESIMDLowerVecArgPass()); | ||
|
@@ -711,7 +689,7 @@ static void LowerEsimdConstructs(Module &M) { | |
MPM.add(createEarlyCSEPass(true)); | ||
MPM.add(createInstructionCombiningPass()); | ||
MPM.add(createDeadCodeEliminationPass()); | ||
MPM.add(createFunctionInliningPassHelper()); | ||
cmc-rep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// TODO: maybe remove some passes below that don't affect code quality | ||
MPM.add(createSROAPass()); | ||
MPM.add(createEarlyCSEPass(true)); | ||
MPM.add(createInstructionCombiningPass()); | ||
|
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.
I suggest to change the comment to explain why this is needed.
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.
Done.