1*9880d681SAndroid Build Coastguard Worker //===-------- MipsELFStreamer.h - ELF Object Output -----------------------===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This is a custom MCELFStreamer which allows us to insert some hooks before 11*9880d681SAndroid Build Coastguard Worker // emitting data into an actual object file. 12*9880d681SAndroid Build Coastguard Worker // 13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H 16*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSELFSTREAMER_H 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker #include "MipsOptionRecord.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCELFStreamer.h" 21*9880d681SAndroid Build Coastguard Worker #include <memory> 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker namespace llvm { 24*9880d681SAndroid Build Coastguard Worker class MCAsmBackend; 25*9880d681SAndroid Build Coastguard Worker class MCCodeEmitter; 26*9880d681SAndroid Build Coastguard Worker class MCContext; 27*9880d681SAndroid Build Coastguard Worker class MCSubtargetInfo; 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard Worker class MipsELFStreamer : public MCELFStreamer { 30*9880d681SAndroid Build Coastguard Worker SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords; 31*9880d681SAndroid Build Coastguard Worker MipsRegInfoRecord *RegInfoRecord; 32*9880d681SAndroid Build Coastguard Worker SmallVector<MCSymbol*, 4> Labels; 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker public: MipsELFStreamer(MCContext & Context,MCAsmBackend & MAB,raw_pwrite_stream & OS,MCCodeEmitter * Emitter)36*9880d681SAndroid Build Coastguard Worker MipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, 37*9880d681SAndroid Build Coastguard Worker MCCodeEmitter *Emitter) 38*9880d681SAndroid Build Coastguard Worker : MCELFStreamer(Context, MAB, OS, Emitter) { 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker RegInfoRecord = new MipsRegInfoRecord(this, Context); 41*9880d681SAndroid Build Coastguard Worker MipsOptionRecords.push_back( 42*9880d681SAndroid Build Coastguard Worker std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord)); 43*9880d681SAndroid Build Coastguard Worker } 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker /// Overriding this function allows us to add arbitrary behaviour before the 46*9880d681SAndroid Build Coastguard Worker /// \p Inst is actually emitted. For example, we can inspect the operands and 47*9880d681SAndroid Build Coastguard Worker /// gather sufficient information that allows us to reason about the register 48*9880d681SAndroid Build Coastguard Worker /// usage for the translation unit. 49*9880d681SAndroid Build Coastguard Worker void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override; 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker /// Overriding this function allows us to record all labels that should be 52*9880d681SAndroid Build Coastguard Worker /// marked as microMIPS. Based on this data marking is done in 53*9880d681SAndroid Build Coastguard Worker /// EmitInstruction. 54*9880d681SAndroid Build Coastguard Worker void EmitLabel(MCSymbol *Symbol) override; 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker /// Overriding this function allows us to dismiss all labels that are 57*9880d681SAndroid Build Coastguard Worker /// candidates for marking as microMIPS when .section directive is processed. 58*9880d681SAndroid Build Coastguard Worker void SwitchSection(MCSection *Section, 59*9880d681SAndroid Build Coastguard Worker const MCExpr *Subsection = nullptr) override; 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker /// Overriding this function allows us to dismiss all labels that are 62*9880d681SAndroid Build Coastguard Worker /// candidates for marking as microMIPS when .word directive is emitted. 63*9880d681SAndroid Build Coastguard Worker void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override; 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker /// Emits all the option records stored up until the point it's called. 66*9880d681SAndroid Build Coastguard Worker void EmitMipsOptionRecords(); 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker /// Mark labels as microMIPS, if necessary for the subtarget. 69*9880d681SAndroid Build Coastguard Worker void createPendingLabelRelocs(); 70*9880d681SAndroid Build Coastguard Worker }; 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Worker MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB, 73*9880d681SAndroid Build Coastguard Worker raw_pwrite_stream &OS, 74*9880d681SAndroid Build Coastguard Worker MCCodeEmitter *Emitter, bool RelaxAll); 75*9880d681SAndroid Build Coastguard Worker } // namespace llvm. 76*9880d681SAndroid Build Coastguard Worker #endif 77