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