blob: d5340e60231eae4870f8fbab1a518c93e586c026 [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;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000087
88 /// @}
89
90 /// \name Vector TTI Implementations
91 /// @{
92
93 virtual unsigned getNumberOfRegisters(bool Vector) const;
Nadav Rotem83be7b02013-01-09 01:15:42 +000094 virtual unsigned getMaximumUnrollFactor() const;
Nadav Rotem14925e62013-01-09 22:29:00 +000095 virtual unsigned getRegisterBitWidth(bool Vector) const;
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +000096 virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
97 OperandValueKind,
98 OperandValueKind) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +000099 virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
100 int Index, Type *SubTp) const;
101 virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
102 Type *Src) const;
103 virtual unsigned getCFInstrCost(unsigned Opcode) const;
104 virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
105 Type *CondTy) const;
106 virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
107 unsigned Index) const;
108 virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
109 unsigned Alignment,
110 unsigned AddressSpace) const;
111 virtual unsigned getIntrinsicInstrCost(Intrinsic::ID, Type *RetTy,
112 ArrayRef<Type*> Tys) const;
113 virtual unsigned getNumberOfParts(Type *Tp) const;
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000114 virtual unsigned getAddressComputationCost(Type *Ty, bool IsComplex) const;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000115
116 /// @}
117};
118
119}
120
121INITIALIZE_AG_PASS(BasicTTI, TargetTransformInfo, "basictti",
122 "Target independent code generator's TTI", true, true, false)
123char BasicTTI::ID = 0;
124
125ImmutablePass *
Bill Wendlingea442812013-06-19 20:51:24 +0000126llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
127 return new BasicTTI(TM);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000128}
129
Tom Stellard57e6b2d2013-07-27 00:01:07 +0000130bool BasicTTI::hasBranchDivergence() const { return false; }
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000131
132bool BasicTTI::isLegalAddImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000133 return getTLI()->isLegalAddImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000134}
135
136bool BasicTTI::isLegalICmpImmediate(int64_t imm) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000137 return getTLI()->isLegalICmpImmediate(imm);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000138}
139
140bool BasicTTI::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
141 int64_t BaseOffset, bool HasBaseReg,
142 int64_t Scale) const {
Benjamin Kramer69e42db2013-01-11 20:05:37 +0000143 TargetLoweringBase::AddrMode AM;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000144 AM.BaseGV = BaseGV;
145 AM.BaseOffs = BaseOffset;
146 AM.HasBaseReg = HasBaseReg;
147 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000148 return getTLI()->isLegalAddressingMode(AM, Ty);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000149}
150
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000151int BasicTTI::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
152 int64_t BaseOffset, bool HasBaseReg,
153 int64_t Scale) const {
154 TargetLoweringBase::AddrMode AM;
155 AM.BaseGV = BaseGV;
156 AM.BaseOffs = BaseOffset;
157 AM.HasBaseReg = HasBaseReg;
158 AM.Scale = Scale;
Bill Wendlingea442812013-06-19 20:51:24 +0000159 return getTLI()->getScalingFactorCost(AM, Ty);
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000160}
161
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000162bool BasicTTI::isTruncateFree(Type *Ty1, Type *Ty2) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000163 return getTLI()->isTruncateFree(Ty1, Ty2);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000164}
165
166bool BasicTTI::isTypeLegal(Type *Ty) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000167 EVT T = getTLI()->getValueType(Ty);
168 return getTLI()->isTypeLegal(T);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000169}
170
171unsigned BasicTTI::getJumpBufAlignment() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000172 return getTLI()->getJumpBufAlignment();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000173}
174
175unsigned BasicTTI::getJumpBufSize() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000176 return getTLI()->getJumpBufSize();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000177}
178
179bool BasicTTI::shouldBuildLookupTables() const {
Bill Wendlingea442812013-06-19 20:51:24 +0000180 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000181 return TLI->supportJumpTables() &&
182 (TLI->isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
183 TLI->isOperationLegalOrCustom(ISD::BRIND, MVT::Other));
184}
185
Richard Sandiforda8a70992013-08-23 10:27:02 +0000186bool BasicTTI::haveFastSqrt(Type *Ty) const {
187 const TargetLoweringBase *TLI = getTLI();
188 EVT VT = TLI->getValueType(Ty);
189 return TLI->isTypeLegal(VT) && TLI->isOperationLegalOrCustom(ISD::FSQRT, VT);
190}
191
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000192//===----------------------------------------------------------------------===//
193//
194// Calls used by the vectorizers.
195//
196//===----------------------------------------------------------------------===//
197
198unsigned BasicTTI::getScalarizationOverhead(Type *Ty, bool Insert,
199 bool Extract) const {
200 assert (Ty->isVectorTy() && "Can only scalarize vectors");
201 unsigned Cost = 0;
202
203 for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) {
204 if (Insert)
205 Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
206 if (Extract)
207 Cost += TopTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, i);
208 }
209
210 return Cost;
211}
212
213unsigned BasicTTI::getNumberOfRegisters(bool Vector) const {
214 return 1;
215}
216
Nadav Rotem14925e62013-01-09 22:29:00 +0000217unsigned BasicTTI::getRegisterBitWidth(bool Vector) const {
218 return 32;
219}
220
Nadav Rotem83be7b02013-01-09 01:15:42 +0000221unsigned BasicTTI::getMaximumUnrollFactor() const {
222 return 1;
223}
224
Arnold Schwaighofer6bf4f672013-04-04 23:26:21 +0000225unsigned BasicTTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
226 OperandValueKind,
227 OperandValueKind) const {
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000228 // Check if any of the operands are vector operands.
Bill Wendlingea442812013-06-19 20:51:24 +0000229 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000230 int ISD = TLI->InstructionOpcodeToISD(Opcode);
231 assert(ISD && "Invalid opcode");
232
233 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty);
234
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000235 bool IsFloat = Ty->getScalarType()->isFloatingPointTy();
Nadav Rotem42082002013-04-14 05:55:18 +0000236 // Assume that floating point arithmetic operations cost twice as much as
237 // integer operations.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000238 unsigned OpCost = (IsFloat ? 2 : 1);
239
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000240 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
241 // The operation is legal. Assume it costs 1.
Nadav Rotem42082002013-04-14 05:55:18 +0000242 // If the type is split to multiple registers, assume that there is some
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000243 // overhead to this.
244 // TODO: Once we have extract/insert subvector cost we need to use them.
245 if (LT.first > 1)
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000246 return LT.first * 2 * OpCost;
247 return LT.first * 1 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000248 }
249
250 if (!TLI->isOperationExpand(ISD, LT.second)) {
251 // If the operation is custom lowered then assume
252 // thare the code is twice as expensive.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000253 return LT.first * 2 * OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000254 }
255
256 // Else, assume that we need to scalarize this op.
257 if (Ty->isVectorTy()) {
258 unsigned Num = Ty->getVectorNumElements();
259 unsigned Cost = TopTTI->getArithmeticInstrCost(Opcode, Ty->getScalarType());
260 // return the cost of multiple scalar invocation plus the cost of inserting
261 // and extracting the values.
262 return getScalarizationOverhead(Ty, true, true) + Num * Cost;
263 }
264
265 // We don't know anything about this scalar instruction.
Nadav Rotem9eb366a2013-04-12 21:15:03 +0000266 return OpCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000267}
268
269unsigned BasicTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
270 Type *SubTp) const {
271 return 1;
272}
273
274unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
275 Type *Src) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000276 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000277 int ISD = TLI->InstructionOpcodeToISD(Opcode);
278 assert(ISD && "Invalid opcode");
279
280 std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(Src);
281 std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(Dst);
282
Nadav Rotem3e40d922013-01-11 19:54:13 +0000283 // Check for NOOP conversions.
284 if (SrcLT.first == DstLT.first &&
285 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
286
287 // Bitcast between types that are legalized to the same type are free.
288 if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
289 return 0;
290 }
291
292 if (Opcode == Instruction::Trunc &&
293 TLI->isTruncateFree(SrcLT.second, DstLT.second))
294 return 0;
295
296 if (Opcode == Instruction::ZExt &&
297 TLI->isZExtFree(SrcLT.second, DstLT.second))
298 return 0;
299
300 // If the cast is marked as legal (or promote) then assume low cost.
301 if (TLI->isOperationLegalOrPromote(ISD, DstLT.second))
302 return 1;
303
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000304 // Handle scalar conversions.
305 if (!Src->isVectorTy() && !Dst->isVectorTy()) {
306
307 // Scalar bitcasts are usually free.
308 if (Opcode == Instruction::BitCast)
309 return 0;
310
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000311 // Just check the op cost. If the operation is legal then assume it costs 1.
312 if (!TLI->isOperationExpand(ISD, DstLT.second))
313 return 1;
314
315 // Assume that illegal scalar instruction are expensive.
316 return 4;
317 }
318
319 // Check vector-to-vector casts.
320 if (Dst->isVectorTy() && Src->isVectorTy()) {
321
322 // If the cast is between same-sized registers, then the check is simple.
323 if (SrcLT.first == DstLT.first &&
324 SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
325
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000326 // Assume that Zext is done using AND.
327 if (Opcode == Instruction::ZExt)
328 return 1;
329
330 // Assume that sext is done using SHL and SRA.
331 if (Opcode == Instruction::SExt)
332 return 2;
333
334 // Just check the op cost. If the operation is legal then assume it costs
335 // 1 and multiply by the type-legalization overhead.
336 if (!TLI->isOperationExpand(ISD, DstLT.second))
337 return SrcLT.first * 1;
338 }
339
340 // If we are converting vectors and the operation is illegal, or
341 // if the vectors are legalized to different types, estimate the
342 // scalarization costs.
343 unsigned Num = Dst->getVectorNumElements();
344 unsigned Cost = TopTTI->getCastInstrCost(Opcode, Dst->getScalarType(),
345 Src->getScalarType());
346
347 // Return the cost of multiple scalar invocation plus the cost of
348 // inserting and extracting the values.
349 return getScalarizationOverhead(Dst, true, true) + Num * Cost;
350 }
351
352 // We already handled vector-to-vector and scalar-to-scalar conversions. This
353 // is where we handle bitcast between vectors and scalars. We need to assume
354 // that the conversion is scalarized in one way or another.
355 if (Opcode == Instruction::BitCast)
356 // Illegal bitcasts are done by storing and loading from a stack slot.
357 return (Src->isVectorTy()? getScalarizationOverhead(Src, false, true):0) +
358 (Dst->isVectorTy()? getScalarizationOverhead(Dst, true, false):0);
359
360 llvm_unreachable("Unhandled cast");
361 }
362
363unsigned BasicTTI::getCFInstrCost(unsigned Opcode) const {
364 // Branches are assumed to be predicted.
365 return 0;
366}
367
368unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
369 Type *CondTy) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000370 const TargetLoweringBase *TLI = getTLI();
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000371 int ISD = TLI->InstructionOpcodeToISD(Opcode);
372 assert(ISD && "Invalid opcode");
373
374 // Selects on vectors are actually vector selects.
375 if (ISD == ISD::SELECT) {
376 assert(CondTy && "CondTy must exist");
377 if (CondTy->isVectorTy())
378 ISD = ISD::VSELECT;
379 }
380
381 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
382
383 if (!TLI->isOperationExpand(ISD, LT.second)) {
384 // The operation is legal. Assume it costs 1. Multiply
385 // by the type-legalization overhead.
386 return LT.first * 1;
387 }
388
389 // Otherwise, assume that the cast is scalarized.
390 if (ValTy->isVectorTy()) {
391 unsigned Num = ValTy->getVectorNumElements();
392 if (CondTy)
393 CondTy = CondTy->getScalarType();
394 unsigned Cost = TopTTI->getCmpSelInstrCost(Opcode, ValTy->getScalarType(),
395 CondTy);
396
397 // Return the cost of multiple scalar invocation plus the cost of inserting
398 // and extracting the values.
399 return getScalarizationOverhead(ValTy, true, false) + Num * Cost;
400 }
401
402 // Unknown scalar opcode.
403 return 1;
404}
405
406unsigned BasicTTI::getVectorInstrCost(unsigned Opcode, Type *Val,
407 unsigned Index) const {
408 return 1;
409}
410
411unsigned BasicTTI::getMemoryOpCost(unsigned Opcode, Type *Src,
412 unsigned Alignment,
413 unsigned AddressSpace) const {
414 assert(!Src->isVoidTy() && "Invalid type");
Bill Wendlingea442812013-06-19 20:51:24 +0000415 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Src);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000416
417 // Assume that all loads of legal types cost 1.
418 return LT.first;
419}
420
Benjamin Kramer8611d442013-02-28 19:09:33 +0000421unsigned BasicTTI::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000422 ArrayRef<Type *> Tys) const {
Benjamin Kramer8611d442013-02-28 19:09:33 +0000423 unsigned ISD = 0;
424 switch (IID) {
425 default: {
426 // Assume that we need to scalarize this intrinsic.
427 unsigned ScalarizationCost = 0;
428 unsigned ScalarCalls = 1;
429 if (RetTy->isVectorTy()) {
430 ScalarizationCost = getScalarizationOverhead(RetTy, true, false);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000431 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
432 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000433 for (unsigned i = 0, ie = Tys.size(); i != ie; ++i) {
434 if (Tys[i]->isVectorTy()) {
435 ScalarizationCost += getScalarizationOverhead(Tys[i], false, true);
436 ScalarCalls = std::max(ScalarCalls, RetTy->getVectorNumElements());
437 }
438 }
439
440 return ScalarCalls + ScalarizationCost;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000441 }
Benjamin Kramer8611d442013-02-28 19:09:33 +0000442 // Look for intrinsics that can be lowered directly or turned into a scalar
443 // intrinsic call.
444 case Intrinsic::sqrt: ISD = ISD::FSQRT; break;
445 case Intrinsic::sin: ISD = ISD::FSIN; break;
446 case Intrinsic::cos: ISD = ISD::FCOS; break;
447 case Intrinsic::exp: ISD = ISD::FEXP; break;
448 case Intrinsic::exp2: ISD = ISD::FEXP2; break;
449 case Intrinsic::log: ISD = ISD::FLOG; break;
450 case Intrinsic::log10: ISD = ISD::FLOG10; break;
451 case Intrinsic::log2: ISD = ISD::FLOG2; break;
452 case Intrinsic::fabs: ISD = ISD::FABS; break;
Hal Finkel66d1fa62013-08-19 23:35:46 +0000453 case Intrinsic::copysign: ISD = ISD::FCOPYSIGN; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000454 case Intrinsic::floor: ISD = ISD::FFLOOR; break;
455 case Intrinsic::ceil: ISD = ISD::FCEIL; break;
456 case Intrinsic::trunc: ISD = ISD::FTRUNC; break;
Hal Finkel04b84c22013-07-08 03:24:07 +0000457 case Intrinsic::nearbyint:
458 ISD = ISD::FNEARBYINT; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000459 case Intrinsic::rint: ISD = ISD::FRINT; break;
Hal Finkel41418d12013-08-07 22:49:12 +0000460 case Intrinsic::round: ISD = ISD::FROUND; break;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000461 case Intrinsic::pow: ISD = ISD::FPOW; break;
462 case Intrinsic::fma: ISD = ISD::FMA; break;
463 case Intrinsic::fmuladd: ISD = ISD::FMA; break; // FIXME: mul + add?
Arnold Schwaighofer2d66d4c2013-08-06 22:37:52 +0000464 case Intrinsic::lifetime_start:
465 case Intrinsic::lifetime_end:
466 return 0;
Benjamin Kramer8611d442013-02-28 19:09:33 +0000467 }
468
Bill Wendlingea442812013-06-19 20:51:24 +0000469 const TargetLoweringBase *TLI = getTLI();
Benjamin Kramer8611d442013-02-28 19:09:33 +0000470 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(RetTy);
471
472 if (TLI->isOperationLegalOrPromote(ISD, LT.second)) {
473 // The operation is legal. Assume it costs 1.
474 // If the type is split to multiple registers, assume that thre is some
475 // overhead to this.
476 // TODO: Once we have extract/insert subvector cost we need to use them.
477 if (LT.first > 1)
478 return LT.first * 2;
479 return LT.first * 1;
480 }
481
482 if (!TLI->isOperationExpand(ISD, LT.second)) {
483 // If the operation is custom lowered then assume
484 // thare the code is twice as expensive.
485 return LT.first * 2;
486 }
487
488 // Else, assume that we need to scalarize this intrinsic. For math builtins
489 // this will emit a costly libcall, adding call overhead and spills. Make it
490 // very expensive.
491 if (RetTy->isVectorTy()) {
492 unsigned Num = RetTy->getVectorNumElements();
493 unsigned Cost = TopTTI->getIntrinsicInstrCost(IID, RetTy->getScalarType(),
494 Tys);
495 return 10 * Cost * Num;
496 }
497
498 // This is going to be turned into a library call, make it expensive.
499 return 10;
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000500}
501
502unsigned BasicTTI::getNumberOfParts(Type *Tp) const {
Bill Wendlingea442812013-06-19 20:51:24 +0000503 std::pair<unsigned, MVT> LT = getTLI()->getTypeLegalizationCost(Tp);
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000504 return LT.first;
505}
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000506
Arnold Schwaighoferc0a11ed2013-07-12 19:16:02 +0000507unsigned BasicTTI::getAddressComputationCost(Type *Ty, bool IsComplex) const {
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000508 return 0;
509}