Most of the global optimization concern should be in global.
Signed-off-by: Jean Privat <jean@pryen.org>
# Global imports
import icode
import program
+import abstracttool
# Global Analysis types
private import instantiated_type_analysis
redef class ToolContext
readable writable var _global_callgraph: String = "rta"
- readable writable var _no_dead_method_removal: Bool = false
- readable writable var _no_inline_get_set: Bool = false
- readable writable var _no_callgraph_from_init: Bool = false
- readable writable var _no_out_of_init_get_test_removal: Bool = false
+
+ readable var _opt_global: OptionBool = new OptionBool("Use global compilation", "--global")
+ readable var _opt_global_no_STF_opt: OptionBool = new OptionBool("Do not use SFT optimization", "--no-global-SFT-optimization")
+ readable var _opt_global_no_DMR_opt: OptionBool = new OptionBool("Do not use dead method removal optimization", "--no-global-DMR-optimization")
+ readable var _opt_global_no_inline_get_set: OptionBool = new OptionBool("Do not automatically inline getters/setters", "--no-global-get-set-inlining")
+ readable var _opt_global_no_out_of_init_get_test_opt: OptionBool = new OptionBool("Do not remove get tests outside object initialization", "--no-global-OOIT-optimization")
+ readable var _opt_global_no_RFIMA: OptionBool = new OptionBool("Do not use a specialized algorithm to find reachable methods from initializers", "--no-global-RFIM-analysis")
+ readable var _opt_global_callgraph: OptionEnum = new OptionEnum(["none", "cha", "rta"], "The algorithm to use to build the callgraph", 2, "--global-callgraph")
+
+ redef init
+ do
+ super
+ option_context.add_option(opt_global, opt_global_no_STF_opt, opt_global_no_DMR_opt, opt_global_callgraph, opt_global_no_inline_get_set, opt_global_no_RFIMA, opt_global_no_out_of_init_get_test_opt)
+ end
+end
+
+redef class AbstractCompiler
+ redef fun process_options
+ do
+ # FIXME: for some reason (a bug in the metamodel obviously) redefining process_options in ToolContext does not work: the compilation goes fine but the caal-mext-method skips it.
+ super
+ global = opt_global.value
+ use_SFT_optimization = not opt_global_no_STF_opt.value
+ global_callgraph = opt_global_callgraph.value_name
+ end
end
redef class Program
# This method will analyse the program and store results (in global compilation only)
fun do_global_analysis do
assert tc.global
+ # Pre optimizations:
+ if not tc.opt_global_no_inline_get_set.value then inline_get_set
if tc.global_callgraph == "cha" then
var cha = new ChaBuilder(self)
rai_builder.work
rai = rai_builder.context
- if not tc.no_callgraph_from_init then
+ if not tc.opt_global_no_RFIMA.value then
var b = new RFIMABuilder(self)
b.work
rfima = b.context
end
if rfima == null then rfima = new DefaultReachableFromInitMethodAnalysis
- end
- # This method will optimize the program (in global compilation only)
- # Those are done before analysis
- fun do_global_pre_analysis_optimizations do
- assert tc.global
- if not tc.no_inline_get_set then inline_get_set
- end
+ # Post optimizations
+ if not tc.opt_global_no_DMR_opt.value then optimize_dead_methods
+ if not tc.opt_global_no_out_of_init_get_test_opt.value then optimize_out_of_init_getters
- # This method will optimize the program (in global compilation only)
- # Those are done after analysis
- fun do_global_post_analysis_optimizations do
- assert tc.global
- if not tc.no_dead_method_removal then optimize_dead_methods
- if not tc.no_out_of_init_get_test_removal then optimize_out_of_init_getters
+ # LOG
+ if tc.opt_log.value then
+ dump_global_optimizations_information(tc.log_directory)
+ dump_global_analysis_information(tc.log_directory)
+ end
end
fun dump_global_optimizations_information(directory_name: String) do
readable var _opt_boost: OptionBool = new OptionBool("Optimize compilation", "-O", "--boost")
readable var _opt_no_cc: OptionBool = new OptionBool("Do not invoke C compiler", "--no-cc")
readable var _opt_cc_no_link: OptionBool = new OptionBool("Do not invoke C linker", "--cc-no-link")
- readable var _opt_global: OptionBool = new OptionBool("Use global compilation", "--global")
- readable var _opt_global_no_STF_opt: OptionBool = new OptionBool("Do not use SFT optimization", "--no-global-SFT-optimization")
- readable var _opt_global_no_DMR_opt: OptionBool = new OptionBool("Do not use dead method removal optimization", "--no-global-DMR-optimization")
- readable var _opt_global_no_inline_get_set: OptionBool = new OptionBool("Do not automatically inline getters/setters", "--no-global-get-set-inlining")
- readable var _opt_global_no_out_of_init_get_test_opt: OptionBool = new OptionBool("Do not remove get tests outside object initialization", "--no-global-OOIT-optimization")
- readable var _opt_global_no_RFIMA: OptionBool = new OptionBool("Do not use a specialized algorithm to find reachable methods from initializers", "--no-global-RFIM-analysis")
- readable var _opt_global_callgraph: OptionEnum = new OptionEnum(["none", "cha", "rta"], "The algorithm to use to build the callgraph", 2, "--global-callgraph")
readable var _opt_clibdir: OptionString = new OptionString("NIT C library directory", "--clibdir")
readable var _opt_bindir: OptionString = new OptionString("NIT tools directory", "--bindir")
readable var _opt_compdir: OptionString = new OptionString("Intermediate compilation directory", "--compdir")
init
do
super("nitc")
- option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_cc_no_link, opt_cc_libs, opt_cc_lib_paths, opt_cc_include_paths, opt_global, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix, opt_global_no_STF_opt, opt_global_no_DMR_opt, opt_global_callgraph, opt_global_no_inline_get_set, opt_global_no_RFIMA, opt_global_no_out_of_init_get_test_opt, opt_output_format)
+ option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_cc_no_link, opt_cc_libs, opt_cc_lib_paths, opt_cc_include_paths, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix, opt_output_format)
end
redef fun process_options
cc_include_paths = opt_cc_include_paths.value
var ext = opt_extension_prefix.value
if ext != null then ext_prefix = ext else ext_prefix = ""
- global = opt_global.value
- use_SFT_optimization = not opt_global_no_STF_opt.value
- no_dead_method_removal = opt_global_no_DMR_opt.value
- no_inline_get_set = opt_global_no_inline_get_set.value
- no_callgraph_from_init = opt_global_no_RFIMA.value
- no_out_of_init_get_test_removal = opt_global_no_out_of_init_get_test_opt.value
- global_callgraph = opt_global_callgraph.value_name
compdir = opt_compdir.value
if compdir == null then
var dir = once ("NIT_COMPDIR".to_symbol).environ
p.output_format = opt_output_format.value_name
p.compute_main_method
p.generate_allocation_iroutines
- if global then
- p.do_global_pre_analysis_optimizations
- p.do_global_analysis
- p.do_global_post_analysis_optimizations
- if opt_log.value then
- p.dump_global_optimizations_information(log_directory)
- p.dump_global_analysis_information(log_directory)
- end
- end
+ if global then p.do_global_analysis
p.do_table_computation
p.compile_prog
end
end
end
+redef class ToolContext
+ redef init do super # Avoid local property conflict
+end
+
+
var c = new NitCompiler
c.exec_cmd_line
-h, -?, --help Show Help (This screen)
--version Show version and exit
-v, --verbose Verbose
+ --global Use global compilation
+ --no-global-SFT-optimization Do not use SFT optimization
+ --no-global-DMR-optimization Do not use dead method removal optimization
+ --global-callgraph The algorithm to use to build the callgraph <none, cha, rta>
+ --no-global-get-set-inlining Do not automatically inline getters/setters
+ --no-global-RFIM-analysis Do not use a specialized algorithm to find reachable methods from initializers
+ --no-global-OOIT-optimization Do not remove get tests outside object initialization
-o, --output Output file
-O, --boost Optimize compilation
--no-cc Do not invoke C compiler
--cc-lib-name Name of library to use for C compiler
--cc-lib-path Path to libraries for C compiler
--cc-header-path Path to .h files for C compiler
- --global Use global compilation
--clibdir NIT C library directory
--bindir NIT tools directory
--compdir Intermediate compilation directory
-p, --extension-prefix Append prefix to file extension
- --no-global-SFT-optimization Do not use SFT optimization
- --no-global-DMR-optimization Do not use dead method removal optimization
- --global-callgraph The algorithm to use to build the callgraph <none, cha, rta>
- --no-global-get-set-inlining Do not automatically inline getters/setters
- --no-global-RFIM-analysis Do not use a specialized algorithm to find reachable methods from initializers
- --no-global-OOIT-optimization Do not remove get tests outside object initialization
--output-format The type of code we want to be generated <none, C, icode>