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