67 const TargetMachine &TM;
69 X86AsmPrinter &AsmPrinter;
74 MCOperand LowerMachineOperand(
const MachineInstr *
MI,
75 const MachineOperand &MO)
const;
76 void Lower(
const MachineInstr *
MI, MCInst &OutMI)
const;
82 MachineModuleInfoMachO &getMachOMMI()
const;
98 if (b ==
OS.getAllowAutoPadding())
100 OS.setAllowAutoPadding(b);
102 OS.emitRawComment(
"autopadding");
104 OS.emitRawComment(
"noautopadding");
112void X86AsmPrinter::StackMapShadowTracker::count(
const MCInst &Inst,
116 SmallString<256>
Code;
119 CurrentShadowSize +=
Code.size();
120 if (CurrentShadowSize >= RequiredShadowSize)
125void X86AsmPrinter::StackMapShadowTracker::emitShadowPadding(
126 MCStreamer &
OutStreamer,
const MCSubtargetInfo &STI) {
127 if (InShadow && CurrentShadowSize < RequiredShadowSize) {
130 &
MF->getSubtarget<X86Subtarget>());
134void X86AsmPrinter::EmitAndCountInstruction(MCInst &Inst) {
150MCSymbol *X86MCInstLower::GetSymbolFromOperand(
const MachineOperand &MO)
const {
157 "Isn't a symbol reference");
160 SmallString<128>
Name;
173 Suffix =
"$non_lazy_ptr";
178 Name +=
DL.getInternalSymbolPrefix();
185 }
else if (MO.
isMBB()) {
200 MachineModuleInfoCOFF &MMICOFF =
203 if (!StubSym.getPointer()) {
213 getMachOMMI().getGVStubEntry(Sym);
227MCOperand X86MCInstLower::LowerSymbolOperand(
const MachineOperand &MO,
228 MCSymbol *Sym)
const {
231 const MCExpr *Expr =
nullptr;
314 AsmPrinter.
OutStreamer->emitAssignment(Label, Expr);
330 return Subtarget.is64Bit() ? X86::RET64 : X86::RET32;
333MCOperand X86MCInstLower::LowerMachineOperand(
const MachineInstr *
MI,
334 const MachineOperand &MO)
const {
370 Opcode = X86::JMP32r;
373 Opcode = X86::JMP32m;
375 case X86::TAILJMPr64:
376 Opcode = X86::JMP64r;
378 case X86::TAILJMPm64:
379 Opcode = X86::JMP64m;
381 case X86::TAILJMPr64_REX:
382 Opcode = X86::JMP64r_REX;
384 case X86::TAILJMPm64_REX:
385 Opcode = X86::JMP64m_REX;
388 case X86::TAILJMPd64:
389 Opcode = IsLarge ? X86::JMPABS64i : X86::JMP_1;
391 case X86::TAILJMPd_CC:
392 case X86::TAILJMPd64_CC:
400void X86MCInstLower::Lower(
const MachineInstr *
MI, MCInst &OutMI)
const {
403 for (
const MachineOperand &MO :
MI->operands())
404 if (
auto Op = LowerMachineOperand(
MI, MO);
Op.isValid())
424 "Unexpected # of LEA operands");
426 "LEA has segment specified!");
431 case X86::MULX64Hrm: {
436 case X86::MULX32Hrr: NewOpc = X86::MULX32rr;
break;
437 case X86::MULX32Hrm: NewOpc = X86::MULX32rm;
break;
438 case X86::MULX64Hrr: NewOpc = X86::MULX64rr;
break;
439 case X86::MULX64Hrm: NewOpc = X86::MULX64rm;
break;
452 case X86::CALL64pcrel32:
456 case X86::EH_RETURN64: {
461 case X86::CLEANUPRET: {
467 case X86::CATCHRET: {
470 unsigned ReturnReg = In64BitMode ? X86::RAX : X86::EAX;
479 case X86::TAILJMPr64:
480 case X86::TAILJMPr64_REX:
485 case X86::TAILJMPd64: {
489 "Unexpected TAILJMPd64 in large code model without JMPABS");
493 case X86::TAILJMPd_CC:
494 case X86::TAILJMPd64_CC:
499 case X86::TAILJMPm64:
500 case X86::TAILJMPm64_REX:
502 "Unexpected number of operands!");
505 case X86::MASKMOVDQU:
506 case X86::VMASKMOVDQU:
520 const MachineOperand *FlagDef =
521 MI->findRegisterDefOperand(X86::EFLAGS,
nullptr);
531void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
532 const MachineInstr &
MI) {
533 NoAutoPaddingScope NoPadScope(*OutStreamer);
534 bool Is64Bits = getSubtarget().is64Bit();
535 bool Is64BitsLP64 = getSubtarget().isTarget64BitLP64();
539 switch (
MI.getOpcode()) {
540 case X86::TLS_addr32:
541 case X86::TLS_addr64:
542 case X86::TLS_addrX32:
545 case X86::TLS_base_addr32:
548 case X86::TLS_base_addr64:
549 case X86::TLS_base_addrX32:
552 case X86::TLS_desc32:
553 case X86::TLS_desc64:
561 MCInstLowering.GetSymbolFromOperand(
MI.getOperand(3)), Specifier, Ctx);
568 bool UseGot = MMI->getModule()->getRtLibUseGOT() &&
575 EmitAndCountInstruction(
576 MCInstBuilder(Is64BitsLP64 ? X86::LEA64r : X86::LEA32r)
577 .addReg(Is64BitsLP64 ? X86::RAX : X86::EAX)
578 .addReg(Is64Bits ? X86::RIP : X86::EBX)
583 EmitAndCountInstruction(
584 MCInstBuilder(Is64Bits ? X86::CALL64m : X86::CALL32m)
585 .addReg(Is64BitsLP64 ? X86::RAX : X86::EAX)
590 }
else if (Is64Bits) {
592 if (NeedsPadding && Is64BitsLP64)
593 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
594 EmitAndCountInstruction(MCInstBuilder(X86::LEA64r)
604 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
605 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
606 EmitAndCountInstruction(MCInstBuilder(X86::REX64_PREFIX));
611 EmitAndCountInstruction(MCInstBuilder(X86::CALL64m)
618 EmitAndCountInstruction(
619 MCInstBuilder(X86::CALL64pcrel32)
624 EmitAndCountInstruction(MCInstBuilder(X86::LEA32r)
632 EmitAndCountInstruction(MCInstBuilder(X86::LEA32r)
644 EmitAndCountInstruction(MCInstBuilder(X86::CALL32m)
651 EmitAndCountInstruction(
652 MCInstBuilder(X86::CALLpcrel32)
665 unsigned MaxNopLength = 1;
666 unsigned BaseReg = X86::RAX;
668 if (
Subtarget->hasFeature(X86::TuningFast7ByteNOP))
670 else if (
Subtarget->hasFeature(X86::TuningFast15ByteNOP))
672 else if (
Subtarget->hasFeature(X86::TuningFast11ByteNOP))
683 NumBytes = std::min(NumBytes, MaxNopLength);
686 unsigned Opc, ScaleVal, IndexReg, Displacement, SegmentReg;
687 IndexReg = Displacement = SegmentReg = 0;
744 SegmentReg = X86::CS;
748 unsigned NumPrefixes = std::min(NumBytes - NopSize, 5U);
749 NopSize += NumPrefixes;
750 for (
unsigned i = 0; i != NumPrefixes; ++i)
768 .addImm(Displacement)
773 assert(NopSize <= NumBytes &&
"We overemitted?");
780 unsigned NopsToEmit = NumBytes;
784 assert(NopsToEmit >= NumBytes &&
"Emitted more than I asked for!");
788void X86AsmPrinter::LowerSTATEPOINT(
const MachineInstr &
MI,
789 X86MCInstLower &MCIL) {
790 assert(
Subtarget->is64Bit() &&
"Statepoint currently only supports X86-64");
792 NoAutoPaddingScope NoPadScope(*OutStreamer);
794 StatepointOpers SOpers(&
MI);
795 if (
unsigned PatchBytes = SOpers.getNumPatchBytes()) {
799 const MachineOperand &CallTarget = SOpers.getCallTarget();
800 MCOperand CallTargetMCOp;
802 switch (CallTarget.
getType()) {
805 CallTargetMCOp = MCIL.LowerSymbolOperand(
806 CallTarget, MCIL.GetSymbolFromOperand(CallTarget));
807 CallOpcode = X86::CALL64pcrel32;
815 CallOpcode = X86::CALL64pcrel32;
827 CallOpcode = X86::CALL64r;
839 maybeEmitNopAfterCallForWindowsEH(&
MI);
847 SM.recordStatepoint(*MILabel,
MI);
850void X86AsmPrinter::LowerFAULTING_OP(
const MachineInstr &FaultingMI,
851 X86MCInstLower &MCIL) {
855 NoAutoPaddingScope NoPadScope(*OutStreamer);
862 unsigned OperandsBeginIdx = 4;
869 FM.recordFaultingOp(FK, FaultingLabel, HandlerLabel);
872 MI.setOpcode(Opcode);
874 if (DefRegister != X86::NoRegister)
877 for (
const MachineOperand &MO :
879 if (
auto Op = MCIL.LowerMachineOperand(&FaultingMI, MO);
Op.isValid())
886void X86AsmPrinter::LowerFENTRY_CALL(
const MachineInstr &
MI,
887 X86MCInstLower &MCIL) {
891 if (MF->getFunction().hasFnAttribute(
"mrecord-mcount")) {
892 MCSymbol *DotSym = OutContext.createTempSymbol();
901 if (MF->getFunction().hasFnAttribute(
"mnop-mcount")) {
911 EmitAndCountInstruction(
912 MCInstBuilder(Is64Bits ? X86::CALL64pcrel32 : X86::CALLpcrel32)
916void X86AsmPrinter::LowerKCFI_CHECK(
const MachineInstr &
MI) {
917 assert(std::next(
MI.getIterator())->isCall() &&
918 "KCFI_CHECK not followed by a call instruction");
926 "patchable-function-prefix");
933 const Register AddrReg =
MI.getOperand(0).getReg();
934 const uint32_t
Type =
MI.getOperand(1).getImm();
937 unsigned TempReg = AddrReg == X86::R10 ? X86::R11D : X86::R10D;
938 EmitAndCountInstruction(
939 MCInstBuilder(X86::MOV32ri).addReg(TempReg).addImm(-MaskKCFIType(
Type)));
940 EmitAndCountInstruction(MCInstBuilder(X86::ADD32rm)
941 .addReg(X86::NoRegister)
945 .addReg(X86::NoRegister)
946 .addImm(-(PrefixNops + 4))
947 .addReg(X86::NoRegister));
950 EmitAndCountInstruction(
951 MCInstBuilder(X86::JCC_1)
957 EmitAndCountInstruction(MCInstBuilder(X86::TRAP));
958 emitKCFITrapEntry(MF,
Trap);
962void X86AsmPrinter::LowerASAN_CHECK_MEMACCESS(
const MachineInstr &
MI) {
964 if (!TM.getTargetTriple().isOSBinFormatELF()) {
969 const auto &
Reg =
MI.getOperand(0).getReg();
970 ASanAccessInfo AccessInfo(
MI.getOperand(1).getImm());
976 TM.getTargetTriple(), 64, AccessInfo.CompileKernel,
977 &ShadowBase, &MappingScale, &OrShadowOffset);
979 StringRef
Name = AccessInfo.IsWrite ?
"store" :
"load";
980 StringRef
Op = OrShadowOffset ?
"or" :
"add";
981 std::string SymName = (
"__asan_check_" +
Name +
"_" +
Op +
"_" +
982 Twine(1ULL << AccessInfo.AccessSizeIndex) +
"_" +
983 TM.getMCRegisterInfo().getName(
Reg.
asMCReg()))
987 "OrShadowOffset is not supported with optimized callbacks");
989 EmitAndCountInstruction(
990 MCInstBuilder(X86::CALL64pcrel32)
992 OutContext.getOrCreateSymbol(SymName), OutContext)));
995void X86AsmPrinter::LowerPATCHABLE_OP(
const MachineInstr &
MI,
996 X86MCInstLower &MCIL) {
999 NoAutoPaddingScope NoPadScope(*OutStreamer);
1002 MI.getParent()->instr_end());
1004 SmallString<256>
Code;
1005 unsigned MinSize =
MI.getOperand(0).getImm();
1007 if (NextMI !=
MI.getParent()->end() && !NextMI->isInlineAsm()) {
1012 MCIL.Lower(&*NextMI, MCI);
1018 if (
Code.size() < MinSize) {
1019 if (MinSize == 2 &&
Subtarget->is32Bit() &&
1027 MCInstBuilder(X86::MOV32rr_REV).addReg(X86::EDI).addReg(X86::EDI),
1031 assert(NopSize == MinSize &&
"Could not implement MinSize!");
1039void X86AsmPrinter::LowerSTACKMAP(
const MachineInstr &
MI) {
1040 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
1046 SM.recordStackMap(*MILabel,
MI);
1047 unsigned NumShadowBytes =
MI.getOperand(1).getImm();
1048 SMShadowTracker.reset(NumShadowBytes);
1053void X86AsmPrinter::LowerPATCHPOINT(
const MachineInstr &
MI,
1054 X86MCInstLower &MCIL) {
1055 assert(
Subtarget->is64Bit() &&
"Patchpoint currently only supports X86-64");
1057 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
1059 NoAutoPaddingScope NoPadScope(*OutStreamer);
1064 SM.recordPatchPoint(*MILabel,
MI);
1066 PatchPointOpers opers(&
MI);
1067 unsigned ScratchIdx = opers.getNextScratchIdx();
1068 unsigned EncodedBytes = 0;
1069 const MachineOperand &CalleeMO = opers.getCallTarget();
1074 MCOperand CalleeMCOp;
1085 CalleeMCOp = MCIL.LowerSymbolOperand(CalleeMO,
1086 MCIL.GetSymbolFromOperand(CalleeMO));
1092 Register ScratchReg =
MI.getOperand(ScratchIdx).getReg();
1098 EmitAndCountInstruction(
1099 MCInstBuilder(X86::MOV64ri).addReg(ScratchReg).
addOperand(CalleeMCOp));
1103 "Lowering patchpoint with thunks not yet implemented.");
1104 EmitAndCountInstruction(MCInstBuilder(X86::CALL64r).addReg(ScratchReg));
1108 unsigned NumBytes = opers.getNumPatchBytes();
1109 assert(NumBytes >= EncodedBytes &&
1110 "Patchpoint can't request size less than the length of a call.");
1115void X86AsmPrinter::LowerPATCHABLE_EVENT_CALL(
const MachineInstr &
MI,
1116 X86MCInstLower &MCIL) {
1117 assert(
Subtarget->is64Bit() &&
"XRay custom events only supports X86-64");
1119 NoAutoPaddingScope NoPadScope(*OutStreamer);
1141 auto CurSled = OutContext.createTempSymbol(
"xray_event_sled_",
true);
1142 OutStreamer->
AddComment(
"# XRay Custom Event Log");
1153 const Register DestRegs[] = {X86::RDI, X86::RSI};
1154 bool UsedMask[] = {
false,
false};
1163 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I)
1164 if (
auto Op = MCIL.LowerMachineOperand(&
MI,
MI.getOperand(
I));
1166 assert(
Op.isReg() &&
"Only support arguments in registers");
1169 if (SrcRegs[
I] != DestRegs[
I]) {
1171 EmitAndCountInstruction(
1172 MCInstBuilder(X86::PUSH64r).addReg(DestRegs[
I]));
1182 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I)
1183 if (SrcRegs[
I] != DestRegs[
I])
1184 EmitAndCountInstruction(
1185 MCInstBuilder(X86::MOV64rr).addReg(DestRegs[
I]).addReg(SrcRegs[
I]));
1189 auto TSym = OutContext.getOrCreateSymbol(
"__xray_CustomEvent");
1191 if (isPositionIndependent())
1195 EmitAndCountInstruction(MCInstBuilder(X86::CALL64pcrel32)
1196 .
addOperand(MCIL.LowerSymbolOperand(TOp, TSym)));
1199 for (
unsigned I =
sizeof UsedMask;
I-- > 0;)
1201 EmitAndCountInstruction(MCInstBuilder(X86::POP64r).addReg(DestRegs[
I]));
1205 OutStreamer->
AddComment(
"xray custom event end.");
1210 recordSled(CurSled,
MI, SledKind::CUSTOM_EVENT, 2);
1213void X86AsmPrinter::LowerPATCHABLE_TYPED_EVENT_CALL(
const MachineInstr &
MI,
1214 X86MCInstLower &MCIL) {
1215 assert(
Subtarget->is64Bit() &&
"XRay typed events only supports X86-64");
1217 NoAutoPaddingScope NoPadScope(*OutStreamer);
1239 auto CurSled = OutContext.createTempSymbol(
"xray_typed_event_sled_",
true);
1240 OutStreamer->
AddComment(
"# XRay Typed Event Log");
1252 const Register DestRegs[] = {X86::RDI, X86::RSI, X86::RDX};
1253 bool UsedMask[] = {
false,
false,
false};
1262 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I)
1263 if (
auto Op = MCIL.LowerMachineOperand(&
MI,
MI.getOperand(
I));
1266 assert(
Op.isReg() &&
"Only supports arguments in registers");
1269 if (SrcRegs[
I] != DestRegs[
I]) {
1271 EmitAndCountInstruction(
1272 MCInstBuilder(X86::PUSH64r).addReg(DestRegs[
I]));
1287 for (
unsigned I = 0;
I <
MI.getNumOperands(); ++
I)
1289 EmitAndCountInstruction(
1290 MCInstBuilder(X86::MOV64rr).addReg(DestRegs[
I]).addReg(SrcRegs[
I]));
1294 auto TSym = OutContext.getOrCreateSymbol(
"__xray_TypedEvent");
1296 if (isPositionIndependent())
1300 EmitAndCountInstruction(MCInstBuilder(X86::CALL64pcrel32)
1301 .
addOperand(MCIL.LowerSymbolOperand(TOp, TSym)));
1304 for (
unsigned I =
sizeof UsedMask;
I-- > 0;)
1306 EmitAndCountInstruction(MCInstBuilder(X86::POP64r).addReg(DestRegs[
I]));
1310 OutStreamer->
AddComment(
"xray typed event end.");
1313 recordSled(CurSled,
MI, SledKind::TYPED_EVENT, 2);
1316void X86AsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
const MachineInstr &
MI,
1317 X86MCInstLower &MCIL) {
1319 NoAutoPaddingScope NoPadScope(*OutStreamer);
1322 if (
F.hasFnAttribute(
"patchable-function-entry")) {
1323 unsigned Num =
F.getFnAttributeAsParsedInteger(
"patchable-function-entry");
1340 auto CurSled = OutContext.createTempSymbol(
"xray_sled_",
true);
1349 recordSled(CurSled,
MI, SledKind::FUNCTION_ENTER, 2);
1352void X86AsmPrinter::LowerPATCHABLE_RET(
const MachineInstr &
MI,
1353 X86MCInstLower &MCIL) {
1354 NoAutoPaddingScope NoPadScope(*OutStreamer);
1370 auto CurSled = OutContext.createTempSymbol(
"xray_sled_",
true);
1373 unsigned OpCode =
MI.getOperand(0).getImm();
1377 if (
auto Op = MCIL.LowerMachineOperand(&
MI, MO);
Op.isValid())
1381 recordSled(CurSled,
MI, SledKind::FUNCTION_EXIT, 2);
1384void X86AsmPrinter::LowerPATCHABLE_TAIL_CALL(
const MachineInstr &
MI,
1385 X86MCInstLower &MCIL) {
1390 bool IsConditional = TC.
getOpcode() == X86::JCC_1;
1392 if (IsConditional) {
1403 FallthroughLabel = OutContext.createTempSymbol();
1406 MCInstBuilder(X86::JCC_1)
1415 NoAutoPaddingScope NoPadScope(*OutStreamer);
1423 auto CurSled = OutContext.createTempSymbol(
"xray_sled_",
true);
1426 auto Target = OutContext.createTempSymbol();
1434 recordSled(CurSled,
MI, SledKind::TAIL_CALL, 2);
1439 for (
auto &MO : TCOperands)
1440 if (
auto Op = MCIL.LowerMachineOperand(&
MI, MO);
Op.isValid())
1445 OutStreamer->
emitLabel(FallthroughLabel);
1461 unsigned SrcOpIdx) {
1471 CS <<
" {%" << Mask <<
"}";
1482 if (Src1Name == Src2Name)
1483 for (
int i = 0, e = ShuffleMask.size(); i != e; ++i)
1484 if (ShuffleMask[i] >= e)
1485 ShuffleMask[i] -= e;
1487 for (
int i = 0, e = ShuffleMask.size(); i != e; ++i) {
1497 bool isSrc1 = ShuffleMask[i] < (int)e;
1498 CS << (isSrc1 ? Src1Name : Src2Name) <<
'[';
1500 bool IsFirst =
true;
1502 (ShuffleMask[i] < (
int)e) == isSrc1) {
1510 CS << ShuffleMask[i] % (int)e;
1520 std::string Comment;
1540 bool PrintZero =
false) {
1549 CS << (PrintZero ? 0ULL : Val.
getRawData()[i]);
1556 bool PrintZero =
false) {
1572 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
1581 unsigned EltBits = VTy->getScalarSizeInBits();
1582 unsigned E = std::min(
BitWidth / EltBits, VTy->getNumElements());
1584 for (
unsigned I = 0;
I !=
E; ++
I) {
1595 Type *EltTy = CDS->getElementType();
1599 unsigned E = std::min(
BitWidth / EltBits, (
unsigned)CDS->getNumElements());
1601 for (
unsigned I = 0;
I !=
E; ++
I) {
1615 unsigned EltBits = CV->getType()->getScalarSizeInBits();
1616 unsigned E = std::min(
BitWidth / EltBits, CV->getNumOperands());
1618 for (
unsigned I = 0;
I !=
E; ++
I) {
1632 int SclWidth,
int VecWidth,
1633 const char *ShuffleComment) {
1636 std::string Comment;
1644 for (
int I = 1,
E = VecWidth / SclWidth;
I <
E; ++
I) {
1654 CS << ShuffleComment;
1662 std::string Comment;
1666 for (
int l = 0; l != Repeats; ++l) {
1677 unsigned OpNo,
int BitWidth,
int Repeats = 1) {
1679 std::string Comment;
1682 for (
int I = 0;
I != Repeats; ++
I) {
1693 int SrcEltBits,
int DstEltBits,
bool IsSext) {
1696 if (
C &&
C->getType()->getScalarSizeInBits() ==
unsigned(SrcEltBits)) {
1698 int NumElts = CDS->getNumElements();
1699 std::string Comment;
1703 for (
int i = 0; i != NumElts; ++i) {
1706 if (CDS->getElementType()->isIntegerTy()) {
1707 APInt Elt = CDS->getElementAsAPInt(i);
1708 Elt = IsSext ? Elt.
sext(DstEltBits) : Elt.
zext(DstEltBits);
1722 int SrcEltBits,
int DstEltBits) {
1726 int SrcEltBits,
int DstEltBits) {
1727 if (
printExtend(
MI, OutStreamer, SrcEltBits, DstEltBits,
false))
1731 std::string Comment;
1738 assert((Width % DstEltBits) == 0 && (DstEltBits % SrcEltBits) == 0 &&
1739 "Illegal extension ratio");
1746void X86AsmPrinter::EmitSEHInstruction(
const MachineInstr *
MI) {
1747 assert(MF->
hasWinCFI() &&
"SEH_ instruction in function without WinCFI?");
1748 assert(getSubtarget().isOSWindowsOrUEFI() &&
1749 "SEH_ instruction Windows and UEFI only");
1753 X86TargetStreamer *XTS =
1755 switch (
MI->getOpcode()) {
1756 case X86::SEH_PushReg:
1759 case X86::SEH_StackAlloc:
1762 case X86::SEH_StackAlign:
1765 case X86::SEH_SetFrame:
1766 assert(
MI->getOperand(1).getImm() == 0 &&
1767 ".cv_fpo_setframe takes no offset");
1770 case X86::SEH_EndPrologue:
1773 case X86::SEH_SaveReg:
1774 case X86::SEH_SaveXMM:
1775 case X86::SEH_PushFrame:
1776 case X86::SEH_Push2Regs:
1786 switch (
MI->getOpcode()) {
1787 case X86::SEH_PushReg:
1791 case X86::SEH_Push2Regs:
1793 MI->getOperand(1).getImm());
1796 case X86::SEH_SaveReg:
1798 MI->getOperand(1).getImm());
1801 case X86::SEH_SaveXMM:
1803 MI->getOperand(1).getImm());
1806 case X86::SEH_StackAlloc:
1810 case X86::SEH_SetFrame:
1812 MI->getOperand(1).getImm());
1815 case X86::SEH_PushFrame:
1819 case X86::SEH_EndPrologue:
1823 case X86::SEH_BeginEpilogue:
1827 case X86::SEH_EndEpilogue:
1831 case X86::SEH_UnwindV2Start:
1835 case X86::SEH_UnwindVersion:
1846 switch (
MI->getOpcode()) {
1851 case X86::VPSHUFBrm:
1852 case X86::VPSHUFBYrm:
1853 case X86::VPSHUFBZ128rm:
1854 case X86::VPSHUFBZ128rmk:
1855 case X86::VPSHUFBZ128rmkz:
1856 case X86::VPSHUFBZ256rm:
1857 case X86::VPSHUFBZ256rmk:
1858 case X86::VPSHUFBZ256rmkz:
1859 case X86::VPSHUFBZrm:
1860 case X86::VPSHUFBZrmk:
1861 case X86::VPSHUFBZrmkz: {
1873 case X86::VPERMILPSrm:
1874 case X86::VPERMILPSYrm:
1875 case X86::VPERMILPSZ128rm:
1876 case X86::VPERMILPSZ128rmk:
1877 case X86::VPERMILPSZ128rmkz:
1878 case X86::VPERMILPSZ256rm:
1879 case X86::VPERMILPSZ256rmk:
1880 case X86::VPERMILPSZ256rmkz:
1881 case X86::VPERMILPSZrm:
1882 case X86::VPERMILPSZrmk:
1883 case X86::VPERMILPSZrmkz: {
1894 case X86::VPERMILPDrm:
1895 case X86::VPERMILPDYrm:
1896 case X86::VPERMILPDZ128rm:
1897 case X86::VPERMILPDZ128rmk:
1898 case X86::VPERMILPDZ128rmkz:
1899 case X86::VPERMILPDZ256rm:
1900 case X86::VPERMILPDZ256rmk:
1901 case X86::VPERMILPDZ256rmkz:
1902 case X86::VPERMILPDZrm:
1903 case X86::VPERMILPDZrmk:
1904 case X86::VPERMILPDZrmkz: {
1916 case X86::VPERMIL2PDrm:
1917 case X86::VPERMIL2PSrm:
1918 case X86::VPERMIL2PDYrm:
1919 case X86::VPERMIL2PSYrm: {
1921 "Unexpected number of operands!");
1924 if (!CtrlOp.
isImm())
1928 switch (
MI->getOpcode()) {
1930 case X86::VPERMIL2PSrm:
case X86::VPERMIL2PSYrm: ElSize = 32;
break;
1931 case X86::VPERMIL2PDrm:
case X86::VPERMIL2PDYrm: ElSize = 64;
break;
1944 case X86::VPPERMrrm: {
1955 case X86::MMX_MOVQ64rm: {
1957 std::string Comment;
1962 CS <<
"0x" <<
toString(CF->getValueAPF().bitcastToAPInt(), 16,
false);
1969 case X86::GF2P8AFFINEQBrmi:
1970 case X86::VGF2P8AFFINEQBrmi:
1971 case X86::VGF2P8AFFINEQBYrmi:
1972 case X86::VGF2P8AFFINEQBZrmi:
1973 case X86::VGF2P8AFFINEQBZ128rmi:
1974 case X86::VGF2P8AFFINEQBZ256rmi: {
1982 case X86::VGF2P8AFFINEQBZ128rmbi:
1983 case X86::VGF2P8AFFINEQBZ256rmbi:
1984 case X86::VGF2P8AFFINEQBZrmbi: {
1991#define INSTR_CASE(Prefix, Instr, Suffix, Postfix) \
1992 case X86::Prefix##Instr##Suffix##rm##Postfix:
1994#define CASE_AVX512_ARITH_RM(Instr) \
1995 INSTR_CASE(V, Instr, Z128, ) \
1996 INSTR_CASE(V, Instr, Z128, k) \
1997 INSTR_CASE(V, Instr, Z128, kz) \
1998 INSTR_CASE(V, Instr, Z256, ) \
1999 INSTR_CASE(V, Instr, Z256, k) \
2000 INSTR_CASE(V, Instr, Z256, kz) \
2001 INSTR_CASE(V, Instr, Z, ) \
2002 INSTR_CASE(V, Instr, Z, k) \
2003 INSTR_CASE(V, Instr, Z, kz)
2005#define CASE_ARITH_RM(Instr) \
2006 INSTR_CASE(, Instr, , ) \
2007 INSTR_CASE(V, Instr, , ) \
2008 INSTR_CASE(V, Instr, Y, ) \
2009 INSTR_CASE(V, Instr, Z128, ) \
2010 INSTR_CASE(V, Instr, Z128, k) \
2011 INSTR_CASE(V, Instr, Z128, kz) \
2012 INSTR_CASE(V, Instr, Z256, ) \
2013 INSTR_CASE(V, Instr, Z256, k) \
2014 INSTR_CASE(V, Instr, Z256, kz) \
2015 INSTR_CASE(V, Instr, Z, ) \
2016 INSTR_CASE(V, Instr, Z, k) \
2017 INSTR_CASE(V, Instr, Z, kz)
2039 unsigned VectorWidth =
2045#define MASK_AVX512_CASE(Instr) \
2053 case X86::MOVSDrm_alt:
2054 case X86::VMOVSDrm_alt:
2055 case X86::VMOVSDZrm_alt:
2056 case X86::MOVQI2PQIrm:
2057 case X86::VMOVQI2PQIrm:
2058 case X86::VMOVQI2PQIZrm:
2063 case X86::VMOVSHZrm_alt:
2065 "mem[0],zero,zero,zero,zero,zero,zero,zero");
2071 case X86::MOVSSrm_alt:
2072 case X86::VMOVSSrm_alt:
2073 case X86::VMOVSSZrm_alt:
2074 case X86::MOVDI2PDIrm:
2075 case X86::VMOVDI2PDIrm:
2076 case X86::VMOVDI2PDIZrm:
2080#define MOV_CASE(Prefix, Suffix) \
2081 case X86::Prefix##MOVAPD##Suffix##rm: \
2082 case X86::Prefix##MOVAPS##Suffix##rm: \
2083 case X86::Prefix##MOVUPD##Suffix##rm: \
2084 case X86::Prefix##MOVUPS##Suffix##rm: \
2085 case X86::Prefix##MOVDQA##Suffix##rm: \
2086 case X86::Prefix##MOVDQU##Suffix##rm:
2088#define MOV_AVX512_CASE(Suffix, Postfix) \
2089 case X86::VMOVDQA64##Suffix##rm##Postfix: \
2090 case X86::VMOVDQA32##Suffix##rm##Postfix: \
2091 case X86::VMOVDQU64##Suffix##rm##Postfix: \
2092 case X86::VMOVDQU32##Suffix##rm##Postfix: \
2093 case X86::VMOVDQU16##Suffix##rm##Postfix: \
2094 case X86::VMOVDQU8##Suffix##rm##Postfix: \
2095 case X86::VMOVAPS##Suffix##rm##Postfix: \
2096 case X86::VMOVAPD##Suffix##rm##Postfix: \
2097 case X86::VMOVUPS##Suffix##rm##Postfix: \
2098 case X86::VMOVUPD##Suffix##rm##Postfix:
2100#define CASE_128_MOV_RM() \
2103 MOV_AVX512_CASE(Z128, ) \
2104 MOV_AVX512_CASE(Z128, k) \
2105 MOV_AVX512_CASE(Z128, kz)
2107#define CASE_256_MOV_RM() \
2109 MOV_AVX512_CASE(Z256, ) \
2110 MOV_AVX512_CASE(Z256, k) \
2111 MOV_AVX512_CASE(Z256, kz) \
2113#define CASE_512_MOV_RM() \
2114 MOV_AVX512_CASE(Z, ) \
2115 MOV_AVX512_CASE(Z, k) \
2116 MOV_AVX512_CASE(Z, kz) \
2129 case X86::VBROADCASTF128rm:
2130 case X86::VBROADCASTI128rm:
2152 case X86::MOVDDUPrm:
2153 case X86::VMOVDDUPrm:
2155 case X86::VPBROADCASTQrm:
2159 case X86::VBROADCASTSDYrm:
2161 case X86::VPBROADCASTQYrm:
2169 case X86::VBROADCASTSSrm:
2171 case X86::VPBROADCASTDrm:
2175 case X86::VBROADCASTSSYrm:
2177 case X86::VPBROADCASTDYrm:
2185 case X86::VPBROADCASTWrm:
2189 case X86::VPBROADCASTWYrm:
2196 case X86::VPBROADCASTBrm:
2200 case X86::VPBROADCASTBYrm:
2208#define MOVX_CASE(Prefix, Ext, Type, Suffix, Postfix) \
2209 case X86::Prefix##PMOV##Ext##Type##Suffix##rm##Postfix:
2211#define CASE_MOVX_RM(Ext, Type) \
2212 MOVX_CASE(, Ext, Type, , ) \
2213 MOVX_CASE(V, Ext, Type, , ) \
2214 MOVX_CASE(V, Ext, Type, Y, ) \
2215 MOVX_CASE(V, Ext, Type, Z128, ) \
2216 MOVX_CASE(V, Ext, Type, Z128, k ) \
2217 MOVX_CASE(V, Ext, Type, Z128, kz ) \
2218 MOVX_CASE(V, Ext, Type, Z256, ) \
2219 MOVX_CASE(V, Ext, Type, Z256, k ) \
2220 MOVX_CASE(V, Ext, Type, Z256, kz ) \
2221 MOVX_CASE(V, Ext, Type, Z, ) \
2222 MOVX_CASE(V, Ext, Type, Z, k ) \
2223 MOVX_CASE(V, Ext, Type, Z, kz )
2272 assert(
MI->getOpcode() == X86::TAILJMPm64_REX ||
2273 MI->getOpcode() == X86::CALL64m);
2283 for (
auto I =
MBB.instr_rbegin(),
E =
MBB.instr_rend();
I !=
E; ++
I)
2284 if (
I->isJumpTableDebugInfo())
2295 X86MCInstLower MCInstLowering(*
MF, *
this);
2299 if (
MI->getOpcode() == X86::OR64rm) {
2300 for (
auto &Opd :
MI->operands()) {
2301 if (Opd.isSymbol() &&
StringRef(Opd.getSymbolName()) ==
2302 "swift_async_extendedFramePointerFlags") {
2303 ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags =
true;
2313 if (
TM.Options.MCOptions.ShowMCEncoding) {
2315 OutStreamer->AddComment(
"EVEX TO LEGACY Compression ",
false);
2317 OutStreamer->AddComment(
"EVEX TO VEX Compression ",
false);
2319 OutStreamer->AddComment(
"EVEX TO EVEX Compression ",
false);
2323 bool IsTailJump =
false;
2325 switch (
MI->getOpcode()) {
2326 case TargetOpcode::DBG_VALUE:
2329 case X86::EH_RETURN:
2330 case X86::EH_RETURN64: {
2337 case X86::CLEANUPRET: {
2343 case X86::CATCHRET: {
2350 case X86::ENDBR64: {
2357 MI == &
MF->front().front()) {
2359 MCInstLowering.Lower(
MI, Inst);
2360 EmitAndCountInstruction(Inst);
2368 case X86::TAILJMPd64:
2369 if (IndCSPrefix &&
MI->hasRegisterImplicitUseOperand(X86::R11))
2373 emitLabelAndRecordForImportCallOptimization(
2374 IMAGE_RETPOLINE_AMD64_IMPORT_BR);
2385 case X86::TAILJMPd_CC:
2386 case X86::TAILJMPr64:
2387 case X86::TAILJMPm64:
2388 case X86::TAILJMPd64_CC:
2389 if (EnableImportCallOptimization)
2391 "import call optimization was enabled");
2398 case X86::TAILJMPm64_REX:
2400 emitLabelAndRecordForImportCallOptimization(
2401 IMAGE_RETPOLINE_AMD64_CFG_BR_REX);
2408 case X86::TAILJMPr64_REX: {
2409 if (EnableImportCallOptimization) {
2410 assert(
MI->getOperand(0).getReg() == X86::RAX &&
2411 "Indirect tail calls with impcall enabled must go through RAX (as "
2412 "enforced by TCRETURNImpCallri64)");
2413 emitLabelAndRecordForImportCallOptimization(
2414 IMAGE_RETPOLINE_AMD64_INDIR_BR);
2424 uint16_t EncodedReg =
2425 this->
getSubtarget().getRegisterInfo()->getEncodingValue(
2426 MI->getOperand(0).getReg().asMCReg());
2427 emitLabelAndRecordForImportCallOptimization(
2428 (ImportCallKind)(IMAGE_RETPOLINE_AMD64_SWITCHTABLE_FIRST +
2440 "Unexpected JMP instruction was emitted for a jump-table when import "
2441 "call optimization was enabled");
2444 case X86::TLS_addr32:
2445 case X86::TLS_addr64:
2446 case X86::TLS_addrX32:
2447 case X86::TLS_base_addr32:
2448 case X86::TLS_base_addr64:
2449 case X86::TLS_base_addrX32:
2450 case X86::TLS_desc32:
2451 case X86::TLS_desc64:
2452 return LowerTlsAddr(MCInstLowering, *
MI);
2454 case X86::MOVPC32r: {
2465 EmitAndCountInstruction(
2471 bool hasFP = FrameLowering->
hasFP(*
MF);
2474 bool HasActiveDwarfFrame =
OutStreamer->getNumFrameInfos() &&
2479 if (HasActiveDwarfFrame && !hasFP) {
2480 OutStreamer->emitCFIAdjustCfaOffset(-stackGrowth);
2488 EmitAndCountInstruction(
2491 if (HasActiveDwarfFrame && !hasFP) {
2497 case X86::ADD32ri: {
2513 MCSymbol *OpSym = MCInstLowering.GetSymbolFromOperand(
MI->getOperand(2));
2524 .addReg(
MI->getOperand(0).getReg())
2525 .
addReg(
MI->getOperand(1).getReg())
2529 case TargetOpcode::STATEPOINT:
2530 return LowerSTATEPOINT(*
MI, MCInstLowering);
2532 case TargetOpcode::FAULTING_OP:
2533 return LowerFAULTING_OP(*
MI, MCInstLowering);
2535 case TargetOpcode::FENTRY_CALL:
2536 return LowerFENTRY_CALL(*
MI, MCInstLowering);
2538 case TargetOpcode::PATCHABLE_OP:
2539 return LowerPATCHABLE_OP(*
MI, MCInstLowering);
2541 case TargetOpcode::STACKMAP:
2542 return LowerSTACKMAP(*
MI);
2544 case TargetOpcode::PATCHPOINT:
2545 return LowerPATCHPOINT(*
MI, MCInstLowering);
2547 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
2548 return LowerPATCHABLE_FUNCTION_ENTER(*
MI, MCInstLowering);
2550 case TargetOpcode::PATCHABLE_RET:
2551 return LowerPATCHABLE_RET(*
MI, MCInstLowering);
2553 case TargetOpcode::PATCHABLE_TAIL_CALL:
2554 return LowerPATCHABLE_TAIL_CALL(*
MI, MCInstLowering);
2556 case TargetOpcode::PATCHABLE_EVENT_CALL:
2557 return LowerPATCHABLE_EVENT_CALL(*
MI, MCInstLowering);
2559 case TargetOpcode::PATCHABLE_TYPED_EVENT_CALL:
2560 return LowerPATCHABLE_TYPED_EVENT_CALL(*
MI, MCInstLowering);
2562 case X86::MORESTACK_RET:
2566 case X86::KCFI_CHECK:
2567 return LowerKCFI_CHECK(*
MI);
2569 case X86::ASAN_CHECK_MEMACCESS:
2570 return LowerASAN_CHECK_MEMACCESS(*
MI);
2572 case X86::MORESTACK_RET_RESTORE_R10:
2575 EmitAndCountInstruction(
2576 MCInstBuilder(X86::MOV64rr).addReg(X86::R10).addReg(X86::RAX));
2579 case X86::SEH_PushReg:
2580 case X86::SEH_Push2Regs:
2581 case X86::SEH_SaveReg:
2582 case X86::SEH_SaveXMM:
2583 case X86::SEH_StackAlloc:
2584 case X86::SEH_StackAlign:
2585 case X86::SEH_SetFrame:
2586 case X86::SEH_PushFrame:
2587 case X86::SEH_EndPrologue:
2588 case X86::SEH_EndEpilogue:
2589 case X86::SEH_UnwindV2Start:
2590 case X86::SEH_UnwindVersion:
2591 EmitSEHInstruction(
MI);
2594 case X86::SEH_SplitChainedAtEndOfBlock:
2595 assert(!SplitChainedAtEndOfBlock &&
2596 "Duplicate SEH_SplitChainedAtEndOfBlock in a current block");
2597 SplitChainedAtEndOfBlock =
true;
2600 case X86::SEH_SplitChained:
2601 assert(
MF->hasWinCFI() &&
"SEH_ instruction in function without WinCFI?");
2605 case X86::SEH_BeginEpilogue: {
2606 assert(
MF->hasWinCFI() &&
"SEH_ instruction in function without WinCFI?");
2607 EmitSEHInstruction(
MI);
2610 case X86::UBSAN_UD1:
2615 .addReg(X86::NoRegister)
2616 .addImm(
MI->getOperand(0).getImm())
2617 .
addReg(X86::NoRegister));
2619 case X86::CALL64pcrel32:
2620 if (IndCSPrefix &&
MI->hasRegisterImplicitUseOperand(X86::R11))
2624 emitLabelAndRecordForImportCallOptimization(
2625 IMAGE_RETPOLINE_AMD64_IMPORT_CALL);
2628 MCInstLowering.Lower(
MI, TmpInst);
2633 emitCallInstruction(TmpInst);
2635 maybeEmitNopAfterCallForWindowsEH(
MI);
2642 if (EnableImportCallOptimization) {
2643 assert(
MI->getOperand(0).getReg() == X86::RAX &&
2644 "Indirect calls with impcall enabled must go through RAX (as "
2645 "enforced by CALL64r_ImpCall)");
2647 emitLabelAndRecordForImportCallOptimization(
2648 IMAGE_RETPOLINE_AMD64_INDIR_CALL);
2650 MCInstLowering.Lower(
MI, TmpInst);
2651 emitCallInstruction(TmpInst);
2656 maybeEmitNopAfterCallForWindowsEH(
MI);
2663 emitLabelAndRecordForImportCallOptimization(
2664 IMAGE_RETPOLINE_AMD64_CFG_CALL);
2679 getSubtarget().getCLOpts().branch_hint_probability_threshold, 100);
2680 if (EdgeProb > Threshold)
2688 EmitAndCountInstruction(
2691 .addImm(
MI->getOperand(0).getImm()));
2696 MCInstLowering.Lower(
MI, TmpInst);
2699 emitCallInstruction(TmpInst);
2703 maybeEmitNopAfterCallForWindowsEH(
MI);
2707 EmitAndCountInstruction(TmpInst);
2718 maybeEmitNopAfterCallForWindowsEH(
MI);
2722void X86AsmPrinter::emitCallInstruction(
const llvm::MCInst &MCI) {
2729 SMShadowTracker.count(MCI, getSubtargetInfo(), CodeEmitter.get());
2732 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
2796void X86AsmPrinter::maybeEmitNopAfterCallForWindowsEH(
const MachineInstr *
MI) {
2821 const MachineInstr &NextMI = *
MBBI;
2827 if (HasEHPersonality) {
2828 EmitAndCountInstruction(MCInstBuilder(X86::NOOP));
2847 if (NextMI.
getOpcode() == X86::SEH_BeginEpilogue) {
2848 EmitAndCountInstruction(MCInstBuilder(X86::NOOP));
2874 if (HasEHPersonality) {
2880 if (
MI->getParent()->succ_empty())
2881 EmitAndCountInstruction(MCInstBuilder(X86::INT3));
2883 EmitAndCountInstruction(MCInstBuilder(X86::NOOP));
2889 const MachineBasicBlock *NextMBB = &*MFI;
2895void X86AsmPrinter::emitLabelAndRecordForImportCallOptimization(
2896 ImportCallKind Kind) {
2897 assert(EnableImportCallOptimization);
2899 MCSymbol *CallSiteSymbol = MMI->getContext().createNamedTempSymbol(
"impcall");
2903 .push_back({CallSiteSymbol,
Kind});
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static void printShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef< int > Mask)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
print mir2vec MIR2Vec Vocabulary Printer Pass
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Promote Memory to Register
static MCSymbol * GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
This file defines the SmallString class.
static MCOperand LowerSymbolOperand(const MachineInstr *MI, const MachineOperand &MO, const MCSymbol *Symbol, AsmPrinter &AP)
static void emitX86Nops(MCStreamer &OS, unsigned NumBytes, const X86Subtarget *Subtarget)
Emit the optimal amount of multi-byte nops on X86.
static unsigned getRetOpcode(const X86Subtarget &Subtarget)
static void printSignExtend(const MachineInstr *MI, MCStreamer &OutStreamer, int SrcEltBits, int DstEltBits)
static unsigned getSrcIdx(const MachineInstr *MI, unsigned SrcIdx)
static void printBroadcast(const MachineInstr *MI, MCStreamer &OutStreamer, int Repeats, int BitWidth)
static bool printExtend(const MachineInstr *MI, MCStreamer &OutStreamer, int SrcEltBits, int DstEltBits, bool IsSext)
static void printZeroUpperMove(const MachineInstr *MI, MCStreamer &OutStreamer, int SclWidth, int VecWidth, const char *ShuffleComment)
static void addConstantComment(const MachineInstr *MI, MCStreamer &OutStreamer, unsigned OpNo, int BitWidth, int Repeats=1)
static unsigned convertTailJumpOpcode(unsigned Opcode, bool IsLarge=false)
#define MASK_AVX512_CASE(Instr)
#define CASE_ARITH_RM(Instr)
static void addConstantComments(const MachineInstr *MI, MCStreamer &OutStreamer)
#define CASE_256_MOV_RM()
#define CASE_AVX512_ARITH_RM(Instr)
bool hasJumpTableInfoInBlock(const llvm::MachineInstr *MI)
static unsigned emitNop(MCStreamer &OS, unsigned NumBytes, const X86Subtarget *Subtarget)
Emit the largest nop instruction smaller than or equal to NumBytes bytes.
static void printDstRegisterName(raw_ostream &CS, const MachineInstr *MI, unsigned SrcOpIdx)
#define CASE_MOVX_RM(Ext, Type)
bool isImportedFunction(const MachineOperand &MO)
static void printConstant(const APInt &Val, raw_ostream &CS, bool PrintZero=false)
static void printZeroExtend(const MachineInstr *MI, MCStreamer &OutStreamer, int SrcEltBits, int DstEltBits)
static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx, unsigned SrcOp2Idx, ArrayRef< int > Mask)
bool isCallToCFGuardFunction(const MachineInstr *MI)
#define CASE_512_MOV_RM()
#define CASE_128_MOV_RM()
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
const fltSemantics & getSemantics() const
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getNumWords() const
Get the number of words.
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
MCSymbol * getSymbol(const GlobalValue *GV) const
MCSymbol * CurrentFnBegin
TargetMachine & TM
Target machine description.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
MachineFunction * MF
The current machine function.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
MCContext & OutContext
This is the context for the output file that we are streaming.
MCSymbol * createTempSymbol(const Twine &Name) const
MCSymbol * CurrentPatchableFunctionEntrySym
The symbol for the entry in __patchable_function_entires.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
const MCAsmInfo & MAI
Target Asm Printer information.
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
std::function< MachineBranchProbabilityInfo *(MachineFunction &)> GetMBPI
This is an important base class in LLVM.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
uint64_t getFnAttributeAsParsedInteger(StringRef Kind, uint64_t Default=0) const
For a string attribute Kind, parse attribute as an integer.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
bool hasInternalLinkage() const
bool doesSetDirectiveSuppressReloc() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
MCCodeEmitter - Generic instruction encoding interface.
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
LLVM_ABI const MCTargetOptions & getTargetOptions() const
Base class for the full range of assembler expressions which are needed for parsing.
MCInstBuilder & addReg(MCRegister Reg)
Add a new register operand.
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
iterator insert(iterator I, const MCOperand &Op)
void setFlags(unsigned F)
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
Streaming machine code generation interface.
virtual void emitWinCFIUnwindVersion(uint8_t Version, SMLoc Loc=SMLoc())
virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc=SMLoc())
virtual void emitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
virtual bool popSection()
Restore the current and previous section from the section stack.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
void emitSymbolValue(const MCSymbol *Sym, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
virtual void emitWinCFIUnwindV2Start(SMLoc Loc=SMLoc())
virtual void emitWinCFIEndEpilogue(SMLoc Loc=SMLoc())
virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
MCContext & getContext() const
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
virtual void emitWinCFIBeginEpilogue(SMLoc Loc=SMLoc())
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
virtual void emitWinCFIEndProlog(SMLoc Loc=SMLoc())
void pushSection()
Save the current and previous section on the section stack.
virtual void emitWinCFIPush2Regs(MCRegister Reg1, MCRegister Reg2, SMLoc Loc=SMLoc())
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
MCSection * getCurrentSectionOnly() const
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
instr_iterator instr_begin()
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
instr_iterator instr_end()
LLVM_ABI BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
MCSymbol * getPICBaseSymbol() const
getPICBaseSymbol - Return a function-local symbol to represent the PIC base.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
const MachineOperand & getOperand(unsigned i) const
bool isMetaInstruction(QueryType Type=IgnoreBundle) const
Return true if this instruction doesn't produce any output in the form of executable instructions.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
void setTargetFlags(unsigned F)
MCSymbol * getMCSymbol() const
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
int64_t getOffset() const
Return the offset from the symbol in this operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
PointerTy getPointer() const
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
const Triple & getTargetTriple() const
CodeModel::Model getCodeModel() const
Returns the code model.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static const char * getRegisterName(MCRegister Reg)
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
const X86Subtarget & getSubtarget() const
X86AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo, const MachineInstr *MI) override
Let the target do anything it needs to do after emitting inlineasm.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
unsigned getSlotSize() const
virtual bool emitFPOPushReg(MCRegister Reg, SMLoc L={})
virtual bool emitFPOEndPrologue(SMLoc L={})
virtual bool emitFPOStackAlign(unsigned Align, SMLoc L={})
virtual bool emitFPOSetFrame(MCRegister Reg, SMLoc L={})
virtual bool emitFPOStackAlloc(unsigned StackAlloc, SMLoc L={})
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
bool isKMergeMasked(uint64_t TSFlags)
@ MO_TLSLD
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
@ MO_GOTPCREL_NORELAX
MO_GOTPCREL_NORELAX - Same as MO_GOTPCREL except that R_X86_64_GOTPCREL relocations are guaranteed to...
@ MO_GOTOFF
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
@ MO_DARWIN_NONLAZY_PIC_BASE
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
@ MO_GOT_ABSOLUTE_ADDRESS
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [.
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
@ MO_NTPOFF
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
@ MO_DARWIN_NONLAZY
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
@ MO_INDNTPOFF
MO_INDNTPOFF - On a symbol operand this indicates that the immediate is the absolute address of the G...
@ MO_GOTNTPOFF
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
@ MO_TPOFF
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
@ MO_TLVP_PIC_BASE
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
@ MO_GOT
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
@ MO_ABS8
MO_ABS8 - On a symbol operand this indicates that the symbol is known to be an absolute symbol in ran...
@ MO_PLT
MO_PLT - On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol n...
@ MO_TLSGD
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
@ MO_NO_FLAG
MO_NO_FLAG - No flag for the operand.
@ MO_TLVP
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
@ MO_GOTTPOFF
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
@ MO_SECREL
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
@ MO_DTPOFF
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
@ MO_PIC_BASE_OFFSET
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
@ MO_TLSLDM
MO_TLSLDM - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
@ MO_GOTPCREL
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
bool isKMasked(uint64_t TSFlags)
bool isX86_64ExtendedReg(MCRegister Reg)
bool optimizeToFixedRegisterOrShortImmediateForm(MCInst &MI)
bool optimizeMOV(MCInst &MI, bool In64BitMode)
Simplify things like MOV32rm to MOV32o32a.
CondCode GetOppositeBranchCondition(CondCode CC)
GetOppositeBranchCondition - Return the inverse of the specified cond, e.g.
bool optimizeMOVSX(MCInst &MI)
bool optimizeVPCMPWithImmediateOneOrSix(MCInst &MI)
bool optimizeShiftRotateWithImmediateOne(MCInst &MI)
bool optimizeInstFromVEX3ToVEX2(MCInst &MI, const MCInstrDesc &Desc)
const Constant * getConstantFromPool(const MachineInstr &MI, unsigned OpNo)
Find any constant pool entry associated with a specific instruction operand.
bool optimizeINCDEC(MCInst &MI, bool In64BitMode)
unsigned getVectorRegisterWidth(const MCOperandInfo &Info)
Get the width of the vector register operand.
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, unsigned NumDstElts, bool IsAnyExtend, SmallVectorImpl< int > &ShuffleMask)
Decode a zero extension instruction as a shuffle mask.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
LLVM_ABI bool isCFGuardFunction(const GlobalValue *GV)
IterT skipMetaInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-meta instruction or to End and return the resulting iterator.
void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
LLVM_ABI void getAddressSanitizerParams(const LLVMContext &Ctx, const Triple &TargetTriple, int LongSize, bool IsKasan, uint64_t *ShadowBase, int *MappingScale, bool *OrShadowOffset)
void DecodeVPPERMMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPPERM mask from a raw array of constants such as from BUILD_VECTOR.
DWARFExpression::Operation Op
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr unsigned BitWidth
@ WinEH
Windows Exception Handling.
void DecodePSHUFBMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a PSHUFB mask from a raw array of constants such as from BUILD_VECTOR.
void changeAndComment(bool b)
NoAutoPaddingScope(MCStreamer &OS)
const bool OldAllowAutoPadding