LLVM 22.0.0git
X86ISelLoweringCall.cpp
Go to the documentation of this file.
1//===- llvm/lib/Target/X86/X86ISelCallLowering.cpp - Call lowering --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file implements the lowering of LLVM calls to DAG nodes.
11//
12//===----------------------------------------------------------------------===//
13
15#include "X86.h"
16#include "X86CallingConv.h"
17#include "X86FrameLowering.h"
18#include "X86ISelLowering.h"
19#include "X86InstrBuilder.h"
21#include "X86TargetMachine.h"
22#include "llvm/ADT/Statistic.h"
28#include "llvm/IR/IRBuilder.h"
29#include "llvm/IR/Module.h"
30
31#define DEBUG_TYPE "x86-isel"
32
33using namespace llvm;
34
35STATISTIC(NumTailCalls, "Number of tail calls");
36
37/// Call this when the user attempts to do something unsupported, like
38/// returning a double without SSE2 enabled on x86_64. This is not fatal, unlike
39/// report_fatal_error, so calling code should attempt to recover without
40/// crashing.
41static void errorUnsupported(SelectionDAG &DAG, const SDLoc &dl,
42 const char *Msg) {
44 DAG.getContext()->diagnose(
46}
47
48/// Returns true if a CC can dynamically exclude a register from the list of
49/// callee-saved-registers (TargetRegistryInfo::getCalleeSavedRegs()) based on
50/// the return registers.
52 switch (CC) {
53 default:
54 return false;
58 return true;
59 }
60}
61
62/// Returns true if a CC can dynamically exclude a register from the list of
63/// callee-saved-registers (TargetRegistryInfo::getCalleeSavedRegs()) based on
64/// the parameters.
66 return CC == CallingConv::X86_RegCall;
67}
68
69static std::pair<MVT, unsigned>
71 const X86Subtarget &Subtarget) {
72 // v2i1/v4i1/v8i1/v16i1 all pass in xmm registers unless the calling
73 // convention is one that uses k registers.
74 if (NumElts == 2)
75 return {MVT::v2i64, 1};
76 if (NumElts == 4)
77 return {MVT::v4i32, 1};
78 if (NumElts == 8 && CC != CallingConv::X86_RegCall &&
80 return {MVT::v8i16, 1};
81 if (NumElts == 16 && CC != CallingConv::X86_RegCall &&
83 return {MVT::v16i8, 1};
84 // v32i1 passes in ymm unless we have BWI and the calling convention is
85 // regcall.
86 if (NumElts == 32 && (!Subtarget.hasBWI() || CC != CallingConv::X86_RegCall))
87 return {MVT::v32i8, 1};
88 // Split v64i1 vectors if we don't have v64i8 available.
89 if (NumElts == 64 && Subtarget.hasBWI() && CC != CallingConv::X86_RegCall) {
90 if (Subtarget.useAVX512Regs())
91 return {MVT::v64i8, 1};
92 return {MVT::v32i8, 2};
93 }
94
95 // Break wide or odd vXi1 vectors into scalars to match avx2 behavior.
96 if (!isPowerOf2_32(NumElts) || (NumElts == 64 && !Subtarget.hasBWI()) ||
97 NumElts > 64)
98 return {MVT::i8, NumElts};
99
101}
102
105 EVT VT) const {
106 if (VT.isVector()) {
107 if (VT.getVectorElementType() == MVT::i1 && Subtarget.hasAVX512()) {
108 unsigned NumElts = VT.getVectorNumElements();
109
110 MVT RegisterVT;
111 unsigned NumRegisters;
112 std::tie(RegisterVT, NumRegisters) =
113 handleMaskRegisterForCallingConv(NumElts, CC, Subtarget);
114 if (RegisterVT != MVT::INVALID_SIMPLE_VALUE_TYPE)
115 return RegisterVT;
116 }
117
118 if (VT.getVectorElementType() == MVT::f16 && VT.getVectorNumElements() < 8)
119 return MVT::v8f16;
120 }
121
122 // We will use more GPRs for f64 and f80 on 32 bits when x87 is disabled.
123 if ((VT == MVT::f64 || VT == MVT::f80) && !Subtarget.is64Bit() &&
124 !Subtarget.hasX87())
125 return MVT::i32;
126
127 if (isTypeLegal(MVT::f16)) {
128 if (VT.isVector() && VT.getVectorElementType() == MVT::bf16)
130 Context, CC, VT.changeVectorElementType(MVT::f16));
131
132 if (VT == MVT::bf16)
133 return MVT::f16;
134 }
135
137}
138
141 EVT VT) const {
142 if (VT.isVector()) {
143 if (VT.getVectorElementType() == MVT::i1 && Subtarget.hasAVX512()) {
144 unsigned NumElts = VT.getVectorNumElements();
145
146 MVT RegisterVT;
147 unsigned NumRegisters;
148 std::tie(RegisterVT, NumRegisters) =
149 handleMaskRegisterForCallingConv(NumElts, CC, Subtarget);
150 if (RegisterVT != MVT::INVALID_SIMPLE_VALUE_TYPE)
151 return NumRegisters;
152 }
153
154 if (VT.getVectorElementType() == MVT::f16 && VT.getVectorNumElements() < 8)
155 return 1;
156 }
157
158 // We have to split f64 to 2 registers and f80 to 3 registers on 32 bits if
159 // x87 is disabled.
160 if (!Subtarget.is64Bit() && !Subtarget.hasX87()) {
161 if (VT == MVT::f64)
162 return 2;
163 if (VT == MVT::f80)
164 return 3;
165 }
166
167 if (VT.isVector() && VT.getVectorElementType() == MVT::bf16 &&
168 isTypeLegal(MVT::f16))
170 VT.changeVectorElementType(MVT::f16));
171
173}
174
176 LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
177 unsigned &NumIntermediates, MVT &RegisterVT) const {
178 // Break wide or odd vXi1 vectors into scalars to match avx2 behavior.
179 if (VT.isVector() && VT.getVectorElementType() == MVT::i1 &&
180 Subtarget.hasAVX512() &&
182 (VT.getVectorNumElements() == 64 && !Subtarget.hasBWI()) ||
183 VT.getVectorNumElements() > 64)) {
184 RegisterVT = MVT::i8;
185 IntermediateVT = MVT::i1;
186 NumIntermediates = VT.getVectorNumElements();
187 return NumIntermediates;
188 }
189
190 // Split v64i1 vectors if we don't have v64i8 available.
191 if (VT == MVT::v64i1 && Subtarget.hasBWI() && !Subtarget.useAVX512Regs() &&
193 RegisterVT = MVT::v32i8;
194 IntermediateVT = MVT::v32i1;
195 NumIntermediates = 2;
196 return 2;
197 }
198
199 // Split vNbf16 vectors according to vNf16.
200 if (VT.isVector() && VT.getVectorElementType() == MVT::bf16 &&
201 isTypeLegal(MVT::f16))
202 VT = VT.changeVectorElementType(MVT::f16);
203
205 NumIntermediates, RegisterVT);
206}
207
209 LLVMContext& Context,
210 EVT VT) const {
211 if (!VT.isVector())
212 return MVT::i8;
213
214 if (Subtarget.hasAVX512()) {
215 // Figure out what this type will be legalized to.
216 EVT LegalVT = VT;
217 while (getTypeAction(Context, LegalVT) != TypeLegal)
218 LegalVT = getTypeToTransformTo(Context, LegalVT);
219
220 // If we got a 512-bit vector then we'll definitely have a vXi1 compare.
221 if (LegalVT.getSimpleVT().is512BitVector())
222 return EVT::getVectorVT(Context, MVT::i1, VT.getVectorElementCount());
223
224 if (LegalVT.getSimpleVT().isVector() && Subtarget.hasVLX()) {
225 // If we legalized to less than a 512-bit vector, then we will use a vXi1
226 // compare for vXi32/vXi64 for sure. If we have BWI we will also support
227 // vXi16/vXi8.
228 MVT EltVT = LegalVT.getSimpleVT().getVectorElementType();
229 if (Subtarget.hasBWI() || EltVT.getSizeInBits() >= 32)
230 return EVT::getVectorVT(Context, MVT::i1, VT.getVectorElementCount());
231 }
232 }
233
235}
236
238 Type *Ty, CallingConv::ID CallConv, bool isVarArg,
239 const DataLayout &DL) const {
240 // On x86-64 i128 is split into two i64s and needs to be allocated to two
241 // consecutive registers, or spilled to the stack as a whole. On x86-32 i128
242 // is split to four i32s and never actually passed in registers, but we use
243 // the consecutive register mark to match it in TableGen.
244 if (Ty->isIntegerTy(128))
245 return true;
246
247 // On x86-32, fp128 acts the same as i128.
248 if (Subtarget.is32Bit() && Ty->isFP128Ty())
249 return true;
250
251 return false;
252}
253
254/// Helper for getByValTypeAlignment to determine
255/// the desired ByVal argument alignment.
256static void getMaxByValAlign(Type *Ty, Align &MaxAlign) {
257 if (MaxAlign == 16)
258 return;
259 if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
260 if (VTy->getPrimitiveSizeInBits().getFixedValue() == 128)
261 MaxAlign = Align(16);
262 } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
263 Align EltAlign;
264 getMaxByValAlign(ATy->getElementType(), EltAlign);
265 if (EltAlign > MaxAlign)
266 MaxAlign = EltAlign;
267 } else if (StructType *STy = dyn_cast<StructType>(Ty)) {
268 for (auto *EltTy : STy->elements()) {
269 Align EltAlign;
270 getMaxByValAlign(EltTy, EltAlign);
271 if (EltAlign > MaxAlign)
272 MaxAlign = EltAlign;
273 if (MaxAlign == 16)
274 break;
275 }
276 }
277}
278
279/// Return the desired alignment for ByVal aggregate
280/// function arguments in the caller parameter area. For X86, aggregates
281/// that contain SSE vectors are placed at 16-byte boundaries while the rest
282/// are at 4-byte boundaries.
284 const DataLayout &DL) const {
285 if (Subtarget.is64Bit())
286 return std::max(DL.getABITypeAlign(Ty), Align::Constant<8>());
287
288 Align Alignment(4);
289 if (Subtarget.hasSSE1())
290 getMaxByValAlign(Ty, Alignment);
291 return Alignment;
292}
293
294/// It returns EVT::Other if the type should be determined using generic
295/// target-independent logic.
296/// For vector ops we check that the overall size isn't larger than our
297/// preferred vector width.
299 LLVMContext &Context, const MemOp &Op,
300 const AttributeList &FuncAttributes) const {
301 if (!FuncAttributes.hasFnAttr(Attribute::NoImplicitFloat)) {
302 if (Op.size() >= 16 &&
303 (!Subtarget.isUnalignedMem16Slow() || Op.isAligned(Align(16)))) {
304 // FIXME: Check if unaligned 64-byte accesses are slow.
305 if (Op.size() >= 64 && Subtarget.hasAVX512() && Subtarget.hasEVEX512() &&
306 (Subtarget.getPreferVectorWidth() >= 512)) {
307 return Subtarget.hasBWI() ? MVT::v64i8 : MVT::v16i32;
308 }
309 // FIXME: Check if unaligned 32-byte accesses are slow.
310 if (Op.size() >= 32 && Subtarget.hasAVX() &&
311 Subtarget.useLight256BitInstructions()) {
312 // Although this isn't a well-supported type for AVX1, we'll let
313 // legalization and shuffle lowering produce the optimal codegen. If we
314 // choose an optimal type with a vector element larger than a byte,
315 // getMemsetStores() may create an intermediate splat (using an integer
316 // multiply) before we splat as a vector.
317 return MVT::v32i8;
318 }
319 if (Subtarget.hasSSE2() && (Subtarget.getPreferVectorWidth() >= 128))
320 return MVT::v16i8;
321 // TODO: Can SSE1 handle a byte vector?
322 // If we have SSE1 registers we should be able to use them.
323 if (Subtarget.hasSSE1() && (Subtarget.is64Bit() || Subtarget.hasX87()) &&
324 (Subtarget.getPreferVectorWidth() >= 128))
325 return MVT::v4f32;
326 } else if (((Op.isMemcpy() && !Op.isMemcpyStrSrc()) || Op.isZeroMemset()) &&
327 Op.size() >= 8 && !Subtarget.is64Bit() && Subtarget.hasSSE2()) {
328 // Do not use f64 to lower memcpy if source is string constant. It's
329 // better to use i32 to avoid the loads.
330 // Also, do not use f64 to lower memset unless this is a memset of zeros.
331 // The gymnastics of splatting a byte value into an XMM register and then
332 // only using 8-byte stores (because this is a CPU with slow unaligned
333 // 16-byte accesses) makes that a loser.
334 return MVT::f64;
335 }
336 }
337 // This is a compromise. If we reach here, unaligned accesses may be slow on
338 // this target. However, creating smaller, aligned accesses could be even
339 // slower and would certainly be a lot more code.
340 if (Subtarget.is64Bit() && Op.size() >= 8)
341 return MVT::i64;
342 return MVT::i32;
343}
344
346 if (VT == MVT::f32)
347 return Subtarget.hasSSE1();
348 if (VT == MVT::f64)
349 return Subtarget.hasSSE2();
350 return true;
351}
352
353static bool isBitAligned(Align Alignment, uint64_t SizeInBits) {
354 return (8 * Alignment.value()) % SizeInBits == 0;
355}
356
358 if (isBitAligned(Alignment, VT.getSizeInBits()))
359 return true;
360 switch (VT.getSizeInBits()) {
361 default:
362 // 8-byte and under are always assumed to be fast.
363 return true;
364 case 128:
365 return !Subtarget.isUnalignedMem16Slow();
366 case 256:
367 return !Subtarget.isUnalignedMem32Slow();
368 // TODO: What about AVX-512 (512-bit) accesses?
369 }
370}
371
373 EVT VT, unsigned, Align Alignment, MachineMemOperand::Flags Flags,
374 unsigned *Fast) const {
375 if (Fast)
376 *Fast = isMemoryAccessFast(VT, Alignment);
377 // NonTemporal vector memory ops must be aligned.
378 if (!!(Flags & MachineMemOperand::MONonTemporal) && VT.isVector()) {
379 // NT loads can only be vector aligned, so if its less aligned than the
380 // minimum vector size (which we can split the vector down to), we might as
381 // well use a regular unaligned vector load.
382 // We don't have any NT loads pre-SSE41.
383 if (!!(Flags & MachineMemOperand::MOLoad))
384 return (Alignment < 16 || !Subtarget.hasSSE41());
385 return false;
386 }
387 // Misaligned accesses of any size are always allowed.
388 return true;
389}
390
392 const DataLayout &DL, EVT VT,
393 unsigned AddrSpace, Align Alignment,
395 unsigned *Fast) const {
396 if (Fast)
397 *Fast = isMemoryAccessFast(VT, Alignment);
398 if (!!(Flags & MachineMemOperand::MONonTemporal) && VT.isVector()) {
399 if (allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags,
400 /*Fast=*/nullptr))
401 return true;
402 // NonTemporal vector memory ops are special, and must be aligned.
403 if (!isBitAligned(Alignment, VT.getSizeInBits()))
404 return false;
405 switch (VT.getSizeInBits()) {
406 case 128:
407 if (!!(Flags & MachineMemOperand::MOLoad) && Subtarget.hasSSE41())
408 return true;
409 if (!!(Flags & MachineMemOperand::MOStore) && Subtarget.hasSSE2())
410 return true;
411 return false;
412 case 256:
413 if (!!(Flags & MachineMemOperand::MOLoad) && Subtarget.hasAVX2())
414 return true;
415 if (!!(Flags & MachineMemOperand::MOStore) && Subtarget.hasAVX())
416 return true;
417 return false;
418 case 512:
419 if (Subtarget.hasAVX512() && Subtarget.hasEVEX512())
420 return true;
421 return false;
422 default:
423 return false; // Don't have NonTemporal vector memory ops of this size.
424 }
425 }
426 return true;
427}
428
429/// Return the entry encoding for a jump table in the
430/// current function. The returned value is a member of the
431/// MachineJumpTableInfo::JTEntryKind enum.
433 // In GOT pic mode, each entry in the jump table is emitted as a @GOTOFF
434 // symbol.
435 if (isPositionIndependent() && Subtarget.isPICStyleGOT())
437 if (isPositionIndependent() &&
439 !Subtarget.isTargetCOFF())
441
442 // Otherwise, use the normal jump table encoding heuristics.
444}
445
447 return Subtarget.useSoftFloat();
448}
449
451 ArgListTy &Args) const {
452
453 // Only relabel X86-32 for C / Stdcall CCs.
454 if (Subtarget.is64Bit())
455 return;
456 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
457 return;
458 unsigned ParamRegs = 0;
459 if (auto *M = MF->getFunction().getParent())
460 ParamRegs = M->getNumberRegisterParameters();
461
462 // Mark the first N int arguments as having reg
463 for (auto &Arg : Args) {
464 Type *T = Arg.Ty;
465 if (T->isIntOrPtrTy())
466 if (MF->getDataLayout().getTypeAllocSize(T) <= 8) {
467 unsigned numRegs = 1;
468 if (MF->getDataLayout().getTypeAllocSize(T) > 4)
469 numRegs = 2;
470 if (ParamRegs < numRegs)
471 return;
472 ParamRegs -= numRegs;
473 Arg.IsInReg = true;
474 }
475 }
476}
477
478const MCExpr *
480 const MachineBasicBlock *MBB,
481 unsigned uid,MCContext &Ctx) const{
483 // In 32-bit ELF systems, our jump table entries are formed with @GOTOFF
484 // entries.
486}
487
488/// Returns relocation base for the given PIC jumptable.
490 SelectionDAG &DAG) const {
491 if (!Subtarget.is64Bit())
492 // This doesn't have SDLoc associated with it, but is not really the
493 // same as a Register.
494 return DAG.getNode(X86ISD::GlobalBaseReg, SDLoc(),
496 return Table;
497}
498
499/// This returns the relocation base for the given PIC jumptable,
500/// the same as getPICJumpTableRelocBase, but as an MCExpr.
502getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI,
503 MCContext &Ctx) const {
504 // X86-64 uses RIP relative addressing based on the jump table label.
505 if (Subtarget.isPICStyleRIPRel() ||
506 (Subtarget.is64Bit() &&
509
510 // Otherwise, the reference is relative to the PIC base.
511 return MCSymbolRefExpr::create(MF->getPICBaseSymbol(), Ctx);
512}
513
514std::pair<const TargetRegisterClass *, uint8_t>
516 MVT VT) const {
517 const TargetRegisterClass *RRC = nullptr;
518 uint8_t Cost = 1;
519 switch (VT.SimpleTy) {
520 default:
522 case MVT::i8: case MVT::i16: case MVT::i32: case MVT::i64:
523 RRC = Subtarget.is64Bit() ? &X86::GR64RegClass : &X86::GR32RegClass;
524 break;
525 case MVT::x86mmx:
526 RRC = &X86::VR64RegClass;
527 break;
528 case MVT::f32: case MVT::f64:
529 case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64:
530 case MVT::v4f32: case MVT::v2f64:
531 case MVT::v32i8: case MVT::v16i16: case MVT::v8i32: case MVT::v4i64:
532 case MVT::v8f32: case MVT::v4f64:
533 case MVT::v64i8: case MVT::v32i16: case MVT::v16i32: case MVT::v8i64:
534 case MVT::v16f32: case MVT::v8f64:
535 RRC = &X86::VR128XRegClass;
536 break;
537 }
538 return std::make_pair(RRC, Cost);
539}
540
541unsigned X86TargetLowering::getAddressSpace() const {
542 if (Subtarget.is64Bit())
544 : X86AS::FS;
545 return X86AS::GS;
546}
547
548static bool hasStackGuardSlotTLS(const Triple &TargetTriple) {
549 return TargetTriple.isOSGlibc() || TargetTriple.isOSFuchsia() ||
550 (TargetTriple.isAndroid() && !TargetTriple.isAndroidVersionLT(17));
551}
552
554 int Offset, unsigned AddressSpace) {
556 ConstantInt::get(Type::getInt32Ty(IRB.getContext()), Offset),
558}
559
561 // glibc, bionic, and Fuchsia have a special slot for the stack guard in
562 // tcbhead_t; use it instead of the usual global variable (see
563 // sysdeps/{i386,x86_64}/nptl/tls.h)
564 if (hasStackGuardSlotTLS(Subtarget.getTargetTriple())) {
565 unsigned AddressSpace = getAddressSpace();
566
567 // <zircon/tls.h> defines ZX_TLS_STACK_GUARD_OFFSET with this value.
568 if (Subtarget.isTargetFuchsia())
569 return SegmentOffset(IRB, 0x10, AddressSpace);
570
571 Module *M = IRB.GetInsertBlock()->getParent()->getParent();
572 // Specially, some users may customize the base reg and offset.
573 int Offset = M->getStackProtectorGuardOffset();
574 // If we don't set -stack-protector-guard-offset value:
575 // %fs:0x28, unless we're using a Kernel code model, in which case
576 // it's %gs:0x28. gs:0x14 on i386.
577 if (Offset == INT_MAX)
578 Offset = (Subtarget.is64Bit()) ? 0x28 : 0x14;
579
580 StringRef GuardReg = M->getStackProtectorGuardReg();
581 if (GuardReg == "fs")
583 else if (GuardReg == "gs")
585
586 // Use symbol guard if user specify.
587 StringRef GuardSymb = M->getStackProtectorGuardSymbol();
588 if (!GuardSymb.empty()) {
589 GlobalVariable *GV = M->getGlobalVariable(GuardSymb);
590 if (!GV) {
591 Type *Ty = Subtarget.is64Bit() ? Type::getInt64Ty(M->getContext())
592 : Type::getInt32Ty(M->getContext());
593 GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage,
594 nullptr, GuardSymb, nullptr,
596 if (!Subtarget.isTargetDarwin())
597 GV->setDSOLocal(M->getDirectAccessExternalData());
598 }
599 return GV;
600 }
601
602 return SegmentOffset(IRB, Offset, AddressSpace);
603 }
605}
606
608 // MSVC CRT provides functionalities for stack protection.
609 if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
611 // MSVC CRT has a global variable holding security cookie.
612 M.getOrInsertGlobal("__security_cookie",
613 PointerType::getUnqual(M.getContext()));
614
615 // MSVC CRT has a function to validate security cookie.
616 FunctionCallee SecurityCheckCookie = M.getOrInsertFunction(
617 "__security_check_cookie", Type::getVoidTy(M.getContext()),
618 PointerType::getUnqual(M.getContext()));
619 if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
620 F->setCallingConv(CallingConv::X86_FastCall);
621 F->addParamAttr(0, Attribute::AttrKind::InReg);
622 }
623 return;
624 }
625
626 StringRef GuardMode = M.getStackProtectorGuard();
627
628 // glibc, bionic, and Fuchsia have a special slot for the stack guard.
629 if ((GuardMode == "tls" || GuardMode.empty()) &&
631 return;
633}
634
636 // MSVC CRT has a function to validate security cookie.
637 if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
639 return M.getFunction("__security_check_cookie");
640 }
642}
643
644Value *
646 // Android provides a fixed TLS slot for the SafeStack pointer. See the
647 // definition of TLS_SLOT_SAFESTACK in
648 // https://android.googlesource.com/platform/bionic/+/master/libc/private/bionic_tls.h
649 if (Subtarget.isTargetAndroid()) {
650 // %fs:0x48, unless we're using a Kernel code model, in which case it's %gs:
651 // %gs:0x24 on i386
652 int Offset = (Subtarget.is64Bit()) ? 0x48 : 0x24;
653 return SegmentOffset(IRB, Offset, getAddressSpace());
654 }
655
656 // Fuchsia is similar.
657 if (Subtarget.isTargetFuchsia()) {
658 // <zircon/tls.h> defines ZX_TLS_UNSAFE_SP_OFFSET with this value.
659 return SegmentOffset(IRB, 0x18, getAddressSpace());
660 }
661
663}
664
665//===----------------------------------------------------------------------===//
666// Return Value Calling Convention Implementation
667//===----------------------------------------------------------------------===//
668
669bool X86TargetLowering::CanLowerReturn(
670 CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
671 const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
672 const Type *RetTy) const {
674 CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
675 return CCInfo.CheckReturn(Outs, RetCC_X86);
676}
677
678const MCPhysReg *X86TargetLowering::getScratchRegisters(CallingConv::ID) const {
679 static const MCPhysReg ScratchRegs[] = { X86::R11, 0 };
680 return ScratchRegs;
681}
682
683ArrayRef<MCPhysReg> X86TargetLowering::getRoundingControlRegisters() const {
684 static const MCPhysReg RCRegs[] = {X86::FPCW, X86::MXCSR};
685 return RCRegs;
686}
687
688/// Lowers masks values (v*i1) to the local register values
689/// \returns DAG node after lowering to register type
690static SDValue lowerMasksToReg(const SDValue &ValArg, const EVT &ValLoc,
691 const SDLoc &DL, SelectionDAG &DAG) {
692 EVT ValVT = ValArg.getValueType();
693
694 if (ValVT == MVT::v1i1)
695 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ValLoc, ValArg,
696 DAG.getIntPtrConstant(0, DL));
697
698 if ((ValVT == MVT::v8i1 && (ValLoc == MVT::i8 || ValLoc == MVT::i32)) ||
699 (ValVT == MVT::v16i1 && (ValLoc == MVT::i16 || ValLoc == MVT::i32))) {
700 // Two stage lowering might be required
701 // bitcast: v8i1 -> i8 / v16i1 -> i16
702 // anyextend: i8 -> i32 / i16 -> i32
703 EVT TempValLoc = ValVT == MVT::v8i1 ? MVT::i8 : MVT::i16;
704 SDValue ValToCopy = DAG.getBitcast(TempValLoc, ValArg);
705 if (ValLoc == MVT::i32)
706 ValToCopy = DAG.getNode(ISD::ANY_EXTEND, DL, ValLoc, ValToCopy);
707 return ValToCopy;
708 }
709
710 if ((ValVT == MVT::v32i1 && ValLoc == MVT::i32) ||
711 (ValVT == MVT::v64i1 && ValLoc == MVT::i64)) {
712 // One stage lowering is required
713 // bitcast: v32i1 -> i32 / v64i1 -> i64
714 return DAG.getBitcast(ValLoc, ValArg);
715 }
716
717 return DAG.getNode(ISD::ANY_EXTEND, DL, ValLoc, ValArg);
718}
719
720/// Breaks v64i1 value into two registers and adds the new node to the DAG
722 const SDLoc &DL, SelectionDAG &DAG, SDValue &Arg,
723 SmallVectorImpl<std::pair<Register, SDValue>> &RegsToPass, CCValAssign &VA,
724 CCValAssign &NextVA, const X86Subtarget &Subtarget) {
725 assert(Subtarget.hasBWI() && "Expected AVX512BW target!");
726 assert(Subtarget.is32Bit() && "Expecting 32 bit target");
727 assert(Arg.getValueType() == MVT::i64 && "Expecting 64 bit value");
728 assert(VA.isRegLoc() && NextVA.isRegLoc() &&
729 "The value should reside in two registers");
730
731 // Before splitting the value we cast it to i64
732 Arg = DAG.getBitcast(MVT::i64, Arg);
733
734 // Splitting the value into two i32 types
735 SDValue Lo, Hi;
736 std::tie(Lo, Hi) = DAG.SplitScalar(Arg, DL, MVT::i32, MVT::i32);
737
738 // Attach the two i32 types into corresponding registers
739 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Lo));
740 RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), Hi));
741}
742
744X86TargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
745 bool isVarArg,
747 const SmallVectorImpl<SDValue> &OutVals,
748 const SDLoc &dl, SelectionDAG &DAG) const {
751
752 // In some cases we need to disable registers from the default CSR list.
753 // For example, when they are used as return registers (preserve_* and X86's
754 // regcall) or for argument passing (X86's regcall).
755 bool ShouldDisableCalleeSavedRegister =
756 shouldDisableRetRegFromCSR(CallConv) ||
757 MF.getFunction().hasFnAttribute("no_caller_saved_registers");
758
759 if (CallConv == CallingConv::X86_INTR && !Outs.empty())
760 report_fatal_error("X86 interrupts may not return any value");
761
763 CCState CCInfo(CallConv, isVarArg, MF, RVLocs, *DAG.getContext());
764 CCInfo.AnalyzeReturn(Outs, RetCC_X86);
765
767 for (unsigned I = 0, OutsIndex = 0, E = RVLocs.size(); I != E;
768 ++I, ++OutsIndex) {
769 CCValAssign &VA = RVLocs[I];
770 assert(VA.isRegLoc() && "Can only return in registers!");
771
772 // Add the register to the CalleeSaveDisableRegs list.
773 if (ShouldDisableCalleeSavedRegister)
775
776 SDValue ValToCopy = OutVals[OutsIndex];
777 EVT ValVT = ValToCopy.getValueType();
778
779 // Promote values to the appropriate types.
780 if (VA.getLocInfo() == CCValAssign::SExt)
781 ValToCopy = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), ValToCopy);
782 else if (VA.getLocInfo() == CCValAssign::ZExt)
783 ValToCopy = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), ValToCopy);
784 else if (VA.getLocInfo() == CCValAssign::AExt) {
785 if (ValVT.isVector() && ValVT.getVectorElementType() == MVT::i1)
786 ValToCopy = lowerMasksToReg(ValToCopy, VA.getLocVT(), dl, DAG);
787 else
788 ValToCopy = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), ValToCopy);
789 }
790 else if (VA.getLocInfo() == CCValAssign::BCvt)
791 ValToCopy = DAG.getBitcast(VA.getLocVT(), ValToCopy);
792
794 "Unexpected FP-extend for return value.");
795
796 // Report an error if we have attempted to return a value via an XMM
797 // register and SSE was disabled.
798 if (!Subtarget.hasSSE1() && X86::FR32XRegClass.contains(VA.getLocReg())) {
799 errorUnsupported(DAG, dl, "SSE register return with SSE disabled");
800 VA.convertToReg(X86::FP0); // Set reg to FP0, avoid hitting asserts.
801 } else if (!Subtarget.hasSSE2() &&
802 X86::FR64XRegClass.contains(VA.getLocReg()) &&
803 ValVT == MVT::f64) {
804 // When returning a double via an XMM register, report an error if SSE2 is
805 // not enabled.
806 errorUnsupported(DAG, dl, "SSE2 register return with SSE2 disabled");
807 VA.convertToReg(X86::FP0); // Set reg to FP0, avoid hitting asserts.
808 }
809
810 // Returns in ST0/ST1 are handled specially: these are pushed as operands to
811 // the RET instruction and handled by the FP Stackifier.
812 if (VA.getLocReg() == X86::FP0 ||
813 VA.getLocReg() == X86::FP1) {
814 // If this is a copy from an xmm register to ST(0), use an FPExtend to
815 // change the value to the FP stack register class.
817 ValToCopy = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f80, ValToCopy);
818 RetVals.push_back(std::make_pair(VA.getLocReg(), ValToCopy));
819 // Don't emit a copytoreg.
820 continue;
821 }
822
823 // 64-bit vector (MMX) values are returned in XMM0 / XMM1 except for v1i64
824 // which is returned in RAX / RDX.
825 if (Subtarget.is64Bit()) {
826 if (ValVT == MVT::x86mmx) {
827 if (VA.getLocReg() == X86::XMM0 || VA.getLocReg() == X86::XMM1) {
828 ValToCopy = DAG.getBitcast(MVT::i64, ValToCopy);
829 ValToCopy = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2i64,
830 ValToCopy);
831 // If we don't have SSE2 available, convert to v4f32 so the generated
832 // register is legal.
833 if (!Subtarget.hasSSE2())
834 ValToCopy = DAG.getBitcast(MVT::v4f32, ValToCopy);
835 }
836 }
837 }
838
839 if (VA.needsCustom()) {
840 assert(VA.getValVT() == MVT::v64i1 &&
841 "Currently the only custom case is when we split v64i1 to 2 regs");
842
843 Passv64i1ArgInRegs(dl, DAG, ValToCopy, RetVals, VA, RVLocs[++I],
844 Subtarget);
845
846 // Add the second register to the CalleeSaveDisableRegs list.
847 if (ShouldDisableCalleeSavedRegister)
848 MF.getRegInfo().disableCalleeSavedRegister(RVLocs[I].getLocReg());
849 } else {
850 RetVals.push_back(std::make_pair(VA.getLocReg(), ValToCopy));
851 }
852 }
853
854 SDValue Glue;
856 RetOps.push_back(Chain); // Operand #0 = Chain (updated below)
857 // Operand #1 = Bytes To Pop
858 RetOps.push_back(DAG.getTargetConstant(FuncInfo->getBytesToPopOnReturn(), dl,
859 MVT::i32));
860
861 // Copy the result values into the output registers.
862 for (auto &RetVal : RetVals) {
863 if (RetVal.first == X86::FP0 || RetVal.first == X86::FP1) {
864 RetOps.push_back(RetVal.second);
865 continue; // Don't emit a copytoreg.
866 }
867
868 Chain = DAG.getCopyToReg(Chain, dl, RetVal.first, RetVal.second, Glue);
869 Glue = Chain.getValue(1);
870 RetOps.push_back(
871 DAG.getRegister(RetVal.first, RetVal.second.getValueType()));
872 }
873
874 // Swift calling convention does not require we copy the sret argument
875 // into %rax/%eax for the return, and SRetReturnReg is not set for Swift.
876
877 // All x86 ABIs require that for returning structs by value we copy
878 // the sret argument into %rax/%eax (depending on ABI) for the return.
879 // We saved the argument into a virtual register in the entry block,
880 // so now we copy the value out and into %rax/%eax.
881 //
882 // Checking Function.hasStructRetAttr() here is insufficient because the IR
883 // may not have an explicit sret argument. If FuncInfo.CanLowerReturn is
884 // false, then an sret argument may be implicitly inserted in the SelDAG. In
885 // either case FuncInfo->setSRetReturnReg() will have been called.
886 if (Register SRetReg = FuncInfo->getSRetReturnReg()) {
887 // When we have both sret and another return value, we should use the
888 // original Chain stored in RetOps[0], instead of the current Chain updated
889 // in the above loop. If we only have sret, RetOps[0] equals to Chain.
890
891 // For the case of sret and another return value, we have
892 // Chain_0 at the function entry
893 // Chain_1 = getCopyToReg(Chain_0) in the above loop
894 // If we use Chain_1 in getCopyFromReg, we will have
895 // Val = getCopyFromReg(Chain_1)
896 // Chain_2 = getCopyToReg(Chain_1, Val) from below
897
898 // getCopyToReg(Chain_0) will be glued together with
899 // getCopyToReg(Chain_1, Val) into Unit A, getCopyFromReg(Chain_1) will be
900 // in Unit B, and we will have cyclic dependency between Unit A and Unit B:
901 // Data dependency from Unit B to Unit A due to usage of Val in
902 // getCopyToReg(Chain_1, Val)
903 // Chain dependency from Unit A to Unit B
904
905 // So here, we use RetOps[0] (i.e Chain_0) for getCopyFromReg.
906 SDValue Val = DAG.getCopyFromReg(RetOps[0], dl, SRetReg,
908
909 Register RetValReg
910 = (Subtarget.is64Bit() && !Subtarget.isTarget64BitILP32()) ?
911 X86::RAX : X86::EAX;
912 Chain = DAG.getCopyToReg(Chain, dl, RetValReg, Val, Glue);
913 Glue = Chain.getValue(1);
914
915 // RAX/EAX now acts like a return value.
916 RetOps.push_back(
917 DAG.getRegister(RetValReg, getPointerTy(DAG.getDataLayout())));
918
919 // Add the returned register to the CalleeSaveDisableRegs list. Don't do
920 // this however for preserve_most/preserve_all to minimize the number of
921 // callee-saved registers for these CCs.
922 if (ShouldDisableCalleeSavedRegister &&
923 CallConv != CallingConv::PreserveAll &&
924 CallConv != CallingConv::PreserveMost)
926 }
927
928 const X86RegisterInfo *TRI = Subtarget.getRegisterInfo();
929 const MCPhysReg *I =
930 TRI->getCalleeSavedRegsViaCopy(&DAG.getMachineFunction());
931 if (I) {
932 for (; *I; ++I) {
933 if (X86::GR64RegClass.contains(*I))
934 RetOps.push_back(DAG.getRegister(*I, MVT::i64));
935 else
936 llvm_unreachable("Unexpected register class in CSRsViaCopy!");
937 }
938 }
939
940 RetOps[0] = Chain; // Update chain.
941
942 // Add the glue if we have it.
943 if (Glue.getNode())
944 RetOps.push_back(Glue);
945
947 if (CallConv == CallingConv::X86_INTR)
948 opcode = X86ISD::IRET;
949 return DAG.getNode(opcode, dl, MVT::Other, RetOps);
950}
951
952bool X86TargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const {
953 if (N->getNumValues() != 1 || !N->hasNUsesOfValue(1, 0))
954 return false;
955
956 SDValue TCChain = Chain;
957 SDNode *Copy = *N->user_begin();
958 if (Copy->getOpcode() == ISD::CopyToReg) {
959 // If the copy has a glue operand, we conservatively assume it isn't safe to
960 // perform a tail call.
961 if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue)
962 return false;
963 TCChain = Copy->getOperand(0);
964 } else if (Copy->getOpcode() != ISD::FP_EXTEND)
965 return false;
966
967 bool HasRet = false;
968 for (const SDNode *U : Copy->users()) {
969 if (U->getOpcode() != X86ISD::RET_GLUE)
970 return false;
971 // If we are returning more than one value, we can definitely
972 // not make a tail call see PR19530
973 if (U->getNumOperands() > 4)
974 return false;
975 if (U->getNumOperands() == 4 &&
976 U->getOperand(U->getNumOperands() - 1).getValueType() != MVT::Glue)
977 return false;
978 HasRet = true;
979 }
980
981 if (!HasRet)
982 return false;
983
984 Chain = TCChain;
985 return true;
986}
987
988EVT X86TargetLowering::getTypeForExtReturn(LLVMContext &Context, EVT VT,
989 ISD::NodeType ExtendKind) const {
990 MVT ReturnMVT = MVT::i32;
991
992 bool Darwin = Subtarget.getTargetTriple().isOSDarwin();
993 if (VT == MVT::i1 || (!Darwin && (VT == MVT::i8 || VT == MVT::i16))) {
994 // The ABI does not require i1, i8 or i16 to be extended.
995 //
996 // On Darwin, there is code in the wild relying on Clang's old behaviour of
997 // always extending i8/i16 return values, so keep doing that for now.
998 // (PR26665).
999 ReturnMVT = MVT::i8;
1000 }
1001
1002 EVT MinVT = getRegisterType(Context, ReturnMVT);
1003 return VT.bitsLT(MinVT) ? MinVT : VT;
1004}
1005
1006/// Reads two 32 bit registers and creates a 64 bit mask value.
1007/// \param VA The current 32 bit value that need to be assigned.
1008/// \param NextVA The next 32 bit value that need to be assigned.
1009/// \param Root The parent DAG node.
1010/// \param [in,out] InGlue Represents SDvalue in the parent DAG node for
1011/// glue purposes. In the case the DAG is already using
1012/// physical register instead of virtual, we should glue
1013/// our new SDValue to InGlue SDvalue.
1014/// \return a new SDvalue of size 64bit.
1016 SDValue &Root, SelectionDAG &DAG,
1017 const SDLoc &DL, const X86Subtarget &Subtarget,
1018 SDValue *InGlue = nullptr) {
1019 assert((Subtarget.hasBWI()) && "Expected AVX512BW target!");
1020 assert(Subtarget.is32Bit() && "Expecting 32 bit target");
1021 assert(VA.getValVT() == MVT::v64i1 &&
1022 "Expecting first location of 64 bit width type");
1023 assert(NextVA.getValVT() == VA.getValVT() &&
1024 "The locations should have the same type");
1025 assert(VA.isRegLoc() && NextVA.isRegLoc() &&
1026 "The values should reside in two registers");
1027
1028 SDValue Lo, Hi;
1029 SDValue ArgValueLo, ArgValueHi;
1030
1032 const TargetRegisterClass *RC = &X86::GR32RegClass;
1033
1034 // Read a 32 bit value from the registers.
1035 if (nullptr == InGlue) {
1036 // When no physical register is present,
1037 // create an intermediate virtual register.
1038 Register Reg = MF.addLiveIn(VA.getLocReg(), RC);
1039 ArgValueLo = DAG.getCopyFromReg(Root, DL, Reg, MVT::i32);
1040 Reg = MF.addLiveIn(NextVA.getLocReg(), RC);
1041 ArgValueHi = DAG.getCopyFromReg(Root, DL, Reg, MVT::i32);
1042 } else {
1043 // When a physical register is available read the value from it and glue
1044 // the reads together.
1045 ArgValueLo =
1046 DAG.getCopyFromReg(Root, DL, VA.getLocReg(), MVT::i32, *InGlue);
1047 *InGlue = ArgValueLo.getValue(2);
1048 ArgValueHi =
1049 DAG.getCopyFromReg(Root, DL, NextVA.getLocReg(), MVT::i32, *InGlue);
1050 *InGlue = ArgValueHi.getValue(2);
1051 }
1052
1053 // Convert the i32 type into v32i1 type.
1054 Lo = DAG.getBitcast(MVT::v32i1, ArgValueLo);
1055
1056 // Convert the i32 type into v32i1 type.
1057 Hi = DAG.getBitcast(MVT::v32i1, ArgValueHi);
1058
1059 // Concatenate the two values together.
1060 return DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v64i1, Lo, Hi);
1061}
1062
1063/// The function will lower a register of various sizes (8/16/32/64)
1064/// to a mask value of the expected size (v8i1/v16i1/v32i1/v64i1)
1065/// \returns a DAG node contains the operand after lowering to mask type.
1066static SDValue lowerRegToMasks(const SDValue &ValArg, const EVT &ValVT,
1067 const EVT &ValLoc, const SDLoc &DL,
1068 SelectionDAG &DAG) {
1069 SDValue ValReturned = ValArg;
1070
1071 if (ValVT == MVT::v1i1)
1072 return DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, MVT::v1i1, ValReturned);
1073
1074 if (ValVT == MVT::v64i1) {
1075 // In 32 bit machine, this case is handled by getv64i1Argument
1076 assert(ValLoc == MVT::i64 && "Expecting only i64 locations");
1077 // In 64 bit machine, There is no need to truncate the value only bitcast
1078 } else {
1079 MVT MaskLenVT;
1080 switch (ValVT.getSimpleVT().SimpleTy) {
1081 case MVT::v8i1:
1082 MaskLenVT = MVT::i8;
1083 break;
1084 case MVT::v16i1:
1085 MaskLenVT = MVT::i16;
1086 break;
1087 case MVT::v32i1:
1088 MaskLenVT = MVT::i32;
1089 break;
1090 default:
1091 llvm_unreachable("Expecting a vector of i1 types");
1092 }
1093
1094 ValReturned = DAG.getNode(ISD::TRUNCATE, DL, MaskLenVT, ValReturned);
1095 }
1096 return DAG.getBitcast(ValVT, ValReturned);
1097}
1098
1100 const SDLoc &dl, Register Reg, EVT VT,
1101 SDValue Glue) {
1102 SDVTList VTs = DAG.getVTList(VT, MVT::Other, MVT::Glue);
1103 SDValue Ops[] = {Chain, DAG.getRegister(Reg, VT), Glue};
1104 return DAG.getNode(X86ISD::POP_FROM_X87_REG, dl, VTs,
1105 ArrayRef(Ops, Glue.getNode() ? 3 : 2));
1106}
1107
1108/// Lower the result values of a call into the
1109/// appropriate copies out of appropriate physical registers.
1110///
1111SDValue X86TargetLowering::LowerCallResult(
1112 SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool isVarArg,
1113 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
1115 uint32_t *RegMask) const {
1116
1117 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
1118 // Assign locations to each value returned by this call.
1120 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
1121 *DAG.getContext());
1122 CCInfo.AnalyzeCallResult(Ins, RetCC_X86);
1123
1124 // Copy all of the result registers out of their specified physreg.
1125 for (unsigned I = 0, InsIndex = 0, E = RVLocs.size(); I != E;
1126 ++I, ++InsIndex) {
1127 CCValAssign &VA = RVLocs[I];
1128 EVT CopyVT = VA.getLocVT();
1129
1130 // In some calling conventions we need to remove the used registers
1131 // from the register mask.
1132 if (RegMask) {
1133 for (MCPhysReg SubReg : TRI->subregs_inclusive(VA.getLocReg()))
1134 RegMask[SubReg / 32] &= ~(1u << (SubReg % 32));
1135 }
1136
1137 // Report an error if there was an attempt to return FP values via XMM
1138 // registers.
1139 if (!Subtarget.hasSSE1() && X86::FR32XRegClass.contains(VA.getLocReg())) {
1140 errorUnsupported(DAG, dl, "SSE register return with SSE disabled");
1141 if (VA.getLocReg() == X86::XMM1)
1142 VA.convertToReg(X86::FP1); // Set reg to FP1, avoid hitting asserts.
1143 else
1144 VA.convertToReg(X86::FP0); // Set reg to FP0, avoid hitting asserts.
1145 } else if (!Subtarget.hasSSE2() &&
1146 X86::FR64XRegClass.contains(VA.getLocReg()) &&
1147 CopyVT == MVT::f64) {
1148 errorUnsupported(DAG, dl, "SSE2 register return with SSE2 disabled");
1149 if (VA.getLocReg() == X86::XMM1)
1150 VA.convertToReg(X86::FP1); // Set reg to FP1, avoid hitting asserts.
1151 else
1152 VA.convertToReg(X86::FP0); // Set reg to FP0, avoid hitting asserts.
1153 }
1154
1155 // If we prefer to use the value in xmm registers, copy it out as f80 and
1156 // use a truncate to move it from fp stack reg to xmm reg.
1157 bool RoundAfterCopy = false;
1158 bool X87Result = VA.getLocReg() == X86::FP0 || VA.getLocReg() == X86::FP1;
1159 if (X87Result && isScalarFPTypeInSSEReg(VA.getValVT())) {
1160 if (!Subtarget.hasX87())
1161 report_fatal_error("X87 register return with X87 disabled");
1162 CopyVT = MVT::f80;
1163 RoundAfterCopy = (CopyVT != VA.getLocVT());
1164 }
1165
1166 SDValue Val;
1167 if (VA.needsCustom()) {
1168 assert(VA.getValVT() == MVT::v64i1 &&
1169 "Currently the only custom case is when we split v64i1 to 2 regs");
1170 Val =
1171 getv64i1Argument(VA, RVLocs[++I], Chain, DAG, dl, Subtarget, &InGlue);
1172 } else {
1173 Chain =
1174 X87Result
1175 ? getPopFromX87Reg(DAG, Chain, dl, VA.getLocReg(), CopyVT, InGlue)
1176 .getValue(1)
1177 : DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), CopyVT, InGlue)
1178 .getValue(1);
1179 Val = Chain.getValue(0);
1180 InGlue = Chain.getValue(2);
1181 }
1182
1183 if (RoundAfterCopy)
1184 Val = DAG.getNode(ISD::FP_ROUND, dl, VA.getValVT(), Val,
1185 // This truncation won't change the value.
1186 DAG.getIntPtrConstant(1, dl, /*isTarget=*/true));
1187
1188 if (VA.isExtInLoc()) {
1189 if (VA.getValVT().isVector() &&
1190 VA.getValVT().getScalarType() == MVT::i1 &&
1191 ((VA.getLocVT() == MVT::i64) || (VA.getLocVT() == MVT::i32) ||
1192 (VA.getLocVT() == MVT::i16) || (VA.getLocVT() == MVT::i8))) {
1193 // promoting a mask type (v*i1) into a register of type i64/i32/i16/i8
1194 Val = lowerRegToMasks(Val, VA.getValVT(), VA.getLocVT(), dl, DAG);
1195 } else
1196 Val = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), Val);
1197 }
1198
1199 if (VA.getLocInfo() == CCValAssign::BCvt)
1200 Val = DAG.getBitcast(VA.getValVT(), Val);
1201
1202 InVals.push_back(Val);
1203 }
1204
1205 return Chain;
1206}
1207
1208//===----------------------------------------------------------------------===//
1209// C & StdCall & Fast Calling Convention implementation
1210//===----------------------------------------------------------------------===//
1211// StdCall calling convention seems to be standard for many Windows' API
1212// routines and around. It differs from C calling convention just a little:
1213// callee should clean up the stack, not caller. Symbols should be also
1214// decorated in some fancy way :) It doesn't support any vector arguments.
1215// For info on fast calling convention see Fast Calling Convention (tail call)
1216// implementation LowerX86_32FastCCCallTo.
1217
1218/// Determines whether Args, either a set of outgoing arguments to a call, or a
1219/// set of incoming args of a call, contains an sret pointer that the callee
1220/// pops
1221template <typename T>
1222static bool hasCalleePopSRet(const SmallVectorImpl<T> &Args,
1223 const X86Subtarget &Subtarget) {
1224 // Not C++20 (yet), so no concepts available.
1225 static_assert(std::is_same_v<T, ISD::OutputArg> ||
1226 std::is_same_v<T, ISD::InputArg>,
1227 "requires ISD::OutputArg or ISD::InputArg");
1228
1229 // Only 32-bit pops the sret. It's a 64-bit world these days, so early-out
1230 // for most compilations.
1231 if (!Subtarget.is32Bit())
1232 return false;
1233
1234 if (Args.empty())
1235 return false;
1236
1237 // Most calls do not have an sret argument, check the arg next.
1238 const ISD::ArgFlagsTy &Flags = Args[0].Flags;
1239 if (!Flags.isSRet() || Flags.isInReg())
1240 return false;
1241
1242 // The MSVCabi does not pop the sret.
1243 if (Subtarget.getTargetTriple().isOSMSVCRT())
1244 return false;
1245
1246 // MCUs don't pop the sret
1247 if (Subtarget.isTargetMCU())
1248 return false;
1249
1250 // Callee pops argument
1251 return true;
1252}
1253
1254/// Make a copy of an aggregate at address specified by "Src" to address
1255/// "Dst" with size and alignment information specified by the specific
1256/// parameter attribute. The copy will be passed as a byval function parameter.
1258 SDValue Chain, ISD::ArgFlagsTy Flags,
1259 SelectionDAG &DAG, const SDLoc &dl) {
1260 SDValue SizeNode = DAG.getIntPtrConstant(Flags.getByValSize(), dl);
1261
1262 return DAG.getMemcpy(
1263 Chain, dl, Dst, Src, SizeNode, Flags.getNonZeroByValAlign(),
1264 /*isVolatile*/ false, /*AlwaysInline=*/true,
1265 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(), MachinePointerInfo());
1266}
1267
1268/// Return true if the calling convention is one that we can guarantee TCO for.
1270 return (CC == CallingConv::Fast || CC == CallingConv::GHC ||
1273}
1274
1275/// Return true if we might ever do TCO for calls with this calling convention.
1277 switch (CC) {
1278 // C calling conventions:
1279 case CallingConv::C:
1280 case CallingConv::Win64:
1283 // Callee pop conventions:
1288 // Swift:
1289 case CallingConv::Swift:
1290 return true;
1291 default:
1292 return canGuaranteeTCO(CC);
1293 }
1294}
1295
1296/// Return true if the function is being made into a tailcall target by
1297/// changing its ABI.
1298static bool shouldGuaranteeTCO(CallingConv::ID CC, bool GuaranteedTailCallOpt) {
1299 return (GuaranteedTailCallOpt && canGuaranteeTCO(CC)) ||
1301}
1302
1303bool X86TargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const {
1304 if (!CI->isTailCall())
1305 return false;
1306
1307 CallingConv::ID CalleeCC = CI->getCallingConv();
1308 if (!mayTailCallThisCC(CalleeCC))
1309 return false;
1310
1311 return true;
1312}
1313
1314SDValue
1315X86TargetLowering::LowerMemArgument(SDValue Chain, CallingConv::ID CallConv,
1317 const SDLoc &dl, SelectionDAG &DAG,
1318 const CCValAssign &VA,
1319 MachineFrameInfo &MFI, unsigned i) const {
1320 // Create the nodes corresponding to a load from this parameter slot.
1321 ISD::ArgFlagsTy Flags = Ins[i].Flags;
1322 bool AlwaysUseMutable = shouldGuaranteeTCO(
1323 CallConv, DAG.getTarget().Options.GuaranteedTailCallOpt);
1324 bool isImmutable = !AlwaysUseMutable && !Flags.isByVal();
1325 EVT ValVT;
1326 MVT PtrVT = getPointerTy(DAG.getDataLayout());
1327
1328 // If value is passed by pointer we have address passed instead of the value
1329 // itself. No need to extend if the mask value and location share the same
1330 // absolute size.
1331 bool ExtendedInMem =
1332 VA.isExtInLoc() && VA.getValVT().getScalarType() == MVT::i1 &&
1334
1335 if (VA.getLocInfo() == CCValAssign::Indirect || ExtendedInMem)
1336 ValVT = VA.getLocVT();
1337 else
1338 ValVT = VA.getValVT();
1339
1340 // FIXME: For now, all byval parameter objects are marked mutable. This can be
1341 // changed with more analysis.
1342 // In case of tail call optimization mark all arguments mutable. Since they
1343 // could be overwritten by lowering of arguments in case of a tail call.
1344 if (Flags.isByVal()) {
1345 unsigned Bytes = Flags.getByValSize();
1346 if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects.
1347
1348 // FIXME: For now, all byval parameter objects are marked as aliasing. This
1349 // can be improved with deeper analysis.
1350 int FI = MFI.CreateFixedObject(Bytes, VA.getLocMemOffset(), isImmutable,
1351 /*isAliased=*/true);
1352 return DAG.getFrameIndex(FI, PtrVT);
1353 }
1354
1355 EVT ArgVT = Ins[i].ArgVT;
1356
1357 // If this is a vector that has been split into multiple parts, don't elide
1358 // the copy. The layout on the stack may not match the packed in-memory
1359 // layout.
1360 bool ScalarizedVector = ArgVT.isVector() && !VA.getLocVT().isVector();
1361
1362 // This is an argument in memory. We might be able to perform copy elision.
1363 // If the argument is passed directly in memory without any extension, then we
1364 // can perform copy elision. Large vector types, for example, may be passed
1365 // indirectly by pointer.
1366 if (Flags.isCopyElisionCandidate() &&
1367 VA.getLocInfo() != CCValAssign::Indirect && !ExtendedInMem &&
1368 !ScalarizedVector) {
1369 SDValue PartAddr;
1370 if (Ins[i].PartOffset == 0) {
1371 // If this is a one-part value or the first part of a multi-part value,
1372 // create a stack object for the entire argument value type and return a
1373 // load from our portion of it. This assumes that if the first part of an
1374 // argument is in memory, the rest will also be in memory.
1375 int FI = MFI.CreateFixedObject(ArgVT.getStoreSize(), VA.getLocMemOffset(),
1376 /*IsImmutable=*/false);
1377 PartAddr = DAG.getFrameIndex(FI, PtrVT);
1378 return DAG.getLoad(
1379 ValVT, dl, Chain, PartAddr,
1381 }
1382
1383 // This is not the first piece of an argument in memory. See if there is
1384 // already a fixed stack object including this offset. If so, assume it
1385 // was created by the PartOffset == 0 branch above and create a load from
1386 // the appropriate offset into it.
1387 int64_t PartBegin = VA.getLocMemOffset();
1388 int64_t PartEnd = PartBegin + ValVT.getSizeInBits() / 8;
1389 int FI = MFI.getObjectIndexBegin();
1390 for (; MFI.isFixedObjectIndex(FI); ++FI) {
1391 int64_t ObjBegin = MFI.getObjectOffset(FI);
1392 int64_t ObjEnd = ObjBegin + MFI.getObjectSize(FI);
1393 if (ObjBegin <= PartBegin && PartEnd <= ObjEnd)
1394 break;
1395 }
1396 if (MFI.isFixedObjectIndex(FI)) {
1397 SDValue Addr =
1398 DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getFrameIndex(FI, PtrVT),
1399 DAG.getIntPtrConstant(Ins[i].PartOffset, dl));
1400 return DAG.getLoad(ValVT, dl, Chain, Addr,
1402 DAG.getMachineFunction(), FI, Ins[i].PartOffset));
1403 }
1404 }
1405
1406 int FI = MFI.CreateFixedObject(ValVT.getSizeInBits() / 8,
1407 VA.getLocMemOffset(), isImmutable);
1408
1409 // Set SExt or ZExt flag.
1410 if (VA.getLocInfo() == CCValAssign::ZExt) {
1411 MFI.setObjectZExt(FI, true);
1412 } else if (VA.getLocInfo() == CCValAssign::SExt) {
1413 MFI.setObjectSExt(FI, true);
1414 }
1415
1416 MaybeAlign Alignment;
1417 if (Subtarget.isTargetWindowsMSVC() && !Subtarget.is64Bit() &&
1418 ValVT != MVT::f80)
1419 Alignment = MaybeAlign(4);
1420 SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
1421 SDValue Val = DAG.getLoad(
1422 ValVT, dl, Chain, FIN,
1424 Alignment);
1425 return ExtendedInMem
1426 ? (VA.getValVT().isVector()
1427 ? DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VA.getValVT(), Val)
1428 : DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), Val))
1429 : Val;
1430}
1431
1432// FIXME: Get this from tablegen.
1434 const X86Subtarget &Subtarget) {
1435 assert(Subtarget.is64Bit());
1436
1437 if (Subtarget.isCallingConvWin64(CallConv)) {
1438 static const MCPhysReg GPR64ArgRegsWin64[] = {
1439 X86::RCX, X86::RDX, X86::R8, X86::R9
1440 };
1441 return GPR64ArgRegsWin64;
1442 }
1443
1444 static const MCPhysReg GPR64ArgRegs64Bit[] = {
1445 X86::RDI, X86::RSI, X86::RDX, X86::RCX, X86::R8, X86::R9
1446 };
1447 return GPR64ArgRegs64Bit;
1448}
1449
1450// FIXME: Get this from tablegen.
1452 CallingConv::ID CallConv,
1453 const X86Subtarget &Subtarget) {
1454 assert(Subtarget.is64Bit());
1455 if (Subtarget.isCallingConvWin64(CallConv)) {
1456 // The XMM registers which might contain var arg parameters are shadowed
1457 // in their paired GPR. So we only need to save the GPR to their home
1458 // slots.
1459 // TODO: __vectorcall will change this.
1460 return {};
1461 }
1462
1463 bool isSoftFloat = Subtarget.useSoftFloat();
1464 if (isSoftFloat || !Subtarget.hasSSE1())
1465 // Kernel mode asks for SSE to be disabled, so there are no XMM argument
1466 // registers.
1467 return {};
1468
1469 static const MCPhysReg XMMArgRegs64Bit[] = {
1470 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
1471 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
1472 };
1473 return XMMArgRegs64Bit;
1474}
1475
1476#ifndef NDEBUG
1478 return llvm::is_sorted(
1479 ArgLocs, [](const CCValAssign &A, const CCValAssign &B) -> bool {
1480 return A.getValNo() < B.getValNo();
1481 });
1482}
1483#endif
1484
1485namespace {
1486/// This is a helper class for lowering variable arguments parameters.
1487class VarArgsLoweringHelper {
1488public:
1489 VarArgsLoweringHelper(X86MachineFunctionInfo *FuncInfo, const SDLoc &Loc,
1490 SelectionDAG &DAG, const X86Subtarget &Subtarget,
1491 CallingConv::ID CallConv, CCState &CCInfo)
1492 : FuncInfo(FuncInfo), DL(Loc), DAG(DAG), Subtarget(Subtarget),
1493 TheMachineFunction(DAG.getMachineFunction()),
1494 TheFunction(TheMachineFunction.getFunction()),
1495 FrameInfo(TheMachineFunction.getFrameInfo()),
1496 FrameLowering(*Subtarget.getFrameLowering()),
1497 TargLowering(DAG.getTargetLoweringInfo()), CallConv(CallConv),
1498 CCInfo(CCInfo) {}
1499
1500 // Lower variable arguments parameters.
1501 void lowerVarArgsParameters(SDValue &Chain, unsigned StackSize);
1502
1503private:
1504 void createVarArgAreaAndStoreRegisters(SDValue &Chain, unsigned StackSize);
1505
1506 void forwardMustTailParameters(SDValue &Chain);
1507
1508 bool is64Bit() const { return Subtarget.is64Bit(); }
1509 bool isWin64() const { return Subtarget.isCallingConvWin64(CallConv); }
1510
1511 X86MachineFunctionInfo *FuncInfo;
1512 const SDLoc &DL;
1513 SelectionDAG &DAG;
1514 const X86Subtarget &Subtarget;
1515 MachineFunction &TheMachineFunction;
1516 const Function &TheFunction;
1517 MachineFrameInfo &FrameInfo;
1518 const TargetFrameLowering &FrameLowering;
1519 const TargetLowering &TargLowering;
1520 CallingConv::ID CallConv;
1521 CCState &CCInfo;
1522};
1523} // namespace
1524
1525void VarArgsLoweringHelper::createVarArgAreaAndStoreRegisters(
1526 SDValue &Chain, unsigned StackSize) {
1527 // If the function takes variable number of arguments, make a frame index for
1528 // the start of the first vararg value... for expansion of llvm.va_start. We
1529 // can skip this if there are no va_start calls.
1530 if (is64Bit() || (CallConv != CallingConv::X86_FastCall &&
1531 CallConv != CallingConv::X86_ThisCall)) {
1532 FuncInfo->setVarArgsFrameIndex(
1533 FrameInfo.CreateFixedObject(1, StackSize, true));
1534 }
1535
1536 // 64-bit calling conventions support varargs and register parameters, so we
1537 // have to do extra work to spill them in the prologue.
1538 if (is64Bit()) {
1539 // Find the first unallocated argument registers.
1540 ArrayRef<MCPhysReg> ArgGPRs = get64BitArgumentGPRs(CallConv, Subtarget);
1541 ArrayRef<MCPhysReg> ArgXMMs =
1542 get64BitArgumentXMMs(TheMachineFunction, CallConv, Subtarget);
1543 unsigned NumIntRegs = CCInfo.getFirstUnallocated(ArgGPRs);
1544 unsigned NumXMMRegs = CCInfo.getFirstUnallocated(ArgXMMs);
1545
1546 assert(!(NumXMMRegs && !Subtarget.hasSSE1()) &&
1547 "SSE register cannot be used when SSE is disabled!");
1548
1549 if (isWin64()) {
1550 // Get to the caller-allocated home save location. Add 8 to account
1551 // for the return address.
1552 int HomeOffset = FrameLowering.getOffsetOfLocalArea() + 8;
1553 FuncInfo->setRegSaveFrameIndex(
1554 FrameInfo.CreateFixedObject(1, NumIntRegs * 8 + HomeOffset, false));
1555 // Fixup to set vararg frame on shadow area (4 x i64).
1556 if (NumIntRegs < 4)
1557 FuncInfo->setVarArgsFrameIndex(FuncInfo->getRegSaveFrameIndex());
1558 } else {
1559 // For X86-64, if there are vararg parameters that are passed via
1560 // registers, then we must store them to their spots on the stack so
1561 // they may be loaded by dereferencing the result of va_next.
1562 FuncInfo->setVarArgsGPOffset(NumIntRegs * 8);
1563 FuncInfo->setVarArgsFPOffset(ArgGPRs.size() * 8 + NumXMMRegs * 16);
1564 FuncInfo->setRegSaveFrameIndex(FrameInfo.CreateStackObject(
1565 ArgGPRs.size() * 8 + ArgXMMs.size() * 16, Align(16), false));
1566 }
1567
1569 LiveGPRs; // list of SDValue for GPR registers keeping live input value
1570 SmallVector<SDValue, 8> LiveXMMRegs; // list of SDValue for XMM registers
1571 // keeping live input value
1572 SDValue ALVal; // if applicable keeps SDValue for %al register
1573
1574 // Gather all the live in physical registers.
1575 for (MCPhysReg Reg : ArgGPRs.slice(NumIntRegs)) {
1576 Register GPR = TheMachineFunction.addLiveIn(Reg, &X86::GR64RegClass);
1577 LiveGPRs.push_back(DAG.getCopyFromReg(Chain, DL, GPR, MVT::i64));
1578 }
1579 const auto &AvailableXmms = ArgXMMs.slice(NumXMMRegs);
1580 if (!AvailableXmms.empty()) {
1581 Register AL = TheMachineFunction.addLiveIn(X86::AL, &X86::GR8RegClass);
1582 ALVal = DAG.getCopyFromReg(Chain, DL, AL, MVT::i8);
1583 for (MCPhysReg Reg : AvailableXmms) {
1584 // FastRegisterAllocator spills virtual registers at basic
1585 // block boundary. That leads to usages of xmm registers
1586 // outside of check for %al. Pass physical registers to
1587 // VASTART_SAVE_XMM_REGS to avoid unneccessary spilling.
1588 TheMachineFunction.getRegInfo().addLiveIn(Reg);
1589 LiveXMMRegs.push_back(DAG.getRegister(Reg, MVT::v4f32));
1590 }
1591 }
1592
1593 // Store the integer parameter registers.
1595 SDValue RSFIN =
1596 DAG.getFrameIndex(FuncInfo->getRegSaveFrameIndex(),
1597 TargLowering.getPointerTy(DAG.getDataLayout()));
1598 unsigned Offset = FuncInfo->getVarArgsGPOffset();
1599 for (SDValue Val : LiveGPRs) {
1600 SDValue FIN = DAG.getNode(ISD::ADD, DL,
1601 TargLowering.getPointerTy(DAG.getDataLayout()),
1602 RSFIN, DAG.getIntPtrConstant(Offset, DL));
1603 SDValue Store =
1604 DAG.getStore(Val.getValue(1), DL, Val, FIN,
1606 DAG.getMachineFunction(),
1607 FuncInfo->getRegSaveFrameIndex(), Offset));
1608 MemOps.push_back(Store);
1609 Offset += 8;
1610 }
1611
1612 // Now store the XMM (fp + vector) parameter registers.
1613 if (!LiveXMMRegs.empty()) {
1614 SmallVector<SDValue, 12> SaveXMMOps;
1615 SaveXMMOps.push_back(Chain);
1616 SaveXMMOps.push_back(ALVal);
1617 SaveXMMOps.push_back(RSFIN);
1618 SaveXMMOps.push_back(
1619 DAG.getTargetConstant(FuncInfo->getVarArgsFPOffset(), DL, MVT::i32));
1620 llvm::append_range(SaveXMMOps, LiveXMMRegs);
1621 MachineMemOperand *StoreMMO =
1624 DAG.getMachineFunction(), FuncInfo->getRegSaveFrameIndex(),
1625 Offset),
1628 DL, DAG.getVTList(MVT::Other),
1629 SaveXMMOps, MVT::i8, StoreMMO));
1630 }
1631
1632 if (!MemOps.empty())
1633 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOps);
1634 }
1635}
1636
1637void VarArgsLoweringHelper::forwardMustTailParameters(SDValue &Chain) {
1638 // Find the largest legal vector type.
1639 MVT VecVT = MVT::Other;
1640 // FIXME: Only some x86_32 calling conventions support AVX512.
1641 if (Subtarget.useAVX512Regs() &&
1642 (is64Bit() || (CallConv == CallingConv::X86_VectorCall ||
1643 CallConv == CallingConv::Intel_OCL_BI)))
1644 VecVT = MVT::v16f32;
1645 else if (Subtarget.hasAVX())
1646 VecVT = MVT::v8f32;
1647 else if (Subtarget.hasSSE2())
1648 VecVT = MVT::v4f32;
1649
1650 // We forward some GPRs and some vector types.
1651 SmallVector<MVT, 2> RegParmTypes;
1652 MVT IntVT = is64Bit() ? MVT::i64 : MVT::i32;
1653 RegParmTypes.push_back(IntVT);
1654 if (VecVT != MVT::Other)
1655 RegParmTypes.push_back(VecVT);
1656
1657 // Compute the set of forwarded registers. The rest are scratch.
1659 FuncInfo->getForwardedMustTailRegParms();
1660 CCInfo.analyzeMustTailForwardedRegisters(Forwards, RegParmTypes, CC_X86);
1661
1662 // Forward AL for SysV x86_64 targets, since it is used for varargs.
1663 if (is64Bit() && !isWin64() && !CCInfo.isAllocated(X86::AL)) {
1664 Register ALVReg = TheMachineFunction.addLiveIn(X86::AL, &X86::GR8RegClass);
1665 Forwards.push_back(ForwardedRegister(ALVReg, X86::AL, MVT::i8));
1666 }
1667
1668 // Copy all forwards from physical to virtual registers.
1669 for (ForwardedRegister &FR : Forwards) {
1670 // FIXME: Can we use a less constrained schedule?
1671 SDValue RegVal = DAG.getCopyFromReg(Chain, DL, FR.VReg, FR.VT);
1672 FR.VReg = TheMachineFunction.getRegInfo().createVirtualRegister(
1673 TargLowering.getRegClassFor(FR.VT));
1674 Chain = DAG.getCopyToReg(Chain, DL, FR.VReg, RegVal);
1675 }
1676}
1677
1678void VarArgsLoweringHelper::lowerVarArgsParameters(SDValue &Chain,
1679 unsigned StackSize) {
1680 // Set FrameIndex to the 0xAAAAAAA value to mark unset state.
1681 // If necessary, it would be set into the correct value later.
1682 FuncInfo->setVarArgsFrameIndex(0xAAAAAAA);
1683 FuncInfo->setRegSaveFrameIndex(0xAAAAAAA);
1684
1685 if (FrameInfo.hasVAStart())
1686 createVarArgAreaAndStoreRegisters(Chain, StackSize);
1687
1688 if (FrameInfo.hasMustTailInVarArgFunc())
1689 forwardMustTailParameters(Chain);
1690}
1691
1692SDValue X86TargetLowering::LowerFormalArguments(
1693 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
1694 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
1695 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
1698
1699 const Function &F = MF.getFunction();
1700 if (F.hasExternalLinkage() && Subtarget.isTargetCygMing() &&
1701 F.getName() == "main")
1702 FuncInfo->setForceFramePointer(true);
1703
1704 MachineFrameInfo &MFI = MF.getFrameInfo();
1705 bool Is64Bit = Subtarget.is64Bit();
1706 bool IsWin64 = Subtarget.isCallingConvWin64(CallConv);
1707
1708 assert(
1709 !(IsVarArg && canGuaranteeTCO(CallConv)) &&
1710 "Var args not supported with calling conv' regcall, fastcc, ghc or hipe");
1711
1712 // Assign locations to all of the incoming arguments.
1714 CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext());
1715
1716 // Allocate shadow area for Win64.
1717 if (IsWin64)
1718 CCInfo.AllocateStack(32, Align(8));
1719
1720 CCInfo.AnalyzeArguments(Ins, CC_X86);
1721
1722 // In vectorcall calling convention a second pass is required for the HVA
1723 // types.
1724 if (CallingConv::X86_VectorCall == CallConv) {
1725 CCInfo.AnalyzeArgumentsSecondPass(Ins, CC_X86);
1726 }
1727
1728 // The next loop assumes that the locations are in the same order of the
1729 // input arguments.
1730 assert(isSortedByValueNo(ArgLocs) &&
1731 "Argument Location list must be sorted before lowering");
1732
1733 SDValue ArgValue;
1734 for (unsigned I = 0, InsIndex = 0, E = ArgLocs.size(); I != E;
1735 ++I, ++InsIndex) {
1736 assert(InsIndex < Ins.size() && "Invalid Ins index");
1737 CCValAssign &VA = ArgLocs[I];
1738
1739 if (VA.isRegLoc()) {
1740 EVT RegVT = VA.getLocVT();
1741 if (VA.needsCustom()) {
1742 assert(
1743 VA.getValVT() == MVT::v64i1 &&
1744 "Currently the only custom case is when we split v64i1 to 2 regs");
1745
1746 // v64i1 values, in regcall calling convention, that are
1747 // compiled to 32 bit arch, are split up into two registers.
1748 ArgValue =
1749 getv64i1Argument(VA, ArgLocs[++I], Chain, DAG, dl, Subtarget);
1750 } else {
1751 const TargetRegisterClass *RC;
1752 if (RegVT == MVT::i8)
1753 RC = &X86::GR8RegClass;
1754 else if (RegVT == MVT::i16)
1755 RC = &X86::GR16RegClass;
1756 else if (RegVT == MVT::i32)
1757 RC = &X86::GR32RegClass;
1758 else if (Is64Bit && RegVT == MVT::i64)
1759 RC = &X86::GR64RegClass;
1760 else if (RegVT == MVT::f16)
1761 RC = Subtarget.hasAVX512() ? &X86::FR16XRegClass : &X86::FR16RegClass;
1762 else if (RegVT == MVT::f32)
1763 RC = Subtarget.hasAVX512() ? &X86::FR32XRegClass : &X86::FR32RegClass;
1764 else if (RegVT == MVT::f64)
1765 RC = Subtarget.hasAVX512() ? &X86::FR64XRegClass : &X86::FR64RegClass;
1766 else if (RegVT == MVT::f80)
1767 RC = &X86::RFP80RegClass;
1768 else if (RegVT == MVT::f128)
1769 RC = &X86::VR128RegClass;
1770 else if (RegVT.is512BitVector())
1771 RC = &X86::VR512RegClass;
1772 else if (RegVT.is256BitVector())
1773 RC = Subtarget.hasVLX() ? &X86::VR256XRegClass : &X86::VR256RegClass;
1774 else if (RegVT.is128BitVector())
1775 RC = Subtarget.hasVLX() ? &X86::VR128XRegClass : &X86::VR128RegClass;
1776 else if (RegVT == MVT::x86mmx)
1777 RC = &X86::VR64RegClass;
1778 else if (RegVT == MVT::v1i1)
1779 RC = &X86::VK1RegClass;
1780 else if (RegVT == MVT::v8i1)
1781 RC = &X86::VK8RegClass;
1782 else if (RegVT == MVT::v16i1)
1783 RC = &X86::VK16RegClass;
1784 else if (RegVT == MVT::v32i1)
1785 RC = &X86::VK32RegClass;
1786 else if (RegVT == MVT::v64i1)
1787 RC = &X86::VK64RegClass;
1788 else
1789 llvm_unreachable("Unknown argument type!");
1790
1791 Register Reg = MF.addLiveIn(VA.getLocReg(), RC);
1792 ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT);
1793 }
1794
1795 // If this is an 8 or 16-bit value, it is really passed promoted to 32
1796 // bits. Insert an assert[sz]ext to capture this, then truncate to the
1797 // right size.
1798 if (VA.getLocInfo() == CCValAssign::SExt)
1799 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
1800 DAG.getValueType(VA.getValVT()));
1801 else if (VA.getLocInfo() == CCValAssign::ZExt)
1802 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
1803 DAG.getValueType(VA.getValVT()));
1804 else if (VA.getLocInfo() == CCValAssign::BCvt)
1805 ArgValue = DAG.getBitcast(VA.getValVT(), ArgValue);
1806
1807 if (VA.isExtInLoc()) {
1808 // Handle MMX values passed in XMM regs.
1809 if (RegVT.isVector() && VA.getValVT().getScalarType() != MVT::i1)
1810 ArgValue = DAG.getNode(X86ISD::MOVDQ2Q, dl, VA.getValVT(), ArgValue);
1811 else if (VA.getValVT().isVector() &&
1812 VA.getValVT().getScalarType() == MVT::i1 &&
1813 ((VA.getLocVT() == MVT::i64) || (VA.getLocVT() == MVT::i32) ||
1814 (VA.getLocVT() == MVT::i16) || (VA.getLocVT() == MVT::i8))) {
1815 // Promoting a mask type (v*i1) into a register of type i64/i32/i16/i8
1816 ArgValue = lowerRegToMasks(ArgValue, VA.getValVT(), RegVT, dl, DAG);
1817 } else
1818 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
1819 }
1820 } else {
1821 assert(VA.isMemLoc());
1822 ArgValue =
1823 LowerMemArgument(Chain, CallConv, Ins, dl, DAG, VA, MFI, InsIndex);
1824 }
1825
1826 // If value is passed via pointer - do a load.
1827 if (VA.getLocInfo() == CCValAssign::Indirect &&
1828 !(Ins[I].Flags.isByVal() && VA.isRegLoc())) {
1829 ArgValue =
1830 DAG.getLoad(VA.getValVT(), dl, Chain, ArgValue, MachinePointerInfo());
1831 }
1832
1833 InVals.push_back(ArgValue);
1834 }
1835
1836 for (unsigned I = 0, E = Ins.size(); I != E; ++I) {
1837 if (Ins[I].Flags.isSwiftAsync()) {
1838 auto X86FI = MF.getInfo<X86MachineFunctionInfo>();
1839 if (X86::isExtendedSwiftAsyncFrameSupported(Subtarget, MF))
1840 X86FI->setHasSwiftAsyncContext(true);
1841 else {
1842 int PtrSize = Subtarget.is64Bit() ? 8 : 4;
1843 int FI =
1844 MF.getFrameInfo().CreateStackObject(PtrSize, Align(PtrSize), false);
1845 X86FI->setSwiftAsyncContextFrameIdx(FI);
1846 SDValue St = DAG.getStore(
1847 DAG.getEntryNode(), dl, InVals[I],
1848 DAG.getFrameIndex(FI, PtrSize == 8 ? MVT::i64 : MVT::i32),
1850 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, St, Chain);
1851 }
1852 }
1853
1854 // Swift calling convention does not require we copy the sret argument
1855 // into %rax/%eax for the return. We don't set SRetReturnReg for Swift.
1856 if (CallConv == CallingConv::Swift || CallConv == CallingConv::SwiftTail)
1857 continue;
1858
1859 // All x86 ABIs require that for returning structs by value we copy the
1860 // sret argument into %rax/%eax (depending on ABI) for the return. Save
1861 // the argument into a virtual register so that we can access it from the
1862 // return points.
1863 if (Ins[I].Flags.isSRet()) {
1864 assert(!FuncInfo->getSRetReturnReg() &&
1865 "SRet return has already been set");
1866 MVT PtrTy = getPointerTy(DAG.getDataLayout());
1867 Register Reg =
1869 FuncInfo->setSRetReturnReg(Reg);
1870 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[I]);
1871 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
1872 break;
1873 }
1874 }
1875
1876 unsigned StackSize = CCInfo.getStackSize();
1877 // Align stack specially for tail calls.
1878 if (shouldGuaranteeTCO(CallConv,
1880 StackSize = GetAlignedArgumentStackSize(StackSize, DAG);
1881
1882 if (IsVarArg)
1883 VarArgsLoweringHelper(FuncInfo, dl, DAG, Subtarget, CallConv, CCInfo)
1884 .lowerVarArgsParameters(Chain, StackSize);
1885
1886 // Some CCs need callee pop.
1887 if (X86::isCalleePop(CallConv, Is64Bit, IsVarArg,
1889 FuncInfo->setBytesToPopOnReturn(StackSize); // Callee pops everything.
1890 } else if (CallConv == CallingConv::X86_INTR && Ins.size() == 2) {
1891 // X86 interrupts must pop the error code (and the alignment padding) if
1892 // present.
1893 FuncInfo->setBytesToPopOnReturn(Is64Bit ? 16 : 4);
1894 } else {
1895 FuncInfo->setBytesToPopOnReturn(0); // Callee pops nothing.
1896 // If this is an sret function, the return should pop the hidden pointer.
1897 if (!canGuaranteeTCO(CallConv) && hasCalleePopSRet(Ins, Subtarget))
1898 FuncInfo->setBytesToPopOnReturn(4);
1899 }
1900
1901 if (!Is64Bit) {
1902 // RegSaveFrameIndex is X86-64 only.
1903 FuncInfo->setRegSaveFrameIndex(0xAAAAAAA);
1904 }
1905
1906 FuncInfo->setArgumentStackSize(StackSize);
1907
1908 if (WinEHFuncInfo *EHInfo = MF.getWinEHFuncInfo()) {
1909 EHPersonality Personality = classifyEHPersonality(F.getPersonalityFn());
1910 if (Personality == EHPersonality::CoreCLR) {
1911 assert(Is64Bit);
1912 // TODO: Add a mechanism to frame lowering that will allow us to indicate
1913 // that we'd prefer this slot be allocated towards the bottom of the frame
1914 // (i.e. near the stack pointer after allocating the frame). Every
1915 // funclet needs a copy of this slot in its (mostly empty) frame, and the
1916 // offset from the bottom of this and each funclet's frame must be the
1917 // same, so the size of funclets' (mostly empty) frames is dictated by
1918 // how far this slot is from the bottom (since they allocate just enough
1919 // space to accommodate holding this slot at the correct offset).
1920 int PSPSymFI = MFI.CreateStackObject(8, Align(8), /*isSpillSlot=*/false);
1921 EHInfo->PSPSymFrameIdx = PSPSymFI;
1922 }
1923 }
1924
1925 if (shouldDisableArgRegFromCSR(CallConv) ||
1926 F.hasFnAttribute("no_caller_saved_registers")) {
1928 for (std::pair<MCRegister, Register> Pair : MRI.liveins())
1929 MRI.disableCalleeSavedRegister(Pair.first);
1930 }
1931
1932 if (CallingConv::PreserveNone == CallConv)
1933 for (const ISD::InputArg &In : Ins) {
1934 if (In.Flags.isSwiftSelf() || In.Flags.isSwiftAsync() ||
1935 In.Flags.isSwiftError()) {
1936 errorUnsupported(DAG, dl,
1937 "Swift attributes can't be used with preserve_none");
1938 break;
1939 }
1940 }
1941
1942 return Chain;
1943}
1944
1945SDValue X86TargetLowering::LowerMemOpCallTo(SDValue Chain, SDValue StackPtr,
1946 SDValue Arg, const SDLoc &dl,
1947 SelectionDAG &DAG,
1948 const CCValAssign &VA,
1949 ISD::ArgFlagsTy Flags,
1950 bool isByVal) const {
1951 unsigned LocMemOffset = VA.getLocMemOffset();
1952 SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset, dl);
1953 PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(DAG.getDataLayout()),
1954 StackPtr, PtrOff);
1955 if (isByVal)
1956 return CreateCopyOfByValArgument(Arg, PtrOff, Chain, Flags, DAG, dl);
1957
1958 MaybeAlign Alignment;
1959 if (Subtarget.isTargetWindowsMSVC() && !Subtarget.is64Bit() &&
1960 Arg.getSimpleValueType() != MVT::f80)
1961 Alignment = MaybeAlign(4);
1962 return DAG.getStore(
1963 Chain, dl, Arg, PtrOff,
1965 Alignment);
1966}
1967
1968/// Emit a load of return address if tail call
1969/// optimization is performed and it is required.
1970SDValue X86TargetLowering::EmitTailCallLoadRetAddr(
1971 SelectionDAG &DAG, SDValue &OutRetAddr, SDValue Chain, bool IsTailCall,
1972 bool Is64Bit, int FPDiff, const SDLoc &dl) const {
1973 // Adjust the Return address stack slot.
1974 EVT VT = getPointerTy(DAG.getDataLayout());
1975 OutRetAddr = getReturnAddressFrameIndex(DAG);
1976
1977 // Load the "old" Return address.
1978 OutRetAddr = DAG.getLoad(VT, dl, Chain, OutRetAddr, MachinePointerInfo());
1979 return SDValue(OutRetAddr.getNode(), 1);
1980}
1981
1982/// Emit a store of the return address if tail call
1983/// optimization is performed and it is required (FPDiff!=0).
1985 SDValue Chain, SDValue RetAddrFrIdx,
1986 EVT PtrVT, unsigned SlotSize,
1987 int FPDiff, const SDLoc &dl) {
1988 // Store the return address to the appropriate stack slot.
1989 if (!FPDiff) return Chain;
1990 // Calculate the new stack slot for the return address.
1991 int NewReturnAddrFI =
1992 MF.getFrameInfo().CreateFixedObject(SlotSize, (int64_t)FPDiff - SlotSize,
1993 false);
1994 SDValue NewRetAddrFrIdx = DAG.getFrameIndex(NewReturnAddrFI, PtrVT);
1995 Chain = DAG.getStore(Chain, dl, RetAddrFrIdx, NewRetAddrFrIdx,
1997 DAG.getMachineFunction(), NewReturnAddrFI));
1998 return Chain;
1999}
2000
2001/// Returns a vector_shuffle mask for an movs{s|d}, movd
2002/// operation of specified width.
2003SDValue X86TargetLowering::getMOVL(SelectionDAG &DAG, const SDLoc &dl, MVT VT,
2004 SDValue V1, SDValue V2) const {
2005 unsigned NumElems = VT.getVectorNumElements();
2007 Mask.push_back(NumElems);
2008 for (unsigned i = 1; i != NumElems; ++i)
2009 Mask.push_back(i);
2010 return DAG.getVectorShuffle(VT, dl, V1, V2, Mask);
2011}
2012
2013SDValue
2014X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
2015 SmallVectorImpl<SDValue> &InVals) const {
2016 SelectionDAG &DAG = CLI.DAG;
2017 SDLoc &dl = CLI.DL;
2019 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
2021 SDValue Chain = CLI.Chain;
2022 SDValue Callee = CLI.Callee;
2023 CallingConv::ID CallConv = CLI.CallConv;
2024 bool &isTailCall = CLI.IsTailCall;
2025 bool isVarArg = CLI.IsVarArg;
2026 const auto *CB = CLI.CB;
2027
2029 bool Is64Bit = Subtarget.is64Bit();
2030 bool IsWin64 = Subtarget.isCallingConvWin64(CallConv);
2031 bool IsSibcall = false;
2032 bool IsGuaranteeTCO = MF.getTarget().Options.GuaranteedTailCallOpt ||
2033 CallConv == CallingConv::Tail || CallConv == CallingConv::SwiftTail;
2034 bool IsCalleePopSRet = !IsGuaranteeTCO && hasCalleePopSRet(Outs, Subtarget);
2036 bool HasNCSR = (CB && isa<CallInst>(CB) &&
2037 CB->hasFnAttr("no_caller_saved_registers"));
2038 bool IsIndirectCall = (CB && isa<CallInst>(CB) && CB->isIndirectCall());
2039 bool IsCFICall = IsIndirectCall && CLI.CFIType;
2040 const Module *M = MF.getFunction().getParent();
2041
2042 // If the indirect call target has the nocf_check attribute, the call needs
2043 // the NOTRACK prefix. For simplicity just disable tail calls as there are
2044 // so many variants.
2045 bool IsNoTrackIndirectCall = IsIndirectCall && CB->doesNoCfCheck() &&
2046 M->getModuleFlag("cf-protection-branch");
2047 if (IsNoTrackIndirectCall)
2048 isTailCall = false;
2049
2051 if (CallConv == CallingConv::X86_INTR)
2052 report_fatal_error("X86 interrupts may not be called directly");
2053
2054 // Set type id for call site info.
2055 if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall())
2056 CSInfo = MachineFunction::CallSiteInfo(*CB);
2057
2058 if (IsIndirectCall && !IsWin64 &&
2059 M->getModuleFlag("import-call-optimization"))
2060 errorUnsupported(DAG, dl,
2061 "Indirect calls must have a normal calling convention if "
2062 "Import Call Optimization is enabled");
2063
2064 // Analyze operands of the call, assigning locations to each operand.
2066 CCState CCInfo(CallConv, isVarArg, MF, ArgLocs, *DAG.getContext());
2067
2068 // Allocate shadow area for Win64.
2069 if (IsWin64)
2070 CCInfo.AllocateStack(32, Align(8));
2071
2072 CCInfo.AnalyzeArguments(Outs, CC_X86);
2073
2074 // In vectorcall calling convention a second pass is required for the HVA
2075 // types.
2076 if (CallingConv::X86_VectorCall == CallConv) {
2077 CCInfo.AnalyzeArgumentsSecondPass(Outs, CC_X86);
2078 }
2079
2080 bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
2081 if (Subtarget.isPICStyleGOT() && !IsGuaranteeTCO && !IsMustTail) {
2082 // If we are using a GOT, disable tail calls to external symbols with
2083 // default visibility. Tail calling such a symbol requires using a GOT
2084 // relocation, which forces early binding of the symbol. This breaks code
2085 // that require lazy function symbol resolution. Using musttail or
2086 // GuaranteedTailCallOpt will override this.
2087 GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
2088 if (!G || (!G->getGlobal()->hasLocalLinkage() &&
2089 G->getGlobal()->hasDefaultVisibility()))
2090 isTailCall = false;
2091 }
2092
2093 if (isTailCall && !IsMustTail) {
2094 // Check if it's really possible to do a tail call.
2095 isTailCall = IsEligibleForTailCallOptimization(CLI, CCInfo, ArgLocs,
2096 IsCalleePopSRet);
2097
2098 // Sibcalls are automatically detected tailcalls which do not require
2099 // ABI changes.
2100 if (!IsGuaranteeTCO && isTailCall)
2101 IsSibcall = true;
2102
2103 if (isTailCall)
2104 ++NumTailCalls;
2105 }
2106
2107 if (IsMustTail && !isTailCall)
2108 report_fatal_error("failed to perform tail call elimination on a call "
2109 "site marked musttail");
2110
2111 assert(!(isVarArg && canGuaranteeTCO(CallConv)) &&
2112 "Var args not supported with calling convention fastcc, ghc or hipe");
2113
2114 // Get a count of how many bytes are to be pushed on the stack.
2115 unsigned NumBytes = CCInfo.getAlignedCallFrameSize();
2116 if (IsSibcall)
2117 // This is a sibcall. The memory operands are available in caller's
2118 // own caller's stack.
2119 NumBytes = 0;
2120 else if (IsGuaranteeTCO && canGuaranteeTCO(CallConv))
2121 NumBytes = GetAlignedArgumentStackSize(NumBytes, DAG);
2122
2123 int FPDiff = 0;
2124 if (isTailCall &&
2125 shouldGuaranteeTCO(CallConv,
2127 // Lower arguments at fp - stackoffset + fpdiff.
2128 unsigned NumBytesCallerPushed = X86Info->getBytesToPopOnReturn();
2129
2130 FPDiff = NumBytesCallerPushed - NumBytes;
2131
2132 // Set the delta of movement of the returnaddr stackslot.
2133 // But only set if delta is greater than previous delta.
2134 if (FPDiff < X86Info->getTCReturnAddrDelta())
2135 X86Info->setTCReturnAddrDelta(FPDiff);
2136 }
2137
2138 unsigned NumBytesToPush = NumBytes;
2139 unsigned NumBytesToPop = NumBytes;
2140
2141 // If we have an inalloca argument, all stack space has already been allocated
2142 // for us and be right at the top of the stack. We don't support multiple
2143 // arguments passed in memory when using inalloca.
2144 if (!Outs.empty() && Outs.back().Flags.isInAlloca()) {
2145 NumBytesToPush = 0;
2146 if (!ArgLocs.back().isMemLoc())
2147 report_fatal_error("cannot use inalloca attribute on a register "
2148 "parameter");
2149 if (ArgLocs.back().getLocMemOffset() != 0)
2150 report_fatal_error("any parameter with the inalloca attribute must be "
2151 "the only memory argument");
2152 } else if (CLI.IsPreallocated) {
2153 assert(ArgLocs.back().isMemLoc() &&
2154 "cannot use preallocated attribute on a register "
2155 "parameter");
2156 SmallVector<size_t, 4> PreallocatedOffsets;
2157 for (size_t i = 0; i < CLI.OutVals.size(); ++i) {
2158 if (CLI.CB->paramHasAttr(i, Attribute::Preallocated)) {
2159 PreallocatedOffsets.push_back(ArgLocs[i].getLocMemOffset());
2160 }
2161 }
2163 size_t PreallocatedId = MFI->getPreallocatedIdForCallSite(CLI.CB);
2164 MFI->setPreallocatedStackSize(PreallocatedId, NumBytes);
2165 MFI->setPreallocatedArgOffsets(PreallocatedId, PreallocatedOffsets);
2166 NumBytesToPush = 0;
2167 }
2168
2169 if (!IsSibcall && !IsMustTail)
2170 Chain = DAG.getCALLSEQ_START(Chain, NumBytesToPush,
2171 NumBytes - NumBytesToPush, dl);
2172
2173 SDValue RetAddrFrIdx;
2174 // Load return address for tail calls.
2175 if (isTailCall && FPDiff)
2176 Chain = EmitTailCallLoadRetAddr(DAG, RetAddrFrIdx, Chain, isTailCall,
2177 Is64Bit, FPDiff, dl);
2178
2180 SmallVector<SDValue, 8> MemOpChains;
2182
2183 // The next loop assumes that the locations are in the same order of the
2184 // input arguments.
2185 assert(isSortedByValueNo(ArgLocs) &&
2186 "Argument Location list must be sorted before lowering");
2187
2188 // Walk the register/memloc assignments, inserting copies/loads. In the case
2189 // of tail call optimization arguments are handle later.
2190 const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
2191 for (unsigned I = 0, OutIndex = 0, E = ArgLocs.size(); I != E;
2192 ++I, ++OutIndex) {
2193 assert(OutIndex < Outs.size() && "Invalid Out index");
2194 // Skip inalloca/preallocated arguments, they have already been written.
2195 ISD::ArgFlagsTy Flags = Outs[OutIndex].Flags;
2196 if (Flags.isInAlloca() || Flags.isPreallocated())
2197 continue;
2198
2199 CCValAssign &VA = ArgLocs[I];
2200 EVT RegVT = VA.getLocVT();
2201 SDValue Arg = OutVals[OutIndex];
2202 bool isByVal = Flags.isByVal();
2203
2204 // Promote the value if needed.
2205 switch (VA.getLocInfo()) {
2206 default: llvm_unreachable("Unknown loc info!");
2207 case CCValAssign::Full: break;
2208 case CCValAssign::SExt:
2209 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, RegVT, Arg);
2210 break;
2211 case CCValAssign::ZExt:
2212 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, RegVT, Arg);
2213 break;
2214 case CCValAssign::AExt:
2215 if (Arg.getValueType().isVector() &&
2216 Arg.getValueType().getVectorElementType() == MVT::i1)
2217 Arg = lowerMasksToReg(Arg, RegVT, dl, DAG);
2218 else if (RegVT.is128BitVector()) {
2219 // Special case: passing MMX values in XMM registers.
2220 Arg = DAG.getBitcast(MVT::i64, Arg);
2221 Arg = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2i64, Arg);
2222 Arg = getMOVL(DAG, dl, MVT::v2i64, DAG.getUNDEF(MVT::v2i64), Arg);
2223 } else
2224 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, RegVT, Arg);
2225 break;
2226 case CCValAssign::BCvt:
2227 Arg = DAG.getBitcast(RegVT, Arg);
2228 break;
2229 case CCValAssign::Indirect: {
2230 if (isByVal) {
2231 // Memcpy the argument to a temporary stack slot to prevent
2232 // the caller from seeing any modifications the callee may make
2233 // as guaranteed by the `byval` attribute.
2234 int FrameIdx = MF.getFrameInfo().CreateStackObject(
2235 Flags.getByValSize(),
2236 std::max(Align(16), Flags.getNonZeroByValAlign()), false);
2237 SDValue StackSlot =
2238 DAG.getFrameIndex(FrameIdx, getPointerTy(DAG.getDataLayout()));
2239 Chain =
2240 CreateCopyOfByValArgument(Arg, StackSlot, Chain, Flags, DAG, dl);
2241 // From now on treat this as a regular pointer
2242 Arg = StackSlot;
2243 isByVal = false;
2244 } else {
2245 // Store the argument.
2246 SDValue SpillSlot = DAG.CreateStackTemporary(VA.getValVT());
2247 int FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
2248 Chain = DAG.getStore(
2249 Chain, dl, Arg, SpillSlot,
2251 Arg = SpillSlot;
2252 }
2253 break;
2254 }
2255 }
2256
2257 if (VA.needsCustom()) {
2258 assert(VA.getValVT() == MVT::v64i1 &&
2259 "Currently the only custom case is when we split v64i1 to 2 regs");
2260 // Split v64i1 value into two registers
2261 Passv64i1ArgInRegs(dl, DAG, Arg, RegsToPass, VA, ArgLocs[++I], Subtarget);
2262 } else if (VA.isRegLoc()) {
2263 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
2264 const TargetOptions &Options = DAG.getTarget().Options;
2265 if (Options.EmitCallSiteInfo)
2266 CSInfo.ArgRegPairs.emplace_back(VA.getLocReg(), I);
2267 if (isVarArg && IsWin64) {
2268 // Win64 ABI requires argument XMM reg to be copied to the corresponding
2269 // shadow reg if callee is a varargs function.
2270 Register ShadowReg;
2271 switch (VA.getLocReg()) {
2272 case X86::XMM0: ShadowReg = X86::RCX; break;
2273 case X86::XMM1: ShadowReg = X86::RDX; break;
2274 case X86::XMM2: ShadowReg = X86::R8; break;
2275 case X86::XMM3: ShadowReg = X86::R9; break;
2276 }
2277 if (ShadowReg)
2278 RegsToPass.push_back(std::make_pair(ShadowReg, Arg));
2279 }
2280 } else if (!IsSibcall && (!isTailCall || isByVal)) {
2281 assert(VA.isMemLoc());
2282 if (!StackPtr.getNode())
2283 StackPtr = DAG.getCopyFromReg(Chain, dl, RegInfo->getStackRegister(),
2285 MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg,
2286 dl, DAG, VA, Flags, isByVal));
2287 }
2288 }
2289
2290 if (!MemOpChains.empty())
2291 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
2292
2293 if (Subtarget.isPICStyleGOT()) {
2294 // ELF / PIC requires GOT in the EBX register before function calls via PLT
2295 // GOT pointer (except regcall).
2296 if (!isTailCall) {
2297 // Indirect call with RegCall calling convertion may use up all the
2298 // general registers, so it is not suitable to bind EBX reister for
2299 // GOT address, just let register allocator handle it.
2300 if (CallConv != CallingConv::X86_RegCall)
2301 RegsToPass.push_back(std::make_pair(
2302 Register(X86::EBX), DAG.getNode(X86ISD::GlobalBaseReg, SDLoc(),
2303 getPointerTy(DAG.getDataLayout()))));
2304 } else {
2305 // If we are tail calling and generating PIC/GOT style code load the
2306 // address of the callee into ECX. The value in ecx is used as target of
2307 // the tail jump. This is done to circumvent the ebx/callee-saved problem
2308 // for tail calls on PIC/GOT architectures. Normally we would just put the
2309 // address of GOT into ebx and then call target@PLT. But for tail calls
2310 // ebx would be restored (since ebx is callee saved) before jumping to the
2311 // target@PLT.
2312
2313 // Note: The actual moving to ECX is done further down.
2314 GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
2315 if (G && !G->getGlobal()->hasLocalLinkage() &&
2316 G->getGlobal()->hasDefaultVisibility())
2317 Callee = LowerGlobalAddress(Callee, DAG);
2318 else if (isa<ExternalSymbolSDNode>(Callee))
2319 Callee = LowerExternalSymbol(Callee, DAG);
2320 }
2321 }
2322
2323 if (Is64Bit && isVarArg && !IsWin64 && !IsMustTail &&
2324 (Subtarget.hasSSE1() || !M->getModuleFlag("SkipRaxSetup"))) {
2325 // From AMD64 ABI document:
2326 // For calls that may call functions that use varargs or stdargs
2327 // (prototype-less calls or calls to functions containing ellipsis (...) in
2328 // the declaration) %al is used as hidden argument to specify the number
2329 // of SSE registers used. The contents of %al do not need to match exactly
2330 // the number of registers, but must be an ubound on the number of SSE
2331 // registers used and is in the range 0 - 8 inclusive.
2332
2333 // Count the number of XMM registers allocated.
2334 static const MCPhysReg XMMArgRegs[] = {
2335 X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
2336 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7
2337 };
2338 unsigned NumXMMRegs = CCInfo.getFirstUnallocated(XMMArgRegs);
2339 assert((Subtarget.hasSSE1() || !NumXMMRegs)
2340 && "SSE registers cannot be used when SSE is disabled");
2341 RegsToPass.push_back(std::make_pair(Register(X86::AL),
2342 DAG.getConstant(NumXMMRegs, dl,
2343 MVT::i8)));
2344 }
2345
2346 if (isVarArg && IsMustTail) {
2347 const auto &Forwards = X86Info->getForwardedMustTailRegParms();
2348 for (const auto &F : Forwards) {
2349 SDValue Val = DAG.getCopyFromReg(Chain, dl, F.VReg, F.VT);
2350 RegsToPass.push_back(std::make_pair(F.PReg, Val));
2351 }
2352 }
2353
2354 // For tail calls lower the arguments to the 'real' stack slots. Sibcalls
2355 // don't need this because the eligibility check rejects calls that require
2356 // shuffling arguments passed in memory.
2357 if (!IsSibcall && isTailCall) {
2358 // Force all the incoming stack arguments to be loaded from the stack
2359 // before any new outgoing arguments or the return address are stored to the
2360 // stack, because the outgoing stack slots may alias the incoming argument
2361 // stack slots, and the alias isn't otherwise explicit. This is slightly
2362 // more conservative than necessary, because it means that each store
2363 // effectively depends on every argument instead of just those arguments it
2364 // would clobber.
2365 Chain = DAG.getStackArgumentTokenFactor(Chain);
2366
2367 SmallVector<SDValue, 8> MemOpChains2;
2368 SDValue FIN;
2369 int FI = 0;
2370 for (unsigned I = 0, OutsIndex = 0, E = ArgLocs.size(); I != E;
2371 ++I, ++OutsIndex) {
2372 CCValAssign &VA = ArgLocs[I];
2373
2374 if (VA.isRegLoc()) {
2375 if (VA.needsCustom()) {
2376 assert((CallConv == CallingConv::X86_RegCall) &&
2377 "Expecting custom case only in regcall calling convention");
2378 // This means that we are in special case where one argument was
2379 // passed through two register locations - Skip the next location
2380 ++I;
2381 }
2382
2383 continue;
2384 }
2385
2386 assert(VA.isMemLoc());
2387 SDValue Arg = OutVals[OutsIndex];
2388 ISD::ArgFlagsTy Flags = Outs[OutsIndex].Flags;
2389 // Skip inalloca/preallocated arguments. They don't require any work.
2390 if (Flags.isInAlloca() || Flags.isPreallocated())
2391 continue;
2392 // Create frame index.
2393 int32_t Offset = VA.getLocMemOffset()+FPDiff;
2394 uint32_t OpSize = (VA.getLocVT().getSizeInBits()+7)/8;
2395 FI = MF.getFrameInfo().CreateFixedObject(OpSize, Offset, true);
2396 FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
2397
2398 if (Flags.isByVal()) {
2399 // Copy relative to framepointer.
2401 if (!StackPtr.getNode())
2402 StackPtr = DAG.getCopyFromReg(Chain, dl, RegInfo->getStackRegister(),
2405 StackPtr, Source);
2406
2407 MemOpChains2.push_back(
2408 CreateCopyOfByValArgument(Source, FIN, Chain, Flags, DAG, dl));
2409 } else {
2410 // Store relative to framepointer.
2411 MemOpChains2.push_back(DAG.getStore(
2412 Chain, dl, Arg, FIN,
2414 }
2415 }
2416
2417 if (!MemOpChains2.empty())
2418 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains2);
2419
2420 // Store the return address to the appropriate stack slot.
2421 Chain = EmitTailCallStoreRetAddr(DAG, MF, Chain, RetAddrFrIdx,
2423 RegInfo->getSlotSize(), FPDiff, dl);
2424 }
2425
2426 // Build a sequence of copy-to-reg nodes chained together with token chain
2427 // and glue operands which copy the outgoing args into registers.
2428 SDValue InGlue;
2429 for (const auto &[Reg, N] : RegsToPass) {
2430 Chain = DAG.getCopyToReg(Chain, dl, Reg, N, InGlue);
2431 InGlue = Chain.getValue(1);
2432 }
2433
2434 bool IsImpCall = false;
2435 if (DAG.getTarget().getCodeModel() == CodeModel::Large) {
2436 assert(Is64Bit && "Large code model is only legal in 64-bit mode.");
2437 // In the 64-bit large code model, we have to make all calls
2438 // through a register, since the call instruction's 32-bit
2439 // pc-relative offset may not be large enough to hold the whole
2440 // address.
2441 } else if (Callee->getOpcode() == ISD::GlobalAddress ||
2442 Callee->getOpcode() == ISD::ExternalSymbol) {
2443 // Lower direct calls to global addresses and external symbols. Setting
2444 // ForCall to true here has the effect of removing WrapperRIP when possible
2445 // to allow direct calls to be selected without first materializing the
2446 // address into a register.
2447 Callee = LowerGlobalOrExternal(Callee, DAG, /*ForCall=*/true, &IsImpCall);
2448 } else if (Subtarget.isTarget64BitILP32() &&
2449 Callee.getValueType() == MVT::i32) {
2450 // Zero-extend the 32-bit Callee address into a 64-bit according to x32 ABI
2451 Callee = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, Callee);
2452 }
2453
2455
2456 if (!IsSibcall && isTailCall && !IsMustTail) {
2457 Chain = DAG.getCALLSEQ_END(Chain, NumBytesToPop, 0, InGlue, dl);
2458 InGlue = Chain.getValue(1);
2459 }
2460
2461 Ops.push_back(Chain);
2462 Ops.push_back(Callee);
2463
2464 if (isTailCall)
2465 Ops.push_back(DAG.getSignedTargetConstant(FPDiff, dl, MVT::i32));
2466
2467 // Add argument registers to the end of the list so that they are known live
2468 // into the call.
2469 for (const auto &[Reg, N] : RegsToPass)
2470 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
2471
2472 // Add a register mask operand representing the call-preserved registers.
2473 const uint32_t *Mask = [&]() {
2474 auto AdaptedCC = CallConv;
2475 // If HasNCSR is asserted (attribute NoCallerSavedRegisters exists),
2476 // use X86_INTR calling convention because it has the same CSR mask
2477 // (same preserved registers).
2478 if (HasNCSR)
2480 // If NoCalleeSavedRegisters is requested, than use GHC since it happens
2481 // to use the CSR_NoRegs_RegMask.
2482 if (CB && CB->hasFnAttr("no_callee_saved_registers"))
2483 AdaptedCC = (CallingConv::ID)CallingConv::GHC;
2484 return RegInfo->getCallPreservedMask(MF, AdaptedCC);
2485 }();
2486 assert(Mask && "Missing call preserved mask for calling convention");
2487
2488 if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getFramePtr())) {
2489 X86Info->setFPClobberedByCall(true);
2490 if (CLI.CB && isa<InvokeInst>(CLI.CB))
2491 X86Info->setFPClobberedByInvoke(true);
2492 }
2493 if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getBaseRegister())) {
2494 X86Info->setBPClobberedByCall(true);
2495 if (CLI.CB && isa<InvokeInst>(CLI.CB))
2496 X86Info->setBPClobberedByInvoke(true);
2497 }
2498
2499 // If this is an invoke in a 32-bit function using a funclet-based
2500 // personality, assume the function clobbers all registers. If an exception
2501 // is thrown, the runtime will not restore CSRs.
2502 // FIXME: Model this more precisely so that we can register allocate across
2503 // the normal edge and spill and fill across the exceptional edge.
2504 if (!Is64Bit && CLI.CB && isa<InvokeInst>(CLI.CB)) {
2505 const Function &CallerFn = MF.getFunction();
2506 EHPersonality Pers =
2507 CallerFn.hasPersonalityFn()
2510 if (isFuncletEHPersonality(Pers))
2511 Mask = RegInfo->getNoPreservedMask();
2512 }
2513
2514 // Define a new register mask from the existing mask.
2515 uint32_t *RegMask = nullptr;
2516
2517 // In some calling conventions we need to remove the used physical registers
2518 // from the reg mask. Create a new RegMask for such calling conventions.
2519 // RegMask for calling conventions that disable only return registers (e.g.
2520 // preserve_most) will be modified later in LowerCallResult.
2521 bool ShouldDisableArgRegs = shouldDisableArgRegFromCSR(CallConv) || HasNCSR;
2522 if (ShouldDisableArgRegs || shouldDisableRetRegFromCSR(CallConv)) {
2523 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
2524
2525 // Allocate a new Reg Mask and copy Mask.
2526 RegMask = MF.allocateRegMask();
2527 unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs());
2528 memcpy(RegMask, Mask, sizeof(RegMask[0]) * RegMaskSize);
2529
2530 // Make sure all sub registers of the argument registers are reset
2531 // in the RegMask.
2532 if (ShouldDisableArgRegs) {
2533 for (auto const &RegPair : RegsToPass)
2534 for (MCPhysReg SubReg : TRI->subregs_inclusive(RegPair.first))
2535 RegMask[SubReg / 32] &= ~(1u << (SubReg % 32));
2536 }
2537
2538 // Create the RegMask Operand according to our updated mask.
2539 Ops.push_back(DAG.getRegisterMask(RegMask));
2540 } else {
2541 // Create the RegMask Operand according to the static mask.
2542 Ops.push_back(DAG.getRegisterMask(Mask));
2543 }
2544
2545 if (InGlue.getNode())
2546 Ops.push_back(InGlue);
2547
2548 if (isTailCall) {
2549 // We used to do:
2550 //// If this is the first return lowered for this function, add the regs
2551 //// to the liveout set for the function.
2552 // This isn't right, although it's probably harmless on x86; liveouts
2553 // should be computed from returns not tail calls. Consider a void
2554 // function making a tail call to a function returning int.
2556 SDValue Ret = DAG.getNode(X86ISD::TC_RETURN, dl, MVT::Other, Ops);
2557
2558 if (IsCFICall)
2559 Ret.getNode()->setCFIType(CLI.CFIType->getZExtValue());
2560
2561 DAG.addNoMergeSiteInfo(Ret.getNode(), CLI.NoMerge);
2562 DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
2563 return Ret;
2564 }
2565
2566 // Returns a chain & a glue for retval copy to use.
2567 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
2568 if (IsImpCall) {
2569 Chain = DAG.getNode(X86ISD::IMP_CALL, dl, NodeTys, Ops);
2570 } else if (IsNoTrackIndirectCall) {
2571 Chain = DAG.getNode(X86ISD::NT_CALL, dl, NodeTys, Ops);
2572 } else if (CLI.CB && objcarc::hasAttachedCallOpBundle(CLI.CB)) {
2573 // Calls with a "clang.arc.attachedcall" bundle are special. They should be
2574 // expanded to the call, directly followed by a special marker sequence and
2575 // a call to a ObjC library function. Use the CALL_RVMARKER to do that.
2576 assert(!isTailCall &&
2577 "tail calls cannot be marked with clang.arc.attachedcall");
2578 assert(Is64Bit && "clang.arc.attachedcall is only supported in 64bit mode");
2579
2580 // Add a target global address for the retainRV/claimRV runtime function
2581 // just before the call target.
2583 auto PtrVT = getPointerTy(DAG.getDataLayout());
2584 auto GA = DAG.getTargetGlobalAddress(ARCFn, dl, PtrVT);
2585 Ops.insert(Ops.begin() + 1, GA);
2586 Chain = DAG.getNode(X86ISD::CALL_RVMARKER, dl, NodeTys, Ops);
2587 } else {
2588 Chain = DAG.getNode(X86ISD::CALL, dl, NodeTys, Ops);
2589 }
2590
2591 if (IsCFICall)
2592 Chain.getNode()->setCFIType(CLI.CFIType->getZExtValue());
2593
2594 InGlue = Chain.getValue(1);
2595 DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge);
2596 DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
2597
2598 // Save heapallocsite metadata.
2599 if (CLI.CB)
2600 if (MDNode *HeapAlloc = CLI.CB->getMetadata("heapallocsite"))
2601 DAG.addHeapAllocSite(Chain.getNode(), HeapAlloc);
2602
2603 // Create the CALLSEQ_END node.
2604 unsigned NumBytesForCalleeToPop = 0; // Callee pops nothing.
2605 if (X86::isCalleePop(CallConv, Is64Bit, isVarArg,
2607 NumBytesForCalleeToPop = NumBytes; // Callee pops everything
2608 else if (!canGuaranteeTCO(CallConv) && IsCalleePopSRet)
2609 // If this call passes a struct-return pointer, the callee
2610 // pops that struct pointer.
2611 NumBytesForCalleeToPop = 4;
2612
2613 // Returns a glue for retval copy to use.
2614 if (!IsSibcall) {
2615 Chain = DAG.getCALLSEQ_END(Chain, NumBytesToPop, NumBytesForCalleeToPop,
2616 InGlue, dl);
2617 InGlue = Chain.getValue(1);
2618 }
2619
2620 if (CallingConv::PreserveNone == CallConv)
2621 for (const ISD::OutputArg &Out : Outs) {
2622 if (Out.Flags.isSwiftSelf() || Out.Flags.isSwiftAsync() ||
2623 Out.Flags.isSwiftError()) {
2624 errorUnsupported(DAG, dl,
2625 "Swift attributes can't be used with preserve_none");
2626 break;
2627 }
2628 }
2629
2630 // Handle result values, copying them out of physregs into vregs that we
2631 // return.
2632 return LowerCallResult(Chain, InGlue, CallConv, isVarArg, Ins, dl, DAG,
2633 InVals, RegMask);
2634}
2635
2636//===----------------------------------------------------------------------===//
2637// Fast Calling Convention (tail call) implementation
2638//===----------------------------------------------------------------------===//
2639
2640// Like std call, callee cleans arguments, convention except that ECX is
2641// reserved for storing the tail called function address. Only 2 registers are
2642// free for argument passing (inreg). Tail call optimization is performed
2643// provided:
2644// * tailcallopt is enabled
2645// * caller/callee are fastcc
2646// On X86_64 architecture with GOT-style position independent code only local
2647// (within module) calls are supported at the moment.
2648// To keep the stack aligned according to platform abi the function
2649// GetAlignedArgumentStackSize ensures that argument delta is always multiples
2650// of stack alignment. (Dynamic linkers need this - Darwin's dyld for example)
2651// If a tail called function callee has more arguments than the caller the
2652// caller needs to make sure that there is room to move the RETADDR to. This is
2653// achieved by reserving an area the size of the argument delta right after the
2654// original RETADDR, but before the saved framepointer or the spilled registers
2655// e.g. caller(arg1, arg2) calls callee(arg1, arg2,arg3,arg4)
2656// stack layout:
2657// arg1
2658// arg2
2659// RETADDR
2660// [ new RETADDR
2661// move area ]
2662// (possible EBP)
2663// ESI
2664// EDI
2665// local1 ..
2666
2667/// Make the stack size align e.g 16n + 12 aligned for a 16-byte align
2668/// requirement.
2669unsigned
2670X86TargetLowering::GetAlignedArgumentStackSize(const unsigned StackSize,
2671 SelectionDAG &DAG) const {
2672 const Align StackAlignment = Subtarget.getFrameLowering()->getStackAlign();
2673 const uint64_t SlotSize = Subtarget.getRegisterInfo()->getSlotSize();
2674 assert(StackSize % SlotSize == 0 &&
2675 "StackSize must be a multiple of SlotSize");
2676 return alignTo(StackSize + SlotSize, StackAlignment) - SlotSize;
2677}
2678
2679/// Return true if the given stack call argument is already available in the
2680/// same position (relatively) of the caller's incoming argument stack.
2681static
2684 const X86InstrInfo *TII, const CCValAssign &VA) {
2685 unsigned Bytes = Arg.getValueSizeInBits() / 8;
2686
2687 for (;;) {
2688 // Look through nodes that don't alter the bits of the incoming value.
2689 unsigned Op = Arg.getOpcode();
2690 if (Op == ISD::ZERO_EXTEND || Op == ISD::ANY_EXTEND || Op == ISD::BITCAST ||
2691 Op == ISD::AssertZext) {
2692 Arg = Arg.getOperand(0);
2693 continue;
2694 }
2695 if (Op == ISD::TRUNCATE) {
2696 const SDValue &TruncInput = Arg.getOperand(0);
2697 if (TruncInput.getOpcode() == ISD::AssertZext &&
2698 cast<VTSDNode>(TruncInput.getOperand(1))->getVT() ==
2699 Arg.getValueType()) {
2700 Arg = TruncInput.getOperand(0);
2701 continue;
2702 }
2703 }
2704 break;
2705 }
2706
2707 int FI = INT_MAX;
2708 if (Arg.getOpcode() == ISD::CopyFromReg) {
2709 Register VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg();
2710 if (!VR.isVirtual())
2711 return false;
2712 MachineInstr *Def = MRI->getVRegDef(VR);
2713 if (!Def)
2714 return false;
2715 if (!Flags.isByVal()) {
2716 if (!TII->isLoadFromStackSlot(*Def, FI))
2717 return false;
2718 } else {
2719 unsigned Opcode = Def->getOpcode();
2720 if ((Opcode == X86::LEA32r || Opcode == X86::LEA64r ||
2721 Opcode == X86::LEA64_32r) &&
2722 Def->getOperand(1).isFI()) {
2723 FI = Def->getOperand(1).getIndex();
2724 Bytes = Flags.getByValSize();
2725 } else
2726 return false;
2727 }
2728 } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) {
2729 if (Flags.isByVal())
2730 // ByVal argument is passed in as a pointer but it's now being
2731 // dereferenced. e.g.
2732 // define @foo(%struct.X* %A) {
2733 // tail call @bar(%struct.X* byval %A)
2734 // }
2735 return false;
2736 SDValue Ptr = Ld->getBasePtr();
2737 FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr);
2738 if (!FINode)
2739 return false;
2740 FI = FINode->getIndex();
2741 } else if (Arg.getOpcode() == ISD::FrameIndex && Flags.isByVal()) {
2742 FrameIndexSDNode *FINode = cast<FrameIndexSDNode>(Arg);
2743 FI = FINode->getIndex();
2744 Bytes = Flags.getByValSize();
2745 } else
2746 return false;
2747
2748 assert(FI != INT_MAX);
2749 if (!MFI.isFixedObjectIndex(FI))
2750 return false;
2751
2752 if (Offset != MFI.getObjectOffset(FI))
2753 return false;
2754
2755 // If this is not byval, check that the argument stack object is immutable.
2756 // inalloca and argument copy elision can create mutable argument stack
2757 // objects. Byval objects can be mutated, but a byval call intends to pass the
2758 // mutated memory.
2759 if (!Flags.isByVal() && !MFI.isImmutableObjectIndex(FI))
2760 return false;
2761
2762 if (VA.getLocVT().getFixedSizeInBits() >
2764 // If the argument location is wider than the argument type, check that any
2765 // extension flags match.
2766 if (Flags.isZExt() != MFI.isObjectZExt(FI) ||
2767 Flags.isSExt() != MFI.isObjectSExt(FI)) {
2768 return false;
2769 }
2770 }
2771
2772 return Bytes == MFI.getObjectSize(FI);
2773}
2774
2775static bool
2777 Register CallerSRetReg) {
2778 const auto &Outs = CLI.Outs;
2779 const auto &OutVals = CLI.OutVals;
2780
2781 // We know the caller has a sret pointer argument (CallerSRetReg). Locate the
2782 // operand index within the callee that may have a sret pointer too.
2783 unsigned Pos = 0;
2784 for (unsigned E = Outs.size(); Pos != E; ++Pos)
2785 if (Outs[Pos].Flags.isSRet())
2786 break;
2787 // Bail out if the callee has not any sret argument.
2788 if (Pos == Outs.size())
2789 return false;
2790
2791 // At this point, either the caller is forwarding its sret argument to the
2792 // callee, or the callee is being passed a different sret pointer. We now look
2793 // for a CopyToReg, where the callee sret argument is written into a new vreg
2794 // (which should later be %rax/%eax, if this is returned).
2795 SDValue SRetArgVal = OutVals[Pos];
2796 for (SDNode *User : SRetArgVal->users()) {
2797 if (User->getOpcode() != ISD::CopyToReg)
2798 continue;
2799 Register Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
2800 if (Reg == CallerSRetReg && User->getOperand(2) == SRetArgVal)
2801 return true;
2802 }
2803
2804 return false;
2805}
2806
2807/// Check whether the call is eligible for tail call optimization. Targets
2808/// that want to do tail call optimization should implement this function.
2809/// Note that the x86 backend does not check musttail calls for eligibility! The
2810/// rest of x86 tail call lowering must be prepared to forward arguments of any
2811/// type.
2812bool X86TargetLowering::IsEligibleForTailCallOptimization(
2814 SmallVectorImpl<CCValAssign> &ArgLocs, bool IsCalleePopSRet) const {
2815 SelectionDAG &DAG = CLI.DAG;
2816 const SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
2817 const SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
2819 SDValue Callee = CLI.Callee;
2820 CallingConv::ID CalleeCC = CLI.CallConv;
2821 bool isVarArg = CLI.IsVarArg;
2822
2823 if (!mayTailCallThisCC(CalleeCC))
2824 return false;
2825
2826 // If -tailcallopt is specified, make fastcc functions tail-callable.
2829 const Function &CallerF = MF.getFunction();
2830
2831 // If the function return type is x86_fp80 and the callee return type is not,
2832 // then the FP_EXTEND of the call result is not a nop. It's not safe to
2833 // perform a tailcall optimization here.
2834 if (CallerF.getReturnType()->isX86_FP80Ty() && !CLI.RetTy->isX86_FP80Ty())
2835 return false;
2836
2837 CallingConv::ID CallerCC = CallerF.getCallingConv();
2838 bool CCMatch = CallerCC == CalleeCC;
2839 bool IsCalleeWin64 = Subtarget.isCallingConvWin64(CalleeCC);
2840 bool IsCallerWin64 = Subtarget.isCallingConvWin64(CallerCC);
2841 bool IsGuaranteeTCO = DAG.getTarget().Options.GuaranteedTailCallOpt ||
2842 CalleeCC == CallingConv::Tail || CalleeCC == CallingConv::SwiftTail;
2843
2844 // Win64 functions have extra shadow space for argument homing. Don't do the
2845 // sibcall if the caller and callee have mismatched expectations for this
2846 // space.
2847 if (IsCalleeWin64 != IsCallerWin64)
2848 return false;
2849
2850 if (IsGuaranteeTCO) {
2851 if (canGuaranteeTCO(CalleeCC) && CCMatch)
2852 return true;
2853 return false;
2854 }
2855
2856 // Look for obvious safe cases to perform tail call optimization that do not
2857 // require ABI changes. This is what gcc calls sibcall.
2858
2859 // Can't do sibcall if stack needs to be dynamically re-aligned. PEI needs to
2860 // emit a special epilogue.
2861 const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
2862 if (RegInfo->hasStackRealignment(MF))
2863 return false;
2864
2865 // Avoid sibcall optimization if we are an sret return function and the callee
2866 // is incompatible, unless such premises are proven wrong. See comment in
2867 // LowerReturn about why hasStructRetAttr is insufficient.
2868 if (Register SRetReg = FuncInfo->getSRetReturnReg()) {
2869 // For a compatible tail call the callee must return our sret pointer. So it
2870 // needs to be (a) an sret function itself and (b) we pass our sret as its
2871 // sret. Condition #b is harder to determine.
2872 if (!mayBeSRetTailCallCompatible(CLI, SRetReg))
2873 return false;
2874 } else if (IsCalleePopSRet)
2875 // The callee pops an sret, so we cannot tail-call, as our caller doesn't
2876 // expect that.
2877 return false;
2878
2879 // Do not sibcall optimize vararg calls unless all arguments are passed via
2880 // registers.
2881 LLVMContext &C = *DAG.getContext();
2882 if (isVarArg && !Outs.empty()) {
2883 // Optimizing for varargs on Win64 is unlikely to be safe without
2884 // additional testing.
2885 if (IsCalleeWin64 || IsCallerWin64)
2886 return false;
2887
2888 for (const auto &VA : ArgLocs)
2889 if (!VA.isRegLoc())
2890 return false;
2891 }
2892
2893 // If the call result is in ST0 / ST1, it needs to be popped off the x87
2894 // stack. Therefore, if it's not used by the call it is not safe to optimize
2895 // this into a sibcall.
2896 bool Unused = false;
2897 for (const auto &In : Ins) {
2898 if (!In.Used) {
2899 Unused = true;
2900 break;
2901 }
2902 }
2903 if (Unused) {
2905 CCState RVCCInfo(CalleeCC, false, MF, RVLocs, C);
2906 RVCCInfo.AnalyzeCallResult(Ins, RetCC_X86);
2907 for (const auto &VA : RVLocs) {
2908 if (VA.getLocReg() == X86::FP0 || VA.getLocReg() == X86::FP1)
2909 return false;
2910 }
2911 }
2912
2913 // Check that the call results are passed in the same way.
2914 if (!CCState::resultsCompatible(CalleeCC, CallerCC, MF, C, Ins,
2916 return false;
2917 // The callee has to preserve all registers the caller needs to preserve.
2918 const X86RegisterInfo *TRI = Subtarget.getRegisterInfo();
2919 const uint32_t *CallerPreserved = TRI->getCallPreservedMask(MF, CallerCC);
2920 if (!CCMatch) {
2921 const uint32_t *CalleePreserved = TRI->getCallPreservedMask(MF, CalleeCC);
2922 if (!TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
2923 return false;
2924 }
2925
2926 // The stack frame of the caller cannot be replaced by the tail-callee one's
2927 // if the function is required to preserve all the registers. Conservatively
2928 // prevent tail optimization even if hypothetically all the registers are used
2929 // for passing formal parameters or returning values.
2930 if (CallerF.hasFnAttribute("no_caller_saved_registers"))
2931 return false;
2932
2933 unsigned StackArgsSize = CCInfo.getStackSize();
2934
2935 // If the callee takes no arguments then go on to check the results of the
2936 // call.
2937 if (!Outs.empty()) {
2938 if (StackArgsSize > 0) {
2939 // Check if the arguments are already laid out in the right way as
2940 // the caller's fixed stack objects.
2941 MachineFrameInfo &MFI = MF.getFrameInfo();
2942 const MachineRegisterInfo *MRI = &MF.getRegInfo();
2943 const X86InstrInfo *TII = Subtarget.getInstrInfo();
2944 for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
2945 const CCValAssign &VA = ArgLocs[I];
2946 SDValue Arg = OutVals[I];
2947 ISD::ArgFlagsTy Flags = Outs[I].Flags;
2949 return false;
2950 if (!VA.isRegLoc()) {
2951 if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, MFI, MRI,
2952 TII, VA))
2953 return false;
2954 }
2955 }
2956 }
2957
2958 bool PositionIndependent = isPositionIndependent();
2959 // If the tailcall address may be in a register, then make sure it's
2960 // possible to register allocate for it. In 32-bit, the call address can
2961 // only target EAX, EDX, or ECX since the tail call must be scheduled after
2962 // callee-saved registers are restored. These happen to be the same
2963 // registers used to pass 'inreg' arguments so watch out for those.
2964 if (!Subtarget.is64Bit() && ((!isa<GlobalAddressSDNode>(Callee) &&
2965 !isa<ExternalSymbolSDNode>(Callee)) ||
2966 PositionIndependent)) {
2967 unsigned NumInRegs = 0;
2968 // In PIC we need an extra register to formulate the address computation
2969 // for the callee.
2970 unsigned MaxInRegs = PositionIndependent ? 2 : 3;
2971
2972 for (const auto &VA : ArgLocs) {
2973 if (!VA.isRegLoc())
2974 continue;
2975 Register Reg = VA.getLocReg();
2976 switch (Reg) {
2977 default: break;
2978 case X86::EAX: case X86::EDX: case X86::ECX:
2979 if (++NumInRegs == MaxInRegs)
2980 return false;
2981 break;
2982 }
2983 }
2984 }
2985
2986 const MachineRegisterInfo &MRI = MF.getRegInfo();
2987 if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
2988 return false;
2989 }
2990
2991 bool CalleeWillPop =
2992 X86::isCalleePop(CalleeCC, Subtarget.is64Bit(), isVarArg,
2994
2995 if (unsigned BytesToPop = FuncInfo->getBytesToPopOnReturn()) {
2996 // If we have bytes to pop, the callee must pop them.
2997 bool CalleePopMatches = CalleeWillPop && BytesToPop == StackArgsSize;
2998 if (!CalleePopMatches)
2999 return false;
3000 } else if (CalleeWillPop && StackArgsSize > 0) {
3001 // If we don't have bytes to pop, make sure the callee doesn't pop any.
3002 return false;
3003 }
3004
3005 return true;
3006}
3007
3008/// Determines whether the callee is required to pop its own arguments.
3009/// Callee pop is necessary to support tail calls.
3011 bool is64Bit, bool IsVarArg, bool GuaranteeTCO) {
3012 // If GuaranteeTCO is true, we force some calls to be callee pop so that we
3013 // can guarantee TCO.
3014 if (!IsVarArg && shouldGuaranteeTCO(CallingConv, GuaranteeTCO))
3015 return true;
3016
3017 switch (CallingConv) {
3018 default:
3019 return false;
3024 return !is64Bit;
3025 }
3026}
unsigned SubReg
unsigned const MachineRegisterInfo * MRI
static bool canGuaranteeTCO(CallingConv::ID CC, bool GuaranteeTailCalls)
Return true if the calling convention is one that we can guarantee TCO for.
static bool mayTailCallThisCC(CallingConv::ID CC)
Return true if we might ever do TCO for calls with this calling convention.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
return RetTy
uint64_t Addr
const HexagonInstrInfo * TII
static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, const SDLoc &dl)
CreateCopyOfByValArgument - Make a copy of an aggregate at address specified by "Src" to address "Dst...
Module.h This file contains the declarations for the Module class.
static LVOptions Options
Definition: LVOptions.cpp:25
const MCPhysReg ArgGPRs[]
static bool shouldGuaranteeTCO(CallingConv::ID CC, bool GuaranteedTailCallOpt)
Return true if the function is being made into a tailcall target by changing its ABI.
static bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, MachineFrameInfo &MFI, const MachineRegisterInfo *MRI, const M68kInstrInfo *TII, const CCValAssign &VA)
Return true if the given stack call argument is already available in the same position (relatively) o...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
Register const TargetRegisterInfo * TRI
This file defines ARC utility functions which are used by various parts of the compiler.
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
static void getMaxByValAlign(Type *Ty, Align &MaxAlign, Align MaxMaxAlign)
getMaxByValAlign - Helper for getByValTypeAlignment to determine the desired ByVal argument alignment...
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:480
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static bool is64Bit(const char *name)
static SDValue lowerMasksToReg(const SDValue &ValArg, const EVT &ValLoc, const SDLoc &DL, SelectionDAG &DAG)
Lowers masks values (v*i1) to the local register values.
static void Passv64i1ArgInRegs(const SDLoc &DL, SelectionDAG &DAG, SDValue &Arg, SmallVectorImpl< std::pair< Register, SDValue > > &RegsToPass, CCValAssign &VA, CCValAssign &NextVA, const X86Subtarget &Subtarget)
Breaks v64i1 value into two registers and adds the new node to the DAG.
static SDValue getv64i1Argument(CCValAssign &VA, CCValAssign &NextVA, SDValue &Root, SelectionDAG &DAG, const SDLoc &DL, const X86Subtarget &Subtarget, SDValue *InGlue=nullptr)
Reads two 32 bit registers and creates a 64 bit mask value.
static ArrayRef< MCPhysReg > get64BitArgumentXMMs(MachineFunction &MF, CallingConv::ID CallConv, const X86Subtarget &Subtarget)
static bool isSortedByValueNo(ArrayRef< CCValAssign > ArgLocs)
static ArrayRef< MCPhysReg > get64BitArgumentGPRs(CallingConv::ID CallConv, const X86Subtarget &Subtarget)
static SDValue getPopFromX87Reg(SelectionDAG &DAG, SDValue Chain, const SDLoc &dl, Register Reg, EVT VT, SDValue Glue)
static bool mayBeSRetTailCallCompatible(const TargetLowering::CallLoweringInfo &CLI, Register CallerSRetReg)
static std::pair< MVT, unsigned > handleMaskRegisterForCallingConv(unsigned NumElts, CallingConv::ID CC, const X86Subtarget &Subtarget)
static bool shouldDisableRetRegFromCSR(CallingConv::ID CC)
Returns true if a CC can dynamically exclude a register from the list of callee-saved-registers (Targ...
static void errorUnsupported(SelectionDAG &DAG, const SDLoc &dl, const char *Msg)
Call this when the user attempts to do something unsupported, like returning a double without SSE2 en...
static SDValue EmitTailCallStoreRetAddr(SelectionDAG &DAG, MachineFunction &MF, SDValue Chain, SDValue RetAddrFrIdx, EVT PtrVT, unsigned SlotSize, int FPDiff, const SDLoc &dl)
Emit a store of the return address if tail call optimization is performed and it is required (FPDiff!...
static bool hasCalleePopSRet(const SmallVectorImpl< T > &Args, const X86Subtarget &Subtarget)
Determines whether Args, either a set of outgoing arguments to a call, or a set of incoming args of a...
static bool shouldDisableArgRegFromCSR(CallingConv::ID CC)
Returns true if a CC can dynamically exclude a register from the list of callee-saved-registers (Targ...
static bool hasStackGuardSlotTLS(const Triple &TargetTriple)
static SDValue lowerRegToMasks(const SDValue &ValArg, const EVT &ValVT, const EVT &ValLoc, const SDLoc &DL, SelectionDAG &DAG)
The function will lower a register of various sizes (8/16/32/64) to a mask value of the expected size...
static Constant * SegmentOffset(IRBuilderBase &IRB, int Offset, unsigned AddressSpace)
static bool isBitAligned(Align Alignment, uint64_t SizeInBits)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:191
LLVM_ABI bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:213
CCState - This class holds information needed while lowering arguments and return values.
static LLVM_ABI bool resultsCompatible(CallingConv::ID CalleeCC, CallingConv::ID CallerCC, MachineFunction &MF, LLVMContext &C, const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn CalleeFn, CCAssignFn CallerFn)
Returns true if the results of the two calling conventions are compatible.
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
CCValAssign - Represent assignment of one arg/retval to a location.
bool isRegLoc() const
void convertToReg(MCRegister Reg)
Register getLocReg() const
LocInfo getLocInfo() const
bool needsCustom() const
bool isMemLoc() const
bool isExtInLoc() const
int64_t getLocMemOffset() const
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1406
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
This class represents a function call, abstracting a target machine's calling convention.
bool isTailCall() const
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2314
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:163
This is an important base class in LLVM.
Definition: Constant.h:43
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:504
Diagnostic information for unsupported feature in backend.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:170
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:270
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:903
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1036
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:727
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:663
void setDSOLocal(bool Local)
Definition: GlobalValue.h:305
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:53
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:114
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:201
LLVMContext & getContext() const
Definition: IRBuilder.h:203
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Definition: IRBuilder.h:605
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:428
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This class is used to represent ISD::LOAD nodes.
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.h:214
Metadata node.
Definition: Metadata.h:1077
Machine Value Type.
@ INVALID_SIMPLE_VALUE_TYPE
SimpleValueType SimpleTy
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool is512BitVector() const
Return true if this is a 512-bit vector type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
MVT getVectorElementType() const
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void setObjectZExt(int ObjectIdx, bool IsZExt)
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
void setObjectSExt(int ObjectIdx, bool IsSExt)
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
void setHasTailCall(bool V=true)
bool isObjectZExt(int ObjectIdx) const
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isObjectSExt(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
MCSymbol * getPICBaseSymbol() const
getPICBaseSymbol - Return a function-local symbol to represent the PIC base.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
uint32_t * allocateRegMask()
Allocate and initialize a register mask with NumRegister bits.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
Definition: MachineInstr.h:72
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
@ EK_LabelDifference64
EK_LabelDifference64 - Each entry is the address of the block minus the address of the jump table.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOLoad
The memory access reads data.
@ MONonTemporal
The memory access is non-temporal.
@ MOStore
The memory access writes data.
static unsigned getRegMaskSize(unsigned NumRegs)
Returns number of elements needed for a regmask array.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI void disableCalleeSavedRegister(MCRegister Reg)
Disables the register from the list of CSRs.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:720
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:74
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
const DebugLoc & getDebugLoc() const
Represents one node in the SelectionDAG.
void setCFIType(uint32_t Type)
iterator_range< user_iterator > users()
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:229
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:758
LLVM_ABI SDValue getStackArgumentTokenFactor(SDValue Chain)
Compute a TokenFactor to force all the incoming stack arguments to be loaded from the stack.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
Definition: SelectionDAG.h:813
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=LocationSize::precise(0), const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
LLVM_ABI SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), BatchAAResults *BatchAA=nullptr)
void addNoMergeSiteInfo(const SDNode *Node, bool NoMerge)
Set NoMergeSiteInfo to be associated with Node if NoMerge is true.
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
LLVM_ABI SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
Definition: SelectionDAG.h:839
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:498
void addHeapAllocSite(const SDNode *Node, MDNode *MD)
Set HeapAllocSite to be associated with Node.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:719
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
const TargetMachine & getTarget() const
Definition: SelectionDAG.h:499
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:707
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:493
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask)
void addCallSiteInfo(const SDNode *Node, CallSiteInfo &&CallInfo)
Set CallSiteInfo to be associated with Node.
LLVMContext * getContext() const
Definition: SelectionDAG.h:511
LLVM_ABI SDValue CreateStackTemporary(TypeSize Bytes, Align Alignment)
Create a stack temporary based on the size in bytes and the alignment.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:581
LLVM_ABI std::pair< SDValue, SDValue > SplitScalar(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the scalar node with EXTRACT_ELEMENT using the provided VTs and return the low/high part.
LLVM_ABI SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:806
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
Class to represent struct types.
Definition: DerivedTypes.h:218
Information about stack frame layout on the target.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual Value * getSafeStackPointerLocation(IRBuilderBase &IRB) const
Returns the target-specific address of the unsafe stack pointer.
const TargetMachine & getTargetMachine() const
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
virtual unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
virtual Function * getSSPStackGuardCheck(const Module &M) const
If the target has a standard stack protection check function that performs validation and error handl...
virtual Value * getIRStackGuard(IRBuilderBase &IRB) const
If the target has a standard location for the stack protector guard, returns the address of that loca...
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
virtual std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const
Return the largest legal super-reg register class of the register class for the specified type and it...
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
std::vector< ArgListEntry > ArgListTy
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual void insertSSPDeclarations(Module &M) const
Inserts necessary declarations for SSP (stack protection) purpose.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual const MCExpr * getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI, MCContext &Ctx) const
This returns the relocation base for the given PIC jumptable, the same as getPICJumpTableRelocBase,...
bool parametersInCSRMatch(const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask, const SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< SDValue > &OutVals) const
Check whether parameters to a call that are passed in callee saved registers are the same as from the...
bool isPositionIndependent() const
virtual unsigned getJumpTableEncoding() const
Return the entry encoding for a jump table in the current function.
TargetOptions Options
CodeModel::Model getCodeModel() const
Returns the code model.
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
unsigned EmitCallGraphSection
Emit section containing call graph metadata.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
bool isAndroidVersionLT(unsigned Major) const
Definition: Triple.h:818
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:816
bool isOSMSVCRT() const
Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
Definition: Triple.h:719
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or bridgeOS).
Definition: Triple.h:608
bool isOSGlibc() const
Tests whether the OS uses glibc.
Definition: Triple.h:750
bool isOSFuchsia() const
Definition: Triple.h:639
bool isWindowsMSVCEnvironment() const
Checks if the environment could be MSVC.
Definition: Triple.h:686
bool isWindowsItaniumEnvironment() const
Definition: Triple.h:701
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition: Type.h:159
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:162
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:240
Value * getOperand(unsigned i) const
Definition: User.h:232
LLVM Value Representation.
Definition: Value.h:75
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
void setBytesToPopOnReturn(unsigned bytes)
void setVarArgsGPOffset(unsigned Offset)
void setArgumentStackSize(unsigned size)
SmallVectorImpl< ForwardedRegister > & getForwardedMustTailRegParms()
void setVarArgsFPOffset(unsigned Offset)
unsigned getSlotSize() const
bool hasSSE1() const
Definition: X86Subtarget.h:189
bool useLight256BitInstructions() const
Definition: X86Subtarget.h:254
bool isPICStyleGOT() const
Definition: X86Subtarget.h:333
bool isTargetMCU() const
Definition: X86Subtarget.h:298
bool isTargetWindowsMSVC() const
Definition: X86Subtarget.h:301
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
Definition: X86Subtarget.h:173
bool isTargetDarwin() const
Definition: X86Subtarget.h:284
const Triple & getTargetTriple() const
Definition: X86Subtarget.h:282
const X86InstrInfo * getInstrInfo() const override
Definition: X86Subtarget.h:122
bool useAVX512Regs() const
Definition: X86Subtarget.h:249
bool isTargetCOFF() const
Definition: X86Subtarget.h:291
bool isCallingConvWin64(CallingConv::ID CC) const
Definition: X86Subtarget.h:342
bool hasAVX512() const
Definition: X86Subtarget.h:197
bool hasSSE41() const
Definition: X86Subtarget.h:193
bool hasSSE2() const
Definition: X86Subtarget.h:190
bool isTargetFuchsia() const
Definition: X86Subtarget.h:299
bool isPICStyleRIPRel() const
Definition: X86Subtarget.h:334
bool isTargetCygMing() const
Definition: X86Subtarget.h:321
const X86RegisterInfo * getRegisterInfo() const override
Definition: X86Subtarget.h:132
bool hasAVX() const
Definition: X86Subtarget.h:195
unsigned getPreferVectorWidth() const
Definition: X86Subtarget.h:221
bool isTargetAndroid() const
Definition: X86Subtarget.h:297
const X86FrameLowering * getFrameLowering() const override
Definition: X86Subtarget.h:124
bool hasAVX2() const
Definition: X86Subtarget.h:196
std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const override
Return the largest legal super-reg register class of the register class for the specified type and it...
SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG) const override
Returns relocation base for the given PIC jumptable.
unsigned getJumpTableEncoding() const override
Return the entry encoding for a jump table in the current function.
bool isMemoryAccessFast(EVT VT, Align Alignment) const
bool useSoftFloat() const override
const MCExpr * getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI, MCContext &Ctx) const override
This returns the relocation base for the given PIC jumptable, the same as getPICJumpTableRelocBase,...
bool isSafeMemOpType(MVT VT) const override
Returns true if it's safe to use load / store of the specified type to expand memcpy / memset inline.
bool functionArgumentNeedsConsecutiveRegisters(Type *Ty, CallingConv::ID CallConv, bool isVarArg, const DataLayout &DL) const override
For some targets, an LLVM struct type must be broken down into multiple simple types,...
Value * getIRStackGuard(IRBuilderBase &IRB) const override
If the target has a standard location for the stack protector cookie, returns the address of that loc...
Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const override
Return the desired alignment for ByVal aggregate function arguments in the caller parameter area.
Function * getSSPStackGuardCheck(const Module &M) const override
If the target has a standard stack protection check function that performs validation and error handl...
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const override
Returns true if the target allows unaligned memory accesses of the specified type.
EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op, const AttributeList &FuncAttributes) const override
It returns EVT::Other if the type should be determined using generic target-independent logic.
unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const override
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
void markLibCallAttributes(MachineFunction *MF, unsigned CC, ArgListTy &Args) const override
Value * getSafeStackPointerLocation(IRBuilderBase &IRB) const override
Return true if the target stores SafeStack pointer at a fixed offset in some non-standard address spa...
bool isScalarFPTypeInSSEReg(EVT VT) const
Return true if the specified scalar FP type is computed in an SSE register, not on the X87 floating p...
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain targets require unusual breakdowns of certain types.
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const override
This function returns true if the memory access is aligned or if the target allows this specific unal...
SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the value type to use for ISD::SETCC.
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const override
For types supported by the target, this is an identity function.
void insertSSPDeclarations(Module &M) const override
Inserts necessary declarations for SSP (stack protection) purpose.
const MCExpr * LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, const MachineBasicBlock *MBB, unsigned uid, MCContext &Ctx) const override
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:203
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
Definition: BitmaskEnum.h:126
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
Definition: CallingConv.h:151
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
Definition: CallingConv.h:53
@ Swift
Calling convention for Swift.
Definition: CallingConv.h:69
@ PreserveMost
Used for runtime calls that preserves most registers.
Definition: CallingConv.h:63
@ X86_INTR
x86 hardware interrupt context.
Definition: CallingConv.h:173
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition: CallingConv.h:50
@ X86_ThisCall
Similar to X86_StdCall.
Definition: CallingConv.h:122
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
Definition: CallingConv.h:66
@ X86_StdCall
stdcall is mostly used by the Win32 API.
Definition: CallingConv.h:99
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
Definition: CallingConv.h:163
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
Definition: CallingConv.h:147
@ PreserveNone
Used for runtime calls that preserves none general registers.
Definition: CallingConv.h:90
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition: CallingConv.h:76
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
Definition: CallingConv.h:159
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition: CallingConv.h:87
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
Definition: CallingConv.h:203
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ X86_FastCall
'fast' analog of X86_StdCall.
Definition: CallingConv.h:103
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:41
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:259
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:835
@ GlobalAddress
Definition: ISDOpcodes.h:88
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:571
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:975
@ FrameIndex
Definition: ISDOpcodes.h:90
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:826
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
Definition: ISDOpcodes.h:656
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition: ISDOpcodes.h:225
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:563
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition: ISDOpcodes.h:219
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:832
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:960
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:53
@ ExternalSymbol
Definition: ISDOpcodes.h:93
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:941
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:838
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:62
@ AssertZext
Definition: ISDOpcodes.h:63
@ FS
Definition: X86.h:214
@ GS
Definition: X86.h:213
Reg
All possible values of the reg field in the ModR/M byte.
@ RET_GLUE
Return with a glue operand.
@ IRET
Return from interrupt. Operand 0 is the number of bytes to pop.
@ CALL
These operations represent an abstract X86 call instruction, which includes a bunch of information.
@ GlobalBaseReg
On Darwin, this node represents the result of the popl at function entry, used for PIC code.
@ TC_RETURN
Tail call return.
@ NT_CALL
Same as call except it adds the NoTrack prefix.
@ MOVDQ2Q
Copies a 64-bit value from the low word of an XMM vector to an MMX vector.
@ POP_FROM_X87_REG
The same as ISD::CopyFromReg except that this node makes it explicit that it may lower to an x87 FPU ...
bool isExtendedSwiftAsyncFrameSupported(const X86Subtarget &Subtarget, const MachineFunction &MF)
True if the target supports the extended frame for async Swift functions.
bool isCalleePop(CallingConv::ID CallingConv, bool is64Bit, bool IsVarArg, bool GuaranteeTCO)
Determines whether the callee is required to pop its own arguments.
std::optional< Function * > getAttachedARCFunction(const CallBase *CB)
This function returns operand bundle clang_arc_attachedcall's argument, which is the address of the A...
Definition: ObjCARCUtil.h:43
bool hasAttachedCallOpBundle(const CallBase *CB)
Definition: ObjCARCUtil.h:29
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2155
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:288
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1939
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
bool CC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
bool RetCC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
Extended Value Type.
Definition: ValueTypes.h:35
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:94
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition: ValueTypes.h:390
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition: ValueTypes.h:74
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition: ValueTypes.h:295
ElementCount getVectorElementCount() const
Definition: ValueTypes.h:345
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
bool is128BitVector() const
Return true if this is a 128-bit vector type.
Definition: ValueTypes.h:207
bool is512BitVector() const
Return true if this is a 512-bit vector type.
Definition: ValueTypes.h:217
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:168
bool is256BitVector() const
Return true if this is a 256-bit vector type.
Definition: ValueTypes.h:212
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:323
EVT changeVectorElementType(EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
Definition: ValueTypes.h:102
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:331
Describes a register that needs to be forwarded from the prologue to a musttail call.
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
SmallVector< ArgRegPair, 1 > ArgRegPairs
Vector of call argument and its forwarding register.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs
SmallVector< SDValue, 32 > OutVals
Type * RetTy
Same as OrigRetTy, or partially legalized for soft float libcalls.