Chromium Code Reviews| 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/code-assembler.h" | 5 #include "src/compiler/code-assembler.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 202 } |
| 203 IntPtrMatcher m(node); | 203 IntPtrMatcher m(node); |
| 204 if (m.HasValue()) { | 204 if (m.HasValue()) { |
| 205 out_value = Smi::cast(bit_cast<Object*>(m.Value())); | 205 out_value = Smi::cast(bit_cast<Object*>(m.Value())); |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 return false; | 208 return false; |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool CodeAssembler::ToIntPtrConstant(Node* node, intptr_t& out_value) { | 211 bool CodeAssembler::ToIntPtrConstant(Node* node, intptr_t& out_value) { |
| 212 if (node->opcode() == IrOpcode::kBitcastWordToTaggedSigned || | |
| 213 node->opcode() == IrOpcode::kBitcastWordToTagged) { | |
| 214 node = node->InputAt(0); | |
| 215 } | |
| 212 IntPtrMatcher m(node); | 216 IntPtrMatcher m(node); |
| 213 if (m.HasValue()) out_value = m.Value(); | 217 if (m.HasValue()) out_value = m.Value(); |
| 214 return m.HasValue(); | 218 return m.HasValue(); |
| 215 } | 219 } |
| 216 | 220 |
| 217 Node* CodeAssembler::Parameter(int value) { | 221 Node* CodeAssembler::Parameter(int value) { |
| 218 return raw_assembler()->Parameter(value); | 222 return raw_assembler()->Parameter(value); |
| 219 } | 223 } |
| 220 | 224 |
| 221 void CodeAssembler::Return(Node* value) { | 225 void CodeAssembler::Return(Node* value) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 return raw_assembler()->LoadStackPointer(); | 266 return raw_assembler()->LoadStackPointer(); |
| 263 } | 267 } |
| 264 | 268 |
| 265 #define DEFINE_CODE_ASSEMBLER_BINARY_OP(name) \ | 269 #define DEFINE_CODE_ASSEMBLER_BINARY_OP(name) \ |
| 266 Node* CodeAssembler::name(Node* a, Node* b) { \ | 270 Node* CodeAssembler::name(Node* a, Node* b) { \ |
| 267 return raw_assembler()->name(a, b); \ | 271 return raw_assembler()->name(a, b); \ |
| 268 } | 272 } |
| 269 CODE_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_ASSEMBLER_BINARY_OP) | 273 CODE_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_ASSEMBLER_BINARY_OP) |
| 270 #undef DEFINE_CODE_ASSEMBLER_BINARY_OP | 274 #undef DEFINE_CODE_ASSEMBLER_BINARY_OP |
| 271 | 275 |
| 276 Node* CodeAssembler::IntPtrAdd(Node* left, Node* right) { | |
| 277 intptr_t left_constant; | |
| 278 bool is_left_constant = ToIntPtrConstant(left, left_constant); | |
| 279 intptr_t right_constant; | |
| 280 bool is_right_constant = ToIntPtrConstant(right, right_constant); | |
| 281 if (is_left_constant) { | |
| 282 if (is_right_constant) { | |
| 283 intptr_t sum = left_constant + right_constant; | |
| 284 if (sum >= std::numeric_limits<int32_t>::min() && | |
|
Igor Sheludko
2016/12/28 15:57:05
I think we can always return the sum.
danno
2016/12/28 16:05:33
Done.
| |
| 285 sum <= std::numeric_limits<int32_t>::max()) { | |
| 286 return IntPtrConstant(sum); | |
| 287 } | |
| 288 } | |
| 289 if (left_constant == 0) { | |
| 290 return right; | |
| 291 } | |
| 292 } else if (is_right_constant) { | |
| 293 if (right_constant == 0) { | |
| 294 return left; | |
| 295 } | |
| 296 } | |
| 297 return raw_assembler()->IntPtrAdd(left, right); | |
| 298 } | |
| 299 | |
| 300 Node* CodeAssembler::IntPtrSub(Node* left, Node* right) { | |
| 301 intptr_t left_constant; | |
| 302 bool is_left_constant = ToIntPtrConstant(left, left_constant); | |
| 303 intptr_t right_constant; | |
| 304 bool is_right_constant = ToIntPtrConstant(right, right_constant); | |
| 305 if (is_left_constant) { | |
| 306 if (is_right_constant) { | |
| 307 intptr_t diff = left_constant - right_constant; | |
| 308 if (diff >= std::numeric_limits<int32_t>::min() && | |
|
Igor Sheludko
2016/12/28 15:57:05
Same here.
danno
2016/12/28 16:05:33
Done.
| |
| 309 diff <= std::numeric_limits<int32_t>::max()) { | |
| 310 return IntPtrConstant(diff); | |
| 311 } | |
| 312 } | |
| 313 } else if (is_right_constant) { | |
| 314 if (right_constant == 0) { | |
| 315 return left; | |
| 316 } | |
| 317 } | |
| 318 return raw_assembler()->IntPtrSub(left, right); | |
| 319 } | |
| 320 | |
| 272 Node* CodeAssembler::WordShl(Node* value, int shift) { | 321 Node* CodeAssembler::WordShl(Node* value, int shift) { |
| 273 return (shift != 0) ? raw_assembler()->WordShl(value, IntPtrConstant(shift)) | 322 return (shift != 0) ? raw_assembler()->WordShl(value, IntPtrConstant(shift)) |
| 274 : value; | 323 : value; |
| 275 } | 324 } |
| 276 | 325 |
| 277 Node* CodeAssembler::WordShr(Node* value, int shift) { | 326 Node* CodeAssembler::WordShr(Node* value, int shift) { |
| 278 return (shift != 0) ? raw_assembler()->WordShr(value, IntPtrConstant(shift)) | 327 return (shift != 0) ? raw_assembler()->WordShr(value, IntPtrConstant(shift)) |
| 279 : value; | 328 : value; |
| 280 } | 329 } |
| 281 | 330 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 } | 803 } |
| 755 } | 804 } |
| 756 } | 805 } |
| 757 | 806 |
| 758 bound_ = true; | 807 bound_ = true; |
| 759 } | 808 } |
| 760 | 809 |
| 761 } // namespace compiler | 810 } // namespace compiler |
| 762 } // namespace internal | 811 } // namespace internal |
| 763 } // namespace v8 | 812 } // namespace v8 |
| OLD | NEW |