OLD | NEW |
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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/graph.h" | 6 #include "src/compiler/graph.h" |
| 7 #include "src/compiler/linkage.h" |
7 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/operator-properties.h" | 9 #include "src/compiler/operator-properties.h" |
9 #include "src/compiler/verifier.h" | 10 #include "src/compiler/verifier.h" |
10 #include "src/types-inl.h" | 11 #include "src/types-inl.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 // static | 17 // static |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 287 } |
287 #ifdef DEBUG | 288 #ifdef DEBUG |
288 for (size_t index = 0; index < projection_count; ++index) { | 289 for (size_t index = 0; index < projection_count; ++index) { |
289 DCHECK_NOT_NULL(projections[index]); | 290 DCHECK_NOT_NULL(projections[index]); |
290 } | 291 } |
291 #endif | 292 #endif |
292 } | 293 } |
293 | 294 |
294 | 295 |
295 // static | 296 // static |
| 297 MaybeHandle<Context> NodeProperties::GetSpecializationContext( |
| 298 Node* node, MaybeHandle<Context> context) { |
| 299 switch (node->opcode()) { |
| 300 case IrOpcode::kHeapConstant: |
| 301 return Handle<Context>::cast(OpParameter<Handle<HeapObject>>(node)); |
| 302 case IrOpcode::kParameter: { |
| 303 Node* const start = NodeProperties::GetValueInput(node, 0); |
| 304 DCHECK_EQ(IrOpcode::kStart, start->opcode()); |
| 305 int const index = ParameterIndexOf(node->op()); |
| 306 // The context is always the last parameter to a JavaScript function, and |
| 307 // {Parameter} indices start at -1, so value outputs of {Start} look like |
| 308 // this: closure, receiver, param0, ..., paramN, context. |
| 309 if (index == start->op()->ValueOutputCount() - 2) { |
| 310 return context; |
| 311 } |
| 312 break; |
| 313 } |
| 314 default: |
| 315 break; |
| 316 } |
| 317 return MaybeHandle<Context>(); |
| 318 } |
| 319 |
| 320 |
| 321 // static |
| 322 MaybeHandle<Context> NodeProperties::GetSpecializationNativeContext( |
| 323 Node* node, MaybeHandle<Context> native_context) { |
| 324 while (true) { |
| 325 switch (node->opcode()) { |
| 326 case IrOpcode::kJSCreateBlockContext: |
| 327 case IrOpcode::kJSCreateCatchContext: |
| 328 case IrOpcode::kJSCreateFunctionContext: |
| 329 case IrOpcode::kJSCreateModuleContext: |
| 330 case IrOpcode::kJSCreateScriptContext: |
| 331 case IrOpcode::kJSCreateWithContext: { |
| 332 // Skip over the intermediate contexts, we're only interested in the |
| 333 // very last context in the context chain anyway. |
| 334 node = NodeProperties::GetContextInput(node); |
| 335 break; |
| 336 } |
| 337 case IrOpcode::kHeapConstant: { |
| 338 // Extract the native context from the actual {context}. |
| 339 Handle<Context> context = |
| 340 Handle<Context>::cast(OpParameter<Handle<HeapObject>>(node)); |
| 341 return handle(context->native_context()); |
| 342 } |
| 343 case IrOpcode::kOsrValue: { |
| 344 int const index = OpParameter<int>(node); |
| 345 if (index == Linkage::kOsrContextSpillSlotIndex) { |
| 346 return native_context; |
| 347 } |
| 348 return MaybeHandle<Context>(); |
| 349 } |
| 350 case IrOpcode::kParameter: { |
| 351 Node* const start = NodeProperties::GetValueInput(node, 0); |
| 352 DCHECK_EQ(IrOpcode::kStart, start->opcode()); |
| 353 int const index = ParameterIndexOf(node->op()); |
| 354 // The context is always the last parameter to a JavaScript function, |
| 355 // and {Parameter} indices start at -1, so value outputs of {Start} |
| 356 // look like this: closure, receiver, param0, ..., paramN, context. |
| 357 if (index == start->op()->ValueOutputCount() - 2) { |
| 358 return native_context; |
| 359 } |
| 360 return MaybeHandle<Context>(); |
| 361 } |
| 362 default: |
| 363 return MaybeHandle<Context>(); |
| 364 } |
| 365 } |
| 366 } |
| 367 |
| 368 |
| 369 // static |
| 370 MaybeHandle<JSGlobalObject> NodeProperties::GetSpecializationGlobalObject( |
| 371 Node* node, MaybeHandle<Context> native_context) { |
| 372 Handle<Context> context; |
| 373 if (GetSpecializationNativeContext(node, native_context).ToHandle(&context)) { |
| 374 return handle(context->global_object()); |
| 375 } |
| 376 return MaybeHandle<JSGlobalObject>(); |
| 377 } |
| 378 |
| 379 |
| 380 // static |
296 Type* NodeProperties::GetTypeOrAny(Node* node) { | 381 Type* NodeProperties::GetTypeOrAny(Node* node) { |
297 return IsTyped(node) ? node->type() : Type::Any(); | 382 return IsTyped(node) ? node->type() : Type::Any(); |
298 } | 383 } |
299 | 384 |
300 | 385 |
301 // static | 386 // static |
302 bool NodeProperties::AllValueInputsAreTyped(Node* node) { | 387 bool NodeProperties::AllValueInputsAreTyped(Node* node) { |
303 int input_count = node->op()->ValueInputCount(); | 388 int input_count = node->op()->ValueInputCount(); |
304 for (int index = 0; index < input_count; ++index) { | 389 for (int index = 0; index < input_count; ++index) { |
305 if (!IsTyped(GetValueInput(node, index))) return false; | 390 if (!IsTyped(GetValueInput(node, index))) return false; |
306 } | 391 } |
307 return true; | 392 return true; |
308 } | 393 } |
309 | 394 |
310 | 395 |
311 // static | 396 // static |
312 bool NodeProperties::IsInputRange(Edge edge, int first, int num) { | 397 bool NodeProperties::IsInputRange(Edge edge, int first, int num) { |
313 if (num == 0) return false; | 398 if (num == 0) return false; |
314 int const index = edge.index(); | 399 int const index = edge.index(); |
315 return first <= index && index < first + num; | 400 return first <= index && index < first + num; |
316 } | 401 } |
317 | 402 |
318 } // namespace compiler | 403 } // namespace compiler |
319 } // namespace internal | 404 } // namespace internal |
320 } // namespace v8 | 405 } // namespace v8 |
OLD | NEW |