Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:39

0001 //===- Transforms/Instrumentation/PGOInstrumentation.h ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// This file provides the interface for IR based instrumentation passes (
0011 /// (profile-gen, and profile-use).
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H
0016 #define LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H
0017 
0018 #include "llvm/ADT/ArrayRef.h"
0019 #include "llvm/ADT/IntrusiveRefCntPtr.h"
0020 #include "llvm/IR/PassManager.h"
0021 #include "llvm/Support/CommandLine.h"
0022 #include <cstdint>
0023 #include <string>
0024 
0025 namespace llvm {
0026 
0027 extern cl::opt<bool> DebugInfoCorrelate;
0028 
0029 class Function;
0030 class Instruction;
0031 class Module;
0032 
0033 namespace vfs {
0034 class FileSystem;
0035 } // namespace vfs
0036 
0037 /// The instrumentation (profile-instr-gen) pass for IR based PGO.
0038 // We use this pass to create COMDAT profile variables for context
0039 // sensitive PGO (CSPGO). The reason to have a pass for this is CSPGO
0040 // can be run after LTO/ThinLTO linking. Lld linker needs to see
0041 // all the COMDAT variables before linking. So we have this pass
0042 // always run before linking for CSPGO.
0043 class PGOInstrumentationGenCreateVar
0044     : public PassInfoMixin<PGOInstrumentationGenCreateVar> {
0045 public:
0046   PGOInstrumentationGenCreateVar(std::string CSInstrName = "",
0047                                  bool Sampling = false)
0048       : CSInstrName(CSInstrName), ProfileSampling(Sampling) {}
0049   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
0050 
0051 private:
0052   std::string CSInstrName;
0053   bool ProfileSampling;
0054 };
0055 
0056 enum class PGOInstrumentationType { Invalid = 0, FDO, CSFDO, CTXPROF };
0057 /// The instrumentation (profile-instr-gen) pass for IR based PGO.
0058 class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> {
0059 public:
0060   PGOInstrumentationGen(
0061       PGOInstrumentationType InstrumentationType = PGOInstrumentationType ::FDO)
0062       : InstrumentationType(InstrumentationType) {}
0063   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
0064 
0065 private:
0066   // If this is a context sensitive instrumentation.
0067   const PGOInstrumentationType InstrumentationType;
0068 };
0069 
0070 /// The profile annotation (profile-instr-use) pass for IR based PGO.
0071 class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> {
0072 public:
0073   PGOInstrumentationUse(std::string Filename = "",
0074                         std::string RemappingFilename = "", bool IsCS = false,
0075                         IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
0076 
0077   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
0078 
0079 private:
0080   std::string ProfileFileName;
0081   std::string ProfileRemappingFileName;
0082   // If this is a context sensitive instrumentation.
0083   bool IsCS;
0084   IntrusiveRefCntPtr<vfs::FileSystem> FS;
0085 };
0086 
0087 /// The indirect function call promotion pass.
0088 class PGOIndirectCallPromotion : public PassInfoMixin<PGOIndirectCallPromotion> {
0089 public:
0090   PGOIndirectCallPromotion(bool IsInLTO = false, bool SamplePGO = false)
0091       : InLTO(IsInLTO), SamplePGO(SamplePGO) {}
0092 
0093   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
0094 
0095 private:
0096   bool InLTO;
0097   bool SamplePGO;
0098 };
0099 
0100 /// The profile size based optimization pass for memory intrinsics.
0101 class PGOMemOPSizeOpt : public PassInfoMixin<PGOMemOPSizeOpt> {
0102 public:
0103   PGOMemOPSizeOpt() = default;
0104 
0105   PreservedAnalyses run(Function &F, FunctionAnalysisManager &MAM);
0106 };
0107 
0108 void setProfMetadata(Module *M, Instruction *TI, ArrayRef<uint64_t> EdgeCounts,
0109                      uint64_t MaxCount);
0110 
0111 void setIrrLoopHeaderMetadata(Module *M, Instruction *TI, uint64_t Count);
0112 
0113 } // end namespace llvm
0114 
0115 #endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H