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