blob: 83840aa7fbb61e176eebc2bb14e4466f8c699951 [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
Warren Ristow6452bdd2019-06-17 17:20:08 +0000186bool TargetTransformInfo::isLegalNTStore(Type *DataType,
187 unsigned Alignment) const {
188 return TTIImpl->isLegalNTStore(DataType, Alignment);
189}
190
191bool TargetTransformInfo::isLegalNTLoad(Type *DataType,
192 unsigned Alignment) const {
193 return TTIImpl->isLegalNTLoad(DataType, Alignment);
194}
195
Elena Demikhovsky09285852015-10-25 15:37:55 +0000196bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
197 return TTIImpl->isLegalMaskedGather(DataType);
198}
199
200bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
Mohammed Agabariacef53dc2017-07-27 10:28:16 +0000201 return TTIImpl->isLegalMaskedScatter(DataType);
Elena Demikhovsky09285852015-10-25 15:37:55 +0000202}
203
Craig Topper9f0b17a2019-03-21 17:38:52 +0000204bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType) const {
205 return TTIImpl->isLegalMaskedCompressStore(DataType);
206}
207
208bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType) const {
209 return TTIImpl->isLegalMaskedExpandLoad(DataType);
210}
211
Sanjay Patel6fd43912017-09-09 13:38:18 +0000212bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const {
213 return TTIImpl->hasDivRemOp(DataType, IsSigned);
214}
215
Artem Belevichcb8f6322017-10-24 20:31:44 +0000216bool TargetTransformInfo::hasVolatileVariant(Instruction *I,
217 unsigned AddrSpace) const {
218 return TTIImpl->hasVolatileVariant(I, AddrSpace);
219}
220
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000221bool TargetTransformInfo::prefersVectorizedAddressing() const {
222 return TTIImpl->prefersVectorizedAddressing();
223}
224
Quentin Colombetbf490d42013-05-31 21:29:03 +0000225int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
226 int64_t BaseOffset,
227 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000228 int64_t Scale,
229 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000230 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
231 Scale, AddrSpace);
232 assert(Cost >= 0 && "TTI should not produce negative costs!");
233 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000234}
235
Jonas Paulsson024e3192017-07-21 11:59:37 +0000236bool TargetTransformInfo::LSRWithInstrQueries() const {
237 return TTIImpl->LSRWithInstrQueries();
238}
239
Chandler Carruth539edf42013-01-05 11:43:11 +0000240bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000241 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000242}
243
Chad Rosier54390052015-02-23 19:15:16 +0000244bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
245 return TTIImpl->isProfitableToHoist(I);
246}
247
David Blaikie8ad9a972018-03-28 22:28:50 +0000248bool TargetTransformInfo::useAA() const { return TTIImpl->useAA(); }
249
Chandler Carruth539edf42013-01-05 11:43:11 +0000250bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000251 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000252}
253
254unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000255 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000256}
257
258unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000259 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000260}
261
262bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000263 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000264}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000265bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
266 return TTIImpl->shouldBuildLookupTablesForConstant(C);
267}
Chandler Carruth539edf42013-01-05 11:43:11 +0000268
Zaara Syeda1f59ae32018-01-30 16:17:22 +0000269bool TargetTransformInfo::useColdCCForColdCall(Function &F) const {
270 return TTIImpl->useColdCCForColdCall(F);
271}
272
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000273unsigned TargetTransformInfo::
274getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
275 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
276}
277
278unsigned TargetTransformInfo::
279getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
280 unsigned VF) const {
281 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
282}
283
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000284bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
285 return TTIImpl->supportsEfficientVectorElementLoadStore();
286}
287
Olivier Sallenave049d8032015-03-06 23:12:04 +0000288bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
289 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
290}
291
Clement Courbetb2c3eb82017-10-30 14:19:33 +0000292const TargetTransformInfo::MemCmpExpansionOptions *
293TargetTransformInfo::enableMemCmpExpansion(bool IsZeroCmp) const {
294 return TTIImpl->enableMemCmpExpansion(IsZeroCmp);
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000295}
296
Silviu Baranga61bdc512015-08-10 14:50:54 +0000297bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
298 return TTIImpl->enableInterleavedAccessVectorization();
299}
300
Dorit Nuzman38bbf812018-10-14 08:50:06 +0000301bool TargetTransformInfo::enableMaskedInterleavedAccessVectorization() const {
302 return TTIImpl->enableMaskedInterleavedAccessVectorization();
303}
304
Renato Golin5cb666a2016-04-14 20:42:18 +0000305bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
306 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
307}
308
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000309bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
310 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000311 unsigned AddressSpace,
312 unsigned Alignment,
313 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000314 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000315 Alignment, Fast);
316}
317
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000318TargetTransformInfo::PopcntSupportKind
319TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000320 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000321}
322
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000323bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000324 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000325}
326
Sanjay Patel0de1a4b2017-11-27 21:15:43 +0000327bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const {
328 return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
329}
330
Chandler Carruth93205eb2015-08-05 18:08:10 +0000331int TargetTransformInfo::getFPOpCost(Type *Ty) const {
332 int Cost = TTIImpl->getFPOpCost(Ty);
333 assert(Cost >= 0 && "TTI should not produce negative costs!");
334 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000335}
336
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000337int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
338 const APInt &Imm,
339 Type *Ty) const {
340 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
341 assert(Cost >= 0 && "TTI should not produce negative costs!");
342 return Cost;
343}
344
Chandler Carruth93205eb2015-08-05 18:08:10 +0000345int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
346 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
347 assert(Cost >= 0 && "TTI should not produce negative costs!");
348 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000349}
350
Chandler Carruth93205eb2015-08-05 18:08:10 +0000351int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
352 const APInt &Imm, Type *Ty) const {
353 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
354 assert(Cost >= 0 && "TTI should not produce negative costs!");
355 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000356}
357
Chandler Carruth93205eb2015-08-05 18:08:10 +0000358int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
359 const APInt &Imm, Type *Ty) const {
360 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
361 assert(Cost >= 0 && "TTI should not produce negative costs!");
362 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000363}
364
Chandler Carruth539edf42013-01-05 11:43:11 +0000365unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000366 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000367}
368
Nadav Rotemb1791a72013-01-09 22:29:00 +0000369unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000370 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000371}
372
Adam Nemete29686e2017-05-15 21:15:01 +0000373unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
374 return TTIImpl->getMinVectorRegisterBitWidth();
375}
376
Krzysztof Parzyszek5d93fdf2018-03-27 16:14:11 +0000377bool TargetTransformInfo::shouldMaximizeVectorBandwidth(bool OptSize) const {
378 return TTIImpl->shouldMaximizeVectorBandwidth(OptSize);
379}
380
Krzysztof Parzyszekdfed9412018-04-13 20:16:32 +0000381unsigned TargetTransformInfo::getMinimumVF(unsigned ElemWidth) const {
382 return TTIImpl->getMinimumVF(ElemWidth);
383}
384
Jun Bum Limdee55652017-04-03 19:20:07 +0000385bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
386 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
387 return TTIImpl->shouldConsiderAddressTypePromotion(
388 I, AllowPromotionWithoutCommonHeader);
389}
390
Adam Nemetaf761102016-01-21 18:28:36 +0000391unsigned TargetTransformInfo::getCacheLineSize() const {
392 return TTIImpl->getCacheLineSize();
393}
394
Tobias Grosserd7eb6192017-08-24 09:46:25 +0000395llvm::Optional<unsigned> TargetTransformInfo::getCacheSize(CacheLevel Level)
396 const {
397 return TTIImpl->getCacheSize(Level);
398}
399
400llvm::Optional<unsigned> TargetTransformInfo::getCacheAssociativity(
401 CacheLevel Level) const {
402 return TTIImpl->getCacheAssociativity(Level);
403}
404
Adam Nemetdadfbb52016-01-27 22:21:25 +0000405unsigned TargetTransformInfo::getPrefetchDistance() const {
406 return TTIImpl->getPrefetchDistance();
407}
408
Adam Nemet6d8beec2016-03-18 00:27:38 +0000409unsigned TargetTransformInfo::getMinPrefetchStride() const {
410 return TTIImpl->getMinPrefetchStride();
411}
412
Adam Nemet709e3042016-03-18 00:27:43 +0000413unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
414 return TTIImpl->getMaxPrefetchIterationsAhead();
415}
416
Wei Mi062c7442015-05-06 17:12:25 +0000417unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
418 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000419}
420
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000421TargetTransformInfo::OperandValueKind
Simon Pilgrim077a42c2018-11-13 13:45:10 +0000422TargetTransformInfo::getOperandInfo(Value *V, OperandValueProperties &OpProps) {
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000423 OperandValueKind OpInfo = OK_AnyValue;
424 OpProps = OP_None;
425
426 if (auto *CI = dyn_cast<ConstantInt>(V)) {
427 if (CI->getValue().isPowerOf2())
428 OpProps = OP_PowerOf2;
429 return OK_UniformConstantValue;
430 }
431
Simon Pilgrim2b166c52018-11-14 15:04:08 +0000432 // A broadcast shuffle creates a uniform value.
433 // TODO: Add support for non-zero index broadcasts.
434 // TODO: Add support for different source vector width.
435 if (auto *ShuffleInst = dyn_cast<ShuffleVectorInst>(V))
436 if (ShuffleInst->isZeroEltSplat())
437 OpInfo = OK_UniformValue;
438
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000439 const Value *Splat = getSplatValue(V);
440
441 // Check for a splat of a constant or for a non uniform vector of constants
442 // and check if the constant(s) are all powers of two.
443 if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
444 OpInfo = OK_NonUniformConstantValue;
445 if (Splat) {
446 OpInfo = OK_UniformConstantValue;
447 if (auto *CI = dyn_cast<ConstantInt>(Splat))
448 if (CI->getValue().isPowerOf2())
449 OpProps = OP_PowerOf2;
450 } else if (auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
451 OpProps = OP_PowerOf2;
452 for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
453 if (auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
454 if (CI->getValue().isPowerOf2())
455 continue;
456 OpProps = OP_None;
457 break;
458 }
459 }
460 }
461
462 // Check for a splat of a uniform value. This is not loop aware, so return
463 // true only for the obviously uniform cases (argument, globalvalue)
464 if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
465 OpInfo = OK_UniformValue;
466
467 return OpInfo;
468}
469
Chandler Carruth93205eb2015-08-05 18:08:10 +0000470int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000471 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
472 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000473 OperandValueProperties Opd2PropInfo,
474 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000475 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000476 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000477 assert(Cost >= 0 && "TTI should not produce negative costs!");
478 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000479}
480
Chandler Carruth93205eb2015-08-05 18:08:10 +0000481int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
482 Type *SubTp) const {
483 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
484 assert(Cost >= 0 && "TTI should not produce negative costs!");
485 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000486}
487
Chandler Carruth93205eb2015-08-05 18:08:10 +0000488int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000489 Type *Src, const Instruction *I) const {
490 assert ((I == nullptr || I->getOpcode() == Opcode) &&
491 "Opcode should reflect passed instruction.");
492 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000493 assert(Cost >= 0 && "TTI should not produce negative costs!");
494 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000495}
496
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000497int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
498 VectorType *VecTy,
499 unsigned Index) const {
500 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
501 assert(Cost >= 0 && "TTI should not produce negative costs!");
502 return Cost;
503}
504
Chandler Carruth93205eb2015-08-05 18:08:10 +0000505int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
506 int Cost = TTIImpl->getCFInstrCost(Opcode);
507 assert(Cost >= 0 && "TTI should not produce negative costs!");
508 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000509}
510
Chandler Carruth93205eb2015-08-05 18:08:10 +0000511int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000512 Type *CondTy, const Instruction *I) const {
513 assert ((I == nullptr || I->getOpcode() == Opcode) &&
514 "Opcode should reflect passed instruction.");
515 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000516 assert(Cost >= 0 && "TTI should not produce negative costs!");
517 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000518}
519
Chandler Carruth93205eb2015-08-05 18:08:10 +0000520int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
521 unsigned Index) const {
522 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
523 assert(Cost >= 0 && "TTI should not produce negative costs!");
524 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000525}
526
Chandler Carruth93205eb2015-08-05 18:08:10 +0000527int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
528 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000529 unsigned AddressSpace,
530 const Instruction *I) const {
531 assert ((I == nullptr || I->getOpcode() == Opcode) &&
532 "Opcode should reflect passed instruction.");
533 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000534 assert(Cost >= 0 && "TTI should not produce negative costs!");
535 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000536}
537
Chandler Carruth93205eb2015-08-05 18:08:10 +0000538int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
539 unsigned Alignment,
540 unsigned AddressSpace) const {
541 int Cost =
542 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
543 assert(Cost >= 0 && "TTI should not produce negative costs!");
544 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000545}
546
Elena Demikhovsky54946982015-12-28 20:10:59 +0000547int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
548 Value *Ptr, bool VariableMask,
549 unsigned Alignment) const {
550 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
551 Alignment);
552 assert(Cost >= 0 && "TTI should not produce negative costs!");
553 return Cost;
554}
555
Chandler Carruth93205eb2015-08-05 18:08:10 +0000556int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000557 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
Dorit Nuzman34da6dd2018-10-31 09:57:56 +0000558 unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond,
559 bool UseMaskForGaps) const {
560 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
561 Alignment, AddressSpace,
562 UseMaskForCond,
563 UseMaskForGaps);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000564 assert(Cost >= 0 && "TTI should not produce negative costs!");
565 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000566}
567
Chandler Carruth93205eb2015-08-05 18:08:10 +0000568int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000569 ArrayRef<Type *> Tys, FastMathFlags FMF,
570 unsigned ScalarizationCostPassed) const {
571 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
572 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000573 assert(Cost >= 0 && "TTI should not produce negative costs!");
574 return Cost;
575}
576
Elena Demikhovsky54946982015-12-28 20:10:59 +0000577int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000578 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
579 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000580 assert(Cost >= 0 && "TTI should not produce negative costs!");
581 return Cost;
582}
583
Chandler Carruth93205eb2015-08-05 18:08:10 +0000584int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
585 ArrayRef<Type *> Tys) const {
586 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
587 assert(Cost >= 0 && "TTI should not produce negative costs!");
588 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000589}
590
Chandler Carruth539edf42013-01-05 11:43:11 +0000591unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000592 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000593}
594
Chandler Carruth93205eb2015-08-05 18:08:10 +0000595int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000596 ScalarEvolution *SE,
597 const SCEV *Ptr) const {
598 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000599 assert(Cost >= 0 && "TTI should not produce negative costs!");
600 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000601}
Chandler Carruth539edf42013-01-05 11:43:11 +0000602
Sjoerd Meijerea31ddb2019-04-30 10:28:50 +0000603int TargetTransformInfo::getMemcpyCost(const Instruction *I) const {
604 int Cost = TTIImpl->getMemcpyCost(I);
605 assert(Cost >= 0 && "TTI should not produce negative costs!");
606 return Cost;
607}
608
Alexey Bataev3e9b3eb2017-07-31 14:19:32 +0000609int TargetTransformInfo::getArithmeticReductionCost(unsigned Opcode, Type *Ty,
610 bool IsPairwiseForm) const {
611 int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000612 assert(Cost >= 0 && "TTI should not produce negative costs!");
613 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000614}
615
Alexey Bataev6dd29fc2017-09-08 13:49:36 +0000616int TargetTransformInfo::getMinMaxReductionCost(Type *Ty, Type *CondTy,
617 bool IsPairwiseForm,
618 bool IsUnsigned) const {
619 int Cost =
620 TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned);
621 assert(Cost >= 0 && "TTI should not produce negative costs!");
622 return Cost;
623}
624
Chandler Carruth705b1852015-01-31 03:43:40 +0000625unsigned
626TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
627 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000628}
629
630bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
631 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000632 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000633}
634
Anna Thomasb2a212c2017-06-06 16:45:25 +0000635unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
636 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
637}
638
Chandler Carruth705b1852015-01-31 03:43:40 +0000639Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
640 IntrinsicInst *Inst, Type *ExpectedType) const {
641 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
642}
643
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000644Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
645 Value *Length,
646 unsigned SrcAlign,
647 unsigned DestAlign) const {
648 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
649 DestAlign);
650}
651
652void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
653 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
654 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
655 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
656 SrcAlign, DestAlign);
657}
658
Eric Christopherd566fb12015-07-29 22:09:48 +0000659bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
660 const Function *Callee) const {
661 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000662}
663
Tom Stellard3d36e5c2019-01-16 05:15:31 +0000664bool TargetTransformInfo::areFunctionArgsABICompatible(
665 const Function *Caller, const Function *Callee,
666 SmallPtrSetImpl<Argument *> &Args) const {
667 return TTIImpl->areFunctionArgsABICompatible(Caller, Callee, Args);
668}
669
Krzysztof Parzyszek0b377e02018-03-26 13:10:09 +0000670bool TargetTransformInfo::isIndexedLoadLegal(MemIndexedMode Mode,
671 Type *Ty) const {
672 return TTIImpl->isIndexedLoadLegal(Mode, Ty);
673}
674
675bool TargetTransformInfo::isIndexedStoreLegal(MemIndexedMode Mode,
676 Type *Ty) const {
677 return TTIImpl->isIndexedStoreLegal(Mode, Ty);
678}
679
Volkan Keles1c386812016-10-03 10:31:34 +0000680unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
681 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
682}
683
684bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
685 return TTIImpl->isLegalToVectorizeLoad(LI);
686}
687
688bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
689 return TTIImpl->isLegalToVectorizeStore(SI);
690}
691
692bool TargetTransformInfo::isLegalToVectorizeLoadChain(
693 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
694 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
695 AddrSpace);
696}
697
698bool TargetTransformInfo::isLegalToVectorizeStoreChain(
699 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
700 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
701 AddrSpace);
702}
703
704unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
705 unsigned LoadSize,
706 unsigned ChainSizeInBytes,
707 VectorType *VecTy) const {
708 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
709}
710
711unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
712 unsigned StoreSize,
713 unsigned ChainSizeInBytes,
714 VectorType *VecTy) const {
715 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
716}
717
Amara Emersoncf9daa32017-05-09 10:43:25 +0000718bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
719 Type *Ty, ReductionFlags Flags) const {
720 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
721}
722
Amara Emerson836b0f42017-05-10 09:42:49 +0000723bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
724 return TTIImpl->shouldExpandReduction(II);
725}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000726
Amara Emerson14688222019-06-17 23:20:29 +0000727unsigned TargetTransformInfo::getGISelRematGlobalCost() const {
728 return TTIImpl->getGISelRematGlobalCost();
729}
730
Guozhi Wei62d64142017-09-08 22:29:17 +0000731int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
732 return TTIImpl->getInstructionLatency(I);
733}
734
Guozhi Wei62d64142017-09-08 22:29:17 +0000735static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft,
736 unsigned Level) {
737 // We don't need a shuffle if we just want to have element 0 in position 0 of
738 // the vector.
739 if (!SI && Level == 0 && IsLeft)
740 return true;
741 else if (!SI)
742 return false;
743
744 SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1);
745
746 // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether
747 // we look at the left or right side.
748 for (unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2)
749 Mask[i] = val;
750
751 SmallVector<int, 16> ActualMask = SI->getShuffleMask();
752 return Mask == ActualMask;
753}
754
755namespace {
756/// Kind of the reduction data.
757enum ReductionKind {
758 RK_None, /// Not a reduction.
759 RK_Arithmetic, /// Binary reduction data.
760 RK_MinMax, /// Min/max reduction data.
761 RK_UnsignedMinMax, /// Unsigned min/max reduction data.
762};
763/// Contains opcode + LHS/RHS parts of the reduction operations.
764struct ReductionData {
765 ReductionData() = delete;
766 ReductionData(ReductionKind Kind, unsigned Opcode, Value *LHS, Value *RHS)
767 : Opcode(Opcode), LHS(LHS), RHS(RHS), Kind(Kind) {
768 assert(Kind != RK_None && "expected binary or min/max reduction only.");
769 }
770 unsigned Opcode = 0;
771 Value *LHS = nullptr;
772 Value *RHS = nullptr;
773 ReductionKind Kind = RK_None;
774 bool hasSameData(ReductionData &RD) const {
775 return Kind == RD.Kind && Opcode == RD.Opcode;
776 }
777};
778} // namespace
779
780static Optional<ReductionData> getReductionData(Instruction *I) {
781 Value *L, *R;
782 if (m_BinOp(m_Value(L), m_Value(R)).match(I))
Fangrui Songf78650a2018-07-30 19:41:25 +0000783 return ReductionData(RK_Arithmetic, I->getOpcode(), L, R);
Guozhi Wei62d64142017-09-08 22:29:17 +0000784 if (auto *SI = dyn_cast<SelectInst>(I)) {
785 if (m_SMin(m_Value(L), m_Value(R)).match(SI) ||
786 m_SMax(m_Value(L), m_Value(R)).match(SI) ||
787 m_OrdFMin(m_Value(L), m_Value(R)).match(SI) ||
788 m_OrdFMax(m_Value(L), m_Value(R)).match(SI) ||
789 m_UnordFMin(m_Value(L), m_Value(R)).match(SI) ||
790 m_UnordFMax(m_Value(L), m_Value(R)).match(SI)) {
791 auto *CI = cast<CmpInst>(SI->getCondition());
Fangrui Songf78650a2018-07-30 19:41:25 +0000792 return ReductionData(RK_MinMax, CI->getOpcode(), L, R);
793 }
Guozhi Wei62d64142017-09-08 22:29:17 +0000794 if (m_UMin(m_Value(L), m_Value(R)).match(SI) ||
795 m_UMax(m_Value(L), m_Value(R)).match(SI)) {
796 auto *CI = cast<CmpInst>(SI->getCondition());
797 return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R);
798 }
799 }
800 return llvm::None;
801}
802
803static ReductionKind matchPairwiseReductionAtLevel(Instruction *I,
804 unsigned Level,
805 unsigned NumLevels) {
806 // Match one level of pairwise operations.
807 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
808 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
809 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
810 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
811 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
812 if (!I)
813 return RK_None;
814
815 assert(I->getType()->isVectorTy() && "Expecting a vector type");
816
817 Optional<ReductionData> RD = getReductionData(I);
818 if (!RD)
819 return RK_None;
820
821 ShuffleVectorInst *LS = dyn_cast<ShuffleVectorInst>(RD->LHS);
822 if (!LS && Level)
823 return RK_None;
824 ShuffleVectorInst *RS = dyn_cast<ShuffleVectorInst>(RD->RHS);
825 if (!RS && Level)
826 return RK_None;
827
828 // On level 0 we can omit one shufflevector instruction.
829 if (!Level && !RS && !LS)
830 return RK_None;
831
832 // Shuffle inputs must match.
833 Value *NextLevelOpL = LS ? LS->getOperand(0) : nullptr;
834 Value *NextLevelOpR = RS ? RS->getOperand(0) : nullptr;
835 Value *NextLevelOp = nullptr;
836 if (NextLevelOpR && NextLevelOpL) {
837 // If we have two shuffles their operands must match.
838 if (NextLevelOpL != NextLevelOpR)
839 return RK_None;
840
841 NextLevelOp = NextLevelOpL;
842 } else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) {
843 // On the first level we can omit the shufflevector <0, undef,...>. So the
844 // input to the other shufflevector <1, undef> must match with one of the
845 // inputs to the current binary operation.
846 // Example:
847 // %NextLevelOpL = shufflevector %R, <1, undef ...>
848 // %BinOp = fadd %NextLevelOpL, %R
849 if (NextLevelOpL && NextLevelOpL != RD->RHS)
850 return RK_None;
851 else if (NextLevelOpR && NextLevelOpR != RD->LHS)
852 return RK_None;
853
854 NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS;
855 } else
856 return RK_None;
857
858 // Check that the next levels binary operation exists and matches with the
859 // current one.
860 if (Level + 1 != NumLevels) {
861 Optional<ReductionData> NextLevelRD =
862 getReductionData(cast<Instruction>(NextLevelOp));
863 if (!NextLevelRD || !RD->hasSameData(*NextLevelRD))
864 return RK_None;
865 }
866
867 // Shuffle mask for pairwise operation must match.
868 if (matchPairwiseShuffleMask(LS, /*IsLeft=*/true, Level)) {
869 if (!matchPairwiseShuffleMask(RS, /*IsLeft=*/false, Level))
870 return RK_None;
871 } else if (matchPairwiseShuffleMask(RS, /*IsLeft=*/true, Level)) {
872 if (!matchPairwiseShuffleMask(LS, /*IsLeft=*/false, Level))
873 return RK_None;
874 } else {
875 return RK_None;
876 }
877
878 if (++Level == NumLevels)
879 return RD->Kind;
880
881 // Match next level.
882 return matchPairwiseReductionAtLevel(cast<Instruction>(NextLevelOp), Level,
883 NumLevels);
884}
885
886static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot,
887 unsigned &Opcode, Type *&Ty) {
888 if (!EnableReduxCost)
889 return RK_None;
890
891 // Need to extract the first element.
892 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
893 unsigned Idx = ~0u;
894 if (CI)
895 Idx = CI->getZExtValue();
896 if (Idx != 0)
897 return RK_None;
898
899 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
900 if (!RdxStart)
901 return RK_None;
902 Optional<ReductionData> RD = getReductionData(RdxStart);
903 if (!RD)
904 return RK_None;
905
906 Type *VecTy = RdxStart->getType();
907 unsigned NumVecElems = VecTy->getVectorNumElements();
908 if (!isPowerOf2_32(NumVecElems))
909 return RK_None;
910
911 // We look for a sequence of shuffle,shuffle,add triples like the following
912 // that builds a pairwise reduction tree.
Fangrui Songf78650a2018-07-30 19:41:25 +0000913 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000914 // (X0, X1, X2, X3)
915 // (X0 + X1, X2 + X3, undef, undef)
916 // ((X0 + X1) + (X2 + X3), undef, undef, undef)
Fangrui Songf78650a2018-07-30 19:41:25 +0000917 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000918 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
919 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
920 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
921 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
922 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
923 // %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
924 // <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
925 // %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
926 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
927 // %bin.rdx8 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
928 // %r = extractelement <4 x float> %bin.rdx8, i32 0
929 if (matchPairwiseReductionAtLevel(RdxStart, 0, Log2_32(NumVecElems)) ==
930 RK_None)
931 return RK_None;
932
933 Opcode = RD->Opcode;
934 Ty = VecTy;
935
936 return RD->Kind;
937}
938
939static std::pair<Value *, ShuffleVectorInst *>
940getShuffleAndOtherOprd(Value *L, Value *R) {
941 ShuffleVectorInst *S = nullptr;
942
943 if ((S = dyn_cast<ShuffleVectorInst>(L)))
944 return std::make_pair(R, S);
945
946 S = dyn_cast<ShuffleVectorInst>(R);
947 return std::make_pair(L, S);
948}
949
950static ReductionKind
951matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot,
952 unsigned &Opcode, Type *&Ty) {
953 if (!EnableReduxCost)
954 return RK_None;
955
956 // Need to extract the first element.
957 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
958 unsigned Idx = ~0u;
959 if (CI)
960 Idx = CI->getZExtValue();
961 if (Idx != 0)
962 return RK_None;
963
964 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
965 if (!RdxStart)
966 return RK_None;
967 Optional<ReductionData> RD = getReductionData(RdxStart);
968 if (!RD)
969 return RK_None;
970
971 Type *VecTy = ReduxRoot->getOperand(0)->getType();
972 unsigned NumVecElems = VecTy->getVectorNumElements();
973 if (!isPowerOf2_32(NumVecElems))
974 return RK_None;
975
976 // We look for a sequence of shuffles and adds like the following matching one
977 // fadd, shuffle vector pair at a time.
Fangrui Songf78650a2018-07-30 19:41:25 +0000978 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000979 // %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef,
980 // <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
981 // %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
982 // %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef,
983 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
984 // %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
985 // %r = extractelement <4 x float> %bin.rdx8, i32 0
986
987 unsigned MaskStart = 1;
988 Instruction *RdxOp = RdxStart;
Fangrui Songf78650a2018-07-30 19:41:25 +0000989 SmallVector<int, 32> ShuffleMask(NumVecElems, 0);
Guozhi Wei62d64142017-09-08 22:29:17 +0000990 unsigned NumVecElemsRemain = NumVecElems;
991 while (NumVecElemsRemain - 1) {
992 // Check for the right reduction operation.
993 if (!RdxOp)
994 return RK_None;
995 Optional<ReductionData> RDLevel = getReductionData(RdxOp);
996 if (!RDLevel || !RDLevel->hasSameData(*RD))
997 return RK_None;
998
999 Value *NextRdxOp;
1000 ShuffleVectorInst *Shuffle;
1001 std::tie(NextRdxOp, Shuffle) =
1002 getShuffleAndOtherOprd(RDLevel->LHS, RDLevel->RHS);
1003
1004 // Check the current reduction operation and the shuffle use the same value.
1005 if (Shuffle == nullptr)
1006 return RK_None;
1007 if (Shuffle->getOperand(0) != NextRdxOp)
1008 return RK_None;
1009
1010 // Check that shuffle masks matches.
1011 for (unsigned j = 0; j != MaskStart; ++j)
1012 ShuffleMask[j] = MaskStart + j;
1013 // Fill the rest of the mask with -1 for undef.
1014 std::fill(&ShuffleMask[MaskStart], ShuffleMask.end(), -1);
1015
1016 SmallVector<int, 16> Mask = Shuffle->getShuffleMask();
1017 if (ShuffleMask != Mask)
1018 return RK_None;
1019
1020 RdxOp = dyn_cast<Instruction>(NextRdxOp);
1021 NumVecElemsRemain /= 2;
1022 MaskStart *= 2;
1023 }
1024
1025 Opcode = RD->Opcode;
1026 Ty = VecTy;
1027 return RD->Kind;
1028}
1029
1030int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
1031 switch (I->getOpcode()) {
1032 case Instruction::GetElementPtr:
1033 return getUserCost(I);
1034
1035 case Instruction::Ret:
1036 case Instruction::PHI:
1037 case Instruction::Br: {
1038 return getCFInstrCost(I->getOpcode());
1039 }
1040 case Instruction::Add:
1041 case Instruction::FAdd:
1042 case Instruction::Sub:
1043 case Instruction::FSub:
1044 case Instruction::Mul:
1045 case Instruction::FMul:
1046 case Instruction::UDiv:
1047 case Instruction::SDiv:
1048 case Instruction::FDiv:
1049 case Instruction::URem:
1050 case Instruction::SRem:
1051 case Instruction::FRem:
1052 case Instruction::Shl:
1053 case Instruction::LShr:
1054 case Instruction::AShr:
1055 case Instruction::And:
1056 case Instruction::Or:
1057 case Instruction::Xor: {
Simon Pilgrim4162d772018-05-22 10:40:09 +00001058 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1059 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1060 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1061 Op2VK = getOperandInfo(I->getOperand(1), Op2VP);
1062 SmallVector<const Value *, 2> Operands(I->operand_values());
1063 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1064 Op1VP, Op2VP, Operands);
Guozhi Wei62d64142017-09-08 22:29:17 +00001065 }
Craig Topper50d50282019-05-28 04:09:18 +00001066 case Instruction::FNeg: {
1067 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1068 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1069 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1070 Op2VK = OK_AnyValue;
1071 Op2VP = OP_None;
1072 SmallVector<const Value *, 2> Operands(I->operand_values());
1073 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1074 Op1VP, Op2VP, Operands);
1075 }
Guozhi Wei62d64142017-09-08 22:29:17 +00001076 case Instruction::Select: {
1077 const SelectInst *SI = cast<SelectInst>(I);
1078 Type *CondTy = SI->getCondition()->getType();
1079 return getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, I);
1080 }
1081 case Instruction::ICmp:
1082 case Instruction::FCmp: {
1083 Type *ValTy = I->getOperand(0)->getType();
1084 return getCmpSelInstrCost(I->getOpcode(), ValTy, I->getType(), I);
1085 }
1086 case Instruction::Store: {
1087 const StoreInst *SI = cast<StoreInst>(I);
1088 Type *ValTy = SI->getValueOperand()->getType();
1089 return getMemoryOpCost(I->getOpcode(), ValTy,
1090 SI->getAlignment(),
1091 SI->getPointerAddressSpace(), I);
1092 }
1093 case Instruction::Load: {
1094 const LoadInst *LI = cast<LoadInst>(I);
1095 return getMemoryOpCost(I->getOpcode(), I->getType(),
1096 LI->getAlignment(),
1097 LI->getPointerAddressSpace(), I);
1098 }
1099 case Instruction::ZExt:
1100 case Instruction::SExt:
1101 case Instruction::FPToUI:
1102 case Instruction::FPToSI:
1103 case Instruction::FPExt:
1104 case Instruction::PtrToInt:
1105 case Instruction::IntToPtr:
1106 case Instruction::SIToFP:
1107 case Instruction::UIToFP:
1108 case Instruction::Trunc:
1109 case Instruction::FPTrunc:
1110 case Instruction::BitCast:
1111 case Instruction::AddrSpaceCast: {
1112 Type *SrcTy = I->getOperand(0)->getType();
1113 return getCastInstrCost(I->getOpcode(), I->getType(), SrcTy, I);
1114 }
1115 case Instruction::ExtractElement: {
1116 const ExtractElementInst * EEI = cast<ExtractElementInst>(I);
1117 ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1));
1118 unsigned Idx = -1;
1119 if (CI)
1120 Idx = CI->getZExtValue();
1121
1122 // Try to match a reduction sequence (series of shufflevector and vector
1123 // adds followed by a extractelement).
1124 unsigned ReduxOpCode;
1125 Type *ReduxType;
1126
1127 switch (matchVectorSplittingReduction(EEI, ReduxOpCode, ReduxType)) {
1128 case RK_Arithmetic:
1129 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1130 /*IsPairwiseForm=*/false);
1131 case RK_MinMax:
1132 return getMinMaxReductionCost(
1133 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1134 /*IsPairwiseForm=*/false, /*IsUnsigned=*/false);
1135 case RK_UnsignedMinMax:
1136 return getMinMaxReductionCost(
1137 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1138 /*IsPairwiseForm=*/false, /*IsUnsigned=*/true);
1139 case RK_None:
1140 break;
1141 }
1142
1143 switch (matchPairwiseReduction(EEI, ReduxOpCode, ReduxType)) {
1144 case RK_Arithmetic:
1145 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1146 /*IsPairwiseForm=*/true);
1147 case RK_MinMax:
1148 return getMinMaxReductionCost(
1149 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1150 /*IsPairwiseForm=*/true, /*IsUnsigned=*/false);
1151 case RK_UnsignedMinMax:
1152 return getMinMaxReductionCost(
1153 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1154 /*IsPairwiseForm=*/true, /*IsUnsigned=*/true);
1155 case RK_None:
1156 break;
1157 }
1158
1159 return getVectorInstrCost(I->getOpcode(),
1160 EEI->getOperand(0)->getType(), Idx);
1161 }
1162 case Instruction::InsertElement: {
1163 const InsertElementInst * IE = cast<InsertElementInst>(I);
1164 ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
Fangrui Songf78650a2018-07-30 19:41:25 +00001165 unsigned Idx = -1;
Guozhi Wei62d64142017-09-08 22:29:17 +00001166 if (CI)
1167 Idx = CI->getZExtValue();
1168 return getVectorInstrCost(I->getOpcode(),
1169 IE->getType(), Idx);
1170 }
1171 case Instruction::ShuffleVector: {
1172 const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001173 Type *Ty = Shuffle->getType();
1174 Type *SrcTy = Shuffle->getOperand(0)->getType();
1175
1176 // TODO: Identify and add costs for insert subvector, etc.
1177 int SubIndex;
1178 if (Shuffle->isExtractSubvectorMask(SubIndex))
Simon Pilgrim26e1c882018-11-09 18:30:59 +00001179 return TTIImpl->getShuffleCost(SK_ExtractSubvector, SrcTy, SubIndex, Ty);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001180
Sanjay Patel2ca33602018-06-19 18:44:00 +00001181 if (Shuffle->changesLength())
1182 return -1;
Fangrui Songf78650a2018-07-30 19:41:25 +00001183
Sanjay Patel2ca33602018-06-19 18:44:00 +00001184 if (Shuffle->isIdentity())
1185 return 0;
Guozhi Wei62d64142017-09-08 22:29:17 +00001186
Sanjay Patel2ca33602018-06-19 18:44:00 +00001187 if (Shuffle->isReverse())
1188 return TTIImpl->getShuffleCost(SK_Reverse, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001189
Sanjay Patel2ca33602018-06-19 18:44:00 +00001190 if (Shuffle->isSelect())
1191 return TTIImpl->getShuffleCost(SK_Select, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001192
Sanjay Patel2ca33602018-06-19 18:44:00 +00001193 if (Shuffle->isTranspose())
1194 return TTIImpl->getShuffleCost(SK_Transpose, Ty, 0, nullptr);
Matthew Simpsonb4096eb2018-04-26 13:48:33 +00001195
Sanjay Patel2ca33602018-06-19 18:44:00 +00001196 if (Shuffle->isZeroEltSplat())
1197 return TTIImpl->getShuffleCost(SK_Broadcast, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001198
Sanjay Patel2ca33602018-06-19 18:44:00 +00001199 if (Shuffle->isSingleSource())
1200 return TTIImpl->getShuffleCost(SK_PermuteSingleSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001201
Sanjay Patel2ca33602018-06-19 18:44:00 +00001202 return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001203 }
1204 case Instruction::Call:
1205 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
1206 SmallVector<Value *, 4> Args(II->arg_operands());
1207
1208 FastMathFlags FMF;
1209 if (auto *FPMO = dyn_cast<FPMathOperator>(II))
1210 FMF = FPMO->getFastMathFlags();
1211
1212 return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(),
1213 Args, FMF);
1214 }
1215 return -1;
1216 default:
1217 // We don't have any information on this instruction.
1218 return -1;
1219 }
1220}
1221
Chandler Carruth705b1852015-01-31 03:43:40 +00001222TargetTransformInfo::Concept::~Concept() {}
1223
Chandler Carruthe0385522015-02-01 10:11:22 +00001224TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
1225
1226TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001227 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +00001228 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +00001229
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001230TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +00001231 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +00001232 return TTICallback(F);
1233}
1234
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001235AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001236
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001237TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +00001238 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +00001239}
1240
Chandler Carruth705b1852015-01-31 03:43:40 +00001241// Register the basic pass.
1242INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
1243 "Target Transform Information", false, true)
1244char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +00001245
Chandler Carruth705b1852015-01-31 03:43:40 +00001246void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +00001247
Chandler Carruth705b1852015-01-31 03:43:40 +00001248TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001249 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001250 initializeTargetTransformInfoWrapperPassPass(
1251 *PassRegistry::getPassRegistry());
1252}
1253
1254TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001255 TargetIRAnalysis TIRA)
1256 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001257 initializeTargetTransformInfoWrapperPassPass(
1258 *PassRegistry::getPassRegistry());
1259}
1260
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001261TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +00001262 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001263 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001264 return *TTI;
1265}
1266
Chandler Carruth93dcdc42015-01-31 11:17:59 +00001267ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001268llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
1269 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +00001270}