LegalizeTypesGeneric.cpp 20 KB

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