13 #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H 14 #define LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H 46 class AtomicCmpXchgInst;
53 class CatchReturnInst;
54 class CatchSwitchInst;
56 class CleanupReturnInst;
59 class ConstrainedFPIntrinsic;
63 class DILocalVariable;
66 class FunctionLoweringInfo;
75 class MachineBasicBlock;
81 class SwiftErrorValueTracking;
83 class TargetLibraryInfo;
87 class UnreachableInst;
107 class DanglingDebugInfo {
110 unsigned SDNodeOrder = 0;
113 DanglingDebugInfo() =
default;
115 : DI(di), dl(std::move(DL)), SDNodeOrder(SDNO) {}
119 unsigned getSDNodeOrder() {
return SDNodeOrder; }
123 typedef std::vector<DanglingDebugInfo> DanglingDebugInfoVector;
162 unsigned SDNodeOrder;
297 class StackProtectorDescriptor {
299 StackProtectorDescriptor() =
default;
303 bool shouldEmitStackProtector()
const {
304 return ParentMBB && SuccessMBB && FailureMBB;
307 bool shouldEmitFunctionBasedCheckStackProtector()
const {
308 return ParentMBB && !SuccessMBB && !FailureMBB;
314 bool FunctionBasedInstrumentation) {
316 assert(!shouldEmitStackProtector() &&
"Stack Protector Descriptor is " 317 "already initialized!");
319 if (!FunctionBasedInstrumentation) {
320 SuccessMBB = AddSuccessorMBB(BB, MBB,
true);
321 FailureMBB = AddSuccessorMBB(BB, MBB,
false, FailureMBB);
335 void resetPerBBState() {
337 SuccessMBB =
nullptr;
349 void resetPerFunctionState() {
350 FailureMBB =
nullptr;
400 :
SwitchCG::SwitchLowering(funcinfo), SDB(sdb) {}
405 SDB->addSuccessorWithProb(Src, Dst, Prob);
412 std::unique_ptr<SDAGSwitchLowering>
SL;
442 : SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()), DAG(dag),
444 SwiftError(swifterror) {}
479 return SDLoc(CurInst, SDNodeOrder);
490 void visit(
unsigned Opcode,
const User &I);
525 if (NodeMap.
find(V) == NodeMap.
end())
527 return NodeMap[V].getNode();
535 assert(!N.
getNode() &&
"Already set a value for this node!");
541 assert(!N.
getNode() &&
"Already set a value for this node!");
569 const CallBase *Call,
unsigned ArgIdx,
570 unsigned NumArgs,
SDValue Callee,
571 Type *ReturnTy,
bool IsPatchPoint);
573 std::pair<SDValue, SDValue>
616 unsigned NumPatchBytes = -1;
641 bool VarArgDisallowed,
642 bool ForceVoidReturnTy);
664 void addSuccessorWithProb(
689 void visitUnary(
const User &I,
unsigned Opcode);
692 void visitBinary(
const User &I,
unsigned Opcode);
693 void visitShift(
const User &I,
unsigned Opcode);
694 void visitAdd(
const User &I) { visitBinary(I,
ISD::ADD); }
696 void visitSub(
const User &I) { visitBinary(I,
ISD::SUB); }
697 void visitFSub(
const User &I);
698 void visitMul(
const User &I) { visitBinary(I,
ISD::MUL); }
704 void visitSDiv(
const User &I);
706 void visitAnd (
const User &I) { visitBinary(I,
ISD::AND); }
707 void visitOr (
const User &I) { visitBinary(I,
ISD::OR); }
708 void visitXor (
const User &I) { visitBinary(I,
ISD::XOR); }
709 void visitShl (
const User &I) { visitShift(I,
ISD::SHL); }
710 void visitLShr(
const User &I) { visitShift(I,
ISD::SRL); }
711 void visitAShr(
const User &I) { visitShift(I,
ISD::SRA); }
712 void visitICmp(
const User &I);
713 void visitFCmp(
const User &I);
715 void visitTrunc(
const User &I);
716 void visitZExt(
const User &I);
717 void visitSExt(
const User &I);
718 void visitFPTrunc(
const User &I);
719 void visitFPExt(
const User &I);
720 void visitFPToUI(
const User &I);
721 void visitFPToSI(
const User &I);
722 void visitUIToFP(
const User &I);
723 void visitSIToFP(
const User &I);
724 void visitPtrToInt(
const User &I);
725 void visitIntToPtr(
const User &I);
726 void visitBitCast(
const User &I);
727 void visitAddrSpaceCast(
const User &I);
729 void visitExtractElement(
const User &I);
730 void visitInsertElement(
const User &I);
731 void visitShuffleVector(
const User &I);
733 void visitExtractValue(
const User &I);
734 void visitInsertValue(
const User &I);
737 void visitGetElementPtr(
const User &I);
738 void visitSelect(
const User &I);
743 void visitMaskedLoad(
const CallInst &I,
bool IsExpanding =
false);
744 void visitMaskedStore(
const CallInst &I,
bool IsCompressing =
false);
745 void visitMaskedGather(
const CallInst &I);
746 void visitMaskedScatter(
const CallInst &I);
750 void visitPHI(
const PHINode &I);
752 bool visitMemCmpCall(
const CallInst &I);
753 bool visitMemPCpyCall(
const CallInst &I);
754 bool visitMemChrCall(
const CallInst &I);
755 bool visitStrCpyCall(
const CallInst &I,
bool isStpcpy);
756 bool visitStrCmpCall(
const CallInst &I);
757 bool visitStrLenCall(
const CallInst &I);
758 bool visitStrNLenCall(
const CallInst &I);
759 bool visitUnaryFloatCall(
const CallInst &I,
unsigned Opcode);
760 bool visitBinaryFloatCall(
const CallInst &I,
unsigned Opcode);
761 void visitAtomicLoad(
const LoadInst &I);
762 void visitAtomicStore(
const StoreInst &I);
763 void visitLoadFromSwiftError(
const LoadInst &I);
764 void visitStoreToSwiftError(
const StoreInst &I);
768 void visitIntrinsicCall(
const CallInst &I,
unsigned Intrinsic);
769 void visitTargetIntrinsic(
const CallInst &I,
unsigned Intrinsic);
772 void visitVAStart(
const CallInst &I);
775 void visitVACopy(
const CallInst &I);
776 void visitStackmap(
const CallInst &I);
784 void visitVectorReduce(
const CallInst &I,
unsigned Intrinsic);
787 llvm_unreachable(
"UserOp1 should not exist at instruction selection time!");
790 llvm_unreachable(
"UserOp2 should not exist at instruction selection time!");
796 void HandlePHINodesInSuccessorBlocks(
const BasicBlock *LLVMBB);
803 bool EmitFuncArgumentDbgValue(
const Value *V,
DILocalVariable *Variable,
805 bool IsDbgDeclare,
const SDValue &
N);
812 void updateDAGForMaybeTailCall(
SDValue MaybeTC);
817 unsigned DbgSDNodeOrder);
820 void lowerCallToExternalSymbol(
const CallInst &I,
const char *FunctionName);
884 const Value *V =
nullptr)
const;
898 void AddInlineAsmOperands(
unsigned Code,
bool HasMatching,
899 unsigned MatchingIdx,
const SDLoc &dl,
904 return std::accumulate(RegCount.
begin(), RegCount.
end(), 0) > 1;
913 #endif // LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
Return a value (possibly void), from a function.
A parsed version of the target data layout string in and methods for querying it. ...
Represents calls to the gc.result intrinsic.
DebugLoc getCurDebugLoc() const
bool ShouldEmitAsBranches(const std::vector< SwitchCG::CaseBlock > &Cases)
If the set of cases should be emitted as a series of branches, return true.
CaseClusterVector::iterator CaseClusterIt
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
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)
void visitBitTestCase(SwitchCG::BitTestBlock &BB, MachineBasicBlock *NextMBB, BranchProbability BranchProbToNext, unsigned Reg, SwitchCG::BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
void LowerCallSiteWithDeoptBundle(const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB)
This class represents a function call, abstracting a target machine's calling convention.
void LowerDeoptimizingReturn()
void setValue(const Value *V, SDValue NewN)
Optional< CallingConv::ID > CallConv
Records if this value needs to be treated in an ABI dependant manner, different to normal type legali...
SwiftErrorValueTracking & SwiftError
Information about the swifterror values used throughout the function.
SDNode * getNodeForIRValue(const Value *V)
Return the SDNode for the specified IR value if it exists.
This class implements a map that also provides access to all stored values in a deterministic order...
This structure is used to communicate between SelectionDAGBuilder and SDISel for the code generation ...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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.
void visitBitTestHeader(SwitchCG::BitTestBlock &B, MachineBasicBlock *SwitchBB)
visitBitTestHeader - This function emits necessary code to produce value suitable for "bit tests" ...
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...
std::unique_ptr< SDAGSwitchLowering > SL
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()
Similar to getMemoryRoot, but also flushes PendingConstrainedFP(Strict) items.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StatepointLoweringInfo(SelectionDAG &DAG)
Shift and rotation operations.
void resolveOrClearDbgInfo()
Evict any dangling debug information, attempting to salvage it first.
ArrayRef< const Use > GCTransitionArgs
The list of gc transition arguments present in the gc.statepoint being lowered.
SDAGSwitchLowering(SelectionDAGBuilder *sdb, FunctionLoweringInfo &funcinfo)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
SmallVector< EVT, 4 > ValueVTs
The value types of the values, which may not be legal, and may need be promoted or synthesized from o...
std::vector< CaseCluster > CaseClusterVector
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...
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.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I, SDValue Op)
SDValue getMemoryRoot()
Return the current virtual root of the Selection DAG, flushing any PendingLoad items.
An instruction for storing to memory.
void init(GCFunctionInfo *gfi, AliasAnalysis *AA, const TargetLibraryInfo *li)
bool findValue(const Value *V) const
void visitJumpTable(SwitchCG::JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
void append(const RegsForValue &RHS)
Add the specified values to this one.
void salvageUnresolvedDbgValue(DanglingDebugInfo &DDI)
For the given dangling debuginfo record, perform last-ditch efforts to resolve the debuginfo to somet...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
iterator find(const_arg_type_t< KeyT > Val)
bool handleDebugValue(const Value *V, DILocalVariable *Var, DIExpression *Expr, DebugLoc CurDL, DebugLoc InstDL, unsigned Order)
For a given Value, attempt to create and record a SDDbgValue in the SelectionDAG. ...
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
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.
Resume the propagation of an exception.
Indirect Branch Instruction.
void LowerCallSiteWithDeoptBundleImpl(const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB, bool VarArgDisallowed, bool ForceVoidReturnTy)
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
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
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
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...
This struct represents the registers (physical or virtual) that a particular set of values is assigne...
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...
This class represents a freeze function that returns random concrete value if an operand is either a ...
void visit(const Instruction &I)
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
virtual void addSuccessorWithProb(MachineBasicBlock *Src, MachineBasicBlock *Dst, BranchProbability Prob=BranchProbability::getUnknown()) override
Represents one node in the SelectionDAG.
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
When an MBB was split during scheduling, update the references that need to refer to the last resulti...
GCFunctionInfo * GFI
Garbage collection metadata for the function.
amdgpu Simplify well known AMD library false FunctionCallee Callee
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.
SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo, SwiftErrorValueTracking &swifterror, CodeGenOpt::Level ol)
SmallVector< SDValue, 8 > PendingLoads
Loads are not emitted to the program immediately.
void LowerStatepoint(ImmutableStatepoint ISP, const BasicBlock *EHPadBB=nullptr)
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...
void visitJumpTableHeader(SwitchCG::JumpTable &JT, SwitchCG::JumpTableHeader &JTH, MachineBasicBlock *SwitchBB)
visitJumpTableHeader - This function emits necessary code to produce index in the JumpTable from swit...
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)
If there was virtual register allocated for the value V emit CopyFromReg of the specified type Ty...
void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall, const BasicBlock *EHPadBB=nullptr)
FunctionLoweringInfo & 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.
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI, const CallBase *Call, unsigned ArgIdx, unsigned NumArgs, SDValue Callee, Type *ReturnTy, bool IsPatchPoint)
Populate a CallLowerinInfo (into CLI) based on the properties of the call being lowered.
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...
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 (...
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.
A cluster of case labels.
Perform various unary floating-point operations inspired by libm.
SmallVector< unsigned, 4 > Regs
This list holds the registers assigned to the values.
SmallVector< const Value *, 16 > Ptrs
static const unsigned LowestSDNodeOrder
Lowest valid SDNodeOrder.
void visitSwitchCase(SwitchCG::CaseBlock &CB, MachineBasicBlock *SwitchBB)
visitSwitchCase - Emits the necessary code to represent a single node in the binary search tree resul...
void resolveDanglingDebugInfo(const Value *V, SDValue Val)
If we saw an earlier dbg_value referring to V, generate the debug data structures now that we've seen...
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.