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
34 # Global Analysis implementation
37 # Global Optimizations
38 import dead_method_removal
40 redef class ToolContext
41 readable writable var _global_callgraph
: String = "cha"
42 readable writable var _no_dead_method_removal
: Bool = false
46 # This method will analyse the program and store results (in global compilation only)
47 fun do_global_analysis
do
50 if tc
.global_callgraph
== "cha" then
51 var cha
= new ChaBuilder(self)
56 # Ensure we have all analysis created
57 if rma
== null then rma
= new DefaultReachableMethodAnalysis
58 if ita
== null then ita
= new DefaultInstantiatedTypeAnalysis
60 # This method will optimize the program (in global compilation only)
61 fun do_global_optimizations
do
63 if not tc
.no_dead_method_removal
then optimize_dead_methods
68 # Perfom all optimizations
69 fun optimize
(m
: MMModule)
72 allocate_iregister_slots