MBFIWrapper.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===- MBFIWrapper.cpp - MachineBlockFrequencyInfo wrapper ----------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This class keeps track of branch frequencies of newly created blocks and
  10. // tail-merged blocks. Used by the TailDuplication and MachineBlockPlacement.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MBFIWrapper.h"
  14. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  15. using namespace llvm;
  16. BlockFrequency MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const {
  17. auto I = MergedBBFreq.find(MBB);
  18. if (I != MergedBBFreq.end())
  19. return I->second;
  20. return MBFI.getBlockFreq(MBB);
  21. }
  22. void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
  23. BlockFrequency F) {
  24. MergedBBFreq[MBB] = F;
  25. }
  26. Optional<uint64_t>
  27. MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const {
  28. auto I = MergedBBFreq.find(MBB);
  29. // Modified block frequency also impacts profile count. So we should compute
  30. // profile count from new block frequency if it has been changed.
  31. if (I != MergedBBFreq.end())
  32. return MBFI.getProfileCountFromFreq(I->second.getFrequency());
  33. return MBFI.getBlockProfileCount(MBB);
  34. }
  35. raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
  36. const MachineBasicBlock *MBB) const {
  37. return MBFI.printBlockFreq(OS, getBlockFreq(MBB));
  38. }
  39. raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
  40. const BlockFrequency Freq) const {
  41. return MBFI.printBlockFreq(OS, Freq);
  42. }
  43. void MBFIWrapper::view(const Twine &Name, bool isSimple) {
  44. MBFI.view(Name, isSimple);
  45. }
  46. uint64_t MBFIWrapper::getEntryFreq() const {
  47. return MBFI.getEntryFreq();
  48. }