@@ -85,16 +85,22 @@ static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
8585}
8686
8787// / Return the length of the longest entry in the table.
88- template <typename T>
89- static size_t getLongestEntryLength (ArrayRef<T> Table) {
88+ static size_t getLongestEntryLength (ArrayRef<SubtargetFeatureKV> Table) {
9089 size_t MaxLen = 0 ;
9190 for (auto &I : Table)
9291 MaxLen = std::max (MaxLen, std::strlen (I.Key ));
9392 return MaxLen;
9493}
9594
95+ static size_t getLongestEntryLength (ArrayRef<StringRef> Table) {
96+ size_t MaxLen = 0 ;
97+ for (StringRef I : Table)
98+ MaxLen = std::max (MaxLen, I.size ());
99+ return MaxLen;
100+ }
101+
96102// / Display help for feature and mcpu choices.
97- static void Help (ArrayRef<SubtargetSubTypeKV> CPUTable ,
103+ static void Help (ArrayRef<StringRef> CPUNames ,
98104 ArrayRef<SubtargetFeatureKV> FeatTable) {
99105 // the static variable ensures that the help information only gets
100106 // printed once even though a target machine creates multiple subtargets
@@ -104,14 +110,20 @@ static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
104110 }
105111
106112 // Determine the length of the longest CPU and Feature entries.
107- unsigned MaxCPULen = getLongestEntryLength (CPUTable );
113+ unsigned MaxCPULen = getLongestEntryLength (CPUNames );
108114 unsigned MaxFeatLen = getLongestEntryLength (FeatTable);
109115
110116 // Print the CPU table.
111117 errs () << " Available CPUs for this target:\n\n " ;
112- for (auto &CPU : CPUTable)
113- errs () << format (" %-*s - Select the %s processor.\n " , MaxCPULen, CPU.Key ,
114- CPU.Key );
118+ for (auto &CPUName : CPUNames) {
119+ // Skip apple-latest, as that's only meant to be used in
120+ // disassemblers/debuggers, and we don't want normal code to be built with
121+ // it as an -mcpu=
122+ if (CPUName == " apple-latest" )
123+ continue ;
124+ errs () << format (" %-*s - Select the %s processor.\n " , MaxCPULen,
125+ CPUName.str ().c_str (), CPUName.str ().c_str ());
126+ }
115127 errs () << ' \n ' ;
116128
117129 // Print the Feature table.
@@ -127,7 +139,7 @@ static void Help(ArrayRef<SubtargetSubTypeKV> CPUTable,
127139}
128140
129141// / Display help for mcpu choices only
130- static void cpuHelp (ArrayRef<SubtargetSubTypeKV> CPUTable ) {
142+ static void cpuHelp (ArrayRef<StringRef> CPUNames ) {
131143 // the static variable ensures that the help information only gets
132144 // printed once even though a target machine creates multiple subtargets
133145 static bool PrintOnce = false ;
@@ -137,8 +149,14 @@ static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
137149
138150 // Print the CPU table.
139151 errs () << " Available CPUs for this target:\n\n " ;
140- for (auto &CPU : CPUTable)
141- errs () << " \t " << CPU.Key << " \n " ;
152+ for (auto &CPU : CPUNames) {
153+ // Skip apple-latest, as that's only meant to be used in
154+ // disassemblers/debuggers, and we don't want normal code to be built with
155+ // it as an -mcpu=
156+ if (CPU == " apple-latest" )
157+ continue ;
158+ errs () << " \t " << CPU << " \n " ;
159+ }
142160 errs () << ' \n ' ;
143161
144162 errs () << " Use -mcpu or -mtune to specify the target's processor.\n "
@@ -148,7 +166,9 @@ static void cpuHelp(ArrayRef<SubtargetSubTypeKV> CPUTable) {
148166 PrintOnce = true ;
149167}
150168
151- static FeatureBitset getFeatures (StringRef CPU, StringRef TuneCPU, StringRef FS,
169+ static FeatureBitset getFeatures (MCSubtargetInfo &STI, StringRef CPU,
170+ StringRef TuneCPU, StringRef FS,
171+ ArrayRef<StringRef> ProcNames,
152172 ArrayRef<SubtargetSubTypeKV> ProcDesc,
153173 ArrayRef<SubtargetFeatureKV> ProcFeatures) {
154174 SubtargetFeatures Features (FS);
@@ -163,7 +183,7 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
163183
164184 // Check if help is needed
165185 if (CPU == " help" )
166- Help (ProcDesc , ProcFeatures);
186+ Help (ProcNames , ProcFeatures);
167187
168188 // Find CPU entry if CPU name is specified.
169189 else if (!CPU.empty ()) {
@@ -196,9 +216,9 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
196216 for (const std::string &Feature : Features.getFeatures ()) {
197217 // Check for help
198218 if (Feature == " +help" )
199- Help (ProcDesc , ProcFeatures);
219+ Help (ProcNames , ProcFeatures);
200220 else if (Feature == " +cpuhelp" )
201- cpuHelp (ProcDesc );
221+ cpuHelp (ProcNames );
202222 else
203223 ApplyFeatureFlag (Bits, Feature, ProcFeatures);
204224 }
@@ -208,7 +228,8 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS,
208228
209229void MCSubtargetInfo::InitMCProcessorInfo (StringRef CPU, StringRef TuneCPU,
210230 StringRef FS) {
211- FeatureBits = getFeatures (CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
231+ FeatureBits =
232+ getFeatures (*this , CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);
212233 FeatureString = std::string (FS);
213234
214235 if (!TuneCPU.empty ())
@@ -219,20 +240,19 @@ void MCSubtargetInfo::InitMCProcessorInfo(StringRef CPU, StringRef TuneCPU,
219240
220241void MCSubtargetInfo::setDefaultFeatures (StringRef CPU, StringRef TuneCPU,
221242 StringRef FS) {
222- FeatureBits = getFeatures (CPU, TuneCPU, FS, ProcDesc, ProcFeatures);
243+ FeatureBits =
244+ getFeatures (*this , CPU, TuneCPU, FS, ProcNames, ProcDesc, ProcFeatures);
223245 FeatureString = std::string (FS);
224246}
225247
226- MCSubtargetInfo::MCSubtargetInfo (const Triple &TT, StringRef C, StringRef TC,
227- StringRef FS, ArrayRef<SubtargetFeatureKV> PF,
228- ArrayRef<SubtargetSubTypeKV> PD,
229- const MCWriteProcResEntry *WPR,
230- const MCWriteLatencyEntry *WL,
231- const MCReadAdvanceEntry *RA,
232- const InstrStage *IS, const unsigned *OC,
233- const unsigned *FP)
248+ MCSubtargetInfo::MCSubtargetInfo (
249+ const Triple &TT, StringRef C, StringRef TC, StringRef FS,
250+ ArrayRef<StringRef> PN, ArrayRef<SubtargetFeatureKV> PF,
251+ ArrayRef<SubtargetSubTypeKV> PD, const MCWriteProcResEntry *WPR,
252+ const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA,
253+ const InstrStage *IS, const unsigned *OC, const unsigned *FP)
234254 : TargetTriple(TT), CPU(std::string(C)), TuneCPU(std::string(TC)),
235- ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),
255+ ProcNames(PN), ProcFeatures(PF), ProcDesc(PD), WriteProcResTable(WPR),
236256 WriteLatencyTable(WL), ReadAdvanceTable(RA), Stages(IS),
237257 OperandCycles(OC), ForwardingPaths(FP) {
238258 InitMCProcessorInfo (CPU, TuneCPU, FS);
0 commit comments