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