xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Transforms/IPO/MemProfContextDisambiguation.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1 //==- MemProfContextDisambiguation.h - Context Disambiguation ----*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implements support for context disambiguation of allocation calls for profile
10 // guided heap optimization using memprof metadata. See implementation file for
11 // details.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
16 #define LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringSet.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/IR/ModuleSummaryIndex.h"
22 #include "llvm/IR/PassManager.h"
23 #include <functional>
24 
25 namespace llvm {
26 class GlobalValueSummary;
27 class Module;
28 class OptimizationRemarkEmitter;
29 
30 class MemProfContextDisambiguation
31     : public PassInfoMixin<MemProfContextDisambiguation> {
32   /// Run the context disambiguator on \p M, returns true if any changes made.
33   bool processModule(
34       Module &M,
35       function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter);
36 
37   /// In the ThinLTO backend, apply the cloning decisions in ImportSummary to
38   /// the IR.
39   bool applyImport(Module &M);
40 
41   /// Import summary containing cloning decisions for the ThinLTO backend.
42   const ModuleSummaryIndex *ImportSummary;
43 
44   // Owns the import summary specified by internal options for testing the
45   // ThinLTO backend via opt (to simulate distributed ThinLTO).
46   std::unique_ptr<ModuleSummaryIndex> ImportSummaryForTesting;
47 
48 public:
49   MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr);
50 
51   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
52 
53   void run(ModuleSummaryIndex &Index,
54            function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
55                isPrevailing);
56 };
57 } // end namespace llvm
58 
59 #endif // LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
60