65
Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta

Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

  • View
    223

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Tree-Traversal Orientation Analysis Tree-Traversal Orientation Analysis

Stephen Curial, Kevin Andrusky and José Nelson AmaralUniversity of Alberta

Stephen Curial, Kevin Andrusky and José Nelson AmaralUniversity of Alberta

Page 2: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

OverviewOverview

A compiler-based analysis to determine the predominant orientation of traversal of trees.

The compiler automatically inserts instrumentation into the the program to create an instrumented executable that computes an orientation score for each tree in the program.

Page 3: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

OverviewOverview

A compiler-based analysis to determine the predominant orientation of traversal of trees.

The compiler automatically inserts instrumentation into the the program to create an instrumented executable that computes an orientation score for each tree in the program.

Page 4: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

dfs(tree *t){ if(t = NULL)

return; dfs(t->left); dfs(t->right);}

OverviewOverview

Program Source

InstrumentedExecutable

?

Compiler

Tree Analysis Library

Orientation Score

“Typical”Input

Page 5: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Tree-Traversal Orientation AnalysisTree-Traversal Orientation Analysis

Returns an orientation score [-1,1] 1 is depth-first traversal -1 is breadth first traversal 0 is an unknown traversal

Returns an orientation score [-1,1] 1 is depth-first traversal -1 is breadth first traversal 0 is an unknown traversal

DFSBFS

-1 0 1

Page 6: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

OverviewOverview

struct tree *t1, *t2;init(t1,t2);dfs(t1);bfs(t2);…

… …

t1 t2

orientation score = 1.0 orientation score = -1.0

Page 7: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Calculating the Orientation Score Calculating the Orientation Score

Every memory access to a tree is classified as: Depth-First Breadth-First Both Neither

The orientation score of each tree is calculated as:

Every memory access to a tree is classified as: Depth-First Breadth-First Both Neither

The orientation score of each tree is calculated as:

num _ depth − num _breadth

num _ accesses∈ −1,1[ ]

Page 8: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Calculating the Orientation Score Calculating the Orientation Score

A linked-list access could be classified as both Breadth- and Depth-First.

In this analysis a memory access to a 1-arity tree is classified as Depth-First.

An alternative is to provide a three-dimensional score that also classifies linked-list traversal.

A linked-list access could be classified as both Breadth- and Depth-First.

In this analysis a memory access to a 1-arity tree is classified as Depth-First.

An alternative is to provide a three-dimensional score that also classifies linked-list traversal.

Page 9: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if an Access is Depth-First

Determining if an Access is Depth-First

The TAL maintains a stack of choice-points for each tree.

Each choice-point consists of: 1. the address of a node, t, in the tree,

2. all n children of t, c1 … cn, with a boolean representing if they have been visited, and

3. a boolean value representing if the node has been visited

The TAL maintains a stack of choice-points for each tree.

Each choice-point consists of: 1. the address of a node, t, in the tree,

2. all n children of t, c1 … cn, with a boolean representing if they have been visited, and

3. a boolean value representing if the node has been visited

Page 10: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

cptop: the address of the choice point on top of the stack;

t: the address of the tree node been referenced now;

cplow: the address of a choice point below cptop in the stack;

cptop: the address of the choice point on top of the stack;

t: the address of the tree node been referenced now;

cplow: the address of a choice point below cptop in the stack;

cptop

cplow

Page 11: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

An access to tree node t is classified as depth-first if and only if:

1. cptop is equal to t; OR

2. A child ci of cptop is equal to t; OR

3. There exists a lower choice point in the stack cplow

such that cplow or a child of cplow is equal t AND all of the choice-points on the stack above cplow have been visited.

An access to tree node t is classified as depth-first if and only if:

1. cptop is equal to t; OR

2. A child ci of cptop is equal to t; OR

3. There exists a lower choice point in the stack cplow

such that cplow or a child of cplow is equal t AND all of the choice-points on the stack above cplow have been visited.

cptop

cplow

Page 12: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

Every time a node is visited, a choice-point for that node is pushed onto the stack.

Every time a node is visited, a choice-point for that node is pushed onto the stack.

1

2 3

8 9 a b c d e f

7654

Page 13: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

Every time a node is visited, a choice-point for that node is pushed onto the stack.

Every time a node is visited, a choice-point for that node is pushed onto the stack.

1

2 3

8 9 a b c d e f

7654

1 (2,3)

t = 1

ctop

node (c1,c2)

Page 14: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

1(2,3)2 (4,5)

Dark color means visited

t = 2

ctop

Condition 2: t = c1 2 is DFS

Page 15: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 4

4 (8,9)

1(2,3)2 (4,5) ctop

Condition 2: t = c1 4 is DFS

Page 16: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 8

4 (8,9)

1(2,3)2 (4,5)

ctop

Condition 2: t = c1 8 is DFS

Note: Children of 8are null thus 8 is not a choice point.

Page 17: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 9

4 (8,9)

1(2,3)2 (4,5)

ctop

Condition 2: t = c2 9 is DFS

Note: Children of 9are null thus 9 is not a choice point.

Page 18: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 5

4 (8,9)

1(2,3)2 (4,5)

ctop

clow

Condition 3: t = clow.c2 5 is DFSPop everything above clow

Page 19: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 5

1(2,3)2 (4,5) ctop

Condition 3: t = clow.c2 5 is DFSPop everything above clow

Page 20: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 5

1(2,3)2 (4,5)

ctop5 (a,b)

Page 21: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = a

1(2,3)2 (4,5)

ctop

Condition 2: t = c1 a is DFS

5 (a,b)

Page 22: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = b

1(2,3)2 (4,5)

ctop

Condition 2: t = c2 b is DFS

5 (a,b)

Page 23: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 3

1(2,3)2 (4,5)

ctop

Condition 3: t = clow.c2 b is DFSPop everything above clow

5 (a,b)

clow

Page 24: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Depth-First

Determining if a Access is Depth-First

1

2 3

8 9 a b c d e f

7654

t = 3

1(2,3)3 (6,7)

ctop

Page 25: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

The TAL maintains an open and next list for each tree. They are stored as double-ended bit-vectors.

If an access is found in the open list it is classified as Breadth-First.

The TAL maintains an open and next list for each tree. They are stored as double-ended bit-vectors.

If an access is found in the open list it is classified as Breadth-First.

1 2 3 4 5 6 7 8 9 a b c d e f

1 2 3 4 5 6 7 8 9 a b c d e f

Open

Next

Page 26: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

Open

Next

Page 27: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

2 3

Open

Next

Page 28: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

2 3Open

Next

Page 29: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

2 3Open

Next

Access is classified as Breadth-First

Page 30: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

3Open

Next

Page 31: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

3

4 5

Open

Next

Page 32: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

3

4 5 6 7

Open

Next

Access is classified as Breadth-First

Page 33: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

4 5 6 7

Open

Next

Page 34: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

4 5 6 7Open

Next

Page 35: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

4 5 6 7

8 9

Open

Next

Access is classified as Breadth-First

Page 36: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Determining if a Access is Breadth-First

Determining if a Access is Breadth-First

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

When tree node t is accessed: The children of t are added to the next list. If t is in the open list it is removed from the open list

and the access is classified as breadth first. When the open list is empty it is swapped with the

next list.

1

2 3

8 9 a b c d e f

7654

5 6 7

8 9

Open

Next

Page 37: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

ImplementationImplementationBuilt in the Open Research Compiler (ORC)

Operates on the WHIRL (Winning Hierarchical Intermediate Representation Language) IR.

Analysis requires Interprocedural Analysis (IPA).Automatically identifies link-based tree data structures

using Ghiya and Hendren’s analysis [2] or programmer annotations.

Instrumentation can be inserted into each procedure without IPA.

Built in the Open Research Compiler (ORC) Operates on the WHIRL (Winning Hierarchical

Intermediate Representation Language) IR. Analysis requires Interprocedural Analysis (IPA).

Automatically identifies link-based tree data structures using Ghiya and Hendren’s analysis [2] or programmer annotations.

Instrumentation can be inserted into each procedure without IPA.

Page 38: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

ImplementationImplementation

Calls our Tree Analysis Library (TAL) register_tree_access_with_children()

Takes Parameters: void *addr_deref int tree_id int num_children void *child_addr, …

Calls our Tree Analysis Library (TAL) register_tree_access_with_children()

Takes Parameters: void *addr_deref int tree_id int num_children void *child_addr, …

Page 39: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

ImplementationImplementation

Analysis is safe and will not cause a correct program to fail.

Replace calls to malloc/calloc/realloc with TALs wrapper functions. If memory allocation fails, the analysis is abandoned and

the memory used by the analysis is freed.

Memory address are calculated and accessed for the instrumentation in locations that are safe. i.e. Will not dereference null pointers

if( tree != NULL && tree->data == 1)

Analysis is safe and will not cause a correct program to fail.

Replace calls to malloc/calloc/realloc with TALs wrapper functions. If memory allocation fails, the analysis is abandoned and

the memory used by the analysis is freed.

Memory address are calculated and accessed for the instrumentation in locations that are safe. i.e. Will not dereference null pointers

if( tree != NULL && tree->data == 1)

Page 40: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?How do we identify tree references? Example Code:

/* inorder tree traversal */void inorder_traverse_tree(struct tn *tree_ptr){

if(tree_ptr == NULL) return;

inorder_traverse_tree(tree_ptr->left); tree_ptr->data++; inorder_traverse_tree(tree_ptr->right);

}

Example Code:

/* inorder tree traversal */void inorder_traverse_tree(struct tn *tree_ptr){

if(tree_ptr == NULL) return;

inorder_traverse_tree(tree_ptr->left); tree_ptr->data++; inorder_traverse_tree(tree_ptr->right);

}

Page 41: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IFLOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags 0x7e

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IFLOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags 0x7e

LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8> <field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1> LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<30,tn,8> T<31,anon_ptr.,8> <field_id:3> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags 0x7e RETURN END_BLOCK

void inorder_traverse_tree(struct tn *tree_ptr)

{ if(tree_ptr == NULL) return; inorder_traverse_tree(tree_ptr-

>left); tree_ptr->data++; inorder_traverse_tree(tree_ptr-

>right);}

void inorder_traverse_tree(struct tn *tree_ptr)

{ if(tree_ptr == NULL) return; inorder_traverse_tree(tree_ptr-

>left); tree_ptr->data++; inorder_traverse_tree(tree_ptr-

>right);}

Page 42: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1> LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:3> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e RETURN END_BLOCK

FUNC_ENTRY(inorder_traverse_tree)

IDNAME(tree_ptr)

BLOCK BLOCK BLOCK

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr)

LOC 1 95 {

FUNC_ENTRY <1,25,inorder_traverse_tree>

IDNAME 0 <2,1,tree_ptr>

BODY

BLOCK

END_BLOCK

BLOCK

END_BLOCK

BLOCK

void inorder_traverse_tree(struct tn *tree_ptr)

Page 43: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1> LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:3> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e RETURN END_BLOCK

FUNC_ENTRY(inorder_traverse_tree)

IDNAME(tree_ptr)

BLOCK BLOCK BLOCK

IF

EQ

LDID(tree_ptr)

INTCONST 0x0

RETURN

BLOCK(then)

LOC 1 96 if(tree_ptr == NULL)

IF

U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8>

U8INTCONST 0 (0x0)

I4U8EQ

THEN

BLOCK

LOC 1 97 return;

RETURN

END_BLOCK

if(tree_ptr == NULL)

Page 44: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1> LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:3> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e RETURN END_BLOCK

BLOCK

VCALL

PARAM

ILOAD (offset 8)

LDID(tree_ptr)

LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8> <field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags 0x7e

inorder_traverse_tree(tree_ptr->left);

Page 45: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 {FUNC_ENTRY <1,25,inorder_traverse_tree> IDNAME 0 <2,1,tree_ptr>BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 <2,1,tree_ptr> T<32,anon_ptr.,8> U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK ELSE LOC 1 96 BLOCK END_BLOCK END_IF

LOC 1 100 LOC 1 101 inorder_traverse_tree(tree_ptr->left); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:2> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1> LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<30,tn,8> T<31,anon_ptr.,8>

<field_id:3> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,25,inorder_traverse_tree> # flags

0x7e RETURN END_BLOCK

BLOCK

VCALL

PARAM

ILOAD (offset 8)

LDID(tree_ptr)

ISTORE (offset 8)

LDID(tree_ptr)

ADD

INTCONST 0x1

ILOAD (offset 0)

LDID(tree_ptr)

LOC 1 102 tree_ptr->data++; U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4I4ILOAD 0 T<30,tn,8> T<31,anon_ptr.,8> <field_id:1> I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> I4ISTORE 0 T<31,anon_ptr.,8> <field_id:1>

tree_ptr->data++;

Page 46: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?BLOCK

VCALL

PARAM

ILOAD (offset 8)

LDID(tree_ptr)

VCALL

PARAM

ILOAD (offset 16)

LDID(tree_ptr)

ISTORE (offset 8)

LDID(tree_ptr)

ADD

INTCONST 0x1

ILOAD (offset 0)

LDID(tree_ptr)

FUNC_ENTRY(inorder_traverse_tree)

BLOCK BLOCK

IF

EQ

LDID INTCONST 0x0

RETURN

BLOCK(then)

void inorder_traverse_tree(struct tn *tree_ptr)

{ if(tree_ptr == NULL) return; inorder_traverse_tree(tree_ptr-

>left); tree_ptr->data++; inorder_traverse_tree(tree_ptr-

>right);}

void inorder_traverse_tree(struct tn *tree_ptr)

{ if(tree_ptr == NULL) return; inorder_traverse_tree(tree_ptr-

>left); tree_ptr->data++; inorder_traverse_tree(tree_ptr-

>right);}

Page 47: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?BLOCK

VCALL

PARAM

VCALL

PARAM

ISTORE (offset 8)

LDID(tree_ptr)

ADD

INTCONST 0x1

FUNC_ENTRY(inorder_traverse_tree)

BLOCK BLOCK

IF

EQ

LDID INTCONST 0x0

RETURN

BLOCK(then) ILOAD

(offset 8)

LDID(tree_ptr)

ILOAD (offset 0)

LDID(tree_ptr)

ILOAD (offset 16)

LDID(tree_ptr)

Where are the tree accesses?

Page 48: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

How do we identify tree references?

How do we identify tree references?BLOCK

VCALL

PARAM

VCALL

PARAM

ISTORE (offset 8)

LDID(tree_ptr)

ADD

INTCONST 0x1

FUNC_ENTRY(inorder_traverse_tree)

BLOCK BLOCK

IF

EQ

LDID INTCONST 0x0

RETURN

BLOCK(then) ILOAD

(offset 8)

LDID(tree_ptr)

ILOAD (offset 0)

LDID(tree_ptr)

ILOAD (offset 16)

LDID(tree_ptr)

This is where our extension to the ORC inserts code into the WHIRL Tree.

Page 49: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

The Nodes we Insert Into WHIRLThe Nodes we Insert Into WHIRL

U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value U4INTCONST 1 (0x1) U4PARM 2 T<8,.predef_U4,4> # by_value U4INTCONST 2 (0x2) U4PARM 2 T<8,.predef_U4,4> # by_value U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<31,anon_ptr.,8> T<34,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<31,anon_ptr.,8> T<34,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,21,register_access_with_children> # flags 0x7e

U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value U4INTCONST 1 (0x1) U4PARM 2 T<8,.predef_U4,4> # by_value U4INTCONST 2 (0x2) U4PARM 2 T<8,.predef_U4,4> # by_value U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 8 T<31,anon_ptr.,8> T<34,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value U8U8LDID 0 <2,1,tree_ptr> T<31,anon_ptr.,8> U8U8ILOAD 16 T<31,anon_ptr.,8> T<34,anon_ptr.,8> U8PARM 2 T<31,anon_ptr.,8> # by_value VCALL 126 <1,21,register_access_with_children> # flags 0x7e

Page 50: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

The Nodes we Insert Into WHIRLThe Nodes we Insert Into WHIRL

VCALL(register_tree_access_with_children)

ILOAD(offset 16)

ILOAD(offset 8)

PARM PARM PARM PARM

INTCONST0x1

INTCONST0x2

LDID(tree_ptr)

LDID(tree_ptr)

PARM

LDID(tree_ptr)

Page 51: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Experimental SetupExperimental Setup

Open Research Compiler v2.1 Optimization level -O3

1.3 GHz Itanium21 GB of RAM

Open Research Compiler v2.1 Optimization level -O3

1.3 GHz Itanium21 GB of RAM

Page 52: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Synthetic BenchmarksSynthetic Benchmarks

RandomDepth: DFS traversal of binary tree, children visited in random order;

BreadthFirst: BFS on binary tree;

DepthBreadth: DFS followed by BFS on binary tree;

NonStandard: A traversal that is neither BFS nor DFS;

MultiDepth: Several DFSs: in-order, pre-order, and post-order;

BreadthSearch: Several BFS searchers on a tree with random branching factor (2 to 6);

BinarySearch: Several searches in a binary tree.

RandomDepth: DFS traversal of binary tree, children visited in random order;

BreadthFirst: BFS on binary tree;

DepthBreadth: DFS followed by BFS on binary tree;

NonStandard: A traversal that is neither BFS nor DFS;

MultiDepth: Several DFSs: in-order, pre-order, and post-order;

BreadthSearch: Several BFS searchers on a tree with random branching factor (2 to 6);

BinarySearch: Several searches in a binary tree.

Page 53: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Analysis Results (Synthetic Benchmark)

Analysis Results (Synthetic Benchmark)

BenchmarkOrientation Score

Expected ExperimentalRandom Depth 1.0 1.000000Breadth-First -1.0 -0.999992Depth-Breadth 0.0 0.000000Non-Standard 0.0 0.136381Multi Depth 1.0 0.999974Breadth Search -1.0 -0.995669Binary Search 1.0 0.941225

Page 54: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Analysis Results (Olden Benchmark)

Analysis Results (Olden Benchmark)

BenchmarkOrientation Score

Expected ExperimentalBH 0.0 0.010266Bisort 0.0 -0.001014Health 1.0 0.807330MST Low positive 0.335852 Perimeter Low positive 0.195177Power 1.0 0.991617Treeadd 1.0 1.000000TSP Low positive 0.173267

Page 55: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Runtime Overhead (Synthetic Benchmark)

Runtime Overhead (Synthetic Benchmark)

BenchmarkRuntime (s)

Original InstrumentedRandom Depth 0.90 10.72Breadth-First 1.09 1.81Depth-Breadth 1.33 7.84Non-Standard 0.36 2.68Multi Depth 0.47 3.94 Breadth Search 0.36 1.83Binary Search 0.20 2.75

Page 56: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Runtime Overhead (Olden Benchmark)

Runtime Overhead (Olden Benchmark)

BenchmarkRuntime (s)

Original InstrumentedBH 0.45 6.88Bisort 0.03 1.01Health 0.05 12.06MST 5.71 11.42Perimeter 0.02 1.55Power 1.35 1.60Treeadd 0.13 6.35TSP 0.01 1.40

Page 57: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Memory Overhead (Synthetic Benchmark)

Memory Overhead (Synthetic Benchmark)

BenchmarkMemory Usage (kbytes)

Original InstrumentedRandom Depth 854 976 855 040 Breadth-First 424 928 441 328 Depth-Breadth 220 112 252 896Non-Standard 420 800 420 912Multi Depth 529 344 652 288Breadth Search 30 192 47 408Binary Search 224 192 224 320

Page 58: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Memory Overhead (Olden Benchmark)

Memory Overhead (Olden Benchmark)

BenchmarkMemory Usage (kbytes)

Original InstrumentedBH 3 520 3 520Bisort 3 008 3 040Health 8 448 8 624MST 4 752 6 272Perimeter 6 064 6 528Power 3 648 3 712Treeadd 3 008 3 008TSP 3 024 3 040

Page 59: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Possible Clients of the AnalysisPossible Clients of the Analysis

Prefetching Luk and Mowry - History-Pointer Prefetching [7] Cahoon and McKinley - Jump-Pointer Prefetching [3]

Prefetching Luk and Mowry - History-Pointer Prefetching [7] Cahoon and McKinley - Jump-Pointer Prefetching [3]

struct myStruct{ int data; struct myStruct *next;};

struct myStruct{ int data; struct myStruct *next; struct myStruct *prefetch;};

Page 60: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Possible Clients of the AnalysisPossible Clients of the Analysis

Prefetching In the first iteration through the pointer chasing

loop there is no prefetching (initializing prefetch pointers).

If the traversal is known, the history pointers can be initialized as the data structure is allocated.Eliminate compulsory cache misses

Prefetching In the first iteration through the pointer chasing

loop there is no prefetching (initializing prefetch pointers).

If the traversal is known, the history pointers can be initialized as the data structure is allocated.Eliminate compulsory cache misses

Page 61: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Possible Clients of the AnalysisPossible Clients of the Analysis

Modify Data Layout Memory Allocation

Calder et al. [4] and Chilimbi, Hill and Larus [6]Create a custom allocator or a reallocation

method that (re)organizes the data structure.Manual & semi-automatic techniques.

Automatically insert the allocation calls with a hint from our analysis.

Modify Data Layout Memory Allocation

Calder et al. [4] and Chilimbi, Hill and Larus [6]Create a custom allocator or a reallocation

method that (re)organizes the data structure.Manual & semi-automatic techniques.

Automatically insert the allocation calls with a hint from our analysis.

Page 62: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Possible Clients of the AnalysisPossible Clients of the Analysis

Modify Data Layout Structure Reorganization

Truong, Bodin and Seznec [8] Chilimbi, Davidson and Larus [5]

Use analysis information with Chilimbi’s data outlining or Truong’s ialloc memory allocator to improve spatial locality.

Modify Data Layout Structure Reorganization

Truong, Bodin and Seznec [8] Chilimbi, Davidson and Larus [5]

Use analysis information with Chilimbi’s data outlining or Truong’s ialloc memory allocator to improve spatial locality.

Page 63: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

ConclusionConclusion

Developed an efficient analysis to automatically determine the orientation of tree traversals. Instrumented applications only require 7%

more memory. There are many clients for this analysis

that can potentially improve program performance.

Developed an efficient analysis to automatically determine the orientation of tree traversals. Instrumented applications only require 7%

more memory. There are many clients for this analysis

that can potentially improve program performance.

Page 64: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

Questions?Questions?

Page 65: Tree-Traversal Orientation Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José

ReferencesReferences [1] J. Patterson. Modern Microprocessors A 90 Minute Guide!

http://www.pattosoft.com.au/Articles/ModernMicroprocessors/ [2] R. Ghiya and L. J. Hendren. Is it a tree, a dag, or a cyclic graph? A

shape analysis for heap directed pointers in C. POPL 1996 [3] B.Cahoon and K.S. McKinley. Data flow analysis for software

prefetching linked data structures in Java. PACT ‘01 [4] B.Calder, C. Krintz, S. John, T. Austin. Cache-conscious data

placement. ASPLOS-VIII, 1998 [5] T.M. Chilimbi, B. Davidson and J.R. Larus. Cache-conscious

structure definition. PLDI ‘99 [6] T.M. Chilimbi, M.D. Hill and J.R. Larus. Cache-conscious structure

layout. PLDI ‘99 [7] C.K. Luk and T.C. Mowry. Compiler-based prefetching for recursive

data structures. ACM SIGOPS Operating Systems Review, 1996. [8] D.N. Truong, F. Bodin and A. Seznec. Improving cache behavior of

dynamically allocated data structures. PACT ‘98

[1] J. Patterson. Modern Microprocessors A 90 Minute Guide! http://www.pattosoft.com.au/Articles/ModernMicroprocessors/

[2] R. Ghiya and L. J. Hendren. Is it a tree, a dag, or a cyclic graph? A shape analysis for heap directed pointers in C. POPL 1996

[3] B.Cahoon and K.S. McKinley. Data flow analysis for software prefetching linked data structures in Java. PACT ‘01

[4] B.Calder, C. Krintz, S. John, T. Austin. Cache-conscious data placement. ASPLOS-VIII, 1998

[5] T.M. Chilimbi, B. Davidson and J.R. Larus. Cache-conscious structure definition. PLDI ‘99

[6] T.M. Chilimbi, M.D. Hill and J.R. Larus. Cache-conscious structure layout. PLDI ‘99

[7] C.K. Luk and T.C. Mowry. Compiler-based prefetching for recursive data structures. ACM SIGOPS Operating Systems Review, 1996.

[8] D.N. Truong, F. Bodin and A. Seznec. Improving cache behavior of dynamically allocated data structures. PACT ‘98