LLVM  5.0.0
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 
14 #include "llvm/ADT/Optional.h"
17 #include "llvm/MC/MCInst.h"
19 #include "llvm/Support/Format.h"
21 #include <string>
22 
23 using namespace llvm;
24 
26  const Triple &TT, StringRef CPU, StringRef FS,
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 
35 
37  return true;
38 }
39 
41  return false;
42 }
43 
45  return enableMachineScheduler();
46 }
47 
49  CodeGenOpt::Level OptLevel) const {
50  return true;
51 }
52 
55 }
56 
58  return false;
59 }
60 
61 static std::string createSchedInfoStr(unsigned Latency,
62  Optional<double> RThroughput) {
63  static const char *SchedPrefix = " sched: [";
64  std::string Comment;
65  raw_string_ostream CS(Comment);
66  if (Latency > 0 && RThroughput.hasValue())
67  CS << SchedPrefix << Latency << format(":%2.2f", RThroughput.getValue())
68  << "]";
69  else if (Latency > 0)
70  CS << SchedPrefix << Latency << ":?]";
71  else if (RThroughput.hasValue())
72  CS << SchedPrefix << "?:" << RThroughput.getValue() << "]";
73  CS.flush();
74  return Comment;
75 }
76 
77 /// Returns string representation of scheduler comment
79  if (MI.isPseudo() || MI.isTerminator())
80  return std::string();
81  // We don't cache TSchedModel because it depends on TargetInstrInfo
82  // that could be changed during the compilation
83  TargetSchedModel TSchedModel;
84  TSchedModel.init(getSchedModel(), this, getInstrInfo());
85  unsigned Latency = TSchedModel.computeInstrLatency(&MI);
86  Optional<double> RThroughput = TSchedModel.computeInstrRThroughput(&MI);
87  return createSchedInfoStr(Latency, RThroughput);
88 }
89 
90 /// Returns string representation of scheduler comment
91 std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const {
92  // We don't cache TSchedModel because it depends on TargetInstrInfo
93  // that could be changed during the compilation
94  TargetSchedModel TSchedModel;
95  TSchedModel.init(getSchedModel(), this, getInstrInfo());
96  if (!TSchedModel.hasInstrSchedModel())
97  return std::string();
98  unsigned Latency = TSchedModel.computeInstrLatency(MCI.getOpcode());
99  Optional<double> RThroughput =
100  TSchedModel.computeInstrRThroughput(MCI.getOpcode());
101  return createSchedInfoStr(Latency, RThroughput);
102 }
virtual bool enableMachineScheduler() const
True if the subtarget should run MachineScheduler after aggressive coalescing.
static std::string createSchedInfoStr(unsigned Latency, Optional< double > RThroughput)
bool hasValue() const
Definition: Optional.h:133
virtual bool enableAtomicExpand() const
True if the subtarget should run the atomic expansion pass.
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction...
Definition: MachineInstr.h:424
void init(const MCSchedModel &sm, const TargetSubtargetInfo *sti, const TargetInstrInfo *tii)
Initialize the machine model for instruction scheduling.
virtual bool enablePostRAScheduler() const
True if the subtarget should run a scheduler after register allocation.
Used to provide key value pairs for CPU and arbitrary pointers.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
Definition: MachineInstr.h:448
Provide an instruction scheduling machine model to CodeGen passes.
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
virtual bool enableJoinGlobalCopies() const
True if the subtarget should enable joining global copies.
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:129
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
Definition: MCSchedule.h:55
Optional< double > computeInstrRThroughput(const MachineInstr *MI) const
Compute the reciprocal throughput of the given instruction.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool hasInstrSchedModel() const
Return true if this machine model includes an instruction-level scheduling model. ...
Specify the latency in cpu cycles for a particular scheduling class and def index.
Definition: MCSchedule.h:69
unsigned getOpcode() const
Definition: MCInst.h:168
Specify the number of cycles allowed after instruction issue before a particular use operand reads it...
Definition: MCSchedule.h:86
Representation of each machine instruction.
Definition: MachineInstr.h:59
These values represent a non-pipelined step in the execution of an instruction.
MCSubtargetInfo - Generic base class for all target subtargets.
std::string getSchedInfoStr(const MachineInstr &MI) const override
Returns string representation of scheduler comment.
virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const
True if the subtarget should run the local reassignment heuristic of the register allocator...
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
virtual const TargetInstrInfo * getInstrInfo() const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual bool useAA() const
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine, etc.).