blob: fb0db03eb3fb484379c5427fb3d3e4fdbe1d1c81 [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 Carruth705b1852015-01-31 03:43:40 +000011#include "llvm/Analysis/TargetTransformInfoImpl.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000012#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000015#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "llvm/IR/IntrinsicInst.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000017#include "llvm/IR/Module.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000018#include "llvm/IR/Operator.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000019#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000020#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000021
22using namespace llvm;
23
Chandler Carruthf1221bd2014-04-22 02:48:03 +000024#define DEBUG_TYPE "tti"
25
Chandler Carruth93dcdc42015-01-31 11:17:59 +000026namespace {
27/// \brief No-op implementation of the TTI interface using the utility base
28/// classes.
29///
30/// This is used when no target specific information is available.
31struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000032 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000033 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
34};
35}
36
Mehdi Amini5010ebf2015-07-09 02:08:42 +000037TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000038 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
39
Chandler Carruth705b1852015-01-31 03:43:40 +000040TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000041
Chandler Carruth705b1852015-01-31 03:43:40 +000042TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
43 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000044
Chandler Carruth705b1852015-01-31 03:43:40 +000045TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
46 TTIImpl = std::move(RHS.TTIImpl);
47 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000048}
49
Chandler Carruth93205eb2015-08-05 18:08:10 +000050int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
51 Type *OpTy) const {
52 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
53 assert(Cost >= 0 && "TTI should not produce negative costs!");
54 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000055}
56
Chandler Carruth93205eb2015-08-05 18:08:10 +000057int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
58 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
59 assert(Cost >= 0 && "TTI should not produce negative costs!");
60 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000061}
62
Chandler Carruth93205eb2015-08-05 18:08:10 +000063int TargetTransformInfo::getCallCost(const Function *F,
64 ArrayRef<const Value *> Arguments) const {
65 int Cost = TTIImpl->getCallCost(F, Arguments);
66 assert(Cost >= 0 && "TTI should not produce negative costs!");
67 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000068}
69
Justin Lebar8650a4d2016-04-15 01:38:48 +000070unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
71 return TTIImpl->getInliningThresholdMultiplier();
72}
73
Jingyue Wu15f3e822016-07-08 21:48:05 +000074int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
75 ArrayRef<const Value *> Operands) const {
76 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
77}
78
Chandler Carruth93205eb2015-08-05 18:08:10 +000079int TargetTransformInfo::getIntrinsicCost(
80 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
81 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
82 assert(Cost >= 0 && "TTI should not produce negative costs!");
83 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000084}
85
Chandler Carruth93205eb2015-08-05 18:08:10 +000086int TargetTransformInfo::getUserCost(const User *U) const {
87 int Cost = TTIImpl->getUserCost(U);
88 assert(Cost >= 0 && "TTI should not produce negative costs!");
89 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000090}
91
Tom Stellard8b1e0212013-07-27 00:01:07 +000092bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000093 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000094}
95
Jingyue Wu5da831c2015-04-10 05:03:50 +000096bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
97 return TTIImpl->isSourceOfDivergence(V);
98}
99
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000100bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000101 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000102}
103
Chandler Carruth705b1852015-01-31 03:43:40 +0000104void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +0000105 Loop *L, UnrollingPreferences &UP) const {
106 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000107}
108
Chandler Carruth539edf42013-01-05 11:43:11 +0000109bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000110 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000111}
112
113bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000114 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000115}
116
117bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
118 int64_t BaseOffset,
119 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000120 int64_t Scale,
121 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000122 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000123 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000124}
125
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000126bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
127 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000128}
129
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000130bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
131 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000132}
133
Elena Demikhovsky09285852015-10-25 15:37:55 +0000134bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
135 return TTIImpl->isLegalMaskedGather(DataType);
136}
137
138bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
139 return TTIImpl->isLegalMaskedGather(DataType);
140}
141
Quentin Colombetbf490d42013-05-31 21:29:03 +0000142int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
143 int64_t BaseOffset,
144 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000145 int64_t Scale,
146 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000147 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
148 Scale, AddrSpace);
149 assert(Cost >= 0 && "TTI should not produce negative costs!");
150 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000151}
152
Jonas Paulsson7a794222016-08-17 13:24:19 +0000153bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
154 int64_t Offset) const {
155 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
156}
157
Chandler Carruth539edf42013-01-05 11:43:11 +0000158bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000159 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000160}
161
Chad Rosier54390052015-02-23 19:15:16 +0000162bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
163 return TTIImpl->isProfitableToHoist(I);
164}
165
Chandler Carruth539edf42013-01-05 11:43:11 +0000166bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000167 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000168}
169
170unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000171 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000172}
173
174unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000175 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000176}
177
178bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000179 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000180}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000181bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
182 return TTIImpl->shouldBuildLookupTablesForConstant(C);
183}
Chandler Carruth539edf42013-01-05 11:43:11 +0000184
Olivier Sallenave049d8032015-03-06 23:12:04 +0000185bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
186 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
187}
188
Silviu Baranga61bdc512015-08-10 14:50:54 +0000189bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
190 return TTIImpl->enableInterleavedAccessVectorization();
191}
192
Renato Golin5cb666a2016-04-14 20:42:18 +0000193bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
194 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
195}
196
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000197bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
198 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000199 unsigned AddressSpace,
200 unsigned Alignment,
201 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000202 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000203 Alignment, Fast);
204}
205
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000206TargetTransformInfo::PopcntSupportKind
207TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000208 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000209}
210
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000211bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000212 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000213}
214
Chandler Carruth93205eb2015-08-05 18:08:10 +0000215int TargetTransformInfo::getFPOpCost(Type *Ty) const {
216 int Cost = TTIImpl->getFPOpCost(Ty);
217 assert(Cost >= 0 && "TTI should not produce negative costs!");
218 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000219}
220
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000221int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
222 const APInt &Imm,
223 Type *Ty) const {
224 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
225 assert(Cost >= 0 && "TTI should not produce negative costs!");
226 return Cost;
227}
228
Chandler Carruth93205eb2015-08-05 18:08:10 +0000229int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
230 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
231 assert(Cost >= 0 && "TTI should not produce negative costs!");
232 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000233}
234
Chandler Carruth93205eb2015-08-05 18:08:10 +0000235int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
236 const APInt &Imm, Type *Ty) const {
237 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
238 assert(Cost >= 0 && "TTI should not produce negative costs!");
239 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000240}
241
Chandler Carruth93205eb2015-08-05 18:08:10 +0000242int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
243 const APInt &Imm, Type *Ty) const {
244 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
245 assert(Cost >= 0 && "TTI should not produce negative costs!");
246 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000247}
248
Chandler Carruth539edf42013-01-05 11:43:11 +0000249unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000250 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000251}
252
Nadav Rotemb1791a72013-01-09 22:29:00 +0000253unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000254 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000255}
256
Adam Nemetaf761102016-01-21 18:28:36 +0000257unsigned TargetTransformInfo::getCacheLineSize() const {
258 return TTIImpl->getCacheLineSize();
259}
260
Adam Nemetdadfbb52016-01-27 22:21:25 +0000261unsigned TargetTransformInfo::getPrefetchDistance() const {
262 return TTIImpl->getPrefetchDistance();
263}
264
Adam Nemet6d8beec2016-03-18 00:27:38 +0000265unsigned TargetTransformInfo::getMinPrefetchStride() const {
266 return TTIImpl->getMinPrefetchStride();
267}
268
Adam Nemet709e3042016-03-18 00:27:43 +0000269unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
270 return TTIImpl->getMaxPrefetchIterationsAhead();
271}
272
Wei Mi062c7442015-05-06 17:12:25 +0000273unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
274 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000275}
276
Chandler Carruth93205eb2015-08-05 18:08:10 +0000277int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000278 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
279 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000280 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000281 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
282 Opd1PropInfo, Opd2PropInfo);
283 assert(Cost >= 0 && "TTI should not produce negative costs!");
284 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000285}
286
Chandler Carruth93205eb2015-08-05 18:08:10 +0000287int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
288 Type *SubTp) const {
289 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
290 assert(Cost >= 0 && "TTI should not produce negative costs!");
291 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000292}
293
Chandler Carruth93205eb2015-08-05 18:08:10 +0000294int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
295 Type *Src) const {
296 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
297 assert(Cost >= 0 && "TTI should not produce negative costs!");
298 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000299}
300
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000301int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
302 VectorType *VecTy,
303 unsigned Index) const {
304 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
305 assert(Cost >= 0 && "TTI should not produce negative costs!");
306 return Cost;
307}
308
Chandler Carruth93205eb2015-08-05 18:08:10 +0000309int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
310 int Cost = TTIImpl->getCFInstrCost(Opcode);
311 assert(Cost >= 0 && "TTI should not produce negative costs!");
312 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000313}
314
Chandler Carruth93205eb2015-08-05 18:08:10 +0000315int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
316 Type *CondTy) const {
317 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
318 assert(Cost >= 0 && "TTI should not produce negative costs!");
319 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000320}
321
Chandler Carruth93205eb2015-08-05 18:08:10 +0000322int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
323 unsigned Index) const {
324 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
325 assert(Cost >= 0 && "TTI should not produce negative costs!");
326 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000327}
328
Chandler Carruth93205eb2015-08-05 18:08:10 +0000329int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
330 unsigned Alignment,
331 unsigned AddressSpace) const {
332 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
333 assert(Cost >= 0 && "TTI should not produce negative costs!");
334 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000335}
336
Chandler Carruth93205eb2015-08-05 18:08:10 +0000337int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
338 unsigned Alignment,
339 unsigned AddressSpace) const {
340 int Cost =
341 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
342 assert(Cost >= 0 && "TTI should not produce negative costs!");
343 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000344}
345
Elena Demikhovsky54946982015-12-28 20:10:59 +0000346int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
347 Value *Ptr, bool VariableMask,
348 unsigned Alignment) const {
349 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
350 Alignment);
351 assert(Cost >= 0 && "TTI should not produce negative costs!");
352 return Cost;
353}
354
Chandler Carruth93205eb2015-08-05 18:08:10 +0000355int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000356 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
357 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000358 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
359 Alignment, AddressSpace);
360 assert(Cost >= 0 && "TTI should not produce negative costs!");
361 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000362}
363
Chandler Carruth93205eb2015-08-05 18:08:10 +0000364int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000365 ArrayRef<Type *> Tys,
366 FastMathFlags FMF) const {
367 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000368 assert(Cost >= 0 && "TTI should not produce negative costs!");
369 return Cost;
370}
371
Elena Demikhovsky54946982015-12-28 20:10:59 +0000372int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000373 ArrayRef<Value *> Args,
374 FastMathFlags FMF) const {
375 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000376 assert(Cost >= 0 && "TTI should not produce negative costs!");
377 return Cost;
378}
379
Chandler Carruth93205eb2015-08-05 18:08:10 +0000380int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
381 ArrayRef<Type *> Tys) const {
382 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
383 assert(Cost >= 0 && "TTI should not produce negative costs!");
384 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000385}
386
Chandler Carruth539edf42013-01-05 11:43:11 +0000387unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000388 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000389}
390
Chandler Carruth93205eb2015-08-05 18:08:10 +0000391int TargetTransformInfo::getAddressComputationCost(Type *Tp,
392 bool IsComplex) const {
393 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
394 assert(Cost >= 0 && "TTI should not produce negative costs!");
395 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000396}
Chandler Carruth539edf42013-01-05 11:43:11 +0000397
Chandler Carruth93205eb2015-08-05 18:08:10 +0000398int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
399 bool IsPairwiseForm) const {
400 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
401 assert(Cost >= 0 && "TTI should not produce negative costs!");
402 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000403}
404
Chandler Carruth705b1852015-01-31 03:43:40 +0000405unsigned
406TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
407 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000408}
409
410bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
411 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000412 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000413}
414
Chandler Carruth705b1852015-01-31 03:43:40 +0000415Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
416 IntrinsicInst *Inst, Type *ExpectedType) const {
417 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
418}
419
Eric Christopherd566fb12015-07-29 22:09:48 +0000420bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
421 const Function *Callee) const {
422 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000423}
424
Volkan Keles1c386812016-10-03 10:31:34 +0000425unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
426 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
427}
428
429bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
430 return TTIImpl->isLegalToVectorizeLoad(LI);
431}
432
433bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
434 return TTIImpl->isLegalToVectorizeStore(SI);
435}
436
437bool TargetTransformInfo::isLegalToVectorizeLoadChain(
438 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
439 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
440 AddrSpace);
441}
442
443bool TargetTransformInfo::isLegalToVectorizeStoreChain(
444 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
445 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
446 AddrSpace);
447}
448
449unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
450 unsigned LoadSize,
451 unsigned ChainSizeInBytes,
452 VectorType *VecTy) const {
453 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
454}
455
456unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
457 unsigned StoreSize,
458 unsigned ChainSizeInBytes,
459 VectorType *VecTy) const {
460 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
461}
462
Chandler Carruth705b1852015-01-31 03:43:40 +0000463TargetTransformInfo::Concept::~Concept() {}
464
Chandler Carruthe0385522015-02-01 10:11:22 +0000465TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
466
467TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000468 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000469 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000470
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000471TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000472 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000473 return TTICallback(F);
474}
475
Chandler Carruthb4faf132016-03-11 10:22:49 +0000476char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000477
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000478TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000479 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000480}
481
Chandler Carruth705b1852015-01-31 03:43:40 +0000482// Register the basic pass.
483INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
484 "Target Transform Information", false, true)
485char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000486
Chandler Carruth705b1852015-01-31 03:43:40 +0000487void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000488
Chandler Carruth705b1852015-01-31 03:43:40 +0000489TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000490 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000491 initializeTargetTransformInfoWrapperPassPass(
492 *PassRegistry::getPassRegistry());
493}
494
495TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000496 TargetIRAnalysis TIRA)
497 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000498 initializeTargetTransformInfoWrapperPassPass(
499 *PassRegistry::getPassRegistry());
500}
501
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000502TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000503 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000504 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000505 return *TTI;
506}
507
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000508ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000509llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
510 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000511}