2nd March 2010IFIP WG 2.11 St Andrews1 Costing by construction Greg Michaelson School of Mathematical & Computer Sciences Heriot-Watt University.

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

Debugging Natural Semantics Specifications Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information Science.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
1 Compiler Construction Intermediate Code Generation.
Program Representations. Representing programs Goals.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Typed Assembly Languages COS 441, Fall 2004 Frances Spalding Based on slides from Dave Walker and Greg Morrisett.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
COMP 4—Power Tools for the Mind1 PowerTools What’s in the Box? Turing 1: An Introduction to Programming You will learn elementary computer programming.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.1 Spring 2010 Marco Valtorta
Describing Syntax and Semantics
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Computer Science 101 Introduction to Programming.
Chapter 17 Programming Tools The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
© Andrew IrelandSoftware Design F28SD2 Function-oriented Design Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt University Edinburgh.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Computer Science 101 Introduction to Programming.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
PART I SISTEM UTILITIES Lecture 6 Compilers Ştefan Stăncescu 1.
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:
Computer Science 101 Introduction to Programming.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
© Gudmund Grov & Andrew Ireland Dependable Systems Group Planning for System Development Gudmund Grov & Andrew Ireland Dependable Systems Group School.
Advanced Functional Programming Tim Sheard 1 Lecture 6 Functional Programming Tim Sheard & Mark Jones Monads & Interpreters.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Programming in Hume Greg Michaelson School of Mathematical & Computer Sciences Heriot-Watt University SICSA International Summer School on Advances in.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
Copyright 2001, Matt Dwyer, John Hatcliff, and Radu Iosif. The syllabus and all lectures for this course are copyrighted materials and may not be used.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
Code Generation CPSC 388 Ellen Walker Hiram College.
Elements of Computing Systems, Nisan & Schocken, MIT Press, Chapter 6: Assembler slide 1www.nand2tetris.org Building a Modern Computer.
© Andrew IrelandGrand Challenges for Computing Research 2004 The Verifying Compiler Andrew Ireland Dependable Systems Group School of Mathematical & Computer.
Chapter 6 Testing and running a solution. Errors X Three types Syntax Logic Run-time.
Software Development Environment
Basic Concepts: computer, program, programming …
CSCI-235 Micro-Computer Applications
Representation, Syntax, Paradigms, Types
Context-free grammars (CFGs)
User-Defined Functions
Intermediate Code Generation
Course supervisor: Lubna Siddiqui
Intermediate Representations Hal Perkins Autumn 2011
Compiler Construction
Computer Organization & Compilation Process
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Advanced Programming Behnam Hatami Fall 2017.
Functional Programming
Representation, Syntax, Paradigms, Types
Software Development Environment, File Storage & Compiling
Computer Organization & Compilation Process
Motivation for Language Specification
Computer Systems An Introducton.
Compiler Structures 1. Overview Objective
WJEC GCSE Computer Science
Presentation transcript:

2nd March 2010IFIP WG 2.11 St Andrews1 Costing by construction Greg Michaelson School of Mathematical & Computer Sciences Heriot-Watt University

2nd March 2010IFIP WG 2.11 St Andrews2 Overview how can we use cost information (e.g. WCET, space) to guide software construction? –mini-Hume compilation to stack machine cost model –box calculus –augmenting box calculus with costs –costulator

2nd March 2010IFIP WG 2.11 St Andrews3 Overview mature WCET/space costs models for many languages analysis tools are whole program –apply after not during initial software construction can we see cost implications at every stage as we construct software?

2nd March 2010IFIP WG 2.11 St Andrews4 Hume with Kevin Hammond (St Andrews) formally motivated language for resource aware system construction concurrent finite state boxes joined by wires box transitions from patterns to expressions rich polymorphic types

2nd March 2010IFIP WG 2.11 St Andrews5 Hume strong separation of: –coordination: between boxes & environment –expression: within boxes strong formal foundations –semantics + type system tool chain via abstract machine to code amortised cost models instantiated for concrete platforms

2nd March 2010IFIP WG 2.11 St Andrews6 Hume Turing complete - too big for this presentation mini-Hume –integers types only –no functions –no if/case –no * (ignore) pattern or expression

2nd March 2010IFIP WG 2.11 St Andrews7 mini-Hume box gen in (n) out (n’,r) match (x) -> (x+1,x); box d in (x) out (y) match (n) -> (2*n); stream output to “std_out”; wire gen (gen.n’initially 0) (gen.n,d.x); wire d (gen.r) (output); n gen x -> (x+1,x) n’ r x d n -> 2*n y output

2nd March 2010IFIP WG 2.11 St Andrews8 mini-Hume prog -> coord ; [coord] coord -> box | wire | stream box -> box id in ( vars ) out ( vars ) match ( patts ) -> ( exp ) |... vars -> var | var, vars patts -> int | var | patt, patts exp -> int | var | exp op exp | exp, exp wire -> wire id ( ins ) ( outs ) ins -> var | var.var [ initially int] | ins, ins outs -> var | var. var | outs, outs stream -> stream id [ from / to ] “ path ”

2nd March 2010IFIP WG 2.11 St Andrews9 Execution model forever for each box- execute find pattern matching inputs bind pattern variables evaluate exp to produce outputs for each box- super step copy outputs to associated inputs

2nd March 2010IFIP WG 2.11 St Andrews10 Stack machine PUSHI integerstack[sp++] = integer VAR identifierallocate next memory address PUSHM identifier stack[sp++] = mem[addr(identifier)] POPM identifiermem[addr(identifier)] = stack[--sp] POP sp-- ADD stack[sp-2] = stack[sp-2]+stack[sp-1]; sp-- SUB stack[sp-2] = stack[sp-2]-stack[sp-1]; sp-- MULT stack[sp-2] = stack[sp-2]*stack[sp-1]; sp-- DIV stack[sp-2] = stack[sp-2]/stack[sp-2]; sp-- LABEL label JNEG label if(stack[sp--]<0) goto label JZERO label if(stack[sp--]==0) goto label JPOS label if(stack[sp--]>0) goto label JNZERO label if(stack[sp--]!=0) goto label JMP label goto label

2nd March 2010IFIP WG 2.11 St Andrews11 Compilation box incd in (s,n) out (s',n',r) match (0,x) -> (1,x+1,x+1) | (1,x) -> (0,x+1,2*x); stream output to "std_out"; wire incd (incd.s' initially 0, incd.n' initially 0) (incd.s,incd.n,output); LABEL incd0 -box/patt 0 PUSHM incdI0 PUSHI 0 SUB JNZERO incd1 -exp 0 PUSHI 1 POPM incdO0 PUSHM incdI1 PUSHI 1 ADD POPM incdO1 PUSHM incdI1 PUSHI 1 ADD POPM incdO2 JMP incdEND -links VAR incdI0 - s VAR incdI1 - n VAR incdO0 – s’ VAR incdO1 – n’ VAR incdO2 - r VAR output - initially PUSHI 0 POPM incdI0 PUSHI 0 POPM incdI1 - execute LABEL _MAIN -pattern 1 LABEL incd (pattern 2) LABEL incd2 - super step LABEL incdEND PUSHM incdO0 POPM incdI0 PUSHM incdO1 POPM incdI1 PUSHM incdO2 POPM output - loop SHOW JMP _MAIN

2nd March 2010IFIP WG 2.11 St Andrews12 Cost model box costs in execution box -> box id in ( vars ) out ( vars ) match ( patts ) -> ( exps ) |...- max ((Σcost(patt i ) )+ cost (exp i ))+1 - JMP patt -> int - 4 – PUSHM,PUSHI,SUB,JNZ var - 0 patt, patts- cost(patt) + cost(patts) exp ->int PUSHI var PUSHM exp 1 op exp 2 - cost(exp 1 )+cost(exp 2 )+1 - op exp, exps- cost(exp)+1+cost(exps) - POPM

2nd March 2010IFIP WG 2.11 St Andrews13 Cost model wire costs in super step wire -> wire id ( ins ) ( outs ) - cost(ins)+cost(outs) ins -> var- 2 – PUSHM,POPM var.var [ initially int] - 2[+2] – PUSHM,POPM [+PUSHI,POPM] ins 1, ins 2 - cost(ins 1 )+cost(ins 2 ) outs -> var - 2 – PUSHM,POPM var. var- 2 – PUSHM,POPM outs 1, outs 2 - cost(outs 1 )+cost(outs 2 )

2nd March 2010IFIP WG 2.11 St Andrews14 Box calculus with Gudmund Grov (Heriot-Watt/ Edinburgh) based on BMF, fold/unfold, FP etc rules to: –introduce/eliminate boxes/wires –split/join boxes horizontally/vertically NB rules affect coordination and expressions layers

2nd March 2010IFIP WG 2.11 St Andrews15 Box calculus x -> f (g x) (x,y) -> (f x,g y) x -> g x y -> f y x -> f xy -> g y x -> x identityvertical split/join horizontal split/join

2nd March 2010IFIP WG 2.11 St Andrews16 Box calculus x -> x (x,y) -> x x -> (x,y) input introduction/elimination output introduction/elimination

2nd March 2010IFIP WG 2.11 St Andrews17 Costing by construction augment rules with cost judgements construct software from scratch –use rules to justify each step –show cost impact of each rule application

2nd March 2010IFIP WG 2.11 St Andrews18 Box calculus + costs x -> f (g x) x -> g x y -> f y x -> x identityvertical split/join +/- cost patt x +/- cost exp x +/- 2 - super step from x +/- 2 - super step to x +/- cost patt y +/- 2 - super step from g x +/- 2 - super step to y

2nd March 2010IFIP WG 2.11 St Andrews19 Box calculus + costs (x,y) -> (f x,g y) x -> f xy -> g y horizontal split/join no additional cost

2nd March 2010IFIP WG 2.11 St Andrews20 Box calculus + costs x -> x (x,y) -> x x -> (x,y) input introduction/elimination output introduction/elimination +/- cost patt y +/- 2 - super step to y +/- cost exp y +/- 2 - super step from y

2nd March 2010IFIP WG 2.11 St Andrews21 Costulator Rule COST FileCode

2nd March 2010IFIP WG 2.11 St Andrews22 Costulator Rule COST FileCode

2nd March 2010IFIP WG 2.11 St Andrews23 Identity Split box > Join box > Add in Add out Costulator Rule COST File name? initially: 0 space: link: 2 pattern: 0 cost: 4 x -> x name? Code

2nd March 2010IFIP WG 2.11 St Andrews24 Costulator Rule COST File inc initially: 0 space: link: 2 pattern: 0 cost: 4 x -> x inc Code

2nd March 2010IFIP WG 2.11 St Andrews25 Identity Split box > Join box > Add in Add out Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,y) inc Code

2nd March 2010IFIP WG 2.11 St Andrews26 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,y) inc Code

2nd March 2010IFIP WG 2.11 St Andrews27 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,y) inc Code

2nd March 2010IFIP WG 2.11 St Andrews28 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,y) inc Code

2nd March 2010IFIP WG 2.11 St Andrews29 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,y) inc Code

2nd March 2010IFIP WG 2.11 St Andrews30 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 6 x -> (x,x) inc Code

2nd March 2010IFIP WG 2.11 St Andrews31 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc Code

2nd March 2010IFIP WG 2.11 St Andrews32 Costulator Rule COST File inc initially: 0 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc Code name: ? initially: ?

2nd March 2010IFIP WG 2.11 St Andrews33 Costulator Rule COST File inc initially: 2 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc Code name: n initially: 0

2nd March 2010IFIP WG 2.11 St Andrews34 Costulator Rule COST File inc initially: 2 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc Code n 0...

2nd March 2010IFIP WG 2.11 St Andrews35 Costulator Rule COST File inc initially: 2 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc 0 Code n n’ r

2nd March 2010IFIP WG 2.11 St Andrews36 Costulator Rule COST File inc initially: 2 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc 0 Code n n’ r Show Compile Run

2nd March 2010IFIP WG 2.11 St Andrews37 Costulator Rule COST File inc initially: 2 space: link: 3 pattern: 0 cost: 9 x -> (x+1,x) inc 0 Code n n’ r box inc in (n) out (n’,r) match ( x) -> (x+1,x); wire inc (inc.n’ initially 0) (inc.n); X

2nd March 2010IFIP WG 2.11 St Andrews38 X by construction syntax directed editing –also visual editing –editor obliges user to only follow grammar rules in constructing/changing program correctness by construction –theorem prover obliges user to only apply correctness preserving rules to composing correct constructs –e.g. Martin-Löf type theory

2nd March 2010IFIP WG 2.11 St Andrews39 X by construction too restrictive typically can’t make bad moves to get to a good state bad constructs are: –ungrammatical (syntax) –incorrect (correctness)

2nd March 2010IFIP WG 2.11 St Andrews40 X by construction costing isn’t like that! everything has a cost, even “wrong” bits of program –cost is 0 –cost is a variable maybe not the cost you want though so need cost monitoring

2nd March 2010IFIP WG 2.11 St Andrews41 Conclusion Costing by construction: –lets you watch how your programming affects costs as the program develops –does not oblige you to form grammatical/correct/well costed constructs as you go along –might cleanly augment an IDE

2nd March 2010IFIP WG 2.11 St Andrews42 Conclusion mini-Hume compiler + stack machine + cost analysis all written in Standard ML Costulator longer term project... thanks to: –Kevin Hammond: Hume + costs –Gudmund Grov: Box calculus