blob: 56a0ff96c7bd6e6e10ba4410a4ae35c727aa5a1e [file] [log] [blame]
Eugene Zelenkocd8ea022017-02-03 23:39:33 +00001//===- MipsELFStreamer.h - ELF Object Output --------------------*- C++ -*-===//
Matheus Almeidadac77fb2014-03-27 11:39:03 +00002//
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// This is a custom MCELFStreamer which allows us to insert some hooks before
11// emitting data into an actual object file.
12//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
16#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H
Matheus Almeidadac77fb2014-03-27 11:39:03 +000017
Daniel Sanders68c37472014-07-21 13:30:55 +000018#include "MipsOptionRecord.h"
19#include "llvm/ADT/SmallVector.h"
Matheus Almeidadac77fb2014-03-27 11:39:03 +000020#include "llvm/MC/MCELFStreamer.h"
Daniel Sanders68c37472014-07-21 13:30:55 +000021#include <memory>
Matheus Almeidadac77fb2014-03-27 11:39:03 +000022
23namespace llvm {
Eugene Zelenkocd8ea022017-02-03 23:39:33 +000024
Matheus Almeidadac77fb2014-03-27 11:39:03 +000025class MCAsmBackend;
26class MCCodeEmitter;
27class MCContext;
28class MCSubtargetInfo;
Aleksandar Beserminji81eb4402018-10-15 14:39:12 +000029struct MCDwarfFrameInfo;
Matheus Almeidadac77fb2014-03-27 11:39:03 +000030
31class MipsELFStreamer : public MCELFStreamer {
Daniel Sanders68c37472014-07-21 13:30:55 +000032 SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
33 MipsRegInfoRecord *RegInfoRecord;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000034 SmallVector<MCSymbol*, 4> Labels;
35
Matheus Almeidadac77fb2014-03-27 11:39:03 +000036public:
Lang Hames02d33052017-10-11 01:57:21 +000037 MipsELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
Peter Collingbournef7b81db2018-05-18 18:26:45 +000038 std::unique_ptr<MCObjectWriter> OW,
Lang Hames2241ffa2017-10-11 23:34:47 +000039 std::unique_ptr<MCCodeEmitter> Emitter);
Daniel Sanders68c37472014-07-21 13:30:55 +000040
41 /// Overriding this function allows us to add arbitrary behaviour before the
42 /// \p Inst is actually emitted. For example, we can inspect the operands and
43 /// gather sufficient information that allows us to reason about the register
44 /// usage for the translation unit.
Andrew V. Tischenko75745d02017-04-14 07:44:23 +000045 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
46 bool = false) override;
Daniel Sanders68c37472014-07-21 13:30:55 +000047
Zoran Jovanovic9c654832014-11-05 16:35:20 +000048 /// Overriding this function allows us to record all labels that should be
49 /// marked as microMIPS. Based on this data marking is done in
50 /// EmitInstruction.
Rafael Espindolabe991572017-02-10 15:13:12 +000051 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000052
53 /// Overriding this function allows us to dismiss all labels that are
54 /// candidates for marking as microMIPS when .section directive is processed.
Rafael Espindola0709a7b2015-05-21 19:20:38 +000055 void SwitchSection(MCSection *Section,
Zoran Jovanovic9c654832014-11-05 16:35:20 +000056 const MCExpr *Subsection = nullptr) override;
57
Simon Atanasyanb5244592018-07-25 07:07:43 +000058 /// Overriding these functions allows us to dismiss all labels that are
59 /// candidates for marking as microMIPS when .word/.long/.4byte etc
60 /// directives are emitted.
Craig Topper3c76c522015-09-20 23:35:59 +000061 void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
Simon Atanasyanb5244592018-07-25 07:07:43 +000062 void EmitIntValue(uint64_t Value, unsigned Size) override;
Zoran Jovanovic9c654832014-11-05 16:35:20 +000063
Aleksandar Beserminji81eb4402018-10-15 14:39:12 +000064 // Overriding these functions allows us to avoid recording of these labels
65 // in EmitLabel and later marking them as microMIPS.
66 void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
67 void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
68 MCSymbol *EmitCFILabel() override;
69
Daniel Sanders68c37472014-07-21 13:30:55 +000070 /// Emits all the option records stored up until the point it's called.
71 void EmitMipsOptionRecords();
Toma Tabacu9ca50962015-04-16 09:53:47 +000072
73 /// Mark labels as microMIPS, if necessary for the subtarget.
74 void createPendingLabelRelocs();
Matheus Almeidadac77fb2014-03-27 11:39:03 +000075};
76
Lang Hames02d33052017-10-11 01:57:21 +000077MCELFStreamer *createMipsELFStreamer(MCContext &Context,
78 std::unique_ptr<MCAsmBackend> MAB,
Peter Collingbournef7b81db2018-05-18 18:26:45 +000079 std::unique_ptr<MCObjectWriter> OW,
Lang Hames2241ffa2017-10-11 23:34:47 +000080 std::unique_ptr<MCCodeEmitter> Emitter,
81 bool RelaxAll);
Eugene Zelenkocd8ea022017-02-03 23:39:33 +000082} // end namespace llvm
83
84#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H