LLVM  8.0.1
MipsAsmPrinter.cpp
Go to the documentation of this file.
1 //===- MipsAsmPrinter.cpp - Mips LLVM Assembly Printer --------------------===//
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 contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to GAS-format MIPS assembly language.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "MipsAsmPrinter.h"
21 #include "Mips.h"
22 #include "MipsMCInstLower.h"
23 #include "MipsMachineFunction.h"
24 #include "MipsSubtarget.h"
25 #include "MipsTargetMachine.h"
26 #include "MipsTargetStreamer.h"
27 #include "llvm/ADT/SmallString.h"
28 #include "llvm/ADT/StringRef.h"
29 #include "llvm/ADT/Triple.h"
30 #include "llvm/ADT/Twine.h"
31 #include "llvm/BinaryFormat/ELF.h"
41 #include "llvm/IR/Attributes.h"
42 #include "llvm/IR/BasicBlock.h"
43 #include "llvm/IR/DataLayout.h"
44 #include "llvm/IR/Function.h"
45 #include "llvm/IR/InlineAsm.h"
46 #include "llvm/IR/Instructions.h"
47 #include "llvm/MC/MCContext.h"
48 #include "llvm/MC/MCExpr.h"
49 #include "llvm/MC/MCInst.h"
50 #include "llvm/MC/MCInstBuilder.h"
52 #include "llvm/MC/MCSectionELF.h"
53 #include "llvm/MC/MCSymbol.h"
54 #include "llvm/MC/MCSymbolELF.h"
55 #include "llvm/Support/Casting.h"
60 #include <cassert>
61 #include <cstdint>
62 #include <map>
63 #include <memory>
64 #include <string>
65 #include <vector>
66 
67 using namespace llvm;
68 
69 #define DEBUG_TYPE "mips-asm-printer"
70 
72 
73 MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() const {
74  return static_cast<MipsTargetStreamer &>(*OutStreamer->getTargetStreamer());
75 }
76 
79 
81  if (Subtarget->inMips16Mode())
82  for (std::map<
83  const char *,
84  const Mips16HardFloatInfo::FuncSignature *>::const_iterator
85  it = MipsFI->StubsNeeded.begin();
86  it != MipsFI->StubsNeeded.end(); ++it) {
87  const char *Symbol = it->first;
88  const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
89  if (StubsNeeded.find(Symbol) == StubsNeeded.end())
90  StubsNeeded[Symbol] = Signature;
91  }
92  MCP = MF.getConstantPool();
93 
94  // In NaCl, all indirect jump targets must be aligned to bundle size.
95  if (Subtarget->isTargetNaCl())
96  NaClAlignIndirectJumpTargets(MF);
97 
99 
100  emitXRayTable();
101 
102  return true;
103 }
104 
105 bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
106  MCOp = MCInstLowering.LowerOperand(MO);
107  return MCOp.isValid();
108 }
109 
110 #include "MipsGenMCPseudoLowering.inc"
111 
112 // Lower PseudoReturn/PseudoIndirectBranch/PseudoIndirectBranch64 to JR, JR_MM,
113 // JALR, or JALR64 as appropriate for the target.
114 void MipsAsmPrinter::emitPseudoIndirectBranch(MCStreamer &OutStreamer,
115  const MachineInstr *MI) {
116  bool HasLinkReg = false;
117  bool InMicroMipsMode = Subtarget->inMicroMipsMode();
118  MCInst TmpInst0;
119 
120  if (Subtarget->hasMips64r6()) {
121  // MIPS64r6 should use (JALR64 ZERO_64, $rs)
122  TmpInst0.setOpcode(Mips::JALR64);
123  HasLinkReg = true;
124  } else if (Subtarget->hasMips32r6()) {
125  // MIPS32r6 should use (JALR ZERO, $rs)
126  if (InMicroMipsMode)
127  TmpInst0.setOpcode(Mips::JRC16_MMR6);
128  else {
129  TmpInst0.setOpcode(Mips::JALR);
130  HasLinkReg = true;
131  }
132  } else if (Subtarget->inMicroMipsMode())
133  // microMIPS should use (JR_MM $rs)
134  TmpInst0.setOpcode(Mips::JR_MM);
135  else {
136  // Everything else should use (JR $rs)
137  TmpInst0.setOpcode(Mips::JR);
138  }
139 
140  MCOperand MCOp;
141 
142  if (HasLinkReg) {
143  unsigned ZeroReg = Subtarget->isGP64bit() ? Mips::ZERO_64 : Mips::ZERO;
144  TmpInst0.addOperand(MCOperand::createReg(ZeroReg));
145  }
146 
147  lowerOperand(MI->getOperand(0), MCOp);
148  TmpInst0.addOperand(MCOp);
149 
150  EmitToStreamer(OutStreamer, TmpInst0);
151 }
152 
153 // If there is an MO_JALR operand, insert:
154 //
155 // .reloc tmplabel, R_{MICRO}MIPS_JALR, symbol
156 // tmplabel:
157 //
158 // This is an optimization hint for the linker which may then replace
159 // an indirect call with a direct branch.
160 static void emitDirectiveRelocJalr(const MachineInstr &MI,
162  TargetMachine &TM,
163  MCStreamer &OutStreamer,
164  const MipsSubtarget &Subtarget) {
165  for (unsigned int I = MI.getDesc().getNumOperands(), E = MI.getNumOperands();
166  I < E; ++I) {
167  MachineOperand MO = MI.getOperand(I);
168  if (MO.isMCSymbol() && (MO.getTargetFlags() & MipsII::MO_JALR)) {
169  MCSymbol *Callee = MO.getMCSymbol();
170  if (Callee && !Callee->getName().empty()) {
171  MCSymbol *OffsetLabel = OutContext.createTempSymbol();
172  const MCExpr *OffsetExpr =
173  MCSymbolRefExpr::create(OffsetLabel, OutContext);
174  const MCExpr *CaleeExpr =
175  MCSymbolRefExpr::create(Callee, OutContext);
176  OutStreamer.EmitRelocDirective
177  (*OffsetExpr,
178  Subtarget.inMicroMipsMode() ? "R_MICROMIPS_JALR" : "R_MIPS_JALR",
179  CaleeExpr, SMLoc(), *TM.getMCSubtargetInfo());
180  OutStreamer.EmitLabel(OffsetLabel);
181  return;
182  }
183  }
184  }
185 }
186 
188  MipsTargetStreamer &TS = getTargetStreamer();
189  unsigned Opc = MI->getOpcode();
191 
192  if (MI->isDebugValue()) {
193  SmallString<128> Str;
194  raw_svector_ostream OS(Str);
195 
196  PrintDebugValueComment(MI, OS);
197  return;
198  }
199  if (MI->isDebugLabel())
200  return;
201 
202  // If we just ended a constant pool, mark it as such.
203  if (InConstantPool && Opc != Mips::CONSTPOOL_ENTRY) {
204  OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
205  InConstantPool = false;
206  }
207  if (Opc == Mips::CONSTPOOL_ENTRY) {
208  // CONSTPOOL_ENTRY - This instruction represents a floating
209  // constant pool in the function. The first operand is the ID#
210  // for this instruction, the second is the index into the
211  // MachineConstantPool that this is, the third is the size in
212  // bytes of this constant pool entry.
213  // The required alignment is specified on the basic block holding this MI.
214  //
215  unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
216  unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
217 
218  // If this is the first entry of the pool, mark it.
219  if (!InConstantPool) {
220  OutStreamer->EmitDataRegion(MCDR_DataRegion);
221  InConstantPool = true;
222  }
223 
224  OutStreamer->EmitLabel(GetCPISymbol(LabelId));
225 
226  const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
227  if (MCPE.isMachineConstantPoolEntry())
229  else
231  return;
232  }
233 
234  switch (Opc) {
235  case Mips::PATCHABLE_FUNCTION_ENTER:
237  return;
238  case Mips::PATCHABLE_FUNCTION_EXIT:
240  return;
241  case Mips::PATCHABLE_TAIL_CALL:
243  return;
244  }
245 
246  if (EmitJalrReloc &&
247  (MI->isReturn() || MI->isCall() || MI->isIndirectBranch())) {
248  emitDirectiveRelocJalr(*MI, OutContext, TM, *OutStreamer, *Subtarget);
249  }
250 
253 
254  do {
255  // Do any auto-generated pseudo lowerings.
256  if (emitPseudoExpansionLowering(*OutStreamer, &*I))
257  continue;
258 
259  if (I->getOpcode() == Mips::PseudoReturn ||
260  I->getOpcode() == Mips::PseudoReturn64 ||
261  I->getOpcode() == Mips::PseudoIndirectBranch ||
262  I->getOpcode() == Mips::PseudoIndirectBranch64 ||
263  I->getOpcode() == Mips::TAILCALLREG ||
264  I->getOpcode() == Mips::TAILCALLREG64) {
265  emitPseudoIndirectBranch(*OutStreamer, &*I);
266  continue;
267  }
268 
269  // The inMips16Mode() test is not permanent.
270  // Some instructions are marked as pseudo right now which
271  // would make the test fail for the wrong reason but
272  // that will be fixed soon. We need this here because we are
273  // removing another test for this situation downstream in the
274  // callchain.
275  //
276  if (I->isPseudo() && !Subtarget->inMips16Mode()
277  && !isLongBranchPseudo(I->getOpcode()))
278  llvm_unreachable("Pseudo opcode found in EmitInstruction()");
279 
280  MCInst TmpInst0;
281  MCInstLowering.Lower(&*I, TmpInst0);
282  EmitToStreamer(*OutStreamer, TmpInst0);
283  } while ((++I != E) && I->isInsideBundle()); // Delay slot check
284 }
285 
286 //===----------------------------------------------------------------------===//
287 //
288 // Mips Asm Directives
289 //
290 // -- Frame directive "frame Stackpointer, Stacksize, RARegister"
291 // Describe the stack frame.
292 //
293 // -- Mask directives "(f)mask bitmask, offset"
294 // Tells the assembler which registers are saved and where.
295 // bitmask - contain a little endian bitset indicating which registers are
296 // saved on function prologue (e.g. with a 0x80000000 mask, the
297 // assembler knows the register 31 (RA) is saved at prologue.
298 // offset - the position before stack pointer subtraction indicating where
299 // the first saved register on prologue is located. (e.g. with a
300 //
301 // Consider the following function prologue:
302 //
303 // .frame $fp,48,$ra
304 // .mask 0xc0000000,-8
305 // addiu $sp, $sp, -48
306 // sw $ra, 40($sp)
307 // sw $fp, 36($sp)
308 //
309 // With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
310 // 30 (FP) are saved at prologue. As the save order on prologue is from
311 // left to right, RA is saved first. A -8 offset means that after the
312 // stack pointer subtration, the first register in the mask (RA) will be
313 // saved at address 48-8=40.
314 //
315 //===----------------------------------------------------------------------===//
316 
317 //===----------------------------------------------------------------------===//
318 // Mask directives
319 //===----------------------------------------------------------------------===//
320 
321 // Create a bitmask with all callee saved registers for CPU or Floating Point
322 // registers. For CPU registers consider RA, GP and FP for saving if necessary.
324  // CPU and FPU Saved Registers Bitmasks
325  unsigned CPUBitmask = 0, FPUBitmask = 0;
326  int CPUTopSavedRegOff, FPUTopSavedRegOff;
327 
328  // Set the CPU and FPU Bitmasks
329  const MachineFrameInfo &MFI = MF->getFrameInfo();
331  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
332  // size of stack area to which FP callee-saved regs are saved.
333  unsigned CPURegSize = TRI->getRegSizeInBits(Mips::GPR32RegClass) / 8;
334  unsigned FGR32RegSize = TRI->getRegSizeInBits(Mips::FGR32RegClass) / 8;
335  unsigned AFGR64RegSize = TRI->getRegSizeInBits(Mips::AFGR64RegClass) / 8;
336  bool HasAFGR64Reg = false;
337  unsigned CSFPRegsSize = 0;
338 
339  for (const auto &I : CSI) {
340  unsigned Reg = I.getReg();
341  unsigned RegNum = TRI->getEncodingValue(Reg);
342 
343  // If it's a floating point register, set the FPU Bitmask.
344  // If it's a general purpose register, set the CPU Bitmask.
345  if (Mips::FGR32RegClass.contains(Reg)) {
346  FPUBitmask |= (1 << RegNum);
347  CSFPRegsSize += FGR32RegSize;
348  } else if (Mips::AFGR64RegClass.contains(Reg)) {
349  FPUBitmask |= (3 << RegNum);
350  CSFPRegsSize += AFGR64RegSize;
351  HasAFGR64Reg = true;
352  } else if (Mips::GPR32RegClass.contains(Reg))
353  CPUBitmask |= (1 << RegNum);
354  }
355 
356  // FP Regs are saved right below where the virtual frame pointer points to.
357  FPUTopSavedRegOff = FPUBitmask ?
358  (HasAFGR64Reg ? -AFGR64RegSize : -FGR32RegSize) : 0;
359 
360  // CPU Regs are saved below FP Regs.
361  CPUTopSavedRegOff = CPUBitmask ? -CSFPRegsSize - CPURegSize : 0;
362 
363  MipsTargetStreamer &TS = getTargetStreamer();
364  // Print CPUBitmask
365  TS.emitMask(CPUBitmask, CPUTopSavedRegOff);
366 
367  // Print FPUBitmask
368  TS.emitFMask(FPUBitmask, FPUTopSavedRegOff);
369 }
370 
371 //===----------------------------------------------------------------------===//
372 // Frame and Set directives
373 //===----------------------------------------------------------------------===//
374 
375 /// Frame Directive
378 
379  unsigned stackReg = RI.getFrameRegister(*MF);
380  unsigned returnReg = RI.getRARegister();
381  unsigned stackSize = MF->getFrameInfo().getStackSize();
382 
383  getTargetStreamer().emitFrame(stackReg, stackSize, returnReg);
384 }
385 
386 /// Emit Set directives.
388  switch (static_cast<MipsTargetMachine &>(TM).getABI().GetEnumValue()) {
389  case MipsABIInfo::ABI::O32: return "abi32";
390  case MipsABIInfo::ABI::N32: return "abiN32";
391  case MipsABIInfo::ABI::N64: return "abi64";
392  default: llvm_unreachable("Unknown Mips ABI");
393  }
394 }
395 
397  MipsTargetStreamer &TS = getTargetStreamer();
398 
399  // NaCl sandboxing requires that indirect call instructions are masked.
400  // This means that function entry points should be bundle-aligned.
401  if (Subtarget->isTargetNaCl())
403 
404  if (Subtarget->inMicroMipsMode()) {
406  TS.setUsesMicroMips();
408  } else
410 
411  if (Subtarget->inMips16Mode())
413  else
415 
417  OutStreamer->EmitLabel(CurrentFnSym);
418 }
419 
420 /// EmitFunctionBodyStart - Targets can override this to emit stuff before
421 /// the first basic block in the function.
423  MipsTargetStreamer &TS = getTargetStreamer();
424 
426 
427  bool IsNakedFunction = MF->getFunction().hasFnAttribute(Attribute::Naked);
428  if (!IsNakedFunction)
430 
431  if (!IsNakedFunction)
433 
434  if (!Subtarget->inMips16Mode()) {
438  }
439 }
440 
441 /// EmitFunctionBodyEnd - Targets can override this to emit stuff after
442 /// the last basic block in the function.
444  MipsTargetStreamer &TS = getTargetStreamer();
445 
446  // There are instruction for this macros, but they must
447  // always be at the function end, and we can't emit and
448  // break with BB logic.
449  if (!Subtarget->inMips16Mode()) {
450  TS.emitDirectiveSetAt();
453  }
455  // Make sure to terminate any constant pools that were at the end
456  // of the function.
457  if (!InConstantPool)
458  return;
459  InConstantPool = false;
460  OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
461 }
462 
465  MipsTargetStreamer &TS = getTargetStreamer();
466  if (MBB.empty())
467  TS.emitDirectiveInsn();
468 }
469 
470 /// isBlockOnlyReachableByFallthough - Return true if the basic block has
471 /// exactly one predecessor and the control transfer mechanism between
472 /// the predecessor and this block is a fall-through.
474  MBB) const {
475  // The predecessor has to be immediately before this block.
476  const MachineBasicBlock *Pred = *MBB->pred_begin();
477 
478  // If the predecessor is a switch statement, assume a jump table
479  // implementation, so it is not a fall through.
480  if (const BasicBlock *bb = Pred->getBasicBlock())
481  if (isa<SwitchInst>(bb->getTerminator()))
482  return false;
483 
484  // If this is a landing pad, it isn't a fall through. If it has no preds,
485  // then nothing falls through to it.
486  if (MBB->isEHPad() || MBB->pred_empty())
487  return false;
488 
489  // If there isn't exactly one predecessor, it can't be a fall through.
491  ++PI2;
492 
493  if (PI2 != MBB->pred_end())
494  return false;
495 
496  // The predecessor has to be immediately before this block.
497  if (!Pred->isLayoutSuccessor(MBB))
498  return false;
499 
500  // If the block is completely empty, then it definitely does fall through.
501  if (Pred->empty())
502  return true;
503 
504  // Otherwise, check the last instruction.
505  // Check if the last terminator is an unconditional branch.
507  while (I != Pred->begin() && !(--I)->isTerminator()) ;
508 
509  return !I->isBarrier();
510 }
511 
512 // Print out an operand for an inline asm expression.
513 bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
514  unsigned AsmVariant, const char *ExtraCode,
515  raw_ostream &O) {
516  // Does this asm operand have a single letter operand modifier?
517  if (ExtraCode && ExtraCode[0]) {
518  if (ExtraCode[1] != 0) return true; // Unknown modifier.
519 
520  const MachineOperand &MO = MI->getOperand(OpNum);
521  switch (ExtraCode[0]) {
522  default:
523  // See if this is a generic print operand
524  return AsmPrinter::PrintAsmOperand(MI,OpNum,AsmVariant,ExtraCode,O);
525  case 'X': // hex const int
527  return true;
528  O << "0x" << Twine::utohexstr(MO.getImm());
529  return false;
530  case 'x': // hex const int (low 16 bits)
532  return true;
533  O << "0x" << Twine::utohexstr(MO.getImm() & 0xffff);
534  return false;
535  case 'd': // decimal const int
537  return true;
538  O << MO.getImm();
539  return false;
540  case 'm': // decimal const int minus 1
542  return true;
543  O << MO.getImm() - 1;
544  return false;
545  case 'y': // exact log2
547  return true;
548  if (!isPowerOf2_64(MO.getImm()))
549  return true;
550  O << Log2_64(MO.getImm());
551  return false;
552  case 'z':
553  // $0 if zero, regular printing otherwise
554  if (MO.getType() == MachineOperand::MO_Immediate && MO.getImm() == 0) {
555  O << "$0";
556  return false;
557  }
558  // If not, call printOperand as normal.
559  break;
560  case 'D': // Second part of a double word register operand
561  case 'L': // Low order register of a double word register operand
562  case 'M': // High order register of a double word register operand
563  {
564  if (OpNum == 0)
565  return true;
566  const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
567  if (!FlagsOP.isImm())
568  return true;
569  unsigned Flags = FlagsOP.getImm();
570  unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
571  // Number of registers represented by this operand. We are looking
572  // for 2 for 32 bit mode and 1 for 64 bit mode.
573  if (NumVals != 2) {
574  if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
575  unsigned Reg = MO.getReg();
576  O << '$' << MipsInstPrinter::getRegisterName(Reg);
577  return false;
578  }
579  return true;
580  }
581 
582  unsigned RegOp = OpNum;
583  if (!Subtarget->isGP64bit()){
584  // Endianness reverses which register holds the high or low value
585  // between M and L.
586  switch(ExtraCode[0]) {
587  case 'M':
588  RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
589  break;
590  case 'L':
591  RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
592  break;
593  case 'D': // Always the second part
594  RegOp = OpNum + 1;
595  }
596  if (RegOp >= MI->getNumOperands())
597  return true;
598  const MachineOperand &MO = MI->getOperand(RegOp);
599  if (!MO.isReg())
600  return true;
601  unsigned Reg = MO.getReg();
602  O << '$' << MipsInstPrinter::getRegisterName(Reg);
603  return false;
604  }
605  break;
606  }
607  case 'w':
608  // Print MSA registers for the 'f' constraint
609  // In LLVM, the 'w' modifier doesn't need to do anything.
610  // We can just call printOperand as normal.
611  break;
612  }
613  }
614 
615  printOperand(MI, OpNum, O);
616  return false;
617 }
618 
620  unsigned OpNum, unsigned AsmVariant,
621  const char *ExtraCode,
622  raw_ostream &O) {
623  assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
624  const MachineOperand &BaseMO = MI->getOperand(OpNum);
625  const MachineOperand &OffsetMO = MI->getOperand(OpNum + 1);
626  assert(BaseMO.isReg() && "Unexpected base pointer for inline asm memory operand.");
627  assert(OffsetMO.isImm() && "Unexpected offset for inline asm memory operand.");
628  int Offset = OffsetMO.getImm();
629 
630  // Currently we are expecting either no ExtraCode or 'D','M','L'.
631  if (ExtraCode) {
632  switch (ExtraCode[0]) {
633  case 'D':
634  Offset += 4;
635  break;
636  case 'M':
637  if (Subtarget->isLittle())
638  Offset += 4;
639  break;
640  case 'L':
641  if (!Subtarget->isLittle())
642  Offset += 4;
643  break;
644  default:
645  return true; // Unknown modifier.
646  }
647  }
648 
649  O << Offset << "($" << MipsInstPrinter::getRegisterName(BaseMO.getReg())
650  << ")";
651 
652  return false;
653 }
654 
655 void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
656  raw_ostream &O) {
657  const MachineOperand &MO = MI->getOperand(opNum);
658  bool closeP = false;
659 
660  if (MO.getTargetFlags())
661  closeP = true;
662 
663  switch(MO.getTargetFlags()) {
664  case MipsII::MO_GPREL: O << "%gp_rel("; break;
665  case MipsII::MO_GOT_CALL: O << "%call16("; break;
666  case MipsII::MO_GOT: O << "%got("; break;
667  case MipsII::MO_ABS_HI: O << "%hi("; break;
668  case MipsII::MO_ABS_LO: O << "%lo("; break;
669  case MipsII::MO_HIGHER: O << "%higher("; break;
670  case MipsII::MO_HIGHEST: O << "%highest(("; break;
671  case MipsII::MO_TLSGD: O << "%tlsgd("; break;
672  case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
673  case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
674  case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
675  case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
676  case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
677  case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
678  case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
679  case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
680  }
681 
682  switch (MO.getType()) {
684  O << '$'
686  break;
687 
689  O << MO.getImm();
690  break;
691 
693  MO.getMBB()->getSymbol()->print(O, MAI);
694  return;
695 
697  getSymbol(MO.getGlobal())->print(O, MAI);
698  break;
699 
702  O << BA->getName();
703  break;
704  }
705 
707  O << getDataLayout().getPrivateGlobalPrefix() << "CPI"
708  << getFunctionNumber() << "_" << MO.getIndex();
709  if (MO.getOffset())
710  O << "+" << MO.getOffset();
711  break;
712 
713  default:
714  llvm_unreachable("<unknown operand type>");
715  }
716 
717  if (closeP) O << ")";
718 }
719 
720 void MipsAsmPrinter::
721 printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O) {
722  // Load/Store memory operands -- imm($reg)
723  // If PIC target the target is loaded as the
724  // pattern lw $25,%call16($28)
725 
726  // opNum can be invalid if instruction has reglist as operand.
727  // MemOperand is always last operand of instruction (base + offset).
728  switch (MI->getOpcode()) {
729  default:
730  break;
731  case Mips::SWM32_MM:
732  case Mips::LWM32_MM:
733  opNum = MI->getNumOperands() - 2;
734  break;
735  }
736 
737  printOperand(MI, opNum+1, O);
738  O << "(";
739  printOperand(MI, opNum, O);
740  O << ")";
741 }
742 
743 void MipsAsmPrinter::
744 printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O) {
745  // when using stack locations for not load/store instructions
746  // print the same way as all normal 3 operand instructions.
747  printOperand(MI, opNum, O);
748  O << ", ";
749  printOperand(MI, opNum+1, O);
750 }
751 
752 void MipsAsmPrinter::
753 printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
754  const char *Modifier) {
755  const MachineOperand &MO = MI->getOperand(opNum);
757 }
758 
759 void MipsAsmPrinter::
760 printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
761  for (int i = opNum, e = MI->getNumOperands(); i != e; ++i) {
762  if (i != opNum) O << ", ";
763  printOperand(MI, i, O);
764  }
765 }
766 
768  MipsTargetStreamer &TS = getTargetStreamer();
769 
770  // MipsTargetStreamer has an initialization order problem when emitting an
771  // object file directly (see MipsTargetELFStreamer for full details). Work
772  // around it by re-initializing the PIC state here.
774 
775  // Compute MIPS architecture attributes based on the default subtarget
776  // that we'd have constructed. Module level directives aren't LTO
777  // clean anyhow.
778  // FIXME: For ifunc related functions we could iterate over and look
779  // for a feature string that doesn't match the default one.
780  const Triple &TT = TM.getTargetTriple();
783  const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
784  const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, 0);
785 
786  bool IsABICalls = STI.isABICalls();
787  const MipsABIInfo &ABI = MTM.getABI();
788  if (IsABICalls) {
790  // FIXME: This condition should be a lot more complicated that it is here.
791  // Ideally it should test for properties of the ABI and not the ABI
792  // itself.
793  // For the moment, I'm only correcting enough to make MIPS-IV work.
794  if (!isPositionIndependent() && STI.hasSym32())
796  }
797 
798  // Tell the assembler which ABI we are using
799  std::string SectionName = std::string(".mdebug.") + getCurrentABIString();
800  OutStreamer->SwitchSection(
801  OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
802 
803  // NaN: At the moment we only support:
804  // 1. .nan legacy (default)
805  // 2. .nan 2008
806  STI.isNaN2008() ? TS.emitDirectiveNaN2008()
807  : TS.emitDirectiveNaNLegacy();
808 
809  // TODO: handle O64 ABI
810 
811  TS.updateABIInfo(STI);
812 
813  // We should always emit a '.module fp=...' but binutils 2.24 does not accept
814  // it. We therefore emit it when it contradicts the ABI defaults (-mfpxx or
815  // -mfp64) and omit it otherwise.
816  if ((ABI.IsO32() && (STI.isABI_FPXX() || STI.isFP64bit())) ||
817  STI.useSoftFloat())
819 
820  // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
821  // accept it. We therefore emit it when it contradicts the default or an
822  // option has changed the default (i.e. FPXX) and omit it otherwise.
823  if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
825 }
826 
827 void MipsAsmPrinter::emitInlineAsmStart() const {
828  MipsTargetStreamer &TS = getTargetStreamer();
829 
830  // GCC's choice of assembler options for inline assembly code ('at', 'macro'
831  // and 'reorder') is different from LLVM's choice for generated code ('noat',
832  // 'nomacro' and 'noreorder').
833  // In order to maintain compatibility with inline assembly code which depends
834  // on GCC's assembler options being used, we have to switch to those options
835  // for the duration of the inline assembly block and then switch back.
837  TS.emitDirectiveSetAt();
840  OutStreamer->AddBlankLine();
841 }
842 
843 void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
844  const MCSubtargetInfo *EndInfo) const {
845  OutStreamer->AddBlankLine();
846  getTargetStreamer().emitDirectiveSetPop();
847 }
848 
849 void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
850  MCInst I;
851  I.setOpcode(Mips::JAL);
852  I.addOperand(
854  OutStreamer->EmitInstruction(I, STI);
855 }
856 
857 void MipsAsmPrinter::EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode,
858  unsigned Reg) {
859  MCInst I;
860  I.setOpcode(Opcode);
862  OutStreamer->EmitInstruction(I, STI);
863 }
864 
865 void MipsAsmPrinter::EmitInstrRegReg(const MCSubtargetInfo &STI,
866  unsigned Opcode, unsigned Reg1,
867  unsigned Reg2) {
868  MCInst I;
869  //
870  // Because of the current td files for Mips32, the operands for MTC1
871  // appear backwards from their normal assembly order. It's not a trivial
872  // change to fix this in the td file so we adjust for it here.
873  //
874  if (Opcode == Mips::MTC1) {
875  unsigned Temp = Reg1;
876  Reg1 = Reg2;
877  Reg2 = Temp;
878  }
879  I.setOpcode(Opcode);
882  OutStreamer->EmitInstruction(I, STI);
883 }
884 
885 void MipsAsmPrinter::EmitInstrRegRegReg(const MCSubtargetInfo &STI,
886  unsigned Opcode, unsigned Reg1,
887  unsigned Reg2, unsigned Reg3) {
888  MCInst I;
889  I.setOpcode(Opcode);
893  OutStreamer->EmitInstruction(I, STI);
894 }
895 
896 void MipsAsmPrinter::EmitMovFPIntPair(const MCSubtargetInfo &STI,
897  unsigned MovOpc, unsigned Reg1,
898  unsigned Reg2, unsigned FPReg1,
899  unsigned FPReg2, bool LE) {
900  if (!LE) {
901  unsigned temp = Reg1;
902  Reg1 = Reg2;
903  Reg2 = temp;
904  }
905  EmitInstrRegReg(STI, MovOpc, Reg1, FPReg1);
906  EmitInstrRegReg(STI, MovOpc, Reg2, FPReg2);
907 }
908 
909 void MipsAsmPrinter::EmitSwapFPIntParams(const MCSubtargetInfo &STI,
911  bool LE, bool ToFP) {
912  using namespace Mips16HardFloatInfo;
913 
914  unsigned MovOpc = ToFP ? Mips::MTC1 : Mips::MFC1;
915  switch (PV) {
916  case FSig:
917  EmitInstrRegReg(STI, MovOpc, Mips::A0, Mips::F12);
918  break;
919  case FFSig:
920  EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F14, LE);
921  break;
922  case FDSig:
923  EmitInstrRegReg(STI, MovOpc, Mips::A0, Mips::F12);
924  EmitMovFPIntPair(STI, MovOpc, Mips::A2, Mips::A3, Mips::F14, Mips::F15, LE);
925  break;
926  case DSig:
927  EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
928  break;
929  case DDSig:
930  EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
931  EmitMovFPIntPair(STI, MovOpc, Mips::A2, Mips::A3, Mips::F14, Mips::F15, LE);
932  break;
933  case DFSig:
934  EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F12, Mips::F13, LE);
935  EmitInstrRegReg(STI, MovOpc, Mips::A2, Mips::F14);
936  break;
937  case NoSig:
938  return;
939  }
940 }
941 
942 void MipsAsmPrinter::EmitSwapFPIntRetval(
944  bool LE) {
945  using namespace Mips16HardFloatInfo;
946 
947  unsigned MovOpc = Mips::MFC1;
948  switch (RV) {
949  case FRet:
950  EmitInstrRegReg(STI, MovOpc, Mips::V0, Mips::F0);
951  break;
952  case DRet:
953  EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
954  break;
955  case CFRet:
956  EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
957  break;
958  case CDRet:
959  EmitMovFPIntPair(STI, MovOpc, Mips::V0, Mips::V1, Mips::F0, Mips::F1, LE);
960  EmitMovFPIntPair(STI, MovOpc, Mips::A0, Mips::A1, Mips::F2, Mips::F3, LE);
961  break;
962  case NoFPRet:
963  break;
964  }
965 }
966 
967 void MipsAsmPrinter::EmitFPCallStub(
968  const char *Symbol, const Mips16HardFloatInfo::FuncSignature *Signature) {
969  using namespace Mips16HardFloatInfo;
970 
971  MCSymbol *MSymbol = OutContext.getOrCreateSymbol(StringRef(Symbol));
972  bool LE = getDataLayout().isLittleEndian();
973  // Construct a local MCSubtargetInfo here.
974  // This is because the MachineFunction won't exist (but have not yet been
975  // freed) and since we're at the global level we can use the default
976  // constructed subtarget.
977  std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
980 
981  //
982  // .global xxxx
983  //
984  OutStreamer->EmitSymbolAttribute(MSymbol, MCSA_Global);
985  const char *RetType;
986  //
987  // make the comment field identifying the return and parameter
988  // types of the floating point stub
989  // # Stub function to call rettype xxxx (params)
990  //
991  switch (Signature->RetSig) {
992  case FRet:
993  RetType = "float";
994  break;
995  case DRet:
996  RetType = "double";
997  break;
998  case CFRet:
999  RetType = "complex";
1000  break;
1001  case CDRet:
1002  RetType = "double complex";
1003  break;
1004  case NoFPRet:
1005  RetType = "";
1006  break;
1007  }
1008  const char *Parms;
1009  switch (Signature->ParamSig) {
1010  case FSig:
1011  Parms = "float";
1012  break;
1013  case FFSig:
1014  Parms = "float, float";
1015  break;
1016  case FDSig:
1017  Parms = "float, double";
1018  break;
1019  case DSig:
1020  Parms = "double";
1021  break;
1022  case DDSig:
1023  Parms = "double, double";
1024  break;
1025  case DFSig:
1026  Parms = "double, float";
1027  break;
1028  case NoSig:
1029  Parms = "";
1030  break;
1031  }
1032  OutStreamer->AddComment("\t# Stub function to call " + Twine(RetType) + " " +
1033  Twine(Symbol) + " (" + Twine(Parms) + ")");
1034  //
1035  // probably not necessary but we save and restore the current section state
1036  //
1037  OutStreamer->PushSection();
1038  //
1039  // .section mips16.call.fpxxxx,"ax",@progbits
1040  //
1042  ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
1044  OutStreamer->SwitchSection(M, nullptr);
1045  //
1046  // .align 2
1047  //
1048  OutStreamer->EmitValueToAlignment(4);
1049  MipsTargetStreamer &TS = getTargetStreamer();
1050  //
1051  // .set nomips16
1052  // .set nomicromips
1053  //
1056  //
1057  // .ent __call_stub_fp_xxxx
1058  // .type __call_stub_fp_xxxx,@function
1059  // __call_stub_fp_xxxx:
1060  //
1061  std::string x = "__call_stub_fp_" + std::string(Symbol);
1062  MCSymbolELF *Stub =
1063  cast<MCSymbolELF>(OutContext.getOrCreateSymbol(StringRef(x)));
1064  TS.emitDirectiveEnt(*Stub);
1065  MCSymbol *MType =
1066  OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
1067  OutStreamer->EmitSymbolAttribute(MType, MCSA_ELF_TypeFunction);
1068  OutStreamer->EmitLabel(Stub);
1069 
1070  // Only handle non-pic for now.
1072  "should not be here if we are compiling pic");
1074  //
1075  // We need to add a MipsMCExpr class to MCTargetDesc to fully implement
1076  // stubs without raw text but this current patch is for compiler generated
1077  // functions and they all return some value.
1078  // The calling sequence for non pic is different in that case and we need
1079  // to implement %lo and %hi in order to handle the case of no return value
1080  // See the corresponding method in Mips16HardFloat for details.
1081  //
1082  // mov the return address to S2.
1083  // we have no stack space to store it and we are about to make another call.
1084  // We need to make sure that the enclosing function knows to save S2
1085  // This should have already been handled.
1086  //
1087  // Mov $18, $31
1088 
1089  EmitInstrRegRegReg(*STI, Mips::OR, Mips::S2, Mips::RA, Mips::ZERO);
1090 
1091  EmitSwapFPIntParams(*STI, Signature->ParamSig, LE, true);
1092 
1093  // Jal xxxx
1094  //
1095  EmitJal(*STI, MSymbol);
1096 
1097  // fix return values
1098  EmitSwapFPIntRetval(*STI, Signature->RetSig, LE);
1099  //
1100  // do the return
1101  // if (Signature->RetSig == NoFPRet)
1102  // llvm_unreachable("should not be any stubs here with no return value");
1103  // else
1104  EmitInstrReg(*STI, Mips::JR, Mips::S2);
1105 
1107  OutStreamer->EmitLabel(Tmp);
1110  const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
1111  OutStreamer->emitELFSize(Stub, T_min_E);
1112  TS.emitDirectiveEnd(x);
1113  OutStreamer->PopSection();
1114 }
1115 
1117  // Emit needed stubs
1118  //
1119  for (std::map<
1120  const char *,
1121  const Mips16HardFloatInfo::FuncSignature *>::const_iterator
1122  it = StubsNeeded.begin();
1123  it != StubsNeeded.end(); ++it) {
1124  const char *Symbol = it->first;
1125  const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
1126  EmitFPCallStub(Symbol, Signature);
1127  }
1128  // return to the text section
1130 }
1131 
1132 void MipsAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) {
1133  const uint8_t NoopsInSledCount = Subtarget->isGP64bit() ? 15 : 11;
1134  // For mips32 we want to emit the following pattern:
1135  //
1136  // .Lxray_sled_N:
1137  // ALIGN
1138  // B .tmpN
1139  // 11 NOP instructions (44 bytes)
1140  // ADDIU T9, T9, 52
1141  // .tmpN
1142  //
1143  // We need the 44 bytes (11 instructions) because at runtime, we'd
1144  // be patching over the full 48 bytes (12 instructions) with the following
1145  // pattern:
1146  //
1147  // ADDIU SP, SP, -8
1148  // NOP
1149  // SW RA, 4(SP)
1150  // SW T9, 0(SP)
1151  // LUI T9, %hi(__xray_FunctionEntry/Exit)
1152  // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1153  // LUI T0, %hi(function_id)
1154  // JALR T9
1155  // ORI T0, T0, %lo(function_id)
1156  // LW T9, 0(SP)
1157  // LW RA, 4(SP)
1158  // ADDIU SP, SP, 8
1159  //
1160  // We add 52 bytes to t9 because we want to adjust the function pointer to
1161  // the actual start of function i.e. the address just after the noop sled.
1162  // We do this because gp displacement relocation is emitted at the start of
1163  // of the function i.e after the nop sled and to correctly calculate the
1164  // global offset table address, t9 must hold the address of the instruction
1165  // containing the gp displacement relocation.
1166  // FIXME: Is this correct for the static relocation model?
1167  //
1168  // For mips64 we want to emit the following pattern:
1169  //
1170  // .Lxray_sled_N:
1171  // ALIGN
1172  // B .tmpN
1173  // 15 NOP instructions (60 bytes)
1174  // .tmpN
1175  //
1176  // We need the 60 bytes (15 instructions) because at runtime, we'd
1177  // be patching over the full 64 bytes (16 instructions) with the following
1178  // pattern:
1179  //
1180  // DADDIU SP, SP, -16
1181  // NOP
1182  // SD RA, 8(SP)
1183  // SD T9, 0(SP)
1184  // LUI T9, %highest(__xray_FunctionEntry/Exit)
1185  // ORI T9, T9, %higher(__xray_FunctionEntry/Exit)
1186  // DSLL T9, T9, 16
1187  // ORI T9, T9, %hi(__xray_FunctionEntry/Exit)
1188  // DSLL T9, T9, 16
1189  // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1190  // LUI T0, %hi(function_id)
1191  // JALR T9
1192  // ADDIU T0, T0, %lo(function_id)
1193  // LD T9, 0(SP)
1194  // LD RA, 8(SP)
1195  // DADDIU SP, SP, 16
1196  //
1197  OutStreamer->EmitCodeAlignment(4);
1198  auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1199  OutStreamer->EmitLabel(CurSled);
1201 
1202  // Emit "B .tmpN" instruction, which jumps over the nop sled to the actual
1203  // start of function
1204  const MCExpr *TargetExpr = MCSymbolRefExpr::create(
1205  Target, MCSymbolRefExpr::VariantKind::VK_None, OutContext);
1206  EmitToStreamer(*OutStreamer, MCInstBuilder(Mips::BEQ)
1207  .addReg(Mips::ZERO)
1208  .addReg(Mips::ZERO)
1209  .addExpr(TargetExpr));
1210 
1211  for (int8_t I = 0; I < NoopsInSledCount; I++)
1212  EmitToStreamer(*OutStreamer, MCInstBuilder(Mips::SLL)
1213  .addReg(Mips::ZERO)
1214  .addReg(Mips::ZERO)
1215  .addImm(0));
1216 
1217  OutStreamer->EmitLabel(Target);
1218 
1219  if (!Subtarget->isGP64bit()) {
1220  EmitToStreamer(*OutStreamer,
1221  MCInstBuilder(Mips::ADDiu)
1222  .addReg(Mips::T9)
1223  .addReg(Mips::T9)
1224  .addImm(0x34));
1225  }
1226 
1227  recordSled(CurSled, MI, Kind);
1228 }
1229 
1231  EmitSled(MI, SledKind::FUNCTION_ENTER);
1232 }
1233 
1235  EmitSled(MI, SledKind::FUNCTION_EXIT);
1236 }
1237 
1239  EmitSled(MI, SledKind::TAIL_CALL);
1240 }
1241 
1243  raw_ostream &OS) {
1244  // TODO: implement
1245 }
1246 
1247 // Emit .dtprelword or .dtpreldword directive
1248 // and value for debug thread local expression.
1249 void MipsAsmPrinter::EmitDebugValue(const MCExpr *Value, unsigned Size) const {
1250  if (auto *MipsExpr = dyn_cast<MipsMCExpr>(Value)) {
1251  if (MipsExpr && MipsExpr->getKind() == MipsMCExpr::MEK_DTPREL) {
1252  switch (Size) {
1253  case 4:
1254  OutStreamer->EmitDTPRel32Value(MipsExpr->getSubExpr());
1255  break;
1256  case 8:
1257  OutStreamer->EmitDTPRel64Value(MipsExpr->getSubExpr());
1258  break;
1259  default:
1260  llvm_unreachable("Unexpected size of expression value.");
1261  }
1262  return;
1263  }
1264  }
1265  AsmPrinter::EmitDebugValue(Value, Size);
1266 }
1267 
1268 // Align all targets of indirect branches on bundle size. Used only if target
1269 // is NaCl.
1270 void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {
1271  // Align all blocks that are jumped to through jump table.
1272  if (MachineJumpTableInfo *JtInfo = MF.getJumpTableInfo()) {
1273  const std::vector<MachineJumpTableEntry> &JT = JtInfo->getJumpTables();
1274  for (unsigned I = 0; I < JT.size(); ++I) {
1275  const std::vector<MachineBasicBlock*> &MBBs = JT[I].MBBs;
1276 
1277  for (unsigned J = 0; J < MBBs.size(); ++J)
1278  MBBs[J]->setAlignment(MIPS_NACL_BUNDLE_ALIGN);
1279  }
1280  }
1281 
1282  // If basic block address is taken, block can be target of indirect branch.
1283  for (auto &MBB : MF) {
1284  if (MBB.hasAddressTaken())
1285  MBB.setAlignment(MIPS_NACL_BUNDLE_ALIGN);
1286  }
1287 }
1288 
1289 bool MipsAsmPrinter::isLongBranchPseudo(int Opcode) const {
1290  return (Opcode == Mips::LONG_BRANCH_LUi
1291  || Opcode == Mips::LONG_BRANCH_LUi2Op
1292  || Opcode == Mips::LONG_BRANCH_LUi2Op_64
1293  || Opcode == Mips::LONG_BRANCH_ADDiu
1294  || Opcode == Mips::LONG_BRANCH_ADDiu2Op
1295  || Opcode == Mips::LONG_BRANCH_DADDiu
1296  || Opcode == Mips::LONG_BRANCH_DADDiu2Op);
1297 }
1298 
1299 // Force static initialization.
1300 extern "C" void LLVMInitializeMipsAsmPrinter() {
1305 }
unsigned getTargetFlags() const
MachineConstantPoolValue * MachineCPVal
virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff)
bool isABICalls() const
StringRef getTargetFeatureString() const
bool isDebugLabel() const
Definition: MachineInstr.h:998
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isCall(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:633
instr_iterator instr_end()
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:94
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:294
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool inMips16Mode() const
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:333
MO_HIGHER/HIGHEST - Represents the highest or higher half word of a 64-bit symbol address...
Definition: MipsBaseInfo.h:85
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:89
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
void EmitFunctionBodyEnd() override
EmitFunctionBodyEnd - Targets can override this to emit stuff after the last basic block in the funct...
MO_TLSGD - Represents the offset into the global offset table at which.
Definition: MipsBaseInfo.h:58
void EmitDebugValue(const MCExpr *Value, unsigned Size) const override
Emit the directive and value for debug thread local expression.
unsigned getReg() const
getReg - Returns the register number.
unsigned Reg
Target & getTheMipselTarget()
virtual void EmitDTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
Definition: MCStreamer.cpp:170
virtual void emitDirectiveSetNoReorder()
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:321
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const override
isBlockOnlyReachableByFallthough - Return true if the basic block has exactly one predecessor and the...
void PushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:368
MachineBasicBlock reference.
unsigned const TargetRegisterInfo * TRI
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:97
void Initialize(MCContext *C)
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
void EmitFunctionBodyStart() override
EmitFunctionBodyStart - Targets can override this to emit stuff before the first basic block in the f...
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:633
void EmitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:956
return AArch64::GPR64RegClass contains(Reg)
SI optimize exec mask operations pre RA
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
virtual void emitDirectiveSetMicroMips()
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:211
virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg)
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
static void emitDirectiveRelocJalr(const MachineInstr &MI, MCContext &OutContext, TargetMachine &TM, MCStreamer &OutStreamer, const MipsSubtarget &Subtarget)
bool inMicroMipsMode() const
void LLVMInitializeMipsAsmPrinter()
virtual void emitDirectiveSetNoMacro()
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
virtual void emitDirectiveEnd(StringRef Name)
bool isGP64bit() const
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getAlignment() const
getAlignment - Return the alignment (log2, not bytes) of the function.
bool hasMips32r6() const
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol address.
Definition: MipsBaseInfo.h:52
const MipsABIInfo & getABI() const
void emitXRayTable()
Emit a table with all XRay instrumentation points.
virtual void emitDirectiveModuleOddSPReg()
Context object for machine code objects.
Definition: MCContext.h:63
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
Definition: MCStreamer.h:312
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:406
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
Definition: MachineInstr.h:663
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:296
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:546
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:203
virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
Target & getTheMips64Target()
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:221
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
This class is a data container for one entry in a MachineConstantPool.
StringRef getTargetCPU() const
void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS)
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
amdgpu Simplify well known AMD library false Value * Callee
const std::string & str() const
Definition: Triple.h:359
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
bool isTargetNaCl() const
MO_GPREL - Represents the offset from the current gp value to be used for the relocatable object file...
Definition: MipsBaseInfo.h:48
bool isReturn(QueryType Type=AnyInBundle) const
Definition: MachineInstr.h:623
MCContext & getContext() const
Address of a global value.
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
Definition: MipsBaseInfo.h:44
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
Target & getTheMips64elTarget()
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:113
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:85
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
virtual void emitDirectiveSetNoMicroMips()
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual void emitDirectiveSetMips16()
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
const GlobalValue * getGlobal() const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
void EmitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
static ManagedStatic< OptionRegistry > OR
Definition: Options.cpp:31
virtual void emitDirectiveSetMacro()
void EmitAlignment(unsigned NumBits, const GlobalObject *GV=nullptr) const
Emit an alignment directive to the specified power of two boundary.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:82
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
Definition: InlineAsm.h:336
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:434
void Lower(const MachineInstr *MI, MCInst &OutMI) const
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.
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
Address of a basic block.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
const Triple & getTargetTriple() const
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
bool IsO32() const
Definition: MipsABIInfo.h:42
self_iterator getIterator()
Definition: ilist_node.h:82
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff)
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
const Target & getTarget() const
MipsMCInstLower MCInstLowering
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
bool hasMips64r6() const
bool isMCSymbol() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
MO_GOTTPREL - Represents the offset from the thread pointer (Initial.
Definition: MipsBaseInfo.h:69
virtual void EmitDataRegion(MCDataRegionType Kind)
Note in the output the specified region Kind.
Definition: MCStreamer.h:452
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
const std::vector< MachineConstantPoolEntry > & getConstants() const
cl::opt< bool > EmitJalrReloc
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:208
virtual void emitDirectiveAbiCalls()
MO_GOT - Represents the offset into the global offset table at which the address the relocation entry...
Definition: MipsBaseInfo.h:38
Iterator for intrusive lists based on ilist_node.
void setOpcode(unsigned Op)
Definition: MCInst.h:173
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
bool isLittle() const
virtual void emitDirectiveOptionPic0()
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
bool isDebugValue() const
Definition: MachineInstr.h:997
MachineOperand class - Representation of each machine instruction operand.
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI)
Emit a .reloc directive.
Definition: MCStreamer.h:946
const MCSubtargetInfo * getMCSubtargetInfo() const
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:231
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:385
virtual void emitDirectiveSetNoMips16()
int64_t getImm() const
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O, const char *Modifier=nullptr)
void EmitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
const char * MipsFCCToString(Mips::CondCode CC)
Target - Wrapper for Target specific information.
union llvm::MachineConstantPoolEntry::@159 Val
The constant itself.
Target & getTheMipsTarget()
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
MO_TPREL_HI/LO - Represents the hi and low part of the offset from.
Definition: MipsBaseInfo.h:73
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:254
static const unsigned MIPS_NACL_BUNDLE_ALIGN
Definition: MipsMCNaCl.h:18
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
const char * getCurrentABIString() const
Emit Set directives.
virtual void setPic(bool Value)
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O)
Representation of each machine instruction.
Definition: MachineInstr.h:64
void updateABIInfo(const PredicateLibrary &P)
virtual void emitDirectiveEnt(const MCSymbol &Symbol)
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
const MipsSubtarget * Subtarget
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
bool isEHPad() const
Returns true if the block is a landing pad.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
.type _foo, STT_FUNC # aka
Definition: MCDirectives.h:23
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
#define I(x, y, z)
Definition: MD5.cpp:58
virtual void EmitDTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
Definition: MCStreamer.cpp:174
Generic base class for all target subtargets.
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O)
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI)
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:124
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
uint32_t Size
Definition: Profile.cpp:47
MCOperand LowerOperand(const MachineOperand &MO, unsigned offset=0) const
unsigned getRARegister() const
This method should return the register where the return address can be found.
void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
LLVM_NODISCARD std::string lower() const
Definition: StringRef.cpp:108
MCSection * getTextSection() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
MCSymbol * getMCSymbol() const
void EmitGlobalConstant(const DataLayout &DL, const Constant *CV)
Print a general LLVM constant to the .s file.
LLVM Value Representation.
Definition: Value.h:73
virtual void emitDirectiveNaNLegacy()
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:347
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:216
const MipsFunctionInfo * MipsFI
IRTranslator LLVM IR MI
void emitFrameDirective()
Frame Directive.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:186
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isValid() const
Definition: MCInst.h:57
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI)
Address of indexed Constant in Constant Pool.
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, unsigned AsmVariant, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
bool isPositionIndependent() const
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
void EmitBasicBlockEnd(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the end of a basic block.
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI)
Represents a location in source code.
Definition: SMLoc.h:24
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:545
.end_data_region
Definition: MCDirectives.h:61
Helper operand used to generate R_MIPS_JALR.
Definition: MipsBaseInfo.h:95
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:60