Revision: 16114
Author:   [email protected]
Date:     Wed Aug  7 19:16:12 2013
Log:      Patch to enhance the source code line information for profiler.

This patch is to enhance the source code line information for profiler.

For the Hydrogen compilation, most of the source code line information
is not copied from the HInstruction the to corresponding LInstruction.

This patch defines one PositionBits field for LInstruction and copies the
sorce code position value from the HInstruction.

When Generating the native code, we use RecordPosition(..) function to
write LInstruction's position value to position recorder.

For the MIPS platform, I did not touch because I have no devices
to verify the modification on it.

[email protected]

Review URL: https://codereview.chromium.org/21042003

Patch from Chunyang Dai <[email protected]>.
http://code.google.com/p/v8/source/detail?r=16114

Modified:
 /branches/bleeding_edge/src/arm/lithium-arm.cc
 /branches/bleeding_edge/src/arm/lithium-arm.h
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.h
 /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
 /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h
 /branches/bleeding_edge/src/ia32/lithium-ia32.cc
 /branches/bleeding_edge/src/ia32/lithium-ia32.h
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.h
 /branches/bleeding_edge/src/x64/lithium-x64.cc
 /branches/bleeding_edge/src/x64/lithium-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc      Wed Aug  7 04:24:14 2013
+++ /branches/bleeding_edge/src/arm/lithium-arm.cc      Wed Aug  7 19:16:12 2013
@@ -885,6 +885,7 @@
     }
 #endif

+    instr->set_position(position_);
     if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
       instr = AssignPointerMap(instr);
     }
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h       Wed Aug  7 04:24:14 2013
+++ /branches/bleeding_edge/src/arm/lithium-arm.h       Wed Aug  7 19:16:12 2013
@@ -208,9 +208,12 @@
 class LInstruction: public ZoneObject {
  public:
   LInstruction()
-      :  environment_(NULL),
-         hydrogen_value_(NULL),
-         is_call_(false) { }
+      : environment_(NULL),
+        hydrogen_value_(NULL),
+        bit_field_(IsCallBits::encode(false)) {
+    set_position(RelocInfo::kNoPosition);
+  }
+
   virtual ~LInstruction() { }

   virtual void CompileToNative(LCodeGen* generator) = 0;
@@ -248,21 +251,31 @@
   void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
   LPointerMap* pointer_map() const { return pointer_map_.get(); }
   bool HasPointerMap() const { return pointer_map_.is_set(); }
+
+ // The 31 bits PositionBits is used to store the int position value. And the
+  // position value may be RelocInfo::kNoPosition (-1). The accessor always
+ // +1/-1 so that the encoded value of position in bit_field_ is always
= 0
+  // and can fit into the 31 bits PositionBits.
+  void set_position(int pos) {
+    bit_field_ = PositionBits::update(bit_field_, pos + 1);
+  }
+  int position() { return PositionBits::decode(bit_field_) - 1; }

   void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
   HValue* hydrogen_value() const { return hydrogen_value_; }

virtual void SetDeferredLazyDeoptimizationEnvironment(LEnvironment* env) { }

-  void MarkAsCall() { is_call_ = true; }
+  void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
+  bool IsCall() const { return IsCallBits::decode(bit_field_); }

   // Interface to the register allocator and iterators.
-  bool ClobbersTemps() const { return is_call_; }
-  bool ClobbersRegisters() const { return is_call_; }
-  bool ClobbersDoubleRegisters() const { return is_call_; }
+  bool ClobbersTemps() const { return IsCall(); }
+  bool ClobbersRegisters() const { return IsCall(); }
+  bool ClobbersDoubleRegisters() const { return IsCall(); }

   // Interface to the register allocator and iterators.
-  bool IsMarkedAsCall() const { return is_call_; }
+  bool IsMarkedAsCall() const { return IsCall(); }

   virtual bool HasResult() const = 0;
   virtual LOperand* result() const = 0;
@@ -286,10 +299,13 @@
   virtual int TempCount() = 0;
   virtual LOperand* TempAt(int i) = 0;

+  class IsCallBits: public BitField<bool, 0, 1> {};
+  class PositionBits: public BitField<int, 1, 31> {};
+
   LEnvironment* environment_;
   SetOncePointer<LPointerMap> pointer_map_;
   HValue* hydrogen_value_;
-  bool is_call_;
+  int bit_field_;
 };


=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Aug 7 04:24:14 2013 +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Aug 7 19:16:12 2013
@@ -273,6 +273,8 @@
               instr->hydrogen_value()->id(),
               instr->Mnemonic());
     }
+
+    RecordAndUpdatePosition(instr->position());

     instr->CompileToNative(this);
   }
@@ -287,6 +289,10 @@
   if (deferred_.length() > 0) {
     for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
       LDeferredCode* code = deferred_[i];
+
+      int pos = instructions_->at(code->instruction_index())->position();
+      RecordAndUpdatePosition(pos);
+
       Comment(";;; <@%d,#%d> "
               "-------------------- Deferred %s --------------------",
               code->instruction_index(),
@@ -995,6 +1001,14 @@
   if (position == RelocInfo::kNoPosition) return;
   masm()->positions_recorder()->RecordPosition(position);
 }
+
+
+void LCodeGen::RecordAndUpdatePosition(int position) {
+  if (position >= 0 && position != old_position_) {
+    masm()->positions_recorder()->RecordPosition(position);
+    old_position_ = position;
+  }
+}


 static const char* LabelType(LLabel* label) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Wed Aug 7 04:24:14 2013 +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Wed Aug 7 19:16:12 2013
@@ -66,7 +66,8 @@
         frame_is_built_(false),
         safepoints_(info->zone()),
         resolver_(this),
-        expected_safepoint_kind_(Safepoint::kSimple) {
+        expected_safepoint_kind_(Safepoint::kSimple),
+        old_position_(RelocInfo::kNoPosition) {
     PopulateDeoptimizationLiteralsWithInlinedFunctions();
   }

@@ -318,6 +319,7 @@
                                               int arguments,
                                               Safepoint::DeoptMode mode);
   void RecordPosition(int position);
+  void RecordAndUpdatePosition(int position);

   static Condition TokenToCondition(Token::Value op, bool is_unsigned);
   void EmitGoto(int block);
@@ -420,6 +422,8 @@

   Safepoint::Kind expected_safepoint_kind_;

+  int old_position_;
+
   class PushSafepointRegistersScope BASE_EMBEDDED {
    public:
     PushSafepointRegistersScope(LCodeGen* codegen,
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Aug 7 04:24:14 2013 +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Aug 7 19:16:12 2013
@@ -355,6 +355,8 @@

     if (!CpuFeatures::IsSupported(SSE2)) FlushX87StackIfNecessary(instr);

+    RecordAndUpdatePosition(instr->position());
+
     instr->CompileToNative(this);

     if (!CpuFeatures::IsSupported(SSE2)) {
@@ -422,6 +424,10 @@
   if (deferred_.length() > 0) {
     for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
       LDeferredCode* code = deferred_[i];
+
+      int pos = instructions_->at(code->instruction_index())->position();
+      RecordAndUpdatePosition(pos);
+
       Comment(";;; <@%d,#%d> "
               "-------------------- Deferred %s --------------------",
               code->instruction_index(),
@@ -1186,6 +1192,14 @@
   if (position == RelocInfo::kNoPosition) return;
   masm()->positions_recorder()->RecordPosition(position);
 }
+
+
+void LCodeGen::RecordAndUpdatePosition(int position) {
+  if (position >= 0 && position != old_position_) {
+    masm()->positions_recorder()->RecordPosition(position);
+    old_position_ = position;
+  }
+}


 static const char* LabelType(LLabel* label) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Wed Aug 7 04:24:14 2013 +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Wed Aug 7 19:16:12 2013
@@ -71,7 +71,8 @@
         x87_stack_depth_(0),
         safepoints_(info->zone()),
         resolver_(this),
-        expected_safepoint_kind_(Safepoint::kSimple) {
+        expected_safepoint_kind_(Safepoint::kSimple),
+        old_position_(RelocInfo::kNoPosition) {
     PopulateDeoptimizationLiteralsWithInlinedFunctions();
   }

@@ -322,6 +323,8 @@
                                     Safepoint::DeoptMode mode);
   void RecordPosition(int position);

+  void RecordAndUpdatePosition(int position);
+
   static Condition TokenToCondition(Token::Value op, bool is_unsigned);
   void EmitGoto(int block);
   template<class InstrType>
@@ -451,6 +454,8 @@

   Safepoint::Kind expected_safepoint_kind_;

+  int old_position_;
+
   class PushSafepointRegistersScope BASE_EMBEDDED {
    public:
     explicit PushSafepointRegistersScope(LCodeGen* codegen)
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Wed Aug 7 10:22:17 2013 +++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Wed Aug 7 19:16:12 2013
@@ -940,6 +940,7 @@
     }
 #endif

+    instr->set_position(position_);
     if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
       instr = AssignPointerMap(instr);
     }
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h     Wed Aug  7 04:24:14 2013
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h     Wed Aug  7 19:16:12 2013
@@ -209,7 +209,10 @@
   LInstruction()
       : environment_(NULL),
         hydrogen_value_(NULL),
-        is_call_(false) { }
+        bit_field_(IsCallBits::encode(false)) {
+    set_position(RelocInfo::kNoPosition);
+  }
+
   virtual ~LInstruction() { }

   virtual void CompileToNative(LCodeGen* generator) = 0;
@@ -248,19 +251,28 @@
   LPointerMap* pointer_map() const { return pointer_map_.get(); }
   bool HasPointerMap() const { return pointer_map_.is_set(); }

+ // The 31 bits PositionBits is used to store the int position value. And the
+  // position value may be RelocInfo::kNoPosition (-1). The accessor always
+ // +1/-1 so that the encoded value of position in bit_field_ is always
= 0
+  // and can fit into the 31 bits PositionBits.
+  void set_position(int pos) {
+    bit_field_ = PositionBits::update(bit_field_, pos + 1);
+  }
+  int position() { return PositionBits::decode(bit_field_) - 1; }

   void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
   HValue* hydrogen_value() const { return hydrogen_value_; }

virtual void SetDeferredLazyDeoptimizationEnvironment(LEnvironment* env) { }

-  void MarkAsCall() { is_call_ = true; }
+  void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
+  bool IsCall() const { return IsCallBits::decode(bit_field_); }

   // Interface to the register allocator and iterators.
-  bool ClobbersTemps() const { return is_call_; }
-  bool ClobbersRegisters() const { return is_call_; }
+  bool ClobbersTemps() const { return IsCall(); }
+  bool ClobbersRegisters() const { return IsCall(); }
   virtual bool ClobbersDoubleRegisters() const {
-    return is_call_ ||
+    return IsCall() ||
       (!CpuFeatures::IsSupported(SSE2) &&
        // We only have rudimentary X87Stack tracking, thus in general
        // cannot handle deoptimization nor phi-nodes.
@@ -293,10 +305,13 @@
   virtual int TempCount() = 0;
   virtual LOperand* TempAt(int i) = 0;

+  class IsCallBits: public BitField<bool, 0, 1> {};
+  class PositionBits: public BitField<int, 1, 31> {};
+
   LEnvironment* environment_;
   SetOncePointer<LPointerMap> pointer_map_;
   HValue* hydrogen_value_;
-  bool is_call_;
+  int bit_field_;
 };


=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Aug 7 18:29:33 2013 +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Aug 7 19:16:12 2013
@@ -277,6 +277,8 @@
               instr->hydrogen_value()->id(),
               instr->Mnemonic());
     }
+
+    RecordAndUpdatePosition(instr->position());

     instr->CompileToNative(this);
   }
@@ -331,6 +333,10 @@
   if (deferred_.length() > 0) {
     for (int i = 0; !is_aborted() && i < deferred_.length(); i++) {
       LDeferredCode* code = deferred_[i];
+
+      int pos = instructions_->at(code->instruction_index())->position();
+      RecordAndUpdatePosition(pos);
+
       Comment(";;; <@%d,#%d> "
               "-------------------- Deferred %s --------------------",
               code->instruction_index(),
@@ -877,6 +883,14 @@
   if (position == RelocInfo::kNoPosition) return;
   masm()->positions_recorder()->RecordPosition(position);
 }
+
+
+void LCodeGen::RecordAndUpdatePosition(int position) {
+  if (position >= 0 && position != old_position_) {
+    masm()->positions_recorder()->RecordPosition(position);
+    old_position_ = position;
+  }
+}


 static const char* LabelType(LLabel* label) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Wed Aug 7 18:29:33 2013 +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Wed Aug 7 19:16:12 2013
@@ -67,7 +67,8 @@
         frame_is_built_(false),
         safepoints_(info->zone()),
         resolver_(this),
-        expected_safepoint_kind_(Safepoint::kSimple) {
+        expected_safepoint_kind_(Safepoint::kSimple),
+        old_position_(RelocInfo::kNoPosition) {
     PopulateDeoptimizationLiteralsWithInlinedFunctions();
   }

@@ -282,6 +283,7 @@
                                     int arguments,
                                     Safepoint::DeoptMode mode);
   void RecordPosition(int position);
+  void RecordAndUpdatePosition(int position);

   static Condition TokenToCondition(Token::Value op, bool is_unsigned);
   void EmitGoto(int block);
@@ -384,6 +386,8 @@

   Safepoint::Kind expected_safepoint_kind_;

+  int old_position_;
+
   class PushSafepointRegistersScope BASE_EMBEDDED {
    public:
     explicit PushSafepointRegistersScope(LCodeGen* codegen)
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc      Wed Aug  7 04:24:14 2013
+++ /branches/bleeding_edge/src/x64/lithium-x64.cc      Wed Aug  7 19:16:12 2013
@@ -884,6 +884,7 @@
     }
 #endif

+    instr->set_position(position_);
     if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) {
       instr = AssignPointerMap(instr);
     }
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h       Wed Aug  7 04:24:14 2013
+++ /branches/bleeding_edge/src/x64/lithium-x64.h       Wed Aug  7 19:16:12 2013
@@ -205,9 +205,11 @@
 class LInstruction: public ZoneObject {
  public:
   LInstruction()
-      :  environment_(NULL),
-         hydrogen_value_(NULL),
-         is_call_(false) { }
+      : environment_(NULL),
+        hydrogen_value_(NULL),
+        bit_field_(IsCallBits::encode(false)) {
+    set_position(RelocInfo::kNoPosition);
+  }

   virtual ~LInstruction() { }

@@ -246,21 +248,31 @@
   void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
   LPointerMap* pointer_map() const { return pointer_map_.get(); }
   bool HasPointerMap() const { return pointer_map_.is_set(); }
+
+ // The 31 bits PositionBits is used to store the int position value. And the
+  // position value may be RelocInfo::kNoPosition (-1). The accessor always
+ // +1/-1 so that the encoded value of position in bit_field_ is always
= 0
+  // and can fit into the 31 bits PositionBits.
+  void set_position(int pos) {
+    bit_field_ = PositionBits::update(bit_field_, pos + 1);
+  }
+  int position() { return PositionBits::decode(bit_field_) - 1; }

   void set_hydrogen_value(HValue* value) { hydrogen_value_ = value; }
   HValue* hydrogen_value() const { return hydrogen_value_; }

-  void MarkAsCall() { is_call_ = true; }
+  void MarkAsCall() { bit_field_ = IsCallBits::update(bit_field_, true); }
+  bool IsCall() const { return IsCallBits::decode(bit_field_); }

   // Interface to the register allocator and iterators.
-  bool ClobbersTemps() const { return is_call_; }
-  bool ClobbersRegisters() const { return is_call_; }
-  bool ClobbersDoubleRegisters() const { return is_call_; }
+  bool ClobbersTemps() const { return IsCall(); }
+  bool ClobbersRegisters() const { return IsCall(); }
+  bool ClobbersDoubleRegisters() const { return IsCall(); }

virtual void SetDeferredLazyDeoptimizationEnvironment(LEnvironment* env) { }

   // Interface to the register allocator and iterators.
-  bool IsMarkedAsCall() const { return is_call_; }
+  bool IsMarkedAsCall() const { return IsCall(); }

   virtual bool HasResult() const = 0;
   virtual LOperand* result() const = 0;
@@ -284,10 +296,13 @@
   virtual int TempCount() = 0;
   virtual LOperand* TempAt(int i) = 0;

+  class IsCallBits: public BitField<bool, 0, 1> {};
+  class PositionBits: public BitField<int, 1, 31> {};
+
   LEnvironment* environment_;
   SetOncePointer<LPointerMap> pointer_map_;
   HValue* hydrogen_value_;
-  bool is_call_;
+  int bit_field_;
 };


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to