[m-rev.] diff: provide finer grained control over --smart-indexing

Julien Fischer jfischer at opturion.com
Wed Apr 3 21:44:14 AEDT 2013


Provide finer grained control over --smart-indexing.

The --smart-indexing option enables a number of smart indexing strategies
depending on the switch category and backend.  This diff adds new developer
only options that provide finer grained control over which smart indexing
strategies are enabled.  I need this to assist in tracking down some problems
with the use of --smart-indexing on the MinGW64 port.

compiler/options.m:
	Add new command line options that can be used to selectively disable
	various types of smart indexing.

compiler/switch_util.m:
	Add a predicate to test whether the user has chosen to disable smart
	indexing for a particular category of switch.

compiler/switch_gen.m:
compiler/ml_switch_gen.m:
	Respect the new options.

Julien.

diff --git a/compiler/ml_switch_gen.m b/compiler/ml_switch_gen.m
index 6bb0648..0fafa13 100644
--- a/compiler/ml_switch_gen.m
+++ b/compiler/ml_switch_gen.m
@@ -182,6 +182,8 @@ ml_gen_switch(SwitchVar, CanFail, Cases,
CodeModel, Context, GoalInfo,
                 SwitchVarTypeDefn),
             hlds_data.get_type_defn_body(SwitchVarTypeDefn, SwitchVarTypeBody),
             SwitchVarTypeBody ^ du_type_reserved_addr = uses_reserved_address
+        ;
+            is_smart_indexing_disabled_category(Globals, SwitchCategory)
         )
     ->
         % XXX In some cases, we could generate better code if we first checked
diff --git a/compiler/options.m b/compiler/options.m
index d25ce2e..d234076 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -757,6 +757,11 @@
     ;         switch_single_rec_base_first
     ;         switch_multi_rec_base_first

+    ;         smart_atomic_indexing
+    ;         smart_string_indexing
+    ;         smart_tag_indexing
+    ;         smart_float_indexing
+
     ;       static_ground_cells
     ;       static_ground_floats
     ;       static_code_addresses
@@ -1623,6 +1628,11 @@ option_defaults_2(optimization_option, [

     % HLDS -> LLDS
     smart_indexing                      -   bool(no),
+    smart_atomic_indexing               -   bool(yes),
+    smart_string_indexing               -   bool(yes),
+    smart_tag_indexing                  -   bool(yes),
+    smart_float_indexing                -   bool(yes),
+
     dense_switch_req_density            -   int(25),
                                         % Minimum density before using
                                         % a dense switch.
@@ -2573,6 +2583,10 @@ long_option("structure-reuse-free-cells",
structure_reuse_free_cells).

 % HLDS->LLDS optimizations
 long_option("smart-indexing",       smart_indexing).
+long_option("smart-atomic-indexing", smart_atomic_indexing).
+long_option("smart-string-indexing", smart_string_indexing).
+long_option("smart-tag-indexing",    smart_tag_indexing).
+long_option("smart-float-indexing",  smart_float_indexing).
 long_option("dense-switch-req-density", dense_switch_req_density).
 long_option("lookup-switch-req-density",lookup_switch_req_density).
 long_option("dense-switch-size",    dense_switch_size).
@@ -5209,6 +5223,9 @@ options_help_hlds_hlds_optimization -->
 %        "\tEnable the analysis for region-based memory management."
     ]).

+    % XXX this is out-of-date.  --smart-indxing also affects the
+    % MLDS backend.
+    %
 :- pred options_help_hlds_llds_optimization(io::di, io::uo) is det.

 options_help_hlds_llds_optimization -->
@@ -5217,6 +5234,16 @@ options_help_hlds_llds_optimization -->
         "--no-smart-indexing",
         "\tGenerate switches as a simple if-then-else chains;",
         "\tdisable string hashing and integer table-lookup indexing.",
+% The following options are for developers only --they provide finer grained
+% control over smart indexing.
+%       "--no-smart-atomic-indexing",
+%       "\tDo not generate smart switches on atomic types.",
+%       "--no-smart-string-indexing",
+%       "\tDo not generate smart switches on strings."
+%       "--no-smart-tag-indexing",
+%       "\tDo not generate smart switches on discriminated union types.",
+%       "---no-smart-float-indexing",
+%       "\tDo not generate smart switches on floats."
         "--dense-switch-req-density <percentage>",
         "\tThe jump table generated for an atomic switch",
         "\tmust have at least this percentage of full slots (default: 25).",
diff --git a/compiler/switch_gen.m b/compiler/switch_gen.m
index 0330c47..c0fdc1b 100644
--- a/compiler/switch_gen.m
+++ b/compiler/switch_gen.m
@@ -151,6 +151,8 @@ generate_switch(CodeModel, Var, CanFail, Cases,
GoalInfo, Code, !CI) :-
             search_type_ctor_defn(TypeTable, VarTypeCtor, VarTypeDefn),
             hlds_data.get_type_defn_body(VarTypeDefn, VarTypeBody),
             VarTypeBody ^ du_type_reserved_addr = uses_reserved_address
+        ;
+            is_smart_indexing_disabled_category(Globals, SwitchCategory)
         )
     ->
         order_and_generate_cases(TaggedCases, VarRval, VarType, VarName,
diff --git a/compiler/switch_util.m b/compiler/switch_util.m
index ae711fb..107d6b9 100644
--- a/compiler/switch_util.m
+++ b/compiler/switch_util.m
@@ -91,6 +91,12 @@
     %
 :- func estimate_switch_tag_test_cost(cons_tag) = int.

+    % Succeeds if smart indexing for the given switch category has been
+    % disabled by the user on the command line.
+    %
+:- pred is_smart_indexing_disabled_category(globals::in, switch_category::in)
+    is semidet.
+
 %-----------------------------------------------------------------------------%
 %
 % Stuff for dense switches.
@@ -585,6 +591,21 @@ estimate_switch_tag_test_cost(Tag) = Cost :-
         unexpected($module, $pred, "non-switch tag")
     ).

+is_smart_indexing_disabled_category(Globals, SwitchCategory) :-
+    (
+        SwitchCategory = atomic_switch,
+        globals.lookup_bool_option(Globals, smart_atomic_indexing, no)
+    ;
+        SwitchCategory = string_switch,
+        globals.lookup_bool_option(Globals, smart_string_indexing, no)
+    ;
+        SwitchCategory = tag_switch,
+        globals.lookup_bool_option(Globals, smart_tag_indexing, no)
+    ;
+        SwitchCategory = float_switch,
+        globals.lookup_bool_option(Globals, smart_float_indexing, no)
+    ).
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 %



More information about the reviews mailing list