1 //===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This is a custom MCELFStreamer which allows us to insert some hooks before
10 // emitting data into an actual object file.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
15 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
17 #include "MipsOptionRecord.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/MC/MCELFStreamer.h"
27 class MCSubtargetInfo
;
28 struct MCDwarfFrameInfo
;
30 class MipsELFStreamer
: public MCELFStreamer
{
31 SmallVector
<std::unique_ptr
<MipsOptionRecord
>, 8> MipsOptionRecords
;
32 MipsRegInfoRecord
*RegInfoRecord
;
33 SmallVector
<MCSymbol
*, 4> Labels
;
36 MipsELFStreamer(MCContext
&Context
, std::unique_ptr
<MCAsmBackend
> MAB
,
37 std::unique_ptr
<MCObjectWriter
> OW
,
38 std::unique_ptr
<MCCodeEmitter
> Emitter
);
40 /// Overriding this function allows us to add arbitrary behaviour before the
41 /// \p Inst is actually emitted. For example, we can inspect the operands and
42 /// gather sufficient information that allows us to reason about the register
43 /// usage for the translation unit.
44 void EmitInstruction(const MCInst
&Inst
, const MCSubtargetInfo
&STI
) override
;
46 /// Overriding this function allows us to record all labels that should be
47 /// marked as microMIPS. Based on this data marking is done in
49 void EmitLabel(MCSymbol
*Symbol
, SMLoc Loc
= SMLoc()) override
;
51 /// Overriding this function allows us to dismiss all labels that are
52 /// candidates for marking as microMIPS when .section directive is processed.
53 void SwitchSection(MCSection
*Section
,
54 const MCExpr
*Subsection
= nullptr) override
;
56 /// Overriding these functions allows us to dismiss all labels that are
57 /// candidates for marking as microMIPS when .word/.long/.4byte etc
58 /// directives are emitted.
59 void EmitValueImpl(const MCExpr
*Value
, unsigned Size
, SMLoc Loc
) override
;
60 void EmitIntValue(uint64_t Value
, unsigned Size
) override
;
62 // Overriding these functions allows us to avoid recording of these labels
63 // in EmitLabel and later marking them as microMIPS.
64 void EmitCFIStartProcImpl(MCDwarfFrameInfo
&Frame
) override
;
65 void EmitCFIEndProcImpl(MCDwarfFrameInfo
&Frame
) override
;
66 MCSymbol
*EmitCFILabel() override
;
68 /// Emits all the option records stored up until the point it's called.
69 void EmitMipsOptionRecords();
71 /// Mark labels as microMIPS, if necessary for the subtarget.
72 void createPendingLabelRelocs();
75 MCELFStreamer
*createMipsELFStreamer(MCContext
&Context
,
76 std::unique_ptr
<MCAsmBackend
> MAB
,
77 std::unique_ptr
<MCObjectWriter
> OW
,
78 std::unique_ptr
<MCCodeEmitter
> Emitter
,
80 } // end namespace llvm
82 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H