LLVM 22.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 // FIXME: Also mark labels when in MIPS16 mode.
76 if (ELFTargetStreamer->isMicroMipsEnabled()) {
77 for (auto *L : Labels) {
78 auto *Label = static_cast<MCSymbolELF *>(L);
80 Label->setOther(ELF::STO_MIPS_MICROMIPS);
81 }
82 }
83
84 Labels.clear();
85}
86
89 Labels.push_back(Symbol);
90}
91
93 MCELFStreamer::switchSection(Section, Subsection);
94 Labels.clear();
95}
96
98 SMLoc Loc) {
100 Labels.clear();
101}
102
107
109 for (const auto &I : MipsOptionRecords)
110 I->EmitMipsOptionRecord();
111}
112
115 std::unique_ptr<MCAsmBackend> MAB,
116 std::unique_ptr<MCObjectWriter> OW,
117 std::unique_ptr<MCCodeEmitter> Emitter) {
118 return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
119 std::move(Emitter));
120}
dxil DXContainer Global Emitter
#define I(x, y, z)
Definition MD5.cpp:58
unsigned OpIndex
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
MCAssembler & getAssembler()
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:33
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
MCContext & getContext() const
Definition MCStreamer.h:314
MCTargetStreamer * getTargetStreamer()
Definition MCStreamer.h:324
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
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 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:23
LLVM Value Representation.
Definition Value.h:75
@ STO_MIPS_MICROMIPS
Definition ELF.h:602
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:1847
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851