ebook img

Automatic algorithm recognition and replacement: a new approach to program optimization PDF

230 Pages·2000·0.671 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Automatic algorithm recognition and replacement: a new approach to program optimization

AutomaticAlgorithm RecognitionandReplacement ANewApproachtoProgramOptimization RobertMetzgerandZhaofangWen TheMITPress Cambridge,Massachusetts London,England (cid:2)c 2000MassachusettsInstituteofTechnology Allrightsreserved.Nopartofthisbookmaybereproducedinanyformbyanyelectronicormechanicalmeans (includingphotocopying,recording,orinformationstorageandretrieval)withoutpermissioninwritingfromthe publisher. ThisbookwassetinTimesRomanbytheauthorusingtheLATEXdocumentpreparationsystem. PrintedonrecycledpaperandboundintheUnitedStatesofAmerica. LibraryofCongressCataloging-in-PublicationData Metzger,RobertC.Automaticalgorithmrecognitionandreplacement:anew approachtoprogramoptimization /RobertMetzger, ZhaofangWen. p. cm. Includesbibliographicalreferencesandindex. ISBN0-262-13386-7(alk.paper) 1.Computeralgorithms.2.Computerprogramming.I.Wen,Zhaofang.II. Title. QA76.9.A43M482000 005.1–dc21 99-088044 Contents ListofFigures v ListofTables ix Acknowledgments xi 1 Introduction 1 2 TheProblemandItsComplexity 15 3 RelatedWork 31 4 ReducingProgramVariation 51 5 InternalProgramRepresentation 69 6 ConvertingtoaCanonicalForm 87 7 MatchingSubprogramsandPatterns 117 8 ExtractingSubprograms 129 9 ValidAlgorithmReplacement 137 10 SelectingAlgorithmReplacements 145 11 PerformingAlgorithmReplacements 153 12 TimeComplexityandPerformance 161 13 Conclusion 165 AppendixA: SystemArchitecture 173 AppendixB: ModuleDesign 179 AppendixC: InputDefinition 191 AppendixD: StatisticsonHeuristicBehavior 203 References 209 Index 213 ListofFigures 1.1 QRTriangularization—triangularizationphase 5 1.2 QRTriangularization—constructionofQphase 6 2.1 Algorithmicallyequivalentloops 20 2.2 I-valsoriginateinseveralways 21 2.3 Type expressionsforFortranvariablesINTEGER M,Nand REALA(100),B(*),C(M,N) 22 2.4 TypeexpressionsforCvariablesintM,N,A[],*B,**C,*D[100] 23 2.5 Algorithmicinstance 24 2.6 Parenthesesoperatorandalgorithmicinstances 25 2.7 Multiplevariablerolesandalgorithmicinstances 25 2.8 Constraintconsistencyinalgorithmicinstancetesting 26 2.9 Typeconsistencyinalgorithmicinstancetesting 27 4.1 Controlflownormalization—beforeandafter 53 4.2 Inductionvariablestrengthreduction—beforeandafter 53 4.3 Scalarexpansion—beforeandafter 54 4.4 Reductivescalartemporaryremoval—beforeandafter 56 4.5 Procedurecallinlining—beforeandafter 57 4.6 Loopdistribution—before 57 4.7 Loopdistribution—after 58 4.8 Conditionaldistribution—beforeandafter 59 4.9 Looppermutation—beforeandafter 59 4.10 Commonsubexpressionelimination—beforeandafter 60 4.11 Redundantassignmentelimination—beforeandafter 61 4.12 Unreachablecodeelimination—beforeandafter 62 4.13 Loopinvariantmotion—beforeandafter 63 4.14 Looprerolling—beforeandafter 64 4.15 Constantpropagation—beforeandafter 67 4.16 Algebraicsimplification 68 5.1 Representationofanarrayelement 70 vi ListofFigures 5.2 Assignmentstatementinloop 70 5.3 Representationofanassignmentstatement 71 5.4 PointerandarraysarerelatedinC 71 5.5 Theinternalrepresentationofp[15]and*(p+15)forC 72 5.6 Notationsusedintheconstructdiagrams 73 5.7 Acontrol-groupliststhestatementsexecutedunderthesame condition 73 5.8 Thecounter-loopconstructisusedtorepresentFortrandoloops 73 5.9 Thepre-test-loopconstructisusedtorepresentCwhileloops 74 5.10 Thepost-test-loopconstructisusedtorepresentCdo-whileloops 74 5.11 Theif-thenconstructisusedrepresentanif-thenstatement 75 5.12 Theif-then-elseconstructisusedtorepresentanif-then-else statement 75 5.13 ConstructsrepresentingAssignmentandI/Ostatements 75 5.14 Constructs representing C return, continue, and break statements 76 5.15 Thecallconstructisusedtorepresentalibraryprocedurecall 76 5.16 Typeconstructs 77 5.17 Thegrammarfori-valrepresentation 78 5.18 Asubtreerepresentingani-val 78 5.19 Ani-valsubtree 79 5.20 Constructingthestatement-leveldataflowdependencegraphs 81 5.21 Matrixmultiplyexample 81 5.22 Binarysearchexample 82 5.23 Thecontroltreeandthevariable-leveldataflowdependence graphforamatrixmultiplysubroutine 83 5.24 Thecontroltreeandthevariable-leveldataflowdependence graphforabinarysearchfunction 84 6.1 Isomorphicexpressiontrees 89 6.2 Non-isomorphicexpressiontrees 90 6.3 Algorithmtoperformtreeorientation 94 ListofFigures vii 6.4 Algorithmtoperformlexicographicsortofstrings 95 6.5 Twoexpressiontrees 95 6.6 Difficultcasesfordistinguishingvariablesbycontext 96 6.7 Algorithmtoperforminitialencoding 97 6.8 Algorithmtorefineencoding 101 6.9 Algorithmtosplitgroupsbyinstancetrees 102 6.10 StepsofprocedureSplitGroupByInstanceTrees,part1 103 6.11 StepsofprocedureSplitGroupByInstanceTrees,part2 104 6.12 Algorithmtosplitgroupsbydistancegraphs 105 6.13 StepsofprocedureSplitGroupByDistanceGraph,part1 106 6.14 StepsofprocedureSplitGroupByDistanceGraph,part2 107 6.15 Algorithmtosplitgroupsbypathstoroot 108 6.16 StepsofprocedureSplitGroupByPathsToRoot,part1 109 6.17 StepsofprocedureSplitGroupByPathsToRoot,part2 110 6.18 Algorithmtoupdatecodesaftersplittinggroups 111 6.19 Algorithmtoadjustcontrolgroups 113 6.20 Algorithmtoperformprioritizedtopologicalsort 114 6.21 Ani-valtree 116 7.1 Algorithmtomatchcontroltrees 118 7.2 Bandedmatrixloop—patternsubprogram 119 7.3 Bandedmatrixloop—extractedsubprogram 119 7.4 I-valtreesforthepatternsubprogram 120 7.5 I-valtreesfortheextractedsubprogram 120 7.6 Anexampleofthepatterndatabaseindexstructure 126 8.1 Computationallyconfluentcode 130 8.2 Algorithmtoextractsubprogramsformatching 132 8.3 Algorithmtofindallconnectedinducedsubgraphvertexsets 134 9.1 Collapsingverticesofadirectedacyclicgraphmayintroduce directedcycles 138 9.2 Non-overlappingreplacementscode 140 viii ListofFigures 9.3 Algorithmtodeterminethefeasibilityofreplacements 142 10.1 Algorithmfindingselectionthatmaximizesreplacementbenefit 150 11.1 Algorithmtoperformalgorithmreplacements 154 11.2 Subprogrambeforeandafterreplacement 156 11.3 Thecontroltreebeforeandafteralgorithmreplacement 157 12.1 Algorithmrecognitionandreplacementsystemflowchart 162 A.1 Algorithmrecognitionandreplacementsystemarchitecture 175 A.2 Algorithmrecognitionprototypedataflow 177 B.1 Structurechartforalgorithmrecognitionandreplacement 179 B.2 Structurechartformatchinganextractedsubprogramagainst thepatterns 182 B.3 Structurechartforpreprocessingapattern 187 ListofTables D.1 Initialpatterngroups 204 D.2 Distributionofgroupswithinvariantset1 205 D.3 Distributionofgroupswithinvariantset2 206 D.4 Distributionofgroupswithinvariantset3 206 D.5 Distributionofcontrolgroupsizes 207 x ListofTables Acknowledgments ThisworkwaspartiallysponsoredbytheAirForceMaterialCommandandtheAdvanced Research Projects Agency / CSTO, under ARPA Order No. B548, issued by ESC/ENS underContract#F19628-94-C-0058.TheremainderoftheworkwasfundedbytheConvex Division of the Hewlett-PackardCompany,formerlyConvexComputer Corporation.We thankbothARPAandConvex/HPforallowingustoundertakethisproject. WenwouldliketoexpresshisappreciationtoTerryCaracuzzo,MarkSchroeder,and RobertCoxforsharingtheirvaluablein-depthexperiencesoftheConvexoptimizingcom- piler. He also enjoyedmany interestingconversationswith Terry Caracuzzoon compiler optimizationsthatnotonlyhelpedthe implementationsof ourpreprocessingtransforma- tions, but also sharpened the ideas of the system design. He thanks Derek G. Corneil for pointing out the best algorithms on graph isomorphism. He would also like to thank StephanOlariuforstimulatingdiscussionsonalgorithmsdesignandforpointingoutref- erencesingraphtheoryrelatedtothisproject.HeisverygratefultoC.MikeOverstreetfor firstintroducinghimtothefieldofprogramanalysisandtransformation. PresleySmithandSteveWallachencouragedMetzgertoseekexternalfundingforhis research ideas. He thanks them for their support and confidence in his efforts. Randall MercerwrotethefirstpatternmatchingtransformationsintheConvexvectorizingFortran compiler,whicheventuallyconvincedMetzgerofthevalueoftheconceptandtheimpos- sibilityoftheapproach. GregAstfalkandJoelWilliamsonfoundnumerousmistakesinourfirstdraftandsug- gestedcorrectionsonbothformandcontent.Wethankthembothfortheirdiligentefforts. AugustinDubrulleprovidedtheQRtriangularizationexampleintheintroductorychapter. SeanStroudandMatthewDiazhelpedusresurrecttheConvexApplicationCompilerfor useinpreprocessingapplicationcodes. Weacknowledgethecommentsoftheanonymousreferees,whichhelpedusimprove the textin severalways, as well as the help of our editor at MIT Press, Doug Sery, who helpedusnavigatetheseeminglyinterminablepathfromdrafttobook. Anyerrorsthatremainarepurelytheresponsibilityoftheauthors.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.