43 #define DEBUG_TYPE "function-lowering-info" 50 if (isa<PHINode>(I))
return true;
53 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
68 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
70 if (
const auto *CI = dyn_cast<CmpInst>(U)) {
71 NumOfSigned += CI->isSigned();
72 NumOfUnsigned += CI->isUnsigned();
75 if (NumOfSigned > NumOfUnsigned)
118 CatchObjects.
insert({AI, {}}).
first->second.push_back(
135 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
136 Type *Ty = AI->getAllocatedType();
144 if (AI->isStaticAlloca() &&
146 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize());
151 if (TySize == 0) TySize = 1;
153 auto Iter = CatchObjects.
find(AI);
154 if (Iter != CatchObjects.
end() && TLI->needsFixedCatchObjects()) {
156 TySize, 0,
false,
true);
171 if (Iter != CatchObjects.
end()) {
172 for (
int *CatchObjPtr : Iter->second)
179 if (Align <= StackAlign)
187 if (isa<CallInst>(
I) || isa<InvokeInst>(
I)) {
190 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
192 std::vector<TargetLowering::AsmOperandInfo> Ops =
193 TLI->ParseConstraints(Fn->getParent()->getDataLayout(),
TRI, CS);
197 TLI->ComputeConstraintToUse(
Op,
SDValue(), DAG);
198 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
199 TLI->getRegForInlineAsmConstraint(TRI,
Op.ConstraintCode,
201 if (PhysReg.first == SP)
211 if (
const auto *II = dyn_cast<IntrinsicInst>(&
I)) {
212 if (II->getIntrinsicID() == Intrinsic::vastart)
218 if (
const auto *CI = dyn_cast<CallInst>(&
I)) {
219 if (CI->isMustTailCall() && Fn->isVarArg())
246 if (!isa<LandingPadInst>(PadInst)) {
251 if (isa<CatchSwitchInst>(PadInst)) {
252 assert(&*BB.begin() == PadInst &&
253 "WinEHPrepare failed to remove PHIs from imaginary BBs");
256 if (isa<FuncletPadInst>(PadInst))
257 assert(&*BB.begin() == PadInst &&
"WinEHPrepare failed to demote PHIs");
267 if (BB.hasAddressTaken())
276 for (
const PHINode &PN : BB.phis()) {
281 if (PN.getType()->isEmptyTy())
286 assert(PHIReg &&
"PHI node does not have an assigned virtual register!");
290 for (
EVT VT : ValueVTs) {
291 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
293 for (
unsigned i = 0; i != NumRegisters; ++i)
294 BuildMI(MBB, DL, TII->
get(TargetOpcode::PHI), PHIReg + i);
295 PHIReg += NumRegisters;
328 const auto *Src = KV.first.get<
const BasicBlock *>();
329 const auto *Dst = KV.second.get<
const BasicBlock *>();
330 NewMap[
MBBMap[Src]] = MBBMap[Dst];
344 LiveOutRegInfo.clear();
375 unsigned FirstReg = 0;
381 for (
unsigned i = 0; i != NumRegs; ++i) {
382 unsigned R =
CreateReg(RegisterVT, isDivergent);
383 if (!FirstReg) FirstReg = R;
401 if (!LiveOutRegInfo.inBounds(Reg))
426 "PHIs with non-vector integer types should have a single VT.");
427 EVT IntVT = ValueVTs[0];
437 LiveOutRegInfo.grow(DestReg);
441 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
454 "CopyToReg node was created.");
470 "Masks should have the same bit width as the type.");
474 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
489 "its CopyToReg node was created.");
521 LLVM_DEBUG(
dbgs() <<
"Argument does not have assigned frame index!\n");
529 unsigned &VReg =
I.first->second;
532 assert(VReg &&
"null vreg in exception pointer table!");
543 P.first->getType(), ValueVTs);
544 unsigned Reg =
P.second;
545 for (
EVT VT : ValueVTs) {
547 for (
unsigned i = 0,
e = NumRegisters; i !=
e; ++i)
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
unsigned CreateReg(MVT VT, bool isDivergent=false)
CreateReg - Allocate a single virtual register for the given type.
SmallVector< WinEHHandlerType, 1 > HandlerArray
bool isDivergent(const Value *V) const
This class represents an incoming formal argument to a Function.
This class represents lattice values for constants.
unsigned getCatchPadExceptionPointerVReg(const Value *CPI, const TargetRegisterClass *RC)
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setHasEHFunclets(bool V)
virtual const TargetLowering * getTargetLowering() const
const AllocaInst * Alloca
LLVMContext & getContext() const
All values hold a context through their type.
unsigned const TargetRegisterInfo * TRI
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
bool isVectorTy() const
True if this is an instance of VectorType.
DenseMap< const Value *, unsigned > CatchPadExceptionPointers
Track virtual registers created for exception pointers.
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
unsigned getBitWidth() const
Get the bit width of this value.
T get() const
Returns the value of the specified pointer type.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG)
set - Initialize this FunctionLoweringInfo with the given Function and its associated MachineFunction...
unsigned getBitWidth() const
Return the number of bits in the APInt.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static bool isUsedOutsideOfDefiningBlock(const Instruction *I)
isUsedOutsideOfDefiningBlock - Return true if this instruction is used by PHI nodes or outside of the...
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
const HexagonInstrInfo * TII
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
bool isIntegerTy() const
True if this is an instance of IntegerType.
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
Type * getType() const
All values are typed, get the type of this value.
void setHasMustTailInVarArgFunc(bool B)
const LiveOutInfo * GetLiveOutRegInfo(unsigned Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual TargetStackID::Value getStackIDForScalableVectors() const
Returns the StackID that scalable vectors should be associated with.
DenseMap< BBOrMBB, BBOrMBB > EHPadUnwindMap
This contains information for each constraint that we are lowering.
DenseSet< unsigned > RegsWithFixups
const LegacyDivergenceAnalysis * DA
static ISD::NodeType getPreferredExtendForValue(const Value *V)
AttributeList getAttributes() const
Return the attribute list for this Function.
bool hasPersonalityFn() const
Check whether this function has a personality function.
virtual const TargetInstrInfo * getInstrInfo() const
void setHasOpaqueSPAdjustment(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
TargetInstrInfo - Interface to description of machine instruction set.
void clear()
clear - Clear out all the function-specific state.
iterator find(const_arg_type_t< KeyT > Val)
Similar to CxxUnwindMapEntry, but supports SEH filters.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void setHasEHScopes(bool V)
Type * getReturnType() const
Returns the type of the ret val.
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
DenseMap< unsigned, const Value * > VirtReg2Value
VirtReg2Value map is needed by the Divergence Analysis driven instruction selection.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
KnownBits zext(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const
Extends the underlying known Zero and One bits.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
const LegacyDivergenceAnalysis * getDivergenceAnalysis() const
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
void setHasVAStart(bool B)
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
void setStackID(int ObjectIdx, uint8_t ID)
DenseMap< const Instruction *, StatepointSpillMap > StatepointSpillMaps
Maps gc.statepoint instructions to their corresponding StatepointSpillMap instances.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
This struct is a compact representation of a valid (non-zero power of two) alignment.
MachineBasicBlock * MBB
MBB - The current block.
SmallVector< unsigned, 50 > StatepointStackSlots
StatepointStackSlots - A list of temporary stack slots (frame indices) used to spill values at a stat...
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...
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
This is the shared class of boolean and integer constants.
Align max(MaybeAlign Lhs, Align Rhs)
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
Module.h This file contains the declarations for the Module class.
Information about stack frame layout on the target.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
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...
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Class for arbitrary precision integers.
iterator_range< user_iterator > users()
union llvm::WinEHHandlerType::@202 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
ANY_EXTEND - Used for integer types. The high bits are undefined.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const WasmEHFuncInfo * getWasmEHFuncInfo() const
getWasmEHFuncInfo - Return information about how the current function uses Wasm exception handling...
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
unsigned CreateRegs(const Value *V)
MachineRegisterInfo * RegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
DenseMap< const Argument *, int > ByValArgFrameIndexMap
ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
uint64_t getKnownMinSize() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Establish a view to a call site for examination.
virtual const TargetFrameLowering * getFrameLowering() const
BitVector DescribedArgs
Bitvector with a bit set if corresponding argument is described in ArgDbgValues.
const Value * getValueFromVirtualReg(unsigned Vreg)
This method is called from TargetLowerinInfo::isSDNodeSourceOfDivergence to get the Value correspondi...
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block...
bool getVectorIsScalable() const
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo)
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
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...
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void push_back(MachineBasicBlock *MBB)
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
const TargetLowering * TLI
void setArgumentFrameIndex(const Argument *A, int FI)
setArgumentFrameIndex - Record frame index for the byval argument.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
unsigned InitializeRegForValue(const Value *V)