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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Matthias Braun | 7f42344 | 2016-11-22 22:09:03 +0000 | [diff] [blame] | 9 | /// \file This file describes the general parts of a Subtarget. |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/Optional.h" |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineInstr.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/TargetInstrInfo.h" |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 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" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 21 | #include <string> |
| 22 | |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 25 | TargetSubtargetInfo::TargetSubtargetInfo( |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 26 | const Triple &TT, StringRef CPU, StringRef FS, |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame] | 27 | ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD, |
| 28 | const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, |
| 29 | const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, |
| 30 | const InstrStage *IS, const unsigned *OC, const unsigned *FP) |
| 31 | : MCSubtargetInfo(TT, CPU, FS, PF, PD, ProcSched, WPR, WL, RA, IS, OC, FP) { |
| 32 | } |
Nate Begeman | f26625e | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 33 | |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame] | 34 | TargetSubtargetInfo::~TargetSubtargetInfo() = default; |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 35 | |
Robin Morisset | 59c23cd | 2014-08-21 21:50:01 +0000 | [diff] [blame] | 36 | bool TargetSubtargetInfo::enableAtomicExpand() const { |
Eric Christopher | c40e5ed | 2014-06-19 21:03:04 +0000 | [diff] [blame] | 37 | return true; |
| 38 | } |
| 39 | |
Chandler Carruth | c58f216 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 40 | bool TargetSubtargetInfo::enableIndirectBrExpand() const { |
| 41 | return false; |
| 42 | } |
| 43 | |
Andrew Trick | 108c88c | 2012-11-13 08:47:29 +0000 | [diff] [blame] | 44 | bool TargetSubtargetInfo::enableMachineScheduler() const { |
| 45 | return false; |
| 46 | } |
| 47 | |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 48 | bool TargetSubtargetInfo::enableJoinGlobalCopies() const { |
| 49 | return enableMachineScheduler(); |
| 50 | } |
| 51 | |
Quentin Colombet | 5caa6a2 | 2014-07-02 18:32:04 +0000 | [diff] [blame] | 52 | bool TargetSubtargetInfo::enableRALocalReassignment( |
| 53 | CodeGenOpt::Level OptLevel) const { |
| 54 | return true; |
| 55 | } |
| 56 | |
Marina Yatsina | f9371d8 | 2017-10-22 17:59:38 +0000 | [diff] [blame] | 57 | bool TargetSubtargetInfo::enableAdvancedRASplitCost() const { |
| 58 | return false; |
| 59 | } |
| 60 | |
Matthias Braun | 39a2afc | 2015-06-13 03:42:16 +0000 | [diff] [blame] | 61 | bool TargetSubtargetInfo::enablePostRAScheduler() const { |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 62 | return getSchedModel().PostRAScheduler; |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Hal Finkel | b350ffd | 2013-08-29 03:25:05 +0000 | [diff] [blame] | 65 | bool TargetSubtargetInfo::useAA() const { |
| 66 | return false; |
| 67 | } |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 68 | |
Sanjay Patel | 59313be | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 69 | static std::string createSchedInfoStr(unsigned Latency, double RThroughput) { |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 70 | static const char *SchedPrefix = " sched: ["; |
| 71 | std::string Comment; |
| 72 | raw_string_ostream CS(Comment); |
Sanjay Patel | 59313be | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 73 | if (RThroughput != 0.0) |
| 74 | CS << SchedPrefix << Latency << format(":%2.2f", RThroughput) |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 75 | << "]"; |
Sanjay Patel | 5773ac3 | 2018-03-14 15:28:48 +0000 | [diff] [blame] | 76 | else |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 77 | CS << SchedPrefix << Latency << ":?]"; |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 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; |
Sanjay Patel | 0d7df36 | 2018-04-08 19:56:04 +0000 | [diff] [blame] | 89 | TSchedModel.init(this); |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 90 | unsigned Latency = TSchedModel.computeInstrLatency(&MI); |
Sanjay Patel | 59313be | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 91 | double RThroughput = TSchedModel.computeReciprocalThroughput(&MI); |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 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; |
Sanjay Patel | 0d7df36 | 2018-04-08 19:56:04 +0000 | [diff] [blame] | 100 | TSchedModel.init(this); |
Andrew V. Tischenko | d565951 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 101 | unsigned Latency; |
| 102 | if (TSchedModel.hasInstrSchedModel()) |
Andrea Di Biagio | be8616f | 2018-05-31 13:30:42 +0000 | [diff] [blame] | 103 | Latency = TSchedModel.computeInstrLatency(MCI); |
Andrew V. Tischenko | d565951 | 2017-08-01 09:15:43 +0000 | [diff] [blame] | 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(); |
Sanjay Patel | 59313be | 2018-06-05 23:34:45 +0000 | [diff] [blame] | 110 | double RThroughput = TSchedModel.computeReciprocalThroughput(MCI); |
Andrew V. Tischenko | 75745d0 | 2017-04-14 07:44:23 +0000 | [diff] [blame] | 111 | return createSchedInfoStr(Latency, RThroughput); |
| 112 | } |
Matthias Braun | 5c290dc | 2018-01-19 03:16:36 +0000 | [diff] [blame] | 113 | |
| 114 | void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const { |
| 115 | } |