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