[phc-internals] [phc commit] r1411 - branches/saturn/src/analyse
codesite-noreply at google.com
codesite-noreply at google.com
Wed Jul 2 16:23:41 IST 2008
Author: paul.biggar
Date: Wed Jul 2 08:23:05 2008
New Revision: 1411
Modified:
branches/saturn/src/analyse/address_taken.clp
branches/saturn/src/analyse/do_optimize.clp
branches/saturn/src/analyse/live.clp
Log:
Include the address-taken aliasing in the liveness, and fix all
compiler errors. Its not yet tested.
Modified: branches/saturn/src/analyse/address_taken.clp
==============================================================================
--- branches/saturn/src/analyse/address_taken.clp (original)
+++ branches/saturn/src/analyse/address_taken.clp Wed Jul 2 08:23:05 2008
@@ -4,27 +4,34 @@
% ignored for scalar optimizations.
-type alias = alias_var {string}
+type alias ::= alias_var {string}
| alias_bottom.
-predicate is_alias (VAR_NAME:string) succeeds [zero,once].
+% Does VAR_NAME alias another variable
+predicate is_alias (in VAR_NAME:string) succeeds [zero,once].
+
is_alias (_) :- in_alias_set (alias_bottom).
is_alias (VAR_NAME) :- in_alias_set (alias_var{VAR_NAME}).
+% Encode aliases
+predicate in_alias_set (in ALIAS:alias).
+
+
+% Error handling
predicate alias_handled (BB:t_cfg_node).
% No aliases
alias_handled (BB) :- cfg_node (BB),
( BB = nentry{_}
- ; BB = nexit{_},
+ ; BB = nexit{_}
; BB = nbranch{_,_,_}
- ; BB = nblock{statement_Assign_var {assign_var {_, _, false, _}}},
- ; BB = nblock{statement_Assign_array {assign_array {_, _, _, false, _}}}
- ; BB = nblock{statement_Push_array {push_array {_, _, _, false, _}}}
- ; BB = nblock{statement_Pre_op {pre_op {_, _, _}}}
+ ; BB = nblock {statement_Assign_var {assign_var {_, _, false, _}}}
+ ; BB = nblock {statement_Assign_array {assign_array {_, _, _, false, _}}}
+ ; BB = nblock {statement_Push_array {push_array {_, _, false, _}}}
+ ; BB = nblock {statement_Pre_op {pre_op {_, _, _}}}
; BB = nblock {statement_Foreach_reset{foreach_reset{_, _, _}}}
; BB = nblock {statement_Foreach_end{foreach_end{_, _, _}}}
- ; BB = nblock {statement_Foreach_next{foreach_next{_, _, _}}}
+ ; BB = nblock {statement_Foreach_next{foreach_next{_, _, _}}}).
predicate aliased (t_VARIABLE_NAME).
@@ -60,14 +67,14 @@
% Globals (VARIABLE_NAME) - Any global must be aliased
cfg_node (BB), BB = nblock{statement_Global {
- global {_, variable_name_VARIABLE_NAME{VAR}}}},
- +alias_expr (BB, VAR), +alias_handled (BB).
+ global {_, variable_name_VARIABLE_NAME{VAR_NAME}}}},
+ +aliased (VAR_NAME), +alias_handled (BB).
% Globals (REFLECTION) - Everything is aliased
% cannot say any variable is defined. So nothing happens.
cfg_node (BB), BB = nblock{statement_Global {
global {_, variable_name_Reflection {_}}}},
- +aliased (BB, alias_bottom),
+ +in_alias_set (alias_bottom),
+alias_handled (BB).
@@ -79,6 +86,7 @@
% No aliases
alias_handled (BB) :- alias_expr (BB, EXPR),
+ (
% Not allowed in MIR:
% literal,
% cast,
@@ -86,21 +94,22 @@
% bin_op,
% constants
% Index_array: $x =& $y[$z] or return $y[$z] - Nothing is aliased here
- EXPR = expr_Index_array {index_array{_, _, _}}),
- EXPR = expr_Foreach_has_key{foreach_has_key{_, ARRAY, _}}
- EXPR = expr_Foreach_get_key{foreach_get_key{_, ARRAY, _}}
- EXPR = expr_Foreach_get_val{foreach_get_val{_, ARRAY, _, _}}
- EXPR = expr_Target_expr {target_expr{_, _, _}}
+ EXPR = expr_Index_array {index_array{_, _, _}}
+ ; EXPR = expr_Foreach_has_key{foreach_has_key{_, _, _}}
+ ; EXPR = expr_Foreach_get_key{foreach_get_key{_, _, _}}
+ ; EXPR = expr_Foreach_get_val{foreach_get_val{_, _, _, _}}
+ ; EXPR = expr_Target_expr {target_expr{_, _, _}}
+ ).
% Variable: $x =& $y; $y is aliased.
alias_expr (BB, expr_Variable{variable{_, VAR_NAME}}),
- +aliased (BB, VAR_NAME),
+ +aliased (VAR_NAME),
+alias_handled (BB).
% Variable_variable: $x =& $$y - Everything is aliased.
alias_expr (BB, expr_Variable_variable {variable_variable{_, _}}),
- +alised (BB, alias_bottom),
+ +in_alias_set (alias_bottom),
+alias_handled (BB).
% Method invocation - all parameters can be aliased
@@ -116,40 +125,21 @@
% No target, empty list, VARIABLE_NAME
alias_actual_params (BB, [PARAM|TAIL]),
- PARAM = actual_parameter {_, no, _,
variable_name_VARIABLE_NAME{VAR_NAME}, []},
- +aliased_var (BB, VAR),
+ PARAM = actual_parameter {_, _, no,
variable_name_VARIABLE_NAME{VAR_NAME}, []},
+ +aliased (VAR_NAME),
+alias_actual_params (BB, TAIL).
% No target, empty list, Reflection
alias_actual_params (BB, [PARAM|TAIL]),
- PARAM = actual_parameter {_, no, _, variable_name_Reflection {_}, []},
- +aliased (BB, alias_bottom),
+ PARAM = actual_parameter {_, _, no, variable_name_Reflection {_}, []},
+ +in_alias_set (alias_bottom),
+alias_actual_params (BB, TAIL).
% Everything else - No aliases
alias_actual_params (BB, [PARAM|TAIL]),
PARAM = actual_parameter {_, _, _, _, _},
- +aliased_var (BB, VAR),
+alias_actual_params (BB, TAIL).
% All params must be handled to get this far
alias_actual_params (BB, []),
+alias_handled (BB).
-
-
-
-
-% Make sure all rules are alias_handled
-predicate alias_handled (BB:t_cfg_node).
-predicate error (BB:t_cfg_node).
-error (BB) :-
- cfg_node (BB),
- ~alias_handled (BB),
- tostring (BB, BB_STR),
- ((BB = nblock {B}, to_node (any{B}, NODE), mir()->source_rep (get_id
(NODE), SOURCE))
- ;
- (BB \= nblock{_}, SOURCE = "SOURCE NOT AVAILABLE")),
- str_cat_list (["Error, not alias_handled: ", BB_STR, " - ", SOURCE], ERROR),
- +print (ERROR).
-
-assert ~error (_).
Modified: branches/saturn/src/analyse/do_optimize.clp
==============================================================================
--- branches/saturn/src/analyse/do_optimize.clp (original)
+++ branches/saturn/src/analyse/do_optimize.clp Wed Jul 2 08:23:05 2008
@@ -4,7 +4,10 @@
analyze session_name("cfg").
% Perform Dead-code elimination.
+import "address_taken.clp".
import "dce.clp".
+
+import "errors.clp".
% After optimizations, iterate, generating a new version of the CFG,
until it converges.
import "do_versioning.clp".
Modified: branches/saturn/src/analyse/live.clp
==============================================================================
--- branches/saturn/src/analyse/live.clp (original)
+++ branches/saturn/src/analyse/live.clp Wed Jul 2 08:23:05 2008
@@ -68,11 +68,11 @@
% Extensional rules (from the predicates).
% Entry and exit - nothing to do here
-handled (BB) :- cfg_node (BB), (BB = nentry{_} ; BB = nexit{_}).
+live_handled (BB) :- cfg_node (BB), (BB = nentry{_} ; BB = nexit{_}).
% Branches - the var is used
cfg_node (BB), BB = nbranch{VAR, _, _},
- +used_var (BB, VAR), +handled (BB).
+ +used_var (BB, VAR), +live_handled (BB).
% Assign_vars - the LHS is defined. The RHS needs to be checked. IS_REF
% doesnt matter: if it is true, then we conservatively miss some definitions,
@@ -87,13 +87,13 @@
cfg_node (BB), BB = nblock{statement_Assign_array {
assign_array {_, LHS, INDEX, _, RHS}}},
+used_var (BB, LHS), +used_var (BB, INDEX), +used_var (BB, RHS),
- +handled (BB).
+ +live_handled (BB).
cfg_node (BB), BB = nblock{statement_Push_array {
push_array {_, ARRAY, _, RHS}}},
+used_var (BB, ARRAY),
+used_var (BB, RHS),
- +handled (BB).
+ +live_handled (BB).
% Eval_expr - Rewrap it, and treat like a normal expr
cfg_node (BB), BB = nblock{statement_Eval_expr{
@@ -108,14 +108,14 @@
% Globals - the overwrite the variables, so consider it a define
cfg_node (BB), BB = nblock{statement_Global {
global {_, variable_name_VARIABLE_NAME{VAR}}}},
- +defined_var (BB, VAR), +handled (BB).
+ +defined_var (BB, VAR), +live_handled (BB).
% globals with reflection - they may-define every variable, which
means we
% cannot say any variable is defined. So nothing happens.
cfg_node (BB), BB = nblock{statement_Global {
global {_, variable_name_Reflection {_}}}},
- +handled (BB).
+ +live_handled (BB).
% Pre_op - the variable is both used and defined
cfg_node (BB), BB = nblock{statement_Pre_op {
@@ -123,20 +123,20 @@
% TODO If VAR is simple, it may be defined here, in which case we can
% remove the definition if VAR is not live on exit, which is not reflected
% here. Add +defined (VAR).
- +used_var (BB, VAR), +handled (BB).
+ +used_var (BB, VAR), +live_handled (BB).
% Foreach statements
cfg_node (BB), BB = nblock {statement_Foreach_reset{foreach_reset{_,
VAR_NAME, _}}},
+used_var (BB, VAR_NAME),
- +handled (BB).
+ +live_handled (BB).
cfg_node (BB), BB = nblock {statement_Foreach_end{foreach_end{_,
VAR_NAME, _}}},
+used_var (BB, VAR_NAME),
- +handled (BB).
+ +live_handled (BB).
cfg_node (BB), BB = nblock {statement_Foreach_next{foreach_next{_,
VAR_NAME, _}}},
+used_var (BB, VAR_NAME),
- +handled (BB).
+ +live_handled (BB).
@@ -147,24 +147,24 @@
predicate use_expr (BB:t_cfg_node, EXPR:t_Expr).
% Literals
-use_expr (BB, expr_INT{_}), +handled (BB).
-use_expr (BB, expr_STRING{_}), +handled (BB).
-use_expr (BB, expr_BOOL{_}), +handled (BB).
-use_expr (BB, expr_REAL{_}), +handled (BB).
+use_expr (BB, expr_INT{_}), +live_handled (BB).
+use_expr (BB, expr_STRING{_}), +live_handled (BB).
+use_expr (BB, expr_BOOL{_}), +live_handled (BB).
+use_expr (BB, expr_REAL{_}), +live_handled (BB).
% Variables
use_expr (BB, expr_Variable{variable{_, VAR_NAME}}),
+used_var (BB, VAR_NAME),
- +handled (BB).
+ +live_handled (BB).
use_expr (BB, expr_Index_array {index_array{_, ARRAY_NAME, INDEX_NAME}}),
+used_var (BB, INDEX_NAME),
+used_var (BB, ARRAY_NAME),
- +handled (BB).
+ +live_handled (BB).
use_expr (BB, expr_Variable_variable {variable_variable{_, _}}),
+used (BB, lv_bottom),
- +handled (BB).
+ +live_handled (BB).
% Target_expr
use_expr (BB, expr_Target_expr {target_expr{_, TARGET, VARIABLE_NAME}}),
@@ -186,39 +186,39 @@
VARIABLE_NAME = variable_name_VARIABLE_NAME {VAR_NAME},
+used_var (BB, VAR_NAME)
)),
- +handled (BB).
+ +live_handled (BB).
% Cast_op
use_expr (BB, expr_Cast {cast {_, _, VAR}}),
+used_var (BB, VAR),
- +handled (BB).
+ +live_handled (BB).
% Unary_op
use_expr (BB, expr_Unary_op {unary_op {_, _, VAR}}),
+used_var (BB, VAR),
- +handled (BB).
+ +live_handled (BB).
% Bin_op
use_expr (BB, expr_Bin_op {bin_op {_, LEFT, _, RIGHT}}),
+used_var (BB, LEFT),
+used_var (BB, RIGHT),
- +handled (BB).
+ +live_handled (BB).
% Constant
use_expr (BB, expr_Constant {_}), % no used vars
- +handled (BB).
+ +live_handled (BB).
% Foreach
use_expr (BB, expr_Foreach_has_key{foreach_has_key{_, ARRAY, _}}),
- +used_var (BB, ARRAY), +handled (BB).
+ +used_var (BB, ARRAY), +live_handled (BB).
use_expr (BB, expr_Foreach_get_key{foreach_get_key{_, ARRAY, _}}),
- +used_var (BB, ARRAY), +handled (BB).
+ +used_var (BB, ARRAY), +live_handled (BB).
% Ignore key.
use_expr (BB, expr_Foreach_get_val{foreach_get_val{_, ARRAY, _, _}}),
- +used_var (BB, ARRAY), +handled (BB).
+ +used_var (BB, ARRAY), +live_handled (BB).
% Method invocation
@@ -236,7 +236,7 @@
% TODO unsafe, this will succeed if one parameter succeeds, whereas it
should fail if any of them fail.
use_actual_params (BB, []),
- +handled (BB).
+ +live_handled (BB).
% VARIABLE_NAMEs
predicate use_variable_names (BB:t_cfg_node, list[t_VARIABLE_NAME]).
@@ -257,17 +257,6 @@
-% Make sure all rules are handled
-predicate handled (BB:t_cfg_node).
-predicate error (BB:t_cfg_node).
-error (BB) :-
- cfg_node (BB),
- ~handled (BB),
- tostring (BB, BB_STR),
- ((BB = nblock {B}, to_node (any{B}, NODE), mir()->source_rep (get_id
(NODE), SOURCE))
- ;
- (BB \= nblock{_}, SOURCE = "SOURCE NOT AVAILABLE")),
- str_cat_list (["Error, not handled: ", BB_STR, " - ", SOURCE], ERROR),
- +print (ERROR).
+% Error checking
+predicate live_handled (BB:t_cfg_node).
-assert ~error (_).
More information about the phc-internals
mailing list