blob: 693caadcfc2f448a2dd77ac60141bf590e75019b [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
Chen Zhengc5b918d2019-06-19 01:26:31 +000043bool HardwareLoopInfo::isHardwareLoopCandidate(ScalarEvolution &SE,
44 LoopInfo &LI, DominatorTree &DT,
45 bool ForceNestedLoop,
46 bool ForceHardwareLoopPHI) {
47 SmallVector<BasicBlock *, 4> ExitingBlocks;
48 L->getExitingBlocks(ExitingBlocks);
49
50 for (SmallVectorImpl<BasicBlock *>::iterator I = ExitingBlocks.begin(),
51 IE = ExitingBlocks.end();
52 I != IE; ++I) {
53 BasicBlock *BB = *I;
54
55 // If we pass the updated counter back through a phi, we need to know
56 // which latch the updated value will be coming from.
57 if (!L->isLoopLatch(BB)) {
58 if (ForceHardwareLoopPHI || CounterInReg)
59 continue;
60 }
61
62 const SCEV *EC = SE.getExitCount(L, BB);
63 if (isa<SCEVCouldNotCompute>(EC))
64 continue;
65 if (const SCEVConstant *ConstEC = dyn_cast<SCEVConstant>(EC)) {
66 if (ConstEC->getValue()->isZero())
67 continue;
68 } else if (!SE.isLoopInvariant(EC, L))
69 continue;
70
71 if (SE.getTypeSizeInBits(EC->getType()) > CountType->getBitWidth())
72 continue;
73
74 // If this exiting block is contained in a nested loop, it is not eligible
75 // for insertion of the branch-and-decrement since the inner loop would
76 // end up messing up the value in the CTR.
77 if (!IsNestingLegal && LI.getLoopFor(BB) != L && !ForceNestedLoop)
78 continue;
79
80 // We now have a loop-invariant count of loop iterations (which is not the
81 // constant zero) for which we know that this loop will not exit via this
82 // existing block.
83
84 // We need to make sure that this block will run on every loop iteration.
85 // For this to be true, we must dominate all blocks with backedges. Such
86 // blocks are in-loop predecessors to the header block.
87 bool NotAlways = false;
88 for (pred_iterator PI = pred_begin(L->getHeader()),
89 PIE = pred_end(L->getHeader());
90 PI != PIE; ++PI) {
91 if (!L->contains(*PI))
92 continue;
93
94 if (!DT.dominates(*I, *PI)) {
95 NotAlways = true;
96 break;
97 }
98 }
99
100 if (NotAlways)
101 continue;
102
103 // Make sure this blocks ends with a conditional branch.
104 Instruction *TI = BB->getTerminator();
105 if (!TI)
106 continue;
107
108 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
109 if (!BI->isConditional())
110 continue;
111
112 ExitBranch = BI;
113 } else
114 continue;
115
116 // Note that this block may not be the loop latch block, even if the loop
117 // has a latch block.
118 ExitBlock = *I;
119 ExitCount = EC;
120 break;
121 }
122
123 if (!ExitBlock)
124 return false;
125 return true;
126}
127
Mehdi Amini5010ebf2015-07-09 02:08:42 +0000128TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000129 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
130
Chandler Carruth705b1852015-01-31 03:43:40 +0000131TargetTransformInfo::~TargetTransformInfo() {}
Nadav Rotem5dc203e2012-10-18 23:22:48 +0000132
Chandler Carruth705b1852015-01-31 03:43:40 +0000133TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
134 : TTIImpl(std::move(Arg.TTIImpl)) {}
Chandler Carruth539edf42013-01-05 11:43:11 +0000135
Chandler Carruth705b1852015-01-31 03:43:40 +0000136TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
137 TTIImpl = std::move(RHS.TTIImpl);
138 return *this;
Chandler Carruth539edf42013-01-05 11:43:11 +0000139}
140
Chandler Carruth93205eb2015-08-05 18:08:10 +0000141int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty,
142 Type *OpTy) const {
143 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy);
144 assert(Cost >= 0 && "TTI should not produce negative costs!");
145 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +0000146}
147
Sjoerd Meijer31ff6472019-03-12 09:48:02 +0000148int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs,
149 const User *U) const {
150 int Cost = TTIImpl->getCallCost(FTy, NumArgs, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000151 assert(Cost >= 0 && "TTI should not produce negative costs!");
152 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000153}
154
Chandler Carruth93205eb2015-08-05 18:08:10 +0000155int TargetTransformInfo::getCallCost(const Function *F,
Sjoerd Meijer31ff6472019-03-12 09:48:02 +0000156 ArrayRef<const Value *> Arguments,
157 const User *U) const {
158 int Cost = TTIImpl->getCallCost(F, Arguments, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000159 assert(Cost >= 0 && "TTI should not produce negative costs!");
160 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000161}
162
Justin Lebar8650a4d2016-04-15 01:38:48 +0000163unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
164 return TTIImpl->getInliningThresholdMultiplier();
165}
166
Jingyue Wu15f3e822016-07-08 21:48:05 +0000167int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
168 ArrayRef<const Value *> Operands) const {
169 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands);
170}
171
Haicheng Wuabdef9e2017-07-15 02:12:16 +0000172int TargetTransformInfo::getExtCost(const Instruction *I,
173 const Value *Src) const {
174 return TTIImpl->getExtCost(I, Src);
175}
176
Chandler Carruth93205eb2015-08-05 18:08:10 +0000177int TargetTransformInfo::getIntrinsicCost(
Sjoerd Meijer31ff6472019-03-12 09:48:02 +0000178 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments,
179 const User *U) const {
180 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments, U);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000181 assert(Cost >= 0 && "TTI should not produce negative costs!");
182 return Cost;
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000183}
184
Jun Bum Lim919f9e82017-04-28 16:04:03 +0000185unsigned
186TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
187 unsigned &JTSize) const {
188 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize);
189}
190
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +0000191int TargetTransformInfo::getUserCost(const User *U,
192 ArrayRef<const Value *> Operands) const {
193 int Cost = TTIImpl->getUserCost(U, Operands);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000194 assert(Cost >= 0 && "TTI should not produce negative costs!");
195 return Cost;
Chandler Carruth511aa762013-01-21 01:27:39 +0000196}
197
Tom Stellard8b1e0212013-07-27 00:01:07 +0000198bool TargetTransformInfo::hasBranchDivergence() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000199 return TTIImpl->hasBranchDivergence();
Tom Stellard8b1e0212013-07-27 00:01:07 +0000200}
201
Jingyue Wu5da831c2015-04-10 05:03:50 +0000202bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
203 return TTIImpl->isSourceOfDivergence(V);
204}
205
Alexander Timofeev0f9c84c2017-06-15 19:33:10 +0000206bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
207 return TTIImpl->isAlwaysUniform(V);
208}
209
Matt Arsenault42b64782017-01-30 23:02:12 +0000210unsigned TargetTransformInfo::getFlatAddressSpace() const {
211 return TTIImpl->getFlatAddressSpace();
212}
213
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000214bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000215 return TTIImpl->isLoweredToCall(F);
Chandler Carruth0ba8db42013-01-22 11:26:02 +0000216}
217
Sam Parkerc5ef5022019-06-07 07:35:30 +0000218bool TargetTransformInfo::isHardwareLoopProfitable(
219 Loop *L, ScalarEvolution &SE, AssumptionCache &AC,
220 TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const {
221 return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
222}
223
Chandler Carruth705b1852015-01-31 03:43:40 +0000224void TargetTransformInfo::getUnrollingPreferences(
Geoff Berry66d9bdb2017-06-28 15:53:17 +0000225 Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const {
226 return TTIImpl->getUnrollingPreferences(L, SE, UP);
Hal Finkel8f2e7002013-09-11 19:25:43 +0000227}
228
Chandler Carruth539edf42013-01-05 11:43:11 +0000229bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000230 return TTIImpl->isLegalAddImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000231}
232
233bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000234 return TTIImpl->isLegalICmpImmediate(Imm);
Chandler Carruth539edf42013-01-05 11:43:11 +0000235}
236
237bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
238 int64_t BaseOffset,
239 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000240 int64_t Scale,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000241 unsigned AddrSpace,
242 Instruction *I) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000243 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000244 Scale, AddrSpace, I);
Chandler Carruth539edf42013-01-05 11:43:11 +0000245}
246
Evgeny Stupachenkof2b3b462017-06-05 23:37:00 +0000247bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
248 return TTIImpl->isLSRCostLess(C1, C2);
249}
250
Sanjay Pateld7c702b2018-02-05 23:43:05 +0000251bool TargetTransformInfo::canMacroFuseCmp() const {
252 return TTIImpl->canMacroFuseCmp();
253}
254
Krzysztof Parzyszek0b377e02018-03-26 13:10:09 +0000255bool TargetTransformInfo::shouldFavorPostInc() const {
256 return TTIImpl->shouldFavorPostInc();
257}
258
Sam Parker67756c02019-02-07 13:32:54 +0000259bool TargetTransformInfo::shouldFavorBackedgeIndex(const Loop *L) const {
260 return TTIImpl->shouldFavorBackedgeIndex(L);
261}
262
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000263bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const {
264 return TTIImpl->isLegalMaskedStore(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000265}
266
Elena Demikhovsky20662e32015-10-19 07:43:38 +0000267bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const {
268 return TTIImpl->isLegalMaskedLoad(DataType);
Chandler Carruth705b1852015-01-31 03:43:40 +0000269}
270
Warren Ristow6452bdd2019-06-17 17:20:08 +0000271bool TargetTransformInfo::isLegalNTStore(Type *DataType,
272 unsigned Alignment) const {
273 return TTIImpl->isLegalNTStore(DataType, Alignment);
274}
275
276bool TargetTransformInfo::isLegalNTLoad(Type *DataType,
277 unsigned Alignment) const {
278 return TTIImpl->isLegalNTLoad(DataType, Alignment);
279}
280
Elena Demikhovsky09285852015-10-25 15:37:55 +0000281bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const {
282 return TTIImpl->isLegalMaskedGather(DataType);
283}
284
285bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const {
Mohammed Agabariacef53dc2017-07-27 10:28:16 +0000286 return TTIImpl->isLegalMaskedScatter(DataType);
Elena Demikhovsky09285852015-10-25 15:37:55 +0000287}
288
Craig Topper9f0b17a2019-03-21 17:38:52 +0000289bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType) const {
290 return TTIImpl->isLegalMaskedCompressStore(DataType);
291}
292
293bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType) const {
294 return TTIImpl->isLegalMaskedExpandLoad(DataType);
295}
296
Sanjay Patel6fd43912017-09-09 13:38:18 +0000297bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const {
298 return TTIImpl->hasDivRemOp(DataType, IsSigned);
299}
300
Artem Belevichcb8f6322017-10-24 20:31:44 +0000301bool TargetTransformInfo::hasVolatileVariant(Instruction *I,
302 unsigned AddrSpace) const {
303 return TTIImpl->hasVolatileVariant(I, AddrSpace);
304}
305
Jonas Paulsson8624b7e2017-05-24 13:42:56 +0000306bool TargetTransformInfo::prefersVectorizedAddressing() const {
307 return TTIImpl->prefersVectorizedAddressing();
308}
309
Quentin Colombetbf490d42013-05-31 21:29:03 +0000310int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
311 int64_t BaseOffset,
312 bool HasBaseReg,
Matt Arsenaulte83379e2015-06-07 20:12:03 +0000313 int64_t Scale,
314 unsigned AddrSpace) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000315 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
316 Scale, AddrSpace);
317 assert(Cost >= 0 && "TTI should not produce negative costs!");
318 return Cost;
Quentin Colombetbf490d42013-05-31 21:29:03 +0000319}
320
Jonas Paulsson024e3192017-07-21 11:59:37 +0000321bool TargetTransformInfo::LSRWithInstrQueries() const {
322 return TTIImpl->LSRWithInstrQueries();
323}
324
Chandler Carruth539edf42013-01-05 11:43:11 +0000325bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000326 return TTIImpl->isTruncateFree(Ty1, Ty2);
Chandler Carruth539edf42013-01-05 11:43:11 +0000327}
328
Chad Rosier54390052015-02-23 19:15:16 +0000329bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
330 return TTIImpl->isProfitableToHoist(I);
331}
332
David Blaikie8ad9a972018-03-28 22:28:50 +0000333bool TargetTransformInfo::useAA() const { return TTIImpl->useAA(); }
334
Chandler Carruth539edf42013-01-05 11:43:11 +0000335bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000336 return TTIImpl->isTypeLegal(Ty);
Chandler Carruth539edf42013-01-05 11:43:11 +0000337}
338
339unsigned TargetTransformInfo::getJumpBufAlignment() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000340 return TTIImpl->getJumpBufAlignment();
Chandler Carruth539edf42013-01-05 11:43:11 +0000341}
342
343unsigned TargetTransformInfo::getJumpBufSize() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000344 return TTIImpl->getJumpBufSize();
Chandler Carruth539edf42013-01-05 11:43:11 +0000345}
346
347bool TargetTransformInfo::shouldBuildLookupTables() const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000348 return TTIImpl->shouldBuildLookupTables();
Chandler Carruth539edf42013-01-05 11:43:11 +0000349}
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000350bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const {
351 return TTIImpl->shouldBuildLookupTablesForConstant(C);
352}
Chandler Carruth539edf42013-01-05 11:43:11 +0000353
Zaara Syeda1f59ae32018-01-30 16:17:22 +0000354bool TargetTransformInfo::useColdCCForColdCall(Function &F) const {
355 return TTIImpl->useColdCCForColdCall(F);
356}
357
Jonas Paulsson8e2f9482017-01-26 07:03:25 +0000358unsigned TargetTransformInfo::
359getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const {
360 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract);
361}
362
363unsigned TargetTransformInfo::
364getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
365 unsigned VF) const {
366 return TTIImpl->getOperandsScalarizationOverhead(Args, VF);
367}
368
Jonas Paulssonda74ed42017-04-12 12:41:37 +0000369bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
370 return TTIImpl->supportsEfficientVectorElementLoadStore();
371}
372
Olivier Sallenave049d8032015-03-06 23:12:04 +0000373bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const {
374 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
375}
376
Clement Courbetb2c3eb82017-10-30 14:19:33 +0000377const TargetTransformInfo::MemCmpExpansionOptions *
378TargetTransformInfo::enableMemCmpExpansion(bool IsZeroCmp) const {
379 return TTIImpl->enableMemCmpExpansion(IsZeroCmp);
Zaara Syeda3a7578c2017-05-31 17:12:38 +0000380}
381
Silviu Baranga61bdc512015-08-10 14:50:54 +0000382bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
383 return TTIImpl->enableInterleavedAccessVectorization();
384}
385
Dorit Nuzman38bbf812018-10-14 08:50:06 +0000386bool TargetTransformInfo::enableMaskedInterleavedAccessVectorization() const {
387 return TTIImpl->enableMaskedInterleavedAccessVectorization();
388}
389
Renato Golin5cb666a2016-04-14 20:42:18 +0000390bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
391 return TTIImpl->isFPVectorizationPotentiallyUnsafe();
392}
393
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000394bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
395 unsigned BitWidth,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000396 unsigned AddressSpace,
397 unsigned Alignment,
398 bool *Fast) const {
Alina Sbirlea6f937b12016-08-04 16:38:44 +0000399 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
Alina Sbirlea327955e2016-07-11 20:46:17 +0000400 Alignment, Fast);
401}
402
Chandler Carruth50a36cd2013-01-07 03:16:03 +0000403TargetTransformInfo::PopcntSupportKind
404TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000405 return TTIImpl->getPopcntSupport(IntTyWidthInBit);
Chandler Carruth539edf42013-01-05 11:43:11 +0000406}
407
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000408bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000409 return TTIImpl->haveFastSqrt(Ty);
Richard Sandiford37cd6cf2013-08-23 10:27:02 +0000410}
411
Sanjay Patel0de1a4b2017-11-27 21:15:43 +0000412bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const {
413 return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
414}
415
Chandler Carruth93205eb2015-08-05 18:08:10 +0000416int TargetTransformInfo::getFPOpCost(Type *Ty) const {
417 int Cost = TTIImpl->getFPOpCost(Ty);
418 assert(Cost >= 0 && "TTI should not produce negative costs!");
419 return Cost;
Cameron Esfahani17177d12015-02-05 02:09:33 +0000420}
421
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000422int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
423 const APInt &Imm,
424 Type *Ty) const {
425 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
426 assert(Cost >= 0 && "TTI should not produce negative costs!");
427 return Cost;
428}
429
Chandler Carruth93205eb2015-08-05 18:08:10 +0000430int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
431 int Cost = TTIImpl->getIntImmCost(Imm, Ty);
432 assert(Cost >= 0 && "TTI should not produce negative costs!");
433 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000434}
435
Chandler Carruth93205eb2015-08-05 18:08:10 +0000436int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx,
437 const APInt &Imm, Type *Ty) const {
438 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty);
439 assert(Cost >= 0 && "TTI should not produce negative costs!");
440 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000441}
442
Chandler Carruth93205eb2015-08-05 18:08:10 +0000443int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
444 const APInt &Imm, Type *Ty) const {
445 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty);
446 assert(Cost >= 0 && "TTI should not produce negative costs!");
447 return Cost;
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000448}
449
Chandler Carruth539edf42013-01-05 11:43:11 +0000450unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000451 return TTIImpl->getNumberOfRegisters(Vector);
Chandler Carruth539edf42013-01-05 11:43:11 +0000452}
453
Nadav Rotemb1791a72013-01-09 22:29:00 +0000454unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000455 return TTIImpl->getRegisterBitWidth(Vector);
Nadav Rotemb1791a72013-01-09 22:29:00 +0000456}
457
Adam Nemete29686e2017-05-15 21:15:01 +0000458unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
459 return TTIImpl->getMinVectorRegisterBitWidth();
460}
461
Krzysztof Parzyszek5d93fdf2018-03-27 16:14:11 +0000462bool TargetTransformInfo::shouldMaximizeVectorBandwidth(bool OptSize) const {
463 return TTIImpl->shouldMaximizeVectorBandwidth(OptSize);
464}
465
Krzysztof Parzyszekdfed9412018-04-13 20:16:32 +0000466unsigned TargetTransformInfo::getMinimumVF(unsigned ElemWidth) const {
467 return TTIImpl->getMinimumVF(ElemWidth);
468}
469
Jun Bum Limdee55652017-04-03 19:20:07 +0000470bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
471 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
472 return TTIImpl->shouldConsiderAddressTypePromotion(
473 I, AllowPromotionWithoutCommonHeader);
474}
475
Adam Nemetaf761102016-01-21 18:28:36 +0000476unsigned TargetTransformInfo::getCacheLineSize() const {
477 return TTIImpl->getCacheLineSize();
478}
479
Tobias Grosserd7eb6192017-08-24 09:46:25 +0000480llvm::Optional<unsigned> TargetTransformInfo::getCacheSize(CacheLevel Level)
481 const {
482 return TTIImpl->getCacheSize(Level);
483}
484
485llvm::Optional<unsigned> TargetTransformInfo::getCacheAssociativity(
486 CacheLevel Level) const {
487 return TTIImpl->getCacheAssociativity(Level);
488}
489
Adam Nemetdadfbb52016-01-27 22:21:25 +0000490unsigned TargetTransformInfo::getPrefetchDistance() const {
491 return TTIImpl->getPrefetchDistance();
492}
493
Adam Nemet6d8beec2016-03-18 00:27:38 +0000494unsigned TargetTransformInfo::getMinPrefetchStride() const {
495 return TTIImpl->getMinPrefetchStride();
496}
497
Adam Nemet709e3042016-03-18 00:27:43 +0000498unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
499 return TTIImpl->getMaxPrefetchIterationsAhead();
500}
501
Wei Mi062c7442015-05-06 17:12:25 +0000502unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
503 return TTIImpl->getMaxInterleaveFactor(VF);
Nadav Rotemb696c362013-01-09 01:15:42 +0000504}
505
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000506TargetTransformInfo::OperandValueKind
Simon Pilgrim077a42c2018-11-13 13:45:10 +0000507TargetTransformInfo::getOperandInfo(Value *V, OperandValueProperties &OpProps) {
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000508 OperandValueKind OpInfo = OK_AnyValue;
509 OpProps = OP_None;
510
511 if (auto *CI = dyn_cast<ConstantInt>(V)) {
512 if (CI->getValue().isPowerOf2())
513 OpProps = OP_PowerOf2;
514 return OK_UniformConstantValue;
515 }
516
Simon Pilgrim2b166c52018-11-14 15:04:08 +0000517 // A broadcast shuffle creates a uniform value.
518 // TODO: Add support for non-zero index broadcasts.
519 // TODO: Add support for different source vector width.
520 if (auto *ShuffleInst = dyn_cast<ShuffleVectorInst>(V))
521 if (ShuffleInst->isZeroEltSplat())
522 OpInfo = OK_UniformValue;
523
Jonas Paulsson29d80f02018-10-05 14:34:04 +0000524 const Value *Splat = getSplatValue(V);
525
526 // Check for a splat of a constant or for a non uniform vector of constants
527 // and check if the constant(s) are all powers of two.
528 if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
529 OpInfo = OK_NonUniformConstantValue;
530 if (Splat) {
531 OpInfo = OK_UniformConstantValue;
532 if (auto *CI = dyn_cast<ConstantInt>(Splat))
533 if (CI->getValue().isPowerOf2())
534 OpProps = OP_PowerOf2;
535 } else if (auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
536 OpProps = OP_PowerOf2;
537 for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
538 if (auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
539 if (CI->getValue().isPowerOf2())
540 continue;
541 OpProps = OP_None;
542 break;
543 }
544 }
545 }
546
547 // Check for a splat of a uniform value. This is not loop aware, so return
548 // true only for the obviously uniform cases (argument, globalvalue)
549 if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
550 OpInfo = OK_UniformValue;
551
552 return OpInfo;
553}
554
Chandler Carruth93205eb2015-08-05 18:08:10 +0000555int TargetTransformInfo::getArithmeticInstrCost(
Chandler Carruth705b1852015-01-31 03:43:40 +0000556 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
557 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000558 OperandValueProperties Opd2PropInfo,
559 ArrayRef<const Value *> Args) const {
Chandler Carruth93205eb2015-08-05 18:08:10 +0000560 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000561 Opd1PropInfo, Opd2PropInfo, Args);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000562 assert(Cost >= 0 && "TTI should not produce negative costs!");
563 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000564}
565
Chandler Carruth93205eb2015-08-05 18:08:10 +0000566int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index,
567 Type *SubTp) const {
568 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp);
569 assert(Cost >= 0 && "TTI should not produce negative costs!");
570 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000571}
572
Chandler Carruth93205eb2015-08-05 18:08:10 +0000573int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000574 Type *Src, const Instruction *I) const {
575 assert ((I == nullptr || I->getOpcode() == Opcode) &&
576 "Opcode should reflect passed instruction.");
577 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000578 assert(Cost >= 0 && "TTI should not produce negative costs!");
579 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000580}
581
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000582int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst,
583 VectorType *VecTy,
584 unsigned Index) const {
585 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
586 assert(Cost >= 0 && "TTI should not produce negative costs!");
587 return Cost;
588}
589
Chandler Carruth93205eb2015-08-05 18:08:10 +0000590int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
591 int Cost = TTIImpl->getCFInstrCost(Opcode);
592 assert(Cost >= 0 && "TTI should not produce negative costs!");
593 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000594}
595
Chandler Carruth93205eb2015-08-05 18:08:10 +0000596int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000597 Type *CondTy, const Instruction *I) const {
598 assert ((I == nullptr || I->getOpcode() == Opcode) &&
599 "Opcode should reflect passed instruction.");
600 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000601 assert(Cost >= 0 && "TTI should not produce negative costs!");
602 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000603}
604
Chandler Carruth93205eb2015-08-05 18:08:10 +0000605int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
606 unsigned Index) const {
607 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
608 assert(Cost >= 0 && "TTI should not produce negative costs!");
609 return Cost;
Chandler Carruth539edf42013-01-05 11:43:11 +0000610}
611
Chandler Carruth93205eb2015-08-05 18:08:10 +0000612int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
613 unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000614 unsigned AddressSpace,
615 const Instruction *I) const {
616 assert ((I == nullptr || I->getOpcode() == Opcode) &&
617 "Opcode should reflect passed instruction.");
618 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000619 assert(Cost >= 0 && "TTI should not produce negative costs!");
620 return Cost;
Elena Demikhovskya3232f72015-01-25 08:44:46 +0000621}
622
Chandler Carruth93205eb2015-08-05 18:08:10 +0000623int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
624 unsigned Alignment,
625 unsigned AddressSpace) const {
626 int Cost =
627 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
628 assert(Cost >= 0 && "TTI should not produce negative costs!");
629 return Cost;
Chandler Carruth705b1852015-01-31 03:43:40 +0000630}
631
Elena Demikhovsky54946982015-12-28 20:10:59 +0000632int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy,
633 Value *Ptr, bool VariableMask,
634 unsigned Alignment) const {
635 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
636 Alignment);
637 assert(Cost >= 0 && "TTI should not produce negative costs!");
638 return Cost;
639}
640
Chandler Carruth93205eb2015-08-05 18:08:10 +0000641int TargetTransformInfo::getInterleavedMemoryOpCost(
Hao Liu32c05392015-06-08 06:39:56 +0000642 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
Dorit Nuzman34da6dd2018-10-31 09:57:56 +0000643 unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond,
644 bool UseMaskForGaps) const {
645 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
646 Alignment, AddressSpace,
647 UseMaskForCond,
648 UseMaskForGaps);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000649 assert(Cost >= 0 && "TTI should not produce negative costs!");
650 return Cost;
Hao Liu32c05392015-06-08 06:39:56 +0000651}
652
Chandler Carruth93205eb2015-08-05 18:08:10 +0000653int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000654 ArrayRef<Type *> Tys, FastMathFlags FMF,
655 unsigned ScalarizationCostPassed) const {
656 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF,
657 ScalarizationCostPassed);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000658 assert(Cost >= 0 && "TTI should not produce negative costs!");
659 return Cost;
660}
661
Elena Demikhovsky54946982015-12-28 20:10:59 +0000662int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
Jonas Paulssona48ea232017-03-14 06:35:36 +0000663 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const {
664 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
Elena Demikhovsky54946982015-12-28 20:10:59 +0000665 assert(Cost >= 0 && "TTI should not produce negative costs!");
666 return Cost;
667}
668
Chandler Carruth93205eb2015-08-05 18:08:10 +0000669int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
670 ArrayRef<Type *> Tys) const {
671 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys);
672 assert(Cost >= 0 && "TTI should not produce negative costs!");
673 return Cost;
Michael Zolotukhin7ed84a82015-03-17 19:26:23 +0000674}
675
Chandler Carruth539edf42013-01-05 11:43:11 +0000676unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000677 return TTIImpl->getNumberOfParts(Tp);
Chandler Carruth539edf42013-01-05 11:43:11 +0000678}
679
Chandler Carruth93205eb2015-08-05 18:08:10 +0000680int TargetTransformInfo::getAddressComputationCost(Type *Tp,
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000681 ScalarEvolution *SE,
682 const SCEV *Ptr) const {
683 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000684 assert(Cost >= 0 && "TTI should not produce negative costs!");
685 return Cost;
Arnold Schwaighofer594fa2d2013-02-08 14:50:48 +0000686}
Chandler Carruth539edf42013-01-05 11:43:11 +0000687
Sjoerd Meijerea31ddb2019-04-30 10:28:50 +0000688int TargetTransformInfo::getMemcpyCost(const Instruction *I) const {
689 int Cost = TTIImpl->getMemcpyCost(I);
690 assert(Cost >= 0 && "TTI should not produce negative costs!");
691 return Cost;
692}
693
Alexey Bataev3e9b3eb2017-07-31 14:19:32 +0000694int TargetTransformInfo::getArithmeticReductionCost(unsigned Opcode, Type *Ty,
695 bool IsPairwiseForm) const {
696 int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm);
Chandler Carruth93205eb2015-08-05 18:08:10 +0000697 assert(Cost >= 0 && "TTI should not produce negative costs!");
698 return Cost;
Arnold Schwaighofercae87352013-09-17 18:06:50 +0000699}
700
Alexey Bataev6dd29fc2017-09-08 13:49:36 +0000701int TargetTransformInfo::getMinMaxReductionCost(Type *Ty, Type *CondTy,
702 bool IsPairwiseForm,
703 bool IsUnsigned) const {
704 int Cost =
705 TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned);
706 assert(Cost >= 0 && "TTI should not produce negative costs!");
707 return Cost;
708}
709
Chandler Carruth705b1852015-01-31 03:43:40 +0000710unsigned
711TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
712 return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
Chad Rosierf9327d62015-01-26 22:51:15 +0000713}
714
715bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
716 MemIntrinsicInfo &Info) const {
Chandler Carruth705b1852015-01-31 03:43:40 +0000717 return TTIImpl->getTgtMemIntrinsic(Inst, Info);
Chad Rosierf9327d62015-01-26 22:51:15 +0000718}
719
Anna Thomasb2a212c2017-06-06 16:45:25 +0000720unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
721 return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
722}
723
Chandler Carruth705b1852015-01-31 03:43:40 +0000724Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
725 IntrinsicInst *Inst, Type *ExpectedType) const {
726 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
727}
728
Sean Fertile9cd1cdf2017-07-07 02:00:06 +0000729Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context,
730 Value *Length,
731 unsigned SrcAlign,
732 unsigned DestAlign) const {
733 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign,
734 DestAlign);
735}
736
737void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
738 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
739 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const {
740 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
741 SrcAlign, DestAlign);
742}
743
Eric Christopherd566fb12015-07-29 22:09:48 +0000744bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
745 const Function *Callee) const {
746 return TTIImpl->areInlineCompatible(Caller, Callee);
Eric Christopher4371b132015-07-02 01:11:47 +0000747}
748
Tom Stellard3d36e5c2019-01-16 05:15:31 +0000749bool TargetTransformInfo::areFunctionArgsABICompatible(
750 const Function *Caller, const Function *Callee,
751 SmallPtrSetImpl<Argument *> &Args) const {
752 return TTIImpl->areFunctionArgsABICompatible(Caller, Callee, Args);
753}
754
Krzysztof Parzyszek0b377e02018-03-26 13:10:09 +0000755bool TargetTransformInfo::isIndexedLoadLegal(MemIndexedMode Mode,
756 Type *Ty) const {
757 return TTIImpl->isIndexedLoadLegal(Mode, Ty);
758}
759
760bool TargetTransformInfo::isIndexedStoreLegal(MemIndexedMode Mode,
761 Type *Ty) const {
762 return TTIImpl->isIndexedStoreLegal(Mode, Ty);
763}
764
Volkan Keles1c386812016-10-03 10:31:34 +0000765unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
766 return TTIImpl->getLoadStoreVecRegBitWidth(AS);
767}
768
769bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
770 return TTIImpl->isLegalToVectorizeLoad(LI);
771}
772
773bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
774 return TTIImpl->isLegalToVectorizeStore(SI);
775}
776
777bool TargetTransformInfo::isLegalToVectorizeLoadChain(
778 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
779 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
780 AddrSpace);
781}
782
783bool TargetTransformInfo::isLegalToVectorizeStoreChain(
784 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const {
785 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
786 AddrSpace);
787}
788
789unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
790 unsigned LoadSize,
791 unsigned ChainSizeInBytes,
792 VectorType *VecTy) const {
793 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
794}
795
796unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
797 unsigned StoreSize,
798 unsigned ChainSizeInBytes,
799 VectorType *VecTy) const {
800 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
801}
802
Amara Emersoncf9daa32017-05-09 10:43:25 +0000803bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode,
804 Type *Ty, ReductionFlags Flags) const {
805 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags);
806}
807
Amara Emerson836b0f42017-05-10 09:42:49 +0000808bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
809 return TTIImpl->shouldExpandReduction(II);
810}
Amara Emersoncf9daa32017-05-09 10:43:25 +0000811
Amara Emerson14688222019-06-17 23:20:29 +0000812unsigned TargetTransformInfo::getGISelRematGlobalCost() const {
813 return TTIImpl->getGISelRematGlobalCost();
814}
815
Guozhi Wei62d64142017-09-08 22:29:17 +0000816int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
817 return TTIImpl->getInstructionLatency(I);
818}
819
Guozhi Wei62d64142017-09-08 22:29:17 +0000820static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft,
821 unsigned Level) {
822 // We don't need a shuffle if we just want to have element 0 in position 0 of
823 // the vector.
824 if (!SI && Level == 0 && IsLeft)
825 return true;
826 else if (!SI)
827 return false;
828
829 SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1);
830
831 // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether
832 // we look at the left or right side.
833 for (unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2)
834 Mask[i] = val;
835
836 SmallVector<int, 16> ActualMask = SI->getShuffleMask();
837 return Mask == ActualMask;
838}
839
840namespace {
841/// Kind of the reduction data.
842enum ReductionKind {
843 RK_None, /// Not a reduction.
844 RK_Arithmetic, /// Binary reduction data.
845 RK_MinMax, /// Min/max reduction data.
846 RK_UnsignedMinMax, /// Unsigned min/max reduction data.
847};
848/// Contains opcode + LHS/RHS parts of the reduction operations.
849struct ReductionData {
850 ReductionData() = delete;
851 ReductionData(ReductionKind Kind, unsigned Opcode, Value *LHS, Value *RHS)
852 : Opcode(Opcode), LHS(LHS), RHS(RHS), Kind(Kind) {
853 assert(Kind != RK_None && "expected binary or min/max reduction only.");
854 }
855 unsigned Opcode = 0;
856 Value *LHS = nullptr;
857 Value *RHS = nullptr;
858 ReductionKind Kind = RK_None;
859 bool hasSameData(ReductionData &RD) const {
860 return Kind == RD.Kind && Opcode == RD.Opcode;
861 }
862};
863} // namespace
864
865static Optional<ReductionData> getReductionData(Instruction *I) {
866 Value *L, *R;
867 if (m_BinOp(m_Value(L), m_Value(R)).match(I))
Fangrui Songf78650a2018-07-30 19:41:25 +0000868 return ReductionData(RK_Arithmetic, I->getOpcode(), L, R);
Guozhi Wei62d64142017-09-08 22:29:17 +0000869 if (auto *SI = dyn_cast<SelectInst>(I)) {
870 if (m_SMin(m_Value(L), m_Value(R)).match(SI) ||
871 m_SMax(m_Value(L), m_Value(R)).match(SI) ||
872 m_OrdFMin(m_Value(L), m_Value(R)).match(SI) ||
873 m_OrdFMax(m_Value(L), m_Value(R)).match(SI) ||
874 m_UnordFMin(m_Value(L), m_Value(R)).match(SI) ||
875 m_UnordFMax(m_Value(L), m_Value(R)).match(SI)) {
876 auto *CI = cast<CmpInst>(SI->getCondition());
Fangrui Songf78650a2018-07-30 19:41:25 +0000877 return ReductionData(RK_MinMax, CI->getOpcode(), L, R);
878 }
Guozhi Wei62d64142017-09-08 22:29:17 +0000879 if (m_UMin(m_Value(L), m_Value(R)).match(SI) ||
880 m_UMax(m_Value(L), m_Value(R)).match(SI)) {
881 auto *CI = cast<CmpInst>(SI->getCondition());
882 return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R);
883 }
884 }
885 return llvm::None;
886}
887
888static ReductionKind matchPairwiseReductionAtLevel(Instruction *I,
889 unsigned Level,
890 unsigned NumLevels) {
891 // Match one level of pairwise operations.
892 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
893 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
894 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
895 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
896 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
897 if (!I)
898 return RK_None;
899
900 assert(I->getType()->isVectorTy() && "Expecting a vector type");
901
902 Optional<ReductionData> RD = getReductionData(I);
903 if (!RD)
904 return RK_None;
905
906 ShuffleVectorInst *LS = dyn_cast<ShuffleVectorInst>(RD->LHS);
907 if (!LS && Level)
908 return RK_None;
909 ShuffleVectorInst *RS = dyn_cast<ShuffleVectorInst>(RD->RHS);
910 if (!RS && Level)
911 return RK_None;
912
913 // On level 0 we can omit one shufflevector instruction.
914 if (!Level && !RS && !LS)
915 return RK_None;
916
917 // Shuffle inputs must match.
918 Value *NextLevelOpL = LS ? LS->getOperand(0) : nullptr;
919 Value *NextLevelOpR = RS ? RS->getOperand(0) : nullptr;
920 Value *NextLevelOp = nullptr;
921 if (NextLevelOpR && NextLevelOpL) {
922 // If we have two shuffles their operands must match.
923 if (NextLevelOpL != NextLevelOpR)
924 return RK_None;
925
926 NextLevelOp = NextLevelOpL;
927 } else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) {
928 // On the first level we can omit the shufflevector <0, undef,...>. So the
929 // input to the other shufflevector <1, undef> must match with one of the
930 // inputs to the current binary operation.
931 // Example:
932 // %NextLevelOpL = shufflevector %R, <1, undef ...>
933 // %BinOp = fadd %NextLevelOpL, %R
934 if (NextLevelOpL && NextLevelOpL != RD->RHS)
935 return RK_None;
936 else if (NextLevelOpR && NextLevelOpR != RD->LHS)
937 return RK_None;
938
939 NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS;
940 } else
941 return RK_None;
942
943 // Check that the next levels binary operation exists and matches with the
944 // current one.
945 if (Level + 1 != NumLevels) {
946 Optional<ReductionData> NextLevelRD =
947 getReductionData(cast<Instruction>(NextLevelOp));
948 if (!NextLevelRD || !RD->hasSameData(*NextLevelRD))
949 return RK_None;
950 }
951
952 // Shuffle mask for pairwise operation must match.
953 if (matchPairwiseShuffleMask(LS, /*IsLeft=*/true, Level)) {
954 if (!matchPairwiseShuffleMask(RS, /*IsLeft=*/false, Level))
955 return RK_None;
956 } else if (matchPairwiseShuffleMask(RS, /*IsLeft=*/true, Level)) {
957 if (!matchPairwiseShuffleMask(LS, /*IsLeft=*/false, Level))
958 return RK_None;
959 } else {
960 return RK_None;
961 }
962
963 if (++Level == NumLevels)
964 return RD->Kind;
965
966 // Match next level.
967 return matchPairwiseReductionAtLevel(cast<Instruction>(NextLevelOp), Level,
968 NumLevels);
969}
970
971static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot,
972 unsigned &Opcode, Type *&Ty) {
973 if (!EnableReduxCost)
974 return RK_None;
975
976 // Need to extract the first element.
977 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
978 unsigned Idx = ~0u;
979 if (CI)
980 Idx = CI->getZExtValue();
981 if (Idx != 0)
982 return RK_None;
983
984 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
985 if (!RdxStart)
986 return RK_None;
987 Optional<ReductionData> RD = getReductionData(RdxStart);
988 if (!RD)
989 return RK_None;
990
991 Type *VecTy = RdxStart->getType();
992 unsigned NumVecElems = VecTy->getVectorNumElements();
993 if (!isPowerOf2_32(NumVecElems))
994 return RK_None;
995
996 // We look for a sequence of shuffle,shuffle,add triples like the following
997 // that builds a pairwise reduction tree.
Fangrui Songf78650a2018-07-30 19:41:25 +0000998 //
Guozhi Wei62d64142017-09-08 22:29:17 +0000999 // (X0, X1, X2, X3)
1000 // (X0 + X1, X2 + X3, undef, undef)
1001 // ((X0 + X1) + (X2 + X3), undef, undef, undef)
Fangrui Songf78650a2018-07-30 19:41:25 +00001002 //
Guozhi Wei62d64142017-09-08 22:29:17 +00001003 // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
1004 // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
1005 // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
1006 // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
1007 // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
1008 // %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
1009 // <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1010 // %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
1011 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
1012 // %bin.rdx8 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
1013 // %r = extractelement <4 x float> %bin.rdx8, i32 0
1014 if (matchPairwiseReductionAtLevel(RdxStart, 0, Log2_32(NumVecElems)) ==
1015 RK_None)
1016 return RK_None;
1017
1018 Opcode = RD->Opcode;
1019 Ty = VecTy;
1020
1021 return RD->Kind;
1022}
1023
1024static std::pair<Value *, ShuffleVectorInst *>
1025getShuffleAndOtherOprd(Value *L, Value *R) {
1026 ShuffleVectorInst *S = nullptr;
1027
1028 if ((S = dyn_cast<ShuffleVectorInst>(L)))
1029 return std::make_pair(R, S);
1030
1031 S = dyn_cast<ShuffleVectorInst>(R);
1032 return std::make_pair(L, S);
1033}
1034
1035static ReductionKind
1036matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot,
1037 unsigned &Opcode, Type *&Ty) {
1038 if (!EnableReduxCost)
1039 return RK_None;
1040
1041 // Need to extract the first element.
1042 ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1));
1043 unsigned Idx = ~0u;
1044 if (CI)
1045 Idx = CI->getZExtValue();
1046 if (Idx != 0)
1047 return RK_None;
1048
1049 auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0));
1050 if (!RdxStart)
1051 return RK_None;
1052 Optional<ReductionData> RD = getReductionData(RdxStart);
1053 if (!RD)
1054 return RK_None;
1055
1056 Type *VecTy = ReduxRoot->getOperand(0)->getType();
1057 unsigned NumVecElems = VecTy->getVectorNumElements();
1058 if (!isPowerOf2_32(NumVecElems))
1059 return RK_None;
1060
1061 // We look for a sequence of shuffles and adds like the following matching one
1062 // fadd, shuffle vector pair at a time.
Fangrui Songf78650a2018-07-30 19:41:25 +00001063 //
Guozhi Wei62d64142017-09-08 22:29:17 +00001064 // %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef,
1065 // <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
1066 // %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
1067 // %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef,
1068 // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
1069 // %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
1070 // %r = extractelement <4 x float> %bin.rdx8, i32 0
1071
1072 unsigned MaskStart = 1;
1073 Instruction *RdxOp = RdxStart;
Fangrui Songf78650a2018-07-30 19:41:25 +00001074 SmallVector<int, 32> ShuffleMask(NumVecElems, 0);
Guozhi Wei62d64142017-09-08 22:29:17 +00001075 unsigned NumVecElemsRemain = NumVecElems;
1076 while (NumVecElemsRemain - 1) {
1077 // Check for the right reduction operation.
1078 if (!RdxOp)
1079 return RK_None;
1080 Optional<ReductionData> RDLevel = getReductionData(RdxOp);
1081 if (!RDLevel || !RDLevel->hasSameData(*RD))
1082 return RK_None;
1083
1084 Value *NextRdxOp;
1085 ShuffleVectorInst *Shuffle;
1086 std::tie(NextRdxOp, Shuffle) =
1087 getShuffleAndOtherOprd(RDLevel->LHS, RDLevel->RHS);
1088
1089 // Check the current reduction operation and the shuffle use the same value.
1090 if (Shuffle == nullptr)
1091 return RK_None;
1092 if (Shuffle->getOperand(0) != NextRdxOp)
1093 return RK_None;
1094
1095 // Check that shuffle masks matches.
1096 for (unsigned j = 0; j != MaskStart; ++j)
1097 ShuffleMask[j] = MaskStart + j;
1098 // Fill the rest of the mask with -1 for undef.
1099 std::fill(&ShuffleMask[MaskStart], ShuffleMask.end(), -1);
1100
1101 SmallVector<int, 16> Mask = Shuffle->getShuffleMask();
1102 if (ShuffleMask != Mask)
1103 return RK_None;
1104
1105 RdxOp = dyn_cast<Instruction>(NextRdxOp);
1106 NumVecElemsRemain /= 2;
1107 MaskStart *= 2;
1108 }
1109
1110 Opcode = RD->Opcode;
1111 Ty = VecTy;
1112 return RD->Kind;
1113}
1114
1115int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
1116 switch (I->getOpcode()) {
1117 case Instruction::GetElementPtr:
1118 return getUserCost(I);
1119
1120 case Instruction::Ret:
1121 case Instruction::PHI:
1122 case Instruction::Br: {
1123 return getCFInstrCost(I->getOpcode());
1124 }
1125 case Instruction::Add:
1126 case Instruction::FAdd:
1127 case Instruction::Sub:
1128 case Instruction::FSub:
1129 case Instruction::Mul:
1130 case Instruction::FMul:
1131 case Instruction::UDiv:
1132 case Instruction::SDiv:
1133 case Instruction::FDiv:
1134 case Instruction::URem:
1135 case Instruction::SRem:
1136 case Instruction::FRem:
1137 case Instruction::Shl:
1138 case Instruction::LShr:
1139 case Instruction::AShr:
1140 case Instruction::And:
1141 case Instruction::Or:
1142 case Instruction::Xor: {
Simon Pilgrim4162d772018-05-22 10:40:09 +00001143 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1144 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1145 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1146 Op2VK = getOperandInfo(I->getOperand(1), Op2VP);
1147 SmallVector<const Value *, 2> Operands(I->operand_values());
1148 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1149 Op1VP, Op2VP, Operands);
Guozhi Wei62d64142017-09-08 22:29:17 +00001150 }
Craig Topper50d50282019-05-28 04:09:18 +00001151 case Instruction::FNeg: {
1152 TargetTransformInfo::OperandValueKind Op1VK, Op2VK;
1153 TargetTransformInfo::OperandValueProperties Op1VP, Op2VP;
1154 Op1VK = getOperandInfo(I->getOperand(0), Op1VP);
1155 Op2VK = OK_AnyValue;
1156 Op2VP = OP_None;
1157 SmallVector<const Value *, 2> Operands(I->operand_values());
1158 return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, Op2VK,
1159 Op1VP, Op2VP, Operands);
1160 }
Guozhi Wei62d64142017-09-08 22:29:17 +00001161 case Instruction::Select: {
1162 const SelectInst *SI = cast<SelectInst>(I);
1163 Type *CondTy = SI->getCondition()->getType();
1164 return getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, I);
1165 }
1166 case Instruction::ICmp:
1167 case Instruction::FCmp: {
1168 Type *ValTy = I->getOperand(0)->getType();
1169 return getCmpSelInstrCost(I->getOpcode(), ValTy, I->getType(), I);
1170 }
1171 case Instruction::Store: {
1172 const StoreInst *SI = cast<StoreInst>(I);
1173 Type *ValTy = SI->getValueOperand()->getType();
1174 return getMemoryOpCost(I->getOpcode(), ValTy,
1175 SI->getAlignment(),
1176 SI->getPointerAddressSpace(), I);
1177 }
1178 case Instruction::Load: {
1179 const LoadInst *LI = cast<LoadInst>(I);
1180 return getMemoryOpCost(I->getOpcode(), I->getType(),
1181 LI->getAlignment(),
1182 LI->getPointerAddressSpace(), I);
1183 }
1184 case Instruction::ZExt:
1185 case Instruction::SExt:
1186 case Instruction::FPToUI:
1187 case Instruction::FPToSI:
1188 case Instruction::FPExt:
1189 case Instruction::PtrToInt:
1190 case Instruction::IntToPtr:
1191 case Instruction::SIToFP:
1192 case Instruction::UIToFP:
1193 case Instruction::Trunc:
1194 case Instruction::FPTrunc:
1195 case Instruction::BitCast:
1196 case Instruction::AddrSpaceCast: {
1197 Type *SrcTy = I->getOperand(0)->getType();
1198 return getCastInstrCost(I->getOpcode(), I->getType(), SrcTy, I);
1199 }
1200 case Instruction::ExtractElement: {
1201 const ExtractElementInst * EEI = cast<ExtractElementInst>(I);
1202 ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1));
1203 unsigned Idx = -1;
1204 if (CI)
1205 Idx = CI->getZExtValue();
1206
1207 // Try to match a reduction sequence (series of shufflevector and vector
1208 // adds followed by a extractelement).
1209 unsigned ReduxOpCode;
1210 Type *ReduxType;
1211
1212 switch (matchVectorSplittingReduction(EEI, ReduxOpCode, ReduxType)) {
1213 case RK_Arithmetic:
1214 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1215 /*IsPairwiseForm=*/false);
1216 case RK_MinMax:
1217 return getMinMaxReductionCost(
1218 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1219 /*IsPairwiseForm=*/false, /*IsUnsigned=*/false);
1220 case RK_UnsignedMinMax:
1221 return getMinMaxReductionCost(
1222 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1223 /*IsPairwiseForm=*/false, /*IsUnsigned=*/true);
1224 case RK_None:
1225 break;
1226 }
1227
1228 switch (matchPairwiseReduction(EEI, ReduxOpCode, ReduxType)) {
1229 case RK_Arithmetic:
1230 return getArithmeticReductionCost(ReduxOpCode, ReduxType,
1231 /*IsPairwiseForm=*/true);
1232 case RK_MinMax:
1233 return getMinMaxReductionCost(
1234 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1235 /*IsPairwiseForm=*/true, /*IsUnsigned=*/false);
1236 case RK_UnsignedMinMax:
1237 return getMinMaxReductionCost(
1238 ReduxType, CmpInst::makeCmpResultType(ReduxType),
1239 /*IsPairwiseForm=*/true, /*IsUnsigned=*/true);
1240 case RK_None:
1241 break;
1242 }
1243
1244 return getVectorInstrCost(I->getOpcode(),
1245 EEI->getOperand(0)->getType(), Idx);
1246 }
1247 case Instruction::InsertElement: {
1248 const InsertElementInst * IE = cast<InsertElementInst>(I);
1249 ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
Fangrui Songf78650a2018-07-30 19:41:25 +00001250 unsigned Idx = -1;
Guozhi Wei62d64142017-09-08 22:29:17 +00001251 if (CI)
1252 Idx = CI->getZExtValue();
1253 return getVectorInstrCost(I->getOpcode(),
1254 IE->getType(), Idx);
1255 }
1256 case Instruction::ShuffleVector: {
1257 const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001258 Type *Ty = Shuffle->getType();
1259 Type *SrcTy = Shuffle->getOperand(0)->getType();
1260
1261 // TODO: Identify and add costs for insert subvector, etc.
1262 int SubIndex;
1263 if (Shuffle->isExtractSubvectorMask(SubIndex))
Simon Pilgrim26e1c882018-11-09 18:30:59 +00001264 return TTIImpl->getShuffleCost(SK_ExtractSubvector, SrcTy, SubIndex, Ty);
Simon Pilgrimd0c71602018-11-09 16:28:19 +00001265
Sanjay Patel2ca33602018-06-19 18:44:00 +00001266 if (Shuffle->changesLength())
1267 return -1;
Fangrui Songf78650a2018-07-30 19:41:25 +00001268
Sanjay Patel2ca33602018-06-19 18:44:00 +00001269 if (Shuffle->isIdentity())
1270 return 0;
Guozhi Wei62d64142017-09-08 22:29:17 +00001271
Sanjay Patel2ca33602018-06-19 18:44:00 +00001272 if (Shuffle->isReverse())
1273 return TTIImpl->getShuffleCost(SK_Reverse, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001274
Sanjay Patel2ca33602018-06-19 18:44:00 +00001275 if (Shuffle->isSelect())
1276 return TTIImpl->getShuffleCost(SK_Select, Ty, 0, nullptr);
Simon Pilgrim07839212018-06-12 14:47:13 +00001277
Sanjay Patel2ca33602018-06-19 18:44:00 +00001278 if (Shuffle->isTranspose())
1279 return TTIImpl->getShuffleCost(SK_Transpose, Ty, 0, nullptr);
Matthew Simpsonb4096eb2018-04-26 13:48:33 +00001280
Sanjay Patel2ca33602018-06-19 18:44:00 +00001281 if (Shuffle->isZeroEltSplat())
1282 return TTIImpl->getShuffleCost(SK_Broadcast, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001283
Sanjay Patel2ca33602018-06-19 18:44:00 +00001284 if (Shuffle->isSingleSource())
1285 return TTIImpl->getShuffleCost(SK_PermuteSingleSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001286
Sanjay Patel2ca33602018-06-19 18:44:00 +00001287 return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr);
Guozhi Wei62d64142017-09-08 22:29:17 +00001288 }
1289 case Instruction::Call:
1290 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
1291 SmallVector<Value *, 4> Args(II->arg_operands());
1292
1293 FastMathFlags FMF;
1294 if (auto *FPMO = dyn_cast<FPMathOperator>(II))
1295 FMF = FPMO->getFastMathFlags();
1296
1297 return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(),
1298 Args, FMF);
1299 }
1300 return -1;
1301 default:
1302 // We don't have any information on this instruction.
1303 return -1;
1304 }
1305}
1306
Chandler Carruth705b1852015-01-31 03:43:40 +00001307TargetTransformInfo::Concept::~Concept() {}
1308
Chandler Carruthe0385522015-02-01 10:11:22 +00001309TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
1310
1311TargetIRAnalysis::TargetIRAnalysis(
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001312 std::function<Result(const Function &)> TTICallback)
Benjamin Kramer82de7d32016-05-27 14:27:24 +00001313 : TTICallback(std::move(TTICallback)) {}
Chandler Carruthe0385522015-02-01 10:11:22 +00001314
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001315TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
Sean Silva36e0d012016-08-09 00:28:15 +00001316 FunctionAnalysisManager &) {
Chandler Carruthe0385522015-02-01 10:11:22 +00001317 return TTICallback(F);
1318}
1319
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001320AnalysisKey TargetIRAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001321
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001322TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
Mehdi Amini5010ebf2015-07-09 02:08:42 +00001323 return Result(F.getParent()->getDataLayout());
Chandler Carruthe0385522015-02-01 10:11:22 +00001324}
1325
Chandler Carruth705b1852015-01-31 03:43:40 +00001326// Register the basic pass.
1327INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
1328 "Target Transform Information", false, true)
1329char TargetTransformInfoWrapperPass::ID = 0;
Chandler Carruth539edf42013-01-05 11:43:11 +00001330
Chandler Carruth705b1852015-01-31 03:43:40 +00001331void TargetTransformInfoWrapperPass::anchor() {}
Chandler Carruth539edf42013-01-05 11:43:11 +00001332
Chandler Carruth705b1852015-01-31 03:43:40 +00001333TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001334 : ImmutablePass(ID) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001335 initializeTargetTransformInfoWrapperPassPass(
1336 *PassRegistry::getPassRegistry());
1337}
1338
1339TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001340 TargetIRAnalysis TIRA)
1341 : ImmutablePass(ID), TIRA(std::move(TIRA)) {
Chandler Carruth705b1852015-01-31 03:43:40 +00001342 initializeTargetTransformInfoWrapperPassPass(
1343 *PassRegistry::getPassRegistry());
1344}
1345
Eric Christophera4e5d3c2015-09-16 23:38:13 +00001346TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
Sean Silva36e0d012016-08-09 00:28:15 +00001347 FunctionAnalysisManager DummyFAM;
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001348 TTI = TIRA.run(F, DummyFAM);
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001349 return *TTI;
1350}
1351
Chandler Carruth93dcdc42015-01-31 11:17:59 +00001352ImmutablePass *
Chandler Carruth5ec2b1d2015-02-01 12:26:09 +00001353llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
1354 return new TargetTransformInfoWrapperPass(std::move(TIRA));
Chandler Carruth539edf42013-01-05 11:43:11 +00001355}