45 #define DEBUG_TYPE "function-lowering-info"
52 if (isa<PHINode>(I))
return true;
55 if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
70 unsigned NumOfSigned = 0, NumOfUnsigned = 0;
72 if (
const auto *CI = dyn_cast<CmpInst>(U)) {
73 NumOfSigned += CI->isSigned();
74 NumOfUnsigned += CI->isUnsigned();
77 if (NumOfSigned > NumOfUnsigned)
102 for (; BB != EB; ++BB)
105 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
I)) {
107 if (AI->isStaticAlloca()) {
108 const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize());
109 Type *Ty = AI->getAllocatedType();
116 if (TySize == 0) TySize = 1;
124 AI->getAllocatedType()),
126 unsigned StackAlign =
128 if (Align <= StackAlign)
136 if (isa<CallInst>(
I) || isa<InvokeInst>(
I)) {
139 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
141 std::vector<TargetLowering::AsmOperandInfo> Ops =
143 for (
size_t I = 0, E = Ops.size();
I != E; ++
I) {
147 TLI->ComputeConstraintToUse(Op,
SDValue(), DAG);
148 std::pair<unsigned, const TargetRegisterClass *> PhysReg =
151 if (PhysReg.first == SP)
161 if (
const auto *II = dyn_cast<IntrinsicInst>(
I)) {
162 if (II->getIntrinsicID() == Intrinsic::vastart)
168 if (
const auto *CI = dyn_cast<CallInst>(
I)) {
176 if (!isa<AllocaInst>(
I) ||
184 assert(
DI->getVariable() &&
"Missing variable");
185 assert(
DI->getDebugLoc() &&
"Missing location");
192 if (
const BitCastInst *BCI = dyn_cast<BitCastInst>(Address))
193 Address = BCI->getOperand(0);
194 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(Address)) {
200 FI,
DI->getDebugLoc());
214 for (BB =
Fn->
begin(); BB != EB; ++BB) {
222 if (BB->hasAddressTaken())
237 assert(PHIReg &&
"PHI node does not have an assigned virtual register!");
241 for (
unsigned vti = 0, vte = ValueVTs.
size(); vti != vte; ++vti) {
242 EVT VT = ValueVTs[vti];
243 unsigned NumRegisters = TLI->getNumRegisters(
Fn->
getContext(), VT);
245 for (
unsigned i = 0; i != NumRegisters; ++i)
247 PHIReg += NumRegisters;
254 for (BB =
Fn->
begin(); BB != EB; ++BB) {
255 if (
const auto *Invoke = dyn_cast<InvokeInst>(BB->getTerminator()))
256 MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad();
257 if (BB->isLandingPad())
258 LPads.
push_back(BB->getLandingPadInst());
270 addSEHHandlersForLPads(LPads);
291 void FunctionLoweringInfo::addSEHHandlersForLPads(
310 for (
auto I = Actions.
rbegin(), E = Actions.
rend();
I != E; ++
I) {
312 if (
auto *
CH = dyn_cast<CatchHandler>(Action)) {
315 assert((Filter ||
CH->getSelector()->isNullValue()) &&
316 "expected function or catch-all");
317 const auto *RecoverBA =
318 cast<BlockAddress>(
CH->getHandlerBlockOrFunc());
321 assert(isa<CleanupHandler>(Action));
334 "Not all catch info was assigned to a landing pad!");
343 LiveOutRegInfo.clear();
372 unsigned FirstReg = 0;
378 for (
unsigned i = 0; i != NumRegs; ++i) {
380 if (!FirstReg) FirstReg = R;
393 if (!LiveOutRegInfo.inBounds(Reg))
418 assert(ValueVTs.
size() == 1 &&
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)) {
436 APInt Zero(BitWidth, 0);
448 assert(
ValueMap.
count(V) &&
"V should have been placed in ValueMap when its"
449 "CopyToReg node was created.");
465 "Masks should have the same bit width as the type.");
469 if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
471 APInt Zero(BitWidth, 0);
485 assert(
ValueMap.
count(V) &&
"V should have been placed in ValueMap when "
486 "its CopyToReg node was created.");
519 DEBUG(
dbgs() <<
"Argument does not have assigned frame index!\n");
537 if (i->isFloatingPointTy()) {
568 Constant *CVal = cast<Constant>(Val);
572 FilterList.
push_back(cast<GlobalValue>((*II)->stripPointerCasts()));
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
const Value * getCalledValue() const
getCalledValue - Get a pointer to the function that is invoked by this instruction.
void push_back(const T &Elt)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
LLVM Argument representation.
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
WinEHFuncInfo & getWinEHFuncInfo(const Function *F)
SmallPtrSet< const Instruction *, 8 > CatchInfoFound
Intrinsic::ID getIntrinsicID() const
getIntrinsicID - Return the intrinsic ID of this intrinsic.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
DenseMap< const Instruction *, StatepointSpilledValueMapTy > StatepointRelocatedValues
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, unsigned Slot, const DILocation *Loc)
setVariableDbgInfo - Collect information used to emit debugging information of a variable.
Type * getReturnType() const
const Function * getParent() const
Return the enclosing method, or null if none.
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
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...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
static bool isUsedOutsideOfDefiningBlock(const Instruction *I)
isUsedOutsideOfDefiningBlock - Return true if this instruction is used by PHI nodes or outside of the...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const HexagonInstrInfo * TII
A Use represents the edge between a Value definition and its users.
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of call arguments.
Reg
All possible values of the reg field in the ModR/M byte.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool hasDebugInfo() const
hasDebugInfo - Returns true if valid debug info is present.
bool usesVAFloatArgument() const
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
FunctionType - Class to represent function types.
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
void setHasMustTailInVarArgFunc(bool B)
const LiveOutInfo * GetLiveOutRegInfo(unsigned Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
void GetReturnInfo(Type *ReturnType, AttributeSet 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...
This contains information for each constraint that we are lowering.
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static ISD::NodeType getPreferredExtendForValue(const Value *V)
unsigned getNumClauses() const
getNumClauses - Get the number of clauses for this landing pad.
void addPersonality(MachineBasicBlock *LandingPad, const Function *Personality)
addPersonality - Provide the personality function for the exception information.
ConstraintPrefix Type
Type - The basic type of the constraint: input/output/clobber.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
void setHasOpaqueSPAdjustment(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void addFilterTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue * > TyInfo)
addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
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...
void AddLandingPadInfo(const LandingPadInst &I, MachineModuleInfo &MMI, MachineBasicBlock *MBB)
AddLandingPadInfo - Extract the exception handling information from the landingpad instruction and ad...
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
TargetInstrInfo - Interface to description of machine instruction set.
void clear()
clear - Clear out all the function-specific state.
DenseMap< const LandingPadInst *, int > LandingPadStateMap
SmallPtrSet< const Instruction *, 8 > CatchInfoLost
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
Constant * stripPointerCasts()
MVT - Machine Value Type.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
void addCatchTypeInfo(MachineBasicBlock *LandingPad, ArrayRef< const GlobalValue * > TyInfo)
addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
Type * getContainedType(unsigned i) const
getContainedType - This method is used to implement the type iterator (defined at the end of the file...
This is an important base class in LLVM.
bool hasPersonalityFn() const
Get the personality function associated with this function.
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
void setHasVAStart(bool B)
unsigned getBitWidth() const
Return the number of bits in the APInt.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
iterator_range< po_iterator< T > > post_order(const T &G)
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
EVT - Extended Value Type.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVMContext & getContext() const
All values hold a context through their type.
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination register based on the LiveOutI...
std::string ConstraintCode
This contains the actual string for the code, like "m".
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
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 calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which describes the state number...
virtual const TargetFrameLowering * getFrameLowering() const
This is the shared class of boolean and integer constants.
void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter, const BlockAddress *RecoverLabel)
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Constant * getHandlerBlockOrFunc()
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.
Type * getType() const
All values are typed, get the type of this value.
virtual const TargetLowering * getTargetLowering() const
void addSEHCleanupHandler(MachineBasicBlock *LandingPad, const Function *Cleanup)
void addCleanup(MachineBasicBlock *LandingPad)
addCleanup - Add a cleanup action for a landing pad.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
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.
AttributeSet getAttributes() const
Return the attribute list for this Function.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
void addWinEHState(MachineBasicBlock *LandingPad, int State)
Class for arbitrary precision integers.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
iterator_range< user_iterator > users()
void setHasAddressTaken()
setHasAddressTaken - Set this block to reflect that it potentially is the target of an indirect branc...
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ANY_EXTEND - Used for integer types. The high bits are undefined.
const Function * getWinEHParent(const Function *F) const
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
MachineRegisterInfo * RegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Constant * getPersonalityFn() const
DenseMap< const Argument *, int > ByValArgFrameIndexMap
ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
ImmutableCallSite - establish a view to a call site for examination.
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
bool isCatch(unsigned Idx) const
isCatch - Return 'true' if the clause and index Idx is a catch clause.
void setUsesVAFloatArgument(bool b)
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...
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
reverse_iterator rbegin()
bool isEmptyTy() const
isEmptyTy - Return true if this type is empty, that is, it has no elements or all its elements are em...
virtual const TargetInstrInfo * getInstrInfo() const
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
void push_back(MachineBasicBlock *MBB)
bool isCleanup() const
isCleanup - Return 'true' if this landingpad instruction is a cleanup.
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MachineModuleInfo & getMMI() const
const TargetLowering * TLI
MVT ConstraintVT
The ValueType for the operand value.
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 ComputeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo *MMI)
ComputeUsesVAFloatArgument - Determine if any floating-point values are being passed to this variadic...
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
DbgDeclareInst - This represents the llvm.dbg.declare instruction.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
const BasicBlock * getParent() const
bool isMSVCEHPersonality(EHPersonality Pers)
Returns true if this is an MSVC personality function.
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
void parseEHActions(const IntrinsicInst *II, SmallVectorImpl< std::unique_ptr< ActionHandler >> &Actions)
MachineModuleInfo - This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
AllocaInst - an instruction to allocate memory on the stack.
unsigned InitializeRegForValue(const Value *V)