File: vn_type.m

package info (click to toggle)
mercury 0.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 18,488 kB
  • ctags: 9,800
  • sloc: objc: 146,680; ansic: 51,418; sh: 6,436; lisp: 1,567; cpp: 1,040; perl: 854; makefile: 450; asm: 232; awk: 203; exp: 32; fortran: 3; csh: 1
file content (210 lines) | stat: -rw-r--r-- 6,879 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
%-----------------------------------------------------------------------------%
% Copyright (C) 1995-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%

% vn_type.m - types for value numbering.

% Author: zs.

%-----------------------------------------------------------------------------%

:- module vn_type.

:- interface.
:- import_module llds, builtin_ops, livemap, options.
:- import_module getopt, map, set, list, std_util.

:- type vn == int.

:- type vnlval		--->	vn_reg(reg_type, int)
			;	vn_temp(reg_type, int)
			;	vn_stackvar(int)
			;	vn_framevar(int)
			;	vn_succip
			;	vn_maxfr
			;	vn_curfr
			;	vn_succfr(vn)
			;	vn_prevfr(vn)
			;	vn_redofr(vn)
			;	vn_redoip(vn)
			;	vn_succip(vn)
			;	vn_hp
			;	vn_sp
			;	vn_field(maybe(tag), vn, vn)
			;	vn_mem_ref(vn).

			% these lvals do not have vnlval parallels
			%	lvar(var)

:- type vnrval		--->	vn_origlval(vnlval)
			;	vn_mkword(tag, vn)
			;	vn_const(rval_const)
			;	vn_create(tag, list(maybe(rval)),
					create_arg_types, static_or_dynamic,
					int, string)
			;	vn_unop(unary_op, vn)
			;	vn_binop(binary_op, vn, vn)
			;	vn_stackvar_addr(int)
			;	vn_framevar_addr(int)
			;	vn_heap_addr(vn, int, int).

			% these rvals do not have vnrval parallels
			%	var(var)

	% given a vnlval, figure out its type
:- pred vn_type__vnlval_type(vnlval::in, llds_type::out) is det.

	% given a vnrval, figure out its type
:- pred vn_type__vnrval_type(vnrval::in, llds_type::out) is det.

:- type vn_src		--->	src_ctrl(int)
			;	src_liveval(vnlval)
			;	src_access(vnlval)
			;	src_vn(int).

:- type vn_node		--->	node_shared(vn)
			;	node_lval(vnlval)
			;	node_origlval(vnlval)
			;	node_ctrl(int).

:- type vn_instr	--->	vn_livevals(lvalset)
			;	vn_call(code_addr, code_addr, list(liveinfo),
					term__context, call_model)
			;	vn_mkframe(nondet_frame_info, code_addr)
			;	vn_label(label)
			;	vn_goto(code_addr)
			;	vn_computed_goto(vn, list(label))
			;	vn_if_val(vn, code_addr)
			;	vn_mark_hp(vnlval)
			;	vn_restore_hp(vn)
			;	vn_store_ticket(vnlval)
			;	vn_reset_ticket(vn, reset_trail_reason)
			;	vn_discard_ticket
			;	vn_mark_ticket_stack(vnlval)
			;	vn_discard_tickets_to(vn)
			;	vn_incr_sp(int, string)
			;	vn_decr_sp(int).

:- type parentry	==	pair(lval, list(rval)).
:- type parallel	--->	parallel(label, label, list(parentry)).

:- type vnlvalset	==	set(vnlval).

:- type ctrlmap		==	map(int, vn_instr).
:- type flushmap	==	map(int, flushmapentry).
:- type flushmapentry	==	map(vnlval, vn).
:- type parmap		==	map(int, list(parallel)).

:- type vn_ctrl_tuple	--->	tuple(int, ctrlmap, flushmap, int, parmap).

:- type vn_params.

:- pred vn_type__init_params(option_table(option), vn_params).
:- mode vn_type__init_params(in, out) is det.

:- pred vn_type__bytes_per_word(vn_params, int).
:- mode vn_type__bytes_per_word(in, out) is det.

:- pred vn_type__real_r_regs(vn_params, int).
:- mode vn_type__real_r_regs(in, out) is det.

:- pred vn_type__real_f_regs(vn_params, int).
:- mode vn_type__real_f_regs(in, out) is det.

:- pred vn_type__real_r_temps(vn_params, int).
:- mode vn_type__real_r_temps(in, out) is det.

:- pred vn_type__real_f_temps(vn_params, int).
:- mode vn_type__real_f_temps(in, out) is det.

:- pred vn_type__costof_assign(vn_params, int).
:- mode vn_type__costof_assign(in, out) is det.

:- pred vn_type__costof_intops(vn_params, int).
:- mode vn_type__costof_intops(in, out) is det.

:- pred vn_type__costof_stackref(vn_params, int).
:- mode vn_type__costof_stackref(in, out) is det.

:- pred vn_type__costof_heapref(vn_params, int).
:- mode vn_type__costof_heapref(in, out) is det.

:- implementation.

:- import_module int.

:- type vn_params	--->	vn_params(
					int,	% word size in bytes
						% needed for incr_hp; incr_hp
					int,	% number of real r regs
					int,	% number of real f regs
					int,	% number of real r temps
					int,	% number of real f temps
					int,	% cost of assign
					int,	% cost of int operation
					int,	% cost of stack reference
					int	% cost of heap reference
				).

vn_type__init_params(OptionTable, VnParams) :-
	getopt__lookup_int_option(OptionTable, num_real_r_regs, RealRRegs),
	getopt__lookup_int_option(OptionTable, num_real_f_regs, RealFRegs),
	getopt__lookup_int_option(OptionTable, num_real_r_temps, RealRTemps),
	getopt__lookup_int_option(OptionTable, num_real_f_temps, RealFTemps),
	getopt__lookup_int_option(OptionTable, bytes_per_word, WordBytes),
	VnParams = vn_params(WordBytes, RealRRegs, RealFRegs,
		RealRTemps, RealFTemps, 1, 1, 2, 2).

vn_type__bytes_per_word(vn_params(BytesPerWord, _, _, _, _, _, _, _, _),
	BytesPerWord).
vn_type__real_r_regs(vn_params(_, RealRRegs, _, _, _, _, _, _, _),
	RealRRegs).
vn_type__real_f_regs(vn_params(_, _, RealFRegs, _, _, _, _, _, _),
	RealFRegs).
vn_type__real_r_temps(vn_params(_, _, _, RealRTemps, _, _, _, _, _),
	RealRTemps).
vn_type__real_f_temps(vn_params(_, _, _, _, RealFTemps, _, _, _, _),
	RealFTemps).
vn_type__costof_assign(vn_params(_, _, _, _, _, AssignCost, _, _, _),
	AssignCost).
vn_type__costof_intops(vn_params(_, _, _, _, _, _, IntOpCost, _, _),
	IntOpCost).
vn_type__costof_stackref(vn_params(_, _, _, _, _, _, _, StackCost, _),
	StackCost).
vn_type__costof_heapref(vn_params(_, _, _, _, _, _, _, _, HeapCost),
	HeapCost).

vn_type__vnrval_type(vn_origlval(Lval), Type) :-
	vn_type__vnlval_type(Lval, Type).
vn_type__vnrval_type(vn_create(_, _, _, _, _, _), data_ptr).
vn_type__vnrval_type(vn_mkword(_, _), data_ptr). % see comment in llds.m
vn_type__vnrval_type(vn_const(Const), Type) :-
	llds__const_type(Const, Type).
vn_type__vnrval_type(vn_unop(UnOp, _), Type) :-
	llds__unop_return_type(UnOp, Type).
vn_type__vnrval_type(vn_binop(BinOp, _, _), Type) :-
	llds__binop_return_type(BinOp, Type).
vn_type__vnrval_type(vn_stackvar_addr(_), data_ptr).
vn_type__vnrval_type(vn_framevar_addr(_), data_ptr).
vn_type__vnrval_type(vn_heap_addr(_, _, _), data_ptr).

vn_type__vnlval_type(vn_reg(RegType, _), Type) :-
	llds__register_type(RegType, Type).
vn_type__vnlval_type(vn_succip, code_ptr).
vn_type__vnlval_type(vn_maxfr, data_ptr).
vn_type__vnlval_type(vn_curfr, data_ptr).
vn_type__vnlval_type(vn_hp, data_ptr).
vn_type__vnlval_type(vn_sp, data_ptr).
vn_type__vnlval_type(vn_temp(RegType, _), Type) :-
	llds__register_type(RegType, Type).
vn_type__vnlval_type(vn_stackvar(_), word).
vn_type__vnlval_type(vn_framevar(_), word).
vn_type__vnlval_type(vn_succip(_), code_ptr).
vn_type__vnlval_type(vn_redoip(_), code_ptr).
vn_type__vnlval_type(vn_redofr(_), data_ptr).
vn_type__vnlval_type(vn_succfr(_), data_ptr).
vn_type__vnlval_type(vn_prevfr(_), data_ptr).
vn_type__vnlval_type(vn_field(_, _, _), word).
vn_type__vnlval_type(vn_mem_ref(_), word).