[m-rev.] [reuse] diff: add foreign_code_attribute about aliasing
Peter Ross
peter.ross at miscrit.be
Thu Mar 22 00:20:38 AEDT 2001
Hi,
===================================================================
Estimated hours taken: 2
Branches: reuse
Add the ability to annotate pragma_foreign code with possible aliasing
information. Currently we only allow the attributes no_aliasing and
unknown_aliasing. At a later date we want to be able to annotate which
head variables are possibly aliased.
compiler/pa_alias_as.m:
Check the foreign_code attributes for aliasing information when
determining the aliasing.
compiler/pa_run.m:
compiler/sr_dead.m:
compiler/sr_indirect.m:
Pass the pragma_foreign_code_attributes to extend_foreign_code.
compiler/prog_data.m:
compiler/prog_io_pragma.m:
Add the new attributes no_aliasing and unknown_aliasing.
Index: pa_alias_as.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias_as.m,v
retrieving revision 1.1.2.15
diff -u -r1.1.2.15 pa_alias_as.m
--- pa_alias_as.m 2001/03/20 17:34:48 1.1.2.15
+++ pa_alias_as.m 2001/03/21 13:15:38
@@ -114,10 +114,11 @@
hlds_goal__hlds_goal_info, alias_as, alias_as).
:- mode extend_unification(in, in, in, in, in, out) is det.
-:- pred extend_foreign_code(proc_info, module_info, hlds_goal_info,
+:- pred extend_foreign_code(proc_info, module_info, hlds_goal_info,
+ pragma_foreign_code_attributes,
list(prog_var), list(maybe(pair(string, mode))),
list(type), alias_as, alias_as).
-:- mode extend_foreign_code(in, in, in, in, in, in, in, out) is det.
+:- mode extend_foreign_code(in, in, in, in, in, in, in, in, out) is det.
% Add two abstract substitutions to each other. These
% abstract substitutions come from different contexts, and have
@@ -471,8 +472,8 @@
%-----------------------------------------------------------------------------%
-extend_foreign_code(_ProcInfo, HLDS, GoalInfo,
- Vars, MaybeModes, Types, Alias0, Alias):-
+extend_foreign_code(_ProcInfo, HLDS, GoalInfo,
+ Attrs, Vars, MaybeModes, Types, Alias0, Alias):-
to_trios(Vars, MaybeModes, Types, Trios),
% remove all unique objects
remove_all_unique_vars(HLDS, Trios, NonUniqueVars),
@@ -480,12 +481,14 @@
collect_all_output_vars(HLDS, NonUniqueVars, OutputVars),
% collect_all_input_vars(HLDS, NonUniqueVars, InputVars),
(
-% (
+ (
OutputVars = []
+ ;
+ aliasing(Attrs, no_aliasing)
% ;
% % XXXXXXXXXXXXXXXXX !!
% OutputVars = [_], InputVars = []
-% )
+ )
->
Alias = Alias0
;
Index: pa_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_run.m,v
retrieving revision 1.1.2.18
diff -u -r1.1.2.18 pa_run.m
--- pa_run.m 2001/03/20 17:34:49 1.1.2.18
+++ pa_run.m 2001/03/21 13:15:38
@@ -430,10 +430,10 @@
analyse_goal( ProcInfo, HLDS, ELSE, T2, T, A0, A3),
pa_alias_as__least_upper_bound( ProcInfo, HLDS, A2, A3, A).
-analyse_goal_expr( pragma_foreign_code( _,_,_, Vars, MaybeModes,Types,_ ),
- Info, ProcInfo, HLDS ,
+analyse_goal_expr(pragma_foreign_code(Attrs, _, _, Vars, MaybeModes, Types, _),
+ Info, ProcInfo, HLDS,
T, T, Ain, A) :-
- pa_alias_as__extend_foreign_code( ProcInfo, HLDS, Info, Vars,
+ pa_alias_as__extend_foreign_code(ProcInfo, HLDS, Info, Attrs, Vars,
MaybeModes, Types, Ain, A).
% error( "(pa) pragma_c_code not handled") .
Index: prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.58.2.7
diff -u -r1.58.2.7 prog_data.m
--- prog_data.m 2001/02/07 14:30:25 1.58.2.7
+++ prog_data.m 2001/03/21 13:15:39
@@ -566,6 +566,13 @@
pragma_foreign_code_attributes).
:- mode set_tabled_for_io(in, in, out) is det.
+:- pred aliasing(pragma_foreign_code_attributes, aliasing).
+:- mode aliasing(in, out) is det.
+
+:- pred set_aliasing(pragma_foreign_code_attributes, aliasing,
+ pragma_foreign_code_attributes).
+:- mode set_aliasing(in, in, out) is det.
+
% For pragma c_code, there are two different calling conventions,
% one for C code that may recursively call Mercury code, and another
% more efficient one for the case when we know that the C code will
@@ -585,6 +592,10 @@
---> not_tabled_for_io
; tabled_for_io.
+:- type aliasing
+ ---> no_aliasing
+ ; unknown_aliasing.
+
:- type pragma_var
---> pragma_var(prog_var, string, mode).
% variable, name, mode
@@ -970,12 +981,13 @@
foreign_language :: foreign_language,
may_call_mercury :: may_call_mercury,
thread_safe :: thread_safe,
- tabled_for_io :: tabled_for_io
+ tabled_for_io :: tabled_for_io,
+ aliasing :: aliasing
).
default_attributes(Language,
attributes(Language, may_call_mercury, not_thread_safe,
- not_tabled_for_io)).
+ not_tabled_for_io, unknown_aliasing)).
may_call_mercury(Attrs, Attrs ^ may_call_mercury).
@@ -985,6 +997,8 @@
tabled_for_io(Attrs, Attrs ^ tabled_for_io).
+aliasing(Attrs, Attrs ^ aliasing).
+
set_may_call_mercury(Attrs0, MayCallMercury, Attrs) :-
Attrs = Attrs0 ^ may_call_mercury := MayCallMercury.
@@ -997,11 +1011,15 @@
set_tabled_for_io(Attrs0, TabledForIo, Attrs) :-
Attrs = Attrs0 ^ tabled_for_io := TabledForIo.
+set_aliasing(Attrs0, TabledForIo, Attrs) :-
+ Attrs = Attrs0 ^ aliasing := TabledForIo.
+
attributes_to_strings(Attrs, StringList) :-
% We ignore Lang because it isn't an attribute that you can put
% in the attribute list -- the foreign language specifier string
% is at the start of the pragma.
- Attrs = attributes(_Lang, MayCallMercury, ThreadSafe, TabledForIO),
+ Attrs = attributes(_Lang, MayCallMercury, ThreadSafe,
+ TabledForIO, Aliasing),
(
MayCallMercury = may_call_mercury,
MayCallMercuryStr = "may_call_mercury"
@@ -1022,7 +1040,15 @@
;
TabledForIO = not_tabled_for_io,
TabledForIOStr = "not_tabled_for_io"
+ ),
+ (
+ Aliasing = no_aliasing,
+ AliasingStr = "no_aliasing"
+ ;
+ Aliasing = unknown_aliasing,
+ AliasingStr = "unknown_aliasing"
),
- StringList = [MayCallMercuryStr, ThreadSafeStr, TabledForIOStr].
+ StringList = [MayCallMercuryStr, ThreadSafeStr, TabledForIOStr,
+ AliasingStr].
%-----------------------------------------------------------------------------%
Index: prog_io_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.23.2.6
diff -u -r1.23.2.6 prog_io_pragma.m
--- prog_io_pragma.m 2001/02/07 14:30:26 1.23.2.6
+++ prog_io_pragma.m 2001/03/21 13:15:40
@@ -1174,7 +1174,8 @@
:- type collected_pragma_foreign_code_attribute
---> may_call_mercury(may_call_mercury)
; thread_safe(thread_safe)
- ; tabled_for_io(tabled_for_io).
+ ; tabled_for_io(tabled_for_io)
+ ; aliasing(aliasing).
:- pred parse_pragma_foreign_code_attributes_term(foreign_language, term,
pragma_foreign_code_attributes).
@@ -1210,10 +1211,20 @@
fail
;
set_tabled_for_io(Attributes2, tabled_for_io,
- Attributes)
+ Attributes3)
)
;
- Attributes = Attributes2
+ Attributes3 = Attributes2
+ ),
+ ( list__member(aliasing(no_aliasing), AttrList) ->
+ ( list__member(aliasing(unknown_aliasing), AttrList) ->
+ % XXX an error message would be nice
+ fail
+ ;
+ set_aliasing(Attributes3, no_aliasing, Attributes)
+ )
+ ;
+ Attributes = Attributes3
).
:- pred parse_pragma_foreign_code_attributes_term0(term,
@@ -1248,6 +1259,8 @@
Flag = thread_safe(ThreadSafe)
; parse_tabled_for_io(Term, TabledForIo) ->
Flag = tabled_for_io(TabledForIo)
+ ; parse_aliasing(Term, Aliasing) ->
+ Flag = aliasing(Aliasing)
;
fail
).
@@ -1279,6 +1292,14 @@
tabled_for_io).
parse_tabled_for_io(term__functor(term__atom("not_tabled_for_io"), [], _),
not_tabled_for_io).
+
+:- pred parse_aliasing(term, aliasing).
+:- mode parse_aliasing(in, out) is semidet.
+
+parse_aliasing(term__functor(term__atom("no_aliasing"), [], _),
+ no_aliasing).
+parse_aliasing(term__functor(term__atom("unknown_aliasing"), [], _),
+ unknown_aliasing).
% parse a pragma foreign_code declaration
Index: sr_dead.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_dead.m,v
retrieving revision 1.1.2.15
diff -u -r1.1.2.15 sr_dead.m
--- sr_dead.m 2001/03/16 09:09:57 1.1.2.15
+++ sr_dead.m 2001/03/21 13:15:40
@@ -178,8 +178,8 @@
annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
- Expr0 = pragma_foreign_code(_, _, _, Vars, MaybeModes, Types, _),
- pa_alias_as__extend_foreign_code(ProcInfo, HLDS, Info0, Vars,
+ Expr0 = pragma_foreign_code(Attrs, _, _, Vars, MaybeModes, Types, _),
+ pa_alias_as__extend_foreign_code(ProcInfo, HLDS, Info0, Attrs, Vars,
MaybeModes, Types, Alias0, Alias),
Pool = Pool0,
Goal = Expr0 - Info0.
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.20
diff -u -r1.1.2.20 sr_indirect.m
--- sr_indirect.m 2001/03/16 17:15:47 1.1.2.20
+++ sr_indirect.m 2001/03/21 13:15:41
@@ -398,9 +398,9 @@
Goal = Expr - Info.
analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI) :-
- Expr0 = pragma_foreign_code( _, _, _, Vars, MaybeModes, Types, _ ),
- pa_alias_as__extend_foreign_code( ProcInfo, HLDS, Info0, Vars,
- MaybeModes, Types, AI0 ^ alias, Alias),
+ Expr0 = pragma_foreign_code(Attrs, _, _, Vars, MaybeModes, Types, _ ),
+ pa_alias_as__extend_foreign_code(ProcInfo, HLDS, Info0, Attrs, Vars,
+ MaybeModes, Types, AI0 ^ alias, Alias),
AI = AI0 ^ alias := Alias,
Goal = Expr0 - Info0.
@@ -596,11 +596,11 @@
Expr = if_then_else( Vars, Cond, Then, Else, SM),
Goal = Expr - Info.
-analyse_goal( ProcInfo, HLDS, Expr0 - Info0, Goal, Pool0, Pool,
+analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, Pool0, Pool,
Alias0, Alias,
FP0, FP) :-
- Expr0 = pragma_foreign_code(_, _, _, Vars, MaybeModes, Types, _ ),
- pa_alias_as__extend_foreign_code( ProcInfo, HLDS, Info0, Vars,
+ Expr0 = pragma_foreign_code(Attrs, _, _, Vars, MaybeModes, Types, _),
+ pa_alias_as__extend_foreign_code(ProcInfo, HLDS, Info0, Attrs, Vars,
MaybeModes, Types, Alias0, Alias),
Pool = Pool0,
FP = FP0,
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list