blob: 55b50ae42bc0b22d107e8d4abbff613ae4245f45 [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 Sbirlea327955e2016-07-11 20:46:17 +0000189bool TargetTransformInfo::allowsMisalignedMemoryAccesses(unsigned BitWidth,
190 unsigned AddressSpace,
191 unsigned Alignment,
192 bool *Fast) const {
193 return TTIImpl->allowsMisalignedMemoryAccesses(BitWidth, AddressSpace,
194 Alignment, Fast);
195}
196
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000197TargetTransformInfo::PopcntSupportKind
198TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000199 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000200}
201
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000202bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000203 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000204}
205
Chandler Carruth93205eb2015-08-05 18:08:10 +0000206int TargetTransformInfo::getFPOpCost(Type *Ty) const {
207 int Cost = TTIImpl->getFPOpCost(Ty);
208 assert(Cost >= 0 && "TTI should not produce negative costs!");
209 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000210}
211
Chandler Carruth93205eb2015-08-05 18:08:10 +0000212int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
213 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
214 assert(Cost >= 0 && "TTI should not produce negative costs!");
215 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000216}
217
Chandler Carruth93205eb2015-08-05 18:08:10 +0000218int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
219 const APInt &Imm, Type *Ty) const {
220 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
221 assert(Cost >= 0 && "TTI should not produce negative costs!");
222 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000223}
224
Chandler Carruth93205eb2015-08-05 18:08:10 +0000225int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
226 const APInt &Imm, Type *Ty) const {
227 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
228 assert(Cost >= 0 && "TTI should not produce negative costs!");
229 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000230}
231
Chandler Carruth539edf42013-01-05 11:43:11 +0000232unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000233 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000234}
235
Nadav Rotemb1791a72013-01-09 22:29:00 +0000236unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000237 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000238}
239
Matt Arsenault8dad57c2016-06-16 21:43:12 +0000240unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
241 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
242}
243
Adam Nemetaf761102016-01-21 18:28:36 +0000244unsigned TargetTransformInfo::getCacheLineSize() const {
245 return TTIImpl->getCacheLineSize();
246}
247
Adam Nemetdadfbb52016-01-27 22:21:25 +0000248unsigned TargetTransformInfo::getPrefetchDistance() const {
249 return TTIImpl->getPrefetchDistance();
250}
251
Adam Nemet6d8beec2016-03-18 00:27:38 +0000252unsigned TargetTransformInfo::getMinPrefetchStride() const {
253 return TTIImpl->getMinPrefetchStride();
254}
255
Adam Nemet709e3042016-03-18 00:27:43 +0000256unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
257 return TTIImpl->getMaxPrefetchIterationsAhead();
258}
259
Wei Mi062c7442015-05-06 17:12:25 +0000260unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
261 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000262}
263
Chandler Carruth93205eb2015-08-05 18:08:10 +0000264int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000265 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
266 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000267 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000268 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
269 Opd1PropInfo, Opd2PropInfo);
270 assert(Cost >= 0 && "TTI should not produce negative costs!");
271 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000272}
273
Chandler Carruth93205eb2015-08-05 18:08:10 +0000274int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
275 Type *SubTp) const {
276 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
277 assert(Cost >= 0 && "TTI should not produce negative costs!");
278 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000279}
280
Chandler Carruth93205eb2015-08-05 18:08:10 +0000281int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
282 Type *Src) const {
283 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
284 assert(Cost >= 0 && "TTI should not produce negative costs!");
285 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000286}
287
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000288int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
289 VectorType *VecTy,
290 unsigned Index) const {
291 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
292 assert(Cost >= 0 && "TTI should not produce negative costs!");
293 return Cost;
294}
295
Chandler Carruth93205eb2015-08-05 18:08:10 +0000296int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
297 int Cost = TTIImpl->getCFInstrCost(Opcode);
298 assert(Cost >= 0 && "TTI should not produce negative costs!");
299 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000300}
301
Chandler Carruth93205eb2015-08-05 18:08:10 +0000302int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
303 Type *CondTy) const {
304 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
305 assert(Cost >= 0 && "TTI should not produce negative costs!");
306 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000307}
308
Chandler Carruth93205eb2015-08-05 18:08:10 +0000309int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
310 unsigned Index) const {
311 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
312 assert(Cost >= 0 && "TTI should not produce negative costs!");
313 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000314}
315
Chandler Carruth93205eb2015-08-05 18:08:10 +0000316int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
317 unsigned Alignment,
318 unsigned AddressSpace) const {
319 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
320 assert(Cost >= 0 && "TTI should not produce negative costs!");
321 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000322}
323
Chandler Carruth93205eb2015-08-05 18:08:10 +0000324int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
325 unsigned Alignment,
326 unsigned AddressSpace) const {
327 int Cost =
328 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
329 assert(Cost >= 0 && "TTI should not produce negative costs!");
330 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000331}
332
Elena Demikhovsky54946982015-12-28 20:10:59 +0000333int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
334 Value *Ptr, bool VariableMask,
335 unsigned Alignment) const {
336 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
337 Alignment);
338 assert(Cost >= 0 && "TTI should not produce negative costs!");
339 return Cost;
340}
341
Chandler Carruth93205eb2015-08-05 18:08:10 +0000342int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000343 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
344 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000345 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
346 Alignment, AddressSpace);
347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000349}
350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000352 ArrayRef<Type *> Tys,
353 FastMathFlags FMF) const {
354 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000355 assert(Cost >= 0 && "TTI should not produce negative costs!");
356 return Cost;
357}
358
Elena Demikhovsky54946982015-12-28 20:10:59 +0000359int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000360 ArrayRef<Value *> Args,
361 FastMathFlags FMF) const {
362 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000363 assert(Cost >= 0 && "TTI should not produce negative costs!");
364 return Cost;
365}
366
Chandler Carruth93205eb2015-08-05 18:08:10 +0000367int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
368 ArrayRef<Type *> Tys) const {
369 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
370 assert(Cost >= 0 && "TTI should not produce negative costs!");
371 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000372}
373
Chandler Carruth539edf42013-01-05 11:43:11 +0000374unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000375 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000376}
377
Chandler Carruth93205eb2015-08-05 18:08:10 +0000378int TargetTransformInfo::getAddressComputationCost(Type *Tp,
379 bool IsComplex) const {
380 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
381 assert(Cost >= 0 && "TTI should not produce negative costs!");
382 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000383}
Chandler Carruth539edf42013-01-05 11:43:11 +0000384
Chandler Carruth93205eb2015-08-05 18:08:10 +0000385int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
386 bool IsPairwiseForm) const {
387 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
388 assert(Cost >= 0 && "TTI should not produce negative costs!");
389 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000390}
391
Chandler Carruth705b1852015-01-31 03:43:40 +0000392unsigned
393TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
394 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000395}
396
397bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
398 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000399 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000400}
401
Chandler Carruth705b1852015-01-31 03:43:40 +0000402Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
403 IntrinsicInst *Inst, Type *ExpectedType) const {
404 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
405}
406
Eric Christopherd566fb12015-07-29 22:09:48 +0000407bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
408 const Function *Callee) const {
409 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000410}
411
Chandler Carruth705b1852015-01-31 03:43:40 +0000412TargetTransformInfo::Concept::~Concept() {}
413
Chandler Carruthe0385522015-02-01 10:11:22 +0000414TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
415
416TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000417 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000418 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000419
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000420TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
421 AnalysisManager<Function> &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000422 return TTICallback(F);
423}
424
Chandler Carruthb4faf132016-03-11 10:22:49 +0000425char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000426
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000427TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000428 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000429}
430
Chandler Carruth705b1852015-01-31 03:43:40 +0000431// Register the basic pass.
432INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
433 "Target Transform Information", false, true)
434char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000435
Chandler Carruth705b1852015-01-31 03:43:40 +0000436void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000437
Chandler Carruth705b1852015-01-31 03:43:40 +0000438TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000439 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000440 initializeTargetTransformInfoWrapperPassPass(
441 *PassRegistry::getPassRegistry());
442}
443
444TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000445 TargetIRAnalysis TIRA)
446 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000447 initializeTargetTransformInfoWrapperPassPass(
448 *PassRegistry::getPassRegistry());
449}
450
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000451TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000452 AnalysisManager<Function> DummyFAM;
453 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000454 return *TTI;
455}
456
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000457ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000458llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
459 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000460}