Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/raw-machine-assembler.h" | 5 #include "src/compiler/raw-machine-assembler.h" |
| 6 | 6 |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/compiler/pipeline.h" | 8 #include "src/compiler/pipeline.h" |
| 9 #include "src/compiler/scheduler.h" | 9 #include "src/compiler/scheduler.h" |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 BasicBlock* default_block = Use(default_label); | 88 BasicBlock* default_block = Use(default_label); |
| 89 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node); | 89 Node* default_node = graph()->NewNode(common()->IfDefault(), switch_node); |
| 90 schedule()->AddNode(default_block, default_node); | 90 schedule()->AddNode(default_block, default_node); |
| 91 succ_blocks[case_count] = default_block; | 91 succ_blocks[case_count] = default_block; |
| 92 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count); | 92 schedule()->AddSwitch(CurrentBlock(), switch_node, succ_blocks, succ_count); |
| 93 current_block_ = nullptr; | 93 current_block_ = nullptr; |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 void RawMachineAssembler::Return(Node* value) { | 97 void RawMachineAssembler::Return(Node* value) { |
| 98 Node* ret = graph()->NewNode(common()->Return(), value); | 98 Node* ret = MakeNode(common()->Return(), 1, &value); |
| 99 schedule()->AddReturn(CurrentBlock(), ret); | 99 schedule()->AddReturn(CurrentBlock(), ret); |
| 100 current_block_ = nullptr; | 100 current_block_ = nullptr; |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, | 104 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, |
| 105 Node** args) { | 105 Node** args) { |
| 106 int param_count = | 106 int param_count = |
| 107 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 107 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 108 int input_count = param_count + 3; | 108 int input_count = param_count + 3; |
| 109 Node** buffer = zone()->NewArray<Node*>(input_count); | 109 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 110 int index = 0; | 110 int index = 0; |
| 111 buffer[index++] = function; | 111 buffer[index++] = function; |
| 112 for (int i = 0; i < param_count; i++) { | 112 for (int i = 0; i < param_count; i++) { |
| 113 buffer[index++] = args[i]; | 113 buffer[index++] = args[i]; |
| 114 } | 114 } |
| 115 buffer[index++] = graph()->start(); | 115 buffer[index++] = graph()->start(); |
| 116 buffer[index++] = graph()->start(); | 116 buffer[index++] = graph()->start(); |
| 117 Node* call = graph()->NewNode(common()->Call(desc), input_count, buffer); | 117 return NewNode(common()->Call(desc), input_count, buffer); |
| 118 schedule()->AddNode(CurrentBlock(), call); | |
| 119 return call; | |
| 120 } | 118 } |
| 121 | 119 |
| 122 | 120 |
| 123 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, | 121 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, |
| 124 Node* function, Node** args, | 122 Node* function, Node** args, |
| 125 Node* frame_state) { | 123 Node* frame_state) { |
| 126 DCHECK(desc->NeedsFrameState()); | 124 DCHECK(desc->NeedsFrameState()); |
| 127 int param_count = | 125 int param_count = |
| 128 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 126 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 129 int input_count = param_count + 4; | 127 int input_count = param_count + 4; |
| 130 Node** buffer = zone()->NewArray<Node*>(input_count); | 128 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 131 int index = 0; | 129 int index = 0; |
| 132 buffer[index++] = function; | 130 buffer[index++] = function; |
| 133 for (int i = 0; i < param_count; i++) { | 131 for (int i = 0; i < param_count; i++) { |
| 134 buffer[index++] = args[i]; | 132 buffer[index++] = args[i]; |
| 135 } | 133 } |
| 136 buffer[index++] = frame_state; | 134 buffer[index++] = frame_state; |
| 137 buffer[index++] = graph()->start(); | 135 buffer[index++] = graph()->start(); |
| 138 buffer[index++] = graph()->start(); | 136 buffer[index++] = graph()->start(); |
| 139 Node* call = graph()->NewNode(common()->Call(desc), input_count, buffer); | 137 return NewNode(common()->Call(desc), input_count, buffer); |
| 140 schedule()->AddNode(CurrentBlock(), call); | |
| 141 return call; | |
| 142 } | 138 } |
| 143 | 139 |
| 144 | 140 |
| 145 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, | 141 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, |
| 146 Node** args) { | 142 Node** args) { |
| 147 int param_count = | 143 int param_count = |
| 148 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 144 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 149 int input_count = param_count + 3; | 145 int input_count = param_count + 3; |
| 150 Node** buffer = zone()->NewArray<Node*>(input_count); | 146 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 151 int index = 0; | 147 int index = 0; |
| 152 buffer[index++] = function; | 148 buffer[index++] = function; |
| 153 for (int i = 0; i < param_count; i++) { | 149 for (int i = 0; i < param_count; i++) { |
| 154 buffer[index++] = args[i]; | 150 buffer[index++] = args[i]; |
| 155 } | 151 } |
| 156 buffer[index++] = graph()->start(); | 152 buffer[index++] = graph()->start(); |
| 157 buffer[index++] = graph()->start(); | 153 buffer[index++] = graph()->start(); |
| 158 Node* tail_call = | 154 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); |
| 159 graph()->NewNode(common()->TailCall(desc), input_count, buffer); | |
| 160 schedule()->AddTailCall(CurrentBlock(), tail_call); | 155 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 161 return tail_call; | 156 return tail_call; |
| 162 } | 157 } |
| 163 | 158 |
| 164 | 159 |
| 165 Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver, | 160 Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver, |
| 166 Node* context, Node* frame_state, | 161 Node* context, Node* frame_state, |
| 167 CallFunctionFlags flags) { | 162 CallFunctionFlags flags) { |
| 168 Callable callable = CodeFactory::CallFunction(isolate(), 0, flags); | 163 Callable callable = CodeFactory::CallFunction(isolate(), 0, flags); |
| 169 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 164 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 170 isolate(), zone(), callable.descriptor(), 1, | 165 isolate(), zone(), callable.descriptor(), 1, |
| 171 CallDescriptor::kNeedsFrameState, Operator::kNoProperties); | 166 CallDescriptor::kNeedsFrameState, Operator::kNoProperties); |
| 172 Node* stub_code = HeapConstant(callable.code()); | 167 Node* stub_code = HeapConstant(callable.code()); |
| 173 Node* call = graph()->NewNode(common()->Call(desc), stub_code, function, | 168 return NewNode(common()->Call(desc), stub_code, function, receiver, context, |
| 174 receiver, context, frame_state, | 169 frame_state, graph()->start(), graph()->start()); |
| 175 graph()->start(), graph()->start()); | |
| 176 schedule()->AddNode(CurrentBlock(), call); | |
| 177 return call; | |
| 178 } | 170 } |
| 179 | 171 |
| 180 | 172 |
| 181 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function, | 173 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function, |
| 182 Node* arg1, Node* context) { | 174 Node* arg1, Node* context) { |
| 183 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( | 175 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( |
| 184 zone(), function, 1, Operator::kNoProperties, false); | 176 zone(), function, 1, Operator::kNoProperties, false); |
| 185 | 177 |
| 186 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 178 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 187 Node* ref = NewNode( | 179 Node* ref = NewNode( |
| 188 common()->ExternalConstant(ExternalReference(function, isolate()))); | 180 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 189 Node* arity = Int32Constant(1); | 181 Node* arity = Int32Constant(1); |
| 190 | 182 |
| 191 Node* call = | 183 return NewNode(common()->Call(descriptor), centry, arg1, ref, arity, context, |
|
Benedikt Meurer
2015/09/23 06:57:12
Nit: Rename NewNode to AddNode.
Jarin
2015/09/23 07:09:34
Done.
| |
| 192 graph()->NewNode(common()->Call(descriptor), centry, arg1, ref, arity, | 184 graph()->start(), graph()->start()); |
| 193 context, graph()->start(), graph()->start()); | |
| 194 schedule()->AddNode(CurrentBlock(), call); | |
| 195 return call; | |
| 196 } | 185 } |
| 197 | 186 |
| 198 | 187 |
| 199 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function, | 188 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function, |
| 200 Node* arg1, Node* arg2, Node* context) { | 189 Node* arg1, Node* arg2, Node* context) { |
| 201 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( | 190 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( |
| 202 zone(), function, 2, Operator::kNoProperties, false); | 191 zone(), function, 2, Operator::kNoProperties, false); |
| 203 | 192 |
| 204 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 193 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 205 Node* ref = NewNode( | 194 Node* ref = NewNode( |
| 206 common()->ExternalConstant(ExternalReference(function, isolate()))); | 195 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 207 Node* arity = Int32Constant(2); | 196 Node* arity = Int32Constant(2); |
| 208 | 197 |
| 209 Node* call = | 198 return NewNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity, |
| 210 graph()->NewNode(common()->Call(descriptor), centry, arg1, arg2, ref, | 199 context, graph()->start(), graph()->start()); |
| 211 arity, context, graph()->start(), graph()->start()); | |
| 212 schedule()->AddNode(CurrentBlock(), call); | |
| 213 return call; | |
| 214 } | 200 } |
| 215 | 201 |
| 216 | 202 |
| 217 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 203 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
| 218 Node* function) { | 204 Node* function) { |
| 219 MachineSignature::Builder builder(zone(), 1, 0); | 205 MachineSignature::Builder builder(zone(), 1, 0); |
| 220 builder.AddReturn(return_type); | 206 builder.AddReturn(return_type); |
| 221 const CallDescriptor* descriptor = | 207 const CallDescriptor* descriptor = |
| 222 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 208 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 223 | 209 |
| 224 Node* call = graph()->NewNode(common()->Call(descriptor), function, | 210 return NewNode(common()->Call(descriptor), function, graph()->start(), |
| 225 graph()->start(), graph()->start()); | 211 graph()->start()); |
| 226 schedule()->AddNode(CurrentBlock(), call); | |
| 227 return call; | |
| 228 } | 212 } |
| 229 | 213 |
| 230 | 214 |
| 231 Node* RawMachineAssembler::CallCFunction1(MachineType return_type, | 215 Node* RawMachineAssembler::CallCFunction1(MachineType return_type, |
| 232 MachineType arg0_type, Node* function, | 216 MachineType arg0_type, Node* function, |
| 233 Node* arg0) { | 217 Node* arg0) { |
| 234 MachineSignature::Builder builder(zone(), 1, 1); | 218 MachineSignature::Builder builder(zone(), 1, 1); |
| 235 builder.AddReturn(return_type); | 219 builder.AddReturn(return_type); |
| 236 builder.AddParam(arg0_type); | 220 builder.AddParam(arg0_type); |
| 237 const CallDescriptor* descriptor = | 221 const CallDescriptor* descriptor = |
| 238 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 222 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 239 | 223 |
| 240 Node* call = graph()->NewNode(common()->Call(descriptor), function, arg0, | 224 return NewNode(common()->Call(descriptor), function, arg0, graph()->start(), |
| 241 graph()->start(), graph()->start()); | 225 graph()->start()); |
| 242 schedule()->AddNode(CurrentBlock(), call); | |
| 243 return call; | |
| 244 } | 226 } |
| 245 | 227 |
| 246 | 228 |
| 247 Node* RawMachineAssembler::CallCFunction2(MachineType return_type, | 229 Node* RawMachineAssembler::CallCFunction2(MachineType return_type, |
| 248 MachineType arg0_type, | 230 MachineType arg0_type, |
| 249 MachineType arg1_type, Node* function, | 231 MachineType arg1_type, Node* function, |
| 250 Node* arg0, Node* arg1) { | 232 Node* arg0, Node* arg1) { |
| 251 MachineSignature::Builder builder(zone(), 1, 2); | 233 MachineSignature::Builder builder(zone(), 1, 2); |
| 252 builder.AddReturn(return_type); | 234 builder.AddReturn(return_type); |
| 253 builder.AddParam(arg0_type); | 235 builder.AddParam(arg0_type); |
| 254 builder.AddParam(arg1_type); | 236 builder.AddParam(arg1_type); |
| 255 const CallDescriptor* descriptor = | 237 const CallDescriptor* descriptor = |
| 256 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 238 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 257 | 239 |
| 258 Node* call = graph()->NewNode(common()->Call(descriptor), function, arg0, | 240 return NewNode(common()->Call(descriptor), function, arg0, arg1, |
| 259 arg1, graph()->start(), graph()->start()); | 241 graph()->start(), graph()->start()); |
| 260 schedule()->AddNode(CurrentBlock(), call); | |
| 261 return call; | |
| 262 } | 242 } |
| 263 | 243 |
| 264 | 244 |
| 265 Node* RawMachineAssembler::CallCFunction8( | 245 Node* RawMachineAssembler::CallCFunction8( |
| 266 MachineType return_type, MachineType arg0_type, MachineType arg1_type, | 246 MachineType return_type, MachineType arg0_type, MachineType arg1_type, |
| 267 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type, | 247 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type, |
| 268 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type, | 248 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type, |
| 269 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4, | 249 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4, |
| 270 Node* arg5, Node* arg6, Node* arg7) { | 250 Node* arg5, Node* arg6, Node* arg7) { |
| 271 MachineSignature::Builder builder(zone(), 1, 8); | 251 MachineSignature::Builder builder(zone(), 1, 8); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 284 arg2, | 264 arg2, |
| 285 arg3, | 265 arg3, |
| 286 arg4, | 266 arg4, |
| 287 arg5, | 267 arg5, |
| 288 arg6, | 268 arg6, |
| 289 arg7, | 269 arg7, |
| 290 graph()->start(), | 270 graph()->start(), |
| 291 graph()->start()}; | 271 graph()->start()}; |
| 292 const CallDescriptor* descriptor = | 272 const CallDescriptor* descriptor = |
| 293 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 273 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 294 Node* call = | 274 return NewNode(common()->Call(descriptor), arraysize(args), args); |
| 295 graph()->NewNode(common()->Call(descriptor), arraysize(args), args); | |
| 296 schedule()->AddNode(CurrentBlock(), call); | |
| 297 return call; | |
| 298 } | 275 } |
| 299 | 276 |
| 300 | 277 |
| 301 void RawMachineAssembler::Bind(Label* label) { | 278 void RawMachineAssembler::Bind(Label* label) { |
| 302 DCHECK(current_block_ == nullptr); | 279 DCHECK(current_block_ == nullptr); |
| 303 DCHECK(!label->bound_); | 280 DCHECK(!label->bound_); |
| 304 label->bound_ = true; | 281 label->bound_ = true; |
| 305 current_block_ = EnsureBlock(label); | 282 current_block_ = EnsureBlock(label); |
| 306 } | 283 } |
| 307 | 284 |
| 308 | 285 |
| 309 BasicBlock* RawMachineAssembler::Use(Label* label) { | 286 BasicBlock* RawMachineAssembler::Use(Label* label) { |
| 310 label->used_ = true; | 287 label->used_ = true; |
| 311 return EnsureBlock(label); | 288 return EnsureBlock(label); |
| 312 } | 289 } |
| 313 | 290 |
| 314 | 291 |
| 315 BasicBlock* RawMachineAssembler::EnsureBlock(Label* label) { | 292 BasicBlock* RawMachineAssembler::EnsureBlock(Label* label) { |
| 316 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock(); | 293 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock(); |
| 317 return label->block_; | 294 return label->block_; |
| 318 } | 295 } |
| 319 | 296 |
| 320 | 297 |
| 321 BasicBlock* RawMachineAssembler::CurrentBlock() { | 298 BasicBlock* RawMachineAssembler::CurrentBlock() { |
| 322 DCHECK(current_block_); | 299 DCHECK(current_block_); |
| 323 return current_block_; | 300 return current_block_; |
| 324 } | 301 } |
| 325 | 302 |
| 326 | 303 |
| 304 Node* RawMachineAssembler::AddNode(const Operator* op, int input_count, | |
| 305 Node** inputs) { | |
| 306 DCHECK_NOT_NULL(schedule_); | |
| 307 DCHECK(current_block_ != nullptr); | |
| 308 Node* node = MakeNode(op, input_count, inputs); | |
| 309 schedule()->AddNode(CurrentBlock(), node); | |
| 310 return node; | |
| 311 } | |
| 312 | |
| 313 | |
| 327 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count, | 314 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count, |
| 328 Node** inputs) { | 315 Node** inputs) { |
| 329 DCHECK_NOT_NULL(schedule_); | 316 // The raw machine assembler nodes do not have effect and control inputs, |
| 330 DCHECK(current_block_ != nullptr); | 317 // so we disable checking input counts here. |
| 331 Node* node = graph()->NewNode(op, input_count, inputs); | 318 return graph()->NewNodeUnchecked(op, input_count, inputs); |
| 332 schedule()->AddNode(CurrentBlock(), node); | |
| 333 return node; | |
| 334 } | 319 } |
| 335 | 320 |
| 336 } // namespace compiler | 321 } // namespace compiler |
| 337 } // namespace internal | 322 } // namespace internal |
| 338 } // namespace v8 | 323 } // namespace v8 |
| OLD | NEW |