File indexing completed on 2026-05-10 08:43:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
0022 #define LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
0023
0024 #include "llvm/ADT/APInt.h"
0025 #include "llvm/ADT/ArrayRef.h"
0026 #include "llvm/IR/FMF.h"
0027 #include "llvm/IR/InstrTypes.h"
0028 #include "llvm/IR/PassManager.h"
0029 #include "llvm/Pass.h"
0030 #include "llvm/Support/AtomicOrdering.h"
0031 #include "llvm/Support/BranchProbability.h"
0032 #include "llvm/Support/InstructionCost.h"
0033 #include <functional>
0034 #include <optional>
0035 #include <utility>
0036
0037 namespace llvm {
0038
0039 namespace Intrinsic {
0040 typedef unsigned ID;
0041 }
0042
0043 class AllocaInst;
0044 class AssumptionCache;
0045 class BlockFrequencyInfo;
0046 class DominatorTree;
0047 class BranchInst;
0048 class Function;
0049 class GlobalValue;
0050 class InstCombiner;
0051 class OptimizationRemarkEmitter;
0052 class InterleavedAccessInfo;
0053 class IntrinsicInst;
0054 class LoadInst;
0055 class Loop;
0056 class LoopInfo;
0057 class LoopVectorizationLegality;
0058 class ProfileSummaryInfo;
0059 class RecurrenceDescriptor;
0060 class SCEV;
0061 class ScalarEvolution;
0062 class SmallBitVector;
0063 class StoreInst;
0064 class SwitchInst;
0065 class TargetLibraryInfo;
0066 class Type;
0067 class VPIntrinsic;
0068 struct KnownBits;
0069
0070
0071 struct MemIntrinsicInfo {
0072
0073
0074
0075
0076 Value *PtrVal = nullptr;
0077
0078
0079 AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
0080
0081
0082 unsigned short MatchingId = 0;
0083
0084 bool ReadMem = false;
0085 bool WriteMem = false;
0086 bool IsVolatile = false;
0087
0088 bool isUnordered() const {
0089 return (Ordering == AtomicOrdering::NotAtomic ||
0090 Ordering == AtomicOrdering::Unordered) &&
0091 !IsVolatile;
0092 }
0093 };
0094
0095
0096 struct HardwareLoopInfo {
0097 HardwareLoopInfo() = delete;
0098 HardwareLoopInfo(Loop *L);
0099 Loop *L = nullptr;
0100 BasicBlock *ExitBlock = nullptr;
0101 BranchInst *ExitBranch = nullptr;
0102 const SCEV *ExitCount = nullptr;
0103 IntegerType *CountType = nullptr;
0104 Value *LoopDecrement = nullptr;
0105
0106 bool IsNestingLegal = false;
0107
0108 bool CounterInReg = false;
0109
0110 bool PerformEntryTest = false;
0111
0112
0113 bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI,
0114 DominatorTree &DT, bool ForceNestedLoop = false,
0115 bool ForceHardwareLoopPHI = false);
0116 bool canAnalyze(LoopInfo &LI);
0117 };
0118
0119 class IntrinsicCostAttributes {
0120 const IntrinsicInst *II = nullptr;
0121 Type *RetTy = nullptr;
0122 Intrinsic::ID IID;
0123 SmallVector<Type *, 4> ParamTys;
0124 SmallVector<const Value *, 4> Arguments;
0125 FastMathFlags FMF;
0126
0127
0128 InstructionCost ScalarizationCost = InstructionCost::getInvalid();
0129
0130 public:
0131 IntrinsicCostAttributes(
0132 Intrinsic::ID Id, const CallBase &CI,
0133 InstructionCost ScalarCost = InstructionCost::getInvalid(),
0134 bool TypeBasedOnly = false);
0135
0136 IntrinsicCostAttributes(
0137 Intrinsic::ID Id, Type *RTy, ArrayRef<Type *> Tys,
0138 FastMathFlags Flags = FastMathFlags(), const IntrinsicInst *I = nullptr,
0139 InstructionCost ScalarCost = InstructionCost::getInvalid());
0140
0141 IntrinsicCostAttributes(Intrinsic::ID Id, Type *RTy,
0142 ArrayRef<const Value *> Args);
0143
0144 IntrinsicCostAttributes(
0145 Intrinsic::ID Id, Type *RTy, ArrayRef<const Value *> Args,
0146 ArrayRef<Type *> Tys, FastMathFlags Flags = FastMathFlags(),
0147 const IntrinsicInst *I = nullptr,
0148 InstructionCost ScalarCost = InstructionCost::getInvalid());
0149
0150 Intrinsic::ID getID() const { return IID; }
0151 const IntrinsicInst *getInst() const { return II; }
0152 Type *getReturnType() const { return RetTy; }
0153 FastMathFlags getFlags() const { return FMF; }
0154 InstructionCost getScalarizationCost() const { return ScalarizationCost; }
0155 const SmallVectorImpl<const Value *> &getArgs() const { return Arguments; }
0156 const SmallVectorImpl<Type *> &getArgTypes() const { return ParamTys; }
0157
0158 bool isTypeBasedOnly() const {
0159 return Arguments.empty();
0160 }
0161
0162 bool skipScalarizationCost() const { return ScalarizationCost.isValid(); }
0163 };
0164
0165 enum class TailFoldingStyle {
0166
0167 None,
0168
0169
0170
0171
0172
0173
0174
0175
0176 Data,
0177
0178
0179
0180
0181
0182 DataWithoutLaneMask,
0183
0184
0185
0186
0187
0188 DataAndControlFlow,
0189
0190
0191
0192 DataAndControlFlowWithoutRuntimeCheck,
0193
0194
0195 DataWithEVL,
0196 };
0197
0198 struct TailFoldingInfo {
0199 TargetLibraryInfo *TLI;
0200 LoopVectorizationLegality *LVL;
0201 InterleavedAccessInfo *IAI;
0202 TailFoldingInfo(TargetLibraryInfo *TLI, LoopVectorizationLegality *LVL,
0203 InterleavedAccessInfo *IAI)
0204 : TLI(TLI), LVL(LVL), IAI(IAI) {}
0205 };
0206
0207 class TargetTransformInfo;
0208 typedef TargetTransformInfo TTI;
0209
0210
0211
0212 class TargetTransformInfo {
0213 public:
0214 enum PartialReductionExtendKind { PR_None, PR_SignExtend, PR_ZeroExtend };
0215
0216
0217 static PartialReductionExtendKind
0218 getPartialReductionExtendKind(Instruction *I);
0219
0220
0221
0222
0223
0224
0225 template <typename T> TargetTransformInfo(T Impl);
0226
0227
0228
0229
0230
0231
0232 explicit TargetTransformInfo(const DataLayout &DL);
0233
0234
0235 TargetTransformInfo(TargetTransformInfo &&Arg);
0236 TargetTransformInfo &operator=(TargetTransformInfo &&RHS);
0237
0238
0239
0240 ~TargetTransformInfo();
0241
0242
0243
0244
0245
0246
0247 bool invalidate(Function &, const PreservedAnalyses &,
0248 FunctionAnalysisManager::Invalidator &) {
0249
0250
0251 return false;
0252 }
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 enum TargetCostKind {
0264 TCK_RecipThroughput,
0265 TCK_Latency,
0266 TCK_CodeSize,
0267 TCK_SizeAndLatency
0268 };
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288 enum TargetCostConstants {
0289 TCC_Free = 0,
0290 TCC_Basic = 1,
0291 TCC_Expensive = 4
0292 };
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 InstructionCost
0306 getGEPCost(Type *PointeeType, const Value *Ptr,
0307 ArrayRef<const Value *> Operands, Type *AccessType = nullptr,
0308 TargetCostKind CostKind = TCK_SizeAndLatency) const;
0309
0310
0311 struct PointersChainInfo {
0312
0313 unsigned IsSameBaseAddress : 1;
0314
0315
0316 unsigned IsUnitStride : 1;
0317
0318 unsigned IsKnownStride : 1;
0319 unsigned Reserved : 29;
0320
0321 bool isSameBase() const { return IsSameBaseAddress; }
0322 bool isUnitStride() const { return IsSameBaseAddress && IsUnitStride; }
0323 bool isKnownStride() const { return IsSameBaseAddress && IsKnownStride; }
0324
0325 static PointersChainInfo getUnitStride() {
0326 return {1, 1,
0327 1, 0};
0328 }
0329 static PointersChainInfo getKnownStride() {
0330 return {1, 0,
0331 1, 0};
0332 }
0333 static PointersChainInfo getUnknownStride() {
0334 return {1, 0,
0335 0, 0};
0336 }
0337 };
0338 static_assert(sizeof(PointersChainInfo) == 4, "Was size increase justified?");
0339
0340
0341
0342
0343
0344 InstructionCost getPointersChainCost(
0345 ArrayRef<const Value *> Ptrs, const Value *Base,
0346 const PointersChainInfo &Info, Type *AccessTy,
0347 TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
0348
0349
0350
0351
0352
0353
0354
0355 unsigned getInliningThresholdMultiplier() const;
0356
0357 unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const;
0358 unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const;
0359
0360
0361 int getInliningLastCallToStaticBonus() const;
0362
0363
0364 unsigned adjustInliningThreshold(const CallBase *CB) const;
0365
0366
0367
0368 unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const;
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380 int getInlinerVectorBonusPercent() const;
0381
0382
0383
0384 InstructionCost getMemcpyCost(const Instruction *I) const;
0385
0386
0387
0388 uint64_t getMaxMemIntrinsicInlineSizeThreshold() const;
0389
0390
0391
0392
0393 unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
0394 unsigned &JTSize,
0395 ProfileSummaryInfo *PSI,
0396 BlockFrequencyInfo *BFI) const;
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411 InstructionCost getInstructionCost(const User *U,
0412 ArrayRef<const Value *> Operands,
0413 TargetCostKind CostKind) const;
0414
0415
0416
0417 InstructionCost getInstructionCost(const User *U,
0418 TargetCostKind CostKind) const {
0419 SmallVector<const Value *, 4> Operands(U->operand_values());
0420 return getInstructionCost(U, Operands, CostKind);
0421 }
0422
0423
0424
0425 BranchProbability getPredictableBranchThreshold() const;
0426
0427
0428
0429
0430
0431 InstructionCost getBranchMispredictPenalty() const;
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442 bool hasBranchDivergence(const Function *F = nullptr) const;
0443
0444
0445
0446
0447
0448 bool isSourceOfDivergence(const Value *V) const;
0449
0450
0451
0452
0453 bool isAlwaysUniform(const Value *V) const;
0454
0455
0456
0457 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
0458
0459
0460 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478 unsigned getFlatAddressSpace() const;
0479
0480
0481
0482
0483
0484 bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
0485 Intrinsic::ID IID) const;
0486
0487 bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
0488
0489
0490
0491 bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const;
0492
0493 unsigned getAssumedAddrSpace(const Value *V) const;
0494
0495 bool isSingleThreaded() const;
0496
0497 std::pair<const Value *, unsigned>
0498 getPredicatedAddrSpace(const Value *V) const;
0499
0500
0501
0502
0503
0504
0505 Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV,
0506 Value *NewV) const;
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520 bool isLoweredToCall(const Function *F) const;
0521
0522 struct LSRCost {
0523
0524
0525 unsigned Insns;
0526 unsigned NumRegs;
0527 unsigned AddRecCost;
0528 unsigned NumIVMuls;
0529 unsigned NumBaseAdds;
0530 unsigned ImmCost;
0531 unsigned SetupCost;
0532 unsigned ScaleCost;
0533 };
0534
0535
0536 struct UnrollingPreferences {
0537
0538
0539
0540
0541
0542
0543
0544 unsigned Threshold;
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555 unsigned MaxPercentThresholdBoost;
0556
0557
0558 unsigned OptSizeThreshold;
0559
0560
0561 unsigned PartialThreshold;
0562
0563
0564
0565 unsigned PartialOptSizeThreshold;
0566
0567
0568
0569
0570 unsigned Count;
0571
0572 unsigned DefaultUnrollRuntimeCount;
0573
0574
0575
0576
0577 unsigned MaxCount;
0578
0579
0580
0581 unsigned MaxUpperBound;
0582
0583
0584
0585 unsigned FullUnrollMaxCount;
0586
0587
0588
0589
0590 unsigned BEInsns;
0591
0592
0593 bool Partial;
0594
0595
0596
0597 bool Runtime;
0598
0599 bool AllowRemainder;
0600
0601
0602 bool AllowExpensiveTripCount;
0603
0604
0605 bool Force;
0606
0607 bool UpperBound;
0608
0609 bool UnrollRemainder;
0610
0611 bool UnrollAndJam;
0612
0613
0614
0615
0616 unsigned UnrollAndJamInnerLoopThreshold;
0617
0618
0619 unsigned MaxIterationsCountToAnalyze;
0620
0621 bool UnrollVectorizedLoop = false;
0622
0623
0624 unsigned SCEVExpansionBudget;
0625
0626
0627
0628
0629 bool RuntimeUnrollMultiExit;
0630 };
0631
0632
0633
0634
0635 void getUnrollingPreferences(Loop *L, ScalarEvolution &,
0636 UnrollingPreferences &UP,
0637 OptimizationRemarkEmitter *ORE) const;
0638
0639
0640
0641 bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
0642 AssumptionCache &AC, TargetLibraryInfo *LibInfo,
0643 HardwareLoopInfo &HWLoopInfo) const;
0644
0645
0646
0647 unsigned getEpilogueVectorizationMinVF() const;
0648
0649
0650
0651 bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const;
0652
0653
0654
0655
0656
0657
0658
0659 TailFoldingStyle
0660 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const;
0661
0662
0663 struct PeelingPreferences {
0664
0665
0666
0667 unsigned PeelCount;
0668
0669 bool AllowPeeling;
0670
0671 bool AllowLoopNestsPeeling;
0672
0673
0674
0675
0676 bool PeelProfiledIterations;
0677 };
0678
0679
0680
0681
0682 void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
0683 PeelingPreferences &PP) const;
0684
0685
0686
0687
0688
0689
0690
0691
0692 std::optional<Instruction *> instCombineIntrinsic(InstCombiner & IC,
0693 IntrinsicInst & II) const;
0694
0695
0696 std::optional<Value *> simplifyDemandedUseBitsIntrinsic(
0697 InstCombiner & IC, IntrinsicInst & II, APInt DemandedMask,
0698 KnownBits & Known, bool &KnownBitsComputed) const;
0699
0700
0701 std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
0702 InstCombiner & IC, IntrinsicInst & II, APInt DemandedElts,
0703 APInt & UndefElts, APInt & UndefElts2, APInt & UndefElts3,
0704 std::function<void(Instruction *, unsigned, APInt, APInt &)>
0705 SimplifyAndSetOp) const;
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719 enum PopcntSupportKind { PSK_Software, PSK_SlowHardware, PSK_FastHardware };
0720
0721
0722
0723
0724 bool isLegalAddImmediate(int64_t Imm) const;
0725
0726
0727
0728
0729
0730 bool isLegalAddScalableImmediate(int64_t Imm) const;
0731
0732
0733
0734
0735
0736 bool isLegalICmpImmediate(int64_t Imm) const;
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
0749 bool HasBaseReg, int64_t Scale,
0750 unsigned AddrSpace = 0, Instruction *I = nullptr,
0751 int64_t ScalableOffset = 0) const;
0752
0753
0754 bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
0755 const TargetTransformInfo::LSRCost &C2) const;
0756
0757
0758
0759
0760 bool isNumRegsMajorCostOfLSR() const;
0761
0762
0763
0764 bool shouldDropLSRSolutionIfLessProfitable() const;
0765
0766
0767 bool isProfitableLSRChainElement(Instruction *I) const;
0768
0769
0770
0771
0772 bool canMacroFuseCmp() const;
0773
0774
0775
0776 bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
0777 DominatorTree *DT, AssumptionCache *AC,
0778 TargetLibraryInfo *LibInfo) const;
0779
0780 enum AddressingModeKind {
0781 AMK_PreIndexed,
0782 AMK_PostIndexed,
0783 AMK_None
0784 };
0785
0786
0787 AddressingModeKind getPreferredAddressingMode(const Loop *L,
0788 ScalarEvolution *SE) const;
0789
0790
0791 bool isLegalMaskedStore(Type *DataType, Align Alignment) const;
0792
0793 bool isLegalMaskedLoad(Type *DataType, Align Alignment) const;
0794
0795
0796 bool isLegalNTStore(Type *DataType, Align Alignment) const;
0797
0798 bool isLegalNTLoad(Type *DataType, Align Alignment) const;
0799
0800
0801
0802 bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const;
0803
0804
0805 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const;
0806
0807 bool isLegalMaskedGather(Type *DataType, Align Alignment) const;
0808
0809
0810 bool forceScalarizeMaskedGather(VectorType *Type, Align Alignment) const;
0811
0812
0813 bool forceScalarizeMaskedScatter(VectorType *Type, Align Alignment) const;
0814
0815
0816 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const;
0817
0818 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const;
0819
0820
0821 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const;
0822
0823
0824
0825
0826 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
0827 Align Alignment, unsigned AddrSpace) const;
0828
0829
0830 bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const;
0831
0832
0833
0834
0835
0836
0837
0838
0839 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
0840 const SmallBitVector &OpcodeMask) const;
0841
0842
0843 bool enableOrderedReductions() const;
0844
0845
0846
0847
0848
0849
0850 bool hasDivRemOp(Type *DataType, bool IsSigned) const;
0851
0852
0853
0854
0855
0856
0857 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const;
0858
0859
0860 bool prefersVectorizedAddressing() const;
0861
0862
0863
0864
0865
0866
0867
0868 InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
0869 StackOffset BaseOffset, bool HasBaseReg,
0870 int64_t Scale,
0871 unsigned AddrSpace = 0) const;
0872
0873
0874
0875
0876
0877 bool LSRWithInstrQueries() const;
0878
0879
0880
0881
0882 bool isTruncateFree(Type *Ty1, Type *Ty2) const;
0883
0884
0885
0886 bool isProfitableToHoist(Instruction *I) const;
0887
0888 bool useAA() const;
0889
0890
0891 bool isTypeLegal(Type *Ty) const;
0892
0893
0894 unsigned getRegUsageForType(Type *Ty) const;
0895
0896
0897
0898 bool shouldBuildLookupTables() const;
0899
0900
0901
0902 bool shouldBuildLookupTablesForConstant(Constant *C) const;
0903
0904
0905 bool shouldBuildRelLookupTables() const;
0906
0907
0908
0909 bool useColdCCForColdCall(Function &F) const;
0910
0911 bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) const;
0912
0913
0914 bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
0915 unsigned ScalarOpdIdx) const;
0916
0917
0918
0919
0920 bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
0921 int OpdIdx) const;
0922
0923
0924
0925 bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID,
0926 int RetIdx) const;
0927
0928
0929
0930
0931
0932 InstructionCost getScalarizationOverhead(VectorType *Ty,
0933 const APInt &DemandedElts,
0934 bool Insert, bool Extract,
0935 TTI::TargetCostKind CostKind,
0936 ArrayRef<Value *> VL = {}) const;
0937
0938
0939
0940
0941 InstructionCost
0942 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
0943 ArrayRef<Type *> Tys,
0944 TTI::TargetCostKind CostKind) const;
0945
0946
0947
0948
0949 bool supportsEfficientVectorElementLoadStore() const;
0950
0951
0952 bool supportsTailCalls() const;
0953
0954
0955 bool supportsTailCallFor(const CallBase *CB) const;
0956
0957
0958 bool enableAggressiveInterleaving(bool LoopHasReductions) const;
0959
0960
0961
0962 struct MemCmpExpansionOptions {
0963
0964 operator bool() const { return MaxNumLoads > 0; }
0965
0966
0967 unsigned MaxNumLoads = 0;
0968
0969
0970 SmallVector<unsigned, 8> LoadSizes;
0971
0972
0973
0974
0975
0976
0977
0978
0979
0980 unsigned NumLoadsPerBlock = 1;
0981
0982
0983
0984
0985 bool AllowOverlappingLoads = false;
0986
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996 SmallVector<unsigned, 4> AllowedTailExpansions;
0997 };
0998 MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
0999 bool IsZeroCmp) const;
1000
1001
1002 bool enableSelectOptimize() const;
1003
1004
1005
1006
1007
1008 bool shouldTreatInstructionLikeSelect(const Instruction *I) const;
1009
1010
1011 bool enableInterleavedAccessVectorization() const;
1012
1013
1014
1015
1016 bool enableMaskedInterleavedAccessVectorization() const;
1017
1018
1019
1020
1021
1022
1023
1024
1025 bool isFPVectorizationPotentiallyUnsafe() const;
1026
1027
1028 bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth,
1029 unsigned AddressSpace = 0,
1030 Align Alignment = Align(1),
1031 unsigned *Fast = nullptr) const;
1032
1033
1034 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
1035
1036
1037 bool haveFastSqrt(Type *Ty) const;
1038
1039
1040
1041
1042
1043
1044
1045 bool isExpensiveToSpeculativelyExecute(const Instruction *I) const;
1046
1047
1048
1049
1050
1051 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const;
1052
1053
1054
1055 InstructionCost getFPOpCost(Type *Ty) const;
1056
1057
1058
1059 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
1060 TargetCostKind CostKind) const;
1061
1062
1063
1064
1065 InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
1066 const APInt &Imm, Type *Ty,
1067 TargetCostKind CostKind,
1068 Instruction *Inst = nullptr) const;
1069 InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
1070 const APInt &Imm, Type *Ty,
1071 TargetCostKind CostKind) const;
1072
1073
1074
1075
1076
1077
1078
1079
1080 InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
1081 const APInt &Imm, Type *Ty) const;
1082
1083
1084
1085
1086
1087
1088
1089 bool preferToKeepConstantsAttached(const Instruction &Inst,
1090 const Function &Fn) const;
1091
1092
1093
1094
1095
1096
1097
1098 enum ShuffleKind {
1099 SK_Broadcast,
1100 SK_Reverse,
1101 SK_Select,
1102
1103
1104 SK_Transpose,
1105 SK_InsertSubvector,
1106 SK_ExtractSubvector,
1107 SK_PermuteTwoSrc,
1108
1109 SK_PermuteSingleSrc,
1110
1111 SK_Splice
1112
1113
1114
1115 };
1116
1117
1118 enum OperandValueKind {
1119 OK_AnyValue,
1120 OK_UniformValue,
1121 OK_UniformConstantValue,
1122 OK_NonUniformConstantValue
1123 };
1124
1125
1126 enum OperandValueProperties {
1127 OP_None = 0,
1128 OP_PowerOf2 = 1,
1129 OP_NegatedPowerOf2 = 2,
1130 };
1131
1132
1133
1134
1135 struct OperandValueInfo {
1136 OperandValueKind Kind = OK_AnyValue;
1137 OperandValueProperties Properties = OP_None;
1138
1139 bool isConstant() const {
1140 return Kind == OK_UniformConstantValue || Kind == OK_NonUniformConstantValue;
1141 }
1142 bool isUniform() const {
1143 return Kind == OK_UniformConstantValue || Kind == OK_UniformValue;
1144 }
1145 bool isPowerOf2() const {
1146 return Properties == OP_PowerOf2;
1147 }
1148 bool isNegatedPowerOf2() const {
1149 return Properties == OP_NegatedPowerOf2;
1150 }
1151
1152 OperandValueInfo getNoProps() const {
1153 return {Kind, OP_None};
1154 }
1155 };
1156
1157
1158 unsigned getNumberOfRegisters(unsigned ClassID) const;
1159
1160
1161
1162 bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const;
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const;
1176
1177
1178 const char *getRegisterClassName(unsigned ClassID) const;
1179
1180 enum RegisterKind { RGK_Scalar, RGK_FixedWidthVector, RGK_ScalableVector };
1181
1182
1183 TypeSize getRegisterBitWidth(RegisterKind K) const;
1184
1185
1186 unsigned getMinVectorRegisterBitWidth() const;
1187
1188
1189
1190 std::optional<unsigned> getMaxVScale() const;
1191
1192
1193 std::optional<unsigned> getVScaleForTuning() const;
1194
1195
1196 bool isVScaleKnownToBeAPowerOfTwo() const;
1197
1198
1199
1200
1201
1202
1203
1204
1205 bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const;
1206
1207
1208
1209
1210
1211 ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const;
1212
1213
1214
1215
1216 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const;
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226 unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
1227 Type *ScalarValTy) const;
1228
1229
1230
1231
1232 bool shouldConsiderAddressTypePromotion(
1233 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const;
1234
1235
1236 unsigned getCacheLineSize() const;
1237
1238
1239 enum class CacheLevel {
1240 L1D,
1241 L2D,
1242
1243
1244
1245
1246 };
1247
1248
1249 std::optional<unsigned> getCacheSize(CacheLevel Level) const;
1250
1251
1252 std::optional<unsigned> getCacheAssociativity(CacheLevel Level) const;
1253
1254
1255 std::optional<unsigned> getMinPageSize() const;
1256
1257
1258
1259
1260 unsigned getPrefetchDistance() const;
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
1280 unsigned NumStridedMemAccesses,
1281 unsigned NumPrefetches, bool HasCall) const;
1282
1283
1284
1285
1286 unsigned getMaxPrefetchIterationsAhead() const;
1287
1288
1289 bool enableWritePrefetching() const;
1290
1291
1292 bool shouldPrefetchAddressSpace(unsigned AS) const;
1293
1294
1295
1296
1297
1298
1299
1300
1301 InstructionCost
1302 getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB,
1303 Type *AccumType, ElementCount VF,
1304 PartialReductionExtendKind OpAExtend,
1305 PartialReductionExtendKind OpBExtend,
1306 std::optional<unsigned> BinOp = std::nullopt) const;
1307
1308
1309
1310
1311 unsigned getMaxInterleaveFactor(ElementCount VF) const;
1312
1313
1314 static OperandValueInfo getOperandInfo(const Value *V);
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334 InstructionCost getArithmeticInstrCost(
1335 unsigned Opcode, Type *Ty,
1336 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1337 TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None},
1338 TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
1339 ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr,
1340 const TargetLibraryInfo *TLibInfo = nullptr) const;
1341
1342
1343
1344
1345
1346
1347
1348
1349 InstructionCost getAltInstrCost(
1350 VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
1351 const SmallBitVector &OpcodeMask,
1352 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362 InstructionCost
1363 getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask = {},
1364 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1365 int Index = 0, VectorType *SubTp = nullptr,
1366 ArrayRef<const Value *> Args = {},
1367 const Instruction *CxtI = nullptr) const;
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389 enum class CastContextHint : uint8_t {
1390 None,
1391 Normal,
1392 Masked,
1393 GatherScatter,
1394 Interleave,
1395 Reversed,
1396 };
1397
1398
1399
1400
1401
1402
1403 static CastContextHint getCastContextHint(const Instruction *I);
1404
1405
1406
1407
1408 InstructionCost
1409 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
1410 TTI::CastContextHint CCH,
1411 TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
1412 const Instruction *I = nullptr) const;
1413
1414
1415
1416 InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1417 VectorType *VecTy,
1418 unsigned Index) const;
1419
1420
1421
1422 InstructionCost
1423 getCFInstrCost(unsigned Opcode,
1424 TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency,
1425 const Instruction *I = nullptr) const;
1426
1427
1428
1429
1430
1431
1432
1433
1434 InstructionCost
1435 getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
1436 CmpInst::Predicate VecPred,
1437 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1438 OperandValueInfo Op1Info = {OK_AnyValue, OP_None},
1439 OperandValueInfo Op2Info = {OK_AnyValue, OP_None},
1440 const Instruction *I = nullptr) const;
1441
1442
1443
1444
1445
1446
1447 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
1448 TTI::TargetCostKind CostKind,
1449 unsigned Index = -1, Value *Op0 = nullptr,
1450 Value *Op1 = nullptr) const;
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461 InstructionCost getVectorInstrCost(
1462 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
1463 Value *Scalar,
1464 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const;
1465
1466
1467
1468
1469
1470
1471
1472 InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
1473 TTI::TargetCostKind CostKind,
1474 unsigned Index = -1) const;
1475
1476
1477
1478
1479
1480
1481 InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor,
1482 int VF,
1483 const APInt &DemandedDstElts,
1484 TTI::TargetCostKind CostKind) const;
1485
1486
1487 InstructionCost
1488 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
1489 unsigned AddressSpace,
1490 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1491 OperandValueInfo OpdInfo = {OK_AnyValue, OP_None},
1492 const Instruction *I = nullptr) const;
1493
1494
1495 InstructionCost
1496 getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
1497 unsigned AddressSpace,
1498 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1499 const Instruction *I = nullptr) const;
1500
1501
1502 InstructionCost getMaskedMemoryOpCost(
1503 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
1504 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515 InstructionCost getGatherScatterOpCost(
1516 unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
1517 Align Alignment, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1518 const Instruction *I = nullptr) const;
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529 InstructionCost getStridedMemoryOpCost(
1530 unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
1531 Align Alignment, TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1532 const Instruction *I = nullptr) const;
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544 InstructionCost getInterleavedMemoryOpCost(
1545 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
1546 Align Alignment, unsigned AddressSpace,
1547 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1548 bool UseMaskForCond = false, bool UseMaskForGaps = false) const;
1549
1550
1551
1552 static bool requiresOrderedReduction(std::optional<FastMathFlags> FMF) {
1553 return FMF && !(*FMF).allowReassoc();
1554 }
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580 InstructionCost getArithmeticReductionCost(
1581 unsigned Opcode, VectorType *Ty, std::optional<FastMathFlags> FMF,
1582 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1583
1584 InstructionCost getMinMaxReductionCost(
1585 Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF = FastMathFlags(),
1586 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1587
1588
1589
1590
1591
1592
1593 InstructionCost getMulAccReductionCost(
1594 bool IsUnsigned, Type *ResTy, VectorType *Ty,
1595 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1596
1597
1598
1599
1600
1601 InstructionCost getExtendedReductionCost(
1602 unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty,
1603 FastMathFlags FMF,
1604 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1605
1606
1607
1608
1609 InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
1610 TTI::TargetCostKind CostKind) const;
1611
1612
1613 InstructionCost getCallInstrCost(
1614 Function *F, Type *RetTy, ArrayRef<Type *> Tys,
1615 TTI::TargetCostKind CostKind = TTI::TCK_SizeAndLatency) const;
1616
1617
1618
1619 unsigned getNumberOfParts(Type *Tp) const;
1620
1621
1622
1623
1624
1625
1626
1627
1628 InstructionCost getAddressComputationCost(Type *Ty,
1629 ScalarEvolution *SE = nullptr,
1630 const SCEV *Ptr = nullptr) const;
1631
1632
1633
1634
1635
1636
1637 InstructionCost getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const;
1638
1639
1640
1641
1642
1643 bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const;
1644
1645
1646
1647 unsigned getAtomicMemIntrinsicMaxElementSize() const;
1648
1649
1650
1651
1652
1653 Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
1654 Type *ExpectedType) const;
1655
1656
1657 Type *getMemcpyLoopLoweringType(
1658 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
1659 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
1660 std::optional<uint32_t> AtomicElementSize = std::nullopt) const;
1661
1662
1663
1664
1665
1666
1667
1668 void getMemcpyLoopResidualLoweringType(
1669 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
1670 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
1671 Align SrcAlign, Align DestAlign,
1672 std::optional<uint32_t> AtomicCpySize = std::nullopt) const;
1673
1674
1675
1676 bool areInlineCompatible(const Function *Caller,
1677 const Function *Callee) const;
1678
1679
1680
1681
1682
1683
1684
1685 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
1686 unsigned DefaultCallPenalty) const;
1687
1688
1689
1690
1691
1692 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
1693 const ArrayRef<Type *> &Types) const;
1694
1695
1696 enum MemIndexedMode {
1697 MIM_Unindexed,
1698 MIM_PreInc,
1699 MIM_PreDec,
1700 MIM_PostInc,
1701 MIM_PostDec
1702 };
1703
1704
1705 bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const;
1706
1707
1708 bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const;
1709
1710
1711
1712 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
1713
1714
1715 bool isLegalToVectorizeLoad(LoadInst *LI) const;
1716
1717
1718 bool isLegalToVectorizeStore(StoreInst *SI) const;
1719
1720
1721 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
1722 unsigned AddrSpace) const;
1723
1724
1725 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
1726 unsigned AddrSpace) const;
1727
1728
1729 bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
1730 ElementCount VF) const;
1731
1732
1733 bool isElementTypeLegalForScalableVector(Type *Ty) const;
1734
1735
1736
1737 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
1738 unsigned ChainSizeInBytes,
1739 VectorType *VecTy) const;
1740
1741
1742
1743 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
1744 unsigned ChainSizeInBytes,
1745 VectorType *VecTy) const;
1746
1747
1748 struct ReductionFlags {
1749 ReductionFlags() = default;
1750 bool IsMaxOp =
1751 false;
1752 bool IsSigned = false;
1753 bool NoNaN =
1754 false;
1755 };
1756
1757
1758
1759
1760 bool preferFixedOverScalableIfEqualCost() const;
1761
1762
1763 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
1764 ReductionFlags Flags) const;
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
1778 ReductionFlags Flags) const;
1779
1780
1781
1782 bool preferEpilogueVectorization() const;
1783
1784
1785
1786 bool shouldExpandReduction(const IntrinsicInst *II) const;
1787
1788 enum struct ReductionShuffle { SplitHalf, Pairwise };
1789
1790
1791
1792 ReductionShuffle
1793 getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const;
1794
1795
1796
1797 unsigned getGISelRematGlobalCost() const;
1798
1799
1800
1801 unsigned getMinTripCountTailFoldingThreshold() const;
1802
1803
1804 bool supportsScalableVectors() const;
1805
1806
1807 bool enableScalableVectorization() const;
1808
1809
1810
1811
1812
1813
1814
1815 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
1816 Align Alignment) const;
1817
1818
1819
1820
1821
1822
1823 bool isProfitableToSinkOperands(Instruction *I,
1824 SmallVectorImpl<Use *> &Ops) const;
1825
1826
1827
1828
1829
1830
1831 bool isVectorShiftByScalarCheap(Type *Ty) const;
1832
1833 struct VPLegalization {
1834 enum VPTransform {
1835
1836 Legal = 0,
1837
1838 Discard = 1,
1839
1840 Convert = 2
1841 };
1842
1843
1844
1845
1846
1847 VPTransform EVLParamStrategy;
1848
1849
1850
1851
1852
1853 VPTransform OpStrategy;
1854
1855 bool shouldDoNothing() const {
1856 return (EVLParamStrategy == Legal) && (OpStrategy == Legal);
1857 }
1858 VPLegalization(VPTransform EVLParamStrategy, VPTransform OpStrategy)
1859 : EVLParamStrategy(EVLParamStrategy), OpStrategy(OpStrategy) {}
1860 };
1861
1862
1863
1864 VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const;
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876 bool hasArmWideBranch(bool Thumb) const;
1877
1878
1879
1880 uint64_t getFeatureMask(const Function &F) const;
1881
1882
1883 bool isMultiversionedFunction(const Function &F) const;
1884
1885
1886 unsigned getMaxNumArgs() const;
1887
1888
1889
1890 unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const;
1891
1892
1893
1894 private:
1895
1896
1897 class Concept;
1898
1899
1900
1901 template <typename T> class Model;
1902
1903 std::unique_ptr<Concept> TTIImpl;
1904 };
1905
1906 class TargetTransformInfo::Concept {
1907 public:
1908 virtual ~Concept() = 0;
1909 virtual const DataLayout &getDataLayout() const = 0;
1910 virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
1911 ArrayRef<const Value *> Operands,
1912 Type *AccessType,
1913 TTI::TargetCostKind CostKind) = 0;
1914 virtual InstructionCost
1915 getPointersChainCost(ArrayRef<const Value *> Ptrs, const Value *Base,
1916 const TTI::PointersChainInfo &Info, Type *AccessTy,
1917 TTI::TargetCostKind CostKind) = 0;
1918 virtual unsigned getInliningThresholdMultiplier() const = 0;
1919 virtual unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const = 0;
1920 virtual unsigned
1921 getInliningCostBenefitAnalysisProfitableMultiplier() const = 0;
1922 virtual int getInliningLastCallToStaticBonus() const = 0;
1923 virtual unsigned adjustInliningThreshold(const CallBase *CB) = 0;
1924 virtual int getInlinerVectorBonusPercent() const = 0;
1925 virtual unsigned getCallerAllocaCost(const CallBase *CB,
1926 const AllocaInst *AI) const = 0;
1927 virtual InstructionCost getMemcpyCost(const Instruction *I) = 0;
1928 virtual uint64_t getMaxMemIntrinsicInlineSizeThreshold() const = 0;
1929 virtual unsigned
1930 getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize,
1931 ProfileSummaryInfo *PSI,
1932 BlockFrequencyInfo *BFI) = 0;
1933 virtual InstructionCost getInstructionCost(const User *U,
1934 ArrayRef<const Value *> Operands,
1935 TargetCostKind CostKind) = 0;
1936 virtual BranchProbability getPredictableBranchThreshold() = 0;
1937 virtual InstructionCost getBranchMispredictPenalty() = 0;
1938 virtual bool hasBranchDivergence(const Function *F = nullptr) = 0;
1939 virtual bool isSourceOfDivergence(const Value *V) = 0;
1940 virtual bool isAlwaysUniform(const Value *V) = 0;
1941 virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
1942 virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
1943 virtual unsigned getFlatAddressSpace() = 0;
1944 virtual bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
1945 Intrinsic::ID IID) const = 0;
1946 virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
1947 virtual bool
1948 canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const = 0;
1949 virtual unsigned getAssumedAddrSpace(const Value *V) const = 0;
1950 virtual bool isSingleThreaded() const = 0;
1951 virtual std::pair<const Value *, unsigned>
1952 getPredicatedAddrSpace(const Value *V) const = 0;
1953 virtual Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II,
1954 Value *OldV,
1955 Value *NewV) const = 0;
1956 virtual bool isLoweredToCall(const Function *F) = 0;
1957 virtual void getUnrollingPreferences(Loop *L, ScalarEvolution &,
1958 UnrollingPreferences &UP,
1959 OptimizationRemarkEmitter *ORE) = 0;
1960 virtual void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
1961 PeelingPreferences &PP) = 0;
1962 virtual bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
1963 AssumptionCache &AC,
1964 TargetLibraryInfo *LibInfo,
1965 HardwareLoopInfo &HWLoopInfo) = 0;
1966 virtual unsigned getEpilogueVectorizationMinVF() = 0;
1967 virtual bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) = 0;
1968 virtual TailFoldingStyle
1969 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) = 0;
1970 virtual std::optional<Instruction *> instCombineIntrinsic(
1971 InstCombiner &IC, IntrinsicInst &II) = 0;
1972 virtual std::optional<Value *> simplifyDemandedUseBitsIntrinsic(
1973 InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask,
1974 KnownBits & Known, bool &KnownBitsComputed) = 0;
1975 virtual std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
1976 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts,
1977 APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3,
1978 std::function<void(Instruction *, unsigned, APInt, APInt &)>
1979 SimplifyAndSetOp) = 0;
1980 virtual bool isLegalAddImmediate(int64_t Imm) = 0;
1981 virtual bool isLegalAddScalableImmediate(int64_t Imm) = 0;
1982 virtual bool isLegalICmpImmediate(int64_t Imm) = 0;
1983 virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
1984 int64_t BaseOffset, bool HasBaseReg,
1985 int64_t Scale, unsigned AddrSpace,
1986 Instruction *I,
1987 int64_t ScalableOffset) = 0;
1988 virtual bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
1989 const TargetTransformInfo::LSRCost &C2) = 0;
1990 virtual bool isNumRegsMajorCostOfLSR() = 0;
1991 virtual bool shouldDropLSRSolutionIfLessProfitable() const = 0;
1992 virtual bool isProfitableLSRChainElement(Instruction *I) = 0;
1993 virtual bool canMacroFuseCmp() = 0;
1994 virtual bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE,
1995 LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC,
1996 TargetLibraryInfo *LibInfo) = 0;
1997 virtual AddressingModeKind
1998 getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const = 0;
1999 virtual bool isLegalMaskedStore(Type *DataType, Align Alignment) = 0;
2000 virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment) = 0;
2001 virtual bool isLegalNTStore(Type *DataType, Align Alignment) = 0;
2002 virtual bool isLegalNTLoad(Type *DataType, Align Alignment) = 0;
2003 virtual bool isLegalBroadcastLoad(Type *ElementTy,
2004 ElementCount NumElements) const = 0;
2005 virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) = 0;
2006 virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) = 0;
2007 virtual bool forceScalarizeMaskedGather(VectorType *DataType,
2008 Align Alignment) = 0;
2009 virtual bool forceScalarizeMaskedScatter(VectorType *DataType,
2010 Align Alignment) = 0;
2011 virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) = 0;
2012 virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) = 0;
2013 virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) = 0;
2014 virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
2015 Align Alignment,
2016 unsigned AddrSpace) = 0;
2017
2018 virtual bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) = 0;
2019 virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
2020 unsigned Opcode1,
2021 const SmallBitVector &OpcodeMask) const = 0;
2022 virtual bool enableOrderedReductions() = 0;
2023 virtual bool hasDivRemOp(Type *DataType, bool IsSigned) = 0;
2024 virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) = 0;
2025 virtual bool prefersVectorizedAddressing() = 0;
2026 virtual InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
2027 StackOffset BaseOffset,
2028 bool HasBaseReg, int64_t Scale,
2029 unsigned AddrSpace) = 0;
2030 virtual bool LSRWithInstrQueries() = 0;
2031 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) = 0;
2032 virtual bool isProfitableToHoist(Instruction *I) = 0;
2033 virtual bool useAA() = 0;
2034 virtual bool isTypeLegal(Type *Ty) = 0;
2035 virtual unsigned getRegUsageForType(Type *Ty) = 0;
2036 virtual bool shouldBuildLookupTables() = 0;
2037 virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0;
2038 virtual bool shouldBuildRelLookupTables() = 0;
2039 virtual bool useColdCCForColdCall(Function &F) = 0;
2040 virtual bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) = 0;
2041 virtual bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
2042 unsigned ScalarOpdIdx) = 0;
2043 virtual bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
2044 int OpdIdx) = 0;
2045 virtual bool
2046 isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID,
2047 int RetIdx) = 0;
2048 virtual InstructionCost
2049 getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts,
2050 bool Insert, bool Extract, TargetCostKind CostKind,
2051 ArrayRef<Value *> VL = {}) = 0;
2052 virtual InstructionCost
2053 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
2054 ArrayRef<Type *> Tys,
2055 TargetCostKind CostKind) = 0;
2056 virtual bool supportsEfficientVectorElementLoadStore() = 0;
2057 virtual bool supportsTailCalls() = 0;
2058 virtual bool supportsTailCallFor(const CallBase *CB) = 0;
2059 virtual bool enableAggressiveInterleaving(bool LoopHasReductions) = 0;
2060 virtual MemCmpExpansionOptions
2061 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const = 0;
2062 virtual bool enableSelectOptimize() = 0;
2063 virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) = 0;
2064 virtual bool enableInterleavedAccessVectorization() = 0;
2065 virtual bool enableMaskedInterleavedAccessVectorization() = 0;
2066 virtual bool isFPVectorizationPotentiallyUnsafe() = 0;
2067 virtual bool allowsMisalignedMemoryAccesses(LLVMContext &Context,
2068 unsigned BitWidth,
2069 unsigned AddressSpace,
2070 Align Alignment,
2071 unsigned *Fast) = 0;
2072 virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) = 0;
2073 virtual bool haveFastSqrt(Type *Ty) = 0;
2074 virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I) = 0;
2075 virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) = 0;
2076 virtual InstructionCost getFPOpCost(Type *Ty) = 0;
2077 virtual InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
2078 const APInt &Imm, Type *Ty) = 0;
2079 virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
2080 TargetCostKind CostKind) = 0;
2081 virtual InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
2082 const APInt &Imm, Type *Ty,
2083 TargetCostKind CostKind,
2084 Instruction *Inst = nullptr) = 0;
2085 virtual InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
2086 const APInt &Imm, Type *Ty,
2087 TargetCostKind CostKind) = 0;
2088 virtual bool preferToKeepConstantsAttached(const Instruction &Inst,
2089 const Function &Fn) const = 0;
2090 virtual unsigned getNumberOfRegisters(unsigned ClassID) const = 0;
2091 virtual bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const = 0;
2092 virtual unsigned getRegisterClassForType(bool Vector,
2093 Type *Ty = nullptr) const = 0;
2094 virtual const char *getRegisterClassName(unsigned ClassID) const = 0;
2095 virtual TypeSize getRegisterBitWidth(RegisterKind K) const = 0;
2096 virtual unsigned getMinVectorRegisterBitWidth() const = 0;
2097 virtual std::optional<unsigned> getMaxVScale() const = 0;
2098 virtual std::optional<unsigned> getVScaleForTuning() const = 0;
2099 virtual bool isVScaleKnownToBeAPowerOfTwo() const = 0;
2100 virtual bool
2101 shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const = 0;
2102 virtual ElementCount getMinimumVF(unsigned ElemWidth,
2103 bool IsScalable) const = 0;
2104 virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const = 0;
2105 virtual unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
2106 Type *ScalarValTy) const = 0;
2107 virtual bool shouldConsiderAddressTypePromotion(
2108 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) = 0;
2109 virtual unsigned getCacheLineSize() const = 0;
2110 virtual std::optional<unsigned> getCacheSize(CacheLevel Level) const = 0;
2111 virtual std::optional<unsigned> getCacheAssociativity(CacheLevel Level)
2112 const = 0;
2113 virtual std::optional<unsigned> getMinPageSize() const = 0;
2114
2115
2116
2117
2118 virtual unsigned getPrefetchDistance() const = 0;
2119
2120
2121
2122
2123
2124
2125
2126 virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses,
2127 unsigned NumStridedMemAccesses,
2128 unsigned NumPrefetches,
2129 bool HasCall) const = 0;
2130
2131
2132
2133
2134 virtual unsigned getMaxPrefetchIterationsAhead() const = 0;
2135
2136
2137 virtual bool enableWritePrefetching() const = 0;
2138
2139
2140 virtual bool shouldPrefetchAddressSpace(unsigned AS) const = 0;
2141
2142
2143
2144
2145
2146
2147
2148
2149 virtual InstructionCost
2150 getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB,
2151 Type *AccumType, ElementCount VF,
2152 PartialReductionExtendKind OpAExtend,
2153 PartialReductionExtendKind OpBExtend,
2154 std::optional<unsigned> BinOp) const = 0;
2155
2156 virtual unsigned getMaxInterleaveFactor(ElementCount VF) = 0;
2157 virtual InstructionCost getArithmeticInstrCost(
2158 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
2159 OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
2160 ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
2161 virtual InstructionCost getAltInstrCost(
2162 VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
2163 const SmallBitVector &OpcodeMask,
2164 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const = 0;
2165
2166 virtual InstructionCost
2167 getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask,
2168 TTI::TargetCostKind CostKind, int Index, VectorType *SubTp,
2169 ArrayRef<const Value *> Args, const Instruction *CxtI) = 0;
2170 virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst,
2171 Type *Src, CastContextHint CCH,
2172 TTI::TargetCostKind CostKind,
2173 const Instruction *I) = 0;
2174 virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2175 VectorType *VecTy,
2176 unsigned Index) = 0;
2177 virtual InstructionCost getCFInstrCost(unsigned Opcode,
2178 TTI::TargetCostKind CostKind,
2179 const Instruction *I = nullptr) = 0;
2180 virtual InstructionCost
2181 getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
2182 CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind,
2183 OperandValueInfo Op1Info, OperandValueInfo Op2Info,
2184 const Instruction *I) = 0;
2185 virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
2186 TTI::TargetCostKind CostKind,
2187 unsigned Index, Value *Op0,
2188 Value *Op1) = 0;
2189
2190
2191
2192
2193
2194 virtual InstructionCost getVectorInstrCost(
2195 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
2196 Value *Scalar,
2197 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) = 0;
2198
2199 virtual InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
2200 TTI::TargetCostKind CostKind,
2201 unsigned Index) = 0;
2202
2203 virtual InstructionCost
2204 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
2205 const APInt &DemandedDstElts,
2206 TTI::TargetCostKind CostKind) = 0;
2207
2208 virtual InstructionCost
2209 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2210 unsigned AddressSpace, TTI::TargetCostKind CostKind,
2211 OperandValueInfo OpInfo, const Instruction *I) = 0;
2212 virtual InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src,
2213 Align Alignment,
2214 unsigned AddressSpace,
2215 TTI::TargetCostKind CostKind,
2216 const Instruction *I) = 0;
2217 virtual InstructionCost
2218 getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2219 unsigned AddressSpace,
2220 TTI::TargetCostKind CostKind) = 0;
2221 virtual InstructionCost
2222 getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2223 bool VariableMask, Align Alignment,
2224 TTI::TargetCostKind CostKind,
2225 const Instruction *I = nullptr) = 0;
2226 virtual InstructionCost
2227 getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2228 bool VariableMask, Align Alignment,
2229 TTI::TargetCostKind CostKind,
2230 const Instruction *I = nullptr) = 0;
2231
2232 virtual InstructionCost getInterleavedMemoryOpCost(
2233 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
2234 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
2235 bool UseMaskForCond = false, bool UseMaskForGaps = false) = 0;
2236 virtual InstructionCost
2237 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
2238 std::optional<FastMathFlags> FMF,
2239 TTI::TargetCostKind CostKind) = 0;
2240 virtual InstructionCost
2241 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
2242 TTI::TargetCostKind CostKind) = 0;
2243 virtual InstructionCost getExtendedReductionCost(
2244 unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty,
2245 FastMathFlags FMF,
2246 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) = 0;
2247 virtual InstructionCost getMulAccReductionCost(
2248 bool IsUnsigned, Type *ResTy, VectorType *Ty,
2249 TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) = 0;
2250 virtual InstructionCost
2251 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
2252 TTI::TargetCostKind CostKind) = 0;
2253 virtual InstructionCost getCallInstrCost(Function *F, Type *RetTy,
2254 ArrayRef<Type *> Tys,
2255 TTI::TargetCostKind CostKind) = 0;
2256 virtual unsigned getNumberOfParts(Type *Tp) = 0;
2257 virtual InstructionCost
2258 getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr) = 0;
2259 virtual InstructionCost
2260 getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) = 0;
2261 virtual bool getTgtMemIntrinsic(IntrinsicInst *Inst,
2262 MemIntrinsicInfo &Info) = 0;
2263 virtual unsigned getAtomicMemIntrinsicMaxElementSize() const = 0;
2264 virtual Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
2265 Type *ExpectedType) = 0;
2266 virtual Type *getMemcpyLoopLoweringType(
2267 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
2268 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
2269 std::optional<uint32_t> AtomicElementSize) const = 0;
2270
2271 virtual void getMemcpyLoopResidualLoweringType(
2272 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
2273 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
2274 Align SrcAlign, Align DestAlign,
2275 std::optional<uint32_t> AtomicCpySize) const = 0;
2276 virtual bool areInlineCompatible(const Function *Caller,
2277 const Function *Callee) const = 0;
2278 virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
2279 unsigned DefaultCallPenalty) const = 0;
2280 virtual bool areTypesABICompatible(const Function *Caller,
2281 const Function *Callee,
2282 const ArrayRef<Type *> &Types) const = 0;
2283 virtual bool isIndexedLoadLegal(MemIndexedMode Mode, Type *Ty) const = 0;
2284 virtual bool isIndexedStoreLegal(MemIndexedMode Mode, Type *Ty) const = 0;
2285 virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const = 0;
2286 virtual bool isLegalToVectorizeLoad(LoadInst *LI) const = 0;
2287 virtual bool isLegalToVectorizeStore(StoreInst *SI) const = 0;
2288 virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
2289 Align Alignment,
2290 unsigned AddrSpace) const = 0;
2291 virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
2292 Align Alignment,
2293 unsigned AddrSpace) const = 0;
2294 virtual bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
2295 ElementCount VF) const = 0;
2296 virtual bool isElementTypeLegalForScalableVector(Type *Ty) const = 0;
2297 virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
2298 unsigned ChainSizeInBytes,
2299 VectorType *VecTy) const = 0;
2300 virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
2301 unsigned ChainSizeInBytes,
2302 VectorType *VecTy) const = 0;
2303 virtual bool preferFixedOverScalableIfEqualCost() const = 0;
2304 virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty,
2305 ReductionFlags) const = 0;
2306 virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
2307 ReductionFlags) const = 0;
2308 virtual bool preferEpilogueVectorization() const = 0;
2309
2310 virtual bool shouldExpandReduction(const IntrinsicInst *II) const = 0;
2311 virtual ReductionShuffle
2312 getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const = 0;
2313 virtual unsigned getGISelRematGlobalCost() const = 0;
2314 virtual unsigned getMinTripCountTailFoldingThreshold() const = 0;
2315 virtual bool enableScalableVectorization() const = 0;
2316 virtual bool supportsScalableVectors() const = 0;
2317 virtual bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
2318 Align Alignment) const = 0;
2319 virtual bool
2320 isProfitableToSinkOperands(Instruction *I,
2321 SmallVectorImpl<Use *> &OpsToSink) const = 0;
2322
2323 virtual bool isVectorShiftByScalarCheap(Type *Ty) const = 0;
2324 virtual VPLegalization
2325 getVPLegalizationStrategy(const VPIntrinsic &PI) const = 0;
2326 virtual bool hasArmWideBranch(bool Thumb) const = 0;
2327 virtual uint64_t getFeatureMask(const Function &F) const = 0;
2328 virtual bool isMultiversionedFunction(const Function &F) const = 0;
2329 virtual unsigned getMaxNumArgs() const = 0;
2330 virtual unsigned getNumBytesToPadGlobalArray(unsigned Size,
2331 Type *ArrayType) const = 0;
2332 };
2333
2334 template <typename T>
2335 class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
2336 T Impl;
2337
2338 public:
2339 Model(T Impl) : Impl(std::move(Impl)) {}
2340 ~Model() override = default;
2341
2342 const DataLayout &getDataLayout() const override {
2343 return Impl.getDataLayout();
2344 }
2345
2346 InstructionCost
2347 getGEPCost(Type *PointeeType, const Value *Ptr,
2348 ArrayRef<const Value *> Operands, Type *AccessType,
2349 TargetTransformInfo::TargetCostKind CostKind) override {
2350 return Impl.getGEPCost(PointeeType, Ptr, Operands, AccessType, CostKind);
2351 }
2352 InstructionCost getPointersChainCost(ArrayRef<const Value *> Ptrs,
2353 const Value *Base,
2354 const PointersChainInfo &Info,
2355 Type *AccessTy,
2356 TargetCostKind CostKind) override {
2357 return Impl.getPointersChainCost(Ptrs, Base, Info, AccessTy, CostKind);
2358 }
2359 unsigned getInliningThresholdMultiplier() const override {
2360 return Impl.getInliningThresholdMultiplier();
2361 }
2362 unsigned adjustInliningThreshold(const CallBase *CB) override {
2363 return Impl.adjustInliningThreshold(CB);
2364 }
2365 unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const override {
2366 return Impl.getInliningCostBenefitAnalysisSavingsMultiplier();
2367 }
2368 unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const override {
2369 return Impl.getInliningCostBenefitAnalysisProfitableMultiplier();
2370 }
2371 int getInliningLastCallToStaticBonus() const override {
2372 return Impl.getInliningLastCallToStaticBonus();
2373 }
2374 int getInlinerVectorBonusPercent() const override {
2375 return Impl.getInlinerVectorBonusPercent();
2376 }
2377 unsigned getCallerAllocaCost(const CallBase *CB,
2378 const AllocaInst *AI) const override {
2379 return Impl.getCallerAllocaCost(CB, AI);
2380 }
2381 InstructionCost getMemcpyCost(const Instruction *I) override {
2382 return Impl.getMemcpyCost(I);
2383 }
2384
2385 uint64_t getMaxMemIntrinsicInlineSizeThreshold() const override {
2386 return Impl.getMaxMemIntrinsicInlineSizeThreshold();
2387 }
2388
2389 InstructionCost getInstructionCost(const User *U,
2390 ArrayRef<const Value *> Operands,
2391 TargetCostKind CostKind) override {
2392 return Impl.getInstructionCost(U, Operands, CostKind);
2393 }
2394 BranchProbability getPredictableBranchThreshold() override {
2395 return Impl.getPredictableBranchThreshold();
2396 }
2397 InstructionCost getBranchMispredictPenalty() override {
2398 return Impl.getBranchMispredictPenalty();
2399 }
2400 bool hasBranchDivergence(const Function *F = nullptr) override {
2401 return Impl.hasBranchDivergence(F);
2402 }
2403 bool isSourceOfDivergence(const Value *V) override {
2404 return Impl.isSourceOfDivergence(V);
2405 }
2406
2407 bool isAlwaysUniform(const Value *V) override {
2408 return Impl.isAlwaysUniform(V);
2409 }
2410
2411 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const override {
2412 return Impl.isValidAddrSpaceCast(FromAS, ToAS);
2413 }
2414
2415 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const override {
2416 return Impl.addrspacesMayAlias(AS0, AS1);
2417 }
2418
2419 unsigned getFlatAddressSpace() override { return Impl.getFlatAddressSpace(); }
2420
2421 bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
2422 Intrinsic::ID IID) const override {
2423 return Impl.collectFlatAddressOperands(OpIndexes, IID);
2424 }
2425
2426 bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const override {
2427 return Impl.isNoopAddrSpaceCast(FromAS, ToAS);
2428 }
2429
2430 bool
2431 canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const override {
2432 return Impl.canHaveNonUndefGlobalInitializerInAddressSpace(AS);
2433 }
2434
2435 unsigned getAssumedAddrSpace(const Value *V) const override {
2436 return Impl.getAssumedAddrSpace(V);
2437 }
2438
2439 bool isSingleThreaded() const override { return Impl.isSingleThreaded(); }
2440
2441 std::pair<const Value *, unsigned>
2442 getPredicatedAddrSpace(const Value *V) const override {
2443 return Impl.getPredicatedAddrSpace(V);
2444 }
2445
2446 Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV,
2447 Value *NewV) const override {
2448 return Impl.rewriteIntrinsicWithAddressSpace(II, OldV, NewV);
2449 }
2450
2451 bool isLoweredToCall(const Function *F) override {
2452 return Impl.isLoweredToCall(F);
2453 }
2454 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
2455 UnrollingPreferences &UP,
2456 OptimizationRemarkEmitter *ORE) override {
2457 return Impl.getUnrollingPreferences(L, SE, UP, ORE);
2458 }
2459 void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
2460 PeelingPreferences &PP) override {
2461 return Impl.getPeelingPreferences(L, SE, PP);
2462 }
2463 bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
2464 AssumptionCache &AC, TargetLibraryInfo *LibInfo,
2465 HardwareLoopInfo &HWLoopInfo) override {
2466 return Impl.isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
2467 }
2468 unsigned getEpilogueVectorizationMinVF() override {
2469 return Impl.getEpilogueVectorizationMinVF();
2470 }
2471 bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) override {
2472 return Impl.preferPredicateOverEpilogue(TFI);
2473 }
2474 TailFoldingStyle
2475 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) override {
2476 return Impl.getPreferredTailFoldingStyle(IVUpdateMayOverflow);
2477 }
2478 std::optional<Instruction *>
2479 instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) override {
2480 return Impl.instCombineIntrinsic(IC, II);
2481 }
2482 std::optional<Value *>
2483 simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II,
2484 APInt DemandedMask, KnownBits &Known,
2485 bool &KnownBitsComputed) override {
2486 return Impl.simplifyDemandedUseBitsIntrinsic(IC, II, DemandedMask, Known,
2487 KnownBitsComputed);
2488 }
2489 std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
2490 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
2491 APInt &UndefElts2, APInt &UndefElts3,
2492 std::function<void(Instruction *, unsigned, APInt, APInt &)>
2493 SimplifyAndSetOp) override {
2494 return Impl.simplifyDemandedVectorEltsIntrinsic(
2495 IC, II, DemandedElts, UndefElts, UndefElts2, UndefElts3,
2496 SimplifyAndSetOp);
2497 }
2498 bool isLegalAddImmediate(int64_t Imm) override {
2499 return Impl.isLegalAddImmediate(Imm);
2500 }
2501 bool isLegalAddScalableImmediate(int64_t Imm) override {
2502 return Impl.isLegalAddScalableImmediate(Imm);
2503 }
2504 bool isLegalICmpImmediate(int64_t Imm) override {
2505 return Impl.isLegalICmpImmediate(Imm);
2506 }
2507 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
2508 bool HasBaseReg, int64_t Scale, unsigned AddrSpace,
2509 Instruction *I, int64_t ScalableOffset) override {
2510 return Impl.isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale,
2511 AddrSpace, I, ScalableOffset);
2512 }
2513 bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
2514 const TargetTransformInfo::LSRCost &C2) override {
2515 return Impl.isLSRCostLess(C1, C2);
2516 }
2517 bool isNumRegsMajorCostOfLSR() override {
2518 return Impl.isNumRegsMajorCostOfLSR();
2519 }
2520 bool shouldDropLSRSolutionIfLessProfitable() const override {
2521 return Impl.shouldDropLSRSolutionIfLessProfitable();
2522 }
2523 bool isProfitableLSRChainElement(Instruction *I) override {
2524 return Impl.isProfitableLSRChainElement(I);
2525 }
2526 bool canMacroFuseCmp() override { return Impl.canMacroFuseCmp(); }
2527 bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
2528 DominatorTree *DT, AssumptionCache *AC,
2529 TargetLibraryInfo *LibInfo) override {
2530 return Impl.canSaveCmp(L, BI, SE, LI, DT, AC, LibInfo);
2531 }
2532 AddressingModeKind
2533 getPreferredAddressingMode(const Loop *L,
2534 ScalarEvolution *SE) const override {
2535 return Impl.getPreferredAddressingMode(L, SE);
2536 }
2537 bool isLegalMaskedStore(Type *DataType, Align Alignment) override {
2538 return Impl.isLegalMaskedStore(DataType, Alignment);
2539 }
2540 bool isLegalMaskedLoad(Type *DataType, Align Alignment) override {
2541 return Impl.isLegalMaskedLoad(DataType, Alignment);
2542 }
2543 bool isLegalNTStore(Type *DataType, Align Alignment) override {
2544 return Impl.isLegalNTStore(DataType, Alignment);
2545 }
2546 bool isLegalNTLoad(Type *DataType, Align Alignment) override {
2547 return Impl.isLegalNTLoad(DataType, Alignment);
2548 }
2549 bool isLegalBroadcastLoad(Type *ElementTy,
2550 ElementCount NumElements) const override {
2551 return Impl.isLegalBroadcastLoad(ElementTy, NumElements);
2552 }
2553 bool isLegalMaskedScatter(Type *DataType, Align Alignment) override {
2554 return Impl.isLegalMaskedScatter(DataType, Alignment);
2555 }
2556 bool isLegalMaskedGather(Type *DataType, Align Alignment) override {
2557 return Impl.isLegalMaskedGather(DataType, Alignment);
2558 }
2559 bool forceScalarizeMaskedGather(VectorType *DataType,
2560 Align Alignment) override {
2561 return Impl.forceScalarizeMaskedGather(DataType, Alignment);
2562 }
2563 bool forceScalarizeMaskedScatter(VectorType *DataType,
2564 Align Alignment) override {
2565 return Impl.forceScalarizeMaskedScatter(DataType, Alignment);
2566 }
2567 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) override {
2568 return Impl.isLegalMaskedCompressStore(DataType, Alignment);
2569 }
2570 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) override {
2571 return Impl.isLegalMaskedExpandLoad(DataType, Alignment);
2572 }
2573 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) override {
2574 return Impl.isLegalStridedLoadStore(DataType, Alignment);
2575 }
2576 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
2577 Align Alignment,
2578 unsigned AddrSpace) override {
2579 return Impl.isLegalInterleavedAccessType(VTy, Factor, Alignment, AddrSpace);
2580 }
2581 bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) override {
2582 return Impl.isLegalMaskedVectorHistogram(AddrType, DataType);
2583 }
2584 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
2585 const SmallBitVector &OpcodeMask) const override {
2586 return Impl.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask);
2587 }
2588 bool enableOrderedReductions() override {
2589 return Impl.enableOrderedReductions();
2590 }
2591 bool hasDivRemOp(Type *DataType, bool IsSigned) override {
2592 return Impl.hasDivRemOp(DataType, IsSigned);
2593 }
2594 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) override {
2595 return Impl.hasVolatileVariant(I, AddrSpace);
2596 }
2597 bool prefersVectorizedAddressing() override {
2598 return Impl.prefersVectorizedAddressing();
2599 }
2600 InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
2601 StackOffset BaseOffset, bool HasBaseReg,
2602 int64_t Scale,
2603 unsigned AddrSpace) override {
2604 return Impl.getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, Scale,
2605 AddrSpace);
2606 }
2607 bool LSRWithInstrQueries() override { return Impl.LSRWithInstrQueries(); }
2608 bool isTruncateFree(Type *Ty1, Type *Ty2) override {
2609 return Impl.isTruncateFree(Ty1, Ty2);
2610 }
2611 bool isProfitableToHoist(Instruction *I) override {
2612 return Impl.isProfitableToHoist(I);
2613 }
2614 bool useAA() override { return Impl.useAA(); }
2615 bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); }
2616 unsigned getRegUsageForType(Type *Ty) override {
2617 return Impl.getRegUsageForType(Ty);
2618 }
2619 bool shouldBuildLookupTables() override {
2620 return Impl.shouldBuildLookupTables();
2621 }
2622 bool shouldBuildLookupTablesForConstant(Constant *C) override {
2623 return Impl.shouldBuildLookupTablesForConstant(C);
2624 }
2625 bool shouldBuildRelLookupTables() override {
2626 return Impl.shouldBuildRelLookupTables();
2627 }
2628 bool useColdCCForColdCall(Function &F) override {
2629 return Impl.useColdCCForColdCall(F);
2630 }
2631 bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) override {
2632 return Impl.isTargetIntrinsicTriviallyScalarizable(ID);
2633 }
2634
2635 bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
2636 unsigned ScalarOpdIdx) override {
2637 return Impl.isTargetIntrinsicWithScalarOpAtArg(ID, ScalarOpdIdx);
2638 }
2639
2640 bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
2641 int OpdIdx) override {
2642 return Impl.isTargetIntrinsicWithOverloadTypeAtArg(ID, OpdIdx);
2643 }
2644
2645 bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID,
2646 int RetIdx) override {
2647 return Impl.isTargetIntrinsicWithStructReturnOverloadAtField(ID, RetIdx);
2648 }
2649
2650 InstructionCost getScalarizationOverhead(VectorType *Ty,
2651 const APInt &DemandedElts,
2652 bool Insert, bool Extract,
2653 TargetCostKind CostKind,
2654 ArrayRef<Value *> VL = {}) override {
2655 return Impl.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
2656 CostKind, VL);
2657 }
2658 InstructionCost
2659 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
2660 ArrayRef<Type *> Tys,
2661 TargetCostKind CostKind) override {
2662 return Impl.getOperandsScalarizationOverhead(Args, Tys, CostKind);
2663 }
2664
2665 bool supportsEfficientVectorElementLoadStore() override {
2666 return Impl.supportsEfficientVectorElementLoadStore();
2667 }
2668
2669 bool supportsTailCalls() override { return Impl.supportsTailCalls(); }
2670 bool supportsTailCallFor(const CallBase *CB) override {
2671 return Impl.supportsTailCallFor(CB);
2672 }
2673
2674 bool enableAggressiveInterleaving(bool LoopHasReductions) override {
2675 return Impl.enableAggressiveInterleaving(LoopHasReductions);
2676 }
2677 MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
2678 bool IsZeroCmp) const override {
2679 return Impl.enableMemCmpExpansion(OptSize, IsZeroCmp);
2680 }
2681 bool enableSelectOptimize() override {
2682 return Impl.enableSelectOptimize();
2683 }
2684 bool shouldTreatInstructionLikeSelect(const Instruction *I) override {
2685 return Impl.shouldTreatInstructionLikeSelect(I);
2686 }
2687 bool enableInterleavedAccessVectorization() override {
2688 return Impl.enableInterleavedAccessVectorization();
2689 }
2690 bool enableMaskedInterleavedAccessVectorization() override {
2691 return Impl.enableMaskedInterleavedAccessVectorization();
2692 }
2693 bool isFPVectorizationPotentiallyUnsafe() override {
2694 return Impl.isFPVectorizationPotentiallyUnsafe();
2695 }
2696 bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth,
2697 unsigned AddressSpace, Align Alignment,
2698 unsigned *Fast) override {
2699 return Impl.allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
2700 Alignment, Fast);
2701 }
2702 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) override {
2703 return Impl.getPopcntSupport(IntTyWidthInBit);
2704 }
2705 bool haveFastSqrt(Type *Ty) override { return Impl.haveFastSqrt(Ty); }
2706
2707 bool isExpensiveToSpeculativelyExecute(const Instruction* I) override {
2708 return Impl.isExpensiveToSpeculativelyExecute(I);
2709 }
2710
2711 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) override {
2712 return Impl.isFCmpOrdCheaperThanFCmpZero(Ty);
2713 }
2714
2715 InstructionCost getFPOpCost(Type *Ty) override {
2716 return Impl.getFPOpCost(Ty);
2717 }
2718
2719 InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
2720 const APInt &Imm, Type *Ty) override {
2721 return Impl.getIntImmCodeSizeCost(Opc, Idx, Imm, Ty);
2722 }
2723 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
2724 TargetCostKind CostKind) override {
2725 return Impl.getIntImmCost(Imm, Ty, CostKind);
2726 }
2727 InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
2728 const APInt &Imm, Type *Ty,
2729 TargetCostKind CostKind,
2730 Instruction *Inst = nullptr) override {
2731 return Impl.getIntImmCostInst(Opc, Idx, Imm, Ty, CostKind, Inst);
2732 }
2733 InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
2734 const APInt &Imm, Type *Ty,
2735 TargetCostKind CostKind) override {
2736 return Impl.getIntImmCostIntrin(IID, Idx, Imm, Ty, CostKind);
2737 }
2738 bool preferToKeepConstantsAttached(const Instruction &Inst,
2739 const Function &Fn) const override {
2740 return Impl.preferToKeepConstantsAttached(Inst, Fn);
2741 }
2742 unsigned getNumberOfRegisters(unsigned ClassID) const override {
2743 return Impl.getNumberOfRegisters(ClassID);
2744 }
2745 bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const override {
2746 return Impl.hasConditionalLoadStoreForType(Ty);
2747 }
2748 unsigned getRegisterClassForType(bool Vector,
2749 Type *Ty = nullptr) const override {
2750 return Impl.getRegisterClassForType(Vector, Ty);
2751 }
2752 const char *getRegisterClassName(unsigned ClassID) const override {
2753 return Impl.getRegisterClassName(ClassID);
2754 }
2755 TypeSize getRegisterBitWidth(RegisterKind K) const override {
2756 return Impl.getRegisterBitWidth(K);
2757 }
2758 unsigned getMinVectorRegisterBitWidth() const override {
2759 return Impl.getMinVectorRegisterBitWidth();
2760 }
2761 std::optional<unsigned> getMaxVScale() const override {
2762 return Impl.getMaxVScale();
2763 }
2764 std::optional<unsigned> getVScaleForTuning() const override {
2765 return Impl.getVScaleForTuning();
2766 }
2767 bool isVScaleKnownToBeAPowerOfTwo() const override {
2768 return Impl.isVScaleKnownToBeAPowerOfTwo();
2769 }
2770 bool shouldMaximizeVectorBandwidth(
2771 TargetTransformInfo::RegisterKind K) const override {
2772 return Impl.shouldMaximizeVectorBandwidth(K);
2773 }
2774 ElementCount getMinimumVF(unsigned ElemWidth,
2775 bool IsScalable) const override {
2776 return Impl.getMinimumVF(ElemWidth, IsScalable);
2777 }
2778 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override {
2779 return Impl.getMaximumVF(ElemWidth, Opcode);
2780 }
2781 unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
2782 Type *ScalarValTy) const override {
2783 return Impl.getStoreMinimumVF(VF, ScalarMemTy, ScalarValTy);
2784 }
2785 bool shouldConsiderAddressTypePromotion(
2786 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) override {
2787 return Impl.shouldConsiderAddressTypePromotion(
2788 I, AllowPromotionWithoutCommonHeader);
2789 }
2790 unsigned getCacheLineSize() const override { return Impl.getCacheLineSize(); }
2791 std::optional<unsigned> getCacheSize(CacheLevel Level) const override {
2792 return Impl.getCacheSize(Level);
2793 }
2794 std::optional<unsigned>
2795 getCacheAssociativity(CacheLevel Level) const override {
2796 return Impl.getCacheAssociativity(Level);
2797 }
2798
2799 std::optional<unsigned> getMinPageSize() const override {
2800 return Impl.getMinPageSize();
2801 }
2802
2803
2804
2805 unsigned getPrefetchDistance() const override {
2806 return Impl.getPrefetchDistance();
2807 }
2808
2809
2810
2811
2812 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
2813 unsigned NumStridedMemAccesses,
2814 unsigned NumPrefetches,
2815 bool HasCall) const override {
2816 return Impl.getMinPrefetchStride(NumMemAccesses, NumStridedMemAccesses,
2817 NumPrefetches, HasCall);
2818 }
2819
2820
2821
2822
2823 unsigned getMaxPrefetchIterationsAhead() const override {
2824 return Impl.getMaxPrefetchIterationsAhead();
2825 }
2826
2827
2828 bool enableWritePrefetching() const override {
2829 return Impl.enableWritePrefetching();
2830 }
2831
2832
2833 bool shouldPrefetchAddressSpace(unsigned AS) const override {
2834 return Impl.shouldPrefetchAddressSpace(AS);
2835 }
2836
2837 InstructionCost getPartialReductionCost(
2838 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
2839 ElementCount VF, PartialReductionExtendKind OpAExtend,
2840 PartialReductionExtendKind OpBExtend,
2841 std::optional<unsigned> BinOp = std::nullopt) const override {
2842 return Impl.getPartialReductionCost(Opcode, InputTypeA, InputTypeB,
2843 AccumType, VF, OpAExtend, OpBExtend,
2844 BinOp);
2845 }
2846
2847 unsigned getMaxInterleaveFactor(ElementCount VF) override {
2848 return Impl.getMaxInterleaveFactor(VF);
2849 }
2850 unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
2851 unsigned &JTSize,
2852 ProfileSummaryInfo *PSI,
2853 BlockFrequencyInfo *BFI) override {
2854 return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
2855 }
2856 InstructionCost getArithmeticInstrCost(
2857 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
2858 OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
2859 ArrayRef<const Value *> Args,
2860 const Instruction *CxtI = nullptr) override {
2861 return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
2862 Args, CxtI);
2863 }
2864 InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0,
2865 unsigned Opcode1,
2866 const SmallBitVector &OpcodeMask,
2867 TTI::TargetCostKind CostKind) const override {
2868 return Impl.getAltInstrCost(VecTy, Opcode0, Opcode1, OpcodeMask, CostKind);
2869 }
2870
2871 InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
2872 ArrayRef<int> Mask,
2873 TTI::TargetCostKind CostKind, int Index,
2874 VectorType *SubTp,
2875 ArrayRef<const Value *> Args,
2876 const Instruction *CxtI) override {
2877 return Impl.getShuffleCost(Kind, Tp, Mask, CostKind, Index, SubTp, Args,
2878 CxtI);
2879 }
2880 InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
2881 CastContextHint CCH,
2882 TTI::TargetCostKind CostKind,
2883 const Instruction *I) override {
2884 return Impl.getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
2885 }
2886 InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2887 VectorType *VecTy,
2888 unsigned Index) override {
2889 return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
2890 }
2891 InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
2892 const Instruction *I = nullptr) override {
2893 return Impl.getCFInstrCost(Opcode, CostKind, I);
2894 }
2895 InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
2896 CmpInst::Predicate VecPred,
2897 TTI::TargetCostKind CostKind,
2898 OperandValueInfo Op1Info,
2899 OperandValueInfo Op2Info,
2900 const Instruction *I) override {
2901 return Impl.getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
2902 Op1Info, Op2Info, I);
2903 }
2904 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
2905 TTI::TargetCostKind CostKind,
2906 unsigned Index, Value *Op0,
2907 Value *Op1) override {
2908 return Impl.getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1);
2909 }
2910 InstructionCost getVectorInstrCost(
2911 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
2912 Value *Scalar,
2913 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) override {
2914 return Impl.getVectorInstrCost(Opcode, Val, CostKind, Index, Scalar,
2915 ScalarUserAndIdx);
2916 }
2917 InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
2918 TTI::TargetCostKind CostKind,
2919 unsigned Index) override {
2920 return Impl.getVectorInstrCost(I, Val, CostKind, Index);
2921 }
2922 InstructionCost
2923 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
2924 const APInt &DemandedDstElts,
2925 TTI::TargetCostKind CostKind) override {
2926 return Impl.getReplicationShuffleCost(EltTy, ReplicationFactor, VF,
2927 DemandedDstElts, CostKind);
2928 }
2929 InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2930 unsigned AddressSpace,
2931 TTI::TargetCostKind CostKind,
2932 OperandValueInfo OpInfo,
2933 const Instruction *I) override {
2934 return Impl.getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind,
2935 OpInfo, I);
2936 }
2937 InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2938 unsigned AddressSpace,
2939 TTI::TargetCostKind CostKind,
2940 const Instruction *I) override {
2941 return Impl.getVPMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
2942 CostKind, I);
2943 }
2944 InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
2945 Align Alignment, unsigned AddressSpace,
2946 TTI::TargetCostKind CostKind) override {
2947 return Impl.getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
2948 CostKind);
2949 }
2950 InstructionCost
2951 getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2952 bool VariableMask, Align Alignment,
2953 TTI::TargetCostKind CostKind,
2954 const Instruction *I = nullptr) override {
2955 return Impl.getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
2956 Alignment, CostKind, I);
2957 }
2958 InstructionCost
2959 getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2960 bool VariableMask, Align Alignment,
2961 TTI::TargetCostKind CostKind,
2962 const Instruction *I = nullptr) override {
2963 return Impl.getStridedMemoryOpCost(Opcode, DataTy, Ptr, VariableMask,
2964 Alignment, CostKind, I);
2965 }
2966 InstructionCost getInterleavedMemoryOpCost(
2967 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
2968 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
2969 bool UseMaskForCond, bool UseMaskForGaps) override {
2970 return Impl.getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
2971 Alignment, AddressSpace, CostKind,
2972 UseMaskForCond, UseMaskForGaps);
2973 }
2974 InstructionCost
2975 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
2976 std::optional<FastMathFlags> FMF,
2977 TTI::TargetCostKind CostKind) override {
2978 return Impl.getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);
2979 }
2980 InstructionCost
2981 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
2982 TTI::TargetCostKind CostKind) override {
2983 return Impl.getMinMaxReductionCost(IID, Ty, FMF, CostKind);
2984 }
2985 InstructionCost
2986 getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy,
2987 VectorType *Ty, FastMathFlags FMF,
2988 TTI::TargetCostKind CostKind) override {
2989 return Impl.getExtendedReductionCost(Opcode, IsUnsigned, ResTy, Ty, FMF,
2990 CostKind);
2991 }
2992 InstructionCost
2993 getMulAccReductionCost(bool IsUnsigned, Type *ResTy, VectorType *Ty,
2994 TTI::TargetCostKind CostKind) override {
2995 return Impl.getMulAccReductionCost(IsUnsigned, ResTy, Ty, CostKind);
2996 }
2997 InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
2998 TTI::TargetCostKind CostKind) override {
2999 return Impl.getIntrinsicInstrCost(ICA, CostKind);
3000 }
3001 InstructionCost getCallInstrCost(Function *F, Type *RetTy,
3002 ArrayRef<Type *> Tys,
3003 TTI::TargetCostKind CostKind) override {
3004 return Impl.getCallInstrCost(F, RetTy, Tys, CostKind);
3005 }
3006 unsigned getNumberOfParts(Type *Tp) override {
3007 return Impl.getNumberOfParts(Tp);
3008 }
3009 InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
3010 const SCEV *Ptr) override {
3011 return Impl.getAddressComputationCost(Ty, SE, Ptr);
3012 }
3013 InstructionCost getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) override {
3014 return Impl.getCostOfKeepingLiveOverCall(Tys);
3015 }
3016 bool getTgtMemIntrinsic(IntrinsicInst *Inst,
3017 MemIntrinsicInfo &Info) override {
3018 return Impl.getTgtMemIntrinsic(Inst, Info);
3019 }
3020 unsigned getAtomicMemIntrinsicMaxElementSize() const override {
3021 return Impl.getAtomicMemIntrinsicMaxElementSize();
3022 }
3023 Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
3024 Type *ExpectedType) override {
3025 return Impl.getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
3026 }
3027 Type *getMemcpyLoopLoweringType(
3028 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
3029 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
3030 std::optional<uint32_t> AtomicElementSize) const override {
3031 return Impl.getMemcpyLoopLoweringType(Context, Length, SrcAddrSpace,
3032 DestAddrSpace, SrcAlign, DestAlign,
3033 AtomicElementSize);
3034 }
3035 void getMemcpyLoopResidualLoweringType(
3036 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
3037 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
3038 Align SrcAlign, Align DestAlign,
3039 std::optional<uint32_t> AtomicCpySize) const override {
3040 Impl.getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
3041 SrcAddrSpace, DestAddrSpace,
3042 SrcAlign, DestAlign, AtomicCpySize);
3043 }
3044 bool areInlineCompatible(const Function *Caller,
3045 const Function *Callee) const override {
3046 return Impl.areInlineCompatible(Caller, Callee);
3047 }
3048 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
3049 unsigned DefaultCallPenalty) const override {
3050 return Impl.getInlineCallPenalty(F, Call, DefaultCallPenalty);
3051 }
3052 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
3053 const ArrayRef<Type *> &Types) const override {
3054 return Impl.areTypesABICompatible(Caller, Callee, Types);
3055 }
3056 bool isIndexedLoadLegal(MemIndexedMode Mode, Type *Ty) const override {
3057 return Impl.isIndexedLoadLegal(Mode, Ty, getDataLayout());
3058 }
3059 bool isIndexedStoreLegal(MemIndexedMode Mode, Type *Ty) const override {
3060 return Impl.isIndexedStoreLegal(Mode, Ty, getDataLayout());
3061 }
3062 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const override {
3063 return Impl.getLoadStoreVecRegBitWidth(AddrSpace);
3064 }
3065 bool isLegalToVectorizeLoad(LoadInst *LI) const override {
3066 return Impl.isLegalToVectorizeLoad(LI);
3067 }
3068 bool isLegalToVectorizeStore(StoreInst *SI) const override {
3069 return Impl.isLegalToVectorizeStore(SI);
3070 }
3071 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
3072 unsigned AddrSpace) const override {
3073 return Impl.isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
3074 AddrSpace);
3075 }
3076 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
3077 unsigned AddrSpace) const override {
3078 return Impl.isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
3079 AddrSpace);
3080 }
3081 bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
3082 ElementCount VF) const override {
3083 return Impl.isLegalToVectorizeReduction(RdxDesc, VF);
3084 }
3085 bool isElementTypeLegalForScalableVector(Type *Ty) const override {
3086 return Impl.isElementTypeLegalForScalableVector(Ty);
3087 }
3088 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
3089 unsigned ChainSizeInBytes,
3090 VectorType *VecTy) const override {
3091 return Impl.getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
3092 }
3093 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
3094 unsigned ChainSizeInBytes,
3095 VectorType *VecTy) const override {
3096 return Impl.getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
3097 }
3098 bool preferFixedOverScalableIfEqualCost() const override {
3099 return Impl.preferFixedOverScalableIfEqualCost();
3100 }
3101 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
3102 ReductionFlags Flags) const override {
3103 return Impl.preferInLoopReduction(Opcode, Ty, Flags);
3104 }
3105 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
3106 ReductionFlags Flags) const override {
3107 return Impl.preferPredicatedReductionSelect(Opcode, Ty, Flags);
3108 }
3109 bool preferEpilogueVectorization() const override {
3110 return Impl.preferEpilogueVectorization();
3111 }
3112
3113 bool shouldExpandReduction(const IntrinsicInst *II) const override {
3114 return Impl.shouldExpandReduction(II);
3115 }
3116
3117 ReductionShuffle
3118 getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const override {
3119 return Impl.getPreferredExpandedReductionShuffle(II);
3120 }
3121
3122 unsigned getGISelRematGlobalCost() const override {
3123 return Impl.getGISelRematGlobalCost();
3124 }
3125
3126 unsigned getMinTripCountTailFoldingThreshold() const override {
3127 return Impl.getMinTripCountTailFoldingThreshold();
3128 }
3129
3130 bool supportsScalableVectors() const override {
3131 return Impl.supportsScalableVectors();
3132 }
3133
3134 bool enableScalableVectorization() const override {
3135 return Impl.enableScalableVectorization();
3136 }
3137
3138 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
3139 Align Alignment) const override {
3140 return Impl.hasActiveVectorLength(Opcode, DataType, Alignment);
3141 }
3142
3143 bool isProfitableToSinkOperands(Instruction *I,
3144 SmallVectorImpl<Use *> &Ops) const override {
3145 return Impl.isProfitableToSinkOperands(I, Ops);
3146 };
3147
3148 bool isVectorShiftByScalarCheap(Type *Ty) const override {
3149 return Impl.isVectorShiftByScalarCheap(Ty);
3150 }
3151
3152 VPLegalization
3153 getVPLegalizationStrategy(const VPIntrinsic &PI) const override {
3154 return Impl.getVPLegalizationStrategy(PI);
3155 }
3156
3157 bool hasArmWideBranch(bool Thumb) const override {
3158 return Impl.hasArmWideBranch(Thumb);
3159 }
3160
3161 uint64_t getFeatureMask(const Function &F) const override {
3162 return Impl.getFeatureMask(F);
3163 }
3164
3165 bool isMultiversionedFunction(const Function &F) const override {
3166 return Impl.isMultiversionedFunction(F);
3167 }
3168
3169 unsigned getMaxNumArgs() const override {
3170 return Impl.getMaxNumArgs();
3171 }
3172
3173 unsigned getNumBytesToPadGlobalArray(unsigned Size,
3174 Type *ArrayType) const override {
3175 return Impl.getNumBytesToPadGlobalArray(Size, ArrayType);
3176 }
3177 };
3178
3179 template <typename T>
3180 TargetTransformInfo::TargetTransformInfo(T Impl)
3181 : TTIImpl(new Model<T>(Impl)) {}
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194 class TargetIRAnalysis : public AnalysisInfoMixin<TargetIRAnalysis> {
3195 public:
3196 typedef TargetTransformInfo Result;
3197
3198
3199
3200
3201
3202 TargetIRAnalysis();
3203
3204
3205
3206
3207
3208 TargetIRAnalysis(std::function<Result(const Function &)> TTICallback);
3209
3210
3211 TargetIRAnalysis(const TargetIRAnalysis &Arg)
3212 : TTICallback(Arg.TTICallback) {}
3213 TargetIRAnalysis(TargetIRAnalysis &&Arg)
3214 : TTICallback(std::move(Arg.TTICallback)) {}
3215 TargetIRAnalysis &operator=(const TargetIRAnalysis &RHS) {
3216 TTICallback = RHS.TTICallback;
3217 return *this;
3218 }
3219 TargetIRAnalysis &operator=(TargetIRAnalysis &&RHS) {
3220 TTICallback = std::move(RHS.TTICallback);
3221 return *this;
3222 }
3223
3224 Result run(const Function &F, FunctionAnalysisManager &);
3225
3226 private:
3227 friend AnalysisInfoMixin<TargetIRAnalysis>;
3228 static AnalysisKey Key;
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240 std::function<Result(const Function &)> TTICallback;
3241
3242
3243 static Result getDefaultTTI(const Function &F);
3244 };
3245
3246
3247
3248
3249
3250 class TargetTransformInfoWrapperPass : public ImmutablePass {
3251 TargetIRAnalysis TIRA;
3252 std::optional<TargetTransformInfo> TTI;
3253
3254 virtual void anchor();
3255
3256 public:
3257 static char ID;
3258
3259
3260
3261
3262
3263 TargetTransformInfoWrapperPass();
3264
3265 explicit TargetTransformInfoWrapperPass(TargetIRAnalysis TIRA);
3266
3267 TargetTransformInfo &getTTI(const Function &F);
3268 };
3269
3270
3271
3272
3273
3274 ImmutablePass *createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA);
3275
3276 }
3277
3278 #endif