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)
117 CatchObjects.
insert({AI, {}}).
first->second.push_back(
134 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
135 Type *Ty = AI->getAllocatedType();
143 if (AI->isStaticAlloca() &&
145 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize());
149 if (TySize == 0) TySize = 1;
151 auto Iter = CatchObjects.
find(AI);
152 if (Iter != CatchObjects.
end() && TLI->needsFixedCatchObjects()) {
154 TySize, 0,
false,
true);
163 if (Iter != CatchObjects.
end()) {
164 for (
int *CatchObjPtr : Iter->second)
171 if (Align <= StackAlign)
179 if (isa<CallInst>(
I) || isa<InvokeInst>(
I)) {
182 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
184 std::vector<TargetLowering::AsmOperandInfo> Ops =
185 TLI->ParseConstraints(Fn->getParent()->getDataLayout(),
TRI, CS);
189 TLI->ComputeConstraintToUse(
Op,
SDValue(), DAG);
190 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
191 TLI->getRegForInlineAsmConstraint(TRI,
Op.ConstraintCode,
193 if (PhysReg.first == SP)
203 if (
const auto *II = dyn_cast<IntrinsicInst>(&
I)) {
210 if (
const auto *CI = dyn_cast<CallInst>(&
I)) {
211 if (CI->isMustTailCall() && Fn->isVarArg())
238 if (!isa<LandingPadInst>(PadInst)) {
243 if (isa<CatchSwitchInst>(PadInst)) {
244 assert(&*BB.begin() == PadInst &&
245 "WinEHPrepare failed to remove PHIs from imaginary BBs");
248 if (isa<FuncletPadInst>(PadInst))
249 assert(&*BB.begin() == PadInst &&
"WinEHPrepare failed to demote PHIs");
259 if (BB.hasAddressTaken())
268 for (
const PHINode &PN : BB.phis()) {
273 if (PN.getType()->isEmptyTy())
278 assert(PHIReg &&
"PHI node does not have an assigned virtual register!");
282 for (
EVT VT : ValueVTs) {
283 unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
285 for (
unsigned i = 0; i != NumRegisters; ++i)
286 BuildMI(MBB, DL, TII->
get(TargetOpcode::PHI), PHIReg + i);
287 PHIReg += NumRegisters;
320 const auto *Src = KV.first.get<
const BasicBlock *>();
321 const auto *Dst = KV.second.get<
const BasicBlock *>();
322 NewMap[
MBBMap[Src]] = MBBMap[Dst];
327 const auto *Src = KV.first.get<
const BasicBlock *>();
328 const auto *Dst = KV.second.get<
const BasicBlock *>();
329 NewMap[
MBBMap[Src]] = MBBMap[Dst];
343 LiveOutRegInfo.clear();
373 unsigned FirstReg = 0;
379 for (
unsigned i = 0; i != NumRegs; ++i) {
381 if (!FirstReg) FirstReg = R;
394 if (!LiveOutRegInfo.inBounds(Reg))
419 "PHIs with non-vector integer types should have a single VT.");
420 EVT IntVT = ValueVTs[0];
430 LiveOutRegInfo.grow(DestReg);
434 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
447 "CopyToReg node was created.");
463 "Masks should have the same bit width as the type.");
467 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
482 "its CopyToReg node was created.");
514 LLVM_DEBUG(
dbgs() <<
"Argument does not have assigned frame index!\n");
522 unsigned &VReg =
I.first->second;
525 assert(VReg &&
"null vreg in exception pointer table!");
532 auto Key = std::make_pair(MBB, Val);
545 }
else return It->second;
553 std::pair<unsigned, bool>
562 return std::make_pair(VReg,
true);
564 return std::make_pair(It->second,
false);
567 std::pair<unsigned, bool>
574 return std::make_pair(VReg,
true);
576 return std::make_pair(It->second,
false);
586 P.first->getType(), ValueVTs);
587 unsigned Reg =
P.second;
588 for (
EVT VT : ValueVTs) {
590 for (
unsigned i = 0, e = NumRegisters; i != e; ++i)
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
SmallVector< WinEHHandlerType, 1 > HandlerArray
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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.
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setHasEHFunclets(bool V)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
virtual const TargetLowering * getTargetLowering() const
const AllocaInst * Alloca
LLVMContext & getContext() const
All values hold a context through their type.
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value 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.
void setCurrentSwiftErrorVReg(const MachineBasicBlock *MBB, const Value *, unsigned)
Set the swifterror virtual register in the SwiftErrorVRegDefMap for this basic block.
int CreateStackObject(uint64_t Size, unsigned 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...
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.
union llvm::WinEHHandlerType::@189 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
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< unsigned, bool > getOrCreateSwiftErrorVRegDefAt(const Instruction *)
Get or create the swifterror value virtual register for a def of a swifterror by an instruction...
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...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
const HexagonInstrInfo * TII
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
bool isIntegerTy() const
True if this is an instance of IntegerType.
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.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
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...
DenseMap< BBOrMBB, BBOrMBB > EHPadUnwindMap
DenseMap< BBOrMBB, BBOrMBB > ThrowUnwindMap
This contains information for each constraint that we are lowering.
DenseSet< unsigned > RegsWithFixups
KnownBits zextOrTrunc(unsigned BitWidth)
Zero extends or truncates the underlying known Zero and One bits.
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
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
std::pair< unsigned, bool > getOrCreateSwiftErrorVRegUseAt(const Instruction *, const MachineBasicBlock *, const Value *)
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)
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...
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...
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.
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
DenseMap< std::pair< const MachineBasicBlock *, const Value * >, unsigned > SwiftErrorVRegDefMap
A map from swifterror value in a basic block to the virtual register it is currently represented by...
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.
DenseMap< std::pair< const MachineBasicBlock *, const Value * >, unsigned > SwiftErrorVRegUpwardsUse
A list of upward exposed vreg uses that need to be satisfied by either a copy def or a phi node at th...
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.
unsigned CreateRegs(Type *Ty)
CreateRegs - Allocate the appropriate number of virtual registers of the correctly promoted or expand...
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()
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.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
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
const Value * getValueFromVirtualReg(unsigned Vreg)
This method is called from TargetLowerinInfo::isSDNodeSourceOfDivergence to get the Value correspondi...
unsigned CreateReg(MVT VT)
CreateReg - Allocate a single virtual register for the given type.
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block...
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.
T get() const
Returns the value of the specified pointer type.
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.
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.
void push_back(MachineBasicBlock *MBB)
llvm::DenseMap< PointerIntPair< const Instruction *, 1, bool >, unsigned > SwiftErrorVRegDefUses
A map from instructions that define/use a swifterror value to the virtual register that represents th...
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...
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
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.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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)
unsigned getOrCreateSwiftErrorVReg(const MachineBasicBlock *, const Value *)
Get or create the swifterror value virtual register in SwiftErrorVRegDefMap for this basic block...