LLVM  7.0.0
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/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, bool) {
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  MipsTargetELFStreamer *ELFTargetStreamer =
58  static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
59 
60  // FIXME: Also mark labels when in MIPS16 mode.
61  if (ELFTargetStreamer->isMicroMipsEnabled()) {
62  for (auto *L : Labels) {
63  auto *Label = cast<MCSymbolELF>(L);
64  getAssembler().registerSymbol(*Label);
65  Label->setOther(ELF::STO_MIPS_MICROMIPS);
66  }
67  }
68 
69  Labels.clear();
70 }
71 
74  Labels.push_back(Symbol);
75 }
76 
78  const MCExpr *Subsection) {
79  MCELFStreamer::SwitchSection(Section, Subsection);
80  Labels.clear();
81 }
82 
84  SMLoc Loc) {
85  MCELFStreamer::EmitValueImpl(Value, Size, Loc);
86  Labels.clear();
87 }
88 
89 void MipsELFStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
90  MCELFStreamer::EmitIntValue(Value, Size);
91  Labels.clear();
92 }
93 
95  for (const auto &I : MipsOptionRecords)
96  I->EmitMipsOptionRecord();
97 }
98 
100  MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
101  std::unique_ptr<MCObjectWriter> OW, std::unique_ptr<MCCodeEmitter> Emitter,
102  bool RelaxAll) {
103  return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),
104  std::move(Emitter));
105 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
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:250
Definition: BitVector.h:921
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 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:112
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...
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:257
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:993
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.
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.
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:295
LLVM Value Representation.
Definition: Value.h:73
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...