LLVM  3.7.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/StringRef.h"
12 #include "llvm/ADT/Triple.h"
16 #include <algorithm>
17 
18 using namespace llvm;
19 
22  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
24  return Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
25 }
26 
28  FeatureBits = getFeatures(CPU, FS, ProcDesc, ProcFeatures);
29  if (!CPU.empty())
30  CPUSchedModel = &getSchedModelForCPU(CPU);
31  else
32  CPUSchedModel = &MCSchedModel::GetDefaultSchedModel();
33 }
34 
36  FeatureBits = getFeatures(CPU, "", ProcDesc, ProcFeatures);
37 }
38 
39 MCSubtargetInfo::MCSubtargetInfo(
40  const Triple &TT, StringRef C, StringRef FS,
42  const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR,
43  const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
44  const InstrStage *IS, const unsigned *OC, const unsigned *FP)
45  : TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD),
46  ProcSchedModels(ProcSched), WriteProcResTable(WPR), WriteLatencyTable(WL),
47  ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) {
48  InitMCProcessorInfo(CPU, FS);
49 }
50 
51 /// ToggleFeature - Toggle a feature and returns the re-computed feature
52 /// bits. This version does not change the implied bits.
54  FeatureBits.flip(FB);
55  return FeatureBits;
56 }
57 
59  FeatureBits ^= FB;
60  return FeatureBits;
61 }
62 
63 /// ToggleFeature - Toggle a feature and returns the re-computed feature
64 /// bits. This version will also change all implied bits.
67  FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures);
68  return FeatureBits;
69 }
70 
73  FeatureBits = Features.ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
74  return FeatureBits;
75 }
76 
78  assert(ProcSchedModels && "Processor machine model not available!");
79 
80  unsigned NumProcs = ProcDesc.size();
81 #ifndef NDEBUG
82  for (size_t i = 1; i < NumProcs; i++) {
83  assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&
84  "Processor machine model table is not sorted");
85  }
86 #endif
87 
88  // Find entry
89  const SubtargetInfoKV *Found =
90  std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
91  if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {
92  if (CPU != "help") // Don't error if the user asked for help.
93  errs() << "'" << CPU
94  << "' is not a recognized processor for this target"
95  << " (ignoring processor)\n";
97  }
98  assert(Found->Value && "Missing processor SchedModel value");
99  return *(const MCSchedModel *)Found->Value;
100 }
101 
104  const MCSchedModel SchedModel = getSchedModelForCPU(CPU);
105  return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
106 }
107 
108 /// Initialize an InstrItineraryData instance.
110  InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
111  ForwardingPaths);
112 }
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.
static void Found()
const FeatureBitset Features
SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary pointers. ...
FeatureBitset ApplyFeatureFlag(FeatureBitset Bits, StringRef Feature, ArrayRef< SubtargetFeatureKV > FeatureTable)
Apply the feature flag and return the newly updated feature bits.
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: ArrayRef.h:31
void setDefaultFeatures(StringRef CPU)
Set the features to the default for the given CPU.
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:228
FeatureBitset ToggleFeature(uint64_t FB)
ToggleFeature - Toggle a feature and returns the re-computed feature bits.
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...
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
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
Specify the number of cycles allowed after instruction issue before a particular use operand reads it...
Definition: MCSchedule.h:86
FeatureBitset ToggleFeature(FeatureBitset Bits, StringRef String, ArrayRef< SubtargetFeatureKV > FeatureTable)
ToggleFeature - Toggle a feature and returns the newly updated feature bits.
These values represent a non-pipelined step in the execution of an instruction.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetFeatureKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
FeatureBitset getFeatureBits(StringRef CPU, ArrayRef< SubtargetFeatureKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatureTable)
Get feature bits of a CPU.
Machine model for scheduling, bundling, and heuristics.
Definition: MCSchedule.h:136
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110