欢迎来到天天文库
浏览记录
ID:51495990
大小:2.10 MB
页数:117页
时间:2020-03-25
《东南大学 编译原理 课件 Cp9 (2).ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Chapter9CodeOptimizationZhaiYuqingZhouXiaoyuOverviewPositionofcodeoptimizerFrontendSourceprogramCodeoptimizerCodegeneratorIntermediatecodeIntermediatecodetargetprogramPurposeofCodeOptimizertogetbetterefficiencyRunfasterTakelessspacePlacesforPotentialImprovementsSourcecodeUsercanp
2、rofileprogram,changealgorithmortransformloops.IntermediatecodeCompilercanimproveloops,procedurecallsoraddresscalculationsPlacesforPotentialImprovementsTargetcodeCompilercanuseregisters,selectinstructionsordopeepholetransformationsOrganizationofthecodeOptimizerControl-FlowAnalysis
3、IdentifyblocksandloopsintheflowgraphofaprogramData-flowanalysisCollectinformationabouttheprogramasawholeandtodistributethisinformationtoeachblockintheflowgraph.Control-flowanalysisData-flowanalysistransformationsBasicblocksMaximalsequencesofconsecutivethree-addressinstructionswit
4、hthepropertiesthatTheflowofcontrolcanonlyenterthebasicblockthroughthefirstinstructionintheblock.Controlwillleavetheblockwithouthaltingorbranching,exceptpossiblyatthelastinstructionintheblock.AnExampleT1=a*aT2=a*bT3=2*T2T4=T1+T3T5=b*bT6=T4+T5TheUseofaNameSupposethree-addressstatem
5、entiassignsavaluetox.Ifstatementjhasxasanoperand,andcontrolcanflowfromstatementitojalongapaththathasnointerveningassignmentstox,thenwesaystatementjusesthevalueofxcomputedatstatementi.LivevariableWefurthersaythatxisliveatstatementi.Anameinabasicblockissaidtobeliveatagivenpointifit
6、svalueisusedafterthatpointintheprogram,perhapsinanotherbasicblock.PartitionintoBasicBlocksInput:Asequenceofthree-addressstatementsOutput:Alistofbasicblockswitheachthree-addressstatementinexactlyoneblock.Method:Wefirstdeterminethesetofleaders,thefirststatementsofbasicblocks.Determ
7、inationofLeadersofBasicBlocks(1)Thefirststatementisaleader.(2)Anystatementthatisthetargetofaconditionalorunconditionalgotoisaleader.(3)Anystatementthatimmediatelyfollowsagotoorconditionalgotostatementisaleader.PartitionintoBasicBlocksForeachleader,itsbasicblockconsistsoftheleader
8、andallstatementsuptobutnotincludingthene
此文档下载收益归作者所有