LLVM 19.0.0git
X86MCInstLower.cpp
Go to the documentation of this file.
1//===-- X86MCInstLower.cpp - Convert X86 MachineInstr to an MCInst --------===//
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// This file contains code to lower X86 MachineInstrs to their corresponding
10// MCInst records.
11//
12//===----------------------------------------------------------------------===//
13
20#include "X86AsmPrinter.h"
22#include "X86RegisterInfo.h"
24#include "X86Subtarget.h"
32#include "llvm/IR/DataLayout.h"
33#include "llvm/IR/GlobalValue.h"
34#include "llvm/IR/Mangler.h"
35#include "llvm/MC/MCAsmInfo.h"
37#include "llvm/MC/MCContext.h"
38#include "llvm/MC/MCExpr.h"
39#include "llvm/MC/MCFixup.h"
40#include "llvm/MC/MCInst.h"
42#include "llvm/MC/MCSection.h"
44#include "llvm/MC/MCStreamer.h"
45#include "llvm/MC/MCSymbol.h"
46#include "llvm/MC/MCSymbolELF.h"
52#include <string>
53
54using namespace llvm;
55
56namespace {
57
58/// X86MCInstLower - This class is used to lower an MachineInstr into an MCInst.
59class X86MCInstLower {
60 MCContext &Ctx;
61 const MachineFunction &MF;
62 const TargetMachine &TM;
63 const MCAsmInfo &MAI;
65
66public:
67 X86MCInstLower(const MachineFunction &MF, X86AsmPrinter &asmprinter);
68
69 std::optional<MCOperand> LowerMachineOperand(const MachineInstr *MI,
70 const MachineOperand &MO) const;
71 void Lower(const MachineInstr *MI, MCInst &OutMI) const;
72
75
76private:
77 MachineModuleInfoMachO &getMachOMMI() const;
78};
79
80} // end anonymous namespace
81
82/// A RAII helper which defines a region of instructions which can't have
83/// padding added between them for correctness.
88 : OS(OS), OldAllowAutoPadding(OS.getAllowAutoPadding()) {
89 changeAndComment(false);
90 }
92 void changeAndComment(bool b) {
93 if (b == OS.getAllowAutoPadding())
94 return;
96 if (b)
97 OS.emitRawComment("autopadding");
98 else
99 OS.emitRawComment("noautopadding");
100 }
101};
102
103// Emit a minimal sequence of nops spanning NumBytes bytes.
104static void emitX86Nops(MCStreamer &OS, unsigned NumBytes,
105 const X86Subtarget *Subtarget);
106
107void X86AsmPrinter::StackMapShadowTracker::count(MCInst &Inst,
108 const MCSubtargetInfo &STI,
109 MCCodeEmitter *CodeEmitter) {
110 if (InShadow) {
113 CodeEmitter->encodeInstruction(Inst, Code, Fixups, STI);
114 CurrentShadowSize += Code.size();
115 if (CurrentShadowSize >= RequiredShadowSize)
116 InShadow = false; // The shadow is big enough. Stop counting.
117 }
118}
119
120void X86AsmPrinter::StackMapShadowTracker::emitShadowPadding(
121 MCStreamer &OutStreamer, const MCSubtargetInfo &STI) {
122 if (InShadow && CurrentShadowSize < RequiredShadowSize) {
123 InShadow = false;
124 emitX86Nops(OutStreamer, RequiredShadowSize - CurrentShadowSize,
125 &MF->getSubtarget<X86Subtarget>());
126 }
127}
128
129void X86AsmPrinter::EmitAndCountInstruction(MCInst &Inst) {
130 OutStreamer->emitInstruction(Inst, getSubtargetInfo());
131 SMShadowTracker.count(Inst, getSubtargetInfo(), CodeEmitter.get());
132}
133
134X86MCInstLower::X86MCInstLower(const MachineFunction &mf,
135 X86AsmPrinter &asmprinter)
136 : Ctx(mf.getContext()), MF(mf), TM(mf.getTarget()), MAI(*TM.getMCAsmInfo()),
137 AsmPrinter(asmprinter) {}
138
139MachineModuleInfoMachO &X86MCInstLower::getMachOMMI() const {
140 return MF.getMMI().getObjFileInfo<MachineModuleInfoMachO>();
141}
142
143/// GetSymbolFromOperand - Lower an MO_GlobalAddress or MO_ExternalSymbol
144/// operand to an MCSymbol.
145MCSymbol *X86MCInstLower::GetSymbolFromOperand(const MachineOperand &MO) const {
146 const Triple &TT = TM.getTargetTriple();
147 if (MO.isGlobal() && TT.isOSBinFormatELF())
149
150 const DataLayout &DL = MF.getDataLayout();
151 assert((MO.isGlobal() || MO.isSymbol() || MO.isMBB()) &&
152 "Isn't a symbol reference");
153
154 MCSymbol *Sym = nullptr;
156 StringRef Suffix;
157
158 switch (MO.getTargetFlags()) {
160 // Handle dllimport linkage.
161 Name += "__imp_";
162 break;
164 Name += ".refptr.";
165 break;
168 Suffix = "$non_lazy_ptr";
169 break;
170 }
171
172 if (!Suffix.empty())
173 Name += DL.getPrivateGlobalPrefix();
174
175 if (MO.isGlobal()) {
176 const GlobalValue *GV = MO.getGlobal();
178 } else if (MO.isSymbol()) {
180 } else if (MO.isMBB()) {
181 assert(Suffix.empty());
182 Sym = MO.getMBB()->getSymbol();
183 }
184
185 Name += Suffix;
186 if (!Sym)
187 Sym = Ctx.getOrCreateSymbol(Name);
188
189 // If the target flags on the operand changes the name of the symbol, do that
190 // before we return the symbol.
191 switch (MO.getTargetFlags()) {
192 default:
193 break;
194 case X86II::MO_COFFSTUB: {
195 MachineModuleInfoCOFF &MMICOFF =
196 MF.getMMI().getObjFileInfo<MachineModuleInfoCOFF>();
198 if (!StubSym.getPointer()) {
199 assert(MO.isGlobal() && "Extern symbol not handled yet");
201 AsmPrinter.getSymbol(MO.getGlobal()), true);
202 }
203 break;
204 }
208 getMachOMMI().getGVStubEntry(Sym);
209 if (!StubSym.getPointer()) {
210 assert(MO.isGlobal() && "Extern symbol not handled yet");
214 }
215 break;
216 }
217 }
218
219 return Sym;
220}
221
222MCOperand X86MCInstLower::LowerSymbolOperand(const MachineOperand &MO,
223 MCSymbol *Sym) const {
224 // FIXME: We would like an efficient form for this, so we don't have to do a
225 // lot of extra uniquing.
226 const MCExpr *Expr = nullptr;
228
229 switch (MO.getTargetFlags()) {
230 default:
231 llvm_unreachable("Unknown target flag on GV operand");
232 case X86II::MO_NO_FLAG: // No flag.
233 // These affect the name of the symbol, not any suffix.
237 break;
238
239 case X86II::MO_TLVP:
240 RefKind = MCSymbolRefExpr::VK_TLVP;
241 break;
244 // Subtract the pic base.
246 Expr, MCSymbolRefExpr::create(MF.getPICBaseSymbol(), Ctx), Ctx);
247 break;
248 case X86II::MO_SECREL:
250 break;
251 case X86II::MO_TLSGD:
253 break;
254 case X86II::MO_TLSLD:
256 break;
257 case X86II::MO_TLSLDM:
259 break;
262 break;
265 break;
266 case X86II::MO_TPOFF:
268 break;
269 case X86II::MO_DTPOFF:
271 break;
272 case X86II::MO_NTPOFF:
274 break;
277 break;
280 break;
283 break;
284 case X86II::MO_GOT:
285 RefKind = MCSymbolRefExpr::VK_GOT;
286 break;
287 case X86II::MO_GOTOFF:
289 break;
290 case X86II::MO_PLT:
291 RefKind = MCSymbolRefExpr::VK_PLT;
292 break;
293 case X86II::MO_ABS8:
295 break;
298 Expr = MCSymbolRefExpr::create(Sym, Ctx);
299 // Subtract the pic base.
301 Expr, MCSymbolRefExpr::create(MF.getPICBaseSymbol(), Ctx), Ctx);
302 if (MO.isJTI()) {
303 assert(MAI.doesSetDirectiveSuppressReloc());
304 // If .set directive is supported, use it to reduce the number of
305 // relocations the assembler will generate for differences between
306 // local labels. This is only safe when the symbols are in the same
307 // section so we are restricting it to jumptable references.
308 MCSymbol *Label = Ctx.createTempSymbol();
309 AsmPrinter.OutStreamer->emitAssignment(Label, Expr);
310 Expr = MCSymbolRefExpr::create(Label, Ctx);
311 }
312 break;
313 }
314
315 if (!Expr)
316 Expr = MCSymbolRefExpr::create(Sym, RefKind, Ctx);
317
318 if (!MO.isJTI() && !MO.isMBB() && MO.getOffset())
320 Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
321 return MCOperand::createExpr(Expr);
322}
323
324static unsigned getRetOpcode(const X86Subtarget &Subtarget) {
325 return Subtarget.is64Bit() ? X86::RET64 : X86::RET32;
326}
327
328std::optional<MCOperand>
329X86MCInstLower::LowerMachineOperand(const MachineInstr *MI,
330 const MachineOperand &MO) const {
331 switch (MO.getType()) {
332 default:
333 MI->print(errs());
334 llvm_unreachable("unknown operand type");
336 // Ignore all implicit register operands.
337 if (MO.isImplicit())
338 return std::nullopt;
339 return MCOperand::createReg(MO.getReg());
341 return MCOperand::createImm(MO.getImm());
347 return LowerSymbolOperand(MO, MO.getMCSymbol());
353 return LowerSymbolOperand(
356 // Ignore call clobbers.
357 return std::nullopt;
358 }
359}
360
361// Replace TAILJMP opcodes with their equivalent opcodes that have encoding
362// information.
363static unsigned convertTailJumpOpcode(unsigned Opcode) {
364 switch (Opcode) {
365 case X86::TAILJMPr:
366 Opcode = X86::JMP32r;
367 break;
368 case X86::TAILJMPm:
369 Opcode = X86::JMP32m;
370 break;
371 case X86::TAILJMPr64:
372 Opcode = X86::JMP64r;
373 break;
374 case X86::TAILJMPm64:
375 Opcode = X86::JMP64m;
376 break;
377 case X86::TAILJMPr64_REX:
378 Opcode = X86::JMP64r_REX;
379 break;
380 case X86::TAILJMPm64_REX:
381 Opcode = X86::JMP64m_REX;
382 break;
383 case X86::TAILJMPd:
384 case X86::TAILJMPd64:
385 Opcode = X86::JMP_1;
386 break;
387 case X86::TAILJMPd_CC:
388 case X86::TAILJMPd64_CC:
389 Opcode = X86::JCC_1;
390 break;
391 }
392
393 return Opcode;
394}
395
396void X86MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
397 OutMI.setOpcode(MI->getOpcode());
398
399 for (const MachineOperand &MO : MI->operands())
400 if (auto MaybeMCOp = LowerMachineOperand(MI, MO))
401 OutMI.addOperand(*MaybeMCOp);
402
403 bool In64BitMode = AsmPrinter.getSubtarget().is64Bit();
404 if (X86::optimizeInstFromVEX3ToVEX2(OutMI, MI->getDesc()) ||
407 X86::optimizeMOVSX(OutMI) || X86::optimizeINCDEC(OutMI, In64BitMode) ||
408 X86::optimizeMOV(OutMI, In64BitMode) ||
410 return;
411
412 // Handle a few special cases to eliminate operand modifiers.
413 switch (OutMI.getOpcode()) {
414 case X86::LEA64_32r:
415 case X86::LEA64r:
416 case X86::LEA16r:
417 case X86::LEA32r:
418 // LEA should have a segment register, but it must be empty.
420 "Unexpected # of LEA operands");
421 assert(OutMI.getOperand(1 + X86::AddrSegmentReg).getReg() == 0 &&
422 "LEA has segment specified!");
423 break;
424 case X86::MULX32Hrr:
425 case X86::MULX32Hrm:
426 case X86::MULX64Hrr:
427 case X86::MULX64Hrm: {
428 // Turn into regular MULX by duplicating the destination.
429 unsigned NewOpc;
430 switch (OutMI.getOpcode()) {
431 default: llvm_unreachable("Invalid opcode");
432 case X86::MULX32Hrr: NewOpc = X86::MULX32rr; break;
433 case X86::MULX32Hrm: NewOpc = X86::MULX32rm; break;
434 case X86::MULX64Hrr: NewOpc = X86::MULX64rr; break;
435 case X86::MULX64Hrm: NewOpc = X86::MULX64rm; break;
436 }
437 OutMI.setOpcode(NewOpc);
438 // Duplicate the destination.
439 unsigned DestReg = OutMI.getOperand(0).getReg();
440 OutMI.insert(OutMI.begin(), MCOperand::createReg(DestReg));
441 break;
442 }
443 // CALL64r, CALL64pcrel32 - These instructions used to have
444 // register inputs modeled as normal uses instead of implicit uses. As such,
445 // they we used to truncate off all but the first operand (the callee). This
446 // issue seems to have been fixed at some point. This assert verifies that.
447 case X86::CALL64r:
448 case X86::CALL64pcrel32:
449 assert(OutMI.getNumOperands() == 1 && "Unexpected number of operands!");
450 break;
451 case X86::EH_RETURN:
452 case X86::EH_RETURN64: {
453 OutMI = MCInst();
454 OutMI.setOpcode(getRetOpcode(AsmPrinter.getSubtarget()));
455 break;
456 }
457 case X86::CLEANUPRET: {
458 // Replace CLEANUPRET with the appropriate RET.
459 OutMI = MCInst();
460 OutMI.setOpcode(getRetOpcode(AsmPrinter.getSubtarget()));
461 break;
462 }
463 case X86::CATCHRET: {
464 // Replace CATCHRET with the appropriate RET.
465 const X86Subtarget &Subtarget = AsmPrinter.getSubtarget();
466 unsigned ReturnReg = In64BitMode ? X86::RAX : X86::EAX;
467 OutMI = MCInst();
468 OutMI.setOpcode(getRetOpcode(Subtarget));
469 OutMI.addOperand(MCOperand::createReg(ReturnReg));
470 break;
471 }
472 // TAILJMPd, TAILJMPd64, TailJMPd_cc - Lower to the correct jump
473 // instruction.
474 case X86::TAILJMPr:
475 case X86::TAILJMPr64:
476 case X86::TAILJMPr64_REX:
477 case X86::TAILJMPd:
478 case X86::TAILJMPd64:
479 assert(OutMI.getNumOperands() == 1 && "Unexpected number of operands!");
481 break;
482 case X86::TAILJMPd_CC:
483 case X86::TAILJMPd64_CC:
484 assert(OutMI.getNumOperands() == 2 && "Unexpected number of operands!");
486 break;
487 case X86::TAILJMPm:
488 case X86::TAILJMPm64:
489 case X86::TAILJMPm64_REX:
491 "Unexpected number of operands!");
493 break;
494 case X86::MASKMOVDQU:
495 case X86::VMASKMOVDQU:
496 if (In64BitMode)
498 break;
499 case X86::BSF16rm:
500 case X86::BSF16rr:
501 case X86::BSF32rm:
502 case X86::BSF32rr:
503 case X86::BSF64rm:
504 case X86::BSF64rr: {
505 // Add an REP prefix to BSF instructions so that new processors can
506 // recognize as TZCNT, which has better performance than BSF.
507 // BSF and TZCNT have different interpretations on ZF bit. So make sure
508 // it won't be used later.
509 const MachineOperand *FlagDef = MI->findRegisterDefOperand(X86::EFLAGS);
510 if (!MF.getFunction().hasOptSize() && FlagDef && FlagDef->isDead())
512 break;
513 }
514 default:
515 break;
516 }
517}
518
519void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
520 const MachineInstr &MI) {
521 NoAutoPaddingScope NoPadScope(*OutStreamer);
522 bool Is64Bits = getSubtarget().is64Bit();
523 bool Is64BitsLP64 = getSubtarget().isTarget64BitLP64();
524 MCContext &Ctx = OutStreamer->getContext();
525
527 switch (MI.getOpcode()) {
528 case X86::TLS_addr32:
529 case X86::TLS_addr64:
530 case X86::TLS_addrX32:
532 break;
533 case X86::TLS_base_addr32:
535 break;
536 case X86::TLS_base_addr64:
537 case X86::TLS_base_addrX32:
539 break;
540 case X86::TLS_desc32:
541 case X86::TLS_desc64:
543 break;
544 default:
545 llvm_unreachable("unexpected opcode");
546 }
547
549 MCInstLowering.GetSymbolFromOperand(MI.getOperand(3)), SRVK, Ctx);
550
551 // Before binutils 2.41, ld has a bogus TLS relaxation error when the GD/LD
552 // code sequence using R_X86_64_GOTPCREL (instead of R_X86_64_GOTPCRELX) is
553 // attempted to be relaxed to IE/LE (binutils PR24784). Work around the bug by
554 // only using GOT when GOTPCRELX is enabled.
555 // TODO Delete the workaround when rustc no longer relies on the hack
556 bool UseGot = MMI->getModule()->getRtLibUseGOT() &&
558
559 if (SRVK == MCSymbolRefExpr::VK_TLSDESC) {
561 MCInstLowering.GetSymbolFromOperand(MI.getOperand(3)),
563 EmitAndCountInstruction(
564 MCInstBuilder(Is64BitsLP64 ? X86::LEA64r : X86::LEA32r)
565 .addReg(Is64BitsLP64 ? X86::RAX : X86::EAX)
566 .addReg(Is64Bits ? X86::RIP : X86::EBX)
567 .addImm(1)
568 .addReg(0)
569 .addExpr(Sym)
570 .addReg(0));
571 EmitAndCountInstruction(
572 MCInstBuilder(Is64Bits ? X86::CALL64m : X86::CALL32m)
573 .addReg(Is64BitsLP64 ? X86::RAX : X86::EAX)
574 .addImm(1)
575 .addReg(0)
576 .addExpr(Expr)
577 .addReg(0));
578 } else if (Is64Bits) {
579 bool NeedsPadding = SRVK == MCSymbolRefExpr::VK_TLSGD;
580 if (NeedsPadding && Is64BitsLP64)
581 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
582 EmitAndCountInstruction(MCInstBuilder(X86::LEA64r)
583 .addReg(X86::RDI)
584 .addReg(X86::RIP)
585 .addImm(1)
586 .addReg(0)
587 .addExpr(Sym)
588 .addReg(0));
589 const MCSymbol *TlsGetAddr = Ctx.getOrCreateSymbol("__tls_get_addr");
590 if (NeedsPadding) {
591 if (!UseGot)
592 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
593 EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
594 EmitAndCountInstruction(MCInstBuilder(X86::REX64_PREFIX));
595 }
596 if (UseGot) {
597 const MCExpr *Expr = MCSymbolRefExpr::create(
598 TlsGetAddr, MCSymbolRefExpr::VK_GOTPCREL, Ctx);
599 EmitAndCountInstruction(MCInstBuilder(X86::CALL64m)
600 .addReg(X86::RIP)
601 .addImm(1)
602 .addReg(0)
603 .addExpr(Expr)
604 .addReg(0));
605 } else {
606 EmitAndCountInstruction(
607 MCInstBuilder(X86::CALL64pcrel32)
608 .addExpr(MCSymbolRefExpr::create(TlsGetAddr,
610 }
611 } else {
612 if (SRVK == MCSymbolRefExpr::VK_TLSGD && !UseGot) {
613 EmitAndCountInstruction(MCInstBuilder(X86::LEA32r)
614 .addReg(X86::EAX)
615 .addReg(0)
616 .addImm(1)
617 .addReg(X86::EBX)
618 .addExpr(Sym)
619 .addReg(0));
620 } else {
621 EmitAndCountInstruction(MCInstBuilder(X86::LEA32r)
622 .addReg(X86::EAX)
623 .addReg(X86::EBX)
624 .addImm(1)
625 .addReg(0)
626 .addExpr(Sym)
627 .addReg(0));
628 }
629
630 const MCSymbol *TlsGetAddr = Ctx.getOrCreateSymbol("___tls_get_addr");
631 if (UseGot) {
632 const MCExpr *Expr =
634 EmitAndCountInstruction(MCInstBuilder(X86::CALL32m)
635 .addReg(X86::EBX)
636 .addImm(1)
637 .addReg(0)
638 .addExpr(Expr)
639 .addReg(0));
640 } else {
641 EmitAndCountInstruction(
642 MCInstBuilder(X86::CALLpcrel32)
643 .addExpr(MCSymbolRefExpr::create(TlsGetAddr,
645 }
646 }
647}
648
649/// Emit the largest nop instruction smaller than or equal to \p NumBytes
650/// bytes. Return the size of nop emitted.
651static unsigned emitNop(MCStreamer &OS, unsigned NumBytes,
652 const X86Subtarget *Subtarget) {
653 // Determine the longest nop which can be efficiently decoded for the given
654 // target cpu. 15-bytes is the longest single NOP instruction, but some
655 // platforms can't decode the longest forms efficiently.
656 unsigned MaxNopLength = 1;
657 if (Subtarget->is64Bit()) {
658 // FIXME: We can use NOOPL on 32-bit targets with FeatureNOPL, but the
659 // IndexReg/BaseReg below need to be updated.
660 if (Subtarget->hasFeature(X86::TuningFast7ByteNOP))
661 MaxNopLength = 7;
662 else if (Subtarget->hasFeature(X86::TuningFast15ByteNOP))
663 MaxNopLength = 15;
664 else if (Subtarget->hasFeature(X86::TuningFast11ByteNOP))
665 MaxNopLength = 11;
666 else
667 MaxNopLength = 10;
668 } if (Subtarget->is32Bit())
669 MaxNopLength = 2;
670
671 // Cap a single nop emission at the profitable value for the target
672 NumBytes = std::min(NumBytes, MaxNopLength);
673
674 unsigned NopSize;
675 unsigned Opc, BaseReg, ScaleVal, IndexReg, Displacement, SegmentReg;
676 IndexReg = Displacement = SegmentReg = 0;
677 BaseReg = X86::RAX;
678 ScaleVal = 1;
679 switch (NumBytes) {
680 case 0:
681 llvm_unreachable("Zero nops?");
682 break;
683 case 1:
684 NopSize = 1;
685 Opc = X86::NOOP;
686 break;
687 case 2:
688 NopSize = 2;
689 Opc = X86::XCHG16ar;
690 break;
691 case 3:
692 NopSize = 3;
693 Opc = X86::NOOPL;
694 break;
695 case 4:
696 NopSize = 4;
697 Opc = X86::NOOPL;
698 Displacement = 8;
699 break;
700 case 5:
701 NopSize = 5;
702 Opc = X86::NOOPL;
703 Displacement = 8;
704 IndexReg = X86::RAX;
705 break;
706 case 6:
707 NopSize = 6;
708 Opc = X86::NOOPW;
709 Displacement = 8;
710 IndexReg = X86::RAX;
711 break;
712 case 7:
713 NopSize = 7;
714 Opc = X86::NOOPL;
715 Displacement = 512;
716 break;
717 case 8:
718 NopSize = 8;
719 Opc = X86::NOOPL;
720 Displacement = 512;
721 IndexReg = X86::RAX;
722 break;
723 case 9:
724 NopSize = 9;
725 Opc = X86::NOOPW;
726 Displacement = 512;
727 IndexReg = X86::RAX;
728 break;
729 default:
730 NopSize = 10;
731 Opc = X86::NOOPW;
732 Displacement = 512;
733 IndexReg = X86::RAX;
734 SegmentReg = X86::CS;
735 break;
736 }
737
738 unsigned NumPrefixes = std::min(NumBytes - NopSize, 5U);
739 NopSize += NumPrefixes;
740 for (unsigned i = 0; i != NumPrefixes; ++i)
741 OS.emitBytes("\x66");
742
743 switch (Opc) {
744 default: llvm_unreachable("Unexpected opcode");
745 case X86::NOOP:
746 OS.emitInstruction(MCInstBuilder(Opc), *Subtarget);
747 break;
748 case X86::XCHG16ar:
749 OS.emitInstruction(MCInstBuilder(Opc).addReg(X86::AX).addReg(X86::AX),
750 *Subtarget);
751 break;
752 case X86::NOOPL:
753 case X86::NOOPW:
754 OS.emitInstruction(MCInstBuilder(Opc)
755 .addReg(BaseReg)
756 .addImm(ScaleVal)
757 .addReg(IndexReg)
758 .addImm(Displacement)
759 .addReg(SegmentReg),
760 *Subtarget);
761 break;
762 }
763 assert(NopSize <= NumBytes && "We overemitted?");
764 return NopSize;
765}
766
767/// Emit the optimal amount of multi-byte nops on X86.
768static void emitX86Nops(MCStreamer &OS, unsigned NumBytes,
769 const X86Subtarget *Subtarget) {
770 unsigned NopsToEmit = NumBytes;
771 (void)NopsToEmit;
772 while (NumBytes) {
773 NumBytes -= emitNop(OS, NumBytes, Subtarget);
774 assert(NopsToEmit >= NumBytes && "Emitted more than I asked for!");
775 }
776}
777
778void X86AsmPrinter::LowerSTATEPOINT(const MachineInstr &MI,
779 X86MCInstLower &MCIL) {
780 assert(Subtarget->is64Bit() && "Statepoint currently only supports X86-64");
781
782 NoAutoPaddingScope NoPadScope(*OutStreamer);
783
784 StatepointOpers SOpers(&MI);
785 if (unsigned PatchBytes = SOpers.getNumPatchBytes()) {
786 emitX86Nops(*OutStreamer, PatchBytes, Subtarget);
787 } else {
788 // Lower call target and choose correct opcode
789 const MachineOperand &CallTarget = SOpers.getCallTarget();
790 MCOperand CallTargetMCOp;
791 unsigned CallOpcode;
792 switch (CallTarget.getType()) {
795 CallTargetMCOp = MCIL.LowerSymbolOperand(
796 CallTarget, MCIL.GetSymbolFromOperand(CallTarget));
797 CallOpcode = X86::CALL64pcrel32;
798 // Currently, we only support relative addressing with statepoints.
799 // Otherwise, we'll need a scratch register to hold the target
800 // address. You'll fail asserts during load & relocation if this
801 // symbol is to far away. (TODO: support non-relative addressing)
802 break;
804 CallTargetMCOp = MCOperand::createImm(CallTarget.getImm());
805 CallOpcode = X86::CALL64pcrel32;
806 // Currently, we only support relative addressing with statepoints.
807 // Otherwise, we'll need a scratch register to hold the target
808 // immediate. You'll fail asserts during load & relocation if this
809 // address is to far away. (TODO: support non-relative addressing)
810 break;
812 // FIXME: Add retpoline support and remove this.
813 if (Subtarget->useIndirectThunkCalls())
814 report_fatal_error("Lowering register statepoints with thunks not "
815 "yet implemented.");
816 CallTargetMCOp = MCOperand::createReg(CallTarget.getReg());
817 CallOpcode = X86::CALL64r;
818 break;
819 default:
820 llvm_unreachable("Unsupported operand type in statepoint call target");
821 break;
822 }
823
824 // Emit call
826 CallInst.setOpcode(CallOpcode);
827 CallInst.addOperand(CallTargetMCOp);
828 OutStreamer->emitInstruction(CallInst, getSubtargetInfo());
829 }
830
831 // Record our statepoint node in the same section used by STACKMAP
832 // and PATCHPOINT
833 auto &Ctx = OutStreamer->getContext();
834 MCSymbol *MILabel = Ctx.createTempSymbol();
835 OutStreamer->emitLabel(MILabel);
836 SM.recordStatepoint(*MILabel, MI);
837}
838
839void X86AsmPrinter::LowerFAULTING_OP(const MachineInstr &FaultingMI,
840 X86MCInstLower &MCIL) {
841 // FAULTING_LOAD_OP <def>, <faltinf type>, <MBB handler>,
842 // <opcode>, <operands>
843
844 NoAutoPaddingScope NoPadScope(*OutStreamer);
845
846 Register DefRegister = FaultingMI.getOperand(0).getReg();
848 static_cast<FaultMaps::FaultKind>(FaultingMI.getOperand(1).getImm());
849 MCSymbol *HandlerLabel = FaultingMI.getOperand(2).getMBB()->getSymbol();
850 unsigned Opcode = FaultingMI.getOperand(3).getImm();
851 unsigned OperandsBeginIdx = 4;
852
853 auto &Ctx = OutStreamer->getContext();
854 MCSymbol *FaultingLabel = Ctx.createTempSymbol();
855 OutStreamer->emitLabel(FaultingLabel);
856
857 assert(FK < FaultMaps::FaultKindMax && "Invalid Faulting Kind!");
858 FM.recordFaultingOp(FK, FaultingLabel, HandlerLabel);
859
860 MCInst MI;
861 MI.setOpcode(Opcode);
862
863 if (DefRegister != X86::NoRegister)
864 MI.addOperand(MCOperand::createReg(DefRegister));
865
866 for (const MachineOperand &MO :
867 llvm::drop_begin(FaultingMI.operands(), OperandsBeginIdx))
868 if (auto MaybeOperand = MCIL.LowerMachineOperand(&FaultingMI, MO))
869 MI.addOperand(*MaybeOperand);
870
871 OutStreamer->AddComment("on-fault: " + HandlerLabel->getName());
872 OutStreamer->emitInstruction(MI, getSubtargetInfo());
873}
874
875void X86AsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
876 X86MCInstLower &MCIL) {
877 bool Is64Bits = Subtarget->is64Bit();
878 MCContext &Ctx = OutStreamer->getContext();
879 MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
880 const MCSymbolRefExpr *Op =
882
883 EmitAndCountInstruction(
884 MCInstBuilder(Is64Bits ? X86::CALL64pcrel32 : X86::CALLpcrel32)
885 .addExpr(Op));
886}
887
888void X86AsmPrinter::LowerKCFI_CHECK(const MachineInstr &MI) {
889 assert(std::next(MI.getIterator())->isCall() &&
890 "KCFI_CHECK not followed by a call instruction");
891
892 // Adjust the offset for patchable-function-prefix. X86InstrInfo::getNop()
893 // returns a 1-byte X86::NOOP, which means the offset is the same in
894 // bytes. This assumes that patchable-function-prefix is the same for all
895 // functions.
896 const MachineFunction &MF = *MI.getMF();
897 int64_t PrefixNops = 0;
898 (void)MF.getFunction()
899 .getFnAttribute("patchable-function-prefix")
901 .getAsInteger(10, PrefixNops);
902
903 // KCFI allows indirect calls to any location that's preceded by a valid
904 // type identifier. To avoid encoding the full constant into an instruction,
905 // and thus emitting potential call target gadgets at each indirect call
906 // site, load a negated constant to a register and compare that to the
907 // expected value at the call target.
908 const Register AddrReg = MI.getOperand(0).getReg();
909 const uint32_t Type = MI.getOperand(1).getImm();
910 // The check is immediately before the call. If the call target is in R10,
911 // we can clobber R11 for the check instead.
912 unsigned TempReg = AddrReg == X86::R10 ? X86::R11D : X86::R10D;
913 EmitAndCountInstruction(
914 MCInstBuilder(X86::MOV32ri).addReg(TempReg).addImm(-MaskKCFIType(Type)));
915 EmitAndCountInstruction(MCInstBuilder(X86::ADD32rm)
916 .addReg(X86::NoRegister)
917 .addReg(TempReg)
918 .addReg(AddrReg)
919 .addImm(1)
920 .addReg(X86::NoRegister)
921 .addImm(-(PrefixNops + 4))
922 .addReg(X86::NoRegister));
923
925 EmitAndCountInstruction(
926 MCInstBuilder(X86::JCC_1)
928 .addImm(X86::COND_E));
929
931 OutStreamer->emitLabel(Trap);
932 EmitAndCountInstruction(MCInstBuilder(X86::TRAP));
934 OutStreamer->emitLabel(Pass);
935}
936
937void X86AsmPrinter::LowerASAN_CHECK_MEMACCESS(const MachineInstr &MI) {
938 // FIXME: Make this work on non-ELF.
940 report_fatal_error("llvm.asan.check.memaccess only supported on ELF");
941 return;
942 }
943
944 const auto &Reg = MI.getOperand(0).getReg();
945 ASanAccessInfo AccessInfo(MI.getOperand(1).getImm());
946
947 uint64_t ShadowBase;
948 int MappingScale;
949 bool OrShadowOffset;
951 AccessInfo.CompileKernel, &ShadowBase,
952 &MappingScale, &OrShadowOffset);
953
954 StringRef Name = AccessInfo.IsWrite ? "store" : "load";
955 StringRef Op = OrShadowOffset ? "or" : "add";
956 std::string SymName = ("__asan_check_" + Name + "_" + Op + "_" +
957 Twine(1ULL << AccessInfo.AccessSizeIndex) + "_" +
958 TM.getMCRegisterInfo()->getName(Reg.asMCReg()))
959 .str();
960 if (OrShadowOffset)
962 "OrShadowOffset is not supported with optimized callbacks");
963
964 EmitAndCountInstruction(
965 MCInstBuilder(X86::CALL64pcrel32)
968}
969
970void X86AsmPrinter::LowerPATCHABLE_OP(const MachineInstr &MI,
971 X86MCInstLower &MCIL) {
972 // PATCHABLE_OP minsize
973
974 NoAutoPaddingScope NoPadScope(*OutStreamer);
975
976 auto NextMI = std::find_if(std::next(MI.getIterator()),
977 MI.getParent()->end().getInstrIterator(),
978 [](auto &II) { return !II.isMetaInstruction(); });
979
981 unsigned MinSize = MI.getOperand(0).getImm();
982
983 if (NextMI != MI.getParent()->end() && !NextMI->isInlineAsm()) {
984 // Lower the next MachineInstr to find its byte size.
985 // If the next instruction is inline assembly, we skip lowering it for now,
986 // and assume we should always generate NOPs.
987 MCInst MCI;
988 MCIL.Lower(&*NextMI, MCI);
989
991 CodeEmitter->encodeInstruction(MCI, Code, Fixups, getSubtargetInfo());
992 }
993
994 if (Code.size() < MinSize) {
995 if (MinSize == 2 && Subtarget->is32Bit() &&
996 Subtarget->isTargetWindowsMSVC() &&
997 (Subtarget->getCPU().empty() || Subtarget->getCPU() == "pentium3")) {
998 // For compatibility reasons, when targetting MSVC, it is important to
999 // generate a 'legacy' NOP in the form of a 8B FF MOV EDI, EDI. Some tools
1000 // rely specifically on this pattern to be able to patch a function.
1001 // This is only for 32-bit targets, when using /arch:IA32 or /arch:SSE.
1002 OutStreamer->emitInstruction(
1003 MCInstBuilder(X86::MOV32rr_REV).addReg(X86::EDI).addReg(X86::EDI),
1004 *Subtarget);
1005 } else {
1006 unsigned NopSize = emitNop(*OutStreamer, MinSize, Subtarget);
1007 assert(NopSize == MinSize && "Could not implement MinSize!");
1008 (void)NopSize;
1009 }
1010 }
1011}
1012
1013// Lower a stackmap of the form:
1014// <id>, <shadowBytes>, ...
1015void X86AsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
1016 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
1017
1018 auto &Ctx = OutStreamer->getContext();
1019 MCSymbol *MILabel = Ctx.createTempSymbol();
1020 OutStreamer->emitLabel(MILabel);
1021
1022 SM.recordStackMap(*MILabel, MI);
1023 unsigned NumShadowBytes = MI.getOperand(1).getImm();
1024 SMShadowTracker.reset(NumShadowBytes);
1025}
1026
1027// Lower a patchpoint of the form:
1028// [<def>], <id>, <numBytes>, <target>, <numArgs>, <cc>, ...
1029void X86AsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
1030 X86MCInstLower &MCIL) {
1031 assert(Subtarget->is64Bit() && "Patchpoint currently only supports X86-64");
1032
1033 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
1034
1035 NoAutoPaddingScope NoPadScope(*OutStreamer);
1036
1037 auto &Ctx = OutStreamer->getContext();
1038 MCSymbol *MILabel = Ctx.createTempSymbol();
1039 OutStreamer->emitLabel(MILabel);
1040 SM.recordPatchPoint(*MILabel, MI);
1041
1042 PatchPointOpers opers(&MI);
1043 unsigned ScratchIdx = opers.getNextScratchIdx();
1044 unsigned EncodedBytes = 0;
1045 const MachineOperand &CalleeMO = opers.getCallTarget();
1046
1047 // Check for null target. If target is non-null (i.e. is non-zero or is
1048 // symbolic) then emit a call.
1049 if (!(CalleeMO.isImm() && !CalleeMO.getImm())) {
1050 MCOperand CalleeMCOp;
1051 switch (CalleeMO.getType()) {
1052 default:
1053 /// FIXME: Add a verifier check for bad callee types.
1054 llvm_unreachable("Unrecognized callee operand type.");
1056 if (CalleeMO.getImm())
1057 CalleeMCOp = MCOperand::createImm(CalleeMO.getImm());
1058 break;
1061 CalleeMCOp = MCIL.LowerSymbolOperand(CalleeMO,
1062 MCIL.GetSymbolFromOperand(CalleeMO));
1063 break;
1064 }
1065
1066 // Emit MOV to materialize the target address and the CALL to target.
1067 // This is encoded with 12-13 bytes, depending on which register is used.
1068 Register ScratchReg = MI.getOperand(ScratchIdx).getReg();
1069 if (X86II::isX86_64ExtendedReg(ScratchReg))
1070 EncodedBytes = 13;
1071 else
1072 EncodedBytes = 12;
1073
1074 EmitAndCountInstruction(
1075 MCInstBuilder(X86::MOV64ri).addReg(ScratchReg).addOperand(CalleeMCOp));
1076 // FIXME: Add retpoline support and remove this.
1077 if (Subtarget->useIndirectThunkCalls())
1079 "Lowering patchpoint with thunks not yet implemented.");
1080 EmitAndCountInstruction(MCInstBuilder(X86::CALL64r).addReg(ScratchReg));
1081 }
1082
1083 // Emit padding.
1084 unsigned NumBytes = opers.getNumPatchBytes();
1085 assert(NumBytes >= EncodedBytes &&
1086 "Patchpoint can't request size less than the length of a call.");
1087
1088 emitX86Nops(*OutStreamer, NumBytes - EncodedBytes, Subtarget);
1089}
1090
1091void X86AsmPrinter::LowerPATCHABLE_EVENT_CALL(const MachineInstr &MI,
1092 X86MCInstLower &MCIL) {
1093 assert(Subtarget->is64Bit() && "XRay custom events only supports X86-64");
1094
1095 NoAutoPaddingScope NoPadScope(*OutStreamer);
1096
1097 // We want to emit the following pattern, which follows the x86 calling
1098 // convention to prepare for the trampoline call to be patched in.
1099 //
1100 // .p2align 1, ...
1101 // .Lxray_event_sled_N:
1102 // jmp +N // jump across the instrumentation sled
1103 // ... // set up arguments in register
1104 // callq __xray_CustomEvent@plt // force dependency to symbol
1105 // ...
1106 // <jump here>
1107 //
1108 // After patching, it would look something like:
1109 //
1110 // nopw (2-byte nop)
1111 // ...
1112 // callq __xrayCustomEvent // already lowered
1113 // ...
1114 //
1115 // ---
1116 // First we emit the label and the jump.
1117 auto CurSled = OutContext.createTempSymbol("xray_event_sled_", true);
1118 OutStreamer->AddComment("# XRay Custom Event Log");
1119 OutStreamer->emitCodeAlignment(Align(2), &getSubtargetInfo());
1120 OutStreamer->emitLabel(CurSled);
1121
1122 // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as
1123 // an operand (computed as an offset from the jmp instruction).
1124 // FIXME: Find another less hacky way do force the relative jump.
1125 OutStreamer->emitBinaryData("\xeb\x0f");
1126
1127 // The default C calling convention will place two arguments into %rcx and
1128 // %rdx -- so we only work with those.
1129 const Register DestRegs[] = {X86::RDI, X86::RSI};
1130 bool UsedMask[] = {false, false};
1131 // Filled out in loop.
1132 Register SrcRegs[] = {0, 0};
1133
1134 // Then we put the operands in the %rdi and %rsi registers. We spill the
1135 // values in the register before we clobber them, and mark them as used in
1136 // UsedMask. In case the arguments are already in the correct register, we use
1137 // emit nops appropriately sized to keep the sled the same size in every
1138 // situation.
1139 for (unsigned I = 0; I < MI.getNumOperands(); ++I)
1140 if (auto Op = MCIL.LowerMachineOperand(&MI, MI.getOperand(I))) {
1141 assert(Op->isReg() && "Only support arguments in registers");
1142 SrcRegs[I] = getX86SubSuperRegister(Op->getReg(), 64);
1143 assert(SrcRegs[I].isValid() && "Invalid operand");
1144 if (SrcRegs[I] != DestRegs[I]) {
1145 UsedMask[I] = true;
1146 EmitAndCountInstruction(
1147 MCInstBuilder(X86::PUSH64r).addReg(DestRegs[I]));
1148 } else {
1149 emitX86Nops(*OutStreamer, 4, Subtarget);
1150 }
1151 }
1152
1153 // Now that the register values are stashed, mov arguments into place.
1154 // FIXME: This doesn't work if one of the later SrcRegs is equal to an
1155 // earlier DestReg. We will have already overwritten over the register before
1156 // we can copy from it.
1157 for (unsigned I = 0; I < MI.getNumOperands(); ++I)
1158 if (SrcRegs[I] != DestRegs[I])
1159 EmitAndCountInstruction(
1160 MCInstBuilder(X86::MOV64rr).addReg(DestRegs[I]).addReg(SrcRegs[I]));
1161
1162 // We emit a hard dependency on the __xray_CustomEvent symbol, which is the
1163 // name of the trampoline to be implemented by the XRay runtime.
1164 auto TSym = OutContext.getOrCreateSymbol("__xray_CustomEvent");
1168
1169 // Emit the call instruction.
1170 EmitAndCountInstruction(MCInstBuilder(X86::CALL64pcrel32)
1171 .addOperand(MCIL.LowerSymbolOperand(TOp, TSym)));
1172
1173 // Restore caller-saved and used registers.
1174 for (unsigned I = sizeof UsedMask; I-- > 0;)
1175 if (UsedMask[I])
1176 EmitAndCountInstruction(MCInstBuilder(X86::POP64r).addReg(DestRegs[I]));
1177 else
1178 emitX86Nops(*OutStreamer, 1, Subtarget);
1179
1180 OutStreamer->AddComment("xray custom event end.");
1181
1182 // Record the sled version. Version 0 of this sled was spelled differently, so
1183 // we let the runtime handle the different offsets we're using. Version 2
1184 // changed the absolute address to a PC-relative address.
1185 recordSled(CurSled, MI, SledKind::CUSTOM_EVENT, 2);
1186}
1187
1188void X86AsmPrinter::LowerPATCHABLE_TYPED_EVENT_CALL(const MachineInstr &MI,
1189 X86MCInstLower &MCIL) {
1190 assert(Subtarget->is64Bit() && "XRay typed events only supports X86-64");
1191
1192 NoAutoPaddingScope NoPadScope(*OutStreamer);
1193
1194 // We want to emit the following pattern, which follows the x86 calling
1195 // convention to prepare for the trampoline call to be patched in.
1196 //
1197 // .p2align 1, ...
1198 // .Lxray_event_sled_N:
1199 // jmp +N // jump across the instrumentation sled
1200 // ... // set up arguments in register
1201 // callq __xray_TypedEvent@plt // force dependency to symbol
1202 // ...
1203 // <jump here>
1204 //
1205 // After patching, it would look something like:
1206 //
1207 // nopw (2-byte nop)
1208 // ...
1209 // callq __xrayTypedEvent // already lowered
1210 // ...
1211 //
1212 // ---
1213 // First we emit the label and the jump.
1214 auto CurSled = OutContext.createTempSymbol("xray_typed_event_sled_", true);
1215 OutStreamer->AddComment("# XRay Typed Event Log");
1216 OutStreamer->emitCodeAlignment(Align(2), &getSubtargetInfo());
1217 OutStreamer->emitLabel(CurSled);
1218
1219 // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as
1220 // an operand (computed as an offset from the jmp instruction).
1221 // FIXME: Find another less hacky way do force the relative jump.
1222 OutStreamer->emitBinaryData("\xeb\x14");
1223
1224 // An x86-64 convention may place three arguments into %rcx, %rdx, and R8,
1225 // so we'll work with those. Or we may be called via SystemV, in which case
1226 // we don't have to do any translation.
1227 const Register DestRegs[] = {X86::RDI, X86::RSI, X86::RDX};
1228 bool UsedMask[] = {false, false, false};
1229
1230 // Will fill out src regs in the loop.
1231 Register SrcRegs[] = {0, 0, 0};
1232
1233 // Then we put the operands in the SystemV registers. We spill the values in
1234 // the registers before we clobber them, and mark them as used in UsedMask.
1235 // In case the arguments are already in the correct register, we emit nops
1236 // appropriately sized to keep the sled the same size in every situation.
1237 for (unsigned I = 0; I < MI.getNumOperands(); ++I)
1238 if (auto Op = MCIL.LowerMachineOperand(&MI, MI.getOperand(I))) {
1239 // TODO: Is register only support adequate?
1240 assert(Op->isReg() && "Only supports arguments in registers");
1241 SrcRegs[I] = getX86SubSuperRegister(Op->getReg(), 64);
1242 assert(SrcRegs[I].isValid() && "Invalid operand");
1243 if (SrcRegs[I] != DestRegs[I]) {
1244 UsedMask[I] = true;
1245 EmitAndCountInstruction(
1246 MCInstBuilder(X86::PUSH64r).addReg(DestRegs[I]));
1247 } else {
1248 emitX86Nops(*OutStreamer, 4, Subtarget);
1249 }
1250 }
1251
1252 // In the above loop we only stash all of the destination registers or emit
1253 // nops if the arguments are already in the right place. Doing the actually
1254 // moving is postponed until after all the registers are stashed so nothing
1255 // is clobbers. We've already added nops to account for the size of mov and
1256 // push if the register is in the right place, so we only have to worry about
1257 // emitting movs.
1258 // FIXME: This doesn't work if one of the later SrcRegs is equal to an
1259 // earlier DestReg. We will have already overwritten over the register before
1260 // we can copy from it.
1261 for (unsigned I = 0; I < MI.getNumOperands(); ++I)
1262 if (UsedMask[I])
1263 EmitAndCountInstruction(
1264 MCInstBuilder(X86::MOV64rr).addReg(DestRegs[I]).addReg(SrcRegs[I]));
1265
1266 // We emit a hard dependency on the __xray_TypedEvent symbol, which is the
1267 // name of the trampoline to be implemented by the XRay runtime.
1268 auto TSym = OutContext.getOrCreateSymbol("__xray_TypedEvent");
1272
1273 // Emit the call instruction.
1274 EmitAndCountInstruction(MCInstBuilder(X86::CALL64pcrel32)
1275 .addOperand(MCIL.LowerSymbolOperand(TOp, TSym)));
1276
1277 // Restore caller-saved and used registers.
1278 for (unsigned I = sizeof UsedMask; I-- > 0;)
1279 if (UsedMask[I])
1280 EmitAndCountInstruction(MCInstBuilder(X86::POP64r).addReg(DestRegs[I]));
1281 else
1282 emitX86Nops(*OutStreamer, 1, Subtarget);
1283
1284 OutStreamer->AddComment("xray typed event end.");
1285
1286 // Record the sled version.
1287 recordSled(CurSled, MI, SledKind::TYPED_EVENT, 2);
1288}
1289
1290void X86AsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI,
1291 X86MCInstLower &MCIL) {
1292
1293 NoAutoPaddingScope NoPadScope(*OutStreamer);
1294
1295 const Function &F = MF->getFunction();
1296 if (F.hasFnAttribute("patchable-function-entry")) {
1297 unsigned Num;
1298 if (F.getFnAttribute("patchable-function-entry")
1299 .getValueAsString()
1300 .getAsInteger(10, Num))
1301 return;
1302 emitX86Nops(*OutStreamer, Num, Subtarget);
1303 return;
1304 }
1305 // We want to emit the following pattern:
1306 //
1307 // .p2align 1, ...
1308 // .Lxray_sled_N:
1309 // jmp .tmpN
1310 // # 9 bytes worth of noops
1311 //
1312 // We need the 9 bytes because at runtime, we'd be patching over the full 11
1313 // bytes with the following pattern:
1314 //
1315 // mov %r10, <function id, 32-bit> // 6 bytes
1316 // call <relative offset, 32-bits> // 5 bytes
1317 //
1318 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1319 OutStreamer->emitCodeAlignment(Align(2), &getSubtargetInfo());
1320 OutStreamer->emitLabel(CurSled);
1321
1322 // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as
1323 // an operand (computed as an offset from the jmp instruction).
1324 // FIXME: Find another less hacky way do force the relative jump.
1325 OutStreamer->emitBytes("\xeb\x09");
1326 emitX86Nops(*OutStreamer, 9, Subtarget);
1328}
1329
1330void X86AsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
1331 X86MCInstLower &MCIL) {
1332 NoAutoPaddingScope NoPadScope(*OutStreamer);
1333
1334 // Since PATCHABLE_RET takes the opcode of the return statement as an
1335 // argument, we use that to emit the correct form of the RET that we want.
1336 // i.e. when we see this:
1337 //
1338 // PATCHABLE_RET X86::RET ...
1339 //
1340 // We should emit the RET followed by sleds.
1341 //
1342 // .p2align 1, ...
1343 // .Lxray_sled_N:
1344 // ret # or equivalent instruction
1345 // # 10 bytes worth of noops
1346 //
1347 // This just makes sure that the alignment for the next instruction is 2.
1348 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1349 OutStreamer->emitCodeAlignment(Align(2), &getSubtargetInfo());
1350 OutStreamer->emitLabel(CurSled);
1351 unsigned OpCode = MI.getOperand(0).getImm();
1352 MCInst Ret;
1353 Ret.setOpcode(OpCode);
1354 for (auto &MO : drop_begin(MI.operands()))
1355 if (auto MaybeOperand = MCIL.LowerMachineOperand(&MI, MO))
1356 Ret.addOperand(*MaybeOperand);
1357 OutStreamer->emitInstruction(Ret, getSubtargetInfo());
1358 emitX86Nops(*OutStreamer, 10, Subtarget);
1360}
1361
1362void X86AsmPrinter::LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI,
1363 X86MCInstLower &MCIL) {
1364 NoAutoPaddingScope NoPadScope(*OutStreamer);
1365
1366 // Like PATCHABLE_RET, we have the actual instruction in the operands to this
1367 // instruction so we lower that particular instruction and its operands.
1368 // Unlike PATCHABLE_RET though, we put the sled before the JMP, much like how
1369 // we do it for PATCHABLE_FUNCTION_ENTER. The sled should be very similar to
1370 // the PATCHABLE_FUNCTION_ENTER case, followed by the lowering of the actual
1371 // tail call much like how we have it in PATCHABLE_RET.
1372 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1373 OutStreamer->emitCodeAlignment(Align(2), &getSubtargetInfo());
1374 OutStreamer->emitLabel(CurSled);
1376
1377 // Use a two-byte `jmp`. This version of JMP takes an 8-bit relative offset as
1378 // an operand (computed as an offset from the jmp instruction).
1379 // FIXME: Find another less hacky way do force the relative jump.
1380 OutStreamer->emitBytes("\xeb\x09");
1381 emitX86Nops(*OutStreamer, 9, Subtarget);
1382 OutStreamer->emitLabel(Target);
1383 recordSled(CurSled, MI, SledKind::TAIL_CALL, 2);
1384
1385 unsigned OpCode = MI.getOperand(0).getImm();
1386 OpCode = convertTailJumpOpcode(OpCode);
1387 MCInst TC;
1388 TC.setOpcode(OpCode);
1389
1390 // Before emitting the instruction, add a comment to indicate that this is
1391 // indeed a tail call.
1392 OutStreamer->AddComment("TAILCALL");
1393 for (auto &MO : drop_begin(MI.operands()))
1394 if (auto MaybeOperand = MCIL.LowerMachineOperand(&MI, MO))
1395 TC.addOperand(*MaybeOperand);
1396 OutStreamer->emitInstruction(TC, getSubtargetInfo());
1397}
1398
1399// Returns instruction preceding MBBI in MachineFunction.
1400// If MBBI is the first instruction of the first basic block, returns null.
1403 const MachineBasicBlock *MBB = MBBI->getParent();
1404 while (MBBI == MBB->begin()) {
1405 if (MBB == &MBB->getParent()->front())
1407 MBB = MBB->getPrevNode();
1408 MBBI = MBB->end();
1409 }
1410 --MBBI;
1411 return MBBI;
1412}
1413
1414static unsigned getSrcIdx(const MachineInstr* MI, unsigned SrcIdx) {
1415 if (X86II::isKMasked(MI->getDesc().TSFlags)) {
1416 // Skip mask operand.
1417 ++SrcIdx;
1418 if (X86II::isKMergeMasked(MI->getDesc().TSFlags)) {
1419 // Skip passthru operand.
1420 ++SrcIdx;
1421 }
1422 }
1423 return SrcIdx;
1424}
1425
1427 unsigned SrcOpIdx) {
1428 const MachineOperand &DstOp = MI->getOperand(0);
1430
1431 // Handle AVX512 MASK/MASXZ write mask comments.
1432 // MASK: zmmX {%kY}
1433 // MASKZ: zmmX {%kY} {z}
1434 if (X86II::isKMasked(MI->getDesc().TSFlags)) {
1435 const MachineOperand &WriteMaskOp = MI->getOperand(SrcOpIdx - 1);
1437 CS << " {%" << Mask << "}";
1438 if (!X86II::isKMergeMasked(MI->getDesc().TSFlags)) {
1439 CS << " {z}";
1440 }
1441 }
1442}
1443
1444static void printShuffleMask(raw_ostream &CS, StringRef Src1Name,
1445 StringRef Src2Name, ArrayRef<int> Mask) {
1446 // One source operand, fix the mask to print all elements in one span.
1447 SmallVector<int, 8> ShuffleMask(Mask);
1448 if (Src1Name == Src2Name)
1449 for (int i = 0, e = ShuffleMask.size(); i != e; ++i)
1450 if (ShuffleMask[i] >= e)
1451 ShuffleMask[i] -= e;
1452
1453 for (int i = 0, e = ShuffleMask.size(); i != e; ++i) {
1454 if (i != 0)
1455 CS << ",";
1456 if (ShuffleMask[i] == SM_SentinelZero) {
1457 CS << "zero";
1458 continue;
1459 }
1460
1461 // Otherwise, it must come from src1 or src2. Print the span of elements
1462 // that comes from this src.
1463 bool isSrc1 = ShuffleMask[i] < (int)e;
1464 CS << (isSrc1 ? Src1Name : Src2Name) << '[';
1465
1466 bool IsFirst = true;
1467 while (i != e && ShuffleMask[i] != SM_SentinelZero &&
1468 (ShuffleMask[i] < (int)e) == isSrc1) {
1469 if (!IsFirst)
1470 CS << ',';
1471 else
1472 IsFirst = false;
1473 if (ShuffleMask[i] == SM_SentinelUndef)
1474 CS << "u";
1475 else
1476 CS << ShuffleMask[i] % (int)e;
1477 ++i;
1478 }
1479 CS << ']';
1480 --i; // For loop increments element #.
1481 }
1482}
1483
1484static std::string getShuffleComment(const MachineInstr *MI, unsigned SrcOp1Idx,
1485 unsigned SrcOp2Idx, ArrayRef<int> Mask) {
1486 std::string Comment;
1487
1488 const MachineOperand &SrcOp1 = MI->getOperand(SrcOp1Idx);
1489 const MachineOperand &SrcOp2 = MI->getOperand(SrcOp2Idx);
1490 StringRef Src1Name = SrcOp1.isReg()
1492 : "mem";
1493 StringRef Src2Name = SrcOp2.isReg()
1495 : "mem";
1496
1497 raw_string_ostream CS(Comment);
1498 printDstRegisterName(CS, MI, SrcOp1Idx);
1499 CS << " = ";
1500 printShuffleMask(CS, Src1Name, Src2Name, Mask);
1501 CS.flush();
1502
1503 return Comment;
1504}
1505
1506static void printConstant(const APInt &Val, raw_ostream &CS,
1507 bool PrintZero = false) {
1508 if (Val.getBitWidth() <= 64) {
1509 CS << (PrintZero ? 0ULL : Val.getZExtValue());
1510 } else {
1511 // print multi-word constant as (w0,w1)
1512 CS << "(";
1513 for (int i = 0, N = Val.getNumWords(); i < N; ++i) {
1514 if (i > 0)
1515 CS << ",";
1516 CS << (PrintZero ? 0ULL : Val.getRawData()[i]);
1517 }
1518 CS << ")";
1519 }
1520}
1521
1522static void printConstant(const APFloat &Flt, raw_ostream &CS,
1523 bool PrintZero = false) {
1524 SmallString<32> Str;
1525 // Force scientific notation to distinguish from integers.
1526 if (PrintZero)
1527 APFloat::getZero(Flt.getSemantics()).toString(Str, 0, 0);
1528 else
1529 Flt.toString(Str, 0, 0);
1530 CS << Str;
1531}
1532
1533static void printConstant(const Constant *COp, unsigned BitWidth,
1534 raw_ostream &CS, bool PrintZero = false) {
1535 if (isa<UndefValue>(COp)) {
1536 CS << "u";
1537 } else if (auto *CI = dyn_cast<ConstantInt>(COp)) {
1538 printConstant(CI->getValue(), CS, PrintZero);
1539 } else if (auto *CF = dyn_cast<ConstantFP>(COp)) {
1540 printConstant(CF->getValueAPF(), CS, PrintZero);
1541 } else if (auto *CDS = dyn_cast<ConstantDataSequential>(COp)) {
1542 Type *EltTy = CDS->getElementType();
1543 bool IsInteger = EltTy->isIntegerTy();
1544 bool IsFP = EltTy->isHalfTy() || EltTy->isFloatTy() || EltTy->isDoubleTy();
1545 unsigned EltBits = EltTy->getPrimitiveSizeInBits();
1546 unsigned E = std::min(BitWidth / EltBits, CDS->getNumElements());
1547 assert((BitWidth % EltBits) == 0 && "Element size mismatch");
1548 for (unsigned I = 0; I != E; ++I) {
1549 if (I != 0)
1550 CS << ",";
1551 if (IsInteger)
1552 printConstant(CDS->getElementAsAPInt(I), CS, PrintZero);
1553 else if (IsFP)
1554 printConstant(CDS->getElementAsAPFloat(I), CS, PrintZero);
1555 else
1556 CS << "?";
1557 }
1558 } else if (auto *CV = dyn_cast<ConstantVector>(COp)) {
1559 unsigned EltBits = CV->getType()->getScalarSizeInBits();
1560 unsigned E = std::min(BitWidth / EltBits, CV->getNumOperands());
1561 assert((BitWidth % EltBits) == 0 && "Element size mismatch");
1562 for (unsigned I = 0; I != E; ++I) {
1563 if (I != 0)
1564 CS << ",";
1565 printConstant(CV->getOperand(I), EltBits, CS, PrintZero);
1566 }
1567 } else {
1568 CS << "?";
1569 }
1570}
1571
1572static void printZeroUpperMove(const MachineInstr *MI, MCStreamer &OutStreamer,
1573 int SclWidth, int VecWidth,
1574 const char *ShuffleComment) {
1575 unsigned SrcIdx = getSrcIdx(MI, 1);
1576
1577 std::string Comment;
1578 raw_string_ostream CS(Comment);
1579 printDstRegisterName(CS, MI, SrcIdx);
1580 CS << " = ";
1581
1582 if (auto *C = X86::getConstantFromPool(*MI, SrcIdx)) {
1583 CS << "[";
1584 printConstant(C, SclWidth, CS);
1585 for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
1586 CS << ",";
1587 printConstant(C, SclWidth, CS, true);
1588 }
1589 CS << "]";
1590 OutStreamer.AddComment(CS.str());
1591 return; // early-out
1592 }
1593
1594 // We didn't find a constant load, fallback to a shuffle mask decode.
1595 CS << ShuffleComment;
1596 OutStreamer.AddComment(CS.str());
1597}
1598
1599static void printBroadcast(const MachineInstr *MI, MCStreamer &OutStreamer,
1600 int Repeats, int BitWidth) {
1601 unsigned SrcIdx = getSrcIdx(MI, 1);
1602 if (auto *C = X86::getConstantFromPool(*MI, SrcIdx)) {
1603 std::string Comment;
1604 raw_string_ostream CS(Comment);
1605 printDstRegisterName(CS, MI, SrcIdx);
1606 CS << " = [";
1607 for (int l = 0; l != Repeats; ++l) {
1608 if (l != 0)
1609 CS << ",";
1610 printConstant(C, BitWidth, CS);
1611 }
1612 CS << "]";
1613 OutStreamer.AddComment(CS.str());
1614 }
1615}
1616
1617static bool printExtend(const MachineInstr *MI, MCStreamer &OutStreamer,
1618 int SrcEltBits, int DstEltBits, bool IsSext) {
1619 unsigned SrcIdx = getSrcIdx(MI, 1);
1620 auto *C = X86::getConstantFromPool(*MI, SrcIdx);
1621 if (C && C->getType()->getScalarSizeInBits() == unsigned(SrcEltBits)) {
1622 if (auto *CDS = dyn_cast<ConstantDataSequential>(C)) {
1623 int NumElts = CDS->getNumElements();
1624 std::string Comment;
1625 raw_string_ostream CS(Comment);
1626 printDstRegisterName(CS, MI, SrcIdx);
1627 CS << " = [";
1628 for (int i = 0; i != NumElts; ++i) {
1629 if (i != 0)
1630 CS << ",";
1631 if (CDS->getElementType()->isIntegerTy()) {
1632 APInt Elt = CDS->getElementAsAPInt(i);
1633 Elt = IsSext ? Elt.sext(DstEltBits) : Elt.zext(DstEltBits);
1634 printConstant(Elt, CS);
1635 } else
1636 CS << "?";
1637 }
1638 CS << "]";
1639 OutStreamer.AddComment(CS.str());
1640 return true;
1641 }
1642 }
1643
1644 return false;
1645}
1646static void printSignExtend(const MachineInstr *MI, MCStreamer &OutStreamer,
1647 int SrcEltBits, int DstEltBits) {
1648 printExtend(MI, OutStreamer, SrcEltBits, DstEltBits, true);
1649}
1650static void printZeroExtend(const MachineInstr *MI, MCStreamer &OutStreamer,
1651 int SrcEltBits, int DstEltBits) {
1652 if (printExtend(MI, OutStreamer, SrcEltBits, DstEltBits, false))
1653 return;
1654
1655 // We didn't find a constant load, fallback to a shuffle mask decode.
1656 std::string Comment;
1657 raw_string_ostream CS(Comment);
1659 CS << " = ";
1660
1661 SmallVector<int> Mask;
1662 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1663 assert((Width % DstEltBits) == 0 && (DstEltBits % SrcEltBits) == 0 &&
1664 "Illegal extension ratio");
1665 DecodeZeroExtendMask(SrcEltBits, DstEltBits, Width / DstEltBits, false, Mask);
1666 printShuffleMask(CS, "mem", "", Mask);
1667
1668 OutStreamer.AddComment(CS.str());
1669}
1670
1671void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) {
1672 assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
1673 assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) &&
1674 "SEH_ instruction Windows and UEFI only");
1675
1676 // Use the .cv_fpo directives if we're emitting CodeView on 32-bit x86.
1677 if (EmitFPOData) {
1678 X86TargetStreamer *XTS =
1679 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
1680 switch (MI->getOpcode()) {
1681 case X86::SEH_PushReg:
1682 XTS->emitFPOPushReg(MI->getOperand(0).getImm());
1683 break;
1684 case X86::SEH_StackAlloc:
1685 XTS->emitFPOStackAlloc(MI->getOperand(0).getImm());
1686 break;
1687 case X86::SEH_StackAlign:
1688 XTS->emitFPOStackAlign(MI->getOperand(0).getImm());
1689 break;
1690 case X86::SEH_SetFrame:
1691 assert(MI->getOperand(1).getImm() == 0 &&
1692 ".cv_fpo_setframe takes no offset");
1693 XTS->emitFPOSetFrame(MI->getOperand(0).getImm());
1694 break;
1695 case X86::SEH_EndPrologue:
1696 XTS->emitFPOEndPrologue();
1697 break;
1698 case X86::SEH_SaveReg:
1699 case X86::SEH_SaveXMM:
1700 case X86::SEH_PushFrame:
1701 llvm_unreachable("SEH_ directive incompatible with FPO");
1702 break;
1703 default:
1704 llvm_unreachable("expected SEH_ instruction");
1705 }
1706 return;
1707 }
1708
1709 // Otherwise, use the .seh_ directives for all other Windows platforms.
1710 switch (MI->getOpcode()) {
1711 case X86::SEH_PushReg:
1712 OutStreamer->emitWinCFIPushReg(MI->getOperand(0).getImm());
1713 break;
1714
1715 case X86::SEH_SaveReg:
1716 OutStreamer->emitWinCFISaveReg(MI->getOperand(0).getImm(),
1717 MI->getOperand(1).getImm());
1718 break;
1719
1720 case X86::SEH_SaveXMM:
1721 OutStreamer->emitWinCFISaveXMM(MI->getOperand(0).getImm(),
1722 MI->getOperand(1).getImm());
1723 break;
1724
1725 case X86::SEH_StackAlloc:
1726 OutStreamer->emitWinCFIAllocStack(MI->getOperand(0).getImm());
1727 break;
1728
1729 case X86::SEH_SetFrame:
1730 OutStreamer->emitWinCFISetFrame(MI->getOperand(0).getImm(),
1731 MI->getOperand(1).getImm());
1732 break;
1733
1734 case X86::SEH_PushFrame:
1735 OutStreamer->emitWinCFIPushFrame(MI->getOperand(0).getImm());
1736 break;
1737
1738 case X86::SEH_EndPrologue:
1739 OutStreamer->emitWinCFIEndProlog();
1740 break;
1741
1742 default:
1743 llvm_unreachable("expected SEH_ instruction");
1744 }
1745}
1746
1748 MCStreamer &OutStreamer) {
1749 switch (MI->getOpcode()) {
1750 // Lower PSHUFB and VPERMILP normally but add a comment if we can find
1751 // a constant shuffle mask. We won't be able to do this at the MC layer
1752 // because the mask isn't an immediate.
1753 case X86::PSHUFBrm:
1754 case X86::VPSHUFBrm:
1755 case X86::VPSHUFBYrm:
1756 case X86::VPSHUFBZ128rm:
1757 case X86::VPSHUFBZ128rmk:
1758 case X86::VPSHUFBZ128rmkz:
1759 case X86::VPSHUFBZ256rm:
1760 case X86::VPSHUFBZ256rmk:
1761 case X86::VPSHUFBZ256rmkz:
1762 case X86::VPSHUFBZrm:
1763 case X86::VPSHUFBZrmk:
1764 case X86::VPSHUFBZrmkz: {
1765 unsigned SrcIdx = getSrcIdx(MI, 1);
1766 if (auto *C = X86::getConstantFromPool(*MI, SrcIdx + 1)) {
1767 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1769 DecodePSHUFBMask(C, Width, Mask);
1770 if (!Mask.empty())
1771 OutStreamer.AddComment(getShuffleComment(MI, SrcIdx, SrcIdx, Mask));
1772 }
1773 break;
1774 }
1775
1776 case X86::VPERMILPSrm:
1777 case X86::VPERMILPSYrm:
1778 case X86::VPERMILPSZ128rm:
1779 case X86::VPERMILPSZ128rmk:
1780 case X86::VPERMILPSZ128rmkz:
1781 case X86::VPERMILPSZ256rm:
1782 case X86::VPERMILPSZ256rmk:
1783 case X86::VPERMILPSZ256rmkz:
1784 case X86::VPERMILPSZrm:
1785 case X86::VPERMILPSZrmk:
1786 case X86::VPERMILPSZrmkz: {
1787 unsigned SrcIdx = getSrcIdx(MI, 1);
1788 if (auto *C = X86::getConstantFromPool(*MI, SrcIdx + 1)) {
1789 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1791 DecodeVPERMILPMask(C, 32, Width, Mask);
1792 if (!Mask.empty())
1793 OutStreamer.AddComment(getShuffleComment(MI, SrcIdx, SrcIdx, Mask));
1794 }
1795 break;
1796 }
1797 case X86::VPERMILPDrm:
1798 case X86::VPERMILPDYrm:
1799 case X86::VPERMILPDZ128rm:
1800 case X86::VPERMILPDZ128rmk:
1801 case X86::VPERMILPDZ128rmkz:
1802 case X86::VPERMILPDZ256rm:
1803 case X86::VPERMILPDZ256rmk:
1804 case X86::VPERMILPDZ256rmkz:
1805 case X86::VPERMILPDZrm:
1806 case X86::VPERMILPDZrmk:
1807 case X86::VPERMILPDZrmkz: {
1808 unsigned SrcIdx = getSrcIdx(MI, 1);
1809 if (auto *C = X86::getConstantFromPool(*MI, SrcIdx + 1)) {
1810 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1812 DecodeVPERMILPMask(C, 64, Width, Mask);
1813 if (!Mask.empty())
1814 OutStreamer.AddComment(getShuffleComment(MI, SrcIdx, SrcIdx, Mask));
1815 }
1816 break;
1817 }
1818
1819 case X86::VPERMIL2PDrm:
1820 case X86::VPERMIL2PSrm:
1821 case X86::VPERMIL2PDYrm:
1822 case X86::VPERMIL2PSYrm: {
1823 assert(MI->getNumOperands() >= (3 + X86::AddrNumOperands + 1) &&
1824 "Unexpected number of operands!");
1825
1826 const MachineOperand &CtrlOp = MI->getOperand(MI->getNumOperands() - 1);
1827 if (!CtrlOp.isImm())
1828 break;
1829
1830 unsigned ElSize;
1831 switch (MI->getOpcode()) {
1832 default: llvm_unreachable("Invalid opcode");
1833 case X86::VPERMIL2PSrm: case X86::VPERMIL2PSYrm: ElSize = 32; break;
1834 case X86::VPERMIL2PDrm: case X86::VPERMIL2PDYrm: ElSize = 64; break;
1835 }
1836
1837 if (auto *C = X86::getConstantFromPool(*MI, 3)) {
1838 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1840 DecodeVPERMIL2PMask(C, (unsigned)CtrlOp.getImm(), ElSize, Width, Mask);
1841 if (!Mask.empty())
1842 OutStreamer.AddComment(getShuffleComment(MI, 1, 2, Mask));
1843 }
1844 break;
1845 }
1846
1847 case X86::VPPERMrrm: {
1848 if (auto *C = X86::getConstantFromPool(*MI, 3)) {
1849 unsigned Width = X86::getVectorRegisterWidth(MI->getDesc().operands()[0]);
1851 DecodeVPPERMMask(C, Width, Mask);
1852 if (!Mask.empty())
1853 OutStreamer.AddComment(getShuffleComment(MI, 1, 2, Mask));
1854 }
1855 break;
1856 }
1857
1858 case X86::MMX_MOVQ64rm: {
1859 if (auto *C = X86::getConstantFromPool(*MI, 1)) {
1860 std::string Comment;
1861 raw_string_ostream CS(Comment);
1862 const MachineOperand &DstOp = MI->getOperand(0);
1864 if (auto *CF = dyn_cast<ConstantFP>(C)) {
1865 CS << "0x" << toString(CF->getValueAPF().bitcastToAPInt(), 16, false);
1866 OutStreamer.AddComment(CS.str());
1867 }
1868 }
1869 break;
1870 }
1871
1872#define MASK_AVX512_CASE(Instr) \
1873 case Instr: \
1874 case Instr##k: \
1875 case Instr##kz:
1876
1877 case X86::MOVSDrm:
1878 case X86::VMOVSDrm:
1879 MASK_AVX512_CASE(X86::VMOVSDZrm)
1880 case X86::MOVSDrm_alt:
1881 case X86::VMOVSDrm_alt:
1882 case X86::VMOVSDZrm_alt:
1883 case X86::MOVQI2PQIrm:
1884 case X86::VMOVQI2PQIrm:
1885 case X86::VMOVQI2PQIZrm:
1886 printZeroUpperMove(MI, OutStreamer, 64, 128, "mem[0],zero");
1887 break;
1888
1889 MASK_AVX512_CASE(X86::VMOVSHZrm)
1890 case X86::VMOVSHZrm_alt:
1891 printZeroUpperMove(MI, OutStreamer, 16, 128,
1892 "mem[0],zero,zero,zero,zero,zero,zero,zero");
1893 break;
1894
1895 case X86::MOVSSrm:
1896 case X86::VMOVSSrm:
1897 MASK_AVX512_CASE(X86::VMOVSSZrm)
1898 case X86::MOVSSrm_alt:
1899 case X86::VMOVSSrm_alt:
1900 case X86::VMOVSSZrm_alt:
1901 case X86::MOVDI2PDIrm:
1902 case X86::VMOVDI2PDIrm:
1903 case X86::VMOVDI2PDIZrm:
1904 printZeroUpperMove(MI, OutStreamer, 32, 128, "mem[0],zero,zero,zero");
1905 break;
1906
1907#define MOV_CASE(Prefix, Suffix) \
1908 case X86::Prefix##MOVAPD##Suffix##rm: \
1909 case X86::Prefix##MOVAPS##Suffix##rm: \
1910 case X86::Prefix##MOVUPD##Suffix##rm: \
1911 case X86::Prefix##MOVUPS##Suffix##rm: \
1912 case X86::Prefix##MOVDQA##Suffix##rm: \
1913 case X86::Prefix##MOVDQU##Suffix##rm:
1914
1915#define MOV_AVX512_CASE(Suffix, Postfix) \
1916 case X86::VMOVDQA64##Suffix##rm##Postfix: \
1917 case X86::VMOVDQA32##Suffix##rm##Postfix: \
1918 case X86::VMOVDQU64##Suffix##rm##Postfix: \
1919 case X86::VMOVDQU32##Suffix##rm##Postfix: \
1920 case X86::VMOVDQU16##Suffix##rm##Postfix: \
1921 case X86::VMOVDQU8##Suffix##rm##Postfix: \
1922 case X86::VMOVAPS##Suffix##rm##Postfix: \
1923 case X86::VMOVAPD##Suffix##rm##Postfix: \
1924 case X86::VMOVUPS##Suffix##rm##Postfix: \
1925 case X86::VMOVUPD##Suffix##rm##Postfix:
1926
1927#define CASE_128_MOV_RM() \
1928 MOV_CASE(, ) /* SSE */ \
1929 MOV_CASE(V, ) /* AVX-128 */ \
1930 MOV_AVX512_CASE(Z128, ) \
1931 MOV_AVX512_CASE(Z128, k) \
1932 MOV_AVX512_CASE(Z128, kz)
1933
1934#define CASE_256_MOV_RM() \
1935 MOV_CASE(V, Y) /* AVX-256 */ \
1936 MOV_AVX512_CASE(Z256, ) \
1937 MOV_AVX512_CASE(Z256, k) \
1938 MOV_AVX512_CASE(Z256, kz) \
1939
1940#define CASE_512_MOV_RM() \
1941 MOV_AVX512_CASE(Z, ) \
1942 MOV_AVX512_CASE(Z, k) \
1943 MOV_AVX512_CASE(Z, kz) \
1944
1945 // For loads from a constant pool to a vector register, print the constant
1946 // loaded.
1948 printBroadcast(MI, OutStreamer, 1, 128);
1949 break;
1951 printBroadcast(MI, OutStreamer, 1, 256);
1952 break;
1954 printBroadcast(MI, OutStreamer, 1, 512);
1955 break;
1956 case X86::VBROADCASTF128rm:
1957 case X86::VBROADCASTI128rm:
1958 MASK_AVX512_CASE(X86::VBROADCASTF32X4Z256rm)
1959 MASK_AVX512_CASE(X86::VBROADCASTF64X2Z128rm)
1960 MASK_AVX512_CASE(X86::VBROADCASTI32X4Z256rm)
1961 MASK_AVX512_CASE(X86::VBROADCASTI64X2Z128rm)
1962 printBroadcast(MI, OutStreamer, 2, 128);
1963 break;
1964 MASK_AVX512_CASE(X86::VBROADCASTF32X4rm)
1965 MASK_AVX512_CASE(X86::VBROADCASTF64X2rm)
1966 MASK_AVX512_CASE(X86::VBROADCASTI32X4rm)
1967 MASK_AVX512_CASE(X86::VBROADCASTI64X2rm)
1968 printBroadcast(MI, OutStreamer, 4, 128);
1969 break;
1970 MASK_AVX512_CASE(X86::VBROADCASTF32X8rm)
1971 MASK_AVX512_CASE(X86::VBROADCASTF64X4rm)
1972 MASK_AVX512_CASE(X86::VBROADCASTI32X8rm)
1973 MASK_AVX512_CASE(X86::VBROADCASTI64X4rm)
1974 printBroadcast(MI, OutStreamer, 2, 256);
1975 break;
1976
1977 // For broadcast loads from a constant pool to a vector register, repeatedly
1978 // print the constant loaded.
1979 case X86::MOVDDUPrm:
1980 case X86::VMOVDDUPrm:
1981 MASK_AVX512_CASE(X86::VMOVDDUPZ128rm)
1982 case X86::VPBROADCASTQrm:
1983 MASK_AVX512_CASE(X86::VPBROADCASTQZ128rm)
1984 printBroadcast(MI, OutStreamer, 2, 64);
1985 break;
1986 case X86::VBROADCASTSDYrm:
1987 MASK_AVX512_CASE(X86::VBROADCASTSDZ256rm)
1988 case X86::VPBROADCASTQYrm:
1989 MASK_AVX512_CASE(X86::VPBROADCASTQZ256rm)
1990 printBroadcast(MI, OutStreamer, 4, 64);
1991 break;
1992 MASK_AVX512_CASE(X86::VBROADCASTSDZrm)
1993 MASK_AVX512_CASE(X86::VPBROADCASTQZrm)
1994 printBroadcast(MI, OutStreamer, 8, 64);
1995 break;
1996 case X86::VBROADCASTSSrm:
1997 MASK_AVX512_CASE(X86::VBROADCASTSSZ128rm)
1998 case X86::VPBROADCASTDrm:
1999 MASK_AVX512_CASE(X86::VPBROADCASTDZ128rm)
2000 printBroadcast(MI, OutStreamer, 4, 32);
2001 break;
2002 case X86::VBROADCASTSSYrm:
2003 MASK_AVX512_CASE(X86::VBROADCASTSSZ256rm)
2004 case X86::VPBROADCASTDYrm:
2005 MASK_AVX512_CASE(X86::VPBROADCASTDZ256rm)
2006 printBroadcast(MI, OutStreamer, 8, 32);
2007 break;
2008 MASK_AVX512_CASE(X86::VBROADCASTSSZrm)
2009 MASK_AVX512_CASE(X86::VPBROADCASTDZrm)
2010 printBroadcast(MI, OutStreamer, 16, 32);
2011 break;
2012 case X86::VPBROADCASTWrm:
2013 MASK_AVX512_CASE(X86::VPBROADCASTWZ128rm)
2014 printBroadcast(MI, OutStreamer, 8, 16);
2015 break;
2016 case X86::VPBROADCASTWYrm:
2017 MASK_AVX512_CASE(X86::VPBROADCASTWZ256rm)
2018 printBroadcast(MI, OutStreamer, 16, 16);
2019 break;
2020 MASK_AVX512_CASE(X86::VPBROADCASTWZrm)
2021 printBroadcast(MI, OutStreamer, 32, 16);
2022 break;
2023 case X86::VPBROADCASTBrm:
2024 MASK_AVX512_CASE(X86::VPBROADCASTBZ128rm)
2025 printBroadcast(MI, OutStreamer, 16, 8);
2026 break;
2027 case X86::VPBROADCASTBYrm:
2028 MASK_AVX512_CASE(X86::VPBROADCASTBZ256rm)
2029 printBroadcast(MI, OutStreamer, 32, 8);
2030 break;
2031 MASK_AVX512_CASE(X86::VPBROADCASTBZrm)
2032 printBroadcast(MI, OutStreamer, 64, 8);
2033 break;
2034
2035#define MOVX_CASE(Prefix, Ext, Type, Suffix, Postfix) \
2036 case X86::Prefix##PMOV##Ext##Type##Suffix##rm##Postfix:
2037
2038#define CASE_MOVX_RM(Ext, Type) \
2039 MOVX_CASE(, Ext, Type, , ) \
2040 MOVX_CASE(V, Ext, Type, , ) \
2041 MOVX_CASE(V, Ext, Type, Y, ) \
2042 MOVX_CASE(V, Ext, Type, Z128, ) \
2043 MOVX_CASE(V, Ext, Type, Z128, k ) \
2044 MOVX_CASE(V, Ext, Type, Z128, kz ) \
2045 MOVX_CASE(V, Ext, Type, Z256, ) \
2046 MOVX_CASE(V, Ext, Type, Z256, k ) \
2047 MOVX_CASE(V, Ext, Type, Z256, kz ) \
2048 MOVX_CASE(V, Ext, Type, Z, ) \
2049 MOVX_CASE(V, Ext, Type, Z, k ) \
2050 MOVX_CASE(V, Ext, Type, Z, kz )
2051
2052 CASE_MOVX_RM(SX, BD)
2053 printSignExtend(MI, OutStreamer, 8, 32);
2054 break;
2055 CASE_MOVX_RM(SX, BQ)
2056 printSignExtend(MI, OutStreamer, 8, 64);
2057 break;
2058 CASE_MOVX_RM(SX, BW)
2059 printSignExtend(MI, OutStreamer, 8, 16);
2060 break;
2061 CASE_MOVX_RM(SX, DQ)
2062 printSignExtend(MI, OutStreamer, 32, 64);
2063 break;
2064 CASE_MOVX_RM(SX, WD)
2065 printSignExtend(MI, OutStreamer, 16, 32);
2066 break;
2067 CASE_MOVX_RM(SX, WQ)
2068 printSignExtend(MI, OutStreamer, 16, 64);
2069 break;
2070
2071 CASE_MOVX_RM(ZX, BD)
2072 printZeroExtend(MI, OutStreamer, 8, 32);
2073 break;
2074 CASE_MOVX_RM(ZX, BQ)
2075 printZeroExtend(MI, OutStreamer, 8, 64);
2076 break;
2077 CASE_MOVX_RM(ZX, BW)
2078 printZeroExtend(MI, OutStreamer, 8, 16);
2079 break;
2080 CASE_MOVX_RM(ZX, DQ)
2081 printZeroExtend(MI, OutStreamer, 32, 64);
2082 break;
2083 CASE_MOVX_RM(ZX, WD)
2084 printZeroExtend(MI, OutStreamer, 16, 32);
2085 break;
2086 CASE_MOVX_RM(ZX, WQ)
2087 printZeroExtend(MI, OutStreamer, 16, 64);
2088 break;
2089 }
2090}
2091
2093 // FIXME: Enable feature predicate checks once all the test pass.
2094 // X86_MC::verifyInstructionPredicates(MI->getOpcode(),
2095 // Subtarget->getFeatureBits());
2096
2097 X86MCInstLower MCInstLowering(*MF, *this);
2098 const X86RegisterInfo *RI =
2099 MF->getSubtarget<X86Subtarget>().getRegisterInfo();
2100
2101 if (MI->getOpcode() == X86::OR64rm) {
2102 for (auto &Opd : MI->operands()) {
2103 if (Opd.isSymbol() && StringRef(Opd.getSymbolName()) ==
2104 "swift_async_extendedFramePointerFlags") {
2105 ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags = true;
2106 }
2107 }
2108 }
2109
2110 // Add comments for values loaded from constant pool.
2111 if (OutStreamer->isVerboseAsm())
2113
2114 // Add a comment about EVEX compression
2116 if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_LEGACY)
2117 OutStreamer->AddComment("EVEX TO LEGACY Compression ", false);
2118 else if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_VEX)
2119 OutStreamer->AddComment("EVEX TO VEX Compression ", false);
2120 else if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_EVEX)
2121 OutStreamer->AddComment("EVEX TO EVEX Compression ", false);
2122 }
2123
2124 switch (MI->getOpcode()) {
2125 case TargetOpcode::DBG_VALUE:
2126 llvm_unreachable("Should be handled target independently");
2127
2128 case X86::EH_RETURN:
2129 case X86::EH_RETURN64: {
2130 // Lower these as normal, but add some comments.
2131 Register Reg = MI->getOperand(0).getReg();
2132 OutStreamer->AddComment(StringRef("eh_return, addr: %") +
2134 break;
2135 }
2136 case X86::CLEANUPRET: {
2137 // Lower these as normal, but add some comments.
2138 OutStreamer->AddComment("CLEANUPRET");
2139 break;
2140 }
2141
2142 case X86::CATCHRET: {
2143 // Lower these as normal, but add some comments.
2144 OutStreamer->AddComment("CATCHRET");
2145 break;
2146 }
2147
2148 case X86::ENDBR32:
2149 case X86::ENDBR64: {
2150 // CurrentPatchableFunctionEntrySym can be CurrentFnBegin only for
2151 // -fpatchable-function-entry=N,0. The entry MBB is guaranteed to be
2152 // non-empty. If MI is the initial ENDBR, place the
2153 // __patchable_function_entries label after ENDBR.
2156 MI == &MF->front().front()) {
2157 MCInst Inst;
2158 MCInstLowering.Lower(MI, Inst);
2159 EmitAndCountInstruction(Inst);
2162 return;
2163 }
2164 break;
2165 }
2166
2167 case X86::TAILJMPd64:
2168 if (IndCSPrefix && MI->hasRegisterImplicitUseOperand(X86::R11))
2169 EmitAndCountInstruction(MCInstBuilder(X86::CS_PREFIX));
2170 [[fallthrough]];
2171 case X86::TAILJMPr:
2172 case X86::TAILJMPm:
2173 case X86::TAILJMPd:
2174 case X86::TAILJMPd_CC:
2175 case X86::TAILJMPr64:
2176 case X86::TAILJMPm64:
2177 case X86::TAILJMPd64_CC:
2178 case X86::TAILJMPr64_REX:
2179 case X86::TAILJMPm64_REX:
2180 // Lower these as normal, but add some comments.
2181 OutStreamer->AddComment("TAILCALL");
2182 break;
2183
2184 case X86::TLS_addr32:
2185 case X86::TLS_addr64:
2186 case X86::TLS_addrX32:
2187 case X86::TLS_base_addr32:
2188 case X86::TLS_base_addr64:
2189 case X86::TLS_base_addrX32:
2190 case X86::TLS_desc32:
2191 case X86::TLS_desc64:
2192 return LowerTlsAddr(MCInstLowering, *MI);
2193
2194 case X86::MOVPC32r: {
2195 // This is a pseudo op for a two instruction sequence with a label, which
2196 // looks like:
2197 // call "L1$pb"
2198 // "L1$pb":
2199 // popl %esi
2200
2201 // Emit the call.
2202 MCSymbol *PICBase = MF->getPICBaseSymbol();
2203 // FIXME: We would like an efficient form for this, so we don't have to do a
2204 // lot of extra uniquing.
2205 EmitAndCountInstruction(
2206 MCInstBuilder(X86::CALLpcrel32)
2207 .addExpr(MCSymbolRefExpr::create(PICBase, OutContext)));
2208
2209 const X86FrameLowering *FrameLowering =
2210 MF->getSubtarget<X86Subtarget>().getFrameLowering();
2211 bool hasFP = FrameLowering->hasFP(*MF);
2212
2213 // TODO: This is needed only if we require precise CFA.
2214 bool HasActiveDwarfFrame = OutStreamer->getNumFrameInfos() &&
2215 !OutStreamer->getDwarfFrameInfos().back().End;
2216
2217 int stackGrowth = -RI->getSlotSize();
2218
2219 if (HasActiveDwarfFrame && !hasFP) {
2220 OutStreamer->emitCFIAdjustCfaOffset(-stackGrowth);
2221 MF->getInfo<X86MachineFunctionInfo>()->setHasCFIAdjustCfa(true);
2222 }
2223
2224 // Emit the label.
2225 OutStreamer->emitLabel(PICBase);
2226
2227 // popl $reg
2228 EmitAndCountInstruction(
2229 MCInstBuilder(X86::POP32r).addReg(MI->getOperand(0).getReg()));
2230
2231 if (HasActiveDwarfFrame && !hasFP) {
2232 OutStreamer->emitCFIAdjustCfaOffset(stackGrowth);
2233 }
2234 return;
2235 }
2236
2237 case X86::ADD32ri: {
2238 // Lower the MO_GOT_ABSOLUTE_ADDRESS form of ADD32ri.
2239 if (MI->getOperand(2).getTargetFlags() != X86II::MO_GOT_ABSOLUTE_ADDRESS)
2240 break;
2241
2242 // Okay, we have something like:
2243 // EAX = ADD32ri EAX, MO_GOT_ABSOLUTE_ADDRESS(@MYGLOBAL)
2244
2245 // For this, we want to print something like:
2246 // MYGLOBAL + (. - PICBASE)
2247 // However, we can't generate a ".", so just emit a new label here and refer
2248 // to it.
2250 OutStreamer->emitLabel(DotSym);
2251
2252 // Now that we have emitted the label, lower the complex operand expression.
2253 MCSymbol *OpSym = MCInstLowering.GetSymbolFromOperand(MI->getOperand(2));
2254
2255 const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
2256 const MCExpr *PICBase =
2258 DotExpr = MCBinaryExpr::createSub(DotExpr, PICBase, OutContext);
2259
2260 DotExpr = MCBinaryExpr::createAdd(
2262
2263 EmitAndCountInstruction(MCInstBuilder(X86::ADD32ri)
2264 .addReg(MI->getOperand(0).getReg())
2265 .addReg(MI->getOperand(1).getReg())
2266 .addExpr(DotExpr));
2267 return;
2268 }
2269 case TargetOpcode::STATEPOINT:
2270 return LowerSTATEPOINT(*MI, MCInstLowering);
2271
2272 case TargetOpcode::FAULTING_OP:
2273 return LowerFAULTING_OP(*MI, MCInstLowering);
2274
2275 case TargetOpcode::FENTRY_CALL:
2276 return LowerFENTRY_CALL(*MI, MCInstLowering);
2277
2278 case TargetOpcode::PATCHABLE_OP:
2279 return LowerPATCHABLE_OP(*MI, MCInstLowering);
2280
2281 case TargetOpcode::STACKMAP:
2282 return LowerSTACKMAP(*MI);
2283
2284 case TargetOpcode::PATCHPOINT:
2285 return LowerPATCHPOINT(*MI, MCInstLowering);
2286
2287 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
2288 return LowerPATCHABLE_FUNCTION_ENTER(*MI, MCInstLowering);
2289
2290 case TargetOpcode::PATCHABLE_RET:
2291 return LowerPATCHABLE_RET(*MI, MCInstLowering);
2292
2293 case TargetOpcode::PATCHABLE_TAIL_CALL:
2294 return LowerPATCHABLE_TAIL_CALL(*MI, MCInstLowering);
2295
2296 case TargetOpcode::PATCHABLE_EVENT_CALL:
2297 return LowerPATCHABLE_EVENT_CALL(*MI, MCInstLowering);
2298
2299 case TargetOpcode::PATCHABLE_TYPED_EVENT_CALL:
2300 return LowerPATCHABLE_TYPED_EVENT_CALL(*MI, MCInstLowering);
2301
2302 case X86::MORESTACK_RET:
2303 EmitAndCountInstruction(MCInstBuilder(getRetOpcode(*Subtarget)));
2304 return;
2305
2306 case X86::KCFI_CHECK:
2307 return LowerKCFI_CHECK(*MI);
2308
2309 case X86::ASAN_CHECK_MEMACCESS:
2310 return LowerASAN_CHECK_MEMACCESS(*MI);
2311
2312 case X86::MORESTACK_RET_RESTORE_R10:
2313 // Return, then restore R10.
2314 EmitAndCountInstruction(MCInstBuilder(getRetOpcode(*Subtarget)));
2315 EmitAndCountInstruction(
2316 MCInstBuilder(X86::MOV64rr).addReg(X86::R10).addReg(X86::RAX));
2317 return;
2318
2319 case X86::SEH_PushReg:
2320 case X86::SEH_SaveReg:
2321 case X86::SEH_SaveXMM:
2322 case X86::SEH_StackAlloc:
2323 case X86::SEH_StackAlign:
2324 case X86::SEH_SetFrame:
2325 case X86::SEH_PushFrame:
2326 case X86::SEH_EndPrologue:
2327 EmitSEHInstruction(MI);
2328 return;
2329
2330 case X86::SEH_Epilogue: {
2331 assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
2333 // Check if preceded by a call and emit nop if so.
2334 for (MBBI = PrevCrossBBInst(MBBI);
2337 // Pseudo instructions that aren't a call are assumed to not emit any
2338 // code. If they do, we worst case generate unnecessary noops after a
2339 // call.
2340 if (MBBI->isCall() || !MBBI->isPseudo()) {
2341 if (MBBI->isCall())
2342 EmitAndCountInstruction(MCInstBuilder(X86::NOOP));
2343 break;
2344 }
2345 }
2346 return;
2347 }
2348 case X86::UBSAN_UD1:
2349 EmitAndCountInstruction(MCInstBuilder(X86::UD1Lm)
2350 .addReg(X86::EAX)
2351 .addReg(X86::EAX)
2352 .addImm(1)
2353 .addReg(X86::NoRegister)
2354 .addImm(MI->getOperand(0).getImm())
2355 .addReg(X86::NoRegister));
2356 return;
2357 case X86::CALL64pcrel32:
2358 if (IndCSPrefix && MI->hasRegisterImplicitUseOperand(X86::R11))
2359 EmitAndCountInstruction(MCInstBuilder(X86::CS_PREFIX));
2360 break;
2361 }
2362
2363 MCInst TmpInst;
2364 MCInstLowering.Lower(MI, TmpInst);
2365
2366 // Stackmap shadows cannot include branch targets, so we can count the bytes
2367 // in a call towards the shadow, but must ensure that the no thread returns
2368 // in to the stackmap shadow. The only way to achieve this is if the call
2369 // is at the end of the shadow.
2370 if (MI->isCall()) {
2371 // Count then size of the call towards the shadow
2372 SMShadowTracker.count(TmpInst, getSubtargetInfo(), CodeEmitter.get());
2373 // Then flush the shadow so that we fill with nops before the call, not
2374 // after it.
2375 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
2376 // Then emit the call
2377 OutStreamer->emitInstruction(TmpInst, getSubtargetInfo());
2378 return;
2379 }
2380
2381 EmitAndCountInstruction(TmpInst);
2382}
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
static MCSymbol * GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP)
const char LLVMTargetMachineRef TM
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file defines the SmallString class.
static MCOperand LowerSymbolOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
This file contains some functions that are useful when dealing with strings.
static void printShuffleMask(raw_ostream &CS, StringRef Src1Name, StringRef Src2Name, ArrayRef< int > Mask)
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 convertTailJumpOpcode(unsigned Opcode)
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)
#define MASK_AVX512_CASE(Instr)
static void addConstantComments(const MachineInstr *MI, MCStreamer &OutStreamer)
#define CASE_256_MOV_RM()
static MachineBasicBlock::const_iterator PrevCrossBBInst(MachineBasicBlock::const_iterator MBBI)
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)
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)
#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
Definition: APFloat.h:1325
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:957
Class for arbitrary precision integers.
Definition: APInt.h:76
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:981
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1491
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1439
unsigned getNumWords() const
Get the number of words.
Definition: APInt.h:1446
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:954
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:547
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:700
MCSymbol * CurrentFnBegin
Definition: AsmPrinter.h:200
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:87
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
void emitKCFITrapEntry(const MachineFunction &MF, const MCSymbol *Symbol)
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:102
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
Definition: AsmPrinter.cpp:704
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:105
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:94
MCSymbol * createTempSymbol(const Twine &Name) const
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:389
MCSymbol * CurrentPatchableFunctionEntrySym
The symbol for the entry in __patchable_function_entires.
Definition: AsmPrinter.h:117
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:695
StackMaps SM
Definition: AsmPrinter.h:210
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.
Definition: AsmPrinter.cpp:413
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:349
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Register getReg() const
void recordFaultingOp(FaultKind FaultTy, const MCSymbol *FaultingLabel, const MCSymbol *HandlerLabel)
Definition: FaultMaps.cpp:28
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:701
bool hasInternalLinkage() const
Definition: GlobalValue.h:526
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:536
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:621
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
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 const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:81
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:322
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:201
const MCTargetOptions * getTargetOptions() const
Definition: MCContext.h:461
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
Definition: MCInstBuilder.h:37
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Definition: MCInstBuilder.h:61
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
unsigned getNumOperands() const
Definition: MCInst.h:208
unsigned getOpcode() const
Definition: MCInst.h:198
iterator insert(iterator I, const MCOperand &Op)
Definition: MCInst.h:224
void setFlags(unsigned F)
Definition: MCInst.h:200
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
iterator begin()
Definition: MCInst.h:219
void setOpcode(unsigned Op)
Definition: MCInst.h:197
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:69
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
Definition: MCStreamer.h:359
virtual void emitRawComment(const Twine &T, bool TabPrefix=true)
Print T and prefix it with the comment string (normally #) and optionally a tab.
Definition: MCStreamer.cpp:121
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:308
bool getAllowAutoPadding() const
Definition: MCStreamer.h:309
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:397
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
MachineInstrBundleIterator< const MachineInstr > const_iterator
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MCSymbol * getPICBaseSymbol() const
getPICBaseSymbol - Return a function-local symbol to represent the PIC base.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
Representation of each machine instruction.
Definition: MachineInstr.h:69
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:662
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:556
MachineModuleInfoCOFF - This is a MachineModuleInfoImpl implementation for COFF targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
const Module * getModule() const
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isImplicit() 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.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:120
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
Definition: Module.cpp:690
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:130
MI-level patchpoint operands.
Definition: StackMaps.h:76
PointerIntPair - This class implements a pair of a pointer and small integer.
PointerTy getPointer() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
size_t size() const
Definition: SmallVector.h:91
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
void recordStatepoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a statepoint instruction.
Definition: StackMaps.cpp:569
void recordPatchPoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
Definition: StackMaps.cpp:548
void recordStackMap(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
Definition: StackMaps.cpp:538
MI-level Statepoint operands.
Definition: StackMaps.h:158
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:466
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
const Triple & getTargetTriple() const
TargetOptions Options
const MCRegisterInfo * getMCRegisterInfo() const
MCTargetOptions MCOptions
Machine level options.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isUEFI() const
Tests whether the OS is UEFI.
Definition: Triple.h:603
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:703
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:143
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:228
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static const char * getRegisterName(MCRegister Reg)
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
const X86Subtarget & getSubtarget() const
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
unsigned getSlotSize() const
bool isTargetWindowsMSVC() const
Definition: X86Subtarget.h:313
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
Definition: X86Subtarget.h:185
bool useIndirectThunkCalls() const
Definition: X86Subtarget.h:232
X86 target streamer implementing x86-only assembly directives.
virtual bool emitFPOPushReg(unsigned Reg, SMLoc L={})
virtual bool emitFPOSetFrame(unsigned Reg, SMLoc L={})
virtual bool emitFPOEndPrologue(SMLoc L={})
virtual bool emitFPOStackAlign(unsigned Align, 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.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:660
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:678
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Reg
All possible values of the reg field in the ModR/M byte.
bool isKMergeMasked(uint64_t TSFlags)
Definition: X86BaseInfo.h:1329
bool isX86_64ExtendedReg(unsigned RegNo)
Definition: X86BaseInfo.h:1203
@ MO_TLSLD
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:425
@ MO_GOTPCREL_NORELAX
MO_GOTPCREL_NORELAX - Same as MO_GOTPCREL except that R_X86_64_GOTPCREL relocations are guaranteed to...
Definition: X86BaseInfo.h:405
@ MO_GOTOFF
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
Definition: X86BaseInfo.h:395
@ MO_DARWIN_NONLAZY_PIC_BASE
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
Definition: X86BaseInfo.h:482
@ MO_GOT_ABSOLUTE_ADDRESS
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [.
Definition: X86BaseInfo.h:381
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
Definition: X86BaseInfo.h:502
@ MO_NTPOFF
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
Definition: X86BaseInfo.h:464
@ MO_DARWIN_NONLAZY
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:478
@ MO_INDNTPOFF
MO_INDNTPOFF - On a symbol operand this indicates that the immediate is the absolute address of the G...
Definition: X86BaseInfo.h:446
@ MO_GOTNTPOFF
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
Definition: X86BaseInfo.h:470
@ MO_TPOFF
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
Definition: X86BaseInfo.h:452
@ MO_TLVP_PIC_BASE
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
Definition: X86BaseInfo.h:490
@ MO_GOT
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
Definition: X86BaseInfo.h:390
@ MO_ABS8
MO_ABS8 - On a symbol operand this indicates that the symbol is known to be an absolute symbol in ran...
Definition: X86BaseInfo.h:498
@ MO_PLT
MO_PLT - On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol n...
Definition: X86BaseInfo.h:410
@ MO_TLSGD
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:417
@ MO_NO_FLAG
MO_NO_FLAG - No flag for the operand.
Definition: X86BaseInfo.h:377
@ MO_TLVP
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
Definition: X86BaseInfo.h:486
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
Definition: X86BaseInfo.h:474
@ MO_GOTTPOFF
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
Definition: X86BaseInfo.h:439
@ MO_SECREL
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
Definition: X86BaseInfo.h:494
@ MO_DTPOFF
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:458
@ MO_PIC_BASE_OFFSET
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
Definition: X86BaseInfo.h:385
@ MO_TLSLDM
MO_TLSLDM - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:433
@ MO_GOTPCREL
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
Definition: X86BaseInfo.h:401
bool isKMasked(uint64_t TSFlags)
Definition: X86BaseInfo.h:1324
bool optimizeToFixedRegisterOrShortImmediateForm(MCInst &MI)
bool optimizeMOV(MCInst &MI, bool In64BitMode)
Simplify things like MOV32rm to MOV32o32a.
@ AddrSegmentReg
Definition: X86BaseInfo.h:34
@ AddrNumOperands
Definition: X86BaseInfo.h:36
bool optimizeMOVSX(MCInst &MI)
bool optimizeVPCMPWithImmediateOneOrSix(MCInst &MI)
bool optimizeShiftRotateWithImmediateOne(MCInst &MI)
bool optimizeInstFromVEX3ToVEX2(MCInst &MI, const MCInstrDesc &Desc)
@ IP_HAS_AD_SIZE
Definition: X86BaseInfo.h:54
@ IP_HAS_REPEAT
Definition: X86BaseInfo.h:56
const Constant * getConstantFromPool(const MachineInstr &MI, unsigned OpNo)
Find any constant pool entry associated with a specific instruction operand.
@ AC_EVEX_2_EVEX
Definition: X86InstrInfo.h:43
@ AC_EVEX_2_LEGACY
Definition: X86InstrInfo.h:39
bool optimizeINCDEC(MCInst &MI, bool In64BitMode)
unsigned getVectorRegisterWidth(const MCOperandInfo &Info)
Get the width of the vector register operand.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
NodeAddr< CodeNode * > Code
Definition: RDFGraph.h:388
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Definition: STLExtras.h:329
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.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
@ SM_SentinelUndef
@ SM_SentinelZero
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.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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.
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize, bool IsKasan, uint64_t *ShadowBase, int *MappingScale, bool *OrShadowOffset)
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.
#define N
A RAII helper which defines a region of instructions which can't have padding added between them for ...
void changeAndComment(bool b)
NoAutoPaddingScope(MCStreamer &OS)
const bool OldAllowAutoPadding
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39