| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ast.h" | 31 #include "ast.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 // Values appear in instructions. They represent trivial source | 36 // Values appear in instructions. They represent trivial source |
| 37 // expressions: ones with no side effects and that do not require code to be | 37 // expressions: ones with no side effects and that do not require code to be |
| 38 // generated. | 38 // generated. |
| 39 class Value : public ZoneObject { | 39 class Value : public ZoneObject { |
| 40 public: | 40 public: |
| 41 virtual ~Value() {} |
| 42 |
| 41 virtual void ToRegister(MacroAssembler* masm, Register reg) = 0; | 43 virtual void ToRegister(MacroAssembler* masm, Register reg) = 0; |
| 42 | 44 |
| 43 #ifdef DEBUG | 45 #ifdef DEBUG |
| 44 virtual void Print() = 0; | 46 virtual void Print() = 0; |
| 45 #endif | 47 #endif |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 | 50 |
| 49 // A compile-time constant that appeared as a literal in the source AST. | 51 // A compile-time constant that appeared as a literal in the source AST. |
| 50 class Constant : public Value { | 52 class Constant : public Value { |
| 51 public: | 53 public: |
| 52 explicit Constant(Handle<Object> handle) : handle_(handle) {} | 54 explicit Constant(Handle<Object> handle) : handle_(handle) {} |
| 53 | 55 |
| 54 virtual void ToRegister(MacroAssembler* masm, Register reg); | 56 virtual ~Constant() {} |
| 57 |
| 58 void ToRegister(MacroAssembler* masm, Register reg); |
| 55 | 59 |
| 56 #ifdef DEBUG | 60 #ifdef DEBUG |
| 57 void Print(); | 61 void Print(); |
| 58 #endif | 62 #endif |
| 59 | 63 |
| 60 private: | 64 private: |
| 61 Handle<Object> handle_; | 65 Handle<Object> handle_; |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 | 68 |
| 65 // Instructions are computations. The represent non-trivial source | 69 // Instructions are computations. The represent non-trivial source |
| 66 // expressions: typically ones that have side effects and require code to | 70 // expressions: typically ones that have side effects and require code to |
| 67 // be generated. | 71 // be generated. |
| 68 class Instruction : public ZoneObject { | 72 class Instruction : public ZoneObject { |
| 69 public: | 73 public: |
| 74 virtual ~Instruction() {} |
| 75 |
| 70 virtual void Compile(MacroAssembler* masm) = 0; | 76 virtual void Compile(MacroAssembler* masm) = 0; |
| 71 | 77 |
| 72 #ifdef DEBUG | 78 #ifdef DEBUG |
| 73 virtual void Print() = 0; | 79 virtual void Print() = 0; |
| 74 #endif | 80 #endif |
| 75 }; | 81 }; |
| 76 | 82 |
| 77 | 83 |
| 78 // Return a value. | 84 // Return a value. |
| 79 class ReturnInstr : public Instruction { | 85 class ReturnInstr : public Instruction { |
| 80 public: | 86 public: |
| 81 explicit ReturnInstr(Value* value) : value_(value) {} | 87 explicit ReturnInstr(Value* value) : value_(value) {} |
| 82 | 88 |
| 89 virtual ~ReturnInstr() {} |
| 90 |
| 83 void Compile(MacroAssembler* masm); | 91 void Compile(MacroAssembler* masm); |
| 84 | 92 |
| 85 #ifdef DEBUG | 93 #ifdef DEBUG |
| 86 void Print(); | 94 void Print(); |
| 87 #endif | 95 #endif |
| 88 | 96 |
| 89 private: | 97 private: |
| 90 Value* value_; | 98 Value* value_; |
| 91 }; | 99 }; |
| 92 | 100 |
| 93 | 101 |
| 94 // Nodes make up control-flow graphs. They contain single-entry, | 102 // Nodes make up control-flow graphs. They contain single-entry, |
| 95 // single-exit blocks of instructions and administrative nodes making up the | 103 // single-exit blocks of instructions and administrative nodes making up the |
| 96 // graph structure. | 104 // graph structure. |
| 97 class CfgNode : public ZoneObject { | 105 class CfgNode : public ZoneObject { |
| 98 public: | 106 public: |
| 99 CfgNode() : is_marked_(false) { | 107 CfgNode() : is_marked_(false) { |
| 100 #ifdef DEBUG | 108 #ifdef DEBUG |
| 101 number_ = -1; | 109 number_ = -1; |
| 102 #endif | 110 #endif |
| 103 } | 111 } |
| 104 | 112 |
| 113 virtual ~CfgNode() {} |
| 114 |
| 105 bool is_marked() { return is_marked_; } | 115 bool is_marked() { return is_marked_; } |
| 106 | 116 |
| 107 static void Reset(); | 117 static void Reset(); |
| 108 | 118 |
| 109 virtual bool is_block() { return false; } | 119 virtual bool is_block() { return false; } |
| 110 | 120 |
| 111 virtual void Unmark() = 0; | 121 virtual void Unmark() = 0; |
| 112 | 122 |
| 113 virtual void Compile(MacroAssembler* masm) = 0; | 123 virtual void Compile(MacroAssembler* masm) = 0; |
| 114 | 124 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 static int node_counter_; | 140 static int node_counter_; |
| 131 #endif | 141 #endif |
| 132 }; | 142 }; |
| 133 | 143 |
| 134 | 144 |
| 135 // A block is a single-entry, single-exit block of instructions. | 145 // A block is a single-entry, single-exit block of instructions. |
| 136 class InstructionBlock : public CfgNode { | 146 class InstructionBlock : public CfgNode { |
| 137 public: | 147 public: |
| 138 InstructionBlock() : successor_(NULL), instructions_(4) {} | 148 InstructionBlock() : successor_(NULL), instructions_(4) {} |
| 139 | 149 |
| 150 virtual ~InstructionBlock() {} |
| 151 |
| 140 static InstructionBlock* cast(CfgNode* node) { | 152 static InstructionBlock* cast(CfgNode* node) { |
| 141 ASSERT(node->is_block()); | 153 ASSERT(node->is_block()); |
| 142 return reinterpret_cast<InstructionBlock*>(node); | 154 return reinterpret_cast<InstructionBlock*>(node); |
| 143 } | 155 } |
| 144 | 156 |
| 145 void set_successor(CfgNode* succ) { | 157 void set_successor(CfgNode* succ) { |
| 146 ASSERT(successor_ == NULL); | 158 ASSERT(successor_ == NULL); |
| 147 successor_ = succ; | 159 successor_ = succ; |
| 148 } | 160 } |
| 149 | 161 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 165 }; | 177 }; |
| 166 | 178 |
| 167 | 179 |
| 168 // The CFG for a function has a distinguished entry node. It has no | 180 // The CFG for a function has a distinguished entry node. It has no |
| 169 // predecessors and a single successor. The successor is the block | 181 // predecessors and a single successor. The successor is the block |
| 170 // containing the function's first instruction. | 182 // containing the function's first instruction. |
| 171 class EntryNode : public CfgNode { | 183 class EntryNode : public CfgNode { |
| 172 public: | 184 public: |
| 173 EntryNode(FunctionLiteral* fun, InstructionBlock* succ); | 185 EntryNode(FunctionLiteral* fun, InstructionBlock* succ); |
| 174 | 186 |
| 187 virtual ~EntryNode() {} |
| 188 |
| 175 void Unmark(); | 189 void Unmark(); |
| 176 | 190 |
| 177 void Compile(MacroAssembler* masm); | 191 void Compile(MacroAssembler* masm); |
| 178 | 192 |
| 179 #ifdef DEBUG | 193 #ifdef DEBUG |
| 180 void Print(); | 194 void Print(); |
| 181 #endif | 195 #endif |
| 182 | 196 |
| 183 private: | 197 private: |
| 184 InstructionBlock* successor_; | 198 InstructionBlock* successor_; |
| 185 int local_count_; | 199 int local_count_; |
| 186 }; | 200 }; |
| 187 | 201 |
| 188 | 202 |
| 189 // The CFG for a function has a distinguished exit node. It has no | 203 // The CFG for a function has a distinguished exit node. It has no |
| 190 // successor and arbitrarily many predecessors. The predecessors are all | 204 // successor and arbitrarily many predecessors. The predecessors are all |
| 191 // the blocks returning from the function. | 205 // the blocks returning from the function. |
| 192 class ExitNode : public CfgNode { | 206 class ExitNode : public CfgNode { |
| 193 public: | 207 public: |
| 194 explicit ExitNode(FunctionLiteral* fun); | 208 explicit ExitNode(FunctionLiteral* fun); |
| 195 | 209 |
| 210 virtual ~ExitNode() {} |
| 211 |
| 196 void Unmark(); | 212 void Unmark(); |
| 197 | 213 |
| 198 void Compile(MacroAssembler* masm); | 214 void Compile(MacroAssembler* masm); |
| 199 | 215 |
| 200 #ifdef DEBUG | 216 #ifdef DEBUG |
| 201 void Print(); | 217 void Print(); |
| 202 #endif | 218 #endif |
| 203 | 219 |
| 204 private: | 220 private: |
| 205 int parameter_count_; | 221 int parameter_count_; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 #undef DECLARE_VISIT | 318 #undef DECLARE_VISIT |
| 303 | 319 |
| 304 private: | 320 private: |
| 305 Cfg* cfg_; | 321 Cfg* cfg_; |
| 306 }; | 322 }; |
| 307 | 323 |
| 308 | 324 |
| 309 } } // namespace v8::internal | 325 } } // namespace v8::internal |
| 310 | 326 |
| 311 #endif // V8_CFG_H_ | 327 #endif // V8_CFG_H_ |
| OLD | NEW |