STAL - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

STAL

Description:

STAL David Walker (joint work with Karl Crary, Neal Glew and Greg Morrisett) http://www.cs.cornell.edu/home/walker/talnet/tal.html – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 26
Provided by: walker
Category:

less

Transcript and Presenter's Notes

Title: STAL


1
STAL
  • David Walker
  • (joint work with Karl Crary,
  • Neal Glew and Greg Morrisett)
  • http//www.cs.cornell.edu/home/walker/talnet/tal.h
    tml

2
Compiling With Typed ILs Flint, GHC, TIL(T),
...
Terms
Types
Source
IL
Machine
3
TIL Advantages
  • Security (JVM)
  • Optimization (unboxing)
  • Proofs of Correctness (closure conversion)
  • Semantics (Harper Stone)
  • Debugging (TIL)
  • Explicit Compiler Invariants

4
The Gap
Terms
Types
Source
IL
Register Allocation Instruction
Selection Instruction Scheduling Low level
Optimization
Machine
5
TAL Advantages
  • Security, Optimization, Proofs
  • Debugging, Semantics, and Invariants

Terms
Types
Source
IL
Machine
6
Outline
  • Front-end What is TAL?
  • Middle-end Adding Stacks
  • Back-end Typed Code Generation

7
TAL Instructions
  • standard RISC mov, ld, st, add, jmp, beq
  • few macros malloc r1?1, , ?n
  • type annotations unpack ?, r1, r1

8
TAL Types
  • ints and other base types
  • tuples with initialization flags
  • polymorphic code types
  • existential types

ltint0, int1gt
??. r1?, r2int, r3r1 ?
??.lt?.r1?1, ?1gt
9
TAL Example Sum
sum r1 1 2 ... r2 r1 Accumulator
r2 Counter r3 Continuation sum r1int,
r2int, r3r1int beq r2, r3 if r2
0, jump to cont. add r1, r2 r1 r1
r2 sub r2, 1 decrement counter
jmp sum iterate loop
10
TAL Example Mkpair
mkpair r1int, r2r1ltint1, int1gt
malloc r3int, int r3ltint0, int0gt
st r30, r1 r3ltint1, int0gt
st r31, r1 r3ltint1, int1gt
mov r1, r3 jmp r2
jump to cont.
call site r2r1ltint1, int1gt, r5 ltint1,
int1, int1gt mov r1, 17 jmp
mkpair
11
Heap-Allocated Environments
mkpair ??. r1int, r2r1ltint1,int1gt, renv
?, renv?
call site malloc renv?3, ..., ?n st renv0,
r3 ... st renvn, rn jmp mkpairlt?31, ..., ?n1gt
12
Stack- vs Heap-Allocation
  • simple, efficient 1st-class continuations
  • better environment sharing
  • unified memory management
  • better locality
  • benefits from hardware bias
  • GC-independent

Heaps
Stacks
13
STAL
  • new dedicated register sp
  • stack types
  • instructions
  • uninitialized stack slots have nonsense type (ns)

? ? nil ??
salloc n sfree n sld r, spi sst spi, r
14
STAL Example Mkpair
mkpair ??. sp?, r1int, r2spintint?
salloc 2 sp nsns?
sst sp0, r1 sp intns?
sst sp1, r1 sp intint?
jmp r2 jump to cont.
15
STAL Example Sum
accumulator on stack counter in r1 return
address in r2 sum ??. spint?, r1int,
r2spint? beq r1, r2 if r1
0, jump to cont. sld r2, sp0 load
from stack add r2, r1 r2 r2
r1 sst sp0, r2 store to stack
sub r1, 1 decrement counter jmp
sum? iterate loop
16
Sum Example Contd
sum ??. spint?, r1int, r2spint?
call site ??. sp?, r1int,
r2spint?2 ... ?n? salloc n sst
sp1, r2 ... sst spk, rn k
n-1 sst sp0, 0 accumulator jmp
sum?2 ... ?n?
17
Key Points
  • Code types specify stack state
  • Code can be stack-polymorphic
  • Abstract stack type variables protect the
    callers stack from the callee
  • Stack-based code passes continuations

18
Stack- vs. Heap-Allocated Activation Records
  • Stack-allocated activation records
  • Heap-allocated activation records

??. r1int, r2r1int, sp?, sp?
??. r1int, r2r1int, renv?, renv?
19
Calling Conventions
  • Caller boxes continuation
  • Multiple continuations

??. r1int, r2ltr1?, r2int1, ?1gt
??,??. r1int, rretltr1?, r2int1,
?1gt, rexnltr1?, r2int1, ?1gt
20
More Calling Conventions
  • Closed function type
  • Stack-Based Calling Conventions
  • C ??. spr1int, spchar?char?
  • Pascal/Win32 ??. spr1int, sp?char?
  • KML ...

char ? int
21
The Paper
  • Simple Stacks
  • Compound Stacks
  • sp ?1 ? ??2
  • Restricted Stack Pointers
  • r3 ptr(??2)
  • Efficient exceptions, displays, ...
  • Not

22
Implementation
KML
F-omega
Scheme--
Popcorn
Additional Contributers Chris Hawblitzel Fred
Smith Stephanie Weirich Steve Zdancewic
STALx86
23
Summary
  • we can type both stacks and heaps
  • types can specify code generation invariants
  • types explain connections between different
    compilation strategies

24
Stack Allocated Data
sp
-4
?1
17
r3
??1, ?2. sp (int?1) ? (intint?2 ),
r3 ptr(intint?2 )
5
?2
25
PCC vs TAL
  • Use logic to build enforceable abstractions on
  • top of machine language
  • Admit almost all optimizations
  • PCC
  • 1st-order predicate logic
  • LF type checking of embedded proofs
  • Low-level abstractions (addr, read, write, ...)
  • TAL
  • Higher-order type theory
  • Type checking of assembly language objects
    directly
  • High-level abstractions (?, ?, lt?1, ...,?1gt, ...)
Write a Comment
User Comments (0)
About PowerShow.com