blob: 7ac22303deb754d6af371392d58f4f4f574d5fae [file] [log] [blame]
Chandler Carruthd3e73552013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotem5dc203e2012-10-18 23:22:48 +00002//
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
Chandler Carruthd3e73552013-01-07 03:08:10 +000010#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000011#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000012#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000015#include "llvm/IR/IntrinsicInst.h"
16#include "llvm/IR/Operator.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000017#include "llvm/Support/ErrorHandling.h"
18
19using namespace llvm;
20
Chandler Carruthf1221bd2014-04-22 02:48:03 +000021#define DEBUG_TYPE "tti"
22
Chandler Carruth539edf42013-01-05 11:43:11 +000023// Setup the analysis group to manage the TargetTransformInfo passes.
24INITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI)
Nadav Rotem5dc203e2012-10-18 23:22:48 +000025char TargetTransformInfo::ID = 0;
26
Chandler Carruth539edf42013-01-05 11:43:11 +000027TargetTransformInfo::~TargetTransformInfo() {
28}
29
Chandler Carruth664e3542013-01-07 01:37:14 +000030void TargetTransformInfo::pushTTIStack(Pass *P) {
31 TopTTI = this;
32 PrevTTI = &P->getAnalysis<TargetTransformInfo>();
33
34 // Walk up the chain and update the top TTI pointer.
35 for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
36 PTTI->TopTTI = this;
37}
38
Chandler Carruth539edf42013-01-05 11:43:11 +000039void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const {
40 AU.addRequired<TargetTransformInfo>();
41}
42
Chandler Carruth511aa762013-01-21 01:27:39 +000043unsigned TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
44 Type *OpTy) const {
45 return PrevTTI->getOperationCost(Opcode, Ty, OpTy);
46}
47
48unsigned TargetTransformInfo::getGEPCost(
49 const Value *Ptr, ArrayRef<const Value *> Operands) const {
50 return PrevTTI->getGEPCost(Ptr, Operands);
51}
52
Chandler Carruth0ba8db42013-01-22 11:26:02 +000053unsigned TargetTransformInfo::getCallCost(FunctionType *FTy,
54 int NumArgs) const {
55 return PrevTTI->getCallCost(FTy, NumArgs);
56}
57
58unsigned TargetTransformInfo::getCallCost(const Function *F,
59 int NumArgs) const {
60 return PrevTTI->getCallCost(F, NumArgs);
61}
62
63unsigned TargetTransformInfo::getCallCost(
64 const Function *F, ArrayRef<const Value *> Arguments) const {
65 return PrevTTI->getCallCost(F, Arguments);
66}
67
68unsigned TargetTransformInfo::getIntrinsicCost(
69 Intrinsic::ID IID, Type *RetTy, ArrayRef<Type *> ParamTys) const {
70 return PrevTTI->getIntrinsicCost(IID, RetTy, ParamTys);
71}
72
73unsigned TargetTransformInfo::getIntrinsicCost(
74 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
75 return PrevTTI->getIntrinsicCost(IID, RetTy, Arguments);
76}
77
Chandler Carruth511aa762013-01-21 01:27:39 +000078unsigned TargetTransformInfo::getUserCost(const User *U) const {
79 return PrevTTI->getUserCost(U);
80}
81
Tom Stellard8b1e0212013-07-27 00:01:07 +000082bool TargetTransformInfo::hasBranchDivergence() const {
83 return PrevTTI->hasBranchDivergence();
84}
85
Chandler Carruth0ba8db42013-01-22 11:26:02 +000086bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
87 return PrevTTI->isLoweredToCall(F);
88}
89
Hal Finkel8f2e7002013-09-11 19:25:43 +000090void TargetTransformInfo::getUnrollingPreferences(Loop *L,
91 UnrollingPreferences &UP) const {
92 PrevTTI->getUnrollingPreferences(L, UP);
93}
94
Chandler Carruth539edf42013-01-05 11:43:11 +000095bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
96 return PrevTTI->isLegalAddImmediate(Imm);
97}
98
99bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
100 return PrevTTI->isLegalICmpImmediate(Imm);
101}
102
103bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
104 int64_t BaseOffset,
105 bool HasBaseReg,
106 int64_t Scale) const {
107 return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
108 Scale);
109}
110
Quentin Colombetbf490d42013-05-31 21:29:03 +0000111int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
112 int64_t BaseOffset,
113 bool HasBaseReg,
114 int64_t Scale) const {
115 return PrevTTI->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
116 Scale);
117}
118
Chandler Carruth539edf42013-01-05 11:43:11 +0000119bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
120 return PrevTTI->isTruncateFree(Ty1, Ty2);
121}
122
123bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
124 return PrevTTI->isTypeLegal(Ty);
125}
126
127unsigned TargetTransformInfo::getJumpBufAlignment() const {
128 return PrevTTI->getJumpBufAlignment();
129}
130
131unsigned TargetTransformInfo::getJumpBufSize() const {
132 return PrevTTI->getJumpBufSize();
133}
134
135bool TargetTransformInfo::shouldBuildLookupTables() const {
136 return PrevTTI->shouldBuildLookupTables();
137}
138
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000139TargetTransformInfo::PopcntSupportKind
140TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
141 return PrevTTI->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000142}
143
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000144bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
145 return PrevTTI->haveFastSqrt(Ty);
146}
147
Chandler Carruth539edf42013-01-05 11:43:11 +0000148unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
149 return PrevTTI->getIntImmCost(Imm, Ty);
150}
151
Juergen Ributzkaf0dff492014-03-21 06:04:45 +0000152unsigned TargetTransformInfo::getIntImmCost(unsigned Opc, unsigned Idx,
153 const APInt &Imm, Type *Ty) const {
154 return PrevTTI->getIntImmCost(Opc, Idx, Imm, Ty);
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000155}
156
Juergen Ributzkaf0dff492014-03-21 06:04:45 +0000157unsigned TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
158 const APInt &Imm, Type *Ty) const {
159 return PrevTTI->getIntImmCost(IID, Idx, Imm, Ty);
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000160}
161
Chandler Carruth539edf42013-01-05 11:43:11 +0000162unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
163 return PrevTTI->getNumberOfRegisters(Vector);
164}
165
Nadav Rotemb1791a72013-01-09 22:29:00 +0000166unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
167 return PrevTTI->getRegisterBitWidth(Vector);
168}
169
Nadav Rotemb696c362013-01-09 01:15:42 +0000170unsigned TargetTransformInfo::getMaximumUnrollFactor() const {
171 return PrevTTI->getMaximumUnrollFactor();
172}
173
Chandler Carruth539edf42013-01-05 11:43:11 +0000174unsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
Arnold Schwaighoferb9773872013-04-04 23:26:21 +0000175 Type *Ty,
176 OperandValueKind Op1Info,
177 OperandValueKind Op2Info) const {
178 return PrevTTI->getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info);
Chandler Carruth539edf42013-01-05 11:43:11 +0000179}
180
181unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
182 int Index, Type *SubTp) const {
183 return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
184}
185
186unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
187 Type *Src) const {
188 return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
189}
190
191unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
192 return PrevTTI->getCFInstrCost(Opcode);
193}
194
195unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
196 Type *CondTy) const {
197 return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
198}
199
200unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
201 unsigned Index) const {
202 return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
203}
204
205unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
206 unsigned Alignment,
207 unsigned AddressSpace) const {
208 return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
209 ;
210}
211
212unsigned
213TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
214 Type *RetTy,
215 ArrayRef<Type *> Tys) const {
216 return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
217}
218
219unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
220 return PrevTTI->getNumberOfParts(Tp);
221}
222
Arnold Schwaighofer9da9a432013-07-12 19:16:02 +0000223unsigned TargetTransformInfo::getAddressComputationCost(Type *Tp,
224 bool IsComplex) const {
225 return PrevTTI->getAddressComputationCost(Tp, IsComplex);
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000226}
Chandler Carruth539edf42013-01-05 11:43:11 +0000227
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000228unsigned TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
229 bool IsPairwise) const {
230 return PrevTTI->getReductionCost(Opcode, Ty, IsPairwise);
231}
232
James Molloy2b8933c2014-08-05 12:30:34 +0000233unsigned TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type*> Tys)
234 const {
235 return PrevTTI->getCostOfKeepingLiveOverCall(Tys);
236}
237
Chandler Carruth539edf42013-01-05 11:43:11 +0000238namespace {
239
Craig Topper77dfe452014-03-02 08:08:51 +0000240struct NoTTI final : ImmutablePass, TargetTransformInfo {
Chandler Carruth511aa762013-01-21 01:27:39 +0000241 const DataLayout *DL;
242
Craig Topper9f008862014-04-15 04:59:12 +0000243 NoTTI() : ImmutablePass(ID), DL(nullptr) {
Chandler Carruth539edf42013-01-05 11:43:11 +0000244 initializeNoTTIPass(*PassRegistry::getPassRegistry());
245 }
246
Craig Topper73156022014-03-02 09:09:27 +0000247 virtual void initializePass() override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000248 // Note that this subclass is special, and must *not* call initializeTTI as
249 // it does not chain.
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000250 TopTTI = this;
Craig Topper9f008862014-04-15 04:59:12 +0000251 PrevTTI = nullptr;
Rafael Espindola93512512014-02-25 17:30:31 +0000252 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
Craig Topper9f008862014-04-15 04:59:12 +0000253 DL = DLP ? &DLP->getDataLayout() : nullptr;
Chandler Carruth664e3542013-01-07 01:37:14 +0000254 }
255
Craig Topper73156022014-03-02 09:09:27 +0000256 virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
Chandler Carruth539edf42013-01-05 11:43:11 +0000257 // Note that this subclass is special, and must *not* call
258 // TTI::getAnalysisUsage as it breaks the recursion.
259 }
260
261 /// Pass identification.
262 static char ID;
263
264 /// Provide necessary pointer adjustments for the two base classes.
Craig Topper73156022014-03-02 09:09:27 +0000265 virtual void *getAdjustedAnalysisPointer(const void *ID) override {
Chandler Carruth539edf42013-01-05 11:43:11 +0000266 if (ID == &TargetTransformInfo::ID)
267 return (TargetTransformInfo*)this;
268 return this;
269 }
270
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000271 unsigned getOperationCost(unsigned Opcode, Type *Ty,
Craig Topper73156022014-03-02 09:09:27 +0000272 Type *OpTy) const override {
Chandler Carruth511aa762013-01-21 01:27:39 +0000273 switch (Opcode) {
274 default:
275 // By default, just classify everything as 'basic'.
276 return TCC_Basic;
277
278 case Instruction::GetElementPtr:
279 llvm_unreachable("Use getGEPCost for GEP operations!");
280
281 case Instruction::BitCast:
282 assert(OpTy && "Cast instructions must provide the operand type");
283 if (Ty == OpTy || (Ty->isPointerTy() && OpTy->isPointerTy()))
284 // Identity and pointer-to-pointer casts are free.
285 return TCC_Free;
286
287 // Otherwise, the default basic cost is used.
288 return TCC_Basic;
289
Matt Arsenault54c3cbc2013-08-28 22:41:57 +0000290 case Instruction::IntToPtr: {
291 if (!DL)
292 return TCC_Basic;
293
Chandler Carruth511aa762013-01-21 01:27:39 +0000294 // An inttoptr cast is free so long as the input is a legal integer type
295 // which doesn't contain values outside the range of a pointer.
Matt Arsenault54c3cbc2013-08-28 22:41:57 +0000296 unsigned OpSize = OpTy->getScalarSizeInBits();
297 if (DL->isLegalInteger(OpSize) &&
298 OpSize <= DL->getPointerTypeSizeInBits(Ty))
Chandler Carruth511aa762013-01-21 01:27:39 +0000299 return TCC_Free;
300
301 // Otherwise it's not a no-op.
302 return TCC_Basic;
Matt Arsenault54c3cbc2013-08-28 22:41:57 +0000303 }
304 case Instruction::PtrToInt: {
305 if (!DL)
306 return TCC_Basic;
Chandler Carruth511aa762013-01-21 01:27:39 +0000307
Chandler Carruth511aa762013-01-21 01:27:39 +0000308 // A ptrtoint cast is free so long as the result is large enough to store
309 // the pointer, and a legal integer type.
Matt Arsenault54c3cbc2013-08-28 22:41:57 +0000310 unsigned DestSize = Ty->getScalarSizeInBits();
311 if (DL->isLegalInteger(DestSize) &&
312 DestSize >= DL->getPointerTypeSizeInBits(OpTy))
Chandler Carruth511aa762013-01-21 01:27:39 +0000313 return TCC_Free;
314
315 // Otherwise it's not a no-op.
316 return TCC_Basic;
Matt Arsenault54c3cbc2013-08-28 22:41:57 +0000317 }
Chandler Carruth511aa762013-01-21 01:27:39 +0000318 case Instruction::Trunc:
319 // trunc to a native type is free (assuming the target has compare and
320 // shift-right of the same width).
321 if (DL && DL->isLegalInteger(DL->getTypeSizeInBits(Ty)))
322 return TCC_Free;
323
324 return TCC_Basic;
325 }
326 }
327
328 unsigned getGEPCost(const Value *Ptr,
Craig Topper73156022014-03-02 09:09:27 +0000329 ArrayRef<const Value *> Operands) const override {
Chandler Carruth511aa762013-01-21 01:27:39 +0000330 // In the basic model, we just assume that all-constant GEPs will be folded
331 // into their uses via addressing modes.
332 for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
333 if (!isa<Constant>(Operands[Idx]))
334 return TCC_Basic;
335
336 return TCC_Free;
337 }
338
Craig Topper73156022014-03-02 09:09:27 +0000339 unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const override
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000340 {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000341 assert(FTy && "FunctionType must be provided to this routine.");
342
343 // The target-independent implementation just measures the size of the
344 // function by approximating that each argument will take on average one
345 // instruction to prepare.
346
347 if (NumArgs < 0)
348 // Set the argument number to the number of explicit arguments in the
349 // function.
350 NumArgs = FTy->getNumParams();
351
352 return TCC_Basic * (NumArgs + 1);
353 }
354
Craig Topper73156022014-03-02 09:09:27 +0000355 unsigned getCallCost(const Function *F, int NumArgs = -1) const override
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000356 {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000357 assert(F && "A concrete function must be provided to this routine.");
358
359 if (NumArgs < 0)
360 // Set the argument number to the number of explicit arguments in the
361 // function.
362 NumArgs = F->arg_size();
363
364 if (Intrinsic::ID IID = (Intrinsic::ID)F->getIntrinsicID()) {
365 FunctionType *FTy = F->getFunctionType();
366 SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
367 return TopTTI->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
368 }
369
370 if (!TopTTI->isLoweredToCall(F))
371 return TCC_Basic; // Give a basic cost if it will be lowered directly.
372
373 return TopTTI->getCallCost(F->getFunctionType(), NumArgs);
374 }
375
376 unsigned getCallCost(const Function *F,
Craig Topper73156022014-03-02 09:09:27 +0000377 ArrayRef<const Value *> Arguments) const override {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000378 // Simply delegate to generic handling of the call.
379 // FIXME: We should use instsimplify or something else to catch calls which
380 // will constant fold with these arguments.
381 return TopTTI->getCallCost(F, Arguments.size());
382 }
383
384 unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
Craig Topper73156022014-03-02 09:09:27 +0000385 ArrayRef<Type *> ParamTys) const override {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000386 switch (IID) {
387 default:
388 // Intrinsics rarely (if ever) have normal argument setup constraints.
389 // Model them as having a basic instruction cost.
390 // FIXME: This is wrong for libc intrinsics.
391 return TCC_Basic;
392
Hal Finkel93046912014-07-25 21:13:35 +0000393 case Intrinsic::assume:
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000394 case Intrinsic::dbg_declare:
395 case Intrinsic::dbg_value:
396 case Intrinsic::invariant_start:
397 case Intrinsic::invariant_end:
398 case Intrinsic::lifetime_start:
399 case Intrinsic::lifetime_end:
400 case Intrinsic::objectsize:
401 case Intrinsic::ptr_annotation:
402 case Intrinsic::var_annotation:
403 // These intrinsics don't actually represent code after lowering.
404 return TCC_Free;
405 }
406 }
407
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000408 unsigned
409 getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
Craig Topper73156022014-03-02 09:09:27 +0000410 ArrayRef<const Value *> Arguments) const override {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000411 // Delegate to the generic intrinsic handling code. This mostly provides an
412 // opportunity for targets to (for example) special case the cost of
413 // certain intrinsics based on constants used as arguments.
414 SmallVector<Type *, 8> ParamTys;
415 ParamTys.reserve(Arguments.size());
416 for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx)
417 ParamTys.push_back(Arguments[Idx]->getType());
418 return TopTTI->getIntrinsicCost(IID, RetTy, ParamTys);
419 }
420
Craig Topper73156022014-03-02 09:09:27 +0000421 unsigned getUserCost(const User *U) const override {
Chandler Carruthbb9caa92013-01-21 13:04:33 +0000422 if (isa<PHINode>(U))
423 return TCC_Free; // Model all PHI nodes as free.
424
Hal Finkelb4e001c2014-04-01 18:50:06 +0000425 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
426 SmallVector<const Value *, 4> Indices(GEP->idx_begin(), GEP->idx_end());
427 return TopTTI->getGEPCost(GEP->getPointerOperand(), Indices);
428 }
Chandler Carruth511aa762013-01-21 01:27:39 +0000429
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000430 if (ImmutableCallSite CS = U) {
431 const Function *F = CS.getCalledFunction();
432 if (!F) {
433 // Just use the called value type.
434 Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
435 return TopTTI->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
Chandler Carruth511aa762013-01-21 01:27:39 +0000436 }
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000437
Benjamin Kramer3c29c072014-02-10 14:17:42 +0000438 SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000439 return TopTTI->getCallCost(F, Arguments);
Chandler Carruth511aa762013-01-21 01:27:39 +0000440 }
441
442 if (const CastInst *CI = dyn_cast<CastInst>(U)) {
443 // Result of a cmp instruction is often extended (to be used by other
444 // cmp instructions, logical or return instructions). These are usually
445 // nop on most sane targets.
446 if (isa<CmpInst>(CI->getOperand(0)))
447 return TCC_Free;
448 }
449
450 // Otherwise delegate to the fully generic implementations.
451 return getOperationCost(Operator::getOpcode(U), U->getType(),
452 U->getNumOperands() == 1 ?
Craig Topper9f008862014-04-15 04:59:12 +0000453 U->getOperand(0)->getType() : nullptr);
Chandler Carruth511aa762013-01-21 01:27:39 +0000454 }
Chandler Carruth539edf42013-01-05 11:43:11 +0000455
Craig Topper73156022014-03-02 09:09:27 +0000456 bool hasBranchDivergence() const override { return false; }
Tom Stellard8b1e0212013-07-27 00:01:07 +0000457
Craig Topper73156022014-03-02 09:09:27 +0000458 bool isLoweredToCall(const Function *F) const override {
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000459 // FIXME: These should almost certainly not be handled here, and instead
460 // handled with the help of TLI or the target itself. This was largely
461 // ported from existing analysis heuristics here so that such refactorings
462 // can take place in the future.
463
464 if (F->isIntrinsic())
465 return false;
466
467 if (F->hasLocalLinkage() || !F->hasName())
468 return true;
469
470 StringRef Name = F->getName();
471
472 // These will all likely lower to a single selection DAG node.
473 if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
474 Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" ||
475 Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" ||
476 Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl")
477 return false;
478
479 // These are all likely to be optimized into something smaller.
480 if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
481 Name == "exp2l" || Name == "exp2f" || Name == "floor" || Name ==
482 "floorf" || Name == "ceil" || Name == "round" || Name == "ffs" ||
483 Name == "ffsl" || Name == "abs" || Name == "labs" || Name == "llabs")
484 return false;
485
486 return true;
487 }
488
Craig Topper73156022014-03-02 09:09:27 +0000489 void getUnrollingPreferences(Loop *, UnrollingPreferences &) const override {
490 }
Hal Finkel8f2e7002013-09-11 19:25:43 +0000491
Craig Topper73156022014-03-02 09:09:27 +0000492 bool isLegalAddImmediate(int64_t Imm) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000493 return false;
Chandler Carruth539edf42013-01-05 11:43:11 +0000494 }
495
Craig Topper73156022014-03-02 09:09:27 +0000496 bool isLegalICmpImmediate(int64_t Imm) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000497 return false;
Chandler Carruth539edf42013-01-05 11:43:11 +0000498 }
499
500 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
Craig Topper73156022014-03-02 09:09:27 +0000501 bool HasBaseReg, int64_t Scale) const override
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000502 {
Chandler Carruth26c59fa2013-01-07 14:41:08 +0000503 // Guess that reg+reg addressing is allowed. This heuristic is taken from
504 // the implementation of LSR.
505 return !BaseGV && BaseOffset == 0 && Scale <= 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000506 }
507
Quentin Colombetbf490d42013-05-31 21:29:03 +0000508 int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
Craig Topper73156022014-03-02 09:09:27 +0000509 bool HasBaseReg, int64_t Scale) const override {
Quentin Colombetbf490d42013-05-31 21:29:03 +0000510 // Guess that all legal addressing mode are free.
511 if(isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale))
512 return 0;
513 return -1;
514 }
515
Craig Topper73156022014-03-02 09:09:27 +0000516 bool isTruncateFree(Type *Ty1, Type *Ty2) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000517 return false;
Chandler Carruth539edf42013-01-05 11:43:11 +0000518 }
519
Craig Topper73156022014-03-02 09:09:27 +0000520 bool isTypeLegal(Type *Ty) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000521 return false;
Chandler Carruth539edf42013-01-05 11:43:11 +0000522 }
523
Craig Topper73156022014-03-02 09:09:27 +0000524 unsigned getJumpBufAlignment() const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000525 return 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000526 }
527
Craig Topper73156022014-03-02 09:09:27 +0000528 unsigned getJumpBufSize() const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000529 return 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000530 }
531
Craig Topper73156022014-03-02 09:09:27 +0000532 bool shouldBuildLookupTables() const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000533 return true;
Chandler Carruth539edf42013-01-05 11:43:11 +0000534 }
535
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000536 PopcntSupportKind
Craig Topper73156022014-03-02 09:09:27 +0000537 getPopcntSupport(unsigned IntTyWidthInBit) const override {
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000538 return PSK_Software;
Chandler Carruth539edf42013-01-05 11:43:11 +0000539 }
540
Craig Topper73156022014-03-02 09:09:27 +0000541 bool haveFastSqrt(Type *Ty) const override {
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000542 return false;
543 }
544
Craig Topper73156022014-03-02 09:09:27 +0000545 unsigned getIntImmCost(const APInt &Imm, Type *Ty) const override {
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000546 return TCC_Basic;
547 }
548
Juergen Ributzkaf0dff492014-03-21 06:04:45 +0000549 unsigned getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
Craig Topper73156022014-03-02 09:09:27 +0000550 Type *Ty) const override {
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000551 return TCC_Free;
552 }
553
Juergen Ributzkaf0dff492014-03-21 06:04:45 +0000554 unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
Craig Topper73156022014-03-02 09:09:27 +0000555 Type *Ty) const override {
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000556 return TCC_Free;
Chandler Carruth539edf42013-01-05 11:43:11 +0000557 }
558
Craig Topper73156022014-03-02 09:09:27 +0000559 unsigned getNumberOfRegisters(bool Vector) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000560 return 8;
Chandler Carruth539edf42013-01-05 11:43:11 +0000561 }
562
Craig Topper73156022014-03-02 09:09:27 +0000563 unsigned getRegisterBitWidth(bool Vector) const override {
Nadav Rotemb1791a72013-01-09 22:29:00 +0000564 return 32;
565 }
566
Craig Topper73156022014-03-02 09:09:27 +0000567 unsigned getMaximumUnrollFactor() const override {
Nadav Rotemb696c362013-01-09 01:15:42 +0000568 return 1;
569 }
570
Arnold Schwaighoferb9773872013-04-04 23:26:21 +0000571 unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind,
Craig Topper73156022014-03-02 09:09:27 +0000572 OperandValueKind) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000573 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000574 }
575
Juergen Ributzka3e752e72014-01-24 18:22:59 +0000576 unsigned getShuffleCost(ShuffleKind Kind, Type *Ty,
Craig Topper9f008862014-04-15 04:59:12 +0000577 int Index = 0, Type *SubTp = nullptr) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000578 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000579 }
580
581 unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
Craig Topper73156022014-03-02 09:09:27 +0000582 Type *Src) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000583 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000584 }
585
Craig Topper73156022014-03-02 09:09:27 +0000586 unsigned getCFInstrCost(unsigned Opcode) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000587 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000588 }
589
590 unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Craig Topper9f008862014-04-15 04:59:12 +0000591 Type *CondTy = nullptr) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000592 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000593 }
594
595 unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
Craig Topper73156022014-03-02 09:09:27 +0000596 unsigned Index = -1) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000597 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000598 }
599
Craig Topper73156022014-03-02 09:09:27 +0000600 unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
601 unsigned AddressSpace) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000602 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000603 }
604
Craig Topper73156022014-03-02 09:09:27 +0000605 unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
606 ArrayRef<Type*> Tys) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000607 return 1;
Chandler Carruth539edf42013-01-05 11:43:11 +0000608 }
609
Craig Topper73156022014-03-02 09:09:27 +0000610 unsigned getNumberOfParts(Type *Tp) const override {
Chandler Carruth664e3542013-01-07 01:37:14 +0000611 return 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000612 }
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000613
Craig Topper73156022014-03-02 09:09:27 +0000614 unsigned getAddressComputationCost(Type *Tp, bool) const override {
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000615 return 0;
616 }
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000617
Craig Topper73156022014-03-02 09:09:27 +0000618 unsigned getReductionCost(unsigned, Type *, bool) const override {
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000619 return 1;
620 }
James Molloy2b8933c2014-08-05 12:30:34 +0000621
622 unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type*> Tys) const override {
623 return 0;
624 }
625
Chandler Carruth539edf42013-01-05 11:43:11 +0000626};
627
628} // end anonymous namespace
629
Chandler Carruth664e3542013-01-07 01:37:14 +0000630INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti",
Chandler Carruth539edf42013-01-05 11:43:11 +0000631 "No target information", true, true, true)
632char NoTTI::ID = 0;
633
Chandler Carruth664e3542013-01-07 01:37:14 +0000634ImmutablePass *llvm::createNoTargetTransformInfoPass() {
635 return new NoTTI();
Chandler Carruth539edf42013-01-05 11:43:11 +0000636}