summaryrefslogtreecommitdiff
path: root/backend/Unusedglob.ml
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-11-12 13:42:22 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-11-12 13:42:22 +0000
commitce4951549999f403446415c135ad1403a16a15c3 (patch)
treecac9bbb2fea29fce331916b277c38ed8fe29e471 /backend/Unusedglob.ml
parentdcb9f48f51cec5e864565862a700c27df2a1a7e6 (diff)
Globalenvs: allocate one-byte block with permissions Nonempty for each
function definition, so that comparisons between function pointers are correctly defined. AST, Globalenvs, and many other files: represent programs as a list of (function or variable) definitions instead of two lists, one for functions and the other for variables. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2067 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'backend/Unusedglob.ml')
-rw-r--r--backend/Unusedglob.ml25
1 files changed, 12 insertions, 13 deletions
diff --git a/backend/Unusedglob.ml b/backend/Unusedglob.ml
index 4139678..1a88ee9 100644
--- a/backend/Unusedglob.ml
+++ b/backend/Unusedglob.ml
@@ -28,10 +28,6 @@ let add_referenced_instr rf i =
let referenced_function f =
List.fold_left add_referenced_instr IdentSet.empty (code_of_function f)
-let referenced_fundef = function
- | Internal f -> referenced_function f
- | External ef -> IdentSet.empty
-
(* The set of globals referenced from a variable definition (initialization) *)
let add_referenced_init_data rf = function
@@ -43,10 +39,15 @@ let referenced_globvar gv =
(* The map global |-> set of globals it references *)
+let referenced_globdef gd =
+ match gd with
+ | Gfun(Internal f) -> referenced_function f
+ | Gfun(External ef) -> IdentSet.empty
+ | Gvar gv -> referenced_globvar gv
+
let use_map p =
- List.fold_left (fun m (id, gv) -> PTree.set id (referenced_globvar gv) m)
- (List.fold_left (fun m (id, fd) -> PTree.set id (referenced_fundef fd) m)
- PTree.empty p.prog_funct) p.prog_vars
+ List.fold_left (fun m (id, gd) -> PTree.set id (referenced_globdef gd) m)
+ PTree.empty p.prog_defs
(* Worklist algorithm computing the set of used globals *)
@@ -66,9 +67,8 @@ let add_nonstatic wrk id =
if C2C.atom_is_static id then wrk else id :: wrk
let initial_worklist p =
- List.fold_left (fun wrk (id, gv) -> add_nonstatic wrk id)
- (List.fold_left (fun wrk (id, fd) -> add_nonstatic wrk id)
- [] p.prog_funct) p.prog_vars
+ List.fold_left (fun wrk (id, gd) -> add_nonstatic wrk id)
+ [] p.prog_defs
(* Eliminate unused definitions *)
@@ -80,9 +80,8 @@ let rec filter used = function
else filter used rem
let filter_prog used p =
- { prog_funct = filter used p.prog_funct;
- prog_main = p.prog_main;
- prog_vars = filter used p.prog_vars }
+ { prog_defs = filter used p.prog_defs;
+ prog_main = p.prog_main }
(* Entry point *)