LLVM  8.0.1
MipsAsmPrinter.h
Go to the documentation of this file.
1 //===- MipsAsmPrinter.h - Mips LLVM Assembly Printer -----------*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Mips Assembly printer class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
15 #define LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
16 
17 #include "Mips16HardFloatInfo.h"
18 #include "MipsMCInstLower.h"
19 #include "MipsSubtarget.h"
21 #include "llvm/MC/MCStreamer.h"
22 #include "llvm/Support/Compiler.h"
23 #include <algorithm>
24 #include <map>
25 #include <memory>
26 
27 namespace llvm {
28 
29 class MCOperand;
30 class MCSubtargetInfo;
31 class MCSymbol;
32 class MachineBasicBlock;
33 class MachineConstantPool;
34 class MachineFunction;
35 class MachineInstr;
36 class MachineOperand;
37 class MipsFunctionInfo;
38 class MipsTargetStreamer;
39 class Module;
40 class raw_ostream;
41 class TargetMachine;
42 
44  MipsTargetStreamer &getTargetStreamer() const;
45 
46  void EmitInstrWithMacroNoAT(const MachineInstr *MI);
47 
48  //===------------------------------------------------------------------===//
49  // XRay implementation
50  //===------------------------------------------------------------------===//
51 
52 public:
53  // XRay-specific lowering for Mips.
54  void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
55  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
56  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
57 
58 private:
59  /// MCP - Keep a pointer to constantpool entries of the current
60  /// MachineFunction.
61  const MachineConstantPool *MCP = nullptr;
62 
63  /// InConstantPool - Maintain state when emitting a sequence of constant
64  /// pool entries so we can properly mark them as data regions.
65  bool InConstantPool = false;
66 
67  std::map<const char *, const Mips16HardFloatInfo::FuncSignature *>
68  StubsNeeded;
69 
70  void EmitSled(const MachineInstr &MI, SledKind Kind);
71 
72  // tblgen'erated function.
73  bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
74  const MachineInstr *MI);
75 
76  // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch,
77  // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate
78  // for the target.
79  void emitPseudoIndirectBranch(MCStreamer &OutStreamer,
80  const MachineInstr *MI);
81 
82  // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
83  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
84 
85  void emitInlineAsmStart() const override;
86 
87  void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
88  const MCSubtargetInfo *EndInfo) const override;
89 
90  void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
91 
92  void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
93 
94  void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
95  unsigned Reg1, unsigned Reg2);
96 
97  void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
98  unsigned Reg1, unsigned Reg2, unsigned Reg3);
99 
100  void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc,
101  unsigned Reg1, unsigned Reg2, unsigned FPReg1,
102  unsigned FPReg2, bool LE);
103 
104  void EmitSwapFPIntParams(const MCSubtargetInfo &STI,
106  bool ToFP);
107 
108  void EmitSwapFPIntRetval(const MCSubtargetInfo &STI,
110 
111  void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
112 
113  void NaClAlignIndirectJumpTargets(MachineFunction &MF);
114 
115  bool isLongBranchPseudo(int Opcode) const;
116 
117 public:
121 
123  std::unique_ptr<MCStreamer> Streamer)
124  : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(*this) {}
125 
126  StringRef getPassName() const override { return "Mips Assembly Printer"; }
127 
128  bool runOnMachineFunction(MachineFunction &MF) override;
129 
130  void EmitConstantPool() override {
131  bool UsingConstantPools =
132  (Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
133  if (!UsingConstantPools)
135  // we emit constant pools customly!
136  }
137 
138  void EmitInstruction(const MachineInstr *MI) override;
139  void printSavedRegsBitmask();
140  void emitFrameDirective();
141  const char *getCurrentABIString() const;
142  void EmitFunctionEntryLabel() override;
143  void EmitFunctionBodyStart() override;
144  void EmitFunctionBodyEnd() override;
145  void EmitBasicBlockEnd(const MachineBasicBlock &MBB) override;
146  bool isBlockOnlyReachableByFallthrough(
147  const MachineBasicBlock* MBB) const override;
148  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
149  unsigned AsmVariant, const char *ExtraCode,
150  raw_ostream &O) override;
151  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
152  unsigned AsmVariant, const char *ExtraCode,
153  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  const char *Modifier = nullptr);
159  void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
160  void EmitStartOfAsmFile(Module &M) override;
161  void EmitEndOfAsmFile(Module &M) override;
162  void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
163  void EmitDebugValue(const MCExpr *Value, unsigned Size) const override;
164 };
165 
166 } // end namespace llvm
167 
168 #endif // LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool inMips16Mode() const
unsigned Reg
virtual void EmitConstantPool()
Print to the current output stream assembly representations of the constants in the constant pool MCP...
Definition: BitVector.h:938
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
MipsMCInstLower - This class is used to lower an MachineInstr into an MCInst.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
void EmitConstantPool() override
Print to the current output stream assembly representations of the constants in the constant pool MCP...
Streaming machine code generation interface.
Definition: MCStreamer.h:189
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:79
MipsMCInstLower MCInstLowering
MipsAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
static bool useConstantIslands()
static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, const MachineFunction *MF, const Module *M, const MachineFrameInfo *MFI, const TargetInstrInfo *TII, LLVMContext &Ctx)
MachineOperand class - Representation of each machine instruction operand.
Representation of each machine instruction.
Definition: MachineInstr.h:64
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
const MipsSubtarget * Subtarget
Generic base class for all target subtargets.
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
uint32_t Size
Definition: Profile.cpp:47
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:108
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
const MipsFunctionInfo * MipsFI
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35