blob: 52013f796c5606826c89952316d8594888f671c1 [file] [log] [blame]
Chandler Carruthbe049292013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotemcbd9a192012-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 Carruthbe049292013-01-07 03:08:10 +000010#include "llvm/Analysis/TargetTransformInfo.h"
Stephen Hinesebe69fe2015-03-23 12:10:34 -070011#include "llvm/Analysis/TargetTransformInfoImpl.h"
Stephen Hines36b56882014-04-23 16:57:46 -070012#include "llvm/IR/CallSite.h"
Chandler Carruth1e05bd92013-01-21 01:27:39 +000013#include "llvm/IR/DataLayout.h"
Chandler Carruth1e05bd92013-01-21 01:27:39 +000014#include "llvm/IR/Instruction.h"
Chandler Carruth1e05bd92013-01-21 01:27:39 +000015#include "llvm/IR/Instructions.h"
Stephen Hines36b56882014-04-23 16:57:46 -070016#include "llvm/IR/IntrinsicInst.h"
Stephen Hinesebe69fe2015-03-23 12:10:34 -070017#include "llvm/IR/Module.h"
Stephen Hines36b56882014-04-23 16:57:46 -070018#include "llvm/IR/Operator.h"
Nadav Rotemcbd9a192012-10-18 23:22:48 +000019#include "llvm/Support/ErrorHandling.h"
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -070020#include <utility>
Nadav Rotemcbd9a192012-10-18 23:22:48 +000021
22using namespace llvm;
23
Stephen Hinesdce4a402014-05-29 02:49:00 -070024#define DEBUG_TYPE "tti"
25
Stephen Hinesebe69fe2015-03-23 12:10:34 -070026namespace {
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> {
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080032 explicit NoTTIImpl(const DataLayout &DL)
Stephen Hinesebe69fe2015-03-23 12:10:34 -070033 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
34};
Chandler Carruth7bdf6b02013-01-05 11:43:11 +000035}
36
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080037TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Stephen Hinesebe69fe2015-03-23 12:10:34 -070038 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
Chandler Carruthaeef83c2013-01-07 01:37:14 +000039
Stephen Hinesebe69fe2015-03-23 12:10:34 -070040TargetTransformInfo::~TargetTransformInfo() {}
Chandler Carruthaeef83c2013-01-07 01:37:14 +000041
Stephen Hinesebe69fe2015-03-23 12:10:34 -070042TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
43 : TTIImpl(std::move(Arg.TTIImpl)) {}
44
45TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
46 TTIImpl = std::move(RHS.TTIImpl);
47 return *this;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +000048}
49
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080050int 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 Carruth1e05bd92013-01-21 01:27:39 +000055}
56
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080057int 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 Carruth13086a62013-01-22 11:26:02 +000061}
62
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080063int 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 Carruth13086a62013-01-22 11:26:02 +000068}
69
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -070070unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
71 return TTIImpl->getInliningThresholdMultiplier();
72}
73
74int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
75 ArrayRef<const Value *> Operands) const {
76 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
77}
78
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080079int 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 Carruth13086a62013-01-22 11:26:02 +000084}
85
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -080086int 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 Carruth1e05bd92013-01-21 01:27:39 +000090}
91
Tom Stellard57e6b2d2013-07-27 00:01:07 +000092bool TargetTransformInfo::hasBranchDivergence() const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -070093 return TTIImpl->hasBranchDivergence();
Tom Stellard57e6b2d2013-07-27 00:01:07 +000094}
95
Pirama Arumuga Nainar0c7f1162015-05-06 11:46:36 -070096bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
97 return TTIImpl->isSourceOfDivergence(V);
98}
99
Chandler Carruth13086a62013-01-22 11:26:02 +0000100bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700101 return TTIImpl->isLoweredToCall(F);
Chandler Carruth13086a62013-01-22 11:26:02 +0000102}
103
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700104void TargetTransformInfo::getUnrollingPreferences(
105 Loop *L, UnrollingPreferences &UP) const {
106 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel4f7e2c32013-09-11 19:25:43 +0000107}
108
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000109bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700110 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000111}
112
113bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700114 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000115}
116
117bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
118 int64_t BaseOffset,
119 bool HasBaseReg,
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700120 int64_t Scale,
121 unsigned AddrSpace) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700122 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700123 Scale, AddrSpace);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000124}
125
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800126bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
127 return TTIImpl->isLegalMaskedStore(DataType);
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700128}
129
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800130bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
131 return TTIImpl->isLegalMaskedLoad(DataType);
132}
133
134bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
135 return TTIImpl->isLegalMaskedGather(DataType);
136}
137
138bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
139 return TTIImpl->isLegalMaskedGather(DataType);
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700140}
141
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000142int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
143 int64_t BaseOffset,
144 bool HasBaseReg,
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700145 int64_t Scale,
146 unsigned AddrSpace) const {
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800147 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
148 Scale, AddrSpace);
149 assert(Cost >= 0 && "TTI should not produce negative costs!");
150 return Cost;
Quentin Colombet06f5ebc2013-05-31 21:29:03 +0000151}
152
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000153bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700154 return TTIImpl->isTruncateFree(Ty1, Ty2);
155}
156
157bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
158 return TTIImpl->isProfitableToHoist(I);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000159}
160
161bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700162 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000163}
164
165unsigned TargetTransformInfo::getJumpBufAlignment() const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700166 return TTIImpl->getJumpBufAlignment();
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000167}
168
169unsigned TargetTransformInfo::getJumpBufSize() const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700170 return TTIImpl->getJumpBufSize();
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000171}
172
173bool TargetTransformInfo::shouldBuildLookupTables() const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700174 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000175}
176
Pirama Arumuga Nainar4c5e43d2015-04-08 08:55:49 -0700177bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
178 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
179}
180
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800181bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
182 return TTIImpl->enableInterleavedAccessVectorization();
183}
184
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700185bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
186 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
187}
188
189bool TargetTransformInfo::allowsMisalignedMemoryAccesses(unsigned BitWidth,
190 unsigned AddressSpace,
191 unsigned Alignment,
192 bool *Fast) const {
193 return TTIImpl->allowsMisalignedMemoryAccesses(BitWidth, AddressSpace,
194 Alignment, Fast);
195}
196
Chandler Carruthd1b8ef92013-01-07 03:16:03 +0000197TargetTransformInfo::PopcntSupportKind
198TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700199 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000200}
201
Richard Sandiforda8a70992013-08-23 10:27:02 +0000202bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700203 return TTIImpl->haveFastSqrt(Ty);
204}
205
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800206int TargetTransformInfo::getFPOpCost(Type *Ty) const {
207 int Cost = TTIImpl->getFPOpCost(Ty);
208 assert(Cost >= 0 && "TTI should not produce negative costs!");
209 return Cost;
Richard Sandiforda8a70992013-08-23 10:27:02 +0000210}
211
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700212int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
213 const APInt &Imm,
214 Type *Ty) const {
215 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
216 assert(Cost >= 0 && "TTI should not produce negative costs!");
217 return Cost;
218}
219
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800220int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
221 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
222 assert(Cost >= 0 && "TTI should not produce negative costs!");
223 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000224}
225
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800226int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
227 const APInt &Imm, Type *Ty) const {
228 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
229 assert(Cost >= 0 && "TTI should not produce negative costs!");
230 return Cost;
Stephen Hines36b56882014-04-23 16:57:46 -0700231}
232
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800233int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
234 const APInt &Imm, Type *Ty) const {
235 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
236 assert(Cost >= 0 && "TTI should not produce negative costs!");
237 return Cost;
Stephen Hines36b56882014-04-23 16:57:46 -0700238}
239
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000240unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700241 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000242}
243
Nadav Rotem14925e62013-01-09 22:29:00 +0000244unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700245 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotem14925e62013-01-09 22:29:00 +0000246}
247
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700248unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
249 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
250}
251
252unsigned TargetTransformInfo::getCacheLineSize() const {
253 return TTIImpl->getCacheLineSize();
254}
255
256unsigned TargetTransformInfo::getPrefetchDistance() const {
257 return TTIImpl->getPrefetchDistance();
258}
259
260unsigned TargetTransformInfo::getMinPrefetchStride() const {
261 return TTIImpl->getMinPrefetchStride();
262}
263
264unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
265 return TTIImpl->getMaxPrefetchIterationsAhead();
266}
267
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700268unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
269 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotem83be7b02013-01-09 01:15:42 +0000270}
271
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800272int TargetTransformInfo::getArithmeticInstrCost(
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700273 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
274 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Stephen Hines37ed9c12014-12-01 14:51:49 -0800275 OperandValueProperties Opd2PropInfo) const {
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800276 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
277 Opd1PropInfo, Opd2PropInfo);
278 assert(Cost >= 0 && "TTI should not produce negative costs!");
279 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000280}
281
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800282int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
283 Type *SubTp) const {
284 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
285 assert(Cost >= 0 && "TTI should not produce negative costs!");
286 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000287}
288
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800289int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
290 Type *Src) const {
291 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
292 assert(Cost >= 0 && "TTI should not produce negative costs!");
293 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000294}
295
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700296int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
297 VectorType *VecTy,
298 unsigned Index) const {
299 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
300 assert(Cost >= 0 && "TTI should not produce negative costs!");
301 return Cost;
302}
303
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800304int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
305 int Cost = TTIImpl->getCFInstrCost(Opcode);
306 assert(Cost >= 0 && "TTI should not produce negative costs!");
307 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000308}
309
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800310int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
311 Type *CondTy) const {
312 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
313 assert(Cost >= 0 && "TTI should not produce negative costs!");
314 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000315}
316
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800317int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
318 unsigned Index) const {
319 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
320 assert(Cost >= 0 && "TTI should not produce negative costs!");
321 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000322}
323
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800324int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
325 unsigned Alignment,
326 unsigned AddressSpace) const {
327 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
328 assert(Cost >= 0 && "TTI should not produce negative costs!");
329 return Cost;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000330}
331
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800332int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
333 unsigned Alignment,
334 unsigned AddressSpace) const {
335 int Cost =
336 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
337 assert(Cost >= 0 && "TTI should not produce negative costs!");
338 return Cost;
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700339}
340
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700341int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
342 Value *Ptr, bool VariableMask,
343 unsigned Alignment) const {
344 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
345 Alignment);
346 assert(Cost >= 0 && "TTI should not produce negative costs!");
347 return Cost;
348}
349
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800350int TargetTransformInfo::getInterleavedMemoryOpCost(
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700351 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
352 unsigned Alignment, unsigned AddressSpace) const {
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800353 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
354 Alignment, AddressSpace);
355 assert(Cost >= 0 && "TTI should not produce negative costs!");
356 return Cost;
Pirama Arumuga Nainar69488972015-07-01 12:23:51 -0700357}
358
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800359int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700360 ArrayRef<Type *> Tys,
361 FastMathFlags FMF) const {
362 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
363 assert(Cost >= 0 && "TTI should not produce negative costs!");
364 return Cost;
365}
366
367int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
368 ArrayRef<Value *> Args,
369 FastMathFlags FMF) const {
370 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800371 assert(Cost >= 0 && "TTI should not produce negative costs!");
372 return Cost;
373}
374
375int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
376 ArrayRef<Type *> Tys) const {
377 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
378 assert(Cost >= 0 && "TTI should not produce negative costs!");
379 return Cost;
Pirama Arumuga Nainar4c5e43d2015-04-08 08:55:49 -0700380}
381
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000382unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700383 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000384}
385
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800386int TargetTransformInfo::getAddressComputationCost(Type *Tp,
387 bool IsComplex) const {
388 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
389 assert(Cost >= 0 && "TTI should not produce negative costs!");
390 return Cost;
Arnold Schwaighoferfb55a8f2013-02-08 14:50:48 +0000391}
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000392
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800393int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
394 bool IsPairwiseForm) const {
395 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
396 assert(Cost >= 0 && "TTI should not produce negative costs!");
397 return Cost;
Arnold Schwaighofer65457b62013-09-17 18:06:50 +0000398}
399
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700400unsigned
401TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
402 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Stephen Hines37ed9c12014-12-01 14:51:49 -0800403}
404
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700405bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
406 MemIntrinsicInfo &Info) const {
407 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
408}
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000409
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700410Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
411 IntrinsicInst *Inst, Type *ExpectedType) const {
412 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
413}
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000414
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800415bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
416 const Function *Callee) const {
417 return TTIImpl->areInlineCompatible(Caller, Callee);
418}
419
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700420TargetTransformInfo::Concept::~Concept() {}
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000421
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700422TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
Chandler Carruthaeef83c2013-01-07 01:37:14 +0000423
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700424TargetIRAnalysis::TargetIRAnalysis(
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800425 std::function<Result(const Function &)> TTICallback)
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700426 : TTICallback(std::move(TTICallback)) {}
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000427
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700428TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
429 AnalysisManager<Function> &) {
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700430 return TTICallback(F);
431}
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000432
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700433char TargetIRAnalysis::PassID;
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000434
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800435TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
436 return Result(F.getParent()->getDataLayout());
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700437}
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000438
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700439// Register the basic pass.
440INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
441 "Target Transform Information", false, true)
442char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000443
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700444void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000445
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700446TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
447 : ImmutablePass(ID) {
448 initializeTargetTransformInfoWrapperPassPass(
449 *PassRegistry::getPassRegistry());
450}
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000451
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700452TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
453 TargetIRAnalysis TIRA)
454 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
455 initializeTargetTransformInfoWrapperPassPass(
456 *PassRegistry::getPassRegistry());
457}
Matt Arsenaultf9355c82013-08-28 22:41:57 +0000458
Pirama Arumuga Nainarf3ef5332016-03-03 15:48:50 -0800459TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Pirama Arumuga Nainarde2d8692016-09-19 22:57:26 -0700460 AnalysisManager<Function> DummyFAM;
461 TTI = TIRA.run(F, DummyFAM);
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700462 return *TTI;
463}
Chandler Carruth1e05bd92013-01-21 01:27:39 +0000464
Stephen Hinesebe69fe2015-03-23 12:10:34 -0700465ImmutablePass *
466llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
467 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth7bdf6b02013-01-05 11:43:11 +0000468}