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

Unified Diff: src/interpreter/bytecode-register-allocator.h

Issue 1651133002: [interpreter] Move temporary register allocator into own file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments from rmcilroy. Created 4 years, 11 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
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/interpreter/bytecode-register-allocator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-register-allocator.h
diff --git a/src/interpreter/bytecode-register-allocator.h b/src/interpreter/bytecode-register-allocator.h
index 74ab3a42727119c907a05e400b07d1af483a817b..798fd06d2937ce66f978524511f7bdf28910544d 100644
--- a/src/interpreter/bytecode-register-allocator.h
+++ b/src/interpreter/bytecode-register-allocator.h
@@ -5,6 +5,7 @@
#ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
#define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
+#include "src/interpreter/bytecodes.h"
#include "src/zone-containers.h"
namespace v8 {
@@ -14,11 +15,62 @@ namespace interpreter {
class BytecodeArrayBuilder;
class Register;
+class TemporaryRegisterAllocator final {
+ public:
+ TemporaryRegisterAllocator(Zone* zone, int start_index);
+
+ // Borrow a temporary register.
+ int BorrowTemporaryRegister();
+
+ // Borrow a temporary register from the register range outside of
+ // |start_index| to |end_index|.
+ int BorrowTemporaryRegisterNotInRange(int start_index, int end_index);
+
+ // Return a temporary register when no longer used.
+ void ReturnTemporaryRegister(int reg_index);
+
+ // Ensure a run of consecutive registers is available. Each register in
+ // the range should be borrowed with BorrowConsecutiveTemporaryRegister().
+ // Returns the start index of the run.
+ int PrepareForConsecutiveTemporaryRegisters(size_t count);
+
+ // Borrow a register from a range prepared with
+ // PrepareForConsecutiveTemporaryRegisters().
+ void BorrowConsecutiveTemporaryRegister(int reg_index);
+
+ // Returns true if |reg| is a temporary register and is currently
+ // borrowed.
+ bool RegisterIsLive(Register reg) const;
+
+ // Returns the first register in the range of temporary registers.
+ Register first_temporary_register() const;
+
+ // Returns the last register in the range of temporary registers.
+ Register last_temporary_register() const;
+
+ // Returns the start index of temporary register allocations.
+ int allocation_base() const { return allocation_base_; }
+
+ // Returns the number of temporary register allocations made.
+ int allocation_count() const { return allocation_count_; }
+
+ private:
+ // Allocate a temporary register.
+ int AllocateTemporaryRegister();
+
+ ZoneSet<int> free_temporaries_;
+ int allocation_base_;
+ int allocation_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterAllocator);
+};
+
// A class than allows the instantiator to allocate temporary registers that are
// cleaned up when scope is closed.
-class BytecodeRegisterAllocator {
+class BytecodeRegisterAllocator final {
public:
- explicit BytecodeRegisterAllocator(BytecodeArrayBuilder* builder);
+ explicit BytecodeRegisterAllocator(Zone* zone,
+ TemporaryRegisterAllocator* allocator);
~BytecodeRegisterAllocator();
Register NewRegister();
@@ -30,10 +82,9 @@ class BytecodeRegisterAllocator {
bool HasConsecutiveAllocations() const { return next_consecutive_count_ > 0; }
private:
- void* operator new(size_t size);
- void operator delete(void* p);
+ TemporaryRegisterAllocator* base_allocator() const { return base_allocator_; }
- BytecodeArrayBuilder* builder_;
+ TemporaryRegisterAllocator* base_allocator_;
ZoneVector<int> allocated_;
int next_consecutive_register_;
int next_consecutive_count_;
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/interpreter/bytecode-register-allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698