Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
ThinOrFullLTOPhase) {
MPM.addPass(createModuleToFunctionPassAdaptor(
InferAddressSpacesPass(clang::targets::SPIR_GENERIC_AS)));
MPM.addPass(
createModuleToFunctionPassAdaptor(SYCLOptimizeBarriersPass()));
if (Level != OptimizationLevel::O0)
MPM.addPass(createModuleToFunctionPassAdaptor(
SYCLOptimizeBarriersPass()));
});
}

Expand Down
14 changes: 14 additions & 0 deletions clang/test/CodeGenSYCL/kernel-early-optimization-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// CHECK: InferFunctionAttrsPass
// CHECK: AlwaysInlinerPass
// CHECK: ModuleInlinerWrapperPass
// CHECK: SYCLOptimizeBarriersPass
// CHECK: ConstantMergePass
// CHECK: SYCLMutatePrintfAddrspacePass
// CHECK: SYCLPropagateAspectsUsagePass
Expand All @@ -22,4 +23,17 @@
//
// RUN: %clang_cc1 -O2 -fsycl-is-device -triple spir64-unknown-unknown %s -mdebug-pass Structure -emit-llvm -fno-sycl-early-optimizations -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-NOEARLYOPT
// CHECK-NOEARLYOPT-NOT: ConstantMergePass1
// CHECK-NOEARLYOPT-NOT: SYCLOptimizeBarriersPass
// CHECK-NOEARLYOPT: SYCLMutatePrintfAddrspacePass

// RUN: %clang_cc1 -O0 -fsycl-is-device -triple spir64-unknown-unknown %s -mdebug-pass Structure -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-O0
// CHECK-O0-NOT: SYCLOptimizeBarriersPass

template <typename name, typename Func>
void kernel(const Func &f) __attribute__((sycl_kernel)) {
f();
}

void bar() {
kernel<class MyKernel>([=]() {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently non-empty source code is required to make the pass run. @Fznamznon please comment if you are okay with this change or if I should separate the barrier case from this test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine in this file, I don't really get why it happens.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it really weird that the pass manager doesn't report this pass if the source is empty, however I'm not an expert in this. Can we simplify the code and explain why it is required, it is dummy anyway

Suggested change
template <typename name, typename Func>
void kernel(const Func &f) __attribute__((sycl_kernel)) {
f();
}
void bar() {
kernel<class MyKernel>([=]() {});
}
// Some passes don't run on empty code
__attribute__((sycl_device)) void bar() {
}

If a kernel is required please use https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/ContributeToDPCPP.md#dpc-clang-fe-tests .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied. So passes registered via registerOptimizerLastEPCallback are not being run fir the empty test. Passes registered like this are being run at the end of a normal pipeline via invokeOptimizerLastEPCallbacks and ... I haven't yet finished with the debugging, but it seems like it's module-size sensitive.

Loading