LLVM  7.0.0
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  emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
252 }
253 
254 /// Emit the $gp restore operation for .cprestore.
256  const MCSubtargetInfo *STI) {
257  emitLoadWithImmOffset(Mips::LW, Mips::GP, Mips::SP, Offset, Mips::GP, IDLoc,
258  STI);
259 }
260 
261 /// Emit a store instruction with an immediate offset.
263  unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset,
264  function_ref<unsigned()> GetATReg, SMLoc IDLoc,
265  const MCSubtargetInfo *STI) {
266  if (isInt<16>(Offset)) {
267  emitRRI(Opcode, SrcReg, BaseReg, Offset, IDLoc, STI);
268  return;
269  }
270 
271  // sw $8, offset($8) => lui $at, %hi(offset)
272  // add $at, $at, $8
273  // sw $8, %lo(offset)($at)
274 
275  unsigned ATReg = GetATReg();
276  if (!ATReg)
277  return;
278 
279  unsigned LoOffset = Offset & 0x0000ffff;
280  unsigned HiOffset = (Offset & 0xffff0000) >> 16;
281 
282  // If msb of LoOffset is 1(negative number) we must increment HiOffset
283  // to account for the sign-extension of the low part.
284  if (LoOffset & 0x8000)
285  HiOffset++;
286 
287  // Generate the base address in ATReg.
288  emitRI(Mips::LUi, ATReg, HiOffset, IDLoc, STI);
289  if (BaseReg != Mips::ZERO)
290  emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI);
291  // Emit the store with the adjusted base and offset.
292  emitRRI(Opcode, SrcReg, ATReg, LoOffset, IDLoc, STI);
293 }
294 
295 /// Emit a store instruction with an symbol offset. Symbols are assumed to be
296 /// out of range for a simm16 will be expanded to appropriate instructions.
298  unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand,
299  MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
300  const MCSubtargetInfo *STI) {
301  // sw $8, sym => lui $at, %hi(sym)
302  // sw $8, %lo(sym)($at)
303 
304  // Generate the base address in ATReg.
305  emitRX(Mips::LUi, ATReg, HiOperand, IDLoc, STI);
306  if (BaseReg != Mips::ZERO)
307  emitRRR(Mips::ADDu, ATReg, ATReg, BaseReg, IDLoc, STI);
308  // Emit the store with the adjusted base and offset.
309  emitRRX(Opcode, SrcReg, ATReg, LoOperand, IDLoc, STI);
310 }
311 
312 /// Emit a load instruction with an immediate offset. DstReg and TmpReg are
313 /// permitted to be the same register iff DstReg is distinct from BaseReg and
314 /// DstReg is a GPR. It is the callers responsibility to identify such cases
315 /// and pass the appropriate register in TmpReg.
316 void MipsTargetStreamer::emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg,
317  unsigned BaseReg, int64_t Offset,
318  unsigned TmpReg, SMLoc IDLoc,
319  const MCSubtargetInfo *STI) {
320  if (isInt<16>(Offset)) {
321  emitRRI(Opcode, DstReg, BaseReg, Offset, IDLoc, STI);
322  return;
323  }
324 
325  // 1) lw $8, offset($9) => lui $8, %hi(offset)
326  // add $8, $8, $9
327  // lw $8, %lo(offset)($9)
328  // 2) lw $8, offset($8) => lui $at, %hi(offset)
329  // add $at, $at, $8
330  // lw $8, %lo(offset)($at)
331 
332  unsigned LoOffset = Offset & 0x0000ffff;
333  unsigned HiOffset = (Offset & 0xffff0000) >> 16;
334 
335  // If msb of LoOffset is 1(negative number) we must increment HiOffset
336  // to account for the sign-extension of the low part.
337  if (LoOffset & 0x8000)
338  HiOffset++;
339 
340  // Generate the base address in TmpReg.
341  emitRI(Mips::LUi, TmpReg, HiOffset, IDLoc, STI);
342  if (BaseReg != Mips::ZERO)
343  emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
344  // Emit the load with the adjusted base and offset.
345  emitRRI(Opcode, DstReg, TmpReg, LoOffset, IDLoc, STI);
346 }
347 
348 /// Emit a load instruction with an symbol offset. Symbols are assumed to be
349 /// out of range for a simm16 will be expanded to appropriate instructions.
350 /// DstReg and TmpReg are permitted to be the same register iff DstReg is a
351 /// GPR. It is the callers responsibility to identify such cases and pass the
352 /// appropriate register in TmpReg.
353 void MipsTargetStreamer::emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg,
354  unsigned BaseReg,
355  MCOperand &HiOperand,
356  MCOperand &LoOperand,
357  unsigned TmpReg, SMLoc IDLoc,
358  const MCSubtargetInfo *STI) {
359  // 1) lw $8, sym => lui $8, %hi(sym)
360  // lw $8, %lo(sym)($8)
361  // 2) ldc1 $f0, sym => lui $at, %hi(sym)
362  // ldc1 $f0, %lo(sym)($at)
363 
364  // Generate the base address in TmpReg.
365  emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
366  if (BaseReg != Mips::ZERO)
367  emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
368  // Emit the load with the adjusted base and offset.
369  emitRRX(Opcode, DstReg, TmpReg, LoOperand, IDLoc, STI);
370 }
371 
374  : MipsTargetStreamer(S), OS(OS) {}
375 
377  OS << "\t.set\tmicromips\n";
379 }
380 
382  OS << "\t.set\tnomicromips\n";
384 }
385 
387  OS << "\t.set\tmips16\n";
389 }
390 
392  OS << "\t.set\tnomips16\n";
394 }
395 
397  OS << "\t.set\treorder\n";
399 }
400 
402  OS << "\t.set\tnoreorder\n";
404 }
405 
407  OS << "\t.set\tmacro\n";
409 }
410 
412  OS << "\t.set\tnomacro\n";
414 }
415 
417  OS << "\t.set\tmsa\n";
419 }
420 
422  OS << "\t.set\tnomsa\n";
424 }
425 
427  OS << "\t.set\tmt\n";
429 }
430 
432  OS << "\t.set\tnomt\n";
434 }
435 
437  OS << "\t.set\tcrc\n";
439 }
440 
442  OS << "\t.set\tnocrc\n";
444 }
445 
447  OS << "\t.set\tvirt\n";
449 }
450 
452  OS << "\t.set\tnovirt\n";
454 }
455 
457  OS << "\t.set\tginv\n";
459 }
460 
462  OS << "\t.set\tnoginv\n";
464 }
465 
467  OS << "\t.set\tat\n";
469 }
470 
472  OS << "\t.set\tat=$" << Twine(RegNo) << "\n";
474 }
475 
477  OS << "\t.set\tnoat\n";
479 }
480 
482  OS << "\t.end\t" << Name << '\n';
483 }
484 
486  OS << "\t.ent\t" << Symbol.getName() << '\n';
487 }
488 
489 void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
490 
491 void MipsTargetAsmStreamer::emitDirectiveNaN2008() { OS << "\t.nan\t2008\n"; }
492 
494  OS << "\t.nan\tlegacy\n";
495 }
496 
498  OS << "\t.option\tpic0\n";
499 }
500 
502  OS << "\t.option\tpic2\n";
503 }
504 
507  OS << "\t.insn\n";
508 }
509 
510 void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
511  unsigned ReturnReg) {
512  OS << "\t.frame\t$"
513  << StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
514  << StackSize << ",$"
515  << StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower() << '\n';
516 }
517 
519  OS << "\t.set arch=" << Arch << "\n";
521 }
522 
524  OS << "\t.set\tmips0\n";
526 }
527 
529  OS << "\t.set\tmips1\n";
531 }
532 
534  OS << "\t.set\tmips2\n";
536 }
537 
539  OS << "\t.set\tmips3\n";
541 }
542 
544  OS << "\t.set\tmips4\n";
546 }
547 
549  OS << "\t.set\tmips5\n";
551 }
552 
554  OS << "\t.set\tmips32\n";
556 }
557 
559  OS << "\t.set\tmips32r2\n";
561 }
562 
564  OS << "\t.set\tmips32r3\n";
566 }
567 
569  OS << "\t.set\tmips32r5\n";
571 }
572 
574  OS << "\t.set\tmips32r6\n";
576 }
577 
579  OS << "\t.set\tmips64\n";
581 }
582 
584  OS << "\t.set\tmips64r2\n";
586 }
587 
589  OS << "\t.set\tmips64r3\n";
591 }
592 
594  OS << "\t.set\tmips64r5\n";
596 }
597 
599  OS << "\t.set\tmips64r6\n";
601 }
602 
604  OS << "\t.set\tdsp\n";
606 }
607 
609  OS << "\t.set\tdspr2\n";
611 }
612 
614  OS << "\t.set\tnodsp\n";
616 }
617 
619  OS << "\t.set\tpop\n";
621 }
622 
624  OS << "\t.set\tpush\n";
626 }
627 
629  OS << "\t.set\tsoftfloat\n";
631 }
632 
634  OS << "\t.set\thardfloat\n";
636 }
637 
638 // Print a 32 bit hex number with all numbers.
639 static void printHex32(unsigned Value, raw_ostream &OS) {
640  OS << "0x";
641  for (int i = 7; i >= 0; i--)
642  OS.write_hex((Value & (0xF << (i * 4))) >> (i * 4));
643 }
644 
645 void MipsTargetAsmStreamer::emitMask(unsigned CPUBitmask,
646  int CPUTopSavedRegOff) {
647  OS << "\t.mask \t";
648  printHex32(CPUBitmask, OS);
649  OS << ',' << CPUTopSavedRegOff << '\n';
650 }
651 
652 void MipsTargetAsmStreamer::emitFMask(unsigned FPUBitmask,
653  int FPUTopSavedRegOff) {
654  OS << "\t.fmask\t";
655  printHex32(FPUBitmask, OS);
656  OS << "," << FPUTopSavedRegOff << '\n';
657 }
658 
660  OS << "\t.cpload\t$"
661  << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << "\n";
663 }
664 
666  int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc,
667  const MCSubtargetInfo *STI) {
668  MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
669  OS << "\t.cprestore\t" << Offset << "\n";
670  return true;
671 }
672 
674  int RegOrOffset,
675  const MCSymbol &Sym,
676  bool IsReg) {
677  OS << "\t.cpsetup\t$"
678  << StringRef(MipsInstPrinter::getRegisterName(RegNo)).lower() << ", ";
679 
680  if (IsReg)
681  OS << "$"
683  else
684  OS << RegOrOffset;
685 
686  OS << ", ";
687 
688  OS << Sym.getName();
690 }
691 
693  bool SaveLocationIsRegister) {
694  OS << "\t.cpreturn";
696 }
697 
699  OS << "\t.module\tfp=";
701 }
702 
706 
707  OS << "\t.set\tfp=";
708  OS << ABIFlagsSection.getFpABIString(Value) << "\n";
709 }
710 
713 
714  OS << "\t.module\t" << (ABIFlagsSection.OddSPReg ? "" : "no") << "oddspreg\n";
715 }
716 
719  OS << "\t.set\toddspreg\n";
720 }
721 
724  OS << "\t.set\tnooddspreg\n";
725 }
726 
728  OS << "\t.module\tsoftfloat\n";
729 }
730 
732  OS << "\t.module\thardfloat\n";
733 }
734 
736  OS << "\t.module\tmt\n";
737 }
738 
740  OS << "\t.module\tcrc\n";
741 }
742 
744  OS << "\t.module\tnocrc\n";
745 }
746 
748  OS << "\t.module\tvirt\n";
749 }
750 
752  OS << "\t.module\tnovirt\n";
753 }
754 
756  OS << "\t.module\tginv\n";
757 }
758 
760  OS << "\t.module\tnoginv\n";
761 }
762 
763 // This part is for ELF object output.
765  const MCSubtargetInfo &STI)
766  : MipsTargetStreamer(S), MicroMipsEnabled(false), STI(STI) {
768 
769  // It's possible that MCObjectFileInfo isn't fully initialized at this point
770  // due to an initialization order problem where LLVMTargetMachine creates the
771  // target streamer before TargetLoweringObjectFile calls
772  // InitializeMCObjectFileInfo. There doesn't seem to be a single place that
773  // covers all cases so this statement covers most cases and direct object
774  // emission must call setPic() once MCObjectFileInfo has been initialized. The
775  // cases we don't handle here are covered by MipsAsmPrinter.
777 
778  const FeatureBitset &Features = STI.getFeatureBits();
779 
780  // Set the header flags that we can in the constructor.
781  // FIXME: This is a fairly terrible hack. We set the rest
782  // of these in the destructor. The problem here is two-fold:
783  //
784  // a: Some of the eflags can be set/reset by directives.
785  // b: There aren't any usage paths that initialize the ABI
786  // pointer until after we initialize either an assembler
787  // or the target machine.
788  // We can fix this by making the target streamer construct
789  // the ABI, but this is fraught with wide ranging dependency
790  // issues as well.
791  unsigned EFlags = MCA.getELFHeaderEFlags();
792 
793  // FIXME: Fix a dependency issue by instantiating the ABI object to some
794  // default based off the triple. The triple doesn't describe the target
795  // fully, but any external user of the API that uses the MCTargetStreamer
796  // would otherwise crash on assertion failure.
797 
798  ABI = MipsABIInfo(
799  STI.getTargetTriple().getArch() == Triple::ArchType::mipsel ||
800  STI.getTargetTriple().getArch() == Triple::ArchType::mips
801  ? MipsABIInfo::O32()
802  : MipsABIInfo::N64());
803 
804  // Architecture
805  if (Features[Mips::FeatureMips64r6])
806  EFlags |= ELF::EF_MIPS_ARCH_64R6;
807  else if (Features[Mips::FeatureMips64r2] ||
808  Features[Mips::FeatureMips64r3] ||
809  Features[Mips::FeatureMips64r5])
810  EFlags |= ELF::EF_MIPS_ARCH_64R2;
811  else if (Features[Mips::FeatureMips64])
812  EFlags |= ELF::EF_MIPS_ARCH_64;
813  else if (Features[Mips::FeatureMips5])
814  EFlags |= ELF::EF_MIPS_ARCH_5;
815  else if (Features[Mips::FeatureMips4])
816  EFlags |= ELF::EF_MIPS_ARCH_4;
817  else if (Features[Mips::FeatureMips3])
818  EFlags |= ELF::EF_MIPS_ARCH_3;
819  else if (Features[Mips::FeatureMips32r6])
820  EFlags |= ELF::EF_MIPS_ARCH_32R6;
821  else if (Features[Mips::FeatureMips32r2] ||
822  Features[Mips::FeatureMips32r3] ||
823  Features[Mips::FeatureMips32r5])
824  EFlags |= ELF::EF_MIPS_ARCH_32R2;
825  else if (Features[Mips::FeatureMips32])
826  EFlags |= ELF::EF_MIPS_ARCH_32;
827  else if (Features[Mips::FeatureMips2])
828  EFlags |= ELF::EF_MIPS_ARCH_2;
829  else
830  EFlags |= ELF::EF_MIPS_ARCH_1;
831 
832  // Machine
833  if (Features[Mips::FeatureCnMips])
834  EFlags |= ELF::EF_MIPS_MACH_OCTEON;
835 
836  // Other options.
837  if (Features[Mips::FeatureNaN2008])
838  EFlags |= ELF::EF_MIPS_NAN2008;
839 
840  MCA.setELFHeaderEFlags(EFlags);
841 }
842 
844  auto *Symbol = cast<MCSymbolELF>(S);
846  uint8_t Type = Symbol->getType();
847  if (Type != ELF::STT_FUNC)
848  return;
849 
850  if (isMicroMipsEnabled())
851  Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
852 }
853 
856  const MCObjectFileInfo &OFI = *MCA.getContext().getObjectFileInfo();
857 
858  // .bss, .text and .data are always at least 16-byte aligned.
859  MCSection &TextSection = *OFI.getTextSection();
860  MCA.registerSection(TextSection);
861  MCSection &DataSection = *OFI.getDataSection();
862  MCA.registerSection(DataSection);
863  MCSection &BSSSection = *OFI.getBSSSection();
864  MCA.registerSection(BSSSection);
865 
866  TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
867  DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
868  BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
869 
870  if (RoundSectionSizes) {
871  // Make sections sizes a multiple of the alignment. This is useful for
872  // verifying the output of IAS against the output of other assemblers but
873  // it's not necessary to produce a correct object and increases section
874  // size.
875  MCStreamer &OS = getStreamer();
876  for (MCSection &S : MCA) {
877  MCSectionELF &Section = static_cast<MCSectionELF &>(S);
878 
879  unsigned Alignment = Section.getAlignment();
880  if (Alignment) {
881  OS.SwitchSection(&Section);
882  if (Section.UseCodeAlign())
883  OS.EmitCodeAlignment(Alignment, Alignment);
884  else
885  OS.EmitValueToAlignment(Alignment, 0, 1, Alignment);
886  }
887  }
888  }
889 
890  const FeatureBitset &Features = STI.getFeatureBits();
891 
892  // Update e_header flags. See the FIXME and comment above in
893  // the constructor for a full rundown on this.
894  unsigned EFlags = MCA.getELFHeaderEFlags();
895 
896  // ABI
897  // N64 does not require any ABI bits.
898  if (getABI().IsO32())
899  EFlags |= ELF::EF_MIPS_ABI_O32;
900  else if (getABI().IsN32())
901  EFlags |= ELF::EF_MIPS_ABI2;
902 
903  if (Features[Mips::FeatureGP64Bit]) {
904  if (getABI().IsO32())
905  EFlags |= ELF::EF_MIPS_32BITMODE; /* Compatibility Mode */
906  } else if (Features[Mips::FeatureMips64r2] || Features[Mips::FeatureMips64])
907  EFlags |= ELF::EF_MIPS_32BITMODE;
908 
909  // -mplt is not implemented but we should act as if it was
910  // given.
911  if (!Features[Mips::FeatureNoABICalls])
912  EFlags |= ELF::EF_MIPS_CPIC;
913 
914  if (Pic)
916 
917  MCA.setELFHeaderEFlags(EFlags);
918 
919  // Emit all the option records.
920  // At the moment we are only emitting .Mips.options (ODK_REGINFO) and
921  // .reginfo.
922  MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
923  MEF.EmitMipsOptionRecords();
924 
926 }
927 
929  auto *Symbol = cast<MCSymbolELF>(S);
930  // If on rhs is micromips symbol then mark Symbol as microMips.
931  if (Value->getKind() != MCExpr::SymbolRef)
932  return;
933  const auto &RhsSym = cast<MCSymbolELF>(
934  static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
935 
936  if (!(RhsSym.getOther() & ELF::STO_MIPS_MICROMIPS))
937  return;
938 
939  Symbol->setOther(ELF::STO_MIPS_MICROMIPS);
940 }
941 
943  return static_cast<MCELFStreamer &>(Streamer);
944 }
945 
947  MicroMipsEnabled = true;
949 }
950 
952  MicroMipsEnabled = false;
954 }
955 
958  unsigned Flags = MCA.getELFHeaderEFlags();
959  Flags |= ELF::EF_MIPS_MICROMIPS;
960  MCA.setELFHeaderEFlags(Flags);
961 }
962 
965  unsigned Flags = MCA.getELFHeaderEFlags();
966  Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
967  MCA.setELFHeaderEFlags(Flags);
969 }
970 
973  unsigned Flags = MCA.getELFHeaderEFlags();
974  Flags |= ELF::EF_MIPS_NOREORDER;
975  MCA.setELFHeaderEFlags(Flags);
977 }
978 
981  MCContext &Context = MCA.getContext();
982  MCStreamer &OS = getStreamer();
983 
984  MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS, 0);
985 
986  MCSymbol *Sym = Context.getOrCreateSymbol(Name);
987  const MCSymbolRefExpr *ExprRef =
989 
990  MCA.registerSection(*Sec);
991  Sec->setAlignment(4);
992 
993  OS.PushSection();
994 
995  OS.SwitchSection(Sec);
996 
997  OS.EmitValueImpl(ExprRef, 4);
998 
999  OS.EmitIntValue(GPRInfoSet ? GPRBitMask : 0, 4); // reg_mask
1000  OS.EmitIntValue(GPRInfoSet ? GPROffset : 0, 4); // reg_offset
1001 
1002  OS.EmitIntValue(FPRInfoSet ? FPRBitMask : 0, 4); // fpreg_mask
1003  OS.EmitIntValue(FPRInfoSet ? FPROffset : 0, 4); // fpreg_offset
1004 
1005  OS.EmitIntValue(FrameInfoSet ? FrameOffset : 0, 4); // frame_offset
1006  OS.EmitIntValue(FrameInfoSet ? FrameReg : 0, 4); // frame_reg
1007  OS.EmitIntValue(FrameInfoSet ? ReturnReg : 0, 4); // return_reg
1008 
1009  // The .end directive marks the end of a procedure. Invalidate
1010  // the information gathered up until this point.
1011  GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
1012 
1013  OS.PopSection();
1014 
1015  // .end also implicitly sets the size.
1016  MCSymbol *CurPCSym = Context.createTempSymbol();
1017  OS.EmitLabel(CurPCSym);
1020  ExprRef, Context);
1021 
1022  // The ELFObjectWriter can determine the absolute size as it has access to
1023  // the layout information of the assembly file, so a size expression rather
1024  // than an absolute value is ok here.
1025  static_cast<MCSymbolELF *>(Sym)->setSize(Size);
1026 }
1027 
1029  GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
1030 
1031  // .ent also acts like an implicit '.type symbol, STT_FUNC'
1032  static_cast<const MCSymbolELF &>(Symbol).setType(ELF::STT_FUNC);
1033 }
1034 
1037  unsigned Flags = MCA.getELFHeaderEFlags();
1039  MCA.setELFHeaderEFlags(Flags);
1040 }
1041 
1044  unsigned Flags = MCA.getELFHeaderEFlags();
1045  Flags |= ELF::EF_MIPS_NAN2008;
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  // This option overrides other PIC options like -KPIC.
1060  Pic = false;
1061  Flags &= ~ELF::EF_MIPS_PIC;
1062  MCA.setELFHeaderEFlags(Flags);
1063 }
1064 
1067  unsigned Flags = MCA.getELFHeaderEFlags();
1068  Pic = true;
1069  // NOTE: We are following the GAS behaviour here which means the directive
1070  // 'pic2' also sets the CPIC bit in the ELF header. This is different from
1071  // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and
1072  // EF_MIPS_CPIC to be mutually exclusive.
1074  MCA.setELFHeaderEFlags(Flags);
1075 }
1076 
1079  MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
1081 }
1082 
1083 void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
1084  unsigned ReturnReg_) {
1086  const MCRegisterInfo *RegInfo = Context.getRegisterInfo();
1087 
1088  FrameInfoSet = true;
1089  FrameReg = RegInfo->getEncodingValue(StackReg);
1090  FrameOffset = StackSize;
1091  ReturnReg = RegInfo->getEncodingValue(ReturnReg_);
1092 }
1093 
1094 void MipsTargetELFStreamer::emitMask(unsigned CPUBitmask,
1095  int CPUTopSavedRegOff) {
1096  GPRInfoSet = true;
1097  GPRBitMask = CPUBitmask;
1098  GPROffset = CPUTopSavedRegOff;
1099 }
1100 
1101 void MipsTargetELFStreamer::emitFMask(unsigned FPUBitmask,
1102  int FPUTopSavedRegOff) {
1103  FPRInfoSet = true;
1104  FPRBitMask = FPUBitmask;
1105  FPROffset = FPUTopSavedRegOff;
1106 }
1107 
1109  // .cpload $reg
1110  // This directive expands to:
1111  // lui $gp, %hi(_gp_disp)
1112  // addui $gp, $gp, %lo(_gp_disp)
1113  // addu $gp, $gp, $reg
1114  // when support for position independent code is enabled.
1115  if (!Pic || (getABI().IsN32() || getABI().IsN64()))
1116  return;
1117 
1118  // There's a GNU extension controlled by -mno-shared that allows
1119  // locally-binding symbols to be accessed using absolute addresses.
1120  // This is currently not supported. When supported -mno-shared makes
1121  // .cpload expand to:
1122  // lui $gp, %hi(__gnu_local_gp)
1123  // addiu $gp, $gp, %lo(__gnu_local_gp)
1124 
1125  StringRef SymName("_gp_disp");
1127  MCSymbol *GP_Disp = MCA.getContext().getOrCreateSymbol(SymName);
1128  MCA.registerSymbol(*GP_Disp);
1129 
1130  MCInst TmpInst;
1131  TmpInst.setOpcode(Mips::LUi);
1132  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1133  const MCExpr *HiSym = MipsMCExpr::create(
1136  MCA.getContext()),
1137  MCA.getContext());
1138  TmpInst.addOperand(MCOperand::createExpr(HiSym));
1139  getStreamer().EmitInstruction(TmpInst, STI);
1140 
1141  TmpInst.clear();
1142 
1143  TmpInst.setOpcode(Mips::ADDiu);
1144  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1145  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1146  const MCExpr *LoSym = MipsMCExpr::create(
1149  MCA.getContext()),
1150  MCA.getContext());
1151  TmpInst.addOperand(MCOperand::createExpr(LoSym));
1152  getStreamer().EmitInstruction(TmpInst, STI);
1153 
1154  TmpInst.clear();
1155 
1156  TmpInst.setOpcode(Mips::ADDu);
1157  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1158  TmpInst.addOperand(MCOperand::createReg(Mips::GP));
1159  TmpInst.addOperand(MCOperand::createReg(RegNo));
1160  getStreamer().EmitInstruction(TmpInst, STI);
1161 
1163 }
1164 
1166  int Offset, function_ref<unsigned()> GetATReg, SMLoc IDLoc,
1167  const MCSubtargetInfo *STI) {
1168  MipsTargetStreamer::emitDirectiveCpRestore(Offset, GetATReg, IDLoc, STI);
1169  // .cprestore offset
1170  // When PIC mode is enabled and the O32 ABI is used, this directive expands
1171  // to:
1172  // sw $gp, offset($sp)
1173  // and adds a corresponding LW after every JAL.
1174 
1175  // Note that .cprestore is ignored if used with the N32 and N64 ABIs or if it
1176  // is used in non-PIC mode.
1177  if (!Pic || (getABI().IsN32() || getABI().IsN64()))
1178  return true;
1179 
1180  // Store the $gp on the stack.
1181  emitStoreWithImmOffset(Mips::SW, Mips::GP, Mips::SP, Offset, GetATReg, IDLoc,
1182  STI);
1183  return true;
1184 }
1185 
1187  int RegOrOffset,
1188  const MCSymbol &Sym,
1189  bool IsReg) {
1190  // Only N32 and N64 emit anything for .cpsetup iff PIC is set.
1191  if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
1192  return;
1193 
1195 
1197  MCInst Inst;
1198 
1199  // Either store the old $gp in a register or on the stack
1200  if (IsReg) {
1201  // move $save, $gpreg
1202  emitRRR(Mips::OR64, RegOrOffset, Mips::GP, Mips::ZERO, SMLoc(), &STI);
1203  } else {
1204  // sd $gpreg, offset($sp)
1205  emitRRI(Mips::SD, Mips::GP, Mips::SP, RegOrOffset, SMLoc(), &STI);
1206  }
1207 
1208  if (getABI().IsN32()) {
1209  MCSymbol *GPSym = MCA.getContext().getOrCreateSymbol("__gnu_local_gp");
1210  const MipsMCExpr *HiExpr = MipsMCExpr::create(
1212  MCA.getContext());
1213  const MipsMCExpr *LoExpr = MipsMCExpr::create(
1215  MCA.getContext());
1216 
1217  // lui $gp, %hi(__gnu_local_gp)
1218  emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI);
1219 
1220  // addiu $gp, $gp, %lo(__gnu_local_gp)
1221  emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr),
1222  SMLoc(), &STI);
1223 
1224  return;
1225  }
1226 
1227  const MipsMCExpr *HiExpr = MipsMCExpr::createGpOff(
1229  MCA.getContext());
1230  const MipsMCExpr *LoExpr = MipsMCExpr::createGpOff(
1232  MCA.getContext());
1233 
1234  // lui $gp, %hi(%neg(%gp_rel(funcSym)))
1235  emitRX(Mips::LUi, Mips::GP, MCOperand::createExpr(HiExpr), SMLoc(), &STI);
1236 
1237  // addiu $gp, $gp, %lo(%neg(%gp_rel(funcSym)))
1238  emitRRX(Mips::ADDiu, Mips::GP, Mips::GP, MCOperand::createExpr(LoExpr),
1239  SMLoc(), &STI);
1240 
1241  // daddu $gp, $gp, $funcreg
1242  emitRRR(Mips::DADDu, Mips::GP, Mips::GP, RegNo, SMLoc(), &STI);
1243 }
1244 
1246  bool SaveLocationIsRegister) {
1247  // Only N32 and N64 emit anything for .cpreturn iff PIC is set.
1248  if (!Pic || !(getABI().IsN32() || getABI().IsN64()))
1249  return;
1250 
1251  MCInst Inst;
1252  // Either restore the old $gp from a register or on the stack
1253  if (SaveLocationIsRegister) {
1254  Inst.setOpcode(Mips::OR);
1255  Inst.addOperand(MCOperand::createReg(Mips::GP));
1256  Inst.addOperand(MCOperand::createReg(SaveLocation));
1257  Inst.addOperand(MCOperand::createReg(Mips::ZERO));
1258  } else {
1259  Inst.setOpcode(Mips::LD);
1260  Inst.addOperand(MCOperand::createReg(Mips::GP));
1261  Inst.addOperand(MCOperand::createReg(Mips::SP));
1262  Inst.addOperand(MCOperand::createImm(SaveLocation));
1263  }
1264  getStreamer().EmitInstruction(Inst, STI);
1265 
1267 }
1268 
1271  MCContext &Context = MCA.getContext();
1272  MCStreamer &OS = getStreamer();
1273  MCSectionELF *Sec = Context.getELFSection(
1274  ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
1275  MCA.registerSection(*Sec);
1276  Sec->setAlignment(8);
1277  OS.SwitchSection(Sec);
1278 
1279  OS << ABIFlagsSection;
1280 }
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:253
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:321
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:119
Compute iterated dominance frontiers using a linear time algorithm.
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:83
void emitDirectiveCpreturn(unsigned SaveLocation, bool SaveLocationIsRegister) override
void setAlignment(unsigned Value)
Definition: MCSection.h:118
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:106
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:359
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.
Definition: MCStreamer.cpp:973
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:909
const Triple & getTargetTriple() const
unsigned getAlignment() const
Definition: MCSection.h:117
virtual void emitDirectiveSetMips32R3()
const MipsABIInfo & getABI() const
MCContext & getContext() const
Definition: MCAssembler.h:278
virtual void emitDirectiveSetMicroMips()
virtual void emitDirectiveSetMips3()
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:544
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
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:112
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:410
Streaming machine code generation interface.
Definition: MCStreamer.h:183
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
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.
Definition: MCStreamer.cpp:993
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.
Definition: MCStreamer.cpp:981
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:252
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:91
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.
Definition: MCStreamer.cpp:984
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
MCStreamer & Streamer
Definition: MCStreamer.h:85
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
void emitDirectiveSetNoMicroMips() override
void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) override
static bool hasShortDelaySlot(unsigned Opcode)
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:368
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:393
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)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm::Optional< MipsABIInfo > ABI
const FeatureBitset Features
virtual void emitDirectiveNaNLegacy()
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:322
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.