Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University

Size: px
Start display at page:

Download "Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University"

Transcription

1 Fall Compiler Principles Lecture 12: Register Allocation Roman Manevich Ben-Gurion University

2 Syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering Local Optimizations Register Allocation Top-down Parsing (LL) Dataflow Analysis Bottom-up Parsing (LR) Loop Optimizations mid-term exam 2

3 Previously Dataflow framework Conditions for termination Finite lattice height Monotone transfer functions Loop optimizations 3

4 agenda The need for register allocation Global register allocation 4

5 Register allocation motivation 5

6 Registers Most machines have a set of registers, dedicated memory locations that can be accessed quickly, can have computations performed on them, and exist in small quantity Using registers intelligently is a critical step in any compiler A good register allocator can generate code orders of magnitude better than a bad register allocator 6

7 Register allocation In TAC, there are an unlimited number of variables On a physical machine there are a small number of registers: x86 has four general-purpose registers and a number of specialized registers MIPS has twenty-four general-purpose registers and eight special-purpose registers Register allocation is the process of assigning variables to registers and managing data transfer in and out of registers 7

8 Challenges in register allocation Registers are scarce Often substantially more IR variables than registers Need to find a way to reuse registers whenever possible Registers are complicated x86: Each register made of several smaller registers; can't use a register and its constituent registers at the same time x86: Certain instructions must store their results in specific registers; can't store values there if you want to use those instructions MIPS: Some registers reserved for the assembler or operating system Most architectures: Some registers must be preserved across function calls 8

9 naive register allocation 9

10 Simple approach Straightforward solution: Allocate each variable in activation record At each instruction: bring values needed into registers (rematerialization), perform operation, then store result to memory x = y + z mov 16(%ebp), %eax mov 20(%ebp), %ebx add %ebx, %eax mov %eax, 24(%ebx) Problem: program execution very inefficient moving data back and forth between memory and registers 10

11 Reusing registers 11

12 Find a register allocation variable a b c register??? register eax ebx b = a + 2 c = b * b b = c + 1 return b * a 12

13 Is this a valid allocation? variable register register a b c b = a + 2 eax ebx eax eax ebx ebx = eax + 2 Overwrites previous value of a also stored in eax c = b * b eax = ebx * ebx b = c + 1 ebx = eax + 1 return b * a return ebx * eax 13

14 Is this a valid allocation? variable a b c register ebx eax eax register eax ebx b = a + 2 c = b * b b = c + 1 return b * a eax = ebx + 2 eax = eax * eax eax = eax + 1 return eax * ebx Value of c stored in eax is not needed anymore so reuse it for b 14

15 Register interference graph 15

16 Main idea For every node n in CFG, we have out[n] Set of temporaries live out of n Two variables interfere if they appear in the same out[n] of any node n Cannot be allocated to the same register Conversely, if two variables do not interfere with each other, they can be assigned the same register We say they have disjoint live ranges How to assign registers to variables? 16

17 Interference graph Nodes of the graph = variables Edges connect variables that interfere with one another Nodes will be assigned a color corresponding to the register assigned to the variable Two colors can t be next to one another in the graph 17

18 Liveness analysis b = a + 2 c = b * b b = c + 1 return b * a 18

19 Liveness analysis b = a + 2 c = b * b b = c + 1 return b * a {b, a} 19

20 Liveness analysis b = a + 2 c = b * b b = c + 1 return b * a {a, c} {b, a} 20

21 Liveness analysis b = a + 2 c = b * b b = c + 1 return b * a {b, a} {a, c} {b, a} 21

22 Liveness analysis b = a + 2 c = b * b b = c + 1 return b * a {a} {b, a} {a, c} {b, a} 22

23 Interference graph color register b = a + 2 c = b * b b = c + 1 return b * a {a} {b, a} {a, c} {b, a} a eax ebx b c 23

24 Colored graph color register b = a + 2 c = b * b b = c + 1 return b * a {a} {b, a} {a, c} {b, a} a eax ebx b c 24

25 25

26 26

27 Graph coloring 27

28 Graph coloring This problem is equivalent to graph-coloring, which is NP-hard if there are at least three registers No good polynomial-time algorithms (or even good approximations!) are known for this problem We have to be content with a heuristic that is good enough for RIGs that arise in practice (or do we.?) 28

29 Coloring by simplification [Kempe 1879] How to find a K-coloring of a graph Intuition: Suppose we are trying to K-color a graph and find a node with fewer than K edges If we delete this node from the graph and color what remains, we can find a color for this node if we add it back in Reason: fewer than K neighbors some color must be left over 29

30 Coloring by simplification [Kempe 1879] How to find a K-coloring of a graph Phase 1: Simplify Repeatedly simplify graph When a variable (i.e., graph node) is removed, push it on a stack Phase 2: Select Unwind stack and reconstruct the graph as follows: Pop variable from the stack Add it back to the graph Color the node for that variable with a color that it doesn t interfere with simplify select 30

31 Coloring example 31

32 Coloring for K=2 color register eax ebx a stack: b c d e 32

33 Coloring for K=2 color register eax ebx a stack: b c d e c 33

34 Coloring for K=2 color register eax ebx a d b e c stack: e c 34

35 Coloring for K=2 color register eax ebx a d b e c stack: a e c 35

36 Coloring for K=2 color register eax ebx a d b e c stack: b a e c 36

37 Coloring for K=2 color register eax ebx a d b e c stack: d b a e c 37

38 Coloring for K=2 color register eax ebx a stack: d b e c b a e c 38

39 Coloring for K=2 color register eax ebx a d b e c stack: a e c 39

40 Coloring for K=2 color register eax ebx a stack: b c d e e c 40

41 Coloring for K=2 color register eax ebx a stack: b c d e c 41

42 Coloring for K=2 color register eax ebx a stack: b c d e 42

43 spilling 43

44 Failure of heuristic If the graph cannot be colored, it will eventually be simplified to graph in which every node has at least K neighbors Sometimes, the graph is still K-colorable! Finding a K-coloring in all situations is an NP-complete problem We will have to approximate to make register allocators fast enough 44

45 Coloring for K=2 color register eax ebx a stack: b c d e 45

46 Coloring for K=2 color register eax ebx Some graphs can t be colored in K colors: a d b e c stack: c b e a d 46

47 Coloring for K=2 color register eax ebx Some graphs can t be colored in K colors: a d b e c stack: b e a d 47

48 Coloring for K=2 color register eax ebx Some graphs can t be colored in K colors: a b c stack: e a d d e 48

49 Coloring for K=2 color register eax ebx Some graphs can t be colored in K colors: a b c stack: e a d d e no colors left for e! What can we do? 49

50 Chaitin s algorithm [CC 82] Choose and remove an arbitrary node, marking it troublesome Use heuristics to choose which one:? When adding node back in, it may be possible to find a valid color Otherwise, we have to spill that node 50

51 Chaitin s algorithm [CC 82] Choose and remove an arbitrary node, marking it troublesome Use heuristics to choose which one: spill priority = (uo + 10 ui) / deg uo = #use+defs outside of loop ui = #use+defs inside of loop When adding node back in, it may be possible to find a valid color Otherwise, we have to spill that node (lowest priority) 51

52 Spilling Phase 3: Spill once all nodes have K or more neighbors, pick a node for spilling There are many heuristics that can be used to pick a node Try to pick node not used much, not in inner loop Assign its storage to activation record Remove it from graph and mark it as potential spill (technically, push on a spill stack) We can now repeat phases 1-2 without this node 52

53 Chaitin s algorithm [CC 82] Phase 1: Simplify Phase 2: Select Unwind stack and reconstruct the graph as follows: Pop (non-spill) variable from the stack Add it back to the graph Color the node for that variable with a color that it doesn t interfere with its neighbors Unwind spill stack Pop spill variable If there is an available color add back to graph Otherwise mark variable as actual spill Phase 3: Spill If all nodes have K or more neighbors, pick a heavy node for spilling and add to potential spill stack Phase 4: Rewrite Rewrite code for actual spill variables Recompute liveness information Repeat phases

54 Chaitin s algorithm [CC 82] any potential spill done Simplify Liveness analysis Mark potential spills Select colors and detect actual spills any actual spill done Rewrite code to implement actual spills 54

55 Spill example (for K=2) color register eax ebx a b c stack: e a d d e no colors left for e! 55

56 Spill example (for K=2) color register eax ebx a d b e c stack: b e a d 56

57 Spill example (for K=2) color register eax ebx a b c stack: e a d d e 57

58 Spill example (for K=2) color register eax ebx a b c stack: a d d e 58

59 Spill example (for K=2) color register eax ebx a b c stack: d d e 59

60 Spill example (for K=2) color register eax ebx a stack: b c d e 60

61 Register constraints 61

62 Handling precolored nodes Some variables are pre-assigned to registers e.g.: mul on x86/pentium Uses eax; defines eax, edx e.g.: call on x86/pentium Defines (trashes) caller-save registers eax, ecx, edx To properly allocate registers, treat these register uses as special temporary variables and enter into interference graph as precolored nodes 62

63 Handling precolored nodes Simplify. Never remove a pre-colored node it already has a color, i.e., it is a given register Select. Once simplified graph has all colored nodes, add other nodes back in and color them using precolored nodes as starting point 63

64 Optimizing moves 64

65 Optimizing move instructions Code generation produces a lot of extra MOVE instructions MOVE t5, t9 If we can assign t5 and t9 to same register, we can get rid of the MOVE effectively, copy propagation at the register allocation level Idea: if t5 and t9 are not connected in inference graph, coalesce them into a single variable; the move will be redundant 65

66 RIG with MOVE edges Add a second type of edges MOVE edges color register eax ebx a b c d e 66

67 Coalescing Problem: coalescing nodes can make a graph un-colorable Conservative coalescing heuristic MOVE coalesce a b a/b What should we do? 67

68 Conservative coalescing Coalesce MOVE edge (a,b) if it does not affect colorability A node is heavy if its degree is K and light otherwise Briggs criterion: coalesce only if the merged node ab has <K nodes heavy nodes Reason: Simplify will first remove all light neighbors ab will then be adjacent to <K neighbors Simplify can remove ab 68

69 Conservative coalescing Coalesce MOVE edge (a,b) if it does not affect colorability A node is heavy if its degree is K and light otherwise George criterion: coalesce only if all heavy neighbors of a are also neighbors of b Reason: Simplify can remove all light neighbors of a Remaining heavy neighbors of a are neighbors of b so coalescing does not increase the degree of any node 69

70 Coalescing criterion example By the Briggs criterion? #(heavy-neighbors(a,e) < K By the George criterion? All heavy neighbors of a are also neighbors of e a Can we coalesce (a,e)? color register b c eax ebx e 70

71 Coalescing criterion example By the Briggs criterion? NO #(heavy-neighbors(a,e) < K By the George criterion? YES All heavy neighbors of a are also neighbors of e a Can we coalesce (a,e)? color register b c eax ebx e 71

72 Simplify, coalesce and freeze Phase 1: Simplify Step 1 (simplify): simplify as much as possible without removing nodes that are the source or destination of a move (MOVE-related nodes) Step 2 (coalesce): coalesce a MOVE-related edge provided low-degree node results Step 3 (freeze): if neither steps 1 or 2 apply, freeze a MOVE instruction: low-degree nodes involved are marked not MOVE-related (remove MOVE edge) and try step 1 again Step 4 (spill): if all nodes are heavy select a candidate for spilling using a priority function and move to potential spill stack Phase 2: Select Unwind stack and reconstruct the graph as follows: Pop variable from the stack Add it back to the graph Color the node node with a color that it doesn t interfere with Unwind potential spill stack and attempt to color node if unable mark corresponding variable as actual spill Phase 4: Rewrite Allocate position in frame for spilled variable v On each usage of v load to v i from frame 72

73 Simplify, coalesce and freeze Simplify: recursively remove non-move nodes with <K neighbors, pushing them onto stack any simplify done Coalesce: conservatively merge unconstrained MOVE-related nodes with <K heavy neighbors any coalesce done Freeze: give up coalescing on some low-degree MOVE-related node any freeze done 73

74 Overall algorithm any potential spill done Simplify, freeze and coalesce Liveness analysis Mark potential spills Select colors and detect actual spills any actual spill done Rewrite code to implement actual spills 74

75 Recent advances [CC 2013] 75

76 Linear scan register allocation 76

77 Live ranges and live intervals The live range for a variable is the set of program points at which the variable is alive The live interval for a variable is the smallest sub-range of the IR code containing all of a variable s live ranges A property of the IR code, not the CFG Less precise than live ranges, but simpler to work with 77

78 Live ranges and live intervals a b c d e f g e := d + a f := b + c f := f + b IfZ e Goto _L0 d := e + f d := e - f Goto _L1; _L0: d := e-f _L1: g = d 78

79 Register allocation with live ranges Given the live intervals for all the variables in the program, we can allocate registers using a simple greedy algorithm Idea: Track which registers are free at each point When a live interval begins, give that variable a free register When a live interval ends, the register is once again free We can't always fit everything into a register (spill) a b c d e f g 79

80 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 80

81 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 81

82 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 82

83 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 83

84 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 84

85 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 85

86 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 86

87 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 87

88 Example a b c d e f g Free registers R 0 R 1 R 2 R 3 88

89 Example d a b c e f g Free registers R 0 R 1 R 2 R 3 89

90 Example d a b c e f g Free registers R 0 R 1 R 2 R 3 90

91 Example d a b c e f g Free registers R 0 R 1 R 2 R 3 91

92 Another example a b c d e f g Free registers R 0 R 1 R 2 92

93 Another example a b c d e f g Free registers R 0 R 1 R 2 93

94 Another example a b c d e f g Free registers R 0 R 1 R 2 94

95 Another example a b c d e f g Free registers R 0 R 1 R 2 95

96 Another example a b c d e f g Free registers Which register should we use? R 0 R 1 R 2 96

97 Another example a b c d e f g Free registers R 0 R 1 R 2 Which variable should we spill? One with longer interval 97

98 Another example a b c d e f g Free registers R 0 R 1 R 2 98

99 Another example a b c d e f g Free registers R 0 R 1 R 2 99

100 Another example a b c d e f g Free registers R 0 R 1 R 2 100

101 Another example a b c d e f g Free registers R 0 R 1 R 2 101

102 Another example a b c d e f g Free registers R 0 R 1 R 2 102

103 Another example a b c d e f g Free registers R 0 R 1 R 2 103

104 Another example a b c d e f g Free registers R 0 R 1 R 2 104

105 Another example a b c d e f g Free registers R 0 R 1 R 2 105

106 Another example a b c d e f g Free registers R 0 R 1 R 2 106

107 Linear scan register allocation A comparatively new algorithm (Polleto and Sarkar) Advantages: Very efficient (after computing live intervals, runs in linear time) Produces good code in many instances Allocation step works in one pass; can generate code during iteration Often used in JIT compilers like Java HotSpot Disadvantage Imprecise due to use of live intervals rather than live ranges 107

108 Comparison to RA by coloring 108

109 RA recap Naïve allocation per statement (Sethi-Ullman) Done during lowering Graph-coloring Linear scan 109

110 Next lecture: Summary 110

Variables vs. Registers/Memory. Simple Approach. Register Allocation. Interference Graph. Register Allocation Algorithm CS412/CS413

Variables vs. Registers/Memory. Simple Approach. Register Allocation. Interference Graph. Register Allocation Algorithm CS412/CS413 Variables vs. Registers/Memory CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 33: Register Allocation 18 Apr 07 Difference between IR and assembly code: IR (and abstract assembly) manipulate

More information

Register allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices

Register allocation. Register allocation: ffl have value in a register when used. ffl limited resources. ffl changes instruction choices Register allocation IR instruction selection register allocation machine code errors Register allocation: have value in a register when used limited resources changes instruction choices can move loads

More information

Compilation /17a Lecture 10. Register Allocation Noam Rinetzky

Compilation /17a Lecture 10. Register Allocation Noam Rinetzky Compilation 0368-3133 2016/17a Lecture 10 Register Allocation Noam Rinetzky 1 What is a Compiler? 2 Registers Dedicated memory locations that can be accessed quickly, can have computations performed on

More information

Register allocation. instruction selection. machine code. register allocation. errors

Register allocation. instruction selection. machine code. register allocation. errors Register allocation IR instruction selection register allocation machine code errors Register allocation: have value in a register when used limited resources changes instruction choices can move loads

More information

Compilation Lecture 11a. Register Allocation Noam Rinetzky. Text book: Modern compiler implementation in C Andrew A.

Compilation Lecture 11a. Register Allocation Noam Rinetzky. Text book: Modern compiler implementation in C Andrew A. Compilation 0368-3133 Leture 11a Text book: Modern ompiler implementation in C Andrew A. Appel Register Alloation Noam Rinetzky 1 Registers Dediated memory loations that an be aessed quikly, an have omputations

More information

Liveness Analysis and Register Allocation. Xiao Jia May 3 rd, 2013

Liveness Analysis and Register Allocation. Xiao Jia May 3 rd, 2013 Liveness Analysis and Register Allocation Xiao Jia May 3 rd, 2013 1 Outline Control flow graph Liveness analysis Graph coloring Linear scan 2 Basic Block The code in a basic block has: one entry point,

More information

Register allocation. TDT4205 Lecture 31

Register allocation. TDT4205 Lecture 31 1 Register allocation TDT4205 Lecture 31 2 Variables vs. registers TAC has any number of variables Assembly code has to deal with memory and registers Compiler back end must decide how to juggle the contents

More information

Lecture 21 CIS 341: COMPILERS

Lecture 21 CIS 341: COMPILERS Lecture 21 CIS 341: COMPILERS Announcements HW6: Analysis & Optimizations Alias analysis, constant propagation, dead code elimination, register allocation Available Soon Due: Wednesday, April 25 th Zdancewic

More information

Liveness Analysis and Register Allocation

Liveness Analysis and Register Allocation Liveness Analysis and Register Allocation Leonidas Fegaras CSE 5317/4305 L10: Liveness Analysis and Register Allocation 1 Liveness Analysis So far we assumed that we have a very large number of temporary

More information

CSE P 501 Compilers. Register Allocation Hal Perkins Autumn /22/ Hal Perkins & UW CSE P-1

CSE P 501 Compilers. Register Allocation Hal Perkins Autumn /22/ Hal Perkins & UW CSE P-1 CSE P 501 Compilers Register Allocation Hal Perkins Autumn 2011 11/22/2011 2002-11 Hal Perkins & UW CSE P-1 Agenda Register allocation constraints Local methods Faster compile, slower code, but good enough

More information

Topic 12: Register Allocation

Topic 12: Register Allocation Topic 12: Register Allocation COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Structure of backend Register allocation assigns machine registers (finite supply!) to virtual

More information

Global Register Allocation

Global Register Allocation Global Register Allocation Y N Srikant Computer Science and Automation Indian Institute of Science Bangalore 560012 NPTEL Course on Compiler Design Outline n Issues in Global Register Allocation n The

More information

Register allocation. CS Compiler Design. Liveness analysis. Register allocation. Liveness analysis and Register allocation. V.

Register allocation. CS Compiler Design. Liveness analysis. Register allocation. Liveness analysis and Register allocation. V. Register allocation CS3300 - Compiler Design Liveness analysis and Register allocation V. Krishna Nandivada IIT Madras Copyright c 2014 by Antony L. Hosking. Permission to make digital or hard copies of

More information

Register Allocation, iii. Bringing in functions & using spilling & coalescing

Register Allocation, iii. Bringing in functions & using spilling & coalescing Register Allocation, iii Bringing in functions & using spilling & coalescing 1 Function Calls ;; f(x) = let y = g(x) ;; in h(y+x) + y*5 (:f (x

More information

Register Allocation & Liveness Analysis

Register Allocation & Liveness Analysis Department of Computer Sciences Register Allocation & Liveness Analysis CS502 Purdue University is an Equal Opportunity/Equal Access institution. Department of Computer Sciences In IR tree code generation,

More information

CSC D70: Compiler Optimization Register Allocation

CSC D70: Compiler Optimization Register Allocation CSC D70: Compiler Optimization Register Allocation Prof. Gennady Pekhimenko University of Toronto Winter 2018 The content of this lecture is adapted from the lectures of Todd Mowry and Phillip Gibbons

More information

Register Allocation 1

Register Allocation 1 Register Allocation 1 Lecture Outline Memory Hierarchy Management Register Allocation Register interference graph Graph coloring heuristics Spilling Cache Management The Memory Hierarchy Registers < 1

More information

Register Allocation. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

Register Allocation. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Register Allocation Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP at Rice. Copyright 00, Keith D. Cooper & Linda Torczon, all rights reserved.

More information

Register Allocation (via graph coloring) Lecture 25. CS 536 Spring

Register Allocation (via graph coloring) Lecture 25. CS 536 Spring Register Allocation (via graph coloring) Lecture 25 CS 536 Spring 2001 1 Lecture Outline Memory Hierarchy Management Register Allocation Register interference graph Graph coloring heuristics Spilling Cache

More information

Code generation for modern processors

Code generation for modern processors Code generation for modern processors Definitions (1 of 2) What are the dominant performance issues for a superscalar RISC processor? Refs: AS&U, Chapter 9 + Notes. Optional: Muchnick, 16.3 & 17.1 Instruction

More information

Lecture 25: Register Allocation

Lecture 25: Register Allocation Lecture 25: Register Allocation [Adapted from notes by R. Bodik and G. Necula] Topics: Memory Hierarchy Management Register Allocation: Register interference graph Graph coloring heuristics Spilling Cache

More information

Compiler Design. Register Allocation. Hwansoo Han

Compiler Design. Register Allocation. Hwansoo Han Compiler Design Register Allocation Hwansoo Han Big Picture of Code Generation Register allocation Decides which values will reside in registers Changes the storage mapping Concerns about placement of

More information

Global Register Allocation - Part 2

Global Register Allocation - Part 2 Global Register Allocation - Part 2 Y N Srikant Computer Science and Automation Indian Institute of Science Bangalore 560012 NPTEL Course on Compiler Design Outline Issues in Global Register Allocation

More information

Global Register Allocation

Global Register Allocation Global Register Allocation Lecture Outline Memory Hierarchy Management Register Allocation via Graph Coloring Register interference graph Graph coloring heuristics Spilling Cache Management 2 The Memory

More information

Lecture Notes on Register Allocation

Lecture Notes on Register Allocation Lecture Notes on Register Allocation 15-411: Compiler Design Frank Pfenning Lecture 3 September 1, 2009 1 Introduction In this lecture we discuss register allocation, which is one of the last steps in

More information

Register Allocation. Lecture 16

Register Allocation. Lecture 16 Register Allocation Lecture 16 1 Register Allocation This is one of the most sophisticated things that compiler do to optimize performance Also illustrates many of the concepts we ve been discussing in

More information

Code generation for modern processors

Code generation for modern processors Code generation for modern processors What are the dominant performance issues for a superscalar RISC processor? Refs: AS&U, Chapter 9 + Notes. Optional: Muchnick, 16.3 & 17.1 Strategy il il il il asm

More information

Register Allocation. Lecture 38

Register Allocation. Lecture 38 Register Allocation Lecture 38 (from notes by G. Necula and R. Bodik) 4/27/08 Prof. Hilfinger CS164 Lecture 38 1 Lecture Outline Memory Hierarchy Management Register Allocation Register interference graph

More information

Register allocation. Overview

Register allocation. Overview Register allocation Register allocation Overview Variables may be stored in the main memory or in registers. { Main memory is much slower than registers. { The number of registers is strictly limited.

More information

Compiler Architecture

Compiler Architecture Code Generation 1 Compiler Architecture Source language Scanner (lexical analysis) Tokens Parser (syntax analysis) Syntactic structure Semantic Analysis (IC generator) Intermediate Language Code Optimizer

More information

Today More register allocation Clarifications from last time Finish improvements on basic graph coloring concept Procedure calls Interprocedural

Today More register allocation Clarifications from last time Finish improvements on basic graph coloring concept Procedure calls Interprocedural More Register Allocation Last time Register allocation Global allocation via graph coloring Today More register allocation Clarifications from last time Finish improvements on basic graph coloring concept

More information

Low-Level Issues. Register Allocation. Last lecture! Liveness analysis! Register allocation. ! More register allocation. ! Instruction scheduling

Low-Level Issues. Register Allocation. Last lecture! Liveness analysis! Register allocation. ! More register allocation. ! Instruction scheduling Low-Level Issues Last lecture! Liveness analysis! Register allocation!today! More register allocation!later! Instruction scheduling CS553 Lecture Register Allocation I 1 Register Allocation!Problem! Assign

More information

CHAPTER 3. Register allocation

CHAPTER 3. Register allocation CHAPTER 3 Register allocation In chapter 1 we simplified the generation of x86 assembly by placing all variables on the stack. We can improve the performance of the generated code considerably if we instead

More information

Register Allocation. Register Allocation. Local Register Allocation. Live range. Register Allocation for Loops

Register Allocation. Register Allocation. Local Register Allocation. Live range. Register Allocation for Loops DF00100 Advanced Compiler Construction Register Allocation Register Allocation: Determines values (variables, temporaries, constants) to be kept when in registers Register Assignment: Determine in which

More information

CHAPTER 3. Register allocation

CHAPTER 3. Register allocation CHAPTER 3 Register allocation In chapter 1 we simplified the generation of x86 assembly by placing all variables on the stack. We can improve the performance of the generated code considerably if we instead

More information

Rematerialization. Graph Coloring Register Allocation. Some expressions are especially simple to recompute: Last Time

Rematerialization. Graph Coloring Register Allocation. Some expressions are especially simple to recompute: Last Time Graph Coloring Register Allocation Last Time Chaitin et al. Briggs et al. Today Finish Briggs et al. basics An improvement: rematerialization Rematerialization Some expressions are especially simple to

More information

Compilers and Code Optimization EDOARDO FUSELLA

Compilers and Code Optimization EDOARDO FUSELLA Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of

More information

Global Register Allocation via Graph Coloring

Global Register Allocation via Graph Coloring Global Register Allocation via Graph Coloring Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission

More information

Register Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations

Register Allocation. Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class

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

Lecture 6. Register Allocation. I. Introduction. II. Abstraction and the Problem III. Algorithm

Lecture 6. Register Allocation. I. Introduction. II. Abstraction and the Problem III. Algorithm I. Introduction Lecture 6 Register Allocation II. Abstraction and the Problem III. Algorithm Reading: Chapter 8.8.4 Before next class: Chapter 10.1-10.2 CS243: Register Allocation 1 I. Motivation Problem

More information

Outline. Register Allocation. Issues. Storing values between defs and uses. Issues. Issues P3 / 2006

Outline. Register Allocation. Issues. Storing values between defs and uses. Issues. Issues P3 / 2006 P3 / 2006 Register Allocation What is register allocation Spilling More Variations and Optimizations Kostis Sagonas 2 Spring 2006 Storing values between defs and uses Program computes with values value

More information

Code Generation. CS 540 George Mason University

Code Generation. CS 540 George Mason University Code Generation CS 540 George Mason University Compiler Architecture Intermediate Language Intermediate Language Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntactic structure

More information

Register Allocation. Michael O Boyle. February, 2014

Register Allocation. Michael O Boyle. February, 2014 Register Allocation Michael O Boyle February, 2014 1 Course Structure L1 Introduction and Recap L2 Course Work L3+4 Scalar optimisation and dataflow L5 Code generation L6 Instruction scheduling L7 Register

More information

Global Register Allocation - Part 3

Global Register Allocation - Part 3 Global Register Allocation - Part 3 Y N Srikant Computer Science and Automation Indian Institute of Science Bangalore 560012 NPTEL Course on Compiler Design Outline Issues in Global Register Allocation

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

Global Register Allocation - 2

Global Register Allocation - 2 Global Register Allocation - 2 Y N Srikant Computer Science and Automation Indian Institute of Science Bangalore 560012 NPTEL Course on Principles of Compiler Design Outline n Issues in Global Register

More information

Introduction to Optimization, Instruction Selection and Scheduling, and Register Allocation

Introduction to Optimization, Instruction Selection and Scheduling, and Register Allocation Introduction to Optimization, Instruction Selection and Scheduling, and Register Allocation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Traditional Three-pass Compiler

More information

register allocation saves energy register allocation reduces memory accesses.

register allocation saves energy register allocation reduces memory accesses. Lesson 10 Register Allocation Full Compiler Structure Embedded systems need highly optimized code. This part of the course will focus on Back end code generation. Back end: generation of assembly instructions

More information

Register Allocation via Hierarchical Graph Coloring

Register Allocation via Hierarchical Graph Coloring Register Allocation via Hierarchical Graph Coloring by Qunyan Wu A THESIS Submitted in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE IN COMPUTER SCIENCE MICHIGAN TECHNOLOGICAL

More information

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 5: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Lecture Compiler Backend

Lecture Compiler Backend Lecture 19-23 Compiler Backend Jianwen Zhu Electrical and Computer Engineering University of Toronto Jianwen Zhu 2009 - P. 1 Backend Tasks Instruction selection Map virtual instructions To machine instructions

More information

Abstract Interpretation Continued

Abstract Interpretation Continued Abstract Interpretation Continued Height of Lattice: Length of Max. Chain height=5 size=14 T height=2 size = T -2-1 0 1 2 Chain of Length n A set of elements x 0,x 1,..., x n in D that are linearly ordered,

More information

Register Allocation. CS 502 Lecture 14 11/25/08

Register Allocation. CS 502 Lecture 14 11/25/08 Register Allocation CS 502 Lecture 14 11/25/08 Where we are... Reasonably low-level intermediate representation: sequence of simple instructions followed by a transfer of control. a representation of static

More information

Register Allocation. Preston Briggs Reservoir Labs

Register Allocation. Preston Briggs Reservoir Labs Register Allocation Preston Briggs Reservoir Labs An optimizing compiler SL FE IL optimizer IL BE SL A classical optimizing compiler (e.g., LLVM) with three parts and a nice separation of concerns: front

More information

Lecture Overview Register Allocation

Lecture Overview Register Allocation 1 Lecture Overview Register Allocation [Chapter 13] 2 Introduction Registers are the fastest locations in the memory hierarchy. Often, they are the only memory locations that most operations can access

More information

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1 Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces

More information

Code generation for superscalar RISCprocessors. Characteristics of RISC processors. What are RISC and CISC? Processors with and without pipelining

Code generation for superscalar RISCprocessors. Characteristics of RISC processors. What are RISC and CISC? Processors with and without pipelining Code generation for superscalar RISCprocessors What are RISC and CISC? CISC: (Complex Instruction Set Computers) Example: mem(r1+r2) = mem(r1+r2)*mem(r3+disp) RISC: (Reduced Instruction Set Computers)

More information

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis Synthesis of output program (back-end) Intermediate Code Generation Optimization Before and after generating machine

More information

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation

More information

Fall Compiler Principles Lecture 3: Parsing part 2. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 3: Parsing part 2. Roman Manevich Ben-Gurion University Fall 2014-2015 Compiler Principles Lecture 3: Parsing part 2 Roman Manevich Ben-Gurion University Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering

More information

The C2 Register Allocator. Niclas Adlertz

The C2 Register Allocator. Niclas Adlertz The C2 Register Allocator Niclas Adlertz 1 1 Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated

More information

CS5363 Final Review. cs5363 1

CS5363 Final Review. cs5363 1 CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers

More information

Where we are. Instruction selection. Abstract Assembly. CS 4120 Introduction to Compilers

Where we are. Instruction selection. Abstract Assembly. CS 4120 Introduction to Compilers Where we are CS 420 Introduction to Compilers Andrew Myers Cornell University Lecture 8: Instruction Selection 5 Oct 20 Intermediate code Canonical intermediate code Abstract assembly code Assembly code

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution 1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

More information

April 15, 2015 More Register Allocation 1. Problem Register values may change across procedure calls The allocator must be sensitive to this

April 15, 2015 More Register Allocation 1. Problem Register values may change across procedure calls The allocator must be sensitive to this More Register Allocation Last time Register allocation Global allocation via graph coloring Today More register allocation Procedure calls Interprocedural April 15, 2015 More Register Allocation 1 Register

More information

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013 A Bad Name Optimization is the process by which we turn a program into a better one, for some definition of better. CS 2210: Optimization This is impossible in the general case. For instance, a fully optimizing

More information

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev Fall 2017-2018 Compiler Principles Lecture 2: LL parsing Roman Manevich Ben-Gurion University of the Negev 1 Books Compilers Principles, Techniques, and Tools Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman

More information

Group B Assignment 8. Title of Assignment: Problem Definition: Code optimization using DAG Perquisite: Lex, Yacc, Compiler Construction

Group B Assignment 8. Title of Assignment: Problem Definition: Code optimization using DAG Perquisite: Lex, Yacc, Compiler Construction Group B Assignment 8 Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Code optimization using DAG. 8.1.1 Problem Definition: Code optimization using DAG. 8.1.2 Perquisite: Lex, Yacc, Compiler

More information

Register Allocation 3/16/11. What a Smart Allocator Needs to Do. Global Register Allocation. Global Register Allocation. Outline.

Register Allocation 3/16/11. What a Smart Allocator Needs to Do. Global Register Allocation. Global Register Allocation. Outline. What a Smart Allocator Needs to Do Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Determine ranges for each variable can benefit from using

More information

Agenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1

Agenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1 Agenda CSE P 501 Compilers Instruction Selection Hal Perkins Autumn 2005 Compiler back-end organization Low-level intermediate representations Trees Linear Instruction selection algorithms Tree pattern

More information

Register Allocation (wrapup) & Code Scheduling. Constructing and Representing the Interference Graph. Adjacency List CS2210

Register Allocation (wrapup) & Code Scheduling. Constructing and Representing the Interference Graph. Adjacency List CS2210 Register Allocation (wrapup) & Code Scheduling CS2210 Lecture 22 Constructing and Representing the Interference Graph Construction alternatives: as side effect of live variables analysis (when variables

More information

CS 406/534 Compiler Construction Instruction Selection and Global Register Allocation

CS 406/534 Compiler Construction Instruction Selection and Global Register Allocation CS 406/534 Compiler Construction Instruction Selection and Global Register Allocation Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith

More information

Optimization. ASU Textbook Chapter 9. Tsan-sheng Hsu.

Optimization. ASU Textbook Chapter 9. Tsan-sheng Hsu. Optimization ASU Textbook Chapter 9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction For some compiler, the intermediate code is a pseudo code of a virtual machine.

More information

Winter Compiler Construction T10 IR part 3 + Activation records. Today. LIR language

Winter Compiler Construction T10 IR part 3 + Activation records. Today. LIR language Winter 2006-2007 Compiler Construction T10 IR part 3 + Activation records Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Today ic IC Language Lexical Analysis Syntax Analysis

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

CSc 553. Principles of Compilation. 23 : Register Allocation. Department of Computer Science University of Arizona

CSc 553. Principles of Compilation. 23 : Register Allocation. Department of Computer Science University of Arizona CSc 553 Principles of Compilation 3 : egister Allocation Department of Computer Science University of Arizona collberg@gmail.com Copyright c 0 Christian Collberg Introduction Lexing, Parsing Semantic Analysis,

More information

Calvin Lin The University of Texas at Austin

Calvin Lin The University of Texas at Austin Loop Invariant Code Motion Last Time SSA Today Loop invariant code motion Reuse optimization Next Time More reuse optimization Common subexpression elimination Partial redundancy elimination February 23,

More information

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack

More information

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 2: LL parsing Roman Manevich Ben-Gurion University of the Negev 1 Books Compilers Principles, Techniques, and Tools Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman

More information

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016 CS 31: Intro to Systems Functions and the Stack Martin Gagne Swarthmore College February 23, 2016 Reminders Late policy: you do not have to send me an email to inform me of a late submission before the

More information

Characteristics of RISC processors. Code generation for superscalar RISCprocessors. What are RISC and CISC? Processors with and without pipelining

Characteristics of RISC processors. Code generation for superscalar RISCprocessors. What are RISC and CISC? Processors with and without pipelining Code generation for superscalar RISCprocessors What are RISC and CISC? CISC: (Complex Instruction Set Computers) Example: mem(r1+r2) = mem(r1+r2)*mem(r3+disp) RISC: (Reduced Instruction Set Computers)

More information

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller Lecture 10 Return-oriented programming Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller ROP Overview Idea: We forge shellcode out of existing application

More information

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1 CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on

More information

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Calling Conventions See P&H 2.8 and 2.12 Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Goals for Today Review: Calling Conventions call a routine (i.e. transfer control to

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

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers These notes are not yet complete. 1 Interprocedural analysis Some analyses are not sufficiently

More information

x86 Assembly Crash Course Don Porter

x86 Assembly Crash Course Don Porter x86 Assembly Crash Course Don Porter Registers ò Only variables available in assembly ò General Purpose Registers: ò EAX, EBX, ECX, EDX (32 bit) ò Can be addressed by 8 and 16 bit subsets AL AH AX EAX

More information

Redundant Computation Elimination Optimizations. Redundancy Elimination. Value Numbering CS2210

Redundant Computation Elimination Optimizations. Redundancy Elimination. Value Numbering CS2210 Redundant Computation Elimination Optimizations CS2210 Lecture 20 Redundancy Elimination Several categories: Value Numbering local & global Common subexpression elimination (CSE) local & global Loop-invariant

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

Local Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code

Local Optimization: Value Numbering The Desert Island Optimization. Comp 412 COMP 412 FALL Chapter 8 in EaC2e. target code COMP 412 FALL 2017 Local Optimization: Value Numbering The Desert Island Optimization Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon,

More information

Instruction Selection. Problems. DAG Tiling. Pentium ISA. Example Tiling CS412/CS413. Introduction to Compilers Tim Teitelbaum

Instruction Selection. Problems. DAG Tiling. Pentium ISA. Example Tiling CS412/CS413. Introduction to Compilers Tim Teitelbaum Instruction Selection CS42/CS43 Introduction to Compilers Tim Teitelbaum Lecture 32: More Instruction Selection 20 Apr 05. Translate low-level IR code into DAG representation 2. Then find a good tiling

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Intermediate Representations Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 G-1 Agenda Survey of Intermediate Representations Graphical Concrete/Abstract Syntax Trees (ASTs)

More information

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum IR Lowering CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 19: Efficient IL Lowering 7 March 07 Use temporary variables for the translation Temporary variables in the Low IR store intermediate

More information

Parser: SQL parse tree

Parser: SQL parse tree Jinze Liu Parser: SQL parse tree Good old lex & yacc Detect and reject syntax errors Validator: parse tree logical plan Detect and reject semantic errors Nonexistent tables/views/columns? Insufficient

More information

Lecture 15 Register Allocation & Spilling

Lecture 15 Register Allocation & Spilling I. Motivation Lecture 15 Register Allocation & Spilling I. Introduction II. Abstraction and the Problem III. Algorithm IV. Spilling Problem Allocation of variables (pseudo-registers) to hardware registers

More information

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018 238P: Operating Systems Lecture 3: Calling conventions Anton Burtsev October, 2018 What does CPU do internally? (Remember Lecture 01 - Introduction?) CPU execution loop CPU repeatedly reads instructions

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 19: Efficient IL Lowering 5 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 19: Efficient IL Lowering 5 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 19: Efficient IL Lowering 5 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 IR Lowering Use temporary variables for the translation

More information

Review. Pat Morin COMP 3002

Review. Pat Morin COMP 3002 Review Pat Morin COMP 3002 What is a Compiler A compiler translates from a source language S to a target language T while preserving the meaning of the input 2 Structure of a Compiler program text syntactic

More information