0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===-- X86SelectionDAGInfo.cpp - X86 SelectionDAG Info -------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // This file implements the X86SelectionDAGInfo class.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13
|
77
|
14 #include "X86InstrInfo.h"
|
|
15 #include "X86ISelLowering.h"
|
|
16 #include "X86RegisterInfo.h"
|
|
17 #include "X86Subtarget.h"
|
|
18 #include "X86SelectionDAGInfo.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/CodeGen/SelectionDAG.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #include "llvm/IR/DerivedTypes.h"
|
77
|
21 #include "llvm/Target/TargetLowering.h"
|
|
22
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24
|
77
|
25 #define DEBUG_TYPE "x86-selectiondag-info"
|
|
26
|
|
27 bool X86SelectionDAGInfo::isBaseRegConflictPossible(
|
|
28 SelectionDAG &DAG, ArrayRef<unsigned> ClobberSet) const {
|
|
29 // We cannot use TRI->hasBasePointer() until *after* we select all basic
|
|
30 // blocks. Legalization may introduce new stack temporaries with large
|
|
31 // alignment requirements. Fall back to generic code if there are any
|
|
32 // dynamic stack adjustments (hopefully rare) and the base pointer would
|
|
33 // conflict if we had to use it.
|
|
34 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
|
95
|
35 if (!MFI->hasVarSizedObjects() && !MFI->hasOpaqueSPAdjustment())
|
77
|
36 return false;
|
|
37
|
|
38 const X86RegisterInfo *TRI = static_cast<const X86RegisterInfo *>(
|
|
39 DAG.getSubtarget().getRegisterInfo());
|
|
40 unsigned BaseReg = TRI->getBaseRegister();
|
|
41 for (unsigned R : ClobberSet)
|
|
42 if (BaseReg == R)
|
|
43 return true;
|
|
44 return false;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46
|
100
|
47 SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset(
|
|
48 SelectionDAG &DAG, SDLoc dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
49 SDValue Size, unsigned Align, bool isVolatile,
|
|
50 MachinePointerInfo DstPtrInfo) const {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
83
|
52 const X86Subtarget &Subtarget =
|
|
53 DAG.getMachineFunction().getSubtarget<X86Subtarget>();
|
77
|
54
|
|
55 #ifndef NDEBUG
|
|
56 // If the base register might conflict with our physical registers, bail out.
|
95
|
57 const unsigned ClobberSet[] = {X86::RCX, X86::RAX, X86::RDI,
|
|
58 X86::ECX, X86::EAX, X86::EDI};
|
77
|
59 assert(!isBaseRegConflictPossible(DAG, ClobberSet));
|
|
60 #endif
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 // If to a segment-relative address space, use the default lowering.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 if (DstPtrInfo.getAddrSpace() >= 256)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 // If not DWORD aligned or size is more than the threshold, call the library.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 // The libc version is likely to be faster for these cases. It can use the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 // address value and run time information about the CPU.
|
77
|
69 if ((Align & 3) != 0 || !ConstantSize ||
|
|
70 ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 // Check to see if there is a specialized entry-point for memory zeroing.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 ConstantSDNode *V = dyn_cast<ConstantSDNode>(Src);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73
|
100
|
74 if (const char *bzeroEntry = V &&
|
77
|
75 V->isNullValue() ? Subtarget.getBZeroEntry() : nullptr) {
|
100
|
76 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
|
77 EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout());
|
95
|
78 Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 TargetLowering::ArgListTy Args;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 TargetLowering::ArgListEntry Entry;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 Entry.Node = Dst;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 Entry.Ty = IntPtrTy;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 Args.push_back(Entry);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 Entry.Node = Size;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 Args.push_back(Entry);
|
77
|
86
|
|
87 TargetLowering::CallLoweringInfo CLI(DAG);
|
|
88 CLI.setDebugLoc(dl).setChain(Chain)
|
|
89 .setCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()),
|
|
90 DAG.getExternalSymbol(bzeroEntry, IntPtr), std::move(Args),
|
|
91 0)
|
|
92 .setDiscardResult();
|
|
93
|
100
|
94 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 return CallResult.second;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 // Otherwise have the target-independent code call memset.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 uint64_t SizeVal = ConstantSize->getZExtValue();
|
77
|
103 SDValue InFlag;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 EVT AVT;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 SDValue Count;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Src);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 unsigned BytesLeft = 0;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 bool TwoRepStos = false;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 if (ValC) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 unsigned ValReg;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 uint64_t Val = ValC->getZExtValue() & 255;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 // If the value is a constant, then we can potentially use larger sets.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 switch (Align & 3) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 case 2: // WORD aligned
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 AVT = MVT::i16;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 ValReg = X86::AX;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 Val = (Val << 8) | Val;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 break;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 case 0: // DWORD aligned
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 AVT = MVT::i32;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 ValReg = X86::EAX;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 Val = (Val << 8) | Val;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 Val = (Val << 16) | Val;
|
77
|
125 if (Subtarget.is64Bit() && ((Align & 0x7) == 0)) { // QWORD aligned
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 AVT = MVT::i64;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 ValReg = X86::RAX;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 Val = (Val << 32) | Val;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 break;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 default: // Byte aligned
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 AVT = MVT::i8;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 ValReg = X86::AL;
|
95
|
134 Count = DAG.getIntPtrConstant(SizeVal, dl);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 break;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 if (AVT.bitsGT(MVT::i8)) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 unsigned UBytes = AVT.getSizeInBits() / 8;
|
95
|
140 Count = DAG.getIntPtrConstant(SizeVal / UBytes, dl);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 BytesLeft = SizeVal % UBytes;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143
|
100
|
144 Chain = DAG.getCopyToReg(Chain, dl, ValReg, DAG.getConstant(Val, dl, AVT),
|
|
145 InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 } else {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 AVT = MVT::i8;
|
95
|
149 Count = DAG.getIntPtrConstant(SizeVal, dl);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 Chain = DAG.getCopyToReg(Chain, dl, X86::AL, Src, InFlag);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153
|
77
|
154 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX,
|
|
155 Count, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 InFlag = Chain.getValue(1);
|
77
|
157 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI,
|
|
158 Dst, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
|
77
|
163 Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 if (TwoRepStos) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 Count = Size;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 EVT CVT = Count.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 SDValue Left = DAG.getNode(ISD::AND, dl, CVT, Count,
|
95
|
170 DAG.getConstant((AVT == MVT::i64) ? 7 : 3, dl,
|
|
171 CVT));
|
100
|
172 Chain = DAG.getCopyToReg(Chain, dl, (CVT == MVT::i64) ? X86::RCX : X86::ECX,
|
|
173 Left, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 SDValue Ops[] = { Chain, DAG.getValueType(MVT::i8), InFlag };
|
77
|
177 Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 } else if (BytesLeft) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 // Handle the last 1 - 7 bytes.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 unsigned Offset = SizeVal - BytesLeft;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 EVT AddrVT = Dst.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 EVT SizeVT = Size.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 Chain = DAG.getMemset(Chain, dl,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 DAG.getNode(ISD::ADD, dl, AddrVT, Dst,
|
95
|
186 DAG.getConstant(Offset, dl, AddrVT)),
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 Src,
|
95
|
188 DAG.getConstant(BytesLeft, dl, SizeVT),
|
|
189 Align, isVolatile, false,
|
|
190 DstPtrInfo.getWithOffset(Offset));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 // TODO: Use a Tokenfactor, as in memcpy, instead of a single chain.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 return Chain;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196
|
83
|
197 SDValue X86SelectionDAGInfo::EmitTargetCodeForMemcpy(
|
|
198 SelectionDAG &DAG, SDLoc dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
199 SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
|
|
200 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 // This requires the copy size to be a constant, preferably
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 // within a subtarget-specific limit.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
83
|
204 const X86Subtarget &Subtarget =
|
|
205 DAG.getMachineFunction().getSubtarget<X86Subtarget>();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 if (!ConstantSize)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 uint64_t SizeVal = ConstantSize->getZExtValue();
|
77
|
209 if (!AlwaysInline && SizeVal > Subtarget.getMaxInlineSizeThreshold())
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 /// If not DWORD aligned, it is more efficient to call the library. However
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 /// if calling the library is not allowed (AlwaysInline), then soldier on as
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 /// the code generated here is better than the long load-store sequence we
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 /// would otherwise get.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 if (!AlwaysInline && (Align & 3) != 0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 // If to a segment-relative address space, use the default lowering.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 if (DstPtrInfo.getAddrSpace() >= 256 ||
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 SrcPtrInfo.getAddrSpace() >= 256)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223
|
77
|
224 // If the base register might conflict with our physical registers, bail out.
|
95
|
225 const unsigned ClobberSet[] = {X86::RCX, X86::RSI, X86::RDI,
|
|
226 X86::ECX, X86::ESI, X86::EDI};
|
77
|
227 if (isBaseRegConflictPossible(DAG, ClobberSet))
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228 return SDValue();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 MVT AVT;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 if (Align & 1)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 AVT = MVT::i8;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 else if (Align & 2)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 AVT = MVT::i16;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 else if (Align & 4)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 // DWORD aligned
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 AVT = MVT::i32;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 // QWORD aligned
|
77
|
240 AVT = Subtarget.is64Bit() ? MVT::i64 : MVT::i32;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 unsigned UBytes = AVT.getSizeInBits() / 8;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 unsigned CountVal = SizeVal / UBytes;
|
95
|
244 SDValue Count = DAG.getIntPtrConstant(CountVal, dl);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 unsigned BytesLeft = SizeVal % UBytes;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246
|
77
|
247 SDValue InFlag;
|
100
|
248 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX,
|
|
249 Count, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 InFlag = Chain.getValue(1);
|
100
|
251 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI,
|
|
252 Dst, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 InFlag = Chain.getValue(1);
|
100
|
254 Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RSI : X86::ESI,
|
|
255 Src, InFlag);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256 InFlag = Chain.getValue(1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
|
77
|
260 SDValue RepMovs = DAG.getNode(X86ISD::REP_MOVS, dl, Tys, Ops);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 SmallVector<SDValue, 4> Results;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 Results.push_back(RepMovs);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 if (BytesLeft) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 // Handle the last 1 - 7 bytes.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 unsigned Offset = SizeVal - BytesLeft;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 EVT DstVT = Dst.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 EVT SrcVT = Src.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 EVT SizeVT = Size.getValueType();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 Results.push_back(DAG.getMemcpy(Chain, dl,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 DAG.getNode(ISD::ADD, dl, DstVT, Dst,
|
95
|
272 DAG.getConstant(Offset, dl,
|
|
273 DstVT)),
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 DAG.getNode(ISD::ADD, dl, SrcVT, Src,
|
95
|
275 DAG.getConstant(Offset, dl,
|
|
276 SrcVT)),
|
|
277 DAG.getConstant(BytesLeft, dl, SizeVT),
|
|
278 Align, isVolatile, AlwaysInline, false,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 DstPtrInfo.getWithOffset(Offset),
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 SrcPtrInfo.getWithOffset(Offset)));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282
|
77
|
283 return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Results);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 }
|