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::isFoldableMemAccessOffset(Instruction *I, 193 int64_t Offset) const { 194 return TTIImpl->isFoldableMemAccessOffset(I, Offset); 195 } 196 197 bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { 198 return TTIImpl->isTruncateFree(Ty1, Ty2); 199 } 200 201 bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const { 202 return TTIImpl->isProfitableToHoist(I); 203 } 204 205 bool TargetTransformInfo::isTypeLegal(Type *Ty) const { 206 return TTIImpl->isTypeLegal(Ty); 207 } 208 209 unsigned TargetTransformInfo::getJumpBufAlignment() const { 210 return TTIImpl->getJumpBufAlignment(); 211 } 212 213 unsigned TargetTransformInfo::getJumpBufSize() const { 214 return TTIImpl->getJumpBufSize(); 215 } 216 217 bool TargetTransformInfo::shouldBuildLookupTables() const { 218 return TTIImpl->shouldBuildLookupTables(); 219 } 220 bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const { 221 return TTIImpl->shouldBuildLookupTablesForConstant(C); 222 } 223 224 unsigned TargetTransformInfo:: 225 getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const { 226 return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract); 227 } 228 229 unsigned TargetTransformInfo:: 230 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args, 231 unsigned VF) const { 232 return TTIImpl->getOperandsScalarizationOverhead(Args, VF); 233 } 234 235 bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const { 236 return TTIImpl->supportsEfficientVectorElementLoadStore(); 237 } 238 239 bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const { 240 return TTIImpl->enableAggressiveInterleaving(LoopHasReductions); 241 } 242 243 bool TargetTransformInfo::expandMemCmp(Instruction *I, unsigned &MaxLoadSize) const { 244 return TTIImpl->expandMemCmp(I, MaxLoadSize); 245 } 246 247 bool TargetTransformInfo::enableInterleavedAccessVectorization() const { 248 return TTIImpl->enableInterleavedAccessVectorization(); 249 } 250 251 bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const { 252 return TTIImpl->isFPVectorizationPotentiallyUnsafe(); 253 } 254 255 bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context, 256 unsigned BitWidth, 257 unsigned AddressSpace, 258 unsigned Alignment, 259 bool *Fast) const { 260 return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace, 261 Alignment, Fast); 262 } 263 264 TargetTransformInfo::PopcntSupportKind 265 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const { 266 return TTIImpl->getPopcntSupport(IntTyWidthInBit); 267 } 268 269 bool TargetTransformInfo::haveFastSqrt(Type *Ty) const { 270 return TTIImpl->haveFastSqrt(Ty); 271 } 272 273 int TargetTransformInfo::getFPOpCost(Type *Ty) const { 274 int Cost = TTIImpl->getFPOpCost(Ty); 275 assert(Cost >= 0 && "TTI should not produce negative costs!"); 276 return Cost; 277 } 278 279 int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, 280 const APInt &Imm, 281 Type *Ty) const { 282 int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty); 283 assert(Cost >= 0 && "TTI should not produce negative costs!"); 284 return Cost; 285 } 286 287 int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { 288 int Cost = TTIImpl->getIntImmCost(Imm, Ty); 289 assert(Cost >= 0 && "TTI should not produce negative costs!"); 290 return Cost; 291 } 292 293 int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx, 294 const APInt &Imm, Type *Ty) const { 295 int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty); 296 assert(Cost >= 0 && "TTI should not produce negative costs!"); 297 return Cost; 298 } 299 300 int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx, 301 const APInt &Imm, Type *Ty) const { 302 int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty); 303 assert(Cost >= 0 && "TTI should not produce negative costs!"); 304 return Cost; 305 } 306 307 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { 308 return TTIImpl->getNumberOfRegisters(Vector); 309 } 310 311 unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const { 312 return TTIImpl->getRegisterBitWidth(Vector); 313 } 314 315 unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const { 316 return TTIImpl->getMinVectorRegisterBitWidth(); 317 } 318 319 bool TargetTransformInfo::shouldConsiderAddressTypePromotion( 320 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const { 321 return TTIImpl->shouldConsiderAddressTypePromotion( 322 I, AllowPromotionWithoutCommonHeader); 323 } 324 325 unsigned TargetTransformInfo::getCacheLineSize() const { 326 return TTIImpl->getCacheLineSize(); 327 } 328 329 unsigned TargetTransformInfo::getPrefetchDistance() const { 330 return TTIImpl->getPrefetchDistance(); 331 } 332 333 unsigned TargetTransformInfo::getMinPrefetchStride() const { 334 return TTIImpl->getMinPrefetchStride(); 335 } 336 337 unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const { 338 return TTIImpl->getMaxPrefetchIterationsAhead(); 339 } 340 341 unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const { 342 return TTIImpl->getMaxInterleaveFactor(VF); 343 } 344 345 int TargetTransformInfo::getArithmeticInstrCost( 346 unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, 347 OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, 348 OperandValueProperties Opd2PropInfo, 349 ArrayRef<const Value *> Args) const { 350 int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 351 Opd1PropInfo, Opd2PropInfo, Args); 352 assert(Cost >= 0 && "TTI should not produce negative costs!"); 353 return Cost; 354 } 355 356 int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index, 357 Type *SubTp) const { 358 int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp); 359 assert(Cost >= 0 && "TTI should not produce negative costs!"); 360 return Cost; 361 } 362 363 int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, 364 Type *Src, const Instruction *I) const { 365 assert ((I == nullptr || I->getOpcode() == Opcode) && 366 "Opcode should reflect passed instruction."); 367 int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I); 368 assert(Cost >= 0 && "TTI should not produce negative costs!"); 369 return Cost; 370 } 371 372 int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst, 373 VectorType *VecTy, 374 unsigned Index) const { 375 int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index); 376 assert(Cost >= 0 && "TTI should not produce negative costs!"); 377 return Cost; 378 } 379 380 int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { 381 int Cost = TTIImpl->getCFInstrCost(Opcode); 382 assert(Cost >= 0 && "TTI should not produce negative costs!"); 383 return Cost; 384 } 385 386 int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 387 Type *CondTy, const Instruction *I) const { 388 assert ((I == nullptr || I->getOpcode() == Opcode) && 389 "Opcode should reflect passed instruction."); 390 int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I); 391 assert(Cost >= 0 && "TTI should not produce negative costs!"); 392 return Cost; 393 } 394 395 int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, 396 unsigned Index) const { 397 int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index); 398 assert(Cost >= 0 && "TTI should not produce negative costs!"); 399 return Cost; 400 } 401 402 int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, 403 unsigned Alignment, 404 unsigned AddressSpace, 405 const Instruction *I) const { 406 assert ((I == nullptr || I->getOpcode() == Opcode) && 407 "Opcode should reflect passed instruction."); 408 int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I); 409 assert(Cost >= 0 && "TTI should not produce negative costs!"); 410 return Cost; 411 } 412 413 int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src, 414 unsigned Alignment, 415 unsigned AddressSpace) const { 416 int Cost = 417 TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace); 418 assert(Cost >= 0 && "TTI should not produce negative costs!"); 419 return Cost; 420 } 421 422 int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy, 423 Value *Ptr, bool VariableMask, 424 unsigned Alignment) const { 425 int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, 426 Alignment); 427 assert(Cost >= 0 && "TTI should not produce negative costs!"); 428 return Cost; 429 } 430 431 int TargetTransformInfo::getInterleavedMemoryOpCost( 432 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices, 433 unsigned Alignment, unsigned AddressSpace) const { 434 int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, 435 Alignment, AddressSpace); 436 assert(Cost >= 0 && "TTI should not produce negative costs!"); 437 return Cost; 438 } 439 440 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, 441 ArrayRef<Type *> Tys, FastMathFlags FMF, 442 unsigned ScalarizationCostPassed) const { 443 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF, 444 ScalarizationCostPassed); 445 assert(Cost >= 0 && "TTI should not produce negative costs!"); 446 return Cost; 447 } 448 449 int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, 450 ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const { 451 int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF); 452 assert(Cost >= 0 && "TTI should not produce negative costs!"); 453 return Cost; 454 } 455 456 int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy, 457 ArrayRef<Type *> Tys) const { 458 int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys); 459 assert(Cost >= 0 && "TTI should not produce negative costs!"); 460 return Cost; 461 } 462 463 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { 464 return TTIImpl->getNumberOfParts(Tp); 465 } 466 467 int TargetTransformInfo::getAddressComputationCost(Type *Tp, 468 ScalarEvolution *SE, 469 const SCEV *Ptr) const { 470 int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr); 471 assert(Cost >= 0 && "TTI should not produce negative costs!"); 472 return Cost; 473 } 474 475 int TargetTransformInfo::getReductionCost(unsigned Opcode, Type *Ty, 476 bool IsPairwiseForm) const { 477 int Cost = TTIImpl->getReductionCost(Opcode, Ty, IsPairwiseForm); 478 assert(Cost >= 0 && "TTI should not produce negative costs!"); 479 return Cost; 480 } 481 482 unsigned 483 TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const { 484 return TTIImpl->getCostOfKeepingLiveOverCall(Tys); 485 } 486 487 bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst, 488 MemIntrinsicInfo &Info) const { 489 return TTIImpl->getTgtMemIntrinsic(Inst, Info); 490 } 491 492 unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const { 493 return TTIImpl->getAtomicMemIntrinsicMaxElementSize(); 494 } 495 496 Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic( 497 IntrinsicInst *Inst, Type *ExpectedType) const { 498 return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType); 499 } 500 501 Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context, 502 Value *Length, 503 unsigned SrcAlign, 504 unsigned DestAlign) const { 505 return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign, 506 DestAlign); 507 } 508 509 void TargetTransformInfo::getMemcpyLoopResidualLoweringType( 510 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context, 511 unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const { 512 TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes, 513 SrcAlign, DestAlign); 514 } 515 516 bool TargetTransformInfo::useWideIRMemcpyLoopLowering() const { 517 return UseWideMemcpyLoopLowering; 518 } 519 520 bool TargetTransformInfo::areInlineCompatible(const Function *Caller, 521 const Function *Callee) const { 522 return TTIImpl->areInlineCompatible(Caller, Callee); 523 } 524 525 unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const { 526 return TTIImpl->getLoadStoreVecRegBitWidth(AS); 527 } 528 529 bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const { 530 return TTIImpl->isLegalToVectorizeLoad(LI); 531 } 532 533 bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const { 534 return TTIImpl->isLegalToVectorizeStore(SI); 535 } 536 537 bool TargetTransformInfo::isLegalToVectorizeLoadChain( 538 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { 539 return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment, 540 AddrSpace); 541 } 542 543 bool TargetTransformInfo::isLegalToVectorizeStoreChain( 544 unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { 545 return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment, 546 AddrSpace); 547 } 548 549 unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF, 550 unsigned LoadSize, 551 unsigned ChainSizeInBytes, 552 VectorType *VecTy) const { 553 return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy); 554 } 555 556 unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF, 557 unsigned StoreSize, 558 unsigned ChainSizeInBytes, 559 VectorType *VecTy) const { 560 return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy); 561 } 562 563 bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode, 564 Type *Ty, ReductionFlags Flags) const { 565 return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags); 566 } 567 568 bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const { 569 return TTIImpl->shouldExpandReduction(II); 570 } 571 572 TargetTransformInfo::Concept::~Concept() {} 573 574 TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} 575 576 TargetIRAnalysis::TargetIRAnalysis( 577 std::function<Result(const Function &)> TTICallback) 578 : TTICallback(std::move(TTICallback)) {} 579 580 TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F, 581 FunctionAnalysisManager &) { 582 return TTICallback(F); 583 } 584 585 AnalysisKey TargetIRAnalysis::Key; 586 587 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) { 588 return Result(F.getParent()->getDataLayout()); 589 } 590 591 // Register the basic pass. 592 INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti", 593 "Target Transform Information", false, true) 594 char TargetTransformInfoWrapperPass::ID = 0; 595 596 void TargetTransformInfoWrapperPass::anchor() {} 597 598 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass() 599 : ImmutablePass(ID) { 600 initializeTargetTransformInfoWrapperPassPass( 601 *PassRegistry::getPassRegistry()); 602 } 603 604 TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass( 605 TargetIRAnalysis TIRA) 606 : ImmutablePass(ID), TIRA(std::move(TIRA)) { 607 initializeTargetTransformInfoWrapperPassPass( 608 *PassRegistry::getPassRegistry()); 609 } 610 611 TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) { 612 FunctionAnalysisManager DummyFAM; 613 TTI = TIRA.run(F, DummyFAM); 614 return *TTI; 615 } 616 617 ImmutablePass * 618 llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) { 619 return new TargetTransformInfoWrapperPass(std::move(TIRA)); 620 } 621