LLVM 19.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 }
77 unsigned adjustInliningThreshold(const CallBase *CB) const { return 0; }
78 unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const {
79 return 0;
80 };
81
82 int getInlinerVectorBonusPercent() const { return 150; }
83
85 return TTI::TCC_Expensive;
86 }
87
89 return 64;
90 }
91
92 // Although this default value is arbitrary, it is not random. It is assumed
93 // that a condition that evaluates the same way by a higher percentage than
94 // this is best represented as control flow. Therefore, the default value N
95 // should be set such that the win from N% correct executions is greater than
96 // the loss from (100 - N)% mispredicted executions for the majority of
97 // intended targets.
99 return BranchProbability(99, 100);
100 }
101
102 bool hasBranchDivergence(const Function *F = nullptr) const { return false; }
103
104 bool isSourceOfDivergence(const Value *V) const { return false; }
105
106 bool isAlwaysUniform(const Value *V) const { return false; }
107
108 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const {
109 return false;
110 }
111
112 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
113 return true;
114 }
115
116 unsigned getFlatAddressSpace() const { return -1; }
117
119 Intrinsic::ID IID) const {
120 return false;
121 }
122
123 bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
125 return AS == 0;
126 };
127
128 unsigned getAssumedAddrSpace(const Value *V) const { return -1; }
129
130 bool isSingleThreaded() const { return false; }
131
132 std::pair<const Value *, unsigned>
134 return std::make_pair(nullptr, -1);
135 }
136
138 Value *NewV) const {
139 return nullptr;
140 }
141
142 bool isLoweredToCall(const Function *F) const {
143 assert(F && "A concrete function must be provided to this routine.");
144
145 // FIXME: These should almost certainly not be handled here, and instead
146 // handled with the help of TLI or the target itself. This was largely
147 // ported from existing analysis heuristics here so that such refactorings
148 // can take place in the future.
149
150 if (F->isIntrinsic())
151 return false;
152
153 if (F->hasLocalLinkage() || !F->hasName())
154 return true;
155
156 StringRef Name = F->getName();
157
158 // These will all likely lower to a single selection DAG node.
159 if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
160 Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" ||
161 Name == "fmin" || Name == "fminf" || Name == "fminl" ||
162 Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
163 Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" ||
164 Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl")
165 return false;
166
167 // These are all likely to be optimized into something smaller.
168 if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
169 Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
170 Name == "floorf" || Name == "ceil" || Name == "round" ||
171 Name == "ffs" || Name == "ffsl" || Name == "abs" || Name == "labs" ||
172 Name == "llabs")
173 return false;
174
175 return true;
176 }
177
180 HardwareLoopInfo &HWLoopInfo) const {
181 return false;
182 }
183
184 bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const { return false; }
185
187 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const {
189 }
190
191 std::optional<Instruction *> instCombineIntrinsic(InstCombiner &IC,
192 IntrinsicInst &II) const {
193 return std::nullopt;
194 }
195
196 std::optional<Value *>
198 APInt DemandedMask, KnownBits &Known,
199 bool &KnownBitsComputed) const {
200 return std::nullopt;
201 }
202
204 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
205 APInt &UndefElts2, APInt &UndefElts3,
206 std::function<void(Instruction *, unsigned, APInt, APInt &)>
207 SimplifyAndSetOp) const {
208 return std::nullopt;
209 }
210
213 OptimizationRemarkEmitter *) const {}
214
216 TTI::PeelingPreferences &) const {}
217
218 bool isLegalAddImmediate(int64_t Imm) const { return false; }
219
220 bool isLegalAddScalableImmediate(int64_t Imm) const { return false; }
221
222 bool isLegalICmpImmediate(int64_t Imm) const { return false; }
223
224 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
225 bool HasBaseReg, int64_t Scale, unsigned AddrSpace,
226 Instruction *I = nullptr,
227 int64_t ScalableOffset = 0) const {
228 // Guess that only reg and reg+reg addressing is allowed. This heuristic is
229 // taken from the implementation of LSR.
230 return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
231 }
232
233 bool isLSRCostLess(const TTI::LSRCost &C1, const TTI::LSRCost &C2) const {
234 return std::tie(C1.NumRegs, C1.AddRecCost, C1.NumIVMuls, C1.NumBaseAdds,
235 C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
236 std::tie(C2.NumRegs, C2.AddRecCost, C2.NumIVMuls, C2.NumBaseAdds,
237 C2.ScaleCost, C2.ImmCost, C2.SetupCost);
238 }
239
240 bool isNumRegsMajorCostOfLSR() const { return true; }
241
242 bool shouldFoldTerminatingConditionAfterLSR() const { return false; }
243
244 bool isProfitableLSRChainElement(Instruction *I) const { return false; }
245
246 bool canMacroFuseCmp() const { return false; }
247
250 TargetLibraryInfo *LibInfo) const {
251 return false;
252 }
253
256 return TTI::AMK_None;
257 }
258
259 bool isLegalMaskedStore(Type *DataType, Align Alignment) const {
260 return false;
261 }
262
263 bool isLegalMaskedLoad(Type *DataType, Align Alignment) const {
264 return false;
265 }
266
267 bool isLegalNTStore(Type *DataType, Align Alignment) const {
268 // By default, assume nontemporal memory stores are available for stores
269 // that are aligned and have a size that is a power of 2.
270 unsigned DataSize = DL.getTypeStoreSize(DataType);
271 return Alignment >= DataSize && isPowerOf2_32(DataSize);
272 }
273
274 bool isLegalNTLoad(Type *DataType, Align Alignment) const {
275 // By default, assume nontemporal memory loads are available for loads that
276 // are aligned and have a size that is a power of 2.
277 unsigned DataSize = DL.getTypeStoreSize(DataType);
278 return Alignment >= DataSize && isPowerOf2_32(DataSize);
279 }
280
281 bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const {
282 return false;
283 }
284
285 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const {
286 return false;
287 }
288
289 bool isLegalMaskedGather(Type *DataType, Align Alignment) const {
290 return false;
291 }
292
293 bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment) const {
294 return false;
295 }
296
298 Align Alignment) const {
299 return false;
300 }
301
302 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const {
303 return false;
304 }
305
306 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
307 const SmallBitVector &OpcodeMask) const {
308 return false;
309 }
310
311 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const {
312 return false;
313 }
314
315 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const {
316 return false;
317 }
318
319 bool enableOrderedReductions() const { return false; }
320
321 bool hasDivRemOp(Type *DataType, bool IsSigned) const { return false; }
322
323 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const {
324 return false;
325 }
326
327 bool prefersVectorizedAddressing() const { return true; }
328
330 StackOffset BaseOffset, bool HasBaseReg,
331 int64_t Scale,
332 unsigned AddrSpace) const {
333 // Guess that all legal addressing mode are free.
334 if (isLegalAddressingMode(Ty, BaseGV, BaseOffset.getFixed(), HasBaseReg,
335 Scale, AddrSpace, /*I=*/nullptr,
336 BaseOffset.getScalable()))
337 return 0;
338 return -1;
339 }
340
341 bool LSRWithInstrQueries() const { return false; }
342
343 bool isTruncateFree(Type *Ty1, Type *Ty2) const { return false; }
344
345 bool isProfitableToHoist(Instruction *I) const { return true; }
346
347 bool useAA() const { return false; }
348
349 bool isTypeLegal(Type *Ty) const { return false; }
350
351 unsigned getRegUsageForType(Type *Ty) const { return 1; }
352
353 bool shouldBuildLookupTables() const { return true; }
354
355 bool shouldBuildLookupTablesForConstant(Constant *C) const { return true; }
356
357 bool shouldBuildRelLookupTables() const { return false; }
358
359 bool useColdCCForColdCall(Function &F) const { return false; }
360
362 const APInt &DemandedElts,
363 bool Insert, bool Extract,
365 return 0;
366 }
367
372 return 0;
373 }
374
375 bool supportsEfficientVectorElementLoadStore() const { return false; }
376
377 bool supportsTailCalls() const { return true; }
378
379 bool enableAggressiveInterleaving(bool LoopHasReductions) const {
380 return false;
381 }
382
384 bool IsZeroCmp) const {
385 return {};
386 }
387
388 bool enableSelectOptimize() const { return true; }
389
391 // If the select is a logical-and/logical-or then it is better treated as a
392 // and/or by the backend.
393 using namespace llvm::PatternMatch;
394 return isa<SelectInst>(I) &&
397 }
398
399 bool enableInterleavedAccessVectorization() const { return false; }
400
401 bool enableMaskedInterleavedAccessVectorization() const { return false; }
402
403 bool isFPVectorizationPotentiallyUnsafe() const { return false; }
404
406 unsigned AddressSpace, Align Alignment,
407 unsigned *Fast) const {
408 return false;
409 }
410
411 TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const {
412 return TTI::PSK_Software;
413 }
414
415 bool haveFastSqrt(Type *Ty) const { return false; }
416
417 bool isExpensiveToSpeculativelyExecute(const Instruction *I) { return true; }
418
419 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return true; }
420
423 }
424
425 InstructionCost getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx,
426 const APInt &Imm, Type *Ty) const {
427 return 0;
428 }
429
432 return TTI::TCC_Basic;
433 }
434
435 InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
436 const APInt &Imm, Type *Ty,
438 Instruction *Inst = nullptr) const {
439 return TTI::TCC_Free;
440 }
441
443 const APInt &Imm, Type *Ty,
445 return TTI::TCC_Free;
446 }
447
449 const Function &Fn) const {
450 return false;
451 }
452
453 unsigned getNumberOfRegisters(unsigned ClassID) const { return 8; }
454
455 unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const {
456 return Vector ? 1 : 0;
457 };
458
459 const char *getRegisterClassName(unsigned ClassID) const {
460 switch (ClassID) {
461 default:
462 return "Generic::Unknown Register Class";
463 case 0:
464 return "Generic::ScalarRC";
465 case 1:
466 return "Generic::VectorRC";
467 }
468 }
469
471 return TypeSize::getFixed(32);
472 }
473
474 unsigned getMinVectorRegisterBitWidth() const { return 128; }
475
476 std::optional<unsigned> getMaxVScale() const { return std::nullopt; }
477 std::optional<unsigned> getVScaleForTuning() const { return std::nullopt; }
478 bool isVScaleKnownToBeAPowerOfTwo() const { return false; }
479
480 bool
482 return false;
483 }
484
485 ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const {
486 return ElementCount::get(0, IsScalable);
487 }
488
489 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const { return 0; }
490 unsigned getStoreMinimumVF(unsigned VF, Type *, Type *) const { return VF; }
491
493 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const {
494 AllowPromotionWithoutCommonHeader = false;
495 return false;
496 }
497
498 unsigned getCacheLineSize() const { return 0; }
499 std::optional<unsigned>
501 switch (Level) {
503 [[fallthrough]];
505 return std::nullopt;
506 }
507 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
508 }
509
510 std::optional<unsigned>
512 switch (Level) {
514 [[fallthrough]];
516 return std::nullopt;
517 }
518
519 llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
520 }
521
522 std::optional<unsigned> getMinPageSize() const { return {}; }
523
524 unsigned getPrefetchDistance() const { return 0; }
525 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
526 unsigned NumStridedMemAccesses,
527 unsigned NumPrefetches, bool HasCall) const {
528 return 1;
529 }
530 unsigned getMaxPrefetchIterationsAhead() const { return UINT_MAX; }
531 bool enableWritePrefetching() const { return false; }
532 bool shouldPrefetchAddressSpace(unsigned AS) const { return !AS; }
533
534 unsigned getMaxInterleaveFactor(ElementCount VF) const { return 1; }
535
537 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
540 const Instruction *CxtI = nullptr) const {
541 // Widenable conditions will eventually lower into constants, so some
542 // operations with them will be trivially optimized away.
543 auto IsWidenableCondition = [](const Value *V) {
544 if (auto *II = dyn_cast<IntrinsicInst>(V))
545 if (II->getIntrinsicID() == Intrinsic::experimental_widenable_condition)
546 return true;
547 return false;
548 };
549 // FIXME: A number of transformation tests seem to require these values
550 // which seems a little odd for how arbitary there are.
551 switch (Opcode) {
552 default:
553 break;
554 case Instruction::FDiv:
555 case Instruction::FRem:
556 case Instruction::SDiv:
557 case Instruction::SRem:
558 case Instruction::UDiv:
559 case Instruction::URem:
560 // FIXME: Unlikely to be true for CodeSize.
561 return TTI::TCC_Expensive;
562 case Instruction::And:
563 case Instruction::Or:
564 if (any_of(Args, IsWidenableCondition))
565 return TTI::TCC_Free;
566 break;
567 }
568
569 // Assume a 3cy latency for fp arithmetic ops.
571 if (Ty->getScalarType()->isFloatingPointTy())
572 return 3;
573
574 return 1;
575 }
576
578 unsigned Opcode1,
579 const SmallBitVector &OpcodeMask,
582 }
583
585 ArrayRef<int> Mask,
587 VectorType *SubTp,
588 ArrayRef<const Value *> Args = std::nullopt,
589 const Instruction *CxtI = nullptr) const {
590 return 1;
591 }
592
593 InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
596 const Instruction *I) const {
597 switch (Opcode) {
598 default:
599 break;
600 case Instruction::IntToPtr: {
601 unsigned SrcSize = Src->getScalarSizeInBits();
602 if (DL.isLegalInteger(SrcSize) &&
603 SrcSize <= DL.getPointerTypeSizeInBits(Dst))
604 return 0;
605 break;
606 }
607 case Instruction::PtrToInt: {
608 unsigned DstSize = Dst->getScalarSizeInBits();
609 if (DL.isLegalInteger(DstSize) &&
610 DstSize >= DL.getPointerTypeSizeInBits(Src))
611 return 0;
612 break;
613 }
614 case Instruction::BitCast:
615 if (Dst == Src || (Dst->isPointerTy() && Src->isPointerTy()))
616 // Identity and pointer-to-pointer casts are free.
617 return 0;
618 break;
619 case Instruction::Trunc: {
620 // trunc to a native type is free (assuming the target has compare and
621 // shift-right of the same width).
622 TypeSize DstSize = DL.getTypeSizeInBits(Dst);
623 if (!DstSize.isScalable() && DL.isLegalInteger(DstSize.getFixedValue()))
624 return 0;
625 break;
626 }
627 }
628 return 1;
629 }
630
632 VectorType *VecTy,
633 unsigned Index) const {
634 return 1;
635 }
636
638 const Instruction *I = nullptr) const {
639 // A phi would be free, unless we're costing the throughput because it
640 // will require a register.
641 if (Opcode == Instruction::PHI && CostKind != TTI::TCK_RecipThroughput)
642 return 0;
643 return 1;
644 }
645
646 InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
647 CmpInst::Predicate VecPred,
649 const Instruction *I) const {
650 return 1;
651 }
652
655 unsigned Index, Value *Op0,
656 Value *Op1) const {
657 return 1;
658 }
659
662 unsigned Index) const {
663 return 1;
664 }
665
666 unsigned getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
667 const APInt &DemandedDstElts,
669 return 1;
670 }
671
672 InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
673 unsigned AddressSpace,
676 const Instruction *I) const {
677 return 1;
678 }
679
680 InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
681 unsigned AddressSpace,
683 const Instruction *I) const {
684 return 1;
685 }
686
688 Align Alignment, unsigned AddressSpace,
690 return 1;
691 }
692
694 const Value *Ptr, bool VariableMask,
695 Align Alignment,
697 const Instruction *I = nullptr) const {
698 return 1;
699 }
700
702 const Value *Ptr, bool VariableMask,
703 Align Alignment,
705 const Instruction *I = nullptr) const {
707 }
708
710 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
711 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
712 bool UseMaskForCond, bool UseMaskForGaps) const {
713 return 1;
714 }
715
718 switch (ICA.getID()) {
719 default:
720 break;
721 case Intrinsic::allow_runtime_check:
722 case Intrinsic::allow_ubsan_check:
723 case Intrinsic::annotation:
724 case Intrinsic::assume:
725 case Intrinsic::sideeffect:
726 case Intrinsic::pseudoprobe:
727 case Intrinsic::arithmetic_fence:
728 case Intrinsic::dbg_assign:
729 case Intrinsic::dbg_declare:
730 case Intrinsic::dbg_value:
731 case Intrinsic::dbg_label:
732 case Intrinsic::invariant_start:
733 case Intrinsic::invariant_end:
734 case Intrinsic::launder_invariant_group:
735 case Intrinsic::strip_invariant_group:
736 case Intrinsic::is_constant:
737 case Intrinsic::lifetime_start:
738 case Intrinsic::lifetime_end:
739 case Intrinsic::experimental_noalias_scope_decl:
740 case Intrinsic::objectsize:
741 case Intrinsic::ptr_annotation:
742 case Intrinsic::var_annotation:
743 case Intrinsic::experimental_gc_result:
744 case Intrinsic::experimental_gc_relocate:
745 case Intrinsic::coro_alloc:
746 case Intrinsic::coro_begin:
747 case Intrinsic::coro_free:
748 case Intrinsic::coro_end:
749 case Intrinsic::coro_frame:
750 case Intrinsic::coro_size:
751 case Intrinsic::coro_align:
752 case Intrinsic::coro_suspend:
753 case Intrinsic::coro_subfn_addr:
754 case Intrinsic::threadlocal_address:
755 case Intrinsic::experimental_widenable_condition:
756 case Intrinsic::ssa_copy:
757 // These intrinsics don't actually represent code after lowering.
758 return 0;
759 }
760 return 1;
761 }
762
766 return 1;
767 }
768
769 // Assume that we have a register of the right size for the type.
770 unsigned getNumberOfParts(Type *Tp) const { return 1; }
771
773 const SCEV *) const {
774 return 0;
775 }
776
778 std::optional<FastMathFlags> FMF,
779 TTI::TargetCostKind) const {
780 return 1;
781 }
782
785 TTI::TargetCostKind) const {
786 return 1;
787 }
788
789 InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned,
790 Type *ResTy, VectorType *Ty,
791 FastMathFlags FMF,
793 return 1;
794 }
795
797 VectorType *Ty,
799 return 1;
800 }
801
803 return 0;
804 }
805
807 return false;
808 }
809
811 // Note for overrides: You must ensure for all element unordered-atomic
812 // memory intrinsics that all power-of-2 element sizes up to, and
813 // including, the return value of this method have a corresponding
814 // runtime lib call. These runtime lib call definitions can be found
815 // in RuntimeLibcalls.h
816 return 0;
817 }
818
820 Type *ExpectedType) const {
821 return nullptr;
822 }
823
824 Type *
826 unsigned SrcAddrSpace, unsigned DestAddrSpace,
827 unsigned SrcAlign, unsigned DestAlign,
828 std::optional<uint32_t> AtomicElementSize) const {
829 return AtomicElementSize ? Type::getIntNTy(Context, *AtomicElementSize * 8)
831 }
832
834 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
835 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
836 unsigned SrcAlign, unsigned DestAlign,
837 std::optional<uint32_t> AtomicCpySize) const {
838 unsigned OpSizeInBytes = AtomicCpySize ? *AtomicCpySize : 1;
839 Type *OpType = Type::getIntNTy(Context, OpSizeInBytes * 8);
840 for (unsigned i = 0; i != RemainingBytes; i += OpSizeInBytes)
841 OpsOut.push_back(OpType);
842 }
843
844 bool areInlineCompatible(const Function *Caller,
845 const Function *Callee) const {
846 return (Caller->getFnAttribute("target-cpu") ==
847 Callee->getFnAttribute("target-cpu")) &&
848 (Caller->getFnAttribute("target-features") ==
849 Callee->getFnAttribute("target-features"));
850 }
851
852 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
853 unsigned DefaultCallPenalty) const {
854 return DefaultCallPenalty;
855 }
856
857 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
858 const ArrayRef<Type *> &Types) const {
859 return (Caller->getFnAttribute("target-cpu") ==
860 Callee->getFnAttribute("target-cpu")) &&
861 (Caller->getFnAttribute("target-features") ==
862 Callee->getFnAttribute("target-features"));
863 }
864
866 const DataLayout &DL) const {
867 return false;
868 }
869
871 const DataLayout &DL) const {
872 return false;
873 }
874
875 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const { return 128; }
876
877 bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
878
879 bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
880
881 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
882 unsigned AddrSpace) const {
883 return true;
884 }
885
886 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
887 unsigned AddrSpace) const {
888 return true;
889 }
890
892 ElementCount VF) const {
893 return true;
894 }
895
896 bool isElementTypeLegalForScalableVector(Type *Ty) const { return true; }
897
898 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
899 unsigned ChainSizeInBytes,
900 VectorType *VecTy) const {
901 return VF;
902 }
903
904 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
905 unsigned ChainSizeInBytes,
906 VectorType *VecTy) const {
907 return VF;
908 }
909
910 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
911 TTI::ReductionFlags Flags) const {
912 return false;
913 }
914
915 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
916 TTI::ReductionFlags Flags) const {
917 return false;
918 }
919
921 return true;
922 }
923
924 bool shouldExpandReduction(const IntrinsicInst *II) const { return true; }
925
926 unsigned getGISelRematGlobalCost() const { return 1; }
927
928 unsigned getMinTripCountTailFoldingThreshold() const { return 0; }
929
930 bool supportsScalableVectors() const { return false; }
931
932 bool enableScalableVectorization() const { return false; }
933
934 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
935 Align Alignment) const {
936 return false;
937 }
938
943 /* OperatorStrategy */ TargetTransformInfo::VPLegalization::Convert);
944 }
945
946 bool hasArmWideBranch(bool) const { return false; }
947
948 unsigned getMaxNumArgs() const { return UINT_MAX; }
949
950protected:
951 // Obtain the minimum required size to hold the value (without the sign)
952 // In case of a vector it returns the min required size for one element.
953 unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const {
954 if (isa<ConstantDataVector>(Val) || isa<ConstantVector>(Val)) {
955 const auto *VectorValue = cast<Constant>(Val);
956
957 // In case of a vector need to pick the max between the min
958 // required size for each element
959 auto *VT = cast<FixedVectorType>(Val->getType());
960
961 // Assume unsigned elements
962 isSigned = false;
963
964 // The max required size is the size of the vector element type
965 unsigned MaxRequiredSize =
966 VT->getElementType()->getPrimitiveSizeInBits().getFixedValue();
967
968 unsigned MinRequiredSize = 0;
969 for (unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
970 if (auto *IntElement =
971 dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
972 bool signedElement = IntElement->getValue().isNegative();
973 // Get the element min required size.
974 unsigned ElementMinRequiredSize =
975 IntElement->getValue().getSignificantBits() - 1;
976 // In case one element is signed then all the vector is signed.
977 isSigned |= signedElement;
978 // Save the max required bit size between all the elements.
979 MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
980 } else {
981 // not an int constant element
982 return MaxRequiredSize;
983 }
984 }
985 return MinRequiredSize;
986 }
987
988 if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
989 isSigned = CI->getValue().isNegative();
990 return CI->getValue().getSignificantBits() - 1;
991 }
992
993 if (const auto *Cast = dyn_cast<SExtInst>(Val)) {
994 isSigned = true;
995 return Cast->getSrcTy()->getScalarSizeInBits() - 1;
996 }
997
998 if (const auto *Cast = dyn_cast<ZExtInst>(Val)) {
999 isSigned = false;
1000 return Cast->getSrcTy()->getScalarSizeInBits();
1001 }
1002
1003 isSigned = false;
1004 return Val->getType()->getScalarSizeInBits();
1005 }
1006
1007 bool isStridedAccess(const SCEV *Ptr) const {
1008 return Ptr && isa<SCEVAddRecExpr>(Ptr);
1009 }
1010
1012 const SCEV *Ptr) const {
1013 if (!isStridedAccess(Ptr))
1014 return nullptr;
1015 const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
1016 return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
1017 }
1018
1020 int64_t MergeDistance) const {
1021 const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
1022 if (!Step)
1023 return false;
1024 APInt StrideVal = Step->getAPInt();
1025 if (StrideVal.getBitWidth() > 64)
1026 return false;
1027 // FIXME: Need to take absolute value for negative stride case.
1028 return StrideVal.getSExtValue() < MergeDistance;
1029 }
1030};
1031
1032/// CRTP base class for use as a mix-in that aids implementing
1033/// a TargetTransformInfo-compatible class.
1034template <typename T>
1036private:
1038
1039protected:
1041
1042public:
1044
1048 assert(PointeeType && Ptr && "can't get GEPCost of nullptr");
1049 auto *BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
1050 bool HasBaseReg = (BaseGV == nullptr);
1051
1052 auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
1053 APInt BaseOffset(PtrSizeBits, 0);
1054 int64_t Scale = 0;
1055
1056 auto GTI = gep_type_begin(PointeeType, Operands);
1057 Type *TargetType = nullptr;
1058
1059 // Handle the case where the GEP instruction has a single operand,
1060 // the basis, therefore TargetType is a nullptr.
1061 if (Operands.empty())
1062 return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
1063
1064 for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
1065 TargetType = GTI.getIndexedType();
1066 // We assume that the cost of Scalar GEP with constant index and the
1067 // cost of Vector GEP with splat constant index are the same.
1068 const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
1069 if (!ConstIdx)
1070 if (auto Splat = getSplatValue(*I))
1071 ConstIdx = dyn_cast<ConstantInt>(Splat);
1072 if (StructType *STy = GTI.getStructTypeOrNull()) {
1073 // For structures the index is always splat or scalar constant
1074 assert(ConstIdx && "Unexpected GEP index");
1075 uint64_t Field = ConstIdx->getZExtValue();
1076 BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
1077 } else {
1078 // If this operand is a scalable type, bail out early.
1079 // TODO: Make isLegalAddressingMode TypeSize aware.
1080 if (TargetType->isScalableTy())
1081 return TTI::TCC_Basic;
1082 int64_t ElementSize =
1083 GTI.getSequentialElementStride(DL).getFixedValue();
1084 if (ConstIdx) {
1085 BaseOffset +=
1086 ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
1087 } else {
1088 // Needs scale register.
1089 if (Scale != 0)
1090 // No addressing mode takes two scale registers.
1091 return TTI::TCC_Basic;
1092 Scale = ElementSize;
1093 }
1094 }
1095 }
1096
1097 // If we haven't been provided a hint, use the target type for now.
1098 //
1099 // TODO: Take a look at potentially removing this: This is *slightly* wrong
1100 // as it's possible to have a GEP with a foldable target type but a memory
1101 // access that isn't foldable. For example, this load isn't foldable on
1102 // RISC-V:
1103 //
1104 // %p = getelementptr i32, ptr %base, i32 42
1105 // %x = load <2 x i32>, ptr %p
1106 if (!AccessType)
1107 AccessType = TargetType;
1108
1109 // If the final address of the GEP is a legal addressing mode for the given
1110 // access type, then we can fold it into its users.
1111 if (static_cast<T *>(this)->isLegalAddressingMode(
1112 AccessType, const_cast<GlobalValue *>(BaseGV),
1113 BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale,
1114 Ptr->getType()->getPointerAddressSpace()))
1115 return TTI::TCC_Free;
1116
1117 // TODO: Instead of returning TCC_Basic here, we should use
1118 // getArithmeticInstrCost. Or better yet, provide a hook to let the target
1119 // model it.
1120 return TTI::TCC_Basic;
1121 }
1122
1124 const Value *Base,
1126 Type *AccessTy,
1129 // In the basic model we take into account GEP instructions only
1130 // (although here can come alloca instruction, a value, constants and/or
1131 // constant expressions, PHIs, bitcasts ... whatever allowed to be used as a
1132 // pointer). Typically, if Base is a not a GEP-instruction and all the
1133 // pointers are relative to the same base address, all the rest are
1134 // either GEP instructions, PHIs, bitcasts or constants. When we have same
1135 // base, we just calculate cost of each non-Base GEP as an ADD operation if
1136 // any their index is a non-const.
1137 // If no known dependecies between the pointers cost is calculated as a sum
1138 // of costs of GEP instructions.
1139 for (const Value *V : Ptrs) {
1140 const auto *GEP = dyn_cast<GetElementPtrInst>(V);
1141 if (!GEP)
1142 continue;
1143 if (Info.isSameBase() && V != Base) {
1144 if (GEP->hasAllConstantIndices())
1145 continue;
1146 Cost += static_cast<T *>(this)->getArithmeticInstrCost(
1147 Instruction::Add, GEP->getType(), CostKind,
1149 std::nullopt);
1150 } else {
1151 SmallVector<const Value *> Indices(GEP->indices());
1152 Cost += static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
1153 GEP->getPointerOperand(),
1154 Indices, AccessTy, CostKind);
1155 }
1156 }
1157 return Cost;
1158 }
1159
1163 using namespace llvm::PatternMatch;
1164
1165 auto *TargetTTI = static_cast<T *>(this);
1166 // Handle non-intrinsic calls, invokes, and callbr.
1167 // FIXME: Unlikely to be true for anything but CodeSize.
1168 auto *CB = dyn_cast<CallBase>(U);
1169 if (CB && !isa<IntrinsicInst>(U)) {
1170 if (const Function *F = CB->getCalledFunction()) {
1171 if (!TargetTTI->isLoweredToCall(F))
1172 return TTI::TCC_Basic; // Give a basic cost if it will be lowered
1173
1174 return TTI::TCC_Basic * (F->getFunctionType()->getNumParams() + 1);
1175 }
1176 // For indirect or other calls, scale cost by number of arguments.
1177 return TTI::TCC_Basic * (CB->arg_size() + 1);
1178 }
1179
1180 Type *Ty = U->getType();
1181 unsigned Opcode = Operator::getOpcode(U);
1182 auto *I = dyn_cast<Instruction>(U);
1183 switch (Opcode) {
1184 default:
1185 break;
1186 case Instruction::Call: {
1187 assert(isa<IntrinsicInst>(U) && "Unexpected non-intrinsic call");
1188 auto *Intrinsic = cast<IntrinsicInst>(U);
1189 IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
1190 return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
1191 }
1192 case Instruction::Br:
1193 case Instruction::Ret:
1194 case Instruction::PHI:
1195 case Instruction::Switch:
1196 return TargetTTI->getCFInstrCost(Opcode, CostKind, I);
1197 case Instruction::ExtractValue:
1198 case Instruction::Freeze:
1199 return TTI::TCC_Free;
1200 case Instruction::Alloca:
1201 if (cast<AllocaInst>(U)->isStaticAlloca())
1202 return TTI::TCC_Free;
1203 break;
1204 case Instruction::GetElementPtr: {
1205 const auto *GEP = cast<GEPOperator>(U);
1206 Type *AccessType = nullptr;
1207 // For now, only provide the AccessType in the simple case where the GEP
1208 // only has one user.
1209 if (GEP->hasOneUser() && I)
1210 AccessType = I->user_back()->getAccessType();
1211
1212 return TargetTTI->getGEPCost(GEP->getSourceElementType(),
1213 Operands.front(), Operands.drop_front(),
1214 AccessType, CostKind);
1215 }
1216 case Instruction::Add:
1217 case Instruction::FAdd:
1218 case Instruction::Sub:
1219 case Instruction::FSub:
1220 case Instruction::Mul:
1221 case Instruction::FMul:
1222 case Instruction::UDiv:
1223 case Instruction::SDiv:
1224 case Instruction::FDiv:
1225 case Instruction::URem:
1226 case Instruction::SRem:
1227 case Instruction::FRem:
1228 case Instruction::Shl:
1229 case Instruction::LShr:
1230 case Instruction::AShr:
1231 case Instruction::And:
1232 case Instruction::Or:
1233 case Instruction::Xor:
1234 case Instruction::FNeg: {
1236 TTI::OperandValueInfo Op2Info;
1237 if (Opcode != Instruction::FNeg)
1238 Op2Info = TTI::getOperandInfo(Operands[1]);
1239 return TargetTTI->getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
1240 Op2Info, Operands, I);
1241 }
1242 case Instruction::IntToPtr:
1243 case Instruction::PtrToInt:
1244 case Instruction::SIToFP:
1245 case Instruction::UIToFP:
1246 case Instruction::FPToUI:
1247 case Instruction::FPToSI:
1248 case Instruction::Trunc:
1249 case Instruction::FPTrunc:
1250 case Instruction::BitCast:
1251 case Instruction::FPExt:
1252 case Instruction::SExt:
1253 case Instruction::ZExt:
1254 case Instruction::AddrSpaceCast: {
1255 Type *OpTy = Operands[0]->getType();
1256 return TargetTTI->getCastInstrCost(
1257 Opcode, Ty, OpTy, TTI::getCastContextHint(I), CostKind, I);
1258 }
1259 case Instruction::Store: {
1260 auto *SI = cast<StoreInst>(U);
1261 Type *ValTy = Operands[0]->getType();
1263 return TargetTTI->getMemoryOpCost(Opcode, ValTy, SI->getAlign(),
1264 SI->getPointerAddressSpace(), CostKind,
1265 OpInfo, I);
1266 }
1267 case Instruction::Load: {
1268 // FIXME: Arbitary cost which could come from the backend.
1270 return 4;
1271 auto *LI = cast<LoadInst>(U);
1272 Type *LoadType = U->getType();
1273 // If there is a non-register sized type, the cost estimation may expand
1274 // it to be several instructions to load into multiple registers on the
1275 // target. But, if the only use of the load is a trunc instruction to a
1276 // register sized type, the instruction selector can combine these
1277 // instructions to be a single load. So, in this case, we use the
1278 // destination type of the trunc instruction rather than the load to
1279 // accurately estimate the cost of this load instruction.
1280 if (CostKind == TTI::TCK_CodeSize && LI->hasOneUse() &&
1281 !LoadType->isVectorTy()) {
1282 if (const TruncInst *TI = dyn_cast<TruncInst>(*LI->user_begin()))
1283 LoadType = TI->getDestTy();
1284 }
1285 return TargetTTI->getMemoryOpCost(Opcode, LoadType, LI->getAlign(),
1287 {TTI::OK_AnyValue, TTI::OP_None}, I);
1288 }
1289 case Instruction::Select: {
1290 const Value *Op0, *Op1;
1291 if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) ||
1292 match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
1293 // select x, y, false --> x & y
1294 // select x, true, y --> x | y
1295 const auto Op1Info = TTI::getOperandInfo(Op0);
1296 const auto Op2Info = TTI::getOperandInfo(Op1);
1297 assert(Op0->getType()->getScalarSizeInBits() == 1 &&
1298 Op1->getType()->getScalarSizeInBits() == 1);
1299
1301 return TargetTTI->getArithmeticInstrCost(
1302 match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, Ty,
1303 CostKind, Op1Info, Op2Info, Operands, I);
1304 }
1305 Type *CondTy = Operands[0]->getType();
1306 return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy,
1308 CostKind, I);
1309 }
1310 case Instruction::ICmp:
1311 case Instruction::FCmp: {
1312 Type *ValTy = Operands[0]->getType();
1313 // TODO: Also handle ICmp/FCmp constant expressions.
1314 return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(),
1315 I ? cast<CmpInst>(I)->getPredicate()
1317 CostKind, I);
1318 }
1319 case Instruction::InsertElement: {
1320 auto *IE = dyn_cast<InsertElementInst>(U);
1321 if (!IE)
1322 return TTI::TCC_Basic; // FIXME
1323 unsigned Idx = -1;
1324 if (auto *CI = dyn_cast<ConstantInt>(Operands[2]))
1325 if (CI->getValue().getActiveBits() <= 32)
1326 Idx = CI->getZExtValue();
1327 return TargetTTI->getVectorInstrCost(*IE, Ty, CostKind, Idx);
1328 }
1329 case Instruction::ShuffleVector: {
1330 auto *Shuffle = dyn_cast<ShuffleVectorInst>(U);
1331 if (!Shuffle)
1332 return TTI::TCC_Basic; // FIXME
1333
1334 auto *VecTy = cast<VectorType>(U->getType());
1335 auto *VecSrcTy = cast<VectorType>(Operands[0]->getType());
1336 ArrayRef<int> Mask = Shuffle->getShuffleMask();
1337 int NumSubElts, SubIndex;
1338
1339 // TODO: move more of this inside improveShuffleKindFromMask.
1340 if (Shuffle->changesLength()) {
1341 // Treat a 'subvector widening' as a free shuffle.
1342 if (Shuffle->increasesLength() && Shuffle->isIdentityWithPadding())
1343 return 0;
1344
1345 if (Shuffle->isExtractSubvectorMask(SubIndex))
1346 return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecSrcTy,
1347 Mask, CostKind, SubIndex, VecTy,
1348 Operands, Shuffle);
1349
1350 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1351 return TargetTTI->getShuffleCost(
1352 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1353 FixedVectorType::get(VecTy->getScalarType(), NumSubElts),
1354 Operands, Shuffle);
1355
1356 int ReplicationFactor, VF;
1357 if (Shuffle->isReplicationMask(ReplicationFactor, VF)) {
1358 APInt DemandedDstElts = APInt::getZero(Mask.size());
1359 for (auto I : enumerate(Mask)) {
1360 if (I.value() != PoisonMaskElem)
1361 DemandedDstElts.setBit(I.index());
1362 }
1363 return TargetTTI->getReplicationShuffleCost(
1364 VecSrcTy->getElementType(), ReplicationFactor, VF,
1365 DemandedDstElts, CostKind);
1366 }
1367
1368 bool IsUnary = isa<UndefValue>(Operands[1]);
1369 NumSubElts = VecSrcTy->getElementCount().getKnownMinValue();
1370 SmallVector<int, 16> AdjustMask(Mask.begin(), Mask.end());
1371
1372 // Widening shuffle - widening the source(s) to the new length
1373 // (treated as free - see above), and then perform the adjusted
1374 // shuffle at that width.
1375 if (Shuffle->increasesLength()) {
1376 for (int &M : AdjustMask)
1377 M = M >= NumSubElts ? (M + (Mask.size() - NumSubElts)) : M;
1378
1379 return TargetTTI->getShuffleCost(
1381 AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1382 }
1383
1384 // Narrowing shuffle - perform shuffle at original wider width and
1385 // then extract the lower elements.
1386 AdjustMask.append(NumSubElts - Mask.size(), PoisonMaskElem);
1387
1388 InstructionCost ShuffleCost = TargetTTI->getShuffleCost(
1390 VecSrcTy, AdjustMask, CostKind, 0, nullptr, Operands, Shuffle);
1391
1392 SmallVector<int, 16> ExtractMask(Mask.size());
1393 std::iota(ExtractMask.begin(), ExtractMask.end(), 0);
1394 return ShuffleCost + TargetTTI->getShuffleCost(
1395 TTI::SK_ExtractSubvector, VecSrcTy,
1396 ExtractMask, CostKind, 0, VecTy, {}, Shuffle);
1397 }
1398
1399 if (Shuffle->isIdentity())
1400 return 0;
1401
1402 if (Shuffle->isReverse())
1403 return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, Mask, CostKind,
1404 0, nullptr, Operands, Shuffle);
1405
1406 if (Shuffle->isSelect())
1407 return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, Mask, CostKind,
1408 0, nullptr, Operands, Shuffle);
1409
1410 if (Shuffle->isTranspose())
1411 return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, Mask,
1412 CostKind, 0, nullptr, Operands,
1413 Shuffle);
1414
1415 if (Shuffle->isZeroEltSplat())
1416 return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, Mask,
1417 CostKind, 0, nullptr, Operands,
1418 Shuffle);
1419
1420 if (Shuffle->isSingleSource())
1421 return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy, Mask,
1422 CostKind, 0, nullptr, Operands,
1423 Shuffle);
1424
1425 if (Shuffle->isInsertSubvectorMask(NumSubElts, SubIndex))
1426 return TargetTTI->getShuffleCost(
1427 TTI::SK_InsertSubvector, VecTy, Mask, CostKind, SubIndex,
1428 FixedVectorType::get(VecTy->getScalarType(), NumSubElts), Operands,
1429 Shuffle);
1430
1431 if (Shuffle->isSplice(SubIndex))
1432 return TargetTTI->getShuffleCost(TTI::SK_Splice, VecTy, Mask, CostKind,
1433 SubIndex, nullptr, Operands, Shuffle);
1434
1435 return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, Mask,
1436 CostKind, 0, nullptr, Operands, Shuffle);
1437 }
1438 case Instruction::ExtractElement: {
1439 auto *EEI = dyn_cast<ExtractElementInst>(U);
1440 if (!EEI)
1441 return TTI::TCC_Basic; // FIXME
1442 unsigned Idx = -1;
1443 if (auto *CI = dyn_cast<ConstantInt>(Operands[1]))
1444 if (CI->getValue().getActiveBits() <= 32)
1445 Idx = CI->getZExtValue();
1446 Type *DstTy = Operands[0]->getType();
1447 return TargetTTI->getVectorInstrCost(*EEI, DstTy, CostKind, Idx);
1448 }
1449 }
1450
1451 // By default, just classify everything as 'basic' or -1 to represent that
1452 // don't know the throughput cost.
1454 }
1455
1457 auto *TargetTTI = static_cast<T *>(this);
1458 SmallVector<const Value *, 4> Ops(I->operand_values());
1459 InstructionCost Cost = TargetTTI->getInstructionCost(
1462 }
1463
1464 bool supportsTailCallFor(const CallBase *CB) const {
1465 return static_cast<const T *>(this)->supportsTailCalls();
1466 }
1467};
1468} // namespace llvm
1469
1470#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
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
LLVMContext & Context
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:40
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition: APInt.h:76
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition: APInt.h:1308
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1439
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1010
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition: APInt.h:178
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1513
an instruction to allocate memory on the stack
Definition: Instructions.h:59
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
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:1494
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:993
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
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:154
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:145
This is an important base class in LLVM.
Definition: Constant.h:41
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
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:260
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:720
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:763
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:672
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:472
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:314
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:692
The core instruction combiner logic.
Definition: InstCombiner.h:47
static InstructionCost getInvalid(CostType Val=0)
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:54
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:184
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:44
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:41
The optimization diagnostic interface.
Analysis providing profile information.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:71
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:586
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:696
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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:317
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TypeSize getElementOffset(unsigned Idx) const
Definition: DataLayout.h:651
Class to represent struct types.
Definition: DerivedTypes.h:216
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
void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type * > &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace, unsigned SrcAlign, unsigned DestAlign, std::optional< uint32_t > AtomicCpySize) const
bool isLegalToVectorizeStore(StoreInst *SI) const
bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const
bool shouldTreatInstructionLikeSelect(const Instruction *I)
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
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 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
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 getShuffleCost(TTI::ShuffleKind Kind, VectorType *Ty, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args=std::nullopt, const Instruction *CxtI=nullptr) 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 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
unsigned minRequiredElementSize(const Value *Val, bool &isSigned) const
Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, unsigned SrcAlign, unsigned DestAlign, std::optional< uint32_t > AtomicElementSize) const
std::optional< unsigned > getCacheSize(TargetTransformInfo::CacheLevel Level) const
unsigned getAssumedAddrSpace(const Value *V) 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
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
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
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, const Instruction *I) 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 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)
const char * getRegisterClassName(unsigned ClassID) const
bool isElementTypeLegalForScalableVector(Type *Ty) const
bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const
bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind) 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
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
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
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:342
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:265
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.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:185
bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:348
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:403
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:199
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
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
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:456
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
Definition: STLExtras.h:2406
AddressSpace
Definition: NVPTXBaseInfo.h:21
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:1729
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:275
constexpr int PoisonMaskElem
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
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.