Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +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 | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineInstr.h" |
| 15 | #include "llvm/CodeGen/TargetSchedule.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetSubtargetInfo.h" |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
| 20 | //--------------------------------------------------------------------------- |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 21 | // TargetSubtargetInfo Class |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 22 | // |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 23 | TargetSubtargetInfo::TargetSubtargetInfo( |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 24 | const Triple &TT, StringRef CPU, StringRef FS, |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 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 | } |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 31 | |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 32 | TargetSubtargetInfo::~TargetSubtargetInfo() {} |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 33 | |
Robin Morisset | 59c23cd | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 34 | bool TargetSubtargetInfo::enableAtomicExpand() const { |
Eric Christopher | c40e5ed | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 35 | return true; |
| 36 | } |
| 37 | |
Andrew Trick | 108c88c | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 38 | bool TargetSubtargetInfo::enableMachineScheduler() const { |
| 39 | return false; |
| 40 | } |
| 41 | |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 42 | bool TargetSubtargetInfo::enableJoinGlobalCopies() const { |
| 43 | return enableMachineScheduler(); |
| 44 | } |
| 45 | |
Quentin Colombet | 5caa6a2 | 2014-07-02 18:32:04 +0000 | [diff] [blame] | 46 | bool TargetSubtargetInfo::enableRALocalReassignment( |
| 47 | CodeGenOpt::Level OptLevel) const { |
| 48 | return true; |
| 49 | } |
| 50 | |
Matthias Braun | 39a2afc | 2015-06-13 03:42:16 +0000 | [diff] [blame] | 51 | bool TargetSubtargetInfo::enablePostRAScheduler() const { |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 52 | return getSchedModel().PostRAScheduler; |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Hal Finkel | b350ffd | 2013-08-29 03:25:05 +0000 | [diff] [blame] | 55 | bool TargetSubtargetInfo::useAA() const { |
| 56 | return false; |
| 57 | } |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 58 | |
| 59 | static std::string createSchedInfoStr(unsigned Latency, |
| 60 | Optional<double> RThroughput) { |
| 61 | static const char *SchedPrefix = " sched: ["; |
| 62 | std::string Comment; |
| 63 | raw_string_ostream CS(Comment); |
| 64 | if (Latency > 0 && RThroughput.hasValue()) |
| 65 | CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue()) |
| 66 | << "]"; |
| 67 | else if (Latency > 0) |
| 68 | CS << SchedPrefix << Latency << ":?]"; |
| 69 | else if (RThroughput.hasValue()) |
| 70 | CS << SchedPrefix << "?:" << RThroughput.getValue() << "]"; |
| 71 | CS.flush(); |
| 72 | return Comment; |
| 73 | } |
| 74 | |
| 75 | /// Returns string representation of scheduler comment |
| 76 | std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const { |
| 77 | if (MI.isPseudo() || MI.isTerminator()) |
| 78 | return std::string(); |
| 79 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 80 | // that could be changed during the compilation |
| 81 | TargetSchedModel TSchedModel; |
| 82 | TSchedModel.init(getSchedModel(), this, getInstrInfo()); |
| 83 | unsigned Latency = TSchedModel.computeInstrLatency(&MI); |
| 84 | Optional<double> RThroughput = TSchedModel.computeInstrRThroughput(&MI); |
| 85 | return createSchedInfoStr(Latency, RThroughput); |
| 86 | } |
| 87 | |
| 88 | /// Returns string representation of scheduler comment |
| 89 | std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const { |
| 90 | // We don't cache TSchedModel because it depends on TargetInstrInfo |
| 91 | // that could be changed during the compilation |
| 92 | TargetSchedModel TSchedModel; |
| 93 | TSchedModel.init(getSchedModel(), this, getInstrInfo()); |
| 94 | if (!TSchedModel.hasInstrSchedModel()) |
| 95 | return std::string(); |
| 96 | unsigned Latency = TSchedModel.computeInstrLatency(MCI.getOpcode()); |
| 97 | Optional<double> RThroughput = |
| 98 | TSchedModel.computeInstrRThroughput(MCI.getOpcode()); |
| 99 | return createSchedInfoStr(Latency, RThroughput); |
| 100 | } |