MBFIWrapper.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/ADT/Optional.h"
  14. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  15. #include "llvm/CodeGen/MBFIWrapper.h"
  16. using namespace llvm;
  17. BlockFrequency MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const {
  18. auto I = MergedBBFreq.find(MBB);
  19. if (I != MergedBBFreq.end())
  20. return I->second;
  21. return MBFI.getBlockFreq(MBB);
  22. }
  23. void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
  24. BlockFrequency F) {
  25. MergedBBFreq[MBB] = F;
  26. }
  27. Optional<uint64_t>
  28. MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const {
  29. auto I = MergedBBFreq.find(MBB);
  30. // Modified block frequency also impacts profile count. So we should compute
  31. // profile count from new block frequency if it has been changed.
  32. if (I != MergedBBFreq.end())
  33. return MBFI.getProfileCountFromFreq(I->second.getFrequency());
  34. return MBFI.getBlockProfileCount(MBB);
  35. }
  36. raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
  37. const MachineBasicBlock *MBB) const {
  38. return MBFI.printBlockFreq(OS, getBlockFreq(MBB));
  39. }
  40. raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
  41. const BlockFrequency Freq) const {
  42. return MBFI.printBlockFreq(OS, Freq);
  43. }
  44. void MBFIWrapper::view(const Twine &Name, bool isSimple) {
  45. MBFI.view(Name, isSimple);
  46. }
  47. uint64_t MBFIWrapper::getEntryFreq() const {
  48. return MBFI.getEntryFreq();
  49. }