LLVM 19.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 "X86InstrInfo.h"
22#include "X86Subtarget.h"
30#include "llvm/IR/InlineAsm.h"
31#include "llvm/IR/Mangler.h"
32#include "llvm/IR/Module.h"
33#include "llvm/IR/Type.h"
34#include "llvm/MC/MCAsmInfo.h"
36#include "llvm/MC/MCContext.h"
37#include "llvm/MC/MCExpr.h"
38#include "llvm/MC/MCInst.h"
43#include "llvm/MC/MCStreamer.h"
44#include "llvm/MC/MCSymbol.h"
46#include "llvm/Support/Debug.h"
49
50using namespace llvm;
51
53 std::unique_ptr<MCStreamer> Streamer)
54 : AsmPrinter(TM, std::move(Streamer)), FM(*this) {}
55
56//===----------------------------------------------------------------------===//
57// Primitive Helper Functions.
58//===----------------------------------------------------------------------===//
59
60/// runOnMachineFunction - Emit the function body.
61///
63 Subtarget = &MF.getSubtarget<X86Subtarget>();
64
65 SMShadowTracker.startFunction(MF);
66 CodeEmitter.reset(TM.getTarget().createMCCodeEmitter(
67 *Subtarget->getInstrInfo(), MF.getContext()));
68
69 const Module *M = MF.getFunction().getParent();
70 EmitFPOData = Subtarget->isTargetWin32() && M->getCodeViewFlag();
71
72 IndCSPrefix = M->getModuleFlag("indirect_branch_cs_prefix");
73
75
76 if (Subtarget->isTargetCOFF()) {
77 bool Local = MF.getFunction().hasLocalLinkage();
78 OutStreamer->beginCOFFSymbolDef(CurrentFnSym);
79 OutStreamer->emitCOFFSymbolStorageClass(
83 OutStreamer->endCOFFSymbolDef();
84 }
85
86 // Emit the rest of the function body.
88
89 // Emit the XRay table for this function.
91
92 EmitFPOData = false;
93
94 IndCSPrefix = false;
95
96 // We didn't modify anything.
97 return false;
98}
99
101 if (EmitFPOData) {
102 auto *XTS =
103 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
104 XTS->emitFPOProc(
107 }
108}
109
111 if (EmitFPOData) {
112 auto *XTS =
113 static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
114 XTS->emitFPOEndProc();
115 }
116}
117
118uint32_t X86AsmPrinter::MaskKCFIType(uint32_t Value) {
119 // If the type hash matches an invalid pattern, mask the value.
120 const uint32_t InvalidValues[] = {
121 0xFA1E0FF3, /* ENDBR64 */
122 0xFB1E0FF3, /* ENDBR32 */
123 };
124 for (uint32_t N : InvalidValues) {
125 // LowerKCFI_CHECK emits -Value for indirect call checks, so we must also
126 // mask that. Note that -(Value + 1) == ~Value.
127 if (N == Value || -N == Value)
128 return Value + 1;
129 }
130 return Value;
131}
132
133void X86AsmPrinter::EmitKCFITypePadding(const MachineFunction &MF,
134 bool HasType) {
135 // Keep the function entry aligned, taking patchable-function-prefix into
136 // account if set.
137 int64_t PrefixBytes = 0;
138 (void)MF.getFunction()
139 .getFnAttribute("patchable-function-prefix")
141 .getAsInteger(10, PrefixBytes);
142
143 // Also take the type identifier into account if we're emitting
144 // one. Otherwise, just pad with nops. The X86::MOV32ri instruction emitted
145 // in X86AsmPrinter::emitKCFITypeId is 5 bytes long.
146 if (HasType)
147 PrefixBytes += 5;
148
149 emitNops(offsetToAlignment(PrefixBytes, MF.getAlignment()));
150}
151
152/// emitKCFITypeId - Emit the KCFI type information in architecture specific
153/// format.
155 const Function &F = MF.getFunction();
156 if (!F.getParent()->getModuleFlag("kcfi"))
157 return;
158
159 ConstantInt *Type = nullptr;
160 if (const MDNode *MD = F.getMetadata(LLVMContext::MD_kcfi_type))
161 Type = mdconst::extract<ConstantInt>(MD->getOperand(0));
162
163 // If we don't have a type to emit, just emit padding if needed to maintain
164 // the same alignment for all functions.
165 if (!Type) {
166 EmitKCFITypePadding(MF, /*HasType=*/false);
167 return;
168 }
169
170 // Emit a function symbol for the type data to avoid unreachable instruction
171 // warnings from binary validation tools, and use the same linkage as the
172 // parent function. Note that using local linkage would result in duplicate
173 // symbols for weak parent functions.
174 MCSymbol *FnSym = OutContext.getOrCreateSymbol("__cfi_" + MF.getName());
175 emitLinkage(&MF.getFunction(), FnSym);
177 OutStreamer->emitSymbolAttribute(FnSym, MCSA_ELF_TypeFunction);
178 OutStreamer->emitLabel(FnSym);
179
180 // Embed the type hash in the X86::MOV32ri instruction to avoid special
181 // casing object file parsers.
182 EmitKCFITypePadding(MF);
183 EmitAndCountInstruction(MCInstBuilder(X86::MOV32ri)
184 .addReg(X86::EAX)
185 .addImm(MaskKCFIType(Type->getZExtValue())));
186
188 MCSymbol *EndSym = OutContext.createTempSymbol("cfi_func_end");
189 OutStreamer->emitLabel(EndSym);
190
191 const MCExpr *SizeExp = MCBinaryExpr::createSub(
194 OutStreamer->emitELFSize(FnSym, SizeExp);
195 }
196}
197
198/// PrintSymbolOperand - Print a raw symbol reference operand. This handles
199/// jump tables, constant pools, global address and external symbols, all of
200/// which print to a label with various suffixes for relocation types etc.
201void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
202 raw_ostream &O) {
203 switch (MO.getType()) {
204 default: llvm_unreachable("unknown symbol type!");
206 GetCPISymbol(MO.getIndex())->print(O, MAI);
207 printOffset(MO.getOffset(), O);
208 break;
210 const GlobalValue *GV = MO.getGlobal();
211
212 MCSymbol *GVSym;
215 GVSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
216 else
217 GVSym = getSymbolPreferLocal(*GV);
218
219 // Handle dllimport linkage.
221 GVSym = OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
222 else if (MO.getTargetFlags() == X86II::MO_COFFSTUB)
223 GVSym =
224 OutContext.getOrCreateSymbol(Twine(".refptr.") + GVSym->getName());
225
228 MCSymbol *Sym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
230 MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
231 if (!StubSym.getPointer())
233 !GV->hasInternalLinkage());
234 }
235
236 // If the name begins with a dollar-sign, enclose it in parens. We do this
237 // to avoid having it look like an integer immediate to the assembler.
238 if (GVSym->getName()[0] != '$')
239 GVSym->print(O, MAI);
240 else {
241 O << '(';
242 GVSym->print(O, MAI);
243 O << ')';
244 }
245 printOffset(MO.getOffset(), O);
246 break;
247 }
248 }
249
250 switch (MO.getTargetFlags()) {
251 default:
252 llvm_unreachable("Unknown target flag on GV operand");
253 case X86II::MO_NO_FLAG: // No flag.
254 break;
258 // These affect the name of the symbol, not any suffix.
259 break;
261 O << " + [.-";
263 O << ']';
264 break;
267 O << '-';
269 break;
270 case X86II::MO_TLSGD: O << "@TLSGD"; break;
271 case X86II::MO_TLSLD: O << "@TLSLD"; break;
272 case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
273 case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
274 case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
275 case X86II::MO_TPOFF: O << "@TPOFF"; break;
276 case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
277 case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
278 case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
279 case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
280 case X86II::MO_GOTPCREL_NORELAX: O << "@GOTPCREL_NORELAX"; break;
281 case X86II::MO_GOT: O << "@GOT"; break;
282 case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
283 case X86II::MO_PLT: O << "@PLT"; break;
284 case X86II::MO_TLVP: O << "@TLVP"; break;
286 O << "@TLVP" << '-';
288 break;
289 case X86II::MO_SECREL: O << "@SECREL32"; break;
290 }
291}
292
293void X86AsmPrinter::PrintOperand(const MachineInstr *MI, unsigned OpNo,
294 raw_ostream &O) {
295 const MachineOperand &MO = MI->getOperand(OpNo);
296 const bool IsATT = MI->getInlineAsmDialect() == InlineAsm::AD_ATT;
297 switch (MO.getType()) {
298 default: llvm_unreachable("unknown operand type!");
300 if (IsATT)
301 O << '%';
303 return;
304 }
305
307 if (IsATT)
308 O << '$';
309 O << MO.getImm();
310 return;
311
314 switch (MI->getInlineAsmDialect()) {
316 O << '$';
317 break;
319 O << "offset ";
320 break;
321 }
322 PrintSymbolOperand(MO, O);
323 break;
324 }
327 Sym->print(O, MAI);
328 break;
329 }
330 }
331}
332
333/// PrintModifiedOperand - Print subregisters based on supplied modifier,
334/// deferring to PrintOperand() if no modifier was supplied or if operand is not
335/// a register.
336void X86AsmPrinter::PrintModifiedOperand(const MachineInstr *MI, unsigned OpNo,
337 raw_ostream &O, const char *Modifier) {
338 const MachineOperand &MO = MI->getOperand(OpNo);
339 if (!Modifier || !MO.isReg())
340 return PrintOperand(MI, OpNo, O);
341 if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
342 O << '%';
343 Register Reg = MO.getReg();
344 if (strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
345 unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
346 (strcmp(Modifier+6,"32") == 0) ? 32 :
347 (strcmp(Modifier+6,"16") == 0) ? 16 : 8;
349 }
351}
352
353/// PrintPCRelImm - This is used to print an immediate value that ends up
354/// being encoded as a pc-relative value. These print slightly differently, for
355/// example, a $ is not emitted.
356void X86AsmPrinter::PrintPCRelImm(const MachineInstr *MI, unsigned OpNo,
357 raw_ostream &O) {
358 const MachineOperand &MO = MI->getOperand(OpNo);
359 switch (MO.getType()) {
360 default: llvm_unreachable("Unknown pcrel immediate operand");
362 // pc-relativeness was handled when computing the value in the reg.
363 PrintOperand(MI, OpNo, O);
364 return;
366 O << MO.getImm();
367 return;
369 PrintSymbolOperand(MO, O);
370 return;
371 }
372}
373
374void X86AsmPrinter::PrintLeaMemReference(const MachineInstr *MI, unsigned OpNo,
375 raw_ostream &O, const char *Modifier) {
376 const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
377 const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
378 const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
379
380 // If we really don't want to print out (rip), don't.
381 bool HasBaseReg = BaseReg.getReg() != 0;
382 if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
383 BaseReg.getReg() == X86::RIP)
384 HasBaseReg = false;
385
386 // HasParenPart - True if we will print out the () part of the mem ref.
387 bool HasParenPart = IndexReg.getReg() || HasBaseReg;
388
389 switch (DispSpec.getType()) {
390 default:
391 llvm_unreachable("unknown operand type!");
393 int DispVal = DispSpec.getImm();
394 if (DispVal || !HasParenPart)
395 O << DispVal;
396 break;
397 }
400 PrintSymbolOperand(DispSpec, O);
401 break;
402 }
403
404 if (Modifier && strcmp(Modifier, "H") == 0)
405 O << "+8";
406
407 if (HasParenPart) {
408 assert(IndexReg.getReg() != X86::ESP &&
409 "X86 doesn't allow scaling by ESP");
410
411 O << '(';
412 if (HasBaseReg)
413 PrintModifiedOperand(MI, OpNo + X86::AddrBaseReg, O, Modifier);
414
415 if (IndexReg.getReg()) {
416 O << ',';
417 PrintModifiedOperand(MI, OpNo + X86::AddrIndexReg, O, Modifier);
418 unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
419 if (ScaleVal != 1)
420 O << ',' << ScaleVal;
421 }
422 O << ')';
423 }
424}
425
426static bool isSimpleReturn(const MachineInstr &MI) {
427 // We exclude all tail calls here which set both isReturn and isCall.
428 return MI.getDesc().isReturn() && !MI.getDesc().isCall();
429}
430
432 unsigned Opc = MI.getOpcode();
433 return MI.getDesc().isIndirectBranch() /*Make below code in a good shape*/ ||
434 Opc == X86::TAILJMPr || Opc == X86::TAILJMPm ||
435 Opc == X86::TAILJMPr64 || Opc == X86::TAILJMPm64 ||
436 Opc == X86::TCRETURNri || Opc == X86::TCRETURNmi ||
437 Opc == X86::TCRETURNri64 || Opc == X86::TCRETURNmi64 ||
438 Opc == X86::TAILJMPr64_REX || Opc == X86::TAILJMPm64_REX;
439}
440
442 if (Subtarget->hardenSlsRet() || Subtarget->hardenSlsIJmp()) {
443 auto I = MBB.getLastNonDebugInstr();
444 if (I != MBB.end()) {
445 if ((Subtarget->hardenSlsRet() && isSimpleReturn(*I)) ||
446 (Subtarget->hardenSlsIJmp() && isIndirectBranchOrTailCall(*I))) {
447 MCInst TmpInst;
448 TmpInst.setOpcode(X86::INT3);
449 EmitToStreamer(*OutStreamer, TmpInst);
450 }
451 }
452 }
454 SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
455}
456
457void X86AsmPrinter::PrintMemReference(const MachineInstr *MI, unsigned OpNo,
458 raw_ostream &O, const char *Modifier) {
459 assert(isMem(*MI, OpNo) && "Invalid memory reference!");
460 const MachineOperand &Segment = MI->getOperand(OpNo + X86::AddrSegmentReg);
461 if (Segment.getReg()) {
462 PrintModifiedOperand(MI, OpNo + X86::AddrSegmentReg, O, Modifier);
463 O << ':';
464 }
465 PrintLeaMemReference(MI, OpNo, O, Modifier);
466}
467
468
469void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
470 unsigned OpNo, raw_ostream &O,
471 const char *Modifier) {
472 const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
473 unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
474 const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
475 const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
476 const MachineOperand &SegReg = MI->getOperand(OpNo + X86::AddrSegmentReg);
477
478 // If we really don't want to print out (rip), don't.
479 bool HasBaseReg = BaseReg.getReg() != 0;
480 if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
481 BaseReg.getReg() == X86::RIP)
482 HasBaseReg = false;
483
484 // If we really just want to print out displacement.
485 if (Modifier && (DispSpec.isGlobal() || DispSpec.isSymbol()) &&
486 !strcmp(Modifier, "disp-only")) {
487 HasBaseReg = false;
488 }
489
490 // If this has a segment register, print it.
491 if (SegReg.getReg()) {
492 PrintOperand(MI, OpNo + X86::AddrSegmentReg, O);
493 O << ':';
494 }
495
496 O << '[';
497
498 bool NeedPlus = false;
499 if (HasBaseReg) {
500 PrintOperand(MI, OpNo + X86::AddrBaseReg, O);
501 NeedPlus = true;
502 }
503
504 if (IndexReg.getReg()) {
505 if (NeedPlus) O << " + ";
506 if (ScaleVal != 1)
507 O << ScaleVal << '*';
508 PrintOperand(MI, OpNo + X86::AddrIndexReg, O);
509 NeedPlus = true;
510 }
511
512 if (!DispSpec.isImm()) {
513 if (NeedPlus) O << " + ";
514 // Do not add `offset` operator. Matches the behaviour of
515 // X86IntelInstPrinter::printMemReference.
516 PrintSymbolOperand(DispSpec, O);
517 } else {
518 int64_t DispVal = DispSpec.getImm();
519 if (DispVal || (!IndexReg.getReg() && !HasBaseReg)) {
520 if (NeedPlus) {
521 if (DispVal > 0)
522 O << " + ";
523 else {
524 O << " - ";
525 DispVal = -DispVal;
526 }
527 }
528 O << DispVal;
529 }
530 }
531 O << ']';
532}
533
534const MCSubtargetInfo *X86AsmPrinter::getIFuncMCSubtargetInfo() const {
535 assert(Subtarget);
536 return Subtarget;
537}
538
539void X86AsmPrinter::emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI,
540 MCSymbol *LazyPointer) {
541 // _ifunc:
542 // jmpq *lazy_pointer(%rip)
543
544 OutStreamer->emitInstruction(
545 MCInstBuilder(X86::JMP32m)
546 .addReg(X86::RIP)
547 .addImm(1)
548 .addReg(0)
550 MCSymbolRefExpr::create(LazyPointer, OutContext)))
551 .addReg(0),
552 *Subtarget);
553}
554
555void X86AsmPrinter::emitMachOIFuncStubHelperBody(Module &M,
556 const GlobalIFunc &GI,
557 MCSymbol *LazyPointer) {
558 // _ifunc.stub_helper:
559 // push %rax
560 // push %rdi
561 // push %rsi
562 // push %rdx
563 // push %rcx
564 // push %r8
565 // push %r9
566 // callq foo
567 // movq %rax,lazy_pointer(%rip)
568 // pop %r9
569 // pop %r8
570 // pop %rcx
571 // pop %rdx
572 // pop %rsi
573 // pop %rdi
574 // pop %rax
575 // jmpq *lazy_pointer(%rip)
576
577 for (int Reg :
578 {X86::RAX, X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8, X86::R9})
579 OutStreamer->emitInstruction(MCInstBuilder(X86::PUSH64r).addReg(Reg),
580 *Subtarget);
581
582 OutStreamer->emitInstruction(
583 MCInstBuilder(X86::CALL64pcrel32)
585 *Subtarget);
586
587 OutStreamer->emitInstruction(
588 MCInstBuilder(X86::MOV64mr)
589 .addReg(X86::RIP)
590 .addImm(1)
591 .addReg(0)
593 MCSymbolRefExpr::create(LazyPointer, OutContext)))
594 .addReg(0)
595 .addReg(X86::RAX),
596 *Subtarget);
597
598 for (int Reg :
599 {X86::R9, X86::R8, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RAX})
600 OutStreamer->emitInstruction(MCInstBuilder(X86::POP64r).addReg(Reg),
601 *Subtarget);
602
603 OutStreamer->emitInstruction(
604 MCInstBuilder(X86::JMP32m)
605 .addReg(X86::RIP)
606 .addImm(1)
607 .addReg(0)
609 MCSymbolRefExpr::create(LazyPointer, OutContext)))
610 .addReg(0),
611 *Subtarget);
612}
613
614static bool printAsmMRegister(const X86AsmPrinter &P, const MachineOperand &MO,
615 char Mode, raw_ostream &O) {
616 Register Reg = MO.getReg();
617 bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
618
619 if (!X86::GR8RegClass.contains(Reg) &&
620 !X86::GR16RegClass.contains(Reg) &&
621 !X86::GR32RegClass.contains(Reg) &&
622 !X86::GR64RegClass.contains(Reg))
623 return true;
624
625 switch (Mode) {
626 default: return true; // Unknown mode.
627 case 'b': // Print QImode register
628 Reg = getX86SubSuperRegister(Reg, 8);
629 break;
630 case 'h': // Print QImode high register
631 Reg = getX86SubSuperRegister(Reg, 8, true);
632 if (!Reg.isValid())
633 return true;
634 break;
635 case 'w': // Print HImode register
636 Reg = getX86SubSuperRegister(Reg, 16);
637 break;
638 case 'k': // Print SImode register
639 Reg = getX86SubSuperRegister(Reg, 32);
640 break;
641 case 'V':
642 EmitPercent = false;
643 [[fallthrough]];
644 case 'q':
645 // Print 64-bit register names if 64-bit integer registers are available.
646 // Otherwise, print 32-bit register names.
647 Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
648 break;
649 }
650
651 if (EmitPercent)
652 O << '%';
653
655 return false;
656}
657
658static bool printAsmVRegister(const MachineOperand &MO, char Mode,
659 raw_ostream &O) {
660 Register Reg = MO.getReg();
661 bool EmitPercent = MO.getParent()->getInlineAsmDialect() == InlineAsm::AD_ATT;
662
663 unsigned Index;
664 if (X86::VR128XRegClass.contains(Reg))
665 Index = Reg - X86::XMM0;
666 else if (X86::VR256XRegClass.contains(Reg))
667 Index = Reg - X86::YMM0;
668 else if (X86::VR512RegClass.contains(Reg))
669 Index = Reg - X86::ZMM0;
670 else
671 return true;
672
673 switch (Mode) {
674 default: // Unknown mode.
675 return true;
676 case 'x': // Print V4SFmode register
677 Reg = X86::XMM0 + Index;
678 break;
679 case 't': // Print V8SFmode register
680 Reg = X86::YMM0 + Index;
681 break;
682 case 'g': // Print V16SFmode register
683 Reg = X86::ZMM0 + Index;
684 break;
685 }
686
687 if (EmitPercent)
688 O << '%';
689
691 return false;
692}
693
694/// PrintAsmOperand - Print out an operand for an inline asm expression.
695///
697 const char *ExtraCode, raw_ostream &O) {
698 // Does this asm operand have a single letter operand modifier?
699 if (ExtraCode && ExtraCode[0]) {
700 if (ExtraCode[1] != 0) return true; // Unknown modifier.
701
702 const MachineOperand &MO = MI->getOperand(OpNo);
703
704 switch (ExtraCode[0]) {
705 default:
706 // See if this is a generic print operand
707 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
708 case 'a': // This is an address. Currently only 'i' and 'r' are expected.
709 switch (MO.getType()) {
710 default:
711 return true;
713 O << MO.getImm();
714 return false;
718 llvm_unreachable("unexpected operand type!");
720 PrintSymbolOperand(MO, O);
721 if (Subtarget->isPICStyleRIPRel())
722 O << "(%rip)";
723 return false;
725 O << '(';
726 PrintOperand(MI, OpNo, O);
727 O << ')';
728 return false;
729 }
730
731 case 'c': // Don't print "$" before a global var name or constant.
732 switch (MO.getType()) {
733 default:
734 PrintOperand(MI, OpNo, O);
735 break;
737 O << MO.getImm();
738 break;
742 llvm_unreachable("unexpected operand type!");
744 PrintSymbolOperand(MO, O);
745 break;
746 }
747 return false;
748
749 case 'A': // Print '*' before a register (it must be a register)
750 if (MO.isReg()) {
751 O << '*';
752 PrintOperand(MI, OpNo, O);
753 return false;
754 }
755 return true;
756
757 case 'b': // Print QImode register
758 case 'h': // Print QImode high register
759 case 'w': // Print HImode register
760 case 'k': // Print SImode register
761 case 'q': // Print DImode register
762 case 'V': // Print native register without '%'
763 if (MO.isReg())
764 return printAsmMRegister(*this, MO, ExtraCode[0], O);
765 PrintOperand(MI, OpNo, O);
766 return false;
767
768 case 'x': // Print V4SFmode register
769 case 't': // Print V8SFmode register
770 case 'g': // Print V16SFmode register
771 if (MO.isReg())
772 return printAsmVRegister(MO, ExtraCode[0], O);
773 PrintOperand(MI, OpNo, O);
774 return false;
775
776 case 'p': {
777 const MachineOperand &MO = MI->getOperand(OpNo);
779 return true;
780 PrintSymbolOperand(MO, O);
781 return false;
782 }
783
784 case 'P': // This is the operand of a call, treat specially.
785 PrintPCRelImm(MI, OpNo, O);
786 return false;
787
788 case 'n': // Negate the immediate or print a '-' before the operand.
789 // Note: this is a temporary solution. It should be handled target
790 // independently as part of the 'MC' work.
791 if (MO.isImm()) {
792 O << -MO.getImm();
793 return false;
794 }
795 O << '-';
796 }
797 }
798
799 PrintOperand(MI, OpNo, O);
800 return false;
801}
802
804 const char *ExtraCode,
805 raw_ostream &O) {
806 if (ExtraCode && ExtraCode[0]) {
807 if (ExtraCode[1] != 0) return true; // Unknown modifier.
808
809 switch (ExtraCode[0]) {
810 default: return true; // Unknown modifier.
811 case 'b': // Print QImode register
812 case 'h': // Print QImode high register
813 case 'w': // Print HImode register
814 case 'k': // Print SImode register
815 case 'q': // Print SImode register
816 // These only apply to registers, ignore on mem.
817 break;
818 case 'H':
819 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
820 return true; // Unsupported modifier in Intel inline assembly.
821 } else {
822 PrintMemReference(MI, OpNo, O, "H");
823 }
824 return false;
825 // Print memory only with displacement. The Modifer 'P' is used in inline
826 // asm to present a call symbol or a global symbol which can not use base
827 // reg or index reg.
828 case 'P':
829 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
830 PrintIntelMemReference(MI, OpNo, O, "disp-only");
831 } else {
832 PrintMemReference(MI, OpNo, O, "disp-only");
833 }
834 return false;
835 }
836 }
837 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
838 PrintIntelMemReference(MI, OpNo, O, nullptr);
839 } else {
840 PrintMemReference(MI, OpNo, O, nullptr);
841 }
842 return false;
843}
844
846 const Triple &TT = TM.getTargetTriple();
847
848 if (TT.isOSBinFormatELF()) {
849 // Assemble feature flags that may require creation of a note section.
850 unsigned FeatureFlagsAnd = 0;
851 if (M.getModuleFlag("cf-protection-branch"))
852 FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_IBT;
853 if (M.getModuleFlag("cf-protection-return"))
854 FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_SHSTK;
855
856 if (FeatureFlagsAnd) {
857 // Emit a .note.gnu.property section with the flags.
858 assert((TT.isArch32Bit() || TT.isArch64Bit()) &&
859 "CFProtection used on invalid architecture!");
860 MCSection *Cur = OutStreamer->getCurrentSectionOnly();
862 ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
863 OutStreamer->switchSection(Nt);
864
865 // Emitting note header.
866 const int WordSize = TT.isArch64Bit() && !TT.isX32() ? 8 : 4;
867 emitAlignment(WordSize == 4 ? Align(4) : Align(8));
868 OutStreamer->emitIntValue(4, 4 /*size*/); // data size for "GNU\0"
869 OutStreamer->emitIntValue(8 + WordSize, 4 /*size*/); // Elf_Prop size
870 OutStreamer->emitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4 /*size*/);
871 OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
872
873 // Emitting an Elf_Prop for the CET properties.
875 OutStreamer->emitInt32(4); // data size
876 OutStreamer->emitInt32(FeatureFlagsAnd); // data
877 emitAlignment(WordSize == 4 ? Align(4) : Align(8)); // padding
878
879 OutStreamer->switchSection(Cur);
880 }
881 }
882
883 if (TT.isOSBinFormatMachO())
884 OutStreamer->switchSection(getObjFileLowering().getTextSection());
885
886 if (TT.isOSBinFormatCOFF()) {
887 // Emit an absolute @feat.00 symbol.
889 OutStreamer->beginCOFFSymbolDef(S);
890 OutStreamer->emitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
891 OutStreamer->emitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
892 OutStreamer->endCOFFSymbolDef();
893 int64_t Feat00Value = 0;
894
895 if (TT.getArch() == Triple::x86) {
896 // According to the PE-COFF spec, the LSB of this value marks the object
897 // for "registered SEH". This means that all SEH handler entry points
898 // must be registered in .sxdata. Use of any unregistered handlers will
899 // cause the process to terminate immediately. LLVM does not know how to
900 // register any SEH handlers, so its object files should be safe.
901 Feat00Value |= COFF::Feat00Flags::SafeSEH;
902 }
903
904 if (M.getModuleFlag("cfguard")) {
905 // Object is CFG-aware.
906 Feat00Value |= COFF::Feat00Flags::GuardCF;
907 }
908
909 if (M.getModuleFlag("ehcontguard")) {
910 // Object also has EHCont.
911 Feat00Value |= COFF::Feat00Flags::GuardEHCont;
912 }
913
914 if (M.getModuleFlag("ms-kernel")) {
915 // Object is compiled with /kernel.
916 Feat00Value |= COFF::Feat00Flags::Kernel;
917 }
918
919 OutStreamer->emitSymbolAttribute(S, MCSA_Global);
920 OutStreamer->emitAssignment(
921 S, MCConstantExpr::create(Feat00Value, MMI->getContext()));
922 }
923 OutStreamer->emitSyntaxDirective();
924
925 // If this is not inline asm and we're in 16-bit
926 // mode prefix assembly with .code16.
927 bool is16 = TT.getEnvironment() == Triple::CODE16;
928 if (M.getModuleInlineAsm().empty() && is16)
929 OutStreamer->emitAssemblerFlag(MCAF_Code16);
930}
931
932static void
935 // L_foo$stub:
936 OutStreamer.emitLabel(StubLabel);
937 // .indirect_symbol _foo
939
940 if (MCSym.getInt())
941 // External to current translation unit.
942 OutStreamer.emitIntValue(0, 4/*size*/);
943 else
944 // Internal to current translation unit.
945 //
946 // When we place the LSDA into the TEXT section, the type info
947 // pointers need to be indirect and pc-rel. We accomplish this by
948 // using NLPs; however, sometimes the types are local to the file.
949 // We need to fill in the value for the NLP in those cases.
950 OutStreamer.emitValue(
951 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
952 4 /*size*/);
953}
954
955static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) {
956
957 MachineModuleInfoMachO &MMIMacho =
959
960 // Output stubs for dynamically-linked functions.
962
963 // Output stubs for external and common global variables.
964 Stubs = MMIMacho.GetGVStubList();
965 if (!Stubs.empty()) {
966 OutStreamer.switchSection(MMI->getContext().getMachOSection(
967 "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
969
970 for (auto &Stub : Stubs)
971 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
972
973 Stubs.clear();
974 OutStreamer.addBlankLine();
975 }
976}
977
979 const Triple &TT = TM.getTargetTriple();
980
981 if (TT.isOSBinFormatMachO()) {
982 // Mach-O uses non-lazy symbol stubs to encode per-TU information into
983 // global table for symbol lookup.
985
986 // Emit fault map information.
988
989 // This flag tells the linker that no global symbols contain code that fall
990 // through to other global symbols (e.g. an implementation of multiple entry
991 // points). If this doesn't occur, the linker can safely perform dead code
992 // stripping. Since LLVM never generates code that does this, it is always
993 // safe to set.
994 OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
995 } else if (TT.isOSBinFormatCOFF()) {
996 if (MMI->usesMSVCFloatingPoint()) {
997 // In Windows' libcmt.lib, there is a file which is linked in only if the
998 // symbol _fltused is referenced. Linking this in causes some
999 // side-effects:
1000 //
1001 // 1. For x86-32, it will set the x87 rounding mode to 53-bit instead of
1002 // 64-bit mantissas at program start.
1003 //
1004 // 2. It links in support routines for floating-point in scanf and printf.
1005 //
1006 // MSVC emits an undefined reference to _fltused when there are any
1007 // floating point operations in the program (including calls). A program
1008 // that only has: `scanf("%f", &global_float);` may fail to trigger this,
1009 // but oh well...that's a documented issue.
1010 StringRef SymbolName =
1011 (TT.getArch() == Triple::x86) ? "__fltused" : "_fltused";
1012 MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
1013 OutStreamer->emitSymbolAttribute(S, MCSA_Global);
1014 return;
1015 }
1016 } else if (TT.isOSBinFormatELF()) {
1018 }
1019
1020 // Emit __morestack address if needed for indirect calls.
1021 if (TT.getArch() == Triple::x86_64 && TM.getCodeModel() == CodeModel::Large) {
1022 if (MCSymbol *AddrSymbol = OutContext.lookupSymbol("__morestack_addr")) {
1023 Align Alignment(1);
1026 /*C=*/nullptr, Alignment);
1027 OutStreamer->switchSection(ReadOnlySection);
1028 OutStreamer->emitLabel(AddrSymbol);
1029
1030 unsigned PtrSize = MAI->getCodePointerSize();
1031 OutStreamer->emitSymbolValue(GetExternalSymbolSymbol("__morestack"),
1032 PtrSize);
1033 }
1034 }
1035}
1036
1037//===----------------------------------------------------------------------===//
1038// Target Registry Stuff
1039//===----------------------------------------------------------------------===//
1040
1041// Force static initialization.
1045}
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym)
MachineBasicBlock & MBB
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:135
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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 ...
Module.h This file contains the declarations for the Module class.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
#define P(N)
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmPrinter()
static bool printAsmMRegister(const X86AsmPrinter &P, const MachineOperand &MO, char Mode, raw_ostream &O)
static bool isSimpleReturn(const MachineInstr &MI)
static bool isIndirectBranchOrTailCall(const MachineInstr &MI)
static bool printAsmVRegister(const MachineOperand &MO, char Mode, raw_ostream &O)
static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:383
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
Definition: AsmPrinter.cpp:676
void emitNops(unsigned N)
Emit N NOP instructions.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:403
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:89
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.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:92
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:104
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.
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.
Definition: AsmPrinter.cpp:631
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.
Definition: AsmPrinter.cpp:680
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:123
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:107
void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:96
MCSymbol * GetExternalSymbolSymbol(Twine Sym) const
Return the MCSymbol for the specified ExternalSymbol.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:101
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
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.
Definition: AsmPrinter.cpp:387
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:398
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.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:391
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
void serializeToFaultMapSection()
Definition: FaultMaps.cpp:45
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.cpp:745
const Constant * getResolver() const
Definition: GlobalIFunc.h:70
bool hasLocalLinkage() const
Definition: GlobalValue.h:528
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
bool hasInternalLinkage() const
Definition: GlobalValue.h:526
bool hasDotTypeDotSizeDirective() const
Definition: MCAsmInfo.h:742
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:546
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:617
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:193
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.
Definition: MCContext.cpp:484
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:346
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:547
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:408
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:213
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:184
void setOpcode(unsigned Op)
Definition: MCInst.h:197
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:385
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
MCContext & getContext() const
Definition: MCStreamer.h:300
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:179
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:414
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.
Definition: MCStreamer.cpp:133
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)
Definition: MCExpr.h:393
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:58
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
Metadata node.
Definition: Metadata.h:1067
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MCContext & getContext() const
Align getAlignment() const
getAlignment - Return the alignment of the function.
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...
Representation of each machine instruction.
Definition: MachineInstr.h:69
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.
bool usesMSVCFloatingPoint() const
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:65
PointerIntPair - This class implements a pair of a pointer and small integer.
IntType getInt() const
PointerTy getPointer() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static SectionKind getMetadata()
Definition: SectionKind.h:188
static SectionKind getReadOnly()
Definition: SectionKind.h:192
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:455
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) 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.
Definition: TargetMachine.h:77
const Triple & getTargetTriple() const
const Target & getTarget() const
CodeModel::Model getCodeModel() const
Returns the code model.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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
LLVM Value Representation.
Definition: Value.h:74
static const char * getRegisterName(MCRegister Reg)
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...
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
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...
const X86InstrInfo * getInstrInfo() const override
Definition: X86Subtarget.h:122
bool isTargetCOFF() const
Definition: X86Subtarget.h:287
bool isPICStyleRIPRel() const
Definition: X86Subtarget.h:329
bool isTargetWin32() const
Definition: X86Subtarget.h:326
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:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_SYM_CLASS_EXTERNAL
External symbol.
Definition: COFF.h:223
@ IMAGE_SYM_CLASS_STATIC
Static.
Definition: COFF.h:224
@ SafeSEH
Definition: COFF.h:796
@ GuardEHCont
Definition: COFF.h:804
@ GuardCF
Definition: COFF.h:802
@ Kernel
Definition: COFF.h:806
@ IMAGE_SYM_DTYPE_NULL
No complex type; simple scalar variable.
Definition: COFF.h:273
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
Definition: COFF.h:275
@ SCT_COMPLEX_TYPE_SHIFT
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: COFF.h:279
@ NT_GNU_PROPERTY_TYPE_0
Definition: ELF.h:1720
@ GNU_PROPERTY_X86_FEATURE_1_AND
Definition: ELF.h:1755
@ GNU_PROPERTY_X86_FEATURE_1_SHSTK
Definition: ELF.h:1796
@ GNU_PROPERTY_X86_FEATURE_1_IBT
Definition: ELF.h:1795
@ SHT_NOTE
Definition: ELF.h:1074
@ SHF_ALLOC
Definition: ELF.h:1165
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition: MachO.h:139
Reg
All possible values of the reg field in the ModR/M byte.
@ MO_TLSLD
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:411
@ MO_GOTPCREL_NORELAX
MO_GOTPCREL_NORELAX - Same as MO_GOTPCREL except that R_X86_64_GOTPCREL relocations are guaranteed to...
Definition: X86BaseInfo.h:391
@ MO_GOTOFF
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
Definition: X86BaseInfo.h:381
@ 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:468
@ MO_GOT_ABSOLUTE_ADDRESS
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [.
Definition: X86BaseInfo.h:367
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
Definition: X86BaseInfo.h:488
@ MO_NTPOFF
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
Definition: X86BaseInfo.h:450
@ MO_DARWIN_NONLAZY
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:464
@ MO_INDNTPOFF
MO_INDNTPOFF - On a symbol operand this indicates that the immediate is the absolute address of the G...
Definition: X86BaseInfo.h:432
@ MO_GOTNTPOFF
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
Definition: X86BaseInfo.h:456
@ MO_TPOFF
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
Definition: X86BaseInfo.h:438
@ 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:476
@ 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:376
@ 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:396
@ MO_TLSGD
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:403
@ MO_NO_FLAG
MO_NO_FLAG - No flag for the operand.
Definition: X86BaseInfo.h:363
@ MO_TLVP
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
Definition: X86BaseInfo.h:472
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
Definition: X86BaseInfo.h:460
@ MO_GOTTPOFF
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
Definition: X86BaseInfo.h:425
@ MO_SECREL
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
Definition: X86BaseInfo.h:480
@ MO_DTPOFF
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:444
@ 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:371
@ MO_TLSLDM
MO_TLSLDM - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:419
@ MO_GOTPCREL
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
Definition: X86BaseInfo.h:387
@ AddrScaleAmt
Definition: X86BaseInfo.h:30
@ AddrSegmentReg
Definition: X86BaseInfo.h:34
@ AddrIndexReg
Definition: X86BaseInfo.h:31
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
static bool isMem(const MachineInstr &MI, unsigned Op)
Definition: X86InstrInfo.h:170
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
Target & getTheX86_32Target()
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:197
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:56
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:55
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:1849
Target & getTheX86_64Target()
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
@ MCSA_Global
.type _foo, @gnu_unique_object
Definition: MCDirectives.h:30
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#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,...