Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Unified Diff: runtime/vm/locations.cc

Issue 10382234: Introduce locations based code generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed Srdjan comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+
« runtime/vm/locations.h ('K') | « runtime/vm/locations.h ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698