LLVM  8.0.1
TargetSubtargetInfo.cpp
Go to the documentation of this file.
1 //===- TargetSubtargetInfo.cpp - General Target Information ----------------==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file This file describes the general parts of a Subtarget.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/Optional.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/Support/Format.h"
22 #include <string>
23 
24 using namespace llvm;
25 
27  const Triple &TT, StringRef CPU, StringRef FS,
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 }
34 
36 
38  return true;
39 }
40 
42  return false;
43 }
44 
46  return false;
47 }
48 
50  return enableMachineScheduler();
51 }
52 
54  CodeGenOpt::Level OptLevel) const {
55  return true;
56 }
57 
59  return false;
60 }
61 
64 }
65 
67  return false;
68 }
69 
70 static std::string createSchedInfoStr(unsigned Latency, double RThroughput) {
71  static const char *SchedPrefix = " sched: [";
72  std::string Comment;
73  raw_string_ostream CS(Comment);
74  if (RThroughput != 0.0)
75  CS << SchedPrefix << Latency << format(":%2.2f", RThroughput)
76  << "]";
77  else
78  CS << SchedPrefix << Latency << ":?]";
79  CS.flush();
80  return Comment;
81 }
82 
83 /// Returns string representation of scheduler comment
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;
90  TSchedModel.init(this);
91  unsigned Latency = TSchedModel.computeInstrLatency(&MI);
92  double RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
93  return createSchedInfoStr(Latency, RThroughput);
94 }
95 
96 /// Returns string representation of scheduler comment
97 std::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;
101  TSchedModel.init(this);
102  unsigned Latency;
103  if (TSchedModel.hasInstrSchedModel())
104  Latency = TSchedModel.computeInstrLatency(MCI);
105  else if (TSchedModel.hasInstrItineraries()) {
106  auto *ItinData = TSchedModel.getInstrItineraries();
107  Latency = ItinData->getStageLatency(
108  getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
109  } else
110  return std::string();
111  double RThroughput = TSchedModel.computeReciprocalThroughput(MCI);
112  return createSchedInfoStr(Latency, RThroughput);
113 }
114 
116 }
virtual bool enableJoinGlobalCopies() const
True if the subtarget should enable joining global copies.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
double computeReciprocalThroughput(const MachineInstr *MI) const
Compute the reciprocal throughput of the given instruction.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
Used to provide key value pairs for CPU and arbitrary pointers.
SI optimize exec mask operations pre RA
Provide an instruction scheduling machine model to CodeGen passes.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
Definition: MachineInstr.h:649
const InstrItineraryData * getInstrItineraries() const
bool hasInstrSchedModel() const
Return true if this machine model includes an instruction-level scheduling model. ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
virtual const TargetInstrInfo * getInstrInfo() const
virtual void mirFileLoaded(MachineFunction &MF) const
This is called after a .mir file was loaded.
std::string getSchedInfoStr(const MachineInstr &MI) const
Returns string representation of scheduler comment.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
Definition: MCSchedule.h:64
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn&#39;t correspond to a real machine instruction...
Definition: MachineInstr.h:619
virtual bool enableIndirectBrExpand() const
True if the subtarget should run the indirectbr expansion pass.
void init(const TargetSubtargetInfo *TSInfo)
Initialize the machine model for instruction scheduling.
virtual bool enableMachineScheduler() const
True if the subtarget should run MachineScheduler after aggressive coalescing.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Specify the latency in cpu cycles for a particular scheduling class and def index.
Definition: MCSchedule.h:78
bool hasInstrItineraries() const
Return true if this machine model includes cycle-to-cycle itinerary data.
virtual bool enableAtomicExpand() const
True if the subtarget should run the atomic expansion pass.
Specify the number of cycles allowed after instruction issue before a particular use operand reads it...
Definition: MCSchedule.h:95
Representation of each machine instruction.
Definition: MachineInstr.h:64
virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const
True if the subtarget should run the local reassignment heuristic of the register allocator...
These values represent a non-pipelined step in the execution of an instruction.
Generic base class for all target subtargets.
static std::string createSchedInfoStr(unsigned Latency, double RThroughput)
virtual bool enablePostRAScheduler() const
True if the subtarget should run a scheduler after register allocation.
virtual bool enableAdvancedRASplitCost() const
True if the subtarget should consider the cost of local intervals created by a split candidate when c...
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:483
IRTranslator LLVM IR MI
virtual bool useAA() const
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine, etc.).
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned getOpcode() const
Definition: MCInst.h:174
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget&#39;s CPU.