LLVM 20.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
20#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/Operator.h"
25#include <optional>
26#include <utility>
27
28namespace llvm {
29
30class Function;
31
32/// Base class for use as a mix-in that aids implementing
33/// a TargetTransformInfo-compatible class.
35
36protected:
38
39 const DataLayout &DL;
40
42
43public:
44 // Provide value semantics. MSVC requires that we spell all of these out.
47
48 const DataLayout &getDataLayout() const { return DL; }
49
50 InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
53 // In the basic model, we just assume that all-constant GEPs will be folded
54 // into their uses via addressing modes.
55 for (const Value *Operand : Operands)
56 if (!isa<Constant>(Operand))
57 return TTI::TCC_Basic;
58
59 return TTI::TCC_Free;
60 }
61
63 unsigned &JTSize,
65 BlockFrequencyInfo *BFI) const {
66 (void)PSI;
67 (void)BFI;
68 JTSize = 0;
69 return SI.getNumCases();
70 }
71
72 unsigned getInliningThresholdMultiplier() const { return 1; }
75 return 8;
76 }
78 // This is the value of InlineConstants::LastCallToStaticBonus before it was
79 // removed along with the introduction of this function.
80 return 15000;
81 }
82 unsigned adjustInliningThreshold(const CallBase *CB) const { return 0; }
83 unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const {
84 return 0;
85 };
86
87 int getInlinerVectorBonusPercent() const { return 150; }
88
90 return TTI::TCC_Expensive;
91 }
92
94 return 64;
95 }
96
97 // Although this default value is arbitrary, it is not random. It is assumed
98 // that a condition that evaluates the same way by a higher percentage than
99 // this is best represented as control flow. Therefore, the default value N
100 // should be set such that the win from N% correct executions is greater than
101 // the loss from (100 - N)% mispredicted executions for the majority of
102 // intended targets.
104 return BranchProbability(99, 100);
105 }
106
108
109 bool hasBranchDivergence(const Function *F = nullptr) const { return false; }
110
111 bool isSourceOfDivergence(const Value *V) const { return false; }
112
113 bool isAlwaysUniform(const Value *V) const { return false; }
114
115 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const {
116 return false;
117 }
118
119 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
120 return true;
121 }
122
123 unsigned getFlatAddressSpace() const { return -1; }
124
126 Intrinsic::ID IID) const {
127 return false;
128 }
129
130 bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
132 return AS == 0;
133 };
134
135 unsigned getAssumedAddrSpace(const Value *V) const { return -1; }
136
137 bool isSingleThreaded() const { return false; }
138
139 std::pair<const Value *, unsigned>
141 return std::make_pair(nullptr, -1);
142 }
143
145 Value *NewV) const {
146 return nullptr;
147 }
148
149 bool isLoweredToCall(const Function *F) const {
150 assert(F && "A concrete function must be provided to this routine.");
151
152 // FIXME: These should almost certainly not be handled here, and instead
153 // handled with the help of TLI or the target itself. This was largely
154 // ported from existing analysis heuristics here so that such refactorings
155 // can take place in the future.
156
157 if (F->isIntrinsic())
158 return false;
159
160 if (F->hasLocalLinkage() || !F->hasName())
161 return true;
162
163 StringRef Name = F->getName();
164
165 // These will all likely lower to a single selection DAG node.
166 // clang-format off
167 if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
168 Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
169 Name == "fmin" || Name == "fminf" || Name == "fminl" ||
170 Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
171 Name == "sin" || Name == "sinf" || Name == "sinl" ||
172 Name == "cos" || Name == "cosf" || Name == "cosl" ||
173 Name == "tan" || Name == "tanf" || Name == "tanl" ||
174 Name == "asin" || Name == "asinf" || Name == "asinl" ||
175 Name == "acos" || Name == "acosf" || Name == "acosl" ||
176 Name == "atan" || Name == "atanf" || Name == "atanl" ||
177 Name == "atan2" || Name == "atan2f" || Name == "atan2l"||
178 Name == "sinh" || Name == "sinhf" || Name == "sinhl" ||
179 Name == "cosh" || Name == "coshf" || Name == "coshl" ||
180 Name == "tanh" || Name == "tanhf" || Name == "tanhl" ||
181 Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" ||
182 Name == "exp10" || Name == "exp10l" || Name == "exp10f")
183 return false;
184 // clang-format on
185 // These are all likely to be optimized into something smaller.
186 if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
187 Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
188 Name == "floorf" || Name == "ceil" || Name == "round" ||
189 Name == "ffs" || Name == "ffsl" || Name == "abs" || Name == "labs" ||
190 Name == "llabs")
191 return false;
192
193 return true;
194 }
195
198 HardwareLoopInfo &HWLoopInfo) const {
199 return false;
200 }
201
202 unsigned getEpilogueVectorizationMinVF() const { return 16; }
203
204 bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const { return false; }
205
207 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const {
209 }
210
211 std::optional<Instruction *> instCombineIntrinsic(InstCombiner &IC,
212 IntrinsicInst &II) const {
213 return std::nullopt;
214 }
215
216 std::optional<Value *>
218 APInt DemandedMask, KnownBits &Known,
219 bool &KnownBitsComputed) const {
220 return std::nullopt;
221 }
222
224 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
225 APInt &UndefElts2, APInt &UndefElts3,
226 std::function<void(Instruction *, unsigned, APInt, APInt &)>
227 SimplifyAndSetOp) const {
228 return std::nullopt;
229 }
230
233 OptimizationRemarkEmitter *) const {}
234
236 TTI::PeelingPreferences &) const {}
237
238 bool isLegalAddImmediate(int64_t Imm) const { return false; }
239
240 bool isLegalAddScalableImmediate(int64_t Imm) const { return false; }
241
242 bool isLegalICmpImmediate(int64_t Imm) const { return false; }
243
244 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
245 bool HasBaseReg, int64_t Scale, unsigned AddrSpace,
246 Instruction *I = nullptr,
247 int64_t ScalableOffset = 0) const {
248 // Guess that only reg and reg+reg addressing is allowed. This heuristic is
249 // taken from the implementation of LSR.
250 return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
251 }
252
253 bool isLSRCostLess(const TTI::LSRCost &C1, const TTI::LSRCost &C2) const {
254 return std::tie(C1.NumRegs, C1.AddRecCost, C1.NumIVMuls, C1.NumBaseAdds,
255 C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
256 std::tie(C2.NumRegs, C2.AddRecCost, C2.NumIVMuls, C2.NumBaseAdds,
257 C2.ScaleCost, C2.ImmCost, C2.SetupCost);
258 }
259
260 bool isNumRegsMajorCostOfLSR() const { return true; }
261
262 bool shouldDropLSRSolutionIfLessProfitable() const { return false; }
263
264 bool isProfitableLSRChainElement(Instruction *I) const { return false; }
265
266 bool canMacroFuseCmp() const { return false; }
267
270 TargetLibraryInfo *LibInfo) const {
271 return false;
272 }
273
276 return TTI::AMK_None;
277 }
278
279 bool isLegalMaskedStore(Type *DataType, Align Alignment) const {
280 return false;
281 }
282
283 bool isLegalMaskedLoad(Type *DataType, Align Alignment) const {
284 return false;
285 }
286
287 bool isLegalNTStore(Type *DataType, Align Alignment) const {
288 // By default, assume nontemporal memory stores are available for stores
289 // that are aligned and have a size that is a power of 2.
290 unsigned DataSize = DL.getTypeStoreSize(DataType);
291 return Alignment >= DataSize && isPowerOf2_32(DataSize);
292 }
293
294 bool isLegalNTLoad(Type *DataType, Align Alignment) const {
295 // By default, assume nontemporal memory loads are available for loads that
296 // are aligned and have a size that is a power of 2.
297 unsigned DataSize = DL.getTypeStoreSize(DataType);
298 return Alignment >= DataSize && isPowerOf2_32(DataSize);
299 }
300
301 bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const {
302 return false;
303 }
304
305 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const {
306 return false;
307 }
308
309 bool isLegalMaskedGather(Type *DataType, Align Alignment) const {
310 return false;
311 }
312
313 bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment) const {
314 return false;
315 }
316
318 Align Alignment) const {
319 return false;
320 }
321
322 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const {
323 return false;
324 }
325
326 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
327 const SmallBitVector &OpcodeMask) const {
328 return false;
329 }
330
331 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const {
332 return false;
333 }
334
335 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const {
336 return false;
337 }
338
339 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
340 Align Alignment, unsigned AddrSpace) {
341 return false;
342 }
343
344 bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const {
345 return false;
346 }
347
348 bool enableOrderedReductions() const { return false; }
349
350 bool hasDivRemOp(Type *DataType, bool IsSigned) const { return false; }
351
352 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const {
353 return false;
354 }
355
356 bool prefersVectorizedAddressing() const { return true; }
357
359 StackOffset BaseOffset, bool HasBaseReg,
360 int64_t Scale,
361 unsigned AddrSpace) const {
362 // Guess that all legal addressing mode are free.
363 if (isLegalAddressingMode(Ty, BaseGV, BaseOffset.getFixed(), HasBaseReg,
364 Scale, AddrSpace, /*I=*/nullptr,
365 BaseOffset.getScalable()))
366 return 0;
367 return -1;
368 }
369
370 bool LSRWithInstrQueries() const { return false; }
371
372 bool isTruncateFree(Type *Ty1, Type *Ty2) const { return false; }
373
374 bool isProfitableToHoist(Instruction *I) const { return true; }
375
376 bool useAA() const { return false; }
377
378 bool isTypeLegal(Type *Ty) const { return false; }
379
380 unsigned getRegUsageForType(Type *Ty) const { return 1; }
381
382 bool shouldBuildLookupTables() const { return true; }
383
384 bool shouldBuildLookupTablesForConstant(Constant *C) const { return true; }
385
386 bool shouldBuildRelLookupTables() const { return false; }
387
388 bool useColdCCForColdCall(Function &F) const { return false; }
389
391 return false;
392 }
393
395 unsigned ScalarOpdIdx) const {
396 return false;
397 }
398
400 int OpdIdx) const {
401 return OpdIdx == -1;
402 }
403
405 int RetIdx) const {
406 return RetIdx == 0;
407 }
408
410 const APInt &DemandedElts,
411 bool Insert, bool Extract,
413 ArrayRef<Value *> VL = {}) const {
414 return 0;
415 }
416
417 InstructionCost
421 return 0;
422 }
423
424 bool supportsEfficientVectorElementLoadStore() const { return false; }
425
426 bool supportsTailCalls() const { return true; }
427
428 bool enableAggressiveInterleaving(bool LoopHasReductions) const {
429 return false;
430 }
431
433 bool IsZeroCmp) const {
434 return {};
435 }
436
437 bool enableSelectOptimize() const { return true; }
438
440 // A select with two constant operands will usually be better left as a
441 // select.
442 using namespace llvm::PatternMatch;
444 return false;
445 // If the select is a logical-and/logical-or then it is better treated as a
446 // and/or by the backend.
447 return isa<SelectInst>(I) &&
450 }
451
452 bool enableInterleavedAccessVectorization() const { return false; }
453
454 bool enableMaskedInterleavedAccessVectorization() const { return false; }
455
456 bool isFPVectorizationPotentiallyUnsafe() const { return false; }
457
459 unsigned AddressSpace, Align Alignment,
460 unsigned *Fast) const {
461 return false;
462 }
463
464 TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const {
465 return TTI::PSK_Software;
466 }
467
468 bool haveFastSqrt(Type *Ty) const { return false; }
469
470 bool isExpensiveToSpeculativelyExecute(const Instruction *I) { return true; }
471
472 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return true; }
473
476 }
477
478 InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
479 const APInt &Imm, Type *Ty) const {
480 return 0;
481 }
482
485 return TTI::TCC_Basic;
486 }
487
488 InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
489 const APInt &Imm, Type *Ty,
491 Instruction *Inst = nullptr) const {
492 return TTI::TCC_Free;
493 }
494
496 const APInt &Imm, Type *Ty,
498 return TTI::TCC_Free;
499 }
500
502 const Function &Fn) const {
503 return false;
504 }
505
506 unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
507 bool hasConditionalLoadStoreForType(Type *Ty) const { return false; }
508
509 unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const {
510 return Vector ? 1 : 0;
511 };
512
513 const char *getRegisterClassName(unsigned ClassID) const {
514 switch (ClassID) {
515 default:
516 return "Generic::Unknown Register Class";
517 case 0:
518 return "Generic::ScalarRC";
519 case 1:
520 return "Generic::VectorRC";
521 }
522 }
523
525 return TypeSize::getFixed(32);
526 }
527
528 unsigned getMinVectorRegisterBitWidth() const { return 128; }
529
530 std::optional<unsigned> getMaxVScale() const { return std::nullopt; }
531 std::optional<unsigned> getVScaleForTuning() const { return std::nullopt; }
532 bool isVScaleKnownToBeAPowerOfTwo() const { return false; }
533
534 bool
536 return false;
537 }
538
539 ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const {
540 return ElementCount::get(0, IsScalable);
541 }
542
543 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const { return 0; }
544 unsigned getStoreMinimumVF(unsigned VF, Type *, Type *) const { return VF; }
545
547 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
548 AllowPromotionWithoutCommonHeader = false;
549 return false;
550 }
551
552 unsigned getCacheLineSize() const { return 0; }
553 std::optional<unsigned>
555 switch (Level) {
557 [[fallthrough]];
559 return std::nullopt;
560 }
561 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
562 }
563
564 std::optional<unsigned>
566 switch (Level) {
568 [[fallthrough]];
570 return std::nullopt;
571 }
572
573 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
574 }
575
576 std::optional<unsigned> getMinPageSize() const { return {}; }
577
578 unsigned getPrefetchDistance() const { return 0; }
579 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
580 unsigned NumStridedMemAccesses,
581 unsigned NumPrefetches, bool HasCall) const {
582 return 1;
583 }
584 unsigned getMaxPrefetchIterationsAhead() const { return UINT_MAX; }
585 bool enableWritePrefetching() const { return false; }
586 bool shouldPrefetchAddressSpace(unsigned AS) const { return !AS; }
587
589 getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB,
590 Type *AccumType, ElementCount VF,
593 std::optional<unsigned> BinOp = std::nullopt) const {
595 }
596
597 unsigned getMaxInterleaveFactor(ElementCount VF) const { return 1; }
598
600 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
603 const Instruction *CxtI = nullptr) const {
604 // Widenable conditions will eventually lower into constants, so some
605 // operations with them will be trivially optimized away.
606 auto IsWidenableCondition = [](const Value *V) {
607 if (auto *II = dyn_cast<IntrinsicInst>(V))
608 if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
609 return true;
610 return false;
611 };
612 // FIXME: A number of transformation tests seem to require these values
613 // which seems a little odd for how arbitary there are.
614 switch (Opcode) {
615 default:
616 break;
617 case Instruction::FDiv:
618 case Instruction::FRem:
619 case Instruction::SDiv:
620 case Instruction::SRem:
621 case Instruction::UDiv:
622 case Instruction::URem:
623 // FIXME: Unlikely to be true for CodeSize.
624 return TTI::TCC_Expensive;
625 case Instruction::And:
626 case Instruction::Or:
627 if (any_of(Args, IsWidenableCondition))
628 return TTI::TCC_Free;
629 break;
630 }
631
632 // Assume a 3cy latency for fp arithmetic ops.
634 if (Ty->getScalarType()->isFloatingPointTy())
635 return 3;
636
637 return 1;
638 }
639
641 unsigned Opcode1,
642 const SmallBitVector &OpcodeMask,
645 }
646
648 ArrayRef<int> Mask,
650 VectorType *SubTp,
651 ArrayRef<const Value *> Args = {},
652 const Instruction *CxtI = nullptr) const {
653 return 1;
654 }
655
656 InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
659 const Instruction *I) const {
660 switch (Opcode) {
661 default:
662 break;
663 case Instruction::IntToPtr: {
664 unsigned SrcSize = Src->getScalarSizeInBits();
665 if (DL.isLegalInteger(SrcSize) &&
666 SrcSize <= DL.getPointerTypeSizeInBits(Dst))
667 return 0;
668 break;
669 }
670 case Instruction::PtrToInt: {
671 unsigned DstSize = Dst->getScalarSizeInBits();
672 if (DL.isLegalInteger(DstSize) &&
673 DstSize >= DL.getPointerTypeSizeInBits(Src))
674 return 0;
675 break;
676 }
677 case Instruction::BitCast:
678 if (Dst == Src || (Dst->isPointerTy() && Src->isPointerTy()))
679 // Identity and pointer-to-pointer casts are free.
680 return 0;
681 break;
682 case Instruction::Trunc: {
683 // trunc to a native type is free (assuming the target has compare and
684 // shift-right of the same width).
685 TypeSize DstSize = DL.getTypeSizeInBits(Dst);
686 if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedValue()))
687 return 0;
688 break;
689 }
690 }
691 return 1;
692 }
693
695 VectorType *VecTy,
696 unsigned Index) const {
697 return 1;
698 }
699
701 const Instruction *I = nullptr) const {
702 // A phi would be free, unless we're costing the throughput because it
703 // will require a register.
704 if (Opcode == Instruction::PHI && CostKind != TTI::TCK_RecipThroughput)
705 return 0;
706 return 1;
707 }
708
709 InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
710 CmpInst::Predicate VecPred,
712 TTI::OperandValueInfo Op1Info,
713 TTI::OperandValueInfo Op2Info,
714 const Instruction *I) const {
715 return 1;
716 }
717
720 unsigned Index, Value *Op0,
721 Value *Op1) const {
722 return 1;
723 }
724
725 /// \param ScalarUserAndIdx encodes the information about extracts from a
726 /// vector with 'Scalar' being the value being extracted,'User' being the user
727 /// of the extract(nullptr if user is not known before vectorization) and
728 /// 'Idx' being the extract lane.
730 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
731 Value *Scalar,
732 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
733 return 1;
734 }
735
738 unsigned Index) const {
739 return 1;
740 }
741
742 unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
743 const APInt &DemandedDstElts,
745 return 1;
746 }
747
748 InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
749 unsigned AddressSpace,
752 const Instruction *I) const {
753 return 1;
754 }
755
756 InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
757 unsigned AddressSpace,
759 const Instruction *I) const {
760 return 1;
761 }
762
764 Align Alignment, unsigned AddressSpace,
766 return 1;
767 }
768
770 const Value *Ptr, bool VariableMask,
771 Align Alignment,
773 const Instruction *I = nullptr) const {
774 return 1;
775 }
776
778 const Value *Ptr, bool VariableMask,
779 Align Alignment,
781 const Instruction *I = nullptr) const {
783 }
784
786 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
787 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
788 bool UseMaskForCond, bool UseMaskForGaps) const {
789 return 1;
790 }
791
794 switch (ICA.getID()) {
795 default:
796 break;
797 case Intrinsic::experimental_vector_histogram_add:
798 // For now, we want explicit support from the target for histograms.
800 case Intrinsic::allow_runtime_check:
801 case Intrinsic::allow_ubsan_check:
802 case Intrinsic::annotation:
803 case Intrinsic::assume:
804 case Intrinsic::sideeffect:
805 case Intrinsic::pseudoprobe:
806 case Intrinsic::arithmetic_fence:
807 case Intrinsic::dbg_assign:
808 case Intrinsic::dbg_declare:
809 case Intrinsic::dbg_value:
810 case Intrinsic::dbg_label:
811 case Intrinsic::invariant_start:
812 case Intrinsic::invariant_end:
813 case Intrinsic::launder_invariant_group:
814 case Intrinsic::strip_invariant_group:
815 case Intrinsic::is_constant:
816 case Intrinsic::lifetime_start:
817 case Intrinsic::lifetime_end:
818 case Intrinsic::experimental_noalias_scope_decl:
819 case Intrinsic::objectsize:
820 case Intrinsic::ptr_annotation:
821 case Intrinsic::var_annotation:
822 case Intrinsic::experimental_gc_result:
823 case Intrinsic::experimental_gc_relocate:
824 case Intrinsic::coro_alloc:
825 case Intrinsic::coro_begin:
826 case Intrinsic::coro_begin_custom_abi:
827 case Intrinsic::coro_free:
828 case Intrinsic::coro_end:
829 case Intrinsic::coro_frame:
830 case Intrinsic::coro_size:
831 case Intrinsic::coro_align:
832 case Intrinsic::coro_suspend:
833 case Intrinsic::coro_subfn_addr:
834 case Intrinsic::threadlocal_address:
835 case Intrinsic::experimental_widenable_condition:
836 case Intrinsic::ssa_copy:
837 // These intrinsics don't actually represent code after lowering.
838 return 0;
839 }
840 return 1;
841 }
842
846 return 1;
847 }
848
849 // Assume that we have a register of the right size for the type.
850 unsigned getNumberOfParts(Type *Tp) const { return 1; }
851
853 const SCEV *) const {
854 return 0;
855 }
856
858 std::optional<FastMathFlags> FMF,
859 TTI::TargetCostKind) const {
860 return 1;
861 }
862
865 TTI::TargetCostKind) const {
866 return 1;
867 }
868
869 InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned,
870 Type *ResTy, VectorType *Ty,
871 FastMathFlags FMF,
873 return 1;
874 }
875
877 VectorType *Ty,
879 return 1;
880 }
881
883 return 0;
884 }
885
887 return false;
888 }
889
891 // Note for overrides: You must ensure for all element unordered-atomic
892 // memory intrinsics that all power-of-2 element sizes up to, and
893 // including, the return value of this method have a corresponding
894 // runtime lib call. These runtime lib call definitions can be found
895 // in RuntimeLibcalls.h
896 return 0;
897 }
898
900 Type *ExpectedType) const {
901 return nullptr;
902 }
903
904 Type *
906 unsigned SrcAddrSpace, unsigned DestAddrSpace,
907 Align SrcAlign, Align DestAlign,
908 std::optional<uint32_t> AtomicElementSize) const {
909 return AtomicElementSize ? Type::getIntNTy(Context, *AtomicElementSize * 8)
910 : Type::getInt8Ty(Context);
911 }
912
914 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
915 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
916 Align SrcAlign, Align DestAlign,
917 std::optional<uint32_t> AtomicCpySize) const {
918 unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
919 Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
920 for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
921 OpsOut.push_back(OpType);
922 }
923
924 bool areInlineCompatible(const Function *Caller,
925 const Function *Callee) const {
926 return (Caller->getFnAttribute("target-cpu") ==
927 Callee->getFnAttribute("target-cpu")) &&
928 (Caller->getFnAttribute("target-features") ==
929 Callee->getFnAttribute("target-features"));
930 }
931
932 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
933 unsigned DefaultCallPenalty) const {
934 return DefaultCallPenalty;
935 }
936
937 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
938 const ArrayRef<Type *> &Types) const {
939 return (Caller->getFnAttribute("target-cpu") ==
940 Callee->getFnAttribute("target-cpu")) &&
941 (Caller->getFnAttribute("target-features") ==
942 Callee->getFnAttribute("target-features"));
943 }
944
946 const DataLayout &DL) const {
947 return false;
948 }
949
951 const DataLayout &DL) const {
952 return false;
953 }
954
955 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const { return 128; }
956
957 bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
958
959 bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
960
961 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
962 unsigned AddrSpace) const {
963 return true;
964 }
965
966 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
967 unsigned AddrSpace) const {
968 return true;
969 }
970
972 ElementCount VF) const {
973 return true;
974 }
975
976 bool isElementTypeLegalForScalableVector(Type *Ty) const { return true; }
977
978 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
979 unsigned ChainSizeInBytes,
980 VectorType *VecTy) const {
981 return VF;
982 }
983
984 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
985 unsigned ChainSizeInBytes,
986 VectorType *VecTy) const {
987 return VF;
988 }
989
990 bool preferFixedOverScalableIfEqualCost() const { return false; }
991
992 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
993 TTI::ReductionFlags Flags) const {
994 return false;
995 }
996
997 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
998 TTI::ReductionFlags Flags) const {
999 return false;
1000 }
1001
1003 return true;
1004 }
1005
1006 bool shouldExpandReduction(const IntrinsicInst *II) const { return true; }
1007
1011 }
1012
1013 unsigned getGISelRematGlobalCost() const { return 1; }
1014
1015 unsigned getMinTripCountTailFoldingThreshold() const { return 0; }
1016
1017 bool supportsScalableVectors() const { return false; }
1018
1019 bool enableScalableVectorization() const { return false; }
1020
1021 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
1022 Align Alignment) const {
1023 return false;
1024 }
1025
1027 SmallVectorImpl<Use *> &Ops) const {
1028 return false;
1029 }
1030
1031 bool isVectorShiftByScalarCheap(Type *Ty) const { return false; }
1032
1036 /* EVLParamStrategy */ TargetTransformInfo::VPLegalization::Discard,
1037 /* OperatorStrategy */ TargetTransformInfo::VPLegalization::Convert);
1038 }
1039
1040 bool hasArmWideBranch(bool) const { return false; }
1041
1042 uint64_t getFeatureMask(const Function &F) const { return 0; }
1043
1044 bool isMultiversionedFunction(const Function &F) const { return false; }
1045
1046 unsigned getMaxNumArgs() const { return UINT_MAX; }
1047
1048 unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const {
1049 return 0;
1050 }
1051
1052protected:
1053 // Obtain the minimum required size to hold the value (without the sign)
1054 // In case of a vector it returns the min required size for one element.
1055 unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const {
1056 if (isa<ConstantDataVector>(Val) || isa<ConstantVector>(Val)) {
1057 const auto *VectorValue = cast<Constant>(Val);
1058
1059 // In case of a vector need to pick the max between the min
1060 // required size for each element
1061 auto *VT = cast<FixedVectorType>(Val->getType());
1062
1063 // Assume unsigned elements
1064 isSigned = false;
1065
1066 // The max required size is the size of the vector element type
1067 unsigned MaxRequiredSize =
1068 VT->getElementType()->getPrimitiveSizeInBits().getFixedValue();
1069
1070 unsigned MinRequiredSize = 0;
1071 for (unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
1072 if (auto *IntElement =
1073 dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
1074 bool signedElement = IntElement->getValue().isNegative();
1075 // Get the element min required size.
1076 unsigned ElementMinRequiredSize =
1077 IntElement->getValue().getSignificantBits() - 1;
1078 // In case one element is signed then all the vector is signed.
1079 isSigned |= signedElement;
1080 // Save the max required bit size between all the elements.
1081 MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
1082 } else {
1083 // not an int constant element
1084 return MaxRequiredSize;
1085 }
1086 }
1087 return MinRequiredSize;
1088 }
1089
1090 if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
1091 isSigned = CI->getValue().isNegative();
1092 return CI->getValue().getSignificantBits() - 1;
1093 }
1094
1095 if (const auto *Cast = dyn_cast<SExtInst>(Val)) {
1096 isSigned = true;
1097 return Cast->getSrcTy()->getScalarSizeInBits() - 1;
1098 }
1099
1100 if (const auto *Cast = dyn_cast<ZExtInst>(Val)) {
1101 isSigned = false;
1102 return Cast->getSrcTy()->getScalarSizeInBits();
1103 }
1104
1105 isSigned = false;
1106 return Val->getType()->getScalarSizeInBits();
1107 }
1108
1109 bool isStridedAccess(const SCEV *Ptr) const {
1110 return Ptr && isa<SCEVAddRecExpr>(Ptr);
1111 }
1112
1114 const SCEV *Ptr) const {
1115 if (!isStridedAccess(Ptr))
1116 return nullptr;
1117 const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
1118 return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
1119 }
1120
1122 int64_t MergeDistance) const {
1123 const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
1124 if (!Step)
1125 return false;
1126 APInt StrideVal = Step->getAPInt();
1127 if (StrideVal.getBitWidth() > 64)
1128 return false;
1129 // FIXME: Need to take absolute value for negative stride case.
1130 return StrideVal.getSExtValue() < MergeDistance;
1131 }
1132};
1133
1134/// CRTP base class for use as a mix-in that aids implementing
1135/// a TargetTransformInfo-compatible class.
1136template <typename T>
1138private:
1140
1141protected:
1143
1144public:
1146
1150 assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
1151 auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
1152 bool HasBaseReg = (BaseGV == nullptr);
1153
1154 auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
1155 APInt BaseOffset(PtrSizeBits, 0);
1156 int64_t Scale = 0;
1157
1158 auto GTI = gep_type_begin(PointeeType, Operands);
1159 Type *TargetType = nullptr;
1160
1161 // Handle the case where the GEP instruction has a single operand,
1162 // the basis, therefore TargetType is a nullptr.
1163 if (Operands.empty())
1164 return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
1165
1166 for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
1167 TargetType = GTI.getIndexedType();
1168 // We assume that the cost of Scalar GEP with constant index and the
1169 // cost of Vector GEP with splat constant index are the same.
1170 const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
1171 if (!ConstIdx)
1172 if (auto Splat = getSplatValue(*I))
1173 ConstIdx = dyn_cast<ConstantInt>(Splat);
1174 if (StructType *STy = GTI.getStructTypeOrNull()) {
1175 // For structures the index is always splat or scalar constant
1176 assert(ConstIdx && "Unexpected GEP index");
1177 uint64_t Field = ConstIdx->getZExtValue();
1178 BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
1179 } else {
1180 // If this operand is a scalable type, bail out early.
1181 // TODO: Make isLegalAddressingMode TypeSize aware.
1182 if (TargetType->isScalableTy())
1183 return TTI::TCC_Basic;
1184 int64_t ElementSize =
1185 GTI.getSequentialElementStride(DL).getFixedValue();
1186 if (ConstIdx) {
1187 BaseOffset +=
1188 ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
1189 } else {
1190 // Needs scale register.
1191 if (Scale != 0)
1192 // No addressing mode takes two scale registers.
1193 return TTI::TCC_Basic;
1194 Scale = ElementSize;
1195 }
1196 }
1197 }
1198
1199 // If we haven't been provided a hint, use the target type for now.
1200 //
1201 // TODO: Take a look at potentially removing this: This is *slightly* wrong
1202 // as it's possible to have a GEP with a foldable target type but a memory
1203 // access that isn't foldable. For example, this load isn't foldable on
1204 // RISC-V:
1205 //
1206 // %p = getelementptr i32, ptr %base, i32 42
1207 // %x = load <2 x i32>, ptr %p
1208 if (!AccessType)
1209 AccessType = TargetType;
1210
1211 // If the final address of the GEP is a legal addressing mode for the given
1212 // access type, then we can fold it into its users.
1213 if (static_cast<T *>(this)->isLegalAddressingMode(
1214 AccessType, const_cast<GlobalValue *>(BaseGV),
1215 BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
1216 Ptr->getType()->getPointerAddressSpace()))
1217 return TTI::TCC_Free;
1218
1219 // TODO: Instead of returning TCC_Basic here, we should use
1220 // getArithmeticInstrCost. Or better yet, provide a hook to let the target
1221 // model it.
1222 return TTI::TCC_Basic;
1223 }
1224
1226 const Value *Base,
1228 Type *AccessTy,
1231 // In the basic model we take into account GEP instructions only
1232 // (although here can come alloca instruction, a value, constants and/or
1233 // constant expressions, PHIs, bitcasts ... whatever allowed to be used as a
1234 // pointer). Typically, if Base is a not a GEP-instruction and all the
1235 // pointers are relative to the same base address, all the rest are
1236 // either GEP instructions, PHIs, bitcasts or constants. When we have same
1237 // base, we just calculate cost of each non-Base GEP as an ADD operation if
1238 // any their index is a non-const.
1239 // If no known dependecies between the pointers cost is calculated as a sum
1240 // of costs of GEP instructions.
1241 for (const Value *V : Ptrs) {
1242 const auto *GEP = dyn_cast<GetElementPtrInst>(V);
1243 if (!GEP)
1244 continue;
1245 if (Info.isSameBase() && V != Base) {
1246 if (GEP->hasAllConstantIndices())
1247 continue;
1248 Cost += static_cast<T *>(this)->getArithmeticInstrCost(
1249 Instruction::Add, GEP->getType(), CostKind,
1251 {});
1252 } else {
1253 SmallVector<const Value *> Indices(GEP->indices());
1254 Cost += static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
1255 GEP->getPointerOperand(),
1256 Indices, AccessTy, CostKind);
1257 }
1258 }
1259 return Cost;
1260 }
1261
1265 using namespace llvm::PatternMatch;
1266
1267 auto *TargetTTI = static_cast<T *>(this);
1268 // Handle non-intrinsic calls, invokes, and callbr.
1269 // FIXME: Unlikely to be true for anything but CodeSize.
1270 auto *CB = dyn_cast<CallBase>(U);
1271 if (CB && !isa<IntrinsicInst>(U)) {
1272 if (const Function *F = CB->getCalledFunction()) {
1273 if (!TargetTTI->isLoweredToCall(F))
1274 return TTI::TCC_Basic; // Give a basic cost if it will be lowered
1275
1276 return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
1277 }
1278 // For indirect or other calls, scale cost by number of arguments.
1279 return TTI::TCC_Basic * (CB->arg_size() + 1);
1280 }
1281
1282 Type *Ty = U->getType();
1283 unsigned Opcode = Operator::getOpcode(U);
1284 auto *I = dyn_cast<Instruction>(U);
1285 switch (Opcode) {
1286 default:
1287 break;
1288 case Instruction::Call: {
1289 assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
1290 auto *Intrinsic = cast<IntrinsicInst>(U);
1291 IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
1292 return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
1293 }
1294 case Instruction::Br:
1295 case Instruction::Ret:
1296 case Instruction::PHI:
1297 case Instruction::Switch:
1298 return TargetTTI->getCFInstrCost(Opcode, CostKind, I);
1299 case Instruction::ExtractValue:
1300 case Instruction::Freeze:
1301 return TTI::TCC_Free;
1302 case Instruction::Alloca:
1303 if (cast<AllocaInst>(U)->isStaticAlloca())
1304 return TTI::TCC_Free;
1305 break;
1306 case Instruction::GetElementPtr: {
1307 const auto *GEP = cast<GEPOperator>(U);
1308 Type *AccessType = nullptr;
1309 // For now, only provide the AccessType in the simple case where the GEP
1310 // only has one user.
1311 if (GEP->hasOneUser() && I)
1312 AccessType = I->user_back()->getAccessType();
1313
1314 return TargetTTI->getGEPCost(GEP->getSourceElementType(),
1315 Operands.front(), Operands.drop_front(),
1316 AccessType, CostKind);
1317 }
1318 case Instruction::Add:
1319 case Instruction::FAdd:
1320 case Instruction::Sub:
1321 case Instruction::FSub:
1322 case Instruction::Mul:
1323 case Instruction::FMul:
1324 case Instruction::UDiv:
1325 case Instruction::SDiv:
1326 case Instruction::FDiv:
1327 case Instruction::URem:
1328 case Instruction::SRem:
1329 case Instruction::FRem:
1330 case Instruction::Shl:
1331 case Instruction::LShr:
1332 case Instruction::AShr:
1333 case Instruction::And:
1334 case Instruction::Or:
1335 case Instruction::Xor:
1336 case Instruction::FNeg: {
1338 TTI::OperandValueInfo Op2Info;
1339 if (Opcode != Instruction::FNeg)
1340 Op2Info = TTI::getOperandInfo(Operands[1]);
1341 return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
1342 Op2Info, Operands, I);
1343 }
1344 case Instruction::IntToPtr:
1345 case Instruction::PtrToInt:
1346 case Instruction::SIToFP:
1347 case Instruction::UIToFP:
1348 case Instruction::FPToUI:
1349 case Instruction::FPToSI:
1350 case Instruction::Trunc:
1351 case Instruction::FPTrunc:
1352 case Instruction::BitCast:
1353 case Instruction::FPExt:
1354 case Instruction::SExt:
1355 case Instruction::ZExt:
1356 case Instruction::AddrSpaceCast: {
1357 Type *OpTy = Operands[0]->getType();
1358 return TargetTTI->getCastInstrCost(
1359 Opcode, Ty, OpTy, TTI::getCastContextHint(I), CostKind, I);
1360 }
1361 case Instruction::Store: {
1362 auto *SI = cast<StoreInst>(U);
1363 Type *ValTy = Operands[0]->getType();
1365 return TargetTTI->getMemoryOpCost(Opcode, ValTy, SI->getAlign(),
1366 SI->getPointerAddressSpace(), CostKind,
1367 OpInfo, I);
1368 }
1369 case Instruction::Load: {
1370 // FIXME: Arbitary cost which could come from the backend.
1372 return 4;
1373 auto *LI = cast<LoadInst>(U);
1374 Type *LoadType = U->getType();
1375 // If there is a non-register sized type, the cost estimation may expand
1376 // it to be several instructions to load into multiple registers on the
1377 // target. But, if the only use of the load is a trunc instruction to a
1378 // register sized type, the instruction selector can combine these
1379 // instructions to be a single load. So, in this case, we use the
1380 // destination type of the trunc instruction rather than the load to
1381 // accurately estimate the cost of this load instruction.
1382 if (CostKind == TTI::TCK_CodeSize && LI->hasOneUse() &&
1383 !LoadType->isVectorTy()) {
1384 if (const TruncInst *TI = dyn_cast<TruncInst>(*LI->user_begin()))
1385 LoadType = TI->getDestTy();
1386 }
1387 return TargetTTI->getMemoryOpCost(Opcode, LoadType, LI->getAlign(),
1389 {TTI::OK_AnyValue, TTI::OP_None}, I);
1390 }
1391 case Instruction::Select: {
1392 const Value *Op0, *Op1;
1393 if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
1394 match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
1395 // select x, y, false --> x & y
1396 // select x, true, y --> x | y
1397 const auto Op1Info = TTI::getOperandInfo(Op0);
1398 const auto Op2Info = TTI::getOperandInfo(Op1);
1399 assert(Op0->getType()->getScalarSizeInBits() == 1 &&
1400 Op1->getType()->getScalarSizeInBits() == 1);
1401
1403 return TargetTTI->getArithmeticInstrCost(
1404 match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
1405 CostKind, Op1Info, Op2Info, Operands, I);
1406 }
1407 const auto Op1Info = TTI::getOperandInfo(Operands[1]);
1408 const auto Op2Info = TTI::getOperandInfo(Operands[2]);
1409 Type *CondTy = Operands[0]->getType();
1410 return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,
1412 CostKind, Op1Info, Op2Info, I);
1413 }
1414 case Instruction::ICmp:
1415 case Instruction::FCmp: {
1416 const auto Op1Info = TTI::getOperandInfo(Operands[0]);
1417 const auto Op2Info = TTI::getOperandInfo(Operands[1]);
1418 Type *ValTy = Operands[0]->getType();
1419 // TODO: Also handle ICmp/FCmp constant expressions.
1420 return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(),
1421 I ? cast<CmpInst>(I)->getPredicate()
1423 CostKind, Op1Info, Op2Info, I);
1424 }
1425 case Instruction::InsertElement: {
1426 auto *IE = dyn_cast<InsertElementInst>(U);
1427 if (!IE)
1428 return TTI::TCC_Basic; // FIXME
1429 unsigned Idx = -1;
1430 if (auto *CI = dyn_cast<ConstantInt>(Operands[2]))
1431 if (CI->getValue().getActiveBits() <= 32)
1432 Idx = CI->getZExtValue();
1433 return TargetTTI->getVectorInstrCost(*IE, Ty, CostKind, Idx);
1434 }
1435 case Instruction::ShuffleVector: {
1436 auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
1437 if (!Shuffle)
1438 return TTI::TCC_Basic; // FIXME
1439
1440 auto *VecTy = cast<VectorType>(U->getType());
1441 auto *VecSrcTy = cast<VectorType>(Operands[0]->getType());
1442 ArrayRef<int> Mask = Shuffle->getShuffleMask();
1443 int NumSubElts, SubIndex;
1444
1445 // TODO: move more of this inside improveShuffleKindFromMask.
1446 if (Shuffle->changesLength()) {
1447 // Treat a 'subvector widening' as a free shuffle.
1448 if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding())
1449 return 0;
1450
1451 if (Shuffle->isExtractSubvectorMask(SubIndex))
1452 return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecSrcTy,
1453 Mask, CostKind, SubIndex, VecTy,
1454 Operands, Shuffle);
1455
1456 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1457 return TargetTTI->getShuffleCost(
1458 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1459 FixedVectorType::get(VecTy->getScalarType(), NumSubElts),
1460 Operands, Shuffle);
1461
1462 int ReplicationFactor, VF;
1463 if (Shuffle->isReplicationMask(ReplicationFactor, VF)) {
1464 APInt DemandedDstElts = APInt::getZero(Mask.size());
1465 for (auto I : enumerate(Mask)) {
1466 if (I.value() != PoisonMaskElem)
1467 DemandedDstElts.setBit(I.index());
1468 }
1469 return TargetTTI->getReplicationShuffleCost(
1470 VecSrcTy->getElementType(), ReplicationFactor, VF,
1471 DemandedDstElts, CostKind);
1472 }
1473
1474 bool IsUnary = isa<UndefValue>(Operands[1]);
1475 NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
1476 SmallVector<int, 16> AdjustMask(Mask);
1477
1478 // Widening shuffle - widening the source(s) to the new length
1479 // (treated as free - see above), and then perform the adjusted
1480 // shuffle at that width.
1481 if (Shuffle->increasesLength()) {
1482 for (int &M : AdjustMask)
1483 M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
1484
1485 return TargetTTI->getShuffleCost(
1487 AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1488 }
1489
1490 // Narrowing shuffle - perform shuffle at original wider width and
1491 // then extract the lower elements.
1492 AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
1493
1494 InstructionCost ShuffleCost = TargetTTI->getShuffleCost(
1496 VecSrcTy, AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1497
1498 SmallVector<int, 16> ExtractMask(Mask.size());
1499 std::iota(ExtractMask.begin(), ExtractMask.end(), 0);
1500 return ShuffleCost + TargetTTI->getShuffleCost(
1501 TTI::SK_ExtractSubvector, VecSrcTy,
1502 ExtractMask, CostKind, 0, VecTy, {}, Shuffle);
1503 }
1504
1505 if (Shuffle->isIdentity())
1506 return 0;
1507
1508 if (Shuffle->isReverse())
1509 return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, Mask, CostKind,
1510 0, nullptr, Operands, Shuffle);
1511
1512 if (Shuffle->isSelect())
1513 return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, Mask, CostKind,
1514 0, nullptr, Operands, Shuffle);
1515
1516 if (Shuffle->isTranspose())
1517 return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, Mask,
1518 CostKind, 0, nullptr, Operands,
1519 Shuffle);
1520
1521 if (Shuffle->isZeroEltSplat())
1522 return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, Mask,
1523 CostKind, 0, nullptr, Operands,
1524 Shuffle);
1525
1526 if (Shuffle->isSingleSource())
1527 return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy, Mask,
1528 CostKind, 0, nullptr, Operands,
1529 Shuffle);
1530
1531 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1532 return TargetTTI->getShuffleCost(
1533 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1534 FixedVectorType::get(VecTy->getScalarType(), NumSubElts), Operands,
1535 Shuffle);
1536
1537 if (Shuffle->isSplice(SubIndex))
1538 return TargetTTI->getShuffleCost(TTI::SK_Splice, VecTy, Mask, CostKind,
1539 SubIndex, nullptr, Operands, Shuffle);
1540
1541 return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, Mask,
1542 CostKind, 0, nullptr, Operands, Shuffle);
1543 }
1544 case Instruction::ExtractElement: {
1545 auto *EEI = dyn_cast<ExtractElementInst>(U);
1546 if (!EEI)
1547 return TTI::TCC_Basic; // FIXME
1548 unsigned Idx = -1;
1549 if (auto *CI = dyn_cast<ConstantInt>(Operands[1]))
1550 if (CI->getValue().getActiveBits() <= 32)
1551 Idx = CI->getZExtValue();
1552 Type *DstTy = Operands[0]->getType();
1553 return TargetTTI->getVectorInstrCost(*EEI, DstTy, CostKind, Idx);
1554 }
1555 }
1556
1557 // By default, just classify everything as 'basic' or -1 to represent that
1558 // don't know the throughput cost.
1560 }
1561
1563 auto *TargetTTI = static_cast<T *>(this);
1564 SmallVector<const Value *, 4> Ops(I->operand_values());
1565 InstructionCost Cost = TargetTTI->getInstructionCost(
1568 }
1569
1570 bool supportsTailCallFor(const CallBase *CB) const {
1571 return static_cast<const T *>(this)->supportsTailCalls();
1572 }
1573};
1574} // namespace llvm
1575
1576#endif
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint32_t Index
uint64_t Size
static bool isSigned(unsigned int Opcode)
Hexagon Common GEP
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
uint64_t IntrinsicInst * II
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:1330
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1468
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1015
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:200
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1542
an instruction to allocate memory on the stack
Definition: Instructions.h:63
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Class to represent array types.
Definition: DerivedTypes.h:395
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...
Definition: InstrTypes.h:1112
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
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:157
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:148
This is an important base class in LLVM.
Definition: Constant.h:42
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU.
Definition: DataLayout.h:219
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:709
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:743
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:617
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:421
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition: TypeSize.h:317
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:791
The core instruction combiner logic.
Definition: InstCombiner.h:48
static InstructionCost getInvalid(CostType Val=0)
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:176
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:42
The optimization diagnostic interface.
Analysis providing profile information.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:77
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...
Definition: SmallVector.h:573
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:683
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:33
static StackOffset getScalable(int64_t Scalable)
Definition: TypeSize.h:43
static StackOffset getFixed(int64_t Fixed)
Definition: TypeSize.h:42
An instruction for storing to memory.
Definition: Instructions.h:292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
TypeSize getElementOffset(unsigned Idx) const
Definition: DataLayout.h:596
Class to represent struct types.
Definition: DerivedTypes.h:218
Multiway switch.
Provides information about what library functions are available for the current target.
Base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class.
const DataLayout & getDataLayout() const
bool isLegalToVectorizeStore(StoreInst *SI) const
bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const
bool shouldTreatInstructionLikeSelect(const Instruction *I)
bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx) const
bool isLegalToVectorizeLoad(LoadInst *LI) const
bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const
std::optional< unsigned > getVScaleForTuning() const
bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const
bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const
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
bool isLegalICmpImmediate(int64_t Imm) const
bool hasConditionalLoadStoreForType(Type *Ty) const
unsigned getRegUsageForType(Type *Ty) const
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond, bool UseMaskForGaps) const
bool areTypesABICompatible(const Function *Caller, const Function *Callee, const ArrayRef< Type * > &Types) const
void getPeelingPreferences(Loop *, ScalarEvolution &, TTI::PeelingPreferences &) const
bool isAlwaysUniform(const Value *V) const
bool isProfitableToHoist(Instruction *I) const
unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const
bool isLSRCostLess(const TTI::LSRCost &C1, const TTI::LSRCost &C2) const
bool isExpensiveToSpeculativelyExecute(const Instruction *I)
bool isTruncateFree(Type *Ty1, Type *Ty2) const
bool isStridedAccess(const SCEV *Ptr) const
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *Ty, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const
InstructionCost getBranchMispredictPenalty() const
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const
InstructionCost getArithmeticReductionCost(unsigned, VectorType *, std::optional< FastMathFlags > FMF, TTI::TargetCostKind) const
InstructionCost getFPOpCost(Type *Ty) const
unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const
InstructionCost getMemcpyCost(const Instruction *I) const
unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
std::optional< unsigned > getMaxVScale() const
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const
bool isProfitableLSRChainElement(Instruction *I) const
InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty) const
bool preferToKeepConstantsAttached(const Instruction &Inst, const Function &Fn) const
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType) const
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const
bool isLegalMaskedStore(Type *DataType, Align Alignment) const
InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const
unsigned getInlineCallPenalty(const Function *F, const CallBase &Call, unsigned DefaultCallPenalty) const
InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, const Instruction *I) const
InstructionCost getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const
bool isNoopAddrSpaceCast(unsigned, unsigned) const
unsigned getStoreMinimumVF(unsigned VF, Type *, Type *) const
InstructionCost getVectorInstrCost(const Instruction &I, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const
bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) const
bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty, TTI::ReductionFlags Flags) const
TargetTransformInfoImplBase(TargetTransformInfoImplBase &&Arg)
TargetTransformInfo::VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
void getUnrollingPreferences(Loop *, ScalarEvolution &, TTI::UnrollingPreferences &, OptimizationRemarkEmitter *) const
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I=nullptr, int64_t ScalableOffset=0) const
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const
bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace)
unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const
std::optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const
unsigned getAssumedAddrSpace(const Value *V) const
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx) const
bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const
bool isLegalNTStore(Type *DataType, Align Alignment) const
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
bool isLegalMaskedGather(Type *DataType, Align Alignment) const
unsigned adjustInliningThreshold(const CallBase *CB) const
BranchProbability getPredictableBranchThreshold() const
std::optional< unsigned > getMinPageSize() const
uint64_t getFeatureMask(const Function &F) const
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace, Align Alignment, unsigned *Fast) const
void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type * > &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicCpySize) const
const SCEVConstant * getConstantStrideStep(ScalarEvolution *SE, const SCEV *Ptr) const
unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool isIndexedLoadLegal(TTI::MemIndexedMode Mode, Type *Ty, const DataLayout &DL) const
bool shouldPrefetchAddressSpace(unsigned AS) const
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind)
bool isSourceOfDivergence(const Value *V) const
bool enableAggressiveInterleaving(bool LoopHasReductions) const
unsigned getMaxInterleaveFactor(ElementCount VF) const
TTI::ReductionShuffle getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace) const
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I) const
std::optional< unsigned > getCacheAssociativity(TargetTransformInfo::CacheLevel Level) const
bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CxtI=nullptr) const
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const
bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment) const
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp=std::nullopt) const
unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const
bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const
InstructionCost getMulAccReductionCost(bool IsUnsigned, Type *ResTy, VectorType *Ty, TTI::TargetCostKind CostKind) const
bool isIndexedStoreLegal(TTI::MemIndexedMode Mode, Type *Ty, const DataLayout &DL) const
bool hasDivRemOp(Type *DataType, bool IsSigned) const
InstructionCost getAddressComputationCost(Type *Tp, ScalarEvolution *, const SCEV *) const
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
bool preferInLoopReduction(unsigned Opcode, Type *Ty, TTI::ReductionFlags Flags) const
InstructionCost getOperandsScalarizationOverhead(ArrayRef< const Value * > Args, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const
bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const
bool isConstantStridedAccessLessThan(ScalarEvolution *SE, const SCEV *Ptr, int64_t MergeDistance) const
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind) const
bool isLoweredToCall(const Function *F) const
bool hasBranchDivergence(const Function *F=nullptr) const
TargetTransformInfoImplBase(const DataLayout &DL)
bool isMultiversionedFunction(const Function &F) const
bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const
const char * getRegisterClassName(unsigned ClassID) const
bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx) const
bool isElementTypeLegalForScalableVector(Type *Ty) const
bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const
Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicElementSize) const
bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const
TailFoldingStyle getPreferredTailFoldingStyle(bool IVUpdateMayOverflow=true) const
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx) const
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *, FastMathFlags, TTI::TargetCostKind) const
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Op0, Value *Op1) const
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo, const Instruction *I) const
bool useColdCCForColdCall(Function &F) const
bool shouldExpandReduction(const IntrinsicInst *II) const
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const
unsigned getNumberOfRegisters(unsigned ClassID) const
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index) const
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, TTI::TargetCostKind CostKind) const
bool isLegalNTLoad(Type *DataType, Align Alignment) const
std::optional< Value * > simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed) const
bool forceScalarizeMaskedScatter(VectorType *DataType, Align Alignment) const
bool hasActiveVectorLength(unsigned Opcode, Type *DataType, Align Alignment) const
bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask) const
bool isLegalMaskedLoad(Type *DataType, Align Alignment) const
bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, ArrayRef< Value * > VL={}) const
bool isLegalAddScalableImmediate(int64_t Imm) const
bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const
InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, TTI::TargetCostKind CostKind) const
TargetTransformInfoImplBase(const TargetTransformInfoImplBase &Arg)=default
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info, TTI::OperandValueInfo Op2Info, const Instruction *I) const
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const
bool shouldBuildLookupTablesForConstant(Constant *C) const
Value * rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
CRTP base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class.
bool supportsTailCallFor(const CallBase *CB) const
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, TTI::TargetCostKind CostKind)
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, TTI::TargetCostKind CostKind)
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind)
bool isExpensiveToSpeculativelyExecute(const Instruction *I)
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
static CastContextHint getCastContextHint(const Instruction *I)
Calculates a CastContextHint from I.
static 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.
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:345
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:270
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:184
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:355
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
Base class of all SIMD vector types.
Definition: DerivedTypes.h:427
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:202
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ 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
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:165
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
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.
Definition: PatternMatch.h:92
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.
Definition: PatternMatch.h:239
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:480
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:2448
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:293
constexpr int PoisonMaskElem
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:217
gep_type_iterator gep_type_begin(const User *GEP)
InstructionCost Cost
@ DataWithoutLaneMask
Same as Data, but avoids using the get.active.lane.mask intrinsic to calculate the mask and instead i...
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.
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.
Flags describing the kind of vector reduction.
Parameters that control the generic loop unrolling transformation.