LLVM 22.0.0git
DWARFCFIFunctionFrameStreamer.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file declares CFIFunctionFrameStreamer class.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DWARFCFICHECKER_DWARFCFIFUNCTIONFRAMESTREAMER_H
15#define LLVM_DWARFCFICHECKER_DWARFCFIFUNCTIONFRAMESTREAMER_H
16
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCDwarf.h"
21#include "llvm/MC/MCInstrInfo.h"
22#include "llvm/MC/MCStreamer.h"
24#include <memory>
25#include <optional>
26
27namespace llvm {
28
29/// This class is an `MCStreamer` implementation that watches for machine
30/// instructions and CFI directives. It cuts the stream into function frames and
31/// channels them to `CFIFunctionFrameReceiver`. A function frame is the machine
32/// instructions and CFI directives that are between `.cfi_startproc` and
33/// `.cfi_endproc` directives.
35public:
37 std::unique_ptr<CFIFunctionFrameReceiver> Receiver)
38 : MCStreamer(Context), Receiver(std::move(Receiver)) {
39 assert(this->Receiver && "Receiver should not be null");
40 }
41
42 bool hasRawTextSupport() const override { return true; }
44
46 return true;
47 }
48
50 Align ByteAlignment) override {}
51 void emitSubsectionsViaSymbols() override {};
52 void beginCOFFSymbolDef(const MCSymbol *Symbol) override {}
54 void emitCOFFSymbolType(int Type) override {}
55 void endCOFFSymbolDef() override {}
59
60 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
61 void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
62 void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame) override;
63
64private:
65 /// This method sends the last instruction, along with its associated
66 /// directives, to the receiver and then updates the internal state of the
67 /// class. It moves the directive index to after the last directive and sets
68 /// the last instruction to \p NewInst . This method assumes it is called in
69 /// the middle of an unfinished DWARF debug frame; if not, an assertion will
70 /// fail.
71 void updateReceiver(const std::optional<MCInst> &NewInst);
72
73private:
74 /// The following fields are stacks that store the state of the stream sent to
75 /// the receiver in each frame. This class, like `MCStreamer`, assumes that
76 /// the debug frames are intertwined with each other only in stack form.
77
78 /// The last instruction that is not sent to the receiver for each frame.
79 SmallVector<std::optional<MCInst>> LastInstructions;
80 /// The index of the last directive that is not sent to the receiver for each
81 /// frame.
82 SmallVector<unsigned> LastDirectiveIndices;
83 /// The index of each frame in `DwarfFrameInfos` field in `MCStreamer`.
84 SmallVector<unsigned> FrameIndices;
85
86 std::unique_ptr<CFIFunctionFrameReceiver> Receiver;
87};
88
89} // namespace llvm
90
91#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file declares CFIFunctionFrameReceiver class.
DXIL Finalize Linkage
This file defines the SmallVector class.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
void emitRawTextImpl(StringRef String) override
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
void emitSubsectionsViaSymbols() override
Emit a .subsection_via_symbols directive.
void emitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void emitCOFFSymbolType(int Type) override
Emit the type of the symbol.
CFIFunctionFrameStreamer(MCContext &Context, std::unique_ptr< CFIFunctionFrameReceiver > Receiver)
bool hasRawTextSupport() const override
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText.
void beginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
void endCOFFSymbolDef() override
Marks the end of the symbol definition.
void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol, MCSymbolAttr Linkage, MCSymbolAttr Visibility) override
Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
Context object for machine code objects.
Definition MCContext.h:83
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
MCStreamer(MCContext &Ctx)
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39