1 / 23

Advanced Compilers CMPSCI 710 Spring 2003 Interprocedural Analysis

Advanced Compilers CMPSCI 710 Spring 2003 Interprocedural Analysis. Emery Berger University of Massachusetts, Amherst. Topics. Up to now Intra procedural analyses Dataflow analyses DefUse, SSA Register Allocation Scheduling Just for individual procedures

apollo
Download Presentation

Advanced Compilers CMPSCI 710 Spring 2003 Interprocedural Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced CompilersCMPSCI 710Spring 2003Interprocedural Analysis Emery Berger University of Massachusetts, Amherst

  2. Topics • Up to now • Intraprocedural analyses • Dataflow analyses • DefUse, SSA • Register Allocation • Scheduling • Just for individual procedures • Today: Interprocedural analysis • across/between procedures • Why?

  3. Aliasing • Formals and/or globals may be aliased • Two names point to same location • Only form of aliasing for Java, Fortran • At procedure call • Globals may be modified or used • Actual args may be modified or used

  4. Aliasing Examples, I • Need alias analysis to do: • Instruction scheduling • Register allocation

  5. Aliasing Examples, II • Need alias analysis to do: • Dead code elimination • Code motion

  6. Alias Examples, III • Need alias analysis to do: • Constant propagation • To perform alias analysis, we need…

  7. Interprocedural Analysis • Goals • Enable standard optimizations even with procedure calls • Reduce call overhead for procedures • Enable optimizations not possible for single procedures • Optimizations • Register allocation • Loop transformations • CSE, etc.

  8. Problems withInterprocedural Analysis • Not without drawbacks • Whole-program analysis • What about libraries? • Separate compilation requires recompilation analysis [Burke & Torczon 93] • Expensive • Doesn’t scale well, or worse • Some problems intractable • e.g., Flow-sensitive kill

  9. Analysis Sensitivity • Flow-insensitive • What may happen (on at least one path) • Linear-time • Flow-sensitive • Consider control flow (what must happen) • Iterative data-flow: possibly exponential • Context-insensitive • Call treated the same regardless of caller • “Monovariant” analysis • Context-sensitive • Reanalyze callee for each caller • “Polyvariant” analysis • More sensitivity ) more accuracy, but more expense

  10. Context Sensitivity • Reanalyze callee as if procedure was inlined • Too expensive in space & time • Recursion? • Approximate context sensitivity: • Reanalyze callee for k levels of calling context

  11. Summary Information • Another approach: summarize each procedure • Effect/result of called procedure for callers • Effect/input of callers for called procedure • Store in database for use by later optimization pass • Pros: • Concise • Fast • Practical: separate compilation • Cons: • Imprecise

  12. Two Types of Information • Track info that flows into procedures • “Propagation problems”, e.g.: • which formals are constant? • which formals are aliased to globals? • Track info that flows out of procedures • “Side effect problems”, e.g.: • which globals defined/used by procedure? • which locals defined/used by procedure? • Which actual parameters defined by procedure?

  13. Propagation Summaries: Examples • MAY-ALIAS • Formals that may be aliased to globals • MUST-ALIAS • Formals definitely aliased to globals • CONSTANT • Formals that are definitely constant

  14. Side-Effect Summaries: Examples • MOD • Variables possibly modified (defined) by procedure call • REF • Variables possibly referenced (used) by procedure • KILL • Variables that are definitely killed in procedure

  15. Computing Summaries • Bottom-up (MOD, REF, KILL) • Summarizes effect of call • Top-down (MAY-ALIAS) • Summarizes information about caller • Bi-directional (AVAIL, CONSTANT) • Info to/from caller & callee

  16. Implementing IPA: The Call Graph • Represent procedure call relationshipby call graph • G = (V,E,start) • Each procedure is unique vertex • Call site = edge between caller & callee • (u,v) = call from u to v • Can label with source line • Cycles represent recursion

  17. Call Graph Example

  18. Side-Effect Summarization • At procedure boundaries: • Translate formal args to actuals at call site • Compute: • GMOD, GREF = procedure side effects • MOD, REF = effects at call site • Possibly specific to call

  19. Side-Effect Summary Example

  20. Alternatives to IPA: Inlining • Inlining: replace call with procedure body • Pros • Exposes context & side effects • Simple • Cons • Code bloat (bad for caches, branch predictor) • Can’t decide statically for OOPs • Library source? • Recursion? • How do we decide when to inline?

  21. Alternatives to IPA: Cloning • Cloning: customize procedure for certain call sites • Partition call sites to procedure p into equivalence classes • e.g., {{call3, call1}, {call4}} • Equivalence based on optimization • Constant propagation: partition based on parameter value

  22. Cloning • Pros • Compromise between inlining & IPA • Less code bloat compared to inlining • No problem with recursion • Improves optimization potential (compared to IPA) • Cons • Some code bloat (compared to IPA) • Doesn’t eliminate need for IPA • How do we partition call sites?

  23. Conclusion • Interprocedural analysis • Difficult but expensive • Need source code, recompilation analysis • Trade-offs for precision & speed/space • Better than inlining • Useful for many optimizations • IPA and cloning likely to become more important • Java: many small procedures • Next time: • Homework 2 review

More Related