43#define DEBUG_TYPE "function-lowering-info"
49 if (
I->use_empty())
return false;
52 for (
const User *U :
I->users())
68 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
69 for (
const Use &U :
I->uses()) {
71 NumOfSigned += CI->isSigned();
72 NumOfUnsigned += CI->isUnsigned();
75 if (!CallI->isArgOperand(&U))
77 unsigned ArgNo = CallI->getArgOperandNo(&U);
78 NumOfUnsigned += CallI->paramHasAttr(ArgNo, Attribute::ZExt);
79 NumOfSigned += CallI->paramHasAttr(ArgNo, Attribute::SExt);
82 if (NumOfSigned > NumOfUnsigned)
92 TLI =
MF->getSubtarget().getTargetLowering();
108 TLI->CanLowerReturn(CC, *
MF,
Fn->isVarArg(), Outs,
Fn->getContext(),
Fn->getReturnType());
113 Fn->hasPersonalityFn() ?
Fn->getPersonalityFn() :
nullptr);
128 CatchObjects[AI].push_back(&
H.CatchObj.FrameIndex);
130 H.CatchObj.FrameIndex = INT_MAX;
142 Align Alignment = AI->getAlign();
147 if (AI->isStaticAlloca() &&
149 TypeSize AllocaSize = AI->getAllocationSize(
MF->getDataLayout())
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,
false,
true);
159 MF->getFrameInfo().setObjectAlignment(FrameIndex, Alignment);
161 FrameIndex =
MF->getFrameInfo().CreateStackObject(TySize, Alignment,
169 MF->getFrameInfo().setStackID(FrameIndex,
174 if (Iter != CatchObjects.
end()) {
175 for (
int *CatchObjPtr : Iter->second)
176 *CatchObjPtr = FrameIndex;
183 MF->getFrameInfo().CreateVariableSizedObject(
184 Alignment <= StackAlign ?
Align(1) : Alignment, AI);
188 if (
Call->isInlineAsm()) {
189 Register SP =
TLI->getStackPointerRegisterToSaveRestore();
191 std::vector<TargetLowering::AsmOperandInfo>
Ops =
192 TLI->ParseConstraints(
Fn->getDataLayout(),
TRI,
198 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
199 TLI->getRegForInlineAsmConstraint(
TRI,
Op.ConstraintCode,
201 if (PhysReg.first == SP)
202 MF->getFrameInfo().setHasOpaqueSPAdjustment(
true);
207 switch (
II->getIntrinsicID()) {
208 case Intrinsic::vastart:
212 MF->getFrameInfo().setHasVAStart(
true);
214 case Intrinsic::fake_use:
217 MF->setHasFakeUses(
true);
227 if (CI->isMustTailCall() &&
Fn->isVarArg())
228 MF->getFrameInfo().setHasMustTailInVarArgFunc(
true);
232 if (
Call->hasFnAttr(Attribute::ReturnsTwice))
233 MF->setExposesReturnsTwice(
true);
252 MBBMap.resize(
Fn->getMaxBlockNumber());
263 MF->setHasEHScopes(
true);
264 MF->setHasEHFunclets(
true);
265 MF->getFrameInfo().setHasOpaqueSPAdjustment(
true);
268 assert(BB.begin() == PadInst &&
269 "WinEHPrepare failed to remove PHIs from imaginary BBs");
274 assert(BB.begin() == PadInst &&
"WinEHPrepare failed to demote PHIs");
287 if (BB.hasAddressTaken()) {
289 if (!BA->hasZeroLiveUses())
299 for (
const PHINode &PN : BB.phis()) {
304 if (PN.getType()->isEmptyTy())
309 assert(PHIReg &&
"PHI node does not have an assigned virtual register!");
313 for (
EVT VT : ValueVTs) {
314 unsigned NumRegisters =
TLI->getNumRegisters(
Fn->getContext(), VT);
316 for (
unsigned i = 0; i != NumRegisters; ++i)
318 PHIReg += NumRegisters;
351 LiveOutRegInfo.clear();
366 return RegInfo->createVirtualRegister(
TLI->getRegClassFor(VT, isDivergent));
381 for (
EVT ValueVT : ValueVTs) {
382 MVT RegisterVT =
TLI->getRegisterType(Ty->getContext(), ValueVT);
384 unsigned NumRegs =
TLI->getNumRegisters(Ty->getContext(), ValueVT);
385 for (
unsigned i = 0; i != NumRegs; ++i) {
387 if (!FirstReg) FirstReg = R;
395 !
TLI->requiresUniformRegister(*
MF, V));
403 assert(R ==
Register() &&
"Already initialized this value register!");
415 if (!LiveOutRegInfo.inBounds(Reg))
434 if (!Ty->isIntegerTy())
440 "PHIs with non-vector integer types should have a single VT.");
441 EVT IntVT = ValueVTs[0];
443 unsigned NumRegisters =
TLI->getNumRegisters(PN->
getContext(), IntVT);
445 if (NumRegisters != 1 &&
MF->getDataLayout().isBigEndian())
457 assert(BaseReg.isVirtual() &&
"Expected a virtual reg");
459 for (
unsigned RegIdx = 0; RegIdx < NumRegisters; ++RegIdx) {
461 Register DestReg = BaseReg.id() + RegIdx;
462 LiveOutRegInfo.grow(DestReg);
474 if (
TLI->signExtendConstant(CI))
483 "V should have been placed in ValueMap when its"
484 "CopyToReg node was created.");
491 SrcReg = SrcReg.
id() + RegIdx;
502 "Masks should have the same bit width as the type.");
514 if (
TLI->signExtendConstant(CI))
526 assert(
ValueMap.count(V) &&
"V should have been placed in ValueMap when "
527 "its CopyToReg node was created.");
534 SrcReg = SrcReg.
id() + RegIdx;
561 LLVM_DEBUG(
dbgs() <<
"Argument does not have assigned frame index!\n");
572 assert(VReg &&
"null vreg in exception pointer table!");
583 P.first->getType(), ValueVTs);
585 for (
EVT VT : ValueVTs) {
586 unsigned NumRegisters =
TLI->getNumRegisters(
Fn->getContext(), VT);
587 for (
unsigned i = 0, e = NumRegisters; i != e; ++i)
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[]
Register const TargetRegisterInfo * TRI
Promote Memory to Register
uint64_t IntrinsicInst * II
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
InstListType::const_iterator const_iterator
The address of a basic block.
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.
iterator find(const_arg_type_t< KeyT > Val)
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.
const UniformityInfo * UA
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.
const TargetLowering * TLI
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.
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.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr unsigned id() const
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()
The instances of the Type class are immutable: once they are created, they are never changed.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVMContext & getContext() const
All values hold a context through their type.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ SIGN_EXTEND
Conversion operators.
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...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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.
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...
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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
unsigned getBitWidth() const
Get the bit width of this value.
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
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...
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