@@ -53,7 +53,7 @@ def remove_backwards_edges(current_node, visited: Set, current_path: Set, cfg:nx
53
53
54
54
55
55
def compute_variable_depth (liveness_info : Dict [str , LivenessAnalysisInfoSSA ], topological_order : List ) -> Dict [
56
- str , Dict [str , Tuple [int , int ]]]:
56
+ str , Dict [str , Tuple [int , int , int ]]]:
57
57
"""
58
58
For each variable at every point in the CFG, returns the corresponding depth of the last time a variable was used
59
59
and the position being used in the current block (if any). Useful for determining in which order
@@ -63,19 +63,17 @@ def compute_variable_depth(liveness_info: Dict[str, LivenessAnalysisInfoSSA], to
63
63
variable_depth_out = dict ()
64
64
variable_depth_in = dict ()
65
65
max_depth = len (topological_order ) + 1
66
+ max_instr_idx = 100
66
67
67
68
for node in reversed (topological_order ):
68
69
block_info = liveness_info [node ].block_info
69
70
instructions = block_info .instructions
70
- max_instr_idx = len (instructions ) + 1
71
71
72
72
current_variable_depth_out = dict ()
73
73
74
74
# Initialize variables in the live_in set to len(topological_order) + 1
75
- for input_variable in liveness_info [node ].in_state .live_vars :
76
- current_variable_depth_out [input_variable ] = max_depth , max_instr_idx
77
-
78
- # Link each variable to the position being used in the instructions
75
+ for input_variable in liveness_info [node ].out_state .live_vars :
76
+ current_variable_depth_out [input_variable ] = max_depth , max_instr_idx , max_instr_idx
79
77
80
78
# For each successor, compute the variable depth information and update the corresponding map
81
79
for succ_node in block_info .successors :
@@ -84,27 +82,28 @@ def compute_variable_depth(liveness_info: Dict[str, LivenessAnalysisInfoSSA], to
84
82
# as we will visit it later
85
83
previous_variable_depth = variable_depth_in .get (succ_node , dict ())
86
84
87
- for variable , depth in previous_variable_depth .items ():
85
+ for variable , previous_variable_info in previous_variable_depth .items ():
88
86
# Update the depth if it already appears in the dict
89
87
variable_info = current_variable_depth_out .get (variable , None )
90
88
if variable_info is not None :
91
- var_depth , instr_pos = variable_info
92
89
# If the depth of the successor variable is less than the one we have actually
93
- if variable_info >= depth :
94
- current_variable_depth_out [variable ] = variable_info
90
+ if variable_info > previous_variable_info :
91
+ current_variable_depth_out [variable ] = previous_variable_info [ 0 ] + 1 , previous_variable_info [ 1 ], previous_variable_info [ 2 ]
95
92
else :
96
- current_variable_depth_out [variable ] = depth [0 ] + 1 , max_instr_idx
93
+ current_variable_depth_out [variable ] = previous_variable_info [0 ] + 1 , previous_variable_info [ 1 ], previous_variable_info [ 2 ]
97
94
95
+ # Afterwards, we update the information of the in set
98
96
current_variable_depth_in = current_variable_depth_out .copy ()
99
97
100
- # Finally, we update the corresponding variables that are defined in the blocks
101
- # for used_variable in set(block_info.uses).union(block_info.phi_uses):
102
- # current_variable_depth_out[used_variable] = 0
98
+ # Link each variable to the position being used in the instructions
99
+ for i , instruction in enumerate (instructions ):
100
+ for j , in_arg in enumerate (instruction .in_args ):
101
+ current_variable_depth_in [in_arg ] = 0 , i , j
103
102
104
103
variable_depth_out [node ] = current_variable_depth_out
105
104
variable_depth_in [node ] = current_variable_depth_in
106
105
107
- return variable_depth_out
106
+ return variable_depth_in
108
107
109
108
110
109
def compute_block_level (dominance_tree : nx .DiGraph , start : str ) -> Dict [str , int ]:
@@ -161,7 +160,7 @@ def output_stack_layout(input_stack: List[str], final_stack_elements: List[str],
161
160
vars_to_place = live_vars .difference (set (final_stack_elements + bottom_output_stack ))
162
161
163
162
# Sort the vars to place according to the variable depth info order in reversed order
164
- vars_to_place_sorted = sorted (vars_to_place , key = lambda x : (* variable_depth_info [x ], x ), reverse = True )
163
+ vars_to_place_sorted = sorted (vars_to_place , key = lambda x : (variable_depth_info [x ], x ), reverse = True )
165
164
166
165
# Try to place the variables in reversed order
167
166
i , j = len (bottom_output_stack ) - 1 , 0
0 commit comments