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/generic-node-inl.h" | 5 #include "src/compiler/generic-node-inl.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/machine-operator.h" | 7 #include "src/compiler/machine-operator.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/simplified-operator-reducer.h" | 9 #include "src/compiler/simplified-operator-reducer.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} | 15 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} |
16 | 16 |
17 | 17 |
18 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { | 18 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { |
19 switch (node->opcode()) { | 19 switch (node->opcode()) { |
20 case IrOpcode::kBooleanNot: { | 20 case IrOpcode::kBooleanNot: { |
21 HeapObjectMatcher m(node->InputAt(0)); | 21 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); |
22 if (m.IsKnownGlobal(factory()->false_value())) { | 22 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { |
23 return Replace(jsgraph()->TrueConstant()); | 23 return Replace(jsgraph()->TrueConstant()); |
24 } | 24 } |
25 if (m.IsKnownGlobal(factory()->true_value())) { | 25 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { |
26 return Replace(jsgraph()->FalseConstant()); | 26 return Replace(jsgraph()->FalseConstant()); |
27 } | 27 } |
28 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); | 28 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); |
29 break; | 29 break; |
30 } | 30 } |
31 case IrOpcode::kChangeBitToBool: { | 31 case IrOpcode::kChangeBitToBool: { |
32 Int32Matcher m(node->InputAt(0)); | 32 Int32Matcher m(node->InputAt(0)); |
33 if (m.Is(0)) return Replace(jsgraph()->FalseConstant()); | 33 if (m.Is(0)) return Replace(jsgraph()->FalseConstant()); |
34 if (m.Is(1)) return Replace(jsgraph()->TrueConstant()); | 34 if (m.Is(1)) return Replace(jsgraph()->TrueConstant()); |
35 if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0)); | 35 if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0)); |
36 break; | 36 break; |
37 } | 37 } |
38 case IrOpcode::kChangeBoolToBit: { | 38 case IrOpcode::kChangeBoolToBit: { |
39 HeapObjectMatcher m(node->InputAt(0)); | 39 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); |
40 if (m.IsKnownGlobal(factory()->false_value())) return ReplaceInt32(0); | 40 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { |
41 if (m.IsKnownGlobal(factory()->true_value())) return ReplaceInt32(1); | 41 return ReplaceInt32(0); |
| 42 } |
| 43 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { |
| 44 return ReplaceInt32(1); |
| 45 } |
42 if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0)); | 46 if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0)); |
43 break; | 47 break; |
44 } | 48 } |
45 case IrOpcode::kChangeFloat64ToTagged: { | 49 case IrOpcode::kChangeFloat64ToTagged: { |
46 Float64Matcher m(node->InputAt(0)); | 50 Float64Matcher m(node->InputAt(0)); |
47 if (m.HasValue()) return ReplaceNumber(m.Value()); | 51 if (m.HasValue()) return ReplaceNumber(m.Value()); |
48 break; | 52 break; |
49 } | 53 } |
50 case IrOpcode::kChangeInt32ToTagged: { | 54 case IrOpcode::kChangeInt32ToTagged: { |
51 Int32Matcher m(node->InputAt(0)); | 55 Int32Matcher m(node->InputAt(0)); |
52 if (m.HasValue()) return ReplaceNumber(m.Value()); | 56 if (m.HasValue()) return ReplaceNumber(m.Value()); |
53 break; | 57 break; |
54 } | 58 } |
55 case IrOpcode::kChangeTaggedToFloat64: { | 59 case IrOpcode::kChangeTaggedToFloat64: { |
56 Float64Matcher m(node->InputAt(0)); | 60 NumberMatcher m(node->InputAt(0)); |
57 if (m.HasValue()) return ReplaceFloat64(m.Value()); | 61 if (m.HasValue()) return ReplaceFloat64(m.Value()); |
58 if (m.IsChangeFloat64ToTagged()) return Replace(m.node()->InputAt(0)); | 62 if (m.IsChangeFloat64ToTagged()) return Replace(m.node()->InputAt(0)); |
59 if (m.IsChangeInt32ToTagged()) { | 63 if (m.IsChangeInt32ToTagged()) { |
60 return Change(node, machine()->ChangeInt32ToFloat64(), | 64 return Change(node, machine()->ChangeInt32ToFloat64(), |
61 m.node()->InputAt(0)); | 65 m.node()->InputAt(0)); |
62 } | 66 } |
63 if (m.IsChangeUint32ToTagged()) { | 67 if (m.IsChangeUint32ToTagged()) { |
64 return Change(node, machine()->ChangeUint32ToFloat64(), | 68 return Change(node, machine()->ChangeUint32ToFloat64(), |
65 m.node()->InputAt(0)); | 69 m.node()->InputAt(0)); |
66 } | 70 } |
67 break; | 71 break; |
68 } | 72 } |
69 case IrOpcode::kChangeTaggedToInt32: { | 73 case IrOpcode::kChangeTaggedToInt32: { |
70 Float64Matcher m(node->InputAt(0)); | 74 NumberMatcher m(node->InputAt(0)); |
71 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); | 75 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
72 if (m.IsChangeFloat64ToTagged()) { | 76 if (m.IsChangeFloat64ToTagged()) { |
73 return Change(node, machine()->ChangeFloat64ToInt32(), | 77 return Change(node, machine()->ChangeFloat64ToInt32(), |
74 m.node()->InputAt(0)); | 78 m.node()->InputAt(0)); |
75 } | 79 } |
76 if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0)); | 80 if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0)); |
77 break; | 81 break; |
78 } | 82 } |
79 case IrOpcode::kChangeTaggedToUint32: { | 83 case IrOpcode::kChangeTaggedToUint32: { |
80 Float64Matcher m(node->InputAt(0)); | 84 NumberMatcher m(node->InputAt(0)); |
81 if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value())); | 85 if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value())); |
82 if (m.IsChangeFloat64ToTagged()) { | 86 if (m.IsChangeFloat64ToTagged()) { |
83 return Change(node, machine()->ChangeFloat64ToUint32(), | 87 return Change(node, machine()->ChangeFloat64ToUint32(), |
84 m.node()->InputAt(0)); | 88 m.node()->InputAt(0)); |
85 } | 89 } |
86 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); | 90 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); |
87 break; | 91 break; |
88 } | 92 } |
89 case IrOpcode::kChangeUint32ToTagged: { | 93 case IrOpcode::kChangeUint32ToTagged: { |
90 Uint32Matcher m(node->InputAt(0)); | 94 Uint32Matcher m(node->InputAt(0)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } | 132 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } |
129 | 133 |
130 | 134 |
131 Factory* SimplifiedOperatorReducer::factory() const { | 135 Factory* SimplifiedOperatorReducer::factory() const { |
132 return jsgraph()->isolate()->factory(); | 136 return jsgraph()->isolate()->factory(); |
133 } | 137 } |
134 | 138 |
135 } // namespace compiler | 139 } // namespace compiler |
136 } // namespace internal | 140 } // namespace internal |
137 } // namespace v8 | 141 } // namespace v8 |
OLD | NEW |