blob: c5793add30b1230602437584a6921a93c685a976 [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"
20
21using namespace llvm;
22
Chandler Carruthf1221bd2014-04-22 02:48:03 +000023#define DEBUG_TYPE "tti"
24
Chandler Carruth93dcdc42015-01-31 11:17:59 +000025namespace {
26/// \brief No-op implementation of the TTI interface using the utility base
27/// classes.
28///
29/// This is used when no target specific information is available.
30struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000031 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000032 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
33};
34}
35
Mehdi Amini5010ebf2015-07-09 02:08:42 +000036TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000037 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
38
Chandler Carruth705b1852015-01-31 03:43:40 +000039TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000040
Chandler Carruth705b1852015-01-31 03:43:40 +000041TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
42 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000043
Chandler Carruth705b1852015-01-31 03:43:40 +000044TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
45 TTIImpl = std::move(RHS.TTIImpl);
46 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000047}
48
Chandler Carruth93205eb2015-08-05 18:08:10 +000049int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
50 Type *OpTy) const {
51 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
52 assert(Cost >= 0 && "TTI should not produce negative costs!");
53 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000054}
55
Chandler Carruth93205eb2015-08-05 18:08:10 +000056int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const {
57 int Cost = TTIImpl->getCallCost(FTy, NumArgs);
58 assert(Cost >= 0 && "TTI should not produce negative costs!");
59 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000060}
61
Chandler Carruth93205eb2015-08-05 18:08:10 +000062int TargetTransformInfo::getCallCost(const Function *F,
63 ArrayRef<const Value *> Arguments) const {
64 int Cost = TTIImpl->getCallCost(F, Arguments);
65 assert(Cost >= 0 && "TTI should not produce negative costs!");
66 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000067}
68
Justin Lebar8650a4d2016-04-15 01:38:48 +000069unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
70 return TTIImpl->getInliningThresholdMultiplier();
71}
72
Chandler Carruth93205eb2015-08-05 18:08:10 +000073int TargetTransformInfo::getIntrinsicCost(
74 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
75 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
76 assert(Cost >= 0 && "TTI should not produce negative costs!");
77 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000078}
79
Chandler Carruth93205eb2015-08-05 18:08:10 +000080int TargetTransformInfo::getUserCost(const User *U) const {
81 int Cost = TTIImpl->getUserCost(U);
82 assert(Cost >= 0 && "TTI should not produce negative costs!");
83 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000084}
85
Tom Stellard8b1e0212013-07-27 00:01:07 +000086bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000087 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000088}
89
Jingyue Wu5da831c2015-04-10 05:03:50 +000090bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
91 return TTIImpl->isSourceOfDivergence(V);
92}
93
Chandler Carruth0ba8db42013-01-22 11:26:02 +000094bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +000095 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +000096}
97
Chandler Carruth705b1852015-01-31 03:43:40 +000098void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +000099 Loop *L, UnrollingPreferences &UP) const {
100 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000101}
102
Chandler Carruth539edf42013-01-05 11:43:11 +0000103bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000104 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000105}
106
107bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000108 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000109}
110
111bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
112 int64_t BaseOffset,
113 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000114 int64_t Scale,
115 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000116 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000117 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000118}
119
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000120bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
121 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000122}
123
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000124bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
125 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000126}
127
Elena Demikhovsky09285852015-10-25 15:37:55 +0000128bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
129 return TTIImpl->isLegalMaskedGather(DataType);
130}
131
132bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
133 return TTIImpl->isLegalMaskedGather(DataType);
134}
135
Quentin Colombetbf490d42013-05-31 21:29:03 +0000136int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
137 int64_t BaseOffset,
138 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000139 int64_t Scale,
140 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000141 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
142 Scale, AddrSpace);
143 assert(Cost >= 0 && "TTI should not produce negative costs!");
144 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000145}
146
Chandler Carruth539edf42013-01-05 11:43:11 +0000147bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000148 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000149}
150
Chad Rosier54390052015-02-23 19:15:16 +0000151bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
152 return TTIImpl->isProfitableToHoist(I);
153}
154
Chandler Carruth539edf42013-01-05 11:43:11 +0000155bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000156 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000157}
158
159unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000160 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000161}
162
163unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000164 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000165}
166
167bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000168 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000169}
170
Olivier Sallenave049d8032015-03-06 23:12:04 +0000171bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
172 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
173}
174
Silviu Baranga61bdc512015-08-10 14:50:54 +0000175bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
176 return TTIImpl->enableInterleavedAccessVectorization();
177}
178
Renato Golin5cb666a2016-04-14 20:42:18 +0000179bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
180 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
181}
182
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000183TargetTransformInfo::PopcntSupportKind
184TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000185 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000186}
187
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000188bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000189 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000190}
191
Chandler Carruth93205eb2015-08-05 18:08:10 +0000192int TargetTransformInfo::getFPOpCost(Type *Ty) const {
193 int Cost = TTIImpl->getFPOpCost(Ty);
194 assert(Cost >= 0 && "TTI should not produce negative costs!");
195 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000196}
197
Chandler Carruth93205eb2015-08-05 18:08:10 +0000198int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
199 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
200 assert(Cost >= 0 && "TTI should not produce negative costs!");
201 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000202}
203
Chandler Carruth93205eb2015-08-05 18:08:10 +0000204int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
205 const APInt &Imm, Type *Ty) const {
206 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
207 assert(Cost >= 0 && "TTI should not produce negative costs!");
208 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000209}
210
Chandler Carruth93205eb2015-08-05 18:08:10 +0000211int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
212 const APInt &Imm, Type *Ty) const {
213 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
214 assert(Cost >= 0 && "TTI should not produce negative costs!");
215 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000216}
217
Chandler Carruth539edf42013-01-05 11:43:11 +0000218unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000219 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000220}
221
Nadav Rotemb1791a72013-01-09 22:29:00 +0000222unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000223 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000224}
225
Adam Nemetaf761102016-01-21 18:28:36 +0000226unsigned TargetTransformInfo::getCacheLineSize() const {
227 return TTIImpl->getCacheLineSize();
228}
229
Adam Nemetdadfbb52016-01-27 22:21:25 +0000230unsigned TargetTransformInfo::getPrefetchDistance() const {
231 return TTIImpl->getPrefetchDistance();
232}
233
Adam Nemet6d8beec2016-03-18 00:27:38 +0000234unsigned TargetTransformInfo::getMinPrefetchStride() const {
235 return TTIImpl->getMinPrefetchStride();
236}
237
Adam Nemet709e3042016-03-18 00:27:43 +0000238unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
239 return TTIImpl->getMaxPrefetchIterationsAhead();
240}
241
Wei Mi062c7442015-05-06 17:12:25 +0000242unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
243 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000244}
245
Chandler Carruth93205eb2015-08-05 18:08:10 +0000246int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000247 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
248 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000249 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000250 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
251 Opd1PropInfo, Opd2PropInfo);
252 assert(Cost >= 0 && "TTI should not produce negative costs!");
253 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000254}
255
Chandler Carruth93205eb2015-08-05 18:08:10 +0000256int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
257 Type *SubTp) const {
258 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
259 assert(Cost >= 0 && "TTI should not produce negative costs!");
260 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000261}
262
Chandler Carruth93205eb2015-08-05 18:08:10 +0000263int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
264 Type *Src) const {
265 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
266 assert(Cost >= 0 && "TTI should not produce negative costs!");
267 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000268}
269
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000270int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
271 VectorType *VecTy,
272 unsigned Index) const {
273 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
274 assert(Cost >= 0 && "TTI should not produce negative costs!");
275 return Cost;
276}
277
Chandler Carruth93205eb2015-08-05 18:08:10 +0000278int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
279 int Cost = TTIImpl->getCFInstrCost(Opcode);
280 assert(Cost >= 0 && "TTI should not produce negative costs!");
281 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000282}
283
Chandler Carruth93205eb2015-08-05 18:08:10 +0000284int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
285 Type *CondTy) const {
286 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
287 assert(Cost >= 0 && "TTI should not produce negative costs!");
288 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000289}
290
Chandler Carruth93205eb2015-08-05 18:08:10 +0000291int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
292 unsigned Index) const {
293 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
294 assert(Cost >= 0 && "TTI should not produce negative costs!");
295 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000296}
297
Chandler Carruth93205eb2015-08-05 18:08:10 +0000298int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
299 unsigned Alignment,
300 unsigned AddressSpace) const {
301 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
302 assert(Cost >= 0 && "TTI should not produce negative costs!");
303 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000304}
305
Chandler Carruth93205eb2015-08-05 18:08:10 +0000306int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
307 unsigned Alignment,
308 unsigned AddressSpace) const {
309 int Cost =
310 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
311 assert(Cost >= 0 && "TTI should not produce negative costs!");
312 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000313}
314
Elena Demikhovsky54946982015-12-28 20:10:59 +0000315int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
316 Value *Ptr, bool VariableMask,
317 unsigned Alignment) const {
318 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
319 Alignment);
320 assert(Cost >= 0 && "TTI should not produce negative costs!");
321 return Cost;
322}
323
Chandler Carruth93205eb2015-08-05 18:08:10 +0000324int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000325 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
326 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000327 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
328 Alignment, AddressSpace);
329 assert(Cost >= 0 && "TTI should not produce negative costs!");
330 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000331}
332
Chandler Carruth93205eb2015-08-05 18:08:10 +0000333int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000334 ArrayRef<Type *> Tys,
335 FastMathFlags FMF) const {
336 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000337 assert(Cost >= 0 && "TTI should not produce negative costs!");
338 return Cost;
339}
340
Elena Demikhovsky54946982015-12-28 20:10:59 +0000341int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
David Majnemer0f26b0a2016-04-14 07:13:24 +0000342 ArrayRef<Value *> Args,
343 FastMathFlags FMF) const {
344 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000345 assert(Cost >= 0 && "TTI should not produce negative costs!");
346 return Cost;
347}
348
Chandler Carruth93205eb2015-08-05 18:08:10 +0000349int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
350 ArrayRef<Type *> Tys) const {
351 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
352 assert(Cost >= 0 && "TTI should not produce negative costs!");
353 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000354}
355
Chandler Carruth539edf42013-01-05 11:43:11 +0000356unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000357 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000358}
359
Chandler Carruth93205eb2015-08-05 18:08:10 +0000360int TargetTransformInfo::getAddressComputationCost(Type *Tp,
361 bool IsComplex) const {
362 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
363 assert(Cost >= 0 && "TTI should not produce negative costs!");
364 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000365}
Chandler Carruth539edf42013-01-05 11:43:11 +0000366
Chandler Carruth93205eb2015-08-05 18:08:10 +0000367int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
368 bool IsPairwiseForm) const {
369 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
370 assert(Cost >= 0 && "TTI should not produce negative costs!");
371 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000372}
373
Chandler Carruth705b1852015-01-31 03:43:40 +0000374unsigned
375TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
376 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000377}
378
379bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
380 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000381 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000382}
383
Chandler Carruth705b1852015-01-31 03:43:40 +0000384Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
385 IntrinsicInst *Inst, Type *ExpectedType) const {
386 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
387}
388
Eric Christopherd566fb12015-07-29 22:09:48 +0000389bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
390 const Function *Callee) const {
391 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000392}
393
Chandler Carruth705b1852015-01-31 03:43:40 +0000394TargetTransformInfo::Concept::~Concept() {}
395
Chandler Carruthe0385522015-02-01 10:11:22 +0000396TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
397
398TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000399 std::function<Result(const Function &)> TTICallback)
Chandler Carruthe0385522015-02-01 10:11:22 +0000400 : TTICallback(TTICallback) {}
401
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000402TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000403 return TTICallback(F);
404}
405
Chandler Carruthb4faf132016-03-11 10:22:49 +0000406char TargetIRAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +0000407
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000408TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000409 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000410}
411
Chandler Carruth705b1852015-01-31 03:43:40 +0000412// Register the basic pass.
413INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
414 "Target Transform Information", false, true)
415char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000416
Chandler Carruth705b1852015-01-31 03:43:40 +0000417void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000418
Chandler Carruth705b1852015-01-31 03:43:40 +0000419TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000420 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000421 initializeTargetTransformInfoWrapperPassPass(
422 *PassRegistry::getPassRegistry());
423}
424
425TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000426 TargetIRAnalysis TIRA)
427 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000428 initializeTargetTransformInfoWrapperPassPass(
429 *PassRegistry::getPassRegistry());
430}
431
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000432TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000433 TTI = TIRA.run(F);
434 return *TTI;
435}
436
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000437ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000438llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
439 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000440}