Author: [email protected]
Date: Thu Jan  8 05:01:12 2009
New Revision: 1048

Modified:
    branches/experimental/toiger/src/codegen-ia32.cc
    branches/experimental/toiger/src/codegen-ia32.h
    branches/experimental/toiger/src/jump-target-ia32.cc
    branches/experimental/toiger/src/register-allocator-ia32.cc
    branches/experimental/toiger/src/register-allocator-ia32.h
    branches/experimental/toiger/src/virtual-frame-ia32.cc

Log:
Experimental: a quick hack to allow different live values to flow down
the two CFG edges at a branch.  The values on the frame flow to the
labeled block, and the values on the frame and all live non-frame
references (results) flow to the fall-through.

The hack is to save and restore non-frame references whenever the code
generator's frame is switched.  Once "MakeMergable" goes away and the
merge code is moved from the source to the destination block, this
will be unnecessary.
Review URL: http://codereview.chromium.org/17412

Modified: branches/experimental/toiger/src/codegen-ia32.cc
==============================================================================
--- branches/experimental/toiger/src/codegen-ia32.cc    (original)
+++ branches/experimental/toiger/src/codegen-ia32.cc    Thu Jan  8 05:01:12  
2009
@@ -90,14 +90,23 @@
  }


-void CodeGenerator::SetFrame(VirtualFrame* new_frame) {
+void CodeGenerator::SetFrame(VirtualFrame* new_frame,
+                             RegisterFile* non_frame_registers) {
+  RegisterFile saved_counts;
    if (has_valid_frame()) {
      frame_->DetachFromCodeGenerator();
+    // The remaining register reference counts are the non-frame ones.
+    allocator_->SaveTo(&saved_counts);
    }
+
    if (new_frame != NULL) {
+    // Restore the non-frame register references that go with the new  
frame.
+    allocator_->RestoreFrom(non_frame_registers);
      new_frame->AttachToCodeGenerator();
    }
+
    frame_ = new_frame;
+  saved_counts.CopyTo(non_frame_registers);
  }


@@ -129,7 +138,7 @@
    RegisterAllocator register_allocator(this);
    allocator_ = &register_allocator;
    ASSERT(frame_ == NULL);
-  SetFrame(new VirtualFrame(this));
+  frame_ = new VirtualFrame(this);
    cc_reg_ = no_condition;
    function_return_.set_code_generator(this);
    function_return_is_shadowed_ = false;

Modified: branches/experimental/toiger/src/codegen-ia32.h
==============================================================================
--- branches/experimental/toiger/src/codegen-ia32.h     (original)
+++ branches/experimental/toiger/src/codegen-ia32.h     Thu Jan  8 05:01:12 2009
@@ -189,7 +189,10 @@

    bool has_valid_frame() const { return frame_ != NULL; }

-  void SetFrame(VirtualFrame* frame);
+  // Set the virtual frame to be new_frame, with non-frame register
+  // reference counts given by non_frame_registers.  The non-frame register
+  // reference counts of the old frame are returned in non_frame_registers.
+  void SetFrame(VirtualFrame* new_frame, RegisterFile*  
non_frame_registers);

    void DeleteFrame();


Modified: branches/experimental/toiger/src/jump-target-ia32.cc
==============================================================================
--- branches/experimental/toiger/src/jump-target-ia32.cc        (original)
+++ branches/experimental/toiger/src/jump-target-ia32.cc        Thu Jan  8  
05:01:12 2009
@@ -72,7 +72,8 @@
      current_frame->MakeMergable();
      expected_frame_ = current_frame;
      ASSERT(cgen_->HasValidEntryRegisters());
-    cgen_->SetFrame(NULL);
+    RegisterFile ignored;
+    cgen_->SetFrame(NULL, &ignored);
    } else {
      current_frame->MergeTo(expected_frame_);
      ASSERT(cgen_->HasValidEntryRegisters());
@@ -102,7 +103,6 @@

    VirtualFrame* current_frame = cgen_->frame();
    ASSERT(current_frame != NULL);
-  ASSERT(cgen_->HasValidEntryRegisters());

    if (expected_frame_ == NULL) {
      expected_frame_ = new VirtualFrame(current_frame);
@@ -132,11 +132,22 @@
      Label original_fall_through;
      __ j(NegateCondition(cc), &original_fall_through, NegateHint(hint));
      VirtualFrame* working_frame = new VirtualFrame(current_frame);
-    cgen_->SetFrame(working_frame);
+
+    // Switch to the working frame for the merge code with only the  
reserved
+    // registers referenced outside the frame.  Explicitly setting
+    // references here is ugly, but temporary.
+    RegisterFile non_frame_registers;
+    non_frame_registers.Use(esi);
+    non_frame_registers.Use(ebp);
+    non_frame_registers.Use(esp);
+    cgen_->SetFrame(working_frame, &non_frame_registers);
+
      working_frame->MergeTo(expected_frame_);
      ASSERT(cgen_->HasValidEntryRegisters());
      __ jmp(&label_);
-    cgen_->SetFrame(current_frame);
+
+    // Restore the current frame and its associated non-frame registers.
+    cgen_->SetFrame(current_frame, &non_frame_registers);
      delete working_frame;
      __ bind(&original_fall_through);
    }
@@ -234,7 +245,14 @@
      ASSERT(cgen_->HasValidEntryRegisters());
      expected_frame_ = new VirtualFrame(current_frame);
    } else if (current_frame == NULL) {
-    cgen_->SetFrame(new VirtualFrame(expected_frame_));
+    // Pick up the frame from the label.  No merge code is necessary.
+    // Manually setting the reserved register reference counts is clumsy  
but
+    // temporary.
+    RegisterFile non_frame_registers;
+    non_frame_registers.Use(esi);
+    non_frame_registers.Use(ebp);
+    non_frame_registers.Use(esp);
+    cgen_->SetFrame(new VirtualFrame(expected_frame_),  
&non_frame_registers);
      ASSERT(cgen_->HasValidEntryRegisters());
    } else {
      ASSERT(cgen_->HasValidEntryRegisters());

Modified: branches/experimental/toiger/src/register-allocator-ia32.cc
==============================================================================
--- branches/experimental/toiger/src/register-allocator-ia32.cc (original)
+++ branches/experimental/toiger/src/register-allocator-ia32.cc Thu Jan  8  
05:01:12 2009
@@ -103,14 +103,30 @@


  //  
-------------------------------------------------------------------------
+// RegisterFile implementation.
+
+
+void RegisterFile::CopyTo(RegisterFile* other) {
+  for (int i = 0; i < kNumRegisters; i++) {
+    other->ref_counts_[i] = ref_counts_[i];
+  }
+}
+
+
+//  
-------------------------------------------------------------------------
  // RegisterAllocator implementation.

  void RegisterAllocator::Initialize() {
+  Reset();
+  Use(edi);
+}
+
+
+void RegisterAllocator::Reset() {
    registers_.Reset();
    Use(esp);
    Use(ebp);
    Use(esi);
-  Use(edi);
  }



Modified: branches/experimental/toiger/src/register-allocator-ia32.h
==============================================================================
--- branches/experimental/toiger/src/register-allocator-ia32.h  (original)
+++ branches/experimental/toiger/src/register-allocator-ia32.h  Thu Jan  8  
05:01:12 2009
@@ -157,6 +157,9 @@
      }
    }

+  // Copy the reference counts from this register file to the other.
+  void CopyTo(RegisterFile* other);
+
    static const int kNumRegisters = 8;

   private:
@@ -191,6 +194,11 @@
    // the virtual frame); and the other registers are free.
    void Initialize();

+  // Reset the register reference counts to free all non-reserved  
registers.
+  // A frame-external reference is kept to each of the reserved registers
+  // (esp, ebp, and esi).
+  void Reset();
+
    // Allocate a free register and return a register result if possible or
    // fail and return an invalid result.
    Result Allocate();
@@ -202,6 +210,16 @@
    // Allocate a free register without spilling any from the current frame  
or
    // fail and return an invalid result.
    Result AllocateWithoutSpilling();
+
+  // Copy the internal state to a register file, to be restored later by
+  // RestoreFrom.
+  void SaveTo(RegisterFile* register_file) {
+    registers_.CopyTo(register_file);
+  }
+
+  void RestoreFrom(RegisterFile* register_file) {
+    register_file->CopyTo(&registers_);
+  }

   private:
    CodeGenerator* cgen_;

Modified: branches/experimental/toiger/src/virtual-frame-ia32.cc
==============================================================================
--- branches/experimental/toiger/src/virtual-frame-ia32.cc      (original)
+++ branches/experimental/toiger/src/virtual-frame-ia32.cc      Thu Jan  8  
05:01:12 2009
@@ -308,8 +308,11 @@
    // with the frame.  We simply save the current frame and restore it at  
the
    // end of this function.  We should find a better way to deal with this.
    VirtualFrame* original_frame = cgen_->frame();
-  ASSERT(cgen_->HasValidEntryRegisters());
-  cgen_->SetFrame(this);
+  RegisterFile non_frame_registers;
+  non_frame_registers.Use(esi);
+  non_frame_registers.Use(ebp);
+  non_frame_registers.Use(esp);
+  cgen_->SetFrame(this, &non_frame_registers);
    ASSERT(cgen_->HasValidEntryRegisters());

    // Remove constants from the frame and ensure that no registers are
@@ -383,8 +386,7 @@

    delete[] new_elements;
    ASSERT(cgen_->HasValidEntryRegisters());
-  cgen_->SetFrame(original_frame);
-  ASSERT(cgen_->HasValidEntryRegisters());
+  cgen_->SetFrame(original_frame, &non_frame_registers);
  }



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to