aboutsummaryrefslogtreecommitdiffstats
path: root/backend/LICMaux.ml
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-04-19 17:26:05 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-04-19 17:26:05 +0200
commit9c97918742e00798bad8c7862de92831bb62a69e (patch)
treeef0bf3861369f8515d6b7eb85373ce02ad8c1953 /backend/LICMaux.ml
parent300e51261c090e6a66bd0e0004bb530b64caf6e9 (diff)
downloadcompcert-kvx-9c97918742e00798bad8c7862de92831bb62a69e.tar.gz
compcert-kvx-9c97918742e00798bad8c7862de92831bb62a69e.zip
try building injection lists
Diffstat (limited to 'backend/LICMaux.ml')
-rw-r--r--backend/LICMaux.ml52
1 files changed, 52 insertions, 0 deletions
diff --git a/backend/LICMaux.ml b/backend/LICMaux.ml
index 39e336eb..5028869f 100644
--- a/backend/LICMaux.ml
+++ b/backend/LICMaux.ml
@@ -3,6 +3,7 @@ open Camlcoq;;
open Maps;;
open Kildall;;
open HashedSet;;
+open Inject;;
type reg = P.t;;
@@ -107,6 +108,57 @@ let inner_loops (f : coq_function) : PSet.t PTree.t =
and predecessors = Kildall.make_predecessors f.fn_code RTL.successors_instr in
PTree.map (filter_dominated_part predecessors) parts;;
+let map_reg mapper r =
+ match PTree.get r mapper with
+ | None -> r
+ | Some x -> x;;
+
+let rewrite_loop_body (last_alloc : reg ref)
+ (insns : RTL.code) (header : P.t) (loop_body : PSet.t) =
+ let seen = ref PSet.empty
+ and stack = Stack.create ()
+ and rewritten = ref [] in
+ let add_inj ii = rewritten := ii::!rewritten in
+ Stack.push (header, PTree.empty) stack;
+ while not (Stack.is_empty stack)
+ do
+ let (pc, mapper) = Stack.pop stack in
+ if not (PSet.contains !seen pc)
+ then
+ begin
+ seen := PSet.add pc !seen;
+ match PTree.get pc insns with
+ | None -> ()
+ | Some ii ->
+ let mapper' =
+ match ii with
+ | Iop(op, args, res, pc') ->
+ let new_res = P.succ !last_alloc in
+ last_alloc := new_res;
+ add_inj (INJop(op,
+ (List.map (map_reg mapper) args),
+ new_res));
+ PTree.set res new_res mapper
+ | Iload(trap, chunk, addr, args, res, pc') ->
+ let new_res = P.succ !last_alloc in
+ last_alloc := new_res;
+ add_inj (INJload(chunk, addr,
+ (List.map (map_reg mapper) args),
+ new_res));
+ PTree.set res new_res mapper
+ | _ -> mapper in
+ List.iter (fun x -> Stack.push (x, mapper') stack)
+ (successors_instr ii)
+ end
+ done;
+ List.rev !rewritten;;
+
+(*
+| INJnop
+| INJop of operation * reg list * reg
+| INJload of memory_chunk * addressing * reg list * reg
+ *)
+
let pp_list pp_item oc l =
output_string oc "{ ";
let first = ref true in