Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 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 | |
| 10 | #include "llvm/MC/MCSubtargetInfo.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/StringRef.h" |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/Triple.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCInstrItineraries.h" |
| 14 | #include "llvm/MC/SubtargetFeature.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include <algorithm> |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
Craig Topper | 0e6c5b6 | 2012-10-03 06:47:18 +0000 | [diff] [blame] | 20 | /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 21 | /// with feature string). Recompute feature bits and scheduling model. |
| 22 | void |
| 23 | MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) { |
| 24 | SubtargetFeatures Features(FS); |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 25 | FeatureBits = Features.getFeatureBits(CPU, ProcDesc, ProcFeatures); |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 26 | if (!CPU.empty()) |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 27 | CPUSchedModel = &getSchedModelForCPU(CPU); |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 28 | else |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 29 | CPUSchedModel = &MCSchedModel::GetDefaultSchedModel(); |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame^] | 32 | MCSubtargetInfo::MCSubtargetInfo( |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 33 | const Triple &TT, StringRef C, StringRef FS, |
| 34 | ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD, |
| 35 | const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, |
| 36 | const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, |
Duncan P. N. Exon Smith | 754e21f | 2015-07-10 22:43:42 +0000 | [diff] [blame^] | 37 | const InstrStage *IS, const unsigned *OC, const unsigned *FP) |
| 38 | : TargetTriple(TT), CPU(C), ProcFeatures(PF), ProcDesc(PD), |
| 39 | ProcSchedModels(ProcSched), WriteProcResTable(WPR), WriteLatencyTable(WL), |
| 40 | ReadAdvanceTable(RA), Stages(IS), OperandCycles(OC), ForwardingPaths(FP) { |
Andrew Trick | ba7b921 | 2012-09-18 05:33:15 +0000 | [diff] [blame] | 41 | InitMCProcessorInfo(CPU, FS); |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 44 | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
| 45 | /// bits. This version does not change the implied bits. |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 46 | FeatureBitset MCSubtargetInfo::ToggleFeature(uint64_t FB) { |
| 47 | FeatureBits.flip(FB); |
| 48 | return FeatureBits; |
| 49 | } |
| 50 | |
| 51 | FeatureBitset MCSubtargetInfo::ToggleFeature(const FeatureBitset &FB) { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 52 | FeatureBits ^= FB; |
| 53 | return FeatureBits; |
| 54 | } |
| 55 | |
| 56 | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
| 57 | /// bits. This version will also change all implied bits. |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 58 | FeatureBitset MCSubtargetInfo::ToggleFeature(StringRef FS) { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 59 | SubtargetFeatures Features; |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 60 | FeatureBits = Features.ToggleFeature(FeatureBits, FS, ProcFeatures); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 61 | return FeatureBits; |
| 62 | } |
| 63 | |
John Brawn | d03d229 | 2015-06-05 13:29:24 +0000 | [diff] [blame] | 64 | FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) { |
| 65 | SubtargetFeatures Features; |
| 66 | FeatureBits = Features.ApplyFeatureFlag(FeatureBits, FS, ProcFeatures); |
| 67 | return FeatureBits; |
| 68 | } |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 69 | |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 70 | const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const { |
Andrew Trick | ac36af4 | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 71 | assert(ProcSchedModels && "Processor machine model not available!"); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 72 | |
Eric Christopher | dc5072d | 2014-05-06 20:23:04 +0000 | [diff] [blame] | 73 | unsigned NumProcs = ProcDesc.size(); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 74 | #ifndef NDEBUG |
| 75 | for (size_t i = 1; i < NumProcs; i++) { |
Andrew Trick | ac36af4 | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 76 | assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 && |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 77 | "Processor machine model table is not sorted"); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 78 | } |
| 79 | #endif |
| 80 | |
| 81 | // Find entry |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 82 | const SubtargetInfoKV *Found = |
| 83 | std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, CPU); |
| 84 | if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) { |
Craig Topper | 768ccc4 | 2015-04-02 04:27:50 +0000 | [diff] [blame] | 85 | if (CPU != "help") // Don't error if the user asked for help. |
| 86 | errs() << "'" << CPU |
| 87 | << "' is not a recognized processor for this target" |
| 88 | << " (ignoring processor)\n"; |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 89 | return MCSchedModel::GetDefaultSchedModel(); |
Artyom Skrobov | eab7515 | 2014-01-25 16:56:18 +0000 | [diff] [blame] | 90 | } |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 91 | assert(Found->Value && "Missing processor SchedModel value"); |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 92 | return *(const MCSchedModel *)Found->Value; |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 93 | } |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 94 | |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 95 | InstrItineraryData |
| 96 | MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const { |
Pete Cooper | 1175945 | 2014-09-02 17:43:54 +0000 | [diff] [blame] | 97 | const MCSchedModel SchedModel = getSchedModelForCPU(CPU); |
Andrew Trick | 87255e3 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 98 | return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths); |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 99 | } |
Andrew Trick | d2a19da | 2012-09-14 20:26:46 +0000 | [diff] [blame] | 100 | |
| 101 | /// Initialize an InstrItineraryData instance. |
| 102 | void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const { |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 103 | InstrItins = InstrItineraryData(getSchedModel(), Stages, OperandCycles, |
| 104 | ForwardingPaths); |
Andrew Trick | d2a19da | 2012-09-14 20:26:46 +0000 | [diff] [blame] | 105 | } |