1*9880d681SAndroid Build Coastguard Worker //===-- SystemZSelectionDAGInfo.cpp - SystemZ SelectionDAG Info -----------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements the SystemZSelectionDAGInfo class.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker #include "SystemZTargetMachine.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/SelectionDAG.h"
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker using namespace llvm;
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "systemz-selectiondag-info"
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker // Decide whether it is best to use a loop or straight-line code for
22*9880d681SAndroid Build Coastguard Worker // a block operation of Size bytes with source address Src and destination
23*9880d681SAndroid Build Coastguard Worker // address Dest. Sequence is the opcode to use for straight-line code
24*9880d681SAndroid Build Coastguard Worker // (such as MVC) and Loop is the opcode to use for loops (such as MVC_LOOP).
25*9880d681SAndroid Build Coastguard Worker // Return the chain for the completed operation.
emitMemMem(SelectionDAG & DAG,const SDLoc & DL,unsigned Sequence,unsigned Loop,SDValue Chain,SDValue Dst,SDValue Src,uint64_t Size)26*9880d681SAndroid Build Coastguard Worker static SDValue emitMemMem(SelectionDAG &DAG, const SDLoc &DL, unsigned Sequence,
27*9880d681SAndroid Build Coastguard Worker unsigned Loop, SDValue Chain, SDValue Dst,
28*9880d681SAndroid Build Coastguard Worker SDValue Src, uint64_t Size) {
29*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src.getValueType();
30*9880d681SAndroid Build Coastguard Worker // The heuristic we use is to prefer loops for anything that would
31*9880d681SAndroid Build Coastguard Worker // require 7 or more MVCs. With these kinds of sizes there isn't
32*9880d681SAndroid Build Coastguard Worker // much to choose between straight-line code and looping code,
33*9880d681SAndroid Build Coastguard Worker // since the time will be dominated by the MVCs themselves.
34*9880d681SAndroid Build Coastguard Worker // However, the loop has 4 or 5 instructions (depending on whether
35*9880d681SAndroid Build Coastguard Worker // the base addresses can be proved equal), so there doesn't seem
36*9880d681SAndroid Build Coastguard Worker // much point using a loop for 5 * 256 bytes or fewer. Anything in
37*9880d681SAndroid Build Coastguard Worker // the range (5 * 256, 6 * 256) will need another instruction after
38*9880d681SAndroid Build Coastguard Worker // the loop, so it doesn't seem worth using a loop then either.
39*9880d681SAndroid Build Coastguard Worker // The next value up, 6 * 256, can be implemented in the same
40*9880d681SAndroid Build Coastguard Worker // number of straight-line MVCs as 6 * 256 - 1.
41*9880d681SAndroid Build Coastguard Worker if (Size > 6 * 256)
42*9880d681SAndroid Build Coastguard Worker return DAG.getNode(Loop, DL, MVT::Other, Chain, Dst, Src,
43*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size, DL, PtrVT),
44*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size / 256, DL, PtrVT));
45*9880d681SAndroid Build Coastguard Worker return DAG.getNode(Sequence, DL, MVT::Other, Chain, Dst, Src,
46*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size, DL, PtrVT));
47*9880d681SAndroid Build Coastguard Worker }
48*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForMemcpy(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,unsigned Align,bool IsVolatile,bool AlwaysInline,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const49*9880d681SAndroid Build Coastguard Worker SDValue SystemZSelectionDAGInfo::EmitTargetCodeForMemcpy(
50*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,
51*9880d681SAndroid Build Coastguard Worker SDValue Size, unsigned Align, bool IsVolatile, bool AlwaysInline,
52*9880d681SAndroid Build Coastguard Worker MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
53*9880d681SAndroid Build Coastguard Worker if (IsVolatile)
54*9880d681SAndroid Build Coastguard Worker return SDValue();
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker if (auto *CSize = dyn_cast<ConstantSDNode>(Size))
57*9880d681SAndroid Build Coastguard Worker return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
58*9880d681SAndroid Build Coastguard Worker Chain, Dst, Src, CSize->getZExtValue());
59*9880d681SAndroid Build Coastguard Worker return SDValue();
60*9880d681SAndroid Build Coastguard Worker }
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker // Handle a memset of 1, 2, 4 or 8 bytes with the operands given by
63*9880d681SAndroid Build Coastguard Worker // Chain, Dst, ByteVal and Size. These cases are expected to use
64*9880d681SAndroid Build Coastguard Worker // MVI, MVHHI, MVHI and MVGHI respectively.
memsetStore(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dst,uint64_t ByteVal,uint64_t Size,unsigned Align,MachinePointerInfo DstPtrInfo)65*9880d681SAndroid Build Coastguard Worker static SDValue memsetStore(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
66*9880d681SAndroid Build Coastguard Worker SDValue Dst, uint64_t ByteVal, uint64_t Size,
67*9880d681SAndroid Build Coastguard Worker unsigned Align, MachinePointerInfo DstPtrInfo) {
68*9880d681SAndroid Build Coastguard Worker uint64_t StoreVal = ByteVal;
69*9880d681SAndroid Build Coastguard Worker for (unsigned I = 1; I < Size; ++I)
70*9880d681SAndroid Build Coastguard Worker StoreVal |= ByteVal << (I * 8);
71*9880d681SAndroid Build Coastguard Worker return DAG.getStore(Chain, DL,
72*9880d681SAndroid Build Coastguard Worker DAG.getConstant(StoreVal, DL,
73*9880d681SAndroid Build Coastguard Worker MVT::getIntegerVT(Size * 8)),
74*9880d681SAndroid Build Coastguard Worker Dst, DstPtrInfo, false, false, Align);
75*9880d681SAndroid Build Coastguard Worker }
76*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForMemset(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dst,SDValue Byte,SDValue Size,unsigned Align,bool IsVolatile,MachinePointerInfo DstPtrInfo) const77*9880d681SAndroid Build Coastguard Worker SDValue SystemZSelectionDAGInfo::EmitTargetCodeForMemset(
78*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst,
79*9880d681SAndroid Build Coastguard Worker SDValue Byte, SDValue Size, unsigned Align, bool IsVolatile,
80*9880d681SAndroid Build Coastguard Worker MachinePointerInfo DstPtrInfo) const {
81*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Dst.getValueType();
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker if (IsVolatile)
84*9880d681SAndroid Build Coastguard Worker return SDValue();
85*9880d681SAndroid Build Coastguard Worker
86*9880d681SAndroid Build Coastguard Worker if (auto *CSize = dyn_cast<ConstantSDNode>(Size)) {
87*9880d681SAndroid Build Coastguard Worker uint64_t Bytes = CSize->getZExtValue();
88*9880d681SAndroid Build Coastguard Worker if (Bytes == 0)
89*9880d681SAndroid Build Coastguard Worker return SDValue();
90*9880d681SAndroid Build Coastguard Worker if (auto *CByte = dyn_cast<ConstantSDNode>(Byte)) {
91*9880d681SAndroid Build Coastguard Worker // Handle cases that can be done using at most two of
92*9880d681SAndroid Build Coastguard Worker // MVI, MVHI, MVHHI and MVGHI. The latter two can only be
93*9880d681SAndroid Build Coastguard Worker // used if ByteVal is all zeros or all ones; in other casees,
94*9880d681SAndroid Build Coastguard Worker // we can move at most 2 halfwords.
95*9880d681SAndroid Build Coastguard Worker uint64_t ByteVal = CByte->getZExtValue();
96*9880d681SAndroid Build Coastguard Worker if (ByteVal == 0 || ByteVal == 255 ?
97*9880d681SAndroid Build Coastguard Worker Bytes <= 16 && countPopulation(Bytes) <= 2 :
98*9880d681SAndroid Build Coastguard Worker Bytes <= 4) {
99*9880d681SAndroid Build Coastguard Worker unsigned Size1 = Bytes == 16 ? 8 : 1 << findLastSet(Bytes);
100*9880d681SAndroid Build Coastguard Worker unsigned Size2 = Bytes - Size1;
101*9880d681SAndroid Build Coastguard Worker SDValue Chain1 = memsetStore(DAG, DL, Chain, Dst, ByteVal, Size1,
102*9880d681SAndroid Build Coastguard Worker Align, DstPtrInfo);
103*9880d681SAndroid Build Coastguard Worker if (Size2 == 0)
104*9880d681SAndroid Build Coastguard Worker return Chain1;
105*9880d681SAndroid Build Coastguard Worker Dst = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
106*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size1, DL, PtrVT));
107*9880d681SAndroid Build Coastguard Worker DstPtrInfo = DstPtrInfo.getWithOffset(Size1);
108*9880d681SAndroid Build Coastguard Worker SDValue Chain2 = memsetStore(DAG, DL, Chain, Dst, ByteVal, Size2,
109*9880d681SAndroid Build Coastguard Worker std::min(Align, Size1), DstPtrInfo);
110*9880d681SAndroid Build Coastguard Worker return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chain1, Chain2);
111*9880d681SAndroid Build Coastguard Worker }
112*9880d681SAndroid Build Coastguard Worker } else {
113*9880d681SAndroid Build Coastguard Worker // Handle one and two bytes using STC.
114*9880d681SAndroid Build Coastguard Worker if (Bytes <= 2) {
115*9880d681SAndroid Build Coastguard Worker SDValue Chain1 = DAG.getStore(Chain, DL, Byte, Dst, DstPtrInfo,
116*9880d681SAndroid Build Coastguard Worker false, false, Align);
117*9880d681SAndroid Build Coastguard Worker if (Bytes == 1)
118*9880d681SAndroid Build Coastguard Worker return Chain1;
119*9880d681SAndroid Build Coastguard Worker SDValue Dst2 = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
120*9880d681SAndroid Build Coastguard Worker DAG.getConstant(1, DL, PtrVT));
121*9880d681SAndroid Build Coastguard Worker SDValue Chain2 = DAG.getStore(Chain, DL, Byte, Dst2,
122*9880d681SAndroid Build Coastguard Worker DstPtrInfo.getWithOffset(1),
123*9880d681SAndroid Build Coastguard Worker false, false, 1);
124*9880d681SAndroid Build Coastguard Worker return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chain1, Chain2);
125*9880d681SAndroid Build Coastguard Worker }
126*9880d681SAndroid Build Coastguard Worker }
127*9880d681SAndroid Build Coastguard Worker assert(Bytes >= 2 && "Should have dealt with 0- and 1-byte cases already");
128*9880d681SAndroid Build Coastguard Worker
129*9880d681SAndroid Build Coastguard Worker // Handle the special case of a memset of 0, which can use XC.
130*9880d681SAndroid Build Coastguard Worker auto *CByte = dyn_cast<ConstantSDNode>(Byte);
131*9880d681SAndroid Build Coastguard Worker if (CByte && CByte->getZExtValue() == 0)
132*9880d681SAndroid Build Coastguard Worker return emitMemMem(DAG, DL, SystemZISD::XC, SystemZISD::XC_LOOP,
133*9880d681SAndroid Build Coastguard Worker Chain, Dst, Dst, Bytes);
134*9880d681SAndroid Build Coastguard Worker
135*9880d681SAndroid Build Coastguard Worker // Copy the byte to the first location and then use MVC to copy
136*9880d681SAndroid Build Coastguard Worker // it to the rest.
137*9880d681SAndroid Build Coastguard Worker Chain = DAG.getStore(Chain, DL, Byte, Dst, DstPtrInfo,
138*9880d681SAndroid Build Coastguard Worker false, false, Align);
139*9880d681SAndroid Build Coastguard Worker SDValue DstPlus1 = DAG.getNode(ISD::ADD, DL, PtrVT, Dst,
140*9880d681SAndroid Build Coastguard Worker DAG.getConstant(1, DL, PtrVT));
141*9880d681SAndroid Build Coastguard Worker return emitMemMem(DAG, DL, SystemZISD::MVC, SystemZISD::MVC_LOOP,
142*9880d681SAndroid Build Coastguard Worker Chain, DstPlus1, Dst, Bytes - 1);
143*9880d681SAndroid Build Coastguard Worker }
144*9880d681SAndroid Build Coastguard Worker return SDValue();
145*9880d681SAndroid Build Coastguard Worker }
146*9880d681SAndroid Build Coastguard Worker
147*9880d681SAndroid Build Coastguard Worker // Use CLC to compare [Src1, Src1 + Size) with [Src2, Src2 + Size),
148*9880d681SAndroid Build Coastguard Worker // deciding whether to use a loop or straight-line code.
emitCLC(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src1,SDValue Src2,uint64_t Size)149*9880d681SAndroid Build Coastguard Worker static SDValue emitCLC(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
150*9880d681SAndroid Build Coastguard Worker SDValue Src1, SDValue Src2, uint64_t Size) {
151*9880d681SAndroid Build Coastguard Worker SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue);
152*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src1.getValueType();
153*9880d681SAndroid Build Coastguard Worker // A two-CLC sequence is a clear win over a loop, not least because it
154*9880d681SAndroid Build Coastguard Worker // needs only one branch. A three-CLC sequence needs the same number
155*9880d681SAndroid Build Coastguard Worker // of branches as a loop (i.e. 2), but is shorter. That brings us to
156*9880d681SAndroid Build Coastguard Worker // lengths greater than 768 bytes. It seems relatively likely that
157*9880d681SAndroid Build Coastguard Worker // a difference will be found within the first 768 bytes, so we just
158*9880d681SAndroid Build Coastguard Worker // optimize for the smallest number of branch instructions, in order
159*9880d681SAndroid Build Coastguard Worker // to avoid polluting the prediction buffer too much. A loop only ever
160*9880d681SAndroid Build Coastguard Worker // needs 2 branches, whereas a straight-line sequence would need 3 or more.
161*9880d681SAndroid Build Coastguard Worker if (Size > 3 * 256)
162*9880d681SAndroid Build Coastguard Worker return DAG.getNode(SystemZISD::CLC_LOOP, DL, VTs, Chain, Src1, Src2,
163*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size, DL, PtrVT),
164*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size / 256, DL, PtrVT));
165*9880d681SAndroid Build Coastguard Worker return DAG.getNode(SystemZISD::CLC, DL, VTs, Chain, Src1, Src2,
166*9880d681SAndroid Build Coastguard Worker DAG.getConstant(Size, DL, PtrVT));
167*9880d681SAndroid Build Coastguard Worker }
168*9880d681SAndroid Build Coastguard Worker
169*9880d681SAndroid Build Coastguard Worker // Convert the current CC value into an integer that is 0 if CC == 0,
170*9880d681SAndroid Build Coastguard Worker // less than zero if CC == 1 and greater than zero if CC >= 2.
171*9880d681SAndroid Build Coastguard Worker // The sequence starts with IPM, which puts CC into bits 29 and 28
172*9880d681SAndroid Build Coastguard Worker // of an integer and clears bits 30 and 31.
addIPMSequence(const SDLoc & DL,SDValue Glue,SelectionDAG & DAG)173*9880d681SAndroid Build Coastguard Worker static SDValue addIPMSequence(const SDLoc &DL, SDValue Glue,
174*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG) {
175*9880d681SAndroid Build Coastguard Worker SDValue IPM = DAG.getNode(SystemZISD::IPM, DL, MVT::i32, Glue);
176*9880d681SAndroid Build Coastguard Worker SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i32, IPM,
177*9880d681SAndroid Build Coastguard Worker DAG.getConstant(SystemZ::IPM_CC, DL, MVT::i32));
178*9880d681SAndroid Build Coastguard Worker SDValue ROTL = DAG.getNode(ISD::ROTL, DL, MVT::i32, SRL,
179*9880d681SAndroid Build Coastguard Worker DAG.getConstant(31, DL, MVT::i32));
180*9880d681SAndroid Build Coastguard Worker return ROTL;
181*9880d681SAndroid Build Coastguard Worker }
182*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForMemcmp(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src1,SDValue Src2,SDValue Size,MachinePointerInfo Op1PtrInfo,MachinePointerInfo Op2PtrInfo) const183*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForMemcmp(
184*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
185*9880d681SAndroid Build Coastguard Worker SDValue Src2, SDValue Size, MachinePointerInfo Op1PtrInfo,
186*9880d681SAndroid Build Coastguard Worker MachinePointerInfo Op2PtrInfo) const {
187*9880d681SAndroid Build Coastguard Worker if (auto *CSize = dyn_cast<ConstantSDNode>(Size)) {
188*9880d681SAndroid Build Coastguard Worker uint64_t Bytes = CSize->getZExtValue();
189*9880d681SAndroid Build Coastguard Worker assert(Bytes > 0 && "Caller should have handled 0-size case");
190*9880d681SAndroid Build Coastguard Worker Chain = emitCLC(DAG, DL, Chain, Src1, Src2, Bytes);
191*9880d681SAndroid Build Coastguard Worker SDValue Glue = Chain.getValue(1);
192*9880d681SAndroid Build Coastguard Worker return std::make_pair(addIPMSequence(DL, Glue, DAG), Chain);
193*9880d681SAndroid Build Coastguard Worker }
194*9880d681SAndroid Build Coastguard Worker return std::make_pair(SDValue(), SDValue());
195*9880d681SAndroid Build Coastguard Worker }
196*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForMemchr(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src,SDValue Char,SDValue Length,MachinePointerInfo SrcPtrInfo) const197*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForMemchr(
198*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
199*9880d681SAndroid Build Coastguard Worker SDValue Char, SDValue Length, MachinePointerInfo SrcPtrInfo) const {
200*9880d681SAndroid Build Coastguard Worker // Use SRST to find the character. End is its address on success.
201*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src.getValueType();
202*9880d681SAndroid Build Coastguard Worker SDVTList VTs = DAG.getVTList(PtrVT, MVT::Other, MVT::Glue);
203*9880d681SAndroid Build Coastguard Worker Length = DAG.getZExtOrTrunc(Length, DL, PtrVT);
204*9880d681SAndroid Build Coastguard Worker Char = DAG.getZExtOrTrunc(Char, DL, MVT::i32);
205*9880d681SAndroid Build Coastguard Worker Char = DAG.getNode(ISD::AND, DL, MVT::i32, Char,
206*9880d681SAndroid Build Coastguard Worker DAG.getConstant(255, DL, MVT::i32));
207*9880d681SAndroid Build Coastguard Worker SDValue Limit = DAG.getNode(ISD::ADD, DL, PtrVT, Src, Length);
208*9880d681SAndroid Build Coastguard Worker SDValue End = DAG.getNode(SystemZISD::SEARCH_STRING, DL, VTs, Chain,
209*9880d681SAndroid Build Coastguard Worker Limit, Src, Char);
210*9880d681SAndroid Build Coastguard Worker Chain = End.getValue(1);
211*9880d681SAndroid Build Coastguard Worker SDValue Glue = End.getValue(2);
212*9880d681SAndroid Build Coastguard Worker
213*9880d681SAndroid Build Coastguard Worker // Now select between End and null, depending on whether the character
214*9880d681SAndroid Build Coastguard Worker // was found.
215*9880d681SAndroid Build Coastguard Worker SDValue Ops[] = {End, DAG.getConstant(0, DL, PtrVT),
216*9880d681SAndroid Build Coastguard Worker DAG.getConstant(SystemZ::CCMASK_SRST, DL, MVT::i32),
217*9880d681SAndroid Build Coastguard Worker DAG.getConstant(SystemZ::CCMASK_SRST_FOUND, DL, MVT::i32),
218*9880d681SAndroid Build Coastguard Worker Glue};
219*9880d681SAndroid Build Coastguard Worker VTs = DAG.getVTList(PtrVT, MVT::Glue);
220*9880d681SAndroid Build Coastguard Worker End = DAG.getNode(SystemZISD::SELECT_CCMASK, DL, VTs, Ops);
221*9880d681SAndroid Build Coastguard Worker return std::make_pair(End, Chain);
222*9880d681SAndroid Build Coastguard Worker }
223*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForStrcpy(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dest,SDValue Src,MachinePointerInfo DestPtrInfo,MachinePointerInfo SrcPtrInfo,bool isStpcpy) const224*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcpy(
225*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
226*9880d681SAndroid Build Coastguard Worker SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo,
227*9880d681SAndroid Build Coastguard Worker bool isStpcpy) const {
228*9880d681SAndroid Build Coastguard Worker SDVTList VTs = DAG.getVTList(Dest.getValueType(), MVT::Other);
229*9880d681SAndroid Build Coastguard Worker SDValue EndDest = DAG.getNode(SystemZISD::STPCPY, DL, VTs, Chain, Dest, Src,
230*9880d681SAndroid Build Coastguard Worker DAG.getConstant(0, DL, MVT::i32));
231*9880d681SAndroid Build Coastguard Worker return std::make_pair(isStpcpy ? EndDest : Dest, EndDest.getValue(1));
232*9880d681SAndroid Build Coastguard Worker }
233*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForStrcmp(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src1,SDValue Src2,MachinePointerInfo Op1PtrInfo,MachinePointerInfo Op2PtrInfo) const234*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcmp(
235*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
236*9880d681SAndroid Build Coastguard Worker SDValue Src2, MachinePointerInfo Op1PtrInfo,
237*9880d681SAndroid Build Coastguard Worker MachinePointerInfo Op2PtrInfo) const {
238*9880d681SAndroid Build Coastguard Worker SDVTList VTs = DAG.getVTList(Src1.getValueType(), MVT::Other, MVT::Glue);
239*9880d681SAndroid Build Coastguard Worker SDValue Unused = DAG.getNode(SystemZISD::STRCMP, DL, VTs, Chain, Src1, Src2,
240*9880d681SAndroid Build Coastguard Worker DAG.getConstant(0, DL, MVT::i32));
241*9880d681SAndroid Build Coastguard Worker Chain = Unused.getValue(1);
242*9880d681SAndroid Build Coastguard Worker SDValue Glue = Chain.getValue(2);
243*9880d681SAndroid Build Coastguard Worker return std::make_pair(addIPMSequence(DL, Glue, DAG), Chain);
244*9880d681SAndroid Build Coastguard Worker }
245*9880d681SAndroid Build Coastguard Worker
246*9880d681SAndroid Build Coastguard Worker // Search from Src for a null character, stopping once Src reaches Limit.
247*9880d681SAndroid Build Coastguard Worker // Return a pair of values, the first being the number of nonnull characters
248*9880d681SAndroid Build Coastguard Worker // and the second being the out chain.
249*9880d681SAndroid Build Coastguard Worker //
250*9880d681SAndroid Build Coastguard Worker // This can be used for strlen by setting Limit to 0.
getBoundedStrlen(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src,SDValue Limit)251*9880d681SAndroid Build Coastguard Worker static std::pair<SDValue, SDValue> getBoundedStrlen(SelectionDAG &DAG,
252*9880d681SAndroid Build Coastguard Worker const SDLoc &DL,
253*9880d681SAndroid Build Coastguard Worker SDValue Chain, SDValue Src,
254*9880d681SAndroid Build Coastguard Worker SDValue Limit) {
255*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src.getValueType();
256*9880d681SAndroid Build Coastguard Worker SDVTList VTs = DAG.getVTList(PtrVT, MVT::Other, MVT::Glue);
257*9880d681SAndroid Build Coastguard Worker SDValue End = DAG.getNode(SystemZISD::SEARCH_STRING, DL, VTs, Chain,
258*9880d681SAndroid Build Coastguard Worker Limit, Src, DAG.getConstant(0, DL, MVT::i32));
259*9880d681SAndroid Build Coastguard Worker Chain = End.getValue(1);
260*9880d681SAndroid Build Coastguard Worker SDValue Len = DAG.getNode(ISD::SUB, DL, PtrVT, End, Src);
261*9880d681SAndroid Build Coastguard Worker return std::make_pair(Len, Chain);
262*9880d681SAndroid Build Coastguard Worker }
263*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForStrlen(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src,MachinePointerInfo SrcPtrInfo) const264*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrlen(
265*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
266*9880d681SAndroid Build Coastguard Worker MachinePointerInfo SrcPtrInfo) const {
267*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src.getValueType();
268*9880d681SAndroid Build Coastguard Worker return getBoundedStrlen(DAG, DL, Chain, Src, DAG.getConstant(0, DL, PtrVT));
269*9880d681SAndroid Build Coastguard Worker }
270*9880d681SAndroid Build Coastguard Worker
EmitTargetCodeForStrnlen(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Src,SDValue MaxLength,MachinePointerInfo SrcPtrInfo) const271*9880d681SAndroid Build Coastguard Worker std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrnlen(
272*9880d681SAndroid Build Coastguard Worker SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src,
273*9880d681SAndroid Build Coastguard Worker SDValue MaxLength, MachinePointerInfo SrcPtrInfo) const {
274*9880d681SAndroid Build Coastguard Worker EVT PtrVT = Src.getValueType();
275*9880d681SAndroid Build Coastguard Worker MaxLength = DAG.getZExtOrTrunc(MaxLength, DL, PtrVT);
276*9880d681SAndroid Build Coastguard Worker SDValue Limit = DAG.getNode(ISD::ADD, DL, PtrVT, Src, MaxLength);
277*9880d681SAndroid Build Coastguard Worker return getBoundedStrlen(DAG, DL, Chain, Src, Limit);
278*9880d681SAndroid Build Coastguard Worker }
279