18#define DEBUG_TYPE "arm-selectiondag-info"
22 cl::desc(
"Control conversion of memcpy to "
23 "Tail predicated loops (WLSTP)"),
26 "Don't convert memcpy to TP loop."),
28 "Always convert memcpy to TP loop."),
30 "Allow (may be subject to certain conditions) "
31 "conversion of memcpy to TP loop.")));
62 if (TLI->getLibcallImpl(LC) != RTLIB::impl___aeabi_memcpy)
65 AEABILibcall = AEABI_MEMCPY;
68 if (TLI->getLibcallImpl(LC) != RTLIB::impl___aeabi_memmove)
71 AEABILibcall = AEABI_MEMMOVE;
74 if (TLI->getLibcallImpl(LC) != RTLIB::impl___aeabi_memset)
77 AEABILibcall = AEABI_MEMSET;
79 AEABILibcall = AEABI_MEMCLR;
92 AlignVariant = ALIGN8;
93 else if ((
Align & 3) == 0)
94 AlignVariant = ALIGN4;
96 AlignVariant = ALIGN1;
100 Args.emplace_back(Dst, IntPtrTy);
101 if (AEABILibcall == AEABI_MEMCLR) {
102 Args.emplace_back(
Size, IntPtrTy);
103 }
else if (AEABILibcall == AEABI_MEMSET) {
107 Args.emplace_back(
Size, IntPtrTy);
110 if (Src.getValueType().bitsGT(MVT::i32))
112 else if (Src.getValueType().bitsLT(MVT::i32))
117 Entry.IsSExt =
false;
118 Args.push_back(Entry);
120 Args.emplace_back(Src, IntPtrTy);
121 Args.emplace_back(
Size, IntPtrTy);
124 static const RTLIB::Libcall FunctionImpls[4][3] = {
125 {RTLIB::MEMCPY, RTLIB::AEABI_MEMCPY4, RTLIB::AEABI_MEMCPY8},
126 {RTLIB::MEMMOVE, RTLIB::AEABI_MEMMOVE4, RTLIB::AEABI_MEMMOVE8},
127 {RTLIB::MEMSET, RTLIB::AEABI_MEMSET4, RTLIB::AEABI_MEMSET8},
128 {RTLIB::AEABI_MEMCLR, RTLIB::AEABI_MEMCLR4, RTLIB::AEABI_MEMCLR8}};
130 RTLIB::Libcall NewLC = FunctionImpls[AEABILibcall][AlignVariant];
141 std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
143 return CallResult.second;
149 Align Alignment,
bool IsMemcpy) {
157 if (
F.hasOptNone() ||
F.hasOptSize())
163 if (!ConstantSize && Alignment >=
Align(4))
181 if (Subtarget.hasMVEIntegerOps() &&
188 if (Alignment <
Align(4))
194 Alignment.
value(), RTLIB::MEMCPY);
195 uint64_t SizeVal = ConstantSize->getZExtValue();
198 Alignment.
value(), RTLIB::MEMCPY);
200 unsigned BytesLeft = SizeVal & 3;
201 unsigned NumMemOps = SizeVal >> 2;
202 unsigned EmittedNumMemOps = 0;
207 const unsigned MaxLoadsInLDM = Subtarget.
isThumb1Only() ? 4 : 6;
221 unsigned NumMEMCPYs = (NumMemOps + MaxLoadsInLDM - 1) / MaxLoadsInLDM;
225 if (NumMEMCPYs > 1 && Subtarget.
hasMinSize()) {
231 for (
unsigned I = 0;
I != NumMEMCPYs; ++
I) {
234 unsigned NextEmittedNumMemOps = NumMemOps * (
I + 1) / NumMEMCPYs;
235 unsigned NumRegs = NextEmittedNumMemOps - EmittedNumMemOps;
245 EmittedNumMemOps = NextEmittedNumMemOps;
252 auto getRemainingValueType = [](
unsigned BytesLeft) {
253 return (BytesLeft >= 2) ? MVT::i16 : MVT::i8;
255 auto getRemainingSize = [](
unsigned BytesLeft) {
256 return (BytesLeft >= 2) ? 2 : 1;
259 unsigned BytesLeftSave = BytesLeft;
262 VT = getRemainingValueType(BytesLeft);
263 VTSize = getRemainingSize(BytesLeft);
264 Loads[i] = DAG.
getLoad(VT, dl, Chain,
276 BytesLeft = BytesLeftSave;
278 VT = getRemainingValueType(BytesLeft);
279 VTSize = getRemainingSize(BytesLeft);
280 TFOps[i] = DAG.
getStore(Chain, dl, Loads[i],
296 Alignment.
value(), RTLIB::MEMMOVE);
310 if (Subtarget.hasMVEIntegerOps() &&
321 Alignment.
value(), RTLIB::MEMSET);
static bool shouldGenerateInlineTPLoop(const ARMSubtarget &Subtarget, const SelectionDAG &DAG, ConstantSDNode *ConstantSize, Align Alignment, bool IsMemcpy)
static cl::opt< TPLoop::MemTransfer > EnableMemtransferTPLoop("arm-memtransfer-tploop", cl::Hidden, cl::desc("Control conversion of memcpy to " "Tail predicated loops (WLSTP)"), cl::init(TPLoop::ForceDisabled), cl::values(clEnumValN(TPLoop::ForceDisabled, "force-disabled", "Don't convert memcpy to TP loop."), clEnumValN(TPLoop::ForceEnabled, "force-enabled", "Always convert memcpy to TP loop."), clEnumValN(TPLoop::Allow, "allow", "Allow (may be subject to certain conditions) " "conversion of memcpy to TP loop.")))
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
SDValue EmitSpecializedLibcall(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, SDValue Size, unsigned Align, RTLIB::Libcall LC) const
SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo) const override
Emit target-specific code that performs a memset.
SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const override
Emit target-specific code that performs a memcpy.
SDValue EmitTargetCodeForMemmove(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVolatile, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const override
Emit target-specific code that performs a memmove.
bool isTargetMemoryOpcode(unsigned Opcode) const override
Returns true if a node with the given target-specific opcode has a memory operand.
bool isThumb1Only() const
const ARMTargetLowering * getTargetLowering() const override
unsigned getMaxMemcpyTPInlineSizeThreshold() const
getMaxMemcpyTPInlineSizeThreshold - Returns the maximum size that still makes it profitable to inline...
unsigned getMaxInlineSizeThreshold() const
getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size that still makes it profitable t...
uint64_t getZExtValue() const
LLVM_ABI IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDValue getValue(unsigned R) const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineFunction & getMachineFunction() const
SDValue getSplatBuildVector(EVT VT, const SDLoc &DL, SDValue Op)
Return a splat ISD::BUILD_VECTOR node, consisting of Op splatted to all elements.
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVMContext * getContext() const
std::vector< ArgListEntry > ArgListTy
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
@ ADD
Simple integer binary arithmetic operators.
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
This class contains a discriminated union of information about pointers in memory operands,...
MachinePointerInfo getWithOffset(int64_t O) const
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This structure contains all information that is necessary for lowering calls.
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
CallLoweringInfo & setDiscardResult(bool Value=true)
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
CallLoweringInfo & setChain(SDValue InChain)