LLVM  8.0.1
MipsTargetStreamer.cpp
Go to the documentation of this file.
1 //===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
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 // This file provides Mips specific target streamer methods.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MipsTargetStreamer.h"
17 #include "MipsELFStreamer.h"
18 #include "MipsMCExpr.h"
19 #include "MipsMCTargetDesc.h"
20 #include "MipsTargetObjectFile.h"
21 #include "llvm/BinaryFormat/ELF.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCSectionELF.h"
25 #include "llvm/MC/MCSymbolELF.h"
29 
30 using namespace llvm;
31 
32 namespace {
33 static cl::opt<bool> RoundSectionSizes(
34  "mips-round-section-sizes", cl::init(false),
35  cl::desc("Round section sizes up to the section alignment"), cl::Hidden);
36 } // end anonymous namespace
37 
39  : MCTargetStreamer(S), ModuleDirectiveAllowed(true) {
41 }
64 }
74 void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
75  unsigned ReturnReg) {}
76 void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
77 void MipsTargetStreamer::emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) {
78 }
81 }
102 }
105 }
111  int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc,
112  const MCSubtargetInfo *STI) {
114  return true;
115 }
116 void MipsTargetStreamer::emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
117  const MCSymbol &Sym, bool IsReg) {
118 }
119 void MipsTargetStreamer::emitDirectiveCpreturn(unsigned SaveLocation,
120  bool SaveLocationIsRegister) {}
121 
123 
126  report_fatal_error("+nooddspreg is only valid for O32");
127 }
140 }
144 }
145 
146 void MipsTargetStreamer::emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
147  const MCSubtargetInfo *STI) {
148  MCInst TmpInst;
149  TmpInst.setOpcode(Opcode);
150  TmpInst.addOperand(MCOperand::createReg(Reg0));
151  TmpInst.setLoc(IDLoc);
152  getStreamer().EmitInstruction(TmpInst, *STI);
153 }
154 
155 void MipsTargetStreamer::emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1,
156  SMLoc IDLoc, const MCSubtargetInfo *STI) {
157  MCInst TmpInst;
158  TmpInst.setOpcode(Opcode);
159  TmpInst.addOperand(MCOperand::createReg(Reg0));
160  TmpInst.addOperand(Op1);
161  TmpInst.setLoc(IDLoc);
162  getStreamer().EmitInstruction(TmpInst, *STI);
163 }
164 
165 void MipsTargetStreamer::emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm,
166  SMLoc IDLoc, const MCSubtargetInfo *STI) {
167  emitRX(Opcode, Reg0, MCOperand::createImm(Imm), IDLoc, STI);
168 }
169 
170 void MipsTargetStreamer::emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1,
171  SMLoc IDLoc, const MCSubtargetInfo *STI) {
172  emitRX(Opcode, Reg0, MCOperand::createReg(Reg1), IDLoc, STI);
173 }
174 
175 void MipsTargetStreamer::emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2,
176  SMLoc IDLoc, const MCSubtargetInfo *STI) {
177  MCInst TmpInst;
178  TmpInst.setOpcode(Opcode);
179  TmpInst.addOperand(MCOperand::createImm(Imm1));
180  TmpInst.addOperand(MCOperand::createImm(Imm2));
181  TmpInst.setLoc(IDLoc);
182  getStreamer().EmitInstruction(TmpInst, *STI);
183 }
184 
185 void MipsTargetStreamer::emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1,
186  MCOperand Op2, SMLoc IDLoc,
187  const MCSubtargetInfo *STI) {
188  MCInst TmpInst;
189  TmpInst.setOpcode(Opcode);
190  TmpInst.addOperand(MCOperand::createReg(Reg0));
191  TmpInst.addOperand(MCOperand::createReg(Reg1));
192  TmpInst.addOperand(Op2);
193  TmpInst.setLoc(IDLoc);
194  getStreamer().EmitInstruction(TmpInst, *STI);
195 }
196 
197 void MipsTargetStreamer::emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1,
198  unsigned Reg2, SMLoc IDLoc,
199  const MCSubtargetInfo *STI) {
200  emitRRX(Opcode, Reg0, Reg1, MCOperand::createReg(Reg2), IDLoc, STI);
201 }
202 
203 void MipsTargetStreamer::emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1,
204  int16_t Imm, SMLoc IDLoc,
205  const MCSubtargetInfo *STI) {
206  emitRRX(Opcode, Reg0, Reg1, MCOperand::createImm(Imm), IDLoc, STI);
207 }
208 
209 void MipsTargetStreamer::emitRRIII(unsigned Opcode, unsigned Reg0,
210  unsigned Reg1, int16_t Imm0, int16_t Imm1,
211  int16_t Imm2, SMLoc IDLoc,
212  const MCSubtargetInfo *STI) {
213  MCInst TmpInst;
214  TmpInst.setOpcode(Opcode);
215  TmpInst.addOperand(MCOperand::createReg(Reg0));
216  TmpInst.addOperand(MCOperand::createReg(Reg1));
217  TmpInst.addOperand(MCOperand::createImm(Imm0));
218  TmpInst.addOperand(MCOperand::createImm(Imm1));
219  TmpInst.addOperand(MCOperand::createImm(Imm2));
220  TmpInst.setLoc(IDLoc);
221  getStreamer().EmitInstruction(TmpInst, *STI);
222 }
223 
224 void MipsTargetStreamer::emitAddu(unsigned DstReg, unsigned SrcReg,
225  unsigned TrgReg, bool Is64Bit,
226  const MCSubtargetInfo *STI) {
227  emitRRR(Is64Bit ? Mips::DADDu : Mips::ADDu, DstReg, SrcReg, TrgReg, SMLoc(),
228  STI);
229 }
230 
231 void MipsTargetStreamer::emitDSLL(unsigned DstReg, unsigned SrcReg,
232  int16_t ShiftAmount, SMLoc IDLoc,
233  const MCSubtargetInfo *STI) {
234  if (ShiftAmount >= 32) {
235  emitRRI(Mips::DSLL32, DstReg, SrcReg, ShiftAmount - 32, IDLoc, STI);
236  return;
237  }
238 
239  emitRRI(Mips::DSLL, DstReg, SrcReg, ShiftAmount, IDLoc, STI);
240 }
241 
243  const MCSubtargetInfo *STI) {
244  if (hasShortDelaySlot)
245  emitRR(Mips::MOVE16_MM, Mips::ZERO, Mips::ZERO, IDLoc, STI);
246  else
247  emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
248 }
249 
251  const FeatureBitset &Features = STI->getFeatureBits();
252  if (Features[Mips::FeatureMicroMips])
253  emitRR(Mips::MOVE16_MM, Mips::ZERO, Mips::ZERO, IDLoc, STI);
254  else
255  emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
256 }
257 
258 /// Emit the $gp restore operation for .cprestore.
260  const MCSubtargetInfo *STI) {
261  emitLoadWithImmOffset(Mips::LW, Mips::GP, Mips::SP, Offset, Mips::GP, IDLoc,
262  STI);
263 }
264 
265 /// Emit a store instruction with an immediate offset.
267  unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset,
268  function_ref<unsigned()> GetATReg, SMLoc IDLoc,
269  const MCSubtargetInfo *STI) {
270  if (isInt<16>(Offset)) {
271  emitRRI(Opcode, SrcReg, BaseReg, Offset, IDLoc, STI);
272  return;
273  }
274 
275  // sw $8, offset($8) => lui $at, %hi(offset)
276  // add $at, $at, $8
277  // sw $8, %lo(offset)($at)
278 
279  unsigned ATReg = GetATReg();
280  if (!ATReg)
281  return;
282 
283  unsigned LoOffset = Offset & 0x0000ffff;
284  unsigned HiOffset = (Offset & 0xffff0000) >> 16;
285 
286  // If msb of LoOffset is 1(negative number) we must increment HiOffset
287  // to account for the sign-extension of the low part.
288  if (LoOffset & 0x8000)
289  HiOffset++;
290 
291  // Generate the base address in ATReg.
292  emitRI(Mips::LUi, ATReg, HiOffset, IDLoc, STI);
293  if (BaseReg != Mips::ZERO)
294  emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI);
295  // Emit the store with the adjusted base and offset.
296  emitRRI(Opcode, SrcReg, ATReg, LoOffset, IDLoc, STI);
297 }
298 
299 /// Emit a store instruction with an symbol offset. Symbols are assumed to be
300 /// out of range for a simm16 will be expanded to appropriate instructions.
302  unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand,
303  MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
304  const MCSubtargetInfo *STI) {
305  // sw $8, sym => lui $at, %hi(sym)
306  // sw $8, %lo(sym)($at)
307 
308  // Generate the base address in ATReg.
309  emitRX(Mips::LUi, ATReg, HiOperand, IDLoc, STI);
310  if (BaseReg != Mips::ZERO)
311  emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI);
312  // Emit the store with the adjusted base and offset.
313  emitRRX(Opcode, SrcReg, ATReg, LoOperand, IDLoc, STI);
314 }
315 
316 /// Emit a load instruction with an immediate offset. DstReg and TmpReg are
317 /// permitted to be the same register iff DstReg is distinct from BaseReg and
318 /// DstReg is a GPR. It is the callers responsibility to identify such cases
319 /// and pass the appropriate register in TmpReg.
320 void MipsTargetStreamer::emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg,
321  unsigned BaseReg, int64_t Offset,
322  unsigned TmpReg, SMLoc IDLoc,
323  const MCSubtargetInfo *STI) {
324  if (isInt<16>(Offset)) {
325  emitRRI(Opcode, DstReg, BaseReg, Offset, IDLoc, STI);
326  return;
327  }
328 
329  // 1) lw $8, offset($9) => lui $8, %hi(offset)
330  // add $8, $8, $9
331  // lw $8, %lo(offset)($9)
332  // 2) lw $8, offset($8) => lui $at, %hi(offset)
333  // add $at, $at, $8
334  // lw $8, %lo(offset)($at)
335 
336  unsigned LoOffset = Offset & 0x0000ffff;
337  unsigned HiOffset = (Offset & 0xffff0000) >> 16;
338 
339  // If msb of LoOffset is 1(negative number) we must increment HiOffset
340  // to account for the sign-extension of the low part.
341  if (LoOffset & 0x8000)
342  HiOffset++;
343 
344  // Generate the base address in TmpReg.
345  emitRI(Mips::LUi, TmpReg, HiOffset, IDLoc, STI);
346  if (BaseReg != Mips::ZERO)
347  emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
348  // Emit the load with the adjusted base and offset.
349  emitRRI(Opcode, DstReg, TmpReg, LoOffset, IDLoc, STI);
350 }
351 
352 /// Emit a load instruction with an symbol offset. Symbols are assumed to be
353 /// out of range for a simm16 will be expanded to appropriate instructions.
354 /// DstReg and TmpReg are permitted to be the same register iff DstReg is a
355 /// GPR. It is the callers responsibility to identify such cases and pass the
356 /// appropriate register in TmpReg.
357 void MipsTargetStreamer::emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg,
358  unsigned BaseReg,
359  MCOperand &HiOperand,
360  MCOperand &LoOperand,
361  unsigned TmpReg, SMLoc IDLoc,
362  const MCSubtargetInfo *STI) {
363  // 1) lw $8, sym => lui $8, %hi(sym)
364  // lw $8, %lo(sym)($8)
365  // 2) ldc1 $f0, sym => lui $at, %hi(sym)
366  // ldc1 $f0, %lo(sym)($at)
367 
368  // Generate the base address in TmpReg.
369  emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
370  if (BaseReg != Mips::ZERO)
371  emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
372  // Emit the load with the adjusted base and offset.
373  emitRRX(Opcode, DstReg, TmpReg, LoOperand, IDLoc, STI);
374 }
375 
378  : MipsTargetStreamer(S), OS(OS) {}
379 
381  OS << "\t.set\tmicromips\n";
383 }
384 
386  OS << "\t.set\tnomicromips\n";
388 }
389 
391  OS << "\t.set\tmips16\n";
393 }
394 
396  OS << "\t.set\tnomips16\n";
398 }
399 
401  OS << "\t.set\treorder\n";
403 }
404 
406  OS << "\t.set\tnoreorder\n";
408 }
409 
411  OS << "\t.set\tmacro\n";
413 }
414 
416  OS << "\t.set\tnomacro\n";
418 }
419 
421  OS << "\t.set\tmsa\n";
423 }
424 
426  OS << "\t.set\tnomsa\n";
428 }
429 
431  OS << "\t.set\tmt\n";
433 }
434 
436  OS << "\t.set\tnomt\n";
438 }
439 
441  OS << "\t.set\tcrc\n";
443 }
444 
446  OS << "\t.set\tnocrc\n";
448 }
449 
451  OS << "\t.set\tvirt\n";
453 }
454 
456  OS << "\t.set\tnovirt\n";
458 }
459 
461  OS << "\t.set\tginv\n";
463 }
464 
466  OS << "\t.set\tnoginv\n";
468 }
469 
471  OS << "\t.set\tat\n";
473 }
474 
476  OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
478 }
479 
481  OS << "\t.set\tnoat\n";
483 }
484 
486  OS << "\t.end\t" << Name << '\n';
487 }
488 
490  OS << "\t.ent\t" << Symbol.getName() << '\n';
491 }
492 
493 void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
494 
495 void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
496 
498  OS << "\t.nan\tlegacy\n";
499 }
500 
502  OS << "\t.option\tpic0\n";
503 }
504 
506  OS << "\t.option\tpic2\n";
507 }
508 
511  OS << "\t.insn\n";
512 }
513 
514 void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
515  unsigned ReturnReg) {
516  OS << "\t.frame\t$"
517  << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
518  << StackSize << ",$"
519  << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
520 }
521 
523  OS << "\t.set arch=" << Arch << "\n";
525 }
526 
528  OS << "\t.set\tmips0\n";
530 }
531 
533  OS << "\t.set\tmips1\n";
535 }
536 
538  OS << "\t.set\tmips2\n";
540 }
541 
543  OS << "\t.set\tmips3\n";
545 }
546 
548  OS << "\t.set\tmips4\n";
550 }
551 
553  OS << "\t.set\tmips5\n";
555 }
556 
558  OS << "\t.set\tmips32\n";
560 }
561 
563  OS << "\t.set\tmips32r2\n";
565 }
566 
568  OS << "\t.set\tmips32r3\n";
570 }
571 
573  OS << "\t.set\tmips32r5\n";
575 }
576 
578  OS << "\t.set\tmips32r6\n";
580 }
581 
583  OS << "\t.set\tmips64\n";
585 }
586 
588  OS << "\t.set\tmips64r2\n";
590 }
591 
593  OS << "\t.set\tmips64r3\n";
595 }
596 
598  OS << "\t.set\tmips64r5\n";
600 }
601 
603  OS << "\t.set\tmips64r6\n";
605 }
606 
608  OS << "\t.set\tdsp\n";
610 }
611 
613  OS << "\t.set\tdspr2\n";
615 }
616 
618  OS << "\t.set\tnodsp\n";
620 }
621 
623  OS << "\t.set\tpop\n";
625 }
626 
628  OS << "\t.set\tpush\n";
630 }
631 
633  OS << "\t.set\tsoftfloat\n";
635 }
636 
638  OS << "\t.set\thardfloat\n";
640 }
641 
642 // Print a 32 bit hex number with all numbers.
643 static void printHex32(unsigned Value, raw_ostream &OS) {
644  OS << "0x";
645  for (int i = 7; i >= 0; i--)
646  OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
647 }
648 
649 void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
650  int CPUTopSavedRegOff) {
651  OS << "\t.mask \t";
652  printHex32(CPUBitmask, OS);
653  OS << ',' << CPUTopSavedRegOff << '\n';
654 }
655 
656 void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
657  int FPUTopSavedRegOff) {
658  OS << "\t.fmask\t";
659  printHex32(FPUBitmask, OS);
660  OS << "," << FPUTopSavedRegOff << '\n';
661 }
662 
664  OS << "\t.cpload\t$"
665  << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
667 }
668 
670  int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc,
671  const MCSubtargetInfo *STI) {
672  MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
673  OS << "\t.cprestore\t" << Offset << "\n";
674  return true;
675 }
676 
678  int RegOrOffset,
679  const MCSymbol &Sym,
680  bool IsReg) {
681  OS << "\t.cpsetup\t$"
682  << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
683 
684  if (IsReg)
685  OS << "$"
687  else
688  OS << RegOrOffset;
689 
690  OS << ", ";
691 
692  OS << Sym.getName();
694 }
695 
697  bool SaveLocationIsRegister) {
698  OS << "\t.cpreturn";
700 }
701 
705  OS << "\t.module\tsoftfloat\n";
706  else
707  OS << "\t.module\tfp=" << ABIFlagsSection.getFpABIString(FpABI) << "\n";
708 }
709 
713 
714  OS << "\t.set\tfp=";
715  OS << ABIFlagsSection.getFpABIString(Value) << "\n";
716 }
717 
720 
721  OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
722 }
723 
726  OS << "\t.set\toddspreg\n";
727 }
728 
731  OS << "\t.set\tnooddspreg\n";
732 }
733 
735  OS << "\t.module\tsoftfloat\n";
736 }
737 
739  OS << "\t.module\thardfloat\n";
740 }
741 
743  OS << "\t.module\tmt\n";
744 }
745 
747  OS << "\t.module\tcrc\n";
748 }
749 
751  OS << "\t.module\tnocrc\n";
752 }
753 
755  OS << "\t.module\tvirt\n";
756 }
757 
759  OS << "\t.module\tnovirt\n";
760 }
761 
763  OS << "\t.module\tginv\n";
764 }
765 
767  OS << "\t.module\tnoginv\n";
768 }
769 
770 // This part is for ELF object output.
772  const MCSubtargetInfo &STI)
773  : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
775 
776  // It's possible that MCObjectFileInfo isn't fully initialized at this point
777  // due to an initialization order problem where LLVMTargetMachine creates the
778  // target streamer before TargetLoweringObjectFile calls
779  // InitializeMCObjectFileInfo. There doesn't seem to be a single place that
780  // covers all cases so this statement covers most cases and direct object
781  // emission must call setPic() once MCObjectFileInfo has been initialized. The
782  // cases we don't handle here are covered by MipsAsmPrinter.
784 
785  const FeatureBitset &Features = STI.getFeatureBits();
786 
787  // Set the header flags that we can in the constructor.
788  // FIXME: This is a fairly terrible hack. We set the rest
789  // of these in the destructor. The problem here is two-fold:
790  //
791  // a: Some of the eflags can be set/reset by directives.
792  // b: There aren't any usage paths that initialize the ABI
793  // pointer until after we initialize either an assembler
794  // or the target machine.
795  // We can fix this by making the target streamer construct
796  // the ABI, but this is fraught with wide ranging dependency
797  // issues as well.
798  unsigned EFlags = MCA.getELFHeaderEFlags();
799 
800  // FIXME: Fix a dependency issue by instantiating the ABI object to some
801  // default based off the triple. The triple doesn't describe the target
802  // fully, but any external user of the API that uses the MCTargetStreamer
803  // would otherwise crash on assertion failure.
804 
805  ABI = MipsABIInfo(
806  STI.getTargetTriple().getArch() == Triple::ArchType::mipsel ||
807  STI.getTargetTriple().getArch() == Triple::ArchType::mips
808  ? MipsABIInfo::O32()
809  : MipsABIInfo::N64());
810 
811  // Architecture
812  if (Features[Mips::FeatureMips64r6])
813  EFlags |= ELF::EF_MIPS_ARCH_64R6;
814  else if (Features[Mips::FeatureMips64r2] ||
815  Features[Mips::FeatureMips64r3] ||
816  Features[Mips::FeatureMips64r5])
817  EFlags |= ELF::EF_MIPS_ARCH_64R2;
818  else if (Features[Mips::FeatureMips64])
819  EFlags |= ELF::EF_MIPS_ARCH_64;
820  else if (Features[Mips::FeatureMips5])
821  EFlags |= ELF::EF_MIPS_ARCH_5;
822  else if (Features[Mips::FeatureMips4])
823  EFlags |= ELF::EF_MIPS_ARCH_4;
824  else if (Features[Mips::FeatureMips3])
825  EFlags |= ELF::EF_MIPS_ARCH_3;
826  else if (Features[Mips::FeatureMips32r6])
827  EFlags |= ELF::EF_MIPS_ARCH_32R6;
828  else if (Features[Mips::FeatureMips32r2] ||
829  Features[Mips::FeatureMips32r3] ||
830  Features[Mips::FeatureMips32r5])
831  EFlags |= ELF::EF_MIPS_ARCH_32R2;
832  else if (Features[Mips::FeatureMips32])
833  EFlags |= ELF::EF_MIPS_ARCH_32;
834  else if (Features[Mips::FeatureMips2])
835  EFlags |= ELF::EF_MIPS_ARCH_2;
836  else
837  EFlags |= ELF::EF_MIPS_ARCH_1;
838 
839  // Machine
840  if (Features[Mips::FeatureCnMips])
841  EFlags |= ELF::EF_MIPS_MACH_OCTEON;
842 
843  // Other options.
844  if (Features[Mips::FeatureNaN2008])
845  EFlags |= ELF::EF_MIPS_NAN2008;
846 
847  MCA.setELFHeaderEFlags(EFlags);
848 }
849 
851  auto *Symbol = cast<MCSymbolELF>(S);
853  uint8_t Type = Symbol->getType();
854  if (Type != ELF::STT_FUNC)
855  return;
856 
857  if (isMicroMipsEnabled())
858  Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
859 }
860 
863  const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
864 
865  // .bss, .text and .data are always at least 16-byte aligned.
866  MCSection &TextSection = *OFI.getTextSection();
867  MCA.registerSection(TextSection);
868  MCSection &DataSection = *OFI.getDataSection();
869  MCA.registerSection(DataSection);
870  MCSection &BSSSection = *OFI.getBSSSection();
871  MCA.registerSection(BSSSection);
872 
873  TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
874  DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
875  BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
876 
877  if (RoundSectionSizes) {
878  // Make sections sizes a multiple of the alignment. This is useful for
879  // verifying the output of IAS against the output of other assemblers but
880  // it's not necessary to produce a correct object and increases section
881  // size.
882  MCStreamer &OS = getStreamer();
883  for (MCSection &S : MCA) {
884  MCSectionELF &Section = static_cast<MCSectionELF &>(S);
885 
886  unsigned Alignment = Section.getAlignment();
887  if (Alignment) {
888  OS.SwitchSection(&Section);
889  if (Section.UseCodeAlign())
890  OS.EmitCodeAlignment(Alignment, Alignment);
891  else
892  OS.EmitValueToAlignment(Alignment, 0, 1, Alignment);
893  }
894  }
895  }
896 
897  const FeatureBitset &Features = STI.getFeatureBits();
898 
899  // Update e_header flags. See the FIXME and comment above in
900  // the constructor for a full rundown on this.
901  unsigned EFlags = MCA.getELFHeaderEFlags();
902 
903  // ABI
904  // N64 does not require any ABI bits.
905  if (getABI().IsO32())
906  EFlags |= ELF::EF_MIPS_ABI_O32;
907  else if (getABI().IsN32())
908  EFlags |= ELF::EF_MIPS_ABI2;
909 
910  if (Features[Mips::FeatureGP64Bit]) {
911  if (getABI().IsO32())
912  EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
913  } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
914  EFlags |= ELF::EF_MIPS_32BITMODE;
915 
916  // -mplt is not implemented but we should act as if it was
917  // given.
918  if (!Features[Mips::FeatureNoABICalls])
919  EFlags |= ELF::EF_MIPS_CPIC;
920 
921  if (Pic)
923 
924  MCA.setELFHeaderEFlags(EFlags);
925 
926  // Emit all the option records.
927  // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
928  // .reginfo.
929  MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
930  MEF.EmitMipsOptionRecords();
931 
933 }
934 
936  auto *Symbol = cast<MCSymbolELF>(S);
937  // If on rhs is micromips symbol then mark Symbol as microMips.
938  if (Value->getKind() != MCExpr::SymbolRef)
939  return;
940  const auto &RhsSym = cast<MCSymbolELF>(
941  static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
942 
943  if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
944  return;
945 
946  Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
947 }
948 
950  return static_cast<MCELFStreamer &>(Streamer);
951 }
952 
954  MicroMipsEnabled = true;
956 }
957 
959  MicroMipsEnabled = false;
961 }
962 
965  unsigned Flags = MCA.getELFHeaderEFlags();
966  Flags |= ELF::EF_MIPS_MICROMIPS;
967  MCA.setELFHeaderEFlags(Flags);
968 }
969 
972  unsigned Flags = MCA.getELFHeaderEFlags();
973  Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
974  MCA.setELFHeaderEFlags(Flags);
976 }
977 
980  unsigned Flags = MCA.getELFHeaderEFlags();
981  Flags |= ELF::EF_MIPS_NOREORDER;
982  MCA.setELFHeaderEFlags(Flags);
984 }
985 
988  MCContext &Context = MCA.getContext();
989  MCStreamer &OS = getStreamer();
990 
991  MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS, 0);
992 
993  MCSymbol *Sym = Context.getOrCreateSymbol(Name);
994  const MCSymbolRefExpr *ExprRef =
996 
997  MCA.registerSection(*Sec);
998  Sec->setAlignment(4);
999 
1000  OS.PushSection();
1001 
1002  OS.SwitchSection(Sec);
1003 
1004  OS.EmitValueImpl(ExprRef, 4);
1005 
1006  OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
1007  OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
1008 
1009  OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
1010  OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
1011 
1012  OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
1013  OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
1014  OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
1015 
1016  // The .end directive marks the end of a procedure. Invalidate
1017  // the information gathered up until this point.
1018  GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
1019 
1020  OS.PopSection();
1021 
1022  // .end also implicitly sets the size.
1023  MCSymbol *CurPCSym = Context.createTempSymbol();
1024  OS.EmitLabel(CurPCSym);
1027  ExprRef, Context);
1028 
1029  // The ELFObjectWriter can determine the absolute size as it has access to
1030  // the layout information of the assembly file, so a size expression rather
1031  // than an absolute value is ok here.
1032  static_cast<MCSymbolELF *>(Sym)->setSize(Size);
1033 }
1034 
1036  GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
1037 
1038  // .ent also acts like an implicit '.type symbol, STT_FUNC'
1039  static_cast<const MCSymbolELF &>(Symbol).setType(ELF::STT_FUNC);
1040 }
1041 
1044  unsigned Flags = MCA.getELFHeaderEFlags();
1046  MCA.setELFHeaderEFlags(Flags);
1047 }
1048 
1051  unsigned Flags = MCA.getELFHeaderEFlags();
1052  Flags |= ELF::EF_MIPS_NAN2008;
1053  MCA.setELFHeaderEFlags(Flags);
1054 }
1055 
1058  unsigned Flags = MCA.getELFHeaderEFlags();
1059  Flags &= ~ELF::EF_MIPS_NAN2008;
1060  MCA.setELFHeaderEFlags(Flags);
1061 }
1062 
1065  unsigned Flags = MCA.getELFHeaderEFlags();
1066  // This option overrides other PIC options like -KPIC.
1067  Pic = false;
1068  Flags &= ~ELF::EF_MIPS_PIC;
1069  MCA.setELFHeaderEFlags(Flags);
1070 }
1071 
1074  unsigned Flags = MCA.getELFHeaderEFlags();
1075  Pic = true;
1076  // NOTE: We are following the GAS behaviour here which means the directive
1077  // 'pic2' also sets the CPIC bit in the ELF header. This is different from
1078  // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
1079  // EF_MIPS_CPIC to be mutually exclusive.
1081  MCA.setELFHeaderEFlags(Flags);
1082 }
1083 
1086  MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
1088 }
1089 
1090 void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
1091  unsigned ReturnReg_) {
1093  const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
1094 
1095  FrameInfoSet = true;
1096  FrameReg = RegInfo->getEncodingValue(StackReg);
1097  FrameOffset = StackSize;
1098  ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
1099 }
1100 
1101 void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
1102  int CPUTopSavedRegOff) {
1103  GPRInfoSet = true;
1104  GPRBitMask = CPUBitmask;
1105  GPROffset = CPUTopSavedRegOff;
1106 }
1107 
1108 void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
1109  int FPUTopSavedRegOff) {
1110  FPRInfoSet = true;
1111  FPRBitMask = FPUBitmask;
1112  FPROffset = FPUTopSavedRegOff;
1113 }
1114 
1116  // .cpload $reg
1117  // This directive expands to:
1118  // lui $gp, %hi(_gp_disp)
1119  // addui $gp, $gp, %lo(_gp_disp)
1120  // addu $gp, $gp, $reg
1121  // when support for position independent code is enabled.
1122  if (!Pic || (getABI().IsN32() || getABI().IsN64()))
1123  return;
1124 
1125  // There's a GNU extension controlled by -mno-shared that allows
1126  // locally-binding symbols to be accessed using absolute addresses.
1127  // This is currently not supported. When supported -mno-shared makes
1128  // .cpload expand to:
1129  // lui $gp, %hi(__gnu_local_gp)
1130  // addiu $gp, $gp, %lo(__gnu_local_gp)
1131 
1132  StringRef SymName("_gp_disp");
1134  MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
1135  MCA.registerSymbol(*GP_Disp);
1136 
1137  MCInst TmpInst;
1138  TmpInst.setOpcode(Mips::LUi);
1139  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1140  const MCExpr *HiSym = MipsMCExpr::create(
1143  MCA.getContext()),
1144  MCA.getContext());
1145  TmpInst.addOperand(MCOperand::createExpr(HiSym));
1146  getStreamer().EmitInstruction(TmpInst, STI);
1147 
1148  TmpInst.clear();
1149 
1150  TmpInst.setOpcode(Mips::ADDiu);
1151  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1152  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1153  const MCExpr *LoSym = MipsMCExpr::create(
1156  MCA.getContext()),
1157  MCA.getContext());
1158  TmpInst.addOperand(MCOperand::createExpr(LoSym));
1159  getStreamer().EmitInstruction(TmpInst, STI);
1160 
1161  TmpInst.clear();
1162 
1163  TmpInst.setOpcode(Mips::ADDu);
1164  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1165  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1166  TmpInst.addOperand(MCOperand::createReg(RegNo));
1167  getStreamer().EmitInstruction(TmpInst, STI);
1168 
1170 }
1171 
1173  int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc,
1174  const MCSubtargetInfo *STI) {
1175  MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
1176  // .cprestore offset
1177  // When PIC mode is enabled and the O32 ABI is used, this directive expands
1178  // to:
1179  // sw $gp, offset($sp)
1180  // and adds a corresponding LW after every JAL.
1181 
1182  // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it
1183  // is used in non-PIC mode.
1184  if (!Pic || (getABI().IsN32() || getABI().IsN64()))
1185  return true;
1186 
1187  // Store the $gp on the stack.
1188  emitStoreWithImmOffset(Mips::SW, Mips::GP, Mips::SP, Offset, GetATReg, IDLoc,
1189  STI);
1190  return true;
1191 }
1192 
1194  int RegOrOffset,
1195  const MCSymbol &Sym,
1196  bool IsReg) {
1197  // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
1198  if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
1199  return;
1200 
1202 
1204  MCInst Inst;
1205 
1206  // Either store the old $gp in a register or on the stack
1207  if (IsReg) {
1208  // move $save, $gpreg
1209  emitRRR(Mips::OR64, RegOrOffset, Mips::GP, Mips::ZERO, SMLoc(), &STI);
1210  } else {
1211  // sd $gpreg, offset($sp)
1212  emitRRI(Mips::SD, Mips::GP, Mips::SP, RegOrOffset, SMLoc(), &STI);
1213  }
1214 
1215  if (getABI().IsN32()) {
1216  MCSymbol *GPSym = MCA.getContext().getOrCreateSymbol("__gnu_local_gp");
1217  const MipsMCExpr *HiExpr = MipsMCExpr::create(
1219  MCA.getContext());
1220  const MipsMCExpr *LoExpr = MipsMCExpr::create(
1222  MCA.getContext());
1223 
1224  // lui $gp, %hi(__gnu_local_gp)
1225  emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI);
1226 
1227  // addiu $gp, $gp, %lo(__gnu_local_gp)
1228  emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr),
1229  SMLoc(), &STI);
1230 
1231  return;
1232  }
1233 
1234  const MipsMCExpr *HiExpr = MipsMCExpr::createGpOff(
1236  MCA.getContext());
1237  const MipsMCExpr *LoExpr = MipsMCExpr::createGpOff(
1239  MCA.getContext());
1240 
1241  // lui $gp, %hi(%neg(%gp_rel(funcSym)))
1242  emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI);
1243 
1244  // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
1245  emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr),
1246  SMLoc(), &STI);
1247 
1248  // daddu $gp, $gp, $funcreg
1249  emitRRR(Mips::DADDu, Mips::GP, Mips::GP, RegNo, SMLoc(), &STI);
1250 }
1251 
1253  bool SaveLocationIsRegister) {
1254  // Only N32 and N64 emit anything for .cpreturn iff PIC is set.
1255  if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
1256  return;
1257 
1258  MCInst Inst;
1259  // Either restore the old $gp from a register or on the stack
1260  if (SaveLocationIsRegister) {
1261  Inst.setOpcode(Mips::OR);
1262  Inst.addOperand(MCOperand::createReg(Mips::GP));
1263  Inst.addOperand(MCOperand::createReg(SaveLocation));
1264  Inst.addOperand(MCOperand::createReg(Mips::ZERO));
1265  } else {
1266  Inst.setOpcode(Mips::LD);
1267  Inst.addOperand(MCOperand::createReg(Mips::GP));
1268  Inst.addOperand(MCOperand::createReg(Mips::SP));
1269  Inst.addOperand(MCOperand::createImm(SaveLocation));
1270  }
1271  getStreamer().EmitInstruction(Inst, STI);
1272 
1274 }
1275 
1278  MCContext &Context = MCA.getContext();
1279  MCStreamer &OS = getStreamer();
1280  MCSectionELF *Sec = Context.getELFSection(
1281  ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
1282  MCA.registerSection(*Sec);
1283  Sec->setAlignment(8);
1284  OS.SwitchSection(Sec);
1285 
1286  OS << ABIFlagsSection;
1287 }
void emitDirectiveEnd(StringRef Name) override
virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff)
void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override
void setELFHeaderEFlags(unsigned Flags)
Definition: MCAssembler.h:256
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
virtual void emitDirectiveModuleGINV()
void emitDirectiveModuleSoftFloat() override
void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg) override
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVMContext & Context
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
virtual void emitDirectiveOptionPic2()
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void clear()
Definition: MCInst.h:191
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void emitDirectiveSetNoMicroMips() override
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit, const MCSubtargetInfo *STI)
Target specific streamer interface.
Definition: MCStreamer.h:84
void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister) override
void setAlignment(unsigned Value)
Definition: MCSection.h:122
const FeatureBitset Features
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
virtual void emitDirectiveSetNoReorder()
virtual void emitDirectiveModuleHardFloat()
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:368
virtual void emitDirectiveModuleNoGINV()
void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:306
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
block Block Frequency true
virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI) override
Emit a .cprestore directive.
void emitDirectiveCpLoad(unsigned RegNo) override
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:956
const Triple & getTargetTriple() const
unsigned getAlignment() const
Definition: MCSection.h:121
virtual void emitDirectiveSetMips32R3()
const MipsABIInfo & getABI() const
MCContext & getContext() const
Definition: MCAssembler.h:285
virtual void emitDirectiveSetMicroMips()
virtual void emitDirectiveSetMips3()
amdgpu Simplify well known AMD library false Value Value const Twine & Name
void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) override
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, int64_t Offset, unsigned TmpReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an immediate offset.
const FeatureBitset & getFeatureBits() const
virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg)
virtual void emitDirectiveSetMips0()
virtual void emitDirectiveSetSoftFloat()
virtual void emitDirectiveSetNoMacro()
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool registerSection(MCSection &Section)
virtual void emitDirectiveEnd(StringRef Name)
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
MCSection * getBSSSection() const
MCSection * getDataSection() const
virtual void emitDirectiveSetMips32R6()
void createPendingLabelRelocs()
Mark labels as microMIPS, if necessary for the subtarget.
void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override
virtual void emitDirectiveSetMips1()
virtual void emitDirectiveModuleOddSPReg()
Context object for machine code objects.
Definition: MCContext.h:63
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveModuleSoftFloat()
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:546
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:290
MipsABIFlagsSection ABIFlagsSection
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
void emitLabel(MCSymbol *Symbol) override
virtual void emitDirectiveSetOddSPReg()
virtual void emitDirectiveSetMips64R2()
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:124
virtual void emitDirectiveSetNoOddSPReg()
void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg) override
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:337
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:423
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
virtual void emitDirectiveSetMips4()
Container class for subtarget features.
static const MipsMCExpr * createGpOff(MipsExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: MipsMCExpr.cpp:33
static bool hasShortDelaySlot(MCInst &Inst)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
virtual void emitDirectiveSetNoMicroMips()
StringRef getFpABIString(FpABIKind Value)
virtual void emitDirectiveModuleVirt()
virtual void emitDirectiveSetMips16()
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
static MipsABIInfo O32()
Definition: MipsABIInfo.h:35
MCAssembler & getAssembler()
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:31
virtual void emitDirectiveSetMacro()
void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister) override
void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveCpLoad(unsigned RegNo)
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
virtual void emitDirectiveSetArch(StringRef Arch)
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff)
unsigned getELFHeaderEFlags() const
ELF e_header flags.
Definition: MCAssembler.h:255
virtual void emitDirectiveSetNoCRC()
virtual void emitDirectiveSetMips32R5()
virtual void emitDirectiveSetMips32R2()
void setLoc(SMLoc loc)
Definition: MCInst.h:179
void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an symbol offset.
virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value)
void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveAbiCalls()
void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override
virtual void emitDirectiveSetMips64R6()
void emitDirectiveEnt(const MCSymbol &Symbol) override
MCStreamer & getStreamer()
Definition: MCStreamer.h:92
void emitDirectiveEnt(const MCSymbol &Symbol) override
virtual void emitDirectiveModuleNoVirt()
void setOpcode(unsigned Op)
Definition: MCInst.h:173
virtual void emitDirectiveOptionPic0()
void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
ExprKind getKind() const
Definition: MCExpr.h:73
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
virtual void emitDirectiveSetNoGINV()
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
MCStreamer & Streamer
Definition: MCStreamer.h:86
virtual void emitDirectiveSetNoMips16()
void emitDirectiveSetNoOddSPReg() override
void emitDirectiveSetAtWithArg(unsigned RegNo) override
void emitDirectiveEnd(StringRef Name) override
MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
void EmitMipsOptionRecords()
Emits all the option records stored up until the point it&#39;s called.
virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, const MCSymbol &Sym, bool IsReg)
static const MipsMCExpr * create(MipsExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: MipsMCExpr.cpp:28
virtual void emitDirectiveSetNoVirt()
void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an offset.
virtual void emitDirectiveSetMips64R3()
virtual void emitDirectiveSetMips64R5()
void emitDirectiveCpLoad(unsigned RegNo) override
virtual void emitDirectiveEnt(const MCSymbol &Symbol)
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
virtual void emitDirectiveSetHardFloat()
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
virtual void emitDirectiveSetMips64()
virtual bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetMips5()
virtual void emitDirectiveSetMips2()
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
References to labels and assigned expressions.
Definition: MCExpr.h:41
uint32_t Size
Definition: Profile.cpp:47
void emitDirectiveSetNoMicroMips() override
void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) override
void emitDirectiveSetArch(StringRef Arch) override
void emitDirectiveModuleOddSPReg() override
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
LLVM_NODISCARD std::string lower() const
Definition: StringRef.cpp:108
void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
MCSection * getTextSection() const
bool PopSection()
Restore the current and previous section from the section stack.
Definition: MCStreamer.h:377
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389
virtual void emitDirectiveSetReorder()
static const char * getRegisterName(unsigned RegNo)
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:295
LLVM Value Representation.
Definition: Value.h:73
virtual void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister)
llvm::Optional< MipsABIInfo > ABI
virtual void emitDirectiveNaNLegacy()
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:347
void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
virtual void emitDirectiveSetMips32()
virtual void emitDirectiveSetNoMsa()
void addOperand(const MCOperand &Op)
Definition: MCInst.h:186
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual void emitDirectiveModuleNoCRC()
bool isPositionIndependent() const
static void printHex32(unsigned Value, raw_ostream &OS)
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
bool emitDirectiveCpRestore(int Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI) override
virtual void emitDirectiveSetAtWithArg(unsigned RegNo)
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123
static MipsABIInfo N64()
Definition: MipsABIInfo.h:37
void emitDirectiveModuleHardFloat() override
void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an symbol offset.
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Emit the given Instruction into the current section.