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(JSGraph* jsgraph) |
| 16 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
| 17 |
| 18 |
15 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} | 19 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} |
16 | 20 |
17 | 21 |
18 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { | 22 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { |
19 switch (node->opcode()) { | 23 switch (node->opcode()) { |
20 case IrOpcode::kBooleanNot: { | 24 case IrOpcode::kBooleanNot: { |
21 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); | 25 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); |
22 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { | 26 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { |
23 return Replace(jsgraph()->TrueConstant()); | 27 return Replace(jsgraph()->TrueConstant()); |
24 } | 28 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 m.node()->InputAt(0)); | 92 m.node()->InputAt(0)); |
89 } | 93 } |
90 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); | 94 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); |
91 break; | 95 break; |
92 } | 96 } |
93 case IrOpcode::kChangeUint32ToTagged: { | 97 case IrOpcode::kChangeUint32ToTagged: { |
94 Uint32Matcher m(node->InputAt(0)); | 98 Uint32Matcher m(node->InputAt(0)); |
95 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); | 99 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); |
96 break; | 100 break; |
97 } | 101 } |
| 102 case IrOpcode::kLoadElement: { |
| 103 ElementAccess access = ElementAccessOf(node->op()); |
| 104 if (access.bounds_check == kTypedArrayBoundsCheck) { |
| 105 NumericValueMatcher mkey(node->InputAt(1)); |
| 106 NumericValueMatcher mlength(node->InputAt(2)); |
| 107 if (mkey.HasValue() && mlength.HasValue()) { |
| 108 // Skip the typed array bounds check if key and length are constant. |
| 109 if (mkey.Value() < mlength.Value()) { |
| 110 access.bounds_check = kNoBoundsCheck; |
| 111 node->set_op(simplified()->LoadElement(access)); |
| 112 return Changed(node); |
| 113 } |
| 114 } |
| 115 } |
| 116 break; |
| 117 } |
| 118 case IrOpcode::kStoreElement: { |
| 119 ElementAccess access = ElementAccessOf(node->op()); |
| 120 if (access.bounds_check == kTypedArrayBoundsCheck) { |
| 121 NumericValueMatcher mkey(node->InputAt(1)); |
| 122 NumericValueMatcher mlength(node->InputAt(2)); |
| 123 if (mkey.HasValue() && mlength.HasValue()) { |
| 124 // Skip the typed array bounds check if key and length are constant. |
| 125 if (mkey.Value() < mlength.Value()) { |
| 126 access.bounds_check = kNoBoundsCheck; |
| 127 node->set_op(simplified()->StoreElement(access)); |
| 128 return Changed(node); |
| 129 } |
| 130 } |
| 131 } |
| 132 break; |
| 133 } |
98 default: | 134 default: |
99 break; | 135 break; |
100 } | 136 } |
101 return NoChange(); | 137 return NoChange(); |
102 } | 138 } |
103 | 139 |
104 | 140 |
105 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, | 141 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, |
106 Node* a) { | 142 Node* a) { |
107 node->set_op(op); | 143 node->set_op(op); |
(...skipping 30 matching lines...) Expand all Loading... |
138 } | 174 } |
139 | 175 |
140 | 176 |
141 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { | 177 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { |
142 return jsgraph()->machine(); | 178 return jsgraph()->machine(); |
143 } | 179 } |
144 | 180 |
145 } // namespace compiler | 181 } // namespace compiler |
146 } // namespace internal | 182 } // namespace internal |
147 } // namespace v8 | 183 } // namespace v8 |
OLD | NEW |