HPCToolkit
binarytree_uwi.h
Go to the documentation of this file.
1 #ifndef __BINARYTREE_UWI_H__
2 #define __BINARYTREE_UWI_H__
3 
4 //******************************************************************************
5 // global include files
6 //******************************************************************************
7 
8 #include <stdint.h>
9 #include <stdbool.h>
10 
11 
12 //******************************************************************************
13 // local include files
14 //******************************************************************************
15 
17 #include "interval_t.h"
18 
19 
20 /******************************************************************************
21  * macros to convert the old unwind interval data structure
22  *
23 
24 struct unwind_interval_t {
25  struct splay_interval_s common;
26  ra_loc ra_status;
27  int sp_ra_pos;
28  int sp_bp_pos;
29  bp_loc bp_status;
30  int bp_ra_pos;
31  int bp_bp_pos;
32  struct unwind_interval_t *prev_canonical;
33  int restored_canonical;
34  bool has_tail_calls;
35 };
36 typedef struct unwind_interval_t unwind_interval;
37 
38  * to the new one, which is bitree_uwi_t, a binary tree of uwi_t.
39  *
40  ******************************************************************************/
41 
42 #define UWI_NEXT(btuwi) (bitree_uwi_rightsubtree(btuwi))
43 #define UWI_START_ADDR(btuwi) (bitree_uwi_interval(btuwi))->start
44 #define UWI_END_ADDR(btuwi) (bitree_uwi_interval(btuwi))->end
45 #define MAX_RECIPE_STR 256
46 
47 //******************************************************************************
48 // abstract data type
49 //******************************************************************************
50 
51 typedef struct recipe_s uw_recipe_t;
52 
53 typedef struct uwi_s {
55  char recipe[];
56 } uwi_t;
57 
58 typedef struct bitree_uwi_s bitree_uwi_t;
59 
60 typedef struct btuwi_status_s {
63  int count;
64  int error; // 0 if no error; value = error code or count depending upon unwinder
66 
67 typedef enum unwinder_e {
71 } unwinder_t;
72 
73 /*
74  * initialize the MCS lock for the hidden global free unwind interval tree.
75  */
76 void
77 bitree_uwi_init(mem_alloc m_alloc);
78 
79 /*
80  * Returns a bitree_uwi_t node whose left and right subtree nodes are NULL.
81  * The root value of the returned node is a non-null uwi_t*, which is a pair
82  * of the form (interval_t* interval, uw_recipe_t* recipe).
83  * interval is non-null and *interval = [0, 0).
84  * recipe is non-null and points to a concrete instance of an unwind recipe.
85  */
87 bitree_uwi_malloc(unwinder_t uw, size_t recipe_size);
88 
89 /*
90  * If tree != NULL return tree to global free tree,
91  * otherwise do nothing.
92  */
94 
95 
96 // return the value at the root
97 // pre-condition: tree != NULL
98 uwi_t*
100 
101 // pre-condition: tree != NULL
104 
105 // pre-condition: tree != NULL
108 
109 void
112  bitree_uwi_t* subtree);
113 
114 void
117  bitree_uwi_t* subtree);
118 
119 // return the interval_t part of the interval_t key of the tree root
120 // pre-condition: tree != NULL
121 interval_t*
123 
124 // return the recipe_t value of the tree root
125 // pre-condition: tree != NULL
128 
129 // given a tree that is a list, with all left children empty,
130 // restructure to make a balanced tree
131 bitree_uwi_t *
133 
134 // restructure a binary tree so that all its left children are null
137 
138 // use uwi_t_cmp to find a matching node in a binary search tree of uwi_t
139 // empty tree is returned if no match is found.
142 
143 // use uwi_t_inrange to find a node in a binary search tree of uwi_t that
144 // contains the given address
145 // empty tree is returned if no such node is found.
147 bitree_uwi_inrange(bitree_uwi_t *tree, uintptr_t address);
148 
149 /*
150  * Concrete implementation of the abstract val_tostr function of the
151  * generic_val class.
152  * pre-condition: uwr is of type uw_recipe_t*
153  */
154 void
155 uw_recipe_tostr(void* uwr, char str[], unwinder_t uw);
156 
157 void
158 uw_recipe_print(void* uwr);
159 
160 // compute a string representing the binary tree printed vertically and
161 // return result in the treestr parameter.
162 // caller should provide the appropriate length for treestr.
163 void
164 bitree_uwi_tostring_indent(bitree_uwi_t *tree, char *indents, char treestr[], unwinder_t uw);
165 
166 #endif /* __BINARYTREE_UWI_H__ */
unwinder_e
bitree_uwi_t * bitree_uwi_rightsubtree(bitree_uwi_t *tree)
void uw_recipe_print(void *uwr)
bitree_uwi_t * first
void *(* mem_alloc)(size_t size)
Definition: mem_manager.h:17
bitree_uwi_t * bitree_uwi_find(bitree_uwi_t *tree, uwi_t *val)
uwi_t * bitree_uwi_rootval(bitree_uwi_t *tree)
bitree_uwi_t * bitree_uwi_flatten(bitree_uwi_t *tree)
char * first_undecoded_ins
struct uwi_s uwi_t
void uw_recipe_tostr(void *uwr, char str[], unwinder_t uw)
bitree_uwi_t * bitree_uwi_malloc(unwinder_t uw, size_t recipe_size)
interval_t interval
void bitree_uwi_free(unwinder_t uw, bitree_uwi_t *tree)
bitree_uwi_t * bitree_uwi_inrange(bitree_uwi_t *tree, uintptr_t address)
uw_recipe_t * bitree_uwi_recipe(bitree_uwi_t *tree)
interval_t * bitree_uwi_interval(bitree_uwi_t *tree)
struct bitree_uwi_s bitree_uwi_t
struct btuwi_status_s btuwi_status_t
void bitree_uwi_init(mem_alloc m_alloc)
void bitree_uwi_set_leftsubtree(bitree_uwi_t *tree, bitree_uwi_t *subtree)
void bitree_uwi_tostring_indent(bitree_uwi_t *tree, char *indents, char treestr[], unwinder_t uw)
bitree_uwi_t * bitree_uwi_leftsubtree(bitree_uwi_t *tree)
char recipe[]
void bitree_uwi_set_rightsubtree(bitree_uwi_t *tree, bitree_uwi_t *subtree)
enum unwinder_e unwinder_t
bitree_uwi_t * bitree_uwi_rebalance(bitree_uwi_t *tree, int count)
struct recipe_s uw_recipe_t
bitree_uwi_t * tree