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

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

Issue 298883009: Eliminate some unnecessary handle allocations in the compiler. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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/flow_graph_compiler_x64.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"
11 #include "vm/handles_impl.h" 11 #include "vm/handles_impl.h"
12 #include "vm/locations.h" 12 #include "vm/locations.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/parser.h"
14 15
15 namespace dart { 16 namespace dart {
16 17
17 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); 18 DECLARE_FLAG(bool, throw_on_javascript_int_overflow);
18 19
19 class BitVector; 20 class BitVector;
20 class BlockEntryInstr; 21 class BlockEntryInstr;
21 class BufferFormatter; 22 class BufferFormatter;
22 class CatchBlockEntryInstr; 23 class CatchBlockEntryInstr;
23 class ComparisonInstr; 24 class ComparisonInstr;
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 // Abstract super-class of all instructions that define a value (Bind, Phi). 1752 // Abstract super-class of all instructions that define a value (Bind, Phi).
1752 class Definition : public Instruction { 1753 class Definition : public Instruction {
1753 public: 1754 public:
1754 Definition(); 1755 Definition();
1755 1756
1756 virtual Definition* AsDefinition() { return this; } 1757 virtual Definition* AsDefinition() { return this; }
1757 1758
1758 bool IsComparison() { return (AsComparison() != NULL); } 1759 bool IsComparison() { return (AsComparison() != NULL); }
1759 virtual ComparisonInstr* AsComparison() { return NULL; } 1760 virtual ComparisonInstr* AsComparison() { return NULL; }
1760 1761
1761 // Overridden by definitions that push arguments. 1762 // Overridden by definitions that have pushed arguments.
1762 virtual intptr_t ArgumentCount() const { return 0; } 1763 virtual intptr_t ArgumentCount() const { return 0; }
1763 1764
1764 // Overridden by definitions that have call counts. 1765 // Overridden by definitions that have call counts.
1765 virtual intptr_t CallCount() const { 1766 virtual intptr_t CallCount() const {
1766 UNREACHABLE(); 1767 UNREACHABLE();
1767 return -1; 1768 return -1;
1768 } 1769 }
1769 1770
1770 intptr_t temp_index() const { return temp_index_; } 1771 intptr_t temp_index() const { return temp_index_; }
1771 void set_temp_index(intptr_t index) { temp_index_ = index; } 1772 void set_temp_index(intptr_t index) { temp_index_ = index; }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 } 1925 }
1925 1926
1926 1927
1927 inline void Value::BindToEnvironment(Definition* def) { 1928 inline void Value::BindToEnvironment(Definition* def) {
1928 RemoveFromUseList(); 1929 RemoveFromUseList();
1929 set_definition(def); 1930 set_definition(def);
1930 def->AddEnvUse(this); 1931 def->AddEnvUse(this);
1931 } 1932 }
1932 1933
1933 1934
1935 template<intptr_t N>
1936 class TemplateDefinition : public Definition {
1937 public:
1938 TemplateDefinition<N>() : inputs_() { }
1939
1940 virtual intptr_t InputCount() const { return N; }
1941 virtual Value* InputAt(intptr_t i) const { return inputs_[i]; }
1942
1943 protected:
1944 EmbeddedArray<Value*, N> inputs_;
1945
1946 private:
1947 friend class BranchInstr;
1948 friend class IfThenElseInstr;
1949
1950 virtual void RawSetInputAt(intptr_t i, Value* value) {
1951 inputs_[i] = value;
1952 }
1953 };
1954
1955
1956 struct BranchLabels {
1957 Label* true_label;
1958 Label* false_label;
1959 Label* fall_through;
1960 };
1961
1962
1934 class PhiInstr : public Definition { 1963 class PhiInstr : public Definition {
1935 public: 1964 public:
1936 PhiInstr(JoinEntryInstr* block, intptr_t num_inputs) 1965 PhiInstr(JoinEntryInstr* block, intptr_t num_inputs)
1937 : block_(block), 1966 : block_(block),
1938 inputs_(num_inputs), 1967 inputs_(num_inputs),
1939 is_alive_(false), 1968 is_alive_(false),
1940 representation_(kTagged), 1969 representation_(kTagged),
1941 reaching_defs_(NULL) { 1970 reaching_defs_(NULL) {
1942 for (intptr_t i = 0; i < num_inputs; ++i) { 1971 for (intptr_t i = 0; i < num_inputs; ++i) {
1943 inputs_.Add(NULL); 1972 inputs_.Add(NULL);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 private: 2088 private:
2060 virtual void RawSetInputAt(intptr_t i, Value* value) { UNREACHABLE(); } 2089 virtual void RawSetInputAt(intptr_t i, Value* value) { UNREACHABLE(); }
2061 2090
2062 const intptr_t index_; 2091 const intptr_t index_;
2063 BlockEntryInstr* block_; 2092 BlockEntryInstr* block_;
2064 2093
2065 DISALLOW_COPY_AND_ASSIGN(ParameterInstr); 2094 DISALLOW_COPY_AND_ASSIGN(ParameterInstr);
2066 }; 2095 };
2067 2096
2068 2097
2069 class PushArgumentInstr : public Definition { 2098 class PushArgumentInstr : public TemplateDefinition<1> {
2070 public: 2099 public:
2071 explicit PushArgumentInstr(Value* value) { 2100 explicit PushArgumentInstr(Value* value) {
2072 SetInputAt(0, value); 2101 SetInputAt(0, value);
2073 } 2102 }
2074 2103
2075 DECLARE_INSTRUCTION(PushArgument) 2104 DECLARE_INSTRUCTION(PushArgument)
2076 2105
2077 intptr_t InputCount() const { return 1; }
2078 Value* InputAt(intptr_t i) const {
2079 ASSERT(i == 0);
2080 return value_;
2081 }
2082
2083 virtual intptr_t ArgumentCount() const { return 0; } 2106 virtual intptr_t ArgumentCount() const { return 0; }
2084 2107
2085 virtual CompileType ComputeType() const; 2108 virtual CompileType ComputeType() const;
2086 2109
2087 Value* value() const { return value_; } 2110 Value* value() const { return InputAt(0); }
2088
2089 virtual intptr_t Hashcode() const {
2090 UNREACHABLE();
2091 return 0;
2092 }
2093 2111
2094 virtual bool CanDeoptimize() const { return false; } 2112 virtual bool CanDeoptimize() const { return false; }
2095 2113
2096 virtual EffectSet Effects() const { return EffectSet::None(); } 2114 virtual EffectSet Effects() const { return EffectSet::None(); }
2097 2115
2098 virtual void PrintOperandsTo(BufferFormatter* f) const; 2116 virtual void PrintOperandsTo(BufferFormatter* f) const;
2099 2117
2100 virtual bool MayThrow() const { return false; } 2118 virtual bool MayThrow() const { return false; }
2101 2119
2102 private: 2120 private:
2103 virtual void RawSetInputAt(intptr_t i, Value* value) {
2104 ASSERT(i == 0);
2105 value_ = value;
2106 }
2107
2108 Value* value_;
2109
2110 DISALLOW_COPY_AND_ASSIGN(PushArgumentInstr); 2121 DISALLOW_COPY_AND_ASSIGN(PushArgumentInstr);
2111 }; 2122 };
2112 2123
2113 2124
2114 inline Definition* Instruction::ArgumentAt(intptr_t index) const { 2125 inline Definition* Instruction::ArgumentAt(intptr_t index) const {
2115 return PushArgumentAt(index)->value()->definition(); 2126 return PushArgumentAt(index)->value()->definition();
2116 } 2127 }
2117 2128
2118 2129
2119 class ReturnInstr : public TemplateInstruction<1> { 2130 class ReturnInstr : public TemplateInstruction<1> {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 private: 2264 private:
2254 JoinEntryInstr* successor_; 2265 JoinEntryInstr* successor_;
2255 double edge_weight_; 2266 double edge_weight_;
2256 2267
2257 // Parallel move that will be used by linear scan register allocator to 2268 // Parallel move that will be used by linear scan register allocator to
2258 // connect live ranges at the end of the block and resolve phis. 2269 // connect live ranges at the end of the block and resolve phis.
2259 ParallelMoveInstr* parallel_move_; 2270 ParallelMoveInstr* parallel_move_;
2260 }; 2271 };
2261 2272
2262 2273
2263 template<intptr_t N>
2264 class TemplateDefinition : public Definition {
2265 public:
2266 TemplateDefinition<N>() : inputs_() { }
2267
2268 virtual intptr_t InputCount() const { return N; }
2269 virtual Value* InputAt(intptr_t i) const { return inputs_[i]; }
2270
2271 protected:
2272 EmbeddedArray<Value*, N> inputs_;
2273
2274 private:
2275 friend class BranchInstr;
2276 friend class IfThenElseInstr;
2277
2278 virtual void RawSetInputAt(intptr_t i, Value* value) {
2279 inputs_[i] = value;
2280 }
2281 };
2282
2283
2284 struct BranchLabels {
2285 Label* true_label;
2286 Label* false_label;
2287 Label* fall_through;
2288 };
2289
2290
2291 class ComparisonInstr : public TemplateDefinition<2> { 2274 class ComparisonInstr : public TemplateDefinition<2> {
2292 public: 2275 public:
2293 Value* left() const { return inputs_[0]; } 2276 Value* left() const { return inputs_[0]; }
2294 Value* right() const { return inputs_[1]; } 2277 Value* right() const { return inputs_[1]; }
2295 2278
2296 virtual ComparisonInstr* AsComparison() { return this; } 2279 virtual ComparisonInstr* AsComparison() { return this; }
2297 2280
2298 virtual intptr_t token_pos() const { return token_pos_; } 2281 virtual intptr_t token_pos() const { return token_pos_; }
2299 Token::Kind kind() const { return kind_; } 2282 Token::Kind kind() const { return kind_; }
2300 2283
(...skipping 5543 matching lines...) Expand 10 before | Expand all | Expand 10 after
7844 } 7827 }
7845 } 7828 }
7846 7829
7847 ShallowIterator iterator_; 7830 ShallowIterator iterator_;
7848 }; 7831 };
7849 7832
7850 // Construct an environment by constructing uses from an array of definitions. 7833 // Construct an environment by constructing uses from an array of definitions.
7851 static Environment* From(Isolate* isolate, 7834 static Environment* From(Isolate* isolate,
7852 const GrowableArray<Definition*>& definitions, 7835 const GrowableArray<Definition*>& definitions,
7853 intptr_t fixed_parameter_count, 7836 intptr_t fixed_parameter_count,
7854 const Code& code); 7837 const ParsedFunction* parsed_function);
7855 7838
7856 void set_locations(Location* locations) { 7839 void set_locations(Location* locations) {
7857 ASSERT(locations_ == NULL); 7840 ASSERT(locations_ == NULL);
7858 locations_ = locations; 7841 locations_ = locations;
7859 } 7842 }
7860 7843
7861 void set_deopt_id(intptr_t deopt_id) { deopt_id_ = deopt_id; } 7844 void set_deopt_id(intptr_t deopt_id) { deopt_id_ = deopt_id; }
7862 intptr_t deopt_id() const { return deopt_id_; } 7845 intptr_t deopt_id() const { return deopt_id_; }
7863 7846
7864 Environment* outer() const { return outer_; } 7847 Environment* outer() const { return outer_; }
(...skipping 19 matching lines...) Expand all
7884 index -= env->Length(); 7867 index -= env->Length();
7885 env = env->outer_; 7868 env = env->outer_;
7886 } 7869 }
7887 return env->ValueAt(index); 7870 return env->ValueAt(index);
7888 } 7871 }
7889 7872
7890 intptr_t fixed_parameter_count() const { 7873 intptr_t fixed_parameter_count() const {
7891 return fixed_parameter_count_; 7874 return fixed_parameter_count_;
7892 } 7875 }
7893 7876
7894 const Code& code() const { return code_; } 7877 const Code& code() const { return parsed_function_->code(); }
7895 7878
7896 Environment* DeepCopy(Isolate* isolate) const { 7879 Environment* DeepCopy(Isolate* isolate) const {
7897 return DeepCopy(isolate, Length()); 7880 return DeepCopy(isolate, Length());
7898 } 7881 }
7899 7882
7900 void DeepCopyTo(Isolate* isolate, Instruction* instr) const; 7883 void DeepCopyTo(Isolate* isolate, Instruction* instr) const;
7901 void DeepCopyToOuter(Isolate* isolate, Instruction* instr) const; 7884 void DeepCopyToOuter(Isolate* isolate, Instruction* instr) const;
7902 7885
7903 void PrintTo(BufferFormatter* f) const; 7886 void PrintTo(BufferFormatter* f) const;
7904 const char* ToCString() const; 7887 const char* ToCString() const;
7905 7888
7906 // Deep copy an environment. The 'length' parameter may be less than the 7889 // Deep copy an environment. The 'length' parameter may be less than the
7907 // environment's length in order to drop values (e.g., passed arguments) 7890 // environment's length in order to drop values (e.g., passed arguments)
7908 // from the copy. 7891 // from the copy.
7909 Environment* DeepCopy(Isolate* isolate, intptr_t length) const; 7892 Environment* DeepCopy(Isolate* isolate, intptr_t length) const;
7910 7893
7911 private: 7894 private:
7912 friend class ShallowIterator; 7895 friend class ShallowIterator;
7913 7896
7914 Environment(intptr_t length, 7897 Environment(intptr_t length,
7915 intptr_t fixed_parameter_count, 7898 intptr_t fixed_parameter_count,
7916 intptr_t deopt_id, 7899 intptr_t deopt_id,
7917 const Code& code, 7900 const ParsedFunction* parsed_function,
7918 Environment* outer) 7901 Environment* outer)
7919 : values_(length), 7902 : values_(length),
7920 locations_(NULL), 7903 locations_(NULL),
7921 fixed_parameter_count_(fixed_parameter_count), 7904 fixed_parameter_count_(fixed_parameter_count),
7922 deopt_id_(deopt_id), 7905 deopt_id_(deopt_id),
7923 code_(code), 7906 parsed_function_(parsed_function),
7924 outer_(outer) { } 7907 outer_(outer) { }
7925 7908
7926 7909
7927 GrowableArray<Value*> values_; 7910 GrowableArray<Value*> values_;
7928 Location* locations_; 7911 Location* locations_;
7929 const intptr_t fixed_parameter_count_; 7912 const intptr_t fixed_parameter_count_;
7930 intptr_t deopt_id_; 7913 intptr_t deopt_id_;
7931 const Code& code_; 7914 const ParsedFunction* parsed_function_;
7932 Environment* outer_; 7915 Environment* outer_;
7933 7916
7934 DISALLOW_COPY_AND_ASSIGN(Environment); 7917 DISALLOW_COPY_AND_ASSIGN(Environment);
7935 }; 7918 };
7936 7919
7937 7920
7938 // Visitor base class to visit each instruction and computation in a flow 7921 // Visitor base class to visit each instruction and computation in a flow
7939 // graph as defined by a reversed list of basic blocks. 7922 // graph as defined by a reversed list of basic blocks.
7940 class FlowGraphVisitor : public ValueObject { 7923 class FlowGraphVisitor : public ValueObject {
7941 public: 7924 public:
(...skipping 23 matching lines...) Expand all
7965 ForwardInstructionIterator* current_iterator_; 7948 ForwardInstructionIterator* current_iterator_;
7966 7949
7967 private: 7950 private:
7968 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 7951 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
7969 }; 7952 };
7970 7953
7971 7954
7972 } // namespace dart 7955 } // namespace dart
7973 7956
7974 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 7957 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_x64.cc ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698