X86.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. //===--- X86.h - Declare X86 target feature support -------------*- 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. //
  9. // This file declares X86 TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
  14. #include "OSTargets.h"
  15. #include "clang/Basic/TargetInfo.h"
  16. #include "clang/Basic/TargetOptions.h"
  17. #include "llvm/ADT/Triple.h"
  18. #include "llvm/Support/Compiler.h"
  19. namespace clang {
  20. namespace targets {
  21. // X86 target abstract base class; x86-32 and x86-64 are very close, so
  22. // most of the implementation can be shared.
  23. class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
  24. enum X86SSEEnum {
  25. NoSSE,
  26. SSE1,
  27. SSE2,
  28. SSE3,
  29. SSSE3,
  30. SSE41,
  31. SSE42,
  32. AVX,
  33. AVX2,
  34. AVX512F
  35. } SSELevel = NoSSE;
  36. enum MMX3DNowEnum {
  37. NoMMX3DNow,
  38. MMX,
  39. AMD3DNow,
  40. AMD3DNowAthlon
  41. } MMX3DNowLevel = NoMMX3DNow;
  42. enum XOPEnum { NoXOP, SSE4A, FMA4, XOP } XOPLevel = NoXOP;
  43. bool HasAES = false;
  44. bool HasVAES = false;
  45. bool HasPCLMUL = false;
  46. bool HasVPCLMULQDQ = false;
  47. bool HasGFNI = false;
  48. bool HasLZCNT = false;
  49. bool HasRDRND = false;
  50. bool HasFSGSBASE = false;
  51. bool HasBMI = false;
  52. bool HasBMI2 = false;
  53. bool HasPOPCNT = false;
  54. bool HasRTM = false;
  55. bool HasPRFCHW = false;
  56. bool HasRDSEED = false;
  57. bool HasADX = false;
  58. bool HasTBM = false;
  59. bool HasLWP = false;
  60. bool HasFMA = false;
  61. bool HasF16C = false;
  62. bool HasAVX512CD = false;
  63. bool HasAVX512VPOPCNTDQ = false;
  64. bool HasAVX512VNNI = false;
  65. bool HasAVX512BF16 = false;
  66. bool HasAVX512ER = false;
  67. bool HasAVX512PF = false;
  68. bool HasAVX512DQ = false;
  69. bool HasAVX512BITALG = false;
  70. bool HasAVX512BW = false;
  71. bool HasAVX512VL = false;
  72. bool HasAVX512VBMI = false;
  73. bool HasAVX512VBMI2 = false;
  74. bool HasAVX512IFMA = false;
  75. bool HasAVX512VP2INTERSECT = false;
  76. bool HasSHA = false;
  77. bool HasSHSTK = false;
  78. bool HasSGX = false;
  79. bool HasCX8 = false;
  80. bool HasCX16 = false;
  81. bool HasFXSR = false;
  82. bool HasXSAVE = false;
  83. bool HasXSAVEOPT = false;
  84. bool HasXSAVEC = false;
  85. bool HasXSAVES = false;
  86. bool HasMWAITX = false;
  87. bool HasCLZERO = false;
  88. bool HasCLDEMOTE = false;
  89. bool HasPCONFIG = false;
  90. bool HasPKU = false;
  91. bool HasCLFLUSHOPT = false;
  92. bool HasCLWB = false;
  93. bool HasMOVBE = false;
  94. bool HasPREFETCHWT1 = false;
  95. bool HasRDPID = false;
  96. bool HasRetpolineExternalThunk = false;
  97. bool HasLAHFSAHF = false;
  98. bool HasWBNOINVD = false;
  99. bool HasWAITPKG = false;
  100. bool HasMOVDIRI = false;
  101. bool HasMOVDIR64B = false;
  102. bool HasPTWRITE = false;
  103. bool HasINVPCID = false;
  104. bool HasENQCMD = false;
  105. protected:
  106. /// Enumeration of all of the X86 CPUs supported by Clang.
  107. ///
  108. /// Each enumeration represents a particular CPU supported by Clang. These
  109. /// loosely correspond to the options passed to '-march' or '-mtune' flags.
  110. enum CPUKind {
  111. CK_Generic,
  112. #define PROC(ENUM, STRING, IS64BIT) CK_##ENUM,
  113. #include "clang/Basic/X86Target.def"
  114. } CPU = CK_Generic;
  115. bool checkCPUKind(CPUKind Kind) const;
  116. CPUKind getCPUKind(StringRef CPU) const;
  117. enum FPMathKind { FP_Default, FP_SSE, FP_387 } FPMath = FP_Default;
  118. public:
  119. X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  120. : TargetInfo(Triple) {
  121. LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
  122. }
  123. const char *getLongDoubleMangling() const override {
  124. return LongDoubleFormat == &llvm::APFloat::IEEEquad() ? "g" : "e";
  125. }
  126. unsigned getFloatEvalMethod() const override {
  127. // X87 evaluates with 80 bits "long double" precision.
  128. return SSELevel == NoSSE ? 2 : 0;
  129. }
  130. ArrayRef<const char *> getGCCRegNames() const override;
  131. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
  132. return None;
  133. }
  134. ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
  135. bool validateCpuSupports(StringRef Name) const override;
  136. bool validateCpuIs(StringRef Name) const override;
  137. bool validateCPUSpecificCPUDispatch(StringRef Name) const override;
  138. char CPUSpecificManglingCharacter(StringRef Name) const override;
  139. void getCPUSpecificCPUDispatchFeatures(
  140. StringRef Name,
  141. llvm::SmallVectorImpl<StringRef> &Features) const override;
  142. bool validateAsmConstraint(const char *&Name,
  143. TargetInfo::ConstraintInfo &info) const override;
  144. bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
  145. bool &HasSizeMismatch) const override {
  146. // esp and ebp are the only 32-bit registers the x86 backend can currently
  147. // handle.
  148. if (RegName.equals("esp") || RegName.equals("ebp")) {
  149. // Check that the register size is 32-bit.
  150. HasSizeMismatch = RegSize != 32;
  151. return true;
  152. }
  153. return false;
  154. }
  155. bool validateOutputSize(StringRef Constraint, unsigned Size) const override;
  156. bool validateInputSize(StringRef Constraint, unsigned Size) const override;
  157. virtual bool
  158. checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
  159. return true;
  160. };
  161. virtual bool
  162. checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
  163. return true;
  164. };
  165. virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const;
  166. std::string convertConstraint(const char *&Constraint) const override;
  167. const char *getClobbers() const override {
  168. return "~{dirflag},~{fpsr},~{flags}";
  169. }
  170. StringRef getConstraintRegister(StringRef Constraint,
  171. StringRef Expression) const override {
  172. StringRef::iterator I, E;
  173. for (I = Constraint.begin(), E = Constraint.end(); I != E; ++I) {
  174. if (isalpha(*I) || *I == '@')
  175. break;
  176. }
  177. if (I == E)
  178. return "";
  179. switch (*I) {
  180. // For the register constraints, return the matching register name
  181. case 'a':
  182. return "ax";
  183. case 'b':
  184. return "bx";
  185. case 'c':
  186. return "cx";
  187. case 'd':
  188. return "dx";
  189. case 'S':
  190. return "si";
  191. case 'D':
  192. return "di";
  193. // In case the constraint is 'r' we need to return Expression
  194. case 'r':
  195. return Expression;
  196. // Double letters Y<x> constraints
  197. case 'Y':
  198. if ((++I != E) && ((*I == '0') || (*I == 'z')))
  199. return "xmm0";
  200. break;
  201. default:
  202. break;
  203. }
  204. return "";
  205. }
  206. bool useFP16ConversionIntrinsics() const override {
  207. return false;
  208. }
  209. void getTargetDefines(const LangOptions &Opts,
  210. MacroBuilder &Builder) const override;
  211. static void setSSELevel(llvm::StringMap<bool> &Features, X86SSEEnum Level,
  212. bool Enabled);
  213. static void setMMXLevel(llvm::StringMap<bool> &Features, MMX3DNowEnum Level,
  214. bool Enabled);
  215. static void setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
  216. bool Enabled);
  217. void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
  218. bool Enabled) const override {
  219. setFeatureEnabledImpl(Features, Name, Enabled);
  220. }
  221. // This exists purely to cut down on the number of virtual calls in
  222. // initFeatureMap which calls this repeatedly.
  223. static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
  224. StringRef Name, bool Enabled);
  225. bool
  226. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  227. StringRef CPU,
  228. const std::vector<std::string> &FeaturesVec) const override;
  229. bool isValidFeatureName(StringRef Name) const override;
  230. bool hasFeature(StringRef Feature) const override;
  231. bool handleTargetFeatures(std::vector<std::string> &Features,
  232. DiagnosticsEngine &Diags) override;
  233. StringRef getABI() const override {
  234. if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX512F)
  235. return "avx512";
  236. if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX)
  237. return "avx";
  238. if (getTriple().getArch() == llvm::Triple::x86 &&
  239. MMX3DNowLevel == NoMMX3DNow)
  240. return "no-mmx";
  241. return "";
  242. }
  243. bool isValidCPUName(StringRef Name) const override {
  244. return checkCPUKind(getCPUKind(Name));
  245. }
  246. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  247. bool setCPU(const std::string &Name) override {
  248. return checkCPUKind(CPU = getCPUKind(Name));
  249. }
  250. unsigned multiVersionSortPriority(StringRef Name) const override;
  251. bool setFPMath(StringRef Name) override;
  252. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  253. // Most of the non-ARM calling conventions are i386 conventions.
  254. switch (CC) {
  255. case CC_X86ThisCall:
  256. case CC_X86FastCall:
  257. case CC_X86StdCall:
  258. case CC_X86VectorCall:
  259. case CC_X86RegCall:
  260. case CC_C:
  261. case CC_PreserveMost:
  262. case CC_Swift:
  263. case CC_X86Pascal:
  264. case CC_IntelOclBicc:
  265. case CC_OpenCLKernel:
  266. return CCCR_OK;
  267. default:
  268. return CCCR_Warning;
  269. }
  270. }
  271. CallingConv getDefaultCallingConv() const override {
  272. return CC_C;
  273. }
  274. bool hasSjLjLowering() const override { return true; }
  275. void setSupportedOpenCLOpts() override {
  276. getSupportedOpenCLOpts().supportAll();
  277. }
  278. };
  279. // X86-32 generic target
  280. class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo {
  281. public:
  282. X86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  283. : X86TargetInfo(Triple, Opts) {
  284. DoubleAlign = LongLongAlign = 32;
  285. LongDoubleWidth = 96;
  286. LongDoubleAlign = 32;
  287. SuitableAlign = 128;
  288. resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
  289. "f80:32-n8:16:32-S128");
  290. SizeType = UnsignedInt;
  291. PtrDiffType = SignedInt;
  292. IntPtrType = SignedInt;
  293. RegParmMax = 3;
  294. // Use fpret for all types.
  295. RealTypeUsesObjCFPRet =
  296. ((1 << TargetInfo::Float) | (1 << TargetInfo::Double) |
  297. (1 << TargetInfo::LongDouble));
  298. // x86-32 has atomics up to 8 bytes
  299. MaxAtomicPromoteWidth = 64;
  300. MaxAtomicInlineWidth = 32;
  301. }
  302. BuiltinVaListKind getBuiltinVaListKind() const override {
  303. return TargetInfo::CharPtrBuiltinVaList;
  304. }
  305. int getEHDataRegisterNumber(unsigned RegNo) const override {
  306. if (RegNo == 0)
  307. return 0;
  308. if (RegNo == 1)
  309. return 2;
  310. return -1;
  311. }
  312. bool validateOperandSize(StringRef Constraint, unsigned Size) const override {
  313. switch (Constraint[0]) {
  314. default:
  315. break;
  316. case 'R':
  317. case 'q':
  318. case 'Q':
  319. case 'a':
  320. case 'b':
  321. case 'c':
  322. case 'd':
  323. case 'S':
  324. case 'D':
  325. return Size <= 32;
  326. case 'A':
  327. return Size <= 64;
  328. }
  329. return X86TargetInfo::validateOperandSize(Constraint, Size);
  330. }
  331. void setMaxAtomicWidth() override {
  332. if (hasFeature("cx8"))
  333. MaxAtomicInlineWidth = 64;
  334. }
  335. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  336. };
  337. class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
  338. : public NetBSDTargetInfo<X86_32TargetInfo> {
  339. public:
  340. NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  341. : NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
  342. unsigned getFloatEvalMethod() const override {
  343. unsigned Major, Minor, Micro;
  344. getTriple().getOSVersion(Major, Minor, Micro);
  345. // New NetBSD uses the default rounding mode.
  346. if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
  347. return X86_32TargetInfo::getFloatEvalMethod();
  348. // NetBSD before 6.99.26 defaults to "double" rounding.
  349. return 1;
  350. }
  351. };
  352. class LLVM_LIBRARY_VISIBILITY OpenBSDI386TargetInfo
  353. : public OpenBSDTargetInfo<X86_32TargetInfo> {
  354. public:
  355. OpenBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  356. : OpenBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {
  357. SizeType = UnsignedLong;
  358. IntPtrType = SignedLong;
  359. PtrDiffType = SignedLong;
  360. }
  361. };
  362. class LLVM_LIBRARY_VISIBILITY DarwinI386TargetInfo
  363. : public DarwinTargetInfo<X86_32TargetInfo> {
  364. public:
  365. DarwinI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  366. : DarwinTargetInfo<X86_32TargetInfo>(Triple, Opts) {
  367. LongDoubleWidth = 128;
  368. LongDoubleAlign = 128;
  369. SuitableAlign = 128;
  370. MaxVectorAlign = 256;
  371. // The watchOS simulator uses the builtin bool type for Objective-C.
  372. llvm::Triple T = llvm::Triple(Triple);
  373. if (T.isWatchOS())
  374. UseSignedCharForObjCBool = false;
  375. SizeType = UnsignedLong;
  376. IntPtrType = SignedLong;
  377. resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
  378. "f80:128-n8:16:32-S128");
  379. HasAlignMac68kSupport = true;
  380. }
  381. bool handleTargetFeatures(std::vector<std::string> &Features,
  382. DiagnosticsEngine &Diags) override {
  383. if (!DarwinTargetInfo<X86_32TargetInfo>::handleTargetFeatures(Features,
  384. Diags))
  385. return false;
  386. // We now know the features we have: we can decide how to align vectors.
  387. MaxVectorAlign =
  388. hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
  389. return true;
  390. }
  391. };
  392. // x86-32 Windows target
  393. class LLVM_LIBRARY_VISIBILITY WindowsX86_32TargetInfo
  394. : public WindowsTargetInfo<X86_32TargetInfo> {
  395. public:
  396. WindowsX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  397. : WindowsTargetInfo<X86_32TargetInfo>(Triple, Opts) {
  398. DoubleAlign = LongLongAlign = 64;
  399. bool IsWinCOFF =
  400. getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
  401. resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:"
  402. "64-i64:64-f80:32-n8:16:32-a:0:32-S32"
  403. : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:"
  404. "64-i64:64-f80:32-n8:16:32-a:0:32-S32");
  405. }
  406. };
  407. // x86-32 Windows Visual Studio target
  408. class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32TargetInfo
  409. : public WindowsX86_32TargetInfo {
  410. public:
  411. MicrosoftX86_32TargetInfo(const llvm::Triple &Triple,
  412. const TargetOptions &Opts)
  413. : WindowsX86_32TargetInfo(Triple, Opts) {
  414. LongDoubleWidth = LongDoubleAlign = 64;
  415. LongDoubleFormat = &llvm::APFloat::IEEEdouble();
  416. }
  417. void getTargetDefines(const LangOptions &Opts,
  418. MacroBuilder &Builder) const override {
  419. WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
  420. // The value of the following reflects processor type.
  421. // 300=386, 400=486, 500=Pentium, 600=Blend (default)
  422. // We lost the original triple, so we use the default.
  423. Builder.defineMacro("_M_IX86", "600");
  424. }
  425. };
  426. // x86-32 MinGW target
  427. class LLVM_LIBRARY_VISIBILITY MinGWX86_32TargetInfo
  428. : public WindowsX86_32TargetInfo {
  429. public:
  430. MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  431. : WindowsX86_32TargetInfo(Triple, Opts) {
  432. HasFloat128 = true;
  433. }
  434. void getTargetDefines(const LangOptions &Opts,
  435. MacroBuilder &Builder) const override {
  436. WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
  437. Builder.defineMacro("_X86_");
  438. }
  439. };
  440. // x86-32 Cygwin target
  441. class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
  442. public:
  443. CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  444. : X86_32TargetInfo(Triple, Opts) {
  445. this->WCharType = TargetInfo::UnsignedShort;
  446. DoubleAlign = LongLongAlign = 64;
  447. resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
  448. "32-n8:16:32-a:0:32-S32");
  449. }
  450. void getTargetDefines(const LangOptions &Opts,
  451. MacroBuilder &Builder) const override {
  452. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  453. Builder.defineMacro("_X86_");
  454. Builder.defineMacro("__CYGWIN__");
  455. Builder.defineMacro("__CYGWIN32__");
  456. addCygMingDefines(Opts, Builder);
  457. DefineStd(Builder, "unix", Opts);
  458. if (Opts.CPlusPlus)
  459. Builder.defineMacro("_GNU_SOURCE");
  460. }
  461. };
  462. // x86-32 Haiku target
  463. class LLVM_LIBRARY_VISIBILITY HaikuX86_32TargetInfo
  464. : public HaikuTargetInfo<X86_32TargetInfo> {
  465. public:
  466. HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  467. : HaikuTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
  468. void getTargetDefines(const LangOptions &Opts,
  469. MacroBuilder &Builder) const override {
  470. HaikuTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
  471. Builder.defineMacro("__INTEL__");
  472. }
  473. };
  474. // X86-32 MCU target
  475. class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public X86_32TargetInfo {
  476. public:
  477. MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  478. : X86_32TargetInfo(Triple, Opts) {
  479. LongDoubleWidth = 64;
  480. LongDoubleFormat = &llvm::APFloat::IEEEdouble();
  481. resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
  482. "32-f128:32-n8:16:32-a:0:32-S32");
  483. WIntType = UnsignedInt;
  484. }
  485. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  486. // On MCU we support only C calling convention.
  487. return CC == CC_C ? CCCR_OK : CCCR_Warning;
  488. }
  489. void getTargetDefines(const LangOptions &Opts,
  490. MacroBuilder &Builder) const override {
  491. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  492. Builder.defineMacro("__iamcu");
  493. Builder.defineMacro("__iamcu__");
  494. }
  495. bool allowsLargerPreferedTypeAlignment() const override { return false; }
  496. };
  497. // x86-32 RTEMS target
  498. class LLVM_LIBRARY_VISIBILITY RTEMSX86_32TargetInfo : public X86_32TargetInfo {
  499. public:
  500. RTEMSX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  501. : X86_32TargetInfo(Triple, Opts) {
  502. SizeType = UnsignedLong;
  503. IntPtrType = SignedLong;
  504. PtrDiffType = SignedLong;
  505. }
  506. void getTargetDefines(const LangOptions &Opts,
  507. MacroBuilder &Builder) const override {
  508. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  509. Builder.defineMacro("__INTEL__");
  510. Builder.defineMacro("__rtems__");
  511. }
  512. };
  513. // x86-64 generic target
  514. class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
  515. public:
  516. X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  517. : X86TargetInfo(Triple, Opts) {
  518. const bool IsX32 = getTriple().getEnvironment() == llvm::Triple::GNUX32;
  519. bool IsWinCOFF =
  520. getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
  521. LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
  522. LongDoubleWidth = 128;
  523. LongDoubleAlign = 128;
  524. LargeArrayMinWidth = 128;
  525. LargeArrayAlign = 128;
  526. SuitableAlign = 128;
  527. SizeType = IsX32 ? UnsignedInt : UnsignedLong;
  528. PtrDiffType = IsX32 ? SignedInt : SignedLong;
  529. IntPtrType = IsX32 ? SignedInt : SignedLong;
  530. IntMaxType = IsX32 ? SignedLongLong : SignedLong;
  531. Int64Type = IsX32 ? SignedLongLong : SignedLong;
  532. RegParmMax = 6;
  533. // Pointers are 32-bit in x32.
  534. resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
  535. "i64:64-f80:128-n8:16:32:64-S128"
  536. : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:"
  537. "64-i64:64-f80:128-n8:16:32:64-S128"
  538. : "e-m:e-p270:32:32-p271:32:32-p272:64:"
  539. "64-i64:64-f80:128-n8:16:32:64-S128");
  540. // Use fpret only for long double.
  541. RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
  542. // Use fp2ret for _Complex long double.
  543. ComplexLongDoubleUsesFP2Ret = true;
  544. // Make __builtin_ms_va_list available.
  545. HasBuiltinMSVaList = true;
  546. // x86-64 has atomics up to 16 bytes.
  547. MaxAtomicPromoteWidth = 128;
  548. MaxAtomicInlineWidth = 64;
  549. }
  550. BuiltinVaListKind getBuiltinVaListKind() const override {
  551. return TargetInfo::X86_64ABIBuiltinVaList;
  552. }
  553. int getEHDataRegisterNumber(unsigned RegNo) const override {
  554. if (RegNo == 0)
  555. return 0;
  556. if (RegNo == 1)
  557. return 1;
  558. return -1;
  559. }
  560. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  561. switch (CC) {
  562. case CC_C:
  563. case CC_Swift:
  564. case CC_X86VectorCall:
  565. case CC_IntelOclBicc:
  566. case CC_Win64:
  567. case CC_PreserveMost:
  568. case CC_PreserveAll:
  569. case CC_X86RegCall:
  570. case CC_OpenCLKernel:
  571. return CCCR_OK;
  572. default:
  573. return CCCR_Warning;
  574. }
  575. }
  576. CallingConv getDefaultCallingConv() const override {
  577. return CC_C;
  578. }
  579. // for x32 we need it here explicitly
  580. bool hasInt128Type() const override { return true; }
  581. unsigned getUnwindWordWidth() const override { return 64; }
  582. unsigned getRegisterWidth() const override { return 64; }
  583. bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
  584. bool &HasSizeMismatch) const override {
  585. // rsp and rbp are the only 64-bit registers the x86 backend can currently
  586. // handle.
  587. if (RegName.equals("rsp") || RegName.equals("rbp")) {
  588. // Check that the register size is 64-bit.
  589. HasSizeMismatch = RegSize != 64;
  590. return true;
  591. }
  592. // Check if the register is a 32-bit register the backend can handle.
  593. return X86TargetInfo::validateGlobalRegisterVariable(RegName, RegSize,
  594. HasSizeMismatch);
  595. }
  596. void setMaxAtomicWidth() override {
  597. if (hasFeature("cx16"))
  598. MaxAtomicInlineWidth = 128;
  599. }
  600. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  601. };
  602. // x86-64 Windows target
  603. class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
  604. : public WindowsTargetInfo<X86_64TargetInfo> {
  605. public:
  606. WindowsX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  607. : WindowsTargetInfo<X86_64TargetInfo>(Triple, Opts) {
  608. LongWidth = LongAlign = 32;
  609. DoubleAlign = LongLongAlign = 64;
  610. IntMaxType = SignedLongLong;
  611. Int64Type = SignedLongLong;
  612. SizeType = UnsignedLongLong;
  613. PtrDiffType = SignedLongLong;
  614. IntPtrType = SignedLongLong;
  615. }
  616. BuiltinVaListKind getBuiltinVaListKind() const override {
  617. return TargetInfo::CharPtrBuiltinVaList;
  618. }
  619. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  620. switch (CC) {
  621. case CC_X86StdCall:
  622. case CC_X86ThisCall:
  623. case CC_X86FastCall:
  624. return CCCR_Ignore;
  625. case CC_C:
  626. case CC_X86VectorCall:
  627. case CC_IntelOclBicc:
  628. case CC_PreserveMost:
  629. case CC_PreserveAll:
  630. case CC_X86_64SysV:
  631. case CC_Swift:
  632. case CC_X86RegCall:
  633. case CC_OpenCLKernel:
  634. return CCCR_OK;
  635. default:
  636. return CCCR_Warning;
  637. }
  638. }
  639. };
  640. // x86-64 Windows Visual Studio target
  641. class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo
  642. : public WindowsX86_64TargetInfo {
  643. public:
  644. MicrosoftX86_64TargetInfo(const llvm::Triple &Triple,
  645. const TargetOptions &Opts)
  646. : WindowsX86_64TargetInfo(Triple, Opts) {
  647. LongDoubleWidth = LongDoubleAlign = 64;
  648. LongDoubleFormat = &llvm::APFloat::IEEEdouble();
  649. }
  650. void getTargetDefines(const LangOptions &Opts,
  651. MacroBuilder &Builder) const override {
  652. WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
  653. Builder.defineMacro("_M_X64", "100");
  654. Builder.defineMacro("_M_AMD64", "100");
  655. }
  656. TargetInfo::CallingConvKind
  657. getCallingConvKind(bool ClangABICompat4) const override {
  658. return CCK_MicrosoftWin64;
  659. }
  660. };
  661. // x86-64 MinGW target
  662. class LLVM_LIBRARY_VISIBILITY MinGWX86_64TargetInfo
  663. : public WindowsX86_64TargetInfo {
  664. public:
  665. MinGWX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  666. : WindowsX86_64TargetInfo(Triple, Opts) {
  667. // Mingw64 rounds long double size and alignment up to 16 bytes, but sticks
  668. // with x86 FP ops. Weird.
  669. LongDoubleWidth = LongDoubleAlign = 128;
  670. LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
  671. HasFloat128 = true;
  672. }
  673. };
  674. // x86-64 Cygwin target
  675. class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
  676. public:
  677. CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  678. : X86_64TargetInfo(Triple, Opts) {
  679. this->WCharType = TargetInfo::UnsignedShort;
  680. TLSSupported = false;
  681. }
  682. void getTargetDefines(const LangOptions &Opts,
  683. MacroBuilder &Builder) const override {
  684. X86_64TargetInfo::getTargetDefines(Opts, Builder);
  685. Builder.defineMacro("__x86_64__");
  686. Builder.defineMacro("__CYGWIN__");
  687. Builder.defineMacro("__CYGWIN64__");
  688. addCygMingDefines(Opts, Builder);
  689. DefineStd(Builder, "unix", Opts);
  690. if (Opts.CPlusPlus)
  691. Builder.defineMacro("_GNU_SOURCE");
  692. }
  693. };
  694. class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
  695. : public DarwinTargetInfo<X86_64TargetInfo> {
  696. public:
  697. DarwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  698. : DarwinTargetInfo<X86_64TargetInfo>(Triple, Opts) {
  699. Int64Type = SignedLongLong;
  700. // The 64-bit iOS simulator uses the builtin bool type for Objective-C.
  701. llvm::Triple T = llvm::Triple(Triple);
  702. if (T.isiOS())
  703. UseSignedCharForObjCBool = false;
  704. resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:"
  705. "16:32:64-S128");
  706. }
  707. bool handleTargetFeatures(std::vector<std::string> &Features,
  708. DiagnosticsEngine &Diags) override {
  709. if (!DarwinTargetInfo<X86_64TargetInfo>::handleTargetFeatures(Features,
  710. Diags))
  711. return false;
  712. // We now know the features we have: we can decide how to align vectors.
  713. MaxVectorAlign =
  714. hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
  715. return true;
  716. }
  717. };
  718. class LLVM_LIBRARY_VISIBILITY OpenBSDX86_64TargetInfo
  719. : public OpenBSDTargetInfo<X86_64TargetInfo> {
  720. public:
  721. OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  722. : OpenBSDTargetInfo<X86_64TargetInfo>(Triple, Opts) {
  723. IntMaxType = SignedLongLong;
  724. Int64Type = SignedLongLong;
  725. }
  726. };
  727. // x86_32 Android target
  728. class LLVM_LIBRARY_VISIBILITY AndroidX86_32TargetInfo
  729. : public LinuxTargetInfo<X86_32TargetInfo> {
  730. public:
  731. AndroidX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  732. : LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts) {
  733. SuitableAlign = 32;
  734. LongDoubleWidth = 64;
  735. LongDoubleFormat = &llvm::APFloat::IEEEdouble();
  736. }
  737. };
  738. // x86_64 Android target
  739. class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo
  740. : public LinuxTargetInfo<X86_64TargetInfo> {
  741. public:
  742. AndroidX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  743. : LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts) {
  744. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  745. }
  746. };
  747. } // namespace targets
  748. } // namespace clang
  749. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_X86_H