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 3 // found in the LICENSE file. 4 5 #include "src/compiler/js-frame-specialization.h" 6 7 #include "src/compiler/js-graph.h" 8 #include "src/compiler/linkage.h" 9 #include "src/frames-inl.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace compiler { 14 15 Reduction JSFrameSpecialization::Reduce(Node* node) { 16 switch (node->opcode()) { 17 case IrOpcode::kOsrValue: 18 return ReduceOsrValue(node); 19 case IrOpcode::kParameter: 20 return ReduceParameter(node); 21 default: 22 break; 23 } 24 return NoChange(); 25 } 26 27 28 Reduction JSFrameSpecialization::ReduceOsrValue(Node* node) { 29 DCHECK_EQ(IrOpcode::kOsrValue, node->opcode()); 30 Handle<Object> value; 31 int const index = OpParameter<int>(node); 32 int const parameters_count = frame()->ComputeParametersCount() + 1; 33 if (index == Linkage::kOsrContextSpillSlotIndex) { 34 value = handle(frame()->context(), isolate()); 35 } else if (index >= parameters_count) { 36 value = handle(frame()->GetExpression(index - parameters_count), isolate()); 37 } else { 38 // The OsrValue index 0 is the receiver. 39 value = 40 handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(), 41 isolate()); 42 } 43 return Replace(jsgraph()->Constant(value)); 44 } 45 46 47 Reduction JSFrameSpecialization::ReduceParameter(Node* node) { 48 DCHECK_EQ(IrOpcode::kParameter, node->opcode()); 49 Handle<Object> value; 50 int const index = ParameterIndexOf(node->op()); 51 int const parameters_count = frame()->ComputeParametersCount() + 1; 52 if (index == Linkage::kJSCallClosureParamIndex) { 53 // The Parameter index references the closure. 54 value = handle(frame()->function(), isolate()); 55 } else if (index == Linkage::GetJSCallArgCountParamIndex(parameters_count)) { 56 // The Parameter index references the parameter count. 57 value = handle(Smi::FromInt(parameters_count - 1), isolate()); 58 } else if (index == Linkage::GetJSCallContextParamIndex(parameters_count)) { 59 // The Parameter index references the context. 60 value = handle(frame()->context(), isolate()); 61 } else { 62 // The Parameter index 0 is the receiver. 63 value = 64 handle(index ? frame()->GetParameter(index - 1) : frame()->receiver(), 65 isolate()); 66 } 67 return Replace(jsgraph()->Constant(value)); 68 } 69 70 71 Isolate* JSFrameSpecialization::isolate() const { return jsgraph()->isolate(); } 72 73 } // namespace compiler 74 } // namespace internal 75 } // namespace v8 76