blob: 383d602f51d0b1fb18b1b893a7d098811b989a0a [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
Chandler Carruth539edf42013-01-05 11:43:11 +0000153bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000154 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000155}
156
Chad Rosier54390052015-02-23 19:15:16 +0000157bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
158 return TTIImpl->isProfitableToHoist(I);
159}
160
Chandler Carruth539edf42013-01-05 11:43:11 +0000161bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000162 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000163}
164
165unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000166 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000167}
168
169unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000170 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000171}
172
173bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000174 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000175}
176
Olivier Sallenave049d8032015-03-06 23:12:04 +0000177bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
178 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
179}
180
Silviu Baranga61bdc512015-08-10 14:50:54 +0000181bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
182 return TTIImpl->enableInterleavedAccessVectorization();
183}
184
Renato Golin5cb666a2016-04-14 20:42:18 +0000185bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
186 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
187}
188
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000189bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
190 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000191 unsigned AddressSpace,
192 unsigned Alignment,
193 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000194 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000195 Alignment, Fast);
196}
197
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000198TargetTransformInfo::PopcntSupportKind
199TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000200 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000201}
202
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000203bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000204 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000205}
206
Chandler Carruth93205eb2015-08-05 18:08:10 +0000207int TargetTransformInfo::getFPOpCost(Type *Ty) const {
208 int Cost = TTIImpl->getFPOpCost(Ty);
209 assert(Cost >= 0 && "TTI should not produce negative costs!");
210 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000211}
212
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000213int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
214 const APInt &Imm,
215 Type *Ty) const {
216 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
217 assert(Cost >= 0 && "TTI should not produce negative costs!");
218 return Cost;
219}
220
Chandler Carruth93205eb2015-08-05 18:08:10 +0000221int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
222 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
223 assert(Cost >= 0 && "TTI should not produce negative costs!");
224 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000225}
226
Chandler Carruth93205eb2015-08-05 18:08:10 +0000227int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
228 const APInt &Imm, Type *Ty) const {
229 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
230 assert(Cost >= 0 && "TTI should not produce negative costs!");
231 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000232}
233
Chandler Carruth93205eb2015-08-05 18:08:10 +0000234int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
235 const APInt &Imm, Type *Ty) const {
236 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
237 assert(Cost >= 0 && "TTI should not produce negative costs!");
238 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000239}
240
Chandler Carruth539edf42013-01-05 11:43:11 +0000241unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000242 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000243}
244
Nadav Rotemb1791a72013-01-09 22:29:00 +0000245unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000246 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000247}
248
Matt Arsenault8dad57c2016-06-16 21:43:12 +0000249unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
250 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
251}
252
Adam Nemetaf761102016-01-21 18:28:36 +0000253unsigned TargetTransformInfo::getCacheLineSize() const {
254 return TTIImpl->getCacheLineSize();
255}
256
Adam Nemetdadfbb52016-01-27 22:21:25 +0000257unsigned TargetTransformInfo::getPrefetchDistance() const {
258 return TTIImpl->getPrefetchDistance();
259}
260
Adam Nemet6d8beec2016-03-18 00:27:38 +0000261unsigned TargetTransformInfo::getMinPrefetchStride() const {
262 return TTIImpl->getMinPrefetchStride();
263}
264
Adam Nemet709e3042016-03-18 00:27:43 +0000265unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
266 return TTIImpl->getMaxPrefetchIterationsAhead();
267}
268
Wei Mi062c7442015-05-06 17:12:25 +0000269unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
270 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000271}
272
Chandler Carruth93205eb2015-08-05 18:08:10 +0000273int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000274 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
275 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000276 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000277 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
278 Opd1PropInfo, Opd2PropInfo);
279 assert(Cost >= 0 && "TTI should not produce negative costs!");
280 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000281}
282
Chandler Carruth93205eb2015-08-05 18:08:10 +0000283int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
284 Type *SubTp) const {
285 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
286 assert(Cost >= 0 && "TTI should not produce negative costs!");
287 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000288}
289
Chandler Carruth93205eb2015-08-05 18:08:10 +0000290int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
291 Type *Src) const {
292 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
293 assert(Cost >= 0 && "TTI should not produce negative costs!");
294 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000295}
296
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000297int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
298 VectorType *VecTy,
299 unsigned Index) const {
300 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
301 assert(Cost >= 0 && "TTI should not produce negative costs!");
302 return Cost;
303}
304
Chandler Carruth93205eb2015-08-05 18:08:10 +0000305int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
306 int Cost = TTIImpl->getCFInstrCost(Opcode);
307 assert(Cost >= 0 && "TTI should not produce negative costs!");
308 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000309}
310
Chandler Carruth93205eb2015-08-05 18:08:10 +0000311int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
312 Type *CondTy) const {
313 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
314 assert(Cost >= 0 && "TTI should not produce negative costs!");
315 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000316}
317
Chandler Carruth93205eb2015-08-05 18:08:10 +0000318int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
319 unsigned Index) const {
320 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
321 assert(Cost >= 0 && "TTI should not produce negative costs!");
322 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000323}
324
Chandler Carruth93205eb2015-08-05 18:08:10 +0000325int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
326 unsigned Alignment,
327 unsigned AddressSpace) const {
328 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
329 assert(Cost >= 0 && "TTI should not produce negative costs!");
330 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000331}
332
Chandler Carruth93205eb2015-08-05 18:08:10 +0000333int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
334 unsigned Alignment,
335 unsigned AddressSpace) const {
336 int Cost =
337 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
338 assert(Cost >= 0 && "TTI should not produce negative costs!");
339 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000340}
341
Elena Demikhovsky54946982015-12-28 20:10:59 +0000342int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
343 Value *Ptr, bool VariableMask,
344 unsigned Alignment) const {
345 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
346 Alignment);
347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
349}
350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000352 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
353 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000354 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
355 Alignment, AddressSpace);
356 assert(Cost >= 0 && "TTI should not produce negative costs!");
357 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000358}
359
Chandler Carruth93205eb2015-08-05 18:08:10 +0000360int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000361 ArrayRef<Type *> Tys,
362 FastMathFlags FMF) const {
363 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000364 assert(Cost >= 0 && "TTI should not produce negative costs!");
365 return Cost;
366}
367
Elena Demikhovsky54946982015-12-28 20:10:59 +0000368int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000369 ArrayRef<Value *> Args,
370 FastMathFlags FMF) const {
371 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000372 assert(Cost >= 0 && "TTI should not produce negative costs!");
373 return Cost;
374}
375
Chandler Carruth93205eb2015-08-05 18:08:10 +0000376int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
377 ArrayRef<Type *> Tys) const {
378 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
379 assert(Cost >= 0 && "TTI should not produce negative costs!");
380 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000381}
382
Chandler Carruth539edf42013-01-05 11:43:11 +0000383unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000384 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000385}
386
Chandler Carruth93205eb2015-08-05 18:08:10 +0000387int TargetTransformInfo::getAddressComputationCost(Type *Tp,
388 bool IsComplex) const {
389 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
390 assert(Cost >= 0 && "TTI should not produce negative costs!");
391 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000392}
Chandler Carruth539edf42013-01-05 11:43:11 +0000393
Chandler Carruth93205eb2015-08-05 18:08:10 +0000394int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
395 bool IsPairwiseForm) const {
396 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
397 assert(Cost >= 0 && "TTI should not produce negative costs!");
398 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000399}
400
Chandler Carruth705b1852015-01-31 03:43:40 +0000401unsigned
402TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
403 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000404}
405
406bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
407 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000408 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000409}
410
Chandler Carruth705b1852015-01-31 03:43:40 +0000411Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
412 IntrinsicInst *Inst, Type *ExpectedType) const {
413 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
414}
415
Eric Christopherd566fb12015-07-29 22:09:48 +0000416bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
417 const Function *Callee) const {
418 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000419}
420
Chandler Carruth705b1852015-01-31 03:43:40 +0000421TargetTransformInfo::Concept::~Concept() {}
422
Chandler Carruthe0385522015-02-01 10:11:22 +0000423TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
424
425TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000426 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000427 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000428
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000429TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000430 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000431 return TTICallback(F);
432}
433
Chandler Carruthb4faf132016-03-11 10:22:49 +0000434char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000435
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000436TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000437 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000438}
439
Chandler Carruth705b1852015-01-31 03:43:40 +0000440// Register the basic pass.
441INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
442 "Target Transform Information", false, true)
443char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000444
Chandler Carruth705b1852015-01-31 03:43:40 +0000445void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000446
Chandler Carruth705b1852015-01-31 03:43:40 +0000447TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000448 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000449 initializeTargetTransformInfoWrapperPassPass(
450 *PassRegistry::getPassRegistry());
451}
452
453TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000454 TargetIRAnalysis TIRA)
455 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000456 initializeTargetTransformInfoWrapperPassPass(
457 *PassRegistry::getPassRegistry());
458}
459
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000460TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000461 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000462 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000463 return *TTI;
464}
465
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000466ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000467llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
468 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000469}