FUNCTION MERGING by SEQUENCE ALIGNMENT DOES SIZE MATTER? DOES - - PowerPoint PPT Presentation

function merging
SMART_READER_LITE
LIVE PREVIEW

FUNCTION MERGING by SEQUENCE ALIGNMENT DOES SIZE MATTER? DOES - - PowerPoint PPT Presentation

Rodrigo Rocha http://rcor.me University of Edinburgh FUNCTION MERGING by SEQUENCE ALIGNMENT DOES SIZE MATTER? DOES SIZE MATTER? S E Y DOES SIZE MATTER? S E Y ... EMBEDDED SYSTEMS SAVINGS IN CODE Smaller Memories 1 0 1 1 0 1


slide-1
SLIDE 1

http://rcor.me Rodrigo Rocha

University of Edinburgh

by

SEQUENCE ALIGNMENT

FUNCTION MERGING

slide-2
SLIDE 2

DOES SIZE MATTER?

slide-3
SLIDE 3

Y E S

DOES SIZE MATTER?

slide-4
SLIDE 4

...

EMBEDDED SYSTEMS

Y E S

DOES SIZE MATTER?

slide-5
SLIDE 5

BIN

01011 10110 1

1

1

1

1

1

1

SAVINGS IN CODE

Smaller Memories

COST SAVINGS

slide-6
SLIDE 6

HOW TO REDUCE SIZE?

slide-7
SLIDE 7

Similar or Identical

MERGE FUNCTIONS

HOW TO REDUCE SIZE?

slide-8
SLIDE 8

int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

MERGING FUNCTIONS

slide-9
SLIDE 9

int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Identical Code

MERGING FUNCTIONS

slide-10
SLIDE 10

merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Identical Code

MERGING FUNCTIONS

slide-11
SLIDE 11

merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-12
SLIDE 12

, int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-13
SLIDE 13

int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-14
SLIDE 14

10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-15
SLIDE 15

b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-16
SLIDE 16

term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Selecting Different Operands

MERGING FUNCTIONS

slide-17
SLIDE 17

term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Branching to Distinct CFG

MERGING FUNCTIONS

slide-18
SLIDE 18

if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Branching to Distinct CFG

MERGING FUNCTIONS

slide-19
SLIDE 19

if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Branching to Distinct CFG

MERGING FUNCTIONS

slide-20
SLIDE 20

if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Combining the Return Value

MERGING FUNCTIONS

slide-21
SLIDE 21

if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Combining the Return Value

MERGING FUNCTIONS

slide-22
SLIDE 22

int if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Combining the Return Value

MERGING FUNCTIONS

slide-23
SLIDE 23

return result; } int if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Combining the Return Value

MERGING FUNCTIONS

slide-24
SLIDE 24

return result; } int if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

Reduces Code Size!

MERGING FUNCTIONS

slide-25
SLIDE 25

return result; } int if (func_id==2) if (result==0) printf("result is zero\n"); term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b int var = a*b + int result = foo(var); printf("result: %d\n", result); int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

However... State of the Art FAILS

MERGING FUNCTIONS

slide-26
SLIDE 26

Production compilers: LLVM, GCC, MSVC

WHAT WE HAVE

slide-27
SLIDE 27

Only Identical Functions Production compilers: LLVM, GCC, MSVC

WHAT WE HAVE

slide-28
SLIDE 28

The state of the art

WHAT WE HAVE

slide-29
SLIDE 29

significant improvement but... The state of the art

WHAT WE HAVE

slide-30
SLIDE 30

MUST HAVE IDENTICAL significant improvement but... The state of the art

WHAT WE HAVE

slide-31
SLIDE 31

CFGs MUST HAVE IDENTICAL significant improvement but... The state of the art

WHAT WE HAVE

slide-32
SLIDE 32

Return types CFGs MUST HAVE IDENTICAL significant improvement but... The state of the art

WHAT WE HAVE

slide-33
SLIDE 33

Lists of parameters Return types CFGs MUST HAVE IDENTICAL significant improvement but... The state of the art

WHAT WE HAVE

slide-34
SLIDE 34

Number of instructions Lists of parameters Return types CFGs MUST HAVE IDENTICAL significant improvement but... The state of the art

WHAT WE HAVE

slide-35
SLIDE 35

WHAT WE WANT

slide-36
SLIDE 36

Merge ANY two functions

WHAT WE WANT

slide-37
SLIDE 37

Merge ANY two functions CHOOSE when to do it and Merge ANY two functions

WHAT WE WANT

slide-38
SLIDE 38

int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result; } void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n"); }

HOW WE DO IT

slide-39
SLIDE 39

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end

IR Level HOW WE DO IT

slide-40
SLIDE 40

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

HOW WE DO IT

slide-41
SLIDE 41

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

LINEARIZATION

slide-42
SLIDE 42

label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2

LINEARIZATION

slide-43
SLIDE 43

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

LINEARIZATION

slide-44
SLIDE 44

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

LINEARIZATION

slide-45
SLIDE 45

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

LINEARIZATION

slide-46
SLIDE 46

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

LINEARIZATION

slide-47
SLIDE 47

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

IDENTIFY WHAT TO MERGE

slide-48
SLIDE 48

label: entry %r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 label: entry %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void

IDENTIFY WHAT TO MERGE

slide-49
SLIDE 49

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-50
SLIDE 50

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-51
SLIDE 51

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-52
SLIDE 52

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-53
SLIDE 53

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-54
SLIDE 54

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-55
SLIDE 55

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-56
SLIDE 56

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-57
SLIDE 57

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-58
SLIDE 58

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-59
SLIDE 59

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-60
SLIDE 60

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-61
SLIDE 61

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-62
SLIDE 62

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-63
SLIDE 63

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Match

IDENTIFY WHAT TO MERGE

slide-64
SLIDE 64

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-65
SLIDE 65

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-66
SLIDE 66

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-67
SLIDE 67

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-68
SLIDE 68

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

Mismatch

IDENTIFY WHAT TO MERGE

slide-69
SLIDE 69

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-70
SLIDE 70

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-71
SLIDE 71

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-72
SLIDE 72

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-73
SLIDE 73

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-74
SLIDE 74

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-75
SLIDE 75

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-76
SLIDE 76

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-77
SLIDE 77

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-78
SLIDE 78

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-79
SLIDE 79

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-80
SLIDE 80

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-81
SLIDE 81

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

IDENTIFY WHAT TO MERGE

slide-82
SLIDE 82

G C A T - G C U G - A T T A C A

Bioinformatics SEQUENCE ALIGNMENT

slide-83
SLIDE 83

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

SEQUENCE ALIGNMENT

slide-84
SLIDE 84

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

Gap: -1 Mismatch: -1 Match: +2

SEQUENCE ALIGNMENT

slide-85
SLIDE 85

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4

SEQUENCE ALIGNMENT

slide-86
SLIDE 86

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4

SEQUENCE ALIGNMENT

slide-87
SLIDE 87

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4
  • 1 -1 = -2

SEQUENCE ALIGNMENT

slide-88
SLIDE 88

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1 -2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4
  • 1 -1 = -2
  • 1 -1 = -2

SEQUENCE ALIGNMENT

slide-89
SLIDE 89

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4
  • 1 -1 = -2
  • 1 -1 = -2

0 + 2 = 2

SEQUENCE ALIGNMENT

slide-90
SLIDE 90

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4
  • 1 -1 = -2
  • 1 -1 = -2

0 + 2 = 2 2

SEQUENCE ALIGNMENT

slide-91
SLIDE 91

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1 -2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4

2 -1 = 1

  • 2 -1 = -3
  • 1 -1 = -2

2

SEQUENCE ALIGNMENT

slide-92
SLIDE 92

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 2
  • 3
  • 12
  • 11
  • 10
  • 9
  • 8
  • 7
  • 6
  • 5
  • 4
  • 1
  • 2
  • 3
  • 5
  • 6
  • 4

2 -1 = 1

  • 2 -1 = -3
  • 1 -1 = -2

2 1

SEQUENCE ALIGNMENT

slide-93
SLIDE 93

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 1
  • 2
  • 2
  • 3
  • 3
  • 12
  • 11
  • 10
  • 9
  • 9
  • 8
  • 8
  • 7
  • 7
  • 6
  • 6
  • 6
  • 5
  • 5
  • 6
  • 4
  • 4

2 1

  • 1
  • 2
  • 3
  • 5
  • 4
  • 5
  • 4
  • 3
  • 2
  • 1

1 2 3 4 1

  • 1
  • 2
  • 3

1 4 5 5 6 6 6 3 6 6 3 2 4 3 2 1

  • 1
  • 2
  • 3

1 2 3 4 5 6 7 8 3 4 5 7 8 9 10 7 9 8 9 7 5 4

SEQUENCE ALIGNMENT

slide-94
SLIDE 94

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 1
  • 2
  • 2
  • 3
  • 3
  • 12
  • 11
  • 10
  • 9
  • 9
  • 8
  • 8
  • 7
  • 7
  • 6
  • 6
  • 6
  • 5
  • 5
  • 6
  • 4
  • 4

2 1

  • 1
  • 2
  • 3
  • 5
  • 4
  • 5
  • 4
  • 3
  • 2
  • 1

1 2 3 4 1

  • 1
  • 2
  • 3

1 4 5 5 6 6 6 3 6 6 3 2 4 3 2 1

  • 1
  • 2
  • 3

1 2 3 4 5 6 7 8 3 4 5 7 8 9 10 7 9 8 9 7 5 4

SEQUENCE ALIGNMENT

slide-95
SLIDE 95

Gap: -1 Mismatch: -1 Match: +2

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 1
  • 2
  • 2
  • 3
  • 3
  • 12
  • 11
  • 10
  • 9
  • 9
  • 8
  • 8
  • 7
  • 7
  • 6
  • 6
  • 6
  • 5
  • 5
  • 6
  • 4
  • 4

2 1

  • 1
  • 2
  • 3
  • 5
  • 4
  • 5
  • 4
  • 3
  • 2
  • 1

1 2 3 4 1

  • 1
  • 2
  • 3

1 4 5 5 6 6 6 3 6 6 3 2 4 3 2 1

  • 1
  • 2
  • 3

1 2 3 4 5 6 7 8 3 4 5 7 8 9 10 7 9 8 9 7 5 4

SEQUENCE ALIGNMENT

slide-96
SLIDE 96

mul add call foo call printf ret mul add call foo call printf icmp eq br label call br label ret label label

  • 1
  • 1
  • 2
  • 2
  • 3
  • 3
  • 12
  • 11
  • 10
  • 9
  • 9
  • 8
  • 8
  • 7
  • 7
  • 6
  • 6
  • 6
  • 5
  • 5
  • 6
  • 4
  • 4

2 1

  • 1
  • 2
  • 3
  • 5
  • 4
  • 5
  • 4
  • 3
  • 2
  • 1

1 2 3 4 1

  • 1
  • 2
  • 3

1 4 5 5 6 6 6 3 6 6 3 2 4 3 2 1

  • 1
  • 2
  • 3

1 2 3 4 5 6 7 8 3 4 5 7 8 9 10 7 9 8 9 7 5 4

SEQUENCE ALIGNMENT

slide-97
SLIDE 97

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: entry label: entry

CODE GENERATION

slide-98
SLIDE 98

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 entry b1

Renaming Table

CODE GENERATION

slide-99
SLIDE 99

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 entry b1

Renaming Table

CODE GENERATION

slide-100
SLIDE 100

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %r0 = mul %a, %b %x0 = mul %a, %b entry b1

Renaming Table

CODE GENERATION

slide-101
SLIDE 101

%r0 = mul %a, %b %r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x0 = mul %a, %b %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b entry b1

Renaming Table

CODE GENERATION

slide-102
SLIDE 102

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-103
SLIDE 103

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %m1 = add entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-104
SLIDE 104

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %m1 = add entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-105
SLIDE 105

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %m1 = add %m0, entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-106
SLIDE 106

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %m1 = add %m0, entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-107
SLIDE 107

%r1 = add %r0, 10 %r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x1 = add %x0, %b %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, entry b1 r0 m0 x0 m0

Renaming Table

CODE GENERATION

slide-108
SLIDE 108

%r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 entry b1 r0 m0 x0 m0 r1 m1 x1 m1

Renaming Table

CODE GENERATION

slide-109
SLIDE 109

%r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 entry b1 r0 m0 x0 m0 r1 m1 x1 m1

Renaming Table

CODE GENERATION

slide-110
SLIDE 110

%r2 = call foo(%r1) %r3 = call printf(@str,%r2) ret %r2 %x2 = call foo(%x1) %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) entry b1 r0 m0 x0 m0 r1 m1 x1 m1

Renaming Table

CODE GENERATION

slide-111
SLIDE 111

%r3 = call printf(@str,%r2) ret %r2 %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2

Renaming Table

CODE GENERATION

slide-112
SLIDE 112

%r3 = call printf(@str,%r2) ret %r2 %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2

Renaming Table

CODE GENERATION

slide-113
SLIDE 113

%r3 = call printf(@str,%r2) ret %r2 %x3 = call printf(@str,%x2) %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2

Renaming Table

CODE GENERATION

slide-114
SLIDE 114

ret %r2 %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-115
SLIDE 115

ret %r2 %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-116
SLIDE 116

ret %r2 %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-117
SLIDE 117

ret %r2 %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-118
SLIDE 118

ret %r2 %x4 = icmp eq %x2, 0 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-119
SLIDE 119

ret %r2 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-120
SLIDE 120

ret %r2 br %x4, %if.then, %if.end label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-121
SLIDE 121

ret %r2 label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-122
SLIDE 122

ret %r2 label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-123
SLIDE 123

ret %r2 label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-124
SLIDE 124

ret %r2 label: if.then %x5 = call printf(@str) br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-125
SLIDE 125

ret %r2 label: if.then br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-126
SLIDE 126

ret %r2 label: if.then br %if.end label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-127
SLIDE 127

ret %r2 label: if.then label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-128
SLIDE 128

ret %r2 label: if.then label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-129
SLIDE 129

ret %r2 label: if.then label: if.end ret void label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-130
SLIDE 130

label: if.then label: if.end label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end label: b4 br %b4 br %b4 ret %r2 ret void entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-131
SLIDE 131

label: b4 ret %r2 ret void label: if.then label: if.end label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end br %b4 br %b4 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-132
SLIDE 132

label: if.end br %b4 label: if.then label: b1 %m0 = mul %a, %b %t0 = select %0, 10, %b %m1 = add %m0, %t0 %m2 = call foo(%m1) %m3 = call printf(@str,%m2) br %0, %b2, %b3 label: b3 label: b2 %x4 = icmp eq %m2, 0 br %x4, %if.then, %if.end %x5 = call printf(@str) br %if.end label: b4 br %b4 ret %m2 entry b1 r0 m0 x0 m0 r1 m1 x1 m1 r2 m2 x2 m2 r3 m3 x3 m3

Renaming Table

CODE GENERATION

slide-133
SLIDE 133

i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-134
SLIDE 134

i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-135
SLIDE 135

i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-136
SLIDE 136

i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-137
SLIDE 137

i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-138
SLIDE 138

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-139
SLIDE 139

double

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-140
SLIDE 140

double

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-141
SLIDE 141

float

double

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-142
SLIDE 142

float

double

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-143
SLIDE 143

float

double

float i32* i32 i1 i1 FuncID i1 i32 i32* float

double float float

i32 i32*

Function 1 Function 2

MERGING PARAMETERS

slide-144
SLIDE 144

WHAT WE CAN HANDLE

slide-145
SLIDE 145

CFGs Instructions Return Types List of Parameters Operands Number of Instructions

L L V M ' s I d e n t i c a l O n l y S t a t e

  • f

A r t O u r T e c h n i q u e ( F M S A )

A l l

  • w

e d D i f f e r e n c e s

WHAT WE CAN HANDLE

slide-146
SLIDE 146

PROFITABLE MERGES

slide-147
SLIDE 147

Brute Force

PROFITABLE MERGES

slide-148
SLIDE 148

Brute Force Brute Force: Infeasible

PROFITABLE MERGES

slide-149
SLIDE 149

PROFITABLE MERGES

slide-150
SLIDE 150

Precompute Fingerprints

PROFITABLE MERGES

slide-151
SLIDE 151

Precompute Fingerprints

add br call

...

PROFITABLE MERGES

slide-152
SLIDE 152

Ranking Candidates

PROFITABLE MERGES

slide-153
SLIDE 153

Ranking Candidates

PROFITABLE MERGES

slide-154
SLIDE 154

Ranking Candidates

Estimated Upper-Bound Reduction

PROFITABLE MERGES

slide-155
SLIDE 155

Ranking Candidates

PROFITABLE MERGES

slide-156
SLIDE 156

Ranking Candidates

PROFITABLE MERGES

slide-157
SLIDE 157

Ranking Candidates

PROFITABLE MERGES

slide-158
SLIDE 158

Ranking Candidates

PROFITABLE MERGES

slide-159
SLIDE 159

MiBench SPEC 2006 Benchmark Suite: LTO with -Os SOA: State of the Art LLVM: Identical Only FMSA: Our Technique

EVALUATION SETUP

slide-160
SLIDE 160

1 2 3 4 5 6

% LLVM SOA FMSA

CODE SIZE REDUCTION

AVERAGE ON SPEC'06

slide-161
SLIDE 161

0.1 1.5 2

% LLVM SOA FMSA

CODE SIZE REDUCTION

1 0.5

AVERAGE ON MIBENCH

slide-162
SLIDE 162

1 2 3 4 5 6

% LLVM SOA FMSA

CODE SIZE REDUCTION

2 4 6 8 10 12

% LLVM SOA FMSA C Programs C++ Programs

AVERAGE ON SPEC'06

slide-163
SLIDE 163

1 1.2

LLVM SOA FMSA

NORMALIZED RUNTIME

0.5

1.02

AVERAGE ON SPEC'06

slide-164
SLIDE 164

1 1.2

LLVM SOA FMSA

NORMALIZED COMPILE TIME

0.5

1.15

AVERAGE ON SPEC'06

slide-165
SLIDE 165

Efficient Exploration Mechanism NOVEL and POWERFUL Technique for Merging ANY Pair of Functions

CONCLUSION

slide-166
SLIDE 166

https://groups.google.com/d/msg/llvm-dev/HQRg58ZCXsM/N7fbgvZgBQAJ

LLVM Dev RFC:

https://github.com/rcorcs/fmsa

Source Code:

LINKS

https://reviews.llvm.org/D59442

LLVM Patch:

https://doi.org/10.1109/CGO.2019.8661174

Paper (CGO'19 ):

slide-167
SLIDE 167

Rodrigo Rocha

Pavlos Petoumenos Zheng Wang Murray Cole Hugh Leather

Function Merging by Sequence Alignment

slide-168
SLIDE 168

4 . p e r l b e n c h 4 1 . b z i p 2 4 3 . g c c 4 2 9 . m c f 4 3 3 . m i l c 4 4 4 . n a m d 4 4 5 . g

  • b

m k 4 4 7 . d e a l I I 4 5 . s

  • p

l e x 4 5 3 . p

  • v

r a y 4 5 6 . h m m e r 4 5 8 . s j e n g 4 6 2 . l i b q u a n t u m 4 6 4 . h 2 6 4 r e f 4 7 . l b m 4 7 1 .

  • m

n e t p p 4 7 3 . a s t a r 4 8 2 . s p h i n x 3 M e a n 20 40 60 80 100

Compilation Time (%)

Fingerprinting Ranking Linearization Alignment Code-Gen Updating Calls

Compilation Breakdown

Future Work: Use a greedy sequence alignment Avoid wasteful merges

slide-169
SLIDE 169 4 . p e r l b e n c h 4 1 . b z i p 2 4 3 . g c c 4 2 9 . m c f 4 3 3 . m i l c 4 4 4 . n a m d 4 4 5 . g
  • b
m k 4 4 7 . d e a l I I 4 5 . s
  • p
l e x 4 5 3 . p
  • v
r a y 4 5 6 . h m m e r 4 5 8 . s j e n g 4 6 2 . l i b q u a n t u m 4 6 4 . h 2 6 4 r e f 4 7 . l b m 4 7 1 .
  • m
n e t p p 4 7 3 . a s t a r 4 8 2 . s p h i n x 3 4 8 3 . x a l a n c b m k M e a n 5 10 15 20 25

Reduction (%)

1 . 4 2 . 5 6 . 6 . 2 6 . 2 6 . 3 Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle] C R C 3 2 F F T a d p c m _ c a d p c m _ d b a s i c m a t h b i t c
  • u

n t b l

  • w

f i s h _ d b l

  • w

f i s h _ e c j p e g d i j k s t r a d j p e g g h

  • s

t s c r i p t g s m i s p e l l p a t r i c i a p g p q s

  • r

t r i j n d a e l r s y n t h s h a s t r i n g s e a r c h s u s a n t y p e s e t M e a n 1 2 3 4 5

Reduction (%)

. . 1 1 . 7 1 . 7 1 . 7 1 . 7

Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle]

Intel

SPEC 2006 MiBench

slide-170
SLIDE 170

4 . p e r l b e n c h 4 1 . b z i p 2 4 3 . g c c 4 2 9 . m c f 4 3 3 . m i l c 4 4 4 . n a m d 4 4 5 . g

  • b

m k 4 4 7 . d e a l I I 4 5 . s

  • p

l e x 4 5 3 . p

  • v

r a y 4 5 6 . h m m e r 4 5 8 . s j e n g 4 6 2 . l i b q u a n t u m 4 6 4 . h 2 6 4 r e f 4 7 . l b m 4 7 1 .

  • m

n e t p p 4 7 3 . a s t a r 4 8 2 . s p h i n x 3 4 8 3 . x a l a n c b m k M e a n 5 10 15 20 25 30

Reduction (%)

1 . 8 3 . 5 . 7 5 . 9 6 . 6 . 1

Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle]

ARM

SPEC 2006

slide-171
SLIDE 171

Compilation Time

4 . p e r l b e n c h 4 1 . b z i p 2 4 3 . g c c 4 2 9 . m c f 4 3 3 . m i l c 4 4 4 . n a m d 4 4 5 . g

  • b

m k 4 4 7 . d e a l I I 4 5 . s

  • p

l e x 4 5 3 . p

  • v

r a y 4 5 6 . h m m e r 4 5 8 . s j e n g 4 6 2 . l i b q u a n t u m 4 6 4 . h 2 6 4 r e f 4 7 . l b m 4 7 1 .

  • m

n e t p p 4 7 3 . a s t a r 4 8 2 . s p h i n x 3 4 8 3 . x a l a n c b m k M e a n 1 2 3 4

Normalized Time

1 . 1 . 1.15 1 . 4 7 1 . 7 4

Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10]

SPEC 2006

slide-172
SLIDE 172

Runtime Overhead

4 . p e r l b e n c h 4 1 . b z i p 2 4 3 . g c c 4 2 9 . m c f 4 3 3 . m i l c 4 4 4 . n a m d 4 4 5 . g

  • b

m k 4 4 7 . d e a l I I 4 5 . s

  • p

l e x 4 5 3 . p

  • v

r a y 4 5 6 . h m m e r 4 5 8 . s j e n g 4 6 2 . l i b q u a n t u m 4 6 4 . h 2 6 4 r e f 4 7 . l b m 4 7 1 .

  • m

n e t p p 4 7 3 . a s t a r 4 8 2 . s p h i n x 3 4 8 3 . x a l a n c b m k M e a n 0.8 0.9 1.0 1.1 1.2

Normalized Runtime

1 . 1 . 1 . 2 1 . 3 1 . 3

Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10]

SPEC 2006

slide-173
SLIDE 173

Profile-Guided Results

1 2 3 4 5

Reduction (%)

0.50 0.75 1.00 1.10 1.20

Normalized Runtime

SoA FMSA [NO-PG] FMSA [PG-V1] FMSA [PG-V2]

SPEC 2006: 433.milc

slide-174
SLIDE 174

Example: State of the Art

slide-175
SLIDE 175

Example of Identical Functions

template <int dim> unsigned int PolynomialSpace<dim>:: compute_n_pols (const unsigned int n) { unsigned int n_pols = n; for (unsigned int i=1; i<dim; ++i) { n _pols *= (n+i); n _pols /= (i+ 1); } return n_pols; } unsigned int PolynomialSpace<1>:: compute_n_pols(const unsigned int n) { return n; } template <int dim> inline unsigned int TensorProductPolynomials<dim>:: x_to_the_dim (const unsigned int x) { unsigned int y = 1; for (unsigned int d=0; d<dim; ++d) { y *= x; } return y; } unsigned int TensorProductPolynomials<1>:: x_to_the_dim(const unsigned int x) { return x; }

After template specialization and applying optimizations:

slide-176
SLIDE 176
slide-177
SLIDE 177

Compilation Pipeline

.c .c .c ...

  • pt

...

FE FE FE

  • pt
  • pt

link

  • pt

FM

BE

.o

Function Merging LTO IR

}

Back End

Front End

...