xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Transforms/IPO/MemProfContextDisambiguation.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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/IR/GlobalValue.h"
19 #include "llvm/IR/ModuleSummaryIndex.h"
20 #include "llvm/IR/PassManager.h"
21 #include <functional>
22 
23 namespace llvm {
24 class GlobalValueSummary;
25 class Module;
26 class OptimizationRemarkEmitter;
27 
28 class MemProfContextDisambiguation
29     : public PassInfoMixin<MemProfContextDisambiguation> {
30   /// Run the context disambiguator on \p M, returns true if any changes made.
31   bool processModule(
32       Module &M,
33       function_ref<OptimizationRemarkEmitter &(Function *)> OREGetter);
34 
35   /// In the ThinLTO backend, apply the cloning decisions in ImportSummary to
36   /// the IR.
37   bool applyImport(Module &M);
38 
39   /// Import summary containing cloning decisions for the ThinLTO backend.
40   const ModuleSummaryIndex *ImportSummary;
41 
42   // Owns the import summary specified by internal options for testing the
43   // ThinLTO backend via opt (to simulate distributed ThinLTO).
44   std::unique_ptr<ModuleSummaryIndex> ImportSummaryForTesting;
45 
46 public:
47   MemProfContextDisambiguation(const ModuleSummaryIndex *Summary = nullptr);
48 
49   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
50 
51   void run(ModuleSummaryIndex &Index,
52            function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
53                isPrevailing);
54 };
55 } // end namespace llvm
56 
57 #endif // LLVM_TRANSFORMS_IPO_MEMPROF_CONTEXT_DISAMBIGUATION_H
58