blob: 6231402f043ef698119985f249a52365496ccd36 [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
David Blaikieb3bde2e2017-11-17 01:07:10 +000014#include "llvm/CodeGen/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"
David Blaikie3f833ed2017-11-08 01:01:31 +000017#include "llvm/CodeGen/TargetInstrInfo.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000018#include "llvm/CodeGen/TargetSchedule.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000019#include "llvm/MC/MCInst.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000020#include "llvm/Support/Format.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000021#include "llvm/Support/raw_ostream.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
Chandler Carruthc58f2162018-01-22 22:05:25 +000041bool TargetSubtargetInfo::enableIndirectBrExpand() const {
42 return false;
43}
44
Andrew Trick108c88c2012-11-13 08:47:29 +000045bool TargetSubtargetInfo::enableMachineScheduler() const {
46 return false;
47}
48
Eric Christopher5f141b02015-03-11 22:56:10 +000049bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
50 return enableMachineScheduler();
51}
52
Quentin Colombet5caa6a22014-07-02 18:32:04 +000053bool TargetSubtargetInfo::enableRALocalReassignment(
54 CodeGenOpt::Level OptLevel) const {
55 return true;
56}
57
Marina Yatsinaf9371d82017-10-22 17:59:38 +000058bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
59 return false;
60}
61
Matthias Braun39a2afc2015-06-13 03:42:16 +000062bool TargetSubtargetInfo::enablePostRAScheduler() const {
Pete Cooper11759452014-09-02 17:43:54 +000063 return getSchedModel().PostRAScheduler;
David Goodwin0d412c22009-11-10 00:48:55 +000064}
65
Hal Finkelb350ffd2013-08-29 03:25:05 +000066bool TargetSubtargetInfo::useAA() const {
67 return false;
68}
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000069
70static std::string createSchedInfoStr(unsigned Latency,
Sanjay Patel5773ac32018-03-14 15:28:48 +000071 Optional<double> RThroughput) {
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000072 static const char *SchedPrefix = " sched: [";
73 std::string Comment;
74 raw_string_ostream CS(Comment);
Sanjay Patel5773ac32018-03-14 15:28:48 +000075 if (RThroughput.hasValue())
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000076 CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue())
77 << "]";
Sanjay Patel5773ac32018-03-14 15:28:48 +000078 else
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000079 CS << SchedPrefix << Latency << ":?]";
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000080 CS.flush();
81 return Comment;
82}
83
84/// Returns string representation of scheduler comment
85std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const {
86 if (MI.isPseudo() || MI.isTerminator())
87 return std::string();
88 // We don't cache TSchedModel because it depends on TargetInstrInfo
89 // that could be changed during the compilation
90 TargetSchedModel TSchedModel;
Sanjay Patel0d7df362018-04-08 19:56:04 +000091 TSchedModel.init(this);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000092 unsigned Latency = TSchedModel.computeInstrLatency(&MI);
Andrea Di Biagiob9acf132018-04-15 17:32:17 +000093 Optional<double> RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000094 return createSchedInfoStr(Latency, RThroughput);
95}
96
97/// Returns string representation of scheduler comment
98std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const {
99 // We don't cache TSchedModel because it depends on TargetInstrInfo
100 // that could be changed during the compilation
101 TargetSchedModel TSchedModel;
Sanjay Patel0d7df362018-04-08 19:56:04 +0000102 TSchedModel.init(this);
Andrew V. Tischenkod5659512017-08-01 09:15:43 +0000103 unsigned Latency;
104 if (TSchedModel.hasInstrSchedModel())
105 Latency = TSchedModel.computeInstrLatency(MCI.getOpcode());
106 else if (TSchedModel.hasInstrItineraries()) {
107 auto *ItinData = TSchedModel.getInstrItineraries();
108 Latency = ItinData->getStageLatency(
109 getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
110 } else
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000111 return std::string();
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000112 Optional<double> RThroughput =
Andrea Di Biagiob9acf132018-04-15 17:32:17 +0000113 TSchedModel.computeReciprocalThroughput(MCI.getOpcode());
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000114 return createSchedInfoStr(Latency, RThroughput);
115}
Matthias Braun5c290dc2018-01-19 03:16:36 +0000116
117void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
118}