blob: 0883ab0ce7f1e54179cd1a5f9f250ade891d50f1 [file] [log] [blame]
Chandler Carruthaeef83c2013-01-07 01:37:14 +00001//===- BasicTargetTransformInfo.cpp - Basic target-independent TTI impl ---===//
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/// \file
10/// This file provides the implementation of a basic TargetTransformInfo pass
11/// predicated on the target abstractions present in the target independent
12/// code generator. It uses these (primarily TargetLowering) to model as much
13/// of the TTI query interface as possible. It is included by most targets so
14/// that they can specialize only a small subset of the query space.
15///
16//===----------------------------------------------------------------------===//
17
18#define DEBUG_TYPE "basictti"
19#include "llvm/CodeGen/Passes.h"
Chandler Carruthbe049292013-01-07 03:08:10 +000020#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruthaeef83c2013-01-07 01:37:14 +000021#include "llvm/Target/TargetLowering.h"
Chandler Carruthaeef83c2013-01-07 01:37:14 +000022#include <utility>
23
24using namespace llvm;
25
26namespace {
27
28class BasicTTI : public ImmutablePass, public TargetTransformInfo {
Bill Wendlingea442812013-06-19 20:51:24 +000029 const TargetMachine *TM;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000030
31 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
32 /// are set if the result needs to be inserted and/or extracted from vectors.
33 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
34
Bill Wendlingea442812013-06-19 20:51:24 +000035 const TargetLoweringBase *getTLI() const { return TM->getTargetLowering(); }
36
Chandler Carruthaeef83c2013-01-07 01:37:14 +000037public:
Bill Wendlingea442812013-06-19 20:51:24 +000038 BasicTTI() : ImmutablePass(ID), TM(0) {
Chandler Carruthaeef83c2013-01-07 01:37:14 +000039 llvm_unreachable("This pass cannot be directly constructed");
40 }
41
Bill Wendlingea442812013-06-19 20:51:24 +000042 BasicTTI(const TargetMachine *TM) : ImmutablePass(ID), TM(TM) {
Chandler Carruthaeef83c2013-01-07 01:37:14 +000043 initializeBasicTTIPass(*PassRegistry::getPassRegistry());
44 }
45
46 virtual void initializePass() {
47 pushTTIStack(this);
48 }
49
50 virtual void finalizePass() {
51 popTTIStack();
52 }
53
54 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
55 TargetTransformInfo::getAnalysisUsage(AU);
56 }
57
58 /// Pass identification.
59 static char ID;
60
61 /// Provide necessary pointer adjustments for the two base classes.
62 virtual void *getAdjustedAnalysisPointer(const void *ID) {
63 if (ID == &TargetTransformInfo::ID)
64 return (TargetTransformInfo*)this;
65 return this;
66 }
67
Tom Stellard57e6b2d2013-07-27 00:01:07 +000068 virtual bool hasBranchDivergence() const;
69
Chandler Carruthaeef83c2013-01-07 01:37:14 +000070 /// \name Scalar TTI Implementations
71 /// @{
72
73 virtual bool isLegalAddImmediate(int64_t imm) const;
74 virtual bool isLegalICmpImmediate(int64_t imm) const;
75 virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
76 int64_t BaseOffset, bool HasBaseReg,
77 int64_t Scale) const;
Quentin Colombet06f5ebc2013-05-31 21:29:03 +000078 virtual int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
79 int64_t BaseOffset, bool HasBaseReg,
80 int64_t Scale) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000081 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
82 virtual bool isTypeLegal(Type *Ty) const;
83 virtual unsigned getJumpBufAlignment() const;
84 virtual unsigned getJumpBufSize() const;
85 virtual bool shouldBuildLookupTables() const;
86
87 /// @}
88
89 /// \name Vector TTI Implementations
90 /// @{
91
92 virtual unsigned getNumberOfRegisters(bool Vector) const;
Nadav Rotem83be7b02013-01-09 01:15:42 +000093 virtual unsigned getMaximumUnrollFactor() const;
Nadav Rotem14925e62013-01-09 22:29:00 +000094 virtual unsigned getRegisterBitWidth(bool Vector) const;
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +000095 virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
96 OperandValueKind,
97 OperandValueKind) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000098 virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
99 int Index, Type *SubTp) const;
100 virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
101 Type *Src) const;
102 virtual unsigned getCFInstrCost(unsigned Opcode) const;
103 virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
104 Type *CondTy) const;
105 virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
106 unsigned Index) const;
107 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
108 unsigned Alignment,
109 unsigned AddressSpace) const;
110 virtual unsigned getIntrinsicInstrCost(Intrinsic::ID, Type *RetTy,
111 ArrayRef<Type*> Tys) const;
112 virtual unsigned getNumberOfParts(Type *Tp) const;
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000113 virtual unsigned getAddressComputationCost(Type *Ty, bool IsComplex) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000114
115 /// @}
116};
117
118}
119
120INITIALIZE_AG_PASS(BasicTTI, TargetTransformInfo, "basictti",
121 "Target independent code generator's TTI", true, true, false)
122char BasicTTI::ID = 0;
123
124ImmutablePass *
Bill Wendlingea442812013-06-19 20:51:24 +0000125llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
126 return new BasicTTI(TM);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000127}
128
Tom Stellard57e6b2d2013-07-27 00:01:07 +0000129bool BasicTTI::hasBranchDivergence() const { return false; }
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000130
131bool BasicTTI::isLegalAddImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000132 return getTLI()->isLegalAddImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000133}
134
135bool BasicTTI::isLegalICmpImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000136 return getTLI()->isLegalICmpImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000137}
138
139bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
140 int64_t BaseOffset, bool HasBaseReg,
141 int64_t Scale) const {
Benjamin Kramer69e42db2013-01-11 20:05:37 +0000142 TargetLoweringBase::AddrMode AM;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000143 AM.BaseGV = BaseGV;
144 AM.BaseOffs = BaseOffset;
145 AM.HasBaseReg = HasBaseReg;
146 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000147 return getTLI()->isLegalAddressingMode(AM, Ty);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000148}
149
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000150int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
151 int64_t BaseOffset, bool HasBaseReg,
152 int64_t Scale) const {
153 TargetLoweringBase::AddrMode AM;
154 AM.BaseGV = BaseGV;
155 AM.BaseOffs = BaseOffset;
156 AM.HasBaseReg = HasBaseReg;
157 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000158 return getTLI()->getScalingFactorCost(AM, Ty);
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000159}
160
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000161bool BasicTTI::isTruncateFree(Type *Ty1, Type *Ty2) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000162 return getTLI()->isTruncateFree(Ty1, Ty2);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000163}
164
165bool BasicTTI::isTypeLegal(Type *Ty) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000166 EVT T = getTLI()->getValueType(Ty);
167 return getTLI()->isTypeLegal(T);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000168}
169
170unsigned BasicTTI::getJumpBufAlignment() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000171 return getTLI()->getJumpBufAlignment();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000172}
173
174unsigned BasicTTI::getJumpBufSize() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000175 return getTLI()->getJumpBufSize();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000176}
177
178bool BasicTTI::shouldBuildLookupTables() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000179 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000180 return TLI->supportJumpTables() &&
181 (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
182 TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
183}
184
185//===----------------------------------------------------------------------===//
186//
187// Calls used by the vectorizers.
188//
189//===----------------------------------------------------------------------===//
190
191unsigned BasicTTI::getScalarizationOverhead(Type *Ty, bool Insert,
192 bool Extract) const {
193 assert (Ty->isVectorTy() && "Can only scalarize vectors");
194 unsigned Cost = 0;
195
196 for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) {
197 if (Insert)
198 Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
199 if (Extract)
200 Cost += TopTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, i);
201 }
202
203 return Cost;
204}
205
206unsigned BasicTTI::getNumberOfRegisters(bool Vector) const {
207 return 1;
208}
209
Nadav Rotem14925e62013-01-09 22:29:00 +0000210unsigned BasicTTI::getRegisterBitWidth(bool Vector) const {
211 return 32;
212}
213
Nadav Rotem83be7b02013-01-09 01:15:42 +0000214unsigned BasicTTI::getMaximumUnrollFactor() const {
215 return 1;
216}
217
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +0000218unsigned BasicTTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
219 OperandValueKind,
220 OperandValueKind) const {
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000221 // Check if any of the operands are vector operands.
Bill Wendlingea442812013-06-19 20:51:24 +0000222 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000223 int ISD = TLI->InstructionOpcodeToISD(Opcode);
224 assert(ISD && "Invalid opcode");
225
226 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty);
227
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000228 bool IsFloat = Ty->getScalarType()->isFloatingPointTy();
Nadav Rotem42082002013-04-14 05:55:18 +0000229 // Assume that floating point arithmetic operations cost twice as much as
230 // integer operations.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000231 unsigned OpCost = (IsFloat ? 2 : 1);
232
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000233 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
234 // The operation is legal. Assume it costs 1.
Nadav Rotem42082002013-04-14 05:55:18 +0000235 // If the type is split to multiple registers, assume that there is some
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000236 // overhead to this.
237 // TODO: Once we have extract/insert subvector cost we need to use them.
238 if (LT.first > 1)
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000239 return LT.first * 2 * OpCost;
240 return LT.first * 1 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000241 }
242
243 if (!TLI->isOperationExpand(ISD, LT.second)) {
244 // If the operation is custom lowered then assume
245 // thare the code is twice as expensive.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000246 return LT.first * 2 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000247 }
248
249 // Else, assume that we need to scalarize this op.
250 if (Ty->isVectorTy()) {
251 unsigned Num = Ty->getVectorNumElements();
252 unsigned Cost = TopTTI->getArithmeticInstrCost(Opcode, Ty->getScalarType());
253 // return the cost of multiple scalar invocation plus the cost of inserting
254 // and extracting the values.
255 return getScalarizationOverhead(Ty, true, true) + Num * Cost;
256 }
257
258 // We don't know anything about this scalar instruction.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000259 return OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000260}
261
262unsigned BasicTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
263 Type *SubTp) const {
264 return 1;
265}
266
267unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
268 Type *Src) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000269 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000270 int ISD = TLI->InstructionOpcodeToISD(Opcode);
271 assert(ISD && "Invalid opcode");
272
273 std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(Src);
274 std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(Dst);
275
Nadav Rotem3e40d922013-01-11 19:54:13 +0000276 // Check for NOOP conversions.
277 if (SrcLT.first == DstLT.first &&
278 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
279
280 // Bitcast between types that are legalized to the same type are free.
281 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
282 return 0;
283 }
284
285 if (Opcode == Instruction::Trunc &&
286 TLI->isTruncateFree(SrcLT.second, DstLT.second))
287 return 0;
288
289 if (Opcode == Instruction::ZExt &&
290 TLI->isZExtFree(SrcLT.second, DstLT.second))
291 return 0;
292
293 // If the cast is marked as legal (or promote) then assume low cost.
294 if (TLI->isOperationLegalOrPromote(ISD, DstLT.second))
295 return 1;
296
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000297 // Handle scalar conversions.
298 if (!Src->isVectorTy() && !Dst->isVectorTy()) {
299
300 // Scalar bitcasts are usually free.
301 if (Opcode == Instruction::BitCast)
302 return 0;
303
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000304 // Just check the op cost. If the operation is legal then assume it costs 1.
305 if (!TLI->isOperationExpand(ISD, DstLT.second))
306 return 1;
307
308 // Assume that illegal scalar instruction are expensive.
309 return 4;
310 }
311
312 // Check vector-to-vector casts.
313 if (Dst->isVectorTy() && Src->isVectorTy()) {
314
315 // If the cast is between same-sized registers, then the check is simple.
316 if (SrcLT.first == DstLT.first &&
317 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
318
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000319 // Assume that Zext is done using AND.
320 if (Opcode == Instruction::ZExt)
321 return 1;
322
323 // Assume that sext is done using SHL and SRA.
324 if (Opcode == Instruction::SExt)
325 return 2;
326
327 // Just check the op cost. If the operation is legal then assume it costs
328 // 1 and multiply by the type-legalization overhead.
329 if (!TLI->isOperationExpand(ISD, DstLT.second))
330 return SrcLT.first * 1;
331 }
332
333 // If we are converting vectors and the operation is illegal, or
334 // if the vectors are legalized to different types, estimate the
335 // scalarization costs.
336 unsigned Num = Dst->getVectorNumElements();
337 unsigned Cost = TopTTI->getCastInstrCost(Opcode, Dst->getScalarType(),
338 Src->getScalarType());
339
340 // Return the cost of multiple scalar invocation plus the cost of
341 // inserting and extracting the values.
342 return getScalarizationOverhead(Dst, true, true) + Num * Cost;
343 }
344
345 // We already handled vector-to-vector and scalar-to-scalar conversions. This
346 // is where we handle bitcast between vectors and scalars. We need to assume
347 // that the conversion is scalarized in one way or another.
348 if (Opcode == Instruction::BitCast)
349 // Illegal bitcasts are done by storing and loading from a stack slot.
350 return (Src->isVectorTy()? getScalarizationOverhead(Src, false, true):0) +
351 (Dst->isVectorTy()? getScalarizationOverhead(Dst, true, false):0);
352
353 llvm_unreachable("Unhandled cast");
354 }
355
356unsigned BasicTTI::getCFInstrCost(unsigned Opcode) const {
357 // Branches are assumed to be predicted.
358 return 0;
359}
360
361unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
362 Type *CondTy) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000363 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000364 int ISD = TLI->InstructionOpcodeToISD(Opcode);
365 assert(ISD && "Invalid opcode");
366
367 // Selects on vectors are actually vector selects.
368 if (ISD == ISD::SELECT) {
369 assert(CondTy && "CondTy must exist");
370 if (CondTy->isVectorTy())
371 ISD = ISD::VSELECT;
372 }
373
374 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
375
376 if (!TLI->isOperationExpand(ISD, LT.second)) {
377 // The operation is legal. Assume it costs 1. Multiply
378 // by the type-legalization overhead.
379 return LT.first * 1;
380 }
381
382 // Otherwise, assume that the cast is scalarized.
383 if (ValTy->isVectorTy()) {
384 unsigned Num = ValTy->getVectorNumElements();
385 if (CondTy)
386 CondTy = CondTy->getScalarType();
387 unsigned Cost = TopTTI->getCmpSelInstrCost(Opcode, ValTy->getScalarType(),
388 CondTy);
389
390 // Return the cost of multiple scalar invocation plus the cost of inserting
391 // and extracting the values.
392 return getScalarizationOverhead(ValTy, true, false) + Num * Cost;
393 }
394
395 // Unknown scalar opcode.
396 return 1;
397}
398
399unsigned BasicTTI::getVectorInstrCost(unsigned Opcode, Type *Val,
400 unsigned Index) const {
401 return 1;
402}
403
404unsigned BasicTTI::getMemoryOpCost(unsigned Opcode, Type *Src,
405 unsigned Alignment,
406 unsigned AddressSpace) const {
407 assert(!Src->isVoidTy() && "Invalid type");
Bill Wendlingea442812013-06-19 20:51:24 +0000408 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Src);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000409
410 // Assume that all loads of legal types cost 1.
411 return LT.first;
412}
413
Benjamin Kramer8611d442013-02-28 19:09:33 +0000414unsigned BasicTTI::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000415 ArrayRef<Type *> Tys) const {
Benjamin Kramer8611d442013-02-28 19:09:33 +0000416 unsigned ISD = 0;
417 switch (IID) {
418 default: {
419 // Assume that we need to scalarize this intrinsic.
420 unsigned ScalarizationCost = 0;
421 unsigned ScalarCalls = 1;
422 if (RetTy->isVectorTy()) {
423 ScalarizationCost = getScalarizationOverhead(RetTy, true, false);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000424 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
425 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000426 for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
427 if (Tys[i]->isVectorTy()) {
428 ScalarizationCost += getScalarizationOverhead(Tys[i], false, true);
429 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
430 }
431 }
432
433 return ScalarCalls + ScalarizationCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000434 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000435 // Look for intrinsics that can be lowered directly or turned into a scalar
436 // intrinsic call.
437 case Intrinsic::sqrt: ISD = ISD::FSQRT; break;
438 case Intrinsic::sin: ISD = ISD::FSIN; break;
439 case Intrinsic::cos: ISD = ISD::FCOS; break;
440 case Intrinsic::exp: ISD = ISD::FEXP; break;
441 case Intrinsic::exp2: ISD = ISD::FEXP2; break;
442 case Intrinsic::log: ISD = ISD::FLOG; break;
443 case Intrinsic::log10: ISD = ISD::FLOG10; break;
444 case Intrinsic::log2: ISD = ISD::FLOG2; break;
445 case Intrinsic::fabs: ISD = ISD::FABS; break;
Hal Finkel66d1fa62013-08-19 23:35:46 +0000446 case Intrinsic::copysign: ISD = ISD::FCOPYSIGN; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000447 case Intrinsic::floor: ISD = ISD::FFLOOR; break;
448 case Intrinsic::ceil: ISD = ISD::FCEIL; break;
449 case Intrinsic::trunc: ISD = ISD::FTRUNC; break;
Hal Finkel04b84c22013-07-08 03:24:07 +0000450 case Intrinsic::nearbyint:
451 ISD = ISD::FNEARBYINT; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000452 case Intrinsic::rint: ISD = ISD::FRINT; break;
Hal Finkel41418d12013-08-07 22:49:12 +0000453 case Intrinsic::round: ISD = ISD::FROUND; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000454 case Intrinsic::pow: ISD = ISD::FPOW; break;
455 case Intrinsic::fma: ISD = ISD::FMA; break;
456 case Intrinsic::fmuladd: ISD = ISD::FMA; break; // FIXME: mul + add?
Arnold Schwaighofer2d66d4c2013-08-06 22:37:52 +0000457 case Intrinsic::lifetime_start:
458 case Intrinsic::lifetime_end:
459 return 0;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000460 }
461
Bill Wendlingea442812013-06-19 20:51:24 +0000462 const TargetLoweringBase *TLI = getTLI();
Benjamin Kramer8611d442013-02-28 19:09:33 +0000463 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy);
464
465 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
466 // The operation is legal. Assume it costs 1.
467 // If the type is split to multiple registers, assume that thre is some
468 // overhead to this.
469 // TODO: Once we have extract/insert subvector cost we need to use them.
470 if (LT.first > 1)
471 return LT.first * 2;
472 return LT.first * 1;
473 }
474
475 if (!TLI->isOperationExpand(ISD, LT.second)) {
476 // If the operation is custom lowered then assume
477 // thare the code is twice as expensive.
478 return LT.first * 2;
479 }
480
481 // Else, assume that we need to scalarize this intrinsic. For math builtins
482 // this will emit a costly libcall, adding call overhead and spills. Make it
483 // very expensive.
484 if (RetTy->isVectorTy()) {
485 unsigned Num = RetTy->getVectorNumElements();
486 unsigned Cost = TopTTI->getIntrinsicInstrCost(IID, RetTy->getScalarType(),
487 Tys);
488 return 10 * Cost * Num;
489 }
490
491 // This is going to be turned into a library call, make it expensive.
492 return 10;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000493}
494
495unsigned BasicTTI::getNumberOfParts(Type *Tp) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000496 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Tp);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000497 return LT.first;
498}
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000499
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000500unsigned BasicTTI::getAddressComputationCost(Type *Ty, bool IsComplex) const {
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000501 return 0;
502}