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 14 #include "llvm/CodeGen/TargetSubtargetInfo.h" 15 #include "llvm/ADT/Optional.h" 16 #include "llvm/CodeGen/MachineInstr.h" 17 #include "llvm/CodeGen/TargetInstrInfo.h" 18 #include "llvm/CodeGen/TargetSchedule.h" 19 #include "llvm/MC/MCInst.h" 20 #include "llvm/Support/Format.h" 21 #include "llvm/Support/raw_ostream.h" 22 #include <string> 23 24 using namespace llvm; 25 26 TargetSubtargetInfo::TargetSubtargetInfo( 27 const Triple &TT, StringRef CPU, StringRef FS, 28 ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD, 29 const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, 30 const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, 31 const InstrStage *IS, const unsigned *OC, const unsigned *FP) 32 : MCSubtargetInfo(TT, CPU, FS, PF, PD, ProcSched, WPR, WL, RA, IS, OC, FP) { 33 } 34 35 TargetSubtargetInfo::~TargetSubtargetInfo() = default; 36 37 bool TargetSubtargetInfo::enableAtomicExpand() const { 38 return true; 39 } 40 41 bool TargetSubtargetInfo::enableIndirectBrExpand() const { 42 return false; 43 } 44 45 bool TargetSubtargetInfo::enableMachineScheduler() const { 46 return false; 47 } 48 49 bool TargetSubtargetInfo::enableJoinGlobalCopies() const { 50 return enableMachineScheduler(); 51 } 52 53 bool TargetSubtargetInfo::enableRALocalReassignment( 54 CodeGenOpt::Level OptLevel) const { 55 return true; 56 } 57 58 bool TargetSubtargetInfo::enableAdvancedRASplitCost() const { 59 return false; 60 } 61 62 bool TargetSubtargetInfo::enablePostRAScheduler() const { 63 return getSchedModel().PostRAScheduler; 64 } 65 66 bool TargetSubtargetInfo::useAA() const { 67 return false; 68 } 69 70 static std::string createSchedInfoStr(unsigned Latency, 71 Optional<double> RThroughput) { 72 static const char *SchedPrefix = " sched: ["; 73 std::string Comment; 74 raw_string_ostream CS(Comment); 75 if (RThroughput.hasValue()) 76 CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue()) 77 << "]"; 78 else 79 CS << SchedPrefix << Latency << ":?]"; 80 CS.flush(); 81 return Comment; 82 } 83 84 /// Returns string representation of scheduler comment 85 std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const { 86 if (MI.isPseudo() || MI.isTerminator()) 87 return std::string(); 88 // We don't cache TSchedModel because it depends on TargetInstrInfo 89 // that could be changed during the compilation 90 TargetSchedModel TSchedModel; 91 TSchedModel.init(this); 92 unsigned Latency = TSchedModel.computeInstrLatency(&MI); 93 Optional<double> RThroughput = TSchedModel.computeInstrRThroughput(&MI); 94 return createSchedInfoStr(Latency, RThroughput); 95 } 96 97 /// Returns string representation of scheduler comment 98 std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const { 99 // We don't cache TSchedModel because it depends on TargetInstrInfo 100 // that could be changed during the compilation 101 TargetSchedModel TSchedModel; 102 TSchedModel.init(this); 103 unsigned Latency; 104 if (TSchedModel.hasInstrSchedModel()) 105 Latency = TSchedModel.computeInstrLatency(MCI.getOpcode()); 106 else if (TSchedModel.hasInstrItineraries()) { 107 auto *ItinData = TSchedModel.getInstrItineraries(); 108 Latency = ItinData->getStageLatency( 109 getInstrInfo()->get(MCI.getOpcode()).getSchedClass()); 110 } else 111 return std::string(); 112 Optional<double> RThroughput = 113 TSchedModel.computeInstrRThroughput(MCI.getOpcode()); 114 return createSchedInfoStr(Latency, RThroughput); 115 } 116 117 void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const { 118 } 119