diff options
author | Renato Golin <renato.golin@linaro.org> | 2013-01-16 21:29:55 +0000 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2013-01-16 21:29:55 +0000 |
commit | d3c965d6251e6d939f7797f8704d4e3a82f7e274 (patch) | |
tree | 8efa0dd2fa26f1d3c24e434257eeabe7bce8db22 /lib/Target/X86 | |
parent | ac47c1bc39d9d5de51d8ef5385545e643e076556 (diff) | |
download | external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.zip external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.tar.gz external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.tar.bz2 |
Change CostTable model to be global to all targets
Moving the X86CostTable to a common place, so that other back-ends
can share the code. Also simplifying it a bit and commoning up
tables with one and two types on operations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172658 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r-- | lib/Target/X86/X86TargetTransformInfo.cpp | 168 |
1 files changed, 66 insertions, 102 deletions
diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp index 675c896..a988cfe 100644 --- a/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/lib/Target/X86/X86TargetTransformInfo.cpp @@ -119,44 +119,6 @@ llvm::createX86TargetTransformInfoPass(const X86TargetMachine *TM) { // //===----------------------------------------------------------------------===// -namespace { -struct X86CostTblEntry { - int ISD; - MVT Type; - unsigned Cost; -}; -} - -static int -FindInTable(const X86CostTblEntry *Tbl, unsigned len, int ISD, MVT Ty) { - for (unsigned int i = 0; i < len; ++i) - if (Tbl[i].ISD == ISD && Tbl[i].Type == Ty) - return i; - - // Could not find an entry. - return -1; -} - -namespace { -struct X86TypeConversionCostTblEntry { - int ISD; - MVT Dst; - MVT Src; - unsigned Cost; -}; -} - -static int -FindInConvertTable(const X86TypeConversionCostTblEntry *Tbl, unsigned len, - int ISD, MVT Dst, MVT Src) { - for (unsigned int i = 0; i < len; ++i) - if (Tbl[i].ISD == ISD && Tbl[i].Src == Src && Tbl[i].Dst == Dst) - return i; - - // Could not find an entry. - return -1; -} - X86TTI::PopcntSupportKind X86TTI::getPopcntSupport(unsigned TyWidth) const { assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2"); // TODO: Currently the __builtin_popcount() implementation using SSE3 @@ -206,24 +168,24 @@ unsigned X86TTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty) const { int ISD = TLI->InstructionOpcodeToISD(Opcode); assert(ISD && "Invalid opcode"); - static const X86CostTblEntry AVX1CostTable[] = { - // We don't have to scalarize unsupported ops. We can issue two half-sized - // operations and we only need to extract the upper YMM half. - // Two ops + 1 extract + 1 insert = 4. - { ISD::MUL, MVT::v8i32, 4 }, - { ISD::SUB, MVT::v8i32, 4 }, - { ISD::ADD, MVT::v8i32, 4 }, - { ISD::MUL, MVT::v4i64, 4 }, - { ISD::SUB, MVT::v4i64, 4 }, - { ISD::ADD, MVT::v4i64, 4 }, - }; + // We don't have to scalarize unsupported ops. We can issue two half-sized + // operations and we only need to extract the upper YMM half. + // Two ops + 1 extract + 1 insert = 4. + static const CostTableEntry AVX1CostTable[] = { + { ISD::MUL, { MVT::v8i32 }, 4 }, + { ISD::SUB, { MVT::v8i32 }, 4 }, + { ISD::ADD, { MVT::v8i32 }, 4 }, + { ISD::MUL, { MVT::v4i64 }, 4 }, + { ISD::SUB, { MVT::v4i64 }, 4 }, + { ISD::ADD, { MVT::v4i64 }, 4 }, + }; + UnaryCostTable costTable (AVX1CostTable, array_lengthof(AVX1CostTable)); // Look for AVX1 lowering tricks. if (ST->hasAVX()) { - int Idx = FindInTable(AVX1CostTable, array_lengthof(AVX1CostTable), ISD, - LT.second); - if (Idx != -1) - return LT.first * AVX1CostTable[Idx].Cost; + unsigned cost = costTable.findCost(ISD, LT.second); + if (cost != BinaryCostTable::COST_NOT_FOUND) + return LT.first * cost; } // Fallback to the default implementation. return TargetTransformInfo::getArithmeticInstrCost(Opcode, Ty); @@ -254,30 +216,29 @@ unsigned X86TTI::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) const { if (!SrcTy.isSimple() || !DstTy.isSimple()) return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src); - static const X86TypeConversionCostTblEntry AVXConversionTbl[] = { - { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, - { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i16, 1 }, - { ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, - { ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i32, 1 }, - { ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 1 }, - { ISD::TRUNCATE, MVT::v8i16, MVT::v8i32, 1 }, - { ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 1 }, - { ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 1 }, - { ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 1 }, - { ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 1 }, - { ISD::FP_TO_SINT, MVT::v8i8, MVT::v8f32, 1 }, - { ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 1 }, - { ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i1, 6 }, - { ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i1, 9 }, - { ISD::TRUNCATE, MVT::v8i32, MVT::v8i64, 3 }, + static const CostTableEntry AVXConversionTbl[] = { + { ISD::SIGN_EXTEND, { MVT::v8i32, MVT::v8i16 }, 1 }, + { ISD::ZERO_EXTEND, { MVT::v8i32, MVT::v8i16 }, 1 }, + { ISD::SIGN_EXTEND, { MVT::v4i64, MVT::v4i32 }, 1 }, + { ISD::ZERO_EXTEND, { MVT::v4i64, MVT::v4i32 }, 1 }, + { ISD::TRUNCATE, { MVT::v4i32, MVT::v4i64 }, 1 }, + { ISD::TRUNCATE, { MVT::v8i16, MVT::v8i32 }, 1 }, + { ISD::SINT_TO_FP, { MVT::v8f32, MVT::v8i8 }, 1 }, + { ISD::SINT_TO_FP, { MVT::v4f32, MVT::v4i8 }, 1 }, + { ISD::UINT_TO_FP, { MVT::v8f32, MVT::v8i8 }, 1 }, + { ISD::UINT_TO_FP, { MVT::v4f32, MVT::v4i8 }, 1 }, + { ISD::FP_TO_SINT, { MVT::v8i8, MVT::v8f32 }, 1 }, + { ISD::FP_TO_SINT, { MVT::v4i8, MVT::v4f32 }, 1 }, + { ISD::ZERO_EXTEND, { MVT::v8i32, MVT::v8i1 }, 6 }, + { ISD::SIGN_EXTEND, { MVT::v8i32, MVT::v8i1 }, 9 }, + { ISD::TRUNCATE, { MVT::v8i32, MVT::v8i64 }, 3 } }; + BinaryCostTable costTable (AVXConversionTbl, array_lengthof(AVXConversionTbl)); if (ST->hasAVX()) { - int Idx = FindInConvertTable(AVXConversionTbl, - array_lengthof(AVXConversionTbl), - ISD, DstTy.getSimpleVT(), SrcTy.getSimpleVT()); - if (Idx != -1) - return AVXConversionTbl[Idx].Cost; + unsigned cost = costTable.findCost(ISD, DstTy.getSimpleVT(), SrcTy.getSimpleVT()); + if (cost != BinaryCostTable::COST_NOT_FOUND) + return cost; } return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src); @@ -293,48 +254,51 @@ unsigned X86TTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, int ISD = TLI->InstructionOpcodeToISD(Opcode); assert(ISD && "Invalid opcode"); - static const X86CostTblEntry SSE42CostTbl[] = { - { ISD::SETCC, MVT::v2f64, 1 }, - { ISD::SETCC, MVT::v4f32, 1 }, - { ISD::SETCC, MVT::v2i64, 1 }, - { ISD::SETCC, MVT::v4i32, 1 }, - { ISD::SETCC, MVT::v8i16, 1 }, - { ISD::SETCC, MVT::v16i8, 1 }, + static const CostTableEntry SSE42CostTbl[] = { + { ISD::SETCC, { MVT::v2f64 }, 1 }, + { ISD::SETCC, { MVT::v4f32 }, 1 }, + { ISD::SETCC, { MVT::v2i64 }, 1 }, + { ISD::SETCC, { MVT::v4i32 }, 1 }, + { ISD::SETCC, { MVT::v8i16 }, 1 }, + { ISD::SETCC, { MVT::v16i8 }, 1 }, }; + UnaryCostTable costTableSSE4 (SSE42CostTbl, array_lengthof(SSE42CostTbl)); - static const X86CostTblEntry AVX1CostTbl[] = { - { ISD::SETCC, MVT::v4f64, 1 }, - { ISD::SETCC, MVT::v8f32, 1 }, + static const CostTableEntry AVX1CostTbl[] = { + { ISD::SETCC, { MVT::v4f64 }, 1 }, + { ISD::SETCC, { MVT::v8f32 }, 1 }, // AVX1 does not support 8-wide integer compare. - { ISD::SETCC, MVT::v4i64, 4 }, - { ISD::SETCC, MVT::v8i32, 4 }, - { ISD::SETCC, MVT::v16i16, 4 }, - { ISD::SETCC, MVT::v32i8, 4 }, + { ISD::SETCC, { MVT::v4i64 }, 4 }, + { ISD::SETCC, { MVT::v8i32 }, 4 }, + { ISD::SETCC, { MVT::v16i16 }, 4 }, + { ISD::SETCC, { MVT::v32i8 }, 4 }, }; + UnaryCostTable costTableAVX1 (AVX1CostTbl, array_lengthof(AVX1CostTbl)); - static const X86CostTblEntry AVX2CostTbl[] = { - { ISD::SETCC, MVT::v4i64, 1 }, - { ISD::SETCC, MVT::v8i32, 1 }, - { ISD::SETCC, MVT::v16i16, 1 }, - { ISD::SETCC, MVT::v32i8, 1 }, + static const CostTableEntry AVX2CostTbl[] = { + { ISD::SETCC, { MVT::v4i64 }, 1 }, + { ISD::SETCC, { MVT::v8i32 }, 1 }, + { ISD::SETCC, { MVT::v16i16 }, 1 }, + { ISD::SETCC, { MVT::v32i8 }, 1 }, }; + UnaryCostTable costTableAVX2 (AVX2CostTbl, array_lengthof(AVX2CostTbl)); if (ST->hasAVX2()) { - int Idx = FindInTable(AVX2CostTbl, array_lengthof(AVX2CostTbl), ISD, MTy); - if (Idx != -1) - return LT.first * AVX2CostTbl[Idx].Cost; + unsigned cost = costTableAVX2.findCost(ISD, MTy); + if (cost != BinaryCostTable::COST_NOT_FOUND) + return LT.first * cost; } if (ST->hasAVX()) { - int Idx = FindInTable(AVX1CostTbl, array_lengthof(AVX1CostTbl), ISD, MTy); - if (Idx != -1) - return LT.first * AVX1CostTbl[Idx].Cost; + unsigned cost = costTableAVX1.findCost(ISD, MTy); + if (cost != BinaryCostTable::COST_NOT_FOUND) + return LT.first * cost; } if (ST->hasSSE42()) { - int Idx = FindInTable(SSE42CostTbl, array_lengthof(SSE42CostTbl), ISD, MTy); - if (Idx != -1) - return LT.first * SSE42CostTbl[Idx].Cost; + unsigned cost = costTableSSE4.findCost(ISD, MTy); + if (cost != BinaryCostTable::COST_NOT_FOUND) + return LT.first * cost; } return TargetTransformInfo::getCmpSelInstrCost(Opcode, ValTy, CondTy); |