| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/locations.h" | 5 #include "vm/locations.h" |
| 6 | 6 |
| 7 #include "vm/intermediate_language.h" | 7 #include "vm/intermediate_language.h" |
| 8 #include "vm/flow_graph_compiler.h" |
| 8 | 9 |
| 9 namespace dart { | 10 namespace dart { |
| 10 | 11 |
| 11 | 12 LocationSummary* LocationSummary::Make(intptr_t input_count, |
| 12 static Register AllocateFreeRegister( | 13 Location out, |
| 13 EmbeddedArray<bool, kNumberOfCpuRegisters>* blocked_registers) { | 14 ContainsCall contains_call, |
| 14 for (intptr_t regno = 0; regno < kNumberOfCpuRegisters; regno++) { | 15 ContainsBranch contains_branch) { |
| 15 if (!blocked_registers->At(regno)) { | 16 LocationSummary* summary = new LocationSummary(input_count, |
| 16 blocked_registers->SetAt(regno, true); | 17 0, |
| 17 return static_cast<Register>(regno); | 18 contains_call, |
| 18 } | 19 contains_branch); |
| 19 } | |
| 20 UNREACHABLE(); | |
| 21 return kNoRegister; | |
| 22 } | |
| 23 | |
| 24 | |
| 25 void LocationSummary::AllocateRegisters() { | |
| 26 EmbeddedArray<bool, kNumberOfCpuRegisters> blocked_registers; | |
| 27 | |
| 28 // Mark all available registers free. | |
| 29 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) { | |
| 30 blocked_registers[i] = false; | |
| 31 } | |
| 32 | |
| 33 // Mark all fixed input, temp and output registers as used. | |
| 34 for (intptr_t i = 0; i < input_count(); i++) { | |
| 35 Location loc = in(i); | |
| 36 if (loc.kind() == Location::kRegister) { | |
| 37 ASSERT(!blocked_registers[loc.reg()]); | |
| 38 blocked_registers[loc.reg()] = true; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 for (intptr_t i = 0; i < temp_count(); i++) { | |
| 43 Location loc = temp(i); | |
| 44 if (loc.kind() == Location::kRegister) { | |
| 45 ASSERT(!blocked_registers[loc.reg()]); | |
| 46 blocked_registers[loc.reg()] = true; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 if (out().kind() == Location::kRegister) { | |
| 51 // Fixed output registers are allowed to overlap with | |
| 52 // temps and inputs. | |
| 53 blocked_registers[out().reg()] = true; | |
| 54 } | |
| 55 | |
| 56 // Do not allocate known registers. | |
| 57 blocked_registers[CTX] = true; | |
| 58 blocked_registers[SPREG] = true; | |
| 59 blocked_registers[FPREG] = true; | |
| 60 if (TMP != kNoRegister) { | |
| 61 blocked_registers[TMP] = true; | |
| 62 } | |
| 63 | |
| 64 // Allocate all unallocated input locations. | |
| 65 for (intptr_t i = 0; i < input_count(); i++) { | |
| 66 Location loc = in(i); | |
| 67 if (loc.kind() == Location::kUnallocated) { | |
| 68 ASSERT(loc.policy() == Location::kRequiresRegister); | |
| 69 set_in(i, Location::RegisterLocation( | |
| 70 AllocateFreeRegister(&blocked_registers))); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 // Allocate all unallocated temp locations. | |
| 75 for (intptr_t i = 0; i < temp_count(); i++) { | |
| 76 Location loc = temp(i); | |
| 77 if (loc.kind() == Location::kUnallocated) { | |
| 78 ASSERT(loc.policy() == Location::kRequiresRegister); | |
| 79 set_temp(i, Location::RegisterLocation( | |
| 80 AllocateFreeRegister(&blocked_registers))); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 Location result_location = out(); | |
| 85 if (result_location.kind() == Location::kUnallocated) { | |
| 86 switch (result_location.policy()) { | |
| 87 case Location::kRequiresRegister: | |
| 88 result_location = Location::RegisterLocation( | |
| 89 AllocateFreeRegister(&blocked_registers)); | |
| 90 break; | |
| 91 case Location::kSameAsFirstInput: | |
| 92 result_location = in(0); | |
| 93 break; | |
| 94 } | |
| 95 set_out(result_location); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 | |
| 100 LocationSummary* LocationSummary::Make(intptr_t input_count, Location out) { | |
| 101 LocationSummary* summary = new LocationSummary(input_count, 0); | |
| 102 for (intptr_t i = 0; i < input_count; i++) { | 20 for (intptr_t i = 0; i < input_count; i++) { |
| 103 summary->set_in(i, Location::RequiresRegister()); | 21 summary->set_in(i, Location::RequiresRegister()); |
| 104 } | 22 } |
| 105 summary->set_out(out); | 23 summary->set_out(out); |
| 106 return summary; | 24 return summary; |
| 107 } | 25 } |
| 108 | 26 |
| 109 } // namespace dart | 27 } // namespace dart |
| 110 | 28 |
| OLD | NEW |