1
play

1 Calling Conventions Architecture Review: Caller- and Callee-Saved - PowerPoint PPT Presentation

Prelude Register Allocation II The Sears Tower in Chicago was the worlds Last time tallest building from 1974 until 1998. Register allocation Global allocation via graph coloring Today More register allocation Fun facts


  1. Prelude Register Allocation II The Sears Tower in Chicago was the world’s Last time tallest building from 1974 until 1998. – Register allocation – Global allocation via graph coloring Today – More register allocation Fun facts – Allocation across procedure calls – The Sears Tower contains enough concrete to build an eight-lane, five- mile-long highway, enough steel to build 50,000 automobiles, and enough telephone wiring to wrap around the world 1.75 times. – At the very top of the building, the maximum wind drift is just one foot. – Six roof-mounted robotic window-washing machines clean all 16,1000 windows on the Sears tower. – My son Kevin visited the “Serious” tower no less than 5 times during the two years we lived in Chicago. CS553 Lecture Register Allocation II 1 CS553 Lecture Register Allocation II 2 Interference Graph Allocators Register Allocation and Procedure Calls Chaitin Briggs Problem – Register values may change across procedure calls – The allocator must be sensitive to this Two approaches – Work within a well-defined calling convention – Use interprocedural allocation (not covering this) CS553 Lecture Register Allocation II 3 CS553 Lecture Register Allocation II 4 1

  2. Calling Conventions Architecture Review: Caller- and Callee-Saved Registers Partition registers into two categories Goals – Caller-saved – Fast calls (pass arguments in registers, minimal register saving/restoring) – Callee-saved – Language-independent – Support debugging, profiling, garbage collection, etc. Caller-saved registers – Caller must save/restore these registers when live across call Complicating Issues – Callee is free to use them – Varargs – Passing/returning aggregates caller Example foo() – Exceptions, non-local returns callee – setjmp() / longjmp() { r caller = 4 goo() is free to goo() save r caller modify r caller { goo() r caller = 99 restore r caller } r caller ? } CS553 Lecture Register Allocation II 5 CS553 Lecture Register Allocation II 6 Architecture Review: Caller- and Callee-Saved Registers Architectures with Callee and Caller Registers Callee-saved registers SPARC – Callee must save/restore these registers when it uses them – hardware-saved %i0-%i7, %o0-%o8 – Caller expects callee to not change them Alpha – 7 callee-saved out of 32 registers Example callee MIPS caller foo() goo() promises – caller-saved: $t0-$t9, $a0-$a3, $v0-$v1 { not to modify goo() – callee-saved: $s0-$s7, $ra, $fp r callee = 4 r callee { PPC save r callee goo() r callee = 99 – 18 callee-saved restore r callee – 14 caller-saved r callee ? } } StarCore EABI – 4 callee-saved – 28 caller-saved CS553 Lecture Register Allocation II 7 CS553 Lecture Register Allocation II 8 2

  3. Register Allocation and Calling Conventions Precolored Nodes Add architectural registers to interference graph Insensitive register allocation – Precolored (mutually interfering) – Save all live caller-saved registers before call; restore after – Not simplifiable – Save all used callee-saved registers at procedure entry; restore at return – Not spillable – Suboptimal foo() Express allocation constraints { – Integers usually can’t be stored in floating point registers t = … A variable that is not live across calls should go in – Some instructions can only store result in certain registers … = t caller-saved registers – Caller-saved and callee-saved registers. . . s = … A variable that is live across multiple calls should f() s3 s2 r1 go in callee-saved registers g() … = s } s4 s1 r2 f3 Sensitive register allocation – Encode calling convention constraints in the IR and interference graph – How? Use precolored nodes floating point floating point integer integer CS553 Lecture Register Allocation II 9 CS553 Lecture Register Allocation II 10 Precolored Nodes and Calling Conventions Example Callee-saved registers r1 , r2 caller-saved – Treat entry as def of all callee-saved registers foo(): r3 callee-saved – Treat exit as use of them all def(r3) – Allocator must “spill” callee-saved registers to use them t1 := r3 a := ... b := ... foo() ... a ... { r1 call goo t1 def(r3) ... b ... Live range of callee-saved registers r3 := t1 use(r3) use(r3) r3 r2 b a } return Caller-saved registers – Variables live across call interfere with all caller-saved registers CS553 Lecture Register Allocation II 11 CS553 Lecture Register Allocation II 12 3

  4. MiniJava compiler, Tiger pg. 198, Ch 11, Ch 12 Tradeoffs Callee-saved registers Callee-saved registers – MipsFrame.java, calleeSaves = { RA, S0, S1, S2, S3, S4, S5, S6, S7}, + Decreases code size: one procedure body may have multiple calls – In MipsFrameRegAlloc.java procEntryExit1 – at entry, copy calleeSaves into temporaries + Small procedures tend to need fewer registers than large ones; callee-save – at end, copy from temporaries back into calleeSaves makes sense because procedure sizes are shrinking – In MipsFrameRegAlloc.java procEntryExit2 − May increase execution time: For long-lived variables, may save and – at entry, could put a source statement with defs, but is not necessary restore registers multiple times, once for each procedure, instead of a – at end, already inserting a sink statement that uses all calleeSaves Caller-saved registers single end-to-end save/restore – MipsFrame.java, callerSaves = {T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, V0, V1}; – Put them all in destlist for the function call, see Codegen.java call to frame.callDefs() The larger “problem” – Put use in sink statement so they are live from call to end of procedure Special registers – We’re making local decisions for policies that require global information – Cannot use for register allocation, might want to make FP (which is S8) special – In MipsFrame.java procEntryExit2 put uses of the special registers in sink stmt Argument registers can also be used as caller-saved registers – Codegen.java pushes all arguments onto the stack right now CS553 Lecture Register Allocation II 13 CS553 Lecture Register Allocation II 14 Concepts Next Time Register allocation and procedure calls Reading – Make sure to read the Briggs paper Calling conventions – Caller- vs. callee-saved registers Lecture – Precoloring – Register Allocation III CS553 Lecture Register Allocation II 15 CS553 Lecture Register Allocation II 16 4

  5. Problem with Callee-Saved Registers Run-time systems ( e.g., setjmp() / longjmp() and debuggers) need to know register values in any stack frame – Caller-saved registers are on stack frame at known location – Callee-saved registers? F4: save r3 F3: r1, r2 caller-saved F2: save r1,r2 r3 callee-saved F1: CS553 Lecture Register Allocation II 17 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend