MIRFSDiscriminator.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===----- MIRFSDiscriminator.h: MIR FS Discriminator Support --0-- 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 supporting functions for adding Machine level IR
  15. // Flow Sensitive discriminators to the instruction debug information. With
  16. // this, a cloned machine instruction in a different MachineBasicBlock will
  17. // have its own discriminator value. This is done in a MIRAddFSDiscriminators
  18. // pass.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
  22. #define LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
  23. #include "llvm/Analysis/ProfileSummaryInfo.h"
  24. #include "llvm/CodeGen/MachineBasicBlock.h"
  25. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  26. #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
  27. #include "llvm/CodeGen/MachineDominators.h"
  28. #include "llvm/CodeGen/MachineFunction.h"
  29. #include "llvm/CodeGen/MachineFunctionPass.h"
  30. #include "llvm/CodeGen/MachineInstr.h"
  31. #include "llvm/CodeGen/MachineLoopInfo.h"
  32. #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
  33. #include "llvm/CodeGen/MachinePostDominators.h"
  34. #include "llvm/CodeGen/Passes.h"
  35. #include "llvm/IR/DebugInfoMetadata.h"
  36. #include "llvm/IR/Function.h"
  37. #include "llvm/IR/Module.h"
  38. #include "llvm/InitializePasses.h"
  39. #include "llvm/ProfileData/InstrProf.h"
  40. #include "llvm/ProfileData/SampleProf.h"
  41. #include "llvm/ProfileData/SampleProfReader.h"
  42. #include <cassert>
  43. namespace llvm {
  44. using namespace sampleprof;
  45. class MIRAddFSDiscriminators : public MachineFunctionPass {
  46. MachineFunction *MF;
  47. unsigned LowBit;
  48. unsigned HighBit;
  49. public:
  50. static char ID;
  51. /// PassNum is the sequence number this pass is called, start from 1.
  52. MIRAddFSDiscriminators(FSDiscriminatorPass P = FSDiscriminatorPass::Pass1)
  53. : MachineFunctionPass(ID) {
  54. LowBit = getFSPassBitBegin(P);
  55. HighBit = getFSPassBitEnd(P);
  56. assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit");
  57. }
  58. StringRef getPassName() const override {
  59. return "Add FS discriminators in MIR";
  60. }
  61. /// getNumFSBBs() - Return the number of machine BBs that have FS samples.
  62. unsigned getNumFSBBs();
  63. /// getNumFSSamples() - Return the number of samples that have flow sensitive
  64. /// values.
  65. uint64_t getNumFSSamples();
  66. /// getMachineFunction - Return the current machine function.
  67. const MachineFunction *getMachineFunction() const { return MF; }
  68. private:
  69. bool runOnMachineFunction(MachineFunction &) override;
  70. };
  71. } // namespace llvm
  72. #endif // LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
  73. #ifdef __GNUC__
  74. #pragma GCC diagnostic pop
  75. #endif