2017-08-04 00:12:30 +02:00
|
|
|
//===- MipsAsmPrinter.h - Mips LLVM Assembly Printer -----------*- C++ -*--===//
|
2011-07-07 22:10:52 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Mips Assembly printer class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
|
2011-07-07 22:10:52 +02:00
|
|
|
|
2014-02-14 20:16:39 +01:00
|
|
|
#include "Mips16HardFloatInfo.h"
|
2012-03-28 02:22:50 +02:00
|
|
|
#include "MipsMCInstLower.h"
|
2011-07-07 22:10:52 +02:00
|
|
|
#include "MipsSubtarget.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2017-08-04 00:12:30 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-07 22:10:52 +02:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2017-08-04 00:12:30 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2011-07-07 22:10:52 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-08-04 00:12:30 +02:00
|
|
|
|
|
|
|
class MCOperand;
|
|
|
|
class MCSubtargetInfo;
|
|
|
|
class MCSymbol;
|
2011-07-07 22:10:52 +02:00
|
|
|
class MachineBasicBlock;
|
2017-08-04 00:12:30 +02:00
|
|
|
class MachineConstantPool;
|
|
|
|
class MachineFunction;
|
|
|
|
class MachineInstr;
|
|
|
|
class MachineOperand;
|
|
|
|
class MipsFunctionInfo;
|
2013-10-08 15:08:17 +02:00
|
|
|
class MipsTargetStreamer;
|
2011-07-07 22:10:52 +02:00
|
|
|
class Module;
|
2012-03-17 19:46:09 +01:00
|
|
|
class raw_ostream;
|
2017-08-04 00:12:30 +02:00
|
|
|
class TargetMachine;
|
2011-07-07 22:10:52 +02:00
|
|
|
|
|
|
|
class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
|
2014-12-17 11:56:16 +01:00
|
|
|
MipsTargetStreamer &getTargetStreamer() const;
|
2011-11-23 23:19:28 +01:00
|
|
|
|
2012-03-28 02:22:50 +02:00
|
|
|
void EmitInstrWithMacroNoAT(const MachineInstr *MI);
|
|
|
|
|
2017-02-15 11:48:11 +01:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// XRay implementation
|
|
|
|
//===------------------------------------------------------------------===//
|
2017-08-04 00:12:30 +02:00
|
|
|
|
2017-02-15 11:48:11 +01:00
|
|
|
public:
|
|
|
|
// XRay-specific lowering for Mips.
|
|
|
|
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
|
|
|
|
void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
|
|
|
|
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
|
|
|
|
|
2012-09-27 03:59:07 +02:00
|
|
|
private:
|
2017-08-04 00:12:30 +02:00
|
|
|
/// MCP - Keep a pointer to constantpool entries of the current
|
|
|
|
/// MachineFunction.
|
|
|
|
const MachineConstantPool *MCP = nullptr;
|
|
|
|
|
|
|
|
/// InConstantPool - Maintain state when emitting a sequence of constant
|
|
|
|
/// pool entries so we can properly mark them as data regions.
|
|
|
|
bool InConstantPool = false;
|
|
|
|
|
|
|
|
std::map<const char *, const Mips16HardFloatInfo::FuncSignature *>
|
|
|
|
StubsNeeded;
|
|
|
|
|
2017-02-15 11:48:11 +01:00
|
|
|
void EmitSled(const MachineInstr &MI, SledKind Kind);
|
|
|
|
|
2012-09-27 03:59:07 +02:00
|
|
|
// tblgen'erated function.
|
|
|
|
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
|
|
|
|
const MachineInstr *MI);
|
|
|
|
|
2014-07-09 12:21:59 +02:00
|
|
|
// Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch,
|
|
|
|
// and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate
|
|
|
|
// for the target.
|
|
|
|
void emitPseudoIndirectBranch(MCStreamer &OutStreamer,
|
|
|
|
const MachineInstr *MI);
|
[mips][mips64r6] Use JALR for returns instead of JR (which is not available on MIPS32r6/MIPS64r6)
Summary:
RET, and RET_MM have been replaced by a pseudo named PseudoReturn.
In addition a version with a 64-bit GPR named PseudoReturn64 has been
added.
Instruction selection for a return matches RetRA, which is expanded post
register allocation to PseudoReturn/PseudoReturn64. During MipsAsmPrinter,
this PseudoReturn/PseudoReturn64 are emitted as:
- (JALR64 $zero, $rs) on MIPS64r6
- (JALR $zero, $rs) on MIPS32r6
- (JR_MM $rs) on microMIPS
- (JR $rs) otherwise
On MIPS32r6/MIPS64r6, 'jr $rs' is an alias for 'jalr $zero, $rs'. To aid
development and review (specifically, to ensure all cases of jr are
updated), these aliases are temporarily named 'r6.jr' instead of 'jr'.
A follow up patch will change them back to the correct mnemonic.
Added (JALR $zero, $rs) to MipsNaClELFStreamer's definition of an indirect
jump, and removed it from its definition of a call.
Note: I haven't accounted for MIPS64 in MipsNaClELFStreamer since it's
doesn't appear to account for any MIPS64-specifics.
The return instruction created as part of eh_return expansion is now expanded
using expandRetRA() so we use the right return instruction on MIPS32r6/MIPS64r6
('jalr $zero, $rs').
Also, fixed a misuse of isABI_N64() to detect 64-bit wide registers in
expandEhReturn().
Reviewers: jkolek, vmedic, mseaborn, zoran.jovanovic, dsanders
Reviewed By: dsanders
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D4268
llvm-svn: 212604
2014-07-09 12:16:07 +02:00
|
|
|
|
2012-09-27 03:59:07 +02:00
|
|
|
// lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
|
|
|
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
|
|
|
|
|
2015-02-19 20:52:25 +01:00
|
|
|
void emitInlineAsmStart() const override;
|
2014-12-17 11:56:16 +01:00
|
|
|
|
|
|
|
void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
|
|
|
|
const MCSubtargetInfo *EndInfo) const override;
|
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
|
|
|
|
unsigned Reg1, unsigned Reg2);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
|
|
|
|
unsigned Reg1, unsigned Reg2, unsigned Reg3);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc,
|
|
|
|
unsigned Reg1, unsigned Reg2, unsigned FPReg1,
|
|
|
|
unsigned FPReg2, bool LE);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitSwapFPIntParams(const MCSubtargetInfo &STI,
|
|
|
|
Mips16HardFloatInfo::FPParamVariant, bool LE,
|
2014-02-14 20:16:39 +01:00
|
|
|
bool ToFP);
|
|
|
|
|
2015-02-21 09:48:22 +01:00
|
|
|
void EmitSwapFPIntRetval(const MCSubtargetInfo &STI,
|
|
|
|
Mips16HardFloatInfo::FPReturnVariant, bool LE);
|
2014-02-14 20:16:39 +01:00
|
|
|
|
|
|
|
void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
|
2013-10-27 22:57:36 +01:00
|
|
|
|
2014-02-28 11:00:38 +01:00
|
|
|
void NaClAlignIndirectJumpTargets(MachineFunction &MF);
|
|
|
|
|
2014-04-30 17:06:25 +02:00
|
|
|
bool isLongBranchPseudo(int Opcode) const;
|
|
|
|
|
2011-07-07 22:10:52 +02:00
|
|
|
public:
|
2011-11-23 23:19:28 +01:00
|
|
|
const MipsSubtarget *Subtarget;
|
2012-03-28 02:22:50 +02:00
|
|
|
const MipsFunctionInfo *MipsFI;
|
|
|
|
MipsMCInstLower MCInstLowering;
|
2011-11-23 23:19:28 +01:00
|
|
|
|
2015-01-18 21:29:04 +01:00
|
|
|
explicit MipsAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
2017-08-04 00:12:30 +02:00
|
|
|
: AsmPrinter(TM, std::move(Streamer)), MCInstLowering(*this) {}
|
2011-07-07 22:10:52 +02:00
|
|
|
|
2016-10-01 04:56:57 +02:00
|
|
|
StringRef getPassName() const override { return "Mips Assembly Printer"; }
|
2011-07-07 22:10:52 +02:00
|
|
|
|
2014-04-29 09:58:02 +02:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2012-03-28 02:22:50 +02:00
|
|
|
|
2014-04-29 09:58:02 +02:00
|
|
|
void EmitConstantPool() override {
|
2013-11-26 21:38:40 +01:00
|
|
|
bool UsingConstantPools =
|
|
|
|
(Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
|
2013-10-27 22:57:36 +01:00
|
|
|
if (!UsingConstantPools)
|
|
|
|
AsmPrinter::EmitConstantPool();
|
|
|
|
// we emit constant pools customly!
|
|
|
|
}
|
|
|
|
|
2014-04-29 09:58:02 +02:00
|
|
|
void EmitInstruction(const MachineInstr *MI) override;
|
2014-01-27 05:33:11 +01:00
|
|
|
void printSavedRegsBitmask();
|
2011-07-07 22:10:52 +02:00
|
|
|
void emitFrameDirective();
|
|
|
|
const char *getCurrentABIString() const;
|
2014-04-29 09:58:02 +02:00
|
|
|
void EmitFunctionEntryLabel() override;
|
|
|
|
void EmitFunctionBodyStart() override;
|
|
|
|
void EmitFunctionBodyEnd() override;
|
2015-05-08 11:10:15 +02:00
|
|
|
void EmitBasicBlockEnd(const MachineBasicBlock &MBB) override;
|
2014-04-29 09:58:02 +02:00
|
|
|
bool isBlockOnlyReachableByFallthrough(
|
|
|
|
const MachineBasicBlock* MBB) const override;
|
2011-07-07 22:10:52 +02:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2014-04-29 09:58:02 +02:00
|
|
|
raw_ostream &O) override;
|
2011-07-07 22:10:52 +02:00
|
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
|
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2014-04-29 09:58:02 +02:00
|
|
|
raw_ostream &O) override;
|
2011-07-07 22:10:52 +02:00
|
|
|
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
|
2011-07-07 22:54:20 +02:00
|
|
|
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
|
|
|
|
void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
|
2016-09-09 13:06:01 +02:00
|
|
|
void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
|
|
|
|
const char *Modifier = nullptr);
|
2014-11-19 17:44:02 +01:00
|
|
|
void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
|
2014-04-29 09:58:02 +02:00
|
|
|
void EmitStartOfAsmFile(Module &M) override;
|
|
|
|
void EmitEndOfAsmFile(Module &M) override;
|
2011-07-07 22:10:52 +02:00
|
|
|
void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
|
2017-02-08 20:03:46 +01:00
|
|
|
void EmitDebugThreadLocal(const MCExpr *Value, unsigned Size) const override;
|
2011-07-07 22:10:52 +02:00
|
|
|
};
|
|
|
|
|
2017-08-04 00:12:30 +02:00
|
|
|
} // end namespace llvm
|
2011-07-07 22:10:52 +02:00
|
|
|
|
2017-08-04 00:12:30 +02:00
|
|
|
#endif // LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
|