blob: 427e1ed8ceb6f2feb028eb99560ef8ced44da956 [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
Chandler Carruth93205eb2015-08-05 18:08:10 +000069int TargetTransformInfo::getIntrinsicCost(
70 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const {
71 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments);
72 assert(Cost >= 0 && "TTI should not produce negative costs!");
73 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000074}
75
Chandler Carruth93205eb2015-08-05 18:08:10 +000076int TargetTransformInfo::getUserCost(const User *U) const {
77 int Cost = TTIImpl->getUserCost(U);
78 assert(Cost >= 0 && "TTI should not produce negative costs!");
79 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000080}
81
Tom Stellard8b1e0212013-07-27 00:01:07 +000082bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +000083 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +000084}
85
Jingyue Wu5da831c2015-04-10 05:03:50 +000086bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
87 return TTIImpl->isSourceOfDivergence(V);
88}
89
Chandler Carruth0ba8db42013-01-22 11:26:02 +000090bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +000091 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +000092}
93
Chandler Carruth705b1852015-01-31 03:43:40 +000094void TargetTransformInfo::getUnrollingPreferences(
Chandler Carruthab5cb362015-02-01 14:31:23 +000095 Loop *L, UnrollingPreferences &UP) const {
96 return TTIImpl->getUnrollingPreferences(L, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +000097}
98
Chandler Carruth539edf42013-01-05 11:43:11 +000099bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000100 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000101}
102
103bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000104 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000105}
106
107bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
108 int64_t BaseOffset,
109 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000110 int64_t Scale,
111 unsigned AddrSpace) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000112 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000113 Scale, AddrSpace);
Chandler Carruth539edf42013-01-05 11:43:11 +0000114}
115
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000116bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
117 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000118}
119
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000120bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
121 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000122}
123
Quentin Colombetbf490d42013-05-31 21:29:03 +0000124int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
125 int64_t BaseOffset,
126 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000127 int64_t Scale,
128 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000129 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
130 Scale, AddrSpace);
131 assert(Cost >= 0 && "TTI should not produce negative costs!");
132 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000133}
134
Chandler Carruth539edf42013-01-05 11:43:11 +0000135bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000136 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000137}
138
Sanjoy Dasc3182d82015-07-27 23:27:43 +0000139bool TargetTransformInfo::isZExtFree(Type *Ty1, Type *Ty2) const {
140 return TTIImpl->isZExtFree(Ty1, Ty2);
141}
142
Chad Rosier54390052015-02-23 19:15:16 +0000143bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
144 return TTIImpl->isProfitableToHoist(I);
145}
146
Chandler Carruth539edf42013-01-05 11:43:11 +0000147bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000148 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000149}
150
151unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000152 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000153}
154
155unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000156 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000157}
158
159bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000160 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000161}
162
Olivier Sallenave049d8032015-03-06 23:12:04 +0000163bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
164 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
165}
166
Silviu Baranga61bdc512015-08-10 14:50:54 +0000167bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
168 return TTIImpl->enableInterleavedAccessVectorization();
169}
170
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000171TargetTransformInfo::PopcntSupportKind
172TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000173 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000174}
175
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000176bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000177 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000178}
179
Chandler Carruth93205eb2015-08-05 18:08:10 +0000180int TargetTransformInfo::getFPOpCost(Type *Ty) const {
181 int Cost = TTIImpl->getFPOpCost(Ty);
182 assert(Cost >= 0 && "TTI should not produce negative costs!");
183 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000184}
185
Chandler Carruth93205eb2015-08-05 18:08:10 +0000186int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
187 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
188 assert(Cost >= 0 && "TTI should not produce negative costs!");
189 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000190}
191
Chandler Carruth93205eb2015-08-05 18:08:10 +0000192int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
193 const APInt &Imm, Type *Ty) const {
194 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
195 assert(Cost >= 0 && "TTI should not produce negative costs!");
196 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000197}
198
Chandler Carruth93205eb2015-08-05 18:08:10 +0000199int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
200 const APInt &Imm, Type *Ty) const {
201 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
202 assert(Cost >= 0 && "TTI should not produce negative costs!");
203 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000204}
205
Chandler Carruth539edf42013-01-05 11:43:11 +0000206unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000207 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000208}
209
Nadav Rotemb1791a72013-01-09 22:29:00 +0000210unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000211 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000212}
213
Wei Mi062c7442015-05-06 17:12:25 +0000214unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
215 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000216}
217
Chandler Carruth93205eb2015-08-05 18:08:10 +0000218int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000219 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
220 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Karthik Bhat7f33ff72014-08-25 04:56:54 +0000221 OperandValueProperties Opd2PropInfo) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000222 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
223 Opd1PropInfo, Opd2PropInfo);
224 assert(Cost >= 0 && "TTI should not produce negative costs!");
225 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000226}
227
Chandler Carruth93205eb2015-08-05 18:08:10 +0000228int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
229 Type *SubTp) const {
230 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
231 assert(Cost >= 0 && "TTI should not produce negative costs!");
232 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000233}
234
Chandler Carruth93205eb2015-08-05 18:08:10 +0000235int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
236 Type *Src) const {
237 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src);
238 assert(Cost >= 0 && "TTI should not produce negative costs!");
239 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000240}
241
Chandler Carruth93205eb2015-08-05 18:08:10 +0000242int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
243 int Cost = TTIImpl->getCFInstrCost(Opcode);
244 assert(Cost >= 0 && "TTI should not produce negative costs!");
245 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000246}
247
Chandler Carruth93205eb2015-08-05 18:08:10 +0000248int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
249 Type *CondTy) const {
250 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy);
251 assert(Cost >= 0 && "TTI should not produce negative costs!");
252 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000253}
254
Chandler Carruth93205eb2015-08-05 18:08:10 +0000255int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
256 unsigned Index) const {
257 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
258 assert(Cost >= 0 && "TTI should not produce negative costs!");
259 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000260}
261
Chandler Carruth93205eb2015-08-05 18:08:10 +0000262int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
263 unsigned Alignment,
264 unsigned AddressSpace) const {
265 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
266 assert(Cost >= 0 && "TTI should not produce negative costs!");
267 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000268}
269
Chandler Carruth93205eb2015-08-05 18:08:10 +0000270int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
271 unsigned Alignment,
272 unsigned AddressSpace) const {
273 int Cost =
274 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
275 assert(Cost >= 0 && "TTI should not produce negative costs!");
276 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000277}
278
Chandler Carruth93205eb2015-08-05 18:08:10 +0000279int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000280 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
281 unsigned Alignment, unsigned AddressSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000282 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
283 Alignment, AddressSpace);
284 assert(Cost >= 0 && "TTI should not produce negative costs!");
285 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000286}
287
Chandler Carruth93205eb2015-08-05 18:08:10 +0000288int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000289 ArrayRef<Type *> Tys) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000290 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys);
291 assert(Cost >= 0 && "TTI should not produce negative costs!");
292 return Cost;
293}
294
295int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
296 ArrayRef<Type *> Tys) const {
297 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
298 assert(Cost >= 0 && "TTI should not produce negative costs!");
299 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000300}
301
Chandler Carruth539edf42013-01-05 11:43:11 +0000302unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000303 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000304}
305
Chandler Carruth93205eb2015-08-05 18:08:10 +0000306int TargetTransformInfo::getAddressComputationCost(Type *Tp,
307 bool IsComplex) const {
308 int Cost = TTIImpl->getAddressComputationCost(Tp, IsComplex);
309 assert(Cost >= 0 && "TTI should not produce negative costs!");
310 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000311}
Chandler Carruth539edf42013-01-05 11:43:11 +0000312
Chandler Carruth93205eb2015-08-05 18:08:10 +0000313int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty,
314 bool IsPairwiseForm) const {
315 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm);
316 assert(Cost >= 0 && "TTI should not produce negative costs!");
317 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000318}
319
Chandler Carruth705b1852015-01-31 03:43:40 +0000320unsigned
321TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
322 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000323}
324
325bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
326 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000327 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000328}
329
Chandler Carruth705b1852015-01-31 03:43:40 +0000330Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
331 IntrinsicInst *Inst, Type *ExpectedType) const {
332 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
333}
334
Eric Christopherd566fb12015-07-29 22:09:48 +0000335bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
336 const Function *Callee) const {
337 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000338}
339
Chandler Carruth705b1852015-01-31 03:43:40 +0000340TargetTransformInfo::Concept::~Concept() {}
341
Chandler Carruthe0385522015-02-01 10:11:22 +0000342TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
343
344TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000345 std::function<Result(const Function &)> TTICallback)
Chandler Carruthe0385522015-02-01 10:11:22 +0000346 : TTICallback(TTICallback) {}
347
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000348TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F) {
Chandler Carruthe0385522015-02-01 10:11:22 +0000349 return TTICallback(F);
350}
351
352char TargetIRAnalysis::PassID;
353
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000354TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000355 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +0000356}
357
Chandler Carruth705b1852015-01-31 03:43:40 +0000358// Register the basic pass.
359INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
360 "Target Transform Information", false, true)
361char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +0000362
Chandler Carruth705b1852015-01-31 03:43:40 +0000363void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000364
Chandler Carruth705b1852015-01-31 03:43:40 +0000365TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000366 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000367 initializeTargetTransformInfoWrapperPassPass(
368 *PassRegistry::getPassRegistry());
369}
370
371TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000372 TargetIRAnalysis TIRA)
373 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +0000374 initializeTargetTransformInfoWrapperPassPass(
375 *PassRegistry::getPassRegistry());
376}
377
Eric Christophera4e5d3c2015-09-16 23:38:13 +0000378TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000379 TTI = TIRA.run(F);
380 return *TTI;
381}
382
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000383ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +0000384llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
385 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +0000386}