1 | //===- Transforms/Instrumentation/PGOInstrumentation.h ----------*- 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 | /// \file |
10 | /// This file provides the interface for IR based instrumentation passes ( |
11 | /// (profile-gen, and profile-use). |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H |
16 | #define LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H |
17 | |
18 | #include "llvm/ADT/ArrayRef.h" |
19 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
20 | #include "llvm/IR/PassManager.h" |
21 | #include "llvm/Support/CommandLine.h" |
22 | #include <cstdint> |
23 | #include <string> |
24 | |
25 | namespace llvm { |
26 | |
27 | extern cl::opt<bool> DebugInfoCorrelate; |
28 | |
29 | class Function; |
30 | class Instruction; |
31 | class Module; |
32 | |
33 | namespace vfs { |
34 | class FileSystem; |
35 | } // namespace vfs |
36 | |
37 | /// The instrumentation (profile-instr-gen) pass for IR based PGO. |
38 | // We use this pass to create COMDAT profile variables for context |
39 | // sensitive PGO (CSPGO). The reason to have a pass for this is CSPGO |
40 | // can be run after LTO/ThinLTO linking. Lld linker needs to see |
41 | // all the COMDAT variables before linking. So we have this pass |
42 | // always run before linking for CSPGO. |
43 | class PGOInstrumentationGenCreateVar |
44 | : public PassInfoMixin<PGOInstrumentationGenCreateVar> { |
45 | public: |
46 | PGOInstrumentationGenCreateVar(std::string CSInstrName = "" ) |
47 | : CSInstrName(CSInstrName) {} |
48 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
49 | |
50 | private: |
51 | std::string CSInstrName; |
52 | }; |
53 | |
54 | /// The instrumentation (profile-instr-gen) pass for IR based PGO. |
55 | class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> { |
56 | public: |
57 | PGOInstrumentationGen(bool IsCS = false) : IsCS(IsCS) {} |
58 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
59 | |
60 | private: |
61 | // If this is a context sensitive instrumentation. |
62 | bool IsCS; |
63 | }; |
64 | |
65 | /// The profile annotation (profile-instr-use) pass for IR based PGO. |
66 | class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> { |
67 | public: |
68 | PGOInstrumentationUse(std::string Filename = "" , |
69 | std::string RemappingFilename = "" , bool IsCS = false, |
70 | IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr); |
71 | |
72 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
73 | |
74 | private: |
75 | std::string ProfileFileName; |
76 | std::string ProfileRemappingFileName; |
77 | // If this is a context sensitive instrumentation. |
78 | bool IsCS; |
79 | IntrusiveRefCntPtr<vfs::FileSystem> FS; |
80 | }; |
81 | |
82 | /// The indirect function call promotion pass. |
83 | class PGOIndirectCallPromotion : public PassInfoMixin<PGOIndirectCallPromotion> { |
84 | public: |
85 | PGOIndirectCallPromotion(bool IsInLTO = false, bool SamplePGO = false) |
86 | : InLTO(IsInLTO), SamplePGO(SamplePGO) {} |
87 | |
88 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
89 | |
90 | private: |
91 | bool InLTO; |
92 | bool SamplePGO; |
93 | }; |
94 | |
95 | /// The profile size based optimization pass for memory intrinsics. |
96 | class PGOMemOPSizeOpt : public PassInfoMixin<PGOMemOPSizeOpt> { |
97 | public: |
98 | PGOMemOPSizeOpt() = default; |
99 | |
100 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &MAM); |
101 | }; |
102 | |
103 | void setProfMetadata(Module *M, Instruction *TI, ArrayRef<uint64_t> EdgeCounts, |
104 | uint64_t MaxCount); |
105 | |
106 | void (Module *M, Instruction *TI, uint64_t Count); |
107 | |
108 | } // end namespace llvm |
109 | |
110 | #endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H |
111 | |