Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/compiler/simplified-operator-reducer.cc

Issue 768543002: [WIP] TrapHandler 2014/11/27. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | src/compiler/typer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 m.node()->InputAt(0)); 92 m.node()->InputAt(0));
93 } 93 }
94 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0)); 94 if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0));
95 break; 95 break;
96 } 96 }
97 case IrOpcode::kChangeUint32ToTagged: { 97 case IrOpcode::kChangeUint32ToTagged: {
98 Uint32Matcher m(node->InputAt(0)); 98 Uint32Matcher m(node->InputAt(0));
99 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); 99 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value()));
100 break; 100 break;
101 } 101 }
102 case IrOpcode::kLoadElement: { 102 case IrOpcode::kBoundsCheck:
103 ElementAccess access = ElementAccessOf(node->op()); 103 return ReduceBoundsCheck(node);
104 if (access.bounds_check == kTypedArrayBoundsCheck) {
105 NumberMatcher mkey(node->InputAt(1));
106 NumberMatcher 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() >= 0 && 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 NumberMatcher mkey(node->InputAt(1));
122 NumberMatcher 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() >= 0 && 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 }
134 default: 104 default:
135 break; 105 break;
136 } 106 }
137 return NoChange(); 107 return NoChange();
138 } 108 }
109
110
111 namespace {
112
113 // TODO(bmeurer): Move to node-matchers.h/cc
114 class BoundsCheckMatcher FINAL : public NodeMatcher {
115 public:
116 typedef Uint32Matcher Offset;
117 typedef Uint32Matcher Length;
118
119 explicit BoundsCheckMatcher(Node* node)
120 : NodeMatcher(node), offset_(InputAt(0)), length_(InputAt(1)) {
121 DCHECK_EQ(IrOpcode::kBoundsCheck, opcode());
122 }
123
124 Offset const& offset() const { return offset_; }
125 Length const& length() const { return length_; }
126 size_t guard() const { return OpParameter<size_t>(op()); }
127
128 private:
129 Offset const offset_;
130 Length const length_;
131 };
132
133 } // namespace
134
135
136 Reduction SimplifiedOperatorReducer::ReduceBoundsCheck(Node* const node) {
137 BoundsCheckMatcher m(node);
138 if (m.offset().HasValue()) {
139 if (m.length().HasValue()) {
140 return Replace((m.offset().Value() < m.length().Value())
141 ? m.offset().node()
142 : m.length().node());
143 }
144 if (m.offset().Value() <= m.guard()) {
145 return Replace(m.offset().node());
146 }
147 }
148 if (m.offset().IsInt32Add()) {
149 Uint32BinopMatcher moffset(m.offset().node());
150 if (moffset.right().IsInRange(0, m.guard())) {
151 Node* const chk = graph()->NewNode(
152 simplified()->BoundsCheck(m.guard() - moffset.right().Value()),
153 moffset.left().node(), m.length().node());
154 Node* const add =
155 graph()->NewNode(machine()->Int32Add(), chk, moffset.right().node());
156 return Replace(add);
157 }
158 }
159 return NoChange();
160 }
139 161
140 162
141 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, 163 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op,
142 Node* a) { 164 Node* a) {
143 node->set_op(op); 165 node->set_op(op);
144 node->ReplaceInput(0, a); 166 node->ReplaceInput(0, a);
145 return Changed(node); 167 return Changed(node);
146 } 168 }
147 169
148 170
(...skipping 25 matching lines...) Expand all
174 } 196 }
175 197
176 198
177 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { 199 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const {
178 return jsgraph()->machine(); 200 return jsgraph()->machine();
179 } 201 }
180 202
181 } // namespace compiler 203 } // namespace compiler
182 } // namespace internal 204 } // namespace internal
183 } // namespace v8 205 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-operator-reducer.h ('k') | src/compiler/typer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698