LLVM 24.0.0git
TargetTransformInfoImpl.h
Go to the documentation of this file.
1//===- TargetTransformInfoImpl.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file provides helpers for the implementation of
10/// a TargetTransformInfo-conforming class.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
15#define LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
16
21#include "llvm/IR/DataLayout.h"
24#include "llvm/IR/Operator.h"
26#include <optional>
27#include <utility>
28
29namespace llvm {
30
31class Function;
32
33/// Base class for use as a mix-in that aids implementing
34/// a TargetTransformInfo-compatible class.
36
37protected:
39
40 const DataLayout &DL;
41
43
44public:
46
47 // Provide value semantics. MSVC requires that we spell all of these out.
50
51 virtual const DataLayout &getDataLayout() const { return DL; }
52
53 // FIXME: It looks like this implementation is dead. All clients appear to
54 // use the (non-const) version from `TargetTransformInfoImplCRTPBase`.
55 virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
57 Type *AccessType,
59 // In the basic model, we just assume that all-constant GEPs will be folded
60 // into their uses via addressing modes.
61 for (const Value *Operand : Operands)
62 if (!isa<Constant>(Operand))
63 return TTI::TCC_Basic;
64
65 return TTI::TCC_Free;
66 }
67
68 virtual InstructionCost
70 const TTI::PointersChainInfo &Info, Type *AccessTy,
72 llvm_unreachable("Not implemented");
73 }
74
75 virtual unsigned
78 BlockFrequencyInfo *BFI) const {
79 (void)PSI;
80 (void)BFI;
81 JTSize = 0;
82 return SI.getNumCases();
83 }
84
85 virtual InstructionCost
90
91 virtual unsigned getInliningThresholdMultiplier() const { return 1; }
93 return 8;
94 }
96 return 8;
97 }
99 // This is the value of InlineConstants::LastCallToStaticBonus before it was
100 // removed along with the introduction of this function.
101 return 15000;
102 }
103 virtual unsigned adjustInliningThreshold(const CallBase *CB) const {
104 return 0;
105 }
106 virtual unsigned getCallerAllocaCost(const CallBase *CB,
107 const AllocaInst *AI) const {
108 return 0;
109 };
110
111 virtual int getInlinerVectorBonusPercent() const { return 150; }
112
114 return TTI::TCC_Expensive;
115 }
116
117 virtual uint64_t getMaxMemIntrinsicInlineSizeThreshold() const { return 64; }
118
119 // Although this default value is arbitrary, it is not random. It is assumed
120 // that a condition that evaluates the same way by a higher percentage than
121 // this is best represented as control flow. Therefore, the default value N
122 // should be set such that the win from N% correct executions is greater than
123 // the loss from (100 - N)% mispredicted executions for the majority of
124 // intended targets.
126 return BranchProbability(99, 100);
127 }
128
129 virtual InstructionCost getBranchMispredictPenalty() const { return 0; }
130
131 virtual bool hasBranchDivergence(const Function *F = nullptr) const {
132 return false;
133 }
134
135 virtual ValueUniformity getValueUniformity(const Value *V) const {
137 }
138
139 virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const {
140 return false;
141 }
142
143 virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
144 return true;
145 }
146
147 virtual unsigned getFlatAddressSpace() const { return -1; }
148
150 Intrinsic::ID IID) const {
151 return false;
152 }
153
154 virtual bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
155
156 virtual std::pair<KnownBits, KnownBits>
157 computeKnownBitsAddrSpaceCast(unsigned ToAS, const Value &PtrOp) const {
158 const Type *PtrTy = PtrOp.getType();
159 assert(PtrTy->isPtrOrPtrVectorTy() &&
160 "expected pointer or pointer vector type");
161 unsigned FromAS = PtrTy->getPointerAddressSpace();
162
163 if (DL.isNonIntegralAddressSpace(FromAS))
164 return std::pair(KnownBits(DL.getPointerSizeInBits(FromAS)),
165 KnownBits(DL.getPointerSizeInBits(ToAS)));
166
167 KnownBits FromPtrBits;
168 if (const AddrSpaceCastInst *CastI = dyn_cast<AddrSpaceCastInst>(&PtrOp)) {
169 std::pair<KnownBits, KnownBits> KB = computeKnownBitsAddrSpaceCast(
170 CastI->getDestAddressSpace(), *CastI->getPointerOperand());
171 FromPtrBits = KB.second;
172 } else {
173 FromPtrBits = computeKnownBits(&PtrOp, DL, nullptr);
174 }
175
176 KnownBits ToPtrBits =
177 computeKnownBitsAddrSpaceCast(FromAS, ToAS, FromPtrBits);
178
179 return {FromPtrBits, ToPtrBits};
180 }
181
182 virtual KnownBits
183 computeKnownBitsAddrSpaceCast(unsigned FromAS, unsigned ToAS,
184 const KnownBits &FromPtrBits) const {
185 unsigned ToASBitSize = DL.getPointerSizeInBits(ToAS);
186
187 if (DL.isNonIntegralAddressSpace(FromAS))
188 return KnownBits(ToASBitSize);
189
190 // By default, we assume that all valid "larger" (e.g. 64-bit) to "smaller"
191 // (e.g. 32-bit) casts work by chopping off the high bits.
192 // By default, we do not assume that null results in null again.
193 return FromPtrBits.anyextOrTrunc(ToASBitSize);
194 }
195
197 unsigned DstAS) const {
198 return {DL.getPointerSizeInBits(SrcAS), 0};
199 }
200
201 virtual bool
203 return AS == 0;
204 };
205
206 virtual unsigned getAssumedAddrSpace(const Value *V) const { return -1; }
207
208 virtual bool isSingleThreaded() const { return false; }
209
210 virtual std::pair<const Value *, unsigned>
212 return std::make_pair(nullptr, -1);
213 }
214
216 Value *OldV,
217 Value *NewV) const {
218 return nullptr;
219 }
220
221 virtual bool isLoweredToCall(const Function *F) const {
222 assert(F && "A concrete function must be provided to this routine.");
223
224 // FIXME: These should almost certainly not be handled here, and instead
225 // handled with the help of TLI or the target itself. This was largely
226 // ported from existing analysis heuristics here so that such refactorings
227 // can take place in the future.
228
229 if (F->isIntrinsic())
230 return false;
231
232 if (F->hasLocalLinkage() || !F->hasName())
233 return true;
234
235 StringRef Name = F->getName();
236
237 // These will all likely lower to a single selection DAG node.
238 // clang-format off
239 if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
240 Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
241 Name == "fmin" || Name == "fminf" || Name == "fminl" ||
242 Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
243 Name == "sin" || Name == "sinf" || Name == "sinl" ||
244 Name == "cos" || Name == "cosf" || Name == "cosl" ||
245 Name == "tan" || Name == "tanf" || Name == "tanl" ||
246 Name == "asin" || Name == "asinf" || Name == "asinl" ||
247 Name == "acos" || Name == "acosf" || Name == "acosl" ||
248 Name == "atan" || Name == "atanf" || Name == "atanl" ||
249 Name == "atan2" || Name == "atan2f" || Name == "atan2l"||
250 Name == "sinh" || Name == "sinhf" || Name == "sinhl" ||
251 Name == "cosh" || Name == "coshf" || Name == "coshl" ||
252 Name == "tanh" || Name == "tanhf" || Name == "tanhl" ||
253 Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" ||
254 Name == "exp10" || Name == "exp10l" || Name == "exp10f")
255 return false;
256 // clang-format on
257 // These are all likely to be optimized into something smaller.
258 if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
259 Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
260 Name == "floorf" || Name == "ceil" || Name == "round" ||
261 Name == "ffs" || Name == "ffsl" || Name == "abs" || Name == "labs" ||
262 Name == "llabs")
263 return false;
264
265 return true;
266 }
267
269 AssumptionCache &AC,
270 TargetLibraryInfo *LibInfo,
271 HardwareLoopInfo &HWLoopInfo) const {
272 return false;
273 }
274
275 virtual unsigned getEpilogueVectorizationMinVF() const { return 16; }
276
278 return false;
279 }
280
284
285 virtual std::optional<Instruction *>
287 return std::nullopt;
288 }
289
290 virtual std::optional<Value *>
292 APInt DemandedMask, KnownBits &Known,
293 bool &KnownBitsComputed) const {
294 return std::nullopt;
295 }
296
297 virtual std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
298 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
299 APInt &UndefElts2, APInt &UndefElts3,
300 std::function<void(Instruction *, unsigned, APInt, APInt &)>
301 SimplifyAndSetOp) const {
302 return std::nullopt;
303 }
304
308
311
312 virtual bool isLegalAddImmediate(int64_t Imm) const { return false; }
313
314 virtual bool isLegalAddScalableImmediate(int64_t Imm) const { return false; }
315
316 virtual bool isLegalICmpImmediate(int64_t Imm) const { return false; }
317
318 virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
319 int64_t BaseOffset, bool HasBaseReg,
320 int64_t Scale, unsigned AddrSpace,
321 Instruction *I = nullptr,
322 int64_t ScalableOffset = 0) const {
323 // Guess that only reg and reg+reg addressing is allowed. This heuristic is
324 // taken from the implementation of LSR.
325 return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
326 }
327
328 virtual bool isLSRCostLess(const TTI::LSRCost &C1,
329 const TTI::LSRCost &C2) const {
330 return std::tie(C1.NumRegs, C1.AddRecCost, C1.NumIVMuls, C1.NumBaseAdds,
331 C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
332 std::tie(C2.NumRegs, C2.AddRecCost, C2.NumIVMuls, C2.NumBaseAdds,
333 C2.ScaleCost, C2.ImmCost, C2.SetupCost);
334 }
335
336 virtual bool isNumRegsMajorCostOfLSR() const { return true; }
337
338 virtual bool shouldDropLSRSolutionIfLessProfitable() const { return false; }
339
341 return false;
342 }
343
344 virtual bool canMacroFuseCmp() const { return false; }
345
346 virtual bool canSaveCmp(Loop *L, CondBrInst **BI, ScalarEvolution *SE,
348 TargetLibraryInfo *LibInfo) const {
349 return false;
350 }
351
354 return TTI::AMK_None;
355 }
356
357 virtual bool isLegalMaskedStore(Type *DataType, Align Alignment,
358 unsigned AddressSpace,
359 TTI::MaskKind MaskKind) const {
360 return false;
361 }
362
363 virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment,
364 unsigned AddressSpace,
365 TTI::MaskKind MaskKind) const {
366 return false;
367 }
368
369 virtual bool isLegalNTStore(Type *DataType, Align Alignment) const {
370 // By default, assume nontemporal memory stores are available for stores
371 // that are aligned and have a size that is a power of 2.
372 unsigned DataSize = DL.getTypeStoreSize(DataType);
373 return Alignment >= DataSize && isPowerOf2_32(DataSize);
374 }
375
376 virtual bool isLegalNTLoad(Type *DataType, Align Alignment) const {
377 // By default, assume nontemporal memory loads are available for loads that
378 // are aligned and have a size that is a power of 2.
379 unsigned DataSize = DL.getTypeStoreSize(DataType);
380 return Alignment >= DataSize && isPowerOf2_32(DataSize);
381 }
382
383 virtual bool isLegalBroadcastLoad(Type *ElementTy,
384 ElementCount NumElements) const {
385 return false;
386 }
387
388 virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) const {
389 return false;
390 }
391
392 virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) const {
393 return false;
394 }
395
397 Align Alignment) const {
398 return false;
399 }
400
402 Align Alignment) const {
403 return false;
404 }
405
406 virtual bool isLegalMaskedCompressStore(Type *DataType,
407 Align Alignment) const {
408 return false;
409 }
410
411 virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
412 unsigned Opcode1,
413 const SmallBitVector &OpcodeMask) const {
414 return false;
415 }
416
417 virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const {
418 return false;
419 }
420
421 virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const {
422 return false;
423 }
424
425 virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
426 Align Alignment,
427 unsigned AddrSpace) const {
428 return false;
429 }
430
431 virtual bool isLegalMaskedVectorHistogram(Type *AddrType,
432 Type *DataType) const {
433 return false;
434 }
435
436 virtual bool enableOrderedReductions() const { return false; }
437
438 virtual bool hasDivRemOp(Type *DataType, bool IsSigned) const {
439 return false;
440 }
441
442 virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const {
443 return false;
444 }
445
446 virtual bool prefersVectorizedAddressing() const { return true; }
447
449 StackOffset BaseOffset,
450 bool HasBaseReg, int64_t Scale,
451 unsigned AddrSpace) const {
452 // Guess that all legal addressing mode are free.
453 if (isLegalAddressingMode(Ty, BaseGV, BaseOffset.getFixed(), HasBaseReg,
454 Scale, AddrSpace, /*I=*/nullptr,
455 BaseOffset.getScalable()))
456 return 0;
458 }
459
460 virtual bool LSRWithInstrQueries() const { return false; }
461
462 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const { return false; }
463
464 virtual bool isProfitableToHoist(Instruction *I) const { return true; }
465
466 virtual bool useAA() const { return false; }
467
468 virtual bool isTypeLegal(Type *Ty) const { return false; }
469
470 virtual unsigned getRegUsageForType(Type *Ty) const { return 1; }
471
472 virtual bool shouldBuildLookupTables() const { return true; }
473
475 return true;
476 }
477
478 virtual unsigned getMinimumLookupTableEntryBitWidth() const { return 8; }
479
480 virtual bool shouldBuildRelLookupTables() const { return false; }
481
482 virtual bool useColdCCForColdCall(Function &F) const { return false; }
483
484 virtual bool useFastCCForInternalCall(Function &F) const { return true; }
485
487 unsigned ScalarOpdIdx) const {
488 return false;
489 }
490
492 int OpdIdx) const {
493 return OpdIdx == -1;
494 }
495
496 virtual bool
498 int RetIdx) const {
499 return RetIdx == 0;
500 }
501
503 VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
504 TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
505 ArrayRef<Value *> VL = {},
507 // Default implementation returns 0.
508 // BasicTTIImpl provides the actual implementation.
509 return 0;
510 }
511
517
518 virtual bool supportsEfficientVectorElementLoadStore() const { return false; }
519
520 virtual bool supportsTailCalls() const { return true; }
521
522 virtual bool supportsTailCallFor(const CallBase *CB) const {
523 llvm_unreachable("Not implemented");
524 }
525
526 virtual bool enableAggressiveInterleaving(bool LoopHasReductions) const {
527 return false;
528 }
529
531 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
532 return {};
533 }
534
535 virtual bool enableSelectOptimize() const { return true; }
536
537 virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) const {
538 // A select with two constant operands will usually be better left as a
539 // select.
540 using namespace llvm::PatternMatch;
542 return false;
543 // If the select is a logical-and/logical-or then it is better treated as a
544 // and/or by the backend.
545 return isa<SelectInst>(I) &&
548 }
549
550 virtual bool enableInterleavedAccessVectorization() const { return false; }
551
553 return false;
554 }
555
556 virtual bool isFPVectorizationPotentiallyUnsafe() const { return false; }
557
559 unsigned BitWidth,
560 unsigned AddressSpace,
561 Align Alignment,
562 unsigned *Fast) const {
563 return false;
564 }
565
567 getPopcntSupport(unsigned IntTyWidthInBit) const {
568 return TTI::PSK_Software;
569 }
570
571 virtual bool haveFastSqrt(Type *Ty) const { return false; }
572
573 virtual bool haveFastClmul(IntegerType *Ty) const { return false; }
574
576 return true;
577 }
578
579 virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return true; }
580
581 virtual InstructionCost getFPOpCost(Type *Ty) const {
583 }
584
585 virtual InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
586 const APInt &Imm,
587 Type *Ty) const {
588 return 0;
589 }
590
591 virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
593 return TTI::TCC_Basic;
594 }
595
596 virtual InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
597 const APInt &Imm, Type *Ty,
599 Instruction *Inst = nullptr) const {
600 return TTI::TCC_Free;
601 }
602
603 virtual InstructionCost
604 getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
605 Type *Ty, TTI::TargetCostKind CostKind) const {
606 return TTI::TCC_Free;
607 }
608
610 const Function &Fn) const {
611 return false;
612 }
613
614 virtual unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
615 virtual bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
616 return false;
617 }
618
619 virtual unsigned getRegisterClassForType(bool Vector,
620 Type *Ty = nullptr) const {
621 return Vector ? 1 : 0;
622 }
623
624 virtual const char *getRegisterClassName(unsigned ClassID) const {
625 switch (ClassID) {
626 default:
627 return "Generic::Unknown Register Class";
628 case 0:
629 return "Generic::ScalarRC";
630 case 1:
631 return "Generic::VectorRC";
632 }
633 }
634
635 virtual InstructionCost
638 return TTI::TCC_Basic;
639 }
640
641 virtual InstructionCost
644 return TTI::TCC_Basic;
645 }
646
647 virtual TypeSize
651
652 virtual unsigned getMinVectorRegisterBitWidth() const { return 128; }
653
654 virtual std::optional<unsigned> getMaxVScale() const { return std::nullopt; }
655 virtual std::optional<unsigned> getVScaleForTuning() const {
656 return std::nullopt;
657 }
658
659 virtual bool
663
664 virtual ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const {
665 return ElementCount::get(0, IsScalable);
666 }
667
668 virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const {
669 return 0;
670 }
671 virtual unsigned getStoreMinimumVF(unsigned VF, Type *, Type *, Align,
672 unsigned) const {
673 return VF;
674 }
675
677 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
678 AllowPromotionWithoutCommonHeader = false;
679 return false;
680 }
681
682 virtual unsigned getCacheLineSize() const { return 0; }
683 virtual std::optional<unsigned>
685 switch (Level) {
687 [[fallthrough]];
689 return std::nullopt;
690 }
691 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
692 }
693
694 virtual std::optional<unsigned>
696 switch (Level) {
698 [[fallthrough]];
700 return std::nullopt;
701 }
702
703 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
704 }
705
706 virtual std::optional<unsigned> getMinPageSize() const { return {}; }
707
708 virtual unsigned getPrefetchDistance() const { return 0; }
709 virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses,
710 unsigned NumStridedMemAccesses,
711 unsigned NumPrefetches,
712 bool HasCall) const {
713 return 1;
714 }
715 virtual unsigned getMaxPrefetchIterationsAhead() const { return UINT_MAX; }
716 virtual bool enableWritePrefetching() const { return false; }
717 virtual bool shouldPrefetchAddressSpace(unsigned AS) const { return !AS; }
718
720 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
722 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
723 TTI::TargetCostKind CostKind, std::optional<FastMathFlags> FMF) const {
725 }
726
728 bool HasUnorderedReductions) const {
729 return 1;
730 }
731
733 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
735 ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) const {
736 // Widenable conditions will eventually lower into constants, so some
737 // operations with them will be trivially optimized away.
738 auto IsWidenableCondition = [](const Value *V) {
739 if (auto *II = dyn_cast<IntrinsicInst>(V))
740 if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
741 return true;
742 return false;
743 };
744 // FIXME: A number of transformation tests seem to require these values
745 // which seems a little odd for how arbitary there are.
746 switch (Opcode) {
747 default:
748 break;
749 case Instruction::FDiv:
750 case Instruction::FRem:
751 case Instruction::SDiv:
752 case Instruction::SRem:
753 case Instruction::UDiv:
754 case Instruction::URem:
755 // FIXME: Unlikely to be true for CodeSize.
756 return TTI::TCC_Expensive;
757 case Instruction::And:
758 case Instruction::Or:
759 if (any_of(Args, IsWidenableCondition))
760 return TTI::TCC_Free;
761 break;
762 }
763
764 // Assume a 3cy latency for fp arithmetic ops.
766 if (Ty->getScalarType()->isFloatingPointTy())
767 return 3;
768
769 return 1;
770 }
771
772 virtual InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0,
773 unsigned Opcode1,
774 const SmallBitVector &OpcodeMask,
777 }
778
779 virtual InstructionCost
782 VectorType *SubTp, ArrayRef<const Value *> Args = {},
783 const Instruction *CxtI = nullptr) const {
784 return 1;
785 }
786
787 virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst,
788 Type *Src, TTI::CastContextHint CCH,
790 const Instruction *I) const {
791 switch (Opcode) {
792 default:
793 break;
794 case Instruction::IntToPtr: {
795 unsigned SrcSize = Src->getScalarSizeInBits();
796 if (DL.isLegalInteger(SrcSize) &&
797 SrcSize <= DL.getPointerTypeSizeInBits(Dst))
798 return 0;
799 break;
800 }
801 case Instruction::PtrToAddr: {
802 unsigned DstSize = Dst->getScalarSizeInBits();
803 assert(DstSize == DL.getAddressSizeInBits(Src));
804 if (DL.isLegalInteger(DstSize))
805 return 0;
806 break;
807 }
808 case Instruction::PtrToInt: {
809 unsigned DstSize = Dst->getScalarSizeInBits();
810 if (DL.isLegalInteger(DstSize) &&
811 DstSize >= DL.getPointerTypeSizeInBits(Src))
812 return 0;
813 break;
814 }
815 case Instruction::BitCast:
816 if (Dst == Src || (Dst->isPointerTy() && Src->isPointerTy()))
817 // Identity and pointer-to-pointer casts are free.
818 return 0;
819 break;
820 case Instruction::Trunc: {
821 // trunc to a native type is free (assuming the target has compare and
822 // shift-right of the same width).
823 TypeSize DstSize = DL.getTypeSizeInBits(Dst);
824 if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedValue()))
825 return 0;
826 break;
827 }
828 }
829 return 1;
830 }
831
832 virtual InstructionCost
833 getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
834 unsigned Index, TTI::TargetCostKind CostKind) const {
835 return 1;
836 }
837
838 virtual InstructionCost getCFInstrCost(unsigned Opcode,
840 const Instruction *I = nullptr) const {
841 // A phi would be free, unless we're costing the throughput because it
842 // will require a register.
843 if (Opcode == Instruction::PHI && CostKind != TTI::TCK_RecipThroughput)
844 return 0;
845 return 1;
846 }
847
849 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
851 TTI::OperandValueInfo Op2Info, const Instruction *I) const {
852 return 1;
853 }
854
856 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
857 const Value *Op0, const Value *Op1,
859 return 1;
860 }
861
862 /// \param ScalarUserAndIdx encodes the information about extracts from a
863 /// vector with 'Scalar' being the value being extracted,'User' being the user
864 /// of the extract(nullptr if user is not known before vectorization) and
865 /// 'Idx' being the extract lane.
867 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
868 Value *Scalar,
869 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
871 return 1;
872 }
873
876 unsigned Index,
878 return 1;
879 }
880
881 virtual InstructionCost
884 unsigned Index) const {
885 return 1;
886 }
887
888 virtual InstructionCost
889 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
890 const APInt &DemandedDstElts,
892 return 1;
893 }
894
895 virtual InstructionCost
898 // Note: The `insertvalue` cost here is chosen to match the default case of
899 // getInstructionCost() -- as prior to adding this helper `insertvalue` was
900 // not handled.
901 if (Opcode == Instruction::InsertValue &&
903 return TTI::TCC_Basic;
904 return TTI::TCC_Free;
905 }
906
907 virtual InstructionCost
908 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
910 TTI::OperandValueInfo OpInfo, const Instruction *I) const {
911 return 1;
912 }
913
915 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
916 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
917 bool UseMaskForCond, bool UseMaskForGaps) const {
918 return 1;
919 }
920
921 virtual InstructionCost
924 switch (ICA.getID()) {
925 default:
926 break;
927 case Intrinsic::allow_runtime_check:
928 case Intrinsic::allow_ubsan_check:
929 case Intrinsic::annotation:
930 case Intrinsic::assume:
931 case Intrinsic::sideeffect:
932 case Intrinsic::pseudoprobe:
933 case Intrinsic::arithmetic_fence:
934 case Intrinsic::dbg_assign:
935 case Intrinsic::dbg_declare:
936 case Intrinsic::dbg_value:
937 case Intrinsic::dbg_label:
938 case Intrinsic::invariant_start:
939 case Intrinsic::invariant_end:
940 case Intrinsic::launder_invariant_group:
941 case Intrinsic::strip_invariant_group:
942 case Intrinsic::is_constant:
943 case Intrinsic::lifetime_start:
944 case Intrinsic::lifetime_end:
945 case Intrinsic::experimental_noalias_scope_decl:
946 case Intrinsic::objectsize:
947 case Intrinsic::ptr_annotation:
948 case Intrinsic::var_annotation:
949 case Intrinsic::experimental_gc_result:
950 case Intrinsic::experimental_gc_relocate:
951 case Intrinsic::coro_alloc:
952 case Intrinsic::coro_begin:
953 case Intrinsic::coro_begin_custom_abi:
954 case Intrinsic::coro_dead:
955 case Intrinsic::coro_id:
956 case Intrinsic::coro_id_async:
957 case Intrinsic::coro_id_retcon:
958 case Intrinsic::coro_id_retcon_once:
959 case Intrinsic::coro_noop:
960 case Intrinsic::coro_free:
961 case Intrinsic::coro_end:
962 case Intrinsic::coro_frame:
963 case Intrinsic::coro_size:
964 case Intrinsic::coro_align:
965 case Intrinsic::coro_suspend:
966 case Intrinsic::coro_subfn_addr:
967 case Intrinsic::threadlocal_address:
968 case Intrinsic::experimental_widenable_condition:
969 case Intrinsic::ssa_copy:
970 // These intrinsics don't actually represent code after lowering.
971 return 0;
972 case Intrinsic::bswap:
973 if (!ICA.getReturnType()->isVectorTy() &&
974 !isPowerOf2_64(DL.getTypeSizeInBits(ICA.getReturnType())))
976 }
977 return 1;
978 }
979
980 virtual InstructionCost
983 switch (MICA.getID()) {
984 case Intrinsic::masked_scatter:
985 case Intrinsic::masked_gather:
986 case Intrinsic::masked_load:
987 case Intrinsic::masked_store:
988 case Intrinsic::vp_scatter:
989 case Intrinsic::vp_gather:
990 case Intrinsic::masked_compressstore:
991 case Intrinsic::masked_expandload:
992 return 1;
993 }
995 }
996
1000 return 1;
1001 }
1002
1003 // Assume that we have a register of the right size for the type.
1004 virtual unsigned getNumberOfParts(Type *Tp) const { return 1; }
1005
1008 const SCEV *,
1009 TTI::TargetCostKind) const {
1010 return 0;
1011 }
1012
1013 virtual InstructionCost
1015 std::optional<FastMathFlags> FMF,
1016 TTI::TargetCostKind) const {
1017 return 1;
1018 }
1019
1022 TTI::TargetCostKind) const {
1023 return 1;
1024 }
1025
1026 virtual InstructionCost
1027 getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy,
1028 VectorType *Ty, std::optional<FastMathFlags> FMF,
1030 return 1;
1031 }
1032
1033 virtual InstructionCost
1034 getMulAccReductionCost(bool IsUnsigned, unsigned RedOpcode, Type *ResTy,
1036 return 1;
1037 }
1038
1039 virtual InstructionCost
1041 return 0;
1042 }
1043
1045 MemIntrinsicInfo &Info) const {
1046 return false;
1047 }
1048
1049 virtual unsigned getAtomicMemIntrinsicMaxElementSize() const {
1050 // Note for overrides: You must ensure for all element unordered-atomic
1051 // memory intrinsics that all power-of-2 element sizes up to, and
1052 // including, the return value of this method have a corresponding
1053 // runtime lib call. These runtime lib call definitions can be found
1054 // in RuntimeLibcalls.h
1055 return 0;
1056 }
1057
1058 virtual Value *
1060 bool CanCreate = true) const {
1061 return nullptr;
1062 }
1063
1064 virtual Type *
1066 unsigned SrcAddrSpace, unsigned DestAddrSpace,
1067 Align SrcAlign, Align DestAlign,
1068 std::optional<uint32_t> AtomicElementSize) const {
1069 return AtomicElementSize ? Type::getIntNTy(Context, *AtomicElementSize * 8)
1070 : Type::getInt8Ty(Context);
1071 }
1072
1074 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
1075 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
1076 Align SrcAlign, Align DestAlign,
1077 std::optional<uint32_t> AtomicCpySize) const {
1078 unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
1079 Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
1080 for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
1081 OpsOut.push_back(OpType);
1082 }
1083
1084 virtual bool areInlineCompatible(const Function *Caller,
1085 const Function *Callee) const {
1086 return (Caller->getFnAttribute("target-cpu") ==
1087 Callee->getFnAttribute("target-cpu")) &&
1088 (Caller->getFnAttribute("target-features") ==
1089 Callee->getFnAttribute("target-features"));
1090 }
1091
1092 virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
1093 unsigned DefaultCallPenalty) const {
1094 return DefaultCallPenalty;
1095 }
1096
1097 virtual bool
1099 const Attribute &Attr) const {
1100 // Copy attributes by default
1101 return true;
1102 }
1103
1104 virtual bool areTypesABICompatible(const Function *Caller,
1105 const Function *Callee,
1106 ArrayRef<Type *> Types) const {
1107 return (Caller->getFnAttribute("target-cpu") ==
1108 Callee->getFnAttribute("target-cpu")) &&
1109 (Caller->getFnAttribute("target-features") ==
1110 Callee->getFnAttribute("target-features"));
1111 }
1112
1114 return false;
1115 }
1116
1118 return false;
1119 }
1120
1121 virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const {
1122 return 128;
1123 }
1124
1125 virtual bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
1126
1127 virtual bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
1128
1129 virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
1130 Align Alignment,
1131 unsigned AddrSpace) const {
1132 return true;
1133 }
1134
1135 virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
1136 Align Alignment,
1137 unsigned AddrSpace) const {
1138 return true;
1139 }
1140
1142 ElementCount VF) const {
1143 return true;
1144 }
1145
1147 return true;
1148 }
1149
1150 virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
1151 unsigned ChainSizeInBytes,
1152 VectorType *VecTy) const {
1153 return VF;
1154 }
1155
1156 virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
1157 unsigned ChainSizeInBytes,
1158 VectorType *VecTy) const {
1159 return VF;
1160 }
1161
1162 virtual bool preferFixedOverScalableIfEqualCost() const { return false; }
1163
1164 virtual bool preferInLoopReduction(RecurKind Kind, Type *Ty) const {
1165 return false;
1166 }
1167 virtual bool preferAlternateOpcodeVectorization() const { return true; }
1168
1169 virtual bool preferSLPInstCountCheck() const { return true; }
1170
1171 virtual bool preferPredicatedReductionSelect() const { return false; }
1172
1173 virtual bool preferEpilogueVectorization(ElementCount Iters) const {
1174 // We consider epilogue vectorization unprofitable for targets that
1175 // don't consider interleaving beneficial (eg. MVE).
1176 return getMaxInterleaveFactor(Iters, false) > 1;
1177 }
1178
1179 virtual bool shouldConsiderVectorizationRegPressure() const { return false; }
1180
1181 virtual bool shouldExpandReduction(const IntrinsicInst *II) const {
1182 return true;
1183 }
1184
1185 virtual TTI::ReductionShuffle
1189
1190 virtual unsigned getGISelRematGlobalCost() const { return 1; }
1191
1192 virtual unsigned getMinTripCountTailFoldingThreshold() const { return 0; }
1193
1194 virtual bool supportsScalableVectors() const { return false; }
1195
1196 virtual bool enableScalableVectorization() const { return false; }
1197
1198 virtual bool hasActiveVectorLength() const { return false; }
1199
1201 SmallVectorImpl<Use *> &Ops) const {
1202 return false;
1203 }
1204
1205 virtual bool isVectorShiftByScalarCheap(Type *Ty) const { return false; }
1206
1213
1214 virtual bool hasArmWideBranch(bool) const { return false; }
1215
1216 virtual APInt getFeatureMask(const Function &F) const {
1217 return APInt::getZero(32);
1218 }
1219
1220 virtual APInt getPriorityMask(const Function &F) const {
1221 return APInt::getZero(32);
1222 }
1223
1224 virtual bool isMultiversionedFunction(const Function &F) const {
1225 return false;
1226 }
1227
1228 virtual unsigned getMaxNumArgs() const { return UINT_MAX; }
1229
1230 virtual unsigned getNumBytesToPadGlobalArray(unsigned Size,
1231 Type *ArrayType) const {
1232 return 0;
1233 }
1234
1236 const Function &F,
1237 SmallVectorImpl<std::pair<StringRef, int64_t>> &LB) const {}
1238
1239 virtual bool allowVectorElementIndexingUsingGEP() const { return true; }
1240
1241 virtual bool isUniform(const Instruction *I,
1242 const SmallBitVector &UniformArgs) const {
1243 llvm_unreachable("target must implement isUniform for Custom uniformity");
1244 }
1245
1246protected:
1247 // Obtain the minimum required size to hold the value (without the sign)
1248 // In case of a vector it returns the min required size for one element.
1249 unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const {
1251 const auto *VectorValue = cast<Constant>(Val);
1252
1253 // In case of a vector need to pick the max between the min
1254 // required size for each element
1255 auto *VT = cast<FixedVectorType>(Val->getType());
1256
1257 // Assume unsigned elements
1258 isSigned = false;
1259
1260 // The max required size is the size of the vector element type
1261 unsigned MaxRequiredSize =
1262 VT->getElementType()->getPrimitiveSizeInBits().getFixedValue();
1263
1264 unsigned MinRequiredSize = 0;
1265 for (unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
1266 if (auto *IntElement =
1267 dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
1268 bool signedElement = IntElement->getValue().isNegative();
1269 // Get the element min required size.
1270 unsigned ElementMinRequiredSize =
1271 IntElement->getValue().getSignificantBits() - 1;
1272 // In case one element is signed then all the vector is signed.
1273 isSigned |= signedElement;
1274 // Save the max required bit size between all the elements.
1275 MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
1276 } else {
1277 // not an int constant element
1278 return MaxRequiredSize;
1279 }
1280 }
1281 return MinRequiredSize;
1282 }
1283
1284 if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
1285 isSigned = CI->getValue().isNegative();
1286 return CI->getValue().getSignificantBits() - 1;
1287 }
1288
1289 if (const auto *Cast = dyn_cast<SExtInst>(Val)) {
1290 isSigned = true;
1291 return Cast->getSrcTy()->getScalarSizeInBits() - 1;
1292 }
1293
1294 if (const auto *Cast = dyn_cast<ZExtInst>(Val)) {
1295 isSigned = false;
1296 return Cast->getSrcTy()->getScalarSizeInBits();
1297 }
1298
1299 isSigned = false;
1300 return Val->getType()->getScalarSizeInBits();
1301 }
1302
1303 bool isStridedAccess(const SCEV *Ptr) const {
1304 return Ptr && isa<SCEVAddRecExpr>(Ptr);
1305 }
1306
1308 const SCEV *Ptr) const {
1309 if (!isStridedAccess(Ptr))
1310 return nullptr;
1311 const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
1312 return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
1313 }
1314
1316 int64_t MergeDistance) const {
1317 const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
1318 if (!Step)
1319 return false;
1320 APInt StrideVal = Step->getAPInt();
1321 if (StrideVal.getBitWidth() > 64)
1322 return false;
1323 // FIXME: Need to take absolute value for negative stride case.
1324 return StrideVal.getSExtValue() < MergeDistance;
1325 }
1326};
1327
1328/// CRTP base class for use as a mix-in that aids implementing
1329/// a TargetTransformInfo-compatible class.
1330template <typename T>
1332private:
1333 typedef TargetTransformInfoImplBase BaseT;
1334
1335protected:
1337
1338public:
1339 InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
1341 TTI::TargetCostKind CostKind) const override {
1342 assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
1343 auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
1344 bool HasBaseReg = (BaseGV == nullptr);
1345
1346 auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
1347 APInt BaseOffset(PtrSizeBits, 0);
1348 int64_t Scale = 0;
1349
1350 auto GTI = gep_type_begin(PointeeType, Operands);
1351 Type *TargetType = nullptr;
1352
1353 // Handle the case where the GEP instruction has a single operand,
1354 // the basis, therefore TargetType is a nullptr.
1355 if (Operands.empty())
1356 return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
1357
1358 for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
1359 TargetType = GTI.getIndexedType();
1360 // We assume that the cost of Scalar GEP with constant index and the
1361 // cost of Vector GEP with splat constant index are the same.
1362 const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
1363 if (!ConstIdx)
1364 if (auto Splat = getSplatValue(*I))
1365 ConstIdx = dyn_cast<ConstantInt>(Splat);
1366 if (StructType *STy = GTI.getStructTypeOrNull()) {
1367 // For structures the index is always splat or scalar constant
1368 assert(ConstIdx && "Unexpected GEP index");
1369 uint64_t Field = ConstIdx->getZExtValue();
1370 BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
1371 } else {
1372 // If this operand is a scalable type, bail out early.
1373 // TODO: Make isLegalAddressingMode TypeSize aware.
1374 if (TargetType->isScalableTy())
1375 return TTI::TCC_Basic;
1376 int64_t ElementSize =
1377 GTI.getSequentialElementStride(DL).getFixedValue();
1378 if (ConstIdx) {
1379 BaseOffset +=
1380 ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
1381 } else {
1382 // Needs scale register.
1383 if (Scale != 0)
1384 // No addressing mode takes two scale registers.
1385 return TTI::TCC_Basic;
1386 Scale = ElementSize;
1387 }
1388 }
1389 }
1390
1391 // If we haven't been provided a hint, use the target type for now.
1392 //
1393 // TODO: Take a look at potentially removing this: This is *slightly* wrong
1394 // as it's possible to have a GEP with a foldable target type but a memory
1395 // access that isn't foldable. For example, this load isn't foldable on
1396 // RISC-V:
1397 //
1398 // %p = getelementptr i32, ptr %base, i32 42
1399 // %x = load <2 x i32>, ptr %p
1400 if (!AccessType)
1401 AccessType = TargetType;
1402
1403 // If the final address of the GEP is a legal addressing mode for the given
1404 // access type, then we can fold it into its users.
1405 if (static_cast<const T *>(this)->isLegalAddressingMode(
1406 AccessType, const_cast<GlobalValue *>(BaseGV),
1407 BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
1409 return TTI::TCC_Free;
1410
1411 // TODO: Instead of returning TCC_Basic here, we should use
1412 // getArithmeticInstrCost. Or better yet, provide a hook to let the target
1413 // model it.
1414 return TTI::TCC_Basic;
1415 }
1416
1419 const TTI::PointersChainInfo &Info, Type *AccessTy,
1420 TTI::TargetCostKind CostKind) const override {
1422 // In the basic model we take into account GEP instructions only
1423 // (although here can come alloca instruction, a value, constants and/or
1424 // constant expressions, PHIs, bitcasts ... whatever allowed to be used as a
1425 // pointer). Typically, if Base is a not a GEP-instruction and all the
1426 // pointers are relative to the same base address, all the rest are
1427 // either GEP instructions, PHIs, bitcasts or constants. When we have same
1428 // base, we just calculate cost of each non-Base GEP as an ADD operation if
1429 // any their index is a non-const.
1430 // If no known dependecies between the pointers cost is calculated as a sum
1431 // of costs of GEP instructions.
1432 for (const Value *V : Ptrs) {
1433 const auto *GEP = dyn_cast<GetElementPtrInst>(V);
1434 if (!GEP)
1435 continue;
1436 if (Info.isSameBase() && V != Base) {
1437 if (GEP->hasAllConstantIndices())
1438 continue;
1439 Cost += static_cast<const T *>(this)->getArithmeticInstrCost(
1440 Instruction::Add, GEP->getType(), CostKind,
1441 {TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None},
1442 {});
1443 } else {
1444 SmallVector<const Value *> Indices(GEP->indices());
1445 Cost += static_cast<const T *>(this)->getGEPCost(
1446 GEP->getSourceElementType(), GEP->getPointerOperand(), Indices,
1447 AccessTy, CostKind);
1448 }
1449 }
1450 return Cost;
1451 }
1452
1455 TTI::TargetCostKind CostKind) const override {
1456 using namespace llvm::PatternMatch;
1457
1458 auto *TargetTTI = static_cast<const T *>(this);
1459 // Handle non-intrinsic calls, invokes, and callbr.
1460 // FIXME: Unlikely to be true for anything but CodeSize.
1461 auto *CB = dyn_cast<CallBase>(U);
1462 if (CB && !isa<IntrinsicInst>(U)) {
1463 if (const Function *F = CB->getCalledFunction()) {
1464 if (!TargetTTI->isLoweredToCall(F))
1465 return TTI::TCC_Basic; // Give a basic cost if it will be lowered
1466
1467 return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
1468 }
1469 // For indirect or other calls, scale cost by number of arguments.
1470 return TTI::TCC_Basic * (CB->arg_size() + 1);
1471 }
1472
1473 Type *Ty = U->getType();
1474 unsigned Opcode = Operator::getOpcode(U);
1475 auto *I = dyn_cast<Instruction>(U);
1476 switch (Opcode) {
1477 default:
1478 break;
1479 case Instruction::Call: {
1480 assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
1481 auto *Intrinsic = cast<IntrinsicInst>(U);
1482 IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
1483 return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
1484 }
1485 case Instruction::UncondBr:
1486 case Instruction::CondBr:
1487 case Instruction::Ret:
1488 case Instruction::PHI:
1489 case Instruction::Switch:
1490 return TargetTTI->getCFInstrCost(Opcode, CostKind, I);
1491 case Instruction::Freeze:
1492 return TTI::TCC_Free;
1493 case Instruction::ExtractValue:
1494 case Instruction::InsertValue:
1495 return TargetTTI->getInsertExtractValueCost(Opcode, CostKind);
1496 case Instruction::Alloca:
1497 if (cast<AllocaInst>(U)->isStaticAlloca())
1498 return TTI::TCC_Free;
1499 break;
1500 case Instruction::GetElementPtr: {
1501 const auto *GEP = cast<GEPOperator>(U);
1502 Type *AccessType = nullptr;
1503 // For now, only provide the AccessType in the simple case where the GEP
1504 // only has one user.
1505 if (GEP->hasOneUser() && I)
1506 AccessType = I->user_back()->getAccessType();
1507
1508 return TargetTTI->getGEPCost(GEP->getSourceElementType(),
1509 Operands.front(), Operands.drop_front(),
1510 AccessType, CostKind);
1511 }
1512 case Instruction::Add:
1513 case Instruction::FAdd:
1514 case Instruction::Sub:
1515 case Instruction::FSub:
1516 case Instruction::Mul:
1517 case Instruction::FMul:
1518 case Instruction::UDiv:
1519 case Instruction::SDiv:
1520 case Instruction::FDiv:
1521 case Instruction::URem:
1522 case Instruction::SRem:
1523 case Instruction::FRem:
1524 case Instruction::Shl:
1525 case Instruction::LShr:
1526 case Instruction::AShr:
1527 case Instruction::And:
1528 case Instruction::Or:
1529 case Instruction::Xor:
1530 case Instruction::FNeg: {
1532 TTI::OperandValueInfo Op2Info;
1533 if (Opcode != Instruction::FNeg)
1534 Op2Info = TTI::getOperandInfo(Operands[1]);
1535 return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
1536 Op2Info, Operands, I);
1537 }
1538 case Instruction::IntToPtr:
1539 case Instruction::PtrToAddr:
1540 case Instruction::PtrToInt:
1541 case Instruction::SIToFP:
1542 case Instruction::UIToFP:
1543 case Instruction::FPToUI:
1544 case Instruction::FPToSI:
1545 case Instruction::Trunc:
1546 case Instruction::FPTrunc:
1547 case Instruction::BitCast:
1548 case Instruction::FPExt:
1549 case Instruction::SExt:
1550 case Instruction::ZExt:
1551 case Instruction::AddrSpaceCast: {
1552 Type *OpTy = Operands[0]->getType();
1553 return TargetTTI->getCastInstrCost(
1554 Opcode, Ty, OpTy, TTI::getCastContextHint(I), CostKind, I);
1555 }
1556 case Instruction::Store: {
1557 auto *SI = cast<StoreInst>(U);
1558 Type *ValTy = Operands[0]->getType();
1560 return TargetTTI->getMemoryOpCost(Opcode, ValTy, SI->getAlign(),
1561 SI->getPointerAddressSpace(), CostKind,
1562 OpInfo, I);
1563 }
1564 case Instruction::Load: {
1565 auto *LI = cast<LoadInst>(U);
1566 Type *LoadType = U->getType();
1567 // If there is a non-register sized type, the cost estimation may expand
1568 // it to be several instructions to load into multiple registers on the
1569 // target. But, if the only use of the load is a trunc instruction to a
1570 // register sized type, the instruction selector can combine these
1571 // instructions to be a single load. So, in this case, we use the
1572 // destination type of the trunc instruction rather than the load to
1573 // accurately estimate the cost of this load instruction.
1574 if (CostKind == TTI::TCK_CodeSize && LI->hasOneUse() &&
1575 !LoadType->isVectorTy()) {
1576 if (const TruncInst *TI = dyn_cast<TruncInst>(*LI->user_begin()))
1577 LoadType = TI->getDestTy();
1578 }
1579 return TargetTTI->getMemoryOpCost(Opcode, LoadType, LI->getAlign(),
1581 {TTI::OK_AnyValue, TTI::OP_None}, I);
1582 }
1583 case Instruction::Select: {
1584 const Value *Op0, *Op1;
1585 if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
1586 match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
1587 // select x, y, false --> x & y
1588 // select x, true, y --> x | y
1589 const auto Op1Info = TTI::getOperandInfo(Op0);
1590 const auto Op2Info = TTI::getOperandInfo(Op1);
1591 assert(Op0->getType()->getScalarSizeInBits() == 1 &&
1592 Op1->getType()->getScalarSizeInBits() == 1);
1593
1595 return TargetTTI->getArithmeticInstrCost(
1596 match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
1597 CostKind, Op1Info, Op2Info, Operands, I);
1598 }
1599 const auto Op1Info = TTI::getOperandInfo(Operands[1]);
1600 const auto Op2Info = TTI::getOperandInfo(Operands[2]);
1601 Type *CondTy = Operands[0]->getType();
1602 return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,
1604 CostKind, Op1Info, Op2Info, I);
1605 }
1606 case Instruction::ICmp:
1607 case Instruction::FCmp: {
1608 const auto Op1Info = TTI::getOperandInfo(Operands[0]);
1609 const auto Op2Info = TTI::getOperandInfo(Operands[1]);
1610 Type *ValTy = Operands[0]->getType();
1611 // TODO: Also handle ICmp/FCmp constant expressions.
1612 return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(),
1613 I ? cast<CmpInst>(I)->getPredicate()
1615 CostKind, Op1Info, Op2Info, I);
1616 }
1617 case Instruction::InsertElement: {
1618 auto *IE = dyn_cast<InsertElementInst>(U);
1619 if (!IE)
1620 return TTI::TCC_Basic; // FIXME
1621 unsigned Idx = -1;
1622 if (auto *CI = dyn_cast<ConstantInt>(Operands[2]))
1623 if (CI->getValue().getActiveBits() <= 32)
1624 Idx = CI->getZExtValue();
1625 return TargetTTI->getVectorInstrCost(*IE, Ty, CostKind, Idx,
1627 }
1628 case Instruction::ShuffleVector: {
1629 auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
1630 if (!Shuffle)
1631 return TTI::TCC_Basic; // FIXME
1632
1633 auto *VecTy = cast<VectorType>(U->getType());
1634 auto *VecSrcTy = cast<VectorType>(Operands[0]->getType());
1635 ArrayRef<int> Mask = Shuffle->getShuffleMask();
1636 int NumSubElts, SubIndex;
1637
1638 // Treat undef/poison mask as free (no matter the length).
1639 if (all_of(Mask, [](int M) { return M < 0; }))
1640 return TTI::TCC_Free;
1641
1642 // TODO: move more of this inside improveShuffleKindFromMask.
1643 if (Shuffle->changesLength()) {
1644 // Treat a 'subvector widening' as a free shuffle.
1645 if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding())
1646 return TTI::TCC_Free;
1647
1648 if (Shuffle->isExtractSubvectorMask(SubIndex))
1649 return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecTy,
1650 VecSrcTy, Mask, CostKind, SubIndex,
1651 VecTy, Operands, Shuffle);
1652
1653 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1654 return TargetTTI->getShuffleCost(
1655 TTI::SK_InsertSubvector, VecTy, VecSrcTy, Mask, CostKind,
1656 SubIndex,
1657 FixedVectorType::get(VecTy->getScalarType(), NumSubElts),
1658 Operands, Shuffle);
1659
1660 int ReplicationFactor, VF;
1661 if (Shuffle->isReplicationMask(ReplicationFactor, VF)) {
1662 APInt DemandedDstElts = APInt::getZero(Mask.size());
1663 for (auto I : enumerate(Mask)) {
1664 if (I.value() != PoisonMaskElem)
1665 DemandedDstElts.setBit(I.index());
1666 }
1667 return TargetTTI->getReplicationShuffleCost(
1668 VecSrcTy->getElementType(), ReplicationFactor, VF,
1669 DemandedDstElts, CostKind);
1670 }
1671
1672 bool IsUnary = isa<UndefValue>(Operands[1]);
1673 NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
1674 SmallVector<int, 16> AdjustMask(Mask);
1675
1676 // Widening shuffle - widening the source(s) to the new length
1677 // (treated as free - see above), and then perform the adjusted
1678 // shuffle at that width.
1679 if (Shuffle->increasesLength()) {
1680 for (int &M : AdjustMask)
1681 M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
1682
1683 return TargetTTI->getShuffleCost(
1685 VecTy, AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1686 }
1687
1688 // Narrowing shuffle - perform shuffle at original wider width and
1689 // then extract the lower elements.
1690 // FIXME: This can assume widening, which is not true of all vector
1691 // architectures (and is not even the default).
1692 AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
1693
1694 InstructionCost ShuffleCost = TargetTTI->getShuffleCost(
1696 VecSrcTy, VecSrcTy, AdjustMask, CostKind, 0, nullptr, Operands,
1697 Shuffle);
1698
1699 SmallVector<int, 16> ExtractMask(Mask.size());
1700 std::iota(ExtractMask.begin(), ExtractMask.end(), 0);
1701 return ShuffleCost + TargetTTI->getShuffleCost(
1702 TTI::SK_ExtractSubvector, VecTy, VecSrcTy,
1703 ExtractMask, CostKind, 0, VecTy, {}, Shuffle);
1704 }
1705
1706 if (Shuffle->isIdentity())
1707 return TTI::TCC_Free;
1708
1709 if (Shuffle->isReverse())
1710 return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, VecSrcTy, Mask,
1711 CostKind, 0, nullptr, Operands,
1712 Shuffle);
1713
1714 if (Shuffle->isTranspose())
1715 return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, VecSrcTy,
1716 Mask, CostKind, 0, nullptr, Operands,
1717 Shuffle);
1718
1719 if (Shuffle->isZeroEltSplat())
1720 return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, VecSrcTy,
1721 Mask, CostKind, 0, nullptr, Operands,
1722 Shuffle);
1723
1724 if (Shuffle->isSingleSource())
1725 return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy,
1726 VecSrcTy, Mask, CostKind, 0, nullptr,
1727 Operands, Shuffle);
1728
1729 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1730 return TargetTTI->getShuffleCost(
1731 TTI::SK_InsertSubvector, VecTy, VecSrcTy, Mask, CostKind, SubIndex,
1732 FixedVectorType::get(VecTy->getScalarType(), NumSubElts), Operands,
1733 Shuffle);
1734
1735 if (Shuffle->isSelect())
1736 return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, VecSrcTy, Mask,
1737 CostKind, 0, nullptr, Operands,
1738 Shuffle);
1739
1740 if (Shuffle->isSplice(SubIndex))
1741 return TargetTTI->getShuffleCost(TTI::SK_Splice, VecTy, VecSrcTy, Mask,
1742 CostKind, SubIndex, nullptr, Operands,
1743 Shuffle);
1744
1745 return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, VecSrcTy,
1746 Mask, CostKind, 0, nullptr, Operands,
1747 Shuffle);
1748 }
1749 case Instruction::ExtractElement: {
1750 auto *EEI = dyn_cast<ExtractElementInst>(U);
1751 if (!EEI)
1752 return TTI::TCC_Basic; // FIXME
1753 unsigned Idx = -1;
1754 if (auto *CI = dyn_cast<ConstantInt>(Operands[1]))
1755 if (CI->getValue().getActiveBits() <= 32)
1756 Idx = CI->getZExtValue();
1757 Type *DstTy = Operands[0]->getType();
1758 return TargetTTI->getVectorInstrCost(*EEI, DstTy, CostKind, Idx);
1759 }
1760 }
1761
1762 // By default, just classify everything remaining as 'basic'.
1763 return TTI::TCC_Basic;
1764 }
1765
1767 auto *TargetTTI = static_cast<const T *>(this);
1768 SmallVector<const Value *, 4> Ops(I->operand_values());
1769 InstructionCost Cost = TargetTTI->getInstructionCost(
1772 }
1773
1774 bool supportsTailCallFor(const CallBase *CB) const override {
1775 return static_cast<const T *>(this)->supportsTailCalls();
1776 }
1777};
1778} // namespace llvm
1779
1780#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:215
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
static bool isSigned(unsigned Opcode)
Hexagon Common GEP
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
uint64_t IntrinsicInst * II
OptimizedStructLayoutField Field
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
SI Fold Operands
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
This pass exposes codegen information to IR-level passes.
static void computeKnownBits(const Value *V, const APInt &DemandedElts, KnownBits &Known, const SimplifyQuery &Q, unsigned Depth)
Determine which bits of V are known to be either zero or one and return them in the Known bit set.
Class for arbitrary precision integers.
Definition APInt.h:78
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition APInt.h:1355
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1513
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition APInt.cpp:1084
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:201
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1587
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Class to represent array types.
A cache of @llvm.assume calls within a function.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
Conditional Branch instruction.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:168
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition Constants.h:159
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition TypeSize.h:315
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:867
The core instruction combiner logic.
static InstructionCost getInvalid(CostType Val=0)
Class to represent integer types.
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Information for memory intrinsic cost model.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition Operator.h:43
The optimization diagnostic interface.
Analysis providing profile information.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
This node represents a polynomial recurrence on the trip count of the specified loop.
SCEVUse getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
This class represents a constant integer value.
const APInt & getAPInt() const
This class represents an analyzed expression in the program.
The main scalar evolution driver.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
static StackOffset getScalable(int64_t Scalable)
Definition TypeSize.h:40
static StackOffset getFixed(int64_t Fixed)
Definition TypeSize.h:39
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
Multiway switch.
Provides information about what library functions are available for the current target.
virtual InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, TTI::TargetCostKind CostKind) const
virtual bool preferAlternateOpcodeVectorization() const
virtual bool isProfitableLSRChainElement(Instruction *I) const
virtual unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const
virtual unsigned getMinimumLookupTableEntryBitWidth() const
virtual bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
virtual InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
virtual TailFoldingStyle getPreferredTailFoldingStyle() const
virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const
virtual bool haveFastClmul(IntegerType *Ty) const
virtual bool preferFixedOverScalableIfEqualCost() const
virtual InstructionCost getMulAccReductionCost(bool IsUnsigned, unsigned RedOpcode, Type *ResTy, VectorType *Ty, TTI::TargetCostKind CostKind) const
virtual const DataLayout & getDataLayout() const
virtual std::optional< unsigned > getCacheAssociativity(TargetTransformInfo::CacheLevel Level) const
virtual InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const
virtual bool enableInterleavedAccessVectorization() const
virtual InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const
virtual InstructionCost getOperandsScalarizationOverhead(ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
virtual InstructionCost getFPOpCost(Type *Ty) const
virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const
virtual TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
bool isStridedAccess(const SCEV *Ptr) const
virtual unsigned getAtomicMemIntrinsicMaxElementSize() const
virtual Value * rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
virtual TargetTransformInfo::VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
virtual bool enableAggressiveInterleaving(bool LoopHasReductions) const
virtual std::optional< Value * > simplifyDemandedVectorEltsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3, std::function< void(Instruction *, unsigned, APInt, APInt &)> SimplifyAndSetOp) const
virtual bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind) const
virtual InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *, const SCEV *, TTI::TargetCostKind) const
virtual bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const
virtual bool isIndexedLoadLegal(TTI::MemIndexedMode Mode, Type *Ty) const
virtual unsigned adjustInliningThreshold(const CallBase *CB) const
virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
virtual bool shouldDropLSRSolutionIfLessProfitable() const
virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const
virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind) const
virtual bool hasDivRemOp(Type *DataType, bool IsSigned) const
virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const
virtual bool isLegalICmpImmediate(int64_t Imm) const
virtual InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo, const Instruction *I) const
virtual bool haveFastSqrt(Type *Ty) const
virtual ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const
virtual bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const
virtual unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
virtual std::optional< unsigned > getVScaleForTuning() const
virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
virtual InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const
virtual unsigned getNumberOfParts(Type *Tp) const
virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const
virtual bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const
virtual void getPeelingPreferences(Loop *, ScalarEvolution &, TTI::PeelingPreferences &) const
virtual std::optional< Value * > simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed) const
virtual bool useColdCCForColdCall(Function &F) const
virtual unsigned getNumberOfRegisters(unsigned ClassID) const
virtual bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const
virtual APInt getAddrSpaceCastPreservedPtrMask(unsigned SrcAS, unsigned DstAS) const
virtual bool isLegalAddScalableImmediate(int64_t Imm) const
virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace) const
virtual bool preferTailFoldingOverEpilogue(TailFoldingInfo *TFI) const
TargetTransformInfoImplBase(TargetTransformInfoImplBase &&Arg)
virtual bool shouldPrefetchAddressSpace(unsigned AS) const
virtual bool forceScalarizeMaskedScatter(VectorType *DataType, Align Alignment) const
virtual uint64_t getMaxMemIntrinsicInlineSizeThreshold() const
virtual KnownBits computeKnownBitsAddrSpaceCast(unsigned FromAS, unsigned ToAS, const KnownBits &FromPtrBits) const
virtual unsigned getMinVectorRegisterBitWidth() const
unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const
virtual bool shouldBuildLookupTablesForConstant(Constant *C) const
virtual bool isFPVectorizationPotentiallyUnsafe() const
virtual bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const
virtual InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const
virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask) const
virtual InstructionCost getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const
virtual std::optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const
virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index, TTI::TargetCostKind CostKind) const
virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) const
virtual std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const
virtual unsigned getEpilogueVectorizationMinVF() const
virtual std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const
virtual bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const
virtual void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type * > &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicCpySize) const
virtual unsigned getStoreMinimumVF(unsigned VF, Type *, Type *, Align, unsigned) const
virtual InstructionCost getRegisterClassReloadCost(unsigned ClassID, TTI::TargetCostKind CostKind) const
virtual TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
virtual TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const
virtual bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment) const
virtual unsigned getMaxPrefetchIterationsAhead() const
virtual bool allowVectorElementIndexingUsingGEP() const
virtual bool isUniform(const Instruction *I, const SmallBitVector &UniformArgs) const
virtual InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const
virtual TTI::ReductionShuffle getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const
const SCEVConstant * getConstantStrideStep(ScalarEvolution *SE, const SCEV *Ptr) const
virtual bool hasBranchDivergence(const Function *F=nullptr) const
virtual InstructionCost getArithmeticReductionCost(unsigned, VectorType *, std::optional< FastMathFlags > FMF, TTI::TargetCostKind) const
virtual bool isProfitableToHoist(Instruction *I) const
virtual const char * getRegisterClassName(unsigned ClassID) const
virtual InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *, FastMathFlags, TTI::TargetCostKind) const
virtual bool isLegalToVectorizeLoad(LoadInst *LI) const
virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
virtual InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, TTI::TargetCostKind CostKind) const
virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call, unsigned DefaultCallPenalty) const
virtual unsigned getMaxInterleaveFactor(ElementCount VF, bool HasUnorderedReductions) const
virtual InstructionCost getVectorInstrCost(const Instruction &I, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
virtual bool isVectorShiftByScalarCheap(Type *Ty) const
virtual bool isLegalNTStore(Type *DataType, Align Alignment) const
virtual APInt getFeatureMask(const Function &F) const
virtual InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
virtual std::optional< unsigned > getMinPageSize() const
virtual bool shouldCopyAttributeWhenOutliningFrom(const Function *Caller, const Attribute &Attr) const
virtual unsigned getRegUsageForType(Type *Ty) const
virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I=nullptr, int64_t ScalableOffset=0) const
virtual InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
virtual bool isElementTypeLegalForScalableVector(Type *Ty) const
virtual bool isLoweredToCall(const Function *F) const
virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) const
virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
virtual InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CxtI=nullptr) const
virtual InstructionCost getRegisterClassSpillCost(unsigned ClassID, TTI::TargetCostKind CostKind) const
virtual bool isIndexedStoreLegal(TTI::MemIndexedMode Mode, Type *Ty) const
virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, TTI::TargetCostKind CostKind) const
virtual BranchProbability getPredictableBranchThreshold() const
virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
virtual InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind) const
virtual bool isLegalToVectorizeStore(StoreInst *SI) const
virtual bool areInlineCompatible(const Function *Caller, const Function *Callee) const
virtual bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx) const
virtual bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const
virtual bool canSaveCmp(Loop *L, CondBrInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const
virtual bool preferInLoopReduction(RecurKind Kind, Type *Ty) const
virtual bool isMultiversionedFunction(const Function &F) const
virtual InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const
virtual bool isNoopAddrSpaceCast(unsigned, unsigned) const
virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I) const
virtual bool isLSRCostLess(const TTI::LSRCost &C1, const TTI::LSRCost &C2) const
virtual bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const
virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) const
virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
virtual bool isLegalAddImmediate(int64_t Imm) const
virtual InstructionCost getInsertExtractValueCost(unsigned Opcode, TTI::TargetCostKind CostKind) const
virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I) const
virtual ValueUniformity getValueUniformity(const Value *V) const
virtual bool isLegalNTLoad(Type *DataType, Align Alignment) const
virtual InstructionCost getBranchMispredictPenalty() const
virtual bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx) const
virtual InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
virtual InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty) const
bool isConstantStridedAccessLessThan(ScalarEvolution *SE, const SCEV *Ptr, int64_t MergeDistance) const
virtual Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType, bool CanCreate=true) const
virtual bool enableMaskedInterleavedAccessVectorization() const
virtual std::pair< KnownBits, KnownBits > computeKnownBitsAddrSpaceCast(unsigned ToAS, const Value &PtrOp) const
virtual Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicElementSize) const
virtual unsigned getInliningThresholdMultiplier() const
TargetTransformInfoImplBase(const DataLayout &DL)
virtual InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const
virtual InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info, const Instruction *I) const
virtual bool shouldExpandReduction(const IntrinsicInst *II) const
virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
virtual unsigned getGISelRematGlobalCost() const
virtual InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond, bool UseMaskForGaps) const
virtual bool isTypeLegal(Type *Ty) const
virtual unsigned getAssumedAddrSpace(const Value *V) const
virtual bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace, Align Alignment, unsigned *Fast) const
virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
virtual InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const
virtual unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const
virtual bool areTypesABICompatible(const Function *Caller, const Function *Callee, ArrayRef< Type * > Types) const
virtual unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const
virtual bool preferToKeepConstantsAttached(const Instruction &Inst, const Function &Fn) const
virtual InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const
virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const
virtual bool supportsTailCallFor(const CallBase *CB) const
virtual std::optional< unsigned > getMaxVScale() const
virtual bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
virtual bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx) const
virtual bool shouldConsiderVectorizationRegPressure() const
virtual InstructionCost getMemcpyCost(const Instruction *I) const
virtual unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const
virtual bool useFastCCForInternalCall(Function &F) const
virtual bool preferEpilogueVectorization(ElementCount Iters) const
virtual void getUnrollingPreferences(Loop *, ScalarEvolution &, TTI::UnrollingPreferences &, OptimizationRemarkEmitter *) const
TargetTransformInfoImplBase(const TargetTransformInfoImplBase &Arg)=default
virtual bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const
virtual bool supportsEfficientVectorElementLoadStore() const
virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const
virtual APInt getPriorityMask(const Function &F) const
virtual unsigned getMinTripCountTailFoldingThreshold() const
virtual TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const
virtual void collectKernelLaunchBounds(const Function &F, SmallVectorImpl< std::pair< StringRef, int64_t > > &LB) const
bool supportsTailCallFor(const CallBase *CB) const override
bool isExpensiveToSpeculativelyExecute(const Instruction *I) const override
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const override
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, TTI::TargetCostKind CostKind) const override
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, TTI::TargetCostKind CostKind) const override
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
static LLVM_ABI CastContextHint getCastContextHint(const Instruction *I)
Calculates a CastContextHint from I.
MaskKind
Some targets only support masked load/store with a constant mask.
static LLVM_ABI OperandValueInfo getOperandInfo(const Value *V)
Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
TargetCostKind
The kind of cost model.
@ TCK_RecipThroughput
Reciprocal throughput.
@ TCK_CodeSize
Instruction code size.
@ TCK_SizeAndLatency
The weighted sum of size and latency.
@ TCK_Latency
The latency of instruction.
PopcntSupportKind
Flags indicating the kind of support for population count.
llvm::VectorInstrContext VectorInstrContext
@ TCC_Expensive
The cost of a 'div' instruction on x86.
@ TCC_Free
Expected to fold away in lowering.
@ TCC_Basic
The cost of a typical 'add' instruction.
MemIndexedMode
The type of load/store indexing.
AddressingModeKind
Which addressing mode Loop Strength Reduction will try to generate.
@ AMK_None
Don't prefer any addressing mode.
static LLVM_ABI VectorInstrContext getVectorInstrContextHint(const Instruction *I)
Calculates a VectorInstrContext from I.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
@ SK_InsertSubvector
InsertSubvector. Index indicates start offset.
@ SK_Select
Selects elements from the corresponding lane of either source operand.
@ SK_PermuteSingleSrc
Shuffle elements of single source vector with any shuffle mask.
@ SK_Transpose
Transpose two vectors.
@ SK_Splice
Concatenates elements from the first input vector with elements of the second input vector.
@ SK_Broadcast
Broadcast element 0 to all other elements.
@ SK_PermuteTwoSrc
Merge elements from two source vectors into one with any shuffle mask.
@ SK_Reverse
Reverse the order of the vector.
@ SK_ExtractSubvector
ExtractSubvector Index indicates start offset.
CastContextHint
Represents a hint about the context in which a cast is used.
@ None
The cast is not used with a load/store of any kind.
CacheLevel
The possible cache levels.
This class represents a truncation of integer types.
static constexpr TypeSize get(ScalarTy Quantity, bool Scalable)
Definition TypeSize.h:340
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:288
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
Definition Type.cpp:61
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:307
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:232
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:285
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:313
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:713
Base class of all SIMD vector types.
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
LogicalOp_match< LHS, RHS, Instruction::And > m_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R either in the form of L & R or L ?
bool match(Val *V, const Pattern &P)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Constant()
Match an arbitrary Constant and ignore it.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
LogicalOp_match< LHS, RHS, Instruction::Or > m_LogicalOr(const LHS &L, const RHS &R)
Matches L || R either in the form of L | R or L ?
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:578
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
InstructionCost Cost
@ Known
Known to have no common set bits.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr int PoisonMaskElem
RecurKind
These are the kinds of recurrences that we support.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
gep_type_iterator gep_type_begin(const User *GEP)
@ DataWithoutLaneMask
Same as Data, but avoids using the get.active.lane.mask intrinsic to calculate the mask and instead i...
ValueUniformity
Enum describing how values behave with respect to uniformity and divergence, to answer the question: ...
Definition Uniformity.h:18
@ Default
The result value is uniform if and only if all operands are uniform.
Definition Uniformity.h:20
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Attributes of a target dependent hardware loop.
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition KnownBits.h:190
Information about a load/store intrinsic defined by the target.
Returns options for expansion of memcmp. IsZeroCmp is.
Describe known properties for a set of pointers.
Parameters that control the generic loop unrolling transformation.