TargetTransformInfo.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
  2. //
  3. // 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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Analysis/TargetTransformInfo.h"
  9. #include "llvm/Analysis/CFG.h"
  10. #include "llvm/Analysis/LoopIterator.h"
  11. #include "llvm/Analysis/TargetTransformInfoImpl.h"
  12. #include "llvm/IR/CFG.h"
  13. #include "llvm/IR/DataLayout.h"
  14. #include "llvm/IR/Dominators.h"
  15. #include "llvm/IR/Instruction.h"
  16. #include "llvm/IR/Instructions.h"
  17. #include "llvm/IR/IntrinsicInst.h"
  18. #include "llvm/IR/Module.h"
  19. #include "llvm/IR/Operator.h"
  20. #include "llvm/IR/PatternMatch.h"
  21. #include "llvm/InitializePasses.h"
  22. #include "llvm/Support/CommandLine.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. #include <utility>
  25. using namespace llvm;
  26. using namespace PatternMatch;
  27. #define DEBUG_TYPE "tti"
  28. static cl::opt<bool> EnableReduxCost("costmodel-reduxcost", cl::init(false),
  29. cl::Hidden,
  30. cl::desc("Recognize reduction patterns."));
  31. namespace {
  32. /// No-op implementation of the TTI interface using the utility base
  33. /// classes.
  34. ///
  35. /// This is used when no target specific information is available.
  36. struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
  37. explicit NoTTIImpl(const DataLayout &DL)
  38. : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
  39. };
  40. } // namespace
  41. bool HardwareLoopInfo::canAnalyze(LoopInfo &LI) {
  42. // If the loop has irreducible control flow, it can not be converted to
  43. // Hardware loop.
  44. LoopBlocksRPO RPOT(L);
  45. RPOT.perform(&LI);
  46. if (containsIrreducibleCFG<const BasicBlock *>(RPOT, LI))
  47. return false;
  48. return true;
  49. }
  50. IntrinsicCostAttributes::IntrinsicCostAttributes(
  51. Intrinsic::ID Id, const CallBase &CI, InstructionCost ScalarizationCost)
  52. : II(dyn_cast<IntrinsicInst>(&CI)), RetTy(CI.getType()), IID(Id),
  53. ScalarizationCost(ScalarizationCost) {
  54. if (const auto *FPMO = dyn_cast<FPMathOperator>(&CI))
  55. FMF = FPMO->getFastMathFlags();
  56. Arguments.insert(Arguments.begin(), CI.arg_begin(), CI.arg_end());
  57. FunctionType *FTy = CI.getCalledFunction()->getFunctionType();
  58. ParamTys.insert(ParamTys.begin(), FTy->param_begin(), FTy->param_end());
  59. }
  60. IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *RTy,
  61. ArrayRef<Type *> Tys,
  62. FastMathFlags Flags,
  63. const IntrinsicInst *I,
  64. InstructionCost ScalarCost)
  65. : II(I), RetTy(RTy), IID(Id), FMF(Flags), ScalarizationCost(ScalarCost) {
  66. ParamTys.insert(ParamTys.begin(), Tys.begin(), Tys.end());
  67. }
  68. IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *Ty,
  69. ArrayRef<const Value *> Args)
  70. : RetTy(Ty), IID(Id) {
  71. Arguments.insert(Arguments.begin(), Args.begin(), Args.end());
  72. ParamTys.reserve(Arguments.size());
  73. for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx)
  74. ParamTys.push_back(Arguments[Idx]->getType());
  75. }
  76. IntrinsicCostAttributes::IntrinsicCostAttributes(Intrinsic::ID Id, Type *RTy,
  77. ArrayRef<const Value *> Args,
  78. ArrayRef<Type *> Tys,
  79. FastMathFlags Flags,
  80. const IntrinsicInst *I,
  81. InstructionCost ScalarCost)
  82. : II(I), RetTy(RTy), IID(Id), FMF(Flags), ScalarizationCost(ScalarCost) {
  83. ParamTys.insert(ParamTys.begin(), Tys.begin(), Tys.end());
  84. Arguments.insert(Arguments.begin(), Args.begin(), Args.end());
  85. }
  86. bool HardwareLoopInfo::isHardwareLoopCandidate(ScalarEvolution &SE,
  87. LoopInfo &LI, DominatorTree &DT,
  88. bool ForceNestedLoop,
  89. bool ForceHardwareLoopPHI) {
  90. SmallVector<BasicBlock *, 4> ExitingBlocks;
  91. L->getExitingBlocks(ExitingBlocks);
  92. for (BasicBlock *BB : ExitingBlocks) {
  93. // If we pass the updated counter back through a phi, we need to know
  94. // which latch the updated value will be coming from.
  95. if (!L->isLoopLatch(BB)) {
  96. if (ForceHardwareLoopPHI || CounterInReg)
  97. continue;
  98. }
  99. const SCEV *EC = SE.getExitCount(L, BB);
  100. if (isa<SCEVCouldNotCompute>(EC))
  101. continue;
  102. if (const SCEVConstant *ConstEC = dyn_cast<SCEVConstant>(EC)) {
  103. if (ConstEC->getValue()->isZero())
  104. continue;
  105. } else if (!SE.isLoopInvariant(EC, L))
  106. continue;
  107. if (SE.getTypeSizeInBits(EC->getType()) > CountType->getBitWidth())
  108. continue;
  109. // If this exiting block is contained in a nested loop, it is not eligible
  110. // for insertion of the branch-and-decrement since the inner loop would
  111. // end up messing up the value in the CTR.
  112. if (!IsNestingLegal && LI.getLoopFor(BB) != L && !ForceNestedLoop)
  113. continue;
  114. // We now have a loop-invariant count of loop iterations (which is not the
  115. // constant zero) for which we know that this loop will not exit via this
  116. // existing block.
  117. // We need to make sure that this block will run on every loop iteration.
  118. // For this to be true, we must dominate all blocks with backedges. Such
  119. // blocks are in-loop predecessors to the header block.
  120. bool NotAlways = false;
  121. for (BasicBlock *Pred : predecessors(L->getHeader())) {
  122. if (!L->contains(Pred))
  123. continue;
  124. if (!DT.dominates(BB, Pred)) {
  125. NotAlways = true;
  126. break;
  127. }
  128. }
  129. if (NotAlways)
  130. continue;
  131. // Make sure this blocks ends with a conditional branch.
  132. Instruction *TI = BB->getTerminator();
  133. if (!TI)
  134. continue;
  135. if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
  136. if (!BI->isConditional())
  137. continue;
  138. ExitBranch = BI;
  139. } else
  140. continue;
  141. // Note that this block may not be the loop latch block, even if the loop
  142. // has a latch block.
  143. ExitBlock = BB;
  144. ExitCount = EC;
  145. break;
  146. }
  147. if (!ExitBlock)
  148. return false;
  149. return true;
  150. }
  151. TargetTransformInfo::TargetTransformInfo(const DataLayout &DL)
  152. : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
  153. TargetTransformInfo::~TargetTransformInfo() {}
  154. TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
  155. : TTIImpl(std::move(Arg.TTIImpl)) {}
  156. TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) {
  157. TTIImpl = std::move(RHS.TTIImpl);
  158. return *this;
  159. }
  160. unsigned TargetTransformInfo::getInliningThresholdMultiplier() const {
  161. return TTIImpl->getInliningThresholdMultiplier();
  162. }
  163. unsigned
  164. TargetTransformInfo::adjustInliningThreshold(const CallBase *CB) const {
  165. return TTIImpl->adjustInliningThreshold(CB);
  166. }
  167. int TargetTransformInfo::getInlinerVectorBonusPercent() const {
  168. return TTIImpl->getInlinerVectorBonusPercent();
  169. }
  170. InstructionCost
  171. TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr,
  172. ArrayRef<const Value *> Operands,
  173. TTI::TargetCostKind CostKind) const {
  174. return TTIImpl->getGEPCost(PointeeType, Ptr, Operands, CostKind);
  175. }
  176. unsigned TargetTransformInfo::getEstimatedNumberOfCaseClusters(
  177. const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI,
  178. BlockFrequencyInfo *BFI) const {
  179. return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
  180. }
  181. InstructionCost
  182. TargetTransformInfo::getUserCost(const User *U,
  183. ArrayRef<const Value *> Operands,
  184. enum TargetCostKind CostKind) const {
  185. InstructionCost Cost = TTIImpl->getUserCost(U, Operands, CostKind);
  186. assert((CostKind == TTI::TCK_RecipThroughput || Cost >= 0) &&
  187. "TTI should not produce negative costs!");
  188. return Cost;
  189. }
  190. BranchProbability TargetTransformInfo::getPredictableBranchThreshold() const {
  191. return TTIImpl->getPredictableBranchThreshold();
  192. }
  193. bool TargetTransformInfo::hasBranchDivergence() const {
  194. return TTIImpl->hasBranchDivergence();
  195. }
  196. bool TargetTransformInfo::useGPUDivergenceAnalysis() const {
  197. return TTIImpl->useGPUDivergenceAnalysis();
  198. }
  199. bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const {
  200. return TTIImpl->isSourceOfDivergence(V);
  201. }
  202. bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const {
  203. return TTIImpl->isAlwaysUniform(V);
  204. }
  205. unsigned TargetTransformInfo::getFlatAddressSpace() const {
  206. return TTIImpl->getFlatAddressSpace();
  207. }
  208. bool TargetTransformInfo::collectFlatAddressOperands(
  209. SmallVectorImpl<int> &OpIndexes, Intrinsic::ID IID) const {
  210. return TTIImpl->collectFlatAddressOperands(OpIndexes, IID);
  211. }
  212. bool TargetTransformInfo::isNoopAddrSpaceCast(unsigned FromAS,
  213. unsigned ToAS) const {
  214. return TTIImpl->isNoopAddrSpaceCast(FromAS, ToAS);
  215. }
  216. bool TargetTransformInfo::canHaveNonUndefGlobalInitializerInAddressSpace(
  217. unsigned AS) const {
  218. return TTIImpl->canHaveNonUndefGlobalInitializerInAddressSpace(AS);
  219. }
  220. unsigned TargetTransformInfo::getAssumedAddrSpace(const Value *V) const {
  221. return TTIImpl->getAssumedAddrSpace(V);
  222. }
  223. std::pair<const Value *, unsigned>
  224. TargetTransformInfo::getPredicatedAddrSpace(const Value *V) const {
  225. return TTIImpl->getPredicatedAddrSpace(V);
  226. }
  227. Value *TargetTransformInfo::rewriteIntrinsicWithAddressSpace(
  228. IntrinsicInst *II, Value *OldV, Value *NewV) const {
  229. return TTIImpl->rewriteIntrinsicWithAddressSpace(II, OldV, NewV);
  230. }
  231. bool TargetTransformInfo::isLoweredToCall(const Function *F) const {
  232. return TTIImpl->isLoweredToCall(F);
  233. }
  234. bool TargetTransformInfo::isHardwareLoopProfitable(
  235. Loop *L, ScalarEvolution &SE, AssumptionCache &AC,
  236. TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const {
  237. return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
  238. }
  239. bool TargetTransformInfo::preferPredicateOverEpilogue(
  240. Loop *L, LoopInfo *LI, ScalarEvolution &SE, AssumptionCache &AC,
  241. TargetLibraryInfo *TLI, DominatorTree *DT,
  242. const LoopAccessInfo *LAI) const {
  243. return TTIImpl->preferPredicateOverEpilogue(L, LI, SE, AC, TLI, DT, LAI);
  244. }
  245. bool TargetTransformInfo::emitGetActiveLaneMask() const {
  246. return TTIImpl->emitGetActiveLaneMask();
  247. }
  248. Optional<Instruction *>
  249. TargetTransformInfo::instCombineIntrinsic(InstCombiner &IC,
  250. IntrinsicInst &II) const {
  251. return TTIImpl->instCombineIntrinsic(IC, II);
  252. }
  253. Optional<Value *> TargetTransformInfo::simplifyDemandedUseBitsIntrinsic(
  254. InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known,
  255. bool &KnownBitsComputed) const {
  256. return TTIImpl->simplifyDemandedUseBitsIntrinsic(IC, II, DemandedMask, Known,
  257. KnownBitsComputed);
  258. }
  259. Optional<Value *> TargetTransformInfo::simplifyDemandedVectorEltsIntrinsic(
  260. InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
  261. APInt &UndefElts2, APInt &UndefElts3,
  262. std::function<void(Instruction *, unsigned, APInt, APInt &)>
  263. SimplifyAndSetOp) const {
  264. return TTIImpl->simplifyDemandedVectorEltsIntrinsic(
  265. IC, II, DemandedElts, UndefElts, UndefElts2, UndefElts3,
  266. SimplifyAndSetOp);
  267. }
  268. void TargetTransformInfo::getUnrollingPreferences(
  269. Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP,
  270. OptimizationRemarkEmitter *ORE) const {
  271. return TTIImpl->getUnrollingPreferences(L, SE, UP, ORE);
  272. }
  273. void TargetTransformInfo::getPeelingPreferences(Loop *L, ScalarEvolution &SE,
  274. PeelingPreferences &PP) const {
  275. return TTIImpl->getPeelingPreferences(L, SE, PP);
  276. }
  277. bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
  278. return TTIImpl->isLegalAddImmediate(Imm);
  279. }
  280. bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
  281. return TTIImpl->isLegalICmpImmediate(Imm);
  282. }
  283. bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
  284. int64_t BaseOffset,
  285. bool HasBaseReg, int64_t Scale,
  286. unsigned AddrSpace,
  287. Instruction *I) const {
  288. return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
  289. Scale, AddrSpace, I);
  290. }
  291. bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const {
  292. return TTIImpl->isLSRCostLess(C1, C2);
  293. }
  294. bool TargetTransformInfo::isNumRegsMajorCostOfLSR() const {
  295. return TTIImpl->isNumRegsMajorCostOfLSR();
  296. }
  297. bool TargetTransformInfo::isProfitableLSRChainElement(Instruction *I) const {
  298. return TTIImpl->isProfitableLSRChainElement(I);
  299. }
  300. bool TargetTransformInfo::canMacroFuseCmp() const {
  301. return TTIImpl->canMacroFuseCmp();
  302. }
  303. bool TargetTransformInfo::canSaveCmp(Loop *L, BranchInst **BI,
  304. ScalarEvolution *SE, LoopInfo *LI,
  305. DominatorTree *DT, AssumptionCache *AC,
  306. TargetLibraryInfo *LibInfo) const {
  307. return TTIImpl->canSaveCmp(L, BI, SE, LI, DT, AC, LibInfo);
  308. }
  309. TTI::AddressingModeKind
  310. TargetTransformInfo::getPreferredAddressingMode(const Loop *L,
  311. ScalarEvolution *SE) const {
  312. return TTIImpl->getPreferredAddressingMode(L, SE);
  313. }
  314. bool TargetTransformInfo::isLegalMaskedStore(Type *DataType,
  315. Align Alignment) const {
  316. return TTIImpl->isLegalMaskedStore(DataType, Alignment);
  317. }
  318. bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType,
  319. Align Alignment) const {
  320. return TTIImpl->isLegalMaskedLoad(DataType, Alignment);
  321. }
  322. bool TargetTransformInfo::isLegalNTStore(Type *DataType,
  323. Align Alignment) const {
  324. return TTIImpl->isLegalNTStore(DataType, Alignment);
  325. }
  326. bool TargetTransformInfo::isLegalNTLoad(Type *DataType, Align Alignment) const {
  327. return TTIImpl->isLegalNTLoad(DataType, Alignment);
  328. }
  329. bool TargetTransformInfo::isLegalMaskedGather(Type *DataType,
  330. Align Alignment) const {
  331. return TTIImpl->isLegalMaskedGather(DataType, Alignment);
  332. }
  333. bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType,
  334. Align Alignment) const {
  335. return TTIImpl->isLegalMaskedScatter(DataType, Alignment);
  336. }
  337. bool TargetTransformInfo::forceScalarizeMaskedGather(VectorType *DataType,
  338. Align Alignment) const {
  339. return TTIImpl->forceScalarizeMaskedGather(DataType, Alignment);
  340. }
  341. bool TargetTransformInfo::forceScalarizeMaskedScatter(VectorType *DataType,
  342. Align Alignment) const {
  343. return TTIImpl->forceScalarizeMaskedScatter(DataType, Alignment);
  344. }
  345. bool TargetTransformInfo::isLegalMaskedCompressStore(Type *DataType) const {
  346. return TTIImpl->isLegalMaskedCompressStore(DataType);
  347. }
  348. bool TargetTransformInfo::isLegalMaskedExpandLoad(Type *DataType) const {
  349. return TTIImpl->isLegalMaskedExpandLoad(DataType);
  350. }
  351. bool TargetTransformInfo::enableOrderedReductions() const {
  352. return TTIImpl->enableOrderedReductions();
  353. }
  354. bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const {
  355. return TTIImpl->hasDivRemOp(DataType, IsSigned);
  356. }
  357. bool TargetTransformInfo::hasVolatileVariant(Instruction *I,
  358. unsigned AddrSpace) const {
  359. return TTIImpl->hasVolatileVariant(I, AddrSpace);
  360. }
  361. bool TargetTransformInfo::prefersVectorizedAddressing() const {
  362. return TTIImpl->prefersVectorizedAddressing();
  363. }
  364. InstructionCost TargetTransformInfo::getScalingFactorCost(
  365. Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg,
  366. int64_t Scale, unsigned AddrSpace) const {
  367. InstructionCost Cost = TTIImpl->getScalingFactorCost(
  368. Ty, BaseGV, BaseOffset, HasBaseReg, Scale, AddrSpace);
  369. assert(Cost >= 0 && "TTI should not produce negative costs!");
  370. return Cost;
  371. }
  372. bool TargetTransformInfo::LSRWithInstrQueries() const {
  373. return TTIImpl->LSRWithInstrQueries();
  374. }
  375. bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
  376. return TTIImpl->isTruncateFree(Ty1, Ty2);
  377. }
  378. bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const {
  379. return TTIImpl->isProfitableToHoist(I);
  380. }
  381. bool TargetTransformInfo::useAA() const { return TTIImpl->useAA(); }
  382. bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
  383. return TTIImpl->isTypeLegal(Ty);
  384. }
  385. InstructionCost TargetTransformInfo::getRegUsageForType(Type *Ty) const {
  386. return TTIImpl->getRegUsageForType(Ty);
  387. }
  388. bool TargetTransformInfo::shouldBuildLookupTables() const {
  389. return TTIImpl->shouldBuildLookupTables();
  390. }
  391. bool TargetTransformInfo::shouldBuildLookupTablesForConstant(
  392. Constant *C) const {
  393. return TTIImpl->shouldBuildLookupTablesForConstant(C);
  394. }
  395. bool TargetTransformInfo::shouldBuildRelLookupTables() const {
  396. return TTIImpl->shouldBuildRelLookupTables();
  397. }
  398. bool TargetTransformInfo::useColdCCForColdCall(Function &F) const {
  399. return TTIImpl->useColdCCForColdCall(F);
  400. }
  401. InstructionCost
  402. TargetTransformInfo::getScalarizationOverhead(VectorType *Ty,
  403. const APInt &DemandedElts,
  404. bool Insert, bool Extract) const {
  405. return TTIImpl->getScalarizationOverhead(Ty, DemandedElts, Insert, Extract);
  406. }
  407. InstructionCost TargetTransformInfo::getOperandsScalarizationOverhead(
  408. ArrayRef<const Value *> Args, ArrayRef<Type *> Tys) const {
  409. return TTIImpl->getOperandsScalarizationOverhead(Args, Tys);
  410. }
  411. bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const {
  412. return TTIImpl->supportsEfficientVectorElementLoadStore();
  413. }
  414. bool TargetTransformInfo::enableAggressiveInterleaving(
  415. bool LoopHasReductions) const {
  416. return TTIImpl->enableAggressiveInterleaving(LoopHasReductions);
  417. }
  418. TargetTransformInfo::MemCmpExpansionOptions
  419. TargetTransformInfo::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
  420. return TTIImpl->enableMemCmpExpansion(OptSize, IsZeroCmp);
  421. }
  422. bool TargetTransformInfo::enableInterleavedAccessVectorization() const {
  423. return TTIImpl->enableInterleavedAccessVectorization();
  424. }
  425. bool TargetTransformInfo::enableMaskedInterleavedAccessVectorization() const {
  426. return TTIImpl->enableMaskedInterleavedAccessVectorization();
  427. }
  428. bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const {
  429. return TTIImpl->isFPVectorizationPotentiallyUnsafe();
  430. }
  431. bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context,
  432. unsigned BitWidth,
  433. unsigned AddressSpace,
  434. Align Alignment,
  435. bool *Fast) const {
  436. return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth,
  437. AddressSpace, Alignment, Fast);
  438. }
  439. TargetTransformInfo::PopcntSupportKind
  440. TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
  441. return TTIImpl->getPopcntSupport(IntTyWidthInBit);
  442. }
  443. bool TargetTransformInfo::haveFastSqrt(Type *Ty) const {
  444. return TTIImpl->haveFastSqrt(Ty);
  445. }
  446. bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const {
  447. return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
  448. }
  449. InstructionCost TargetTransformInfo::getFPOpCost(Type *Ty) const {
  450. InstructionCost Cost = TTIImpl->getFPOpCost(Ty);
  451. assert(Cost >= 0 && "TTI should not produce negative costs!");
  452. return Cost;
  453. }
  454. InstructionCost TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode,
  455. unsigned Idx,
  456. const APInt &Imm,
  457. Type *Ty) const {
  458. InstructionCost Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty);
  459. assert(Cost >= 0 && "TTI should not produce negative costs!");
  460. return Cost;
  461. }
  462. InstructionCost
  463. TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty,
  464. TTI::TargetCostKind CostKind) const {
  465. InstructionCost Cost = TTIImpl->getIntImmCost(Imm, Ty, CostKind);
  466. assert(Cost >= 0 && "TTI should not produce negative costs!");
  467. return Cost;
  468. }
  469. InstructionCost TargetTransformInfo::getIntImmCostInst(
  470. unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty,
  471. TTI::TargetCostKind CostKind, Instruction *Inst) const {
  472. InstructionCost Cost =
  473. TTIImpl->getIntImmCostInst(Opcode, Idx, Imm, Ty, CostKind, Inst);
  474. assert(Cost >= 0 && "TTI should not produce negative costs!");
  475. return Cost;
  476. }
  477. InstructionCost
  478. TargetTransformInfo::getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
  479. const APInt &Imm, Type *Ty,
  480. TTI::TargetCostKind CostKind) const {
  481. InstructionCost Cost =
  482. TTIImpl->getIntImmCostIntrin(IID, Idx, Imm, Ty, CostKind);
  483. assert(Cost >= 0 && "TTI should not produce negative costs!");
  484. return Cost;
  485. }
  486. unsigned TargetTransformInfo::getNumberOfRegisters(unsigned ClassID) const {
  487. return TTIImpl->getNumberOfRegisters(ClassID);
  488. }
  489. unsigned TargetTransformInfo::getRegisterClassForType(bool Vector,
  490. Type *Ty) const {
  491. return TTIImpl->getRegisterClassForType(Vector, Ty);
  492. }
  493. const char *TargetTransformInfo::getRegisterClassName(unsigned ClassID) const {
  494. return TTIImpl->getRegisterClassName(ClassID);
  495. }
  496. TypeSize TargetTransformInfo::getRegisterBitWidth(
  497. TargetTransformInfo::RegisterKind K) const {
  498. return TTIImpl->getRegisterBitWidth(K);
  499. }
  500. unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const {
  501. return TTIImpl->getMinVectorRegisterBitWidth();
  502. }
  503. Optional<unsigned> TargetTransformInfo::getMaxVScale() const {
  504. return TTIImpl->getMaxVScale();
  505. }
  506. Optional<unsigned> TargetTransformInfo::getVScaleForTuning() const {
  507. return TTIImpl->getVScaleForTuning();
  508. }
  509. bool TargetTransformInfo::shouldMaximizeVectorBandwidth() const {
  510. return TTIImpl->shouldMaximizeVectorBandwidth();
  511. }
  512. ElementCount TargetTransformInfo::getMinimumVF(unsigned ElemWidth,
  513. bool IsScalable) const {
  514. return TTIImpl->getMinimumVF(ElemWidth, IsScalable);
  515. }
  516. unsigned TargetTransformInfo::getMaximumVF(unsigned ElemWidth,
  517. unsigned Opcode) const {
  518. return TTIImpl->getMaximumVF(ElemWidth, Opcode);
  519. }
  520. bool TargetTransformInfo::shouldConsiderAddressTypePromotion(
  521. const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
  522. return TTIImpl->shouldConsiderAddressTypePromotion(
  523. I, AllowPromotionWithoutCommonHeader);
  524. }
  525. unsigned TargetTransformInfo::getCacheLineSize() const {
  526. return TTIImpl->getCacheLineSize();
  527. }
  528. llvm::Optional<unsigned>
  529. TargetTransformInfo::getCacheSize(CacheLevel Level) const {
  530. return TTIImpl->getCacheSize(Level);
  531. }
  532. llvm::Optional<unsigned>
  533. TargetTransformInfo::getCacheAssociativity(CacheLevel Level) const {
  534. return TTIImpl->getCacheAssociativity(Level);
  535. }
  536. unsigned TargetTransformInfo::getPrefetchDistance() const {
  537. return TTIImpl->getPrefetchDistance();
  538. }
  539. unsigned TargetTransformInfo::getMinPrefetchStride(
  540. unsigned NumMemAccesses, unsigned NumStridedMemAccesses,
  541. unsigned NumPrefetches, bool HasCall) const {
  542. return TTIImpl->getMinPrefetchStride(NumMemAccesses, NumStridedMemAccesses,
  543. NumPrefetches, HasCall);
  544. }
  545. unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const {
  546. return TTIImpl->getMaxPrefetchIterationsAhead();
  547. }
  548. bool TargetTransformInfo::enableWritePrefetching() const {
  549. return TTIImpl->enableWritePrefetching();
  550. }
  551. unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const {
  552. return TTIImpl->getMaxInterleaveFactor(VF);
  553. }
  554. TargetTransformInfo::OperandValueKind
  555. TargetTransformInfo::getOperandInfo(const Value *V,
  556. OperandValueProperties &OpProps) {
  557. OperandValueKind OpInfo = OK_AnyValue;
  558. OpProps = OP_None;
  559. if (const auto *CI = dyn_cast<ConstantInt>(V)) {
  560. if (CI->getValue().isPowerOf2())
  561. OpProps = OP_PowerOf2;
  562. return OK_UniformConstantValue;
  563. }
  564. // A broadcast shuffle creates a uniform value.
  565. // TODO: Add support for non-zero index broadcasts.
  566. // TODO: Add support for different source vector width.
  567. if (const auto *ShuffleInst = dyn_cast<ShuffleVectorInst>(V))
  568. if (ShuffleInst->isZeroEltSplat())
  569. OpInfo = OK_UniformValue;
  570. const Value *Splat = getSplatValue(V);
  571. // Check for a splat of a constant or for a non uniform vector of constants
  572. // and check if the constant(s) are all powers of two.
  573. if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
  574. OpInfo = OK_NonUniformConstantValue;
  575. if (Splat) {
  576. OpInfo = OK_UniformConstantValue;
  577. if (auto *CI = dyn_cast<ConstantInt>(Splat))
  578. if (CI->getValue().isPowerOf2())
  579. OpProps = OP_PowerOf2;
  580. } else if (const auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
  581. OpProps = OP_PowerOf2;
  582. for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
  583. if (auto *CI = dyn_cast<ConstantInt>(CDS->getElementAsConstant(I)))
  584. if (CI->getValue().isPowerOf2())
  585. continue;
  586. OpProps = OP_None;
  587. break;
  588. }
  589. }
  590. }
  591. // Check for a splat of a uniform value. This is not loop aware, so return
  592. // true only for the obviously uniform cases (argument, globalvalue)
  593. if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat)))
  594. OpInfo = OK_UniformValue;
  595. return OpInfo;
  596. }
  597. InstructionCost TargetTransformInfo::getArithmeticInstrCost(
  598. unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
  599. OperandValueKind Opd1Info, OperandValueKind Opd2Info,
  600. OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo,
  601. ArrayRef<const Value *> Args, const Instruction *CxtI) const {
  602. InstructionCost Cost =
  603. TTIImpl->getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
  604. Opd1PropInfo, Opd2PropInfo, Args, CxtI);
  605. assert(Cost >= 0 && "TTI should not produce negative costs!");
  606. return Cost;
  607. }
  608. InstructionCost TargetTransformInfo::getShuffleCost(ShuffleKind Kind,
  609. VectorType *Ty,
  610. ArrayRef<int> Mask,
  611. int Index,
  612. VectorType *SubTp) const {
  613. InstructionCost Cost = TTIImpl->getShuffleCost(Kind, Ty, Mask, Index, SubTp);
  614. assert(Cost >= 0 && "TTI should not produce negative costs!");
  615. return Cost;
  616. }
  617. TTI::CastContextHint
  618. TargetTransformInfo::getCastContextHint(const Instruction *I) {
  619. if (!I)
  620. return CastContextHint::None;
  621. auto getLoadStoreKind = [](const Value *V, unsigned LdStOp, unsigned MaskedOp,
  622. unsigned GatScatOp) {
  623. const Instruction *I = dyn_cast<Instruction>(V);
  624. if (!I)
  625. return CastContextHint::None;
  626. if (I->getOpcode() == LdStOp)
  627. return CastContextHint::Normal;
  628. if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
  629. if (II->getIntrinsicID() == MaskedOp)
  630. return TTI::CastContextHint::Masked;
  631. if (II->getIntrinsicID() == GatScatOp)
  632. return TTI::CastContextHint::GatherScatter;
  633. }
  634. return TTI::CastContextHint::None;
  635. };
  636. switch (I->getOpcode()) {
  637. case Instruction::ZExt:
  638. case Instruction::SExt:
  639. case Instruction::FPExt:
  640. return getLoadStoreKind(I->getOperand(0), Instruction::Load,
  641. Intrinsic::masked_load, Intrinsic::masked_gather);
  642. case Instruction::Trunc:
  643. case Instruction::FPTrunc:
  644. if (I->hasOneUse())
  645. return getLoadStoreKind(*I->user_begin(), Instruction::Store,
  646. Intrinsic::masked_store,
  647. Intrinsic::masked_scatter);
  648. break;
  649. default:
  650. return CastContextHint::None;
  651. }
  652. return TTI::CastContextHint::None;
  653. }
  654. InstructionCost TargetTransformInfo::getCastInstrCost(
  655. unsigned Opcode, Type *Dst, Type *Src, CastContextHint CCH,
  656. TTI::TargetCostKind CostKind, const Instruction *I) const {
  657. assert((I == nullptr || I->getOpcode() == Opcode) &&
  658. "Opcode should reflect passed instruction.");
  659. InstructionCost Cost =
  660. TTIImpl->getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
  661. assert(Cost >= 0 && "TTI should not produce negative costs!");
  662. return Cost;
  663. }
  664. InstructionCost TargetTransformInfo::getExtractWithExtendCost(
  665. unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index) const {
  666. InstructionCost Cost =
  667. TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
  668. assert(Cost >= 0 && "TTI should not produce negative costs!");
  669. return Cost;
  670. }
  671. InstructionCost TargetTransformInfo::getCFInstrCost(
  672. unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I) const {
  673. assert((I == nullptr || I->getOpcode() == Opcode) &&
  674. "Opcode should reflect passed instruction.");
  675. InstructionCost Cost = TTIImpl->getCFInstrCost(Opcode, CostKind, I);
  676. assert(Cost >= 0 && "TTI should not produce negative costs!");
  677. return Cost;
  678. }
  679. InstructionCost TargetTransformInfo::getCmpSelInstrCost(
  680. unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
  681. TTI::TargetCostKind CostKind, const Instruction *I) const {
  682. assert((I == nullptr || I->getOpcode() == Opcode) &&
  683. "Opcode should reflect passed instruction.");
  684. InstructionCost Cost =
  685. TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);
  686. assert(Cost >= 0 && "TTI should not produce negative costs!");
  687. return Cost;
  688. }
  689. InstructionCost TargetTransformInfo::getVectorInstrCost(unsigned Opcode,
  690. Type *Val,
  691. unsigned Index) const {
  692. InstructionCost Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index);
  693. assert(Cost >= 0 && "TTI should not produce negative costs!");
  694. return Cost;
  695. }
  696. InstructionCost TargetTransformInfo::getReplicationShuffleCost(
  697. Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts,
  698. TTI::TargetCostKind CostKind) {
  699. InstructionCost Cost = TTIImpl->getReplicationShuffleCost(
  700. EltTy, ReplicationFactor, VF, DemandedDstElts, CostKind);
  701. assert(Cost >= 0 && "TTI should not produce negative costs!");
  702. return Cost;
  703. }
  704. InstructionCost TargetTransformInfo::getMemoryOpCost(
  705. unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
  706. TTI::TargetCostKind CostKind, const Instruction *I) const {
  707. assert((I == nullptr || I->getOpcode() == Opcode) &&
  708. "Opcode should reflect passed instruction.");
  709. InstructionCost Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment,
  710. AddressSpace, CostKind, I);
  711. assert(Cost >= 0 && "TTI should not produce negative costs!");
  712. return Cost;
  713. }
  714. InstructionCost TargetTransformInfo::getMaskedMemoryOpCost(
  715. unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
  716. TTI::TargetCostKind CostKind) const {
  717. InstructionCost Cost = TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment,
  718. AddressSpace, CostKind);
  719. assert(Cost >= 0 && "TTI should not produce negative costs!");
  720. return Cost;
  721. }
  722. InstructionCost TargetTransformInfo::getGatherScatterOpCost(
  723. unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
  724. Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I) const {
  725. InstructionCost Cost = TTIImpl->getGatherScatterOpCost(
  726. Opcode, DataTy, Ptr, VariableMask, Alignment, CostKind, I);
  727. assert(Cost >= 0 && "TTI should not produce negative costs!");
  728. return Cost;
  729. }
  730. InstructionCost TargetTransformInfo::getInterleavedMemoryOpCost(
  731. unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
  732. Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
  733. bool UseMaskForCond, bool UseMaskForGaps) const {
  734. InstructionCost Cost = TTIImpl->getInterleavedMemoryOpCost(
  735. Opcode, VecTy, Factor, Indices, Alignment, AddressSpace, CostKind,
  736. UseMaskForCond, UseMaskForGaps);
  737. assert(Cost >= 0 && "TTI should not produce negative costs!");
  738. return Cost;
  739. }
  740. InstructionCost
  741. TargetTransformInfo::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
  742. TTI::TargetCostKind CostKind) const {
  743. InstructionCost Cost = TTIImpl->getIntrinsicInstrCost(ICA, CostKind);
  744. assert(Cost >= 0 && "TTI should not produce negative costs!");
  745. return Cost;
  746. }
  747. InstructionCost
  748. TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy,
  749. ArrayRef<Type *> Tys,
  750. TTI::TargetCostKind CostKind) const {
  751. InstructionCost Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys, CostKind);
  752. assert(Cost >= 0 && "TTI should not produce negative costs!");
  753. return Cost;
  754. }
  755. unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
  756. return TTIImpl->getNumberOfParts(Tp);
  757. }
  758. InstructionCost
  759. TargetTransformInfo::getAddressComputationCost(Type *Tp, ScalarEvolution *SE,
  760. const SCEV *Ptr) const {
  761. InstructionCost Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr);
  762. assert(Cost >= 0 && "TTI should not produce negative costs!");
  763. return Cost;
  764. }
  765. InstructionCost TargetTransformInfo::getMemcpyCost(const Instruction *I) const {
  766. InstructionCost Cost = TTIImpl->getMemcpyCost(I);
  767. assert(Cost >= 0 && "TTI should not produce negative costs!");
  768. return Cost;
  769. }
  770. InstructionCost TargetTransformInfo::getArithmeticReductionCost(
  771. unsigned Opcode, VectorType *Ty, Optional<FastMathFlags> FMF,
  772. TTI::TargetCostKind CostKind) const {
  773. InstructionCost Cost =
  774. TTIImpl->getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);
  775. assert(Cost >= 0 && "TTI should not produce negative costs!");
  776. return Cost;
  777. }
  778. InstructionCost TargetTransformInfo::getMinMaxReductionCost(
  779. VectorType *Ty, VectorType *CondTy, bool IsUnsigned,
  780. TTI::TargetCostKind CostKind) const {
  781. InstructionCost Cost =
  782. TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsUnsigned, CostKind);
  783. assert(Cost >= 0 && "TTI should not produce negative costs!");
  784. return Cost;
  785. }
  786. InstructionCost TargetTransformInfo::getExtendedAddReductionCost(
  787. bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
  788. TTI::TargetCostKind CostKind) const {
  789. return TTIImpl->getExtendedAddReductionCost(IsMLA, IsUnsigned, ResTy, Ty,
  790. CostKind);
  791. }
  792. InstructionCost
  793. TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
  794. return TTIImpl->getCostOfKeepingLiveOverCall(Tys);
  795. }
  796. bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst,
  797. MemIntrinsicInfo &Info) const {
  798. return TTIImpl->getTgtMemIntrinsic(Inst, Info);
  799. }
  800. unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const {
  801. return TTIImpl->getAtomicMemIntrinsicMaxElementSize();
  802. }
  803. Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
  804. IntrinsicInst *Inst, Type *ExpectedType) const {
  805. return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
  806. }
  807. Type *TargetTransformInfo::getMemcpyLoopLoweringType(
  808. LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
  809. unsigned DestAddrSpace, unsigned SrcAlign, unsigned DestAlign) const {
  810. return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAddrSpace,
  811. DestAddrSpace, SrcAlign, DestAlign);
  812. }
  813. void TargetTransformInfo::getMemcpyLoopResidualLoweringType(
  814. SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
  815. unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
  816. unsigned SrcAlign, unsigned DestAlign) const {
  817. TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
  818. SrcAddrSpace, DestAddrSpace,
  819. SrcAlign, DestAlign);
  820. }
  821. bool TargetTransformInfo::areInlineCompatible(const Function *Caller,
  822. const Function *Callee) const {
  823. return TTIImpl->areInlineCompatible(Caller, Callee);
  824. }
  825. bool TargetTransformInfo::areTypesABICompatible(
  826. const Function *Caller, const Function *Callee,
  827. const ArrayRef<Type *> &Types) const {
  828. return TTIImpl->areTypesABICompatible(Caller, Callee, Types);
  829. }
  830. bool TargetTransformInfo::isIndexedLoadLegal(MemIndexedMode Mode,
  831. Type *Ty) const {
  832. return TTIImpl->isIndexedLoadLegal(Mode, Ty);
  833. }
  834. bool TargetTransformInfo::isIndexedStoreLegal(MemIndexedMode Mode,
  835. Type *Ty) const {
  836. return TTIImpl->isIndexedStoreLegal(Mode, Ty);
  837. }
  838. unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const {
  839. return TTIImpl->getLoadStoreVecRegBitWidth(AS);
  840. }
  841. bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const {
  842. return TTIImpl->isLegalToVectorizeLoad(LI);
  843. }
  844. bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const {
  845. return TTIImpl->isLegalToVectorizeStore(SI);
  846. }
  847. bool TargetTransformInfo::isLegalToVectorizeLoadChain(
  848. unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const {
  849. return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
  850. AddrSpace);
  851. }
  852. bool TargetTransformInfo::isLegalToVectorizeStoreChain(
  853. unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const {
  854. return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
  855. AddrSpace);
  856. }
  857. bool TargetTransformInfo::isLegalToVectorizeReduction(
  858. const RecurrenceDescriptor &RdxDesc, ElementCount VF) const {
  859. return TTIImpl->isLegalToVectorizeReduction(RdxDesc, VF);
  860. }
  861. bool TargetTransformInfo::isElementTypeLegalForScalableVector(Type *Ty) const {
  862. return TTIImpl->isElementTypeLegalForScalableVector(Ty);
  863. }
  864. unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF,
  865. unsigned LoadSize,
  866. unsigned ChainSizeInBytes,
  867. VectorType *VecTy) const {
  868. return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
  869. }
  870. unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF,
  871. unsigned StoreSize,
  872. unsigned ChainSizeInBytes,
  873. VectorType *VecTy) const {
  874. return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
  875. }
  876. bool TargetTransformInfo::preferInLoopReduction(unsigned Opcode, Type *Ty,
  877. ReductionFlags Flags) const {
  878. return TTIImpl->preferInLoopReduction(Opcode, Ty, Flags);
  879. }
  880. bool TargetTransformInfo::preferPredicatedReductionSelect(
  881. unsigned Opcode, Type *Ty, ReductionFlags Flags) const {
  882. return TTIImpl->preferPredicatedReductionSelect(Opcode, Ty, Flags);
  883. }
  884. TargetTransformInfo::VPLegalization
  885. TargetTransformInfo::getVPLegalizationStrategy(const VPIntrinsic &VPI) const {
  886. return TTIImpl->getVPLegalizationStrategy(VPI);
  887. }
  888. bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
  889. return TTIImpl->shouldExpandReduction(II);
  890. }
  891. unsigned TargetTransformInfo::getGISelRematGlobalCost() const {
  892. return TTIImpl->getGISelRematGlobalCost();
  893. }
  894. bool TargetTransformInfo::supportsScalableVectors() const {
  895. return TTIImpl->supportsScalableVectors();
  896. }
  897. bool TargetTransformInfo::enableScalableVectorization() const {
  898. return TTIImpl->enableScalableVectorization();
  899. }
  900. bool TargetTransformInfo::hasActiveVectorLength(unsigned Opcode, Type *DataType,
  901. Align Alignment) const {
  902. return TTIImpl->hasActiveVectorLength(Opcode, DataType, Alignment);
  903. }
  904. InstructionCost
  905. TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
  906. return TTIImpl->getInstructionLatency(I);
  907. }
  908. InstructionCost
  909. TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
  910. TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
  911. switch (I->getOpcode()) {
  912. case Instruction::GetElementPtr:
  913. case Instruction::Ret:
  914. case Instruction::PHI:
  915. case Instruction::Br:
  916. case Instruction::Add:
  917. case Instruction::FAdd:
  918. case Instruction::Sub:
  919. case Instruction::FSub:
  920. case Instruction::Mul:
  921. case Instruction::FMul:
  922. case Instruction::UDiv:
  923. case Instruction::SDiv:
  924. case Instruction::FDiv:
  925. case Instruction::URem:
  926. case Instruction::SRem:
  927. case Instruction::FRem:
  928. case Instruction::Shl:
  929. case Instruction::LShr:
  930. case Instruction::AShr:
  931. case Instruction::And:
  932. case Instruction::Or:
  933. case Instruction::Xor:
  934. case Instruction::FNeg:
  935. case Instruction::Select:
  936. case Instruction::ICmp:
  937. case Instruction::FCmp:
  938. case Instruction::Store:
  939. case Instruction::Load:
  940. case Instruction::ZExt:
  941. case Instruction::SExt:
  942. case Instruction::FPToUI:
  943. case Instruction::FPToSI:
  944. case Instruction::FPExt:
  945. case Instruction::PtrToInt:
  946. case Instruction::IntToPtr:
  947. case Instruction::SIToFP:
  948. case Instruction::UIToFP:
  949. case Instruction::Trunc:
  950. case Instruction::FPTrunc:
  951. case Instruction::BitCast:
  952. case Instruction::AddrSpaceCast:
  953. case Instruction::ExtractElement:
  954. case Instruction::InsertElement:
  955. case Instruction::ExtractValue:
  956. case Instruction::ShuffleVector:
  957. case Instruction::Call:
  958. case Instruction::Switch:
  959. return getUserCost(I, CostKind);
  960. default:
  961. // We don't have any information on this instruction.
  962. return -1;
  963. }
  964. }
  965. TargetTransformInfo::Concept::~Concept() {}
  966. TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {}
  967. TargetIRAnalysis::TargetIRAnalysis(
  968. std::function<Result(const Function &)> TTICallback)
  969. : TTICallback(std::move(TTICallback)) {}
  970. TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
  971. FunctionAnalysisManager &) {
  972. return TTICallback(F);
  973. }
  974. AnalysisKey TargetIRAnalysis::Key;
  975. TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
  976. return Result(F.getParent()->getDataLayout());
  977. }
  978. // Register the basic pass.
  979. INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
  980. "Target Transform Information", false, true)
  981. char TargetTransformInfoWrapperPass::ID = 0;
  982. void TargetTransformInfoWrapperPass::anchor() {}
  983. TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass()
  984. : ImmutablePass(ID) {
  985. initializeTargetTransformInfoWrapperPassPass(
  986. *PassRegistry::getPassRegistry());
  987. }
  988. TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
  989. TargetIRAnalysis TIRA)
  990. : ImmutablePass(ID), TIRA(std::move(TIRA)) {
  991. initializeTargetTransformInfoWrapperPassPass(
  992. *PassRegistry::getPassRegistry());
  993. }
  994. TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) {
  995. FunctionAnalysisManager DummyFAM;
  996. TTI = TIRA.run(F, DummyFAM);
  997. return *TTI;
  998. }
  999. ImmutablePass *
  1000. llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) {
  1001. return new TargetTransformInfoWrapperPass(std::move(TIRA));
  1002. }