| 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/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
| 10 #include "src/compiler/scheduler.h" | 10 #include "src/compiler/scheduler.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 Node* ret = MakeNode(common()->Return(3), 3, values); | 114 Node* ret = MakeNode(common()->Return(3), 3, values); |
| 115 schedule()->AddReturn(CurrentBlock(), ret); | 115 schedule()->AddReturn(CurrentBlock(), ret); |
| 116 current_block_ = nullptr; | 116 current_block_ = nullptr; |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, | 120 Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function, |
| 121 Node** args) { | 121 Node** args) { |
| 122 int param_count = | 122 int param_count = |
| 123 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 123 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 124 int input_count = param_count + 3; | 124 int input_count = param_count + 1; |
| 125 Node** buffer = zone()->NewArray<Node*>(input_count); | 125 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 126 int index = 0; | 126 int index = 0; |
| 127 buffer[index++] = function; | 127 buffer[index++] = function; |
| 128 for (int i = 0; i < param_count; i++) { | 128 for (int i = 0; i < param_count; i++) { |
| 129 buffer[index++] = args[i]; | 129 buffer[index++] = args[i]; |
| 130 } | 130 } |
| 131 buffer[index++] = graph()->start(); | |
| 132 buffer[index++] = graph()->start(); | |
| 133 return AddNode(common()->Call(desc), input_count, buffer); | 131 return AddNode(common()->Call(desc), input_count, buffer); |
| 134 } | 132 } |
| 135 | 133 |
| 136 | 134 |
| 137 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, | 135 Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc, |
| 138 Node* function, Node** args, | 136 Node* function, Node** args, |
| 139 Node* frame_state) { | 137 Node* frame_state) { |
| 140 DCHECK(desc->NeedsFrameState()); | 138 DCHECK(desc->NeedsFrameState()); |
| 141 int param_count = | 139 int param_count = |
| 142 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 140 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 143 int input_count = param_count + 4; | 141 int input_count = param_count + 2; |
| 144 Node** buffer = zone()->NewArray<Node*>(input_count); | 142 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 145 int index = 0; | 143 int index = 0; |
| 146 buffer[index++] = function; | 144 buffer[index++] = function; |
| 147 for (int i = 0; i < param_count; i++) { | 145 for (int i = 0; i < param_count; i++) { |
| 148 buffer[index++] = args[i]; | 146 buffer[index++] = args[i]; |
| 149 } | 147 } |
| 150 buffer[index++] = frame_state; | 148 buffer[index++] = frame_state; |
| 151 buffer[index++] = graph()->start(); | |
| 152 buffer[index++] = graph()->start(); | |
| 153 return AddNode(common()->Call(desc), input_count, buffer); | 149 return AddNode(common()->Call(desc), input_count, buffer); |
| 154 } | 150 } |
| 155 | 151 |
| 156 | 152 |
| 157 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function, | 153 Node* RawMachineAssembler::CallRuntime1(Runtime::FunctionId function, |
| 158 Node* arg1, Node* context) { | 154 Node* arg1, Node* context) { |
| 159 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( | 155 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( |
| 160 zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags); | 156 zone(), function, 1, Operator::kNoProperties, CallDescriptor::kNoFlags); |
| 161 | 157 |
| 162 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 158 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 163 Node* ref = AddNode( | 159 Node* ref = AddNode( |
| 164 common()->ExternalConstant(ExternalReference(function, isolate()))); | 160 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 165 Node* arity = Int32Constant(1); | 161 Node* arity = Int32Constant(1); |
| 166 | 162 |
| 167 return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context, | 163 return AddNode(common()->Call(descriptor), centry, arg1, ref, arity, context); |
| 168 graph()->start(), graph()->start()); | |
| 169 } | 164 } |
| 170 | 165 |
| 171 | 166 |
| 172 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function, | 167 Node* RawMachineAssembler::CallRuntime2(Runtime::FunctionId function, |
| 173 Node* arg1, Node* arg2, Node* context) { | 168 Node* arg1, Node* arg2, Node* context) { |
| 174 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( | 169 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( |
| 175 zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags); | 170 zone(), function, 2, Operator::kNoProperties, CallDescriptor::kNoFlags); |
| 176 | 171 |
| 177 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 172 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 178 Node* ref = AddNode( | 173 Node* ref = AddNode( |
| 179 common()->ExternalConstant(ExternalReference(function, isolate()))); | 174 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 180 Node* arity = Int32Constant(2); | 175 Node* arity = Int32Constant(2); |
| 181 | 176 |
| 182 return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity, | 177 return AddNode(common()->Call(descriptor), centry, arg1, arg2, ref, arity, |
| 183 context, graph()->start(), graph()->start()); | 178 context); |
| 184 } | 179 } |
| 185 | 180 |
| 186 | 181 |
| 187 Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function, | 182 Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function, |
| 188 Node* arg1, Node* arg2, Node* arg3, | 183 Node* arg1, Node* arg2, Node* arg3, |
| 189 Node* arg4, Node* context) { | 184 Node* arg4, Node* context) { |
| 190 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( | 185 CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor( |
| 191 zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags); | 186 zone(), function, 4, Operator::kNoProperties, CallDescriptor::kNoFlags); |
| 192 | 187 |
| 193 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 188 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 194 Node* ref = AddNode( | 189 Node* ref = AddNode( |
| 195 common()->ExternalConstant(ExternalReference(function, isolate()))); | 190 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 196 Node* arity = Int32Constant(4); | 191 Node* arity = Int32Constant(4); |
| 197 | 192 |
| 198 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4, | 193 return AddNode(common()->Call(descriptor), centry, arg1, arg2, arg3, arg4, |
| 199 ref, arity, context, graph()->start(), graph()->start()); | 194 ref, arity, context); |
| 200 } | 195 } |
| 201 | 196 |
| 202 | 197 |
| 203 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, | 198 Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function, |
| 204 Node** args) { | 199 Node** args) { |
| 205 int param_count = | 200 int param_count = |
| 206 static_cast<int>(desc->GetMachineSignature()->parameter_count()); | 201 static_cast<int>(desc->GetMachineSignature()->parameter_count()); |
| 207 int input_count = param_count + 3; | 202 int input_count = param_count + 1; |
| 208 Node** buffer = zone()->NewArray<Node*>(input_count); | 203 Node** buffer = zone()->NewArray<Node*>(input_count); |
| 209 int index = 0; | 204 int index = 0; |
| 210 buffer[index++] = function; | 205 buffer[index++] = function; |
| 211 for (int i = 0; i < param_count; i++) { | 206 for (int i = 0; i < param_count; i++) { |
| 212 buffer[index++] = args[i]; | 207 buffer[index++] = args[i]; |
| 213 } | 208 } |
| 214 buffer[index++] = graph()->start(); | |
| 215 buffer[index++] = graph()->start(); | |
| 216 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); | 209 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); |
| 217 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); | 210 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
| 218 schedule()->AddTailCall(CurrentBlock(), tail_call); | 211 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 219 current_block_ = nullptr; | 212 current_block_ = nullptr; |
| 220 return tail_call; | 213 return tail_call; |
| 221 } | 214 } |
| 222 | 215 |
| 223 | 216 |
| 224 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, | 217 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, |
| 225 Node* arg1, Node* context) { | 218 Node* arg1, Node* context) { |
| 226 const int kArity = 1; | 219 const int kArity = 1; |
| 227 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 220 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 228 zone(), function, kArity, Operator::kNoProperties, | 221 zone(), function, kArity, Operator::kNoProperties, |
| 229 CallDescriptor::kSupportsTailCalls); | 222 CallDescriptor::kSupportsTailCalls); |
| 230 | 223 |
| 231 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 224 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 232 Node* ref = AddNode( | 225 Node* ref = AddNode( |
| 233 common()->ExternalConstant(ExternalReference(function, isolate()))); | 226 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 234 Node* arity = Int32Constant(kArity); | 227 Node* arity = Int32Constant(kArity); |
| 235 | 228 |
| 236 Node* nodes[] = {centry, arg1, ref, arity, context, graph()->start(), | 229 Node* nodes[] = {centry, arg1, ref, arity, context}; |
| 237 graph()->start()}; | |
| 238 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | 230 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
| 239 | 231 |
| 240 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); | 232 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
| 241 schedule()->AddTailCall(CurrentBlock(), tail_call); | 233 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 242 current_block_ = nullptr; | 234 current_block_ = nullptr; |
| 243 return tail_call; | 235 return tail_call; |
| 244 } | 236 } |
| 245 | 237 |
| 246 | 238 |
| 247 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, | 239 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, |
| 248 Node* arg1, Node* arg2, | 240 Node* arg1, Node* arg2, |
| 249 Node* context) { | 241 Node* context) { |
| 250 const int kArity = 2; | 242 const int kArity = 2; |
| 251 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 243 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 252 zone(), function, kArity, Operator::kNoProperties, | 244 zone(), function, kArity, Operator::kNoProperties, |
| 253 CallDescriptor::kSupportsTailCalls); | 245 CallDescriptor::kSupportsTailCalls); |
| 254 | 246 |
| 255 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 247 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
| 256 Node* ref = AddNode( | 248 Node* ref = AddNode( |
| 257 common()->ExternalConstant(ExternalReference(function, isolate()))); | 249 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 258 Node* arity = Int32Constant(kArity); | 250 Node* arity = Int32Constant(kArity); |
| 259 | 251 |
| 260 Node* nodes[] = { | 252 Node* nodes[] = {centry, arg1, arg2, ref, arity, context}; |
| 261 centry, arg1, arg2, ref, arity, context, graph()->start(), | |
| 262 graph()->start()}; | |
| 263 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | 253 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
| 264 | 254 |
| 265 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); | 255 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
| 266 schedule()->AddTailCall(CurrentBlock(), tail_call); | 256 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 267 current_block_ = nullptr; | 257 current_block_ = nullptr; |
| 268 return tail_call; | 258 return tail_call; |
| 269 } | 259 } |
| 270 | 260 |
| 271 | 261 |
| 272 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 262 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
| 273 Node* function) { | 263 Node* function) { |
| 274 MachineSignature::Builder builder(zone(), 1, 0); | 264 MachineSignature::Builder builder(zone(), 1, 0); |
| 275 builder.AddReturn(return_type); | 265 builder.AddReturn(return_type); |
| 276 const CallDescriptor* descriptor = | 266 const CallDescriptor* descriptor = |
| 277 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 267 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 278 | 268 |
| 279 return AddNode(common()->Call(descriptor), function, graph()->start(), | 269 return AddNode(common()->Call(descriptor), function); |
| 280 graph()->start()); | |
| 281 } | 270 } |
| 282 | 271 |
| 283 | 272 |
| 284 Node* RawMachineAssembler::CallCFunction1(MachineType return_type, | 273 Node* RawMachineAssembler::CallCFunction1(MachineType return_type, |
| 285 MachineType arg0_type, Node* function, | 274 MachineType arg0_type, Node* function, |
| 286 Node* arg0) { | 275 Node* arg0) { |
| 287 MachineSignature::Builder builder(zone(), 1, 1); | 276 MachineSignature::Builder builder(zone(), 1, 1); |
| 288 builder.AddReturn(return_type); | 277 builder.AddReturn(return_type); |
| 289 builder.AddParam(arg0_type); | 278 builder.AddParam(arg0_type); |
| 290 const CallDescriptor* descriptor = | 279 const CallDescriptor* descriptor = |
| 291 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 280 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 292 | 281 |
| 293 return AddNode(common()->Call(descriptor), function, arg0, graph()->start(), | 282 return AddNode(common()->Call(descriptor), function, arg0); |
| 294 graph()->start()); | |
| 295 } | 283 } |
| 296 | 284 |
| 297 | 285 |
| 298 Node* RawMachineAssembler::CallCFunction2(MachineType return_type, | 286 Node* RawMachineAssembler::CallCFunction2(MachineType return_type, |
| 299 MachineType arg0_type, | 287 MachineType arg0_type, |
| 300 MachineType arg1_type, Node* function, | 288 MachineType arg1_type, Node* function, |
| 301 Node* arg0, Node* arg1) { | 289 Node* arg0, Node* arg1) { |
| 302 MachineSignature::Builder builder(zone(), 1, 2); | 290 MachineSignature::Builder builder(zone(), 1, 2); |
| 303 builder.AddReturn(return_type); | 291 builder.AddReturn(return_type); |
| 304 builder.AddParam(arg0_type); | 292 builder.AddParam(arg0_type); |
| 305 builder.AddParam(arg1_type); | 293 builder.AddParam(arg1_type); |
| 306 const CallDescriptor* descriptor = | 294 const CallDescriptor* descriptor = |
| 307 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 295 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 308 | 296 |
| 309 return AddNode(common()->Call(descriptor), function, arg0, arg1, | 297 return AddNode(common()->Call(descriptor), function, arg0, arg1); |
| 310 graph()->start(), graph()->start()); | |
| 311 } | 298 } |
| 312 | 299 |
| 313 | 300 |
| 314 Node* RawMachineAssembler::CallCFunction8( | 301 Node* RawMachineAssembler::CallCFunction8( |
| 315 MachineType return_type, MachineType arg0_type, MachineType arg1_type, | 302 MachineType return_type, MachineType arg0_type, MachineType arg1_type, |
| 316 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type, | 303 MachineType arg2_type, MachineType arg3_type, MachineType arg4_type, |
| 317 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type, | 304 MachineType arg5_type, MachineType arg6_type, MachineType arg7_type, |
| 318 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4, | 305 Node* function, Node* arg0, Node* arg1, Node* arg2, Node* arg3, Node* arg4, |
| 319 Node* arg5, Node* arg6, Node* arg7) { | 306 Node* arg5, Node* arg6, Node* arg7) { |
| 320 MachineSignature::Builder builder(zone(), 1, 8); | 307 MachineSignature::Builder builder(zone(), 1, 8); |
| 321 builder.AddReturn(return_type); | 308 builder.AddReturn(return_type); |
| 322 builder.AddParam(arg0_type); | 309 builder.AddParam(arg0_type); |
| 323 builder.AddParam(arg1_type); | 310 builder.AddParam(arg1_type); |
| 324 builder.AddParam(arg2_type); | 311 builder.AddParam(arg2_type); |
| 325 builder.AddParam(arg3_type); | 312 builder.AddParam(arg3_type); |
| 326 builder.AddParam(arg4_type); | 313 builder.AddParam(arg4_type); |
| 327 builder.AddParam(arg5_type); | 314 builder.AddParam(arg5_type); |
| 328 builder.AddParam(arg6_type); | 315 builder.AddParam(arg6_type); |
| 329 builder.AddParam(arg7_type); | 316 builder.AddParam(arg7_type); |
| 330 Node* args[] = {function, | 317 Node* args[] = {function, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7}; |
| 331 arg0, | |
| 332 arg1, | |
| 333 arg2, | |
| 334 arg3, | |
| 335 arg4, | |
| 336 arg5, | |
| 337 arg6, | |
| 338 arg7, | |
| 339 graph()->start(), | |
| 340 graph()->start()}; | |
| 341 const CallDescriptor* descriptor = | 318 const CallDescriptor* descriptor = |
| 342 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 319 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
| 343 return AddNode(common()->Call(descriptor), arraysize(args), args); | 320 return AddNode(common()->Call(descriptor), arraysize(args), args); |
| 344 } | 321 } |
| 345 | 322 |
| 346 | 323 |
| 347 void RawMachineAssembler::Bind(RawMachineLabel* label) { | 324 void RawMachineAssembler::Bind(RawMachineLabel* label) { |
| 348 DCHECK(current_block_ == nullptr); | 325 DCHECK(current_block_ == nullptr); |
| 349 DCHECK(!label->bound_); | 326 DCHECK(!label->bound_); |
| 350 label->bound_ = true; | 327 label->bound_ = true; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 367 |
| 391 RawMachineLabel::RawMachineLabel() | 368 RawMachineLabel::RawMachineLabel() |
| 392 : block_(NULL), used_(false), bound_(false) {} | 369 : block_(NULL), used_(false), bound_(false) {} |
| 393 | 370 |
| 394 | 371 |
| 395 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } | 372 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } |
| 396 | 373 |
| 397 } // namespace compiler | 374 } // namespace compiler |
| 398 } // namespace internal | 375 } // namespace internal |
| 399 } // namespace v8 | 376 } // namespace v8 |
| OLD | NEW |