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

Side by Side Diff: src/interpreter/bytecode-pipeline.h

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments. Created 4 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 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 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_
6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_
7
8 #include "src/interpreter/bytecode-register-allocator.h"
9 #include "src/interpreter/bytecodes.h"
10 #include "src/zone-containers.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace interpreter {
15
16 class BytecodeArrayBuilder;
17 class SourcePositionTableBuilder;
18 class TemporaryRegisterAllocator;
rmcilroy 2016/05/10 11:14:10 All these forward declarations seem to be unused.
oth 2016/05/11 13:17:31 Done.
19
20 class BytecodeNodeAllocator;
21
22 // Source code position information.
23 class BytecodeSourceInfo final {
24 public:
25 static const int kUninitializedPosition = -1;
26
27 BytecodeSourceInfo(int position = kUninitializedPosition,
28 bool is_statement = false)
29 : source_position_(position), is_statement_(is_statement) {}
30
31 // Combine later source info with current.
32 void Update(const BytecodeSourceInfo& entry);
33
34 int source_position() const {
35 DCHECK(is_valid());
36 return source_position_;
37 }
38
39 bool is_statement() const { return is_valid() && is_statement_; }
40
41 bool is_valid() const { return source_position_ != kUninitializedPosition; }
42 void set_invalid() { source_position_ = kUninitializedPosition; }
43
44 bool operator==(const BytecodeSourceInfo& other) const {
45 return source_position_ == other.source_position_ &&
46 is_statement_ == other.is_statement_;
47 }
48 bool operator!=(const BytecodeSourceInfo& other) const {
49 return source_position_ != other.source_position_ ||
50 is_statement_ != other.is_statement_;
51 }
52
53 private:
54 int source_position_;
55 bool is_statement_;
56
57 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo);
58 };
59
60 // A container for a generated bytecode, it's operands, and source information.
61 // These must be allocated by a BytecodeNodeAllocator instance.
62 class BytecodeNode final : ZoneObject {
63 public:
64 // Print to stream.
65 void Print(std::ostream& os);
66
67 // Return the size when this node is serialized to a bytecode array.
68 size_t Size() const;
69
70 // Return to node to allocator for re-use.
71 void Release();
72
73 Bytecode bytecode() const { return bytecode_; }
74 void set_bytecode(Bytecode bytecode);
75 void set_bytecode(Bytecode bytecode, uint32_t operand0,
76 OperandScale operand_scale);
77 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
78 OperandScale operand_scale);
79 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
80 uint32_t operand2, OperandScale operand_scale);
81 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
82 uint32_t operand2, uint32_t operand3,
83 OperandScale operand_scale);
84
85 // Replaces the associated bytecode with an operand-compatible
86 // equivalent or Nop.
87 void replace_bytecode(Bytecode bytecode);
88
89 uint32_t* operands() { return operands_; }
90 const uint32_t* operands() const { return operands_; }
91
92 int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); }
93
94 OperandScale operand_scale() const { return operand_scale_; }
95
96 const BytecodeSourceInfo& source_info() const { return source_info_; }
97 BytecodeSourceInfo& source_info() { return source_info_; }
98
99 private:
100 static const int kInvalidPosition = kMinInt;
101 static const size_t kMaxOperands = 4;
102
103 friend class BytecodeNodeAllocator;
104 explicit BytecodeNode(BytecodeNodeAllocator* allocator);
105
106 Bytecode bytecode_;
107 uint32_t operands_[kMaxOperands];
108 OperandScale operand_scale_;
109 BytecodeSourceInfo source_info_;
110 BytecodeNodeAllocator* allocator_;
111 BytecodeNode* next_;
112
113 DISALLOW_COPY_AND_ASSIGN(BytecodeNode);
114 };
115
116 // Allocator for BytecodeNodes that zone allocates them when needed
117 // and maintains a freelist to reduce number of allocations and limit
118 // memory use.
119 class BytecodeNodeAllocator final {
120 public:
121 explicit BytecodeNodeAllocator(Zone* zone)
122 : allocation_count_(0), free_list_(nullptr), zone_(zone) {}
123
124 BytecodeNode* Allocate();
125
126 private:
127 friend class BytecodeNode;
128 static const int kMaxDebugAllocations = 8;
129
130 void Release(BytecodeNode* node);
131
132 Zone* zone() const { return zone_; }
133
134 int allocation_count_;
135 BytecodeNode* free_list_;
136 Zone* zone_;
137
138 DISALLOW_COPY_AND_ASSIGN(BytecodeNodeAllocator);
139 };
140
141 // Interface for bytecode writers.
rmcilroy 2016/05/10 11:14:10 /bytecode writers/bytecode writer pipeline stages/
oth 2016/05/11 13:17:31 Done.
142 class BytecodePipelineStage {
143 public:
144 virtual ~BytecodePipelineStage() {}
145
146 // Flush state for bytecode array offset calculation. Returns the
147 // current size of bytecode array.
148 virtual size_t FlushForOffset() = 0;
149
150 // Signal end of basic block.
151 virtual void LeaveBasicBlock() = 0;
152
153 // Write bytecode into pipeline. The callee owns node from here and
154 // the caller should not hold any references to it.
155 virtual void Write(BytecodeNode* node) = 0;
156 };
157
158 } // namespace interpreter
159 } // namespace internal
160 } // namespace v8
161
162 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698