Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H |
| 11 | #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 12 | |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCELFStreamer.h" |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCRegisterInfo.h" |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCStreamer.h" |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/MipsABIFlagsSection.h" |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 17 | |
| 18 | namespace llvm { |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 19 | |
Daniel Sanders | 324ad95 | 2014-07-08 13:13:42 +0000 | [diff] [blame] | 20 | struct MipsABIFlagsSection; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 21 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 22 | class MipsTargetStreamer : public MCTargetStreamer { |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 23 | public: |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 24 | MipsTargetStreamer(MCStreamer &S); |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 25 | virtual void emitDirectiveSetMicroMips(); |
| 26 | virtual void emitDirectiveSetNoMicroMips(); |
| 27 | virtual void emitDirectiveSetMips16(); |
| 28 | virtual void emitDirectiveSetNoMips16(); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 29 | |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 30 | virtual void emitDirectiveSetReorder(); |
| 31 | virtual void emitDirectiveSetNoReorder(); |
| 32 | virtual void emitDirectiveSetMacro(); |
| 33 | virtual void emitDirectiveSetNoMacro(); |
Daniel Sanders | 4493443 | 2014-08-07 12:03:36 +0000 | [diff] [blame] | 34 | virtual void emitDirectiveSetMsa(); |
| 35 | virtual void emitDirectiveSetNoMsa(); |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 36 | virtual void emitDirectiveSetAt(); |
| 37 | virtual void emitDirectiveSetNoAt(); |
| 38 | virtual void emitDirectiveEnd(StringRef Name); |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 39 | |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 40 | virtual void emitDirectiveEnt(const MCSymbol &Symbol); |
| 41 | virtual void emitDirectiveAbiCalls(); |
| 42 | virtual void emitDirectiveNaN2008(); |
| 43 | virtual void emitDirectiveNaNLegacy(); |
| 44 | virtual void emitDirectiveOptionPic0(); |
| 45 | virtual void emitDirectiveOptionPic2(); |
Rafael Espindola | 054234f | 2014-01-27 03:53:56 +0000 | [diff] [blame] | 46 | virtual void emitFrame(unsigned StackReg, unsigned StackSize, |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 47 | unsigned ReturnReg); |
| 48 | virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); |
| 49 | virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff); |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 50 | |
Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 51 | virtual void emitDirectiveSetArch(StringRef Arch); |
Toma Tabacu | 2664779 | 2014-09-09 12:52:14 +0000 | [diff] [blame^] | 52 | virtual void emitDirectiveSetMips0(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 53 | virtual void emitDirectiveSetMips1(); |
| 54 | virtual void emitDirectiveSetMips2(); |
| 55 | virtual void emitDirectiveSetMips3(); |
| 56 | virtual void emitDirectiveSetMips4(); |
| 57 | virtual void emitDirectiveSetMips5(); |
| 58 | virtual void emitDirectiveSetMips32(); |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 59 | virtual void emitDirectiveSetMips32R2(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 60 | virtual void emitDirectiveSetMips32R6(); |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 61 | virtual void emitDirectiveSetMips64(); |
| 62 | virtual void emitDirectiveSetMips64R2(); |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 63 | virtual void emitDirectiveSetMips64R6(); |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 64 | virtual void emitDirectiveSetDsp(); |
Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 65 | virtual void emitDirectiveSetPop(); |
| 66 | virtual void emitDirectiveSetPush(); |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 67 | |
| 68 | // PIC support |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 69 | virtual void emitDirectiveCpload(unsigned RegNo); |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 70 | virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
Rafael Espindola | 60890b8 | 2014-06-23 19:43:40 +0000 | [diff] [blame] | 71 | const MCSymbol &Sym, bool IsReg); |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 72 | |
| 73 | /// Emit a '.module fp=value' directive using the given values. |
| 74 | /// Updates the .MIPS.abiflags section |
| 75 | virtual void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, |
| 76 | bool Is32BitABI) { |
| 77 | ABIFlagsSection.setFpABI(Value, Is32BitABI); |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 78 | } |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 79 | |
| 80 | /// Emit a '.module fp=value' directive using the current values of the |
| 81 | /// .MIPS.abiflags section. |
| 82 | void emitDirectiveModuleFP() { |
| 83 | emitDirectiveModuleFP(ABIFlagsSection.getFpABI(), |
| 84 | ABIFlagsSection.Is32BitABI); |
| 85 | } |
| 86 | |
| 87 | virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI); |
| 88 | virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){}; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 89 | virtual void emitMipsAbiFlags(){}; |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 90 | void forbidModuleDirective() { ModuleDirectiveAllowed = false; } |
| 91 | bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; } |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 92 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 93 | // This method enables template classes to set internal abi flags |
| 94 | // structure values. |
| 95 | template <class PredicateLibrary> |
| 96 | void updateABIInfo(const PredicateLibrary &P) { |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 97 | ABIFlagsSection.setAllFromPredicates(P); |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 100 | MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; } |
| 101 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 102 | protected: |
Daniel Sanders | c7dbc63 | 2014-07-08 10:11:38 +0000 | [diff] [blame] | 103 | MipsABIFlagsSection ABIFlagsSection; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 104 | |
Daniel Sanders | d97a634 | 2014-08-13 10:07:34 +0000 | [diff] [blame] | 105 | bool GPRInfoSet; |
| 106 | unsigned GPRBitMask; |
| 107 | int GPROffset; |
| 108 | |
| 109 | bool FPRInfoSet; |
| 110 | unsigned FPRBitMask; |
| 111 | int FPROffset; |
| 112 | |
| 113 | bool FrameInfoSet; |
| 114 | int FrameOffset; |
| 115 | unsigned FrameReg; |
| 116 | unsigned ReturnReg; |
| 117 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 118 | private: |
Daniel Sanders | cdb45fa | 2014-08-14 09:18:14 +0000 | [diff] [blame] | 119 | bool ModuleDirectiveAllowed; |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 120 | }; |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 121 | |
| 122 | // This part is for ascii assembly output |
| 123 | class MipsTargetAsmStreamer : public MipsTargetStreamer { |
Jack Carter | 6ef6cc5 | 2013-11-19 20:53:28 +0000 | [diff] [blame] | 124 | formatted_raw_ostream &OS; |
| 125 | |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 126 | public: |
Rafael Espindola | 24ea09e | 2014-01-26 06:06:37 +0000 | [diff] [blame] | 127 | MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 128 | void emitDirectiveSetMicroMips() override; |
| 129 | void emitDirectiveSetNoMicroMips() override; |
| 130 | void emitDirectiveSetMips16() override; |
| 131 | void emitDirectiveSetNoMips16() override; |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 132 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 133 | void emitDirectiveSetReorder() override; |
| 134 | void emitDirectiveSetNoReorder() override; |
| 135 | void emitDirectiveSetMacro() override; |
| 136 | void emitDirectiveSetNoMacro() override; |
Daniel Sanders | 4493443 | 2014-08-07 12:03:36 +0000 | [diff] [blame] | 137 | void emitDirectiveSetMsa() override; |
| 138 | void emitDirectiveSetNoMsa() override; |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 139 | void emitDirectiveSetAt() override; |
| 140 | void emitDirectiveSetNoAt() override; |
| 141 | void emitDirectiveEnd(StringRef Name) override; |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 142 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 143 | void emitDirectiveEnt(const MCSymbol &Symbol) override; |
| 144 | void emitDirectiveAbiCalls() override; |
| 145 | void emitDirectiveNaN2008() override; |
| 146 | void emitDirectiveNaNLegacy() override; |
| 147 | void emitDirectiveOptionPic0() override; |
| 148 | void emitDirectiveOptionPic2() override; |
| 149 | void emitFrame(unsigned StackReg, unsigned StackSize, |
| 150 | unsigned ReturnReg) override; |
| 151 | void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; |
| 152 | void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 153 | |
Toma Tabacu | 85618b3 | 2014-08-19 14:22:52 +0000 | [diff] [blame] | 154 | void emitDirectiveSetArch(StringRef Arch) override; |
Toma Tabacu | 2664779 | 2014-09-09 12:52:14 +0000 | [diff] [blame^] | 155 | void emitDirectiveSetMips0() override; |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 156 | void emitDirectiveSetMips1() override; |
| 157 | void emitDirectiveSetMips2() override; |
| 158 | void emitDirectiveSetMips3() override; |
| 159 | void emitDirectiveSetMips4() override; |
| 160 | void emitDirectiveSetMips5() override; |
| 161 | void emitDirectiveSetMips32() override; |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 162 | void emitDirectiveSetMips32R2() override; |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 163 | void emitDirectiveSetMips32R6() override; |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 164 | void emitDirectiveSetMips64() override; |
| 165 | void emitDirectiveSetMips64R2() override; |
Daniel Sanders | f0df221 | 2014-08-04 12:20:00 +0000 | [diff] [blame] | 166 | void emitDirectiveSetMips64R6() override; |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 167 | void emitDirectiveSetDsp() override; |
Toma Tabacu | 9db22db | 2014-09-09 10:15:38 +0000 | [diff] [blame] | 168 | void emitDirectiveSetPop() override; |
| 169 | void emitDirectiveSetPush() override; |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 170 | |
| 171 | // PIC support |
Benjamin Kramer | 8c90fd7 | 2014-09-03 11:41:21 +0000 | [diff] [blame] | 172 | void emitDirectiveCpload(unsigned RegNo) override; |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 173 | void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
| 174 | const MCSymbol &Sym, bool IsReg) override; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 175 | |
| 176 | // ABI Flags |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 177 | void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, |
| 178 | bool Is32BitABI) override; |
| 179 | void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; |
| 180 | void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 181 | void emitMipsAbiFlags() override; |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | // This part is for ELF object output |
| 185 | class MipsTargetELFStreamer : public MipsTargetStreamer { |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 186 | bool MicroMipsEnabled; |
Rafael Espindola | 972e71a | 2014-01-31 23:10:26 +0000 | [diff] [blame] | 187 | const MCSubtargetInfo &STI; |
Matheus Almeida | f79b281 | 2014-03-26 13:40:29 +0000 | [diff] [blame] | 188 | bool Pic; |
Jack Carter | 3953672 | 2014-01-22 23:08:42 +0000 | [diff] [blame] | 189 | |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 190 | public: |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 191 | bool isMicroMipsEnabled() const { return MicroMipsEnabled; } |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 192 | MCELFStreamer &getStreamer(); |
Rafael Espindola | cb1953f | 2014-01-26 06:57:13 +0000 | [diff] [blame] | 193 | MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 194 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 195 | void emitLabel(MCSymbol *Symbol) override; |
| 196 | void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; |
Craig Topper | 7315602 | 2014-03-02 09:09:27 +0000 | [diff] [blame] | 197 | void finish() override; |
Rafael Espindola | 6d5f7ce | 2014-01-14 04:25:13 +0000 | [diff] [blame] | 198 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 199 | void emitDirectiveSetMicroMips() override; |
| 200 | void emitDirectiveSetNoMicroMips() override; |
| 201 | void emitDirectiveSetMips16() override; |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 202 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 203 | void emitDirectiveSetNoReorder() override; |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 204 | void emitDirectiveEnd(StringRef Name) override; |
Rafael Espindola | eb0a8af | 2014-01-26 05:06:48 +0000 | [diff] [blame] | 205 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 206 | void emitDirectiveEnt(const MCSymbol &Symbol) override; |
| 207 | void emitDirectiveAbiCalls() override; |
| 208 | void emitDirectiveNaN2008() override; |
| 209 | void emitDirectiveNaNLegacy() override; |
| 210 | void emitDirectiveOptionPic0() override; |
| 211 | void emitDirectiveOptionPic2() override; |
| 212 | void emitFrame(unsigned StackReg, unsigned StackSize, |
| 213 | unsigned ReturnReg) override; |
| 214 | void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; |
| 215 | void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; |
Vladimir Medic | 615b26e | 2014-03-04 09:54:09 +0000 | [diff] [blame] | 216 | |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 217 | // PIC support |
Benjamin Kramer | 8c90fd7 | 2014-09-03 11:41:21 +0000 | [diff] [blame] | 218 | void emitDirectiveCpload(unsigned RegNo) override; |
Matheus Almeida | d92a3fa | 2014-05-01 10:24:46 +0000 | [diff] [blame] | 219 | void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
| 220 | const MCSymbol &Sym, bool IsReg) override; |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 221 | |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 222 | // ABI Flags |
Daniel Sanders | 7e52742 | 2014-07-10 13:38:23 +0000 | [diff] [blame] | 223 | void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; |
Vladimir Medic | fb8a2a9 | 2014-07-08 08:59:22 +0000 | [diff] [blame] | 224 | void emitMipsAbiFlags() override; |
| 225 | |
Matheus Almeida | 525bc4f | 2014-04-30 11:28:42 +0000 | [diff] [blame] | 226 | protected: |
| 227 | bool isO32() const { return STI.getFeatureBits() & Mips::FeatureO32; } |
| 228 | bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; } |
| 229 | bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; } |
Jack Carter | 86ac5c1 | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 230 | }; |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 231 | } |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 232 | #endif |