blob: 859fac3cd63aa028e8171ef8403852ea298920c5 [file] [log] [blame]
Eugene Zelenko8361b0a2017-06-19 22:43:19 +00001//===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
Nate Begemanf26625e2005-07-12 01:41:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Nate Begemanf26625e2005-07-12 01:41:54 +00007//
8//===----------------------------------------------------------------------===//
9//
Matthias Braun7f423442016-11-22 22:09:03 +000010/// \file This file describes the general parts of a Subtarget.
Nate Begemanf26625e2005-07-12 01:41:54 +000011//
12//===----------------------------------------------------------------------===//
13
Andrew V. Tischenkod5659512017-08-01 09:15:43 +000014#include "llvm/Target/TargetSubtargetInfo.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000015#include "llvm/ADT/Optional.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000016#include "llvm/CodeGen/MachineInstr.h"
17#include "llvm/CodeGen/TargetSchedule.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000018#include "llvm/MC/MCInst.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000019#include "llvm/Support/Format.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000020#include "llvm/Support/raw_ostream.h"
Andrew V. Tischenkod5659512017-08-01 09:15:43 +000021#include "llvm/Target/TargetInstrInfo.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000022#include <string>
23
Nate Begemanf26625e2005-07-12 01:41:54 +000024using namespace llvm;
25
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000026TargetSubtargetInfo::TargetSubtargetInfo(
Daniel Sanders50f17232015-09-15 16:17:27 +000027 const Triple &TT, StringRef CPU, StringRef FS,
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000028 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 Begemanf26625e2005-07-12 01:41:54 +000034
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000035TargetSubtargetInfo::~TargetSubtargetInfo() = default;
David Goodwin0d412c22009-11-10 00:48:55 +000036
Robin Morisset59c23cd2014-08-21 21:50:01 +000037bool TargetSubtargetInfo::enableAtomicExpand() const {
Eric Christopherc40e5ed2014-06-19 21:03:04 +000038 return true;
39}
40
Andrew Trick108c88c2012-11-13 08:47:29 +000041bool TargetSubtargetInfo::enableMachineScheduler() const {
42 return false;
43}
44
Eric Christopher5f141b02015-03-11 22:56:10 +000045bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
46 return enableMachineScheduler();
47}
48
Quentin Colombet5caa6a22014-07-02 18:32:04 +000049bool TargetSubtargetInfo::enableRALocalReassignment(
50 CodeGenOpt::Level OptLevel) const {
51 return true;
52}
53
Matthias Braun39a2afc2015-06-13 03:42:16 +000054bool TargetSubtargetInfo::enablePostRAScheduler() const {
Pete Cooper11759452014-09-02 17:43:54 +000055 return getSchedModel().PostRAScheduler;
David Goodwin0d412c22009-11-10 00:48:55 +000056}
57
Hal Finkelb350ffd2013-08-29 03:25:05 +000058bool TargetSubtargetInfo::useAA() const {
59 return false;
60}
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000061
62static std::string createSchedInfoStr(unsigned Latency,
63 Optional<double> RThroughput) {
64 static const char *SchedPrefix = " sched: [";
65 std::string Comment;
66 raw_string_ostream CS(Comment);
67 if (Latency > 0 && RThroughput.hasValue())
68 CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue())
69 << "]";
70 else if (Latency > 0)
71 CS << SchedPrefix << Latency << ":?]";
72 else if (RThroughput.hasValue())
73 CS << SchedPrefix << "?:" << RThroughput.getValue() << "]";
74 CS.flush();
75 return Comment;
76}
77
78/// Returns string representation of scheduler comment
79std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const {
80 if (MI.isPseudo() || MI.isTerminator())
81 return std::string();
82 // We don't cache TSchedModel because it depends on TargetInstrInfo
83 // that could be changed during the compilation
84 TargetSchedModel TSchedModel;
85 TSchedModel.init(getSchedModel(), this, getInstrInfo());
86 unsigned Latency = TSchedModel.computeInstrLatency(&MI);
87 Optional<double> RThroughput = TSchedModel.computeInstrRThroughput(&MI);
88 return createSchedInfoStr(Latency, RThroughput);
89}
90
91/// Returns string representation of scheduler comment
92std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const {
93 // We don't cache TSchedModel because it depends on TargetInstrInfo
94 // that could be changed during the compilation
95 TargetSchedModel TSchedModel;
96 TSchedModel.init(getSchedModel(), this, getInstrInfo());
Andrew V. Tischenkod5659512017-08-01 09:15:43 +000097 unsigned Latency;
98 if (TSchedModel.hasInstrSchedModel())
99 Latency = TSchedModel.computeInstrLatency(MCI.getOpcode());
100 else if (TSchedModel.hasInstrItineraries()) {
101 auto *ItinData = TSchedModel.getInstrItineraries();
102 Latency = ItinData->getStageLatency(
103 getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
104 } else
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000105 return std::string();
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000106 Optional<double> RThroughput =
107 TSchedModel.computeInstrRThroughput(MCI.getOpcode());
108 return createSchedInfoStr(Latency, RThroughput);
109}