1 //===-- MCSubtargetInfo.cpp - Subtarget Information -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCSubtargetInfo.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/MC/MCInstrItineraries.h"
14 #include "llvm/MC/SubtargetFeature.h"
15 #include "llvm/Support/raw_ostream.h"
20 /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented
21 /// with feature string). Recompute feature bits and scheduling model.
23 MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) {
24 SubtargetFeatures Features(FS);
25 FeatureBits = Features.getFeatureBits(CPU, ProcDesc, ProcFeatures);
26 InitCPUSchedModel(CPU);
30 MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) {
32 CPUSchedModel = getSchedModelForCPU(CPU);
34 CPUSchedModel = MCSchedModel::GetDefaultSchedModel();
38 MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef C, StringRef FS,
39 ArrayRef<SubtargetFeatureKV> PF,
40 ArrayRef<SubtargetFeatureKV> PD,
41 const SubtargetInfoKV *ProcSched,
42 const MCWriteProcResEntry *WPR,
43 const MCWriteLatencyEntry *WL,
44 const MCReadAdvanceEntry *RA,
52 ProcSchedModels = ProcSched;
53 WriteProcResTable = WPR;
54 WriteLatencyTable = WL;
55 ReadAdvanceTable = RA;
61 InitMCProcessorInfo(CPU, FS);
64 /// ToggleFeature - Toggle a feature and returns the re-computed feature
65 /// bits. This version does not change the implied bits.
66 uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) {
71 /// ToggleFeature - Toggle a feature and returns the re-computed feature
72 /// bits. This version will also change all implied bits.
73 uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
74 SubtargetFeatures Features;
75 FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures);
81 MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
82 assert(ProcSchedModels && "Processor machine model not available!");
84 unsigned NumProcs = ProcDesc.size();
86 for (size_t i = 1; i < NumProcs; i++) {
87 assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 &&
88 "Processor machine model table is not sorted");
93 const SubtargetInfoKV *Found =
94 std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU);
95 if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) {
96 if (CPU != "help") // Don't error if the user asked for help.
98 << "' is not a recognized processor for this target"
99 << " (ignoring processor)\n";
100 return MCSchedModel::GetDefaultSchedModel();
102 assert(Found->Value && "Missing processor SchedModel value");
103 return *(const MCSchedModel *)Found->Value;
107 MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
108 const MCSchedModel SchedModel = getSchedModelForCPU(CPU);
109 return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
112 /// Initialize an InstrItineraryData instance.
113 void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
115 InstrItineraryData(CPUSchedModel, Stages, OperandCycles, ForwardingPaths);