LCOV - code coverage report
Current view: top level - include/llvm/Transforms/IPO - FunctionImport.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 2 2 100.0 %
Date: 2018-05-20 00:06:23 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/Transforms/IPO/FunctionImport.h - ThinLTO importing -*- 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             : #ifndef LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
      11             : #define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
      12             : 
      13             : #include "llvm/ADT/DenseSet.h"
      14             : #include "llvm/ADT/StringMap.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include "llvm/IR/GlobalValue.h"
      17             : #include "llvm/IR/ModuleSummaryIndex.h"
      18             : #include "llvm/IR/PassManager.h"
      19             : #include "llvm/Support/Error.h"
      20             : #include <functional>
      21             : #include <map>
      22             : #include <memory>
      23             : #include <string>
      24             : #include <system_error>
      25             : #include <unordered_set>
      26             : #include <utility>
      27             : 
      28             : namespace llvm {
      29             : 
      30             : class Module;
      31             : 
      32             : /// The function importer is automatically importing function from other modules
      33             : /// based on the provided summary informations.
      34         266 : class FunctionImporter {
      35             : public:
      36             :   /// Set of functions to import from a source module. Each entry is a map
      37             :   /// containing all the functions to import for a source module.
      38             :   /// The keys is the GUID identifying a function to import, and the value
      39             :   /// is the threshold applied when deciding to import it.
      40             :   using FunctionsToImportTy = std::map<GlobalValue::GUID, unsigned>;
      41             : 
      42             :   /// The map contains an entry for every module to import from, the key being
      43             :   /// the module identifier to pass to the ModuleLoader. The value is the set of
      44             :   /// functions to import.
      45             :   using ImportMapTy = StringMap<FunctionsToImportTy>;
      46             : 
      47             :   /// The set contains an entry for every global value the module exports.
      48             :   using ExportSetTy = std::unordered_set<GlobalValue::GUID>;
      49             : 
      50             :   /// A function of this type is used to load modules referenced by the index.
      51             :   using ModuleLoaderTy =
      52             :       std::function<Expected<std::unique_ptr<Module>>(StringRef Identifier)>;
      53             : 
      54             :   /// Create a Function Importer.
      55             :   FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader)
      56         331 :       : Index(Index), ModuleLoader(std::move(ModuleLoader)) {}
      57             : 
      58             :   /// Import functions in Module \p M based on the supplied import list.
      59             :   Expected<bool> importFunctions(Module &M, const ImportMapTy &ImportList);
      60             : 
      61             : private:
      62             :   /// The summaries index used to trigger importing.
      63             :   const ModuleSummaryIndex &Index;
      64             : 
      65             :   /// Factory function to load a Module for a given identifier
      66             :   ModuleLoaderTy ModuleLoader;
      67             : };
      68             : 
      69             : /// The function importing pass
      70             : class FunctionImportPass : public PassInfoMixin<FunctionImportPass> {
      71             : public:
      72             :   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
      73             : };
      74             : 
      75             : /// Compute all the imports and exports for every module in the Index.
      76             : ///
      77             : /// \p ModuleToDefinedGVSummaries contains for each Module a map
      78             : /// (GUID -> Summary) for every global defined in the module.
      79             : ///
      80             : /// \p ImportLists will be populated with an entry for every Module we are
      81             : /// importing into. This entry is itself a map that can be passed to
      82             : /// FunctionImporter::importFunctions() above (see description there).
      83             : ///
      84             : /// \p ExportLists contains for each Module the set of globals (GUID) that will
      85             : /// be imported by another module, or referenced by such a function. I.e. this
      86             : /// is the set of globals that need to be promoted/renamed appropriately.
      87             : void ComputeCrossModuleImport(
      88             :     const ModuleSummaryIndex &Index,
      89             :     const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
      90             :     StringMap<FunctionImporter::ImportMapTy> &ImportLists,
      91             :     StringMap<FunctionImporter::ExportSetTy> &ExportLists);
      92             : 
      93             : /// Compute all the imports for the given module using the Index.
      94             : ///
      95             : /// \p ImportList will be populated with a map that can be passed to
      96             : /// FunctionImporter::importFunctions() above (see description there).
      97             : void ComputeCrossModuleImportForModule(
      98             :     StringRef ModulePath, const ModuleSummaryIndex &Index,
      99             :     FunctionImporter::ImportMapTy &ImportList);
     100             : 
     101             : /// Mark all external summaries in \p Index for import into the given module.
     102             : /// Used for distributed builds using a distributed index.
     103             : ///
     104             : /// \p ImportList will be populated with a map that can be passed to
     105             : /// FunctionImporter::importFunctions() above (see description there).
     106             : void ComputeCrossModuleImportForModuleFromIndex(
     107             :     StringRef ModulePath, const ModuleSummaryIndex &Index,
     108             :     FunctionImporter::ImportMapTy &ImportList);
     109             : 
     110             : /// PrevailingType enum used as a return type of callback passed
     111             : /// to computeDeadSymbols. Yes and No values used when status explicitly
     112             : /// set by symbols resolution, otherwise status is Unknown.
     113             : enum class PrevailingType { Yes, No, Unknown };
     114             : 
     115             : /// Compute all the symbols that are "dead": i.e these that can't be reached
     116             : /// in the graph from any of the given symbols listed in
     117             : /// \p GUIDPreservedSymbols. Non-prevailing symbols are symbols without a
     118             : /// prevailing copy anywhere in IR and are normally dead, \p isPrevailing
     119             : /// predicate returns status of symbol.
     120             : void computeDeadSymbols(
     121             :     ModuleSummaryIndex &Index,
     122             :     const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
     123             :     function_ref<PrevailingType(GlobalValue::GUID)> isPrevailing);
     124             : 
     125             : /// Converts value \p GV to declaration, or replaces with a declaration if
     126             : /// it is an alias. Returns true if converted, false if replaced.
     127             : bool convertToDeclaration(GlobalValue &GV);
     128             : 
     129             : /// Compute the set of summaries needed for a ThinLTO backend compilation of
     130             : /// \p ModulePath.
     131             : //
     132             : /// This includes summaries from that module (in case any global summary based
     133             : /// optimizations were recorded) and from any definitions in other modules that
     134             : /// should be imported.
     135             : //
     136             : /// \p ModuleToSummariesForIndex will be populated with the needed summaries
     137             : /// from each required module path. Use a std::map instead of StringMap to get
     138             : /// stable order for bitcode emission.
     139             : void gatherImportedSummariesForModule(
     140             :     StringRef ModulePath,
     141             :     const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
     142             :     const FunctionImporter::ImportMapTy &ImportList,
     143             :     std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
     144             : 
     145             : /// Emit into \p OutputFilename the files module \p ModulePath will import from.
     146             : std::error_code
     147             : EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename,
     148             :                  const FunctionImporter::ImportMapTy &ModuleImports);
     149             : 
     150             : /// Resolve WeakForLinker values in \p TheModule based on the information
     151             : /// recorded in the summaries during global summary-based analysis.
     152             : void thinLTOResolveWeakForLinkerModule(Module &TheModule,
     153             :                                        const GVSummaryMapTy &DefinedGlobals);
     154             : 
     155             : /// Internalize \p TheModule based on the information recorded in the summaries
     156             : /// during global summary-based analysis.
     157             : void thinLTOInternalizeModule(Module &TheModule,
     158             :                               const GVSummaryMapTy &DefinedGlobals);
     159             : 
     160             : } // end namespace llvm
     161             : 
     162             : #endif // LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H

Generated by: LCOV version 1.13