Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 1 | // llvm/Target/TargetTransformImpl.cpp - Target Loop Trans Info ---*- C++ -*-=// |
| 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 | #include "llvm/Target/TargetTransformImpl.h" |
| 11 | #include "llvm/Target/TargetLowering.h" |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 12 | #include <utility> |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace llvm; |
| 15 | |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | // |
| 18 | // Calls used by scalar transformations. |
| 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 22 | bool ScalarTargetTransformImpl::isLegalAddImmediate(int64_t imm) const { |
| 23 | return TLI->isLegalAddImmediate(imm); |
| 24 | } |
| 25 | |
| 26 | bool ScalarTargetTransformImpl::isLegalICmpImmediate(int64_t imm) const { |
| 27 | return TLI->isLegalICmpImmediate(imm); |
| 28 | } |
| 29 | |
Chandler Carruth | 64e407b | 2013-01-05 03:36:17 +0000 | [diff] [blame^] | 30 | bool ScalarTargetTransformImpl::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, |
| 31 | int64_t BaseOffset, bool HasBaseReg, |
| 32 | int64_t Scale) const { |
| 33 | AddrMode AM; |
| 34 | AM.BaseGV = BaseGV; |
| 35 | AM.BaseOffs = BaseOffset; |
| 36 | AM.HasBaseReg = HasBaseReg; |
| 37 | AM.Scale = Scale; |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 38 | return TLI->isLegalAddressingMode(AM, Ty); |
| 39 | } |
| 40 | |
| 41 | bool ScalarTargetTransformImpl::isTruncateFree(Type *Ty1, Type *Ty2) const { |
| 42 | return TLI->isTruncateFree(Ty1, Ty2); |
| 43 | } |
| 44 | |
| 45 | bool ScalarTargetTransformImpl::isTypeLegal(Type *Ty) const { |
| 46 | EVT T = TLI->getValueType(Ty); |
| 47 | return TLI->isTypeLegal(T); |
| 48 | } |
| 49 | |
| 50 | unsigned ScalarTargetTransformImpl::getJumpBufAlignment() const { |
| 51 | return TLI->getJumpBufAlignment(); |
| 52 | } |
| 53 | |
| 54 | unsigned ScalarTargetTransformImpl::getJumpBufSize() const { |
| 55 | return TLI->getJumpBufSize(); |
| 56 | } |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 57 | |
Hans Wennborg | 04d7d13 | 2012-10-30 11:23:25 +0000 | [diff] [blame] | 58 | bool ScalarTargetTransformImpl::shouldBuildLookupTables() const { |
| 59 | return TLI->supportJumpTables() && |
| 60 | (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) || |
| 61 | TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other)); |
| 62 | } |
| 63 | |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 64 | //===----------------------------------------------------------------------===// |
| 65 | // |
| 66 | // Calls used by the vectorizers. |
| 67 | // |
| 68 | //===----------------------------------------------------------------------===// |
Nadav Rotem | e623702 | 2012-11-05 19:32:46 +0000 | [diff] [blame] | 69 | int VectorTargetTransformImpl::InstructionOpcodeToISD(unsigned Opcode) const { |
Renato Golin | e5372d6 | 2012-10-26 12:24:52 +0000 | [diff] [blame] | 70 | enum InstructionOpcodes { |
| 71 | #define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM, |
| 72 | #define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 73 | #include "llvm/IR/Instruction.def" |
Renato Golin | e5372d6 | 2012-10-26 12:24:52 +0000 | [diff] [blame] | 74 | }; |
| 75 | switch (static_cast<InstructionOpcodes>(Opcode)) { |
| 76 | case Ret: return 0; |
| 77 | case Br: return 0; |
| 78 | case Switch: return 0; |
| 79 | case IndirectBr: return 0; |
| 80 | case Invoke: return 0; |
| 81 | case Resume: return 0; |
| 82 | case Unreachable: return 0; |
| 83 | case Add: return ISD::ADD; |
| 84 | case FAdd: return ISD::FADD; |
| 85 | case Sub: return ISD::SUB; |
| 86 | case FSub: return ISD::FSUB; |
| 87 | case Mul: return ISD::MUL; |
| 88 | case FMul: return ISD::FMUL; |
| 89 | case UDiv: return ISD::UDIV; |
| 90 | case SDiv: return ISD::UDIV; |
| 91 | case FDiv: return ISD::FDIV; |
| 92 | case URem: return ISD::UREM; |
| 93 | case SRem: return ISD::SREM; |
| 94 | case FRem: return ISD::FREM; |
| 95 | case Shl: return ISD::SHL; |
| 96 | case LShr: return ISD::SRL; |
| 97 | case AShr: return ISD::SRA; |
| 98 | case And: return ISD::AND; |
| 99 | case Or: return ISD::OR; |
| 100 | case Xor: return ISD::XOR; |
| 101 | case Alloca: return 0; |
| 102 | case Load: return ISD::LOAD; |
| 103 | case Store: return ISD::STORE; |
| 104 | case GetElementPtr: return 0; |
| 105 | case Fence: return 0; |
| 106 | case AtomicCmpXchg: return 0; |
| 107 | case AtomicRMW: return 0; |
| 108 | case Trunc: return ISD::TRUNCATE; |
| 109 | case ZExt: return ISD::ZERO_EXTEND; |
Nadav Rotem | 2d1528b | 2012-11-05 22:20:53 +0000 | [diff] [blame] | 110 | case SExt: return ISD::SIGN_EXTEND; |
Renato Golin | e5372d6 | 2012-10-26 12:24:52 +0000 | [diff] [blame] | 111 | case FPToUI: return ISD::FP_TO_UINT; |
| 112 | case FPToSI: return ISD::FP_TO_SINT; |
| 113 | case UIToFP: return ISD::UINT_TO_FP; |
| 114 | case SIToFP: return ISD::SINT_TO_FP; |
| 115 | case FPTrunc: return ISD::FP_ROUND; |
| 116 | case FPExt: return ISD::FP_EXTEND; |
| 117 | case PtrToInt: return ISD::BITCAST; |
| 118 | case IntToPtr: return ISD::BITCAST; |
| 119 | case BitCast: return ISD::BITCAST; |
| 120 | case ICmp: return ISD::SETCC; |
| 121 | case FCmp: return ISD::SETCC; |
| 122 | case PHI: return 0; |
| 123 | case Call: return 0; |
| 124 | case Select: return ISD::SELECT; |
| 125 | case UserOp1: return 0; |
| 126 | case UserOp2: return 0; |
| 127 | case VAArg: return 0; |
| 128 | case ExtractElement: return ISD::EXTRACT_VECTOR_ELT; |
| 129 | case InsertElement: return ISD::INSERT_VECTOR_ELT; |
| 130 | case ShuffleVector: return ISD::VECTOR_SHUFFLE; |
| 131 | case ExtractValue: return ISD::MERGE_VALUES; |
| 132 | case InsertValue: return ISD::MERGE_VALUES; |
| 133 | case LandingPad: return 0; |
| 134 | } |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 135 | |
Renato Golin | e5372d6 | 2012-10-26 12:24:52 +0000 | [diff] [blame] | 136 | llvm_unreachable("Unknown instruction type encountered!"); |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Nadav Rotem | e623702 | 2012-11-05 19:32:46 +0000 | [diff] [blame] | 139 | std::pair<unsigned, MVT> |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 140 | VectorTargetTransformImpl::getTypeLegalizationCost(Type *Ty) const { |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 141 | LLVMContext &C = Ty->getContext(); |
| 142 | EVT MTy = TLI->getValueType(Ty); |
| 143 | |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 144 | unsigned Cost = 1; |
| 145 | // We keep legalizing the type until we find a legal kind. We assume that |
| 146 | // the only operation that costs anything is the split. After splitting |
| 147 | // we need to handle two types. |
| 148 | while (true) { |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 149 | TargetLowering::LegalizeKind LK = TLI->getTypeConversion(C, MTy); |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 150 | |
| 151 | if (LK.first == TargetLowering::TypeLegal) |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 152 | return std::make_pair(Cost, MTy.getSimpleVT()); |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 153 | |
Nadav Rotem | 75138f5 | 2012-11-05 21:11:10 +0000 | [diff] [blame] | 154 | if (LK.first == TargetLowering::TypeSplitVector || |
| 155 | LK.first == TargetLowering::TypeExpandInteger) |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 156 | Cost *= 2; |
| 157 | |
| 158 | // Keep legalizing the type. |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 159 | MTy = LK.second; |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 162 | |
| 163 | unsigned |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 164 | VectorTargetTransformImpl::getScalarizationOverhead(Type *Ty, |
| 165 | bool Insert, |
| 166 | bool Extract) const { |
| 167 | assert (Ty->isVectorTy() && "Can only scalarize vectors"); |
Hans Wennborg | b9051db | 2012-10-29 16:26:52 +0000 | [diff] [blame] | 168 | unsigned Cost = 0; |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 169 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 170 | for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) { |
| 171 | if (Insert) |
| 172 | Cost += getVectorInstrCost(Instruction::InsertElement, Ty, i); |
| 173 | if (Extract) |
| 174 | Cost += getVectorInstrCost(Instruction::ExtractElement, Ty, i); |
Nadav Rotem | 1e19e46 | 2012-10-25 18:17:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 177 | return Cost; |
| 178 | } |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 179 | |
Nadav Rotem | e503319 | 2013-01-04 17:48:25 +0000 | [diff] [blame] | 180 | unsigned VectorTargetTransformImpl::getNumberOfRegisters(bool Vector) const { |
Nadav Rotem | 5d592d2 | 2013-01-04 18:40:39 +0000 | [diff] [blame] | 181 | return 1; |
Nadav Rotem | e503319 | 2013-01-04 17:48:25 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 184 | unsigned VectorTargetTransformImpl::getArithmeticInstrCost(unsigned Opcode, |
| 185 | Type *Ty) const { |
| 186 | // Check if any of the operands are vector operands. |
| 187 | int ISD = InstructionOpcodeToISD(Opcode); |
| 188 | assert(ISD && "Invalid opcode"); |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 189 | |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 190 | std::pair<unsigned, MVT> LT = getTypeLegalizationCost(Ty); |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 191 | |
Nadav Rotem | 6f3d81a | 2012-12-23 17:31:23 +0000 | [diff] [blame] | 192 | if (TLI->isOperationLegalOrPromote(ISD, LT.second)) { |
| 193 | // The operation is legal. Assume it costs 1. |
| 194 | // If the type is split to multiple registers, assume that thre is some |
| 195 | // overhead to this. |
| 196 | // TODO: Once we have extract/insert subvector cost we need to use them. |
| 197 | if (LT.first > 1) |
| 198 | return LT.first * 2; |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 199 | return LT.first * 1; |
| 200 | } |
| 201 | |
Nadav Rotem | 6f3d81a | 2012-12-23 17:31:23 +0000 | [diff] [blame] | 202 | if (!TLI->isOperationExpand(ISD, LT.second)) { |
| 203 | // If the operation is custom lowered then assume |
| 204 | // thare the code is twice as expensive. |
| 205 | return LT.first * 2; |
| 206 | } |
| 207 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 208 | // Else, assume that we need to scalarize this op. |
| 209 | if (Ty->isVectorTy()) { |
| 210 | unsigned Num = Ty->getVectorNumElements(); |
| 211 | unsigned Cost = getArithmeticInstrCost(Opcode, Ty->getScalarType()); |
| 212 | // return the cost of multiple scalar invocation plus the cost of inserting |
| 213 | // and extracting the values. |
| 214 | return getScalarizationOverhead(Ty, true, true) + Num * Cost; |
| 215 | } |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 216 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 217 | // We don't know anything about this scalar instruction. |
| 218 | return 1; |
| 219 | } |
| 220 | |
Nadav Rotem | daf7b5c | 2012-12-24 08:57:47 +0000 | [diff] [blame] | 221 | unsigned VectorTargetTransformImpl::getShuffleCost(ShuffleKind Kind, |
Hal Finkel | 82860f6 | 2013-01-03 02:34:09 +0000 | [diff] [blame] | 222 | Type *Tp, int Index, Type *SubTp) const { |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 223 | return 1; |
| 224 | } |
| 225 | |
| 226 | unsigned VectorTargetTransformImpl::getCastInstrCost(unsigned Opcode, Type *Dst, |
| 227 | Type *Src) const { |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 228 | int ISD = InstructionOpcodeToISD(Opcode); |
| 229 | assert(ISD && "Invalid opcode"); |
| 230 | |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 231 | std::pair<unsigned, MVT> SrcLT = getTypeLegalizationCost(Src); |
| 232 | std::pair<unsigned, MVT> DstLT = getTypeLegalizationCost(Dst); |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 233 | |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 234 | // Handle scalar conversions. |
| 235 | if (!Src->isVectorTy() && !Dst->isVectorTy()) { |
Nadav Rotem | 2b0c96f | 2012-11-02 21:47:47 +0000 | [diff] [blame] | 236 | |
Nadav Rotem | 955cf53 | 2012-11-11 05:34:45 +0000 | [diff] [blame] | 237 | // Scalar bitcasts are usually free. |
| 238 | if (Opcode == Instruction::BitCast) |
| 239 | return 0; |
| 240 | |
| 241 | if (Opcode == Instruction::Trunc && |
| 242 | TLI->isTruncateFree(SrcLT.second, DstLT.second)) |
| 243 | return 0; |
| 244 | |
| 245 | if (Opcode == Instruction::ZExt && |
| 246 | TLI->isZExtFree(SrcLT.second, DstLT.second)) |
Nadav Rotem | 2b0c96f | 2012-11-02 21:47:47 +0000 | [diff] [blame] | 247 | return 0; |
| 248 | |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 249 | // Just check the op cost. If the operation is legal then assume it costs 1. |
| 250 | if (!TLI->isOperationExpand(ISD, DstLT.second)) |
| 251 | return 1; |
| 252 | |
| 253 | // Assume that illegal scalar instruction are expensive. |
| 254 | return 4; |
| 255 | } |
| 256 | |
| 257 | // Check vector-to-vector casts. |
| 258 | if (Dst->isVectorTy() && Src->isVectorTy()) { |
| 259 | |
| 260 | // If the cast is between same-sized registers, then the check is simple. |
| 261 | if (SrcLT.first == DstLT.first && |
| 262 | SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) { |
| 263 | |
| 264 | // Bitcast between types that are legalized to the same type are free. |
Nadav Rotem | 2d1528b | 2012-11-05 22:20:53 +0000 | [diff] [blame] | 265 | if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc) |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 266 | return 0; |
| 267 | |
Nadav Rotem | 2d1528b | 2012-11-05 22:20:53 +0000 | [diff] [blame] | 268 | // Assume that Zext is done using AND. |
| 269 | if (Opcode == Instruction::ZExt) |
| 270 | return 1; |
| 271 | |
| 272 | // Assume that sext is done using SHL and SRA. |
| 273 | if (Opcode == Instruction::SExt) |
| 274 | return 2; |
| 275 | |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 276 | // Just check the op cost. If the operation is legal then assume it costs |
| 277 | // 1 and multiply by the type-legalization overhead. |
| 278 | if (!TLI->isOperationExpand(ISD, DstLT.second)) |
| 279 | return SrcLT.first * 1; |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 280 | } |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 281 | |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 282 | // If we are converting vectors and the operation is illegal, or |
| 283 | // if the vectors are legalized to different types, estimate the |
| 284 | // scalarization costs. |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 285 | unsigned Num = Dst->getVectorNumElements(); |
Hal Finkel | c588e0e | 2012-10-30 02:41:57 +0000 | [diff] [blame] | 286 | unsigned Cost = getCastInstrCost(Opcode, Dst->getScalarType(), |
| 287 | Src->getScalarType()); |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 288 | |
| 289 | // Return the cost of multiple scalar invocation plus the cost of |
| 290 | // inserting and extracting the values. |
| 291 | return getScalarizationOverhead(Dst, true, true) + Num * Cost; |
Hal Finkel | c588e0e | 2012-10-30 02:41:57 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Nadav Rotem | d54fed2 | 2012-12-23 07:23:55 +0000 | [diff] [blame] | 294 | // We already handled vector-to-vector and scalar-to-scalar conversions. This |
Nadav Rotem | 0dba9a9 | 2012-10-31 20:52:26 +0000 | [diff] [blame] | 295 | // is where we handle bitcast between vectors and scalars. We need to assume |
| 296 | // that the conversion is scalarized in one way or another. |
| 297 | if (Opcode == Instruction::BitCast) |
| 298 | // Illegal bitcasts are done by storing and loading from a stack slot. |
| 299 | return (Src->isVectorTy()? getScalarizationOverhead(Src, false, true):0) + |
| 300 | (Dst->isVectorTy()? getScalarizationOverhead(Dst, true, false):0); |
| 301 | |
| 302 | llvm_unreachable("Unhandled cast"); |
| 303 | } |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 304 | |
| 305 | unsigned VectorTargetTransformImpl::getCFInstrCost(unsigned Opcode) const { |
Nadav Rotem | d54fed2 | 2012-12-23 07:23:55 +0000 | [diff] [blame] | 306 | // Branches are assumed to be predicted. |
Nadav Rotem | 0602bb4 | 2012-12-05 21:21:26 +0000 | [diff] [blame] | 307 | return 0; |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | unsigned VectorTargetTransformImpl::getCmpSelInstrCost(unsigned Opcode, |
| 311 | Type *ValTy, |
| 312 | Type *CondTy) const { |
| 313 | int ISD = InstructionOpcodeToISD(Opcode); |
| 314 | assert(ISD && "Invalid opcode"); |
Hans Wennborg | b9051db | 2012-10-29 16:26:52 +0000 | [diff] [blame] | 315 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 316 | // Selects on vectors are actually vector selects. |
| 317 | if (ISD == ISD::SELECT) { |
| 318 | assert(CondTy && "CondTy must exist"); |
| 319 | if (CondTy->isVectorTy()) |
| 320 | ISD = ISD::VSELECT; |
| 321 | } |
| 322 | |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 323 | std::pair<unsigned, MVT> LT = getTypeLegalizationCost(ValTy); |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 324 | |
| 325 | if (!TLI->isOperationExpand(ISD, LT.second)) { |
| 326 | // The operation is legal. Assume it costs 1. Multiply |
| 327 | // by the type-legalization overhead. |
| 328 | return LT.first * 1; |
| 329 | } |
| 330 | |
| 331 | // Otherwise, assume that the cast is scalarized. |
| 332 | if (ValTy->isVectorTy()) { |
| 333 | unsigned Num = ValTy->getVectorNumElements(); |
| 334 | if (CondTy) |
| 335 | CondTy = CondTy->getScalarType(); |
| 336 | unsigned Cost = getCmpSelInstrCost(Opcode, ValTy->getScalarType(), |
| 337 | CondTy); |
| 338 | |
Nadav Rotem | 75138f5 | 2012-11-05 21:11:10 +0000 | [diff] [blame] | 339 | // Return the cost of multiple scalar invocation plus the cost of inserting |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 340 | // and extracting the values. |
| 341 | return getScalarizationOverhead(ValTy, true, false) + Num * Cost; |
| 342 | } |
| 343 | |
Nadav Rotem | e498160 | 2012-10-29 05:28:35 +0000 | [diff] [blame] | 344 | // Unknown scalar opcode. |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 345 | return 1; |
| 346 | } |
| 347 | |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 348 | unsigned VectorTargetTransformImpl::getVectorInstrCost(unsigned Opcode, |
| 349 | Type *Val, |
| 350 | unsigned Index) const { |
| 351 | return 1; |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | unsigned |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 355 | VectorTargetTransformImpl::getMemoryOpCost(unsigned Opcode, Type *Src, |
| 356 | unsigned Alignment, |
| 357 | unsigned AddressSpace) const { |
Nadav Rotem | c2a537b | 2012-12-21 01:24:36 +0000 | [diff] [blame] | 358 | assert(!Src->isVoidTy() && "Invalid type"); |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 359 | std::pair<unsigned, MVT> LT = getTypeLegalizationCost(Src); |
Nadav Rotem | a5a3a61 | 2012-10-26 23:49:28 +0000 | [diff] [blame] | 360 | |
Nadav Rotem | 2652c50 | 2012-10-24 23:47:38 +0000 | [diff] [blame] | 361 | // Assume that all loads of legal types cost 1. |
| 362 | return LT.first; |
Nadav Rotem | 2704834 | 2012-10-24 17:22:41 +0000 | [diff] [blame] | 363 | } |
Hal Finkel | 102a7c0 | 2012-10-26 04:28:02 +0000 | [diff] [blame] | 364 | |
| 365 | unsigned |
Paul Redmond | 8801666 | 2012-12-09 20:42:17 +0000 | [diff] [blame] | 366 | VectorTargetTransformImpl::getIntrinsicInstrCost(Intrinsic::ID, Type *RetTy, |
| 367 | ArrayRef<Type*> Tys) const { |
| 368 | // assume that we need to scalarize this intrinsic. |
| 369 | unsigned ScalarizationCost = 0; |
| 370 | unsigned ScalarCalls = 1; |
| 371 | if (RetTy->isVectorTy()) { |
| 372 | ScalarizationCost = getScalarizationOverhead(RetTy, true, false); |
| 373 | ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements()); |
| 374 | } |
| 375 | for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) { |
| 376 | if (Tys[i]->isVectorTy()) { |
| 377 | ScalarizationCost += getScalarizationOverhead(Tys[i], false, true); |
| 378 | ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements()); |
| 379 | } |
| 380 | } |
| 381 | return ScalarCalls + ScalarizationCost; |
| 382 | } |
| 383 | |
| 384 | unsigned |
Hal Finkel | 102a7c0 | 2012-10-26 04:28:02 +0000 | [diff] [blame] | 385 | VectorTargetTransformImpl::getNumberOfParts(Type *Tp) const { |
Nadav Rotem | 887c1fe | 2012-11-05 23:57:45 +0000 | [diff] [blame] | 386 | std::pair<unsigned, MVT> LT = getTypeLegalizationCost(Tp); |
Nadav Rotem | e498160 | 2012-10-29 05:28:35 +0000 | [diff] [blame] | 387 | return LT.first; |
Hal Finkel | 102a7c0 | 2012-10-26 04:28:02 +0000 | [diff] [blame] | 388 | } |