Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 // M is a two argument macro. It is applied to each concrete value's | 52 // M is a two argument macro. It is applied to each concrete value's |
| 53 // typename and classname. | 53 // typename and classname. |
| 54 #define FOR_EACH_VALUE(M) \ | 54 #define FOR_EACH_VALUE(M) \ |
| 55 M(Use, UseVal) \ | 55 M(Use, UseVal) \ |
| 56 M(Constant, ConstantVal) \ | 56 M(Constant, ConstantVal) \ |
| 57 | 57 |
| 58 | 58 |
| 59 // M is a two argument macro. It is applied to each concrete instruction's | 59 // M is a two argument macro. It is applied to each concrete instruction's |
| 60 // (including the values) typename and classname. | 60 // (including the values) typename and classname. |
| 61 #define FOR_EACH_COMPUTATION(M) \ | 61 #define FOR_EACH_COMPUTATION(M) \ |
| 62 FOR_EACH_VALUE(M) \ | |
| 63 M(AssertAssignable, AssertAssignableComp) \ | 62 M(AssertAssignable, AssertAssignableComp) \ |
| 64 M(AssertBoolean, AssertBooleanComp) \ | 63 M(AssertBoolean, AssertBooleanComp) \ |
| 65 M(CurrentContext, CurrentContextComp) \ | 64 M(CurrentContext, CurrentContextComp) \ |
| 66 M(StoreContext, StoreContextComp) \ | 65 M(StoreContext, StoreContextComp) \ |
| 67 M(ClosureCall, ClosureCallComp) \ | 66 M(ClosureCall, ClosureCallComp) \ |
| 68 M(InstanceCall, InstanceCallComp) \ | 67 M(InstanceCall, InstanceCallComp) \ |
| 69 M(PolymorphicInstanceCall, PolymorphicInstanceCallComp) \ | 68 M(PolymorphicInstanceCall, PolymorphicInstanceCallComp) \ |
| 70 M(StaticCall, StaticCallComp) \ | 69 M(StaticCall, StaticCallComp) \ |
| 71 M(LoadLocal, LoadLocalComp) \ | 70 M(LoadLocal, LoadLocalComp) \ |
| 72 M(StoreLocal, StoreLocalComp) \ | 71 M(StoreLocal, StoreLocalComp) \ |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 95 M(ChainContext, ChainContextComp) \ | 94 M(ChainContext, ChainContextComp) \ |
| 96 M(CloneContext, CloneContextComp) \ | 95 M(CloneContext, CloneContextComp) \ |
| 97 M(CatchEntry, CatchEntryComp) \ | 96 M(CatchEntry, CatchEntryComp) \ |
| 98 M(BinaryOp, BinaryOpComp) \ | 97 M(BinaryOp, BinaryOpComp) \ |
| 99 M(DoubleBinaryOp, DoubleBinaryOpComp) \ | 98 M(DoubleBinaryOp, DoubleBinaryOpComp) \ |
| 100 M(UnarySmiOp, UnarySmiOpComp) \ | 99 M(UnarySmiOp, UnarySmiOpComp) \ |
| 101 M(NumberNegate, NumberNegateComp) \ | 100 M(NumberNegate, NumberNegateComp) \ |
| 102 M(CheckStackOverflow, CheckStackOverflowComp) \ | 101 M(CheckStackOverflow, CheckStackOverflowComp) \ |
| 103 M(DoubleToDouble, DoubleToDoubleComp) \ | 102 M(DoubleToDouble, DoubleToDoubleComp) \ |
| 104 M(SmiToDouble, SmiToDoubleComp) \ | 103 M(SmiToDouble, SmiToDoubleComp) \ |
| 105 M(CheckClass, CheckClassComp) | 104 M(CheckClass, CheckClassComp) \ |
| 105 M(Materialize, MaterializeComp) | |
| 106 | 106 |
| 107 | 107 |
| 108 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; | 108 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; |
| 109 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) | 109 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) |
| 110 FOR_EACH_VALUE(FORWARD_DECLARATION) | |
| 110 #undef FORWARD_DECLARATION | 111 #undef FORWARD_DECLARATION |
| 111 | 112 |
| 112 // Forward declarations. | 113 // Forward declarations. |
| 113 class BindInstr; | 114 class BindInstr; |
| 114 class BranchInstr; | 115 class BranchInstr; |
| 115 class BufferFormatter; | 116 class BufferFormatter; |
| 116 class ComparisonComp; | 117 class ComparisonComp; |
| 117 class Definition; | 118 class Definition; |
| 118 class Instruction; | 119 class Instruction; |
| 119 class PushArgumentInstr; | 120 class PushArgumentInstr; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 ASSERT(inputs_[i] != NULL); | 306 ASSERT(inputs_[i] != NULL); |
| 306 inputs_[i]->RemoveFromUseList(); | 307 inputs_[i]->RemoveFromUseList(); |
| 307 } | 308 } |
| 308 } | 309 } |
| 309 | 310 |
| 310 protected: | 311 protected: |
| 311 EmbeddedArray<Value*, N> inputs_; | 312 EmbeddedArray<Value*, N> inputs_; |
| 312 }; | 313 }; |
| 313 | 314 |
| 314 | 315 |
| 315 class Value : public TemplateComputation<0> { | 316 class Value : public ZoneAllocated { |
| 316 public: | 317 public: |
| 317 Value() { } | 318 Value() { } |
| 318 | 319 |
| 320 // Declare an enum value used to define kind-test predicates. | |
| 321 enum ValueKind { | |
| 322 #define DECLARE_VALUE_KIND(ShortName, ClassName) k##ShortName, | |
| 323 FOR_EACH_VALUE(DECLARE_VALUE_KIND) | |
| 324 #undef DECLARE_VALUE_KIND | |
| 325 }; | |
| 326 | |
| 327 // Declare predicate for each value. | |
| 328 #define DECLARE_PREDICATE(ShortName, ClassName) \ | |
| 329 inline bool Is##ShortName() const; \ | |
| 330 inline const ClassName* As##ShortName() const; \ | |
| 331 inline ClassName* As##ShortName(); | |
| 332 FOR_EACH_VALUE(DECLARE_PREDICATE) | |
|
srdjan
2012/08/21 22:14:53
Is it worth going through all this for just two su
Florian Schneider
2012/08/22 10:59:00
Yes, maybe we can get rid of ConstantVal completel
| |
| 333 #undef DECLARE_PREDICATE | |
| 334 | |
| 335 virtual ValueKind value_kind() const = 0; | |
| 336 | |
| 337 virtual RawAbstractType* CompileType() const = 0; | |
| 338 virtual intptr_t ResultCid() const = 0; | |
| 339 | |
| 340 virtual void PrintTo(BufferFormatter* f) const = 0; | |
| 341 | |
| 319 // Returns true if the value represents a constant. | 342 // Returns true if the value represents a constant. |
| 320 virtual bool BindsToConstant() const = 0; | 343 virtual bool BindsToConstant() const = 0; |
| 321 | 344 |
| 322 // Returns true if the value represents constant null. | 345 // Returns true if the value represents constant null. |
| 323 virtual bool BindsToConstantNull() const = 0; | 346 virtual bool BindsToConstantNull() const = 0; |
| 324 | 347 |
| 325 // Assert if BindsToConstant() is false, otherwise returns constant. | 348 // Assert if BindsToConstant() is false, otherwise returns constant. |
| 326 virtual const Object& BoundConstant() const = 0; | 349 virtual const Object& BoundConstant() const = 0; |
| 327 | 350 |
| 328 // Reminder: The type of the constant null is the bottom type, which is more | 351 // Reminder: The type of the constant null is the bottom type, which is more |
| 329 // specific than any type. | 352 // specific than any type. |
| 330 bool CompileTypeIsMoreSpecificThan(const AbstractType& dst_type) const; | 353 bool CompileTypeIsMoreSpecificThan(const AbstractType& dst_type) const; |
| 331 | 354 |
| 332 virtual void RemoveFromUseList() = 0; | 355 virtual void RemoveFromUseList() = 0; |
| 333 | 356 |
| 357 virtual bool Equals(Value* other) const = 0; | |
| 358 | |
| 334 private: | 359 private: |
| 335 DISALLOW_COPY_AND_ASSIGN(Value); | 360 DISALLOW_COPY_AND_ASSIGN(Value); |
| 336 }; | 361 }; |
| 337 | 362 |
| 338 | 363 |
| 339 // Functions defined in all concrete computation classes. | 364 // Functions defined in all concrete computation classes. |
| 340 #define DECLARE_COMPUTATION(ShortName) \ | 365 #define DECLARE_COMPUTATION(ShortName) \ |
| 341 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr); \ | 366 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr); \ |
| 342 virtual ComputationKind computation_kind() const { \ | 367 virtual ComputationKind computation_kind() const { \ |
| 343 return Computation::k##ShortName; \ | 368 return Computation::k##ShortName; \ |
| 344 } \ | 369 } \ |
| 345 virtual intptr_t ArgumentCount() const { return 0; } \ | 370 virtual intptr_t ArgumentCount() const { return 0; } \ |
| 346 virtual const char* DebugName() const { return #ShortName; } \ | 371 virtual const char* DebugName() const { return #ShortName; } \ |
| 347 virtual RawAbstractType* CompileType() const; \ | 372 virtual RawAbstractType* CompileType() const; \ |
| 348 virtual LocationSummary* MakeLocationSummary() const; \ | 373 virtual LocationSummary* MakeLocationSummary() const; \ |
| 349 virtual void EmitNativeCode(FlowGraphCompiler* compiler); | 374 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 350 | 375 |
| 351 // Functions defined in all concrete value classes. | 376 // Functions defined in all concrete value classes. |
| 352 #define DECLARE_VALUE(ShortName) \ | 377 #define DECLARE_VALUE(ShortName) \ |
| 353 DECLARE_COMPUTATION(ShortName) \ | 378 virtual ValueKind value_kind() const { \ |
| 379 return Value::k##ShortName; \ | |
| 380 } \ | |
| 381 virtual const char* DebugName() const { return #ShortName; } \ | |
| 382 virtual RawAbstractType* CompileType() const; \ | |
| 383 virtual bool Equals(Value* other) const; \ | |
| 354 virtual void PrintTo(BufferFormatter* f) const; | 384 virtual void PrintTo(BufferFormatter* f) const; |
| 355 | 385 |
| 356 | 386 |
| 357 // Function defined in all call computation classes. | 387 // Function defined in all call computation classes. |
| 358 #define DECLARE_CALL_COMPUTATION(ShortName) \ | 388 #define DECLARE_CALL_COMPUTATION(ShortName) \ |
| 359 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr); \ | 389 virtual void Accept(FlowGraphVisitor* visitor, BindInstr* instr); \ |
| 360 virtual ComputationKind computation_kind() const { \ | 390 virtual ComputationKind computation_kind() const { \ |
| 361 return Computation::k##ShortName; \ | 391 return Computation::k##ShortName; \ |
| 362 } \ | 392 } \ |
| 363 virtual const char* DebugName() const { return #ShortName; } \ | 393 virtual const char* DebugName() const { return #ShortName; } \ |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 387 | 417 |
| 388 virtual bool CanDeoptimize() const { return false; } | 418 virtual bool CanDeoptimize() const { return false; } |
| 389 | 419 |
| 390 UseVal* next_use() const { return next_use_; } | 420 UseVal* next_use() const { return next_use_; } |
| 391 UseVal* previous_use() const { return previous_use_; } | 421 UseVal* previous_use() const { return previous_use_; } |
| 392 virtual void RemoveFromUseList(); | 422 virtual void RemoveFromUseList(); |
| 393 virtual void RemoveInputUses() { RemoveFromUseList(); } | 423 virtual void RemoveInputUses() { RemoveFromUseList(); } |
| 394 | 424 |
| 395 virtual intptr_t ResultCid() const; | 425 virtual intptr_t ResultCid() const; |
| 396 | 426 |
| 397 virtual bool AttributesEqual(Computation* other) const; | |
| 398 | |
| 399 private: | 427 private: |
| 400 void AddToUseList(); | 428 void AddToUseList(); |
| 401 Definition* definition_; | 429 Definition* definition_; |
| 402 UseVal* next_use_; | 430 UseVal* next_use_; |
| 403 UseVal* previous_use_; | 431 UseVal* previous_use_; |
| 404 | 432 |
| 405 friend class Definition; | 433 friend class Definition; |
| 406 | 434 |
| 407 DISALLOW_COPY_AND_ASSIGN(UseVal); | 435 DISALLOW_COPY_AND_ASSIGN(UseVal); |
| 408 }; | 436 }; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 426 | 454 |
| 427 // Returns true if the value represents constant null. | 455 // Returns true if the value represents constant null. |
| 428 virtual bool BindsToConstantNull() const { return value().IsNull(); } | 456 virtual bool BindsToConstantNull() const { return value().IsNull(); } |
| 429 | 457 |
| 430 virtual bool CanDeoptimize() const { return false; } | 458 virtual bool CanDeoptimize() const { return false; } |
| 431 | 459 |
| 432 virtual void RemoveFromUseList() { } | 460 virtual void RemoveFromUseList() { } |
| 433 | 461 |
| 434 virtual intptr_t ResultCid() const; | 462 virtual intptr_t ResultCid() const; |
| 435 | 463 |
| 436 virtual bool AttributesEqual(Computation* other) const; | |
| 437 | |
| 438 private: | 464 private: |
| 439 const Object& value_; | 465 const Object& value_; |
| 440 | 466 |
| 441 DISALLOW_COPY_AND_ASSIGN(ConstantVal); | 467 DISALLOW_COPY_AND_ASSIGN(ConstantVal); |
| 442 }; | 468 }; |
| 443 | 469 |
| 444 #undef DECLARE_VALUE | 470 #undef DECLARE_VALUE |
| 445 | 471 |
| 446 | 472 |
| 473 class MaterializeComp : public TemplateComputation<0> { | |
| 474 public: | |
| 475 explicit MaterializeComp(ConstantVal* constant_val) | |
| 476 : constant_val_(constant_val) { } | |
| 477 | |
| 478 DECLARE_COMPUTATION(Materialize) | |
| 479 | |
| 480 virtual void PrintOperandsTo(BufferFormatter* f) const; | |
| 481 | |
| 482 virtual bool CanDeoptimize() const { return false; } | |
| 483 | |
| 484 ConstantVal* constant_val() const { return constant_val_; } | |
| 485 | |
| 486 virtual intptr_t ResultCid() const; | |
| 487 | |
| 488 private: | |
| 489 ConstantVal* constant_val_; | |
| 490 }; | |
| 491 | |
| 492 | |
| 447 class AssertAssignableComp : public TemplateComputation<3> { | 493 class AssertAssignableComp : public TemplateComputation<3> { |
| 448 public: | 494 public: |
| 449 AssertAssignableComp(intptr_t token_pos, | 495 AssertAssignableComp(intptr_t token_pos, |
| 450 intptr_t try_index, | 496 intptr_t try_index, |
| 451 Value* value, | 497 Value* value, |
| 452 Value* instantiator, | 498 Value* instantiator, |
| 453 Value* instantiator_type_arguments, | 499 Value* instantiator_type_arguments, |
| 454 const AbstractType& dst_type, | 500 const AbstractType& dst_type, |
| 455 const String& dst_name) | 501 const String& dst_name) |
| 456 : token_pos_(token_pos), | 502 : token_pos_(token_pos), |
| (...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1823 InstanceCallComp* original_; | 1869 InstanceCallComp* original_; |
| 1824 | 1870 |
| 1825 DISALLOW_COPY_AND_ASSIGN(CheckClassComp); | 1871 DISALLOW_COPY_AND_ASSIGN(CheckClassComp); |
| 1826 }; | 1872 }; |
| 1827 | 1873 |
| 1828 | 1874 |
| 1829 #undef DECLARE_COMPUTATION | 1875 #undef DECLARE_COMPUTATION |
| 1830 | 1876 |
| 1831 | 1877 |
| 1832 // Implementation of type testers and cast functins. | 1878 // Implementation of type testers and cast functins. |
| 1833 #define DEFINE_PREDICATE(ShortName, ClassName) \ | 1879 #define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \ |
| 1834 bool Computation::Is##ShortName() const { \ | 1880 bool Computation::Is##ShortName() const { \ |
| 1835 return computation_kind() == k##ShortName; \ | 1881 return computation_kind() == k##ShortName; \ |
| 1836 } \ | 1882 } \ |
| 1837 const ClassName* Computation::As##ShortName() const { \ | 1883 const ClassName* Computation::As##ShortName() const { \ |
| 1838 if (!Is##ShortName()) return NULL; \ | 1884 if (!Is##ShortName()) return NULL; \ |
| 1839 return static_cast<const ClassName*>(this); \ | 1885 return static_cast<const ClassName*>(this); \ |
| 1840 } \ | 1886 } \ |
| 1841 ClassName* Computation::As##ShortName() { \ | 1887 ClassName* Computation::As##ShortName() { \ |
| 1842 if (!Is##ShortName()) return NULL; \ | 1888 if (!Is##ShortName()) return NULL; \ |
| 1843 return static_cast<ClassName*>(this); \ | 1889 return static_cast<ClassName*>(this); \ |
| 1844 } | 1890 } |
| 1845 FOR_EACH_COMPUTATION(DEFINE_PREDICATE) | 1891 FOR_EACH_COMPUTATION(DEFINE_COMPUTATION_PREDICATE) |
| 1846 #undef DEFINE_PREDICATE | 1892 #undef DEFINE_COMPUTATION_PREDICATE |
| 1847 | 1893 |
| 1894 #define DEFINE_VALUE_PREDICATE(ShortName, ClassName) \ | |
| 1895 bool Value::Is##ShortName() const { \ | |
| 1896 return value_kind() == k##ShortName; \ | |
| 1897 } \ | |
| 1898 const ClassName* Value::As##ShortName() const { \ | |
| 1899 if (!Is##ShortName()) return NULL; \ | |
| 1900 return static_cast<const ClassName*>(this); \ | |
| 1901 } \ | |
| 1902 ClassName* Value::As##ShortName() { \ | |
| 1903 if (!Is##ShortName()) return NULL; \ | |
| 1904 return static_cast<ClassName*>(this); \ | |
| 1905 } | |
| 1906 FOR_EACH_VALUE(DEFINE_VALUE_PREDICATE) | |
| 1907 #undef DEFINE_VALUE_PREDICATE | |
| 1848 | 1908 |
| 1849 // Instructions. | 1909 // Instructions. |
| 1850 | 1910 |
| 1851 // M is a single argument macro. It is applied to each concrete instruction | 1911 // M is a single argument macro. It is applied to each concrete instruction |
| 1852 // type name. The concrete instruction classes are the name with Instr | 1912 // type name. The concrete instruction classes are the name with Instr |
| 1853 // concatenated. | 1913 // concatenated. |
| 1854 #define FOR_EACH_INSTRUCTION(M) \ | 1914 #define FOR_EACH_INSTRUCTION(M) \ |
| 1855 M(GraphEntry) \ | 1915 M(GraphEntry) \ |
| 1856 M(JoinEntry) \ | 1916 M(JoinEntry) \ |
| 1857 M(TargetEntry) \ | 1917 M(TargetEntry) \ |
| (...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3024 ForwardInstructionIterator* current_iterator_; | 3084 ForwardInstructionIterator* current_iterator_; |
| 3025 | 3085 |
| 3026 private: | 3086 private: |
| 3027 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 3087 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 3028 }; | 3088 }; |
| 3029 | 3089 |
| 3030 | 3090 |
| 3031 } // namespace dart | 3091 } // namespace dart |
| 3032 | 3092 |
| 3033 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 3093 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |