LLVM 19.0.0git
MipsELFStreamer.cpp
Go to the documentation of this file.
1//===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//
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#include "MipsELFStreamer.h"
10#include "MipsOptionRecord.h"
11#include "MipsTargetStreamer.h"
14#include "llvm/MC/MCAssembler.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCDwarf.h"
18#include "llvm/MC/MCInst.h"
20#include "llvm/MC/MCSymbolELF.h"
22
23using namespace llvm;
24
26 std::unique_ptr<MCAsmBackend> MAB,
27 std::unique_ptr<MCObjectWriter> OW,
28 std::unique_ptr<MCCodeEmitter> Emitter)
29 : MCELFStreamer(Context, std::move(MAB), std::move(OW),
30 std::move(Emitter)) {
31 RegInfoRecord = new MipsRegInfoRecord(this, Context);
32 MipsOptionRecords.push_back(
33 std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
34}
35
37 const MCSubtargetInfo &STI) {
39
40 MCContext &Context = getContext();
41 const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
42
43 for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
44 const MCOperand &Op = Inst.getOperand(OpIndex);
45
46 if (!Op.isReg())
47 continue;
48
49 unsigned Reg = Op.getReg();
50 RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
51 }
52
54}
55
59}
60
62 MCSymbol *Label = getContext().createTempSymbol("cfi", true);
64 return Label;
65}
66
70}
71
73 MipsTargetELFStreamer *ELFTargetStreamer =
75
76 // FIXME: Also mark labels when in MIPS16 mode.
77 if (ELFTargetStreamer->isMicroMipsEnabled()) {
78 for (auto *L : Labels) {
79 auto *Label = cast<MCSymbolELF>(L);
81 Label->setOther(ELF::STO_MIPS_MICROMIPS);
82 }
83 }
84
85 Labels.clear();
86}
87
90 Labels.push_back(Symbol);
91}
92
94 const MCExpr *Subsection) {
95 MCELFStreamer::switchSection(Section, Subsection);
96 Labels.clear();
97}
98
100 SMLoc Loc) {
102 Labels.clear();
103}
104
107 Labels.clear();
108}
109
111 for (const auto &I : MipsOptionRecords)
112 I->EmitMipsOptionRecord();
113}
114
117 std::unique_ptr<MCAsmBackend> MAB,
118 std::unique_ptr<MCObjectWriter> OW,
119 std::unique_ptr<MCCodeEmitter> Emitter) {
120 return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
121 std::move(Emitter));
122}
dxil DXContainer Global Emitter
uint64_t Size
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned OpIndex
This class represents an Operation in the Expression.
bool registerSymbol(const MCSymbol &Symbol)
Context object for machine code objects.
Definition: MCContext.h:82
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:331
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:417
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
unsigned getNumOperands() const
Definition: MCInst.h:208
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
MCAssembler & getAssembler()
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:35
MCContext & getContext() const
Definition: MCStreamer.h:297
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:306
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:134
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
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:40
void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr) override
Overriding this function allows us to dismiss all labels that are candidates for marking as microMIPS...
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override
void EmitMipsOptionRecords()
Emits all the option records stored up until the point it's called.
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Overriding this function allows us to add arbitrary behaviour before the Inst is actually emitted.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Overriding this function allows us to record all labels that should be marked as microMIPS.
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override
MipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
MCSymbol * emitCFILabel() override
When emitting an object file, create and emit a real label.
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
void emitIntValue(uint64_t Value, unsigned Size) override
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Overriding these functions allows us to dismiss all labels that are candidates for marking as microMI...
void SetPhysRegUsed(unsigned Reg, const MCRegisterInfo *MCRegInfo)
Represents a location in source code.
Definition: SMLoc.h:23
LLVM Value Representation.
Definition: Value.h:74
@ STO_MIPS_MICROMIPS
Definition: ELF.h:590
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
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:858
MCSymbol * Begin
Definition: MCDwarf.h:700