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 | #ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_H_ |
| 19 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 20 | #include "base/bit_field.h" |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 21 | #include "globals.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 22 | #include "instruction_set.h" |
| 23 | #include "memory_region.h" |
| 24 | #include "nodes.h" |
| 25 | #include "utils/assembler.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 29 | static size_t constexpr kVRegSize = 4; |
| 30 | |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 31 | class DexCompilationUnit; |
| 32 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | class CodeAllocator { |
| 34 | public: |
| 35 | CodeAllocator() { } |
| 36 | virtual ~CodeAllocator() { } |
| 37 | |
| 38 | virtual uint8_t* Allocate(size_t size) = 0; |
| 39 | |
| 40 | private: |
| 41 | DISALLOW_COPY_AND_ASSIGN(CodeAllocator); |
| 42 | }; |
| 43 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 44 | struct PcInfo { |
| 45 | uint32_t dex_pc; |
| 46 | uintptr_t native_pc; |
| 47 | }; |
| 48 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 49 | /** |
| 50 | * A Location is an abstraction over the potential location |
| 51 | * of an instruction. It could be in register or stack. |
| 52 | */ |
| 53 | class Location : public ValueObject { |
| 54 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 55 | enum Kind { |
| 56 | kInvalid = 0, |
| 57 | kStackSlot = 1, // Word size slot. |
| 58 | kDoubleStackSlot = 2, // 64bit stack slot. |
| 59 | kRegister = 3, |
| 60 | // On 32bits architectures, quick can pass a long where the |
| 61 | // low bits are in the last parameter register, and the high |
| 62 | // bits are in a stack slot. The kQuickParameter kind is for |
| 63 | // handling this special case. |
| 64 | kQuickParameter = 4, |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 65 | |
| 66 | // Unallocated location represents a location that is not fixed and can be |
| 67 | // allocated by a register allocator. Each unallocated location has |
| 68 | // a policy that specifies what kind of location is suitable. Payload |
| 69 | // contains register allocation policy. |
| 70 | kUnallocated = 5, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 71 | }; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 72 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 73 | Location() : value_(kInvalid) { |
| 74 | DCHECK(!IsValid()); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 77 | Location(const Location& other) : ValueObject(), value_(other.value_) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 78 | |
| 79 | Location& operator=(const Location& other) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 80 | value_ = other.value_; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 81 | return *this; |
| 82 | } |
| 83 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 84 | bool IsValid() const { |
| 85 | return value_ != kInvalid; |
| 86 | } |
| 87 | |
| 88 | // Register locations. |
| 89 | static Location RegisterLocation(ManagedRegister reg) { |
| 90 | return Location(kRegister, reg.RegId()); |
| 91 | } |
| 92 | |
| 93 | bool IsRegister() const { |
| 94 | return GetKind() == kRegister; |
| 95 | } |
| 96 | |
| 97 | ManagedRegister reg() const { |
| 98 | DCHECK(IsRegister()); |
| 99 | return static_cast<ManagedRegister>(GetPayload()); |
| 100 | } |
| 101 | |
| 102 | static uword EncodeStackIndex(intptr_t stack_index) { |
| 103 | DCHECK(-kStackIndexBias <= stack_index); |
| 104 | DCHECK(stack_index < kStackIndexBias); |
| 105 | return static_cast<uword>(kStackIndexBias + stack_index); |
| 106 | } |
| 107 | |
| 108 | static Location StackSlot(intptr_t stack_index) { |
| 109 | uword payload = EncodeStackIndex(stack_index); |
| 110 | Location loc(kStackSlot, payload); |
| 111 | // Ensure that sign is preserved. |
| 112 | DCHECK_EQ(loc.GetStackIndex(), stack_index); |
| 113 | return loc; |
| 114 | } |
| 115 | |
| 116 | bool IsStackSlot() const { |
| 117 | return GetKind() == kStackSlot; |
| 118 | } |
| 119 | |
| 120 | static Location DoubleStackSlot(intptr_t stack_index) { |
| 121 | uword payload = EncodeStackIndex(stack_index); |
| 122 | Location loc(kDoubleStackSlot, payload); |
| 123 | // Ensure that sign is preserved. |
| 124 | DCHECK_EQ(loc.GetStackIndex(), stack_index); |
| 125 | return loc; |
| 126 | } |
| 127 | |
| 128 | bool IsDoubleStackSlot() const { |
| 129 | return GetKind() == kDoubleStackSlot; |
| 130 | } |
| 131 | |
| 132 | intptr_t GetStackIndex() const { |
| 133 | DCHECK(IsStackSlot() || IsDoubleStackSlot()); |
| 134 | // Decode stack index manually to preserve sign. |
| 135 | return GetPayload() - kStackIndexBias; |
| 136 | } |
| 137 | |
| 138 | intptr_t GetHighStackIndex(uintptr_t word_size) const { |
| 139 | DCHECK(IsDoubleStackSlot()); |
| 140 | // Decode stack index manually to preserve sign. |
| 141 | return GetPayload() - kStackIndexBias + word_size; |
| 142 | } |
| 143 | |
| 144 | static Location QuickParameter(uint32_t parameter_index) { |
| 145 | return Location(kQuickParameter, parameter_index); |
| 146 | } |
| 147 | |
| 148 | uint32_t GetQuickParameterIndex() const { |
| 149 | DCHECK(IsQuickParameter()); |
| 150 | return GetPayload(); |
| 151 | } |
| 152 | |
| 153 | bool IsQuickParameter() const { |
| 154 | return GetKind() == kQuickParameter; |
| 155 | } |
| 156 | |
| 157 | arm::ArmManagedRegister AsArm() const; |
| 158 | x86::X86ManagedRegister AsX86() const; |
| 159 | |
| 160 | Kind GetKind() const { |
| 161 | return KindField::Decode(value_); |
| 162 | } |
| 163 | |
| 164 | bool Equals(Location other) const { |
| 165 | return value_ == other.value_; |
| 166 | } |
| 167 | |
| 168 | const char* DebugString() const { |
| 169 | switch (GetKind()) { |
| 170 | case kInvalid: return "?"; |
| 171 | case kRegister: return "R"; |
| 172 | case kStackSlot: return "S"; |
| 173 | case kDoubleStackSlot: return "DS"; |
| 174 | case kQuickParameter: return "Q"; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 175 | case kUnallocated: return "U"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 176 | } |
| 177 | return "?"; |
| 178 | } |
| 179 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 180 | // Unallocated locations. |
| 181 | enum Policy { |
| 182 | kAny, |
| 183 | kRequiresRegister, |
| 184 | kSameAsFirstInput, |
| 185 | }; |
| 186 | |
| 187 | bool IsUnallocated() const { |
| 188 | return GetKind() == kUnallocated; |
| 189 | } |
| 190 | |
| 191 | static Location UnallocatedLocation(Policy policy) { |
| 192 | return Location(kUnallocated, PolicyField::Encode(policy)); |
| 193 | } |
| 194 | |
| 195 | // Any free register is suitable to replace this unallocated location. |
| 196 | static Location Any() { |
| 197 | return UnallocatedLocation(kAny); |
| 198 | } |
| 199 | |
| 200 | static Location RequiresRegister() { |
| 201 | return UnallocatedLocation(kRequiresRegister); |
| 202 | } |
| 203 | |
| 204 | // The location of the first input to the instruction will be |
| 205 | // used to replace this unallocated location. |
| 206 | static Location SameAsFirstInput() { |
| 207 | return UnallocatedLocation(kSameAsFirstInput); |
| 208 | } |
| 209 | |
| 210 | Policy GetPolicy() const { |
| 211 | DCHECK(IsUnallocated()); |
| 212 | return PolicyField::Decode(GetPayload()); |
| 213 | } |
| 214 | |
| 215 | uword GetEncoding() const { |
| 216 | return GetPayload(); |
| 217 | } |
| 218 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 219 | private: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 220 | // Number of bits required to encode Kind value. |
| 221 | static constexpr uint32_t kBitsForKind = 4; |
| 222 | static constexpr uint32_t kBitsForPayload = kWordSize * kBitsPerByte - kBitsForKind; |
| 223 | |
| 224 | explicit Location(uword value) : value_(value) {} |
| 225 | |
| 226 | Location(Kind kind, uword payload) |
| 227 | : value_(KindField::Encode(kind) | PayloadField::Encode(payload)) {} |
| 228 | |
| 229 | uword GetPayload() const { |
| 230 | return PayloadField::Decode(value_); |
| 231 | } |
| 232 | |
| 233 | typedef BitField<Kind, 0, kBitsForKind> KindField; |
| 234 | typedef BitField<uword, kBitsForKind, kBitsForPayload> PayloadField; |
| 235 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 236 | // Layout for kUnallocated locations payload. |
| 237 | typedef BitField<Policy, 0, 3> PolicyField; |
| 238 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 239 | // Layout for stack slots. |
| 240 | static const intptr_t kStackIndexBias = |
| 241 | static_cast<intptr_t>(1) << (kBitsForPayload - 1); |
| 242 | |
| 243 | // Location either contains kind and payload fields or a tagged handle for |
| 244 | // a constant locations. Values of enumeration Kind are selected in such a |
| 245 | // way that none of them can be interpreted as a kConstant tag. |
| 246 | uword value_; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /** |
| 250 | * The code generator computes LocationSummary for each instruction so that |
| 251 | * the instruction itself knows what code to generate: where to find the inputs |
| 252 | * and where to place the result. |
| 253 | * |
| 254 | * The intent is to have the code for generating the instruction independent of |
| 255 | * register allocation. A register allocator just has to provide a LocationSummary. |
| 256 | */ |
| 257 | class LocationSummary : public ArenaObject { |
| 258 | public: |
| 259 | explicit LocationSummary(HInstruction* instruction) |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 260 | : inputs_(instruction->GetBlock()->GetGraph()->GetArena(), instruction->InputCount()), |
| 261 | temps_(instruction->GetBlock()->GetGraph()->GetArena(), 0) { |
| 262 | inputs_.SetSize(instruction->InputCount()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 263 | for (size_t i = 0; i < instruction->InputCount(); i++) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 264 | inputs_.Put(i, Location()); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | void SetInAt(uint32_t at, Location location) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 269 | inputs_.Put(at, location); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | Location InAt(uint32_t at) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 273 | return inputs_.Get(at); |
| 274 | } |
| 275 | |
| 276 | size_t GetInputCount() const { |
| 277 | return inputs_.Size(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void SetOut(Location location) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 281 | output_ = Location(location); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 284 | void AddTemp(Location location) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 285 | temps_.Add(location); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | Location GetTemp(uint32_t at) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 289 | return temps_.Get(at); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 292 | void SetTempAt(uint32_t at, Location location) { |
| 293 | temps_.Put(at, location); |
| 294 | } |
| 295 | |
| 296 | size_t GetTempCount() const { |
| 297 | return temps_.Size(); |
| 298 | } |
| 299 | |
| 300 | Location Out() const { return output_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 301 | |
| 302 | private: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 303 | GrowableArray<Location> inputs_; |
| 304 | GrowableArray<Location> temps_; |
| 305 | Location output_; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 306 | |
| 307 | DISALLOW_COPY_AND_ASSIGN(LocationSummary); |
| 308 | }; |
| 309 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 310 | class CodeGenerator : public ArenaObject { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 311 | public: |
| 312 | // Compiles the graph to executable instructions. Returns whether the compilation |
| 313 | // succeeded. |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 314 | void Compile(CodeAllocator* allocator); |
| 315 | static CodeGenerator* Create(ArenaAllocator* allocator, |
| 316 | HGraph* graph, |
| 317 | InstructionSet instruction_set); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 318 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 319 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 320 | |
| 321 | Label* GetLabelOf(HBasicBlock* block) const; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 322 | bool GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 323 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 324 | virtual void GenerateFrameEntry() = 0; |
| 325 | virtual void GenerateFrameExit() = 0; |
| 326 | virtual void Bind(Label* label) = 0; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 327 | virtual void Move(HInstruction* instruction, Location location, HInstruction* move_for) = 0; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 328 | virtual HGraphVisitor* GetLocationBuilder() = 0; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 329 | virtual HGraphVisitor* GetInstructionVisitor() = 0; |
| 330 | virtual Assembler* GetAssembler() = 0; |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 331 | virtual size_t GetWordSize() const = 0; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 332 | |
| 333 | uint32_t GetFrameSize() const { return frame_size_; } |
| 334 | void SetFrameSize(uint32_t size) { frame_size_ = size; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 335 | uint32_t GetCoreSpillMask() const { return core_spill_mask_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 336 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 337 | void RecordPcInfo(uint32_t dex_pc) { |
| 338 | struct PcInfo pc_info; |
| 339 | pc_info.dex_pc = dex_pc; |
| 340 | pc_info.native_pc = GetAssembler()->CodeSize(); |
| 341 | pc_infos_.Add(pc_info); |
| 342 | } |
| 343 | |
| 344 | void BuildMappingTable(std::vector<uint8_t>* vector) const; |
| 345 | void BuildVMapTable(std::vector<uint8_t>* vector) const; |
Nicolas Geoffray | 92cf83e | 2014-03-18 17:59:20 +0000 | [diff] [blame] | 346 | void BuildNativeGCMap( |
| 347 | std::vector<uint8_t>* vector, const DexCompilationUnit& dex_compilation_unit) const; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 348 | |
| 349 | protected: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 350 | CodeGenerator(HGraph* graph, size_t number_of_registers) |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 351 | : frame_size_(0), |
| 352 | graph_(graph), |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 353 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 354 | pc_infos_(graph->GetArena(), 32), |
| 355 | blocked_registers_(static_cast<bool*>( |
| 356 | graph->GetArena()->Alloc(number_of_registers * sizeof(bool), kArenaAllocData))) { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame^] | 357 | block_labels_.SetSize(graph->GetBlocks().Size()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 358 | } |
| 359 | ~CodeGenerator() { } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 361 | // Register allocation logic. |
| 362 | void AllocateRegistersLocally(HInstruction* instruction) const; |
| 363 | |
| 364 | // Backend specific implementation for allocating a register. |
| 365 | virtual ManagedRegister AllocateFreeRegister(Primitive::Type type, |
| 366 | bool* blocked_registers) const = 0; |
| 367 | |
| 368 | // Raw implementation of allocating a register: loops over blocked_registers to find |
| 369 | // the first available register. |
| 370 | size_t AllocateFreeRegisterInternal(bool* blocked_registers, size_t number_of_registers) const; |
| 371 | |
| 372 | virtual void SetupBlockedRegisters(bool* blocked_registers) const = 0; |
| 373 | virtual size_t GetNumberOfRegisters() const = 0; |
| 374 | |
| 375 | virtual Location GetStackLocation(HLoadLocal* load) const = 0; |
| 376 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 377 | // Frame size required for this method. |
| 378 | uint32_t frame_size_; |
| 379 | uint32_t core_spill_mask_; |
| 380 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 381 | private: |
| 382 | void InitLocations(HInstruction* instruction); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 383 | void CompileBlock(HBasicBlock* block); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 384 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 385 | HGraph* const graph_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 386 | |
| 387 | // Labels for each block that will be compiled. |
| 388 | GrowableArray<Label> block_labels_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 389 | GrowableArray<PcInfo> pc_infos_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 390 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 391 | // Temporary data structure used when doing register allocation. |
| 392 | bool* const blocked_registers_; |
| 393 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 394 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 395 | }; |
| 396 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 397 | template <typename T> |
| 398 | class CallingConvention { |
| 399 | public: |
| 400 | CallingConvention(const T* registers, int number_of_registers) |
| 401 | : registers_(registers), number_of_registers_(number_of_registers) {} |
| 402 | |
| 403 | size_t GetNumberOfRegisters() const { return number_of_registers_; } |
| 404 | |
| 405 | T GetRegisterAt(size_t index) const { |
| 406 | DCHECK_LT(index, number_of_registers_); |
| 407 | return registers_[index]; |
| 408 | } |
| 409 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 410 | uint8_t GetStackOffsetOf(size_t index, size_t word_size) const { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 411 | // We still reserve the space for parameters passed by registers. |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 412 | // Add word_size for the method pointer. |
| 413 | return index * kVRegSize + word_size; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | private: |
| 417 | const T* registers_; |
| 418 | const size_t number_of_registers_; |
| 419 | |
| 420 | DISALLOW_COPY_AND_ASSIGN(CallingConvention); |
| 421 | }; |
| 422 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 423 | } // namespace art |
| 424 | |
| 425 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_H_ |