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