ARM.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. //===--- ARM.cpp - ARM (not AArch64) Helpers for Tools ----------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "ARM.h"
  9. #include "clang/Driver/Driver.h"
  10. #include "clang/Driver/DriverDiagnostic.h"
  11. #include "clang/Driver/Options.h"
  12. #include "llvm/ADT/StringSwitch.h"
  13. #include "llvm/Option/ArgList.h"
  14. #include "llvm/Support/ARMTargetParser.h"
  15. #include "llvm/Support/TargetParser.h"
  16. #include "llvm/Support/Host.h"
  17. using namespace clang::driver;
  18. using namespace clang::driver::tools;
  19. using namespace clang;
  20. using namespace llvm::opt;
  21. // Get SubArch (vN).
  22. int arm::getARMSubArchVersionNumber(const llvm::Triple &Triple) {
  23. llvm::StringRef Arch = Triple.getArchName();
  24. return llvm::ARM::parseArchVersion(Arch);
  25. }
  26. // True if M-profile.
  27. bool arm::isARMMProfile(const llvm::Triple &Triple) {
  28. llvm::StringRef Arch = Triple.getArchName();
  29. return llvm::ARM::parseArchProfile(Arch) == llvm::ARM::ProfileKind::M;
  30. }
  31. // True if A-profile.
  32. bool arm::isARMAProfile(const llvm::Triple &Triple) {
  33. llvm::StringRef Arch = Triple.getArchName();
  34. return llvm::ARM::parseArchProfile(Arch) == llvm::ARM::ProfileKind::A;
  35. }
  36. // Get Arch/CPU from args.
  37. void arm::getARMArchCPUFromArgs(const ArgList &Args, llvm::StringRef &Arch,
  38. llvm::StringRef &CPU, bool FromAs) {
  39. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
  40. CPU = A->getValue();
  41. if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
  42. Arch = A->getValue();
  43. if (!FromAs)
  44. return;
  45. for (const Arg *A :
  46. Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
  47. // Use getValues because -Wa can have multiple arguments
  48. // e.g. -Wa,-mcpu=foo,-mcpu=bar
  49. for (StringRef Value : A->getValues()) {
  50. if (Value.startswith("-mcpu="))
  51. CPU = Value.substr(6);
  52. if (Value.startswith("-march="))
  53. Arch = Value.substr(7);
  54. }
  55. }
  56. }
  57. // Handle -mhwdiv=.
  58. // FIXME: Use ARMTargetParser.
  59. static void getARMHWDivFeatures(const Driver &D, const Arg *A,
  60. const ArgList &Args, StringRef HWDiv,
  61. std::vector<StringRef> &Features) {
  62. uint64_t HWDivID = llvm::ARM::parseHWDiv(HWDiv);
  63. if (!llvm::ARM::getHWDivFeatures(HWDivID, Features))
  64. D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
  65. }
  66. // Handle -mfpu=.
  67. static unsigned getARMFPUFeatures(const Driver &D, const Arg *A,
  68. const ArgList &Args, StringRef FPU,
  69. std::vector<StringRef> &Features) {
  70. unsigned FPUID = llvm::ARM::parseFPU(FPU);
  71. if (!llvm::ARM::getFPUFeatures(FPUID, Features))
  72. D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
  73. return FPUID;
  74. }
  75. // Decode ARM features from string like +[no]featureA+[no]featureB+...
  76. static bool DecodeARMFeatures(const Driver &D, StringRef text, StringRef CPU,
  77. llvm::ARM::ArchKind ArchKind,
  78. std::vector<StringRef> &Features,
  79. unsigned &ArgFPUID) {
  80. SmallVector<StringRef, 8> Split;
  81. text.split(Split, StringRef("+"), -1, false);
  82. for (StringRef Feature : Split) {
  83. if (!appendArchExtFeatures(CPU, ArchKind, Feature, Features, ArgFPUID))
  84. return false;
  85. }
  86. return true;
  87. }
  88. static void DecodeARMFeaturesFromCPU(const Driver &D, StringRef CPU,
  89. std::vector<StringRef> &Features) {
  90. CPU = CPU.split("+").first;
  91. if (CPU != "generic") {
  92. llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
  93. uint64_t Extension = llvm::ARM::getDefaultExtensions(CPU, ArchKind);
  94. llvm::ARM::getExtensionFeatures(Extension, Features);
  95. }
  96. }
  97. // Check if -march is valid by checking if it can be canonicalised and parsed.
  98. // getARMArch is used here instead of just checking the -march value in order
  99. // to handle -march=native correctly.
  100. static void checkARMArchName(const Driver &D, const Arg *A, const ArgList &Args,
  101. llvm::StringRef ArchName, llvm::StringRef CPUName,
  102. std::vector<StringRef> &Features,
  103. const llvm::Triple &Triple, unsigned &ArgFPUID) {
  104. std::pair<StringRef, StringRef> Split = ArchName.split("+");
  105. std::string MArch = arm::getARMArch(ArchName, Triple);
  106. llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(MArch);
  107. if (ArchKind == llvm::ARM::ArchKind::INVALID ||
  108. (Split.second.size() && !DecodeARMFeatures(D, Split.second, CPUName,
  109. ArchKind, Features, ArgFPUID)))
  110. D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
  111. }
  112. // Check -mcpu=. Needs ArchName to handle -mcpu=generic.
  113. static void checkARMCPUName(const Driver &D, const Arg *A, const ArgList &Args,
  114. llvm::StringRef CPUName, llvm::StringRef ArchName,
  115. std::vector<StringRef> &Features,
  116. const llvm::Triple &Triple, unsigned &ArgFPUID) {
  117. std::pair<StringRef, StringRef> Split = CPUName.split("+");
  118. std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
  119. llvm::ARM::ArchKind ArchKind =
  120. arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
  121. if (ArchKind == llvm::ARM::ArchKind::INVALID ||
  122. (Split.second.size() &&
  123. !DecodeARMFeatures(D, Split.second, CPU, ArchKind, Features, ArgFPUID)))
  124. D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
  125. }
  126. bool arm::useAAPCSForMachO(const llvm::Triple &T) {
  127. // The backend is hardwired to assume AAPCS for M-class processors, ensure
  128. // the frontend matches that.
  129. return T.getEnvironment() == llvm::Triple::EABI ||
  130. T.getEnvironment() == llvm::Triple::EABIHF ||
  131. T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
  132. }
  133. // We follow GCC and support when the backend has support for the MRC/MCR
  134. // instructions that are used to set the hard thread pointer ("CP15 C13
  135. // Thread id").
  136. bool arm::isHardTPSupported(const llvm::Triple &Triple) {
  137. int Ver = getARMSubArchVersionNumber(Triple);
  138. llvm::ARM::ArchKind AK = llvm::ARM::parseArch(Triple.getArchName());
  139. return Triple.isARM() || AK == llvm::ARM::ArchKind::ARMV6T2 ||
  140. (Ver >= 7 && AK != llvm::ARM::ArchKind::ARMV8MBaseline);
  141. }
  142. // Select mode for reading thread pointer (-mtp=soft/cp15).
  143. arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
  144. const llvm::Triple &Triple, bool ForAS) {
  145. if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
  146. arm::ReadTPMode ThreadPointer =
  147. llvm::StringSwitch<arm::ReadTPMode>(A->getValue())
  148. .Case("cp15", ReadTPMode::Cp15)
  149. .Case("soft", ReadTPMode::Soft)
  150. .Default(ReadTPMode::Invalid);
  151. if (ThreadPointer == ReadTPMode::Cp15 && !isHardTPSupported(Triple) &&
  152. !ForAS) {
  153. D.Diag(diag::err_target_unsupported_tp_hard) << Triple.getArchName();
  154. return ReadTPMode::Invalid;
  155. }
  156. if (ThreadPointer != ReadTPMode::Invalid)
  157. return ThreadPointer;
  158. if (StringRef(A->getValue()).empty())
  159. D.Diag(diag::err_drv_missing_arg_mtp) << A->getAsString(Args);
  160. else
  161. D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
  162. return ReadTPMode::Invalid;
  163. }
  164. return ReadTPMode::Soft;
  165. }
  166. void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
  167. types::ID InputType, llvm::Triple &Triple) {
  168. StringRef MCPU, MArch;
  169. if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
  170. MCPU = A->getValue();
  171. if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
  172. MArch = A->getValue();
  173. std::string CPU = Triple.isOSBinFormatMachO()
  174. ? tools::arm::getARMCPUForMArch(MArch, Triple).str()
  175. : tools::arm::getARMTargetCPU(MCPU, MArch, Triple);
  176. StringRef Suffix = tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
  177. bool IsBigEndian = Triple.getArch() == llvm::Triple::armeb ||
  178. Triple.getArch() == llvm::Triple::thumbeb;
  179. // Handle pseudo-target flags '-mlittle-endian'/'-EL' and
  180. // '-mbig-endian'/'-EB'.
  181. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
  182. options::OPT_mbig_endian)) {
  183. IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
  184. }
  185. std::string ArchName = IsBigEndian ? "armeb" : "arm";
  186. // FIXME: Thumb should just be another -target-feaure, not in the triple.
  187. bool IsMProfile =
  188. llvm::ARM::parseArchProfile(Suffix) == llvm::ARM::ProfileKind::M;
  189. bool ThumbDefault = IsMProfile ||
  190. // Thumb2 is the default for V7 on Darwin.
  191. (llvm::ARM::parseArchVersion(Suffix) == 7 &&
  192. Triple.isOSBinFormatMachO()) ||
  193. // FIXME: this is invalid for WindowsCE
  194. Triple.isOSWindows();
  195. // Check if ARM ISA was explicitly selected (using -mno-thumb or -marm) for
  196. // M-Class CPUs/architecture variants, which is not supported.
  197. bool ARMModeRequested =
  198. !Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault);
  199. if (IsMProfile && ARMModeRequested) {
  200. if (MCPU.size())
  201. D.Diag(diag::err_cpu_unsupported_isa) << CPU << "ARM";
  202. else
  203. D.Diag(diag::err_arch_unsupported_isa)
  204. << tools::arm::getARMArch(MArch, Triple) << "ARM";
  205. }
  206. // Check to see if an explicit choice to use thumb has been made via
  207. // -mthumb. For assembler files we must check for -mthumb in the options
  208. // passed to the assembler via -Wa or -Xassembler.
  209. bool IsThumb = false;
  210. if (InputType != types::TY_PP_Asm)
  211. IsThumb =
  212. Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault);
  213. else {
  214. // Ideally we would check for these flags in
  215. // CollectArgsForIntegratedAssembler but we can't change the ArchName at
  216. // that point.
  217. llvm::StringRef WaMArch, WaMCPU;
  218. for (const auto *A :
  219. Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
  220. for (StringRef Value : A->getValues()) {
  221. // There is no assembler equivalent of -mno-thumb, -marm, or -mno-arm.
  222. if (Value == "-mthumb")
  223. IsThumb = true;
  224. else if (Value.startswith("-march="))
  225. WaMArch = Value.substr(7);
  226. else if (Value.startswith("-mcpu="))
  227. WaMCPU = Value.substr(6);
  228. }
  229. }
  230. if (WaMCPU.size() || WaMArch.size()) {
  231. // The way this works means that we prefer -Wa,-mcpu's architecture
  232. // over -Wa,-march. Which matches the compiler behaviour.
  233. Suffix = tools::arm::getLLVMArchSuffixForARM(WaMCPU, WaMArch, Triple);
  234. }
  235. }
  236. // Assembly files should start in ARM mode, unless arch is M-profile, or
  237. // -mthumb has been passed explicitly to the assembler. Windows is always
  238. // thumb.
  239. if (IsThumb || IsMProfile || Triple.isOSWindows()) {
  240. if (IsBigEndian)
  241. ArchName = "thumbeb";
  242. else
  243. ArchName = "thumb";
  244. }
  245. Triple.setArchName(ArchName + Suffix.str());
  246. }
  247. void arm::setFloatABIInTriple(const Driver &D, const ArgList &Args,
  248. llvm::Triple &Triple) {
  249. bool isHardFloat =
  250. (arm::getARMFloatABI(D, Triple, Args) == arm::FloatABI::Hard);
  251. switch (Triple.getEnvironment()) {
  252. case llvm::Triple::GNUEABI:
  253. case llvm::Triple::GNUEABIHF:
  254. Triple.setEnvironment(isHardFloat ? llvm::Triple::GNUEABIHF
  255. : llvm::Triple::GNUEABI);
  256. break;
  257. case llvm::Triple::EABI:
  258. case llvm::Triple::EABIHF:
  259. Triple.setEnvironment(isHardFloat ? llvm::Triple::EABIHF
  260. : llvm::Triple::EABI);
  261. break;
  262. case llvm::Triple::MuslEABI:
  263. case llvm::Triple::MuslEABIHF:
  264. Triple.setEnvironment(isHardFloat ? llvm::Triple::MuslEABIHF
  265. : llvm::Triple::MuslEABI);
  266. break;
  267. default: {
  268. arm::FloatABI DefaultABI = arm::getDefaultFloatABI(Triple);
  269. if (DefaultABI != arm::FloatABI::Invalid &&
  270. isHardFloat != (DefaultABI == arm::FloatABI::Hard)) {
  271. Arg *ABIArg =
  272. Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
  273. options::OPT_mfloat_abi_EQ);
  274. assert(ABIArg && "Non-default float abi expected to be from arg");
  275. D.Diag(diag::err_drv_unsupported_opt_for_target)
  276. << ABIArg->getAsString(Args) << Triple.getTriple();
  277. }
  278. break;
  279. }
  280. }
  281. }
  282. arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, const ArgList &Args) {
  283. return arm::getARMFloatABI(TC.getDriver(), TC.getEffectiveTriple(), Args);
  284. }
  285. arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple &Triple) {
  286. auto SubArch = getARMSubArchVersionNumber(Triple);
  287. switch (Triple.getOS()) {
  288. case llvm::Triple::Darwin:
  289. case llvm::Triple::MacOSX:
  290. case llvm::Triple::IOS:
  291. case llvm::Triple::TvOS:
  292. // Darwin defaults to "softfp" for v6 and v7.
  293. if (Triple.isWatchABI())
  294. return FloatABI::Hard;
  295. else
  296. return (SubArch == 6 || SubArch == 7) ? FloatABI::SoftFP : FloatABI::Soft;
  297. case llvm::Triple::WatchOS:
  298. return FloatABI::Hard;
  299. // FIXME: this is invalid for WindowsCE
  300. case llvm::Triple::Win32:
  301. // It is incorrect to select hard float ABI on MachO platforms if the ABI is
  302. // "apcs-gnu".
  303. if (Triple.isOSBinFormatMachO() && !useAAPCSForMachO(Triple))
  304. return FloatABI::Soft;
  305. return FloatABI::Hard;
  306. case llvm::Triple::NetBSD:
  307. switch (Triple.getEnvironment()) {
  308. case llvm::Triple::EABIHF:
  309. case llvm::Triple::GNUEABIHF:
  310. return FloatABI::Hard;
  311. default:
  312. return FloatABI::Soft;
  313. }
  314. break;
  315. case llvm::Triple::FreeBSD:
  316. switch (Triple.getEnvironment()) {
  317. case llvm::Triple::GNUEABIHF:
  318. return FloatABI::Hard;
  319. default:
  320. // FreeBSD defaults to soft float
  321. return FloatABI::Soft;
  322. }
  323. break;
  324. case llvm::Triple::OpenBSD:
  325. return FloatABI::SoftFP;
  326. default:
  327. switch (Triple.getEnvironment()) {
  328. case llvm::Triple::GNUEABIHF:
  329. case llvm::Triple::MuslEABIHF:
  330. case llvm::Triple::EABIHF:
  331. return FloatABI::Hard;
  332. case llvm::Triple::GNUEABI:
  333. case llvm::Triple::MuslEABI:
  334. case llvm::Triple::EABI:
  335. // EABI is always AAPCS, and if it was not marked 'hard', it's softfp
  336. return FloatABI::SoftFP;
  337. case llvm::Triple::Android:
  338. return (SubArch >= 7) ? FloatABI::SoftFP : FloatABI::Soft;
  339. default:
  340. return FloatABI::Invalid;
  341. }
  342. }
  343. return FloatABI::Invalid;
  344. }
  345. // Select the float ABI as determined by -msoft-float, -mhard-float, and
  346. // -mfloat-abi=.
  347. arm::FloatABI arm::getARMFloatABI(const Driver &D, const llvm::Triple &Triple,
  348. const ArgList &Args) {
  349. arm::FloatABI ABI = FloatABI::Invalid;
  350. if (Arg *A =
  351. Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
  352. options::OPT_mfloat_abi_EQ)) {
  353. if (A->getOption().matches(options::OPT_msoft_float)) {
  354. ABI = FloatABI::Soft;
  355. } else if (A->getOption().matches(options::OPT_mhard_float)) {
  356. ABI = FloatABI::Hard;
  357. } else {
  358. ABI = llvm::StringSwitch<arm::FloatABI>(A->getValue())
  359. .Case("soft", FloatABI::Soft)
  360. .Case("softfp", FloatABI::SoftFP)
  361. .Case("hard", FloatABI::Hard)
  362. .Default(FloatABI::Invalid);
  363. if (ABI == FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
  364. D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
  365. ABI = FloatABI::Soft;
  366. }
  367. }
  368. }
  369. // If unspecified, choose the default based on the platform.
  370. if (ABI == FloatABI::Invalid)
  371. ABI = arm::getDefaultFloatABI(Triple);
  372. if (ABI == FloatABI::Invalid) {
  373. // Assume "soft", but warn the user we are guessing.
  374. if (Triple.isOSBinFormatMachO() &&
  375. Triple.getSubArch() == llvm::Triple::ARMSubArch_v7em)
  376. ABI = FloatABI::Hard;
  377. else
  378. ABI = FloatABI::Soft;
  379. if (Triple.getOS() != llvm::Triple::UnknownOS ||
  380. !Triple.isOSBinFormatMachO())
  381. D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft";
  382. }
  383. assert(ABI != FloatABI::Invalid && "must select an ABI");
  384. return ABI;
  385. }
  386. static bool hasIntegerMVE(const std::vector<StringRef> &F) {
  387. auto MVE = llvm::find(llvm::reverse(F), "+mve");
  388. auto NoMVE = llvm::find(llvm::reverse(F), "-mve");
  389. return MVE != F.rend() &&
  390. (NoMVE == F.rend() || std::distance(MVE, NoMVE) > 0);
  391. }
  392. void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
  393. const ArgList &Args, ArgStringList &CmdArgs,
  394. std::vector<StringRef> &Features, bool ForAS) {
  395. bool KernelOrKext =
  396. Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
  397. arm::FloatABI ABI = arm::getARMFloatABI(D, Triple, Args);
  398. llvm::Optional<std::pair<const Arg *, StringRef>> WaCPU, WaFPU, WaHDiv,
  399. WaArch;
  400. // This vector will accumulate features from the architecture
  401. // extension suffixes on -mcpu and -march (e.g. the 'bar' in
  402. // -mcpu=foo+bar). We want to apply those after the features derived
  403. // from the FPU, in case -mfpu generates a negative feature which
  404. // the +bar is supposed to override.
  405. std::vector<StringRef> ExtensionFeatures;
  406. if (!ForAS) {
  407. // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
  408. // yet (it uses the -mfloat-abi and -msoft-float options), and it is
  409. // stripped out by the ARM target. We should probably pass this a new
  410. // -target-option, which is handled by the -cc1/-cc1as invocation.
  411. //
  412. // FIXME2: For consistency, it would be ideal if we set up the target
  413. // machine state the same when using the frontend or the assembler. We don't
  414. // currently do that for the assembler, we pass the options directly to the
  415. // backend and never even instantiate the frontend TargetInfo. If we did,
  416. // and used its handleTargetFeatures hook, then we could ensure the
  417. // assembler and the frontend behave the same.
  418. // Use software floating point operations?
  419. if (ABI == arm::FloatABI::Soft)
  420. Features.push_back("+soft-float");
  421. // Use software floating point argument passing?
  422. if (ABI != arm::FloatABI::Hard)
  423. Features.push_back("+soft-float-abi");
  424. } else {
  425. // Here, we make sure that -Wa,-mfpu/cpu/arch/hwdiv will be passed down
  426. // to the assembler correctly.
  427. for (const Arg *A :
  428. Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
  429. // We use getValues here because you can have many options per -Wa
  430. // We will keep the last one we find for each of these
  431. for (StringRef Value : A->getValues()) {
  432. if (Value.startswith("-mfpu=")) {
  433. WaFPU = std::make_pair(A, Value.substr(6));
  434. } else if (Value.startswith("-mcpu=")) {
  435. WaCPU = std::make_pair(A, Value.substr(6));
  436. } else if (Value.startswith("-mhwdiv=")) {
  437. WaHDiv = std::make_pair(A, Value.substr(8));
  438. } else if (Value.startswith("-march=")) {
  439. WaArch = std::make_pair(A, Value.substr(7));
  440. }
  441. }
  442. }
  443. }
  444. if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::Cp15)
  445. Features.push_back("+read-tp-hard");
  446. const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
  447. const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
  448. StringRef ArchName;
  449. StringRef CPUName;
  450. unsigned ArchArgFPUID = llvm::ARM::FK_INVALID;
  451. unsigned CPUArgFPUID = llvm::ARM::FK_INVALID;
  452. // Check -mcpu. ClangAs gives preference to -Wa,-mcpu=.
  453. if (WaCPU) {
  454. if (CPUArg)
  455. D.Diag(clang::diag::warn_drv_unused_argument)
  456. << CPUArg->getAsString(Args);
  457. CPUName = WaCPU->second;
  458. CPUArg = WaCPU->first;
  459. } else if (CPUArg)
  460. CPUName = CPUArg->getValue();
  461. // Check -march. ClangAs gives preference to -Wa,-march=.
  462. if (WaArch) {
  463. if (ArchArg)
  464. D.Diag(clang::diag::warn_drv_unused_argument)
  465. << ArchArg->getAsString(Args);
  466. ArchName = WaArch->second;
  467. // This will set any features after the base architecture.
  468. checkARMArchName(D, WaArch->first, Args, ArchName, CPUName,
  469. ExtensionFeatures, Triple, ArchArgFPUID);
  470. // The base architecture was handled in ToolChain::ComputeLLVMTriple because
  471. // triple is read only by this point.
  472. } else if (ArchArg) {
  473. ArchName = ArchArg->getValue();
  474. checkARMArchName(D, ArchArg, Args, ArchName, CPUName, ExtensionFeatures,
  475. Triple, ArchArgFPUID);
  476. }
  477. // Add CPU features for generic CPUs
  478. if (CPUName == "native") {
  479. llvm::StringMap<bool> HostFeatures;
  480. if (llvm::sys::getHostCPUFeatures(HostFeatures))
  481. for (auto &F : HostFeatures)
  482. Features.push_back(
  483. Args.MakeArgString((F.second ? "+" : "-") + F.first()));
  484. } else if (!CPUName.empty()) {
  485. // This sets the default features for the specified CPU. We certainly don't
  486. // want to override the features that have been explicitly specified on the
  487. // command line. Therefore, process them directly instead of appending them
  488. // at the end later.
  489. DecodeARMFeaturesFromCPU(D, CPUName, Features);
  490. }
  491. if (CPUArg)
  492. checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, ExtensionFeatures,
  493. Triple, CPUArgFPUID);
  494. // Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=.
  495. unsigned FPUID = llvm::ARM::FK_INVALID;
  496. const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
  497. if (WaFPU) {
  498. if (FPUArg)
  499. D.Diag(clang::diag::warn_drv_unused_argument)
  500. << FPUArg->getAsString(Args);
  501. (void)getARMFPUFeatures(D, WaFPU->first, Args, WaFPU->second, Features);
  502. } else if (FPUArg) {
  503. FPUID = getARMFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features);
  504. } else if (Triple.isAndroid() && getARMSubArchVersionNumber(Triple) >= 7) {
  505. const char *AndroidFPU = "neon";
  506. FPUID = llvm::ARM::parseFPU(AndroidFPU);
  507. if (!llvm::ARM::getFPUFeatures(FPUID, Features))
  508. D.Diag(clang::diag::err_drv_clang_unsupported)
  509. << std::string("-mfpu=") + AndroidFPU;
  510. } else {
  511. if (!ForAS) {
  512. std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
  513. llvm::ARM::ArchKind ArchKind =
  514. arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
  515. FPUID = llvm::ARM::getDefaultFPU(CPU, ArchKind);
  516. (void)llvm::ARM::getFPUFeatures(FPUID, Features);
  517. }
  518. }
  519. // Now we've finished accumulating features from arch, cpu and fpu,
  520. // we can append the ones for architecture extensions that we
  521. // collected separately.
  522. Features.insert(std::end(Features),
  523. std::begin(ExtensionFeatures), std::end(ExtensionFeatures));
  524. // Honor -mhwdiv=. ClangAs gives preference to -Wa,-mhwdiv=.
  525. const Arg *HDivArg = Args.getLastArg(options::OPT_mhwdiv_EQ);
  526. if (WaHDiv) {
  527. if (HDivArg)
  528. D.Diag(clang::diag::warn_drv_unused_argument)
  529. << HDivArg->getAsString(Args);
  530. getARMHWDivFeatures(D, WaHDiv->first, Args, WaHDiv->second, Features);
  531. } else if (HDivArg)
  532. getARMHWDivFeatures(D, HDivArg, Args, HDivArg->getValue(), Features);
  533. // Handle (arch-dependent) fp16fml/fullfp16 relationship.
  534. // Must happen before any features are disabled due to soft-float.
  535. // FIXME: this fp16fml option handling will be reimplemented after the
  536. // TargetParser rewrite.
  537. const auto ItRNoFullFP16 = std::find(Features.rbegin(), Features.rend(), "-fullfp16");
  538. const auto ItRFP16FML = std::find(Features.rbegin(), Features.rend(), "+fp16fml");
  539. if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8_4a) {
  540. const auto ItRFullFP16 = std::find(Features.rbegin(), Features.rend(), "+fullfp16");
  541. if (ItRFullFP16 < ItRNoFullFP16 && ItRFullFP16 < ItRFP16FML) {
  542. // Only entangled feature that can be to the right of this +fullfp16 is -fp16fml.
  543. // Only append the +fp16fml if there is no -fp16fml after the +fullfp16.
  544. if (std::find(Features.rbegin(), ItRFullFP16, "-fp16fml") == ItRFullFP16)
  545. Features.push_back("+fp16fml");
  546. }
  547. else
  548. goto fp16_fml_fallthrough;
  549. }
  550. else {
  551. fp16_fml_fallthrough:
  552. // In both of these cases, putting the 'other' feature on the end of the vector will
  553. // result in the same effect as placing it immediately after the current feature.
  554. if (ItRNoFullFP16 < ItRFP16FML)
  555. Features.push_back("-fp16fml");
  556. else if (ItRNoFullFP16 > ItRFP16FML)
  557. Features.push_back("+fullfp16");
  558. }
  559. // Setting -msoft-float/-mfloat-abi=soft, -mfpu=none, or adding +nofp to
  560. // -march/-mcpu effectively disables the FPU (GCC ignores the -mfpu options in
  561. // this case). Note that the ABI can also be set implicitly by the target
  562. // selected.
  563. if (ABI == arm::FloatABI::Soft) {
  564. llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features);
  565. // Disable all features relating to hardware FP, not already disabled by the
  566. // above call.
  567. Features.insert(Features.end(), {"-dotprod", "-fp16fml", "-bf16", "-mve",
  568. "-mve.fp", "-fpregs"});
  569. } else if (FPUID == llvm::ARM::FK_NONE ||
  570. ArchArgFPUID == llvm::ARM::FK_NONE ||
  571. CPUArgFPUID == llvm::ARM::FK_NONE) {
  572. // -mfpu=none, -march=armvX+nofp or -mcpu=X+nofp is *very* similar to
  573. // -mfloat-abi=soft, only that it should not disable MVE-I. They disable the
  574. // FPU, but not the FPU registers, thus MVE-I, which depends only on the
  575. // latter, is still supported.
  576. Features.insert(Features.end(),
  577. {"-dotprod", "-fp16fml", "-bf16", "-mve.fp"});
  578. if (!hasIntegerMVE(Features))
  579. Features.emplace_back("-fpregs");
  580. }
  581. // En/disable crc code generation.
  582. if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
  583. if (A->getOption().matches(options::OPT_mcrc))
  584. Features.push_back("+crc");
  585. else
  586. Features.push_back("-crc");
  587. }
  588. // For Arch >= ARMv8.0 && A or R profile: crypto = sha2 + aes
  589. // Rather than replace within the feature vector, determine whether each
  590. // algorithm is enabled and append this to the end of the vector.
  591. // The algorithms can be controlled by their specific feature or the crypto
  592. // feature, so their status can be determined by the last occurance of
  593. // either in the vector. This allows one to supercede the other.
  594. // e.g. +crypto+noaes in -march/-mcpu should enable sha2, but not aes
  595. // FIXME: this needs reimplementation after the TargetParser rewrite
  596. bool HasSHA2 = false;
  597. bool HasAES = false;
  598. const auto ItCrypto =
  599. llvm::find_if(llvm::reverse(Features), [](const StringRef F) {
  600. return F.contains("crypto");
  601. });
  602. const auto ItSHA2 =
  603. llvm::find_if(llvm::reverse(Features), [](const StringRef F) {
  604. return F.contains("crypto") || F.contains("sha2");
  605. });
  606. const auto ItAES =
  607. llvm::find_if(llvm::reverse(Features), [](const StringRef F) {
  608. return F.contains("crypto") || F.contains("aes");
  609. });
  610. const bool FoundSHA2 = ItSHA2 != Features.rend();
  611. const bool FoundAES = ItAES != Features.rend();
  612. if (FoundSHA2)
  613. HasSHA2 = ItSHA2->take_front() == "+";
  614. if (FoundAES)
  615. HasAES = ItAES->take_front() == "+";
  616. if (ItCrypto != Features.rend()) {
  617. if (HasSHA2 && HasAES)
  618. Features.push_back("+crypto");
  619. else
  620. Features.push_back("-crypto");
  621. if (HasSHA2)
  622. Features.push_back("+sha2");
  623. else
  624. Features.push_back("-sha2");
  625. if (HasAES)
  626. Features.push_back("+aes");
  627. else
  628. Features.push_back("-aes");
  629. }
  630. if (HasSHA2 || HasAES) {
  631. StringRef ArchSuffix = arm::getLLVMArchSuffixForARM(
  632. arm::getARMTargetCPU(CPUName, ArchName, Triple), ArchName, Triple);
  633. llvm::ARM::ProfileKind ArchProfile =
  634. llvm::ARM::parseArchProfile(ArchSuffix);
  635. if (!((llvm::ARM::parseArchVersion(ArchSuffix) >= 8) &&
  636. (ArchProfile == llvm::ARM::ProfileKind::A ||
  637. ArchProfile == llvm::ARM::ProfileKind::R))) {
  638. if (HasSHA2)
  639. D.Diag(clang::diag::warn_target_unsupported_extension)
  640. << "sha2"
  641. << llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
  642. if (HasAES)
  643. D.Diag(clang::diag::warn_target_unsupported_extension)
  644. << "aes"
  645. << llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
  646. // With -fno-integrated-as -mfpu=crypto-neon-fp-armv8 some assemblers such
  647. // as the GNU assembler will permit the use of crypto instructions as the
  648. // fpu will override the architecture. We keep the crypto feature in this
  649. // case to preserve compatibility. In all other cases we remove the crypto
  650. // feature.
  651. if (!Args.hasArg(options::OPT_fno_integrated_as)) {
  652. Features.push_back("-sha2");
  653. Features.push_back("-aes");
  654. }
  655. }
  656. }
  657. // CMSE: Check for target 8M (for -mcmse to be applicable) is performed later.
  658. if (Args.getLastArg(options::OPT_mcmse))
  659. Features.push_back("+8msecext");
  660. if (Arg *A = Args.getLastArg(options::OPT_mfix_cmse_cve_2021_35465,
  661. options::OPT_mno_fix_cmse_cve_2021_35465)) {
  662. if (!Args.getLastArg(options::OPT_mcmse))
  663. D.Diag(diag::err_opt_not_valid_without_opt)
  664. << A->getOption().getName() << "-mcmse";
  665. if (A->getOption().matches(options::OPT_mfix_cmse_cve_2021_35465))
  666. Features.push_back("+fix-cmse-cve-2021-35465");
  667. else
  668. Features.push_back("-fix-cmse-cve-2021-35465");
  669. }
  670. // Look for the last occurrence of -mlong-calls or -mno-long-calls. If
  671. // neither options are specified, see if we are compiling for kernel/kext and
  672. // decide whether to pass "+long-calls" based on the OS and its version.
  673. if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
  674. options::OPT_mno_long_calls)) {
  675. if (A->getOption().matches(options::OPT_mlong_calls))
  676. Features.push_back("+long-calls");
  677. } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
  678. !Triple.isWatchOS()) {
  679. Features.push_back("+long-calls");
  680. }
  681. // Generate execute-only output (no data access to code sections).
  682. // This only makes sense for the compiler, not for the assembler.
  683. if (!ForAS) {
  684. // Supported only on ARMv6T2 and ARMv7 and above.
  685. // Cannot be combined with -mno-movt or -mlong-calls
  686. if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) {
  687. if (A->getOption().matches(options::OPT_mexecute_only)) {
  688. if (getARMSubArchVersionNumber(Triple) < 7 &&
  689. llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2)
  690. D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName();
  691. else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
  692. D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args);
  693. // Long calls create constant pool entries and have not yet been fixed up
  694. // to play nicely with execute-only. Hence, they cannot be used in
  695. // execute-only code for now
  696. else if (Arg *B = Args.getLastArg(options::OPT_mlong_calls, options::OPT_mno_long_calls)) {
  697. if (B->getOption().matches(options::OPT_mlong_calls))
  698. D.Diag(diag::err_opt_not_valid_with_opt) << A->getAsString(Args) << B->getAsString(Args);
  699. }
  700. Features.push_back("+execute-only");
  701. }
  702. }
  703. }
  704. // Kernel code has more strict alignment requirements.
  705. if (KernelOrKext) {
  706. Features.push_back("+strict-align");
  707. if (!ForAS)
  708. CmdArgs.push_back("-Wunaligned-access");
  709. } else if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
  710. options::OPT_munaligned_access)) {
  711. if (A->getOption().matches(options::OPT_munaligned_access)) {
  712. // No v6M core supports unaligned memory access (v6M ARM ARM A3.2).
  713. if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
  714. D.Diag(diag::err_target_unsupported_unaligned) << "v6m";
  715. // v8M Baseline follows on from v6M, so doesn't support unaligned memory
  716. // access either.
  717. else if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
  718. D.Diag(diag::err_target_unsupported_unaligned) << "v8m.base";
  719. } else {
  720. Features.push_back("+strict-align");
  721. if (!ForAS)
  722. CmdArgs.push_back("-Wunaligned-access");
  723. }
  724. } else {
  725. // Assume pre-ARMv6 doesn't support unaligned accesses.
  726. //
  727. // ARMv6 may or may not support unaligned accesses depending on the
  728. // SCTLR.U bit, which is architecture-specific. We assume ARMv6
  729. // Darwin and NetBSD targets support unaligned accesses, and others don't.
  730. //
  731. // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
  732. // which raises an alignment fault on unaligned accesses. Linux
  733. // defaults this bit to 0 and handles it as a system-wide (not
  734. // per-process) setting. It is therefore safe to assume that ARMv7+
  735. // Linux targets support unaligned accesses. The same goes for NaCl
  736. // and Windows.
  737. //
  738. // The above behavior is consistent with GCC.
  739. int VersionNum = getARMSubArchVersionNumber(Triple);
  740. if (Triple.isOSDarwin() || Triple.isOSNetBSD()) {
  741. if (VersionNum < 6 ||
  742. Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m) {
  743. Features.push_back("+strict-align");
  744. if (!ForAS)
  745. CmdArgs.push_back("-Wunaligned-access");
  746. }
  747. } else if (Triple.isOSLinux() || Triple.isOSNaCl() ||
  748. Triple.isOSWindows()) {
  749. if (VersionNum < 7) {
  750. Features.push_back("+strict-align");
  751. if (!ForAS)
  752. CmdArgs.push_back("-Wunaligned-access");
  753. }
  754. } else {
  755. Features.push_back("+strict-align");
  756. if (!ForAS)
  757. CmdArgs.push_back("-Wunaligned-access");
  758. }
  759. }
  760. // llvm does not support reserving registers in general. There is support
  761. // for reserving r9 on ARM though (defined as a platform-specific register
  762. // in ARM EABI).
  763. if (Args.hasArg(options::OPT_ffixed_r9))
  764. Features.push_back("+reserve-r9");
  765. // The kext linker doesn't know how to deal with movw/movt.
  766. if (KernelOrKext || Args.hasArg(options::OPT_mno_movt))
  767. Features.push_back("+no-movt");
  768. if (Args.hasArg(options::OPT_mno_neg_immediates))
  769. Features.push_back("+no-neg-immediates");
  770. // Enable/disable straight line speculation hardening.
  771. if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
  772. StringRef Scope = A->getValue();
  773. bool EnableRetBr = false;
  774. bool EnableBlr = false;
  775. bool DisableComdat = false;
  776. if (Scope != "none") {
  777. SmallVector<StringRef, 4> Opts;
  778. Scope.split(Opts, ",");
  779. for (auto Opt : Opts) {
  780. Opt = Opt.trim();
  781. if (Opt == "all") {
  782. EnableBlr = true;
  783. EnableRetBr = true;
  784. continue;
  785. }
  786. if (Opt == "retbr") {
  787. EnableRetBr = true;
  788. continue;
  789. }
  790. if (Opt == "blr") {
  791. EnableBlr = true;
  792. continue;
  793. }
  794. if (Opt == "comdat") {
  795. DisableComdat = false;
  796. continue;
  797. }
  798. if (Opt == "nocomdat") {
  799. DisableComdat = true;
  800. continue;
  801. }
  802. D.Diag(diag::err_invalid_sls_hardening)
  803. << Scope << A->getAsString(Args);
  804. break;
  805. }
  806. }
  807. if (EnableRetBr || EnableBlr)
  808. if (!(isARMAProfile(Triple) && getARMSubArchVersionNumber(Triple) >= 7))
  809. D.Diag(diag::err_sls_hardening_arm_not_supported)
  810. << Scope << A->getAsString(Args);
  811. if (EnableRetBr)
  812. Features.push_back("+harden-sls-retbr");
  813. if (EnableBlr)
  814. Features.push_back("+harden-sls-blr");
  815. if (DisableComdat) {
  816. Features.push_back("+harden-sls-nocomdat");
  817. }
  818. }
  819. if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
  820. Features.push_back("+no-bti-at-return-twice");
  821. }
  822. std::string arm::getARMArch(StringRef Arch, const llvm::Triple &Triple) {
  823. std::string MArch;
  824. if (!Arch.empty())
  825. MArch = std::string(Arch);
  826. else
  827. MArch = std::string(Triple.getArchName());
  828. MArch = StringRef(MArch).split("+").first.lower();
  829. // Handle -march=native.
  830. if (MArch == "native") {
  831. std::string CPU = std::string(llvm::sys::getHostCPUName());
  832. if (CPU != "generic") {
  833. // Translate the native cpu into the architecture suffix for that CPU.
  834. StringRef Suffix = arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
  835. // If there is no valid architecture suffix for this CPU we don't know how
  836. // to handle it, so return no architecture.
  837. if (Suffix.empty())
  838. MArch = "";
  839. else
  840. MArch = std::string("arm") + Suffix.str();
  841. }
  842. }
  843. return MArch;
  844. }
  845. /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
  846. StringRef arm::getARMCPUForMArch(StringRef Arch, const llvm::Triple &Triple) {
  847. std::string MArch = getARMArch(Arch, Triple);
  848. // getARMCPUForArch defaults to the triple if MArch is empty, but empty MArch
  849. // here means an -march=native that we can't handle, so instead return no CPU.
  850. if (MArch.empty())
  851. return StringRef();
  852. // We need to return an empty string here on invalid MArch values as the
  853. // various places that call this function can't cope with a null result.
  854. return Triple.getARMCPUForArch(MArch);
  855. }
  856. /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
  857. std::string arm::getARMTargetCPU(StringRef CPU, StringRef Arch,
  858. const llvm::Triple &Triple) {
  859. // FIXME: Warn on inconsistent use of -mcpu and -march.
  860. // If we have -mcpu=, use that.
  861. if (!CPU.empty()) {
  862. std::string MCPU = StringRef(CPU).split("+").first.lower();
  863. // Handle -mcpu=native.
  864. if (MCPU == "native")
  865. return std::string(llvm::sys::getHostCPUName());
  866. else
  867. return MCPU;
  868. }
  869. return std::string(getARMCPUForMArch(Arch, Triple));
  870. }
  871. /// getLLVMArchSuffixForARM - Get the LLVM ArchKind value to use for a
  872. /// particular CPU (or Arch, if CPU is generic). This is needed to
  873. /// pass to functions like llvm::ARM::getDefaultFPU which need an
  874. /// ArchKind as well as a CPU name.
  875. llvm::ARM::ArchKind arm::getLLVMArchKindForARM(StringRef CPU, StringRef Arch,
  876. const llvm::Triple &Triple) {
  877. llvm::ARM::ArchKind ArchKind;
  878. if (CPU == "generic" || CPU.empty()) {
  879. std::string ARMArch = tools::arm::getARMArch(Arch, Triple);
  880. ArchKind = llvm::ARM::parseArch(ARMArch);
  881. if (ArchKind == llvm::ARM::ArchKind::INVALID)
  882. // In case of generic Arch, i.e. "arm",
  883. // extract arch from default cpu of the Triple
  884. ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(ARMArch));
  885. } else {
  886. // FIXME: horrible hack to get around the fact that Cortex-A7 is only an
  887. // armv7k triple if it's actually been specified via "-arch armv7k".
  888. ArchKind = (Arch == "armv7k" || Arch == "thumbv7k")
  889. ? llvm::ARM::ArchKind::ARMV7K
  890. : llvm::ARM::parseCPUArch(CPU);
  891. }
  892. return ArchKind;
  893. }
  894. /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
  895. /// CPU (or Arch, if CPU is generic).
  896. // FIXME: This is redundant with -mcpu, why does LLVM use this.
  897. StringRef arm::getLLVMArchSuffixForARM(StringRef CPU, StringRef Arch,
  898. const llvm::Triple &Triple) {
  899. llvm::ARM::ArchKind ArchKind = getLLVMArchKindForARM(CPU, Arch, Triple);
  900. if (ArchKind == llvm::ARM::ArchKind::INVALID)
  901. return "";
  902. return llvm::ARM::getSubArch(ArchKind);
  903. }
  904. void arm::appendBE8LinkFlag(const ArgList &Args, ArgStringList &CmdArgs,
  905. const llvm::Triple &Triple) {
  906. if (Args.hasArg(options::OPT_r))
  907. return;
  908. // ARMv7 (and later) and ARMv6-M do not support BE-32, so instruct the linker
  909. // to generate BE-8 executables.
  910. if (arm::getARMSubArchVersionNumber(Triple) >= 7 || arm::isARMMProfile(Triple))
  911. CmdArgs.push_back("--be8");
  912. }