blob: 763b68418787d2d20fb7f14e7e9ee2cc59bdce2f [file] [log] [blame]
Chandler Carruthd3e73552013-01-07 03:08:10 +00001//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
Nadav Rotem5dc203e2012-10-18 23:22:48 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Nadav Rotem5dc203e2012-10-18 23:22:48 +00006//
7//===----------------------------------------------------------------------===//
8
Chandler Carruthd3e73552013-01-07 03:08:10 +00009#include "llvm/Analysis/TargetTransformInfo.h"
Chandler Carruth705b1852015-01-31 03:43:40 +000010#include "llvm/Analysis/TargetTransformInfoImpl.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000011#include "llvm/IR/CallSite.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000012#include "llvm/IR/DataLayout.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000013#include "llvm/IR/Instruction.h"
Chandler Carruth511aa762013-01-21 01:27:39 +000014#include "llvm/IR/Instructions.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000015#include "llvm/IR/IntrinsicInst.h"
Chandler Carruthe0385522015-02-01 10:11:22 +000016#include "llvm/IR/Module.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000017#include "llvm/IR/Operator.h"
Guozhi Wei62d64142017-09-08 22:29:17 +000018#include "llvm/IR/PatternMatch.h"
Sean Fertile9cd1cdf2017-07-07 02:00:06 +000019#include "llvm/Support/CommandLine.h"
Nadav Rotem5dc203e2012-10-18 23:22:48 +000020#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000021#include <utility>
Nadav Rotem5dc203e2012-10-18 23:22:48 +000022
23using namespace llvm;
Guozhi Wei62d64142017-09-08 22:29:17 +000024using namespace PatternMatch;
Nadav Rotem5dc203e2012-10-18 23:22:48 +000025
Chandler Carruthf1221bd2014-04-22 02:48:03 +000026#define DEBUG_TYPE "tti"
27
Guozhi Wei62d64142017-09-08 22:29:17 +000028static cl::opt<bool> EnableReduxCost("costmodel-reduxcost", cl::init(false),
29 cl::Hidden,
30 cl::desc("Recognize reduction patterns."));
31
Chandler Carruth93dcdc42015-01-31 11:17:59 +000032namespace {
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000033/// No-op implementation of the TTI interface using the utility base
Chandler Carruth93dcdc42015-01-31 11:17:59 +000034/// classes.
35///
36/// This is used when no target specific information is available.
37struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
Mehdi Amini5010ebf2015-07-09 02:08:42 +000038 explicit NoTTIImpl(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000039 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
40};
41}
42
Mehdi Amini5010ebf2015-07-09 02:08:42 +000043TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +000044 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
45
Chandler Carruth705b1852015-01-31 03:43:40 +000046TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +000047
Chandler Carruth705b1852015-01-31 03:43:40 +000048TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
49 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +000050
Chandler Carruth705b1852015-01-31 03:43:40 +000051TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
52 TTIImpl = std::move(RHS.TTIImpl);
53 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +000054}
55
Chandler Carruth93205eb2015-08-05 18:08:10 +000056int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
57 Type *OpTy) const {
58 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
59 assert(Cost >= 0 && "TTI should not produce negative costs!");
60 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +000061}
62
Sjoerd Meijer31ff6472019-03-12 09:48:02 +000063int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs,
64 const User *U) const {
65 int Cost = TTIImpl->getCallCost(FTy, NumArgs, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +000066 assert(Cost >= 0 && "TTI should not produce negative costs!");
67 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000068}
69
Chandler Carruth93205eb2015-08-05 18:08:10 +000070int TargetTransformInfo::getCallCost(const Function *F,
Sjoerd Meijer31ff6472019-03-12 09:48:02 +000071 ArrayRef<const Value *> Arguments,
72 const User *U) const {
73 int Cost = TTIImpl->getCallCost(F, Arguments, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +000074 assert(Cost >= 0 && "TTI should not produce negative costs!");
75 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000076}
77
Justin Lebar8650a4d2016-04-15 01:38:48 +000078unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
79 return TTIImpl->getInliningThresholdMultiplier();
80}
81
Jingyue Wu15f3e822016-07-08 21:48:05 +000082int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
83 ArrayRef<const Value *> Operands) const {
84 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
85}
86
Haicheng Wuabdef9e2017-07-15 02:12:16 +000087int TargetTransformInfo::getExtCost(const Instruction *I,
88 const Value *Src) const {
89 return TTIImpl->getExtCost(I, Src);
90}
91
Chandler Carruth93205eb2015-08-05 18:08:10 +000092int TargetTransformInfo::getIntrinsicCost(
Sjoerd Meijer31ff6472019-03-12 09:48:02 +000093 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments,
94 const User *U) const {
95 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +000096 assert(Cost >= 0 && "TTI should not produce negative costs!");
97 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +000098}
99
Jun Bum Lim919f9e82017-04-28 16:04:03 +0000100unsigned
101TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
102 unsigned &JTSize) const {
103 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
104}
105
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +0000106int TargetTransformInfo::getUserCost(const User *U,
107 ArrayRef<const Value *> Operands) const {
108 int Cost = TTIImpl->getUserCost(U, Operands);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000109 assert(Cost >= 0 && "TTI should not produce negative costs!");
110 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +0000111}
112
Tom Stellard8b1e0212013-07-27 00:01:07 +0000113bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000114 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +0000115}
116
Jingyue Wu5da831c2015-04-10 05:03:50 +0000117bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
118 return TTIImpl->isSourceOfDivergence(V);
119}
120
Alexander Timofeev0f9c84c2017-06-15 19:33:10 +0000121bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
122 return TTIImpl->isAlwaysUniform(V);
123}
124
Matt Arsenault42b64782017-01-30 23:02:12 +0000125unsigned TargetTransformInfo::getFlatAddressSpace() const {
126 return TTIImpl->getFlatAddressSpace();
127}
128
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000129bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000130 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000131}
132
Sam Parkerc5ef5022019-06-07 07:35:30 +0000133bool TargetTransformInfo::isHardwareLoopProfitable(
134 Loop *L, ScalarEvolution &SE, AssumptionCache &AC,
135 TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const {
136 return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
137}
138
Chandler Carruth705b1852015-01-31 03:43:40 +0000139void TargetTransformInfo::getUnrollingPreferences(
Geoff Berry66d9bdb2017-06-28 15:53:17 +0000140 Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
141 return TTIImpl->getUnrollingPreferences(L, SE, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000142}
143
Chandler Carruth539edf42013-01-05 11:43:11 +0000144bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000145 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000146}
147
148bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000149 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000150}
151
152bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
153 int64_t BaseOffset,
154 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000155 int64_t Scale,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000156 unsigned AddrSpace,
157 Instruction *I) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000158 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000159 Scale, AddrSpace, I);
Chandler Carruth539edf42013-01-05 11:43:11 +0000160}
161
Evgeny Stupachenkof2b3b462017-06-05 23:37:00 +0000162bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
163 return TTIImpl->isLSRCostLess(C1, C2);
164}
165
Sanjay Pateld7c702b2018-02-05 23:43:05 +0000166bool TargetTransformInfo::canMacroFuseCmp() const {
167 return TTIImpl->canMacroFuseCmp();
168}
169
Krzysztof Parzyszek0b377e02018-03-26 13:10:09 +0000170bool TargetTransformInfo::shouldFavorPostInc() const {
171 return TTIImpl->shouldFavorPostInc();
172}
173
Sam Parker67756c02019-02-07 13:32:54 +0000174bool TargetTransformInfo::shouldFavorBackedgeIndex(const Loop *L) const {
175 return TTIImpl->shouldFavorBackedgeIndex(L);
176}
177
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000178bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
179 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000180}
181
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000182bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
183 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000184}
185
Elena Demikhovsky09285852015-10-25 15:37:55 +0000186bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
187 return TTIImpl->isLegalMaskedGather(DataType);
188}
189
190bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
Mohammed Agabariacef53dc2017-07-27 10:28:16 +0000191 return TTIImpl->isLegalMaskedScatter(DataType);
Elena Demikhovsky09285852015-10-25 15:37:55 +0000192}
193
Craig Topper9f0b17a2019-03-21 17:38:52 +0000194bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType) const {
195 return TTIImpl->isLegalMaskedCompressStore(DataType);
196}
197
198bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType) const {
199 return TTIImpl->isLegalMaskedExpandLoad(DataType);
200}
201
Sanjay Patel6fd43912017-09-09 13:38:18 +0000202bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const {
203 return TTIImpl->hasDivRemOp(DataType, IsSigned);
204}
205
Artem Belevichcb8f6322017-10-24 20:31:44 +0000206bool TargetTransformInfo::hasVolatileVariant(Instruction *I,
207 unsigned AddrSpace) const {
208 return TTIImpl->hasVolatileVariant(I, AddrSpace);
209}
210
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000211bool TargetTransformInfo::prefersVectorizedAddressing() const {
212 return TTIImpl->prefersVectorizedAddressing();
213}
214
Quentin Colombetbf490d42013-05-31 21:29:03 +0000215int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
216 int64_t BaseOffset,
217 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000218 int64_t Scale,
219 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000220 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
221 Scale, AddrSpace);
222 assert(Cost >= 0 && "TTI should not produce negative costs!");
223 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000224}
225
Jonas Paulsson024e3192017-07-21 11:59:37 +0000226bool TargetTransformInfo::LSRWithInstrQueries() const {
227 return TTIImpl->LSRWithInstrQueries();
228}
229
Chandler Carruth539edf42013-01-05 11:43:11 +0000230bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000231 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000232}
233
Chad Rosier54390052015-02-23 19:15:16 +0000234bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
235 return TTIImpl->isProfitableToHoist(I);
236}
237
David Blaikie8ad9a972018-03-28 22:28:50 +0000238bool TargetTransformInfo::useAA() const { return TTIImpl->useAA(); }
239
Chandler Carruth539edf42013-01-05 11:43:11 +0000240bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000241 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000242}
243
244unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000245 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000246}
247
248unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000249 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000250}
251
252bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000253 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000254}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000255bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
256 return TTIImpl->shouldBuildLookupTablesForConstant(C);
257}
Chandler Carruth539edf42013-01-05 11:43:11 +0000258
Zaara Syeda1f59ae32018-01-30 16:17:22 +0000259bool TargetTransformInfo::useColdCCForColdCall(Function &F) const {
260 return TTIImpl->useColdCCForColdCall(F);
261}
262
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000263unsigned TargetTransformInfo::
264getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
265 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
266}
267
268unsigned TargetTransformInfo::
269getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
270 unsigned VF) const {
271 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
272}
273
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000274bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
275 return TTIImpl->supportsEfficientVectorElementLoadStore();
276}
277
Olivier Sallenave049d8032015-03-06 23:12:04 +0000278bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
279 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
280}
281
Clement Courbetb2c3eb82017-10-30 14:19:33 +0000282const TargetTransformInfo::MemCmpExpansionOptions *
283TargetTransformInfo::enableMemCmpExpansion(bool IsZeroCmp) const {
284 return TTIImpl->enableMemCmpExpansion(IsZeroCmp);
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000285}
286
Silviu Baranga61bdc512015-08-10 14:50:54 +0000287bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
288 return TTIImpl->enableInterleavedAccessVectorization();
289}
290
Dorit Nuzman38bbf812018-10-14 08:50:06 +0000291bool TargetTransformInfo::enableMaskedInterleavedAccessVectorization() const {
292 return TTIImpl->enableMaskedInterleavedAccessVectorization();
293}
294
Renato Golin5cb666a2016-04-14 20:42:18 +0000295bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
296 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
297}
298
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000299bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
300 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000301 unsigned AddressSpace,
302 unsigned Alignment,
303 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000304 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000305 Alignment, Fast);
306}
307
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000308TargetTransformInfo::PopcntSupportKind
309TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000310 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000311}
312
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000313bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000314 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000315}
316
Sanjay Patel0de1a4b2017-11-27 21:15:43 +0000317bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const {
318 return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
319}
320
Chandler Carruth93205eb2015-08-05 18:08:10 +0000321int TargetTransformInfo::getFPOpCost(Type *Ty) const {
322 int Cost = TTIImpl->getFPOpCost(Ty);
323 assert(Cost >= 0 && "TTI should not produce negative costs!");
324 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000325}
326
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000327int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
328 const APInt &Imm,
329 Type *Ty) const {
330 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
331 assert(Cost >= 0 && "TTI should not produce negative costs!");
332 return Cost;
333}
334
Chandler Carruth93205eb2015-08-05 18:08:10 +0000335int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
336 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
337 assert(Cost >= 0 && "TTI should not produce negative costs!");
338 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000339}
340
Chandler Carruth93205eb2015-08-05 18:08:10 +0000341int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
342 const APInt &Imm, Type *Ty) const {
343 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
344 assert(Cost >= 0 && "TTI should not produce negative costs!");
345 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000346}
347
Chandler Carruth93205eb2015-08-05 18:08:10 +0000348int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
349 const APInt &Imm, Type *Ty) const {
350 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
351 assert(Cost >= 0 && "TTI should not produce negative costs!");
352 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000353}
354
Chandler Carruth539edf42013-01-05 11:43:11 +0000355unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000356 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000357}
358
Nadav Rotemb1791a72013-01-09 22:29:00 +0000359unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000360 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000361}
362
Adam Nemete29686e2017-05-15 21:15:01 +0000363unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
364 return TTIImpl->getMinVectorRegisterBitWidth();
365}
366
Krzysztof Parzyszek5d93fdf2018-03-27 16:14:11 +0000367bool TargetTransformInfo::shouldMaximizeVectorBandwidth(bool OptSize) const {
368 return TTIImpl->shouldMaximizeVectorBandwidth(OptSize);
369}
370
Krzysztof Parzyszekdfed9412018-04-13 20:16:32 +0000371unsigned TargetTransformInfo::getMinimumVF(unsigned ElemWidth) const {
372 return TTIImpl->getMinimumVF(ElemWidth);
373}
374
Jun Bum Limdee55652017-04-03 19:20:07 +0000375bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
376 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
377 return TTIImpl->shouldConsiderAddressTypePromotion(
378 I, AllowPromotionWithoutCommonHeader);
379}
380
Adam Nemetaf761102016-01-21 18:28:36 +0000381unsigned TargetTransformInfo::getCacheLineSize() const {
382 return TTIImpl->getCacheLineSize();
383}
384
Tobias Grosserd7eb6192017-08-24 09:46:25 +0000385llvm::Optional<unsigned> TargetTransformInfo::getCacheSize(CacheLevel Level)
386 const {
387 return TTIImpl->getCacheSize(Level);
388}
389
390llvm::Optional<unsigned> TargetTransformInfo::getCacheAssociativity(
391 CacheLevel Level) const {
392 return TTIImpl->getCacheAssociativity(Level);
393}
394
Adam Nemetdadfbb52016-01-27 22:21:25 +0000395unsigned TargetTransformInfo::getPrefetchDistance() const {
396 return TTIImpl->getPrefetchDistance();
397}
398
Adam Nemet6d8beec2016-03-18 00:27:38 +0000399unsigned TargetTransformInfo::getMinPrefetchStride() const {
400 return TTIImpl->getMinPrefetchStride();
401}
402
Adam Nemet709e3042016-03-18 00:27:43 +0000403unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
404 return TTIImpl->getMaxPrefetchIterationsAhead();
405}
406
Wei Mi062c7442015-05-06 17:12:25 +0000407unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
408 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000409}
410
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000411TargetTransformInfo::OperandValueKind
Simon Pilgrim077a42c2018-11-13 13:45:10 +0000412TargetTransformInfo::getOperandInfo(Value *V, OperandValueProperties &OpProps) {
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000413 OperandValueKind OpInfo = OK_AnyValue;
414 OpProps = OP_None;
415
416 if (auto *CI = dyn_cast<ConstantInt>(V)) {
417 if (CI->getValue().isPowerOf2())
418 OpProps = OP_PowerOf2;
419 return OK_UniformConstantValue;
420 }
421
Simon Pilgrim2b166c52018-11-14 15:04:08 +0000422 // A broadcast shuffle creates a uniform value.
423 // TODO: Add support for non-zero index broadcasts.
424 // TODO: Add support for different source vector width.
425 if (auto *ShuffleInst = dyn_cast<ShuffleVectorInst>(V))
426 if (ShuffleInst->isZeroEltSplat())
427 OpInfo = OK_UniformValue;
428
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000429 const Value *Splat = getSplatValue(V);
430
431 // Check for a splat of a constant or for a non uniform vector of constants
432 // and check if the constant(s) are all powers of two.
433 if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
434 OpInfo = OK_NonUniformConstantValue;
435 if (Splat) {
436 OpInfo = OK_UniformConstantValue;
437 if (auto *CI = dyn_cast<ConstantInt>(Splat))
438 if (CI->getValue().isPowerOf2())
439 OpProps = OP_PowerOf2;
440 } else if (auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
441 OpProps = OP_PowerOf2;
442 for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
443 if (auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
444 if (CI->getValue().isPowerOf2())
445 continue;
446 OpProps = OP_None;
447 break;
448 }
449 }
450 }
451
452 // Check for a splat of a uniform value. This is not loop aware, so return
453 // true only for the obviously uniform cases (argument, globalvalue)
454 if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
455 OpInfo = OK_UniformValue;
456
457 return OpInfo;
458}
459
Chandler Carruth93205eb2015-08-05 18:08:10 +0000460int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000461 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
462 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000463 OperandValueProperties Opd2PropInfo,
464 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000465 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000466 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000467 assert(Cost >= 0 && "TTI should not produce negative costs!");
468 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000469}
470
Chandler Carruth93205eb2015-08-05 18:08:10 +0000471int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
472 Type *SubTp) const {
473 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
474 assert(Cost >= 0 && "TTI should not produce negative costs!");
475 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000476}
477
Chandler Carruth93205eb2015-08-05 18:08:10 +0000478int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000479 Type *Src, const Instruction *I) const {
480 assert ((I == nullptr || I->getOpcode() == Opcode) &&
481 "Opcode should reflect passed instruction.");
482 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000483 assert(Cost >= 0 && "TTI should not produce negative costs!");
484 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000485}
486
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000487int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
488 VectorType *VecTy,
489 unsigned Index) const {
490 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
491 assert(Cost >= 0 && "TTI should not produce negative costs!");
492 return Cost;
493}
494
Chandler Carruth93205eb2015-08-05 18:08:10 +0000495int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
496 int Cost = TTIImpl->getCFInstrCost(Opcode);
497 assert(Cost >= 0 && "TTI should not produce negative costs!");
498 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000499}
500
Chandler Carruth93205eb2015-08-05 18:08:10 +0000501int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000502 Type *CondTy, const Instruction *I) const {
503 assert ((I == nullptr || I->getOpcode() == Opcode) &&
504 "Opcode should reflect passed instruction.");
505 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000506 assert(Cost >= 0 && "TTI should not produce negative costs!");
507 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000508}
509
Chandler Carruth93205eb2015-08-05 18:08:10 +0000510int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
511 unsigned Index) const {
512 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
513 assert(Cost >= 0 && "TTI should not produce negative costs!");
514 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000515}
516
Chandler Carruth93205eb2015-08-05 18:08:10 +0000517int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
518 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000519 unsigned AddressSpace,
520 const Instruction *I) const {
521 assert ((I == nullptr || I->getOpcode() == Opcode) &&
522 "Opcode should reflect passed instruction.");
523 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000524 assert(Cost >= 0 && "TTI should not produce negative costs!");
525 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000526}
527
Chandler Carruth93205eb2015-08-05 18:08:10 +0000528int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
529 unsigned Alignment,
530 unsigned AddressSpace) const {
531 int Cost =
532 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
533 assert(Cost >= 0 && "TTI should not produce negative costs!");
534 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000535}
536
Elena Demikhovsky54946982015-12-28 20:10:59 +0000537int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
538 Value *Ptr, bool VariableMask,
539 unsigned Alignment) const {
540 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
541 Alignment);
542 assert(Cost >= 0 && "TTI should not produce negative costs!");
543 return Cost;
544}
545
Chandler Carruth93205eb2015-08-05 18:08:10 +0000546int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000547 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
Dorit Nuzman34da6dd2018-10-31 09:57:56 +0000548 unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond,
549 bool UseMaskForGaps) const {
550 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
551 Alignment, AddressSpace,
552 UseMaskForCond,
553 UseMaskForGaps);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000554 assert(Cost >= 0 && "TTI should not produce negative costs!");
555 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000556}
557
Chandler Carruth93205eb2015-08-05 18:08:10 +0000558int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000559 ArrayRef<Type *> Tys, FastMathFlags FMF,
560 unsigned ScalarizationCostPassed) const {
561 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
562 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000563 assert(Cost >= 0 && "TTI should not produce negative costs!");
564 return Cost;
565}
566
Elena Demikhovsky54946982015-12-28 20:10:59 +0000567int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000568 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
569 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000570 assert(Cost >= 0 && "TTI should not produce negative costs!");
571 return Cost;
572}
573
Chandler Carruth93205eb2015-08-05 18:08:10 +0000574int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
575 ArrayRef<Type *> Tys) const {
576 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
577 assert(Cost >= 0 && "TTI should not produce negative costs!");
578 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000579}
580
Chandler Carruth539edf42013-01-05 11:43:11 +0000581unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000582 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000583}
584
Chandler Carruth93205eb2015-08-05 18:08:10 +0000585int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000586 ScalarEvolution *SE,
587 const SCEV *Ptr) const {
588 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000589 assert(Cost >= 0 && "TTI should not produce negative costs!");
590 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000591}
Chandler Carruth539edf42013-01-05 11:43:11 +0000592
Sjoerd Meijerea31ddb2019-04-30 10:28:50 +0000593int TargetTransformInfo::getMemcpyCost(const Instruction *I) const {
594 int Cost = TTIImpl->getMemcpyCost(I);
595 assert(Cost >= 0 && "TTI should not produce negative costs!");
596 return Cost;
597}
598
Alexey Bataev3e9b3eb2017-07-31 14:19:32 +0000599int TargetTransformInfo::getArithmeticReductionCost(unsigned Opcode, Type *Ty,
600 bool IsPairwiseForm) const {
601 int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000602 assert(Cost >= 0 && "TTI should not produce negative costs!");
603 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000604}
605
Alexey Bataev6dd29fc2017-09-08 13:49:36 +0000606int TargetTransformInfo::getMinMaxReductionCost(Type *Ty, Type *CondTy,
607 bool IsPairwiseForm,
608 bool IsUnsigned) const {
609 int Cost =
610 TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned);
611 assert(Cost >= 0 && "TTI should not produce negative costs!");
612 return Cost;
613}
614
Chandler Carruth705b1852015-01-31 03:43:40 +0000615unsigned
616TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
617 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000618}
619
620bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
621 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000622 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000623}
624
Anna Thomasb2a212c2017-06-06 16:45:25 +0000625unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
626 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
627}
628
Chandler Carruth705b1852015-01-31 03:43:40 +0000629Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
630 IntrinsicInst *Inst, Type *ExpectedType) const {
631 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
632}
633
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000634Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
635 Value *Length,
636 unsigned SrcAlign,
637 unsigned DestAlign) const {
638 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
639 DestAlign);
640}
641
642void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
643 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
644 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
645 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
646 SrcAlign, DestAlign);
647}
648
Eric Christopherd566fb12015-07-29 22:09:48 +0000649bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
650 const Function *Callee) const {
651 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000652}
653
Tom Stellard3d36e5c2019-01-16 05:15:31 +0000654bool TargetTransformInfo::areFunctionArgsABICompatible(
655 const Function *Caller, const Function *Callee,
656 SmallPtrSetImpl<Argument *> &Args) const {
657 return TTIImpl->areFunctionArgsABICompatible(Caller, Callee, Args);
658}
659
Krzysztof Parzyszek0b377e02018-03-26 13:10:09 +0000660bool TargetTransformInfo::isIndexedLoadLegal(MemIndexedMode Mode,
661 Type *Ty) const {
662 return TTIImpl->isIndexedLoadLegal(Mode, Ty);
663}
664
665bool TargetTransformInfo::isIndexedStoreLegal(MemIndexedMode Mode,
666 Type *Ty) const {
667 return TTIImpl->isIndexedStoreLegal(Mode, Ty);
668}
669
Volkan Keles1c386812016-10-03 10:31:34 +0000670unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
671 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
672}
673
674bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
675 return TTIImpl->isLegalToVectorizeLoad(LI);
676}
677
678bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
679 return TTIImpl->isLegalToVectorizeStore(SI);
680}
681
682bool TargetTransformInfo::isLegalToVectorizeLoadChain(
683 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
684 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
685 AddrSpace);
686}
687
688bool TargetTransformInfo::isLegalToVectorizeStoreChain(
689 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
690 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
691 AddrSpace);
692}
693
694unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
695 unsigned LoadSize,
696 unsigned ChainSizeInBytes,
697 VectorType *VecTy) const {
698 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
699}
700
701unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
702 unsigned StoreSize,
703 unsigned ChainSizeInBytes,
704 VectorType *VecTy) const {
705 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
706}
707
Amara Emersoncf9daa32017-05-09 10:43:25 +0000708bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
709 Type *Ty, ReductionFlags Flags) const {
710 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
711}
712
Amara Emerson836b0f42017-05-10 09:42:49 +0000713bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
714 return TTIImpl->shouldExpandReduction(II);
715}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000716
Guozhi Wei62d64142017-09-08 22:29:17 +0000717int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
718 return TTIImpl->getInstructionLatency(I);
719}
720
Guozhi Wei62d64142017-09-08 22:29:17 +0000721static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft,
722 unsigned Level) {
723 // We don't need a shuffle if we just want to have element 0 in position 0 of
724 // the vector.
725 if (!SI && Level == 0 && IsLeft)
726 return true;
727 else if (!SI)
728 return false;
729
730 SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1);
731
732 // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether
733 // we look at the left or right side.
734 for (unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2)
735 Mask[i] = val;
736
737 SmallVector<int, 16> ActualMask = SI->getShuffleMask();
738 return Mask == ActualMask;
739}
740
741namespace {
742/// Kind of the reduction data.
743enum ReductionKind {
744 RK_None, /// Not a reduction.
745 RK_Arithmetic, /// Binary reduction data.
746 RK_MinMax, /// Min/max reduction data.
747 RK_UnsignedMinMax, /// Unsigned min/max reduction data.
748};
749/// Contains opcode + LHS/RHS parts of the reduction operations.
750struct ReductionData {
751 ReductionData() = delete;
752 ReductionData(ReductionKind Kind, unsigned Opcode, Value *LHS, Value *RHS)
753 : Opcode(Opcode), LHS(LHS), RHS(RHS), Kind(Kind) {
754 assert(Kind != RK_None && "expected binary or min/max reduction only.");
755 }
756 unsigned Opcode = 0;
757 Value *LHS = nullptr;
758 Value *RHS = nullptr;
759 ReductionKind Kind = RK_None;
760 bool hasSameData(ReductionData &RD) const {
761 return Kind == RD.Kind && Opcode == RD.Opcode;
762 }
763};
764} // namespace
765
766static Optional<ReductionData> getReductionData(Instruction *I) {
767 Value *L, *R;
768 if (m_BinOp(m_Value(L), m_Value(R)).match(I))
Fangrui Songf78650a2018-07-30 19:41:25 +0000769 return ReductionData(RK_Arithmetic, I->getOpcode(), L, R);
Guozhi Wei62d64142017-09-08 22:29:17 +0000770 if (auto *SI = dyn_cast<SelectInst>(I)) {
771 if (m_SMin(m_Value(L), m_Value(R)).match(SI) ||
772 m_SMax(m_Value(L), m_Value(R)).match(SI) ||
773 m_OrdFMin(m_Value(L), m_Value(R)).match(SI) ||
774 m_OrdFMax(m_Value(L), m_Value(R)).match(SI) ||
775 m_UnordFMin(m_Value(L), m_Value(R)).match(SI) ||
776 m_UnordFMax(m_Value(L), m_Value(R)).match(SI)) {
777 auto *CI = cast<CmpInst>(SI->getCondition());
Fangrui Songf78650a2018-07-30 19:41:25 +0000778 return ReductionData(RK_MinMax, CI->getOpcode(), L, R);
779 }
Guozhi Wei62d64142017-09-08 22:29:17 +0000780 if (m_UMin(m_Value(L), m_Value(R)).match(SI) ||
781 m_UMax(m_Value(L), m_Value(R)).match(SI)) {
782 auto *CI = cast<CmpInst>(SI->getCondition());
783 return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R);
784 }
785 }
786 return llvm::None;
787}
788
789static ReductionKind matchPairwiseReductionAtLevel(Instruction *I,
790 unsigned Level,
791 unsigned NumLevels) {
792 // Match one level of pairwise operations.
793 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
794 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
795 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
796 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
797 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
798 if (!I)
799 return RK_None;
800
801 assert(I->getType()->isVectorTy() && "Expecting a vector type");
802
803 Optional<ReductionData> RD = getReductionData(I);
804 if (!RD)
805 return RK_None;
806
807 ShuffleVectorInst *LS = dyn_cast<ShuffleVectorInst>(RD->LHS);
808 if (!LS && Level)
809 return RK_None;
810 ShuffleVectorInst *RS = dyn_cast<ShuffleVectorInst>(RD->RHS);
811 if (!RS && Level)
812 return RK_None;
813
814 // On level 0 we can omit one shufflevector instruction.
815 if (!Level && !RS && !LS)
816 return RK_None;
817
818 // Shuffle inputs must match.
819 Value *NextLevelOpL = LS ? LS->getOperand(0) : nullptr;
820 Value *NextLevelOpR = RS ? RS->getOperand(0) : nullptr;
821 Value *NextLevelOp = nullptr;
822 if (NextLevelOpR && NextLevelOpL) {
823 // If we have two shuffles their operands must match.
824 if (NextLevelOpL != NextLevelOpR)
825 return RK_None;
826
827 NextLevelOp = NextLevelOpL;
828 } else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) {
829 // On the first level we can omit the shufflevector <0, undef,...>. So the
830 // input to the other shufflevector <1, undef> must match with one of the
831 // inputs to the current binary operation.
832 // Example:
833 // %NextLevelOpL = shufflevector %R, <1, undef ...>
834 // %BinOp = fadd %NextLevelOpL, %R
835 if (NextLevelOpL && NextLevelOpL != RD->RHS)
836 return RK_None;
837 else if (NextLevelOpR && NextLevelOpR != RD->LHS)
838 return RK_None;
839
840 NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS;
841 } else
842 return RK_None;
843
844 // Check that the next levels binary operation exists and matches with the
845 // current one.
846 if (Level + 1 != NumLevels) {
847 Optional<ReductionData> NextLevelRD =
848 getReductionData(cast<Instruction>(NextLevelOp));
849 if (!NextLevelRD || !RD->hasSameData(*NextLevelRD))
850 return RK_None;
851 }
852
853 // Shuffle mask for pairwise operation must match.
854 if (matchPairwiseShuffleMask(LS, /*IsLeft=*/true, Level)) {
855 if (!matchPairwiseShuffleMask(RS, /*IsLeft=*/false, Level))
856 return RK_None;
857 } else if (matchPairwiseShuffleMask(RS, /*IsLeft=*/true, Level)) {
858 if (!matchPairwiseShuffleMask(LS, /*IsLeft=*/false, Level))
859 return RK_None;
860 } else {
861 return RK_None;
862 }
863
864 if (++Level == NumLevels)
865 return RD->Kind;
866
867 // Match next level.
868 return matchPairwiseReductionAtLevel(cast<Instruction>(NextLevelOp), Level,
869 NumLevels);
870}
871
872static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot,
873 unsigned &Opcode, Type *&Ty) {
874 if (!EnableReduxCost)
875 return RK_None;
876
877 // Need to extract the first element.
878 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
879 unsigned Idx = ~0u;
880 if (CI)
881 Idx = CI->getZExtValue();
882 if (Idx != 0)
883 return RK_None;
884
885 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
886 if (!RdxStart)
887 return RK_None;
888 Optional<ReductionData> RD = getReductionData(RdxStart);
889 if (!RD)
890 return RK_None;
891
892 Type *VecTy = RdxStart->getType();
893 unsigned NumVecElems = VecTy->getVectorNumElements();
894 if (!isPowerOf2_32(NumVecElems))
895 return RK_None;
896
897 // We look for a sequence of shuffle,shuffle,add triples like the following
898 // that builds a pairwise reduction tree.
Fangrui Songf78650a2018-07-30 19:41:25 +0000899 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000900 // (X0, X1, X2, X3)
901 // (X0 + X1, X2 + X3, undef, undef)
902 // ((X0 + X1) + (X2 + X3), undef, undef, undef)
Fangrui Songf78650a2018-07-30 19:41:25 +0000903 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000904 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
905 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
906 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
907 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
908 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
909 // %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
910 // <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
911 // %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
912 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
913 // %bin.rdx8 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
914 // %r = extractelement <4 x float> %bin.rdx8, i32 0
915 if (matchPairwiseReductionAtLevel(RdxStart, 0, Log2_32(NumVecElems)) ==
916 RK_None)
917 return RK_None;
918
919 Opcode = RD->Opcode;
920 Ty = VecTy;
921
922 return RD->Kind;
923}
924
925static std::pair<Value *, ShuffleVectorInst *>
926getShuffleAndOtherOprd(Value *L, Value *R) {
927 ShuffleVectorInst *S = nullptr;
928
929 if ((S = dyn_cast<ShuffleVectorInst>(L)))
930 return std::make_pair(R, S);
931
932 S = dyn_cast<ShuffleVectorInst>(R);
933 return std::make_pair(L, S);
934}
935
936static ReductionKind
937matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot,
938 unsigned &Opcode, Type *&Ty) {
939 if (!EnableReduxCost)
940 return RK_None;
941
942 // Need to extract the first element.
943 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
944 unsigned Idx = ~0u;
945 if (CI)
946 Idx = CI->getZExtValue();
947 if (Idx != 0)
948 return RK_None;
949
950 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
951 if (!RdxStart)
952 return RK_None;
953 Optional<ReductionData> RD = getReductionData(RdxStart);
954 if (!RD)
955 return RK_None;
956
957 Type *VecTy = ReduxRoot->getOperand(0)->getType();
958 unsigned NumVecElems = VecTy->getVectorNumElements();
959 if (!isPowerOf2_32(NumVecElems))
960 return RK_None;
961
962 // We look for a sequence of shuffles and adds like the following matching one
963 // fadd, shuffle vector pair at a time.
Fangrui Songf78650a2018-07-30 19:41:25 +0000964 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000965 // %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef,
966 // <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
967 // %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
968 // %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef,
969 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
970 // %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
971 // %r = extractelement <4 x float> %bin.rdx8, i32 0
972
973 unsigned MaskStart = 1;
974 Instruction *RdxOp = RdxStart;
Fangrui Songf78650a2018-07-30 19:41:25 +0000975 SmallVector<int, 32> ShuffleMask(NumVecElems, 0);
Guozhi Wei62d64142017-09-08 22:29:17 +0000976 unsigned NumVecElemsRemain = NumVecElems;
977 while (NumVecElemsRemain - 1) {
978 // Check for the right reduction operation.
979 if (!RdxOp)
980 return RK_None;
981 Optional<ReductionData> RDLevel = getReductionData(RdxOp);
982 if (!RDLevel || !RDLevel->hasSameData(*RD))
983 return RK_None;
984
985 Value *NextRdxOp;
986 ShuffleVectorInst *Shuffle;
987 std::tie(NextRdxOp, Shuffle) =
988 getShuffleAndOtherOprd(RDLevel->LHS, RDLevel->RHS);
989
990 // Check the current reduction operation and the shuffle use the same value.
991 if (Shuffle == nullptr)
992 return RK_None;
993 if (Shuffle->getOperand(0) != NextRdxOp)
994 return RK_None;
995
996 // Check that shuffle masks matches.
997 for (unsigned j = 0; j != MaskStart; ++j)
998 ShuffleMask[j] = MaskStart + j;
999 // Fill the rest of the mask with -1 for undef.
1000 std::fill(&ShuffleMask[MaskStart], ShuffleMask.end(), -1);
1001
1002 SmallVector<int, 16> Mask = Shuffle->getShuffleMask();
1003 if (ShuffleMask != Mask)
1004 return RK_None;
1005
1006 RdxOp = dyn_cast<Instruction>(NextRdxOp);
1007 NumVecElemsRemain /= 2;
1008 MaskStart *= 2;
1009 }
1010
1011 Opcode = RD->Opcode;
1012 Ty = VecTy;
1013 return RD->Kind;
1014}
1015
1016int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
1017 switch (I->getOpcode()) {
1018 case Instruction::GetElementPtr:
1019 return getUserCost(I);
1020
1021 case Instruction::Ret:
1022 case Instruction::PHI:
1023 case Instruction::Br: {
1024 return getCFInstrCost(I->getOpcode());
1025 }
1026 case Instruction::Add:
1027 case Instruction::FAdd:
1028 case Instruction::Sub:
1029 case Instruction::FSub:
1030 case Instruction::Mul:
1031 case Instruction::FMul:
1032 case Instruction::UDiv:
1033 case Instruction::SDiv:
1034 case Instruction::FDiv:
1035 case Instruction::URem:
1036 case Instruction::SRem:
1037 case Instruction::FRem:
1038 case Instruction::Shl:
1039 case Instruction::LShr:
1040 case Instruction::AShr:
1041 case Instruction::And:
1042 case Instruction::Or:
1043 case Instruction::Xor: {
Simon Pilgrim4162d772018-05-22 10:40:09 +00001044 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1045 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1046 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1047 Op2VK = getOperandInfo(I->getOperand(1), Op2VP);
1048 SmallVector<const Value *, 2> Operands(I->operand_values());
1049 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1050 Op1VP, Op2VP, Operands);
Guozhi Wei62d64142017-09-08 22:29:17 +00001051 }
Craig Topper50d50282019-05-28 04:09:18 +00001052 case Instruction::FNeg: {
1053 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1054 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1055 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1056 Op2VK = OK_AnyValue;
1057 Op2VP = OP_None;
1058 SmallVector<const Value *, 2> Operands(I->operand_values());
1059 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1060 Op1VP, Op2VP, Operands);
1061 }
Guozhi Wei62d64142017-09-08 22:29:17 +00001062 case Instruction::Select: {
1063 const SelectInst *SI = cast<SelectInst>(I);
1064 Type *CondTy = SI->getCondition()->getType();
1065 return getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, I);
1066 }
1067 case Instruction::ICmp:
1068 case Instruction::FCmp: {
1069 Type *ValTy = I->getOperand(0)->getType();
1070 return getCmpSelInstrCost(I->getOpcode(), ValTy, I->getType(), I);
1071 }
1072 case Instruction::Store: {
1073 const StoreInst *SI = cast<StoreInst>(I);
1074 Type *ValTy = SI->getValueOperand()->getType();
1075 return getMemoryOpCost(I->getOpcode(), ValTy,
1076 SI->getAlignment(),
1077 SI->getPointerAddressSpace(), I);
1078 }
1079 case Instruction::Load: {
1080 const LoadInst *LI = cast<LoadInst>(I);
1081 return getMemoryOpCost(I->getOpcode(), I->getType(),
1082 LI->getAlignment(),
1083 LI->getPointerAddressSpace(), I);
1084 }
1085 case Instruction::ZExt:
1086 case Instruction::SExt:
1087 case Instruction::FPToUI:
1088 case Instruction::FPToSI:
1089 case Instruction::FPExt:
1090 case Instruction::PtrToInt:
1091 case Instruction::IntToPtr:
1092 case Instruction::SIToFP:
1093 case Instruction::UIToFP:
1094 case Instruction::Trunc:
1095 case Instruction::FPTrunc:
1096 case Instruction::BitCast:
1097 case Instruction::AddrSpaceCast: {
1098 Type *SrcTy = I->getOperand(0)->getType();
1099 return getCastInstrCost(I->getOpcode(), I->getType(), SrcTy, I);
1100 }
1101 case Instruction::ExtractElement: {
1102 const ExtractElementInst * EEI = cast<ExtractElementInst>(I);
1103 ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1));
1104 unsigned Idx = -1;
1105 if (CI)
1106 Idx = CI->getZExtValue();
1107
1108 // Try to match a reduction sequence (series of shufflevector and vector
1109 // adds followed by a extractelement).
1110 unsigned ReduxOpCode;
1111 Type *ReduxType;
1112
1113 switch (matchVectorSplittingReduction(EEI, ReduxOpCode, ReduxType)) {
1114 case RK_Arithmetic:
1115 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1116 /*IsPairwiseForm=*/false);
1117 case RK_MinMax:
1118 return getMinMaxReductionCost(
1119 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1120 /*IsPairwiseForm=*/false, /*IsUnsigned=*/false);
1121 case RK_UnsignedMinMax:
1122 return getMinMaxReductionCost(
1123 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1124 /*IsPairwiseForm=*/false, /*IsUnsigned=*/true);
1125 case RK_None:
1126 break;
1127 }
1128
1129 switch (matchPairwiseReduction(EEI, ReduxOpCode, ReduxType)) {
1130 case RK_Arithmetic:
1131 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1132 /*IsPairwiseForm=*/true);
1133 case RK_MinMax:
1134 return getMinMaxReductionCost(
1135 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1136 /*IsPairwiseForm=*/true, /*IsUnsigned=*/false);
1137 case RK_UnsignedMinMax:
1138 return getMinMaxReductionCost(
1139 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1140 /*IsPairwiseForm=*/true, /*IsUnsigned=*/true);
1141 case RK_None:
1142 break;
1143 }
1144
1145 return getVectorInstrCost(I->getOpcode(),
1146 EEI->getOperand(0)->getType(), Idx);
1147 }
1148 case Instruction::InsertElement: {
1149 const InsertElementInst * IE = cast<InsertElementInst>(I);
1150 ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
Fangrui Songf78650a2018-07-30 19:41:25 +00001151 unsigned Idx = -1;
Guozhi Wei62d64142017-09-08 22:29:17 +00001152 if (CI)
1153 Idx = CI->getZExtValue();
1154 return getVectorInstrCost(I->getOpcode(),
1155 IE->getType(), Idx);
1156 }
1157 case Instruction::ShuffleVector: {
1158 const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001159 Type *Ty = Shuffle->getType();
1160 Type *SrcTy = Shuffle->getOperand(0)->getType();
1161
1162 // TODO: Identify and add costs for insert subvector, etc.
1163 int SubIndex;
1164 if (Shuffle->isExtractSubvectorMask(SubIndex))
Simon Pilgrim26e1c882018-11-09 18:30:59 +00001165 return TTIImpl->getShuffleCost(SK_ExtractSubvector, SrcTy, SubIndex, Ty);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001166
Sanjay Patel2ca33602018-06-19 18:44:00 +00001167 if (Shuffle->changesLength())
1168 return -1;
Fangrui Songf78650a2018-07-30 19:41:25 +00001169
Sanjay Patel2ca33602018-06-19 18:44:00 +00001170 if (Shuffle->isIdentity())
1171 return 0;
Guozhi Wei62d64142017-09-08 22:29:17 +00001172
Sanjay Patel2ca33602018-06-19 18:44:00 +00001173 if (Shuffle->isReverse())
1174 return TTIImpl->getShuffleCost(SK_Reverse, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001175
Sanjay Patel2ca33602018-06-19 18:44:00 +00001176 if (Shuffle->isSelect())
1177 return TTIImpl->getShuffleCost(SK_Select, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001178
Sanjay Patel2ca33602018-06-19 18:44:00 +00001179 if (Shuffle->isTranspose())
1180 return TTIImpl->getShuffleCost(SK_Transpose, Ty, 0, nullptr);
Matthew Simpsonb4096eb2018-04-26 13:48:33 +00001181
Sanjay Patel2ca33602018-06-19 18:44:00 +00001182 if (Shuffle->isZeroEltSplat())
1183 return TTIImpl->getShuffleCost(SK_Broadcast, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001184
Sanjay Patel2ca33602018-06-19 18:44:00 +00001185 if (Shuffle->isSingleSource())
1186 return TTIImpl->getShuffleCost(SK_PermuteSingleSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001187
Sanjay Patel2ca33602018-06-19 18:44:00 +00001188 return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001189 }
1190 case Instruction::Call:
1191 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
1192 SmallVector<Value *, 4> Args(II->arg_operands());
1193
1194 FastMathFlags FMF;
1195 if (auto *FPMO = dyn_cast<FPMathOperator>(II))
1196 FMF = FPMO->getFastMathFlags();
1197
1198 return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(),
1199 Args, FMF);
1200 }
1201 return -1;
1202 default:
1203 // We don't have any information on this instruction.
1204 return -1;
1205 }
1206}
1207
Chandler Carruth705b1852015-01-31 03:43:40 +00001208TargetTransformInfo::Concept::~Concept() {}
1209
Chandler Carruthe0385522015-02-01 10:11:22 +00001210TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
1211
1212TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001213 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +00001214 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +00001215
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001216TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +00001217 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +00001218 return TTICallback(F);
1219}
1220
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001221AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001222
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001223TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +00001224 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +00001225}
1226
Chandler Carruth705b1852015-01-31 03:43:40 +00001227// Register the basic pass.
1228INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
1229 "Target Transform Information", false, true)
1230char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +00001231
Chandler Carruth705b1852015-01-31 03:43:40 +00001232void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +00001233
Chandler Carruth705b1852015-01-31 03:43:40 +00001234TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001235 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001236 initializeTargetTransformInfoWrapperPassPass(
1237 *PassRegistry::getPassRegistry());
1238}
1239
1240TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001241 TargetIRAnalysis TIRA)
1242 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001243 initializeTargetTransformInfoWrapperPassPass(
1244 *PassRegistry::getPassRegistry());
1245}
1246
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001247TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +00001248 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001249 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001250 return *TTI;
1251}
1252
Chandler Carruth93dcdc42015-01-31 11:17:59 +00001253ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001254llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
1255 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +00001256}