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_ARM_UNWINDING_INFO_WRITER_H_
6 #define V8_COMPILER_ARM_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:
UnwindingInfoWriter(Zone * zone)18   explicit UnwindingInfoWriter(Zone* zone)
19       : zone_(zone),
20         eh_frame_writer_(zone),
21         saved_lr_(false),
22         block_will_exit_(false),
23         block_initial_states_(zone) {
24     if (enabled()) eh_frame_writer_.Initialize();
25   }
26 
SetNumberOfInstructionBlocks(int number)27   void SetNumberOfInstructionBlocks(int number) {
28     if (enabled()) block_initial_states_.resize(number);
29   }
30 
31   void BeginInstructionBlock(int pc_offset, const InstructionBlock* block);
32   void EndInstructionBlock(const InstructionBlock* block);
33 
34   void MarkLinkRegisterOnTopOfStack(int pc_offset);
35   void MarkPopLinkRegisterFromTopOfStack(int pc_offset);
36 
37   void MarkFrameConstructed(int at_pc);
38   void MarkFrameDeconstructed(int at_pc);
39 
MarkBlockWillExit()40   void MarkBlockWillExit() { block_will_exit_ = true; }
41 
Finish(int code_size)42   void Finish(int code_size) {
43     if (enabled()) eh_frame_writer_.Finish(code_size);
44   }
45 
eh_frame_writer()46   EhFrameWriter* eh_frame_writer() {
47     return enabled() ? &eh_frame_writer_ : nullptr;
48   }
49 
50  private:
enabled()51   bool enabled() const { return FLAG_perf_prof_unwinding_info; }
52 
53   class BlockInitialState : public ZoneObject {
54    public:
BlockInitialState(bool saved_lr)55     explicit BlockInitialState(bool saved_lr) : saved_lr_(saved_lr) {}
56 
57     bool saved_lr_;
58   };
59 
60   Zone* zone_;
61   EhFrameWriter eh_frame_writer_;
62   bool saved_lr_;
63   bool block_will_exit_;
64 
65   ZoneVector<const BlockInitialState*> block_initial_states_;
66 };
67 
68 }  // namespace compiler
69 }  // namespace internal
70 }  // namespace v8
71 
72 #endif
73