X86.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. //===--- X86.cpp - Implement X86 target feature support -------------------===//
  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 implements X86 TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "X86.h"
  13. #include "clang/Basic/Builtins.h"
  14. #include "clang/Basic/Diagnostic.h"
  15. #include "clang/Basic/TargetBuiltins.h"
  16. #include "llvm/ADT/StringExtras.h"
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/ADT/StringSwitch.h"
  19. #include "llvm/Support/X86TargetParser.h"
  20. #include <optional>
  21. namespace clang {
  22. namespace targets {
  23. static constexpr Builtin::Info BuiltinInfoX86[] = {
  24. #define BUILTIN(ID, TYPE, ATTRS) \
  25. {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
  26. #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
  27. {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
  28. #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
  29. {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
  30. #include "clang/Basic/BuiltinsX86.def"
  31. #define BUILTIN(ID, TYPE, ATTRS) \
  32. {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
  33. #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
  34. {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
  35. #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
  36. {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
  37. #include "clang/Basic/BuiltinsX86_64.def"
  38. };
  39. static const char *const GCCRegNames[] = {
  40. "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
  41. "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
  42. "argp", "flags", "fpcr", "fpsr", "dirflag", "frame", "xmm0", "xmm1",
  43. "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", "mm0", "mm1",
  44. "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", "r8", "r9",
  45. "r10", "r11", "r12", "r13", "r14", "r15", "xmm8", "xmm9",
  46. "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", "ymm0", "ymm1",
  47. "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7", "ymm8", "ymm9",
  48. "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15", "xmm16", "xmm17",
  49. "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "xmm24", "xmm25",
  50. "xmm26", "xmm27", "xmm28", "xmm29", "xmm30", "xmm31", "ymm16", "ymm17",
  51. "ymm18", "ymm19", "ymm20", "ymm21", "ymm22", "ymm23", "ymm24", "ymm25",
  52. "ymm26", "ymm27", "ymm28", "ymm29", "ymm30", "ymm31", "zmm0", "zmm1",
  53. "zmm2", "zmm3", "zmm4", "zmm5", "zmm6", "zmm7", "zmm8", "zmm9",
  54. "zmm10", "zmm11", "zmm12", "zmm13", "zmm14", "zmm15", "zmm16", "zmm17",
  55. "zmm18", "zmm19", "zmm20", "zmm21", "zmm22", "zmm23", "zmm24", "zmm25",
  56. "zmm26", "zmm27", "zmm28", "zmm29", "zmm30", "zmm31", "k0", "k1",
  57. "k2", "k3", "k4", "k5", "k6", "k7",
  58. "cr0", "cr2", "cr3", "cr4", "cr8",
  59. "dr0", "dr1", "dr2", "dr3", "dr6", "dr7",
  60. "bnd0", "bnd1", "bnd2", "bnd3",
  61. "tmm0", "tmm1", "tmm2", "tmm3", "tmm4", "tmm5", "tmm6", "tmm7",
  62. };
  63. const TargetInfo::AddlRegName AddlRegNames[] = {
  64. {{"al", "ah", "eax", "rax"}, 0},
  65. {{"bl", "bh", "ebx", "rbx"}, 3},
  66. {{"cl", "ch", "ecx", "rcx"}, 2},
  67. {{"dl", "dh", "edx", "rdx"}, 1},
  68. {{"esi", "rsi"}, 4},
  69. {{"edi", "rdi"}, 5},
  70. {{"esp", "rsp"}, 7},
  71. {{"ebp", "rbp"}, 6},
  72. {{"r8d", "r8w", "r8b"}, 38},
  73. {{"r9d", "r9w", "r9b"}, 39},
  74. {{"r10d", "r10w", "r10b"}, 40},
  75. {{"r11d", "r11w", "r11b"}, 41},
  76. {{"r12d", "r12w", "r12b"}, 42},
  77. {{"r13d", "r13w", "r13b"}, 43},
  78. {{"r14d", "r14w", "r14b"}, 44},
  79. {{"r15d", "r15w", "r15b"}, 45},
  80. };
  81. } // namespace targets
  82. } // namespace clang
  83. using namespace clang;
  84. using namespace clang::targets;
  85. bool X86TargetInfo::setFPMath(StringRef Name) {
  86. if (Name == "387") {
  87. FPMath = FP_387;
  88. return true;
  89. }
  90. if (Name == "sse") {
  91. FPMath = FP_SSE;
  92. return true;
  93. }
  94. return false;
  95. }
  96. bool X86TargetInfo::initFeatureMap(
  97. llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
  98. const std::vector<std::string> &FeaturesVec) const {
  99. // FIXME: This *really* should not be here.
  100. // X86_64 always has SSE2.
  101. if (getTriple().getArch() == llvm::Triple::x86_64)
  102. setFeatureEnabled(Features, "sse2", true);
  103. using namespace llvm::X86;
  104. SmallVector<StringRef, 16> CPUFeatures;
  105. getFeaturesForCPU(CPU, CPUFeatures);
  106. for (auto &F : CPUFeatures)
  107. setFeatureEnabled(Features, F, true);
  108. std::vector<std::string> UpdatedFeaturesVec;
  109. for (const auto &Feature : FeaturesVec) {
  110. // Expand general-regs-only to -x86, -mmx and -sse
  111. if (Feature == "+general-regs-only") {
  112. UpdatedFeaturesVec.push_back("-x87");
  113. UpdatedFeaturesVec.push_back("-mmx");
  114. UpdatedFeaturesVec.push_back("-sse");
  115. continue;
  116. }
  117. UpdatedFeaturesVec.push_back(Feature);
  118. }
  119. if (!TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec))
  120. return false;
  121. // Can't do this earlier because we need to be able to explicitly enable
  122. // or disable these features and the things that they depend upon.
  123. // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
  124. auto I = Features.find("sse4.2");
  125. if (I != Features.end() && I->getValue() &&
  126. !llvm::is_contained(UpdatedFeaturesVec, "-popcnt"))
  127. Features["popcnt"] = true;
  128. // Additionally, if SSE is enabled and mmx is not explicitly disabled,
  129. // then enable MMX.
  130. I = Features.find("sse");
  131. if (I != Features.end() && I->getValue() &&
  132. !llvm::is_contained(UpdatedFeaturesVec, "-mmx"))
  133. Features["mmx"] = true;
  134. // Enable xsave if avx is enabled and xsave is not explicitly disabled.
  135. I = Features.find("avx");
  136. if (I != Features.end() && I->getValue() &&
  137. !llvm::is_contained(UpdatedFeaturesVec, "-xsave"))
  138. Features["xsave"] = true;
  139. // Enable CRC32 if SSE4.2 is enabled and CRC32 is not explicitly disabled.
  140. I = Features.find("sse4.2");
  141. if (I != Features.end() && I->getValue() &&
  142. !llvm::is_contained(UpdatedFeaturesVec, "-crc32"))
  143. Features["crc32"] = true;
  144. return true;
  145. }
  146. void X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
  147. StringRef Name, bool Enabled) const {
  148. if (Name == "sse4") {
  149. // We can get here via the __target__ attribute since that's not controlled
  150. // via the -msse4/-mno-sse4 command line alias. Handle this the same way
  151. // here - turn on the sse4.2 if enabled, turn off the sse4.1 level if
  152. // disabled.
  153. if (Enabled)
  154. Name = "sse4.2";
  155. else
  156. Name = "sse4.1";
  157. }
  158. Features[Name] = Enabled;
  159. llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
  160. }
  161. /// handleTargetFeatures - Perform initialization based on the user
  162. /// configured set of features.
  163. bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
  164. DiagnosticsEngine &Diags) {
  165. for (const auto &Feature : Features) {
  166. if (Feature[0] != '+')
  167. continue;
  168. if (Feature == "+aes") {
  169. HasAES = true;
  170. } else if (Feature == "+vaes") {
  171. HasVAES = true;
  172. } else if (Feature == "+pclmul") {
  173. HasPCLMUL = true;
  174. } else if (Feature == "+vpclmulqdq") {
  175. HasVPCLMULQDQ = true;
  176. } else if (Feature == "+lzcnt") {
  177. HasLZCNT = true;
  178. } else if (Feature == "+rdrnd") {
  179. HasRDRND = true;
  180. } else if (Feature == "+fsgsbase") {
  181. HasFSGSBASE = true;
  182. } else if (Feature == "+bmi") {
  183. HasBMI = true;
  184. } else if (Feature == "+bmi2") {
  185. HasBMI2 = true;
  186. } else if (Feature == "+popcnt") {
  187. HasPOPCNT = true;
  188. } else if (Feature == "+rtm") {
  189. HasRTM = true;
  190. } else if (Feature == "+prfchw") {
  191. HasPRFCHW = true;
  192. } else if (Feature == "+rdseed") {
  193. HasRDSEED = true;
  194. } else if (Feature == "+adx") {
  195. HasADX = true;
  196. } else if (Feature == "+tbm") {
  197. HasTBM = true;
  198. } else if (Feature == "+lwp") {
  199. HasLWP = true;
  200. } else if (Feature == "+fma") {
  201. HasFMA = true;
  202. } else if (Feature == "+f16c") {
  203. HasF16C = true;
  204. } else if (Feature == "+gfni") {
  205. HasGFNI = true;
  206. } else if (Feature == "+avx512cd") {
  207. HasAVX512CD = true;
  208. } else if (Feature == "+avx512vpopcntdq") {
  209. HasAVX512VPOPCNTDQ = true;
  210. } else if (Feature == "+avx512vnni") {
  211. HasAVX512VNNI = true;
  212. } else if (Feature == "+avx512bf16") {
  213. HasAVX512BF16 = true;
  214. } else if (Feature == "+avx512er") {
  215. HasAVX512ER = true;
  216. } else if (Feature == "+avx512fp16") {
  217. HasAVX512FP16 = true;
  218. HasLegalHalfType = true;
  219. } else if (Feature == "+avx512pf") {
  220. HasAVX512PF = true;
  221. } else if (Feature == "+avx512dq") {
  222. HasAVX512DQ = true;
  223. } else if (Feature == "+avx512bitalg") {
  224. HasAVX512BITALG = true;
  225. } else if (Feature == "+avx512bw") {
  226. HasAVX512BW = true;
  227. } else if (Feature == "+avx512vl") {
  228. HasAVX512VL = true;
  229. } else if (Feature == "+avx512vbmi") {
  230. HasAVX512VBMI = true;
  231. } else if (Feature == "+avx512vbmi2") {
  232. HasAVX512VBMI2 = true;
  233. } else if (Feature == "+avx512ifma") {
  234. HasAVX512IFMA = true;
  235. } else if (Feature == "+avx512vp2intersect") {
  236. HasAVX512VP2INTERSECT = true;
  237. } else if (Feature == "+sha") {
  238. HasSHA = true;
  239. } else if (Feature == "+shstk") {
  240. HasSHSTK = true;
  241. } else if (Feature == "+movbe") {
  242. HasMOVBE = true;
  243. } else if (Feature == "+sgx") {
  244. HasSGX = true;
  245. } else if (Feature == "+cx8") {
  246. HasCX8 = true;
  247. } else if (Feature == "+cx16") {
  248. HasCX16 = true;
  249. } else if (Feature == "+fxsr") {
  250. HasFXSR = true;
  251. } else if (Feature == "+xsave") {
  252. HasXSAVE = true;
  253. } else if (Feature == "+xsaveopt") {
  254. HasXSAVEOPT = true;
  255. } else if (Feature == "+xsavec") {
  256. HasXSAVEC = true;
  257. } else if (Feature == "+xsaves") {
  258. HasXSAVES = true;
  259. } else if (Feature == "+mwaitx") {
  260. HasMWAITX = true;
  261. } else if (Feature == "+pku") {
  262. HasPKU = true;
  263. } else if (Feature == "+clflushopt") {
  264. HasCLFLUSHOPT = true;
  265. } else if (Feature == "+clwb") {
  266. HasCLWB = true;
  267. } else if (Feature == "+wbnoinvd") {
  268. HasWBNOINVD = true;
  269. } else if (Feature == "+prefetchi") {
  270. HasPREFETCHI = true;
  271. } else if (Feature == "+prefetchwt1") {
  272. HasPREFETCHWT1 = true;
  273. } else if (Feature == "+clzero") {
  274. HasCLZERO = true;
  275. } else if (Feature == "+cldemote") {
  276. HasCLDEMOTE = true;
  277. } else if (Feature == "+rdpid") {
  278. HasRDPID = true;
  279. } else if (Feature == "+rdpru") {
  280. HasRDPRU = true;
  281. } else if (Feature == "+kl") {
  282. HasKL = true;
  283. } else if (Feature == "+widekl") {
  284. HasWIDEKL = true;
  285. } else if (Feature == "+retpoline-external-thunk") {
  286. HasRetpolineExternalThunk = true;
  287. } else if (Feature == "+sahf") {
  288. HasLAHFSAHF = true;
  289. } else if (Feature == "+waitpkg") {
  290. HasWAITPKG = true;
  291. } else if (Feature == "+movdiri") {
  292. HasMOVDIRI = true;
  293. } else if (Feature == "+movdir64b") {
  294. HasMOVDIR64B = true;
  295. } else if (Feature == "+pconfig") {
  296. HasPCONFIG = true;
  297. } else if (Feature == "+ptwrite") {
  298. HasPTWRITE = true;
  299. } else if (Feature == "+invpcid") {
  300. HasINVPCID = true;
  301. } else if (Feature == "+enqcmd") {
  302. HasENQCMD = true;
  303. } else if (Feature == "+hreset") {
  304. HasHRESET = true;
  305. } else if (Feature == "+amx-bf16") {
  306. HasAMXBF16 = true;
  307. } else if (Feature == "+amx-fp16") {
  308. HasAMXFP16 = true;
  309. } else if (Feature == "+amx-int8") {
  310. HasAMXINT8 = true;
  311. } else if (Feature == "+amx-tile") {
  312. HasAMXTILE = true;
  313. } else if (Feature == "+cmpccxadd") {
  314. HasCMPCCXADD = true;
  315. } else if (Feature == "+raoint") {
  316. HasRAOINT = true;
  317. } else if (Feature == "+avxifma") {
  318. HasAVXIFMA = true;
  319. } else if (Feature == "+avxneconvert") {
  320. HasAVXNECONVERT= true;
  321. } else if (Feature == "+avxvnni") {
  322. HasAVXVNNI = true;
  323. } else if (Feature == "+avxvnniint8") {
  324. HasAVXVNNIINT8 = true;
  325. } else if (Feature == "+serialize") {
  326. HasSERIALIZE = true;
  327. } else if (Feature == "+tsxldtrk") {
  328. HasTSXLDTRK = true;
  329. } else if (Feature == "+uintr") {
  330. HasUINTR = true;
  331. } else if (Feature == "+crc32") {
  332. HasCRC32 = true;
  333. } else if (Feature == "+x87") {
  334. HasX87 = true;
  335. }
  336. X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
  337. .Case("+avx512f", AVX512F)
  338. .Case("+avx2", AVX2)
  339. .Case("+avx", AVX)
  340. .Case("+sse4.2", SSE42)
  341. .Case("+sse4.1", SSE41)
  342. .Case("+ssse3", SSSE3)
  343. .Case("+sse3", SSE3)
  344. .Case("+sse2", SSE2)
  345. .Case("+sse", SSE1)
  346. .Default(NoSSE);
  347. SSELevel = std::max(SSELevel, Level);
  348. HasFloat16 = SSELevel >= SSE2;
  349. HasBFloat16 = SSELevel >= SSE2;
  350. MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch<MMX3DNowEnum>(Feature)
  351. .Case("+3dnowa", AMD3DNowAthlon)
  352. .Case("+3dnow", AMD3DNow)
  353. .Case("+mmx", MMX)
  354. .Default(NoMMX3DNow);
  355. MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
  356. XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
  357. .Case("+xop", XOP)
  358. .Case("+fma4", FMA4)
  359. .Case("+sse4a", SSE4A)
  360. .Default(NoXOP);
  361. XOPLevel = std::max(XOPLevel, XLevel);
  362. }
  363. // LLVM doesn't have a separate switch for fpmath, so only accept it if it
  364. // matches the selected sse level.
  365. if ((FPMath == FP_SSE && SSELevel < SSE1) ||
  366. (FPMath == FP_387 && SSELevel >= SSE1)) {
  367. Diags.Report(diag::err_target_unsupported_fpmath)
  368. << (FPMath == FP_SSE ? "sse" : "387");
  369. return false;
  370. }
  371. SimdDefaultAlign =
  372. hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
  373. // FIXME: We should allow long double type on 32-bits to match with GCC.
  374. // This requires backend to be able to lower f80 without x87 first.
  375. if (!HasX87 && LongDoubleFormat == &llvm::APFloat::x87DoubleExtended())
  376. HasLongDouble = false;
  377. return true;
  378. }
  379. /// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
  380. /// definitions for this particular subtarget.
  381. void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
  382. MacroBuilder &Builder) const {
  383. // Inline assembly supports X86 flag outputs.
  384. Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
  385. std::string CodeModel = getTargetOpts().CodeModel;
  386. if (CodeModel == "default")
  387. CodeModel = "small";
  388. Builder.defineMacro("__code_model_" + CodeModel + "__");
  389. // Target identification.
  390. if (getTriple().getArch() == llvm::Triple::x86_64) {
  391. Builder.defineMacro("__amd64__");
  392. Builder.defineMacro("__amd64");
  393. Builder.defineMacro("__x86_64");
  394. Builder.defineMacro("__x86_64__");
  395. if (getTriple().getArchName() == "x86_64h") {
  396. Builder.defineMacro("__x86_64h");
  397. Builder.defineMacro("__x86_64h__");
  398. }
  399. } else {
  400. DefineStd(Builder, "i386", Opts);
  401. }
  402. Builder.defineMacro("__SEG_GS");
  403. Builder.defineMacro("__SEG_FS");
  404. Builder.defineMacro("__seg_gs", "__attribute__((address_space(256)))");
  405. Builder.defineMacro("__seg_fs", "__attribute__((address_space(257)))");
  406. // Subtarget options.
  407. // FIXME: We are hard-coding the tune parameters based on the CPU, but they
  408. // truly should be based on -mtune options.
  409. using namespace llvm::X86;
  410. switch (CPU) {
  411. case CK_None:
  412. break;
  413. case CK_i386:
  414. // The rest are coming from the i386 define above.
  415. Builder.defineMacro("__tune_i386__");
  416. break;
  417. case CK_i486:
  418. case CK_WinChipC6:
  419. case CK_WinChip2:
  420. case CK_C3:
  421. defineCPUMacros(Builder, "i486");
  422. break;
  423. case CK_PentiumMMX:
  424. Builder.defineMacro("__pentium_mmx__");
  425. Builder.defineMacro("__tune_pentium_mmx__");
  426. [[fallthrough]];
  427. case CK_i586:
  428. case CK_Pentium:
  429. defineCPUMacros(Builder, "i586");
  430. defineCPUMacros(Builder, "pentium");
  431. break;
  432. case CK_Pentium3:
  433. case CK_PentiumM:
  434. Builder.defineMacro("__tune_pentium3__");
  435. [[fallthrough]];
  436. case CK_Pentium2:
  437. case CK_C3_2:
  438. Builder.defineMacro("__tune_pentium2__");
  439. [[fallthrough]];
  440. case CK_PentiumPro:
  441. case CK_i686:
  442. defineCPUMacros(Builder, "i686");
  443. defineCPUMacros(Builder, "pentiumpro");
  444. break;
  445. case CK_Pentium4:
  446. defineCPUMacros(Builder, "pentium4");
  447. break;
  448. case CK_Yonah:
  449. case CK_Prescott:
  450. case CK_Nocona:
  451. defineCPUMacros(Builder, "nocona");
  452. break;
  453. case CK_Core2:
  454. case CK_Penryn:
  455. defineCPUMacros(Builder, "core2");
  456. break;
  457. case CK_Bonnell:
  458. defineCPUMacros(Builder, "atom");
  459. break;
  460. case CK_Silvermont:
  461. defineCPUMacros(Builder, "slm");
  462. break;
  463. case CK_Goldmont:
  464. defineCPUMacros(Builder, "goldmont");
  465. break;
  466. case CK_GoldmontPlus:
  467. defineCPUMacros(Builder, "goldmont_plus");
  468. break;
  469. case CK_Tremont:
  470. defineCPUMacros(Builder, "tremont");
  471. break;
  472. case CK_Nehalem:
  473. case CK_Westmere:
  474. case CK_SandyBridge:
  475. case CK_IvyBridge:
  476. case CK_Haswell:
  477. case CK_Broadwell:
  478. case CK_SkylakeClient:
  479. case CK_SkylakeServer:
  480. case CK_Cascadelake:
  481. case CK_Cooperlake:
  482. case CK_Cannonlake:
  483. case CK_IcelakeClient:
  484. case CK_Rocketlake:
  485. case CK_IcelakeServer:
  486. case CK_Tigerlake:
  487. case CK_SapphireRapids:
  488. case CK_Alderlake:
  489. case CK_Raptorlake:
  490. case CK_Meteorlake:
  491. case CK_Sierraforest:
  492. case CK_Grandridge:
  493. case CK_Graniterapids:
  494. case CK_Emeraldrapids:
  495. // FIXME: Historically, we defined this legacy name, it would be nice to
  496. // remove it at some point. We've never exposed fine-grained names for
  497. // recent primary x86 CPUs, and we should keep it that way.
  498. defineCPUMacros(Builder, "corei7");
  499. break;
  500. case CK_KNL:
  501. defineCPUMacros(Builder, "knl");
  502. break;
  503. case CK_KNM:
  504. break;
  505. case CK_Lakemont:
  506. defineCPUMacros(Builder, "i586", /*Tuning*/false);
  507. defineCPUMacros(Builder, "pentium", /*Tuning*/false);
  508. Builder.defineMacro("__tune_lakemont__");
  509. break;
  510. case CK_K6_2:
  511. Builder.defineMacro("__k6_2__");
  512. Builder.defineMacro("__tune_k6_2__");
  513. [[fallthrough]];
  514. case CK_K6_3:
  515. if (CPU != CK_K6_2) { // In case of fallthrough
  516. // FIXME: GCC may be enabling these in cases where some other k6
  517. // architecture is specified but -m3dnow is explicitly provided. The
  518. // exact semantics need to be determined and emulated here.
  519. Builder.defineMacro("__k6_3__");
  520. Builder.defineMacro("__tune_k6_3__");
  521. }
  522. [[fallthrough]];
  523. case CK_K6:
  524. defineCPUMacros(Builder, "k6");
  525. break;
  526. case CK_Athlon:
  527. case CK_AthlonXP:
  528. defineCPUMacros(Builder, "athlon");
  529. if (SSELevel != NoSSE) {
  530. Builder.defineMacro("__athlon_sse__");
  531. Builder.defineMacro("__tune_athlon_sse__");
  532. }
  533. break;
  534. case CK_K8:
  535. case CK_K8SSE3:
  536. case CK_x86_64:
  537. defineCPUMacros(Builder, "k8");
  538. break;
  539. case CK_x86_64_v2:
  540. case CK_x86_64_v3:
  541. case CK_x86_64_v4:
  542. break;
  543. case CK_AMDFAM10:
  544. defineCPUMacros(Builder, "amdfam10");
  545. break;
  546. case CK_BTVER1:
  547. defineCPUMacros(Builder, "btver1");
  548. break;
  549. case CK_BTVER2:
  550. defineCPUMacros(Builder, "btver2");
  551. break;
  552. case CK_BDVER1:
  553. defineCPUMacros(Builder, "bdver1");
  554. break;
  555. case CK_BDVER2:
  556. defineCPUMacros(Builder, "bdver2");
  557. break;
  558. case CK_BDVER3:
  559. defineCPUMacros(Builder, "bdver3");
  560. break;
  561. case CK_BDVER4:
  562. defineCPUMacros(Builder, "bdver4");
  563. break;
  564. case CK_ZNVER1:
  565. defineCPUMacros(Builder, "znver1");
  566. break;
  567. case CK_ZNVER2:
  568. defineCPUMacros(Builder, "znver2");
  569. break;
  570. case CK_ZNVER3:
  571. defineCPUMacros(Builder, "znver3");
  572. break;
  573. case CK_ZNVER4:
  574. defineCPUMacros(Builder, "znver4");
  575. break;
  576. case CK_Geode:
  577. defineCPUMacros(Builder, "geode");
  578. break;
  579. }
  580. // Target properties.
  581. Builder.defineMacro("__REGISTER_PREFIX__", "");
  582. // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
  583. // functions in glibc header files that use FP Stack inline asm which the
  584. // backend can't deal with (PR879).
  585. Builder.defineMacro("__NO_MATH_INLINES");
  586. if (HasAES)
  587. Builder.defineMacro("__AES__");
  588. if (HasVAES)
  589. Builder.defineMacro("__VAES__");
  590. if (HasPCLMUL)
  591. Builder.defineMacro("__PCLMUL__");
  592. if (HasVPCLMULQDQ)
  593. Builder.defineMacro("__VPCLMULQDQ__");
  594. // Note, in 32-bit mode, GCC does not define the macro if -mno-sahf. In LLVM,
  595. // the feature flag only applies to 64-bit mode.
  596. if (HasLAHFSAHF || getTriple().getArch() == llvm::Triple::x86)
  597. Builder.defineMacro("__LAHF_SAHF__");
  598. if (HasLZCNT)
  599. Builder.defineMacro("__LZCNT__");
  600. if (HasRDRND)
  601. Builder.defineMacro("__RDRND__");
  602. if (HasFSGSBASE)
  603. Builder.defineMacro("__FSGSBASE__");
  604. if (HasBMI)
  605. Builder.defineMacro("__BMI__");
  606. if (HasBMI2)
  607. Builder.defineMacro("__BMI2__");
  608. if (HasPOPCNT)
  609. Builder.defineMacro("__POPCNT__");
  610. if (HasRTM)
  611. Builder.defineMacro("__RTM__");
  612. if (HasPRFCHW)
  613. Builder.defineMacro("__PRFCHW__");
  614. if (HasRDSEED)
  615. Builder.defineMacro("__RDSEED__");
  616. if (HasADX)
  617. Builder.defineMacro("__ADX__");
  618. if (HasTBM)
  619. Builder.defineMacro("__TBM__");
  620. if (HasLWP)
  621. Builder.defineMacro("__LWP__");
  622. if (HasMWAITX)
  623. Builder.defineMacro("__MWAITX__");
  624. if (HasMOVBE)
  625. Builder.defineMacro("__MOVBE__");
  626. switch (XOPLevel) {
  627. case XOP:
  628. Builder.defineMacro("__XOP__");
  629. [[fallthrough]];
  630. case FMA4:
  631. Builder.defineMacro("__FMA4__");
  632. [[fallthrough]];
  633. case SSE4A:
  634. Builder.defineMacro("__SSE4A__");
  635. [[fallthrough]];
  636. case NoXOP:
  637. break;
  638. }
  639. if (HasFMA)
  640. Builder.defineMacro("__FMA__");
  641. if (HasF16C)
  642. Builder.defineMacro("__F16C__");
  643. if (HasGFNI)
  644. Builder.defineMacro("__GFNI__");
  645. if (HasAVX512CD)
  646. Builder.defineMacro("__AVX512CD__");
  647. if (HasAVX512VPOPCNTDQ)
  648. Builder.defineMacro("__AVX512VPOPCNTDQ__");
  649. if (HasAVX512VNNI)
  650. Builder.defineMacro("__AVX512VNNI__");
  651. if (HasAVX512BF16)
  652. Builder.defineMacro("__AVX512BF16__");
  653. if (HasAVX512ER)
  654. Builder.defineMacro("__AVX512ER__");
  655. if (HasAVX512FP16)
  656. Builder.defineMacro("__AVX512FP16__");
  657. if (HasAVX512PF)
  658. Builder.defineMacro("__AVX512PF__");
  659. if (HasAVX512DQ)
  660. Builder.defineMacro("__AVX512DQ__");
  661. if (HasAVX512BITALG)
  662. Builder.defineMacro("__AVX512BITALG__");
  663. if (HasAVX512BW)
  664. Builder.defineMacro("__AVX512BW__");
  665. if (HasAVX512VL)
  666. Builder.defineMacro("__AVX512VL__");
  667. if (HasAVX512VBMI)
  668. Builder.defineMacro("__AVX512VBMI__");
  669. if (HasAVX512VBMI2)
  670. Builder.defineMacro("__AVX512VBMI2__");
  671. if (HasAVX512IFMA)
  672. Builder.defineMacro("__AVX512IFMA__");
  673. if (HasAVX512VP2INTERSECT)
  674. Builder.defineMacro("__AVX512VP2INTERSECT__");
  675. if (HasSHA)
  676. Builder.defineMacro("__SHA__");
  677. if (HasFXSR)
  678. Builder.defineMacro("__FXSR__");
  679. if (HasXSAVE)
  680. Builder.defineMacro("__XSAVE__");
  681. if (HasXSAVEOPT)
  682. Builder.defineMacro("__XSAVEOPT__");
  683. if (HasXSAVEC)
  684. Builder.defineMacro("__XSAVEC__");
  685. if (HasXSAVES)
  686. Builder.defineMacro("__XSAVES__");
  687. if (HasPKU)
  688. Builder.defineMacro("__PKU__");
  689. if (HasCLFLUSHOPT)
  690. Builder.defineMacro("__CLFLUSHOPT__");
  691. if (HasCLWB)
  692. Builder.defineMacro("__CLWB__");
  693. if (HasWBNOINVD)
  694. Builder.defineMacro("__WBNOINVD__");
  695. if (HasSHSTK)
  696. Builder.defineMacro("__SHSTK__");
  697. if (HasSGX)
  698. Builder.defineMacro("__SGX__");
  699. if (HasPREFETCHI)
  700. Builder.defineMacro("__PREFETCHI__");
  701. if (HasPREFETCHWT1)
  702. Builder.defineMacro("__PREFETCHWT1__");
  703. if (HasCLZERO)
  704. Builder.defineMacro("__CLZERO__");
  705. if (HasKL)
  706. Builder.defineMacro("__KL__");
  707. if (HasWIDEKL)
  708. Builder.defineMacro("__WIDEKL__");
  709. if (HasRDPID)
  710. Builder.defineMacro("__RDPID__");
  711. if (HasRDPRU)
  712. Builder.defineMacro("__RDPRU__");
  713. if (HasCLDEMOTE)
  714. Builder.defineMacro("__CLDEMOTE__");
  715. if (HasWAITPKG)
  716. Builder.defineMacro("__WAITPKG__");
  717. if (HasMOVDIRI)
  718. Builder.defineMacro("__MOVDIRI__");
  719. if (HasMOVDIR64B)
  720. Builder.defineMacro("__MOVDIR64B__");
  721. if (HasPCONFIG)
  722. Builder.defineMacro("__PCONFIG__");
  723. if (HasPTWRITE)
  724. Builder.defineMacro("__PTWRITE__");
  725. if (HasINVPCID)
  726. Builder.defineMacro("__INVPCID__");
  727. if (HasENQCMD)
  728. Builder.defineMacro("__ENQCMD__");
  729. if (HasHRESET)
  730. Builder.defineMacro("__HRESET__");
  731. if (HasAMXTILE)
  732. Builder.defineMacro("__AMX_TILE__");
  733. if (HasAMXINT8)
  734. Builder.defineMacro("__AMX_INT8__");
  735. if (HasAMXBF16)
  736. Builder.defineMacro("__AMX_BF16__");
  737. if (HasAMXFP16)
  738. Builder.defineMacro("__AMX_FP16__");
  739. if (HasCMPCCXADD)
  740. Builder.defineMacro("__CMPCCXADD__");
  741. if (HasRAOINT)
  742. Builder.defineMacro("__RAOINT__");
  743. if (HasAVXIFMA)
  744. Builder.defineMacro("__AVXIFMA__");
  745. if (HasAVXNECONVERT)
  746. Builder.defineMacro("__AVXNECONVERT__");
  747. if (HasAVXVNNI)
  748. Builder.defineMacro("__AVXVNNI__");
  749. if (HasAVXVNNIINT8)
  750. Builder.defineMacro("__AVXVNNIINT8__");
  751. if (HasSERIALIZE)
  752. Builder.defineMacro("__SERIALIZE__");
  753. if (HasTSXLDTRK)
  754. Builder.defineMacro("__TSXLDTRK__");
  755. if (HasUINTR)
  756. Builder.defineMacro("__UINTR__");
  757. if (HasCRC32)
  758. Builder.defineMacro("__CRC32__");
  759. // Each case falls through to the previous one here.
  760. switch (SSELevel) {
  761. case AVX512F:
  762. Builder.defineMacro("__AVX512F__");
  763. [[fallthrough]];
  764. case AVX2:
  765. Builder.defineMacro("__AVX2__");
  766. [[fallthrough]];
  767. case AVX:
  768. Builder.defineMacro("__AVX__");
  769. [[fallthrough]];
  770. case SSE42:
  771. Builder.defineMacro("__SSE4_2__");
  772. [[fallthrough]];
  773. case SSE41:
  774. Builder.defineMacro("__SSE4_1__");
  775. [[fallthrough]];
  776. case SSSE3:
  777. Builder.defineMacro("__SSSE3__");
  778. [[fallthrough]];
  779. case SSE3:
  780. Builder.defineMacro("__SSE3__");
  781. [[fallthrough]];
  782. case SSE2:
  783. Builder.defineMacro("__SSE2__");
  784. Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
  785. [[fallthrough]];
  786. case SSE1:
  787. Builder.defineMacro("__SSE__");
  788. Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
  789. [[fallthrough]];
  790. case NoSSE:
  791. break;
  792. }
  793. if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
  794. switch (SSELevel) {
  795. case AVX512F:
  796. case AVX2:
  797. case AVX:
  798. case SSE42:
  799. case SSE41:
  800. case SSSE3:
  801. case SSE3:
  802. case SSE2:
  803. Builder.defineMacro("_M_IX86_FP", Twine(2));
  804. break;
  805. case SSE1:
  806. Builder.defineMacro("_M_IX86_FP", Twine(1));
  807. break;
  808. default:
  809. Builder.defineMacro("_M_IX86_FP", Twine(0));
  810. break;
  811. }
  812. }
  813. // Each case falls through to the previous one here.
  814. switch (MMX3DNowLevel) {
  815. case AMD3DNowAthlon:
  816. Builder.defineMacro("__3dNOW_A__");
  817. [[fallthrough]];
  818. case AMD3DNow:
  819. Builder.defineMacro("__3dNOW__");
  820. [[fallthrough]];
  821. case MMX:
  822. Builder.defineMacro("__MMX__");
  823. [[fallthrough]];
  824. case NoMMX3DNow:
  825. break;
  826. }
  827. if (CPU >= CK_i486 || CPU == CK_None) {
  828. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  829. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  830. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  831. }
  832. if (HasCX8)
  833. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  834. if (HasCX16 && getTriple().getArch() == llvm::Triple::x86_64)
  835. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
  836. if (HasFloat128)
  837. Builder.defineMacro("__SIZEOF_FLOAT128__", "16");
  838. }
  839. bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
  840. return llvm::StringSwitch<bool>(Name)
  841. .Case("3dnow", true)
  842. .Case("3dnowa", true)
  843. .Case("adx", true)
  844. .Case("aes", true)
  845. .Case("amx-bf16", true)
  846. .Case("amx-fp16", true)
  847. .Case("amx-int8", true)
  848. .Case("amx-tile", true)
  849. .Case("avx", true)
  850. .Case("avx2", true)
  851. .Case("avx512f", true)
  852. .Case("avx512cd", true)
  853. .Case("avx512vpopcntdq", true)
  854. .Case("avx512vnni", true)
  855. .Case("avx512bf16", true)
  856. .Case("avx512er", true)
  857. .Case("avx512fp16", true)
  858. .Case("avx512pf", true)
  859. .Case("avx512dq", true)
  860. .Case("avx512bitalg", true)
  861. .Case("avx512bw", true)
  862. .Case("avx512vl", true)
  863. .Case("avx512vbmi", true)
  864. .Case("avx512vbmi2", true)
  865. .Case("avx512ifma", true)
  866. .Case("avx512vp2intersect", true)
  867. .Case("avxifma", true)
  868. .Case("avxneconvert", true)
  869. .Case("avxvnni", true)
  870. .Case("avxvnniint8", true)
  871. .Case("bmi", true)
  872. .Case("bmi2", true)
  873. .Case("cldemote", true)
  874. .Case("clflushopt", true)
  875. .Case("clwb", true)
  876. .Case("clzero", true)
  877. .Case("cmpccxadd", true)
  878. .Case("crc32", true)
  879. .Case("cx16", true)
  880. .Case("enqcmd", true)
  881. .Case("f16c", true)
  882. .Case("fma", true)
  883. .Case("fma4", true)
  884. .Case("fsgsbase", true)
  885. .Case("fxsr", true)
  886. .Case("general-regs-only", true)
  887. .Case("gfni", true)
  888. .Case("hreset", true)
  889. .Case("invpcid", true)
  890. .Case("kl", true)
  891. .Case("widekl", true)
  892. .Case("lwp", true)
  893. .Case("lzcnt", true)
  894. .Case("mmx", true)
  895. .Case("movbe", true)
  896. .Case("movdiri", true)
  897. .Case("movdir64b", true)
  898. .Case("mwaitx", true)
  899. .Case("pclmul", true)
  900. .Case("pconfig", true)
  901. .Case("pku", true)
  902. .Case("popcnt", true)
  903. .Case("prefetchi", true)
  904. .Case("prefetchwt1", true)
  905. .Case("prfchw", true)
  906. .Case("ptwrite", true)
  907. .Case("raoint", true)
  908. .Case("rdpid", true)
  909. .Case("rdpru", true)
  910. .Case("rdrnd", true)
  911. .Case("rdseed", true)
  912. .Case("rtm", true)
  913. .Case("sahf", true)
  914. .Case("serialize", true)
  915. .Case("sgx", true)
  916. .Case("sha", true)
  917. .Case("shstk", true)
  918. .Case("sse", true)
  919. .Case("sse2", true)
  920. .Case("sse3", true)
  921. .Case("ssse3", true)
  922. .Case("sse4", true)
  923. .Case("sse4.1", true)
  924. .Case("sse4.2", true)
  925. .Case("sse4a", true)
  926. .Case("tbm", true)
  927. .Case("tsxldtrk", true)
  928. .Case("uintr", true)
  929. .Case("vaes", true)
  930. .Case("vpclmulqdq", true)
  931. .Case("wbnoinvd", true)
  932. .Case("waitpkg", true)
  933. .Case("x87", true)
  934. .Case("xop", true)
  935. .Case("xsave", true)
  936. .Case("xsavec", true)
  937. .Case("xsaves", true)
  938. .Case("xsaveopt", true)
  939. .Default(false);
  940. }
  941. bool X86TargetInfo::hasFeature(StringRef Feature) const {
  942. return llvm::StringSwitch<bool>(Feature)
  943. .Case("adx", HasADX)
  944. .Case("aes", HasAES)
  945. .Case("amx-bf16", HasAMXBF16)
  946. .Case("amx-fp16", HasAMXFP16)
  947. .Case("amx-int8", HasAMXINT8)
  948. .Case("amx-tile", HasAMXTILE)
  949. .Case("avx", SSELevel >= AVX)
  950. .Case("avx2", SSELevel >= AVX2)
  951. .Case("avx512f", SSELevel >= AVX512F)
  952. .Case("avx512cd", HasAVX512CD)
  953. .Case("avx512vpopcntdq", HasAVX512VPOPCNTDQ)
  954. .Case("avx512vnni", HasAVX512VNNI)
  955. .Case("avx512bf16", HasAVX512BF16)
  956. .Case("avx512er", HasAVX512ER)
  957. .Case("avx512fp16", HasAVX512FP16)
  958. .Case("avx512pf", HasAVX512PF)
  959. .Case("avx512dq", HasAVX512DQ)
  960. .Case("avx512bitalg", HasAVX512BITALG)
  961. .Case("avx512bw", HasAVX512BW)
  962. .Case("avx512vl", HasAVX512VL)
  963. .Case("avx512vbmi", HasAVX512VBMI)
  964. .Case("avx512vbmi2", HasAVX512VBMI2)
  965. .Case("avx512ifma", HasAVX512IFMA)
  966. .Case("avx512vp2intersect", HasAVX512VP2INTERSECT)
  967. .Case("avxifma", HasAVXIFMA)
  968. .Case("avxneconvert", HasAVXNECONVERT)
  969. .Case("avxvnni", HasAVXVNNI)
  970. .Case("avxvnniint8", HasAVXVNNIINT8)
  971. .Case("bmi", HasBMI)
  972. .Case("bmi2", HasBMI2)
  973. .Case("cldemote", HasCLDEMOTE)
  974. .Case("clflushopt", HasCLFLUSHOPT)
  975. .Case("clwb", HasCLWB)
  976. .Case("clzero", HasCLZERO)
  977. .Case("cmpccxadd", HasCMPCCXADD)
  978. .Case("crc32", HasCRC32)
  979. .Case("cx8", HasCX8)
  980. .Case("cx16", HasCX16)
  981. .Case("enqcmd", HasENQCMD)
  982. .Case("f16c", HasF16C)
  983. .Case("fma", HasFMA)
  984. .Case("fma4", XOPLevel >= FMA4)
  985. .Case("fsgsbase", HasFSGSBASE)
  986. .Case("fxsr", HasFXSR)
  987. .Case("gfni", HasGFNI)
  988. .Case("hreset", HasHRESET)
  989. .Case("invpcid", HasINVPCID)
  990. .Case("kl", HasKL)
  991. .Case("widekl", HasWIDEKL)
  992. .Case("lwp", HasLWP)
  993. .Case("lzcnt", HasLZCNT)
  994. .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
  995. .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
  996. .Case("mmx", MMX3DNowLevel >= MMX)
  997. .Case("movbe", HasMOVBE)
  998. .Case("movdiri", HasMOVDIRI)
  999. .Case("movdir64b", HasMOVDIR64B)
  1000. .Case("mwaitx", HasMWAITX)
  1001. .Case("pclmul", HasPCLMUL)
  1002. .Case("pconfig", HasPCONFIG)
  1003. .Case("pku", HasPKU)
  1004. .Case("popcnt", HasPOPCNT)
  1005. .Case("prefetchi", HasPREFETCHI)
  1006. .Case("prefetchwt1", HasPREFETCHWT1)
  1007. .Case("prfchw", HasPRFCHW)
  1008. .Case("ptwrite", HasPTWRITE)
  1009. .Case("raoint", HasRAOINT)
  1010. .Case("rdpid", HasRDPID)
  1011. .Case("rdpru", HasRDPRU)
  1012. .Case("rdrnd", HasRDRND)
  1013. .Case("rdseed", HasRDSEED)
  1014. .Case("retpoline-external-thunk", HasRetpolineExternalThunk)
  1015. .Case("rtm", HasRTM)
  1016. .Case("sahf", HasLAHFSAHF)
  1017. .Case("serialize", HasSERIALIZE)
  1018. .Case("sgx", HasSGX)
  1019. .Case("sha", HasSHA)
  1020. .Case("shstk", HasSHSTK)
  1021. .Case("sse", SSELevel >= SSE1)
  1022. .Case("sse2", SSELevel >= SSE2)
  1023. .Case("sse3", SSELevel >= SSE3)
  1024. .Case("ssse3", SSELevel >= SSSE3)
  1025. .Case("sse4.1", SSELevel >= SSE41)
  1026. .Case("sse4.2", SSELevel >= SSE42)
  1027. .Case("sse4a", XOPLevel >= SSE4A)
  1028. .Case("tbm", HasTBM)
  1029. .Case("tsxldtrk", HasTSXLDTRK)
  1030. .Case("uintr", HasUINTR)
  1031. .Case("vaes", HasVAES)
  1032. .Case("vpclmulqdq", HasVPCLMULQDQ)
  1033. .Case("wbnoinvd", HasWBNOINVD)
  1034. .Case("waitpkg", HasWAITPKG)
  1035. .Case("x86", true)
  1036. .Case("x86_32", getTriple().getArch() == llvm::Triple::x86)
  1037. .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64)
  1038. .Case("x87", HasX87)
  1039. .Case("xop", XOPLevel >= XOP)
  1040. .Case("xsave", HasXSAVE)
  1041. .Case("xsavec", HasXSAVEC)
  1042. .Case("xsaves", HasXSAVES)
  1043. .Case("xsaveopt", HasXSAVEOPT)
  1044. .Default(false);
  1045. }
  1046. // We can't use a generic validation scheme for the features accepted here
  1047. // versus subtarget features accepted in the target attribute because the
  1048. // bitfield structure that's initialized in the runtime only supports the
  1049. // below currently rather than the full range of subtarget features. (See
  1050. // X86TargetInfo::hasFeature for a somewhat comprehensive list).
  1051. bool X86TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
  1052. return llvm::StringSwitch<bool>(FeatureStr)
  1053. #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
  1054. #include "llvm/TargetParser/X86TargetParser.def"
  1055. .Default(false);
  1056. }
  1057. static llvm::X86::ProcessorFeatures getFeature(StringRef Name) {
  1058. return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
  1059. #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
  1060. .Case(STR, llvm::X86::FEATURE_##ENUM)
  1061. #include "llvm/TargetParser/X86TargetParser.def"
  1062. ;
  1063. // Note, this function should only be used after ensuring the value is
  1064. // correct, so it asserts if the value is out of range.
  1065. }
  1066. unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const {
  1067. // Valid CPUs have a 'key feature' that compares just better than its key
  1068. // feature.
  1069. using namespace llvm::X86;
  1070. CPUKind Kind = parseArchX86(Name);
  1071. if (Kind != CK_None) {
  1072. ProcessorFeatures KeyFeature = getKeyFeature(Kind);
  1073. return (getFeaturePriority(KeyFeature) << 1) + 1;
  1074. }
  1075. // Now we know we have a feature, so get its priority and shift it a few so
  1076. // that we have sufficient room for the CPUs (above).
  1077. return getFeaturePriority(getFeature(Name)) << 1;
  1078. }
  1079. bool X86TargetInfo::validateCPUSpecificCPUDispatch(StringRef Name) const {
  1080. return llvm::StringSwitch<bool>(Name)
  1081. #define CPU_SPECIFIC(NAME, TUNE_NAME, MANGLING, FEATURES) .Case(NAME, true)
  1082. #define CPU_SPECIFIC_ALIAS(NEW_NAME, TUNE_NAME, NAME) .Case(NEW_NAME, true)
  1083. #include "llvm/TargetParser/X86TargetParser.def"
  1084. .Default(false);
  1085. }
  1086. static StringRef CPUSpecificCPUDispatchNameDealias(StringRef Name) {
  1087. return llvm::StringSwitch<StringRef>(Name)
  1088. #define CPU_SPECIFIC_ALIAS(NEW_NAME, TUNE_NAME, NAME) .Case(NEW_NAME, NAME)
  1089. #include "llvm/TargetParser/X86TargetParser.def"
  1090. .Default(Name);
  1091. }
  1092. char X86TargetInfo::CPUSpecificManglingCharacter(StringRef Name) const {
  1093. return llvm::StringSwitch<char>(CPUSpecificCPUDispatchNameDealias(Name))
  1094. #define CPU_SPECIFIC(NAME, TUNE_NAME, MANGLING, FEATURES) .Case(NAME, MANGLING)
  1095. #include "llvm/TargetParser/X86TargetParser.def"
  1096. .Default(0);
  1097. }
  1098. void X86TargetInfo::getCPUSpecificCPUDispatchFeatures(
  1099. StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
  1100. StringRef WholeList =
  1101. llvm::StringSwitch<StringRef>(CPUSpecificCPUDispatchNameDealias(Name))
  1102. #define CPU_SPECIFIC(NAME, TUNE_NAME, MANGLING, FEATURES) .Case(NAME, FEATURES)
  1103. #include "llvm/TargetParser/X86TargetParser.def"
  1104. .Default("");
  1105. WholeList.split(Features, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
  1106. }
  1107. StringRef X86TargetInfo::getCPUSpecificTuneName(StringRef Name) const {
  1108. return llvm::StringSwitch<StringRef>(Name)
  1109. #define CPU_SPECIFIC(NAME, TUNE_NAME, MANGLING, FEATURES) .Case(NAME, TUNE_NAME)
  1110. #define CPU_SPECIFIC_ALIAS(NEW_NAME, TUNE_NAME, NAME) .Case(NEW_NAME, TUNE_NAME)
  1111. #include "llvm/TargetParser/X86TargetParser.def"
  1112. .Default("");
  1113. }
  1114. // We can't use a generic validation scheme for the cpus accepted here
  1115. // versus subtarget cpus accepted in the target attribute because the
  1116. // variables intitialized by the runtime only support the below currently
  1117. // rather than the full range of cpus.
  1118. bool X86TargetInfo::validateCpuIs(StringRef FeatureStr) const {
  1119. return llvm::StringSwitch<bool>(FeatureStr)
  1120. #define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
  1121. #define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
  1122. #define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
  1123. #define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
  1124. #define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
  1125. #include "llvm/TargetParser/X86TargetParser.def"
  1126. .Default(false);
  1127. }
  1128. static unsigned matchAsmCCConstraint(const char *&Name) {
  1129. auto RV = llvm::StringSwitch<unsigned>(Name)
  1130. .Case("@cca", 4)
  1131. .Case("@ccae", 5)
  1132. .Case("@ccb", 4)
  1133. .Case("@ccbe", 5)
  1134. .Case("@ccc", 4)
  1135. .Case("@cce", 4)
  1136. .Case("@ccz", 4)
  1137. .Case("@ccg", 4)
  1138. .Case("@ccge", 5)
  1139. .Case("@ccl", 4)
  1140. .Case("@ccle", 5)
  1141. .Case("@ccna", 5)
  1142. .Case("@ccnae", 6)
  1143. .Case("@ccnb", 5)
  1144. .Case("@ccnbe", 6)
  1145. .Case("@ccnc", 5)
  1146. .Case("@ccne", 5)
  1147. .Case("@ccnz", 5)
  1148. .Case("@ccng", 5)
  1149. .Case("@ccnge", 6)
  1150. .Case("@ccnl", 5)
  1151. .Case("@ccnle", 6)
  1152. .Case("@ccno", 5)
  1153. .Case("@ccnp", 5)
  1154. .Case("@ccns", 5)
  1155. .Case("@cco", 4)
  1156. .Case("@ccp", 4)
  1157. .Case("@ccs", 4)
  1158. .Default(0);
  1159. return RV;
  1160. }
  1161. bool X86TargetInfo::validateAsmConstraint(
  1162. const char *&Name, TargetInfo::ConstraintInfo &Info) const {
  1163. switch (*Name) {
  1164. default:
  1165. return false;
  1166. // Constant constraints.
  1167. case 'e': // 32-bit signed integer constant for use with sign-extending x86_64
  1168. // instructions.
  1169. case 'Z': // 32-bit unsigned integer constant for use with zero-extending
  1170. // x86_64 instructions.
  1171. case 's':
  1172. Info.setRequiresImmediate();
  1173. return true;
  1174. case 'I':
  1175. Info.setRequiresImmediate(0, 31);
  1176. return true;
  1177. case 'J':
  1178. Info.setRequiresImmediate(0, 63);
  1179. return true;
  1180. case 'K':
  1181. Info.setRequiresImmediate(-128, 127);
  1182. return true;
  1183. case 'L':
  1184. Info.setRequiresImmediate({int(0xff), int(0xffff), int(0xffffffff)});
  1185. return true;
  1186. case 'M':
  1187. Info.setRequiresImmediate(0, 3);
  1188. return true;
  1189. case 'N':
  1190. Info.setRequiresImmediate(0, 255);
  1191. return true;
  1192. case 'O':
  1193. Info.setRequiresImmediate(0, 127);
  1194. return true;
  1195. // Register constraints.
  1196. case 'Y': // 'Y' is the first character for several 2-character constraints.
  1197. // Shift the pointer to the second character of the constraint.
  1198. Name++;
  1199. switch (*Name) {
  1200. default:
  1201. return false;
  1202. case 'z': // First SSE register.
  1203. case '2':
  1204. case 't': // Any SSE register, when SSE2 is enabled.
  1205. case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
  1206. case 'm': // Any MMX register, when inter-unit moves enabled.
  1207. case 'k': // AVX512 arch mask registers: k1-k7.
  1208. Info.setAllowsRegister();
  1209. return true;
  1210. }
  1211. case 'f': // Any x87 floating point stack register.
  1212. // Constraint 'f' cannot be used for output operands.
  1213. if (Info.ConstraintStr[0] == '=')
  1214. return false;
  1215. Info.setAllowsRegister();
  1216. return true;
  1217. case 'a': // eax.
  1218. case 'b': // ebx.
  1219. case 'c': // ecx.
  1220. case 'd': // edx.
  1221. case 'S': // esi.
  1222. case 'D': // edi.
  1223. case 'A': // edx:eax.
  1224. case 't': // Top of floating point stack.
  1225. case 'u': // Second from top of floating point stack.
  1226. case 'q': // Any register accessible as [r]l: a, b, c, and d.
  1227. case 'y': // Any MMX register.
  1228. case 'v': // Any {X,Y,Z}MM register (Arch & context dependent)
  1229. case 'x': // Any SSE register.
  1230. case 'k': // Any AVX512 mask register (same as Yk, additionally allows k0
  1231. // for intermideate k reg operations).
  1232. case 'Q': // Any register accessible as [r]h: a, b, c, and d.
  1233. case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
  1234. case 'l': // "Index" registers: any general register that can be used as an
  1235. // index in a base+index memory access.
  1236. Info.setAllowsRegister();
  1237. return true;
  1238. // Floating point constant constraints.
  1239. case 'C': // SSE floating point constant.
  1240. case 'G': // x87 floating point constant.
  1241. return true;
  1242. case '@':
  1243. // CC condition changes.
  1244. if (auto Len = matchAsmCCConstraint(Name)) {
  1245. Name += Len - 1;
  1246. Info.setAllowsRegister();
  1247. return true;
  1248. }
  1249. return false;
  1250. }
  1251. }
  1252. // Below is based on the following information:
  1253. // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1254. // | Processor Name | Cache Line Size (Bytes) | Source |
  1255. // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1256. // | i386 | 64 | https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf |
  1257. // | i486 | 16 | "four doublewords" (doubleword = 32 bits, 4 bits * 32 bits = 16 bytes) https://en.wikichip.org/w/images/d/d3/i486_MICROPROCESSOR_HARDWARE_REFERENCE_MANUAL_%281990%29.pdf and http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.126.4216&rep=rep1&type=pdf (page 29) |
  1258. // | i586/Pentium MMX | 32 | https://www.7-cpu.com/cpu/P-MMX.html |
  1259. // | i686/Pentium | 32 | https://www.7-cpu.com/cpu/P6.html |
  1260. // | Netburst/Pentium4 | 64 | https://www.7-cpu.com/cpu/P4-180.html |
  1261. // | Atom | 64 | https://www.7-cpu.com/cpu/Atom.html |
  1262. // | Westmere | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/sandy_bridge_(client) "Cache Architecture" |
  1263. // | Sandy Bridge | 64 | https://en.wikipedia.org/wiki/Sandy_Bridge and https://www.7-cpu.com/cpu/SandyBridge.html |
  1264. // | Ivy Bridge | 64 | https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and https://www.7-cpu.com/cpu/IvyBridge.html |
  1265. // | Haswell | 64 | https://www.7-cpu.com/cpu/Haswell.html |
  1266. // | Boadwell | 64 | https://www.7-cpu.com/cpu/Broadwell.html |
  1267. // | Skylake (including skylake-avx512) | 64 | https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache Hierarchy" |
  1268. // | Cascade Lake | 64 | https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html "Cache Hierarchy" |
  1269. // | Skylake | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/kaby_lake "Memory Hierarchy" |
  1270. // | Ice Lake | 64 | https://www.7-cpu.com/cpu/Ice_Lake.html |
  1271. // | Knights Landing | 64 | https://software.intel.com/en-us/articles/intel-xeon-phi-processor-7200-family-memory-management-optimizations "The Intel® Xeon Phi™ Processor Architecture" |
  1272. // | Knights Mill | 64 | https://software.intel.com/sites/default/files/managed/9e/bc/64-ia-32-architectures-optimization-manual.pdf?countrylabel=Colombia "2.5.5.2 L1 DCache " |
  1273. // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1274. std::optional<unsigned> X86TargetInfo::getCPUCacheLineSize() const {
  1275. using namespace llvm::X86;
  1276. switch (CPU) {
  1277. // i386
  1278. case CK_i386:
  1279. // i486
  1280. case CK_i486:
  1281. case CK_WinChipC6:
  1282. case CK_WinChip2:
  1283. case CK_C3:
  1284. // Lakemont
  1285. case CK_Lakemont:
  1286. return 16;
  1287. // i586
  1288. case CK_i586:
  1289. case CK_Pentium:
  1290. case CK_PentiumMMX:
  1291. // i686
  1292. case CK_PentiumPro:
  1293. case CK_i686:
  1294. case CK_Pentium2:
  1295. case CK_Pentium3:
  1296. case CK_PentiumM:
  1297. case CK_C3_2:
  1298. // K6
  1299. case CK_K6:
  1300. case CK_K6_2:
  1301. case CK_K6_3:
  1302. // Geode
  1303. case CK_Geode:
  1304. return 32;
  1305. // Netburst
  1306. case CK_Pentium4:
  1307. case CK_Prescott:
  1308. case CK_Nocona:
  1309. // Atom
  1310. case CK_Bonnell:
  1311. case CK_Silvermont:
  1312. case CK_Goldmont:
  1313. case CK_GoldmontPlus:
  1314. case CK_Tremont:
  1315. case CK_Westmere:
  1316. case CK_SandyBridge:
  1317. case CK_IvyBridge:
  1318. case CK_Haswell:
  1319. case CK_Broadwell:
  1320. case CK_SkylakeClient:
  1321. case CK_SkylakeServer:
  1322. case CK_Cascadelake:
  1323. case CK_Nehalem:
  1324. case CK_Cooperlake:
  1325. case CK_Cannonlake:
  1326. case CK_Tigerlake:
  1327. case CK_SapphireRapids:
  1328. case CK_IcelakeClient:
  1329. case CK_Rocketlake:
  1330. case CK_IcelakeServer:
  1331. case CK_Alderlake:
  1332. case CK_Raptorlake:
  1333. case CK_Meteorlake:
  1334. case CK_Sierraforest:
  1335. case CK_Grandridge:
  1336. case CK_Graniterapids:
  1337. case CK_Emeraldrapids:
  1338. case CK_KNL:
  1339. case CK_KNM:
  1340. // K7
  1341. case CK_Athlon:
  1342. case CK_AthlonXP:
  1343. // K8
  1344. case CK_K8:
  1345. case CK_K8SSE3:
  1346. case CK_AMDFAM10:
  1347. // Bobcat
  1348. case CK_BTVER1:
  1349. case CK_BTVER2:
  1350. // Bulldozer
  1351. case CK_BDVER1:
  1352. case CK_BDVER2:
  1353. case CK_BDVER3:
  1354. case CK_BDVER4:
  1355. // Zen
  1356. case CK_ZNVER1:
  1357. case CK_ZNVER2:
  1358. case CK_ZNVER3:
  1359. case CK_ZNVER4:
  1360. // Deprecated
  1361. case CK_x86_64:
  1362. case CK_x86_64_v2:
  1363. case CK_x86_64_v3:
  1364. case CK_x86_64_v4:
  1365. case CK_Yonah:
  1366. case CK_Penryn:
  1367. case CK_Core2:
  1368. return 64;
  1369. // The following currently have unknown cache line sizes (but they are probably all 64):
  1370. // Core
  1371. case CK_None:
  1372. return std::nullopt;
  1373. }
  1374. llvm_unreachable("Unknown CPU kind");
  1375. }
  1376. bool X86TargetInfo::validateOutputSize(const llvm::StringMap<bool> &FeatureMap,
  1377. StringRef Constraint,
  1378. unsigned Size) const {
  1379. // Strip off constraint modifiers.
  1380. while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
  1381. Constraint = Constraint.substr(1);
  1382. return validateOperandSize(FeatureMap, Constraint, Size);
  1383. }
  1384. bool X86TargetInfo::validateInputSize(const llvm::StringMap<bool> &FeatureMap,
  1385. StringRef Constraint,
  1386. unsigned Size) const {
  1387. return validateOperandSize(FeatureMap, Constraint, Size);
  1388. }
  1389. bool X86TargetInfo::validateOperandSize(const llvm::StringMap<bool> &FeatureMap,
  1390. StringRef Constraint,
  1391. unsigned Size) const {
  1392. switch (Constraint[0]) {
  1393. default:
  1394. break;
  1395. case 'k':
  1396. // Registers k0-k7 (AVX512) size limit is 64 bit.
  1397. case 'y':
  1398. return Size <= 64;
  1399. case 'f':
  1400. case 't':
  1401. case 'u':
  1402. return Size <= 128;
  1403. case 'Y':
  1404. // 'Y' is the first character for several 2-character constraints.
  1405. switch (Constraint[1]) {
  1406. default:
  1407. return false;
  1408. case 'm':
  1409. // 'Ym' is synonymous with 'y'.
  1410. case 'k':
  1411. return Size <= 64;
  1412. case 'z':
  1413. // XMM0/YMM/ZMM0
  1414. if (hasFeatureEnabled(FeatureMap, "avx512f"))
  1415. // ZMM0 can be used if target supports AVX512F.
  1416. return Size <= 512U;
  1417. else if (hasFeatureEnabled(FeatureMap, "avx"))
  1418. // YMM0 can be used if target supports AVX.
  1419. return Size <= 256U;
  1420. else if (hasFeatureEnabled(FeatureMap, "sse"))
  1421. return Size <= 128U;
  1422. return false;
  1423. case 'i':
  1424. case 't':
  1425. case '2':
  1426. // 'Yi','Yt','Y2' are synonymous with 'x' when SSE2 is enabled.
  1427. if (SSELevel < SSE2)
  1428. return false;
  1429. break;
  1430. }
  1431. break;
  1432. case 'v':
  1433. case 'x':
  1434. if (hasFeatureEnabled(FeatureMap, "avx512f"))
  1435. // 512-bit zmm registers can be used if target supports AVX512F.
  1436. return Size <= 512U;
  1437. else if (hasFeatureEnabled(FeatureMap, "avx"))
  1438. // 256-bit ymm registers can be used if target supports AVX.
  1439. return Size <= 256U;
  1440. return Size <= 128U;
  1441. }
  1442. return true;
  1443. }
  1444. std::string X86TargetInfo::convertConstraint(const char *&Constraint) const {
  1445. switch (*Constraint) {
  1446. case '@':
  1447. if (auto Len = matchAsmCCConstraint(Constraint)) {
  1448. std::string Converted = "{" + std::string(Constraint, Len) + "}";
  1449. Constraint += Len - 1;
  1450. return Converted;
  1451. }
  1452. return std::string(1, *Constraint);
  1453. case 'a':
  1454. return std::string("{ax}");
  1455. case 'b':
  1456. return std::string("{bx}");
  1457. case 'c':
  1458. return std::string("{cx}");
  1459. case 'd':
  1460. return std::string("{dx}");
  1461. case 'S':
  1462. return std::string("{si}");
  1463. case 'D':
  1464. return std::string("{di}");
  1465. case 'p': // Keep 'p' constraint (address).
  1466. return std::string("p");
  1467. case 't': // top of floating point stack.
  1468. return std::string("{st}");
  1469. case 'u': // second from top of floating point stack.
  1470. return std::string("{st(1)}"); // second from top of floating point stack.
  1471. case 'Y':
  1472. switch (Constraint[1]) {
  1473. default:
  1474. // Break from inner switch and fall through (copy single char),
  1475. // continue parsing after copying the current constraint into
  1476. // the return string.
  1477. break;
  1478. case 'k':
  1479. case 'm':
  1480. case 'i':
  1481. case 't':
  1482. case 'z':
  1483. case '2':
  1484. // "^" hints llvm that this is a 2 letter constraint.
  1485. // "Constraint++" is used to promote the string iterator
  1486. // to the next constraint.
  1487. return std::string("^") + std::string(Constraint++, 2);
  1488. }
  1489. [[fallthrough]];
  1490. default:
  1491. return std::string(1, *Constraint);
  1492. }
  1493. }
  1494. void X86TargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
  1495. bool Only64Bit = getTriple().getArch() != llvm::Triple::x86;
  1496. llvm::X86::fillValidCPUArchList(Values, Only64Bit);
  1497. }
  1498. void X86TargetInfo::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const {
  1499. llvm::X86::fillValidTuneCPUList(Values);
  1500. }
  1501. ArrayRef<const char *> X86TargetInfo::getGCCRegNames() const {
  1502. return llvm::ArrayRef(GCCRegNames);
  1503. }
  1504. ArrayRef<TargetInfo::AddlRegName> X86TargetInfo::getGCCAddlRegNames() const {
  1505. return llvm::ArrayRef(AddlRegNames);
  1506. }
  1507. ArrayRef<Builtin::Info> X86_32TargetInfo::getTargetBuiltins() const {
  1508. return llvm::ArrayRef(BuiltinInfoX86, clang::X86::LastX86CommonBuiltin -
  1509. Builtin::FirstTSBuiltin + 1);
  1510. }
  1511. ArrayRef<Builtin::Info> X86_64TargetInfo::getTargetBuiltins() const {
  1512. return llvm::ArrayRef(BuiltinInfoX86,
  1513. X86::LastTSBuiltin - Builtin::FirstTSBuiltin);
  1514. }