1 //===--- ARM.cpp - ARM (not AArch64) Helpers for Tools ----------*- 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 #include "ARM.h"
11 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/DriverDiagnostic.h"
13 #include "clang/Driver/Options.h"
14 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/Option/ArgList.h"
16 #include "llvm/Support/TargetParser.h"
17 
18 using namespace clang::driver;
19 using namespace clang::driver::tools;
20 using namespace clang;
21 using namespace llvm::opt;
22 
23 // Get SubArch (vN).
24 int arm::getARMSubArchVersionNumber(const llvm::Triple &Triple) {
25   llvm::StringRef Arch = Triple.getArchName();
26   return llvm::ARM::parseArchVersion(Arch);
27 }
28 
29 // True if M-profile.
30 bool arm::isARMMProfile(const llvm::Triple &Triple) {
31   llvm::StringRef Arch = Triple.getArchName();
32   return llvm::ARM::parseArchProfile(Arch) == llvm::ARM::ProfileKind::M;
33 }
34 
35 // Get Arch/CPU from args.
36 void arm::getARMArchCPUFromArgs(const ArgList &Args, llvm::StringRef &Arch,
37                                 llvm::StringRef &CPU, bool FromAs) {
38   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
39     CPU = A->getValue();
40   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
41     Arch = A->getValue();
42   if (!FromAs)
43     return;
44 
45   for (const Arg *A :
46        Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
47     StringRef Value = A->getValue();
48     if (Value.startswith("-mcpu="))
49       CPU = Value.substr(6);
50     if (Value.startswith("-march="))
51       Arch = Value.substr(7);
52   }
53 }
54 
55 // Handle -mhwdiv=.
56 // FIXME: Use ARMTargetParser.
57 static void getARMHWDivFeatures(const Driver &D, const Arg *A,
58                                 const ArgList &Args, StringRef HWDiv,
59                                 std::vector<StringRef> &Features) {
60   unsigned HWDivID = llvm::ARM::parseHWDiv(HWDiv);
61   if (!llvm::ARM::getHWDivFeatures(HWDivID, Features))
62     D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
63 }
64 
65 // Handle -mfpu=.
66 static void getARMFPUFeatures(const Driver &D, const Arg *A,
67                               const ArgList &Args, StringRef FPU,
68                               std::vector<StringRef> &Features) {
69   unsigned FPUID = llvm::ARM::parseFPU(FPU);
70   if (!llvm::ARM::getFPUFeatures(FPUID, Features))
71     D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
72 }
73 
74 // Decode ARM features from string like +[no]featureA+[no]featureB+...
75 static bool DecodeARMFeatures(const Driver &D, StringRef text,
76                               std::vector<StringRef> &Features) {
77   SmallVector<StringRef, 8> Split;
78   text.split(Split, StringRef("+"), -1, false);
79 
80   for (StringRef Feature : Split) {
81     StringRef FeatureName = llvm::ARM::getArchExtFeature(Feature);
82     if (!FeatureName.empty())
83       Features.push_back(FeatureName);
84     else
85       return false;
86   }
87   return true;
88 }
89 
90 static void DecodeARMFeaturesFromCPU(const Driver &D, StringRef CPU,
91                                      std::vector<StringRef> &Features) {
92   if (CPU != "generic") {
93     llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
94     unsigned Extension = llvm::ARM::getDefaultExtensions(CPU, ArchKind);
95     llvm::ARM::getExtensionFeatures(Extension, Features);
96   }
97 }
98 
99 // Check if -march is valid by checking if it can be canonicalised and parsed.
100 // getARMArch is used here instead of just checking the -march value in order
101 // to handle -march=native correctly.
102 static void checkARMArchName(const Driver &D, const Arg *A, const ArgList &Args,
103                              llvm::StringRef ArchName,
104                              std::vector<StringRef> &Features,
105                              const llvm::Triple &Triple) {
106   std::pair<StringRef, StringRef> Split = ArchName.split("+");
107 
108   std::string MArch = arm::getARMArch(ArchName, Triple);
109   if (llvm::ARM::parseArch(MArch) == llvm::ARM::ArchKind::INVALID ||
110       (Split.second.size() && !DecodeARMFeatures(D, Split.second, Features)))
111     D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
112 }
113 
114 // Check -mcpu=. Needs ArchName to handle -mcpu=generic.
115 static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args,
116                             llvm::StringRef CPUName, llvm::StringRef ArchName,
117                             std::vector<StringRef> &Features,
118                             const llvm::Triple &Triple) {
119   std::pair<StringRef, StringRef> Split = CPUName.split("+");
120 
121   std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
122   if (arm::getLLVMArchSuffixForARM(CPU, ArchName, Triple).empty() ||
123       (Split.second.size() && !DecodeARMFeatures(D, Split.second, Features)))
124     D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
125 }
126 
127 bool arm::useAAPCSForMachO(const llvm::Triple &T) {
128   // The backend is hardwired to assume AAPCS for M-class processors, ensure
129   // the frontend matches that.
130   return T.getEnvironment() == llvm::Triple::EABI ||
131          T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
132 }
133 
134 // Select the float ABI as determined by -msoft-float, -mhard-float, and
135 // -mfloat-abi=.
136 arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
137   const Driver &D = TC.getDriver();
138   const llvm::Triple &Triple = TC.getEffectiveTriple();
139   auto SubArch = getARMSubArchVersionNumber(Triple);
140   arm::FloatABI ABI = FloatABI::Invalid;
141   if (Arg *A =
142           Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
143                           options::OPT_mfloat_abi_EQ)) {
144     if (A->getOption().matches(options::OPT_msoft_float)) {
145       ABI = FloatABI::Soft;
146     } else if (A->getOption().matches(options::OPT_mhard_float)) {
147       ABI = FloatABI::Hard;
148     } else {
149       ABI = llvm::StringSwitch<arm::FloatABI>(A->getValue())
150                 .Case("soft", FloatABI::Soft)
151                 .Case("softfp", FloatABI::SoftFP)
152                 .Case("hard", FloatABI::Hard)
153                 .Default(FloatABI::Invalid);
154       if (ABI == FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
155         D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
156         ABI = FloatABI::Soft;
157       }
158     }
159 
160     // It is incorrect to select hard float ABI on MachO platforms if the ABI is
161     // "apcs-gnu".
162     if (Triple.isOSBinFormatMachO() && !useAAPCSForMachO(Triple) &&
163         ABI == FloatABI::Hard) {
164       D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args)
165                                                        << Triple.getArchName();
166     }
167   }
168 
169   // If unspecified, choose the default based on the platform.
170   if (ABI == FloatABI::Invalid) {
171     switch (Triple.getOS()) {
172     case llvm::Triple::Darwin:
173     case llvm::Triple::MacOSX:
174     case llvm::Triple::IOS:
175     case llvm::Triple::TvOS: {
176       // Darwin defaults to "softfp" for v6 and v7.
177       ABI = (SubArch == 6 || SubArch == 7) ? FloatABI::SoftFP : FloatABI::Soft;
178       ABI = Triple.isWatchABI() ? FloatABI::Hard : ABI;
179       break;
180     }
181     case llvm::Triple::WatchOS:
182       ABI = FloatABI::Hard;
183       break;
184 
185     // FIXME: this is invalid for WindowsCE
186     case llvm::Triple::Win32:
187       ABI = FloatABI::Hard;
188       break;
189 
190     case llvm::Triple::NetBSD:
191       switch (Triple.getEnvironment()) {
192       case llvm::Triple::EABIHF:
193       case llvm::Triple::GNUEABIHF:
194         ABI = FloatABI::Hard;
195         break;
196       default:
197         ABI = FloatABI::Soft;
198         break;
199       }
200       break;
201 
202     case llvm::Triple::FreeBSD:
203       switch (Triple.getEnvironment()) {
204       case llvm::Triple::GNUEABIHF:
205         ABI = FloatABI::Hard;
206         break;
207       default:
208         // FreeBSD defaults to soft float
209         ABI = FloatABI::Soft;
210         break;
211       }
212       break;
213 
214     case llvm::Triple::OpenBSD:
215       ABI = FloatABI::Soft;
216       break;
217 
218     default:
219       switch (Triple.getEnvironment()) {
220       case llvm::Triple::GNUEABIHF:
221       case llvm::Triple::MuslEABIHF:
222       case llvm::Triple::EABIHF:
223         ABI = FloatABI::Hard;
224         break;
225       case llvm::Triple::GNUEABI:
226       case llvm::Triple::MuslEABI:
227       case llvm::Triple::EABI:
228         // EABI is always AAPCS, and if it was not marked 'hard', it's softfp
229         ABI = FloatABI::SoftFP;
230         break;
231       case llvm::Triple::Android:
232         ABI = (SubArch == 7) ? FloatABI::SoftFP : FloatABI::Soft;
233         break;
234       default:
235         // Assume "soft", but warn the user we are guessing.
236         if (Triple.isOSBinFormatMachO() &&
237             Triple.getSubArch() == llvm::Triple::ARMSubArch_v7em)
238           ABI = FloatABI::Hard;
239         else
240           ABI = FloatABI::Soft;
241 
242         if (Triple.getOS() != llvm::Triple::UnknownOS ||
243             !Triple.isOSBinFormatMachO())
244           D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft";
245         break;
246       }
247     }
248   }
249 
250   assert(ABI != FloatABI::Invalid && "must select an ABI");
251   return ABI;
252 }
253 
254 void arm::getARMTargetFeatures(const ToolChain &TC,
255                                const llvm::Triple &Triple,
256                                const ArgList &Args,
257                                ArgStringList &CmdArgs,
258                                std::vector<StringRef> &Features,
259                                bool ForAS) {
260   const Driver &D = TC.getDriver();
261 
262   bool KernelOrKext =
263       Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
264   arm::FloatABI ABI = arm::getARMFloatABI(TC, Args);
265   const Arg *WaCPU = nullptr, *WaFPU = nullptr;
266   const Arg *WaHDiv = nullptr, *WaArch = nullptr;
267 
268   if (!ForAS) {
269     // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
270     // yet (it uses the -mfloat-abi and -msoft-float options), and it is
271     // stripped out by the ARM target. We should probably pass this a new
272     // -target-option, which is handled by the -cc1/-cc1as invocation.
273     //
274     // FIXME2:  For consistency, it would be ideal if we set up the target
275     // machine state the same when using the frontend or the assembler. We don't
276     // currently do that for the assembler, we pass the options directly to the
277     // backend and never even instantiate the frontend TargetInfo. If we did,
278     // and used its handleTargetFeatures hook, then we could ensure the
279     // assembler and the frontend behave the same.
280 
281     // Use software floating point operations?
282     if (ABI == arm::FloatABI::Soft)
283       Features.push_back("+soft-float");
284 
285     // Use software floating point argument passing?
286     if (ABI != arm::FloatABI::Hard)
287       Features.push_back("+soft-float-abi");
288   } else {
289     // Here, we make sure that -Wa,-mfpu/cpu/arch/hwdiv will be passed down
290     // to the assembler correctly.
291     for (const Arg *A :
292          Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
293       StringRef Value = A->getValue();
294       if (Value.startswith("-mfpu=")) {
295         WaFPU = A;
296       } else if (Value.startswith("-mcpu=")) {
297         WaCPU = A;
298       } else if (Value.startswith("-mhwdiv=")) {
299         WaHDiv = A;
300       } else if (Value.startswith("-march=")) {
301         WaArch = A;
302       }
303     }
304   }
305 
306   // Check -march. ClangAs gives preference to -Wa,-march=.
307   const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
308   StringRef ArchName;
309   if (WaArch) {
310     if (ArchArg)
311       D.Diag(clang::diag::warn_drv_unused_argument)
312           << ArchArg->getAsString(Args);
313     ArchName = StringRef(WaArch->getValue()).substr(7);
314     checkARMArchName(D, WaArch, Args, ArchName, Features, Triple);
315     // FIXME: Set Arch.
316     D.Diag(clang::diag::warn_drv_unused_argument) << WaArch->getAsString(Args);
317   } else if (ArchArg) {
318     ArchName = ArchArg->getValue();
319     checkARMArchName(D, ArchArg, Args, ArchName, Features, Triple);
320   }
321 
322   // Check -mcpu. ClangAs gives preference to -Wa,-mcpu=.
323   const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
324   StringRef CPUName;
325   if (WaCPU) {
326     if (CPUArg)
327       D.Diag(clang::diag::warn_drv_unused_argument)
328           << CPUArg->getAsString(Args);
329     CPUName = StringRef(WaCPU->getValue()).substr(6);
330     checkARMCPUName(D, WaCPU, Args, CPUName, ArchName, Features, Triple);
331   } else if (CPUArg) {
332     CPUName = CPUArg->getValue();
333     checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, Features, Triple);
334   }
335 
336   // Add CPU features for generic CPUs
337   if (CPUName == "native") {
338     llvm::StringMap<bool> HostFeatures;
339     if (llvm::sys::getHostCPUFeatures(HostFeatures))
340       for (auto &F : HostFeatures)
341         Features.push_back(
342             Args.MakeArgString((F.second ? "+" : "-") + F.first()));
343   } else if (!CPUName.empty()) {
344     DecodeARMFeaturesFromCPU(D, CPUName, Features);
345   }
346 
347   // Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=.
348   const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
349   if (WaFPU) {
350     if (FPUArg)
351       D.Diag(clang::diag::warn_drv_unused_argument)
352           << FPUArg->getAsString(Args);
353     getARMFPUFeatures(D, WaFPU, Args, StringRef(WaFPU->getValue()).substr(6),
354                       Features);
355   } else if (FPUArg) {
356     getARMFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features);
357   }
358 
359   // Honor -mhwdiv=. ClangAs gives preference to -Wa,-mhwdiv=.
360   const Arg *HDivArg = Args.getLastArg(options::OPT_mhwdiv_EQ);
361   if (WaHDiv) {
362     if (HDivArg)
363       D.Diag(clang::diag::warn_drv_unused_argument)
364           << HDivArg->getAsString(Args);
365     getARMHWDivFeatures(D, WaHDiv, Args,
366                         StringRef(WaHDiv->getValue()).substr(8), Features);
367   } else if (HDivArg)
368     getARMHWDivFeatures(D, HDivArg, Args, HDivArg->getValue(), Features);
369 
370   // Setting -msoft-float effectively disables NEON because of the GCC
371   // implementation, although the same isn't true of VFP or VFP3.
372   if (ABI == arm::FloatABI::Soft) {
373     Features.push_back("-neon");
374     // Also need to explicitly disable features which imply NEON.
375     Features.push_back("-crypto");
376   }
377 
378   // En/disable crc code generation.
379   if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
380     if (A->getOption().matches(options::OPT_mcrc))
381       Features.push_back("+crc");
382     else
383       Features.push_back("-crc");
384   }
385 
386   // Look for the last occurrence of -mlong-calls or -mno-long-calls. If
387   // neither options are specified, see if we are compiling for kernel/kext and
388   // decide whether to pass "+long-calls" based on the OS and its version.
389   if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
390                                options::OPT_mno_long_calls)) {
391     if (A->getOption().matches(options::OPT_mlong_calls))
392       Features.push_back("+long-calls");
393   } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
394              !Triple.isWatchOS()) {
395       Features.push_back("+long-calls");
396   }
397 
398   // Generate execute-only output (no data access to code sections).
399   // This only makes sense for the compiler, not for the assembler.
400   if (!ForAS) {
401     // Supported only on ARMv6T2 and ARMv7 and above.
402     // Cannot be combined with -mno-movt or -mlong-calls
403     if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) {
404       if (A->getOption().matches(options::OPT_mexecute_only)) {
405         if (getARMSubArchVersionNumber(Triple) < 7 &&
406             llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2)
407               D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName();
408         else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
409           D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args);
410         // Long calls create constant pool entries and have not yet been fixed up
411         // to play nicely with execute-only. Hence, they cannot be used in
412         // execute-only code for now
413         else if (Arg *B = Args.getLastArg(options::OPT_mlong_calls, options::OPT_mno_long_calls)) {
414           if (B->getOption().matches(options::OPT_mlong_calls))
415             D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args);
416         }
417 	Features.push_back("+execute-only");
418       }
419     }
420   }
421 
422   // Kernel code has more strict alignment requirements.
423   if (KernelOrKext)
424     Features.push_back("+strict-align");
425   else if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
426                                     options::OPT_munaligned_access)) {
427     if (A->getOption().matches(options::OPT_munaligned_access)) {
428       // No v6M core supports unaligned memory access (v6M ARM ARM A3.2).
429       if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
430         D.Diag(diag::err_target_unsupported_unaligned) << "v6m";
431       // v8M Baseline follows on from v6M, so doesn't support unaligned memory
432       // access either.
433       else if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
434         D.Diag(diag::err_target_unsupported_unaligned) << "v8m.base";
435     } else
436       Features.push_back("+strict-align");
437   } else {
438     // Assume pre-ARMv6 doesn't support unaligned accesses.
439     //
440     // ARMv6 may or may not support unaligned accesses depending on the
441     // SCTLR.U bit, which is architecture-specific. We assume ARMv6
442     // Darwin and NetBSD targets support unaligned accesses, and others don't.
443     //
444     // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
445     // which raises an alignment fault on unaligned accesses. Linux
446     // defaults this bit to 0 and handles it as a system-wide (not
447     // per-process) setting. It is therefore safe to assume that ARMv7+
448     // Linux targets support unaligned accesses. The same goes for NaCl.
449     //
450     // The above behavior is consistent with GCC.
451     int VersionNum = getARMSubArchVersionNumber(Triple);
452     if (Triple.isOSDarwin() || Triple.isOSNetBSD()) {
453       if (VersionNum < 6 ||
454           Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
455         Features.push_back("+strict-align");
456     } else if (Triple.isOSLinux() || Triple.isOSNaCl()) {
457       if (VersionNum < 7)
458         Features.push_back("+strict-align");
459     } else
460       Features.push_back("+strict-align");
461   }
462 
463   // llvm does not support reserving registers in general. There is support
464   // for reserving r9 on ARM though (defined as a platform-specific register
465   // in ARM EABI).
466   if (Args.hasArg(options::OPT_ffixed_r9))
467     Features.push_back("+reserve-r9");
468 
469   // The kext linker doesn't know how to deal with movw/movt.
470   if (KernelOrKext || Args.hasArg(options::OPT_mno_movt))
471     Features.push_back("+no-movt");
472 
473   if (Args.hasArg(options::OPT_mno_neg_immediates))
474     Features.push_back("+no-neg-immediates");
475 }
476 
477 const std::string arm::getARMArch(StringRef Arch, const llvm::Triple &Triple) {
478   std::string MArch;
479   if (!Arch.empty())
480     MArch = Arch;
481   else
482     MArch = Triple.getArchName();
483   MArch = StringRef(MArch).split("+").first.lower();
484 
485   // Handle -march=native.
486   if (MArch == "native") {
487     std::string CPU = llvm::sys::getHostCPUName();
488     if (CPU != "generic") {
489       // Translate the native cpu into the architecture suffix for that CPU.
490       StringRef Suffix = arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
491       // If there is no valid architecture suffix for this CPU we don't know how
492       // to handle it, so return no architecture.
493       if (Suffix.empty())
494         MArch = "";
495       else
496         MArch = std::string("arm") + Suffix.str();
497     }
498   }
499 
500   return MArch;
501 }
502 
503 /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
504 StringRef arm::getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple) {
505   std::string MArch = getARMArch(Arch, Triple);
506   // getARMCPUForArch defaults to the triple if MArch is empty, but empty MArch
507   // here means an -march=native that we can't handle, so instead return no CPU.
508   if (MArch.empty())
509     return StringRef();
510 
511   // We need to return an empty string here on invalid MArch values as the
512   // various places that call this function can't cope with a null result.
513   return Triple.getARMCPUForArch(MArch);
514 }
515 
516 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
517 std::string arm::getARMTargetCPU(StringRef CPU, StringRef Arch,
518                                  const llvm::Triple &Triple) {
519   // FIXME: Warn on inconsistent use of -mcpu and -march.
520   // If we have -mcpu=, use that.
521   if (!CPU.empty()) {
522     std::string MCPU = StringRef(CPU).split("+").first.lower();
523     // Handle -mcpu=native.
524     if (MCPU == "native")
525       return llvm::sys::getHostCPUName();
526     else
527       return MCPU;
528   }
529 
530   return getARMCPUForMArch(Arch, Triple);
531 }
532 
533 /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
534 /// CPU  (or Arch, if CPU is generic).
535 // FIXME: This is redundant with -mcpu, why does LLVM use this.
536 StringRef arm::getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch,
537                                        const llvm::Triple &Triple) {
538   llvm::ARM::ArchKind ArchKind;
539   if (CPU == "generic") {
540     std::string ARMArch = tools::arm::getARMArch(Arch, Triple);
541     ArchKind = llvm::ARM::parseArch(ARMArch);
542     if (ArchKind == llvm::ARM::ArchKind::INVALID)
543       // In case of generic Arch, i.e. "arm",
544       // extract arch from default cpu of the Triple
545       ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(ARMArch));
546   } else {
547     // FIXME: horrible hack to get around the fact that Cortex-A7 is only an
548     // armv7k triple if it's actually been specified via "-arch armv7k".
549     ArchKind = (Arch == "armv7k" || Arch == "thumbv7k")
550                           ? llvm::ARM::ArchKind::ARMV7K
551                           : llvm::ARM::parseCPUArch(CPU);
552   }
553   if (ArchKind == llvm::ARM::ArchKind::INVALID)
554     return "";
555   return llvm::ARM::getSubArch(ArchKind);
556 }
557 
558 void arm::appendEBLinkFlags(const ArgList &Args, ArgStringList &CmdArgs,
559                             const llvm::Triple &Triple) {
560   if (Args.hasArg(options::OPT_r))
561     return;
562 
563   // ARMv7 (and later) and ARMv6-M do not support BE-32, so instruct the linker
564   // to generate BE-8 executables.
565   if (arm::getARMSubArchVersionNumber(Triple) >= 7 || arm::isARMMProfile(Triple))
566     CmdArgs.push_back("--be8");
567 }
568