blob: fa29c05fd6c2accf79daf4e0fd0208bc188a9604 [file] [log] [blame]
Eugene Zelenko810d1a02017-06-19 22:43:19 +00001//===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
Nate Begemanfb5792f2005-07-12 01:41:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Begemanfb5792f2005-07-12 01:41:54 +00007//
8//===----------------------------------------------------------------------===//
9//
Matthias Braune4362262016-11-22 22:09:03 +000010/// \file This file describes the general parts of a Subtarget.
Nate Begemanfb5792f2005-07-12 01:41:54 +000011//
12//===----------------------------------------------------------------------===//
13
David Blaikiee3a9b4c2017-11-17 01:07:10 +000014#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko810d1a02017-06-19 22:43:19 +000015#include "llvm/ADT/Optional.h"
Andrew V. Tischenko37965612017-04-14 07:44:23 +000016#include "llvm/CodeGen/MachineInstr.h"
David Blaikie48319232017-11-08 01:01:31 +000017#include "llvm/CodeGen/TargetInstrInfo.h"
Andrew V. Tischenko37965612017-04-14 07:44:23 +000018#include "llvm/CodeGen/TargetSchedule.h"
Eugene Zelenko810d1a02017-06-19 22:43:19 +000019#include "llvm/MC/MCInst.h"
Eugene Zelenko810d1a02017-06-19 22:43:19 +000020#include "llvm/Support/Format.h"
Andrew V. Tischenko37965612017-04-14 07:44:23 +000021#include "llvm/Support/raw_ostream.h"
Eugene Zelenko810d1a02017-06-19 22:43:19 +000022#include <string>
23
Nate Begemanfb5792f2005-07-12 01:41:54 +000024using namespace llvm;
25
Duncan P. N. Exon Smith16859aa2015-07-10 22:43:42 +000026TargetSubtargetInfo::TargetSubtargetInfo(
Daniel Sanders47b167d2015-09-15 16:17:27 +000027 const Triple &TT, StringRef CPU, StringRef FS,
Duncan P. N. Exon Smith16859aa2015-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 Begemanfb5792f2005-07-12 01:41:54 +000034
Eugene Zelenko810d1a02017-06-19 22:43:19 +000035TargetSubtargetInfo::~TargetSubtargetInfo() = default;
David Goodwinc2e8a7e2009-11-10 00:48:55 +000036
Robin Morissetcf165c32014-08-21 21:50:01 +000037bool TargetSubtargetInfo::enableAtomicExpand() const {
Eric Christopherd2f93582014-06-19 21:03:04 +000038 return true;
39}
40
Chandler Carruthfd5a8722018-01-22 22:05:25 +000041bool TargetSubtargetInfo::enableIndirectBrExpand() const {
42 return false;
43}
44
Andrew Trickad1cc1d2012-11-13 08:47:29 +000045bool TargetSubtargetInfo::enableMachineScheduler() const {
46 return false;
47}
48
Eric Christopherfba5b652015-03-11 22:56:10 +000049bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
50 return enableMachineScheduler();
51}
52
Quentin Colombet5599fde2014-07-02 18:32:04 +000053bool TargetSubtargetInfo::enableRALocalReassignment(
54 CodeGenOpt::Level OptLevel) const {
55 return true;
56}
57
Marina Yatsinab76f9892017-10-22 17:59:38 +000058bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
59 return false;
60}
61
Matthias Braun8ce6c582015-06-13 03:42:16 +000062bool TargetSubtargetInfo::enablePostRAScheduler() const {
Pete Cooper6de6c6a2014-09-02 17:43:54 +000063 return getSchedModel().PostRAScheduler;
David Goodwinc2e8a7e2009-11-10 00:48:55 +000064}
65
Hal Finkel738073c2013-08-29 03:25:05 +000066bool TargetSubtargetInfo::useAA() const {
67 return false;
68}
Andrew V. Tischenko37965612017-04-14 07:44:23 +000069
Sanjay Patel863443f2018-06-05 23:34:45 +000070static std::string createSchedInfoStr(unsigned Latency, double RThroughput) {
Andrew V. Tischenko37965612017-04-14 07:44:23 +000071 static const char *SchedPrefix = " sched: [";
72 std::string Comment;
73 raw_string_ostream CS(Comment);
Sanjay Patel863443f2018-06-05 23:34:45 +000074 if (RThroughput != 0.0)
75 CS << SchedPrefix << Latency << format(":%2.2f", RThroughput)
Andrew V. Tischenko37965612017-04-14 07:44:23 +000076 << "]";
Sanjay Patela816f422018-03-14 15:28:48 +000077 else
Andrew V. Tischenko37965612017-04-14 07:44:23 +000078 CS << SchedPrefix << Latency << ":?]";
Andrew V. Tischenko37965612017-04-14 07:44:23 +000079 CS.flush();
80 return Comment;
81}
82
83/// Returns string representation of scheduler comment
84std::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 Patele599cea2018-04-08 19:56:04 +000090 TSchedModel.init(this);
Andrew V. Tischenko37965612017-04-14 07:44:23 +000091 unsigned Latency = TSchedModel.computeInstrLatency(&MI);
Sanjay Patel863443f2018-06-05 23:34:45 +000092 double RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
Andrew V. Tischenko37965612017-04-14 07:44:23 +000093 return createSchedInfoStr(Latency, RThroughput);
94}
95
96/// Returns string representation of scheduler comment
97std::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 Patele599cea2018-04-08 19:56:04 +0000101 TSchedModel.init(this);
Andrew V. Tischenko052dd782017-08-01 09:15:43 +0000102 unsigned Latency;
103 if (TSchedModel.hasInstrSchedModel())
Andrea Di Biagioae5fb652018-05-31 13:30:42 +0000104 Latency = TSchedModel.computeInstrLatency(MCI);
Andrew V. Tischenko052dd782017-08-01 09:15:43 +0000105 else if (TSchedModel.hasInstrItineraries()) {
106 auto *ItinData = TSchedModel.getInstrItineraries();
107 Latency = ItinData->getStageLatency(
108 getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
109 } else
Andrew V. Tischenko37965612017-04-14 07:44:23 +0000110 return std::string();
Sanjay Patel863443f2018-06-05 23:34:45 +0000111 double RThroughput = TSchedModel.computeReciprocalThroughput(MCI);
Andrew V. Tischenko37965612017-04-14 07:44:23 +0000112 return createSchedInfoStr(Latency, RThroughput);
113}
Matthias Braun5d9e10f2018-01-19 03:16:36 +0000114
115void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
116}