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 analysis and optimizations
26 # Local Analysis/Optimization
27 import allocate_iregister_slots
30 # Global Analysis types
31 import instantiated_type_analysis
32 import reachable_method_analysis
33 import reachable_as_init
35 # Global Analysis implementation
38 import reachable_as_init_impl
40 # Global Optimizations
41 import dead_method_removal
42 import inline_get_and_set
44 redef class ToolContext
45 readable writable var _global_callgraph
: String = "rta"
46 readable writable var _no_dead_method_removal
: Bool = false
47 readable writable var _no_inline_get_set
: Bool = false
51 # This method will analyse the program and store results (in global compilation only)
52 fun do_global_analysis
do
55 if tc
.global_callgraph
== "cha" then
56 var cha
= new ChaBuilder(self)
59 else if tc
.global_callgraph
== "rta" then
60 var rta
= new RtaBuilder(self)
66 # Ensure we have all analysis created
67 if rma
== null then rma
= new DefaultReachableMethodAnalysis
68 if ita
== null then ita
= new DefaultInstantiatedTypeAnalysis
70 var rai_builder
= new ReachableAsInitBuilder(self)
72 rai
= rai_builder
.context
74 # This method will optimize the program (in global compilation only)
75 # Those are done before analysis
76 fun do_global_pre_analysis_optimizations
do
78 if not tc
.no_inline_get_set
then inline_get_set
81 # This method will optimize the program (in global compilation only)
82 # Those are done after analysis
83 fun do_global_post_analysis_optimizations
do
85 if not tc
.no_dead_method_removal
then optimize_dead_methods
88 # This method will create log files storing analysis information
89 fun dump_global_analysis_information
(directory_name
: String) do
90 dump_reachable_methods
(directory_name
, tc
.global_callgraph
)
91 dump_unreachable_methods
(directory_name
, tc
.global_callgraph
)
92 dump_instantiated_types
(directory_name
)
93 dump_not_instantiated_types
(directory_name
)
94 dump_reachable_as_init_methods
(directory_name
)
99 # Perfom all optimizations
100 fun optimize
(m
: MMModule)
103 allocate_iregister_slots