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

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

Issue 10867012: Add a smi-check instruction for arithmetic smi operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 8 years, 4 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 M(CatchEntry, CatchEntryComp) \ 96 M(CatchEntry, CatchEntryComp) \
97 M(BinarySmiOp, BinarySmiOpComp) \ 97 M(BinarySmiOp, BinarySmiOpComp) \
98 M(BinaryMintOp, BinaryMintOpComp) \ 98 M(BinaryMintOp, BinaryMintOpComp) \
99 M(BinaryDoubleOp, BinaryDoubleOpComp) \ 99 M(BinaryDoubleOp, BinaryDoubleOpComp) \
100 M(UnarySmiOp, UnarySmiOpComp) \ 100 M(UnarySmiOp, UnarySmiOpComp) \
101 M(NumberNegate, NumberNegateComp) \ 101 M(NumberNegate, NumberNegateComp) \
102 M(CheckStackOverflow, CheckStackOverflowComp) \ 102 M(CheckStackOverflow, CheckStackOverflowComp) \
103 M(DoubleToDouble, DoubleToDoubleComp) \ 103 M(DoubleToDouble, DoubleToDoubleComp) \
104 M(SmiToDouble, SmiToDoubleComp) \ 104 M(SmiToDouble, SmiToDoubleComp) \
105 M(CheckClass, CheckClassComp) \ 105 M(CheckClass, CheckClassComp) \
106 M(CheckSmi, CheckSmiComp) \
106 M(Materialize, MaterializeComp) 107 M(Materialize, MaterializeComp)
107 108
108 109
109 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; 110 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName;
110 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) 111 FOR_EACH_COMPUTATION(FORWARD_DECLARATION)
111 FOR_EACH_VALUE(FORWARD_DECLARATION) 112 FOR_EACH_VALUE(FORWARD_DECLARATION)
112 #undef FORWARD_DECLARATION 113 #undef FORWARD_DECLARATION
113 114
114 // Forward declarations. 115 // Forward declarations.
115 class BindInstr; 116 class BindInstr;
(...skipping 29 matching lines...) Expand all
145 virtual Value* InputAt(intptr_t i) const = 0; 146 virtual Value* InputAt(intptr_t i) const = 0;
146 virtual void SetInputAt(intptr_t i, Value* value) = 0; 147 virtual void SetInputAt(intptr_t i, Value* value) = 0;
147 148
148 // Call computations override this function and return the 149 // Call computations override this function and return the
149 // number of pushed arguments. 150 // number of pushed arguments.
150 virtual intptr_t ArgumentCount() const = 0; 151 virtual intptr_t ArgumentCount() const = 0;
151 152
152 // Returns true, if this computation can deoptimize. 153 // Returns true, if this computation can deoptimize.
153 virtual bool CanDeoptimize() const = 0; 154 virtual bool CanDeoptimize() const = 0;
154 155
155 // Optimize this computation. Returns a replacement for the instruction 156 // Returns a replacement for the instruction that wraps this computation.
156 // that wraps this computation or NULL if nothing to replace. 157 // Returns NULL if instr can be eliminated.
157 virtual Definition* TryReplace(BindInstr* instr) { return NULL; } 158 // By default returns instr (input parameter) which means no change.
159 virtual Definition* TryReplace(BindInstr* instr) const;
158 160
159 // Compares two computations. Returns true, if: 161 // Compares two computations. Returns true, if:
160 // 1. They are of the same kind. 162 // 1. They are of the same kind.
161 // 2. All input operands match. 163 // 2. All input operands match.
162 // 3. All other attributes match. 164 // 3. All other attributes match.
163 bool Equals(Computation* other) const; 165 bool Equals(Computation* other) const;
164 166
165 // Returns a hash code for use with hash maps. 167 // Returns a hash code for use with hash maps.
166 virtual intptr_t Hashcode() const; 168 virtual intptr_t Hashcode() const;
167 169
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 : ComparisonComp(kind, left, right) { 767 : ComparisonComp(kind, left, right) {
766 ASSERT((kind == Token::kEQ_STRICT) || (kind == Token::kNE_STRICT)); 768 ASSERT((kind == Token::kEQ_STRICT) || (kind == Token::kNE_STRICT));
767 } 769 }
768 770
769 DECLARE_COMPUTATION(StrictCompare) 771 DECLARE_COMPUTATION(StrictCompare)
770 772
771 virtual void PrintOperandsTo(BufferFormatter* f) const; 773 virtual void PrintOperandsTo(BufferFormatter* f) const;
772 774
773 virtual bool CanDeoptimize() const { return false; } 775 virtual bool CanDeoptimize() const { return false; }
774 776
775 virtual Definition* TryReplace(BindInstr* instr); 777 virtual Definition* TryReplace(BindInstr* instr) const;
778
776 virtual intptr_t ResultCid() const { return kBoolCid; } 779 virtual intptr_t ResultCid() const { return kBoolCid; }
777 780
778 private: 781 private:
779 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); 782 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp);
780 }; 783 };
781 784
782 785
783 class EqualityCompareComp : public ComparisonComp { 786 class EqualityCompareComp : public ComparisonComp {
784 public: 787 public:
785 EqualityCompareComp(intptr_t token_pos, 788 EqualityCompareComp(intptr_t token_pos,
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 Value* right() const { return inputs_[1]; } 1671 Value* right() const { return inputs_[1]; }
1669 1672
1670 Token::Kind op_kind() const { return op_kind_; } 1673 Token::Kind op_kind() const { return op_kind_; }
1671 1674
1672 InstanceCallComp* instance_call() const { return instance_call_; } 1675 InstanceCallComp* instance_call() const { return instance_call_; }
1673 1676
1674 virtual void PrintOperandsTo(BufferFormatter* f) const; 1677 virtual void PrintOperandsTo(BufferFormatter* f) const;
1675 1678
1676 DECLARE_COMPUTATION(BinarySmiOp) 1679 DECLARE_COMPUTATION(BinarySmiOp)
1677 1680
1678 virtual bool CanDeoptimize() const { return true; } 1681 virtual bool CanDeoptimize() const;
1682
1679 virtual intptr_t ResultCid() const; 1683 virtual intptr_t ResultCid() const;
1680 1684
1681 private: 1685 private:
1682 const Token::Kind op_kind_; 1686 const Token::Kind op_kind_;
1683 InstanceCallComp* instance_call_; 1687 InstanceCallComp* instance_call_;
1684 1688
1685 DISALLOW_COPY_AND_ASSIGN(BinarySmiOpComp); 1689 DISALLOW_COPY_AND_ASSIGN(BinarySmiOpComp);
1686 }; 1690 };
1687 1691
1688 1692
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 1887
1884 virtual bool AttributesEqual(Computation* other) const; 1888 virtual bool AttributesEqual(Computation* other) const;
1885 1889
1886 virtual bool HasSideEffect() const { return false; } 1890 virtual bool HasSideEffect() const { return false; }
1887 1891
1888 Value* value() const { return inputs_[0]; } 1892 Value* value() const { return inputs_[0]; }
1889 1893
1890 intptr_t deopt_id() const { return original_->deopt_id(); } 1894 intptr_t deopt_id() const { return original_->deopt_id(); }
1891 intptr_t try_index() const { return original_->try_index(); } 1895 intptr_t try_index() const { return original_->try_index(); }
1892 1896
1897 virtual void PrintOperandsTo(BufferFormatter* f) const;
1898
1893 private: 1899 private:
1894 InstanceCallComp* original_; 1900 InstanceCallComp* original_;
1895 1901
1896 DISALLOW_COPY_AND_ASSIGN(CheckClassComp); 1902 DISALLOW_COPY_AND_ASSIGN(CheckClassComp);
1897 }; 1903 };
1898 1904
1899 1905
1906 class CheckSmiComp : public TemplateComputation<1> {
1907 public:
1908 CheckSmiComp(Value* value, InstanceCallComp* original)
1909 : original_(original) {
1910 ASSERT(value != NULL);
1911 inputs_[0] = value;
1912 }
1913
1914 DECLARE_COMPUTATION(CheckSmi)
1915
1916 virtual bool CanDeoptimize() const { return true; }
1917
1918 virtual bool AttributesEqual(Computation* other) const { return true; }
1919
1920 virtual bool HasSideEffect() const { return false; }
1921
1922 virtual Definition* TryReplace(BindInstr* instr) const;
1923
1924 Value* value() const { return inputs_[0]; }
1925
1926 intptr_t deopt_id() const { return original_->deopt_id(); }
1927 intptr_t try_index() const { return original_->try_index(); }
1928
1929 private:
1930 InstanceCallComp* original_;
1931
1932 DISALLOW_COPY_AND_ASSIGN(CheckSmiComp);
1933 };
1934
1935
1900 #undef DECLARE_COMPUTATION 1936 #undef DECLARE_COMPUTATION
1901 1937
1902 1938
1903 // Implementation of type testers and cast functins. 1939 // Implementation of type testers and cast functins.
1904 #define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \ 1940 #define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \
1905 bool Computation::Is##ShortName() const { \ 1941 bool Computation::Is##ShortName() const { \
1906 return computation_kind() == k##ShortName; \ 1942 return computation_kind() == k##ShortName; \
1907 } \ 1943 } \
1908 const ClassName* Computation::As##ShortName() const { \ 1944 const ClassName* Computation::As##ShortName() const { \
1909 if (!Is##ShortName()) return NULL; \ 1945 if (!Is##ShortName()) return NULL; \
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3056 3092
3057 Location* LocationSlotAt(intptr_t ix) const { 3093 Location* LocationSlotAt(intptr_t ix) const {
3058 ASSERT((ix >= 0) && (ix < values_.length())); 3094 ASSERT((ix >= 0) && (ix < values_.length()));
3059 return &locations_[ix]; 3095 return &locations_[ix];
3060 } 3096 }
3061 3097
3062 intptr_t fixed_parameter_count() const { 3098 intptr_t fixed_parameter_count() const {
3063 return fixed_parameter_count_; 3099 return fixed_parameter_count_;
3064 } 3100 }
3065 3101
3102 Environment* Copy() const;
3103
3066 void PrintTo(BufferFormatter* f) const; 3104 void PrintTo(BufferFormatter* f) const;
3067 3105
3068 private: 3106 private:
3107 Environment(intptr_t length, intptr_t fixed_parameter_count)
3108 : values_(length),
3109 locations_(NULL),
3110 fixed_parameter_count_(fixed_parameter_count) { }
3111
3069 GrowableArray<Value*> values_; 3112 GrowableArray<Value*> values_;
3070 Location* locations_; 3113 Location* locations_;
3071 const intptr_t fixed_parameter_count_; 3114 const intptr_t fixed_parameter_count_;
3072 3115
3073 DISALLOW_COPY_AND_ASSIGN(Environment); 3116 DISALLOW_COPY_AND_ASSIGN(Environment);
3074 }; 3117 };
3075 3118
3076 3119
3077 // Visitor base class to visit each instruction and computation in a flow 3120 // Visitor base class to visit each instruction and computation in a flow
3078 // graph as defined by a reversed list of basic blocks. 3121 // graph as defined by a reversed list of basic blocks.
(...skipping 30 matching lines...) Expand all
3109 ForwardInstructionIterator* current_iterator_; 3152 ForwardInstructionIterator* current_iterator_;
3110 3153
3111 private: 3154 private:
3112 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 3155 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
3113 }; 3156 };
3114 3157
3115 3158
3116 } // namespace dart 3159 } // namespace dart
3117 3160
3118 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 3161 #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