STAL David Walker (joint work with Karl Crary, Neal Glew and Greg Morrisett)

Slides:



Advertisements
Similar presentations
COS 441 Exam Stuff David Walker. TAL 2 Logistics take-home exam will become available on the course web site Jan write down when you download &
Advertisements

Type Analysis and Typed Compilation Stephanie Weirich Cornell University.
Instruction Set Design
The University of Adelaide, School of Computer Science
COMP3221 lec16-function-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 16 : Functions in C/ Assembly - II
CPU Review and Programming Models CT101 – Computing Systems.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
Typed Assembly Languages COS 441, Fall 2004 Frances Spalding Based on slides from Dave Walker and Greg Morrisett.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
CS 536 Spring Run-time organization Lecture 19.
Survey of Typed Assembly Language (TAL) Introduction and Motivation –Conventional untyped compiler < Typed intermediate languages –Typed intermediate language.
Typed Memory Management in a Calculus of Capabilities David Walker (with Karl Crary and Greg Morrisett)
CS 536 Spring Code generation I Lecture 20.
1 A Dependently Typed Assembly Language Hongwei Xi University of Cincinnati and Robert Harper Carnegie Mellon University.
Intro to Computer Architecture
Run time vs. Compile time
Semantics of Calls and Returns
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
4/6/08Prof. Hilfinger CS164 Lecture 291 Code Generation Lecture 29 (based on slides by R. Bodik)
Compiling with Dependent Types Hongwei Xi University of Cincinnati.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Programming Models CT213 – Computing Systems Organization.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Cosc 2150: Computer Organization
Programming Language Principles Lecture 24 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Subroutines.
CS 352 : Computer Organization and Design University of Wisconsin-Eau Claire Dan Ernst Execution of Machine Code Machine State and Operations Apps O/S.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter# 6 Code generation.  The final phase in our compiler model is the code generator.  It takes as input the intermediate representation(IR) produced.
Functions. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 JSR Instruction Jumps to a location (like.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CS 598 Scripting Languages Design and Implementation 12. Interpreter implementation.
C-- The lowest "high level" language... even lower than C.
1 Assembly Language: Function Calls Jennifer Rexford.
Overview of Back-end for CComp Zhaopeng Li Software Security Lab. June 8, 2009.
Alias Types David Walker Cornell University What do you want to type check today?
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Closure Compiler Baojian Hua Closure An implementation technique traditionally for functional languages Lisp, Scheme, Haskell, Ocaml,
Datapath and control Dr. ir. A.B.J. Kokkeler 1. What is programming ? “Programming is instructing a computer to do something for you with the help of.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
Chapter 14 Functions.
Storage Allocation Mechanisms
A Memory Aliased Instruction Set Architecture
CSCI206 - Computer Organization & Programming
Introduction to Compilers Tim Teitelbaum
Procedures (Functions)
Procedures (Functions)
TALx86: A Realistic Typed Assembly Language
Chapter 7 Subroutines Dr. A.P. Preethy
Code Generation Part I Chapter 9
CSCI206 - Computer Organization & Programming
Lecture 4: MIPS Instruction Set
Code Generation.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
Lecture 30 (based on slides by R. Bodik)
Subroutines and the Stack
Code Generation Part I Chapter 9
The University of Adelaide, School of Computer Science
COP 4600 Operating Systems Fall 2010
Implementing Functions: Overview
Presentation transcript:

STAL David Walker (joint work with Karl Crary, Neal Glew and Greg Morrisett)

Dave Walker2 Compiling With Typed ILs [Flint, GHC, TIL(T),...] TermsTypes Source IL Machine

Dave Walker3 TIL Advantages Security (JVM) Optimization (unboxing) Proofs of Correctness (closure conversion) Semantics (Harper & Stone) Debugging (TIL) Explicit Compiler Invariants

Dave Walker4 The Gap Machine TermsTypes Source IL Register Allocation Instruction Selection Instruction Scheduling Low level Optimization

Dave Walker5 TAL Advantages Security, Optimization, Proofs Debugging, Semantics, and Invariants TermsTypes Source IL Machine

Dave Walker6 Outline Front-end: What is TAL? Middle-end: Adding Stacks Back-end: Typed Code Generation

Dave Walker7 TAL Instructions standard RISC: mov, ld, st, add, jmp, beq … few macros: malloc r1[  1, …,  n ] type annotations: unpack [ , r1], r1

Dave Walker8 TAL Types ints and other base types tuples with initialization flags: polymorphic code types: existential types:  [  ].{ r1: , r2:int, r3:{r1:  } } .

Dave Walker9 TAL Example: Sum % sum: r r2 % r1: Accumulator % r2: Counter % r3: Continuation sum: { r1:int, r2:int, r3:{r1:int} } beq r2, r3% if r2 = 0, jump to cont. add r1, r2% r1 := r1 + r2 sub r2, 1% decrement counter jmp sum% iterate loop

Dave Walker10 TAL Example: Mkpair mkpair: { r1:int, r2:{r1: } } malloc r3[int, int] % r3: st r3[0], r1 % r3: st r3[1], r1 % r3: mov r1, r3 jmp r2 % jump to cont. call site : { r2:{r1: }, r5: } mov r1, 17 jmp mkpair

Dave Walker11 Heap-Allocated Environments mkpair:  [  ].{ r1:int, r2:{r1:, r env :  }, r env :  } call site : malloc r env [  3,...,  n ] st r env [0], r3... st r env [n], rn jmp mkpair[ ] r env

Dave Walker12 Stack- vs Heap-Allocation simple, efficient 1st- class continuations better environment sharing unified memory management better locality benefits from hardware bias GC-independent HeapsStacks

Dave Walker13 STAL new dedicated register: sp stack types: instructions: uninitialized stack slots have nonsense type (ns)  :=  | nil |  ::  salloc n | sfree n | sld r, sp[i] | sst sp[i], r

Dave Walker14 STAL Example: Mkpair mkpair:  [  ].{ sp: , r1:int, r2:{sp:int::int::  } } salloc 2% sp: ns::ns::  sst sp[0], r1% sp: int::ns::  sst sp[1], r1% sp: int::int::  jmp r2% jump to cont.

Dave Walker15 STAL Example: Sum % accumulator: on stack % counter: in r1 % return address: in r2 sum:  [  ].{ sp:int:: , r1:int, r2:{sp:int::  } } beq r1, r2% if r1 = 0, jump to cont. sld r2, sp[0]% load from stack add r2, r1% r2 := r2 + r1 sst sp[0], r2% store to stack sub r1, 1% decrement counter jmp sum[  ]% iterate loop

Dave Walker16 Sum Example Cont’d call site :  [  ’].{ sp:  ’, r1:int, r2:{sp:int::  2 ::... ::  n ::  ’} } salloc n sst sp[1], r2... sst sp[k], rn % k = n-1 sst sp[0], 0 % accumulator jmp sum[  2 ::... ::  n ::  ’] sum:  [  ].{ sp:int:: , r1:int, r2:{sp:int::  } } sp : int :  ’’  :  n

Dave Walker17 Key Points Code types specify stack state Code can be stack-polymorphic Abstract stack type variables protect the caller’s stack from the callee Stack-based code passes continuations

Dave Walker18 Stack-allocated activation records: Heap-allocated activation records: Stack- vs. Heap-Allocated Activation Records  [  ].{ r1:int, r2:{r1:int, r env :  }, r env :  }  [  ].{ r1:int, r2:{r1:int, sp:  }, sp:  } r env sp

Dave Walker19 Caller boxes continuation: Multiple continuations: Calling Conventions  [  ].{ r1:int, r2: }  [ ,  ].{ r1:int, r ret :, r exn : }

Dave Walker20 More Calling Conventions Closed function type: Stack-Based Calling Conventions: C:  [  ].{ sp:{r1:int, sp:char::  }::char::  } Pascal/Win32:  [  ].{ sp:{r1:int, sp:  }::char::  } KML:... char  int

Dave Walker21 The Paper Simple Stacks Compound Stacks –sp :  1   ::  2 Restricted Stack Pointers –r3 : ptr(  ::  2 ) Efficient exceptions, displays,... Not &

Dave Walker22 Implementation KML F-omega++ STALx86 Scheme-- Popcorn Additional Contributers: Chris Hawblitzel Fred Smith Stephanie Weirich Steve Zdancewic

Dave Walker23 Summary we can type both stacks and heaps types can specify code generation invariants types explain connections between different compilation strategies

Dave Walker24 Stack Allocated Data 11 sp 2 r3  [  1,  2 ]. {sp: (int::  1 )  (int::int::  2 ), r3: ptr(int::int::  2 )}

Dave Walker25 PCC vs TAL 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 ( , ,,...) Use logic to build enforceable abstractions on top of machine language Admit almost all optimizations