[Mesa-dev] [PATCH 1/2] clover: Fix kernel metadata retrieval after clang r273425

Francisco Jerez currojerez at riseup.net
Tue Jun 28 06:13:29 UTC 2016


Jan Vesely <jan.vesely at rutgers.edu> writes:

> On Wed, 2016-06-22 at 20:52 -0400, Jan Vesely wrote:
>> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
>
> sorry for an early ping, but at least the first patch is needed to
> unbreak clover with recent llvm (otherwise all kernel launches fail
> with unknown kernel name)
>
I'm about to send out a series rewriting most of this code, I think
PATCH 2 would likely cause more merge conflicts than it would help.
I've pushed PATCH 1 though to keep the build working in the meantime
with latest Clang from SVN.

Thanks.

> thanks,
> Jan
>
>> ---
>>  .../state_trackers/clover/llvm/invocation.cpp      | 35
>> +++++++++++++++++++---
>>  1 file changed, 31 insertions(+), 4 deletions(-)
>> 
>> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> index 57eaaaa..db748b4 100644
>> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> @@ -277,7 +277,16 @@ namespace {
>>     }
>>  
>>     std::vector<llvm::Function *>
>> -   find_kernels(const llvm::Module *mod) {
>> +   find_kernels(llvm::Module *mod) {
>> +      std::vector<llvm::Function *> kernels;
>> +#if HAVE_LLVM >= 0x0309
>> +      auto &list = mod->getFunctionList();
>> +      for_each(list.begin(), list.end(), [&](llvm::Function &f){
>> +         if (f.getMetadata("kernel_arg_type"))
>> +           kernels.push_back(&f);
>> +      });
>> +      return kernels;
>> +#endif
>>        const llvm::NamedMDNode *kernel_node =
>>                                   mod-
>> >getNamedMetadata("opencl.kernels");
>>        // This means there are no kernels in the program.  The spec
>> does not
>> @@ -287,7 +296,6 @@ namespace {
>>           return std::vector<llvm::Function *>();
>>        }
>>  
>> -      std::vector<llvm::Function *> kernels;
>>        kernels.reserve(kernel_node->getNumOperands());
>>        for (unsigned i = 0; i < kernel_node->getNumOperands(); ++i) {
>>  #if HAVE_LLVM >= 0x0306
>> @@ -373,8 +381,27 @@ namespace {
>>        kernel_arg_md(llvm::StringRef type_name_, llvm::StringRef
>> access_qual_):
>>           type_name(type_name_), access_qual(access_qual_) {}
>>     };
>> +#if HAVE_LLVM >= 0x0309
>> +   std::vector<kernel_arg_md>
>> +   get_kernel_arg_md(const llvm::Function *kernel_func) {
>>  
>> -#if HAVE_LLVM >= 0x0306
>> +      size_t num_args = kernel_func->getArgumentList().size();
>> +
>> +      auto aq = kernel_func->getMetadata("kernel_arg_access_qual");
>> +      auto ty = kernel_func->getMetadata("kernel_arg_type");
>> +
>> +      std::vector<kernel_arg_md> res;
>> +      res.reserve(num_args);
>> +      for (size_t i = 0; i < num_args; ++i) {
>> +         res.push_back(kernel_arg_md(
>> +            llvm::cast<llvm::MDString>(ty->getOperand(i))-
>> >getString(),
>> +            llvm::cast<llvm::MDString>(aq->getOperand(i))-
>> >getString()));
>> +      }
>> +
>> +      return res;
>> +   }
>> +
>> +#elif HAVE_LLVM >= 0x0306
>>  
>>     const llvm::MDNode *
>>     get_kernel_metadata(const llvm::Function *kernel_func) {
>> @@ -772,7 +799,7 @@ namespace {
>>  
>>     module
>>     build_module_native(std::vector<char> &code,
>> -                       const llvm::Module *mod,
>> +                       llvm::Module *mod,
>>                         const clang::LangAS::Map &address_spaces,
>>                         std::string &r_log) {
>>  
> -- 
>
> Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160627/d9550b21/attachment.sig>


More information about the mesa-dev mailing list