Skip to content

Commit c23f7e4

Browse files
committed
[SYCL] Add ITT annotations for SPIR functions as well
Previously if was done one for SPIR kernels Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 90c79c7 commit c23f7e4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

llvm/lib/Transforms/Instrumentation/SPIRITTAnnotations.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@ 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

146+
// Check for calling convention of a function. Return true if it's SPIR
147+
// function.
148+
inline bool isSPIRFunction(Function &F) {
149+
return F.getCallingConv() == CallingConv::SPIR_FUNC;
150+
}
151+
146152
Instruction *emitCall(Module &M, Type *RetTy, StringRef FunctionName,
147153
ArrayRef<Value *> Args, Instruction *InsertBefore) {
148154
SmallVector<Type *, 8> ArgTys(Args.size());
@@ -240,20 +246,24 @@ PreservedAnalyses SPIRITTAnnotationsPass::run(Module &M,
240246
SPIRV_GROUP_FMAX, SPIRV_GROUP_UMAX, SPIRV_GROUP_SMAX};
241247

242248
for (Function &F : M) {
243-
// Annotate only SPIR kernels
244-
if (F.isDeclaration() || !isSPIRKernel(F))
249+
// Annotate only SPIR kernels and functions
250+
bool IsSPIRKernel = isSPIRKernel(F);
251+
bool IsSPIRFunction = isSPIRFunction(F);
252+
if (F.isDeclaration() || !(isSPIRKernel || isSPIRFunction))
245253
continue;
246254

247255
// At the beggining of a kernel insert work item start annotation
248256
// instruction.
249-
IRModified |= insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_START,
250-
&*inst_begin(F));
257+
if (IsSPIRKernel)
258+
IRModified |= insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_START,
259+
&*inst_begin(F));
251260

252261
for (BasicBlock &BB : F) {
253262
// 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);
263+
if (IsSPIRKernel)
264+
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator()))
265+
IRModified |=
266+
insertSimpleInstrumentationCall(M, ITT_ANNOTATION_WI_FINISH, RI);
257267
for (Instruction &I : BB) {
258268
CallInst *CI = dyn_cast<CallInst>(&I);
259269
if (!CI)

0 commit comments

Comments
 (0)