LegalizeTypesGeneric.cpp revision 193323
1193323Sed//===-------- LegalizeTypesGeneric.cpp - Generic type legalization --------===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This file implements generic type expansion and splitting for LegalizeTypes.
11193323Sed// The routines here perform legalization when the details of the type (such as
12193323Sed// whether it is an integer or a float) do not matter.
13193323Sed// Expansion is the act of changing a computation in an illegal type to be a
14193323Sed// computation in two identical registers of a smaller type.
15193323Sed// Splitting is the act of changing a computation in an illegal type to be a
16193323Sed// computation in two not necessarily identical registers of a smaller type.
17193323Sed//
18193323Sed//===----------------------------------------------------------------------===//
19193323Sed
20193323Sed#include "LegalizeTypes.h"
21193323Sed#include "llvm/Target/TargetData.h"
22193323Sed#include "llvm/CodeGen/PseudoSourceValue.h"
23193323Sedusing namespace llvm;
24193323Sed
25193323Sed//===----------------------------------------------------------------------===//
26193323Sed// Generic Result Expansion.
27193323Sed//===----------------------------------------------------------------------===//
28193323Sed
29193323Sed// These routines assume that the Lo/Hi part is stored first in memory on
30193323Sed// little/big-endian machines, followed by the Hi/Lo part.  This means that
31193323Sed// they cannot be used as is on vectors, for which Lo is always stored first.
32193323Sed
33193323Sedvoid DAGTypeLegalizer::ExpandRes_BIT_CONVERT(SDNode *N, SDValue &Lo,
34193323Sed                                             SDValue &Hi) {
35193323Sed  MVT OutVT = N->getValueType(0);
36193323Sed  MVT NOutVT = TLI.getTypeToTransformTo(OutVT);
37193323Sed  SDValue InOp = N->getOperand(0);
38193323Sed  MVT InVT = InOp.getValueType();
39193323Sed  DebugLoc dl = N->getDebugLoc();
40193323Sed
41193323Sed  // Handle some special cases efficiently.
42193323Sed  switch (getTypeAction(InVT)) {
43193323Sed    default:
44193323Sed      assert(false && "Unknown type action!");
45193323Sed    case Legal:
46193323Sed    case PromoteInteger:
47193323Sed      break;
48193323Sed    case SoftenFloat:
49193323Sed      // Convert the integer operand instead.
50193323Sed      SplitInteger(GetSoftenedFloat(InOp), Lo, Hi);
51193323Sed      Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Lo);
52193323Sed      Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Hi);
53193323Sed      return;
54193323Sed    case ExpandInteger:
55193323Sed    case ExpandFloat:
56193323Sed      // Convert the expanded pieces of the input.
57193323Sed      GetExpandedOp(InOp, Lo, Hi);
58193323Sed      Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Lo);
59193323Sed      Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Hi);
60193323Sed      return;
61193323Sed    case SplitVector:
62193323Sed      // Convert the split parts of the input if it was split in two.
63193323Sed      GetSplitVector(InOp, Lo, Hi);
64193323Sed      if (Lo.getValueType() == Hi.getValueType()) {
65193323Sed        if (TLI.isBigEndian())
66193323Sed          std::swap(Lo, Hi);
67193323Sed        Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Lo);
68193323Sed        Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Hi);
69193323Sed        return;
70193323Sed      }
71193323Sed      break;
72193323Sed    case ScalarizeVector:
73193323Sed      // Convert the element instead.
74193323Sed      SplitInteger(BitConvertToInteger(GetScalarizedVector(InOp)), Lo, Hi);
75193323Sed      Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Lo);
76193323Sed      Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Hi);
77193323Sed      return;
78193323Sed    case WidenVector: {
79193323Sed      assert(!(InVT.getVectorNumElements() & 1) && "Unsupported BIT_CONVERT");
80193323Sed      InOp = GetWidenedVector(InOp);
81193323Sed      MVT InNVT = MVT::getVectorVT(InVT.getVectorElementType(),
82193323Sed                                   InVT.getVectorNumElements()/2);
83193323Sed      Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, InNVT, InOp,
84193323Sed                       DAG.getIntPtrConstant(0));
85193323Sed      Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, InNVT, InOp,
86193323Sed                       DAG.getIntPtrConstant(InNVT.getVectorNumElements()));
87193323Sed      if (TLI.isBigEndian())
88193323Sed        std::swap(Lo, Hi);
89193323Sed      Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Lo);
90193323Sed      Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NOutVT, Hi);
91193323Sed      return;
92193323Sed    }
93193323Sed  }
94193323Sed
95193323Sed  // Lower the bit-convert to a store/load from the stack.
96193323Sed  assert(NOutVT.isByteSized() && "Expanded type not byte sized!");
97193323Sed
98193323Sed  // Create the stack frame object.  Make sure it is aligned for both
99193323Sed  // the source and expanded destination types.
100193323Sed  unsigned Alignment =
101193323Sed    TLI.getTargetData()->getPrefTypeAlignment(NOutVT.getTypeForMVT());
102193323Sed  SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment);
103193323Sed  int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
104193323Sed  const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
105193323Sed
106193323Sed  // Emit a store to the stack slot.
107193323Sed  SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, SV, 0);
108193323Sed
109193323Sed  // Load the first half from the stack slot.
110193323Sed  Lo = DAG.getLoad(NOutVT, dl, Store, StackPtr, SV, 0);
111193323Sed
112193323Sed  // Increment the pointer to the other half.
113193323Sed  unsigned IncrementSize = NOutVT.getSizeInBits() / 8;
114193323Sed  StackPtr = DAG.getNode(ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
115193323Sed                         DAG.getIntPtrConstant(IncrementSize));
116193323Sed
117193323Sed  // Load the second half from the stack slot.
118193323Sed  Hi = DAG.getLoad(NOutVT, dl, Store, StackPtr, SV, IncrementSize, false,
119193323Sed                   MinAlign(Alignment, IncrementSize));
120193323Sed
121193323Sed  // Handle endianness of the load.
122193323Sed  if (TLI.isBigEndian())
123193323Sed    std::swap(Lo, Hi);
124193323Sed}
125193323Sed
126193323Sedvoid DAGTypeLegalizer::ExpandRes_BUILD_PAIR(SDNode *N, SDValue &Lo,
127193323Sed                                            SDValue &Hi) {
128193323Sed  // Return the operands.
129193323Sed  Lo = N->getOperand(0);
130193323Sed  Hi = N->getOperand(1);
131193323Sed}
132193323Sed
133193323Sedvoid DAGTypeLegalizer::ExpandRes_EXTRACT_ELEMENT(SDNode *N, SDValue &Lo,
134193323Sed                                                 SDValue &Hi) {
135193323Sed  GetExpandedOp(N->getOperand(0), Lo, Hi);
136193323Sed  SDValue Part = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() ?
137193323Sed                   Hi : Lo;
138193323Sed
139193323Sed  assert(Part.getValueType() == N->getValueType(0) &&
140193323Sed         "Type twice as big as expanded type not itself expanded!");
141193323Sed
142193323Sed  GetPairElements(Part, Lo, Hi);
143193323Sed}
144193323Sed
145193323Sedvoid DAGTypeLegalizer::ExpandRes_EXTRACT_VECTOR_ELT(SDNode *N, SDValue &Lo,
146193323Sed                                                    SDValue &Hi) {
147193323Sed  SDValue OldVec = N->getOperand(0);
148193323Sed  unsigned OldElts = OldVec.getValueType().getVectorNumElements();
149193323Sed  DebugLoc dl = N->getDebugLoc();
150193323Sed
151193323Sed  // Convert to a vector of the expanded element type, for example
152193323Sed  // <3 x i64> -> <6 x i32>.
153193323Sed  MVT OldVT = N->getValueType(0);
154193323Sed  MVT NewVT = TLI.getTypeToTransformTo(OldVT);
155193323Sed
156193323Sed  SDValue NewVec = DAG.getNode(ISD::BIT_CONVERT, dl,
157193323Sed                                 MVT::getVectorVT(NewVT, 2*OldElts),
158193323Sed                                 OldVec);
159193323Sed
160193323Sed  // Extract the elements at 2 * Idx and 2 * Idx + 1 from the new vector.
161193323Sed  SDValue Idx = N->getOperand(1);
162193323Sed
163193323Sed  // Make sure the type of Idx is big enough to hold the new values.
164193323Sed  if (Idx.getValueType().bitsLT(TLI.getPointerTy()))
165193323Sed    Idx = DAG.getNode(ISD::ZERO_EXTEND, dl, TLI.getPointerTy(), Idx);
166193323Sed
167193323Sed  Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, Idx);
168193323Sed  Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, NewVec, Idx);
169193323Sed
170193323Sed  Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx,
171193323Sed                    DAG.getConstant(1, Idx.getValueType()));
172193323Sed  Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT, NewVec, Idx);
173193323Sed
174193323Sed  if (TLI.isBigEndian())
175193323Sed    std::swap(Lo, Hi);
176193323Sed}
177193323Sed
178193323Sedvoid DAGTypeLegalizer::ExpandRes_NormalLoad(SDNode *N, SDValue &Lo,
179193323Sed                                            SDValue &Hi) {
180193323Sed  assert(ISD::isNormalLoad(N) && "This routine only for normal loads!");
181193323Sed  DebugLoc dl = N->getDebugLoc();
182193323Sed
183193323Sed  LoadSDNode *LD = cast<LoadSDNode>(N);
184193323Sed  MVT NVT = TLI.getTypeToTransformTo(LD->getValueType(0));
185193323Sed  SDValue Chain = LD->getChain();
186193323Sed  SDValue Ptr = LD->getBasePtr();
187193323Sed  int SVOffset = LD->getSrcValueOffset();
188193323Sed  unsigned Alignment = LD->getAlignment();
189193323Sed  bool isVolatile = LD->isVolatile();
190193323Sed
191193323Sed  assert(NVT.isByteSized() && "Expanded type not byte sized!");
192193323Sed
193193323Sed  Lo = DAG.getLoad(NVT, dl, Chain, Ptr, LD->getSrcValue(), SVOffset,
194193323Sed                   isVolatile, Alignment);
195193323Sed
196193323Sed  // Increment the pointer to the other half.
197193323Sed  unsigned IncrementSize = NVT.getSizeInBits() / 8;
198193323Sed  Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
199193323Sed                    DAG.getIntPtrConstant(IncrementSize));
200193323Sed  Hi = DAG.getLoad(NVT, dl, Chain, Ptr, LD->getSrcValue(),
201193323Sed                   SVOffset+IncrementSize,
202193323Sed                   isVolatile, MinAlign(Alignment, IncrementSize));
203193323Sed
204193323Sed  // Build a factor node to remember that this load is independent of the
205193323Sed  // other one.
206193323Sed  Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
207193323Sed                      Hi.getValue(1));
208193323Sed
209193323Sed  // Handle endianness of the load.
210193323Sed  if (TLI.isBigEndian())
211193323Sed    std::swap(Lo, Hi);
212193323Sed
213193323Sed  // Modified the chain - switch anything that used the old chain to use
214193323Sed  // the new one.
215193323Sed  ReplaceValueWith(SDValue(N, 1), Chain);
216193323Sed}
217193323Sed
218193323Sedvoid DAGTypeLegalizer::ExpandRes_VAARG(SDNode *N, SDValue &Lo, SDValue &Hi) {
219193323Sed  MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
220193323Sed  SDValue Chain = N->getOperand(0);
221193323Sed  SDValue Ptr = N->getOperand(1);
222193323Sed  DebugLoc dl = N->getDebugLoc();
223193323Sed
224193323Sed  Lo = DAG.getVAArg(NVT, dl, Chain, Ptr, N->getOperand(2));
225193323Sed  Hi = DAG.getVAArg(NVT, dl, Lo.getValue(1), Ptr, N->getOperand(2));
226193323Sed
227193323Sed  // Handle endianness of the load.
228193323Sed  if (TLI.isBigEndian())
229193323Sed    std::swap(Lo, Hi);
230193323Sed
231193323Sed  // Modified the chain - switch anything that used the old chain to use
232193323Sed  // the new one.
233193323Sed  ReplaceValueWith(SDValue(N, 1), Hi.getValue(1));
234193323Sed}
235193323Sed
236193323Sed
237193323Sed//===--------------------------------------------------------------------===//
238193323Sed// Generic Operand Expansion.
239193323Sed//===--------------------------------------------------------------------===//
240193323Sed
241193323SedSDValue DAGTypeLegalizer::ExpandOp_BIT_CONVERT(SDNode *N) {
242193323Sed  DebugLoc dl = N->getDebugLoc();
243193323Sed  if (N->getValueType(0).isVector()) {
244193323Sed    // An illegal expanding type is being converted to a legal vector type.
245193323Sed    // Make a two element vector out of the expanded parts and convert that
246193323Sed    // instead, but only if the new vector type is legal (otherwise there
247193323Sed    // is no point, and it might create expansion loops).  For example, on
248193323Sed    // x86 this turns v1i64 = BIT_CONVERT i64 into v1i64 = BIT_CONVERT v2i32.
249193323Sed    MVT OVT = N->getOperand(0).getValueType();
250193323Sed    MVT NVT = MVT::getVectorVT(TLI.getTypeToTransformTo(OVT), 2);
251193323Sed
252193323Sed    if (isTypeLegal(NVT)) {
253193323Sed      SDValue Parts[2];
254193323Sed      GetExpandedOp(N->getOperand(0), Parts[0], Parts[1]);
255193323Sed
256193323Sed      if (TLI.isBigEndian())
257193323Sed        std::swap(Parts[0], Parts[1]);
258193323Sed
259193323Sed      SDValue Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, NVT, Parts, 2);
260193323Sed      return DAG.getNode(ISD::BIT_CONVERT, dl, N->getValueType(0), Vec);
261193323Sed    }
262193323Sed  }
263193323Sed
264193323Sed  // Otherwise, store to a temporary and load out again as the new type.
265193323Sed  return CreateStackStoreLoad(N->getOperand(0), N->getValueType(0));
266193323Sed}
267193323Sed
268193323SedSDValue DAGTypeLegalizer::ExpandOp_BUILD_VECTOR(SDNode *N) {
269193323Sed  // The vector type is legal but the element type needs expansion.
270193323Sed  MVT VecVT = N->getValueType(0);
271193323Sed  unsigned NumElts = VecVT.getVectorNumElements();
272193323Sed  MVT OldVT = N->getOperand(0).getValueType();
273193323Sed  MVT NewVT = TLI.getTypeToTransformTo(OldVT);
274193323Sed  DebugLoc dl = N->getDebugLoc();
275193323Sed
276193323Sed  assert(OldVT == VecVT.getVectorElementType() &&
277193323Sed         "BUILD_VECTOR operand type doesn't match vector element type!");
278193323Sed
279193323Sed  // Build a vector of twice the length out of the expanded elements.
280193323Sed  // For example <3 x i64> -> <6 x i32>.
281193323Sed  std::vector<SDValue> NewElts;
282193323Sed  NewElts.reserve(NumElts*2);
283193323Sed
284193323Sed  for (unsigned i = 0; i < NumElts; ++i) {
285193323Sed    SDValue Lo, Hi;
286193323Sed    GetExpandedOp(N->getOperand(i), Lo, Hi);
287193323Sed    if (TLI.isBigEndian())
288193323Sed      std::swap(Lo, Hi);
289193323Sed    NewElts.push_back(Lo);
290193323Sed    NewElts.push_back(Hi);
291193323Sed  }
292193323Sed
293193323Sed  SDValue NewVec = DAG.getNode(ISD::BUILD_VECTOR, dl,
294193323Sed                                 MVT::getVectorVT(NewVT, NewElts.size()),
295193323Sed                                 &NewElts[0], NewElts.size());
296193323Sed
297193323Sed  // Convert the new vector to the old vector type.
298193323Sed  return DAG.getNode(ISD::BIT_CONVERT, dl, VecVT, NewVec);
299193323Sed}
300193323Sed
301193323SedSDValue DAGTypeLegalizer::ExpandOp_EXTRACT_ELEMENT(SDNode *N) {
302193323Sed  SDValue Lo, Hi;
303193323Sed  GetExpandedOp(N->getOperand(0), Lo, Hi);
304193323Sed  return cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() ? Hi : Lo;
305193323Sed}
306193323Sed
307193323SedSDValue DAGTypeLegalizer::ExpandOp_INSERT_VECTOR_ELT(SDNode *N) {
308193323Sed  // The vector type is legal but the element type needs expansion.
309193323Sed  MVT VecVT = N->getValueType(0);
310193323Sed  unsigned NumElts = VecVT.getVectorNumElements();
311193323Sed  DebugLoc dl = N->getDebugLoc();
312193323Sed
313193323Sed  SDValue Val = N->getOperand(1);
314193323Sed  MVT OldEVT = Val.getValueType();
315193323Sed  MVT NewEVT = TLI.getTypeToTransformTo(OldEVT);
316193323Sed
317193323Sed  assert(OldEVT == VecVT.getVectorElementType() &&
318193323Sed         "Inserted element type doesn't match vector element type!");
319193323Sed
320193323Sed  // Bitconvert to a vector of twice the length with elements of the expanded
321193323Sed  // type, insert the expanded vector elements, and then convert back.
322193323Sed  MVT NewVecVT = MVT::getVectorVT(NewEVT, NumElts*2);
323193323Sed  SDValue NewVec = DAG.getNode(ISD::BIT_CONVERT, dl,
324193323Sed                               NewVecVT, N->getOperand(0));
325193323Sed
326193323Sed  SDValue Lo, Hi;
327193323Sed  GetExpandedOp(Val, Lo, Hi);
328193323Sed  if (TLI.isBigEndian())
329193323Sed    std::swap(Lo, Hi);
330193323Sed
331193323Sed  SDValue Idx = N->getOperand(2);
332193323Sed  Idx = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, Idx);
333193323Sed  NewVec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVecVT, NewVec, Lo, Idx);
334193323Sed  Idx = DAG.getNode(ISD::ADD, dl,
335193323Sed                    Idx.getValueType(), Idx, DAG.getIntPtrConstant(1));
336193323Sed  NewVec =  DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVecVT, NewVec, Hi, Idx);
337193323Sed
338193323Sed  // Convert the new vector to the old vector type.
339193323Sed  return DAG.getNode(ISD::BIT_CONVERT, dl, VecVT, NewVec);
340193323Sed}
341193323Sed
342193323SedSDValue DAGTypeLegalizer::ExpandOp_SCALAR_TO_VECTOR(SDNode *N) {
343193323Sed  DebugLoc dl = N->getDebugLoc();
344193323Sed  MVT VT = N->getValueType(0);
345193323Sed  assert(VT.getVectorElementType() == N->getOperand(0).getValueType() &&
346193323Sed         "SCALAR_TO_VECTOR operand type doesn't match vector element type!");
347193323Sed  unsigned NumElts = VT.getVectorNumElements();
348193323Sed  SmallVector<SDValue, 16> Ops(NumElts);
349193323Sed  Ops[0] = N->getOperand(0);
350193323Sed  SDValue UndefVal = DAG.getUNDEF(Ops[0].getValueType());
351193323Sed  for (unsigned i = 1; i < NumElts; ++i)
352193323Sed    Ops[i] = UndefVal;
353193323Sed  return DAG.getNode(ISD::BUILD_VECTOR, dl, VT, &Ops[0], NumElts);
354193323Sed}
355193323Sed
356193323SedSDValue DAGTypeLegalizer::ExpandOp_NormalStore(SDNode *N, unsigned OpNo) {
357193323Sed  assert(ISD::isNormalStore(N) && "This routine only for normal stores!");
358193323Sed  assert(OpNo == 1 && "Can only expand the stored value so far");
359193323Sed  DebugLoc dl = N->getDebugLoc();
360193323Sed
361193323Sed  StoreSDNode *St = cast<StoreSDNode>(N);
362193323Sed  MVT NVT = TLI.getTypeToTransformTo(St->getValue().getValueType());
363193323Sed  SDValue Chain = St->getChain();
364193323Sed  SDValue Ptr = St->getBasePtr();
365193323Sed  int SVOffset = St->getSrcValueOffset();
366193323Sed  unsigned Alignment = St->getAlignment();
367193323Sed  bool isVolatile = St->isVolatile();
368193323Sed
369193323Sed  assert(NVT.isByteSized() && "Expanded type not byte sized!");
370193323Sed  unsigned IncrementSize = NVT.getSizeInBits() / 8;
371193323Sed
372193323Sed  SDValue Lo, Hi;
373193323Sed  GetExpandedOp(St->getValue(), Lo, Hi);
374193323Sed
375193323Sed  if (TLI.isBigEndian())
376193323Sed    std::swap(Lo, Hi);
377193323Sed
378193323Sed  Lo = DAG.getStore(Chain, dl, Lo, Ptr, St->getSrcValue(), SVOffset,
379193323Sed                    isVolatile, Alignment);
380193323Sed
381193323Sed  Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
382193323Sed                    DAG.getIntPtrConstant(IncrementSize));
383193323Sed  assert(isTypeLegal(Ptr.getValueType()) && "Pointers must be legal!");
384193323Sed  Hi = DAG.getStore(Chain, dl, Hi, Ptr, St->getSrcValue(),
385193323Sed                    SVOffset + IncrementSize,
386193323Sed                    isVolatile, MinAlign(Alignment, IncrementSize));
387193323Sed
388193323Sed  return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
389193323Sed}
390193323Sed
391193323Sed
392193323Sed//===--------------------------------------------------------------------===//
393193323Sed// Generic Result Splitting.
394193323Sed//===--------------------------------------------------------------------===//
395193323Sed
396193323Sed// Be careful to make no assumptions about which of Lo/Hi is stored first in
397193323Sed// memory (for vectors it is always Lo first followed by Hi in the following
398193323Sed// bytes; for integers and floats it is Lo first if and only if the machine is
399193323Sed// little-endian).
400193323Sed
401193323Sedvoid DAGTypeLegalizer::SplitRes_MERGE_VALUES(SDNode *N,
402193323Sed                                             SDValue &Lo, SDValue &Hi) {
403193323Sed  // A MERGE_VALUES node can produce any number of values.  We know that the
404193323Sed  // first illegal one needs to be expanded into Lo/Hi.
405193323Sed  unsigned i;
406193323Sed
407193323Sed  // The string of legal results gets turned into input operands, which have
408193323Sed  // the same type.
409193323Sed  for (i = 0; isTypeLegal(N->getValueType(i)); ++i)
410193323Sed    ReplaceValueWith(SDValue(N, i), SDValue(N->getOperand(i)));
411193323Sed
412193323Sed  // The first illegal result must be the one that needs to be expanded.
413193323Sed  GetSplitOp(N->getOperand(i), Lo, Hi);
414193323Sed
415193323Sed  // Legalize the rest of the results into the input operands whether they are
416193323Sed  // legal or not.
417193323Sed  unsigned e = N->getNumValues();
418193323Sed  for (++i; i != e; ++i)
419193323Sed    ReplaceValueWith(SDValue(N, i), SDValue(N->getOperand(i)));
420193323Sed}
421193323Sed
422193323Sedvoid DAGTypeLegalizer::SplitRes_SELECT(SDNode *N, SDValue &Lo,
423193323Sed                                       SDValue &Hi) {
424193323Sed  SDValue LL, LH, RL, RH;
425193323Sed  DebugLoc dl = N->getDebugLoc();
426193323Sed  GetSplitOp(N->getOperand(1), LL, LH);
427193323Sed  GetSplitOp(N->getOperand(2), RL, RH);
428193323Sed
429193323Sed  SDValue Cond = N->getOperand(0);
430193323Sed  Lo = DAG.getNode(ISD::SELECT, dl, LL.getValueType(), Cond, LL, RL);
431193323Sed  Hi = DAG.getNode(ISD::SELECT, dl, LH.getValueType(), Cond, LH, RH);
432193323Sed}
433193323Sed
434193323Sedvoid DAGTypeLegalizer::SplitRes_SELECT_CC(SDNode *N, SDValue &Lo,
435193323Sed                                          SDValue &Hi) {
436193323Sed  SDValue LL, LH, RL, RH;
437193323Sed  DebugLoc dl = N->getDebugLoc();
438193323Sed  GetSplitOp(N->getOperand(2), LL, LH);
439193323Sed  GetSplitOp(N->getOperand(3), RL, RH);
440193323Sed
441193323Sed  Lo = DAG.getNode(ISD::SELECT_CC, dl, LL.getValueType(), N->getOperand(0),
442193323Sed                   N->getOperand(1), LL, RL, N->getOperand(4));
443193323Sed  Hi = DAG.getNode(ISD::SELECT_CC, dl, LH.getValueType(), N->getOperand(0),
444193323Sed                   N->getOperand(1), LH, RH, N->getOperand(4));
445193323Sed}
446193323Sed
447193323Sedvoid DAGTypeLegalizer::SplitRes_UNDEF(SDNode *N, SDValue &Lo, SDValue &Hi) {
448193323Sed  MVT LoVT, HiVT;
449193323Sed  DebugLoc dl = N->getDebugLoc();
450193323Sed  GetSplitDestVTs(N->getValueType(0), LoVT, HiVT);
451193323Sed  Lo = DAG.getUNDEF(LoVT);
452193323Sed  Hi = DAG.getUNDEF(HiVT);
453193323Sed}
454