TargetSubtargetInfo.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. /// \file This file describes the general parts of a Subtarget.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  14. #include "llvm/ADT/Optional.h"
  15. #include "llvm/CodeGen/MachineInstr.h"
  16. #include "llvm/CodeGen/TargetInstrInfo.h"
  17. #include "llvm/CodeGen/TargetSchedule.h"
  18. #include "llvm/MC/MCInst.h"
  19. #include "llvm/Support/Format.h"
  20. #include "llvm/Support/raw_ostream.h"
  21. #include <string>
  22. using namespace llvm;
  23. TargetSubtargetInfo::TargetSubtargetInfo(
  24. const Triple &TT, StringRef CPU, StringRef FS,
  25. ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD,
  26. const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
  27. const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
  28. const InstrStage *IS, const unsigned *OC, const unsigned *FP)
  29. : MCSubtargetInfo(TT, CPU, FS, PF, PD, ProcSched, WPR, WL, RA, IS, OC, FP) {
  30. }
  31. TargetSubtargetInfo::~TargetSubtargetInfo() = default;
  32. bool TargetSubtargetInfo::enableAtomicExpand() const {
  33. return true;
  34. }
  35. bool TargetSubtargetInfo::enableIndirectBrExpand() const {
  36. return false;
  37. }
  38. bool TargetSubtargetInfo::enableMachineScheduler() const {
  39. return false;
  40. }
  41. bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
  42. return enableMachineScheduler();
  43. }
  44. bool TargetSubtargetInfo::enableRALocalReassignment(
  45. CodeGenOpt::Level OptLevel) const {
  46. return true;
  47. }
  48. bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
  49. return false;
  50. }
  51. bool TargetSubtargetInfo::enablePostRAScheduler() const {
  52. return getSchedModel().PostRAScheduler;
  53. }
  54. bool TargetSubtargetInfo::useAA() const {
  55. return false;
  56. }
  57. static std::string createSchedInfoStr(unsigned Latency,
  58. Optional<double> RThroughput) {
  59. static const char *SchedPrefix = " sched: [";
  60. std::string Comment;
  61. raw_string_ostream CS(Comment);
  62. if (RThroughput.hasValue())
  63. CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue())
  64. << "]";
  65. else
  66. CS << SchedPrefix << Latency << ":?]";
  67. CS.flush();
  68. return Comment;
  69. }
  70. /// Returns string representation of scheduler comment
  71. std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const {
  72. if (MI.isPseudo() || MI.isTerminator())
  73. return std::string();
  74. // We don't cache TSchedModel because it depends on TargetInstrInfo
  75. // that could be changed during the compilation
  76. TargetSchedModel TSchedModel;
  77. TSchedModel.init(this);
  78. unsigned Latency = TSchedModel.computeInstrLatency(&MI);
  79. Optional<double> RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
  80. return createSchedInfoStr(Latency, RThroughput);
  81. }
  82. /// Returns string representation of scheduler comment
  83. std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const {
  84. // We don't cache TSchedModel because it depends on TargetInstrInfo
  85. // that could be changed during the compilation
  86. TargetSchedModel TSchedModel;
  87. TSchedModel.init(this);
  88. unsigned Latency;
  89. if (TSchedModel.hasInstrSchedModel())
  90. Latency = TSchedModel.computeInstrLatency(MCI);
  91. else if (TSchedModel.hasInstrItineraries()) {
  92. auto *ItinData = TSchedModel.getInstrItineraries();
  93. Latency = ItinData->getStageLatency(
  94. getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
  95. } else
  96. return std::string();
  97. Optional<double> RThroughput =
  98. TSchedModel.computeReciprocalThroughput(MCI);
  99. return createSchedInfoStr(Latency, RThroughput);
  100. }
  101. void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
  102. }