| 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/growable_array.h" | 9 #include "vm/growable_array.h" |
| 10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // <Instruction> ::= Do <Computation> <Instruction> | 153 // <Instruction> ::= Do <Computation> <Instruction> |
| 154 // | Bind <int> <Computation> <Instruction> | 154 // | Bind <int> <Computation> <Instruction> |
| 155 // | Return <Value> | 155 // | Return <Value> |
| 156 // | Branch <Value> <Instruction> <Instruction> | 156 // | Branch <Value> <Instruction> <Instruction> |
| 157 // | Empty <Instruction> | 157 // | Empty <Instruction> |
| 158 | 158 |
| 159 class Instruction : public ZoneAllocated { | 159 class Instruction : public ZoneAllocated { |
| 160 public: | 160 public: |
| 161 Instruction() : mark_(false) { } | 161 Instruction() : mark_(false) { } |
| 162 | 162 |
| 163 virtual void set_successor(Instruction* instr) = 0; | 163 virtual void SetSuccessor(Instruction* instr) = 0; |
| 164 virtual bool IsBlockEntry() const { return false; } |
| 165 virtual void SetBlockNumber(intptr_t number) { UNREACHABLE(); } |
| 166 virtual intptr_t GetBlockNumber() const { |
| 167 UNREACHABLE(); |
| 168 return -1; |
| 169 } |
| 164 | 170 |
| 165 // Perform a postorder traversal of the instruction graph reachable from | 171 // Perform a postorder traversal of the instruction graph reachable from |
| 166 // this instruction. Append the result to the end of the in/out parameter | 172 // this instruction. Accumulate basic block entries in the order visited |
| 167 // visited. | 173 // in the in/out parameter 'block_entries'. |
| 168 virtual void Postorder(GrowableArray<Instruction*>* visited) = 0; | 174 virtual void Postorder(GrowableArray<Instruction*>* block_entries) = 0; |
| 169 | 175 |
| 170 // Print an instruction without indentation, instruction number, or a | 176 // Print an instruction without a four space indent, and no trailing |
| 171 // trailing newline. | 177 // newline. Basic block entries are labeled with their block number. |
| 172 virtual void Print( | 178 // Return the instruction's successor if there is a single successor |
| 173 intptr_t instruction_index, | 179 // otherwise NULL. |
| 174 const GrowableArray<Instruction*>& instruction_list) const = 0; | 180 virtual Instruction* Print() const = 0; |
| 175 | 181 |
| 176 // Mark bit to support non-reentrant recursive traversal (i.e., | 182 // Mark bit to support non-reentrant recursive traversal (i.e., |
| 177 // identification of cycles). Before and after a traversal, all the nodes | 183 // identification of cycles). Before and after a traversal, all the nodes |
| 178 // must have the same mark. | 184 // must have the same mark. |
| 179 bool mark() const { return mark_; } | 185 bool mark() const { return mark_; } |
| 180 void flip_mark() { mark_ = !mark_; } | 186 void flip_mark() { mark_ = !mark_; } |
| 181 | 187 |
| 182 protected: | |
| 183 // Helper for print handling of successors of nodes with a single successor. | |
| 184 // "goto %d" is printed if the successor is not the next instruction. | |
| 185 void PrintGotoSuccessor( | |
| 186 Instruction* successor, | |
| 187 intptr_t instruction_index, | |
| 188 const GrowableArray<Instruction*>& instruction_list) const; | |
| 189 | |
| 190 private: | 188 private: |
| 191 bool mark_; | 189 bool mark_; |
| 192 }; | 190 }; |
| 193 | 191 |
| 194 | 192 |
| 195 class DoInstr : public Instruction { | 193 class DoInstr : public Instruction { |
| 196 public: | 194 public: |
| 197 explicit DoInstr(Computation* comp) | 195 explicit DoInstr(Computation* comp) |
| 198 : Instruction(), computation_(comp), successor_(NULL) { } | 196 : Instruction(), computation_(comp), successor_(NULL) { } |
| 199 | 197 |
| 200 virtual void set_successor(Instruction* instr) { | 198 virtual void SetSuccessor(Instruction* instr) { |
| 201 ASSERT(successor_ == NULL); | 199 ASSERT(successor_ == NULL); |
| 202 successor_ = instr; | 200 successor_ = instr; |
| 203 } | 201 } |
| 204 | 202 |
| 205 virtual void Postorder(GrowableArray<Instruction*>* visited); | 203 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 206 | 204 |
| 207 virtual void Print( | 205 virtual Instruction* Print() const; |
| 208 intptr_t instruction_index, | |
| 209 const GrowableArray<Instruction*>& instruction_list) const; | |
| 210 | 206 |
| 211 private: | 207 private: |
| 212 Computation* computation_; | 208 Computation* computation_; |
| 213 Instruction* successor_; | 209 Instruction* successor_; |
| 214 }; | 210 }; |
| 215 | 211 |
| 216 | 212 |
| 217 class BindInstr : public Instruction { | 213 class BindInstr : public Instruction { |
| 218 public: | 214 public: |
| 219 BindInstr(intptr_t temp_index, Computation* computation) | 215 BindInstr(intptr_t temp_index, Computation* computation) |
| 220 : Instruction(), | 216 : Instruction(), |
| 221 temp_index_(temp_index), | 217 temp_index_(temp_index), |
| 222 computation_(computation), | 218 computation_(computation), |
| 223 successor_(NULL) { } | 219 successor_(NULL) { } |
| 224 | 220 |
| 225 virtual void set_successor(Instruction* instr) { | 221 virtual void SetSuccessor(Instruction* instr) { |
| 226 ASSERT(successor_ == NULL); | 222 ASSERT(successor_ == NULL); |
| 227 successor_ = instr; | 223 successor_ = instr; |
| 228 } | 224 } |
| 229 | 225 |
| 230 virtual void Postorder(GrowableArray<Instruction*>* visited); | 226 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 231 | 227 |
| 232 virtual void Print( | 228 virtual Instruction* Print() const; |
| 233 intptr_t instruction_index, | |
| 234 const GrowableArray<Instruction*>& instruction_list) const; | |
| 235 | 229 |
| 236 private: | 230 private: |
| 237 const intptr_t temp_index_; | 231 const intptr_t temp_index_; |
| 238 Computation* computation_; | 232 Computation* computation_; |
| 239 Instruction* successor_; | 233 Instruction* successor_; |
| 240 }; | 234 }; |
| 241 | 235 |
| 242 | 236 |
| 243 class JoinEntryInstr : public Instruction { | 237 class JoinEntryInstr : public Instruction { |
| 244 public: | 238 public: |
| 245 JoinEntryInstr() : Instruction(), successor_(NULL) { } | 239 JoinEntryInstr() : Instruction(), block_number_(-1), successor_(NULL) { } |
| 246 | 240 |
| 247 virtual void set_successor(Instruction* instr) { | 241 virtual void SetSuccessor(Instruction* instr) { |
| 248 ASSERT(successor_ == NULL); | 242 ASSERT(successor_ == NULL); |
| 249 successor_ = instr; | 243 successor_ = instr; |
| 250 } | 244 } |
| 251 | 245 |
| 252 virtual void Postorder(GrowableArray<Instruction*>* visited); | 246 virtual bool IsBlockEntry() const { return true; } |
| 247 virtual void SetBlockNumber(intptr_t number) { block_number_ = number; } |
| 248 virtual intptr_t GetBlockNumber() const { return block_number_; } |
| 253 | 249 |
| 254 virtual void Print( | 250 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 255 intptr_t instruction_index, | 251 |
| 256 const GrowableArray<Instruction*>& instruction_list) const; | 252 virtual Instruction* Print() const; |
| 257 | 253 |
| 258 private: | 254 private: |
| 255 intptr_t block_number_; |
| 259 Instruction* successor_; | 256 Instruction* successor_; |
| 260 }; | 257 }; |
| 261 | 258 |
| 262 | 259 |
| 263 class TargetEntryInstr : public Instruction { | 260 class TargetEntryInstr : public Instruction { |
| 264 public: | 261 public: |
| 265 TargetEntryInstr() : Instruction(), successor_(NULL) { } | 262 TargetEntryInstr() : Instruction(), block_number_(-1), successor_(NULL) { } |
| 266 | 263 |
| 267 virtual void set_successor(Instruction* instr) { | 264 virtual void SetSuccessor(Instruction* instr) { |
| 268 ASSERT(successor_ == NULL); | 265 ASSERT(successor_ == NULL); |
| 269 successor_ = instr; | 266 successor_ = instr; |
| 270 } | 267 } |
| 271 | 268 |
| 272 virtual void Postorder(GrowableArray<Instruction*>* visited); | 269 virtual bool IsBlockEntry() const { return true; } |
| 270 virtual void SetBlockNumber(intptr_t number) { block_number_ = number; } |
| 271 virtual intptr_t GetBlockNumber() const { return block_number_; } |
| 273 | 272 |
| 274 virtual void Print( | 273 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 275 intptr_t instruction_index, | 274 |
| 276 const GrowableArray<Instruction*>& instruction_list) const; | 275 virtual Instruction* Print() const; |
| 277 | 276 |
| 278 private: | 277 private: |
| 278 intptr_t block_number_; |
| 279 Instruction* successor_; | 279 Instruction* successor_; |
| 280 }; | 280 }; |
| 281 | 281 |
| 282 | 282 |
| 283 class ReturnInstr : public Instruction { | 283 class ReturnInstr : public Instruction { |
| 284 public: | 284 public: |
| 285 explicit ReturnInstr(Value* value) : Instruction(), value_(value) { } | 285 explicit ReturnInstr(Value* value) : Instruction(), value_(value) { } |
| 286 | 286 |
| 287 virtual void set_successor(Instruction* instr) { UNREACHABLE(); } | 287 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| 288 | 288 |
| 289 virtual void Postorder(GrowableArray<Instruction*>* visited); | 289 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 290 | 290 |
| 291 virtual void Print( | 291 virtual Instruction* Print() const; |
| 292 intptr_t instruction_index, | |
| 293 const GrowableArray<Instruction*>& instruction_list) const; | |
| 294 | 292 |
| 295 private: | 293 private: |
| 296 Value* value_; | 294 Value* value_; |
| 297 }; | 295 }; |
| 298 | 296 |
| 299 | 297 |
| 300 class BranchInstr : public Instruction { | 298 class BranchInstr : public Instruction { |
| 301 public: | 299 public: |
| 302 explicit BranchInstr(Value* value) | 300 explicit BranchInstr(Value* value) |
| 303 : Instruction(), | 301 : Instruction(), |
| 304 value_(value), | 302 value_(value), |
| 305 true_successor_(NULL), | 303 true_successor_(NULL), |
| 306 false_successor_(NULL) { } | 304 false_successor_(NULL) { } |
| 307 | 305 |
| 308 virtual void set_successor(Instruction* instr) { UNREACHABLE(); } | 306 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| 309 | 307 |
| 310 TargetEntryInstr** true_successor_address() { return &true_successor_; } | 308 TargetEntryInstr** true_successor_address() { return &true_successor_; } |
| 311 TargetEntryInstr** false_successor_address() { return &false_successor_; } | 309 TargetEntryInstr** false_successor_address() { return &false_successor_; } |
| 312 | 310 |
| 313 virtual void Postorder(GrowableArray<Instruction*>* visited); | 311 virtual void Postorder(GrowableArray<Instruction*>* block_entries); |
| 314 | 312 |
| 315 virtual void Print( | 313 virtual Instruction* Print() const; |
| 316 intptr_t instruction_index, | |
| 317 const GrowableArray<Instruction*>& instruction_list) const; | |
| 318 | 314 |
| 319 private: | 315 private: |
| 320 Value* value_; | 316 Value* value_; |
| 321 TargetEntryInstr* true_successor_; | 317 TargetEntryInstr* true_successor_; |
| 322 TargetEntryInstr* false_successor_; | 318 TargetEntryInstr* false_successor_; |
| 323 }; | 319 }; |
| 324 | 320 |
| 325 | 321 |
| 326 } // namespace dart | 322 } // namespace dart |
| 327 | 323 |
| 328 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 324 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |