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

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

Issue 321593004: Refactor RangeBoundary +/- infinity to be distinct RangeBoundary kinds. (Closed) Base URL: https://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 | « runtime/vm/il_printer.cc ('k') | runtime/vm/intermediate_language.cc » ('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 (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 2466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 2477
2478 virtual bool MayThrow() const { return false; } 2478 virtual bool MayThrow() const { return false; }
2479 2479
2480 private: 2480 private:
2481 DISALLOW_COPY_AND_ASSIGN(RedefinitionInstr); 2481 DISALLOW_COPY_AND_ASSIGN(RedefinitionInstr);
2482 }; 2482 };
2483 2483
2484 2484
2485 class RangeBoundary : public ValueObject { 2485 class RangeBoundary : public ValueObject {
2486 public: 2486 public:
2487 enum Kind { kUnknown, kSymbol, kConstant }; 2487 enum Kind {
2488 kUnknown,
2489 kNegativeInfinity,
2490 kPositiveInfinity,
2491 kSymbol,
2492 kConstant,
2493 };
2488 2494
2489 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { } 2495 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { }
2490 2496
2491 RangeBoundary(const RangeBoundary& other) 2497 RangeBoundary(const RangeBoundary& other)
2492 : ValueObject(), 2498 : ValueObject(),
2493 kind_(other.kind_), 2499 kind_(other.kind_),
2494 value_(other.value_), 2500 value_(other.value_),
2495 offset_(other.offset_) { } 2501 offset_(other.offset_) { }
2496 2502
2497 RangeBoundary& operator=(const RangeBoundary& other) { 2503 RangeBoundary& operator=(const RangeBoundary& other) {
2498 kind_ = other.kind_; 2504 kind_ = other.kind_;
2499 value_ = other.value_; 2505 value_ = other.value_;
2500 offset_ = other.offset_; 2506 offset_ = other.offset_;
2501 return *this; 2507 return *this;
2502 } 2508 }
2503 2509
2504 static RangeBoundary FromConstant(intptr_t val) { 2510 static RangeBoundary FromConstant(intptr_t val) {
2505 return RangeBoundary(kConstant, val, 0); 2511 return RangeBoundary(kConstant, val, 0);
2506 } 2512 }
2507 2513
2514 static RangeBoundary NegativeInfinity() {
2515 return RangeBoundary(kNegativeInfinity, 0, 0);
2516 }
2517
2518 static RangeBoundary PositiveInfinity() {
2519 return RangeBoundary(kPositiveInfinity, 0, 0);
2520 }
2521
2508 static RangeBoundary FromDefinition(Definition* defn, intptr_t offs = 0); 2522 static RangeBoundary FromDefinition(Definition* defn, intptr_t offs = 0);
2509 2523
2510 static RangeBoundary MinSmi() { 2524 static RangeBoundary MinSmi() {
2511 return FromConstant(Smi::kMinValue); 2525 return FromConstant(Smi::kMinValue);
2512 } 2526 }
2513 2527
2514 static RangeBoundary MaxSmi() { 2528 static RangeBoundary MaxSmi() {
2515 return FromConstant(Smi::kMaxValue); 2529 return FromConstant(Smi::kMaxValue);
2516 } 2530 }
2517 2531
2518 static const intptr_t kMinusInfinity = Smi::kMinValue - 1;
2519 static const intptr_t kPlusInfinity = Smi::kMaxValue + 1;
2520
2521 static RangeBoundary OverflowedMinSmi() {
2522 return FromConstant(Smi::kMinValue - 1);
2523 }
2524
2525 static RangeBoundary OverflowedMaxSmi() {
2526 return FromConstant(Smi::kMaxValue + 1);
2527 }
2528
2529 static RangeBoundary Min(RangeBoundary a, RangeBoundary b); 2532 static RangeBoundary Min(RangeBoundary a, RangeBoundary b);
2530 2533
2531 static RangeBoundary Max(RangeBoundary a, RangeBoundary b); 2534 static RangeBoundary Max(RangeBoundary a, RangeBoundary b);
2532 2535
2533 bool Overflowed() const { 2536 bool Overflowed() const {
2534 return IsConstant() && !Smi::IsValid(value()); 2537 // If the value is a constant outside of Smi range or infinity.
2538 return (IsConstant() && !Smi::IsValid(value())) || IsInfinity();
2535 } 2539 }
2536 2540
2537 RangeBoundary Clamp() const { 2541 RangeBoundary Clamp() const {
2538 if (IsConstant()) { 2542 if (IsNegativeInfinity()) {
2543 return MinSmi();
2544 } else if (IsPositiveInfinity()) {
2545 return MaxSmi();
2546 } else if (IsConstant()) {
2539 if (value() < Smi::kMinValue) return MinSmi(); 2547 if (value() < Smi::kMinValue) return MinSmi();
2540 if (value() > Smi::kMaxValue) return MaxSmi(); 2548 if (value() > Smi::kMaxValue) return MaxSmi();
2541 } 2549 }
2542 return *this; 2550 return *this;
2543 } 2551 }
2544 2552
2545 bool Equals(const RangeBoundary& other) const {
2546 return (kind_ == other.kind_) && (value_ == other.value_);
2547 }
2548
2549 bool IsUnknown() const { return kind_ == kUnknown; } 2553 bool IsUnknown() const { return kind_ == kUnknown; }
2550 bool IsConstant() const { return kind_ == kConstant; } 2554 bool IsConstant() const { return kind_ == kConstant; }
2551 bool IsSymbol() const { return kind_ == kSymbol; } 2555 bool IsSymbol() const { return kind_ == kSymbol; }
2556 bool IsNegativeInfinity() const { return kind_ == kNegativeInfinity; }
2557 bool IsPositiveInfinity() const { return kind_ == kPositiveInfinity; }
2558 bool IsInfinity() const {
2559 return IsNegativeInfinity() || IsPositiveInfinity();
2560 }
2552 2561
2553 intptr_t value() const { 2562 intptr_t value() const {
2554 ASSERT(IsConstant()); 2563 ASSERT(IsConstant());
2555 return value_; 2564 return value_;
2556 } 2565 }
2557 2566
2558 Definition* symbol() const { 2567 Definition* symbol() const {
2559 ASSERT(IsSymbol()); 2568 ASSERT(IsSymbol());
2560 return reinterpret_cast<Definition*>(value_); 2569 return reinterpret_cast<Definition*>(value_);
2561 } 2570 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 static Range* Unknown() { 2620 static Range* Unknown() {
2612 return new Range(RangeBoundary::MinSmi(), RangeBoundary::MaxSmi()); 2621 return new Range(RangeBoundary::MinSmi(), RangeBoundary::MaxSmi());
2613 } 2622 }
2614 2623
2615 void PrintTo(BufferFormatter* f) const; 2624 void PrintTo(BufferFormatter* f) const;
2616 static const char* ToCString(Range* range); 2625 static const char* ToCString(Range* range);
2617 2626
2618 const RangeBoundary& min() const { return min_; } 2627 const RangeBoundary& min() const { return min_; }
2619 const RangeBoundary& max() const { return max_; } 2628 const RangeBoundary& max() const { return max_; }
2620 2629
2621 bool Equals(Range* other) {
2622 return min_.Equals(other->min_) && max_.Equals(other->max_);
2623 }
2624
2625 static RangeBoundary ConstantMin(const Range* range) { 2630 static RangeBoundary ConstantMin(const Range* range) {
2626 if (range == NULL) return RangeBoundary::MinSmi(); 2631 if (range == NULL) {
2632 return RangeBoundary::MinSmi();
2633 }
2627 return range->min().LowerBound().Clamp(); 2634 return range->min().LowerBound().Clamp();
2628 } 2635 }
2629 2636
2630 static RangeBoundary ConstantMax(const Range* range) { 2637 static RangeBoundary ConstantMax(const Range* range) {
2631 if (range == NULL) return RangeBoundary::MaxSmi(); 2638 if (range == NULL) {
2639 return RangeBoundary::MaxSmi();
2640 }
2632 return range->max().UpperBound().Clamp(); 2641 return range->max().UpperBound().Clamp();
2633 } 2642 }
2634 2643
2644 // [0, +inf]
2645 bool IsPositive() const;
Florian Schneider 2014/06/10 10:43:20 I find IsPositive and IsNegative more confusing th
2646
2647 // [-inf, 0)
2648 bool IsNegative() const;
2649
2650 // [-inf, val].
2651 bool OnlyLessThanOrEqualTo(intptr_t val) const;
2652
2635 // Inclusive. 2653 // Inclusive.
2636 bool IsWithin(intptr_t min_int, intptr_t max_int) const; 2654 bool IsWithin(intptr_t min_int, intptr_t max_int) const;
2637 2655
2638 // Inclusive. 2656 // Inclusive.
2639 bool Overlaps(intptr_t min_int, intptr_t max_int) const; 2657 bool Overlaps(intptr_t min_int, intptr_t max_int) const;
2640 2658
2641 bool IsUnsatisfiable() const; 2659 bool IsUnsatisfiable() const;
2642 2660
2643 private: 2661 private:
2644 RangeBoundary min_; 2662 RangeBoundary min_;
(...skipping 5339 matching lines...) Expand 10 before | Expand all | Expand 10 after
7984 ForwardInstructionIterator* current_iterator_; 8002 ForwardInstructionIterator* current_iterator_;
7985 8003
7986 private: 8004 private:
7987 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 8005 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
7988 }; 8006 };
7989 8007
7990 8008
7991 } // namespace dart 8009 } // namespace dart
7992 8010
7993 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 8011 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/il_printer.cc ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698