LLVM  5.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/MCAssembler.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCSymbolELF.h"
18 #include "llvm/Support/Casting.h"
19 
20 using namespace llvm;
21 
23  const MCSubtargetInfo &STI, bool) {
25 
27  const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
28 
29  for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
30  const MCOperand &Op = Inst.getOperand(OpIndex);
31 
32  if (!Op.isReg())
33  continue;
34 
35  unsigned Reg = Op.getReg();
36  RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
37  }
38 
40 }
41 
43  MipsTargetELFStreamer *ELFTargetStreamer =
44  static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
45 
46  // FIXME: Also mark labels when in MIPS16 mode.
47  if (ELFTargetStreamer->isMicroMipsEnabled()) {
48  for (auto *L : Labels) {
49  auto *Label = cast<MCSymbolELF>(L);
50  getAssembler().registerSymbol(*Label);
51  Label->setOther(ELF::STO_MIPS_MICROMIPS);
52  }
53  }
54 
55  Labels.clear();
56 }
57 
60  Labels.push_back(Symbol);
61 }
62 
64  const MCExpr *Subsection) {
65  MCELFStreamer::SwitchSection(Section, Subsection);
66  Labels.clear();
67 }
68 
70  SMLoc Loc) {
71  MCELFStreamer::EmitValueImpl(Value, Size, Loc);
72  Labels.clear();
73 }
74 
76  for (const auto &I : MipsOptionRecords)
77  I->EmitMipsOptionRecord();
78 }
79 
81  MCAsmBackend &MAB,
83  MCCodeEmitter *Emitter,
84  bool RelaxAll) {
85  return new MipsELFStreamer(Context, MAB, OS, Emitter);
86 }
MachineLoop * L
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
LLVMContext & Context
bool isReg() const
Definition: MCInst.h:58
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
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:36
Reg
All possible values of the reg field in the ModR/M byte.
MCContext & getContext() const
Definition: MCStreamer.h:226
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
Context object for machine code objects.
Definition: MCContext.h:59
unsigned getReg() const
Returns the register number.
Definition: MCInst.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.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:228
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:854
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
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 EmitMipsOptionRecords()
Emits all the option records stored up until the point it's called.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:285
unsigned getNumOperands() const
Definition: MCInst.h:175
#define I(x, y, z)
Definition: MD5.cpp:58
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Overriding this function allows us to dismiss all labels that are candidates for marking as microMIPS...
MCSubtargetInfo - 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.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
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:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:173
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...