LLVM 23.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
88 llvm_unreachable("Not implemented");
89 }
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
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
196 virtual bool
198 return AS == 0;
199 };
200
201 virtual unsigned getAssumedAddrSpace(const Value *V) const { return -1; }
202
203 virtual bool isSingleThreaded() const { return false; }
204
205 virtual std::pair<const Value *, unsigned>
207 return std::make_pair(nullptr, -1);
208 }
209
211 Value *OldV,
212 Value *NewV) const {
213 return nullptr;
214 }
215
216 virtual bool isLoweredToCall(const Function *F) const {
217 assert(F && "A concrete function must be provided to this routine.");
218
219 // FIXME: These should almost certainly not be handled here, and instead
220 // handled with the help of TLI or the target itself. This was largely
221 // ported from existing analysis heuristics here so that such refactorings
222 // can take place in the future.
223
224 if (F->isIntrinsic())
225 return false;
226
227 if (F->hasLocalLinkage() || !F->hasName())
228 return true;
229
230 StringRef Name = F->getName();
231
232 // These will all likely lower to a single selection DAG node.
233 // clang-format off
234 if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
235 Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
236 Name == "fmin" || Name == "fminf" || Name == "fminl" ||
237 Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
238 Name == "sin" || Name == "sinf" || Name == "sinl" ||
239 Name == "cos" || Name == "cosf" || Name == "cosl" ||
240 Name == "tan" || Name == "tanf" || Name == "tanl" ||
241 Name == "asin" || Name == "asinf" || Name == "asinl" ||
242 Name == "acos" || Name == "acosf" || Name == "acosl" ||
243 Name == "atan" || Name == "atanf" || Name == "atanl" ||
244 Name == "atan2" || Name == "atan2f" || Name == "atan2l"||
245 Name == "sinh" || Name == "sinhf" || Name == "sinhl" ||
246 Name == "cosh" || Name == "coshf" || Name == "coshl" ||
247 Name == "tanh" || Name == "tanhf" || Name == "tanhl" ||
248 Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" ||
249 Name == "exp10" || Name == "exp10l" || Name == "exp10f")
250 return false;
251 // clang-format on
252 // These are all likely to be optimized into something smaller.
253 if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
254 Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
255 Name == "floorf" || Name == "ceil" || Name == "round" ||
256 Name == "ffs" || Name == "ffsl" || Name == "abs" || Name == "labs" ||
257 Name == "llabs")
258 return false;
259
260 return true;
261 }
262
264 AssumptionCache &AC,
265 TargetLibraryInfo *LibInfo,
266 HardwareLoopInfo &HWLoopInfo) const {
267 return false;
268 }
269
270 virtual unsigned getEpilogueVectorizationMinVF() const { return 16; }
271
273 return false;
274 }
275
276 virtual TailFoldingStyle
277 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const {
279 }
280
281 virtual std::optional<Instruction *>
283 return std::nullopt;
284 }
285
286 virtual std::optional<Value *>
288 APInt DemandedMask, KnownBits &Known,
289 bool &KnownBitsComputed) const {
290 return std::nullopt;
291 }
292
293 virtual std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
294 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
295 APInt &UndefElts2, APInt &UndefElts3,
296 std::function<void(Instruction *, unsigned, APInt, APInt &)>
297 SimplifyAndSetOp) const {
298 return std::nullopt;
299 }
300
304
307
308 virtual bool isLegalAddImmediate(int64_t Imm) const { return false; }
309
310 virtual bool isLegalAddScalableImmediate(int64_t Imm) const { return false; }
311
312 virtual bool isLegalICmpImmediate(int64_t Imm) const { return false; }
313
314 virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
315 int64_t BaseOffset, bool HasBaseReg,
316 int64_t Scale, unsigned AddrSpace,
317 Instruction *I = nullptr,
318 int64_t ScalableOffset = 0) const {
319 // Guess that only reg and reg+reg addressing is allowed. This heuristic is
320 // taken from the implementation of LSR.
321 return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
322 }
323
324 virtual bool isLSRCostLess(const TTI::LSRCost &C1,
325 const TTI::LSRCost &C2) const {
326 return std::tie(C1.NumRegs, C1.AddRecCost, C1.NumIVMuls, C1.NumBaseAdds,
327 C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
328 std::tie(C2.NumRegs, C2.AddRecCost, C2.NumIVMuls, C2.NumBaseAdds,
329 C2.ScaleCost, C2.ImmCost, C2.SetupCost);
330 }
331
332 virtual bool isNumRegsMajorCostOfLSR() const { return true; }
333
334 virtual bool shouldDropLSRSolutionIfLessProfitable() const { return false; }
335
337 return false;
338 }
339
340 virtual bool canMacroFuseCmp() const { return false; }
341
342 virtual bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE,
344 TargetLibraryInfo *LibInfo) const {
345 return false;
346 }
347
350 return TTI::AMK_None;
351 }
352
353 virtual bool isLegalMaskedStore(Type *DataType, Align Alignment,
354 unsigned AddressSpace,
355 TTI::MaskKind MaskKind) const {
356 return false;
357 }
358
359 virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment,
360 unsigned AddressSpace,
361 TTI::MaskKind MaskKind) const {
362 return false;
363 }
364
365 virtual bool isLegalNTStore(Type *DataType, Align Alignment) const {
366 // By default, assume nontemporal memory stores are available for stores
367 // that are aligned and have a size that is a power of 2.
368 unsigned DataSize = DL.getTypeStoreSize(DataType);
369 return Alignment >= DataSize && isPowerOf2_32(DataSize);
370 }
371
372 virtual bool isLegalNTLoad(Type *DataType, Align Alignment) const {
373 // By default, assume nontemporal memory loads are available for loads that
374 // are aligned and have a size that is a power of 2.
375 unsigned DataSize = DL.getTypeStoreSize(DataType);
376 return Alignment >= DataSize && isPowerOf2_32(DataSize);
377 }
378
379 virtual bool isLegalBroadcastLoad(Type *ElementTy,
380 ElementCount NumElements) const {
381 return false;
382 }
383
384 virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) const {
385 return false;
386 }
387
388 virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) const {
389 return false;
390 }
391
393 Align Alignment) const {
394 return false;
395 }
396
398 Align Alignment) const {
399 return false;
400 }
401
402 virtual bool isLegalMaskedCompressStore(Type *DataType,
403 Align Alignment) const {
404 return false;
405 }
406
407 virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
408 unsigned Opcode1,
409 const SmallBitVector &OpcodeMask) const {
410 return false;
411 }
412
413 virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const {
414 return false;
415 }
416
417 virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const {
418 return false;
419 }
420
421 virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
422 Align Alignment,
423 unsigned AddrSpace) const {
424 return false;
425 }
426
427 virtual bool isLegalMaskedVectorHistogram(Type *AddrType,
428 Type *DataType) const {
429 return false;
430 }
431
432 virtual bool enableOrderedReductions() const { return false; }
433
434 virtual bool hasDivRemOp(Type *DataType, bool IsSigned) const {
435 return false;
436 }
437
438 virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const {
439 return false;
440 }
441
442 virtual bool prefersVectorizedAddressing() const { return true; }
443
445 StackOffset BaseOffset,
446 bool HasBaseReg, int64_t Scale,
447 unsigned AddrSpace) const {
448 // Guess that all legal addressing mode are free.
449 if (isLegalAddressingMode(Ty, BaseGV, BaseOffset.getFixed(), HasBaseReg,
450 Scale, AddrSpace, /*I=*/nullptr,
451 BaseOffset.getScalable()))
452 return 0;
454 }
455
456 virtual bool LSRWithInstrQueries() const { return false; }
457
458 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const { return false; }
459
460 virtual bool isProfitableToHoist(Instruction *I) const { return true; }
461
462 virtual bool useAA() const { return false; }
463
464 virtual bool isTypeLegal(Type *Ty) const { return false; }
465
466 virtual unsigned getRegUsageForType(Type *Ty) const { return 1; }
467
468 virtual bool shouldBuildLookupTables() const { return true; }
469
471 return true;
472 }
473
474 virtual bool shouldBuildRelLookupTables() const { return false; }
475
476 virtual bool useColdCCForColdCall(Function &F) const { return false; }
477
478 virtual bool useFastCCForInternalCall(Function &F) const { return true; }
479
481 return false;
482 }
483
485 unsigned ScalarOpdIdx) const {
486 return false;
487 }
488
490 int OpdIdx) const {
491 return OpdIdx == -1;
492 }
493
494 virtual bool
496 int RetIdx) const {
497 return RetIdx == 0;
498 }
499
501 VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
502 TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
503 ArrayRef<Value *> VL = {}) const {
504 return 0;
505 }
506
507 virtual InstructionCost
512
513 virtual bool supportsEfficientVectorElementLoadStore() const { return false; }
514
515 virtual bool supportsTailCalls() const { return true; }
516
517 virtual bool supportsTailCallFor(const CallBase *CB) const {
518 llvm_unreachable("Not implemented");
519 }
520
521 virtual bool enableAggressiveInterleaving(bool LoopHasReductions) const {
522 return false;
523 }
524
526 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
527 return {};
528 }
529
530 virtual bool enableSelectOptimize() const { return true; }
531
532 virtual bool shouldTreatInstructionLikeSelect(const Instruction *I) const {
533 // A select with two constant operands will usually be better left as a
534 // select.
535 using namespace llvm::PatternMatch;
537 return false;
538 // If the select is a logical-and/logical-or then it is better treated as a
539 // and/or by the backend.
540 return isa<SelectInst>(I) &&
543 }
544
545 virtual bool enableInterleavedAccessVectorization() const { return false; }
546
548 return false;
549 }
550
551 virtual bool isFPVectorizationPotentiallyUnsafe() const { return false; }
552
554 unsigned BitWidth,
555 unsigned AddressSpace,
556 Align Alignment,
557 unsigned *Fast) const {
558 return false;
559 }
560
562 getPopcntSupport(unsigned IntTyWidthInBit) const {
563 return TTI::PSK_Software;
564 }
565
566 virtual bool haveFastSqrt(Type *Ty) const { return false; }
567
569 return true;
570 }
571
572 virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return true; }
573
574 virtual InstructionCost getFPOpCost(Type *Ty) const {
576 }
577
578 virtual InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
579 const APInt &Imm,
580 Type *Ty) const {
581 return 0;
582 }
583
584 virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
586 return TTI::TCC_Basic;
587 }
588
589 virtual InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
590 const APInt &Imm, Type *Ty,
592 Instruction *Inst = nullptr) const {
593 return TTI::TCC_Free;
594 }
595
596 virtual InstructionCost
597 getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
598 Type *Ty, TTI::TargetCostKind CostKind) const {
599 return TTI::TCC_Free;
600 }
601
603 const Function &Fn) const {
604 return false;
605 }
606
607 virtual unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
608 virtual bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const {
609 return false;
610 }
611
612 virtual unsigned getRegisterClassForType(bool Vector,
613 Type *Ty = nullptr) const {
614 return Vector ? 1 : 0;
615 }
616
617 virtual const char *getRegisterClassName(unsigned ClassID) const {
618 switch (ClassID) {
619 default:
620 return "Generic::Unknown Register Class";
621 case 0:
622 return "Generic::ScalarRC";
623 case 1:
624 return "Generic::VectorRC";
625 }
626 }
627
628 virtual TypeSize
632
633 virtual unsigned getMinVectorRegisterBitWidth() const { return 128; }
634
635 virtual std::optional<unsigned> getMaxVScale() const { return std::nullopt; }
636 virtual std::optional<unsigned> getVScaleForTuning() const {
637 return std::nullopt;
638 }
639 virtual bool isVScaleKnownToBeAPowerOfTwo() const { return false; }
640
641 virtual bool
645
646 virtual ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const {
647 return ElementCount::get(0, IsScalable);
648 }
649
650 virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const {
651 return 0;
652 }
653 virtual unsigned getStoreMinimumVF(unsigned VF, Type *, Type *) const {
654 return VF;
655 }
656
658 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
659 AllowPromotionWithoutCommonHeader = false;
660 return false;
661 }
662
663 virtual unsigned getCacheLineSize() const { return 0; }
664 virtual std::optional<unsigned>
666 switch (Level) {
668 [[fallthrough]];
670 return std::nullopt;
671 }
672 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
673 }
674
675 virtual std::optional<unsigned>
677 switch (Level) {
679 [[fallthrough]];
681 return std::nullopt;
682 }
683
684 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
685 }
686
687 virtual std::optional<unsigned> getMinPageSize() const { return {}; }
688
689 virtual unsigned getPrefetchDistance() const { return 0; }
690 virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses,
691 unsigned NumStridedMemAccesses,
692 unsigned NumPrefetches,
693 bool HasCall) const {
694 return 1;
695 }
696 virtual unsigned getMaxPrefetchIterationsAhead() const { return UINT_MAX; }
697 virtual bool enableWritePrefetching() const { return false; }
698 virtual bool shouldPrefetchAddressSpace(unsigned AS) const { return !AS; }
699
701 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
703 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
706 }
707
708 virtual unsigned getMaxInterleaveFactor(ElementCount VF) const { return 1; }
709
711 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
713 ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) const {
714 // Widenable conditions will eventually lower into constants, so some
715 // operations with them will be trivially optimized away.
716 auto IsWidenableCondition = [](const Value *V) {
717 if (auto *II = dyn_cast<IntrinsicInst>(V))
718 if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
719 return true;
720 return false;
721 };
722 // FIXME: A number of transformation tests seem to require these values
723 // which seems a little odd for how arbitary there are.
724 switch (Opcode) {
725 default:
726 break;
727 case Instruction::FDiv:
728 case Instruction::FRem:
729 case Instruction::SDiv:
730 case Instruction::SRem:
731 case Instruction::UDiv:
732 case Instruction::URem:
733 // FIXME: Unlikely to be true for CodeSize.
734 return TTI::TCC_Expensive;
735 case Instruction::And:
736 case Instruction::Or:
737 if (any_of(Args, IsWidenableCondition))
738 return TTI::TCC_Free;
739 break;
740 }
741
742 // Assume a 3cy latency for fp arithmetic ops.
744 if (Ty->getScalarType()->isFloatingPointTy())
745 return 3;
746
747 return 1;
748 }
749
750 virtual InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0,
751 unsigned Opcode1,
752 const SmallBitVector &OpcodeMask,
755 }
756
757 virtual InstructionCost
760 VectorType *SubTp, ArrayRef<const Value *> Args = {},
761 const Instruction *CxtI = nullptr) const {
762 return 1;
763 }
764
765 virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst,
766 Type *Src, TTI::CastContextHint CCH,
768 const Instruction *I) const {
769 switch (Opcode) {
770 default:
771 break;
772 case Instruction::IntToPtr: {
773 unsigned SrcSize = Src->getScalarSizeInBits();
774 if (DL.isLegalInteger(SrcSize) &&
775 SrcSize <= DL.getPointerTypeSizeInBits(Dst))
776 return 0;
777 break;
778 }
779 case Instruction::PtrToAddr: {
780 unsigned DstSize = Dst->getScalarSizeInBits();
781 assert(DstSize == DL.getAddressSizeInBits(Src));
782 if (DL.isLegalInteger(DstSize))
783 return 0;
784 break;
785 }
786 case Instruction::PtrToInt: {
787 unsigned DstSize = Dst->getScalarSizeInBits();
788 if (DL.isLegalInteger(DstSize) &&
789 DstSize >= DL.getPointerTypeSizeInBits(Src))
790 return 0;
791 break;
792 }
793 case Instruction::BitCast:
794 if (Dst == Src || (Dst->isPointerTy() && Src->isPointerTy()))
795 // Identity and pointer-to-pointer casts are free.
796 return 0;
797 break;
798 case Instruction::Trunc: {
799 // trunc to a native type is free (assuming the target has compare and
800 // shift-right of the same width).
801 TypeSize DstSize = DL.getTypeSizeInBits(Dst);
802 if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedValue()))
803 return 0;
804 break;
805 }
806 }
807 return 1;
808 }
809
810 virtual InstructionCost
811 getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
812 unsigned Index, TTI::TargetCostKind CostKind) const {
813 return 1;
814 }
815
816 virtual InstructionCost getCFInstrCost(unsigned Opcode,
818 const Instruction *I = nullptr) const {
819 // A phi would be free, unless we're costing the throughput because it
820 // will require a register.
821 if (Opcode == Instruction::PHI && CostKind != TTI::TCK_RecipThroughput)
822 return 0;
823 return 1;
824 }
825
827 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
829 TTI::OperandValueInfo Op2Info, const Instruction *I) const {
830 return 1;
831 }
832
833 virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
835 unsigned Index, const Value *Op0,
836 const Value *Op1) const {
837 return 1;
838 }
839
840 /// \param ScalarUserAndIdx encodes the information about extracts from a
841 /// vector with 'Scalar' being the value being extracted,'User' being the user
842 /// of the extract(nullptr if user is not known before vectorization) and
843 /// 'Idx' being the extract lane.
845 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
846 Value *Scalar,
847 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
848 return 1;
849 }
850
853 unsigned Index) const {
854 return 1;
855 }
856
857 virtual InstructionCost
860 unsigned Index) const {
861 return 1;
862 }
863
864 virtual InstructionCost
865 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
866 const APInt &DemandedDstElts,
868 return 1;
869 }
870
871 virtual InstructionCost
874 // Note: The `insertvalue` cost here is chosen to match the default case of
875 // getInstructionCost() -- as prior to adding this helper `insertvalue` was
876 // not handled.
877 if (Opcode == Instruction::InsertValue &&
879 return TTI::TCC_Basic;
880 return TTI::TCC_Free;
881 }
882
883 virtual InstructionCost
884 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
886 TTI::OperandValueInfo OpInfo, const Instruction *I) const {
887 return 1;
888 }
889
891 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
892 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
893 bool UseMaskForCond, bool UseMaskForGaps) const {
894 return 1;
895 }
896
897 virtual InstructionCost
900 switch (ICA.getID()) {
901 default:
902 break;
903 case Intrinsic::allow_runtime_check:
904 case Intrinsic::allow_ubsan_check:
905 case Intrinsic::annotation:
906 case Intrinsic::assume:
907 case Intrinsic::sideeffect:
908 case Intrinsic::pseudoprobe:
909 case Intrinsic::arithmetic_fence:
910 case Intrinsic::dbg_assign:
911 case Intrinsic::dbg_declare:
912 case Intrinsic::dbg_value:
913 case Intrinsic::dbg_label:
914 case Intrinsic::invariant_start:
915 case Intrinsic::invariant_end:
916 case Intrinsic::launder_invariant_group:
917 case Intrinsic::strip_invariant_group:
918 case Intrinsic::is_constant:
919 case Intrinsic::lifetime_start:
920 case Intrinsic::lifetime_end:
921 case Intrinsic::experimental_noalias_scope_decl:
922 case Intrinsic::objectsize:
923 case Intrinsic::ptr_annotation:
924 case Intrinsic::var_annotation:
925 case Intrinsic::experimental_gc_result:
926 case Intrinsic::experimental_gc_relocate:
927 case Intrinsic::coro_alloc:
928 case Intrinsic::coro_begin:
929 case Intrinsic::coro_begin_custom_abi:
930 case Intrinsic::coro_free:
931 case Intrinsic::coro_end:
932 case Intrinsic::coro_frame:
933 case Intrinsic::coro_size:
934 case Intrinsic::coro_align:
935 case Intrinsic::coro_suspend:
936 case Intrinsic::coro_subfn_addr:
937 case Intrinsic::threadlocal_address:
938 case Intrinsic::experimental_widenable_condition:
939 case Intrinsic::ssa_copy:
940 // These intrinsics don't actually represent code after lowering.
941 return 0;
942 }
943 return 1;
944 }
945
946 virtual InstructionCost
949 switch (MICA.getID()) {
950 case Intrinsic::masked_scatter:
951 case Intrinsic::masked_gather:
952 case Intrinsic::masked_load:
953 case Intrinsic::masked_store:
954 case Intrinsic::vp_scatter:
955 case Intrinsic::vp_gather:
956 case Intrinsic::masked_compressstore:
957 case Intrinsic::masked_expandload:
958 return 1;
959 }
961 }
962
966 return 1;
967 }
968
969 // Assume that we have a register of the right size for the type.
970 virtual unsigned getNumberOfParts(Type *Tp) const { return 1; }
971
974 const SCEV *,
975 TTI::TargetCostKind) const {
976 return 0;
977 }
978
979 virtual InstructionCost
981 std::optional<FastMathFlags> FMF,
982 TTI::TargetCostKind) const {
983 return 1;
984 }
985
991
992 virtual InstructionCost
993 getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy,
994 VectorType *Ty, std::optional<FastMathFlags> FMF,
996 return 1;
997 }
998
999 virtual InstructionCost
1000 getMulAccReductionCost(bool IsUnsigned, unsigned RedOpcode, Type *ResTy,
1002 return 1;
1003 }
1004
1005 virtual InstructionCost
1007 return 0;
1008 }
1009
1011 MemIntrinsicInfo &Info) const {
1012 return false;
1013 }
1014
1015 virtual unsigned getAtomicMemIntrinsicMaxElementSize() const {
1016 // Note for overrides: You must ensure for all element unordered-atomic
1017 // memory intrinsics that all power-of-2 element sizes up to, and
1018 // including, the return value of this method have a corresponding
1019 // runtime lib call. These runtime lib call definitions can be found
1020 // in RuntimeLibcalls.h
1021 return 0;
1022 }
1023
1024 virtual Value *
1026 bool CanCreate = true) const {
1027 return nullptr;
1028 }
1029
1030 virtual Type *
1032 unsigned SrcAddrSpace, unsigned DestAddrSpace,
1033 Align SrcAlign, Align DestAlign,
1034 std::optional<uint32_t> AtomicElementSize) const {
1035 return AtomicElementSize ? Type::getIntNTy(Context, *AtomicElementSize * 8)
1036 : Type::getInt8Ty(Context);
1037 }
1038
1040 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
1041 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
1042 Align SrcAlign, Align DestAlign,
1043 std::optional<uint32_t> AtomicCpySize) const {
1044 unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
1045 Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
1046 for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
1047 OpsOut.push_back(OpType);
1048 }
1049
1050 virtual bool areInlineCompatible(const Function *Caller,
1051 const Function *Callee) const {
1052 return (Caller->getFnAttribute("target-cpu") ==
1053 Callee->getFnAttribute("target-cpu")) &&
1054 (Caller->getFnAttribute("target-features") ==
1055 Callee->getFnAttribute("target-features"));
1056 }
1057
1058 virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
1059 unsigned DefaultCallPenalty) const {
1060 return DefaultCallPenalty;
1061 }
1062
1063 virtual bool areTypesABICompatible(const Function *Caller,
1064 const Function *Callee,
1065 ArrayRef<Type *> Types) const {
1066 return (Caller->getFnAttribute("target-cpu") ==
1067 Callee->getFnAttribute("target-cpu")) &&
1068 (Caller->getFnAttribute("target-features") ==
1069 Callee->getFnAttribute("target-features"));
1070 }
1071
1073 return false;
1074 }
1075
1077 return false;
1078 }
1079
1080 virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const {
1081 return 128;
1082 }
1083
1084 virtual bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
1085
1086 virtual bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
1087
1088 virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
1089 Align Alignment,
1090 unsigned AddrSpace) const {
1091 return true;
1092 }
1093
1094 virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
1095 Align Alignment,
1096 unsigned AddrSpace) const {
1097 return true;
1098 }
1099
1101 ElementCount VF) const {
1102 return true;
1103 }
1104
1106 return true;
1107 }
1108
1109 virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
1110 unsigned ChainSizeInBytes,
1111 VectorType *VecTy) const {
1112 return VF;
1113 }
1114
1115 virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
1116 unsigned ChainSizeInBytes,
1117 VectorType *VecTy) const {
1118 return VF;
1119 }
1120
1121 virtual bool preferFixedOverScalableIfEqualCost(bool IsEpilogue) const {
1122 return false;
1123 }
1124
1125 virtual bool preferInLoopReduction(RecurKind Kind, Type *Ty) const {
1126 return false;
1127 }
1128 virtual bool preferAlternateOpcodeVectorization() const { return true; }
1129
1130 virtual bool preferPredicatedReductionSelect() const { return false; }
1131
1132 virtual bool preferEpilogueVectorization() const { return true; }
1133
1134 virtual bool shouldConsiderVectorizationRegPressure() const { return false; }
1135
1136 virtual bool shouldExpandReduction(const IntrinsicInst *II) const {
1137 return true;
1138 }
1139
1140 virtual TTI::ReductionShuffle
1144
1145 virtual unsigned getGISelRematGlobalCost() const { return 1; }
1146
1147 virtual unsigned getMinTripCountTailFoldingThreshold() const { return 0; }
1148
1149 virtual bool supportsScalableVectors() const { return false; }
1150
1151 virtual bool enableScalableVectorization() const { return false; }
1152
1153 virtual bool hasActiveVectorLength() const { return false; }
1154
1156 SmallVectorImpl<Use *> &Ops) const {
1157 return false;
1158 }
1159
1160 virtual bool isVectorShiftByScalarCheap(Type *Ty) const { return false; }
1161
1168
1169 virtual bool hasArmWideBranch(bool) const { return false; }
1170
1171 virtual APInt getFeatureMask(const Function &F) const {
1172 return APInt::getZero(32);
1173 }
1174
1175 virtual APInt getPriorityMask(const Function &F) const {
1176 return APInt::getZero(32);
1177 }
1178
1179 virtual bool isMultiversionedFunction(const Function &F) const {
1180 return false;
1181 }
1182
1183 virtual unsigned getMaxNumArgs() const { return UINT_MAX; }
1184
1185 virtual unsigned getNumBytesToPadGlobalArray(unsigned Size,
1186 Type *ArrayType) const {
1187 return 0;
1188 }
1189
1191 const Function &F,
1192 SmallVectorImpl<std::pair<StringRef, int64_t>> &LB) const {}
1193
1194 virtual bool allowVectorElementIndexingUsingGEP() const { return true; }
1195
1196protected:
1197 // Obtain the minimum required size to hold the value (without the sign)
1198 // In case of a vector it returns the min required size for one element.
1199 unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const {
1201 const auto *VectorValue = cast<Constant>(Val);
1202
1203 // In case of a vector need to pick the max between the min
1204 // required size for each element
1205 auto *VT = cast<FixedVectorType>(Val->getType());
1206
1207 // Assume unsigned elements
1208 isSigned = false;
1209
1210 // The max required size is the size of the vector element type
1211 unsigned MaxRequiredSize =
1212 VT->getElementType()->getPrimitiveSizeInBits().getFixedValue();
1213
1214 unsigned MinRequiredSize = 0;
1215 for (unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
1216 if (auto *IntElement =
1217 dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
1218 bool signedElement = IntElement->getValue().isNegative();
1219 // Get the element min required size.
1220 unsigned ElementMinRequiredSize =
1221 IntElement->getValue().getSignificantBits() - 1;
1222 // In case one element is signed then all the vector is signed.
1223 isSigned |= signedElement;
1224 // Save the max required bit size between all the elements.
1225 MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
1226 } else {
1227 // not an int constant element
1228 return MaxRequiredSize;
1229 }
1230 }
1231 return MinRequiredSize;
1232 }
1233
1234 if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
1235 isSigned = CI->getValue().isNegative();
1236 return CI->getValue().getSignificantBits() - 1;
1237 }
1238
1239 if (const auto *Cast = dyn_cast<SExtInst>(Val)) {
1240 isSigned = true;
1241 return Cast->getSrcTy()->getScalarSizeInBits() - 1;
1242 }
1243
1244 if (const auto *Cast = dyn_cast<ZExtInst>(Val)) {
1245 isSigned = false;
1246 return Cast->getSrcTy()->getScalarSizeInBits();
1247 }
1248
1249 isSigned = false;
1250 return Val->getType()->getScalarSizeInBits();
1251 }
1252
1253 bool isStridedAccess(const SCEV *Ptr) const {
1254 return Ptr && isa<SCEVAddRecExpr>(Ptr);
1255 }
1256
1258 const SCEV *Ptr) const {
1259 if (!isStridedAccess(Ptr))
1260 return nullptr;
1261 const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
1262 return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
1263 }
1264
1266 int64_t MergeDistance) const {
1267 const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
1268 if (!Step)
1269 return false;
1270 APInt StrideVal = Step->getAPInt();
1271 if (StrideVal.getBitWidth() > 64)
1272 return false;
1273 // FIXME: Need to take absolute value for negative stride case.
1274 return StrideVal.getSExtValue() < MergeDistance;
1275 }
1276};
1277
1278/// CRTP base class for use as a mix-in that aids implementing
1279/// a TargetTransformInfo-compatible class.
1280template <typename T>
1282private:
1283 typedef TargetTransformInfoImplBase BaseT;
1284
1285protected:
1287
1288public:
1289 InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
1290 ArrayRef<const Value *> Operands, Type *AccessType,
1291 TTI::TargetCostKind CostKind) const override {
1292 assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
1293 auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
1294 bool HasBaseReg = (BaseGV == nullptr);
1295
1296 auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
1297 APInt BaseOffset(PtrSizeBits, 0);
1298 int64_t Scale = 0;
1299
1300 auto GTI = gep_type_begin(PointeeType, Operands);
1301 Type *TargetType = nullptr;
1302
1303 // Handle the case where the GEP instruction has a single operand,
1304 // the basis, therefore TargetType is a nullptr.
1305 if (Operands.empty())
1306 return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
1307
1308 for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
1309 TargetType = GTI.getIndexedType();
1310 // We assume that the cost of Scalar GEP with constant index and the
1311 // cost of Vector GEP with splat constant index are the same.
1312 const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
1313 if (!ConstIdx)
1314 if (auto Splat = getSplatValue(*I))
1315 ConstIdx = dyn_cast<ConstantInt>(Splat);
1316 if (StructType *STy = GTI.getStructTypeOrNull()) {
1317 // For structures the index is always splat or scalar constant
1318 assert(ConstIdx && "Unexpected GEP index");
1319 uint64_t Field = ConstIdx->getZExtValue();
1320 BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
1321 } else {
1322 // If this operand is a scalable type, bail out early.
1323 // TODO: Make isLegalAddressingMode TypeSize aware.
1324 if (TargetType->isScalableTy())
1325 return TTI::TCC_Basic;
1326 int64_t ElementSize =
1327 GTI.getSequentialElementStride(DL).getFixedValue();
1328 if (ConstIdx) {
1329 BaseOffset +=
1330 ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
1331 } else {
1332 // Needs scale register.
1333 if (Scale != 0)
1334 // No addressing mode takes two scale registers.
1335 return TTI::TCC_Basic;
1336 Scale = ElementSize;
1337 }
1338 }
1339 }
1340
1341 // If we haven't been provided a hint, use the target type for now.
1342 //
1343 // TODO: Take a look at potentially removing this: This is *slightly* wrong
1344 // as it's possible to have a GEP with a foldable target type but a memory
1345 // access that isn't foldable. For example, this load isn't foldable on
1346 // RISC-V:
1347 //
1348 // %p = getelementptr i32, ptr %base, i32 42
1349 // %x = load <2 x i32>, ptr %p
1350 if (!AccessType)
1351 AccessType = TargetType;
1352
1353 // If the final address of the GEP is a legal addressing mode for the given
1354 // access type, then we can fold it into its users.
1355 if (static_cast<const T *>(this)->isLegalAddressingMode(
1356 AccessType, const_cast<GlobalValue *>(BaseGV),
1357 BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
1359 return TTI::TCC_Free;
1360
1361 // TODO: Instead of returning TCC_Basic here, we should use
1362 // getArithmeticInstrCost. Or better yet, provide a hook to let the target
1363 // model it.
1364 return TTI::TCC_Basic;
1365 }
1366
1369 const TTI::PointersChainInfo &Info, Type *AccessTy,
1370 TTI::TargetCostKind CostKind) const override {
1372 // In the basic model we take into account GEP instructions only
1373 // (although here can come alloca instruction, a value, constants and/or
1374 // constant expressions, PHIs, bitcasts ... whatever allowed to be used as a
1375 // pointer). Typically, if Base is a not a GEP-instruction and all the
1376 // pointers are relative to the same base address, all the rest are
1377 // either GEP instructions, PHIs, bitcasts or constants. When we have same
1378 // base, we just calculate cost of each non-Base GEP as an ADD operation if
1379 // any their index is a non-const.
1380 // If no known dependecies between the pointers cost is calculated as a sum
1381 // of costs of GEP instructions.
1382 for (const Value *V : Ptrs) {
1383 const auto *GEP = dyn_cast<GetElementPtrInst>(V);
1384 if (!GEP)
1385 continue;
1386 if (Info.isSameBase() && V != Base) {
1387 if (GEP->hasAllConstantIndices())
1388 continue;
1389 Cost += static_cast<const T *>(this)->getArithmeticInstrCost(
1390 Instruction::Add, GEP->getType(), CostKind,
1391 {TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None},
1392 {});
1393 } else {
1394 SmallVector<const Value *> Indices(GEP->indices());
1395 Cost += static_cast<const T *>(this)->getGEPCost(
1396 GEP->getSourceElementType(), GEP->getPointerOperand(), Indices,
1397 AccessTy, CostKind);
1398 }
1399 }
1400 return Cost;
1401 }
1402
1405 TTI::TargetCostKind CostKind) const override {
1406 using namespace llvm::PatternMatch;
1407
1408 auto *TargetTTI = static_cast<const T *>(this);
1409 // Handle non-intrinsic calls, invokes, and callbr.
1410 // FIXME: Unlikely to be true for anything but CodeSize.
1411 auto *CB = dyn_cast<CallBase>(U);
1412 if (CB && !isa<IntrinsicInst>(U)) {
1413 if (const Function *F = CB->getCalledFunction()) {
1414 if (!TargetTTI->isLoweredToCall(F))
1415 return TTI::TCC_Basic; // Give a basic cost if it will be lowered
1416
1417 return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
1418 }
1419 // For indirect or other calls, scale cost by number of arguments.
1420 return TTI::TCC_Basic * (CB->arg_size() + 1);
1421 }
1422
1423 Type *Ty = U->getType();
1424 unsigned Opcode = Operator::getOpcode(U);
1425 auto *I = dyn_cast<Instruction>(U);
1426 switch (Opcode) {
1427 default:
1428 break;
1429 case Instruction::Call: {
1430 assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
1431 auto *Intrinsic = cast<IntrinsicInst>(U);
1432 IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
1433 return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
1434 }
1435 case Instruction::Br:
1436 case Instruction::Ret:
1437 case Instruction::PHI:
1438 case Instruction::Switch:
1439 return TargetTTI->getCFInstrCost(Opcode, CostKind, I);
1440 case Instruction::Freeze:
1441 return TTI::TCC_Free;
1442 case Instruction::ExtractValue:
1443 case Instruction::InsertValue:
1444 return TargetTTI->getInsertExtractValueCost(Opcode, CostKind);
1445 case Instruction::Alloca:
1446 if (cast<AllocaInst>(U)->isStaticAlloca())
1447 return TTI::TCC_Free;
1448 break;
1449 case Instruction::GetElementPtr: {
1450 const auto *GEP = cast<GEPOperator>(U);
1451 Type *AccessType = nullptr;
1452 // For now, only provide the AccessType in the simple case where the GEP
1453 // only has one user.
1454 if (GEP->hasOneUser() && I)
1455 AccessType = I->user_back()->getAccessType();
1456
1457 return TargetTTI->getGEPCost(GEP->getSourceElementType(),
1458 Operands.front(), Operands.drop_front(),
1459 AccessType, CostKind);
1460 }
1461 case Instruction::Add:
1462 case Instruction::FAdd:
1463 case Instruction::Sub:
1464 case Instruction::FSub:
1465 case Instruction::Mul:
1466 case Instruction::FMul:
1467 case Instruction::UDiv:
1468 case Instruction::SDiv:
1469 case Instruction::FDiv:
1470 case Instruction::URem:
1471 case Instruction::SRem:
1472 case Instruction::FRem:
1473 case Instruction::Shl:
1474 case Instruction::LShr:
1475 case Instruction::AShr:
1476 case Instruction::And:
1477 case Instruction::Or:
1478 case Instruction::Xor:
1479 case Instruction::FNeg: {
1480 const TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(Operands[0]);
1481 TTI::OperandValueInfo Op2Info;
1482 if (Opcode != Instruction::FNeg)
1483 Op2Info = TTI::getOperandInfo(Operands[1]);
1484 return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
1485 Op2Info, Operands, I);
1486 }
1487 case Instruction::IntToPtr:
1488 case Instruction::PtrToAddr:
1489 case Instruction::PtrToInt:
1490 case Instruction::SIToFP:
1491 case Instruction::UIToFP:
1492 case Instruction::FPToUI:
1493 case Instruction::FPToSI:
1494 case Instruction::Trunc:
1495 case Instruction::FPTrunc:
1496 case Instruction::BitCast:
1497 case Instruction::FPExt:
1498 case Instruction::SExt:
1499 case Instruction::ZExt:
1500 case Instruction::AddrSpaceCast: {
1501 Type *OpTy = Operands[0]->getType();
1502 return TargetTTI->getCastInstrCost(
1503 Opcode, Ty, OpTy, TTI::getCastContextHint(I), CostKind, I);
1504 }
1505 case Instruction::Store: {
1506 auto *SI = cast<StoreInst>(U);
1507 Type *ValTy = Operands[0]->getType();
1508 TTI::OperandValueInfo OpInfo = TTI::getOperandInfo(Operands[0]);
1509 return TargetTTI->getMemoryOpCost(Opcode, ValTy, SI->getAlign(),
1510 SI->getPointerAddressSpace(), CostKind,
1511 OpInfo, I);
1512 }
1513 case Instruction::Load: {
1514 // FIXME: Arbitary cost which could come from the backend.
1516 return 4;
1517 auto *LI = cast<LoadInst>(U);
1518 Type *LoadType = U->getType();
1519 // If there is a non-register sized type, the cost estimation may expand
1520 // it to be several instructions to load into multiple registers on the
1521 // target. But, if the only use of the load is a trunc instruction to a
1522 // register sized type, the instruction selector can combine these
1523 // instructions to be a single load. So, in this case, we use the
1524 // destination type of the trunc instruction rather than the load to
1525 // accurately estimate the cost of this load instruction.
1526 if (CostKind == TTI::TCK_CodeSize && LI->hasOneUse() &&
1527 !LoadType->isVectorTy()) {
1528 if (const TruncInst *TI = dyn_cast<TruncInst>(*LI->user_begin()))
1529 LoadType = TI->getDestTy();
1530 }
1531 return TargetTTI->getMemoryOpCost(Opcode, LoadType, LI->getAlign(),
1533 {TTI::OK_AnyValue, TTI::OP_None}, I);
1534 }
1535 case Instruction::Select: {
1536 const Value *Op0, *Op1;
1537 if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
1538 match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
1539 // select x, y, false --> x & y
1540 // select x, true, y --> x | y
1541 const auto Op1Info = TTI::getOperandInfo(Op0);
1542 const auto Op2Info = TTI::getOperandInfo(Op1);
1543 assert(Op0->getType()->getScalarSizeInBits() == 1 &&
1544 Op1->getType()->getScalarSizeInBits() == 1);
1545
1546 SmallVector<const Value *, 2> Operands{Op0, Op1};
1547 return TargetTTI->getArithmeticInstrCost(
1548 match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
1549 CostKind, Op1Info, Op2Info, Operands, I);
1550 }
1551 const auto Op1Info = TTI::getOperandInfo(Operands[1]);
1552 const auto Op2Info = TTI::getOperandInfo(Operands[2]);
1553 Type *CondTy = Operands[0]->getType();
1554 return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,
1556 CostKind, Op1Info, Op2Info, I);
1557 }
1558 case Instruction::ICmp:
1559 case Instruction::FCmp: {
1560 const auto Op1Info = TTI::getOperandInfo(Operands[0]);
1561 const auto Op2Info = TTI::getOperandInfo(Operands[1]);
1562 Type *ValTy = Operands[0]->getType();
1563 // TODO: Also handle ICmp/FCmp constant expressions.
1564 return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(),
1565 I ? cast<CmpInst>(I)->getPredicate()
1567 CostKind, Op1Info, Op2Info, I);
1568 }
1569 case Instruction::InsertElement: {
1570 auto *IE = dyn_cast<InsertElementInst>(U);
1571 if (!IE)
1572 return TTI::TCC_Basic; // FIXME
1573 unsigned Idx = -1;
1574 if (auto *CI = dyn_cast<ConstantInt>(Operands[2]))
1575 if (CI->getValue().getActiveBits() <= 32)
1576 Idx = CI->getZExtValue();
1577 return TargetTTI->getVectorInstrCost(*IE, Ty, CostKind, Idx);
1578 }
1579 case Instruction::ShuffleVector: {
1580 auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
1581 if (!Shuffle)
1582 return TTI::TCC_Basic; // FIXME
1583
1584 auto *VecTy = cast<VectorType>(U->getType());
1585 auto *VecSrcTy = cast<VectorType>(Operands[0]->getType());
1586 ArrayRef<int> Mask = Shuffle->getShuffleMask();
1587 int NumSubElts, SubIndex;
1588
1589 // Treat undef/poison mask as free (no matter the length).
1590 if (all_of(Mask, [](int M) { return M < 0; }))
1591 return TTI::TCC_Free;
1592
1593 // TODO: move more of this inside improveShuffleKindFromMask.
1594 if (Shuffle->changesLength()) {
1595 // Treat a 'subvector widening' as a free shuffle.
1596 if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding())
1597 return TTI::TCC_Free;
1598
1599 if (Shuffle->isExtractSubvectorMask(SubIndex))
1600 return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecTy,
1601 VecSrcTy, Mask, CostKind, SubIndex,
1602 VecTy, Operands, Shuffle);
1603
1604 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1605 return TargetTTI->getShuffleCost(
1606 TTI::SK_InsertSubvector, VecTy, VecSrcTy, Mask, CostKind,
1607 SubIndex,
1608 FixedVectorType::get(VecTy->getScalarType(), NumSubElts),
1609 Operands, Shuffle);
1610
1611 int ReplicationFactor, VF;
1612 if (Shuffle->isReplicationMask(ReplicationFactor, VF)) {
1613 APInt DemandedDstElts = APInt::getZero(Mask.size());
1614 for (auto I : enumerate(Mask)) {
1615 if (I.value() != PoisonMaskElem)
1616 DemandedDstElts.setBit(I.index());
1617 }
1618 return TargetTTI->getReplicationShuffleCost(
1619 VecSrcTy->getElementType(), ReplicationFactor, VF,
1620 DemandedDstElts, CostKind);
1621 }
1622
1623 bool IsUnary = isa<UndefValue>(Operands[1]);
1624 NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
1625 SmallVector<int, 16> AdjustMask(Mask);
1626
1627 // Widening shuffle - widening the source(s) to the new length
1628 // (treated as free - see above), and then perform the adjusted
1629 // shuffle at that width.
1630 if (Shuffle->increasesLength()) {
1631 for (int &M : AdjustMask)
1632 M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
1633
1634 return TargetTTI->getShuffleCost(
1636 VecTy, AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1637 }
1638
1639 // Narrowing shuffle - perform shuffle at original wider width and
1640 // then extract the lower elements.
1641 // FIXME: This can assume widening, which is not true of all vector
1642 // architectures (and is not even the default).
1643 AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
1644
1645 InstructionCost ShuffleCost = TargetTTI->getShuffleCost(
1647 VecSrcTy, VecSrcTy, AdjustMask, CostKind, 0, nullptr, Operands,
1648 Shuffle);
1649
1650 SmallVector<int, 16> ExtractMask(Mask.size());
1651 std::iota(ExtractMask.begin(), ExtractMask.end(), 0);
1652 return ShuffleCost + TargetTTI->getShuffleCost(
1653 TTI::SK_ExtractSubvector, VecTy, VecSrcTy,
1654 ExtractMask, CostKind, 0, VecTy, {}, Shuffle);
1655 }
1656
1657 if (Shuffle->isIdentity())
1658 return TTI::TCC_Free;
1659
1660 if (Shuffle->isReverse())
1661 return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, VecSrcTy, Mask,
1662 CostKind, 0, nullptr, Operands,
1663 Shuffle);
1664
1665 if (Shuffle->isTranspose())
1666 return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, VecSrcTy,
1667 Mask, CostKind, 0, nullptr, Operands,
1668 Shuffle);
1669
1670 if (Shuffle->isZeroEltSplat())
1671 return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, VecSrcTy,
1672 Mask, CostKind, 0, nullptr, Operands,
1673 Shuffle);
1674
1675 if (Shuffle->isSingleSource())
1676 return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy,
1677 VecSrcTy, Mask, CostKind, 0, nullptr,
1678 Operands, Shuffle);
1679
1680 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1681 return TargetTTI->getShuffleCost(
1682 TTI::SK_InsertSubvector, VecTy, VecSrcTy, Mask, CostKind, SubIndex,
1683 FixedVectorType::get(VecTy->getScalarType(), NumSubElts), Operands,
1684 Shuffle);
1685
1686 if (Shuffle->isSelect())
1687 return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, VecSrcTy, Mask,
1688 CostKind, 0, nullptr, Operands,
1689 Shuffle);
1690
1691 if (Shuffle->isSplice(SubIndex))
1692 return TargetTTI->getShuffleCost(TTI::SK_Splice, VecTy, VecSrcTy, Mask,
1693 CostKind, SubIndex, nullptr, Operands,
1694 Shuffle);
1695
1696 return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, VecSrcTy,
1697 Mask, CostKind, 0, nullptr, Operands,
1698 Shuffle);
1699 }
1700 case Instruction::ExtractElement: {
1701 auto *EEI = dyn_cast<ExtractElementInst>(U);
1702 if (!EEI)
1703 return TTI::TCC_Basic; // FIXME
1704 unsigned Idx = -1;
1705 if (auto *CI = dyn_cast<ConstantInt>(Operands[1]))
1706 if (CI->getValue().getActiveBits() <= 32)
1707 Idx = CI->getZExtValue();
1708 Type *DstTy = Operands[0]->getType();
1709 return TargetTTI->getVectorInstrCost(*EEI, DstTy, CostKind, Idx);
1710 }
1711 }
1712
1713 // By default, just classify everything remaining as 'basic'.
1714 return TTI::TCC_Basic;
1715 }
1716
1718 auto *TargetTTI = static_cast<const T *>(this);
1719 SmallVector<const Value *, 4> Ops(I->operand_values());
1720 InstructionCost Cost = TargetTTI->getInstructionCost(
1723 }
1724
1725 bool supportsTailCallFor(const CallBase *CB) const override {
1726 return static_cast<const T *>(this)->supportsTailCalls();
1727 }
1728};
1729} // namespace llvm
1730
1731#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
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")))
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")))
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
This pass exposes codegen information to IR-level passes.
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:1339
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1497
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition APInt.cpp:1052
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:1571
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:195
const T & front() const
front - Get the first element.
Definition ArrayRef.h:145
iterator end() const
Definition ArrayRef.h:131
iterator begin() const
Definition ArrayRef.h:130
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:137
Class to represent array types.
A cache of @llvm.assume calls within a function.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Conditional or Unconditional Branch instruction.
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:676
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:164
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:22
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:802
The core instruction combiner logic.
static InstructionCost getInvalid(CostType Val=0)
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.
const SCEV * 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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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 bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
virtual InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const
virtual InstructionCost getMulAccReductionCost(bool IsUnsigned, unsigned RedOpcode, Type *ResTy, VectorType *Ty, TTI::TargetCostKind CostKind) const
virtual const DataLayout & getDataLayout() const
virtual bool preferFixedOverScalableIfEqualCost(bool IsEpilogue) 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 getFPOpCost(Type *Ty) const
virtual unsigned getMaxInterleaveFactor(ElementCount VF) 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 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1) 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 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) 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 unsigned getStoreMinimumVF(unsigned VF, Type *, Type *) 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 preferPredicateOverEpilogue(TailFoldingInfo *TFI) 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 bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const
virtual InstructionCost getVectorInstrCost(const Instruction &I, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) 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 bool isLegalAddScalableImmediate(int64_t Imm) const
virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace) 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 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 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 bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) 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 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 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 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 getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CxtI=nullptr) 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 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 InstructionUniformity getInstructionUniformity(const Value *V) 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 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 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx) 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 getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}) 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 InstructionCost getOperandsScalarizationOverhead(ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const
virtual TailFoldingStyle getPreferredTailFoldingStyle(bool IVUpdateMayOverflow=true) 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.
@ 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.
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.
CacheLevel
The possible cache levels.
This class represents a truncation of integer types.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:273
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:294
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:230
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:270
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:300
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:256
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:708
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
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_LogicalOr()
Matches L || R where L and R are arbitrary values.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Length
Definition DWP.cpp:532
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:1737
InstructionCost Cost
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:2544
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
FunctionAddr VTableAddr uintptr_t uintptr_t DataSize
Definition InstrProf.h:267
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:1744
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
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...
InstructionUniformity
Enum describing how instructions behave with respect to uniformity and divergence,...
Definition Uniformity.h:18
@ Default
The result values are 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:189
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.