BEAMJIT, a Maze of Twisty Little Traces

Size: px
Start display at page:

Download "BEAMJIT, a Maze of Twisty Little Traces"

Transcription

1 BEAMJIT, a Maze of Twisty Little Traces A walk-through of the prototype just-in-time (JIT) compiler for Erlang. Frej Drejhammar <frej@sics.se>

2 Who am I? Senior researcher at the Swedish Institute of Computer Science (SICS) working on programming tools and distributed systems.

3 What this talk is About A brief introduction to the BEAM just-in-time compiler followed by a walk-through of last year s development.

4 Outline Background Just-In-Time Compilation BEAM: Specification & Implementation Project Goal Tools JIT:ing as it applies to BEAM The BEAM JIT Prototypes Future Work Acknowledgements & Questions

5 Just-In-Time (JIT) Compilation Decide at runtime to compile hot parts to native code. Fairly common implementation technique Python (Psyco, PyPy) Smalltalk (Cog) Java (HotSpot) JavaScript (SquirrelFish Extreme, SpiderMonkey)

6 BEAM: Specification & Implementation BEAM is the name of the Erlang VM. A register machine. Approximately 150 instructions which are specialized to approximately 450 macro-instructions using a peephole optimizer during code loading. Hand-written C (mostly) directly threaded interpreter. No authoritative description of the semantics of the VM except the implementation source code!

7 Project Goal Goals: Do as little manual work as possible. Preserve the semantics of plain BEAM. Automatically stay in sync with the plain BEAM, i.e. if bugs are fixed in the interpreter the JIT should not have to be modified manually. Have a native code generator which is state-of-the-art. Plan: Parse and extract semantics from the C implementation. Transform the parsed C source to C fragments which are then reassembled into a replacement interpreter which includes a JIT-compiler.

8 HiPE vs JIT Why would Erlang need a JIT-compiler, we already have HiPE? Cross module optimization. Native-code much larger than BEAM-code. Tracing does not require switching to full emulation. Modules stay target independent, simplifies deployment: No need for cross compilation. Binaries not strongly coupled to a particular build of the emulator.

9 Tools LLVM A Compiler Infrastructure, contains a collection of modular and reusable compiler and toolchain technologies. Uses a low-level assembler-like representation called LLVM-IR. Clang A mostly gcc-compatible front-end for C-like languages, produces LLVM-IR. libclang A C library built on top of Clang, allows the AST of a parsed C-module to be accessed and traversed.

10 Just-In-Time (JIT) Compilation as it Applies to BEAM Use light-weight profiling to detect when we are at a place which is frequently executed. Trace the flow of execution until we get back to the same place. Compile trace to native code. NOTE: We are tracing the execution flow in the interpreter, the granularity is finer than BEAM opcodes. Profile Trace Generate Native Code Run Native

11 BEAMJIT: What is Needed? Three basic execution modes Profiling Tracing Native Interpreter loop has to be modified to support mode switching: Turn on/off tracing. Passing state to/from native code. Native code generation: Need the semantics for each instruction.

12 Extracting the Semantics of the BEAM Opcodes bb_3944 bb_3950 i_bs_get_utf8_xfd is_function_fr bb_3784 bb_3788 bb_4130 bb_3776 bb_3783 i_bs_get_utf8_rfd bb_3936 bb_3794 bb_3792 bb_3790 i_bs_get_binary2_fxisid bb_4126 bb_3921 bb_4138 bb_4162 bb_3775 bb_4141 bb_4149 bb_4128 bb_4097 bb_4164 bb_3919 bb_3923 bb_4155 bb_3911 bb_4140 bb_4143 bb_3925 bb_4372 bb_4161 i_bs_get_binary2_frisid bb_4063 bb_4099 bb_4178 bb_4096 bb_4174 bb_4061 i_bs_skip_bits2_fxyi bb_4176 bb_4132 bb_4565 bb_4568 bb_4374 bb_4073 bb_4371 bb_4065 bb_4180 bb_4566 bb_4574 bb_4561 bb_4109 i_bs_get_float2_fxisid bb_4356 bb_4360 bb_4358 bb_4580 bb_4365 bb_4384 bb_4115 bb_4113 bb_4111 bb_4067 bb_4521 bb_4557 bb_4090 bb_4527 bb_4517 bb_4390 bb_4075 bb_4077 bb_4540 bb_4401 bb_4362 i_bs_skip_bits2_fxxi bb_4525 bb_4526 bb_4406 bb_4533 bb_4397 bb_4386 bb_4076 bb_4084 bb_4388 bb_4413 bb_4408 bb_4420 bb_2488 bb_3851 i_bs_skip_bits2_frxi bb_4405 bb_4486 bb_4493 i_bs_start_match2_rfiid i_bs_skip_bits2_fxri bb_4485 bb_4500 bb_3854 bb_4488 bb_4481 bb_4477 i_bs_get_integer_fiid i_bs_start_match2_yfiid i_bs_skip_bits2_fryi bb_4446 bb_4445 bb_4454 bb_4460 bb_3538 bb_4441 bb_4437 i_bs_start_match2_xfiid bb_4448 bb_3866 bb_3860 i_bs_match_string_xfii bb_4008 bb_3900 bb_3852 bb_4009 bb_4015 bb_4014 bb_4313 bb_4016 bb_3898 bb_4311 i_bs_match_string_rfii i_bs_get_float2_frisid bb_3872 bb_3894 bb_3896 bb_3883 bb_4343 bb_4315 bb_4320 bb_3884 bb_4326 bb_4339 bb_4327 bb_4329 bb_3878 do_is_ne_exact_literal bb_4345 bb_4317 bb_3847 bb_1636 bb_3880 i_is_ne_exact_literal_yfc bb_4341 bb_3762 bb_3745 bb_3746 bb_3752 bb_3758 bb_3764 bb_3584 bb_3753 bb_3760 Use libclang to parse and simplify the interpreter source: Flatten variable scopes. Remove loops, replace by if + goto. Make fall-troughs explicit. Turn structured C into a spaghetti of Basic Blocks (BB), CFG Control Flow Graph. Do liveness-analysis of variables.

13 Outline Background Just-In-Time Compilation BEAM: Specification & Implementation Project Goal Tools JIT:ing as it applies to BEAM The BEAM JIT Prototypes Future Work Acknowledgements & Questions

14 BEAMJIT Evolution Evolution since last year Mk. I (EUC 12) Mk. Ib MK. II MK. III Mk. IV (EUC 13)

15 BEAMJIT Mk. I: Profiling First step in figuring out what to JIT-compile Let Erlang compiler insert profile instructions at places which can be the head of a loop. Count the number of times a function is executed. Trigger tracing when count is high enough. Eventually everything is compiled, this is BAD. Requires implementing (by hand) the profile-instruction in the interpreter.

16 BEAMJIT Mk. I: Tracing Switch to a new version of the interpreter, generated from the CFG. For each basic block we pass through, record basic block identity and PC. Abort trace if too long. If we reach the profile instruction we started the trace from We have found a loop!

17 BEAMJIT Mk. I: Profiling to Tracing Mode Switch Direct threading PC 0xCDAADEF0 0xCDAADEFF 0xCDAACAF8 0xCDAAD432 0xDEADBEEF Indirect threading PC XCDAACAF8 x = x + 1;... Profiling Opcodes 95: 0xCBAADEF0 96: 0xCDAEDEFF 97: 0xCDAACAF8 98: 0xCDAAD432 99: 0xDEADBEEF Tracing Opcodes 95: 0xCBBADEF0 96: 0xCBAEDEFF 97: 0xCBAACAF8 98: 0xCBAAD432 99: 0xDBADBEEF 0XCDAACAF8 x = x + 1;... Have two implementations of each opcode. Switch the table of opcodes. 0XCBAACAF8 record_trace_bb(4711, PC) x = x + 1;...

18 BEAMJIT Mk. I: Cost of Indirect Threading

19 BEAMJIT Mk. I: Native-code Generation Glue together LLVM-IR-fragments for the trace. Guards are inserted to make sure we stay on the traced path. Hand the resulting IR off to LLVM. Fragments are extracted from the CFG as C-source, compiled to IR using clang (at build-time) and loaded during system initialization. jit_emu.c Trace beam_emu.c CFG Bitcode IR generator LLVM optimizer Native code fragments.c

20 BEAMJIT Mk. I: Calling Native Code Interpreter Native: Interpreter: Copy live variables to a structure. Native: Load vars into temporaries. Native Interpreter: The reverse. Jump to the BB to continue from.

21 BEAMJIT Mk. I: Performance Depressing performance. Running in pure interpreting mode, 6-7 times slower. x =...; if (x!= 0) x = x+ 1; else x = x - 1;... bb0: regx =... brz bb1, bb0... bb1: regx =... brz bb1, bb0 bb0: regx = load(@x) inc regx bb1: regx = load(@x) dec regx

22 BEAMJIT Mk. Ib: First Useful First version that could compile OTP without crashing and pass the test suite. Make profiler time-aware. Measure execution intensity by including timestamp, count is incremented if the function was executed recently, reset otherwise. Blacklist locations which: Never produce a successful trace. Where we leave the trace without executing the loop at least once. GC traces when they are no longer needed. Minor performance improvements.

23 BEAMJIT Mk. II: Make it Easy for the Compiler Modify the interpreter loop as little as possible. Have separate trace interpreter. Limit entry to the interpreter at instruction boundaries. Have separate cleanup-interpreter to continue execution to the next instruction boundary. Profiling Tracing Native Cleanup

24 BEAMJIT Mk. II: Implementation Tricks Use liveness information from the CFG. Package native-code as a function where the arguments are the live variables. The cleanup-interpreter is a set of functions, one for each BB, which tail-recursively calls the next BB. Arguments are the live variables.

25 BEAMJIT Mk. II: Performance Performance not stellar. Sensitive to placement in source-code. Should be possible to optimize further.

26 BEAMJIT Mk. III: Trace-Along Appears that we quite often compile a trace which is not representative. Ensure that we have a representative trace: Trace-Along Follow along a previously created trace. Abort trace if we diverge. Generate code when succeeded multiple times.

27 BEAMJIT Mk. IV: Multi-path We blacklist many locations where trace-along repeatedly fails to find a representative trace. Allow multi-path traces. Generate native code when the trace has not grown for N successive iterations. Slows down LLVM optimization and native code generation significantly.

28 BEAMJIT Mk. IV: Trace Compression LLVM slowdown appears to be related to the size of the CFG. Inspection of traces shows loops and common segments. Compress traces to remove shared segments. BB=0 ip=0x4567 BB=0 ip=0x4567 BB=1 ip=0x4567 BB=2 ip=0x4567 BB=1 ip=0x4567 BB=2 ip=0x4567 BB=3 ip=0x4568 BB=3 ip=0x4568 BB=3 ip=0x4568 BB=4 ip=0x4569 BB=4 ip=0x4569 BB=4 ip=0x4569

29 BEAMJIT Mk. IV: Performance Compilation overhead dwarfs everything else (-O2). Future work: Figure out which optimization passes are needed.

30 BEAMJIT Mk. IV: Performance (cont.)

31 BEAMJIT Mk. IV: Performance (cont.) Guards costly. Not good where the common case cannot be on the fast path

32 Future Work Do not fixate on finding loops Allow traces which are runs rather than loops, ring benchmarks. Erlang-aware constant propagation: Eliminate loads from code (constant at compile time). Will eliminate loading of immediates. Will eliminate many of the guards. Increase performance in plain interpreting mode. Run native-code generation in separate thread. Extend trace outside the main interpreter loop, inside BIFs.

33 Outline Background Just-In-Time Compilation BEAM: Specification & Implementation Project Goal Tools JIT:ing as it applies to BEAM The BEAM JIT Prototypes Future Work Acknowledgements & Questions

34 Acknowledgements This work is funded by Ericsson AB.

35 Questions?

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar

BEAMJIT: An LLVM based just-in-time compiler for Erlang. Frej Drejhammar BEAMJIT: An LLVM based just-in-time compiler for Erlang Frej Drejhammar 140407 Who am I? Senior researcher at the Swedish Institute of Computer Science (SICS) working on programming languages,

More information

A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine. Frej Drejhammar and Lars Rasmusson

A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine. Frej Drejhammar and Lars Rasmusson A Status Update of BEAMJIT, the Just-in-Time Compiling Abstract Machine Frej Drejhammar and Lars Rasmusson 140609 Who am I? Senior researcher at the Swedish Institute of Computer Science

More information

Intermediate Code & Local Optimizations

Intermediate Code & Local Optimizations Lecture Outline Intermediate Code & Local Optimizations Intermediate code Local optimizations Compiler Design I (2011) 2 Code Generation Summary We have so far discussed Runtime organization Simple stack

More information

Accelerating Ruby with LLVM

Accelerating Ruby with LLVM Accelerating Ruby with LLVM Evan Phoenix Oct 2, 2009 RUBY RUBY Strongly, dynamically typed RUBY Unified Model RUBY Everything is an object RUBY 3.class # => Fixnum RUBY Every code context is equal RUBY

More information

PyPy - How to not write Virtual Machines for Dynamic Languages

PyPy - How to not write Virtual Machines for Dynamic Languages PyPy - How to not write Virtual Machines for Dynamic Languages Institut für Informatik Heinrich-Heine-Universität Düsseldorf ESUG 2007 Scope This talk is about: implementing dynamic languages (with a focus

More information

ART JIT in Android N. Xueliang ZHONG Linaro ART Team

ART JIT in Android N. Xueliang ZHONG Linaro ART Team ART JIT in Android N Xueliang ZHONG Linaro ART Team linaro-art@linaro.org 1 Outline Android Runtime (ART) and the new challenges ART Implementation in Android N Tooling Performance Data & Findings Q &

More information

Introduction. CS 2210 Compiler Design Wonsun Ahn

Introduction. CS 2210 Compiler Design Wonsun Ahn Introduction CS 2210 Compiler Design Wonsun Ahn What is a Compiler? Compiler: A program that translates source code written in one language to a target code written in another language Source code: Input

More information

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment

ECE 5775 (Fall 17) High-Level Digital Design Automation. Static Single Assignment ECE 5775 (Fall 17) High-Level Digital Design Automation Static Single Assignment Announcements HW 1 released (due Friday) Student-led discussions on Tuesday 9/26 Sign up on Piazza: 3 students / group Meet

More information

CSc 453 Interpreters & Interpretation

CSc 453 Interpreters & Interpretation CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson Interpreters An interpreter is a program that executes another program. An interpreter implements a virtual machine,

More information

Truffle A language implementation framework

Truffle A language implementation framework Truffle A language implementation framework Boris Spasojević Senior Researcher VM Research Group, Oracle Labs Slides based on previous talks given by Christian Wimmer, Christian Humer and Matthias Grimmer.

More information

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction Lecture content TDDA69 Data and Program Structure Introduction Cyrille Berger Course Introduction to the different Programming Paradigm The different programming paradigm Why different paradigms? Introduction

More information

Intermediate Code & Local Optimizations. Lecture 20

Intermediate Code & Local Optimizations. Lecture 20 Intermediate Code & Local Optimizations Lecture 20 Lecture Outline Intermediate code Local optimizations Next time: global optimizations 2 Code Generation Summary We have discussed Runtime organization

More information

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. IR Generation Announcements My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. This is a hard deadline and no late submissions will be

More information

Just-In-Time Compilation

Just-In-Time Compilation Just-In-Time Compilation Thiemo Bucciarelli Institute for Software Engineering and Programming Languages 18. Januar 2016 T. Bucciarelli 18. Januar 2016 1/25 Agenda Definitions Just-In-Time Compilation

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Outline Smalltalk Overview Pragmatic Smalltalk Closing. Pragmatic Smalltalk. David Chisnall. February 7,

Outline Smalltalk Overview Pragmatic Smalltalk Closing. Pragmatic Smalltalk. David Chisnall. February 7, February 7, 2009 http://etoileos.com Outline Using The Smalltalk Family Smalltalk - first dynamic, object-oriented, language. Self - Smalltalk without classes. JavaScript - Self with Java syntax. A Quick

More information

Trace-based JIT Compilation

Trace-based JIT Compilation Trace-based JIT Compilation Hiroshi Inoue, IBM Research - Tokyo 1 Trace JIT vs. Method JIT https://twitter.com/yukihiro_matz/status/533775624486133762 2 Background: Trace-based Compilation Using a Trace,

More information

Just-In-Time Compilers & Runtime Optimizers

Just-In-Time Compilers & Runtime Optimizers COMP 412 FALL 2017 Just-In-Time Compilers & Runtime Optimizers Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved.

More information

Intermediate Representation (IR)

Intermediate Representation (IR) Intermediate Representation (IR) Components and Design Goals for an IR IR encodes all knowledge the compiler has derived about source program. Simple compiler structure source code More typical compiler

More information

Executing Legacy Applications on a Java Operating System

Executing Legacy Applications on a Java Operating System Executing Legacy Applications on a Java Operating System Andreas Gal, Michael Yang, Christian Probst, and Michael Franz University of California, Irvine {gal,mlyang,probst,franz}@uci.edu May 30, 2004 Abstract

More information

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto)

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto) YETI GraduallY Extensible Trace Interpreter Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto) VEE 2007 1 Goal Create a VM that is more easily extended with a just

More information

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler

More information

INTRODUCTION TO LLVM Bo Wang SA 2016 Fall

INTRODUCTION TO LLVM Bo Wang SA 2016 Fall INTRODUCTION TO LLVM Bo Wang SA 2016 Fall LLVM Basic LLVM IR LLVM Pass OUTLINE What is LLVM? LLVM is a compiler infrastructure designed as a set of reusable libraries with well-defined interfaces. Implemented

More information

The HALFWORD HEAP EMULATOR

The HALFWORD HEAP EMULATOR The HALFWORD HEAP EMULATOR EXPLORING A VIRTUAL MACHINE patrik Nyblom, Ericsson ab pan@erlang.org The Beam Virtual Machine Björns/Bogdans Erlang Abstract Machine Has evolved over the years and is a joint

More information

Design & Implementation Overview

Design & Implementation Overview P Fall 2017 Outline P 1 2 3 4 5 6 7 P P Ontological commitments P Imperative l Architecture: Memory cells variables Data movement (memory memory, CPU memory) assignment Sequential machine instruction execution

More information

Compiler Design Spring 2018

Compiler Design Spring 2018 Compiler Design Spring 2018 Thomas R. Gross Computer Science Department ETH Zurich, Switzerland 1 Logistics Lecture Tuesdays: 10:15 11:55 Thursdays: 10:15 -- 11:55 In ETF E1 Recitation Announced later

More information

Evolution of Virtual Machine Technologies for Portability and Application Capture. Bob Vandette Java Hotspot VM Engineering Sept 2004

Evolution of Virtual Machine Technologies for Portability and Application Capture. Bob Vandette Java Hotspot VM Engineering Sept 2004 Evolution of Virtual Machine Technologies for Portability and Application Capture Bob Vandette Java Hotspot VM Engineering Sept 2004 Topics Virtual Machine Evolution Timeline & Products Trends forcing

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler Hiroshi Inoue, Hiroshige Hayashizaki, Peng Wu and Toshio Nakatani IBM Research Tokyo IBM Research T.J. Watson Research Center April

More information

What do Compilers Produce?

What do Compilers Produce? What do Compilers Produce? Pure Machine Code Compilers may generate code for a particular machine, not assuming any operating system or library routines. This is pure code because it includes nothing beyond

More information

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1 SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine David Bélanger dbelan2@cs.mcgill.ca Sable Research Group McGill University Montreal, QC January 28, 2004 SABLEJIT: A Retargetable

More information

Lecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations

Lecture Outline. Intermediate code Intermediate Code & Local Optimizations. Local optimizations. Lecture 14. Next time: global optimizations Lecture Outline Intermediate code Intermediate Code & Local Optimizations Lecture 14 Local optimizations Next time: global optimizations Prof. Aiken CS 143 Lecture 14 1 Prof. Aiken CS 143 Lecture 14 2

More information

Sista: Improving Cog s JIT performance. Clément Béra

Sista: Improving Cog s JIT performance. Clément Béra Sista: Improving Cog s JIT performance Clément Béra Main people involved in Sista Eliot Miranda Over 30 years experience in Smalltalk VM Clément Béra 2 years engineer in the Pharo team Phd student starting

More information

HiPE Copyright Ericsson AB. All Rights Reserved. HiPE March 11, 2019

HiPE Copyright Ericsson AB. All Rights Reserved. HiPE March 11, 2019 Copyright 2006-2019 Ericsson AB. All Rights Reserved. 3.18.3 March 11, 2019 Copyright 2006-2019 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may

More information

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace Project there are a couple of 3 person teams regroup or see me or forever hold your peace a new drop with new type checking is coming using it is optional 1 Compiler Architecture source code Now we jump

More information

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Administration Design reports due Friday Current demo schedule on web page send mail with preferred times if you haven

More information

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization. Where We Are Source Code Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Machine Code Where We Are Source Code Lexical Analysis Syntax Analysis

More information

Intermediate Representations

Intermediate Representations COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

An Assembler for the MSSP Distiller Eric Zimmerman University of Illinois, Urbana Champaign

An Assembler for the MSSP Distiller Eric Zimmerman University of Illinois, Urbana Champaign An Assembler for the MSSP Distiller Eric Zimmerman University of Illinois, Urbana Champaign Abstract It is important to have a means of manually testing a potential optimization before laboring to fully

More information

VA Smalltalk 9: Exploring the next-gen LLVM-based virtual machine

VA Smalltalk 9: Exploring the next-gen LLVM-based virtual machine 2017 FAST Conference La Plata, Argentina November, 2017 VA Smalltalk 9: Exploring the next-gen LLVM-based virtual machine Alexander Mitin Senior Software Engineer Instantiations, Inc. The New VM Runtime

More information

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

CPSC 3740 Programming Languages University of Lethbridge. Control Structures Control Structures A control structure is a control statement and the collection of statements whose execution it controls. Common controls: selection iteration branching Control Structures 1 15 Howard

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages

More information

Summary: Open Questions:

Summary: Open Questions: Summary: The paper proposes an new parallelization technique, which provides dynamic runtime parallelization of loops from binary single-thread programs with minimal architectural change. The realization

More information

IBM Research - Tokyo 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術. Trace Compilation IBM Corporation

IBM Research - Tokyo 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術. Trace Compilation IBM Corporation 数理 計算科学特論 C プログラミング言語処理系の最先端実装技術 Trace Compilation Trace JIT vs. Method JIT https://twitter.com/yukihiro_matz/status/533775624486133762 2 Background: Trace-based Compilation Using a Trace, a hot path identified

More information

Compiler-guaranteed Safety in Code-copying Virtual Machines

Compiler-guaranteed Safety in Code-copying Virtual Machines Compiler-guaranteed Safety in Code-copying Virtual Machines Gregory B. Prokopski Clark Verbrugge School of Computer Science Sable Research Group McGill University Montreal, Canada International Conference

More information

1 Little Man Computer

1 Little Man Computer 1 Little Man Computer Session 5 Reference Notes CPU Architecture and Assembly 1.1 Versions Little Man Computer is a widely used simulator of a (very simple) computer. There are a number of implementations.

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

High-Level Language VMs

High-Level Language VMs High-Level Language VMs Outline Motivation What is the need for HLL VMs? How are these different from System or Process VMs? Approach to HLL VMs Evolutionary history Pascal P-code Object oriented HLL VMs

More information

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

More information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

Other Forms of Intermediate Code. Local Optimizations. Lecture 34

Other Forms of Intermediate Code. Local Optimizations. Lecture 34 Other Forms of Intermediate Code. Local Optimizations Lecture 34 (Adapted from notes by R. Bodik and G. Necula) 4/18/08 Prof. Hilfinger CS 164 Lecture 34 1 Administrative HW #5 is now on-line. Due next

More information

Administrative. Other Forms of Intermediate Code. Local Optimizations. Lecture 34. Code Generation Summary. Why Intermediate Languages?

Administrative. Other Forms of Intermediate Code. Local Optimizations. Lecture 34. Code Generation Summary. Why Intermediate Languages? Administrative Other Forms of Intermediate Code. Local Optimizations HW #5 is now on-line. Due next Friday. If your test grade is not glookupable, please tell us. Please submit test regrading pleas to

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

Interprocedural Type Specialization of JavaScript Programs Without Type Analysis

Interprocedural Type Specialization of JavaScript Programs Without Type Analysis Interprocedural Type Specialization of JavaScript Programs Without Type Analysis Maxime Chevalier-Boisvert joint work with Marc Feeley ECOOP - July 20th, 2016 Overview Previous work: Lazy Basic Block Versioning

More information

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011 Étoilé Pragmatic Smalltalk David Chisnall August 25, 2011 Smalltalk is Awesome! Pure object-oriented system Clean, simple syntax Automatic persistence and many other great features ...but no one cares

More information

Dynamic Languages Strike Back. Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008

Dynamic Languages Strike Back. Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008 Dynamic Languages Strike Back Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008 What is this talk about? Popular opinion of dynamic languages: Unfixably slow Not possible to create IDE-quality

More information

Trace Compilation. Christian Wimmer September 2009

Trace Compilation. Christian Wimmer  September 2009 Trace Compilation Christian Wimmer cwimmer@uci.edu www.christianwimmer.at September 2009 Department of Computer Science University of California, Irvine Background Institute for System Software Johannes

More information

Lecture 3 Overview of the LLVM Compiler

Lecture 3 Overview of the LLVM Compiler LLVM Compiler System Lecture 3 Overview of the LLVM Compiler The LLVM Compiler Infrastructure - Provides reusable components for building compilers - Reduce the time/cost to build a new compiler - Build

More information

Computer Organization & Assembly Language Programming

Computer Organization & Assembly Language Programming Computer Organization & Assembly Language Programming CSE 2312 Lecture 11 Introduction of Assembly Language 1 Assembly Language Translation The Assembly Language layer is implemented by translation rather

More information

CS 241 Honors Memory

CS 241 Honors Memory CS 241 Honors Memory Ben Kurtovic Atul Sandur Bhuvan Venkatesh Brian Zhou Kevin Hong University of Illinois Urbana Champaign February 20, 2018 CS 241 Course Staff (UIUC) Memory February 20, 2018 1 / 35

More information

IR Optimization. May 15th, Tuesday, May 14, 13

IR Optimization. May 15th, Tuesday, May 14, 13 IR Optimization May 15th, 2013 Tuesday, May 14, 13 But before we talk about IR optimization... Wrapping up IR generation Tuesday, May 14, 13 Three-Address Code Or TAC The IR that you will be using for

More information

McSema: Static Translation of X86 Instructions to LLVM

McSema: Static Translation of X86 Instructions to LLVM McSema: Static Translation of X86 Instructions to LLVM ARTEM DINABURG, ARTEM@TRAILOFBITS.COM ANDREW RUEF, ANDREW@TRAILOFBITS.COM About Us Artem Security Researcher blog.dinaburg.org Andrew PhD Student,

More information

Intermediate Representations

Intermediate Representations Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end

More information

Mixed Mode Execution with Context Threading

Mixed Mode Execution with Context Threading Mixed Mode Execution with Context Threading Mathew Zaleski, Marc Berndl, Angela Demke Brown University of Toronto {matz,berndl,demke}@cs.toronto.edu (CASCON 2005, Oct 19/2005.) Overview Introduction Background:

More information

History of Compilers The term

History of Compilers The term History of Compilers The term compiler was coined in the early 1950s by Grace Murray Hopper. Translation was viewed as the compilation of a sequence of machine-language subprograms selected from a library.

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

Building Binary Optimizer with LLVM

Building Binary Optimizer with LLVM Building Binary Optimizer with LLVM Maksim Panchenko maks@fb.com BOLT Binary Optimization and Layout Tool Built in less than 6 months x64 Linux ELF Runs on large binary (HHVM, non-jitted part) Improves

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Lecture 23 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week Fri at 11am No Class

More information

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz

Compiler Design. Fall Control-Flow Analysis. Prof. Pedro C. Diniz Compiler Design Fall 2015 Control-Flow Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292

More information

Multi-dimensional Arrays

Multi-dimensional Arrays Multi-dimensional Arrays IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula) A 2D array is a 1D array of 1D arrays Java uses arrays of pointers to arrays for >1D

More information

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code BILL BLUNDEN Apress About the Author Acknowledgments Introduction xi xiii xv Chapter 1 Preventative Medicine 1 1.1 Core Problems 2

More information

Program verification. Generalities about software Verification Model Checking. September 20, 2016

Program verification. Generalities about software Verification Model Checking. September 20, 2016 Program verification Generalities about software Verification Model Checking Laure Gonnord David Monniaux September 20, 2016 1 / 43 The teaching staff Laure Gonnord, associate professor, LIP laboratory,

More information

Dynamically-typed Languages. David Miller

Dynamically-typed Languages. David Miller Dynamically-typed Languages David Miller Dynamically-typed Language Everything is a value No type declarations Examples of dynamically-typed languages APL, Io, JavaScript, Lisp, Lua, Objective-C, Perl,

More information

Dynamic Binary Translation for Generation of Cycle AccurateOctober Architecture 28, 2008 Simulators 1 / 1

Dynamic Binary Translation for Generation of Cycle AccurateOctober Architecture 28, 2008 Simulators 1 / 1 Dynamic Binary Translation for Generation of Cycle Accurate Architecture Simulators Institut für Computersprachen Technische Universtät Wien Austria Andreas Fellnhofer Andreas Krall David Riegler Part

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Languages and Compiler Design II IR Code Optimization

Languages and Compiler Design II IR Code Optimization Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda IR Optimization

More information

CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages CSc 520 Principles of Programming Languages 44: Interpreters Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg [1] Compiler

More information

The State of TclQuadcode

The State of TclQuadcode The State of TclQuadcode Kevin B. Kenny Donal K. Fellows Tcl Core Team 24 th Annual Tcl/Tk Conference 16-20 October 2017 What TclQuadcode is: Native code compiler for Tcl Procedures only Not yet methods,

More information

LLVM Summer School, Paris 2017

LLVM Summer School, Paris 2017 LLVM Summer School, Paris 2017 David Chisnall June 12 & 13 Setting up You may either use the VMs provided on the lab machines or your own computer for the exercises. If you are using your own machine,

More information

Combining Analyses, Combining Optimizations - Summary

Combining Analyses, Combining Optimizations - Summary Combining Analyses, Combining Optimizations - Summary 1. INTRODUCTION Cliff Click s thesis Combining Analysis, Combining Optimizations [Click and Cooper 1995] uses a structurally different intermediate

More information

The VMKit project: Java (and.net) on top of LLVM

The VMKit project: Java (and.net) on top of LLVM The VMKit project: Java (and.net) on top of LLVM Nicolas Geoffray Université Pierre et Marie Curie, France nicolas.geoffray@lip6.fr What is VMKit? Glue between existing VM components LLVM, GNU Classpath,

More information

CS553 Lecture Dynamic Optimizations 2

CS553 Lecture Dynamic Optimizations 2 Dynamic Optimizations Last time Predication and speculation Today Dynamic compilation CS553 Lecture Dynamic Optimizations 2 Motivation Limitations of static analysis Programs can have values and invariants

More information

Cog VM Evolution. Clément Béra. Thursday, August 25, 16

Cog VM Evolution. Clément Béra. Thursday, August 25, 16 Cog VM Evolution Clément Béra Cog VM? Smalltalk virtual machine Default VM for Pharo Squeak Newspeak Cuis Cog Philosophy Open source (MIT) Simple Is the optimization / feature worth the added complexity?

More information

A Method-Based Ahead-of-Time Compiler For Android Applications

A Method-Based Ahead-of-Time Compiler For Android Applications A Method-Based Ahead-of-Time Compiler For Android Applications Fatma Deli Computer Science & Software Engineering University of Washington Bothell November, 2012 2 Introduction This paper proposes a method-based

More information

CS 406/534 Compiler Construction Putting It All Together

CS 406/534 Compiler Construction Putting It All Together CS 406/534 Compiler Construction Putting It All Together Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith Cooper, Prof. Ken Kennedy

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

Compilers and Code Optimization EDOARDO FUSELLA

Compilers and Code Optimization EDOARDO FUSELLA Compilers and Code Optimization EDOARDO FUSELLA Contents LLVM The nu+ architecture and toolchain LLVM 3 What is LLVM? LLVM is a compiler infrastructure designed as a set of reusable libraries with well

More information

Lecture 15: Iteration and Recursion

Lecture 15: Iteration and Recursion Lecture 15: and Recursion The University of North Carolina at Chapel Hill Spring 2002 Lecture 15: and Recursion Feb 13/15 1 Control Flow Mechanisms Sequencing Textual order, Precedence in Expression Selection

More information

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters CSc 453 Compiler source Lexer tokens Parser AST Compilers and Systems Software 18 : Interpreters VM Code Gen IR Interm. Code Gen AST Semantic Analyser Department of Computer Science University of Arizona

More information

Titan: A System Programming Language made for Lua

Titan: A System Programming Language made for Lua Titan: A System Programming Language made for Lua Hugo Musso Gualandi, PUC-Rio in collaboration with André Maidl, Fabio Mascarenhas, Gabriel Ligneul and Hisham Muhammad Part 1: Why Titan We started out

More information

XDP Hardware Offload: Current Work, Debugging and Edge Cases

XDP Hardware Offload: Current Work, Debugging and Edge Cases XDP Hardware Offload: Current Work, Debugging and Edge Cases Jakub Kicinski, Nicolaas Viljoen Netronome Systems Santa Clara, United States jakub.kicinski@netronome.com, nick.viljoen@netronome.com Abstract

More information

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax

More information

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation Prelude COMP 181 Lecture 14 Intermediate representations and code generation October 19, 2006 Who is Seth Lloyd? Professor of mechanical engineering at MIT, pioneer in quantum computing Article in Nature:

More information

Towards An Adaptive Framework for Performance Portability

Towards An Adaptive Framework for Performance Portability Towards An Adaptive Framework for Performance Portability Work in Progress (submission #23) Patrick Maier Magnus Morton Phil Trinder School of Computing Science University of Glasgow IFL 25 Maier, Morton,

More information

Towards Ruby3x3 Performance

Towards Ruby3x3 Performance Towards Ruby3x3 Performance Introducing RTL and MJIT Vladimir Makarov Red Hat September 21, 2017 Vladimir Makarov (Red Hat) Towards Ruby3x3 Performance September 21, 2017 1 / 30 About Myself Red Hat, Toronto

More information

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2

Building a Compiler with. JoeQ. Outline of this lecture. Building a compiler: what pieces we need? AKA, how to solve Homework 2 Building a Compiler with JoeQ AKA, how to solve Homework 2 Outline of this lecture Building a compiler: what pieces we need? An effective IR for Java joeq Homework hints How to Build a Compiler 1. Choose

More information

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Intermediate representations and code generation Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Today Intermediate representations and code generation Scanner Parser Semantic

More information

Parley: Federated Virtual Machines

Parley: Federated Virtual Machines 1 IBM Research Parley: Federated Virtual Machines Perry Cheng, Dave Grove, Martin Hirzel, Rob O Callahan and Nikhil Swamy VEE Workshop September 2004 2002 IBM Corporation What is Parley? Motivation Virtual

More information