blob: c9f90b88cac37c437635827d7a7754bb27e7e887 [file] [log] [blame]
Eugene Zelenko8361b0a2017-06-19 22:43:19 +00001//===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
Nate Begemanf26625e2005-07-12 01:41:54 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Begemanf26625e2005-07-12 01:41:54 +00006//
7//===----------------------------------------------------------------------===//
8//
Matthias Braun7f423442016-11-22 22:09:03 +00009/// \file This file describes the general parts of a Subtarget.
Nate Begemanf26625e2005-07-12 01:41:54 +000010//
11//===----------------------------------------------------------------------===//
12
David Blaikieb3bde2e2017-11-17 01:07:10 +000013#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000014#include "llvm/ADT/Optional.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000015#include "llvm/CodeGen/MachineInstr.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000016#include "llvm/CodeGen/TargetInstrInfo.h"
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000017#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"
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000021#include <string>
22
Nate Begemanf26625e2005-07-12 01:41:54 +000023using namespace llvm;
24
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000025TargetSubtargetInfo::TargetSubtargetInfo(
Daniel Sanders50f17232015-09-15 16:17:27 +000026 const Triple &TT, StringRef CPU, StringRef FS,
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +000027 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 Begemanf26625e2005-07-12 01:41:54 +000033
Eugene Zelenko8361b0a2017-06-19 22:43:19 +000034TargetSubtargetInfo::~TargetSubtargetInfo() = default;
David Goodwin0d412c22009-11-10 00:48:55 +000035
Robin Morisset59c23cd2014-08-21 21:50:01 +000036bool TargetSubtargetInfo::enableAtomicExpand() const {
Eric Christopherc40e5ed2014-06-19 21:03:04 +000037 return true;
38}
39
Chandler Carruthc58f2162018-01-22 22:05:25 +000040bool TargetSubtargetInfo::enableIndirectBrExpand() const {
41 return false;
42}
43
Andrew Trick108c88c2012-11-13 08:47:29 +000044bool TargetSubtargetInfo::enableMachineScheduler() const {
45 return false;
46}
47
Eric Christopher5f141b02015-03-11 22:56:10 +000048bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
49 return enableMachineScheduler();
50}
51
Quentin Colombet5caa6a22014-07-02 18:32:04 +000052bool TargetSubtargetInfo::enableRALocalReassignment(
53 CodeGenOpt::Level OptLevel) const {
54 return true;
55}
56
Marina Yatsinaf9371d82017-10-22 17:59:38 +000057bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
58 return false;
59}
60
Matthias Braun39a2afc2015-06-13 03:42:16 +000061bool TargetSubtargetInfo::enablePostRAScheduler() const {
Pete Cooper11759452014-09-02 17:43:54 +000062 return getSchedModel().PostRAScheduler;
David Goodwin0d412c22009-11-10 00:48:55 +000063}
64
Hal Finkelb350ffd2013-08-29 03:25:05 +000065bool TargetSubtargetInfo::useAA() const {
66 return false;
67}
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000068
Sanjay Patel59313be2018-06-05 23:34:45 +000069static std::string createSchedInfoStr(unsigned Latency, double RThroughput) {
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000070 static const char *SchedPrefix = " sched: [";
71 std::string Comment;
72 raw_string_ostream CS(Comment);
Sanjay Patel59313be2018-06-05 23:34:45 +000073 if (RThroughput != 0.0)
74 CS << SchedPrefix << Latency << format(":%2.2f", RThroughput)
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000075 << "]";
Sanjay Patel5773ac32018-03-14 15:28:48 +000076 else
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000077 CS << SchedPrefix << Latency << ":?]";
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000078 CS.flush();
79 return Comment;
80}
81
82/// Returns string representation of scheduler comment
83std::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 Patel0d7df362018-04-08 19:56:04 +000089 TSchedModel.init(this);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000090 unsigned Latency = TSchedModel.computeInstrLatency(&MI);
Sanjay Patel59313be2018-06-05 23:34:45 +000091 double RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000092 return createSchedInfoStr(Latency, RThroughput);
93}
94
95/// Returns string representation of scheduler comment
96std::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 Patel0d7df362018-04-08 19:56:04 +0000100 TSchedModel.init(this);
Andrew V. Tischenkod5659512017-08-01 09:15:43 +0000101 unsigned Latency;
102 if (TSchedModel.hasInstrSchedModel())
Andrea Di Biagiobe8616f2018-05-31 13:30:42 +0000103 Latency = TSchedModel.computeInstrLatency(MCI);
Andrew V. Tischenkod5659512017-08-01 09:15:43 +0000104 else if (TSchedModel.hasInstrItineraries()) {
105 auto *ItinData = TSchedModel.getInstrItineraries();
106 Latency = ItinData->getStageLatency(
107 getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
108 } else
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000109 return std::string();
Sanjay Patel59313be2018-06-05 23:34:45 +0000110 double RThroughput = TSchedModel.computeReciprocalThroughput(MCI);
Andrew V. Tischenko75745d02017-04-14 07:44:23 +0000111 return createSchedInfoStr(Latency, RThroughput);
112}
Matthias Braun5c290dc2018-01-19 03:16:36 +0000113
114void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
115}