blob: 7a8d4f3be24fc0a9726a00b619fc69ebcf62d58d [file] [log] [blame]
Chandler Carruthd3e73552013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotem5dc203e2012-10-18 23:22:48 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chandler Carruthd3e73552013-01-07 03:08:10 +000010#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth705b1852015-01-31 03:43:40 +000011#include "llvm/Analysis/TargetTransformInfoImpl.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000012#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000015#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "llvm/IR/IntrinsicInst.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000017#include "llvm/IR/Module.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000018#include "llvm/IR/Operator.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000019#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000020#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000021
22using namespace llvm;
23
Chandler Carruthf1221bd2014-04-22 02:48:03 +000024#define DEBUG_TYPE "tti"
25
Chandler Carruth93dcdc42015-01-31 11:17:59 +000026namespace {
27/// \brief No-op implementation of the TTI interface using the utility base
28/// classes.
29///
30/// This is used when no target specific information is available.
31struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000032 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000033 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
34};
35}
36
Mehdi Amini5010ebf2015-07-09 02:08:42 +000037TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000038 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
39
Chandler Carruth705b1852015-01-31 03:43:40 +000040TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000041
Chandler Carruth705b1852015-01-31 03:43:40 +000042TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
43 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000044
Chandler Carruth705b1852015-01-31 03:43:40 +000045TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
46 TTIImpl = std::move(RHS.TTIImpl);
47 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000048}
49
Chandler Carruth93205eb2015-08-05 18:08:10 +000050int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
51 Type *OpTy) const {
52 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
53 assert(Cost >= 0 && "TTI should not produce negative costs!");
54 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000055}
56
Chandler Carruth93205eb2015-08-05 18:08:10 +000057int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
58 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
59 assert(Cost >= 0 && "TTI should not produce negative costs!");
60 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000061}
62
Chandler Carruth93205eb2015-08-05 18:08:10 +000063int TargetTransformInfo::getCallCost(const Function *F,
64 ArrayRef<const Value *> Arguments) const {
65 int Cost = TTIImpl->getCallCost(F, Arguments);
66 assert(Cost >= 0 && "TTI should not produce negative costs!");
67 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000068}
69
Justin Lebar8650a4d2016-04-15 01:38:48 +000070unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
71 return TTIImpl->getInliningThresholdMultiplier();
72}
73
Jingyue Wu15f3e822016-07-08 21:48:05 +000074int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
75 ArrayRef<const Value *> Operands) const {
76 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
77}
78
Chandler Carruth93205eb2015-08-05 18:08:10 +000079int TargetTransformInfo::getIntrinsicCost(
80 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
81 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
82 assert(Cost >= 0 && "TTI should not produce negative costs!");
83 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000084}
85
Jun Bum Lim919f9e82017-04-28 16:04:03 +000086unsigned
87TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
88 unsigned &JTSize) const {
89 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
90}
91
Chandler Carruth93205eb2015-08-05 18:08:10 +000092int TargetTransformInfo::getUserCost(const User *U) const {
93 int Cost = TTIImpl->getUserCost(U);
94 assert(Cost >= 0 && "TTI should not produce negative costs!");
95 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000096}
97
Tom Stellard8b1e0212013-07-27 00:01:07 +000098bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000099 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +0000100}
101
Jingyue Wu5da831c2015-04-10 05:03:50 +0000102bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
103 return TTIImpl->isSourceOfDivergence(V);
104}
105
Matt Arsenault42b64782017-01-30 23:02:12 +0000106unsigned TargetTransformInfo::getFlatAddressSpace() const {
107 return TTIImpl->getFlatAddressSpace();
108}
109
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000110bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000111 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000112}
113
Chandler Carruth705b1852015-01-31 03:43:40 +0000114void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +0000115 Loop *L, UnrollingPreferences &UP) const {
116 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000117}
118
Chandler Carruth539edf42013-01-05 11:43:11 +0000119bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000120 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000121}
122
123bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000124 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000125}
126
127bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
128 int64_t BaseOffset,
129 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000130 int64_t Scale,
131 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000132 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000133 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000134}
135
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000136bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
137 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000138}
139
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000140bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
141 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000142}
143
Elena Demikhovsky09285852015-10-25 15:37:55 +0000144bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
145 return TTIImpl->isLegalMaskedGather(DataType);
146}
147
148bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
149 return TTIImpl->isLegalMaskedGather(DataType);
150}
151
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000152bool TargetTransformInfo::prefersVectorizedAddressing() const {
153 return TTIImpl->prefersVectorizedAddressing();
154}
155
Quentin Colombetbf490d42013-05-31 21:29:03 +0000156int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
157 int64_t BaseOffset,
158 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000159 int64_t Scale,
160 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000161 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
162 Scale, AddrSpace);
163 assert(Cost >= 0 && "TTI should not produce negative costs!");
164 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000165}
166
Jonas Paulsson7a794222016-08-17 13:24:19 +0000167bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
168 int64_t Offset) const {
169 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
170}
171
Chandler Carruth539edf42013-01-05 11:43:11 +0000172bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000173 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000174}
175
Chad Rosier54390052015-02-23 19:15:16 +0000176bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
177 return TTIImpl->isProfitableToHoist(I);
178}
179
Chandler Carruth539edf42013-01-05 11:43:11 +0000180bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000181 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000182}
183
184unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000185 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000186}
187
188unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000189 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000190}
191
192bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000193 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000194}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000195bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
196 return TTIImpl->shouldBuildLookupTablesForConstant(C);
197}
Chandler Carruth539edf42013-01-05 11:43:11 +0000198
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000199unsigned TargetTransformInfo::
200getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
201 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
202}
203
204unsigned TargetTransformInfo::
205getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
206 unsigned VF) const {
207 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
208}
209
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000210bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
211 return TTIImpl->supportsEfficientVectorElementLoadStore();
212}
213
Olivier Sallenave049d8032015-03-06 23:12:04 +0000214bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
215 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
216}
217
Silviu Baranga61bdc512015-08-10 14:50:54 +0000218bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
219 return TTIImpl->enableInterleavedAccessVectorization();
220}
221
Renato Golin5cb666a2016-04-14 20:42:18 +0000222bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
223 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
224}
225
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000226bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
227 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000228 unsigned AddressSpace,
229 unsigned Alignment,
230 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000231 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000232 Alignment, Fast);
233}
234
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000235TargetTransformInfo::PopcntSupportKind
236TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000237 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000238}
239
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000240bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000241 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000242}
243
Chandler Carruth93205eb2015-08-05 18:08:10 +0000244int TargetTransformInfo::getFPOpCost(Type *Ty) const {
245 int Cost = TTIImpl->getFPOpCost(Ty);
246 assert(Cost >= 0 && "TTI should not produce negative costs!");
247 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000248}
249
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000250int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
251 const APInt &Imm,
252 Type *Ty) const {
253 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
254 assert(Cost >= 0 && "TTI should not produce negative costs!");
255 return Cost;
256}
257
Chandler Carruth93205eb2015-08-05 18:08:10 +0000258int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
259 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
260 assert(Cost >= 0 && "TTI should not produce negative costs!");
261 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000262}
263
Chandler Carruth93205eb2015-08-05 18:08:10 +0000264int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
265 const APInt &Imm, Type *Ty) const {
266 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
267 assert(Cost >= 0 && "TTI should not produce negative costs!");
268 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000269}
270
Chandler Carruth93205eb2015-08-05 18:08:10 +0000271int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
272 const APInt &Imm, Type *Ty) const {
273 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
274 assert(Cost >= 0 && "TTI should not produce negative costs!");
275 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000276}
277
Chandler Carruth539edf42013-01-05 11:43:11 +0000278unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000279 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000280}
281
Nadav Rotemb1791a72013-01-09 22:29:00 +0000282unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000283 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000284}
285
Adam Nemete29686e2017-05-15 21:15:01 +0000286unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
287 return TTIImpl->getMinVectorRegisterBitWidth();
288}
289
Jun Bum Limdee55652017-04-03 19:20:07 +0000290bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
291 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
292 return TTIImpl->shouldConsiderAddressTypePromotion(
293 I, AllowPromotionWithoutCommonHeader);
294}
295
Adam Nemetaf761102016-01-21 18:28:36 +0000296unsigned TargetTransformInfo::getCacheLineSize() const {
297 return TTIImpl->getCacheLineSize();
298}
299
Adam Nemetdadfbb52016-01-27 22:21:25 +0000300unsigned TargetTransformInfo::getPrefetchDistance() const {
301 return TTIImpl->getPrefetchDistance();
302}
303
Adam Nemet6d8beec2016-03-18 00:27:38 +0000304unsigned TargetTransformInfo::getMinPrefetchStride() const {
305 return TTIImpl->getMinPrefetchStride();
306}
307
Adam Nemet709e3042016-03-18 00:27:43 +0000308unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
309 return TTIImpl->getMaxPrefetchIterationsAhead();
310}
311
Wei Mi062c7442015-05-06 17:12:25 +0000312unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
313 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000314}
315
Chandler Carruth93205eb2015-08-05 18:08:10 +0000316int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000317 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
318 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000319 OperandValueProperties Opd2PropInfo,
320 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000321 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000322 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000323 assert(Cost >= 0 && "TTI should not produce negative costs!");
324 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000325}
326
Chandler Carruth93205eb2015-08-05 18:08:10 +0000327int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
328 Type *SubTp) const {
329 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
330 assert(Cost >= 0 && "TTI should not produce negative costs!");
331 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000332}
333
Chandler Carruth93205eb2015-08-05 18:08:10 +0000334int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000335 Type *Src, const Instruction *I) const {
336 assert ((I == nullptr || I->getOpcode() == Opcode) &&
337 "Opcode should reflect passed instruction.");
338 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000339 assert(Cost >= 0 && "TTI should not produce negative costs!");
340 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000341}
342
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000343int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
344 VectorType *VecTy,
345 unsigned Index) const {
346 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
349}
350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
352 int Cost = TTIImpl->getCFInstrCost(Opcode);
353 assert(Cost >= 0 && "TTI should not produce negative costs!");
354 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000355}
356
Chandler Carruth93205eb2015-08-05 18:08:10 +0000357int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000358 Type *CondTy, const Instruction *I) const {
359 assert ((I == nullptr || I->getOpcode() == Opcode) &&
360 "Opcode should reflect passed instruction.");
361 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000362 assert(Cost >= 0 && "TTI should not produce negative costs!");
363 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000364}
365
Chandler Carruth93205eb2015-08-05 18:08:10 +0000366int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
367 unsigned Index) const {
368 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
369 assert(Cost >= 0 && "TTI should not produce negative costs!");
370 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000371}
372
Chandler Carruth93205eb2015-08-05 18:08:10 +0000373int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
374 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000375 unsigned AddressSpace,
376 const Instruction *I) const {
377 assert ((I == nullptr || I->getOpcode() == Opcode) &&
378 "Opcode should reflect passed instruction.");
379 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000380 assert(Cost >= 0 && "TTI should not produce negative costs!");
381 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000382}
383
Chandler Carruth93205eb2015-08-05 18:08:10 +0000384int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
385 unsigned Alignment,
386 unsigned AddressSpace) const {
387 int Cost =
388 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
389 assert(Cost >= 0 && "TTI should not produce negative costs!");
390 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000391}
392
Elena Demikhovsky54946982015-12-28 20:10:59 +0000393int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
394 Value *Ptr, bool VariableMask,
395 unsigned Alignment) const {
396 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
397 Alignment);
398 assert(Cost >= 0 && "TTI should not produce negative costs!");
399 return Cost;
400}
401
Chandler Carruth93205eb2015-08-05 18:08:10 +0000402int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000403 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
404 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000405 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
406 Alignment, AddressSpace);
407 assert(Cost >= 0 && "TTI should not produce negative costs!");
408 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000409}
410
Chandler Carruth93205eb2015-08-05 18:08:10 +0000411int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000412 ArrayRef<Type *> Tys, FastMathFlags FMF,
413 unsigned ScalarizationCostPassed) const {
414 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
415 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000416 assert(Cost >= 0 && "TTI should not produce negative costs!");
417 return Cost;
418}
419
Elena Demikhovsky54946982015-12-28 20:10:59 +0000420int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000421 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
422 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000423 assert(Cost >= 0 && "TTI should not produce negative costs!");
424 return Cost;
425}
426
Chandler Carruth93205eb2015-08-05 18:08:10 +0000427int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
428 ArrayRef<Type *> Tys) const {
429 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
430 assert(Cost >= 0 && "TTI should not produce negative costs!");
431 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000432}
433
Chandler Carruth539edf42013-01-05 11:43:11 +0000434unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000435 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000436}
437
Chandler Carruth93205eb2015-08-05 18:08:10 +0000438int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000439 ScalarEvolution *SE,
440 const SCEV *Ptr) const {
441 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000442 assert(Cost >= 0 && "TTI should not produce negative costs!");
443 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000444}
Chandler Carruth539edf42013-01-05 11:43:11 +0000445
Chandler Carruth93205eb2015-08-05 18:08:10 +0000446int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
447 bool IsPairwiseForm) const {
448 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
449 assert(Cost >= 0 && "TTI should not produce negative costs!");
450 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000451}
452
Chandler Carruth705b1852015-01-31 03:43:40 +0000453unsigned
454TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
455 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000456}
457
458bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
459 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000460 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000461}
462
Chandler Carruth705b1852015-01-31 03:43:40 +0000463Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
464 IntrinsicInst *Inst, Type *ExpectedType) const {
465 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
466}
467
Eric Christopherd566fb12015-07-29 22:09:48 +0000468bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
469 const Function *Callee) const {
470 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000471}
472
Volkan Keles1c386812016-10-03 10:31:34 +0000473unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
474 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
475}
476
477bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
478 return TTIImpl->isLegalToVectorizeLoad(LI);
479}
480
481bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
482 return TTIImpl->isLegalToVectorizeStore(SI);
483}
484
485bool TargetTransformInfo::isLegalToVectorizeLoadChain(
486 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
487 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
488 AddrSpace);
489}
490
491bool TargetTransformInfo::isLegalToVectorizeStoreChain(
492 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
493 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
494 AddrSpace);
495}
496
497unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
498 unsigned LoadSize,
499 unsigned ChainSizeInBytes,
500 VectorType *VecTy) const {
501 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
502}
503
504unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
505 unsigned StoreSize,
506 unsigned ChainSizeInBytes,
507 VectorType *VecTy) const {
508 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
509}
510
Amara Emersoncf9daa32017-05-09 10:43:25 +0000511bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
512 Type *Ty, ReductionFlags Flags) const {
513 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
514}
515
Amara Emerson836b0f42017-05-10 09:42:49 +0000516bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
517 return TTIImpl->shouldExpandReduction(II);
518}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000519
Chandler Carruth705b1852015-01-31 03:43:40 +0000520TargetTransformInfo::Concept::~Concept() {}
521
Chandler Carruthe0385522015-02-01 10:11:22 +0000522TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
523
524TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000525 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000526 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000527
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000528TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000529 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000530 return TTICallback(F);
531}
532
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000533AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000534
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000535TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000536 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000537}
538
Chandler Carruth705b1852015-01-31 03:43:40 +0000539// Register the basic pass.
540INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
541 "Target Transform Information", false, true)
542char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000543
Chandler Carruth705b1852015-01-31 03:43:40 +0000544void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000545
Chandler Carruth705b1852015-01-31 03:43:40 +0000546TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000547 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000548 initializeTargetTransformInfoWrapperPassPass(
549 *PassRegistry::getPassRegistry());
550}
551
552TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000553 TargetIRAnalysis TIRA)
554 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000555 initializeTargetTransformInfoWrapperPassPass(
556 *PassRegistry::getPassRegistry());
557}
558
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000559TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000560 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000561 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000562 return *TTI;
563}
564
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000565ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000566llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
567 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000568}