LLVM 23.0.0git
FunctionLoweringInfo.cpp
Go to the documentation of this file.
1//===-- FunctionLoweringInfo.cpp ------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This implements routines for translating functions from LLVM IR into
10// Machine IR.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/APInt.h"
28#include "llvm/IR/Constants.h"
29#include "llvm/IR/DataLayout.h"
31#include "llvm/IR/Function.h"
34#include "llvm/IR/Intrinsics.h"
35#include "llvm/Support/Debug.h"
38#include <algorithm>
39using namespace llvm;
40
41#define DEBUG_TYPE "function-lowering-info"
42
43/// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by
44/// PHI nodes or outside of the basic block that defines it, or used by a
45/// switch or atomic instruction, which may expand to multiple basic blocks.
47 if (I->use_empty()) return false;
48 if (isa<PHINode>(I)) return true;
49 const BasicBlock *BB = I->getParent();
50 for (const User *U : I->users())
51 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
52 return true;
53
54 return false;
55}
56
58 // For the users of the source value being used for compare instruction, if
59 // the number of signed predicate is greater than unsigned predicate, we
60 // prefer to use SIGN_EXTEND.
61 //
62 // With this optimization, we would be able to reduce some redundant sign or
63 // zero extension instruction, and eventually more machine CSE opportunities
64 // can be exposed.
65 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
66 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
67 for (const Use &U : I->uses()) {
68 if (const auto *CI = dyn_cast<CmpInst>(U.getUser())) {
69 NumOfSigned += CI->isSigned();
70 NumOfUnsigned += CI->isUnsigned();
71 }
72 if (const auto *CallI = dyn_cast<CallBase>(U.getUser())) {
73 if (!CallI->isArgOperand(&U))
74 continue;
75 unsigned ArgNo = CallI->getArgOperandNo(&U);
76 NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
77 NumOfSigned += CallI->paramHasAttr(ArgNo, Attribute::SExt);
78 }
79 }
80 if (NumOfSigned > NumOfUnsigned)
81 ExtendKind = ISD::SIGN_EXTEND;
82
83 return ExtendKind;
84}
85
87 SelectionDAG *DAG) {
88 Fn = &fn;
89 MF = &mf;
90 TLI = MF->getSubtarget().getTargetLowering();
91 RegInfo = &MF->getRegInfo();
92 const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
93 UA = DAG->getUniformityInfo();
94
95 // Check whether the function can return without sret-demotion.
97 CallingConv::ID CC = Fn->getCallingConv();
98
99 GetReturnInfo(CC, Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI,
100 mf.getDataLayout());
102 TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext(), Fn->getReturnType());
103
104 // If this personality uses funclets, we need to do a bit more work.
107 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr);
108 if (isFuncletEHPersonality(Personality)) {
109 // Calculate state numbers if we haven't already.
110 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
111 if (Personality == EHPersonality::MSVC_CXX)
113 else if (isAsynchronousEHPersonality(Personality))
114 calculateSEHStateNumbers(&fn, EHInfo);
115 else if (Personality == EHPersonality::CoreCLR)
116 calculateClrEHStateNumbers(&fn, EHInfo);
117
118 // Map all BB references in the WinEH data to MBBs.
119 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
120 for (WinEHHandlerType &H : TBME.HandlerArray) {
121 if (const AllocaInst *AI = H.CatchObj.Alloca)
122 CatchObjects[AI].push_back(&H.CatchObj.FrameIndex);
123 else
124 H.CatchObj.FrameIndex = INT_MAX;
125 }
126 }
127 }
128
129 // Initialize the mapping of values to registers. This is only set up for
130 // instruction values that are used outside of the block that defines
131 // them.
132 const Align StackAlign = TFI->getStackAlign();
133 for (const BasicBlock &BB : *Fn) {
134 for (const Instruction &I : BB) {
135 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
136 Align Alignment = AI->getAlign();
137
138 // Static allocas can be folded into the initial stack frame
139 // adjustment. For targets that don't realign the stack, don't
140 // do this if there is an extra alignment requirement.
141 if (AI->isStaticAlloca() &&
142 (TFI->isStackRealignable() || (Alignment <= StackAlign))) {
143 TypeSize AllocaSize = AI->getAllocationSize(MF->getDataLayout())
144 .value_or(TypeSize::getZero());
145 uint64_t TySize = AllocaSize.getKnownMinValue();
146 if (TySize == 0)
147 TySize = 1; // Don't create zero-sized stack objects.
148 int FrameIndex = INT_MAX;
149 auto Iter = CatchObjects.find(AI);
150 if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) {
151 FrameIndex = MF->getFrameInfo().CreateFixedObject(
152 TySize, 0, /*IsImmutable=*/false, /*isAliased=*/true);
153 MF->getFrameInfo().setObjectAlignment(FrameIndex, Alignment);
154 } else {
155 FrameIndex = MF->getFrameInfo().CreateStackObject(TySize, Alignment,
156 false, AI);
157 }
158
159 // Scalable vectors and structures that contain scalable vectors may
160 // need a special StackID to distinguish them from other (fixed size)
161 // stack objects.
162 if (AllocaSize.isScalable())
163 MF->getFrameInfo().setStackID(FrameIndex,
165
166 StaticAllocaMap[AI] = FrameIndex;
167 // Update the catch handler information.
168 if (Iter != CatchObjects.end()) {
169 for (int *CatchObjPtr : Iter->second)
170 *CatchObjPtr = FrameIndex;
171 }
172 } else {
173 // FIXME: Overaligned static allocas should be grouped into
174 // a single dynamic allocation instead of using a separate
175 // stack allocation for each one.
176 // Inform the Frame Information that we have variable-sized objects.
177 MF->getFrameInfo().CreateVariableSizedObject(
178 Alignment <= StackAlign ? Align(1) : Alignment, AI);
179 }
180 } else if (auto *Call = dyn_cast<CallBase>(&I)) {
181 // Look for inline asm that clobbers the SP register.
182 if (Call->isInlineAsm()) {
183 Register SP = TLI->getStackPointerRegisterToSaveRestore();
184 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
185 std::vector<TargetLowering::AsmOperandInfo> Ops =
186 TLI->ParseConstraints(Fn->getDataLayout(), TRI,
187 *Call);
189 if (Op.Type == InlineAsm::isClobber) {
190 // Clobbers don't have SDValue operands, hence SDValue().
191 TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
192 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
193 TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode,
194 Op.ConstraintVT);
195 if (PhysReg.first == SP)
196 MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
197 }
198 }
199 }
200 if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
201 switch (II->getIntrinsicID()) {
202 case Intrinsic::vastart:
203 // Look for calls to the @llvm.va_start intrinsic. We can omit
204 // some prologue boilerplate for variadic functions that don't
205 // examine their arguments.
206 MF->getFrameInfo().setHasVAStart(true);
207 break;
208 case Intrinsic::fake_use:
209 // Look for llvm.fake.uses, so that we can remove loads into fake
210 // uses later if necessary.
211 MF->setHasFakeUses(true);
212 break;
213 default:
214 break;
215 }
216 }
217
218 // If we have a musttail call in a variadic function, we need to ensure
219 // we forward implicit register parameters.
220 if (const auto *CI = dyn_cast<CallInst>(&I)) {
221 if (CI->isMustTailCall() && Fn->isVarArg())
222 MF->getFrameInfo().setHasMustTailInVarArgFunc(true);
223 }
224
225 // Determine if there is a call to setjmp in the machine function.
226 if (Call->hasFnAttr(Attribute::ReturnsTwice))
227 MF->setExposesReturnsTwice(true);
228 }
229
230 // Mark values used outside their block as exported, by allocating
231 // a virtual register for them.
235
236 // Decide the preferred extend type for a value. This iterates over all
237 // users and therefore isn't cheap, so don't do this at O0.
240 }
241 }
242
243 // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This
244 // also creates the initial PHI MachineInstrs, though none of the input
245 // operands are populated.
246 MBBMap.resize(Fn->getMaxBlockNumber());
247 for (const BasicBlock &BB : *Fn) {
248 // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks
249 // are really data, and no instructions can live here.
250 if (BB.isEHPad()) {
251 BasicBlock::const_iterator PadInst = BB.getFirstNonPHIIt();
252 // If this is a non-landingpad EH pad, mark this function as using
253 // funclets.
254 // FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid
255 // setting this in such cases in order to improve frame layout.
256 if (!isa<LandingPadInst>(PadInst)) {
257 MF->setHasEHScopes(true);
258 MF->setHasEHFunclets(true);
259 MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
260 }
261 if (isa<CatchSwitchInst>(PadInst)) {
262 assert(BB.begin() == PadInst &&
263 "WinEHPrepare failed to remove PHIs from imaginary BBs");
264 continue;
265 }
266 if (isa<FuncletPadInst>(PadInst) &&
267 Personality != EHPersonality::Wasm_CXX)
268 assert(BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
269 }
270
272 MBBMap[BB.getNumber()] = MBB;
273 MF->push_back(MBB);
274
275 // Transfer the address-taken flag. This is necessary because there could
276 // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only
277 // the first one should be marked.
278 // Only mark the block if the BlockAddress actually has users. The
279 // hasAddressTaken flag may be stale if the BlockAddress was optimized away
280 // but the constant still exists in the uniquing table.
281 if (BB.hasAddressTaken()) {
282 if (BlockAddress *BA = BlockAddress::lookup(&BB))
283 if (!BA->hasZeroLiveUses())
284 MBB->setAddressTakenIRBlock(const_cast<BasicBlock *>(&BB));
285 }
286
287 // Mark landing pad blocks.
288 if (BB.isEHPad())
289 MBB->setIsEHPad();
290
291 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
292 // appropriate.
293 for (const PHINode &PN : BB.phis()) {
294 if (PN.use_empty())
295 continue;
296
297 // Skip empty types
298 if (PN.getType()->isEmptyTy())
299 continue;
300
301 DebugLoc DL = PN.getDebugLoc();
302 Register PHIReg = ValueMap[&PN];
303 assert(PHIReg && "PHI node does not have an assigned virtual register!");
304
305 SmallVector<EVT, 4> ValueVTs;
306 ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs);
307 for (EVT VT : ValueVTs) {
308 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
309 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
310 for (unsigned i = 0; i != NumRegisters; ++i)
311 BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i);
312 PHIReg += NumRegisters;
313 }
314 }
315 }
316
317 if (isFuncletEHPersonality(Personality)) {
318 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
319
320 // Map all BB references in the WinEH data to MBBs.
321 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
322 for (WinEHHandlerType &H : TBME.HandlerArray) {
323 if (H.Handler)
324 H.Handler = getMBB(cast<const BasicBlock *>(H.Handler));
325 }
326 }
327 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
328 if (UME.Cleanup)
330 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap)
331 UME.Handler = getMBB(cast<const BasicBlock *>(UME.Handler));
332 for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap)
334 }
335}
336
337/// clear - Clear out all the function-specific state. This returns this
338/// FunctionLoweringInfo to an empty state, ready to be used for a
339/// different function.
341 MBBMap.clear();
342 ValueMap.clear();
343 VirtReg2Value.clear();
344 StaticAllocaMap.clear();
345 LiveOutRegInfo.clear();
346 VisitedBBs.clear();
347 ArgDbgValues.clear();
348 DescribedArgs.clear();
349 ByValArgFrameIndexMap.clear();
350 RegFixups.clear();
351 RegsWithFixups.clear();
352 StatepointStackSlots.clear();
354 PreferredExtendType.clear();
356}
357
358/// CreateReg - Allocate a single virtual register for the given type.
360 return RegInfo->createVirtualRegister(TLI->getRegClassFor(VT, isDivergent));
361}
362
363/// CreateRegs - Allocate the appropriate number of virtual registers of
364/// the correctly promoted or expanded types. Assign these registers
365/// consecutive vreg numbers and return the first assigned number.
366///
367/// In the case that the given value has struct or array type, this function
368/// will assign registers for each member or element.
369///
371 SmallVector<EVT, 4> ValueVTs;
372 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
373
374 Register FirstReg;
375 for (EVT ValueVT : ValueVTs) {
376 MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT);
377
378 unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT);
379 for (unsigned i = 0; i != NumRegs; ++i) {
380 Register R = CreateReg(RegisterVT, isDivergent);
381 if (!FirstReg) FirstReg = R;
382 }
383 }
384 return FirstReg;
385}
386
388 return CreateRegs(V->getType(), UA && UA->isDivergent(V) &&
389 !TLI->requiresUniformRegister(*MF, V));
390}
391
393 // Tokens live in vregs only when used for convergence control.
394 if (V->getType()->isTokenTy() && !isa<ConvergenceControlInst>(V))
395 return 0;
396 Register &R = ValueMap[V];
397 assert(R == Register() && "Already initialized this value register!");
398 assert(VirtReg2Value.empty());
399 return R = CreateRegs(V);
400}
401
402/// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
403/// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
404/// the register's LiveOutInfo is for a smaller bit width, it is extended to
405/// the larger bit width by zero extension. The bit width must be no smaller
406/// than the LiveOutInfo's existing bit width.
409 if (!LiveOutRegInfo.inBounds(Reg))
410 return nullptr;
411
412 LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
413 if (!LOI->IsValid)
414 return nullptr;
415
416 if (BitWidth > LOI->Known.getBitWidth()) {
417 LOI->NumSignBits = 1;
418 LOI->Known = LOI->Known.anyext(BitWidth);
419 }
420
421 return LOI;
422}
423
424/// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
425/// register based on the LiveOutInfo of its operands.
427 Type *Ty = PN->getType();
428 if (!Ty->isIntegerTy())
429 return;
430
431 SmallVector<EVT, 1> ValueVTs;
432 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
433 assert(ValueVTs.size() == 1 &&
434 "PHIs with non-vector integer types should have a single VT.");
435 EVT IntVT = ValueVTs[0];
436
437 unsigned NumRegisters = TLI->getNumRegisters(PN->getContext(), IntVT);
438 // FIXME: Support multiple registers for big endian targets.
439 if (NumRegisters != 1 && MF->getDataLayout().isBigEndian())
440 return;
441 IntVT = TLI->getRegisterType(PN->getContext(), IntVT);
442 unsigned BitWidth = IntVT.getSizeInBits();
443
444 auto It = ValueMap.find(PN);
445 if (It == ValueMap.end())
446 return;
447
448 Register BaseReg = It->second;
449 if (!BaseReg)
450 return;
451 assert(BaseReg.isVirtual() && "Expected a virtual reg");
452
453 for (unsigned RegIdx = 0; RegIdx < NumRegisters; ++RegIdx) {
454 // Split registers are assigned sequentially.
455 Register DestReg = BaseReg.id() + RegIdx;
456 LiveOutRegInfo.grow(DestReg);
457 LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg];
458
459 Value *V = PN->getIncomingValue(0);
460 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
461 DestLOI.NumSignBits = 1;
462 DestLOI.Known = KnownBits(BitWidth);
463 continue;
464 }
465
466 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
467 APInt Val;
468 if (TLI->signExtendConstant(CI))
469 Val = CI->getValue().sext(BitWidth * NumRegisters);
470 else
471 Val = CI->getValue().zext(BitWidth * NumRegisters);
472 APInt Extracted = Val.extractBits(BitWidth, BitWidth * RegIdx);
473 DestLOI.NumSignBits = Extracted.getNumSignBits();
474 DestLOI.Known = KnownBits::makeConstant(Extracted);
475 } else {
476 assert(ValueMap.count(V) &&
477 "V should have been placed in ValueMap when its"
478 "CopyToReg node was created.");
479 Register SrcReg = ValueMap[V];
480 if (!SrcReg.isVirtual()) {
481 DestLOI.IsValid = false;
482 continue;
483 }
484 // Split registers are assigned sequentially.
485 SrcReg = SrcReg.id() + RegIdx;
486 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
487 if (!SrcLOI) {
488 DestLOI.IsValid = false;
489 continue;
490 }
491 DestLOI = *SrcLOI;
492 }
493
494 assert(DestLOI.Known.Zero.getBitWidth() == BitWidth &&
495 DestLOI.Known.One.getBitWidth() == BitWidth &&
496 "Masks should have the same bit width as the type.");
497
498 for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) {
499 Value *V = PN->getIncomingValue(i);
500 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
501 DestLOI.NumSignBits = 1;
502 DestLOI.Known = KnownBits(BitWidth);
503 break;
504 }
505
506 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
507 APInt Val;
508 if (TLI->signExtendConstant(CI))
509 Val = CI->getValue().sext(BitWidth * NumRegisters);
510 else
511 Val = CI->getValue().zext(BitWidth * NumRegisters);
512 APInt Extracted = Val.extractBits(BitWidth, BitWidth * RegIdx);
513 DestLOI.NumSignBits =
514 std::min(DestLOI.NumSignBits, Extracted.getNumSignBits());
515 DestLOI.Known =
516 DestLOI.Known.intersectWith(KnownBits::makeConstant(Extracted));
517 continue;
518 }
519
520 assert(ValueMap.count(V) && "V should have been placed in ValueMap when "
521 "its CopyToReg node was created.");
522 Register SrcReg = ValueMap[V];
523 if (!SrcReg.isVirtual()) {
524 DestLOI.IsValid = false;
525 break;
526 }
527 // Split registers are assigned sequentially.
528 SrcReg = SrcReg.id() + RegIdx;
529 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
530 if (!SrcLOI) {
531 DestLOI.IsValid = false;
532 break;
533 }
534 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits);
535 DestLOI.Known = DestLOI.Known.intersectWith(SrcLOI->Known);
536 }
537 }
538}
539
540/// setArgumentFrameIndex - Record frame index for the byval
541/// argument. This overrides previous frame index entry for this argument,
542/// if any.
547
548/// getArgumentFrameIndex - Get frame index for the byval argument.
549/// If the argument does not have any assigned frame index then 0 is
550/// returned.
552 auto I = ByValArgFrameIndexMap.find(A);
553 if (I != ByValArgFrameIndexMap.end())
554 return I->second;
555 LLVM_DEBUG(dbgs() << "Argument does not have assigned frame index!\n");
556 return INT_MAX;
557}
558
560 const Value *CPI, const TargetRegisterClass *RC) {
561 MachineRegisterInfo &MRI = MF->getRegInfo();
562 auto I = CatchPadExceptionPointers.insert({CPI, 0});
563 Register &VReg = I.first->second;
564 if (I.second)
565 VReg = MRI.createVirtualRegister(RC);
566 assert(VReg && "null vreg in exception pointer table!");
567 return VReg;
568}
569
570const Value *
572 if (VirtReg2Value.empty()) {
573 SmallVector<EVT, 4> ValueVTs;
574 for (auto &P : ValueMap) {
575 ValueVTs.clear();
576 ComputeValueVTs(*TLI, Fn->getDataLayout(),
577 P.first->getType(), ValueVTs);
578 Register Reg = P.second;
579 for (EVT VT : ValueVTs) {
580 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
581 for (unsigned i = 0, e = NumRegisters; i != e; ++i)
582 VirtReg2Value[Reg++] = P.first;
583 }
584 }
585 }
586 return VirtReg2Value.lookup(Vreg);
587}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static ISD::NodeType getPreferredExtendForValue(const Instruction *I)
static bool isUsedOutsideOfDefiningBlock(const Instruction *I)
isUsedOutsideOfDefiningBlock - Return true if this instruction is used by PHI nodes or outside of the...
const HexagonInstrInfo * TII
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
#define H(x, y, z)
Definition MD5.cpp:56
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
uint64_t IntrinsicInst * II
#define P(N)
#define LLVM_DEBUG(...)
Definition Debug.h:114
This file describes how to lower LLVM code to machine code.
LLVM IR instance of the generic uniformity analysis.
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1054
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1511
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition APInt.h:1651
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
Definition APInt.cpp:1027
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:482
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstListType::const_iterator const_iterator
Definition BasicBlock.h:171
The address of a basic block.
Definition Constants.h:1065
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
A debug info location.
Definition DebugLoc.h:123
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:178
iterator end()
Definition DenseMap.h:81
Register CreateRegs(const Value *V)
SmallPtrSet< const DbgVariableRecord *, 8 > PreprocessedDVRDeclares
Collection of dbg_declare instructions handled after argument lowering and before ISel proper.
void clear()
clear - Clear out all the function-specific state.
MachineBasicBlock * getMBB(const BasicBlock *BB) const
DenseSet< Register > RegsWithFixups
void setArgumentFrameIndex(const Argument *A, int FI)
setArgumentFrameIndex - Record frame index for the byval argument.
SmallVector< bool > VisitedBBs
The set of basic blocks visited thus far by instruction selection.
BitVector DescribedArgs
Bitvector with a bit set if corresponding argument is described in ArgDbgValues.
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block.
DenseMap< const Instruction *, StatepointSpillMapTy > StatepointRelocationMaps
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
const LiveOutInfo * GetLiveOutRegInfo(Register Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
Register InitializeRegForValue(const Value *V)
DenseMap< const Value *, Register > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
SmallVector< unsigned, 50 > StatepointStackSlots
StatepointStackSlots - A list of temporary stack slots (frame indices) used to spill values at a stat...
void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG)
set - Initialize this FunctionLoweringInfo with the given Function and its associated MachineFunction...
MachineBasicBlock * MBB
MBB - The current block.
DenseMap< const Argument *, int > ByValArgFrameIndexMap
ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
DenseMap< Register, Register > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
SmallVector< MachineBasicBlock * > MBBMap
A mapping from LLVM basic block number to their machine block.
const Value * getValueFromVirtualReg(Register Vreg)
This method is called from TargetLowerinInfo::isSDNodeSourceOfDivergence to get the Value correspondi...
DenseMap< Register, const Value * > VirtReg2Value
VirtReg2Value map is needed by the Divergence Analysis driven instruction selection.
MachineRegisterInfo * RegInfo
Register CreateReg(MVT VT, bool isDivergent=false)
CreateReg - Allocate a single virtual register for the given type.
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
Register getCatchPadExceptionPointerVReg(const Value *CPI, const TargetRegisterClass *RC)
DenseMap< const Value *, Register > CatchPadExceptionPointers
Track virtual registers created for exception pointers.
Machine Value Type.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
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...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr unsigned id() const
Definition Register.h:100
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const UniformityInfo * getUniformityInfo() const
CodeGenOptLevel getOptLevel() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Information about stack frame layout on the target.
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
virtual TargetStackID::Value getStackIDForScalableVectors() const
Returns the StackID that scalable vectors should be associated with.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static constexpr TypeSize getZero()
Definition TypeSize.h:349
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
CallInst * Call
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:41
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:853
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:844
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags,...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
DWARFExpression::Operation Op
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
MBBOrBasicBlock Cleanup
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:381
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition KnownBits.h:315
unsigned getBitWidth() const
Get the bit width of this value.
Definition KnownBits.h:44
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition KnownBits.h:325
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
Definition KnownBits.h:171
Similar to CxxUnwindMapEntry, but supports SEH filters.
This contains information for each constraint that we are lowering.
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
SmallVector< WinEHHandlerType, 1 > HandlerArray