MIRSampleProfile.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===----- MIRSampleProfile.h: SampleFDO Support in MIR ---*- c++ -*-------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains the supoorting functions for machine level Sample FDO
  15. // loader. This is used in Flow Sensitive SampelFDO.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H
  19. #define LLVM_CODEGEN_MIRSAMPLEPROFILE_H
  20. #include "llvm/Analysis/ProfileSummaryInfo.h"
  21. #include "llvm/CodeGen/MachineBasicBlock.h"
  22. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  23. #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
  24. #include "llvm/CodeGen/MachineDominators.h"
  25. #include "llvm/CodeGen/MachineFunction.h"
  26. #include "llvm/CodeGen/MachineFunctionPass.h"
  27. #include "llvm/CodeGen/MachineInstr.h"
  28. #include "llvm/CodeGen/MachineLoopInfo.h"
  29. #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
  30. #include "llvm/CodeGen/MachinePostDominators.h"
  31. #include "llvm/CodeGen/Passes.h"
  32. #include "llvm/IR/DebugInfoMetadata.h"
  33. #include "llvm/IR/Function.h"
  34. #include "llvm/IR/Module.h"
  35. #include "llvm/InitializePasses.h"
  36. #include "llvm/ProfileData/InstrProf.h"
  37. #include "llvm/ProfileData/SampleProf.h"
  38. #include "llvm/ProfileData/SampleProfReader.h"
  39. #include <cassert>
  40. namespace llvm {
  41. using namespace sampleprof;
  42. class MIRProfileLoader;
  43. class MIRProfileLoaderPass : public MachineFunctionPass {
  44. MachineFunction *MF;
  45. std::string ProfileFileName;
  46. FSDiscriminatorPass P;
  47. unsigned LowBit;
  48. unsigned HighBit;
  49. public:
  50. static char ID;
  51. /// FS bits will only use the '1' bits in the Mask.
  52. MIRProfileLoaderPass(std::string FileName = "",
  53. std::string RemappingFileName = "",
  54. FSDiscriminatorPass P = FSDiscriminatorPass::Pass1);
  55. /// getMachineFunction - Return the last machine function computed.
  56. const MachineFunction *getMachineFunction() const { return MF; }
  57. StringRef getPassName() const override { return "SampleFDO loader in MIR"; }
  58. private:
  59. void init(MachineFunction &MF);
  60. bool runOnMachineFunction(MachineFunction &) override;
  61. bool doInitialization(Module &M) override;
  62. void getAnalysisUsage(AnalysisUsage &AU) const override;
  63. std::unique_ptr<MIRProfileLoader> MIRSampleLoader;
  64. /// Hold the information of the basic block frequency.
  65. MachineBlockFrequencyInfo *MBFI;
  66. };
  67. } // namespace llvm
  68. #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H
  69. #ifdef __GNUC__
  70. #pragma GCC diagnostic pop
  71. #endif