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