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

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: 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
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | runtime/vm/intermediate_language.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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& a,
Vyacheslav Egorov (Google) 2014/06/12 14:59:00 operand a
Florian Schneider 2014/06/12 15:12:43 Done.
2620 intptr_t b,
Vyacheslav Egorov (Google) 2014/06/12 14:59:00 more meaningful name: shift?
Florian Schneider 2014/06/12 15:12:42 Done.
2621 const RangeBoundary& overflow) {
2622 ASSERT(a.IsConstant());
2623 ASSERT(b >= 0);
2624 intptr_t limit = 63 - b;
Vyacheslav Egorov (Google) 2014/06/12 14:59:00 I think this should be 64 (think b = 0).
Florian Schneider 2014/06/12 15:12:42 Done.
2625 if ((a.value() == 0) ||
2626 ((limit > 0) &&
2627 (Utils::IsInt(limit, static_cast<int64_t>(a.value()))))) {
2628 // Result stays in 64 bit range.
2629 int64_t result = a.value() << b;
Vyacheslav Egorov (Google) 2014/06/12 14:59:00 this is intptr_t range shift
Florian Schneider 2014/06/12 15:12:42 Done.
2630 return Smi::IsValid(result)
2631 ? RangeBoundary::FromConstant(result)
2632 : overflow;
2633 }
2634 return overflow;
2635 }
2636
2610 private: 2637 private:
2611 RangeBoundary(Kind kind, intptr_t value, intptr_t offset) 2638 RangeBoundary(Kind kind, intptr_t value, intptr_t offset)
2612 : kind_(kind), value_(value), offset_(offset) { } 2639 : kind_(kind), value_(value), offset_(offset) { }
2613 2640
2614 Kind kind_; 2641 Kind kind_;
2615 intptr_t value_; 2642 intptr_t value_;
2616 intptr_t offset_; 2643 intptr_t offset_;
2617 }; 2644 };
2618 2645
2619 2646
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 bool OnlyLessThanOrEqualTo(intptr_t val) const; 2682 bool OnlyLessThanOrEqualTo(intptr_t val) const;
2656 2683
2657 // Inclusive. 2684 // Inclusive.
2658 bool IsWithin(intptr_t min_int, intptr_t max_int) const; 2685 bool IsWithin(intptr_t min_int, intptr_t max_int) const;
2659 2686
2660 // Inclusive. 2687 // Inclusive.
2661 bool Overlaps(intptr_t min_int, intptr_t max_int) const; 2688 bool Overlaps(intptr_t min_int, intptr_t max_int) const;
2662 2689
2663 bool IsUnsatisfiable() const; 2690 bool IsUnsatisfiable() const;
2664 2691
2692 static void Shl(Range* left_range,
2693 Range* right_range,
2694 RangeBoundary* min,
2695 RangeBoundary* max);
2696
2665 private: 2697 private:
2666 RangeBoundary min_; 2698 RangeBoundary min_;
2667 RangeBoundary max_; 2699 RangeBoundary max_;
2668 }; 2700 };
2669 2701
2670 2702
2671 class ConstraintInstr : public TemplateDefinition<2> { 2703 class ConstraintInstr : public TemplateDefinition<2> {
2672 public: 2704 public:
2673 ConstraintInstr(Value* value, Range* constraint) 2705 ConstraintInstr(Value* value, Range* constraint)
2674 : constraint_(constraint), 2706 : constraint_(constraint),
(...skipping 5331 matching lines...) Expand 10 before | Expand all | Expand 10 after
8006 ForwardInstructionIterator* current_iterator_; 8038 ForwardInstructionIterator* current_iterator_;
8007 8039
8008 private: 8040 private:
8009 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 8041 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
8010 }; 8042 };
8011 8043
8012 8044
8013 } // namespace dart 8045 } // namespace dart
8014 8046
8015 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 8047 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | runtime/vm/intermediate_language.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698