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