Presentation is loading. Please wait.

Presentation is loading. Please wait.

Determining Tree-Traversals Orientation using Feedback-Directed Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen.

Similar presentations


Presentation on theme: "Determining Tree-Traversals Orientation using Feedback-Directed Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen."— Presentation transcript:

1 Determining Tree-Traversals Orientation using Feedback-Directed Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta

2 Why do we need to know the orientation of tree-traversals? High Memory Latency Memory Wall Compilers can improve spatial locality Using data transformations Must know the data access pattern before re- arranging High Memory Latency Memory Wall Compilers can improve spatial locality Using data transformations Must know the data access pattern before re- arranging Image Courtesy [1]

3 Overview We develop a compiler based analysis to determine the Tree-Traversal Orientation. Given a program as input, the compiler automatically inserts instrumentation into the the program to create an instrumented executable that will determine an orientation score for each tree in the program.

4 Overview We develop a compiler based analysis to determine the Tree-Traversal Orientation. Given a program as input, the compiler automatically inserts instrumentation into the the program to create an instrumented executable that will determine an orientation score for each tree in the program.

5 dfs(tree *t){ if(t = NULL) return; dfs(t->left); dfs(t->right); } Overview Program Source Instrumented Executable Orientation Score ? Compiler Tree Analysis Library

6 Tree-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 DFS BFS 0 1

7 Overview struct tree *t1, *t2; init(t1,t2); dfs(t1); bfs(t2); … …… t1t2 orientation score = 1.0 orientation score = -1.0

8 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:

9 Calculating the Orientation Score A linked-list access can be classified as both Breadth- and Depth-First. If a memory access to a 1-arity tree is classified as both Breadth- and Depth-First It will be considered Depth-First. This result will likely be more useful to clients of the analysis. A linked-list access can be classified as both Breadth- and Depth-First. If a memory access to a 1-arity tree is classified as both Breadth- and Depth-First It will be considered Depth-First. This result will likely be more useful to clients of the analysis.

10 Determining if a 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, c 1 … c n, 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, c 1 … c n, and 3. a boolean value representing if the node has been visited

11 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 …

12 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 … 2 3

13 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 … 2 3 4 5 Dark color means visited

14 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 … 2 3 4 5 8 9

15 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 … 2 3 4 5 8 9

16 Determining if a Access is Depth-First Every time a node is visited, a choice-point for each of its children is pushed onto the stack. 1 2 3 89abcdef 7654 … 2 3 4 5 8 9

17 Determining if a Access is Depth-First A choice-point is popped off the stack when a tree node lower in the stack is visited and all of the choice-points above have been visited. All the choice points up to the node that was visited are popped. 1 2 3 89abcdef 7654 … 2 3 4 5 8 9

18 Determining if a Access is Depth-First A choice-point is popped off the stack when a tree node lower in the stack is visited and all of the choice-points above have been visited. All the choice points up the node that was visited are popped. 1 2 3 89abcdef 7654 … 2 3 4 5

19 Determining if a Access is Depth-First A choice-point is popped off the stack when a tree node lower in the stack is visited and all of the choice-points above have been visited. All the choice points up the node that was visited are popped. 1 2 3 89abcdef 7654 … 2 3 4 5 a b

20 Determining if a Access is Depth-First An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. cp top

21 Determining if a Access is Depth-First An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. cp top

22 Determining if a Access is Depth-First An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. cp top

23 Determining if a Access is Depth-First An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. An access to tree node t is classified as depth-first if and only if: 1. The address of cp top is equal to the address of t; OR 2. The address of child c i of cp top is equal to the address of t; OR 3. There exists and ancestor cp anc of cp top such that the address of cp anc is equal to the address of t and all of the choice-points on the stack above cp anc have been visited. cp anc cp top

24 Determining if a Access is Breadth-First The TAL maintains an open and next list for each tree. They are stored a double-ended bit-vectors. The TAL maintains an open and next list for each tree. They are stored a double-ended bit-vectors. 123456789abcdef 123456789abcdef Open Next

25 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 89abcdef 7654 … Open Next

26 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 89abcdef 7654 … 23 Open Next

27 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 89abcdef 7654 … 23 Open Next

28 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 89abcdef 7654 … 23 Open Next

29 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 89abcdef 7654 … 3 Open Next

30 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 89abcdef 7654 … 3 45 Open Next

31 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 89abcdef 7654 … 4567 Open Next

32 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 89abcdef 7654 … 4567 Open Next

33 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 89abcdef 7654 … 567 89 Open Next

34 Implementation 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. 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.

35 Implementation 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, …

36 Implementation 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)

37 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); }

38 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK

39 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK FUNC_ENTRY (inorder_traverse_tree) IDNAME (tree_ptr) BLOCK LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK void inorder_traverse_tree(struct tn *tree_ptr)

40 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK FUNC_ENTRY (inorder_traverse_tree) IDNAME (tree_ptr) BLOCK IF EQ LDID (tree_ptr) INTCONST 0x0 RETURN BLOCK (then) LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T U8INTCONST 0 (0x0) I4U8EQ THEN BLOCK LOC 1 97 return; RETURN END_BLOCK if(tree_ptr == NULL)

41 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e inorder_traverse_tree(tree_ptr->left);

42 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # 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 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T tree_ptr->data++;

43 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK 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) LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e inorder_traverse_tree(tree_ptr->right);

44 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK 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) IDNAME (tree_ptr) BLOCK IF EQ LDIDINTCONST 0x0 RETURN BLOCK (then)

45 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK BLOCK VCALL PARAM VCALL PARAM ISTORE (offset 8) LDID (tree_ptr) ADD INTCONST 0x1 FUNC_ENTRY (inorder_traverse_tree) IDNAME (tree_ptr) BLOCK IF EQ LDIDINTCONST 0x0 RETURN BLOCK (then) Where do we access trees in memory? ILOAD (offset 8) LDID (tree_ptr) ILOAD (offset 16) LDID (tree_ptr) ILOAD (offset 0) LDID (tree_ptr)

46 How do we identify tree references? LOC 1 94 void inorder_traverse_tree(struct tn *tree_ptr) LOC 1 95 { FUNC_ENTRY IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 IDNAME 0 BODY BLOCK END_BLOCK BLOCK END_BLOCK BLOCK PRAGMA 0 120 0 (0x0) # PREAMBLE_END LOC 1 96 if(tree_ptr == NULL) IF U8U8LDID 0 T 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 T U8U8ILOAD 8 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e LOC 1 102 tree_ptr->data++; U8U8LDID 0 T I4I4ILOAD 0 T T I4INTCONST 1 (0x1) I4ADD U8U8LDID 0 T I4ISTORE 0 T LOC 1 103 inorder_traverse_tree(tree_ptr->right); U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e RETURN END_BLOCK BLOCK VCALL PARAM VCALL PARAM ISTORE (offset 8) LDID (tree_ptr) ADD INTCONST 0x1 FUNC_ENTRY (inorder_traverse_tree) IDNAME (tree_ptr) BLOCK IF EQ LDIDINTCONST 0x0 RETURN BLOCK (then) This is where our extension to the ORC inserts code into the WHIRL Tree. ILOAD (offset 8) LDID (tree_ptr) ILOAD (offset 16) LDID (tree_ptr) ILOAD (offset 0) LDID (tree_ptr)

47 The Nodes we Insert Into WHIRL U8U8LDID 0 T U8PARM 2 T # by_value U4INTCONST 1 (0x1) U4PARM 2 T # by_value U4INTCONST 2 (0x2) U4PARM 2 T # by_value U8U8LDID 0 T U8U8ILOAD 8 T T U8PARM 2 T # by_value U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e U8U8LDID 0 T U8PARM 2 T # by_value U4INTCONST 1 (0x1) U4PARM 2 T # by_value U4INTCONST 2 (0x2) U4PARM 2 T # by_value U8U8LDID 0 T U8U8ILOAD 8 T T U8PARM 2 T # by_value U8U8LDID 0 T U8U8ILOAD 16 T T U8PARM 2 T # by_value VCALL 126 # flags 0x7e

48 The Nodes we Insert Into WHIRL VCALL (register_tree_access_with_children) ILOAD (offset 16) ILOAD (offset 8) PARM INTCONST 0x1 INTCONST 0x2 LDID (tree_ptr) LDID (tree_ptr) PARM LDID (tree_ptr)

49 Experimental Setup Open Research Compiler v2.1 Optimization level -O3 1.3 GHz Itanium2 1 GB of RAM Open Research Compiler v2.1 Optimization level -O3 1.3 GHz Itanium2 1 GB of RAM

50 Analysis Results (Synthetic Benchmark) Benchmark Orientation Score ExpectedExperimental Random Depth1.01.000000 Breadth-First-0.999992 Depth-Breadth0.00.000000 Non-Standard0.00.136381 Multi Depth1.00.999974 Breadth Search-0.995669 Binary Search1.00.941225

51 Analysis Results (Olden Benchmark) Benchmark Orientation Score ExpectedExperimental BH0.0 0.010266 Bisort0.0-0.001014 Health1.00.807330 MSTLow positive0.335852 PerimeterLow positive 0.195177 Power1.00.991617 Treeadd1.01.000000 TSPLow positive0.173267

52 Runtime Overhead (Synthetic Benchmark) Benchmark Runtime (s) OriginalInstrumented Random Depth0.9010.72 Breadth-First1.091.81 Depth-Breadth1.337.84 Non-Standard0.362.68 Multi Depth0.473.94 Breadth Search0.361.83 Binary Search0.202.75

53 Runtime Overhead (Olden Benchmark) Benchmark Runtime (s) OriginalInstrumented BH0.456.88 Bisort0.031.01 Health0.0512.06 MST5.7111.42 Perimeter0.021.55 Power1.351.60 Treeadd0.136.35 TSP0.011.40

54 Memory Overhead (Synthetic Benchmark) Benchmark Memory Usage (kbytes) OriginalInstrumented Random Depth854 976855 040 Breadth-First424 928441 328 Depth-Breadth220 112252 896 Non-Standard420 800420 912 Multi Depth529 344652 288 Breadth Search30 19247 408 Binary Search224 192224 320

55 Memory Overhead (Olden Benchmark) Benchmark Memory Usage (kbytes) OriginalInstrumented BH3 520 Bisort3 0083 040 Health8 4488 624 MST4 7526 272 Perimeter6 0646 528 Power3 6483 712 Treeadd3 008 TSP3 0243 040

56 Conclusion Developed an efficient analysis to automatically determine the orientation of tree traversals Instrumented applications only require 7% more memory Developed an efficient analysis to automatically determine the orientation of tree traversals Instrumented applications only require 7% more memory

57 Questions?

58 References [1] Jason Patterson. Modern Microprocessors A 90 Minute Guide! http://www.pattosoft.com.au/Articles/ModernMicropro cessors/ http://www.pattosoft.com.au/Articles/ModernMicropro cessors/ [2] R. Ghiya, L. J. Hendren. Is it a tree, a dag, or a cyclic graph? A shape analysis for heap directed pointers in C. POPL 1996 [1] Jason Patterson. Modern Microprocessors A 90 Minute Guide! http://www.pattosoft.com.au/Articles/ModernMicropro cessors/ http://www.pattosoft.com.au/Articles/ModernMicropro cessors/ [2] R. Ghiya, L. J. Hendren. Is it a tree, a dag, or a cyclic graph? A shape analysis for heap directed pointers in C. POPL 1996


Download ppt "Determining Tree-Traversals Orientation using Feedback-Directed Analysis Stephen Curial, Kevin Andrusky and José Nelson Amaral University of Alberta Stephen."

Similar presentations


Ads by Google