1 //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Analysis/TargetTransformInfo.h" 11 #include "llvm/Analysis/TargetTransformInfoImpl.h" 12 #include "llvm/IR/CallSite.h" 13 #include "llvm/IR/DataLayout.h" 14 #include "llvm/IR/Instruction.h" 15 #include "llvm/IR/Instructions.h" 16 #include "llvm/IR/IntrinsicInst.h" 17 #include "llvm/IR/Module.h" 18 #include "llvm/IR/Operator.h" 19 #include "llvm/Support/CommandLine.h" 20 #include "llvm/Support/ErrorHandling.h" 21 #include <utility> 22 23 using namespace llvm; 24 25 #define DEBUG_TYPE "tti" 26 27 static cl::opt<bool> UseWideMemcpyLoopLowering( 28 "use-wide-memcpy-loop-lowering", cl::init(false), 29 cl::desc("Enables the new wide memcpy loop lowering in Transforms/Utils."), 30 cl::Hidden); 31 32 namespace { 33 /// \brief No-op implementation of the TTI interface using the utility base 34 /// classes. 35 /// 36 /// This is used when no target specific information is available. 37 struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> { 38 explicit NoTTIImpl(const DataLayout &DL) 39 : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {} 40 }; 41 } 42 43 TargetTransformInfo::TargetTransformInfo(const DataLayout &DL) 44 : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {} 45 46 TargetTransformInfo::~TargetTransformInfo() {} 47 48 TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg) 49 : TTIImpl(std::move(Arg.TTIImpl)) {} 50 51 TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) { 52 TTIImpl = std::move(RHS.TTIImpl); 53 return *this; 54 } 55 56 int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty, 57 Type *OpTy) const { 58 int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy); 59 assert(Cost >= 0 && "TTI should not produce negative costs!"); 60 return Cost; 61 } 62 63 int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const { 64 int Cost = TTIImpl->getCallCost(FTy, NumArgs); 65 assert(Cost >= 0 && "TTI should not produce negative costs!"); 66 return Cost; 67 } 68 69 int TargetTransformInfo::getCallCost(const Function *F, 70 ArrayRef<const Value *> Arguments) const { 71 int Cost = TTIImpl->getCallCost(F, Arguments); 72 assert(Cost >= 0 && "TTI should not produce negative costs!"); 73 return Cost; 74 } 75 76 unsigned TargetTransformInfo::getInliningThresholdMultiplier() const { 77 return TTIImpl->getInliningThresholdMultiplier(); 78 } 79 80 int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr, 81 ArrayRef<const Value *> Operands) const { 82 return TTIImpl->getGEPCost(PointeeType, Ptr, Operands); 83 } 84 85 int TargetTransformInfo::getExtCost(const Instruction *I, 86 const Value *Src) const { 87 return TTIImpl->getExtCost(I, Src); 88 } 89 90 int TargetTransformInfo::getIntrinsicCost( 91 Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const { 92 int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments); 93 assert(Cost >= 0 && "TTI should not produce negative costs!"); 94 return Cost; 95 } 96 97 unsigned 98 TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI, 99 unsigned &JTSize) const { 100 return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize); 101 } 102 103 int TargetTransformInfo::getUserCost(const User *U, 104 ArrayRef<const Value *> Operands) const { 105 int Cost = TTIImpl->getUserCost(U, Operands); 106 assert(Cost >= 0 && "TTI should not produce negative costs!"); 107 return Cost; 108 } 109 110 bool TargetTransformInfo::hasBranchDivergence() const { 111 return TTIImpl->hasBranchDivergence(); 112 } 113 114 bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const { 115 return TTIImpl->isSourceOfDivergence(V); 116 } 117 118 bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const { 119 return TTIImpl->isAlwaysUniform(V); 120 } 121 122 unsigned TargetTransformInfo::getFlatAddressSpace() const { 123 return TTIImpl->getFlatAddressSpace(); 124 } 125 126 bool TargetTransformInfo::isLoweredToCall(const Function *F) const { 127 return TTIImpl->isLoweredToCall(F); 128 } 129 130 void TargetTransformInfo::getUnrollingPreferences( 131 Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const { 132 return TTIImpl->getUnrollingPreferences(L, SE, UP); 133 } 134 135 bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const { 136 return TTIImpl->isLegalAddImmediate(Imm); 137 } 138 139 bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const { 140 return TTIImpl->isLegalICmpImmediate(Imm); 141 } 142 143 bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, 144 int64_t BaseOffset, 145 bool HasBaseReg, 146 int64_t Scale, 147 unsigned AddrSpace, 148 Instruction *I) const { 149 return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, 150 Scale, AddrSpace, I); 151 } 152 153 bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const { 154 return TTIImpl->isLSRCostLess(C1, C2); 155 } 156 157 bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const { 158 return TTIImpl->isLegalMaskedStore(DataType); 159 } 160 161 bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const { 162 return TTIImpl->isLegalMaskedLoad(DataType); 163 } 164 165 bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const { 166 return TTIImpl->isLegalMaskedGather(DataType); 167 } 168 169 bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const { 170 return TTIImpl->isLegalMaskedScatter(DataType); 171 } 172 173 bool TargetTransformInfo::prefersVectorizedAddressing() const { 174 return TTIImpl->prefersVectorizedAddressing(); 175 } 176 177 int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, 178 int64_t BaseOffset, 179 bool HasBaseReg, 180 int64_t Scale, 181 unsigned AddrSpace) const { 182 int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, 183 Scale, AddrSpace); 184 assert(Cost >= 0 && "TTI should not produce negative costs!"); 185 return Cost; 186 } 187 188 bool TargetTransformInfo::LSRWithInstrQueries() const { 189 return TTIImpl->LSRWithInstrQueries(); 190 } 191 192 bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { 193 return TTIImpl->isTruncateFree(Ty1, Ty2); 194 } 195 196 bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const { 197 return TTIImpl->isProfitableToHoist(I); 198 } 199 200 bool TargetTransformInfo::isTypeLegal(Type *Ty) const { 201 return TTIImpl->isTypeLegal(Ty); 202 } 203 204 unsigned TargetTransformInfo::getJumpBufAlignment() const { 205 return TTIImpl->getJumpBufAlignment(); 206 } 207 208 unsigned TargetTransformInfo::getJumpBufSize() const { 209 return TTIImpl->getJumpBufSize(); 210 } 211 212 bool TargetTransformInfo::shouldBuildLookupTables() const { 213 return TTIImpl->shouldBuildLookupTables(); 214 } 215 bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const { 216 return TTIImpl->shouldBuildLookupTablesForConstant(C); 217 } 218 219 unsigned TargetTransformInfo:: 220 getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const { 221 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract); 222 } 223 224 unsigned TargetTransformInfo:: 225 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args, 226 unsigned VF) const { 227 return TTIImpl->getOperandsScalarizationOverhead(Args, VF); 228 } 229 230 bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const { 231 return TTIImpl->supportsEfficientVectorElementLoadStore(); 232 } 233 234 bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const { 235 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions); 236 } 237 238 bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const { 239 return TTIImpl->expandMemCmp(I, MaxLoadSize); 240 } 241 242 bool TargetTransformInfo::enableInterleavedAccessVectorization() const { 243 return TTIImpl->enableInterleavedAccessVectorization(); 244 } 245 246 bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const { 247 return TTIImpl->isFPVectorizationPotentiallyUnsafe(); 248 } 249 250 bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context, 251 unsigned BitWidth, 252 unsigned AddressSpace, 253 unsigned Alignment, 254 bool *Fast) const { 255 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace, 256 Alignment, Fast); 257 } 258 259 TargetTransformInfo::PopcntSupportKind 260 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const { 261 return TTIImpl->getPopcntSupport(IntTyWidthInBit); 262 } 263 264 bool TargetTransformInfo::haveFastSqrt(Type *Ty) const { 265 return TTIImpl->haveFastSqrt(Ty); 266 } 267 268 int TargetTransformInfo::getFPOpCost(Type *Ty) const { 269 int Cost = TTIImpl->getFPOpCost(Ty); 270 assert(Cost >= 0 && "TTI should not produce negative costs!"); 271 return Cost; 272 } 273 274 int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, 275 const APInt &Imm, 276 Type *Ty) const { 277 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty); 278 assert(Cost >= 0 && "TTI should not produce negative costs!"); 279 return Cost; 280 } 281 282 int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { 283 int Cost = TTIImpl->getIntImmCost(Imm, Ty); 284 assert(Cost >= 0 && "TTI should not produce negative costs!"); 285 return Cost; 286 } 287 288 int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx, 289 const APInt &Imm, Type *Ty) const { 290 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty); 291 assert(Cost >= 0 && "TTI should not produce negative costs!"); 292 return Cost; 293 } 294 295 int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx, 296 const APInt &Imm, Type *Ty) const { 297 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty); 298 assert(Cost >= 0 && "TTI should not produce negative costs!"); 299 return Cost; 300 } 301 302 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { 303 return TTIImpl->getNumberOfRegisters(Vector); 304 } 305 306 unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const { 307 return TTIImpl->getRegisterBitWidth(Vector); 308 } 309 310 unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const { 311 return TTIImpl->getMinVectorRegisterBitWidth(); 312 } 313 314 bool TargetTransformInfo::shouldConsiderAddressTypePromotion( 315 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const { 316 return TTIImpl->shouldConsiderAddressTypePromotion( 317 I, AllowPromotionWithoutCommonHeader); 318 } 319 320 unsigned TargetTransformInfo::getCacheLineSize() const { 321 return TTIImpl->getCacheLineSize(); 322 } 323 324 llvm::Optional<unsigned> TargetTransformInfo::getCacheSize(CacheLevel Level) 325 const { 326 return TTIImpl->getCacheSize(Level); 327 } 328 329 llvm::Optional<unsigned> TargetTransformInfo::getCacheAssociativity( 330 CacheLevel Level) const { 331 return TTIImpl->getCacheAssociativity(Level); 332 } 333 334 unsigned TargetTransformInfo::getPrefetchDistance() const { 335 return TTIImpl->getPrefetchDistance(); 336 } 337 338 unsigned TargetTransformInfo::getMinPrefetchStride() const { 339 return TTIImpl->getMinPrefetchStride(); 340 } 341 342 unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const { 343 return TTIImpl->getMaxPrefetchIterationsAhead(); 344 } 345 346 unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const { 347 return TTIImpl->getMaxInterleaveFactor(VF); 348 } 349 350 int TargetTransformInfo::getArithmeticInstrCost( 351 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, 352 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, 353 OperandValueProperties Opd2PropInfo, 354 ArrayRef<const Value *> Args) const { 355 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 356 Opd1PropInfo, Opd2PropInfo, Args); 357 assert(Cost >= 0 && "TTI should not produce negative costs!"); 358 return Cost; 359 } 360 361 int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index, 362 Type *SubTp) const { 363 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp); 364 assert(Cost >= 0 && "TTI should not produce negative costs!"); 365 return Cost; 366 } 367 368 int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, 369 Type *Src, const Instruction *I) const { 370 assert ((I == nullptr || I->getOpcode() == Opcode) && 371 "Opcode should reflect passed instruction."); 372 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I); 373 assert(Cost >= 0 && "TTI should not produce negative costs!"); 374 return Cost; 375 } 376 377 int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst, 378 VectorType *VecTy, 379 unsigned Index) const { 380 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index); 381 assert(Cost >= 0 && "TTI should not produce negative costs!"); 382 return Cost; 383 } 384 385 int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { 386 int Cost = TTIImpl->getCFInstrCost(Opcode); 387 assert(Cost >= 0 && "TTI should not produce negative costs!"); 388 return Cost; 389 } 390 391 int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 392 Type *CondTy, const Instruction *I) const { 393 assert ((I == nullptr || I->getOpcode() == Opcode) && 394 "Opcode should reflect passed instruction."); 395 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I); 396 assert(Cost >= 0 && "TTI should not produce negative costs!"); 397 return Cost; 398 } 399 400 int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, 401 unsigned Index) const { 402 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index); 403 assert(Cost >= 0 && "TTI should not produce negative costs!"); 404 return Cost; 405 } 406 407 int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, 408 unsigned Alignment, 409 unsigned AddressSpace, 410 const Instruction *I) const { 411 assert ((I == nullptr || I->getOpcode() == Opcode) && 412 "Opcode should reflect passed instruction."); 413 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I); 414 assert(Cost >= 0 && "TTI should not produce negative costs!"); 415 return Cost; 416 } 417 418 int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src, 419 unsigned Alignment, 420 unsigned AddressSpace) const { 421 int Cost = 422 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace); 423 assert(Cost >= 0 && "TTI should not produce negative costs!"); 424 return Cost; 425 } 426 427 int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy, 428 Value *Ptr, bool VariableMask, 429 unsigned Alignment) const { 430 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, 431 Alignment); 432 assert(Cost >= 0 && "TTI should not produce negative costs!"); 433 return Cost; 434 } 435 436 int TargetTransformInfo::getInterleavedMemoryOpCost( 437 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices, 438 unsigned Alignment, unsigned AddressSpace) const { 439 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, 440 Alignment, AddressSpace); 441 assert(Cost >= 0 && "TTI should not produce negative costs!"); 442 return Cost; 443 } 444 445 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, 446 ArrayRef<Type *> Tys, FastMathFlags FMF, 447 unsigned ScalarizationCostPassed) const { 448 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF, 449 ScalarizationCostPassed); 450 assert(Cost >= 0 && "TTI should not produce negative costs!"); 451 return Cost; 452 } 453 454 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, 455 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const { 456 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF); 457 assert(Cost >= 0 && "TTI should not produce negative costs!"); 458 return Cost; 459 } 460 461 int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy, 462 ArrayRef<Type *> Tys) const { 463 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys); 464 assert(Cost >= 0 && "TTI should not produce negative costs!"); 465 return Cost; 466 } 467 468 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { 469 return TTIImpl->getNumberOfParts(Tp); 470 } 471 472 int TargetTransformInfo::getAddressComputationCost(Type *Tp, 473 ScalarEvolution *SE, 474 const SCEV *Ptr) const { 475 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr); 476 assert(Cost >= 0 && "TTI should not produce negative costs!"); 477 return Cost; 478 } 479 480 int TargetTransformInfo::getArithmeticReductionCost(unsigned Opcode, Type *Ty, 481 bool IsPairwiseForm) const { 482 int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm); 483 assert(Cost >= 0 && "TTI should not produce negative costs!"); 484 return Cost; 485 } 486 487 unsigned 488 TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const { 489 return TTIImpl->getCostOfKeepingLiveOverCall(Tys); 490 } 491 492 bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst, 493 MemIntrinsicInfo &Info) const { 494 return TTIImpl->getTgtMemIntrinsic(Inst, Info); 495 } 496 497 unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const { 498 return TTIImpl->getAtomicMemIntrinsicMaxElementSize(); 499 } 500 501 Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic( 502 IntrinsicInst *Inst, Type *ExpectedType) const { 503 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType); 504 } 505 506 Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context, 507 Value *Length, 508 unsigned SrcAlign, 509 unsigned DestAlign) const { 510 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign, 511 DestAlign); 512 } 513 514 void TargetTransformInfo::getMemcpyLoopResidualLoweringType( 515 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context, 516 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const { 517 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes, 518 SrcAlign, DestAlign); 519 } 520 521 bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const { 522 return UseWideMemcpyLoopLowering; 523 } 524 525 bool TargetTransformInfo::areInlineCompatible(const Function *Caller, 526 const Function *Callee) const { 527 return TTIImpl->areInlineCompatible(Caller, Callee); 528 } 529 530 unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const { 531 return TTIImpl->getLoadStoreVecRegBitWidth(AS); 532 } 533 534 bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const { 535 return TTIImpl->isLegalToVectorizeLoad(LI); 536 } 537 538 bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const { 539 return TTIImpl->isLegalToVectorizeStore(SI); 540 } 541 542 bool TargetTransformInfo::isLegalToVectorizeLoadChain( 543 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { 544 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment, 545 AddrSpace); 546 } 547 548 bool TargetTransformInfo::isLegalToVectorizeStoreChain( 549 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { 550 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment, 551 AddrSpace); 552 } 553 554 unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF, 555 unsigned LoadSize, 556 unsigned ChainSizeInBytes, 557 VectorType *VecTy) const { 558 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy); 559 } 560 561 unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF, 562 unsigned StoreSize, 563 unsigned ChainSizeInBytes, 564 VectorType *VecTy) const { 565 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy); 566 } 567 568 bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode, 569 Type *Ty, ReductionFlags Flags) const { 570 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags); 571 } 572 573 bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const { 574 return TTIImpl->shouldExpandReduction(II); 575 } 576 577 TargetTransformInfo::Concept::~Concept() {} 578 579 TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} 580 581 TargetIRAnalysis::TargetIRAnalysis( 582 std::function<Result(const Function &)> TTICallback) 583 : TTICallback(std::move(TTICallback)) {} 584 585 TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F, 586 FunctionAnalysisManager &) { 587 return TTICallback(F); 588 } 589 590 AnalysisKey TargetIRAnalysis::Key; 591 592 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) { 593 return Result(F.getParent()->getDataLayout()); 594 } 595 596 // Register the basic pass. 597 INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti", 598 "Target Transform Information", false, true) 599 char TargetTransformInfoWrapperPass::ID = 0; 600 601 void TargetTransformInfoWrapperPass::anchor() {} 602 603 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass() 604 : ImmutablePass(ID) { 605 initializeTargetTransformInfoWrapperPassPass( 606 *PassRegistry::getPassRegistry()); 607 } 608 609 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass( 610 TargetIRAnalysis TIRA) 611 : ImmutablePass(ID), TIRA(std::move(TIRA)) { 612 initializeTargetTransformInfoWrapperPassPass( 613 *PassRegistry::getPassRegistry()); 614 } 615 616 TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) { 617 FunctionAnalysisManager DummyFAM; 618 TTI = TIRA.run(F, DummyFAM); 619 return *TTI; 620 } 621 622 ImmutablePass * 623 llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) { 624 return new TargetTransformInfoWrapperPass(std::move(TIRA)); 625 } 626