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