xref: /freebsd-src/contrib/llvm-project/llvm/lib/MC/MCSubtargetInfo.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- MCSubtargetInfo.cpp - Subtarget Information ------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
100b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
110b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
120b57cec5SDimitry Andric #include "llvm/MC/MCInstrItineraries.h"
130b57cec5SDimitry Andric #include "llvm/MC/MCSchedule.h"
140b57cec5SDimitry Andric #include "llvm/Support/Format.h"
150b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
1606c3fb27SDimitry Andric #include "llvm/TargetParser/SubtargetFeature.h"
170b57cec5SDimitry Andric #include <algorithm>
180b57cec5SDimitry Andric #include <cassert>
190b57cec5SDimitry Andric #include <cstring>
20bdd1243dSDimitry Andric #include <optional>
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric using namespace llvm;
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric /// Find KV in array using binary search.
250b57cec5SDimitry Andric template <typename T>
260b57cec5SDimitry Andric static const T *Find(StringRef S, ArrayRef<T> A) {
270b57cec5SDimitry Andric   // Binary search the array
280b57cec5SDimitry Andric   auto F = llvm::lower_bound(A, S);
290b57cec5SDimitry Andric   // If not found then return NULL
300b57cec5SDimitry Andric   if (F == A.end() || StringRef(F->Key) != S) return nullptr;
310b57cec5SDimitry Andric   // Return the found array item
320b57cec5SDimitry Andric   return F;
330b57cec5SDimitry Andric }
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric /// For each feature that is (transitively) implied by this feature, set it.
360b57cec5SDimitry Andric static
370b57cec5SDimitry Andric void SetImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies,
380b57cec5SDimitry Andric                     ArrayRef<SubtargetFeatureKV> FeatureTable) {
390b57cec5SDimitry Andric   // OR the Implies bits in outside the loop. This allows the Implies for CPUs
400b57cec5SDimitry Andric   // which might imply features not in FeatureTable to use this.
410b57cec5SDimitry Andric   Bits |= Implies;
420b57cec5SDimitry Andric   for (const SubtargetFeatureKV &FE : FeatureTable)
430b57cec5SDimitry Andric     if (Implies.test(FE.Value))
440b57cec5SDimitry Andric       SetImpliedBits(Bits, FE.Implies.getAsBitset(), FeatureTable);
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric /// For each feature that (transitively) implies this feature, clear it.
480b57cec5SDimitry Andric static
490b57cec5SDimitry Andric void ClearImpliedBits(FeatureBitset &Bits, unsigned Value,
500b57cec5SDimitry Andric                       ArrayRef<SubtargetFeatureKV> FeatureTable) {
510b57cec5SDimitry Andric   for (const SubtargetFeatureKV &FE : FeatureTable) {
520b57cec5SDimitry Andric     if (FE.Implies.getAsBitset().test(Value)) {
530b57cec5SDimitry Andric       Bits.reset(FE.Value);
540b57cec5SDimitry Andric       ClearImpliedBits(Bits, FE.Value, FeatureTable);
550b57cec5SDimitry Andric     }
560b57cec5SDimitry Andric   }
570b57cec5SDimitry Andric }
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
600b57cec5SDimitry Andric                              ArrayRef<SubtargetFeatureKV> FeatureTable) {
610b57cec5SDimitry Andric   assert(SubtargetFeatures::hasFlag(Feature) &&
620b57cec5SDimitry Andric          "Feature flags should start with '+' or '-'");
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   // Find feature in table.
650b57cec5SDimitry Andric   const SubtargetFeatureKV *FeatureEntry =
660b57cec5SDimitry Andric       Find(SubtargetFeatures::StripFlag(Feature), FeatureTable);
670b57cec5SDimitry Andric   // If there is a match
680b57cec5SDimitry Andric   if (FeatureEntry) {
690b57cec5SDimitry Andric     // Enable/disable feature in bits
700b57cec5SDimitry Andric     if (SubtargetFeatures::isEnabled(Feature)) {
710b57cec5SDimitry Andric       Bits.set(FeatureEntry->Value);
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric       // For each feature that this implies, set it.
740b57cec5SDimitry Andric       SetImpliedBits(Bits, FeatureEntry->Implies.getAsBitset(), FeatureTable);
750b57cec5SDimitry Andric     } else {
760b57cec5SDimitry Andric       Bits.reset(FeatureEntry->Value);
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric       // For each feature that implies this, clear it.
790b57cec5SDimitry Andric       ClearImpliedBits(Bits, FeatureEntry->Value, FeatureTable);
800b57cec5SDimitry Andric     }
810b57cec5SDimitry Andric   } else {
820b57cec5SDimitry Andric     errs() << "'" << Feature << "' is not a recognized feature for this target"
830b57cec5SDimitry Andric            << " (ignoring feature)\n";
840b57cec5SDimitry Andric   }
850b57cec5SDimitry Andric }
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric /// Return the length of the longest entry in the table.
880b57cec5SDimitry Andric template <typename T>
890b57cec5SDimitry Andric static size_t getLongestEntryLength(ArrayRef<T> Table) {
900b57cec5SDimitry Andric   size_t MaxLen = 0;
910b57cec5SDimitry Andric   for (auto &I : Table)
920b57cec5SDimitry Andric     MaxLen = std::max(MaxLen, std::strlen(I.Key));
930b57cec5SDimitry Andric   return MaxLen;
940b57cec5SDimitry Andric }
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric /// Display help for feature and mcpu choices.
970b57cec5SDimitry Andric static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
980b57cec5SDimitry Andric                  ArrayRef<SubtargetFeatureKV> FeatTable) {
990b57cec5SDimitry Andric   // the static variable ensures that the help information only gets
1000b57cec5SDimitry Andric   // printed once even though a target machine creates multiple subtargets
1010b57cec5SDimitry Andric   static bool PrintOnce = false;
1020b57cec5SDimitry Andric   if (PrintOnce) {
1030b57cec5SDimitry Andric     return;
1040b57cec5SDimitry Andric   }
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   // Determine the length of the longest CPU and Feature entries.
1070b57cec5SDimitry Andric   unsigned MaxCPULen  = getLongestEntryLength(CPUTable);
1080b57cec5SDimitry Andric   unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   // Print the CPU table.
1110b57cec5SDimitry Andric   errs() << "Available CPUs for this target:\n\n";
1120b57cec5SDimitry Andric   for (auto &CPU : CPUTable)
1130b57cec5SDimitry Andric     errs() << format("  %-*s - Select the %s processor.\n", MaxCPULen, CPU.Key,
1140b57cec5SDimitry Andric                      CPU.Key);
1150b57cec5SDimitry Andric   errs() << '\n';
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   // Print the Feature table.
1180b57cec5SDimitry Andric   errs() << "Available features for this target:\n\n";
1190b57cec5SDimitry Andric   for (auto &Feature : FeatTable)
1200b57cec5SDimitry Andric     errs() << format("  %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
1210b57cec5SDimitry Andric   errs() << '\n';
1220b57cec5SDimitry Andric 
1230b57cec5SDimitry Andric   errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
1240b57cec5SDimitry Andric             "For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric   PrintOnce = true;
1270b57cec5SDimitry Andric }
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric /// Display help for mcpu choices only
1300b57cec5SDimitry Andric static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
1310b57cec5SDimitry Andric   // the static variable ensures that the help information only gets
1320b57cec5SDimitry Andric   // printed once even though a target machine creates multiple subtargets
1330b57cec5SDimitry Andric   static bool PrintOnce = false;
1340b57cec5SDimitry Andric   if (PrintOnce) {
1350b57cec5SDimitry Andric     return;
1360b57cec5SDimitry Andric   }
1370b57cec5SDimitry Andric 
1380b57cec5SDimitry Andric   // Print the CPU table.
1390b57cec5SDimitry Andric   errs() << "Available CPUs for this target:\n\n";
1400b57cec5SDimitry Andric   for (auto &CPU : CPUTable)
1410b57cec5SDimitry Andric     errs() << "\t" << CPU.Key << "\n";
1420b57cec5SDimitry Andric   errs() << '\n';
1430b57cec5SDimitry Andric 
1440b57cec5SDimitry Andric   errs() << "Use -mcpu or -mtune to specify the target's processor.\n"
14506c3fb27SDimitry Andric             "For example, clang --target=aarch64-unknown-linux-gnu "
1460b57cec5SDimitry Andric             "-mcpu=cortex-a35\n";
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric   PrintOnce = true;
1490b57cec5SDimitry Andric }
1500b57cec5SDimitry Andric 
151e8d8bef9SDimitry Andric static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
1520b57cec5SDimitry Andric                                  ArrayRef<SubtargetSubTypeKV> ProcDesc,
1530b57cec5SDimitry Andric                                  ArrayRef<SubtargetFeatureKV> ProcFeatures) {
1540b57cec5SDimitry Andric   SubtargetFeatures Features(FS);
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric   if (ProcDesc.empty() || ProcFeatures.empty())
1570b57cec5SDimitry Andric     return FeatureBitset();
1580b57cec5SDimitry Andric 
1595ffd83dbSDimitry Andric   assert(llvm::is_sorted(ProcDesc) && "CPU table is not sorted");
1605ffd83dbSDimitry Andric   assert(llvm::is_sorted(ProcFeatures) && "CPU features table is not sorted");
1610b57cec5SDimitry Andric   // Resulting bits
1620b57cec5SDimitry Andric   FeatureBitset Bits;
1630b57cec5SDimitry Andric 
1640b57cec5SDimitry Andric   // Check if help is needed
1650b57cec5SDimitry Andric   if (CPU == "help")
1660b57cec5SDimitry Andric     Help(ProcDesc, ProcFeatures);
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric   // Find CPU entry if CPU name is specified.
1690b57cec5SDimitry Andric   else if (!CPU.empty()) {
1700b57cec5SDimitry Andric     const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc);
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric     // If there is a match
1730b57cec5SDimitry Andric     if (CPUEntry) {
1740b57cec5SDimitry Andric       // Set the features implied by this CPU feature, if any.
1750b57cec5SDimitry Andric       SetImpliedBits(Bits, CPUEntry->Implies.getAsBitset(), ProcFeatures);
1760b57cec5SDimitry Andric     } else {
1770b57cec5SDimitry Andric       errs() << "'" << CPU << "' is not a recognized processor for this target"
1780b57cec5SDimitry Andric              << " (ignoring processor)\n";
1790b57cec5SDimitry Andric     }
1800b57cec5SDimitry Andric   }
1810b57cec5SDimitry Andric 
182e8d8bef9SDimitry Andric   if (!TuneCPU.empty()) {
183e8d8bef9SDimitry Andric     const SubtargetSubTypeKV *CPUEntry = Find(TuneCPU, ProcDesc);
184e8d8bef9SDimitry Andric 
185e8d8bef9SDimitry Andric     // If there is a match
186e8d8bef9SDimitry Andric     if (CPUEntry) {
187e8d8bef9SDimitry Andric       // Set the features implied by this CPU feature, if any.
188e8d8bef9SDimitry Andric       SetImpliedBits(Bits, CPUEntry->TuneImplies.getAsBitset(), ProcFeatures);
189e8d8bef9SDimitry Andric     } else if (TuneCPU != CPU) {
190e8d8bef9SDimitry Andric       errs() << "'" << TuneCPU << "' is not a recognized processor for this "
191e8d8bef9SDimitry Andric              << "target (ignoring processor)\n";
192e8d8bef9SDimitry Andric     }
193e8d8bef9SDimitry Andric   }
194e8d8bef9SDimitry Andric 
1950b57cec5SDimitry Andric   // Iterate through each feature
1960b57cec5SDimitry Andric   for (const std::string &Feature : Features.getFeatures()) {
1970b57cec5SDimitry Andric     // Check for help
1980b57cec5SDimitry Andric     if (Feature == "+help")
1990b57cec5SDimitry Andric       Help(ProcDesc, ProcFeatures);
2005ffd83dbSDimitry Andric     else if (Feature == "+cpuhelp")
2010b57cec5SDimitry Andric       cpuHelp(ProcDesc);
2020b57cec5SDimitry Andric     else
2030b57cec5SDimitry Andric       ApplyFeatureFlag(Bits, Feature, ProcFeatures);
2040b57cec5SDimitry Andric   }
2050b57cec5SDimitry Andric 
2060b57cec5SDimitry Andric   return Bits;
2070b57cec5SDimitry Andric }
2080b57cec5SDimitry Andric 
209e8d8bef9SDimitry Andric void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef TuneCPU,
210e8d8bef9SDimitry Andric                                           StringRef FS) {
211e8d8bef9SDimitry Andric   FeatureBits = getFeatures(CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
212fe6060f1SDimitry Andric   FeatureString = std::string(FS);
213fe6060f1SDimitry Andric 
214e8d8bef9SDimitry Andric   if (!TuneCPU.empty())
215e8d8bef9SDimitry Andric     CPUSchedModel = &getSchedModelForCPU(TuneCPU);
2160b57cec5SDimitry Andric   else
2175f757f3fSDimitry Andric     CPUSchedModel = &MCSchedModel::Default;
2180b57cec5SDimitry Andric }
2190b57cec5SDimitry Andric 
220e8d8bef9SDimitry Andric void MCSubtargetInfo::setDefaultFeatures(StringRef CPU, StringRef TuneCPU,
221e8d8bef9SDimitry Andric                                          StringRef FS) {
222e8d8bef9SDimitry Andric   FeatureBits = getFeatures(CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
223fe6060f1SDimitry Andric   FeatureString = std::string(FS);
2240b57cec5SDimitry Andric }
2250b57cec5SDimitry Andric 
226e8d8bef9SDimitry Andric MCSubtargetInfo::MCSubtargetInfo(const Triple &TT, StringRef C, StringRef TC,
227e8d8bef9SDimitry Andric                                  StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
2285ffd83dbSDimitry Andric                                  ArrayRef<SubtargetSubTypeKV> PD,
2290b57cec5SDimitry Andric                                  const MCWriteProcResEntry *WPR,
2305ffd83dbSDimitry Andric                                  const MCWriteLatencyEntry *WL,
2315ffd83dbSDimitry Andric                                  const MCReadAdvanceEntry *RA,
2325ffd83dbSDimitry Andric                                  const InstrStage *IS, const unsigned *OC,
2335ffd83dbSDimitry Andric                                  const unsigned *FP)
234e8d8bef9SDimitry Andric     : TargetTriple(TT), CPU(std::string(C)), TuneCPU(std::string(TC)),
235e8d8bef9SDimitry Andric       ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),
236e8d8bef9SDimitry Andric       WriteLatencyTable(WL), ReadAdvanceTable(RA), Stages(IS),
237e8d8bef9SDimitry Andric       OperandCycles(OC), ForwardingPaths(FP) {
238e8d8bef9SDimitry Andric   InitMCProcessorInfo(CPU, TuneCPU, FS);
2390b57cec5SDimitry Andric }
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) {
2420b57cec5SDimitry Andric   FeatureBits.flip(FB);
2430b57cec5SDimitry Andric   return FeatureBits;
2440b57cec5SDimitry Andric }
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) {
2470b57cec5SDimitry Andric   FeatureBits ^= FB;
2480b57cec5SDimitry Andric   return FeatureBits;
2490b57cec5SDimitry Andric }
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::SetFeatureBitsTransitively(
2520b57cec5SDimitry Andric   const FeatureBitset &FB) {
2530b57cec5SDimitry Andric   SetImpliedBits(FeatureBits, FB, ProcFeatures);
2540b57cec5SDimitry Andric   return FeatureBits;
2550b57cec5SDimitry Andric }
2560b57cec5SDimitry Andric 
2570b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::ClearFeatureBitsTransitively(
2580b57cec5SDimitry Andric   const FeatureBitset &FB) {
2590b57cec5SDimitry Andric   for (unsigned I = 0, E = FB.size(); I < E; I++) {
2600b57cec5SDimitry Andric     if (FB[I]) {
2610b57cec5SDimitry Andric       FeatureBits.reset(I);
2620b57cec5SDimitry Andric       ClearImpliedBits(FeatureBits, I, ProcFeatures);
2630b57cec5SDimitry Andric     }
2640b57cec5SDimitry Andric   }
2650b57cec5SDimitry Andric   return FeatureBits;
2660b57cec5SDimitry Andric }
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef Feature) {
2690b57cec5SDimitry Andric   // Find feature in table.
2700b57cec5SDimitry Andric   const SubtargetFeatureKV *FeatureEntry =
2710b57cec5SDimitry Andric       Find(SubtargetFeatures::StripFlag(Feature), ProcFeatures);
2720b57cec5SDimitry Andric   // If there is a match
2730b57cec5SDimitry Andric   if (FeatureEntry) {
2740b57cec5SDimitry Andric     if (FeatureBits.test(FeatureEntry->Value)) {
2750b57cec5SDimitry Andric       FeatureBits.reset(FeatureEntry->Value);
2760b57cec5SDimitry Andric       // For each feature that implies this, clear it.
2770b57cec5SDimitry Andric       ClearImpliedBits(FeatureBits, FeatureEntry->Value, ProcFeatures);
2780b57cec5SDimitry Andric     } else {
2790b57cec5SDimitry Andric       FeatureBits.set(FeatureEntry->Value);
2800b57cec5SDimitry Andric 
2810b57cec5SDimitry Andric       // For each feature that this implies, set it.
2820b57cec5SDimitry Andric       SetImpliedBits(FeatureBits, FeatureEntry->Implies.getAsBitset(),
2830b57cec5SDimitry Andric                      ProcFeatures);
2840b57cec5SDimitry Andric     }
2850b57cec5SDimitry Andric   } else {
2860b57cec5SDimitry Andric     errs() << "'" << Feature << "' is not a recognized feature for this target"
2870b57cec5SDimitry Andric            << " (ignoring feature)\n";
2880b57cec5SDimitry Andric   }
2890b57cec5SDimitry Andric 
2900b57cec5SDimitry Andric   return FeatureBits;
2910b57cec5SDimitry Andric }
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
2940b57cec5SDimitry Andric   ::ApplyFeatureFlag(FeatureBits, FS, ProcFeatures);
2950b57cec5SDimitry Andric   return FeatureBits;
2960b57cec5SDimitry Andric }
2970b57cec5SDimitry Andric 
2980b57cec5SDimitry Andric bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
2990b57cec5SDimitry Andric   SubtargetFeatures T(FS);
3000b57cec5SDimitry Andric   FeatureBitset Set, All;
3010b57cec5SDimitry Andric   for (std::string F : T.getFeatures()) {
3020b57cec5SDimitry Andric     ::ApplyFeatureFlag(Set, F, ProcFeatures);
3030b57cec5SDimitry Andric     if (F[0] == '-')
3040b57cec5SDimitry Andric       F[0] = '+';
3050b57cec5SDimitry Andric     ::ApplyFeatureFlag(All, F, ProcFeatures);
3060b57cec5SDimitry Andric   }
3070b57cec5SDimitry Andric   return (FeatureBits & All) == Set;
3080b57cec5SDimitry Andric }
3090b57cec5SDimitry Andric 
3100b57cec5SDimitry Andric const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
3115ffd83dbSDimitry Andric   assert(llvm::is_sorted(ProcDesc) &&
3120b57cec5SDimitry Andric          "Processor machine model table is not sorted");
3130b57cec5SDimitry Andric 
3140b57cec5SDimitry Andric   // Find entry
3150b57cec5SDimitry Andric   const SubtargetSubTypeKV *CPUEntry = Find(CPU, ProcDesc);
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric   if (!CPUEntry) {
3180b57cec5SDimitry Andric     if (CPU != "help") // Don't error if the user asked for help.
3190b57cec5SDimitry Andric       errs() << "'" << CPU
3200b57cec5SDimitry Andric              << "' is not a recognized processor for this target"
3210b57cec5SDimitry Andric              << " (ignoring processor)\n";
3225f757f3fSDimitry Andric     return MCSchedModel::Default;
3230b57cec5SDimitry Andric   }
3240b57cec5SDimitry Andric   assert(CPUEntry->SchedModel && "Missing processor SchedModel value");
3250b57cec5SDimitry Andric   return *CPUEntry->SchedModel;
3260b57cec5SDimitry Andric }
3270b57cec5SDimitry Andric 
3280b57cec5SDimitry Andric InstrItineraryData
3290b57cec5SDimitry Andric MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
3300b57cec5SDimitry Andric   const MCSchedModel &SchedModel = getSchedModelForCPU(CPU);
3310b57cec5SDimitry Andric   return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths);
3320b57cec5SDimitry Andric }
3330b57cec5SDimitry Andric 
3340b57cec5SDimitry Andric void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const {
3350b57cec5SDimitry Andric   InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles,
3360b57cec5SDimitry Andric                                   ForwardingPaths);
3370b57cec5SDimitry Andric }
3388bcb0991SDimitry Andric 
339*0fca6ea1SDimitry Andric std::vector<SubtargetFeatureKV>
340*0fca6ea1SDimitry Andric MCSubtargetInfo::getEnabledProcessorFeatures() const {
341*0fca6ea1SDimitry Andric   std::vector<SubtargetFeatureKV> EnabledFeatures;
342*0fca6ea1SDimitry Andric   auto IsEnabled = [&](const SubtargetFeatureKV &FeatureKV) {
343*0fca6ea1SDimitry Andric     return FeatureBits.test(FeatureKV.Value);
344*0fca6ea1SDimitry Andric   };
345*0fca6ea1SDimitry Andric   llvm::copy_if(ProcFeatures, std::back_inserter(EnabledFeatures), IsEnabled);
346*0fca6ea1SDimitry Andric   return EnabledFeatures;
347*0fca6ea1SDimitry Andric }
348*0fca6ea1SDimitry Andric 
349bdd1243dSDimitry Andric std::optional<unsigned> MCSubtargetInfo::getCacheSize(unsigned Level) const {
350bdd1243dSDimitry Andric   return std::nullopt;
3518bcb0991SDimitry Andric }
3528bcb0991SDimitry Andric 
353bdd1243dSDimitry Andric std::optional<unsigned>
3548bcb0991SDimitry Andric MCSubtargetInfo::getCacheAssociativity(unsigned Level) const {
355bdd1243dSDimitry Andric   return std::nullopt;
3568bcb0991SDimitry Andric }
3578bcb0991SDimitry Andric 
358bdd1243dSDimitry Andric std::optional<unsigned>
359bdd1243dSDimitry Andric MCSubtargetInfo::getCacheLineSize(unsigned Level) const {
360bdd1243dSDimitry Andric   return std::nullopt;
3618bcb0991SDimitry Andric }
3628bcb0991SDimitry Andric 
3638bcb0991SDimitry Andric unsigned MCSubtargetInfo::getPrefetchDistance() const {
3648bcb0991SDimitry Andric   return 0;
3658bcb0991SDimitry Andric }
3668bcb0991SDimitry Andric 
3678bcb0991SDimitry Andric unsigned MCSubtargetInfo::getMaxPrefetchIterationsAhead() const {
3688bcb0991SDimitry Andric   return UINT_MAX;
3698bcb0991SDimitry Andric }
3708bcb0991SDimitry Andric 
3715ffd83dbSDimitry Andric bool MCSubtargetInfo::enableWritePrefetching() const {
3725ffd83dbSDimitry Andric   return false;
3735ffd83dbSDimitry Andric }
3745ffd83dbSDimitry Andric 
3755ffd83dbSDimitry Andric unsigned MCSubtargetInfo::getMinPrefetchStride(unsigned NumMemAccesses,
3765ffd83dbSDimitry Andric                                                unsigned NumStridedMemAccesses,
3775ffd83dbSDimitry Andric                                                unsigned NumPrefetches,
3785ffd83dbSDimitry Andric                                                bool HasCall) const {
3798bcb0991SDimitry Andric   return 1;
3808bcb0991SDimitry Andric }
381bdd1243dSDimitry Andric 
382bdd1243dSDimitry Andric bool MCSubtargetInfo::shouldPrefetchAddressSpace(unsigned AS) const {
383bdd1243dSDimitry Andric   return !AS;
384bdd1243dSDimitry Andric }
385