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

          Line data    Source code
       1             : //===- IRTransformLayer.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             : // Run all IR passed in through a user supplied functor.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
      15             : #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
      16             : 
      17             : #include "llvm/ExecutionEngine/JITSymbol.h"
      18             : #include <memory>
      19             : #include <string>
      20             : 
      21             : namespace llvm {
      22             : class Module;
      23             : namespace orc {
      24             : 
      25             : /// @brief IR mutating layer.
      26             : ///
      27             : ///   This layer applies a user supplied transform to each module that is added,
      28             : /// then adds the transformed module to the layer below.
      29             : template <typename BaseLayerT, typename TransformFtor>
      30          14 : class IRTransformLayer {
      31             : public:
      32             : 
      33             :   /// @brief Handle to a set of added modules.
      34             :   using ModuleHandleT = typename BaseLayerT::ModuleHandleT;
      35             : 
      36             :   /// @brief Construct an IRTransformLayer with the given BaseLayer
      37           7 :   IRTransformLayer(BaseLayerT &BaseLayer,
      38             :                    TransformFtor Transform = TransformFtor())
      39          14 :     : BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
      40             : 
      41             :   /// @brief Apply the transform functor to the module, then add the module to
      42             :   ///        the layer below, along with the memory manager and symbol resolver.
      43             :   ///
      44             :   /// @return A handle for the added modules.
      45             :   Expected<ModuleHandleT>
      46          19 :   addModule(std::shared_ptr<Module> M,
      47             :             std::shared_ptr<JITSymbolResolver> Resolver) {
      48         133 :     return BaseLayer.addModule(Transform(std::move(M)), std::move(Resolver));
      49             :   }
      50             : 
      51             :   /// @brief Remove the module associated with the handle H.
      52          38 :   Error removeModule(ModuleHandleT H) { return BaseLayer.removeModule(H); }
      53             : 
      54             :   /// @brief Search for the given named symbol.
      55             :   /// @param Name The name of the symbol to search for.
      56             :   /// @param ExportedSymbolsOnly If true, search only for exported symbols.
      57             :   /// @return A handle for the given named symbol, if it exists.
      58             :   JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
      59          12 :     return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
      60             :   }
      61             : 
      62             :   /// @brief Get the address of the given symbol in the context of the module
      63             :   ///        represented by the handle H. This call is forwarded to the base
      64             :   ///        layer's implementation.
      65             :   /// @param H The handle for the module to search in.
      66             :   /// @param Name The name of the symbol to search for.
      67             :   /// @param ExportedSymbolsOnly If true, search only for exported symbols.
      68             :   /// @return A handle for the given named symbol, if it is found in the
      69             :   ///         given module.
      70             :   JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
      71             :                          bool ExportedSymbolsOnly) {
      72          76 :     return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
      73             :   }
      74             : 
      75             :   /// @brief Immediately emit and finalize the module represented by the given
      76             :   ///        handle.
      77             :   /// @param H Handle for module to emit/finalize.
      78             :   Error emitAndFinalize(ModuleHandleT H) {
      79             :     return BaseLayer.emitAndFinalize(H);
      80             :   }
      81             : 
      82             :   /// @brief Access the transform functor directly.
      83             :   TransformFtor& getTransform() { return Transform; }
      84             : 
      85             :   /// @brief Access the mumate functor directly.
      86             :   const TransformFtor& getTransform() const { return Transform; }
      87             : 
      88             : private:
      89             :   BaseLayerT &BaseLayer;
      90             :   TransformFtor Transform;
      91             : };
      92             : 
      93             : } // end namespace orc
      94             : } // end namespace llvm
      95             : 
      96             : #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H

Generated by: LCOV version 1.13