Index: runtime/vm/locations.cc |
diff --git a/runtime/vm/locations.cc b/runtime/vm/locations.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c85f96b7d531c9dbd22a165e2c7c6600bb79ee06 |
--- /dev/null |
+++ b/runtime/vm/locations.cc |
@@ -0,0 +1,70 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#include "vm/locations.h" |
+ |
+#include "vm/intermediate_language.h" |
+ |
+namespace dart { |
+ |
+ |
+static Register AllocateFreeRegister( |
+ EmbeddedArray<bool, kNumberOfCpuRegisters>* blocked_registers) { |
+ for (int regno = 0; regno < kNumberOfCpuRegisters; regno++) { |
srdjan
2012/05/21 16:05:22
intptr_t
Vyacheslav Egorov (Google)
2012/05/21 19:53:46
Done.
|
+ if (!blocked_registers->At(regno)) { |
Florian Schneider
2012/05/21 18:33:38
(*blocked_registers)[regno] should also work here.
srdjan
2012/05/21 19:49:43
I like the idea of getting rid of const overloaded
Vyacheslav Egorov (Google)
2012/05/21 19:53:46
I'll go with a method, it looks nicer.
|
+ blocked_registers->SetAt(regno, true); |
Florian Schneider
2012/05/21 18:33:38
(*blocked_registers)[regno] = true;
should also w
Vyacheslav Egorov (Google)
2012/05/21 19:53:46
I'll go with a method, it looks nicer.
|
+ return static_cast<Register>(regno); |
+ } |
+ } |
+ UNREACHABLE(); |
+ return kNoRegister; |
+} |
+ |
+ |
+void LocationSummary::AllocateRegisters() { |
+ EmbeddedArray<bool, kNumberOfCpuRegisters> blocked_registers; |
+ |
+ // Mark all registers free. |
+ for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) { |
+ blocked_registers[i] = false; |
+ } |
+ |
+ // Mark all fixed registers as used. |
+ for (intptr_t i = 0; i < count(); i++) { |
+ Location loc = in(i); |
+ if (loc.kind() == Location::kRegister) { |
+ ASSERT(!blocked_registers[loc.AsRegister()]); |
+ blocked_registers[loc.value()] = true; |
+ } |
+ } |
+ |
+ // Allocate all unallocated input locations. |
+ for (intptr_t i = 0; i < count(); i++) { |
+ Location loc = in(i); |
+ if (loc.kind() == Location::kUnallocated) { |
+ ASSERT(UnallocatedLocation::Cast(loc).policy() == |
+ UnallocatedLocation::kRegister); |
+ set_in(i, RegisterLocation( |
+ AllocateFreeRegister(&blocked_registers))); |
+ } |
+ } |
+ |
+ Location result_location = out(); |
+ if (result_location.kind() == Location::kUnallocated) { |
+ switch (UnallocatedLocation::Cast(result_location).policy()) { |
+ case UnallocatedLocation::kRegister: |
+ result_location = RegisterLocation( |
+ AllocateFreeRegister(&blocked_registers)); |
+ break; |
+ case UnallocatedLocation::kSameAsFirstInput: |
+ result_location = in(0); |
+ break; |
+ } |
+ set_out(result_location); |
+ } |
+} |
+ |
+ |
+} // namespace dart |
+ |