LLVM  8.0.1
MipsELFStreamer.cpp
Go to the documentation of this file.
1 //===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "MipsELFStreamer.h"
11 #include "MipsOptionRecord.h"
12 #include "MipsTargetStreamer.h"
13 #include "llvm/BinaryFormat/ELF.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCAssembler.h"
16 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCDwarf.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCObjectWriter.h"
21 #include "llvm/MC/MCSymbolELF.h"
22 #include "llvm/Support/Casting.h"
23 
24 using namespace llvm;
25 
27  std::unique_ptr<MCAsmBackend> MAB,
28  std::unique_ptr<MCObjectWriter> OW,
29  std::unique_ptr<MCCodeEmitter> Emitter)
30  : MCELFStreamer(Context, std::move(MAB), std::move(OW),
31  std::move(Emitter)) {
32  RegInfoRecord = new MipsRegInfoRecord(this, Context);
33  MipsOptionRecords.push_back(
34  std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
35 }
36 
38  const MCSubtargetInfo &STI, bool) {
40 
42  const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
43 
44  for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
45  const MCOperand &Op = Inst.getOperand(OpIndex);
46 
47  if (!Op.isReg())
48  continue;
49 
50  unsigned Reg = Op.getReg();
51  RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
52  }
53 
55 }
56 
58  Frame.Begin = getContext().createTempSymbol();
60 }
61 
63  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
65  return Label;
66 }
67 
69  Frame.End = getContext().createTempSymbol();
71 }
72 
74  MipsTargetELFStreamer *ELFTargetStreamer =
75  static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
76 
77  // FIXME: Also mark labels when in MIPS16 mode.
78  if (ELFTargetStreamer->isMicroMipsEnabled()) {
79  for (auto *L : Labels) {
80  auto *Label = cast<MCSymbolELF>(L);
81  getAssembler().registerSymbol(*Label);
82  Label->setOther(ELF::STO_MIPS_MICROMIPS);
83  }
84  }
85 
86  Labels.clear();
87 }
88 
91  Labels.push_back(Symbol);
92 }
93 
95  const MCExpr *Subsection) {
96  MCELFStreamer::SwitchSection(Section, Subsection);
97  Labels.clear();
98 }
99 
101  SMLoc Loc) {
102  MCELFStreamer::EmitValueImpl(Value, Size, Loc);
103  Labels.clear();
104 }
105 
106 void MipsELFStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
107  MCELFStreamer::EmitIntValue(Value, Size);
108  Labels.clear();
109 }
110 
112  for (const auto &I : MipsOptionRecords)
113  I->EmitMipsOptionRecord();
114 }
115 
117  MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
118  std::unique_ptr<MCObjectWriter> OW, std::unique_ptr<MCCodeEmitter> Emitter,
119  bool RelaxAll) {
120  return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
121  std::move(Emitter));
122 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
unsigned Reg
bool isReg() const
Definition: MCInst.h:58
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
MCContext & getContext() const
Definition: MCStreamer.h:251
Definition: BitVector.h:938
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:36
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override
MCSymbol * Begin
Definition: MCDwarf.h:590
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
Context object for machine code objects.
Definition: MCContext.h:63
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:124
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
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:217
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:184
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 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:182
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:47
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:295
LLVM Value Representation.
Definition: Value.h:73
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Emit the given Instruction into the current section.
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Overriding this function allows us to add arbitrary behaviour before the Inst is actually emitted...