blob: d73b1a12803187114c55d34904957cdf580f086c [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
Matt Arsenault42b64782017-01-30 23:02:12 +0000100unsigned TargetTransformInfo::getFlatAddressSpace() const {
101 return TTIImpl->getFlatAddressSpace();
102}
103
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000104bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000105 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000106}
107
Chandler Carruth705b1852015-01-31 03:43:40 +0000108void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +0000109 Loop *L, UnrollingPreferences &UP) const {
110 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000111}
112
Chandler Carruth539edf42013-01-05 11:43:11 +0000113bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000114 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000115}
116
117bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000118 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000119}
120
121bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
122 int64_t BaseOffset,
123 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000124 int64_t Scale,
125 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000126 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000127 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000128}
129
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000130bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
131 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000132}
133
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000134bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
135 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000136}
137
Elena Demikhovsky09285852015-10-25 15:37:55 +0000138bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
139 return TTIImpl->isLegalMaskedGather(DataType);
140}
141
142bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
143 return TTIImpl->isLegalMaskedGather(DataType);
144}
145
Quentin Colombetbf490d42013-05-31 21:29:03 +0000146int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
147 int64_t BaseOffset,
148 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000149 int64_t Scale,
150 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000151 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
152 Scale, AddrSpace);
153 assert(Cost >= 0 && "TTI should not produce negative costs!");
154 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000155}
156
Jonas Paulsson7a794222016-08-17 13:24:19 +0000157bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
158 int64_t Offset) const {
159 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
160}
161
Chandler Carruth539edf42013-01-05 11:43:11 +0000162bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000163 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000164}
165
Chad Rosier54390052015-02-23 19:15:16 +0000166bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
167 return TTIImpl->isProfitableToHoist(I);
168}
169
Chandler Carruth539edf42013-01-05 11:43:11 +0000170bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000171 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000172}
173
174unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000175 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000176}
177
178unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000179 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000180}
181
182bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000183 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000184}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000185bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
186 return TTIImpl->shouldBuildLookupTablesForConstant(C);
187}
Chandler Carruth539edf42013-01-05 11:43:11 +0000188
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000189unsigned TargetTransformInfo::
190getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
191 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
192}
193
194unsigned TargetTransformInfo::
195getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
196 unsigned VF) const {
197 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
198}
199
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000200bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
201 return TTIImpl->supportsEfficientVectorElementLoadStore();
202}
203
Olivier Sallenave049d8032015-03-06 23:12:04 +0000204bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
205 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
206}
207
Silviu Baranga61bdc512015-08-10 14:50:54 +0000208bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
209 return TTIImpl->enableInterleavedAccessVectorization();
210}
211
Renato Golin5cb666a2016-04-14 20:42:18 +0000212bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
213 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
214}
215
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000216bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
217 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000218 unsigned AddressSpace,
219 unsigned Alignment,
220 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000221 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000222 Alignment, Fast);
223}
224
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000225TargetTransformInfo::PopcntSupportKind
226TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000227 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000228}
229
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000230bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000231 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000232}
233
Chandler Carruth93205eb2015-08-05 18:08:10 +0000234int TargetTransformInfo::getFPOpCost(Type *Ty) const {
235 int Cost = TTIImpl->getFPOpCost(Ty);
236 assert(Cost >= 0 && "TTI should not produce negative costs!");
237 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000238}
239
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000240int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
241 const APInt &Imm,
242 Type *Ty) const {
243 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
244 assert(Cost >= 0 && "TTI should not produce negative costs!");
245 return Cost;
246}
247
Chandler Carruth93205eb2015-08-05 18:08:10 +0000248int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
249 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
250 assert(Cost >= 0 && "TTI should not produce negative costs!");
251 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000252}
253
Chandler Carruth93205eb2015-08-05 18:08:10 +0000254int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
255 const APInt &Imm, Type *Ty) const {
256 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
257 assert(Cost >= 0 && "TTI should not produce negative costs!");
258 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000259}
260
Chandler Carruth93205eb2015-08-05 18:08:10 +0000261int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
262 const APInt &Imm, Type *Ty) const {
263 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
264 assert(Cost >= 0 && "TTI should not produce negative costs!");
265 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000266}
267
Chandler Carruth539edf42013-01-05 11:43:11 +0000268unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000269 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000270}
271
Nadav Rotemb1791a72013-01-09 22:29:00 +0000272unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000273 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000274}
275
Jun Bum Limdee55652017-04-03 19:20:07 +0000276bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
277 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
278 return TTIImpl->shouldConsiderAddressTypePromotion(
279 I, AllowPromotionWithoutCommonHeader);
280}
281
Adam Nemetaf761102016-01-21 18:28:36 +0000282unsigned TargetTransformInfo::getCacheLineSize() const {
283 return TTIImpl->getCacheLineSize();
284}
285
Adam Nemetdadfbb52016-01-27 22:21:25 +0000286unsigned TargetTransformInfo::getPrefetchDistance() const {
287 return TTIImpl->getPrefetchDistance();
288}
289
Adam Nemet6d8beec2016-03-18 00:27:38 +0000290unsigned TargetTransformInfo::getMinPrefetchStride() const {
291 return TTIImpl->getMinPrefetchStride();
292}
293
Adam Nemet709e3042016-03-18 00:27:43 +0000294unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
295 return TTIImpl->getMaxPrefetchIterationsAhead();
296}
297
Wei Mi062c7442015-05-06 17:12:25 +0000298unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
299 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000300}
301
Chandler Carruth93205eb2015-08-05 18:08:10 +0000302int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000303 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
304 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000305 OperandValueProperties Opd2PropInfo,
306 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000307 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000308 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000309 assert(Cost >= 0 && "TTI should not produce negative costs!");
310 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000311}
312
Chandler Carruth93205eb2015-08-05 18:08:10 +0000313int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
314 Type *SubTp) const {
315 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
316 assert(Cost >= 0 && "TTI should not produce negative costs!");
317 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000318}
319
Chandler Carruth93205eb2015-08-05 18:08:10 +0000320int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000321 Type *Src, const Instruction *I) const {
322 assert ((I == nullptr || I->getOpcode() == Opcode) &&
323 "Opcode should reflect passed instruction.");
324 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000325 assert(Cost >= 0 && "TTI should not produce negative costs!");
326 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000327}
328
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000329int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
330 VectorType *VecTy,
331 unsigned Index) const {
332 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
333 assert(Cost >= 0 && "TTI should not produce negative costs!");
334 return Cost;
335}
336
Chandler Carruth93205eb2015-08-05 18:08:10 +0000337int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
338 int Cost = TTIImpl->getCFInstrCost(Opcode);
339 assert(Cost >= 0 && "TTI should not produce negative costs!");
340 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000341}
342
Chandler Carruth93205eb2015-08-05 18:08:10 +0000343int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000344 Type *CondTy, const Instruction *I) const {
345 assert ((I == nullptr || I->getOpcode() == Opcode) &&
346 "Opcode should reflect passed instruction.");
347 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000348 assert(Cost >= 0 && "TTI should not produce negative costs!");
349 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000350}
351
Chandler Carruth93205eb2015-08-05 18:08:10 +0000352int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
353 unsigned Index) const {
354 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
355 assert(Cost >= 0 && "TTI should not produce negative costs!");
356 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000357}
358
Chandler Carruth93205eb2015-08-05 18:08:10 +0000359int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
360 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000361 unsigned AddressSpace,
362 const Instruction *I) const {
363 assert ((I == nullptr || I->getOpcode() == Opcode) &&
364 "Opcode should reflect passed instruction.");
365 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000366 assert(Cost >= 0 && "TTI should not produce negative costs!");
367 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000368}
369
Chandler Carruth93205eb2015-08-05 18:08:10 +0000370int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
371 unsigned Alignment,
372 unsigned AddressSpace) const {
373 int Cost =
374 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
375 assert(Cost >= 0 && "TTI should not produce negative costs!");
376 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000377}
378
Elena Demikhovsky54946982015-12-28 20:10:59 +0000379int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
380 Value *Ptr, bool VariableMask,
381 unsigned Alignment) const {
382 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
383 Alignment);
384 assert(Cost >= 0 && "TTI should not produce negative costs!");
385 return Cost;
386}
387
Chandler Carruth93205eb2015-08-05 18:08:10 +0000388int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000389 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
390 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000391 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
392 Alignment, AddressSpace);
393 assert(Cost >= 0 && "TTI should not produce negative costs!");
394 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000395}
396
Chandler Carruth93205eb2015-08-05 18:08:10 +0000397int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000398 ArrayRef<Type *> Tys, FastMathFlags FMF,
399 unsigned ScalarizationCostPassed) const {
400 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
401 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000402 assert(Cost >= 0 && "TTI should not produce negative costs!");
403 return Cost;
404}
405
Elena Demikhovsky54946982015-12-28 20:10:59 +0000406int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000407 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
408 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000409 assert(Cost >= 0 && "TTI should not produce negative costs!");
410 return Cost;
411}
412
Chandler Carruth93205eb2015-08-05 18:08:10 +0000413int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
414 ArrayRef<Type *> Tys) const {
415 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
416 assert(Cost >= 0 && "TTI should not produce negative costs!");
417 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000418}
419
Chandler Carruth539edf42013-01-05 11:43:11 +0000420unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000421 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000422}
423
Chandler Carruth93205eb2015-08-05 18:08:10 +0000424int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000425 ScalarEvolution *SE,
426 const SCEV *Ptr) const {
427 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000428 assert(Cost >= 0 && "TTI should not produce negative costs!");
429 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000430}
Chandler Carruth539edf42013-01-05 11:43:11 +0000431
Chandler Carruth93205eb2015-08-05 18:08:10 +0000432int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
433 bool IsPairwiseForm) const {
434 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
435 assert(Cost >= 0 && "TTI should not produce negative costs!");
436 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000437}
438
Chandler Carruth705b1852015-01-31 03:43:40 +0000439unsigned
440TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
441 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000442}
443
444bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
445 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000446 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000447}
448
Chandler Carruth705b1852015-01-31 03:43:40 +0000449Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
450 IntrinsicInst *Inst, Type *ExpectedType) const {
451 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
452}
453
Eric Christopherd566fb12015-07-29 22:09:48 +0000454bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
455 const Function *Callee) const {
456 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000457}
458
Volkan Keles1c386812016-10-03 10:31:34 +0000459unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
460 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
461}
462
463bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
464 return TTIImpl->isLegalToVectorizeLoad(LI);
465}
466
467bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
468 return TTIImpl->isLegalToVectorizeStore(SI);
469}
470
471bool TargetTransformInfo::isLegalToVectorizeLoadChain(
472 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
473 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
474 AddrSpace);
475}
476
477bool TargetTransformInfo::isLegalToVectorizeStoreChain(
478 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
479 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
480 AddrSpace);
481}
482
483unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
484 unsigned LoadSize,
485 unsigned ChainSizeInBytes,
486 VectorType *VecTy) const {
487 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
488}
489
490unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
491 unsigned StoreSize,
492 unsigned ChainSizeInBytes,
493 VectorType *VecTy) const {
494 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
495}
496
Chandler Carruth705b1852015-01-31 03:43:40 +0000497TargetTransformInfo::Concept::~Concept() {}
498
Chandler Carruthe0385522015-02-01 10:11:22 +0000499TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
500
501TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000502 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000503 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000504
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000505TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000506 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000507 return TTICallback(F);
508}
509
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000510AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000511
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000512TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000513 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000514}
515
Chandler Carruth705b1852015-01-31 03:43:40 +0000516// Register the basic pass.
517INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
518 "Target Transform Information", false, true)
519char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000520
Chandler Carruth705b1852015-01-31 03:43:40 +0000521void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000522
Chandler Carruth705b1852015-01-31 03:43:40 +0000523TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000524 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000525 initializeTargetTransformInfoWrapperPassPass(
526 *PassRegistry::getPassRegistry());
527}
528
529TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000530 TargetIRAnalysis TIRA)
531 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000532 initializeTargetTransformInfoWrapperPassPass(
533 *PassRegistry::getPassRegistry());
534}
535
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000536TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000537 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000538 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000539 return *TTI;
540}
541
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000542ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000543llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
544 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000545}