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

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

Issue 13469013: Use range analysis to improve constant propagation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 // successor. 1818 // successor.
1819 void set_constrained_type(ConstrainedCompileType* type) { 1819 void set_constrained_type(ConstrainedCompileType* type) {
1820 constrained_type_ = type; 1820 constrained_type_ = type;
1821 } 1821 }
1822 1822
1823 // Return compile type constrained by the comparison of this branch. 1823 // Return compile type constrained by the comparison of this branch.
1824 ConstrainedCompileType* constrained_type() const { 1824 ConstrainedCompileType* constrained_type() const {
1825 return constrained_type_; 1825 return constrained_type_;
1826 } 1826 }
1827 1827
1828 void set_constant_target(TargetEntryInstr* target) {
1829 ASSERT(target == true_successor() || target == false_successor());
1830 constant_target_ = target;
1831 }
1832 TargetEntryInstr* constant_target() const {
1833 return constant_target_;
1834 }
1835
1828 private: 1836 private:
1829 virtual void RawSetInputAt(intptr_t i, Value* value); 1837 virtual void RawSetInputAt(intptr_t i, Value* value);
1830 1838
1831 ComparisonInstr* comparison_; 1839 ComparisonInstr* comparison_;
1832 const bool is_checked_; 1840 const bool is_checked_;
1833 1841
1834 ConstrainedCompileType* constrained_type_; 1842 ConstrainedCompileType* constrained_type_;
1835 1843
1844 TargetEntryInstr* constant_target_;
1845
1836 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 1846 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
1837 }; 1847 };
1838 1848
1839 1849
1840 class StoreContextInstr : public TemplateInstruction<1> { 1850 class StoreContextInstr : public TemplateInstruction<1> {
1841 public: 1851 public:
1842 explicit StoreContextInstr(Value* value) { 1852 explicit StoreContextInstr(Value* value) {
1843 SetInputAt(0, value); 1853 SetInputAt(0, value);
1844 } 1854 }
1845 1855
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 void PrintTo(BufferFormatter* f) const; 2032 void PrintTo(BufferFormatter* f) const;
2023 static const char* ToCString(Range* range); 2033 static const char* ToCString(Range* range);
2024 2034
2025 const RangeBoundary& min() const { return min_; } 2035 const RangeBoundary& min() const { return min_; }
2026 const RangeBoundary& max() const { return max_; } 2036 const RangeBoundary& max() const { return max_; }
2027 2037
2028 bool Equals(Range* other) { 2038 bool Equals(Range* other) {
2029 return min_.Equals(other->min_) && max_.Equals(other->max_); 2039 return min_.Equals(other->min_) && max_.Equals(other->max_);
2030 } 2040 }
2031 2041
2032 static RangeBoundary ConstantMin(Range* range) { 2042 static RangeBoundary ConstantMin(const Range* range) {
2033 if (range == NULL) return RangeBoundary::MinSmi(); 2043 if (range == NULL) return RangeBoundary::MinSmi();
2034 return range->min().LowerBound().Clamp(); 2044 return range->min().LowerBound().Clamp();
2035 } 2045 }
2036 2046
2037 static RangeBoundary ConstantMax(Range* range) { 2047 static RangeBoundary ConstantMax(const Range* range) {
2038 if (range == NULL) return RangeBoundary::MaxSmi(); 2048 if (range == NULL) return RangeBoundary::MaxSmi();
2039 return range->max().UpperBound().Clamp(); 2049 return range->max().UpperBound().Clamp();
2040 } 2050 }
2041 2051
2042 // Inclusive. 2052 // Inclusive.
2043 bool IsWithin(intptr_t min_int, intptr_t max_int) const; 2053 bool IsWithin(intptr_t min_int, intptr_t max_int) const;
2044 2054
2055 bool IsUnsatisfiable() const;
2056
2045 private: 2057 private:
2046 RangeBoundary min_; 2058 RangeBoundary min_;
2047 RangeBoundary max_; 2059 RangeBoundary max_;
2048 }; 2060 };
2049 2061
2050 2062
2051 class ConstraintInstr : public TemplateDefinition<2> { 2063 class ConstraintInstr : public TemplateDefinition<2> {
2052 public: 2064 public:
2053 ConstraintInstr(Value* value, Range* constraint) 2065 ConstraintInstr(Value* value, Range* constraint)
2054 : constraint_(constraint) { 2066 : constraint_(constraint),
2067 target_(NULL) {
2055 SetInputAt(0, value); 2068 SetInputAt(0, value);
2056 } 2069 }
2057 2070
2058 DECLARE_INSTRUCTION(Constraint) 2071 DECLARE_INSTRUCTION(Constraint)
2059 2072
2060 virtual intptr_t InputCount() const { 2073 virtual intptr_t InputCount() const {
2061 return (inputs_[1] == NULL) ? 1 : 2; 2074 return (inputs_[1] == NULL) ? 1 : 2;
2062 } 2075 }
2063 2076
2064 virtual CompileType ComputeType() const; 2077 virtual CompileType ComputeType() const;
(...skipping 13 matching lines...) Expand all
2078 Range* constraint() const { return constraint_; } 2091 Range* constraint() const { return constraint_; }
2079 2092
2080 virtual void InferRange(); 2093 virtual void InferRange();
2081 2094
2082 void AddDependency(Definition* defn) { 2095 void AddDependency(Definition* defn) {
2083 Value* val = new Value(defn); 2096 Value* val = new Value(defn);
2084 defn->AddInputUse(val); 2097 defn->AddInputUse(val);
2085 SetInputAt(1, val); 2098 SetInputAt(1, val);
2086 } 2099 }
2087 2100
2101 // Constraints for branches have their target block stored in order
2102 // to find the the comparsion that generated the constraint:
2103 // target->predecessor->last_instruction->comparison.
2104 void set_target(TargetEntryInstr* target) {
2105 target_ = target;
2106 }
2107 TargetEntryInstr* target() const {
2108 return target_;
2109 }
2110
2088 private: 2111 private:
2089 Value* dependency() { 2112 Value* dependency() {
2090 return inputs_[1]; 2113 return inputs_[1];
2091 } 2114 }
2092 2115
2093 Range* constraint_; 2116 Range* constraint_;
2117 TargetEntryInstr* target_;
2094 2118
2095 DISALLOW_COPY_AND_ASSIGN(ConstraintInstr); 2119 DISALLOW_COPY_AND_ASSIGN(ConstraintInstr);
2096 }; 2120 };
2097 2121
2098 2122
2099 class ConstantInstr : public TemplateDefinition<0> { 2123 class ConstantInstr : public TemplateDefinition<0> {
2100 public: 2124 public:
2101 explicit ConstantInstr(const Object& value) 2125 explicit ConstantInstr(const Object& value)
2102 : value_(value) { } 2126 : value_(value) { }
2103 2127
(...skipping 2573 matching lines...) Expand 10 before | Expand all | Expand 10 after
4677 ForwardInstructionIterator* current_iterator_; 4701 ForwardInstructionIterator* current_iterator_;
4678 4702
4679 private: 4703 private:
4680 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 4704 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
4681 }; 4705 };
4682 4706
4683 4707
4684 } // namespace dart 4708 } // namespace dart
4685 4709
4686 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 4710 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698