Skip to content
Snippets Groups Projects
Commit 0f7b31bd authored by THIRIOUX Xavier's avatar THIRIOUX Xavier
Browse files

restored correct inlining for constants and locals

parent c7504a35
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,10 @@ module ExprDep = struct
program/schedule, but used to simplify causality analysis *)
let mk_instance_var eq f =
incr instance_var_cpt;
Format.sprintf "%s_%d_%d" f (fst eq.eq_loc).Lexing.pos_lnum !instance_var_cpt
let loc = fst eq.eq_loc in
let lin = loc.Lexing.pos_lnum in
let col = loc.Lexing.pos_cnum - loc.Lexing.pos_bol in
Format.sprintf "%s_%d_%d_%d" f lin col !instance_var_cpt
let mk_call_instance_var id =
Format.sprintf "?%s" id
......
......@@ -147,6 +147,7 @@ let is_aliasable_input node var =
(* replace variable [v] by [v'] in graph [g]. [v'] is a dead variable *)
let replace_in_dep_graph v v' g =
assert (IdentDepGraph.mem_vertex g v);
IdentDepGraph.add_vertex g v';
IdentDepGraph.iter_succ (fun s -> IdentDepGraph.add_edge g v' s) g v;
IdentDepGraph.iter_pred (fun p -> IdentDepGraph.add_edge g p v') g v;
......
......@@ -1457,6 +1457,7 @@ let optimize params prog node_schs machine_code =
machine_code)
else machine_code
in
let consts = Corelang.get_consts prog in
(* Optimize machine code *)
let prog, machine_code, removed_table =
if
......@@ -1469,7 +1470,7 @@ let optimize params prog node_schs machine_code =
"@ @[<v 2>.. machines optimization: const. inlining (partial eval. \
with const)@ ");
let machine_code, removed_table =
machines_unfold (Corelang.get_consts prog) node_schs machine_code
machines_unfold consts node_schs machine_code
in
Log.report ~level:3 (fun fmt ->
Format.fprintf
......@@ -1512,7 +1513,7 @@ let optimize params prog node_schs machine_code =
let machine_code =
if !Options.optimization >= 3 && not (Backends.is_functional ()) then
let node_schs =
Scheduling.remove_prog_inlined_locals removed_table node_schs
Scheduling.remove_prog_inlined_consts_and_locals consts removed_table node_schs
in
let reuse_tables = Scheduling.compute_prog_reuse_table node_schs in
machine_code
......
......@@ -161,8 +161,8 @@ let compute_prog_reuse_table report = IMap.map compute_node_reuse_table report
(* removes inlined local variables from schedule report, which are now
useless *)
let remove_node_inlined_locals locals report =
let is_inlined v = IMap.exists (fun l _ -> v = l) locals in
let remove_node_inlined_consts_and_locals consts consts_and_locals report =
let is_inlined v = IMap.mem v consts_and_locals in
let schedule' =
List.fold_right
(fun heads q ->
......@@ -171,16 +171,22 @@ let remove_node_inlined_locals locals report =
report.schedule
[]
in
IMap.iter (fun v _ -> Hashtbl.remove report.fanin_table v) locals;
IMap.iter (fun v _ -> Hashtbl.remove report.fanin_table v) consts_and_locals;
IMap.iter
(fun v _ ->
let iv = ExprDep.(mk_call_instance_var (mk_call_instance_var v)) in
Liveness.replace_in_dep_graph v iv report.dep_graph)
locals;
if List.exists (fun decl -> Corelang.(const_of_top decl).const_id = v)
consts
then
let iv = ExprDep.(mk_read_var v) in
IdentDepGraph.remove_vertex report.dep_graph iv
else
let iv = ExprDep.(mk_call_instance_var (mk_call_instance_var v)) in
Liveness.replace_in_dep_graph v iv report.dep_graph)
consts_and_locals;
{ report with schedule = schedule' }
let remove_prog_inlined_locals removed reuse =
IMap.mapi (fun id -> remove_node_inlined_locals (IMap.find id removed)) reuse
let remove_prog_inlined_consts_and_locals consts removed reuse =
IMap.mapi (fun id -> remove_node_inlined_consts_and_locals consts (IMap.find id removed)) reuse
let pp_eq_schedule fmt vl =
match vl with
......
......@@ -6,8 +6,8 @@ open Scheduling_type
val schedule_node : node_desc -> schedule_report
val schedule_prog : program_t -> program_t * schedule_report IMap.t
val remove_prog_inlined_locals :
'a IMap.t IMap.t -> schedule_report IMap.t -> schedule_report IMap.t
val remove_prog_inlined_consts_and_locals :
top_decl list -> 'a IMap.t IMap.t -> schedule_report IMap.t -> schedule_report IMap.t
val compute_prog_reuse_table :
schedule_report IMap.t -> (ident, var_decl) Hashtbl.t IMap.t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment