Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 17 | #include "optimizing_compiler.h" |
| 18 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 19 | #include <fstream> |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
| 22 | #include "builder.h" |
| 23 | #include "code_generator.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 24 | #include "compiler.h" |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 25 | #include "constant_folding.h" |
| 26 | #include "dead_code_elimination.h" |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 27 | #include "driver/compiler_driver.h" |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 28 | #include "driver/dex_compilation_unit.h" |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 29 | #include "graph_visualizer.h" |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 30 | #include "gvn.h" |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 31 | #include "instruction_simplifier.h" |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 32 | #include "nodes.h" |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 33 | #include "prepare_for_register_allocation.h" |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 34 | #include "register_allocator.h" |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 35 | #include "ssa_phi_elimination.h" |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 36 | #include "ssa_liveness_analysis.h" |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 37 | #include "utils/arena_allocator.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Used by the code generator, to allocate the code in a vector. |
| 43 | */ |
| 44 | class CodeVectorAllocator FINAL : public CodeAllocator { |
| 45 | public: |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 46 | CodeVectorAllocator() {} |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 47 | |
| 48 | virtual uint8_t* Allocate(size_t size) { |
| 49 | size_ = size; |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 50 | memory_.resize(size); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 51 | return &memory_[0]; |
| 52 | } |
| 53 | |
| 54 | size_t GetSize() const { return size_; } |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 55 | const std::vector<uint8_t>& GetMemory() const { return memory_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | std::vector<uint8_t> memory_; |
| 59 | size_t size_; |
| 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(CodeVectorAllocator); |
| 62 | }; |
| 63 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 64 | /** |
| 65 | * If set to true, generates a file suitable for the c1visualizer tool and IRHydra. |
| 66 | */ |
| 67 | static bool kIsVisualizerEnabled = false; |
| 68 | |
| 69 | /** |
| 70 | * Filter to apply to the visualizer. Methods whose name contain that filter will |
| 71 | * be in the file. |
| 72 | */ |
| 73 | static const char* kStringFilter = ""; |
| 74 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 75 | class OptimizingCompiler FINAL : public Compiler { |
| 76 | public: |
| 77 | explicit OptimizingCompiler(CompilerDriver* driver); |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 78 | ~OptimizingCompiler(); |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 79 | |
| 80 | bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu) const |
| 81 | OVERRIDE; |
| 82 | |
| 83 | CompiledMethod* Compile(const DexFile::CodeItem* code_item, |
| 84 | uint32_t access_flags, |
| 85 | InvokeType invoke_type, |
| 86 | uint16_t class_def_idx, |
| 87 | uint32_t method_idx, |
| 88 | jobject class_loader, |
| 89 | const DexFile& dex_file) const OVERRIDE; |
| 90 | |
| 91 | CompiledMethod* TryCompile(const DexFile::CodeItem* code_item, |
| 92 | uint32_t access_flags, |
| 93 | InvokeType invoke_type, |
| 94 | uint16_t class_def_idx, |
| 95 | uint32_t method_idx, |
| 96 | jobject class_loader, |
| 97 | const DexFile& dex_file) const; |
| 98 | |
| 99 | // For the following methods we will use the fallback. This is a delegation pattern. |
| 100 | CompiledMethod* JniCompile(uint32_t access_flags, |
| 101 | uint32_t method_idx, |
| 102 | const DexFile& dex_file) const OVERRIDE; |
| 103 | |
| 104 | uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const OVERRIDE |
| 105 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 106 | |
| 107 | bool WriteElf(art::File* file, |
| 108 | OatWriter* oat_writer, |
| 109 | const std::vector<const art::DexFile*>& dex_files, |
| 110 | const std::string& android_root, |
| 111 | bool is_host) const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 112 | |
| 113 | Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const OVERRIDE; |
| 114 | |
| 115 | void InitCompilationUnit(CompilationUnit& cu) const OVERRIDE; |
| 116 | |
| 117 | void Init() const OVERRIDE; |
| 118 | |
| 119 | void UnInit() const OVERRIDE; |
| 120 | |
| 121 | private: |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 122 | // Whether we should run any optimization or register allocation. If false, will |
| 123 | // just run the code generation after the graph was built. |
| 124 | const bool run_optimizations_; |
| 125 | mutable AtomicInteger total_compiled_methods_; |
| 126 | mutable AtomicInteger unoptimized_compiled_methods_; |
| 127 | mutable AtomicInteger optimized_compiled_methods_; |
| 128 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 129 | std::unique_ptr<std::ostream> visualizer_output_; |
| 130 | |
| 131 | // Delegate to another compiler in case the optimizing compiler cannot compile a method. |
| 132 | // Currently the fallback is the quick compiler. |
| 133 | std::unique_ptr<Compiler> delegate_; |
| 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompiler); |
| 136 | }; |
| 137 | |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 138 | static const int kMaximumCompilationTimeBeforeWarning = 100; /* ms */ |
| 139 | |
| 140 | OptimizingCompiler::OptimizingCompiler(CompilerDriver* driver) |
| 141 | : Compiler(driver, kMaximumCompilationTimeBeforeWarning), |
| 142 | run_optimizations_( |
| 143 | driver->GetCompilerOptions().GetCompilerFilter() != CompilerOptions::kTime), |
| 144 | total_compiled_methods_(0), |
| 145 | unoptimized_compiled_methods_(0), |
| 146 | optimized_compiled_methods_(0), |
| 147 | delegate_(Create(driver, Compiler::Kind::kQuick)) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 148 | if (kIsVisualizerEnabled) { |
| 149 | visualizer_output_.reset(new std::ofstream("art.cfg")); |
| 150 | } |
| 151 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 152 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 153 | void OptimizingCompiler::Init() const { |
| 154 | delegate_->Init(); |
| 155 | } |
| 156 | |
| 157 | void OptimizingCompiler::UnInit() const { |
| 158 | delegate_->UnInit(); |
| 159 | } |
| 160 | |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 161 | OptimizingCompiler::~OptimizingCompiler() { |
Nicolas Geoffray | ce71ae7 | 2014-09-18 11:31:32 +0100 | [diff] [blame] | 162 | if (total_compiled_methods_ == 0) { |
| 163 | LOG(INFO) << "Did not compile any method."; |
| 164 | } else { |
| 165 | size_t unoptimized_percent = (unoptimized_compiled_methods_ * 100 / total_compiled_methods_); |
| 166 | size_t optimized_percent = (optimized_compiled_methods_ * 100 / total_compiled_methods_); |
| 167 | LOG(INFO) << "Compiled " << total_compiled_methods_ << " methods: " |
| 168 | << unoptimized_percent << "% (" << unoptimized_compiled_methods_ << ") unoptimized, " |
| 169 | << optimized_percent << "% (" << optimized_compiled_methods_ << ") optimized."; |
| 170 | } |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 173 | bool OptimizingCompiler::CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, |
| 174 | CompilationUnit* cu) const { |
| 175 | return delegate_->CanCompileMethod(method_idx, dex_file, cu); |
| 176 | } |
| 177 | |
| 178 | CompiledMethod* OptimizingCompiler::JniCompile(uint32_t access_flags, |
| 179 | uint32_t method_idx, |
| 180 | const DexFile& dex_file) const { |
| 181 | return delegate_->JniCompile(access_flags, method_idx, dex_file); |
| 182 | } |
| 183 | |
| 184 | uintptr_t OptimizingCompiler::GetEntryPointOf(mirror::ArtMethod* method) const { |
| 185 | return delegate_->GetEntryPointOf(method); |
| 186 | } |
| 187 | |
| 188 | bool OptimizingCompiler::WriteElf(art::File* file, OatWriter* oat_writer, |
| 189 | const std::vector<const art::DexFile*>& dex_files, |
| 190 | const std::string& android_root, bool is_host) const { |
| 191 | return delegate_->WriteElf(file, oat_writer, dex_files, android_root, is_host); |
| 192 | } |
| 193 | |
| 194 | Backend* OptimizingCompiler::GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const { |
| 195 | return delegate_->GetCodeGenerator(cu, compilation_unit); |
| 196 | } |
| 197 | |
| 198 | void OptimizingCompiler::InitCompilationUnit(CompilationUnit& cu) const { |
| 199 | delegate_->InitCompilationUnit(cu); |
| 200 | } |
| 201 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 202 | CompiledMethod* OptimizingCompiler::TryCompile(const DexFile::CodeItem* code_item, |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 203 | uint32_t access_flags, |
| 204 | InvokeType invoke_type, |
| 205 | uint16_t class_def_idx, |
| 206 | uint32_t method_idx, |
| 207 | jobject class_loader, |
| 208 | const DexFile& dex_file) const { |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 209 | total_compiled_methods_++; |
Nicolas Geoffray | 8fb5ce3 | 2014-07-04 09:43:26 +0100 | [diff] [blame] | 210 | InstructionSet instruction_set = GetCompilerDriver()->GetInstructionSet(); |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 211 | // Always use the thumb2 assembler: some runtime functionality (like implicit stack |
| 212 | // overflow checks) assume thumb2. |
| 213 | if (instruction_set == kArm) { |
| 214 | instruction_set = kThumb2; |
Nicolas Geoffray | 8fb5ce3 | 2014-07-04 09:43:26 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // Do not attempt to compile on architectures we do not support. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 218 | if (instruction_set != kArm64 && |
| 219 | instruction_set != kThumb2 && |
| 220 | instruction_set != kX86 && |
| 221 | instruction_set != kX86_64) { |
Nicolas Geoffray | 8fb5ce3 | 2014-07-04 09:43:26 +0100 | [diff] [blame] | 222 | return nullptr; |
| 223 | } |
| 224 | |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 225 | DexCompilationUnit dex_compilation_unit( |
| 226 | nullptr, class_loader, art::Runtime::Current()->GetClassLinker(), dex_file, code_item, |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 227 | class_def_idx, method_idx, access_flags, |
| 228 | GetCompilerDriver()->GetVerifiedMethod(&dex_file, method_idx)); |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 229 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 230 | // For testing purposes, we put a special marker on method names that should be compiled |
| 231 | // with this compiler. This makes sure we're not regressing. |
| 232 | bool shouldCompile = dex_compilation_unit.GetSymbol().find("00024opt_00024") != std::string::npos; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 233 | bool shouldOptimize = |
| 234 | dex_compilation_unit.GetSymbol().find("00024reg_00024") != std::string::npos; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 235 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 236 | ArenaPool pool; |
| 237 | ArenaAllocator arena(&pool); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 238 | HGraphBuilder builder(&arena, &dex_compilation_unit, &dex_file, GetCompilerDriver()); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 239 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 240 | HGraph* graph = builder.BuildGraph(*code_item); |
| 241 | if (graph == nullptr) { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 242 | if (shouldCompile) { |
| 243 | LOG(FATAL) << "Could not build graph in optimizing compiler"; |
| 244 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 245 | return nullptr; |
| 246 | } |
| 247 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 248 | CodeGenerator* codegen = CodeGenerator::Create(&arena, graph, instruction_set); |
| 249 | if (codegen == nullptr) { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 250 | if (shouldCompile) { |
| 251 | LOG(FATAL) << "Could not find code generator for optimizing compiler"; |
| 252 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 253 | return nullptr; |
| 254 | } |
| 255 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 256 | HGraphVisualizer visualizer( |
| 257 | visualizer_output_.get(), graph, kStringFilter, *codegen, dex_compilation_unit); |
| 258 | visualizer.DumpGraph("builder"); |
| 259 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 260 | CodeVectorAllocator allocator; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 261 | |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 262 | if (run_optimizations_ && RegisterAllocator::CanAllocateRegistersFor(*graph, instruction_set)) { |
| 263 | optimized_compiled_methods_++; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 264 | graph->BuildDominatorTree(); |
| 265 | graph->TransformToSSA(); |
| 266 | visualizer.DumpGraph("ssa"); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 267 | graph->FindNaturalLoops(); |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 268 | |
Roland Levillain | 75be283 | 2014-10-17 17:02:00 +0100 | [diff] [blame] | 269 | HDeadCodeElimination(graph, visualizer).Execute(); |
| 270 | HConstantFolding(graph, visualizer).Execute(); |
| 271 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 272 | SsaRedundantPhiElimination(graph).Run(); |
| 273 | SsaDeadPhiElimination(graph).Run(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 274 | InstructionSimplifier(graph).Run(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 275 | GlobalValueNumberer(graph->GetArena(), graph).Run(); |
| 276 | visualizer.DumpGraph(kGVNPassName); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 277 | PrepareForRegisterAllocation(graph).Run(); |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 278 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 279 | SsaLivenessAnalysis liveness(*graph, codegen); |
| 280 | liveness.Analyze(); |
| 281 | visualizer.DumpGraph(kLivenessPassName); |
| 282 | |
| 283 | RegisterAllocator register_allocator(graph->GetArena(), codegen, liveness); |
| 284 | register_allocator.AllocateRegisters(); |
| 285 | |
| 286 | visualizer.DumpGraph(kRegisterAllocatorPassName); |
| 287 | codegen->CompileOptimized(&allocator); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 288 | |
| 289 | std::vector<uint8_t> mapping_table; |
| 290 | SrcMap src_mapping_table; |
| 291 | codegen->BuildMappingTable(&mapping_table, |
| 292 | GetCompilerDriver()->GetCompilerOptions().GetIncludeDebugSymbols() ? |
| 293 | &src_mapping_table : nullptr); |
| 294 | |
| 295 | std::vector<uint8_t> stack_map; |
| 296 | codegen->BuildStackMaps(&stack_map); |
| 297 | |
| 298 | return new CompiledMethod(GetCompilerDriver(), |
| 299 | instruction_set, |
| 300 | allocator.GetMemory(), |
| 301 | codegen->GetFrameSize(), |
| 302 | codegen->GetCoreSpillMask(), |
| 303 | 0, /* FPR spill mask, unused */ |
| 304 | mapping_table, |
| 305 | stack_map); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 306 | } else if (shouldOptimize && RegisterAllocator::Supports(instruction_set)) { |
| 307 | LOG(FATAL) << "Could not allocate registers in optimizing compiler"; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 308 | return nullptr; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 309 | } else { |
Nicolas Geoffray | 88157ef | 2014-09-12 10:29:53 +0100 | [diff] [blame] | 310 | unoptimized_compiled_methods_++; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 311 | codegen->CompileBaseline(&allocator); |
| 312 | |
| 313 | // Run these phases to get some test coverage. |
| 314 | graph->BuildDominatorTree(); |
| 315 | graph->TransformToSSA(); |
| 316 | visualizer.DumpGraph("ssa"); |
| 317 | graph->FindNaturalLoops(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 318 | SsaRedundantPhiElimination(graph).Run(); |
| 319 | SsaDeadPhiElimination(graph).Run(); |
| 320 | GlobalValueNumberer(graph->GetArena(), graph).Run(); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 321 | SsaLivenessAnalysis liveness(*graph, codegen); |
| 322 | liveness.Analyze(); |
| 323 | visualizer.DumpGraph(kLivenessPassName); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 324 | |
| 325 | std::vector<uint8_t> mapping_table; |
| 326 | SrcMap src_mapping_table; |
| 327 | codegen->BuildMappingTable(&mapping_table, |
| 328 | GetCompilerDriver()->GetCompilerOptions().GetIncludeDebugSymbols() ? |
| 329 | &src_mapping_table : nullptr); |
| 330 | std::vector<uint8_t> vmap_table; |
| 331 | codegen->BuildVMapTable(&vmap_table); |
| 332 | std::vector<uint8_t> gc_map; |
| 333 | codegen->BuildNativeGCMap(&gc_map, dex_compilation_unit); |
| 334 | |
| 335 | return new CompiledMethod(GetCompilerDriver(), |
| 336 | instruction_set, |
| 337 | allocator.GetMemory(), |
| 338 | codegen->GetFrameSize(), |
| 339 | codegen->GetCoreSpillMask(), |
| 340 | 0, /* FPR spill mask, unused */ |
| 341 | &src_mapping_table, |
| 342 | mapping_table, |
| 343 | vmap_table, |
| 344 | gc_map, |
| 345 | nullptr); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 346 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 349 | CompiledMethod* OptimizingCompiler::Compile(const DexFile::CodeItem* code_item, |
| 350 | uint32_t access_flags, |
| 351 | InvokeType invoke_type, |
| 352 | uint16_t class_def_idx, |
| 353 | uint32_t method_idx, |
| 354 | jobject class_loader, |
| 355 | const DexFile& dex_file) const { |
| 356 | CompiledMethod* method = TryCompile(code_item, access_flags, invoke_type, class_def_idx, |
| 357 | method_idx, class_loader, dex_file); |
| 358 | if (method != nullptr) { |
| 359 | return method; |
| 360 | } |
| 361 | |
| 362 | return delegate_->Compile(code_item, access_flags, invoke_type, class_def_idx, method_idx, |
| 363 | class_loader, dex_file); |
| 364 | } |
| 365 | |
| 366 | Compiler* CreateOptimizingCompiler(CompilerDriver* driver) { |
| 367 | return new OptimizingCompiler(driver); |
| 368 | } |
| 369 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 370 | } // namespace art |