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; }
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
588 unsigned getMaxInterleaveFactor(ElementCount VF) const { return 1; }
589
591 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
594 const Instruction *CxtI = nullptr) const {
595 // Widenable conditions will eventually lower into constants, so some
596 // operations with them will be trivially optimized away.
597 auto IsWidenableCondition = [](const Value *V) {
598 if (auto *II = dyn_cast<IntrinsicInst>(V))
599 if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
600 return true;
601 return false;
602 };
603 // FIXME: A number of transformation tests seem to require these values
604 // which seems a little odd for how arbitary there are.
605 switch (Opcode) {
606 default:
607 break;
608 case Instruction::FDiv:
609 case Instruction::FRem:
610 case Instruction::SDiv:
611 case Instruction::SRem:
612 case Instruction::UDiv:
613 case Instruction::URem:
614 // FIXME: Unlikely to be true for CodeSize.
615 return TTI::TCC_Expensive;
616 case Instruction::And:
617 case Instruction::Or:
618 if (any_of(Args, IsWidenableCondition))
619 return TTI::TCC_Free;
620 break;
621 }
622
623 // Assume a 3cy latency for fp arithmetic ops.
625 if (Ty->getScalarType()->isFloatingPointTy())
626 return 3;
627
628 return 1;
629 }
630
632 unsigned Opcode1,
633 const SmallBitVector &OpcodeMask,
636 }
637
639 ArrayRef<int> Mask,
641 VectorType *SubTp,
642 ArrayRef<const Value *> Args = {},
643 const Instruction *CxtI = nullptr) const {
644 return 1;
645 }
646
647 InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
650 const Instruction *I) const {
651 switch (Opcode) {
652 default:
653 break;
654 case Instruction::IntToPtr: {
655 unsigned SrcSize = Src->getScalarSizeInBits();
656 if (DL.isLegalInteger(SrcSize) &&
657 SrcSize <= DL.getPointerTypeSizeInBits(Dst))
658 return 0;
659 break;
660 }
661 case Instruction::PtrToInt: {
662 unsigned DstSize = Dst->getScalarSizeInBits();
663 if (DL.isLegalInteger(DstSize) &&
664 DstSize >= DL.getPointerTypeSizeInBits(Src))
665 return 0;
666 break;
667 }
668 case Instruction::BitCast:
669 if (Dst == Src || (Dst->isPointerTy() && Src->isPointerTy()))
670 // Identity and pointer-to-pointer casts are free.
671 return 0;
672 break;
673 case Instruction::Trunc: {
674 // trunc to a native type is free (assuming the target has compare and
675 // shift-right of the same width).
676 TypeSize DstSize = DL.getTypeSizeInBits(Dst);
677 if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedValue()))
678 return 0;
679 break;
680 }
681 }
682 return 1;
683 }
684
686 VectorType *VecTy,
687 unsigned Index) const {
688 return 1;
689 }
690
692 const Instruction *I = nullptr) const {
693 // A phi would be free, unless we're costing the throughput because it
694 // will require a register.
695 if (Opcode == Instruction::PHI && CostKind != TTI::TCK_RecipThroughput)
696 return 0;
697 return 1;
698 }
699
700 InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
701 CmpInst::Predicate VecPred,
703 TTI::OperandValueInfo Op1Info,
704 TTI::OperandValueInfo Op2Info,
705 const Instruction *I) const {
706 return 1;
707 }
708
711 unsigned Index, Value *Op0,
712 Value *Op1) const {
713 return 1;
714 }
715
716 /// \param ScalarUserAndIdx encodes the information about extracts from a
717 /// vector with 'Scalar' being the value being extracted,'User' being the user
718 /// of the extract(nullptr if user is not known before vectorization) and
719 /// 'Idx' being the extract lane.
721 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
722 Value *Scalar,
723 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
724 return 1;
725 }
726
729 unsigned Index) const {
730 return 1;
731 }
732
733 unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
734 const APInt &DemandedDstElts,
736 return 1;
737 }
738
739 InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
740 unsigned AddressSpace,
743 const Instruction *I) const {
744 return 1;
745 }
746
747 InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
748 unsigned AddressSpace,
750 const Instruction *I) const {
751 return 1;
752 }
753
755 Align Alignment, unsigned AddressSpace,
757 return 1;
758 }
759
761 const Value *Ptr, bool VariableMask,
762 Align Alignment,
764 const Instruction *I = nullptr) const {
765 return 1;
766 }
767
769 const Value *Ptr, bool VariableMask,
770 Align Alignment,
772 const Instruction *I = nullptr) const {
774 }
775
777 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
778 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
779 bool UseMaskForCond, bool UseMaskForGaps) const {
780 return 1;
781 }
782
785 switch (ICA.getID()) {
786 default:
787 break;
788 case Intrinsic::experimental_vector_histogram_add:
789 // For now, we want explicit support from the target for histograms.
791 case Intrinsic::allow_runtime_check:
792 case Intrinsic::allow_ubsan_check:
793 case Intrinsic::annotation:
794 case Intrinsic::assume:
795 case Intrinsic::sideeffect:
796 case Intrinsic::pseudoprobe:
797 case Intrinsic::arithmetic_fence:
798 case Intrinsic::dbg_assign:
799 case Intrinsic::dbg_declare:
800 case Intrinsic::dbg_value:
801 case Intrinsic::dbg_label:
802 case Intrinsic::invariant_start:
803 case Intrinsic::invariant_end:
804 case Intrinsic::launder_invariant_group:
805 case Intrinsic::strip_invariant_group:
806 case Intrinsic::is_constant:
807 case Intrinsic::lifetime_start:
808 case Intrinsic::lifetime_end:
809 case Intrinsic::experimental_noalias_scope_decl:
810 case Intrinsic::objectsize:
811 case Intrinsic::ptr_annotation:
812 case Intrinsic::var_annotation:
813 case Intrinsic::experimental_gc_result:
814 case Intrinsic::experimental_gc_relocate:
815 case Intrinsic::coro_alloc:
816 case Intrinsic::coro_begin:
817 case Intrinsic::coro_begin_custom_abi:
818 case Intrinsic::coro_free:
819 case Intrinsic::coro_end:
820 case Intrinsic::coro_frame:
821 case Intrinsic::coro_size:
822 case Intrinsic::coro_align:
823 case Intrinsic::coro_suspend:
824 case Intrinsic::coro_subfn_addr:
825 case Intrinsic::threadlocal_address:
826 case Intrinsic::experimental_widenable_condition:
827 case Intrinsic::ssa_copy:
828 // These intrinsics don't actually represent code after lowering.
829 return 0;
830 }
831 return 1;
832 }
833
837 return 1;
838 }
839
840 // Assume that we have a register of the right size for the type.
841 unsigned getNumberOfParts(Type *Tp) const { return 1; }
842
844 const SCEV *) const {
845 return 0;
846 }
847
849 std::optional<FastMathFlags> FMF,
850 TTI::TargetCostKind) const {
851 return 1;
852 }
853
856 TTI::TargetCostKind) const {
857 return 1;
858 }
859
860 InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned,
861 Type *ResTy, VectorType *Ty,
862 FastMathFlags FMF,
864 return 1;
865 }
866
868 VectorType *Ty,
870 return 1;
871 }
872
874 return 0;
875 }
876
878 return false;
879 }
880
882 // Note for overrides: You must ensure for all element unordered-atomic
883 // memory intrinsics that all power-of-2 element sizes up to, and
884 // including, the return value of this method have a corresponding
885 // runtime lib call. These runtime lib call definitions can be found
886 // in RuntimeLibcalls.h
887 return 0;
888 }
889
891 Type *ExpectedType) const {
892 return nullptr;
893 }
894
895 Type *
897 unsigned SrcAddrSpace, unsigned DestAddrSpace,
898 Align SrcAlign, Align DestAlign,
899 std::optional<uint32_t> AtomicElementSize) const {
900 return AtomicElementSize ? Type::getIntNTy(Context, *AtomicElementSize * 8)
901 : Type::getInt8Ty(Context);
902 }
903
905 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
906 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
907 Align SrcAlign, Align DestAlign,
908 std::optional<uint32_t> AtomicCpySize) const {
909 unsigned OpSizeInBytes = AtomicCpySize.value_or(1);
910 Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
911 for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
912 OpsOut.push_back(OpType);
913 }
914
915 bool areInlineCompatible(const Function *Caller,
916 const Function *Callee) const {
917 return (Caller->getFnAttribute("target-cpu") ==
918 Callee->getFnAttribute("target-cpu")) &&
919 (Caller->getFnAttribute("target-features") ==
920 Callee->getFnAttribute("target-features"));
921 }
922
923 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
924 unsigned DefaultCallPenalty) const {
925 return DefaultCallPenalty;
926 }
927
928 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
929 const ArrayRef<Type *> &Types) const {
930 return (Caller->getFnAttribute("target-cpu") ==
931 Callee->getFnAttribute("target-cpu")) &&
932 (Caller->getFnAttribute("target-features") ==
933 Callee->getFnAttribute("target-features"));
934 }
935
937 const DataLayout &DL) const {
938 return false;
939 }
940
942 const DataLayout &DL) const {
943 return false;
944 }
945
946 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const { return 128; }
947
948 bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
949
950 bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
951
952 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
953 unsigned AddrSpace) const {
954 return true;
955 }
956
957 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
958 unsigned AddrSpace) const {
959 return true;
960 }
961
963 ElementCount VF) const {
964 return true;
965 }
966
967 bool isElementTypeLegalForScalableVector(Type *Ty) const { return true; }
968
969 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
970 unsigned ChainSizeInBytes,
971 VectorType *VecTy) const {
972 return VF;
973 }
974
975 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
976 unsigned ChainSizeInBytes,
977 VectorType *VecTy) const {
978 return VF;
979 }
980
981 bool preferFixedOverScalableIfEqualCost() const { return false; }
982
983 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
984 TTI::ReductionFlags Flags) const {
985 return false;
986 }
987
988 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
989 TTI::ReductionFlags Flags) const {
990 return false;
991 }
992
994 return true;
995 }
996
997 bool shouldExpandReduction(const IntrinsicInst *II) const { return true; }
998
1002 }
1003
1004 unsigned getGISelRematGlobalCost() const { return 1; }
1005
1006 unsigned getMinTripCountTailFoldingThreshold() const { return 0; }
1007
1008 bool supportsScalableVectors() const { return false; }
1009
1010 bool enableScalableVectorization() const { return false; }
1011
1012 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
1013 Align Alignment) const {
1014 return false;
1015 }
1016
1018 SmallVectorImpl<Use *> &Ops) const {
1019 return false;
1020 }
1021
1022 bool isVectorShiftByScalarCheap(Type *Ty) const { return false; }
1023
1027 /* EVLParamStrategy */ TargetTransformInfo::VPLegalization::Discard,
1028 /* OperatorStrategy */ TargetTransformInfo::VPLegalization::Convert);
1029 }
1030
1031 bool hasArmWideBranch(bool) const { return false; }
1032
1033 unsigned getMaxNumArgs() const { return UINT_MAX; }
1034
1035 unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const {
1036 return 0;
1037 }
1038
1039protected:
1040 // Obtain the minimum required size to hold the value (without the sign)
1041 // In case of a vector it returns the min required size for one element.
1042 unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const {
1043 if (isa<ConstantDataVector>(Val) || isa<ConstantVector>(Val)) {
1044 const auto *VectorValue = cast<Constant>(Val);
1045
1046 // In case of a vector need to pick the max between the min
1047 // required size for each element
1048 auto *VT = cast<FixedVectorType>(Val->getType());
1049
1050 // Assume unsigned elements
1051 isSigned = false;
1052
1053 // The max required size is the size of the vector element type
1054 unsigned MaxRequiredSize =
1055 VT->getElementType()->getPrimitiveSizeInBits().getFixedValue();
1056
1057 unsigned MinRequiredSize = 0;
1058 for (unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
1059 if (auto *IntElement =
1060 dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
1061 bool signedElement = IntElement->getValue().isNegative();
1062 // Get the element min required size.
1063 unsigned ElementMinRequiredSize =
1064 IntElement->getValue().getSignificantBits() - 1;
1065 // In case one element is signed then all the vector is signed.
1066 isSigned |= signedElement;
1067 // Save the max required bit size between all the elements.
1068 MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
1069 } else {
1070 // not an int constant element
1071 return MaxRequiredSize;
1072 }
1073 }
1074 return MinRequiredSize;
1075 }
1076
1077 if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
1078 isSigned = CI->getValue().isNegative();
1079 return CI->getValue().getSignificantBits() - 1;
1080 }
1081
1082 if (const auto *Cast = dyn_cast<SExtInst>(Val)) {
1083 isSigned = true;
1084 return Cast->getSrcTy()->getScalarSizeInBits() - 1;
1085 }
1086
1087 if (const auto *Cast = dyn_cast<ZExtInst>(Val)) {
1088 isSigned = false;
1089 return Cast->getSrcTy()->getScalarSizeInBits();
1090 }
1091
1092 isSigned = false;
1093 return Val->getType()->getScalarSizeInBits();
1094 }
1095
1096 bool isStridedAccess(const SCEV *Ptr) const {
1097 return Ptr && isa<SCEVAddRecExpr>(Ptr);
1098 }
1099
1101 const SCEV *Ptr) const {
1102 if (!isStridedAccess(Ptr))
1103 return nullptr;
1104 const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
1105 return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
1106 }
1107
1109 int64_t MergeDistance) const {
1110 const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
1111 if (!Step)
1112 return false;
1113 APInt StrideVal = Step->getAPInt();
1114 if (StrideVal.getBitWidth() > 64)
1115 return false;
1116 // FIXME: Need to take absolute value for negative stride case.
1117 return StrideVal.getSExtValue() < MergeDistance;
1118 }
1119};
1120
1121/// CRTP base class for use as a mix-in that aids implementing
1122/// a TargetTransformInfo-compatible class.
1123template <typename T>
1125private:
1127
1128protected:
1130
1131public:
1133
1137 assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
1138 auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
1139 bool HasBaseReg = (BaseGV == nullptr);
1140
1141 auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
1142 APInt BaseOffset(PtrSizeBits, 0);
1143 int64_t Scale = 0;
1144
1145 auto GTI = gep_type_begin(PointeeType, Operands);
1146 Type *TargetType = nullptr;
1147
1148 // Handle the case where the GEP instruction has a single operand,
1149 // the basis, therefore TargetType is a nullptr.
1150 if (Operands.empty())
1151 return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
1152
1153 for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
1154 TargetType = GTI.getIndexedType();
1155 // We assume that the cost of Scalar GEP with constant index and the
1156 // cost of Vector GEP with splat constant index are the same.
1157 const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
1158 if (!ConstIdx)
1159 if (auto Splat = getSplatValue(*I))
1160 ConstIdx = dyn_cast<ConstantInt>(Splat);
1161 if (StructType *STy = GTI.getStructTypeOrNull()) {
1162 // For structures the index is always splat or scalar constant
1163 assert(ConstIdx && "Unexpected GEP index");
1164 uint64_t Field = ConstIdx->getZExtValue();
1165 BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
1166 } else {
1167 // If this operand is a scalable type, bail out early.
1168 // TODO: Make isLegalAddressingMode TypeSize aware.
1169 if (TargetType->isScalableTy())
1170 return TTI::TCC_Basic;
1171 int64_t ElementSize =
1172 GTI.getSequentialElementStride(DL).getFixedValue();
1173 if (ConstIdx) {
1174 BaseOffset +=
1175 ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
1176 } else {
1177 // Needs scale register.
1178 if (Scale != 0)
1179 // No addressing mode takes two scale registers.
1180 return TTI::TCC_Basic;
1181 Scale = ElementSize;
1182 }
1183 }
1184 }
1185
1186 // If we haven't been provided a hint, use the target type for now.
1187 //
1188 // TODO: Take a look at potentially removing this: This is *slightly* wrong
1189 // as it's possible to have a GEP with a foldable target type but a memory
1190 // access that isn't foldable. For example, this load isn't foldable on
1191 // RISC-V:
1192 //
1193 // %p = getelementptr i32, ptr %base, i32 42
1194 // %x = load <2 x i32>, ptr %p
1195 if (!AccessType)
1196 AccessType = TargetType;
1197
1198 // If the final address of the GEP is a legal addressing mode for the given
1199 // access type, then we can fold it into its users.
1200 if (static_cast<T *>(this)->isLegalAddressingMode(
1201 AccessType, const_cast<GlobalValue *>(BaseGV),
1202 BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
1203 Ptr->getType()->getPointerAddressSpace()))
1204 return TTI::TCC_Free;
1205
1206 // TODO: Instead of returning TCC_Basic here, we should use
1207 // getArithmeticInstrCost. Or better yet, provide a hook to let the target
1208 // model it.
1209 return TTI::TCC_Basic;
1210 }
1211
1213 const Value *Base,
1215 Type *AccessTy,
1218 // In the basic model we take into account GEP instructions only
1219 // (although here can come alloca instruction, a value, constants and/or
1220 // constant expressions, PHIs, bitcasts ... whatever allowed to be used as a
1221 // pointer). Typically, if Base is a not a GEP-instruction and all the
1222 // pointers are relative to the same base address, all the rest are
1223 // either GEP instructions, PHIs, bitcasts or constants. When we have same
1224 // base, we just calculate cost of each non-Base GEP as an ADD operation if
1225 // any their index is a non-const.
1226 // If no known dependecies between the pointers cost is calculated as a sum
1227 // of costs of GEP instructions.
1228 for (const Value *V : Ptrs) {
1229 const auto *GEP = dyn_cast<GetElementPtrInst>(V);
1230 if (!GEP)
1231 continue;
1232 if (Info.isSameBase() && V != Base) {
1233 if (GEP->hasAllConstantIndices())
1234 continue;
1235 Cost += static_cast<T *>(this)->getArithmeticInstrCost(
1236 Instruction::Add, GEP->getType(), CostKind,
1238 {});
1239 } else {
1240 SmallVector<const Value *> Indices(GEP->indices());
1241 Cost += static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
1242 GEP->getPointerOperand(),
1243 Indices, AccessTy, CostKind);
1244 }
1245 }
1246 return Cost;
1247 }
1248
1252 using namespace llvm::PatternMatch;
1253
1254 auto *TargetTTI = static_cast<T *>(this);
1255 // Handle non-intrinsic calls, invokes, and callbr.
1256 // FIXME: Unlikely to be true for anything but CodeSize.
1257 auto *CB = dyn_cast<CallBase>(U);
1258 if (CB && !isa<IntrinsicInst>(U)) {
1259 if (const Function *F = CB->getCalledFunction()) {
1260 if (!TargetTTI->isLoweredToCall(F))
1261 return TTI::TCC_Basic; // Give a basic cost if it will be lowered
1262
1263 return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
1264 }
1265 // For indirect or other calls, scale cost by number of arguments.
1266 return TTI::TCC_Basic * (CB->arg_size() + 1);
1267 }
1268
1269 Type *Ty = U->getType();
1270 unsigned Opcode = Operator::getOpcode(U);
1271 auto *I = dyn_cast<Instruction>(U);
1272 switch (Opcode) {
1273 default:
1274 break;
1275 case Instruction::Call: {
1276 assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
1277 auto *Intrinsic = cast<IntrinsicInst>(U);
1278 IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
1279 return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
1280 }
1281 case Instruction::Br:
1282 case Instruction::Ret:
1283 case Instruction::PHI:
1284 case Instruction::Switch:
1285 return TargetTTI->getCFInstrCost(Opcode, CostKind, I);
1286 case Instruction::ExtractValue:
1287 case Instruction::Freeze:
1288 return TTI::TCC_Free;
1289 case Instruction::Alloca:
1290 if (cast<AllocaInst>(U)->isStaticAlloca())
1291 return TTI::TCC_Free;
1292 break;
1293 case Instruction::GetElementPtr: {
1294 const auto *GEP = cast<GEPOperator>(U);
1295 Type *AccessType = nullptr;
1296 // For now, only provide the AccessType in the simple case where the GEP
1297 // only has one user.
1298 if (GEP->hasOneUser() && I)
1299 AccessType = I->user_back()->getAccessType();
1300
1301 return TargetTTI->getGEPCost(GEP->getSourceElementType(),
1302 Operands.front(), Operands.drop_front(),
1303 AccessType, CostKind);
1304 }
1305 case Instruction::Add:
1306 case Instruction::FAdd:
1307 case Instruction::Sub:
1308 case Instruction::FSub:
1309 case Instruction::Mul:
1310 case Instruction::FMul:
1311 case Instruction::UDiv:
1312 case Instruction::SDiv:
1313 case Instruction::FDiv:
1314 case Instruction::URem:
1315 case Instruction::SRem:
1316 case Instruction::FRem:
1317 case Instruction::Shl:
1318 case Instruction::LShr:
1319 case Instruction::AShr:
1320 case Instruction::And:
1321 case Instruction::Or:
1322 case Instruction::Xor:
1323 case Instruction::FNeg: {
1325 TTI::OperandValueInfo Op2Info;
1326 if (Opcode != Instruction::FNeg)
1327 Op2Info = TTI::getOperandInfo(Operands[1]);
1328 return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
1329 Op2Info, Operands, I);
1330 }
1331 case Instruction::IntToPtr:
1332 case Instruction::PtrToInt:
1333 case Instruction::SIToFP:
1334 case Instruction::UIToFP:
1335 case Instruction::FPToUI:
1336 case Instruction::FPToSI:
1337 case Instruction::Trunc:
1338 case Instruction::FPTrunc:
1339 case Instruction::BitCast:
1340 case Instruction::FPExt:
1341 case Instruction::SExt:
1342 case Instruction::ZExt:
1343 case Instruction::AddrSpaceCast: {
1344 Type *OpTy = Operands[0]->getType();
1345 return TargetTTI->getCastInstrCost(
1346 Opcode, Ty, OpTy, TTI::getCastContextHint(I), CostKind, I);
1347 }
1348 case Instruction::Store: {
1349 auto *SI = cast<StoreInst>(U);
1350 Type *ValTy = Operands[0]->getType();
1352 return TargetTTI->getMemoryOpCost(Opcode, ValTy, SI->getAlign(),
1353 SI->getPointerAddressSpace(), CostKind,
1354 OpInfo, I);
1355 }
1356 case Instruction::Load: {
1357 // FIXME: Arbitary cost which could come from the backend.
1359 return 4;
1360 auto *LI = cast<LoadInst>(U);
1361 Type *LoadType = U->getType();
1362 // If there is a non-register sized type, the cost estimation may expand
1363 // it to be several instructions to load into multiple registers on the
1364 // target. But, if the only use of the load is a trunc instruction to a
1365 // register sized type, the instruction selector can combine these
1366 // instructions to be a single load. So, in this case, we use the
1367 // destination type of the trunc instruction rather than the load to
1368 // accurately estimate the cost of this load instruction.
1369 if (CostKind == TTI::TCK_CodeSize && LI->hasOneUse() &&
1370 !LoadType->isVectorTy()) {
1371 if (const TruncInst *TI = dyn_cast<TruncInst>(*LI->user_begin()))
1372 LoadType = TI->getDestTy();
1373 }
1374 return TargetTTI->getMemoryOpCost(Opcode, LoadType, LI->getAlign(),
1376 {TTI::OK_AnyValue, TTI::OP_None}, I);
1377 }
1378 case Instruction::Select: {
1379 const Value *Op0, *Op1;
1380 if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
1381 match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
1382 // select x, y, false --> x & y
1383 // select x, true, y --> x | y
1384 const auto Op1Info = TTI::getOperandInfo(Op0);
1385 const auto Op2Info = TTI::getOperandInfo(Op1);
1386 assert(Op0->getType()->getScalarSizeInBits() == 1 &&
1387 Op1->getType()->getScalarSizeInBits() == 1);
1388
1390 return TargetTTI->getArithmeticInstrCost(
1391 match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
1392 CostKind, Op1Info, Op2Info, Operands, I);
1393 }
1394 const auto Op1Info = TTI::getOperandInfo(Operands[1]);
1395 const auto Op2Info = TTI::getOperandInfo(Operands[2]);
1396 Type *CondTy = Operands[0]->getType();
1397 return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,
1399 CostKind, Op1Info, Op2Info, I);
1400 }
1401 case Instruction::ICmp:
1402 case Instruction::FCmp: {
1403 const auto Op1Info = TTI::getOperandInfo(Operands[0]);
1404 const auto Op2Info = TTI::getOperandInfo(Operands[1]);
1405 Type *ValTy = Operands[0]->getType();
1406 // TODO: Also handle ICmp/FCmp constant expressions.
1407 return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(),
1408 I ? cast<CmpInst>(I)->getPredicate()
1410 CostKind, Op1Info, Op2Info, I);
1411 }
1412 case Instruction::InsertElement: {
1413 auto *IE = dyn_cast<InsertElementInst>(U);
1414 if (!IE)
1415 return TTI::TCC_Basic; // FIXME
1416 unsigned Idx = -1;
1417 if (auto *CI = dyn_cast<ConstantInt>(Operands[2]))
1418 if (CI->getValue().getActiveBits() <= 32)
1419 Idx = CI->getZExtValue();
1420 return TargetTTI->getVectorInstrCost(*IE, Ty, CostKind, Idx);
1421 }
1422 case Instruction::ShuffleVector: {
1423 auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
1424 if (!Shuffle)
1425 return TTI::TCC_Basic; // FIXME
1426
1427 auto *VecTy = cast<VectorType>(U->getType());
1428 auto *VecSrcTy = cast<VectorType>(Operands[0]->getType());
1429 ArrayRef<int> Mask = Shuffle->getShuffleMask();
1430 int NumSubElts, SubIndex;
1431
1432 // TODO: move more of this inside improveShuffleKindFromMask.
1433 if (Shuffle->changesLength()) {
1434 // Treat a 'subvector widening' as a free shuffle.
1435 if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding())
1436 return 0;
1437
1438 if (Shuffle->isExtractSubvectorMask(SubIndex))
1439 return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecSrcTy,
1440 Mask, CostKind, SubIndex, VecTy,
1441 Operands, Shuffle);
1442
1443 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1444 return TargetTTI->getShuffleCost(
1445 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1446 FixedVectorType::get(VecTy->getScalarType(), NumSubElts),
1447 Operands, Shuffle);
1448
1449 int ReplicationFactor, VF;
1450 if (Shuffle->isReplicationMask(ReplicationFactor, VF)) {
1451 APInt DemandedDstElts = APInt::getZero(Mask.size());
1452 for (auto I : enumerate(Mask)) {
1453 if (I.value() != PoisonMaskElem)
1454 DemandedDstElts.setBit(I.index());
1455 }
1456 return TargetTTI->getReplicationShuffleCost(
1457 VecSrcTy->getElementType(), ReplicationFactor, VF,
1458 DemandedDstElts, CostKind);
1459 }
1460
1461 bool IsUnary = isa<UndefValue>(Operands[1]);
1462 NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
1463 SmallVector<int, 16> AdjustMask(Mask);
1464
1465 // Widening shuffle - widening the source(s) to the new length
1466 // (treated as free - see above), and then perform the adjusted
1467 // shuffle at that width.
1468 if (Shuffle->increasesLength()) {
1469 for (int &M : AdjustMask)
1470 M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
1471
1472 return TargetTTI->getShuffleCost(
1474 AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1475 }
1476
1477 // Narrowing shuffle - perform shuffle at original wider width and
1478 // then extract the lower elements.
1479 AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
1480
1481 InstructionCost ShuffleCost = TargetTTI->getShuffleCost(
1483 VecSrcTy, AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1484
1485 SmallVector<int, 16> ExtractMask(Mask.size());
1486 std::iota(ExtractMask.begin(), ExtractMask.end(), 0);
1487 return ShuffleCost + TargetTTI->getShuffleCost(
1488 TTI::SK_ExtractSubvector, VecSrcTy,
1489 ExtractMask, CostKind, 0, VecTy, {}, Shuffle);
1490 }
1491
1492 if (Shuffle->isIdentity())
1493 return 0;
1494
1495 if (Shuffle->isReverse())
1496 return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, Mask, CostKind,
1497 0, nullptr, Operands, Shuffle);
1498
1499 if (Shuffle->isSelect())
1500 return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, Mask, CostKind,
1501 0, nullptr, Operands, Shuffle);
1502
1503 if (Shuffle->isTranspose())
1504 return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, Mask,
1505 CostKind, 0, nullptr, Operands,
1506 Shuffle);
1507
1508 if (Shuffle->isZeroEltSplat())
1509 return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, Mask,
1510 CostKind, 0, nullptr, Operands,
1511 Shuffle);
1512
1513 if (Shuffle->isSingleSource())
1514 return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy, Mask,
1515 CostKind, 0, nullptr, Operands,
1516 Shuffle);
1517
1518 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1519 return TargetTTI->getShuffleCost(
1520 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1521 FixedVectorType::get(VecTy->getScalarType(), NumSubElts), Operands,
1522 Shuffle);
1523
1524 if (Shuffle->isSplice(SubIndex))
1525 return TargetTTI->getShuffleCost(TTI::SK_Splice, VecTy, Mask, CostKind,
1526 SubIndex, nullptr, Operands, Shuffle);
1527
1528 return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, Mask,
1529 CostKind, 0, nullptr, Operands, Shuffle);
1530 }
1531 case Instruction::ExtractElement: {
1532 auto *EEI = dyn_cast<ExtractElementInst>(U);
1533 if (!EEI)
1534 return TTI::TCC_Basic; // FIXME
1535 unsigned Idx = -1;
1536 if (auto *CI = dyn_cast<ConstantInt>(Operands[1]))
1537 if (CI->getValue().getActiveBits() <= 32)
1538 Idx = CI->getZExtValue();
1539 Type *DstTy = Operands[0]->getType();
1540 return TargetTTI->getVectorInstrCost(*EEI, DstTy, CostKind, Idx);
1541 }
1542 }
1543
1544 // By default, just classify everything as 'basic' or -1 to represent that
1545 // don't know the throughput cost.
1547 }
1548
1550 auto *TargetTTI = static_cast<T *>(this);
1551 SmallVector<const Value *, 4> Ops(I->operand_values());
1552 InstructionCost Cost = TargetTTI->getInstructionCost(
1555 }
1556
1557 bool supportsTailCallFor(const CallBase *CB) const {
1558 return static_cast<const T *>(this)->supportsTailCalls();
1559 }
1560};
1561} // namespace llvm
1562
1563#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:1120
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
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
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 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:291
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.