How can I tell whether a `Function` is a HIP device kernel from LLVM `Module`'s function list?

Now I want to do some optimizations on HIP device kernels, how can I distinguish device kernels from the module’s other host function?

Result run(Module& M, ModuleAnalysisManager& MAM) {
    for (const auto& function : M.getFunctionList()) {
      // function.isHIPKernel?
    }
    return {};
}

If you target AMD GPUs you can check the calling convention, it would be amdgpu_kernel, or sth like it.
If you want to be more generic, check the !llvm.nvvm module metadata and go from there.
See: llvm-project/OpenMPOpt.cpp at 39fc67b8af707f6bdcbcfbec1e17f14ffbaeecb8 · llvm/llvm-project · GitHub

The correct way would be to checking F.getCallingConv() == CallingConv::AMDGPU_KERNEL

It works. Thank you very much!