| 1 | //===- MipsAsmPrinter.h - Mips LLVM Assembly Printer -----------*- C++ -*--===// |
| 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 | // Mips Assembly printer class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H |
| 14 | #define LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H |
| 15 | |
| 16 | #include "Mips16HardFloatInfo.h" |
| 17 | #include "MipsMCInstLower.h" |
| 18 | #include "MipsSubtarget.h" |
| 19 | #include "llvm/CodeGen/AsmPrinter.h" |
| 20 | #include "llvm/MC/MCStreamer.h" |
| 21 | #include "llvm/Support/Compiler.h" |
| 22 | #include <algorithm> |
| 23 | #include <map> |
| 24 | #include <memory> |
| 25 | |
| 26 | namespace llvm { |
| 27 | |
| 28 | class MCOperand; |
| 29 | class MCSubtargetInfo; |
| 30 | class MCSymbol; |
| 31 | class MachineBasicBlock; |
| 32 | class MachineConstantPool; |
| 33 | class MachineFunction; |
| 34 | class MachineInstr; |
| 35 | class MachineOperand; |
| 36 | class MipsFunctionInfo; |
| 37 | class MipsTargetStreamer; |
| 38 | class Module; |
| 39 | class raw_ostream; |
| 40 | class TargetMachine; |
| 41 | |
| 42 | class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter { |
| 43 | MipsTargetStreamer &getTargetStreamer() const; |
| 44 | |
| 45 | void EmitInstrWithMacroNoAT(const MachineInstr *MI); |
| 46 | |
| 47 | //===------------------------------------------------------------------===// |
| 48 | // XRay implementation |
| 49 | //===------------------------------------------------------------------===// |
| 50 | |
| 51 | public: |
| 52 | // XRay-specific lowering for Mips. |
| 53 | void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI); |
| 54 | void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI); |
| 55 | void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI); |
| 56 | |
| 57 | private: |
| 58 | /// MCP - Keep a pointer to constantpool entries of the current |
| 59 | /// MachineFunction. |
| 60 | const MachineConstantPool *MCP = nullptr; |
| 61 | |
| 62 | /// InConstantPool - Maintain state when emitting a sequence of constant |
| 63 | /// pool entries so we can properly mark them as data regions. |
| 64 | bool InConstantPool = false; |
| 65 | |
| 66 | std::map<const char *, const Mips16HardFloatInfo::FuncSignature *> |
| 67 | StubsNeeded; |
| 68 | |
| 69 | void EmitSled(const MachineInstr &MI, SledKind Kind); |
| 70 | |
| 71 | // tblgen'erated function. |
| 72 | bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst); |
| 73 | |
| 74 | // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch, |
| 75 | // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate |
| 76 | // for the target. |
| 77 | void emitPseudoIndirectBranch(MCStreamer &OutStreamer, |
| 78 | const MachineInstr *MI); |
| 79 | |
| 80 | // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. |
| 81 | bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); |
| 82 | |
| 83 | void emitInlineAsmStart() const override; |
| 84 | |
| 85 | void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, |
| 86 | const MCSubtargetInfo *EndInfo) const override; |
| 87 | |
| 88 | void emitJumpTableEntry(const MachineJumpTableInfo &MJTI, |
| 89 | const MachineBasicBlock *MBB, |
| 90 | unsigned uid) const override; |
| 91 | |
| 92 | void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol); |
| 93 | |
| 94 | void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg); |
| 95 | |
| 96 | void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode, |
| 97 | unsigned Reg1, unsigned Reg2); |
| 98 | |
| 99 | void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode, |
| 100 | unsigned Reg1, unsigned Reg2, unsigned Reg3); |
| 101 | |
| 102 | void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc, |
| 103 | unsigned Reg1, unsigned Reg2, unsigned FPReg1, |
| 104 | unsigned FPReg2, bool LE); |
| 105 | |
| 106 | void EmitSwapFPIntParams(const MCSubtargetInfo &STI, |
| 107 | Mips16HardFloatInfo::FPParamVariant, bool LE, |
| 108 | bool ToFP); |
| 109 | |
| 110 | void EmitSwapFPIntRetval(const MCSubtargetInfo &STI, |
| 111 | Mips16HardFloatInfo::FPReturnVariant, bool LE); |
| 112 | |
| 113 | void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *); |
| 114 | |
| 115 | void NaClAlignIndirectJumpTargets(MachineFunction &MF); |
| 116 | |
| 117 | bool isLongBranchPseudo(int Opcode) const; |
| 118 | |
| 119 | public: |
| 120 | static char ID; |
| 121 | |
| 122 | const MipsSubtarget *Subtarget; |
| 123 | const MipsFunctionInfo *MipsFI; |
| 124 | MipsMCInstLower MCInstLowering; |
| 125 | |
| 126 | explicit MipsAsmPrinter(TargetMachine &TM, |
| 127 | std::unique_ptr<MCStreamer> Streamer) |
| 128 | : AsmPrinter(TM, std::move(Streamer), ID), MCInstLowering(*this) {} |
| 129 | |
| 130 | StringRef getPassName() const override { return "Mips Assembly Printer" ; } |
| 131 | |
| 132 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 133 | |
| 134 | void emitConstantPool() override { |
| 135 | bool UsingConstantPools = |
| 136 | (Subtarget->inMips16Mode() && Subtarget->useConstantIslands()); |
| 137 | if (!UsingConstantPools) |
| 138 | AsmPrinter::emitConstantPool(); |
| 139 | // we emit constant pools customly! |
| 140 | } |
| 141 | |
| 142 | void emitInstruction(const MachineInstr *MI) override; |
| 143 | void printSavedRegsBitmask(); |
| 144 | void emitFrameDirective(); |
| 145 | const char *getCurrentABIString() const; |
| 146 | void emitFunctionEntryLabel() override; |
| 147 | void emitFunctionBodyStart() override; |
| 148 | void emitFunctionBodyEnd() override; |
| 149 | void emitBasicBlockEnd(const MachineBasicBlock &MBB) override; |
| 150 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 151 | const char *, raw_ostream &O) override; |
| 152 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, |
| 153 | const char *, raw_ostream &O) override; |
| 154 | void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O); |
| 155 | void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O); |
| 156 | void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O); |
| 157 | void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O); |
| 158 | void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O); |
| 159 | void emitStartOfAsmFile(Module &M) override; |
| 160 | void emitEndOfAsmFile(Module &M) override; |
| 161 | void (const MachineInstr *MI, raw_ostream &OS); |
| 162 | void emitDebugValue(const MCExpr *Value, unsigned Size) const override; |
| 163 | }; |
| 164 | |
| 165 | } // end namespace llvm |
| 166 | |
| 167 | #endif // LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H |
| 168 | |