Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 1 | //===- TargetSubtargetInfo.cpp - General Target Information ----------------==// |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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 | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Matthias Braun | e436226 | 2016-11-22 22:09:03 +0000 | [diff] [blame] | 10 | /// \file This file describes the general parts of a Subtarget. |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Blaikie | e3a9b4c | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Optional.h" |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstr.h" |
David Blaikie | 4831923 | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/TargetInstrInfo.h" |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/TargetSchedule.h" |
Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInst.h" |
Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Format.h" |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Duncan P. N. Exon Smith | 16859aa | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 26 | TargetSubtargetInfo::TargetSubtargetInfo( |
Daniel Sanders | 47b167d | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 27 | const Triple &TT, StringRef CPU, StringRef FS, |
Duncan P. N. Exon Smith | 16859aa | 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 | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 34 | |
Eugene Zelenko | 810d1a0 | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 35 | TargetSubtargetInfo::~TargetSubtargetInfo() = default; |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 36 | |
Robin Morisset | cf165c3 | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 37 | bool TargetSubtargetInfo::enableAtomicExpand() const { |
Eric Christopher | d2f9358 | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 38 | return true; |
| 39 | } |
| 40 | |
Chandler Carruth | fd5a872 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 41 | bool TargetSubtargetInfo::enableIndirectBrExpand() const { |
| 42 | return false; |
| 43 | } |
| 44 | |
Andrew Trick | ad1cc1d | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 45 | bool TargetSubtargetInfo::enableMachineScheduler() const { |
| 46 | return false; |
| 47 | } |
| 48 | |
Eric Christopher | fba5b65 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 49 | bool TargetSubtargetInfo::enableJoinGlobalCopies() const { |
| 50 | return enableMachineScheduler(); |
| 51 | } |
| 52 | |
Quentin Colombet | 5599fde | 2014-07-02 18:32:04 +0000 | [diff] [blame] | 53 | bool TargetSubtargetInfo::enableRALocalReassignment( |
| 54 | CodeGenOpt::Level OptLevel) const { |
| 55 | return true; |
| 56 | } |
| 57 | |
Marina Yatsina | b76f989 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 58 | bool TargetSubtargetInfo::enableAdvancedRASplitCost() const { |
| 59 | return false; |
| 60 | } |
| 61 | |
Matthias Braun | 8ce6c58 | 2015-06-13 03:42:16 +0000 | [diff] [blame] | 62 | bool TargetSubtargetInfo::enablePostRAScheduler() const { |
Pete Cooper | 6de6c6a | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 63 | return getSchedModel().PostRAScheduler; |
David Goodwin | c2e8a7e | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Hal Finkel | 738073c | 2013-08-29 03:25:05 +0000 | [diff] [blame] | 66 | bool TargetSubtargetInfo::useAA() const { |
| 67 | return false; |
| 68 | } |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 69 | |
Sanjay Patel | 863443f | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 70 | static std::string createSchedInfoStr(unsigned Latency, double RThroughput) { |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 71 | static const char *SchedPrefix = " sched: ["; |
| 72 | std::string Comment; |
| 73 | raw_string_ostream CS(Comment); |
Sanjay Patel | 863443f | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 74 | if (RThroughput != 0.0) |
| 75 | CS << SchedPrefix << Latency << format(":%2.2f", RThroughput) |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 76 | << "]"; |
Sanjay Patel | a816f42 | 2018-03-14 15:28:48 +0000 | [diff] [blame] | 77 | else |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 78 | CS << SchedPrefix << Latency << ":?]"; |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 79 | CS.flush(); |
| 80 | return Comment; |
| 81 | } |
| 82 | |
| 83 | /// Returns string representation of scheduler comment |
| 84 | std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const { |
| 85 | if (MI.isPseudo() || MI.isTerminator()) |
| 86 | return std::string(); |
| 87 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 88 | // that could be changed during the compilation |
| 89 | TargetSchedModel TSchedModel; |
Sanjay Patel | e599cea | 2018-04-08 19:56:04 +0000 | [diff] [blame] | 90 | TSchedModel.init(this); |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 91 | unsigned Latency = TSchedModel.computeInstrLatency(&MI); |
Sanjay Patel | 863443f | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 92 | double RThroughput = TSchedModel.computeReciprocalThroughput(&MI); |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 93 | return createSchedInfoStr(Latency, RThroughput); |
| 94 | } |
| 95 | |
| 96 | /// Returns string representation of scheduler comment |
| 97 | std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const { |
| 98 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 99 | // that could be changed during the compilation |
| 100 | TargetSchedModel TSchedModel; |
Sanjay Patel | e599cea | 2018-04-08 19:56:04 +0000 | [diff] [blame] | 101 | TSchedModel.init(this); |
Andrew V. Tischenko | 052dd78 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 102 | unsigned Latency; |
| 103 | if (TSchedModel.hasInstrSchedModel()) |
Andrea Di Biagio | ae5fb65 | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 104 | Latency = TSchedModel.computeInstrLatency(MCI); |
Andrew V. Tischenko | 052dd78 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 105 | else if (TSchedModel.hasInstrItineraries()) { |
| 106 | auto *ItinData = TSchedModel.getInstrItineraries(); |
| 107 | Latency = ItinData->getStageLatency( |
| 108 | getInstrInfo()->get(MCI.getOpcode()).getSchedClass()); |
| 109 | } else |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 110 | return std::string(); |
Sanjay Patel | 863443f | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 111 | double RThroughput = TSchedModel.computeReciprocalThroughput(MCI); |
Andrew V. Tischenko | 3796561 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 112 | return createSchedInfoStr(Latency, RThroughput); |
| 113 | } |
Matthias Braun | 5d9e10f | 2018-01-19 03:16:36 +0000 | [diff] [blame] | 114 | |
| 115 | void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const { |
| 116 | } |