LLVM 22.0.0git
CallLowering.cpp
Go to the documentation of this file.
1//===-- lib/CodeGen/GlobalISel/CallLowering.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 some simple delegations needed for call lowering.
11///
12//===----------------------------------------------------------------------===//
13
23#include "llvm/IR/DataLayout.h"
24#include "llvm/IR/LLVMContext.h"
25#include "llvm/IR/Module.h"
27
28#define DEBUG_TYPE "call-lowering"
29
30using namespace llvm;
31
32void CallLowering::anchor() {}
33
34/// Helper function which updates \p Flags when \p AttrFn returns true.
35static void
37 const std::function<bool(Attribute::AttrKind)> &AttrFn) {
38 // TODO: There are missing flags. Add them here.
39 if (AttrFn(Attribute::SExt))
40 Flags.setSExt();
41 if (AttrFn(Attribute::ZExt))
42 Flags.setZExt();
43 if (AttrFn(Attribute::InReg))
44 Flags.setInReg();
45 if (AttrFn(Attribute::StructRet))
46 Flags.setSRet();
47 if (AttrFn(Attribute::Nest))
48 Flags.setNest();
49 if (AttrFn(Attribute::ByVal))
50 Flags.setByVal();
51 if (AttrFn(Attribute::ByRef))
52 Flags.setByRef();
53 if (AttrFn(Attribute::Preallocated))
54 Flags.setPreallocated();
55 if (AttrFn(Attribute::InAlloca))
56 Flags.setInAlloca();
57 if (AttrFn(Attribute::Returned))
58 Flags.setReturned();
59 if (AttrFn(Attribute::SwiftSelf))
60 Flags.setSwiftSelf();
61 if (AttrFn(Attribute::SwiftAsync))
62 Flags.setSwiftAsync();
63 if (AttrFn(Attribute::SwiftError))
64 Flags.setSwiftError();
65}
66
68 unsigned ArgIdx) const {
69 ISD::ArgFlagsTy Flags;
70 addFlagsUsingAttrFn(Flags, [&Call, &ArgIdx](Attribute::AttrKind Attr) {
71 return Call.paramHasAttr(ArgIdx, Attr);
72 });
73 return Flags;
74}
75
78 ISD::ArgFlagsTy Flags;
80 return Call.hasRetAttr(Attr);
81 });
82 return Flags;
83}
84
86 const AttributeList &Attrs,
87 unsigned OpIdx) const {
88 addFlagsUsingAttrFn(Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) {
89 return Attrs.hasAttributeAtIndex(OpIdx, Attr);
90 });
91}
92
94 ArrayRef<Register> ResRegs,
96 Register SwiftErrorVReg,
97 std::optional<PtrAuthInfo> PAI,
98 Register ConvergenceCtrlToken,
99 std::function<Register()> GetCalleeReg) const {
100 CallLoweringInfo Info;
101 const DataLayout &DL = MIRBuilder.getDataLayout();
102 MachineFunction &MF = MIRBuilder.getMF();
104 bool CanBeTailCalled = CB.isTailCall() &&
106 (MF.getFunction()
107 .getFnAttribute("disable-tail-calls")
108 .getValueAsString() != "true");
109
110 CallingConv::ID CallConv = CB.getCallingConv();
111 Type *RetTy = CB.getType();
112 bool IsVarArg = CB.getFunctionType()->isVarArg();
113
115 getReturnInfo(CallConv, RetTy, CB.getAttributes(), SplitArgs, DL);
116 Info.CanLowerReturn = canLowerReturn(MF, CallConv, SplitArgs, IsVarArg);
117
118 Info.IsConvergent = CB.isConvergent();
119
120 if (!Info.CanLowerReturn) {
121 // Callee requires sret demotion.
122 insertSRetOutgoingArgument(MIRBuilder, CB, Info);
123
124 // The sret demotion isn't compatible with tail-calls, since the sret
125 // argument points into the caller's stack frame.
126 CanBeTailCalled = false;
127 }
128
129 // First step is to marshall all the function's parameters into the correct
130 // physregs and memory locations. Gather the sequence of argument types that
131 // we'll pass to the assigner function.
132 unsigned i = 0;
133 unsigned NumFixedArgs = CB.getFunctionType()->getNumParams();
134 for (const auto &Arg : CB.args()) {
135 ArgInfo OrigArg{ArgRegs[i], *Arg.get(), i, getAttributesForArgIdx(CB, i)};
136 setArgFlags(OrigArg, i + AttributeList::FirstArgIndex, DL, CB);
137 if (i >= NumFixedArgs)
138 OrigArg.Flags[0].setVarArg();
139
140 // If we have an explicit sret argument that is an Instruction, (i.e., it
141 // might point to function-local memory), we can't meaningfully tail-call.
142 if (OrigArg.Flags[0].isSRet() && isa<Instruction>(&Arg))
143 CanBeTailCalled = false;
144
145 Info.OrigArgs.push_back(OrigArg);
146 ++i;
147 }
148
149 // Try looking through a bitcast from one function type to another.
150 // Commonly happens with calls to objc_msgSend().
151 const Value *CalleeV = CB.getCalledOperand()->stripPointerCasts();
152
153 // If IRTranslator chose to drop the ptrauth info, we can turn this into
154 // a direct call.
156 CalleeV = cast<ConstantPtrAuth>(CalleeV)->getPointer();
157 assert(isa<Function>(CalleeV));
158 }
159
160 if (const Function *F = dyn_cast<Function>(CalleeV)) {
161 if (F->hasFnAttribute(Attribute::NonLazyBind)) {
162 LLT Ty = getLLTForType(*F->getType(), DL);
163 Register Reg = MIRBuilder.buildGlobalValue(Ty, F).getReg(0);
164 Info.Callee = MachineOperand::CreateReg(Reg, false);
165 } else {
166 Info.Callee = MachineOperand::CreateGA(F, 0);
167 }
168 } else if (isa<GlobalIFunc>(CalleeV) || isa<GlobalAlias>(CalleeV)) {
169 // IR IFuncs and Aliases can't be forward declared (only defined), so the
170 // callee must be in the same TU and therefore we can direct-call it without
171 // worrying about it being out of range.
172 Info.Callee = MachineOperand::CreateGA(cast<GlobalValue>(CalleeV), 0);
173 } else
174 Info.Callee = MachineOperand::CreateReg(GetCalleeReg(), false);
175
176 Register ReturnHintAlignReg;
177 Align ReturnHintAlign;
178
179 Info.OrigRet = ArgInfo{ResRegs, RetTy, 0, getAttributesForReturn(CB)};
180
181 if (!Info.OrigRet.Ty->isVoidTy()) {
182 setArgFlags(Info.OrigRet, AttributeList::ReturnIndex, DL, CB);
183
184 if (MaybeAlign Alignment = CB.getRetAlign()) {
185 if (*Alignment > Align(1)) {
186 ReturnHintAlignReg = MRI.cloneVirtualRegister(ResRegs[0]);
187 Info.OrigRet.Regs[0] = ReturnHintAlignReg;
188 ReturnHintAlign = *Alignment;
189 }
190 }
191 }
192
193 auto Bundle = CB.getOperandBundle(LLVMContext::OB_kcfi);
194 if (Bundle && CB.isIndirectCall()) {
195 Info.CFIType = cast<ConstantInt>(Bundle->Inputs[0]);
196 assert(Info.CFIType->getType()->isIntegerTy(32) && "Invalid CFI type");
197 }
198
199 Info.CB = &CB;
200 Info.KnownCallees = CB.getMetadata(LLVMContext::MD_callees);
201 Info.CallConv = CallConv;
202 Info.SwiftErrorVReg = SwiftErrorVReg;
203 Info.PAI = PAI;
204 Info.ConvergenceCtrlToken = ConvergenceCtrlToken;
205 Info.IsMustTailCall = CB.isMustTailCall();
206 Info.IsTailCall = CanBeTailCalled;
207 Info.IsVarArg = IsVarArg;
208 if (!lowerCall(MIRBuilder, Info))
209 return false;
210
211 if (ReturnHintAlignReg && !Info.LoweredTailCall) {
212 MIRBuilder.buildAssertAlign(ResRegs[0], ReturnHintAlignReg,
213 ReturnHintAlign);
214 }
215
216 return true;
217}
218
219template <typename FuncInfoTy>
221 const DataLayout &DL,
222 const FuncInfoTy &FuncInfo) const {
223 auto &Flags = Arg.Flags[0];
224 const AttributeList &Attrs = FuncInfo.getAttributes();
225 addArgFlagsFromAttributes(Flags, Attrs, OpIdx);
226
228 if (PtrTy) {
229 Flags.setPointer();
230 Flags.setPointerAddrSpace(PtrTy->getPointerAddressSpace());
231 }
232
233 Align MemAlign = DL.getABITypeAlign(Arg.Ty);
234 if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated() ||
235 Flags.isByRef()) {
236 assert(OpIdx >= AttributeList::FirstArgIndex);
237 unsigned ParamIdx = OpIdx - AttributeList::FirstArgIndex;
238
239 Type *ElementTy = FuncInfo.getParamByValType(ParamIdx);
240 if (!ElementTy)
241 ElementTy = FuncInfo.getParamByRefType(ParamIdx);
242 if (!ElementTy)
243 ElementTy = FuncInfo.getParamInAllocaType(ParamIdx);
244 if (!ElementTy)
245 ElementTy = FuncInfo.getParamPreallocatedType(ParamIdx);
246
247 assert(ElementTy && "Must have byval, inalloca or preallocated type");
248
249 uint64_t MemSize = DL.getTypeAllocSize(ElementTy);
250 if (Flags.isByRef())
251 Flags.setByRefSize(MemSize);
252 else
253 Flags.setByValSize(MemSize);
254
255 // For ByVal, alignment should be passed from FE. BE will guess if
256 // this info is not there but there are cases it cannot get right.
257 if (auto ParamAlign = FuncInfo.getParamStackAlign(ParamIdx))
258 MemAlign = *ParamAlign;
259 else if ((ParamAlign = FuncInfo.getParamAlign(ParamIdx)))
260 MemAlign = *ParamAlign;
261 else
262 MemAlign = getTLI()->getByValTypeAlignment(ElementTy, DL);
263 } else if (OpIdx >= AttributeList::FirstArgIndex) {
264 if (auto ParamAlign =
265 FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex))
266 MemAlign = *ParamAlign;
267 }
268 Flags.setMemAlign(MemAlign);
269 Flags.setOrigAlign(DL.getABITypeAlign(Arg.Ty));
270
271 // Don't try to use the returned attribute if the argument is marked as
272 // swiftself, since it won't be passed in x0.
273 if (Flags.isSwiftSelf())
274 Flags.setReturned(false);
275}
276
277template void
279 const DataLayout &DL,
280 const Function &FuncInfo) const;
281
282template void
284 const DataLayout &DL,
285 const CallBase &FuncInfo) const;
286
288 SmallVectorImpl<ArgInfo> &SplitArgs,
289 const DataLayout &DL,
290 CallingConv::ID CallConv,
291 SmallVectorImpl<uint64_t> *Offsets) const {
292 LLVMContext &Ctx = OrigArg.Ty->getContext();
293
294 SmallVector<EVT, 4> SplitVTs;
295 ComputeValueVTs(*TLI, DL, OrigArg.Ty, SplitVTs, /*MemVTs=*/nullptr, Offsets,
296 0);
297
298 if (SplitVTs.size() == 0)
299 return;
300
301 if (SplitVTs.size() == 1) {
302 // No splitting to do, but we want to replace the original type (e.g. [1 x
303 // double] -> double).
304 SplitArgs.emplace_back(OrigArg.Regs[0], SplitVTs[0].getTypeForEVT(Ctx),
305 OrigArg.OrigArgIndex, OrigArg.Flags[0],
306 OrigArg.OrigValue);
307 return;
308 }
309
310 // Create one ArgInfo for each virtual register in the original ArgInfo.
311 assert(OrigArg.Regs.size() == SplitVTs.size() && "Regs / types mismatch");
312
313 bool NeedsRegBlock = TLI->functionArgumentNeedsConsecutiveRegisters(
314 OrigArg.Ty, CallConv, false, DL);
315 for (unsigned i = 0, e = SplitVTs.size(); i < e; ++i) {
316 Type *SplitTy = SplitVTs[i].getTypeForEVT(Ctx);
317 SplitArgs.emplace_back(OrigArg.Regs[i], SplitTy, OrigArg.OrigArgIndex,
318 OrigArg.Flags[0]);
319 if (NeedsRegBlock)
320 SplitArgs.back().Flags[0].setInConsecutiveRegs();
321 }
322
323 SplitArgs.back().Flags[0].setInConsecutiveRegsLast();
324}
325
326/// Pack values \p SrcRegs to cover the vector type result \p DstRegs.
329 ArrayRef<Register> SrcRegs) {
330 MachineRegisterInfo &MRI = *B.getMRI();
331 LLT LLTy = MRI.getType(DstRegs[0]);
332 LLT PartLLT = MRI.getType(SrcRegs[0]);
333
334 // Deal with v3s16 split into v2s16
335 LLT LCMTy = getCoverTy(LLTy, PartLLT);
336 if (LCMTy == LLTy) {
337 // Common case where no padding is needed.
338 assert(DstRegs.size() == 1);
339 return B.buildConcatVectors(DstRegs[0], SrcRegs);
340 }
341
342 // We need to create an unmerge to the result registers, which may require
343 // widening the original value.
344 Register UnmergeSrcReg;
345 if (LCMTy != PartLLT) {
346 assert(DstRegs.size() == 1);
347 return B.buildDeleteTrailingVectorElements(
348 DstRegs[0], B.buildMergeLikeInstr(LCMTy, SrcRegs));
349 } else {
350 // We don't need to widen anything if we're extracting a scalar which was
351 // promoted to a vector e.g. s8 -> v4s8 -> s8
352 assert(SrcRegs.size() == 1);
353 UnmergeSrcReg = SrcRegs[0];
354 }
355
356 int NumDst = LCMTy.getSizeInBits() / LLTy.getSizeInBits();
357
358 SmallVector<Register, 8> PadDstRegs(NumDst);
359 llvm::copy(DstRegs, PadDstRegs.begin());
360
361 // Create the excess dead defs for the unmerge.
362 for (int I = DstRegs.size(); I != NumDst; ++I)
363 PadDstRegs[I] = MRI.createGenericVirtualRegister(LLTy);
364
365 if (PadDstRegs.size() == 1)
366 return B.buildDeleteTrailingVectorElements(DstRegs[0], UnmergeSrcReg);
367 return B.buildUnmerge(PadDstRegs, UnmergeSrcReg);
368}
369
370/// Create a sequence of instructions to combine pieces split into register
371/// typed values to the original IR value. \p OrigRegs contains the destination
372/// value registers of type \p LLTy, and \p Regs contains the legalized pieces
373/// with type \p PartLLT. This is used for incoming values (physregs to vregs).
375 ArrayRef<Register> Regs, LLT LLTy, LLT PartLLT,
376 const ISD::ArgFlagsTy Flags) {
377 MachineRegisterInfo &MRI = *B.getMRI();
378
379 if (PartLLT == LLTy) {
380 // We should have avoided introducing a new virtual register, and just
381 // directly assigned here.
382 assert(OrigRegs[0] == Regs[0]);
383 return;
384 }
385
386 if (PartLLT.getSizeInBits() == LLTy.getSizeInBits() && OrigRegs.size() == 1 &&
387 Regs.size() == 1) {
388 B.buildBitcast(OrigRegs[0], Regs[0]);
389 return;
390 }
391
392 // A vector PartLLT needs extending to LLTy's element size.
393 // E.g. <2 x s64> = G_SEXT <2 x s32>.
394 if (PartLLT.isVector() == LLTy.isVector() &&
395 PartLLT.getScalarSizeInBits() > LLTy.getScalarSizeInBits() &&
396 (!PartLLT.isVector() ||
397 PartLLT.getElementCount() == LLTy.getElementCount()) &&
398 OrigRegs.size() == 1 && Regs.size() == 1) {
399 Register SrcReg = Regs[0];
400
401 LLT LocTy = MRI.getType(SrcReg);
402
403 if (Flags.isSExt()) {
404 SrcReg = B.buildAssertSExt(LocTy, SrcReg, LLTy.getScalarSizeInBits())
405 .getReg(0);
406 } else if (Flags.isZExt()) {
407 SrcReg = B.buildAssertZExt(LocTy, SrcReg, LLTy.getScalarSizeInBits())
408 .getReg(0);
409 }
410
411 // Sometimes pointers are passed zero extended.
412 LLT OrigTy = MRI.getType(OrigRegs[0]);
413 if (OrigTy.isPointer()) {
414 LLT IntPtrTy = LLT::scalar(OrigTy.getSizeInBits());
415 B.buildIntToPtr(OrigRegs[0], B.buildTrunc(IntPtrTy, SrcReg));
416 return;
417 }
418
419 B.buildTrunc(OrigRegs[0], SrcReg);
420 return;
421 }
422
423 if (!LLTy.isVector() && !PartLLT.isVector()) {
424 assert(OrigRegs.size() == 1);
425 LLT OrigTy = MRI.getType(OrigRegs[0]);
426
427 unsigned SrcSize = PartLLT.getSizeInBits().getFixedValue() * Regs.size();
428 if (SrcSize == OrigTy.getSizeInBits())
429 B.buildMergeValues(OrigRegs[0], Regs);
430 else {
431 auto Widened = B.buildMergeLikeInstr(LLT::scalar(SrcSize), Regs);
432 B.buildTrunc(OrigRegs[0], Widened);
433 }
434
435 return;
436 }
437
438 if (PartLLT.isVector()) {
439 assert(OrigRegs.size() == 1);
440 SmallVector<Register> CastRegs(Regs);
441
442 // If PartLLT is a mismatched vector in both number of elements and element
443 // size, e.g. PartLLT == v2s64 and LLTy is v3s32, then first coerce it to
444 // have the same elt type, i.e. v4s32.
445 // TODO: Extend this coersion to element multiples other than just 2.
446 if (TypeSize::isKnownGT(PartLLT.getSizeInBits(), LLTy.getSizeInBits()) &&
447 PartLLT.getScalarSizeInBits() == LLTy.getScalarSizeInBits() * 2 &&
448 Regs.size() == 1) {
449 LLT NewTy = PartLLT.changeElementType(LLTy.getElementType())
450 .changeElementCount(PartLLT.getElementCount() * 2);
451 CastRegs[0] = B.buildBitcast(NewTy, Regs[0]).getReg(0);
452 PartLLT = NewTy;
453 }
454
455 if (LLTy.getScalarType() == PartLLT.getElementType()) {
456 mergeVectorRegsToResultRegs(B, OrigRegs, CastRegs);
457 } else {
458 unsigned I = 0;
459 LLT GCDTy = getGCDType(LLTy, PartLLT);
460
461 // We are both splitting a vector, and bitcasting its element types. Cast
462 // the source pieces into the appropriate number of pieces with the result
463 // element type.
464 for (Register SrcReg : CastRegs)
465 CastRegs[I++] = B.buildBitcast(GCDTy, SrcReg).getReg(0);
466 mergeVectorRegsToResultRegs(B, OrigRegs, CastRegs);
467 }
468
469 return;
470 }
471
472 assert(LLTy.isVector() && !PartLLT.isVector());
473
474 LLT DstEltTy = LLTy.getElementType();
475
476 // Pointer information was discarded. We'll need to coerce some register types
477 // to avoid violating type constraints.
478 LLT RealDstEltTy = MRI.getType(OrigRegs[0]).getElementType();
479
480 assert(DstEltTy.getSizeInBits() == RealDstEltTy.getSizeInBits());
481
482 if (DstEltTy == PartLLT) {
483 // Vector was trivially scalarized.
484
485 if (RealDstEltTy.isPointer()) {
486 for (Register Reg : Regs)
487 MRI.setType(Reg, RealDstEltTy);
488 }
489
490 B.buildBuildVector(OrigRegs[0], Regs);
491 } else if (DstEltTy.getSizeInBits() > PartLLT.getSizeInBits()) {
492 // Deal with vector with 64-bit elements decomposed to 32-bit
493 // registers. Need to create intermediate 64-bit elements.
494 SmallVector<Register, 8> EltMerges;
495 int PartsPerElt =
496 divideCeil(DstEltTy.getSizeInBits(), PartLLT.getSizeInBits());
497 LLT ExtendedPartTy = LLT::scalar(PartLLT.getSizeInBits() * PartsPerElt);
498
499 for (int I = 0, NumElts = LLTy.getNumElements(); I != NumElts; ++I) {
500 auto Merge =
501 B.buildMergeLikeInstr(ExtendedPartTy, Regs.take_front(PartsPerElt));
502 if (ExtendedPartTy.getSizeInBits() > RealDstEltTy.getSizeInBits())
503 Merge = B.buildTrunc(RealDstEltTy, Merge);
504 // Fix the type in case this is really a vector of pointers.
505 MRI.setType(Merge.getReg(0), RealDstEltTy);
506 EltMerges.push_back(Merge.getReg(0));
507 Regs = Regs.drop_front(PartsPerElt);
508 }
509
510 B.buildBuildVector(OrigRegs[0], EltMerges);
511 } else {
512 // Vector was split, and elements promoted to a wider type.
513 // FIXME: Should handle floating point promotions.
514 unsigned NumElts = LLTy.getNumElements();
515 LLT BVType = LLT::fixed_vector(NumElts, PartLLT);
516
517 Register BuildVec;
518 if (NumElts == Regs.size())
519 BuildVec = B.buildBuildVector(BVType, Regs).getReg(0);
520 else {
521 // Vector elements are packed in the inputs.
522 // e.g. we have a <4 x s16> but 2 x s32 in regs.
523 assert(NumElts > Regs.size());
524 LLT SrcEltTy = MRI.getType(Regs[0]);
525
526 LLT OriginalEltTy = MRI.getType(OrigRegs[0]).getElementType();
527
528 // Input registers contain packed elements.
529 // Determine how many elements per reg.
530 assert((SrcEltTy.getSizeInBits() % OriginalEltTy.getSizeInBits()) == 0);
531 unsigned EltPerReg =
532 (SrcEltTy.getSizeInBits() / OriginalEltTy.getSizeInBits());
533
535 BVRegs.reserve(Regs.size() * EltPerReg);
536 for (Register R : Regs) {
537 auto Unmerge = B.buildUnmerge(OriginalEltTy, R);
538 for (unsigned K = 0; K < EltPerReg; ++K)
539 BVRegs.push_back(B.buildAnyExt(PartLLT, Unmerge.getReg(K)).getReg(0));
540 }
541
542 // We may have some more elements in BVRegs, e.g. if we have 2 s32 pieces
543 // for a <3 x s16> vector. We should have less than EltPerReg extra items.
544 if (BVRegs.size() > NumElts) {
545 assert((BVRegs.size() - NumElts) < EltPerReg);
546 BVRegs.truncate(NumElts);
547 }
548 BuildVec = B.buildBuildVector(BVType, BVRegs).getReg(0);
549 }
550 B.buildTrunc(OrigRegs[0], BuildVec);
551 }
552}
553
554/// Create a sequence of instructions to expand the value in \p SrcReg (of type
555/// \p SrcTy) to the types in \p DstRegs (of type \p PartTy). \p ExtendOp should
556/// contain the type of scalar value extension if necessary.
557///
558/// This is used for outgoing values (vregs to physregs)
560 Register SrcReg, LLT SrcTy, LLT PartTy,
561 unsigned ExtendOp = TargetOpcode::G_ANYEXT) {
562 // We could just insert a regular copy, but this is unreachable at the moment.
563 assert(SrcTy != PartTy && "identical part types shouldn't reach here");
564
565 const TypeSize PartSize = PartTy.getSizeInBits();
566
567 if (PartTy.isVector() == SrcTy.isVector() &&
568 PartTy.getScalarSizeInBits() > SrcTy.getScalarSizeInBits()) {
569 assert(DstRegs.size() == 1);
570 B.buildInstr(ExtendOp, {DstRegs[0]}, {SrcReg});
571 return;
572 }
573
574 if (SrcTy.isVector() && !PartTy.isVector() &&
575 TypeSize::isKnownGT(PartSize, SrcTy.getElementType().getSizeInBits())) {
576 // Vector was scalarized, and the elements extended.
577 auto UnmergeToEltTy = B.buildUnmerge(SrcTy.getElementType(), SrcReg);
578 for (int i = 0, e = DstRegs.size(); i != e; ++i)
579 B.buildAnyExt(DstRegs[i], UnmergeToEltTy.getReg(i));
580 return;
581 }
582
583 if (SrcTy.isVector() && PartTy.isVector() &&
584 PartTy.getSizeInBits() == SrcTy.getSizeInBits() &&
585 ElementCount::isKnownLT(SrcTy.getElementCount(),
586 PartTy.getElementCount())) {
587 // A coercion like: v2f32 -> v4f32 or nxv2f32 -> nxv4f32
588 Register DstReg = DstRegs.front();
589 B.buildPadVectorWithUndefElements(DstReg, SrcReg);
590 return;
591 }
592
593 LLT GCDTy = getGCDType(SrcTy, PartTy);
594 if (GCDTy == PartTy) {
595 // If this already evenly divisible, we can create a simple unmerge.
596 B.buildUnmerge(DstRegs, SrcReg);
597 return;
598 }
599
600 if (SrcTy.isVector() && !PartTy.isVector() &&
601 SrcTy.getScalarSizeInBits() > PartTy.getSizeInBits()) {
602 LLT ExtTy =
603 LLT::vector(SrcTy.getElementCount(),
604 LLT::scalar(PartTy.getScalarSizeInBits() * DstRegs.size() /
605 SrcTy.getNumElements()));
606 auto Ext = B.buildAnyExt(ExtTy, SrcReg);
607 B.buildUnmerge(DstRegs, Ext);
608 return;
609 }
610
611 MachineRegisterInfo &MRI = *B.getMRI();
612 LLT DstTy = MRI.getType(DstRegs[0]);
613 LLT LCMTy = getCoverTy(SrcTy, PartTy);
614
615 if (PartTy.isVector() && LCMTy == PartTy) {
616 assert(DstRegs.size() == 1);
617 B.buildPadVectorWithUndefElements(DstRegs[0], SrcReg);
618 return;
619 }
620
621 const unsigned DstSize = DstTy.getSizeInBits();
622 const unsigned SrcSize = SrcTy.getSizeInBits();
623 unsigned CoveringSize = LCMTy.getSizeInBits();
624
625 Register UnmergeSrc = SrcReg;
626
627 if (!LCMTy.isVector() && CoveringSize != SrcSize) {
628 // For scalars, it's common to be able to use a simple extension.
629 if (SrcTy.isScalar() && DstTy.isScalar()) {
630 CoveringSize = alignTo(SrcSize, DstSize);
631 LLT CoverTy = LLT::scalar(CoveringSize);
632 UnmergeSrc = B.buildInstr(ExtendOp, {CoverTy}, {SrcReg}).getReg(0);
633 } else {
634 // Widen to the common type.
635 // FIXME: This should respect the extend type
636 Register Undef = B.buildUndef(SrcTy).getReg(0);
637 SmallVector<Register, 8> MergeParts(1, SrcReg);
638 for (unsigned Size = SrcSize; Size != CoveringSize; Size += SrcSize)
639 MergeParts.push_back(Undef);
640 UnmergeSrc = B.buildMergeLikeInstr(LCMTy, MergeParts).getReg(0);
641 }
642 }
643
644 if (LCMTy.isVector() && CoveringSize != SrcSize)
645 UnmergeSrc = B.buildPadVectorWithUndefElements(LCMTy, SrcReg).getReg(0);
646
647 B.buildUnmerge(DstRegs, UnmergeSrc);
648}
649
651 ValueHandler &Handler, ValueAssigner &Assigner,
653 CallingConv::ID CallConv, bool IsVarArg,
654 ArrayRef<Register> ThisReturnRegs) const {
655 MachineFunction &MF = MIRBuilder.getMF();
656 const Function &F = MF.getFunction();
658
659 CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, F.getContext());
660 if (!determineAssignments(Assigner, Args, CCInfo))
661 return false;
662
663 return handleAssignments(Handler, Args, CCInfo, ArgLocs, MIRBuilder,
664 ThisReturnRegs);
665}
666
668 if (Flags.isSExt())
669 return TargetOpcode::G_SEXT;
670 if (Flags.isZExt())
671 return TargetOpcode::G_ZEXT;
672 return TargetOpcode::G_ANYEXT;
673}
674
677 CCState &CCInfo) const {
678 LLVMContext &Ctx = CCInfo.getContext();
679 const CallingConv::ID CallConv = CCInfo.getCallingConv();
680
681 unsigned NumArgs = Args.size();
682 for (unsigned i = 0; i != NumArgs; ++i) {
683 EVT CurVT = EVT::getEVT(Args[i].Ty);
684
685 MVT NewVT = TLI->getRegisterTypeForCallingConv(Ctx, CallConv, CurVT);
686
687 // If we need to split the type over multiple regs, check it's a scenario
688 // we currently support.
689 unsigned NumParts =
690 TLI->getNumRegistersForCallingConv(Ctx, CallConv, CurVT);
691
692 if (NumParts == 1) {
693 // Try to use the register type if we couldn't assign the VT.
694 if (Assigner.assignArg(i, CurVT, NewVT, NewVT, CCValAssign::Full, Args[i],
695 Args[i].Flags[0], CCInfo))
696 return false;
697 continue;
698 }
699
700 // For incoming arguments (physregs to vregs), we could have values in
701 // physregs (or memlocs) which we want to extract and copy to vregs.
702 // During this, we might have to deal with the LLT being split across
703 // multiple regs, so we have to record this information for later.
704 //
705 // If we have outgoing args, then we have the opposite case. We have a
706 // vreg with an LLT which we want to assign to a physical location, and
707 // we might have to record that the value has to be split later.
708
709 // We're handling an incoming arg which is split over multiple regs.
710 // E.g. passing an s128 on AArch64.
711 ISD::ArgFlagsTy OrigFlags = Args[i].Flags[0];
712 Args[i].Flags.clear();
713
714 for (unsigned Part = 0; Part < NumParts; ++Part) {
715 ISD::ArgFlagsTy Flags = OrigFlags;
716 if (Part == 0) {
717 Flags.setSplit();
718 } else {
719 Flags.setOrigAlign(Align(1));
720 if (Part == NumParts - 1)
721 Flags.setSplitEnd();
722 }
723
724 Args[i].Flags.push_back(Flags);
725 if (Assigner.assignArg(i, CurVT, NewVT, NewVT, CCValAssign::Full, Args[i],
726 Args[i].Flags[Part], CCInfo)) {
727 // Still couldn't assign this smaller part type for some reason.
728 return false;
729 }
730 }
731 }
732
733 return true;
734}
735
738 CCState &CCInfo,
740 MachineIRBuilder &MIRBuilder,
741 ArrayRef<Register> ThisReturnRegs) const {
742 MachineFunction &MF = MIRBuilder.getMF();
744 const Function &F = MF.getFunction();
745 const DataLayout &DL = F.getDataLayout();
746
747 const unsigned NumArgs = Args.size();
748
749 // Stores thunks for outgoing register assignments. This is used so we delay
750 // generating register copies until mem loc assignments are done. We do this
751 // so that if the target is using the delayed stack protector feature, we can
752 // find the split point of the block accurately. E.g. if we have:
753 // G_STORE %val, %memloc
754 // $x0 = COPY %foo
755 // $x1 = COPY %bar
756 // CALL func
757 // ... then the split point for the block will correctly be at, and including,
758 // the copy to $x0. If instead the G_STORE instruction immediately precedes
759 // the CALL, then we'd prematurely choose the CALL as the split point, thus
760 // generating a split block with a CALL that uses undefined physregs.
761 SmallVector<std::function<void()>> DelayedOutgoingRegAssignments;
762
763 for (unsigned i = 0, j = 0; i != NumArgs; ++i, ++j) {
764 assert(j < ArgLocs.size() && "Skipped too many arg locs");
765 CCValAssign &VA = ArgLocs[j];
766 assert(VA.getValNo() == i && "Location doesn't correspond to current arg");
767
768 if (VA.needsCustom()) {
769 std::function<void()> Thunk;
770 unsigned NumArgRegs = Handler.assignCustomValue(
771 Args[i], ArrayRef(ArgLocs).slice(j), &Thunk);
772 if (Thunk)
773 DelayedOutgoingRegAssignments.emplace_back(Thunk);
774 if (!NumArgRegs)
775 return false;
776 j += (NumArgRegs - 1);
777 continue;
778 }
779
780 auto AllocaAddressSpace = MF.getDataLayout().getAllocaAddrSpace();
781
782 const MVT ValVT = VA.getValVT();
783 const MVT LocVT = VA.getLocVT();
784
785 const LLT LocTy(LocVT);
786 const LLT ValTy(ValVT);
787 const LLT NewLLT = Handler.isIncomingArgumentHandler() ? LocTy : ValTy;
788 const EVT OrigVT = EVT::getEVT(Args[i].Ty);
789 const LLT OrigTy = getLLTForType(*Args[i].Ty, DL);
790 const LLT PointerTy = LLT::pointer(
791 AllocaAddressSpace, DL.getPointerSizeInBits(AllocaAddressSpace));
792
793 // Expected to be multiple regs for a single incoming arg.
794 // There should be Regs.size() ArgLocs per argument.
795 // This should be the same as getNumRegistersForCallingConv
796 const unsigned NumParts = Args[i].Flags.size();
797
798 // Now split the registers into the assigned types.
799 Args[i].OrigRegs.assign(Args[i].Regs.begin(), Args[i].Regs.end());
800
801 if (NumParts != 1 || NewLLT != OrigTy) {
802 // If we can't directly assign the register, we need one or more
803 // intermediate values.
804 Args[i].Regs.resize(NumParts);
805
806 // When we have indirect parameter passing we are receiving a pointer,
807 // that points to the actual value, so we need one "temporary" pointer.
808 if (VA.getLocInfo() == CCValAssign::Indirect) {
809 if (Handler.isIncomingArgumentHandler())
810 Args[i].Regs[0] = MRI.createGenericVirtualRegister(PointerTy);
811 } else {
812 // For each split register, create and assign a vreg that will store
813 // the incoming component of the larger value. These will later be
814 // merged to form the final vreg.
815 for (unsigned Part = 0; Part < NumParts; ++Part)
816 Args[i].Regs[Part] = MRI.createGenericVirtualRegister(NewLLT);
817 }
818 }
819
820 assert((j + (NumParts - 1)) < ArgLocs.size() &&
821 "Too many regs for number of args");
822
823 // Coerce into outgoing value types before register assignment.
824 if (!Handler.isIncomingArgumentHandler() && OrigTy != ValTy &&
826 assert(Args[i].OrigRegs.size() == 1);
827 buildCopyToRegs(MIRBuilder, Args[i].Regs, Args[i].OrigRegs[0], OrigTy,
828 ValTy, extendOpFromFlags(Args[i].Flags[0]));
829 }
830
831 bool IndirectParameterPassingHandled = false;
832 bool BigEndianPartOrdering = TLI->hasBigEndianPartOrdering(OrigVT, DL);
833 for (unsigned Part = 0; Part < NumParts; ++Part) {
834 assert((VA.getLocInfo() != CCValAssign::Indirect || Part == 0) &&
835 "Only the first parameter should be processed when "
836 "handling indirect passing!");
837 Register ArgReg = Args[i].Regs[Part];
838 // There should be Regs.size() ArgLocs per argument.
839 unsigned Idx = BigEndianPartOrdering ? NumParts - 1 - Part : Part;
840 CCValAssign &VA = ArgLocs[j + Idx];
841 const ISD::ArgFlagsTy Flags = Args[i].Flags[Part];
842
843 // We found an indirect parameter passing, and we have an
844 // OutgoingValueHandler as our handler (so we are at the call site or the
845 // return value). In this case, start the construction of the following
846 // GMIR, that is responsible for the preparation of indirect parameter
847 // passing:
848 //
849 // %1(indirectly passed type) = The value to pass
850 // %3(pointer) = G_FRAME_INDEX %stack.0
851 // G_STORE %1, %3 :: (store (s128), align 8)
852 //
853 // After this GMIR, the remaining part of the loop body will decide how
854 // to get the value to the caller and we break out of the loop.
855 if (VA.getLocInfo() == CCValAssign::Indirect &&
856 !Handler.isIncomingArgumentHandler()) {
857 Align AlignmentForStored = DL.getPrefTypeAlign(Args[i].Ty);
858 MachineFrameInfo &MFI = MF.getFrameInfo();
859 // Get some space on the stack for the value, so later we can pass it
860 // as a reference.
861 int FrameIdx = MFI.CreateStackObject(OrigTy.getScalarSizeInBits(),
862 AlignmentForStored, false);
863 Register PointerToStackReg =
864 MIRBuilder.buildFrameIndex(PointerTy, FrameIdx).getReg(0);
865 MachinePointerInfo StackPointerMPO =
867 // Store the value in the previously created stack space.
868 MIRBuilder.buildStore(Args[i].OrigRegs[Part], PointerToStackReg,
869 StackPointerMPO,
870 inferAlignFromPtrInfo(MF, StackPointerMPO));
871
872 ArgReg = PointerToStackReg;
873 IndirectParameterPassingHandled = true;
874 }
875
876 if (VA.isMemLoc() && !Flags.isByVal()) {
877 // Individual pieces may have been spilled to the stack and others
878 // passed in registers.
879
880 // TODO: The memory size may be larger than the value we need to
881 // store. We may need to adjust the offset for big endian targets.
882 LLT MemTy = Handler.getStackValueStoreType(DL, VA, Flags);
883
885 Register StackAddr =
887 ? PointerTy.getSizeInBytes()
888 : MemTy.getSizeInBytes(),
889 VA.getLocMemOffset(), MPO, Flags);
890
891 // Finish the handling of indirect passing from the passers
892 // (OutgoingParameterHandler) side.
893 // This branch is needed, so the pointer to the value is loaded onto the
894 // stack.
896 Handler.assignValueToAddress(ArgReg, StackAddr, PointerTy, MPO, VA);
897 else
898 Handler.assignValueToAddress(Args[i], Part, StackAddr, MemTy, MPO,
899 VA);
900 } else if (VA.isMemLoc() && Flags.isByVal()) {
901 assert(Args[i].Regs.size() == 1 && "didn't expect split byval pointer");
902
903 if (Handler.isIncomingArgumentHandler()) {
904 // We just need to copy the frame index value to the pointer.
906 Register StackAddr = Handler.getStackAddress(
907 Flags.getByValSize(), VA.getLocMemOffset(), MPO, Flags);
908 MIRBuilder.buildCopy(Args[i].Regs[0], StackAddr);
909 } else {
910 // For outgoing byval arguments, insert the implicit copy byval
911 // implies, such that writes in the callee do not modify the caller's
912 // value.
913 uint64_t MemSize = Flags.getByValSize();
914 int64_t Offset = VA.getLocMemOffset();
915
916 MachinePointerInfo DstMPO;
917 Register StackAddr =
918 Handler.getStackAddress(MemSize, Offset, DstMPO, Flags);
919
920 MachinePointerInfo SrcMPO(Args[i].OrigValue);
921 if (!Args[i].OrigValue) {
922 // We still need to accurately track the stack address space if we
923 // don't know the underlying value.
924 const LLT PtrTy = MRI.getType(StackAddr);
925 SrcMPO = MachinePointerInfo(PtrTy.getAddressSpace());
926 }
927
928 Align DstAlign = std::max(Flags.getNonZeroByValAlign(),
929 inferAlignFromPtrInfo(MF, DstMPO));
930
931 Align SrcAlign = std::max(Flags.getNonZeroByValAlign(),
932 inferAlignFromPtrInfo(MF, SrcMPO));
933
934 Handler.copyArgumentMemory(Args[i], StackAddr, Args[i].Regs[0],
935 DstMPO, DstAlign, SrcMPO, SrcAlign,
936 MemSize, VA);
937 }
938 } else if (i == 0 && !ThisReturnRegs.empty() &&
939 Handler.isIncomingArgumentHandler() &&
941 Handler.assignValueToReg(ArgReg, ThisReturnRegs[Part], VA);
942 } else if (Handler.isIncomingArgumentHandler()) {
943 Handler.assignValueToReg(ArgReg, VA.getLocReg(), VA);
944 } else {
945 DelayedOutgoingRegAssignments.emplace_back([=, &Handler]() {
946 Handler.assignValueToReg(ArgReg, VA.getLocReg(), VA);
947 });
948 }
949
950 // Finish the handling of indirect parameter passing when receiving
951 // the value (we are in the called function or the caller when receiving
952 // the return value).
953 if (VA.getLocInfo() == CCValAssign::Indirect &&
954 Handler.isIncomingArgumentHandler()) {
955 Align Alignment = DL.getABITypeAlign(Args[i].Ty);
957
958 // Since we are doing indirect parameter passing, we know that the value
959 // in the temporary register is not the value passed to the function,
960 // but rather a pointer to that value. Let's load that value into the
961 // virtual register where the parameter should go.
962 MIRBuilder.buildLoad(Args[i].OrigRegs[0], Args[i].Regs[0], MPO,
963 Alignment);
964
965 IndirectParameterPassingHandled = true;
966 }
967
968 if (IndirectParameterPassingHandled)
969 break;
970 }
971
972 // Now that all pieces have been assigned, re-pack the register typed values
973 // into the original value typed registers. This is only necessary, when
974 // the value was passed in multiple registers, not indirectly.
975 if (Handler.isIncomingArgumentHandler() && OrigVT != LocVT &&
976 !IndirectParameterPassingHandled) {
977 // Merge the split registers into the expected larger result vregs of
978 // the original call.
979 buildCopyFromRegs(MIRBuilder, Args[i].OrigRegs, Args[i].Regs, OrigTy,
980 LocTy, Args[i].Flags[0]);
981 }
982
983 j += NumParts - 1;
984 }
985 for (auto &Fn : DelayedOutgoingRegAssignments)
986 Fn();
987
988 return true;
989}
990
992 ArrayRef<Register> VRegs, Register DemoteReg,
993 int FI) const {
994 MachineFunction &MF = MIRBuilder.getMF();
996 const DataLayout &DL = MF.getDataLayout();
997
998 SmallVector<EVT, 4> SplitVTs;
1000 ComputeValueVTs(*TLI, DL, RetTy, SplitVTs, /*MemVTs=*/nullptr, &Offsets, 0);
1001
1002 assert(VRegs.size() == SplitVTs.size());
1003
1004 unsigned NumValues = SplitVTs.size();
1005 Align BaseAlign = DL.getPrefTypeAlign(RetTy);
1006 Type *RetPtrTy =
1007 PointerType::get(RetTy->getContext(), DL.getAllocaAddrSpace());
1008 LLT OffsetLLTy = getLLTForType(*DL.getIndexType(RetPtrTy), DL);
1009
1011
1012 for (unsigned I = 0; I < NumValues; ++I) {
1013 Register Addr;
1014 MIRBuilder.materializeObjectPtrOffset(Addr, DemoteReg, OffsetLLTy,
1015 Offsets[I]);
1016 auto *MMO = MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOLoad,
1017 MRI.getType(VRegs[I]),
1018 commonAlignment(BaseAlign, Offsets[I]));
1019 MIRBuilder.buildLoad(VRegs[I], Addr, *MMO);
1020 }
1021}
1022
1024 ArrayRef<Register> VRegs,
1025 Register DemoteReg) const {
1026 MachineFunction &MF = MIRBuilder.getMF();
1028 const DataLayout &DL = MF.getDataLayout();
1029
1030 SmallVector<EVT, 4> SplitVTs;
1032 ComputeValueVTs(*TLI, DL, RetTy, SplitVTs, /*MemVTs=*/nullptr, &Offsets, 0);
1033
1034 assert(VRegs.size() == SplitVTs.size());
1035
1036 unsigned NumValues = SplitVTs.size();
1037 Align BaseAlign = DL.getPrefTypeAlign(RetTy);
1038 unsigned AS = DL.getAllocaAddrSpace();
1039 LLT OffsetLLTy = getLLTForType(*DL.getIndexType(RetTy->getContext(), AS), DL);
1040
1041 MachinePointerInfo PtrInfo(AS);
1042
1043 for (unsigned I = 0; I < NumValues; ++I) {
1044 Register Addr;
1045 MIRBuilder.materializeObjectPtrOffset(Addr, DemoteReg, OffsetLLTy,
1046 Offsets[I]);
1047 auto *MMO = MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore,
1048 MRI.getType(VRegs[I]),
1049 commonAlignment(BaseAlign, Offsets[I]));
1050 MIRBuilder.buildStore(VRegs[I], Addr, *MMO);
1051 }
1052}
1053
1055 const Function &F, SmallVectorImpl<ArgInfo> &SplitArgs, Register &DemoteReg,
1056 MachineRegisterInfo &MRI, const DataLayout &DL) const {
1057 unsigned AS = DL.getAllocaAddrSpace();
1058 DemoteReg = MRI.createGenericVirtualRegister(
1059 LLT::pointer(AS, DL.getPointerSizeInBits(AS)));
1060
1061 Type *PtrTy = PointerType::get(F.getContext(), AS);
1062
1063 SmallVector<EVT, 1> ValueVTs;
1064 ComputeValueVTs(*TLI, DL, PtrTy, ValueVTs);
1065
1066 // NOTE: Assume that a pointer won't get split into more than one VT.
1067 assert(ValueVTs.size() == 1);
1068
1069 ArgInfo DemoteArg(DemoteReg, ValueVTs[0].getTypeForEVT(PtrTy->getContext()),
1071 setArgFlags(DemoteArg, AttributeList::ReturnIndex, DL, F);
1072 DemoteArg.Flags[0].setSRet();
1073 SplitArgs.insert(SplitArgs.begin(), DemoteArg);
1074}
1075
1077 const CallBase &CB,
1078 CallLoweringInfo &Info) const {
1079 const DataLayout &DL = MIRBuilder.getDataLayout();
1080 Type *RetTy = CB.getType();
1081 unsigned AS = DL.getAllocaAddrSpace();
1082 LLT FramePtrTy = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
1083
1084 int FI = MIRBuilder.getMF().getFrameInfo().CreateStackObject(
1085 DL.getTypeAllocSize(RetTy), DL.getPrefTypeAlign(RetTy), false);
1086
1087 Register DemoteReg = MIRBuilder.buildFrameIndex(FramePtrTy, FI).getReg(0);
1088 ArgInfo DemoteArg(DemoteReg, PointerType::get(RetTy->getContext(), AS),
1090 setArgFlags(DemoteArg, AttributeList::ReturnIndex, DL, CB);
1091 DemoteArg.Flags[0].setSRet();
1092
1093 Info.OrigArgs.insert(Info.OrigArgs.begin(), DemoteArg);
1094 Info.DemoteStackIndex = FI;
1095 Info.DemoteRegister = DemoteReg;
1096}
1097
1100 CCAssignFn *Fn) const {
1101 for (unsigned I = 0, E = Outs.size(); I < E; ++I) {
1102 MVT VT = MVT::getVT(Outs[I].Ty);
1103 if (Fn(I, VT, VT, CCValAssign::Full, Outs[I].Flags[0], Outs[I].Ty, CCInfo))
1104 return false;
1105 }
1106 return true;
1107}
1108
1110 AttributeList Attrs,
1112 const DataLayout &DL) const {
1113 LLVMContext &Context = RetTy->getContext();
1115
1116 SmallVector<EVT, 4> SplitVTs;
1117 ComputeValueVTs(*TLI, DL, RetTy, SplitVTs);
1118 addArgFlagsFromAttributes(Flags, Attrs, AttributeList::ReturnIndex);
1119
1120 for (EVT VT : SplitVTs) {
1121 unsigned NumParts =
1122 TLI->getNumRegistersForCallingConv(Context, CallConv, VT);
1123 MVT RegVT = TLI->getRegisterTypeForCallingConv(Context, CallConv, VT);
1124 Type *PartTy = EVT(RegVT).getTypeForEVT(Context);
1125
1126 for (unsigned I = 0; I < NumParts; ++I) {
1127 Outs.emplace_back(PartTy, Flags);
1128 }
1129 }
1130}
1131
1133 const auto &F = MF.getFunction();
1134 Type *ReturnType = F.getReturnType();
1135 CallingConv::ID CallConv = F.getCallingConv();
1136
1138 getReturnInfo(CallConv, ReturnType, F.getAttributes(), SplitArgs,
1139 MF.getDataLayout());
1140 return canLowerReturn(MF, CallConv, SplitArgs, F.isVarArg());
1141}
1142
1144 const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask,
1145 const SmallVectorImpl<CCValAssign> &OutLocs,
1146 const SmallVectorImpl<ArgInfo> &OutArgs) const {
1147 for (unsigned i = 0; i < OutLocs.size(); ++i) {
1148 const auto &ArgLoc = OutLocs[i];
1149 // If it's not a register, it's fine.
1150 if (!ArgLoc.isRegLoc())
1151 continue;
1152
1153 MCRegister PhysReg = ArgLoc.getLocReg();
1154
1155 // Only look at callee-saved registers.
1156 if (MachineOperand::clobbersPhysReg(CallerPreservedMask, PhysReg))
1157 continue;
1158
1159 LLVM_DEBUG(
1160 dbgs()
1161 << "... Call has an argument passed in a callee-saved register.\n");
1162
1163 // Check if it was copied from.
1164 const ArgInfo &OutInfo = OutArgs[i];
1165
1166 if (OutInfo.Regs.size() > 1) {
1167 LLVM_DEBUG(
1168 dbgs() << "... Cannot handle arguments in multiple registers.\n");
1169 return false;
1170 }
1171
1172 // Check if we copy the register, walking through copies from virtual
1173 // registers. Note that getDefIgnoringCopies does not ignore copies from
1174 // physical registers.
1175 MachineInstr *RegDef = getDefIgnoringCopies(OutInfo.Regs[0], MRI);
1176 if (!RegDef || RegDef->getOpcode() != TargetOpcode::COPY) {
1177 LLVM_DEBUG(
1178 dbgs()
1179 << "... Parameter was not copied into a VReg, cannot tail call.\n");
1180 return false;
1181 }
1182
1183 // Got a copy. Verify that it's the same as the register we want.
1184 Register CopyRHS = RegDef->getOperand(1).getReg();
1185 if (CopyRHS != PhysReg) {
1186 LLVM_DEBUG(dbgs() << "... Callee-saved register was not copied into "
1187 "VReg, cannot tail call.\n");
1188 return false;
1189 }
1190 }
1191
1192 return true;
1193}
1194
1196 MachineFunction &MF,
1198 ValueAssigner &CalleeAssigner,
1199 ValueAssigner &CallerAssigner) const {
1200 const Function &F = MF.getFunction();
1201 CallingConv::ID CalleeCC = Info.CallConv;
1202 CallingConv::ID CallerCC = F.getCallingConv();
1203
1204 if (CallerCC == CalleeCC)
1205 return true;
1206
1208 CCState CCInfo1(CalleeCC, Info.IsVarArg, MF, ArgLocs1, F.getContext());
1209 if (!determineAssignments(CalleeAssigner, InArgs, CCInfo1))
1210 return false;
1211
1213 CCState CCInfo2(CallerCC, F.isVarArg(), MF, ArgLocs2, F.getContext());
1214 if (!determineAssignments(CallerAssigner, InArgs, CCInfo2))
1215 return false;
1216
1217 // We need the argument locations to match up exactly. If there's more in
1218 // one than the other, then we are done.
1219 if (ArgLocs1.size() != ArgLocs2.size())
1220 return false;
1221
1222 // Make sure that each location is passed in exactly the same way.
1223 for (unsigned i = 0, e = ArgLocs1.size(); i < e; ++i) {
1224 const CCValAssign &Loc1 = ArgLocs1[i];
1225 const CCValAssign &Loc2 = ArgLocs2[i];
1226
1227 // We need both of them to be the same. So if one is a register and one
1228 // isn't, we're done.
1229 if (Loc1.isRegLoc() != Loc2.isRegLoc())
1230 return false;
1231
1232 if (Loc1.isRegLoc()) {
1233 // If they don't have the same register location, we're done.
1234 if (Loc1.getLocReg() != Loc2.getLocReg())
1235 return false;
1236
1237 // They matched, so we can move to the next ArgLoc.
1238 continue;
1239 }
1240
1241 // Loc1 wasn't a RegLoc, so they both must be MemLocs. Check if they match.
1242 if (Loc1.getLocMemOffset() != Loc2.getLocMemOffset())
1243 return false;
1244 }
1245
1246 return true;
1247}
1248
1250 const DataLayout &DL, const CCValAssign &VA, ISD::ArgFlagsTy Flags) const {
1251 const MVT ValVT = VA.getValVT();
1252 if (ValVT != MVT::iPTR) {
1253 LLT ValTy(ValVT);
1254
1255 // We lost the pointeriness going through CCValAssign, so try to restore it
1256 // based on the flags.
1257 if (Flags.isPointer()) {
1258 LLT PtrTy = LLT::pointer(Flags.getPointerAddrSpace(),
1259 ValTy.getScalarSizeInBits());
1260 if (ValVT.isVector() && ValVT.getVectorNumElements() != 1)
1261 return LLT::vector(ValTy.getElementCount(), PtrTy);
1262 return PtrTy;
1263 }
1264
1265 return ValTy;
1266 }
1267
1268 unsigned AddrSpace = Flags.getPointerAddrSpace();
1269 return LLT::pointer(AddrSpace, DL.getPointerSize(AddrSpace));
1270}
1271
1273 const ArgInfo &Arg, Register DstPtr, Register SrcPtr,
1274 const MachinePointerInfo &DstPtrInfo, Align DstAlign,
1275 const MachinePointerInfo &SrcPtrInfo, Align SrcAlign, uint64_t MemSize,
1276 CCValAssign &VA) const {
1277 MachineFunction &MF = MIRBuilder.getMF();
1279 SrcPtrInfo,
1281 SrcAlign);
1282
1284 DstPtrInfo,
1286 MemSize, DstAlign);
1287
1288 const LLT PtrTy = MRI.getType(DstPtr);
1289 const LLT SizeTy = LLT::scalar(PtrTy.getSizeInBits());
1290
1291 auto SizeConst = MIRBuilder.buildConstant(SizeTy, MemSize);
1292 MIRBuilder.buildMemCpy(DstPtr, SrcPtr, SizeConst, *DstMMO, *SrcMMO);
1293}
1294
1296 const CCValAssign &VA,
1297 unsigned MaxSizeBits) {
1298 LLT LocTy{VA.getLocVT()};
1299 LLT ValTy{VA.getValVT()};
1300
1301 if (LocTy.getSizeInBits() == ValTy.getSizeInBits())
1302 return ValReg;
1303
1304 if (LocTy.isScalar() && MaxSizeBits && MaxSizeBits < LocTy.getSizeInBits()) {
1305 if (MaxSizeBits <= ValTy.getSizeInBits())
1306 return ValReg;
1307 LocTy = LLT::scalar(MaxSizeBits);
1308 }
1309
1310 const LLT ValRegTy = MRI.getType(ValReg);
1311 if (ValRegTy.isPointer()) {
1312 // The x32 ABI wants to zero extend 32-bit pointers to 64-bit registers, so
1313 // we have to cast to do the extension.
1314 LLT IntPtrTy = LLT::scalar(ValRegTy.getSizeInBits());
1315 ValReg = MIRBuilder.buildPtrToInt(IntPtrTy, ValReg).getReg(0);
1316 }
1317
1318 switch (VA.getLocInfo()) {
1319 default:
1320 break;
1321 case CCValAssign::Full:
1322 case CCValAssign::BCvt:
1323 // FIXME: bitconverting between vector types may or may not be a
1324 // nop in big-endian situations.
1325 return ValReg;
1326 case CCValAssign::AExt: {
1327 auto MIB = MIRBuilder.buildAnyExt(LocTy, ValReg);
1328 return MIB.getReg(0);
1329 }
1330 case CCValAssign::SExt: {
1331 Register NewReg = MRI.createGenericVirtualRegister(LocTy);
1332 MIRBuilder.buildSExt(NewReg, ValReg);
1333 return NewReg;
1334 }
1335 case CCValAssign::ZExt: {
1336 Register NewReg = MRI.createGenericVirtualRegister(LocTy);
1337 MIRBuilder.buildZExt(NewReg, ValReg);
1338 return NewReg;
1339 }
1340 }
1341 llvm_unreachable("unable to extend register");
1342}
1343
1344void CallLowering::ValueAssigner::anchor() {}
1345
1347 const CCValAssign &VA, Register SrcReg, LLT NarrowTy) {
1348 switch (VA.getLocInfo()) {
1350 return MIRBuilder
1351 .buildAssertZExt(MRI.cloneVirtualRegister(SrcReg), SrcReg,
1352 NarrowTy.getScalarSizeInBits())
1353 .getReg(0);
1354 }
1356 return MIRBuilder
1357 .buildAssertSExt(MRI.cloneVirtualRegister(SrcReg), SrcReg,
1358 NarrowTy.getScalarSizeInBits())
1359 .getReg(0);
1360 break;
1361 }
1362 default:
1363 return SrcReg;
1364 }
1365}
1366
1367/// Check if we can use a basic COPY instruction between the two types.
1368///
1369/// We're currently building on top of the infrastructure using MVT, which loses
1370/// pointer information in the CCValAssign. We accept copies from physical
1371/// registers that have been reported as integers if it's to an equivalent sized
1372/// pointer LLT.
1373static bool isCopyCompatibleType(LLT SrcTy, LLT DstTy) {
1374 if (SrcTy == DstTy)
1375 return true;
1376
1377 if (SrcTy.getSizeInBits() != DstTy.getSizeInBits())
1378 return false;
1379
1380 SrcTy = SrcTy.getScalarType();
1381 DstTy = DstTy.getScalarType();
1382
1383 return (SrcTy.isPointer() && DstTy.isScalar()) ||
1384 (DstTy.isPointer() && SrcTy.isScalar());
1385}
1386
1388 Register ValVReg, Register PhysReg, const CCValAssign &VA) {
1389 const MVT LocVT = VA.getLocVT();
1390 const LLT LocTy(LocVT);
1391 const LLT RegTy = MRI.getType(ValVReg);
1392
1393 if (isCopyCompatibleType(RegTy, LocTy)) {
1394 MIRBuilder.buildCopy(ValVReg, PhysReg);
1395 return;
1396 }
1397
1398 auto Copy = MIRBuilder.buildCopy(LocTy, PhysReg);
1399 auto Hint = buildExtensionHint(VA, Copy.getReg(0), RegTy);
1400 MIRBuilder.buildTrunc(ValVReg, Hint);
1401}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void addFlagsUsingAttrFn(ISD::ArgFlagsTy &Flags, const std::function< bool(Attribute::AttrKind)> &AttrFn)
Helper function which updates Flags when AttrFn returns true.
static void buildCopyToRegs(MachineIRBuilder &B, ArrayRef< Register > DstRegs, Register SrcReg, LLT SrcTy, LLT PartTy, unsigned ExtendOp=TargetOpcode::G_ANYEXT)
Create a sequence of instructions to expand the value in SrcReg (of type SrcTy) to the types in DstRe...
static MachineInstrBuilder mergeVectorRegsToResultRegs(MachineIRBuilder &B, ArrayRef< Register > DstRegs, ArrayRef< Register > SrcRegs)
Pack values SrcRegs to cover the vector type result DstRegs.
static void buildCopyFromRegs(MachineIRBuilder &B, ArrayRef< Register > OrigRegs, ArrayRef< Register > Regs, LLT LLTy, LLT PartLLT, const ISD::ArgFlagsTy Flags)
Create a sequence of instructions to combine pieces split into register typed values to the original ...
static bool isCopyCompatibleType(LLT SrcTy, LLT DstTy)
Check if we can use a basic COPY instruction between the two types.
static unsigned extendOpFromFlags(llvm::ISD::ArgFlagsTy Flags)
This file describes how to lower LLVM calls to machine code calls.
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
This file declares the MachineIRBuilder class.
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
MachineInstr unsigned OpIdx
R600 Clause Merge
#define LLVM_DEBUG(...)
Definition Debug.h:114
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition ArrayRef.h:220
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:196
const T & front() const
front - Get the first element.
Definition ArrayRef.h:146
size_t size() const
size - Get the array size.
Definition ArrayRef.h:143
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:138
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:88
CCState - This class holds information needed while lowering arguments and return values.
CallingConv::ID getCallingConv() const
LLVMContext & getContext() const
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
LocInfo getLocInfo() const
bool needsCustom() const
int64_t getLocMemOffset() const
unsigned getValNo() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
MaybeAlign getRetAlign() const
Extract the alignment of the return value.
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
CallingConv::ID getCallingConv() const
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
Value * getCalledOperand() const
bool isConvergent() const
Determine if the invoke is convergent.
FunctionType * getFunctionType() const
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
AttributeList getAttributes() const
Return the attributes for this call.
LLVM_ABI bool isTailCall() const
Tests if this call site is marked as a tail call.
void insertSRetOutgoingArgument(MachineIRBuilder &MIRBuilder, const CallBase &CB, CallLoweringInfo &Info) const
For the call-base described by CB, insert the hidden sret ArgInfo to the OrigArgs field of Info.
void insertSRetLoads(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg, int FI) const
Load the returned value from the stack into virtual registers in VRegs.
bool checkReturnTypeForCallConv(MachineFunction &MF) const
Toplevel function to check the return type based on the target calling convention.
bool handleAssignments(ValueHandler &Handler, SmallVectorImpl< ArgInfo > &Args, CCState &CCState, SmallVectorImpl< CCValAssign > &ArgLocs, MachineIRBuilder &MIRBuilder, ArrayRef< Register > ThisReturnRegs={}) const
Use Handler to insert code to handle the argument/return values represented by Args.
bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF, SmallVectorImpl< ArgInfo > &InArgs, ValueAssigner &CalleeAssigner, ValueAssigner &CallerAssigner) const
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< uint64_t > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
virtual bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv, SmallVectorImpl< BaseArgInfo > &Outs, bool IsVarArg) const
This hook must be implemented to check whether the return values described by Outs can fit into the r...
virtual bool isTypeIsValidForThisReturn(EVT Ty) const
For targets which support the "returned" parameter attribute, returns true if the given type is a val...
void insertSRetIncomingArgument(const Function &F, SmallVectorImpl< ArgInfo > &SplitArgs, Register &DemoteReg, MachineRegisterInfo &MRI, const DataLayout &DL) const
Insert the hidden sret ArgInfo to the beginning of SplitArgs.
ISD::ArgFlagsTy getAttributesForArgIdx(const CallBase &Call, unsigned ArgIdx) const
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs={}) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
void insertSRetStores(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg) const
Store the return value given by VRegs into stack starting at the offset specified in DemoteReg.
void addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags, const AttributeList &Attrs, unsigned OpIdx) const
Adds flags to Flags based off of the attributes in Attrs.
bool parametersInCSRMatch(const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask, const SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ArgInfo > &OutVals) const
Check whether parameters to a call that are passed in callee saved registers are the same as from the...
void getReturnInfo(CallingConv::ID CallConv, Type *RetTy, AttributeList Attrs, SmallVectorImpl< BaseArgInfo > &Outs, const DataLayout &DL) const
Get the type and the ArgFlags for the split components of RetTy as returned by ComputeValueVTs.
bool determineAssignments(ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, CCState &CCInfo) const
Analyze the argument list in Args, using Assigner to populate CCInfo.
bool checkReturn(CCState &CCInfo, SmallVectorImpl< BaseArgInfo > &Outs, CCAssignFn *Fn) const
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
ISD::ArgFlagsTy getAttributesForReturn(const CallBase &Call) const
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
unsigned getAllocaAddrSpace() const
Definition DataLayout.h:239
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
bool isVarArg() const
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
constexpr unsigned getScalarSizeInBits() const
constexpr bool isScalar() const
constexpr LLT changeElementType(LLT NewEltTy) const
If this type is a vector, return a vector with the same number of elements but the new element type.
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr bool isPointer() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr LLT changeElementCount(ElementCount EC) const
Return a vector or scalar with the same element type and the new element count.
constexpr LLT getScalarType() const
constexpr TypeSize getSizeInBytes() const
Returns the total size of the type in bytes, i.e.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
Machine Value Type.
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
static LLVM_ABI MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
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.
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.
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Helper class to build MachineInstr.
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
std::optional< MachineInstrBuilder > materializeObjectPtrOffset(Register &Res, Register Op0, const LLT ValueTy, uint64_t Value)
Materialize and insert an instruction with appropriate flags for addressing some offset of an object,...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildAssertAlign(const DstOp &Res, const SrcOp &Op, Align AlignVal)
Build and insert Res = G_ASSERT_ALIGN Op, AlignVal.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
const DataLayout & getDataLayout() const
Register getReg(unsigned Idx) const
Get the register for the operand index.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Class to represent pointers.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
iterator insert(iterator I, T &&Elt)
void truncate(size_type N)
Like resize, but requires that N is less than size().
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const
Returns the desired alignment for ByVal or InAlloca aggregate function arguments in the caller parame...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:352
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:128
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:701
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:217
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:224
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition Analysis.cpp:119
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
void * PointerTy
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
Definition Utils.cpp:492
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:394
LLVM_ABI LLVM_READNONE LLT getCoverTy(LLT OrigTy, LLT TargetTy)
Return smallest type that covers both OrigTy and TargetTy and is multiple of TargetTy.
Definition Utils.cpp:1255
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM, bool ReturnsFirstArg=false)
Test if the given instruction is in a position to be optimized with a tail-call.
Definition Analysis.cpp:543
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1835
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
LLVM_ABI LLVM_READNONE LLT getGCDType(LLT OrigTy, LLT TargetTy)
Return a type where the total size is the greatest common divisor of OrigTy and TargetTy.
Definition Utils.cpp:1276
LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
Definition Utils.cpp:898
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
const Value * OrigValue
Optionally track the original IR value for the argument.
SmallVector< Register, 4 > Regs
unsigned OrigArgIndex
Index original Function's argument.
static const unsigned NoArgIndex
Sentinel value for implicit machine-level input arguments.
SmallVector< ISD::ArgFlagsTy, 4 > Flags
void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA) override
Provides a default implementation for argument handling.
Register buildExtensionHint(const CCValAssign &VA, Register SrcReg, LLT NarrowTy)
Insert G_ASSERT_ZEXT/G_ASSERT_SEXT or other hint instruction based on VA, returning the new register ...
Argument handling is mostly uniform between the four places that make these decisions: function forma...
virtual bool assignArg(unsigned ValNo, EVT OrigVT, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const ArgInfo &Info, ISD::ArgFlagsTy Flags, CCState &State)
Wrap call to (typically tablegenerated CCAssignFn).
void copyArgumentMemory(const ArgInfo &Arg, Register DstPtr, Register SrcPtr, const MachinePointerInfo &DstPtrInfo, Align DstAlign, const MachinePointerInfo &SrcPtrInfo, Align SrcAlign, uint64_t MemSize, CCValAssign &VA) const
Do a memory copy of MemSize bytes from SrcPtr to DstPtr.
virtual Register getStackAddress(uint64_t MemSize, int64_t Offset, MachinePointerInfo &MPO, ISD::ArgFlagsTy Flags)=0
Materialize a VReg containing the address of the specified stack-based object.
virtual LLT getStackValueStoreType(const DataLayout &DL, const CCValAssign &VA, ISD::ArgFlagsTy Flags) const
Return the in-memory size to write for the argument at VA.
bool isIncomingArgumentHandler() const
Returns true if the handler is dealing with incoming arguments, i.e.
virtual void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)=0
The specified value has been assigned to a stack location.
Register extendRegister(Register ValReg, const CCValAssign &VA, unsigned MaxSizeBits=0)
Extend a register to the location type given in VA, capped at extending to at most MaxSize bits.
virtual unsigned assignCustomValue(ArgInfo &Arg, ArrayRef< CCValAssign > VAs, std::function< void()> *Thunk=nullptr)
Handle custom values, which may be passed into one or more of VAs.
virtual void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA)=0
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
Extended Value Type.
Definition ValueTypes.h:35
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
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:106