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

Side by Side Diff: src/full-codegen.h

Issue 6976028: Reduced the code ping-pong between the full code generator and contexts a bit. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // May emit code to traverse the context chain, destroying the scratch 321 // May emit code to traverse the context chain, destroying the scratch
322 // register. 322 // register.
323 MemOperand EmitSlotSearch(Slot* slot, Register scratch); 323 MemOperand EmitSlotSearch(Slot* slot, Register scratch);
324 324
325 // Forward the bailout responsibility for the given expression to 325 // Forward the bailout responsibility for the given expression to
326 // the next child visited (which must be in a test context). 326 // the next child visited (which must be in a test context).
327 void ForwardBailoutToChild(Expression* expr); 327 void ForwardBailoutToChild(Expression* expr);
328 328
329 void VisitForEffect(Expression* expr) { 329 void VisitForEffect(Expression* expr) {
330 EffectContext context(this); 330 EffectContext context(this);
331 HandleInNonTestContext(expr, NO_REGISTERS); 331 VisitInSameContext(expr);
Kevin Millikin (Chromium) 2011/05/31 11:46:28 "SameContext" is not quite right because it raises
Sven Panne 2011/05/31 14:30:33 Done.
332 } 332 }
333 333
334 void VisitForAccumulatorValue(Expression* expr) { 334 void VisitForAccumulatorValue(Expression* expr) {
335 AccumulatorValueContext context(this); 335 AccumulatorValueContext context(this);
336 HandleInNonTestContext(expr, TOS_REG); 336 VisitInSameContext(expr);
337 } 337 }
338 338
339 void VisitForStackValue(Expression* expr) { 339 void VisitForStackValue(Expression* expr) {
340 StackValueContext context(this); 340 StackValueContext context(this);
341 HandleInNonTestContext(expr, NO_REGISTERS); 341 VisitInSameContext(expr);
342 } 342 }
343 343
344 void VisitForControl(Expression* expr, 344 void VisitForControl(Expression* expr,
345 Label* if_true, 345 Label* if_true,
346 Label* if_false, 346 Label* if_false,
347 Label* fall_through) { 347 Label* fall_through) {
348 TestContext context(this, if_true, if_false, fall_through); 348 TestContext context(this, if_true, if_false, fall_through);
349 VisitInTestContext(expr); 349 VisitInSameContext(expr);
350 // Forwarding bailouts to children is a one shot operation. It
351 // should have been processed at this point.
352 ASSERT(forward_bailout_pending_ == NULL);
353 } 350 }
354 351
355 void HandleInNonTestContext(Expression* expr, State state);
356 void VisitInTestContext(Expression* expr);
357
358 void VisitDeclarations(ZoneList<Declaration*>* declarations); 352 void VisitDeclarations(ZoneList<Declaration*>* declarations);
359 void DeclareGlobals(Handle<FixedArray> pairs); 353 void DeclareGlobals(Handle<FixedArray> pairs);
360 354
361 // Try to perform a comparison as a fast inlined literal compare if 355 // Try to perform a comparison as a fast inlined literal compare if
362 // the operands allow it. Returns true if the compare operations 356 // the operands allow it. Returns true if the compare operations
363 // has been matched and all code generated; false otherwise. 357 // has been matched and all code generated; false otherwise.
364 bool TryLiteralCompare(Token::Value op, 358 bool TryLiteralCompare(Token::Value op,
365 Expression* left, 359 Expression* left,
366 Expression* right, 360 Expression* right,
367 Label* if_true, 361 Label* if_true,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // in v8::internal::Context. 536 // in v8::internal::Context.
543 void LoadContextField(Register dst, int context_index); 537 void LoadContextField(Register dst, int context_index);
544 538
545 // AST node visit functions. 539 // AST node visit functions.
546 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); 540 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
547 AST_NODE_LIST(DECLARE_VISIT) 541 AST_NODE_LIST(DECLARE_VISIT)
548 #undef DECLARE_VISIT 542 #undef DECLARE_VISIT
549 543
550 void EmitUnaryOperation(UnaryOperation* expr, const char* comment); 544 void EmitUnaryOperation(UnaryOperation* expr, const char* comment);
551 545
552 // Handles the shortcutted logical binary operations in VisitBinaryOperation. 546 void VisitComma(BinaryOperation* expr);
553 void EmitLogicalOperation(BinaryOperation* expr); 547 void VisitAndOr(BinaryOperation* expr, bool is_logical_and);
Kevin Millikin (Chromium) 2011/05/31 11:46:28 VisitLogicalOperation? We should get Logical in
Sven Panne 2011/05/31 14:30:33 OK, I'm changing HGraphBuilder's corresponding met
548 void VisitCommon(BinaryOperation* expr);
Kevin Millikin (Chromium) 2011/05/31 11:46:28 Common is nondescriptive. How about ArithmeticOpe
Sven Panne 2011/05/31 14:30:33 OK, I'll sync HGraphBuilder, too.
549 void VisitInSameContext(Expression* expr);
554 550
555 void VisitForTypeofValue(Expression* expr); 551 void VisitForTypeofValue(Expression* expr);
556 552
557 struct BailoutEntry { 553 struct BailoutEntry {
558 unsigned id; 554 unsigned id;
559 unsigned pc_and_state; 555 unsigned pc_and_state;
560 }; 556 };
561 557
562 558
563 class ExpressionContext BASE_EMBEDDED { 559 class ExpressionContext BASE_EMBEDDED {
(...skipping 27 matching lines...) Expand all
591 // implementation will bind both labels unless it's a TestContext, which 587 // implementation will bind both labels unless it's a TestContext, which
592 // won't bind them at this point. 588 // won't bind them at this point.
593 virtual void Plug(Label* materialize_true, 589 virtual void Plug(Label* materialize_true,
594 Label* materialize_false) const = 0; 590 Label* materialize_false) const = 0;
595 591
596 // Emit code to discard count elements from the top of stack, then convert 592 // Emit code to discard count elements from the top of stack, then convert
597 // a pure value into the result expected according to this expression 593 // a pure value into the result expected according to this expression
598 // context. 594 // context.
599 virtual void DropAndPlug(int count, Register reg) const = 0; 595 virtual void DropAndPlug(int count, Register reg) const = 0;
600 596
601 // For shortcutting operations || and &&.
602 virtual void EmitLogicalLeft(BinaryOperation* expr,
603 Label* eval_right,
604 Label* done) const = 0;
605
606 // Set up branch labels for a test expression. The three Label** parameters 597 // Set up branch labels for a test expression. The three Label** parameters
607 // are output parameters. 598 // are output parameters.
608 virtual void PrepareTest(Label* materialize_true, 599 virtual void PrepareTest(Label* materialize_true,
609 Label* materialize_false, 600 Label* materialize_false,
610 Label** if_true, 601 Label** if_true,
611 Label** if_false, 602 Label** if_false,
612 Label** fall_through) const = 0; 603 Label** fall_through) const = 0;
613 604
614 virtual void HandleExpression(Expression* expr) const = 0;
615
616 // Returns true if we are evaluating only for side effects (ie if the result 605 // Returns true if we are evaluating only for side effects (ie if the result
617 // will be discarded). 606 // will be discarded).
618 virtual bool IsEffect() const { return false; } 607 virtual bool IsEffect() const { return false; }
619 608
609 // Returns true if we are evaluating for the value (in accu/on stack).
610 virtual bool IsAccumulatorValue() const { return false; }
611 virtual bool IsStackValue() const { return false; }
612
620 // Returns true if we are branching on the value rather than materializing 613 // Returns true if we are branching on the value rather than materializing
621 // it. Only used for asserts. 614 // it. Only used for asserts.
622 virtual bool IsTest() const { return false; } 615 virtual bool IsTest() const { return false; }
623 616
624 protected: 617 protected:
625 FullCodeGenerator* codegen() const { return codegen_; } 618 FullCodeGenerator* codegen() const { return codegen_; }
626 MacroAssembler* masm() const { return masm_; } 619 MacroAssembler* masm() const { return masm_; }
627 MacroAssembler* masm_; 620 MacroAssembler* masm_;
628 621
629 private: 622 private:
630 const ExpressionContext* old_; 623 const ExpressionContext* old_;
631 FullCodeGenerator* codegen_; 624 FullCodeGenerator* codegen_;
632 }; 625 };
633 626
634 class AccumulatorValueContext : public ExpressionContext { 627 class AccumulatorValueContext : public ExpressionContext {
635 public: 628 public:
636 explicit AccumulatorValueContext(FullCodeGenerator* codegen) 629 explicit AccumulatorValueContext(FullCodeGenerator* codegen)
637 : ExpressionContext(codegen) { } 630 : ExpressionContext(codegen) { }
638 631
639 virtual void Plug(bool flag) const; 632 virtual void Plug(bool flag) const;
640 virtual void Plug(Register reg) const; 633 virtual void Plug(Register reg) const;
641 virtual void Plug(Label* materialize_true, Label* materialize_false) const; 634 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
642 virtual void Plug(Slot* slot) const; 635 virtual void Plug(Slot* slot) const;
643 virtual void Plug(Handle<Object> lit) const; 636 virtual void Plug(Handle<Object> lit) const;
644 virtual void Plug(Heap::RootListIndex) const; 637 virtual void Plug(Heap::RootListIndex) const;
645 virtual void PlugTOS() const; 638 virtual void PlugTOS() const;
646 virtual void DropAndPlug(int count, Register reg) const; 639 virtual void DropAndPlug(int count, Register reg) const;
647 virtual void EmitLogicalLeft(BinaryOperation* expr,
648 Label* eval_right,
649 Label* done) const;
650 virtual void PrepareTest(Label* materialize_true, 640 virtual void PrepareTest(Label* materialize_true,
651 Label* materialize_false, 641 Label* materialize_false,
652 Label** if_true, 642 Label** if_true,
653 Label** if_false, 643 Label** if_false,
654 Label** fall_through) const; 644 Label** fall_through) const;
655 virtual void HandleExpression(Expression* expr) const; 645 virtual bool IsAccumulatorValue() const { return true; }
656 }; 646 };
657 647
658 class StackValueContext : public ExpressionContext { 648 class StackValueContext : public ExpressionContext {
659 public: 649 public:
660 explicit StackValueContext(FullCodeGenerator* codegen) 650 explicit StackValueContext(FullCodeGenerator* codegen)
661 : ExpressionContext(codegen) { } 651 : ExpressionContext(codegen) { }
662 652
663 virtual void Plug(bool flag) const; 653 virtual void Plug(bool flag) const;
664 virtual void Plug(Register reg) const; 654 virtual void Plug(Register reg) const;
665 virtual void Plug(Label* materialize_true, Label* materialize_false) const; 655 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
666 virtual void Plug(Slot* slot) const; 656 virtual void Plug(Slot* slot) const;
667 virtual void Plug(Handle<Object> lit) const; 657 virtual void Plug(Handle<Object> lit) const;
668 virtual void Plug(Heap::RootListIndex) const; 658 virtual void Plug(Heap::RootListIndex) const;
669 virtual void PlugTOS() const; 659 virtual void PlugTOS() const;
670 virtual void DropAndPlug(int count, Register reg) const; 660 virtual void DropAndPlug(int count, Register reg) const;
671 virtual void EmitLogicalLeft(BinaryOperation* expr,
672 Label* eval_right,
673 Label* done) const;
674 virtual void PrepareTest(Label* materialize_true, 661 virtual void PrepareTest(Label* materialize_true,
675 Label* materialize_false, 662 Label* materialize_false,
676 Label** if_true, 663 Label** if_true,
677 Label** if_false, 664 Label** if_false,
678 Label** fall_through) const; 665 Label** fall_through) const;
679 virtual void HandleExpression(Expression* expr) const; 666 virtual bool IsStackValue() const { return true; }
680 }; 667 };
681 668
682 class TestContext : public ExpressionContext { 669 class TestContext : public ExpressionContext {
683 public: 670 public:
684 explicit TestContext(FullCodeGenerator* codegen, 671 explicit TestContext(FullCodeGenerator* codegen,
685 Label* true_label, 672 Label* true_label,
686 Label* false_label, 673 Label* false_label,
687 Label* fall_through) 674 Label* fall_through)
688 : ExpressionContext(codegen), 675 : ExpressionContext(codegen),
689 true_label_(true_label), 676 true_label_(true_label),
(...skipping 10 matching lines...) Expand all
700 Label* fall_through() const { return fall_through_; } 687 Label* fall_through() const { return fall_through_; }
701 688
702 virtual void Plug(bool flag) const; 689 virtual void Plug(bool flag) const;
703 virtual void Plug(Register reg) const; 690 virtual void Plug(Register reg) const;
704 virtual void Plug(Label* materialize_true, Label* materialize_false) const; 691 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
705 virtual void Plug(Slot* slot) const; 692 virtual void Plug(Slot* slot) const;
706 virtual void Plug(Handle<Object> lit) const; 693 virtual void Plug(Handle<Object> lit) const;
707 virtual void Plug(Heap::RootListIndex) const; 694 virtual void Plug(Heap::RootListIndex) const;
708 virtual void PlugTOS() const; 695 virtual void PlugTOS() const;
709 virtual void DropAndPlug(int count, Register reg) const; 696 virtual void DropAndPlug(int count, Register reg) const;
710 virtual void EmitLogicalLeft(BinaryOperation* expr,
711 Label* eval_right,
712 Label* done) const;
713 virtual void PrepareTest(Label* materialize_true, 697 virtual void PrepareTest(Label* materialize_true,
714 Label* materialize_false, 698 Label* materialize_false,
715 Label** if_true, 699 Label** if_true,
716 Label** if_false, 700 Label** if_false,
717 Label** fall_through) const; 701 Label** fall_through) const;
718 virtual void HandleExpression(Expression* expr) const;
719 virtual bool IsTest() const { return true; } 702 virtual bool IsTest() const { return true; }
720 703
721 private: 704 private:
722 Label* true_label_; 705 Label* true_label_;
723 Label* false_label_; 706 Label* false_label_;
724 Label* fall_through_; 707 Label* fall_through_;
725 }; 708 };
726 709
727 class EffectContext : public ExpressionContext { 710 class EffectContext : public ExpressionContext {
728 public: 711 public:
729 explicit EffectContext(FullCodeGenerator* codegen) 712 explicit EffectContext(FullCodeGenerator* codegen)
730 : ExpressionContext(codegen) { } 713 : ExpressionContext(codegen) { }
731 714
732 virtual void Plug(bool flag) const; 715 virtual void Plug(bool flag) const;
733 virtual void Plug(Register reg) const; 716 virtual void Plug(Register reg) const;
734 virtual void Plug(Label* materialize_true, Label* materialize_false) const; 717 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
735 virtual void Plug(Slot* slot) const; 718 virtual void Plug(Slot* slot) const;
736 virtual void Plug(Handle<Object> lit) const; 719 virtual void Plug(Handle<Object> lit) const;
737 virtual void Plug(Heap::RootListIndex) const; 720 virtual void Plug(Heap::RootListIndex) const;
738 virtual void PlugTOS() const; 721 virtual void PlugTOS() const;
739 virtual void DropAndPlug(int count, Register reg) const; 722 virtual void DropAndPlug(int count, Register reg) const;
740 virtual void EmitLogicalLeft(BinaryOperation* expr,
741 Label* eval_right,
742 Label* done) const;
743 virtual void PrepareTest(Label* materialize_true, 723 virtual void PrepareTest(Label* materialize_true,
744 Label* materialize_false, 724 Label* materialize_false,
745 Label** if_true, 725 Label** if_true,
746 Label** if_false, 726 Label** if_false,
747 Label** fall_through) const; 727 Label** fall_through) const;
748 virtual void HandleExpression(Expression* expr) const;
749 virtual bool IsEffect() const { return true; } 728 virtual bool IsEffect() const { return true; }
750 }; 729 };
751 730
752 MacroAssembler* masm_; 731 MacroAssembler* masm_;
753 CompilationInfo* info_; 732 CompilationInfo* info_;
754 Label return_label_; 733 Label return_label_;
755 NestedStatement* nesting_stack_; 734 NestedStatement* nesting_stack_;
756 int loop_depth_; 735 int loop_depth_;
757 const ExpressionContext* context_; 736 const ExpressionContext* context_;
758 ZoneList<BailoutEntry> bailout_entries_; 737 ZoneList<BailoutEntry> bailout_entries_;
759 ZoneList<BailoutEntry> stack_checks_; 738 ZoneList<BailoutEntry> stack_checks_;
760 ForwardBailoutStack* forward_bailout_stack_; 739 ForwardBailoutStack* forward_bailout_stack_;
761 ForwardBailoutStack* forward_bailout_pending_; 740 ForwardBailoutStack* forward_bailout_pending_;
762 741
763 friend class NestedStatement; 742 friend class NestedStatement;
764 743
765 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); 744 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator);
766 }; 745 };
767 746
768 747
769 } } // namespace v8::internal 748 } } // namespace v8::internal
770 749
771 #endif // V8_FULL_CODEGEN_H_ 750 #endif // V8_FULL_CODEGEN_H_
OLDNEW
« no previous file with comments | « src/arm/full-codegen-arm.cc ('k') | src/full-codegen.cc » ('j') | src/full-codegen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698