[phc-internals] [phc commit] r1413 - branches/saturn/src/analyse
codesite-noreply at google.com
codesite-noreply at google.com
Thu Jul 3 15:06:22 IST 2008
Author: paul.biggar
Date: Thu Jul 3 07:05:45 2008
New Revision: 1413
Modified:
branches/saturn/src/analyse/address_taken.clp
branches/saturn/src/analyse/cfg.clp
branches/saturn/src/analyse/do_cfg.clp
branches/saturn/src/analyse/errors.clp
branches/saturn/src/analyse/linearize_cfg.clp
branches/saturn/src/analyse/live.clp
Log:
There were infinite loops for branches that linked back on themselves.
We couldn't actually represent them in the existing CFG. This adds a
nempty{_} to represent statements that do nothing in the CFG (gotos and
labels). When the CFG is being linearized, these are removed. However,
they are kept around in the CFG, which makes it quite a bit larger than
it might otherwise be.
There are only about 75 skips/timeouts after this (down from about 150).
Modified: branches/saturn/src/analyse/address_taken.clp
==============================================================================
--- branches/saturn/src/analyse/address_taken.clp (original)
+++ branches/saturn/src/analyse/address_taken.clp Thu Jul 3 07:05:45 2008
@@ -24,6 +24,7 @@
alias_handled (BB) :- cfg_node (BB),
( BB = nentry{_}
; BB = nexit{_}
+ ; BB = nempty{_}
; BB = nbranch{_,_,_}
; BB = nblock {statement_Assign_var {assign_var {_, _, false, _}}}
; BB = nblock {statement_Assign_array {assign_array {_, _, _, false, _}}}
Modified: branches/saturn/src/analyse/cfg.clp
==============================================================================
--- branches/saturn/src/analyse/cfg.clp (original)
+++ branches/saturn/src/analyse/cfg.clp Thu Jul 3 07:05:45 2008
@@ -6,11 +6,15 @@
% Phase 2: Build the CFG
type t_cfg_node ::=
- nentry{t_Method} % function entry
-| nexit{t_Method} % function exit
-| nblock{t_Statement} % basic block (BBs only have 1 statement in them)
- % branch (branches on the condition in t_VARIABLE_NAME)
-| nbranch{t_VARIABLE_NAME, TRUE:t_cfg_node, FALSE:t_cfg_node}
+ nentry{t_Method} % function entry
+| nexit{t_Method} % function exit
+| nblock{t_Statement} % basic block (BBs only have 1 statement in
+ % them)
+| nbranch{ VARIABLE_NAME:t_VARIABLE_NAME, % branch on VARIABLE_NAME
+ TRUE:t_cfg_node,
+ FALSE:t_cfg_node}
+
+| nempty{t_Statement} % We replace labels and gotos with empty blocks
.
predicate cfg_edge (N0:t_cfg_node, N1:t_cfg_node) order[N0, N1].
Modified: branches/saturn/src/analyse/do_cfg.clp
==============================================================================
--- branches/saturn/src/analyse/do_cfg.clp (original)
+++ branches/saturn/src/analyse/do_cfg.clp Thu Jul 3 07:05:45 2008
@@ -103,20 +103,24 @@
pp_edge (p_s{S}, P1), % get next pp
+dfs (N1, P1, no, METHOD_NAME).
-% Label - dont create a node or an edge, just follow the path
+% Label - create an empty statement and follow the path
dfs (N, p_s{S}, IS_TARGET, METHOD_NAME),
S = statement_Label{_},
+ N1 = nempty{S},
+ +method_edge (N, N1, IS_TARGET, METHOD_NAME),
% recurse
pp_edge (p_s{S}, P1), % get next pp
- +dfs (N, P1, IS_TARGET, METHOD_NAME).
+ +dfs (N1, P1, IS_TARGET, METHOD_NAME).
-% Goto - dont create a node or an edge, just follow the path
-dfs (N, p_s{statement_Goto{G}}, IS_TARGET, METHOD_NAME),
- G = goto {_, lABEL_NAME{_, LABEL_NAME}},
+% Goto - create and empty statement and follow the path
+dfs (N, p_s{S}, IS_TARGET, METHOD_NAME),
+ S = statement_Goto {goto {_, lABEL_NAME{_, LABEL_NAME}}},
+ N1 = nempty{S},
+ +method_edge (N, N1, IS_TARGET, METHOD_NAME),
% find target and recurse
% find the names of the labels for the branch targets
find_target (LABEL_NAME, PP),
- +dfs (N, PP, IS_TARGET, METHOD_NAME).
+ +dfs (N1, PP, IS_TARGET, METHOD_NAME).
% Branch - create a fake node, which will be fixed up later, and
follow both
Modified: branches/saturn/src/analyse/errors.clp
==============================================================================
--- branches/saturn/src/analyse/errors.clp (original)
+++ branches/saturn/src/analyse/errors.clp Thu Jul 3 07:05:45 2008
@@ -2,24 +2,24 @@
% Error handling
-predicate error_in (BB:t_cfg_node).
-error_in (BB) :-
+predicate error_in (BB:t_cfg_node, NAME:string).
+error_in (BB, NAME) :-
cfg_node (BB),
(
- ~live_handled (BB)
- ; ~alias_handled (BB)
+ ~live_handled (BB), NAME = "LIVE"
+ ; ~alias_handled (BB), NAME = "ALIAS"
).
% This is done in separate predicates so that the error will print
before the
% assertion executes.
predicate error (BB:t_cfg_node).
error (BB) :-
- error_in (BB),
+ error_in (BB, NAME),
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),
+ str_cat_list (["Error, not handled (", NAME, "): ", BB_STR, " - ",
SOURCE], ERROR),
+print (ERROR).
assert ~error (_).
Modified: branches/saturn/src/analyse/linearize_cfg.clp
==============================================================================
--- branches/saturn/src/analyse/linearize_cfg.clp (original)
+++ branches/saturn/src/analyse/linearize_cfg.clp Thu Jul 3 07:05:45 2008
@@ -30,10 +30,14 @@
predicate ordered_statements (STATEMENTS:list[t_Statement]).
-% Base case
-order_nodes (_, STATEMENTS, []), +ordered_statements (STATEMENTS).
+% No more statements to analyse
+order_nodes (_, STATEMENTS, []),
+ % Add the final label for the exit node
+ cfg_node (BB), BB = nexit{_},
+ list_append (STATEMENTS, [bb_label(BB)], ALL_STATEMENTS),
+ +ordered_statements (ALL_STATEMENTS).
-% Seen this before
+% Seen this statement before
order_nodes (PREV, STATEMENTS, [BB|TAIL]),
list_mem (PREV, BB),
+order_nodes (PREV, STATEMENTS, TAIL).
@@ -60,18 +64,20 @@
cfg_node (BB),
BB = nblock{S}, cfg_edge (BB, NEXT),
- LABEL = bb_label (BB),
- GOTO = bb_goto (NEXT),
- STATEMENTS = [LABEL, S, GOTO],
- +linear_statements (BB, STATEMENTS).
+ +linear_statements (BB, [bb_label (BB), S, bb_goto (NEXT)]).
cfg_node (BB),
BB = nentry{_}, cfg_edge (BB, NEXT),
+linear_statements (BB, [bb_goto (NEXT)]).
+% This must be the last statement, but with DFS, it might not be. Add
it later.
cfg_node (BB),
BB = nexit{_},
- +linear_statements (BB, [bb_label (BB)]).
+ +linear_statements (BB, []).
+
+cfg_node (BB),
+ BB = nempty{_}, cfg_edge (BB, NEXT),
+ +linear_statements (BB, [bb_label (BB), bb_goto (NEXT)]).
Modified: branches/saturn/src/analyse/live.clp
==============================================================================
--- branches/saturn/src/analyse/live.clp (original)
+++ branches/saturn/src/analyse/live.clp Thu Jul 3 07:05:45 2008
@@ -68,7 +68,7 @@
% Extensional rules (from the predicates).
% Entry and exit - nothing to do here
-live_handled (BB) :- cfg_node (BB), (BB = nentry{_} ; BB = nexit{_}).
+live_handled (BB) :- cfg_node (BB), (BB = nentry{_} ; BB = nexit{_} ;
BB = nempty{_}).
% Branches - the var is used
cfg_node (BB), BB = nbranch{VAR, _, _},
More information about the phc-internals
mailing list