]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MCTargetDesc / MipsELFStreamer.cpp
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
26 MipsELFStreamer::MipsELFStreamer(MCContext &Context,
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
37 void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
38                                       const MCSubtargetInfo &STI, bool) {
39   MCELFStreamer::EmitInstruction(Inst, STI);
40
41   MCContext &Context = getContext();
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
54   createPendingLabelRelocs();
55 }
56
57 void MipsELFStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
58   Frame.Begin = getContext().createTempSymbol();
59   MCELFStreamer::EmitLabel(Frame.Begin);
60 }
61
62 MCSymbol *MipsELFStreamer::EmitCFILabel() {
63   MCSymbol *Label = getContext().createTempSymbol("cfi", true);
64   MCELFStreamer::EmitLabel(Label);
65   return Label;
66 }
67
68 void MipsELFStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
69   Frame.End = getContext().createTempSymbol();
70   MCELFStreamer::EmitLabel(Frame.End);
71 }
72
73 void MipsELFStreamer::createPendingLabelRelocs() {
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
89 void MipsELFStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
90   MCELFStreamer::EmitLabel(Symbol);
91   Labels.push_back(Symbol);
92 }
93
94 void MipsELFStreamer::SwitchSection(MCSection *Section,
95                                     const MCExpr *Subsection) {
96   MCELFStreamer::SwitchSection(Section, Subsection);
97   Labels.clear();
98 }
99
100 void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
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
111 void MipsELFStreamer::EmitMipsOptionRecords() {
112   for (const auto &I : MipsOptionRecords)
113     I->EmitMipsOptionRecord();
114 }
115
116 MCELFStreamer *llvm::createMipsELFStreamer(
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 }