IncrementalSourceMgr.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===-------------------- IncrementalSourceMgr.cpp ------------------------===//
  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. /// \file
  10. /// This file defines some implementations for IncrementalSourceMgr.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/MCA/IncrementalSourceMgr.h"
  14. #ifndef NDEBUG
  15. #include "llvm/Support/Format.h"
  16. #endif
  17. using namespace llvm;
  18. using namespace llvm::mca;
  19. void IncrementalSourceMgr::clear() {
  20. Staging.clear();
  21. InstStorage.clear();
  22. TotalCounter = 0U;
  23. EOS = false;
  24. }
  25. void IncrementalSourceMgr::updateNext() {
  26. ++TotalCounter;
  27. Instruction *I = Staging.front();
  28. Staging.pop_front();
  29. I->reset();
  30. if (InstFreedCB)
  31. InstFreedCB(I);
  32. }
  33. #ifndef NDEBUG
  34. void IncrementalSourceMgr::printStatistic(raw_ostream &OS) {
  35. unsigned MaxInstStorageSize = InstStorage.size();
  36. if (MaxInstStorageSize <= TotalCounter) {
  37. auto Ratio = double(MaxInstStorageSize) / double(TotalCounter);
  38. OS << "Cache ratio = " << MaxInstStorageSize << " / " << TotalCounter
  39. << llvm::format(" (%.2f%%)", (1.0 - Ratio) * 100.0) << "\n";
  40. } else {
  41. OS << "Error: Number of created instructions "
  42. << "are larger than the number of issued instructions\n";
  43. }
  44. }
  45. #endif