final.c 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918
  1. /* Convert RTL to assembler code and output it, for GNU compiler.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This is the final pass of the compiler.
  16. It looks at the rtl code for a function and outputs assembler code.
  17. Call `final_start_function' to output the assembler code for function entry,
  18. `final' to output assembler code for some RTL code,
  19. `final_end_function' to output assembler code for function exit.
  20. If a function is compiled in several pieces, each piece is
  21. output separately with `final'.
  22. Some optimizations are also done at this level.
  23. Move instructions that were made unnecessary by good register allocation
  24. are detected and omitted from the output. (Though most of these
  25. are removed by the last jump pass.)
  26. Instructions to set the condition codes are omitted when it can be
  27. seen that the condition codes already had the desired values.
  28. In some cases it is sufficient if the inherited condition codes
  29. have related values, but this may require the following insn
  30. (the one that tests the condition codes) to be modified.
  31. The code for the function prologue and epilogue are generated
  32. directly in assembler by the target functions function_prologue and
  33. function_epilogue. Those instructions never exist as rtl. */
  34. #include "config.h"
  35. #include "system.h"
  36. #include "coretypes.h"
  37. #include "tm.h"
  38. #include "hash-set.h"
  39. #include "machmode.h"
  40. #include "vec.h"
  41. #include "double-int.h"
  42. #include "input.h"
  43. #include "alias.h"
  44. #include "symtab.h"
  45. #include "wide-int.h"
  46. #include "inchash.h"
  47. #include "tree.h"
  48. #include "varasm.h"
  49. #include "hard-reg-set.h"
  50. #include "rtl.h"
  51. #include "tm_p.h"
  52. #include "regs.h"
  53. #include "insn-config.h"
  54. #include "insn-attr.h"
  55. #include "recog.h"
  56. #include "conditions.h"
  57. #include "flags.h"
  58. #include "output.h"
  59. #include "except.h"
  60. #include "function.h"
  61. #include "rtl-error.h"
  62. #include "toplev.h" /* exact_log2, floor_log2 */
  63. #include "reload.h"
  64. #include "intl.h"
  65. #include "predict.h"
  66. #include "dominance.h"
  67. #include "cfg.h"
  68. #include "cfgrtl.h"
  69. #include "basic-block.h"
  70. #include "target.h"
  71. #include "targhooks.h"
  72. #include "debug.h"
  73. #include "hashtab.h"
  74. #include "statistics.h"
  75. #include "real.h"
  76. #include "fixed-value.h"
  77. #include "expmed.h"
  78. #include "dojump.h"
  79. #include "explow.h"
  80. #include "calls.h"
  81. #include "emit-rtl.h"
  82. #include "stmt.h"
  83. #include "expr.h"
  84. #include "tree-pass.h"
  85. #include "hash-map.h"
  86. #include "is-a.h"
  87. #include "plugin-api.h"
  88. #include "ipa-ref.h"
  89. #include "cgraph.h"
  90. #include "tree-ssa.h"
  91. #include "coverage.h"
  92. #include "df.h"
  93. #include "ggc.h"
  94. #include "cfgloop.h"
  95. #include "params.h"
  96. #include "tree-pretty-print.h" /* for dump_function_header */
  97. #include "asan.h"
  98. #include "wide-int-print.h"
  99. #include "rtl-iter.h"
  100. #ifdef XCOFF_DEBUGGING_INFO
  101. #include "xcoffout.h" /* Needed for external data
  102. declarations for e.g. AIX 4.x. */
  103. #endif
  104. #include "dwarf2out.h"
  105. #ifdef DBX_DEBUGGING_INFO
  106. #include "dbxout.h"
  107. #endif
  108. #ifdef SDB_DEBUGGING_INFO
  109. #include "sdbout.h"
  110. #endif
  111. /* Most ports that aren't using cc0 don't need to define CC_STATUS_INIT.
  112. So define a null default for it to save conditionalization later. */
  113. #ifndef CC_STATUS_INIT
  114. #define CC_STATUS_INIT
  115. #endif
  116. /* Is the given character a logical line separator for the assembler? */
  117. #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
  118. #define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == ';')
  119. #endif
  120. #ifndef JUMP_TABLES_IN_TEXT_SECTION
  121. #define JUMP_TABLES_IN_TEXT_SECTION 0
  122. #endif
  123. /* Bitflags used by final_scan_insn. */
  124. #define SEEN_NOTE 1
  125. #define SEEN_EMITTED 2
  126. /* Last insn processed by final_scan_insn. */
  127. static rtx_insn *debug_insn;
  128. rtx_insn *current_output_insn;
  129. /* Line number of last NOTE. */
  130. static int last_linenum;
  131. /* Last discriminator written to assembly. */
  132. static int last_discriminator;
  133. /* Discriminator of current block. */
  134. static int discriminator;
  135. /* Highest line number in current block. */
  136. static int high_block_linenum;
  137. /* Likewise for function. */
  138. static int high_function_linenum;
  139. /* Filename of last NOTE. */
  140. static const char *last_filename;
  141. /* Override filename and line number. */
  142. static const char *override_filename;
  143. static int override_linenum;
  144. /* Whether to force emission of a line note before the next insn. */
  145. static bool force_source_line = false;
  146. extern const int length_unit_log; /* This is defined in insn-attrtab.c. */
  147. /* Nonzero while outputting an `asm' with operands.
  148. This means that inconsistencies are the user's fault, so don't die.
  149. The precise value is the insn being output, to pass to error_for_asm. */
  150. const rtx_insn *this_is_asm_operands;
  151. /* Number of operands of this insn, for an `asm' with operands. */
  152. static unsigned int insn_noperands;
  153. /* Compare optimization flag. */
  154. static rtx last_ignored_compare = 0;
  155. /* Assign a unique number to each insn that is output.
  156. This can be used to generate unique local labels. */
  157. static int insn_counter = 0;
  158. #ifdef HAVE_cc0
  159. /* This variable contains machine-dependent flags (defined in tm.h)
  160. set and examined by output routines
  161. that describe how to interpret the condition codes properly. */
  162. CC_STATUS cc_status;
  163. /* During output of an insn, this contains a copy of cc_status
  164. from before the insn. */
  165. CC_STATUS cc_prev_status;
  166. #endif
  167. /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
  168. static int block_depth;
  169. /* Nonzero if have enabled APP processing of our assembler output. */
  170. static int app_on;
  171. /* If we are outputting an insn sequence, this contains the sequence rtx.
  172. Zero otherwise. */
  173. rtx_sequence *final_sequence;
  174. #ifdef ASSEMBLER_DIALECT
  175. /* Number of the assembler dialect to use, starting at 0. */
  176. static int dialect_number;
  177. #endif
  178. /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
  179. rtx current_insn_predicate;
  180. /* True if printing into -fdump-final-insns= dump. */
  181. bool final_insns_dump_p;
  182. /* True if profile_function should be called, but hasn't been called yet. */
  183. static bool need_profile_function;
  184. static int asm_insn_count (rtx);
  185. static void profile_function (FILE *);
  186. static void profile_after_prologue (FILE *);
  187. static bool notice_source_line (rtx_insn *, bool *);
  188. static rtx walk_alter_subreg (rtx *, bool *);
  189. static void output_asm_name (void);
  190. static void output_alternate_entry_point (FILE *, rtx_insn *);
  191. static tree get_mem_expr_from_op (rtx, int *);
  192. static void output_asm_operand_names (rtx *, int *, int);
  193. #ifdef LEAF_REGISTERS
  194. static void leaf_renumber_regs (rtx_insn *);
  195. #endif
  196. #ifdef HAVE_cc0
  197. static int alter_cond (rtx);
  198. #endif
  199. #ifndef ADDR_VEC_ALIGN
  200. static int final_addr_vec_align (rtx);
  201. #endif
  202. static int align_fuzz (rtx, rtx, int, unsigned);
  203. static void collect_fn_hard_reg_usage (void);
  204. static tree get_call_fndecl (rtx_insn *);
  205. /* Initialize data in final at the beginning of a compilation. */
  206. void
  207. init_final (const char *filename ATTRIBUTE_UNUSED)
  208. {
  209. app_on = 0;
  210. final_sequence = 0;
  211. #ifdef ASSEMBLER_DIALECT
  212. dialect_number = ASSEMBLER_DIALECT;
  213. #endif
  214. }
  215. /* Default target function prologue and epilogue assembler output.
  216. If not overridden for epilogue code, then the function body itself
  217. contains return instructions wherever needed. */
  218. void
  219. default_function_pro_epilogue (FILE *file ATTRIBUTE_UNUSED,
  220. HOST_WIDE_INT size ATTRIBUTE_UNUSED)
  221. {
  222. }
  223. void
  224. default_function_switched_text_sections (FILE *file ATTRIBUTE_UNUSED,
  225. tree decl ATTRIBUTE_UNUSED,
  226. bool new_is_cold ATTRIBUTE_UNUSED)
  227. {
  228. }
  229. /* Default target hook that outputs nothing to a stream. */
  230. void
  231. no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
  232. {
  233. }
  234. /* Enable APP processing of subsequent output.
  235. Used before the output from an `asm' statement. */
  236. void
  237. app_enable (void)
  238. {
  239. if (! app_on)
  240. {
  241. fputs (ASM_APP_ON, asm_out_file);
  242. app_on = 1;
  243. }
  244. }
  245. /* Disable APP processing of subsequent output.
  246. Called from varasm.c before most kinds of output. */
  247. void
  248. app_disable (void)
  249. {
  250. if (app_on)
  251. {
  252. fputs (ASM_APP_OFF, asm_out_file);
  253. app_on = 0;
  254. }
  255. }
  256. /* Return the number of slots filled in the current
  257. delayed branch sequence (we don't count the insn needing the
  258. delay slot). Zero if not in a delayed branch sequence. */
  259. #ifdef DELAY_SLOTS
  260. int
  261. dbr_sequence_length (void)
  262. {
  263. if (final_sequence != 0)
  264. return XVECLEN (final_sequence, 0) - 1;
  265. else
  266. return 0;
  267. }
  268. #endif
  269. /* The next two pages contain routines used to compute the length of an insn
  270. and to shorten branches. */
  271. /* Arrays for insn lengths, and addresses. The latter is referenced by
  272. `insn_current_length'. */
  273. static int *insn_lengths;
  274. vec<int> insn_addresses_;
  275. /* Max uid for which the above arrays are valid. */
  276. static int insn_lengths_max_uid;
  277. /* Address of insn being processed. Used by `insn_current_length'. */
  278. int insn_current_address;
  279. /* Address of insn being processed in previous iteration. */
  280. int insn_last_address;
  281. /* known invariant alignment of insn being processed. */
  282. int insn_current_align;
  283. /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
  284. gives the next following alignment insn that increases the known
  285. alignment, or NULL_RTX if there is no such insn.
  286. For any alignment obtained this way, we can again index uid_align with
  287. its uid to obtain the next following align that in turn increases the
  288. alignment, till we reach NULL_RTX; the sequence obtained this way
  289. for each insn we'll call the alignment chain of this insn in the following
  290. comments. */
  291. struct label_alignment
  292. {
  293. short alignment;
  294. short max_skip;
  295. };
  296. static rtx *uid_align;
  297. static int *uid_shuid;
  298. static struct label_alignment *label_align;
  299. /* Indicate that branch shortening hasn't yet been done. */
  300. void
  301. init_insn_lengths (void)
  302. {
  303. if (uid_shuid)
  304. {
  305. free (uid_shuid);
  306. uid_shuid = 0;
  307. }
  308. if (insn_lengths)
  309. {
  310. free (insn_lengths);
  311. insn_lengths = 0;
  312. insn_lengths_max_uid = 0;
  313. }
  314. if (HAVE_ATTR_length)
  315. INSN_ADDRESSES_FREE ();
  316. if (uid_align)
  317. {
  318. free (uid_align);
  319. uid_align = 0;
  320. }
  321. }
  322. /* Obtain the current length of an insn. If branch shortening has been done,
  323. get its actual length. Otherwise, use FALLBACK_FN to calculate the
  324. length. */
  325. static int
  326. get_attr_length_1 (rtx_insn *insn, int (*fallback_fn) (rtx_insn *))
  327. {
  328. rtx body;
  329. int i;
  330. int length = 0;
  331. if (!HAVE_ATTR_length)
  332. return 0;
  333. if (insn_lengths_max_uid > INSN_UID (insn))
  334. return insn_lengths[INSN_UID (insn)];
  335. else
  336. switch (GET_CODE (insn))
  337. {
  338. case NOTE:
  339. case BARRIER:
  340. case CODE_LABEL:
  341. case DEBUG_INSN:
  342. return 0;
  343. case CALL_INSN:
  344. case JUMP_INSN:
  345. length = fallback_fn (insn);
  346. break;
  347. case INSN:
  348. body = PATTERN (insn);
  349. if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
  350. return 0;
  351. else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
  352. length = asm_insn_count (body) * fallback_fn (insn);
  353. else if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (body))
  354. for (i = 0; i < seq->len (); i++)
  355. length += get_attr_length_1 (seq->insn (i), fallback_fn);
  356. else
  357. length = fallback_fn (insn);
  358. break;
  359. default:
  360. break;
  361. }
  362. #ifdef ADJUST_INSN_LENGTH
  363. ADJUST_INSN_LENGTH (insn, length);
  364. #endif
  365. return length;
  366. }
  367. /* Obtain the current length of an insn. If branch shortening has been done,
  368. get its actual length. Otherwise, get its maximum length. */
  369. int
  370. get_attr_length (rtx_insn *insn)
  371. {
  372. return get_attr_length_1 (insn, insn_default_length);
  373. }
  374. /* Obtain the current length of an insn. If branch shortening has been done,
  375. get its actual length. Otherwise, get its minimum length. */
  376. int
  377. get_attr_min_length (rtx_insn *insn)
  378. {
  379. return get_attr_length_1 (insn, insn_min_length);
  380. }
  381. /* Code to handle alignment inside shorten_branches. */
  382. /* Here is an explanation how the algorithm in align_fuzz can give
  383. proper results:
  384. Call a sequence of instructions beginning with alignment point X
  385. and continuing until the next alignment point `block X'. When `X'
  386. is used in an expression, it means the alignment value of the
  387. alignment point.
  388. Call the distance between the start of the first insn of block X, and
  389. the end of the last insn of block X `IX', for the `inner size of X'.
  390. This is clearly the sum of the instruction lengths.
  391. Likewise with the next alignment-delimited block following X, which we
  392. shall call block Y.
  393. Call the distance between the start of the first insn of block X, and
  394. the start of the first insn of block Y `OX', for the `outer size of X'.
  395. The estimated padding is then OX - IX.
  396. OX can be safely estimated as
  397. if (X >= Y)
  398. OX = round_up(IX, Y)
  399. else
  400. OX = round_up(IX, X) + Y - X
  401. Clearly est(IX) >= real(IX), because that only depends on the
  402. instruction lengths, and those being overestimated is a given.
  403. Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
  404. we needn't worry about that when thinking about OX.
  405. When X >= Y, the alignment provided by Y adds no uncertainty factor
  406. for branch ranges starting before X, so we can just round what we have.
  407. But when X < Y, we don't know anything about the, so to speak,
  408. `middle bits', so we have to assume the worst when aligning up from an
  409. address mod X to one mod Y, which is Y - X. */
  410. #ifndef LABEL_ALIGN
  411. #define LABEL_ALIGN(LABEL) align_labels_log
  412. #endif
  413. #ifndef LOOP_ALIGN
  414. #define LOOP_ALIGN(LABEL) align_loops_log
  415. #endif
  416. #ifndef LABEL_ALIGN_AFTER_BARRIER
  417. #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
  418. #endif
  419. #ifndef JUMP_ALIGN
  420. #define JUMP_ALIGN(LABEL) align_jumps_log
  421. #endif
  422. int
  423. default_label_align_after_barrier_max_skip (rtx_insn *insn ATTRIBUTE_UNUSED)
  424. {
  425. return 0;
  426. }
  427. int
  428. default_loop_align_max_skip (rtx_insn *insn ATTRIBUTE_UNUSED)
  429. {
  430. return align_loops_max_skip;
  431. }
  432. int
  433. default_label_align_max_skip (rtx_insn *insn ATTRIBUTE_UNUSED)
  434. {
  435. return align_labels_max_skip;
  436. }
  437. int
  438. default_jump_align_max_skip (rtx_insn *insn ATTRIBUTE_UNUSED)
  439. {
  440. return align_jumps_max_skip;
  441. }
  442. #ifndef ADDR_VEC_ALIGN
  443. static int
  444. final_addr_vec_align (rtx addr_vec)
  445. {
  446. int align = GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec)));
  447. if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  448. align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  449. return exact_log2 (align);
  450. }
  451. #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
  452. #endif
  453. #ifndef INSN_LENGTH_ALIGNMENT
  454. #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
  455. #endif
  456. #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
  457. static int min_labelno, max_labelno;
  458. #define LABEL_TO_ALIGNMENT(LABEL) \
  459. (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
  460. #define LABEL_TO_MAX_SKIP(LABEL) \
  461. (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
  462. /* For the benefit of port specific code do this also as a function. */
  463. int
  464. label_to_alignment (rtx label)
  465. {
  466. if (CODE_LABEL_NUMBER (label) <= max_labelno)
  467. return LABEL_TO_ALIGNMENT (label);
  468. return 0;
  469. }
  470. int
  471. label_to_max_skip (rtx label)
  472. {
  473. if (CODE_LABEL_NUMBER (label) <= max_labelno)
  474. return LABEL_TO_MAX_SKIP (label);
  475. return 0;
  476. }
  477. /* The differences in addresses
  478. between a branch and its target might grow or shrink depending on
  479. the alignment the start insn of the range (the branch for a forward
  480. branch or the label for a backward branch) starts out on; if these
  481. differences are used naively, they can even oscillate infinitely.
  482. We therefore want to compute a 'worst case' address difference that
  483. is independent of the alignment the start insn of the range end
  484. up on, and that is at least as large as the actual difference.
  485. The function align_fuzz calculates the amount we have to add to the
  486. naively computed difference, by traversing the part of the alignment
  487. chain of the start insn of the range that is in front of the end insn
  488. of the range, and considering for each alignment the maximum amount
  489. that it might contribute to a size increase.
  490. For casesi tables, we also want to know worst case minimum amounts of
  491. address difference, in case a machine description wants to introduce
  492. some common offset that is added to all offsets in a table.
  493. For this purpose, align_fuzz with a growth argument of 0 computes the
  494. appropriate adjustment. */
  495. /* Compute the maximum delta by which the difference of the addresses of
  496. START and END might grow / shrink due to a different address for start
  497. which changes the size of alignment insns between START and END.
  498. KNOWN_ALIGN_LOG is the alignment known for START.
  499. GROWTH should be ~0 if the objective is to compute potential code size
  500. increase, and 0 if the objective is to compute potential shrink.
  501. The return value is undefined for any other value of GROWTH. */
  502. static int
  503. align_fuzz (rtx start, rtx end, int known_align_log, unsigned int growth)
  504. {
  505. int uid = INSN_UID (start);
  506. rtx align_label;
  507. int known_align = 1 << known_align_log;
  508. int end_shuid = INSN_SHUID (end);
  509. int fuzz = 0;
  510. for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
  511. {
  512. int align_addr, new_align;
  513. uid = INSN_UID (align_label);
  514. align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
  515. if (uid_shuid[uid] > end_shuid)
  516. break;
  517. known_align_log = LABEL_TO_ALIGNMENT (align_label);
  518. new_align = 1 << known_align_log;
  519. if (new_align < known_align)
  520. continue;
  521. fuzz += (-align_addr ^ growth) & (new_align - known_align);
  522. known_align = new_align;
  523. }
  524. return fuzz;
  525. }
  526. /* Compute a worst-case reference address of a branch so that it
  527. can be safely used in the presence of aligned labels. Since the
  528. size of the branch itself is unknown, the size of the branch is
  529. not included in the range. I.e. for a forward branch, the reference
  530. address is the end address of the branch as known from the previous
  531. branch shortening pass, minus a value to account for possible size
  532. increase due to alignment. For a backward branch, it is the start
  533. address of the branch as known from the current pass, plus a value
  534. to account for possible size increase due to alignment.
  535. NB.: Therefore, the maximum offset allowed for backward branches needs
  536. to exclude the branch size. */
  537. int
  538. insn_current_reference_address (rtx_insn *branch)
  539. {
  540. rtx dest, seq;
  541. int seq_uid;
  542. if (! INSN_ADDRESSES_SET_P ())
  543. return 0;
  544. seq = NEXT_INSN (PREV_INSN (branch));
  545. seq_uid = INSN_UID (seq);
  546. if (!JUMP_P (branch))
  547. /* This can happen for example on the PA; the objective is to know the
  548. offset to address something in front of the start of the function.
  549. Thus, we can treat it like a backward branch.
  550. We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
  551. any alignment we'd encounter, so we skip the call to align_fuzz. */
  552. return insn_current_address;
  553. dest = JUMP_LABEL (branch);
  554. /* BRANCH has no proper alignment chain set, so use SEQ.
  555. BRANCH also has no INSN_SHUID. */
  556. if (INSN_SHUID (seq) < INSN_SHUID (dest))
  557. {
  558. /* Forward branch. */
  559. return (insn_last_address + insn_lengths[seq_uid]
  560. - align_fuzz (seq, dest, length_unit_log, ~0));
  561. }
  562. else
  563. {
  564. /* Backward branch. */
  565. return (insn_current_address
  566. + align_fuzz (dest, seq, length_unit_log, ~0));
  567. }
  568. }
  569. /* Compute branch alignments based on frequency information in the
  570. CFG. */
  571. unsigned int
  572. compute_alignments (void)
  573. {
  574. int log, max_skip, max_log;
  575. basic_block bb;
  576. int freq_max = 0;
  577. int freq_threshold = 0;
  578. if (label_align)
  579. {
  580. free (label_align);
  581. label_align = 0;
  582. }
  583. max_labelno = max_label_num ();
  584. min_labelno = get_first_label_num ();
  585. label_align = XCNEWVEC (struct label_alignment, max_labelno - min_labelno + 1);
  586. /* If not optimizing or optimizing for size, don't assign any alignments. */
  587. if (! optimize || optimize_function_for_size_p (cfun))
  588. return 0;
  589. if (dump_file)
  590. {
  591. dump_reg_info (dump_file);
  592. dump_flow_info (dump_file, TDF_DETAILS);
  593. flow_loops_dump (dump_file, NULL, 1);
  594. }
  595. loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
  596. FOR_EACH_BB_FN (bb, cfun)
  597. if (bb->frequency > freq_max)
  598. freq_max = bb->frequency;
  599. freq_threshold = freq_max / PARAM_VALUE (PARAM_ALIGN_THRESHOLD);
  600. if (dump_file)
  601. fprintf (dump_file, "freq_max: %i\n",freq_max);
  602. FOR_EACH_BB_FN (bb, cfun)
  603. {
  604. rtx_insn *label = BB_HEAD (bb);
  605. int fallthru_frequency = 0, branch_frequency = 0, has_fallthru = 0;
  606. edge e;
  607. edge_iterator ei;
  608. if (!LABEL_P (label)
  609. || optimize_bb_for_size_p (bb))
  610. {
  611. if (dump_file)
  612. fprintf (dump_file,
  613. "BB %4i freq %4i loop %2i loop_depth %2i skipped.\n",
  614. bb->index, bb->frequency, bb->loop_father->num,
  615. bb_loop_depth (bb));
  616. continue;
  617. }
  618. max_log = LABEL_ALIGN (label);
  619. max_skip = targetm.asm_out.label_align_max_skip (label);
  620. FOR_EACH_EDGE (e, ei, bb->preds)
  621. {
  622. if (e->flags & EDGE_FALLTHRU)
  623. has_fallthru = 1, fallthru_frequency += EDGE_FREQUENCY (e);
  624. else
  625. branch_frequency += EDGE_FREQUENCY (e);
  626. }
  627. if (dump_file)
  628. {
  629. fprintf (dump_file, "BB %4i freq %4i loop %2i loop_depth"
  630. " %2i fall %4i branch %4i",
  631. bb->index, bb->frequency, bb->loop_father->num,
  632. bb_loop_depth (bb),
  633. fallthru_frequency, branch_frequency);
  634. if (!bb->loop_father->inner && bb->loop_father->num)
  635. fprintf (dump_file, " inner_loop");
  636. if (bb->loop_father->header == bb)
  637. fprintf (dump_file, " loop_header");
  638. fprintf (dump_file, "\n");
  639. }
  640. /* There are two purposes to align block with no fallthru incoming edge:
  641. 1) to avoid fetch stalls when branch destination is near cache boundary
  642. 2) to improve cache efficiency in case the previous block is not executed
  643. (so it does not need to be in the cache).
  644. We to catch first case, we align frequently executed blocks.
  645. To catch the second, we align blocks that are executed more frequently
  646. than the predecessor and the predecessor is likely to not be executed
  647. when function is called. */
  648. if (!has_fallthru
  649. && (branch_frequency > freq_threshold
  650. || (bb->frequency > bb->prev_bb->frequency * 10
  651. && (bb->prev_bb->frequency
  652. <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency / 2))))
  653. {
  654. log = JUMP_ALIGN (label);
  655. if (dump_file)
  656. fprintf (dump_file, " jump alignment added.\n");
  657. if (max_log < log)
  658. {
  659. max_log = log;
  660. max_skip = targetm.asm_out.jump_align_max_skip (label);
  661. }
  662. }
  663. /* In case block is frequent and reached mostly by non-fallthru edge,
  664. align it. It is most likely a first block of loop. */
  665. if (has_fallthru
  666. && !(single_succ_p (bb)
  667. && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun))
  668. && optimize_bb_for_speed_p (bb)
  669. && branch_frequency + fallthru_frequency > freq_threshold
  670. && (branch_frequency
  671. > fallthru_frequency * PARAM_VALUE (PARAM_ALIGN_LOOP_ITERATIONS)))
  672. {
  673. log = LOOP_ALIGN (label);
  674. if (dump_file)
  675. fprintf (dump_file, " internal loop alignment added.\n");
  676. if (max_log < log)
  677. {
  678. max_log = log;
  679. max_skip = targetm.asm_out.loop_align_max_skip (label);
  680. }
  681. }
  682. LABEL_TO_ALIGNMENT (label) = max_log;
  683. LABEL_TO_MAX_SKIP (label) = max_skip;
  684. }
  685. loop_optimizer_finalize ();
  686. free_dominance_info (CDI_DOMINATORS);
  687. return 0;
  688. }
  689. /* Grow the LABEL_ALIGN array after new labels are created. */
  690. static void
  691. grow_label_align (void)
  692. {
  693. int old = max_labelno;
  694. int n_labels;
  695. int n_old_labels;
  696. max_labelno = max_label_num ();
  697. n_labels = max_labelno - min_labelno + 1;
  698. n_old_labels = old - min_labelno + 1;
  699. label_align = XRESIZEVEC (struct label_alignment, label_align, n_labels);
  700. /* Range of labels grows monotonically in the function. Failing here
  701. means that the initialization of array got lost. */
  702. gcc_assert (n_old_labels <= n_labels);
  703. memset (label_align + n_old_labels, 0,
  704. (n_labels - n_old_labels) * sizeof (struct label_alignment));
  705. }
  706. /* Update the already computed alignment information. LABEL_PAIRS is a vector
  707. made up of pairs of labels for which the alignment information of the first
  708. element will be copied from that of the second element. */
  709. void
  710. update_alignments (vec<rtx> &label_pairs)
  711. {
  712. unsigned int i = 0;
  713. rtx iter, label = NULL_RTX;
  714. if (max_labelno != max_label_num ())
  715. grow_label_align ();
  716. FOR_EACH_VEC_ELT (label_pairs, i, iter)
  717. if (i & 1)
  718. {
  719. LABEL_TO_ALIGNMENT (label) = LABEL_TO_ALIGNMENT (iter);
  720. LABEL_TO_MAX_SKIP (label) = LABEL_TO_MAX_SKIP (iter);
  721. }
  722. else
  723. label = iter;
  724. }
  725. namespace {
  726. const pass_data pass_data_compute_alignments =
  727. {
  728. RTL_PASS, /* type */
  729. "alignments", /* name */
  730. OPTGROUP_NONE, /* optinfo_flags */
  731. TV_NONE, /* tv_id */
  732. 0, /* properties_required */
  733. 0, /* properties_provided */
  734. 0, /* properties_destroyed */
  735. 0, /* todo_flags_start */
  736. 0, /* todo_flags_finish */
  737. };
  738. class pass_compute_alignments : public rtl_opt_pass
  739. {
  740. public:
  741. pass_compute_alignments (gcc::context *ctxt)
  742. : rtl_opt_pass (pass_data_compute_alignments, ctxt)
  743. {}
  744. /* opt_pass methods: */
  745. virtual unsigned int execute (function *) { return compute_alignments (); }
  746. }; // class pass_compute_alignments
  747. } // anon namespace
  748. rtl_opt_pass *
  749. make_pass_compute_alignments (gcc::context *ctxt)
  750. {
  751. return new pass_compute_alignments (ctxt);
  752. }
  753. /* Make a pass over all insns and compute their actual lengths by shortening
  754. any branches of variable length if possible. */
  755. /* shorten_branches might be called multiple times: for example, the SH
  756. port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
  757. In order to do this, it needs proper length information, which it obtains
  758. by calling shorten_branches. This cannot be collapsed with
  759. shorten_branches itself into a single pass unless we also want to integrate
  760. reorg.c, since the branch splitting exposes new instructions with delay
  761. slots. */
  762. void
  763. shorten_branches (rtx_insn *first)
  764. {
  765. rtx_insn *insn;
  766. int max_uid;
  767. int i;
  768. int max_log;
  769. int max_skip;
  770. #define MAX_CODE_ALIGN 16
  771. rtx_insn *seq;
  772. int something_changed = 1;
  773. char *varying_length;
  774. rtx body;
  775. int uid;
  776. rtx align_tab[MAX_CODE_ALIGN];
  777. /* Compute maximum UID and allocate label_align / uid_shuid. */
  778. max_uid = get_max_uid ();
  779. /* Free uid_shuid before reallocating it. */
  780. free (uid_shuid);
  781. uid_shuid = XNEWVEC (int, max_uid);
  782. if (max_labelno != max_label_num ())
  783. grow_label_align ();
  784. /* Initialize label_align and set up uid_shuid to be strictly
  785. monotonically rising with insn order. */
  786. /* We use max_log here to keep track of the maximum alignment we want to
  787. impose on the next CODE_LABEL (or the current one if we are processing
  788. the CODE_LABEL itself). */
  789. max_log = 0;
  790. max_skip = 0;
  791. for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
  792. {
  793. int log;
  794. INSN_SHUID (insn) = i++;
  795. if (INSN_P (insn))
  796. continue;
  797. if (LABEL_P (insn))
  798. {
  799. rtx_insn *next;
  800. bool next_is_jumptable;
  801. /* Merge in alignments computed by compute_alignments. */
  802. log = LABEL_TO_ALIGNMENT (insn);
  803. if (max_log < log)
  804. {
  805. max_log = log;
  806. max_skip = LABEL_TO_MAX_SKIP (insn);
  807. }
  808. next = next_nonnote_insn (insn);
  809. next_is_jumptable = next && JUMP_TABLE_DATA_P (next);
  810. if (!next_is_jumptable)
  811. {
  812. log = LABEL_ALIGN (insn);
  813. if (max_log < log)
  814. {
  815. max_log = log;
  816. max_skip = targetm.asm_out.label_align_max_skip (insn);
  817. }
  818. }
  819. /* ADDR_VECs only take room if read-only data goes into the text
  820. section. */
  821. if ((JUMP_TABLES_IN_TEXT_SECTION
  822. || readonly_data_section == text_section)
  823. && next_is_jumptable)
  824. {
  825. log = ADDR_VEC_ALIGN (next);
  826. if (max_log < log)
  827. {
  828. max_log = log;
  829. max_skip = targetm.asm_out.label_align_max_skip (insn);
  830. }
  831. }
  832. LABEL_TO_ALIGNMENT (insn) = max_log;
  833. LABEL_TO_MAX_SKIP (insn) = max_skip;
  834. max_log = 0;
  835. max_skip = 0;
  836. }
  837. else if (BARRIER_P (insn))
  838. {
  839. rtx_insn *label;
  840. for (label = insn; label && ! INSN_P (label);
  841. label = NEXT_INSN (label))
  842. if (LABEL_P (label))
  843. {
  844. log = LABEL_ALIGN_AFTER_BARRIER (insn);
  845. if (max_log < log)
  846. {
  847. max_log = log;
  848. max_skip = targetm.asm_out.label_align_after_barrier_max_skip (label);
  849. }
  850. break;
  851. }
  852. }
  853. }
  854. if (!HAVE_ATTR_length)
  855. return;
  856. /* Allocate the rest of the arrays. */
  857. insn_lengths = XNEWVEC (int, max_uid);
  858. insn_lengths_max_uid = max_uid;
  859. /* Syntax errors can lead to labels being outside of the main insn stream.
  860. Initialize insn_addresses, so that we get reproducible results. */
  861. INSN_ADDRESSES_ALLOC (max_uid);
  862. varying_length = XCNEWVEC (char, max_uid);
  863. /* Initialize uid_align. We scan instructions
  864. from end to start, and keep in align_tab[n] the last seen insn
  865. that does an alignment of at least n+1, i.e. the successor
  866. in the alignment chain for an insn that does / has a known
  867. alignment of n. */
  868. uid_align = XCNEWVEC (rtx, max_uid);
  869. for (i = MAX_CODE_ALIGN; --i >= 0;)
  870. align_tab[i] = NULL_RTX;
  871. seq = get_last_insn ();
  872. for (; seq; seq = PREV_INSN (seq))
  873. {
  874. int uid = INSN_UID (seq);
  875. int log;
  876. log = (LABEL_P (seq) ? LABEL_TO_ALIGNMENT (seq) : 0);
  877. uid_align[uid] = align_tab[0];
  878. if (log)
  879. {
  880. /* Found an alignment label. */
  881. uid_align[uid] = align_tab[log];
  882. for (i = log - 1; i >= 0; i--)
  883. align_tab[i] = seq;
  884. }
  885. }
  886. /* When optimizing, we start assuming minimum length, and keep increasing
  887. lengths as we find the need for this, till nothing changes.
  888. When not optimizing, we start assuming maximum lengths, and
  889. do a single pass to update the lengths. */
  890. bool increasing = optimize != 0;
  891. #ifdef CASE_VECTOR_SHORTEN_MODE
  892. if (optimize)
  893. {
  894. /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
  895. label fields. */
  896. int min_shuid = INSN_SHUID (get_insns ()) - 1;
  897. int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
  898. int rel;
  899. for (insn = first; insn != 0; insn = NEXT_INSN (insn))
  900. {
  901. rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
  902. int len, i, min, max, insn_shuid;
  903. int min_align;
  904. addr_diff_vec_flags flags;
  905. if (! JUMP_TABLE_DATA_P (insn)
  906. || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
  907. continue;
  908. pat = PATTERN (insn);
  909. len = XVECLEN (pat, 1);
  910. gcc_assert (len > 0);
  911. min_align = MAX_CODE_ALIGN;
  912. for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
  913. {
  914. rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
  915. int shuid = INSN_SHUID (lab);
  916. if (shuid < min)
  917. {
  918. min = shuid;
  919. min_lab = lab;
  920. }
  921. if (shuid > max)
  922. {
  923. max = shuid;
  924. max_lab = lab;
  925. }
  926. if (min_align > LABEL_TO_ALIGNMENT (lab))
  927. min_align = LABEL_TO_ALIGNMENT (lab);
  928. }
  929. XEXP (pat, 2) = gen_rtx_LABEL_REF (Pmode, min_lab);
  930. XEXP (pat, 3) = gen_rtx_LABEL_REF (Pmode, max_lab);
  931. insn_shuid = INSN_SHUID (insn);
  932. rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
  933. memset (&flags, 0, sizeof (flags));
  934. flags.min_align = min_align;
  935. flags.base_after_vec = rel > insn_shuid;
  936. flags.min_after_vec = min > insn_shuid;
  937. flags.max_after_vec = max > insn_shuid;
  938. flags.min_after_base = min > rel;
  939. flags.max_after_base = max > rel;
  940. ADDR_DIFF_VEC_FLAGS (pat) = flags;
  941. if (increasing)
  942. PUT_MODE (pat, CASE_VECTOR_SHORTEN_MODE (0, 0, pat));
  943. }
  944. }
  945. #endif /* CASE_VECTOR_SHORTEN_MODE */
  946. /* Compute initial lengths, addresses, and varying flags for each insn. */
  947. int (*length_fun) (rtx_insn *) = increasing ? insn_min_length : insn_default_length;
  948. for (insn_current_address = 0, insn = first;
  949. insn != 0;
  950. insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
  951. {
  952. uid = INSN_UID (insn);
  953. insn_lengths[uid] = 0;
  954. if (LABEL_P (insn))
  955. {
  956. int log = LABEL_TO_ALIGNMENT (insn);
  957. if (log)
  958. {
  959. int align = 1 << log;
  960. int new_address = (insn_current_address + align - 1) & -align;
  961. insn_lengths[uid] = new_address - insn_current_address;
  962. }
  963. }
  964. INSN_ADDRESSES (uid) = insn_current_address + insn_lengths[uid];
  965. if (NOTE_P (insn) || BARRIER_P (insn)
  966. || LABEL_P (insn) || DEBUG_INSN_P (insn))
  967. continue;
  968. if (insn->deleted ())
  969. continue;
  970. body = PATTERN (insn);
  971. if (JUMP_TABLE_DATA_P (insn))
  972. {
  973. /* This only takes room if read-only data goes into the text
  974. section. */
  975. if (JUMP_TABLES_IN_TEXT_SECTION
  976. || readonly_data_section == text_section)
  977. insn_lengths[uid] = (XVECLEN (body,
  978. GET_CODE (body) == ADDR_DIFF_VEC)
  979. * GET_MODE_SIZE (GET_MODE (body)));
  980. /* Alignment is handled by ADDR_VEC_ALIGN. */
  981. }
  982. else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
  983. insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
  984. else if (rtx_sequence *body_seq = dyn_cast <rtx_sequence *> (body))
  985. {
  986. int i;
  987. int const_delay_slots;
  988. #ifdef DELAY_SLOTS
  989. const_delay_slots = const_num_delay_slots (body_seq->insn (0));
  990. #else
  991. const_delay_slots = 0;
  992. #endif
  993. int (*inner_length_fun) (rtx_insn *)
  994. = const_delay_slots ? length_fun : insn_default_length;
  995. /* Inside a delay slot sequence, we do not do any branch shortening
  996. if the shortening could change the number of delay slots
  997. of the branch. */
  998. for (i = 0; i < body_seq->len (); i++)
  999. {
  1000. rtx_insn *inner_insn = body_seq->insn (i);
  1001. int inner_uid = INSN_UID (inner_insn);
  1002. int inner_length;
  1003. if (GET_CODE (body) == ASM_INPUT
  1004. || asm_noperands (PATTERN (inner_insn)) >= 0)
  1005. inner_length = (asm_insn_count (PATTERN (inner_insn))
  1006. * insn_default_length (inner_insn));
  1007. else
  1008. inner_length = inner_length_fun (inner_insn);
  1009. insn_lengths[inner_uid] = inner_length;
  1010. if (const_delay_slots)
  1011. {
  1012. if ((varying_length[inner_uid]
  1013. = insn_variable_length_p (inner_insn)) != 0)
  1014. varying_length[uid] = 1;
  1015. INSN_ADDRESSES (inner_uid) = (insn_current_address
  1016. + insn_lengths[uid]);
  1017. }
  1018. else
  1019. varying_length[inner_uid] = 0;
  1020. insn_lengths[uid] += inner_length;
  1021. }
  1022. }
  1023. else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
  1024. {
  1025. insn_lengths[uid] = length_fun (insn);
  1026. varying_length[uid] = insn_variable_length_p (insn);
  1027. }
  1028. /* If needed, do any adjustment. */
  1029. #ifdef ADJUST_INSN_LENGTH
  1030. ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
  1031. if (insn_lengths[uid] < 0)
  1032. fatal_insn ("negative insn length", insn);
  1033. #endif
  1034. }
  1035. /* Now loop over all the insns finding varying length insns. For each,
  1036. get the current insn length. If it has changed, reflect the change.
  1037. When nothing changes for a full pass, we are done. */
  1038. while (something_changed)
  1039. {
  1040. something_changed = 0;
  1041. insn_current_align = MAX_CODE_ALIGN - 1;
  1042. for (insn_current_address = 0, insn = first;
  1043. insn != 0;
  1044. insn = NEXT_INSN (insn))
  1045. {
  1046. int new_length;
  1047. #ifdef ADJUST_INSN_LENGTH
  1048. int tmp_length;
  1049. #endif
  1050. int length_align;
  1051. uid = INSN_UID (insn);
  1052. if (LABEL_P (insn))
  1053. {
  1054. int log = LABEL_TO_ALIGNMENT (insn);
  1055. #ifdef CASE_VECTOR_SHORTEN_MODE
  1056. /* If the mode of a following jump table was changed, we
  1057. may need to update the alignment of this label. */
  1058. rtx_insn *next;
  1059. bool next_is_jumptable;
  1060. next = next_nonnote_insn (insn);
  1061. next_is_jumptable = next && JUMP_TABLE_DATA_P (next);
  1062. if ((JUMP_TABLES_IN_TEXT_SECTION
  1063. || readonly_data_section == text_section)
  1064. && next_is_jumptable)
  1065. {
  1066. int newlog = ADDR_VEC_ALIGN (next);
  1067. if (newlog != log)
  1068. {
  1069. log = newlog;
  1070. LABEL_TO_ALIGNMENT (insn) = log;
  1071. something_changed = 1;
  1072. }
  1073. }
  1074. #endif
  1075. if (log > insn_current_align)
  1076. {
  1077. int align = 1 << log;
  1078. int new_address= (insn_current_address + align - 1) & -align;
  1079. insn_lengths[uid] = new_address - insn_current_address;
  1080. insn_current_align = log;
  1081. insn_current_address = new_address;
  1082. }
  1083. else
  1084. insn_lengths[uid] = 0;
  1085. INSN_ADDRESSES (uid) = insn_current_address;
  1086. continue;
  1087. }
  1088. length_align = INSN_LENGTH_ALIGNMENT (insn);
  1089. if (length_align < insn_current_align)
  1090. insn_current_align = length_align;
  1091. insn_last_address = INSN_ADDRESSES (uid);
  1092. INSN_ADDRESSES (uid) = insn_current_address;
  1093. #ifdef CASE_VECTOR_SHORTEN_MODE
  1094. if (optimize
  1095. && JUMP_TABLE_DATA_P (insn)
  1096. && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
  1097. {
  1098. rtx body = PATTERN (insn);
  1099. int old_length = insn_lengths[uid];
  1100. rtx_insn *rel_lab =
  1101. safe_as_a <rtx_insn *> (XEXP (XEXP (body, 0), 0));
  1102. rtx min_lab = XEXP (XEXP (body, 2), 0);
  1103. rtx max_lab = XEXP (XEXP (body, 3), 0);
  1104. int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
  1105. int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
  1106. int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
  1107. rtx_insn *prev;
  1108. int rel_align = 0;
  1109. addr_diff_vec_flags flags;
  1110. machine_mode vec_mode;
  1111. /* Avoid automatic aggregate initialization. */
  1112. flags = ADDR_DIFF_VEC_FLAGS (body);
  1113. /* Try to find a known alignment for rel_lab. */
  1114. for (prev = rel_lab;
  1115. prev
  1116. && ! insn_lengths[INSN_UID (prev)]
  1117. && ! (varying_length[INSN_UID (prev)] & 1);
  1118. prev = PREV_INSN (prev))
  1119. if (varying_length[INSN_UID (prev)] & 2)
  1120. {
  1121. rel_align = LABEL_TO_ALIGNMENT (prev);
  1122. break;
  1123. }
  1124. /* See the comment on addr_diff_vec_flags in rtl.h for the
  1125. meaning of the flags values. base: REL_LAB vec: INSN */
  1126. /* Anything after INSN has still addresses from the last
  1127. pass; adjust these so that they reflect our current
  1128. estimate for this pass. */
  1129. if (flags.base_after_vec)
  1130. rel_addr += insn_current_address - insn_last_address;
  1131. if (flags.min_after_vec)
  1132. min_addr += insn_current_address - insn_last_address;
  1133. if (flags.max_after_vec)
  1134. max_addr += insn_current_address - insn_last_address;
  1135. /* We want to know the worst case, i.e. lowest possible value
  1136. for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
  1137. its offset is positive, and we have to be wary of code shrink;
  1138. otherwise, it is negative, and we have to be vary of code
  1139. size increase. */
  1140. if (flags.min_after_base)
  1141. {
  1142. /* If INSN is between REL_LAB and MIN_LAB, the size
  1143. changes we are about to make can change the alignment
  1144. within the observed offset, therefore we have to break
  1145. it up into two parts that are independent. */
  1146. if (! flags.base_after_vec && flags.min_after_vec)
  1147. {
  1148. min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
  1149. min_addr -= align_fuzz (insn, min_lab, 0, 0);
  1150. }
  1151. else
  1152. min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
  1153. }
  1154. else
  1155. {
  1156. if (flags.base_after_vec && ! flags.min_after_vec)
  1157. {
  1158. min_addr -= align_fuzz (min_lab, insn, 0, ~0);
  1159. min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
  1160. }
  1161. else
  1162. min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
  1163. }
  1164. /* Likewise, determine the highest lowest possible value
  1165. for the offset of MAX_LAB. */
  1166. if (flags.max_after_base)
  1167. {
  1168. if (! flags.base_after_vec && flags.max_after_vec)
  1169. {
  1170. max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
  1171. max_addr += align_fuzz (insn, max_lab, 0, ~0);
  1172. }
  1173. else
  1174. max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
  1175. }
  1176. else
  1177. {
  1178. if (flags.base_after_vec && ! flags.max_after_vec)
  1179. {
  1180. max_addr += align_fuzz (max_lab, insn, 0, 0);
  1181. max_addr += align_fuzz (insn, rel_lab, 0, 0);
  1182. }
  1183. else
  1184. max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
  1185. }
  1186. vec_mode = CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
  1187. max_addr - rel_addr, body);
  1188. if (!increasing
  1189. || (GET_MODE_SIZE (vec_mode)
  1190. >= GET_MODE_SIZE (GET_MODE (body))))
  1191. PUT_MODE (body, vec_mode);
  1192. if (JUMP_TABLES_IN_TEXT_SECTION
  1193. || readonly_data_section == text_section)
  1194. {
  1195. insn_lengths[uid]
  1196. = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
  1197. insn_current_address += insn_lengths[uid];
  1198. if (insn_lengths[uid] != old_length)
  1199. something_changed = 1;
  1200. }
  1201. continue;
  1202. }
  1203. #endif /* CASE_VECTOR_SHORTEN_MODE */
  1204. if (! (varying_length[uid]))
  1205. {
  1206. if (NONJUMP_INSN_P (insn)
  1207. && GET_CODE (PATTERN (insn)) == SEQUENCE)
  1208. {
  1209. int i;
  1210. body = PATTERN (insn);
  1211. for (i = 0; i < XVECLEN (body, 0); i++)
  1212. {
  1213. rtx inner_insn = XVECEXP (body, 0, i);
  1214. int inner_uid = INSN_UID (inner_insn);
  1215. INSN_ADDRESSES (inner_uid) = insn_current_address;
  1216. insn_current_address += insn_lengths[inner_uid];
  1217. }
  1218. }
  1219. else
  1220. insn_current_address += insn_lengths[uid];
  1221. continue;
  1222. }
  1223. if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
  1224. {
  1225. rtx_sequence *seqn = as_a <rtx_sequence *> (PATTERN (insn));
  1226. int i;
  1227. body = PATTERN (insn);
  1228. new_length = 0;
  1229. for (i = 0; i < seqn->len (); i++)
  1230. {
  1231. rtx_insn *inner_insn = seqn->insn (i);
  1232. int inner_uid = INSN_UID (inner_insn);
  1233. int inner_length;
  1234. INSN_ADDRESSES (inner_uid) = insn_current_address;
  1235. /* insn_current_length returns 0 for insns with a
  1236. non-varying length. */
  1237. if (! varying_length[inner_uid])
  1238. inner_length = insn_lengths[inner_uid];
  1239. else
  1240. inner_length = insn_current_length (inner_insn);
  1241. if (inner_length != insn_lengths[inner_uid])
  1242. {
  1243. if (!increasing || inner_length > insn_lengths[inner_uid])
  1244. {
  1245. insn_lengths[inner_uid] = inner_length;
  1246. something_changed = 1;
  1247. }
  1248. else
  1249. inner_length = insn_lengths[inner_uid];
  1250. }
  1251. insn_current_address += inner_length;
  1252. new_length += inner_length;
  1253. }
  1254. }
  1255. else
  1256. {
  1257. new_length = insn_current_length (insn);
  1258. insn_current_address += new_length;
  1259. }
  1260. #ifdef ADJUST_INSN_LENGTH
  1261. /* If needed, do any adjustment. */
  1262. tmp_length = new_length;
  1263. ADJUST_INSN_LENGTH (insn, new_length);
  1264. insn_current_address += (new_length - tmp_length);
  1265. #endif
  1266. if (new_length != insn_lengths[uid]
  1267. && (!increasing || new_length > insn_lengths[uid]))
  1268. {
  1269. insn_lengths[uid] = new_length;
  1270. something_changed = 1;
  1271. }
  1272. else
  1273. insn_current_address += insn_lengths[uid] - new_length;
  1274. }
  1275. /* For a non-optimizing compile, do only a single pass. */
  1276. if (!increasing)
  1277. break;
  1278. }
  1279. free (varying_length);
  1280. }
  1281. /* Given the body of an INSN known to be generated by an ASM statement, return
  1282. the number of machine instructions likely to be generated for this insn.
  1283. This is used to compute its length. */
  1284. static int
  1285. asm_insn_count (rtx body)
  1286. {
  1287. const char *templ;
  1288. if (GET_CODE (body) == ASM_INPUT)
  1289. templ = XSTR (body, 0);
  1290. else
  1291. templ = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
  1292. return asm_str_count (templ);
  1293. }
  1294. /* Return the number of machine instructions likely to be generated for the
  1295. inline-asm template. */
  1296. int
  1297. asm_str_count (const char *templ)
  1298. {
  1299. int count = 1;
  1300. if (!*templ)
  1301. return 0;
  1302. for (; *templ; templ++)
  1303. if (IS_ASM_LOGICAL_LINE_SEPARATOR (*templ, templ)
  1304. || *templ == '\n')
  1305. count++;
  1306. return count;
  1307. }
  1308. /* ??? This is probably the wrong place for these. */
  1309. /* Structure recording the mapping from source file and directory
  1310. names at compile time to those to be embedded in debug
  1311. information. */
  1312. typedef struct debug_prefix_map
  1313. {
  1314. const char *old_prefix;
  1315. const char *new_prefix;
  1316. size_t old_len;
  1317. size_t new_len;
  1318. struct debug_prefix_map *next;
  1319. } debug_prefix_map;
  1320. /* Linked list of such structures. */
  1321. static debug_prefix_map *debug_prefix_maps;
  1322. /* Record a debug file prefix mapping. ARG is the argument to
  1323. -fdebug-prefix-map and must be of the form OLD=NEW. */
  1324. void
  1325. add_debug_prefix_map (const char *arg)
  1326. {
  1327. debug_prefix_map *map;
  1328. const char *p;
  1329. p = strchr (arg, '=');
  1330. if (!p)
  1331. {
  1332. error ("invalid argument %qs to -fdebug-prefix-map", arg);
  1333. return;
  1334. }
  1335. map = XNEW (debug_prefix_map);
  1336. map->old_prefix = xstrndup (arg, p - arg);
  1337. map->old_len = p - arg;
  1338. p++;
  1339. map->new_prefix = xstrdup (p);
  1340. map->new_len = strlen (p);
  1341. map->next = debug_prefix_maps;
  1342. debug_prefix_maps = map;
  1343. }
  1344. /* Perform user-specified mapping of debug filename prefixes. Return
  1345. the new name corresponding to FILENAME. */
  1346. const char *
  1347. remap_debug_filename (const char *filename)
  1348. {
  1349. debug_prefix_map *map;
  1350. char *s;
  1351. const char *name;
  1352. size_t name_len;
  1353. for (map = debug_prefix_maps; map; map = map->next)
  1354. if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
  1355. break;
  1356. if (!map)
  1357. return filename;
  1358. name = filename + map->old_len;
  1359. name_len = strlen (name) + 1;
  1360. s = (char *) alloca (name_len + map->new_len);
  1361. memcpy (s, map->new_prefix, map->new_len);
  1362. memcpy (s + map->new_len, name, name_len);
  1363. return ggc_strdup (s);
  1364. }
  1365. /* Return true if DWARF2 debug info can be emitted for DECL. */
  1366. static bool
  1367. dwarf2_debug_info_emitted_p (tree decl)
  1368. {
  1369. if (write_symbols != DWARF2_DEBUG && write_symbols != VMS_AND_DWARF2_DEBUG)
  1370. return false;
  1371. if (DECL_IGNORED_P (decl))
  1372. return false;
  1373. return true;
  1374. }
  1375. /* Return scope resulting from combination of S1 and S2. */
  1376. static tree
  1377. choose_inner_scope (tree s1, tree s2)
  1378. {
  1379. if (!s1)
  1380. return s2;
  1381. if (!s2)
  1382. return s1;
  1383. if (BLOCK_NUMBER (s1) > BLOCK_NUMBER (s2))
  1384. return s1;
  1385. return s2;
  1386. }
  1387. /* Emit lexical block notes needed to change scope from S1 to S2. */
  1388. static void
  1389. change_scope (rtx_insn *orig_insn, tree s1, tree s2)
  1390. {
  1391. rtx_insn *insn = orig_insn;
  1392. tree com = NULL_TREE;
  1393. tree ts1 = s1, ts2 = s2;
  1394. tree s;
  1395. while (ts1 != ts2)
  1396. {
  1397. gcc_assert (ts1 && ts2);
  1398. if (BLOCK_NUMBER (ts1) > BLOCK_NUMBER (ts2))
  1399. ts1 = BLOCK_SUPERCONTEXT (ts1);
  1400. else if (BLOCK_NUMBER (ts1) < BLOCK_NUMBER (ts2))
  1401. ts2 = BLOCK_SUPERCONTEXT (ts2);
  1402. else
  1403. {
  1404. ts1 = BLOCK_SUPERCONTEXT (ts1);
  1405. ts2 = BLOCK_SUPERCONTEXT (ts2);
  1406. }
  1407. }
  1408. com = ts1;
  1409. /* Close scopes. */
  1410. s = s1;
  1411. while (s != com)
  1412. {
  1413. rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
  1414. NOTE_BLOCK (note) = s;
  1415. s = BLOCK_SUPERCONTEXT (s);
  1416. }
  1417. /* Open scopes. */
  1418. s = s2;
  1419. while (s != com)
  1420. {
  1421. insn = emit_note_before (NOTE_INSN_BLOCK_BEG, insn);
  1422. NOTE_BLOCK (insn) = s;
  1423. s = BLOCK_SUPERCONTEXT (s);
  1424. }
  1425. }
  1426. /* Rebuild all the NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes based
  1427. on the scope tree and the newly reordered instructions. */
  1428. static void
  1429. reemit_insn_block_notes (void)
  1430. {
  1431. tree cur_block = DECL_INITIAL (cfun->decl);
  1432. rtx_insn *insn;
  1433. rtx_note *note;
  1434. insn = get_insns ();
  1435. for (; insn; insn = NEXT_INSN (insn))
  1436. {
  1437. tree this_block;
  1438. /* Prevent lexical blocks from straddling section boundaries. */
  1439. if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
  1440. {
  1441. for (tree s = cur_block; s != DECL_INITIAL (cfun->decl);
  1442. s = BLOCK_SUPERCONTEXT (s))
  1443. {
  1444. rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
  1445. NOTE_BLOCK (note) = s;
  1446. note = emit_note_after (NOTE_INSN_BLOCK_BEG, insn);
  1447. NOTE_BLOCK (note) = s;
  1448. }
  1449. }
  1450. if (!active_insn_p (insn))
  1451. continue;
  1452. /* Avoid putting scope notes between jump table and its label. */
  1453. if (JUMP_TABLE_DATA_P (insn))
  1454. continue;
  1455. this_block = insn_scope (insn);
  1456. /* For sequences compute scope resulting from merging all scopes
  1457. of instructions nested inside. */
  1458. if (rtx_sequence *body = dyn_cast <rtx_sequence *> (PATTERN (insn)))
  1459. {
  1460. int i;
  1461. this_block = NULL;
  1462. for (i = 0; i < body->len (); i++)
  1463. this_block = choose_inner_scope (this_block,
  1464. insn_scope (body->insn (i)));
  1465. }
  1466. if (! this_block)
  1467. {
  1468. if (INSN_LOCATION (insn) == UNKNOWN_LOCATION)
  1469. continue;
  1470. else
  1471. this_block = DECL_INITIAL (cfun->decl);
  1472. }
  1473. if (this_block != cur_block)
  1474. {
  1475. change_scope (insn, cur_block, this_block);
  1476. cur_block = this_block;
  1477. }
  1478. }
  1479. /* change_scope emits before the insn, not after. */
  1480. note = emit_note (NOTE_INSN_DELETED);
  1481. change_scope (note, cur_block, DECL_INITIAL (cfun->decl));
  1482. delete_insn (note);
  1483. reorder_blocks ();
  1484. }
  1485. static const char *some_local_dynamic_name;
  1486. /* Locate some local-dynamic symbol still in use by this function
  1487. so that we can print its name in local-dynamic base patterns.
  1488. Return null if there are no local-dynamic references. */
  1489. const char *
  1490. get_some_local_dynamic_name ()
  1491. {
  1492. subrtx_iterator::array_type array;
  1493. rtx_insn *insn;
  1494. if (some_local_dynamic_name)
  1495. return some_local_dynamic_name;
  1496. for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
  1497. if (NONDEBUG_INSN_P (insn))
  1498. FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
  1499. {
  1500. const_rtx x = *iter;
  1501. if (GET_CODE (x) == SYMBOL_REF)
  1502. {
  1503. if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
  1504. return some_local_dynamic_name = XSTR (x, 0);
  1505. if (CONSTANT_POOL_ADDRESS_P (x))
  1506. iter.substitute (get_pool_constant (x));
  1507. }
  1508. }
  1509. return 0;
  1510. }
  1511. /* Output assembler code for the start of a function,
  1512. and initialize some of the variables in this file
  1513. for the new function. The label for the function and associated
  1514. assembler pseudo-ops have already been output in `assemble_start_function'.
  1515. FIRST is the first insn of the rtl for the function being compiled.
  1516. FILE is the file to write assembler code to.
  1517. OPTIMIZE_P is nonzero if we should eliminate redundant
  1518. test and compare insns. */
  1519. void
  1520. final_start_function (rtx_insn *first, FILE *file,
  1521. int optimize_p ATTRIBUTE_UNUSED)
  1522. {
  1523. block_depth = 0;
  1524. this_is_asm_operands = 0;
  1525. need_profile_function = false;
  1526. last_filename = LOCATION_FILE (prologue_location);
  1527. last_linenum = LOCATION_LINE (prologue_location);
  1528. last_discriminator = discriminator = 0;
  1529. high_block_linenum = high_function_linenum = last_linenum;
  1530. if (flag_sanitize & SANITIZE_ADDRESS)
  1531. asan_function_start ();
  1532. if (!DECL_IGNORED_P (current_function_decl))
  1533. debug_hooks->begin_prologue (last_linenum, last_filename);
  1534. if (!dwarf2_debug_info_emitted_p (current_function_decl))
  1535. dwarf2out_begin_prologue (0, NULL);
  1536. #ifdef LEAF_REG_REMAP
  1537. if (crtl->uses_only_leaf_regs)
  1538. leaf_renumber_regs (first);
  1539. #endif
  1540. /* The Sun386i and perhaps other machines don't work right
  1541. if the profiling code comes after the prologue. */
  1542. if (targetm.profile_before_prologue () && crtl->profile)
  1543. {
  1544. if (targetm.asm_out.function_prologue
  1545. == default_function_pro_epilogue
  1546. #ifdef HAVE_prologue
  1547. && HAVE_prologue
  1548. #endif
  1549. )
  1550. {
  1551. rtx_insn *insn;
  1552. for (insn = first; insn; insn = NEXT_INSN (insn))
  1553. if (!NOTE_P (insn))
  1554. {
  1555. insn = NULL;
  1556. break;
  1557. }
  1558. else if (NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK
  1559. || NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
  1560. break;
  1561. else if (NOTE_KIND (insn) == NOTE_INSN_DELETED
  1562. || NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION)
  1563. continue;
  1564. else
  1565. {
  1566. insn = NULL;
  1567. break;
  1568. }
  1569. if (insn)
  1570. need_profile_function = true;
  1571. else
  1572. profile_function (file);
  1573. }
  1574. else
  1575. profile_function (file);
  1576. }
  1577. /* If debugging, assign block numbers to all of the blocks in this
  1578. function. */
  1579. if (write_symbols)
  1580. {
  1581. reemit_insn_block_notes ();
  1582. number_blocks (current_function_decl);
  1583. /* We never actually put out begin/end notes for the top-level
  1584. block in the function. But, conceptually, that block is
  1585. always needed. */
  1586. TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
  1587. }
  1588. if (warn_frame_larger_than
  1589. && get_frame_size () > frame_larger_than_size)
  1590. {
  1591. /* Issue a warning */
  1592. warning (OPT_Wframe_larger_than_,
  1593. "the frame size of %wd bytes is larger than %wd bytes",
  1594. get_frame_size (), frame_larger_than_size);
  1595. }
  1596. /* First output the function prologue: code to set up the stack frame. */
  1597. targetm.asm_out.function_prologue (file, get_frame_size ());
  1598. /* If the machine represents the prologue as RTL, the profiling code must
  1599. be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
  1600. #ifdef HAVE_prologue
  1601. if (! HAVE_prologue)
  1602. #endif
  1603. profile_after_prologue (file);
  1604. }
  1605. static void
  1606. profile_after_prologue (FILE *file ATTRIBUTE_UNUSED)
  1607. {
  1608. if (!targetm.profile_before_prologue () && crtl->profile)
  1609. profile_function (file);
  1610. }
  1611. static void
  1612. profile_function (FILE *file ATTRIBUTE_UNUSED)
  1613. {
  1614. #ifndef NO_PROFILE_COUNTERS
  1615. # define NO_PROFILE_COUNTERS 0
  1616. #endif
  1617. #ifdef ASM_OUTPUT_REG_PUSH
  1618. rtx sval = NULL, chain = NULL;
  1619. if (cfun->returns_struct)
  1620. sval = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl),
  1621. true);
  1622. if (cfun->static_chain_decl)
  1623. chain = targetm.calls.static_chain (current_function_decl, true);
  1624. #endif /* ASM_OUTPUT_REG_PUSH */
  1625. if (! NO_PROFILE_COUNTERS)
  1626. {
  1627. int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
  1628. switch_to_section (data_section);
  1629. ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
  1630. targetm.asm_out.internal_label (file, "LP", current_function_funcdef_no);
  1631. assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
  1632. }
  1633. switch_to_section (current_function_section ());
  1634. #ifdef ASM_OUTPUT_REG_PUSH
  1635. if (sval && REG_P (sval))
  1636. ASM_OUTPUT_REG_PUSH (file, REGNO (sval));
  1637. if (chain && REG_P (chain))
  1638. ASM_OUTPUT_REG_PUSH (file, REGNO (chain));
  1639. #endif
  1640. FUNCTION_PROFILER (file, current_function_funcdef_no);
  1641. #ifdef ASM_OUTPUT_REG_PUSH
  1642. if (chain && REG_P (chain))
  1643. ASM_OUTPUT_REG_POP (file, REGNO (chain));
  1644. if (sval && REG_P (sval))
  1645. ASM_OUTPUT_REG_POP (file, REGNO (sval));
  1646. #endif
  1647. }
  1648. /* Output assembler code for the end of a function.
  1649. For clarity, args are same as those of `final_start_function'
  1650. even though not all of them are needed. */
  1651. void
  1652. final_end_function (void)
  1653. {
  1654. app_disable ();
  1655. if (!DECL_IGNORED_P (current_function_decl))
  1656. debug_hooks->end_function (high_function_linenum);
  1657. /* Finally, output the function epilogue:
  1658. code to restore the stack frame and return to the caller. */
  1659. targetm.asm_out.function_epilogue (asm_out_file, get_frame_size ());
  1660. /* And debug output. */
  1661. if (!DECL_IGNORED_P (current_function_decl))
  1662. debug_hooks->end_epilogue (last_linenum, last_filename);
  1663. if (!dwarf2_debug_info_emitted_p (current_function_decl)
  1664. && dwarf2out_do_frame ())
  1665. dwarf2out_end_epilogue (last_linenum, last_filename);
  1666. some_local_dynamic_name = 0;
  1667. }
  1668. /* Dumper helper for basic block information. FILE is the assembly
  1669. output file, and INSN is the instruction being emitted. */
  1670. static void
  1671. dump_basic_block_info (FILE *file, rtx_insn *insn, basic_block *start_to_bb,
  1672. basic_block *end_to_bb, int bb_map_size, int *bb_seqn)
  1673. {
  1674. basic_block bb;
  1675. if (!flag_debug_asm)
  1676. return;
  1677. if (INSN_UID (insn) < bb_map_size
  1678. && (bb = start_to_bb[INSN_UID (insn)]) != NULL)
  1679. {
  1680. edge e;
  1681. edge_iterator ei;
  1682. fprintf (file, "%s BLOCK %d", ASM_COMMENT_START, bb->index);
  1683. if (bb->frequency)
  1684. fprintf (file, " freq:%d", bb->frequency);
  1685. if (bb->count)
  1686. fprintf (file, " count:%"PRId64,
  1687. bb->count);
  1688. fprintf (file, " seq:%d", (*bb_seqn)++);
  1689. fprintf (file, "\n%s PRED:", ASM_COMMENT_START);
  1690. FOR_EACH_EDGE (e, ei, bb->preds)
  1691. {
  1692. dump_edge_info (file, e, TDF_DETAILS, 0);
  1693. }
  1694. fprintf (file, "\n");
  1695. }
  1696. if (INSN_UID (insn) < bb_map_size
  1697. && (bb = end_to_bb[INSN_UID (insn)]) != NULL)
  1698. {
  1699. edge e;
  1700. edge_iterator ei;
  1701. fprintf (asm_out_file, "%s SUCC:", ASM_COMMENT_START);
  1702. FOR_EACH_EDGE (e, ei, bb->succs)
  1703. {
  1704. dump_edge_info (asm_out_file, e, TDF_DETAILS, 1);
  1705. }
  1706. fprintf (file, "\n");
  1707. }
  1708. }
  1709. /* Output assembler code for some insns: all or part of a function.
  1710. For description of args, see `final_start_function', above. */
  1711. void
  1712. final (rtx_insn *first, FILE *file, int optimize_p)
  1713. {
  1714. rtx_insn *insn, *next;
  1715. int seen = 0;
  1716. /* Used for -dA dump. */
  1717. basic_block *start_to_bb = NULL;
  1718. basic_block *end_to_bb = NULL;
  1719. int bb_map_size = 0;
  1720. int bb_seqn = 0;
  1721. last_ignored_compare = 0;
  1722. #ifdef HAVE_cc0
  1723. for (insn = first; insn; insn = NEXT_INSN (insn))
  1724. {
  1725. /* If CC tracking across branches is enabled, record the insn which
  1726. jumps to each branch only reached from one place. */
  1727. if (optimize_p && JUMP_P (insn))
  1728. {
  1729. rtx lab = JUMP_LABEL (insn);
  1730. if (lab && LABEL_P (lab) && LABEL_NUSES (lab) == 1)
  1731. {
  1732. LABEL_REFS (lab) = insn;
  1733. }
  1734. }
  1735. }
  1736. #endif
  1737. init_recog ();
  1738. CC_STATUS_INIT;
  1739. if (flag_debug_asm)
  1740. {
  1741. basic_block bb;
  1742. bb_map_size = get_max_uid () + 1;
  1743. start_to_bb = XCNEWVEC (basic_block, bb_map_size);
  1744. end_to_bb = XCNEWVEC (basic_block, bb_map_size);
  1745. /* There is no cfg for a thunk. */
  1746. if (!cfun->is_thunk)
  1747. FOR_EACH_BB_REVERSE_FN (bb, cfun)
  1748. {
  1749. start_to_bb[INSN_UID (BB_HEAD (bb))] = bb;
  1750. end_to_bb[INSN_UID (BB_END (bb))] = bb;
  1751. }
  1752. }
  1753. /* Output the insns. */
  1754. for (insn = first; insn;)
  1755. {
  1756. if (HAVE_ATTR_length)
  1757. {
  1758. if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
  1759. {
  1760. /* This can be triggered by bugs elsewhere in the compiler if
  1761. new insns are created after init_insn_lengths is called. */
  1762. gcc_assert (NOTE_P (insn));
  1763. insn_current_address = -1;
  1764. }
  1765. else
  1766. insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
  1767. }
  1768. dump_basic_block_info (file, insn, start_to_bb, end_to_bb,
  1769. bb_map_size, &bb_seqn);
  1770. insn = final_scan_insn (insn, file, optimize_p, 0, &seen);
  1771. }
  1772. if (flag_debug_asm)
  1773. {
  1774. free (start_to_bb);
  1775. free (end_to_bb);
  1776. }
  1777. /* Remove CFI notes, to avoid compare-debug failures. */
  1778. for (insn = first; insn; insn = next)
  1779. {
  1780. next = NEXT_INSN (insn);
  1781. if (NOTE_P (insn)
  1782. && (NOTE_KIND (insn) == NOTE_INSN_CFI
  1783. || NOTE_KIND (insn) == NOTE_INSN_CFI_LABEL))
  1784. delete_insn (insn);
  1785. }
  1786. }
  1787. const char *
  1788. get_insn_template (int code, rtx insn)
  1789. {
  1790. switch (insn_data[code].output_format)
  1791. {
  1792. case INSN_OUTPUT_FORMAT_SINGLE:
  1793. return insn_data[code].output.single;
  1794. case INSN_OUTPUT_FORMAT_MULTI:
  1795. return insn_data[code].output.multi[which_alternative];
  1796. case INSN_OUTPUT_FORMAT_FUNCTION:
  1797. gcc_assert (insn);
  1798. return (*insn_data[code].output.function) (recog_data.operand,
  1799. as_a <rtx_insn *> (insn));
  1800. default:
  1801. gcc_unreachable ();
  1802. }
  1803. }
  1804. /* Emit the appropriate declaration for an alternate-entry-point
  1805. symbol represented by INSN, to FILE. INSN is a CODE_LABEL with
  1806. LABEL_KIND != LABEL_NORMAL.
  1807. The case fall-through in this function is intentional. */
  1808. static void
  1809. output_alternate_entry_point (FILE *file, rtx_insn *insn)
  1810. {
  1811. const char *name = LABEL_NAME (insn);
  1812. switch (LABEL_KIND (insn))
  1813. {
  1814. case LABEL_WEAK_ENTRY:
  1815. #ifdef ASM_WEAKEN_LABEL
  1816. ASM_WEAKEN_LABEL (file, name);
  1817. #endif
  1818. case LABEL_GLOBAL_ENTRY:
  1819. targetm.asm_out.globalize_label (file, name);
  1820. case LABEL_STATIC_ENTRY:
  1821. #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
  1822. ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
  1823. #endif
  1824. ASM_OUTPUT_LABEL (file, name);
  1825. break;
  1826. case LABEL_NORMAL:
  1827. default:
  1828. gcc_unreachable ();
  1829. }
  1830. }
  1831. /* Given a CALL_INSN, find and return the nested CALL. */
  1832. static rtx
  1833. call_from_call_insn (rtx_call_insn *insn)
  1834. {
  1835. rtx x;
  1836. gcc_assert (CALL_P (insn));
  1837. x = PATTERN (insn);
  1838. while (GET_CODE (x) != CALL)
  1839. {
  1840. switch (GET_CODE (x))
  1841. {
  1842. default:
  1843. gcc_unreachable ();
  1844. case COND_EXEC:
  1845. x = COND_EXEC_CODE (x);
  1846. break;
  1847. case PARALLEL:
  1848. x = XVECEXP (x, 0, 0);
  1849. break;
  1850. case SET:
  1851. x = XEXP (x, 1);
  1852. break;
  1853. }
  1854. }
  1855. return x;
  1856. }
  1857. /* The final scan for one insn, INSN.
  1858. Args are same as in `final', except that INSN
  1859. is the insn being scanned.
  1860. Value returned is the next insn to be scanned.
  1861. NOPEEPHOLES is the flag to disallow peephole processing (currently
  1862. used for within delayed branch sequence output).
  1863. SEEN is used to track the end of the prologue, for emitting
  1864. debug information. We force the emission of a line note after
  1865. both NOTE_INSN_PROLOGUE_END and NOTE_INSN_FUNCTION_BEG. */
  1866. rtx_insn *
  1867. final_scan_insn (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
  1868. int nopeepholes ATTRIBUTE_UNUSED, int *seen)
  1869. {
  1870. #ifdef HAVE_cc0
  1871. rtx set;
  1872. #endif
  1873. rtx_insn *next;
  1874. insn_counter++;
  1875. /* Ignore deleted insns. These can occur when we split insns (due to a
  1876. template of "#") while not optimizing. */
  1877. if (insn->deleted ())
  1878. return NEXT_INSN (insn);
  1879. switch (GET_CODE (insn))
  1880. {
  1881. case NOTE:
  1882. switch (NOTE_KIND (insn))
  1883. {
  1884. case NOTE_INSN_DELETED:
  1885. break;
  1886. case NOTE_INSN_SWITCH_TEXT_SECTIONS:
  1887. in_cold_section_p = !in_cold_section_p;
  1888. if (dwarf2out_do_frame ())
  1889. dwarf2out_switch_text_section ();
  1890. else if (!DECL_IGNORED_P (current_function_decl))
  1891. debug_hooks->switch_text_section ();
  1892. switch_to_section (current_function_section ());
  1893. targetm.asm_out.function_switched_text_sections (asm_out_file,
  1894. current_function_decl,
  1895. in_cold_section_p);
  1896. /* Emit a label for the split cold section. Form label name by
  1897. suffixing "cold" to the original function's name. */
  1898. if (in_cold_section_p)
  1899. {
  1900. tree cold_function_name
  1901. = clone_function_name (current_function_decl, "cold");
  1902. ASM_OUTPUT_LABEL (asm_out_file,
  1903. IDENTIFIER_POINTER (cold_function_name));
  1904. }
  1905. break;
  1906. case NOTE_INSN_BASIC_BLOCK:
  1907. if (need_profile_function)
  1908. {
  1909. profile_function (asm_out_file);
  1910. need_profile_function = false;
  1911. }
  1912. if (targetm.asm_out.unwind_emit)
  1913. targetm.asm_out.unwind_emit (asm_out_file, insn);
  1914. discriminator = NOTE_BASIC_BLOCK (insn)->discriminator;
  1915. break;
  1916. case NOTE_INSN_EH_REGION_BEG:
  1917. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
  1918. NOTE_EH_HANDLER (insn));
  1919. break;
  1920. case NOTE_INSN_EH_REGION_END:
  1921. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
  1922. NOTE_EH_HANDLER (insn));
  1923. break;
  1924. case NOTE_INSN_PROLOGUE_END:
  1925. targetm.asm_out.function_end_prologue (file);
  1926. profile_after_prologue (file);
  1927. if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
  1928. {
  1929. *seen |= SEEN_EMITTED;
  1930. force_source_line = true;
  1931. }
  1932. else
  1933. *seen |= SEEN_NOTE;
  1934. break;
  1935. case NOTE_INSN_EPILOGUE_BEG:
  1936. if (!DECL_IGNORED_P (current_function_decl))
  1937. (*debug_hooks->begin_epilogue) (last_linenum, last_filename);
  1938. targetm.asm_out.function_begin_epilogue (file);
  1939. break;
  1940. case NOTE_INSN_CFI:
  1941. dwarf2out_emit_cfi (NOTE_CFI (insn));
  1942. break;
  1943. case NOTE_INSN_CFI_LABEL:
  1944. ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI",
  1945. NOTE_LABEL_NUMBER (insn));
  1946. break;
  1947. case NOTE_INSN_FUNCTION_BEG:
  1948. if (need_profile_function)
  1949. {
  1950. profile_function (asm_out_file);
  1951. need_profile_function = false;
  1952. }
  1953. app_disable ();
  1954. if (!DECL_IGNORED_P (current_function_decl))
  1955. debug_hooks->end_prologue (last_linenum, last_filename);
  1956. if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
  1957. {
  1958. *seen |= SEEN_EMITTED;
  1959. force_source_line = true;
  1960. }
  1961. else
  1962. *seen |= SEEN_NOTE;
  1963. break;
  1964. case NOTE_INSN_BLOCK_BEG:
  1965. if (debug_info_level == DINFO_LEVEL_NORMAL
  1966. || debug_info_level == DINFO_LEVEL_VERBOSE
  1967. || write_symbols == DWARF2_DEBUG
  1968. || write_symbols == VMS_AND_DWARF2_DEBUG
  1969. || write_symbols == VMS_DEBUG)
  1970. {
  1971. int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
  1972. app_disable ();
  1973. ++block_depth;
  1974. high_block_linenum = last_linenum;
  1975. /* Output debugging info about the symbol-block beginning. */
  1976. if (!DECL_IGNORED_P (current_function_decl))
  1977. debug_hooks->begin_block (last_linenum, n);
  1978. /* Mark this block as output. */
  1979. TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
  1980. }
  1981. if (write_symbols == DBX_DEBUG
  1982. || write_symbols == SDB_DEBUG)
  1983. {
  1984. location_t *locus_ptr
  1985. = block_nonartificial_location (NOTE_BLOCK (insn));
  1986. if (locus_ptr != NULL)
  1987. {
  1988. override_filename = LOCATION_FILE (*locus_ptr);
  1989. override_linenum = LOCATION_LINE (*locus_ptr);
  1990. }
  1991. }
  1992. break;
  1993. case NOTE_INSN_BLOCK_END:
  1994. if (debug_info_level == DINFO_LEVEL_NORMAL
  1995. || debug_info_level == DINFO_LEVEL_VERBOSE
  1996. || write_symbols == DWARF2_DEBUG
  1997. || write_symbols == VMS_AND_DWARF2_DEBUG
  1998. || write_symbols == VMS_DEBUG)
  1999. {
  2000. int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
  2001. app_disable ();
  2002. /* End of a symbol-block. */
  2003. --block_depth;
  2004. gcc_assert (block_depth >= 0);
  2005. if (!DECL_IGNORED_P (current_function_decl))
  2006. debug_hooks->end_block (high_block_linenum, n);
  2007. }
  2008. if (write_symbols == DBX_DEBUG
  2009. || write_symbols == SDB_DEBUG)
  2010. {
  2011. tree outer_block = BLOCK_SUPERCONTEXT (NOTE_BLOCK (insn));
  2012. location_t *locus_ptr
  2013. = block_nonartificial_location (outer_block);
  2014. if (locus_ptr != NULL)
  2015. {
  2016. override_filename = LOCATION_FILE (*locus_ptr);
  2017. override_linenum = LOCATION_LINE (*locus_ptr);
  2018. }
  2019. else
  2020. {
  2021. override_filename = NULL;
  2022. override_linenum = 0;
  2023. }
  2024. }
  2025. break;
  2026. case NOTE_INSN_DELETED_LABEL:
  2027. /* Emit the label. We may have deleted the CODE_LABEL because
  2028. the label could be proved to be unreachable, though still
  2029. referenced (in the form of having its address taken. */
  2030. ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  2031. break;
  2032. case NOTE_INSN_DELETED_DEBUG_LABEL:
  2033. /* Similarly, but need to use different namespace for it. */
  2034. if (CODE_LABEL_NUMBER (insn) != -1)
  2035. ASM_OUTPUT_DEBUG_LABEL (file, "LDL", CODE_LABEL_NUMBER (insn));
  2036. break;
  2037. case NOTE_INSN_VAR_LOCATION:
  2038. case NOTE_INSN_CALL_ARG_LOCATION:
  2039. if (!DECL_IGNORED_P (current_function_decl))
  2040. debug_hooks->var_location (insn);
  2041. break;
  2042. default:
  2043. gcc_unreachable ();
  2044. break;
  2045. }
  2046. break;
  2047. case BARRIER:
  2048. break;
  2049. case CODE_LABEL:
  2050. /* The target port might emit labels in the output function for
  2051. some insn, e.g. sh.c output_branchy_insn. */
  2052. if (CODE_LABEL_NUMBER (insn) <= max_labelno)
  2053. {
  2054. int align = LABEL_TO_ALIGNMENT (insn);
  2055. #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
  2056. int max_skip = LABEL_TO_MAX_SKIP (insn);
  2057. #endif
  2058. if (align && NEXT_INSN (insn))
  2059. {
  2060. #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
  2061. ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
  2062. #else
  2063. #ifdef ASM_OUTPUT_ALIGN_WITH_NOP
  2064. ASM_OUTPUT_ALIGN_WITH_NOP (file, align);
  2065. #else
  2066. ASM_OUTPUT_ALIGN (file, align);
  2067. #endif
  2068. #endif
  2069. }
  2070. }
  2071. CC_STATUS_INIT;
  2072. if (!DECL_IGNORED_P (current_function_decl) && LABEL_NAME (insn))
  2073. debug_hooks->label (as_a <rtx_code_label *> (insn));
  2074. app_disable ();
  2075. next = next_nonnote_insn (insn);
  2076. /* If this label is followed by a jump-table, make sure we put
  2077. the label in the read-only section. Also possibly write the
  2078. label and jump table together. */
  2079. if (next != 0 && JUMP_TABLE_DATA_P (next))
  2080. {
  2081. #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
  2082. /* In this case, the case vector is being moved by the
  2083. target, so don't output the label at all. Leave that
  2084. to the back end macros. */
  2085. #else
  2086. if (! JUMP_TABLES_IN_TEXT_SECTION)
  2087. {
  2088. int log_align;
  2089. switch_to_section (targetm.asm_out.function_rodata_section
  2090. (current_function_decl));
  2091. #ifdef ADDR_VEC_ALIGN
  2092. log_align = ADDR_VEC_ALIGN (next);
  2093. #else
  2094. log_align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
  2095. #endif
  2096. ASM_OUTPUT_ALIGN (file, log_align);
  2097. }
  2098. else
  2099. switch_to_section (current_function_section ());
  2100. #ifdef ASM_OUTPUT_CASE_LABEL
  2101. ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
  2102. next);
  2103. #else
  2104. targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
  2105. #endif
  2106. #endif
  2107. break;
  2108. }
  2109. if (LABEL_ALT_ENTRY_P (insn))
  2110. output_alternate_entry_point (file, insn);
  2111. else
  2112. targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
  2113. break;
  2114. default:
  2115. {
  2116. rtx body = PATTERN (insn);
  2117. int insn_code_number;
  2118. const char *templ;
  2119. bool is_stmt;
  2120. /* Reset this early so it is correct for ASM statements. */
  2121. current_insn_predicate = NULL_RTX;
  2122. /* An INSN, JUMP_INSN or CALL_INSN.
  2123. First check for special kinds that recog doesn't recognize. */
  2124. if (GET_CODE (body) == USE /* These are just declarations. */
  2125. || GET_CODE (body) == CLOBBER)
  2126. break;
  2127. #ifdef HAVE_cc0
  2128. {
  2129. /* If there is a REG_CC_SETTER note on this insn, it means that
  2130. the setting of the condition code was done in the delay slot
  2131. of the insn that branched here. So recover the cc status
  2132. from the insn that set it. */
  2133. rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
  2134. if (note)
  2135. {
  2136. rtx_insn *other = as_a <rtx_insn *> (XEXP (note, 0));
  2137. NOTICE_UPDATE_CC (PATTERN (other), other);
  2138. cc_prev_status = cc_status;
  2139. }
  2140. }
  2141. #endif
  2142. /* Detect insns that are really jump-tables
  2143. and output them as such. */
  2144. if (JUMP_TABLE_DATA_P (insn))
  2145. {
  2146. #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
  2147. int vlen, idx;
  2148. #endif
  2149. if (! JUMP_TABLES_IN_TEXT_SECTION)
  2150. switch_to_section (targetm.asm_out.function_rodata_section
  2151. (current_function_decl));
  2152. else
  2153. switch_to_section (current_function_section ());
  2154. app_disable ();
  2155. #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
  2156. if (GET_CODE (body) == ADDR_VEC)
  2157. {
  2158. #ifdef ASM_OUTPUT_ADDR_VEC
  2159. ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
  2160. #else
  2161. gcc_unreachable ();
  2162. #endif
  2163. }
  2164. else
  2165. {
  2166. #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
  2167. ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
  2168. #else
  2169. gcc_unreachable ();
  2170. #endif
  2171. }
  2172. #else
  2173. vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
  2174. for (idx = 0; idx < vlen; idx++)
  2175. {
  2176. if (GET_CODE (body) == ADDR_VEC)
  2177. {
  2178. #ifdef ASM_OUTPUT_ADDR_VEC_ELT
  2179. ASM_OUTPUT_ADDR_VEC_ELT
  2180. (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  2181. #else
  2182. gcc_unreachable ();
  2183. #endif
  2184. }
  2185. else
  2186. {
  2187. #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
  2188. ASM_OUTPUT_ADDR_DIFF_ELT
  2189. (file,
  2190. body,
  2191. CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  2192. CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  2193. #else
  2194. gcc_unreachable ();
  2195. #endif
  2196. }
  2197. }
  2198. #ifdef ASM_OUTPUT_CASE_END
  2199. ASM_OUTPUT_CASE_END (file,
  2200. CODE_LABEL_NUMBER (PREV_INSN (insn)),
  2201. insn);
  2202. #endif
  2203. #endif
  2204. switch_to_section (current_function_section ());
  2205. break;
  2206. }
  2207. /* Output this line note if it is the first or the last line
  2208. note in a row. */
  2209. if (!DECL_IGNORED_P (current_function_decl)
  2210. && notice_source_line (insn, &is_stmt))
  2211. (*debug_hooks->source_line) (last_linenum, last_filename,
  2212. last_discriminator, is_stmt);
  2213. if (GET_CODE (body) == ASM_INPUT)
  2214. {
  2215. const char *string = XSTR (body, 0);
  2216. /* There's no telling what that did to the condition codes. */
  2217. CC_STATUS_INIT;
  2218. if (string[0])
  2219. {
  2220. expanded_location loc;
  2221. app_enable ();
  2222. loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body));
  2223. if (*loc.file && loc.line)
  2224. fprintf (asm_out_file, "%s %i \"%s\" 1\n",
  2225. ASM_COMMENT_START, loc.line, loc.file);
  2226. fprintf (asm_out_file, "\t%s\n", string);
  2227. #if HAVE_AS_LINE_ZERO
  2228. if (*loc.file && loc.line)
  2229. fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
  2230. #endif
  2231. }
  2232. break;
  2233. }
  2234. /* Detect `asm' construct with operands. */
  2235. if (asm_noperands (body) >= 0)
  2236. {
  2237. unsigned int noperands = asm_noperands (body);
  2238. rtx *ops = XALLOCAVEC (rtx, noperands);
  2239. const char *string;
  2240. location_t loc;
  2241. expanded_location expanded;
  2242. /* There's no telling what that did to the condition codes. */
  2243. CC_STATUS_INIT;
  2244. /* Get out the operand values. */
  2245. string = decode_asm_operands (body, ops, NULL, NULL, NULL, &loc);
  2246. /* Inhibit dying on what would otherwise be compiler bugs. */
  2247. insn_noperands = noperands;
  2248. this_is_asm_operands = insn;
  2249. expanded = expand_location (loc);
  2250. #ifdef FINAL_PRESCAN_INSN
  2251. FINAL_PRESCAN_INSN (insn, ops, insn_noperands);
  2252. #endif
  2253. /* Output the insn using them. */
  2254. if (string[0])
  2255. {
  2256. app_enable ();
  2257. if (expanded.file && expanded.line)
  2258. fprintf (asm_out_file, "%s %i \"%s\" 1\n",
  2259. ASM_COMMENT_START, expanded.line, expanded.file);
  2260. output_asm_insn (string, ops);
  2261. #if HAVE_AS_LINE_ZERO
  2262. if (expanded.file && expanded.line)
  2263. fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
  2264. #endif
  2265. }
  2266. if (targetm.asm_out.final_postscan_insn)
  2267. targetm.asm_out.final_postscan_insn (file, insn, ops,
  2268. insn_noperands);
  2269. this_is_asm_operands = 0;
  2270. break;
  2271. }
  2272. app_disable ();
  2273. if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (body))
  2274. {
  2275. /* A delayed-branch sequence */
  2276. int i;
  2277. final_sequence = seq;
  2278. /* The first insn in this SEQUENCE might be a JUMP_INSN that will
  2279. force the restoration of a comparison that was previously
  2280. thought unnecessary. If that happens, cancel this sequence
  2281. and cause that insn to be restored. */
  2282. next = final_scan_insn (seq->insn (0), file, 0, 1, seen);
  2283. if (next != seq->insn (1))
  2284. {
  2285. final_sequence = 0;
  2286. return next;
  2287. }
  2288. for (i = 1; i < seq->len (); i++)
  2289. {
  2290. rtx_insn *insn = seq->insn (i);
  2291. rtx_insn *next = NEXT_INSN (insn);
  2292. /* We loop in case any instruction in a delay slot gets
  2293. split. */
  2294. do
  2295. insn = final_scan_insn (insn, file, 0, 1, seen);
  2296. while (insn != next);
  2297. }
  2298. #ifdef DBR_OUTPUT_SEQEND
  2299. DBR_OUTPUT_SEQEND (file);
  2300. #endif
  2301. final_sequence = 0;
  2302. /* If the insn requiring the delay slot was a CALL_INSN, the
  2303. insns in the delay slot are actually executed before the
  2304. called function. Hence we don't preserve any CC-setting
  2305. actions in these insns and the CC must be marked as being
  2306. clobbered by the function. */
  2307. if (CALL_P (seq->insn (0)))
  2308. {
  2309. CC_STATUS_INIT;
  2310. }
  2311. break;
  2312. }
  2313. /* We have a real machine instruction as rtl. */
  2314. body = PATTERN (insn);
  2315. #ifdef HAVE_cc0
  2316. set = single_set (insn);
  2317. /* Check for redundant test and compare instructions
  2318. (when the condition codes are already set up as desired).
  2319. This is done only when optimizing; if not optimizing,
  2320. it should be possible for the user to alter a variable
  2321. with the debugger in between statements
  2322. and the next statement should reexamine the variable
  2323. to compute the condition codes. */
  2324. if (optimize_p)
  2325. {
  2326. if (set
  2327. && GET_CODE (SET_DEST (set)) == CC0
  2328. && insn != last_ignored_compare)
  2329. {
  2330. rtx src1, src2;
  2331. if (GET_CODE (SET_SRC (set)) == SUBREG)
  2332. SET_SRC (set) = alter_subreg (&SET_SRC (set), true);
  2333. src1 = SET_SRC (set);
  2334. src2 = NULL_RTX;
  2335. if (GET_CODE (SET_SRC (set)) == COMPARE)
  2336. {
  2337. if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
  2338. XEXP (SET_SRC (set), 0)
  2339. = alter_subreg (&XEXP (SET_SRC (set), 0), true);
  2340. if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
  2341. XEXP (SET_SRC (set), 1)
  2342. = alter_subreg (&XEXP (SET_SRC (set), 1), true);
  2343. if (XEXP (SET_SRC (set), 1)
  2344. == CONST0_RTX (GET_MODE (XEXP (SET_SRC (set), 0))))
  2345. src2 = XEXP (SET_SRC (set), 0);
  2346. }
  2347. if ((cc_status.value1 != 0
  2348. && rtx_equal_p (src1, cc_status.value1))
  2349. || (cc_status.value2 != 0
  2350. && rtx_equal_p (src1, cc_status.value2))
  2351. || (src2 != 0 && cc_status.value1 != 0
  2352. && rtx_equal_p (src2, cc_status.value1))
  2353. || (src2 != 0 && cc_status.value2 != 0
  2354. && rtx_equal_p (src2, cc_status.value2)))
  2355. {
  2356. /* Don't delete insn if it has an addressing side-effect. */
  2357. if (! FIND_REG_INC_NOTE (insn, NULL_RTX)
  2358. /* or if anything in it is volatile. */
  2359. && ! volatile_refs_p (PATTERN (insn)))
  2360. {
  2361. /* We don't really delete the insn; just ignore it. */
  2362. last_ignored_compare = insn;
  2363. break;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. /* If this is a conditional branch, maybe modify it
  2369. if the cc's are in a nonstandard state
  2370. so that it accomplishes the same thing that it would
  2371. do straightforwardly if the cc's were set up normally. */
  2372. if (cc_status.flags != 0
  2373. && JUMP_P (insn)
  2374. && GET_CODE (body) == SET
  2375. && SET_DEST (body) == pc_rtx
  2376. && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  2377. && COMPARISON_P (XEXP (SET_SRC (body), 0))
  2378. && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
  2379. {
  2380. /* This function may alter the contents of its argument
  2381. and clear some of the cc_status.flags bits.
  2382. It may also return 1 meaning condition now always true
  2383. or -1 meaning condition now always false
  2384. or 2 meaning condition nontrivial but altered. */
  2385. int result = alter_cond (XEXP (SET_SRC (body), 0));
  2386. /* If condition now has fixed value, replace the IF_THEN_ELSE
  2387. with its then-operand or its else-operand. */
  2388. if (result == 1)
  2389. SET_SRC (body) = XEXP (SET_SRC (body), 1);
  2390. if (result == -1)
  2391. SET_SRC (body) = XEXP (SET_SRC (body), 2);
  2392. /* The jump is now either unconditional or a no-op.
  2393. If it has become a no-op, don't try to output it.
  2394. (It would not be recognized.) */
  2395. if (SET_SRC (body) == pc_rtx)
  2396. {
  2397. delete_insn (insn);
  2398. break;
  2399. }
  2400. else if (ANY_RETURN_P (SET_SRC (body)))
  2401. /* Replace (set (pc) (return)) with (return). */
  2402. PATTERN (insn) = body = SET_SRC (body);
  2403. /* Rerecognize the instruction if it has changed. */
  2404. if (result != 0)
  2405. INSN_CODE (insn) = -1;
  2406. }
  2407. /* If this is a conditional trap, maybe modify it if the cc's
  2408. are in a nonstandard state so that it accomplishes the same
  2409. thing that it would do straightforwardly if the cc's were
  2410. set up normally. */
  2411. if (cc_status.flags != 0
  2412. && NONJUMP_INSN_P (insn)
  2413. && GET_CODE (body) == TRAP_IF
  2414. && COMPARISON_P (TRAP_CONDITION (body))
  2415. && XEXP (TRAP_CONDITION (body), 0) == cc0_rtx)
  2416. {
  2417. /* This function may alter the contents of its argument
  2418. and clear some of the cc_status.flags bits.
  2419. It may also return 1 meaning condition now always true
  2420. or -1 meaning condition now always false
  2421. or 2 meaning condition nontrivial but altered. */
  2422. int result = alter_cond (TRAP_CONDITION (body));
  2423. /* If TRAP_CONDITION has become always false, delete the
  2424. instruction. */
  2425. if (result == -1)
  2426. {
  2427. delete_insn (insn);
  2428. break;
  2429. }
  2430. /* If TRAP_CONDITION has become always true, replace
  2431. TRAP_CONDITION with const_true_rtx. */
  2432. if (result == 1)
  2433. TRAP_CONDITION (body) = const_true_rtx;
  2434. /* Rerecognize the instruction if it has changed. */
  2435. if (result != 0)
  2436. INSN_CODE (insn) = -1;
  2437. }
  2438. /* Make same adjustments to instructions that examine the
  2439. condition codes without jumping and instructions that
  2440. handle conditional moves (if this machine has either one). */
  2441. if (cc_status.flags != 0
  2442. && set != 0)
  2443. {
  2444. rtx cond_rtx, then_rtx, else_rtx;
  2445. if (!JUMP_P (insn)
  2446. && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
  2447. {
  2448. cond_rtx = XEXP (SET_SRC (set), 0);
  2449. then_rtx = XEXP (SET_SRC (set), 1);
  2450. else_rtx = XEXP (SET_SRC (set), 2);
  2451. }
  2452. else
  2453. {
  2454. cond_rtx = SET_SRC (set);
  2455. then_rtx = const_true_rtx;
  2456. else_rtx = const0_rtx;
  2457. }
  2458. if (COMPARISON_P (cond_rtx)
  2459. && XEXP (cond_rtx, 0) == cc0_rtx)
  2460. {
  2461. int result;
  2462. result = alter_cond (cond_rtx);
  2463. if (result == 1)
  2464. validate_change (insn, &SET_SRC (set), then_rtx, 0);
  2465. else if (result == -1)
  2466. validate_change (insn, &SET_SRC (set), else_rtx, 0);
  2467. else if (result == 2)
  2468. INSN_CODE (insn) = -1;
  2469. if (SET_DEST (set) == SET_SRC (set))
  2470. delete_insn (insn);
  2471. }
  2472. }
  2473. #endif
  2474. #ifdef HAVE_peephole
  2475. /* Do machine-specific peephole optimizations if desired. */
  2476. if (optimize_p && !flag_no_peephole && !nopeepholes)
  2477. {
  2478. rtx_insn *next = peephole (insn);
  2479. /* When peepholing, if there were notes within the peephole,
  2480. emit them before the peephole. */
  2481. if (next != 0 && next != NEXT_INSN (insn))
  2482. {
  2483. rtx_insn *note, *prev = PREV_INSN (insn);
  2484. for (note = NEXT_INSN (insn); note != next;
  2485. note = NEXT_INSN (note))
  2486. final_scan_insn (note, file, optimize_p, nopeepholes, seen);
  2487. /* Put the notes in the proper position for a later
  2488. rescan. For example, the SH target can do this
  2489. when generating a far jump in a delayed branch
  2490. sequence. */
  2491. note = NEXT_INSN (insn);
  2492. SET_PREV_INSN (note) = prev;
  2493. SET_NEXT_INSN (prev) = note;
  2494. SET_NEXT_INSN (PREV_INSN (next)) = insn;
  2495. SET_PREV_INSN (insn) = PREV_INSN (next);
  2496. SET_NEXT_INSN (insn) = next;
  2497. SET_PREV_INSN (next) = insn;
  2498. }
  2499. /* PEEPHOLE might have changed this. */
  2500. body = PATTERN (insn);
  2501. }
  2502. #endif
  2503. /* Try to recognize the instruction.
  2504. If successful, verify that the operands satisfy the
  2505. constraints for the instruction. Crash if they don't,
  2506. since `reload' should have changed them so that they do. */
  2507. insn_code_number = recog_memoized (insn);
  2508. cleanup_subreg_operands (insn);
  2509. /* Dump the insn in the assembly for debugging (-dAP).
  2510. If the final dump is requested as slim RTL, dump slim
  2511. RTL to the assembly file also. */
  2512. if (flag_dump_rtl_in_asm)
  2513. {
  2514. print_rtx_head = ASM_COMMENT_START;
  2515. if (! (dump_flags & TDF_SLIM))
  2516. print_rtl_single (asm_out_file, insn);
  2517. else
  2518. dump_insn_slim (asm_out_file, insn);
  2519. print_rtx_head = "";
  2520. }
  2521. if (! constrain_operands_cached (insn, 1))
  2522. fatal_insn_not_found (insn);
  2523. /* Some target machines need to prescan each insn before
  2524. it is output. */
  2525. #ifdef FINAL_PRESCAN_INSN
  2526. FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
  2527. #endif
  2528. if (targetm.have_conditional_execution ()
  2529. && GET_CODE (PATTERN (insn)) == COND_EXEC)
  2530. current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
  2531. #ifdef HAVE_cc0
  2532. cc_prev_status = cc_status;
  2533. /* Update `cc_status' for this instruction.
  2534. The instruction's output routine may change it further.
  2535. If the output routine for a jump insn needs to depend
  2536. on the cc status, it should look at cc_prev_status. */
  2537. NOTICE_UPDATE_CC (body, insn);
  2538. #endif
  2539. current_output_insn = debug_insn = insn;
  2540. /* Find the proper template for this insn. */
  2541. templ = get_insn_template (insn_code_number, insn);
  2542. /* If the C code returns 0, it means that it is a jump insn
  2543. which follows a deleted test insn, and that test insn
  2544. needs to be reinserted. */
  2545. if (templ == 0)
  2546. {
  2547. rtx_insn *prev;
  2548. gcc_assert (prev_nonnote_insn (insn) == last_ignored_compare);
  2549. /* We have already processed the notes between the setter and
  2550. the user. Make sure we don't process them again, this is
  2551. particularly important if one of the notes is a block
  2552. scope note or an EH note. */
  2553. for (prev = insn;
  2554. prev != last_ignored_compare;
  2555. prev = PREV_INSN (prev))
  2556. {
  2557. if (NOTE_P (prev))
  2558. delete_insn (prev); /* Use delete_note. */
  2559. }
  2560. return prev;
  2561. }
  2562. /* If the template is the string "#", it means that this insn must
  2563. be split. */
  2564. if (templ[0] == '#' && templ[1] == '\0')
  2565. {
  2566. rtx_insn *new_rtx = try_split (body, insn, 0);
  2567. /* If we didn't split the insn, go away. */
  2568. if (new_rtx == insn && PATTERN (new_rtx) == body)
  2569. fatal_insn ("could not split insn", insn);
  2570. /* If we have a length attribute, this instruction should have
  2571. been split in shorten_branches, to ensure that we would have
  2572. valid length info for the splitees. */
  2573. gcc_assert (!HAVE_ATTR_length);
  2574. return new_rtx;
  2575. }
  2576. /* ??? This will put the directives in the wrong place if
  2577. get_insn_template outputs assembly directly. However calling it
  2578. before get_insn_template breaks if the insns is split. */
  2579. if (targetm.asm_out.unwind_emit_before_insn
  2580. && targetm.asm_out.unwind_emit)
  2581. targetm.asm_out.unwind_emit (asm_out_file, insn);
  2582. if (rtx_call_insn *call_insn = dyn_cast <rtx_call_insn *> (insn))
  2583. {
  2584. rtx x = call_from_call_insn (call_insn);
  2585. x = XEXP (x, 0);
  2586. if (x && MEM_P (x) && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
  2587. {
  2588. tree t;
  2589. x = XEXP (x, 0);
  2590. t = SYMBOL_REF_DECL (x);
  2591. if (t)
  2592. assemble_external (t);
  2593. }
  2594. if (!DECL_IGNORED_P (current_function_decl))
  2595. debug_hooks->var_location (insn);
  2596. }
  2597. /* Output assembler code from the template. */
  2598. output_asm_insn (templ, recog_data.operand);
  2599. /* Some target machines need to postscan each insn after
  2600. it is output. */
  2601. if (targetm.asm_out.final_postscan_insn)
  2602. targetm.asm_out.final_postscan_insn (file, insn, recog_data.operand,
  2603. recog_data.n_operands);
  2604. if (!targetm.asm_out.unwind_emit_before_insn
  2605. && targetm.asm_out.unwind_emit)
  2606. targetm.asm_out.unwind_emit (asm_out_file, insn);
  2607. current_output_insn = debug_insn = 0;
  2608. }
  2609. }
  2610. return NEXT_INSN (insn);
  2611. }
  2612. /* Return whether a source line note needs to be emitted before INSN.
  2613. Sets IS_STMT to TRUE if the line should be marked as a possible
  2614. breakpoint location. */
  2615. static bool
  2616. notice_source_line (rtx_insn *insn, bool *is_stmt)
  2617. {
  2618. const char *filename;
  2619. int linenum;
  2620. if (override_filename)
  2621. {
  2622. filename = override_filename;
  2623. linenum = override_linenum;
  2624. }
  2625. else if (INSN_HAS_LOCATION (insn))
  2626. {
  2627. expanded_location xloc = insn_location (insn);
  2628. filename = xloc.file;
  2629. linenum = xloc.line;
  2630. }
  2631. else
  2632. {
  2633. filename = NULL;
  2634. linenum = 0;
  2635. }
  2636. if (filename == NULL)
  2637. return false;
  2638. if (force_source_line
  2639. || filename != last_filename
  2640. || last_linenum != linenum)
  2641. {
  2642. force_source_line = false;
  2643. last_filename = filename;
  2644. last_linenum = linenum;
  2645. last_discriminator = discriminator;
  2646. *is_stmt = true;
  2647. high_block_linenum = MAX (last_linenum, high_block_linenum);
  2648. high_function_linenum = MAX (last_linenum, high_function_linenum);
  2649. return true;
  2650. }
  2651. if (SUPPORTS_DISCRIMINATOR && last_discriminator != discriminator)
  2652. {
  2653. /* If the discriminator changed, but the line number did not,
  2654. output the line table entry with is_stmt false so the
  2655. debugger does not treat this as a breakpoint location. */
  2656. last_discriminator = discriminator;
  2657. *is_stmt = false;
  2658. return true;
  2659. }
  2660. return false;
  2661. }
  2662. /* For each operand in INSN, simplify (subreg (reg)) so that it refers
  2663. directly to the desired hard register. */
  2664. void
  2665. cleanup_subreg_operands (rtx_insn *insn)
  2666. {
  2667. int i;
  2668. bool changed = false;
  2669. extract_insn_cached (insn);
  2670. for (i = 0; i < recog_data.n_operands; i++)
  2671. {
  2672. /* The following test cannot use recog_data.operand when testing
  2673. for a SUBREG: the underlying object might have been changed
  2674. already if we are inside a match_operator expression that
  2675. matches the else clause. Instead we test the underlying
  2676. expression directly. */
  2677. if (GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
  2678. {
  2679. recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i], true);
  2680. changed = true;
  2681. }
  2682. else if (GET_CODE (recog_data.operand[i]) == PLUS
  2683. || GET_CODE (recog_data.operand[i]) == MULT
  2684. || MEM_P (recog_data.operand[i]))
  2685. recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i], &changed);
  2686. }
  2687. for (i = 0; i < recog_data.n_dups; i++)
  2688. {
  2689. if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
  2690. {
  2691. *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i], true);
  2692. changed = true;
  2693. }
  2694. else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
  2695. || GET_CODE (*recog_data.dup_loc[i]) == MULT
  2696. || MEM_P (*recog_data.dup_loc[i]))
  2697. *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i], &changed);
  2698. }
  2699. if (changed)
  2700. df_insn_rescan (insn);
  2701. }
  2702. /* If X is a SUBREG, try to replace it with a REG or a MEM, based on
  2703. the thing it is a subreg of. Do it anyway if FINAL_P. */
  2704. rtx
  2705. alter_subreg (rtx *xp, bool final_p)
  2706. {
  2707. rtx x = *xp;
  2708. rtx y = SUBREG_REG (x);
  2709. /* simplify_subreg does not remove subreg from volatile references.
  2710. We are required to. */
  2711. if (MEM_P (y))
  2712. {
  2713. int offset = SUBREG_BYTE (x);
  2714. /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
  2715. contains 0 instead of the proper offset. See simplify_subreg. */
  2716. if (offset == 0
  2717. && GET_MODE_SIZE (GET_MODE (y)) < GET_MODE_SIZE (GET_MODE (x)))
  2718. {
  2719. int difference = GET_MODE_SIZE (GET_MODE (y))
  2720. - GET_MODE_SIZE (GET_MODE (x));
  2721. if (WORDS_BIG_ENDIAN)
  2722. offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
  2723. if (BYTES_BIG_ENDIAN)
  2724. offset += difference % UNITS_PER_WORD;
  2725. }
  2726. if (final_p)
  2727. *xp = adjust_address (y, GET_MODE (x), offset);
  2728. else
  2729. *xp = adjust_address_nv (y, GET_MODE (x), offset);
  2730. }
  2731. else if (REG_P (y) && HARD_REGISTER_P (y))
  2732. {
  2733. rtx new_rtx = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
  2734. SUBREG_BYTE (x));
  2735. if (new_rtx != 0)
  2736. *xp = new_rtx;
  2737. else if (final_p && REG_P (y))
  2738. {
  2739. /* Simplify_subreg can't handle some REG cases, but we have to. */
  2740. unsigned int regno;
  2741. HOST_WIDE_INT offset;
  2742. regno = subreg_regno (x);
  2743. if (subreg_lowpart_p (x))
  2744. offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
  2745. else
  2746. offset = SUBREG_BYTE (x);
  2747. *xp = gen_rtx_REG_offset (y, GET_MODE (x), regno, offset);
  2748. }
  2749. }
  2750. return *xp;
  2751. }
  2752. /* Do alter_subreg on all the SUBREGs contained in X. */
  2753. static rtx
  2754. walk_alter_subreg (rtx *xp, bool *changed)
  2755. {
  2756. rtx x = *xp;
  2757. switch (GET_CODE (x))
  2758. {
  2759. case PLUS:
  2760. case MULT:
  2761. case AND:
  2762. XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
  2763. XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1), changed);
  2764. break;
  2765. case MEM:
  2766. case ZERO_EXTEND:
  2767. XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
  2768. break;
  2769. case SUBREG:
  2770. *changed = true;
  2771. return alter_subreg (xp, true);
  2772. default:
  2773. break;
  2774. }
  2775. return *xp;
  2776. }
  2777. #ifdef HAVE_cc0
  2778. /* Given BODY, the body of a jump instruction, alter the jump condition
  2779. as required by the bits that are set in cc_status.flags.
  2780. Not all of the bits there can be handled at this level in all cases.
  2781. The value is normally 0.
  2782. 1 means that the condition has become always true.
  2783. -1 means that the condition has become always false.
  2784. 2 means that COND has been altered. */
  2785. static int
  2786. alter_cond (rtx cond)
  2787. {
  2788. int value = 0;
  2789. if (cc_status.flags & CC_REVERSED)
  2790. {
  2791. value = 2;
  2792. PUT_CODE (cond, swap_condition (GET_CODE (cond)));
  2793. }
  2794. if (cc_status.flags & CC_INVERTED)
  2795. {
  2796. value = 2;
  2797. PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
  2798. }
  2799. if (cc_status.flags & CC_NOT_POSITIVE)
  2800. switch (GET_CODE (cond))
  2801. {
  2802. case LE:
  2803. case LEU:
  2804. case GEU:
  2805. /* Jump becomes unconditional. */
  2806. return 1;
  2807. case GT:
  2808. case GTU:
  2809. case LTU:
  2810. /* Jump becomes no-op. */
  2811. return -1;
  2812. case GE:
  2813. PUT_CODE (cond, EQ);
  2814. value = 2;
  2815. break;
  2816. case LT:
  2817. PUT_CODE (cond, NE);
  2818. value = 2;
  2819. break;
  2820. default:
  2821. break;
  2822. }
  2823. if (cc_status.flags & CC_NOT_NEGATIVE)
  2824. switch (GET_CODE (cond))
  2825. {
  2826. case GE:
  2827. case GEU:
  2828. /* Jump becomes unconditional. */
  2829. return 1;
  2830. case LT:
  2831. case LTU:
  2832. /* Jump becomes no-op. */
  2833. return -1;
  2834. case LE:
  2835. case LEU:
  2836. PUT_CODE (cond, EQ);
  2837. value = 2;
  2838. break;
  2839. case GT:
  2840. case GTU:
  2841. PUT_CODE (cond, NE);
  2842. value = 2;
  2843. break;
  2844. default:
  2845. break;
  2846. }
  2847. if (cc_status.flags & CC_NO_OVERFLOW)
  2848. switch (GET_CODE (cond))
  2849. {
  2850. case GEU:
  2851. /* Jump becomes unconditional. */
  2852. return 1;
  2853. case LEU:
  2854. PUT_CODE (cond, EQ);
  2855. value = 2;
  2856. break;
  2857. case GTU:
  2858. PUT_CODE (cond, NE);
  2859. value = 2;
  2860. break;
  2861. case LTU:
  2862. /* Jump becomes no-op. */
  2863. return -1;
  2864. default:
  2865. break;
  2866. }
  2867. if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
  2868. switch (GET_CODE (cond))
  2869. {
  2870. default:
  2871. gcc_unreachable ();
  2872. case NE:
  2873. PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
  2874. value = 2;
  2875. break;
  2876. case EQ:
  2877. PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
  2878. value = 2;
  2879. break;
  2880. }
  2881. if (cc_status.flags & CC_NOT_SIGNED)
  2882. /* The flags are valid if signed condition operators are converted
  2883. to unsigned. */
  2884. switch (GET_CODE (cond))
  2885. {
  2886. case LE:
  2887. PUT_CODE (cond, LEU);
  2888. value = 2;
  2889. break;
  2890. case LT:
  2891. PUT_CODE (cond, LTU);
  2892. value = 2;
  2893. break;
  2894. case GT:
  2895. PUT_CODE (cond, GTU);
  2896. value = 2;
  2897. break;
  2898. case GE:
  2899. PUT_CODE (cond, GEU);
  2900. value = 2;
  2901. break;
  2902. default:
  2903. break;
  2904. }
  2905. return value;
  2906. }
  2907. #endif
  2908. /* Report inconsistency between the assembler template and the operands.
  2909. In an `asm', it's the user's fault; otherwise, the compiler's fault. */
  2910. void
  2911. output_operand_lossage (const char *cmsgid, ...)
  2912. {
  2913. char *fmt_string;
  2914. char *new_message;
  2915. const char *pfx_str;
  2916. va_list ap;
  2917. va_start (ap, cmsgid);
  2918. pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
  2919. fmt_string = xasprintf ("%s%s", pfx_str, _(cmsgid));
  2920. new_message = xvasprintf (fmt_string, ap);
  2921. if (this_is_asm_operands)
  2922. error_for_asm (this_is_asm_operands, "%s", new_message);
  2923. else
  2924. internal_error ("%s", new_message);
  2925. free (fmt_string);
  2926. free (new_message);
  2927. va_end (ap);
  2928. }
  2929. /* Output of assembler code from a template, and its subroutines. */
  2930. /* Annotate the assembly with a comment describing the pattern and
  2931. alternative used. */
  2932. static void
  2933. output_asm_name (void)
  2934. {
  2935. if (debug_insn)
  2936. {
  2937. int num = INSN_CODE (debug_insn);
  2938. fprintf (asm_out_file, "\t%s %d\t%s",
  2939. ASM_COMMENT_START, INSN_UID (debug_insn),
  2940. insn_data[num].name);
  2941. if (insn_data[num].n_alternatives > 1)
  2942. fprintf (asm_out_file, "/%d", which_alternative + 1);
  2943. if (HAVE_ATTR_length)
  2944. fprintf (asm_out_file, "\t[length = %d]",
  2945. get_attr_length (debug_insn));
  2946. /* Clear this so only the first assembler insn
  2947. of any rtl insn will get the special comment for -dp. */
  2948. debug_insn = 0;
  2949. }
  2950. }
  2951. /* If OP is a REG or MEM and we can find a MEM_EXPR corresponding to it
  2952. or its address, return that expr . Set *PADDRESSP to 1 if the expr
  2953. corresponds to the address of the object and 0 if to the object. */
  2954. static tree
  2955. get_mem_expr_from_op (rtx op, int *paddressp)
  2956. {
  2957. tree expr;
  2958. int inner_addressp;
  2959. *paddressp = 0;
  2960. if (REG_P (op))
  2961. return REG_EXPR (op);
  2962. else if (!MEM_P (op))
  2963. return 0;
  2964. if (MEM_EXPR (op) != 0)
  2965. return MEM_EXPR (op);
  2966. /* Otherwise we have an address, so indicate it and look at the address. */
  2967. *paddressp = 1;
  2968. op = XEXP (op, 0);
  2969. /* First check if we have a decl for the address, then look at the right side
  2970. if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
  2971. But don't allow the address to itself be indirect. */
  2972. if ((expr = get_mem_expr_from_op (op, &inner_addressp)) && ! inner_addressp)
  2973. return expr;
  2974. else if (GET_CODE (op) == PLUS
  2975. && (expr = get_mem_expr_from_op (XEXP (op, 1), &inner_addressp)))
  2976. return expr;
  2977. while (UNARY_P (op)
  2978. || GET_RTX_CLASS (GET_CODE (op)) == RTX_BIN_ARITH)
  2979. op = XEXP (op, 0);
  2980. expr = get_mem_expr_from_op (op, &inner_addressp);
  2981. return inner_addressp ? 0 : expr;
  2982. }
  2983. /* Output operand names for assembler instructions. OPERANDS is the
  2984. operand vector, OPORDER is the order to write the operands, and NOPS
  2985. is the number of operands to write. */
  2986. static void
  2987. output_asm_operand_names (rtx *operands, int *oporder, int nops)
  2988. {
  2989. int wrote = 0;
  2990. int i;
  2991. for (i = 0; i < nops; i++)
  2992. {
  2993. int addressp;
  2994. rtx op = operands[oporder[i]];
  2995. tree expr = get_mem_expr_from_op (op, &addressp);
  2996. fprintf (asm_out_file, "%c%s",
  2997. wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START);
  2998. wrote = 1;
  2999. if (expr)
  3000. {
  3001. fprintf (asm_out_file, "%s",
  3002. addressp ? "*" : "");
  3003. print_mem_expr (asm_out_file, expr);
  3004. wrote = 1;
  3005. }
  3006. else if (REG_P (op) && ORIGINAL_REGNO (op)
  3007. && ORIGINAL_REGNO (op) != REGNO (op))
  3008. fprintf (asm_out_file, " tmp%i", ORIGINAL_REGNO (op));
  3009. }
  3010. }
  3011. #ifdef ASSEMBLER_DIALECT
  3012. /* Helper function to parse assembler dialects in the asm string.
  3013. This is called from output_asm_insn and asm_fprintf. */
  3014. static const char *
  3015. do_assembler_dialects (const char *p, int *dialect)
  3016. {
  3017. char c = *(p - 1);
  3018. switch (c)
  3019. {
  3020. case '{':
  3021. {
  3022. int i;
  3023. if (*dialect)
  3024. output_operand_lossage ("nested assembly dialect alternatives");
  3025. else
  3026. *dialect = 1;
  3027. /* If we want the first dialect, do nothing. Otherwise, skip
  3028. DIALECT_NUMBER of strings ending with '|'. */
  3029. for (i = 0; i < dialect_number; i++)
  3030. {
  3031. while (*p && *p != '}')
  3032. {
  3033. if (*p == '|')
  3034. {
  3035. p++;
  3036. break;
  3037. }
  3038. /* Skip over any character after a percent sign. */
  3039. if (*p == '%')
  3040. p++;
  3041. if (*p)
  3042. p++;
  3043. }
  3044. if (*p == '}')
  3045. break;
  3046. }
  3047. if (*p == '\0')
  3048. output_operand_lossage ("unterminated assembly dialect alternative");
  3049. }
  3050. break;
  3051. case '|':
  3052. if (*dialect)
  3053. {
  3054. /* Skip to close brace. */
  3055. do
  3056. {
  3057. if (*p == '\0')
  3058. {
  3059. output_operand_lossage ("unterminated assembly dialect alternative");
  3060. break;
  3061. }
  3062. /* Skip over any character after a percent sign. */
  3063. if (*p == '%' && p[1])
  3064. {
  3065. p += 2;
  3066. continue;
  3067. }
  3068. if (*p++ == '}')
  3069. break;
  3070. }
  3071. while (1);
  3072. *dialect = 0;
  3073. }
  3074. else
  3075. putc (c, asm_out_file);
  3076. break;
  3077. case '}':
  3078. if (! *dialect)
  3079. putc (c, asm_out_file);
  3080. *dialect = 0;
  3081. break;
  3082. default:
  3083. gcc_unreachable ();
  3084. }
  3085. return p;
  3086. }
  3087. #endif
  3088. /* Output text from TEMPLATE to the assembler output file,
  3089. obeying %-directions to substitute operands taken from
  3090. the vector OPERANDS.
  3091. %N (for N a digit) means print operand N in usual manner.
  3092. %lN means require operand N to be a CODE_LABEL or LABEL_REF
  3093. and print the label name with no punctuation.
  3094. %cN means require operand N to be a constant
  3095. and print the constant expression with no punctuation.
  3096. %aN means expect operand N to be a memory address
  3097. (not a memory reference!) and print a reference
  3098. to that address.
  3099. %nN means expect operand N to be a constant
  3100. and print a constant expression for minus the value
  3101. of the operand, with no other punctuation. */
  3102. void
  3103. output_asm_insn (const char *templ, rtx *operands)
  3104. {
  3105. const char *p;
  3106. int c;
  3107. #ifdef ASSEMBLER_DIALECT
  3108. int dialect = 0;
  3109. #endif
  3110. int oporder[MAX_RECOG_OPERANDS];
  3111. char opoutput[MAX_RECOG_OPERANDS];
  3112. int ops = 0;
  3113. /* An insn may return a null string template
  3114. in a case where no assembler code is needed. */
  3115. if (*templ == 0)
  3116. return;
  3117. memset (opoutput, 0, sizeof opoutput);
  3118. p = templ;
  3119. putc ('\t', asm_out_file);
  3120. #ifdef ASM_OUTPUT_OPCODE
  3121. ASM_OUTPUT_OPCODE (asm_out_file, p);
  3122. #endif
  3123. while ((c = *p++))
  3124. switch (c)
  3125. {
  3126. case '\n':
  3127. if (flag_verbose_asm)
  3128. output_asm_operand_names (operands, oporder, ops);
  3129. if (flag_print_asm_name)
  3130. output_asm_name ();
  3131. ops = 0;
  3132. memset (opoutput, 0, sizeof opoutput);
  3133. putc (c, asm_out_file);
  3134. #ifdef ASM_OUTPUT_OPCODE
  3135. while ((c = *p) == '\t')
  3136. {
  3137. putc (c, asm_out_file);
  3138. p++;
  3139. }
  3140. ASM_OUTPUT_OPCODE (asm_out_file, p);
  3141. #endif
  3142. break;
  3143. #ifdef ASSEMBLER_DIALECT
  3144. case '{':
  3145. case '}':
  3146. case '|':
  3147. p = do_assembler_dialects (p, &dialect);
  3148. break;
  3149. #endif
  3150. case '%':
  3151. /* %% outputs a single %. %{, %} and %| print {, } and | respectively
  3152. if ASSEMBLER_DIALECT defined and these characters have a special
  3153. meaning as dialect delimiters.*/
  3154. if (*p == '%'
  3155. #ifdef ASSEMBLER_DIALECT
  3156. || *p == '{' || *p == '}' || *p == '|'
  3157. #endif
  3158. )
  3159. {
  3160. putc (*p, asm_out_file);
  3161. p++;
  3162. }
  3163. /* %= outputs a number which is unique to each insn in the entire
  3164. compilation. This is useful for making local labels that are
  3165. referred to more than once in a given insn. */
  3166. else if (*p == '=')
  3167. {
  3168. p++;
  3169. fprintf (asm_out_file, "%d", insn_counter);
  3170. }
  3171. /* % followed by a letter and some digits
  3172. outputs an operand in a special way depending on the letter.
  3173. Letters `acln' are implemented directly.
  3174. Other letters are passed to `output_operand' so that
  3175. the TARGET_PRINT_OPERAND hook can define them. */
  3176. else if (ISALPHA (*p))
  3177. {
  3178. int letter = *p++;
  3179. unsigned long opnum;
  3180. char *endptr;
  3181. opnum = strtoul (p, &endptr, 10);
  3182. if (endptr == p)
  3183. output_operand_lossage ("operand number missing "
  3184. "after %%-letter");
  3185. else if (this_is_asm_operands && opnum >= insn_noperands)
  3186. output_operand_lossage ("operand number out of range");
  3187. else if (letter == 'l')
  3188. output_asm_label (operands[opnum]);
  3189. else if (letter == 'a')
  3190. output_address (operands[opnum]);
  3191. else if (letter == 'c')
  3192. {
  3193. if (CONSTANT_ADDRESS_P (operands[opnum]))
  3194. output_addr_const (asm_out_file, operands[opnum]);
  3195. else
  3196. output_operand (operands[opnum], 'c');
  3197. }
  3198. else if (letter == 'n')
  3199. {
  3200. if (CONST_INT_P (operands[opnum]))
  3201. fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
  3202. - INTVAL (operands[opnum]));
  3203. else
  3204. {
  3205. putc ('-', asm_out_file);
  3206. output_addr_const (asm_out_file, operands[opnum]);
  3207. }
  3208. }
  3209. else
  3210. output_operand (operands[opnum], letter);
  3211. if (!opoutput[opnum])
  3212. oporder[ops++] = opnum;
  3213. opoutput[opnum] = 1;
  3214. p = endptr;
  3215. c = *p;
  3216. }
  3217. /* % followed by a digit outputs an operand the default way. */
  3218. else if (ISDIGIT (*p))
  3219. {
  3220. unsigned long opnum;
  3221. char *endptr;
  3222. opnum = strtoul (p, &endptr, 10);
  3223. if (this_is_asm_operands && opnum >= insn_noperands)
  3224. output_operand_lossage ("operand number out of range");
  3225. else
  3226. output_operand (operands[opnum], 0);
  3227. if (!opoutput[opnum])
  3228. oporder[ops++] = opnum;
  3229. opoutput[opnum] = 1;
  3230. p = endptr;
  3231. c = *p;
  3232. }
  3233. /* % followed by punctuation: output something for that
  3234. punctuation character alone, with no operand. The
  3235. TARGET_PRINT_OPERAND hook decides what is actually done. */
  3236. else if (targetm.asm_out.print_operand_punct_valid_p ((unsigned char) *p))
  3237. output_operand (NULL_RTX, *p++);
  3238. else
  3239. output_operand_lossage ("invalid %%-code");
  3240. break;
  3241. default:
  3242. putc (c, asm_out_file);
  3243. }
  3244. /* Write out the variable names for operands, if we know them. */
  3245. if (flag_verbose_asm)
  3246. output_asm_operand_names (operands, oporder, ops);
  3247. if (flag_print_asm_name)
  3248. output_asm_name ();
  3249. putc ('\n', asm_out_file);
  3250. }
  3251. /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
  3252. void
  3253. output_asm_label (rtx x)
  3254. {
  3255. char buf[256];
  3256. if (GET_CODE (x) == LABEL_REF)
  3257. x = LABEL_REF_LABEL (x);
  3258. if (LABEL_P (x)
  3259. || (NOTE_P (x)
  3260. && NOTE_KIND (x) == NOTE_INSN_DELETED_LABEL))
  3261. ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  3262. else
  3263. output_operand_lossage ("'%%l' operand isn't a label");
  3264. assemble_name (asm_out_file, buf);
  3265. }
  3266. /* Marks SYMBOL_REFs in x as referenced through use of assemble_external. */
  3267. void
  3268. mark_symbol_refs_as_used (rtx x)
  3269. {
  3270. subrtx_iterator::array_type array;
  3271. FOR_EACH_SUBRTX (iter, array, x, ALL)
  3272. {
  3273. const_rtx x = *iter;
  3274. if (GET_CODE (x) == SYMBOL_REF)
  3275. if (tree t = SYMBOL_REF_DECL (x))
  3276. assemble_external (t);
  3277. }
  3278. }
  3279. /* Print operand X using machine-dependent assembler syntax.
  3280. CODE is a non-digit that preceded the operand-number in the % spec,
  3281. such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
  3282. between the % and the digits.
  3283. When CODE is a non-letter, X is 0.
  3284. The meanings of the letters are machine-dependent and controlled
  3285. by TARGET_PRINT_OPERAND. */
  3286. void
  3287. output_operand (rtx x, int code ATTRIBUTE_UNUSED)
  3288. {
  3289. if (x && GET_CODE (x) == SUBREG)
  3290. x = alter_subreg (&x, true);
  3291. /* X must not be a pseudo reg. */
  3292. if (!targetm.no_register_allocation)
  3293. gcc_assert (!x || !REG_P (x) || REGNO (x) < FIRST_PSEUDO_REGISTER);
  3294. targetm.asm_out.print_operand (asm_out_file, x, code);
  3295. if (x == NULL_RTX)
  3296. return;
  3297. mark_symbol_refs_as_used (x);
  3298. }
  3299. /* Print a memory reference operand for address X using
  3300. machine-dependent assembler syntax. */
  3301. void
  3302. output_address (rtx x)
  3303. {
  3304. bool changed = false;
  3305. walk_alter_subreg (&x, &changed);
  3306. targetm.asm_out.print_operand_address (asm_out_file, x);
  3307. }
  3308. /* Print an integer constant expression in assembler syntax.
  3309. Addition and subtraction are the only arithmetic
  3310. that may appear in these expressions. */
  3311. void
  3312. output_addr_const (FILE *file, rtx x)
  3313. {
  3314. char buf[256];
  3315. restart:
  3316. switch (GET_CODE (x))
  3317. {
  3318. case PC:
  3319. putc ('.', file);
  3320. break;
  3321. case SYMBOL_REF:
  3322. if (SYMBOL_REF_DECL (x))
  3323. assemble_external (SYMBOL_REF_DECL (x));
  3324. #ifdef ASM_OUTPUT_SYMBOL_REF
  3325. ASM_OUTPUT_SYMBOL_REF (file, x);
  3326. #else
  3327. assemble_name (file, XSTR (x, 0));
  3328. #endif
  3329. break;
  3330. case LABEL_REF:
  3331. x = LABEL_REF_LABEL (x);
  3332. /* Fall through. */
  3333. case CODE_LABEL:
  3334. ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  3335. #ifdef ASM_OUTPUT_LABEL_REF
  3336. ASM_OUTPUT_LABEL_REF (file, buf);
  3337. #else
  3338. assemble_name (file, buf);
  3339. #endif
  3340. break;
  3341. case CONST_INT:
  3342. fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
  3343. break;
  3344. case CONST:
  3345. /* This used to output parentheses around the expression,
  3346. but that does not work on the 386 (either ATT or BSD assembler). */
  3347. output_addr_const (file, XEXP (x, 0));
  3348. break;
  3349. case CONST_WIDE_INT:
  3350. /* We do not know the mode here so we have to use a round about
  3351. way to build a wide-int to get it printed properly. */
  3352. {
  3353. wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0),
  3354. CONST_WIDE_INT_NUNITS (x),
  3355. CONST_WIDE_INT_NUNITS (x)
  3356. * HOST_BITS_PER_WIDE_INT,
  3357. false);
  3358. print_decs (w, file);
  3359. }
  3360. break;
  3361. case CONST_DOUBLE:
  3362. if (CONST_DOUBLE_AS_INT_P (x))
  3363. {
  3364. /* We can use %d if the number is one word and positive. */
  3365. if (CONST_DOUBLE_HIGH (x))
  3366. fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
  3367. (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x),
  3368. (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
  3369. else if (CONST_DOUBLE_LOW (x) < 0)
  3370. fprintf (file, HOST_WIDE_INT_PRINT_HEX,
  3371. (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
  3372. else
  3373. fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
  3374. }
  3375. else
  3376. /* We can't handle floating point constants;
  3377. PRINT_OPERAND must handle them. */
  3378. output_operand_lossage ("floating constant misused");
  3379. break;
  3380. case CONST_FIXED:
  3381. fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x));
  3382. break;
  3383. case PLUS:
  3384. /* Some assemblers need integer constants to appear last (eg masm). */
  3385. if (CONST_INT_P (XEXP (x, 0)))
  3386. {
  3387. output_addr_const (file, XEXP (x, 1));
  3388. if (INTVAL (XEXP (x, 0)) >= 0)
  3389. fprintf (file, "+");
  3390. output_addr_const (file, XEXP (x, 0));
  3391. }
  3392. else
  3393. {
  3394. output_addr_const (file, XEXP (x, 0));
  3395. if (!CONST_INT_P (XEXP (x, 1))
  3396. || INTVAL (XEXP (x, 1)) >= 0)
  3397. fprintf (file, "+");
  3398. output_addr_const (file, XEXP (x, 1));
  3399. }
  3400. break;
  3401. case MINUS:
  3402. /* Avoid outputting things like x-x or x+5-x,
  3403. since some assemblers can't handle that. */
  3404. x = simplify_subtraction (x);
  3405. if (GET_CODE (x) != MINUS)
  3406. goto restart;
  3407. output_addr_const (file, XEXP (x, 0));
  3408. fprintf (file, "-");
  3409. if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0)
  3410. || GET_CODE (XEXP (x, 1)) == PC
  3411. || GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
  3412. output_addr_const (file, XEXP (x, 1));
  3413. else
  3414. {
  3415. fputs (targetm.asm_out.open_paren, file);
  3416. output_addr_const (file, XEXP (x, 1));
  3417. fputs (targetm.asm_out.close_paren, file);
  3418. }
  3419. break;
  3420. case ZERO_EXTEND:
  3421. case SIGN_EXTEND:
  3422. case SUBREG:
  3423. case TRUNCATE:
  3424. output_addr_const (file, XEXP (x, 0));
  3425. break;
  3426. default:
  3427. if (targetm.asm_out.output_addr_const_extra (file, x))
  3428. break;
  3429. output_operand_lossage ("invalid expression as operand");
  3430. }
  3431. }
  3432. /* Output a quoted string. */
  3433. void
  3434. output_quoted_string (FILE *asm_file, const char *string)
  3435. {
  3436. #ifdef OUTPUT_QUOTED_STRING
  3437. OUTPUT_QUOTED_STRING (asm_file, string);
  3438. #else
  3439. char c;
  3440. putc ('\"', asm_file);
  3441. while ((c = *string++) != 0)
  3442. {
  3443. if (ISPRINT (c))
  3444. {
  3445. if (c == '\"' || c == '\\')
  3446. putc ('\\', asm_file);
  3447. putc (c, asm_file);
  3448. }
  3449. else
  3450. fprintf (asm_file, "\\%03o", (unsigned char) c);
  3451. }
  3452. putc ('\"', asm_file);
  3453. #endif
  3454. }
  3455. /* Write a HOST_WIDE_INT number in hex form 0x1234, fast. */
  3456. void
  3457. fprint_whex (FILE *f, unsigned HOST_WIDE_INT value)
  3458. {
  3459. char buf[2 + CHAR_BIT * sizeof (value) / 4];
  3460. if (value == 0)
  3461. putc ('0', f);
  3462. else
  3463. {
  3464. char *p = buf + sizeof (buf);
  3465. do
  3466. *--p = "0123456789abcdef"[value % 16];
  3467. while ((value /= 16) != 0);
  3468. *--p = 'x';
  3469. *--p = '0';
  3470. fwrite (p, 1, buf + sizeof (buf) - p, f);
  3471. }
  3472. }
  3473. /* Internal function that prints an unsigned long in decimal in reverse.
  3474. The output string IS NOT null-terminated. */
  3475. static int
  3476. sprint_ul_rev (char *s, unsigned long value)
  3477. {
  3478. int i = 0;
  3479. do
  3480. {
  3481. s[i] = "0123456789"[value % 10];
  3482. value /= 10;
  3483. i++;
  3484. /* alternate version, without modulo */
  3485. /* oldval = value; */
  3486. /* value /= 10; */
  3487. /* s[i] = "0123456789" [oldval - 10*value]; */
  3488. /* i++ */
  3489. }
  3490. while (value != 0);
  3491. return i;
  3492. }
  3493. /* Write an unsigned long as decimal to a file, fast. */
  3494. void
  3495. fprint_ul (FILE *f, unsigned long value)
  3496. {
  3497. /* python says: len(str(2**64)) == 20 */
  3498. char s[20];
  3499. int i;
  3500. i = sprint_ul_rev (s, value);
  3501. /* It's probably too small to bother with string reversal and fputs. */
  3502. do
  3503. {
  3504. i--;
  3505. putc (s[i], f);
  3506. }
  3507. while (i != 0);
  3508. }
  3509. /* Write an unsigned long as decimal to a string, fast.
  3510. s must be wide enough to not overflow, at least 21 chars.
  3511. Returns the length of the string (without terminating '\0'). */
  3512. int
  3513. sprint_ul (char *s, unsigned long value)
  3514. {
  3515. int len;
  3516. char tmp_c;
  3517. int i;
  3518. int j;
  3519. len = sprint_ul_rev (s, value);
  3520. s[len] = '\0';
  3521. /* Reverse the string. */
  3522. i = 0;
  3523. j = len - 1;
  3524. while (i < j)
  3525. {
  3526. tmp_c = s[i];
  3527. s[i] = s[j];
  3528. s[j] = tmp_c;
  3529. i++; j--;
  3530. }
  3531. return len;
  3532. }
  3533. /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
  3534. %R prints the value of REGISTER_PREFIX.
  3535. %L prints the value of LOCAL_LABEL_PREFIX.
  3536. %U prints the value of USER_LABEL_PREFIX.
  3537. %I prints the value of IMMEDIATE_PREFIX.
  3538. %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
  3539. Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
  3540. We handle alternate assembler dialects here, just like output_asm_insn. */
  3541. void
  3542. asm_fprintf (FILE *file, const char *p, ...)
  3543. {
  3544. char buf[10];
  3545. char *q, c;
  3546. #ifdef ASSEMBLER_DIALECT
  3547. int dialect = 0;
  3548. #endif
  3549. va_list argptr;
  3550. va_start (argptr, p);
  3551. buf[0] = '%';
  3552. while ((c = *p++))
  3553. switch (c)
  3554. {
  3555. #ifdef ASSEMBLER_DIALECT
  3556. case '{':
  3557. case '}':
  3558. case '|':
  3559. p = do_assembler_dialects (p, &dialect);
  3560. break;
  3561. #endif
  3562. case '%':
  3563. c = *p++;
  3564. q = &buf[1];
  3565. while (strchr ("-+ #0", c))
  3566. {
  3567. *q++ = c;
  3568. c = *p++;
  3569. }
  3570. while (ISDIGIT (c) || c == '.')
  3571. {
  3572. *q++ = c;
  3573. c = *p++;
  3574. }
  3575. switch (c)
  3576. {
  3577. case '%':
  3578. putc ('%', file);
  3579. break;
  3580. case 'd': case 'i': case 'u':
  3581. case 'x': case 'X': case 'o':
  3582. case 'c':
  3583. *q++ = c;
  3584. *q = 0;
  3585. fprintf (file, buf, va_arg (argptr, int));
  3586. break;
  3587. case 'w':
  3588. /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
  3589. 'o' cases, but we do not check for those cases. It
  3590. means that the value is a HOST_WIDE_INT, which may be
  3591. either `long' or `long long'. */
  3592. memcpy (q, HOST_WIDE_INT_PRINT, strlen (HOST_WIDE_INT_PRINT));
  3593. q += strlen (HOST_WIDE_INT_PRINT);
  3594. *q++ = *p++;
  3595. *q = 0;
  3596. fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
  3597. break;
  3598. case 'l':
  3599. *q++ = c;
  3600. #ifdef HAVE_LONG_LONG
  3601. if (*p == 'l')
  3602. {
  3603. *q++ = *p++;
  3604. *q++ = *p++;
  3605. *q = 0;
  3606. fprintf (file, buf, va_arg (argptr, long long));
  3607. }
  3608. else
  3609. #endif
  3610. {
  3611. *q++ = *p++;
  3612. *q = 0;
  3613. fprintf (file, buf, va_arg (argptr, long));
  3614. }
  3615. break;
  3616. case 's':
  3617. *q++ = c;
  3618. *q = 0;
  3619. fprintf (file, buf, va_arg (argptr, char *));
  3620. break;
  3621. case 'O':
  3622. #ifdef ASM_OUTPUT_OPCODE
  3623. ASM_OUTPUT_OPCODE (asm_out_file, p);
  3624. #endif
  3625. break;
  3626. case 'R':
  3627. #ifdef REGISTER_PREFIX
  3628. fprintf (file, "%s", REGISTER_PREFIX);
  3629. #endif
  3630. break;
  3631. case 'I':
  3632. #ifdef IMMEDIATE_PREFIX
  3633. fprintf (file, "%s", IMMEDIATE_PREFIX);
  3634. #endif
  3635. break;
  3636. case 'L':
  3637. #ifdef LOCAL_LABEL_PREFIX
  3638. fprintf (file, "%s", LOCAL_LABEL_PREFIX);
  3639. #endif
  3640. break;
  3641. case 'U':
  3642. fputs (user_label_prefix, file);
  3643. break;
  3644. #ifdef ASM_FPRINTF_EXTENSIONS
  3645. /* Uppercase letters are reserved for general use by asm_fprintf
  3646. and so are not available to target specific code. In order to
  3647. prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
  3648. they are defined here. As they get turned into real extensions
  3649. to asm_fprintf they should be removed from this list. */
  3650. case 'A': case 'B': case 'C': case 'D': case 'E':
  3651. case 'F': case 'G': case 'H': case 'J': case 'K':
  3652. case 'M': case 'N': case 'P': case 'Q': case 'S':
  3653. case 'T': case 'V': case 'W': case 'Y': case 'Z':
  3654. break;
  3655. ASM_FPRINTF_EXTENSIONS (file, argptr, p)
  3656. #endif
  3657. default:
  3658. gcc_unreachable ();
  3659. }
  3660. break;
  3661. default:
  3662. putc (c, file);
  3663. }
  3664. va_end (argptr);
  3665. }
  3666. /* Return nonzero if this function has no function calls. */
  3667. int
  3668. leaf_function_p (void)
  3669. {
  3670. rtx_insn *insn;
  3671. /* Some back-ends (e.g. s390) want leaf functions to stay leaf
  3672. functions even if they call mcount. */
  3673. if (crtl->profile && !targetm.keep_leaf_when_profiled ())
  3674. return 0;
  3675. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  3676. {
  3677. if (CALL_P (insn)
  3678. && ! SIBLING_CALL_P (insn))
  3679. return 0;
  3680. if (NONJUMP_INSN_P (insn)
  3681. && GET_CODE (PATTERN (insn)) == SEQUENCE
  3682. && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
  3683. && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
  3684. return 0;
  3685. }
  3686. return 1;
  3687. }
  3688. /* Return 1 if branch is a forward branch.
  3689. Uses insn_shuid array, so it works only in the final pass. May be used by
  3690. output templates to customary add branch prediction hints.
  3691. */
  3692. int
  3693. final_forward_branch_p (rtx_insn *insn)
  3694. {
  3695. int insn_id, label_id;
  3696. gcc_assert (uid_shuid);
  3697. insn_id = INSN_SHUID (insn);
  3698. label_id = INSN_SHUID (JUMP_LABEL (insn));
  3699. /* We've hit some insns that does not have id information available. */
  3700. gcc_assert (insn_id && label_id);
  3701. return insn_id < label_id;
  3702. }
  3703. /* On some machines, a function with no call insns
  3704. can run faster if it doesn't create its own register window.
  3705. When output, the leaf function should use only the "output"
  3706. registers. Ordinarily, the function would be compiled to use
  3707. the "input" registers to find its arguments; it is a candidate
  3708. for leaf treatment if it uses only the "input" registers.
  3709. Leaf function treatment means renumbering so the function
  3710. uses the "output" registers instead. */
  3711. #ifdef LEAF_REGISTERS
  3712. /* Return 1 if this function uses only the registers that can be
  3713. safely renumbered. */
  3714. int
  3715. only_leaf_regs_used (void)
  3716. {
  3717. int i;
  3718. const char *const permitted_reg_in_leaf_functions = LEAF_REGISTERS;
  3719. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3720. if ((df_regs_ever_live_p (i) || global_regs[i])
  3721. && ! permitted_reg_in_leaf_functions[i])
  3722. return 0;
  3723. if (crtl->uses_pic_offset_table
  3724. && pic_offset_table_rtx != 0
  3725. && REG_P (pic_offset_table_rtx)
  3726. && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
  3727. return 0;
  3728. return 1;
  3729. }
  3730. /* Scan all instructions and renumber all registers into those
  3731. available in leaf functions. */
  3732. static void
  3733. leaf_renumber_regs (rtx_insn *first)
  3734. {
  3735. rtx_insn *insn;
  3736. /* Renumber only the actual patterns.
  3737. The reg-notes can contain frame pointer refs,
  3738. and renumbering them could crash, and should not be needed. */
  3739. for (insn = first; insn; insn = NEXT_INSN (insn))
  3740. if (INSN_P (insn))
  3741. leaf_renumber_regs_insn (PATTERN (insn));
  3742. }
  3743. /* Scan IN_RTX and its subexpressions, and renumber all regs into those
  3744. available in leaf functions. */
  3745. void
  3746. leaf_renumber_regs_insn (rtx in_rtx)
  3747. {
  3748. int i, j;
  3749. const char *format_ptr;
  3750. if (in_rtx == 0)
  3751. return;
  3752. /* Renumber all input-registers into output-registers.
  3753. renumbered_regs would be 1 for an output-register;
  3754. they */
  3755. if (REG_P (in_rtx))
  3756. {
  3757. int newreg;
  3758. /* Don't renumber the same reg twice. */
  3759. if (in_rtx->used)
  3760. return;
  3761. newreg = REGNO (in_rtx);
  3762. /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
  3763. to reach here as part of a REG_NOTE. */
  3764. if (newreg >= FIRST_PSEUDO_REGISTER)
  3765. {
  3766. in_rtx->used = 1;
  3767. return;
  3768. }
  3769. newreg = LEAF_REG_REMAP (newreg);
  3770. gcc_assert (newreg >= 0);
  3771. df_set_regs_ever_live (REGNO (in_rtx), false);
  3772. df_set_regs_ever_live (newreg, true);
  3773. SET_REGNO (in_rtx, newreg);
  3774. in_rtx->used = 1;
  3775. }
  3776. if (INSN_P (in_rtx))
  3777. {
  3778. /* Inside a SEQUENCE, we find insns.
  3779. Renumber just the patterns of these insns,
  3780. just as we do for the top-level insns. */
  3781. leaf_renumber_regs_insn (PATTERN (in_rtx));
  3782. return;
  3783. }
  3784. format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
  3785. for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
  3786. switch (*format_ptr++)
  3787. {
  3788. case 'e':
  3789. leaf_renumber_regs_insn (XEXP (in_rtx, i));
  3790. break;
  3791. case 'E':
  3792. if (NULL != XVEC (in_rtx, i))
  3793. {
  3794. for (j = 0; j < XVECLEN (in_rtx, i); j++)
  3795. leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
  3796. }
  3797. break;
  3798. case 'S':
  3799. case 's':
  3800. case '0':
  3801. case 'i':
  3802. case 'w':
  3803. case 'n':
  3804. case 'u':
  3805. break;
  3806. default:
  3807. gcc_unreachable ();
  3808. }
  3809. }
  3810. #endif
  3811. /* Turn the RTL into assembly. */
  3812. static unsigned int
  3813. rest_of_handle_final (void)
  3814. {
  3815. const char *fnname = get_fnname_from_decl (current_function_decl);
  3816. assemble_start_function (current_function_decl, fnname);
  3817. final_start_function (get_insns (), asm_out_file, optimize);
  3818. final (get_insns (), asm_out_file, optimize);
  3819. if (flag_ipa_ra)
  3820. collect_fn_hard_reg_usage ();
  3821. final_end_function ();
  3822. /* The IA-64 ".handlerdata" directive must be issued before the ".endp"
  3823. directive that closes the procedure descriptor. Similarly, for x64 SEH.
  3824. Otherwise it's not strictly necessary, but it doesn't hurt either. */
  3825. output_function_exception_table (fnname);
  3826. assemble_end_function (current_function_decl, fnname);
  3827. user_defined_section_attribute = false;
  3828. /* Free up reg info memory. */
  3829. free_reg_info ();
  3830. if (! quiet_flag)
  3831. fflush (asm_out_file);
  3832. /* Write DBX symbols if requested. */
  3833. /* Note that for those inline functions where we don't initially
  3834. know for certain that we will be generating an out-of-line copy,
  3835. the first invocation of this routine (rest_of_compilation) will
  3836. skip over this code by doing a `goto exit_rest_of_compilation;'.
  3837. Later on, wrapup_global_declarations will (indirectly) call
  3838. rest_of_compilation again for those inline functions that need
  3839. to have out-of-line copies generated. During that call, we
  3840. *will* be routed past here. */
  3841. timevar_push (TV_SYMOUT);
  3842. if (!DECL_IGNORED_P (current_function_decl))
  3843. debug_hooks->function_decl (current_function_decl);
  3844. timevar_pop (TV_SYMOUT);
  3845. /* Release the blocks that are linked to DECL_INITIAL() to free the memory. */
  3846. DECL_INITIAL (current_function_decl) = error_mark_node;
  3847. if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
  3848. && targetm.have_ctors_dtors)
  3849. targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
  3850. decl_init_priority_lookup
  3851. (current_function_decl));
  3852. if (DECL_STATIC_DESTRUCTOR (current_function_decl)
  3853. && targetm.have_ctors_dtors)
  3854. targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
  3855. decl_fini_priority_lookup
  3856. (current_function_decl));
  3857. return 0;
  3858. }
  3859. namespace {
  3860. const pass_data pass_data_final =
  3861. {
  3862. RTL_PASS, /* type */
  3863. "final", /* name */
  3864. OPTGROUP_NONE, /* optinfo_flags */
  3865. TV_FINAL, /* tv_id */
  3866. 0, /* properties_required */
  3867. 0, /* properties_provided */
  3868. 0, /* properties_destroyed */
  3869. 0, /* todo_flags_start */
  3870. 0, /* todo_flags_finish */
  3871. };
  3872. class pass_final : public rtl_opt_pass
  3873. {
  3874. public:
  3875. pass_final (gcc::context *ctxt)
  3876. : rtl_opt_pass (pass_data_final, ctxt)
  3877. {}
  3878. /* opt_pass methods: */
  3879. virtual unsigned int execute (function *) { return rest_of_handle_final (); }
  3880. }; // class pass_final
  3881. } // anon namespace
  3882. rtl_opt_pass *
  3883. make_pass_final (gcc::context *ctxt)
  3884. {
  3885. return new pass_final (ctxt);
  3886. }
  3887. static unsigned int
  3888. rest_of_handle_shorten_branches (void)
  3889. {
  3890. /* Shorten branches. */
  3891. shorten_branches (get_insns ());
  3892. return 0;
  3893. }
  3894. namespace {
  3895. const pass_data pass_data_shorten_branches =
  3896. {
  3897. RTL_PASS, /* type */
  3898. "shorten", /* name */
  3899. OPTGROUP_NONE, /* optinfo_flags */
  3900. TV_SHORTEN_BRANCH, /* tv_id */
  3901. 0, /* properties_required */
  3902. 0, /* properties_provided */
  3903. 0, /* properties_destroyed */
  3904. 0, /* todo_flags_start */
  3905. 0, /* todo_flags_finish */
  3906. };
  3907. class pass_shorten_branches : public rtl_opt_pass
  3908. {
  3909. public:
  3910. pass_shorten_branches (gcc::context *ctxt)
  3911. : rtl_opt_pass (pass_data_shorten_branches, ctxt)
  3912. {}
  3913. /* opt_pass methods: */
  3914. virtual unsigned int execute (function *)
  3915. {
  3916. return rest_of_handle_shorten_branches ();
  3917. }
  3918. }; // class pass_shorten_branches
  3919. } // anon namespace
  3920. rtl_opt_pass *
  3921. make_pass_shorten_branches (gcc::context *ctxt)
  3922. {
  3923. return new pass_shorten_branches (ctxt);
  3924. }
  3925. static unsigned int
  3926. rest_of_clean_state (void)
  3927. {
  3928. rtx_insn *insn, *next;
  3929. FILE *final_output = NULL;
  3930. int save_unnumbered = flag_dump_unnumbered;
  3931. int save_noaddr = flag_dump_noaddr;
  3932. if (flag_dump_final_insns)
  3933. {
  3934. final_output = fopen (flag_dump_final_insns, "a");
  3935. if (!final_output)
  3936. {
  3937. error ("could not open final insn dump file %qs: %m",
  3938. flag_dump_final_insns);
  3939. flag_dump_final_insns = NULL;
  3940. }
  3941. else
  3942. {
  3943. flag_dump_noaddr = flag_dump_unnumbered = 1;
  3944. if (flag_compare_debug_opt || flag_compare_debug)
  3945. dump_flags |= TDF_NOUID;
  3946. dump_function_header (final_output, current_function_decl,
  3947. dump_flags);
  3948. final_insns_dump_p = true;
  3949. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  3950. if (LABEL_P (insn))
  3951. INSN_UID (insn) = CODE_LABEL_NUMBER (insn);
  3952. else
  3953. {
  3954. if (NOTE_P (insn))
  3955. set_block_for_insn (insn, NULL);
  3956. INSN_UID (insn) = 0;
  3957. }
  3958. }
  3959. }
  3960. /* It is very important to decompose the RTL instruction chain here:
  3961. debug information keeps pointing into CODE_LABEL insns inside the function
  3962. body. If these remain pointing to the other insns, we end up preserving
  3963. whole RTL chain and attached detailed debug info in memory. */
  3964. for (insn = get_insns (); insn; insn = next)
  3965. {
  3966. next = NEXT_INSN (insn);
  3967. SET_NEXT_INSN (insn) = NULL;
  3968. SET_PREV_INSN (insn) = NULL;
  3969. if (final_output
  3970. && (!NOTE_P (insn) ||
  3971. (NOTE_KIND (insn) != NOTE_INSN_VAR_LOCATION
  3972. && NOTE_KIND (insn) != NOTE_INSN_CALL_ARG_LOCATION
  3973. && NOTE_KIND (insn) != NOTE_INSN_BLOCK_BEG
  3974. && NOTE_KIND (insn) != NOTE_INSN_BLOCK_END
  3975. && NOTE_KIND (insn) != NOTE_INSN_DELETED_DEBUG_LABEL)))
  3976. print_rtl_single (final_output, insn);
  3977. }
  3978. if (final_output)
  3979. {
  3980. flag_dump_noaddr = save_noaddr;
  3981. flag_dump_unnumbered = save_unnumbered;
  3982. final_insns_dump_p = false;
  3983. if (fclose (final_output))
  3984. {
  3985. error ("could not close final insn dump file %qs: %m",
  3986. flag_dump_final_insns);
  3987. flag_dump_final_insns = NULL;
  3988. }
  3989. }
  3990. /* In case the function was not output,
  3991. don't leave any temporary anonymous types
  3992. queued up for sdb output. */
  3993. #ifdef SDB_DEBUGGING_INFO
  3994. if (write_symbols == SDB_DEBUG)
  3995. sdbout_types (NULL_TREE);
  3996. #endif
  3997. flag_rerun_cse_after_global_opts = 0;
  3998. reload_completed = 0;
  3999. epilogue_completed = 0;
  4000. #ifdef STACK_REGS
  4001. regstack_completed = 0;
  4002. #endif
  4003. /* Clear out the insn_length contents now that they are no
  4004. longer valid. */
  4005. init_insn_lengths ();
  4006. /* Show no temporary slots allocated. */
  4007. init_temp_slots ();
  4008. free_bb_for_insn ();
  4009. delete_tree_ssa ();
  4010. /* We can reduce stack alignment on call site only when we are sure that
  4011. the function body just produced will be actually used in the final
  4012. executable. */
  4013. if (decl_binds_to_current_def_p (current_function_decl))
  4014. {
  4015. unsigned int pref = crtl->preferred_stack_boundary;
  4016. if (crtl->stack_alignment_needed > crtl->preferred_stack_boundary)
  4017. pref = crtl->stack_alignment_needed;
  4018. cgraph_node::rtl_info (current_function_decl)
  4019. ->preferred_incoming_stack_boundary = pref;
  4020. }
  4021. /* Make sure volatile mem refs aren't considered valid operands for
  4022. arithmetic insns. We must call this here if this is a nested inline
  4023. function, since the above code leaves us in the init_recog state,
  4024. and the function context push/pop code does not save/restore volatile_ok.
  4025. ??? Maybe it isn't necessary for expand_start_function to call this
  4026. anymore if we do it here? */
  4027. init_recog_no_volatile ();
  4028. /* We're done with this function. Free up memory if we can. */
  4029. free_after_parsing (cfun);
  4030. free_after_compilation (cfun);
  4031. return 0;
  4032. }
  4033. namespace {
  4034. const pass_data pass_data_clean_state =
  4035. {
  4036. RTL_PASS, /* type */
  4037. "*clean_state", /* name */
  4038. OPTGROUP_NONE, /* optinfo_flags */
  4039. TV_FINAL, /* tv_id */
  4040. 0, /* properties_required */
  4041. 0, /* properties_provided */
  4042. PROP_rtl, /* properties_destroyed */
  4043. 0, /* todo_flags_start */
  4044. 0, /* todo_flags_finish */
  4045. };
  4046. class pass_clean_state : public rtl_opt_pass
  4047. {
  4048. public:
  4049. pass_clean_state (gcc::context *ctxt)
  4050. : rtl_opt_pass (pass_data_clean_state, ctxt)
  4051. {}
  4052. /* opt_pass methods: */
  4053. virtual unsigned int execute (function *)
  4054. {
  4055. return rest_of_clean_state ();
  4056. }
  4057. }; // class pass_clean_state
  4058. } // anon namespace
  4059. rtl_opt_pass *
  4060. make_pass_clean_state (gcc::context *ctxt)
  4061. {
  4062. return new pass_clean_state (ctxt);
  4063. }
  4064. /* Return true if INSN is a call to the the current function. */
  4065. static bool
  4066. self_recursive_call_p (rtx_insn *insn)
  4067. {
  4068. tree fndecl = get_call_fndecl (insn);
  4069. return (fndecl == current_function_decl
  4070. && decl_binds_to_current_def_p (fndecl));
  4071. }
  4072. /* Collect hard register usage for the current function. */
  4073. static void
  4074. collect_fn_hard_reg_usage (void)
  4075. {
  4076. rtx_insn *insn;
  4077. #ifdef STACK_REGS
  4078. int i;
  4079. #endif
  4080. struct cgraph_rtl_info *node;
  4081. HARD_REG_SET function_used_regs;
  4082. /* ??? To be removed when all the ports have been fixed. */
  4083. if (!targetm.call_fusage_contains_non_callee_clobbers)
  4084. return;
  4085. CLEAR_HARD_REG_SET (function_used_regs);
  4086. for (insn = get_insns (); insn != NULL_RTX; insn = next_insn (insn))
  4087. {
  4088. HARD_REG_SET insn_used_regs;
  4089. if (!NONDEBUG_INSN_P (insn))
  4090. continue;
  4091. if (CALL_P (insn)
  4092. && !self_recursive_call_p (insn))
  4093. {
  4094. if (!get_call_reg_set_usage (insn, &insn_used_regs,
  4095. call_used_reg_set))
  4096. return;
  4097. IOR_HARD_REG_SET (function_used_regs, insn_used_regs);
  4098. }
  4099. find_all_hard_reg_sets (insn, &insn_used_regs, false);
  4100. IOR_HARD_REG_SET (function_used_regs, insn_used_regs);
  4101. }
  4102. /* Be conservative - mark fixed and global registers as used. */
  4103. IOR_HARD_REG_SET (function_used_regs, fixed_reg_set);
  4104. #ifdef STACK_REGS
  4105. /* Handle STACK_REGS conservatively, since the df-framework does not
  4106. provide accurate information for them. */
  4107. for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
  4108. SET_HARD_REG_BIT (function_used_regs, i);
  4109. #endif
  4110. /* The information we have gathered is only interesting if it exposes a
  4111. register from the call_used_regs that is not used in this function. */
  4112. if (hard_reg_set_subset_p (call_used_reg_set, function_used_regs))
  4113. return;
  4114. node = cgraph_node::rtl_info (current_function_decl);
  4115. gcc_assert (node != NULL);
  4116. COPY_HARD_REG_SET (node->function_used_regs, function_used_regs);
  4117. node->function_used_regs_valid = 1;
  4118. }
  4119. /* Get the declaration of the function called by INSN. */
  4120. static tree
  4121. get_call_fndecl (rtx_insn *insn)
  4122. {
  4123. rtx note, datum;
  4124. note = find_reg_note (insn, REG_CALL_DECL, NULL_RTX);
  4125. if (note == NULL_RTX)
  4126. return NULL_TREE;
  4127. datum = XEXP (note, 0);
  4128. if (datum != NULL_RTX)
  4129. return SYMBOL_REF_DECL (datum);
  4130. return NULL_TREE;
  4131. }
  4132. /* Return the cgraph_rtl_info of the function called by INSN. Returns NULL for
  4133. call targets that can be overwritten. */
  4134. static struct cgraph_rtl_info *
  4135. get_call_cgraph_rtl_info (rtx_insn *insn)
  4136. {
  4137. tree fndecl;
  4138. if (insn == NULL_RTX)
  4139. return NULL;
  4140. fndecl = get_call_fndecl (insn);
  4141. if (fndecl == NULL_TREE
  4142. || !decl_binds_to_current_def_p (fndecl))
  4143. return NULL;
  4144. return cgraph_node::rtl_info (fndecl);
  4145. }
  4146. /* Find hard registers used by function call instruction INSN, and return them
  4147. in REG_SET. Return DEFAULT_SET in REG_SET if not found. */
  4148. bool
  4149. get_call_reg_set_usage (rtx_insn *insn, HARD_REG_SET *reg_set,
  4150. HARD_REG_SET default_set)
  4151. {
  4152. if (flag_ipa_ra)
  4153. {
  4154. struct cgraph_rtl_info *node = get_call_cgraph_rtl_info (insn);
  4155. if (node != NULL
  4156. && node->function_used_regs_valid)
  4157. {
  4158. COPY_HARD_REG_SET (*reg_set, node->function_used_regs);
  4159. AND_HARD_REG_SET (*reg_set, default_set);
  4160. return true;
  4161. }
  4162. }
  4163. COPY_HARD_REG_SET (*reg_set, default_set);
  4164. return false;
  4165. }