LLVM 23.0.0git
X86AsmPrinter.cpp
Go to the documentation of this file.
1//===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
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 a printer that converts from our internal representation
10// of machine-dependent LLVM code to X86 machine code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "X86AsmPrinter.h"
20#include "X86.h"
21#include "X86InstrInfo.h"
23#include "X86Subtarget.h"
24#include "llvm-c/Visibility.h"
33#include "llvm/IR/InlineAsm.h"
35#include "llvm/IR/Mangler.h"
36#include "llvm/IR/Module.h"
37#include "llvm/IR/Type.h"
38#include "llvm/MC/MCAsmInfo.h"
40#include "llvm/MC/MCContext.h"
41#include "llvm/MC/MCExpr.h"
42#include "llvm/MC/MCInst.h"
47#include "llvm/MC/MCStreamer.h"
48#include "llvm/MC/MCSymbol.h"
50#include "llvm/Support/Debug.h"
53
54using namespace llvm;
55
57 std::unique_ptr<MCStreamer> Streamer)
58 : AsmPrinter(TM, std::move(Streamer), ID), FM(*this) {
59 GetPSI = [this](Module &M) -> ProfileSummaryInfo * {
61 return &PSIW->getPSI();
62 return nullptr;
63 };
64 GetSDPI = [this](Module &M) -> StaticDataProfileInfo * {
65 if (auto *SDPIW =
67 return &SDPIW->getStaticDataProfileInfo();
68 return nullptr;
69 };
70}
71
72//===----------------------------------------------------------------------===//
73// Primitive Helper Functions.
74//===----------------------------------------------------------------------===//
75
76/// runOnMachineFunction - Emit the function body.
77///
79 PSI = GetPSI(*MF.getFunction().getParent());
80 SDPI = GetSDPI(*MF.getFunction().getParent());
81
82 Subtarget = &MF.getSubtarget<X86Subtarget>();
83
84 SMShadowTracker.startFunction(MF);
85 CodeEmitter.reset(TM.getTarget().createMCCodeEmitter(
86 *Subtarget->getInstrInfo(), MF.getContext()));
87
88 const Module *M = MF.getFunction().getParent();
89 EmitFPOData = Subtarget->isTargetWin32() && M->getCodeViewFlag();
90
91 IndCSPrefix = M->getModuleFlag("indirect_branch_cs_prefix");
92
94
95 if (Subtarget->isTargetCOFF()) {
96 bool Local = MF.getFunction().hasLocalLinkage();
97 OutStreamer->beginCOFFSymbolDef(CurrentFnSym);
98 OutStreamer->emitCOFFSymbolStorageClass(
102 OutStreamer->endCOFFSymbolDef();
103 }
104
105 // Emit the rest of the function body.
107
108 // Emit the XRay table for this function.
110
111 EmitFPOData = false;
112
113 IndCSPrefix = false;
114
115 // We didn't modify anything.
116 return false;
117}
118
120 if (EmitFPOData) {
121 auto *XTS =
122 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
123 XTS->emitFPOProc(
126 }
127}
128
130 if (EmitFPOData) {
131 auto *XTS =
132 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
133 XTS->emitFPOEndProc();
134 }
135}
136
137uint32_t X86AsmPrinter::MaskKCFIType(uint32_t Value) {
138 // If the type hash matches an invalid pattern, mask the value.
139 const uint32_t InvalidValues[] = {
140 0xFA1E0FF3, /* ENDBR64 */
141 0xFB1E0FF3, /* ENDBR32 */
142 };
143 for (uint32_t N : InvalidValues) {
144 // LowerKCFI_CHECK emits -Value for indirect call checks, so we must also
145 // mask that. Note that -(Value + 1) == ~Value.
146 if (N == Value || -N == Value)
147 return Value + 1;
148 }
149 return Value;
150}
151
152void X86AsmPrinter::EmitKCFITypePadding(const MachineFunction &MF,
153 bool HasType) {
154 // Keep the function entry aligned, taking patchable-function-prefix into
155 // account if set.
156 int64_t PrefixBytes = MF.getFunction().getFnAttributeAsParsedInteger(
157 "patchable-function-prefix");
158
159 // Also take the type identifier into account if we're emitting
160 // one. Otherwise, just pad with nops. The X86::MOV32ri instruction emitted
161 // in X86AsmPrinter::emitKCFITypeId is 5 bytes long.
162 if (HasType)
163 PrefixBytes += 5;
164
165 emitNops(offsetToAlignment(PrefixBytes, MF.getPreferredAlignment()));
166}
167
168/// emitKCFITypeId - Emit the KCFI type information in architecture specific
169/// format.
171 const Function &F = MF.getFunction();
172 if (!F.getParent()->getModuleFlag("kcfi"))
173 return;
174
175 ConstantInt *Type = nullptr;
176 if (const MDNode *MD = F.getMetadata(LLVMContext::MD_kcfi_type))
177 Type = mdconst::extract<ConstantInt>(MD->getOperand(0));
178
179 // If we don't have a type to emit, just emit padding if needed to maintain
180 // the same alignment for all functions.
181 if (!Type) {
182 EmitKCFITypePadding(MF, /*HasType=*/false);
183 return;
184 }
185
186 // Emit a function symbol for the type data to avoid unreachable instruction
187 // warnings from binary validation tools, and use the same linkage as the
188 // parent function. Note that using local linkage would result in duplicate
189 // symbols for weak parent functions.
190 MCSymbol *FnSym = OutContext.getOrCreateSymbol("__cfi_" + MF.getName());
191 emitLinkage(&MF.getFunction(), FnSym);
192 if (MAI.hasDotTypeDotSizeDirective())
193 OutStreamer->emitSymbolAttribute(FnSym, MCSA_ELF_TypeFunction);
194 OutStreamer->emitLabel(FnSym);
195
196 // Embed the type hash in the X86::MOV32ri instruction to avoid special
197 // casing object file parsers.
198 EmitKCFITypePadding(MF);
199 unsigned DestReg = X86::EAX;
200
201 if (F.getParent()->getModuleFlag("kcfi-arity")) {
202 // The ArityToRegMap assumes the 64-bit SysV ABI.
203 [[maybe_unused]] const auto &Triple = MF.getTarget().getTargetTriple();
205
206 // Determine the function's arity (i.e., the number of arguments) at the ABI
207 // level by counting the number of parameters that are passed
208 // as registers, such as pointers and 64-bit (or smaller) integers. The
209 // Linux x86-64 ABI allows up to 6 integer parameters to be passed in GPRs.
210 // Additional parameters or parameters larger than 64 bits may be passed on
211 // the stack, in which case the arity is denoted as 7. Floating-point
212 // arguments passed in XMM0-XMM7 are not counted toward arity because
213 // floating-point values are not relevant to enforcing kCFI at this time.
214 const unsigned ArityToRegMap[8] = {X86::EAX, X86::ECX, X86::EDX, X86::EBX,
215 X86::ESP, X86::EBP, X86::ESI, X86::EDI};
216 int Arity;
217 if (MF.getInfo<X86MachineFunctionInfo>()->getArgumentStackSize() > 0) {
218 Arity = 7;
219 } else {
220 Arity = 0;
221 for (const auto &LI : MF.getRegInfo().liveins()) {
222 auto Reg = LI.first;
223 if (X86::GR8RegClass.contains(Reg) || X86::GR16RegClass.contains(Reg) ||
224 X86::GR32RegClass.contains(Reg) ||
225 X86::GR64RegClass.contains(Reg)) {
226 ++Arity;
227 }
228 }
229 }
230 DestReg = ArityToRegMap[Arity];
231 }
232
233 EmitAndCountInstruction(MCInstBuilder(X86::MOV32ri)
234 .addReg(DestReg)
235 .addImm(MaskKCFIType(Type->getZExtValue())));
236
237 if (MAI.hasDotTypeDotSizeDirective()) {
238 MCSymbol *EndSym = OutContext.createTempSymbol("cfi_func_end");
239 OutStreamer->emitLabel(EndSym);
240
241 const MCExpr *SizeExp = MCBinaryExpr::createSub(
244 OutStreamer->emitELFSize(FnSym, SizeExp);
245 }
246}
247
248/// PrintSymbolOperand - Print a raw symbol reference operand. This handles
249/// jump tables, constant pools, global address and external symbols, all of
250/// which print to a label with various suffixes for relocation types etc.
251void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
252 raw_ostream &O) {
253 switch (MO.getType()) {
254 default: llvm_unreachable("unknown symbol type!");
256 GetCPISymbol(MO.getIndex())->print(O, MAI);
257 printOffset(MO.getOffset(), O);
258 break;
260 const GlobalValue *GV = MO.getGlobal();
261
262 MCSymbol *GVSym;
265 GVSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
266 else
267 GVSym = getSymbolPreferLocal(*GV);
268
269 // Handle dllimport linkage.
271 GVSym = OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
272 else if (MO.getTargetFlags() == X86II::MO_COFFSTUB)
273 GVSym =
274 OutContext.getOrCreateSymbol(Twine(".refptr.") + GVSym->getName());
275
278 MCSymbol *Sym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
280 MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
281 if (!StubSym.getPointer())
283 !GV->hasInternalLinkage());
284 }
285
286 // If the name begins with a dollar-sign, enclose it in parens. We do this
287 // to avoid having it look like an integer immediate to the assembler.
288 if (GVSym->getName()[0] != '$')
289 GVSym->print(O, MAI);
290 else {
291 O << '(';
292 GVSym->print(O, MAI);
293 O << ')';
294 }
295 printOffset(MO.getOffset(), O);
296 break;
297 }
298 }
299
300 switch (MO.getTargetFlags()) {
301 default:
302 llvm_unreachable("Unknown target flag on GV operand");
303 case X86II::MO_NO_FLAG: // No flag.
304 break;
308 // These affect the name of the symbol, not any suffix.
309 break;
311 O << " + [.-";
312 MF->getPICBaseSymbol()->print(O, MAI);
313 O << ']';
314 break;
317 O << '-';
318 MF->getPICBaseSymbol()->print(O, MAI);
319 break;
320 case X86II::MO_TLSGD: O << "@TLSGD"; break;
321 case X86II::MO_TLSLD: O << "@TLSLD"; break;
322 case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
323 case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
324 case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
325 case X86II::MO_TPOFF: O << "@TPOFF"; break;
326 case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
327 case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
328 case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
329 case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
330 case X86II::MO_GOTPCREL_NORELAX: O << "@GOTPCREL_NORELAX"; break;
331 case X86II::MO_GOT: O << "@GOT"; break;
332 case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
333 case X86II::MO_PLT: O << "@PLT"; break;
334 case X86II::MO_TLVP: O << "@TLVP"; break;
336 O << "@TLVP" << '-';
337 MF->getPICBaseSymbol()->print(O, MAI);
338 break;
339 case X86II::MO_SECREL: O << "@SECREL32"; break;
340 }
341}
342
343void X86AsmPrinter::PrintOperand(const MachineInstr *MI, unsigned OpNo,
344 raw_ostream &O) {
345 const MachineOperand &MO = MI->getOperand(OpNo);
346 const bool IsATT = MI->getInlineAsmDialect() == InlineAsm::AD_ATT;
347 switch (MO.getType()) {
348 default: llvm_unreachable("unknown operand type!");
350 if (IsATT)
351 O << '%';
353 return;
354 }
355
357 if (IsATT)
358 O << '$';
359 O << MO.getImm();
360 return;
361
364 switch (MI->getInlineAsmDialect()) {
366 O << '$';
367 break;
369 O << "offset ";
370 break;
371 }
372 PrintSymbolOperand(MO, O);
373 break;
374 }
377 Sym->print(O, MAI);
378 break;
379 }
380 }
381}
382
383/// PrintModifiedOperand - Print subregisters based on supplied modifier,
384/// deferring to PrintOperand() if no modifier was supplied or if operand is not
385/// a register.
386void X86AsmPrinter::PrintModifiedOperand(const MachineInstr *MI, unsigned OpNo,
387 raw_ostream &O, StringRef Modifier) {
388 const MachineOperand &MO = MI->getOperand(OpNo);
389 if (Modifier.empty() || !MO.isReg())
390 return PrintOperand(MI, OpNo, O);
391 if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
392 O << '%';
393 Register Reg = MO.getReg();
394 if (Modifier.consume_front("subreg")) {
395 unsigned Size = (Modifier == "64") ? 64
396 : (Modifier == "32") ? 32
397 : (Modifier == "16") ? 16
398 : 8;
400 }
402}
403
404/// PrintPCRelImm - This is used to print an immediate value that ends up
405/// being encoded as a pc-relative value. These print slightly differently, for
406/// example, a $ is not emitted.
407void X86AsmPrinter::PrintPCRelImm(const MachineInstr *MI, unsigned OpNo,
408 raw_ostream &O) {
409 const MachineOperand &MO = MI->getOperand(OpNo);
410 switch (MO.getType()) {
411 default: llvm_unreachable("Unknown pcrel immediate operand");
413 // pc-relativeness was handled when computing the value in the reg.
414 PrintOperand(MI, OpNo, O);
415 return;
417 O << MO.getImm();
418 return;
420 PrintSymbolOperand(MO, O);
421 return;
422 }
423}
424
425void X86AsmPrinter::PrintLeaMemReference(const MachineInstr *MI, unsigned OpNo,
426 raw_ostream &O, StringRef Modifier) {
427 const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
428 const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
429 const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
430
431 // If we really don't want to print out (rip), don't.
432 bool HasBaseReg = BaseReg.getReg() != 0;
433 if (HasBaseReg && Modifier == "no-rip" && BaseReg.getReg() == X86::RIP)
434 HasBaseReg = false;
435
436 // HasParenPart - True if we will print out the () part of the mem ref.
437 bool HasParenPart = IndexReg.getReg() || HasBaseReg;
438
439 switch (DispSpec.getType()) {
440 default:
441 llvm_unreachable("unknown operand type!");
443 int DispVal = DispSpec.getImm();
444 if (DispVal || !HasParenPart)
445 O << DispVal;
446 break;
447 }
450 PrintSymbolOperand(DispSpec, O);
451 break;
452 }
453
454 if (Modifier == "H")
455 O << "+8";
456
457 if (HasParenPart) {
458 assert(IndexReg.getReg() != X86::ESP &&
459 "X86 doesn't allow scaling by ESP");
460
461 O << '(';
462 if (HasBaseReg)
463 PrintModifiedOperand(MI, OpNo + X86::AddrBaseReg, O, Modifier);
464
465 if (IndexReg.getReg()) {
466 O << ',';
467 PrintModifiedOperand(MI, OpNo + X86::AddrIndexReg, O, Modifier);
468 unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
469 if (ScaleVal != 1)
470 O << ',' << ScaleVal;
471 }
472 O << ')';
473 }
474}
475
476static bool isSimpleReturn(const MachineInstr &MI) {
477 // We exclude all tail calls here which set both isReturn and isCall.
478 return MI.getDesc().isReturn() && !MI.getDesc().isCall();
479}
480
482 unsigned Opc = MI.getOpcode();
483 return MI.getDesc().isIndirectBranch() /*Make below code in a good shape*/ ||
484 Opc == X86::TAILJMPr || Opc == X86::TAILJMPm ||
485 Opc == X86::TAILJMPr64 || Opc == X86::TAILJMPm64 ||
486 Opc == X86::TCRETURNri || Opc == X86::TCRETURN_WIN64ri ||
487 Opc == X86::TCRETURN_HIPE32ri || Opc == X86::TCRETURNmi ||
488 Opc == X86::TCRETURN_WINmi64 || Opc == X86::TCRETURNri64 ||
489 Opc == X86::TCRETURNmi64 || Opc == X86::TCRETURNri64_ImpCall ||
490 Opc == X86::TAILJMPr64_REX || Opc == X86::TAILJMPm64_REX;
491}
492
494 if (Subtarget->hardenSlsRet() || Subtarget->hardenSlsIJmp()) {
495 auto I = MBB.getLastNonDebugInstr();
496 if (I != MBB.end()) {
497 if ((Subtarget->hardenSlsRet() && isSimpleReturn(*I)) ||
498 (Subtarget->hardenSlsIJmp() && isIndirectBranchOrTailCall(*I))) {
499 MCInst TmpInst;
500 TmpInst.setOpcode(X86::INT3);
501 EmitToStreamer(*OutStreamer, TmpInst);
502 }
503 }
504 }
505 if (SplitChainedAtEndOfBlock) {
506 OutStreamer->emitWinCFISplitChained();
507 // Splitting into a new unwind info implicitly starts a prolog. We have no
508 // instructions to add to the prolog, so immediately end it.
509 OutStreamer->emitWinCFIEndProlog();
510 SplitChainedAtEndOfBlock = false;
511 }
513 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
514}
515
516void X86AsmPrinter::PrintMemReference(const MachineInstr *MI, unsigned OpNo,
517 raw_ostream &O, StringRef Modifier) {
518 assert(isMem(*MI, OpNo) && "Invalid memory reference!");
519 const MachineOperand &Segment = MI->getOperand(OpNo + X86::AddrSegmentReg);
520 if (Segment.getReg()) {
521 PrintModifiedOperand(MI, OpNo + X86::AddrSegmentReg, O, Modifier);
522 O << ':';
523 }
524 PrintLeaMemReference(MI, OpNo, O, Modifier);
525}
526
527void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
528 unsigned OpNo, raw_ostream &O,
529 StringRef Modifier) {
530 const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
531 unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
532 const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
533 const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
534 const MachineOperand &SegReg = MI->getOperand(OpNo + X86::AddrSegmentReg);
535
536 // If we really don't want to print out (rip), don't.
537 bool HasBaseReg = BaseReg.getReg() != 0;
538 if (HasBaseReg && Modifier == "no-rip" && BaseReg.getReg() == X86::RIP)
539 HasBaseReg = false;
540
541 // If we really just want to print out displacement.
542 if ((DispSpec.isGlobal() || DispSpec.isSymbol()) && Modifier == "disp-only") {
543 HasBaseReg = false;
544 }
545
546 // If this has a segment register, print it.
547 if (SegReg.getReg()) {
548 PrintOperand(MI, OpNo + X86::AddrSegmentReg, O);
549 O << ':';
550 }
551
552 O << '[';
553
554 bool NeedPlus = false;
555 if (HasBaseReg) {
556 PrintOperand(MI, OpNo + X86::AddrBaseReg, O);
557 NeedPlus = true;
558 }
559
560 if (IndexReg.getReg()) {
561 if (NeedPlus) O << " + ";
562 if (ScaleVal != 1)
563 O << ScaleVal << '*';
564 PrintOperand(MI, OpNo + X86::AddrIndexReg, O);
565 NeedPlus = true;
566 }
567
568 if (!DispSpec.isImm()) {
569 if (NeedPlus) O << " + ";
570 // Do not add `offset` operator. Matches the behaviour of
571 // X86IntelInstPrinter::printMemReference.
572 PrintSymbolOperand(DispSpec, O);
573 } else {
574 int64_t DispVal = DispSpec.getImm();
575 if (DispVal || (!IndexReg.getReg() && !HasBaseReg)) {
576 if (NeedPlus) {
577 if (DispVal > 0)
578 O << " + ";
579 else {
580 O << " - ";
581 DispVal = -DispVal;
582 }
583 }
584 O << DispVal;
585 }
586 }
587 O << ']';
588}
589
591 assert(Subtarget);
592 return Subtarget;
593}
594
595void X86AsmPrinter::emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI,
596 MCSymbol *LazyPointer) {
597 // _ifunc:
598 // jmpq *lazy_pointer(%rip)
599
600 OutStreamer->emitInstruction(
601 MCInstBuilder(X86::JMP32m)
602 .addReg(X86::RIP)
603 .addImm(1)
604 .addReg(0)
606 MCSymbolRefExpr::create(LazyPointer, OutContext)))
607 .addReg(0),
608 *Subtarget);
609}
610
611void X86AsmPrinter::emitMachOIFuncStubHelperBody(Module &M,
612 const GlobalIFunc &GI,
613 MCSymbol *LazyPointer) {
614 // _ifunc.stub_helper:
615 // push %rax
616 // push %rdi
617 // push %rsi
618 // push %rdx
619 // push %rcx
620 // push %r8
621 // push %r9
622 // callq foo
623 // movq %rax,lazy_pointer(%rip)
624 // pop %r9
625 // pop %r8
626 // pop %rcx
627 // pop %rdx
628 // pop %rsi
629 // pop %rdi
630 // pop %rax
631 // jmpq *lazy_pointer(%rip)
632
633 for (int Reg :
634 {X86::RAX, X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8, X86::R9})
635 OutStreamer->emitInstruction(MCInstBuilder(X86::PUSH64r).addReg(Reg),
636 *Subtarget);
637
638 OutStreamer->emitInstruction(
639 MCInstBuilder(X86::CALL64pcrel32)
641 *Subtarget);
642
643 OutStreamer->emitInstruction(
644 MCInstBuilder(X86::MOV64mr)
645 .addReg(X86::RIP)
646 .addImm(1)
647 .addReg(0)
649 MCSymbolRefExpr::create(LazyPointer, OutContext)))
650 .addReg(0)
651 .addReg(X86::RAX),
652 *Subtarget);
653
654 for (int Reg :
655 {X86::R9, X86::R8, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RAX})
656 OutStreamer->emitInstruction(MCInstBuilder(X86::POP64r).addReg(Reg),
657 *Subtarget);
658
659 OutStreamer->emitInstruction(
660 MCInstBuilder(X86::JMP32m)
661 .addReg(X86::RIP)
662 .addImm(1)
663 .addReg(0)
665 MCSymbolRefExpr::create(LazyPointer, OutContext)))
666 .addReg(0),
667 *Subtarget);
668}
669
670static bool printAsmMRegister(const X86AsmPrinter &P, const MachineOperand &MO,
671 char Mode, raw_ostream &O) {
672 Register Reg = MO.getReg();
673 bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
674
675 if (!X86::GR8RegClass.contains(Reg) &&
676 !X86::GR16RegClass.contains(Reg) &&
677 !X86::GR32RegClass.contains(Reg) &&
678 !X86::GR64RegClass.contains(Reg))
679 return true;
680
681 switch (Mode) {
682 default: return true; // Unknown mode.
683 case 'b': // Print QImode register
685 break;
686 case 'h': // Print QImode high register
687 Reg = getX86SubSuperRegister(Reg, 8, true);
688 if (!Reg.isValid())
689 return true;
690 break;
691 case 'w': // Print HImode register
693 break;
694 case 'k': // Print SImode register
696 break;
697 case 'V':
698 EmitPercent = false;
699 [[fallthrough]];
700 case 'q':
701 // Print 64-bit register names if 64-bit integer registers are available.
702 // Otherwise, print 32-bit register names.
703 Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
704 break;
705 }
706
707 if (EmitPercent)
708 O << '%';
709
711 return false;
712}
713
714static bool printAsmVRegister(const MachineOperand &MO, char Mode,
715 raw_ostream &O) {
716 Register Reg = MO.getReg();
717 bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
718
719 unsigned Index;
720 if (X86::VR128XRegClass.contains(Reg))
721 Index = Reg - X86::XMM0;
722 else if (X86::VR256XRegClass.contains(Reg))
723 Index = Reg - X86::YMM0;
724 else if (X86::VR512RegClass.contains(Reg))
725 Index = Reg - X86::ZMM0;
726 else
727 return true;
728
729 switch (Mode) {
730 default: // Unknown mode.
731 return true;
732 case 'x': // Print V4SFmode register
733 Reg = X86::XMM0 + Index;
734 break;
735 case 't': // Print V8SFmode register
736 Reg = X86::YMM0 + Index;
737 break;
738 case 'g': // Print V16SFmode register
739 Reg = X86::ZMM0 + Index;
740 break;
741 }
742
743 if (EmitPercent)
744 O << '%';
745
747 return false;
748}
749
750/// PrintAsmOperand - Print out an operand for an inline asm expression.
751///
753 const char *ExtraCode, raw_ostream &O) {
754 // Does this asm operand have a single letter operand modifier?
755 if (ExtraCode && ExtraCode[0]) {
756 if (ExtraCode[1] != 0) return true; // Unknown modifier.
757
758 const MachineOperand &MO = MI->getOperand(OpNo);
759
760 switch (ExtraCode[0]) {
761 default:
762 // See if this is a generic print operand
763 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
764 case 'a': // This is an address. Currently only 'i' and 'r' are expected.
765 switch (MO.getType()) {
766 default:
767 return true;
769 O << MO.getImm();
770 return false;
774 llvm_unreachable("unexpected operand type!");
776 PrintSymbolOperand(MO, O);
777 if (Subtarget->is64Bit())
778 O << "(%rip)";
779 return false;
781 O << '(';
782 PrintOperand(MI, OpNo, O);
783 O << ')';
784 return false;
785 }
786
787 case 'c': // Don't print "$" before a global var name or constant.
788 switch (MO.getType()) {
789 default:
790 PrintOperand(MI, OpNo, O);
791 break;
793 O << MO.getImm();
794 break;
798 llvm_unreachable("unexpected operand type!");
800 PrintSymbolOperand(MO, O);
801 break;
802 }
803 return false;
804
805 case 'A': // Print '*' before a register (it must be a register)
806 if (MO.isReg()) {
807 O << '*';
808 PrintOperand(MI, OpNo, O);
809 return false;
810 }
811 return true;
812
813 case 'b': // Print QImode register
814 case 'h': // Print QImode high register
815 case 'w': // Print HImode register
816 case 'k': // Print SImode register
817 case 'q': // Print DImode register
818 case 'V': // Print native register without '%'
819 if (MO.isReg())
820 return printAsmMRegister(*this, MO, ExtraCode[0], O);
821 PrintOperand(MI, OpNo, O);
822 return false;
823
824 case 'x': // Print V4SFmode register
825 case 't': // Print V8SFmode register
826 case 'g': // Print V16SFmode register
827 if (MO.isReg())
828 return printAsmVRegister(MO, ExtraCode[0], O);
829 PrintOperand(MI, OpNo, O);
830 return false;
831
832 case 'p': {
833 const MachineOperand &MO = MI->getOperand(OpNo);
835 return true;
836 PrintSymbolOperand(MO, O);
837 return false;
838 }
839
840 case 'P': // This is the operand of a call, treat specially.
841 PrintPCRelImm(MI, OpNo, O);
842 return false;
843
844 case 'n': // Negate the immediate or print a '-' before the operand.
845 // Note: this is a temporary solution. It should be handled target
846 // independently as part of the 'MC' work.
847 if (MO.isImm()) {
848 O << -MO.getImm();
849 return false;
850 }
851 O << '-';
852 }
853 }
854
855 PrintOperand(MI, OpNo, O);
856 return false;
857}
858
860 const char *ExtraCode,
861 raw_ostream &O) {
862 if (ExtraCode && ExtraCode[0]) {
863 if (ExtraCode[1] != 0) return true; // Unknown modifier.
864
865 switch (ExtraCode[0]) {
866 default: return true; // Unknown modifier.
867 case 'a': {
868 // Print as address — only valid with 'p' constraint.
869 const InlineAsm::Flag Flags(MI->getOperand(OpNo - 1).getImm());
870 if (Flags.getMemoryConstraintID() != InlineAsm::ConstraintCode::p)
871 return true;
872 break;
873 }
874 case 'b': // Print QImode register
875 case 'h': // Print QImode high register
876 case 'w': // Print HImode register
877 case 'k': // Print SImode register
878 case 'q': // Print SImode register
879 // These only apply to registers, ignore on mem.
880 break;
881 case 'H':
882 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
883 return true; // Unsupported modifier in Intel inline assembly.
884 } else {
885 PrintMemReference(MI, OpNo, O, "H");
886 }
887 return false;
888 // Print memory only with displacement. The Modifer 'P' is used in inline
889 // asm to present a call symbol or a global symbol which can not use base
890 // reg or index reg.
891 case 'P':
892 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
893 PrintIntelMemReference(MI, OpNo, O, "disp-only");
894 } else {
895 PrintMemReference(MI, OpNo, O, "disp-only");
896 }
897 return false;
898 }
899 } else {
900 // Constraint 'p' requires modifier 'a'.
901 const InlineAsm::Flag Flags(MI->getOperand(OpNo - 1).getImm());
902 if (Flags.getMemoryConstraintID() == InlineAsm::ConstraintCode::p)
903 return true;
904 }
905 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
906 PrintIntelMemReference(MI, OpNo, O);
907 } else {
908 PrintMemReference(MI, OpNo, O);
909 }
910 return false;
911}
912
914 const Triple &TT = TM.getTargetTriple();
915
916 if (TT.isOSBinFormatELF()) {
917 // Assemble feature flags that may require creation of a note section.
918 unsigned FeatureFlagsAnd = 0;
919 if (M.getModuleFlag("cf-protection-branch"))
920 FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_IBT;
921 if (M.getModuleFlag("cf-protection-return"))
922 FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_SHSTK;
923
924 if (FeatureFlagsAnd) {
925 // Emit a .note.gnu.property section with the flags.
926 assert((TT.isX86_32() || TT.isX86_64()) &&
927 "CFProtection used on invalid architecture!");
928 MCSection *Cur = OutStreamer->getCurrentSectionOnly();
929 MCSection *Nt = MMI->getContext().getELFSection(
930 ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
931 OutStreamer->switchSection(Nt);
932
933 // Emitting note header.
934 const int WordSize = TT.isX86_64() && !TT.isX32() ? 8 : 4;
935 emitAlignment(WordSize == 4 ? Align(4) : Align(8));
936 OutStreamer->emitIntValue(4, 4 /*size*/); // data size for "GNU\0"
937 OutStreamer->emitIntValue(8 + WordSize, 4 /*size*/); // Elf_Prop size
938 OutStreamer->emitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4 /*size*/);
939 OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
940
941 // Emitting an Elf_Prop for the CET properties.
943 OutStreamer->emitInt32(4); // data size
944 OutStreamer->emitInt32(FeatureFlagsAnd); // data
945 emitAlignment(WordSize == 4 ? Align(4) : Align(8)); // padding
946
947 OutStreamer->switchSection(Cur);
948 }
949 }
950
951 if (TT.isOSBinFormatMachO())
952 OutStreamer->switchSection(getObjFileLowering().getTextSection());
953
954 if (TT.isOSBinFormatCOFF()) {
957
958 if (M.getModuleFlag("import-call-optimization"))
959 EnableImportCallOptimization = true;
960 }
961
962 // TODO: Support prefixed registers for the Intel syntax.
963 const bool IntelSyntax =
964 MAI.getOutputAssemblerDialect() == InlineAsm::AD_Intel;
965 OutStreamer->emitSyntaxDirective(IntelSyntax ? "intel" : "att",
966 IntelSyntax ? "noprefix" : "");
967
968 // If this is not inline asm and we're in 16-bit
969 // mode prefix assembly with .code16.
970 bool is16 = TT.getEnvironment() == Triple::CODE16;
971 if (M.getModuleInlineAsm().empty() && is16) {
972 auto *XTS =
973 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
974 XTS->emitCode16();
975 }
976}
977
978static void
981 // L_foo$stub:
982 OutStreamer.emitLabel(StubLabel);
983 // .indirect_symbol _foo
985
986 if (MCSym.getInt())
987 // External to current translation unit.
988 OutStreamer.emitIntValue(0, 4/*size*/);
989 else
990 // Internal to current translation unit.
991 //
992 // When we place the LSDA into the TEXT section, the type info
993 // pointers need to be indirect and pc-rel. We accomplish this by
994 // using NLPs; however, sometimes the types are local to the file.
995 // We need to fill in the value for the NLP in those cases.
996 OutStreamer.emitValue(
997 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
998 4 /*size*/);
999}
1000
1001static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) {
1002
1003 MachineModuleInfoMachO &MMIMacho =
1005
1006 // Output stubs for dynamically-linked functions.
1008
1009 // Output stubs for external and common global variables.
1010 Stubs = MMIMacho.GetGVStubList();
1011 if (!Stubs.empty()) {
1012 OutStreamer.switchSection(MMI->getContext().getMachOSection(
1013 "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
1015
1016 for (auto &Stub : Stubs)
1017 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
1018
1019 Stubs.clear();
1020 OutStreamer.addBlankLine();
1021 }
1022}
1023
1024/// True if this module is being built for windows/msvc, and uses floating
1025/// point. This is used to emit an undefined reference to _fltused. This is
1026/// needed in Windows kernel or driver contexts to find and prevent code from
1027/// modifying non-GPR registers.
1028///
1029/// TODO: It would be better if this was computed from MIR by looking for
1030/// selected floating-point instructions.
1031static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M) {
1032 // Only needed for MSVC
1033 if (!TT.isWindowsMSVCEnvironment())
1034 return false;
1035
1036 for (const Function &F : M) {
1037 for (const Instruction &I : instructions(F)) {
1038 if (I.getType()->isFloatingPointTy())
1039 return true;
1040
1041 for (const auto &Op : I.operands()) {
1042 if (Op->getType()->isFloatingPointTy())
1043 return true;
1044 }
1045 }
1046 }
1047
1048 return false;
1049}
1050
1052 const Triple &TT = TM.getTargetTriple();
1053
1054 if (TT.isOSBinFormatMachO()) {
1055 // Mach-O uses non-lazy symbol stubs to encode per-TU information into
1056 // global table for symbol lookup.
1058
1059 // Emit fault map information.
1060 FM.serializeToFaultMapSection();
1061
1062 // This flag tells the linker that no global symbols contain code that fall
1063 // through to other global symbols (e.g. an implementation of multiple entry
1064 // points). If this doesn't occur, the linker can safely perform dead code
1065 // stripping. Since LLVM never generates code that does this, it is always
1066 // safe to set.
1067 OutStreamer->emitSubsectionsViaSymbols();
1068 } else if (TT.isOSBinFormatCOFF()) {
1069 // If import call optimization is enabled, emit the appropriate section.
1070 // We do this whether or not we recorded any items.
1071 if (EnableImportCallOptimization) {
1072 OutStreamer->switchSection(getObjFileLowering().getImportCallSection());
1073
1074 // Section always starts with some magic.
1075 constexpr char ImpCallMagic[12] = "RetpolineV1";
1076 OutStreamer->emitBytes(StringRef{ImpCallMagic, sizeof(ImpCallMagic)});
1077
1078 // Layout of this section is:
1079 // Per section that contains an item to record:
1080 // uint32_t SectionSize: Size in bytes for information in this section.
1081 // uint32_t Section Number
1082 // Per call to imported function in section:
1083 // uint32_t Kind: the kind of item.
1084 // uint32_t InstOffset: the offset of the instr in its parent section.
1085 for (auto &[Section, CallsToImportedFuncs] :
1086 SectionToImportedFunctionCalls) {
1087 unsigned SectionSize =
1088 sizeof(uint32_t) * (2 + 2 * CallsToImportedFuncs.size());
1089 OutStreamer->emitInt32(SectionSize);
1090 OutStreamer->emitCOFFSecNumber(Section->getBeginSymbol());
1091 for (auto &[CallsiteSymbol, Kind] : CallsToImportedFuncs) {
1092 OutStreamer->emitInt32(Kind);
1093 OutStreamer->emitCOFFSecOffset(CallsiteSymbol);
1094 }
1095 }
1096 }
1097
1098 if (usesMSVCFloatingPoint(TT, M)) {
1099 // In Windows' libcmt.lib, there is a file which is linked in only if the
1100 // symbol _fltused is referenced. Linking this in causes some
1101 // side-effects:
1102 //
1103 // 1. For x86-32, it will set the x87 rounding mode to 53-bit instead of
1104 // 64-bit mantissas at program start.
1105 //
1106 // 2. It links in support routines for floating-point in scanf and printf.
1107 //
1108 // MSVC emits an undefined reference to _fltused when there are any
1109 // floating point operations in the program (including calls). A program
1110 // that only has: `scanf("%f", &global_float);` may fail to trigger this,
1111 // but oh well...that's a documented issue.
1112 StringRef SymbolName =
1113 (TT.getArch() == Triple::x86) ? "__fltused" : "_fltused";
1114 MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
1115 OutStreamer->emitSymbolAttribute(S, MCSA_Global);
1116 return;
1117 }
1118 } else if (TT.isOSBinFormatELF()) {
1119 FM.serializeToFaultMapSection();
1120 }
1121
1122 // Emit __morestack address if needed for indirect calls.
1123 if (TT.isX86_64() && TM.getCodeModel() == CodeModel::Large) {
1124 if (MCSymbol *AddrSymbol = OutContext.lookupSymbol("__morestack_addr")) {
1125 Align Alignment(1);
1128 /*C=*/nullptr, Alignment, /*F=*/nullptr);
1129 OutStreamer->switchSection(ReadOnlySection);
1130 OutStreamer->emitLabel(AddrSymbol);
1131
1132 unsigned PtrSize = MAI.getCodePointerSize();
1133 OutStreamer->emitSymbolValue(GetExternalSymbolSymbol("__morestack"),
1134 PtrSize);
1135 }
1136 }
1137}
1138
1139char X86AsmPrinter::ID = 0;
1140
1141INITIALIZE_PASS(X86AsmPrinter, "x86-asm-printer", "X86 Assembly Printer", false,
1142 false)
1143
1144//===----------------------------------------------------------------------===//
1145// Target Registry Stuff
1146//===----------------------------------------------------------------------===//
1147
1148// Force static initialization.
1149extern "C" LLVM_C_ABI void LLVMInitializeX86AsmPrinter() {
1152}
1153
1156 X86AsmPrinter &AsmPrinter = static_cast<X86AsmPrinter &>(
1157 MAM.getResult<AsmPrinterAnalysis>(M).getPrinter());
1158 AsmPrinter.GetPSI = [&MAM](Module &M) {
1159 return &MAM.getResult<ProfileSummaryAnalysis>(M);
1160 };
1161 AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
1164 return PreservedAnalyses::all();
1165}
1166
1169 X86AsmPrinter &AsmPrinter = static_cast<X86AsmPrinter &>(
1171 .getCachedResult<AsmPrinterAnalysis>(*MF.getFunction().getParent())
1172 ->getPrinter());
1173 AsmPrinter.GetPSI = [&MFAM, &MF](Module &M) {
1175 .getCachedResult<ProfileSummaryAnalysis>(M);
1176 };
1177 AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
1180 return PreservedAnalyses::all();
1181}
1182
1185 X86AsmPrinter &AsmPrinter = static_cast<X86AsmPrinter &>(
1186 MAM.getCachedResult<AsmPrinterAnalysis>(M)->getPrinter());
1187 AsmPrinter.GetPSI = [&MAM](Module &M) {
1188 return &MAM.getResult<ProfileSummaryAnalysis>(M);
1189 };
1190 AsmPrinter.GetSDPI = [](Module &M) { return nullptr; };
1193 return PreservedAnalyses::all();
1194}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym)
MachineBasicBlock & MBB
Expand Atomic instructions
static const Function * getParent(const Value *V)
#define X(NUM, ENUM, NAME)
Definition ELF.h:851
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:483
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition Visibility.h:40
static bool printAsmMRegister(const X86AsmPrinter &P, const MachineOperand &MO, char Mode, raw_ostream &O)
static bool isSimpleReturn(const MachineInstr &MI)
static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M)
True if this module is being built for windows/msvc, and uses floating point.
static bool isIndirectBranchOrTailCall(const MachineInstr &MI)
static bool printAsmVRegister(const MachineOperand &MO, char Mode, raw_ostream &O)
static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:91
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
MCSymbol * getSymbol(const GlobalValue *GV) const
void emitNops(unsigned N)
Emit N NOP instructions.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:94
void emitXRayTable()
Emit a table with all XRay instrumentation points.
virtual void emitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
Align emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
virtual const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV=nullptr, uint64_t Offset=0)
Lower the specified LLVM Constant to an MCExpr.
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
void emitFunctionBody()
This method emits the body and trailer for a function.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition AsmPrinter.h:128
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition AsmPrinter.h:112
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:101
const StaticDataProfileInfo * SDPI
Provides the profile information for constants.
Definition AsmPrinter.h:147
bool doFinalization(Module &M) override
Shut down the asmprinter.
virtual const MCSubtargetInfo * getIFuncMCSubtargetInfo() const
getSubtargetInfo() cannot be used where this is needed because we don't have a MachineFunction when w...
Definition AsmPrinter.h:683
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:456
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:106
const ProfileSummaryInfo * PSI
The profile summary information.
Definition AsmPrinter.h:150
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:97
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
const DataLayout & getDataLayout() const
Return information about data layout.
void emitCOFFFeatureSymbol(Module &M)
Emits the @feat.00 symbol indicating the features enabled in this module.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
void emitCOFFReplaceableFunctionData(Module &M)
Emits symbols and data to allow functions marked with the loader-replaceable attribute to be replacea...
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
const Constant * getResolver() const
Definition GlobalIFunc.h:73
bool hasInternalLinkage() const
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
LLVM_ABI MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void setOpcode(unsigned Op)
Definition MCInst.h:201
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
Definition MCStreamer.h:415
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
MCContext & getContext() const
Definition MCStreamer.h:323
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:59
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Metadata node.
Definition Metadata.h:1080
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
LLVM_ABI InlineAsm::AsmDialect getInlineAsmDialect() const
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
SymbolListTy GetGVStubList()
Accessor methods to return the set of stubs in sorted order.
This class contains meta information specific to a module.
const MCContext & getContext() const
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
const BlockAddress * getBlockAddress() const
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
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.
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ 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.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
IntType getInt() const
PointerTy getPointer() const
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static SectionKind getMetadata()
static SectionKind getReadOnly()
A class that holds the constants that represent static data and their profile information and provide...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:140
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:655
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const
Given a constant with the SectionKind, return a section that it should be placed in.
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
bool isX86_64() const
Tests whether the target is x86 (64-bit).
Definition Triple.h:1115
bool isOSWindows() const
Tests whether the OS is Windows.
Definition Triple.h:698
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
static const char * getRegisterName(MCRegister Reg)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - Emit the function body.
void emitKCFITypeId(const MachineFunction &MF) override
emitKCFITypeId - Emit the KCFI type information in architecture specific format.
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
std::function< ProfileSummaryInfo *(Module &)> GetPSI
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
std::function< StaticDataProfileInfo *(Module &)> GetSDPI
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void emitBasicBlockEnd(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the end of a basic block.
X86AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
PrintAsmOperand - Print out an operand for an inline asm expression.
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
X86 target streamer implementing x86-only assembly directives.
virtual bool emitFPOProc(const MCSymbol *ProcSym, unsigned ParamsSize, SMLoc L={})
virtual bool emitFPOEndProc(SMLoc L={})
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_SYM_CLASS_EXTERNAL
External symbol.
Definition COFF.h:224
@ IMAGE_SYM_CLASS_STATIC
Static.
Definition COFF.h:225
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
Definition COFF.h:276
@ SCT_COMPLEX_TYPE_SHIFT
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition COFF.h:280
@ NT_GNU_PROPERTY_TYPE_0
Definition ELF.h:1811
@ SHF_ALLOC
Definition ELF.h:1249
@ SHT_NOTE
Definition ELF.h:1154
@ GNU_PROPERTY_X86_FEATURE_1_AND
Definition ELF.h:1846
@ GNU_PROPERTY_X86_FEATURE_1_SHSTK
Definition ELF.h:1893
@ GNU_PROPERTY_X86_FEATURE_1_IBT
Definition ELF.h:1892
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition MachO.h:139
@ MO_TLSLD
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
@ MO_GOTPCREL_NORELAX
MO_GOTPCREL_NORELAX - Same as MO_GOTPCREL except that R_X86_64_GOTPCREL relocations are guaranteed to...
@ MO_GOTOFF
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
@ MO_DARWIN_NONLAZY_PIC_BASE
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
@ MO_GOT_ABSOLUTE_ADDRESS
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [.
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
@ MO_NTPOFF
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
@ MO_DARWIN_NONLAZY
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
@ MO_INDNTPOFF
MO_INDNTPOFF - On a symbol operand this indicates that the immediate is the absolute address of the G...
@ MO_GOTNTPOFF
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
@ MO_TPOFF
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
@ MO_TLVP_PIC_BASE
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
@ MO_GOT
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
@ MO_PLT
MO_PLT - On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol n...
@ MO_TLSGD
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
@ MO_NO_FLAG
MO_NO_FLAG - No flag for the operand.
@ MO_TLVP
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
@ MO_GOTTPOFF
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
@ MO_SECREL
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
@ MO_DTPOFF
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
@ MO_PIC_BASE_OFFSET
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
@ MO_TLSLDM
MO_TLSLDM - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
@ MO_GOTPCREL
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:668
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition SFrame.h:77
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
static bool isMem(const MachineInstr &MI, unsigned Op)
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
Target & getTheX86_32Target()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition Alignment.h:186
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1916
void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
Target & getTheX86_64Target()
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...