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