[m-rev.] for review: Add a `pregen' grade component.
Peter Wang
novalazy at gmail.com
Fri Mar 15 17:48:52 AEDT 2013
Still needs more testing.
---
Add a `pregen' grade component and associated option `--pregenerated-dist',
intended for use in the pre-generated C files in the source distribution
ONLY.
Traditionally, by forcing the use of 2 tag bits and boxed floats, we
could provide one set of pre-generated C files, nominally targeting
32-bit platforms but also working on 64-bit platforms.
This became insufficient after I made two data representation changes.
The same constructor may have different layouts of its arguments
for --bits-per-word=32 and --bits-per-word=64:
- double-precision `float' arguments can be stored across two
words on 32-bit, whereas only one word is required on 64-bit;
- consecutive enum arguments can be packed into a single word
but the number of arguments that can be packed differs.
As a result, data structures created in a user module could be
misinterpreted when passed to a pre-generated standard library module,
and vice versa. (The enum case probably does not occur in practice.)
The solution adopted here is to allow configure to detect normal 64-bit
settings (3 tag bits, unboxed floats) irrespective of whether a usable
Mercury installation already exists. When present, the `pregen' grade
component causes the compiler and scripts to override the configuration
and enforce settings for portable C source files. The source
distribution should supply C source files from a `pregen' grade.
During installation, if required, the pre-generated C source files are
used to build and install a Mercury compiler _in a .pregen grade_.
Then it is used to install the libraries _in non-.pregen grades_,
so that configured settings have their usual effect.
Another benefit is that a user on a 64-bit system will get the "optimal"
installation using 3 tag bits and unboxed floats without additional
effort.
A small disadvantage is that a minimal installation of Mercury takes
slightly longer, as the default library grade no longer comes from the
pre-generated C source files.
compiler/options.m:
Add `--pregenerated-dist' option (same as `pregen' grade component).
Add `--arg-pack-bits <n>' internal option.
`--allow-argument-packing' is obsolete.
Add `--allow-double-word-fields' internal option.
compiler/handle_options.m:
Add `pregen' grade component. `pregen' implies boxed floats and
`spf' (single-prec float) implies unboxed floats, so we consider
them incompatible. There should be no need to use both at once.
In `pregen' grades, override settings to create portable C
source files.
Handle the internal `--arg-pack-bits <n>' option.
compiler/make_hlds_passes.m:
Pack only as many consecutive arguments as will fit into the
number of bits specified by `--arg-pack-bits', rather than into
the number of word bits. `pregen' implies --arg-pack-bits=32
Use `--allow-double-word-fields' to decide whether to store
floats across two words. `pregen' disables it.
compiler/compile_target_code.m:
Define MR_PREGENERATED_DIST when compiling C files in a `pregen'
grade.
compiler/c_util.m:
Write PREGENERATED_DIST={yes,no} into the grade info header at
the top of C files. This is checked by configure.
runtime/mercury_conf_param.h:
Make MR_PREGENERATED_DIST force the same settings as the
`--pregenerated-dist' option.
runtime/mercury_grade.h:
Add "_pregen" to the MR_GRADE macro so that `pregen' and
non-`pregen' object files are not accidentally mixed.
configure.ac:
As above, do NOT force 2 tag bits and unboxed floats when there
is no usable Mercury compiler installed.
BOOTSTRAP_GRADE is now a grade containing `.pregen'.
Make a minimal installation install $BEST_GRADE_FOR_COMPILER as
the default grade, not the grade that the compiler happens to be
built in, which might be a `pregen' grade.
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
Support `pregen' grade component and `--pregenerated-dist'
in shell scripts.
tools/test_mercury:
Add a note.
---
compiler/c_util.m | 3 +
compiler/compile_target_code.m | 11 ++++
compiler/handle_options.m | 53 +++++++++++++++++---
compiler/make_hlds_passes.m | 27 ++++------
compiler/options.m | 42 ++++++++++------
configure.ac | 93 +++++++++++++---------------------
runtime/mercury_conf_param.h | 18 +++++++
runtime/mercury_grade.h | 5 ++-
scripts/canonical_grade.sh-subr | 11 +++-
scripts/init_grade_options.sh-subr | 1 +
scripts/mgnuc.in | 12 +++--
scripts/parse_grade_options.sh-subr | 10 ++++
tools/test_mercury | 1 +
13 files changed, 183 insertions(+), 104 deletions(-)
diff --git a/compiler/c_util.m b/compiler/c_util.m
index e068f01..fc81414 100644
--- a/compiler/c_util.m
+++ b/compiler/c_util.m
@@ -664,6 +664,8 @@ output_c_file_intro_and_grade(Globals, SourceFileName, Version, !IO) :-
string.int_to_string(NumTagBits, NumTagBitsStr),
globals.lookup_bool_option(Globals, unboxed_float, UnboxedFloat),
UnboxedFloatStr = convert_bool_to_string(UnboxedFloat),
+ globals.lookup_bool_option(Globals, pregenerated_dist, PregeneratedDist),
+ PregeneratedDistStr = convert_bool_to_string(PregeneratedDist),
globals.lookup_bool_option(Globals, highlevel_code, HighLevelCode),
HighLevelCodeStr = convert_bool_to_string(HighLevelCode),
@@ -679,6 +681,7 @@ output_c_file_intro_and_grade(Globals, SourceFileName, Version, !IO) :-
"**\n",
"** TAG_BITS=", NumTagBitsStr, "\n",
"** UNBOXED_FLOAT=", UnboxedFloatStr, "\n",
+ "** PREGENERATED_DIST=", PregeneratedDistStr, "\n",
"** HIGHLEVEL_CODE=", HighLevelCodeStr, "\n",
"**\n",
"** END_OF_C_GRADE_INFO\n",
diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 64f0830..e139538 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -923,6 +923,15 @@ gather_grade_defines(Globals, PIC, GradeDefines) :-
MinimalModelDebug = no,
MinimalModelOpt = MinimalModelBaseOpt
),
+
+ globals.lookup_bool_option(Globals, pregenerated_dist, PregeneratedDist),
+ (
+ PregeneratedDist = yes,
+ PregeneratedDistOpt = "-DMR_PREGENERATED_DIST "
+ ;
+ PregeneratedDist = no,
+ PregeneratedDistOpt = ""
+ ),
globals.lookup_bool_option(Globals, single_prec_float, SinglePrecFloat),
(
SinglePrecFloat = yes,
@@ -931,6 +940,7 @@ gather_grade_defines(Globals, PIC, GradeDefines) :-
SinglePrecFloat = no,
SinglePrecFloatOpt = ""
),
+
globals.lookup_bool_option(Globals, use_regions, UseRegions),
(
UseRegions = yes,
@@ -977,6 +987,7 @@ gather_grade_defines(Globals, PIC, GradeDefines) :-
UseTrailOpt,
TrailSegOpt,
MinimalModelOpt,
+ PregeneratedDistOpt,
SinglePrecFloatOpt,
UseRegionsOpt], GradeDefines).
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index 25afbe9..2303879 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -653,6 +653,20 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
true
),
+ % --pregenerated-dist sets options so that the pre-generated C source
+ % distribution can be compiled equally on 32-bit and 64-bit platforms.
+ globals.lookup_bool_option(!.Globals, pregenerated_dist, PregeneratedDist),
+ (
+ PregeneratedDist = yes,
+ globals.set_option(num_tag_bits, int(2), !Globals),
+ globals.set_option(arg_pack_bits, int(32), !Globals),
+ globals.set_option(unboxed_float, bool(no), !Globals),
+ globals.set_option(single_prec_float, bool(no), !Globals),
+ globals.set_option(allow_double_word_fields, bool(no), !Globals)
+ ;
+ PregeneratedDist = no
+ ),
+
% --tags none implies --num-tag-bits 0.
(
TagsMethod0 = tags_none,
@@ -1385,9 +1399,26 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
% In the future, we may want to use C bit-field syntax for high-level data.
% For other back-ends, any RTTI code will need to be updated to cope with
% packed arguments.
- option_implies(highlevel_data, allow_argument_packing, bool(no), !Globals),
+ %
+ % Only C targets may store a constructor argument across two words.
+ option_implies(highlevel_data, arg_pack_bits, int(0), !Globals),
(
- Target = target_c
+ Target = target_c,
+ globals.lookup_int_option(!.Globals, arg_pack_bits, ArgPackBits0),
+ globals.lookup_int_option(!.Globals, bits_per_word, BitsPerWord),
+ % If --arg-pack-bits is negative then it means use all word bits.
+ ( ArgPackBits0 < 0 ->
+ ArgPackBits = BitsPerWord
+ ; ArgPackBits0 > BitsPerWord ->
+ io.progname_base("mercury_compile", ProgNameB, !IO),
+ io.format("%s: warning: --arg-pack-bits invalid\n",
+ [s(ProgNameB)], !IO),
+ record_warning(!.Globals, !IO),
+ ArgPackBits = BitsPerWord
+ ;
+ ArgPackBits = ArgPackBits0
+ ),
+ globals.set_option(arg_pack_bits, int(ArgPackBits), !Globals)
;
( Target = target_csharp
; Target = target_java
@@ -1395,7 +1426,8 @@ convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
; Target = target_il
; Target = target_erlang
),
- globals.set_option(allow_argument_packing, bool(no), !Globals)
+ globals.set_option(arg_pack_bits, int(0), !Globals),
+ globals.set_option(allow_double_word_fields, bool(no), !Globals)
),
% We assume that single-precision floats do not need to be boxed.
@@ -2704,9 +2736,10 @@ grade_string_to_comp_strings(GradeString, MaybeGrade, !Errors) :-
; comp_term_size % whether or not to record term sizes
; comp_trail % whether or not to use trailing
; comp_minimal_model % whether we set up for minimal model tabling
- ; comp_single_prec_float
- % whether or not to use single precision
- % floating point values
+ ; comp_pregen_spf % whether to assume settings for the
+ % pregenerated C source distribution;
+ % and whether or not to use single precision
+ % floating point values.
; comp_pic % Do we need to reserve a register for
% PIC (position independent code)?
; comp_lowlevel % what to do to target code
@@ -3038,7 +3071,11 @@ grade_component_table("dmmos", comp_minimal_model,
use_minimal_model_own_stacks - bool(yes),
minimal_model_debug - bool(yes)], no, yes).
-grade_component_table("spf", comp_single_prec_float,
+ % Settings for pre-generated source distribution
+ % or single-precision floats.
+grade_component_table("pregen", comp_pregen_spf,
+ [pregenerated_dist - bool(yes)], no, yes).
+grade_component_table("spf", comp_pregen_spf,
[single_prec_float - bool(yes),
unboxed_float - bool(yes)], no, yes).
@@ -3112,6 +3149,8 @@ grade_start_values(trail_segments - bool(no)).
grade_start_values(use_minimal_model_stack_copy - bool(no)).
grade_start_values(use_minimal_model_own_stacks - bool(no)).
grade_start_values(minimal_model_debug - bool(no)).
+grade_start_values(pregenerated_dist - bool(no)).
+grade_start_values(single_prec_float - bool(no)).
grade_start_values(pic_reg - bool(no)).
grade_start_values(exec_trace - bool(no)).
grade_start_values(decl_debug - bool(no)).
diff --git a/compiler/make_hlds_passes.m b/compiler/make_hlds_passes.m
index 296b5ac..5fbaf41 100644
--- a/compiler/make_hlds_passes.m
+++ b/compiler/make_hlds_passes.m
@@ -273,11 +273,9 @@ layout_du_ctor_args(ModuleInfo, DuKind, Ctor0, Ctor) :-
Args1 = Args0
)
),
- globals.lookup_bool_option(Globals, allow_argument_packing, ArgPacking),
- (
- ArgPacking = yes,
- globals.lookup_int_option(Globals, bits_per_word, TargetWordBits),
- pack_du_ctor_args(ModuleInfo, TargetWordBits, 0, Args1, Args2, _),
+ globals.lookup_int_option(Globals, arg_pack_bits, ArgPackBits),
+ ( ArgPackBits > 0 ->
+ pack_du_ctor_args(ModuleInfo, ArgPackBits, 0, Args1, Args2, _),
WorthPacking = worth_arg_packing(Args1, Args2),
(
WorthPacking = yes,
@@ -287,7 +285,6 @@ layout_du_ctor_args(ModuleInfo, DuKind, Ctor0, Ctor) :-
Args = Args1
)
;
- ArgPacking = no,
Args = Args1
),
Ctor = ctor(ExistTVars, Constraints, Name, Args, Context).
@@ -295,26 +292,22 @@ layout_du_ctor_args(ModuleInfo, DuKind, Ctor0, Ctor) :-
:- pred use_double_word_floats(globals::in, bool::out) is det.
use_double_word_floats(Globals, DoubleWordFloats) :-
- globals.get_target(Globals, Target),
- globals.lookup_int_option(Globals, bits_per_word, TargetWordBits),
- globals.lookup_bool_option(Globals, single_prec_float, SinglePrecFloat),
+ globals.lookup_bool_option(Globals, allow_double_word_fields,
+ AllowDoubleWords),
(
- Target = target_c,
+ AllowDoubleWords = yes,
+ globals.lookup_int_option(Globals, bits_per_word, TargetWordBits),
+ globals.lookup_bool_option(Globals, single_prec_float, SinglePrec),
(
TargetWordBits = 32,
- SinglePrecFloat = no
+ SinglePrec = no
->
DoubleWordFloats = yes
;
DoubleWordFloats = no
)
;
- ( Target = target_il
- ; Target = target_csharp
- ; Target = target_java
- ; Target = target_x86_64
- ; Target = target_erlang
- ),
+ AllowDoubleWords = no,
DoubleWordFloats = no
).
diff --git a/compiler/options.m b/compiler/options.m
index ceee077..d25ce2e 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -390,6 +390,7 @@
; use_minimal_model_stack_copy
; use_minimal_model_own_stacks
; minimal_model_debug
+ ; pregenerated_dist
; single_prec_float
; type_layout
; maybe_thread_safe_opt
@@ -421,6 +422,8 @@
; unboxed_float
; unboxed_enums
; unboxed_no_tag_types
+ ; arg_pack_bits
+ ; allow_double_word_fields
; sync_term_size % in words
% LLDS back-end compilation model options
@@ -590,8 +593,6 @@
; type_check_constraints
- ; allow_argument_packing
-
% Code generation options
; low_level_debug
; table_debug
@@ -1336,6 +1337,7 @@ option_defaults_2(compilation_model_option, [
use_minimal_model_stack_copy - bool(no),
use_minimal_model_own_stacks - bool(no),
minimal_model_debug - bool(no),
+ pregenerated_dist - bool(no),
single_prec_float - bool(no),
type_layout - bool(yes),
source_to_source_debug - bool(no),
@@ -1361,13 +1363,17 @@ option_defaults_2(compilation_model_option, [
% The `mmc' script will override the
% above default with a value determined
% at configuration time.
+ unboxed_float - bool(no),
+ unboxed_enums - bool(yes),
+ unboxed_no_tag_types - bool(yes),
+ arg_pack_bits - int(-1),
+ % -1 is a special value which means use
+ % all word bits for argument packing.
+ allow_double_word_fields - bool(yes),
sync_term_size - int(8),
% 8 is the size on linux (at the time
% of writing) - will usually be
% overridden by a value from configure.
- unboxed_float - bool(no),
- unboxed_enums - bool(yes),
- unboxed_no_tag_types - bool(yes),
% LLDS back-end compilation model options
gcc_non_local_gotos - bool(yes),
@@ -1432,8 +1438,7 @@ option_defaults_2(internal_use_option, [
size_region_commit_entry - int(1),
solver_type_auto_init - bool(no),
allow_multi_arm_switches - bool(yes),
- type_check_constraints - bool(no),
- allow_argument_packing - bool(yes)
+ type_check_constraints - bool(no)
]).
option_defaults_2(code_gen_option, [
% Code Generation Options
@@ -2266,6 +2271,7 @@ long_option("use-regions-profiling",use_regions_profiling).
long_option("use-minimal-model-stack-copy", use_minimal_model_stack_copy).
long_option("use-minimal-model-own-stacks", use_minimal_model_own_stacks).
long_option("minimal-model-debug", minimal_model_debug).
+long_option("pregenerated-dist", pregenerated_dist).
long_option("single-prec-float", single_prec_float).
long_option("single-precision-float", single_prec_float).
long_option("pic-reg", pic_reg).
@@ -2276,10 +2282,12 @@ long_option("num-reserved-objects", num_reserved_objects).
long_option("bits-per-word", bits_per_word).
long_option("bytes-per-word", bytes_per_word).
long_option("conf-low-tag-bits", conf_low_tag_bits).
-long_option("sync-term-size", sync_term_size).
long_option("unboxed-float", unboxed_float).
long_option("unboxed-enums", unboxed_enums).
long_option("unboxed-no-tag-types", unboxed_no_tag_types).
+long_option("arg-pack-bits", arg_pack_bits).
+long_option("allow-double-word-fields", allow_double_word_fields).
+long_option("sync-term-size", sync_term_size).
long_option("highlevel-data", highlevel_data).
long_option("high-level-data", highlevel_data).
% LLDS back-end compilation model options
@@ -2344,7 +2352,6 @@ long_option("size-region-commit-entry", size_region_commit_entry).
long_option("solver-type-auto-init", solver_type_auto_init).
long_option("allow-multi-arm-switches", allow_multi_arm_switches).
long_option("type-check-constraints", type_check_constraints).
-long_option("allow-argument-packing", allow_argument_packing).
% code generation options
long_option("low-level-debug", low_level_debug).
@@ -4658,6 +4665,17 @@ options_help_compilation_model -->
% "(This option is not for general use.)",
% "\tBox no-tag types. This option is disabled by default."
+ % This is a developer only option.
+% "--arg-pack-bits <n>",
+% "(This option is not for general use.)",
+% "\tThe number of bits in a word in which to pack constructor"
+% "arguments.",
+
+ % This is a developer only option.
+% "--no-allow-double-word-fields",
+% "(This option is not for general use.)",
+% "\tDisallow storing a single constructor argument in two words"
+% "(namely, double-precision floats).",
]),
io.write_string("\n Developer optional features\n"),
write_tabbed_lines([
@@ -4776,12 +4794,6 @@ options_help_compilation_model -->
% "--type-check-constraints",
% "(This option is not for general use.)",
% Use the constraint based type checker instead of the old one.
-
- % This is a developer only option.
-% "--allow-argument-packing",
-% "(This option is not for general use.)",
-% Allow the compiler to pack multiple constructor arguments into
-% a single field.
]).
:- pred options_help_code_generation(io::di, io::uo) is det.
diff --git a/configure.ac b/configure.ac
index de42c1f..2143b03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1950,14 +1950,6 @@ if test "$mercury_cv_low_tag_bits" -lt 2; then
exit 1
fi
fi
-if test "$mercury_cv_low_tag_bits" -gt 2
-then
- if test "$BOOTSTRAP_MC" = "" -a "$reconfiguring" = "no"
- then
- AC_MSG_WARN(bootstrapping using only 2 low tag bits)
- mercury_cv_low_tag_bits=2
- fi
-fi
AC_DEFINE_UNQUOTED(MR_LOW_TAG_BITS, $mercury_cv_low_tag_bits)
LOW_TAG_BITS=$mercury_cv_low_tag_bits
AC_SUBST(LOW_TAG_BITS)
@@ -2067,22 +2059,6 @@ AC_CACHE_VAL(mercury_cv_unboxed_floats,
[mercury_cv_unboxed_floats=no])
)
AC_MSG_RESULT($mercury_cv_unboxed_floats)
-if test "$mercury_cv_unboxed_floats" = yes
-then
- if test "$BOOTSTRAP_MC" = "" -a "$reconfiguring" = "no"
- then
- AC_MSG_WARN(
-[Mercury compiler not yet installed -
-**** cannot use unboxed floats, bootstrapping using boxed floats
-**** after installation is complete you may want to reinstall
-**** from scratch so you can use unboxed floats, which are more
-**** efficient.
-**** NOTE: before reinstalling from scratch, ensure that the
-**** source tree is clean by running \`make realclean'. Not doing
-**** this may result in a broken Mercury installation.])
- mercury_cv_unboxed_floats=no
- fi
-fi
if test "$mercury_cv_unboxed_floats" = yes; then
HAVE_BOXED_FLOATS="--unboxed-float"
else
@@ -3271,56 +3247,45 @@ esac
# compiler from the source distribution, if there is no installed Mercury
# compiler. This grade needs to be one for which the C files are compatible
# with the C files that we ship in the source distribution. The C files in the
-# source distribution are generated in either hlc.gc or in asm_fast.gc. In the
-# former case, we _must_ use the grade hlc.gc, in the latter case we can use any
-# of the base LLDS grades (it's the same C code), except that a couple of them
-# (fast and jump) don't support code addresses in static initalizers.
+# source distribution are generated in hlc.gc.pregen or asm_fast.gc.pregen.
+# In the former case, we _must_ use the grade hlc.gc.pregen, in the latter case
+# we can use any of the base LLDS grades (it's the same C code), except that a
+# couple of them (fast and jump) don't support code addresses in static
+# initalizers.
if test "$BOOTSTRAP_HLC" = "yes"
then
- BOOTSTRAP_GRADE=hlc.gc
+ BOOTSTRAP_GRADE=hlc.gc.pregen
else
case $BEST_LLDS_BASE_GRADE in
jump|fast)
if test $mercury_cv_gcc_model_reg = yes; then
- BOOTSTRAP_GRADE=reg.gc
+ BOOTSTRAP_GRADE=reg.gc.pregen
else
- BOOTSTRAP_GRADE=none.gc
+ BOOTSTRAP_GRADE=none.gc.pregen
fi
;;
*)
- BOOTSTRAP_GRADE=$BEST_LLDS_BASE_GRADE.gc
+ BOOTSTRAP_GRADE=$BEST_LLDS_BASE_GRADE.gc.pregen
;;
esac
fi
-# Choose whether to use $BOOTSTRAP_GRADE or $BEST_GRADE_FOR_COMPILER,
-# and if necessary remove the previously built C files.
+# Choose whether to use $BOOTSTRAP_GRADE or $BEST_GRADE_FOR_COMPILER.
+# Previously built C files will be checked for compatibility
+# with these settings, and otherwise removed, later.
-if test "$BEST_GRADE_FOR_COMPILER" != "$BOOTSTRAP_GRADE"; then
- if test "$BOOTSTRAP_MC" = ""; then
- GRADE="$BOOTSTRAP_GRADE"
- AC_MSG_WARN(
+if test "$BOOTSTRAP_MC" = ""; then
+ GRADE="$BOOTSTRAP_GRADE"
+ AC_MSG_WARN(
[Mercury compiler not yet installed -
**** cannot use grade \`$BEST_GRADE_FOR_COMPILER'
**** using grade \`$GRADE' to compile the compiler
-**** after installation is complete you should reinstall
-**** from scratch so you can use the more efficient
-**** grade \`$BEST_GRADE_FOR_COMPILER'.
+**** after installation is complete you may reinstall
+**** from scratch to have a faster compiler.
**** NOTE: before reinstalling from scratch, ensure that the
**** source tree is clean by running \`make realclean'. Not doing
**** this may result in a broken Mercury installation.])
- else
- GRADE=$BEST_GRADE_FOR_COMPILER
- MERCURY_MSG(
-"using grade \`$GRADE' to compile the compiler
- compiler and library will be rebuilt with new grade
- installation may take a long time")
- find library compiler browser mdbcomp \
- profiler deep_profiler ssdb slice \
- -name \*.c -o -name \*.c_date | \
- xargs rm > /dev/null 2>&1
- fi
else
GRADE=$BEST_GRADE_FOR_COMPILER
MERCURY_MSG("using grade \`$GRADE' to compile the compiler")
@@ -3765,8 +3730,8 @@ fi
#
if test "$enable_min_install" = yes
then
- LIBGRADES="$GRADE"
- DEFAULT_GRADE="$GRADE"
+ LIBGRADES="$BEST_GRADE_FOR_COMPILER"
+ DEFAULT_GRADE="$BEST_GRADE_FOR_COMPILER"
fi
# Allow the user to override the default list of library grades
@@ -5224,19 +5189,33 @@ mercury_check_c_files () {
c_dir=$1
c_date_dir=$2
+ case $GRADE in
+ *.pregen*)
+ need_low_tag_bits=2
+ need_unboxed_floats=no
+ need_pregen_dist=yes
+ ;;
+ *)
+ need_low_tag_bits=$mercury_cv_low_tag_bits
+ need_unboxed_floats=$mercury_cv_unboxed_floats
+ need_pregen_dist=no
+ ;;
+ esac
+
for c_file in $c_dir/*.c
do
case $c_file in
*/'*.c')
;;
*/*_init.c)
- some_kept=true
;;
*)
sed -e '/END_OF_C_GRADE_INFO/q' < $c_file > confscratch
- if grep "TAG_BITS=$mercury_cv_low_tag_bits" \
+ if grep "TAG_BITS=$need_low_tag_bits" \
+ confscratch > /dev/null 2>&1 \
+ && grep "UNBOXED_FLOAT=$need_unboxed_floats" \
confscratch > /dev/null 2>&1 \
- && grep "UNBOXED_FLOAT=$mercury_cv_unboxed_floats" \
+ && grep "PREGENERATED_DIST=$need_pregen_dist" \
confscratch > /dev/null 2>&1 \
&& grep "HIGHLEVEL_CODE=$need_hl_c_files" \
confscratch > /dev/null 2>&1
diff --git a/runtime/mercury_conf_param.h b/runtime/mercury_conf_param.h
index 1e17739..170d9f2 100644
--- a/runtime/mercury_conf_param.h
+++ b/runtime/mercury_conf_param.h
@@ -133,6 +133,7 @@
** MR_USE_MINIMAL_MODEL_STACK_COPY
** MR_USE_MINIMAL_MODEL_OWN_STACKS
** MR_MINIMAL_MODEL_DEBUG
+** MR_PREGENERATED_DIST
** MR_USE_SINGLE_PREC_FLOAT
** MR_EXTEND_STACKS_WHEN_NEEDED
** MR_STACK_SEGMENTS
@@ -159,6 +160,7 @@
** --reserve-tag
** --use-minimal-model
** --minimal-model-debug
+** --pregenerated-dist
** --single-prec-float
** --extend-stacks-when-needed
** --stack-segments
@@ -667,6 +669,22 @@
*/
/*
+** MR_PREGENERATED_DIST overrides configured values to assume values compatible
+** with those used to generate the pre-generated source distribution.
+** It implies boxed floats so is incompatible with single-precision floats,
+** which imply unboxed floats.
+*/
+#ifdef MR_PREGENERATED_DIST
+ #undef MR_LOW_TAG_BITS
+ #define MR_LOW_TAG_BITS 2
+ #ifdef MR_USE_SINGLE_PREC_FLOAT
+ #error "MR_PREGENERATED_DIST and MR_USE_SINGLE_PREC_FLOAT both defined"
+ #else
+ #define MR_BOXED_FLOAT 1
+ #endif
+#endif
+
+/*
** MR_PIC means that we are generating position independent code,
** i.e. that the file was compiled with the gcc option `-fpic' or equivalent.
*/
diff --git a/runtime/mercury_grade.h b/runtime/mercury_grade.h
index 7c12d48..44d356b 100644
--- a/runtime/mercury_grade.h
+++ b/runtime/mercury_grade.h
@@ -347,6 +347,7 @@
** Parts 10-11 (i.e. tag bits, and (un)boxed float) are documented as
** "not for general use", and can't be set via the `--grade' option;
** we therefore can't make them part of the grade option string.
+**
** Single-precision floats do form part of the grade option string
** and they imply unboxed floats.
**
@@ -366,7 +367,9 @@
#endif
#define MR_GRADE_OPT_PART_10 MR_GRADE_OPT_PART_9
-#if defined(MR_USE_SINGLE_PREC_FLOAT)
+#if defined(MR_PREGENERATED_DIST)
+ #define MR_GRADE_PART_11 MR_PASTE2(MR_GRADE_PART_10, _pregen)
+#elif defined(MR_USE_SINGLE_PREC_FLOAT)
#if defined(MR_BOXED_FLOAT)
#error "single-precision floats implies unboxed floats"
#endif
diff --git a/scripts/canonical_grade.sh-subr b/scripts/canonical_grade.sh-subr
index 673c8fc..7f0b8c9 100644
--- a/scripts/canonical_grade.sh-subr
+++ b/scripts/canonical_grade.sh-subr
@@ -145,9 +145,14 @@ case $use_minimal_model_stack_copy,$use_minimal_model_own_stacks,$minimal_model_
*) ;;
esac
-case $single_prec_float in
- true) GRADE="$GRADE.spf" ;;
- false) ;;
+case $pregenerated_dist,$single_prec_float in
+ true,false) GRADE="$GRADE.pregen" ;;
+ false,true) GRADE="$GRADE.spf" ;;
+ false,false) ;;
+ *) progname=`basename $0`
+ echo "$progname: error: pregenerated dist incompatible with single-prec float." 1>&2
+ exit 1
+ ;;
esac
# We ignore the value of $picreg in computing the name of the grade
diff --git a/scripts/init_grade_options.sh-subr b/scripts/init_grade_options.sh-subr
index 720251a..e52a0aa 100644
--- a/scripts/init_grade_options.sh-subr
+++ b/scripts/init_grade_options.sh-subr
@@ -85,6 +85,7 @@ trail_segments=false
use_minimal_model_stack_copy=false
use_minimal_model_own_stacks=false
minimal_model_debug=false
+pregenerated_dist=false
single_prec_float=false
pic_reg=false
debug=false
diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index feaafe3..77b01ce 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -423,9 +423,13 @@ case $use_minimal_model,$minimal_model_debug in
*) MINIMAL_MODEL_OPTS="" ;;
esac
-case $single_prec_float in
- true) SINGLE_PREC_FLOAT_OPTS="-DMR_USE_SINGLE_PREC_FLOAT" ;;
- false) SINGLE_PREC_FLOAT_OPTS="" ;;
+case $pregenerated_dist,$single_prec_float in
+ true,true) progname=`basename $0`
+ echo "$progname: cannot enable both pregenerated dist and single-prec float"
+ exit 1 ;;
+ true,false) PREGEN_SPF_OPTS="-DMR_PREGENERATED_DIST" ;;
+ false,true) PREGEN_SPF_OPTS="-DMR_USE_SINGLE_PREC_FLOAT" ;;
+ false,false) PREGEN_SPF_OPTS="" ;;
esac
case $pic_reg in
@@ -712,7 +716,7 @@ ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
$TRAIL_OPTS\
$RECORD_TERM_SIZE_OPTS\
$MINIMAL_MODEL_OPTS\
- $SINGLE_PREC_FLOAT_OPTS\
+ $PREGEN_SPF_OPTS\
$SPLIT_OPTS\
$THREAD_OPTS\
$THREADSCOPE_OPTS\
diff --git a/scripts/parse_grade_options.sh-subr b/scripts/parse_grade_options.sh-subr
index 87a45d1..5a9c85d 100644
--- a/scripts/parse_grade_options.sh-subr
+++ b/scripts/parse_grade_options.sh-subr
@@ -173,6 +173,11 @@
--no-minimal-model-debug)
minimal_model_debug=false ;;
+ --pregenerated-dist)
+ pregenerated_dist=true ;;
+ --no-pregenerated-dist)
+ pregenerated_dist=false ;;
+
--single-prec-float)
single_prec_float=true ;;
--no-single-prec-float)
@@ -258,6 +263,7 @@
use_minimal_model_stack_copy=false
use_minimal_model_own_stacks=false
minimal_model_debug=false
+ pregenerated_dist=false
single_prec_float=false
pic_reg=false
debug=false
@@ -520,6 +526,10 @@
minimal_model_debug=true
;;
+ pregen)
+ pregenerated_dist=true
+ ;;
+
spf)
single_prec_float=true
;;
diff --git a/tools/test_mercury b/tools/test_mercury
index 23a3e73..c63f171 100755
--- a/tools/test_mercury
+++ b/tools/test_mercury
@@ -881,6 +881,7 @@ case $HOST in $ROTD_HOST)
rm -f so_locations &&
rm -f .enable_lib_grades &&
$ACLOCAL_CMD &&
+ # The cache variable settings can be replaced by --pregenerated-dist.
autoconf &&
mercury_cv_low_tag_bits=2 \
mercury_cv_bits_per_word=32 \
--
1.7.4.4
More information about the reviews
mailing list