1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2009 Jean Privat <jean@pryen.org>
4 # Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # Intermediate code global analysis and optimizations
26 # Global Analysis types
27 private import instantiated_type_analysis
28 private import reachable_method_analysis
29 private import reachable_as_init
30 private import reachable_from_init_method_analysis
32 # Global Analysis implementation
33 private import cha_analysis
34 private import rta_analysis
35 private import reachable_as_init_impl
36 private import reachable_from_init_method_analysis_impl
38 # Global Optimizations
39 private import dead_method_removal
40 private import inline_get_and_set
41 private import remove_out_of_init_get_test
43 redef class ToolContext
44 readable writable var _global_callgraph
: String = "rta"
46 readable var _opt_global
: OptionBool = new OptionBool("Use global compilation", "--global")
47 readable var _opt_global_no_STF_opt
: OptionBool = new OptionBool("Do not use SFT optimization", "--no-global-SFT-optimization")
48 readable var _opt_global_no_DMR_opt
: OptionBool = new OptionBool("Do not use dead method removal optimization", "--no-global-DMR-optimization")
49 readable var _opt_global_no_inline_get_set
: OptionBool = new OptionBool("Do not automatically inline getters/setters", "--no-global-get-set-inlining")
50 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")
51 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")
52 readable var _opt_global_callgraph
: OptionEnum = new OptionEnum(["none", "cha", "rta"], "The algorithm to use to build the callgraph", 2, "--global-callgraph")
57 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
)
61 redef class AbstractCompiler
62 redef fun process_options
64 # 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.
66 global
= opt_global
.value
67 use_SFT_optimization
= not opt_global_no_STF_opt
.value
68 global_callgraph
= opt_global_callgraph
.value_name
73 # This method will analyse the program and store results (in global compilation only)
74 fun do_global_analysis
do
77 if not tc
.opt_global_no_inline_get_set
.value
then inline_get_set
79 if tc
.global_callgraph
== "cha" then
80 var cha
= new ChaBuilder(self)
83 else if tc
.global_callgraph
== "rta" then
84 var rta
= new RtaBuilder(self)
90 # Ensure we have all analysis created
91 if rma
== null then rma
= new DefaultReachableMethodAnalysis
92 if ita
== null then ita
= new DefaultInstantiatedTypeAnalysis
94 var rai_builder
= new ReachableAsInitBuilder(self)
96 rai
= rai_builder
.context
98 if not tc
.opt_global_no_RFIMA
.value
then
99 var b
= new RFIMABuilder(self)
104 if rfima
== null then rfima
= new DefaultReachableFromInitMethodAnalysis
107 if not tc
.opt_global_no_DMR_opt
.value
then optimize_dead_methods
108 if not tc
.opt_global_no_out_of_init_get_test_opt
.value
then optimize_out_of_init_getters
111 if tc
.opt_log
.value
then
112 dump_global_optimizations_information
(tc
.log_directory
)
113 dump_global_analysis_information
(tc
.log_directory
)
117 fun dump_global_optimizations_information
(directory_name
: String) do
118 dump_out_of_init_information
(directory_name
)
119 dump_dead_method_optimization
(directory_name
)
120 dump_inline_get_set
(directory_name
)
123 # This method will create log files storing analysis information
124 fun dump_global_analysis_information
(directory_name
: String) do
125 dump_reachable_methods
(directory_name
, tc
.global_callgraph
)
126 dump_unreachable_methods
(directory_name
, tc
.global_callgraph
)
127 dump_instantiated_types
(directory_name
)
128 dump_not_instantiated_types
(directory_name
)
129 dump_reachable_as_init_methods
(directory_name
)
130 dump_reachable_methods_from_init
(directory_name
)
131 dump_unreachable_methods_from_init
(directory_name
)