LLVM 20.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/DataLayout.h"
31#include "llvm/IR/Function.h"
34#include "llvm/IR/Intrinsics.h"
35#include "llvm/Support/Debug.h"
38#include <algorithm>
39using namespace llvm;
40
41#define DEBUG_TYPE "function-lowering-info"
42
43/// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by
44/// PHI nodes or outside of the basic block that defines it, or used by a
45/// switch or atomic instruction, which may expand to multiple basic blocks.
47 if (I->use_empty()) return false;
48 if (isa<PHINode>(I)) return true;
49 const BasicBlock *BB = I->getParent();
50 for (const User *U : I->users())
51 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
52 return true;
53
54 return false;
55}
56
58 // For the users of the source value being used for compare instruction, if
59 // the number of signed predicate is greater than unsigned predicate, we
60 // prefer to use SIGN_EXTEND.
61 //
62 // With this optimization, we would be able to reduce some redundant sign or
63 // zero extension instruction, and eventually more machine CSE opportunities
64 // can be exposed.
65 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
66 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
67 for (const Use &U : I->uses()) {
68 if (const auto *CI = dyn_cast<CmpInst>(U.getUser())) {
69 NumOfSigned += CI->isSigned();
70 NumOfUnsigned += CI->isUnsigned();
71 }
72 if (const auto *CallI = dyn_cast<CallBase>(U.getUser())) {
73 if (!CallI->isArgOperand(&U))
74 continue;
75 unsigned ArgNo = CallI->getArgOperandNo(&U);
76 NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
77 NumOfSigned += CallI->paramHasAttr(ArgNo, Attribute::SExt);
78 }
79 }
80 if (NumOfSigned > NumOfUnsigned)
81 ExtendKind = ISD::SIGN_EXTEND;
82
83 return ExtendKind;
84}
85
87 SelectionDAG *DAG) {
88 Fn = &fn;
89 MF = &mf;
91 RegInfo = &MF->getRegInfo();
93 UA = DAG->getUniformityInfo();
94
95 // Check whether the function can return without sret-demotion.
98
100 mf.getDataLayout());
102 TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext());
103
104 // If this personality uses funclets, we need to do a bit more work.
107 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr);
108 if (isFuncletEHPersonality(Personality)) {
109 // Calculate state numbers if we haven't already.
110 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
111 if (Personality == EHPersonality::MSVC_CXX)
113 else if (isAsynchronousEHPersonality(Personality))
114 calculateSEHStateNumbers(&fn, EHInfo);
115 else if (Personality == EHPersonality::CoreCLR)
116 calculateClrEHStateNumbers(&fn, EHInfo);
117
118 // Map all BB references in the WinEH data to MBBs.
119 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
120 for (WinEHHandlerType &H : TBME.HandlerArray) {
121 if (const AllocaInst *AI = H.CatchObj.Alloca)
122 CatchObjects[AI].push_back(&H.CatchObj.FrameIndex);
123 else
124 H.CatchObj.FrameIndex = INT_MAX;
125 }
126 }
127 }
128
129 // Initialize the mapping of values to registers. This is only set up for
130 // instruction values that are used outside of the block that defines
131 // them.
132 const Align StackAlign = TFI->getStackAlign();
133 for (const BasicBlock &BB : *Fn) {
134 for (const Instruction &I : BB) {
135 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
136 Type *Ty = AI->getAllocatedType();
137 Align Alignment = AI->getAlign();
138
139 // Static allocas can be folded into the initial stack frame
140 // adjustment. For targets that don't realign the stack, don't
141 // do this if there is an extra alignment requirement.
142 if (AI->isStaticAlloca() &&
143 (TFI->isStackRealignable() || (Alignment <= StackAlign))) {
144 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize());
145 uint64_t TySize =
147
148 TySize *= CUI->getZExtValue(); // Get total allocated size.
149 if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects.
150 int FrameIndex = INT_MAX;
151 auto Iter = CatchObjects.find(AI);
152 if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) {
153 FrameIndex = MF->getFrameInfo().CreateFixedObject(
154 TySize, 0, /*IsImmutable=*/false, /*isAliased=*/true);
155 MF->getFrameInfo().setObjectAlignment(FrameIndex, Alignment);
156 } else {
157 FrameIndex = MF->getFrameInfo().CreateStackObject(TySize, Alignment,
158 false, AI);
159 }
160
161 // Scalable vectors and structures that contain scalable vectors may
162 // need a special StackID to distinguish them from other (fixed size)
163 // stack objects.
164 if (Ty->isScalableTy())
165 MF->getFrameInfo().setStackID(FrameIndex,
167
168 StaticAllocaMap[AI] = FrameIndex;
169 // Update the catch handler information.
170 if (Iter != CatchObjects.end()) {
171 for (int *CatchObjPtr : Iter->second)
172 *CatchObjPtr = FrameIndex;
173 }
174 } else {
175 // FIXME: Overaligned static allocas should be grouped into
176 // a single dynamic allocation instead of using a separate
177 // stack allocation for each one.
178 // Inform the Frame Information that we have variable-sized objects.
180 Alignment <= StackAlign ? Align(1) : Alignment, AI);
181 }
182 } else if (auto *Call = dyn_cast<CallBase>(&I)) {
183 // Look for inline asm that clobbers the SP register.
184 if (Call->isInlineAsm()) {
187 std::vector<TargetLowering::AsmOperandInfo> Ops =
189 *Call);
191 if (Op.Type == InlineAsm::isClobber) {
192 // Clobbers don't have SDValue operands, hence SDValue().
194 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
195 TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode,
196 Op.ConstraintVT);
197 if (PhysReg.first == SP)
199 }
200 }
201 }
202 if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
203 switch (II->getIntrinsicID()) {
204 case Intrinsic::vastart:
205 // Look for calls to the @llvm.va_start intrinsic. We can omit
206 // some prologue boilerplate for variadic functions that don't
207 // examine their arguments.
209 break;
210 case Intrinsic::fake_use:
211 // Look for llvm.fake.uses, so that we can remove loads into fake
212 // uses later if necessary.
213 MF->setHasFakeUses(true);
214 break;
215 default:
216 break;
217 }
218 }
219
220 // If we have a musttail call in a variadic function, we need to ensure
221 // we forward implicit register parameters.
222 if (const auto *CI = dyn_cast<CallInst>(&I)) {
223 if (CI->isMustTailCall() && Fn->isVarArg())
225 }
226
227 // Determine if there is a call to setjmp in the machine function.
228 if (Call->hasFnAttr(Attribute::ReturnsTwice))
230 }
231
232 // Mark values used outside their block as exported, by allocating
233 // a virtual register for them.
235 if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I)))
237
238 // Decide the preferred extend type for a value. This iterates over all
239 // users and therefore isn't cheap, so don't do this at O0.
242 }
243 }
244
245 // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This
246 // also creates the initial PHI MachineInstrs, though none of the input
247 // operands are populated.
248 MBBMap.resize(Fn->getMaxBlockNumber());
249 for (const BasicBlock &BB : *Fn) {
250 // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks
251 // are really data, and no instructions can live here.
252 if (BB.isEHPad()) {
253 const Instruction *PadInst = BB.getFirstNonPHI();
254 // If this is a non-landingpad EH pad, mark this function as using
255 // funclets.
256 // FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid
257 // setting this in such cases in order to improve frame layout.
258 if (!isa<LandingPadInst>(PadInst)) {
259 MF->setHasEHScopes(true);
260 MF->setHasEHFunclets(true);
262 }
263 if (isa<CatchSwitchInst>(PadInst)) {
264 assert(&*BB.begin() == PadInst &&
265 "WinEHPrepare failed to remove PHIs from imaginary BBs");
266 continue;
267 }
268 if (isa<FuncletPadInst>(PadInst) &&
269 Personality != EHPersonality::Wasm_CXX)
270 assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
271 }
272
274 MBBMap[BB.getNumber()] = MBB;
275 MF->push_back(MBB);
276
277 // Transfer the address-taken flag. This is necessary because there could
278 // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only
279 // the first one should be marked.
280 if (BB.hasAddressTaken())
281 MBB->setAddressTakenIRBlock(const_cast<BasicBlock *>(&BB));
282
283 // Mark landing pad blocks.
284 if (BB.isEHPad())
285 MBB->setIsEHPad();
286
287 // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
288 // appropriate.
289 for (const PHINode &PN : BB.phis()) {
290 if (PN.use_empty())
291 continue;
292
293 // Skip empty types
294 if (PN.getType()->isEmptyTy())
295 continue;
296
297 DebugLoc DL = PN.getDebugLoc();
298 unsigned PHIReg = ValueMap[&PN];
299 assert(PHIReg && "PHI node does not have an assigned virtual register!");
300
301 SmallVector<EVT, 4> ValueVTs;
302 ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs);
303 for (EVT VT : ValueVTs) {
304 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
306 for (unsigned i = 0; i != NumRegisters; ++i)
307 BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i);
308 PHIReg += NumRegisters;
309 }
310 }
311 }
312
313 if (isFuncletEHPersonality(Personality)) {
314 WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
315
316 // Map all BB references in the WinEH data to MBBs.
317 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
318 for (WinEHHandlerType &H : TBME.HandlerArray) {
319 if (H.Handler)
320 H.Handler = getMBB(cast<const BasicBlock *>(H.Handler));
321 }
322 }
323 for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
324 if (UME.Cleanup)
325 UME.Cleanup = getMBB(cast<const BasicBlock *>(UME.Cleanup));
326 for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap)
327 UME.Handler = getMBB(cast<const BasicBlock *>(UME.Handler));
328 for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap)
329 CME.Handler = getMBB(cast<const BasicBlock *>(CME.Handler));
330 } else if (Personality == EHPersonality::Wasm_CXX) {
331 WasmEHFuncInfo &EHInfo = *MF->getWasmEHFuncInfo();
332 calculateWasmEHInfo(&fn, EHInfo);
333
334 // Map all BB references in the Wasm EH data to MBBs.
335 DenseMap<BBOrMBB, BBOrMBB> SrcToUnwindDest;
336 for (auto &KV : EHInfo.SrcToUnwindDest) {
337 const auto *Src = cast<const BasicBlock *>(KV.first);
338 const auto *Dest = cast<const BasicBlock *>(KV.second);
339 SrcToUnwindDest[getMBB(Src)] = getMBB(Dest);
340 }
341 EHInfo.SrcToUnwindDest = std::move(SrcToUnwindDest);
343 for (auto &KV : EHInfo.UnwindDestToSrcs) {
344 const auto *Dest = cast<const BasicBlock *>(KV.first);
345 MachineBasicBlock *DestMBB = getMBB(Dest);
346 UnwindDestToSrcs[DestMBB] = SmallPtrSet<BBOrMBB, 4>();
347 for (const auto P : KV.second)
348 UnwindDestToSrcs[DestMBB].insert(getMBB(cast<const BasicBlock *>(P)));
349 }
350 EHInfo.UnwindDestToSrcs = std::move(UnwindDestToSrcs);
351 }
352}
353
354/// clear - Clear out all the function-specific state. This returns this
355/// FunctionLoweringInfo to an empty state, ready to be used for a
356/// different function.
358 MBBMap.clear();
359 ValueMap.clear();
360 VirtReg2Value.clear();
361 StaticAllocaMap.clear();
362 LiveOutRegInfo.clear();
364 ArgDbgValues.clear();
366 ByValArgFrameIndexMap.clear();
367 RegFixups.clear();
371 PreferredExtendType.clear();
374}
375
376/// CreateReg - Allocate a single virtual register for the given type.
378 return RegInfo->createVirtualRegister(TLI->getRegClassFor(VT, isDivergent));
379}
380
381/// CreateRegs - Allocate the appropriate number of virtual registers of
382/// the correctly promoted or expanded types. Assign these registers
383/// consecutive vreg numbers and return the first assigned number.
384///
385/// In the case that the given value has struct or array type, this function
386/// will assign registers for each member or element.
387///
389 SmallVector<EVT, 4> ValueVTs;
390 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
391
392 Register FirstReg;
393 for (EVT ValueVT : ValueVTs) {
394 MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT);
395
396 unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT);
397 for (unsigned i = 0; i != NumRegs; ++i) {
398 Register R = CreateReg(RegisterVT, isDivergent);
399 if (!FirstReg) FirstReg = R;
400 }
401 }
402 return FirstReg;
403}
404
406 return CreateRegs(V->getType(), UA && UA->isDivergent(V) &&
408}
409
411 // Tokens live in vregs only when used for convergence control.
412 if (V->getType()->isTokenTy() && !isa<ConvergenceControlInst>(V))
413 return 0;
414 Register &R = ValueMap[V];
415 assert(R == Register() && "Already initialized this value register!");
416 assert(VirtReg2Value.empty());
417 return R = CreateRegs(V);
418}
419
420/// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
421/// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
422/// the register's LiveOutInfo is for a smaller bit width, it is extended to
423/// the larger bit width by zero extension. The bit width must be no smaller
424/// than the LiveOutInfo's existing bit width.
427 if (!LiveOutRegInfo.inBounds(Reg))
428 return nullptr;
429
430 LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
431 if (!LOI->IsValid)
432 return nullptr;
433
434 if (BitWidth > LOI->Known.getBitWidth()) {
435 LOI->NumSignBits = 1;
436 LOI->Known = LOI->Known.anyext(BitWidth);
437 }
438
439 return LOI;
440}
441
442/// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
443/// register based on the LiveOutInfo of its operands.
445 Type *Ty = PN->getType();
446 if (!Ty->isIntegerTy() || Ty->isVectorTy())
447 return;
448
449 SmallVector<EVT, 1> ValueVTs;
450 ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
451 assert(ValueVTs.size() == 1 &&
452 "PHIs with non-vector integer types should have a single VT.");
453 EVT IntVT = ValueVTs[0];
454
455 if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1)
456 return;
457 IntVT = TLI->getRegisterType(PN->getContext(), IntVT);
458 unsigned BitWidth = IntVT.getSizeInBits();
459
460 auto It = ValueMap.find(PN);
461 if (It == ValueMap.end())
462 return;
463
464 Register DestReg = It->second;
465 if (DestReg == 0)
466 return;
467 assert(DestReg.isVirtual() && "Expected a virtual reg");
468 LiveOutRegInfo.grow(DestReg);
469 LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg];
470
471 Value *V = PN->getIncomingValue(0);
472 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
473 DestLOI.NumSignBits = 1;
474 DestLOI.Known = KnownBits(BitWidth);
475 return;
476 }
477
478 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
479 APInt Val;
480 if (TLI->signExtendConstant(CI))
481 Val = CI->getValue().sext(BitWidth);
482 else
483 Val = CI->getValue().zext(BitWidth);
484 DestLOI.NumSignBits = Val.getNumSignBits();
485 DestLOI.Known = KnownBits::makeConstant(Val);
486 } else {
487 assert(ValueMap.count(V) && "V should have been placed in ValueMap when its"
488 "CopyToReg node was created.");
489 Register SrcReg = ValueMap[V];
490 if (!SrcReg.isVirtual()) {
491 DestLOI.IsValid = false;
492 return;
493 }
494 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
495 if (!SrcLOI) {
496 DestLOI.IsValid = false;
497 return;
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 return;
512 }
513
514 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
515 APInt Val;
516 if (TLI->signExtendConstant(CI))
517 Val = CI->getValue().sext(BitWidth);
518 else
519 Val = CI->getValue().zext(BitWidth);
520 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits());
521 DestLOI.Known.Zero &= ~Val;
522 DestLOI.Known.One &= Val;
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 return;
532 }
533 const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
534 if (!SrcLOI) {
535 DestLOI.IsValid = false;
536 return;
537 }
538 DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits);
539 DestLOI.Known = DestLOI.Known.intersectWith(SrcLOI->Known);
540 }
541}
542
543/// setArgumentFrameIndex - Record frame index for the byval
544/// argument. This overrides previous frame index entry for this argument,
545/// if any.
547 int FI) {
549}
550
551/// getArgumentFrameIndex - Get frame index for the byval argument.
552/// If the argument does not have any assigned frame index then 0 is
553/// returned.
555 auto I = ByValArgFrameIndexMap.find(A);
556 if (I != ByValArgFrameIndexMap.end())
557 return I->second;
558 LLVM_DEBUG(dbgs() << "Argument does not have assigned frame index!\n");
559 return INT_MAX;
560}
561
563 const Value *CPI, const TargetRegisterClass *RC) {
565 auto I = CatchPadExceptionPointers.insert({CPI, 0});
566 Register &VReg = I.first->second;
567 if (I.second)
568 VReg = MRI.createVirtualRegister(RC);
569 assert(VReg && "null vreg in exception pointer table!");
570 return VReg;
571}
572
573const Value *
575 if (VirtReg2Value.empty()) {
576 SmallVector<EVT, 4> ValueVTs;
577 for (auto &P : ValueMap) {
578 ValueVTs.clear();
580 P.first->getType(), ValueVTs);
581 unsigned Reg = P.second;
582 for (EVT VT : ValueVTs) {
583 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
584 for (unsigned i = 0, e = NumRegisters; i != e; ++i)
585 VirtReg2Value[Reg++] = P.first;
586 }
587 }
588 }
589 return VirtReg2Value.lookup(Vreg);
590}
unsigned const MachineRegisterInfo * MRI
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")
#define LLVM_DEBUG(...)
Definition: Debug.h:106
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
#define I(x, y, z)
Definition: MD5.cpp:58
#define H(x, y, z)
Definition: MD5.cpp:57
unsigned const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:986
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1468
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition: APInt.h:1607
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:959
an instruction to allocate memory on the stack
Definition: Instructions.h:63
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
void clear()
clear - Removes all bits from the bitvector.
Definition: BitVector.h:335
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:157
This class represents an Operation in the Expression.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:457
A debug info location.
Definition: DebugLoc.h:33
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
iterator end()
Definition: DenseMap.h:84
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
Register CreateRegs(const Value *V)
SmallPtrSet< const DbgVariableRecord *, 8 > PreprocessedDVRDeclares
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.
const UniformityInfo * UA
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)
SmallPtrSet< const DbgDeclareInst *, 8 > PreprocessedDbgDeclares
Collection of dbg.declare instructions handled after argument lowering and before ISel proper.
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 TargetLowering * TLI
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.
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Definition: Function.cpp:373
unsigned getMaxBlockNumber() const
Return a value larger than the largest block number.
Definition: Function.h:828
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:277
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:905
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1048
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:353
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:369
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:221
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:234
bool isDivergent(ConstValueRefT V) const
Whether V is divergent at its definition.
Machine Value Type.
void setAddressTakenIRBlock(BasicBlock *BB)
Set this block to reflect that it corresponds to an IR-level basic block with a BlockAddress.
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
void setStackID(int ObjectIdx, uint8_t ID)
void setHasOpaqueSPAdjustment(bool B)
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setHasMustTailInVarArgFunc(bool B)
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
void setHasEHFunclets(bool V)
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void push_back(MachineBasicBlock *MBB)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
const WasmEHFuncInfo * getWasmEHFuncInfo() const
getWasmEHFuncInfo - Return information about how the current function uses Wasm exception handling.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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:19
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:91
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...
Definition: SelectionDAG.h:228
const UniformityInfo * getUniformityInfo() const
Definition: SelectionDAG.h:504
CodeGenOptLevel getOptLevel() const
Definition: SelectionDAG.h:494
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
size_t size() const
Definition: SmallVector.h:78
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
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.
virtual bool requiresUniformRegister(MachineFunction &MF, const Value *) const
Allows target to decide about the register class of the specific value that is live outside the defin...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual bool needsFixedCatchObjects() const
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
virtual bool signExtendConstant(const ConstantInt *C) const
Return true if this constant should be sign extended when promoting to a larger type.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
virtual AsmOperandInfoVector ParseConstraints(const DataLayout &DL, const TargetRegisterInfo *TRI, const CallBase &Call) const
Split up the constraint string from the inline assembly value into the specific constraints and their...
virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, SDValue Op, SelectionDAG *DAG=nullptr) const
Determines the constraint code and constraint type to use for the specific AsmOperandInfo,...
virtual bool CanLowerReturn(CallingConv::ID, MachineFunction &, bool, const SmallVectorImpl< ISD::OutputArg > &, LLVMContext &) const
This hook should be implemented to check whether the return values described by the Outs array can fi...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetLowering * getTargetLowering() const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:270
bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:237
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
See the file comment.
Definition: ValueMap.h:84
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: ValueMap.h:151
void clear()
Definition: ValueMap.h:145
iterator find(const KeyT &Val)
Definition: ValueMap.h:155
iterator end()
Definition: ValueMap.h:135
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1075
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:40
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:814
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:805
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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 calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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)
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, 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:79
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:217
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo)
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 Handler
Definition: WinEHFuncInfo.h:82
MBBOrBasicBlock Cleanup
Definition: WinEHFuncInfo.h:42
Extended Value Type.
Definition: ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:293
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:43
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition: KnownBits.h:303
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:159
Similar to CxxUnwindMapEntry, but supports SEH filters.
Definition: WinEHFuncInfo.h:46
This contains information for each constraint that we are lowering.
DenseMap< BBOrMBB, SmallPtrSet< BBOrMBB, 4 > > UnwindDestToSrcs
DenseMap< BBOrMBB, BBOrMBB > SrcToUnwindDest
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
Definition: WinEHFuncInfo.h:98
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
Definition: WinEHFuncInfo.h:99
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Definition: WinEHFuncInfo.h:97
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
Definition: WinEHFuncInfo.h:96
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition: WinEHFuncInfo.h:76