LLVM  14.0.0git
AArch64SelectionDAGInfo.cpp
Go to the documentation of this file.
1 //===-- AArch64SelectionDAGInfo.cpp - AArch64 SelectionDAG Info -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the AArch64SelectionDAGInfo class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "AArch64TargetMachine.h"
14 using namespace llvm;
15 
16 #define DEBUG_TYPE "aarch64-selectiondag-info"
17 
19  SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
20  SDValue Size, Align Alignment, bool isVolatile,
21  MachinePointerInfo DstPtrInfo) const {
22  // Check to see if there is a specialized entry-point for memory zeroing.
23  ConstantSDNode *V = dyn_cast<ConstantSDNode>(Src);
24  ConstantSDNode *SizeValue = dyn_cast<ConstantSDNode>(Size);
25  const AArch64Subtarget &STI =
27  const char *bzeroName =
28  (V && V->isZero())
29  ? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO)
30  : nullptr;
31  // For small size (< 256), it is not beneficial to use bzero
32  // instead of memset.
33  if (bzeroName && (!SizeValue || SizeValue->getZExtValue() > 256)) {
34  const AArch64TargetLowering &TLI = *STI.getTargetLowering();
35 
36  EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout());
37  Type *IntPtrTy = Type::getInt8PtrTy(*DAG.getContext());
40  Entry.Node = Dst;
41  Entry.Ty = IntPtrTy;
42  Args.push_back(Entry);
43  Entry.Node = Size;
44  Args.push_back(Entry);
46  CLI.setDebugLoc(dl)
47  .setChain(Chain)
49  DAG.getExternalSymbol(bzeroName, IntPtr),
50  std::move(Args))
52  std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
53  return CallResult.second;
54  }
55  return SDValue();
56 }
57 
58 static const int kSetTagLoopThreshold = 176;
59 
61  SDValue Chain, SDValue Ptr, uint64_t ObjSize,
62  const MachineMemOperand *BaseMemOperand,
63  bool ZeroData) {
65  unsigned ObjSizeScaled = ObjSize / 16;
66 
67  SDValue TagSrc = Ptr;
68  if (Ptr.getOpcode() == ISD::FrameIndex) {
69  int FI = cast<FrameIndexSDNode>(Ptr)->getIndex();
70  Ptr = DAG.getTargetFrameIndex(FI, MVT::i64);
71  // A frame index operand may end up as [SP + offset] => it is fine to use SP
72  // register as the tag source.
73  TagSrc = DAG.getRegister(AArch64::SP, MVT::i64);
74  }
75 
76  const unsigned OpCode1 = ZeroData ? AArch64ISD::STZG : AArch64ISD::STG;
77  const unsigned OpCode2 = ZeroData ? AArch64ISD::STZ2G : AArch64ISD::ST2G;
78 
79  SmallVector<SDValue, 8> OutChains;
80  unsigned OffsetScaled = 0;
81  while (OffsetScaled < ObjSizeScaled) {
82  if (ObjSizeScaled - OffsetScaled >= 2) {
83  SDValue AddrNode =
84  DAG.getMemBasePlusOffset(Ptr, TypeSize::Fixed(OffsetScaled * 16), dl);
86  OpCode2, dl, DAG.getVTList(MVT::Other),
87  {Chain, TagSrc, AddrNode},
88  MVT::v4i64,
89  MF.getMachineMemOperand(BaseMemOperand, OffsetScaled * 16, 16 * 2));
90  OffsetScaled += 2;
91  OutChains.push_back(St);
92  continue;
93  }
94 
95  if (ObjSizeScaled - OffsetScaled > 0) {
96  SDValue AddrNode =
97  DAG.getMemBasePlusOffset(Ptr, TypeSize::Fixed(OffsetScaled * 16), dl);
99  OpCode1, dl, DAG.getVTList(MVT::Other),
100  {Chain, TagSrc, AddrNode},
101  MVT::v2i64,
102  MF.getMachineMemOperand(BaseMemOperand, OffsetScaled * 16, 16));
103  OffsetScaled += 1;
104  OutChains.push_back(St);
105  }
106  }
107 
108  SDValue Res = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OutChains);
109  return Res;
110 }
111 
113  SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Addr,
114  SDValue Size, MachinePointerInfo DstPtrInfo, bool ZeroData) const {
115  uint64_t ObjSize = cast<ConstantSDNode>(Size)->getZExtValue();
116  assert(ObjSize % 16 == 0);
117 
119  MachineMemOperand *BaseMemOperand = MF.getMachineMemOperand(
120  DstPtrInfo, MachineMemOperand::MOStore, ObjSize, Align(16));
121 
122  bool UseSetTagRangeLoop =
123  kSetTagLoopThreshold >= 0 && (int)ObjSize >= kSetTagLoopThreshold;
124  if (!UseSetTagRangeLoop)
125  return EmitUnrolledSetTag(DAG, dl, Chain, Addr, ObjSize, BaseMemOperand,
126  ZeroData);
127 
128  const EVT ResTys[] = {MVT::i64, MVT::i64, MVT::Other};
129 
130  unsigned Opcode;
131  if (Addr.getOpcode() == ISD::FrameIndex) {
132  int FI = cast<FrameIndexSDNode>(Addr)->getIndex();
133  Addr = DAG.getTargetFrameIndex(FI, MVT::i64);
134  Opcode = ZeroData ? AArch64::STZGloop : AArch64::STGloop;
135  } else {
136  Opcode = ZeroData ? AArch64::STZGloop_wback : AArch64::STGloop_wback;
137  }
138  SDValue Ops[] = {DAG.getTargetConstant(ObjSize, dl, MVT::i64), Addr, Chain};
139  SDNode *St = DAG.getMachineNode(Opcode, dl, ResTys, Ops);
140 
141  DAG.setNodeMemRefs(cast<MachineSDNode>(St), {BaseMemOperand});
142  return SDValue(St, 2);
143 }
llvm::CallingConv::C
@ C
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::ConstantSDNode
Definition: SelectionDAGNodes.h:1556
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition: SelectionDAGNodes.h:1086
llvm::Type::getInt8PtrTy
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:255
llvm::TargetLowering::CallLoweringInfo::setChain
CallLoweringInfo & setChain(SDValue InChain)
Definition: TargetLowering.h:3791
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::SelectionDAG::getVTList
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
Definition: SelectionDAG.cpp:8551
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition: MachineFunction.cpp:430
llvm::AArch64ISD::STG
@ STG
Definition: AArch64ISelLowering.h:437
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::TargetLoweringBase::getLibcallName
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
Definition: TargetLowering.h:2859
llvm::SelectionDAG::getMemBasePlusOffset
SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
Definition: SelectionDAG.cpp:6350
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:128
llvm::TargetLowering::LowerCallTo
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
Definition: SelectionDAGBuilder.cpp:9534
llvm::ConstantSDNode::isZero
bool isZero() const
Definition: SelectionDAGNodes.h:1580
llvm::SelectionDAG::getContext
LLVMContext * getContext() const
Definition: SelectionDAG.h:447
llvm::AArch64Subtarget::getTargetLowering
const AArch64TargetLowering * getTargetLowering() const override
Definition: AArch64Subtarget.h:316
llvm::SelectionDAG::getRegister
SDValue getRegister(unsigned Reg, EVT VT)
Definition: SelectionDAG.cpp:1985
EmitUnrolledSetTag
static SDValue EmitUnrolledSetTag(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Ptr, uint64_t ObjSize, const MachineMemOperand *BaseMemOperand, bool ZeroData)
Definition: AArch64SelectionDAGInfo.cpp:60
llvm::SelectionDAG::getTargetFrameIndex
SDValue getTargetFrameIndex(int FI, EVT VT)
Definition: SelectionDAG.h:688
AArch64TargetMachine.h
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:216
llvm::SelectionDAG::getTargetLoweringInfo
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:443
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:35
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::AArch64SelectionDAGInfo::EmitTargetCodeForMemset
SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVolatile, MachinePointerInfo DstPtrInfo) const override
Emit target-specific code that performs a memset.
Definition: AArch64SelectionDAGInfo.cpp:18
llvm::TargetLowering::CallLoweringInfo::setDebugLoc
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
Definition: TargetLowering.h:3786
llvm::TypeSize::Fixed
static TypeSize Fixed(ScalarTy MinVal)
Definition: TypeSize.h:423
llvm::AArch64ISD::STZ2G
@ STZ2G
Definition: AArch64ISelLowering.h:440
llvm::SelectionDAG::getMemIntrinsicNode
SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, uint64_t Size=0, const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
Definition: SelectionDAG.cpp:7239
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AArch64SelectionDAGInfo::EmitTargetCodeForSetTag
SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, MachinePointerInfo DstPtrInfo, bool ZeroData) const override
Definition: AArch64SelectionDAGInfo.cpp:112
llvm::MVT::v4i64
@ v4i64
Definition: MachineValueType.h:120
llvm::TargetLowering::CallLoweringInfo::setLibCallee
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
Definition: TargetLowering.h:3797
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::MVT::v2i64
@ v2i64
Definition: MachineValueType.h:118
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition: MachineMemOperand.h:38
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::SelectionDAG::getNode
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
Definition: SelectionDAG.cpp:8316
llvm::TargetLowering::CallLoweringInfo
This structure contains all information that is necessary for lowering calls.
Definition: TargetLowering.h:3747
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MVT::Other
@ Other
Definition: MachineValueType.h:42
llvm::TargetLoweringBase::ArgListEntry
Definition: TargetLowering.h:274
llvm::ConstantSDNode::getZExtValue
uint64_t getZExtValue() const
Definition: SelectionDAGNodes.h:1571
llvm::SelectionDAG::getMachineNode
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
Definition: SelectionDAG.cpp:8989
llvm::SelectionDAG::setNodeMemRefs
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
Definition: SelectionDAG.cpp:8757
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::MVT::i64
@ i64
Definition: MachineValueType.h:47
llvm::TargetLoweringBase::ArgListTy
std::vector< ArgListEntry > ArgListTy
Definition: TargetLowering.h:304
llvm::ISD::FrameIndex
@ FrameIndex
Definition: ISDOpcodes.h:80
kSetTagLoopThreshold
static const int kSetTagLoopThreshold
Definition: AArch64SelectionDAGInfo.cpp:58
llvm::AArch64ISD::STZG
@ STZG
Definition: AArch64ISelLowering.h:438
llvm::TargetLowering::CallLoweringInfo::setDiscardResult
CallLoweringInfo & setDiscardResult(bool Value=true)
Definition: TargetLowering.h:3866
llvm::SelectionDAG::getDataLayout
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:440
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:138
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition: MachineMemOperand.h:137
llvm::AArch64ISD::ST2G
@ ST2G
Definition: AArch64ISelLowering.h:439
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:186
llvm::SDValue::getOpcode
unsigned getOpcode() const
Definition: SelectionDAGNodes.h:1117
llvm::SelectionDAG::getTargetConstant
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:637
llvm::SelectionDAG::getMachineFunction
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:437
llvm::SelectionDAG::getExternalSymbol
SDValue getExternalSymbol(const char *Sym, EVT VT)
Definition: SelectionDAG.cpp:1736
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::AArch64Subtarget
Definition: AArch64Subtarget.h:38
llvm::AArch64TargetLowering
Definition: AArch64ISelLowering.h:484
llvm::AArch64TargetLowering::getPointerTy
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const override
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Definition: AArch64ISelLowering.h:502
llvm::ISD::TokenFactor
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:52