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"
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"
47#include "llvm/IR/Module.h"
48#include "llvm/MC/MCContext.h"
49#include "llvm/MC/MCExpr.h"
50#include "llvm/MC/MCInst.h"
54#include "llvm/MC/MCSymbol.h"
63#include <cassert>
64#include <cstdint>
65#include <map>
66#include <memory>
67#include <string>
68#include <vector>
69
70using namespace llvm;
71
72#define DEBUG_TYPE "mips-asm-printer"
73
74MipsTargetStreamer &MipsAsmPrinter::getTargetStreamer() const {
75 return static_cast<MipsTargetStreamer &>(*OutStreamer->getTargetStreamer());
76}
77
79 Subtarget = &MF.getSubtarget<MipsSubtarget>();
80
81 MipsFI = MF.getInfo<MipsFunctionInfo>();
82 if (Subtarget->inMips16Mode())
83 for (const auto &I : MipsFI->StubsNeeded)
84 StubsNeeded.insert(I);
85 MCP = MF.getConstantPool();
86
88
90
91 return true;
92}
93
94bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
96 return MCOp.isValid();
97}
98
99#include "MipsGenMCPseudoLowering.inc"
100
101// Lower PseudoReturn/PseudoIndirectBranch/PseudoIndirectBranch64 to JR, JR_MM,
102// JALR, or JALR64 as appropriate for the target.
103void MipsAsmPrinter::emitPseudoIndirectBranch(MCStreamer &OutStreamer,
104 const MachineInstr *MI) {
105 bool HasLinkReg = false;
106 bool InMicroMipsMode = Subtarget->inMicroMipsMode();
107 MCInst TmpInst0;
108
109 if (Subtarget->hasMips64r6()) {
110 // MIPS64r6 should use (JALR64 ZERO_64, $rs)
111 TmpInst0.setOpcode(Mips::JALR64);
112 HasLinkReg = true;
113 } else if (Subtarget->hasMips32r6()) {
114 // MIPS32r6 should use (JALR ZERO, $rs)
115 if (InMicroMipsMode)
116 TmpInst0.setOpcode(Mips::JRC16_MMR6);
117 else {
118 TmpInst0.setOpcode(Mips::JALR);
119 HasLinkReg = true;
120 }
121 } else if (Subtarget->inMicroMipsMode())
122 // microMIPS should use (JR_MM $rs)
123 TmpInst0.setOpcode(Mips::JR_MM);
124 else if (Subtarget->hasNanoMips()) {
125 // nanoMIPS should use (JRC_NM $rs)
126 TmpInst0.setOpcode(Mips::JRC_NM);
127 } else {
128 // Everything else should use (JR $rs)
129 TmpInst0.setOpcode(Mips::JR);
130 }
131
132 MCOperand MCOp;
133
134 if (HasLinkReg) {
135 unsigned ZeroReg = Subtarget->isGP64bit() ? Mips::R0_64 : Mips::R0;
136 TmpInst0.addOperand(MCOperand::createReg(ZeroReg));
137 }
138
139 lowerOperand(MI->getOperand(0), MCOp);
140 TmpInst0.addOperand(MCOp);
141
142 EmitToStreamer(OutStreamer, TmpInst0);
143}
144
145// If there is an MO_JALR operand, insert:
146//
147// .reloc tmplabel, R_{MICRO}MIPS_JALR, symbol
148// tmplabel:
149//
150// This is an optimization hint for the linker which may then replace
151// an indirect call with a direct branch.
156 const MipsSubtarget &Subtarget) {
157 for (const MachineOperand &MO :
158 llvm::drop_begin(MI.operands(), MI.getDesc().getNumOperands())) {
159 if (MO.isMCSymbol() && (MO.getTargetFlags() & MipsII::MO_JALR)) {
160 MCSymbol *Callee = MO.getMCSymbol();
161 if (Callee && !Callee->getName().empty()) {
162 MCSymbol *Sym = GetExternalSymbolSymbol(Callee->getName());
163 MCSymbol *OffsetLabel = OutContext.createTempSymbol();
164 const MCExpr *OffsetExpr =
166 const MCExpr *CaleeExpr = MCSymbolRefExpr::create(Sym, OutContext);
167 OutStreamer.emitRelocDirective(
168 *OffsetExpr,
169 Subtarget.inMicroMipsMode() ? "R_MICROMIPS_JALR" : "R_MIPS_JALR",
170 CaleeExpr);
171 OutStreamer.emitLabel(OffsetLabel);
172 return;
173 }
174 }
175 }
176}
177
179 // FIXME: Enable feature predicate checks once all the test pass.
180 // Mips_MC::verifyInstructionPredicates(MI->getOpcode(),
181 // getSubtargetInfo().getFeatureBits());
182
183 MipsTargetStreamer &TS = getTargetStreamer();
184 unsigned Opc = MI->getOpcode();
186
187 if (MI->isDebugValue()) {
189 raw_svector_ostream OS(Str);
190
192 return;
193 }
194 if (MI->isDebugLabel())
195 return;
196
197 // If we just ended a constant pool, mark it as such.
198 if (InConstantPool && Opc != Mips::CONSTPOOL_ENTRY) {
199 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
200 InConstantPool = false;
201 }
202 if (Opc == Mips::CONSTPOOL_ENTRY) {
203 // CONSTPOOL_ENTRY - This instruction represents a floating
204 // constant pool in the function. The first operand is the ID#
205 // for this instruction, the second is the index into the
206 // MachineConstantPool that this is, the third is the size in
207 // bytes of this constant pool entry.
208 // The required alignment is specified on the basic block holding this MI.
209 //
210 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
211 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
212
213 // If this is the first entry of the pool, mark it.
214 if (!InConstantPool) {
215 OutStreamer->emitDataRegion(MCDR_DataRegion);
216 InConstantPool = true;
217 }
218
219 OutStreamer->emitLabel(GetCPISymbol(LabelId));
220
221 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
224 else
225 emitGlobalConstant(MF->getDataLayout(), MCPE.Val.ConstVal);
226 return;
227 }
228
229 switch (Opc) {
230 case Mips::PATCHABLE_FUNCTION_ENTER:
232 return;
233 case Mips::PATCHABLE_FUNCTION_EXIT:
235 return;
236 case Mips::PATCHABLE_TAIL_CALL:
238 return;
239 }
240
241 if (Subtarget->getMCCLOpts().jalr_reloc &&
242 (MI->isReturn() || MI->isCall() || MI->isIndirectBranch())) {
244 }
245
247 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
248
249 do {
250 // Do any auto-generated pseudo lowerings.
251 if (MCInst OutInst; lowerPseudoInstExpansion(&*I, OutInst)) {
252 EmitToStreamer(*OutStreamer, OutInst);
253 continue;
254 }
255
256 // Skip the BUNDLE pseudo instruction and lower the contents
257 if (I->isBundle())
258 continue;
259
260 if (I->getOpcode() == Mips::PseudoReturn ||
261 I->getOpcode() == Mips::PseudoReturn64 ||
262 I->getOpcode() == Mips::PseudoIndirectBranch ||
263 I->getOpcode() == Mips::PseudoIndirectBranch64 ||
264 I->getOpcode() == Mips::TAILCALLREG ||
265 I->getOpcode() == Mips::TAILCALLREG64) {
266 emitPseudoIndirectBranch(*OutStreamer, &*I);
267 continue;
268 }
269
270 // The inMips16Mode() test is not permanent.
271 // Some instructions are marked as pseudo right now which
272 // would make the test fail for the wrong reason but
273 // that will be fixed soon. We need this here because we are
274 // removing another test for this situation downstream in the
275 // callchain.
276 //
277 if (I->isPseudo() && !Subtarget->inMips16Mode()
278 && !isLongBranchPseudo(I->getOpcode()))
279 llvm_unreachable("Pseudo opcode found in emitInstruction()");
280
281 MCInst TmpInst0;
282 MCInstLowering.Lower(&*I, TmpInst0);
283 EmitToStreamer(*OutStreamer, TmpInst0);
284 } while ((++I != E) && I->isInsideBundle()); // Delay slot check
285}
286
287//===----------------------------------------------------------------------===//
288//
289// Mips Asm Directives
290//
291// -- Frame directive "frame Stackpointer, Stacksize, RARegister"
292// Describe the stack frame.
293//
294// -- Mask directives "(f)mask bitmask, offset"
295// Tells the assembler which registers are saved and where.
296// bitmask - contain a little endian bitset indicating which registers are
297// saved on function prologue (e.g. with a 0x80000000 mask, the
298// assembler knows the register 31 (RA) is saved at prologue.
299// offset - the position before stack pointer subtraction indicating where
300// the first saved register on prologue is located. (e.g. with a
301//
302// Consider the following function prologue:
303//
304// .frame $fp,48,$ra
305// .mask 0xc0000000,-8
306// addiu $sp, $sp, -48
307// sw $ra, 40($sp)
308// sw $fp, 36($sp)
309//
310// With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
311// 30 (FP) are saved at prologue. As the save order on prologue is from
312// left to right, RA is saved first. A -8 offset means that after the
313// stack pointer subtration, the first register in the mask (RA) will be
314// saved at address 48-8=40.
315//
316//===----------------------------------------------------------------------===//
317
318//===----------------------------------------------------------------------===//
319// Mask directives
320//===----------------------------------------------------------------------===//
321
322// Create a bitmask with all callee saved registers for CPU or Floating Point
323// registers. For CPU registers consider RA, GP and FP for saving if necessary.
325 // CPU and FPU Saved Registers Bitmasks
326 unsigned CPUBitmask = 0, FPUBitmask = 0;
327 int CPUTopSavedRegOff, FPUTopSavedRegOff;
328
329 // Set the CPU and FPU Bitmasks
330 const MachineFrameInfo &MFI = MF->getFrameInfo();
331 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
332 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
333 // size of stack area to which FP callee-saved regs are saved.
334 unsigned CPURegSize = TRI->getRegSizeInBits(Mips::GPR32RegClass) / 8;
335 unsigned FGR32RegSize = TRI->getRegSizeInBits(Mips::FGR32RegClass) / 8;
336 unsigned AFGR64RegSize = TRI->getRegSizeInBits(Mips::AFGR64RegClass) / 8;
337 bool HasAFGR64Reg = false;
338 unsigned CSFPRegsSize = 0;
339
340 for (const auto &I : CSI) {
341 Register Reg = I.getReg();
342 unsigned RegNum = TRI->getEncodingValue(Reg);
343
344 // If it's a floating point register, set the FPU Bitmask.
345 // If it's a general purpose register, set the CPU Bitmask.
346 if (Mips::FGR32RegClass.contains(Reg)) {
347 FPUBitmask |= (1 << RegNum);
348 CSFPRegsSize += FGR32RegSize;
349 } else if (Mips::AFGR64RegClass.contains(Reg)) {
350 FPUBitmask |= (3 << RegNum);
351 CSFPRegsSize += AFGR64RegSize;
352 HasAFGR64Reg = true;
353 } else if (Mips::GPR32RegClass.contains(Reg))
354 CPUBitmask |= (1 << RegNum);
355 }
356
357 // FP Regs are saved right below where the virtual frame pointer points to.
358 FPUTopSavedRegOff = FPUBitmask ?
359 (HasAFGR64Reg ? -AFGR64RegSize : -FGR32RegSize) : 0;
360
361 // CPU Regs are saved below FP Regs.
362 CPUTopSavedRegOff = CPUBitmask ? -CSFPRegsSize - CPURegSize : 0;
363
364 MipsTargetStreamer &TS = getTargetStreamer();
365 // Print CPUBitmask
366 TS.emitMask(CPUBitmask, CPUTopSavedRegOff);
367
368 // Print FPUBitmask
369 TS.emitFMask(FPUBitmask, FPUTopSavedRegOff);
370}
371
372//===----------------------------------------------------------------------===//
373// Frame and Set directives
374//===----------------------------------------------------------------------===//
375
376/// Frame Directive
378 const TargetRegisterInfo &RI = *MF->getSubtarget().getRegisterInfo();
379
380 Register stackReg = RI.getFrameRegister(*MF);
381 MCRegister returnReg = RI.getRARegister();
382 unsigned stackSize = MF->getFrameInfo().getStackSize();
383
384 getTargetStreamer().emitFrame(stackReg, stackSize, returnReg);
385}
386
387/// Emit Set directives.
388static const char *getABIString(const MipsABIInfo &ABI) {
389 switch (ABI.GetEnumValue()) {
390 case MipsABIInfo::ABI::O32: return "abi32";
391 case MipsABIInfo::ABI::N32: return "abiN32";
392 case MipsABIInfo::ABI::N64: return "abi64";
394 return "abiP32";
395 default: llvm_unreachable("Unknown Mips ABI");
396 }
397}
398
400 MipsTargetStreamer &TS = getTargetStreamer();
401
402 if (Subtarget->inMicroMipsMode()) {
404 TS.setUsesMicroMips();
406 } else
408
409 if (Subtarget->inMips16Mode())
411 else
413
415 OutStreamer->emitLabel(CurrentFnSym);
416}
417
418/// EmitFunctionBodyStart - Targets can override this to emit stuff before
419/// the first basic block in the function.
421 MipsTargetStreamer &TS = getTargetStreamer();
422
423 MCInstLowering.Initialize(&MF->getContext());
424
425 bool IsNakedFunction = MF->getFunction().hasFnAttribute(Attribute::Naked);
426 if (!IsNakedFunction)
428
429 if (!IsNakedFunction)
431
432 if (!Subtarget->inMips16Mode()) {
436 }
437}
438
439/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
440/// the last basic block in the function.
442 MipsTargetStreamer &TS = getTargetStreamer();
443
444 // There are instruction for this macros, but they must
445 // always be at the function end, and we can't emit and
446 // break with BB logic.
447 if (!Subtarget->inMips16Mode()) {
451 }
452 TS.emitDirectiveEnd(CurrentFnSym->getName());
453 // Make sure to terminate any constant pools that were at the end
454 // of the function.
455 if (!InConstantPool)
456 return;
457 InConstantPool = false;
458 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
459}
460
463 MipsTargetStreamer &TS = getTargetStreamer();
464 if (MBB.empty())
466}
467
468// Print out an operand for an inline asm expression.
470 const char *ExtraCode, raw_ostream &O) {
471 // Does this asm operand have a single letter operand modifier?
472 if (ExtraCode && ExtraCode[0]) {
473 if (ExtraCode[1] != 0) return true; // Unknown modifier.
474
475 const MachineOperand &MO = MI->getOperand(OpNum);
476 switch (ExtraCode[0]) {
477 default:
478 // See if this is a generic print operand
479 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
480 case 'a': // Print a register as a memory address with a zero offset.
481 if (MO.isReg()) {
482 O << "0($" << MipsInstPrinter::getRegisterName(MO.getReg()) << ")";
483 return false;
484 }
485 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
486 case 'X': // hex const int
487 if (!MO.isImm())
488 return true;
489 O << "0x" << Twine::utohexstr(MO.getImm());
490 return false;
491 case 'x': // hex const int (low 16 bits)
492 if (!MO.isImm())
493 return true;
494 O << "0x" << Twine::utohexstr(MO.getImm() & 0xffff);
495 return false;
496 case 'd': // decimal const int
497 if (!MO.isImm())
498 return true;
499 O << MO.getImm();
500 return false;
501 case 'm': // decimal const int minus 1
502 if (!MO.isImm())
503 return true;
504 O << MO.getImm() - 1;
505 return false;
506 case 'y': // exact log2
507 if (!MO.isImm())
508 return true;
509 if (!isPowerOf2_64(MO.getImm()))
510 return true;
511 O << Log2_64(MO.getImm());
512 return false;
513 case 'z':
514 // $0 if zero, regular printing otherwise
515 if (MO.isImm() && MO.getImm() == 0) {
516 O << "$0";
517 return false;
518 }
519 // If not, call printOperand as normal.
520 break;
521 case 'D': // Second part of a double word register operand
522 case 'L': // Low order register of a double word register operand
523 case 'M': // High order register of a double word register operand
524 {
525 if (OpNum == 0)
526 return true;
527 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
528 if (!FlagsOP.isImm())
529 return true;
530 const InlineAsm::Flag Flags(FlagsOP.getImm());
531 const unsigned NumVals = Flags.getNumOperandRegisters();
532 // Number of registers represented by this operand. We are looking
533 // for 2 for 32 bit mode and 1 for 64 bit mode.
534 if (NumVals != 2) {
535 if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
536 Register Reg = MO.getReg();
537 O << '$' << MipsInstPrinter::getRegisterName(Reg);
538 return false;
539 }
540 return true;
541 }
542
543 unsigned RegOp = OpNum;
544 if (!Subtarget->isGP64bit()){
545 // Endianness reverses which register holds the high or low value
546 // between M and L.
547 switch(ExtraCode[0]) {
548 case 'M':
549 RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
550 break;
551 case 'L':
552 RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
553 break;
554 case 'D': // Always the second part
555 RegOp = OpNum + 1;
556 }
557 if (RegOp >= MI->getNumOperands())
558 return true;
559 const MachineOperand &MO = MI->getOperand(RegOp);
560 if (!MO.isReg())
561 return true;
562 Register Reg = MO.getReg();
563 O << '$' << MipsInstPrinter::getRegisterName(Reg);
564 return false;
565 }
566 break;
567 }
568 case 'w': {
570 if (w != Mips::NoRegister) {
572 return false;
573 }
574 break;
575 }
576 }
577 }
578
579 printOperand(MI, OpNum, O);
580 return false;
581}
582
584 unsigned OpNum,
585 const char *ExtraCode,
586 raw_ostream &O) {
587 assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
588 const MachineOperand &BaseMO = MI->getOperand(OpNum);
589 const MachineOperand &OffsetMO = MI->getOperand(OpNum + 1);
590 assert(BaseMO.isReg() &&
591 "Unexpected base pointer for inline asm memory operand.");
592 assert(OffsetMO.isImm() &&
593 "Unexpected offset for inline asm memory operand.");
594 int Offset = OffsetMO.getImm();
595
596 // Currently we are expecting either no ExtraCode or 'D','M','L'.
597 if (ExtraCode) {
598 switch (ExtraCode[0]) {
599 case 'D':
600 Offset += 4;
601 break;
602 case 'M':
603 if (Subtarget->isLittle())
604 Offset += 4;
605 break;
606 case 'L':
607 if (!Subtarget->isLittle())
608 Offset += 4;
609 break;
610 default:
611 return true; // Unknown modifier.
612 }
613 }
614
615 O << Offset << "($" << MipsInstPrinter::getRegisterName(BaseMO.getReg())
616 << ")";
617
618 return false;
619}
620
622 raw_ostream &O) {
623 const MachineOperand &MO = MI->getOperand(opNum);
624 bool closeP = false;
625
626 if (MO.getTargetFlags())
627 closeP = true;
628
629 switch(MO.getTargetFlags()) {
630 case MipsII::MO_GPREL: O << "%gp_rel("; break;
631 case MipsII::MO_GOT_CALL: O << "%call16("; break;
632 case MipsII::MO_GOT: O << "%got("; break;
633 case MipsII::MO_ABS_HI: O << "%hi("; break;
634 case MipsII::MO_ABS_LO: O << "%lo("; break;
635 case MipsII::MO_HIGHER: O << "%higher("; break;
636 case MipsII::MO_HIGHEST: O << "%highest(("; break;
637 case MipsII::MO_TLSGD: O << "%tlsgd("; break;
638 case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
639 case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
640 case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
641 case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
642 case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
643 case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
644 case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
645 case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
646 }
647
648 switch (MO.getType()) {
650 O << '$'
652 break;
653
655 O << MO.getImm();
656 break;
657
659 MO.getMBB()->getSymbol()->print(O, MAI);
660 return;
661
663 PrintSymbolOperand(MO, O);
664 break;
665
668 O << BA->getName();
669 break;
670 }
671
673 O << getDataLayout().getInternalSymbolPrefix() << "CPI"
674 << getFunctionNumber() << "_" << MO.getIndex();
675 if (MO.getOffset())
676 O << "+" << MO.getOffset();
677 break;
678
679 default:
680 llvm_unreachable("<unknown operand type>");
681 }
682
683 if (closeP) O << ")";
684}
685
687 raw_ostream &O) {
688 const MachineOperand &MO = MI->getOperand(opNum);
690}
691
693printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
694 for (int i = opNum, e = MI->getNumOperands(); i != e; ++i) {
695 if (i != opNum) O << ", ";
696 printOperand(MI, i, O);
697 }
698}
699
701 const Triple &TT = M.getTargetTriple();
702
703 if (TT.isOSBinFormatELF()) {
704 MipsTargetStreamer &TS = getTargetStreamer();
705
706 // MipsTargetStreamer has an initialization order problem when emitting an
707 // object file directly (see MipsTargetELFStreamer for full details). Work
708 // around it by re-initializing the PIC state here.
709 TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
710
711 // Try to get target-features from the first function.
712 StringRef FS = TM.getTargetFeatureString();
713 Module::iterator F = M.begin();
714 if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
715 FS = F->getFnAttribute("target-features").getValueAsString();
716
717 std::string strFS = FS.str();
718 if (M.size() && F->getFnAttribute("use-soft-float").getValueAsBool())
719 strFS += strFS.empty() ? "+soft-float" : ",+soft-float";
720
721 // Compute MIPS architecture attributes based on the default subtarget
722 // that we'd have constructed.
723 // FIXME: For ifunc related functions we could iterate over and look
724 // for a feature string that doesn't match the default one.
725 StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
726 const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
727 const MipsSubtarget STI(TT, CPU, StringRef(strFS), MTM.getTargetABIName(M),
728 MTM.isLittleEndian(), MTM, std::nullopt);
729
730 bool IsABICalls = STI.isABICalls();
731 const MipsABIInfo &ABI = STI.getABI();
732 if (IsABICalls) {
734 // FIXME: This condition should be a lot more complicated that it is here.
735 // Ideally it should test for properties of the ABI and not the ABI
736 // itself.
737 // For the moment, I'm only correcting enough to make MIPS-IV work.
738 if (!isPositionIndependent() && STI.hasSym32())
740 }
741
742 // Tell the assembler which ABI we are using
743 std::string SectionName = std::string(".mdebug.") + getABIString(ABI);
744 OutStreamer->switchSection(
745 OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
746
747 // NaN: At the moment we only support:
748 // 1. .nan legacy (default)
749 // 2. .nan 2008
751
752 // TODO: handle O64 ABI
753
754 TS.updateABIInfo(STI);
755
756 // We should always emit a '.module fp=...' but binutils 2.24 does not
757 // accept it. We therefore emit it when it contradicts the ABI defaults
758 // (-mfpxx or -mfp64) and omit it otherwise.
759 // Single-float uses its own ABI even when 64-bit FPRs are enabled.
760 if ((ABI.IsO32() && !STI.isSingleFloat() &&
761 (STI.isABI_FPXX() || STI.isFP64bit())) ||
762 STI.useSoftFloat())
764
765 // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
766 // accept it. We therefore emit it when it contradicts the default or an
767 // option has changed the default (i.e. FPXX) and omit it otherwise.
768 if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
770
771 // Switch to the .text section.
772 OutStreamer->switchSection(getObjFileLowering().getTextSection());
773 }
774}
775
777 MipsTargetStreamer &TS = getTargetStreamer();
778
779 // GCC's choice of assembler options for inline assembly code ('at', 'macro'
780 // and 'reorder') is different from LLVM's choice for generated code ('noat',
781 // 'nomacro' and 'noreorder').
782 // In order to maintain compatibility with inline assembly code which depends
783 // on GCC's assembler options being used, we have to switch to those options
784 // for the duration of the inline assembly block and then switch back.
789 OutStreamer->addBlankLine();
790}
791
792void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
793 const MCSubtargetInfo *EndInfo,
794 const MachineInstr *MI) {
795 OutStreamer->addBlankLine();
796 getTargetStreamer().emitDirectiveSetPop();
797}
798
799void MipsAsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
800 const MachineBasicBlock *MBB,
801 unsigned uid) const {
802 MCSymbol *MBBSym = MBB->getSymbol();
803 switch (MJTI.getEntryKind()) {
807 break;
809 // Each entry is a GP-relative value targeting the block symbol.
810 getTargetStreamer().emitGPRel32Value(
812 break;
814 getTargetStreamer().emitGPRel64Value(
816 break;
817 default:
819 }
820}
821
822void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
823 MCInst I;
824 I.setOpcode(Mips::JAL);
825 I.addOperand(
827 OutStreamer->emitInstruction(I, STI);
828}
829
830void MipsAsmPrinter::EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode,
831 unsigned Reg) {
832 MCInst I;
833 I.setOpcode(Opcode);
834 I.addOperand(MCOperand::createReg(Reg));
835 OutStreamer->emitInstruction(I, STI);
836}
837
838void MipsAsmPrinter::EmitInstrRegReg(const MCSubtargetInfo &STI,
839 unsigned Opcode, unsigned Reg1,
840 unsigned Reg2) {
841 MCInst I;
842 //
843 // Because of the current td files for Mips32, the operands for MTC1
844 // appear backwards from their normal assembly order. It's not a trivial
845 // change to fix this in the td file so we adjust for it here.
846 //
847 if (Opcode == Mips::MTC1) {
848 unsigned Temp = Reg1;
849 Reg1 = Reg2;
850 Reg2 = Temp;
851 }
852 I.setOpcode(Opcode);
853 I.addOperand(MCOperand::createReg(Reg1));
854 I.addOperand(MCOperand::createReg(Reg2));
855 OutStreamer->emitInstruction(I, STI);
856}
857
858void MipsAsmPrinter::EmitInstrRegRegReg(const MCSubtargetInfo &STI,
859 unsigned Opcode, unsigned Reg1,
860 unsigned Reg2, unsigned Reg3) {
861 MCInst I;
862 I.setOpcode(Opcode);
863 I.addOperand(MCOperand::createReg(Reg1));
864 I.addOperand(MCOperand::createReg(Reg2));
865 I.addOperand(MCOperand::createReg(Reg3));
866 OutStreamer->emitInstruction(I, STI);
867}
868
869void MipsAsmPrinter::EmitMovFPIntPair(const MCSubtargetInfo &STI,
870 unsigned MovOpc, unsigned Reg1,
871 unsigned Reg2, unsigned FPReg1,
872 unsigned FPReg2, bool LE) {
873 if (!LE) {
874 unsigned temp = Reg1;
875 Reg1 = Reg2;
876 Reg2 = temp;
877 }
878 EmitInstrRegReg(STI, MovOpc, Reg1, FPReg1);
879 EmitInstrRegReg(STI, MovOpc, Reg2, FPReg2);
880}
881
882void MipsAsmPrinter::EmitSwapFPIntParams(const MCSubtargetInfo &STI,
884 bool LE, bool ToFP) {
885 using namespace Mips16HardFloatInfo;
886
887 const MipsABIInfo &ABI = Subtarget->getABI();
888 unsigned MovOpc = ToFP ? Mips::MTC1 : Mips::MFC1;
889 switch (PV) {
890 case FSig:
891 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
892 break;
893 case FFSig:
894 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
895 Mips::F14, LE);
896 break;
897 case FDSig:
898 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
899 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
900 Mips::F15, LE);
901 break;
902 case DSig:
903 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
904 Mips::F13, LE);
905 break;
906 case DDSig:
907 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
908 Mips::F13, LE);
909 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
910 Mips::F15, LE);
911 break;
912 case DFSig:
913 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
914 Mips::F13, LE);
915 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(2), Mips::F14);
916 break;
917 case NoSig:
918 return;
919 }
920}
921
922void MipsAsmPrinter::EmitSwapFPIntRetval(
924 bool LE) {
925 using namespace Mips16HardFloatInfo;
926
927 const MipsABIInfo &ABI = Subtarget->getABI();
928 unsigned MovOpc = Mips::MFC1;
929 switch (RV) {
930 case FRet:
931 EmitInstrRegReg(STI, MovOpc, ABI.getReturnReg(0), Mips::F0);
932 break;
933 case DRet:
934 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
935 Mips::F0, Mips::F1, LE);
936 break;
937 case CFRet:
938 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
939 Mips::F0, Mips::F1, LE);
940 break;
941 case CDRet:
942 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
943 Mips::F0, Mips::F1, LE);
944 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F2,
945 Mips::F3, LE);
946 break;
947 case NoFPRet:
948 break;
949 }
950}
951
952void MipsAsmPrinter::EmitFPCallStub(
953 const char *Symbol, const Mips16HardFloatInfo::FuncSignature *Signature) {
954 using namespace Mips16HardFloatInfo;
955
956 MCSymbol *MSymbol = OutContext.getOrCreateSymbol(StringRef(Symbol));
958 // Construct a local MCSubtargetInfo here.
959 // This is because the MachineFunction won't exist (but have not yet been
960 // freed) and since we're at the global level we can use the default
961 // constructed subtarget.
962 std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
963 TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
964
965 //
966 // .global xxxx
967 //
968 OutStreamer->emitSymbolAttribute(MSymbol, MCSA_Global);
969 const char *RetType;
970 //
971 // make the comment field identifying the return and parameter
972 // types of the floating point stub
973 // # Stub function to call rettype xxxx (params)
974 //
975 switch (Signature->RetSig) {
976 case FRet:
977 RetType = "float";
978 break;
979 case DRet:
980 RetType = "double";
981 break;
982 case CFRet:
983 RetType = "complex";
984 break;
985 case CDRet:
986 RetType = "double complex";
987 break;
988 case NoFPRet:
989 RetType = "";
990 break;
991 }
992 const char *Parms;
993 switch (Signature->ParamSig) {
994 case FSig:
995 Parms = "float";
996 break;
997 case FFSig:
998 Parms = "float, float";
999 break;
1000 case FDSig:
1001 Parms = "float, double";
1002 break;
1003 case DSig:
1004 Parms = "double";
1005 break;
1006 case DDSig:
1007 Parms = "double, double";
1008 break;
1009 case DFSig:
1010 Parms = "double, float";
1011 break;
1012 case NoSig:
1013 Parms = "";
1014 break;
1015 }
1016 OutStreamer->AddComment("\t# Stub function to call " + Twine(RetType) + " " +
1017 Twine(Symbol) + " (" + Twine(Parms) + ")");
1018 //
1019 // probably not necessary but we save and restore the current section state
1020 //
1021 OutStreamer->pushSection();
1022 //
1023 // .section mips16.call.fpxxxx,"ax",@progbits
1024 //
1025 MCSectionELF *M = OutContext.getELFSection(
1026 ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
1028 OutStreamer->switchSection(M);
1029 //
1030 // .align 2
1031 //
1032 OutStreamer->emitValueToAlignment(Align(4));
1033 MipsTargetStreamer &TS = getTargetStreamer();
1034 //
1035 // .set nomips16
1036 // .set nomicromips
1037 //
1040 //
1041 // .ent __call_stub_fp_xxxx
1042 // .type __call_stub_fp_xxxx,@function
1043 // __call_stub_fp_xxxx:
1044 //
1045 std::string x = "__call_stub_fp_" + std::string(Symbol);
1046 MCSymbol *Stub = OutContext.getOrCreateSymbol(StringRef(x));
1047 TS.emitDirectiveEnt(*Stub);
1048 MCSymbol *MType =
1049 OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
1050 OutStreamer->emitSymbolAttribute(MType, MCSA_ELF_TypeFunction);
1051 OutStreamer->emitLabel(Stub);
1052
1053 // Only handle non-pic for now.
1055 "should not be here if we are compiling pic");
1057 //
1058 // We need to add a MipsMCExpr class to MCTargetDesc to fully implement
1059 // stubs without raw text but this current patch is for compiler generated
1060 // functions and they all return some value.
1061 // The calling sequence for non pic is different in that case and we need
1062 // to implement %lo and %hi in order to handle the case of no return value
1063 // See the corresponding method in Mips16HardFloat for details.
1064 //
1065 // mov the return address to S2.
1066 // we have no stack space to store it and we are about to make another call.
1067 // We need to make sure that the enclosing function knows to save S2
1068 // This should have already been handled.
1069 //
1070 // Mov $18, $31
1071
1072 EmitInstrRegRegReg(*STI, Mips::OR, Subtarget->getABI().getSavedReg(2),
1073 Mips::RA, Mips::R0);
1074
1075 EmitSwapFPIntParams(*STI, Signature->ParamSig, LE, true);
1076
1077 // Jal xxxx
1078 //
1079 EmitJal(*STI, MSymbol);
1080
1081 // fix return values
1082 EmitSwapFPIntRetval(*STI, Signature->RetSig, LE);
1083 //
1084 // do the return
1085 // if (Signature->RetSig == NoFPRet)
1086 // llvm_unreachable("should not be any stubs here with no return value");
1087 // else
1088 EmitInstrReg(*STI, Mips::JR, Subtarget->getABI().getSavedReg(2));
1089
1090 MCSymbol *Tmp = OutContext.createTempSymbol();
1091 OutStreamer->emitLabel(Tmp);
1092 const MCSymbolRefExpr *E = MCSymbolRefExpr::create(Stub, OutContext);
1093 const MCSymbolRefExpr *T = MCSymbolRefExpr::create(Tmp, OutContext);
1094 const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
1095 OutStreamer->emitELFSize(Stub, T_min_E);
1096 TS.emitDirectiveEnd(x);
1097 OutStreamer->popSection();
1098}
1099
1101 // Emit needed stubs
1102 //
1103 for (std::map<
1104 const char *,
1106 it = StubsNeeded.begin();
1107 it != StubsNeeded.end(); ++it) {
1108 const char *Symbol = it->first;
1109 const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
1110 EmitFPCallStub(Symbol, Signature);
1111 }
1112 // return to the text section
1113 OutStreamer->switchSection(OutContext.getObjectFileInfo()->getTextSection());
1114}
1115
1116void MipsAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) {
1117 const uint8_t NoopsInSledCount = Subtarget->isGP64bit() ? 15 : 11;
1118 // For mips32 we want to emit the following pattern:
1119 //
1120 // .Lxray_sled_N:
1121 // ALIGN
1122 // B .tmpN
1123 // 11 NOP instructions (44 bytes)
1124 // ADDIU T9, T9, 52
1125 // .tmpN
1126 //
1127 // We need the 44 bytes (11 instructions) because at runtime, we'd
1128 // be patching over the full 48 bytes (12 instructions) with the following
1129 // pattern:
1130 //
1131 // ADDIU SP, SP, -8
1132 // NOP
1133 // SW RA, 4(SP)
1134 // SW T9, 0(SP)
1135 // LUI T9, %hi(__xray_FunctionEntry/Exit)
1136 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1137 // LUI T0, %hi(function_id)
1138 // JALR T9
1139 // ORI T0, T0, %lo(function_id)
1140 // LW T9, 0(SP)
1141 // LW RA, 4(SP)
1142 // ADDIU SP, SP, 8
1143 //
1144 // We add 52 bytes to t9 because we want to adjust the function pointer to
1145 // the actual start of function i.e. the address just after the noop sled.
1146 // We do this because gp displacement relocation is emitted at the start of
1147 // of the function i.e after the nop sled and to correctly calculate the
1148 // global offset table address, t9 must hold the address of the instruction
1149 // containing the gp displacement relocation.
1150 // FIXME: Is this correct for the static relocation model?
1151 //
1152 // For mips64 we want to emit the following pattern:
1153 //
1154 // .Lxray_sled_N:
1155 // ALIGN
1156 // B .tmpN
1157 // 15 NOP instructions (60 bytes)
1158 // .tmpN
1159 //
1160 // We need the 60 bytes (15 instructions) because at runtime, we'd
1161 // be patching over the full 64 bytes (16 instructions) with the following
1162 // pattern:
1163 //
1164 // DADDIU SP, SP, -16
1165 // NOP
1166 // SD RA, 8(SP)
1167 // SD T9, 0(SP)
1168 // LUI T9, %highest(__xray_FunctionEntry/Exit)
1169 // ORI T9, T9, %higher(__xray_FunctionEntry/Exit)
1170 // DSLL T9, T9, 16
1171 // ORI T9, T9, %hi(__xray_FunctionEntry/Exit)
1172 // DSLL T9, T9, 16
1173 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1174 // LUI T0, %hi(function_id)
1175 // JALR T9
1176 // ADDIU T0, T0, %lo(function_id)
1177 // LD T9, 0(SP)
1178 // LD RA, 8(SP)
1179 // DADDIU SP, SP, 16
1180 //
1181 OutStreamer->emitCodeAlignment(Align(4), getSubtargetInfo());
1182 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1183 OutStreamer->emitLabel(CurSled);
1185
1186 // Emit "B .tmpN" instruction, which jumps over the nop sled to the actual
1187 // start of function
1188 const MCExpr *TargetExpr = MCSymbolRefExpr::create(Target, OutContext);
1190 *OutStreamer,
1191 MCInstBuilder(Mips::BEQ).addReg(Mips::R0).addReg(Mips::R0).addExpr(
1192 TargetExpr));
1193
1194 for (int8_t I = 0; I < NoopsInSledCount; I++)
1196 *OutStreamer,
1197 MCInstBuilder(Mips::SLL).addReg(Mips::R0).addReg(Mips::R0).addImm(0));
1198
1199 OutStreamer->emitLabel(Target);
1200
1201 if (!Subtarget->isGP64bit()) {
1203 .addReg(Mips::R25)
1204 .addReg(Mips::R25)
1205 .addImm(0x34));
1206 }
1207
1208 recordSled(CurSled, MI, Kind, 2);
1209}
1210
1214
1218
1222
1224 raw_ostream &OS) {
1225 // TODO: implement
1226}
1227
1228// Emit .dtprelword or .dtpreldword directive
1229// and value for debug thread local expression.
1230void MipsAsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
1231 if (auto *MipsExpr = dyn_cast<MCSpecifierExpr>(Value)) {
1232 if (MipsExpr && MipsExpr->getSpecifier() == Mips::S_DTPREL) {
1233 switch (Size) {
1234 case 4:
1235 getTargetStreamer().emitDTPRel32Value(MipsExpr->getSubExpr());
1236 break;
1237 case 8:
1238 getTargetStreamer().emitDTPRel64Value(MipsExpr->getSubExpr());
1239 break;
1240 default:
1241 llvm_unreachable("Unexpected size of expression value.");
1242 }
1243 return;
1244 }
1245 }
1247}
1248
1249bool MipsAsmPrinter::isLongBranchPseudo(int Opcode) const {
1250 return (Opcode == Mips::LONG_BRANCH_LUi
1251 || Opcode == Mips::LONG_BRANCH_LUi2Op
1252 || Opcode == Mips::LONG_BRANCH_LUi2Op_64
1253 || Opcode == Mips::LONG_BRANCH_ADDiu
1254 || Opcode == Mips::LONG_BRANCH_ADDiu2Op
1255 || Opcode == Mips::LONG_BRANCH_DADDiu
1256 || Opcode == Mips::LONG_BRANCH_DADDiu2Op);
1257}
1258
1259char MipsAsmPrinter::ID = 0;
1260
1261INITIALIZE_PASS(MipsAsmPrinter, "mips-asm-printer", "Mips Assembly Printer",
1262 false, false)
1263
1264// Force static initialization.
1265extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1266LLVMInitializeMipsAsmPrinter() {
1272}
1273
1282
1294
const AArch64Subtarget & Subtarget
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...
static const Function * getParent(const Value *V)
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
unsigned Opc
#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
#define T
static const char * getABIString(const MipsABIInfo &ABI)
Emit Set directives.
ModuleAnalysisManager MAM
#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:479
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:93
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:381
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:96
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:111
virtual void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
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:133
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:103
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool isPositionIndependent() const
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:478
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:108
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:99
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:219
StringRef getInternalSymbolPrefix() const
Definition DataLayout.h:310
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:424
Context object for machine code objects.
Definition MCContext.h:84
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:31
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
void addOperand(const MCOperand Op)
Definition MCInst.h:214
void setOpcode(unsigned Op)
Definition MCInst.h:200
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:39
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:165
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:137
bool isValid() const
Definition MCInst.h:63
MCRegister getRARegister() const
This method should return the register where the return address can be found.
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
Streaming machine code generation interface.
Definition MCStreamer.h:221
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
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:60
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
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.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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 useSoftFloat() const
bool isNaN2008() const
bool useOddSPReg() const
bool hasSym32() const
bool isABI_FPXX() const
bool isABICalls() 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
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
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:28
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
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:1098
@ SHF_EXECINSTR
Definition ELF.h:1101
@ SHT_PROGBITS
Definition ELF.h:996
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
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
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
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Target & getTheNanoMipsTarget()
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)
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
Target & getTheMips64elTarget()
Target & getTheMipselTarget()
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
Target & getTheMipsTarget()
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
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,...