blob: e1380b73e9ed66d2f78add13cd05aabeb7042641 [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;
Richard Sandiforda8a70992013-08-23 10:27:02 +000086 virtual bool haveFastSqrt(Type *Ty) const;
Hal Finkel32f258b2013-08-29 03:29:57 +000087 virtual bool getUnrollingPreferences(UnrollingPreferences &UP) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000088
89 /// @}
90
91 /// \name Vector TTI Implementations
92 /// @{
93
94 virtual unsigned getNumberOfRegisters(bool Vector) const;
Nadav Rotem83be7b02013-01-09 01:15:42 +000095 virtual unsigned getMaximumUnrollFactor() const;
Nadav Rotem14925e62013-01-09 22:29:00 +000096 virtual unsigned getRegisterBitWidth(bool Vector) const;
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +000097 virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
98 OperandValueKind,
99 OperandValueKind) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000100 virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
101 int Index, Type *SubTp) const;
102 virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
103 Type *Src) const;
104 virtual unsigned getCFInstrCost(unsigned Opcode) const;
105 virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
106 Type *CondTy) const;
107 virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
108 unsigned Index) const;
109 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
110 unsigned Alignment,
111 unsigned AddressSpace) const;
112 virtual unsigned getIntrinsicInstrCost(Intrinsic::ID, Type *RetTy,
113 ArrayRef<Type*> Tys) const;
114 virtual unsigned getNumberOfParts(Type *Tp) const;
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000115 virtual unsigned getAddressComputationCost(Type *Ty, bool IsComplex) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000116
117 /// @}
118};
119
120}
121
122INITIALIZE_AG_PASS(BasicTTI, TargetTransformInfo, "basictti",
123 "Target independent code generator's TTI", true, true, false)
124char BasicTTI::ID = 0;
125
126ImmutablePass *
Bill Wendlingea442812013-06-19 20:51:24 +0000127llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
128 return new BasicTTI(TM);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000129}
130
Tom Stellard57e6b2d2013-07-27 00:01:07 +0000131bool BasicTTI::hasBranchDivergence() const { return false; }
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000132
133bool BasicTTI::isLegalAddImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000134 return getTLI()->isLegalAddImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000135}
136
137bool BasicTTI::isLegalICmpImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000138 return getTLI()->isLegalICmpImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000139}
140
141bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
142 int64_t BaseOffset, bool HasBaseReg,
143 int64_t Scale) const {
Benjamin Kramer69e42db2013-01-11 20:05:37 +0000144 TargetLoweringBase::AddrMode AM;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000145 AM.BaseGV = BaseGV;
146 AM.BaseOffs = BaseOffset;
147 AM.HasBaseReg = HasBaseReg;
148 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000149 return getTLI()->isLegalAddressingMode(AM, Ty);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000150}
151
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000152int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
153 int64_t BaseOffset, bool HasBaseReg,
154 int64_t Scale) const {
155 TargetLoweringBase::AddrMode AM;
156 AM.BaseGV = BaseGV;
157 AM.BaseOffs = BaseOffset;
158 AM.HasBaseReg = HasBaseReg;
159 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000160 return getTLI()->getScalingFactorCost(AM, Ty);
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000161}
162
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000163bool BasicTTI::isTruncateFree(Type *Ty1, Type *Ty2) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000164 return getTLI()->isTruncateFree(Ty1, Ty2);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000165}
166
167bool BasicTTI::isTypeLegal(Type *Ty) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000168 EVT T = getTLI()->getValueType(Ty);
169 return getTLI()->isTypeLegal(T);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000170}
171
172unsigned BasicTTI::getJumpBufAlignment() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000173 return getTLI()->getJumpBufAlignment();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000174}
175
176unsigned BasicTTI::getJumpBufSize() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000177 return getTLI()->getJumpBufSize();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000178}
179
180bool BasicTTI::shouldBuildLookupTables() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000181 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000182 return TLI->supportJumpTables() &&
183 (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
184 TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
185}
186
Richard Sandiforda8a70992013-08-23 10:27:02 +0000187bool BasicTTI::haveFastSqrt(Type *Ty) const {
188 const TargetLoweringBase *TLI = getTLI();
189 EVT VT = TLI->getValueType(Ty);
190 return TLI->isTypeLegal(VT) && TLI->isOperationLegalOrCustom(ISD::FSQRT, VT);
191}
192
Hal Finkel32f258b2013-08-29 03:29:57 +0000193bool BasicTTI::getUnrollingPreferences(UnrollingPreferences &) const {
194 return false;
195}
196
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000197//===----------------------------------------------------------------------===//
198//
199// Calls used by the vectorizers.
200//
201//===----------------------------------------------------------------------===//
202
203unsigned BasicTTI::getScalarizationOverhead(Type *Ty, bool Insert,
204 bool Extract) const {
205 assert (Ty->isVectorTy() && "Can only scalarize vectors");
206 unsigned Cost = 0;
207
208 for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) {
209 if (Insert)
210 Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
211 if (Extract)
212 Cost += TopTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, i);
213 }
214
215 return Cost;
216}
217
218unsigned BasicTTI::getNumberOfRegisters(bool Vector) const {
219 return 1;
220}
221
Nadav Rotem14925e62013-01-09 22:29:00 +0000222unsigned BasicTTI::getRegisterBitWidth(bool Vector) const {
223 return 32;
224}
225
Nadav Rotem83be7b02013-01-09 01:15:42 +0000226unsigned BasicTTI::getMaximumUnrollFactor() const {
227 return 1;
228}
229
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +0000230unsigned BasicTTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
231 OperandValueKind,
232 OperandValueKind) const {
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000233 // Check if any of the operands are vector operands.
Bill Wendlingea442812013-06-19 20:51:24 +0000234 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000235 int ISD = TLI->InstructionOpcodeToISD(Opcode);
236 assert(ISD && "Invalid opcode");
237
238 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty);
239
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000240 bool IsFloat = Ty->getScalarType()->isFloatingPointTy();
Nadav Rotem42082002013-04-14 05:55:18 +0000241 // Assume that floating point arithmetic operations cost twice as much as
242 // integer operations.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000243 unsigned OpCost = (IsFloat ? 2 : 1);
244
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000245 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
246 // The operation is legal. Assume it costs 1.
Nadav Rotem42082002013-04-14 05:55:18 +0000247 // If the type is split to multiple registers, assume that there is some
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000248 // overhead to this.
249 // TODO: Once we have extract/insert subvector cost we need to use them.
250 if (LT.first > 1)
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000251 return LT.first * 2 * OpCost;
252 return LT.first * 1 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000253 }
254
255 if (!TLI->isOperationExpand(ISD, LT.second)) {
256 // If the operation is custom lowered then assume
257 // thare the code is twice as expensive.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000258 return LT.first * 2 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000259 }
260
261 // Else, assume that we need to scalarize this op.
262 if (Ty->isVectorTy()) {
263 unsigned Num = Ty->getVectorNumElements();
264 unsigned Cost = TopTTI->getArithmeticInstrCost(Opcode, Ty->getScalarType());
265 // return the cost of multiple scalar invocation plus the cost of inserting
266 // and extracting the values.
267 return getScalarizationOverhead(Ty, true, true) + Num * Cost;
268 }
269
270 // We don't know anything about this scalar instruction.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000271 return OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000272}
273
274unsigned BasicTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
275 Type *SubTp) const {
276 return 1;
277}
278
279unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
280 Type *Src) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000281 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000282 int ISD = TLI->InstructionOpcodeToISD(Opcode);
283 assert(ISD && "Invalid opcode");
284
285 std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(Src);
286 std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(Dst);
287
Nadav Rotem3e40d922013-01-11 19:54:13 +0000288 // Check for NOOP conversions.
289 if (SrcLT.first == DstLT.first &&
290 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
291
292 // Bitcast between types that are legalized to the same type are free.
293 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
294 return 0;
295 }
296
297 if (Opcode == Instruction::Trunc &&
298 TLI->isTruncateFree(SrcLT.second, DstLT.second))
299 return 0;
300
301 if (Opcode == Instruction::ZExt &&
302 TLI->isZExtFree(SrcLT.second, DstLT.second))
303 return 0;
304
305 // If the cast is marked as legal (or promote) then assume low cost.
306 if (TLI->isOperationLegalOrPromote(ISD, DstLT.second))
307 return 1;
308
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000309 // Handle scalar conversions.
310 if (!Src->isVectorTy() && !Dst->isVectorTy()) {
311
312 // Scalar bitcasts are usually free.
313 if (Opcode == Instruction::BitCast)
314 return 0;
315
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000316 // Just check the op cost. If the operation is legal then assume it costs 1.
317 if (!TLI->isOperationExpand(ISD, DstLT.second))
318 return 1;
319
320 // Assume that illegal scalar instruction are expensive.
321 return 4;
322 }
323
324 // Check vector-to-vector casts.
325 if (Dst->isVectorTy() && Src->isVectorTy()) {
326
327 // If the cast is between same-sized registers, then the check is simple.
328 if (SrcLT.first == DstLT.first &&
329 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
330
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000331 // Assume that Zext is done using AND.
332 if (Opcode == Instruction::ZExt)
333 return 1;
334
335 // Assume that sext is done using SHL and SRA.
336 if (Opcode == Instruction::SExt)
337 return 2;
338
339 // Just check the op cost. If the operation is legal then assume it costs
340 // 1 and multiply by the type-legalization overhead.
341 if (!TLI->isOperationExpand(ISD, DstLT.second))
342 return SrcLT.first * 1;
343 }
344
345 // If we are converting vectors and the operation is illegal, or
346 // if the vectors are legalized to different types, estimate the
347 // scalarization costs.
348 unsigned Num = Dst->getVectorNumElements();
349 unsigned Cost = TopTTI->getCastInstrCost(Opcode, Dst->getScalarType(),
350 Src->getScalarType());
351
352 // Return the cost of multiple scalar invocation plus the cost of
353 // inserting and extracting the values.
354 return getScalarizationOverhead(Dst, true, true) + Num * Cost;
355 }
356
357 // We already handled vector-to-vector and scalar-to-scalar conversions. This
358 // is where we handle bitcast between vectors and scalars. We need to assume
359 // that the conversion is scalarized in one way or another.
360 if (Opcode == Instruction::BitCast)
361 // Illegal bitcasts are done by storing and loading from a stack slot.
362 return (Src->isVectorTy()? getScalarizationOverhead(Src, false, true):0) +
363 (Dst->isVectorTy()? getScalarizationOverhead(Dst, true, false):0);
364
365 llvm_unreachable("Unhandled cast");
366 }
367
368unsigned BasicTTI::getCFInstrCost(unsigned Opcode) const {
369 // Branches are assumed to be predicted.
370 return 0;
371}
372
373unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
374 Type *CondTy) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000375 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000376 int ISD = TLI->InstructionOpcodeToISD(Opcode);
377 assert(ISD && "Invalid opcode");
378
379 // Selects on vectors are actually vector selects.
380 if (ISD == ISD::SELECT) {
381 assert(CondTy && "CondTy must exist");
382 if (CondTy->isVectorTy())
383 ISD = ISD::VSELECT;
384 }
385
386 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
387
388 if (!TLI->isOperationExpand(ISD, LT.second)) {
389 // The operation is legal. Assume it costs 1. Multiply
390 // by the type-legalization overhead.
391 return LT.first * 1;
392 }
393
394 // Otherwise, assume that the cast is scalarized.
395 if (ValTy->isVectorTy()) {
396 unsigned Num = ValTy->getVectorNumElements();
397 if (CondTy)
398 CondTy = CondTy->getScalarType();
399 unsigned Cost = TopTTI->getCmpSelInstrCost(Opcode, ValTy->getScalarType(),
400 CondTy);
401
402 // Return the cost of multiple scalar invocation plus the cost of inserting
403 // and extracting the values.
404 return getScalarizationOverhead(ValTy, true, false) + Num * Cost;
405 }
406
407 // Unknown scalar opcode.
408 return 1;
409}
410
411unsigned BasicTTI::getVectorInstrCost(unsigned Opcode, Type *Val,
412 unsigned Index) const {
413 return 1;
414}
415
416unsigned BasicTTI::getMemoryOpCost(unsigned Opcode, Type *Src,
417 unsigned Alignment,
418 unsigned AddressSpace) const {
419 assert(!Src->isVoidTy() && "Invalid type");
Bill Wendlingea442812013-06-19 20:51:24 +0000420 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Src);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000421
422 // Assume that all loads of legal types cost 1.
423 return LT.first;
424}
425
Benjamin Kramer8611d442013-02-28 19:09:33 +0000426unsigned BasicTTI::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000427 ArrayRef<Type *> Tys) const {
Benjamin Kramer8611d442013-02-28 19:09:33 +0000428 unsigned ISD = 0;
429 switch (IID) {
430 default: {
431 // Assume that we need to scalarize this intrinsic.
432 unsigned ScalarizationCost = 0;
433 unsigned ScalarCalls = 1;
434 if (RetTy->isVectorTy()) {
435 ScalarizationCost = getScalarizationOverhead(RetTy, true, false);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000436 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
437 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000438 for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
439 if (Tys[i]->isVectorTy()) {
440 ScalarizationCost += getScalarizationOverhead(Tys[i], false, true);
441 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
442 }
443 }
444
445 return ScalarCalls + ScalarizationCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000446 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000447 // Look for intrinsics that can be lowered directly or turned into a scalar
448 // intrinsic call.
449 case Intrinsic::sqrt: ISD = ISD::FSQRT; break;
450 case Intrinsic::sin: ISD = ISD::FSIN; break;
451 case Intrinsic::cos: ISD = ISD::FCOS; break;
452 case Intrinsic::exp: ISD = ISD::FEXP; break;
453 case Intrinsic::exp2: ISD = ISD::FEXP2; break;
454 case Intrinsic::log: ISD = ISD::FLOG; break;
455 case Intrinsic::log10: ISD = ISD::FLOG10; break;
456 case Intrinsic::log2: ISD = ISD::FLOG2; break;
457 case Intrinsic::fabs: ISD = ISD::FABS; break;
Hal Finkel66d1fa62013-08-19 23:35:46 +0000458 case Intrinsic::copysign: ISD = ISD::FCOPYSIGN; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000459 case Intrinsic::floor: ISD = ISD::FFLOOR; break;
460 case Intrinsic::ceil: ISD = ISD::FCEIL; break;
461 case Intrinsic::trunc: ISD = ISD::FTRUNC; break;
Hal Finkel04b84c22013-07-08 03:24:07 +0000462 case Intrinsic::nearbyint:
463 ISD = ISD::FNEARBYINT; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000464 case Intrinsic::rint: ISD = ISD::FRINT; break;
Hal Finkel41418d12013-08-07 22:49:12 +0000465 case Intrinsic::round: ISD = ISD::FROUND; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000466 case Intrinsic::pow: ISD = ISD::FPOW; break;
467 case Intrinsic::fma: ISD = ISD::FMA; break;
468 case Intrinsic::fmuladd: ISD = ISD::FMA; break; // FIXME: mul + add?
Arnold Schwaighofer2d66d4c2013-08-06 22:37:52 +0000469 case Intrinsic::lifetime_start:
470 case Intrinsic::lifetime_end:
471 return 0;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000472 }
473
Bill Wendlingea442812013-06-19 20:51:24 +0000474 const TargetLoweringBase *TLI = getTLI();
Benjamin Kramer8611d442013-02-28 19:09:33 +0000475 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy);
476
477 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
478 // The operation is legal. Assume it costs 1.
479 // If the type is split to multiple registers, assume that thre is some
480 // overhead to this.
481 // TODO: Once we have extract/insert subvector cost we need to use them.
482 if (LT.first > 1)
483 return LT.first * 2;
484 return LT.first * 1;
485 }
486
487 if (!TLI->isOperationExpand(ISD, LT.second)) {
488 // If the operation is custom lowered then assume
489 // thare the code is twice as expensive.
490 return LT.first * 2;
491 }
492
493 // Else, assume that we need to scalarize this intrinsic. For math builtins
494 // this will emit a costly libcall, adding call overhead and spills. Make it
495 // very expensive.
496 if (RetTy->isVectorTy()) {
497 unsigned Num = RetTy->getVectorNumElements();
498 unsigned Cost = TopTTI->getIntrinsicInstrCost(IID, RetTy->getScalarType(),
499 Tys);
500 return 10 * Cost * Num;
501 }
502
503 // This is going to be turned into a library call, make it expensive.
504 return 10;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000505}
506
507unsigned BasicTTI::getNumberOfParts(Type *Tp) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000508 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Tp);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000509 return LT.first;
510}
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000511
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000512unsigned BasicTTI::getAddressComputationCost(Type *Ty, bool IsComplex) const {
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000513 return 0;
514}