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

Side by Side Diff: src/interpreter/bytecode-register-allocator.cc

Issue 1587033002: [Interpreter] Ensure we always have an outer register allocation scope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_mythri
Patch Set: Similarity 20 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/interpreter/bytecode-register-allocator.h"
6
7 #include "src/interpreter/bytecode-array-builder.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace interpreter {
12
13 BytecodeRegisterAllocator::BytecodeRegisterAllocator(
14 BytecodeArrayBuilder* builder)
15 : builder_(builder),
16 allocated_(builder->zone()),
17 next_consecutive_register_(-1),
18 next_consecutive_count_(-1) {}
19
20
21 BytecodeRegisterAllocator::~BytecodeRegisterAllocator() {
22 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) {
23 builder_->ReturnTemporaryRegister(*i);
24 }
25 allocated_.clear();
26 }
27
28
29 Register BytecodeRegisterAllocator::NewRegister() {
30 int allocated = -1;
31 if (next_consecutive_count_ <= 0) {
32 allocated = builder_->BorrowTemporaryRegister();
33 } else {
34 allocated = builder_->BorrowTemporaryRegisterNotInRange(
35 next_consecutive_register_,
36 next_consecutive_register_ + next_consecutive_count_ - 1);
37 }
38 allocated_.push_back(allocated);
39 return Register(allocated);
40 }
41
42
43 bool BytecodeRegisterAllocator::RegisterIsAllocatedInThisScope(
44 Register reg) const {
45 for (auto i = allocated_.begin(); i != allocated_.end(); i++) {
46 if (*i == reg.index()) return true;
47 }
48 return false;
49 }
50
51
52 void BytecodeRegisterAllocator::PrepareForConsecutiveAllocations(size_t count) {
53 if (static_cast<int>(count) > next_consecutive_count_) {
54 next_consecutive_register_ =
55 builder_->PrepareForConsecutiveTemporaryRegisters(count);
56 next_consecutive_count_ = static_cast<int>(count);
57 }
58 }
59
60
61 Register BytecodeRegisterAllocator::NextConsecutiveRegister() {
62 DCHECK_GE(next_consecutive_register_, 0);
63 DCHECK_GT(next_consecutive_count_, 0);
64 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_);
65 allocated_.push_back(next_consecutive_register_);
66 next_consecutive_count_--;
67 return Register(next_consecutive_register_++);
68 }
69
70 } // namespace interpreter
71 } // namespace internal
72 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-register-allocator.h ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698