LLVM  14.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"
12 #include "llvm/BinaryFormat/ELF.h"
13 #include "llvm/MC/MCAsmBackend.h"
14 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCCodeEmitter.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCDwarf.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCObjectWriter.h"
20 #include "llvm/MC/MCSymbolELF.h"
21 #include "llvm/Support/Casting.h"
22 
23 using 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 
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 
57  Frame.Begin = getContext().createTempSymbol();
59 }
60 
62  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
64  return Label;
65 }
66 
68  Frame.End = getContext().createTempSymbol();
70 }
71 
73  MipsTargetELFStreamer *ELFTargetStreamer =
74  static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
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);
80  getAssembler().registerSymbol(*Label);
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) {
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 
116  MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
117  std::unique_ptr<MCObjectWriter> OW, std::unique_ptr<MCCodeEmitter> Emitter,
118  bool RelaxAll) {
119  return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
120  std::move(Emitter));
121 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCDwarfFrameInfo::End
MCSymbol * End
Definition: MCDwarf.h:641
MCDwarf.h
llvm::MipsELFStreamer::emitCFIEndProcImpl
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override
Definition: MipsELFStreamer.cpp:67
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCELFStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: MCELFStreamer.cpp:100
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:463
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCDwarfFrameInfo::Begin
MCSymbol * Begin
Definition: MCDwarf.h:640
MipsELFStreamer.h
MCCodeEmitter.h
llvm::MipsELFStreamer::emitIntValue
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.
Definition: MipsELFStreamer.cpp:105
llvm::MipsELFStreamer::SwitchSection
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...
Definition: MipsELFStreamer.cpp:93
MCAssembler.h
llvm::createMipsELFStreamer
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll)
Definition: MipsELFStreamer.cpp:115
llvm::ELF::STO_MIPS_MICROMIPS
@ STO_MIPS_MICROMIPS
Definition: ELF.h:576
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MipsRegInfoRecord
Definition: MipsOptionRecord.h:38
llvm::MipsTargetELFStreamer::isMicroMipsEnabled
bool isMicroMipsEnabled() const
Definition: MipsTargetStreamer.h:319
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::MipsELFStreamer::MipsELFStreamer
MipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition: MipsELFStreamer.cpp:25
llvm::MipsRegInfoRecord::SetPhysRegUsed
void SetPhysRegUsed(unsigned Reg, const MCRegisterInfo *MCRegInfo)
Definition: MipsOptionRecord.cpp:73
ELF.h
llvm::MCELFStreamer
Definition: MCELFStreamer.h:24
MCAsmBackend.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
MipsTargetStreamer.h
MCSymbolELF.h
MCContext.h
llvm::MCObjectStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: MCObjectStreamer.cpp:362
llvm::MipsELFStreamer::emitCFILabel
MCSymbol * emitCFILabel() override
When emitting an object file, create and emit a real label.
Definition: MipsELFStreamer.cpp:61
MCInst.h
MipsOptionRecord.h
llvm::MipsTargetELFStreamer
Definition: MipsTargetStreamer.h:313
llvm::MipsELFStreamer::emitCFIStartProcImpl
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override
Definition: MipsELFStreamer.cpp:56
uint64_t
llvm::MipsELFStreamer::createPendingLabelRelocs
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
Definition: MipsELFStreamer.cpp:72
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::move
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:1609
llvm::MCStreamer::emitIntValue
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:133
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:112
llvm::MCELFStreamer::emitValueImpl
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.
Definition: MCELFStreamer.cpp:357
llvm::MipsELFStreamer::emitValueImpl
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...
Definition: MipsELFStreamer.cpp:99
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:303
llvm::MipsELFStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Overriding this function allows us to add arbitrary behaviour before the Inst is actually emitted.
Definition: MipsELFStreamer.cpp:36
MCObjectWriter.h
std
Definition: BitVector.h:838
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
llvm::MipsELFStreamer
Definition: MipsELFStreamer.h:30
Casting.h
llvm::MipsELFStreamer::EmitMipsOptionRecords
void EmitMipsOptionRecords()
Emits all the option records stored up until the point it's called.
Definition: MipsELFStreamer.cpp:110
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
llvm::MCStreamer::getTargetStreamer
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:287
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::MipsELFStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Overriding this function allows us to record all labels that should be marked as microMIPS.
Definition: MipsELFStreamer.cpp:88
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1212
llvm::MCDwarfFrameInfo
Definition: MCDwarf.h:637
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35