1 //===- Transforms/Instrumentation/PGOInstrumentation.h ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file provides the interface for IR based instrumentation passes (
11 /// (profile-gen, and profile-use).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
16 #define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/PassManager.h"
29 /// The instrumentation (profile-instr-gen) pass for IR based PGO.
30 // We use this pass to create COMDAT profile variables for context
31 // sensitive PGO (CSPGO). The reason to have a pass for this is CSPGO
32 // can be run after LTO/ThinLTO linking. Lld linker needs to see
33 // all the COMDAT variables before linking. So we have this pass
34 // always run before linking for CSPGO.
35 class PGOInstrumentationGenCreateVar
36 : public PassInfoMixin<PGOInstrumentationGenCreateVar> {
38 PGOInstrumentationGenCreateVar(std::string CSInstrName = "")
39 : CSInstrName(CSInstrName) {}
40 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
43 std::string CSInstrName;
46 /// The instrumentation (profile-instr-gen) pass for IR based PGO.
47 class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> {
49 PGOInstrumentationGen(bool IsCS = false) : IsCS(IsCS) {}
50 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
53 // If this is a context sensitive instrumentation.
57 /// The profile annotation (profile-instr-use) pass for IR based PGO.
58 class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> {
60 PGOInstrumentationUse(std::string Filename = "",
61 std::string RemappingFilename = "", bool IsCS = false);
63 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
66 std::string ProfileFileName;
67 std::string ProfileRemappingFileName;
68 // If this is a context sensitive instrumentation.
72 /// The indirect function call promotion pass.
73 class PGOIndirectCallPromotion : public PassInfoMixin<PGOIndirectCallPromotion> {
75 PGOIndirectCallPromotion(bool IsInLTO = false, bool SamplePGO = false)
76 : InLTO(IsInLTO), SamplePGO(SamplePGO) {}
78 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
85 /// The profile size based optimization pass for memory intrinsics.
86 class PGOMemOPSizeOpt : public PassInfoMixin<PGOMemOPSizeOpt> {
88 PGOMemOPSizeOpt() = default;
90 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
93 void setProfMetadata(Module *M, Instruction *TI, ArrayRef<uint64_t> EdgeCounts,
96 void setIrrLoopHeaderMetadata(Module *M, Instruction *TI, uint64_t Count);
98 } // end namespace llvm
100 #endif // LLVM_TRANSFORMS_PGOINSTRUMENTATION_H