MIRFSDiscriminator.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/ADT/StringRef.h"
  24. #include "llvm/CodeGen/MachineFunction.h"
  25. #include "llvm/CodeGen/MachineFunctionPass.h"
  26. #include "llvm/Support/Discriminator.h"
  27. #include <cassert>
  28. #include <cstdint>
  29. namespace llvm {
  30. class MachineFunction;
  31. using namespace sampleprof;
  32. class MIRAddFSDiscriminators : public MachineFunctionPass {
  33. MachineFunction *MF;
  34. unsigned LowBit;
  35. unsigned HighBit;
  36. public:
  37. static char ID;
  38. /// PassNum is the sequence number this pass is called, start from 1.
  39. MIRAddFSDiscriminators(FSDiscriminatorPass P = FSDiscriminatorPass::Pass1)
  40. : MachineFunctionPass(ID) {
  41. LowBit = getFSPassBitBegin(P);
  42. HighBit = getFSPassBitEnd(P);
  43. assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit");
  44. }
  45. StringRef getPassName() const override {
  46. return "Add FS discriminators in MIR";
  47. }
  48. /// getNumFSBBs() - Return the number of machine BBs that have FS samples.
  49. unsigned getNumFSBBs();
  50. /// getNumFSSamples() - Return the number of samples that have flow sensitive
  51. /// values.
  52. uint64_t getNumFSSamples();
  53. /// getMachineFunction - Return the current machine function.
  54. const MachineFunction *getMachineFunction() const { return MF; }
  55. private:
  56. bool runOnMachineFunction(MachineFunction &) override;
  57. };
  58. } // namespace llvm
  59. #endif // LLVM_CODEGEN_MIRFSDISCRIMINATOR_H
  60. #ifdef __GNUC__
  61. #pragma GCC diagnostic pop
  62. #endif