LLVM 23.0.0git
X86AsmBackend.cpp
Go to the documentation of this file.
1//===-- X86AsmBackend.cpp - X86 Assembler Backend -------------------------===//
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
17#include "llvm/MC/MCAssembler.h"
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCDwarf.h"
23#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCInstrInfo.h"
29#include "llvm/MC/MCSection.h"
32#include "llvm/MC/MCValue.h"
37
38using namespace llvm;
39
40namespace {
41/// A wrapper for holding a mask of the values from X86::AlignBranchBoundaryKind
42class X86AlignBranchKind {
43private:
44 uint8_t AlignBranchKind = 0;
45
46public:
47 void operator=(const std::string &Val) {
48 if (Val.empty())
49 return;
50 SmallVector<StringRef, 6> BranchTypes;
51 StringRef(Val).split(BranchTypes, '+', -1, false);
52 for (auto BranchType : BranchTypes) {
53 if (BranchType == "fused")
54 addKind(X86::AlignBranchFused);
55 else if (BranchType == "jcc")
56 addKind(X86::AlignBranchJcc);
57 else if (BranchType == "jmp")
58 addKind(X86::AlignBranchJmp);
59 else if (BranchType == "call")
60 addKind(X86::AlignBranchCall);
61 else if (BranchType == "ret")
62 addKind(X86::AlignBranchRet);
63 else if (BranchType == "indirect")
65 else {
66 errs() << "invalid argument " << BranchType.str()
67 << " to -x86-align-branch=; each element must be one of: fused, "
68 "jcc, jmp, call, ret, indirect.(plus separated)\n";
69 }
70 }
71 }
72
73 operator uint8_t() const { return AlignBranchKind; }
74 void addKind(X86::AlignBranchBoundaryKind Value) { AlignBranchKind |= Value; }
75};
76
77X86AlignBranchKind X86AlignBranchKindLoc;
78
79cl::opt<unsigned> X86AlignBranchBoundary(
80 "x86-align-branch-boundary", cl::init(0),
82 "Control how the assembler should align branches with NOP. If the "
83 "boundary's size is not 0, it should be a power of 2 and no less "
84 "than 32. Branches will be aligned to prevent from being across or "
85 "against the boundary of specified size. The default value 0 does not "
86 "align branches."));
87
89 "x86-align-branch",
91 "Specify types of branches to align (plus separated list of types):"
92 "\njcc indicates conditional jumps"
93 "\nfused indicates fused conditional jumps"
94 "\njmp indicates direct unconditional jumps"
95 "\ncall indicates direct and indirect calls"
96 "\nret indicates rets"
97 "\nindirect indicates indirect unconditional jumps"),
98 cl::location(X86AlignBranchKindLoc));
99
100cl::opt<bool> X86AlignBranchWithin32BBoundaries(
101 "x86-branches-within-32B-boundaries", cl::init(false),
102 cl::desc(
103 "Align selected instructions to mitigate negative performance impact "
104 "of Intel's micro code update for errata skx102. May break "
105 "assumptions about labels corresponding to particular instructions, "
106 "and should be used with caution."));
107
108cl::opt<unsigned> X86PadMaxPrefixSize(
109 "x86-pad-max-prefix-size", cl::init(0),
110 cl::desc("Maximum number of prefixes to use for padding"));
111
112cl::opt<bool> X86PadForAlign(
113 "x86-pad-for-align", cl::init(false), cl::Hidden,
114 cl::desc("Pad previous instructions to implement align directives"));
115
116cl::opt<bool> X86PadForBranchAlign(
117 "x86-pad-for-branch-align", cl::init(true), cl::Hidden,
118 cl::desc("Pad previous instructions to implement branch alignment"));
119
120class X86AsmBackend : public MCAsmBackend {
121 const MCSubtargetInfo &STI;
122 std::unique_ptr<const MCInstrInfo> MCII;
123 X86AlignBranchKind AlignBranchType;
124 Align AlignBoundary;
125 unsigned TargetPrefixMax = 0;
126
127 MCInst PrevInst;
128 unsigned PrevInstOpcode = 0;
129 MCBoundaryAlignFragment *PendingBA = nullptr;
130 std::pair<MCFragment *, size_t> PrevInstPosition;
131
132 uint8_t determinePaddingPrefix(const MCInst &Inst) const;
133 bool isMacroFused(const MCInst &Cmp, const MCInst &Jcc) const;
134 bool needAlign(const MCInst &Inst) const;
135 bool canPadBranches(MCObjectStreamer &OS) const;
136 bool canPadInst(const MCInst &Inst, MCObjectStreamer &OS) const;
137
138public:
139 X86AsmBackend(const Target &T, const MCSubtargetInfo &STI)
140 : MCAsmBackend(llvm::endianness::little), STI(STI),
141 MCII(T.createMCInstrInfo()) {
142 if (X86AlignBranchWithin32BBoundaries) {
143 // At the moment, this defaults to aligning fused branches, unconditional
144 // jumps, and (unfused) conditional jumps with nops. Both the
145 // instructions aligned and the alignment method (nop vs prefix) may
146 // change in the future.
147 AlignBoundary = assumeAligned(32);
148 AlignBranchType.addKind(X86::AlignBranchFused);
149 AlignBranchType.addKind(X86::AlignBranchJcc);
150 AlignBranchType.addKind(X86::AlignBranchJmp);
151 }
152 // Allow overriding defaults set by main flag
153 if (X86AlignBranchBoundary.getNumOccurrences())
154 AlignBoundary = assumeAligned(X86AlignBranchBoundary);
155 if (X86AlignBranch.getNumOccurrences())
156 AlignBranchType = X86AlignBranchKindLoc;
157 if (X86PadMaxPrefixSize.getNumOccurrences())
158 TargetPrefixMax = X86PadMaxPrefixSize;
159
160 AllowAutoPadding =
161 AlignBoundary != Align(1) && AlignBranchType != X86::AlignBranchNone;
162 AllowEnhancedRelaxation =
163 AllowAutoPadding && TargetPrefixMax != 0 && X86PadForBranchAlign;
164 }
165
166 void emitInstructionBegin(MCObjectStreamer &OS, const MCInst &Inst,
167 const MCSubtargetInfo &STI);
168 void emitInstructionEnd(MCObjectStreamer &OS, const MCInst &Inst);
169
170
171 std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
172
173 MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
174
175 std::optional<bool> evaluateFixup(const MCFragment &, MCFixup &, MCValue &,
176 uint64_t &) override;
177 void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
178 uint8_t *Data, uint64_t Value, bool IsResolved) override;
179
180 bool mayNeedRelaxation(unsigned Opcode, ArrayRef<MCOperand> Operands,
181 const MCSubtargetInfo &STI) const override;
182
183 bool fixupNeedsRelaxationAdvanced(const MCFragment &, const MCFixup &,
184 const MCValue &, uint64_t,
185 bool) const override;
186
187 void relaxInstruction(MCInst &Inst,
188 const MCSubtargetInfo &STI) const override;
189
190 bool padInstructionViaRelaxation(MCFragment &RF, MCCodeEmitter &Emitter,
191 unsigned &RemainingSize) const;
192
193 bool padInstructionViaPrefix(MCFragment &RF, MCCodeEmitter &Emitter,
194 unsigned &RemainingSize) const;
195
196 bool padInstructionEncoding(MCFragment &RF, MCCodeEmitter &Emitter,
197 unsigned &RemainingSize) const;
198
199 bool finishLayout() const override;
200
201 unsigned getMaximumNopSize(const MCSubtargetInfo &STI) const override;
202
203 bool writeNopData(raw_ostream &OS, uint64_t Count,
204 const MCSubtargetInfo *STI) const override;
205};
206} // end anonymous namespace
207
208static bool isRelaxableBranch(unsigned Opcode) {
209 return Opcode == X86::JCC_1 || Opcode == X86::JMP_1;
210}
211
212static unsigned getRelaxedOpcodeBranch(unsigned Opcode,
213 bool Is16BitMode = false) {
214 switch (Opcode) {
215 default:
216 llvm_unreachable("invalid opcode for branch");
217 case X86::JCC_1:
218 return (Is16BitMode) ? X86::JCC_2 : X86::JCC_4;
219 case X86::JMP_1:
220 return (Is16BitMode) ? X86::JMP_2 : X86::JMP_4;
221 }
222}
223
224static unsigned getRelaxedOpcode(const MCInst &MI, bool Is16BitMode) {
225 unsigned Opcode = MI.getOpcode();
226 return isRelaxableBranch(Opcode) ? getRelaxedOpcodeBranch(Opcode, Is16BitMode)
228}
229
231 const MCInstrInfo &MCII) {
232 unsigned Opcode = MI.getOpcode();
233 switch (Opcode) {
234 default:
235 return X86::COND_INVALID;
236 case X86::JCC_1: {
237 const MCInstrDesc &Desc = MCII.get(Opcode);
238 return static_cast<X86::CondCode>(
239 MI.getOperand(Desc.getNumOperands() - 1).getImm());
240 }
241 }
242}
243
247 return classifySecondCondCodeInMacroFusion(CC);
248}
249
250/// Check if the instruction uses RIP relative addressing.
251static bool isRIPRelative(const MCInst &MI, const MCInstrInfo &MCII) {
252 unsigned Opcode = MI.getOpcode();
253 const MCInstrDesc &Desc = MCII.get(Opcode);
254 uint64_t TSFlags = Desc.TSFlags;
255 unsigned CurOp = X86II::getOperandBias(Desc);
256 int MemoryOperand = X86II::getMemoryOperandNo(TSFlags);
257 if (MemoryOperand < 0)
258 return false;
259 unsigned BaseRegNum = MemoryOperand + CurOp + X86::AddrBaseReg;
260 MCRegister BaseReg = MI.getOperand(BaseRegNum).getReg();
261 return (BaseReg == X86::RIP);
262}
263
264/// Check if the instruction is a prefix.
265static bool isPrefix(unsigned Opcode, const MCInstrInfo &MCII) {
266 return X86II::isPrefix(MCII.get(Opcode).TSFlags);
267}
268
269/// Check if the instruction is valid as the first instruction in macro fusion.
270static bool isFirstMacroFusibleInst(const MCInst &Inst,
271 const MCInstrInfo &MCII) {
272 // An Intel instruction with RIP relative addressing is not macro fusible.
273 if (isRIPRelative(Inst, MCII))
274 return false;
278}
279
280/// X86 can reduce the bytes of NOP by padding instructions with prefixes to
281/// get a better peformance in some cases. Here, we determine which prefix is
282/// the most suitable.
283///
284/// If the instruction has a segment override prefix, use the existing one.
285/// If the target is 64-bit, use the CS.
286/// If the target is 32-bit,
287/// - If the instruction has a ESP/EBP base register, use SS.
288/// - Otherwise use DS.
289uint8_t X86AsmBackend::determinePaddingPrefix(const MCInst &Inst) const {
290 assert((STI.hasFeature(X86::Is32Bit) || STI.hasFeature(X86::Is64Bit)) &&
291 "Prefixes can be added only in 32-bit or 64-bit mode.");
292 const MCInstrDesc &Desc = MCII->get(Inst.getOpcode());
293 uint64_t TSFlags = Desc.TSFlags;
294
295 // Determine where the memory operand starts, if present.
296 int MemoryOperand = X86II::getMemoryOperandNo(TSFlags);
297 if (MemoryOperand != -1)
298 MemoryOperand += X86II::getOperandBias(Desc);
299
300 MCRegister SegmentReg;
301 if (MemoryOperand >= 0) {
302 // Check for explicit segment override on memory operand.
303 SegmentReg = Inst.getOperand(MemoryOperand + X86::AddrSegmentReg).getReg();
304 }
305
306 switch (TSFlags & X86II::FormMask) {
307 default:
308 break;
309 case X86II::RawFrmDstSrc: {
310 // Check segment override opcode prefix as needed (not for %ds).
311 if (Inst.getOperand(2).getReg() != X86::DS)
312 SegmentReg = Inst.getOperand(2).getReg();
313 break;
314 }
315 case X86II::RawFrmSrc: {
316 // Check segment override opcode prefix as needed (not for %ds).
317 if (Inst.getOperand(1).getReg() != X86::DS)
318 SegmentReg = Inst.getOperand(1).getReg();
319 break;
320 }
322 // Check segment override opcode prefix as needed.
323 SegmentReg = Inst.getOperand(1).getReg();
324 break;
325 }
326 }
327
328 if (SegmentReg)
329 return X86::getSegmentOverridePrefixForReg(SegmentReg);
330
331 if (STI.hasFeature(X86::Is64Bit))
332 return X86::CS_Encoding;
333
334 if (MemoryOperand >= 0) {
335 unsigned BaseRegNum = MemoryOperand + X86::AddrBaseReg;
336 MCRegister BaseReg = Inst.getOperand(BaseRegNum).getReg();
337 if (BaseReg == X86::ESP || BaseReg == X86::EBP)
338 return X86::SS_Encoding;
339 }
340 return X86::DS_Encoding;
341}
342
343/// Check if the two instructions will be macro-fused on the target cpu.
344bool X86AsmBackend::isMacroFused(const MCInst &Cmp, const MCInst &Jcc) const {
345 const MCInstrDesc &InstDesc = MCII->get(Jcc.getOpcode());
346 if (!InstDesc.isConditionalBranch())
347 return false;
348 if (!isFirstMacroFusibleInst(Cmp, *MCII))
349 return false;
350 const X86::FirstMacroFusionInstKind CmpKind =
352 const X86::SecondMacroFusionInstKind BranchKind =
354 return X86::isMacroFused(CmpKind, BranchKind);
355}
356
357/// Check if the instruction has a variant symbol operand.
358static bool hasVariantSymbol(const MCInst &MI) {
359 for (auto &Operand : MI) {
360 if (!Operand.isExpr())
361 continue;
362 const MCExpr &Expr = *Operand.getExpr();
363 if (Expr.getKind() == MCExpr::SymbolRef &&
364 cast<MCSymbolRefExpr>(&Expr)->getSpecifier())
365 return true;
366 }
367 return false;
368}
369
370/// X86 has certain instructions which enable interrupts exactly one
371/// instruction *after* the instruction which stores to SS. Return true if the
372/// given instruction may have such an interrupt delay slot.
373static bool mayHaveInterruptDelaySlot(unsigned InstOpcode) {
374 switch (InstOpcode) {
375 case X86::POPSS16:
376 case X86::POPSS32:
377 case X86::STI:
378 return true;
379
380 case X86::MOV16sr:
381 case X86::MOV32sr:
382 case X86::MOV64sr:
383 case X86::MOV16sm:
384 // In fact, this is only the case if the first operand is SS. However, as
385 // segment moves occur extremely rarely, this is just a minor pessimization.
386 return true;
387 }
388 return false;
389}
390
391/// Return true if we can insert NOP or prefixes automatically before the
392/// the instruction to be emitted.
393bool X86AsmBackend::canPadInst(const MCInst &Inst, MCObjectStreamer &OS) const {
394 if (hasVariantSymbol(Inst))
395 // Linker may rewrite the instruction with variant symbol operand(e.g.
396 // TLSCALL).
397 return false;
398
399 if (mayHaveInterruptDelaySlot(PrevInstOpcode))
400 // If this instruction follows an interrupt enabling instruction with a one
401 // instruction delay, inserting a nop would change behavior.
402 return false;
403
404 if (isPrefix(PrevInstOpcode, *MCII))
405 // If this instruction follows a prefix, inserting a nop/prefix would change
406 // semantic.
407 return false;
408
409 if (isPrefix(Inst.getOpcode(), *MCII))
410 // If this instruction is a prefix, inserting a prefix would change
411 // semantic.
412 return false;
413
414 // If this instruction follows any data, there is no clear instruction
415 // boundary, inserting a nop/prefix would change semantic.
416 auto Offset = OS.getCurFragSize();
417 if (Offset && (OS.getCurrentFragment() != PrevInstPosition.first ||
418 Offset != PrevInstPosition.second))
419 return false;
420
421 return true;
422}
423
424bool X86AsmBackend::canPadBranches(MCObjectStreamer &OS) const {
425 if (!OS.getAllowAutoPadding())
426 return false;
427 assert(allowAutoPadding() && "incorrect initialization!");
428
429 // We only pad in text section.
430 if (!OS.getCurrentSectionOnly()->isText())
431 return false;
432
433 // Branches only need to be aligned in 32-bit or 64-bit mode.
434 if (!(STI.hasFeature(X86::Is64Bit) || STI.hasFeature(X86::Is32Bit)))
435 return false;
436
437 return true;
438}
439
440/// Check if the instruction operand needs to be aligned.
441bool X86AsmBackend::needAlign(const MCInst &Inst) const {
442 const MCInstrDesc &Desc = MCII->get(Inst.getOpcode());
443 return (Desc.isConditionalBranch() &&
444 (AlignBranchType & X86::AlignBranchJcc)) ||
445 (Desc.isUnconditionalBranch() &&
446 (AlignBranchType & X86::AlignBranchJmp)) ||
447 (Desc.isCall() && (AlignBranchType & X86::AlignBranchCall)) ||
448 (Desc.isReturn() && (AlignBranchType & X86::AlignBranchRet)) ||
449 (Desc.isIndirectBranch() &&
450 (AlignBranchType & X86::AlignBranchIndirect));
451}
452
454 const MCSubtargetInfo &STI) {
455 bool AutoPadding = S.getAllowAutoPadding();
456 if (LLVM_LIKELY(!AutoPadding && !X86PadForAlign)) {
457 S.MCObjectStreamer::emitInstruction(Inst, STI);
458 return;
459 }
460
461 auto &Backend = static_cast<X86AsmBackend &>(S.getAssembler().getBackend());
462 Backend.emitInstructionBegin(S, Inst, STI);
463 S.MCObjectStreamer::emitInstruction(Inst, STI);
464 Backend.emitInstructionEnd(S, Inst);
465}
466
467/// Insert BoundaryAlignFragment before instructions to align branches.
468void X86AsmBackend::emitInstructionBegin(MCObjectStreamer &OS,
469 const MCInst &Inst, const MCSubtargetInfo &STI) {
470 bool CanPadInst = canPadInst(Inst, OS);
471 if (CanPadInst)
473
474 if (!canPadBranches(OS))
475 return;
476
477 // NB: PrevInst only valid if canPadBranches is true.
478 if (!isMacroFused(PrevInst, Inst))
479 // Macro fusion doesn't happen indeed, clear the pending.
480 PendingBA = nullptr;
481
482 // When branch padding is enabled (basically the skx102 erratum => unlikely),
483 // we call canPadInst (not cheap) twice. However, in the common case, we can
484 // avoid unnecessary calls to that, as this is otherwise only used for
485 // relaxable fragments.
486 if (!CanPadInst)
487 return;
488
489 if (PendingBA) {
490 auto *NextFragment = PendingBA->getNext();
491 assert(NextFragment && "NextFragment should not be null");
492 if (NextFragment == OS.getCurrentFragment())
493 return;
494 // We eagerly create an empty fragment when inserting a fragment
495 // with a variable-size tail.
496 if (NextFragment->getNext() == OS.getCurrentFragment())
497 return;
498
499 // Macro fusion actually happens and there is no other fragment inserted
500 // after the previous instruction.
501 //
502 // Do nothing here since we already inserted a BoudaryAlign fragment when
503 // we met the first instruction in the fused pair and we'll tie them
504 // together in emitInstructionEnd.
505 //
506 // Note: When there is at least one fragment, such as MCAlignFragment,
507 // inserted after the previous instruction, e.g.
508 //
509 // \code
510 // cmp %rax %rcx
511 // .align 16
512 // je .Label0
513 // \ endcode
514 //
515 // We will treat the JCC as a unfused branch although it may be fused
516 // with the CMP.
517 return;
518 }
519
520 if (needAlign(Inst) || ((AlignBranchType & X86::AlignBranchFused) &&
521 isFirstMacroFusibleInst(Inst, *MCII))) {
522 // If we meet a unfused branch or the first instuction in a fusiable pair,
523 // insert a BoundaryAlign fragment.
524 PendingBA =
525 OS.newSpecialFragment<MCBoundaryAlignFragment>(AlignBoundary, STI);
526 }
527}
528
529/// Set the last fragment to be aligned for the BoundaryAlignFragment.
530void X86AsmBackend::emitInstructionEnd(MCObjectStreamer &OS,
531 const MCInst &Inst) {
532 // Update PrevInstOpcode here, canPadInst() reads that.
533 MCFragment *CF = OS.getCurrentFragment();
534 PrevInstOpcode = Inst.getOpcode();
535 PrevInstPosition = std::make_pair(CF, OS.getCurFragSize());
536
537 if (!canPadBranches(OS))
538 return;
539
540 // PrevInst is only needed if canPadBranches. Copying an MCInst isn't cheap.
541 PrevInst = Inst;
542
543 if (!needAlign(Inst) || !PendingBA)
544 return;
545
546 // Tie the aligned instructions into a pending BoundaryAlign.
547 PendingBA->setLastFragment(CF);
548 PendingBA = nullptr;
549
550 // We need to ensure that further data isn't added to the current
551 // DataFragment, so that we can get the size of instructions later in
552 // MCAssembler::relaxBoundaryAlign. The easiest way is to insert a new empty
553 // DataFragment.
554 OS.newFragment();
555
556 // Update the maximum alignment on the current section if necessary.
557 CF->getParent()->ensureMinAlignment(AlignBoundary);
558}
559
560std::optional<MCFixupKind> X86AsmBackend::getFixupKind(StringRef Name) const {
561 if (STI.getTargetTriple().isOSBinFormatELF()) {
562 unsigned Type;
563 if (STI.getTargetTriple().isX86_64()) {
564 Type = llvm::StringSwitch<unsigned>(Name)
565#define ELF_RELOC(X, Y) .Case(#X, Y)
566#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
567#undef ELF_RELOC
568 .Case("BFD_RELOC_NONE", ELF::R_X86_64_NONE)
569 .Case("BFD_RELOC_8", ELF::R_X86_64_8)
570 .Case("BFD_RELOC_16", ELF::R_X86_64_16)
571 .Case("BFD_RELOC_32", ELF::R_X86_64_32)
572 .Case("BFD_RELOC_64", ELF::R_X86_64_64)
573 .Default(-1u);
574 } else {
575 Type = llvm::StringSwitch<unsigned>(Name)
576#define ELF_RELOC(X, Y) .Case(#X, Y)
577#include "llvm/BinaryFormat/ELFRelocs/i386.def"
578#undef ELF_RELOC
579 .Case("BFD_RELOC_NONE", ELF::R_386_NONE)
580 .Case("BFD_RELOC_8", ELF::R_386_8)
581 .Case("BFD_RELOC_16", ELF::R_386_16)
582 .Case("BFD_RELOC_32", ELF::R_386_32)
583 .Default(-1u);
584 }
585 if (Type == -1u)
586 return std::nullopt;
587 return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
588 }
589 return MCAsmBackend::getFixupKind(Name);
590}
591
592MCFixupKindInfo X86AsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
593 const static MCFixupKindInfo Infos[X86::NumTargetFixupKinds] = {
594 // clang-format off
595 {"reloc_riprel_4byte", 0, 32, 0},
596 {"reloc_riprel_4byte_movq_load", 0, 32, 0},
597 {"reloc_riprel_4byte_movq_load_rex2", 0, 32, 0},
598 {"reloc_riprel_4byte_relax", 0, 32, 0},
599 {"reloc_riprel_4byte_relax_rex", 0, 32, 0},
600 {"reloc_riprel_4byte_relax_rex2", 0, 32, 0},
601 {"reloc_riprel_4byte_relax_evex", 0, 32, 0},
602 {"reloc_signed_4byte", 0, 32, 0},
603 {"reloc_signed_4byte_relax", 0, 32, 0},
604 {"reloc_global_offset_table", 0, 32, 0},
605 {"reloc_branch_4byte_pcrel", 0, 32, 0},
606 // clang-format on
607 };
608
609 // Fixup kinds from .reloc directive are like R_386_NONE/R_X86_64_NONE. They
610 // do not require any extra processing.
611 if (mc::isRelocation(Kind))
612 return {};
613
614 if (Kind < FirstTargetFixupKind)
616
618 "Invalid kind!");
619 assert(Infos[Kind - FirstTargetFixupKind].Name && "Empty fixup name!");
620 return Infos[Kind - FirstTargetFixupKind];
621}
622
623static unsigned getFixupKindSize(unsigned Kind) {
624 switch (Kind) {
625 default:
626 llvm_unreachable("invalid fixup kind!");
627 case FK_NONE:
628 return 0;
629 case FK_SecRel_1:
630 case FK_Data_1:
631 return 1;
632 case FK_SecRel_2:
633 case FK_Data_2:
634 return 2;
646 case FK_SecRel_4:
647 case FK_Data_4:
648 return 4;
649 case FK_SecRel_8:
650 case FK_Data_8:
651 return 8;
652 }
653}
654
655constexpr char GotSymName[] = "_GLOBAL_OFFSET_TABLE_";
656
657// Adjust PC-relative fixup offsets, which are calculated from the start of the
658// next instruction.
659std::optional<bool> X86AsmBackend::evaluateFixup(const MCFragment &,
660 MCFixup &Fixup,
661 MCValue &Target, uint64_t &) {
662 if (Fixup.isPCRel()) {
663 switch (Fixup.getKind()) {
664 case FK_Data_1:
665 Target.setConstant(Target.getConstant() - 1);
666 break;
667 case FK_Data_2:
668 Target.setConstant(Target.getConstant() - 2);
669 break;
670 default: {
671 Target.setConstant(Target.getConstant() - 4);
672 auto *Add = Target.getAddSym();
673 // If this is a pc-relative load off _GLOBAL_OFFSET_TABLE_:
674 // leaq _GLOBAL_OFFSET_TABLE_(%rip), %r15
675 // this needs to be a GOTPC32 relocation.
676 if (Add && Add->getName() == GotSymName)
677 Fixup = MCFixup::create(Fixup.getOffset(), Fixup.getValue(),
679 } break;
680 }
681 }
682 // Use default handling for `Value` and `IsResolved`.
683 return {};
684}
685
686void X86AsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
687 const MCValue &Target, uint8_t *Data,
688 uint64_t Value, bool IsResolved) {
689 // Force relocation when there is a specifier. This might be too conservative
690 // - GAS doesn't emit a relocation for call local@plt; local:.
691 if (Target.getSpecifier())
692 IsResolved = false;
693 maybeAddReloc(F, Fixup, Target, Value, IsResolved);
694
695 auto Kind = Fixup.getKind();
696 if (mc::isRelocation(Kind))
697 return;
698 unsigned Size = getFixupKindSize(Kind);
699
700 assert(Fixup.getOffset() + Size <= F.getSize() && "Invalid fixup offset!");
701
702 // Check fixup value overflow similar to GAS (fixups emitted as RELA
703 // relocations have a value of 0).
704 // - Unknown signedness: the range (-2^N, 2^N) is allowed,
705 // accommodating intN_t, uintN_t, and a non-positive value type.
706 // - Signed (intN_t): the range [-2^(N-1), 2^(N-1)) is allowed.
707 //
708 // Currently only resolved PC-relative fixups are treated as signed. GAS
709 // treats more as signed (e.g. unresolved R_X86_64_32S).
710 // Unresolved fixups have unknown signedness to allow `jmp foo+0xffffffff`.
711 if (Size && Size < 8) {
712 bool Signed = IsResolved && Fixup.isPCRel();
713 uint64_t Mask = ~uint64_t(0) << (Size * 8 - (Signed ? 1 : 0));
714 if ((Value & Mask) && (Signed ? (Value & Mask) != Mask : (-Value & Mask)))
715 getContext().reportError(Fixup.getLoc(),
716 "value of " + Twine(int64_t(Value)) +
717 " is too large for field of " + Twine(Size) +
718 (Size == 1 ? " byte" : " bytes"));
719 }
720
721 for (unsigned i = 0; i != Size; ++i)
722 Data[i] = uint8_t(Value >> (i * 8));
723}
724
725bool X86AsmBackend::mayNeedRelaxation(unsigned Opcode,
726 ArrayRef<MCOperand> Operands,
727 const MCSubtargetInfo &STI) const {
728 unsigned SkipOperands = X86::isCCMPCC(Opcode) ? 2 : 0;
729 return isRelaxableBranch(Opcode) ||
730 (X86::getOpcodeForLongImmediateForm(Opcode) != Opcode &&
731 Operands[Operands.size() - 1 - SkipOperands].isExpr());
732}
733
734bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCFragment &,
735 const MCFixup &Fixup,
736 const MCValue &Target,
737 uint64_t Value,
738 bool Resolved) const {
739 // If resolved, relax if the value is too big for a (signed) i8.
740 //
741 // Currently, `jmp local@plt` relaxes JMP even if the offset is small,
742 // different from gas.
743 if (Resolved)
744 return !isInt<8>(Value) || Target.getSpecifier();
745
746 // Otherwise, relax unless there is a @ABS8 specifier.
747 if (Fixup.getKind() == FK_Data_1 && Target.getAddSym() &&
748 Target.getSpecifier() == X86::S_ABS8)
749 return false;
750 return true;
751}
752
753// FIXME: Can tblgen help at all here to verify there aren't other instructions
754// we can relax?
755void X86AsmBackend::relaxInstruction(MCInst &Inst,
756 const MCSubtargetInfo &STI) const {
757 // The only relaxations X86 does is from a 1byte pcrel to a 4byte pcrel.
758 bool Is16BitMode = STI.hasFeature(X86::Is16Bit);
759 unsigned RelaxedOp = getRelaxedOpcode(Inst, Is16BitMode);
760 assert(RelaxedOp != Inst.getOpcode());
761 Inst.setOpcode(RelaxedOp);
762}
763
764bool X86AsmBackend::padInstructionViaPrefix(MCFragment &RF,
765 MCCodeEmitter &Emitter,
766 unsigned &RemainingSize) const {
767 if (!RF.getAllowAutoPadding())
768 return false;
769 // If the instruction isn't fully relaxed, shifting it around might require a
770 // larger value for one of the fixups then can be encoded. The outer loop
771 // will also catch this before moving to the next instruction, but we need to
772 // prevent padding this single instruction as well.
773 if (mayNeedRelaxation(RF.getOpcode(), RF.getOperands(),
774 *RF.getSubtargetInfo()))
775 return false;
776
777 const unsigned OldSize = RF.getVarSize();
778 if (OldSize == 15)
779 return false;
780
781 const unsigned MaxPossiblePad = std::min(15 - OldSize, RemainingSize);
782 const unsigned RemainingPrefixSize = [&]() -> unsigned {
783 SmallString<15> Code;
784 X86_MC::emitPrefix(Emitter, RF.getInst(), Code, STI);
785 assert(Code.size() < 15 && "The number of prefixes must be less than 15.");
786
787 // TODO: It turns out we need a decent amount of plumbing for the target
788 // specific bits to determine number of prefixes its safe to add. Various
789 // targets (older chips mostly, but also Atom family) encounter decoder
790 // stalls with too many prefixes. For testing purposes, we set the value
791 // externally for the moment.
792 unsigned ExistingPrefixSize = Code.size();
793 if (TargetPrefixMax <= ExistingPrefixSize)
794 return 0;
795 return TargetPrefixMax - ExistingPrefixSize;
796 }();
797 const unsigned PrefixBytesToAdd =
798 std::min(MaxPossiblePad, RemainingPrefixSize);
799 if (PrefixBytesToAdd == 0)
800 return false;
801
802 const uint8_t Prefix = determinePaddingPrefix(RF.getInst());
803
804 SmallString<256> Code;
805 Code.append(PrefixBytesToAdd, Prefix);
806 Code.append(RF.getVarContents().begin(), RF.getVarContents().end());
807 RF.setVarContents(Code);
808
809 // Adjust the fixups for the change in offsets
810 for (auto &F : RF.getVarFixups())
811 F.setOffset(PrefixBytesToAdd + F.getOffset());
812
813 RemainingSize -= PrefixBytesToAdd;
814 return true;
815}
816
817bool X86AsmBackend::padInstructionViaRelaxation(MCFragment &RF,
818 MCCodeEmitter &Emitter,
819 unsigned &RemainingSize) const {
820 if (!mayNeedRelaxation(RF.getOpcode(), RF.getOperands(),
821 *RF.getSubtargetInfo()))
822 // TODO: There are lots of other tricks we could apply for increasing
823 // encoding size without impacting performance.
824 return false;
825
826 MCInst Relaxed = RF.getInst();
827 relaxInstruction(Relaxed, *RF.getSubtargetInfo());
828
830 SmallString<15> Code;
831 Emitter.encodeInstruction(Relaxed, Code, Fixups, *RF.getSubtargetInfo());
832 const unsigned OldSize = RF.getVarContents().size();
833 const unsigned NewSize = Code.size();
834 assert(NewSize >= OldSize && "size decrease during relaxation?");
835 unsigned Delta = NewSize - OldSize;
836 if (Delta > RemainingSize)
837 return false;
838 RF.setInst(Relaxed);
839 RF.setVarContents(Code);
840 RF.setVarFixups(Fixups);
841 RemainingSize -= Delta;
842 return true;
843}
844
845bool X86AsmBackend::padInstructionEncoding(MCFragment &RF,
846 MCCodeEmitter &Emitter,
847 unsigned &RemainingSize) const {
848 bool Changed = false;
849 if (RemainingSize != 0)
850 Changed |= padInstructionViaRelaxation(RF, Emitter, RemainingSize);
851 if (RemainingSize != 0)
852 Changed |= padInstructionViaPrefix(RF, Emitter, RemainingSize);
853 return Changed;
854}
855
856bool X86AsmBackend::finishLayout() const {
857 // See if we can further relax some instructions to cut down on the number of
858 // nop bytes required for code alignment. The actual win is in reducing
859 // instruction count, not number of bytes. Modern X86-64 can easily end up
860 // decode limited. It is often better to reduce the number of instructions
861 // (i.e. eliminate nops) even at the cost of increasing the size and
862 // complexity of others.
863 if (!X86PadForAlign && !X86PadForBranchAlign)
864 return false;
865
866 // The processed regions are delimitered by LabeledFragments. -g may have more
867 // MCSymbols and therefore different relaxation results. X86PadForAlign is
868 // disabled by default to eliminate the -g vs non -g difference.
869 DenseSet<MCFragment *> LabeledFragments;
870 for (const MCSymbol &S : Asm->symbols())
871 LabeledFragments.insert(S.getFragment());
872
873 bool Changed = false;
874 for (MCSection &Sec : *Asm) {
875 if (!Sec.isText())
876 continue;
877
879 for (MCSection::iterator I = Sec.begin(), IE = Sec.end(); I != IE; ++I) {
880 MCFragment &F = *I;
881
882 if (LabeledFragments.count(&F))
883 Relaxable.clear();
884
885 if (F.getKind() == MCFragment::FT_Data) // Skip and ignore
886 continue;
887
888 if (F.getKind() == MCFragment::FT_Relaxable) {
889 auto &RF = cast<MCFragment>(*I);
890 Relaxable.push_back(&RF);
891 continue;
892 }
893
894 auto canHandle = [](MCFragment &F) -> bool {
895 switch (F.getKind()) {
896 default:
897 return false;
899 return X86PadForAlign;
901 return X86PadForBranchAlign;
902 }
903 };
904 // For any unhandled kind, assume we can't change layout.
905 if (!canHandle(F)) {
906 Relaxable.clear();
907 continue;
908 }
909
910 // To keep the effects local, prefer to relax instructions closest to
911 // the align directive. This is purely about human understandability
912 // of the resulting code. If we later find a reason to expand
913 // particular instructions over others, we can adjust.
914 unsigned RemainingSize = Asm->computeFragmentSize(F) - F.getFixedSize();
915 while (!Relaxable.empty() && RemainingSize != 0) {
916 auto &RF = *Relaxable.pop_back_val();
917 // Give the backend a chance to play any tricks it wishes to increase
918 // the encoding size of the given instruction. Target independent code
919 // will try further relaxation, but target's may play further tricks.
920 Changed |= padInstructionEncoding(RF, Asm->getEmitter(), RemainingSize);
921
922 // If we have an instruction which hasn't been fully relaxed, we can't
923 // skip past it and insert bytes before it. Changing its starting
924 // offset might require a larger negative offset than it can encode.
925 // We don't need to worry about larger positive offsets as none of the
926 // possible offsets between this and our align are visible, and the
927 // ones afterwards aren't changing.
928 if (mayNeedRelaxation(RF.getOpcode(), RF.getOperands(),
929 *RF.getSubtargetInfo()))
930 break;
931 }
932 Relaxable.clear();
933
934 // If we're looking at a boundary align, make sure we don't try to pad
935 // its target instructions for some following directive. Doing so would
936 // break the alignment of the current boundary align.
937 if (auto *BF = dyn_cast<MCBoundaryAlignFragment>(&F)) {
938 cast<MCBoundaryAlignFragment>(F).setSize(RemainingSize);
939 Changed = true;
940 const MCFragment *LastFragment = BF->getLastFragment();
941 if (!LastFragment)
942 continue;
943 while (&*I != LastFragment)
944 ++I;
945 }
946 }
947 }
948
949 return Changed;
950}
951
952unsigned X86AsmBackend::getMaximumNopSize(const MCSubtargetInfo &STI) const {
953 if (STI.hasFeature(X86::Is16Bit))
954 return 4;
955 if (!STI.hasFeature(X86::FeatureNOPL) && !STI.hasFeature(X86::Is64Bit))
956 return 1;
957 if (STI.hasFeature(X86::TuningFast7ByteNOP))
958 return 7;
959 if (STI.hasFeature(X86::TuningFast15ByteNOP))
960 return 15;
961 if (STI.hasFeature(X86::TuningFast11ByteNOP))
962 return 11;
963 // FIXME: handle 32-bit mode
964 // 15-bytes is the longest single NOP instruction, but 10-bytes is
965 // commonly the longest that can be efficiently decoded.
966 return 10;
967}
968
969/// Write a sequence of optimal nops to the output, covering \p Count
970/// bytes.
971/// \return - true on success, false on failure
972bool X86AsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
973 const MCSubtargetInfo *STI) const {
974 static const char Nops32Bit[10][11] = {
975 // nop
976 "\x90",
977 // xchg %ax,%ax
978 "\x66\x90",
979 // nopl (%[re]ax)
980 "\x0f\x1f\x00",
981 // nopl 0(%[re]ax)
982 "\x0f\x1f\x40\x00",
983 // nopl 0(%[re]ax,%[re]ax,1)
984 "\x0f\x1f\x44\x00\x00",
985 // nopw 0(%[re]ax,%[re]ax,1)
986 "\x66\x0f\x1f\x44\x00\x00",
987 // nopl 0L(%[re]ax)
988 "\x0f\x1f\x80\x00\x00\x00\x00",
989 // nopl 0L(%[re]ax,%[re]ax,1)
990 "\x0f\x1f\x84\x00\x00\x00\x00\x00",
991 // nopw 0L(%[re]ax,%[re]ax,1)
992 "\x66\x0f\x1f\x84\x00\x00\x00\x00\x00",
993 // nopw %cs:0L(%[re]ax,%[re]ax,1)
994 "\x66\x2e\x0f\x1f\x84\x00\x00\x00\x00\x00",
995 };
996
997 // 16-bit mode uses different nop patterns than 32-bit.
998 static const char Nops16Bit[4][11] = {
999 // nop
1000 "\x90",
1001 // xchg %eax,%eax
1002 "\x66\x90",
1003 // lea 0(%si),%si
1004 "\x8d\x74\x00",
1005 // lea 0w(%si),%si
1006 "\x8d\xb4\x00\x00",
1007 };
1008
1009 const char(*Nops)[11] =
1010 STI->hasFeature(X86::Is16Bit) ? Nops16Bit : Nops32Bit;
1011
1012 uint64_t MaxNopLength = (uint64_t)getMaximumNopSize(*STI);
1013
1014 // Emit as many MaxNopLength NOPs as needed, then emit a NOP of the remaining
1015 // length.
1016 do {
1017 const uint8_t ThisNopLength = (uint8_t) std::min(Count, MaxNopLength);
1018 const uint8_t Prefixes = ThisNopLength <= 10 ? 0 : ThisNopLength - 10;
1019 for (uint8_t i = 0; i < Prefixes; i++)
1020 OS << '\x66';
1021 const uint8_t Rest = ThisNopLength - Prefixes;
1022 if (Rest != 0)
1023 OS.write(Nops[Rest - 1], Rest);
1024 Count -= ThisNopLength;
1025 } while (Count != 0);
1026
1027 return true;
1028}
1029
1030/* *** */
1031
1032namespace {
1033
1034class ELFX86AsmBackend : public X86AsmBackend {
1035public:
1036 uint8_t OSABI;
1037 ELFX86AsmBackend(const Target &T, uint8_t OSABI, const MCSubtargetInfo &STI)
1038 : X86AsmBackend(T, STI), OSABI(OSABI) {}
1039};
1040
1041class ELFX86_32AsmBackend : public ELFX86AsmBackend {
1042public:
1043 ELFX86_32AsmBackend(const Target &T, uint8_t OSABI,
1044 const MCSubtargetInfo &STI)
1045 : ELFX86AsmBackend(T, OSABI, STI) {}
1046
1047 std::unique_ptr<MCObjectTargetWriter>
1048 createObjectTargetWriter() const override {
1049 return createX86ELFObjectWriter(/*IsELF64*/ false, OSABI, ELF::EM_386);
1050 }
1051};
1052
1053class ELFX86_X32AsmBackend : public ELFX86AsmBackend {
1054public:
1055 ELFX86_X32AsmBackend(const Target &T, uint8_t OSABI,
1056 const MCSubtargetInfo &STI)
1057 : ELFX86AsmBackend(T, OSABI, STI) {}
1058
1059 std::unique_ptr<MCObjectTargetWriter>
1060 createObjectTargetWriter() const override {
1061 return createX86ELFObjectWriter(/*IsELF64*/ false, OSABI,
1063 }
1064};
1065
1066class ELFX86_IAMCUAsmBackend : public ELFX86AsmBackend {
1067public:
1068 ELFX86_IAMCUAsmBackend(const Target &T, uint8_t OSABI,
1069 const MCSubtargetInfo &STI)
1070 : ELFX86AsmBackend(T, OSABI, STI) {}
1071
1072 std::unique_ptr<MCObjectTargetWriter>
1073 createObjectTargetWriter() const override {
1074 return createX86ELFObjectWriter(/*IsELF64*/ false, OSABI,
1076 }
1077};
1078
1079class ELFX86_64AsmBackend : public ELFX86AsmBackend {
1080public:
1081 ELFX86_64AsmBackend(const Target &T, uint8_t OSABI,
1082 const MCSubtargetInfo &STI)
1083 : ELFX86AsmBackend(T, OSABI, STI) {}
1084
1085 std::unique_ptr<MCObjectTargetWriter>
1086 createObjectTargetWriter() const override {
1087 return createX86ELFObjectWriter(/*IsELF64*/ true, OSABI, ELF::EM_X86_64);
1088 }
1089};
1090
1091class WindowsX86AsmBackend : public X86AsmBackend {
1092 bool Is64Bit;
1093
1094public:
1095 WindowsX86AsmBackend(const Target &T, bool is64Bit,
1096 const MCSubtargetInfo &STI)
1097 : X86AsmBackend(T, STI)
1098 , Is64Bit(is64Bit) {
1099 }
1100
1101 std::optional<MCFixupKind> getFixupKind(StringRef Name) const override {
1102 return StringSwitch<std::optional<MCFixupKind>>(Name)
1103 .Case("dir32", FK_Data_4)
1104 .Case("secrel32", FK_SecRel_4)
1105 .Case("secidx", FK_SecRel_2)
1106 .Default(MCAsmBackend::getFixupKind(Name));
1107 }
1108
1109 std::unique_ptr<MCObjectTargetWriter>
1110 createObjectTargetWriter() const override {
1111 return createX86WinCOFFObjectWriter(Is64Bit);
1112 }
1113};
1114
1115namespace CU {
1116
1117 /// Compact unwind encoding values.
1118 enum CompactUnwindEncodings {
1119 /// [RE]BP based frame where [RE]BP is pused on the stack immediately after
1120 /// the return address, then [RE]SP is moved to [RE]BP.
1121 UNWIND_MODE_BP_FRAME = 0x01000000,
1122
1123 /// A frameless function with a small constant stack size.
1124 UNWIND_MODE_STACK_IMMD = 0x02000000,
1125
1126 /// A frameless function with a large constant stack size.
1127 UNWIND_MODE_STACK_IND = 0x03000000,
1128
1129 /// No compact unwind encoding is available.
1130 UNWIND_MODE_DWARF = 0x04000000,
1131
1132 /// Mask for encoding the frame registers.
1133 UNWIND_BP_FRAME_REGISTERS = 0x00007FFF,
1134
1135 /// Mask for encoding the frameless registers.
1136 UNWIND_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF
1137 };
1138
1139} // namespace CU
1140
1141class DarwinX86AsmBackend : public X86AsmBackend {
1142 const MCRegisterInfo &MRI;
1143
1144 /// Number of registers that can be saved in a compact unwind encoding.
1145 enum { CU_NUM_SAVED_REGS = 6 };
1146
1147 mutable unsigned SavedRegs[CU_NUM_SAVED_REGS];
1148 Triple TT;
1149 bool Is64Bit;
1150
1151 unsigned OffsetSize; ///< Offset of a "push" instruction.
1152 unsigned MoveInstrSize; ///< Size of a "move" instruction.
1153 unsigned StackDivide; ///< Amount to adjust stack size by.
1154protected:
1155 /// Size of a "push" instruction for the given register.
1156 unsigned PushInstrSize(MCRegister Reg) const {
1157 switch (Reg.id()) {
1158 case X86::EBX:
1159 case X86::ECX:
1160 case X86::EDX:
1161 case X86::EDI:
1162 case X86::ESI:
1163 case X86::EBP:
1164 case X86::RBX:
1165 case X86::RBP:
1166 return 1;
1167 case X86::R12:
1168 case X86::R13:
1169 case X86::R14:
1170 case X86::R15:
1171 return 2;
1172 }
1173 return 1;
1174 }
1175
1176private:
1177 /// Get the compact unwind number for a given register. The number
1178 /// corresponds to the enum lists in compact_unwind_encoding.h.
1179 int getCompactUnwindRegNum(unsigned Reg) const {
1180 static const MCPhysReg CU32BitRegs[7] = {
1181 X86::EBX, X86::ECX, X86::EDX, X86::EDI, X86::ESI, X86::EBP, 0
1182 };
1183 static const MCPhysReg CU64BitRegs[] = {
1184 X86::RBX, X86::R12, X86::R13, X86::R14, X86::R15, X86::RBP, 0
1185 };
1186 const MCPhysReg *CURegs = Is64Bit ? CU64BitRegs : CU32BitRegs;
1187 for (int Idx = 1; *CURegs; ++CURegs, ++Idx)
1188 if (*CURegs == Reg)
1189 return Idx;
1190
1191 return -1;
1192 }
1193
1194 /// Return the registers encoded for a compact encoding with a frame
1195 /// pointer.
1196 uint32_t encodeCompactUnwindRegistersWithFrame() const {
1197 // Encode the registers in the order they were saved --- 3-bits per
1198 // register. The list of saved registers is assumed to be in reverse
1199 // order. The registers are numbered from 1 to CU_NUM_SAVED_REGS.
1200 uint32_t RegEnc = 0;
1201 for (int i = 0, Idx = 0; i != CU_NUM_SAVED_REGS; ++i) {
1202 unsigned Reg = SavedRegs[i];
1203 if (Reg == 0) break;
1204
1205 int CURegNum = getCompactUnwindRegNum(Reg);
1206 if (CURegNum == -1) return ~0U;
1207
1208 // Encode the 3-bit register number in order, skipping over 3-bits for
1209 // each register.
1210 RegEnc |= (CURegNum & 0x7) << (Idx++ * 3);
1211 }
1212
1213 assert((RegEnc & 0x3FFFF) == RegEnc &&
1214 "Invalid compact register encoding!");
1215 return RegEnc;
1216 }
1217
1218 /// Create the permutation encoding used with frameless stacks. It is
1219 /// passed the number of registers to be saved and an array of the registers
1220 /// saved.
1221 uint32_t encodeCompactUnwindRegistersWithoutFrame(unsigned RegCount) const {
1222 // The saved registers are numbered from 1 to 6. In order to encode the
1223 // order in which they were saved, we re-number them according to their
1224 // place in the register order. The re-numbering is relative to the last
1225 // re-numbered register. E.g., if we have registers {6, 2, 4, 5} saved in
1226 // that order:
1227 //
1228 // Orig Re-Num
1229 // ---- ------
1230 // 6 6
1231 // 2 2
1232 // 4 3
1233 // 5 3
1234 //
1235 for (unsigned i = 0; i < RegCount; ++i) {
1236 int CUReg = getCompactUnwindRegNum(SavedRegs[i]);
1237 if (CUReg == -1) return ~0U;
1238 SavedRegs[i] = CUReg;
1239 }
1240
1241 // Reverse the list.
1242 std::reverse(&SavedRegs[0], &SavedRegs[CU_NUM_SAVED_REGS]);
1243
1244 uint32_t RenumRegs[CU_NUM_SAVED_REGS];
1245 for (unsigned i = CU_NUM_SAVED_REGS - RegCount; i < CU_NUM_SAVED_REGS; ++i){
1246 unsigned Countless = 0;
1247 for (unsigned j = CU_NUM_SAVED_REGS - RegCount; j < i; ++j)
1248 if (SavedRegs[j] < SavedRegs[i])
1249 ++Countless;
1250
1251 RenumRegs[i] = SavedRegs[i] - Countless - 1;
1252 }
1253
1254 // Take the renumbered values and encode them into a 10-bit number.
1255 uint32_t permutationEncoding = 0;
1256 switch (RegCount) {
1257 case 6:
1258 permutationEncoding |= 120 * RenumRegs[0] + 24 * RenumRegs[1]
1259 + 6 * RenumRegs[2] + 2 * RenumRegs[3]
1260 + RenumRegs[4];
1261 break;
1262 case 5:
1263 permutationEncoding |= 120 * RenumRegs[1] + 24 * RenumRegs[2]
1264 + 6 * RenumRegs[3] + 2 * RenumRegs[4]
1265 + RenumRegs[5];
1266 break;
1267 case 4:
1268 permutationEncoding |= 60 * RenumRegs[2] + 12 * RenumRegs[3]
1269 + 3 * RenumRegs[4] + RenumRegs[5];
1270 break;
1271 case 3:
1272 permutationEncoding |= 20 * RenumRegs[3] + 4 * RenumRegs[4]
1273 + RenumRegs[5];
1274 break;
1275 case 2:
1276 permutationEncoding |= 5 * RenumRegs[4] + RenumRegs[5];
1277 break;
1278 case 1:
1279 permutationEncoding |= RenumRegs[5];
1280 break;
1281 }
1282
1283 assert((permutationEncoding & 0x3FF) == permutationEncoding &&
1284 "Invalid compact register encoding!");
1285 return permutationEncoding;
1286 }
1287
1288public:
1289 DarwinX86AsmBackend(const Target &T, const MCRegisterInfo &MRI,
1290 const MCSubtargetInfo &STI)
1291 : X86AsmBackend(T, STI), MRI(MRI), TT(STI.getTargetTriple()),
1292 Is64Bit(TT.isX86_64()) {
1293 memset(SavedRegs, 0, sizeof(SavedRegs));
1294 OffsetSize = Is64Bit ? 8 : 4;
1295 MoveInstrSize = Is64Bit ? 3 : 2;
1296 StackDivide = Is64Bit ? 8 : 4;
1297 }
1298
1299 std::unique_ptr<MCObjectTargetWriter>
1300 createObjectTargetWriter() const override {
1301 uint32_t CPUType = cantFail(MachO::getCPUType(TT));
1302 uint32_t CPUSubType = cantFail(MachO::getCPUSubType(TT));
1303 return createX86MachObjectWriter(Is64Bit, CPUType, CPUSubType);
1304 }
1305
1306 /// Implementation of algorithm to generate the compact unwind encoding
1307 /// for the CFI instructions.
1308 uint64_t generateCompactUnwindEncoding(const MCDwarfFrameInfo *FI,
1309 const MCContext *Ctxt) const override {
1310 if (Ctxt->emitDwarfUnwindInfo() == EmitDwarfUnwindType::DwarfOnly)
1311 return CU::UNWIND_MODE_DWARF;
1312
1313 // Signal frames cannot be encoded in compact unwind.
1314 if (FI->IsSignalFrame)
1315 return CU::UNWIND_MODE_DWARF;
1316
1318 if (Instrs.empty()) return 0;
1319 if (!isDarwinCanonicalPersonality(FI->Personality) &&
1321 return CU::UNWIND_MODE_DWARF;
1322
1323 // Reset the saved registers.
1324 unsigned SavedRegIdx = 0;
1325 memset(SavedRegs, 0, sizeof(SavedRegs));
1326
1327 bool HasFP = false;
1328
1329 // Encode that we are using EBP/RBP as the frame pointer.
1330 uint64_t CompactUnwindEncoding = 0;
1331
1332 unsigned SubtractInstrIdx = Is64Bit ? 3 : 2;
1333 unsigned InstrOffset = 0;
1334 unsigned StackAdjust = 0;
1335 uint64_t StackSize = 0;
1336 int64_t MinAbsOffset = std::numeric_limits<int64_t>::max();
1337
1338 for (const MCCFIInstruction &Inst : Instrs) {
1339 switch (Inst.getOperation()) {
1340 default:
1341 // Any other CFI directives indicate a frame that we aren't prepared
1342 // to represent via compact unwind, so just bail out.
1343 return CU::UNWIND_MODE_DWARF;
1345 // Defines a frame pointer. E.g.
1346 //
1347 // movq %rsp, %rbp
1348 // L0:
1349 // .cfi_def_cfa_register %rbp
1350 //
1351 HasFP = true;
1352
1353 // If the frame pointer is other than esp/rsp, we do not have a way to
1354 // generate a compact unwinding representation, so bail out.
1355 if (*MRI.getLLVMRegNum(Inst.getRegister(), true) !=
1356 (Is64Bit ? X86::RBP : X86::EBP))
1357 return CU::UNWIND_MODE_DWARF;
1358
1359 // Reset the counts.
1360 memset(SavedRegs, 0, sizeof(SavedRegs));
1361 StackAdjust = 0;
1362 SavedRegIdx = 0;
1363 MinAbsOffset = std::numeric_limits<int64_t>::max();
1364 InstrOffset += MoveInstrSize;
1365 break;
1366 }
1368 // Defines a new offset for the CFA. E.g.
1369 //
1370 // With frame:
1371 //
1372 // pushq %rbp
1373 // L0:
1374 // .cfi_def_cfa_offset 16
1375 //
1376 // Without frame:
1377 //
1378 // subq $72, %rsp
1379 // L0:
1380 // .cfi_def_cfa_offset 80
1381 //
1382 StackSize = Inst.getOffset() / StackDivide;
1383 break;
1384 }
1386 // Defines a "push" of a callee-saved register. E.g.
1387 //
1388 // pushq %r15
1389 // pushq %r14
1390 // pushq %rbx
1391 // L0:
1392 // subq $120, %rsp
1393 // L1:
1394 // .cfi_offset %rbx, -40
1395 // .cfi_offset %r14, -32
1396 // .cfi_offset %r15, -24
1397 //
1398 if (SavedRegIdx == CU_NUM_SAVED_REGS)
1399 // If there are too many saved registers, we cannot use a compact
1400 // unwind encoding.
1401 return CU::UNWIND_MODE_DWARF;
1402
1403 MCRegister Reg = *MRI.getLLVMRegNum(Inst.getRegister(), true);
1404 SavedRegs[SavedRegIdx++] = Reg.id();
1405 StackAdjust += OffsetSize;
1406 MinAbsOffset = std::min(MinAbsOffset, std::abs(Inst.getOffset()));
1407 InstrOffset += PushInstrSize(Reg);
1408 break;
1409 }
1410 }
1411 }
1412
1413 StackAdjust /= StackDivide;
1414
1415 if (HasFP) {
1416 if ((StackAdjust & 0xFF) != StackAdjust)
1417 // Offset was too big for a compact unwind encoding.
1418 return CU::UNWIND_MODE_DWARF;
1419
1420 // We don't attempt to track a real StackAdjust, so if the saved registers
1421 // aren't adjacent to rbp we can't cope.
1422 if (SavedRegIdx != 0 && MinAbsOffset != 3 * (int)OffsetSize)
1423 return CU::UNWIND_MODE_DWARF;
1424
1425 // Get the encoding of the saved registers when we have a frame pointer.
1426 uint32_t RegEnc = encodeCompactUnwindRegistersWithFrame();
1427 if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
1428
1429 CompactUnwindEncoding |= CU::UNWIND_MODE_BP_FRAME;
1430 CompactUnwindEncoding |= (StackAdjust & 0xFF) << 16;
1431 CompactUnwindEncoding |= RegEnc & CU::UNWIND_BP_FRAME_REGISTERS;
1432 } else {
1433 SubtractInstrIdx += InstrOffset;
1434 ++StackAdjust;
1435
1436 if ((StackSize & 0xFF) == StackSize) {
1437 // Frameless stack with a small stack size.
1438 CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IMMD;
1439
1440 // Encode the stack size.
1441 CompactUnwindEncoding |= (StackSize & 0xFF) << 16;
1442 } else {
1443 if ((StackAdjust & 0x7) != StackAdjust)
1444 // The extra stack adjustments are too big for us to handle.
1445 return CU::UNWIND_MODE_DWARF;
1446
1447 // Frameless stack with an offset too large for us to encode compactly.
1448 CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IND;
1449
1450 // Encode the offset to the nnnnnn value in the 'subl $nnnnnn, ESP'
1451 // instruction.
1452 CompactUnwindEncoding |= (SubtractInstrIdx & 0xFF) << 16;
1453
1454 // Encode any extra stack adjustments (done via push instructions).
1455 CompactUnwindEncoding |= (StackAdjust & 0x7) << 13;
1456 }
1457
1458 // Encode the number of registers saved. (Reverse the list first.)
1459 std::reverse(&SavedRegs[0], &SavedRegs[SavedRegIdx]);
1460 CompactUnwindEncoding |= (SavedRegIdx & 0x7) << 10;
1461
1462 // Get the encoding of the saved registers when we don't have a frame
1463 // pointer.
1464 uint32_t RegEnc = encodeCompactUnwindRegistersWithoutFrame(SavedRegIdx);
1465 if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
1466
1467 // Encode the register encoding.
1468 CompactUnwindEncoding |=
1469 RegEnc & CU::UNWIND_FRAMELESS_STACK_REG_PERMUTATION;
1470 }
1471
1472 return CompactUnwindEncoding;
1473 }
1474};
1475
1476} // end anonymous namespace
1477
1479 const MCSubtargetInfo &STI,
1480 const MCRegisterInfo &MRI,
1481 const MCTargetOptions &Options) {
1482 const Triple &TheTriple = STI.getTargetTriple();
1483 if (TheTriple.isOSBinFormatMachO())
1484 return new DarwinX86AsmBackend(T, MRI, STI);
1485
1486 if (TheTriple.isOSWindows() && TheTriple.isOSBinFormatCOFF())
1487 return new WindowsX86AsmBackend(T, false, STI);
1488
1489 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
1490
1491 if (TheTriple.isOSIAMCU())
1492 return new ELFX86_IAMCUAsmBackend(T, OSABI, STI);
1493
1494 return new ELFX86_32AsmBackend(T, OSABI, STI);
1495}
1496
1498 const MCSubtargetInfo &STI,
1499 const MCRegisterInfo &MRI,
1500 const MCTargetOptions &Options) {
1501 const Triple &TheTriple = STI.getTargetTriple();
1502 if (TheTriple.isOSBinFormatMachO())
1503 return new DarwinX86AsmBackend(T, MRI, STI);
1504
1505 if (TheTriple.isOSWindows() && TheTriple.isOSBinFormatCOFF())
1506 return new WindowsX86AsmBackend(T, true, STI);
1507
1508 if (TheTriple.isUEFI()) {
1509 assert(TheTriple.isOSBinFormatCOFF() &&
1510 "Only COFF format is supported in UEFI environment.");
1511 return new WindowsX86AsmBackend(T, true, STI);
1512 }
1513
1514 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
1515
1516 if (TheTriple.isX32())
1517 return new ELFX86_X32AsmBackend(T, OSABI, STI);
1518 return new ELFX86_64AsmBackend(T, OSABI, STI);
1519}
1520
1521namespace {
1522class X86ELFStreamer : public MCELFStreamer {
1523public:
1524 X86ELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
1525 std::unique_ptr<MCObjectWriter> OW,
1526 std::unique_ptr<MCCodeEmitter> Emitter)
1527 : MCELFStreamer(Context, std::move(TAB), std::move(OW),
1528 std::move(Emitter)) {}
1529
1530 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
1531};
1532} // end anonymous namespace
1533
1534void X86ELFStreamer::emitInstruction(const MCInst &Inst,
1535 const MCSubtargetInfo &STI) {
1536 X86_MC::emitInstruction(*this, Inst, STI);
1537}
1538
1540 std::unique_ptr<MCAsmBackend> &&MAB,
1541 std::unique_ptr<MCObjectWriter> &&MOW,
1542 std::unique_ptr<MCCodeEmitter> &&MCE) {
1543 return new X86ELFStreamer(Context, std::move(MAB), std::move(MOW),
1544 std::move(MCE));
1545}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_LIKELY(EXPR)
Definition Compiler.h:337
dxil DXContainer Global Emitter
IRTranslator LLVM IR MI
static LVOptions Options
Definition LVOptions.cpp:25
static unsigned getRelaxedOpcode(unsigned Opcode)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
#define T
PowerPC TLS Dynamic Call Fixup
if(PassOpts->AAPipeline)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static MCInstrInfo * createMCInstrInfo()
static unsigned getRelaxedOpcodeBranch(unsigned Opcode, bool Is16BitMode=false)
static X86::SecondMacroFusionInstKind classifySecondInstInMacroFusion(const MCInst &MI, const MCInstrInfo &MCII)
static bool isRIPRelative(const MCInst &MI, const MCInstrInfo &MCII)
Check if the instruction uses RIP relative addressing.
static bool mayHaveInterruptDelaySlot(unsigned InstOpcode)
X86 has certain instructions which enable interrupts exactly one instruction after the instruction wh...
static bool isFirstMacroFusibleInst(const MCInst &Inst, const MCInstrInfo &MCII)
Check if the instruction is valid as the first instruction in macro fusion.
constexpr char GotSymName[]
static X86::CondCode getCondFromBranch(const MCInst &MI, const MCInstrInfo &MCII)
static unsigned getRelaxedOpcode(const MCInst &MI, bool Is16BitMode)
static unsigned getFixupKindSize(unsigned Kind)
static bool isRelaxableBranch(unsigned Opcode)
static bool isPrefix(unsigned Opcode, const MCInstrInfo &MCII)
Check if the instruction is a prefix.
static bool hasVariantSymbol(const MCInst &MI)
Check if the instruction has a variant symbol operand.
static bool is64Bit(const char *name)
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
Generic interface to target specific assembler backends.
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
virtual std::optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition MCSection.h:539
void setLastFragment(const MCFragment *F)
Definition MCSection.h:561
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI bool emitCompactUnwindNonCanonical() const
LLVM_ABI EmitDwarfUnwindType emitDwarfUnwindInfo() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
@ SymbolRef
References to labels and assigned expressions.
Definition MCExpr.h:43
ExprKind getKind() const
Definition MCExpr.h:85
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:61
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Definition MCFixup.h:86
bool getAllowAutoPadding() const
Definition MCSection.h:209
void setAllowAutoPadding(bool V)
Definition MCSection.h:210
MCInst getInst() const
Definition MCSection.h:734
unsigned getOpcode() const
Definition MCSection.h:249
MCSection * getParent() const
Definition MCSection.h:181
LLVM_ABI void setVarFixups(ArrayRef< MCFixup > Fixups)
MCFragment * getNext() const
Definition MCSection.h:177
ArrayRef< MCOperand > getOperands() const
Definition MCSection.h:729
size_t getVarSize() const
Definition MCSection.h:224
LLVM_ABI void setVarContents(ArrayRef< char > Contents)
Definition MCSection.cpp:61
MutableArrayRef< char > getVarContents()
Definition MCSection.h:700
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition MCSection.h:197
MutableArrayRef< MCFixup > getVarFixups()
Definition MCSection.h:720
void setInst(const MCInst &Inst)
Definition MCSection.h:743
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getOpcode() const
Definition MCInst.h:202
void setOpcode(unsigned Op)
Definition MCInst.h:201
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
Describe properties that are true of each instruction in the target description file.
bool isConditionalBranch() const
Return true if this is a branch which may fall through to the next instruction or may transfer contro...
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition MCInstrInfo.h:90
Streaming object file generation interface.
FT * newSpecialFragment(Args &&...args)
MCAssembler & getAssembler()
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:73
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
std::optional< MCRegister > getLLVMRegNum(uint64_t RegNum, bool isEH) const
Map a dwarf register back to a target register.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Definition MCSection.h:661
bool isText() const
Definition MCSection.h:644
Streaming machine code generation interface.
Definition MCStreamer.h:222
MCFragment * getCurrentFragment() const
Definition MCStreamer.h:449
size_t getCurFragSize() const
Definition MCStreamer.h:458
bool getAllowAutoPadding() const
Definition MCStreamer.h:341
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:438
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
iterator end() const
Definition ArrayRef.h:339
iterator begin() const
Definition ArrayRef.h:338
constexpr unsigned id() const
Definition Register.h:100
void push_back(const T &Elt)
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
bool isX86_64() const
Tests whether the target is x86 (64-bit).
Definition Triple.h:1119
bool isX32() const
Tests whether the target is X32.
Definition Triple.h:1145
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition Triple.h:791
OSType getOS() const
Get the parsed operating system type of this triple.
Definition Triple.h:445
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition Triple.h:785
bool isUEFI() const
Tests whether the OS is UEFI.
Definition Triple.h:696
bool isOSWindows() const
Tests whether the OS is Windows.
Definition Triple.h:699
bool isOSIAMCU() const
Definition Triple.h:678
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition Triple.h:782
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:212
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:190
raw_ostream & write(unsigned char C)
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ EM_386
Definition ELF.h:141
@ EM_X86_64
Definition ELF.h:183
@ EM_IAMCU
Definition ELF.h:144
LLVM_ABI Expected< uint32_t > getCPUSubType(const Triple &T)
Definition MachO.cpp:107
LLVM_ABI Expected< uint32_t > getCPUType(const Triple &T)
Definition MachO.cpp:87
VE::Fixups getFixupKind(uint8_t S)
bool isPrefix(uint64_t TSFlags)
@ RawFrmDstSrc
RawFrmDstSrc - This form is for instructions that use the source index register SI/ESI/RSI with a pos...
@ RawFrmSrc
RawFrmSrc - This form is for instructions that use the source index register SI/ESI/RSI with a possib...
@ RawFrmMemOffs
RawFrmMemOffs - This form is for instructions that store an absolute memory offset as an immediate wi...
int getMemoryOperandNo(uint64_t TSFlags)
unsigned getOperandBias(const MCInstrDesc &Desc)
Compute whether all of the def operands are repeated in the uses and therefore should be skipped.
void emitPrefix(MCCodeEmitter &MCE, const MCInst &MI, SmallVectorImpl< char > &CB, const MCSubtargetInfo &STI)
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
FirstMacroFusionInstKind classifyFirstOpcodeInMacroFusion(unsigned Opcode)
AlignBranchBoundaryKind
Defines the possible values of the branch boundary alignment mask.
@ AlignBranchIndirect
SecondMacroFusionInstKind
EncodingOfSegmentOverridePrefix getSegmentOverridePrefixForReg(MCRegister Reg)
Given a segment register, return the encoding of the segment override prefix for it.
FirstMacroFusionInstKind
unsigned getOpcodeForLongImmediateForm(unsigned Opcode)
bool isMacroFused(FirstMacroFusionInstKind FirstKind, SecondMacroFusionInstKind SecondKind)
@ reloc_riprel_4byte_movq_load_rex2
@ reloc_signed_4byte_relax
@ reloc_branch_4byte_pcrel
@ NumTargetFixupKinds
@ reloc_riprel_4byte_relax
@ reloc_riprel_4byte_relax_evex
@ reloc_riprel_4byte_relax_rex
@ reloc_global_offset_table
@ reloc_riprel_4byte_movq_load
@ reloc_riprel_4byte_relax_rex2
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
bool isRelocation(MCFixupKind FixupKind)
Definition MCFixup.h:130
NodeAddr< CodeNode * > Code
Definition RDFGraph.h:388
Context & getContext() const
Definition BasicBlock.h:99
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition SFrame.h:77
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
MCAsmBackend * createX86_64AsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
std::unique_ptr< MCObjectTargetWriter > createX86WinCOFFObjectWriter(bool Is64Bit)
Construct an X86 Win COFF object writer.
Op::Description Desc
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition MCFixup.h:22
MCStreamer * createX86ELFStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&MOW, std::unique_ptr< MCCodeEmitter > &&MCE)
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ FirstTargetFixupKind
Definition MCFixup.h:44
@ FK_SecRel_2
A two-byte section relative fixup.
Definition MCFixup.h:40
@ FirstLiteralRelocationKind
Definition MCFixup.h:29
@ FK_Data_8
A eight-byte fixup.
Definition MCFixup.h:37
@ FK_Data_1
A one-byte fixup.
Definition MCFixup.h:34
@ FK_Data_4
A four-byte fixup.
Definition MCFixup.h:36
@ FK_SecRel_8
A eight-byte section relative fixup.
Definition MCFixup.h:42
@ FK_NONE
A no-op fixup.
Definition MCFixup.h:33
@ FK_SecRel_4
A four-byte section relative fixup.
Definition MCFixup.h:41
@ FK_SecRel_1
A one-byte section relative fixup.
Definition MCFixup.h:39
@ FK_Data_2
A two-byte fixup.
Definition MCFixup.h:35
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
std::unique_ptr< MCObjectTargetWriter > createX86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
Construct an X86 Mach-O object writer.
@ Add
Sum of integers.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1916
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
std::unique_ptr< MCObjectTargetWriter > createX86ELFObjectWriter(bool IsELF64, uint8_t OSABI, uint16_t EMachine)
Construct an X86 ELF object writer.
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
Definition Alignment.h:100
endianness
Definition bit.h:71
MCAsmBackend * createX86_32AsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:860
const MCSymbol * Personality
Definition MCDwarf.h:860
std::vector< MCCFIInstruction > Instructions
Definition MCDwarf.h:862