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 3 // found in the LICENSE file. 4 5 #include "src/compiler/frame-states.h" 6 #include "src/compiler/js-context-relaxation.h" 7 #include "src/compiler/js-operator.h" 8 #include "src/compiler/node.h" 9 #include "src/compiler/node-properties.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace compiler { 14 15 Reduction JSContextRelaxation::Reduce(Node* node) { 16 switch (node->opcode()) { 17 case IrOpcode::kJSCallFunction: 18 case IrOpcode::kJSToNumber: { 19 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); 20 Node* outer_frame = frame_state; 21 Node* original_context = NodeProperties::GetContextInput(node); 22 Node* candidate_new_context = original_context; 23 do { 24 FrameStateInfo frame_state_info( 25 OpParameter<FrameStateInfo>(outer_frame->op())); 26 const FrameStateFunctionInfo* function_info = 27 frame_state_info.function_info(); 28 if (function_info == nullptr || 29 (function_info->context_calling_mode() == 30 CALL_CHANGES_NATIVE_CONTEXT)) { 31 break; 32 } 33 candidate_new_context = outer_frame->InputAt(kFrameStateContextInput); 34 outer_frame = outer_frame->InputAt(kFrameStateOuterStateInput); 35 } while (outer_frame->opcode() == IrOpcode::kFrameState); 36 37 while (true) { 38 switch (candidate_new_context->opcode()) { 39 case IrOpcode::kParameter: 40 case IrOpcode::kJSCreateModuleContext: 41 case IrOpcode::kJSCreateScriptContext: 42 if (candidate_new_context != original_context) { 43 NodeProperties::ReplaceContextInput(node, candidate_new_context); 44 return Changed(node); 45 } else { 46 return NoChange(); 47 } 48 case IrOpcode::kJSCreateCatchContext: 49 case IrOpcode::kJSCreateWithContext: 50 case IrOpcode::kJSCreateBlockContext: 51 candidate_new_context = 52 NodeProperties::GetContextInput(candidate_new_context); 53 break; 54 default: 55 return NoChange(); 56 } 57 } 58 } 59 default: 60 break; 61 } 62 return NoChange(); 63 } 64 65 } // namespace compiler 66 } // namespace internal 67 } // namespace v8 68