LinkTimeOptimization - GCC Wiki

文章推薦指數: 80 %
投票人數:10人

Link Time Optimization (LTO) gives GCC the capability of dumping its internal representation (GIMPLE) to disk, so that all the different compilation units ... GCCWiki Search: Login Self LinkTimeOptimization HomePageRecentChangesFindPageHelpContentsLinkTimeOptimization ImmutablePageCommentsInfoAttachments MoreActions: RawText PrintView RenderasDocbook DeleteCache ------------------------ CheckSpelling LikePages LocalSiteMap ------------------------ RenamePage DeletePage ------------------------ SubscribeUser ------------------------ RemoveSpam Reverttothisrevision PackagePages ------------------------ Load Save SlideShow Lastupdated:03-Oct-2009Contents Status Background Requirements Design UsingLTO Buildingthebranch UsingLTO Issueslefttoaddress(TODOlist) Status Thebranchhasbeenmergedtotrunkandisnowclosed.Finalmergeannouncement:http://gcc.gnu.org/ml/gcc/2009-10/msg00060.html Background LinkTimeOptimization(LTO)givesGCCthecapabilityofdumpingitsinternalrepresentation(GIMPLE)todisk,sothatallthedifferentcompilationunitsthatmakeupasingleexecutablecanbeoptimizedasasinglemodule.Thisexpandsthescopeofinter-proceduraloptimizationstoencompassthewholeprogram(or,rather,everythingthatisvisibleatlinktime).Thispagecontainsinformationforthisproject,includingdesign,implementationplan,statusandTODOitems.Ifyouareinterestedincollaborating,pleaseseethelistofTODOitemsattheendofthispage.TheprojectisbeingimplementedintheltoSVNbranch.Togetthelatestversion:$ svn co svn://gcc.gnu.org/svn/gcc/branches/ltoTheusualrulesforcontributingtobranchesapplytothisbranch:Messagesandpatchestothelistsshouldhavetheirsubjectprefixedwith[lto].ChangeLogentriesshouldbewrittentoChangeLog.lto. Requirements ThefundamentalmechanismusedbythecompilertodelayoptimizationuntillinktimeistowritetheGIMPLErepresentationoftheprogramonspecialsectionsintheoutputfile.Fortheinitialimplementationonthebranch,ELFwaschosenasthecontainerformatforthesesections,butinGCC-4.6supporthasbeenaddedonthetrunkforPE-COFFandMach-O.InordertouseLTOthetargetmustsupportoneofthesebinaryformats.ForPE-COFFandMach-Oaminimalbinaryreader/writerisimplementedinGCCitself.ForELF,weareusinglibelfv0.8.12,butanyrelativelyrecentlibelfimplementationshouldwork.NotethatELFisonlyrequiredasthecontainerformatforGIMPLE,thisdoesnotmeanthatELFmustbeusedasthefinalexecutableformat.Despitethe"linktime"name,LTOdoesnotneedtouseanyspeciallinkerfeatures.ThebasicmechanismneededisthedetectionofGIMPLEsectionsinsideobjectfiles.Thisiscurrentlyimplementedincollect2.Therefore,LTOwillworkonanylinkeralreadysupportedbyGCC.Asanaddedfeature,LTOwilltakeadvantageofthepluginfeatureingold.Thisallowsthecompilertopickupobjectfilesthatmayhavebeenstoredinlibraryarchives.Tousethisfeature,youmustbeusinggoldasthelinkerandenabletheuseofthepluginbycompilingwithgcc -fuse-linker-plugin.Thiswillshifttheresponsibilityofdrivingthefinalstagesofcompilationfromcollect2togoldviathelinkerplugin. Design Thefollowingaresomeofthedesigndocumentsanddiscussionsforthebasicfunctionalityandcleanups:InitialdesignLTOdesign.LTODriverStreamerInternalrepresentationchangesDesigndiscussion.ScalableLTOBoFatGCCSummit2007.ScalableWholeProgramoptimizer(WHOPR)WHOPRdesign.Designdiscussion.Designproposalforthewhoprdriverandlinkerplugin.DesignproposalforWPA.WHOPRBoFatGCCSummit2008.DesignproposalfordebugsupportforLTOandsubsequentdiscussion.Cleanupplanforlink-timeanddynamicoptimization UsingLTO Buildingthebranch Tobuildthebranch,makesurethatyouhavelibelfv0.8.12installed.$svncosvn://gcc.gnu.org/svn/gcc/branches/lto $mkdirbld&&cdbld $../lto/configure--enable-lto&&makeIfyouhavelibelfinstalledinanon-systemdirectory,youalsoneedtoadd--with-libelf=totheconfigureline. UsingLTO TherearetwomainflagsthatenableLTOfunctionality.-flto:ThisusesthemainLTOfeatures.Whengivenseveralsourcefilesonthecommandline,itwillwriteouttheILforeachofthemandthenlaunchlto1toloadeveryfunctionineveryfile.Thereconstructedcgraphisthenoptimizedasusual.$gcc-flto-cf1.c $gcc-flto-cf2.c $gcc-flto-off1.of2.oor$gcc-flto-off1.cf2.c-fwhopr:Thisissimilarto-fltobutitsplitscompilationtoachievescalability.Itisintendedtohandleextremelylargeprogramswhosecallgraphsdonotfitinmemory.Seethedesigndocumentfordetails. Issueslefttoaddress(TODOlist) Ifyouareinterestedinworkingonanyoftheseissues,pleaseaddyournametotheitemyouareinterestedinandsendmailtothelist.lto1shouldbeabletounderstandarchivefiles.ThiswouldsavealotofIOintheplugin.Thepluginisalreadyabletoprovidearesolutionfile.Itcanincludetheoffsetofeachobjectinthearchive.Whencompilingwith-funsigned-charreplacecharwithunsigned charinpass_ipa_free_lang_datainsteadofthestreamer(http://gcc.gnu.org/ml/gcc-patches/2009-01/msg01056.html).-v -save-tempsdoesnotalwaysshoweverythingneededtoreproduceacompilationstagewhenusing-fwhoprTheuseof-fwhoprinvolvesseveralcallstolto1withtemporaryfilesthatareoftenremovedbycollect2orthelinkerplug-in.Thismakes-v -save-tempsuseless,particularlywhendebuggingproblemsduringLTRANS.Thisalsomeansthattemporaryfilesshouldusemoreeasilyrecognizablenamesassociatedwiththeoriginalsourcefilesthattheyweregeneratedfrom.Currently,thenamesarecompletelyrandomanditishardtotracethembacktotheoriginalcode.-fwhoprshouldnotlaunchtheLTRANSphasefromlto1Currently,itislto1'sresponsibilitytolaunchltrans-driverwhichistheonethatdistributestheparallelgenerationoffinalcode(LTRANS).Thisshouldbedonebyxgccinstead.WPAshouldusethepassmanagerCurrently,WPAishardwiredinlto/lto.c:lto_maintocallpasses(notably,theinliner)directlyinsteadofusingthepassmanager.ThisalsomeansthattheonlypassthatiscurrentlyworkingwithWPAistheinliner.ThisshouldbechangedsothatthepassmanagerrunsalltheIPApassesinsummarymodeasalltheotherpasses.Designandimplementrulesforhandlingmixedcommandlineoptions.ThebasicproblemhereiswhattodowhentheflagsusedtogeneratetheinitialILaredifferentthantheflagsusedforfinalcodegeneration:$gcc-flto-O2-msse2-cfile.c $gcc-flto-ofilefile.oClearly,-msse2affectscodegenerationinthebackendbutwhatabout-O2?Shoulditbeimpliedinthesecondgccinvocation?Moredetailsandsomeinitialideasaredescribedinthisdocument.Browsing/dumpingtoolsforLTOfilesCurrently,IL,callgraph,symboltableandotherbitsofinformationstoredinLTOfilesareonlyreadablebyGCCwhencompiling.Weneedtoolstobeabletoanalyzeandvisualizethiscontentwhendebugging.ThinkofobjdumpforGIMPLE.(currentlyworkingon:AndiHellmund)Runpass_ipa_free_lang_dataallthetime,notjustinLTOcompilationThisisrelatedtotheimplementationofaGIMPLEtypesystemanddebugginginformation.Thispassremoveseveryfront-endspecificbitsfromtypesanddecls.Indoingso,itobliteratesallthedebugginginformationstashedawayinthosenodesandallthedatathatissometimesreferencedfromlanguagehooksinthebackend.Oncetheseissuesarefixed,wewillbeabletousethispassasthetransitionintotheGIMPLEtypesystem,whichwillcompletetheseparationbetweentheFrontEndsandtherestofthecompiler.ReadGIMPLEfromatextfileCurrently,GIMPLEisgeneratedinternallybythecompilerandemittedinsidespecialsectionsasbinarycontent.ThispermitstheLTOfrontend(lto1)readandreconstitutetheinternalrepresentationthatwasgeneratedfromtheoriginalsourcecode.AveryusefuladditiontotheLTOfrontendwouldbethecapabilityofreadingGIMPLEformattedasatextfile,asifitweresourcecode.ThisinvolvescreatingaparserforLTOandbuildingtheinternalrepresentationdirectlyfromthetextfile.Thiswouldhelpthecreationofunittests.Insteadofrelyingonsourcecode,wecouldgenerateGIMPLEdirectlyusingatexteditorandfeedthattotheoptimizersdirectly.FixdebuginformationforLTOprogramsNone:LinkTimeOptimization(lastedited2014-10-1017:51:01byDiegoNovillo) ImmutablePageCommentsInfoAttachments MoreActions: RawText PrintView RenderasDocbook DeleteCache ------------------------ CheckSpelling LikePages LocalSiteMap ------------------------ RenamePage DeletePage ------------------------ SubscribeUser ------------------------ RemoveSpam Reverttothisrevision PackagePages ------------------------ Load Save SlideShow MoinMoinPoweredPythonPoweredGPLlicensedValidHTML4.01



請為這篇文章評分?