# Changeset View

Changeset View

# Standalone View

Standalone View

# include/llvm/CodeGen/BasicTTIImpl.h

Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Line(s) | 287 | unsigned getArithmeticInstrCost( | |||
---|---|---|---|---|---|

310 | 310 | | |||

311 | if (!TLI->isOperationExpand(ISD, LT.second)) { | 311 | if (!TLI->isOperationExpand(ISD, LT.second)) { | ||

312 | // If the operation is custom lowered, then assume that the code is twice | 312 | // If the operation is custom lowered, then assume that the code is twice | ||

313 | // as expensive. | 313 | // as expensive. | ||

314 | return LT.first * 2 * OpCost; | 314 | return LT.first * 2 * OpCost; | ||

315 | } | 315 | } | ||

316 | 316 | | |||

317 | // Else, assume that we need to scalarize this op. | 317 | // Else, assume that we need to scalarize this op. | ||

318 | // TODO: If one of the types get legalized by splitting, handle this | ||||

319 | // similarly to what getCastInstrCost() does. | ||||

318 | if (Ty->isVectorTy()) { | 320 | if (Ty->isVectorTy()) { | ||

319 | unsigned Num = Ty->getVectorNumElements(); | 321 | unsigned Num = Ty->getVectorNumElements(); | ||

320 | unsigned Cost = static_cast<T *>(this) | 322 | unsigned Cost = static_cast<T *>(this) | ||

321 | ->getArithmeticInstrCost(Opcode, Ty->getScalarType()); | 323 | ->getArithmeticInstrCost(Opcode, Ty->getScalarType()); | ||

322 | // return the cost of multiple scalar invocation plus the cost of | 324 | // return the cost of multiple scalar invocation plus the cost of | ||

323 | // inserting | 325 | // inserting | ||

324 | // and extracting the values. | 326 | // and extracting the values. | ||

325 | return getScalarizationOverhead(Ty, true, true) + Num * Cost; | 327 | return getScalarizationOverhead(Ty, true, true) + Num * Cost; | ||

▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 396 | if (SrcLT.first == DstLT.first && | |||

404 | 406 | | |||

405 | // Just check the op cost. If the operation is legal then assume it | 407 | // Just check the op cost. If the operation is legal then assume it | ||

406 | // costs | 408 | // costs | ||

407 | // 1 and multiply by the type-legalization overhead. | 409 | // 1 and multiply by the type-legalization overhead. | ||

408 | if (!TLI->isOperationExpand(ISD, DstLT.second)) | 410 | if (!TLI->isOperationExpand(ISD, DstLT.second)) | ||

409 | return SrcLT.first * 1; | 411 | return SrcLT.first * 1; | ||

410 | } | 412 | } | ||

411 | 413 | | |||

412 | // If we are converting vectors and the operation is illegal, or | 414 | // If we are legalizing by splitting, query the concrete TTI for the cost | ||

413 | // if the vectors are legalized to different types, estimate the | 415 | // of casting the original vector twice. We also need to factor int the | ||

414 | // scalarization costs. | 416 | // cost of the split itself. Count that as 1, to be consistent with | ||

415 | // TODO: This is probably a big overestimate. For splits, we should have | 417 | // TLI->getTypeLegalizationCost(). | ||

416 | // something like getTypeLegalizationCost() + 2 * getCastInstrCost(). | 418 | if ((TLI->getTypeAction(Src->getContext(), TLI->getValueType(DL, Src)) == | ||

417 | // The same applies to getCmpSelInstrCost() and getArithmeticInstrCost() | 419 | TargetLowering::TypeSplitVector) || | ||

420 | (TLI->getTypeAction(Dst->getContext(), TLI->getValueType(DL, Dst)) == | ||||

421 | TargetLowering::TypeSplitVector)) { | ||||

422 | Type *SplitDst = VectorType::get(Dst->getVectorElementType(), | ||||

423 | Dst->getVectorNumElements() / 2); | ||||

424 | Type *SplitSrc = VectorType::get(Src->getVectorElementType(), | ||||

425 | Src->getVectorNumElements() / 2); | ||||

426 | T *TTI = static_cast<T *>(this); | ||||

427 | return TTI->getVectorSplitCost() + | ||||

428 | (2 * TTI->getCastInstrCost(Opcode, SplitDst, SplitSrc)); | ||||

429 | } | ||||

430 | | ||||

431 | // In other cases where the source or destination are illegal, assume | ||||

432 | // the operation will get scalarized. | ||||

418 | unsigned Num = Dst->getVectorNumElements(); | 433 | unsigned Num = Dst->getVectorNumElements(); | ||

419 | unsigned Cost = static_cast<T *>(this)->getCastInstrCost( | 434 | unsigned Cost = static_cast<T *>(this)->getCastInstrCost( | ||

420 | Opcode, Dst->getScalarType(), Src->getScalarType()); | 435 | Opcode, Dst->getScalarType(), Src->getScalarType()); | ||

421 | 436 | | |||

422 | // Return the cost of multiple scalar invocation plus the cost of | 437 | // Return the cost of multiple scalar invocation plus the cost of | ||

423 | // inserting and extracting the values. | 438 | // inserting and extracting the values. | ||

424 | return getScalarizationOverhead(Dst, true, true) + Num * Cost; | 439 | return getScalarizationOverhead(Dst, true, true) + Num * Cost; | ||

425 | } | 440 | } | ||

▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 469 | unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) { | |||

467 | if (!(ValTy->isVectorTy() && !LT.second.isVector()) && | 482 | if (!(ValTy->isVectorTy() && !LT.second.isVector()) && | ||

468 | !TLI->isOperationExpand(ISD, LT.second)) { | 483 | !TLI->isOperationExpand(ISD, LT.second)) { | ||

469 | // The operation is legal. Assume it costs 1. Multiply | 484 | // The operation is legal. Assume it costs 1. Multiply | ||

470 | // by the type-legalization overhead. | 485 | // by the type-legalization overhead. | ||

471 | return LT.first * 1; | 486 | return LT.first * 1; | ||

472 | } | 487 | } | ||

473 | 488 | | |||

474 | // Otherwise, assume that the cast is scalarized. | 489 | // Otherwise, assume that the cast is scalarized. | ||

490 | // TODO: If one of the types get legalized by splitting, handle this | ||||

491 | // similarly to what getCastInstrCost() does. | ||||

475 | if (ValTy->isVectorTy()) { | 492 | if (ValTy->isVectorTy()) { | ||

476 | unsigned Num = ValTy->getVectorNumElements(); | 493 | unsigned Num = ValTy->getVectorNumElements(); | ||

477 | if (CondTy) | 494 | if (CondTy) | ||

478 | CondTy = CondTy->getScalarType(); | 495 | CondTy = CondTy->getScalarType(); | ||

479 | unsigned Cost = static_cast<T *>(this)->getCmpSelInstrCost( | 496 | unsigned Cost = static_cast<T *>(this)->getCmpSelInstrCost( | ||

480 | Opcode, ValTy->getScalarType(), CondTy); | 497 | Opcode, ValTy->getScalarType(), CondTy); | ||

481 | 498 | | |||

482 | // Return the cost of multiple scalar invocation plus the cost of | 499 | // Return the cost of multiple scalar invocation plus the cost of | ||

483 | // inserting | 500 | // inserting and extracting the values. | ||

484 | // and extracting the values. | | |||

485 | return getScalarizationOverhead(ValTy, true, false) + Num * Cost; | 501 | return getScalarizationOverhead(ValTy, true, false) + Num * Cost; | ||

486 | } | 502 | } | ||

487 | 503 | | |||

488 | // Unknown scalar opcode. | 504 | // Unknown scalar opcode. | ||

489 | return 1; | 505 | return 1; | ||

490 | } | 506 | } | ||

491 | 507 | | |||

492 | unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { | 508 | unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) { | ||

▲ Show 20 Lines • Show All 408 Lines • ▼ Show 20 Line(s) | 910 | unsigned getReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise) { | |||

901 | // Assume the pairwise shuffles add a cost. | 917 | // Assume the pairwise shuffles add a cost. | ||

902 | unsigned ShuffleCost = | 918 | unsigned ShuffleCost = | ||

903 | NumReduxLevels * (IsPairwise + 1) * | 919 | NumReduxLevels * (IsPairwise + 1) * | ||

904 | static_cast<T *>(this) | 920 | static_cast<T *>(this) | ||

905 | ->getShuffleCost(TTI::SK_ExtractSubvector, Ty, NumVecElts / 2, Ty); | 921 | ->getShuffleCost(TTI::SK_ExtractSubvector, Ty, NumVecElts / 2, Ty); | ||

906 | return ShuffleCost + ArithCost + getScalarizationOverhead(Ty, false, true); | 922 | return ShuffleCost + ArithCost + getScalarizationOverhead(Ty, false, true); | ||

907 | } | 923 | } | ||

908 | 924 | | |||

925 | unsigned getVectorSplitCost() { return 1; } | ||||

926 | | ||||

909 | /// @} | 927 | /// @} | ||

910 | }; | 928 | }; | ||

911 | 929 | | |||

912 | /// \brief Concrete BasicTTIImpl that can be used if no further customization | 930 | /// \brief Concrete BasicTTIImpl that can be used if no further customization | ||

913 | /// is needed. | 931 | /// is needed. | ||

914 | class BasicTTIImpl : public BasicTTIImplBase<BasicTTIImpl> { | 932 | class BasicTTIImpl : public BasicTTIImplBase<BasicTTIImpl> { | ||

915 | typedef BasicTTIImplBase<BasicTTIImpl> BaseT; | 933 | typedef BasicTTIImplBase<BasicTTIImpl> BaseT; | ||

916 | friend class BasicTTIImplBase<BasicTTIImpl>; | 934 | friend class BasicTTIImplBase<BasicTTIImpl>; | ||

Show All 21 Lines |