Skip to content

Commit e0455ee

Browse files
authored
[SYCL] Add ITT annotations for SPIR functions as well (#3377)
Previously if was done one for SPIR kernels only Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 64c1270 commit e0455ee

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ ModulePass *llvm::createSPIRITTAnnotationsPass() {
138138

139139
namespace {
140140

141-
// Check for calling convention of a function.
142-
bool isSPIRKernel(Function &F) {
141+
// Check for calling convention of a function. Return true if it's SPIR kernel.
142+
inline bool isSPIRKernel(Function &F) {
143143
return F.getCallingConv() == CallingConv::SPIR_KERNEL;
144144
}
145145

@@ -240,20 +240,24 @@ PreservedAnalyses SPIRITTAnnotationsPass::run(Module &M,
240240
SPIRV_GROUP_FMAX, SPIRV_GROUP_UMAX, SPIRV_GROUP_SMAX};
241241

242242
for (Function &F : M) {
243-
// Annotate only SPIR kernels
244-
if (F.isDeclaration() || !isSPIRKernel(F))
243+
if (F.isDeclaration())
245244
continue;
246245

246+
// Work item start/finish annotations are only for SPIR kernels
247+
bool IsSPIRKernel = isSPIRKernel(F);
248+
247249
// At the beggining of a kernel insert work item start annotation
248250
// instruction.
249-
IRModified |= insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_START,
250-
&*inst_begin(F));
251+
if (IsSPIRKernel)
252+
IRModified |= insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_START,
253+
&*inst_begin(F));
251254

252255
for (BasicBlock &BB : F) {
253256
// Insert Finish instruction before return instruction
254-
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator()))
255-
IRModified |=
256-
insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_FINISH, RI);
257+
if (IsSPIRKernel)
258+
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator()))
259+
IRModified |=
260+
insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_FINISH, RI);
257261
for (Instruction &I : BB) {
258262
CallInst *CI = dyn_cast<CallInst>(&I);
259263
if (!CI)

llvm/test/Transforms/SPIRITTAnnotations/itt_atomic_load.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ if.end.i: ; preds = %entry
4949
; CHECK-NEXT: {{.*}}__spirv_AtomicLoad{{.*}}(i32 addrspace(1)* %[[ATOMIC_ARG_1]],{{.*}}, i32 896
5050
; CHECK-NEXT: call void @__itt_offload_atomic_op_finish(i32 addrspace(1)* %[[ATOMIC_ARG_1]], i32 0, i32 0)
5151
%call3.i.i.i.i = tail call spir_func i32 @_Z18__spirv_AtomicLoadPU3AS1KiN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagE(i32 addrspace(1)* %add.ptr.i34, i32 1, i32 896) #2
52+
call spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %add.ptr.i34)
5253
%ptridx.i.i.i = getelementptr inbounds i32, i32 addrspace(1)* %add.ptr.i, i64 %4
5354
%ptridx.ascast.i.i.i = addrspacecast i32 addrspace(1)* %ptridx.i.i.i to i32 addrspace(4)*
5455
store i32 %call3.i.i.i.i, i32 addrspace(4)* %ptridx.ascast.i.i.i, align 4, !tbaa !14
@@ -60,6 +61,18 @@ _ZZN2cl4sycl7handler24parallel_for_lambda_implI11load_kernelIiEZZ9load_testIiEvN
6061
ret void
6162
}
6263

64+
define weak_odr dso_local spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %ptr) {
65+
entry:
66+
; CHECK-LABEL: spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %{{.*}}) {
67+
; CHECK-NEXT: entry:
68+
; CHECK-NEXT: call void @__itt_offload_atomic_op_start(i32 addrspace(1)* %[[ATOMIC_ARG_S:[0-9a-zA-Z._]+]], i32 0, i32 0)
69+
; CHECK-NEXT: {{.*}}__spirv_AtomicLoad{{.*}}(i32 addrspace(1)* %[[ATOMIC_ARG_S]],{{.*}}, i32 896
70+
; CHECK-NEXT: call void @__itt_offload_atomic_op_finish(i32 addrspace(1)* %[[ATOMIC_ARG_S]], i32 0, i32 0)
71+
call spir_func i32 @_Z18__spirv_AtomicLoadPU3AS1KiN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagE(i32 addrspace(1)* %ptr, i32 1, i32 896) #2
72+
; CHECK-NOT: call void @__itt_offload_wi_finish_wrapper()
73+
ret void
74+
}
75+
6376
; Function Attrs: convergent
6477
declare dso_local spir_func i32 @_Z18__spirv_AtomicLoadPU3AS1KiN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagE(i32 addrspace(1)*, i32, i32) local_unnamed_addr #1
6578

llvm/test/Transforms/SPIRITTAnnotations/itt_atomic_store.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ if.end.i: ; preds = %entry
4646
; CHECK-NEXT: {{.*}}__spirv_AtomicStore{{.*}}(i32 addrspace(1)* %[[ATOMIC_ARG_1]],{{.*}}, i32 896
4747
; CHECK-NEXT: call void @__itt_offload_atomic_op_finish(i32 addrspace(1)* %[[ATOMIC_ARG_1]], i32 1, i32 0
4848
tail call spir_func void @_Z19__spirv_AtomicStorePU3AS1iN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagEi(i32 addrspace(1)* %add.ptr.i, i32 1, i32 896, i32 %conv.i.i) #2
49+
tail call spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %add.ptr.i)
4950
br label %_ZZN2cl4sycl7handler24parallel_for_lambda_implI12store_kernelIiEZZ10store_testIiEvNS0_5queueEmENKUlRS1_E_clES7_EUlNS0_4itemILi1ELb1EEEE_Li1EEEvNS0_5rangeIXT1_EEET0_ENKUlSA_E_clESA_.exit
5051

5152
_ZZN2cl4sycl7handler24parallel_for_lambda_implI12store_kernelIiEZZ10store_testIiEvNS0_5queueEmENKUlRS1_E_clES7_EUlNS0_4itemILi1ELb1EEEE_Li1EEEvNS0_5rangeIXT1_EEET0_ENKUlSA_E_clESA_.exit: ; preds = %entry, %if.end.i
@@ -54,6 +55,20 @@ _ZZN2cl4sycl7handler24parallel_for_lambda_implI12store_kernelIiEZZ10store_testIi
5455
ret void
5556
}
5657

58+
define weak_odr dso_local spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %ptr) {
59+
entry:
60+
; CHECK-LABEL: spir_func void @__synthetic_spir_fun_call(i32 addrspace(1)* %{{.*}}) {
61+
; CHECK: call void @__itt_offload_atomic_op_start(i32 addrspace(1)* %[[ATOMIC_ARG_S:[0-9a-zA-Z._]+]], i32 1, i32 0)
62+
; CHECK-NEXT: {{.*}}__spirv_AtomicStore{{.*}}(i32 addrspace(1)* %[[ATOMIC_ARG_S]],{{.*}}, i32 896
63+
; CHECK-NEXT: call void @__itt_offload_atomic_op_finish(i32 addrspace(1)* %[[ATOMIC_ARG_S]], i32 1, i32 0)
64+
%0 = load <3 x i64>, <3 x i64> addrspace(4)* addrspacecast (<3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId to <3 x i64> addrspace(4)*), align 32, !noalias !15
65+
%1 = extractelement <3 x i64> %0, i64 0
66+
%conv = trunc i64 %1 to i32
67+
tail call spir_func void @_Z19__spirv_AtomicStorePU3AS1iN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagEi(i32 addrspace(1)* %ptr, i32 1, i32 896, i32 %conv) #2
68+
; CHECK-NOT: call void @__itt_offload_wi_finish_wrapper()
69+
ret void
70+
}
71+
5772
; Function Attrs: convergent
5873
declare dso_local spir_func void @_Z19__spirv_AtomicStorePU3AS1iN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagEi(i32 addrspace(1)*, i32, i32, i32) local_unnamed_addr #1
5974

0 commit comments

Comments
 (0)