Home | History | Annotate | Download | only in x64
      1 // Copyright 2016 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_COMPILER_X64_UNWINDING_INFO_WRITER_H_
      6 #define V8_COMPILER_X64_UNWINDING_INFO_WRITER_H_
      7 
      8 #include "src/eh-frame.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 namespace compiler {
     13 
     14 class InstructionBlock;
     15 
     16 class UnwindingInfoWriter {
     17  public:
     18   explicit UnwindingInfoWriter(Zone* zone)
     19       : zone_(zone),
     20         eh_frame_writer_(zone),
     21         tracking_fp_(false),
     22         block_will_exit_(false),
     23         block_initial_states_(zone) {
     24     if (enabled()) eh_frame_writer_.Initialize();
     25   }
     26 
     27   void MaybeIncreaseBaseOffsetAt(int pc_offset, int base_delta) {
     28     if (enabled() && !tracking_fp_) {
     29       eh_frame_writer_.AdvanceLocation(pc_offset);
     30       eh_frame_writer_.IncreaseBaseAddressOffset(base_delta);
     31     }
     32   }
     33 
     34   void SetNumberOfInstructionBlocks(int number) {
     35     if (enabled()) block_initial_states_.resize(number);
     36   }
     37 
     38   void BeginInstructionBlock(int pc_offset, const InstructionBlock* block);
     39   void EndInstructionBlock(const InstructionBlock* block);
     40 
     41   void MarkFrameConstructed(int pc_base);
     42   void MarkFrameDeconstructed(int pc_base);
     43 
     44   void MarkBlockWillExit() { block_will_exit_ = true; }
     45 
     46   void Finish(int code_size) {
     47     if (enabled()) eh_frame_writer_.Finish(code_size);
     48   }
     49 
     50   EhFrameWriter* eh_frame_writer() {
     51     return enabled() ? &eh_frame_writer_ : nullptr;
     52   }
     53 
     54  private:
     55   bool enabled() const { return FLAG_perf_prof_unwinding_info; }
     56 
     57   class BlockInitialState : public ZoneObject {
     58    public:
     59     BlockInitialState(Register reg, int offset, bool tracking_fp)
     60         : register_(reg), offset_(offset), tracking_fp_(tracking_fp) {}
     61 
     62     Register register_;
     63     int offset_;
     64     bool tracking_fp_;
     65   };
     66 
     67   Zone* zone_;
     68   EhFrameWriter eh_frame_writer_;
     69   bool tracking_fp_;
     70   bool block_will_exit_;
     71 
     72   ZoneVector<const BlockInitialState*> block_initial_states_;
     73 };
     74 
     75 }  // namespace compiler
     76 }  // namespace internal
     77 }  // namespace v8
     78 
     79 #endif
     80