@@ -138,11 +138,17 @@ ModulePass *llvm::createSPIRITTAnnotationsPass() {
138
138
139
139
namespace {
140
140
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) {
143
143
return F.getCallingConv () == CallingConv::SPIR_KERNEL;
144
144
}
145
145
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
+
146
152
Instruction *emitCall (Module &M, Type *RetTy, StringRef FunctionName,
147
153
ArrayRef<Value *> Args, Instruction *InsertBefore) {
148
154
SmallVector<Type *, 8 > ArgTys (Args.size ());
@@ -240,20 +246,24 @@ PreservedAnalyses SPIRITTAnnotationsPass::run(Module &M,
240
246
SPIRV_GROUP_FMAX, SPIRV_GROUP_UMAX, SPIRV_GROUP_SMAX};
241
247
242
248
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))
245
253
continue ;
246
254
247
255
// At the beggining of a kernel insert work item start annotation
248
256
// 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));
251
260
252
261
for (BasicBlock &BB : F) {
253
262
// 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);
257
267
for (Instruction &I : BB) {
258
268
CallInst *CI = dyn_cast<CallInst>(&I);
259
269
if (!CI)
0 commit comments