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