IntrinsicsAMDGPU.td 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. //===- IntrinsicsAMDGPU.td - Defines AMDGPU intrinsics -----*- tablegen -*-===//
  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 all of the R600-specific intrinsics.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. class AMDGPUReadPreloadRegisterIntrinsic
  13. : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>;
  14. class AMDGPUReadPreloadRegisterIntrinsicNamed<string name>
  15. : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>, ClangBuiltin<name>;
  16. // Used to tag image and resource intrinsics with information used to generate
  17. // mem operands.
  18. class AMDGPURsrcIntrinsic<int rsrcarg, bit isimage = false> {
  19. int RsrcArg = rsrcarg;
  20. bit IsImage = isimage;
  21. }
  22. let TargetPrefix = "r600" in {
  23. multiclass AMDGPUReadPreloadRegisterIntrinsic_xyz {
  24. def _x : AMDGPUReadPreloadRegisterIntrinsic;
  25. def _y : AMDGPUReadPreloadRegisterIntrinsic;
  26. def _z : AMDGPUReadPreloadRegisterIntrinsic;
  27. }
  28. multiclass AMDGPUReadPreloadRegisterIntrinsic_xyz_named<string prefix> {
  29. def _x : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_x")>;
  30. def _y : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_y")>;
  31. def _z : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_z")>;
  32. }
  33. defm int_r600_read_global_size : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
  34. <"__builtin_r600_read_global_size">;
  35. defm int_r600_read_ngroups : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
  36. <"__builtin_r600_read_ngroups">;
  37. defm int_r600_read_tgid : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
  38. <"__builtin_r600_read_tgid">;
  39. defm int_r600_read_local_size : AMDGPUReadPreloadRegisterIntrinsic_xyz;
  40. defm int_r600_read_tidig : AMDGPUReadPreloadRegisterIntrinsic_xyz;
  41. def int_r600_group_barrier : ClangBuiltin<"__builtin_r600_group_barrier">,
  42. Intrinsic<[], [], [IntrConvergent, IntrWillReturn]>;
  43. // AS 7 is PARAM_I_ADDRESS, used for kernel arguments
  44. def int_r600_implicitarg_ptr :
  45. ClangBuiltin<"__builtin_r600_implicitarg_ptr">,
  46. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 7>], [],
  47. [IntrNoMem, IntrSpeculatable]>;
  48. def int_r600_rat_store_typed :
  49. // 1st parameter: Data
  50. // 2nd parameter: Index
  51. // 3rd parameter: Constant RAT ID
  52. DefaultAttrsIntrinsic<[], [llvm_v4i32_ty, llvm_v4i32_ty, llvm_i32_ty], []>,
  53. ClangBuiltin<"__builtin_r600_rat_store_typed">;
  54. def int_r600_recipsqrt_ieee : DefaultAttrsIntrinsic<
  55. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  56. >;
  57. def int_r600_recipsqrt_clamped : DefaultAttrsIntrinsic<
  58. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  59. >;
  60. def int_r600_cube : DefaultAttrsIntrinsic<
  61. [llvm_v4f32_ty], [llvm_v4f32_ty], [IntrNoMem, IntrSpeculatable]
  62. >;
  63. def int_r600_store_stream_output : DefaultAttrsIntrinsic<
  64. [], [llvm_v4f32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], []
  65. >;
  66. class TextureIntrinsicFloatInput : DefaultAttrsIntrinsic<[llvm_v4f32_ty], [
  67. llvm_v4f32_ty, // Coord
  68. llvm_i32_ty, // offset_x
  69. llvm_i32_ty, // offset_y,
  70. llvm_i32_ty, // offset_z,
  71. llvm_i32_ty, // resource_id
  72. llvm_i32_ty, // samplerid
  73. llvm_i32_ty, // coord_type_x
  74. llvm_i32_ty, // coord_type_y
  75. llvm_i32_ty, // coord_type_z
  76. llvm_i32_ty], // coord_type_w
  77. [IntrNoMem]
  78. >;
  79. class TextureIntrinsicInt32Input : DefaultAttrsIntrinsic<[llvm_v4i32_ty], [
  80. llvm_v4i32_ty, // Coord
  81. llvm_i32_ty, // offset_x
  82. llvm_i32_ty, // offset_y,
  83. llvm_i32_ty, // offset_z,
  84. llvm_i32_ty, // resource_id
  85. llvm_i32_ty, // samplerid
  86. llvm_i32_ty, // coord_type_x
  87. llvm_i32_ty, // coord_type_y
  88. llvm_i32_ty, // coord_type_z
  89. llvm_i32_ty], // coord_type_w
  90. [IntrNoMem]
  91. >;
  92. def int_r600_store_swizzle :
  93. Intrinsic<[], [llvm_v4f32_ty, llvm_i32_ty, llvm_i32_ty], [IntrWillReturn, IntrNoCallback, IntrNoFree]
  94. >;
  95. def int_r600_tex : TextureIntrinsicFloatInput;
  96. def int_r600_texc : TextureIntrinsicFloatInput;
  97. def int_r600_txl : TextureIntrinsicFloatInput;
  98. def int_r600_txlc : TextureIntrinsicFloatInput;
  99. def int_r600_txb : TextureIntrinsicFloatInput;
  100. def int_r600_txbc : TextureIntrinsicFloatInput;
  101. def int_r600_txf : TextureIntrinsicInt32Input;
  102. def int_r600_txq : TextureIntrinsicInt32Input;
  103. def int_r600_ddx : TextureIntrinsicFloatInput;
  104. def int_r600_ddy : TextureIntrinsicFloatInput;
  105. def int_r600_dot4 : DefaultAttrsIntrinsic<[llvm_float_ty],
  106. [llvm_v4f32_ty, llvm_v4f32_ty], [IntrNoMem, IntrSpeculatable]
  107. >;
  108. def int_r600_kill : DefaultAttrsIntrinsic<[], [llvm_float_ty], []>;
  109. } // End TargetPrefix = "r600"
  110. let TargetPrefix = "amdgcn" in {
  111. //===----------------------------------------------------------------------===//
  112. // ABI Special Intrinsics
  113. //===----------------------------------------------------------------------===//
  114. defm int_amdgcn_workitem_id : AMDGPUReadPreloadRegisterIntrinsic_xyz;
  115. defm int_amdgcn_workgroup_id : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
  116. <"__builtin_amdgcn_workgroup_id">;
  117. def int_amdgcn_dispatch_ptr :
  118. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
  119. [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable]>;
  120. def int_amdgcn_queue_ptr :
  121. ClangBuiltin<"__builtin_amdgcn_queue_ptr">,
  122. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
  123. [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable]>;
  124. def int_amdgcn_kernarg_segment_ptr :
  125. ClangBuiltin<"__builtin_amdgcn_kernarg_segment_ptr">,
  126. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
  127. [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable]>;
  128. def int_amdgcn_implicitarg_ptr :
  129. ClangBuiltin<"__builtin_amdgcn_implicitarg_ptr">,
  130. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
  131. [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable]>;
  132. def int_amdgcn_groupstaticsize :
  133. ClangBuiltin<"__builtin_amdgcn_groupstaticsize">,
  134. DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>;
  135. def int_amdgcn_dispatch_id :
  136. ClangBuiltin<"__builtin_amdgcn_dispatch_id">,
  137. DefaultAttrsIntrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrSpeculatable]>;
  138. // For internal use. Coordinates LDS lowering between IR transform and backend.
  139. def int_amdgcn_lds_kernel_id :
  140. DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>;
  141. def int_amdgcn_implicit_buffer_ptr :
  142. ClangBuiltin<"__builtin_amdgcn_implicit_buffer_ptr">,
  143. DefaultAttrsIntrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
  144. [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable]>;
  145. // Set EXEC to the 64-bit value given.
  146. // This is always moved to the beginning of the basic block.
  147. // FIXME: Should be mangled for wave size.
  148. def int_amdgcn_init_exec : Intrinsic<[],
  149. [llvm_i64_ty], // 64-bit literal constant
  150. [IntrConvergent, IntrNoMem, IntrHasSideEffects, IntrNoCallback,
  151. IntrNoFree, IntrWillReturn, ImmArg<ArgIndex<0>>]>;
  152. // Set EXEC according to a thread count packed in an SGPR input:
  153. // thread_count = (input >> bitoffset) & 0x7f;
  154. // This is always moved to the beginning of the basic block.
  155. // Note: only inreg arguments to the parent function are valid as
  156. // inputs to this intrinsic, computed values cannot be used.
  157. def int_amdgcn_init_exec_from_input : Intrinsic<[],
  158. [llvm_i32_ty, // 32-bit SGPR input
  159. llvm_i32_ty], // bit offset of the thread count
  160. [IntrConvergent, IntrHasSideEffects, IntrNoMem, IntrNoCallback,
  161. IntrNoFree, IntrWillReturn, ImmArg<ArgIndex<1>>]>;
  162. def int_amdgcn_wavefrontsize :
  163. ClangBuiltin<"__builtin_amdgcn_wavefrontsize">,
  164. DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>;
  165. //===----------------------------------------------------------------------===//
  166. // Instruction Intrinsics
  167. //===----------------------------------------------------------------------===//
  168. // The first parameter is s_sendmsg immediate (i16),
  169. // the second one is copied to m0
  170. def int_amdgcn_s_sendmsg : ClangBuiltin<"__builtin_amdgcn_s_sendmsg">,
  171. Intrinsic <[], [llvm_i32_ty, llvm_i32_ty],
  172. [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
  173. def int_amdgcn_s_sendmsghalt : ClangBuiltin<"__builtin_amdgcn_s_sendmsghalt">,
  174. Intrinsic <[], [llvm_i32_ty, llvm_i32_ty],
  175. [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
  176. // gfx11 intrinsic
  177. // The first parameter is s_sendmsg immediate (i16). Return type is i32 or i64.
  178. def int_amdgcn_s_sendmsg_rtn : Intrinsic <[llvm_anyint_ty], [llvm_i32_ty],
  179. [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
  180. def int_amdgcn_s_barrier : ClangBuiltin<"__builtin_amdgcn_s_barrier">,
  181. Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  182. def int_amdgcn_wave_barrier : ClangBuiltin<"__builtin_amdgcn_wave_barrier">,
  183. Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  184. // The 1st parameter is a mask for the types of instructions that may be allowed
  185. // to cross the SCHED_BARRIER during scheduling.
  186. // MASK = 0x0000 0000: No instructions may be scheduled across SCHED_BARRIER.
  187. // MASK = 0x0000 0001: ALL, non-memory, non-side-effect producing instructions may be
  188. // scheduled across SCHED_BARRIER, i.e. allow ALU instructions to pass.
  189. // MASK = 0x0000 0002: VALU instructions may be scheduled across SCHED_BARRIER.
  190. // MASK = 0x0000 0004: SALU instructions may be scheduled across SCHED_BARRIER.
  191. // MASK = 0x0000 0008: MFMA/WMMA instructions may be scheduled across SCHED_BARRIER.
  192. // MASK = 0x0000 0010: ALL VMEM instructions may be scheduled across SCHED_BARRIER.
  193. // MASK = 0x0000 0020: VMEM read instructions may be scheduled across SCHED_BARRIER.
  194. // MASK = 0x0000 0040: VMEM write instructions may be scheduled across SCHED_BARRIER.
  195. // MASK = 0x0000 0080: ALL DS instructions may be scheduled across SCHED_BARRIER.
  196. // MASK = 0x0000 0100: ALL DS read instructions may be scheduled accoss SCHED_BARRIER.
  197. // MASK = 0x0000 0200: ALL DS write instructions may be scheduled across SCHED_BARRIER.
  198. def int_amdgcn_sched_barrier : ClangBuiltin<"__builtin_amdgcn_sched_barrier">,
  199. Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrConvergent,
  200. IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  201. // The first parameter is a mask that determines the types of instructions that
  202. // you would like to synchronize around and add to a scheduling group. The
  203. // values of the mask are defined above for sched_barrier. These instructions
  204. // will be selected from the bottom up starting from the sched_group_barrier's
  205. // location during instruction scheduling. The second parameter is the number of
  206. // matching instructions that will be associated with this sched_group_barrier.
  207. // The third parameter is an identifier which is used to describe what other
  208. // sched_group_barriers should be synchronized with.
  209. def int_amdgcn_sched_group_barrier : ClangBuiltin<"__builtin_amdgcn_sched_group_barrier">,
  210. Intrinsic<[], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  211. [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, IntrNoMem, IntrHasSideEffects,
  212. IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  213. // Scheduler optimization hint.
  214. // MASK = 0: Small gemm opt
  215. def int_amdgcn_iglp_opt : ClangBuiltin<"__builtin_amdgcn_iglp_opt">,
  216. Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrConvergent,
  217. IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  218. def int_amdgcn_s_waitcnt : ClangBuiltin<"__builtin_amdgcn_s_waitcnt">,
  219. Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  220. def int_amdgcn_div_scale : DefaultAttrsIntrinsic<
  221. // 1st parameter: Numerator
  222. // 2nd parameter: Denominator
  223. // 3rd parameter: Select quotient. Must equal Numerator or Denominator.
  224. // (0 = Denominator, 1 = Numerator).
  225. [llvm_anyfloat_ty, llvm_i1_ty],
  226. [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i1_ty],
  227. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>]
  228. >;
  229. def int_amdgcn_div_fmas : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
  230. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>, llvm_i1_ty],
  231. [IntrNoMem, IntrSpeculatable]
  232. >;
  233. def int_amdgcn_div_fixup : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
  234. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  235. [IntrNoMem, IntrSpeculatable]
  236. >;
  237. // Look Up 2.0 / pi src0 with segment select src1[4:0]
  238. def int_amdgcn_trig_preop : DefaultAttrsIntrinsic<
  239. [llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty],
  240. [IntrNoMem, IntrSpeculatable]
  241. >;
  242. def int_amdgcn_sin : DefaultAttrsIntrinsic<
  243. [llvm_anyfloat_ty], [LLVMMatchType<0>],
  244. [IntrNoMem, IntrSpeculatable]
  245. >;
  246. def int_amdgcn_cos : DefaultAttrsIntrinsic<
  247. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  248. >;
  249. def int_amdgcn_log_clamp : DefaultAttrsIntrinsic<
  250. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  251. >;
  252. def int_amdgcn_fmul_legacy : ClangBuiltin<"__builtin_amdgcn_fmul_legacy">,
  253. DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty, llvm_float_ty],
  254. [IntrNoMem, IntrSpeculatable, Commutative]
  255. >;
  256. // Fused single-precision multiply-add with legacy behaviour for the multiply,
  257. // which is that +/- 0.0 * anything (even NaN or infinity) is +0.0. This is
  258. // intended for use on subtargets that have the v_fma_legacy_f32 and/or
  259. // v_fmac_legacy_f32 instructions. (Note that v_fma_legacy_f16 is unrelated and
  260. // has a completely different kind of legacy behaviour.)
  261. def int_amdgcn_fma_legacy :
  262. DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  263. [IntrNoMem, IntrSpeculatable, Commutative]
  264. >;
  265. def int_amdgcn_rcp : DefaultAttrsIntrinsic<
  266. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  267. >;
  268. def int_amdgcn_rcp_legacy : ClangBuiltin<"__builtin_amdgcn_rcp_legacy">,
  269. DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty],
  270. [IntrNoMem, IntrSpeculatable]
  271. >;
  272. def int_amdgcn_sqrt : DefaultAttrsIntrinsic<
  273. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  274. >;
  275. def int_amdgcn_rsq : DefaultAttrsIntrinsic<
  276. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  277. >;
  278. def int_amdgcn_rsq_legacy : ClangBuiltin<"__builtin_amdgcn_rsq_legacy">,
  279. DefaultAttrsIntrinsic<
  280. [llvm_float_ty], [llvm_float_ty], [IntrNoMem, IntrSpeculatable]
  281. >;
  282. // out = 1.0 / sqrt(a) result clamped to +/- max_float.
  283. def int_amdgcn_rsq_clamp : DefaultAttrsIntrinsic<
  284. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]>;
  285. // For int_amdgcn_ldexp_f16, only the low 16 bits of the i32 src1 operand will used.
  286. def int_amdgcn_ldexp : DefaultAttrsIntrinsic<
  287. [llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty],
  288. [IntrNoMem, IntrSpeculatable]
  289. >;
  290. def int_amdgcn_frexp_mant : DefaultAttrsIntrinsic<
  291. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  292. >;
  293. def int_amdgcn_frexp_exp : DefaultAttrsIntrinsic<
  294. [llvm_anyint_ty], [llvm_anyfloat_ty], [IntrNoMem, IntrSpeculatable]
  295. >;
  296. // v_fract is buggy on SI/CI. It mishandles infinities, may return 1.0
  297. // and always uses rtz, so is not suitable for implementing the OpenCL
  298. // fract function. It should be ok on VI.
  299. def int_amdgcn_fract : DefaultAttrsIntrinsic<
  300. [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]
  301. >;
  302. def int_amdgcn_cvt_pkrtz : ClangBuiltin<"__builtin_amdgcn_cvt_pkrtz">,
  303. DefaultAttrsIntrinsic<[llvm_v2f16_ty], [llvm_float_ty, llvm_float_ty],
  304. [IntrNoMem, IntrSpeculatable]
  305. >;
  306. def int_amdgcn_cvt_pknorm_i16 :
  307. ClangBuiltin<"__builtin_amdgcn_cvt_pknorm_i16">,
  308. DefaultAttrsIntrinsic<[llvm_v2i16_ty], [llvm_float_ty, llvm_float_ty],
  309. [IntrNoMem, IntrSpeculatable]
  310. >;
  311. def int_amdgcn_cvt_pknorm_u16 :
  312. ClangBuiltin<"__builtin_amdgcn_cvt_pknorm_u16">,
  313. DefaultAttrsIntrinsic<[llvm_v2i16_ty], [llvm_float_ty, llvm_float_ty],
  314. [IntrNoMem, IntrSpeculatable]
  315. >;
  316. def int_amdgcn_cvt_pk_i16 :
  317. ClangBuiltin<"__builtin_amdgcn_cvt_pk_i16">,
  318. DefaultAttrsIntrinsic<
  319. [llvm_v2i16_ty], [llvm_i32_ty, llvm_i32_ty],
  320. [IntrNoMem, IntrSpeculatable]
  321. >;
  322. def int_amdgcn_cvt_pk_u16 : ClangBuiltin<"__builtin_amdgcn_cvt_pk_u16">,
  323. DefaultAttrsIntrinsic<[llvm_v2i16_ty], [llvm_i32_ty, llvm_i32_ty],
  324. [IntrNoMem, IntrSpeculatable]
  325. >;
  326. def int_amdgcn_class : DefaultAttrsIntrinsic<
  327. [llvm_i1_ty], [llvm_anyfloat_ty, llvm_i32_ty],
  328. [IntrNoMem, IntrSpeculatable]
  329. >;
  330. def int_amdgcn_fmed3 : ClangBuiltin<"__builtin_amdgcn_fmed3">,
  331. DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
  332. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  333. [IntrNoMem, IntrSpeculatable]
  334. >;
  335. def int_amdgcn_cubeid : ClangBuiltin<"__builtin_amdgcn_cubeid">,
  336. DefaultAttrsIntrinsic<[llvm_float_ty],
  337. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  338. [IntrNoMem, IntrSpeculatable]
  339. >;
  340. def int_amdgcn_cubema : ClangBuiltin<"__builtin_amdgcn_cubema">,
  341. DefaultAttrsIntrinsic<[llvm_float_ty],
  342. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  343. [IntrNoMem, IntrSpeculatable]
  344. >;
  345. def int_amdgcn_cubesc : ClangBuiltin<"__builtin_amdgcn_cubesc">,
  346. DefaultAttrsIntrinsic<[llvm_float_ty],
  347. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  348. [IntrNoMem, IntrSpeculatable]
  349. >;
  350. def int_amdgcn_cubetc : ClangBuiltin<"__builtin_amdgcn_cubetc">,
  351. DefaultAttrsIntrinsic<[llvm_float_ty],
  352. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  353. [IntrNoMem, IntrSpeculatable]
  354. >;
  355. // v_ffbh_i32, as opposed to v_ffbh_u32. For v_ffbh_u32, llvm.ctlz
  356. // should be used.
  357. def int_amdgcn_sffbh :
  358. DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>],
  359. [IntrNoMem, IntrSpeculatable]
  360. >;
  361. // v_mad_f32|f16/v_mac_f32|f16, selected regardless of denorm support.
  362. def int_amdgcn_fmad_ftz :
  363. DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
  364. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  365. [IntrNoMem, IntrSpeculatable]
  366. >;
  367. // Fields should mirror atomicrmw
  368. class AMDGPUAtomicIncIntrin : Intrinsic<[llvm_anyint_ty],
  369. [llvm_anyptr_ty,
  370. LLVMMatchType<0>,
  371. llvm_i32_ty, // ordering
  372. llvm_i32_ty, // scope
  373. llvm_i1_ty], // isVolatile
  374. [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>,
  375. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, IntrNoCallback, IntrNoFree], "",
  376. [SDNPMemOperand]
  377. >;
  378. def int_amdgcn_atomic_inc : AMDGPUAtomicIncIntrin;
  379. def int_amdgcn_atomic_dec : AMDGPUAtomicIncIntrin;
  380. class AMDGPULDSIntrin :
  381. Intrinsic<[llvm_any_ty],
  382. [LLVMQualPointerType<LLVMMatchType<0>, 3>,
  383. LLVMMatchType<0>,
  384. llvm_i32_ty, // ordering
  385. llvm_i32_ty, // scope
  386. llvm_i1_ty], // isVolatile
  387. [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>,
  388. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, IntrNoCallback, IntrNoFree]
  389. >;
  390. // FIXME: The m0 argument should be moved after the normal arguments
  391. class AMDGPUDSOrderedIntrinsic : Intrinsic<
  392. [llvm_i32_ty],
  393. // M0 = {hi16:address, lo16:waveID}. Allow passing M0 as a pointer, so that
  394. // the bit packing can be optimized at the IR level.
  395. [LLVMQualPointerType<llvm_i32_ty, 2>, // IntToPtr(M0)
  396. llvm_i32_ty, // value to add or swap
  397. llvm_i32_ty, // ordering
  398. llvm_i32_ty, // scope
  399. llvm_i1_ty, // isVolatile
  400. llvm_i32_ty, // ordered count index (OA index), also added to the address
  401. // gfx10: bits 24-27 indicate the number of active threads/dwords
  402. llvm_i1_ty, // wave release, usually set to 1
  403. llvm_i1_ty], // wave done, set to 1 for the last ordered instruction
  404. [IntrWillReturn, NoCapture<ArgIndex<0>>,
  405. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>,
  406. ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>, ImmArg<ArgIndex<7>>, IntrNoCallback, IntrNoFree
  407. ]
  408. >;
  409. class AMDGPUDSAppendConsumedIntrinsic : Intrinsic<
  410. [llvm_i32_ty],
  411. [llvm_anyptr_ty, // LDS or GDS ptr
  412. llvm_i1_ty], // isVolatile
  413. [IntrConvergent, IntrWillReturn, IntrArgMemOnly,
  414. NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<1>>, IntrNoCallback, IntrNoFree],
  415. "",
  416. [SDNPMemOperand]
  417. >;
  418. def int_amdgcn_ds_ordered_add : AMDGPUDSOrderedIntrinsic;
  419. def int_amdgcn_ds_ordered_swap : AMDGPUDSOrderedIntrinsic;
  420. // The pointer argument is assumed to be dynamically uniform if a VGPR.
  421. def int_amdgcn_ds_append : AMDGPUDSAppendConsumedIntrinsic;
  422. def int_amdgcn_ds_consume : AMDGPUDSAppendConsumedIntrinsic;
  423. def int_amdgcn_ds_fadd : AMDGPULDSIntrin;
  424. def int_amdgcn_ds_fmin : AMDGPULDSIntrin;
  425. def int_amdgcn_ds_fmax : AMDGPULDSIntrin;
  426. } // TargetPrefix = "amdgcn"
  427. // New-style image intrinsics
  428. //////////////////////////////////////////////////////////////////////////
  429. // Dimension-aware image intrinsics framework
  430. //////////////////////////////////////////////////////////////////////////
  431. // Helper class to represent (type, name) combinations of arguments. The
  432. // argument names are explanatory and used as DAG operand names for codegen
  433. // pattern matching.
  434. class AMDGPUArg<LLVMType ty, string name> {
  435. LLVMType Type = ty;
  436. string Name = name;
  437. }
  438. // Return [AMDGPUArg<basety, names[0]>, AMDGPUArg<LLVMMatchType<0>, names[1]>, ...]
  439. class makeArgList<list<string> names, LLVMType basety> {
  440. list<AMDGPUArg> ret =
  441. !listconcat([AMDGPUArg<basety, names[0]>],
  442. !foreach(name, !tail(names), AMDGPUArg<LLVMMatchType<0>, name>));
  443. }
  444. // Return arglist, with LLVMMatchType's references shifted by 'shift'.
  445. class arglistmatchshift<list<AMDGPUArg> arglist, int shift> {
  446. list<AMDGPUArg> ret =
  447. !foreach(arg, arglist,
  448. !if(!isa<LLVMMatchType>(arg.Type),
  449. AMDGPUArg<LLVMMatchType<!add(!cast<LLVMMatchType>(arg.Type).Number, shift)>,
  450. arg.Name>,
  451. arg));
  452. }
  453. // Return the concatenation of the given arglists. LLVMMatchType's are adjusted
  454. // accordingly, and shifted by an additional 'shift'.
  455. class arglistconcat<list<list<AMDGPUArg>> arglists, int shift = 0> {
  456. list<AMDGPUArg> ret =
  457. !foldl([]<AMDGPUArg>, arglists, lhs, rhs,
  458. !listconcat(
  459. lhs,
  460. arglistmatchshift<rhs,
  461. !add(shift, !foldl(0, lhs, a, b,
  462. !add(a, b.Type.isAny)))>.ret));
  463. }
  464. // Represent texture/image types / dimensionality.
  465. class AMDGPUDimProps<bits<3> enc, string name, string asmsuffix,
  466. list<string> coord_names, list<string> slice_names,
  467. bit msaa = 0> {
  468. AMDGPUDimProps Dim = !cast<AMDGPUDimProps>(NAME);
  469. string Name = name; // e.g. "2darraymsaa"
  470. string AsmSuffix = asmsuffix; // e.g. 2D_MSAA_ARRAY (used in assembly strings)
  471. bits<3> Encoding = enc;
  472. bit DA = 0; // DA bit in MIMG encoding
  473. bit MSAA = msaa;
  474. list<AMDGPUArg> CoordSliceArgs =
  475. makeArgList<!listconcat(coord_names, slice_names), llvm_anyfloat_ty>.ret;
  476. list<AMDGPUArg> CoordSliceIntArgs =
  477. makeArgList<!listconcat(coord_names, slice_names), llvm_anyint_ty>.ret;
  478. list<AMDGPUArg> GradientArgs =
  479. makeArgList<!listconcat(!foreach(name, coord_names, "d" # name # "dh"),
  480. !foreach(name, coord_names, "d" # name # "dv")),
  481. llvm_anyfloat_ty>.ret;
  482. bits<8> NumCoords = !size(CoordSliceArgs);
  483. bits<8> NumGradients = !size(GradientArgs);
  484. }
  485. def AMDGPUDim1D : AMDGPUDimProps<0x0, "1d", "1D", ["s"], []>;
  486. def AMDGPUDim2D : AMDGPUDimProps<0x1, "2d", "2D", ["s", "t"], []>;
  487. def AMDGPUDim3D : AMDGPUDimProps<0x2, "3d", "3D", ["s", "t", "r"], []>;
  488. let DA = 1 in {
  489. def AMDGPUDimCube : AMDGPUDimProps<0x3, "cube", "CUBE", ["s", "t"], ["face"]>;
  490. def AMDGPUDim1DArray : AMDGPUDimProps<0x4, "1darray", "1D_ARRAY", ["s"], ["slice"]>;
  491. def AMDGPUDim2DArray : AMDGPUDimProps<0x5, "2darray", "2D_ARRAY", ["s", "t"], ["slice"]>;
  492. }
  493. def AMDGPUDim2DMsaa : AMDGPUDimProps<0x6, "2dmsaa", "2D_MSAA", ["s", "t"], ["fragid"], 1>;
  494. let DA = 1 in {
  495. def AMDGPUDim2DArrayMsaa : AMDGPUDimProps<0x7, "2darraymsaa", "2D_MSAA_ARRAY", ["s", "t"], ["slice", "fragid"], 1>;
  496. }
  497. def AMDGPUDims {
  498. list<AMDGPUDimProps> NoMsaa = [AMDGPUDim1D, AMDGPUDim2D, AMDGPUDim3D,
  499. AMDGPUDimCube, AMDGPUDim1DArray,
  500. AMDGPUDim2DArray];
  501. list<AMDGPUDimProps> Msaa = [AMDGPUDim2DMsaa, AMDGPUDim2DArrayMsaa];
  502. list<AMDGPUDimProps> All = !listconcat(NoMsaa, Msaa);
  503. }
  504. // Represent sample variants, i.e. _C, _O, _B, ... and combinations thereof.
  505. class AMDGPUSampleVariant<string ucmod, string lcmod, list<AMDGPUArg> extra_addr> {
  506. string UpperCaseMod = ucmod;
  507. string LowerCaseMod = lcmod;
  508. // {offset} {bias} {z-compare}
  509. list<AMDGPUArg> ExtraAddrArgs = extra_addr;
  510. bit Offset = false;
  511. bit Bias = false;
  512. bit ZCompare = false;
  513. bit Gradients = false;
  514. // Name of the {lod} or {clamp} argument that is appended to the coordinates,
  515. // if any.
  516. string LodOrClamp = "";
  517. }
  518. // AMDGPUSampleVariants: all variants supported by IMAGE_SAMPLE
  519. // AMDGPUSampleVariantsNoGradients: variants supported by IMAGE_GATHER4
  520. defset list<AMDGPUSampleVariant> AMDGPUSampleVariants = {
  521. multiclass AMDGPUSampleHelper_Offset<string ucmod, string lcmod,
  522. list<AMDGPUArg> extra_addr> {
  523. def NAME#lcmod : AMDGPUSampleVariant<ucmod, lcmod, extra_addr>;
  524. let Offset = true in
  525. def NAME#lcmod#_o : AMDGPUSampleVariant<
  526. ucmod#"_O", lcmod#"_o", !listconcat([AMDGPUArg<llvm_i32_ty, "offset">], extra_addr)>;
  527. }
  528. multiclass AMDGPUSampleHelper_Compare<string ucmod, string lcmod,
  529. list<AMDGPUArg> extra_addr> {
  530. defm NAME : AMDGPUSampleHelper_Offset<ucmod, lcmod, extra_addr>;
  531. let ZCompare = true in
  532. defm NAME : AMDGPUSampleHelper_Offset<
  533. "_C"#ucmod, "_c"#lcmod, !listconcat(extra_addr, [AMDGPUArg<llvm_float_ty, "zcompare">])>;
  534. }
  535. multiclass AMDGPUSampleHelper_Clamp<string ucmod, string lcmod,
  536. list<AMDGPUArg> extra_addr> {
  537. defm NAME : AMDGPUSampleHelper_Compare<ucmod, lcmod, extra_addr>;
  538. let LodOrClamp = "clamp" in
  539. defm NAME : AMDGPUSampleHelper_Compare<ucmod#"_CL", lcmod#"_cl", extra_addr>;
  540. }
  541. defset list<AMDGPUSampleVariant> AMDGPUSampleVariantsNoGradients = {
  542. defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"", "", []>;
  543. let Bias = true in
  544. defm AMDGPUSample : AMDGPUSampleHelper_Clamp<
  545. "_B", "_b", [AMDGPUArg<llvm_anyfloat_ty, "bias">]>;
  546. let LodOrClamp = "lod" in
  547. defm AMDGPUSample : AMDGPUSampleHelper_Compare<"_L", "_l", []>;
  548. defm AMDGPUSample : AMDGPUSampleHelper_Compare<"_LZ", "_lz", []>;
  549. }
  550. let Gradients = true in {
  551. defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"_D", "_d", []>;
  552. defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"_CD", "_cd", []>;
  553. }
  554. }
  555. // Helper class to capture the profile of a dimension-aware image intrinsic.
  556. // This information is used to generate the intrinsic's type and to inform
  557. // codegen pattern matching.
  558. class AMDGPUDimProfile<string opmod,
  559. AMDGPUDimProps dim> {
  560. AMDGPUDimProps Dim = dim;
  561. string OpMod = opmod; // the corresponding instruction is named IMAGE_OpMod
  562. // These are intended to be overwritten by subclasses
  563. bit IsSample = false;
  564. bit IsAtomic = false;
  565. list<LLVMType> RetTypes = [];
  566. list<AMDGPUArg> DataArgs = [];
  567. list<AMDGPUArg> ExtraAddrArgs = [];
  568. bit Offset = false;
  569. bit Bias = false;
  570. bit ZCompare = false;
  571. bit Gradients = false;
  572. string LodClampMip = "";
  573. int NumRetAndDataAnyTypes =
  574. !foldl(0, !listconcat(RetTypes, !foreach(arg, DataArgs, arg.Type)), a, b,
  575. !add(a, b.isAny));
  576. list<AMDGPUArg> AddrArgs =
  577. arglistconcat<[ExtraAddrArgs,
  578. !if(Gradients, dim.GradientArgs, []),
  579. !listconcat(!if(IsSample, dim.CoordSliceArgs, dim.CoordSliceIntArgs),
  580. !if(!empty(LodClampMip),
  581. []<AMDGPUArg>,
  582. [AMDGPUArg<LLVMMatchType<0>, LodClampMip>]))],
  583. NumRetAndDataAnyTypes>.ret;
  584. list<LLVMType> AddrTypes = !foreach(arg, AddrArgs, arg.Type);
  585. list<AMDGPUArg> AddrDefaultArgs =
  586. !foreach(arg, AddrArgs,
  587. AMDGPUArg<!if(!or(arg.Type.isAny, !isa<LLVMMatchType>(arg.Type)),
  588. !if(IsSample, llvm_float_ty, llvm_i32_ty), arg.Type),
  589. arg.Name>);
  590. list<AMDGPUArg> AddrA16Args =
  591. !foreach(arg, AddrArgs,
  592. AMDGPUArg<!if(!or(arg.Type.isAny, !isa<LLVMMatchType>(arg.Type)),
  593. !if(IsSample, llvm_half_ty, llvm_i16_ty), arg.Type),
  594. arg.Name>);
  595. }
  596. class AMDGPUDimProfileCopy<AMDGPUDimProfile base> : AMDGPUDimProfile<base.OpMod, base.Dim> {
  597. let IsSample = base.IsSample;
  598. let IsAtomic = base.IsAtomic;
  599. let RetTypes = base.RetTypes;
  600. let DataArgs = base.DataArgs;
  601. let ExtraAddrArgs = base.ExtraAddrArgs;
  602. let Offset = base.Offset;
  603. let Bias = base.Bias;
  604. let ZCompare = base.ZCompare;
  605. let Gradients = base.Gradients;
  606. let LodClampMip = base.LodClampMip;
  607. }
  608. class AMDGPUDimSampleProfile<string opmod,
  609. AMDGPUDimProps dim,
  610. AMDGPUSampleVariant sample> : AMDGPUDimProfile<opmod, dim> {
  611. let IsSample = true;
  612. let RetTypes = [llvm_any_ty];
  613. let ExtraAddrArgs = sample.ExtraAddrArgs;
  614. let Offset = sample.Offset;
  615. let Bias = sample.Bias;
  616. let ZCompare = sample.ZCompare;
  617. let Gradients = sample.Gradients;
  618. let LodClampMip = sample.LodOrClamp;
  619. }
  620. class AMDGPUDimNoSampleProfile<string opmod,
  621. AMDGPUDimProps dim,
  622. list<LLVMType> retty,
  623. list<AMDGPUArg> dataargs,
  624. bit Mip = false> : AMDGPUDimProfile<opmod, dim> {
  625. let RetTypes = retty;
  626. let DataArgs = dataargs;
  627. let LodClampMip = !if(Mip, "mip", "");
  628. }
  629. class AMDGPUDimAtomicProfile<string opmod,
  630. AMDGPUDimProps dim,
  631. list<AMDGPUArg> dataargs> : AMDGPUDimProfile<opmod, dim> {
  632. let RetTypes = [llvm_anyint_ty];
  633. let DataArgs = dataargs;
  634. let IsAtomic = true;
  635. }
  636. class AMDGPUDimAtomicFloatProfile<string opmod, AMDGPUDimProps dim,
  637. list<AMDGPUArg> dataargs>
  638. : AMDGPUDimAtomicProfile<opmod, dim, dataargs> {
  639. let RetTypes = [llvm_anyfloat_ty];
  640. }
  641. class AMDGPUDimGetResInfoProfile<AMDGPUDimProps dim>
  642. : AMDGPUDimProfile<"GET_RESINFO", dim> {
  643. let RetTypes = [llvm_anyfloat_ty];
  644. let DataArgs = [];
  645. let AddrArgs = [AMDGPUArg<llvm_anyint_ty, "mip">];
  646. let LodClampMip = "mip";
  647. }
  648. // Helper class for figuring out image intrinsic argument indexes.
  649. class AMDGPUImageDimIntrinsicEval<AMDGPUDimProfile P_> {
  650. int NumDataArgs = !size(P_.DataArgs);
  651. int NumDmaskArgs = !not(P_.IsAtomic);
  652. int NumOffsetArgs = !if(P_.Offset, 1, 0);
  653. int NumBiasArgs = !if(P_.Bias, 1, 0);
  654. int NumZCompareArgs = !if(P_.ZCompare, 1, 0);
  655. int NumExtraAddrArgs = !add(NumOffsetArgs, NumBiasArgs, NumZCompareArgs);
  656. int NumVAddrArgs = !size(P_.AddrArgs);
  657. int NumGradientArgs = !if(P_.Gradients, !size(P_.Dim.GradientArgs), 0);
  658. int NumCoordArgs = !if(P_.IsSample, !size(P_.Dim.CoordSliceArgs), !size(P_.Dim.CoordSliceIntArgs));
  659. int NumRSrcArgs = 1;
  660. int NumSampArgs = !if(P_.IsSample, 2, 0);
  661. int DmaskArgIndex = NumDataArgs;
  662. int VAddrArgIndex = !add(DmaskArgIndex, NumDmaskArgs);
  663. int OffsetArgIndex = VAddrArgIndex;
  664. int BiasArgIndex = !add(VAddrArgIndex, NumOffsetArgs);
  665. int ZCompareArgIndex = !add(BiasArgIndex, NumBiasArgs);
  666. int GradientArgIndex = !add(VAddrArgIndex, NumExtraAddrArgs);
  667. int CoordArgIndex = !add(GradientArgIndex, NumGradientArgs);
  668. int LodArgIndex = !add(VAddrArgIndex, NumVAddrArgs, -1);
  669. int MipArgIndex = LodArgIndex;
  670. int RsrcArgIndex = !add(VAddrArgIndex, NumVAddrArgs);
  671. int SampArgIndex = !add(RsrcArgIndex, NumRSrcArgs);
  672. int UnormArgIndex = !add(SampArgIndex, 1);
  673. int TexFailCtrlArgIndex = !add(SampArgIndex, NumSampArgs);
  674. int CachePolicyArgIndex = !add(TexFailCtrlArgIndex, 1);
  675. }
  676. // All dimension-aware intrinsics are derived from this class.
  677. class AMDGPUImageDimIntrinsic<AMDGPUDimProfile P_,
  678. list<IntrinsicProperty> props,
  679. list<SDNodeProperty> sdnodeprops> : DefaultAttrsIntrinsic<
  680. P_.RetTypes, // vdata(VGPR) -- for load/atomic-with-return
  681. !listconcat(
  682. !foreach(arg, P_.DataArgs, arg.Type), // vdata(VGPR) -- for store/atomic
  683. !if(P_.IsAtomic, [], [llvm_i32_ty]), // dmask(imm)
  684. P_.AddrTypes, // vaddr(VGPR)
  685. [llvm_v8i32_ty], // rsrc(SGPR)
  686. !if(P_.IsSample, [llvm_v4i32_ty, // samp(SGPR)
  687. llvm_i1_ty], []), // unorm(imm)
  688. [llvm_i32_ty, // texfailctrl(imm; bit 0 = tfe, bit 1 = lwe)
  689. llvm_i32_ty]), // cachepolicy(imm; bit 0 = glc, bit 1 = slc, bit 2 = dlc)
  690. !listconcat(props,
  691. !if(P_.IsAtomic, [], [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.DmaskArgIndex>>]),
  692. !if(P_.IsSample, [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.UnormArgIndex>>], []),
  693. [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.TexFailCtrlArgIndex>>,
  694. ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.CachePolicyArgIndex>>]),
  695. "", sdnodeprops>,
  696. AMDGPURsrcIntrinsic<!add(!size(P_.DataArgs), !size(P_.AddrTypes),
  697. !if(P_.IsAtomic, 0, 1)), 1> {
  698. AMDGPUDimProfile P = P_;
  699. AMDGPUImageDimIntrinsic Intr = !cast<AMDGPUImageDimIntrinsic>(NAME);
  700. let TargetPrefix = "amdgcn";
  701. }
  702. // Marker class for intrinsics with a DMask that determines the returned
  703. // channels.
  704. class AMDGPUImageDMaskIntrinsic;
  705. defset list<AMDGPUImageDimIntrinsic> AMDGPUImageDimIntrinsics = {
  706. //////////////////////////////////////////////////////////////////////////
  707. // Load and store intrinsics
  708. //////////////////////////////////////////////////////////////////////////
  709. multiclass AMDGPUImageDimIntrinsicsNoMsaa<string opmod,
  710. list<LLVMType> retty,
  711. list<AMDGPUArg> dataargs,
  712. list<IntrinsicProperty> props,
  713. list<SDNodeProperty> sdnodeprops,
  714. bit Mip = false> {
  715. foreach dim = AMDGPUDims.NoMsaa in {
  716. def !strconcat(NAME, "_", dim.Name)
  717. : AMDGPUImageDimIntrinsic<
  718. AMDGPUDimNoSampleProfile<opmod, dim, retty, dataargs, Mip>,
  719. props, sdnodeprops>;
  720. }
  721. }
  722. multiclass AMDGPUImageDimIntrinsicsAll<string opmod,
  723. list<LLVMType> retty,
  724. list<AMDGPUArg> dataargs,
  725. list<IntrinsicProperty> props,
  726. list<SDNodeProperty> sdnodeprops,
  727. bit Mip = false> {
  728. foreach dim = AMDGPUDims.All in {
  729. def !strconcat(NAME, "_", dim.Name)
  730. : AMDGPUImageDimIntrinsic<
  731. AMDGPUDimNoSampleProfile<opmod, dim, retty, dataargs, Mip>,
  732. props, sdnodeprops>;
  733. }
  734. }
  735. defm int_amdgcn_image_load
  736. : AMDGPUImageDimIntrinsicsAll<"LOAD", [llvm_any_ty], [], [IntrReadMem],
  737. [SDNPMemOperand]>,
  738. AMDGPUImageDMaskIntrinsic;
  739. defm int_amdgcn_image_load_mip
  740. : AMDGPUImageDimIntrinsicsNoMsaa<"LOAD_MIP", [llvm_any_ty], [],
  741. [IntrReadMem, IntrWillReturn], [SDNPMemOperand], 1>,
  742. AMDGPUImageDMaskIntrinsic;
  743. defm int_amdgcn_image_store : AMDGPUImageDimIntrinsicsAll<
  744. "STORE", [], [AMDGPUArg<llvm_anyfloat_ty, "vdata">],
  745. [IntrWriteMem, IntrWillReturn], [SDNPMemOperand]>;
  746. defm int_amdgcn_image_store_mip : AMDGPUImageDimIntrinsicsNoMsaa<
  747. "STORE_MIP", [], [AMDGPUArg<llvm_anyfloat_ty, "vdata">],
  748. [IntrWriteMem, IntrWillReturn], [SDNPMemOperand], 1>;
  749. //////////////////////////////////////////////////////////////////////////
  750. // MSAA intrinsics
  751. //////////////////////////////////////////////////////////////////////////
  752. foreach dim = AMDGPUDims.Msaa in {
  753. def int_amdgcn_image_msaa_load_x # _ # dim.Name:
  754. AMDGPUImageDimIntrinsic<
  755. AMDGPUDimNoSampleProfile<"MSAA_LOAD_X", dim, [llvm_any_ty], []>,
  756. [IntrReadMem], [SDNPMemOperand]>;
  757. }
  758. foreach dim = AMDGPUDims.Msaa in {
  759. def int_amdgcn_image_msaa_load # _ # dim.Name:
  760. AMDGPUImageDimIntrinsic<
  761. AMDGPUDimNoSampleProfile<"MSAA_LOAD", dim, [llvm_any_ty], []>,
  762. [IntrReadMem], [SDNPMemOperand]>;
  763. }
  764. //////////////////////////////////////////////////////////////////////////
  765. // sample and getlod intrinsics
  766. //////////////////////////////////////////////////////////////////////////
  767. multiclass AMDGPUImageDimSampleDims<string opmod,
  768. AMDGPUSampleVariant sample,
  769. bit NoMem = false> {
  770. foreach dim = AMDGPUDims.NoMsaa in {
  771. def !strconcat(NAME, "_", dim.Name) : AMDGPUImageDimIntrinsic<
  772. AMDGPUDimSampleProfile<opmod, dim, sample>,
  773. !if(NoMem, [IntrNoMem], [IntrReadMem]),
  774. !if(NoMem, [], [SDNPMemOperand])>;
  775. }
  776. }
  777. foreach sample = AMDGPUSampleVariants in {
  778. defm int_amdgcn_image_sample # sample.LowerCaseMod
  779. : AMDGPUImageDimSampleDims<"SAMPLE" # sample.UpperCaseMod, sample>,
  780. AMDGPUImageDMaskIntrinsic;
  781. }
  782. defm int_amdgcn_image_getlod
  783. : AMDGPUImageDimSampleDims<"GET_LOD", AMDGPUSample, 1>,
  784. AMDGPUImageDMaskIntrinsic;
  785. //////////////////////////////////////////////////////////////////////////
  786. // getresinfo intrinsics
  787. //////////////////////////////////////////////////////////////////////////
  788. foreach dim = AMDGPUDims.All in {
  789. def !strconcat("int_amdgcn_image_getresinfo_", dim.Name)
  790. : AMDGPUImageDimIntrinsic<AMDGPUDimGetResInfoProfile<dim>, [IntrNoMem], []>,
  791. AMDGPUImageDMaskIntrinsic;
  792. }
  793. //////////////////////////////////////////////////////////////////////////
  794. // gather4 intrinsics
  795. //////////////////////////////////////////////////////////////////////////
  796. foreach sample = AMDGPUSampleVariantsNoGradients in {
  797. foreach dim = [AMDGPUDim2D, AMDGPUDimCube, AMDGPUDim2DArray] in {
  798. def int_amdgcn_image_gather4 # sample.LowerCaseMod # _ # dim.Name:
  799. AMDGPUImageDimIntrinsic<
  800. AMDGPUDimSampleProfile<"GATHER4" # sample.UpperCaseMod, dim, sample>,
  801. [IntrReadMem], [SDNPMemOperand]>;
  802. }
  803. }
  804. }
  805. //////////////////////////////////////////////////////////////////////////
  806. // atomic intrinsics
  807. //////////////////////////////////////////////////////////////////////////
  808. defset list<AMDGPUImageDimIntrinsic> AMDGPUImageDimAtomicIntrinsics = {
  809. multiclass AMDGPUImageDimAtomicX<string opmod, list<AMDGPUArg> dataargs,
  810. int isFloat = 0> {
  811. foreach dim = AMDGPUDims.All in {
  812. def !strconcat(NAME, "_", dim.Name): AMDGPUImageDimIntrinsic<
  813. !if (isFloat, AMDGPUDimAtomicFloatProfile<opmod, dim, dataargs>,
  814. AMDGPUDimAtomicProfile<opmod, dim, dataargs>),
  815. [], [SDNPMemOperand]>;
  816. }
  817. }
  818. multiclass AMDGPUImageDimAtomic<string opmod, int isFloat = 0> {
  819. defm ""
  820. : AMDGPUImageDimAtomicX<opmod, [AMDGPUArg<LLVMMatchType<0>, "vdata">],
  821. isFloat>;
  822. }
  823. multiclass AMDGPUImageDimFloatAtomic<string opmod> {
  824. defm "" : AMDGPUImageDimAtomic<opmod, 1 /*isFloat*/>;
  825. }
  826. defm int_amdgcn_image_atomic_swap : AMDGPUImageDimAtomic<"ATOMIC_SWAP">;
  827. defm int_amdgcn_image_atomic_add : AMDGPUImageDimAtomic<"ATOMIC_ADD">;
  828. defm int_amdgcn_image_atomic_sub : AMDGPUImageDimAtomic<"ATOMIC_SUB">;
  829. defm int_amdgcn_image_atomic_smin : AMDGPUImageDimAtomic<"ATOMIC_SMIN">;
  830. defm int_amdgcn_image_atomic_umin : AMDGPUImageDimAtomic<"ATOMIC_UMIN">;
  831. defm int_amdgcn_image_atomic_fmin : AMDGPUImageDimFloatAtomic<"ATOMIC_FMIN">;
  832. defm int_amdgcn_image_atomic_smax : AMDGPUImageDimAtomic<"ATOMIC_SMAX">;
  833. defm int_amdgcn_image_atomic_umax : AMDGPUImageDimAtomic<"ATOMIC_UMAX">;
  834. defm int_amdgcn_image_atomic_fmax : AMDGPUImageDimFloatAtomic<"ATOMIC_FMAX">;
  835. defm int_amdgcn_image_atomic_and : AMDGPUImageDimAtomic<"ATOMIC_AND">;
  836. defm int_amdgcn_image_atomic_or : AMDGPUImageDimAtomic<"ATOMIC_OR">;
  837. defm int_amdgcn_image_atomic_xor : AMDGPUImageDimAtomic<"ATOMIC_XOR">;
  838. defm int_amdgcn_image_atomic_inc : AMDGPUImageDimAtomic<"ATOMIC_INC">;
  839. defm int_amdgcn_image_atomic_dec : AMDGPUImageDimAtomic<"ATOMIC_DEC">;
  840. defm int_amdgcn_image_atomic_cmpswap :
  841. AMDGPUImageDimAtomicX<"ATOMIC_CMPSWAP", [AMDGPUArg<LLVMMatchType<0>, "src">,
  842. AMDGPUArg<LLVMMatchType<0>, "cmp">]>;
  843. }
  844. //////////////////////////////////////////////////////////////////////////
  845. // Buffer intrinsics
  846. //////////////////////////////////////////////////////////////////////////
  847. let TargetPrefix = "amdgcn" in {
  848. defset list<AMDGPURsrcIntrinsic> AMDGPUBufferIntrinsics = {
  849. class AMDGPUBufferLoad<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  850. [data_ty],
  851. [llvm_v4i32_ty, // rsrc(SGPR)
  852. llvm_i32_ty, // vindex(VGPR)
  853. llvm_i32_ty, // offset(SGPR/VGPR/imm)
  854. llvm_i1_ty, // glc(imm)
  855. llvm_i1_ty], // slc(imm)
  856. [IntrReadMem, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
  857. AMDGPURsrcIntrinsic<0>;
  858. def int_amdgcn_buffer_load_format : AMDGPUBufferLoad<llvm_anyfloat_ty>;
  859. def int_amdgcn_buffer_load : AMDGPUBufferLoad;
  860. // Generate a buffer_load instruction that may be optimized to s_buffer_load if
  861. // the offset argument is uniform.
  862. def int_amdgcn_s_buffer_load : DefaultAttrsIntrinsic <
  863. [llvm_any_ty],
  864. [llvm_v4i32_ty, // rsrc(SGPR)
  865. llvm_i32_ty, // byte offset
  866. llvm_i32_ty], // cachepolicy(imm; bit 0 = glc, bit 2 = dlc)
  867. [IntrNoMem, ImmArg<ArgIndex<2>>]>,
  868. AMDGPURsrcIntrinsic<0>;
  869. class AMDGPUBufferStore<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  870. [],
  871. [data_ty, // vdata(VGPR)
  872. llvm_v4i32_ty, // rsrc(SGPR)
  873. llvm_i32_ty, // vindex(VGPR)
  874. llvm_i32_ty, // offset(SGPR/VGPR/imm)
  875. llvm_i1_ty, // glc(imm)
  876. llvm_i1_ty], // slc(imm)
  877. [IntrWriteMem, ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
  878. AMDGPURsrcIntrinsic<1>;
  879. def int_amdgcn_buffer_store_format : AMDGPUBufferStore<llvm_anyfloat_ty>;
  880. def int_amdgcn_buffer_store : AMDGPUBufferStore;
  881. // New buffer intrinsics with separate raw and struct variants. The raw
  882. // variant never has an index. The struct variant always has an index, even if
  883. // it is const 0. A struct intrinsic with constant 0 index is different to the
  884. // corresponding raw intrinsic on gfx9+ because the behavior of bound checking
  885. // and swizzling changes depending on whether idxen is set in the instruction.
  886. // These new instrinsics also keep the offset and soffset arguments separate as
  887. // they behave differently in bounds checking and swizzling.
  888. class AMDGPURawBufferLoad<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  889. [data_ty],
  890. [llvm_v4i32_ty, // rsrc(SGPR)
  891. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  892. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  893. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  894. // bit 1 = slc,
  895. // bit 2 = dlc on gfx10+),
  896. // swizzled buffer (bit 3 = swz))
  897. [IntrReadMem, ImmArg<ArgIndex<3>>], "", [SDNPMemOperand]>,
  898. AMDGPURsrcIntrinsic<0>;
  899. def int_amdgcn_raw_buffer_load_format : AMDGPURawBufferLoad<llvm_anyfloat_ty>;
  900. def int_amdgcn_raw_buffer_load : AMDGPURawBufferLoad;
  901. class AMDGPUStructBufferLoad<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  902. [data_ty],
  903. [llvm_v4i32_ty, // rsrc(SGPR)
  904. llvm_i32_ty, // vindex(VGPR)
  905. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  906. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  907. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  908. // bit 1 = slc,
  909. // bit 2 = dlc on gfx10+),
  910. // swizzled buffer (bit 3 = swz))
  911. [IntrReadMem, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
  912. AMDGPURsrcIntrinsic<0>;
  913. def int_amdgcn_struct_buffer_load_format : AMDGPUStructBufferLoad;
  914. def int_amdgcn_struct_buffer_load : AMDGPUStructBufferLoad;
  915. class AMDGPURawBufferStore<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  916. [],
  917. [data_ty, // vdata(VGPR)
  918. llvm_v4i32_ty, // rsrc(SGPR)
  919. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  920. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  921. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  922. // bit 1 = slc,
  923. // bit 2 = dlc on gfx10+),
  924. // swizzled buffer (bit 3 = swz))
  925. [IntrWriteMem, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
  926. AMDGPURsrcIntrinsic<1>;
  927. def int_amdgcn_raw_buffer_store_format : AMDGPURawBufferStore<llvm_anyfloat_ty>;
  928. def int_amdgcn_raw_buffer_store : AMDGPURawBufferStore;
  929. class AMDGPUStructBufferStore<LLVMType data_ty = llvm_any_ty> : DefaultAttrsIntrinsic <
  930. [],
  931. [data_ty, // vdata(VGPR)
  932. llvm_v4i32_ty, // rsrc(SGPR)
  933. llvm_i32_ty, // vindex(VGPR)
  934. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  935. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  936. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  937. // bit 1 = slc,
  938. // bit 2 = dlc on gfx10+),
  939. // swizzled buffer (bit 3 = swz))
  940. [IntrWriteMem, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
  941. AMDGPURsrcIntrinsic<1>;
  942. def int_amdgcn_struct_buffer_store_format : AMDGPUStructBufferStore;
  943. def int_amdgcn_struct_buffer_store : AMDGPUStructBufferStore;
  944. class AMDGPURawBufferAtomic<LLVMType data_ty = llvm_any_ty, bit NoRtn = false> : Intrinsic <
  945. !if(NoRtn, [], [data_ty]),
  946. [!if(NoRtn, data_ty, LLVMMatchType<0>), // vdata(VGPR)
  947. llvm_v4i32_ty, // rsrc(SGPR)
  948. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  949. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  950. llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
  951. [ImmArg<ArgIndex<4>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  952. AMDGPURsrcIntrinsic<1, 0>;
  953. def int_amdgcn_raw_buffer_atomic_swap : AMDGPURawBufferAtomic;
  954. def int_amdgcn_raw_buffer_atomic_add : AMDGPURawBufferAtomic;
  955. def int_amdgcn_raw_buffer_atomic_sub : AMDGPURawBufferAtomic;
  956. def int_amdgcn_raw_buffer_atomic_smin : AMDGPURawBufferAtomic;
  957. def int_amdgcn_raw_buffer_atomic_umin : AMDGPURawBufferAtomic;
  958. def int_amdgcn_raw_buffer_atomic_fmin : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
  959. def int_amdgcn_raw_buffer_atomic_smax : AMDGPURawBufferAtomic;
  960. def int_amdgcn_raw_buffer_atomic_umax : AMDGPURawBufferAtomic;
  961. def int_amdgcn_raw_buffer_atomic_fmax : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
  962. def int_amdgcn_raw_buffer_atomic_and : AMDGPURawBufferAtomic;
  963. def int_amdgcn_raw_buffer_atomic_or : AMDGPURawBufferAtomic;
  964. def int_amdgcn_raw_buffer_atomic_xor : AMDGPURawBufferAtomic;
  965. def int_amdgcn_raw_buffer_atomic_inc : AMDGPURawBufferAtomic;
  966. def int_amdgcn_raw_buffer_atomic_dec : AMDGPURawBufferAtomic;
  967. def int_amdgcn_raw_buffer_atomic_cmpswap : Intrinsic<
  968. [llvm_anyint_ty],
  969. [LLVMMatchType<0>, // src(VGPR)
  970. LLVMMatchType<0>, // cmp(VGPR)
  971. llvm_v4i32_ty, // rsrc(SGPR)
  972. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  973. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  974. llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
  975. [ImmArg<ArgIndex<5>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  976. AMDGPURsrcIntrinsic<2, 0>;
  977. // gfx908 intrinsic
  978. def int_amdgcn_raw_buffer_atomic_fadd : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
  979. class AMDGPUStructBufferAtomic<LLVMType data_ty = llvm_any_ty, bit NoRtn = false> : Intrinsic <
  980. !if(NoRtn, [], [data_ty]),
  981. [!if(NoRtn, data_ty, LLVMMatchType<0>), // vdata(VGPR)
  982. llvm_v4i32_ty, // rsrc(SGPR)
  983. llvm_i32_ty, // vindex(VGPR)
  984. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  985. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  986. llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
  987. [ImmArg<ArgIndex<5>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  988. AMDGPURsrcIntrinsic<1, 0>;
  989. def int_amdgcn_struct_buffer_atomic_swap : AMDGPUStructBufferAtomic;
  990. def int_amdgcn_struct_buffer_atomic_add : AMDGPUStructBufferAtomic;
  991. def int_amdgcn_struct_buffer_atomic_sub : AMDGPUStructBufferAtomic;
  992. def int_amdgcn_struct_buffer_atomic_smin : AMDGPUStructBufferAtomic;
  993. def int_amdgcn_struct_buffer_atomic_umin : AMDGPUStructBufferAtomic;
  994. def int_amdgcn_struct_buffer_atomic_smax : AMDGPUStructBufferAtomic;
  995. def int_amdgcn_struct_buffer_atomic_umax : AMDGPUStructBufferAtomic;
  996. def int_amdgcn_struct_buffer_atomic_and : AMDGPUStructBufferAtomic;
  997. def int_amdgcn_struct_buffer_atomic_or : AMDGPUStructBufferAtomic;
  998. def int_amdgcn_struct_buffer_atomic_xor : AMDGPUStructBufferAtomic;
  999. def int_amdgcn_struct_buffer_atomic_inc : AMDGPUStructBufferAtomic;
  1000. def int_amdgcn_struct_buffer_atomic_dec : AMDGPUStructBufferAtomic;
  1001. def int_amdgcn_struct_buffer_atomic_cmpswap : Intrinsic<
  1002. [llvm_anyint_ty],
  1003. [LLVMMatchType<0>, // src(VGPR)
  1004. LLVMMatchType<0>, // cmp(VGPR)
  1005. llvm_v4i32_ty, // rsrc(SGPR)
  1006. llvm_i32_ty, // vindex(VGPR)
  1007. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  1008. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1009. llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
  1010. [ImmArg<ArgIndex<6>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  1011. AMDGPURsrcIntrinsic<2, 0>;
  1012. // gfx908 intrinsic
  1013. def int_amdgcn_struct_buffer_atomic_fadd : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
  1014. // gfx90a intrinsics
  1015. def int_amdgcn_struct_buffer_atomic_fmin : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
  1016. def int_amdgcn_struct_buffer_atomic_fmax : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
  1017. // Obsolescent tbuffer intrinsics.
  1018. def int_amdgcn_tbuffer_load : DefaultAttrsIntrinsic <
  1019. [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1020. [llvm_v4i32_ty, // rsrc(SGPR)
  1021. llvm_i32_ty, // vindex(VGPR)
  1022. llvm_i32_ty, // voffset(VGPR)
  1023. llvm_i32_ty, // soffset(SGPR)
  1024. llvm_i32_ty, // offset(imm)
  1025. llvm_i32_ty, // dfmt(imm)
  1026. llvm_i32_ty, // nfmt(imm)
  1027. llvm_i1_ty, // glc(imm)
  1028. llvm_i1_ty], // slc(imm)
  1029. [IntrReadMem,
  1030. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>,
  1031. ImmArg<ArgIndex<7>>, ImmArg<ArgIndex<8>>], "", [SDNPMemOperand]>,
  1032. AMDGPURsrcIntrinsic<0>;
  1033. def int_amdgcn_tbuffer_store : DefaultAttrsIntrinsic <
  1034. [],
  1035. [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1036. llvm_v4i32_ty, // rsrc(SGPR)
  1037. llvm_i32_ty, // vindex(VGPR)
  1038. llvm_i32_ty, // voffset(VGPR)
  1039. llvm_i32_ty, // soffset(SGPR)
  1040. llvm_i32_ty, // offset(imm)
  1041. llvm_i32_ty, // dfmt(imm)
  1042. llvm_i32_ty, // nfmt(imm)
  1043. llvm_i1_ty, // glc(imm)
  1044. llvm_i1_ty], // slc(imm)
  1045. [IntrWriteMem, ImmArg<ArgIndex<5>>,
  1046. ImmArg<ArgIndex<6>>, ImmArg<ArgIndex<7>>,
  1047. ImmArg<ArgIndex<8>>, ImmArg<ArgIndex<9>>], "", [SDNPMemOperand]>,
  1048. AMDGPURsrcIntrinsic<1>;
  1049. // New tbuffer intrinsics, with:
  1050. // - raw and struct variants
  1051. // - joint format field
  1052. // - joint cachepolicy field
  1053. def int_amdgcn_raw_tbuffer_load : DefaultAttrsIntrinsic <
  1054. [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1055. [llvm_v4i32_ty, // rsrc(SGPR)
  1056. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  1057. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1058. llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
  1059. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1060. // bit 1 = slc,
  1061. // bit 2 = dlc on gfx10+),
  1062. // swizzled buffer (bit 3 = swz))
  1063. [IntrReadMem,
  1064. ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
  1065. AMDGPURsrcIntrinsic<0>;
  1066. def int_amdgcn_raw_tbuffer_store : DefaultAttrsIntrinsic <
  1067. [],
  1068. [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1069. llvm_v4i32_ty, // rsrc(SGPR)
  1070. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  1071. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1072. llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
  1073. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1074. // bit 1 = slc,
  1075. // bit 2 = dlc on gfx10+),
  1076. // swizzled buffer (bit 3 = swz))
  1077. [IntrWriteMem,
  1078. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
  1079. AMDGPURsrcIntrinsic<1>;
  1080. def int_amdgcn_struct_tbuffer_load : DefaultAttrsIntrinsic <
  1081. [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1082. [llvm_v4i32_ty, // rsrc(SGPR)
  1083. llvm_i32_ty, // vindex(VGPR)
  1084. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  1085. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1086. llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
  1087. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1088. // bit 1 = slc,
  1089. // bit 2 = dlc on gfx10+),
  1090. // swizzled buffer (bit 3 = swz))
  1091. [IntrReadMem,
  1092. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
  1093. AMDGPURsrcIntrinsic<0>;
  1094. def int_amdgcn_struct_tbuffer_store : DefaultAttrsIntrinsic <
  1095. [],
  1096. [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
  1097. llvm_v4i32_ty, // rsrc(SGPR)
  1098. llvm_i32_ty, // vindex(VGPR)
  1099. llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
  1100. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1101. llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
  1102. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1103. // bit 1 = slc,
  1104. // bit 2 = dlc on gfx10+),
  1105. // swizzled buffer (bit 3 = swz))
  1106. [IntrWriteMem,
  1107. ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>], "", [SDNPMemOperand]>,
  1108. AMDGPURsrcIntrinsic<1>;
  1109. class AMDGPUBufferAtomic : Intrinsic <
  1110. [llvm_anyint_ty],
  1111. [LLVMMatchType<0>, // vdata(VGPR)
  1112. llvm_v4i32_ty, // rsrc(SGPR)
  1113. llvm_i32_ty, // vindex(VGPR)
  1114. llvm_i32_ty, // offset(SGPR/VGPR/imm)
  1115. llvm_i1_ty], // slc(imm)
  1116. [ImmArg<ArgIndex<4>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  1117. AMDGPURsrcIntrinsic<1, 0>;
  1118. def int_amdgcn_buffer_atomic_swap : AMDGPUBufferAtomic;
  1119. def int_amdgcn_buffer_atomic_add : AMDGPUBufferAtomic;
  1120. def int_amdgcn_buffer_atomic_sub : AMDGPUBufferAtomic;
  1121. def int_amdgcn_buffer_atomic_smin : AMDGPUBufferAtomic;
  1122. def int_amdgcn_buffer_atomic_umin : AMDGPUBufferAtomic;
  1123. def int_amdgcn_buffer_atomic_smax : AMDGPUBufferAtomic;
  1124. def int_amdgcn_buffer_atomic_umax : AMDGPUBufferAtomic;
  1125. def int_amdgcn_buffer_atomic_and : AMDGPUBufferAtomic;
  1126. def int_amdgcn_buffer_atomic_or : AMDGPUBufferAtomic;
  1127. def int_amdgcn_buffer_atomic_xor : AMDGPUBufferAtomic;
  1128. def int_amdgcn_buffer_atomic_cmpswap : Intrinsic<
  1129. [llvm_i32_ty],
  1130. [llvm_i32_ty, // src(VGPR)
  1131. llvm_i32_ty, // cmp(VGPR)
  1132. llvm_v4i32_ty, // rsrc(SGPR)
  1133. llvm_i32_ty, // vindex(VGPR)
  1134. llvm_i32_ty, // offset(SGPR/VGPR/imm)
  1135. llvm_i1_ty], // slc(imm)
  1136. [ImmArg<ArgIndex<5>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  1137. AMDGPURsrcIntrinsic<2, 0>;
  1138. def int_amdgcn_buffer_atomic_csub : AMDGPUBufferAtomic;
  1139. class AMDGPUBufferAtomicFP : Intrinsic <
  1140. [llvm_anyfloat_ty],
  1141. [LLVMMatchType<0>, // vdata(VGPR)
  1142. llvm_v4i32_ty, // rsrc(SGPR)
  1143. llvm_i32_ty, // vindex(VGPR)
  1144. llvm_i32_ty, // offset(SGPR/VGPR/imm)
  1145. llvm_i1_ty], // slc(imm)
  1146. [ImmArg<ArgIndex<4>>, IntrWillReturn, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>,
  1147. AMDGPURsrcIntrinsic<1, 0>;
  1148. // Legacy form of the intrinsic. raw and struct forms should be preferred.
  1149. def int_amdgcn_buffer_atomic_fadd : AMDGPUBufferAtomicFP;
  1150. class AMDGPURawBufferLoadLDS : Intrinsic <
  1151. [],
  1152. [llvm_v4i32_ty, // rsrc(SGPR)
  1153. LLVMQualPointerType<llvm_i8_ty, 3>, // LDS base offset
  1154. llvm_i32_ty, // Data byte size: 1/2/4
  1155. llvm_i32_ty, // voffset(VGPR, included in bounds checking and swizzling)
  1156. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1157. llvm_i32_ty, // imm offset(imm, included in bounds checking and swizzling)
  1158. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1159. // bit 1 = slc,
  1160. // bit 2 = dlc on gfx10+))
  1161. // swizzled buffer (bit 3 = swz))
  1162. [IntrWillReturn, NoCapture<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<5>>,
  1163. ImmArg<ArgIndex<6>>, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>, AMDGPURsrcIntrinsic<0>;
  1164. def int_amdgcn_raw_buffer_load_lds : AMDGPURawBufferLoadLDS;
  1165. class AMDGPUStructBufferLoadLDS : Intrinsic <
  1166. [],
  1167. [llvm_v4i32_ty, // rsrc(SGPR)
  1168. LLVMQualPointerType<llvm_i8_ty, 3>, // LDS base offset
  1169. llvm_i32_ty, // Data byte size: 1/2/4
  1170. llvm_i32_ty, // vindex(VGPR)
  1171. llvm_i32_ty, // voffset(VGPR, included in bounds checking and swizzling)
  1172. llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
  1173. llvm_i32_ty, // imm offset(imm, included in bounds checking and swizzling)
  1174. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
  1175. // bit 1 = slc,
  1176. // bit 2 = dlc on gfx10+))
  1177. // swizzled buffer (bit 3 = swz))
  1178. [IntrWillReturn, NoCapture<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<6>>,
  1179. ImmArg<ArgIndex<7>>, IntrNoCallback, IntrNoFree], "", [SDNPMemOperand]>, AMDGPURsrcIntrinsic<0>;
  1180. def int_amdgcn_struct_buffer_load_lds : AMDGPUStructBufferLoadLDS;
  1181. } // defset AMDGPUBufferIntrinsics
  1182. // Uses that do not set the done bit should set IntrWriteMem on the
  1183. // call site.
  1184. def int_amdgcn_exp : DefaultAttrsIntrinsic <[], [
  1185. llvm_i32_ty, // tgt,
  1186. llvm_i32_ty, // en
  1187. llvm_any_ty, // src0 (f32 or i32)
  1188. LLVMMatchType<0>, // src1
  1189. LLVMMatchType<0>, // src2
  1190. LLVMMatchType<0>, // src3
  1191. llvm_i1_ty, // done
  1192. llvm_i1_ty // vm (ignored on GFX11+)
  1193. ],
  1194. [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<6>>,
  1195. ImmArg<ArgIndex<7>>, IntrWriteMem, IntrInaccessibleMemOnly]
  1196. >;
  1197. // exp with row_en bit set. Only supported on GFX11+.
  1198. def int_amdgcn_exp_row : DefaultAttrsIntrinsic <[], [
  1199. llvm_i32_ty, // tgt,
  1200. llvm_i32_ty, // en
  1201. llvm_any_ty, // src0 (f32 or i32)
  1202. LLVMMatchType<0>, // src1
  1203. LLVMMatchType<0>, // src2
  1204. LLVMMatchType<0>, // src3
  1205. llvm_i1_ty, // done
  1206. llvm_i32_ty], // row number
  1207. [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<6>>,
  1208. IntrWriteMem, IntrInaccessibleMemOnly]
  1209. >;
  1210. // exp with compr bit set. Not supported on GFX11+.
  1211. def int_amdgcn_exp_compr : DefaultAttrsIntrinsic <[], [
  1212. llvm_i32_ty, // tgt,
  1213. llvm_i32_ty, // en
  1214. llvm_anyvector_ty, // src0 (v2f16 or v2i16)
  1215. LLVMMatchType<0>, // src1
  1216. llvm_i1_ty, // done
  1217. llvm_i1_ty], // vm
  1218. [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<4>>,
  1219. ImmArg<ArgIndex<5>>, IntrWriteMem, IntrInaccessibleMemOnly]
  1220. >;
  1221. def int_amdgcn_buffer_wbinvl1_sc :
  1222. ClangBuiltin<"__builtin_amdgcn_buffer_wbinvl1_sc">,
  1223. DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
  1224. def int_amdgcn_buffer_wbinvl1 :
  1225. ClangBuiltin<"__builtin_amdgcn_buffer_wbinvl1">,
  1226. DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
  1227. def int_amdgcn_s_dcache_inv :
  1228. ClangBuiltin<"__builtin_amdgcn_s_dcache_inv">,
  1229. DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
  1230. def int_amdgcn_s_memtime :
  1231. ClangBuiltin<"__builtin_amdgcn_s_memtime">,
  1232. DefaultAttrsIntrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrHasSideEffects]>;
  1233. def int_amdgcn_s_sleep :
  1234. ClangBuiltin<"__builtin_amdgcn_s_sleep">,
  1235. DefaultAttrsIntrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
  1236. IntrHasSideEffects]> {
  1237. }
  1238. def int_amdgcn_s_incperflevel :
  1239. ClangBuiltin<"__builtin_amdgcn_s_incperflevel">,
  1240. DefaultAttrsIntrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
  1241. IntrHasSideEffects]> {
  1242. }
  1243. def int_amdgcn_s_decperflevel :
  1244. ClangBuiltin<"__builtin_amdgcn_s_decperflevel">,
  1245. DefaultAttrsIntrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
  1246. IntrHasSideEffects]> {
  1247. }
  1248. def int_amdgcn_s_sethalt :
  1249. DefaultAttrsIntrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
  1250. IntrHasSideEffects]>;
  1251. def int_amdgcn_s_setprio :
  1252. ClangBuiltin<"__builtin_amdgcn_s_setprio">,
  1253. DefaultAttrsIntrinsic<[], [llvm_i16_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
  1254. IntrHasSideEffects]>;
  1255. // This is IntrHasSideEffects so it can be used to read cycle counters.
  1256. def int_amdgcn_s_getreg :
  1257. ClangBuiltin<"__builtin_amdgcn_s_getreg">,
  1258. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
  1259. [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]
  1260. >;
  1261. // Note this can be used to set FP environment properties that are
  1262. // unsafe to change in non-strictfp functions. The register properties
  1263. // available (and value required to access them) may differ per
  1264. // subtarget. llvm.amdgcn.s.setreg(hwmode, value)
  1265. def int_amdgcn_s_setreg :
  1266. ClangBuiltin<"__builtin_amdgcn_s_setreg">,
  1267. DefaultAttrsIntrinsic<[], [llvm_i32_ty, llvm_i32_ty],
  1268. [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]
  1269. >;
  1270. // int_amdgcn_s_getpc is provided to allow a specific style of position
  1271. // independent code to determine the high part of its address when it is
  1272. // known (through convention) that the code and any data of interest does
  1273. // not cross a 4Gb address boundary. Use for any other purpose may not
  1274. // produce the desired results as optimizations may cause code movement,
  1275. // especially as we explicitly use IntrNoMem to allow optimizations.
  1276. def int_amdgcn_s_getpc :
  1277. ClangBuiltin<"__builtin_amdgcn_s_getpc">,
  1278. DefaultAttrsIntrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrSpeculatable,
  1279. IntrWillReturn]>;
  1280. // __builtin_amdgcn_interp_mov <param>, <attr_chan>, <attr>, <m0>
  1281. // param values: 0 = P10, 1 = P20, 2 = P0
  1282. def int_amdgcn_interp_mov :
  1283. ClangBuiltin<"__builtin_amdgcn_interp_mov">,
  1284. DefaultAttrsIntrinsic<[llvm_float_ty],
  1285. [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1286. [IntrNoMem, IntrSpeculatable,
  1287. ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
  1288. // __builtin_amdgcn_interp_p1 <i>, <attr_chan>, <attr>, <m0>
  1289. // This intrinsic reads from lds, but the memory values are constant,
  1290. // so it behaves like IntrNoMem.
  1291. def int_amdgcn_interp_p1 :
  1292. ClangBuiltin<"__builtin_amdgcn_interp_p1">,
  1293. DefaultAttrsIntrinsic<[llvm_float_ty],
  1294. [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1295. [IntrNoMem, IntrSpeculatable,
  1296. ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
  1297. // __builtin_amdgcn_interp_p2 <p1>, <j>, <attr_chan>, <attr>, <m0>
  1298. def int_amdgcn_interp_p2 :
  1299. ClangBuiltin<"__builtin_amdgcn_interp_p2">,
  1300. DefaultAttrsIntrinsic<[llvm_float_ty],
  1301. [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1302. [IntrNoMem, IntrSpeculatable,
  1303. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
  1304. // See int_amdgcn_v_interp_p1 for why this is IntrNoMem.
  1305. // __builtin_amdgcn_interp_p1_f16 <i>, <attr_chan>, <attr>, <high>, <m0>
  1306. // high selects whether high or low 16-bits are loaded from LDS
  1307. def int_amdgcn_interp_p1_f16 :
  1308. ClangBuiltin<"__builtin_amdgcn_interp_p1_f16">,
  1309. DefaultAttrsIntrinsic<[llvm_float_ty],
  1310. [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i32_ty],
  1311. [IntrNoMem, IntrSpeculatable,
  1312. ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
  1313. // __builtin_amdgcn_interp_p2_f16 <p1>, <j>, <attr_chan>, <attr>, <high>, <m0>
  1314. // high selects whether high or low 16-bits are loaded from LDS
  1315. def int_amdgcn_interp_p2_f16 :
  1316. ClangBuiltin<"__builtin_amdgcn_interp_p2_f16">,
  1317. DefaultAttrsIntrinsic<[llvm_half_ty],
  1318. [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i32_ty],
  1319. [IntrNoMem, IntrSpeculatable,
  1320. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]>;
  1321. // llvm.amdgcn.lds.direct.load <m0>
  1322. // The input argument is m0, which contains a packed combination of address
  1323. // offset and flags describing the data type.
  1324. def int_amdgcn_lds_direct_load :
  1325. DefaultAttrsIntrinsic<[llvm_any_ty], // overloaded for types u8, u16, i32/f32, i8, i16
  1326. [llvm_i32_ty],
  1327. [IntrReadMem, IntrSpeculatable]>;
  1328. // llvm.amdgcn.lds.param.load <attr_chan>, <attr>, <m0>
  1329. // Like interp intrinsics, this reads from lds, but the memory values are constant,
  1330. // so it behaves like IntrNoMem.
  1331. def int_amdgcn_lds_param_load :
  1332. DefaultAttrsIntrinsic<[llvm_float_ty],
  1333. [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1334. [IntrNoMem, IntrSpeculatable,
  1335. ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>]>;
  1336. // llvm.amdgcn.interp.inreg.p10 <p>, <i>, <p0>
  1337. def int_amdgcn_interp_inreg_p10 :
  1338. DefaultAttrsIntrinsic<[llvm_float_ty],
  1339. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  1340. [IntrNoMem, IntrSpeculatable]>;
  1341. // llvm.amdgcn.interp.inreg.p2 <p>, <j>, <tmp>
  1342. def int_amdgcn_interp_inreg_p2 :
  1343. DefaultAttrsIntrinsic<[llvm_float_ty],
  1344. [llvm_float_ty, llvm_float_ty, llvm_float_ty],
  1345. [IntrNoMem, IntrSpeculatable]>;
  1346. // llvm.amdgcn.interp.inreg.p10.f16 <p>, <i>, <p0>, <high>
  1347. // high selects whether high or low 16-bits are used for p and p0 operands
  1348. def int_amdgcn_interp_inreg_p10_f16:
  1349. DefaultAttrsIntrinsic<[llvm_float_ty],
  1350. [llvm_float_ty, llvm_float_ty, llvm_float_ty, llvm_i1_ty],
  1351. [IntrNoMem, IntrSpeculatable,
  1352. ImmArg<ArgIndex<3>>]>;
  1353. // llvm.amdgcn.interp.inreg.p2.f16 <p>, <j>, <tmp>, <high>
  1354. // high selects whether high or low 16-bits are used for p operand
  1355. def int_amdgcn_interp_inreg_p2_f16 :
  1356. DefaultAttrsIntrinsic<[llvm_half_ty],
  1357. [llvm_float_ty, llvm_float_ty, llvm_float_ty, llvm_i1_ty],
  1358. [IntrNoMem, IntrSpeculatable,
  1359. ImmArg<ArgIndex<3>>]>;
  1360. // Deprecated: use llvm.amdgcn.live.mask instead.
  1361. def int_amdgcn_ps_live : DefaultAttrsIntrinsic <
  1362. [llvm_i1_ty],
  1363. [],
  1364. [IntrNoMem]>;
  1365. // Query currently live lanes.
  1366. // Returns true if lane is live (and not a helper lane).
  1367. def int_amdgcn_live_mask : DefaultAttrsIntrinsic <[llvm_i1_ty],
  1368. [], [IntrReadMem, IntrInaccessibleMemOnly]
  1369. >;
  1370. def int_amdgcn_mbcnt_lo :
  1371. ClangBuiltin<"__builtin_amdgcn_mbcnt_lo">,
  1372. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1373. [IntrNoMem]>;
  1374. def int_amdgcn_mbcnt_hi :
  1375. ClangBuiltin<"__builtin_amdgcn_mbcnt_hi">,
  1376. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1377. [IntrNoMem]>;
  1378. // llvm.amdgcn.ds.swizzle src offset
  1379. def int_amdgcn_ds_swizzle :
  1380. ClangBuiltin<"__builtin_amdgcn_ds_swizzle">,
  1381. Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1382. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree,
  1383. ImmArg<ArgIndex<1>>]>;
  1384. def int_amdgcn_ubfe : DefaultAttrsIntrinsic<[llvm_anyint_ty],
  1385. [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty],
  1386. [IntrNoMem, IntrSpeculatable]
  1387. >;
  1388. def int_amdgcn_sbfe : DefaultAttrsIntrinsic<[llvm_anyint_ty],
  1389. [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty],
  1390. [IntrNoMem, IntrSpeculatable]
  1391. >;
  1392. def int_amdgcn_lerp :
  1393. ClangBuiltin<"__builtin_amdgcn_lerp">,
  1394. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1395. [IntrNoMem, IntrSpeculatable]
  1396. >;
  1397. def int_amdgcn_sad_u8 :
  1398. ClangBuiltin<"__builtin_amdgcn_sad_u8">,
  1399. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1400. [IntrNoMem, IntrSpeculatable]
  1401. >;
  1402. def int_amdgcn_msad_u8 :
  1403. ClangBuiltin<"__builtin_amdgcn_msad_u8">,
  1404. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1405. [IntrNoMem, IntrSpeculatable]
  1406. >;
  1407. def int_amdgcn_sad_hi_u8 :
  1408. ClangBuiltin<"__builtin_amdgcn_sad_hi_u8">,
  1409. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1410. [IntrNoMem, IntrSpeculatable]
  1411. >;
  1412. def int_amdgcn_sad_u16 :
  1413. ClangBuiltin<"__builtin_amdgcn_sad_u16">,
  1414. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1415. [IntrNoMem, IntrSpeculatable]
  1416. >;
  1417. def int_amdgcn_qsad_pk_u16_u8 :
  1418. ClangBuiltin<"__builtin_amdgcn_qsad_pk_u16_u8">,
  1419. DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
  1420. [IntrNoMem, IntrSpeculatable]
  1421. >;
  1422. def int_amdgcn_mqsad_pk_u16_u8 :
  1423. ClangBuiltin<"__builtin_amdgcn_mqsad_pk_u16_u8">,
  1424. DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
  1425. [IntrNoMem, IntrSpeculatable]
  1426. >;
  1427. def int_amdgcn_mqsad_u32_u8 :
  1428. ClangBuiltin<"__builtin_amdgcn_mqsad_u32_u8">,
  1429. DefaultAttrsIntrinsic<[llvm_v4i32_ty], [llvm_i64_ty, llvm_i32_ty, llvm_v4i32_ty],
  1430. [IntrNoMem, IntrSpeculatable]
  1431. >;
  1432. def int_amdgcn_cvt_pk_u8_f32 :
  1433. ClangBuiltin<"__builtin_amdgcn_cvt_pk_u8_f32">,
  1434. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_float_ty, llvm_i32_ty, llvm_i32_ty],
  1435. [IntrNoMem, IntrSpeculatable]
  1436. >;
  1437. def int_amdgcn_icmp :
  1438. Intrinsic<[llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>, llvm_i32_ty],
  1439. [IntrNoMem, IntrConvergent,
  1440. ImmArg<ArgIndex<2>>, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1441. def int_amdgcn_fcmp :
  1442. Intrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty, LLVMMatchType<1>, llvm_i32_ty],
  1443. [IntrNoMem, IntrConvergent,
  1444. ImmArg<ArgIndex<2>>, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1445. def int_amdgcn_ballot :
  1446. Intrinsic<[llvm_anyint_ty], [llvm_i1_ty],
  1447. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1448. def int_amdgcn_readfirstlane :
  1449. ClangBuiltin<"__builtin_amdgcn_readfirstlane">,
  1450. Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
  1451. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1452. // The lane argument must be uniform across the currently active threads of the
  1453. // current wave. Otherwise, the result is undefined.
  1454. def int_amdgcn_readlane :
  1455. ClangBuiltin<"__builtin_amdgcn_readlane">,
  1456. Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1457. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1458. // The value to write and lane select arguments must be uniform across the
  1459. // currently active threads of the current wave. Otherwise, the result is
  1460. // undefined.
  1461. def int_amdgcn_writelane :
  1462. ClangBuiltin<"__builtin_amdgcn_writelane">,
  1463. Intrinsic<[llvm_i32_ty], [
  1464. llvm_i32_ty, // uniform value to write: returned by the selected lane
  1465. llvm_i32_ty, // uniform lane select
  1466. llvm_i32_ty // returned by all lanes other than the selected one
  1467. ],
  1468. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1469. >;
  1470. def int_amdgcn_alignbyte : ClangBuiltin<"__builtin_amdgcn_alignbyte">,
  1471. DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1472. [IntrNoMem, IntrSpeculatable]
  1473. >;
  1474. def int_amdgcn_mul_i24 : DefaultAttrsIntrinsic<[llvm_i32_ty],
  1475. [llvm_i32_ty, llvm_i32_ty],
  1476. [IntrNoMem, IntrSpeculatable]
  1477. >;
  1478. def int_amdgcn_mul_u24 : DefaultAttrsIntrinsic<[llvm_i32_ty],
  1479. [llvm_i32_ty, llvm_i32_ty],
  1480. [IntrNoMem, IntrSpeculatable]
  1481. >;
  1482. def int_amdgcn_mulhi_i24 : DefaultAttrsIntrinsic<[llvm_i32_ty],
  1483. [llvm_i32_ty, llvm_i32_ty],
  1484. [IntrNoMem, IntrSpeculatable]
  1485. >;
  1486. def int_amdgcn_mulhi_u24 : DefaultAttrsIntrinsic<[llvm_i32_ty],
  1487. [llvm_i32_ty, llvm_i32_ty],
  1488. [IntrNoMem, IntrSpeculatable]
  1489. >;
  1490. // llvm.amdgcn.ds.gws.init(i32 bar_val, i32 resource_id)
  1491. //
  1492. // bar_val is the total number of waves that will wait on this
  1493. // barrier, minus 1.
  1494. def int_amdgcn_ds_gws_init :
  1495. ClangBuiltin<"__builtin_amdgcn_ds_gws_init">,
  1496. Intrinsic<[],
  1497. [llvm_i32_ty, llvm_i32_ty],
  1498. [IntrConvergent, IntrWriteMem,
  1499. IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1500. [SDNPMemOperand]
  1501. >;
  1502. // llvm.amdgcn.ds.gws.barrier(i32 vsrc0, i32 resource_id)
  1503. // bar_val is the total number of waves that will wait on this
  1504. // barrier, minus 1.
  1505. def int_amdgcn_ds_gws_barrier :
  1506. ClangBuiltin<"__builtin_amdgcn_ds_gws_barrier">,
  1507. Intrinsic<[],
  1508. [llvm_i32_ty, llvm_i32_ty],
  1509. [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1510. [SDNPMemOperand]
  1511. >;
  1512. // llvm.amdgcn.ds.gws.sema.v(i32 resource_id)
  1513. def int_amdgcn_ds_gws_sema_v :
  1514. ClangBuiltin<"__builtin_amdgcn_ds_gws_sema_v">,
  1515. Intrinsic<[],
  1516. [llvm_i32_ty],
  1517. [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1518. [SDNPMemOperand]
  1519. >;
  1520. // llvm.amdgcn.ds.gws.sema.br(i32 vsrc, i32 resource_id)
  1521. def int_amdgcn_ds_gws_sema_br :
  1522. ClangBuiltin<"__builtin_amdgcn_ds_gws_sema_br">,
  1523. Intrinsic<[],
  1524. [llvm_i32_ty, llvm_i32_ty],
  1525. [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1526. [SDNPMemOperand]
  1527. >;
  1528. // llvm.amdgcn.ds.gws.sema.p(i32 resource_id)
  1529. def int_amdgcn_ds_gws_sema_p :
  1530. ClangBuiltin<"__builtin_amdgcn_ds_gws_sema_p">,
  1531. Intrinsic<[],
  1532. [llvm_i32_ty],
  1533. [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1534. [SDNPMemOperand]
  1535. >;
  1536. // llvm.amdgcn.ds.gws.sema.release.all(i32 resource_id)
  1537. def int_amdgcn_ds_gws_sema_release_all :
  1538. ClangBuiltin<"__builtin_amdgcn_ds_gws_sema_release_all">,
  1539. Intrinsic<[],
  1540. [llvm_i32_ty],
  1541. [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn, IntrNoCallback, IntrNoFree], "",
  1542. [SDNPMemOperand]
  1543. >;
  1544. // Copies the source value to the destination value, with the guarantee that
  1545. // the source value is computed as if the entire program were executed in WQM.
  1546. def int_amdgcn_wqm : Intrinsic<[llvm_any_ty],
  1547. [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1548. >;
  1549. // Copies the source value to the destination value, such that the source
  1550. // is computed as if the entire program were executed in WQM if any other
  1551. // program code executes in WQM.
  1552. def int_amdgcn_softwqm : Intrinsic<[llvm_any_ty],
  1553. [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1554. >;
  1555. // Return true if at least one thread within the pixel quad passes true into
  1556. // the function.
  1557. def int_amdgcn_wqm_vote : Intrinsic<[llvm_i1_ty],
  1558. [llvm_i1_ty], [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1559. >;
  1560. // If false, set EXEC=0 for the current thread until the end of program.
  1561. // FIXME: Should this be IntrNoMem, IntrHasSideEffects, or IntrWillReturn?
  1562. def int_amdgcn_kill : Intrinsic<[], [llvm_i1_ty], [IntrNoCallback, IntrNoFree]>;
  1563. def int_amdgcn_endpgm : ClangBuiltin<"__builtin_amdgcn_endpgm">,
  1564. Intrinsic<[], [], [IntrNoReturn, IntrCold, IntrNoMem, IntrHasSideEffects, IntrNoCallback, IntrNoFree]
  1565. >;
  1566. // If false, mark all active lanes as helper lanes until the end of program.
  1567. def int_amdgcn_wqm_demote : Intrinsic<[],
  1568. [llvm_i1_ty], [IntrWriteMem, IntrInaccessibleMemOnly, IntrNoCallback, IntrNoFree]
  1569. >;
  1570. // Copies the active channels of the source value to the destination value,
  1571. // with the guarantee that the source value is computed as if the entire
  1572. // program were executed in Whole Wavefront Mode, i.e. with all channels
  1573. // enabled, with a few exceptions: - Phi nodes which require WWM return an
  1574. // undefined value.
  1575. def int_amdgcn_strict_wwm : Intrinsic<[llvm_any_ty],
  1576. [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
  1577. IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1578. >;
  1579. // Deprecated. Use int_amdgcn_strict_wwm instead.
  1580. def int_amdgcn_wwm : Intrinsic<[llvm_any_ty],
  1581. [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
  1582. IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1583. >;
  1584. def int_amdgcn_strict_wqm : Intrinsic<[llvm_any_ty],
  1585. [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
  1586. IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1587. >;
  1588. // Given a value, copies it while setting all the inactive lanes to a given
  1589. // value. Note that OpenGL helper lanes are considered active, so if the
  1590. // program ever uses WQM, then the instruction and the first source will be
  1591. // computed in WQM.
  1592. def int_amdgcn_set_inactive :
  1593. Intrinsic<[llvm_anyint_ty],
  1594. [LLVMMatchType<0>, // value to be copied
  1595. LLVMMatchType<0>], // value for the inactive lanes to take
  1596. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1597. // Return if the given flat pointer points to a local memory address.
  1598. def int_amdgcn_is_shared : ClangBuiltin<"__builtin_amdgcn_is_shared">,
  1599. DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_ptr_ty],
  1600. [IntrNoMem, IntrSpeculatable, NoCapture<ArgIndex<0>>]
  1601. >;
  1602. // Return if the given flat pointer points to a prvate memory address.
  1603. def int_amdgcn_is_private : ClangBuiltin<"__builtin_amdgcn_is_private">,
  1604. DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_ptr_ty],
  1605. [IntrNoMem, IntrSpeculatable, NoCapture<ArgIndex<0>>]
  1606. >;
  1607. //===----------------------------------------------------------------------===//
  1608. // CI+ Intrinsics
  1609. //===----------------------------------------------------------------------===//
  1610. def int_amdgcn_s_dcache_inv_vol :
  1611. ClangBuiltin<"__builtin_amdgcn_s_dcache_inv_vol">,
  1612. DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
  1613. def int_amdgcn_buffer_wbinvl1_vol :
  1614. ClangBuiltin<"__builtin_amdgcn_buffer_wbinvl1_vol">,
  1615. DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
  1616. //===----------------------------------------------------------------------===//
  1617. // VI Intrinsics
  1618. //===----------------------------------------------------------------------===//
  1619. // llvm.amdgcn.mov.dpp.i32 <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
  1620. def int_amdgcn_mov_dpp :
  1621. Intrinsic<[llvm_anyint_ty],
  1622. [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
  1623. llvm_i1_ty],
  1624. [IntrNoMem, IntrConvergent, IntrWillReturn,
  1625. ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>,
  1626. ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, IntrNoCallback, IntrNoFree]>;
  1627. // llvm.amdgcn.update.dpp.i32 <old> <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
  1628. // Should be equivalent to:
  1629. // v_mov_b32 <dest> <old>
  1630. // v_mov_b32 <dest> <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
  1631. def int_amdgcn_update_dpp :
  1632. Intrinsic<[llvm_anyint_ty],
  1633. [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty,
  1634. llvm_i32_ty, llvm_i32_ty, llvm_i1_ty],
  1635. [IntrNoMem, IntrConvergent, IntrWillReturn,
  1636. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>,
  1637. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>, IntrNoCallback, IntrNoFree]>;
  1638. def int_amdgcn_s_dcache_wb :
  1639. ClangBuiltin<"__builtin_amdgcn_s_dcache_wb">,
  1640. Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1641. def int_amdgcn_s_dcache_wb_vol :
  1642. ClangBuiltin<"__builtin_amdgcn_s_dcache_wb_vol">,
  1643. Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1644. def int_amdgcn_s_memrealtime :
  1645. ClangBuiltin<"__builtin_amdgcn_s_memrealtime">,
  1646. Intrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1647. // llvm.amdgcn.ds.permute <index> <src>
  1648. def int_amdgcn_ds_permute :
  1649. ClangBuiltin<"__builtin_amdgcn_ds_permute">,
  1650. Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1651. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1652. // llvm.amdgcn.ds.bpermute <index> <src>
  1653. def int_amdgcn_ds_bpermute :
  1654. ClangBuiltin<"__builtin_amdgcn_ds_bpermute">,
  1655. Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
  1656. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1657. // llvm.amdgcn.perm <src0> <src1> <selector>
  1658. def int_amdgcn_perm :
  1659. ClangBuiltin<"__builtin_amdgcn_perm">,
  1660. Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1661. [IntrNoMem, IntrSpeculatable, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1662. //===----------------------------------------------------------------------===//
  1663. // GFX9 Intrinsics
  1664. //===----------------------------------------------------------------------===//
  1665. class AMDGPUGlobalLoadLDS : Intrinsic <
  1666. [],
  1667. [LLVMQualPointerType<llvm_i8_ty, 1>, // Base global pointer to load from
  1668. LLVMQualPointerType<llvm_i8_ty, 3>, // LDS base pointer to store to
  1669. llvm_i32_ty, // Data byte size: 1/2/4
  1670. llvm_i32_ty, // imm offset (applied to both global and LDS address)
  1671. llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc/sc0,
  1672. // bit 1 = slc/sc1,
  1673. // bit 2 = dlc on gfx10+))
  1674. // bit 4 = scc/nt on gfx90a+))
  1675. [IntrWillReturn, NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
  1676. ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, IntrNoCallback, IntrNoFree],
  1677. "", [SDNPMemOperand]>;
  1678. def int_amdgcn_global_load_lds : AMDGPUGlobalLoadLDS;
  1679. //===----------------------------------------------------------------------===//
  1680. // GFX10 Intrinsics
  1681. //===----------------------------------------------------------------------===//
  1682. // llvm.amdgcn.permlane16 <old> <src0> <src1> <src2> <fi> <bound_control>
  1683. def int_amdgcn_permlane16 : ClangBuiltin<"__builtin_amdgcn_permlane16">,
  1684. Intrinsic<[llvm_i32_ty],
  1685. [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i1_ty],
  1686. [IntrNoMem, IntrConvergent, IntrWillReturn,
  1687. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>, IntrNoCallback, IntrNoFree]>;
  1688. // llvm.amdgcn.permlanex16 <old> <src0> <src1> <src2> <fi> <bound_control>
  1689. def int_amdgcn_permlanex16 : ClangBuiltin<"__builtin_amdgcn_permlanex16">,
  1690. Intrinsic<[llvm_i32_ty],
  1691. [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i1_ty],
  1692. [IntrNoMem, IntrConvergent, IntrWillReturn,
  1693. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>, IntrNoCallback, IntrNoFree]>;
  1694. // llvm.amdgcn.mov.dpp8.i32 <src> <sel>
  1695. // <sel> is a 32-bit constant whose high 8 bits must be zero which selects
  1696. // the lanes to read from.
  1697. def int_amdgcn_mov_dpp8 :
  1698. Intrinsic<[llvm_anyint_ty],
  1699. [LLVMMatchType<0>, llvm_i32_ty],
  1700. [IntrNoMem, IntrConvergent, IntrWillReturn,
  1701. ImmArg<ArgIndex<1>>, IntrNoCallback, IntrNoFree]>;
  1702. def int_amdgcn_s_get_waveid_in_workgroup :
  1703. ClangBuiltin<"__builtin_amdgcn_s_get_waveid_in_workgroup">,
  1704. Intrinsic<[llvm_i32_ty], [],
  1705. [IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1706. class AMDGPUGlobalAtomicRtn<LLVMType vt> : Intrinsic <
  1707. [vt],
  1708. [llvm_anyptr_ty, // vaddr
  1709. vt], // vdata(VGPR)
  1710. [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>, IntrNoCallback, IntrNoFree], "",
  1711. [SDNPMemOperand]>;
  1712. def int_amdgcn_global_atomic_csub : AMDGPUGlobalAtomicRtn<llvm_i32_ty>;
  1713. // uint4 llvm.amdgcn.image.bvh.intersect.ray <node_ptr>, <ray_extent>, <ray_origin>,
  1714. // <ray_dir>, <ray_inv_dir>, <texture_descr>
  1715. // <node_ptr> is i32 or i64.
  1716. // <ray_dir> and <ray_inv_dir> are both v3f16 or both v3f32.
  1717. def int_amdgcn_image_bvh_intersect_ray :
  1718. DefaultAttrsIntrinsic<[llvm_v4i32_ty],
  1719. [llvm_anyint_ty, llvm_float_ty, llvm_v3f32_ty, llvm_anyvector_ty,
  1720. LLVMMatchType<1>, llvm_v4i32_ty],
  1721. [IntrReadMem, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1722. //===----------------------------------------------------------------------===//
  1723. // GFX11 Intrinsics
  1724. //===----------------------------------------------------------------------===//
  1725. // llvm.amdgcn.permlane64 <src0>
  1726. def int_amdgcn_permlane64 :
  1727. ClangBuiltin<"__builtin_amdgcn_permlane64">,
  1728. Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
  1729. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1730. def int_amdgcn_ds_add_gs_reg_rtn :
  1731. ClangBuiltin<"__builtin_amdgcn_ds_add_gs_reg_rtn">,
  1732. Intrinsic<[llvm_anyint_ty], [llvm_i32_ty, llvm_i32_ty],
  1733. [ImmArg<ArgIndex<1>>, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1734. def int_amdgcn_ds_sub_gs_reg_rtn :
  1735. ClangBuiltin<"__builtin_amdgcn_ds_sub_gs_reg_rtn">,
  1736. Intrinsic<[llvm_anyint_ty], [llvm_i32_ty, llvm_i32_ty],
  1737. [ImmArg<ArgIndex<1>>, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  1738. def int_amdgcn_ds_bvh_stack_rtn :
  1739. Intrinsic<
  1740. [llvm_i32_ty, llvm_i32_ty], // %vdst, %addr
  1741. [
  1742. llvm_i32_ty, // %addr
  1743. llvm_i32_ty, // %data0
  1744. llvm_v4i32_ty, // %data1
  1745. llvm_i32_ty, // %offset
  1746. ],
  1747. [ImmArg<ArgIndex<3>>, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1748. >;
  1749. // WMMA (Wave Matrix Multiply-Accumulate) intrinsics
  1750. //
  1751. // These operations perform a matrix multiplication and accumulation of
  1752. // the form: D = A * B + C .
  1753. class AMDGPUWmmaIntrinsic<LLVMType AB, LLVMType CD> :
  1754. Intrinsic<
  1755. [CD], // %D
  1756. [
  1757. AB, // %A
  1758. AB, // %B
  1759. LLVMMatchType<0>, // %C
  1760. ],
  1761. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1762. >;
  1763. class AMDGPUWmmaIntrinsicOPSEL<LLVMType AB, LLVMType CD> :
  1764. Intrinsic<
  1765. [CD], // %D
  1766. [
  1767. AB, // %A
  1768. AB, // %B
  1769. LLVMMatchType<0>, // %C
  1770. llvm_i1_ty, // %high
  1771. ],
  1772. [IntrNoMem, IntrConvergent, ImmArg<ArgIndex<3>>, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1773. >;
  1774. class AMDGPUWmmaIntrinsicIU<LLVMType AB, LLVMType CD> :
  1775. Intrinsic<
  1776. [CD], // %D
  1777. [
  1778. llvm_i1_ty, // %A_sign
  1779. AB, // %A
  1780. llvm_i1_ty, // %B_sign
  1781. AB, // %B
  1782. LLVMMatchType<0>, // %C
  1783. llvm_i1_ty, // %clamp
  1784. ],
  1785. [IntrNoMem, IntrConvergent, ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<5>>, IntrWillReturn, IntrNoCallback, IntrNoFree]
  1786. >;
  1787. def int_amdgcn_wmma_f32_16x16x16_f16 : AMDGPUWmmaIntrinsic<llvm_v16f16_ty, llvm_anyfloat_ty>;
  1788. def int_amdgcn_wmma_f32_16x16x16_bf16 : AMDGPUWmmaIntrinsic<llvm_v16i16_ty, llvm_anyfloat_ty>;
  1789. def int_amdgcn_wmma_f16_16x16x16_f16 : AMDGPUWmmaIntrinsicOPSEL<llvm_v16f16_ty, llvm_anyfloat_ty>;
  1790. def int_amdgcn_wmma_bf16_16x16x16_bf16 : AMDGPUWmmaIntrinsicOPSEL<llvm_v16i16_ty, llvm_anyint_ty>;
  1791. def int_amdgcn_wmma_i32_16x16x16_iu8 : AMDGPUWmmaIntrinsicIU<llvm_v4i32_ty, llvm_anyint_ty>;
  1792. def int_amdgcn_wmma_i32_16x16x16_iu4 : AMDGPUWmmaIntrinsicIU<llvm_v2i32_ty, llvm_anyint_ty>;
  1793. def int_amdgcn_s_wait_event_export_ready :
  1794. ClangBuiltin<"__builtin_amdgcn_s_wait_event_export_ready">,
  1795. Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]
  1796. >;
  1797. //===----------------------------------------------------------------------===//
  1798. // Deep learning intrinsics.
  1799. //===----------------------------------------------------------------------===//
  1800. // f32 %r = llvm.amdgcn.fdot2(v2f16 %a, v2f16 %b, f32 %c, i1 %clamp)
  1801. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1802. def int_amdgcn_fdot2 :
  1803. ClangBuiltin<"__builtin_amdgcn_fdot2">,
  1804. DefaultAttrsIntrinsic<
  1805. [llvm_float_ty], // %r
  1806. [
  1807. llvm_v2f16_ty, // %a
  1808. llvm_v2f16_ty, // %b
  1809. llvm_float_ty, // %c
  1810. llvm_i1_ty // %clamp
  1811. ],
  1812. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1813. >;
  1814. // f16 %r = llvm.amdgcn.fdot2.f16.f16(v2f16 %a, v2f16 %b, f16 %c)
  1815. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1816. def int_amdgcn_fdot2_f16_f16 :
  1817. ClangBuiltin<"__builtin_amdgcn_fdot2_f16_f16">,
  1818. DefaultAttrsIntrinsic<
  1819. [llvm_half_ty], // %r
  1820. [
  1821. llvm_v2f16_ty, // %a
  1822. llvm_v2f16_ty, // %b
  1823. llvm_half_ty // %c
  1824. ],
  1825. [IntrNoMem, IntrSpeculatable]
  1826. >;
  1827. // bf16 %r = llvm.amdgcn.fdot2.bf16.bf16(v2bf16 %a, v2bf16 %b, bf16 %c)
  1828. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1829. def int_amdgcn_fdot2_bf16_bf16 :
  1830. ClangBuiltin<"__builtin_amdgcn_fdot2_bf16_bf16">,
  1831. DefaultAttrsIntrinsic<
  1832. [llvm_i16_ty], // %r
  1833. [
  1834. llvm_v2i16_ty, // %a
  1835. llvm_v2i16_ty, // %b
  1836. llvm_i16_ty // %c
  1837. ],
  1838. [IntrNoMem, IntrSpeculatable]
  1839. >;
  1840. // f32 %r = llvm.amdgcn.fdot2.f32.bf16(v2bf16 %a, v2bf16 %b, f32 %c, i1 %clamp)
  1841. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1842. def int_amdgcn_fdot2_f32_bf16 :
  1843. ClangBuiltin<"__builtin_amdgcn_fdot2_f32_bf16">,
  1844. DefaultAttrsIntrinsic<
  1845. [llvm_float_ty], // %r
  1846. [
  1847. llvm_v2i16_ty, // %a
  1848. llvm_v2i16_ty, // %b
  1849. llvm_float_ty, // %c
  1850. llvm_i1_ty // %clamp
  1851. ],
  1852. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1853. >;
  1854. // i32 %r = llvm.amdgcn.sdot2(v2i16 %a, v2i16 %b, i32 %c, i1 %clamp)
  1855. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1856. def int_amdgcn_sdot2 :
  1857. ClangBuiltin<"__builtin_amdgcn_sdot2">,
  1858. DefaultAttrsIntrinsic<
  1859. [llvm_i32_ty], // %r
  1860. [
  1861. llvm_v2i16_ty, // %a
  1862. llvm_v2i16_ty, // %b
  1863. llvm_i32_ty, // %c
  1864. llvm_i1_ty // %clamp
  1865. ],
  1866. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1867. >;
  1868. // u32 %r = llvm.amdgcn.udot2(v2u16 %a, v2u16 %b, u32 %c, i1 %clamp)
  1869. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
  1870. def int_amdgcn_udot2 :
  1871. ClangBuiltin<"__builtin_amdgcn_udot2">,
  1872. DefaultAttrsIntrinsic<
  1873. [llvm_i32_ty], // %r
  1874. [
  1875. llvm_v2i16_ty, // %a
  1876. llvm_v2i16_ty, // %b
  1877. llvm_i32_ty, // %c
  1878. llvm_i1_ty // %clamp
  1879. ],
  1880. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1881. >;
  1882. // i32 %r = llvm.amdgcn.sdot4(v4i8 (as i32) %a, v4i8 (as i32) %b, i32 %c, i1 %clamp)
  1883. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] + %c
  1884. def int_amdgcn_sdot4 :
  1885. ClangBuiltin<"__builtin_amdgcn_sdot4">,
  1886. DefaultAttrsIntrinsic<
  1887. [llvm_i32_ty], // %r
  1888. [
  1889. llvm_i32_ty, // %a
  1890. llvm_i32_ty, // %b
  1891. llvm_i32_ty, // %c
  1892. llvm_i1_ty // %clamp
  1893. ],
  1894. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1895. >;
  1896. // u32 %r = llvm.amdgcn.udot4(v4u8 (as u32) %a, v4u8 (as u32) %b, u32 %c, i1 %clamp)
  1897. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] + %c
  1898. def int_amdgcn_udot4 :
  1899. ClangBuiltin<"__builtin_amdgcn_udot4">,
  1900. DefaultAttrsIntrinsic<
  1901. [llvm_i32_ty], // %r
  1902. [
  1903. llvm_i32_ty, // %a
  1904. llvm_i32_ty, // %b
  1905. llvm_i32_ty, // %c
  1906. llvm_i1_ty // %clamp
  1907. ],
  1908. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1909. >;
  1910. // i32 %r = llvm.amdgcn.sudot4(i1 %a_sign, v4i8 (as i32) %a, i1 %b_sign, v4i8 (as i32) %b, i32 %c, i1 %clamp)
  1911. // Treat input as signed (_sign = 1) or unsigned (_sign = 0).
  1912. // a[i in 0. . . 3] = (%a_sign ? a.i8[i] : promoteToSigned(a.u8[i]));
  1913. // b[i in 0. . . 3] = (%b_sign ? b.i8[i] : promoteToSigned(b.u8[i]));
  1914. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] + %c
  1915. def int_amdgcn_sudot4 :
  1916. ClangBuiltin<"__builtin_amdgcn_sudot4">,
  1917. DefaultAttrsIntrinsic<
  1918. [llvm_i32_ty], // %r
  1919. [
  1920. llvm_i1_ty, // %a_sign
  1921. llvm_i32_ty, // %a
  1922. llvm_i1_ty, // %b_sign
  1923. llvm_i32_ty, // %b
  1924. llvm_i32_ty, // %c
  1925. llvm_i1_ty // %clamp
  1926. ],
  1927. [IntrNoMem, IntrSpeculatable,
  1928. ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<5>>]
  1929. >;
  1930. // i32 %r = llvm.amdgcn.sdot8(v8i4 (as i32) %a, v8i4 (as i32) %b, i32 %c, i1 %clamp)
  1931. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] +
  1932. // %a[4] * %b[4] + %a[5] * %b[5] + %a[6] * %b[6] + %a[7] * %b[7] + %c
  1933. def int_amdgcn_sdot8 :
  1934. ClangBuiltin<"__builtin_amdgcn_sdot8">,
  1935. DefaultAttrsIntrinsic<
  1936. [llvm_i32_ty], // %r
  1937. [
  1938. llvm_i32_ty, // %a
  1939. llvm_i32_ty, // %b
  1940. llvm_i32_ty, // %c
  1941. llvm_i1_ty // %clamp
  1942. ],
  1943. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1944. >;
  1945. // u32 %r = llvm.amdgcn.udot8(v8u4 (as u32) %a, v8u4 (as u32) %b, u32 %c, i1 %clamp)
  1946. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] +
  1947. // %a[4] * %b[4] + %a[5] * %b[5] + %a[6] * %b[6] + %a[7] * %b[7] + %c
  1948. def int_amdgcn_udot8 :
  1949. ClangBuiltin<"__builtin_amdgcn_udot8">,
  1950. DefaultAttrsIntrinsic<
  1951. [llvm_i32_ty], // %r
  1952. [
  1953. llvm_i32_ty, // %a
  1954. llvm_i32_ty, // %b
  1955. llvm_i32_ty, // %c
  1956. llvm_i1_ty // %clamp
  1957. ],
  1958. [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
  1959. >;
  1960. // i32 %r = llvm.amdgcn.sudot8(i1 %a_sign, v8i4 (as i32) %a, i1 %b_sign, v8i4 (as i32) %b, i32 %c, i1 %clamp)
  1961. // Treat input as signed (_sign = 1) or unsigned (_sign = 0).
  1962. // a[i in 0. . . 7] = (%a_sign ? a.i4[i] : promoteToSigned(a.u4[i]));
  1963. // b[i in 0. . . 7] = (%b_sign ? b.i4[i] : promoteToSigned(b.u4[i]));
  1964. // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] +
  1965. // %a[4] * %b[4] + %a[5] * %b[5] + %a[6] * %b[6] + %a[7] * %b[7] + %c
  1966. def int_amdgcn_sudot8 :
  1967. ClangBuiltin<"__builtin_amdgcn_sudot8">,
  1968. DefaultAttrsIntrinsic<
  1969. [llvm_i32_ty], // %r
  1970. [
  1971. llvm_i1_ty, // %a_sign
  1972. llvm_i32_ty, // %a
  1973. llvm_i1_ty, // %b_sign
  1974. llvm_i32_ty, // %b
  1975. llvm_i32_ty, // %c
  1976. llvm_i1_ty // %clamp
  1977. ],
  1978. [IntrNoMem, IntrSpeculatable,
  1979. ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<5>>]
  1980. >;
  1981. //===----------------------------------------------------------------------===//
  1982. // gfx908 intrinsics
  1983. // ===----------------------------------------------------------------------===//
  1984. def int_amdgcn_global_atomic_fadd : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  1985. // llvm.amdgcn.mfma.*.* vdst, srcA, srcB, srcC, cbsz, abid, blgp
  1986. class AMDGPUMfmaIntrinsic<LLVMType DestTy, LLVMType SrcABTy> :
  1987. ClangBuiltin<!subst("int", "__builtin", NAME)>,
  1988. DefaultAttrsIntrinsic<[DestTy],
  1989. [SrcABTy, SrcABTy, DestTy,
  1990. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  1991. [IntrConvergent, IntrNoMem,
  1992. ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
  1993. def int_amdgcn_mfma_f32_32x32x1f32 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_float_ty>;
  1994. def int_amdgcn_mfma_f32_16x16x1f32 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_float_ty>;
  1995. def int_amdgcn_mfma_f32_4x4x1f32 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_float_ty>;
  1996. def int_amdgcn_mfma_f32_32x32x2f32 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_float_ty>;
  1997. def int_amdgcn_mfma_f32_16x16x4f32 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_float_ty>;
  1998. def int_amdgcn_mfma_f32_32x32x4f16 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v4f16_ty>;
  1999. def int_amdgcn_mfma_f32_16x16x4f16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4f16_ty>;
  2000. def int_amdgcn_mfma_f32_4x4x4f16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4f16_ty>;
  2001. def int_amdgcn_mfma_f32_32x32x8f16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4f16_ty>;
  2002. def int_amdgcn_mfma_f32_16x16x16f16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4f16_ty>;
  2003. def int_amdgcn_mfma_i32_32x32x4i8 : AMDGPUMfmaIntrinsic<llvm_v32i32_ty, llvm_i32_ty>;
  2004. def int_amdgcn_mfma_i32_16x16x4i8 : AMDGPUMfmaIntrinsic<llvm_v16i32_ty, llvm_i32_ty>;
  2005. def int_amdgcn_mfma_i32_4x4x4i8 : AMDGPUMfmaIntrinsic<llvm_v4i32_ty, llvm_i32_ty>;
  2006. def int_amdgcn_mfma_i32_32x32x8i8 : AMDGPUMfmaIntrinsic<llvm_v16i32_ty, llvm_i32_ty>;
  2007. def int_amdgcn_mfma_i32_16x16x16i8 : AMDGPUMfmaIntrinsic<llvm_v4i32_ty, llvm_i32_ty>;
  2008. def int_amdgcn_mfma_f32_32x32x2bf16 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v2i16_ty>;
  2009. def int_amdgcn_mfma_f32_16x16x2bf16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v2i16_ty>;
  2010. def int_amdgcn_mfma_f32_4x4x2bf16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v2i16_ty>;
  2011. def int_amdgcn_mfma_f32_32x32x4bf16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v2i16_ty>;
  2012. def int_amdgcn_mfma_f32_16x16x8bf16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v2i16_ty>;
  2013. //===----------------------------------------------------------------------===//
  2014. // gfx90a intrinsics
  2015. // ===----------------------------------------------------------------------===//
  2016. def int_amdgcn_global_atomic_fmin : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  2017. def int_amdgcn_global_atomic_fmax : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  2018. def int_amdgcn_flat_atomic_fadd : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  2019. def int_amdgcn_flat_atomic_fmin : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  2020. def int_amdgcn_flat_atomic_fmax : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
  2021. def int_amdgcn_mfma_f32_32x32x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v4i16_ty>;
  2022. def int_amdgcn_mfma_f32_16x16x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4i16_ty>;
  2023. def int_amdgcn_mfma_f32_4x4x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4i16_ty>;
  2024. def int_amdgcn_mfma_f32_32x32x8bf16_1k : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4i16_ty>;
  2025. def int_amdgcn_mfma_f32_16x16x16bf16_1k : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4i16_ty>;
  2026. // Note: in gfx940 BLGP argument is replaced by NEG bitfield in the DGEMM MFMA.
  2027. // Three bits corresponding to the neg modifier applied to the respective
  2028. // source operand.
  2029. def int_amdgcn_mfma_f64_16x16x4f64 : AMDGPUMfmaIntrinsic<llvm_v4f64_ty, llvm_double_ty>;
  2030. def int_amdgcn_mfma_f64_4x4x4f64 : AMDGPUMfmaIntrinsic<llvm_double_ty, llvm_double_ty>;
  2031. //===----------------------------------------------------------------------===//
  2032. // gfx940 intrinsics
  2033. // ===----------------------------------------------------------------------===//
  2034. // bf16 atomics use v2i16 argument since there is no bf16 data type in the llvm.
  2035. def int_amdgcn_global_atomic_fadd_v2bf16 : AMDGPUGlobalAtomicRtn<llvm_v2i16_ty>;
  2036. def int_amdgcn_flat_atomic_fadd_v2bf16 : AMDGPUGlobalAtomicRtn<llvm_v2i16_ty>;
  2037. def int_amdgcn_ds_fadd_v2bf16 : DefaultAttrsIntrinsic<
  2038. [llvm_v2i16_ty],
  2039. [LLVMQualPointerType<llvm_v2i16_ty, 3>, llvm_v2i16_ty],
  2040. [IntrArgMemOnly, NoCapture<ArgIndex<0>>]>,
  2041. ClangBuiltin<"__builtin_amdgcn_ds_atomic_fadd_v2bf16">;
  2042. def int_amdgcn_mfma_i32_16x16x32_i8 : AMDGPUMfmaIntrinsic<llvm_v4i32_ty, llvm_i64_ty>;
  2043. def int_amdgcn_mfma_i32_32x32x16_i8 : AMDGPUMfmaIntrinsic<llvm_v16i32_ty, llvm_i64_ty>;
  2044. def int_amdgcn_mfma_f32_16x16x8_xf32 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v2f32_ty>;
  2045. def int_amdgcn_mfma_f32_32x32x4_xf32 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v2f32_ty>;
  2046. class AMDGPUMFp8MfmaIntrinsic<LLVMType DestTy> :
  2047. AMDGPUMfmaIntrinsic<DestTy, llvm_i64_ty>;
  2048. multiclass AMDGPUMFp8MfmaIntrinsic<LLVMType DestTy> {
  2049. foreach kind = ["bf8_bf8", "bf8_fp8", "fp8_bf8", "fp8_fp8"] in
  2050. def NAME#"_"#kind : AMDGPUMFp8MfmaIntrinsic<DestTy>;
  2051. }
  2052. defm int_amdgcn_mfma_f32_16x16x32 : AMDGPUMFp8MfmaIntrinsic<llvm_v4f32_ty>;
  2053. defm int_amdgcn_mfma_f32_32x32x16 : AMDGPUMFp8MfmaIntrinsic<llvm_v16f32_ty>;
  2054. // llvm.amdgcn.smfmac.?32.* vdst, srcA, srcB, srcC, index, cbsz, abid
  2055. class AMDGPUMSmfmacIntrinsic<LLVMType DestTy, LLVMType SrcA, LLVMType SrcB> :
  2056. ClangBuiltin<!subst("int", "__builtin", NAME)>,
  2057. DefaultAttrsIntrinsic<[DestTy],
  2058. [SrcA, SrcB, DestTy, llvm_i32_ty,
  2059. llvm_i32_ty, llvm_i32_ty],
  2060. [IntrConvergent, IntrNoMem,
  2061. ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
  2062. def int_amdgcn_smfmac_f32_16x16x32_f16 : AMDGPUMSmfmacIntrinsic<llvm_v4f32_ty, llvm_v4f16_ty, llvm_v8f16_ty>;
  2063. def int_amdgcn_smfmac_f32_32x32x16_f16 : AMDGPUMSmfmacIntrinsic<llvm_v16f32_ty, llvm_v4f16_ty, llvm_v8f16_ty>;
  2064. def int_amdgcn_smfmac_f32_16x16x32_bf16 : AMDGPUMSmfmacIntrinsic<llvm_v4f32_ty, llvm_v4i16_ty, llvm_v8i16_ty>;
  2065. def int_amdgcn_smfmac_f32_32x32x16_bf16 : AMDGPUMSmfmacIntrinsic<llvm_v16f32_ty, llvm_v4i16_ty, llvm_v8i16_ty>;
  2066. def int_amdgcn_smfmac_i32_16x16x64_i8 : AMDGPUMSmfmacIntrinsic<llvm_v4i32_ty, llvm_v2i32_ty, llvm_v4i32_ty>;
  2067. def int_amdgcn_smfmac_i32_32x32x32_i8 : AMDGPUMSmfmacIntrinsic<llvm_v16i32_ty, llvm_v2i32_ty, llvm_v4i32_ty>;
  2068. class AMDGPUMFp8SmfmacIntrinsic<LLVMType DestTy> :
  2069. AMDGPUMSmfmacIntrinsic<DestTy, llvm_v2i32_ty, llvm_v4i32_ty>;
  2070. multiclass AMDGPUMFp8SmfmacIntrinsic<LLVMType DestTy> {
  2071. foreach kind = ["bf8_bf8", "bf8_fp8", "fp8_bf8", "fp8_fp8"] in
  2072. def NAME#"_"#kind : AMDGPUMFp8SmfmacIntrinsic<DestTy>;
  2073. }
  2074. defm int_amdgcn_smfmac_f32_16x16x64 : AMDGPUMFp8SmfmacIntrinsic<llvm_v4f32_ty>;
  2075. defm int_amdgcn_smfmac_f32_32x32x32 : AMDGPUMFp8SmfmacIntrinsic<llvm_v16f32_ty>;
  2076. // llvm.amdgcn.cvt.f32.bf8 float vdst, int srcA, imm byte_sel [0..3]
  2077. // byte_sel selects byte from srcA.
  2078. def int_amdgcn_cvt_f32_bf8 : ClangBuiltin<"__builtin_amdgcn_cvt_f32_bf8">,
  2079. DefaultAttrsIntrinsic<[llvm_float_ty],
  2080. [llvm_i32_ty, llvm_i32_ty],
  2081. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  2082. // llvm.amdgcn.cvt.f32.fp8 float vdst, int srcA, imm byte_sel [0..3]
  2083. def int_amdgcn_cvt_f32_fp8 : ClangBuiltin<"__builtin_amdgcn_cvt_f32_fp8">,
  2084. DefaultAttrsIntrinsic<[llvm_float_ty],
  2085. [llvm_i32_ty, llvm_i32_ty],
  2086. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  2087. // llvm.amdgcn.cvt.pk.f32.bf8 float2 vdst, int srcA, imm word_sel
  2088. // word_sel = 1 selects 2 high bytes, 0 selects 2 low bytes.
  2089. def int_amdgcn_cvt_pk_f32_bf8 : ClangBuiltin<"__builtin_amdgcn_cvt_pk_f32_bf8">,
  2090. DefaultAttrsIntrinsic<[llvm_v2f32_ty],
  2091. [llvm_i32_ty, llvm_i1_ty],
  2092. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  2093. // llvm.amdgcn.cvt.pk.f32.fp8 float2 vdst, int srcA, imm word_sel.
  2094. def int_amdgcn_cvt_pk_f32_fp8 : ClangBuiltin<"__builtin_amdgcn_cvt_pk_f32_fp8">,
  2095. DefaultAttrsIntrinsic<[llvm_v2f32_ty],
  2096. [llvm_i32_ty, llvm_i1_ty],
  2097. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  2098. // llvm.amdgcn.cvt.pk.bf8.f32 int vdst, float srcA, float srcB, int old, imm word_sel
  2099. // word_sel = 1 selects 2 high bytes in the vdst, 0 selects 2 low bytes.
  2100. def int_amdgcn_cvt_pk_bf8_f32 : ClangBuiltin<"__builtin_amdgcn_cvt_pk_bf8_f32">,
  2101. DefaultAttrsIntrinsic<[llvm_i32_ty],
  2102. [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i1_ty],
  2103. [IntrNoMem, ImmArg<ArgIndex<3>>]>;
  2104. // llvm.amdgcn.cvt.pk.fp8.f32 int vdst, float srcA, float srcB, int old, imm word_sel
  2105. def int_amdgcn_cvt_pk_fp8_f32 : ClangBuiltin<"__builtin_amdgcn_cvt_pk_fp8_f32">,
  2106. DefaultAttrsIntrinsic<[llvm_i32_ty],
  2107. [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i1_ty],
  2108. [IntrNoMem, ImmArg<ArgIndex<3>>]>;
  2109. // llvm.amdgcn.cvt.sr.bf8.f32 int vdst, float srcA, int srcB, int old, imm byte_sel [0..3]
  2110. // byte_sel selects byte to write into vdst.
  2111. def int_amdgcn_cvt_sr_bf8_f32 : ClangBuiltin<"__builtin_amdgcn_cvt_sr_bf8_f32">,
  2112. DefaultAttrsIntrinsic<[llvm_i32_ty],
  2113. [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  2114. [IntrNoMem, ImmArg<ArgIndex<3>>]>;
  2115. // llvm.amdgcn.cvt.sr.fp8.f32 int vdst, float srcA, int srcB, int old, imm byte_sel [0..3]
  2116. def int_amdgcn_cvt_sr_fp8_f32 : ClangBuiltin<"__builtin_amdgcn_cvt_sr_fp8_f32">,
  2117. DefaultAttrsIntrinsic<[llvm_i32_ty],
  2118. [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  2119. [IntrNoMem, ImmArg<ArgIndex<3>>]>;
  2120. // Represent a relocation constant.
  2121. def int_amdgcn_reloc_constant : DefaultAttrsIntrinsic<
  2122. [llvm_i32_ty], [llvm_metadata_ty],
  2123. [IntrNoMem, IntrSpeculatable]
  2124. >;
  2125. //===----------------------------------------------------------------------===//
  2126. // Special Intrinsics for backend internal use only. No frontend
  2127. // should emit calls to these.
  2128. // ===----------------------------------------------------------------------===//
  2129. def int_amdgcn_if : Intrinsic<[llvm_i1_ty, llvm_anyint_ty],
  2130. [llvm_i1_ty], [IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  2131. >;
  2132. def int_amdgcn_else : Intrinsic<[llvm_i1_ty, llvm_anyint_ty],
  2133. [llvm_anyint_ty], [IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  2134. >;
  2135. def int_amdgcn_if_break : Intrinsic<[llvm_anyint_ty],
  2136. [llvm_i1_ty, LLVMMatchType<0>],
  2137. [IntrNoMem, IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  2138. >;
  2139. def int_amdgcn_loop : Intrinsic<[llvm_i1_ty],
  2140. [llvm_anyint_ty], [IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]
  2141. >;
  2142. def int_amdgcn_end_cf : Intrinsic<[], [llvm_anyint_ty],
  2143. [IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
  2144. // Represent unreachable in a divergent region.
  2145. def int_amdgcn_unreachable : Intrinsic<[], [], [IntrConvergent, IntrNoCallback, IntrNoFree]>;
  2146. // Emit 2.5 ulp, no denormal division. Should only be inserted by
  2147. // pass based on !fpmath metadata.
  2148. def int_amdgcn_fdiv_fast : DefaultAttrsIntrinsic<
  2149. [llvm_float_ty], [llvm_float_ty, llvm_float_ty],
  2150. [IntrNoMem, IntrSpeculatable]
  2151. >;
  2152. }