14 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H 15 #define LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H 45 class AtomicCmpXchgInst;
51 class CatchReturnInst;
52 class CatchSwitchInst;
54 class CleanupReturnInst;
57 class ConstrainedFPIntrinsic;
61 class DILocalVariable;
64 class FunctionLoweringInfo;
73 class MachineBasicBlock;
80 class TargetLibraryInfo;
84 class UnreachableInst;
104 class DanglingDebugInfo {
107 unsigned SDNodeOrder = 0;
110 DanglingDebugInfo() =
default;
112 : DI(di), dl(std::move(DL)), SDNodeOrder(SDNO) {}
116 unsigned getSDNodeOrder() {
return SDNodeOrder; }
120 typedef std::vector<DanglingDebugInfo> DanglingDebugInfoVector;
147 unsigned SDNodeOrder;
149 enum CaseClusterKind {
161 CaseClusterKind
Kind;
165 unsigned JTCasesIndex;
166 unsigned BTCasesIndex;
181 static CaseCluster jumpTable(
const ConstantInt *Low,
185 C.Kind = CC_JumpTable;
188 C.JTCasesIndex = JTCasesIndex;
196 C.Kind = CC_BitTests;
199 C.BTCasesIndex = BTCasesIndex;
205 using CaseClusterVector = std::vector<CaseCluster>;
206 using CaseClusterIt = CaseClusterVector::iterator;
214 CaseBits() =
default;
217 Mask(mask), BB(bb),
Bits(bits), ExtraProb(Prob) {}
220 using CaseBitsVector = std::vector<CaseBits>;
223 void sortAndRangeify(CaseClusterVector &Clusters);
235 const Value *CmpLHS, *CmpMHS, *CmpRHS;
256 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
257 TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
DL(dl),
258 TrueProb(trueprob), FalseProb(falseprob) {}
276 struct JumpTableHeader {
285 : First(std::move(F)), Last(std::move(L)), SValue(SV), HeaderBB(H),
288 using JumpTableBlock = std::pair<JumpTableHeader, JumpTable>;
298 Mask(M), ThisBB(T), TargetBB(Tr), ExtraProb(Prob) {}
303 struct BitTestBlock {
310 bool ContiguousRange;
320 : First(std::move(F)), Range(std::move(R)), SValue(SV),
Reg(Rg),
321 RegVT(RgVT), Emitted(E), ContiguousRange(CR), Parent(P),
Default(D),
322 Cases(std::move(C)), Prob(Pr) {}
326 uint64_t getJumpTableRange(
const CaseClusterVector &Clusters,
unsigned First,
327 unsigned Last)
const;
331 unsigned First,
unsigned Last)
const;
335 bool buildJumpTable(
const CaseClusterVector &Clusters,
unsigned First,
340 void findJumpTables(CaseClusterVector &Clusters,
const SwitchInst *SI,
345 bool buildBitTests(CaseClusterVector &Clusters,
unsigned First,
unsigned Last,
346 const SwitchInst *SI, CaseCluster &BTCluster);
349 void findBitTestClusters(CaseClusterVector &Clusters,
const SwitchInst *SI);
351 struct SwitchWorkListItem {
353 CaseClusterIt FirstCluster;
354 CaseClusterIt LastCluster;
363 static unsigned caseClusterRank(
const CaseCluster &CC, CaseClusterIt First,
367 void splitWorkItem(
SwitchWorkList &WorkList,
const SwitchWorkListItem &
W,
371 void lowerWorkItem(SwitchWorkListItem W,
Value *Cond,
377 CaseClusterVector &Clusters,
491 class StackProtectorDescriptor {
493 StackProtectorDescriptor() =
default;
497 bool shouldEmitStackProtector()
const {
498 return ParentMBB && SuccessMBB && FailureMBB;
501 bool shouldEmitFunctionBasedCheckStackProtector()
const {
502 return ParentMBB && !SuccessMBB && !FailureMBB;
508 bool FunctionBasedInstrumentation) {
510 assert(!shouldEmitStackProtector() &&
"Stack Protector Descriptor is " 511 "already initialized!");
513 if (!FunctionBasedInstrumentation) {
514 SuccessMBB = AddSuccessorMBB(BB, MBB,
true);
515 FailureMBB = AddSuccessorMBB(BB, MBB,
false, FailureMBB);
529 void resetPerBBState() {
531 SuccessMBB =
nullptr;
543 void resetPerFunctionState() {
544 FailureMBB =
nullptr;
630 : SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()), DAG(dag),
631 FuncInfo(funcinfo) {}
660 return SDLoc(CurInst, SDNodeOrder);
671 void visit(
unsigned Opcode,
const User &I);
692 if (NodeMap.
find(V) == NodeMap.
end())
694 return NodeMap[V].getNode();
702 assert(!N.
getNode() &&
"Already set a value for this node!");
708 assert(!N.
getNode() &&
"Already set a value for this node!");
737 unsigned NumArgs,
SDValue Callee,
738 Type *ReturnTy,
bool IsPatchPoint);
740 std::pair<SDValue, SDValue>
783 unsigned NumPatchBytes = -1;
808 bool VarArgDisallowed,
809 bool ForceVoidReturnTy);
831 void addSuccessorWithProb(
857 void visitUnary(
const User &I,
unsigned Opcode);
860 void visitBinary(
const User &I,
unsigned Opcode);
861 void visitShift(
const User &I,
unsigned Opcode);
862 void visitAdd(
const User &I) { visitBinary(I,
ISD::ADD); }
864 void visitSub(
const User &I) { visitBinary(I,
ISD::SUB); }
865 void visitFSub(
const User &I);
866 void visitMul(
const User &I) { visitBinary(I,
ISD::MUL); }
872 void visitSDiv(
const User &I);
874 void visitAnd (
const User &I) { visitBinary(I,
ISD::AND); }
875 void visitOr (
const User &I) { visitBinary(I,
ISD::OR); }
876 void visitXor (
const User &I) { visitBinary(I,
ISD::XOR); }
877 void visitShl (
const User &I) { visitShift(I,
ISD::SHL); }
878 void visitLShr(
const User &I) { visitShift(I,
ISD::SRL); }
879 void visitAShr(
const User &I) { visitShift(I,
ISD::SRA); }
880 void visitICmp(
const User &I);
881 void visitFCmp(
const User &I);
883 void visitTrunc(
const User &I);
884 void visitZExt(
const User &I);
885 void visitSExt(
const User &I);
886 void visitFPTrunc(
const User &I);
887 void visitFPExt(
const User &I);
888 void visitFPToUI(
const User &I);
889 void visitFPToSI(
const User &I);
890 void visitUIToFP(
const User &I);
891 void visitSIToFP(
const User &I);
892 void visitPtrToInt(
const User &I);
893 void visitIntToPtr(
const User &I);
894 void visitBitCast(
const User &I);
895 void visitAddrSpaceCast(
const User &I);
897 void visitExtractElement(
const User &I);
898 void visitInsertElement(
const User &I);
899 void visitShuffleVector(
const User &I);
901 void visitExtractValue(
const User &I);
902 void visitInsertValue(
const User &I);
905 void visitGetElementPtr(
const User &I);
906 void visitSelect(
const User &I);
911 void visitMaskedLoad(
const CallInst &I,
bool IsExpanding =
false);
912 void visitMaskedStore(
const CallInst &I,
bool IsCompressing =
false);
913 void visitMaskedGather(
const CallInst &I);
914 void visitMaskedScatter(
const CallInst &I);
918 void visitPHI(
const PHINode &I);
920 bool visitMemCmpCall(
const CallInst &I);
921 bool visitMemPCpyCall(
const CallInst &I);
922 bool visitMemChrCall(
const CallInst &I);
923 bool visitStrCpyCall(
const CallInst &I,
bool isStpcpy);
924 bool visitStrCmpCall(
const CallInst &I);
925 bool visitStrLenCall(
const CallInst &I);
926 bool visitStrNLenCall(
const CallInst &I);
927 bool visitUnaryFloatCall(
const CallInst &I,
unsigned Opcode);
928 bool visitBinaryFloatCall(
const CallInst &I,
unsigned Opcode);
929 void visitAtomicLoad(
const LoadInst &I);
930 void visitAtomicStore(
const StoreInst &I);
931 void visitLoadFromSwiftError(
const LoadInst &I);
932 void visitStoreToSwiftError(
const StoreInst &I);
935 const char *visitIntrinsicCall(
const CallInst &I,
unsigned Intrinsic);
936 void visitTargetIntrinsic(
const CallInst &I,
unsigned Intrinsic);
939 void visitVAStart(
const CallInst &I);
942 void visitVACopy(
const CallInst &I);
943 void visitStackmap(
const CallInst &I);
951 void visitVectorReduce(
const CallInst &I,
unsigned Intrinsic);
954 llvm_unreachable(
"UserOp1 should not exist at instruction selection time!");
957 llvm_unreachable(
"UserOp2 should not exist at instruction selection time!");
963 void HandlePHINodesInSuccessorBlocks(
const BasicBlock *LLVMBB);
970 bool EmitFuncArgumentDbgValue(
const Value *V,
DILocalVariable *Variable,
972 bool IsDbgDeclare,
const SDValue &
N);
979 void updateDAGForMaybeTailCall(
SDValue MaybeTC);
984 unsigned DbgSDNodeOrder);
1048 const Value *V =
nullptr)
const;
1062 void AddInlineAsmOperands(
unsigned Code,
bool HasMatching,
1063 unsigned MatchingIdx,
const SDLoc &dl,
1068 return std::accumulate(RegCount.
begin(), RegCount.
end(), 0) > 1;
1077 #endif // LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
Return a value (possibly void), from a function.
std::vector< BitTestBlock > BitTestCases
BitTestCases - Vector of BitTestBlock structures used to communicate SwitchInst code generation infor...
A parsed version of the target data layout string in and methods for querying it. ...
Represents calls to the gc.result intrinsic.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
DebugLoc getCurDebugLoc() const
This class represents lattice values for constants.
void ExportFromCurrentBlock(const Value *V)
ExportFromCurrentBlock - If this condition isn't known to be exported from the current basic block...
const TargetLibraryInfo * LibInfo
StatepointFlags
The statepoint intrinsic accepts a set of flags as its third argument.
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
LPadToCallSiteMap - Map a landing pad to the call site indexes.
void LowerDeoptimizeCall(const CallInst *CI)
An instruction for ordering other memory operations.
TargetLowering::CallLoweringInfo CLI
Information regarding the underlying call instruction.
void CopyValueToVirtualRegister(const Value *V, unsigned Reg)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
SmallVector< const GCRelocateInst *, 16 > GCRelocates
The set of gc.relocate calls associated with this gc.statepoint.
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
A specialization of it's base class for read only access to a gc.statepoint.
bool isABIMangled() const
void push_back(const T &Elt)
SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo, CodeGenOpt::Level ol)
This class represents a function call, abstracting a target machine's calling convention.
void LowerDeoptimizingReturn()
void setValue(const Value *V, SDValue NewN)
void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH, MachineBasicBlock *SwitchBB)
visitJumpTableHeader - This function emits necessary code to produce index in the JumpTable from swit...
Optional< CallingConv::ID > CallConv
Records if this value needs to be treated in an ABI dependant manner, different to normal type legali...
SDNode * getNodeForIRValue(const Value *V)
Return the SDNode for the specified IR value if it exists.
An instruction for reading from memory.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
SDNode * getNode() const
get the SDNode which holds the desired result
This is the common base class for constrained floating point intrinsics.
SDValue getValueImpl(const Value *V)
getValueImpl - Helper function for getValue and getNonRegisterValue.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB, Instruction::BinaryOps Opc, BranchProbability TProb, BranchProbability FProb, bool InvertCond)
void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB, BranchProbability TProb, BranchProbability FProb, bool InvertCond)
EmitBranchForMergedCondition - Helper method for FindMergedConditions.
SDValue getValue(const Value *V)
getValue - Return an SDValue for the given Value.
StackProtectorDescriptor SPDescriptor
A StackProtectorDescriptor structure used to communicate stack protector information in between Selec...
void visitSPDescriptorParent(StackProtectorDescriptor &SPD, MachineBasicBlock *ParentBB)
Codegen a new tail for a stack protector check ParentMBB which has had its tail spliced into a stack ...
SDValue getRoot()
Return the current virtual root of the Selection DAG, flushing any PendingLoad items.
void visitSwitchCase(CaseBlock &CB, MachineBasicBlock *SwitchBB)
visitSwitchCase - Emits the necessary code to represent a single node in the binary search tree resul...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StatepointLoweringInfo(SelectionDAG &DAG)
Shift and rotation operations.
void visitJumpTable(JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
ArrayRef< const Use > GCTransitionArgs
The list of gc transition arguments present in the gc.statepoint being lowered.
SmallVector< EVT, 4 > ValueVTs
The value types of the values, which may not be legal, and may need be promoted or synthesized from o...
const DataLayout & getDataLayout() const
SDValue LowerAsSTATEPOINT(StatepointLoweringInfo &SI)
Lower SLI into a STATEPOINT instruction.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
void LowerCallSiteWithDeoptBundle(ImmutableCallSite CS, SDValue Callee, const BasicBlock *EHPadBB)
This file implements a class to represent arbitrary precision integral constant values and operations...
Simple integer binary arithmetic operators.
SDValue getNonRegisterValue(const Value *V)
getNonRegisterValue - Return an SDValue for the given Value, but don't look in FuncInfo.ValueMap for a virtual register.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool ShouldEmitAsBranches(const std::vector< CaseBlock > &Cases)
If the set of cases should be emitted as a series of branches, return true.
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I, SDValue Op)
An instruction for storing to memory.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
void init(GCFunctionInfo *gfi, AliasAnalysis *AA, const TargetLibraryInfo *li)
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI, ImmutableCallSite CS, unsigned ArgIdx, unsigned NumArgs, SDValue Callee, Type *ReturnTy, bool IsPatchPoint)
Populate a CallLowerinInfo (into CLI) based on the properties of the call being lowered.
bool findValue(const Value *V) const
amdgpu Simplify well known AMD library false Value * Callee
void append(const RegsForValue &RHS)
Add the specified values to this one.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< SDValue, SDValue > lowerInvokable(TargetLowering::CallLoweringInfo &CLI, const BasicBlock *EHPadBB=nullptr)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool HasTailCall
HasTailCall - This is set to true if a call in the current block has been translated as a tail call...
ArrayRef< const Use > DeoptState
The deoptimization state associated with this gc.statepoint call, if any.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Simple binary floating point operators.
Conditional or Unconditional Branch instruction.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Resume the propagation of an exception.
Indirect Branch Instruction.
void dropDanglingDebugInfo(const DILocalVariable *Variable, const DIExpression *Expr)
If we have dangling debug info that describes Variable, or an overlapping part of variable considerin...
This class tracks both per-statepoint and per-selectiondag information.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
This structure contains all information that is necessary for lowering calls.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SDLoc getCurSDLoc() const
void CopyToExportRegsIfNeeded(const Value *V)
CopyToExportRegsIfNeeded - If the given value has virtual registers created for it, emit nodes to copy the value into the virtual registers.
static BranchProbability getUnknown()
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
Codegen the failure basic block for a stack protector check.
const TargetLowering & getTargetLoweringInfo() const
This is the shared class of boolean and integer constants.
SmallVector< unsigned, 4 > RegCount
This list holds the number of registers for each value.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
RegsForValue - This struct represents the registers (physical or virtual) that a particular set of va...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
void clear()
Clear out the current SelectionDAG and the associated state and prepare this SelectionDAGBuilder obje...
void visit(const Instruction &I)
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Represents one node in the SelectionDAG.
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
UpdateSplitBlock - When an MBB was split during scheduling, update the references that need to refer ...
GCFunctionInfo * GFI
GFI - Garbage collection metadata for the function.
Class for arbitrary precision integers.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > StandardNames)
Initialize the set of available library functions based on the specified target triple.
void visitBitTestCase(BitTestBlock &BB, MachineBasicBlock *NextMBB, BranchProbability BranchProbToNext, unsigned Reg, BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
std::vector< JumpTableBlock > JTCases
JTCases - Vector of JumpTable structures used to communicate SwitchInst code generation information...
ANY_EXTEND - Used for integer types. The high bits are undefined.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
SmallVector< SDValue, 8 > PendingLoads
PendingLoads - Loads are not emitted to the program immediately.
void LowerStatepoint(ImmutableStatepoint ISP, const BasicBlock *EHPadBB=nullptr)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Bitwise operators - logical and, logical or, logical xor.
This represents the llvm.dbg.value instruction.
Establish a view to a call site for examination.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
SmallVector< const Value *, 16 > Bases
Bases[i] is the base pointer for Ptrs[i].
StatepointLoweringState StatepointLowering
State used while lowering a statepoint sequence (gc_statepoint, gc_relocate, and gc_result).
SDValue getCopyFromRegs(const Value *V, Type *Ty)
getCopyFromRegs - If there was virtual register allocated for the value V emit CopyFromReg of the spe...
void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall, const BasicBlock *EHPadBB=nullptr)
void LowerCallSiteWithDeoptBundleImpl(ImmutableCallSite CS, SDValue Callee, const BasicBlock *EHPadBB, bool VarArgDisallowed, bool ForceVoidReturnTy)
FunctionLoweringInfo & FuncInfo
FuncInfo - Information about the function as a whole.
SmallVector< MVT, 4 > RegVTs
The value types of the registers.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setUnusedArgValue(const Value *V, SDValue NewN)
Represents calls to the gc.relocate intrinsic.
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ArrayRef< const Use > GCArgs
The full list of gc arguments to the gc.statepoint being lowered.
MVT getFrameIndexTy()
Returns the type of FrameIndex and TargetFrameIndex nodes.
MVT getFrameIndexTy(const DataLayout &DL) const
Return the type for frame index, which is determined by the alloca address space specified through th...
std::vector< CaseBlock > SwitchCases
SwitchCases - Vector of CaseBlock structures used to communicate SwitchInst code generation informati...
Primary interface to the complete machine description for the target machine.
SDValue getControlRoot()
Similar to getRoot, but instead of flushing all the PendingLoad items, flush all the PendingExports i...
Garbage collection metadata for a single function.
void clearDanglingDebugInfo()
Clear the dangling debug information map.
DenseMap< const Constant *, unsigned > ConstantsOut
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB)
Holds the information from a dbg_value node through SDISel.
Perform various unary floating-point operations inspired by libm.
SmallVector< unsigned, 4 > Regs
This list holds the registers assigned to the values.
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB)
visitBitTestHeader - This function emits necessary code to produce value suitable for "bit tests" ...
SmallVector< const Value *, 16 > Ptrs
static const unsigned LowestSDNodeOrder
Lowest valid SDNodeOrder.
void resolveDanglingDebugInfo(const Value *V, SDValue Val)
Describes a gc.statepoint or a gc.statepoint like thing for the purposes of lowering into a STATEPOIN...
This file describes how to lower LLVM code to machine code.
an instruction to allocate memory on the stack
bool occupiesMultipleRegs() const
Check if the total RegCount is greater than one.