LLVM Link Time Optimization: Design and Implementation

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

LLVM features powerful intermodular optimizations which can be used at link time. Link Time Optimization (LTO) is another name for intermodular optimization ... Navigation index next| previous| LLVMHome |  Documentation» UserGuides» Documentation GettingStarted/Tutorials UserGuides Reference GettingInvolved ContributingtoLLVM SubmittingBugReports MailingLists IRC MeetupsandSocialEvents AdditionalLinks FAQ Glossary Publications GithubRepository ThisPage ShowSource Quicksearch LLVMLinkTimeOptimization:DesignandImplementation¶ Description DesignPhilosophy Exampleoflinktimeoptimization AlternativeApproaches Multi-phasecommunicationbetweenlibLTOandlinker Phase1:ReadLLVMBitcodeFiles Phase2:SymbolResolution Phase3:OptimizeBitcodeFiles Phase4:SymbolResolutionafteroptimization libLTO lto_module_t lto_code_gen_t Description¶ LLVMfeaturespowerfulintermodularoptimizationswhichcanbeusedatlink time.LinkTimeOptimization(LTO)isanothernameforintermodular optimizationwhenperformedduringthelinkstage.Thisdocumentdescribesthe interfaceanddesignbetweentheLTOoptimizerandthelinker. DesignPhilosophy¶ TheLLVMLinkTimeOptimizerprovidescompletetransparency,whiledoing intermodularoptimization,inthecompilertoolchain.Itsmaingoalistolet thedevelopertakeadvantageofintermodularoptimizationswithoutmakingany significantchangestothedeveloper’smakefilesorbuildsystem.Thisis achievedthroughtightintegrationwiththelinker.Inthismodel,thelinker treatsLLVMbitcodefileslikenativeobjectfilesandallowsmixingand matchingamongthem.ThelinkeruseslibLTO,asharedobject,tohandleLLVM bitcodefiles.ThistightintegrationbetweenthelinkerandLLVMoptimizer helpstodooptimizationsthatarenotpossibleinothermodels.Thelinker inputallowstheoptimizertoavoidrelyingonconservativeescapeanalysis. Exampleoflinktimeoptimization¶ ThefollowingexampleillustratestheadvantagesofLTO’sintegratedapproach andcleaninterface.ThisexamplerequiresasystemlinkerwhichsupportsLTO throughtheinterfacedescribedinthisdocument.Here,clangtransparently invokessystemlinker. Inputsourcefilea.ciscompiledintoLLVMbitcodeform. Inputsourcefilemain.ciscompiledintonativeobjectcode. ---a.h--- externintfoo1(void); externvoidfoo2(void); externvoidfoo4(void); ---a.c--- #include"a.h" staticsignedinti=0; voidfoo2(void){ i=-1; } staticintfoo3(){ foo4(); return10; } intfoo1(void){ intdata=0; if(i<0) data=foo3(); data=data+42; returndata; } ---main.c--- #include #include"a.h" voidfoo4(void){ printf("Hi\n"); } intmain(){ returnfoo1(); } Tocompile,run: %clang-flto-ca.c-oa.o#



請為這篇文章評分?