blob: 94bbc58541a7705aafcf2fa6c8ce55852d8881ca [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
Chandler Carruth93205eb2015-08-05 18:08:10 +000085int TargetTransformInfo::getIntrinsicCost(
86 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
87 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
88 assert(Cost >= 0 && "TTI should not produce negative costs!");
89 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000090}
91
Jun Bum Lim919f9e82017-04-28 16:04:03 +000092unsigned
93TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
94 unsigned &JTSize) const {
95 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
96}
97
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +000098int TargetTransformInfo::getUserCost(const User *U,
99 ArrayRef<const Value *> Operands) const {
100 int Cost = TTIImpl->getUserCost(U, Operands);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000101 assert(Cost >= 0 && "TTI should not produce negative costs!");
102 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +0000103}
104
Tom Stellard8b1e0212013-07-27 00:01:07 +0000105bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000106 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +0000107}
108
Jingyue Wu5da831c2015-04-10 05:03:50 +0000109bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
110 return TTIImpl->isSourceOfDivergence(V);
111}
112
Alexander Timofeev0f9c84c2017-06-15 19:33:10 +0000113bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
114 return TTIImpl->isAlwaysUniform(V);
115}
116
Matt Arsenault42b64782017-01-30 23:02:12 +0000117unsigned TargetTransformInfo::getFlatAddressSpace() const {
118 return TTIImpl->getFlatAddressSpace();
119}
120
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000121bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000122 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000123}
124
Chandler Carruth705b1852015-01-31 03:43:40 +0000125void TargetTransformInfo::getUnrollingPreferences(
Geoff Berry66d9bdb2017-06-28 15:53:17 +0000126 Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
127 return TTIImpl->getUnrollingPreferences(L, SE, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000128}
129
Chandler Carruth539edf42013-01-05 11:43:11 +0000130bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000131 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000132}
133
134bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000135 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000136}
137
138bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
139 int64_t BaseOffset,
140 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000141 int64_t Scale,
142 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000143 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000144 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000145}
146
Evgeny Stupachenkof2b3b462017-06-05 23:37:00 +0000147bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
148 return TTIImpl->isLSRCostLess(C1, C2);
149}
150
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000151bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
152 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000153}
154
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000155bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
156 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000157}
158
Elena Demikhovsky09285852015-10-25 15:37:55 +0000159bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
160 return TTIImpl->isLegalMaskedGather(DataType);
161}
162
163bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
164 return TTIImpl->isLegalMaskedGather(DataType);
165}
166
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000167bool TargetTransformInfo::prefersVectorizedAddressing() const {
168 return TTIImpl->prefersVectorizedAddressing();
169}
170
Quentin Colombetbf490d42013-05-31 21:29:03 +0000171int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
172 int64_t BaseOffset,
173 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000174 int64_t Scale,
175 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000176 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
177 Scale, AddrSpace);
178 assert(Cost >= 0 && "TTI should not produce negative costs!");
179 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000180}
181
Jonas Paulsson7a794222016-08-17 13:24:19 +0000182bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
183 int64_t Offset) const {
184 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
185}
186
Chandler Carruth539edf42013-01-05 11:43:11 +0000187bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000188 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000189}
190
Chad Rosier54390052015-02-23 19:15:16 +0000191bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
192 return TTIImpl->isProfitableToHoist(I);
193}
194
Chandler Carruth539edf42013-01-05 11:43:11 +0000195bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000196 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000197}
198
199unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000200 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000201}
202
203unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000204 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000205}
206
207bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000208 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000209}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000210bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
211 return TTIImpl->shouldBuildLookupTablesForConstant(C);
212}
Chandler Carruth539edf42013-01-05 11:43:11 +0000213
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000214unsigned TargetTransformInfo::
215getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
216 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
217}
218
219unsigned TargetTransformInfo::
220getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
221 unsigned VF) const {
222 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
223}
224
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000225bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
226 return TTIImpl->supportsEfficientVectorElementLoadStore();
227}
228
Olivier Sallenave049d8032015-03-06 23:12:04 +0000229bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
230 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
231}
232
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000233bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const {
234 return TTIImpl->expandMemCmp(I, MaxLoadSize);
235}
236
Silviu Baranga61bdc512015-08-10 14:50:54 +0000237bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
238 return TTIImpl->enableInterleavedAccessVectorization();
239}
240
Renato Golin5cb666a2016-04-14 20:42:18 +0000241bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
242 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
243}
244
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000245bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
246 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000247 unsigned AddressSpace,
248 unsigned Alignment,
249 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000250 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000251 Alignment, Fast);
252}
253
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000254TargetTransformInfo::PopcntSupportKind
255TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000256 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000257}
258
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000259bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000260 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000261}
262
Chandler Carruth93205eb2015-08-05 18:08:10 +0000263int TargetTransformInfo::getFPOpCost(Type *Ty) const {
264 int Cost = TTIImpl->getFPOpCost(Ty);
265 assert(Cost >= 0 && "TTI should not produce negative costs!");
266 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000267}
268
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000269int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
270 const APInt &Imm,
271 Type *Ty) const {
272 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
273 assert(Cost >= 0 && "TTI should not produce negative costs!");
274 return Cost;
275}
276
Chandler Carruth93205eb2015-08-05 18:08:10 +0000277int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
278 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
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::getIntImmCost(unsigned Opcode, unsigned Idx,
284 const APInt &Imm, Type *Ty) const {
285 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
286 assert(Cost >= 0 && "TTI should not produce negative costs!");
287 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000288}
289
Chandler Carruth93205eb2015-08-05 18:08:10 +0000290int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
291 const APInt &Imm, Type *Ty) const {
292 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
293 assert(Cost >= 0 && "TTI should not produce negative costs!");
294 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000295}
296
Chandler Carruth539edf42013-01-05 11:43:11 +0000297unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000298 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000299}
300
Nadav Rotemb1791a72013-01-09 22:29:00 +0000301unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000302 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000303}
304
Adam Nemete29686e2017-05-15 21:15:01 +0000305unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
306 return TTIImpl->getMinVectorRegisterBitWidth();
307}
308
Jun Bum Limdee55652017-04-03 19:20:07 +0000309bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
310 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
311 return TTIImpl->shouldConsiderAddressTypePromotion(
312 I, AllowPromotionWithoutCommonHeader);
313}
314
Adam Nemetaf761102016-01-21 18:28:36 +0000315unsigned TargetTransformInfo::getCacheLineSize() const {
316 return TTIImpl->getCacheLineSize();
317}
318
Adam Nemetdadfbb52016-01-27 22:21:25 +0000319unsigned TargetTransformInfo::getPrefetchDistance() const {
320 return TTIImpl->getPrefetchDistance();
321}
322
Adam Nemet6d8beec2016-03-18 00:27:38 +0000323unsigned TargetTransformInfo::getMinPrefetchStride() const {
324 return TTIImpl->getMinPrefetchStride();
325}
326
Adam Nemet709e3042016-03-18 00:27:43 +0000327unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
328 return TTIImpl->getMaxPrefetchIterationsAhead();
329}
330
Wei Mi062c7442015-05-06 17:12:25 +0000331unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
332 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000333}
334
Chandler Carruth93205eb2015-08-05 18:08:10 +0000335int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000336 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
337 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000338 OperandValueProperties Opd2PropInfo,
339 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000340 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000341 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000342 assert(Cost >= 0 && "TTI should not produce negative costs!");
343 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000344}
345
Chandler Carruth93205eb2015-08-05 18:08:10 +0000346int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
347 Type *SubTp) const {
348 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
349 assert(Cost >= 0 && "TTI should not produce negative costs!");
350 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000351}
352
Chandler Carruth93205eb2015-08-05 18:08:10 +0000353int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000354 Type *Src, const Instruction *I) const {
355 assert ((I == nullptr || I->getOpcode() == Opcode) &&
356 "Opcode should reflect passed instruction.");
357 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000358 assert(Cost >= 0 && "TTI should not produce negative costs!");
359 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000360}
361
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000362int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
363 VectorType *VecTy,
364 unsigned Index) const {
365 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
366 assert(Cost >= 0 && "TTI should not produce negative costs!");
367 return Cost;
368}
369
Chandler Carruth93205eb2015-08-05 18:08:10 +0000370int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
371 int Cost = TTIImpl->getCFInstrCost(Opcode);
372 assert(Cost >= 0 && "TTI should not produce negative costs!");
373 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000374}
375
Chandler Carruth93205eb2015-08-05 18:08:10 +0000376int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000377 Type *CondTy, const Instruction *I) const {
378 assert ((I == nullptr || I->getOpcode() == Opcode) &&
379 "Opcode should reflect passed instruction.");
380 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000381 assert(Cost >= 0 && "TTI should not produce negative costs!");
382 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000383}
384
Chandler Carruth93205eb2015-08-05 18:08:10 +0000385int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
386 unsigned Index) const {
387 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
388 assert(Cost >= 0 && "TTI should not produce negative costs!");
389 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000390}
391
Chandler Carruth93205eb2015-08-05 18:08:10 +0000392int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
393 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000394 unsigned AddressSpace,
395 const Instruction *I) const {
396 assert ((I == nullptr || I->getOpcode() == Opcode) &&
397 "Opcode should reflect passed instruction.");
398 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000399 assert(Cost >= 0 && "TTI should not produce negative costs!");
400 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000401}
402
Chandler Carruth93205eb2015-08-05 18:08:10 +0000403int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
404 unsigned Alignment,
405 unsigned AddressSpace) const {
406 int Cost =
407 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
408 assert(Cost >= 0 && "TTI should not produce negative costs!");
409 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000410}
411
Elena Demikhovsky54946982015-12-28 20:10:59 +0000412int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
413 Value *Ptr, bool VariableMask,
414 unsigned Alignment) const {
415 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
416 Alignment);
417 assert(Cost >= 0 && "TTI should not produce negative costs!");
418 return Cost;
419}
420
Chandler Carruth93205eb2015-08-05 18:08:10 +0000421int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000422 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
423 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000424 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
425 Alignment, AddressSpace);
426 assert(Cost >= 0 && "TTI should not produce negative costs!");
427 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000428}
429
Chandler Carruth93205eb2015-08-05 18:08:10 +0000430int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000431 ArrayRef<Type *> Tys, FastMathFlags FMF,
432 unsigned ScalarizationCostPassed) const {
433 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
434 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000435 assert(Cost >= 0 && "TTI should not produce negative costs!");
436 return Cost;
437}
438
Elena Demikhovsky54946982015-12-28 20:10:59 +0000439int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000440 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
441 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000442 assert(Cost >= 0 && "TTI should not produce negative costs!");
443 return Cost;
444}
445
Chandler Carruth93205eb2015-08-05 18:08:10 +0000446int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
447 ArrayRef<Type *> Tys) const {
448 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
449 assert(Cost >= 0 && "TTI should not produce negative costs!");
450 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000451}
452
Chandler Carruth539edf42013-01-05 11:43:11 +0000453unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000454 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000455}
456
Chandler Carruth93205eb2015-08-05 18:08:10 +0000457int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000458 ScalarEvolution *SE,
459 const SCEV *Ptr) const {
460 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000461 assert(Cost >= 0 && "TTI should not produce negative costs!");
462 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000463}
Chandler Carruth539edf42013-01-05 11:43:11 +0000464
Chandler Carruth93205eb2015-08-05 18:08:10 +0000465int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
466 bool IsPairwiseForm) const {
467 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
468 assert(Cost >= 0 && "TTI should not produce negative costs!");
469 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000470}
471
Chandler Carruth705b1852015-01-31 03:43:40 +0000472unsigned
473TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
474 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000475}
476
477bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
478 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000479 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000480}
481
Anna Thomasb2a212c2017-06-06 16:45:25 +0000482unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
483 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
484}
485
Chandler Carruth705b1852015-01-31 03:43:40 +0000486Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
487 IntrinsicInst *Inst, Type *ExpectedType) const {
488 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
489}
490
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000491Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
492 Value *Length,
493 unsigned SrcAlign,
494 unsigned DestAlign) const {
495 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
496 DestAlign);
497}
498
499void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
500 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
501 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
502 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
503 SrcAlign, DestAlign);
504}
505
506bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const {
507 return UseWideMemcpyLoopLowering;
508}
509
Eric Christopherd566fb12015-07-29 22:09:48 +0000510bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
511 const Function *Callee) const {
512 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000513}
514
Volkan Keles1c386812016-10-03 10:31:34 +0000515unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
516 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
517}
518
519bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
520 return TTIImpl->isLegalToVectorizeLoad(LI);
521}
522
523bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
524 return TTIImpl->isLegalToVectorizeStore(SI);
525}
526
527bool TargetTransformInfo::isLegalToVectorizeLoadChain(
528 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
529 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
530 AddrSpace);
531}
532
533bool TargetTransformInfo::isLegalToVectorizeStoreChain(
534 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
535 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
536 AddrSpace);
537}
538
539unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
540 unsigned LoadSize,
541 unsigned ChainSizeInBytes,
542 VectorType *VecTy) const {
543 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
544}
545
546unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
547 unsigned StoreSize,
548 unsigned ChainSizeInBytes,
549 VectorType *VecTy) const {
550 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
551}
552
Amara Emersoncf9daa32017-05-09 10:43:25 +0000553bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
554 Type *Ty, ReductionFlags Flags) const {
555 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
556}
557
Amara Emerson836b0f42017-05-10 09:42:49 +0000558bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
559 return TTIImpl->shouldExpandReduction(II);
560}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000561
Chandler Carruth705b1852015-01-31 03:43:40 +0000562TargetTransformInfo::Concept::~Concept() {}
563
Chandler Carruthe0385522015-02-01 10:11:22 +0000564TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
565
566TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000567 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000568 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000569
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000570TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000571 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000572 return TTICallback(F);
573}
574
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000575AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000576
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000577TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000578 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000579}
580
Chandler Carruth705b1852015-01-31 03:43:40 +0000581// Register the basic pass.
582INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
583 "Target Transform Information", false, true)
584char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000585
Chandler Carruth705b1852015-01-31 03:43:40 +0000586void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000587
Chandler Carruth705b1852015-01-31 03:43:40 +0000588TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000589 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000590 initializeTargetTransformInfoWrapperPassPass(
591 *PassRegistry::getPassRegistry());
592}
593
594TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000595 TargetIRAnalysis TIRA)
596 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000597 initializeTargetTransformInfoWrapperPassPass(
598 *PassRegistry::getPassRegistry());
599}
600
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000601TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000602 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000603 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000604 return *TTI;
605}
606
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000607ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000608llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
609 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000610}