LLVM 24.0.0git
MipsAsmPrinter.cpp
Go to the documentation of this file.
1//===- MipsAsmPrinter.cpp - Mips LLVM Assembly Printer --------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a printer that converts from our internal representation
10// of machine-dependent LLVM code to GAS-format MIPS assembly language.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MipsAsmPrinter.h"
21#include "Mips.h"
22#include "MipsMCInstLower.h"
23#include "MipsMachineFunction.h"
24#include "MipsSubtarget.h"
25#include "MipsTargetMachine.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/Twine.h"
40#include "llvm/IR/Attributes.h"
41#include "llvm/IR/BasicBlock.h"
42#include "llvm/IR/DataLayout.h"
43#include "llvm/IR/Function.h"
44#include "llvm/IR/InlineAsm.h"
46#include "llvm/IR/Module.h"
47#include "llvm/MC/MCContext.h"
48#include "llvm/MC/MCExpr.h"
49#include "llvm/MC/MCInst.h"
53#include "llvm/MC/MCSymbol.h"
62#include <cassert>
63#include <cstdint>
64#include <map>
65#include <memory>
66#include <string>
67#include <vector>
68
69using namespace llvm;
70
71#define DEBUG_TYPE "mips-asm-printer"
72
73MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() const {
74 return static_cast<MipsTargetStreamer &>(*OutStreamer->getTargetStreamer());
75}
76
78 Subtarget = &MF.getSubtarget<MipsSubtarget>();
79
80 MipsFI = MF.getInfo<MipsFunctionInfo>();
81 if (Subtarget->inMips16Mode())
82 for (const auto &I : MipsFI->StubsNeeded)
83 StubsNeeded.insert(I);
84 MCP = MF.getConstantPool();
85
87
89
90 return true;
91}
92
93bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
95 return MCOp.isValid();
96}
97
98#include "MipsGenMCPseudoLowering.inc"
99
100// Lower PseudoReturn/PseudoIndirectBranch/PseudoIndirectBranch64 to JR, JR_MM,
101// JALR, or JALR64 as appropriate for the target.
102void MipsAsmPrinter::emitPseudoIndirectBranch(MCStreamer &OutStreamer,
103 const MachineInstr *MI) {
104 bool HasLinkReg = false;
105 bool InMicroMipsMode = Subtarget->inMicroMipsMode();
106 MCInst TmpInst0;
107
108 if (Subtarget->hasMips64r6()) {
109 // MIPS64r6 should use (JALR64 ZERO_64, $rs)
110 TmpInst0.setOpcode(Mips::JALR64);
111 HasLinkReg = true;
112 } else if (Subtarget->hasMips32r6()) {
113 // MIPS32r6 should use (JALR ZERO, $rs)
114 if (InMicroMipsMode)
115 TmpInst0.setOpcode(Mips::JRC16_MMR6);
116 else {
117 TmpInst0.setOpcode(Mips::JALR);
118 HasLinkReg = true;
119 }
120 } else if (Subtarget->inMicroMipsMode())
121 // microMIPS should use (JR_MM $rs)
122 TmpInst0.setOpcode(Mips::JR_MM);
123 else {
124 // Everything else should use (JR $rs)
125 TmpInst0.setOpcode(Mips::JR);
126 }
127
128 MCOperand MCOp;
129
130 if (HasLinkReg) {
131 unsigned ZeroReg = Subtarget->isGP64bit() ? Mips::R0_64 : Mips::R0;
132 TmpInst0.addOperand(MCOperand::createReg(ZeroReg));
133 }
134
135 lowerOperand(MI->getOperand(0), MCOp);
136 TmpInst0.addOperand(MCOp);
137
138 EmitToStreamer(OutStreamer, TmpInst0);
139}
140
141// If there is an MO_JALR operand, insert:
142//
143// .reloc tmplabel, R_{MICRO}MIPS_JALR, symbol
144// tmplabel:
145//
146// This is an optimization hint for the linker which may then replace
147// an indirect call with a direct branch.
152 const MipsSubtarget &Subtarget) {
153 for (const MachineOperand &MO :
154 llvm::drop_begin(MI.operands(), MI.getDesc().getNumOperands())) {
155 if (MO.isMCSymbol() && (MO.getTargetFlags() & MipsII::MO_JALR)) {
156 MCSymbol *Callee = MO.getMCSymbol();
157 if (Callee && !Callee->getName().empty()) {
158 MCSymbol *Sym = GetExternalSymbolSymbol(Callee->getName());
159 MCSymbol *OffsetLabel = OutContext.createTempSymbol();
160 const MCExpr *OffsetExpr =
162 const MCExpr *CaleeExpr = MCSymbolRefExpr::create(Sym, OutContext);
163 OutStreamer.emitRelocDirective(
164 *OffsetExpr,
165 Subtarget.inMicroMipsMode() ? "R_MICROMIPS_JALR" : "R_MIPS_JALR",
166 CaleeExpr);
167 OutStreamer.emitLabel(OffsetLabel);
168 return;
169 }
170 }
171 }
172}
173
175 // FIXME: Enable feature predicate checks once all the test pass.
176 // Mips_MC::verifyInstructionPredicates(MI->getOpcode(),
177 // getSubtargetInfo().getFeatureBits());
178
179 MipsTargetStreamer &TS = getTargetStreamer();
180 unsigned Opc = MI->getOpcode();
182
183 if (MI->isDebugValue()) {
185 raw_svector_ostream OS(Str);
186
188 return;
189 }
190 if (MI->isDebugLabel())
191 return;
192
193 // If we just ended a constant pool, mark it as such.
194 if (InConstantPool && Opc != Mips::CONSTPOOL_ENTRY) {
195 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
196 InConstantPool = false;
197 }
198 if (Opc == Mips::CONSTPOOL_ENTRY) {
199 // CONSTPOOL_ENTRY - This instruction represents a floating
200 // constant pool in the function. The first operand is the ID#
201 // for this instruction, the second is the index into the
202 // MachineConstantPool that this is, the third is the size in
203 // bytes of this constant pool entry.
204 // The required alignment is specified on the basic block holding this MI.
205 //
206 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
207 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
208
209 // If this is the first entry of the pool, mark it.
210 if (!InConstantPool) {
211 OutStreamer->emitDataRegion(MCDR_DataRegion);
212 InConstantPool = true;
213 }
214
215 OutStreamer->emitLabel(GetCPISymbol(LabelId));
216
217 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
220 else
221 emitGlobalConstant(MF->getDataLayout(), MCPE.Val.ConstVal);
222 return;
223 }
224
225 switch (Opc) {
226 case Mips::PATCHABLE_FUNCTION_ENTER:
228 return;
229 case Mips::PATCHABLE_FUNCTION_EXIT:
231 return;
232 case Mips::PATCHABLE_TAIL_CALL:
234 return;
235 }
236
237 if (Subtarget->getMCCLOpts().jalr_reloc &&
238 (MI->isReturn() || MI->isCall() || MI->isIndirectBranch())) {
240 }
241
243 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
244
245 do {
246 // Do any auto-generated pseudo lowerings.
247 if (MCInst OutInst; lowerPseudoInstExpansion(&*I, OutInst)) {
248 EmitToStreamer(*OutStreamer, OutInst);
249 continue;
250 }
251
252 // Skip the BUNDLE pseudo instruction and lower the contents
253 if (I->isBundle())
254 continue;
255
256 if (I->getOpcode() == Mips::PseudoReturn ||
257 I->getOpcode() == Mips::PseudoReturn64 ||
258 I->getOpcode() == Mips::PseudoIndirectBranch ||
259 I->getOpcode() == Mips::PseudoIndirectBranch64 ||
260 I->getOpcode() == Mips::TAILCALLREG ||
261 I->getOpcode() == Mips::TAILCALLREG64) {
262 emitPseudoIndirectBranch(*OutStreamer, &*I);
263 continue;
264 }
265
266 // The inMips16Mode() test is not permanent.
267 // Some instructions are marked as pseudo right now which
268 // would make the test fail for the wrong reason but
269 // that will be fixed soon. We need this here because we are
270 // removing another test for this situation downstream in the
271 // callchain.
272 //
273 if (I->isPseudo() && !Subtarget->inMips16Mode()
274 && !isLongBranchPseudo(I->getOpcode()))
275 llvm_unreachable("Pseudo opcode found in emitInstruction()");
276
277 MCInst TmpInst0;
278 MCInstLowering.Lower(&*I, TmpInst0);
279 EmitToStreamer(*OutStreamer, TmpInst0);
280 } while ((++I != E) && I->isInsideBundle()); // Delay slot check
281}
282
283//===----------------------------------------------------------------------===//
284//
285// Mips Asm Directives
286//
287// -- Frame directive "frame Stackpointer, Stacksize, RARegister"
288// Describe the stack frame.
289//
290// -- Mask directives "(f)mask bitmask, offset"
291// Tells the assembler which registers are saved and where.
292// bitmask - contain a little endian bitset indicating which registers are
293// saved on function prologue (e.g. with a 0x80000000 mask, the
294// assembler knows the register 31 (RA) is saved at prologue.
295// offset - the position before stack pointer subtraction indicating where
296// the first saved register on prologue is located. (e.g. with a
297//
298// Consider the following function prologue:
299//
300// .frame $fp,48,$ra
301// .mask 0xc0000000,-8
302// addiu $sp, $sp, -48
303// sw $ra, 40($sp)
304// sw $fp, 36($sp)
305//
306// With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
307// 30 (FP) are saved at prologue. As the save order on prologue is from
308// left to right, RA is saved first. A -8 offset means that after the
309// stack pointer subtration, the first register in the mask (RA) will be
310// saved at address 48-8=40.
311//
312//===----------------------------------------------------------------------===//
313
314//===----------------------------------------------------------------------===//
315// Mask directives
316//===----------------------------------------------------------------------===//
317
318// Create a bitmask with all callee saved registers for CPU or Floating Point
319// registers. For CPU registers consider RA, GP and FP for saving if necessary.
321 // CPU and FPU Saved Registers Bitmasks
322 unsigned CPUBitmask = 0, FPUBitmask = 0;
323 int CPUTopSavedRegOff, FPUTopSavedRegOff;
324
325 // Set the CPU and FPU Bitmasks
326 const MachineFrameInfo &MFI = MF->getFrameInfo();
327 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
328 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
329 // size of stack area to which FP callee-saved regs are saved.
330 unsigned CPURegSize = TRI->getRegSizeInBits(Mips::GPR32RegClass) / 8;
331 unsigned FGR32RegSize = TRI->getRegSizeInBits(Mips::FGR32RegClass) / 8;
332 unsigned AFGR64RegSize = TRI->getRegSizeInBits(Mips::AFGR64RegClass) / 8;
333 bool HasAFGR64Reg = false;
334 unsigned CSFPRegsSize = 0;
335
336 for (const auto &I : CSI) {
337 Register Reg = I.getReg();
338 unsigned RegNum = TRI->getEncodingValue(Reg);
339
340 // If it's a floating point register, set the FPU Bitmask.
341 // If it's a general purpose register, set the CPU Bitmask.
342 if (Mips::FGR32RegClass.contains(Reg)) {
343 FPUBitmask |= (1 << RegNum);
344 CSFPRegsSize += FGR32RegSize;
345 } else if (Mips::AFGR64RegClass.contains(Reg)) {
346 FPUBitmask |= (3 << RegNum);
347 CSFPRegsSize += AFGR64RegSize;
348 HasAFGR64Reg = true;
349 } else if (Mips::GPR32RegClass.contains(Reg))
350 CPUBitmask |= (1 << RegNum);
351 }
352
353 // FP Regs are saved right below where the virtual frame pointer points to.
354 FPUTopSavedRegOff = FPUBitmask ?
355 (HasAFGR64Reg ? -AFGR64RegSize : -FGR32RegSize) : 0;
356
357 // CPU Regs are saved below FP Regs.
358 CPUTopSavedRegOff = CPUBitmask ? -CSFPRegsSize - CPURegSize : 0;
359
360 MipsTargetStreamer &TS = getTargetStreamer();
361 // Print CPUBitmask
362 TS.emitMask(CPUBitmask, CPUTopSavedRegOff);
363
364 // Print FPUBitmask
365 TS.emitFMask(FPUBitmask, FPUTopSavedRegOff);
366}
367
368//===----------------------------------------------------------------------===//
369// Frame and Set directives
370//===----------------------------------------------------------------------===//
371
372/// Frame Directive
374 const TargetRegisterInfo &RI = *MF->getSubtarget().getRegisterInfo();
375
376 Register stackReg = RI.getFrameRegister(*MF);
377 MCRegister returnReg = RI.getRARegister();
378 unsigned stackSize = MF->getFrameInfo().getStackSize();
379
380 getTargetStreamer().emitFrame(stackReg, stackSize, returnReg);
381}
382
383/// Emit Set directives.
384static const char *getABIString(const MipsABIInfo &ABI) {
385 switch (ABI.GetEnumValue()) {
386 case MipsABIInfo::ABI::O32: return "abi32";
387 case MipsABIInfo::ABI::N32: return "abiN32";
388 case MipsABIInfo::ABI::N64: return "abi64";
389 default: llvm_unreachable("Unknown Mips ABI");
390 }
391}
392
394 MipsTargetStreamer &TS = getTargetStreamer();
395
396 if (Subtarget->inMicroMipsMode()) {
398 TS.setUsesMicroMips();
400 } else
402
403 if (Subtarget->inMips16Mode())
405 else
407
409 OutStreamer->emitLabel(CurrentFnSym);
410}
411
412/// EmitFunctionBodyStart - Targets can override this to emit stuff before
413/// the first basic block in the function.
415 MipsTargetStreamer &TS = getTargetStreamer();
416
417 MCInstLowering.Initialize(&MF->getContext());
418
419 bool IsNakedFunction = MF->getFunction().hasFnAttribute(Attribute::Naked);
420 if (!IsNakedFunction)
422
423 if (!IsNakedFunction)
425
426 if (!Subtarget->inMips16Mode()) {
430 }
431}
432
433/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
434/// the last basic block in the function.
436 MipsTargetStreamer &TS = getTargetStreamer();
437
438 // There are instruction for this macros, but they must
439 // always be at the function end, and we can't emit and
440 // break with BB logic.
441 if (!Subtarget->inMips16Mode()) {
445 }
446 TS.emitDirectiveEnd(CurrentFnSym->getName());
447 // Make sure to terminate any constant pools that were at the end
448 // of the function.
449 if (!InConstantPool)
450 return;
451 InConstantPool = false;
452 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
453}
454
457 MipsTargetStreamer &TS = getTargetStreamer();
458 if (MBB.empty())
460}
461
462// Print out an operand for an inline asm expression.
464 const char *ExtraCode, raw_ostream &O) {
465 // Does this asm operand have a single letter operand modifier?
466 if (ExtraCode && ExtraCode[0]) {
467 if (ExtraCode[1] != 0) return true; // Unknown modifier.
468
469 const MachineOperand &MO = MI->getOperand(OpNum);
470 switch (ExtraCode[0]) {
471 default:
472 // See if this is a generic print operand
473 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
474 case 'X': // hex const int
475 if (!MO.isImm())
476 return true;
477 O << "0x" << Twine::utohexstr(MO.getImm());
478 return false;
479 case 'x': // hex const int (low 16 bits)
480 if (!MO.isImm())
481 return true;
482 O << "0x" << Twine::utohexstr(MO.getImm() & 0xffff);
483 return false;
484 case 'd': // decimal const int
485 if (!MO.isImm())
486 return true;
487 O << MO.getImm();
488 return false;
489 case 'm': // decimal const int minus 1
490 if (!MO.isImm())
491 return true;
492 O << MO.getImm() - 1;
493 return false;
494 case 'y': // exact log2
495 if (!MO.isImm())
496 return true;
497 if (!isPowerOf2_64(MO.getImm()))
498 return true;
499 O << Log2_64(MO.getImm());
500 return false;
501 case 'z':
502 // $0 if zero, regular printing otherwise
503 if (MO.isImm() && MO.getImm() == 0) {
504 O << "$0";
505 return false;
506 }
507 // If not, call printOperand as normal.
508 break;
509 case 'D': // Second part of a double word register operand
510 case 'L': // Low order register of a double word register operand
511 case 'M': // High order register of a double word register operand
512 {
513 if (OpNum == 0)
514 return true;
515 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
516 if (!FlagsOP.isImm())
517 return true;
518 const InlineAsm::Flag Flags(FlagsOP.getImm());
519 const unsigned NumVals = Flags.getNumOperandRegisters();
520 // Number of registers represented by this operand. We are looking
521 // for 2 for 32 bit mode and 1 for 64 bit mode.
522 if (NumVals != 2) {
523 if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
524 Register Reg = MO.getReg();
525 O << '$' << MipsInstPrinter::getRegisterName(Reg);
526 return false;
527 }
528 return true;
529 }
530
531 unsigned RegOp = OpNum;
532 if (!Subtarget->isGP64bit()){
533 // Endianness reverses which register holds the high or low value
534 // between M and L.
535 switch(ExtraCode[0]) {
536 case 'M':
537 RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
538 break;
539 case 'L':
540 RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
541 break;
542 case 'D': // Always the second part
543 RegOp = OpNum + 1;
544 }
545 if (RegOp >= MI->getNumOperands())
546 return true;
547 const MachineOperand &MO = MI->getOperand(RegOp);
548 if (!MO.isReg())
549 return true;
550 Register Reg = MO.getReg();
551 O << '$' << MipsInstPrinter::getRegisterName(Reg);
552 return false;
553 }
554 break;
555 }
556 case 'w': {
558 if (w != Mips::NoRegister) {
560 return false;
561 }
562 break;
563 }
564 }
565 }
566
567 printOperand(MI, OpNum, O);
568 return false;
569}
570
572 unsigned OpNum,
573 const char *ExtraCode,
574 raw_ostream &O) {
575 assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
576 const MachineOperand &BaseMO = MI->getOperand(OpNum);
577 const MachineOperand &OffsetMO = MI->getOperand(OpNum + 1);
578 assert(BaseMO.isReg() &&
579 "Unexpected base pointer for inline asm memory operand.");
580 assert(OffsetMO.isImm() &&
581 "Unexpected offset for inline asm memory operand.");
582 int Offset = OffsetMO.getImm();
583
584 // Currently we are expecting either no ExtraCode or 'D','M','L'.
585 if (ExtraCode) {
586 switch (ExtraCode[0]) {
587 case 'D':
588 Offset += 4;
589 break;
590 case 'M':
591 if (Subtarget->isLittle())
592 Offset += 4;
593 break;
594 case 'L':
595 if (!Subtarget->isLittle())
596 Offset += 4;
597 break;
598 default:
599 return true; // Unknown modifier.
600 }
601 }
602
603 O << Offset << "($" << MipsInstPrinter::getRegisterName(BaseMO.getReg())
604 << ")";
605
606 return false;
607}
608
610 raw_ostream &O) {
611 const MachineOperand &MO = MI->getOperand(opNum);
612 bool closeP = false;
613
614 if (MO.getTargetFlags())
615 closeP = true;
616
617 switch(MO.getTargetFlags()) {
618 case MipsII::MO_GPREL: O << "%gp_rel("; break;
619 case MipsII::MO_GOT_CALL: O << "%call16("; break;
620 case MipsII::MO_GOT: O << "%got("; break;
621 case MipsII::MO_ABS_HI: O << "%hi("; break;
622 case MipsII::MO_ABS_LO: O << "%lo("; break;
623 case MipsII::MO_HIGHER: O << "%higher("; break;
624 case MipsII::MO_HIGHEST: O << "%highest(("; break;
625 case MipsII::MO_TLSGD: O << "%tlsgd("; break;
626 case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
627 case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
628 case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
629 case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
630 case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
631 case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
632 case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
633 case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
634 }
635
636 switch (MO.getType()) {
638 O << '$'
640 break;
641
643 O << MO.getImm();
644 break;
645
647 MO.getMBB()->getSymbol()->print(O, MAI);
648 return;
649
651 PrintSymbolOperand(MO, O);
652 break;
653
656 O << BA->getName();
657 break;
658 }
659
661 O << getDataLayout().getInternalSymbolPrefix() << "CPI"
662 << getFunctionNumber() << "_" << MO.getIndex();
663 if (MO.getOffset())
664 O << "+" << MO.getOffset();
665 break;
666
667 default:
668 llvm_unreachable("<unknown operand type>");
669 }
670
671 if (closeP) O << ")";
672}
673
675 raw_ostream &O) {
676 const MachineOperand &MO = MI->getOperand(opNum);
678}
679
681printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
682 for (int i = opNum, e = MI->getNumOperands(); i != e; ++i) {
683 if (i != opNum) O << ", ";
684 printOperand(MI, i, O);
685 }
686}
687
689 const Triple &TT = M.getTargetTriple();
690
691 if (TT.isOSBinFormatELF()) {
692 MipsTargetStreamer &TS = getTargetStreamer();
693
694 // MipsTargetStreamer has an initialization order problem when emitting an
695 // object file directly (see MipsTargetELFStreamer for full details). Work
696 // around it by re-initializing the PIC state here.
697 TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
698
699 // Try to get target-features from the first function.
700 StringRef FS = TM.getTargetFeatureString();
701 Module::iterator F = M.begin();
702 if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
703 FS = F->getFnAttribute("target-features").getValueAsString();
704
705 std::string strFS = FS.str();
706 if (M.size() && F->getFnAttribute("use-soft-float").getValueAsBool())
707 strFS += strFS.empty() ? "+soft-float" : ",+soft-float";
708
709 // Compute MIPS architecture attributes based on the default subtarget
710 // that we'd have constructed.
711 // FIXME: For ifunc related functions we could iterate over and look
712 // for a feature string that doesn't match the default one.
713 StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
714 const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
715 const MipsSubtarget STI(TT, CPU, StringRef(strFS), MTM.getTargetABIName(M),
716 MTM.isLittleEndian(), MTM, std::nullopt);
717
718 bool IsABICalls = STI.isABICalls();
719 const MipsABIInfo &ABI = STI.getABI();
720 if (IsABICalls) {
722 // FIXME: This condition should be a lot more complicated that it is here.
723 // Ideally it should test for properties of the ABI and not the ABI
724 // itself.
725 // For the moment, I'm only correcting enough to make MIPS-IV work.
726 if (!isPositionIndependent() && STI.hasSym32())
728 }
729
730 // Tell the assembler which ABI we are using
731 std::string SectionName = std::string(".mdebug.") + getABIString(ABI);
732 OutStreamer->switchSection(
733 OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
734
735 // NaN: At the moment we only support:
736 // 1. .nan legacy (default)
737 // 2. .nan 2008
739
740 // TODO: handle O64 ABI
741
742 TS.updateABIInfo(STI);
743
744 // We should always emit a '.module fp=...' but binutils 2.24 does not
745 // accept it. We therefore emit it when it contradicts the ABI defaults
746 // (-mfpxx or -mfp64) and omit it otherwise.
747 // Single-float uses its own ABI even when 64-bit FPRs are enabled.
748 if ((ABI.IsO32() && !STI.isSingleFloat() &&
749 (STI.isABI_FPXX() || STI.isFP64bit())) ||
750 STI.useSoftFloat())
752
753 // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
754 // accept it. We therefore emit it when it contradicts the default or an
755 // option has changed the default (i.e. FPXX) and omit it otherwise.
756 if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
758
759 // Switch to the .text section.
760 OutStreamer->switchSection(getObjFileLowering().getTextSection());
761 }
762}
763
765 MipsTargetStreamer &TS = getTargetStreamer();
766
767 // GCC's choice of assembler options for inline assembly code ('at', 'macro'
768 // and 'reorder') is different from LLVM's choice for generated code ('noat',
769 // 'nomacro' and 'noreorder').
770 // In order to maintain compatibility with inline assembly code which depends
771 // on GCC's assembler options being used, we have to switch to those options
772 // for the duration of the inline assembly block and then switch back.
777 OutStreamer->addBlankLine();
778}
779
780void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
781 const MCSubtargetInfo *EndInfo,
782 const MachineInstr *MI) {
783 OutStreamer->addBlankLine();
784 getTargetStreamer().emitDirectiveSetPop();
785}
786
787void MipsAsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
788 const MachineBasicBlock *MBB,
789 unsigned uid) const {
790 MCSymbol *MBBSym = MBB->getSymbol();
791 switch (MJTI.getEntryKind()) {
795 break;
797 // Each entry is a GP-relative value targeting the block symbol.
798 getTargetStreamer().emitGPRel32Value(
800 break;
802 getTargetStreamer().emitGPRel64Value(
804 break;
805 default:
807 }
808}
809
810void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
811 MCInst I;
812 I.setOpcode(Mips::JAL);
813 I.addOperand(
815 OutStreamer->emitInstruction(I, STI);
816}
817
818void MipsAsmPrinter::EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode,
819 unsigned Reg) {
820 MCInst I;
821 I.setOpcode(Opcode);
822 I.addOperand(MCOperand::createReg(Reg));
823 OutStreamer->emitInstruction(I, STI);
824}
825
826void MipsAsmPrinter::EmitInstrRegReg(const MCSubtargetInfo &STI,
827 unsigned Opcode, unsigned Reg1,
828 unsigned Reg2) {
829 MCInst I;
830 //
831 // Because of the current td files for Mips32, the operands for MTC1
832 // appear backwards from their normal assembly order. It's not a trivial
833 // change to fix this in the td file so we adjust for it here.
834 //
835 if (Opcode == Mips::MTC1) {
836 unsigned Temp = Reg1;
837 Reg1 = Reg2;
838 Reg2 = Temp;
839 }
840 I.setOpcode(Opcode);
841 I.addOperand(MCOperand::createReg(Reg1));
842 I.addOperand(MCOperand::createReg(Reg2));
843 OutStreamer->emitInstruction(I, STI);
844}
845
846void MipsAsmPrinter::EmitInstrRegRegReg(const MCSubtargetInfo &STI,
847 unsigned Opcode, unsigned Reg1,
848 unsigned Reg2, unsigned Reg3) {
849 MCInst I;
850 I.setOpcode(Opcode);
851 I.addOperand(MCOperand::createReg(Reg1));
852 I.addOperand(MCOperand::createReg(Reg2));
853 I.addOperand(MCOperand::createReg(Reg3));
854 OutStreamer->emitInstruction(I, STI);
855}
856
857void MipsAsmPrinter::EmitMovFPIntPair(const MCSubtargetInfo &STI,
858 unsigned MovOpc, unsigned Reg1,
859 unsigned Reg2, unsigned FPReg1,
860 unsigned FPReg2, bool LE) {
861 if (!LE) {
862 unsigned temp = Reg1;
863 Reg1 = Reg2;
864 Reg2 = temp;
865 }
866 EmitInstrRegReg(STI, MovOpc, Reg1, FPReg1);
867 EmitInstrRegReg(STI, MovOpc, Reg2, FPReg2);
868}
869
870void MipsAsmPrinter::EmitSwapFPIntParams(const MCSubtargetInfo &STI,
872 bool LE, bool ToFP) {
873 using namespace Mips16HardFloatInfo;
874
875 const MipsABIInfo &ABI = Subtarget->getABI();
876 unsigned MovOpc = ToFP ? Mips::MTC1 : Mips::MFC1;
877 switch (PV) {
878 case FSig:
879 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
880 break;
881 case FFSig:
882 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
883 Mips::F14, LE);
884 break;
885 case FDSig:
886 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
887 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
888 Mips::F15, LE);
889 break;
890 case DSig:
891 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
892 Mips::F13, LE);
893 break;
894 case DDSig:
895 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
896 Mips::F13, LE);
897 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
898 Mips::F15, LE);
899 break;
900 case DFSig:
901 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
902 Mips::F13, LE);
903 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(2), Mips::F14);
904 break;
905 case NoSig:
906 return;
907 }
908}
909
910void MipsAsmPrinter::EmitSwapFPIntRetval(
912 bool LE) {
913 using namespace Mips16HardFloatInfo;
914
915 const MipsABIInfo &ABI = Subtarget->getABI();
916 unsigned MovOpc = Mips::MFC1;
917 switch (RV) {
918 case FRet:
919 EmitInstrRegReg(STI, MovOpc, ABI.getReturnReg(0), Mips::F0);
920 break;
921 case DRet:
922 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
923 Mips::F0, Mips::F1, LE);
924 break;
925 case CFRet:
926 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
927 Mips::F0, Mips::F1, LE);
928 break;
929 case CDRet:
930 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
931 Mips::F0, Mips::F1, LE);
932 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F2,
933 Mips::F3, LE);
934 break;
935 case NoFPRet:
936 break;
937 }
938}
939
940void MipsAsmPrinter::EmitFPCallStub(
941 const char *Symbol, const Mips16HardFloatInfo::FuncSignature *Signature) {
942 using namespace Mips16HardFloatInfo;
943
944 MCSymbol *MSymbol = OutContext.getOrCreateSymbol(StringRef(Symbol));
946 // Construct a local MCSubtargetInfo here.
947 // This is because the MachineFunction won't exist (but have not yet been
948 // freed) and since we're at the global level we can use the default
949 // constructed subtarget.
950 std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
951 TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
952
953 //
954 // .global xxxx
955 //
956 OutStreamer->emitSymbolAttribute(MSymbol, MCSA_Global);
957 const char *RetType;
958 //
959 // make the comment field identifying the return and parameter
960 // types of the floating point stub
961 // # Stub function to call rettype xxxx (params)
962 //
963 switch (Signature->RetSig) {
964 case FRet:
965 RetType = "float";
966 break;
967 case DRet:
968 RetType = "double";
969 break;
970 case CFRet:
971 RetType = "complex";
972 break;
973 case CDRet:
974 RetType = "double complex";
975 break;
976 case NoFPRet:
977 RetType = "";
978 break;
979 }
980 const char *Parms;
981 switch (Signature->ParamSig) {
982 case FSig:
983 Parms = "float";
984 break;
985 case FFSig:
986 Parms = "float, float";
987 break;
988 case FDSig:
989 Parms = "float, double";
990 break;
991 case DSig:
992 Parms = "double";
993 break;
994 case DDSig:
995 Parms = "double, double";
996 break;
997 case DFSig:
998 Parms = "double, float";
999 break;
1000 case NoSig:
1001 Parms = "";
1002 break;
1003 }
1004 OutStreamer->AddComment("\t# Stub function to call " + Twine(RetType) + " " +
1005 Twine(Symbol) + " (" + Twine(Parms) + ")");
1006 //
1007 // probably not necessary but we save and restore the current section state
1008 //
1009 OutStreamer->pushSection();
1010 //
1011 // .section mips16.call.fpxxxx,"ax",@progbits
1012 //
1013 MCSectionELF *M = OutContext.getELFSection(
1014 ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
1016 OutStreamer->switchSection(M);
1017 //
1018 // .align 2
1019 //
1020 OutStreamer->emitValueToAlignment(Align(4));
1021 MipsTargetStreamer &TS = getTargetStreamer();
1022 //
1023 // .set nomips16
1024 // .set nomicromips
1025 //
1028 //
1029 // .ent __call_stub_fp_xxxx
1030 // .type __call_stub_fp_xxxx,@function
1031 // __call_stub_fp_xxxx:
1032 //
1033 std::string x = "__call_stub_fp_" + std::string(Symbol);
1034 MCSymbol *Stub = OutContext.getOrCreateSymbol(StringRef(x));
1035 TS.emitDirectiveEnt(*Stub);
1036 MCSymbol *MType =
1037 OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
1038 OutStreamer->emitSymbolAttribute(MType, MCSA_ELF_TypeFunction);
1039 OutStreamer->emitLabel(Stub);
1040
1041 // Only handle non-pic for now.
1043 "should not be here if we are compiling pic");
1045 //
1046 // We need to add a MipsMCExpr class to MCTargetDesc to fully implement
1047 // stubs without raw text but this current patch is for compiler generated
1048 // functions and they all return some value.
1049 // The calling sequence for non pic is different in that case and we need
1050 // to implement %lo and %hi in order to handle the case of no return value
1051 // See the corresponding method in Mips16HardFloat for details.
1052 //
1053 // mov the return address to S2.
1054 // we have no stack space to store it and we are about to make another call.
1055 // We need to make sure that the enclosing function knows to save S2
1056 // This should have already been handled.
1057 //
1058 // Mov $18, $31
1059
1060 EmitInstrRegRegReg(*STI, Mips::OR, Subtarget->getABI().getSavedReg(2),
1061 Mips::RA, Mips::R0);
1062
1063 EmitSwapFPIntParams(*STI, Signature->ParamSig, LE, true);
1064
1065 // Jal xxxx
1066 //
1067 EmitJal(*STI, MSymbol);
1068
1069 // fix return values
1070 EmitSwapFPIntRetval(*STI, Signature->RetSig, LE);
1071 //
1072 // do the return
1073 // if (Signature->RetSig == NoFPRet)
1074 // llvm_unreachable("should not be any stubs here with no return value");
1075 // else
1076 EmitInstrReg(*STI, Mips::JR, Subtarget->getABI().getSavedReg(2));
1077
1078 MCSymbol *Tmp = OutContext.createTempSymbol();
1079 OutStreamer->emitLabel(Tmp);
1080 const MCSymbolRefExpr *E = MCSymbolRefExpr::create(Stub, OutContext);
1081 const MCSymbolRefExpr *T = MCSymbolRefExpr::create(Tmp, OutContext);
1082 const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
1083 OutStreamer->emitELFSize(Stub, T_min_E);
1084 TS.emitDirectiveEnd(x);
1085 OutStreamer->popSection();
1086}
1087
1089 // Emit needed stubs
1090 //
1091 for (std::map<
1092 const char *,
1094 it = StubsNeeded.begin();
1095 it != StubsNeeded.end(); ++it) {
1096 const char *Symbol = it->first;
1097 const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
1098 EmitFPCallStub(Symbol, Signature);
1099 }
1100 // return to the text section
1101 OutStreamer->switchSection(OutContext.getObjectFileInfo()->getTextSection());
1102}
1103
1104void MipsAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) {
1105 const uint8_t NoopsInSledCount = Subtarget->isGP64bit() ? 15 : 11;
1106 // For mips32 we want to emit the following pattern:
1107 //
1108 // .Lxray_sled_N:
1109 // ALIGN
1110 // B .tmpN
1111 // 11 NOP instructions (44 bytes)
1112 // ADDIU T9, T9, 52
1113 // .tmpN
1114 //
1115 // We need the 44 bytes (11 instructions) because at runtime, we'd
1116 // be patching over the full 48 bytes (12 instructions) with the following
1117 // pattern:
1118 //
1119 // ADDIU SP, SP, -8
1120 // NOP
1121 // SW RA, 4(SP)
1122 // SW T9, 0(SP)
1123 // LUI T9, %hi(__xray_FunctionEntry/Exit)
1124 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1125 // LUI T0, %hi(function_id)
1126 // JALR T9
1127 // ORI T0, T0, %lo(function_id)
1128 // LW T9, 0(SP)
1129 // LW RA, 4(SP)
1130 // ADDIU SP, SP, 8
1131 //
1132 // We add 52 bytes to t9 because we want to adjust the function pointer to
1133 // the actual start of function i.e. the address just after the noop sled.
1134 // We do this because gp displacement relocation is emitted at the start of
1135 // of the function i.e after the nop sled and to correctly calculate the
1136 // global offset table address, t9 must hold the address of the instruction
1137 // containing the gp displacement relocation.
1138 // FIXME: Is this correct for the static relocation model?
1139 //
1140 // For mips64 we want to emit the following pattern:
1141 //
1142 // .Lxray_sled_N:
1143 // ALIGN
1144 // B .tmpN
1145 // 15 NOP instructions (60 bytes)
1146 // .tmpN
1147 //
1148 // We need the 60 bytes (15 instructions) because at runtime, we'd
1149 // be patching over the full 64 bytes (16 instructions) with the following
1150 // pattern:
1151 //
1152 // DADDIU SP, SP, -16
1153 // NOP
1154 // SD RA, 8(SP)
1155 // SD T9, 0(SP)
1156 // LUI T9, %highest(__xray_FunctionEntry/Exit)
1157 // ORI T9, T9, %higher(__xray_FunctionEntry/Exit)
1158 // DSLL T9, T9, 16
1159 // ORI T9, T9, %hi(__xray_FunctionEntry/Exit)
1160 // DSLL T9, T9, 16
1161 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1162 // LUI T0, %hi(function_id)
1163 // JALR T9
1164 // ADDIU T0, T0, %lo(function_id)
1165 // LD T9, 0(SP)
1166 // LD RA, 8(SP)
1167 // DADDIU SP, SP, 16
1168 //
1169 OutStreamer->emitCodeAlignment(Align(4), getSubtargetInfo());
1170 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1171 OutStreamer->emitLabel(CurSled);
1173
1174 // Emit "B .tmpN" instruction, which jumps over the nop sled to the actual
1175 // start of function
1176 const MCExpr *TargetExpr = MCSymbolRefExpr::create(Target, OutContext);
1178 *OutStreamer,
1179 MCInstBuilder(Mips::BEQ).addReg(Mips::R0).addReg(Mips::R0).addExpr(
1180 TargetExpr));
1181
1182 for (int8_t I = 0; I < NoopsInSledCount; I++)
1184 *OutStreamer,
1185 MCInstBuilder(Mips::SLL).addReg(Mips::R0).addReg(Mips::R0).addImm(0));
1186
1187 OutStreamer->emitLabel(Target);
1188
1189 if (!Subtarget->isGP64bit()) {
1191 .addReg(Mips::R25)
1192 .addReg(Mips::R25)
1193 .addImm(0x34));
1194 }
1195
1196 recordSled(CurSled, MI, Kind, 2);
1197}
1198
1202
1206
1210
1212 raw_ostream &OS) {
1213 // TODO: implement
1214}
1215
1216// Emit .dtprelword or .dtpreldword directive
1217// and value for debug thread local expression.
1218void MipsAsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
1219 if (auto *MipsExpr = dyn_cast<MCSpecifierExpr>(Value)) {
1220 if (MipsExpr && MipsExpr->getSpecifier() == Mips::S_DTPREL) {
1221 switch (Size) {
1222 case 4:
1223 getTargetStreamer().emitDTPRel32Value(MipsExpr->getSubExpr());
1224 break;
1225 case 8:
1226 getTargetStreamer().emitDTPRel64Value(MipsExpr->getSubExpr());
1227 break;
1228 default:
1229 llvm_unreachable("Unexpected size of expression value.");
1230 }
1231 return;
1232 }
1233 }
1235}
1236
1237bool MipsAsmPrinter::isLongBranchPseudo(int Opcode) const {
1238 return (Opcode == Mips::LONG_BRANCH_LUi
1239 || Opcode == Mips::LONG_BRANCH_LUi2Op
1240 || Opcode == Mips::LONG_BRANCH_LUi2Op_64
1241 || Opcode == Mips::LONG_BRANCH_ADDiu
1242 || Opcode == Mips::LONG_BRANCH_ADDiu2Op
1243 || Opcode == Mips::LONG_BRANCH_DADDiu
1244 || Opcode == Mips::LONG_BRANCH_DADDiu2Op);
1245}
1246
1247char MipsAsmPrinter::ID = 0;
1248
1249INITIALIZE_PASS(MipsAsmPrinter, "mips-asm-printer", "Mips Assembly Printer",
1250 false, false)
1251
1252// Force static initialization.
1253extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1254LLVMInitializeMipsAsmPrinter() {
1259}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
This file contains the simple types necessary to represent the attributes associated with functions a...
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Register const TargetRegisterInfo * TRI
@ CDRet
@ NoFPRet
@ CFRet
@ DDSig
@ DFSig
@ FDSig
@ NoSig
@ FFSig
#define T
static const char * getABIString(const MipsABIInfo &ABI)
Emit Set directives.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:480
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
virtual void emitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
unsigned getPointerSize() const
Return the pointer size in bytes from the target triple.
Definition AsmPrinter.h:378
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:98
void emitXRayTable()
Emit a table with all XRay instrumentation points.
virtual void emitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:113
virtual void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
unsigned getFunctionNumber() const
Return a unique ID for the current function.
void emitGlobalConstant(const DataLayout &DL, const Constant *CV, AliasMapTy *AliasList=nullptr)
EmitGlobalConstant - Print a general LLVM constant to the .s file.
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition AsmPrinter.h:135
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:105
bool isPositionIndependent() const
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:475
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:110
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:101
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
const DataLayout & getDataLayout() const
Return information about data layout.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
bool isLittleEndian() const
Layout endianness...
Definition DataLayout.h:217
StringRef getInternalSymbolPrefix() const
Definition DataLayout.h:308
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:40
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
bool isValid() const
Definition MCInst.h:64
MCRegister getRARegister() const
This method should return the register where the return address can be found.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:59
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Instructions::const_iterator const_instr_iterator
This class is a data container for one entry in a MachineConstantPool.
union llvm::MachineConstantPoolEntry::@004270020304201266316354007027341142157160323045 Val
The constant itself.
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
MachineConstantPoolValue * MachineCPVal
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Representation of each machine instruction.
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Register getReg() const
getReg - Returns the register number.
MCSymbol * getMCSymbol() const
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
int64_t getOffset() const
Return the offset from the symbol in this operand.
void emitFunctionBodyStart() override
EmitFunctionBodyStart - Targets can override this to emit stuff before the first basic block in the f...
void emitDebugValue(const MCExpr *Value, unsigned Size) const override
Emit the directive and value for debug thread local expression.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
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)
void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O)
void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O)
void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS)
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
void emitFunctionBodyEnd() override
EmitFunctionBodyEnd - Targets can override this to emit stuff after the last basic block in the funct...
MipsMCInstLower MCInstLowering
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI)
const MipsSubtarget * Subtarget
const MipsFunctionInfo * MipsFI
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI)
void emitFrameDirective()
Frame Directive.
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O)
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
void emitDirectiveRelocJalr(const MachineInstr &MI, MCContext &OutContext, TargetMachine &TM, MCStreamer &OutStreamer, const MipsSubtarget &Subtarget)
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=Mips::NoRegAltName)
MCOperand LowerOperand(const MachineOperand &MO, int64_t offset=0) const
bool isFP64bit() const
bool inMicroMipsMode() const
bool useSoftFloat() const
bool hasMips64r6() const
bool isNaN2008() const
bool useOddSPReg() const
bool hasSym32() const
bool isABI_FPXX() const
bool isABICalls() const
bool isGP64bit() const
bool isSingleFloat() const
const MipsABIInfo & getABI() const
virtual void emitDirectiveSetNoMicroMips()
virtual void emitDirectiveEnd(StringRef Name)
virtual void emitDirectiveEnt(const MCSymbol &Symbol)
virtual void emitDirectiveSetNoMips16()
virtual void setPic(bool Value)
void updateABIInfo(const PredicateLibrary &P)
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff)
virtual void emitDirectiveSetMicroMips()
virtual void emitDirectiveModuleOddSPReg()
virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff)
virtual void emitDirectiveSetNoReorder()
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
FunctionListType::iterator iterator
The Function iterators.
Definition Module.h:93
Wrapper class representing virtual and physical registers.
Definition Register.h:20
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI std::string lower() const
Primary interface to the complete machine description for the target machine.
StringRef getTargetABIName(const Module &M) const
Returns the effective target ABI name: the "target-abi" module flag if present, otherwise the -target...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ SHF_ALLOC
Definition ELF.h:1259
@ SHF_EXECINSTR
Definition ELF.h:1262
@ SHT_PROGBITS
Definition ELF.h:1157
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
const char * MipsFCCToString(Mips::CondCode CC)
constexpr MCPhysReg RA
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:577
Target & getTheMips64Target()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
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:332
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
static MCRegister getMSARegFromFReg(MCRegister Reg)
Target & getTheMips64elTarget()
Target & getTheMipselTarget()
Target & getTheMipsTarget()
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...