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
26namespace llvm {
27
28class MCOperand;
29class MCSubtargetInfo;
30class MCSymbol;
31class MachineBasicBlock;
32class MachineConstantPool;
33class MachineFunction;
34class MachineInstr;
35class MachineOperand;
36class MipsFunctionInfo;
37class MipsTargetStreamer;
38class Module;
39class raw_ostream;
40class TargetMachine;
41
42class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
43 MipsTargetStreamer &getTargetStreamer() const;
44
45 void EmitInstrWithMacroNoAT(const MachineInstr *MI);
46
47 //===------------------------------------------------------------------===//
48 // XRay implementation
49 //===------------------------------------------------------------------===//
50
51public:
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
57private:
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,
87 const MachineInstr *MI) override;
88
89 void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
90 const MachineBasicBlock *MBB,
91 unsigned uid) const override;
92
93 void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
94
95 void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
96
97 void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
98 unsigned Reg1, unsigned Reg2);
99
100 void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
101 unsigned Reg1, unsigned Reg2, unsigned Reg3);
102
103 void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc,
104 unsigned Reg1, unsigned Reg2, unsigned FPReg1,
105 unsigned FPReg2, bool LE);
106
107 void EmitSwapFPIntParams(const MCSubtargetInfo &STI,
108 Mips16HardFloatInfo::FPParamVariant, bool LE,
109 bool ToFP);
110
111 void EmitSwapFPIntRetval(const MCSubtargetInfo &STI,
112 Mips16HardFloatInfo::FPReturnVariant, bool LE);
113
114 void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
115
116 bool isLongBranchPseudo(int Opcode) const;
117
118public:
119 static char ID;
120
121 const MipsSubtarget *Subtarget;
122 const MipsFunctionInfo *MipsFI;
123 MipsMCInstLower MCInstLowering;
124
125 explicit MipsAsmPrinter(TargetMachine &TM,
126 std::unique_ptr<MCStreamer> Streamer)
127 : AsmPrinter(TM, std::move(Streamer), ID), MCInstLowering(*this) {}
128
129 StringRef getPassName() const override { return "Mips Assembly Printer"; }
130
131 bool runOnMachineFunction(MachineFunction &MF) override;
132
133 void emitConstantPool() override {
134 bool UsingConstantPools =
135 (Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
136 if (!UsingConstantPools)
137 AsmPrinter::emitConstantPool();
138 // we emit constant pools customly!
139 }
140
141 void emitInstruction(const MachineInstr *MI) override;
142 void printSavedRegsBitmask();
143 void emitFrameDirective();
144 const char *getCurrentABIString() const;
145 void emitFunctionEntryLabel() override;
146 void emitFunctionBodyStart() override;
147 void emitFunctionBodyEnd() override;
148 void emitBasicBlockEnd(const MachineBasicBlock &MBB) override;
149 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
150 const char *ExtraCode, raw_ostream &O) override;
151 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
152 const char *ExtraCode, raw_ostream &O) override;
153 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
154 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
155 void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
156 void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
157 void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
158 void emitStartOfAsmFile(Module &M) override;
159 void emitEndOfAsmFile(Module &M) override;
160 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
161 void emitDebugValue(const MCExpr *Value, unsigned Size) const override;
162};
163
164} // end namespace llvm
165
166#endif // LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
167