Path: blob/main/contrib/llvm-project/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
35294 views
//===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "MipsELFStreamer.h"9#include "MipsOptionRecord.h"10#include "MipsTargetStreamer.h"11#include "llvm/BinaryFormat/ELF.h"12#include "llvm/MC/MCAsmBackend.h"13#include "llvm/MC/MCAssembler.h"14#include "llvm/MC/MCCodeEmitter.h"15#include "llvm/MC/MCContext.h"16#include "llvm/MC/MCDwarf.h"17#include "llvm/MC/MCInst.h"18#include "llvm/MC/MCObjectWriter.h"19#include "llvm/MC/MCSymbolELF.h"20#include "llvm/Support/Casting.h"2122using namespace llvm;2324MipsELFStreamer::MipsELFStreamer(MCContext &Context,25std::unique_ptr<MCAsmBackend> MAB,26std::unique_ptr<MCObjectWriter> OW,27std::unique_ptr<MCCodeEmitter> Emitter)28: MCELFStreamer(Context, std::move(MAB), std::move(OW),29std::move(Emitter)) {30RegInfoRecord = new MipsRegInfoRecord(this, Context);31MipsOptionRecords.push_back(32std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));33}3435void MipsELFStreamer::emitInstruction(const MCInst &Inst,36const MCSubtargetInfo &STI) {37MCELFStreamer::emitInstruction(Inst, STI);3839MCContext &Context = getContext();40const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();4142for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {43const MCOperand &Op = Inst.getOperand(OpIndex);4445if (!Op.isReg())46continue;4748unsigned Reg = Op.getReg();49RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);50}5152createPendingLabelRelocs();53}5455void MipsELFStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {56Frame.Begin = getContext().createTempSymbol();57MCELFStreamer::emitLabel(Frame.Begin);58}5960MCSymbol *MipsELFStreamer::emitCFILabel() {61MCSymbol *Label = getContext().createTempSymbol("cfi", true);62MCELFStreamer::emitLabel(Label);63return Label;64}6566void MipsELFStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {67Frame.End = getContext().createTempSymbol();68MCELFStreamer::emitLabel(Frame.End);69}7071void MipsELFStreamer::createPendingLabelRelocs() {72MipsTargetELFStreamer *ELFTargetStreamer =73static_cast<MipsTargetELFStreamer *>(getTargetStreamer());7475// FIXME: Also mark labels when in MIPS16 mode.76if (ELFTargetStreamer->isMicroMipsEnabled()) {77for (auto *L : Labels) {78auto *Label = cast<MCSymbolELF>(L);79getAssembler().registerSymbol(*Label);80Label->setOther(ELF::STO_MIPS_MICROMIPS);81}82}8384Labels.clear();85}8687void MipsELFStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {88MCELFStreamer::emitLabel(Symbol);89Labels.push_back(Symbol);90}9192void MipsELFStreamer::switchSection(MCSection *Section, uint32_t Subsection) {93MCELFStreamer::switchSection(Section, Subsection);94Labels.clear();95}9697void MipsELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,98SMLoc Loc) {99MCELFStreamer::emitValueImpl(Value, Size, Loc);100Labels.clear();101}102103void MipsELFStreamer::emitIntValue(uint64_t Value, unsigned Size) {104MCELFStreamer::emitIntValue(Value, Size);105Labels.clear();106}107108void MipsELFStreamer::EmitMipsOptionRecords() {109for (const auto &I : MipsOptionRecords)110I->EmitMipsOptionRecord();111}112113MCELFStreamer *114llvm::createMipsELFStreamer(MCContext &Context,115std::unique_ptr<MCAsmBackend> MAB,116std::unique_ptr<MCObjectWriter> OW,117std::unique_ptr<MCCodeEmitter> Emitter) {118return new MipsELFStreamer(Context, std::move(MAB), std::move(OW),119std::move(Emitter));120}121122123