From ce9b7243279448c2e0691db548d05af871b16f22 Mon Sep 17 00:00:00 2001 From: Mikhail Lychkov Date: Thu, 13 Jan 2022 09:31:04 +0300 Subject: [PATCH 1/4] [SYCL][NewPM] Add SPIRITTAnnotations pass into optimization Add SPIRITTAnnotations pass into clang optimizations pipeline when using new Pass Manager. Signed-off-by: Mikhail Lychkov --- clang/lib/CodeGen/BackendUtil.cpp | 10 ++++++++++ .../test/CodeGenSYCL/kernel-simple-instrumentation.cpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 90db69b44f864..7e95e72316079 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1481,6 +1481,16 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(SYCLMutatePrintfAddrspacePass()); } + // Add SPIRITTAnnotations pass to the pass manager if + // -fsycl-instrument-device-code option was passed. This option can be used + // only with spir triple. + if (CodeGenOpts.SPIRITTAnnotations) { + if (!llvm::Triple(TheModule->getTargetTriple()).isSPIR()) + llvm::report_fatal_error( + "ITT annotations can only by added to a module with spir target"); + MPM.addPass(SPIRITTAnnotationsPass()); + } + // Add a verifier pass if requested. We don't have to do this if the action // requires code generation because there will already be a verifier pass in // the code-generation pipeline. diff --git a/clang/test/CodeGenSYCL/kernel-simple-instrumentation.cpp b/clang/test/CodeGenSYCL/kernel-simple-instrumentation.cpp index 72c744601fcfd..6a6168735dce0 100644 --- a/clang/test/CodeGenSYCL/kernel-simple-instrumentation.cpp +++ b/clang/test/CodeGenSYCL/kernel-simple-instrumentation.cpp @@ -1,7 +1,8 @@ /// Check if start/finish ITT annotations are being added during compilation of /// SYCL device code -// RUN: %clang_cc1 -fsycl-is-device -fsycl-instrument-device-code -triple spir64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fsycl-is-device -flegacy-pass-manager -fsycl-instrument-device-code -triple spir64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fsycl-is-device -fno-legacy-pass-manager -fsycl-instrument-device-code -triple spir64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // CHECK: kernel_function // CHECK-NEXT: entry: From 909a7803c55d1b61a23afa7281035d25fc637ee5 Mon Sep 17 00:00:00 2001 From: Mikhail Lychkov Date: Tue, 18 Jan 2022 05:53:06 +0300 Subject: [PATCH 2/4] Do target check via assert Signed-off-by: Mikhail Lychkov --- clang/lib/CodeGen/BackendUtil.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e87f8a834e17f..5e76df9df580a 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1483,9 +1483,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // -fsycl-instrument-device-code option was passed. This option can be used // only with spir triple. if (CodeGenOpts.SPIRITTAnnotations) { - if (!llvm::Triple(TheModule->getTargetTriple()).isSPIR()) - llvm::report_fatal_error( - "ITT annotations can only by added to a module with spir target"); + assert(llvm::Triple(TheModule->getTargetTriple()).isSPIR() && + "ITT annotations can only by added to a module with spir target"); MPM.addPass(SPIRITTAnnotationsPass()); } From 2ac65a886f14392b0b4bb053e9b421802e72a32a Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Tue, 18 Jan 2022 19:14:26 +0300 Subject: [PATCH 3/4] Update clang/lib/CodeGen/BackendUtil.cpp Co-authored-by: Dmitry Sidorov --- clang/lib/CodeGen/BackendUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 5e76df9df580a..cbba3fb84b5b0 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1484,7 +1484,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // only with spir triple. if (CodeGenOpts.SPIRITTAnnotations) { assert(llvm::Triple(TheModule->getTargetTriple()).isSPIR() && - "ITT annotations can only by added to a module with spir target"); + "ITT annotations can only be added to a module with spir target"); MPM.addPass(SPIRITTAnnotationsPass()); } From f139546d4273d0412f6e22aff22a6bee2bf130e5 Mon Sep 17 00:00:00 2001 From: Mikhail Lychkov Date: Tue, 18 Jan 2022 20:04:51 +0300 Subject: [PATCH 4/4] Fix assert message for itt annotation check Signed-off-by: Mikhail Lychkov --- clang/lib/CodeGen/BackendUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index cbba3fb84b5b0..fabea5d70a840 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1045,7 +1045,7 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager( // used only with spir triple. if (CodeGenOpts.SPIRITTAnnotations) { assert(llvm::Triple(TheModule->getTargetTriple()).isSPIR() && - "ITT annotations can only by added to a module with spir target"); + "ITT annotations can only be added to a module with spir target"); PerModulePasses.add(createSPIRITTAnnotationsLegacyPass()); }