X86ISelLowering.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. //===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- 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 defines the interfaces that X86 uses to lower LLVM code into a
  10. // selection DAG.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_X86_X86ISELLOWERING_H
  14. #define LLVM_LIB_TARGET_X86_X86ISELLOWERING_H
  15. #include "llvm/CodeGen/MachineFunction.h"
  16. #include "llvm/CodeGen/TargetLowering.h"
  17. namespace llvm {
  18. class X86Subtarget;
  19. class X86TargetMachine;
  20. namespace X86ISD {
  21. // X86 Specific DAG Nodes
  22. enum NodeType : unsigned {
  23. // Start the numbering where the builtin ops leave off.
  24. FIRST_NUMBER = ISD::BUILTIN_OP_END,
  25. /// Bit scan forward.
  26. BSF,
  27. /// Bit scan reverse.
  28. BSR,
  29. /// X86 funnel/double shift i16 instructions. These correspond to
  30. /// X86::SHLDW and X86::SHRDW instructions which have different amt
  31. /// modulo rules to generic funnel shifts.
  32. /// NOTE: The operand order matches ISD::FSHL/FSHR not SHLD/SHRD.
  33. FSHL,
  34. FSHR,
  35. /// Bitwise logical AND of floating point values. This corresponds
  36. /// to X86::ANDPS or X86::ANDPD.
  37. FAND,
  38. /// Bitwise logical OR of floating point values. This corresponds
  39. /// to X86::ORPS or X86::ORPD.
  40. FOR,
  41. /// Bitwise logical XOR of floating point values. This corresponds
  42. /// to X86::XORPS or X86::XORPD.
  43. FXOR,
  44. /// Bitwise logical ANDNOT of floating point values. This
  45. /// corresponds to X86::ANDNPS or X86::ANDNPD.
  46. FANDN,
  47. /// These operations represent an abstract X86 call
  48. /// instruction, which includes a bunch of information. In particular the
  49. /// operands of these node are:
  50. ///
  51. /// #0 - The incoming token chain
  52. /// #1 - The callee
  53. /// #2 - The number of arg bytes the caller pushes on the stack.
  54. /// #3 - The number of arg bytes the callee pops off the stack.
  55. /// #4 - The value to pass in AL/AX/EAX (optional)
  56. /// #5 - The value to pass in DL/DX/EDX (optional)
  57. ///
  58. /// The result values of these nodes are:
  59. ///
  60. /// #0 - The outgoing token chain
  61. /// #1 - The first register result value (optional)
  62. /// #2 - The second register result value (optional)
  63. ///
  64. CALL,
  65. /// Same as call except it adds the NoTrack prefix.
  66. NT_CALL,
  67. // Pseudo for a OBJC call that gets emitted together with a special
  68. // marker instruction.
  69. CALL_RVMARKER,
  70. /// X86 compare and logical compare instructions.
  71. CMP,
  72. FCMP,
  73. COMI,
  74. UCOMI,
  75. /// X86 bit-test instructions.
  76. BT,
  77. /// X86 SetCC. Operand 0 is condition code, and operand 1 is the EFLAGS
  78. /// operand, usually produced by a CMP instruction.
  79. SETCC,
  80. /// X86 Select
  81. SELECTS,
  82. // Same as SETCC except it's materialized with a sbb and the value is all
  83. // one's or all zero's.
  84. SETCC_CARRY, // R = carry_bit ? ~0 : 0
  85. /// X86 FP SETCC, implemented with CMP{cc}SS/CMP{cc}SD.
  86. /// Operands are two FP values to compare; result is a mask of
  87. /// 0s or 1s. Generally DTRT for C/C++ with NaNs.
  88. FSETCC,
  89. /// X86 FP SETCC, similar to above, but with output as an i1 mask and
  90. /// and a version with SAE.
  91. FSETCCM,
  92. FSETCCM_SAE,
  93. /// X86 conditional moves. Operand 0 and operand 1 are the two values
  94. /// to select from. Operand 2 is the condition code, and operand 3 is the
  95. /// flag operand produced by a CMP or TEST instruction.
  96. CMOV,
  97. /// X86 conditional branches. Operand 0 is the chain operand, operand 1
  98. /// is the block to branch if condition is true, operand 2 is the
  99. /// condition code, and operand 3 is the flag operand produced by a CMP
  100. /// or TEST instruction.
  101. BRCOND,
  102. /// BRIND node with NoTrack prefix. Operand 0 is the chain operand and
  103. /// operand 1 is the target address.
  104. NT_BRIND,
  105. /// Return with a flag operand. Operand 0 is the chain operand, operand
  106. /// 1 is the number of bytes of stack to pop.
  107. RET_FLAG,
  108. /// Return from interrupt. Operand 0 is the number of bytes to pop.
  109. IRET,
  110. /// Repeat fill, corresponds to X86::REP_STOSx.
  111. REP_STOS,
  112. /// Repeat move, corresponds to X86::REP_MOVSx.
  113. REP_MOVS,
  114. /// On Darwin, this node represents the result of the popl
  115. /// at function entry, used for PIC code.
  116. GlobalBaseReg,
  117. /// A wrapper node for TargetConstantPool, TargetJumpTable,
  118. /// TargetExternalSymbol, TargetGlobalAddress, TargetGlobalTLSAddress,
  119. /// MCSymbol and TargetBlockAddress.
  120. Wrapper,
  121. /// Special wrapper used under X86-64 PIC mode for RIP
  122. /// relative displacements.
  123. WrapperRIP,
  124. /// Copies a 64-bit value from an MMX vector to the low word
  125. /// of an XMM vector, with the high word zero filled.
  126. MOVQ2DQ,
  127. /// Copies a 64-bit value from the low word of an XMM vector
  128. /// to an MMX vector.
  129. MOVDQ2Q,
  130. /// Copies a 32-bit value from the low word of a MMX
  131. /// vector to a GPR.
  132. MMX_MOVD2W,
  133. /// Copies a GPR into the low 32-bit word of a MMX vector
  134. /// and zero out the high word.
  135. MMX_MOVW2D,
  136. /// Extract an 8-bit value from a vector and zero extend it to
  137. /// i32, corresponds to X86::PEXTRB.
  138. PEXTRB,
  139. /// Extract a 16-bit value from a vector and zero extend it to
  140. /// i32, corresponds to X86::PEXTRW.
  141. PEXTRW,
  142. /// Insert any element of a 4 x float vector into any element
  143. /// of a destination 4 x floatvector.
  144. INSERTPS,
  145. /// Insert the lower 8-bits of a 32-bit value to a vector,
  146. /// corresponds to X86::PINSRB.
  147. PINSRB,
  148. /// Insert the lower 16-bits of a 32-bit value to a vector,
  149. /// corresponds to X86::PINSRW.
  150. PINSRW,
  151. /// Shuffle 16 8-bit values within a vector.
  152. PSHUFB,
  153. /// Compute Sum of Absolute Differences.
  154. PSADBW,
  155. /// Compute Double Block Packed Sum-Absolute-Differences
  156. DBPSADBW,
  157. /// Bitwise Logical AND NOT of Packed FP values.
  158. ANDNP,
  159. /// Blend where the selector is an immediate.
  160. BLENDI,
  161. /// Dynamic (non-constant condition) vector blend where only the sign bits
  162. /// of the condition elements are used. This is used to enforce that the
  163. /// condition mask is not valid for generic VSELECT optimizations. This
  164. /// is also used to implement the intrinsics.
  165. /// Operands are in VSELECT order: MASK, TRUE, FALSE
  166. BLENDV,
  167. /// Combined add and sub on an FP vector.
  168. ADDSUB,
  169. // FP vector ops with rounding mode.
  170. FADD_RND,
  171. FADDS,
  172. FADDS_RND,
  173. FSUB_RND,
  174. FSUBS,
  175. FSUBS_RND,
  176. FMUL_RND,
  177. FMULS,
  178. FMULS_RND,
  179. FDIV_RND,
  180. FDIVS,
  181. FDIVS_RND,
  182. FMAX_SAE,
  183. FMAXS_SAE,
  184. FMIN_SAE,
  185. FMINS_SAE,
  186. FSQRT_RND,
  187. FSQRTS,
  188. FSQRTS_RND,
  189. // FP vector get exponent.
  190. FGETEXP,
  191. FGETEXP_SAE,
  192. FGETEXPS,
  193. FGETEXPS_SAE,
  194. // Extract Normalized Mantissas.
  195. VGETMANT,
  196. VGETMANT_SAE,
  197. VGETMANTS,
  198. VGETMANTS_SAE,
  199. // FP Scale.
  200. SCALEF,
  201. SCALEF_RND,
  202. SCALEFS,
  203. SCALEFS_RND,
  204. // Unsigned Integer average.
  205. AVG,
  206. /// Integer horizontal add/sub.
  207. HADD,
  208. HSUB,
  209. /// Floating point horizontal add/sub.
  210. FHADD,
  211. FHSUB,
  212. // Detect Conflicts Within a Vector
  213. CONFLICT,
  214. /// Floating point max and min.
  215. FMAX,
  216. FMIN,
  217. /// Commutative FMIN and FMAX.
  218. FMAXC,
  219. FMINC,
  220. /// Scalar intrinsic floating point max and min.
  221. FMAXS,
  222. FMINS,
  223. /// Floating point reciprocal-sqrt and reciprocal approximation.
  224. /// Note that these typically require refinement
  225. /// in order to obtain suitable precision.
  226. FRSQRT,
  227. FRCP,
  228. // AVX-512 reciprocal approximations with a little more precision.
  229. RSQRT14,
  230. RSQRT14S,
  231. RCP14,
  232. RCP14S,
  233. // Thread Local Storage.
  234. TLSADDR,
  235. // Thread Local Storage. A call to get the start address
  236. // of the TLS block for the current module.
  237. TLSBASEADDR,
  238. // Thread Local Storage. When calling to an OS provided
  239. // thunk at the address from an earlier relocation.
  240. TLSCALL,
  241. // Exception Handling helpers.
  242. EH_RETURN,
  243. // SjLj exception handling setjmp.
  244. EH_SJLJ_SETJMP,
  245. // SjLj exception handling longjmp.
  246. EH_SJLJ_LONGJMP,
  247. // SjLj exception handling dispatch.
  248. EH_SJLJ_SETUP_DISPATCH,
  249. /// Tail call return. See X86TargetLowering::LowerCall for
  250. /// the list of operands.
  251. TC_RETURN,
  252. // Vector move to low scalar and zero higher vector elements.
  253. VZEXT_MOVL,
  254. // Vector integer truncate.
  255. VTRUNC,
  256. // Vector integer truncate with unsigned/signed saturation.
  257. VTRUNCUS,
  258. VTRUNCS,
  259. // Masked version of the above. Used when less than a 128-bit result is
  260. // produced since the mask only applies to the lower elements and can't
  261. // be represented by a select.
  262. // SRC, PASSTHRU, MASK
  263. VMTRUNC,
  264. VMTRUNCUS,
  265. VMTRUNCS,
  266. // Vector FP extend.
  267. VFPEXT,
  268. VFPEXT_SAE,
  269. VFPEXTS,
  270. VFPEXTS_SAE,
  271. // Vector FP round.
  272. VFPROUND,
  273. VFPROUND_RND,
  274. VFPROUNDS,
  275. VFPROUNDS_RND,
  276. // Masked version of above. Used for v2f64->v4f32.
  277. // SRC, PASSTHRU, MASK
  278. VMFPROUND,
  279. // 128-bit vector logical left / right shift
  280. VSHLDQ,
  281. VSRLDQ,
  282. // Vector shift elements
  283. VSHL,
  284. VSRL,
  285. VSRA,
  286. // Vector variable shift
  287. VSHLV,
  288. VSRLV,
  289. VSRAV,
  290. // Vector shift elements by immediate
  291. VSHLI,
  292. VSRLI,
  293. VSRAI,
  294. // Shifts of mask registers.
  295. KSHIFTL,
  296. KSHIFTR,
  297. // Bit rotate by immediate
  298. VROTLI,
  299. VROTRI,
  300. // Vector packed double/float comparison.
  301. CMPP,
  302. // Vector integer comparisons.
  303. PCMPEQ,
  304. PCMPGT,
  305. // v8i16 Horizontal minimum and position.
  306. PHMINPOS,
  307. MULTISHIFT,
  308. /// Vector comparison generating mask bits for fp and
  309. /// integer signed and unsigned data types.
  310. CMPM,
  311. // Vector mask comparison generating mask bits for FP values.
  312. CMPMM,
  313. // Vector mask comparison with SAE for FP values.
  314. CMPMM_SAE,
  315. // Arithmetic operations with FLAGS results.
  316. ADD,
  317. SUB,
  318. ADC,
  319. SBB,
  320. SMUL,
  321. UMUL,
  322. OR,
  323. XOR,
  324. AND,
  325. // Bit field extract.
  326. BEXTR,
  327. BEXTRI,
  328. // Zero High Bits Starting with Specified Bit Position.
  329. BZHI,
  330. // Parallel extract and deposit.
  331. PDEP,
  332. PEXT,
  333. // X86-specific multiply by immediate.
  334. MUL_IMM,
  335. // Vector sign bit extraction.
  336. MOVMSK,
  337. // Vector bitwise comparisons.
  338. PTEST,
  339. // Vector packed fp sign bitwise comparisons.
  340. TESTP,
  341. // OR/AND test for masks.
  342. KORTEST,
  343. KTEST,
  344. // ADD for masks.
  345. KADD,
  346. // Several flavors of instructions with vector shuffle behaviors.
  347. // Saturated signed/unnsigned packing.
  348. PACKSS,
  349. PACKUS,
  350. // Intra-lane alignr.
  351. PALIGNR,
  352. // AVX512 inter-lane alignr.
  353. VALIGN,
  354. PSHUFD,
  355. PSHUFHW,
  356. PSHUFLW,
  357. SHUFP,
  358. // VBMI2 Concat & Shift.
  359. VSHLD,
  360. VSHRD,
  361. VSHLDV,
  362. VSHRDV,
  363. // Shuffle Packed Values at 128-bit granularity.
  364. SHUF128,
  365. MOVDDUP,
  366. MOVSHDUP,
  367. MOVSLDUP,
  368. MOVLHPS,
  369. MOVHLPS,
  370. MOVSD,
  371. MOVSS,
  372. MOVSH,
  373. UNPCKL,
  374. UNPCKH,
  375. VPERMILPV,
  376. VPERMILPI,
  377. VPERMI,
  378. VPERM2X128,
  379. // Variable Permute (VPERM).
  380. // Res = VPERMV MaskV, V0
  381. VPERMV,
  382. // 3-op Variable Permute (VPERMT2).
  383. // Res = VPERMV3 V0, MaskV, V1
  384. VPERMV3,
  385. // Bitwise ternary logic.
  386. VPTERNLOG,
  387. // Fix Up Special Packed Float32/64 values.
  388. VFIXUPIMM,
  389. VFIXUPIMM_SAE,
  390. VFIXUPIMMS,
  391. VFIXUPIMMS_SAE,
  392. // Range Restriction Calculation For Packed Pairs of Float32/64 values.
  393. VRANGE,
  394. VRANGE_SAE,
  395. VRANGES,
  396. VRANGES_SAE,
  397. // Reduce - Perform Reduction Transformation on scalar\packed FP.
  398. VREDUCE,
  399. VREDUCE_SAE,
  400. VREDUCES,
  401. VREDUCES_SAE,
  402. // RndScale - Round FP Values To Include A Given Number Of Fraction Bits.
  403. // Also used by the legacy (V)ROUND intrinsics where we mask out the
  404. // scaling part of the immediate.
  405. VRNDSCALE,
  406. VRNDSCALE_SAE,
  407. VRNDSCALES,
  408. VRNDSCALES_SAE,
  409. // Tests Types Of a FP Values for packed types.
  410. VFPCLASS,
  411. // Tests Types Of a FP Values for scalar types.
  412. VFPCLASSS,
  413. // Broadcast (splat) scalar or element 0 of a vector. If the operand is
  414. // a vector, this node may change the vector length as part of the splat.
  415. VBROADCAST,
  416. // Broadcast mask to vector.
  417. VBROADCASTM,
  418. /// SSE4A Extraction and Insertion.
  419. EXTRQI,
  420. INSERTQI,
  421. // XOP arithmetic/logical shifts.
  422. VPSHA,
  423. VPSHL,
  424. // XOP signed/unsigned integer comparisons.
  425. VPCOM,
  426. VPCOMU,
  427. // XOP packed permute bytes.
  428. VPPERM,
  429. // XOP two source permutation.
  430. VPERMIL2,
  431. // Vector multiply packed unsigned doubleword integers.
  432. PMULUDQ,
  433. // Vector multiply packed signed doubleword integers.
  434. PMULDQ,
  435. // Vector Multiply Packed UnsignedIntegers with Round and Scale.
  436. MULHRS,
  437. // Multiply and Add Packed Integers.
  438. VPMADDUBSW,
  439. VPMADDWD,
  440. // AVX512IFMA multiply and add.
  441. // NOTE: These are different than the instruction and perform
  442. // op0 x op1 + op2.
  443. VPMADD52L,
  444. VPMADD52H,
  445. // VNNI
  446. VPDPBUSD,
  447. VPDPBUSDS,
  448. VPDPWSSD,
  449. VPDPWSSDS,
  450. // FMA nodes.
  451. // We use the target independent ISD::FMA for the non-inverted case.
  452. FNMADD,
  453. FMSUB,
  454. FNMSUB,
  455. FMADDSUB,
  456. FMSUBADD,
  457. // FMA with rounding mode.
  458. FMADD_RND,
  459. FNMADD_RND,
  460. FMSUB_RND,
  461. FNMSUB_RND,
  462. FMADDSUB_RND,
  463. FMSUBADD_RND,
  464. // AVX512-FP16 complex addition and multiplication.
  465. VFMADDC,
  466. VFMADDC_RND,
  467. VFCMADDC,
  468. VFCMADDC_RND,
  469. VFMULC,
  470. VFMULC_RND,
  471. VFCMULC,
  472. VFCMULC_RND,
  473. VFMADDCSH,
  474. VFMADDCSH_RND,
  475. VFCMADDCSH,
  476. VFCMADDCSH_RND,
  477. VFMULCSH,
  478. VFMULCSH_RND,
  479. VFCMULCSH,
  480. VFCMULCSH_RND,
  481. // Compress and expand.
  482. COMPRESS,
  483. EXPAND,
  484. // Bits shuffle
  485. VPSHUFBITQMB,
  486. // Convert Unsigned/Integer to Floating-Point Value with rounding mode.
  487. SINT_TO_FP_RND,
  488. UINT_TO_FP_RND,
  489. SCALAR_SINT_TO_FP,
  490. SCALAR_UINT_TO_FP,
  491. SCALAR_SINT_TO_FP_RND,
  492. SCALAR_UINT_TO_FP_RND,
  493. // Vector float/double to signed/unsigned integer.
  494. CVTP2SI,
  495. CVTP2UI,
  496. CVTP2SI_RND,
  497. CVTP2UI_RND,
  498. // Scalar float/double to signed/unsigned integer.
  499. CVTS2SI,
  500. CVTS2UI,
  501. CVTS2SI_RND,
  502. CVTS2UI_RND,
  503. // Vector float/double to signed/unsigned integer with truncation.
  504. CVTTP2SI,
  505. CVTTP2UI,
  506. CVTTP2SI_SAE,
  507. CVTTP2UI_SAE,
  508. // Scalar float/double to signed/unsigned integer with truncation.
  509. CVTTS2SI,
  510. CVTTS2UI,
  511. CVTTS2SI_SAE,
  512. CVTTS2UI_SAE,
  513. // Vector signed/unsigned integer to float/double.
  514. CVTSI2P,
  515. CVTUI2P,
  516. // Masked versions of above. Used for v2f64->v4f32.
  517. // SRC, PASSTHRU, MASK
  518. MCVTP2SI,
  519. MCVTP2UI,
  520. MCVTTP2SI,
  521. MCVTTP2UI,
  522. MCVTSI2P,
  523. MCVTUI2P,
  524. // Vector float to bfloat16.
  525. // Convert TWO packed single data to one packed BF16 data
  526. CVTNE2PS2BF16,
  527. // Convert packed single data to packed BF16 data
  528. CVTNEPS2BF16,
  529. // Masked version of above.
  530. // SRC, PASSTHRU, MASK
  531. MCVTNEPS2BF16,
  532. // Dot product of BF16 pairs to accumulated into
  533. // packed single precision.
  534. DPBF16PS,
  535. // A stack checking function call. On Windows it's _chkstk call.
  536. DYN_ALLOCA,
  537. // For allocating variable amounts of stack space when using
  538. // segmented stacks. Check if the current stacklet has enough space, and
  539. // falls back to heap allocation if not.
  540. SEG_ALLOCA,
  541. // For allocating stack space when using stack clash protector.
  542. // Allocation is performed by block, and each block is probed.
  543. PROBED_ALLOCA,
  544. // Memory barriers.
  545. MEMBARRIER,
  546. MFENCE,
  547. // Get a random integer and indicate whether it is valid in CF.
  548. RDRAND,
  549. // Get a NIST SP800-90B & C compliant random integer and
  550. // indicate whether it is valid in CF.
  551. RDSEED,
  552. // Protection keys
  553. // RDPKRU - Operand 0 is chain. Operand 1 is value for ECX.
  554. // WRPKRU - Operand 0 is chain. Operand 1 is value for EDX. Operand 2 is
  555. // value for ECX.
  556. RDPKRU,
  557. WRPKRU,
  558. // SSE42 string comparisons.
  559. // These nodes produce 3 results, index, mask, and flags. X86ISelDAGToDAG
  560. // will emit one or two instructions based on which results are used. If
  561. // flags and index/mask this allows us to use a single instruction since
  562. // we won't have to pick and opcode for flags. Instead we can rely on the
  563. // DAG to CSE everything and decide at isel.
  564. PCMPISTR,
  565. PCMPESTR,
  566. // Test if in transactional execution.
  567. XTEST,
  568. // ERI instructions.
  569. RSQRT28,
  570. RSQRT28_SAE,
  571. RSQRT28S,
  572. RSQRT28S_SAE,
  573. RCP28,
  574. RCP28_SAE,
  575. RCP28S,
  576. RCP28S_SAE,
  577. EXP2,
  578. EXP2_SAE,
  579. // Conversions between float and half-float.
  580. CVTPS2PH,
  581. CVTPH2PS,
  582. CVTPH2PS_SAE,
  583. // Masked version of above.
  584. // SRC, RND, PASSTHRU, MASK
  585. MCVTPS2PH,
  586. // Galois Field Arithmetic Instructions
  587. GF2P8AFFINEINVQB,
  588. GF2P8AFFINEQB,
  589. GF2P8MULB,
  590. // LWP insert record.
  591. LWPINS,
  592. // User level wait
  593. UMWAIT,
  594. TPAUSE,
  595. // Enqueue Stores Instructions
  596. ENQCMD,
  597. ENQCMDS,
  598. // For avx512-vp2intersect
  599. VP2INTERSECT,
  600. // User level interrupts - testui
  601. TESTUI,
  602. /// X86 strict FP compare instructions.
  603. STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
  604. STRICT_FCMPS,
  605. // Vector packed double/float comparison.
  606. STRICT_CMPP,
  607. /// Vector comparison generating mask bits for fp and
  608. /// integer signed and unsigned data types.
  609. STRICT_CMPM,
  610. // Vector float/double to signed/unsigned integer with truncation.
  611. STRICT_CVTTP2SI,
  612. STRICT_CVTTP2UI,
  613. // Vector FP extend.
  614. STRICT_VFPEXT,
  615. // Vector FP round.
  616. STRICT_VFPROUND,
  617. // RndScale - Round FP Values To Include A Given Number Of Fraction Bits.
  618. // Also used by the legacy (V)ROUND intrinsics where we mask out the
  619. // scaling part of the immediate.
  620. STRICT_VRNDSCALE,
  621. // Vector signed/unsigned integer to float/double.
  622. STRICT_CVTSI2P,
  623. STRICT_CVTUI2P,
  624. // Strict FMA nodes.
  625. STRICT_FNMADD,
  626. STRICT_FMSUB,
  627. STRICT_FNMSUB,
  628. // Conversions between float and half-float.
  629. STRICT_CVTPS2PH,
  630. STRICT_CVTPH2PS,
  631. // WARNING: Only add nodes here if they are stric FP nodes. Non-memory and
  632. // non-strict FP nodes should be above FIRST_TARGET_STRICTFP_OPCODE.
  633. // Compare and swap.
  634. LCMPXCHG_DAG = ISD::FIRST_TARGET_MEMORY_OPCODE,
  635. LCMPXCHG8_DAG,
  636. LCMPXCHG16_DAG,
  637. LCMPXCHG16_SAVE_RBX_DAG,
  638. /// LOCK-prefixed arithmetic read-modify-write instructions.
  639. /// EFLAGS, OUTCHAIN = LADD(INCHAIN, PTR, RHS)
  640. LADD,
  641. LSUB,
  642. LOR,
  643. LXOR,
  644. LAND,
  645. // Load, scalar_to_vector, and zero extend.
  646. VZEXT_LOAD,
  647. // extract_vector_elt, store.
  648. VEXTRACT_STORE,
  649. // scalar broadcast from memory.
  650. VBROADCAST_LOAD,
  651. // subvector broadcast from memory.
  652. SUBV_BROADCAST_LOAD,
  653. // Store FP control word into i16 memory.
  654. FNSTCW16m,
  655. // Load FP control word from i16 memory.
  656. FLDCW16m,
  657. /// This instruction implements FP_TO_SINT with the
  658. /// integer destination in memory and a FP reg source. This corresponds
  659. /// to the X86::FIST*m instructions and the rounding mode change stuff. It
  660. /// has two inputs (token chain and address) and two outputs (int value
  661. /// and token chain). Memory VT specifies the type to store to.
  662. FP_TO_INT_IN_MEM,
  663. /// This instruction implements SINT_TO_FP with the
  664. /// integer source in memory and FP reg result. This corresponds to the
  665. /// X86::FILD*m instructions. It has two inputs (token chain and address)
  666. /// and two outputs (FP value and token chain). The integer source type is
  667. /// specified by the memory VT.
  668. FILD,
  669. /// This instruction implements a fp->int store from FP stack
  670. /// slots. This corresponds to the fist instruction. It takes a
  671. /// chain operand, value to store, address, and glue. The memory VT
  672. /// specifies the type to store as.
  673. FIST,
  674. /// This instruction implements an extending load to FP stack slots.
  675. /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain
  676. /// operand, and ptr to load from. The memory VT specifies the type to
  677. /// load from.
  678. FLD,
  679. /// This instruction implements a truncating store from FP stack
  680. /// slots. This corresponds to the X86::FST32m / X86::FST64m. It takes a
  681. /// chain operand, value to store, address, and glue. The memory VT
  682. /// specifies the type to store as.
  683. FST,
  684. /// These instructions grab the address of the next argument
  685. /// from a va_list. (reads and modifies the va_list in memory)
  686. VAARG_64,
  687. VAARG_X32,
  688. // Vector truncating store with unsigned/signed saturation
  689. VTRUNCSTOREUS,
  690. VTRUNCSTORES,
  691. // Vector truncating masked store with unsigned/signed saturation
  692. VMTRUNCSTOREUS,
  693. VMTRUNCSTORES,
  694. // X86 specific gather and scatter
  695. MGATHER,
  696. MSCATTER,
  697. // Key locker nodes that produce flags.
  698. AESENC128KL,
  699. AESDEC128KL,
  700. AESENC256KL,
  701. AESDEC256KL,
  702. AESENCWIDE128KL,
  703. AESDECWIDE128KL,
  704. AESENCWIDE256KL,
  705. AESDECWIDE256KL,
  706. // Save xmm argument registers to the stack, according to %al. An operator
  707. // is needed so that this can be expanded with control flow.
  708. VASTART_SAVE_XMM_REGS,
  709. // WARNING: Do not add anything in the end unless you want the node to
  710. // have memop! In fact, starting from FIRST_TARGET_MEMORY_OPCODE all
  711. // opcodes will be thought as target memory ops!
  712. };
  713. } // end namespace X86ISD
  714. namespace X86 {
  715. /// Current rounding mode is represented in bits 11:10 of FPSR. These
  716. /// values are same as corresponding constants for rounding mode used
  717. /// in glibc.
  718. enum RoundingMode {
  719. rmToNearest = 0, // FE_TONEAREST
  720. rmDownward = 1 << 10, // FE_DOWNWARD
  721. rmUpward = 2 << 10, // FE_UPWARD
  722. rmTowardZero = 3 << 10, // FE_TOWARDZERO
  723. rmMask = 3 << 10 // Bit mask selecting rounding mode
  724. };
  725. }
  726. /// Define some predicates that are used for node matching.
  727. namespace X86 {
  728. /// Returns true if Elt is a constant zero or floating point constant +0.0.
  729. bool isZeroNode(SDValue Elt);
  730. /// Returns true of the given offset can be
  731. /// fit into displacement field of the instruction.
  732. bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M,
  733. bool hasSymbolicDisplacement);
  734. /// Determines whether the callee is required to pop its
  735. /// own arguments. Callee pop is necessary to support tail calls.
  736. bool isCalleePop(CallingConv::ID CallingConv,
  737. bool is64Bit, bool IsVarArg, bool GuaranteeTCO);
  738. /// If Op is a constant whose elements are all the same constant or
  739. /// undefined, return true and return the constant value in \p SplatVal.
  740. /// If we have undef bits that don't cover an entire element, we treat these
  741. /// as zero if AllowPartialUndefs is set, else we fail and return false.
  742. bool isConstantSplat(SDValue Op, APInt &SplatVal,
  743. bool AllowPartialUndefs = true);
  744. /// Check if Op is a load operation that could be folded into some other x86
  745. /// instruction as a memory operand. Example: vpaddd (%rdi), %xmm0, %xmm0.
  746. bool mayFoldLoad(SDValue Op, const X86Subtarget &Subtarget,
  747. bool AssumeSingleUse = false);
  748. /// Check if Op is a load operation that could be folded into a vector splat
  749. /// instruction as a memory operand. Example: vbroadcastss 16(%rdi), %xmm2.
  750. bool mayFoldLoadIntoBroadcastFromMem(SDValue Op, MVT EltVT,
  751. const X86Subtarget &Subtarget,
  752. bool AssumeSingleUse = false);
  753. /// Check if Op is a value that could be used to fold a store into some
  754. /// other x86 instruction as a memory operand. Ex: pextrb $0, %xmm0, (%rdi).
  755. bool mayFoldIntoStore(SDValue Op);
  756. /// Check if Op is an operation that could be folded into a zero extend x86
  757. /// instruction.
  758. bool mayFoldIntoZeroExtend(SDValue Op);
  759. } // end namespace X86
  760. //===--------------------------------------------------------------------===//
  761. // X86 Implementation of the TargetLowering interface
  762. class X86TargetLowering final : public TargetLowering {
  763. public:
  764. explicit X86TargetLowering(const X86TargetMachine &TM,
  765. const X86Subtarget &STI);
  766. unsigned getJumpTableEncoding() const override;
  767. bool useSoftFloat() const override;
  768. void markLibCallAttributes(MachineFunction *MF, unsigned CC,
  769. ArgListTy &Args) const override;
  770. MVT getScalarShiftAmountTy(const DataLayout &, EVT VT) const override {
  771. return MVT::i8;
  772. }
  773. const MCExpr *
  774. LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,
  775. const MachineBasicBlock *MBB, unsigned uid,
  776. MCContext &Ctx) const override;
  777. /// Returns relocation base for the given PIC jumptable.
  778. SDValue getPICJumpTableRelocBase(SDValue Table,
  779. SelectionDAG &DAG) const override;
  780. const MCExpr *
  781. getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
  782. unsigned JTI, MCContext &Ctx) const override;
  783. /// Return the desired alignment for ByVal aggregate
  784. /// function arguments in the caller parameter area. For X86, aggregates
  785. /// that contains are placed at 16-byte boundaries while the rest are at
  786. /// 4-byte boundaries.
  787. uint64_t getByValTypeAlignment(Type *Ty,
  788. const DataLayout &DL) const override;
  789. EVT getOptimalMemOpType(const MemOp &Op,
  790. const AttributeList &FuncAttributes) const override;
  791. /// Returns true if it's safe to use load / store of the
  792. /// specified type to expand memcpy / memset inline. This is mostly true
  793. /// for all types except for some special cases. For example, on X86
  794. /// targets without SSE2 f64 load / store are done with fldl / fstpl which
  795. /// also does type conversion. Note the specified type doesn't have to be
  796. /// legal as the hook is used before type legalization.
  797. bool isSafeMemOpType(MVT VT) const override;
  798. /// Returns true if the target allows unaligned memory accesses of the
  799. /// specified type. Returns whether it is "fast" in the last argument.
  800. bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align Alignment,
  801. MachineMemOperand::Flags Flags,
  802. bool *Fast) const override;
  803. /// Provide custom lowering hooks for some operations.
  804. ///
  805. SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
  806. /// Replace the results of node with an illegal result
  807. /// type with new values built out of custom code.
  808. ///
  809. void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
  810. SelectionDAG &DAG) const override;
  811. SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
  812. /// Return true if the target has native support for
  813. /// the specified value type and it is 'desirable' to use the type for the
  814. /// given node type. e.g. On x86 i16 is legal, but undesirable since i16
  815. /// instruction encodings are longer and some i16 instructions are slow.
  816. bool isTypeDesirableForOp(unsigned Opc, EVT VT) const override;
  817. /// Return true if the target has native support for the
  818. /// specified value type and it is 'desirable' to use the type. e.g. On x86
  819. /// i16 is legal, but undesirable since i16 instruction encodings are longer
  820. /// and some i16 instructions are slow.
  821. bool IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const override;
  822. /// Return the newly negated expression if the cost is not expensive and
  823. /// set the cost in \p Cost to indicate that if it is cheaper or neutral to
  824. /// do the negation.
  825. SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG,
  826. bool LegalOperations, bool ForCodeSize,
  827. NegatibleCost &Cost,
  828. unsigned Depth) const override;
  829. MachineBasicBlock *
  830. EmitInstrWithCustomInserter(MachineInstr &MI,
  831. MachineBasicBlock *MBB) const override;
  832. /// This method returns the name of a target specific DAG node.
  833. const char *getTargetNodeName(unsigned Opcode) const override;
  834. /// Do not merge vector stores after legalization because that may conflict
  835. /// with x86-specific store splitting optimizations.
  836. bool mergeStoresAfterLegalization(EVT MemVT) const override {
  837. return !MemVT.isVector();
  838. }
  839. bool canMergeStoresTo(unsigned AddressSpace, EVT MemVT,
  840. const MachineFunction &MF) const override;
  841. bool isCheapToSpeculateCttz() const override;
  842. bool isCheapToSpeculateCtlz() const override;
  843. bool isCtlzFast() const override;
  844. bool hasBitPreservingFPLogic(EVT VT) const override {
  845. return VT == MVT::f32 || VT == MVT::f64 || VT.isVector() ||
  846. (VT == MVT::f16 && X86ScalarSSEf16);
  847. }
  848. bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const override {
  849. // If the pair to store is a mixture of float and int values, we will
  850. // save two bitwise instructions and one float-to-int instruction and
  851. // increase one store instruction. There is potentially a more
  852. // significant benefit because it avoids the float->int domain switch
  853. // for input value. So It is more likely a win.
  854. if ((LTy.isFloatingPoint() && HTy.isInteger()) ||
  855. (LTy.isInteger() && HTy.isFloatingPoint()))
  856. return true;
  857. // If the pair only contains int values, we will save two bitwise
  858. // instructions and increase one store instruction (costing one more
  859. // store buffer). Since the benefit is more blurred so we leave
  860. // such pair out until we get testcase to prove it is a win.
  861. return false;
  862. }
  863. bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
  864. bool hasAndNotCompare(SDValue Y) const override;
  865. bool hasAndNot(SDValue Y) const override;
  866. bool hasBitTest(SDValue X, SDValue Y) const override;
  867. bool shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
  868. SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y,
  869. unsigned OldShiftOpcode, unsigned NewShiftOpcode,
  870. SelectionDAG &DAG) const override;
  871. bool shouldFoldConstantShiftPairToMask(const SDNode *N,
  872. CombineLevel Level) const override;
  873. bool shouldFoldMaskToVariableShiftPair(SDValue Y) const override;
  874. bool
  875. shouldTransformSignedTruncationCheck(EVT XVT,
  876. unsigned KeptBits) const override {
  877. // For vectors, we don't have a preference..
  878. if (XVT.isVector())
  879. return false;
  880. auto VTIsOk = [](EVT VT) -> bool {
  881. return VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32 ||
  882. VT == MVT::i64;
  883. };
  884. // We are ok with KeptBitsVT being byte/word/dword, what MOVS supports.
  885. // XVT will be larger than KeptBitsVT.
  886. MVT KeptBitsVT = MVT::getIntegerVT(KeptBits);
  887. return VTIsOk(XVT) && VTIsOk(KeptBitsVT);
  888. }
  889. bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override;
  890. bool shouldSplatInsEltVarIndex(EVT VT) const override;
  891. bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const override {
  892. // Converting to sat variants holds little benefit on X86 as we will just
  893. // need to saturate the value back using fp arithmatic.
  894. return Op != ISD::FP_TO_UINT_SAT && isOperationLegalOrCustom(Op, VT);
  895. }
  896. bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
  897. return VT.isScalarInteger();
  898. }
  899. /// Vector-sized comparisons are fast using PCMPEQ + PMOVMSK or PTEST.
  900. MVT hasFastEqualityCompare(unsigned NumBits) const override;
  901. /// Return the value type to use for ISD::SETCC.
  902. EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
  903. EVT VT) const override;
  904. bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,
  905. const APInt &DemandedElts,
  906. TargetLoweringOpt &TLO) const override;
  907. /// Determine which of the bits specified in Mask are known to be either
  908. /// zero or one and return them in the KnownZero/KnownOne bitsets.
  909. void computeKnownBitsForTargetNode(const SDValue Op,
  910. KnownBits &Known,
  911. const APInt &DemandedElts,
  912. const SelectionDAG &DAG,
  913. unsigned Depth = 0) const override;
  914. /// Determine the number of bits in the operation that are sign bits.
  915. unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
  916. const APInt &DemandedElts,
  917. const SelectionDAG &DAG,
  918. unsigned Depth) const override;
  919. bool SimplifyDemandedVectorEltsForTargetNode(SDValue Op,
  920. const APInt &DemandedElts,
  921. APInt &KnownUndef,
  922. APInt &KnownZero,
  923. TargetLoweringOpt &TLO,
  924. unsigned Depth) const override;
  925. bool SimplifyDemandedVectorEltsForTargetShuffle(SDValue Op,
  926. const APInt &DemandedElts,
  927. unsigned MaskIndex,
  928. TargetLoweringOpt &TLO,
  929. unsigned Depth) const;
  930. bool SimplifyDemandedBitsForTargetNode(SDValue Op,
  931. const APInt &DemandedBits,
  932. const APInt &DemandedElts,
  933. KnownBits &Known,
  934. TargetLoweringOpt &TLO,
  935. unsigned Depth) const override;
  936. SDValue SimplifyMultipleUseDemandedBitsForTargetNode(
  937. SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
  938. SelectionDAG &DAG, unsigned Depth) const override;
  939. bool isSplatValueForTargetNode(SDValue Op, const APInt &DemandedElts,
  940. APInt &UndefElts,
  941. unsigned Depth) const override;
  942. const Constant *getTargetConstantFromLoad(LoadSDNode *LD) const override;
  943. SDValue unwrapAddress(SDValue N) const override;
  944. SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
  945. bool ExpandInlineAsm(CallInst *CI) const override;
  946. ConstraintType getConstraintType(StringRef Constraint) const override;
  947. /// Examine constraint string and operand type and determine a weight value.
  948. /// The operand object must already have been set up with the operand type.
  949. ConstraintWeight
  950. getSingleConstraintMatchWeight(AsmOperandInfo &info,
  951. const char *constraint) const override;
  952. const char *LowerXConstraint(EVT ConstraintVT) const override;
  953. /// Lower the specified operand into the Ops vector. If it is invalid, don't
  954. /// add anything to Ops. If hasMemory is true it means one of the asm
  955. /// constraint of the inline asm instruction being processed is 'm'.
  956. void LowerAsmOperandForConstraint(SDValue Op,
  957. std::string &Constraint,
  958. std::vector<SDValue> &Ops,
  959. SelectionDAG &DAG) const override;
  960. unsigned
  961. getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
  962. if (ConstraintCode == "v")
  963. return InlineAsm::Constraint_v;
  964. return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
  965. }
  966. /// Handle Lowering flag assembly outputs.
  967. SDValue LowerAsmOutputForConstraint(SDValue &Chain, SDValue &Flag,
  968. const SDLoc &DL,
  969. const AsmOperandInfo &Constraint,
  970. SelectionDAG &DAG) const override;
  971. /// Given a physical register constraint
  972. /// (e.g. {edx}), return the register number and the register class for the
  973. /// register. This should only be used for C_Register constraints. On
  974. /// error, this returns a register number of 0.
  975. std::pair<unsigned, const TargetRegisterClass *>
  976. getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
  977. StringRef Constraint, MVT VT) const override;
  978. /// Return true if the addressing mode represented
  979. /// by AM is legal for this target, for a load/store of the specified type.
  980. bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
  981. Type *Ty, unsigned AS,
  982. Instruction *I = nullptr) const override;
  983. /// Return true if the specified immediate is legal
  984. /// icmp immediate, that is the target has icmp instructions which can
  985. /// compare a register against the immediate without having to materialize
  986. /// the immediate into a register.
  987. bool isLegalICmpImmediate(int64_t Imm) const override;
  988. /// Return true if the specified immediate is legal
  989. /// add immediate, that is the target has add instructions which can
  990. /// add a register and the immediate without having to materialize
  991. /// the immediate into a register.
  992. bool isLegalAddImmediate(int64_t Imm) const override;
  993. bool isLegalStoreImmediate(int64_t Imm) const override;
  994. /// Return the cost of the scaling factor used in the addressing
  995. /// mode represented by AM for this target, for a load/store
  996. /// of the specified type.
  997. /// If the AM is supported, the return value must be >= 0.
  998. /// If the AM is not supported, it returns a negative value.
  999. InstructionCost getScalingFactorCost(const DataLayout &DL,
  1000. const AddrMode &AM, Type *Ty,
  1001. unsigned AS) const override;
  1002. /// This is used to enable splatted operand transforms for vector shifts
  1003. /// and vector funnel shifts.
  1004. bool isVectorShiftByScalarCheap(Type *Ty) const override;
  1005. /// Add x86-specific opcodes to the default list.
  1006. bool isBinOp(unsigned Opcode) const override;
  1007. /// Returns true if the opcode is a commutative binary operation.
  1008. bool isCommutativeBinOp(unsigned Opcode) const override;
  1009. /// Return true if it's free to truncate a value of
  1010. /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
  1011. /// register EAX to i16 by referencing its sub-register AX.
  1012. bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
  1013. bool isTruncateFree(EVT VT1, EVT VT2) const override;
  1014. bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
  1015. /// Return true if any actual instruction that defines a
  1016. /// value of type Ty1 implicit zero-extends the value to Ty2 in the result
  1017. /// register. This does not necessarily include registers defined in
  1018. /// unknown ways, such as incoming arguments, or copies from unknown
  1019. /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this
  1020. /// does not necessarily apply to truncate instructions. e.g. on x86-64,
  1021. /// all instructions that define 32-bit values implicit zero-extend the
  1022. /// result out to 64 bits.
  1023. bool isZExtFree(Type *Ty1, Type *Ty2) const override;
  1024. bool isZExtFree(EVT VT1, EVT VT2) const override;
  1025. bool isZExtFree(SDValue Val, EVT VT2) const override;
  1026. bool shouldSinkOperands(Instruction *I,
  1027. SmallVectorImpl<Use *> &Ops) const override;
  1028. bool shouldConvertPhiType(Type *From, Type *To) const override;
  1029. /// Return true if folding a vector load into ExtVal (a sign, zero, or any
  1030. /// extend node) is profitable.
  1031. bool isVectorLoadExtDesirable(SDValue) const override;
  1032. /// Return true if an FMA operation is faster than a pair of fmul and fadd
  1033. /// instructions. fmuladd intrinsics will be expanded to FMAs when this
  1034. /// method returns true, otherwise fmuladd is expanded to fmul + fadd.
  1035. bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
  1036. EVT VT) const override;
  1037. /// Return true if it's profitable to narrow
  1038. /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow
  1039. /// from i32 to i8 but not from i32 to i16.
  1040. bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
  1041. bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode,
  1042. EVT VT) const override;
  1043. /// Given an intrinsic, checks if on the target the intrinsic will need to map
  1044. /// to a MemIntrinsicNode (touches memory). If this is the case, it returns
  1045. /// true and stores the intrinsic information into the IntrinsicInfo that was
  1046. /// passed to the function.
  1047. bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
  1048. MachineFunction &MF,
  1049. unsigned Intrinsic) const override;
  1050. /// Returns true if the target can instruction select the
  1051. /// specified FP immediate natively. If false, the legalizer will
  1052. /// materialize the FP immediate as a load from a constant pool.
  1053. bool isFPImmLegal(const APFloat &Imm, EVT VT,
  1054. bool ForCodeSize) const override;
  1055. /// Targets can use this to indicate that they only support *some*
  1056. /// VECTOR_SHUFFLE operations, those with specific masks. By default, if a
  1057. /// target supports the VECTOR_SHUFFLE node, all mask values are assumed to
  1058. /// be legal.
  1059. bool isShuffleMaskLegal(ArrayRef<int> Mask, EVT VT) const override;
  1060. /// Similar to isShuffleMaskLegal. Targets can use this to indicate if there
  1061. /// is a suitable VECTOR_SHUFFLE that can be used to replace a VAND with a
  1062. /// constant pool entry.
  1063. bool isVectorClearMaskLegal(ArrayRef<int> Mask, EVT VT) const override;
  1064. /// Returns true if lowering to a jump table is allowed.
  1065. bool areJTsAllowed(const Function *Fn) const override;
  1066. /// If true, then instruction selection should
  1067. /// seek to shrink the FP constant of the specified type to a smaller type
  1068. /// in order to save space and / or reduce runtime.
  1069. bool ShouldShrinkFPConstant(EVT VT) const override {
  1070. // Don't shrink FP constpool if SSE2 is available since cvtss2sd is more
  1071. // expensive than a straight movsd. On the other hand, it's important to
  1072. // shrink long double fp constant since fldt is very slow.
  1073. return !X86ScalarSSEf64 || VT == MVT::f80;
  1074. }
  1075. /// Return true if we believe it is correct and profitable to reduce the
  1076. /// load node to a smaller type.
  1077. bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy,
  1078. EVT NewVT) const override;
  1079. /// Return true if the specified scalar FP type is computed in an SSE
  1080. /// register, not on the X87 floating point stack.
  1081. bool isScalarFPTypeInSSEReg(EVT VT) const {
  1082. return (VT == MVT::f64 && X86ScalarSSEf64) || // f64 is when SSE2
  1083. (VT == MVT::f32 && X86ScalarSSEf32) || // f32 is when SSE1
  1084. (VT == MVT::f16 && X86ScalarSSEf16); // f16 is when AVX512FP16
  1085. }
  1086. /// Returns true if it is beneficial to convert a load of a constant
  1087. /// to just the constant itself.
  1088. bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
  1089. Type *Ty) const override;
  1090. bool reduceSelectOfFPConstantLoads(EVT CmpOpVT) const override;
  1091. bool convertSelectOfConstantsToMath(EVT VT) const override;
  1092. bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
  1093. SDValue C) const override;
  1094. /// Return true if EXTRACT_SUBVECTOR is cheap for this result type
  1095. /// with this index.
  1096. bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
  1097. unsigned Index) const override;
  1098. /// Scalar ops always have equal or better analysis/performance/power than
  1099. /// the vector equivalent, so this always makes sense if the scalar op is
  1100. /// supported.
  1101. bool shouldScalarizeBinop(SDValue) const override;
  1102. /// Extract of a scalar FP value from index 0 of a vector is free.
  1103. bool isExtractVecEltCheap(EVT VT, unsigned Index) const override {
  1104. EVT EltVT = VT.getScalarType();
  1105. return (EltVT == MVT::f32 || EltVT == MVT::f64) && Index == 0;
  1106. }
  1107. /// Overflow nodes should get combined/lowered to optimal instructions
  1108. /// (they should allow eliminating explicit compares by getting flags from
  1109. /// math ops).
  1110. bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
  1111. bool MathUsed) const override;
  1112. bool storeOfVectorConstantIsCheap(EVT MemVT, unsigned NumElem,
  1113. unsigned AddrSpace) const override {
  1114. // If we can replace more than 2 scalar stores, there will be a reduction
  1115. // in instructions even after we add a vector constant load.
  1116. return NumElem > 2;
  1117. }
  1118. bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT,
  1119. const SelectionDAG &DAG,
  1120. const MachineMemOperand &MMO) const override;
  1121. /// Intel processors have a unified instruction and data cache
  1122. const char * getClearCacheBuiltinName() const override {
  1123. return nullptr; // nothing to do, move along.
  1124. }
  1125. Register getRegisterByName(const char* RegName, LLT VT,
  1126. const MachineFunction &MF) const override;
  1127. /// If a physical register, this returns the register that receives the
  1128. /// exception address on entry to an EH pad.
  1129. Register
  1130. getExceptionPointerRegister(const Constant *PersonalityFn) const override;
  1131. /// If a physical register, this returns the register that receives the
  1132. /// exception typeid on entry to a landing pad.
  1133. Register
  1134. getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
  1135. virtual bool needsFixedCatchObjects() const override;
  1136. /// This method returns a target specific FastISel object,
  1137. /// or null if the target does not support "fast" ISel.
  1138. FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
  1139. const TargetLibraryInfo *libInfo) const override;
  1140. /// If the target has a standard location for the stack protector cookie,
  1141. /// returns the address of that location. Otherwise, returns nullptr.
  1142. Value *getIRStackGuard(IRBuilderBase &IRB) const override;
  1143. bool useLoadStackGuardNode() const override;
  1144. bool useStackGuardXorFP() const override;
  1145. void insertSSPDeclarations(Module &M) const override;
  1146. Value *getSDagStackGuard(const Module &M) const override;
  1147. Function *getSSPStackGuardCheck(const Module &M) const override;
  1148. SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val,
  1149. const SDLoc &DL) const override;
  1150. /// Return true if the target stores SafeStack pointer at a fixed offset in
  1151. /// some non-standard address space, and populates the address space and
  1152. /// offset as appropriate.
  1153. Value *getSafeStackPointerLocation(IRBuilderBase &IRB) const override;
  1154. std::pair<SDValue, SDValue> BuildFILD(EVT DstVT, EVT SrcVT, const SDLoc &DL,
  1155. SDValue Chain, SDValue Pointer,
  1156. MachinePointerInfo PtrInfo,
  1157. Align Alignment,
  1158. SelectionDAG &DAG) const;
  1159. /// Customize the preferred legalization strategy for certain types.
  1160. LegalizeTypeAction getPreferredVectorAction(MVT VT) const override;
  1161. bool softPromoteHalfType() const override { return true; }
  1162. MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
  1163. EVT VT) const override;
  1164. unsigned getNumRegistersForCallingConv(LLVMContext &Context,
  1165. CallingConv::ID CC,
  1166. EVT VT) const override;
  1167. unsigned getVectorTypeBreakdownForCallingConv(
  1168. LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
  1169. unsigned &NumIntermediates, MVT &RegisterVT) const override;
  1170. bool isIntDivCheap(EVT VT, AttributeList Attr) const override;
  1171. bool supportSwiftError() const override;
  1172. bool hasStackProbeSymbol(MachineFunction &MF) const override;
  1173. bool hasInlineStackProbe(MachineFunction &MF) const override;
  1174. StringRef getStackProbeSymbolName(MachineFunction &MF) const override;
  1175. unsigned getStackProbeSize(MachineFunction &MF) const;
  1176. bool hasVectorBlend() const override { return true; }
  1177. unsigned getMaxSupportedInterleaveFactor() const override { return 4; }
  1178. /// Lower interleaved load(s) into target specific
  1179. /// instructions/intrinsics.
  1180. bool lowerInterleavedLoad(LoadInst *LI,
  1181. ArrayRef<ShuffleVectorInst *> Shuffles,
  1182. ArrayRef<unsigned> Indices,
  1183. unsigned Factor) const override;
  1184. /// Lower interleaved store(s) into target specific
  1185. /// instructions/intrinsics.
  1186. bool lowerInterleavedStore(StoreInst *SI, ShuffleVectorInst *SVI,
  1187. unsigned Factor) const override;
  1188. SDValue expandIndirectJTBranch(const SDLoc& dl, SDValue Value,
  1189. SDValue Addr, SelectionDAG &DAG)
  1190. const override;
  1191. Align getPrefLoopAlignment(MachineLoop *ML) const override;
  1192. protected:
  1193. std::pair<const TargetRegisterClass *, uint8_t>
  1194. findRepresentativeClass(const TargetRegisterInfo *TRI,
  1195. MVT VT) const override;
  1196. private:
  1197. /// Keep a reference to the X86Subtarget around so that we can
  1198. /// make the right decision when generating code for different targets.
  1199. const X86Subtarget &Subtarget;
  1200. /// Select between SSE or x87 floating point ops.
  1201. /// When SSE is available, use it for f32 operations.
  1202. /// When SSE2 is available, use it for f64 operations.
  1203. bool X86ScalarSSEf32;
  1204. bool X86ScalarSSEf64;
  1205. bool X86ScalarSSEf16;
  1206. /// A list of legal FP immediates.
  1207. std::vector<APFloat> LegalFPImmediates;
  1208. /// Indicate that this x86 target can instruction
  1209. /// select the specified FP immediate natively.
  1210. void addLegalFPImmediate(const APFloat& Imm) {
  1211. LegalFPImmediates.push_back(Imm);
  1212. }
  1213. SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
  1214. CallingConv::ID CallConv, bool isVarArg,
  1215. const SmallVectorImpl<ISD::InputArg> &Ins,
  1216. const SDLoc &dl, SelectionDAG &DAG,
  1217. SmallVectorImpl<SDValue> &InVals,
  1218. uint32_t *RegMask) const;
  1219. SDValue LowerMemArgument(SDValue Chain, CallingConv::ID CallConv,
  1220. const SmallVectorImpl<ISD::InputArg> &ArgInfo,
  1221. const SDLoc &dl, SelectionDAG &DAG,
  1222. const CCValAssign &VA, MachineFrameInfo &MFI,
  1223. unsigned i) const;
  1224. SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
  1225. const SDLoc &dl, SelectionDAG &DAG,
  1226. const CCValAssign &VA,
  1227. ISD::ArgFlagsTy Flags, bool isByval) const;
  1228. // Call lowering helpers.
  1229. /// Check whether the call is eligible for tail call optimization. Targets
  1230. /// that want to do tail call optimization should implement this function.
  1231. bool IsEligibleForTailCallOptimization(
  1232. SDValue Callee, CallingConv::ID CalleeCC, bool IsCalleeStackStructRet,
  1233. bool isVarArg, Type *RetTy, const SmallVectorImpl<ISD::OutputArg> &Outs,
  1234. const SmallVectorImpl<SDValue> &OutVals,
  1235. const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
  1236. SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,
  1237. SDValue Chain, bool IsTailCall,
  1238. bool Is64Bit, int FPDiff,
  1239. const SDLoc &dl) const;
  1240. unsigned GetAlignedArgumentStackSize(unsigned StackSize,
  1241. SelectionDAG &DAG) const;
  1242. unsigned getAddressSpace() const;
  1243. SDValue FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG, bool IsSigned,
  1244. SDValue &Chain) const;
  1245. SDValue LRINT_LLRINTHelper(SDNode *N, SelectionDAG &DAG) const;
  1246. SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
  1247. SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const;
  1248. SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
  1249. SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
  1250. unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
  1251. const unsigned char OpFlags = 0) const;
  1252. SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
  1253. SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
  1254. SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
  1255. SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
  1256. SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
  1257. /// Creates target global address or external symbol nodes for calls or
  1258. /// other uses.
  1259. SDValue LowerGlobalOrExternal(SDValue Op, SelectionDAG &DAG,
  1260. bool ForCall) const;
  1261. SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
  1262. SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
  1263. SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
  1264. SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
  1265. SDValue LowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG) const;
  1266. SDValue LowerLRINT_LLRINT(SDValue Op, SelectionDAG &DAG) const;
  1267. SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
  1268. SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG) const;
  1269. SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
  1270. SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
  1271. SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
  1272. SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
  1273. SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
  1274. SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
  1275. SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
  1276. SDValue LowerADDROFRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
  1277. SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
  1278. SDValue LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG) const;
  1279. SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const;
  1280. SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
  1281. SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
  1282. SDValue lowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const;
  1283. SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
  1284. SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
  1285. SDValue LowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
  1286. SDValue LowerWin64_i128OP(SDValue Op, SelectionDAG &DAG) const;
  1287. SDValue LowerWin64_FP_TO_INT128(SDValue Op, SelectionDAG &DAG,
  1288. SDValue &Chain) const;
  1289. SDValue LowerWin64_INT128_TO_FP(SDValue Op, SelectionDAG &DAG) const;
  1290. SDValue LowerGC_TRANSITION(SDValue Op, SelectionDAG &DAG) const;
  1291. SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
  1292. SDValue lowerFaddFsub(SDValue Op, SelectionDAG &DAG) const;
  1293. SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
  1294. SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
  1295. SDValue
  1296. LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  1297. const SmallVectorImpl<ISD::InputArg> &Ins,
  1298. const SDLoc &dl, SelectionDAG &DAG,
  1299. SmallVectorImpl<SDValue> &InVals) const override;
  1300. SDValue LowerCall(CallLoweringInfo &CLI,
  1301. SmallVectorImpl<SDValue> &InVals) const override;
  1302. SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
  1303. const SmallVectorImpl<ISD::OutputArg> &Outs,
  1304. const SmallVectorImpl<SDValue> &OutVals,
  1305. const SDLoc &dl, SelectionDAG &DAG) const override;
  1306. bool supportSplitCSR(MachineFunction *MF) const override {
  1307. return MF->getFunction().getCallingConv() == CallingConv::CXX_FAST_TLS &&
  1308. MF->getFunction().hasFnAttribute(Attribute::NoUnwind);
  1309. }
  1310. void initializeSplitCSR(MachineBasicBlock *Entry) const override;
  1311. void insertCopiesSplitCSR(
  1312. MachineBasicBlock *Entry,
  1313. const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;
  1314. bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
  1315. bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
  1316. EVT getTypeForExtReturn(LLVMContext &Context, EVT VT,
  1317. ISD::NodeType ExtendKind) const override;
  1318. bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
  1319. bool isVarArg,
  1320. const SmallVectorImpl<ISD::OutputArg> &Outs,
  1321. LLVMContext &Context) const override;
  1322. const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
  1323. TargetLoweringBase::AtomicExpansionKind
  1324. shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
  1325. bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
  1326. TargetLoweringBase::AtomicExpansionKind
  1327. shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
  1328. LoadInst *
  1329. lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const override;
  1330. bool lowerAtomicStoreAsStoreSDNode(const StoreInst &SI) const override;
  1331. bool lowerAtomicLoadAsLoadSDNode(const LoadInst &LI) const override;
  1332. bool needsCmpXchgNb(Type *MemType) const;
  1333. void SetupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB,
  1334. MachineBasicBlock *DispatchBB, int FI) const;
  1335. // Utility function to emit the low-level va_arg code for X86-64.
  1336. MachineBasicBlock *
  1337. EmitVAARGWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const;
  1338. /// Utility function to emit the xmm reg save portion of va_start.
  1339. MachineBasicBlock *EmitLoweredCascadedSelect(MachineInstr &MI1,
  1340. MachineInstr &MI2,
  1341. MachineBasicBlock *BB) const;
  1342. MachineBasicBlock *EmitLoweredSelect(MachineInstr &I,
  1343. MachineBasicBlock *BB) const;
  1344. MachineBasicBlock *EmitLoweredCatchRet(MachineInstr &MI,
  1345. MachineBasicBlock *BB) const;
  1346. MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr &MI,
  1347. MachineBasicBlock *BB) const;
  1348. MachineBasicBlock *EmitLoweredProbedAlloca(MachineInstr &MI,
  1349. MachineBasicBlock *BB) const;
  1350. MachineBasicBlock *EmitLoweredTLSAddr(MachineInstr &MI,
  1351. MachineBasicBlock *BB) const;
  1352. MachineBasicBlock *EmitLoweredTLSCall(MachineInstr &MI,
  1353. MachineBasicBlock *BB) const;
  1354. MachineBasicBlock *EmitLoweredIndirectThunk(MachineInstr &MI,
  1355. MachineBasicBlock *BB) const;
  1356. MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
  1357. MachineBasicBlock *MBB) const;
  1358. void emitSetJmpShadowStackFix(MachineInstr &MI,
  1359. MachineBasicBlock *MBB) const;
  1360. MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
  1361. MachineBasicBlock *MBB) const;
  1362. MachineBasicBlock *emitLongJmpShadowStackFix(MachineInstr &MI,
  1363. MachineBasicBlock *MBB) const;
  1364. MachineBasicBlock *EmitSjLjDispatchBlock(MachineInstr &MI,
  1365. MachineBasicBlock *MBB) const;
  1366. /// Emit flags for the given setcc condition and operands. Also returns the
  1367. /// corresponding X86 condition code constant in X86CC.
  1368. SDValue emitFlagsForSetcc(SDValue Op0, SDValue Op1, ISD::CondCode CC,
  1369. const SDLoc &dl, SelectionDAG &DAG,
  1370. SDValue &X86CC) const;
  1371. /// Check if replacement of SQRT with RSQRT should be disabled.
  1372. bool isFsqrtCheap(SDValue Op, SelectionDAG &DAG) const override;
  1373. /// Use rsqrt* to speed up sqrt calculations.
  1374. SDValue getSqrtEstimate(SDValue Op, SelectionDAG &DAG, int Enabled,
  1375. int &RefinementSteps, bool &UseOneConstNR,
  1376. bool Reciprocal) const override;
  1377. /// Use rcp* to speed up fdiv calculations.
  1378. SDValue getRecipEstimate(SDValue Op, SelectionDAG &DAG, int Enabled,
  1379. int &RefinementSteps) const override;
  1380. /// Reassociate floating point divisions into multiply by reciprocal.
  1381. unsigned combineRepeatedFPDivisors() const override;
  1382. SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
  1383. SmallVectorImpl<SDNode *> &Created) const override;
  1384. };
  1385. namespace X86 {
  1386. FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
  1387. const TargetLibraryInfo *libInfo);
  1388. } // end namespace X86
  1389. // X86 specific Gather/Scatter nodes.
  1390. // The class has the same order of operands as MaskedGatherScatterSDNode for
  1391. // convenience.
  1392. class X86MaskedGatherScatterSDNode : public MemIntrinsicSDNode {
  1393. public:
  1394. // This is a intended as a utility and should never be directly created.
  1395. X86MaskedGatherScatterSDNode() = delete;
  1396. ~X86MaskedGatherScatterSDNode() = delete;
  1397. const SDValue &getBasePtr() const { return getOperand(3); }
  1398. const SDValue &getIndex() const { return getOperand(4); }
  1399. const SDValue &getMask() const { return getOperand(2); }
  1400. const SDValue &getScale() const { return getOperand(5); }
  1401. static bool classof(const SDNode *N) {
  1402. return N->getOpcode() == X86ISD::MGATHER ||
  1403. N->getOpcode() == X86ISD::MSCATTER;
  1404. }
  1405. };
  1406. class X86MaskedGatherSDNode : public X86MaskedGatherScatterSDNode {
  1407. public:
  1408. const SDValue &getPassThru() const { return getOperand(1); }
  1409. static bool classof(const SDNode *N) {
  1410. return N->getOpcode() == X86ISD::MGATHER;
  1411. }
  1412. };
  1413. class X86MaskedScatterSDNode : public X86MaskedGatherScatterSDNode {
  1414. public:
  1415. const SDValue &getValue() const { return getOperand(1); }
  1416. static bool classof(const SDNode *N) {
  1417. return N->getOpcode() == X86ISD::MSCATTER;
  1418. }
  1419. };
  1420. /// Generate unpacklo/unpackhi shuffle mask.
  1421. void createUnpackShuffleMask(EVT VT, SmallVectorImpl<int> &Mask, bool Lo,
  1422. bool Unary);
  1423. /// Similar to unpacklo/unpackhi, but without the 128-bit lane limitation
  1424. /// imposed by AVX and specific to the unary pattern. Example:
  1425. /// v8iX Lo --> <0, 0, 1, 1, 2, 2, 3, 3>
  1426. /// v8iX Hi --> <4, 4, 5, 5, 6, 6, 7, 7>
  1427. void createSplat2ShuffleMask(MVT VT, SmallVectorImpl<int> &Mask, bool Lo);
  1428. } // end namespace llvm
  1429. #endif // LLVM_LIB_TARGET_X86_X86ISELLOWERING_H