LLVM  10.0.0svn
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) {
95  MCELFStreamer::SwitchSection(Section, Subsection);
96  Labels.clear();
97 }
98 
100  SMLoc Loc) {
101  MCELFStreamer::EmitValueImpl(Value, Size, Loc);
102  Labels.clear();
103 }
104 
105 void MipsELFStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
106  MCELFStreamer::EmitIntValue(Value, Size);
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 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
unsigned Reg
bool isReg() const
Definition: MCInst.h:57
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
MCContext & getContext() const
Definition: MCStreamer.h:251
Definition: BitVector.h:937
MipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, 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:35
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override
MCSymbol * Begin
Definition: MCDwarf.h:609
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:64
Context object for machine code objects.
Definition: MCContext.h:65
void SetPhysRegUsed(unsigned Reg, const MCRegisterInfo *MCRegInfo)
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.
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:128
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:225
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:258
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override
MCAssembler & getAssembler()
unsigned getNumOperands() const
Definition: MCInst.h:181
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 EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
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...
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:179
void EmitMipsOptionRecords()
Emits all the option records stored up until the point it&#39;s called.
#define I(x, y, z)
Definition: MD5.cpp:58
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...
Generic base class for all target subtargets.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Overriding this function allows us to record all labels that should be marked as microMIPS.
uint32_t Size
Definition: Profile.cpp:46
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll)
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCSymbol * EmitCFILabel() override
When emitting an object file, create and emit a real label.
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:320
LLVM Value Representation.
Definition: Value.h:73
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Overriding this function allows us to add arbitrary behaviour before the Inst is actually emitted...
Represents a location in source code.
Definition: SMLoc.h:23
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34