hsa-common.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. /* HSAIL and BRIG related macros and definitions.
  2. Copyright (C) 2013-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef HSA_H
  16. #define HSA_H
  17. #include "hsa-brig-format.h"
  18. #include "is-a.h"
  19. #include "predict.h"
  20. #include "tree.h"
  21. #include "vec.h"
  22. #include "hash-table.h"
  23. #include "basic-block.h"
  24. #include "bitmap.h"
  25. /* Return true if the compiler should produce HSAIL. */
  26. static inline bool
  27. hsa_gen_requested_p (void)
  28. {
  29. #ifndef ENABLE_HSA
  30. return false;
  31. #endif
  32. return !flag_disable_hsa;
  33. }
  34. /* Standard warning message if we failed to generate HSAIL for a function. */
  35. #define HSA_SORRY_MSG "could not emit HSAIL for the function"
  36. class hsa_op_immed;
  37. class hsa_op_cst_list;
  38. class hsa_insn_basic;
  39. class hsa_op_address;
  40. class hsa_op_reg;
  41. class hsa_bb;
  42. /* Class representing an input argument, output argument (result) or a
  43. variable, that will eventually end up being a symbol directive. */
  44. struct hsa_symbol
  45. {
  46. /* Constructor. */
  47. hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
  48. BrigLinkage8_t linkage, bool global_scope_p = false,
  49. BrigAllocation allocation = BRIG_ALLOCATION_AUTOMATIC,
  50. BrigAlignment8_t align = BRIG_ALIGNMENT_8);
  51. /* Return total size of the symbol. */
  52. unsigned HOST_WIDE_INT total_byte_size ();
  53. /* Fill in those values into the symbol according to DECL, which are
  54. determined independently from whether it is parameter, result,
  55. or a variable, local or global. */
  56. void fillup_for_decl (tree decl);
  57. /* Pointer to the original tree, which is PARM_DECL for input parameters and
  58. RESULT_DECL for the output parameters. Also can be CONST_DECL for Fortran
  59. constants which need to be put into readonly segment. */
  60. tree m_decl;
  61. /* Name of the symbol, that will be written into output and dumps. Can be
  62. NULL, see name_number below. */
  63. const char *m_name;
  64. /* If name is NULL, artificial name will be formed from the segment name and
  65. this number. */
  66. int m_name_number;
  67. /* Once written, this is the offset of the associated symbol directive. Zero
  68. means the symbol has not been written yet. */
  69. unsigned m_directive_offset;
  70. /* HSA type of the parameter. */
  71. BrigType16_t m_type;
  72. /* The HSA segment this will eventually end up in. */
  73. BrigSegment8_t m_segment;
  74. /* The HSA kind of linkage. */
  75. BrigLinkage8_t m_linkage;
  76. /* Array dimension, if non-zero. */
  77. unsigned HOST_WIDE_INT m_dim;
  78. /* Constant value, used for string constants. */
  79. hsa_op_immed *m_cst_value;
  80. /* Is in global scope. */
  81. bool m_global_scope_p;
  82. /* True if an error has been seen for the symbol. */
  83. bool m_seen_error;
  84. /* Symbol allocation. */
  85. BrigAllocation m_allocation;
  86. /* Flag used for global variables if a variable is already emitted or not. */
  87. bool m_emitted_to_brig;
  88. /* Alignment of the symbol. */
  89. BrigAlignment8_t m_align;
  90. private:
  91. /* Default constructor. */
  92. hsa_symbol ();
  93. };
  94. /* Abstract class for HSA instruction operands. */
  95. class hsa_op_base
  96. {
  97. public:
  98. /* Next operand scheduled to be written when writing BRIG operand
  99. section. */
  100. hsa_op_base *m_next;
  101. /* Offset to which the associated operand structure will be written. Zero if
  102. yet not scheduled for writing. */
  103. unsigned m_brig_op_offset;
  104. /* The type of a particular operand. */
  105. BrigKind16_t m_kind;
  106. protected:
  107. hsa_op_base (BrigKind16_t k);
  108. private:
  109. /* Make the default constructor inaccessible. */
  110. hsa_op_base () {}
  111. };
  112. /* Common abstract ancestor for operands which have a type. */
  113. class hsa_op_with_type : public hsa_op_base
  114. {
  115. public:
  116. /* The type. */
  117. BrigType16_t m_type;
  118. /* Convert an operand to a destination type DTYPE and attach insns
  119. to HBB if needed. */
  120. hsa_op_with_type *get_in_type (BrigType16_t dtype, hsa_bb *hbb);
  121. /* If this operand has integer type smaller than 32 bits, extend it to 32
  122. bits, adding instructions to HBB if needed. */
  123. hsa_op_with_type *extend_int_to_32bit (hsa_bb *hbb);
  124. protected:
  125. hsa_op_with_type (BrigKind16_t k, BrigType16_t t);
  126. private:
  127. /* Make the default constructor inaccessible. */
  128. hsa_op_with_type () : hsa_op_base (BRIG_KIND_NONE) {}
  129. };
  130. /* An immediate HSA operand. */
  131. class hsa_op_immed : public hsa_op_with_type
  132. {
  133. public:
  134. hsa_op_immed (tree tree_val, bool min32int = true);
  135. hsa_op_immed (HOST_WIDE_INT int_value, BrigType16_t type);
  136. void *operator new (size_t);
  137. ~hsa_op_immed ();
  138. void set_type (BrigKind16_t t);
  139. /* Function returns pointer to a buffer that contains binary representation
  140. of the immeadiate value. The buffer has length of BRIG_SIZE and
  141. a caller is responsible for deallocation of the buffer. */
  142. char *emit_to_buffer (unsigned *brig_size);
  143. /* Value as represented by middle end. */
  144. tree m_tree_value;
  145. /* Integer value representation. */
  146. HOST_WIDE_INT m_int_value;
  147. private:
  148. /* Make the default constructor inaccessible. */
  149. hsa_op_immed ();
  150. /* All objects are deallocated by destroying their pool, so make delete
  151. inaccessible too. */
  152. void operator delete (void *) {}
  153. };
  154. /* Report whether or not P is a an immediate operand. */
  155. template <>
  156. template <>
  157. inline bool
  158. is_a_helper <hsa_op_immed *>::test (hsa_op_base *p)
  159. {
  160. return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES;
  161. }
  162. /* Likewise, but for a more specified base. */
  163. template <>
  164. template <>
  165. inline bool
  166. is_a_helper <hsa_op_immed *>::test (hsa_op_with_type *p)
  167. {
  168. return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES;
  169. }
  170. /* HSA register operand. */
  171. class hsa_op_reg : public hsa_op_with_type
  172. {
  173. friend class hsa_insn_basic;
  174. friend class hsa_insn_phi;
  175. public:
  176. hsa_op_reg (BrigType16_t t);
  177. void *operator new (size_t);
  178. /* Verify register operand. */
  179. void verify_ssa ();
  180. /* If NON-NULL, gimple SSA that we come from. NULL if none. */
  181. tree m_gimple_ssa;
  182. /* Defining instruction while still in the SSA. */
  183. hsa_insn_basic *m_def_insn;
  184. /* If the register allocator decides to spill the register, this is the
  185. appropriate spill symbol. */
  186. hsa_symbol *m_spill_sym;
  187. /* Number of this register structure in the order in which they were
  188. allocated. */
  189. int m_order;
  190. int m_lr_begin, m_lr_end;
  191. /* Zero if the register is not yet allocated. After, allocation, this must
  192. be 'c', 's', 'd' or 'q'. */
  193. char m_reg_class;
  194. /* If allocated, the number of the HW register (within its HSA register
  195. class). */
  196. char m_hard_num;
  197. private:
  198. /* Make the default constructor inaccessible. */
  199. hsa_op_reg () : hsa_op_with_type (BRIG_KIND_NONE, BRIG_TYPE_NONE) {}
  200. /* All objects are deallocated by destroying their pool, so make delete
  201. inaccessible too. */
  202. void operator delete (void *) {}
  203. /* Set definition where the register is defined. */
  204. void set_definition (hsa_insn_basic *insn);
  205. /* Uses of the value while still in SSA. */
  206. auto_vec <hsa_insn_basic *> m_uses;
  207. };
  208. /* Report whether or not P is a register operand. */
  209. template <>
  210. template <>
  211. inline bool
  212. is_a_helper <hsa_op_reg *>::test (hsa_op_base *p)
  213. {
  214. return p->m_kind == BRIG_KIND_OPERAND_REGISTER;
  215. }
  216. /* Report whether or not P is a register operand. */
  217. template <>
  218. template <>
  219. inline bool
  220. is_a_helper <hsa_op_reg *>::test (hsa_op_with_type *p)
  221. {
  222. return p->m_kind == BRIG_KIND_OPERAND_REGISTER;
  223. }
  224. /* An address HSA operand. */
  225. class hsa_op_address : public hsa_op_base
  226. {
  227. public:
  228. /* set up a new address operand consisting of base symbol SYM, register R and
  229. immediate OFFSET. If the machine model is not large and offset is 64 bit,
  230. the upper, 32 bits have to be zero. */
  231. hsa_op_address (hsa_symbol *sym, hsa_op_reg *reg,
  232. HOST_WIDE_INT offset = 0);
  233. void *operator new (size_t);
  234. /* Set up a new address operand consisting of base symbol SYM and
  235. immediate OFFSET. If the machine model is not large and offset is 64 bit,
  236. the upper, 32 bits have to be zero. */
  237. hsa_op_address (hsa_symbol *sym, HOST_WIDE_INT offset = 0);
  238. /* Set up a new address operand consisting of register R and
  239. immediate OFFSET. If the machine model is not large and offset is 64 bit,
  240. the upper, 32 bits have to be zero. */
  241. hsa_op_address (hsa_op_reg *reg, HOST_WIDE_INT offset = 0);
  242. /* Symbol base of the address. Can be NULL if there is none. */
  243. hsa_symbol *m_symbol;
  244. /* Register offset. Can be NULL if there is none. */
  245. hsa_op_reg *m_reg;
  246. /* Immediate byte offset. */
  247. HOST_WIDE_INT m_imm_offset;
  248. private:
  249. /* Make the default constructor inaccessible. */
  250. hsa_op_address () : hsa_op_base (BRIG_KIND_NONE) {}
  251. /* All objects are deallocated by destroying their pool, so make delete
  252. inaccessible too. */
  253. void operator delete (void *) {}
  254. };
  255. /* Report whether or not P is an address operand. */
  256. template <>
  257. template <>
  258. inline bool
  259. is_a_helper <hsa_op_address *>::test (hsa_op_base *p)
  260. {
  261. return p->m_kind == BRIG_KIND_OPERAND_ADDRESS;
  262. }
  263. /* A reference to code HSA operand. It can be either reference
  264. to a start of a BB or a start of a function. */
  265. class hsa_op_code_ref : public hsa_op_base
  266. {
  267. public:
  268. hsa_op_code_ref ();
  269. /* Offset in the code section that this refers to. */
  270. unsigned m_directive_offset;
  271. };
  272. /* Report whether or not P is a code reference operand. */
  273. template <>
  274. template <>
  275. inline bool
  276. is_a_helper <hsa_op_code_ref *>::test (hsa_op_base *p)
  277. {
  278. return p->m_kind == BRIG_KIND_OPERAND_CODE_REF;
  279. }
  280. /* Code list HSA operand. */
  281. class hsa_op_code_list: public hsa_op_base
  282. {
  283. public:
  284. hsa_op_code_list (unsigned elements);
  285. void *operator new (size_t);
  286. /* Offset to variable-sized array in hsa_data section, where
  287. are offsets to entries in the hsa_code section. */
  288. auto_vec<unsigned> m_offsets;
  289. private:
  290. /* Make the default constructor inaccessible. */
  291. hsa_op_code_list () : hsa_op_base (BRIG_KIND_NONE) {}
  292. /* All objects are deallocated by destroying their pool, so make delete
  293. inaccessible too. */
  294. void operator delete (void *) {}
  295. };
  296. /* Report whether or not P is a code list operand. */
  297. template <>
  298. template <>
  299. inline bool
  300. is_a_helper <hsa_op_code_list *>::test (hsa_op_base *p)
  301. {
  302. return p->m_kind == BRIG_KIND_OPERAND_CODE_LIST;
  303. }
  304. /* Operand list HSA operand. */
  305. class hsa_op_operand_list: public hsa_op_base
  306. {
  307. public:
  308. hsa_op_operand_list (unsigned elements);
  309. ~hsa_op_operand_list ();
  310. void *operator new (size_t);
  311. /* Offset to variable-sized array in hsa_data section, where
  312. are offsets to entries in the hsa_code section. */
  313. auto_vec<unsigned> m_offsets;
  314. private:
  315. /* Make the default constructor inaccessible. */
  316. hsa_op_operand_list () : hsa_op_base (BRIG_KIND_NONE) {}
  317. /* All objects are deallocated by destroying their pool, so make delete
  318. inaccessible too. */
  319. void operator delete (void *) {}
  320. };
  321. /* Report whether or not P is a code list operand. */
  322. template <>
  323. template <>
  324. inline bool
  325. is_a_helper <hsa_op_operand_list *>::test (hsa_op_base *p)
  326. {
  327. return p->m_kind == BRIG_KIND_OPERAND_OPERAND_LIST;
  328. }
  329. /* Opcodes of instructions that are not part of HSA but that we use to
  330. represent it nevertheless. */
  331. #define HSA_OPCODE_PHI (-1)
  332. #define HSA_OPCODE_ARG_BLOCK (-2)
  333. /* The number of operand pointers we can directly in an instruction. */
  334. #define HSA_BRIG_INT_STORAGE_OPERANDS 5
  335. /* Class representing an HSA instruction. Unlike typical ancestors for
  336. specialized classes, this one is also directly used for all instructions
  337. that are then represented as BrigInstBasic. */
  338. class hsa_insn_basic
  339. {
  340. public:
  341. hsa_insn_basic (unsigned nops, int opc);
  342. hsa_insn_basic (unsigned nops, int opc, BrigType16_t t,
  343. hsa_op_base *arg0 = NULL,
  344. hsa_op_base *arg1 = NULL,
  345. hsa_op_base *arg2 = NULL,
  346. hsa_op_base *arg3 = NULL);
  347. void *operator new (size_t);
  348. void set_op (int index, hsa_op_base *op);
  349. hsa_op_base *get_op (int index);
  350. hsa_op_base **get_op_addr (int index);
  351. unsigned int operand_count ();
  352. void verify ();
  353. unsigned input_count ();
  354. unsigned num_used_ops ();
  355. void set_output_in_type (hsa_op_reg *dest, unsigned op_index, hsa_bb *hbb);
  356. bool op_output_p (unsigned opnum);
  357. /* The previous and next instruction in the basic block. */
  358. hsa_insn_basic *m_prev, *m_next;
  359. /* Basic block this instruction belongs to. */
  360. basic_block m_bb;
  361. /* Operand code distinguishing different types of instructions. Eventually
  362. these should only be BRIG_INST_* values from the BrigOpcode16_t range but
  363. initially we use negative values for PHI nodes and such. */
  364. int m_opcode;
  365. /* Linearized number assigned to the instruction by HSA RA. */
  366. int m_number;
  367. /* Type of the destination of the operations. */
  368. BrigType16_t m_type;
  369. /* BRIG offset of the instruction in code section. */
  370. unsigned int m_brig_offset;
  371. private:
  372. /* Make the default constructor inaccessible. */
  373. hsa_insn_basic () {}
  374. /* All objects are deallocated by destroying their pool, so make delete
  375. inaccessible too. */
  376. void operator delete (void *) {}
  377. /* The individual operands. All instructions but PHI nodes have five or
  378. fewer instructions and so will fit the internal storage. */
  379. /* TODO: Vast majority of instructions have three or fewer operands, so we
  380. may actually try reducing it. */
  381. auto_vec<hsa_op_base *, HSA_BRIG_INT_STORAGE_OPERANDS> m_operands;
  382. };
  383. /* Class representing a PHI node of the SSA form of HSA virtual
  384. registers. */
  385. class hsa_insn_phi : public hsa_insn_basic
  386. {
  387. public:
  388. hsa_insn_phi (unsigned nops, hsa_op_reg *dst);
  389. /* Destination. */
  390. hsa_op_reg *m_dest;
  391. private:
  392. /* Make the default constructor inaccessible. */
  393. hsa_insn_phi () : hsa_insn_basic (1, HSA_OPCODE_PHI) {}
  394. };
  395. /* Report whether or not P is a PHI node. */
  396. template <>
  397. template <>
  398. inline bool
  399. is_a_helper <hsa_insn_phi *>::test (hsa_insn_basic *p)
  400. {
  401. return p->m_opcode == HSA_OPCODE_PHI;
  402. }
  403. /* HSA instruction for */
  404. class hsa_insn_br : public hsa_insn_basic
  405. {
  406. public:
  407. hsa_insn_br (unsigned nops, int opc, BrigType16_t t, BrigWidth8_t width,
  408. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  409. hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
  410. /* Number of work-items affected in the same way by the instruction. */
  411. BrigWidth8_t m_width;
  412. private:
  413. /* Make the default constructor inaccessible. */
  414. hsa_insn_br () : hsa_insn_basic (0, BRIG_OPCODE_BR) {}
  415. };
  416. /* Return true if P is a branching/synchronization instruction. */
  417. template <>
  418. template <>
  419. inline bool
  420. is_a_helper <hsa_insn_br *>::test (hsa_insn_basic *p)
  421. {
  422. return p->m_opcode == BRIG_OPCODE_BARRIER
  423. || p->m_opcode == BRIG_OPCODE_BR;
  424. }
  425. /* HSA instruction for conditional branches. Structurally the same as
  426. hsa_insn_br but we represent it specially because of inherent control
  427. flow it represents. */
  428. class hsa_insn_cbr : public hsa_insn_br
  429. {
  430. public:
  431. hsa_insn_cbr (hsa_op_reg *ctrl);
  432. private:
  433. /* Make the default constructor inaccessible. */
  434. hsa_insn_cbr () : hsa_insn_br (0, BRIG_OPCODE_CBR, BRIG_TYPE_B1,
  435. BRIG_WIDTH_1) {}
  436. };
  437. /* Report whether P is a contitional branching instruction. */
  438. template <>
  439. template <>
  440. inline bool
  441. is_a_helper <hsa_insn_cbr *>::test (hsa_insn_basic *p)
  442. {
  443. return p->m_opcode == BRIG_OPCODE_CBR;
  444. }
  445. /* HSA instruction for switch branches. */
  446. class hsa_insn_sbr : public hsa_insn_basic
  447. {
  448. public:
  449. hsa_insn_sbr (hsa_op_reg *index, unsigned jump_count);
  450. /* Default destructor. */
  451. ~hsa_insn_sbr ();
  452. void replace_all_labels (basic_block old_bb, basic_block new_bb);
  453. /* Width as described in HSA documentation. */
  454. BrigWidth8_t m_width;
  455. /* Jump table. */
  456. vec <basic_block> m_jump_table;
  457. /* Code list for label references. */
  458. hsa_op_code_list *m_label_code_list;
  459. private:
  460. /* Make the default constructor inaccessible. */
  461. hsa_insn_sbr () : hsa_insn_basic (1, BRIG_OPCODE_SBR) {}
  462. };
  463. /* Report whether P is a switch branching instruction. */
  464. template <>
  465. template <>
  466. inline bool
  467. is_a_helper <hsa_insn_sbr *>::test (hsa_insn_basic *p)
  468. {
  469. return p->m_opcode == BRIG_OPCODE_SBR;
  470. }
  471. /* HSA instruction for comparisons. */
  472. class hsa_insn_cmp : public hsa_insn_basic
  473. {
  474. public:
  475. hsa_insn_cmp (BrigCompareOperation8_t cmp, BrigType16_t t,
  476. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  477. hsa_op_base *arg2 = NULL);
  478. /* Source type should be derived from operand types. */
  479. /* The comparison operation. */
  480. BrigCompareOperation8_t m_compare;
  481. /* TODO: Modifiers and packing control are missing but so are everywhere
  482. else. */
  483. private:
  484. /* Make the default constructor inaccessible. */
  485. hsa_insn_cmp () : hsa_insn_basic (1, BRIG_OPCODE_CMP) {}
  486. };
  487. /* Report whether or not P is a comparison instruction. */
  488. template <>
  489. template <>
  490. inline bool
  491. is_a_helper <hsa_insn_cmp *>::test (hsa_insn_basic *p)
  492. {
  493. return p->m_opcode == BRIG_OPCODE_CMP;
  494. }
  495. /* HSA instruction for memory operations. */
  496. class hsa_insn_mem : public hsa_insn_basic
  497. {
  498. public:
  499. hsa_insn_mem (int opc, BrigType16_t t, hsa_op_base *arg0, hsa_op_base *arg1);
  500. /* Set alignment to VALUE. */
  501. void set_align (BrigAlignment8_t value);
  502. /* The segment is of the memory access is either the segment of the symbol in
  503. the address operand or flat address is there is no symbol there. */
  504. /* Required alignment of the memory operation. */
  505. BrigAlignment8_t m_align;
  506. /* HSA equiv class, basically an alias set number. */
  507. uint8_t m_equiv_class;
  508. /* TODO: Add width modifier, perhaps also other things. */
  509. protected:
  510. hsa_insn_mem (unsigned nops, int opc, BrigType16_t t,
  511. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  512. hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
  513. private:
  514. /* Make the default constructor inaccessible. */
  515. hsa_insn_mem () : hsa_insn_basic (1, BRIG_OPCODE_LD) {}
  516. };
  517. /* Report whether or not P is a memory instruction. */
  518. template <>
  519. template <>
  520. inline bool
  521. is_a_helper <hsa_insn_mem *>::test (hsa_insn_basic *p)
  522. {
  523. return (p->m_opcode == BRIG_OPCODE_LD
  524. || p->m_opcode == BRIG_OPCODE_ST);
  525. }
  526. /* HSA instruction for atomic operations. */
  527. class hsa_insn_atomic : public hsa_insn_mem
  528. {
  529. public:
  530. hsa_insn_atomic (int nops, int opc, enum BrigAtomicOperation aop,
  531. BrigType16_t t, BrigMemoryOrder memorder,
  532. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  533. hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
  534. /* The operation itself. */
  535. enum BrigAtomicOperation m_atomicop;
  536. /* Things like acquire/release/aligned. */
  537. enum BrigMemoryOrder m_memoryorder;
  538. /* Scope of the atomic operation. */
  539. enum BrigMemoryScope m_memoryscope;
  540. private:
  541. /* Make the default constructor inaccessible. */
  542. hsa_insn_atomic () : hsa_insn_mem (1, BRIG_KIND_NONE, BRIG_TYPE_NONE) {}
  543. };
  544. /* Report whether or not P is an atomic instruction. */
  545. template <>
  546. template <>
  547. inline bool
  548. is_a_helper <hsa_insn_atomic *>::test (hsa_insn_basic *p)
  549. {
  550. return (p->m_opcode == BRIG_OPCODE_ATOMIC
  551. || p->m_opcode == BRIG_OPCODE_ATOMICNORET);
  552. }
  553. /* HSA instruction for signal operations. */
  554. class hsa_insn_signal : public hsa_insn_basic
  555. {
  556. public:
  557. hsa_insn_signal (int nops, int opc, enum BrigAtomicOperation sop,
  558. BrigType16_t t, BrigMemoryOrder memorder,
  559. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  560. hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
  561. /* Things like acquire/release/aligned. */
  562. enum BrigMemoryOrder m_memory_order;
  563. /* The operation itself. */
  564. enum BrigAtomicOperation m_signalop;
  565. };
  566. /* Report whether or not P is a signal instruction. */
  567. template <>
  568. template <>
  569. inline bool
  570. is_a_helper <hsa_insn_signal *>::test (hsa_insn_basic *p)
  571. {
  572. return (p->m_opcode == BRIG_OPCODE_SIGNAL
  573. || p->m_opcode == BRIG_OPCODE_SIGNALNORET);
  574. }
  575. /* HSA instruction to convert between flat addressing and segments. */
  576. class hsa_insn_seg : public hsa_insn_basic
  577. {
  578. public:
  579. hsa_insn_seg (int opc, BrigType16_t destt, BrigType16_t srct,
  580. BrigSegment8_t seg, hsa_op_base *arg0, hsa_op_base *arg1);
  581. /* Source type. Depends on the source addressing/segment. */
  582. BrigType16_t m_src_type;
  583. /* The segment we are converting from or to. */
  584. BrigSegment8_t m_segment;
  585. private:
  586. /* Make the default constructor inaccessible. */
  587. hsa_insn_seg () : hsa_insn_basic (1, BRIG_OPCODE_STOF) {}
  588. };
  589. /* Report whether or not P is a segment conversion instruction. */
  590. template <>
  591. template <>
  592. inline bool
  593. is_a_helper <hsa_insn_seg *>::test (hsa_insn_basic *p)
  594. {
  595. return (p->m_opcode == BRIG_OPCODE_STOF
  596. || p->m_opcode == BRIG_OPCODE_FTOS);
  597. }
  598. /* Class for internal functions for purpose of HSA emission. */
  599. class hsa_internal_fn
  600. {
  601. public:
  602. hsa_internal_fn (enum internal_fn fn, unsigned type_bit_size):
  603. m_fn (fn), m_type_bit_size (type_bit_size), m_offset (0) {}
  604. hsa_internal_fn (const hsa_internal_fn *f):
  605. m_fn (f->m_fn), m_type_bit_size (f->m_type_bit_size),
  606. m_offset (f->m_offset) {}
  607. /* Return arity of the internal function. */
  608. unsigned get_arity ();
  609. /* Return BRIG type of N-th argument, if -1 is passed, return value type
  610. is received. */
  611. BrigType16_t get_argument_type (int n);
  612. /* Return function name. The memory must be released by a caller. */
  613. char *name ();
  614. /* Internal function. */
  615. enum internal_fn m_fn;
  616. /* Bit width of return type. */
  617. unsigned m_type_bit_size;
  618. /* BRIG offset of declaration of the function. */
  619. BrigCodeOffset32_t m_offset;
  620. };
  621. /* HSA instruction for function call. */
  622. class hsa_insn_call : public hsa_insn_basic
  623. {
  624. public:
  625. hsa_insn_call (tree callee);
  626. hsa_insn_call (hsa_internal_fn *fn);
  627. /* Default destructor. */
  628. ~hsa_insn_call ();
  629. /* Called function. */
  630. tree m_called_function;
  631. /* Called internal function. */
  632. hsa_internal_fn *m_called_internal_fn;
  633. /* Input formal arguments. */
  634. auto_vec <hsa_symbol *> m_input_args;
  635. /* Input arguments store instructions. */
  636. auto_vec <hsa_insn_mem *> m_input_arg_insns;
  637. /* Output argument, can be NULL for void functions. */
  638. hsa_symbol *m_output_arg;
  639. /* Called function code reference. */
  640. hsa_op_code_ref m_func;
  641. /* Code list for arguments of the function. */
  642. hsa_op_code_list *m_args_code_list;
  643. /* Code list for result of the function. */
  644. hsa_op_code_list *m_result_code_list;
  645. private:
  646. /* Make the default constructor inaccessible. */
  647. hsa_insn_call () : hsa_insn_basic (0, BRIG_OPCODE_CALL) {}
  648. };
  649. /* Report whether or not P is a call instruction. */
  650. template <>
  651. template <>
  652. inline bool
  653. is_a_helper <hsa_insn_call *>::test (hsa_insn_basic *p)
  654. {
  655. return (p->m_opcode == BRIG_OPCODE_CALL);
  656. }
  657. /* HSA call instruction block encapsulates definition of arguments,
  658. result type, corresponding loads and a possible store.
  659. Moreover, it contains a single call instruction.
  660. Emission of the instruction will produce multiple
  661. HSAIL instructions. */
  662. class hsa_insn_arg_block : public hsa_insn_basic
  663. {
  664. public:
  665. hsa_insn_arg_block (BrigKind brig_kind, hsa_insn_call * call);
  666. /* Kind of argument block. */
  667. BrigKind m_kind;
  668. /* Call instruction. */
  669. hsa_insn_call *m_call_insn;
  670. };
  671. /* Report whether or not P is a call block instruction. */
  672. template <>
  673. template <>
  674. inline bool
  675. is_a_helper <hsa_insn_arg_block *>::test (hsa_insn_basic *p)
  676. {
  677. return (p->m_opcode == HSA_OPCODE_ARG_BLOCK);
  678. }
  679. /* HSA comment instruction. */
  680. class hsa_insn_comment: public hsa_insn_basic
  681. {
  682. public:
  683. /* Constructor of class representing the comment in HSAIL. */
  684. hsa_insn_comment (const char *s);
  685. /* Default destructor. */
  686. ~hsa_insn_comment ();
  687. char *m_comment;
  688. };
  689. /* Report whether or not P is a call block instruction. */
  690. template <>
  691. template <>
  692. inline bool
  693. is_a_helper <hsa_insn_comment *>::test (hsa_insn_basic *p)
  694. {
  695. return (p->m_opcode == BRIG_KIND_DIRECTIVE_COMMENT);
  696. }
  697. /* HSA queue instruction. */
  698. class hsa_insn_queue: public hsa_insn_basic
  699. {
  700. public:
  701. hsa_insn_queue (int nops, int opcode, BrigSegment segment,
  702. BrigMemoryOrder memory_order,
  703. hsa_op_base *arg0 = NULL, hsa_op_base *arg1 = NULL,
  704. hsa_op_base *arg2 = NULL, hsa_op_base *arg3 = NULL);
  705. /* Destructor. */
  706. ~hsa_insn_queue ();
  707. /* Segment used to refer to the queue. Must be global or flat. */
  708. BrigSegment m_segment;
  709. /* Memory order used to specify synchronization. */
  710. BrigMemoryOrder m_memory_order;
  711. };
  712. /* Report whether or not P is a queue instruction. */
  713. template <>
  714. template <>
  715. inline bool
  716. is_a_helper <hsa_insn_queue *>::test (hsa_insn_basic *p)
  717. {
  718. return (p->m_opcode == BRIG_OPCODE_ADDQUEUEWRITEINDEX
  719. || p->m_opcode == BRIG_OPCODE_CASQUEUEWRITEINDEX
  720. || p->m_opcode == BRIG_OPCODE_LDQUEUEREADINDEX
  721. || p->m_opcode == BRIG_OPCODE_LDQUEUEWRITEINDEX
  722. || p->m_opcode == BRIG_OPCODE_STQUEUEREADINDEX
  723. || p->m_opcode == BRIG_OPCODE_STQUEUEWRITEINDEX);
  724. }
  725. /* HSA source type instruction. */
  726. class hsa_insn_srctype: public hsa_insn_basic
  727. {
  728. public:
  729. hsa_insn_srctype (int nops, BrigOpcode opcode, BrigType16_t destt,
  730. BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
  731. hsa_op_base *arg2);
  732. /* Source type. */
  733. BrigType16_t m_source_type;
  734. /* Destructor. */
  735. ~hsa_insn_srctype ();
  736. };
  737. /* Report whether or not P is a source type instruction. */
  738. template <>
  739. template <>
  740. inline bool
  741. is_a_helper <hsa_insn_srctype *>::test (hsa_insn_basic *p)
  742. {
  743. return (p->m_opcode == BRIG_OPCODE_POPCOUNT
  744. || p->m_opcode == BRIG_OPCODE_FIRSTBIT
  745. || p->m_opcode == BRIG_OPCODE_LASTBIT);
  746. }
  747. /* HSA packed instruction. */
  748. class hsa_insn_packed : public hsa_insn_srctype
  749. {
  750. public:
  751. hsa_insn_packed (int nops, BrigOpcode opcode, BrigType16_t destt,
  752. BrigType16_t srct, hsa_op_base *arg0, hsa_op_base *arg1,
  753. hsa_op_base *arg2);
  754. /* Operand list for an operand of the instruction. */
  755. hsa_op_operand_list *m_operand_list;
  756. /* Destructor. */
  757. ~hsa_insn_packed ();
  758. };
  759. /* Report whether or not P is a combine instruction. */
  760. template <>
  761. template <>
  762. inline bool
  763. is_a_helper <hsa_insn_packed *>::test (hsa_insn_basic *p)
  764. {
  765. return (p->m_opcode == BRIG_OPCODE_COMBINE
  766. || p->m_opcode == BRIG_OPCODE_EXPAND);
  767. }
  768. /* HSA convert instruction. */
  769. class hsa_insn_cvt: public hsa_insn_basic
  770. {
  771. public:
  772. hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src);
  773. };
  774. /* Report whether or not P is a convert instruction. */
  775. template <>
  776. template <>
  777. inline bool
  778. is_a_helper <hsa_insn_cvt *>::test (hsa_insn_basic *p)
  779. {
  780. return (p->m_opcode == BRIG_OPCODE_CVT);
  781. }
  782. /* HSA alloca instruction. */
  783. class hsa_insn_alloca: public hsa_insn_basic
  784. {
  785. public:
  786. hsa_insn_alloca (hsa_op_with_type *dest, hsa_op_with_type *size,
  787. unsigned alignment = 0);
  788. /* Required alignment of the allocation. */
  789. BrigAlignment8_t m_align;
  790. };
  791. /* Report whether or not P is an alloca instruction. */
  792. template <>
  793. template <>
  794. inline bool
  795. is_a_helper <hsa_insn_alloca *>::test (hsa_insn_basic *p)
  796. {
  797. return (p->m_opcode == BRIG_OPCODE_ALLOCA);
  798. }
  799. /* Basic block of HSA instructions. */
  800. class hsa_bb
  801. {
  802. public:
  803. hsa_bb (basic_block cfg_bb);
  804. hsa_bb (basic_block cfg_bb, int idx);
  805. /* Append an instruction INSN into the basic block. */
  806. void append_insn (hsa_insn_basic *insn);
  807. /* Add a PHI instruction. */
  808. void append_phi (hsa_insn_phi *phi);
  809. /* The real CFG BB that this HBB belongs to. */
  810. basic_block m_bb;
  811. /* The operand that refers to the label to this BB. */
  812. hsa_op_code_ref m_label_ref;
  813. /* The first and last instruction. */
  814. hsa_insn_basic *m_first_insn, *m_last_insn;
  815. /* The first and last phi node. */
  816. hsa_insn_phi *m_first_phi, *m_last_phi;
  817. /* Just a number to construct names from. */
  818. int m_index;
  819. auto_bitmap m_liveout, m_livein;
  820. private:
  821. /* Make the default constructor inaccessible. */
  822. hsa_bb ();
  823. /* All objects are deallocated by destroying their pool, so make delete
  824. inaccessible too. */
  825. void operator delete (void *) {}
  826. };
  827. /* Return the corresponding HSA basic block structure for the given control
  828. flow basic_block BB. */
  829. static inline hsa_bb *
  830. hsa_bb_for_bb (basic_block bb)
  831. {
  832. return (struct hsa_bb *) bb->aux;
  833. }
  834. /* Class for hashing local hsa_symbols. */
  835. struct hsa_noop_symbol_hasher : nofree_ptr_hash <hsa_symbol>
  836. {
  837. static inline hashval_t hash (const value_type);
  838. static inline bool equal (const value_type, const compare_type);
  839. };
  840. /* Hash hsa_symbol. */
  841. inline hashval_t
  842. hsa_noop_symbol_hasher::hash (const value_type item)
  843. {
  844. return DECL_UID (item->m_decl);
  845. }
  846. /* Return true if the DECL_UIDs of decls both symbols refer to are equal. */
  847. inline bool
  848. hsa_noop_symbol_hasher::equal (const value_type a, const compare_type b)
  849. {
  850. return (DECL_UID (a->m_decl) == DECL_UID (b->m_decl));
  851. }
  852. /* Structure that encapsulates intermediate representation of a HSA
  853. function. */
  854. class hsa_function_representation
  855. {
  856. public:
  857. hsa_function_representation (tree fdecl, bool kernel_p,
  858. unsigned ssa_names_count,
  859. bool modified_cfg = false);
  860. hsa_function_representation (hsa_internal_fn *fn);
  861. ~hsa_function_representation ();
  862. /* Builds a shadow register that is utilized to a kernel dispatch. */
  863. hsa_op_reg *get_shadow_reg ();
  864. /* Return true if we are in a function that has kernel dispatch
  865. shadow register. */
  866. bool has_shadow_reg_p ();
  867. /* The entry/exit blocks don't contain incoming code,
  868. but the HSA generator might use them to put code into,
  869. so we need hsa_bb instances of them. */
  870. void init_extra_bbs ();
  871. /* Update CFG dominators if m_modified_cfg flag is set. */
  872. void update_dominance ();
  873. /* Return linkage of the representation. */
  874. BrigLinkage8_t get_linkage ();
  875. /* Create a private symbol of requested TYPE. */
  876. hsa_symbol *create_hsa_temporary (BrigType16_t type);
  877. /* Lookup or create a HSA pseudo register for a given gimple SSA name. */
  878. hsa_op_reg *reg_for_gimple_ssa (tree ssa);
  879. /* Name of the function. */
  880. char *m_name;
  881. /* Number of allocated register structures. */
  882. int m_reg_count;
  883. /* Input arguments. */
  884. vec <hsa_symbol *> m_input_args;
  885. /* Output argument or NULL if there is none. */
  886. hsa_symbol *m_output_arg;
  887. /* Hash table of local variable symbols. */
  888. hash_table <hsa_noop_symbol_hasher> *m_local_symbols;
  889. /* Hash map for string constants. */
  890. hash_map <tree, hsa_symbol *> m_string_constants_map;
  891. /* Vector of pointers to spill symbols. */
  892. vec <struct hsa_symbol *> m_spill_symbols;
  893. /* Vector of pointers to global variables and transformed string constants
  894. that are used by the function. */
  895. vec <struct hsa_symbol *> m_global_symbols;
  896. /* Private function artificial variables. */
  897. vec <struct hsa_symbol *> m_private_variables;
  898. /* Vector of called function declarations. */
  899. vec <tree> m_called_functions;
  900. /* Vector of used internal functions. */
  901. vec <hsa_internal_fn *> m_called_internal_fns;
  902. /* Number of HBB BBs. */
  903. int m_hbb_count;
  904. /* Whether or not we could check and enforce SSA properties. */
  905. bool m_in_ssa;
  906. /* True if the function is kernel function. */
  907. bool m_kern_p;
  908. /* True if the function representation is a declaration. */
  909. bool m_declaration_p;
  910. /* Function declaration tree. */
  911. tree m_decl;
  912. /* Internal function info is used for declarations of internal functions. */
  913. hsa_internal_fn *m_internal_fn;
  914. /* Runtime shadow register. */
  915. hsa_op_reg *m_shadow_reg;
  916. /* Number of kernel dispatched which take place in the function. */
  917. unsigned m_kernel_dispatch_count;
  918. /* If the function representation contains a kernel dispatch,
  919. OMP data size is necessary memory that is used for copying before
  920. a kernel dispatch. */
  921. unsigned m_maximum_omp_data_size;
  922. /* Return true if there's an HSA-specific warning already seen. */
  923. bool m_seen_error;
  924. /* Counter for temporary symbols created in the function representation. */
  925. unsigned m_temp_symbol_count;
  926. /* SSA names mapping. */
  927. vec <hsa_op_reg *> m_ssa_map;
  928. /* Flag whether a function needs update of dominators before RA. */
  929. bool m_modified_cfg;
  930. };
  931. enum hsa_function_kind
  932. {
  933. HSA_INVALID,
  934. HSA_KERNEL,
  935. HSA_FUNCTION
  936. };
  937. struct hsa_function_summary
  938. {
  939. /* Default constructor. */
  940. hsa_function_summary ();
  941. /* Kind of GPU/host function. */
  942. hsa_function_kind m_kind;
  943. /* Pointer to a cgraph node which is a HSA implementation of the function.
  944. In case of the function is a HSA function, the bound function points
  945. to the host function. */
  946. cgraph_node *m_bound_function;
  947. /* Identifies if the function is an HSA function or a host function. */
  948. bool m_gpu_implementation_p;
  949. /* True if the function is a gridified kernel. */
  950. bool m_gridified_kernel_p;
  951. };
  952. inline
  953. hsa_function_summary::hsa_function_summary (): m_kind (HSA_INVALID),
  954. m_bound_function (NULL), m_gpu_implementation_p (false)
  955. {
  956. }
  957. /* Function summary for HSA functions. */
  958. class hsa_summary_t: public function_summary <hsa_function_summary *>
  959. {
  960. public:
  961. hsa_summary_t (symbol_table *table):
  962. function_summary<hsa_function_summary *> (table)
  963. {
  964. disable_insertion_hook ();
  965. }
  966. /* Couple GPU and HOST as gpu-specific and host-specific implementation of
  967. the same function. KIND determines whether GPU is a host-invokable kernel
  968. or gpu-callable function and GRIDIFIED_KERNEL_P is set if the function was
  969. gridified in OMP. */
  970. void link_functions (cgraph_node *gpu, cgraph_node *host,
  971. hsa_function_kind kind, bool gridified_kernel_p);
  972. private:
  973. void process_gpu_implementation_attributes (tree gdecl);
  974. };
  975. /* OMP simple builtin describes behavior that should be done for
  976. the routine. */
  977. class omp_simple_builtin
  978. {
  979. public:
  980. omp_simple_builtin (const char *name, const char *warning_message,
  981. bool sorry, hsa_op_immed *return_value = NULL):
  982. m_name (name), m_warning_message (warning_message), m_sorry (sorry),
  983. m_return_value (return_value)
  984. {}
  985. /* Generate HSAIL instructions for the builtin or produce warning message. */
  986. void generate (gimple *stmt, hsa_bb *hbb);
  987. /* Name of function. */
  988. const char *m_name;
  989. /* Warning message. */
  990. const char *m_warning_message;
  991. /* Flag if we should sorry after the warning message is printed. */
  992. bool m_sorry;
  993. /* Return value of the function. */
  994. hsa_op_immed *m_return_value;
  995. /* Emission function. */
  996. void (*m_emit_func) (gimple *stmt, hsa_bb *);
  997. };
  998. /* Class for hashing hsa_internal_fn. */
  999. struct hsa_internal_fn_hasher: free_ptr_hash <hsa_internal_fn>
  1000. {
  1001. static inline hashval_t hash (const value_type);
  1002. static inline bool equal (const value_type, const compare_type);
  1003. };
  1004. /* Hash hsa_symbol. */
  1005. inline hashval_t
  1006. hsa_internal_fn_hasher::hash (const value_type item)
  1007. {
  1008. return item->m_fn;
  1009. }
  1010. /* Return true if the DECL_UIDs of decls both symbols refer to are equal. */
  1011. inline bool
  1012. hsa_internal_fn_hasher::equal (const value_type a, const compare_type b)
  1013. {
  1014. return a->m_fn == b->m_fn && a->m_type_bit_size == b->m_type_bit_size;
  1015. }
  1016. /* in hsa-common.c */
  1017. extern struct hsa_function_representation *hsa_cfun;
  1018. extern hash_map <tree, vec <const char *> *> *hsa_decl_kernel_dependencies;
  1019. extern hsa_summary_t *hsa_summaries;
  1020. extern hsa_symbol *hsa_num_threads;
  1021. extern unsigned hsa_kernel_calls_counter;
  1022. extern hash_set <tree> *hsa_failed_functions;
  1023. extern hash_table <hsa_noop_symbol_hasher> *hsa_global_variable_symbols;
  1024. bool hsa_callable_function_p (tree fndecl);
  1025. void hsa_init_compilation_unit_data (void);
  1026. void hsa_deinit_compilation_unit_data (void);
  1027. bool hsa_machine_large_p (void);
  1028. bool hsa_full_profile_p (void);
  1029. bool hsa_opcode_floating_bit_insn_p (BrigOpcode16_t);
  1030. unsigned hsa_type_bit_size (BrigType16_t t);
  1031. BrigType16_t hsa_bittype_for_bitsize (unsigned bitsize);
  1032. BrigType16_t hsa_uint_for_bitsize (unsigned bitsize);
  1033. BrigType16_t hsa_float_for_bitsize (unsigned bitsize);
  1034. BrigType16_t hsa_bittype_for_type (BrigType16_t t);
  1035. BrigType16_t hsa_unsigned_type_for_type (BrigType16_t t);
  1036. bool hsa_type_packed_p (BrigType16_t type);
  1037. bool hsa_type_float_p (BrigType16_t type);
  1038. bool hsa_type_integer_p (BrigType16_t type);
  1039. bool hsa_btype_p (BrigType16_t type);
  1040. BrigAlignment8_t hsa_alignment_encoding (unsigned n);
  1041. BrigAlignment8_t hsa_natural_alignment (BrigType16_t type);
  1042. BrigAlignment8_t hsa_object_alignment (tree t);
  1043. unsigned hsa_byte_alignment (BrigAlignment8_t alignment);
  1044. void hsa_destroy_operand (hsa_op_base *op);
  1045. void hsa_destroy_insn (hsa_insn_basic *insn);
  1046. void hsa_add_kern_decl_mapping (tree decl, char *name, unsigned, bool);
  1047. unsigned hsa_get_number_decl_kernel_mappings (void);
  1048. tree hsa_get_decl_kernel_mapping_decl (unsigned i);
  1049. char *hsa_get_decl_kernel_mapping_name (unsigned i);
  1050. unsigned hsa_get_decl_kernel_mapping_omp_size (unsigned i);
  1051. bool hsa_get_decl_kernel_mapping_gridified (unsigned i);
  1052. void hsa_free_decl_kernel_mapping (void);
  1053. tree *hsa_get_ctor_statements (void);
  1054. tree *hsa_get_dtor_statements (void);
  1055. tree *hsa_get_kernel_dispatch_type (void);
  1056. void hsa_add_kernel_dependency (tree caller, const char *called_function);
  1057. void hsa_sanitize_name (char *p);
  1058. char *hsa_brig_function_name (const char *p);
  1059. const char *hsa_get_declaration_name (tree decl);
  1060. void hsa_register_kernel (cgraph_node *host);
  1061. void hsa_register_kernel (cgraph_node *gpu, cgraph_node *host);
  1062. bool hsa_seen_error (void);
  1063. void hsa_fail_cfun (void);
  1064. /* In hsa-gen.c. */
  1065. void hsa_build_append_simple_mov (hsa_op_reg *, hsa_op_base *, hsa_bb *);
  1066. hsa_symbol *hsa_get_spill_symbol (BrigType16_t);
  1067. hsa_symbol *hsa_get_string_cst_symbol (BrigType16_t);
  1068. hsa_op_reg *hsa_spill_in (hsa_insn_basic *, hsa_op_reg *, hsa_op_reg **);
  1069. hsa_op_reg *hsa_spill_out (hsa_insn_basic *, hsa_op_reg *, hsa_op_reg **);
  1070. hsa_bb *hsa_init_new_bb (basic_block);
  1071. hsa_function_representation *hsa_generate_function_declaration (tree decl);
  1072. hsa_function_representation *hsa_generate_internal_fn_decl (hsa_internal_fn *);
  1073. tree hsa_get_host_function (tree decl);
  1074. /* In hsa-regalloc.c. */
  1075. void hsa_regalloc (void);
  1076. /* In hsa-brig.c. */
  1077. extern hash_table <hsa_internal_fn_hasher> *hsa_emitted_internal_decls;
  1078. void hsa_brig_emit_function (void);
  1079. void hsa_output_brig (void);
  1080. unsigned hsa_get_imm_brig_type_len (BrigType16_t type);
  1081. void hsa_brig_emit_omp_symbols (void);
  1082. /* In hsa-dump.c. */
  1083. const char *hsa_seg_name (BrigSegment8_t);
  1084. void dump_hsa_insn (FILE *f, hsa_insn_basic *insn);
  1085. void dump_hsa_bb (FILE *, hsa_bb *);
  1086. void dump_hsa_cfun (FILE *);
  1087. DEBUG_FUNCTION void debug_hsa_operand (hsa_op_base *opc);
  1088. DEBUG_FUNCTION void debug_hsa_insn (hsa_insn_basic *insn);
  1089. union hsa_bytes
  1090. {
  1091. uint8_t b8;
  1092. uint16_t b16;
  1093. uint32_t b32;
  1094. uint64_t b64;
  1095. };
  1096. /* Return true if a function DECL is an HSA implementation. */
  1097. static inline bool
  1098. hsa_gpu_implementation_p (tree decl)
  1099. {
  1100. if (hsa_summaries == NULL)
  1101. return false;
  1102. hsa_function_summary *s = hsa_summaries->get (cgraph_node::get_create (decl));
  1103. return s != NULL && s->m_gpu_implementation_p;
  1104. }
  1105. #endif /* HSA_H */