@@ -19,15 +19,16 @@ using namespace llvm;
1919
2020void CFIFunctionFrameStreamer::updateReceiver (
2121 const std::optional<MCInst> &NewInst) {
22- assert (!FrameIndices.empty () && hasUnfinishedDwarfFrameInfo () &&
23- " FunctionUnitStreamer frame indices should be synced with "
24- " MCStreamer's" ); // ! FIXME split this assertions and also check another
25- // ! vectors
26- // ! Add tests for nested frames
22+ assert (hasUnfinishedDwarfFrameInfo () &&
23+ " should have an unfinished DWARF frame here" );
24+ assert (!FrameIndices.empty () &&
25+ " there should be an index available for the current frame" );
26+ assert (FrameIndices.size () == LastInstructions.size ());
27+ assert (LastInstructions.size () == LastDirectiveIndices.size ());
2728
2829 auto Frames = getDwarfFrameInfos ();
2930 assert (FrameIndices.back () < Frames.size ());
30- unsigned LastDirectiveIndex = FrameLastDirectiveIndices .back ();
31+ unsigned LastDirectiveIndex = LastDirectiveIndices .back ();
3132 unsigned CurrentDirectiveIndex =
3233 Frames[FrameIndices.back ()].Instructions .size ();
3334 assert (CurrentDirectiveIndex >= LastDirectiveIndex);
@@ -41,41 +42,46 @@ void CFIFunctionFrameStreamer::updateReceiver(
4142 .drop_back (LastFrame->Instructions .size () - CurrentDirectiveIndex);
4243 }
4344
44- auto MaybeLastInstruction = FrameLastInstructions .back ();
45+ auto MaybeLastInstruction = LastInstructions .back ();
4546 if (MaybeLastInstruction)
47+ // The directives are associated with an instruction.
4648 Receiver->emitInstructionAndDirectives (*MaybeLastInstruction, Directives);
4749 else
50+ // The directives are the prologue directives.
4851 Receiver->startFunctionFrame (false /* TODO: should put isEH here */ ,
4952 Directives);
5053
51- FrameLastInstructions.back () = NewInst;
52- FrameLastDirectiveIndices.back () = CurrentDirectiveIndex;
54+ // Update the internal state for the top frame.
55+ LastInstructions.back () = NewInst;
56+ LastDirectiveIndices.back () = CurrentDirectiveIndex;
5357}
5458
5559void CFIFunctionFrameStreamer::emitInstruction (const MCInst &Inst,
5660 const MCSubtargetInfo &STI) {
57- if (hasUnfinishedDwarfFrameInfo ()) {
61+ if (hasUnfinishedDwarfFrameInfo ())
62+ // Send the last instruction with the unsent directives already in the frame
63+ // to the receiver.
5864 updateReceiver (Inst);
59- }
6065}
6166
6267void CFIFunctionFrameStreamer::emitCFIStartProcImpl (MCDwarfFrameInfo &Frame) {
63- FrameLastInstructions .push_back (std::nullopt );
64- FrameLastDirectiveIndices .push_back (0 );
68+ LastInstructions .push_back (std::nullopt );
69+ LastDirectiveIndices .push_back (0 );
6570 FrameIndices.push_back (getNumFrameInfos ());
6671
6772 MCStreamer::emitCFIStartProcImpl (Frame);
6873}
6974
7075void CFIFunctionFrameStreamer::emitCFIEndProcImpl (MCDwarfFrameInfo &CurFrame) {
76+ // Send the last instruction with the final directives of the current frame to
77+ // the receiver.
7178 updateReceiver (std::nullopt );
7279
7380 assert (!FrameIndices.empty () && " There should be at least one frame to pop" );
74- FrameLastDirectiveIndices .pop_back ();
75- FrameLastInstructions .pop_back ();
81+ LastDirectiveIndices .pop_back ();
82+ LastInstructions .pop_back ();
7683 FrameIndices.pop_back ();
7784
78- dbgs () << " finishing frame\n " ;
7985 Receiver->finishFunctionFrame ();
8086
8187 MCStreamer::emitCFIEndProcImpl (CurFrame);
0 commit comments