LLVM  3.7.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 "MipsTargetStreamer.h"
12 #include "llvm/MC/MCInst.h"
13 #include "llvm/MC/MCSymbolELF.h"
14 #include "llvm/Support/ELF.h"
15 
16 using namespace llvm;
17 
19  const MCSubtargetInfo &STI) {
21 
22  MCContext &Context = getContext();
23  const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
24 
25  for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
26  const MCOperand &Op = Inst.getOperand(OpIndex);
27 
28  if (!Op.isReg())
29  continue;
30 
31  unsigned Reg = Op.getReg();
32  RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
33  }
34 
36 }
37 
39  MipsTargetELFStreamer *ELFTargetStreamer =
40  static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
41 
42  // FIXME: Also mark labels when in MIPS16 mode.
43  if (ELFTargetStreamer->isMicroMipsEnabled()) {
44  for (auto *L : Labels) {
45  auto *Label = cast<MCSymbolELF>(L);
47  Label->setOther(ELF::STO_MIPS_MICROMIPS);
48  }
49  }
50 
51  Labels.clear();
52 }
53 
56  Labels.push_back(Symbol);
57 }
58 
60  const MCExpr *Subsection) {
61  MCELFStreamer::SwitchSection(Section, Subsection);
62  Labels.clear();
63 }
64 
65 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
66  const SMLoc &Loc) {
67  MCELFStreamer::EmitValueImpl(Value, Size, Loc);
68  Labels.clear();
69 }
70 
72  for (const auto &I : MipsOptionRecords)
73  I->EmitMipsOptionRecord();
74 }
75 
77  MCAsmBackend &MAB,
79  MCCodeEmitter *Emitter,
80  bool RelaxAll) {
81  return new MipsELFStreamer(Context, MAB, OS, Emitter);
82 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
bool isReg() const
Definition: MCInst.h:56
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Reg
All possible values of the reg field in the ModR/M byte.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
MCContext & getContext() const
Definition: MCStreamer.h:210
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
Context object for machine code objects.
Definition: MCContext.h:48
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:63
void SetPhysRegUsed(unsigned Reg, const MCRegisterInfo *MCRegInfo)
void EmitLabel(MCSymbol *Symbol) override
Overriding this function allows us to record all labels that should be marked as microMIPS.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:212
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:701
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
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...
MCELFStreamer * createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll)
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void EmitMipsOptionRecords()
Emits all the option records stored up until the point it's called.
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:227
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc) override
Overriding this function allows us to dismiss all labels that are candidates for marking as microMIPS...
unsigned getNumOperands() const
Definition: MCInst.h:166
#define I(x, y, z)
Definition: MD5.cpp:54
MCSubtargetInfo - Generic base class for all target subtargets.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
LLVM Value Representation.
Definition: Value.h:69
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
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:33
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:164