Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 1 | //===- TargetSubtargetInfo.cpp - General Target Information ----------------==// |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Matthias Braun | 7f42344 | 2016-11-22 22:09:03 +0000 | [diff] [blame] | 10 | /// \file This file describes the general parts of a Subtarget. |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Andrew V. Tischenko | d565951 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetSubtargetInfo.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Optional.h" |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstr.h" |
| 17 | #include "llvm/CodeGen/TargetSchedule.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInst.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Format.h" |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Andrew V. Tischenko | d565951 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetInstrInfo.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 26 | TargetSubtargetInfo::TargetSubtargetInfo( |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 27 | const Triple &TT, StringRef CPU, StringRef FS, |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 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 | } |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 34 | |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 35 | TargetSubtargetInfo::~TargetSubtargetInfo() = default; |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 36 | |
Robin Morisset | 59c23cd | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 37 | bool TargetSubtargetInfo::enableAtomicExpand() const { |
Eric Christopher | c40e5ed | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 38 | return true; |
| 39 | } |
| 40 | |
Andrew Trick | 108c88c | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 41 | bool TargetSubtargetInfo::enableMachineScheduler() const { |
| 42 | return false; |
| 43 | } |
| 44 | |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 45 | bool TargetSubtargetInfo::enableJoinGlobalCopies() const { |
| 46 | return enableMachineScheduler(); |
| 47 | } |
| 48 | |
Quentin Colombet | 5caa6a2 | 2014-07-02 18:32:04 +0000 | [diff] [blame] | 49 | bool TargetSubtargetInfo::enableRALocalReassignment( |
| 50 | CodeGenOpt::Level OptLevel) const { |
| 51 | return true; |
| 52 | } |
| 53 | |
Marina Yatsina | f9371d8 | 2017-10-22 17:59:38 +0000 | [diff] [blame^] | 54 | bool TargetSubtargetInfo::enableAdvancedRASplitCost() const { |
| 55 | return false; |
| 56 | } |
| 57 | |
Matthias Braun | 39a2afc | 2015-06-13 03:42:16 +0000 | [diff] [blame] | 58 | bool TargetSubtargetInfo::enablePostRAScheduler() const { |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 59 | return getSchedModel().PostRAScheduler; |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Hal Finkel | b350ffd | 2013-08-29 03:25:05 +0000 | [diff] [blame] | 62 | bool TargetSubtargetInfo::useAA() const { |
| 63 | return false; |
| 64 | } |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 65 | |
| 66 | static std::string createSchedInfoStr(unsigned Latency, |
| 67 | Optional<double> RThroughput) { |
| 68 | static const char *SchedPrefix = " sched: ["; |
| 69 | std::string Comment; |
| 70 | raw_string_ostream CS(Comment); |
| 71 | if (Latency > 0 && RThroughput.hasValue()) |
| 72 | CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue()) |
| 73 | << "]"; |
| 74 | else if (Latency > 0) |
| 75 | CS << SchedPrefix << Latency << ":?]"; |
| 76 | else if (RThroughput.hasValue()) |
| 77 | CS << SchedPrefix << "?:" << RThroughput.getValue() << "]"; |
| 78 | CS.flush(); |
| 79 | return Comment; |
| 80 | } |
| 81 | |
| 82 | /// Returns string representation of scheduler comment |
| 83 | std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const { |
| 84 | if (MI.isPseudo() || MI.isTerminator()) |
| 85 | return std::string(); |
| 86 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 87 | // that could be changed during the compilation |
| 88 | TargetSchedModel TSchedModel; |
| 89 | TSchedModel.init(getSchedModel(), this, getInstrInfo()); |
| 90 | unsigned Latency = TSchedModel.computeInstrLatency(&MI); |
| 91 | Optional<double> RThroughput = TSchedModel.computeInstrRThroughput(&MI); |
| 92 | return createSchedInfoStr(Latency, RThroughput); |
| 93 | } |
| 94 | |
| 95 | /// Returns string representation of scheduler comment |
| 96 | std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const { |
| 97 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 98 | // that could be changed during the compilation |
| 99 | TargetSchedModel TSchedModel; |
| 100 | TSchedModel.init(getSchedModel(), this, getInstrInfo()); |
Andrew V. Tischenko | d565951 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 101 | unsigned Latency; |
| 102 | if (TSchedModel.hasInstrSchedModel()) |
| 103 | Latency = TSchedModel.computeInstrLatency(MCI.getOpcode()); |
| 104 | else if (TSchedModel.hasInstrItineraries()) { |
| 105 | auto *ItinData = TSchedModel.getInstrItineraries(); |
| 106 | Latency = ItinData->getStageLatency( |
| 107 | getInstrInfo()->get(MCI.getOpcode()).getSchedClass()); |
| 108 | } else |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 109 | return std::string(); |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 110 | Optional<double> RThroughput = |
| 111 | TSchedModel.computeInstrRThroughput(MCI.getOpcode()); |
| 112 | return createSchedInfoStr(Latency, RThroughput); |
| 113 | } |