Evan Cheng | 9421470 | 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" |
| 11 | #include "llvm/MC/MCInstrItineraries.h" |
| 12 | #include "llvm/MC/SubtargetFeature.h" |
| 13 | #include "llvm/ADT/StringRef.h" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/Triple.h" |
Evan Cheng | 9421470 | 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 | |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 20 | MCSchedModel MCSchedModel::DefaultSchedModel; // For unknown processors. |
| 21 | |
Andrew Trick | a2a47d1 | 2012-09-17 22:19:12 +0000 | [diff] [blame] | 22 | /// ReInitMCSubtargetInfo - Set or chaing the CPU (optionally supplemented |
| 23 | /// with feature string). Recompute feature bits and scheduling model. |
| 24 | void |
| 25 | MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef FS) { |
| 26 | SubtargetFeatures Features(FS); |
| 27 | FeatureBits = Features.getFeatureBits(CPU, ProcDesc, NumProcs, |
| 28 | ProcFeatures, NumFeatures); |
| 29 | |
| 30 | if (!CPU.empty()) |
| 31 | CPUSchedModel = getSchedModelForCPU(CPU); |
| 32 | else |
| 33 | CPUSchedModel = &MCSchedModel::DefaultSchedModel; |
| 34 | } |
| 35 | |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 36 | void |
| 37 | MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS, |
| 38 | const SubtargetFeatureKV *PF, |
| 39 | const SubtargetFeatureKV *PD, |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 40 | const SubtargetInfoKV *ProcSched, |
Andrew Trick | db7afac | 2012-09-17 22:18:55 +0000 | [diff] [blame] | 41 | const MCWriteProcResEntry *WPR, |
| 42 | const MCWriteLatencyEntry *WL, |
| 43 | const MCReadAdvanceEntry *RA, |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 44 | const InstrStage *IS, |
| 45 | const unsigned *OC, |
| 46 | const unsigned *FP, |
| 47 | unsigned NF, unsigned NP) { |
| 48 | TargetTriple = TT; |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 49 | ProcFeatures = PF; |
| 50 | ProcDesc = PD; |
Andrew Trick | 72d048b | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 51 | ProcSchedModels = ProcSched; |
Andrew Trick | db7afac | 2012-09-17 22:18:55 +0000 | [diff] [blame] | 52 | WriteProcResTable = WPR; |
| 53 | WriteLatencyTable = WL; |
| 54 | ReadAdvanceTable = RA; |
| 55 | |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 56 | Stages = IS; |
| 57 | OperandCycles = OC; |
Andrew Trick | a11a628 | 2012-07-07 03:59:48 +0000 | [diff] [blame] | 58 | ForwardingPaths = FP; |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 59 | NumFeatures = NF; |
| 60 | NumProcs = NP; |
| 61 | |
Andrew Trick | a2a47d1 | 2012-09-17 22:19:12 +0000 | [diff] [blame] | 62 | InitMCProcessorInfo(CPU, FS); |
Evan Cheng | 0ddff1b | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Evan Cheng | ffc0e73 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 65 | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
| 66 | /// bits. This version does not change the implied bits. |
| 67 | uint64_t MCSubtargetInfo::ToggleFeature(uint64_t FB) { |
| 68 | FeatureBits ^= FB; |
| 69 | return FeatureBits; |
| 70 | } |
| 71 | |
| 72 | /// ToggleFeature - Toggle a feature and returns the re-computed feature |
| 73 | /// bits. This version will also change all implied bits. |
| 74 | uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) { |
| 75 | SubtargetFeatures Features; |
| 76 | FeatureBits = Features.ToggleFeature(FeatureBits, FS, |
| 77 | ProcFeatures, NumFeatures); |
| 78 | return FeatureBits; |
| 79 | } |
| 80 | |
| 81 | |
Roman Divacky | 98eb98b | 2012-09-05 21:43:57 +0000 | [diff] [blame] | 82 | const MCSchedModel * |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 83 | MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const { |
Andrew Trick | 72d048b | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 84 | assert(ProcSchedModels && "Processor machine model not available!"); |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 85 | |
| 86 | #ifndef NDEBUG |
| 87 | for (size_t i = 1; i < NumProcs; i++) { |
Andrew Trick | 72d048b | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 88 | assert(strcmp(ProcSchedModels[i - 1].Key, ProcSchedModels[i].Key) < 0 && |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 89 | "Processor machine model table is not sorted"); |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 90 | } |
| 91 | #endif |
| 92 | |
| 93 | // Find entry |
| 94 | SubtargetInfoKV KV; |
| 95 | KV.Key = CPU.data(); |
| 96 | const SubtargetInfoKV *Found = |
Andrew Trick | 72d048b | 2012-09-14 20:26:41 +0000 | [diff] [blame] | 97 | std::lower_bound(ProcSchedModels, ProcSchedModels+NumProcs, KV); |
| 98 | if (Found == ProcSchedModels+NumProcs || StringRef(Found->Key) != CPU) { |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 99 | errs() << "'" << CPU |
| 100 | << "' is not a recognized processor for this target" |
| 101 | << " (ignoring processor)\n"; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 102 | return &MCSchedModel::DefaultSchedModel; |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 103 | } |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 104 | assert(Found->Value && "Missing processor SchedModel value"); |
Roman Divacky | 98eb98b | 2012-09-05 21:43:57 +0000 | [diff] [blame] | 105 | return (const MCSchedModel *)Found->Value; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 106 | } |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 107 | |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 108 | InstrItineraryData |
| 109 | MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const { |
Roman Divacky | 98eb98b | 2012-09-05 21:43:57 +0000 | [diff] [blame] | 110 | const MCSchedModel *SchedModel = getSchedModelForCPU(CPU); |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 111 | return InstrItineraryData(SchedModel, Stages, OperandCycles, ForwardingPaths); |
Evan Cheng | 9421470 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 112 | } |
Andrew Trick | 99ab6c6 | 2012-09-14 20:26:46 +0000 | [diff] [blame] | 113 | |
| 114 | /// Initialize an InstrItineraryData instance. |
| 115 | void MCSubtargetInfo::initInstrItins(InstrItineraryData &InstrItins) const { |
| 116 | InstrItins = |
Andrew Trick | 12886db | 2012-09-17 22:19:08 +0000 | [diff] [blame] | 117 | InstrItineraryData(CPUSchedModel, Stages, OperandCycles, ForwardingPaths); |
Andrew Trick | 99ab6c6 | 2012-09-14 20:26:46 +0000 | [diff] [blame] | 118 | } |