1f4a2713aSLionel Sambuc //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc 10*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H 11*0a6a1f1dSLionel Sambuc #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H 12f4a2713aSLionel Sambuc 13*0a6a1f1dSLionel Sambuc #include "MCTargetDesc/MipsABIFlagsSection.h" 14f4a2713aSLionel Sambuc #include "llvm/MC/MCELFStreamer.h" 15*0a6a1f1dSLionel Sambuc #include "llvm/MC/MCRegisterInfo.h" 16f4a2713aSLionel Sambuc #include "llvm/MC/MCStreamer.h" 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc namespace llvm { 19f4a2713aSLionel Sambuc 20*0a6a1f1dSLionel Sambuc struct MipsABIFlagsSection; 21*0a6a1f1dSLionel Sambuc 22*0a6a1f1dSLionel Sambuc class MipsTargetStreamer : public MCTargetStreamer { 23f4a2713aSLionel Sambuc public: 24*0a6a1f1dSLionel Sambuc MipsTargetStreamer(MCStreamer &S); 25*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMicroMips(); 26*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoMicroMips(); 27*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips16(); 28*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoMips16(); 29*0a6a1f1dSLionel Sambuc 30*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetReorder(); 31*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoReorder(); 32*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMacro(); 33*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoMacro(); 34*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMsa(); 35*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoMsa(); 36*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetAt(); 37*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoAt(); 38*0a6a1f1dSLionel Sambuc virtual void emitDirectiveEnd(StringRef Name); 39*0a6a1f1dSLionel Sambuc 40*0a6a1f1dSLionel Sambuc virtual void emitDirectiveEnt(const MCSymbol &Symbol); 41*0a6a1f1dSLionel Sambuc virtual void emitDirectiveAbiCalls(); 42*0a6a1f1dSLionel Sambuc virtual void emitDirectiveNaN2008(); 43*0a6a1f1dSLionel Sambuc virtual void emitDirectiveNaNLegacy(); 44*0a6a1f1dSLionel Sambuc virtual void emitDirectiveOptionPic0(); 45*0a6a1f1dSLionel Sambuc virtual void emitDirectiveOptionPic2(); 46*0a6a1f1dSLionel Sambuc virtual void emitFrame(unsigned StackReg, unsigned StackSize, 47*0a6a1f1dSLionel Sambuc unsigned ReturnReg); 48*0a6a1f1dSLionel Sambuc virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); 49*0a6a1f1dSLionel Sambuc virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff); 50*0a6a1f1dSLionel Sambuc 51*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetArch(StringRef Arch); 52*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips0(); 53*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips1(); 54*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips2(); 55*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips3(); 56*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips4(); 57*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips5(); 58*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips32(); 59*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips32R2(); 60*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips32R6(); 61*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips64(); 62*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips64R2(); 63*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetMips64R6(); 64*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetDsp(); 65*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetNoDsp(); 66*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetPop(); 67*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetPush(); 68*0a6a1f1dSLionel Sambuc 69*0a6a1f1dSLionel Sambuc // PIC support 70*0a6a1f1dSLionel Sambuc virtual void emitDirectiveCpLoad(unsigned RegNo); 71*0a6a1f1dSLionel Sambuc virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 72*0a6a1f1dSLionel Sambuc const MCSymbol &Sym, bool IsReg); 73*0a6a1f1dSLionel Sambuc 74*0a6a1f1dSLionel Sambuc /// Emit a '.module fp=value' directive using the given values. 75*0a6a1f1dSLionel Sambuc /// Updates the .MIPS.abiflags section emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,bool Is32BitABI)76*0a6a1f1dSLionel Sambuc virtual void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, 77*0a6a1f1dSLionel Sambuc bool Is32BitABI) { 78*0a6a1f1dSLionel Sambuc ABIFlagsSection.setFpABI(Value, Is32BitABI); 79*0a6a1f1dSLionel Sambuc } 80*0a6a1f1dSLionel Sambuc 81*0a6a1f1dSLionel Sambuc /// Emit a '.module fp=value' directive using the current values of the 82*0a6a1f1dSLionel Sambuc /// .MIPS.abiflags section. emitDirectiveModuleFP()83*0a6a1f1dSLionel Sambuc void emitDirectiveModuleFP() { 84*0a6a1f1dSLionel Sambuc emitDirectiveModuleFP(ABIFlagsSection.getFpABI(), 85*0a6a1f1dSLionel Sambuc ABIFlagsSection.Is32BitABI); 86*0a6a1f1dSLionel Sambuc } 87*0a6a1f1dSLionel Sambuc 88*0a6a1f1dSLionel Sambuc virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI); emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value)89*0a6a1f1dSLionel Sambuc virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){}; emitMipsAbiFlags()90*0a6a1f1dSLionel Sambuc virtual void emitMipsAbiFlags(){}; forbidModuleDirective()91*0a6a1f1dSLionel Sambuc void forbidModuleDirective() { ModuleDirectiveAllowed = false; } isModuleDirectiveAllowed()92*0a6a1f1dSLionel Sambuc bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; } 93*0a6a1f1dSLionel Sambuc 94*0a6a1f1dSLionel Sambuc // This method enables template classes to set internal abi flags 95*0a6a1f1dSLionel Sambuc // structure values. 96*0a6a1f1dSLionel Sambuc template <class PredicateLibrary> updateABIInfo(const PredicateLibrary & P)97*0a6a1f1dSLionel Sambuc void updateABIInfo(const PredicateLibrary &P) { 98*0a6a1f1dSLionel Sambuc ABIFlagsSection.setAllFromPredicates(P); 99*0a6a1f1dSLionel Sambuc } 100*0a6a1f1dSLionel Sambuc getABIFlagsSection()101*0a6a1f1dSLionel Sambuc MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; } 102*0a6a1f1dSLionel Sambuc 103*0a6a1f1dSLionel Sambuc protected: 104*0a6a1f1dSLionel Sambuc MipsABIFlagsSection ABIFlagsSection; 105*0a6a1f1dSLionel Sambuc 106*0a6a1f1dSLionel Sambuc bool GPRInfoSet; 107*0a6a1f1dSLionel Sambuc unsigned GPRBitMask; 108*0a6a1f1dSLionel Sambuc int GPROffset; 109*0a6a1f1dSLionel Sambuc 110*0a6a1f1dSLionel Sambuc bool FPRInfoSet; 111*0a6a1f1dSLionel Sambuc unsigned FPRBitMask; 112*0a6a1f1dSLionel Sambuc int FPROffset; 113*0a6a1f1dSLionel Sambuc 114*0a6a1f1dSLionel Sambuc bool FrameInfoSet; 115*0a6a1f1dSLionel Sambuc int FrameOffset; 116*0a6a1f1dSLionel Sambuc unsigned FrameReg; 117*0a6a1f1dSLionel Sambuc unsigned ReturnReg; 118*0a6a1f1dSLionel Sambuc 119*0a6a1f1dSLionel Sambuc private: 120*0a6a1f1dSLionel Sambuc bool ModuleDirectiveAllowed; 121f4a2713aSLionel Sambuc }; 122f4a2713aSLionel Sambuc 123f4a2713aSLionel Sambuc // This part is for ascii assembly output 124f4a2713aSLionel Sambuc class MipsTargetAsmStreamer : public MipsTargetStreamer { 125f4a2713aSLionel Sambuc formatted_raw_ostream &OS; 126f4a2713aSLionel Sambuc 127f4a2713aSLionel Sambuc public: 128*0a6a1f1dSLionel Sambuc MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 129*0a6a1f1dSLionel Sambuc void emitDirectiveSetMicroMips() override; 130*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoMicroMips() override; 131*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips16() override; 132*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoMips16() override; 133*0a6a1f1dSLionel Sambuc 134*0a6a1f1dSLionel Sambuc void emitDirectiveSetReorder() override; 135*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoReorder() override; 136*0a6a1f1dSLionel Sambuc void emitDirectiveSetMacro() override; 137*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoMacro() override; 138*0a6a1f1dSLionel Sambuc void emitDirectiveSetMsa() override; 139*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoMsa() override; 140*0a6a1f1dSLionel Sambuc void emitDirectiveSetAt() override; 141*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoAt() override; 142*0a6a1f1dSLionel Sambuc void emitDirectiveEnd(StringRef Name) override; 143*0a6a1f1dSLionel Sambuc 144*0a6a1f1dSLionel Sambuc void emitDirectiveEnt(const MCSymbol &Symbol) override; 145*0a6a1f1dSLionel Sambuc void emitDirectiveAbiCalls() override; 146*0a6a1f1dSLionel Sambuc void emitDirectiveNaN2008() override; 147*0a6a1f1dSLionel Sambuc void emitDirectiveNaNLegacy() override; 148*0a6a1f1dSLionel Sambuc void emitDirectiveOptionPic0() override; 149*0a6a1f1dSLionel Sambuc void emitDirectiveOptionPic2() override; 150*0a6a1f1dSLionel Sambuc void emitFrame(unsigned StackReg, unsigned StackSize, 151*0a6a1f1dSLionel Sambuc unsigned ReturnReg) override; 152*0a6a1f1dSLionel Sambuc void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; 153*0a6a1f1dSLionel Sambuc void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; 154*0a6a1f1dSLionel Sambuc 155*0a6a1f1dSLionel Sambuc void emitDirectiveSetArch(StringRef Arch) override; 156*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips0() override; 157*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips1() override; 158*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips2() override; 159*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips3() override; 160*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips4() override; 161*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips5() override; 162*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips32() override; 163*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips32R2() override; 164*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips32R6() override; 165*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips64() override; 166*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips64R2() override; 167*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips64R6() override; 168*0a6a1f1dSLionel Sambuc void emitDirectiveSetDsp() override; 169*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoDsp() override; 170*0a6a1f1dSLionel Sambuc void emitDirectiveSetPop() override; 171*0a6a1f1dSLionel Sambuc void emitDirectiveSetPush() override; 172*0a6a1f1dSLionel Sambuc 173*0a6a1f1dSLionel Sambuc // PIC support 174*0a6a1f1dSLionel Sambuc void emitDirectiveCpLoad(unsigned RegNo) override; 175*0a6a1f1dSLionel Sambuc void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 176*0a6a1f1dSLionel Sambuc const MCSymbol &Sym, bool IsReg) override; 177*0a6a1f1dSLionel Sambuc 178*0a6a1f1dSLionel Sambuc // ABI Flags 179*0a6a1f1dSLionel Sambuc void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, 180*0a6a1f1dSLionel Sambuc bool Is32BitABI) override; 181*0a6a1f1dSLionel Sambuc void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; 182*0a6a1f1dSLionel Sambuc void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override; 183*0a6a1f1dSLionel Sambuc void emitMipsAbiFlags() override; 184f4a2713aSLionel Sambuc }; 185f4a2713aSLionel Sambuc 186f4a2713aSLionel Sambuc // This part is for ELF object output 187f4a2713aSLionel Sambuc class MipsTargetELFStreamer : public MipsTargetStreamer { 188*0a6a1f1dSLionel Sambuc bool MicroMipsEnabled; 189*0a6a1f1dSLionel Sambuc const MCSubtargetInfo &STI; 190*0a6a1f1dSLionel Sambuc bool Pic; 191*0a6a1f1dSLionel Sambuc 192f4a2713aSLionel Sambuc public: isMicroMipsEnabled()193*0a6a1f1dSLionel Sambuc bool isMicroMipsEnabled() const { return MicroMipsEnabled; } 194f4a2713aSLionel Sambuc MCELFStreamer &getStreamer(); 195*0a6a1f1dSLionel Sambuc MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 196*0a6a1f1dSLionel Sambuc 197*0a6a1f1dSLionel Sambuc void emitLabel(MCSymbol *Symbol) override; 198*0a6a1f1dSLionel Sambuc void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; 199*0a6a1f1dSLionel Sambuc void finish() override; 200*0a6a1f1dSLionel Sambuc 201*0a6a1f1dSLionel Sambuc void emitDirectiveSetMicroMips() override; 202*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoMicroMips() override; 203*0a6a1f1dSLionel Sambuc void emitDirectiveSetMips16() override; 204*0a6a1f1dSLionel Sambuc 205*0a6a1f1dSLionel Sambuc void emitDirectiveSetNoReorder() override; 206*0a6a1f1dSLionel Sambuc void emitDirectiveEnd(StringRef Name) override; 207*0a6a1f1dSLionel Sambuc 208*0a6a1f1dSLionel Sambuc void emitDirectiveEnt(const MCSymbol &Symbol) override; 209*0a6a1f1dSLionel Sambuc void emitDirectiveAbiCalls() override; 210*0a6a1f1dSLionel Sambuc void emitDirectiveNaN2008() override; 211*0a6a1f1dSLionel Sambuc void emitDirectiveNaNLegacy() override; 212*0a6a1f1dSLionel Sambuc void emitDirectiveOptionPic0() override; 213*0a6a1f1dSLionel Sambuc void emitDirectiveOptionPic2() override; 214*0a6a1f1dSLionel Sambuc void emitFrame(unsigned StackReg, unsigned StackSize, 215*0a6a1f1dSLionel Sambuc unsigned ReturnReg) override; 216*0a6a1f1dSLionel Sambuc void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; 217*0a6a1f1dSLionel Sambuc void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; 218*0a6a1f1dSLionel Sambuc 219*0a6a1f1dSLionel Sambuc // PIC support 220*0a6a1f1dSLionel Sambuc void emitDirectiveCpLoad(unsigned RegNo) override; 221*0a6a1f1dSLionel Sambuc void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 222*0a6a1f1dSLionel Sambuc const MCSymbol &Sym, bool IsReg) override; 223*0a6a1f1dSLionel Sambuc 224*0a6a1f1dSLionel Sambuc // ABI Flags 225*0a6a1f1dSLionel Sambuc void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; 226*0a6a1f1dSLionel Sambuc void emitMipsAbiFlags() override; 227*0a6a1f1dSLionel Sambuc 228*0a6a1f1dSLionel Sambuc protected: isO32()229*0a6a1f1dSLionel Sambuc bool isO32() const { return STI.getFeatureBits() & Mips::FeatureO32; } isN32()230*0a6a1f1dSLionel Sambuc bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; } isN64()231*0a6a1f1dSLionel Sambuc bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; } 232f4a2713aSLionel Sambuc }; 233f4a2713aSLionel Sambuc } 234f4a2713aSLionel Sambuc #endif 235