Project

General

Profile

« Previous | Next » 

Revision 13507742

Added by Pierre-Loïc Garoche about 6 years ago

Refactored some code: optimization of machine

View differences:

src/main_lustre_compiler.ml
262 262
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. generated machines (unoptimized):@ %a@ "Machine_code.pp_machines machine_code);
263 263

  
264 264
  (* Optimize machine code *)
265
  let machine_code =
266
    if !Options.optimization >= 4 (* && !Options.output <> "horn" *) then
267
      begin
268
	Log.report ~level:1 
269
	  (fun fmt -> fprintf fmt ".. machines optimization: sub-expression elimination@,");
270
	let machine_code = Optimize_machine.machines_cse machine_code in
271
	Log.report ~level:3 (fun fmt -> fprintf fmt ".. generated machines (sub-expr elim):@ %a@ "Machine_code.pp_machines machine_code);
272
	machine_code
273
      end
274
    else
275
      machine_code
276
  in
277
  (* Optimize machine code *)
278
  let machine_code, removed_table = 
279
    if !Options.optimization >= 2 (*&& !Options.output <> "horn"*) then
280
      begin
281
	Log.report ~level:1 (fun fmt -> fprintf fmt 
282
	  ".. machines optimization: const. inlining (partial eval. with const)@,");
283
	let machine_code, removed_table = Optimize_machine.machines_unfold (Corelang.get_consts prog) node_schs machine_code in
284
	Log.report ~level:3 (fun fmt -> fprintf fmt "\t@[Eliminated constants: @[%a@]@]@ "
285
	  (pp_imap Optimize_machine.pp_elim) removed_table);
286
	Log.report ~level:3 (fun fmt -> fprintf fmt ".. generated machines (const inlining):@ %a@ "Machine_code.pp_machines machine_code);	
287
	machine_code, removed_table
288
      end
289
    else
290
      machine_code, IMap.empty
291
  in  
292
  (* Optimize machine code *)
293
  let machine_code =
294
    if !Options.optimization >= 3 && not (Corelang.functional_backend ()) then
295
      begin
296
	Log.report ~level:1 (fun fmt -> fprintf fmt ".. machines optimization: minimize stack usage by reusing variables@,");
297
	let node_schs    = Scheduling.remove_prog_inlined_locals removed_table node_schs in
298
	let reuse_tables = Scheduling.compute_prog_reuse_table node_schs in
299
	Optimize_machine.machines_fusion (Optimize_machine.machines_reuse_variables machine_code reuse_tables)
300
      end
301
    else
302
      machine_code
303
  in
304
  
305
  (* Salsa optimize machine code *)
306
  (*
307
  let machine_code = 
308
    if !Options.salsa_enabled then
309
      begin
310
	check_main ();
311
	Log.report ~level:1 (fun fmt -> fprintf fmt ".. salsa machines optimization: optimizing floating-point accuracy with Salsa@,");
312
	(* Selecting float constants for Salsa *)
313
	let constEnv = List.fold_left (
314
	  fun accu c_topdecl ->
315
	    match c_topdecl.top_decl_desc with
316
	    | Const c when Types.is_real_type c.const_type  ->
317
	      (c.const_id, c.const_value) :: accu
318
	    | _ -> accu
319
	) [] (Corelang.get_consts prog) 
320
	in
321
	List.map 
322
	  (Machine_salsa_opt.machine_t2machine_t_optimized_by_salsa constEnv) 
323
	  machine_code 
324
      end
325
    else
326
      machine_code
327
  in
328
  Log.report ~level:3 (fun fmt -> fprintf fmt "@[<v 2>@ %a@]@ "
329
    (Utils.fprintf_list ~sep:"@ " Machine_code.pp_machine)
330
    machine_code);
331
  *)
332
  machine_code
265
  Optimize_machine.optimize prog node_schs machine_code
333 266

  
334 267

  
335 268
(* printing code *)

Also available in: Unified diff