Skip to content

Commit 02b2424

Browse files
author
Artem Gindinson
committed
Merge from 'sycl' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in clang/include/clang/Driver/Options.td
2 parents 5c60232 + be18b1d commit 02b2424

File tree

17 files changed

+855
-0
lines changed

17 files changed

+855
-0
lines changed

.github/CODEOWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,8 @@ SYCLLowerIR/ @kbobrovs @DenisBakhvalov
114114
esimd/ @kbobrovs @DenisBakhvalov
115115
sycl/include/CL/sycl/INTEL/esimd.hpp @kbobrovs @DenisBakhvalov
116116
sycl/doc/extensions/ExplicitSIMD/ @kbobrovs
117+
118+
# ITT annotations
119+
llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp @MrSidims
120+
llvm/include/llvm/Transforms/Instrumentation/SPIRITTAnnotations.h @MrSidims
121+

clang/include/clang/Basic/CodeGenOptions.def

+3
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ CODEGENOPT(PassByValueIsNoAlias, 1, 0)
421421
/// according to the field declaring type width.
422422
CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
423423

424+
// Whether to instrument SPIR device code with ITT annotations
425+
CODEGENOPT(SPIRITTAnnotations, 1, 0)
426+
424427
#undef CODEGENOPT
425428
#undef ENUM_CODEGENOPT
426429
#undef VALUE_CODEGENOPT

clang/include/clang/Driver/Options.td

+4
Original file line numberDiff line numberDiff line change
@@ -2477,6 +2477,10 @@ def fsycl_device_code_lower_esimd : Flag<["-"], "fsycl-device-code-lower-esimd">
24772477
Flags<[CC1Option, CoreOption]>, HelpText<"Lower ESIMD-specific constructs">;
24782478
def fno_sycl_device_code_lower_esimd : Flag<["-"], "fno-sycl-device-code-lower-esimd">,
24792479
Flags<[CC1Option, CoreOption]>, HelpText<"Do not lower ESIMD-specific constructs">;
2480+
def fsycl_instrument_device_code : Flag<["-"], "fsycl-instrument-device-code">,
2481+
Group<sycl_Group>, Flags<[CC1Option, CoreOption]>,
2482+
HelpText<"Add ITT instrumentation intrinsics calls">,
2483+
MarshallingInfoFlag<CodeGenOpts<"SPIRITTAnnotations">>;
24802484
defm sycl_id_queries_fit_in_int: OptInFFlag<"sycl-id-queries-fit-in-int", "Assume", "Do not assume", " that SYCL ID queries fit within MAX_INT.", [CC1Option,CoreOption]>;
24812485
def fsycl_use_bitcode : Flag<["-"], "fsycl-use-bitcode">,
24822486
Flags<[CC1Option, CoreOption]>, HelpText<"Use LLVM bitcode instead of SPIR-V in fat objects">;

clang/lib/CodeGen/BackendUtil.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
7373
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
7474
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
75+
#include "llvm/Transforms/Instrumentation/SPIRITTAnnotations.h"
7576
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
7677
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
7778
#include "llvm/Transforms/ObjCARC.h"
@@ -967,6 +968,16 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
967968
LangOpts.EnableDAEInSpirKernels)
968969
PerModulePasses.add(createDeadArgEliminationSYCLPass());
969970

971+
// Add SPIRITTAnnotations pass to the pass manager if
972+
// -fsycl-instrument-device-code option was passed. This option can be
973+
// used only with spir triple.
974+
if (CodeGenOpts.SPIRITTAnnotations) {
975+
if (!llvm::Triple(TheModule->getTargetTriple()).isSPIR())
976+
llvm::report_fatal_error(
977+
"ITT annotations can only by added to a module with spir target");
978+
PerModulePasses.add(createSPIRITTAnnotationsPass());
979+
}
980+
970981
switch (Action) {
971982
case Backend_EmitNothing:
972983
break;

clang/lib/Driver/ToolChains/Clang.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -5939,6 +5939,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59395939
if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
59405940
Args.AddLastArg(CmdArgs, options::OPT_sycl_std_EQ);
59415941

5942+
// Forward -fsycl-instrument-device-code option to cc1. This option can only
5943+
// be used with spir triple.
5944+
if (Arg *A = Args.getLastArg(options::OPT_fsycl_instrument_device_code)) {
5945+
if (!Triple.isSPIR())
5946+
D.Diag(diag::err_drv_unsupported_opt_for_target)
5947+
<< A->getAsString(Args) << TripleStr;
5948+
CmdArgs.push_back("-fsycl-instrument-device-code");
5949+
}
5950+
59425951
if (IsHIP) {
59435952
if (Args.hasFlag(options::OPT_fhip_new_launch_api,
59445953
options::OPT_fno_hip_new_launch_api, true))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// Check if start/finish ITT annotations are being added during compilation of
2+
/// SYCL device code
3+
4+
// RUN: %clang_cc1 -fsycl-is-device -fsycl-instrument-device-code -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
5+
6+
// CHECK: kernel_function
7+
// CHECK-NEXT: entry:
8+
// CHECK-NEXT: call void @__itt_offload_wi_start_wrapper()
9+
// CHECK: call void @__itt_offload_wi_finish_wrapper()
10+
// CHECK-NEXT: ret void
11+
12+
#include "Inputs/sycl.hpp"
13+
14+
int main() {
15+
cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write> accessorA;
16+
cl::sycl::kernel_single_task<class kernel_function>(
17+
[=]() {
18+
accessorA.use();
19+
});
20+
return 0;
21+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Check that SPIR ITT instrumentation is disabled by default:
2+
// RUN: %clang -### %s 2>&1 \
3+
// RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s
4+
// CHECK-DEFAULT-NOT: "-fsycl-instrument-device-code"
5+
6+
/// Check if "fsycl_instrument_device_code" is passed to -cc1:
7+
// RUN: %clang -### -fsycl-instrument-device-code %s 2>&1 \
8+
// RUN: | FileCheck -check-prefix=CHECK-ENABLED %s
9+
// CHECK-ENABLED: "-cc1"{{.*}} "-fsycl-instrument-device-code"
10+
11+
/// Check if "fsycl_instrument_device_code" usage with a non-spirv target
12+
/// results in an error.
13+
// RUN: %clang -### -fsycl-instrument-device-code --target=x86 %s 2>&1
14+
// expected-error{{unsupported option '-fsycl-instrument-device-code' for target 'x86_64-unknown-linux-gnu'}}

llvm/include/llvm/InitializePasses.h

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ void initializeStripSymbolsPass(PassRegistry&);
428428
void initializeStructurizeCFGLegacyPassPass(PassRegistry &);
429429
void initializeSYCLLowerWGScopeLegacyPassPass(PassRegistry &);
430430
void initializeSYCLLowerESIMDLegacyPassPass(PassRegistry &);
431+
void initializeSPIRITTAnnotationsLegacyPassPass(PassRegistry &);
431432
void initializeESIMDLowerLoadStorePass(PassRegistry &);
432433
void initializeESIMDLowerVecArgLegacyPassPass(PassRegistry &);
433434
void initializeTailCallElimPass(PassRegistry&);

llvm/include/llvm/LinkAllPasses.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "llvm/Transforms/InstCombine/InstCombine.h"
4949
#include "llvm/Transforms/Instrumentation.h"
5050
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
51+
#include "llvm/Transforms/Instrumentation/SPIRITTAnnotations.h"
5152
#include "llvm/Transforms/ObjCARC.h"
5253
#include "llvm/Transforms/Scalar.h"
5354
#include "llvm/Transforms/Scalar/GVN.h"
@@ -204,6 +205,7 @@ namespace {
204205
(void)llvm::createSYCLLowerESIMDPass();
205206
(void)llvm::createESIMDLowerLoadStorePass();
206207
(void)llvm::createESIMDLowerVecArgPass();
208+
(void)llvm::createSPIRITTAnnotationsPass();
207209
std::string buf;
208210
llvm::raw_string_ostream os(buf);
209211
(void) llvm::createPrintModulePass(os);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----- SPIRITTAnnotations.h - SPIR Instrumental Annotations Pass ------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// A transformation pass which adds instrumental calls to annotate SPIR
10+
// synchronization instructions. This can be used for kernel profiling.
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
#include "llvm/IR/Module.h"
16+
#include "llvm/IR/PassManager.h"
17+
18+
namespace llvm {
19+
20+
class SPIRITTAnnotationsPass : public PassInfoMixin<SPIRITTAnnotationsPass> {
21+
public:
22+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
23+
};
24+
25+
ModulePass *createSPIRITTAnnotationsPass();
26+
27+
} // namespace llvm

llvm/lib/Transforms/Instrumentation/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_llvm_component_library(LLVMInstrumentation
1515
PGOMemOPSizeOpt.cpp
1616
PoisonChecking.cpp
1717
SanitizerCoverage.cpp
18+
SPIRITTAnnotations.cpp
1819
ValueProfileCollector.cpp
1920
ThreadSanitizer.cpp
2021
HWAddressSanitizer.cpp

0 commit comments

Comments
 (0)