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_BACKEND_X64_UNWINDING_INFO_WRITER_X64_H_ 6 #define V8_COMPILER_BACKEND_X64_UNWINDING_INFO_WRITER_X64_H_ 7 8 #include "src/diagnostics/eh-frame.h" 9 #include "src/flags/flags.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace compiler { 14 15 class InstructionBlock; 16 17 class UnwindingInfoWriter { 18 public: UnwindingInfoWriter(Zone * zone)19 explicit UnwindingInfoWriter(Zone* zone) 20 : zone_(zone), 21 eh_frame_writer_(zone), 22 tracking_fp_(false), 23 block_will_exit_(false), 24 block_initial_states_(zone) { 25 if (enabled()) eh_frame_writer_.Initialize(); 26 } 27 MaybeIncreaseBaseOffsetAt(int pc_offset,int base_delta)28 void MaybeIncreaseBaseOffsetAt(int pc_offset, int base_delta) { 29 if (enabled() && !tracking_fp_) { 30 eh_frame_writer_.AdvanceLocation(pc_offset); 31 eh_frame_writer_.IncreaseBaseAddressOffset(base_delta); 32 } 33 } 34 SetNumberOfInstructionBlocks(int number)35 void SetNumberOfInstructionBlocks(int number) { 36 if (enabled()) block_initial_states_.resize(number); 37 } 38 39 void BeginInstructionBlock(int pc_offset, const InstructionBlock* block); 40 void EndInstructionBlock(const InstructionBlock* block); 41 42 void MarkFrameConstructed(int pc_base); 43 void MarkFrameDeconstructed(int pc_base); 44 MarkBlockWillExit()45 void MarkBlockWillExit() { block_will_exit_ = true; } 46 Finish(int code_size)47 void Finish(int code_size) { 48 if (enabled()) eh_frame_writer_.Finish(code_size); 49 } 50 eh_frame_writer()51 EhFrameWriter* eh_frame_writer() { 52 return enabled() ? &eh_frame_writer_ : nullptr; 53 } 54 55 private: enabled()56 bool enabled() const { return FLAG_perf_prof_unwinding_info; } 57 58 class BlockInitialState : public ZoneObject { 59 public: BlockInitialState(Register reg,int offset,bool tracking_fp)60 BlockInitialState(Register reg, int offset, bool tracking_fp) 61 : register_(reg), offset_(offset), tracking_fp_(tracking_fp) {} 62 63 Register register_; 64 int offset_; 65 bool tracking_fp_; 66 }; 67 68 Zone* zone_; 69 EhFrameWriter eh_frame_writer_; 70 bool tracking_fp_; 71 bool block_will_exit_; 72 73 ZoneVector<const BlockInitialState*> block_initial_states_; 74 }; 75 76 } // namespace compiler 77 } // namespace internal 78 } // namespace v8 79 80 #endif // V8_COMPILER_BACKEND_X64_UNWINDING_INFO_WRITER_X64_H_ 81