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 'X': // hex const int
481 if (!MO.isImm())
482 return true;
483 O << "0x" << Twine::utohexstr(MO.getImm());
484 return false;
485 case 'x': // hex const int (low 16 bits)
486 if (!MO.isImm())
487 return true;
488 O << "0x" << Twine::utohexstr(MO.getImm() & 0xffff);
489 return false;
490 case 'd': // decimal const int
491 if (!MO.isImm())
492 return true;
493 O << MO.getImm();
494 return false;
495 case 'm': // decimal const int minus 1
496 if (!MO.isImm())
497 return true;
498 O << MO.getImm() - 1;
499 return false;
500 case 'y': // exact log2
501 if (!MO.isImm())
502 return true;
503 if (!isPowerOf2_64(MO.getImm()))
504 return true;
505 O << Log2_64(MO.getImm());
506 return false;
507 case 'z':
508 // $0 if zero, regular printing otherwise
509 if (MO.isImm() && MO.getImm() == 0) {
510 O << "$0";
511 return false;
512 }
513 // If not, call printOperand as normal.
514 break;
515 case 'D': // Second part of a double word register operand
516 case 'L': // Low order register of a double word register operand
517 case 'M': // High order register of a double word register operand
518 {
519 if (OpNum == 0)
520 return true;
521 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
522 if (!FlagsOP.isImm())
523 return true;
524 const InlineAsm::Flag Flags(FlagsOP.getImm());
525 const unsigned NumVals = Flags.getNumOperandRegisters();
526 // Number of registers represented by this operand. We are looking
527 // for 2 for 32 bit mode and 1 for 64 bit mode.
528 if (NumVals != 2) {
529 if (Subtarget->isGP64bit() && NumVals == 1 && MO.isReg()) {
530 Register Reg = MO.getReg();
531 O << '$' << MipsInstPrinter::getRegisterName(Reg);
532 return false;
533 }
534 return true;
535 }
536
537 unsigned RegOp = OpNum;
538 if (!Subtarget->isGP64bit()){
539 // Endianness reverses which register holds the high or low value
540 // between M and L.
541 switch(ExtraCode[0]) {
542 case 'M':
543 RegOp = (Subtarget->isLittle()) ? OpNum + 1 : OpNum;
544 break;
545 case 'L':
546 RegOp = (Subtarget->isLittle()) ? OpNum : OpNum + 1;
547 break;
548 case 'D': // Always the second part
549 RegOp = OpNum + 1;
550 }
551 if (RegOp >= MI->getNumOperands())
552 return true;
553 const MachineOperand &MO = MI->getOperand(RegOp);
554 if (!MO.isReg())
555 return true;
556 Register Reg = MO.getReg();
557 O << '$' << MipsInstPrinter::getRegisterName(Reg);
558 return false;
559 }
560 break;
561 }
562 case 'w': {
564 if (w != Mips::NoRegister) {
566 return false;
567 }
568 break;
569 }
570 }
571 }
572
573 printOperand(MI, OpNum, O);
574 return false;
575}
576
578 unsigned OpNum,
579 const char *ExtraCode,
580 raw_ostream &O) {
581 assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
582 const MachineOperand &BaseMO = MI->getOperand(OpNum);
583 const MachineOperand &OffsetMO = MI->getOperand(OpNum + 1);
584 assert(BaseMO.isReg() &&
585 "Unexpected base pointer for inline asm memory operand.");
586 assert(OffsetMO.isImm() &&
587 "Unexpected offset for inline asm memory operand.");
588 int Offset = OffsetMO.getImm();
589
590 // Currently we are expecting either no ExtraCode or 'D','M','L'.
591 if (ExtraCode) {
592 switch (ExtraCode[0]) {
593 case 'D':
594 Offset += 4;
595 break;
596 case 'M':
597 if (Subtarget->isLittle())
598 Offset += 4;
599 break;
600 case 'L':
601 if (!Subtarget->isLittle())
602 Offset += 4;
603 break;
604 default:
605 return true; // Unknown modifier.
606 }
607 }
608
609 O << Offset << "($" << MipsInstPrinter::getRegisterName(BaseMO.getReg())
610 << ")";
611
612 return false;
613}
614
616 raw_ostream &O) {
617 const MachineOperand &MO = MI->getOperand(opNum);
618 bool closeP = false;
619
620 if (MO.getTargetFlags())
621 closeP = true;
622
623 switch(MO.getTargetFlags()) {
624 case MipsII::MO_GPREL: O << "%gp_rel("; break;
625 case MipsII::MO_GOT_CALL: O << "%call16("; break;
626 case MipsII::MO_GOT: O << "%got("; break;
627 case MipsII::MO_ABS_HI: O << "%hi("; break;
628 case MipsII::MO_ABS_LO: O << "%lo("; break;
629 case MipsII::MO_HIGHER: O << "%higher("; break;
630 case MipsII::MO_HIGHEST: O << "%highest(("; break;
631 case MipsII::MO_TLSGD: O << "%tlsgd("; break;
632 case MipsII::MO_GOTTPREL: O << "%gottprel("; break;
633 case MipsII::MO_TPREL_HI: O << "%tprel_hi("; break;
634 case MipsII::MO_TPREL_LO: O << "%tprel_lo("; break;
635 case MipsII::MO_GPOFF_HI: O << "%hi(%neg(%gp_rel("; break;
636 case MipsII::MO_GPOFF_LO: O << "%lo(%neg(%gp_rel("; break;
637 case MipsII::MO_GOT_DISP: O << "%got_disp("; break;
638 case MipsII::MO_GOT_PAGE: O << "%got_page("; break;
639 case MipsII::MO_GOT_OFST: O << "%got_ofst("; break;
640 }
641
642 switch (MO.getType()) {
644 O << '$'
646 break;
647
649 O << MO.getImm();
650 break;
651
653 MO.getMBB()->getSymbol()->print(O, MAI);
654 return;
655
657 PrintSymbolOperand(MO, O);
658 break;
659
662 O << BA->getName();
663 break;
664 }
665
667 O << getDataLayout().getInternalSymbolPrefix() << "CPI"
668 << getFunctionNumber() << "_" << MO.getIndex();
669 if (MO.getOffset())
670 O << "+" << MO.getOffset();
671 break;
672
673 default:
674 llvm_unreachable("<unknown operand type>");
675 }
676
677 if (closeP) O << ")";
678}
679
681 raw_ostream &O) {
682 const MachineOperand &MO = MI->getOperand(opNum);
684}
685
687printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
688 for (int i = opNum, e = MI->getNumOperands(); i != e; ++i) {
689 if (i != opNum) O << ", ";
690 printOperand(MI, i, O);
691 }
692}
693
695 const Triple &TT = M.getTargetTriple();
696
697 if (TT.isOSBinFormatELF()) {
698 MipsTargetStreamer &TS = getTargetStreamer();
699
700 // MipsTargetStreamer has an initialization order problem when emitting an
701 // object file directly (see MipsTargetELFStreamer for full details). Work
702 // around it by re-initializing the PIC state here.
703 TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
704
705 // Try to get target-features from the first function.
706 StringRef FS = TM.getTargetFeatureString();
707 Module::iterator F = M.begin();
708 if (FS.empty() && M.size() && F->hasFnAttribute("target-features"))
709 FS = F->getFnAttribute("target-features").getValueAsString();
710
711 std::string strFS = FS.str();
712 if (M.size() && F->getFnAttribute("use-soft-float").getValueAsBool())
713 strFS += strFS.empty() ? "+soft-float" : ",+soft-float";
714
715 // Compute MIPS architecture attributes based on the default subtarget
716 // that we'd have constructed.
717 // FIXME: For ifunc related functions we could iterate over and look
718 // for a feature string that doesn't match the default one.
719 StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
720 const MipsTargetMachine &MTM = static_cast<const MipsTargetMachine &>(TM);
721 const MipsSubtarget STI(TT, CPU, StringRef(strFS), MTM.getTargetABIName(M),
722 MTM.isLittleEndian(), MTM, std::nullopt);
723
724 bool IsABICalls = STI.isABICalls();
725 const MipsABIInfo &ABI = STI.getABI();
726 if (IsABICalls) {
728 // FIXME: This condition should be a lot more complicated that it is here.
729 // Ideally it should test for properties of the ABI and not the ABI
730 // itself.
731 // For the moment, I'm only correcting enough to make MIPS-IV work.
732 if (!isPositionIndependent() && STI.hasSym32())
734 }
735
736 // Tell the assembler which ABI we are using
737 std::string SectionName = std::string(".mdebug.") + getABIString(ABI);
738 OutStreamer->switchSection(
739 OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, 0));
740
741 // NaN: At the moment we only support:
742 // 1. .nan legacy (default)
743 // 2. .nan 2008
745
746 // TODO: handle O64 ABI
747
748 TS.updateABIInfo(STI);
749
750 // We should always emit a '.module fp=...' but binutils 2.24 does not
751 // accept it. We therefore emit it when it contradicts the ABI defaults
752 // (-mfpxx or -mfp64) and omit it otherwise.
753 // Single-float uses its own ABI even when 64-bit FPRs are enabled.
754 if ((ABI.IsO32() && !STI.isSingleFloat() &&
755 (STI.isABI_FPXX() || STI.isFP64bit())) ||
756 STI.useSoftFloat())
758
759 // We should always emit a '.module [no]oddspreg' but binutils 2.24 does not
760 // accept it. We therefore emit it when it contradicts the default or an
761 // option has changed the default (i.e. FPXX) and omit it otherwise.
762 if (ABI.IsO32() && (!STI.useOddSPReg() || STI.isABI_FPXX()))
764
765 // Switch to the .text section.
766 OutStreamer->switchSection(getObjFileLowering().getTextSection());
767 }
768}
769
771 MipsTargetStreamer &TS = getTargetStreamer();
772
773 // GCC's choice of assembler options for inline assembly code ('at', 'macro'
774 // and 'reorder') is different from LLVM's choice for generated code ('noat',
775 // 'nomacro' and 'noreorder').
776 // In order to maintain compatibility with inline assembly code which depends
777 // on GCC's assembler options being used, we have to switch to those options
778 // for the duration of the inline assembly block and then switch back.
783 OutStreamer->addBlankLine();
784}
785
786void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
787 const MCSubtargetInfo *EndInfo,
788 const MachineInstr *MI) {
789 OutStreamer->addBlankLine();
790 getTargetStreamer().emitDirectiveSetPop();
791}
792
793void MipsAsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
794 const MachineBasicBlock *MBB,
795 unsigned uid) const {
796 MCSymbol *MBBSym = MBB->getSymbol();
797 switch (MJTI.getEntryKind()) {
801 break;
803 // Each entry is a GP-relative value targeting the block symbol.
804 getTargetStreamer().emitGPRel32Value(
806 break;
808 getTargetStreamer().emitGPRel64Value(
810 break;
811 default:
813 }
814}
815
816void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
817 MCInst I;
818 I.setOpcode(Mips::JAL);
819 I.addOperand(
821 OutStreamer->emitInstruction(I, STI);
822}
823
824void MipsAsmPrinter::EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode,
825 unsigned Reg) {
826 MCInst I;
827 I.setOpcode(Opcode);
828 I.addOperand(MCOperand::createReg(Reg));
829 OutStreamer->emitInstruction(I, STI);
830}
831
832void MipsAsmPrinter::EmitInstrRegReg(const MCSubtargetInfo &STI,
833 unsigned Opcode, unsigned Reg1,
834 unsigned Reg2) {
835 MCInst I;
836 //
837 // Because of the current td files for Mips32, the operands for MTC1
838 // appear backwards from their normal assembly order. It's not a trivial
839 // change to fix this in the td file so we adjust for it here.
840 //
841 if (Opcode == Mips::MTC1) {
842 unsigned Temp = Reg1;
843 Reg1 = Reg2;
844 Reg2 = Temp;
845 }
846 I.setOpcode(Opcode);
847 I.addOperand(MCOperand::createReg(Reg1));
848 I.addOperand(MCOperand::createReg(Reg2));
849 OutStreamer->emitInstruction(I, STI);
850}
851
852void MipsAsmPrinter::EmitInstrRegRegReg(const MCSubtargetInfo &STI,
853 unsigned Opcode, unsigned Reg1,
854 unsigned Reg2, unsigned Reg3) {
855 MCInst I;
856 I.setOpcode(Opcode);
857 I.addOperand(MCOperand::createReg(Reg1));
858 I.addOperand(MCOperand::createReg(Reg2));
859 I.addOperand(MCOperand::createReg(Reg3));
860 OutStreamer->emitInstruction(I, STI);
861}
862
863void MipsAsmPrinter::EmitMovFPIntPair(const MCSubtargetInfo &STI,
864 unsigned MovOpc, unsigned Reg1,
865 unsigned Reg2, unsigned FPReg1,
866 unsigned FPReg2, bool LE) {
867 if (!LE) {
868 unsigned temp = Reg1;
869 Reg1 = Reg2;
870 Reg2 = temp;
871 }
872 EmitInstrRegReg(STI, MovOpc, Reg1, FPReg1);
873 EmitInstrRegReg(STI, MovOpc, Reg2, FPReg2);
874}
875
876void MipsAsmPrinter::EmitSwapFPIntParams(const MCSubtargetInfo &STI,
878 bool LE, bool ToFP) {
879 using namespace Mips16HardFloatInfo;
880
881 const MipsABIInfo &ABI = Subtarget->getABI();
882 unsigned MovOpc = ToFP ? Mips::MTC1 : Mips::MFC1;
883 switch (PV) {
884 case FSig:
885 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
886 break;
887 case FFSig:
888 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
889 Mips::F14, LE);
890 break;
891 case FDSig:
892 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(0), Mips::F12);
893 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
894 Mips::F15, LE);
895 break;
896 case DSig:
897 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
898 Mips::F13, LE);
899 break;
900 case DDSig:
901 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
902 Mips::F13, LE);
903 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(2), ABI.getArgReg(3), Mips::F14,
904 Mips::F15, LE);
905 break;
906 case DFSig:
907 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F12,
908 Mips::F13, LE);
909 EmitInstrRegReg(STI, MovOpc, ABI.getArgReg(2), Mips::F14);
910 break;
911 case NoSig:
912 return;
913 }
914}
915
916void MipsAsmPrinter::EmitSwapFPIntRetval(
918 bool LE) {
919 using namespace Mips16HardFloatInfo;
920
921 const MipsABIInfo &ABI = Subtarget->getABI();
922 unsigned MovOpc = Mips::MFC1;
923 switch (RV) {
924 case FRet:
925 EmitInstrRegReg(STI, MovOpc, ABI.getReturnReg(0), Mips::F0);
926 break;
927 case DRet:
928 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
929 Mips::F0, Mips::F1, LE);
930 break;
931 case CFRet:
932 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
933 Mips::F0, Mips::F1, LE);
934 break;
935 case CDRet:
936 EmitMovFPIntPair(STI, MovOpc, ABI.getReturnReg(0), ABI.getReturnReg(1),
937 Mips::F0, Mips::F1, LE);
938 EmitMovFPIntPair(STI, MovOpc, ABI.getArgReg(0), ABI.getArgReg(1), Mips::F2,
939 Mips::F3, LE);
940 break;
941 case NoFPRet:
942 break;
943 }
944}
945
946void MipsAsmPrinter::EmitFPCallStub(
947 const char *Symbol, const Mips16HardFloatInfo::FuncSignature *Signature) {
948 using namespace Mips16HardFloatInfo;
949
950 MCSymbol *MSymbol = OutContext.getOrCreateSymbol(StringRef(Symbol));
952 // Construct a local MCSubtargetInfo here.
953 // This is because the MachineFunction won't exist (but have not yet been
954 // freed) and since we're at the global level we can use the default
955 // constructed subtarget.
956 std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
957 TM.getTargetTriple(), TM.getTargetCPU(), TM.getTargetFeatureString()));
958
959 //
960 // .global xxxx
961 //
962 OutStreamer->emitSymbolAttribute(MSymbol, MCSA_Global);
963 const char *RetType;
964 //
965 // make the comment field identifying the return and parameter
966 // types of the floating point stub
967 // # Stub function to call rettype xxxx (params)
968 //
969 switch (Signature->RetSig) {
970 case FRet:
971 RetType = "float";
972 break;
973 case DRet:
974 RetType = "double";
975 break;
976 case CFRet:
977 RetType = "complex";
978 break;
979 case CDRet:
980 RetType = "double complex";
981 break;
982 case NoFPRet:
983 RetType = "";
984 break;
985 }
986 const char *Parms;
987 switch (Signature->ParamSig) {
988 case FSig:
989 Parms = "float";
990 break;
991 case FFSig:
992 Parms = "float, float";
993 break;
994 case FDSig:
995 Parms = "float, double";
996 break;
997 case DSig:
998 Parms = "double";
999 break;
1000 case DDSig:
1001 Parms = "double, double";
1002 break;
1003 case DFSig:
1004 Parms = "double, float";
1005 break;
1006 case NoSig:
1007 Parms = "";
1008 break;
1009 }
1010 OutStreamer->AddComment("\t# Stub function to call " + Twine(RetType) + " " +
1011 Twine(Symbol) + " (" + Twine(Parms) + ")");
1012 //
1013 // probably not necessary but we save and restore the current section state
1014 //
1015 OutStreamer->pushSection();
1016 //
1017 // .section mips16.call.fpxxxx,"ax",@progbits
1018 //
1019 MCSectionELF *M = OutContext.getELFSection(
1020 ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
1022 OutStreamer->switchSection(M);
1023 //
1024 // .align 2
1025 //
1026 OutStreamer->emitValueToAlignment(Align(4));
1027 MipsTargetStreamer &TS = getTargetStreamer();
1028 //
1029 // .set nomips16
1030 // .set nomicromips
1031 //
1034 //
1035 // .ent __call_stub_fp_xxxx
1036 // .type __call_stub_fp_xxxx,@function
1037 // __call_stub_fp_xxxx:
1038 //
1039 std::string x = "__call_stub_fp_" + std::string(Symbol);
1040 MCSymbol *Stub = OutContext.getOrCreateSymbol(StringRef(x));
1041 TS.emitDirectiveEnt(*Stub);
1042 MCSymbol *MType =
1043 OutContext.getOrCreateSymbol("__call_stub_fp_" + Twine(Symbol));
1044 OutStreamer->emitSymbolAttribute(MType, MCSA_ELF_TypeFunction);
1045 OutStreamer->emitLabel(Stub);
1046
1047 // Only handle non-pic for now.
1049 "should not be here if we are compiling pic");
1051 //
1052 // We need to add a MipsMCExpr class to MCTargetDesc to fully implement
1053 // stubs without raw text but this current patch is for compiler generated
1054 // functions and they all return some value.
1055 // The calling sequence for non pic is different in that case and we need
1056 // to implement %lo and %hi in order to handle the case of no return value
1057 // See the corresponding method in Mips16HardFloat for details.
1058 //
1059 // mov the return address to S2.
1060 // we have no stack space to store it and we are about to make another call.
1061 // We need to make sure that the enclosing function knows to save S2
1062 // This should have already been handled.
1063 //
1064 // Mov $18, $31
1065
1066 EmitInstrRegRegReg(*STI, Mips::OR, Subtarget->getABI().getSavedReg(2),
1067 Mips::RA, Mips::R0);
1068
1069 EmitSwapFPIntParams(*STI, Signature->ParamSig, LE, true);
1070
1071 // Jal xxxx
1072 //
1073 EmitJal(*STI, MSymbol);
1074
1075 // fix return values
1076 EmitSwapFPIntRetval(*STI, Signature->RetSig, LE);
1077 //
1078 // do the return
1079 // if (Signature->RetSig == NoFPRet)
1080 // llvm_unreachable("should not be any stubs here with no return value");
1081 // else
1082 EmitInstrReg(*STI, Mips::JR, Subtarget->getABI().getSavedReg(2));
1083
1084 MCSymbol *Tmp = OutContext.createTempSymbol();
1085 OutStreamer->emitLabel(Tmp);
1086 const MCSymbolRefExpr *E = MCSymbolRefExpr::create(Stub, OutContext);
1087 const MCSymbolRefExpr *T = MCSymbolRefExpr::create(Tmp, OutContext);
1088 const MCExpr *T_min_E = MCBinaryExpr::createSub(T, E, OutContext);
1089 OutStreamer->emitELFSize(Stub, T_min_E);
1090 TS.emitDirectiveEnd(x);
1091 OutStreamer->popSection();
1092}
1093
1095 // Emit needed stubs
1096 //
1097 for (std::map<
1098 const char *,
1100 it = StubsNeeded.begin();
1101 it != StubsNeeded.end(); ++it) {
1102 const char *Symbol = it->first;
1103 const Mips16HardFloatInfo::FuncSignature *Signature = it->second;
1104 EmitFPCallStub(Symbol, Signature);
1105 }
1106 // return to the text section
1107 OutStreamer->switchSection(OutContext.getObjectFileInfo()->getTextSection());
1108}
1109
1110void MipsAsmPrinter::EmitSled(const MachineInstr &MI, SledKind Kind) {
1111 const uint8_t NoopsInSledCount = Subtarget->isGP64bit() ? 15 : 11;
1112 // For mips32 we want to emit the following pattern:
1113 //
1114 // .Lxray_sled_N:
1115 // ALIGN
1116 // B .tmpN
1117 // 11 NOP instructions (44 bytes)
1118 // ADDIU T9, T9, 52
1119 // .tmpN
1120 //
1121 // We need the 44 bytes (11 instructions) because at runtime, we'd
1122 // be patching over the full 48 bytes (12 instructions) with the following
1123 // pattern:
1124 //
1125 // ADDIU SP, SP, -8
1126 // NOP
1127 // SW RA, 4(SP)
1128 // SW T9, 0(SP)
1129 // LUI T9, %hi(__xray_FunctionEntry/Exit)
1130 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1131 // LUI T0, %hi(function_id)
1132 // JALR T9
1133 // ORI T0, T0, %lo(function_id)
1134 // LW T9, 0(SP)
1135 // LW RA, 4(SP)
1136 // ADDIU SP, SP, 8
1137 //
1138 // We add 52 bytes to t9 because we want to adjust the function pointer to
1139 // the actual start of function i.e. the address just after the noop sled.
1140 // We do this because gp displacement relocation is emitted at the start of
1141 // of the function i.e after the nop sled and to correctly calculate the
1142 // global offset table address, t9 must hold the address of the instruction
1143 // containing the gp displacement relocation.
1144 // FIXME: Is this correct for the static relocation model?
1145 //
1146 // For mips64 we want to emit the following pattern:
1147 //
1148 // .Lxray_sled_N:
1149 // ALIGN
1150 // B .tmpN
1151 // 15 NOP instructions (60 bytes)
1152 // .tmpN
1153 //
1154 // We need the 60 bytes (15 instructions) because at runtime, we'd
1155 // be patching over the full 64 bytes (16 instructions) with the following
1156 // pattern:
1157 //
1158 // DADDIU SP, SP, -16
1159 // NOP
1160 // SD RA, 8(SP)
1161 // SD T9, 0(SP)
1162 // LUI T9, %highest(__xray_FunctionEntry/Exit)
1163 // ORI T9, T9, %higher(__xray_FunctionEntry/Exit)
1164 // DSLL T9, T9, 16
1165 // ORI T9, T9, %hi(__xray_FunctionEntry/Exit)
1166 // DSLL T9, T9, 16
1167 // ORI T9, T9, %lo(__xray_FunctionEntry/Exit)
1168 // LUI T0, %hi(function_id)
1169 // JALR T9
1170 // ADDIU T0, T0, %lo(function_id)
1171 // LD T9, 0(SP)
1172 // LD RA, 8(SP)
1173 // DADDIU SP, SP, 16
1174 //
1175 OutStreamer->emitCodeAlignment(Align(4), getSubtargetInfo());
1176 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1177 OutStreamer->emitLabel(CurSled);
1179
1180 // Emit "B .tmpN" instruction, which jumps over the nop sled to the actual
1181 // start of function
1182 const MCExpr *TargetExpr = MCSymbolRefExpr::create(Target, OutContext);
1184 *OutStreamer,
1185 MCInstBuilder(Mips::BEQ).addReg(Mips::R0).addReg(Mips::R0).addExpr(
1186 TargetExpr));
1187
1188 for (int8_t I = 0; I < NoopsInSledCount; I++)
1190 *OutStreamer,
1191 MCInstBuilder(Mips::SLL).addReg(Mips::R0).addReg(Mips::R0).addImm(0));
1192
1193 OutStreamer->emitLabel(Target);
1194
1195 if (!Subtarget->isGP64bit()) {
1197 .addReg(Mips::R25)
1198 .addReg(Mips::R25)
1199 .addImm(0x34));
1200 }
1201
1202 recordSled(CurSled, MI, Kind, 2);
1203}
1204
1208
1212
1216
1218 raw_ostream &OS) {
1219 // TODO: implement
1220}
1221
1222// Emit .dtprelword or .dtpreldword directive
1223// and value for debug thread local expression.
1224void MipsAsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
1225 if (auto *MipsExpr = dyn_cast<MCSpecifierExpr>(Value)) {
1226 if (MipsExpr && MipsExpr->getSpecifier() == Mips::S_DTPREL) {
1227 switch (Size) {
1228 case 4:
1229 getTargetStreamer().emitDTPRel32Value(MipsExpr->getSubExpr());
1230 break;
1231 case 8:
1232 getTargetStreamer().emitDTPRel64Value(MipsExpr->getSubExpr());
1233 break;
1234 default:
1235 llvm_unreachable("Unexpected size of expression value.");
1236 }
1237 return;
1238 }
1239 }
1241}
1242
1243bool MipsAsmPrinter::isLongBranchPseudo(int Opcode) const {
1244 return (Opcode == Mips::LONG_BRANCH_LUi
1245 || Opcode == Mips::LONG_BRANCH_LUi2Op
1246 || Opcode == Mips::LONG_BRANCH_LUi2Op_64
1247 || Opcode == Mips::LONG_BRANCH_ADDiu
1248 || Opcode == Mips::LONG_BRANCH_ADDiu2Op
1249 || Opcode == Mips::LONG_BRANCH_DADDiu
1250 || Opcode == Mips::LONG_BRANCH_DADDiu2Op);
1251}
1252
1253char MipsAsmPrinter::ID = 0;
1254
1255INITIALIZE_PASS(MipsAsmPrinter, "mips-asm-printer", "Mips Assembly Printer",
1256 false, false)
1257
1258// Force static initialization.
1259extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1260LLVMInitializeMipsAsmPrinter() {
1266}
1267
1276
1288
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.
#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:95
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: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)
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:135
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:105
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: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:220
StringRef getInternalSymbolPrefix() const
Definition DataLayout.h:311
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: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,...