gimple.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971
  1. /* Gimple IR support functions.
  2. Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. Contributed by Aldy Hernandez <aldyh@redhat.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "tm.h"
  20. #include "target.h"
  21. #include "hash-set.h"
  22. #include "machmode.h"
  23. #include "vec.h"
  24. #include "double-int.h"
  25. #include "input.h"
  26. #include "alias.h"
  27. #include "symtab.h"
  28. #include "wide-int.h"
  29. #include "inchash.h"
  30. #include "tree.h"
  31. #include "fold-const.h"
  32. #include "calls.h"
  33. #include "stmt.h"
  34. #include "stor-layout.h"
  35. #include "hard-reg-set.h"
  36. #include "predict.h"
  37. #include "input.h"
  38. #include "function.h"
  39. #include "dominance.h"
  40. #include "cfg.h"
  41. #include "basic-block.h"
  42. #include "tree-ssa-alias.h"
  43. #include "internal-fn.h"
  44. #include "tree-eh.h"
  45. #include "gimple-expr.h"
  46. #include "is-a.h"
  47. #include "gimple.h"
  48. #include "gimple-iterator.h"
  49. #include "gimple-walk.h"
  50. #include "gimple.h"
  51. #include "gimplify.h"
  52. #include "diagnostic.h"
  53. #include "value-prof.h"
  54. #include "flags.h"
  55. #include "alias.h"
  56. #include "demangle.h"
  57. #include "langhooks.h"
  58. #include "bitmap.h"
  59. #include "stringpool.h"
  60. #include "tree-ssanames.h"
  61. #include "ipa-ref.h"
  62. #include "lto-streamer.h"
  63. #include "cgraph.h"
  64. #include "gimple-ssa.h"
  65. /* All the tuples have their operand vector (if present) at the very bottom
  66. of the structure. Therefore, the offset required to find the
  67. operands vector the size of the structure minus the size of the 1
  68. element tree array at the end (see gimple_ops). */
  69. #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
  70. (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
  71. EXPORTED_CONST size_t gimple_ops_offset_[] = {
  72. #include "gsstruct.def"
  73. };
  74. #undef DEFGSSTRUCT
  75. #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof (struct STRUCT),
  76. static const size_t gsstruct_code_size[] = {
  77. #include "gsstruct.def"
  78. };
  79. #undef DEFGSSTRUCT
  80. #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
  81. const char *const gimple_code_name[] = {
  82. #include "gimple.def"
  83. };
  84. #undef DEFGSCODE
  85. #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
  86. EXPORTED_CONST enum gimple_statement_structure_enum gss_for_code_[] = {
  87. #include "gimple.def"
  88. };
  89. #undef DEFGSCODE
  90. /* Gimple stats. */
  91. int gimple_alloc_counts[(int) gimple_alloc_kind_all];
  92. int gimple_alloc_sizes[(int) gimple_alloc_kind_all];
  93. /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
  94. static const char * const gimple_alloc_kind_names[] = {
  95. "assignments",
  96. "phi nodes",
  97. "conditionals",
  98. "everything else"
  99. };
  100. /* Gimple tuple constructors.
  101. Note: Any constructor taking a ``gimple_seq'' as a parameter, can
  102. be passed a NULL to start with an empty sequence. */
  103. /* Set the code for statement G to CODE. */
  104. static inline void
  105. gimple_set_code (gimple g, enum gimple_code code)
  106. {
  107. g->code = code;
  108. }
  109. /* Return the number of bytes needed to hold a GIMPLE statement with
  110. code CODE. */
  111. static inline size_t
  112. gimple_size (enum gimple_code code)
  113. {
  114. return gsstruct_code_size[gss_for_code (code)];
  115. }
  116. /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
  117. operands. */
  118. gimple
  119. gimple_alloc_stat (enum gimple_code code, unsigned num_ops MEM_STAT_DECL)
  120. {
  121. size_t size;
  122. gimple stmt;
  123. size = gimple_size (code);
  124. if (num_ops > 0)
  125. size += sizeof (tree) * (num_ops - 1);
  126. if (GATHER_STATISTICS)
  127. {
  128. enum gimple_alloc_kind kind = gimple_alloc_kind (code);
  129. gimple_alloc_counts[(int) kind]++;
  130. gimple_alloc_sizes[(int) kind] += size;
  131. }
  132. stmt = ggc_alloc_cleared_gimple_statement_stat (size PASS_MEM_STAT);
  133. gimple_set_code (stmt, code);
  134. gimple_set_num_ops (stmt, num_ops);
  135. /* Do not call gimple_set_modified here as it has other side
  136. effects and this tuple is still not completely built. */
  137. stmt->modified = 1;
  138. gimple_init_singleton (stmt);
  139. return stmt;
  140. }
  141. /* Set SUBCODE to be the code of the expression computed by statement G. */
  142. static inline void
  143. gimple_set_subcode (gimple g, unsigned subcode)
  144. {
  145. /* We only have 16 bits for the RHS code. Assert that we are not
  146. overflowing it. */
  147. gcc_assert (subcode < (1 << 16));
  148. g->subcode = subcode;
  149. }
  150. /* Build a tuple with operands. CODE is the statement to build (which
  151. must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the subcode
  152. for the new tuple. NUM_OPS is the number of operands to allocate. */
  153. #define gimple_build_with_ops(c, s, n) \
  154. gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
  155. static gimple
  156. gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
  157. unsigned num_ops MEM_STAT_DECL)
  158. {
  159. gimple s = gimple_alloc_stat (code, num_ops PASS_MEM_STAT);
  160. gimple_set_subcode (s, subcode);
  161. return s;
  162. }
  163. /* Build a GIMPLE_RETURN statement returning RETVAL. */
  164. greturn *
  165. gimple_build_return (tree retval)
  166. {
  167. greturn *s
  168. = as_a <greturn *> (gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK,
  169. 2));
  170. if (retval)
  171. gimple_return_set_retval (s, retval);
  172. return s;
  173. }
  174. /* Reset alias information on call S. */
  175. void
  176. gimple_call_reset_alias_info (gcall *s)
  177. {
  178. if (gimple_call_flags (s) & ECF_CONST)
  179. memset (gimple_call_use_set (s), 0, sizeof (struct pt_solution));
  180. else
  181. pt_solution_reset (gimple_call_use_set (s));
  182. if (gimple_call_flags (s) & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
  183. memset (gimple_call_clobber_set (s), 0, sizeof (struct pt_solution));
  184. else
  185. pt_solution_reset (gimple_call_clobber_set (s));
  186. }
  187. /* Helper for gimple_build_call, gimple_build_call_valist,
  188. gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
  189. components of a GIMPLE_CALL statement to function FN with NARGS
  190. arguments. */
  191. static inline gcall *
  192. gimple_build_call_1 (tree fn, unsigned nargs)
  193. {
  194. gcall *s
  195. = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
  196. nargs + 3));
  197. if (TREE_CODE (fn) == FUNCTION_DECL)
  198. fn = build_fold_addr_expr (fn);
  199. gimple_set_op (s, 1, fn);
  200. gimple_call_set_fntype (s, TREE_TYPE (TREE_TYPE (fn)));
  201. gimple_call_reset_alias_info (s);
  202. return s;
  203. }
  204. /* Build a GIMPLE_CALL statement to function FN with the arguments
  205. specified in vector ARGS. */
  206. gcall *
  207. gimple_build_call_vec (tree fn, vec<tree> args)
  208. {
  209. unsigned i;
  210. unsigned nargs = args.length ();
  211. gcall *call = gimple_build_call_1 (fn, nargs);
  212. for (i = 0; i < nargs; i++)
  213. gimple_call_set_arg (call, i, args[i]);
  214. return call;
  215. }
  216. /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
  217. arguments. The ... are the arguments. */
  218. gcall *
  219. gimple_build_call (tree fn, unsigned nargs, ...)
  220. {
  221. va_list ap;
  222. gcall *call;
  223. unsigned i;
  224. gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
  225. call = gimple_build_call_1 (fn, nargs);
  226. va_start (ap, nargs);
  227. for (i = 0; i < nargs; i++)
  228. gimple_call_set_arg (call, i, va_arg (ap, tree));
  229. va_end (ap);
  230. return call;
  231. }
  232. /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
  233. arguments. AP contains the arguments. */
  234. gcall *
  235. gimple_build_call_valist (tree fn, unsigned nargs, va_list ap)
  236. {
  237. gcall *call;
  238. unsigned i;
  239. gcc_assert (TREE_CODE (fn) == FUNCTION_DECL || is_gimple_call_addr (fn));
  240. call = gimple_build_call_1 (fn, nargs);
  241. for (i = 0; i < nargs; i++)
  242. gimple_call_set_arg (call, i, va_arg (ap, tree));
  243. return call;
  244. }
  245. /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
  246. Build the basic components of a GIMPLE_CALL statement to internal
  247. function FN with NARGS arguments. */
  248. static inline gcall *
  249. gimple_build_call_internal_1 (enum internal_fn fn, unsigned nargs)
  250. {
  251. gcall *s
  252. = as_a <gcall *> (gimple_build_with_ops (GIMPLE_CALL, ERROR_MARK,
  253. nargs + 3));
  254. s->subcode |= GF_CALL_INTERNAL;
  255. gimple_call_set_internal_fn (s, fn);
  256. gimple_call_reset_alias_info (s);
  257. return s;
  258. }
  259. /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
  260. the number of arguments. The ... are the arguments. */
  261. gcall *
  262. gimple_build_call_internal (enum internal_fn fn, unsigned nargs, ...)
  263. {
  264. va_list ap;
  265. gcall *call;
  266. unsigned i;
  267. call = gimple_build_call_internal_1 (fn, nargs);
  268. va_start (ap, nargs);
  269. for (i = 0; i < nargs; i++)
  270. gimple_call_set_arg (call, i, va_arg (ap, tree));
  271. va_end (ap);
  272. return call;
  273. }
  274. /* Build a GIMPLE_CALL statement to internal function FN with the arguments
  275. specified in vector ARGS. */
  276. gcall *
  277. gimple_build_call_internal_vec (enum internal_fn fn, vec<tree> args)
  278. {
  279. unsigned i, nargs;
  280. gcall *call;
  281. nargs = args.length ();
  282. call = gimple_build_call_internal_1 (fn, nargs);
  283. for (i = 0; i < nargs; i++)
  284. gimple_call_set_arg (call, i, args[i]);
  285. return call;
  286. }
  287. /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
  288. assumed to be in GIMPLE form already. Minimal checking is done of
  289. this fact. */
  290. gcall *
  291. gimple_build_call_from_tree (tree t)
  292. {
  293. unsigned i, nargs;
  294. gcall *call;
  295. tree fndecl = get_callee_fndecl (t);
  296. gcc_assert (TREE_CODE (t) == CALL_EXPR);
  297. nargs = call_expr_nargs (t);
  298. call = gimple_build_call_1 (fndecl ? fndecl : CALL_EXPR_FN (t), nargs);
  299. for (i = 0; i < nargs; i++)
  300. gimple_call_set_arg (call, i, CALL_EXPR_ARG (t, i));
  301. gimple_set_block (call, TREE_BLOCK (t));
  302. /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
  303. gimple_call_set_chain (call, CALL_EXPR_STATIC_CHAIN (t));
  304. gimple_call_set_tail (call, CALL_EXPR_TAILCALL (t));
  305. gimple_call_set_return_slot_opt (call, CALL_EXPR_RETURN_SLOT_OPT (t));
  306. if (fndecl
  307. && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
  308. && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA
  309. || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA_WITH_ALIGN))
  310. gimple_call_set_alloca_for_var (call, CALL_ALLOCA_FOR_VAR_P (t));
  311. else
  312. gimple_call_set_from_thunk (call, CALL_FROM_THUNK_P (t));
  313. gimple_call_set_va_arg_pack (call, CALL_EXPR_VA_ARG_PACK (t));
  314. gimple_call_set_nothrow (call, TREE_NOTHROW (t));
  315. gimple_set_no_warning (call, TREE_NO_WARNING (t));
  316. gimple_call_set_with_bounds (call, CALL_WITH_BOUNDS_P (t));
  317. return call;
  318. }
  319. /* Build a GIMPLE_ASSIGN statement.
  320. LHS of the assignment.
  321. RHS of the assignment which can be unary or binary. */
  322. gassign *
  323. gimple_build_assign (tree lhs, tree rhs MEM_STAT_DECL)
  324. {
  325. enum tree_code subcode;
  326. tree op1, op2, op3;
  327. extract_ops_from_tree_1 (rhs, &subcode, &op1, &op2, &op3);
  328. return gimple_build_assign (lhs, subcode, op1, op2, op3 PASS_MEM_STAT);
  329. }
  330. /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
  331. OP1, OP2 and OP3. */
  332. static inline gassign *
  333. gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
  334. tree op2, tree op3 MEM_STAT_DECL)
  335. {
  336. unsigned num_ops;
  337. gassign *p;
  338. /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
  339. code). */
  340. num_ops = get_gimple_rhs_num_ops (subcode) + 1;
  341. p = as_a <gassign *> (
  342. gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
  343. PASS_MEM_STAT));
  344. gimple_assign_set_lhs (p, lhs);
  345. gimple_assign_set_rhs1 (p, op1);
  346. if (op2)
  347. {
  348. gcc_assert (num_ops > 2);
  349. gimple_assign_set_rhs2 (p, op2);
  350. }
  351. if (op3)
  352. {
  353. gcc_assert (num_ops > 3);
  354. gimple_assign_set_rhs3 (p, op3);
  355. }
  356. return p;
  357. }
  358. /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
  359. OP1, OP2 and OP3. */
  360. gassign *
  361. gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
  362. tree op2, tree op3 MEM_STAT_DECL)
  363. {
  364. return gimple_build_assign_1 (lhs, subcode, op1, op2, op3 PASS_MEM_STAT);
  365. }
  366. /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
  367. OP1 and OP2. */
  368. gassign *
  369. gimple_build_assign (tree lhs, enum tree_code subcode, tree op1,
  370. tree op2 MEM_STAT_DECL)
  371. {
  372. return gimple_build_assign_1 (lhs, subcode, op1, op2, NULL_TREE
  373. PASS_MEM_STAT);
  374. }
  375. /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operand OP1. */
  376. gassign *
  377. gimple_build_assign (tree lhs, enum tree_code subcode, tree op1 MEM_STAT_DECL)
  378. {
  379. return gimple_build_assign_1 (lhs, subcode, op1, NULL_TREE, NULL_TREE
  380. PASS_MEM_STAT);
  381. }
  382. /* Build a GIMPLE_COND statement.
  383. PRED is the condition used to compare LHS and the RHS.
  384. T_LABEL is the label to jump to if the condition is true.
  385. F_LABEL is the label to jump to otherwise. */
  386. gcond *
  387. gimple_build_cond (enum tree_code pred_code, tree lhs, tree rhs,
  388. tree t_label, tree f_label)
  389. {
  390. gcond *p;
  391. gcc_assert (TREE_CODE_CLASS (pred_code) == tcc_comparison);
  392. p = as_a <gcond *> (gimple_build_with_ops (GIMPLE_COND, pred_code, 4));
  393. gimple_cond_set_lhs (p, lhs);
  394. gimple_cond_set_rhs (p, rhs);
  395. gimple_cond_set_true_label (p, t_label);
  396. gimple_cond_set_false_label (p, f_label);
  397. return p;
  398. }
  399. /* Build a GIMPLE_COND statement from the conditional expression tree
  400. COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
  401. gcond *
  402. gimple_build_cond_from_tree (tree cond, tree t_label, tree f_label)
  403. {
  404. enum tree_code code;
  405. tree lhs, rhs;
  406. gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
  407. return gimple_build_cond (code, lhs, rhs, t_label, f_label);
  408. }
  409. /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
  410. boolean expression tree COND. */
  411. void
  412. gimple_cond_set_condition_from_tree (gcond *stmt, tree cond)
  413. {
  414. enum tree_code code;
  415. tree lhs, rhs;
  416. gimple_cond_get_ops_from_tree (cond, &code, &lhs, &rhs);
  417. gimple_cond_set_condition (stmt, code, lhs, rhs);
  418. }
  419. /* Build a GIMPLE_LABEL statement for LABEL. */
  420. glabel *
  421. gimple_build_label (tree label)
  422. {
  423. glabel *p
  424. = as_a <glabel *> (gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1));
  425. gimple_label_set_label (p, label);
  426. return p;
  427. }
  428. /* Build a GIMPLE_GOTO statement to label DEST. */
  429. ggoto *
  430. gimple_build_goto (tree dest)
  431. {
  432. ggoto *p
  433. = as_a <ggoto *> (gimple_build_with_ops (GIMPLE_GOTO, ERROR_MARK, 1));
  434. gimple_goto_set_dest (p, dest);
  435. return p;
  436. }
  437. /* Build a GIMPLE_NOP statement. */
  438. gimple
  439. gimple_build_nop (void)
  440. {
  441. return gimple_alloc (GIMPLE_NOP, 0);
  442. }
  443. /* Build a GIMPLE_BIND statement.
  444. VARS are the variables in BODY.
  445. BLOCK is the containing block. */
  446. gbind *
  447. gimple_build_bind (tree vars, gimple_seq body, tree block)
  448. {
  449. gbind *p = as_a <gbind *> (gimple_alloc (GIMPLE_BIND, 0));
  450. gimple_bind_set_vars (p, vars);
  451. if (body)
  452. gimple_bind_set_body (p, body);
  453. if (block)
  454. gimple_bind_set_block (p, block);
  455. return p;
  456. }
  457. /* Helper function to set the simple fields of a asm stmt.
  458. STRING is a pointer to a string that is the asm blocks assembly code.
  459. NINPUT is the number of register inputs.
  460. NOUTPUT is the number of register outputs.
  461. NCLOBBERS is the number of clobbered registers.
  462. */
  463. static inline gasm *
  464. gimple_build_asm_1 (const char *string, unsigned ninputs, unsigned noutputs,
  465. unsigned nclobbers, unsigned nlabels)
  466. {
  467. gasm *p;
  468. int size = strlen (string);
  469. /* ASMs with labels cannot have outputs. This should have been
  470. enforced by the front end. */
  471. gcc_assert (nlabels == 0 || noutputs == 0);
  472. p = as_a <gasm *> (
  473. gimple_build_with_ops (GIMPLE_ASM, ERROR_MARK,
  474. ninputs + noutputs + nclobbers + nlabels));
  475. p->ni = ninputs;
  476. p->no = noutputs;
  477. p->nc = nclobbers;
  478. p->nl = nlabels;
  479. p->string = ggc_alloc_string (string, size);
  480. if (GATHER_STATISTICS)
  481. gimple_alloc_sizes[(int) gimple_alloc_kind (GIMPLE_ASM)] += size;
  482. return p;
  483. }
  484. /* Build a GIMPLE_ASM statement.
  485. STRING is the assembly code.
  486. NINPUT is the number of register inputs.
  487. NOUTPUT is the number of register outputs.
  488. NCLOBBERS is the number of clobbered registers.
  489. INPUTS is a vector of the input register parameters.
  490. OUTPUTS is a vector of the output register parameters.
  491. CLOBBERS is a vector of the clobbered register parameters.
  492. LABELS is a vector of destination labels. */
  493. gasm *
  494. gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs,
  495. vec<tree, va_gc> *outputs, vec<tree, va_gc> *clobbers,
  496. vec<tree, va_gc> *labels)
  497. {
  498. gasm *p;
  499. unsigned i;
  500. p = gimple_build_asm_1 (string,
  501. vec_safe_length (inputs),
  502. vec_safe_length (outputs),
  503. vec_safe_length (clobbers),
  504. vec_safe_length (labels));
  505. for (i = 0; i < vec_safe_length (inputs); i++)
  506. gimple_asm_set_input_op (p, i, (*inputs)[i]);
  507. for (i = 0; i < vec_safe_length (outputs); i++)
  508. gimple_asm_set_output_op (p, i, (*outputs)[i]);
  509. for (i = 0; i < vec_safe_length (clobbers); i++)
  510. gimple_asm_set_clobber_op (p, i, (*clobbers)[i]);
  511. for (i = 0; i < vec_safe_length (labels); i++)
  512. gimple_asm_set_label_op (p, i, (*labels)[i]);
  513. return p;
  514. }
  515. /* Build a GIMPLE_CATCH statement.
  516. TYPES are the catch types.
  517. HANDLER is the exception handler. */
  518. gcatch *
  519. gimple_build_catch (tree types, gimple_seq handler)
  520. {
  521. gcatch *p = as_a <gcatch *> (gimple_alloc (GIMPLE_CATCH, 0));
  522. gimple_catch_set_types (p, types);
  523. if (handler)
  524. gimple_catch_set_handler (p, handler);
  525. return p;
  526. }
  527. /* Build a GIMPLE_EH_FILTER statement.
  528. TYPES are the filter's types.
  529. FAILURE is the filter's failure action. */
  530. geh_filter *
  531. gimple_build_eh_filter (tree types, gimple_seq failure)
  532. {
  533. geh_filter *p = as_a <geh_filter *> (gimple_alloc (GIMPLE_EH_FILTER, 0));
  534. gimple_eh_filter_set_types (p, types);
  535. if (failure)
  536. gimple_eh_filter_set_failure (p, failure);
  537. return p;
  538. }
  539. /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
  540. geh_mnt *
  541. gimple_build_eh_must_not_throw (tree decl)
  542. {
  543. geh_mnt *p = as_a <geh_mnt *> (gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0));
  544. gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
  545. gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
  546. gimple_eh_must_not_throw_set_fndecl (p, decl);
  547. return p;
  548. }
  549. /* Build a GIMPLE_EH_ELSE statement. */
  550. geh_else *
  551. gimple_build_eh_else (gimple_seq n_body, gimple_seq e_body)
  552. {
  553. geh_else *p = as_a <geh_else *> (gimple_alloc (GIMPLE_EH_ELSE, 0));
  554. gimple_eh_else_set_n_body (p, n_body);
  555. gimple_eh_else_set_e_body (p, e_body);
  556. return p;
  557. }
  558. /* Build a GIMPLE_TRY statement.
  559. EVAL is the expression to evaluate.
  560. CLEANUP is the cleanup expression.
  561. KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
  562. whether this is a try/catch or a try/finally respectively. */
  563. gtry *
  564. gimple_build_try (gimple_seq eval, gimple_seq cleanup,
  565. enum gimple_try_flags kind)
  566. {
  567. gtry *p;
  568. gcc_assert (kind == GIMPLE_TRY_CATCH || kind == GIMPLE_TRY_FINALLY);
  569. p = as_a <gtry *> (gimple_alloc (GIMPLE_TRY, 0));
  570. gimple_set_subcode (p, kind);
  571. if (eval)
  572. gimple_try_set_eval (p, eval);
  573. if (cleanup)
  574. gimple_try_set_cleanup (p, cleanup);
  575. return p;
  576. }
  577. /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
  578. CLEANUP is the cleanup expression. */
  579. gimple
  580. gimple_build_wce (gimple_seq cleanup)
  581. {
  582. gimple p = gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR, 0);
  583. if (cleanup)
  584. gimple_wce_set_cleanup (p, cleanup);
  585. return p;
  586. }
  587. /* Build a GIMPLE_RESX statement. */
  588. gresx *
  589. gimple_build_resx (int region)
  590. {
  591. gresx *p
  592. = as_a <gresx *> (gimple_build_with_ops (GIMPLE_RESX, ERROR_MARK, 0));
  593. p->region = region;
  594. return p;
  595. }
  596. /* The helper for constructing a gimple switch statement.
  597. INDEX is the switch's index.
  598. NLABELS is the number of labels in the switch excluding the default.
  599. DEFAULT_LABEL is the default label for the switch statement. */
  600. gswitch *
  601. gimple_build_switch_nlabels (unsigned nlabels, tree index, tree default_label)
  602. {
  603. /* nlabels + 1 default label + 1 index. */
  604. gcc_checking_assert (default_label);
  605. gswitch *p = as_a <gswitch *> (gimple_build_with_ops (GIMPLE_SWITCH,
  606. ERROR_MARK,
  607. 1 + 1 + nlabels));
  608. gimple_switch_set_index (p, index);
  609. gimple_switch_set_default_label (p, default_label);
  610. return p;
  611. }
  612. /* Build a GIMPLE_SWITCH statement.
  613. INDEX is the switch's index.
  614. DEFAULT_LABEL is the default label
  615. ARGS is a vector of labels excluding the default. */
  616. gswitch *
  617. gimple_build_switch (tree index, tree default_label, vec<tree> args)
  618. {
  619. unsigned i, nlabels = args.length ();
  620. gswitch *p = gimple_build_switch_nlabels (nlabels, index, default_label);
  621. /* Copy the labels from the vector to the switch statement. */
  622. for (i = 0; i < nlabels; i++)
  623. gimple_switch_set_label (p, i + 1, args[i]);
  624. return p;
  625. }
  626. /* Build a GIMPLE_EH_DISPATCH statement. */
  627. geh_dispatch *
  628. gimple_build_eh_dispatch (int region)
  629. {
  630. geh_dispatch *p
  631. = as_a <geh_dispatch *> (
  632. gimple_build_with_ops (GIMPLE_EH_DISPATCH, ERROR_MARK, 0));
  633. p->region = region;
  634. return p;
  635. }
  636. /* Build a new GIMPLE_DEBUG_BIND statement.
  637. VAR is bound to VALUE; block and location are taken from STMT. */
  638. gdebug *
  639. gimple_build_debug_bind_stat (tree var, tree value, gimple stmt MEM_STAT_DECL)
  640. {
  641. gdebug *p
  642. = as_a <gdebug *> (gimple_build_with_ops_stat (GIMPLE_DEBUG,
  643. (unsigned)GIMPLE_DEBUG_BIND, 2
  644. PASS_MEM_STAT));
  645. gimple_debug_bind_set_var (p, var);
  646. gimple_debug_bind_set_value (p, value);
  647. if (stmt)
  648. gimple_set_location (p, gimple_location (stmt));
  649. return p;
  650. }
  651. /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
  652. VAR is bound to VALUE; block and location are taken from STMT. */
  653. gdebug *
  654. gimple_build_debug_source_bind_stat (tree var, tree value,
  655. gimple stmt MEM_STAT_DECL)
  656. {
  657. gdebug *p
  658. = as_a <gdebug *> (
  659. gimple_build_with_ops_stat (GIMPLE_DEBUG,
  660. (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
  661. PASS_MEM_STAT));
  662. gimple_debug_source_bind_set_var (p, var);
  663. gimple_debug_source_bind_set_value (p, value);
  664. if (stmt)
  665. gimple_set_location (p, gimple_location (stmt));
  666. return p;
  667. }
  668. /* Build a GIMPLE_OMP_CRITICAL statement.
  669. BODY is the sequence of statements for which only one thread can execute.
  670. NAME is optional identifier for this critical block. */
  671. gomp_critical *
  672. gimple_build_omp_critical (gimple_seq body, tree name)
  673. {
  674. gomp_critical *p
  675. = as_a <gomp_critical *> (gimple_alloc (GIMPLE_OMP_CRITICAL, 0));
  676. gimple_omp_critical_set_name (p, name);
  677. if (body)
  678. gimple_omp_set_body (p, body);
  679. return p;
  680. }
  681. /* Build a GIMPLE_OMP_FOR statement.
  682. BODY is sequence of statements inside the for loop.
  683. KIND is the `for' variant.
  684. CLAUSES, are any of the construct's clauses.
  685. COLLAPSE is the collapse count.
  686. PRE_BODY is the sequence of statements that are loop invariant. */
  687. gomp_for *
  688. gimple_build_omp_for (gimple_seq body, int kind, tree clauses, size_t collapse,
  689. gimple_seq pre_body)
  690. {
  691. gomp_for *p = as_a <gomp_for *> (gimple_alloc (GIMPLE_OMP_FOR, 0));
  692. if (body)
  693. gimple_omp_set_body (p, body);
  694. gimple_omp_for_set_clauses (p, clauses);
  695. gimple_omp_for_set_kind (p, kind);
  696. p->collapse = collapse;
  697. p->iter = ggc_cleared_vec_alloc<gimple_omp_for_iter> (collapse);
  698. if (pre_body)
  699. gimple_omp_for_set_pre_body (p, pre_body);
  700. return p;
  701. }
  702. /* Build a GIMPLE_OMP_PARALLEL statement.
  703. BODY is sequence of statements which are executed in parallel.
  704. CLAUSES, are the OMP parallel construct's clauses.
  705. CHILD_FN is the function created for the parallel threads to execute.
  706. DATA_ARG are the shared data argument(s). */
  707. gomp_parallel *
  708. gimple_build_omp_parallel (gimple_seq body, tree clauses, tree child_fn,
  709. tree data_arg)
  710. {
  711. gomp_parallel *p
  712. = as_a <gomp_parallel *> (gimple_alloc (GIMPLE_OMP_PARALLEL, 0));
  713. if (body)
  714. gimple_omp_set_body (p, body);
  715. gimple_omp_parallel_set_clauses (p, clauses);
  716. gimple_omp_parallel_set_child_fn (p, child_fn);
  717. gimple_omp_parallel_set_data_arg (p, data_arg);
  718. return p;
  719. }
  720. /* Build a GIMPLE_OMP_TASK statement.
  721. BODY is sequence of statements which are executed by the explicit task.
  722. CLAUSES, are the OMP parallel construct's clauses.
  723. CHILD_FN is the function created for the parallel threads to execute.
  724. DATA_ARG are the shared data argument(s).
  725. COPY_FN is the optional function for firstprivate initialization.
  726. ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
  727. gomp_task *
  728. gimple_build_omp_task (gimple_seq body, tree clauses, tree child_fn,
  729. tree data_arg, tree copy_fn, tree arg_size,
  730. tree arg_align)
  731. {
  732. gomp_task *p = as_a <gomp_task *> (gimple_alloc (GIMPLE_OMP_TASK, 0));
  733. if (body)
  734. gimple_omp_set_body (p, body);
  735. gimple_omp_task_set_clauses (p, clauses);
  736. gimple_omp_task_set_child_fn (p, child_fn);
  737. gimple_omp_task_set_data_arg (p, data_arg);
  738. gimple_omp_task_set_copy_fn (p, copy_fn);
  739. gimple_omp_task_set_arg_size (p, arg_size);
  740. gimple_omp_task_set_arg_align (p, arg_align);
  741. return p;
  742. }
  743. /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
  744. BODY is the sequence of statements in the section. */
  745. gimple
  746. gimple_build_omp_section (gimple_seq body)
  747. {
  748. gimple p = gimple_alloc (GIMPLE_OMP_SECTION, 0);
  749. if (body)
  750. gimple_omp_set_body (p, body);
  751. return p;
  752. }
  753. /* Build a GIMPLE_OMP_MASTER statement.
  754. BODY is the sequence of statements to be executed by just the master. */
  755. gimple
  756. gimple_build_omp_master (gimple_seq body)
  757. {
  758. gimple p = gimple_alloc (GIMPLE_OMP_MASTER, 0);
  759. if (body)
  760. gimple_omp_set_body (p, body);
  761. return p;
  762. }
  763. /* Build a GIMPLE_OMP_TASKGROUP statement.
  764. BODY is the sequence of statements to be executed by the taskgroup
  765. construct. */
  766. gimple
  767. gimple_build_omp_taskgroup (gimple_seq body)
  768. {
  769. gimple p = gimple_alloc (GIMPLE_OMP_TASKGROUP, 0);
  770. if (body)
  771. gimple_omp_set_body (p, body);
  772. return p;
  773. }
  774. /* Build a GIMPLE_OMP_CONTINUE statement.
  775. CONTROL_DEF is the definition of the control variable.
  776. CONTROL_USE is the use of the control variable. */
  777. gomp_continue *
  778. gimple_build_omp_continue (tree control_def, tree control_use)
  779. {
  780. gomp_continue *p
  781. = as_a <gomp_continue *> (gimple_alloc (GIMPLE_OMP_CONTINUE, 0));
  782. gimple_omp_continue_set_control_def (p, control_def);
  783. gimple_omp_continue_set_control_use (p, control_use);
  784. return p;
  785. }
  786. /* Build a GIMPLE_OMP_ORDERED statement.
  787. BODY is the sequence of statements inside a loop that will executed in
  788. sequence. */
  789. gimple
  790. gimple_build_omp_ordered (gimple_seq body)
  791. {
  792. gimple p = gimple_alloc (GIMPLE_OMP_ORDERED, 0);
  793. if (body)
  794. gimple_omp_set_body (p, body);
  795. return p;
  796. }
  797. /* Build a GIMPLE_OMP_RETURN statement.
  798. WAIT_P is true if this is a non-waiting return. */
  799. gimple
  800. gimple_build_omp_return (bool wait_p)
  801. {
  802. gimple p = gimple_alloc (GIMPLE_OMP_RETURN, 0);
  803. if (wait_p)
  804. gimple_omp_return_set_nowait (p);
  805. return p;
  806. }
  807. /* Build a GIMPLE_OMP_SECTIONS statement.
  808. BODY is a sequence of section statements.
  809. CLAUSES are any of the OMP sections contsruct's clauses: private,
  810. firstprivate, lastprivate, reduction, and nowait. */
  811. gomp_sections *
  812. gimple_build_omp_sections (gimple_seq body, tree clauses)
  813. {
  814. gomp_sections *p
  815. = as_a <gomp_sections *> (gimple_alloc (GIMPLE_OMP_SECTIONS, 0));
  816. if (body)
  817. gimple_omp_set_body (p, body);
  818. gimple_omp_sections_set_clauses (p, clauses);
  819. return p;
  820. }
  821. /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
  822. gimple
  823. gimple_build_omp_sections_switch (void)
  824. {
  825. return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH, 0);
  826. }
  827. /* Build a GIMPLE_OMP_SINGLE statement.
  828. BODY is the sequence of statements that will be executed once.
  829. CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
  830. copyprivate, nowait. */
  831. gomp_single *
  832. gimple_build_omp_single (gimple_seq body, tree clauses)
  833. {
  834. gomp_single *p
  835. = as_a <gomp_single *> (gimple_alloc (GIMPLE_OMP_SINGLE, 0));
  836. if (body)
  837. gimple_omp_set_body (p, body);
  838. gimple_omp_single_set_clauses (p, clauses);
  839. return p;
  840. }
  841. /* Build a GIMPLE_OMP_TARGET statement.
  842. BODY is the sequence of statements that will be executed.
  843. KIND is the kind of the region.
  844. CLAUSES are any of the construct's clauses. */
  845. gomp_target *
  846. gimple_build_omp_target (gimple_seq body, int kind, tree clauses)
  847. {
  848. gomp_target *p
  849. = as_a <gomp_target *> (gimple_alloc (GIMPLE_OMP_TARGET, 0));
  850. if (body)
  851. gimple_omp_set_body (p, body);
  852. gimple_omp_target_set_clauses (p, clauses);
  853. gimple_omp_target_set_kind (p, kind);
  854. return p;
  855. }
  856. /* Build a GIMPLE_OMP_TEAMS statement.
  857. BODY is the sequence of statements that will be executed.
  858. CLAUSES are any of the OMP teams construct's clauses. */
  859. gomp_teams *
  860. gimple_build_omp_teams (gimple_seq body, tree clauses)
  861. {
  862. gomp_teams *p = as_a <gomp_teams *> (gimple_alloc (GIMPLE_OMP_TEAMS, 0));
  863. if (body)
  864. gimple_omp_set_body (p, body);
  865. gimple_omp_teams_set_clauses (p, clauses);
  866. return p;
  867. }
  868. /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
  869. gomp_atomic_load *
  870. gimple_build_omp_atomic_load (tree lhs, tree rhs)
  871. {
  872. gomp_atomic_load *p
  873. = as_a <gomp_atomic_load *> (gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD, 0));
  874. gimple_omp_atomic_load_set_lhs (p, lhs);
  875. gimple_omp_atomic_load_set_rhs (p, rhs);
  876. return p;
  877. }
  878. /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
  879. VAL is the value we are storing. */
  880. gomp_atomic_store *
  881. gimple_build_omp_atomic_store (tree val)
  882. {
  883. gomp_atomic_store *p
  884. = as_a <gomp_atomic_store *> (gimple_alloc (GIMPLE_OMP_ATOMIC_STORE, 0));
  885. gimple_omp_atomic_store_set_val (p, val);
  886. return p;
  887. }
  888. /* Build a GIMPLE_TRANSACTION statement. */
  889. gtransaction *
  890. gimple_build_transaction (gimple_seq body, tree label)
  891. {
  892. gtransaction *p
  893. = as_a <gtransaction *> (gimple_alloc (GIMPLE_TRANSACTION, 0));
  894. gimple_transaction_set_body (p, body);
  895. gimple_transaction_set_label (p, label);
  896. return p;
  897. }
  898. /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
  899. predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
  900. gimple
  901. gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
  902. {
  903. gimple p = gimple_alloc (GIMPLE_PREDICT, 0);
  904. /* Ensure all the predictors fit into the lower bits of the subcode. */
  905. gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
  906. gimple_predict_set_predictor (p, predictor);
  907. gimple_predict_set_outcome (p, outcome);
  908. return p;
  909. }
  910. #if defined ENABLE_GIMPLE_CHECKING
  911. /* Complain of a gimple type mismatch and die. */
  912. void
  913. gimple_check_failed (const_gimple gs, const char *file, int line,
  914. const char *function, enum gimple_code code,
  915. enum tree_code subcode)
  916. {
  917. internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
  918. gimple_code_name[code],
  919. get_tree_code_name (subcode),
  920. gimple_code_name[gimple_code (gs)],
  921. gs->subcode > 0
  922. ? get_tree_code_name ((enum tree_code) gs->subcode)
  923. : "",
  924. function, trim_filename (file), line);
  925. }
  926. #endif /* ENABLE_GIMPLE_CHECKING */
  927. /* Link gimple statement GS to the end of the sequence *SEQ_P. If
  928. *SEQ_P is NULL, a new sequence is allocated. */
  929. void
  930. gimple_seq_add_stmt (gimple_seq *seq_p, gimple gs)
  931. {
  932. gimple_stmt_iterator si;
  933. if (gs == NULL)
  934. return;
  935. si = gsi_last (*seq_p);
  936. gsi_insert_after (&si, gs, GSI_NEW_STMT);
  937. }
  938. /* Link gimple statement GS to the end of the sequence *SEQ_P. If
  939. *SEQ_P is NULL, a new sequence is allocated. This function is
  940. similar to gimple_seq_add_stmt, but does not scan the operands.
  941. During gimplification, we need to manipulate statement sequences
  942. before the def/use vectors have been constructed. */
  943. void
  944. gimple_seq_add_stmt_without_update (gimple_seq *seq_p, gimple gs)
  945. {
  946. gimple_stmt_iterator si;
  947. if (gs == NULL)
  948. return;
  949. si = gsi_last (*seq_p);
  950. gsi_insert_after_without_update (&si, gs, GSI_NEW_STMT);
  951. }
  952. /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
  953. NULL, a new sequence is allocated. */
  954. void
  955. gimple_seq_add_seq (gimple_seq *dst_p, gimple_seq src)
  956. {
  957. gimple_stmt_iterator si;
  958. if (src == NULL)
  959. return;
  960. si = gsi_last (*dst_p);
  961. gsi_insert_seq_after (&si, src, GSI_NEW_STMT);
  962. }
  963. /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
  964. NULL, a new sequence is allocated. This function is
  965. similar to gimple_seq_add_seq, but does not scan the operands. */
  966. void
  967. gimple_seq_add_seq_without_update (gimple_seq *dst_p, gimple_seq src)
  968. {
  969. gimple_stmt_iterator si;
  970. if (src == NULL)
  971. return;
  972. si = gsi_last (*dst_p);
  973. gsi_insert_seq_after_without_update (&si, src, GSI_NEW_STMT);
  974. }
  975. /* Determine whether to assign a location to the statement GS. */
  976. static bool
  977. should_carry_location_p (gimple gs)
  978. {
  979. /* Don't emit a line note for a label. We particularly don't want to
  980. emit one for the break label, since it doesn't actually correspond
  981. to the beginning of the loop/switch. */
  982. if (gimple_code (gs) == GIMPLE_LABEL)
  983. return false;
  984. return true;
  985. }
  986. /* Set the location for gimple statement GS to LOCATION. */
  987. static void
  988. annotate_one_with_location (gimple gs, location_t location)
  989. {
  990. if (!gimple_has_location (gs)
  991. && !gimple_do_not_emit_location_p (gs)
  992. && should_carry_location_p (gs))
  993. gimple_set_location (gs, location);
  994. }
  995. /* Set LOCATION for all the statements after iterator GSI in sequence
  996. SEQ. If GSI is pointing to the end of the sequence, start with the
  997. first statement in SEQ. */
  998. void
  999. annotate_all_with_location_after (gimple_seq seq, gimple_stmt_iterator gsi,
  1000. location_t location)
  1001. {
  1002. if (gsi_end_p (gsi))
  1003. gsi = gsi_start (seq);
  1004. else
  1005. gsi_next (&gsi);
  1006. for (; !gsi_end_p (gsi); gsi_next (&gsi))
  1007. annotate_one_with_location (gsi_stmt (gsi), location);
  1008. }
  1009. /* Set the location for all the statements in a sequence STMT_P to LOCATION. */
  1010. void
  1011. annotate_all_with_location (gimple_seq stmt_p, location_t location)
  1012. {
  1013. gimple_stmt_iterator i;
  1014. if (gimple_seq_empty_p (stmt_p))
  1015. return;
  1016. for (i = gsi_start (stmt_p); !gsi_end_p (i); gsi_next (&i))
  1017. {
  1018. gimple gs = gsi_stmt (i);
  1019. annotate_one_with_location (gs, location);
  1020. }
  1021. }
  1022. /* Helper function of empty_body_p. Return true if STMT is an empty
  1023. statement. */
  1024. static bool
  1025. empty_stmt_p (gimple stmt)
  1026. {
  1027. if (gimple_code (stmt) == GIMPLE_NOP)
  1028. return true;
  1029. if (gbind *bind_stmt = dyn_cast <gbind *> (stmt))
  1030. return empty_body_p (gimple_bind_body (bind_stmt));
  1031. return false;
  1032. }
  1033. /* Return true if BODY contains nothing but empty statements. */
  1034. bool
  1035. empty_body_p (gimple_seq body)
  1036. {
  1037. gimple_stmt_iterator i;
  1038. if (gimple_seq_empty_p (body))
  1039. return true;
  1040. for (i = gsi_start (body); !gsi_end_p (i); gsi_next (&i))
  1041. if (!empty_stmt_p (gsi_stmt (i))
  1042. && !is_gimple_debug (gsi_stmt (i)))
  1043. return false;
  1044. return true;
  1045. }
  1046. /* Perform a deep copy of sequence SRC and return the result. */
  1047. gimple_seq
  1048. gimple_seq_copy (gimple_seq src)
  1049. {
  1050. gimple_stmt_iterator gsi;
  1051. gimple_seq new_seq = NULL;
  1052. gimple stmt;
  1053. for (gsi = gsi_start (src); !gsi_end_p (gsi); gsi_next (&gsi))
  1054. {
  1055. stmt = gimple_copy (gsi_stmt (gsi));
  1056. gimple_seq_add_stmt (&new_seq, stmt);
  1057. }
  1058. return new_seq;
  1059. }
  1060. /* Return true if calls C1 and C2 are known to go to the same function. */
  1061. bool
  1062. gimple_call_same_target_p (const_gimple c1, const_gimple c2)
  1063. {
  1064. if (gimple_call_internal_p (c1))
  1065. return (gimple_call_internal_p (c2)
  1066. && gimple_call_internal_fn (c1) == gimple_call_internal_fn (c2));
  1067. else
  1068. return (gimple_call_fn (c1) == gimple_call_fn (c2)
  1069. || (gimple_call_fndecl (c1)
  1070. && gimple_call_fndecl (c1) == gimple_call_fndecl (c2)));
  1071. }
  1072. /* Detect flags from a GIMPLE_CALL. This is just like
  1073. call_expr_flags, but for gimple tuples. */
  1074. int
  1075. gimple_call_flags (const_gimple stmt)
  1076. {
  1077. int flags;
  1078. tree decl = gimple_call_fndecl (stmt);
  1079. if (decl)
  1080. flags = flags_from_decl_or_type (decl);
  1081. else if (gimple_call_internal_p (stmt))
  1082. flags = internal_fn_flags (gimple_call_internal_fn (stmt));
  1083. else
  1084. flags = flags_from_decl_or_type (gimple_call_fntype (stmt));
  1085. if (stmt->subcode & GF_CALL_NOTHROW)
  1086. flags |= ECF_NOTHROW;
  1087. return flags;
  1088. }
  1089. /* Return the "fn spec" string for call STMT. */
  1090. static const_tree
  1091. gimple_call_fnspec (const gcall *stmt)
  1092. {
  1093. tree type, attr;
  1094. if (gimple_call_internal_p (stmt))
  1095. return internal_fn_fnspec (gimple_call_internal_fn (stmt));
  1096. type = gimple_call_fntype (stmt);
  1097. if (!type)
  1098. return NULL_TREE;
  1099. attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
  1100. if (!attr)
  1101. return NULL_TREE;
  1102. return TREE_VALUE (TREE_VALUE (attr));
  1103. }
  1104. /* Detects argument flags for argument number ARG on call STMT. */
  1105. int
  1106. gimple_call_arg_flags (const gcall *stmt, unsigned arg)
  1107. {
  1108. const_tree attr = gimple_call_fnspec (stmt);
  1109. if (!attr || 1 + arg >= (unsigned) TREE_STRING_LENGTH (attr))
  1110. return 0;
  1111. switch (TREE_STRING_POINTER (attr)[1 + arg])
  1112. {
  1113. case 'x':
  1114. case 'X':
  1115. return EAF_UNUSED;
  1116. case 'R':
  1117. return EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE;
  1118. case 'r':
  1119. return EAF_NOCLOBBER | EAF_NOESCAPE;
  1120. case 'W':
  1121. return EAF_DIRECT | EAF_NOESCAPE;
  1122. case 'w':
  1123. return EAF_NOESCAPE;
  1124. case '.':
  1125. default:
  1126. return 0;
  1127. }
  1128. }
  1129. /* Detects return flags for the call STMT. */
  1130. int
  1131. gimple_call_return_flags (const gcall *stmt)
  1132. {
  1133. const_tree attr;
  1134. if (gimple_call_flags (stmt) & ECF_MALLOC)
  1135. return ERF_NOALIAS;
  1136. attr = gimple_call_fnspec (stmt);
  1137. if (!attr || TREE_STRING_LENGTH (attr) < 1)
  1138. return 0;
  1139. switch (TREE_STRING_POINTER (attr)[0])
  1140. {
  1141. case '1':
  1142. case '2':
  1143. case '3':
  1144. case '4':
  1145. return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
  1146. case 'm':
  1147. return ERF_NOALIAS;
  1148. case '.':
  1149. default:
  1150. return 0;
  1151. }
  1152. }
  1153. /* Return true if GS is a copy assignment. */
  1154. bool
  1155. gimple_assign_copy_p (gimple gs)
  1156. {
  1157. return (gimple_assign_single_p (gs)
  1158. && is_gimple_val (gimple_op (gs, 1)));
  1159. }
  1160. /* Return true if GS is a SSA_NAME copy assignment. */
  1161. bool
  1162. gimple_assign_ssa_name_copy_p (gimple gs)
  1163. {
  1164. return (gimple_assign_single_p (gs)
  1165. && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
  1166. && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
  1167. }
  1168. /* Return true if GS is an assignment with a unary RHS, but the
  1169. operator has no effect on the assigned value. The logic is adapted
  1170. from STRIP_NOPS. This predicate is intended to be used in tuplifying
  1171. instances in which STRIP_NOPS was previously applied to the RHS of
  1172. an assignment.
  1173. NOTE: In the use cases that led to the creation of this function
  1174. and of gimple_assign_single_p, it is typical to test for either
  1175. condition and to proceed in the same manner. In each case, the
  1176. assigned value is represented by the single RHS operand of the
  1177. assignment. I suspect there may be cases where gimple_assign_copy_p,
  1178. gimple_assign_single_p, or equivalent logic is used where a similar
  1179. treatment of unary NOPs is appropriate. */
  1180. bool
  1181. gimple_assign_unary_nop_p (gimple gs)
  1182. {
  1183. return (is_gimple_assign (gs)
  1184. && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
  1185. || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
  1186. && gimple_assign_rhs1 (gs) != error_mark_node
  1187. && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs)))
  1188. == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs)))));
  1189. }
  1190. /* Set BB to be the basic block holding G. */
  1191. void
  1192. gimple_set_bb (gimple stmt, basic_block bb)
  1193. {
  1194. stmt->bb = bb;
  1195. if (gimple_code (stmt) != GIMPLE_LABEL)
  1196. return;
  1197. /* If the statement is a label, add the label to block-to-labels map
  1198. so that we can speed up edge creation for GIMPLE_GOTOs. */
  1199. if (cfun->cfg)
  1200. {
  1201. tree t;
  1202. int uid;
  1203. t = gimple_label_label (as_a <glabel *> (stmt));
  1204. uid = LABEL_DECL_UID (t);
  1205. if (uid == -1)
  1206. {
  1207. unsigned old_len =
  1208. vec_safe_length (label_to_block_map_for_fn (cfun));
  1209. LABEL_DECL_UID (t) = uid = cfun->cfg->last_label_uid++;
  1210. if (old_len <= (unsigned) uid)
  1211. {
  1212. unsigned new_len = 3 * uid / 2 + 1;
  1213. vec_safe_grow_cleared (label_to_block_map_for_fn (cfun),
  1214. new_len);
  1215. }
  1216. }
  1217. (*label_to_block_map_for_fn (cfun))[uid] = bb;
  1218. }
  1219. }
  1220. /* Modify the RHS of the assignment pointed-to by GSI using the
  1221. operands in the expression tree EXPR.
  1222. NOTE: The statement pointed-to by GSI may be reallocated if it
  1223. did not have enough operand slots.
  1224. This function is useful to convert an existing tree expression into
  1225. the flat representation used for the RHS of a GIMPLE assignment.
  1226. It will reallocate memory as needed to expand or shrink the number
  1227. of operand slots needed to represent EXPR.
  1228. NOTE: If you find yourself building a tree and then calling this
  1229. function, you are most certainly doing it the slow way. It is much
  1230. better to build a new assignment or to use the function
  1231. gimple_assign_set_rhs_with_ops, which does not require an
  1232. expression tree to be built. */
  1233. void
  1234. gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *gsi, tree expr)
  1235. {
  1236. enum tree_code subcode;
  1237. tree op1, op2, op3;
  1238. extract_ops_from_tree_1 (expr, &subcode, &op1, &op2, &op3);
  1239. gimple_assign_set_rhs_with_ops (gsi, subcode, op1, op2, op3);
  1240. }
  1241. /* Set the RHS of assignment statement pointed-to by GSI to CODE with
  1242. operands OP1, OP2 and OP3.
  1243. NOTE: The statement pointed-to by GSI may be reallocated if it
  1244. did not have enough operand slots. */
  1245. void
  1246. gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *gsi, enum tree_code code,
  1247. tree op1, tree op2, tree op3)
  1248. {
  1249. unsigned new_rhs_ops = get_gimple_rhs_num_ops (code);
  1250. gimple stmt = gsi_stmt (*gsi);
  1251. /* If the new CODE needs more operands, allocate a new statement. */
  1252. if (gimple_num_ops (stmt) < new_rhs_ops + 1)
  1253. {
  1254. tree lhs = gimple_assign_lhs (stmt);
  1255. gimple new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1);
  1256. memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt)));
  1257. gimple_init_singleton (new_stmt);
  1258. gsi_replace (gsi, new_stmt, true);
  1259. stmt = new_stmt;
  1260. /* The LHS needs to be reset as this also changes the SSA name
  1261. on the LHS. */
  1262. gimple_assign_set_lhs (stmt, lhs);
  1263. }
  1264. gimple_set_num_ops (stmt, new_rhs_ops + 1);
  1265. gimple_set_subcode (stmt, code);
  1266. gimple_assign_set_rhs1 (stmt, op1);
  1267. if (new_rhs_ops > 1)
  1268. gimple_assign_set_rhs2 (stmt, op2);
  1269. if (new_rhs_ops > 2)
  1270. gimple_assign_set_rhs3 (stmt, op3);
  1271. }
  1272. /* Return the LHS of a statement that performs an assignment,
  1273. either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
  1274. for a call to a function that returns no value, or for a
  1275. statement other than an assignment or a call. */
  1276. tree
  1277. gimple_get_lhs (const_gimple stmt)
  1278. {
  1279. enum gimple_code code = gimple_code (stmt);
  1280. if (code == GIMPLE_ASSIGN)
  1281. return gimple_assign_lhs (stmt);
  1282. else if (code == GIMPLE_CALL)
  1283. return gimple_call_lhs (stmt);
  1284. else
  1285. return NULL_TREE;
  1286. }
  1287. /* Set the LHS of a statement that performs an assignment,
  1288. either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
  1289. void
  1290. gimple_set_lhs (gimple stmt, tree lhs)
  1291. {
  1292. enum gimple_code code = gimple_code (stmt);
  1293. if (code == GIMPLE_ASSIGN)
  1294. gimple_assign_set_lhs (stmt, lhs);
  1295. else if (code == GIMPLE_CALL)
  1296. gimple_call_set_lhs (stmt, lhs);
  1297. else
  1298. gcc_unreachable ();
  1299. }
  1300. /* Return a deep copy of statement STMT. All the operands from STMT
  1301. are reallocated and copied using unshare_expr. The DEF, USE, VDEF
  1302. and VUSE operand arrays are set to empty in the new copy. The new
  1303. copy isn't part of any sequence. */
  1304. gimple
  1305. gimple_copy (gimple stmt)
  1306. {
  1307. enum gimple_code code = gimple_code (stmt);
  1308. unsigned num_ops = gimple_num_ops (stmt);
  1309. gimple copy = gimple_alloc (code, num_ops);
  1310. unsigned i;
  1311. /* Shallow copy all the fields from STMT. */
  1312. memcpy (copy, stmt, gimple_size (code));
  1313. gimple_init_singleton (copy);
  1314. /* If STMT has sub-statements, deep-copy them as well. */
  1315. if (gimple_has_substatements (stmt))
  1316. {
  1317. gimple_seq new_seq;
  1318. tree t;
  1319. switch (gimple_code (stmt))
  1320. {
  1321. case GIMPLE_BIND:
  1322. {
  1323. gbind *bind_stmt = as_a <gbind *> (stmt);
  1324. gbind *bind_copy = as_a <gbind *> (copy);
  1325. new_seq = gimple_seq_copy (gimple_bind_body (bind_stmt));
  1326. gimple_bind_set_body (bind_copy, new_seq);
  1327. gimple_bind_set_vars (bind_copy,
  1328. unshare_expr (gimple_bind_vars (bind_stmt)));
  1329. gimple_bind_set_block (bind_copy, gimple_bind_block (bind_stmt));
  1330. }
  1331. break;
  1332. case GIMPLE_CATCH:
  1333. {
  1334. gcatch *catch_stmt = as_a <gcatch *> (stmt);
  1335. gcatch *catch_copy = as_a <gcatch *> (copy);
  1336. new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt));
  1337. gimple_catch_set_handler (catch_copy, new_seq);
  1338. t = unshare_expr (gimple_catch_types (catch_stmt));
  1339. gimple_catch_set_types (catch_copy, t);
  1340. }
  1341. break;
  1342. case GIMPLE_EH_FILTER:
  1343. {
  1344. geh_filter *eh_filter_stmt = as_a <geh_filter *> (stmt);
  1345. geh_filter *eh_filter_copy = as_a <geh_filter *> (copy);
  1346. new_seq
  1347. = gimple_seq_copy (gimple_eh_filter_failure (eh_filter_stmt));
  1348. gimple_eh_filter_set_failure (eh_filter_copy, new_seq);
  1349. t = unshare_expr (gimple_eh_filter_types (eh_filter_stmt));
  1350. gimple_eh_filter_set_types (eh_filter_copy, t);
  1351. }
  1352. break;
  1353. case GIMPLE_EH_ELSE:
  1354. {
  1355. geh_else *eh_else_stmt = as_a <geh_else *> (stmt);
  1356. geh_else *eh_else_copy = as_a <geh_else *> (copy);
  1357. new_seq = gimple_seq_copy (gimple_eh_else_n_body (eh_else_stmt));
  1358. gimple_eh_else_set_n_body (eh_else_copy, new_seq);
  1359. new_seq = gimple_seq_copy (gimple_eh_else_e_body (eh_else_stmt));
  1360. gimple_eh_else_set_e_body (eh_else_copy, new_seq);
  1361. }
  1362. break;
  1363. case GIMPLE_TRY:
  1364. {
  1365. gtry *try_stmt = as_a <gtry *> (stmt);
  1366. gtry *try_copy = as_a <gtry *> (copy);
  1367. new_seq = gimple_seq_copy (gimple_try_eval (try_stmt));
  1368. gimple_try_set_eval (try_copy, new_seq);
  1369. new_seq = gimple_seq_copy (gimple_try_cleanup (try_stmt));
  1370. gimple_try_set_cleanup (try_copy, new_seq);
  1371. }
  1372. break;
  1373. case GIMPLE_OMP_FOR:
  1374. new_seq = gimple_seq_copy (gimple_omp_for_pre_body (stmt));
  1375. gimple_omp_for_set_pre_body (copy, new_seq);
  1376. t = unshare_expr (gimple_omp_for_clauses (stmt));
  1377. gimple_omp_for_set_clauses (copy, t);
  1378. {
  1379. gomp_for *omp_for_copy = as_a <gomp_for *> (copy);
  1380. omp_for_copy->iter = ggc_vec_alloc<gimple_omp_for_iter>
  1381. ( gimple_omp_for_collapse (stmt));
  1382. }
  1383. for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
  1384. {
  1385. gimple_omp_for_set_cond (copy, i,
  1386. gimple_omp_for_cond (stmt, i));
  1387. gimple_omp_for_set_index (copy, i,
  1388. gimple_omp_for_index (stmt, i));
  1389. t = unshare_expr (gimple_omp_for_initial (stmt, i));
  1390. gimple_omp_for_set_initial (copy, i, t);
  1391. t = unshare_expr (gimple_omp_for_final (stmt, i));
  1392. gimple_omp_for_set_final (copy, i, t);
  1393. t = unshare_expr (gimple_omp_for_incr (stmt, i));
  1394. gimple_omp_for_set_incr (copy, i, t);
  1395. }
  1396. goto copy_omp_body;
  1397. case GIMPLE_OMP_PARALLEL:
  1398. {
  1399. gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
  1400. gomp_parallel *omp_par_copy = as_a <gomp_parallel *> (copy);
  1401. t = unshare_expr (gimple_omp_parallel_clauses (omp_par_stmt));
  1402. gimple_omp_parallel_set_clauses (omp_par_copy, t);
  1403. t = unshare_expr (gimple_omp_parallel_child_fn (omp_par_stmt));
  1404. gimple_omp_parallel_set_child_fn (omp_par_copy, t);
  1405. t = unshare_expr (gimple_omp_parallel_data_arg (omp_par_stmt));
  1406. gimple_omp_parallel_set_data_arg (omp_par_copy, t);
  1407. }
  1408. goto copy_omp_body;
  1409. case GIMPLE_OMP_TASK:
  1410. t = unshare_expr (gimple_omp_task_clauses (stmt));
  1411. gimple_omp_task_set_clauses (copy, t);
  1412. t = unshare_expr (gimple_omp_task_child_fn (stmt));
  1413. gimple_omp_task_set_child_fn (copy, t);
  1414. t = unshare_expr (gimple_omp_task_data_arg (stmt));
  1415. gimple_omp_task_set_data_arg (copy, t);
  1416. t = unshare_expr (gimple_omp_task_copy_fn (stmt));
  1417. gimple_omp_task_set_copy_fn (copy, t);
  1418. t = unshare_expr (gimple_omp_task_arg_size (stmt));
  1419. gimple_omp_task_set_arg_size (copy, t);
  1420. t = unshare_expr (gimple_omp_task_arg_align (stmt));
  1421. gimple_omp_task_set_arg_align (copy, t);
  1422. goto copy_omp_body;
  1423. case GIMPLE_OMP_CRITICAL:
  1424. t = unshare_expr (gimple_omp_critical_name (
  1425. as_a <gomp_critical *> (stmt)));
  1426. gimple_omp_critical_set_name (as_a <gomp_critical *> (copy), t);
  1427. goto copy_omp_body;
  1428. case GIMPLE_OMP_SECTIONS:
  1429. t = unshare_expr (gimple_omp_sections_clauses (stmt));
  1430. gimple_omp_sections_set_clauses (copy, t);
  1431. t = unshare_expr (gimple_omp_sections_control (stmt));
  1432. gimple_omp_sections_set_control (copy, t);
  1433. /* FALLTHRU */
  1434. case GIMPLE_OMP_SINGLE:
  1435. case GIMPLE_OMP_TARGET:
  1436. case GIMPLE_OMP_TEAMS:
  1437. case GIMPLE_OMP_SECTION:
  1438. case GIMPLE_OMP_MASTER:
  1439. case GIMPLE_OMP_TASKGROUP:
  1440. case GIMPLE_OMP_ORDERED:
  1441. copy_omp_body:
  1442. new_seq = gimple_seq_copy (gimple_omp_body (stmt));
  1443. gimple_omp_set_body (copy, new_seq);
  1444. break;
  1445. case GIMPLE_TRANSACTION:
  1446. new_seq = gimple_seq_copy (gimple_transaction_body (
  1447. as_a <gtransaction *> (stmt)));
  1448. gimple_transaction_set_body (as_a <gtransaction *> (copy),
  1449. new_seq);
  1450. break;
  1451. case GIMPLE_WITH_CLEANUP_EXPR:
  1452. new_seq = gimple_seq_copy (gimple_wce_cleanup (stmt));
  1453. gimple_wce_set_cleanup (copy, new_seq);
  1454. break;
  1455. default:
  1456. gcc_unreachable ();
  1457. }
  1458. }
  1459. /* Make copy of operands. */
  1460. for (i = 0; i < num_ops; i++)
  1461. gimple_set_op (copy, i, unshare_expr (gimple_op (stmt, i)));
  1462. if (gimple_has_mem_ops (stmt))
  1463. {
  1464. gimple_set_vdef (copy, gimple_vdef (stmt));
  1465. gimple_set_vuse (copy, gimple_vuse (stmt));
  1466. }
  1467. /* Clear out SSA operand vectors on COPY. */
  1468. if (gimple_has_ops (stmt))
  1469. {
  1470. gimple_set_use_ops (copy, NULL);
  1471. /* SSA operands need to be updated. */
  1472. gimple_set_modified (copy, true);
  1473. }
  1474. return copy;
  1475. }
  1476. /* Return true if statement S has side-effects. We consider a
  1477. statement to have side effects if:
  1478. - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
  1479. - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
  1480. bool
  1481. gimple_has_side_effects (const_gimple s)
  1482. {
  1483. if (is_gimple_debug (s))
  1484. return false;
  1485. /* We don't have to scan the arguments to check for
  1486. volatile arguments, though, at present, we still
  1487. do a scan to check for TREE_SIDE_EFFECTS. */
  1488. if (gimple_has_volatile_ops (s))
  1489. return true;
  1490. if (gimple_code (s) == GIMPLE_ASM
  1491. && gimple_asm_volatile_p (as_a <const gasm *> (s)))
  1492. return true;
  1493. if (is_gimple_call (s))
  1494. {
  1495. int flags = gimple_call_flags (s);
  1496. /* An infinite loop is considered a side effect. */
  1497. if (!(flags & (ECF_CONST | ECF_PURE))
  1498. || (flags & ECF_LOOPING_CONST_OR_PURE))
  1499. return true;
  1500. return false;
  1501. }
  1502. return false;
  1503. }
  1504. /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
  1505. Return true if S can trap. When INCLUDE_MEM is true, check whether
  1506. the memory operations could trap. When INCLUDE_STORES is true and
  1507. S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
  1508. bool
  1509. gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
  1510. {
  1511. tree t, div = NULL_TREE;
  1512. enum tree_code op;
  1513. if (include_mem)
  1514. {
  1515. unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
  1516. for (i = start; i < gimple_num_ops (s); i++)
  1517. if (tree_could_trap_p (gimple_op (s, i)))
  1518. return true;
  1519. }
  1520. switch (gimple_code (s))
  1521. {
  1522. case GIMPLE_ASM:
  1523. return gimple_asm_volatile_p (as_a <gasm *> (s));
  1524. case GIMPLE_CALL:
  1525. t = gimple_call_fndecl (s);
  1526. /* Assume that calls to weak functions may trap. */
  1527. if (!t || !DECL_P (t) || DECL_WEAK (t))
  1528. return true;
  1529. return false;
  1530. case GIMPLE_ASSIGN:
  1531. t = gimple_expr_type (s);
  1532. op = gimple_assign_rhs_code (s);
  1533. if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
  1534. div = gimple_assign_rhs2 (s);
  1535. return (operation_could_trap_p (op, FLOAT_TYPE_P (t),
  1536. (INTEGRAL_TYPE_P (t)
  1537. && TYPE_OVERFLOW_TRAPS (t)),
  1538. div));
  1539. default:
  1540. break;
  1541. }
  1542. return false;
  1543. }
  1544. /* Return true if statement S can trap. */
  1545. bool
  1546. gimple_could_trap_p (gimple s)
  1547. {
  1548. return gimple_could_trap_p_1 (s, true, true);
  1549. }
  1550. /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
  1551. bool
  1552. gimple_assign_rhs_could_trap_p (gimple s)
  1553. {
  1554. gcc_assert (is_gimple_assign (s));
  1555. return gimple_could_trap_p_1 (s, true, false);
  1556. }
  1557. /* Print debugging information for gimple stmts generated. */
  1558. void
  1559. dump_gimple_statistics (void)
  1560. {
  1561. int i, total_tuples = 0, total_bytes = 0;
  1562. if (! GATHER_STATISTICS)
  1563. {
  1564. fprintf (stderr, "No gimple statistics\n");
  1565. return;
  1566. }
  1567. fprintf (stderr, "\nGIMPLE statements\n");
  1568. fprintf (stderr, "Kind Stmts Bytes\n");
  1569. fprintf (stderr, "---------------------------------------\n");
  1570. for (i = 0; i < (int) gimple_alloc_kind_all; ++i)
  1571. {
  1572. fprintf (stderr, "%-20s %7d %10d\n", gimple_alloc_kind_names[i],
  1573. gimple_alloc_counts[i], gimple_alloc_sizes[i]);
  1574. total_tuples += gimple_alloc_counts[i];
  1575. total_bytes += gimple_alloc_sizes[i];
  1576. }
  1577. fprintf (stderr, "---------------------------------------\n");
  1578. fprintf (stderr, "%-20s %7d %10d\n", "Total", total_tuples, total_bytes);
  1579. fprintf (stderr, "---------------------------------------\n");
  1580. }
  1581. /* Return the number of operands needed on the RHS of a GIMPLE
  1582. assignment for an expression with tree code CODE. */
  1583. unsigned
  1584. get_gimple_rhs_num_ops (enum tree_code code)
  1585. {
  1586. enum gimple_rhs_class rhs_class = get_gimple_rhs_class (code);
  1587. if (rhs_class == GIMPLE_UNARY_RHS || rhs_class == GIMPLE_SINGLE_RHS)
  1588. return 1;
  1589. else if (rhs_class == GIMPLE_BINARY_RHS)
  1590. return 2;
  1591. else if (rhs_class == GIMPLE_TERNARY_RHS)
  1592. return 3;
  1593. else
  1594. gcc_unreachable ();
  1595. }
  1596. #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
  1597. (unsigned char) \
  1598. ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
  1599. : ((TYPE) == tcc_binary \
  1600. || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
  1601. : ((TYPE) == tcc_constant \
  1602. || (TYPE) == tcc_declaration \
  1603. || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
  1604. : ((SYM) == TRUTH_AND_EXPR \
  1605. || (SYM) == TRUTH_OR_EXPR \
  1606. || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
  1607. : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
  1608. : ((SYM) == COND_EXPR \
  1609. || (SYM) == WIDEN_MULT_PLUS_EXPR \
  1610. || (SYM) == WIDEN_MULT_MINUS_EXPR \
  1611. || (SYM) == DOT_PROD_EXPR \
  1612. || (SYM) == SAD_EXPR \
  1613. || (SYM) == REALIGN_LOAD_EXPR \
  1614. || (SYM) == VEC_COND_EXPR \
  1615. || (SYM) == VEC_PERM_EXPR \
  1616. || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
  1617. : ((SYM) == CONSTRUCTOR \
  1618. || (SYM) == OBJ_TYPE_REF \
  1619. || (SYM) == ASSERT_EXPR \
  1620. || (SYM) == ADDR_EXPR \
  1621. || (SYM) == WITH_SIZE_EXPR \
  1622. || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
  1623. : GIMPLE_INVALID_RHS),
  1624. #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
  1625. const unsigned char gimple_rhs_class_table[] = {
  1626. #include "all-tree.def"
  1627. };
  1628. #undef DEFTREECODE
  1629. #undef END_OF_BASE_TREE_CODES
  1630. /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
  1631. a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
  1632. we failed to create one. */
  1633. tree
  1634. canonicalize_cond_expr_cond (tree t)
  1635. {
  1636. /* Strip conversions around boolean operations. */
  1637. if (CONVERT_EXPR_P (t)
  1638. && (truth_value_p (TREE_CODE (TREE_OPERAND (t, 0)))
  1639. || TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
  1640. == BOOLEAN_TYPE))
  1641. t = TREE_OPERAND (t, 0);
  1642. /* For !x use x == 0. */
  1643. if (TREE_CODE (t) == TRUTH_NOT_EXPR)
  1644. {
  1645. tree top0 = TREE_OPERAND (t, 0);
  1646. t = build2 (EQ_EXPR, TREE_TYPE (t),
  1647. top0, build_int_cst (TREE_TYPE (top0), 0));
  1648. }
  1649. /* For cmp ? 1 : 0 use cmp. */
  1650. else if (TREE_CODE (t) == COND_EXPR
  1651. && COMPARISON_CLASS_P (TREE_OPERAND (t, 0))
  1652. && integer_onep (TREE_OPERAND (t, 1))
  1653. && integer_zerop (TREE_OPERAND (t, 2)))
  1654. {
  1655. tree top0 = TREE_OPERAND (t, 0);
  1656. t = build2 (TREE_CODE (top0), TREE_TYPE (t),
  1657. TREE_OPERAND (top0, 0), TREE_OPERAND (top0, 1));
  1658. }
  1659. /* For x ^ y use x != y. */
  1660. else if (TREE_CODE (t) == BIT_XOR_EXPR)
  1661. t = build2 (NE_EXPR, TREE_TYPE (t),
  1662. TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
  1663. if (is_gimple_condexpr (t))
  1664. return t;
  1665. return NULL_TREE;
  1666. }
  1667. /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
  1668. the positions marked by the set ARGS_TO_SKIP. */
  1669. gcall *
  1670. gimple_call_copy_skip_args (gcall *stmt, bitmap args_to_skip)
  1671. {
  1672. int i;
  1673. int nargs = gimple_call_num_args (stmt);
  1674. auto_vec<tree> vargs (nargs);
  1675. gcall *new_stmt;
  1676. for (i = 0; i < nargs; i++)
  1677. if (!bitmap_bit_p (args_to_skip, i))
  1678. vargs.quick_push (gimple_call_arg (stmt, i));
  1679. if (gimple_call_internal_p (stmt))
  1680. new_stmt = gimple_build_call_internal_vec (gimple_call_internal_fn (stmt),
  1681. vargs);
  1682. else
  1683. new_stmt = gimple_build_call_vec (gimple_call_fn (stmt), vargs);
  1684. if (gimple_call_lhs (stmt))
  1685. gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
  1686. gimple_set_vuse (new_stmt, gimple_vuse (stmt));
  1687. gimple_set_vdef (new_stmt, gimple_vdef (stmt));
  1688. if (gimple_has_location (stmt))
  1689. gimple_set_location (new_stmt, gimple_location (stmt));
  1690. gimple_call_copy_flags (new_stmt, stmt);
  1691. gimple_call_set_chain (new_stmt, gimple_call_chain (stmt));
  1692. gimple_set_modified (new_stmt, true);
  1693. return new_stmt;
  1694. }
  1695. /* Return true if the field decls F1 and F2 are at the same offset.
  1696. This is intended to be used on GIMPLE types only. */
  1697. bool
  1698. gimple_compare_field_offset (tree f1, tree f2)
  1699. {
  1700. if (DECL_OFFSET_ALIGN (f1) == DECL_OFFSET_ALIGN (f2))
  1701. {
  1702. tree offset1 = DECL_FIELD_OFFSET (f1);
  1703. tree offset2 = DECL_FIELD_OFFSET (f2);
  1704. return ((offset1 == offset2
  1705. /* Once gimplification is done, self-referential offsets are
  1706. instantiated as operand #2 of the COMPONENT_REF built for
  1707. each access and reset. Therefore, they are not relevant
  1708. anymore and fields are interchangeable provided that they
  1709. represent the same access. */
  1710. || (TREE_CODE (offset1) == PLACEHOLDER_EXPR
  1711. && TREE_CODE (offset2) == PLACEHOLDER_EXPR
  1712. && (DECL_SIZE (f1) == DECL_SIZE (f2)
  1713. || (TREE_CODE (DECL_SIZE (f1)) == PLACEHOLDER_EXPR
  1714. && TREE_CODE (DECL_SIZE (f2)) == PLACEHOLDER_EXPR)
  1715. || operand_equal_p (DECL_SIZE (f1), DECL_SIZE (f2), 0))
  1716. && DECL_ALIGN (f1) == DECL_ALIGN (f2))
  1717. || operand_equal_p (offset1, offset2, 0))
  1718. && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1),
  1719. DECL_FIELD_BIT_OFFSET (f2)));
  1720. }
  1721. /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
  1722. should be, so handle differing ones specially by decomposing
  1723. the offset into a byte and bit offset manually. */
  1724. if (tree_fits_shwi_p (DECL_FIELD_OFFSET (f1))
  1725. && tree_fits_shwi_p (DECL_FIELD_OFFSET (f2)))
  1726. {
  1727. unsigned HOST_WIDE_INT byte_offset1, byte_offset2;
  1728. unsigned HOST_WIDE_INT bit_offset1, bit_offset2;
  1729. bit_offset1 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1));
  1730. byte_offset1 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1))
  1731. + bit_offset1 / BITS_PER_UNIT);
  1732. bit_offset2 = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2));
  1733. byte_offset2 = (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2))
  1734. + bit_offset2 / BITS_PER_UNIT);
  1735. if (byte_offset1 != byte_offset2)
  1736. return false;
  1737. return bit_offset1 % BITS_PER_UNIT == bit_offset2 % BITS_PER_UNIT;
  1738. }
  1739. return false;
  1740. }
  1741. /* Return a type the same as TYPE except unsigned or
  1742. signed according to UNSIGNEDP. */
  1743. static tree
  1744. gimple_signed_or_unsigned_type (bool unsignedp, tree type)
  1745. {
  1746. tree type1;
  1747. int i;
  1748. type1 = TYPE_MAIN_VARIANT (type);
  1749. if (type1 == signed_char_type_node
  1750. || type1 == char_type_node
  1751. || type1 == unsigned_char_type_node)
  1752. return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  1753. if (type1 == integer_type_node || type1 == unsigned_type_node)
  1754. return unsignedp ? unsigned_type_node : integer_type_node;
  1755. if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
  1756. return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  1757. if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
  1758. return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  1759. if (type1 == long_long_integer_type_node
  1760. || type1 == long_long_unsigned_type_node)
  1761. return unsignedp
  1762. ? long_long_unsigned_type_node
  1763. : long_long_integer_type_node;
  1764. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  1765. if (int_n_enabled_p[i]
  1766. && (type1 == int_n_trees[i].unsigned_type
  1767. || type1 == int_n_trees[i].signed_type))
  1768. return unsignedp
  1769. ? int_n_trees[i].unsigned_type
  1770. : int_n_trees[i].signed_type;
  1771. #if HOST_BITS_PER_WIDE_INT >= 64
  1772. if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
  1773. return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
  1774. #endif
  1775. if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
  1776. return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
  1777. if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
  1778. return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
  1779. if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
  1780. return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
  1781. if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
  1782. return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
  1783. #define GIMPLE_FIXED_TYPES(NAME) \
  1784. if (type1 == short_ ## NAME ## _type_node \
  1785. || type1 == unsigned_short_ ## NAME ## _type_node) \
  1786. return unsignedp ? unsigned_short_ ## NAME ## _type_node \
  1787. : short_ ## NAME ## _type_node; \
  1788. if (type1 == NAME ## _type_node \
  1789. || type1 == unsigned_ ## NAME ## _type_node) \
  1790. return unsignedp ? unsigned_ ## NAME ## _type_node \
  1791. : NAME ## _type_node; \
  1792. if (type1 == long_ ## NAME ## _type_node \
  1793. || type1 == unsigned_long_ ## NAME ## _type_node) \
  1794. return unsignedp ? unsigned_long_ ## NAME ## _type_node \
  1795. : long_ ## NAME ## _type_node; \
  1796. if (type1 == long_long_ ## NAME ## _type_node \
  1797. || type1 == unsigned_long_long_ ## NAME ## _type_node) \
  1798. return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
  1799. : long_long_ ## NAME ## _type_node;
  1800. #define GIMPLE_FIXED_MODE_TYPES(NAME) \
  1801. if (type1 == NAME ## _type_node \
  1802. || type1 == u ## NAME ## _type_node) \
  1803. return unsignedp ? u ## NAME ## _type_node \
  1804. : NAME ## _type_node;
  1805. #define GIMPLE_FIXED_TYPES_SAT(NAME) \
  1806. if (type1 == sat_ ## short_ ## NAME ## _type_node \
  1807. || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
  1808. return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
  1809. : sat_ ## short_ ## NAME ## _type_node; \
  1810. if (type1 == sat_ ## NAME ## _type_node \
  1811. || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
  1812. return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
  1813. : sat_ ## NAME ## _type_node; \
  1814. if (type1 == sat_ ## long_ ## NAME ## _type_node \
  1815. || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
  1816. return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
  1817. : sat_ ## long_ ## NAME ## _type_node; \
  1818. if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
  1819. || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
  1820. return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
  1821. : sat_ ## long_long_ ## NAME ## _type_node;
  1822. #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
  1823. if (type1 == sat_ ## NAME ## _type_node \
  1824. || type1 == sat_ ## u ## NAME ## _type_node) \
  1825. return unsignedp ? sat_ ## u ## NAME ## _type_node \
  1826. : sat_ ## NAME ## _type_node;
  1827. GIMPLE_FIXED_TYPES (fract);
  1828. GIMPLE_FIXED_TYPES_SAT (fract);
  1829. GIMPLE_FIXED_TYPES (accum);
  1830. GIMPLE_FIXED_TYPES_SAT (accum);
  1831. GIMPLE_FIXED_MODE_TYPES (qq);
  1832. GIMPLE_FIXED_MODE_TYPES (hq);
  1833. GIMPLE_FIXED_MODE_TYPES (sq);
  1834. GIMPLE_FIXED_MODE_TYPES (dq);
  1835. GIMPLE_FIXED_MODE_TYPES (tq);
  1836. GIMPLE_FIXED_MODE_TYPES_SAT (qq);
  1837. GIMPLE_FIXED_MODE_TYPES_SAT (hq);
  1838. GIMPLE_FIXED_MODE_TYPES_SAT (sq);
  1839. GIMPLE_FIXED_MODE_TYPES_SAT (dq);
  1840. GIMPLE_FIXED_MODE_TYPES_SAT (tq);
  1841. GIMPLE_FIXED_MODE_TYPES (ha);
  1842. GIMPLE_FIXED_MODE_TYPES (sa);
  1843. GIMPLE_FIXED_MODE_TYPES (da);
  1844. GIMPLE_FIXED_MODE_TYPES (ta);
  1845. GIMPLE_FIXED_MODE_TYPES_SAT (ha);
  1846. GIMPLE_FIXED_MODE_TYPES_SAT (sa);
  1847. GIMPLE_FIXED_MODE_TYPES_SAT (da);
  1848. GIMPLE_FIXED_MODE_TYPES_SAT (ta);
  1849. /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
  1850. the precision; they have precision set to match their range, but
  1851. may use a wider mode to match an ABI. If we change modes, we may
  1852. wind up with bad conversions. For INTEGER_TYPEs in C, must check
  1853. the precision as well, so as to yield correct results for
  1854. bit-field types. C++ does not have these separate bit-field
  1855. types, and producing a signed or unsigned variant of an
  1856. ENUMERAL_TYPE may cause other problems as well. */
  1857. if (!INTEGRAL_TYPE_P (type)
  1858. || TYPE_UNSIGNED (type) == unsignedp)
  1859. return type;
  1860. #define TYPE_OK(node) \
  1861. (TYPE_MODE (type) == TYPE_MODE (node) \
  1862. && TYPE_PRECISION (type) == TYPE_PRECISION (node))
  1863. if (TYPE_OK (signed_char_type_node))
  1864. return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  1865. if (TYPE_OK (integer_type_node))
  1866. return unsignedp ? unsigned_type_node : integer_type_node;
  1867. if (TYPE_OK (short_integer_type_node))
  1868. return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  1869. if (TYPE_OK (long_integer_type_node))
  1870. return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  1871. if (TYPE_OK (long_long_integer_type_node))
  1872. return (unsignedp
  1873. ? long_long_unsigned_type_node
  1874. : long_long_integer_type_node);
  1875. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  1876. if (int_n_enabled_p[i]
  1877. && TYPE_MODE (type) == int_n_data[i].m
  1878. && TYPE_PRECISION (type) == int_n_data[i].bitsize)
  1879. return unsignedp
  1880. ? int_n_trees[i].unsigned_type
  1881. : int_n_trees[i].signed_type;
  1882. #if HOST_BITS_PER_WIDE_INT >= 64
  1883. if (TYPE_OK (intTI_type_node))
  1884. return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
  1885. #endif
  1886. if (TYPE_OK (intDI_type_node))
  1887. return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
  1888. if (TYPE_OK (intSI_type_node))
  1889. return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
  1890. if (TYPE_OK (intHI_type_node))
  1891. return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
  1892. if (TYPE_OK (intQI_type_node))
  1893. return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
  1894. #undef GIMPLE_FIXED_TYPES
  1895. #undef GIMPLE_FIXED_MODE_TYPES
  1896. #undef GIMPLE_FIXED_TYPES_SAT
  1897. #undef GIMPLE_FIXED_MODE_TYPES_SAT
  1898. #undef TYPE_OK
  1899. return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
  1900. }
  1901. /* Return an unsigned type the same as TYPE in other respects. */
  1902. tree
  1903. gimple_unsigned_type (tree type)
  1904. {
  1905. return gimple_signed_or_unsigned_type (true, type);
  1906. }
  1907. /* Return a signed type the same as TYPE in other respects. */
  1908. tree
  1909. gimple_signed_type (tree type)
  1910. {
  1911. return gimple_signed_or_unsigned_type (false, type);
  1912. }
  1913. /* Return the typed-based alias set for T, which may be an expression
  1914. or a type. Return -1 if we don't do anything special. */
  1915. alias_set_type
  1916. gimple_get_alias_set (tree t)
  1917. {
  1918. tree u;
  1919. /* Permit type-punning when accessing a union, provided the access
  1920. is directly through the union. For example, this code does not
  1921. permit taking the address of a union member and then storing
  1922. through it. Even the type-punning allowed here is a GCC
  1923. extension, albeit a common and useful one; the C standard says
  1924. that such accesses have implementation-defined behavior. */
  1925. for (u = t;
  1926. TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
  1927. u = TREE_OPERAND (u, 0))
  1928. if (TREE_CODE (u) == COMPONENT_REF
  1929. && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
  1930. return 0;
  1931. /* That's all the expressions we handle specially. */
  1932. if (!TYPE_P (t))
  1933. return -1;
  1934. /* For convenience, follow the C standard when dealing with
  1935. character types. Any object may be accessed via an lvalue that
  1936. has character type. */
  1937. if (t == char_type_node
  1938. || t == signed_char_type_node
  1939. || t == unsigned_char_type_node)
  1940. return 0;
  1941. /* Allow aliasing between signed and unsigned variants of the same
  1942. type. We treat the signed variant as canonical. */
  1943. if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
  1944. {
  1945. tree t1 = gimple_signed_type (t);
  1946. /* t1 == t can happen for boolean nodes which are always unsigned. */
  1947. if (t1 != t)
  1948. return get_alias_set (t1);
  1949. }
  1950. return -1;
  1951. }
  1952. /* Helper for gimple_ior_addresses_taken_1. */
  1953. static bool
  1954. gimple_ior_addresses_taken_1 (gimple, tree addr, tree, void *data)
  1955. {
  1956. bitmap addresses_taken = (bitmap)data;
  1957. addr = get_base_address (addr);
  1958. if (addr
  1959. && DECL_P (addr))
  1960. {
  1961. bitmap_set_bit (addresses_taken, DECL_UID (addr));
  1962. return true;
  1963. }
  1964. return false;
  1965. }
  1966. /* Set the bit for the uid of all decls that have their address taken
  1967. in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
  1968. were any in this stmt. */
  1969. bool
  1970. gimple_ior_addresses_taken (bitmap addresses_taken, gimple stmt)
  1971. {
  1972. return walk_stmt_load_store_addr_ops (stmt, addresses_taken, NULL, NULL,
  1973. gimple_ior_addresses_taken_1);
  1974. }
  1975. /* Return true if TYPE1 and TYPE2 are compatible enough for builtin
  1976. processing. */
  1977. static bool
  1978. validate_type (tree type1, tree type2)
  1979. {
  1980. if (INTEGRAL_TYPE_P (type1)
  1981. && INTEGRAL_TYPE_P (type2))
  1982. ;
  1983. else if (POINTER_TYPE_P (type1)
  1984. && POINTER_TYPE_P (type2))
  1985. ;
  1986. else if (TREE_CODE (type1)
  1987. != TREE_CODE (type2))
  1988. return false;
  1989. return true;
  1990. }
  1991. /* Return true when STMTs arguments and return value match those of FNDECL,
  1992. a decl of a builtin function. */
  1993. bool
  1994. gimple_builtin_call_types_compatible_p (const_gimple stmt, tree fndecl)
  1995. {
  1996. gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
  1997. tree ret = gimple_call_lhs (stmt);
  1998. if (ret
  1999. && !validate_type (TREE_TYPE (ret), TREE_TYPE (TREE_TYPE (fndecl))))
  2000. return false;
  2001. tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
  2002. unsigned nargs = gimple_call_num_args (stmt);
  2003. for (unsigned i = 0; i < nargs; ++i)
  2004. {
  2005. /* Variadic args follow. */
  2006. if (!targs)
  2007. return true;
  2008. tree arg = gimple_call_arg (stmt, i);
  2009. if (!validate_type (TREE_TYPE (arg), TREE_VALUE (targs)))
  2010. return false;
  2011. targs = TREE_CHAIN (targs);
  2012. }
  2013. if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
  2014. return false;
  2015. return true;
  2016. }
  2017. /* Return true when STMT is builtins call. */
  2018. bool
  2019. gimple_call_builtin_p (const_gimple stmt)
  2020. {
  2021. tree fndecl;
  2022. if (is_gimple_call (stmt)
  2023. && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
  2024. && DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN)
  2025. return gimple_builtin_call_types_compatible_p (stmt, fndecl);
  2026. return false;
  2027. }
  2028. /* Return true when STMT is builtins call to CLASS. */
  2029. bool
  2030. gimple_call_builtin_p (const_gimple stmt, enum built_in_class klass)
  2031. {
  2032. tree fndecl;
  2033. if (is_gimple_call (stmt)
  2034. && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
  2035. && DECL_BUILT_IN_CLASS (fndecl) == klass)
  2036. return gimple_builtin_call_types_compatible_p (stmt, fndecl);
  2037. return false;
  2038. }
  2039. /* Return true when STMT is builtins call to CODE of CLASS. */
  2040. bool
  2041. gimple_call_builtin_p (const_gimple stmt, enum built_in_function code)
  2042. {
  2043. tree fndecl;
  2044. if (is_gimple_call (stmt)
  2045. && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
  2046. && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
  2047. && DECL_FUNCTION_CODE (fndecl) == code)
  2048. return gimple_builtin_call_types_compatible_p (stmt, fndecl);
  2049. return false;
  2050. }
  2051. /* Return true if STMT clobbers memory. STMT is required to be a
  2052. GIMPLE_ASM. */
  2053. bool
  2054. gimple_asm_clobbers_memory_p (const gasm *stmt)
  2055. {
  2056. unsigned i;
  2057. for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
  2058. {
  2059. tree op = gimple_asm_clobber_op (stmt, i);
  2060. if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op)), "memory") == 0)
  2061. return true;
  2062. }
  2063. return false;
  2064. }
  2065. /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
  2066. void
  2067. dump_decl_set (FILE *file, bitmap set)
  2068. {
  2069. if (set)
  2070. {
  2071. bitmap_iterator bi;
  2072. unsigned i;
  2073. fprintf (file, "{ ");
  2074. EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
  2075. {
  2076. fprintf (file, "D.%u", i);
  2077. fprintf (file, " ");
  2078. }
  2079. fprintf (file, "}");
  2080. }
  2081. else
  2082. fprintf (file, "NIL");
  2083. }
  2084. /* Return true when CALL is a call stmt that definitely doesn't
  2085. free any memory or makes it unavailable otherwise. */
  2086. bool
  2087. nonfreeing_call_p (gimple call)
  2088. {
  2089. if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
  2090. && gimple_call_flags (call) & ECF_LEAF)
  2091. switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
  2092. {
  2093. /* Just in case these become ECF_LEAF in the future. */
  2094. case BUILT_IN_FREE:
  2095. case BUILT_IN_TM_FREE:
  2096. case BUILT_IN_REALLOC:
  2097. case BUILT_IN_STACK_RESTORE:
  2098. return false;
  2099. default:
  2100. return true;
  2101. }
  2102. else if (gimple_call_internal_p (call))
  2103. switch (gimple_call_internal_fn (call))
  2104. {
  2105. case IFN_ABNORMAL_DISPATCHER:
  2106. return true;
  2107. default:
  2108. if (gimple_call_flags (call) & ECF_LEAF)
  2109. return true;
  2110. return false;
  2111. }
  2112. tree fndecl = gimple_call_fndecl (call);
  2113. if (!fndecl)
  2114. return false;
  2115. struct cgraph_node *n = cgraph_node::get (fndecl);
  2116. if (!n)
  2117. return false;
  2118. enum availability availability;
  2119. n = n->function_symbol (&availability);
  2120. if (!n || availability <= AVAIL_INTERPOSABLE)
  2121. return false;
  2122. return n->nonfreeing_fn;
  2123. }
  2124. /* Callback for walk_stmt_load_store_ops.
  2125. Return TRUE if OP will dereference the tree stored in DATA, FALSE
  2126. otherwise.
  2127. This routine only makes a superficial check for a dereference. Thus
  2128. it must only be used if it is safe to return a false negative. */
  2129. static bool
  2130. check_loadstore (gimple, tree op, tree, void *data)
  2131. {
  2132. if ((TREE_CODE (op) == MEM_REF || TREE_CODE (op) == TARGET_MEM_REF)
  2133. && operand_equal_p (TREE_OPERAND (op, 0), (tree)data, 0))
  2134. return true;
  2135. return false;
  2136. }
  2137. /* If OP can be inferred to be non-NULL after STMT executes, return true.
  2138. DEREFERENCE is TRUE if we can use a pointer dereference to infer a
  2139. non-NULL range, FALSE otherwise.
  2140. ATTRIBUTE is TRUE if we can use attributes to infer a non-NULL range
  2141. for function arguments and return values. FALSE otherwise. */
  2142. bool
  2143. infer_nonnull_range (gimple stmt, tree op, bool dereference, bool attribute)
  2144. {
  2145. /* We can only assume that a pointer dereference will yield
  2146. non-NULL if -fdelete-null-pointer-checks is enabled. */
  2147. if (!flag_delete_null_pointer_checks
  2148. || !POINTER_TYPE_P (TREE_TYPE (op))
  2149. || gimple_code (stmt) == GIMPLE_ASM)
  2150. return false;
  2151. if (dereference
  2152. && walk_stmt_load_store_ops (stmt, (void *)op,
  2153. check_loadstore, check_loadstore))
  2154. return true;
  2155. if (attribute
  2156. && is_gimple_call (stmt) && !gimple_call_internal_p (stmt))
  2157. {
  2158. tree fntype = gimple_call_fntype (stmt);
  2159. tree attrs = TYPE_ATTRIBUTES (fntype);
  2160. for (; attrs; attrs = TREE_CHAIN (attrs))
  2161. {
  2162. attrs = lookup_attribute ("nonnull", attrs);
  2163. /* If "nonnull" wasn't specified, we know nothing about
  2164. the argument. */
  2165. if (attrs == NULL_TREE)
  2166. return false;
  2167. /* If "nonnull" applies to all the arguments, then ARG
  2168. is non-null if it's in the argument list. */
  2169. if (TREE_VALUE (attrs) == NULL_TREE)
  2170. {
  2171. for (unsigned int i = 0; i < gimple_call_num_args (stmt); i++)
  2172. {
  2173. if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt, i)))
  2174. && operand_equal_p (op, gimple_call_arg (stmt, i), 0))
  2175. return true;
  2176. }
  2177. return false;
  2178. }
  2179. /* Now see if op appears in the nonnull list. */
  2180. for (tree t = TREE_VALUE (attrs); t; t = TREE_CHAIN (t))
  2181. {
  2182. int idx = TREE_INT_CST_LOW (TREE_VALUE (t)) - 1;
  2183. tree arg = gimple_call_arg (stmt, idx);
  2184. if (operand_equal_p (op, arg, 0))
  2185. return true;
  2186. }
  2187. }
  2188. }
  2189. /* If this function is marked as returning non-null, then we can
  2190. infer OP is non-null if it is used in the return statement. */
  2191. if (attribute)
  2192. if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
  2193. if (gimple_return_retval (return_stmt)
  2194. && operand_equal_p (gimple_return_retval (return_stmt), op, 0)
  2195. && lookup_attribute ("returns_nonnull",
  2196. TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
  2197. return true;
  2198. return false;
  2199. }
  2200. /* Compare two case labels. Because the front end should already have
  2201. made sure that case ranges do not overlap, it is enough to only compare
  2202. the CASE_LOW values of each case label. */
  2203. static int
  2204. compare_case_labels (const void *p1, const void *p2)
  2205. {
  2206. const_tree const case1 = *(const_tree const*)p1;
  2207. const_tree const case2 = *(const_tree const*)p2;
  2208. /* The 'default' case label always goes first. */
  2209. if (!CASE_LOW (case1))
  2210. return -1;
  2211. else if (!CASE_LOW (case2))
  2212. return 1;
  2213. else
  2214. return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
  2215. }
  2216. /* Sort the case labels in LABEL_VEC in place in ascending order. */
  2217. void
  2218. sort_case_labels (vec<tree> label_vec)
  2219. {
  2220. label_vec.qsort (compare_case_labels);
  2221. }
  2222. /* Prepare a vector of case labels to be used in a GIMPLE_SWITCH statement.
  2223. LABELS is a vector that contains all case labels to look at.
  2224. INDEX_TYPE is the type of the switch index expression. Case labels
  2225. in LABELS are discarded if their values are not in the value range
  2226. covered by INDEX_TYPE. The remaining case label values are folded
  2227. to INDEX_TYPE.
  2228. If a default case exists in LABELS, it is removed from LABELS and
  2229. returned in DEFAULT_CASEP. If no default case exists, but the
  2230. case labels already cover the whole range of INDEX_TYPE, a default
  2231. case is returned pointing to one of the existing case labels.
  2232. Otherwise DEFAULT_CASEP is set to NULL_TREE.
  2233. DEFAULT_CASEP may be NULL, in which case the above comment doesn't
  2234. apply and no action is taken regardless of whether a default case is
  2235. found or not. */
  2236. void
  2237. preprocess_case_label_vec_for_gimple (vec<tree> labels,
  2238. tree index_type,
  2239. tree *default_casep)
  2240. {
  2241. tree min_value, max_value;
  2242. tree default_case = NULL_TREE;
  2243. size_t i, len;
  2244. i = 0;
  2245. min_value = TYPE_MIN_VALUE (index_type);
  2246. max_value = TYPE_MAX_VALUE (index_type);
  2247. while (i < labels.length ())
  2248. {
  2249. tree elt = labels[i];
  2250. tree low = CASE_LOW (elt);
  2251. tree high = CASE_HIGH (elt);
  2252. bool remove_element = FALSE;
  2253. if (low)
  2254. {
  2255. gcc_checking_assert (TREE_CODE (low) == INTEGER_CST);
  2256. gcc_checking_assert (!high || TREE_CODE (high) == INTEGER_CST);
  2257. /* This is a non-default case label, i.e. it has a value.
  2258. See if the case label is reachable within the range of
  2259. the index type. Remove out-of-range case values. Turn
  2260. case ranges into a canonical form (high > low strictly)
  2261. and convert the case label values to the index type.
  2262. NB: The type of gimple_switch_index() may be the promoted
  2263. type, but the case labels retain the original type. */
  2264. if (high)
  2265. {
  2266. /* This is a case range. Discard empty ranges.
  2267. If the bounds or the range are equal, turn this
  2268. into a simple (one-value) case. */
  2269. int cmp = tree_int_cst_compare (high, low);
  2270. if (cmp < 0)
  2271. remove_element = TRUE;
  2272. else if (cmp == 0)
  2273. high = NULL_TREE;
  2274. }
  2275. if (! high)
  2276. {
  2277. /* If the simple case value is unreachable, ignore it. */
  2278. if ((TREE_CODE (min_value) == INTEGER_CST
  2279. && tree_int_cst_compare (low, min_value) < 0)
  2280. || (TREE_CODE (max_value) == INTEGER_CST
  2281. && tree_int_cst_compare (low, max_value) > 0))
  2282. remove_element = TRUE;
  2283. else
  2284. low = fold_convert (index_type, low);
  2285. }
  2286. else
  2287. {
  2288. /* If the entire case range is unreachable, ignore it. */
  2289. if ((TREE_CODE (min_value) == INTEGER_CST
  2290. && tree_int_cst_compare (high, min_value) < 0)
  2291. || (TREE_CODE (max_value) == INTEGER_CST
  2292. && tree_int_cst_compare (low, max_value) > 0))
  2293. remove_element = TRUE;
  2294. else
  2295. {
  2296. /* If the lower bound is less than the index type's
  2297. minimum value, truncate the range bounds. */
  2298. if (TREE_CODE (min_value) == INTEGER_CST
  2299. && tree_int_cst_compare (low, min_value) < 0)
  2300. low = min_value;
  2301. low = fold_convert (index_type, low);
  2302. /* If the upper bound is greater than the index type's
  2303. maximum value, truncate the range bounds. */
  2304. if (TREE_CODE (max_value) == INTEGER_CST
  2305. && tree_int_cst_compare (high, max_value) > 0)
  2306. high = max_value;
  2307. high = fold_convert (index_type, high);
  2308. /* We may have folded a case range to a one-value case. */
  2309. if (tree_int_cst_equal (low, high))
  2310. high = NULL_TREE;
  2311. }
  2312. }
  2313. CASE_LOW (elt) = low;
  2314. CASE_HIGH (elt) = high;
  2315. }
  2316. else
  2317. {
  2318. gcc_assert (!default_case);
  2319. default_case = elt;
  2320. /* The default case must be passed separately to the
  2321. gimple_build_switch routine. But if DEFAULT_CASEP
  2322. is NULL, we do not remove the default case (it would
  2323. be completely lost). */
  2324. if (default_casep)
  2325. remove_element = TRUE;
  2326. }
  2327. if (remove_element)
  2328. labels.ordered_remove (i);
  2329. else
  2330. i++;
  2331. }
  2332. len = i;
  2333. if (!labels.is_empty ())
  2334. sort_case_labels (labels);
  2335. if (default_casep && !default_case)
  2336. {
  2337. /* If the switch has no default label, add one, so that we jump
  2338. around the switch body. If the labels already cover the whole
  2339. range of the switch index_type, add the default label pointing
  2340. to one of the existing labels. */
  2341. if (len
  2342. && TYPE_MIN_VALUE (index_type)
  2343. && TYPE_MAX_VALUE (index_type)
  2344. && tree_int_cst_equal (CASE_LOW (labels[0]),
  2345. TYPE_MIN_VALUE (index_type)))
  2346. {
  2347. tree low, high = CASE_HIGH (labels[len - 1]);
  2348. if (!high)
  2349. high = CASE_LOW (labels[len - 1]);
  2350. if (tree_int_cst_equal (high, TYPE_MAX_VALUE (index_type)))
  2351. {
  2352. for (i = 1; i < len; i++)
  2353. {
  2354. high = CASE_LOW (labels[i]);
  2355. low = CASE_HIGH (labels[i - 1]);
  2356. if (!low)
  2357. low = CASE_LOW (labels[i - 1]);
  2358. if (wi::add (low, 1) != high)
  2359. break;
  2360. }
  2361. if (i == len)
  2362. {
  2363. tree label = CASE_LABEL (labels[0]);
  2364. default_case = build_case_label (NULL_TREE, NULL_TREE,
  2365. label);
  2366. }
  2367. }
  2368. }
  2369. }
  2370. if (default_casep)
  2371. *default_casep = default_case;
  2372. }
  2373. /* Set the location of all statements in SEQ to LOC. */
  2374. void
  2375. gimple_seq_set_location (gimple_seq seq, location_t loc)
  2376. {
  2377. for (gimple_stmt_iterator i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
  2378. gimple_set_location (gsi_stmt (i), loc);
  2379. }
  2380. /* Release SSA_NAMEs in SEQ as well as the GIMPLE statements. */
  2381. void
  2382. gimple_seq_discard (gimple_seq seq)
  2383. {
  2384. gimple_stmt_iterator gsi;
  2385. for (gsi = gsi_start (seq); !gsi_end_p (gsi); )
  2386. {
  2387. gimple stmt = gsi_stmt (gsi);
  2388. gsi_remove (&gsi, true);
  2389. release_defs (stmt);
  2390. ggc_free (stmt);
  2391. }
  2392. }
  2393. /* See if STMT now calls function that takes no parameters and if so, drop
  2394. call arguments. This is used when devirtualization machinery redirects
  2395. to __builtiln_unreacahble or __cxa_pure_virutal. */
  2396. void
  2397. maybe_remove_unused_call_args (struct function *fn, gimple stmt)
  2398. {
  2399. tree decl = gimple_call_fndecl (stmt);
  2400. if (TYPE_ARG_TYPES (TREE_TYPE (decl))
  2401. && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))) == void_type_node
  2402. && gimple_call_num_args (stmt))
  2403. {
  2404. gimple_set_num_ops (stmt, 3);
  2405. update_stmt_fn (fn, stmt);
  2406. }
  2407. }