CIS570 Modern Programming Language Implementation. Office hours: TDB 605 Levine eclewis@cis.upenn.edu. cherylh@central.cis.upenn.



Similar documents
Optimizing compilers. CS Modern Compilers: Theory and Practise. Optimization. Compiler structure. Overview of different optimizations

Module: Software Instruction Scheduling Part I

EE361: Digital Computer Organization Course Syllabus

Jonathan Worthington Scarborough Linux User Group


Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

VLIW Processors. VLIW Processors

Automated Program Behavior Analysis

Introduction to Embedded Systems. Software Update Problem

2) Write in detail the issues in the design of code generator.

Instruction Set Architecture (ISA)

Software Pipelining. for (i=1, i<100, i++) { x := A[i]; x := x+1; A[i] := x

CS 40 Computing for the Web

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Levels of Programming Languages. Gerald Penn CSC 324

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

Virtual Machine Learning: Thinking Like a Computer Architect

CSCI E 98: Managed Environments for the Execution of Programs

Cambridge International AS and A Level Computer Science

Programming Languages

Wiggins/Redstone: An On-line Program Specializer

How To Write Portable Programs In C

INSTRUCTION LEVEL PARALLELISM PART VII: REORDER BUFFER

Processor Architectures

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Chapter 5 Instructor's Manual

The programming language C. sws1 1

AMD Opteron Quad-Core

CS 51 Intro to CS. Art Lee. September 2, 2014

Introduction to Virtual Machines

The Design of the Inferno Virtual Machine. Introduction

CHAPTER 1 ENGINEERING PROBLEM SOLVING. Copyright 2013 Pearson Education, Inc.

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Chapter 13: Program Development and Programming Languages

Patterns in Software Engineering

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

Lecture 1: Introduction

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

Parallel Algorithm Engineering

Programming Language Pragmatics

Driving force. What future software needs. Potential research topics

CSE 141L Computer Architecture Lab Fall Lecture 2

Lecture 12: Software protection techniques. Software piracy protection Protection against reverse engineering of software

CA Compiler Construction

Big Data Technology Map-Reduce Motivation: Indexing in Search Engines

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Computer System: User s View. Computer System Components: High Level View. Input. Output. Computer. Computer System: Motherboard Level

Instruction Set Architecture (ISA) Design. Classification Categories

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Applications of obfuscation to software and hardware systems

Static Taint-Analysis on Binary Executables

IA-64 Application Developer s Architecture Guide

Quiz for Chapter 1 Computer Abstractions and Technology 3.10

Unit 4: Performance & Benchmarking. Performance Metrics. This Unit. CIS 501: Computer Architecture. Performance: Latency vs.

An Overview of Stack Architecture and the PSC 1000 Microprocessor

(Refer Slide Time: 02:39)

EE360: Digital Design I Course Syllabus

PHP Debugging. Draft: March 19, Christopher Vickery

The Fastest Way to Parallel Programming for Multicore, Clusters, Supercomputers and the Cloud.

Fundamentals of Java Programming

CSC Software II: Principles of Programming Languages

CPU Organization and Assembly Language

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

MPI and Hybrid Programming Models. William Gropp

picojava TM : A Hardware Implementation of the Java Virtual Machine

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

3 SOFTWARE AND PROGRAMMING LANGUAGES

find model parameters, to validate models, and to develop inputs for models. c 1994 Raj Jain 7.1

High-speed image processing algorithms using MMX hardware

CHAPTER 7: The CPU and Memory

Chapter 13: Program Development and Programming Languages

Course MS10975A Introduction to Programming. Length: 5 Days

IBM CELL CELL INTRODUCTION. Project made by: Origgi Alessandro matr Teruzzi Roberto matr IBM CELL. Politecnico di Milano Como Campus

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

CSE4213 Lecture Notes

A Typing System for an Optimizing Multiple-Backend Tcl Compiler

Lecture 2 Introduction to Data Flow Analysis

Computer Architecture TDTS10

Chapter 11 I/O Management and Disk Scheduling

The C Programming Language course syllabus associate level

ZQL. a cryptographic compiler for processing private data. George Danezis. Joint work with Cédric Fournet, Markulf Kohlweiss, Zhengqin Luo

Administration. Instruction scheduling. Modern processors. Examples. Simplified architecture model. CS 412 Introduction to Compilers

Course Structure of Three Year Degree B.A Programme in Computer Application under Semester System of Dibrugarh University (General Programme)

Building Applications Using Micro Focus COBOL

Lecture 1 Introduction to Parallel Programming

Software Engineering

Architectures and Platforms

Objectives. Python Programming: An Introduction to Computer Science. Lab 01. What we ll learn in this class

Static Scheduling. option #1: dynamic scheduling (by the hardware) option #2: static scheduling (by the compiler) ECE 252 / CPS 220 Lecture Notes

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Lecture 11: Multi-Core and GPU. Multithreading. Integration of multiple processor cores on a single chip.

Week 1 out-of-class notes, discussions and sample problems

Transcription:

CIS570 Modern Programming Language Implementation Instructor: Admin. Assistant: URL: E Christopher Lewis Office hours: TDB 605 Levine eclewis@cis.upenn.edu Cheryl Hickey cherylh@central.cis.upenn.edu 502 Levine http://www.cis.upenn.edu/~eclewis/cis570 CIS570 Lecture 1 Introduction 2 What is CIS570 About? Program representation Can we do better than ASCII.c files? Analysis How do we mechanically derive meaning and intent? How do we reason about programs? Transformation How do we use results of analysis to make the representation better? Domains Language implementation (including Compilation) Computation understanding Software engineering tools (bug detectors, etc.) CIS570 Lecture 1 Introduction 3 CIS570 Lecture 1 1

Structure of CIS570 Lectures Participation is essential (no text book) Reading 6 or 7 papers Read and answer discussion questions before designated class Discussions Some classes will be devoted to discussion But there is always room for discussion Exams Final perhaps? Homework Answer discussion questions before class benefit CIS570 WPE-I Bottom line Very efficient class effort CIS570 Lecture 1 Introduction 4 Plan for Today Motivation Why study compilers? Issues Look at some sample optimizations and assorted issues Administrivia Course details CIS570 Lecture 1 Introduction 5 CIS570 Lecture 1 2

Motivation What is a compiler? A translator that converts a source program into an target program What is an optimizing compiler? A translator that somehow improves the program (versus non-opt. comp.) Why study compilers? They are specifically important: Compilers provide a bridge between applications and architectures They are generally important: Compilers encapsulate techniques for reasoning about programs and their behavior They are cool: First major computer application CIS570 Lecture 1 Introduction 6 Traditional View of Compilers Compiling down Translate high-level language to machine code High-level programming languages Increase programmer productivity Improve program maintenance Improve portability Low-level architectural details Instruction set Addressing modes Pipelines Registers, cache, and the rest of the memory hierarchy Instruction-level parallelism CIS570 Lecture 1 Introduction 7 CIS570 Lecture 1 3

Isn t Compilation A Solved Problem? Optimization for scalar machines is a problem that was solved ten years ago -- David Kuck, 1990 Machines keep changing New features present new problems (e.g., MMX, EPIC, profiling support, TM) Changing costs lead to different concerns (e.g., mem v. ALU ops) Languages keep changing Wacky ideas (e.g., OOP and GC) have gone mainstream Applications keep changing Interactive, real-time, mobile, secure Values keep changing Correctness Run-time performance Code size Compile-time performance Power Security CIS570 Lecture 1 Introduction 8 Modern View of Compilers Analysis and translation are useful everywhere Analysis and transformations can be performed at run time and link time, not just at compile time Translation can be used to improve security Analysis can be used in software engineering Program understanding Reverse engineering Increased interaction between hardware and compilers can improve performance Bottom line Analysis and transformation play essential roles in computer systems Computation important understanding computation important CIS570 Lecture 1 Introduction 9 CIS570 Lecture 1 4

Types of Optimizations Definition An optimization is a transformation that is expected to improve the program in some way; often consists of analysis and transformation e.g., decreasing the running time or decreasing memory requirements Machine-independent optimizations Eliminate redundant computation Move computation to less frequently executed place Specialize some general purpose code Remove useless code CIS570 Lecture 1 Introduction 10 Types of Optimizations (cont) Machine-dependent optimizations Replace a costly operation with a cheaper one Replace a sequence of operations with a cheaper one Hide latency Improve locality Reduce power consumption Enabling transformations Expose opportunities for other optimizations Help structure optimizations CIS570 Lecture 1 Introduction 11 CIS570 Lecture 1 5

Sample Optimizations Arithmetic simplification Constant folding e.g., x = 8/2; x = 4; Strength reduction e.g., x = y * 4; x = y << 2; Constant propagation e.g., x = 3; x = 3; x = 3; y = 4+x; y = 4+3; y = 7; Copy propagation e.g., x = z; x = z; y = 4+x; y = 4+z; CIS570 Lecture 1 Introduction 12 Sample Optimizations (cont) Common subexpression elimination (CSE) e.g., x = a + b; y = a + b; t = a + b; x = t; y = t; Dead (unused) assignment elimination e.g., x = 3;... x not used... x = 4; this assignment is dead Dead (unreachable) code elimination e.g., if (false == true) { printf( debugging... ); } this statement is dead CIS570 Lecture 1 Introduction 13 CIS570 Lecture 1 6

Sample Optimizations (cont) Loop-invariant code motion e.g., for i = 1 to 10 do x = 3;... Induction variable elimination e.g., for i = 1 to 10 do a[i] = a[i] + 1; Loop unrolling e.g., for i = 1 to 10 do a[i] = a[i] + 1; x = 3; for i = 1 to 10 do... for p = &a[1] to &a[10] do *p = *p + 1 for i = 1 to 10 by 2 do a[i] = a[i] + 1; a[i+1] = a[i+1] + 1; CIS570 Lecture 1 Introduction 14 Is an Optimization Worthwhile? Criteria for evaluating optimizations Safety: does it preserve behavior? Profitability: does it actually improve the code? Opportunity: is it widely applicable? Cost (compilation time): can it be practically performed? Cost (complexity): can it be practically implemented? CIS570 Lecture 1 Introduction 15 CIS570 Lecture 1 7

Scope of Analysis/Optimizations Peephole Consider a small window of instructions Usually machine specific Know nothing about context Local Consider blocks of straight line code (no control flow) Simple to analyze Know nothing about context Global (intraprocedural) Consider entire procedures Must consider branches, loops, merging of control flow Use data-flow analysis Make certain assumptions at procedure calls Whole program (interprocedural) Consider multiple procedures Analysis even more complex (calls, returns) Hard with separate compilation CIS570 Lecture 1 Introduction 16 Limits of Compiler Optimizations Fully Optimizing Compiler (FOC) FOC(P) = P opt P opt is the smallest program with same I/O behavior as P Observe If program Q produces no output and never halts, FOC(Q) = L: goto L Aha! We ve solved the halting problem?! Moral Cannot build FOC Can always build a better optimizing compiler (full employment theorem for compiler writers!) CIS570 Lecture 1 Introduction 17 CIS570 Lecture 1 8

Optimizations Don t Always Help Common Subexpression Elimination x = a + b t = a + b y = a + b x = t y = t 2 adds 1 add 4 variables 5 variables CIS570 Lecture 1 Introduction 18 Optimizations Don t Always Help (cont) Fusion and Contraction for i = 1 to n T[i] = A[i] + B[i] for i = 1 to n C[i] = D[i] + T[i] for i = 1 to n t = A[i] + B[i] C[i] = D[i] + t t fits in a register, so no loads or stores in this loop. Huge win on most machines. Degrades performance on machines with hardware managed stream buffers. CIS570 Lecture 1 Introduction 19 CIS570 Lecture 1 9

Optimizations Don t Always Help (cont) Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution of this statement, backpatching replaces the table lookup with a direct call to the proper function. Q: How could this optimization ever hurt? A: The Pentium 4 has a trace cache, when any instruction is modified, the entire trace cache has to be flushed. CIS570 Lecture 1 Introduction 20 Phase Ordering Problem In what order should optimizations be performed? Simple dependences One optimization creates opportunity for another e.g., copy propagation and dead code elimination Cyclic dependences e.g., constant folding and constant propagation Adverse interactions e.g., common subexpression elimination and register allocation e.g., register allocation and instruction scheduling CIS570 Lecture 1 Introduction 21 CIS570 Lecture 1 10

Engineering Issues Building a compiler is an engineering activity Balance multiple goals Benefit for typical programs Complexity of implementation Compilation speed Overall Goal Identify a small set of general analyses and optimization Easier said than done: just one more... CIS570 Lecture 1 Introduction 22 Beyond Optimization Security and Correctness Can we check whether pointers and addresses are valid? Can we detect when untrusted code accesses a sensitive part of a system? Can we detect whether locks are used properly? Can we use compilers to certify that code is correct? Can we use compilers to obfuscate code? CIS570 Lecture 1 Introduction 23 CIS570 Lecture 1 11

Next Time Reading Binary Translation by Sites et al. Lecture Undergraduate compilers in a day! CIS570 Lecture 1 Introduction 24 CIS570 Lecture 1 12