"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/state_trackers/clover/llvm/metadata.hpp" (16 Sep 2020, 2907 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "metadata.hpp" see the Fossies "Dox" file reference documentation.

    1 //
    2 // Copyright 2016 Francisco Jerez
    3 //
    4 // Permission is hereby granted, free of charge, to any person obtaining a
    5 // copy of this software and associated documentation files (the "Software"),
    6 // to deal in the Software without restriction, including without limitation
    7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
    8 // and/or sell copies of the Software, and to permit persons to whom the
    9 // Software is furnished to do so, subject to the following conditions:
   10 //
   11 // The above copyright notice and this permission notice shall be included in
   12 // all copies or substantial portions of the Software.
   13 //
   14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
   18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
   19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
   20 // OTHER DEALINGS IN THE SOFTWARE.
   21 //
   22 
   23 ///
   24 /// \file
   25 /// Utility functions for LLVM IR metadata introspection.
   26 ///
   27 
   28 #ifndef CLOVER_LLVM_METADATA_HPP
   29 #define CLOVER_LLVM_METADATA_HPP
   30 
   31 #include "llvm/compat.hpp"
   32 #include "util/algorithm.hpp"
   33 
   34 #include <vector>
   35 #include <llvm/Config/llvm-config.h>
   36 #include <llvm/IR/Module.h>
   37 #include <llvm/IR/Metadata.h>
   38 
   39 namespace clover {
   40    namespace llvm {
   41       namespace detail {
   42          inline bool
   43          is_kernel(const ::llvm::Function &f) {
   44             return f.getMetadata("kernel_arg_type");
   45          }
   46 
   47          inline iterator_range< ::llvm::MDNode::op_iterator>
   48          get_kernel_metadata_operands(const ::llvm::Function &f,
   49                                       const std::string &name) {
   50             const auto data_node = f.getMetadata(name);
   51             return range(data_node->op_begin(), data_node->op_end());
   52          }
   53       }
   54 
   55       ///
   56       /// Extract the string metadata node \p name corresponding to the kernel
   57       /// argument given by \p arg.
   58       ///
   59       inline std::string
   60       get_argument_metadata(const ::llvm::Function &f,
   61                             const ::llvm::Argument &arg,
   62                             const std::string &name) {
   63          return ::llvm::cast< ::llvm::MDString>(
   64                detail::get_kernel_metadata_operands(f, name)[arg.getArgNo()])
   65             ->getString().str();
   66       }
   67 
   68       ///
   69       /// Return a vector with all CL kernel functions found in the LLVM
   70       /// module \p mod.
   71       ///
   72       inline std::vector<const ::llvm::Function *>
   73       get_kernels(const ::llvm::Module &mod) {
   74          std::vector<const ::llvm::Function *> fs;
   75 
   76          for (auto &f : mod.getFunctionList()) {
   77             if (detail::is_kernel(f))
   78                fs.push_back(&f);
   79          }
   80 
   81          return fs;
   82       }
   83    }
   84 }
   85 
   86 #endif