Initial snarf.
[shack.git] / arch / x86 / opt / x86_opt_util.ml
blobc08c14864423132e9a22b5ad9ab4e2f7c05f8c43
1 (*
2 Utilities for optimizations
3 Copyright (C) 2001 Justin David Smith, Caltech
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 open Flags
21 open Frame_type
22 open X86_inst_type
23 open X86_frame_type
24 open X86_frame
25 open X86_util
28 (*** Registers and Operands ***)
31 (* regs_in_operand
32 Identify registers _used_ in an operand. This for some reason
33 appears to not be consistent with src_regs; at any rate, we need
34 this computation for AGI. *)
35 let regs_in_operand = function
36 ImmediateNumber _
37 | ImmediateLabel _
38 | FPStack _ ->
40 | Register r
41 | FloatRegister r
42 | MMXRegister r
43 | MemReg r
44 | MemRegOff (r, _) ->
45 [r]
46 | MemRegRegOffMul (r1, r2, _, _) ->
47 [r1; r2]
48 | SpillRegister _ ->
49 [ebp]
52 (* reg_in_operand
53 Returns true if the register named appears in the operand *)
54 let reg_in_operand op r =
55 List.mem r (regs_in_operand op)
58 (* is_fpstack
59 Returns true if the operand indicated is an FPStack register *)
60 let is_fpstack = function
61 FPStack _ -> true
62 | _ -> false
65 (*** Liveness ***)
68 (* make_comment_string
69 Builds a comment that is placed immediately (before, after) the
70 instruction given (this is to ensure live-out and depth are ok. *)
71 let make_comment_string inst s =
72 { live_src = [];
73 live_dst = [];
74 live_out = inst.live_out;
75 live_class = CodeNormal;
76 live_depth = inst.live_depth;
77 live_inst = CommentString s;
81 (* make_comment_inst
82 Similar to above, but build a CommentInst instead. *)
83 let make_comment_inst inst s =
84 { live_src = [];
85 live_dst = [];
86 live_out = inst.live_out;
87 live_class = CodeNormal;
88 live_depth = inst.live_depth;
89 live_inst = CommentInst (s, inst.live_inst);
93 let () = std_flags_help_section_text "opt.x86"
94 "Optimizations specific to the X86 backend."