Bladeren bron

Assembly optimizations are now only executed when -noopt is not specified

Taddeus Kroes 12 jaren geleden
bovenliggende
commit
93fade30ba
6 gewijzigde bestanden met toevoegingen van 19 en 11 verwijderingen
  1. 1 1
      phases/assemble.ml
  2. 5 6
      phases/constant_propagation.ml
  3. 1 1
      phases/depth_analysis.ml
  4. 7 3
      phases/peephole.ml
  5. 3 0
      util.ml
  6. 2 0
      util.mli

+ 1 - 1
phases/assemble.ml

@@ -130,7 +130,7 @@ let assemble program =
          * for convenience: the indices in the constant table would be altered,
          * so entries cannot be removed. By this early detection (also during
          * index analysis), they are not added in the first place *)
-        | Const (value, _) when List.mem value immediate_consts ->
+        | Const (value, _) when is_immediate_const value ->
             [InlineComment (LoadImm value, node2str node)]
 
         | Const (value, _) ->

+ 5 - 6
phases/constant_propagation.ml

@@ -162,14 +162,13 @@ let rec prune_vardecs consts = function
     | VarDec (ctype, name, init, ann) when Hashtbl.mem consts name -> DummyNode
     | node -> transform_children (prune_vardecs consts) node
 
-let rec phase input =
-    log_line 1 "- Constant propagation";
-    match input with
-    | Ast node ->
-        if args.optimize then
+let phase = function
+    | Ast node as input ->
+        if args.optimize then (
+            log_line 1 "- Constant propagation";
             let consts = Hashtbl.create 32 in
             let node = propagate consts node in
             Ast (prune_vardecs consts node)
-        else
+        ) else
             input
     | _ -> raise (InvalidInput "constant propagation")

+ 1 - 1
phases/depth_analysis.ml

@@ -47,7 +47,7 @@ let tag_index program =
             nimport := !nimport + 1;
             annotate (LabelName name) (annotate (Index index) node)
 
-        | Const (value, _) when not (List.mem value immediate_consts) ->
+        | Const (value, _) when not (is_immediate_const value) ->
             let index = if Hashtbl.mem consts value then (
                 Hashtbl.find consts value
             ) else (

+ 7 - 3
phases/peephole.ml

@@ -54,8 +54,12 @@ let rec peephole = function
     | hd :: tl -> hd :: (peephole tl)
     | [] -> []
 
-let rec phase input =
-    log_line 1 "- Peephole optimization";
+let phase input =
     match input with
-    | Assembly instrs -> Assembly (peephole (strip_comments instrs))
+    | Assembly instrs ->
+        if args.optimize then (
+            log_line 1 "- Peephole optimization";
+            Assembly (peephole (strip_comments instrs))
+        ) else
+            input
     | _ -> raise (InvalidInput "peephole")

+ 3 - 0
util.ml

@@ -391,3 +391,6 @@ let mapi f lst =
         | [] -> []
         | hd :: tl -> f i hd :: (trav (i + 1) tl)
     in trav 0 lst
+
+let is_immediate_const const =
+    if args.optimize then List.mem const immediate_consts else false

+ 2 - 0
util.mli

@@ -62,3 +62,5 @@ val optmapl : ('a -> 'b) -> 'a list option -> 'b list
 
 (* List.mapi clone (only available in OCaml version >= 4.00 *)
 val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
+
+val is_immediate_const : Types.const -> bool