llvm.org GIT mirror llvm / a13b860
split the vector case out of getCopyToParts into its own function. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111990 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 138 addition(s) and 129 deletion(s). Raw diff Collapse all Expand all
240240 return SDValue();
241241 }
242242
243
244 static void getCopyToPartsVector(SelectionDAG &DAG, DebugLoc dl,
245 SDValue Val, SDValue *Parts, unsigned NumParts,
246 EVT PartVT);
247
243248 /// getCopyToParts - Create a series of nodes that contain the specified value
244249 /// split into legal parts. If the parts contain more bits than Val, then, for
245250 /// integers, ExtendKind can be used to specify how to generate the extra bits.
246 static void getCopyToParts(SelectionDAG &DAG, DebugLoc dl,
251 static void getCopyToParts(SelectionDAG &DAG, DebugLoc DL,
247252 SDValue Val, SDValue *Parts, unsigned NumParts,
248253 EVT PartVT,
249254 ISD::NodeType ExtendKind = ISD::ANY_EXTEND) {
255 EVT ValueVT = Val.getValueType();
256
257 // Handle the vector case separately.
258 if (ValueVT.isVector())
259 return getCopyToPartsVector(DAG, DL, Val, Parts, NumParts, PartVT);
260
250261 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
251 EVT PtrVT = TLI.getPointerTy();
252 EVT ValueVT = Val.getValueType();
253262 unsigned PartBits = PartVT.getSizeInBits();
254263 unsigned OrigNumParts = NumParts;
255264 assert(TLI.isTypeLegal(PartVT) && "Copying to an illegal type!");
256265
257 if (!NumParts)
266 if (NumParts == 0)
258267 return;
259268
260 if (!ValueVT.isVector()) {
261 if (PartVT == ValueVT) {
262 assert(NumParts == 1 && "No-op copy with multiple parts!");
263 Parts[0] = Val;
264 return;
265 }
266
267 if (NumParts * PartBits > ValueVT.getSizeInBits()) {
268 // If the parts cover more bits than the value has, promote the value.
269 if (PartVT.isFloatingPoint() && ValueVT.isFloatingPoint()) {
270 assert(NumParts == 1 && "Do not know what to promote to!");
271 Val = DAG.getNode(ISD::FP_EXTEND, dl, PartVT, Val);
272 } else if (PartVT.isInteger() && ValueVT.isInteger()) {
273 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
274 Val = DAG.getNode(ExtendKind, dl, ValueVT, Val);
275 } else {
276 llvm_unreachable("Unknown mismatch!");
269 assert(!ValueVT.isVector() && "Vector case handled elsewhere");
270 if (PartVT == ValueVT) {
271 assert(NumParts == 1 && "No-op copy with multiple parts!");
272 Parts[0] = Val;
273 return;
274 }
275
276 if (NumParts * PartBits > ValueVT.getSizeInBits()) {
277 // If the parts cover more bits than the value has, promote the value.
278 if (PartVT.isFloatingPoint() && ValueVT.isFloatingPoint()) {
279 assert(NumParts == 1 && "Do not know what to promote to!");
280 Val = DAG.getNode(ISD::FP_EXTEND, DL, PartVT, Val);
281 } else {
282 assert(PartVT.isInteger() && ValueVT.isInteger() &&
283 "Unknown mismatch!");
284 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
285 Val = DAG.getNode(ExtendKind, DL, ValueVT, Val);
286 }
287 } else if (PartBits == ValueVT.getSizeInBits()) {
288 // Different types of the same size.
289 assert(NumParts == 1 && PartVT != ValueVT);
290 Val = DAG.getNode(ISD::BIT_CONVERT, DL, PartVT, Val);
291 } else if (NumParts * PartBits < ValueVT.getSizeInBits()) {
292 // If the parts cover less bits than value has, truncate the value.
293 assert(PartVT.isInteger() && ValueVT.isInteger() &&
294 "Unknown mismatch!");
295 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
296 Val = DAG.getNode(ISD::TRUNCATE, DL, ValueVT, Val);
297 }
298
299 // The value may have changed - recompute ValueVT.
300 ValueVT = Val.getValueType();
301 assert(NumParts * PartBits == ValueVT.getSizeInBits() &&
302 "Failed to tile the value with PartVT!");
303
304 if (NumParts == 1) {
305 assert(PartVT == ValueVT && "Type conversion failed!");
306 Parts[0] = Val;
307 return;
308 }
309
310 // Expand the value into multiple parts.
311 if (NumParts & (NumParts - 1)) {
312 // The number of parts is not a power of 2. Split off and copy the tail.
313 assert(PartVT.isInteger() && ValueVT.isInteger() &&
314 "Do not know what to expand to!");
315 unsigned RoundParts = 1 << Log2_32(NumParts);
316 unsigned RoundBits = RoundParts * PartBits;
317 unsigned OddParts = NumParts - RoundParts;
318 SDValue OddVal = DAG.getNode(ISD::SRL, DL, ValueVT, Val,
319 DAG.getIntPtrConstant(RoundBits));
320 getCopyToParts(DAG, DL, OddVal, Parts + RoundParts, OddParts, PartVT);
321
322 if (TLI.isBigEndian())
323 // The odd parts were reversed by getCopyToParts - unreverse them.
324 std::reverse(Parts + RoundParts, Parts + NumParts);
325
326 NumParts = RoundParts;
327 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
328 Val = DAG.getNode(ISD::TRUNCATE, DL, ValueVT, Val);
329 }
330
331 // The number of parts is a power of 2. Repeatedly bisect the value using
332 // EXTRACT_ELEMENT.
333 Parts[0] = DAG.getNode(ISD::BIT_CONVERT, DL,
334 EVT::getIntegerVT(*DAG.getContext(),
335 ValueVT.getSizeInBits()),
336 Val);
337
338 for (unsigned StepSize = NumParts; StepSize > 1; StepSize /= 2) {
339 for (unsigned i = 0; i < NumParts; i += StepSize) {
340 unsigned ThisBits = StepSize * PartBits / 2;
341 EVT ThisVT = EVT::getIntegerVT(*DAG.getContext(), ThisBits);
342 SDValue &Part0 = Parts[i];
343 SDValue &Part1 = Parts[i+StepSize/2];
344
345 Part1 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL,
346 ThisVT, Part0, DAG.getIntPtrConstant(1));
347 Part0 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL,
348 ThisVT, Part0, DAG.getIntPtrConstant(0));
349
350 if (ThisBits == PartBits && ThisVT != PartVT) {
351 Part0 = DAG.getNode(ISD::BIT_CONVERT, DL, PartVT, Part0);
352 Part1 = DAG.getNode(ISD::BIT_CONVERT, DL, PartVT, Part1);
277353 }
278 } else if (PartBits == ValueVT.getSizeInBits()) {
279 // Different types of the same size.
280 assert(NumParts == 1 && PartVT != ValueVT);
281 Val = DAG.getNode(ISD::BIT_CONVERT, dl, PartVT, Val);
282 } else if (NumParts * PartBits < ValueVT.getSizeInBits()) {
283 // If the parts cover less bits than value has, truncate the value.
284 if (PartVT.isInteger() && ValueVT.isInteger()) {
285 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
286 Val = DAG.getNode(ISD::TRUNCATE, dl, ValueVT, Val);
287 } else {
288 llvm_unreachable("Unknown mismatch!");
289 }
290 }
291
292 // The value may have changed - recompute ValueVT.
293 ValueVT = Val.getValueType();
294 assert(NumParts * PartBits == ValueVT.getSizeInBits() &&
295 "Failed to tile the value with PartVT!");
296
297 if (NumParts == 1) {
298 assert(PartVT == ValueVT && "Type conversion failed!");
299 Parts[0] = Val;
300 return;
301 }
302
303 // Expand the value into multiple parts.
304 if (NumParts & (NumParts - 1)) {
305 // The number of parts is not a power of 2. Split off and copy the tail.
306 assert(PartVT.isInteger() && ValueVT.isInteger() &&
307 "Do not know what to expand to!");
308 unsigned RoundParts = 1 << Log2_32(NumParts);
309 unsigned RoundBits = RoundParts * PartBits;
310 unsigned OddParts = NumParts - RoundParts;
311 SDValue OddVal = DAG.getNode(ISD::SRL, dl, ValueVT, Val,
312 DAG.getConstant(RoundBits,
313 TLI.getPointerTy()));
314 getCopyToParts(DAG, dl, OddVal, Parts + RoundParts,
315 OddParts, PartVT);
316
317 if (TLI.isBigEndian())
318 // The odd parts were reversed by getCopyToParts - unreverse them.
319 std::reverse(Parts + RoundParts, Parts + NumParts);
320
321 NumParts = RoundParts;
322 ValueVT = EVT::getIntegerVT(*DAG.getContext(), NumParts * PartBits);
323 Val = DAG.getNode(ISD::TRUNCATE, dl, ValueVT, Val);
324 }
325
326 // The number of parts is a power of 2. Repeatedly bisect the value using
327 // EXTRACT_ELEMENT.
328 Parts[0] = DAG.getNode(ISD::BIT_CONVERT, dl,
329 EVT::getIntegerVT(*DAG.getContext(),
330 ValueVT.getSizeInBits()),
331 Val);
332
333 for (unsigned StepSize = NumParts; StepSize > 1; StepSize /= 2) {
334 for (unsigned i = 0; i < NumParts; i += StepSize) {
335 unsigned ThisBits = StepSize * PartBits / 2;
336 EVT ThisVT = EVT::getIntegerVT(*DAG.getContext(), ThisBits);
337 SDValue &Part0 = Parts[i];
338 SDValue &Part1 = Parts[i+StepSize/2];
339
340 Part1 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl,
341 ThisVT, Part0,
342 DAG.getConstant(1, PtrVT));
343 Part0 = DAG.getNode(ISD::EXTRACT_ELEMENT, dl,
344 ThisVT, Part0,
345 DAG.getConstant(0, PtrVT));
346
347 if (ThisBits == PartBits && ThisVT != PartVT) {
348 Part0 = DAG.getNode(ISD::BIT_CONVERT, dl,
349 PartVT, Part0);
350 Part1 = DAG.getNode(ISD::BIT_CONVERT, dl,
351 PartVT, Part1);
352 }
353 }
354 }
355
356 if (TLI.isBigEndian())
357 std::reverse(Parts, Parts + OrigNumParts);
358
359 return;
360 }
361
362 // Vector ValueVT.
354 }
355 }
356
357 if (TLI.isBigEndian())
358 std::reverse(Parts, Parts + OrigNumParts);
359 }
360
361
362 /// getCopyToPartsVector - Create a series of nodes that contain the specified
363 /// value split into legal parts.
364 static void getCopyToPartsVector(SelectionDAG &DAG, DebugLoc DL,
365 SDValue Val, SDValue *Parts, unsigned NumParts,
366 EVT PartVT) {
367 EVT ValueVT = Val.getValueType();
368 assert(ValueVT.isVector() && "Not a vector");
369 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
370
363371 if (NumParts == 1) {
364372 if (PartVT != ValueVT) {
365373 if (PartVT.getSizeInBits() == ValueVT.getSizeInBits()) {
366 Val = DAG.getNode(ISD::BIT_CONVERT, dl, PartVT, Val);
374 Val = DAG.getNode(ISD::BIT_CONVERT, DL, PartVT, Val);
367375 } else {
368376 assert(ValueVT.getVectorElementType() == PartVT &&
369377 ValueVT.getVectorNumElements() == 1 &&
370378 "Only trivial vector-to-scalar conversions should get here!");
371 Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
372 PartVT, Val,
373 DAG.getConstant(0, PtrVT));
379 Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL,
380 PartVT, Val, DAG.getIntPtrConstant(0));
374381 }
375382 }
376
383
377384 Parts[0] = Val;
378385 return;
379386 }
380
387
381388 // Handle a multi-element vector.
382389 EVT IntermediateVT, RegisterVT;
383390 unsigned NumIntermediates;
384391 unsigned NumRegs = TLI.getVectorTypeBreakdown(*DAG.getContext(), ValueVT,
385 IntermediateVT, NumIntermediates, RegisterVT);
392 IntermediateVT, NumIntermediates, RegisterVT);
386393 unsigned NumElements = ValueVT.getVectorNumElements();
387
394
388395 assert(NumRegs == NumParts && "Part count doesn't match vector breakdown!");
389396 NumParts = NumRegs; // Silence a compiler warning.
390397 assert(RegisterVT == PartVT && "Part type doesn't match vector breakdown!");
391
398
392399 // Split the vector into intermediate operands.
393400 SmallVector Ops(NumIntermediates);
394401 for (unsigned i = 0; i != NumIntermediates; ++i) {
395402 if (IntermediateVT.isVector())
396 Ops[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl,
403 Ops[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL,
397404 IntermediateVT, Val,
398 DAG.getConstant(i * (NumElements / NumIntermediates),
399 PtrVT));
405 DAG.getIntPtrConstant(i * (NumElements / NumIntermediates)));
400406 else
401 Ops[i] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
407 Ops[i] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL,
402408 IntermediateVT, Val,
403 DAG.getConstant(i, PtrVT));
404 }
405
409 DAG.getIntPtrConstant(i));
410 }
411
406412 // Split the intermediate operands into legal parts.
407413 if (NumParts == NumIntermediates) {
408414 // If the register was not expanded, promote or copy the value,
409415 // as appropriate.
410416 for (unsigned i = 0; i != NumParts; ++i)
411 getCopyToParts(DAG, dl, Ops[i], &Parts[i], 1, PartVT);
417 getCopyToParts(DAG, DL, Ops[i], &Parts[i], 1, PartVT);
412418 } else if (NumParts > 0) {
413419 // If the intermediate type was expanded, split each the value into
414420 // legal parts.
416422 "Must expand into a divisible number of parts!");
417423 unsigned Factor = NumParts / NumIntermediates;
418424 for (unsigned i = 0; i != NumIntermediates; ++i)
419 getCopyToParts(DAG, dl, Ops[i], &Parts[i*Factor], Factor, PartVT);
420 }
421 }
425 getCopyToParts(DAG, DL, Ops[i], &Parts[i*Factor], Factor, PartVT);
426 }
427 }
428
429
430
422431
423432 namespace {
424433 /// RegsForValue - This struct represents the registers (physical or virtual)
10191028 unsigned NumValues = ValueVTs.size();
10201029
10211030 SmallVector Chains(NumValues);
1022 EVT PtrVT = PtrValueVTs[0];
10231031 for (unsigned i = 0; i != NumValues; ++i) {
1024 SDValue Add = DAG.getNode(ISD::ADD, getCurDebugLoc(), PtrVT, RetPtr,
1025 DAG.getConstant(Offsets[i], PtrVT));
1032 SDValue Add = DAG.getNode(ISD::ADD, getCurDebugLoc(),
1033 RetPtr.getValueType(), RetPtr,
1034 DAG.getIntPtrConstant(Offsets[i]));
10261035 Chains[i] =
10271036 DAG.getStore(Chain, getCurDebugLoc(),
10281037 SDValue(RetOp.getNode(), RetOp.getResNo() + i),