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

Side by Side Diff: vm/intermediate_language.h

Issue 10700034: Add a goto instruction to the IL use it to terminate basic blocks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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) 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
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) \
1710 M(ParallelMove) 1711 M(ParallelMove)
1711 1712
1712 1713
1713 // Forward declarations for Instruction classes. 1714 // Forward declarations for Instruction classes.
1714 class BlockEntryInstr; 1715 class BlockEntryInstr;
1715 class FlowGraphBuilder; 1716 class FlowGraphBuilder;
1716 1717
1717 #define FORWARD_DECLARATION(type) class type##Instr; 1718 #define FORWARD_DECLARATION(type) class type##Instr;
1718 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) 1719 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
1719 #undef FORWARD_DECLARATION 1720 #undef FORWARD_DECLARATION
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 #undef INSTRUCTION_TYPE_CHECK 1812 #undef INSTRUCTION_TYPE_CHECK
1812 1813
1813 // Static type of the instruction. 1814 // Static type of the instruction.
1814 virtual RawAbstractType* StaticType() const { 1815 virtual RawAbstractType* StaticType() const {
1815 UNREACHABLE(); 1816 UNREACHABLE();
1816 return AbstractType::null(); 1817 return AbstractType::null();
1817 } 1818 }
1818 1819
1819 // Returns structure describing location constraints required 1820 // Returns structure describing location constraints required
1820 // to emit native code for this instruction. 1821 // to emit native code for this instruction.
1821 virtual LocationSummary* locs() { 1822 virtual LocationSummary* locs() = 0;
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 }
1827 1823
1828 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { 1824 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
1829 UNIMPLEMENTED(); 1825 UNIMPLEMENTED();
1830 } 1826 }
1831 1827
1832 private: 1828 private:
1833 intptr_t cid_; 1829 intptr_t cid_;
1834 ICData* ic_data_; 1830 ICData* ic_data_;
1835 DISALLOW_COPY_AND_ASSIGN(Instruction); 1831 DISALLOW_COPY_AND_ASSIGN(Instruction);
1836 }; 1832 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; } 1879 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; }
1884 1880
1885 const GrowableArray<BlockEntryInstr*>& dominated_blocks() { 1881 const GrowableArray<BlockEntryInstr*>& dominated_blocks() {
1886 return dominated_blocks_; 1882 return dominated_blocks_;
1887 } 1883 }
1888 1884
1889 void AddDominatedBlock(BlockEntryInstr* block) { 1885 void AddDominatedBlock(BlockEntryInstr* block) {
1890 dominated_blocks_.Add(block); 1886 dominated_blocks_.Add(block);
1891 } 1887 }
1892 1888
1893 Instruction* last_instruction() const { return last_instruction_; } 1889 inline Instruction* last_instruction() const;
1894 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } 1890 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; }
1895 1891
1896 virtual void DiscoverBlocks( 1892 virtual void DiscoverBlocks(
1897 BlockEntryInstr* current_block, 1893 BlockEntryInstr* current_block,
1898 GrowableArray<BlockEntryInstr*>* preorder, 1894 GrowableArray<BlockEntryInstr*>* preorder,
1899 GrowableArray<BlockEntryInstr*>* postorder, 1895 GrowableArray<BlockEntryInstr*>* postorder,
1900 GrowableArray<intptr_t>* parent, 1896 GrowableArray<intptr_t>* parent,
1901 GrowableArray<BitVector*>* assigned_vars, 1897 GrowableArray<BitVector*>* assigned_vars,
1902 intptr_t variable_count); 1898 intptr_t variable_count);
1903 1899
1900 virtual LocationSummary* locs() { return NULL; }
1901
1904 protected: 1902 protected:
1905 BlockEntryInstr() 1903 BlockEntryInstr()
1906 : preorder_number_(-1), 1904 : preorder_number_(-1),
1907 postorder_number_(-1), 1905 postorder_number_(-1),
1908 block_id_(-1), 1906 block_id_(-1),
1909 dominator_(NULL), 1907 dominator_(NULL),
1910 dominated_blocks_(1), 1908 dominated_blocks_(1),
1911 last_instruction_(NULL) { } 1909 last_instruction_(NULL) { }
1912 1910
1913 private: 1911 private:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 return predecessors_[index]; 1984 return predecessors_[index];
1987 } 1985 }
1988 virtual void AddPredecessor(BlockEntryInstr* predecessor) { 1986 virtual void AddPredecessor(BlockEntryInstr* predecessor) {
1989 predecessors_.Add(predecessor); 1987 predecessors_.Add(predecessor);
1990 } 1988 }
1991 1989
1992 virtual Instruction* StraightLineSuccessor() const { 1990 virtual Instruction* StraightLineSuccessor() const {
1993 return successor_; 1991 return successor_;
1994 } 1992 }
1995 virtual void SetSuccessor(Instruction* instr) { 1993 virtual void SetSuccessor(Instruction* instr) {
1994 ASSERT(instr == NULL || !instr->IsBlockEntry());
1996 successor_ = instr; 1995 successor_ = instr;
1997 } 1996 }
1998 1997
1999 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } 1998 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; }
2000 1999
2001 virtual void PrepareEntry(FlowGraphCompiler* compiler); 2000 virtual void PrepareEntry(FlowGraphCompiler* compiler);
2002 2001
2003 void InsertPhi(intptr_t var_index, intptr_t var_count); 2002 void InsertPhi(intptr_t var_index, intptr_t var_count);
2004 2003
2005 intptr_t phi_count() const { return phi_count_; } 2004 intptr_t phi_count() const { return phi_count_; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 } 2039 }
2041 virtual void AddPredecessor(BlockEntryInstr* predecessor) { 2040 virtual void AddPredecessor(BlockEntryInstr* predecessor) {
2042 ASSERT(predecessor_ == NULL); 2041 ASSERT(predecessor_ == NULL);
2043 predecessor_ = predecessor; 2042 predecessor_ = predecessor;
2044 } 2043 }
2045 2044
2046 virtual Instruction* StraightLineSuccessor() const { 2045 virtual Instruction* StraightLineSuccessor() const {
2047 return successor_; 2046 return successor_;
2048 } 2047 }
2049 virtual void SetSuccessor(Instruction* instr) { 2048 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
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());
2091 successor_ = instr; 2092 successor_ = instr;
2092 } 2093 }
2093 2094
2094 virtual void RecordAssignedVars(BitVector* assigned_vars); 2095 virtual void RecordAssignedVars(BitVector* assigned_vars);
2095 2096
2096 virtual LocationSummary* locs() { 2097 virtual LocationSummary* locs() {
2097 return computation()->locs(); 2098 return computation()->locs();
2098 } 2099 }
2099 2100
2100 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { 2101 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 DECLARE_INSTRUCTION(Bind) 2143 DECLARE_INSTRUCTION(Bind)
2143 2144
2144 Computation* computation() const { return computation_; } 2145 Computation* computation() const { return computation_; }
2145 virtual void replace_computation(Computation* value) { computation_ = value; } 2146 virtual void replace_computation(Computation* value) { computation_ = value; }
2146 2147
2147 virtual Instruction* StraightLineSuccessor() const { 2148 virtual Instruction* StraightLineSuccessor() const {
2148 return successor_; 2149 return successor_;
2149 } 2150 }
2150 2151
2151 virtual void SetSuccessor(Instruction* instr) { 2152 virtual void SetSuccessor(Instruction* instr) {
2153 ASSERT(instr == NULL || !instr->IsBlockEntry());
2152 successor_ = instr; 2154 successor_ = instr;
2153 } 2155 }
2154 2156
2155 // Static type of the underlying computation. 2157 // Static type of the underlying computation.
2156 virtual RawAbstractType* StaticType() const { 2158 virtual RawAbstractType* StaticType() const {
2157 return computation()->StaticType(); 2159 return computation()->StaticType();
2158 } 2160 }
2159 2161
2160 virtual void RecordAssignedVars(BitVector* assigned_vars); 2162 virtual void RecordAssignedVars(BitVector* assigned_vars);
2161 2163
(...skipping 17 matching lines...) Expand all
2179 for (intptr_t i = 0; i < num_inputs; ++i) { 2181 for (intptr_t i = 0; i < num_inputs; ++i) {
2180 inputs_.Add(NULL); 2182 inputs_.Add(NULL);
2181 } 2183 }
2182 } 2184 }
2183 2185
2184 DECLARE_INSTRUCTION(Phi) 2186 DECLARE_INSTRUCTION(Phi)
2185 2187
2186 virtual Instruction* StraightLineSuccessor() const { return NULL; } 2188 virtual Instruction* StraightLineSuccessor() const { return NULL; }
2187 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 2189 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
2188 2190
2191 virtual LocationSummary* locs() { return NULL; }
2192
2189 private: 2193 private:
2190 GrowableArray<Value*> inputs_; 2194 GrowableArray<Value*> inputs_;
2191 2195
2192 DISALLOW_COPY_AND_ASSIGN(PhiInstr); 2196 DISALLOW_COPY_AND_ASSIGN(PhiInstr);
2193 }; 2197 };
2194 2198
2195 2199
2196 class ReturnInstr : public InstructionWithInputs { 2200 class ReturnInstr : public InstructionWithInputs {
2197 public: 2201 public:
2198 ReturnInstr(intptr_t token_pos, Value* value) 2202 ReturnInstr(intptr_t token_pos, Value* value)
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 Value* value_; 2363 Value* value_;
2360 TargetEntryInstr* true_successor_; 2364 TargetEntryInstr* true_successor_;
2361 TargetEntryInstr* false_successor_; 2365 TargetEntryInstr* false_successor_;
2362 bool is_fused_with_comparison_; 2366 bool is_fused_with_comparison_;
2363 bool is_negated_; 2367 bool is_negated_;
2364 2368
2365 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 2369 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
2366 }; 2370 };
2367 2371
2368 2372
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; }
Vyacheslav Egorov (Google) 2012/06/29 16:06:03 () { single space
Florian Schneider 2012/06/29 16:13:12 Done.
2388
2389 private:
2390 BlockEntryInstr* successor_;
2391 };
2392
2393
2369 class MoveOperands : public ValueObject { 2394 class MoveOperands : public ValueObject {
2370 public: 2395 public:
2371 MoveOperands(Location dest, Location src) : dest_(dest), src_(src) { } 2396 MoveOperands(Location dest, Location src) : dest_(dest), src_(src) { }
2372 2397
2373 Location src() const { return src_; } 2398 Location src() const { return src_; }
2374 Location dest() const { return dest_; } 2399 Location dest() const { return dest_; }
2375 2400
2376 private: 2401 private:
2377 Location dest_; 2402 Location dest_;
2378 Location src_; 2403 Location src_;
(...skipping 14 matching lines...) Expand all
2393 2418
2394 private: 2419 private:
2395 GrowableArray<MoveOperands> moves_; 2420 GrowableArray<MoveOperands> moves_;
2396 2421
2397 DISALLOW_COPY_AND_ASSIGN(ParallelMoveInstr); 2422 DISALLOW_COPY_AND_ASSIGN(ParallelMoveInstr);
2398 }; 2423 };
2399 2424
2400 #undef DECLARE_INSTRUCTION 2425 #undef DECLARE_INSTRUCTION
2401 2426
2402 2427
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
2403 // Visitor base class to visit each instruction and computation in a flow 2439 // Visitor base class to visit each instruction and computation in a flow
2404 // graph as defined by a reversed list of basic blocks. 2440 // graph as defined by a reversed list of basic blocks.
2405 class FlowGraphVisitor : public ValueObject { 2441 class FlowGraphVisitor : public ValueObject {
2406 public: 2442 public:
2407 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) 2443 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order)
2408 : block_order_(block_order) { } 2444 : block_order_(block_order) { }
2409 virtual ~FlowGraphVisitor() { } 2445 virtual ~FlowGraphVisitor() { }
2410 2446
2411 // Visit each block in the block order, and for each block its 2447 // Visit each block in the block order, and for each block its
2412 // instructions in order from the block entry to exit. 2448 // instructions in order from the block entry to exit.
(...skipping 17 matching lines...) Expand all
2430 const GrowableArray<BlockEntryInstr*>& block_order_; 2466 const GrowableArray<BlockEntryInstr*>& block_order_;
2431 2467
2432 private: 2468 private:
2433 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2469 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2434 }; 2470 };
2435 2471
2436 2472
2437 } // namespace dart 2473 } // namespace dart
2438 2474
2439 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2475 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« vm/flow_graph_builder.cc ('K') | « vm/il_printer.cc ('k') | vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698