| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +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 | |
| 17 | #include "code_generator.h" |
| 18 | |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 19 | #ifdef ART_ENABLE_CODEGEN_arm |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 20 | #include "code_generator_arm.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 24 | #include "code_generator_arm64.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 25 | #endif |
| 26 | |
| 27 | #ifdef ART_ENABLE_CODEGEN_x86 |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | #include "code_generator_x86.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #ifdef ART_ENABLE_CODEGEN_x86_64 |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "code_generator_x86_64.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | #ifdef ART_ENABLE_CODEGEN_mips64 |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 36 | #include "code_generator_mips64.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 37 | #endif |
| 38 | |
| Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 39 | #include "compiled_method.h" |
| Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 40 | #include "dex/verified_method.h" |
| 41 | #include "driver/dex_compilation_unit.h" |
| 42 | #include "gc_map_builder.h" |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 43 | #include "graph_visualizer.h" |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 44 | #include "leb128.h" |
| 45 | #include "mapping_table.h" |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 46 | #include "mirror/array-inl.h" |
| 47 | #include "mirror/object_array-inl.h" |
| 48 | #include "mirror/object_reference.h" |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 49 | #include "parallel_move_resolver.h" |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 50 | #include "ssa_liveness_analysis.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 51 | #include "utils/assembler.h" |
| Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 52 | #include "verifier/dex_gc_map.h" |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 53 | #include "vmap_table.h" |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 54 | |
| 55 | namespace art { |
| 56 | |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 57 | // Return whether a location is consistent with a type. |
| 58 | static bool CheckType(Primitive::Type type, Location location) { |
| 59 | if (location.IsFpuRegister() |
| 60 | || (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresFpuRegister))) { |
| 61 | return (type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble); |
| 62 | } else if (location.IsRegister() || |
| 63 | (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresRegister))) { |
| 64 | return Primitive::IsIntegralType(type) || (type == Primitive::kPrimNot); |
| 65 | } else if (location.IsRegisterPair()) { |
| 66 | return type == Primitive::kPrimLong; |
| 67 | } else if (location.IsFpuRegisterPair()) { |
| 68 | return type == Primitive::kPrimDouble; |
| 69 | } else if (location.IsStackSlot()) { |
| 70 | return (Primitive::IsIntegralType(type) && type != Primitive::kPrimLong) |
| 71 | || (type == Primitive::kPrimFloat) |
| 72 | || (type == Primitive::kPrimNot); |
| 73 | } else if (location.IsDoubleStackSlot()) { |
| 74 | return (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 75 | } else if (location.IsConstant()) { |
| 76 | if (location.GetConstant()->IsIntConstant()) { |
| 77 | return Primitive::IsIntegralType(type) && (type != Primitive::kPrimLong); |
| 78 | } else if (location.GetConstant()->IsNullConstant()) { |
| 79 | return type == Primitive::kPrimNot; |
| 80 | } else if (location.GetConstant()->IsLongConstant()) { |
| 81 | return type == Primitive::kPrimLong; |
| 82 | } else if (location.GetConstant()->IsFloatConstant()) { |
| 83 | return type == Primitive::kPrimFloat; |
| 84 | } else { |
| 85 | return location.GetConstant()->IsDoubleConstant() |
| 86 | && (type == Primitive::kPrimDouble); |
| 87 | } |
| 88 | } else { |
| 89 | return location.IsInvalid() || (location.GetPolicy() == Location::kAny); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Check that a location summary is consistent with an instruction. |
| 94 | static bool CheckTypeConsistency(HInstruction* instruction) { |
| 95 | LocationSummary* locations = instruction->GetLocations(); |
| 96 | if (locations == nullptr) { |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | if (locations->Out().IsUnallocated() |
| 101 | && (locations->Out().GetPolicy() == Location::kSameAsFirstInput)) { |
| 102 | DCHECK(CheckType(instruction->GetType(), locations->InAt(0))) |
| 103 | << instruction->GetType() |
| 104 | << " " << locations->InAt(0); |
| 105 | } else { |
| 106 | DCHECK(CheckType(instruction->GetType(), locations->Out())) |
| 107 | << instruction->GetType() |
| 108 | << " " << locations->Out(); |
| 109 | } |
| 110 | |
| 111 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 112 | DCHECK(CheckType(instruction->InputAt(i)->GetType(), locations->InAt(i))) |
| 113 | << instruction->InputAt(i)->GetType() |
| 114 | << " " << locations->InAt(i); |
| 115 | } |
| 116 | |
| 117 | HEnvironment* environment = instruction->GetEnvironment(); |
| 118 | for (size_t i = 0; i < instruction->EnvironmentSize(); ++i) { |
| 119 | if (environment->GetInstructionAt(i) != nullptr) { |
| 120 | Primitive::Type type = environment->GetInstructionAt(i)->GetType(); |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 121 | DCHECK(CheckType(type, environment->GetLocationAt(i))) |
| 122 | << type << " " << environment->GetLocationAt(i); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 123 | } else { |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 124 | DCHECK(environment->GetLocationAt(i).IsInvalid()) |
| 125 | << environment->GetLocationAt(i); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | return true; |
| 129 | } |
| 130 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 131 | size_t CodeGenerator::GetCacheOffset(uint32_t index) { |
| 132 | return mirror::ObjectArray<mirror::Object>::OffsetOfElement(index).SizeValue(); |
| 133 | } |
| 134 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 135 | size_t CodeGenerator::GetCachePointerOffset(uint32_t index) { |
| 136 | auto pointer_size = InstructionSetPointerSize(GetInstructionSet()); |
| 137 | return mirror::Array::DataOffset(pointer_size).Uint32Value() + pointer_size * index; |
| 138 | } |
| 139 | |
| Nicolas Geoffray | 73e80c3 | 2014-07-22 17:47:56 +0100 | [diff] [blame] | 140 | void CodeGenerator::CompileBaseline(CodeAllocator* allocator, bool is_leaf) { |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 141 | Initialize(); |
| Nicolas Geoffray | 73e80c3 | 2014-07-22 17:47:56 +0100 | [diff] [blame] | 142 | if (!is_leaf) { |
| 143 | MarkNotLeaf(); |
| 144 | } |
| Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 145 | const bool is_64_bit = Is64BitInstructionSet(GetInstructionSet()); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 146 | InitializeCodeGeneration(GetGraph()->GetNumberOfLocalVRegs() |
| 147 | + GetGraph()->GetTemporariesVRegSlots() |
| 148 | + 1 /* filler */, |
| 149 | 0, /* the baseline compiler does not have live registers at slow path */ |
| 150 | 0, /* the baseline compiler does not have live registers at slow path */ |
| 151 | GetGraph()->GetMaximumNumberOfOutVRegs() |
| Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 152 | + (is_64_bit ? 2 : 1) /* current method */, |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 153 | GetGraph()->GetBlocks()); |
| 154 | CompileInternal(allocator, /* is_baseline */ true); |
| 155 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 156 | |
| Nicolas Geoffray | dc23d83 | 2015-02-16 11:15:43 +0000 | [diff] [blame] | 157 | bool CodeGenerator::GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const { |
| 158 | DCHECK_EQ(block_order_->Get(current_block_index_), current); |
| 159 | return GetNextBlockToEmit() == FirstNonEmptyBlock(next); |
| 160 | } |
| 161 | |
| 162 | HBasicBlock* CodeGenerator::GetNextBlockToEmit() const { |
| 163 | for (size_t i = current_block_index_ + 1; i < block_order_->Size(); ++i) { |
| 164 | HBasicBlock* block = block_order_->Get(i); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 165 | if (!block->IsSingleJump()) { |
| Nicolas Geoffray | dc23d83 | 2015-02-16 11:15:43 +0000 | [diff] [blame] | 166 | return block; |
| 167 | } |
| 168 | } |
| 169 | return nullptr; |
| 170 | } |
| 171 | |
| 172 | HBasicBlock* CodeGenerator::FirstNonEmptyBlock(HBasicBlock* block) const { |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 173 | while (block->IsSingleJump()) { |
| Nicolas Geoffray | dc23d83 | 2015-02-16 11:15:43 +0000 | [diff] [blame] | 174 | block = block->GetSuccessors().Get(0); |
| 175 | } |
| 176 | return block; |
| 177 | } |
| 178 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 179 | class DisassemblyScope { |
| 180 | public: |
| 181 | DisassemblyScope(HInstruction* instruction, const CodeGenerator& codegen) |
| 182 | : codegen_(codegen), instruction_(instruction), start_offset_(static_cast<size_t>(-1)) { |
| 183 | if (codegen_.GetDisassemblyInformation() != nullptr) { |
| 184 | start_offset_ = codegen_.GetAssembler().CodeSize(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | ~DisassemblyScope() { |
| 189 | // We avoid building this data when we know it will not be used. |
| 190 | if (codegen_.GetDisassemblyInformation() != nullptr) { |
| 191 | codegen_.GetDisassemblyInformation()->AddInstructionInterval( |
| 192 | instruction_, start_offset_, codegen_.GetAssembler().CodeSize()); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | private: |
| 197 | const CodeGenerator& codegen_; |
| 198 | HInstruction* instruction_; |
| 199 | size_t start_offset_; |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | void CodeGenerator::GenerateSlowPaths() { |
| 204 | size_t code_start = 0; |
| 205 | for (size_t i = 0, e = slow_paths_.Size(); i < e; ++i) { |
| 206 | if (disasm_info_ != nullptr) { |
| 207 | code_start = GetAssembler()->CodeSize(); |
| 208 | } |
| 209 | slow_paths_.Get(i)->EmitNativeCode(this); |
| 210 | if (disasm_info_ != nullptr) { |
| 211 | disasm_info_->AddSlowPathInterval(slow_paths_.Get(i), code_start, GetAssembler()->CodeSize()); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 216 | void CodeGenerator::CompileInternal(CodeAllocator* allocator, bool is_baseline) { |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 217 | is_baseline_ = is_baseline; |
| Nicolas Geoffray | 8a16d97 | 2014-09-11 10:30:02 +0100 | [diff] [blame] | 218 | HGraphVisitor* instruction_visitor = GetInstructionVisitor(); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 219 | DCHECK_EQ(current_block_index_, 0u); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 220 | |
| 221 | size_t frame_start = GetAssembler()->CodeSize(); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 222 | GenerateFrameEntry(); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 223 | DCHECK_EQ(GetAssembler()->cfi().GetCurrentCFAOffset(), static_cast<int>(frame_size_)); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 224 | if (disasm_info_ != nullptr) { |
| 225 | disasm_info_->SetFrameEntryInterval(frame_start, GetAssembler()->CodeSize()); |
| 226 | } |
| 227 | |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 228 | for (size_t e = block_order_->Size(); current_block_index_ < e; ++current_block_index_) { |
| 229 | HBasicBlock* block = block_order_->Get(current_block_index_); |
| Nicolas Geoffray | dc23d83 | 2015-02-16 11:15:43 +0000 | [diff] [blame] | 230 | // Don't generate code for an empty block. Its predecessors will branch to its successor |
| 231 | // directly. Also, the label of that block will not be emitted, so this helps catch |
| 232 | // errors where we reference that label. |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 233 | if (block->IsSingleJump()) continue; |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 234 | Bind(block); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 235 | for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
| 236 | HInstruction* current = it.Current(); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 237 | DisassemblyScope disassembly_scope(current, *this); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 238 | if (is_baseline) { |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 239 | InitLocationsBaseline(current); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 240 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 241 | DCHECK(CheckTypeConsistency(current)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 242 | current->Accept(instruction_visitor); |
| 243 | } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 244 | } |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 245 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | GenerateSlowPaths(); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 247 | |
| 248 | // Finalize instructions in assember; |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 249 | Finalize(allocator); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 252 | void CodeGenerator::CompileOptimized(CodeAllocator* allocator) { |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 253 | // The register allocator already called `InitializeCodeGeneration`, |
| 254 | // where the frame size has been computed. |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 255 | DCHECK(block_order_ != nullptr); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 256 | Initialize(); |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 257 | CompileInternal(allocator, /* is_baseline */ false); |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 258 | } |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 259 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 260 | void CodeGenerator::Finalize(CodeAllocator* allocator) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 261 | size_t code_size = GetAssembler()->CodeSize(); |
| 262 | uint8_t* buffer = allocator->Allocate(code_size); |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 263 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 264 | MemoryRegion code(buffer, code_size); |
| 265 | GetAssembler()->FinalizeInstructions(code); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 268 | void CodeGenerator::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches ATTRIBUTE_UNUSED) { |
| 269 | // No linker patches by default. |
| 270 | } |
| 271 | |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 272 | size_t CodeGenerator::FindFreeEntry(bool* array, size_t length) { |
| 273 | for (size_t i = 0; i < length; ++i) { |
| 274 | if (!array[i]) { |
| 275 | array[i] = true; |
| 276 | return i; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 277 | } |
| 278 | } |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 279 | LOG(FATAL) << "Could not find a register in baseline register allocator"; |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 280 | UNREACHABLE(); |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| Nicolas Geoffray | 3c03503 | 2014-10-28 10:46:40 +0000 | [diff] [blame] | 283 | size_t CodeGenerator::FindTwoFreeConsecutiveAlignedEntries(bool* array, size_t length) { |
| 284 | for (size_t i = 0; i < length - 1; i += 2) { |
| Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 285 | if (!array[i] && !array[i + 1]) { |
| 286 | array[i] = true; |
| 287 | array[i + 1] = true; |
| 288 | return i; |
| 289 | } |
| 290 | } |
| 291 | LOG(FATAL) << "Could not find a register in baseline register allocator"; |
| 292 | UNREACHABLE(); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| Nicolas Geoffray | 4c204ba | 2015-02-03 15:12:35 +0000 | [diff] [blame] | 295 | void CodeGenerator::InitializeCodeGeneration(size_t number_of_spill_slots, |
| 296 | size_t maximum_number_of_live_core_registers, |
| 297 | size_t maximum_number_of_live_fp_registers, |
| 298 | size_t number_of_out_slots, |
| 299 | const GrowableArray<HBasicBlock*>& block_order) { |
| 300 | block_order_ = &block_order; |
| 301 | DCHECK(block_order_->Get(0) == GetGraph()->GetEntryBlock()); |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 302 | ComputeSpillMask(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 303 | first_register_slot_in_slow_path_ = (number_of_out_slots + number_of_spill_slots) * kVRegSize; |
| 304 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 305 | if (number_of_spill_slots == 0 |
| 306 | && !HasAllocatedCalleeSaveRegisters() |
| 307 | && IsLeafMethod() |
| 308 | && !RequiresCurrentMethod()) { |
| 309 | DCHECK_EQ(maximum_number_of_live_core_registers, 0u); |
| 310 | DCHECK_EQ(maximum_number_of_live_fp_registers, 0u); |
| 311 | SetFrameSize(CallPushesPC() ? GetWordSize() : 0); |
| 312 | } else { |
| 313 | SetFrameSize(RoundUp( |
| 314 | number_of_spill_slots * kVRegSize |
| 315 | + number_of_out_slots * kVRegSize |
| 316 | + maximum_number_of_live_core_registers * GetWordSize() |
| 317 | + maximum_number_of_live_fp_registers * GetFloatingPointSpillSlotSize() |
| 318 | + FrameEntrySpillSize(), |
| 319 | kStackAlignment)); |
| 320 | } |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | Location CodeGenerator::GetTemporaryLocation(HTemporary* temp) const { |
| 324 | uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs(); |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 325 | // The type of the previous instruction tells us if we need a single or double stack slot. |
| 326 | Primitive::Type type = temp->GetType(); |
| 327 | int32_t temp_size = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble) ? 2 : 1; |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 328 | // Use the temporary region (right below the dex registers). |
| 329 | int32_t slot = GetFrameSize() - FrameEntrySpillSize() |
| 330 | - kVRegSize // filler |
| 331 | - (number_of_locals * kVRegSize) |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 332 | - ((temp_size + temp->GetIndex()) * kVRegSize); |
| 333 | return temp_size == 2 ? Location::DoubleStackSlot(slot) : Location::StackSlot(slot); |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | int32_t CodeGenerator::GetStackSlot(HLocal* local) const { |
| 337 | uint16_t reg_number = local->GetRegNumber(); |
| 338 | uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs(); |
| 339 | if (reg_number >= number_of_locals) { |
| 340 | // Local is a parameter of the method. It is stored in the caller's frame. |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 341 | // TODO: Share this logic with StackVisitor::GetVRegOffsetFromQuickCode. |
| 342 | return GetFrameSize() + InstructionSetPointerSize(GetInstructionSet()) // ART method |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 343 | + (reg_number - number_of_locals) * kVRegSize; |
| 344 | } else { |
| 345 | // Local is a temporary in this method. It is stored in this method's frame. |
| 346 | return GetFrameSize() - FrameEntrySpillSize() |
| 347 | - kVRegSize // filler. |
| 348 | - (number_of_locals * kVRegSize) |
| 349 | + (reg_number * kVRegSize); |
| 350 | } |
| 351 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 352 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 353 | void CodeGenerator::CreateCommonInvokeLocationSummary( |
| Nicolas Geoffray | 4e40c26 | 2015-06-03 12:02:38 +0100 | [diff] [blame] | 354 | HInvoke* invoke, InvokeDexCallingConventionVisitor* visitor) { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 355 | ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena(); |
| 356 | LocationSummary* locations = new (allocator) LocationSummary(invoke, LocationSummary::kCall); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 357 | |
| 358 | for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) { |
| 359 | HInstruction* input = invoke->InputAt(i); |
| 360 | locations->SetInAt(i, visitor->GetNextLocation(input->GetType())); |
| 361 | } |
| 362 | |
| 363 | locations->SetOut(visitor->GetReturnLocation(invoke->GetType())); |
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 364 | |
| 365 | if (invoke->IsInvokeStaticOrDirect()) { |
| 366 | HInvokeStaticOrDirect* call = invoke->AsInvokeStaticOrDirect(); |
| 367 | if (call->IsStringInit()) { |
| 368 | locations->AddTemp(visitor->GetMethodLocation()); |
| 369 | } else if (call->IsRecursive()) { |
| 370 | locations->SetInAt(call->GetCurrentMethodInputIndex(), visitor->GetMethodLocation()); |
| 371 | } else { |
| 372 | locations->AddTemp(visitor->GetMethodLocation()); |
| 373 | locations->SetInAt(call->GetCurrentMethodInputIndex(), Location::RequiresRegister()); |
| 374 | } |
| 375 | } else { |
| 376 | locations->AddTemp(visitor->GetMethodLocation()); |
| 377 | } |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 378 | } |
| 379 | |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 380 | void CodeGenerator::BlockIfInRegister(Location location, bool is_out) const { |
| 381 | // The DCHECKS below check that a register is not specified twice in |
| 382 | // the summary. The out location can overlap with an input, so we need |
| 383 | // to special case it. |
| 384 | if (location.IsRegister()) { |
| 385 | DCHECK(is_out || !blocked_core_registers_[location.reg()]); |
| 386 | blocked_core_registers_[location.reg()] = true; |
| 387 | } else if (location.IsFpuRegister()) { |
| 388 | DCHECK(is_out || !blocked_fpu_registers_[location.reg()]); |
| 389 | blocked_fpu_registers_[location.reg()] = true; |
| 390 | } else if (location.IsFpuRegisterPair()) { |
| 391 | DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()]); |
| 392 | blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()] = true; |
| 393 | DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()]); |
| 394 | blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()] = true; |
| 395 | } else if (location.IsRegisterPair()) { |
| 396 | DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairLow<int>()]); |
| 397 | blocked_core_registers_[location.AsRegisterPairLow<int>()] = true; |
| 398 | DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairHigh<int>()]); |
| 399 | blocked_core_registers_[location.AsRegisterPairHigh<int>()] = true; |
| 400 | } |
| 401 | } |
| 402 | |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 403 | void CodeGenerator::AllocateRegistersLocally(HInstruction* instruction) const { |
| 404 | LocationSummary* locations = instruction->GetLocations(); |
| 405 | if (locations == nullptr) return; |
| 406 | |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 407 | for (size_t i = 0, e = GetNumberOfCoreRegisters(); i < e; ++i) { |
| 408 | blocked_core_registers_[i] = false; |
| 409 | } |
| 410 | |
| 411 | for (size_t i = 0, e = GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 412 | blocked_fpu_registers_[i] = false; |
| 413 | } |
| 414 | |
| 415 | for (size_t i = 0, e = number_of_register_pairs_; i < e; ++i) { |
| 416 | blocked_register_pairs_[i] = false; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | // Mark all fixed input, temp and output registers as used. |
| 420 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 421 | BlockIfInRegister(locations->InAt(i)); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) { |
| 425 | Location loc = locations->GetTemp(i); |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 426 | BlockIfInRegister(loc); |
| 427 | } |
| 428 | Location result_location = locations->Out(); |
| 429 | if (locations->OutputCanOverlapWithInputs()) { |
| 430 | BlockIfInRegister(result_location, /* is_out */ true); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 433 | SetupBlockedRegisters(/* is_baseline */ true); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 434 | |
| 435 | // Allocate all unallocated input locations. |
| 436 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 437 | Location loc = locations->InAt(i); |
| 438 | HInstruction* input = instruction->InputAt(i); |
| 439 | if (loc.IsUnallocated()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 440 | if ((loc.GetPolicy() == Location::kRequiresRegister) |
| 441 | || (loc.GetPolicy() == Location::kRequiresFpuRegister)) { |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 442 | loc = AllocateFreeRegister(input->GetType()); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 443 | } else { |
| 444 | DCHECK_EQ(loc.GetPolicy(), Location::kAny); |
| 445 | HLoadLocal* load = input->AsLoadLocal(); |
| 446 | if (load != nullptr) { |
| 447 | loc = GetStackLocation(load); |
| 448 | } else { |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 449 | loc = AllocateFreeRegister(input->GetType()); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | locations->SetInAt(i, loc); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | // Allocate all unallocated temp locations. |
| 457 | for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) { |
| 458 | Location loc = locations->GetTemp(i); |
| 459 | if (loc.IsUnallocated()) { |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 460 | switch (loc.GetPolicy()) { |
| 461 | case Location::kRequiresRegister: |
| 462 | // Allocate a core register (large enough to fit a 32-bit integer). |
| 463 | loc = AllocateFreeRegister(Primitive::kPrimInt); |
| 464 | break; |
| 465 | |
| 466 | case Location::kRequiresFpuRegister: |
| 467 | // Allocate a core register (large enough to fit a 64-bit double). |
| 468 | loc = AllocateFreeRegister(Primitive::kPrimDouble); |
| 469 | break; |
| 470 | |
| 471 | default: |
| 472 | LOG(FATAL) << "Unexpected policy for temporary location " |
| 473 | << loc.GetPolicy(); |
| 474 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 475 | locations->SetTempAt(i, loc); |
| 476 | } |
| 477 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 478 | if (result_location.IsUnallocated()) { |
| 479 | switch (result_location.GetPolicy()) { |
| 480 | case Location::kAny: |
| 481 | case Location::kRequiresRegister: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 482 | case Location::kRequiresFpuRegister: |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 483 | result_location = AllocateFreeRegister(instruction->GetType()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 484 | break; |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 485 | case Location::kSameAsFirstInput: |
| 486 | result_location = locations->InAt(0); |
| 487 | break; |
| 488 | } |
| Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 489 | locations->UpdateOut(result_location); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 493 | void CodeGenerator::InitLocationsBaseline(HInstruction* instruction) { |
| 494 | AllocateLocations(instruction); |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 495 | if (instruction->GetLocations() == nullptr) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 496 | if (instruction->IsTemporary()) { |
| 497 | HInstruction* previous = instruction->GetPrevious(); |
| 498 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 499 | Move(previous, temp_location, instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 500 | } |
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 501 | return; |
| 502 | } |
| 503 | AllocateRegistersLocally(instruction); |
| 504 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 505 | Location location = instruction->GetLocations()->InAt(i); |
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 506 | HInstruction* input = instruction->InputAt(i); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 507 | if (location.IsValid()) { |
| 508 | // Move the input to the desired location. |
| Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 509 | if (input->GetNext()->IsTemporary()) { |
| 510 | // If the input was stored in a temporary, use that temporary to |
| 511 | // perform the move. |
| 512 | Move(input->GetNext(), location, instruction); |
| 513 | } else { |
| 514 | Move(input, location, instruction); |
| 515 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 520 | void CodeGenerator::AllocateLocations(HInstruction* instruction) { |
| 521 | instruction->Accept(GetLocationBuilder()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 522 | DCHECK(CheckTypeConsistency(instruction)); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 523 | LocationSummary* locations = instruction->GetLocations(); |
| 524 | if (!instruction->IsSuspendCheckEntry()) { |
| 525 | if (locations != nullptr && locations->CanCall()) { |
| 526 | MarkNotLeaf(); |
| 527 | } |
| 528 | if (instruction->NeedsCurrentMethod()) { |
| 529 | SetRequiresCurrentMethod(); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 534 | void CodeGenerator::MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count) const { |
| 535 | if (stats_ != nullptr) { |
| 536 | stats_->RecordStat(compilation_stat, count); |
| 537 | } |
| 538 | } |
| 539 | |
| Nicolas Geoffray | 12df9eb | 2015-01-09 14:53:50 +0000 | [diff] [blame] | 540 | CodeGenerator* CodeGenerator::Create(HGraph* graph, |
| Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 541 | InstructionSet instruction_set, |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 542 | const InstructionSetFeatures& isa_features, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 543 | const CompilerOptions& compiler_options, |
| 544 | OptimizingCompilerStats* stats) { |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 545 | switch (instruction_set) { |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 546 | #ifdef ART_ENABLE_CODEGEN_arm |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 547 | case kArm: |
| 548 | case kThumb2: { |
| Nicolas Geoffray | 12df9eb | 2015-01-09 14:53:50 +0000 | [diff] [blame] | 549 | return new arm::CodeGeneratorARM(graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 550 | *isa_features.AsArmInstructionSetFeatures(), |
| 551 | compiler_options, |
| 552 | stats); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 553 | } |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 554 | #endif |
| 555 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 556 | case kArm64: { |
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 557 | return new arm64::CodeGeneratorARM64(graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 558 | *isa_features.AsArm64InstructionSetFeatures(), |
| 559 | compiler_options, |
| 560 | stats); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 561 | } |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 562 | #endif |
| 563 | #ifdef ART_ENABLE_CODEGEN_mips |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 564 | case kMips: |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 565 | UNUSED(compiler_options); |
| 566 | UNUSED(graph); |
| 567 | UNUSED(isa_features); |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 568 | return nullptr; |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 569 | #endif |
| 570 | #ifdef ART_ENABLE_CODEGEN_mips64 |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 571 | case kMips64: { |
| 572 | return new mips64::CodeGeneratorMIPS64(graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 573 | *isa_features.AsMips64InstructionSetFeatures(), |
| 574 | compiler_options, |
| 575 | stats); |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 576 | } |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 577 | #endif |
| 578 | #ifdef ART_ENABLE_CODEGEN_x86 |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 579 | case kX86: { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 580 | return new x86::CodeGeneratorX86(graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 581 | *isa_features.AsX86InstructionSetFeatures(), |
| 582 | compiler_options, |
| 583 | stats); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 584 | } |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 585 | #endif |
| 586 | #ifdef ART_ENABLE_CODEGEN_x86_64 |
| Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 587 | case kX86_64: { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 588 | return new x86_64::CodeGeneratorX86_64(graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame^] | 589 | *isa_features.AsX86_64InstructionSetFeatures(), |
| 590 | compiler_options, |
| 591 | stats); |
| Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 592 | } |
| Alex Light | 50fa993 | 2015-08-10 15:30:07 -0700 | [diff] [blame] | 593 | #endif |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 594 | default: |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 595 | return nullptr; |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
| Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 599 | void CodeGenerator::BuildNativeGCMap( |
| 600 | std::vector<uint8_t>* data, const DexCompilationUnit& dex_compilation_unit) const { |
| 601 | const std::vector<uint8_t>& gc_map_raw = |
| 602 | dex_compilation_unit.GetVerifiedMethod()->GetDexGcMap(); |
| 603 | verifier::DexPcToReferenceMap dex_gc_map(&(gc_map_raw)[0]); |
| 604 | |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 605 | uint32_t max_native_offset = stack_map_stream_.ComputeMaxNativePcOffset(); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 606 | |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 607 | size_t num_stack_maps = stack_map_stream_.GetNumberOfStackMaps(); |
| 608 | GcMapBuilder builder(data, num_stack_maps, max_native_offset, dex_gc_map.RegWidth()); |
| 609 | for (size_t i = 0; i != num_stack_maps; ++i) { |
| 610 | const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i); |
| 611 | uint32_t native_offset = stack_map_entry.native_pc_offset; |
| 612 | uint32_t dex_pc = stack_map_entry.dex_pc; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 613 | const uint8_t* references = dex_gc_map.FindBitMap(dex_pc, false); |
| Jean Christophe Beyler | 0ada95d | 2014-12-04 11:20:20 -0800 | [diff] [blame] | 614 | CHECK(references != nullptr) << "Missing ref for dex pc 0x" << std::hex << dex_pc; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 615 | builder.AddEntry(native_offset, references); |
| 616 | } |
| Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 619 | void CodeGenerator::BuildSourceMap(DefaultSrcMap* src_map) const { |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 620 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
| 621 | const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i); |
| 622 | uint32_t pc2dex_offset = stack_map_entry.native_pc_offset; |
| 623 | int32_t pc2dex_dalvik_offset = stack_map_entry.dex_pc; |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 624 | src_map->push_back(SrcMapElem({pc2dex_offset, pc2dex_dalvik_offset})); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | void CodeGenerator::BuildMappingTable(std::vector<uint8_t>* data) const { |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 629 | uint32_t pc2dex_data_size = 0u; |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 630 | uint32_t pc2dex_entries = stack_map_stream_.GetNumberOfStackMaps(); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 631 | uint32_t pc2dex_offset = 0u; |
| 632 | int32_t pc2dex_dalvik_offset = 0; |
| 633 | uint32_t dex2pc_data_size = 0u; |
| 634 | uint32_t dex2pc_entries = 0u; |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 635 | uint32_t dex2pc_offset = 0u; |
| 636 | int32_t dex2pc_dalvik_offset = 0; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 637 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 638 | for (size_t i = 0; i < pc2dex_entries; i++) { |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 639 | const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i); |
| 640 | pc2dex_data_size += UnsignedLeb128Size(stack_map_entry.native_pc_offset - pc2dex_offset); |
| 641 | pc2dex_data_size += SignedLeb128Size(stack_map_entry.dex_pc - pc2dex_dalvik_offset); |
| 642 | pc2dex_offset = stack_map_entry.native_pc_offset; |
| 643 | pc2dex_dalvik_offset = stack_map_entry.dex_pc; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 646 | // Walk over the blocks and find which ones correspond to catch block entries. |
| 647 | for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) { |
| 648 | HBasicBlock* block = graph_->GetBlocks().Get(i); |
| 649 | if (block->IsCatchBlock()) { |
| 650 | intptr_t native_pc = GetAddressOf(block); |
| 651 | ++dex2pc_entries; |
| 652 | dex2pc_data_size += UnsignedLeb128Size(native_pc - dex2pc_offset); |
| 653 | dex2pc_data_size += SignedLeb128Size(block->GetDexPc() - dex2pc_dalvik_offset); |
| 654 | dex2pc_offset = native_pc; |
| 655 | dex2pc_dalvik_offset = block->GetDexPc(); |
| 656 | } |
| 657 | } |
| 658 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 659 | uint32_t total_entries = pc2dex_entries + dex2pc_entries; |
| 660 | uint32_t hdr_data_size = UnsignedLeb128Size(total_entries) + UnsignedLeb128Size(pc2dex_entries); |
| 661 | uint32_t data_size = hdr_data_size + pc2dex_data_size + dex2pc_data_size; |
| 662 | data->resize(data_size); |
| 663 | |
| 664 | uint8_t* data_ptr = &(*data)[0]; |
| 665 | uint8_t* write_pos = data_ptr; |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 666 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 667 | write_pos = EncodeUnsignedLeb128(write_pos, total_entries); |
| 668 | write_pos = EncodeUnsignedLeb128(write_pos, pc2dex_entries); |
| 669 | DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size); |
| 670 | uint8_t* write_pos2 = write_pos + pc2dex_data_size; |
| 671 | |
| 672 | pc2dex_offset = 0u; |
| 673 | pc2dex_dalvik_offset = 0u; |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 674 | dex2pc_offset = 0u; |
| 675 | dex2pc_dalvik_offset = 0u; |
| 676 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 677 | for (size_t i = 0; i < pc2dex_entries; i++) { |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 678 | const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i); |
| 679 | DCHECK(pc2dex_offset <= stack_map_entry.native_pc_offset); |
| 680 | write_pos = EncodeUnsignedLeb128(write_pos, stack_map_entry.native_pc_offset - pc2dex_offset); |
| 681 | write_pos = EncodeSignedLeb128(write_pos, stack_map_entry.dex_pc - pc2dex_dalvik_offset); |
| 682 | pc2dex_offset = stack_map_entry.native_pc_offset; |
| 683 | pc2dex_dalvik_offset = stack_map_entry.dex_pc; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 684 | } |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 685 | |
| 686 | for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) { |
| 687 | HBasicBlock* block = graph_->GetBlocks().Get(i); |
| 688 | if (block->IsCatchBlock()) { |
| 689 | intptr_t native_pc = GetAddressOf(block); |
| 690 | write_pos2 = EncodeUnsignedLeb128(write_pos2, native_pc - dex2pc_offset); |
| 691 | write_pos2 = EncodeSignedLeb128(write_pos2, block->GetDexPc() - dex2pc_dalvik_offset); |
| 692 | dex2pc_offset = native_pc; |
| 693 | dex2pc_dalvik_offset = block->GetDexPc(); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 698 | DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size + pc2dex_data_size); |
| 699 | DCHECK_EQ(static_cast<size_t>(write_pos2 - data_ptr), data_size); |
| 700 | |
| 701 | if (kIsDebugBuild) { |
| 702 | // Verify the encoded table holds the expected data. |
| 703 | MappingTable table(data_ptr); |
| 704 | CHECK_EQ(table.TotalSize(), total_entries); |
| 705 | CHECK_EQ(table.PcToDexSize(), pc2dex_entries); |
| 706 | auto it = table.PcToDexBegin(); |
| 707 | auto it2 = table.DexToPcBegin(); |
| 708 | for (size_t i = 0; i < pc2dex_entries; i++) { |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 709 | const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i); |
| 710 | CHECK_EQ(stack_map_entry.native_pc_offset, it.NativePcOffset()); |
| 711 | CHECK_EQ(stack_map_entry.dex_pc, it.DexPc()); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 712 | ++it; |
| 713 | } |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 714 | for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) { |
| 715 | HBasicBlock* block = graph_->GetBlocks().Get(i); |
| 716 | if (block->IsCatchBlock()) { |
| 717 | CHECK_EQ(GetAddressOf(block), it2.NativePcOffset()); |
| 718 | CHECK_EQ(block->GetDexPc(), it2.DexPc()); |
| 719 | ++it2; |
| 720 | } |
| 721 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 722 | CHECK(it == table.PcToDexEnd()); |
| 723 | CHECK(it2 == table.DexToPcEnd()); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | void CodeGenerator::BuildVMapTable(std::vector<uint8_t>* data) const { |
| 728 | Leb128EncodingVector vmap_encoder; |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 729 | // We currently don't use callee-saved registers. |
| 730 | size_t size = 0 + 1 /* marker */ + 0; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 731 | vmap_encoder.Reserve(size + 1u); // All values are likely to be one byte in ULEB128 (<128). |
| 732 | vmap_encoder.PushBackUnsigned(size); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 733 | vmap_encoder.PushBackUnsigned(VmapTable::kAdjustedFpMarker); |
| 734 | |
| 735 | *data = vmap_encoder.GetData(); |
| 736 | } |
| Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 737 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 738 | void CodeGenerator::BuildStackMaps(std::vector<uint8_t>* data) { |
| Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 739 | uint32_t size = stack_map_stream_.PrepareForFillIn(); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 740 | data->resize(size); |
| 741 | MemoryRegion region(data->data(), size); |
| 742 | stack_map_stream_.FillIn(region); |
| 743 | } |
| 744 | |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 745 | void CodeGenerator::RecordPcInfo(HInstruction* instruction, |
| 746 | uint32_t dex_pc, |
| 747 | SlowPathCode* slow_path) { |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 748 | if (instruction != nullptr) { |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 749 | // The code generated for some type conversions and comparisons |
| 750 | // may call the runtime, thus normally requiring a subsequent |
| 751 | // call to this method. However, the method verifier does not |
| 752 | // produce PC information for certain instructions, which are |
| 753 | // considered "atomic" (they cannot join a GC). |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 754 | // Therefore we do not currently record PC information for such |
| 755 | // instructions. As this may change later, we added this special |
| 756 | // case so that code generators may nevertheless call |
| 757 | // CodeGenerator::RecordPcInfo without triggering an error in |
| 758 | // CodeGenerator::BuildNativeGCMap ("Missing ref for dex pc 0x") |
| 759 | // thereafter. |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 760 | if (instruction->IsTypeConversion() || instruction->IsCompare()) { |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 761 | return; |
| 762 | } |
| 763 | if (instruction->IsRem()) { |
| 764 | Primitive::Type type = instruction->AsRem()->GetResultType(); |
| 765 | if ((type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble)) { |
| 766 | return; |
| 767 | } |
| 768 | } |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 771 | uint32_t outer_dex_pc = dex_pc; |
| 772 | uint32_t outer_environment_size = 0; |
| 773 | uint32_t inlining_depth = 0; |
| 774 | if (instruction != nullptr) { |
| 775 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 776 | environment != nullptr; |
| 777 | environment = environment->GetParent()) { |
| 778 | outer_dex_pc = environment->GetDexPc(); |
| 779 | outer_environment_size = environment->Size(); |
| 780 | if (environment != instruction->GetEnvironment()) { |
| 781 | inlining_depth++; |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 786 | // Collect PC infos for the mapping table. |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 787 | uint32_t native_pc = GetAssembler()->CodeSize(); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 788 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 789 | if (instruction == nullptr) { |
| 790 | // For stack overflow checks. |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 791 | stack_map_stream_.BeginStackMapEntry(outer_dex_pc, native_pc, 0, 0, 0, 0); |
| Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 792 | stack_map_stream_.EndStackMapEntry(); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | LocationSummary* locations = instruction->GetLocations(); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 796 | |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 797 | uint32_t register_mask = locations->GetRegisterMask(); |
| 798 | if (locations->OnlyCallsOnSlowPath()) { |
| 799 | // In case of slow path, we currently set the location of caller-save registers |
| 800 | // to register (instead of their stack location when pushed before the slow-path |
| 801 | // call). Therefore register_mask contains both callee-save and caller-save |
| 802 | // registers that hold objects. We must remove the caller-save from the mask, since |
| 803 | // they will be overwritten by the callee. |
| 804 | register_mask &= core_callee_save_mask_; |
| 805 | } |
| 806 | // The register mask must be a subset of callee-save registers. |
| 807 | DCHECK_EQ(register_mask & core_callee_save_mask_, register_mask); |
| Vladimir Marko | bd8c725 | 2015-06-12 10:06:32 +0100 | [diff] [blame] | 808 | stack_map_stream_.BeginStackMapEntry(outer_dex_pc, |
| 809 | native_pc, |
| Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 810 | register_mask, |
| 811 | locations->GetStackMask(), |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 812 | outer_environment_size, |
| Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 813 | inlining_depth); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 814 | |
| 815 | EmitEnvironment(instruction->GetEnvironment(), slow_path); |
| 816 | stack_map_stream_.EndStackMapEntry(); |
| 817 | } |
| 818 | |
| 819 | void CodeGenerator::EmitEnvironment(HEnvironment* environment, SlowPathCode* slow_path) { |
| 820 | if (environment == nullptr) return; |
| 821 | |
| 822 | if (environment->GetParent() != nullptr) { |
| 823 | // We emit the parent environment first. |
| 824 | EmitEnvironment(environment->GetParent(), slow_path); |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 825 | stack_map_stream_.BeginInlineInfoEntry(environment->GetMethodIdx(), |
| 826 | environment->GetDexPc(), |
| 827 | environment->GetInvokeType(), |
| 828 | environment->Size()); |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 829 | } |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 830 | |
| 831 | // Walk over the environment, and record the location of dex registers. |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 832 | for (size_t i = 0, environment_size = environment->Size(); i < environment_size; ++i) { |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 833 | HInstruction* current = environment->GetInstructionAt(i); |
| 834 | if (current == nullptr) { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 835 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 836 | continue; |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 837 | } |
| 838 | |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 839 | Location location = environment->GetLocationAt(i); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 840 | switch (location.GetKind()) { |
| 841 | case Location::kConstant: { |
| 842 | DCHECK_EQ(current, location.GetConstant()); |
| 843 | if (current->IsLongConstant()) { |
| 844 | int64_t value = current->AsLongConstant()->GetValue(); |
| 845 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 846 | DexRegisterLocation::Kind::kConstant, Low32Bits(value)); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 847 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 848 | DexRegisterLocation::Kind::kConstant, High32Bits(value)); |
| 849 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 850 | DCHECK_LT(i, environment_size); |
| 851 | } else if (current->IsDoubleConstant()) { |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 852 | int64_t value = bit_cast<int64_t, double>(current->AsDoubleConstant()->GetValue()); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 853 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 854 | DexRegisterLocation::Kind::kConstant, Low32Bits(value)); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 855 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 856 | DexRegisterLocation::Kind::kConstant, High32Bits(value)); |
| 857 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 858 | DCHECK_LT(i, environment_size); |
| 859 | } else if (current->IsIntConstant()) { |
| 860 | int32_t value = current->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 861 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 862 | } else if (current->IsNullConstant()) { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 863 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, 0); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 864 | } else { |
| 865 | DCHECK(current->IsFloatConstant()) << current->DebugName(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 866 | int32_t value = bit_cast<int32_t, float>(current->AsFloatConstant()->GetValue()); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 867 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 868 | } |
| 869 | break; |
| 870 | } |
| 871 | |
| 872 | case Location::kStackSlot: { |
| 873 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 874 | DexRegisterLocation::Kind::kInStack, location.GetStackIndex()); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 875 | break; |
| 876 | } |
| 877 | |
| 878 | case Location::kDoubleStackSlot: { |
| 879 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 880 | DexRegisterLocation::Kind::kInStack, location.GetStackIndex()); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 881 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 882 | DexRegisterLocation::Kind::kInStack, location.GetHighStackIndex(kVRegSize)); |
| 883 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 884 | DCHECK_LT(i, environment_size); |
| 885 | break; |
| 886 | } |
| 887 | |
| 888 | case Location::kRegister : { |
| 889 | int id = location.reg(); |
| 890 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(id)) { |
| 891 | uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(id); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 892 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 893 | if (current->GetType() == Primitive::kPrimLong) { |
| 894 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 895 | DexRegisterLocation::Kind::kInStack, offset + kVRegSize); |
| 896 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 897 | DCHECK_LT(i, environment_size); |
| 898 | } |
| 899 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 900 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, id); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 901 | if (current->GetType() == Primitive::kPrimLong) { |
| David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 902 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegisterHigh, id); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 903 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 904 | DCHECK_LT(i, environment_size); |
| 905 | } |
| 906 | } |
| 907 | break; |
| 908 | } |
| 909 | |
| 910 | case Location::kFpuRegister : { |
| 911 | int id = location.reg(); |
| 912 | if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(id)) { |
| 913 | uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(id); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 914 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 915 | if (current->GetType() == Primitive::kPrimDouble) { |
| 916 | stack_map_stream_.AddDexRegisterEntry( |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 917 | DexRegisterLocation::Kind::kInStack, offset + kVRegSize); |
| 918 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 919 | DCHECK_LT(i, environment_size); |
| 920 | } |
| 921 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 922 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, id); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 923 | if (current->GetType() == Primitive::kPrimDouble) { |
| David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 924 | stack_map_stream_.AddDexRegisterEntry( |
| 925 | DexRegisterLocation::Kind::kInFpuRegisterHigh, id); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 926 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 927 | DCHECK_LT(i, environment_size); |
| 928 | } |
| 929 | } |
| 930 | break; |
| 931 | } |
| 932 | |
| 933 | case Location::kFpuRegisterPair : { |
| 934 | int low = location.low(); |
| 935 | int high = location.high(); |
| 936 | if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(low)) { |
| 937 | uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(low); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 938 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 939 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 940 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, low); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 941 | } |
| 942 | if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(high)) { |
| 943 | uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(high); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 944 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| 945 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 946 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 947 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, high); |
| 948 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 949 | } |
| 950 | DCHECK_LT(i, environment_size); |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | case Location::kRegisterPair : { |
| 955 | int low = location.low(); |
| 956 | int high = location.high(); |
| 957 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(low)) { |
| 958 | uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(low); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 959 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 960 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 961 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, low); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 962 | } |
| 963 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(high)) { |
| 964 | uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(high); |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 965 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 966 | } else { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 967 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, high); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 968 | } |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 969 | ++i; |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 970 | DCHECK_LT(i, environment_size); |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | case Location::kInvalid: { |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 975 | stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 976 | break; |
| 977 | } |
| 978 | |
| 979 | default: |
| 980 | LOG(FATAL) << "Unexpected kind " << location.GetKind(); |
| 981 | } |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 982 | } |
| Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 983 | |
| 984 | if (environment->GetParent() != nullptr) { |
| 985 | stack_map_stream_.EndInlineInfoEntry(); |
| 986 | } |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 989 | bool CodeGenerator::CanMoveNullCheckToUser(HNullCheck* null_check) { |
| 990 | HInstruction* first_next_not_move = null_check->GetNextDisregardingMoves(); |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 991 | |
| 992 | return (first_next_not_move != nullptr) |
| 993 | && first_next_not_move->CanDoImplicitNullCheckOn(null_check->InputAt(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | void CodeGenerator::MaybeRecordImplicitNullCheck(HInstruction* instr) { |
| 997 | // If we are from a static path don't record the pc as we can't throw NPE. |
| 998 | // NB: having the checks here makes the code much less verbose in the arch |
| 999 | // specific code generators. |
| 1000 | if (instr->IsStaticFieldSet() || instr->IsStaticFieldGet()) { |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | if (!compiler_options_.GetImplicitNullChecks()) { |
| 1005 | return; |
| 1006 | } |
| 1007 | |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1008 | if (!instr->CanDoImplicitNullCheckOn(instr->InputAt(0))) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1009 | return; |
| 1010 | } |
| 1011 | |
| 1012 | // Find the first previous instruction which is not a move. |
| 1013 | HInstruction* first_prev_not_move = instr->GetPreviousDisregardingMoves(); |
| 1014 | |
| 1015 | // If the instruction is a null check it means that `instr` is the first user |
| 1016 | // and needs to record the pc. |
| 1017 | if (first_prev_not_move != nullptr && first_prev_not_move->IsNullCheck()) { |
| 1018 | HNullCheck* null_check = first_prev_not_move->AsNullCheck(); |
| 1019 | // TODO: The parallel moves modify the environment. Their changes need to be reverted |
| 1020 | // otherwise the stack maps at the throw point will not be correct. |
| 1021 | RecordPcInfo(null_check, null_check->GetDexPc()); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1025 | void CodeGenerator::ClearSpillSlotsFromLoopPhisInStackMap(HSuspendCheck* suspend_check) const { |
| 1026 | LocationSummary* locations = suspend_check->GetLocations(); |
| 1027 | HBasicBlock* block = suspend_check->GetBlock(); |
| 1028 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == suspend_check); |
| 1029 | DCHECK(block->IsLoopHeader()); |
| 1030 | |
| 1031 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 1032 | HInstruction* current = it.Current(); |
| 1033 | LiveInterval* interval = current->GetLiveInterval(); |
| 1034 | // We only need to clear bits of loop phis containing objects and allocated in register. |
| 1035 | // Loop phis allocated on stack already have the object in the stack. |
| 1036 | if (current->GetType() == Primitive::kPrimNot |
| 1037 | && interval->HasRegister() |
| 1038 | && interval->HasSpillSlot()) { |
| 1039 | locations->ClearStackBit(interval->GetSpillSlot() / kVRegSize); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1044 | void CodeGenerator::EmitParallelMoves(Location from1, |
| 1045 | Location to1, |
| 1046 | Primitive::Type type1, |
| 1047 | Location from2, |
| 1048 | Location to2, |
| 1049 | Primitive::Type type2) { |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 1050 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1051 | parallel_move.AddMove(from1, to1, type1, nullptr); |
| 1052 | parallel_move.AddMove(from2, to2, type2, nullptr); |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 1053 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1054 | } |
| 1055 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1056 | void CodeGenerator::ValidateInvokeRuntime(HInstruction* instruction, SlowPathCode* slow_path) { |
| 1057 | // Ensure that the call kind indication given to the register allocator is |
| 1058 | // coherent with the runtime call generated, and that the GC side effect is |
| 1059 | // set when required. |
| 1060 | if (slow_path == nullptr) { |
| Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 1061 | DCHECK(instruction->GetLocations()->WillCall()) << instruction->DebugName(); |
| 1062 | DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC())) |
| 1063 | << instruction->DebugName() << instruction->GetSideEffects().ToString(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1064 | } else { |
| Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 1065 | DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal()) |
| 1066 | << instruction->DebugName() << slow_path->GetDescription(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1067 | DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()) || |
| 1068 | // Control flow would not come back into the code if a fatal slow |
| 1069 | // path is taken, so we do not care if it triggers GC. |
| 1070 | slow_path->IsFatal() || |
| 1071 | // HDeoptimize is a special case: we know we are not coming back from |
| 1072 | // it into the code. |
| Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 1073 | instruction->IsDeoptimize()) |
| 1074 | << instruction->DebugName() << instruction->GetSideEffects().ToString() |
| 1075 | << slow_path->GetDescription(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | // Check the coherency of leaf information. |
| 1079 | DCHECK(instruction->IsSuspendCheck() |
| 1080 | || ((slow_path != nullptr) && slow_path->IsFatal()) |
| 1081 | || instruction->GetLocations()->CanCall() |
| Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 1082 | || !IsLeafMethod()) |
| 1083 | << instruction->DebugName() << ((slow_path != nullptr) ? slow_path->GetDescription() : ""); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
| Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 1086 | void SlowPathCode::RecordPcInfo(CodeGenerator* codegen, |
| 1087 | HInstruction* instruction, |
| 1088 | uint32_t dex_pc) { |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1089 | codegen->RecordPcInfo(instruction, dex_pc, this); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void SlowPathCode::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 1093 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 1094 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 1095 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1096 | if (!codegen->IsCoreCalleeSaveRegister(i)) { |
| 1097 | if (register_set->ContainsCoreRegister(i)) { |
| 1098 | // If the register holds an object, update the stack mask. |
| 1099 | if (locations->RegisterContainsObject(i)) { |
| 1100 | locations->SetStackBit(stack_offset / kVRegSize); |
| 1101 | } |
| 1102 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1103 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 1104 | saved_core_stack_offsets_[i] = stack_offset; |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1105 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 1111 | if (!codegen->IsFloatingPointCalleeSaveRegister(i)) { |
| 1112 | if (register_set->ContainsFloatingPointRegister(i)) { |
| 1113 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| Nicolas Geoffray | eeefa12 | 2015-03-13 18:52:59 +0000 | [diff] [blame] | 1114 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 1115 | saved_fpu_stack_offsets_[i] = stack_offset; |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1116 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, i); |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | void SlowPathCode::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 1123 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 1124 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 1125 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1126 | if (!codegen->IsCoreCalleeSaveRegister(i)) { |
| 1127 | if (register_set->ContainsCoreRegister(i)) { |
| 1128 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 1129 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) { |
| 1135 | if (!codegen->IsFloatingPointCalleeSaveRegister(i)) { |
| 1136 | if (register_set->ContainsFloatingPointRegister(i)) { |
| 1137 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 1138 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, i); |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1144 | } // namespace art |