LCOV - code coverage report
Current view: top level - include/llvm/ExecutionEngine/Orc - GlobalMappingLayer.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 9 9 100.0 %
Date: 2017-09-14 15:23:50 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- GlobalMappingLayer.h - Run all IR through a functor ------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // Convenience layer for injecting symbols that will appear in calls to
      11             : // findSymbol.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H
      16             : #define LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H
      17             : 
      18             : #include "llvm/ExecutionEngine/JITSymbol.h"
      19             : #include <map>
      20             : #include <memory>
      21             : #include <string>
      22             : 
      23             : namespace llvm {
      24             : 
      25             : class Module;
      26             : class JITSymbolResolver;
      27             : 
      28             : namespace orc {
      29             : 
      30             : /// @brief Global mapping layer.
      31             : ///
      32             : ///   This layer overrides the findSymbol method to first search a local symbol
      33             : /// table that the client can define. It can be used to inject new symbol
      34             : /// mappings into the JIT. Beware, however: symbols within a single IR module or
      35             : /// object file will still resolve locally (via RuntimeDyld's symbol table) -
      36             : /// such internal references cannot be overriden via this layer.
      37             : template <typename BaseLayerT>
      38           2 : class GlobalMappingLayer {
      39             : public:
      40             : 
      41             :   /// @brief Handle to an added module.
      42             :   using ModuleHandleT = typename BaseLayerT::ModuleHandleT;
      43             : 
      44             :   /// @brief Construct an GlobalMappingLayer with the given BaseLayer
      45           2 :   GlobalMappingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
      46             : 
      47             :   /// @brief Add the given module to the JIT.
      48             :   /// @return A handle for the added modules.
      49             :   ModuleHandleT addModule(std::shared_ptr<Module> M,
      50             :                           std::shared_ptr<JITSymbolResolver> Resolver) {
      51             :     return BaseLayer.addModule(std::move(M), std::move(Resolver));
      52             :   }
      53             : 
      54             :   /// @brief Remove the module set associated with the handle H.
      55             :   void removeModule(ModuleHandleT H) { BaseLayer.removeModule(H); }
      56             : 
      57             :   /// @brief Manually set the address to return for the given symbol.
      58             :   void setGlobalMapping(const std::string &Name, JITTargetAddress Addr) {
      59           1 :     SymbolTable[Name] = Addr;
      60             :   }
      61             : 
      62             :   /// @brief Remove the given symbol from the global mapping.
      63             :   void eraseGlobalMapping(const std::string &Name) {
      64           2 :     SymbolTable.erase(Name);
      65             :   }
      66             : 
      67             :   /// @brief Search for the given named symbol.
      68             :   ///
      69             :   ///          This method will first search the local symbol table, returning
      70             :   ///        any symbol found there. If the symbol is not found in the local
      71             :   ///        table then this call will be passed through to the base layer.
      72             :   ///
      73             :   /// @param Name The name of the symbol to search for.
      74             :   /// @param ExportedSymbolsOnly If true, search only for exported symbols.
      75             :   /// @return A handle for the given named symbol, if it exists.
      76           4 :   JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
      77           8 :     auto I = SymbolTable.find(Name);
      78           8 :     if (I != SymbolTable.end())
      79           3 :       return JITSymbol(I->second, JITSymbolFlags::Exported);
      80           3 :     return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
      81             :   }
      82             : 
      83             :   /// @brief Get the address of the given symbol in the context of the of the
      84             :   ///        module represented by the handle H. This call is forwarded to the
      85             :   ///        base layer's implementation.
      86             :   /// @param H The handle for the module to search in.
      87             :   /// @param Name The name of the symbol to search for.
      88             :   /// @param ExportedSymbolsOnly If true, search only for exported symbols.
      89             :   /// @return A handle for the given named symbol, if it is found in the
      90             :   ///         given module.
      91             :   JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
      92             :                          bool ExportedSymbolsOnly) {
      93             :     return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
      94             :   }
      95             : 
      96             :   /// @brief Immediately emit and finalize the module set represented by the
      97             :   ///        given handle.
      98             :   /// @param H Handle for module set to emit/finalize.
      99             :   void emitAndFinalize(ModuleHandleT H) {
     100             :     BaseLayer.emitAndFinalize(H);
     101             :   }
     102             : 
     103             : private:
     104             :   BaseLayerT &BaseLayer;
     105             :   std::map<std::string, JITTargetAddress> SymbolTable;
     106             : };
     107             : 
     108             : } // end namespace orc
     109             : } // end namespace llvm
     110             : 
     111             : #endif // LLVM_EXECUTIONENGINE_ORC_GLOBALMAPPINGLAYER_H

Generated by: LCOV version 1.13