blob: c8b8740bd852327268be148a4b4cfc5e55038aa5 [file] [log] [blame]
Chandler Carruthd3e73552013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotem5dc203e2012-10-18 23:22:48 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chandler Carruthd3e73552013-01-07 03:08:10 +000010#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth705b1852015-01-31 03:43:40 +000011#include "llvm/Analysis/TargetTransformInfoImpl.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000012#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000015#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "llvm/IR/IntrinsicInst.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000017#include "llvm/IR/Module.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000018#include "llvm/IR/Operator.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000019#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000020#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000021
22using namespace llvm;
23
Chandler Carruthf1221bd2014-04-22 02:48:03 +000024#define DEBUG_TYPE "tti"
25
Chandler Carruth93dcdc42015-01-31 11:17:59 +000026namespace {
27/// \brief No-op implementation of the TTI interface using the utility base
28/// classes.
29///
30/// This is used when no target specific information is available.
31struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000032 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000033 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
34};
35}
36
Mehdi Amini5010ebf2015-07-09 02:08:42 +000037TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000038 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
39
Chandler Carruth705b1852015-01-31 03:43:40 +000040TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000041
Chandler Carruth705b1852015-01-31 03:43:40 +000042TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
43 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000044
Chandler Carruth705b1852015-01-31 03:43:40 +000045TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
46 TTIImpl = std::move(RHS.TTIImpl);
47 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000048}
49
Chandler Carruth93205eb2015-08-05 18:08:10 +000050int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
51 Type *OpTy) const {
52 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
53 assert(Cost >= 0 && "TTI should not produce negative costs!");
54 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000055}
56
Chandler Carruth93205eb2015-08-05 18:08:10 +000057int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
58 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
59 assert(Cost >= 0 && "TTI should not produce negative costs!");
60 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000061}
62
Chandler Carruth93205eb2015-08-05 18:08:10 +000063int TargetTransformInfo::getCallCost(const Function *F,
64 ArrayRef<const Value *> Arguments) const {
65 int Cost = TTIImpl->getCallCost(F, Arguments);
66 assert(Cost >= 0 && "TTI should not produce negative costs!");
67 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000068}
69
Justin Lebar8650a4d2016-04-15 01:38:48 +000070unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
71 return TTIImpl->getInliningThresholdMultiplier();
72}
73
Jingyue Wu15f3e822016-07-08 21:48:05 +000074int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
75 ArrayRef<const Value *> Operands) const {
76 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
77}
78
Chandler Carruth93205eb2015-08-05 18:08:10 +000079int TargetTransformInfo::getIntrinsicCost(
80 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
81 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
82 assert(Cost >= 0 && "TTI should not produce negative costs!");
83 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000084}
85
Chandler Carruth93205eb2015-08-05 18:08:10 +000086int TargetTransformInfo::getUserCost(const User *U) const {
87 int Cost = TTIImpl->getUserCost(U);
88 assert(Cost >= 0 && "TTI should not produce negative costs!");
89 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000090}
91
Tom Stellard8b1e0212013-07-27 00:01:07 +000092bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000093 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000094}
95
Jingyue Wu5da831c2015-04-10 05:03:50 +000096bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
97 return TTIImpl->isSourceOfDivergence(V);
98}
99
Matt Arsenault42b64782017-01-30 23:02:12 +0000100unsigned TargetTransformInfo::getFlatAddressSpace() const {
101 return TTIImpl->getFlatAddressSpace();
102}
103
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000104bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000105 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000106}
107
Chandler Carruth705b1852015-01-31 03:43:40 +0000108void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +0000109 Loop *L, UnrollingPreferences &UP) const {
110 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000111}
112
Chandler Carruth539edf42013-01-05 11:43:11 +0000113bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000114 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000115}
116
117bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000118 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000119}
120
121bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
122 int64_t BaseOffset,
123 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000124 int64_t Scale,
125 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000126 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000127 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000128}
129
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000130bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
131 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000132}
133
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000134bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
135 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000136}
137
Elena Demikhovsky09285852015-10-25 15:37:55 +0000138bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
139 return TTIImpl->isLegalMaskedGather(DataType);
140}
141
142bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
143 return TTIImpl->isLegalMaskedGather(DataType);
144}
145
Quentin Colombetbf490d42013-05-31 21:29:03 +0000146int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
147 int64_t BaseOffset,
148 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000149 int64_t Scale,
150 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000151 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
152 Scale, AddrSpace);
153 assert(Cost >= 0 && "TTI should not produce negative costs!");
154 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000155}
156
Jonas Paulsson7a794222016-08-17 13:24:19 +0000157bool TargetTransformInfo::isFoldableMemAccessOffset(Instruction *I,
158 int64_t Offset) const {
159 return TTIImpl->isFoldableMemAccessOffset(I, Offset);
160}
161
Chandler Carruth539edf42013-01-05 11:43:11 +0000162bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000163 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000164}
165
Chad Rosier54390052015-02-23 19:15:16 +0000166bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
167 return TTIImpl->isProfitableToHoist(I);
168}
169
Chandler Carruth539edf42013-01-05 11:43:11 +0000170bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000171 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000172}
173
174unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000175 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000176}
177
178unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000179 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000180}
181
182bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000183 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000184}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000185bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
186 return TTIImpl->shouldBuildLookupTablesForConstant(C);
187}
Chandler Carruth539edf42013-01-05 11:43:11 +0000188
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000189unsigned TargetTransformInfo::
190getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
191 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
192}
193
194unsigned TargetTransformInfo::
195getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
196 unsigned VF) const {
197 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
198}
199
Olivier Sallenave049d8032015-03-06 23:12:04 +0000200bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
201 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
202}
203
Silviu Baranga61bdc512015-08-10 14:50:54 +0000204bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
205 return TTIImpl->enableInterleavedAccessVectorization();
206}
207
Renato Golin5cb666a2016-04-14 20:42:18 +0000208bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
209 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
210}
211
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000212bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
213 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000214 unsigned AddressSpace,
215 unsigned Alignment,
216 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000217 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000218 Alignment, Fast);
219}
220
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000221TargetTransformInfo::PopcntSupportKind
222TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000223 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000224}
225
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000226bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000227 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000228}
229
Chandler Carruth93205eb2015-08-05 18:08:10 +0000230int TargetTransformInfo::getFPOpCost(Type *Ty) const {
231 int Cost = TTIImpl->getFPOpCost(Ty);
232 assert(Cost >= 0 && "TTI should not produce negative costs!");
233 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000234}
235
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000236int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
237 const APInt &Imm,
238 Type *Ty) const {
239 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
240 assert(Cost >= 0 && "TTI should not produce negative costs!");
241 return Cost;
242}
243
Chandler Carruth93205eb2015-08-05 18:08:10 +0000244int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
245 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
246 assert(Cost >= 0 && "TTI should not produce negative costs!");
247 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000248}
249
Chandler Carruth93205eb2015-08-05 18:08:10 +0000250int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
251 const APInt &Imm, Type *Ty) const {
252 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
253 assert(Cost >= 0 && "TTI should not produce negative costs!");
254 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000255}
256
Chandler Carruth93205eb2015-08-05 18:08:10 +0000257int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
258 const APInt &Imm, Type *Ty) const {
259 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
260 assert(Cost >= 0 && "TTI should not produce negative costs!");
261 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000262}
263
Chandler Carruth539edf42013-01-05 11:43:11 +0000264unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000265 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000266}
267
Nadav Rotemb1791a72013-01-09 22:29:00 +0000268unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000269 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000270}
271
Jun Bum Limdee55652017-04-03 19:20:07 +0000272bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
273 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
274 return TTIImpl->shouldConsiderAddressTypePromotion(
275 I, AllowPromotionWithoutCommonHeader);
276}
277
Adam Nemetaf761102016-01-21 18:28:36 +0000278unsigned TargetTransformInfo::getCacheLineSize() const {
279 return TTIImpl->getCacheLineSize();
280}
281
Adam Nemetdadfbb52016-01-27 22:21:25 +0000282unsigned TargetTransformInfo::getPrefetchDistance() const {
283 return TTIImpl->getPrefetchDistance();
284}
285
Adam Nemet6d8beec2016-03-18 00:27:38 +0000286unsigned TargetTransformInfo::getMinPrefetchStride() const {
287 return TTIImpl->getMinPrefetchStride();
288}
289
Adam Nemet709e3042016-03-18 00:27:43 +0000290unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
291 return TTIImpl->getMaxPrefetchIterationsAhead();
292}
293
Wei Mi062c7442015-05-06 17:12:25 +0000294unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
295 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000296}
297
Chandler Carruth93205eb2015-08-05 18:08:10 +0000298int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000299 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
300 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000301 OperandValueProperties Opd2PropInfo,
302 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000303 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000304 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000305 assert(Cost >= 0 && "TTI should not produce negative costs!");
306 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000307}
308
Chandler Carruth93205eb2015-08-05 18:08:10 +0000309int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
310 Type *SubTp) const {
311 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
312 assert(Cost >= 0 && "TTI should not produce negative costs!");
313 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000314}
315
Chandler Carruth93205eb2015-08-05 18:08:10 +0000316int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000317 Type *Src, const Instruction *I) const {
318 assert ((I == nullptr || I->getOpcode() == Opcode) &&
319 "Opcode should reflect passed instruction.");
320 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000321 assert(Cost >= 0 && "TTI should not produce negative costs!");
322 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000323}
324
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000325int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
326 VectorType *VecTy,
327 unsigned Index) const {
328 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
329 assert(Cost >= 0 && "TTI should not produce negative costs!");
330 return Cost;
331}
332
Chandler Carruth93205eb2015-08-05 18:08:10 +0000333int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
334 int Cost = TTIImpl->getCFInstrCost(Opcode);
335 assert(Cost >= 0 && "TTI should not produce negative costs!");
336 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000337}
338
Chandler Carruth93205eb2015-08-05 18:08:10 +0000339int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000340 Type *CondTy, const Instruction *I) const {
341 assert ((I == nullptr || I->getOpcode() == Opcode) &&
342 "Opcode should reflect passed instruction.");
343 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000344 assert(Cost >= 0 && "TTI should not produce negative costs!");
345 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000346}
347
Chandler Carruth93205eb2015-08-05 18:08:10 +0000348int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
349 unsigned Index) const {
350 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
351 assert(Cost >= 0 && "TTI should not produce negative costs!");
352 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000353}
354
Chandler Carruth93205eb2015-08-05 18:08:10 +0000355int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
356 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000357 unsigned AddressSpace,
358 const Instruction *I) const {
359 assert ((I == nullptr || I->getOpcode() == Opcode) &&
360 "Opcode should reflect passed instruction.");
361 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000362 assert(Cost >= 0 && "TTI should not produce negative costs!");
363 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000364}
365
Chandler Carruth93205eb2015-08-05 18:08:10 +0000366int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
367 unsigned Alignment,
368 unsigned AddressSpace) const {
369 int Cost =
370 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
371 assert(Cost >= 0 && "TTI should not produce negative costs!");
372 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000373}
374
Elena Demikhovsky54946982015-12-28 20:10:59 +0000375int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
376 Value *Ptr, bool VariableMask,
377 unsigned Alignment) const {
378 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
379 Alignment);
380 assert(Cost >= 0 && "TTI should not produce negative costs!");
381 return Cost;
382}
383
Chandler Carruth93205eb2015-08-05 18:08:10 +0000384int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000385 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
386 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000387 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
388 Alignment, AddressSpace);
389 assert(Cost >= 0 && "TTI should not produce negative costs!");
390 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000391}
392
Chandler Carruth93205eb2015-08-05 18:08:10 +0000393int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000394 ArrayRef<Type *> Tys, FastMathFlags FMF,
395 unsigned ScalarizationCostPassed) const {
396 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
397 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000398 assert(Cost >= 0 && "TTI should not produce negative costs!");
399 return Cost;
400}
401
Elena Demikhovsky54946982015-12-28 20:10:59 +0000402int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000403 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
404 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000405 assert(Cost >= 0 && "TTI should not produce negative costs!");
406 return Cost;
407}
408
Chandler Carruth93205eb2015-08-05 18:08:10 +0000409int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
410 ArrayRef<Type *> Tys) const {
411 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
412 assert(Cost >= 0 && "TTI should not produce negative costs!");
413 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000414}
415
Chandler Carruth539edf42013-01-05 11:43:11 +0000416unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000417 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000418}
419
Chandler Carruth93205eb2015-08-05 18:08:10 +0000420int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000421 ScalarEvolution *SE,
422 const SCEV *Ptr) const {
423 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000424 assert(Cost >= 0 && "TTI should not produce negative costs!");
425 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000426}
Chandler Carruth539edf42013-01-05 11:43:11 +0000427
Chandler Carruth93205eb2015-08-05 18:08:10 +0000428int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
429 bool IsPairwiseForm) const {
430 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
431 assert(Cost >= 0 && "TTI should not produce negative costs!");
432 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000433}
434
Chandler Carruth705b1852015-01-31 03:43:40 +0000435unsigned
436TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
437 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000438}
439
440bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
441 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000442 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000443}
444
Chandler Carruth705b1852015-01-31 03:43:40 +0000445Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
446 IntrinsicInst *Inst, Type *ExpectedType) const {
447 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
448}
449
Eric Christopherd566fb12015-07-29 22:09:48 +0000450bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
451 const Function *Callee) const {
452 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000453}
454
Volkan Keles1c386812016-10-03 10:31:34 +0000455unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
456 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
457}
458
459bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
460 return TTIImpl->isLegalToVectorizeLoad(LI);
461}
462
463bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
464 return TTIImpl->isLegalToVectorizeStore(SI);
465}
466
467bool TargetTransformInfo::isLegalToVectorizeLoadChain(
468 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
469 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
470 AddrSpace);
471}
472
473bool TargetTransformInfo::isLegalToVectorizeStoreChain(
474 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
475 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
476 AddrSpace);
477}
478
479unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
480 unsigned LoadSize,
481 unsigned ChainSizeInBytes,
482 VectorType *VecTy) const {
483 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
484}
485
486unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
487 unsigned StoreSize,
488 unsigned ChainSizeInBytes,
489 VectorType *VecTy) const {
490 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
491}
492
Chandler Carruth705b1852015-01-31 03:43:40 +0000493TargetTransformInfo::Concept::~Concept() {}
494
Chandler Carruthe0385522015-02-01 10:11:22 +0000495TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
496
497TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000498 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000499 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +0000500
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000501TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +0000502 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000503 return TTICallback(F);
504}
505
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000506AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000507
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000508TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000509 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000510}
511
Chandler Carruth705b1852015-01-31 03:43:40 +0000512// Register the basic pass.
513INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
514 "Target Transform Information", false, true)
515char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000516
Chandler Carruth705b1852015-01-31 03:43:40 +0000517void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000518
Chandler Carruth705b1852015-01-31 03:43:40 +0000519TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000520 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000521 initializeTargetTransformInfoWrapperPassPass(
522 *PassRegistry::getPassRegistry());
523}
524
525TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000526 TargetIRAnalysis TIRA)
527 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000528 initializeTargetTransformInfoWrapperPassPass(
529 *PassRegistry::getPassRegistry());
530}
531
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000532TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +0000533 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000534 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000535 return *TTI;
536}
537
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000538ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000539llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
540 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000541}