LLVM 24.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"
21
22using namespace llvm;
23
25 std::unique_ptr<MCAsmBackend> MAB,
26 std::unique_ptr<MCObjectWriter> OW,
27 std::unique_ptr<MCCodeEmitter> Emitter)
28 : MCELFStreamer(Context, std::move(MAB), std::move(OW),
29 std::move(Emitter)) {
30 RegInfoRecord = new MipsRegInfoRecord(this, Context);
31 MipsOptionRecords.push_back(
32 std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
33}
34
36 const MCSubtargetInfo &STI) {
38
39 MCContext &Context = getContext();
40 const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
41
42 for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
43 const MCOperand &Op = Inst.getOperand(OpIndex);
44
45 if (!Op.isReg())
46 continue;
47
48 MCRegister Reg = Op.getReg();
49 RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
50 }
51
53}
54
59
61 MCSymbol *Label = getContext().createTempSymbol("cfi", true);
63 return Label;
64}
65
70
72 MipsTargetELFStreamer *ELFTargetStreamer =
74
75 if (ELFTargetStreamer->isMicroMipsEnabled() ||
76 ELFTargetStreamer->isMips16Enabled()) {
77 for (auto *L : Labels) {
78 auto *Label = static_cast<MCSymbolELF *>(L);
80 Label->setOther(ELFTargetStreamer->isMips16Enabled()
83 }
84 }
85
86 Labels.clear();
87}
88
91 Labels.push_back(Symbol);
92}
93
95 MCELFStreamer::switchSection(Section, Subsection);
96 Labels.clear();
97}
98
100 SMLoc Loc) {
102 Labels.clear();
103}
104
105void MipsELFStreamer::emitIntValue(uint64_t Value, unsigned Size) {
107 Labels.clear();
108}
109
114
115void MipsELFStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
116 SMLoc Loc) {
117 MCELFStreamer::emitFill(NumBytes, FillValue, Loc);
118 Labels.clear();
119}
120
121void MipsELFStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
122 int64_t Expr, SMLoc Loc) {
123 MCELFStreamer::emitFill(NumValues, Size, Expr, Loc);
124 Labels.clear();
125}
126
128 for (const auto &I : MipsOptionRecords)
129 I->EmitMipsOptionRecord();
130}
131
134 std::unique_ptr<MCAsmBackend> MAB,
135 std::unique_ptr<MCObjectWriter> OW,
136 std::unique_ptr<MCCodeEmitter> Emitter) {
137 return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
138 std::move(Emitter));
139}
dxil DXContainer Global Emitter
#define I(x, y, z)
Definition MD5.cpp:57
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getNumOperands() const
Definition MCInst.h:212
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
MCAssembler & getAssembler()
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
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.
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:40
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
MCContext & getContext() const
Definition MCStreamer.h:326
MCTargetStreamer * getTargetStreamer()
Definition MCStreamer.h:336
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.
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
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:42
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
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
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 switchSection(MCSection *Section, uint32_t Subsection=0) override
Overriding this function allows us to dismiss all labels that are candidates for marking as microMIPS...
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
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...
Represents a location in source code.
Definition SMLoc.h:22
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
@ STO_MIPS_MICROMIPS
Definition ELF.h:602
@ STO_MIPS_MIPS16
Definition ELF.h:603
This is an optimization pass for GlobalISel generic memory operations.
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
DWARFExpression::Operation Op
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:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878