LegalizeTypesGeneric.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. //===-------- LegalizeTypesGeneric.cpp - Generic type legalization --------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements generic type expansion and splitting for LegalizeTypes.
  11. // The routines here perform legalization when the details of the type (such as
  12. // whether it is an integer or a float) do not matter.
  13. // Expansion is the act of changing a computation in an illegal type to be a
  14. // computation in two identical registers of a smaller type. The Lo/Hi part
  15. // is required to be stored first in memory on little/big-endian machines.
  16. // Splitting is the act of changing a computation in an illegal type to be a
  17. // computation in two not necessarily identical registers of a smaller type.
  18. // There are no requirements on how the type is represented in memory.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #include "LegalizeTypes.h"
  22. #include "llvm/IR/DataLayout.h"
  23. using namespace llvm;
  24. #define DEBUG_TYPE "legalize-types"
  25. //===----------------------------------------------------------------------===//
  26. // Generic Result Expansion.
  27. //===----------------------------------------------------------------------===//
  28. // These routines assume that the Lo/Hi part is stored first in memory on
  29. // little/big-endian machines, followed by the Hi/Lo part. This means that
  30. // they cannot be used as is on vectors, for which Lo is always stored first.
  31. void DAGTypeLegalizer::ExpandRes_MERGE_VALUES(SDNode *N, unsigned ResNo,
  32. SDValue &Lo, SDValue &Hi) {
  33. SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);
  34. GetExpandedOp(Op, Lo, Hi);
  35. }
  36. void DAGTypeLegalizer::ExpandRes_BITCAST(SDNode *N, SDValue &Lo, SDValue &Hi) {
  37. EVT OutVT = N->getValueType(0);
  38. EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
  39. SDValue InOp = N->getOperand(0);
  40. EVT InVT = InOp.getValueType();
  41. SDLoc dl(N);
  42. // Handle some special cases efficiently.
  43. switch (getTypeAction(InVT)) {
  44. case TargetLowering::TypeLegal:
  45. case TargetLowering::TypePromoteInteger:
  46. break;
  47. case TargetLowering::TypePromoteFloat:
  48. llvm_unreachable("Bitcast of a promotion-needing float should never need"
  49. "expansion");
  50. case TargetLowering::TypeSoftenFloat:
  51. // Convert the integer operand instead.
  52. SplitInteger(GetSoftenedFloat(InOp), Lo, Hi);
  53. Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT, Lo);
  54. Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT, Hi);
  55. return;
  56. case TargetLowering::TypeExpandInteger:
  57. case TargetLowering::TypeExpandFloat: {
  58. auto &DL = DAG.getDataLayout();
  59. // Convert the expanded pieces of the input.
  60. GetExpandedOp(InOp, Lo, Hi);
  61. if (TLI.hasBigEndianPartOrdering(InVT, DL) !=
  62. TLI.hasBigEndianPartOrdering(OutVT, DL))
  63. std::swap(Lo, Hi);
  64. Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT, Lo);
  65. Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT, Hi);
  66. return;
  67. }
  68. case TargetLowering::TypeSplitVector:
  69. GetSplitVector(InOp, Lo, Hi);
  70. if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
  71. std::swap(Lo, Hi);
  72. Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT, Lo);
  73. Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT, Hi);
  74. return;
  75. case TargetLowering::TypeScalarizeVector:
  76. // Convert the element instead.
  77. SplitInteger(BitConvertToInteger(GetScalarizedVector(InOp)), Lo, Hi);
  78. Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT, Lo);
  79. Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT, Hi);
  80. return;
  81. case TargetLowering::TypeWidenVector: {
  82. assert(!(InVT.getVectorNumElements() & 1) && "Unsupported BITCAST");
  83. InOp = GetWidenedVector(InOp);
  84. EVT LoVT, HiVT;
  85. std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(InVT);
  86. std::tie(Lo, Hi) = DAG.SplitVector(InOp, dl, LoVT, HiVT);
  87. if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
  88. std::swap(Lo, Hi);
  89. Lo = DAG.getNode(ISD::BITCAST, dl, NOutVT, Lo);
  90. Hi = DAG.getNode(ISD::BITCAST, dl, NOutVT, Hi);
  91. return;
  92. }
  93. }
  94. if (InVT.isVector() && OutVT.isInteger()) {
  95. // Handle cases like i64 = BITCAST v1i64 on x86, where the operand
  96. // is legal but the result is not.
  97. unsigned NumElems = 2;
  98. EVT ElemVT = NOutVT;
  99. EVT NVT = EVT::getVectorVT(*DAG.getContext(), ElemVT, NumElems);
  100. // If <ElemVT * N> is not a legal type, try <ElemVT/2 * (N*2)>.
  101. while (!isTypeLegal(NVT)) {
  102. unsigned NewSizeInBits = ElemVT.getSizeInBits() / 2;
  103. // If the element size is smaller than byte, bail.
  104. if (NewSizeInBits < 8)
  105. break;
  106. NumElems *= 2;
  107. ElemVT = EVT::getIntegerVT(*DAG.getContext(), NewSizeInBits);
  108. NVT = EVT::getVectorVT(*DAG.getContext(), ElemVT, NumElems);
  109. }
  110. if (isTypeLegal(NVT)) {
  111. SDValue CastInOp = DAG.getNode(ISD::BITCAST, dl, NVT, InOp);
  112. SmallVector<SDValue, 8> Vals;
  113. for (unsigned i = 0; i < NumElems; ++i)
  114. Vals.push_back(DAG.getNode(
  115. ISD::EXTRACT_VECTOR_ELT, dl, ElemVT, CastInOp,
  116. DAG.getConstant(i, dl, TLI.getVectorIdxTy(DAG.getDataLayout()))));
  117. // Build Lo, Hi pair by pairing extracted elements if needed.
  118. unsigned Slot = 0;
  119. for (unsigned e = Vals.size(); e - Slot > 2; Slot += 2, e += 1) {
  120. // Each iteration will BUILD_PAIR two nodes and append the result until
  121. // there are only two nodes left, i.e. Lo and Hi.
  122. SDValue LHS = Vals[Slot];
  123. SDValue RHS = Vals[Slot + 1];
  124. if (DAG.getDataLayout().isBigEndian())
  125. std::swap(LHS, RHS);
  126. Vals.push_back(DAG.getNode(ISD::BUILD_PAIR, dl,
  127. EVT::getIntegerVT(
  128. *DAG.getContext(),
  129. LHS.getValueType().getSizeInBits() << 1),
  130. LHS, RHS));
  131. }
  132. Lo = Vals[Slot++];
  133. Hi = Vals[Slot++];
  134. if (DAG.getDataLayout().isBigEndian())
  135. std::swap(Lo, Hi);
  136. return;
  137. }
  138. }
  139. // Lower the bit-convert to a store/load from the stack.
  140. assert(NOutVT.isByteSized() && "Expanded type not byte sized!");
  141. // Create the stack frame object. Make sure it is aligned for both
  142. // the source and expanded destination types.
  143. unsigned Alignment = DAG.getDataLayout().getPrefTypeAlignment(
  144. NOutVT.getTypeForEVT(*DAG.getContext()));
  145. SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment);
  146. int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
  147. MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(SPFI);
  148. // Emit a store to the stack slot.
  149. SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, PtrInfo,
  150. false, false, 0);
  151. // Load the first half from the stack slot.
  152. Lo = DAG.getLoad(NOutVT, dl, Store, StackPtr, PtrInfo,
  153. false, false, false, 0);
  154. // Increment the pointer to the other half.
  155. unsigned IncrementSize = NOutVT.getSizeInBits() / 8;
  156. StackPtr = DAG.getNode(ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
  157. DAG.getConstant(IncrementSize, dl,
  158. StackPtr.getValueType()));
  159. // Load the second half from the stack slot.
  160. Hi = DAG.getLoad(NOutVT, dl, Store, StackPtr,
  161. PtrInfo.getWithOffset(IncrementSize), false,
  162. false, false, MinAlign(Alignment, IncrementSize));
  163. // Handle endianness of the load.
  164. if (TLI.hasBigEndianPartOrdering(OutVT, DAG.getDataLayout()))
  165. std::swap(Lo, Hi);
  166. }
  167. void DAGTypeLegalizer::ExpandRes_BUILD_PAIR(SDNode *N, SDValue &Lo,
  168. SDValue &Hi) {
  169. // Return the operands.
  170. Lo = N->getOperand(0);
  171. Hi = N->getOperand(1);
  172. }
  173. void DAGTypeLegalizer::ExpandRes_EXTRACT_ELEMENT(SDNode *N, SDValue &Lo,
  174. SDValue &Hi) {
  175. GetExpandedOp(N->getOperand(0), Lo, Hi);
  176. SDValue Part = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() ?
  177. Hi : Lo;
  178. assert(Part.getValueType() == N->getValueType(0) &&
  179. "Type twice as big as expanded type not itself expanded!");
  180. GetPairElements(Part, Lo, Hi);
  181. }
  182. void DAGTypeLegalizer::ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo,
  183. SDValue &Hi) {
  184. SDValue OldVec = N->getOperand(0);
  185. unsigned OldElts = OldVec.getValueType().getVectorNumElements();
  186. EVT OldEltVT = OldVec.getValueType().getVectorElementType();
  187. SDLoc dl(N);
  188. // Convert to a vector of the expanded element type, for example
  189. // <3 x i64> -> <6 x i32>.
  190. EVT OldVT = N->getValueType(0);
  191. EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
  192. if (OldVT != OldEltVT) {
  193. // The result of EXTRACT_VECTOR_ELT may be larger than the element type of
  194. // the input vector. If so, extend the elements of the input vector to the
  195. // same bitwidth as the result before expanding.
  196. assert(OldEltVT.bitsLT(OldVT) && "Result type smaller then element type!");
  197. EVT NVecVT = EVT::getVectorVT(*DAG.getContext(), OldVT, OldElts);
  198. OldVec = DAG.getNode(ISD::ANY_EXTEND, dl, NVecVT, N->getOperand(0));
  199. }
  200. SDValue NewVec = DAG.getNode(ISD::BITCAST, dl,
  201. EVT::getVectorVT(*DAG.getContext(),
  202. NewVT, 2*OldElts),
  203. OldVec);
  204. // Extract the elements at 2 * Idx and 2 * Idx + 1 from the new vector.
  205. SDValue Idx = N->getOperand(1);
  206. Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, Idx);
  207. Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, NewVec, Idx);
  208. Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx,
  209. DAG.getConstant(1, dl, Idx.getValueType()));
  210. Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, NewVec, Idx);
  211. if (DAG.getDataLayout().isBigEndian())
  212. std::swap(Lo, Hi);
  213. }
  214. void DAGTypeLegalizer::ExpandRes_NormalLoad(SDNode *N, SDValue &Lo,
  215. SDValue &Hi) {
  216. assert(ISD::isNormalLoad(N) && "This routine only for normal loads!");
  217. SDLoc dl(N);
  218. LoadSDNode *LD = cast<LoadSDNode>(N);
  219. EVT ValueVT = LD->getValueType(0);
  220. EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ValueVT);
  221. SDValue Chain = LD->getChain();
  222. SDValue Ptr = LD->getBasePtr();
  223. unsigned Alignment = LD->getAlignment();
  224. bool isVolatile = LD->isVolatile();
  225. bool isNonTemporal = LD->isNonTemporal();
  226. bool isInvariant = LD->isInvariant();
  227. AAMDNodes AAInfo = LD->getAAInfo();
  228. assert(NVT.isByteSized() && "Expanded type not byte sized!");
  229. Lo = DAG.getLoad(NVT, dl, Chain, Ptr, LD->getPointerInfo(),
  230. isVolatile, isNonTemporal, isInvariant, Alignment,
  231. AAInfo);
  232. // Increment the pointer to the other half.
  233. unsigned IncrementSize = NVT.getSizeInBits() / 8;
  234. Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
  235. DAG.getConstant(IncrementSize, dl, Ptr.getValueType()));
  236. Hi = DAG.getLoad(NVT, dl, Chain, Ptr,
  237. LD->getPointerInfo().getWithOffset(IncrementSize),
  238. isVolatile, isNonTemporal, isInvariant,
  239. MinAlign(Alignment, IncrementSize), AAInfo);
  240. // Build a factor node to remember that this load is independent of the
  241. // other one.
  242. Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
  243. Hi.getValue(1));
  244. // Handle endianness of the load.
  245. if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
  246. std::swap(Lo, Hi);
  247. // Modified the chain - switch anything that used the old chain to use
  248. // the new one.
  249. ReplaceValueWith(SDValue(N, 1), Chain);
  250. }
  251. void DAGTypeLegalizer::ExpandRes_VAARG(SDNode *N, SDValue &Lo, SDValue &Hi) {
  252. EVT OVT = N->getValueType(0);
  253. EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
  254. SDValue Chain = N->getOperand(0);
  255. SDValue Ptr = N->getOperand(1);
  256. SDLoc dl(N);
  257. const unsigned Align = N->getConstantOperandVal(3);
  258. Lo = DAG.getVAArg(NVT, dl, Chain, Ptr, N->getOperand(2), Align);
  259. Hi = DAG.getVAArg(NVT, dl, Lo.getValue(1), Ptr, N->getOperand(2), 0);
  260. // Handle endianness of the load.
  261. if (TLI.hasBigEndianPartOrdering(OVT, DAG.getDataLayout()))
  262. std::swap(Lo, Hi);
  263. // Modified the chain - switch anything that used the old chain to use
  264. // the new one.
  265. ReplaceValueWith(SDValue(N, 1), Hi.getValue(1));
  266. }
  267. //===--------------------------------------------------------------------===//
  268. // Generic Operand Expansion.
  269. //===--------------------------------------------------------------------===//
  270. void DAGTypeLegalizer::IntegerToVector(SDValue Op, unsigned NumElements,
  271. SmallVectorImpl<SDValue> &Ops,
  272. EVT EltVT) {
  273. assert(Op.getValueType().isInteger());
  274. SDLoc DL(Op);
  275. SDValue Parts[2];
  276. if (NumElements > 1) {
  277. NumElements >>= 1;
  278. SplitInteger(Op, Parts[0], Parts[1]);
  279. if (DAG.getDataLayout().isBigEndian())
  280. std::swap(Parts[0], Parts[1]);
  281. IntegerToVector(Parts[0], NumElements, Ops, EltVT);
  282. IntegerToVector(Parts[1], NumElements, Ops, EltVT);
  283. } else {
  284. Ops.push_back(DAG.getNode(ISD::BITCAST, DL, EltVT, Op));
  285. }
  286. }
  287. SDValue DAGTypeLegalizer::ExpandOp_BITCAST(SDNode *N) {
  288. SDLoc dl(N);
  289. if (N->getValueType(0).isVector()) {
  290. // An illegal expanding type is being converted to a legal vector type.
  291. // Make a two element vector out of the expanded parts and convert that
  292. // instead, but only if the new vector type is legal (otherwise there
  293. // is no point, and it might create expansion loops). For example, on
  294. // x86 this turns v1i64 = BITCAST i64 into v1i64 = BITCAST v2i32.
  295. //
  296. // FIXME: I'm not sure why we are first trying to split the input into
  297. // a 2 element vector, so I'm leaving it here to maintain the current
  298. // behavior.
  299. unsigned NumElts = 2;
  300. EVT OVT = N->getOperand(0).getValueType();
  301. EVT NVT = EVT::getVectorVT(*DAG.getContext(),
  302. TLI.getTypeToTransformTo(*DAG.getContext(), OVT),
  303. NumElts);
  304. if (!isTypeLegal(NVT)) {
  305. // If we can't find a legal type by splitting the integer in half,
  306. // then we can use the node's value type.
  307. NumElts = N->getValueType(0).getVectorNumElements();
  308. NVT = N->getValueType(0);
  309. }
  310. SmallVector<SDValue, 8> Ops;
  311. IntegerToVector(N->getOperand(0), NumElts, Ops, NVT.getVectorElementType());
  312. SDValue Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, NVT,
  313. makeArrayRef(Ops.data(), NumElts));
  314. return DAG.getNode(ISD::BITCAST, dl, N->getValueType(0), Vec);
  315. }
  316. // Otherwise, store to a temporary and load out again as the new type.
  317. return CreateStackStoreLoad(N->getOperand(0), N->getValueType(0));
  318. }
  319. SDValue DAGTypeLegalizer::ExpandOp_BUILD_VECTOR(SDNode *N) {
  320. // The vector type is legal but the element type needs expansion.
  321. EVT VecVT = N->getValueType(0);
  322. unsigned NumElts = VecVT.getVectorNumElements();
  323. EVT OldVT = N->getOperand(0).getValueType();
  324. EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
  325. SDLoc dl(N);
  326. assert(OldVT == VecVT.getVectorElementType() &&
  327. "BUILD_VECTOR operand type doesn't match vector element type!");
  328. // Build a vector of twice the length out of the expanded elements.
  329. // For example <3 x i64> -> <6 x i32>.
  330. std::vector<SDValue> NewElts;
  331. NewElts.reserve(NumElts*2);
  332. for (unsigned i = 0; i < NumElts; ++i) {
  333. SDValue Lo, Hi;
  334. GetExpandedOp(N->getOperand(i), Lo, Hi);
  335. if (DAG.getDataLayout().isBigEndian())
  336. std::swap(Lo, Hi);
  337. NewElts.push_back(Lo);
  338. NewElts.push_back(Hi);
  339. }
  340. SDValue NewVec = DAG.getNode(ISD::BUILD_VECTOR, dl,
  341. EVT::getVectorVT(*DAG.getContext(),
  342. NewVT, NewElts.size()),
  343. NewElts);
  344. // Convert the new vector to the old vector type.
  345. return DAG.getNode(ISD::BITCAST, dl, VecVT, NewVec);
  346. }
  347. SDValue DAGTypeLegalizer::ExpandOp_EXTRACT_ELEMENT(SDNode *N) {
  348. SDValue Lo, Hi;
  349. GetExpandedOp(N->getOperand(0), Lo, Hi);
  350. return cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() ? Hi : Lo;
  351. }
  352. SDValue DAGTypeLegalizer::ExpandOp_INSERT_VECTOR_ELT(SDNode *N) {
  353. // The vector type is legal but the element type needs expansion.
  354. EVT VecVT = N->getValueType(0);
  355. unsigned NumElts = VecVT.getVectorNumElements();
  356. SDLoc dl(N);
  357. SDValue Val = N->getOperand(1);
  358. EVT OldEVT = Val.getValueType();
  359. EVT NewEVT = TLI.getTypeToTransformTo(*DAG.getContext(), OldEVT);
  360. assert(OldEVT == VecVT.getVectorElementType() &&
  361. "Inserted element type doesn't match vector element type!");
  362. // Bitconvert to a vector of twice the length with elements of the expanded
  363. // type, insert the expanded vector elements, and then convert back.
  364. EVT NewVecVT = EVT::getVectorVT(*DAG.getContext(), NewEVT, NumElts*2);
  365. SDValue NewVec = DAG.getNode(ISD::BITCAST, dl,
  366. NewVecVT, N->getOperand(0));
  367. SDValue Lo, Hi;
  368. GetExpandedOp(Val, Lo, Hi);
  369. if (DAG.getDataLayout().isBigEndian())
  370. std::swap(Lo, Hi);
  371. SDValue Idx = N->getOperand(2);
  372. Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, Idx);
  373. NewVec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVecVT, NewVec, Lo, Idx);
  374. Idx = DAG.getNode(ISD::ADD, dl,
  375. Idx.getValueType(), Idx,
  376. DAG.getConstant(1, dl, Idx.getValueType()));
  377. NewVec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVecVT, NewVec, Hi, Idx);
  378. // Convert the new vector to the old vector type.
  379. return DAG.getNode(ISD::BITCAST, dl, VecVT, NewVec);
  380. }
  381. SDValue DAGTypeLegalizer::ExpandOp_SCALAR_TO_VECTOR(SDNode *N) {
  382. SDLoc dl(N);
  383. EVT VT = N->getValueType(0);
  384. assert(VT.getVectorElementType() == N->getOperand(0).getValueType() &&
  385. "SCALAR_TO_VECTOR operand type doesn't match vector element type!");
  386. unsigned NumElts = VT.getVectorNumElements();
  387. SmallVector<SDValue, 16> Ops(NumElts);
  388. Ops[0] = N->getOperand(0);
  389. SDValue UndefVal = DAG.getUNDEF(Ops[0].getValueType());
  390. for (unsigned i = 1; i < NumElts; ++i)
  391. Ops[i] = UndefVal;
  392. return DAG.getNode(ISD::BUILD_VECTOR, dl, VT, Ops);
  393. }
  394. SDValue DAGTypeLegalizer::ExpandOp_NormalStore(SDNode *N, unsigned OpNo) {
  395. assert(ISD::isNormalStore(N) && "This routine only for normal stores!");
  396. assert(OpNo == 1 && "Can only expand the stored value so far");
  397. SDLoc dl(N);
  398. StoreSDNode *St = cast<StoreSDNode>(N);
  399. EVT ValueVT = St->getValue().getValueType();
  400. EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ValueVT);
  401. SDValue Chain = St->getChain();
  402. SDValue Ptr = St->getBasePtr();
  403. unsigned Alignment = St->getAlignment();
  404. bool isVolatile = St->isVolatile();
  405. bool isNonTemporal = St->isNonTemporal();
  406. AAMDNodes AAInfo = St->getAAInfo();
  407. assert(NVT.isByteSized() && "Expanded type not byte sized!");
  408. unsigned IncrementSize = NVT.getSizeInBits() / 8;
  409. SDValue Lo, Hi;
  410. GetExpandedOp(St->getValue(), Lo, Hi);
  411. if (TLI.hasBigEndianPartOrdering(ValueVT, DAG.getDataLayout()))
  412. std::swap(Lo, Hi);
  413. Lo = DAG.getStore(Chain, dl, Lo, Ptr, St->getPointerInfo(),
  414. isVolatile, isNonTemporal, Alignment, AAInfo);
  415. Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
  416. DAG.getConstant(IncrementSize, dl, Ptr.getValueType()));
  417. Hi = DAG.getStore(Chain, dl, Hi, Ptr,
  418. St->getPointerInfo().getWithOffset(IncrementSize),
  419. isVolatile, isNonTemporal,
  420. MinAlign(Alignment, IncrementSize), AAInfo);
  421. return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
  422. }
  423. //===--------------------------------------------------------------------===//
  424. // Generic Result Splitting.
  425. //===--------------------------------------------------------------------===//
  426. // Be careful to make no assumptions about which of Lo/Hi is stored first in
  427. // memory (for vectors it is always Lo first followed by Hi in the following
  428. // bytes; for integers and floats it is Lo first if and only if the machine is
  429. // little-endian).
  430. void DAGTypeLegalizer::SplitRes_MERGE_VALUES(SDNode *N, unsigned ResNo,
  431. SDValue &Lo, SDValue &Hi) {
  432. SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);
  433. GetSplitOp(Op, Lo, Hi);
  434. }
  435. void DAGTypeLegalizer::SplitRes_SELECT(SDNode *N, SDValue &Lo,
  436. SDValue &Hi) {
  437. SDValue LL, LH, RL, RH, CL, CH;
  438. SDLoc dl(N);
  439. GetSplitOp(N->getOperand(1), LL, LH);
  440. GetSplitOp(N->getOperand(2), RL, RH);
  441. SDValue Cond = N->getOperand(0);
  442. CL = CH = Cond;
  443. if (Cond.getValueType().isVector()) {
  444. // Check if there are already splitted versions of the vector available and
  445. // use those instead of splitting the mask operand again.
  446. if (getTypeAction(Cond.getValueType()) == TargetLowering::TypeSplitVector)
  447. GetSplitVector(Cond, CL, CH);
  448. else
  449. std::tie(CL, CH) = DAG.SplitVector(Cond, dl);
  450. }
  451. Lo = DAG.getNode(N->getOpcode(), dl, LL.getValueType(), CL, LL, RL);
  452. Hi = DAG.getNode(N->getOpcode(), dl, LH.getValueType(), CH, LH, RH);
  453. }
  454. void DAGTypeLegalizer::SplitRes_SELECT_CC(SDNode *N, SDValue &Lo,
  455. SDValue &Hi) {
  456. SDValue LL, LH, RL, RH;
  457. SDLoc dl(N);
  458. GetSplitOp(N->getOperand(2), LL, LH);
  459. GetSplitOp(N->getOperand(3), RL, RH);
  460. Lo = DAG.getNode(ISD::SELECT_CC, dl, LL.getValueType(), N->getOperand(0),
  461. N->getOperand(1), LL, RL, N->getOperand(4));
  462. Hi = DAG.getNode(ISD::SELECT_CC, dl, LH.getValueType(), N->getOperand(0),
  463. N->getOperand(1), LH, RH, N->getOperand(4));
  464. }
  465. void DAGTypeLegalizer::SplitRes_UNDEF(SDNode *N, SDValue &Lo, SDValue &Hi) {
  466. EVT LoVT, HiVT;
  467. std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(N->getValueType(0));
  468. Lo = DAG.getUNDEF(LoVT);
  469. Hi = DAG.getUNDEF(HiVT);
  470. }