Fixed/added namespace ending comments using clang-tidy. NFC
[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   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 public:
48   void InitMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS,
49                            ArrayRef<SubtargetFeatureKV> PF,
50                            ArrayRef<SubtargetFeatureKV> PD,
51                            const SubtargetInfoKV *ProcSched,
52                            const MCWriteProcResEntry *WPR,
53                            const MCWriteLatencyEntry *WL,
54                            const MCReadAdvanceEntry *RA, const InstrStage *IS,
55                            const unsigned *OC, const unsigned *FP);
56
57   /// getTargetTriple - Return the target triple string.
58   const Triple &getTargetTriple() const { return TargetTriple; }
59
60   /// getCPU - Return the CPU string.
61   StringRef getCPU() const {
62     return CPU;
63   }
64
65   /// getFeatureBits - Return the feature bits.
66   ///
67   const FeatureBitset& getFeatureBits() const {
68     return FeatureBits;
69   }
70
71   /// setFeatureBits - Set the feature bits.
72   ///
73   void setFeatureBits(const FeatureBitset &FeatureBits_) {
74     FeatureBits = FeatureBits_;
75   }
76
77   /// InitMCProcessorInfo - Set or change the CPU (optionally supplemented with
78   /// feature string). Recompute feature bits and scheduling model.
79   void InitMCProcessorInfo(StringRef CPU, StringRef FS);
80
81   /// InitCPUSchedModel - Recompute scheduling model based on CPU.
82   void InitCPUSchedModel(StringRef CPU);
83
84   /// ToggleFeature - Toggle a feature and returns the re-computed feature
85   /// bits. This version does not change the implied bits.
86   FeatureBitset ToggleFeature(uint64_t FB);
87
88   /// ToggleFeature - Toggle a feature and returns the re-computed feature
89   /// bits. This version does not change the implied bits.
90   FeatureBitset ToggleFeature(const FeatureBitset& FB);
91
92   /// ToggleFeature - Toggle a set of features and returns the re-computed
93   /// feature bits. This version will also change all implied bits.
94   FeatureBitset ToggleFeature(StringRef FS);
95
96   /// Apply a feature flag and return the re-computed feature bits, including
97   /// all feature bits implied by the flag.
98   FeatureBitset ApplyFeatureFlag(StringRef FS);
99
100   /// getSchedModelForCPU - Get the machine model of a CPU.
101   ///
102   MCSchedModel getSchedModelForCPU(StringRef CPU) const;
103
104   /// getSchedModel - Get the machine model for this subtarget's CPU.
105   ///
106   const MCSchedModel &getSchedModel() const { return CPUSchedModel; }
107
108   /// Return an iterator at the first process resource consumed by the given
109   /// scheduling class.
110   const MCWriteProcResEntry *getWriteProcResBegin(
111     const MCSchedClassDesc *SC) const {
112     return &WriteProcResTable[SC->WriteProcResIdx];
113   }
114   const MCWriteProcResEntry *getWriteProcResEnd(
115     const MCSchedClassDesc *SC) const {
116     return getWriteProcResBegin(SC) + SC->NumWriteProcResEntries;
117   }
118
119   const MCWriteLatencyEntry *getWriteLatencyEntry(const MCSchedClassDesc *SC,
120                                                   unsigned DefIdx) const {
121     assert(DefIdx < SC->NumWriteLatencyEntries &&
122            "MachineModel does not specify a WriteResource for DefIdx");
123
124     return &WriteLatencyTable[SC->WriteLatencyIdx + DefIdx];
125   }
126
127   int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx,
128                            unsigned WriteResID) const {
129     // TODO: The number of read advance entries in a class can be significant
130     // (~50). Consider compressing the WriteID into a dense ID of those that are
131     // used by ReadAdvance and representing them as a bitset.
132     for (const MCReadAdvanceEntry *I = &ReadAdvanceTable[SC->ReadAdvanceIdx],
133            *E = I + SC->NumReadAdvanceEntries; I != E; ++I) {
134       if (I->UseIdx < UseIdx)
135         continue;
136       if (I->UseIdx > UseIdx)
137         break;
138       // Find the first WriteResIdx match, which has the highest cycle count.
139       if (!I->WriteResourceID || I->WriteResourceID == WriteResID) {
140         return I->Cycles;
141       }
142     }
143     return 0;
144   }
145
146   /// getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
147   ///
148   InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const;
149
150   /// Initialize an InstrItineraryData instance.
151   void initInstrItins(InstrItineraryData &InstrItins) const;
152
153   /// Check whether the CPU string is valid.
154   bool isCPUStringValid(StringRef CPU) {
155     auto Found = std::find_if(ProcDesc.begin(), ProcDesc.end(),
156                               [=](const SubtargetFeatureKV &KV) {
157                                 return CPU == KV.Key; 
158                               });
159     return Found != ProcDesc.end();
160   }
161 };
162
163 } // namespace llvm
164
165 #endif