| OLD | NEW |
| 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 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 M(GraphEntry) \ | 1700 M(GraphEntry) \ |
| 1701 M(JoinEntry) \ | 1701 M(JoinEntry) \ |
| 1702 M(TargetEntry) \ | 1702 M(TargetEntry) \ |
| 1703 M(Do) \ | 1703 M(Do) \ |
| 1704 M(Bind) \ | 1704 M(Bind) \ |
| 1705 M(Phi) \ | 1705 M(Phi) \ |
| 1706 M(Return) \ | 1706 M(Return) \ |
| 1707 M(Throw) \ | 1707 M(Throw) \ |
| 1708 M(ReThrow) \ | 1708 M(ReThrow) \ |
| 1709 M(Branch) \ | 1709 M(Branch) \ |
| 1710 M(Goto) \ | |
| 1711 M(ParallelMove) | 1710 M(ParallelMove) |
| 1712 | 1711 |
| 1713 | 1712 |
| 1714 // Forward declarations for Instruction classes. | 1713 // Forward declarations for Instruction classes. |
| 1715 class BlockEntryInstr; | 1714 class BlockEntryInstr; |
| 1716 class FlowGraphBuilder; | 1715 class FlowGraphBuilder; |
| 1717 | 1716 |
| 1718 #define FORWARD_DECLARATION(type) class type##Instr; | 1717 #define FORWARD_DECLARATION(type) class type##Instr; |
| 1719 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) | 1718 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1720 #undef FORWARD_DECLARATION | 1719 #undef FORWARD_DECLARATION |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 #undef INSTRUCTION_TYPE_CHECK | 1811 #undef INSTRUCTION_TYPE_CHECK |
| 1813 | 1812 |
| 1814 // Static type of the instruction. | 1813 // Static type of the instruction. |
| 1815 virtual RawAbstractType* StaticType() const { | 1814 virtual RawAbstractType* StaticType() const { |
| 1816 UNREACHABLE(); | 1815 UNREACHABLE(); |
| 1817 return AbstractType::null(); | 1816 return AbstractType::null(); |
| 1818 } | 1817 } |
| 1819 | 1818 |
| 1820 // Returns structure describing location constraints required | 1819 // Returns structure describing location constraints required |
| 1821 // to emit native code for this instruction. | 1820 // to emit native code for this instruction. |
| 1822 virtual LocationSummary* locs() = 0; | 1821 virtual LocationSummary* locs() { |
| 1822 // TODO(vegorov): This should be pure virtual method. |
| 1823 // However we are temporary using NULL for instructions that |
| 1824 // were not converted to the location based code generation yet. |
| 1825 return NULL; |
| 1826 } |
| 1823 | 1827 |
| 1824 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { | 1828 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 1825 UNIMPLEMENTED(); | 1829 UNIMPLEMENTED(); |
| 1826 } | 1830 } |
| 1827 | 1831 |
| 1828 private: | 1832 private: |
| 1829 intptr_t cid_; | 1833 intptr_t cid_; |
| 1830 ICData* ic_data_; | 1834 ICData* ic_data_; |
| 1831 DISALLOW_COPY_AND_ASSIGN(Instruction); | 1835 DISALLOW_COPY_AND_ASSIGN(Instruction); |
| 1832 }; | 1836 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; } | 1883 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; } |
| 1880 | 1884 |
| 1881 const GrowableArray<BlockEntryInstr*>& dominated_blocks() { | 1885 const GrowableArray<BlockEntryInstr*>& dominated_blocks() { |
| 1882 return dominated_blocks_; | 1886 return dominated_blocks_; |
| 1883 } | 1887 } |
| 1884 | 1888 |
| 1885 void AddDominatedBlock(BlockEntryInstr* block) { | 1889 void AddDominatedBlock(BlockEntryInstr* block) { |
| 1886 dominated_blocks_.Add(block); | 1890 dominated_blocks_.Add(block); |
| 1887 } | 1891 } |
| 1888 | 1892 |
| 1889 inline Instruction* last_instruction() const; | 1893 Instruction* last_instruction() const { return last_instruction_; } |
| 1890 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } | 1894 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } |
| 1891 | 1895 |
| 1892 virtual void DiscoverBlocks( | 1896 virtual void DiscoverBlocks( |
| 1893 BlockEntryInstr* current_block, | 1897 BlockEntryInstr* current_block, |
| 1894 GrowableArray<BlockEntryInstr*>* preorder, | 1898 GrowableArray<BlockEntryInstr*>* preorder, |
| 1895 GrowableArray<BlockEntryInstr*>* postorder, | 1899 GrowableArray<BlockEntryInstr*>* postorder, |
| 1896 GrowableArray<intptr_t>* parent, | 1900 GrowableArray<intptr_t>* parent, |
| 1897 GrowableArray<BitVector*>* assigned_vars, | 1901 GrowableArray<BitVector*>* assigned_vars, |
| 1898 intptr_t variable_count); | 1902 intptr_t variable_count); |
| 1899 | 1903 |
| 1900 virtual LocationSummary* locs() { return NULL; } | |
| 1901 | |
| 1902 protected: | 1904 protected: |
| 1903 BlockEntryInstr() | 1905 BlockEntryInstr() |
| 1904 : preorder_number_(-1), | 1906 : preorder_number_(-1), |
| 1905 postorder_number_(-1), | 1907 postorder_number_(-1), |
| 1906 block_id_(-1), | 1908 block_id_(-1), |
| 1907 dominator_(NULL), | 1909 dominator_(NULL), |
| 1908 dominated_blocks_(1), | 1910 dominated_blocks_(1), |
| 1909 last_instruction_(NULL) { } | 1911 last_instruction_(NULL) { } |
| 1910 | 1912 |
| 1911 private: | 1913 private: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 return predecessors_[index]; | 1986 return predecessors_[index]; |
| 1985 } | 1987 } |
| 1986 virtual void AddPredecessor(BlockEntryInstr* predecessor) { | 1988 virtual void AddPredecessor(BlockEntryInstr* predecessor) { |
| 1987 predecessors_.Add(predecessor); | 1989 predecessors_.Add(predecessor); |
| 1988 } | 1990 } |
| 1989 | 1991 |
| 1990 virtual Instruction* StraightLineSuccessor() const { | 1992 virtual Instruction* StraightLineSuccessor() const { |
| 1991 return successor_; | 1993 return successor_; |
| 1992 } | 1994 } |
| 1993 virtual void SetSuccessor(Instruction* instr) { | 1995 virtual void SetSuccessor(Instruction* instr) { |
| 1994 ASSERT(instr == NULL || !instr->IsBlockEntry()); | |
| 1995 successor_ = instr; | 1996 successor_ = instr; |
| 1996 } | 1997 } |
| 1997 | 1998 |
| 1998 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } | 1999 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } |
| 1999 | 2000 |
| 2000 virtual void PrepareEntry(FlowGraphCompiler* compiler); | 2001 virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| 2001 | 2002 |
| 2002 void InsertPhi(intptr_t var_index, intptr_t var_count); | 2003 void InsertPhi(intptr_t var_index, intptr_t var_count); |
| 2003 | 2004 |
| 2004 intptr_t phi_count() const { return phi_count_; } | 2005 intptr_t phi_count() const { return phi_count_; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 } | 2040 } |
| 2040 virtual void AddPredecessor(BlockEntryInstr* predecessor) { | 2041 virtual void AddPredecessor(BlockEntryInstr* predecessor) { |
| 2041 ASSERT(predecessor_ == NULL); | 2042 ASSERT(predecessor_ == NULL); |
| 2042 predecessor_ = predecessor; | 2043 predecessor_ = predecessor; |
| 2043 } | 2044 } |
| 2044 | 2045 |
| 2045 virtual Instruction* StraightLineSuccessor() const { | 2046 virtual Instruction* StraightLineSuccessor() const { |
| 2046 return successor_; | 2047 return successor_; |
| 2047 } | 2048 } |
| 2048 virtual void SetSuccessor(Instruction* instr) { | 2049 virtual void SetSuccessor(Instruction* instr) { |
| 2049 ASSERT(instr == NULL || !instr->IsBlockEntry()); | |
| 2050 successor_ = instr; | 2050 successor_ = instr; |
| 2051 } | 2051 } |
| 2052 | 2052 |
| 2053 bool HasTryIndex() const { | 2053 bool HasTryIndex() const { |
| 2054 return try_index_ != CatchClauseNode::kInvalidTryIndex; | 2054 return try_index_ != CatchClauseNode::kInvalidTryIndex; |
| 2055 } | 2055 } |
| 2056 | 2056 |
| 2057 intptr_t try_index() const { | 2057 intptr_t try_index() const { |
| 2058 ASSERT(HasTryIndex()); | 2058 ASSERT(HasTryIndex()); |
| 2059 return try_index_; | 2059 return try_index_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2081 DECLARE_INSTRUCTION(Do) | 2081 DECLARE_INSTRUCTION(Do) |
| 2082 | 2082 |
| 2083 Computation* computation() const { return computation_; } | 2083 Computation* computation() const { return computation_; } |
| 2084 virtual void replace_computation(Computation* value) { computation_ = value; } | 2084 virtual void replace_computation(Computation* value) { computation_ = value; } |
| 2085 | 2085 |
| 2086 virtual Instruction* StraightLineSuccessor() const { | 2086 virtual Instruction* StraightLineSuccessor() const { |
| 2087 return successor_; | 2087 return successor_; |
| 2088 } | 2088 } |
| 2089 | 2089 |
| 2090 virtual void SetSuccessor(Instruction* instr) { | 2090 virtual void SetSuccessor(Instruction* instr) { |
| 2091 ASSERT(instr == NULL || !instr->IsBlockEntry()); | |
| 2092 successor_ = instr; | 2091 successor_ = instr; |
| 2093 } | 2092 } |
| 2094 | 2093 |
| 2095 virtual void RecordAssignedVars(BitVector* assigned_vars); | 2094 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 2096 | 2095 |
| 2097 virtual LocationSummary* locs() { | 2096 virtual LocationSummary* locs() { |
| 2098 return computation()->locs(); | 2097 return computation()->locs(); |
| 2099 } | 2098 } |
| 2100 | 2099 |
| 2101 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { | 2100 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2143 DECLARE_INSTRUCTION(Bind) | 2142 DECLARE_INSTRUCTION(Bind) |
| 2144 | 2143 |
| 2145 Computation* computation() const { return computation_; } | 2144 Computation* computation() const { return computation_; } |
| 2146 virtual void replace_computation(Computation* value) { computation_ = value; } | 2145 virtual void replace_computation(Computation* value) { computation_ = value; } |
| 2147 | 2146 |
| 2148 virtual Instruction* StraightLineSuccessor() const { | 2147 virtual Instruction* StraightLineSuccessor() const { |
| 2149 return successor_; | 2148 return successor_; |
| 2150 } | 2149 } |
| 2151 | 2150 |
| 2152 virtual void SetSuccessor(Instruction* instr) { | 2151 virtual void SetSuccessor(Instruction* instr) { |
| 2153 ASSERT(instr == NULL || !instr->IsBlockEntry()); | |
| 2154 successor_ = instr; | 2152 successor_ = instr; |
| 2155 } | 2153 } |
| 2156 | 2154 |
| 2157 // Static type of the underlying computation. | 2155 // Static type of the underlying computation. |
| 2158 virtual RawAbstractType* StaticType() const { | 2156 virtual RawAbstractType* StaticType() const { |
| 2159 return computation()->StaticType(); | 2157 return computation()->StaticType(); |
| 2160 } | 2158 } |
| 2161 | 2159 |
| 2162 virtual void RecordAssignedVars(BitVector* assigned_vars); | 2160 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 2163 | 2161 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2181 for (intptr_t i = 0; i < num_inputs; ++i) { | 2179 for (intptr_t i = 0; i < num_inputs; ++i) { |
| 2182 inputs_.Add(NULL); | 2180 inputs_.Add(NULL); |
| 2183 } | 2181 } |
| 2184 } | 2182 } |
| 2185 | 2183 |
| 2186 DECLARE_INSTRUCTION(Phi) | 2184 DECLARE_INSTRUCTION(Phi) |
| 2187 | 2185 |
| 2188 virtual Instruction* StraightLineSuccessor() const { return NULL; } | 2186 virtual Instruction* StraightLineSuccessor() const { return NULL; } |
| 2189 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } | 2187 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| 2190 | 2188 |
| 2191 virtual LocationSummary* locs() { return NULL; } | |
| 2192 | |
| 2193 private: | 2189 private: |
| 2194 GrowableArray<Value*> inputs_; | 2190 GrowableArray<Value*> inputs_; |
| 2195 | 2191 |
| 2196 DISALLOW_COPY_AND_ASSIGN(PhiInstr); | 2192 DISALLOW_COPY_AND_ASSIGN(PhiInstr); |
| 2197 }; | 2193 }; |
| 2198 | 2194 |
| 2199 | 2195 |
| 2200 class ReturnInstr : public InstructionWithInputs { | 2196 class ReturnInstr : public InstructionWithInputs { |
| 2201 public: | 2197 public: |
| 2202 ReturnInstr(intptr_t token_pos, Value* value) | 2198 ReturnInstr(intptr_t token_pos, Value* value) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2363 Value* value_; | 2359 Value* value_; |
| 2364 TargetEntryInstr* true_successor_; | 2360 TargetEntryInstr* true_successor_; |
| 2365 TargetEntryInstr* false_successor_; | 2361 TargetEntryInstr* false_successor_; |
| 2366 bool is_fused_with_comparison_; | 2362 bool is_fused_with_comparison_; |
| 2367 bool is_negated_; | 2363 bool is_negated_; |
| 2368 | 2364 |
| 2369 DISALLOW_COPY_AND_ASSIGN(BranchInstr); | 2365 DISALLOW_COPY_AND_ASSIGN(BranchInstr); |
| 2370 }; | 2366 }; |
| 2371 | 2367 |
| 2372 | 2368 |
| 2373 class GotoInstr : public Instruction { | |
| 2374 public: | |
| 2375 explicit GotoInstr(BlockEntryInstr* successor) | |
| 2376 : successor_(successor) { | |
| 2377 ASSERT(successor != NULL); | |
| 2378 } | |
| 2379 | |
| 2380 DECLARE_INSTRUCTION(Goto) | |
| 2381 | |
| 2382 virtual Instruction* StraightLineSuccessor() const { return successor_; } | |
| 2383 virtual void SetSuccessor(Instruction* instr) { | |
| 2384 successor_ = instr->AsBlockEntry(); | |
| 2385 } | |
| 2386 | |
| 2387 virtual LocationSummary* locs() { return NULL; } | |
| 2388 | |
| 2389 private: | |
| 2390 BlockEntryInstr* successor_; | |
| 2391 }; | |
| 2392 | |
| 2393 | |
| 2394 class MoveOperands : public ValueObject { | 2369 class MoveOperands : public ValueObject { |
| 2395 public: | 2370 public: |
| 2396 MoveOperands(Location dest, Location src) : dest_(dest), src_(src) { } | 2371 MoveOperands(Location dest, Location src) : dest_(dest), src_(src) { } |
| 2397 | 2372 |
| 2398 Location src() const { return src_; } | 2373 Location src() const { return src_; } |
| 2399 Location dest() const { return dest_; } | 2374 Location dest() const { return dest_; } |
| 2400 | 2375 |
| 2401 private: | 2376 private: |
| 2402 Location dest_; | 2377 Location dest_; |
| 2403 Location src_; | 2378 Location src_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2418 | 2393 |
| 2419 private: | 2394 private: |
| 2420 GrowableArray<MoveOperands> moves_; | 2395 GrowableArray<MoveOperands> moves_; |
| 2421 | 2396 |
| 2422 DISALLOW_COPY_AND_ASSIGN(ParallelMoveInstr); | 2397 DISALLOW_COPY_AND_ASSIGN(ParallelMoveInstr); |
| 2423 }; | 2398 }; |
| 2424 | 2399 |
| 2425 #undef DECLARE_INSTRUCTION | 2400 #undef DECLARE_INSTRUCTION |
| 2426 | 2401 |
| 2427 | 2402 |
| 2428 // Definition of inline functions. | |
| 2429 Instruction* BlockEntryInstr::last_instruction() const { | |
| 2430 ASSERT(last_instruction_->IsGraphEntry() || | |
| 2431 last_instruction_->IsGoto() || | |
| 2432 last_instruction_->IsReturn() || | |
| 2433 last_instruction_->IsBranch() || | |
| 2434 last_instruction_->IsThrow() || | |
| 2435 last_instruction_->IsReThrow()); | |
| 2436 return last_instruction_; | |
| 2437 } | |
| 2438 | |
| 2439 // Visitor base class to visit each instruction and computation in a flow | 2403 // Visitor base class to visit each instruction and computation in a flow |
| 2440 // graph as defined by a reversed list of basic blocks. | 2404 // graph as defined by a reversed list of basic blocks. |
| 2441 class FlowGraphVisitor : public ValueObject { | 2405 class FlowGraphVisitor : public ValueObject { |
| 2442 public: | 2406 public: |
| 2443 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) | 2407 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) |
| 2444 : block_order_(block_order) { } | 2408 : block_order_(block_order) { } |
| 2445 virtual ~FlowGraphVisitor() { } | 2409 virtual ~FlowGraphVisitor() { } |
| 2446 | 2410 |
| 2447 // Visit each block in the block order, and for each block its | 2411 // Visit each block in the block order, and for each block its |
| 2448 // instructions in order from the block entry to exit. | 2412 // instructions in order from the block entry to exit. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2466 const GrowableArray<BlockEntryInstr*>& block_order_; | 2430 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2467 | 2431 |
| 2468 private: | 2432 private: |
| 2469 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2433 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2470 }; | 2434 }; |
| 2471 | 2435 |
| 2472 | 2436 |
| 2473 } // namespace dart | 2437 } // namespace dart |
| 2474 | 2438 |
| 2475 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2439 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |