1 //===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file This file describes the general parts of a Subtarget.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/CodeGen/TargetSubtargetInfo.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/CodeGen/MachineInstr.h"
16 #include "llvm/CodeGen/TargetInstrInfo.h"
17 #include "llvm/CodeGen/TargetSchedule.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/Support/Format.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include <string>
22 
23 using namespace llvm;
24 
25 TargetSubtargetInfo::TargetSubtargetInfo(
26     const Triple &TT, StringRef CPU, StringRef FS,
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 }
33 
34 TargetSubtargetInfo::~TargetSubtargetInfo() = default;
35 
36 bool TargetSubtargetInfo::enableAtomicExpand() const {
37   return true;
38 }
39 
40 bool TargetSubtargetInfo::enableIndirectBrExpand() const {
41   return false;
42 }
43 
44 bool TargetSubtargetInfo::enableMachineScheduler() const {
45   return false;
46 }
47 
48 bool TargetSubtargetInfo::enableJoinGlobalCopies() const {
49   return enableMachineScheduler();
50 }
51 
52 bool TargetSubtargetInfo::enableRALocalReassignment(
53     CodeGenOpt::Level OptLevel) const {
54   return true;
55 }
56 
57 bool TargetSubtargetInfo::enableAdvancedRASplitCost() const {
58   return false;
59 }
60 
61 bool TargetSubtargetInfo::enablePostRAScheduler() const {
62   return getSchedModel().PostRAScheduler;
63 }
64 
65 bool TargetSubtargetInfo::useAA() const {
66   return false;
67 }
68 
69 static std::string createSchedInfoStr(unsigned Latency, double RThroughput) {
70   static const char *SchedPrefix = " sched: [";
71   std::string Comment;
72   raw_string_ostream CS(Comment);
73   if (RThroughput != 0.0)
74     CS << SchedPrefix << Latency << format(":%2.2f", RThroughput)
75        << "]";
76   else
77     CS << SchedPrefix << Latency << ":?]";
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;
89   TSchedModel.init(this);
90   unsigned Latency = TSchedModel.computeInstrLatency(&MI);
91   double RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
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;
100   TSchedModel.init(this);
101   unsigned Latency;
102   if (TSchedModel.hasInstrSchedModel())
103     Latency = TSchedModel.computeInstrLatency(MCI);
104   else if (TSchedModel.hasInstrItineraries()) {
105     auto *ItinData = TSchedModel.getInstrItineraries();
106     Latency = ItinData->getStageLatency(
107         getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
108   } else
109     return std::string();
110   double RThroughput = TSchedModel.computeReciprocalThroughput(MCI);
111   return createSchedInfoStr(Latency, RThroughput);
112 }
113 
114 void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
115 }
116