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