LLVM 24.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"
32#include "llvm/IR/Function.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/Module.h"
37#include "llvm/Support/Debug.h"
41#include <algorithm>
42using namespace llvm;
43
44#define DEBUG_TYPE "function-lowering-info"
45
46/// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by
47/// PHI nodes or outside of the basic block that defines it, or used by a
48/// switch or atomic instruction, which may expand to multiple basic blocks.
50 if (I->use_empty()) return false;
51 if (isa<PHINode>(I)) return true;
52 const BasicBlock *BB = I->getParent();
53 for (const User *U : I->users())
54 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
55 return true;
56
57 return false;
58}
59
61 // For the users of the source value being used for compare instruction, if
62 // the number of signed predicate is greater than unsigned predicate, we
63 // prefer to use SIGN_EXTEND.
64 //
65 // With this optimization, we would be able to reduce some redundant sign or
66 // zero extension instruction, and eventually more machine CSE opportunities
67 // can be exposed.
68 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
69 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
70 for (const Use &U : I->uses()) {
71 if (const auto *CI = dyn_cast<CmpInst>(U.getUser())) {
72 NumOfSigned += CI->isSigned();
73 NumOfUnsigned += CI->isUnsigned();
74 }
75 if (const auto *CallI = dyn_cast<CallBase>(U.getUser())) {
76 if (!CallI->isArgOperand(&U))
77 continue;
78 unsigned ArgNo = CallI->getArgOperandNo(&U);
79 NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
80 NumOfSigned += CallI->paramHasAttr(ArgNo, Attribute::SExt);
81 }
82 }
83 if (NumOfSigned > NumOfUnsigned)
84 ExtendKind = ISD::SIGN_EXTEND;
85
86 return ExtendKind;
87}
88
90 SelectionDAG *DAG) {
91 Fn = &fn;
92 MF = &mf;
93 TLI = MF->getSubtarget().getTargetLowering();
94 RegInfo = &MF->getRegInfo();
95 const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
96 UA = DAG->getUniformityInfo();
97 // Prefer the "exception-model" module flag, else the TargetOptions default.
98 ExceptionModel = Fn->getParent()->getExceptionModel();
100 ExceptionModel = MF->getTarget().getExceptionModel();
101
102 // Check whether the function can return without sret-demotion.
104 CallingConv::ID CC = Fn->getCallingConv();
105
106 GetReturnInfo(CC, Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI,
107 mf.getDataLayout());
109 TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext(), Fn->getReturnType());
110
111 // If this personality uses funclets, we need to do a bit more work.
114 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr);
115 if (isFuncletEHPersonality(Personality)) {
116 // Calculate state numbers if we haven't already.
117 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
118 if (Personality == EHPersonality::MSVC_CXX)
120 else if (isAsynchronousEHPersonality(Personality))
121 calculateSEHStateNumbers(&fn, EHInfo);
122 else if (Personality == EHPersonality::CoreCLR)
123 calculateClrEHStateNumbers(&fn, EHInfo);
124
125 // Map all BB references in the WinEH data to MBBs.
126 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
127 for (WinEHHandlerType &H : TBME.HandlerArray) {
128 if (const AllocaInst *AI = H.CatchObj.Alloca)
129 CatchObjects[AI].push_back(&H.CatchObj.FrameIndex);
130 else
131 H.CatchObj.FrameIndex = INT_MAX;
132 }
133 }
134 }
135
136 // Initialize the mapping of values to registers. This is only set up for
137 // instruction values that are used outside of the block that defines
138 // them.
139 const Align StackAlign = TFI->getStackAlign();
140 for (const BasicBlock &BB : *Fn) {
141 for (const Instruction &I : BB) {
142 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
143 Align Alignment = AI->getAlign();
144
145 // Static allocas can be folded into the initial stack frame
146 // adjustment. For targets that don't realign the stack, don't
147 // do this if there is an extra alignment requirement.
148 if (AI->isStaticAlloca() &&
149 (TFI->isStackRealignable() || (Alignment <= StackAlign))) {
150 TypeSize AllocaSize = AI->getAllocationSize(MF->getDataLayout())
151 .value_or(TypeSize::getZero());
152 uint64_t TySize = AllocaSize.getKnownMinValue();
153 if (TySize == 0)
154 TySize = 1; // Don't create zero-sized stack objects.
155 int FrameIndex = INT_MAX;
156 auto Iter = CatchObjects.find(AI);
157 if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) {
158 FrameIndex = MF->getFrameInfo().CreateFixedObject(
159 TySize, 0, /*IsImmutable=*/false, /*isAliased=*/true);
160 MF->getFrameInfo().setObjectAlignment(FrameIndex, Alignment);
161 } else {
162 FrameIndex = MF->getFrameInfo().CreateStackObject(TySize, Alignment,
163 false, AI);
164 }
165
166 // Scalable vectors and structures that contain scalable vectors may
167 // need a special StackID to distinguish them from other (fixed size)
168 // stack objects.
169 if (AllocaSize.isScalable())
170 MF->getFrameInfo().setStackID(FrameIndex,
172
173 StaticAllocaMap[AI] = FrameIndex;
174 // Update the catch handler information.
175 if (Iter != CatchObjects.end()) {
176 for (int *CatchObjPtr : Iter->second)
177 *CatchObjPtr = FrameIndex;
178 }
179 } else {
180 // FIXME: Overaligned static allocas should be grouped into
181 // a single dynamic allocation instead of using a separate
182 // stack allocation for each one.
183 // Inform the Frame Information that we have variable-sized objects.
184 MF->getFrameInfo().CreateVariableSizedObject(
185 Alignment <= StackAlign ? Align(1) : Alignment, AI);
186 }
187 } else if (auto *Call = dyn_cast<CallBase>(&I)) {
188 // Look for inline asm that clobbers the SP register.
189 if (Call->isInlineAsm()) {
190 Register SP = TLI->getStackPointerRegisterToSaveRestore();
191 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
192 std::vector<TargetLowering::AsmOperandInfo> Ops =
193 TLI->ParseConstraints(Fn->getDataLayout(), TRI,
194 *Call);
196 if (Op.Type == InlineAsm::isClobber) {
197 // Clobbers don't have SDValue operands, hence SDValue().
198 TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
199 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
200 TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode,
201 Op.ConstraintVT);
202 if (PhysReg.first == SP)
203 MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
204 }
205 }
206 }
207 if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
208 switch (II->getIntrinsicID()) {
209 case Intrinsic::vastart:
210 // Look for calls to the @llvm.va_start intrinsic. We can omit
211 // some prologue boilerplate for variadic functions that don't
212 // examine their arguments.
213 MF->getFrameInfo().setHasVAStart(true);
214 break;
215 case Intrinsic::fake_use:
216 // Look for llvm.fake.uses, so that we can remove loads into fake
217 // uses later if necessary.
218 MF->setHasFakeUses(true);
219 break;
220 default:
221 break;
222 }
223 }
224
225 // If we have a musttail call in a variadic function, we need to ensure
226 // we forward implicit register parameters.
227 if (const auto *CI = dyn_cast<CallInst>(&I)) {
228 if (CI->isMustTailCall() && Fn->isVarArg())
229 MF->getFrameInfo().setHasMustTailInVarArgFunc(true);
230 }
231
232 // Determine if there is a call to setjmp in the machine function.
233 if (Call->hasFnAttr(Attribute::ReturnsTwice))
234 MF->setExposesReturnsTwice(true);
235 }
236
237 // Mark values used outside their block as exported, by allocating
238 // a virtual register for them.
242
243 // Decide the preferred extend type for a value. This iterates over all
244 // users and therefore isn't cheap, so don't do this at O0.
247 }
248 }
249
250 // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This
251 // also creates the initial PHI MachineInstrs, though none of the input
252 // operands are populated.
253 MBBMap.resize(Fn->getMaxBlockNumber());
254 for (const BasicBlock &BB : *Fn) {
255 // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks
256 // are really data, and no instructions can live here.
257 if (BB.isEHPad()) {
258 BasicBlock::const_iterator PadInst = BB.getFirstNonPHIIt();
259 // If this is a non-landingpad EH pad, mark this function as using
260 // funclets.
261 // FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid
262 // setting this in such cases in order to improve frame layout.
263 if (!isa<LandingPadInst>(PadInst)) {
264 MF->setHasEHScopes(true);
265 MF->setHasEHFunclets(true);
266 MF->getFrameInfo().setHasOpaqueSPAdjustment(true);
267 }
268 if (isa<CatchSwitchInst>(PadInst)) {
269 assert(BB.begin() == PadInst &&
270 "WinEHPrepare failed to remove PHIs from imaginary BBs");
271 continue;
272 }
273 if (isa<FuncletPadInst>(PadInst) &&
274 Personality != EHPersonality::Wasm_CXX &&
275 Personality != EHPersonality::Wasm_D)
276 assert(BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
277 }
278
280 MBBMap[BB.getNumber()] = MBB;
281 MF->push_back(MBB);
282
283 // Transfer the address-taken flag. This is necessary because there could
284 // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only
285 // the first one should be marked.
286 // Only mark the block if the BlockAddress actually has users. The
287 // hasAddressTaken flag may be stale if the BlockAddress was optimized away
288 // but the constant still exists in the uniquing table.
289 if (BB.hasAddressTaken()) {
290 if (BlockAddress *BA = BlockAddress::lookup(&BB))
291 if (!BA->hasZeroLiveUses())
292 MBB->setAddressTakenIRBlock(const_cast<BasicBlock *>(&BB));
293 }
294
295 // Mark landing pad blocks.
296 if (BB.isEHPad())
297 MBB->setIsEHPad();
298
299 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
300 // appropriate.
301 for (const PHINode &PN : BB.phis()) {
302 if (PN.use_empty())
303 continue;
304
305 // Skip empty types
306 if (PN.getType()->isEmptyTy())
307 continue;
308
309 DebugLoc DL = PN.getDebugLoc();
310 Register PHIReg = ValueMap[&PN];
311 assert(PHIReg && "PHI node does not have an assigned virtual register!");
312
313 SmallVector<EVT, 4> ValueVTs;
314 ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs);
315 for (EVT VT : ValueVTs) {
316 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
317 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
318 for (unsigned i = 0; i != NumRegisters; ++i)
319 BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i);
320 PHIReg += NumRegisters;
321 }
322 }
323 }
324
325 if (isFuncletEHPersonality(Personality)) {
326 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
327
328 // Map all BB references in the WinEH data to MBBs.
329 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
330 for (WinEHHandlerType &H : TBME.HandlerArray) {
331 if (H.Handler)
332 H.Handler = getMBB(cast<const BasicBlock *>(H.Handler));
333 }
334 }
335 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
336 if (UME.Cleanup)
338 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap)
339 UME.Handler = getMBB(cast<const BasicBlock *>(UME.Handler));
340 for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap)
342 }
343}
344
345/// clear - Clear out all the function-specific state. This returns this
346/// FunctionLoweringInfo to an empty state, ready to be used for a
347/// different function.
349 MBBMap.clear();
350 ValueMap.clear();
351 VirtReg2Value.clear();
352 StaticAllocaMap.clear();
353 LiveOutRegInfo.clear();
354 VisitedBBs.clear();
355 ArgDbgValues.clear();
356 DescribedArgs.clear();
357 ByValArgFrameIndexMap.clear();
358 RegFixups.clear();
359 RegsWithFixups.clear();
360 StatepointStackSlots.clear();
362 PreferredExtendType.clear();
364}
365
366/// CreateReg - Allocate a single virtual register for the given type.
368 return RegInfo->createVirtualRegister(TLI->getRegClassFor(VT, isDivergent));
369}
370
371/// CreateRegs - Allocate the appropriate number of virtual registers of
372/// the correctly promoted or expanded types. Assign these registers
373/// consecutive vreg numbers and return the first assigned number.
374///
375/// In the case that the given value has struct or array type, this function
376/// will assign registers for each member or element.
377///
379 SmallVector<EVT, 4> ValueVTs;
380 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
381
382 Register FirstReg;
383 for (EVT ValueVT : ValueVTs) {
384 MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT);
385
386 unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT);
387 for (unsigned i = 0; i != NumRegs; ++i) {
388 Register R = CreateReg(RegisterVT, isDivergent);
389 if (!FirstReg) FirstReg = R;
390 }
391 }
392 return FirstReg;
393}
394
396 return CreateRegs(V->getType(), UA && UA->isDivergentAtDef(V) &&
397 !TLI->requiresUniformRegister(*MF, V));
398}
399
401 // Tokens live in vregs only when used for convergence control.
402 if (V->getType()->isTokenTy() && !isa<ConvergenceControlInst>(V))
403 return 0;
404 Register &R = ValueMap[V];
405 assert(R == Register() && "Already initialized this value register!");
406 assert(VirtReg2Value.empty());
407 return R = CreateRegs(V);
408}
409
410/// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
411/// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
412/// the register's LiveOutInfo is for a smaller bit width, it is extended to
413/// the larger bit width by zero extension. The bit width must be no smaller
414/// than the LiveOutInfo's existing bit width.
417 if (!LiveOutRegInfo.inBounds(Reg))
418 return nullptr;
419
420 LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
421 if (!LOI->IsValid)
422 return nullptr;
423
424 if (BitWidth > LOI->Known.getBitWidth()) {
425 LOI->NumSignBits = 1;
426 LOI->Known = LOI->Known.anyext(BitWidth);
427 }
428
429 return LOI;
430}
431
432/// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
433/// register based on the LiveOutInfo of its operands.
435 Type *Ty = PN->getType();
436 if (!Ty->isIntegerTy())
437 return;
438
439 SmallVector<EVT, 1> ValueVTs;
440 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
441 assert(ValueVTs.size() == 1 &&
442 "PHIs with non-vector integer types should have a single VT.");
443 EVT IntVT = ValueVTs[0];
444
445 unsigned NumRegisters = TLI->getNumRegisters(PN->getContext(), IntVT);
446 // FIXME: Support multiple registers for big endian targets.
447 if (NumRegisters != 1 && MF->getDataLayout().isBigEndian())
448 return;
449 IntVT = TLI->getRegisterType(PN->getContext(), IntVT);
450 unsigned BitWidth = IntVT.getSizeInBits();
451
452 auto It = ValueMap.find(PN);
453 if (It == ValueMap.end())
454 return;
455
456 Register BaseReg = It->second;
457 if (!BaseReg)
458 return;
459 assert(BaseReg.isVirtual() && "Expected a virtual reg");
460
461 for (unsigned RegIdx = 0; RegIdx < NumRegisters; ++RegIdx) {
462 // Split registers are assigned sequentially.
463 Register DestReg = BaseReg.id() + RegIdx;
464 LiveOutRegInfo.grow(DestReg);
465 LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg];
466
467 Value *V = PN->getIncomingValue(0);
468 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
469 DestLOI.NumSignBits = 1;
470 DestLOI.Known = KnownBits(BitWidth);
471 continue;
472 }
473
474 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
475 APInt Val;
476 if (TLI->signExtendConstant(CI))
477 Val = CI->getValue().sext(BitWidth * NumRegisters);
478 else
479 Val = CI->getValue().zext(BitWidth * NumRegisters);
480 APInt Extracted = Val.extractBits(BitWidth, BitWidth * RegIdx);
481 DestLOI.NumSignBits = Extracted.getNumSignBits();
482 DestLOI.Known = KnownBits::makeConstant(Extracted);
483 } else {
484 assert(ValueMap.count(V) &&
485 "V should have been placed in ValueMap when its"
486 "CopyToReg node was created.");
487 Register SrcReg = ValueMap[V];
488 if (!SrcReg.isVirtual()) {
489 DestLOI.IsValid = false;
490 continue;
491 }
492 // Split registers are assigned sequentially.
493 SrcReg = SrcReg.id() + RegIdx;
494 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
495 if (!SrcLOI) {
496 DestLOI.IsValid = false;
497 continue;
498 }
499 DestLOI = *SrcLOI;
500 }
501
502 assert(DestLOI.Known.Zero.getBitWidth() == BitWidth &&
503 DestLOI.Known.One.getBitWidth() == BitWidth &&
504 "Masks should have the same bit width as the type.");
505
506 for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) {
507 Value *V = PN->getIncomingValue(i);
508 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
509 DestLOI.NumSignBits = 1;
510 DestLOI.Known = KnownBits(BitWidth);
511 break;
512 }
513
514 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
515 APInt Val;
516 if (TLI->signExtendConstant(CI))
517 Val = CI->getValue().sext(BitWidth * NumRegisters);
518 else
519 Val = CI->getValue().zext(BitWidth * NumRegisters);
520 APInt Extracted = Val.extractBits(BitWidth, BitWidth * RegIdx);
521 DestLOI.NumSignBits =
522 std::min(DestLOI.NumSignBits, Extracted.getNumSignBits());
523 DestLOI.Known =
524 DestLOI.Known.intersectWith(KnownBits::makeConstant(Extracted));
525 continue;
526 }
527
528 assert(ValueMap.count(V) && "V should have been placed in ValueMap when "
529 "its CopyToReg node was created.");
530 Register SrcReg = ValueMap[V];
531 if (!SrcReg.isVirtual()) {
532 DestLOI.IsValid = false;
533 break;
534 }
535 // Split registers are assigned sequentially.
536 SrcReg = SrcReg.id() + RegIdx;
537 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
538 if (!SrcLOI) {
539 DestLOI.IsValid = false;
540 break;
541 }
542 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits);
543 DestLOI.Known = DestLOI.Known.intersectWith(SrcLOI->Known);
544 }
545 }
546}
547
548/// setArgumentFrameIndex - Record frame index for the byval
549/// argument. This overrides previous frame index entry for this argument,
550/// if any.
555
556/// getArgumentFrameIndex - Get frame index for the byval argument.
557/// If the argument does not have any assigned frame index then 0 is
558/// returned.
560 auto I = ByValArgFrameIndexMap.find(A);
561 if (I != ByValArgFrameIndexMap.end())
562 return I->second;
563 LLVM_DEBUG(dbgs() << "Argument does not have assigned frame index!\n");
564 return INT_MAX;
565}
566
568 const Value *CPI, const TargetRegisterClass *RC) {
569 MachineRegisterInfo &MRI = MF->getRegInfo();
570 auto I = CatchPadExceptionPointers.insert({CPI, 0});
571 Register &VReg = I.first->second;
572 if (I.second)
573 VReg = MRI.createVirtualRegister(RC);
574 assert(VReg && "null vreg in exception pointer table!");
575 return VReg;
576}
577
578const Value *
580 if (VirtReg2Value.empty()) {
581 SmallVector<EVT, 4> ValueVTs;
582 for (auto &P : ValueMap) {
583 ValueVTs.clear();
584 ComputeValueVTs(*TLI, Fn->getDataLayout(),
585 P.first->getType(), ValueVTs);
586 Register Reg = P.second;
587 for (EVT VT : ValueVTs) {
588 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
589 for (unsigned i = 0, e = NumRegisters; i != e; ++i)
590 VirtReg2Value[Reg++] = P.first;
591 }
592 }
593 }
594 return VirtReg2Value.lookup(Vreg);
595}
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
Module.h This file contains the declarations for the Module class.
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:119
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:1057
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition APInt.h:1648
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
Definition APInt.cpp:1030
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:478
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:1088
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:126
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:782
iterator end()
Definition DenseMap.h:702
LLVM_ABI Register CreateRegs(const Value *V)
SmallPtrSet< const DbgVariableRecord *, 8 > PreprocessedDVRDeclares
Collection of dbg_declare instructions handled after argument lowering and before ISel proper.
LLVM_ABI void clear()
clear - Clear out all the function-specific state.
MachineBasicBlock * getMBB(const BasicBlock *BB) const
DenseSet< Register > RegsWithFixups
LLVM_ABI 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
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI 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.
ExceptionHandling ExceptionModel
The exception model in effect, resolved once per function.
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...
LLVM_ABI 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.
LLVM_ABI 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
LLVM_ABI 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.
LLVM_ABI 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
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
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:345
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:257
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
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:43
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:871
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:862
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.
LLVM_ABI 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:121
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI 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:209
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...
LLVM_ABI 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
@ Default
Not specified; resolve to the target's default model.
Definition CodeGen.h:55
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
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:396
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