blob: 25813c65037f2b77c7306fdad5cd80eb3d8dd415 [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"
Sean Fertile9cd1cdf2017-07-07 02:00:06 +000019#include "llvm/Support/CommandLine.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000020#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000021#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000022
23using namespace llvm;
24
Chandler Carruthf1221bd2014-04-22 02:48:03 +000025#define DEBUG_TYPE "tti"
26
Sean Fertile9cd1cdf2017-07-07 02:00:06 +000027static cl::opt<bool> UseWideMemcpyLoopLowering(
28 "use-wide-memcpy-loop-lowering", cl::init(false),
29 cl::desc("Enables the new wide memcpy loop lowering in Transforms/Utils."),
30 cl::Hidden);
31
Chandler Carruth93dcdc42015-01-31 11:17:59 +000032namespace {
33/// \brief No-op implementation of the TTI interface using the utility base
34/// classes.
35///
36/// This is used when no target specific information is available.
37struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000038 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000039 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
40};
41}
42
Mehdi Amini5010ebf2015-07-09 02:08:42 +000043TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000044 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
45
Chandler Carruth705b1852015-01-31 03:43:40 +000046TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000047
Chandler Carruth705b1852015-01-31 03:43:40 +000048TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
49 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000050
Chandler Carruth705b1852015-01-31 03:43:40 +000051TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
52 TTIImpl = std::move(RHS.TTIImpl);
53 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000054}
55
Chandler Carruth93205eb2015-08-05 18:08:10 +000056int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
57 Type *OpTy) const {
58 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
59 assert(Cost >= 0 && "TTI should not produce negative costs!");
60 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000061}
62
Chandler Carruth93205eb2015-08-05 18:08:10 +000063int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
64 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
65 assert(Cost >= 0 && "TTI should not produce negative costs!");
66 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000067}
68
Chandler Carruth93205eb2015-08-05 18:08:10 +000069int TargetTransformInfo::getCallCost(const Function *F,
70 ArrayRef<const Value *> Arguments) const {
71 int Cost = TTIImpl->getCallCost(F, Arguments);
72 assert(Cost >= 0 && "TTI should not produce negative costs!");
73 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000074}
75
Justin Lebar8650a4d2016-04-15 01:38:48 +000076unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
77 return TTIImpl->getInliningThresholdMultiplier();
78}
79
Jingyue Wu15f3e822016-07-08 21:48:05 +000080int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
81 ArrayRef<const Value *> Operands) const {
82 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
83}
84
Haicheng Wuabdef9e2017-07-15 02:12:16 +000085int TargetTransformInfo::getExtCost(const Instruction *I,
86 const Value *Src) const {
87 return TTIImpl->getExtCost(I, Src);
88}
89
Chandler Carruth93205eb2015-08-05 18:08:10 +000090int TargetTransformInfo::getIntrinsicCost(
91 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
92 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
93 assert(Cost >= 0 && "TTI should not produce negative costs!");
94 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000095}
96
Jun Bum Lim919f9e82017-04-28 16:04:03 +000097unsigned
98TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
99 unsigned &JTSize) const {
100 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
101}
102
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +0000103int TargetTransformInfo::getUserCost(const User *U,
104 ArrayRef<const Value *> Operands) const {
105 int Cost = TTIImpl->getUserCost(U, Operands);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000106 assert(Cost >= 0 && "TTI should not produce negative costs!");
107 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +0000108}
109
Tom Stellard8b1e0212013-07-27 00:01:07 +0000110bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000111 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +0000112}
113
Jingyue Wu5da831c2015-04-10 05:03:50 +0000114bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
115 return TTIImpl->isSourceOfDivergence(V);
116}
117
Alexander Timofeev0f9c84c2017-06-15 19:33:10 +0000118bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
119 return TTIImpl->isAlwaysUniform(V);
120}
121
Matt Arsenault42b64782017-01-30 23:02:12 +0000122unsigned TargetTransformInfo::getFlatAddressSpace() const {
123 return TTIImpl->getFlatAddressSpace();
124}
125
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000126bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000127 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000128}
129
Chandler Carruth705b1852015-01-31 03:43:40 +0000130void TargetTransformInfo::getUnrollingPreferences(
Geoff Berry66d9bdb2017-06-28 15:53:17 +0000131 Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
132 return TTIImpl->getUnrollingPreferences(L, SE, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000133}
134
Chandler Carruth539edf42013-01-05 11:43:11 +0000135bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000136 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000137}
138
139bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000140 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000141}
142
143bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
144 int64_t BaseOffset,
145 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000146 int64_t Scale,
147 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000148 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000149 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000150}
151
Evgeny Stupachenkof2b3b462017-06-05 23:37:00 +0000152bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
153 return TTIImpl->isLSRCostLess(C1, C2);
154}
155
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000156bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
157 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000158}
159
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000160bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
161 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000162}
163
Elena Demikhovsky09285852015-10-25 15:37:55 +0000164bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
165 return TTIImpl->isLegalMaskedGather(DataType);
166}
167
168bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
169 return TTIImpl->isLegalMaskedGather(DataType);
170}
171
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000172bool TargetTransformInfo::prefersVectorizedAddressing() const {
173 return TTIImpl->prefersVectorizedAddressing();
174}
175
Quentin Colombetbf490d42013-05-31 21:29:03 +0000176int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
177 int64_t BaseOffset,
178 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000179 int64_t Scale,
180 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000181 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
182 Scale, AddrSpace);
183 assert(Cost >= 0 && "TTI should not produce negative costs!");
184 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000185}
186
Jonas Paulsson7a794222016-08-17 13:24:19 +0000187bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
188 int64_t Offset) const {
189 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
190}
191
Chandler Carruth539edf42013-01-05 11:43:11 +0000192bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000193 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000194}
195
Chad Rosier54390052015-02-23 19:15:16 +0000196bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
197 return TTIImpl->isProfitableToHoist(I);
198}
199
Chandler Carruth539edf42013-01-05 11:43:11 +0000200bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000201 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000202}
203
204unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000205 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000206}
207
208unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000209 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000210}
211
212bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000213 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000214}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000215bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
216 return TTIImpl->shouldBuildLookupTablesForConstant(C);
217}
Chandler Carruth539edf42013-01-05 11:43:11 +0000218
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000219unsigned TargetTransformInfo::
220getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
221 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
222}
223
224unsigned TargetTransformInfo::
225getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
226 unsigned VF) const {
227 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
228}
229
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000230bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
231 return TTIImpl->supportsEfficientVectorElementLoadStore();
232}
233
Olivier Sallenave049d8032015-03-06 23:12:04 +0000234bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
235 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
236}
237
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000238bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const {
239 return TTIImpl->expandMemCmp(I, MaxLoadSize);
240}
241
Silviu Baranga61bdc512015-08-10 14:50:54 +0000242bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
243 return TTIImpl->enableInterleavedAccessVectorization();
244}
245
Renato Golin5cb666a2016-04-14 20:42:18 +0000246bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
247 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
248}
249
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000250bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
251 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000252 unsigned AddressSpace,
253 unsigned Alignment,
254 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000255 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000256 Alignment, Fast);
257}
258
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000259TargetTransformInfo::PopcntSupportKind
260TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000261 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000262}
263
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000264bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000265 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000266}
267
Chandler Carruth93205eb2015-08-05 18:08:10 +0000268int TargetTransformInfo::getFPOpCost(Type *Ty) const {
269 int Cost = TTIImpl->getFPOpCost(Ty);
270 assert(Cost >= 0 && "TTI should not produce negative costs!");
271 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000272}
273
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000274int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
275 const APInt &Imm,
276 Type *Ty) const {
277 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
278 assert(Cost >= 0 && "TTI should not produce negative costs!");
279 return Cost;
280}
281
Chandler Carruth93205eb2015-08-05 18:08:10 +0000282int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
283 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
284 assert(Cost >= 0 && "TTI should not produce negative costs!");
285 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000286}
287
Chandler Carruth93205eb2015-08-05 18:08:10 +0000288int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
289 const APInt &Imm, Type *Ty) const {
290 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
291 assert(Cost >= 0 && "TTI should not produce negative costs!");
292 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000293}
294
Chandler Carruth93205eb2015-08-05 18:08:10 +0000295int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
296 const APInt &Imm, Type *Ty) const {
297 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
298 assert(Cost >= 0 && "TTI should not produce negative costs!");
299 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000300}
301
Chandler Carruth539edf42013-01-05 11:43:11 +0000302unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000303 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000304}
305
Nadav Rotemb1791a72013-01-09 22:29:00 +0000306unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000307 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000308}
309
Adam Nemete29686e2017-05-15 21:15:01 +0000310unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
311 return TTIImpl->getMinVectorRegisterBitWidth();
312}
313
Jun Bum Limdee55652017-04-03 19:20:07 +0000314bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
315 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
316 return TTIImpl->shouldConsiderAddressTypePromotion(
317 I, AllowPromotionWithoutCommonHeader);
318}
319
Adam Nemetaf761102016-01-21 18:28:36 +0000320unsigned TargetTransformInfo::getCacheLineSize() const {
321 return TTIImpl->getCacheLineSize();
322}
323
Adam Nemetdadfbb52016-01-27 22:21:25 +0000324unsigned TargetTransformInfo::getPrefetchDistance() const {
325 return TTIImpl->getPrefetchDistance();
326}
327
Adam Nemet6d8beec2016-03-18 00:27:38 +0000328unsigned TargetTransformInfo::getMinPrefetchStride() const {
329 return TTIImpl->getMinPrefetchStride();
330}
331
Adam Nemet709e3042016-03-18 00:27:43 +0000332unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
333 return TTIImpl->getMaxPrefetchIterationsAhead();
334}
335
Wei Mi062c7442015-05-06 17:12:25 +0000336unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
337 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000338}
339
Chandler Carruth93205eb2015-08-05 18:08:10 +0000340int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000341 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
342 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000343 OperandValueProperties Opd2PropInfo,
344 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000345 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000346 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000349}
350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
352 Type *SubTp) const {
353 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
354 assert(Cost >= 0 && "TTI should not produce negative costs!");
355 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000356}
357
Chandler Carruth93205eb2015-08-05 18:08:10 +0000358int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000359 Type *Src, const Instruction *I) const {
360 assert ((I == nullptr || I->getOpcode() == Opcode) &&
361 "Opcode should reflect passed instruction.");
362 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000363 assert(Cost >= 0 && "TTI should not produce negative costs!");
364 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000365}
366
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000367int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
368 VectorType *VecTy,
369 unsigned Index) const {
370 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
371 assert(Cost >= 0 && "TTI should not produce negative costs!");
372 return Cost;
373}
374
Chandler Carruth93205eb2015-08-05 18:08:10 +0000375int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
376 int Cost = TTIImpl->getCFInstrCost(Opcode);
377 assert(Cost >= 0 && "TTI should not produce negative costs!");
378 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000379}
380
Chandler Carruth93205eb2015-08-05 18:08:10 +0000381int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000382 Type *CondTy, const Instruction *I) const {
383 assert ((I == nullptr || I->getOpcode() == Opcode) &&
384 "Opcode should reflect passed instruction.");
385 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000386 assert(Cost >= 0 && "TTI should not produce negative costs!");
387 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000388}
389
Chandler Carruth93205eb2015-08-05 18:08:10 +0000390int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
391 unsigned Index) const {
392 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
393 assert(Cost >= 0 && "TTI should not produce negative costs!");
394 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000395}
396
Chandler Carruth93205eb2015-08-05 18:08:10 +0000397int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
398 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000399 unsigned AddressSpace,
400 const Instruction *I) const {
401 assert ((I == nullptr || I->getOpcode() == Opcode) &&
402 "Opcode should reflect passed instruction.");
403 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000404 assert(Cost >= 0 && "TTI should not produce negative costs!");
405 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000406}
407
Chandler Carruth93205eb2015-08-05 18:08:10 +0000408int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
409 unsigned Alignment,
410 unsigned AddressSpace) const {
411 int Cost =
412 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
413 assert(Cost >= 0 && "TTI should not produce negative costs!");
414 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000415}
416
Elena Demikhovsky54946982015-12-28 20:10:59 +0000417int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
418 Value *Ptr, bool VariableMask,
419 unsigned Alignment) const {
420 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
421 Alignment);
422 assert(Cost >= 0 && "TTI should not produce negative costs!");
423 return Cost;
424}
425
Chandler Carruth93205eb2015-08-05 18:08:10 +0000426int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000427 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
428 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000429 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
430 Alignment, AddressSpace);
431 assert(Cost >= 0 && "TTI should not produce negative costs!");
432 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000433}
434
Chandler Carruth93205eb2015-08-05 18:08:10 +0000435int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000436 ArrayRef<Type *> Tys, FastMathFlags FMF,
437 unsigned ScalarizationCostPassed) const {
438 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
439 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000440 assert(Cost >= 0 && "TTI should not produce negative costs!");
441 return Cost;
442}
443
Elena Demikhovsky54946982015-12-28 20:10:59 +0000444int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000445 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
446 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000447 assert(Cost >= 0 && "TTI should not produce negative costs!");
448 return Cost;
449}
450
Chandler Carruth93205eb2015-08-05 18:08:10 +0000451int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
452 ArrayRef<Type *> Tys) const {
453 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
454 assert(Cost >= 0 && "TTI should not produce negative costs!");
455 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000456}
457
Chandler Carruth539edf42013-01-05 11:43:11 +0000458unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000459 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000460}
461
Chandler Carruth93205eb2015-08-05 18:08:10 +0000462int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000463 ScalarEvolution *SE,
464 const SCEV *Ptr) const {
465 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000466 assert(Cost >= 0 && "TTI should not produce negative costs!");
467 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000468}
Chandler Carruth539edf42013-01-05 11:43:11 +0000469
Chandler Carruth93205eb2015-08-05 18:08:10 +0000470int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
471 bool IsPairwiseForm) const {
472 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
473 assert(Cost >= 0 && "TTI should not produce negative costs!");
474 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000475}
476
Chandler Carruth705b1852015-01-31 03:43:40 +0000477unsigned
478TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
479 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000480}
481
482bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
483 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000484 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000485}
486
Anna Thomasb2a212c2017-06-06 16:45:25 +0000487unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
488 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
489}
490
Chandler Carruth705b1852015-01-31 03:43:40 +0000491Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
492 IntrinsicInst *Inst, Type *ExpectedType) const {
493 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
494}
495
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000496Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
497 Value *Length,
498 unsigned SrcAlign,
499 unsigned DestAlign) const {
500 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
501 DestAlign);
502}
503
504void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
505 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
506 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
507 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
508 SrcAlign, DestAlign);
509}
510
511bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const {
512 return UseWideMemcpyLoopLowering;
513}
514
Eric Christopherd566fb12015-07-29 22:09:48 +0000515bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
516 const Function *Callee) const {
517 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000518}
519
Volkan Keles1c386812016-10-03 10:31:34 +0000520unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
521 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
522}
523
524bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
525 return TTIImpl->isLegalToVectorizeLoad(LI);
526}
527
528bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
529 return TTIImpl->isLegalToVectorizeStore(SI);
530}
531
532bool TargetTransformInfo::isLegalToVectorizeLoadChain(
533 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
534 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
535 AddrSpace);
536}
537
538bool TargetTransformInfo::isLegalToVectorizeStoreChain(
539 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
540 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
541 AddrSpace);
542}
543
544unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
545 unsigned LoadSize,
546 unsigned ChainSizeInBytes,
547 VectorType *VecTy) const {
548 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
549}
550
551unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
552 unsigned StoreSize,
553 unsigned ChainSizeInBytes,
554 VectorType *VecTy) const {
555 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
556}
557
Amara Emersoncf9daa32017-05-09 10:43:25 +0000558bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
559 Type *Ty, ReductionFlags Flags) const {
560 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
561}
562
Amara Emerson836b0f42017-05-10 09:42:49 +0000563bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
564 return TTIImpl->shouldExpandReduction(II);
565}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000566
Chandler Carruth705b1852015-01-31 03:43:40 +0000567TargetTransformInfo::Concept::~Concept() {}
568
Chandler Carruthe0385522015-02-01 10:11:22 +0000569TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
570
571TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000572 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000573 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000574
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000575TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000576 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000577 return TTICallback(F);
578}
579
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000580AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000581
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000582TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000583 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000584}
585
Chandler Carruth705b1852015-01-31 03:43:40 +0000586// Register the basic pass.
587INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
588 "Target Transform Information", false, true)
589char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000590
Chandler Carruth705b1852015-01-31 03:43:40 +0000591void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000592
Chandler Carruth705b1852015-01-31 03:43:40 +0000593TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000594 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000595 initializeTargetTransformInfoWrapperPassPass(
596 *PassRegistry::getPassRegistry());
597}
598
599TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000600 TargetIRAnalysis TIRA)
601 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000602 initializeTargetTransformInfoWrapperPassPass(
603 *PassRegistry::getPassRegistry());
604}
605
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000606TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000607 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000608 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000609 return *TTI;
610}
611
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000612ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000613llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
614 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000615}