blob: 762760dd3329f98bdefac46db851815dc8f48e3c [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,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000147 unsigned AddrSpace,
148 Instruction *I) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000149 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000150 Scale, AddrSpace, I);
Chandler Carruth539edf42013-01-05 11:43:11 +0000151}
152
Evgeny Stupachenkof2b3b462017-06-05 23:37:00 +0000153bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
154 return TTIImpl->isLSRCostLess(C1, C2);
155}
156
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000157bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
158 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000159}
160
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000161bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
162 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000163}
164
Elena Demikhovsky09285852015-10-25 15:37:55 +0000165bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
166 return TTIImpl->isLegalMaskedGather(DataType);
167}
168
169bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
170 return TTIImpl->isLegalMaskedGather(DataType);
171}
172
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000173bool TargetTransformInfo::prefersVectorizedAddressing() const {
174 return TTIImpl->prefersVectorizedAddressing();
175}
176
Quentin Colombetbf490d42013-05-31 21:29:03 +0000177int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
178 int64_t BaseOffset,
179 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000180 int64_t Scale,
181 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000182 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
183 Scale, AddrSpace);
184 assert(Cost >= 0 && "TTI should not produce negative costs!");
185 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000186}
187
Jonas Paulsson024e3192017-07-21 11:59:37 +0000188bool TargetTransformInfo::LSRWithInstrQueries() const {
189 return TTIImpl->LSRWithInstrQueries();
190}
191
Jonas Paulsson7a794222016-08-17 13:24:19 +0000192bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
193 int64_t Offset) const {
194 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
195}
196
Chandler Carruth539edf42013-01-05 11:43:11 +0000197bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000198 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000199}
200
Chad Rosier54390052015-02-23 19:15:16 +0000201bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
202 return TTIImpl->isProfitableToHoist(I);
203}
204
Chandler Carruth539edf42013-01-05 11:43:11 +0000205bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000206 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000207}
208
209unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000210 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000211}
212
213unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000214 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000215}
216
217bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000218 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000219}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000220bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
221 return TTIImpl->shouldBuildLookupTablesForConstant(C);
222}
Chandler Carruth539edf42013-01-05 11:43:11 +0000223
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000224unsigned TargetTransformInfo::
225getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
226 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
227}
228
229unsigned TargetTransformInfo::
230getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
231 unsigned VF) const {
232 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
233}
234
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000235bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
236 return TTIImpl->supportsEfficientVectorElementLoadStore();
237}
238
Olivier Sallenave049d8032015-03-06 23:12:04 +0000239bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
240 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
241}
242
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000243bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const {
244 return TTIImpl->expandMemCmp(I, MaxLoadSize);
245}
246
Silviu Baranga61bdc512015-08-10 14:50:54 +0000247bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
248 return TTIImpl->enableInterleavedAccessVectorization();
249}
250
Renato Golin5cb666a2016-04-14 20:42:18 +0000251bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
252 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
253}
254
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000255bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
256 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000257 unsigned AddressSpace,
258 unsigned Alignment,
259 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000260 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000261 Alignment, Fast);
262}
263
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000264TargetTransformInfo::PopcntSupportKind
265TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000266 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000267}
268
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000269bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000270 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000271}
272
Chandler Carruth93205eb2015-08-05 18:08:10 +0000273int TargetTransformInfo::getFPOpCost(Type *Ty) const {
274 int Cost = TTIImpl->getFPOpCost(Ty);
275 assert(Cost >= 0 && "TTI should not produce negative costs!");
276 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000277}
278
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000279int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
280 const APInt &Imm,
281 Type *Ty) const {
282 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
283 assert(Cost >= 0 && "TTI should not produce negative costs!");
284 return Cost;
285}
286
Chandler Carruth93205eb2015-08-05 18:08:10 +0000287int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
288 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
289 assert(Cost >= 0 && "TTI should not produce negative costs!");
290 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000291}
292
Chandler Carruth93205eb2015-08-05 18:08:10 +0000293int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
294 const APInt &Imm, Type *Ty) const {
295 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
296 assert(Cost >= 0 && "TTI should not produce negative costs!");
297 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000298}
299
Chandler Carruth93205eb2015-08-05 18:08:10 +0000300int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
301 const APInt &Imm, Type *Ty) const {
302 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
303 assert(Cost >= 0 && "TTI should not produce negative costs!");
304 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000305}
306
Chandler Carruth539edf42013-01-05 11:43:11 +0000307unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000308 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000309}
310
Nadav Rotemb1791a72013-01-09 22:29:00 +0000311unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000312 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000313}
314
Adam Nemete29686e2017-05-15 21:15:01 +0000315unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
316 return TTIImpl->getMinVectorRegisterBitWidth();
317}
318
Jun Bum Limdee55652017-04-03 19:20:07 +0000319bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
320 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
321 return TTIImpl->shouldConsiderAddressTypePromotion(
322 I, AllowPromotionWithoutCommonHeader);
323}
324
Adam Nemetaf761102016-01-21 18:28:36 +0000325unsigned TargetTransformInfo::getCacheLineSize() const {
326 return TTIImpl->getCacheLineSize();
327}
328
Adam Nemetdadfbb52016-01-27 22:21:25 +0000329unsigned TargetTransformInfo::getPrefetchDistance() const {
330 return TTIImpl->getPrefetchDistance();
331}
332
Adam Nemet6d8beec2016-03-18 00:27:38 +0000333unsigned TargetTransformInfo::getMinPrefetchStride() const {
334 return TTIImpl->getMinPrefetchStride();
335}
336
Adam Nemet709e3042016-03-18 00:27:43 +0000337unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
338 return TTIImpl->getMaxPrefetchIterationsAhead();
339}
340
Wei Mi062c7442015-05-06 17:12:25 +0000341unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
342 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000343}
344
Chandler Carruth93205eb2015-08-05 18:08:10 +0000345int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000346 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
347 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000348 OperandValueProperties Opd2PropInfo,
349 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000350 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000351 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000352 assert(Cost >= 0 && "TTI should not produce negative costs!");
353 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000354}
355
Chandler Carruth93205eb2015-08-05 18:08:10 +0000356int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
357 Type *SubTp) const {
358 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
359 assert(Cost >= 0 && "TTI should not produce negative costs!");
360 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000361}
362
Chandler Carruth93205eb2015-08-05 18:08:10 +0000363int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000364 Type *Src, const Instruction *I) const {
365 assert ((I == nullptr || I->getOpcode() == Opcode) &&
366 "Opcode should reflect passed instruction.");
367 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000368 assert(Cost >= 0 && "TTI should not produce negative costs!");
369 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000370}
371
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000372int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
373 VectorType *VecTy,
374 unsigned Index) const {
375 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
376 assert(Cost >= 0 && "TTI should not produce negative costs!");
377 return Cost;
378}
379
Chandler Carruth93205eb2015-08-05 18:08:10 +0000380int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
381 int Cost = TTIImpl->getCFInstrCost(Opcode);
382 assert(Cost >= 0 && "TTI should not produce negative costs!");
383 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000384}
385
Chandler Carruth93205eb2015-08-05 18:08:10 +0000386int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000387 Type *CondTy, const Instruction *I) const {
388 assert ((I == nullptr || I->getOpcode() == Opcode) &&
389 "Opcode should reflect passed instruction.");
390 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000391 assert(Cost >= 0 && "TTI should not produce negative costs!");
392 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000393}
394
Chandler Carruth93205eb2015-08-05 18:08:10 +0000395int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
396 unsigned Index) const {
397 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
398 assert(Cost >= 0 && "TTI should not produce negative costs!");
399 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000400}
401
Chandler Carruth93205eb2015-08-05 18:08:10 +0000402int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
403 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000404 unsigned AddressSpace,
405 const Instruction *I) const {
406 assert ((I == nullptr || I->getOpcode() == Opcode) &&
407 "Opcode should reflect passed instruction.");
408 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000409 assert(Cost >= 0 && "TTI should not produce negative costs!");
410 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000411}
412
Chandler Carruth93205eb2015-08-05 18:08:10 +0000413int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
414 unsigned Alignment,
415 unsigned AddressSpace) const {
416 int Cost =
417 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
418 assert(Cost >= 0 && "TTI should not produce negative costs!");
419 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000420}
421
Elena Demikhovsky54946982015-12-28 20:10:59 +0000422int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
423 Value *Ptr, bool VariableMask,
424 unsigned Alignment) const {
425 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
426 Alignment);
427 assert(Cost >= 0 && "TTI should not produce negative costs!");
428 return Cost;
429}
430
Chandler Carruth93205eb2015-08-05 18:08:10 +0000431int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000432 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
433 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000434 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
435 Alignment, AddressSpace);
436 assert(Cost >= 0 && "TTI should not produce negative costs!");
437 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000438}
439
Chandler Carruth93205eb2015-08-05 18:08:10 +0000440int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000441 ArrayRef<Type *> Tys, FastMathFlags FMF,
442 unsigned ScalarizationCostPassed) const {
443 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
444 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000445 assert(Cost >= 0 && "TTI should not produce negative costs!");
446 return Cost;
447}
448
Elena Demikhovsky54946982015-12-28 20:10:59 +0000449int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000450 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
451 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000452 assert(Cost >= 0 && "TTI should not produce negative costs!");
453 return Cost;
454}
455
Chandler Carruth93205eb2015-08-05 18:08:10 +0000456int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
457 ArrayRef<Type *> Tys) const {
458 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
459 assert(Cost >= 0 && "TTI should not produce negative costs!");
460 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000461}
462
Chandler Carruth539edf42013-01-05 11:43:11 +0000463unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000464 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000465}
466
Chandler Carruth93205eb2015-08-05 18:08:10 +0000467int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000468 ScalarEvolution *SE,
469 const SCEV *Ptr) const {
470 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000471 assert(Cost >= 0 && "TTI should not produce negative costs!");
472 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000473}
Chandler Carruth539edf42013-01-05 11:43:11 +0000474
Chandler Carruth93205eb2015-08-05 18:08:10 +0000475int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
476 bool IsPairwiseForm) const {
477 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
478 assert(Cost >= 0 && "TTI should not produce negative costs!");
479 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000480}
481
Chandler Carruth705b1852015-01-31 03:43:40 +0000482unsigned
483TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
484 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000485}
486
487bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
488 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000489 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000490}
491
Anna Thomasb2a212c2017-06-06 16:45:25 +0000492unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
493 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
494}
495
Chandler Carruth705b1852015-01-31 03:43:40 +0000496Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
497 IntrinsicInst *Inst, Type *ExpectedType) const {
498 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
499}
500
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000501Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
502 Value *Length,
503 unsigned SrcAlign,
504 unsigned DestAlign) const {
505 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
506 DestAlign);
507}
508
509void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
510 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
511 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
512 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
513 SrcAlign, DestAlign);
514}
515
516bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const {
517 return UseWideMemcpyLoopLowering;
518}
519
Eric Christopherd566fb12015-07-29 22:09:48 +0000520bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
521 const Function *Callee) const {
522 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000523}
524
Volkan Keles1c386812016-10-03 10:31:34 +0000525unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
526 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
527}
528
529bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
530 return TTIImpl->isLegalToVectorizeLoad(LI);
531}
532
533bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
534 return TTIImpl->isLegalToVectorizeStore(SI);
535}
536
537bool TargetTransformInfo::isLegalToVectorizeLoadChain(
538 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
539 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
540 AddrSpace);
541}
542
543bool TargetTransformInfo::isLegalToVectorizeStoreChain(
544 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
545 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
546 AddrSpace);
547}
548
549unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
550 unsigned LoadSize,
551 unsigned ChainSizeInBytes,
552 VectorType *VecTy) const {
553 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
554}
555
556unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
557 unsigned StoreSize,
558 unsigned ChainSizeInBytes,
559 VectorType *VecTy) const {
560 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
561}
562
Amara Emersoncf9daa32017-05-09 10:43:25 +0000563bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
564 Type *Ty, ReductionFlags Flags) const {
565 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
566}
567
Amara Emerson836b0f42017-05-10 09:42:49 +0000568bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
569 return TTIImpl->shouldExpandReduction(II);
570}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000571
Chandler Carruth705b1852015-01-31 03:43:40 +0000572TargetTransformInfo::Concept::~Concept() {}
573
Chandler Carruthe0385522015-02-01 10:11:22 +0000574TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
575
576TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000577 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000578 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000579
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000580TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000581 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000582 return TTICallback(F);
583}
584
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000585AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000586
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000587TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000588 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000589}
590
Chandler Carruth705b1852015-01-31 03:43:40 +0000591// Register the basic pass.
592INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
593 "Target Transform Information", false, true)
594char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000595
Chandler Carruth705b1852015-01-31 03:43:40 +0000596void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000597
Chandler Carruth705b1852015-01-31 03:43:40 +0000598TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000599 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000600 initializeTargetTransformInfoWrapperPassPass(
601 *PassRegistry::getPassRegistry());
602}
603
604TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000605 TargetIRAnalysis TIRA)
606 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000607 initializeTargetTransformInfoWrapperPassPass(
608 *PassRegistry::getPassRegistry());
609}
610
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000611TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000612 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000613 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000614 return *TTI;
615}
616
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000617ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000618llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
619 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000620}