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

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 333643004: Add range analysis for left-shift smi operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments, added tests Created 6 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 2486 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 }; 2497 };
2498 2498
2499 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { } 2499 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { }
2500 2500
2501 RangeBoundary(const RangeBoundary& other) 2501 RangeBoundary(const RangeBoundary& other)
2502 : ValueObject(), 2502 : ValueObject(),
2503 kind_(other.kind_), 2503 kind_(other.kind_),
2504 value_(other.value_), 2504 value_(other.value_),
2505 offset_(other.offset_) { } 2505 offset_(other.offset_) { }
2506 2506
2507 explicit RangeBoundary(intptr_t val)
2508 : kind_(kConstant), value_(val), offset_(0) { }
2509
2507 RangeBoundary& operator=(const RangeBoundary& other) { 2510 RangeBoundary& operator=(const RangeBoundary& other) {
2508 kind_ = other.kind_; 2511 kind_ = other.kind_;
2509 value_ = other.value_; 2512 value_ = other.value_;
2510 offset_ = other.offset_; 2513 offset_ = other.offset_;
2511 return *this; 2514 return *this;
2512 } 2515 }
2513 2516
2514 static RangeBoundary FromConstant(intptr_t val) { 2517 static RangeBoundary FromConstant(intptr_t val) {
2515 return RangeBoundary(kConstant, val, 0); 2518 return RangeBoundary(val);
2516 } 2519 }
2517 2520
2518 static RangeBoundary NegativeInfinity() { 2521 static RangeBoundary NegativeInfinity() {
2519 return RangeBoundary(kNegativeInfinity, 0, 0); 2522 return RangeBoundary(kNegativeInfinity, 0, 0);
2520 } 2523 }
2521 2524
2522 static RangeBoundary PositiveInfinity() { 2525 static RangeBoundary PositiveInfinity() {
2523 return RangeBoundary(kPositiveInfinity, 0, 0); 2526 return RangeBoundary(kPositiveInfinity, 0, 0);
2524 } 2527 }
2525 2528
(...skipping 21 matching lines...) Expand all
2547 return MinSmi(); 2550 return MinSmi();
2548 } else if (IsPositiveInfinity()) { 2551 } else if (IsPositiveInfinity()) {
2549 return MaxSmi(); 2552 return MaxSmi();
2550 } else if (IsConstant()) { 2553 } else if (IsConstant()) {
2551 if (value() < Smi::kMinValue) return MinSmi(); 2554 if (value() < Smi::kMinValue) return MinSmi();
2552 if (value() > Smi::kMaxValue) return MaxSmi(); 2555 if (value() > Smi::kMaxValue) return MaxSmi();
2553 } 2556 }
2554 return *this; 2557 return *this;
2555 } 2558 }
2556 2559
2560 bool Equals(const RangeBoundary& other) {
2561 return kind_ == other.kind_
2562 && value_ == other.value_
2563 && offset_ == other.offset_;
2564 }
2565
2557 bool IsUnknown() const { return kind_ == kUnknown; } 2566 bool IsUnknown() const { return kind_ == kUnknown; }
2558 bool IsConstant() const { return kind_ == kConstant; } 2567 bool IsConstant() const { return kind_ == kConstant; }
2559 bool IsSymbol() const { return kind_ == kSymbol; } 2568 bool IsSymbol() const { return kind_ == kSymbol; }
2560 bool IsNegativeInfinity() const { return kind_ == kNegativeInfinity; } 2569 bool IsNegativeInfinity() const { return kind_ == kNegativeInfinity; }
2561 bool IsPositiveInfinity() const { return kind_ == kPositiveInfinity; } 2570 bool IsPositiveInfinity() const { return kind_ == kPositiveInfinity; }
2562 bool IsInfinity() const { 2571 bool IsInfinity() const {
2563 return IsNegativeInfinity() || IsPositiveInfinity(); 2572 return IsNegativeInfinity() || IsPositiveInfinity();
2564 } 2573 }
2565 2574
2566 intptr_t value() const { 2575 intptr_t value() const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 const RangeBoundary& overflow) { 2609 const RangeBoundary& overflow) {
2601 ASSERT(a.IsConstant() && b.IsConstant()); 2610 ASSERT(a.IsConstant() && b.IsConstant());
2602 2611
2603 intptr_t result = a.value() - b.value(); 2612 intptr_t result = a.value() - b.value();
2604 if (!Smi::IsValid(result)) { 2613 if (!Smi::IsValid(result)) {
2605 return overflow; 2614 return overflow;
2606 } 2615 }
2607 return RangeBoundary::FromConstant(result); 2616 return RangeBoundary::FromConstant(result);
2608 } 2617 }
2609 2618
2619 static RangeBoundary Shl(const RangeBoundary& value_boundary,
2620 intptr_t shift_count,
2621 const RangeBoundary& overflow) {
2622 ASSERT(value_boundary.IsConstant());
2623 ASSERT(shift_count >= 0);
2624 intptr_t limit = 64 - shift_count;
2625 int64_t value = static_cast<int64_t>(value_boundary.value());
2626 if ((value == 0) ||
2627 (shift_count == 0) ||
2628 ((limit > 0) && (Utils::IsInt(limit, value)))) {
2629 // Result stays in 64 bit range.
2630 int64_t result = value << shift_count;
2631 return Smi::IsValid64(result) ? RangeBoundary(result) : overflow;
2632 }
2633 return overflow;
2634 }
2635
2610 private: 2636 private:
2611 RangeBoundary(Kind kind, intptr_t value, intptr_t offset) 2637 RangeBoundary(Kind kind, intptr_t value, intptr_t offset)
2612 : kind_(kind), value_(value), offset_(offset) { } 2638 : kind_(kind), value_(value), offset_(offset) { }
2613 2639
2614 Kind kind_; 2640 Kind kind_;
2615 intptr_t value_; 2641 intptr_t value_;
2616 intptr_t offset_; 2642 intptr_t offset_;
2617 }; 2643 };
2618 2644
2619 2645
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 bool OnlyLessThanOrEqualTo(intptr_t val) const; 2681 bool OnlyLessThanOrEqualTo(intptr_t val) const;
2656 2682
2657 // Inclusive. 2683 // Inclusive.
2658 bool IsWithin(intptr_t min_int, intptr_t max_int) const; 2684 bool IsWithin(intptr_t min_int, intptr_t max_int) const;
2659 2685
2660 // Inclusive. 2686 // Inclusive.
2661 bool Overlaps(intptr_t min_int, intptr_t max_int) const; 2687 bool Overlaps(intptr_t min_int, intptr_t max_int) const;
2662 2688
2663 bool IsUnsatisfiable() const; 2689 bool IsUnsatisfiable() const;
2664 2690
2691 static void Shl(Range* left_range,
2692 Range* right_range,
2693 RangeBoundary* min,
2694 RangeBoundary* max);
2695
2665 private: 2696 private:
2666 RangeBoundary min_; 2697 RangeBoundary min_;
2667 RangeBoundary max_; 2698 RangeBoundary max_;
2668 }; 2699 };
2669 2700
2670 2701
2671 class ConstraintInstr : public TemplateDefinition<2> { 2702 class ConstraintInstr : public TemplateDefinition<2> {
2672 public: 2703 public:
2673 ConstraintInstr(Value* value, Range* constraint) 2704 ConstraintInstr(Value* value, Range* constraint)
2674 : constraint_(constraint), 2705 : constraint_(constraint),
(...skipping 5331 matching lines...) Expand 10 before | Expand all | Expand 10 after
8006 ForwardInstructionIterator* current_iterator_; 8037 ForwardInstructionIterator* current_iterator_;
8007 8038
8008 private: 8039 private:
8009 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 8040 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
8010 }; 8041 };
8011 8042
8012 8043
8013 } // namespace dart 8044 } // namespace dart
8014 8045
8015 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 8046 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | runtime/vm/intermediate_language_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698