MC: Remove MCSubtargetInfo() default constructor
[oota-llvm.git] / include / llvm / MC / MCSubtargetInfo.h
1 //==-- llvm/MC/MCSubtargetInfo.h - Subtarget Information ---------*- C++ -*-==//
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 // This file describes the subtarget options of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSUBTARGETINFO_H
15 #define LLVM_MC_MCSUBTARGETINFO_H
16
17 #include "llvm/MC/MCInstrItineraries.h"
18 #include "llvm/MC/SubtargetFeature.h"
19 #include <string>
20
21 namespace llvm {
22
23 class StringRef;
24
25 //===----------------------------------------------------------------------===//
26 ///
27 /// MCSubtargetInfo - Generic base class for all target subtargets.
28 ///
29 class MCSubtargetInfo {
30   Triple TargetTriple;                        // Target triple
31   std::string CPU; // CPU being targeted.
32   ArrayRef<SubtargetFeatureKV> ProcFeatures;  // Processor feature list
33   ArrayRef<SubtargetFeatureKV> ProcDesc;  // Processor descriptions
34
35   // Scheduler machine model
36   const SubtargetInfoKV *ProcSchedModels;
37   const MCWriteProcResEntry *WriteProcResTable;
38   const MCWriteLatencyEntry *WriteLatencyTable;
39   const MCReadAdvanceEntry *ReadAdvanceTable;
40   const MCSchedModel *CPUSchedModel;
41
42   const InstrStage *Stages;            // Instruction itinerary stages
43   const unsigned *OperandCycles;       // Itinerary operand cycles
44   const unsigned *ForwardingPaths;     // Forwarding paths
45   FeatureBitset FeatureBits;           // Feature bits for current CPU + FS
46
47   MCSubtargetInfo() = delete;
48
49 public:
50   MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS,
51                   ArrayRef<SubtargetFeatureKV> PF,
52                   ArrayRef<SubtargetFeatureKV> PD,
53                   const SubtargetInfoKV *ProcSched,
54                   const MCWriteProcResEntry *WPR, const MCWriteLatencyEntry *WL,
55                   const MCReadAdvanceEntry *RA, const InstrStage *IS,
56                   const unsigned *OC, const unsigned *FP);
57
58   /// getTargetTriple - Return the target triple string.
59   const Triple &getTargetTriple() const { return TargetTriple; }
60
61   /// getCPU - Return the CPU string.
62   StringRef getCPU() const {
63     return CPU;
64   }
65
66   /// getFeatureBits - Return the feature bits.
67   ///
68   const FeatureBitset& getFeatureBits() const {
69     return FeatureBits;
70   }
71
72   /// setFeatureBits - Set the feature bits.
73   ///
74   void setFeatureBits(const FeatureBitset &FeatureBits_) {
75     FeatureBits = FeatureBits_;
76   }
77
78   /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented with
79   /// feature string). Recompute feature bits and scheduling model.
80   void InitMCProcessorInfo(StringRef CPU, StringRef FS);
81
82   /// ToggleFeature - Toggle a feature and returns the re-computed feature
83   /// bits. This version does not change the implied bits.
84   FeatureBitset ToggleFeature(uint64_t FB);
85
86   /// ToggleFeature - Toggle a feature and returns the re-computed feature
87   /// bits. This version does not change the implied bits.
88   FeatureBitset ToggleFeature(const FeatureBitset& FB);
89
90   /// ToggleFeature - Toggle a set of features and returns the re-computed
91   /// feature bits. This version will also change all implied bits.
92   FeatureBitset ToggleFeature(StringRef FS);
93
94   /// Apply a feature flag and return the re-computed feature bits, including
95   /// all feature bits implied by the flag.
96   FeatureBitset ApplyFeatureFlag(StringRef FS);
97
98   /// getSchedModelForCPU - Get the machine model of a CPU.
99   ///
100   const MCSchedModel &getSchedModelForCPU(StringRef CPU) const;
101
102   /// Get the machine model for this subtarget's CPU.
103   const MCSchedModel &getSchedModel() const { return *CPUSchedModel; }
104
105   /// Return an iterator at the first process resource consumed by the given
106   /// scheduling class.
107   const MCWriteProcResEntry *getWriteProcResBegin(
108     const MCSchedClassDesc *SC) const {
109     return &WriteProcResTable[SC->WriteProcResIdx];
110   }
111   const MCWriteProcResEntry *getWriteProcResEnd(
112     const MCSchedClassDesc *SC) const {
113     return getWriteProcResBegin(SC) + SC->NumWriteProcResEntries;
114   }
115
116   const MCWriteLatencyEntry *getWriteLatencyEntry(const MCSchedClassDesc *SC,
117                                                   unsigned DefIdx) const {
118     assert(DefIdx < SC->NumWriteLatencyEntries &&
119            "MachineModel does not specify a WriteResource for DefIdx");
120
121     return &WriteLatencyTable[SC->WriteLatencyIdx + DefIdx];
122   }
123
124   int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx,
125                            unsigned WriteResID) const {
126     // TODO: The number of read advance entries in a class can be significant
127     // (~50). Consider compressing the WriteID into a dense ID of those that are
128     // used by ReadAdvance and representing them as a bitset.
129     for (const MCReadAdvanceEntry *I = &ReadAdvanceTable[SC->ReadAdvanceIdx],
130            *E = I + SC->NumReadAdvanceEntries; I != E; ++I) {
131       if (I->UseIdx < UseIdx)
132         continue;
133       if (I->UseIdx > UseIdx)
134         break;
135       // Find the first WriteResIdx match, which has the highest cycle count.
136       if (!I->WriteResourceID || I->WriteResourceID == WriteResID) {
137         return I->Cycles;
138       }
139     }
140     return 0;
141   }
142
143   /// getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
144   ///
145   InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const;
146
147   /// Initialize an InstrItineraryData instance.
148   void initInstrItins(InstrItineraryData &InstrItins) const;
149
150   /// Check whether the CPU string is valid.
151   bool isCPUStringValid(StringRef CPU) const {
152     auto Found = std::find_if(ProcDesc.begin(), ProcDesc.end(),
153                               [=](const SubtargetFeatureKV &KV) {
154                                 return CPU == KV.Key; 
155                               });
156     return Found != ProcDesc.end();
157   }
158 };
159
160 } // End llvm namespace
161
162 #endif