LLVM  5.0.0
MCSubtargetInfo.cpp
Go to the documentation of this file.
1 //===- MCSubtargetInfo.cpp - Subtarget 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 
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/StringRef.h"
14 #include "llvm/MC/MCSchedule.h"
17 #include <algorithm>
18 #include <cassert>
19 #include <cstring>
20 
21 using namespace llvm;
22 
25  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
27  return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
28 }
29 
31  FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
32  if (!CPU.empty())
33  CPUSchedModel = &getSchedModelForCPU(CPU);
34  else
35  CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
36 }
37 
39  FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
40 }
41 
43  const Triple &TT, StringRef C, StringRef FS,
45  const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
46  const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
47  const InstrStage *IS, const unsigned *OC, const unsigned *FP)
48  : TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD),
49  ProcSchedModels(ProcSched), WriteProcResTable(WPR), WriteLatencyTable(WL),
50  ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
51  InitMCProcessorInfo(CPU, FS);
52 }
53 
54 /// ToggleFeature - Toggle a feature and returns the re-computed feature
55 /// bits. This version does not change the implied bits.
57  FeatureBits.flip(FB);
58  return FeatureBits;
59 }
60 
62  FeatureBits ^= FB;
63  return FeatureBits;
64 }
65 
66 /// ToggleFeature - Toggle a feature and returns the re-computed feature
67 /// bits. This version will also change all implied bits.
69  SubtargetFeatures::ToggleFeature(FeatureBits, FS, ProcFeatures);
70  return FeatureBits;
71 }
72 
74  SubtargetFeatures::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
75  return FeatureBits;
76 }
77 
79  assert(ProcSchedModels && "Processor machine model not available!");
80 
81  ArrayRef<SubtargetInfoKV> SchedModels(ProcSchedModels, ProcDesc.size());
82 
83  assert(std::is_sorted(SchedModels.begin(), SchedModels.end(),
84  [](const SubtargetInfoKV &LHS, const SubtargetInfoKV &RHS) {
85  return strcmp(LHS.Key, RHS.Key) < 0;
86  }) &&
87  "Processor machine model table is not sorted");
88 
89  // Find entry
90  auto Found =
91  std::lower_bound(SchedModels.begin(), SchedModels.end(), CPU);
92  if (Found == SchedModels.end() || StringRef(Found->Key) != CPU) {
93  if (CPU != "help") // Don't error if the user asked for help.
94  errs() << "'" << CPU
95  << "' is not a recognized processor for this target"
96  << " (ignoring processor)\n";
98  }
99  assert(Found->Value && "Missing processor SchedModel value");
100  return *(const MCSchedModel *)Found->Value;
101 }
102 
105  const MCSchedModel SchedModel = getSchedModelForCPU(CPU);
106  return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
107 }
108 
109 /// Initialize an InstrItineraryData instance.
111  InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
112  ForwardingPaths);
113 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const
getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
const char * Key
K-V key string.
Used to provide key value pairs for CPU and arbitrary pointers.
void initInstrItins(InstrItineraryData &InstrItins) const
Initialize an InstrItineraryData instance.
const MCSchedModel & getSchedModelForCPU(StringRef CPU) const
getSchedModelForCPU - Get the machine model of a CPU.
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
Itinerary data supplied by a subtarget to be used by a target.
void InitMCProcessorInfo(StringRef CPU, StringRef FS)
Initialize the scheduling model and feature bits.
static const MCSchedModel & GetDefaultSchedModel()
Returns the default initialized model.
Definition: MCSchedule.h:227
FeatureBitset ToggleFeature(uint64_t FB)
ToggleFeature - Toggle a feature and returns the re-computed feature bits.
Container class for subtarget features.
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
Definition: MCSchedule.h:55
FeatureBitset ApplyFeatureFlag(StringRef FS)
Apply a feature flag and return the re-computed feature bits, including all feature bits implied by t...
static void ToggleFeature(FeatureBitset &Bits, StringRef String, ArrayRef< SubtargetFeatureKV > FeatureTable)
Toggles a feature and update the feature bits.
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:69
Manages the enabling and disabling of subtarget specific features.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
Specify the number of cycles allowed after instruction issue before a particular use operand reads it...
Definition: MCSchedule.h:86
These values represent a non-pipelined step in the execution of an instruction.
#define C
Definition: LargeTest.cpp:25
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, ArrayRef< SubtargetFeatureKV > FeatureTable)
Applies the feature flag and update the feature bits.
const FeatureBitset Features
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetFeatureKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
FeatureBitset getFeatureBits(StringRef CPU, ArrayRef< SubtargetFeatureKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatureTable)
Returns feature bits of a CPU.
Machine model for scheduling, bundling, and heuristics.
Definition: MCSchedule.h:136
void setDefaultFeatures(StringRef CPU, StringRef FS)
Set the features to the default for the given CPU with an appended feature string.