summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/radeon/R600OpenCLUtils.h
blob: 91e41d63d0d4a2ab73da80ba0d92eaf10f9c9302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//===-- OpenCLUtils.h - TODO: Add brief description -------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// TODO: Add full description
//
//===----------------------------------------------------------------------===//
#ifndef OPENCLUTILS_H
#define OPENCLUTILS_H

#include "llvm/Function.h"

#include <llvm/Module.h>

static bool isOpenCLKernel(const llvm::Function* fun)
{
  llvm::Module *mod = const_cast<llvm::Function*>(fun)->getParent();
  llvm::NamedMDNode * md = mod->getOrInsertNamedMetadata("opencl.kernels");

  if (!md or !md->getNumOperands())
  {
    return false;
  }

  for (int i = 0; i < int(md->getNumOperands()); i++)
  {
    if (!md->getOperand(i) or !md->getOperand(i)->getOperand(0))
    {
      continue;
    }
    
    assert(md->getOperand(i)->getNumOperands() == 1);

    if (md->getOperand(i)->getOperand(0)->getName() == fun->getName())
    {
      return true;
    }
  }

  return false;
}


#endif