58 #define DEBUG_TYPE "asm-printer" 68 AArch64AsmPrinter(
TargetMachine &
TM, std::unique_ptr<MCStreamer> Streamer)
69 :
AsmPrinter(TM, std::move(Streamer)), MCInstLowering(OutContext, *
this),
72 StringRef getPassName()
const override {
return "AArch64 Assembly Printer"; }
85 void LowerPATCHABLE_FUNCTION_ENTER(
const MachineInstr &MI);
86 void LowerPATCHABLE_FUNCTION_EXIT(
const MachineInstr &MI);
93 bool emitPseudoExpansionLowering(
MCStreamer &OutStreamer,
118 bool PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNum,
119 unsigned AsmVariant,
const char *ExtraCode,
121 bool PrintAsmMemoryOperand(
const MachineInstr *MI,
unsigned OpNum,
122 unsigned AsmVariant,
const char *ExtraCode,
127 void EmitFunctionBodyEnd()
override;
129 MCSymbol *GetCPISymbol(
unsigned CPID)
const override;
130 void EmitEndOfAsmFile(
Module &M)
override;
140 using MInstToMCSymbol = std::map<const MachineInstr *, MCSymbol *>;
142 MInstToMCSymbol LOHInstToLabel;
147 void AArch64AsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
const MachineInstr &
MI)
149 EmitSled(MI, SledKind::FUNCTION_ENTER);
152 void AArch64AsmPrinter::LowerPATCHABLE_FUNCTION_EXIT(
const MachineInstr &MI)
154 EmitSled(MI, SledKind::FUNCTION_EXIT);
157 void AArch64AsmPrinter::LowerPATCHABLE_TAIL_CALL(
const MachineInstr &MI)
159 EmitSled(MI, SledKind::TAIL_CALL);
164 static const int8_t NoopsInSledCount = 7;
185 OutStreamer->EmitCodeAlignment(4);
186 auto CurSled = OutContext.createTempSymbol(
"xray_sled_",
true);
187 OutStreamer->EmitLabel(CurSled);
188 auto Target = OutContext.createTempSymbol();
195 for (int8_t
I = 0;
I < NoopsInSledCount;
I++)
196 EmitToStreamer(*OutStreamer,
MCInstBuilder(AArch64::HINT).addImm(0));
198 OutStreamer->EmitLabel(
Target);
199 recordSled(CurSled, MI, Kind);
202 void AArch64AsmPrinter::EmitEndOfAsmFile(
Module &M) {
203 const Triple &TT =
TM.getTargetTriple();
211 SM.serializeToStackMapSection();
215 void AArch64AsmPrinter::EmitLOHs() {
218 for (
const auto &
D : AArch64FI->getLOHContainer()) {
220 MInstToMCSymbol::iterator LabelIt = LOHInstToLabel.find(MI);
221 assert(LabelIt != LOHInstToLabel.end() &&
222 "Label hasn't been inserted for LOH related instruction");
225 OutStreamer->EmitLOHDirective(
D.getKind(), MCArgs);
230 void AArch64AsmPrinter::EmitFunctionBodyEnd() {
231 if (!AArch64FI->getLOHRelated().empty())
236 MCSymbol *AArch64AsmPrinter::GetCPISymbol(
unsigned CPID)
const {
240 if (!getDataLayout().getLinkerPrivateGlobalPrefix().empty())
241 return OutContext.getOrCreateSymbol(
242 Twine(getDataLayout().getLinkerPrivateGlobalPrefix()) +
"CPI" +
243 Twine(getFunctionNumber()) +
"_" +
Twine(CPID));
262 int64_t Imm = MO.
getImm();
306 bool AArch64AsmPrinter::printAsmRegInClass(
const MachineOperand &MO,
309 assert(MO.
isReg() &&
"Should only get here with a register!");
312 unsigned RegToPrint = RC->
getRegister(RI->getEncodingValue(Reg));
313 assert(RI->regsOverlap(RegToPrint, Reg));
315 RegToPrint, isVector ? AArch64::vreg : AArch64::NoRegAltName);
319 bool AArch64AsmPrinter::PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNum,
329 if (ExtraCode && ExtraCode[0]) {
330 if (ExtraCode[1] != 0)
333 switch (ExtraCode[0]) {
337 PrintAsmMemoryOperand(MI, OpNum, AsmVariant, ExtraCode, O);
344 unsigned Reg = ExtraCode[0] ==
'w' ? AArch64::WZR : AArch64::XZR;
357 switch (ExtraCode[0]) {
359 RC = &AArch64::FPR8RegClass;
362 RC = &AArch64::FPR16RegClass;
365 RC = &AArch64::FPR32RegClass;
368 RC = &AArch64::FPR64RegClass;
371 RC = &AArch64::FPR128RegClass;
376 return printAsmRegInClass(MO, RC,
false , O);
389 if (AArch64::GPR32allRegClass.
contains(Reg) ||
390 AArch64::GPR64allRegClass.
contains(Reg))
394 return printAsmRegInClass(MO, &AArch64::FPR128RegClass,
true ,
402 bool AArch64AsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *MI,
405 const char *ExtraCode,
407 if (ExtraCode && ExtraCode[0] && ExtraCode[0] !=
'a')
411 assert(MO.
isReg() &&
"unexpected inline asm memory operand");
416 void AArch64AsmPrinter::PrintDebugValueComment(
const MachineInstr *MI,
420 OS <<
'\t' << MAI->getCommentString() <<
"DEBUG_VALUE: ";
441 assert(NumNOPBytes % 4 == 0 &&
"Invalid number of NOP bytes requested!");
447 while (NumNOPBytes > 0) {
448 if (MII == MBB.
end() || MII->isCall() ||
449 MII->getOpcode() == AArch64::DBG_VALUE ||
450 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
451 MII->getOpcode() == TargetOpcode::STACKMAP)
458 for (
unsigned i = 0; i < NumNOPBytes; i += 4)
471 unsigned EncodedBytes = 0;
473 assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
474 "High 16 bits of call target should be zero.");
480 .addImm((CallTarget >> 32) & 0xFFFF)
485 .addImm((CallTarget >> 16) & 0xFFFF)
490 .addImm(CallTarget & 0xFFFF)
492 EmitToStreamer(OutStreamer,
MCInstBuilder(AArch64::BLR).addReg(ScratchReg));
496 assert(NumBytes >= EncodedBytes &&
497 "Patchpoint can't request size less than the length of a call.");
498 assert((NumBytes - EncodedBytes) % 4 == 0 &&
499 "Invalid number of NOP bytes requested!");
500 for (
unsigned i = EncodedBytes; i < NumBytes; i += 4)
501 EmitToStreamer(OutStreamer,
MCInstBuilder(AArch64::HINT).addImm(0));
504 void AArch64AsmPrinter::EmitFMov0(
const MachineInstr &MI) {
506 if (STI->hasZeroCycleZeroing() && !STI->hasZeroCycleZeroingFPWorkaround()) {
508 if (AArch64::H0 <= DestReg && DestReg <= AArch64::H31)
509 DestReg = AArch64::Q0 + (DestReg - AArch64::H0);
510 else if (AArch64::S0 <= DestReg && DestReg <= AArch64::S31)
511 DestReg = AArch64::Q0 + (DestReg - AArch64::S0);
513 assert(AArch64::D0 <= DestReg && DestReg <= AArch64::D31);
514 DestReg = AArch64::Q0 + (DestReg - AArch64::D0);
517 MOVI.setOpcode(AArch64::MOVIv2d_ns);
520 EmitToStreamer(*OutStreamer, MOVI);
525 case AArch64::FMOVH0:
530 case AArch64::FMOVS0:
535 case AArch64::FMOVD0:
541 EmitToStreamer(*OutStreamer, FMov);
547 #include "AArch64GenMCPseudoLowering.inc" 549 void AArch64AsmPrinter::EmitInstruction(
const MachineInstr *MI) {
551 if (emitPseudoExpansionLowering(*OutStreamer, MI))
554 if (AArch64FI->getLOHRelated().count(MI)) {
556 MCSymbol *LOHLabel = createTempSymbol(
"loh");
558 LOHInstToLabel[
MI] = LOHLabel;
566 case AArch64::MOVIv2d_ns:
569 if (STI->hasZeroCycleZeroingFPWorkaround() &&
575 EmitToStreamer(*OutStreamer, TmpInst);
580 case AArch64::DBG_VALUE: {
584 PrintDebugValueComment(MI, OS);
593 case AArch64::TCRETURNri: {
597 EmitToStreamer(*OutStreamer, TmpInst);
600 case AArch64::TCRETURNdi: {
602 MCInstLowering.lowerOperand(MI->
getOperand(0), Dest);
606 EmitToStreamer(*OutStreamer, TmpInst);
619 MCOperand Sym, SymTLSDescLo12, SymTLSDesc;
622 MCInstLowering.lowerOperand(MO_Sym, Sym);
623 MCInstLowering.lowerOperand(MO_TLSDESC_LO12, SymTLSDescLo12);
624 MCInstLowering.lowerOperand(MO_TLSDESC, SymTLSDesc);
630 EmitToStreamer(*OutStreamer, Adrp);
638 EmitToStreamer(*OutStreamer, Ldr);
646 EmitToStreamer(*OutStreamer, Add);
651 TLSDescCall.
setOpcode(AArch64::TLSDESCCALL);
653 EmitToStreamer(*OutStreamer, TLSDescCall);
658 EmitToStreamer(*OutStreamer, Blr);
663 case AArch64::FMOVH0:
664 case AArch64::FMOVS0:
665 case AArch64::FMOVD0:
669 case TargetOpcode::STACKMAP:
670 return LowerSTACKMAP(*OutStreamer, SM, *MI);
672 case TargetOpcode::PATCHPOINT:
673 return LowerPATCHPOINT(*OutStreamer, SM, *MI);
675 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
676 LowerPATCHABLE_FUNCTION_ENTER(*MI);
679 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
680 LowerPATCHABLE_FUNCTION_EXIT(*MI);
683 case TargetOpcode::PATCHABLE_TAIL_CALL:
684 LowerPATCHABLE_TAIL_CALL(*MI);
690 MCInstLowering.Lower(MI, TmpInst);
691 EmitToStreamer(*OutStreamer, TmpInst);
unsigned getTargetFlags() const
void push_back(const T &Elt)
Target & getTheAArch64beTarget()
static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO, char Mode, raw_ostream &O)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned getNextScratchIdx(unsigned StartIdx=0) const
Get the next scratch register operand index.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
static const char * getRegisterName(unsigned RegNo, unsigned AltIdx=AArch64::NoRegAltName)
void EmitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ...
Compute iterated dominance frontiers using a linear time algorithm.
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
void setTargetFlags(unsigned F)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
Target & getTheAArch64leTarget()
unsigned getRegister(unsigned i) const
Return the specified register in the class.
unsigned getReg() const
getReg - Returns the register number.
unsigned getSubReg() const
A raw_ostream that writes to an SmallVector or SmallString.
static unsigned getXRegFromWReg(unsigned Reg)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
return AArch64::GPR64RegClass contains(Reg)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumOperands() const
Access to explicit operands of the instruction.
void LLVMInitializeAArch64AsmPrinter()
static StringRef getName(Value *V)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Target & getTheARM64Target()
zlib-gnu style compression
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Instances of this class represent a single low-level machine instruction.
static unsigned getWRegFromXReg(unsigned Reg)
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText...
static unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
Address of a global value.
Streaming machine code generation interface.
Control flow instructions. These all have token chains.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const GlobalValue * getGlobal() const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
This class is intended to be used as a driving class for all asm writers.
Represent the analysis usage information of a pass.
Address of a basic block.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
.subsections_via_symbols (MachO)
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
MI-level patchpoint operands.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
MO_TLS - Indicates that the operand being accessed is some kind of thread-local symbol.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void recordPatchPoint(const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
Triple - Helper class for working with autoconf configuration names.
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given stackmap should emit.
void setOpcode(unsigned Op)
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
StringRef str()
Return a StringRef for the vector contents.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Target - Wrapper for Target specific information.
void recordStackMap(const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
void setPreservesAll()
Set by analyses that do not transform their input at all.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
AArch64MCInstLower - This class is used to lower an MachineInstr into an MCInst.
MI-level stackmap operands.
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given patchpoint should emit.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
This class implements an extremely fast bulk output stream that can only output to a stream...
Primary interface to the complete machine description for the target machine.
const MachineOperand & getCallTarget() const
Returns the target of the underlying call.
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
Instances of this class represent operands of the MCInst class.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
const MDNode * getMetadata() const
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.