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