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

Side by Side Diff: src/compiler/interpreter-assembler.cc

Issue 1289863003: [interpreter]: Changes to interpreter builtins for accumulator and register file registers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix_interpreter_initialization
Patch Set: Rename incoming_accumulator Created 5 years, 4 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
« no previous file with comments | « src/compiler/interpreter-assembler.h ('k') | src/compiler/linkage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/interpreter-assembler.h" 5 #include "src/compiler/interpreter-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/compiler/graph.h" 9 #include "src/compiler/graph.h"
10 #include "src/compiler/instruction-selector.h" 10 #include "src/compiler/instruction-selector.h"
(...skipping 13 matching lines...) Expand all
24 24
25 25
26 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, 26 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone,
27 interpreter::Bytecode bytecode) 27 interpreter::Bytecode bytecode)
28 : bytecode_(bytecode), 28 : bytecode_(bytecode),
29 raw_assembler_(new RawMachineAssembler( 29 raw_assembler_(new RawMachineAssembler(
30 isolate, new (zone) Graph(zone), 30 isolate, new (zone) Graph(zone),
31 Linkage::GetInterpreterDispatchDescriptor(zone), kMachPtr, 31 Linkage::GetInterpreterDispatchDescriptor(zone), kMachPtr,
32 InstructionSelector::SupportedMachineOperatorFlags())), 32 InstructionSelector::SupportedMachineOperatorFlags())),
33 end_node_(nullptr), 33 end_node_(nullptr),
34 accumulator_(
35 raw_assembler_->Parameter(Linkage::kInterpreterAccumulatorParameter)),
34 code_generated_(false) {} 36 code_generated_(false) {}
35 37
36 38
37 InterpreterAssembler::~InterpreterAssembler() {} 39 InterpreterAssembler::~InterpreterAssembler() {}
38 40
39 41
40 Handle<Code> InterpreterAssembler::GenerateCode() { 42 Handle<Code> InterpreterAssembler::GenerateCode() {
41 DCHECK(!code_generated_); 43 DCHECK(!code_generated_);
42 44
43 End(); 45 End();
44 46
45 Schedule* schedule = raw_assembler_->Export(); 47 Schedule* schedule = raw_assembler_->Export();
46 // TODO(rmcilroy): use a non-testing code generator. 48 // TODO(rmcilroy): use a non-testing code generator.
47 Handle<Code> code = Pipeline::GenerateCodeForTesting( 49 Handle<Code> code = Pipeline::GenerateCodeForTesting(
48 isolate(), raw_assembler_->call_descriptor(), graph(), schedule); 50 isolate(), raw_assembler_->call_descriptor(), graph(), schedule);
49 51
50 #ifdef ENABLE_DISASSEMBLER 52 #ifdef ENABLE_DISASSEMBLER
51 if (FLAG_trace_ignition_codegen) { 53 if (FLAG_trace_ignition_codegen) {
52 OFStream os(stdout); 54 OFStream os(stdout);
53 code->Disassemble(interpreter::Bytecodes::ToString(bytecode_), os); 55 code->Disassemble(interpreter::Bytecodes::ToString(bytecode_), os);
54 os << std::flush; 56 os << std::flush;
55 } 57 }
56 #endif 58 #endif
57 59
58 code_generated_ = true; 60 code_generated_ = true;
59 return code; 61 return code;
60 } 62 }
61 63
62 64
63 Node* InterpreterAssembler::BytecodeArrayPointer() { 65 Node* InterpreterAssembler::GetAccumulator() {
66 return accumulator_;
67 }
68
69
70 void InterpreterAssembler::SetAccumulator(Node* value) {
71 accumulator_ = value;
72 }
73
74
75 Node* InterpreterAssembler::RegisterFileRawPointer() {
76 return raw_assembler_->Parameter(Linkage::kInterpreterRegisterFileParameter);
77 }
78
79
80 Node* InterpreterAssembler::BytecodeArrayTaggedPointer() {
64 return raw_assembler_->Parameter(Linkage::kInterpreterBytecodeArrayParameter); 81 return raw_assembler_->Parameter(Linkage::kInterpreterBytecodeArrayParameter);
65 } 82 }
66 83
67 84
68 Node* InterpreterAssembler::BytecodeOffset() { 85 Node* InterpreterAssembler::BytecodeOffset() {
69 return raw_assembler_->Parameter( 86 return raw_assembler_->Parameter(
70 Linkage::kInterpreterBytecodeOffsetParameter); 87 Linkage::kInterpreterBytecodeOffsetParameter);
71 } 88 }
72 89
73 90
74 Node* InterpreterAssembler::DispatchTablePointer() { 91 Node* InterpreterAssembler::DispatchTableRawPointer() {
75 return raw_assembler_->Parameter(Linkage::kInterpreterDispatchTableParameter); 92 return raw_assembler_->Parameter(Linkage::kInterpreterDispatchTableParameter);
76 } 93 }
77 94
78 95
79 Node* InterpreterAssembler::FramePointer() { 96 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) {
80 return raw_assembler_->LoadFramePointer(); 97 return raw_assembler_->WordShl(index, Int32Constant(kPointerSizeLog2));
81 } 98 }
82 99
83 100
84 Node* InterpreterAssembler::RegisterFrameOffset(int index) { 101 Node* InterpreterAssembler::LoadRegister(Node* reg_index) {
85 DCHECK_LE(index, kMaxRegisterIndex); 102 return raw_assembler_->Load(kMachPtr, RegisterFileRawPointer(),
86 return Int32Constant(kFirstRegisterOffsetFromFp - 103 RegisterFrameOffset(reg_index));
87 (index << kPointerSizeLog2));
88 } 104 }
89 105
90 106
91 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) { 107 Node* InterpreterAssembler::StoreRegister(Node* value, Node* reg_index) {
92 return raw_assembler_->IntPtrSub( 108 return raw_assembler_->Store(kMachPtr, RegisterFileRawPointer(),
93 Int32Constant(kFirstRegisterOffsetFromFp), 109 RegisterFrameOffset(reg_index), value);
94 raw_assembler_->WordShl(index, Int32Constant(kPointerSizeLog2)));
95 } 110 }
96 111
97 112
98 Node* InterpreterAssembler::BytecodeOperand(int delta) { 113 Node* InterpreterAssembler::BytecodeOperand(int delta) {
99 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_)); 114 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_));
100 return raw_assembler_->Load( 115 return raw_assembler_->Load(
101 kMachUint8, BytecodeArrayPointer(), 116 kMachUint8, BytecodeArrayTaggedPointer(),
102 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta))); 117 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta)));
103 } 118 }
104 119
105 120
106 Node* InterpreterAssembler::LoadRegister(int index) { 121 Node* InterpreterAssembler::BytecodeOperandSignExtended(int delta) {
107 return raw_assembler_->Load(kMachPtr, FramePointer(), 122 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_));
108 RegisterFrameOffset(index)); 123 Node* load = raw_assembler_->Load(
124 kMachInt8, BytecodeArrayTaggedPointer(),
125 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta)));
126 // Ensure that we sign extend to full pointer size
127 if (kPointerSize == 8) {
128 load = raw_assembler_->ChangeInt32ToInt64(load);
129 }
130 return load;
109 } 131 }
110 132
111 133
112 Node* InterpreterAssembler::LoadRegister(Node* index) {
113 return raw_assembler_->Load(kMachPtr, FramePointer(),
114 RegisterFrameOffset(index));
115 }
116
117
118 Node* InterpreterAssembler::StoreRegister(Node* value, int index) {
119 return raw_assembler_->Store(kMachPtr, FramePointer(),
120 RegisterFrameOffset(index), value);
121 }
122
123
124 Node* InterpreterAssembler::StoreRegister(Node* value, Node* index) {
125 return raw_assembler_->Store(kMachPtr, FramePointer(),
126 RegisterFrameOffset(index), value);
127 }
128
129
130 void InterpreterAssembler::Return() { 134 void InterpreterAssembler::Return() {
131 Node* exit_trampoline_code_object = 135 Node* exit_trampoline_code_object =
132 HeapConstant(Unique<HeapObject>::CreateImmovable( 136 HeapConstant(Unique<HeapObject>::CreateImmovable(
133 isolate()->builtins()->InterpreterExitTrampoline())); 137 isolate()->builtins()->InterpreterExitTrampoline()));
134 // If the order of the parameters you need to change the call signature below. 138 // If the order of the parameters you need to change the call signature below.
135 STATIC_ASSERT(0 == Linkage::kInterpreterBytecodeOffsetParameter); 139 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter);
136 STATIC_ASSERT(1 == Linkage::kInterpreterBytecodeArrayParameter); 140 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter);
137 STATIC_ASSERT(2 == Linkage::kInterpreterDispatchTableParameter); 141 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter);
138 Node* tail_call = graph()->NewNode( 142 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter);
139 common()->TailCall(call_descriptor()), exit_trampoline_code_object, 143 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter);
140 BytecodeOffset(), BytecodeArrayPointer(), DispatchTablePointer(), 144 Node* tail_call = raw_assembler_->TailCallInterpreterDispatch(
141 graph()->start(), graph()->start()); 145 call_descriptor(), exit_trampoline_code_object, GetAccumulator(),
142 schedule()->AddTailCall(raw_assembler_->CurrentBlock(), tail_call); 146 RegisterFileRawPointer(), BytecodeOffset(), BytecodeArrayTaggedPointer(),
147 DispatchTableRawPointer());
143 // This should always be the end node. 148 // This should always be the end node.
144 SetEndInput(tail_call); 149 SetEndInput(tail_call);
145 } 150 }
146 151
147 152
148 Node* InterpreterAssembler::Advance(int delta) { 153 Node* InterpreterAssembler::Advance(int delta) {
149 return raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(delta)); 154 return raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(delta));
150 } 155 }
151 156
152 157
153 void InterpreterAssembler::Dispatch() { 158 void InterpreterAssembler::Dispatch() {
154 Node* new_bytecode_offset = Advance(interpreter::Bytecodes::Size(bytecode_)); 159 Node* new_bytecode_offset = Advance(interpreter::Bytecodes::Size(bytecode_));
155 Node* target_bytecode = raw_assembler_->Load( 160 Node* target_bytecode = raw_assembler_->Load(
156 kMachUint8, BytecodeArrayPointer(), new_bytecode_offset); 161 kMachUint8, BytecodeArrayTaggedPointer(), new_bytecode_offset);
157 162
158 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion 163 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion
159 // from code object on every dispatch. 164 // from code object on every dispatch.
160 Node* target_code_object = raw_assembler_->Load( 165 Node* target_code_object = raw_assembler_->Load(
161 kMachPtr, DispatchTablePointer(), 166 kMachPtr, DispatchTableRawPointer(),
162 raw_assembler_->Word32Shl(target_bytecode, 167 raw_assembler_->Word32Shl(target_bytecode,
163 Int32Constant(kPointerSizeLog2))); 168 Int32Constant(kPointerSizeLog2)));
164 169
165 // If the order of the parameters you need to change the call signature below. 170 // If the order of the parameters you need to change the call signature below.
166 STATIC_ASSERT(0 == Linkage::kInterpreterBytecodeOffsetParameter); 171 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter);
167 STATIC_ASSERT(1 == Linkage::kInterpreterBytecodeArrayParameter); 172 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter);
168 STATIC_ASSERT(2 == Linkage::kInterpreterDispatchTableParameter); 173 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter);
169 Node* tail_call = graph()->NewNode( 174 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter);
170 common()->TailCall(call_descriptor()), target_code_object, 175 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter);
171 new_bytecode_offset, BytecodeArrayPointer(), DispatchTablePointer(), 176 Node* tail_call = raw_assembler_->TailCallInterpreterDispatch(
172 graph()->start(), graph()->start()); 177 call_descriptor(), target_code_object, GetAccumulator(),
173 schedule()->AddTailCall(raw_assembler_->CurrentBlock(), tail_call); 178 RegisterFileRawPointer(), new_bytecode_offset,
179 BytecodeArrayTaggedPointer(), DispatchTableRawPointer());
174 // This should always be the end node. 180 // This should always be the end node.
175 SetEndInput(tail_call); 181 SetEndInput(tail_call);
176 } 182 }
177 183
178 184
179 void InterpreterAssembler::SetEndInput(Node* input) { 185 void InterpreterAssembler::SetEndInput(Node* input) {
180 DCHECK(!end_node_); 186 DCHECK(!end_node_);
181 end_node_ = input; 187 end_node_ = input;
182 } 188 }
183 189
184 190
185 void InterpreterAssembler::End() { 191 void InterpreterAssembler::End() {
186 DCHECK(end_node_); 192 DCHECK(end_node_);
187 // TODO(rmcilroy): Support more than 1 end input. 193 // TODO(rmcilroy): Support more than 1 end input.
188 Node* end = graph()->NewNode(common()->End(1), end_node_); 194 Node* end = graph()->NewNode(raw_assembler_->common()->End(1), end_node_);
189 graph()->SetEnd(end); 195 graph()->SetEnd(end);
190 } 196 }
191 197
192 198
193 // RawMachineAssembler delegate helpers: 199 // RawMachineAssembler delegate helpers:
194 Isolate* InterpreterAssembler::isolate() { return raw_assembler_->isolate(); } 200 Isolate* InterpreterAssembler::isolate() { return raw_assembler_->isolate(); }
195 201
196 202
197 Graph* InterpreterAssembler::graph() { return raw_assembler_->graph(); } 203 Graph* InterpreterAssembler::graph() { return raw_assembler_->graph(); }
198 204
199 205
200 CallDescriptor* InterpreterAssembler::call_descriptor() const { 206 CallDescriptor* InterpreterAssembler::call_descriptor() const {
201 return raw_assembler_->call_descriptor(); 207 return raw_assembler_->call_descriptor();
202 } 208 }
203 209
204 210
205 Schedule* InterpreterAssembler::schedule() { 211 Schedule* InterpreterAssembler::schedule() {
206 return raw_assembler_->schedule(); 212 return raw_assembler_->schedule();
207 } 213 }
208 214
209 215
210 MachineOperatorBuilder* InterpreterAssembler::machine() {
211 return raw_assembler_->machine();
212 }
213
214
215 CommonOperatorBuilder* InterpreterAssembler::common() {
216 return raw_assembler_->common();
217 }
218
219
220 Node* InterpreterAssembler::Int32Constant(int value) { 216 Node* InterpreterAssembler::Int32Constant(int value) {
221 return raw_assembler_->Int32Constant(value); 217 return raw_assembler_->Int32Constant(value);
222 } 218 }
223 219
224 220
225 Node* InterpreterAssembler::NumberConstant(double value) { 221 Node* InterpreterAssembler::NumberConstant(double value) {
226 return raw_assembler_->NumberConstant(value); 222 return raw_assembler_->NumberConstant(value);
227 } 223 }
228 224
229 225
230 Node* InterpreterAssembler::HeapConstant(Unique<HeapObject> object) { 226 Node* InterpreterAssembler::HeapConstant(Unique<HeapObject> object) {
231 return raw_assembler_->HeapConstant(object); 227 return raw_assembler_->HeapConstant(object);
232 } 228 }
233 229
234
235 } // namespace interpreter 230 } // namespace interpreter
236 } // namespace internal 231 } // namespace internal
237 } // namespace v8 232 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/interpreter-assembler.h ('k') | src/compiler/linkage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698