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