LLVM 24.0.0git
RISCVTargetTransformInfo.h
Go to the documentation of this file.
1//===- RISCVTargetTransformInfo.h - RISC-V specific TTI ---------*- 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 defines a TargetTransformInfoImplBase conforming object specific
10/// to the RISC-V target machine. It uses the target's detailed information to
11/// provide more precise answers to certain TTI queries, while letting the
12/// target independent and default TTI implementations handle the rest.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_RISCV_RISCVTARGETTRANSFORMINFO_H
17#define LLVM_LIB_TARGET_RISCV_RISCVTARGETTRANSFORMINFO_H
18
19#include "RISCVSubtarget.h"
20#include "RISCVTargetMachine.h"
23#include "llvm/IR/Function.h"
24#include <optional>
25
26namespace llvm {
27
28class RISCVTTIImpl final : public BasicTTIImplBase<RISCVTTIImpl> {
30 using TTI = TargetTransformInfo;
31
32 friend BaseT;
33
34 const RISCVSubtarget *ST;
35 const RISCVTargetLowering *TLI;
36
37 const RISCVSubtarget *getST() const { return ST; }
38 const RISCVTargetLowering *getTLI() const { return TLI; }
39
40 /// This function returns an estimate for VL to be used in VL based terms
41 /// of the cost model. For fixed length vectors, this is simply the
42 /// vector length. For scalable vectors, we return results consistent
43 /// with getVScaleForTuning under the assumption that clients are also
44 /// using that when comparing costs between scalar and vector representation.
45 /// This does unfortunately mean that we can both undershoot and overshot
46 /// the true cost significantly if getVScaleForTuning is wildly off for the
47 /// actual target hardware.
48 unsigned getEstimatedVLFor(VectorType *Ty) const;
49
50 /// This function calculates the costs for one or more RVV opcodes based
51 /// on the vtype and the cost kind.
52 /// \param Opcodes A list of opcodes of the RVV instruction to evaluate.
53 /// \param VT The MVT of vtype associated with the RVV instructions.
54 /// For widening/narrowing instructions where the result and source types
55 /// differ, it is important to check the spec to determine whether the vtype
56 /// refers to the result or source type.
57 /// \param CostKind The type of cost to compute.
58 InstructionCost getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
59 TTI::TargetCostKind CostKind) const;
60
61 // Return the cost of generating a PC relative address
63 getStaticDataAddrGenerationCost(const TTI::TargetCostKind CostKind) const;
64
65 /// Return the cost of accessing a constant pool entry of the specified
66 /// type.
67 InstructionCost getConstantPoolLoadCost(Type *Ty,
68 TTI::TargetCostKind CostKind) const;
69
70 /// If this shuffle can be lowered as a masked slide pair (at worst),
71 /// return a cost for it.
72 InstructionCost getSlideCost(FixedVectorType *Tp, ArrayRef<int> Mask,
73 TTI::TargetCostKind CostKind) const;
74
75 /// Return the type used to cost vzip.vv, whose LMUL represents the
76 /// interleaved destination EMUL. Return an invalid MVT if illegal.
77 MVT getZvzipVZIPCostVT(MVT InterleavedVT) const;
78
79 /// Return the type used to cost vunzipe.v/vunzipo.v, whose LMUL represents
80 /// the interleaved source EMUL. Return an invalid MVT if illegal.
81 MVT getZvzipVUNZIPCostVT(MVT InterleavedVT) const;
82
83 /// If a fixed-length shuffle can be lowered to a vzip.vv instruction,
84 /// return its cost.
85 InstructionCost getVZIPCost(TTI::ShuffleKind Kind, VectorType *DstTy,
86 VectorType *SrcTy, ArrayRef<int> Mask,
87 TTI::TargetCostKind CostKind) const;
88
89public:
90 explicit RISCVTTIImpl(const RISCVTargetMachine *TM, const Function &F)
91 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
92 TLI(ST->getTargetLowering()) {}
93
94 /// Return the cost of materializing an immediate for a value operand of
95 /// a store instruction.
97 TTI::TargetCostKind CostKind) const;
98
100 TTI::TargetCostKind CostKind) const override;
101 InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx,
102 const APInt &Imm, Type *Ty,
103 TTI::TargetCostKind CostKind,
104 Instruction *Inst = nullptr) const override;
106 const ICmpInst &Cond, const APInt &PostIncExitValue) const override;
108 getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
109 Type *Ty, TTI::TargetCostKind CostKind) const override;
110
111 /// \name EVL Support for predicated vectorization.
112 /// Whether the target supports the %evl parameter of VP intrinsic efficiently
113 /// in hardware. (see LLVM Language Reference - "Vector Predication
114 /// Intrinsics",
115 /// https://llvm.org/docs/LangRef.html#vector-predication-intrinsics and
116 /// "IR-level VP intrinsics",
117 /// https://llvm.org/docs/Proposals/VectorPredication.html#ir-level-vp-intrinsics).
118 bool hasActiveVectorLength() const override;
119
121 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
123 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
124 TTI::TargetCostKind CostKind,
125 std::optional<FastMathFlags> FMF) const override;
126
127 bool shouldExpandReduction(const IntrinsicInst *II) const override;
128 bool supportsScalableVectors() const override {
129 // VLEN=32 support is incomplete.
130 return ST->hasVInstructions() &&
131 (ST->getRealMinVLen() >= RISCV::RVVBitsPerBlock);
132 }
133 bool enableOrderedReductions() const override { return true; }
134 bool enableScalableVectorization() const override {
135 return ST->hasVInstructions();
136 }
138 return ST->hasVInstructions();
139 }
141 return ST->hasVInstructions() ? TailFoldingStyle::DataWithEVL
143 }
144 std::optional<unsigned> getVScaleForTuning() const override;
145
148
149 unsigned getRegUsageForType(Type *Ty) const override;
150
151 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override;
152
153 bool preferAlternateOpcodeVectorization() const override;
154
155 bool preferEpilogueVectorization(ElementCount Iters) const override {
156 // Epilogue vectorization is usually unprofitable - tail folding or
157 // a smaller VF would have been better. This a blunt hammer - we
158 // should re-examine this once vectorization is better tuned.
159 return false;
160 }
161
162 bool shouldConsiderVectorizationRegPressure() const override { return true; }
163
166 TTI::TargetCostKind CostKind) const override;
167
169 TTI::TargetCostKind CostKind) const;
170
173 const TTI::PointersChainInfo &Info, Type *AccessTy,
174 const TTI::TargetCostKind CostKind) const override;
175
178 OptimizationRemarkEmitter *ORE) const override;
179
181 TTI::PeelingPreferences &PP) const override;
182
184 MemIntrinsicInfo &Info) const override;
185
186 unsigned getMinVectorRegisterBitWidth() const override {
187 return ST->useRVVForFixedLengthVectors() ? 16 : 0;
188 }
189
192 TTI::TargetCostKind CostKind, ArrayRef<int> Mask, int Index,
193 VectorType *SubTp, ArrayRef<const Value *> Args = {},
194 const Instruction *CtxI = nullptr,
196 TTI::VectorInstrContext::None) const override;
197
199 getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts,
200 bool Insert, bool Extract,
201 TTI::TargetCostKind CostKind,
202 bool ForPoisonSrc = true, ArrayRef<Value *> VL = {},
204 TTI::VectorInstrContext::None) const override;
205
207 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
208 TTI::TargetCostKind CostKind) const override;
209
211 getAddressComputationCost(Type *PTy, ScalarEvolution *SE, const SCEV *Ptr,
212 TTI::TargetCostKind CostKind) const override;
213
215 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
216 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
217 bool UseMaskForCond = false, bool UseMaskForGaps = false) const override;
218
219 InstructionCost getGatherScatterOpCost(const MemIntrinsicCostAttributes &MICA,
220 TTI::TargetCostKind CostKind) const;
221
223 getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
224 TTI::TargetCostKind CostKind) const;
225
226 InstructionCost getStridedMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
227 TTI::TargetCostKind CostKind) const;
228
231
233 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
235 const Instruction *I = nullptr) const override;
236
238 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
239 TTI::TargetCostKind CostKind) const override;
240
241 std::optional<InstructionCost> getCombinedArithmeticInstructionCost(
242 unsigned ISDOpcode, Type *Ty, TTI::TargetCostKind CostKind,
244 ArrayRef<const Value *> Args, const Instruction *CtxI) const;
245
247 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
248 std::optional<FastMathFlags> FMF,
249 TTI::TargetCostKind CostKind) const override;
250
252 getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy,
253 VectorType *ValTy, std::optional<FastMathFlags> FMF,
254 TTI::TargetCostKind CostKind) const override;
255
257 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
258 TTI::TargetCostKind CostKind,
260 const Instruction *I = nullptr) const override;
261
263 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
264 TTI::TargetCostKind CostKind,
267 const Instruction *I = nullptr) const override;
268
269 InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
270 const Instruction *I = nullptr) const override;
271
274 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
275 unsigned Index, const Value *Op0, const Value *Op1,
277 TTI::VectorInstrContext::None) const override;
278
280 getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val,
281 TTI::TargetCostKind CostKind,
282 unsigned Index) const override;
283
285 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
288 ArrayRef<const Value *> Args = {}, const Instruction *CtxI = nullptr,
289 const TargetLibraryInfo *TLibInfo = nullptr,
290 ArrayRef<const Value *> Scalars = {}) const override;
291
292 bool isElementTypeLegalForScalableVector(Type *Ty) const override {
293 return TLI->isLegalElementTypeForRVV(TLI->getValueType(DL, Ty));
294 }
295
296 bool isLegalMaskedLoadStore(Type *DataType, Align Alignment) const {
297 if (!ST->hasVInstructions())
298 return false;
299
300 EVT DataTypeVT = TLI->getValueType(DL, DataType);
301
302 // Only support fixed vectors if we know the minimum vector size.
303 if (DataTypeVT.isFixedLengthVector() && !ST->useRVVForFixedLengthVectors())
304 return false;
305
306 EVT ElemType = DataTypeVT.getScalarType();
307 if (!ST->enableUnalignedVectorMem() && Alignment < ElemType.getStoreSize())
308 return false;
309
310 return TLI->isLegalElementTypeForRVV(ElemType);
311 }
312
313 bool isLegalMaskedLoad(Type *DataType, Align Alignment,
314 unsigned /*AddressSpace*/,
315 TTI::MaskKind /*MaskKind*/) const override {
316 return isLegalMaskedLoadStore(DataType, Alignment);
317 }
318 bool isLegalMaskedStore(Type *DataType, Align Alignment,
319 unsigned /*AddressSpace*/,
320 TTI::MaskKind /*MaskKind*/) const override {
321 return isLegalMaskedLoadStore(DataType, Alignment);
322 }
323
324 bool isLegalMaskedGatherScatter(Type *DataType, Align Alignment) const {
325 if (!ST->hasVInstructions())
326 return false;
327
328 EVT DataTypeVT = TLI->getValueType(DL, DataType);
329
330 // Only support fixed vectors if we know the minimum vector size.
331 if (DataTypeVT.isFixedLengthVector() && !ST->useRVVForFixedLengthVectors())
332 return false;
333
334 // We also need to check if the vector of address is valid.
335 EVT PointerTypeVT = EVT(TLI->getPointerTy(DL));
336 if (DataTypeVT.isScalableVector() &&
337 !TLI->isLegalElementTypeForRVV(PointerTypeVT))
338 return false;
339
340 EVT ElemType = DataTypeVT.getScalarType();
341 if (!ST->enableUnalignedVectorMem() && Alignment < ElemType.getStoreSize())
342 return false;
343
344 return TLI->isLegalElementTypeForRVV(ElemType);
345 }
346
347 bool isLegalMaskedGather(Type *DataType, Align Alignment) const override {
348 return isLegalMaskedGatherScatter(DataType, Alignment);
349 }
350 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override {
351 return isLegalMaskedGatherScatter(DataType, Alignment);
352 }
353
355 Align Alignment) const override {
356 // Scalarize masked gather for RV64 if EEW=64 indices aren't supported.
357 return ST->is64Bit() && !ST->hasVInstructionsI64();
358 }
359
361 Align Alignment) const override {
362 // Scalarize masked scatter for RV64 if EEW=64 indices aren't supported.
363 return ST->is64Bit() && !ST->hasVInstructionsI64();
364 }
365
366 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const override {
367 EVT DataTypeVT = TLI->getValueType(DL, DataType);
368 return TLI->isLegalStridedLoadStore(DataTypeVT, Alignment);
369 }
370
371 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
372 Align Alignment,
373 unsigned AddrSpace) const override {
374 return TLI->isLegalInterleavedAccessType(VTy, Factor, Alignment, AddrSpace,
375 DL);
376 }
377
378 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const override;
379
380 bool isLegalMaskedCompressStore(Type *DataTy, Align Alignment) const override;
381
382 bool isLegalBroadcastLoad(Type *ElementTy,
383 ElementCount NumElements) const override;
384
385 /// \returns How the target needs this vector-predicated operation to be
386 /// transformed.
388 getVPLegalizationStrategy(const VPIntrinsic &PI) const override {
390 static const Intrinsic::ID Supported[] = {
391 Intrinsic::experimental_vp_strided_load,
392 Intrinsic::experimental_vp_strided_store,
393 Intrinsic::experimental_vp_reverse,
394 Intrinsic::experimental_vp_splice,
395 Intrinsic::vp_cttz_elts,
396 Intrinsic::vp_gather,
397 Intrinsic::vp_load,
398 Intrinsic::vp_load_ff,
399 Intrinsic::vp_merge,
400 Intrinsic::vp_reduce_add,
401 Intrinsic::vp_reduce_and,
402 Intrinsic::vp_reduce_fadd,
403 Intrinsic::vp_reduce_fmax,
404 Intrinsic::vp_reduce_fmaximum,
405 Intrinsic::vp_reduce_fmin,
406 Intrinsic::vp_reduce_fminimum,
407 Intrinsic::vp_reduce_fmul,
408 Intrinsic::vp_reduce_mul,
409 Intrinsic::vp_reduce_or,
410 Intrinsic::vp_reduce_smax,
411 Intrinsic::vp_reduce_smin,
412 Intrinsic::vp_reduce_umax,
413 Intrinsic::vp_reduce_umin,
414 Intrinsic::vp_reduce_xor,
415 Intrinsic::vp_scatter,
416 Intrinsic::vp_sdiv,
417 Intrinsic::vp_srem,
418 Intrinsic::vp_store,
419 Intrinsic::vp_udiv,
420 Intrinsic::vp_urem};
421 if (!ST->hasVInstructions() ||
422 (PI.getIntrinsicID() == Intrinsic::vp_reduce_mul &&
424 ->getElementType()
425 ->getIntegerBitWidth() != 1) ||
426 !is_contained(Supported, PI.getIntrinsicID()))
429 }
430
432 ElementCount VF) const override {
433 if (!VF.isScalable())
434 return true;
435
436 Type *Ty = RdxDesc.getRecurrenceType();
437 if (!TLI->isLegalElementTypeForRVV(TLI->getValueType(DL, Ty)))
438 return false;
439
440 switch (RdxDesc.getRecurrenceKind()) {
441 case RecurKind::Add:
442 case RecurKind::Sub:
444 case RecurKind::And:
445 case RecurKind::Or:
446 case RecurKind::Xor:
447 case RecurKind::SMin:
448 case RecurKind::SMax:
449 case RecurKind::UMin:
450 case RecurKind::UMax:
451 case RecurKind::FMin:
452 case RecurKind::FMax:
455 return true;
456 case RecurKind::AnyOf:
457 case RecurKind::FAdd:
458 case RecurKind::FSub:
460 // We can't promote f16/bf16 fadd reductions and scalable vectors can't be
461 // expanded.
462 if (Ty->isBFloatTy() || (Ty->isHalfTy() && !ST->hasVInstructionsF16()))
463 return false;
464 return true;
465 case RecurKind::Mul:
466 case RecurKind::FMul:
476 return false;
477 default:
478 llvm_unreachable("Unknown reduction kind.");
479 }
480 }
481
483 bool HasUnorderedReductions) const override {
484 // Don't interleave if the loop has been vectorized with scalable vectors.
485 if (VF.isScalable())
486 return 1;
487 // If the loop will not be vectorized, don't interleave the loop.
488 // Let regular unroll to unroll the loop.
489 return VF.isScalar() ? 1 : ST->getMaxInterleaveFactor();
490 }
491
492 bool enableInterleavedAccessVectorization() const override { return true; }
493
495 return ST->hasVInstructions();
496 }
497
498 unsigned getMinTripCountTailFoldingThreshold() const override;
499
501 unsigned getNumberOfRegisters(unsigned ClassID) const override {
502 switch (ClassID) {
504 // 31 = 32 GPR - x0 (zero register)
505 // FIXME: Should we exclude fixed registers like SP, TP or GP?
506 return 31;
508 if (ST->hasStdExtF())
509 return 32;
510 return 0;
512 // Although there are 32 vector registers, v0 is special in that it is the
513 // only register that can be used to hold a mask.
514 // FIXME: Should we conservatively return 31 as the number of usable
515 // vector registers?
516 return ST->hasVInstructions() ? 32 : 0;
517 }
518 llvm_unreachable("unknown register class");
519 }
520
522 getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override;
523
525 Type *Ty = nullptr) const override {
526 if (Vector)
528 if (!Ty)
530
531 Type *ScalarTy = Ty->getScalarType();
532 if ((ScalarTy->isHalfTy() && ST->hasStdExtZfhmin()) ||
533 (ScalarTy->isFloatTy() && ST->hasStdExtF()) ||
534 (ScalarTy->isDoubleTy() && ST->hasStdExtD())) {
536 }
537
539 }
540
541 const char *getRegisterClassName(unsigned ClassID) const override {
542 switch (ClassID) {
544 return "RISCV::GPRRC";
546 return "RISCV::FPRRC";
548 return "RISCV::VRRC";
549 }
550 llvm_unreachable("unknown register class");
551 }
552
555 TTI::TargetCostKind CostKind) const override {
556 // Unlike scalar spills, spilling a vector register requires materializing
557 // the address of the spill slot in addition to the store itself, as there
558 // is no vector store with a frame index addressing mode.
559 if (ClassID == RISCVRegisterClass::VRRC)
560 return 2 * TTI::TCC_Basic;
561 return TTI::TCC_Basic;
562 }
563
566 TTI::TargetCostKind CostKind) const override {
567 if (ClassID == RISCVRegisterClass::VRRC)
568 return 2 * TTI::TCC_Basic;
569 return TTI::TCC_Basic;
570 }
571
573 const TargetTransformInfo::LSRCost &C2) const override;
574
576 const Instruction &I,
577 bool &AllowPromotionWithoutCommonHeader) const override;
578 std::optional<unsigned> getMinPageSize() const override { return 4096; }
579 /// Return true if the (vector) instruction I will be lowered to an
580 /// instruction with a scalar splat operand for the given Operand number.
581 bool canSplatOperand(Instruction *I, int Operand) const;
582 /// Return true if a vector instruction will lower to a target instruction
583 /// able to splat the given operand.
584 bool canSplatOperand(unsigned Opcode, int Operand,
585 Intrinsic::ID IntrinsicID) const;
586
588 ArrayRef<int> Mask, ArrayRef<Value *> Scalars,
591 GatherUseOps) const override;
592
594 SmallVectorImpl<Use *> &Ops) const override;
595
597 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override;
598
599 bool enableSelectOptimize() const override {
600 return ST->enableSelectOptimize();
601 }
602
603 bool shouldTreatInstructionLikeSelect(const Instruction *I) const override;
604
605 bool
607 const Attribute &Attr) const override;
608
609 std::optional<Instruction *>
611};
612
613} // end namespace llvm
614
615#endif // LLVM_LIB_TARGET_RISCV_RISCVTARGETTRANSFORMINFO_H
uint64_t Imm
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
TargetTransformInfo::VPLegalization VPLegalization
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
int64_t C1
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL)
Value * getArgOperand(unsigned i) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
constexpr bool isScalar() const
Exactly one element.
Definition TypeSize.h:317
Class to represent fixed width SIMD vectors.
This instruction compares its operands according to the predicate given to the constructor.
The core instruction combiner logic.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Machine Value Type.
Information for memory intrinsic cost model.
The optimization diagnostic interface.
unsigned getMaxInterleaveFactor(ElementCount VF, bool HasUnorderedReductions) const override
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *ValTy, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
bool supportsScalableVectors() const override
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool shouldCopyAttributeWhenOutliningFrom(const Function *Caller, const Attribute &Attr) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const override
InstructionCost getStridedMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
bool isLegalMaskedLoadStore(Type *DataType, Align Alignment) const
TargetTransformInfo::VectorInstrContext getBuildVectorContextHint(ArrayRef< int > Mask, ArrayRef< Value * > Scalars, function_ref< bool(SmallVectorImpl< TargetTransformInfo::BuildVectorUseOp > &)> GatherUseOps) const override
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
unsigned getMinTripCountTailFoldingThreshold() const override
InstructionCost getRegisterClassReloadCost(unsigned ClassID, TTI::TargetCostKind CostKind) const override
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const override
bool preferLoopExitWithEqualityComparison(const ICmpInst &Cond, const APInt &PostIncExitValue) const override
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override
InstructionCost getAddressComputationCost(Type *PTy, ScalarEvolution *SE, const SCEV *Ptr, TTI::TargetCostKind CostKind) const override
bool preferTailFoldingOverEpilogue(TailFoldingInfo *TFI) const override
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 override
InstructionCost getStoreImmCost(Type *VecTy, TTI::OperandValueInfo OpInfo, TTI::TargetCostKind CostKind) const
Return the cost of materializing an immediate for a value operand of a store instruction.
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned, TTI::MaskKind) const override
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const override
bool isElementTypeLegalForScalableVector(Type *Ty) const override
bool enableMaskedInterleavedAccessVectorization() const override
bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace) const override
std::optional< unsigned > getMinPageSize() const override
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const override
bool enableSelectOptimize() const override
bool hasActiveVectorLength() const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool shouldConsiderVectorizationRegPressure() const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const override
bool forceScalarizeMaskedScatter(VectorType *VTy, Align Alignment) const override
const char * getRegisterClassName(unsigned ClassID) const override
InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
Try to calculate op costs for min/max reduction operations.
bool canSplatOperand(Instruction *I, int Operand) const
Return true if the (vector) instruction I will be lowered to an instruction with a scalar splat opera...
bool enableInterleavedAccessVectorization() const override
TailFoldingStyle getPreferredTailFoldingStyle() const override
bool isLegalMaskedGatherScatter(Type *DataType, Align Alignment) const
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const override
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const override
unsigned getRegUsageForType(Type *Ty) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
unsigned getMinVectorRegisterBitWidth() const override
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override
bool isLegalMaskedCompressStore(Type *DataTy, Align Alignment) const override
InstructionCost getGatherScatterOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
bool enableOrderedReductions() const override
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 override
bool shouldTreatInstructionLikeSelect(const Instruction *I) const override
InstructionCost getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
RISCVTTIImpl(const RISCVTargetMachine *TM, const Function &F)
TargetTransformInfo::VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const override
bool preferEpilogueVectorization(ElementCount Iters) const override
bool preferAlternateOpcodeVectorization() const override
bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const override
Check if sinking I's operands to I's basic block is profitable, because the operands can be folded in...
unsigned getNumberOfRegisters(unsigned ClassID) const override
bool shouldExpandReduction(const IntrinsicInst *II) const override
InstructionCost getRegisterClassSpillCost(unsigned ClassID, TTI::TargetCostKind CostKind) const override
std::optional< unsigned > getVScaleForTuning() const override
std::optional< InstructionCost > getCombinedArithmeticInstructionCost(unsigned ISDOpcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CtxI) const
Check to see if this instruction is expected to be combined to a simpler operation during/before lowe...
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
Get memory intrinsic cost based on arguments.
bool isLegalMaskedGather(Type *DataType, Align Alignment) const override
bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned, TTI::MaskKind) const override
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, const TTI::TargetCostKind CostKind) const override
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override
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 override
Estimate the overhead of scalarizing an instruction.
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpdInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const override
bool enableScalableVectorization() const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
InstructionCost getMaskedMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const override
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const override
See if I should be considered for address type promotion.
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
bool forceScalarizeMaskedGather(VectorType *VTy, Align Alignment) const override
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Type * getRecurrenceType() const
Returns the type of the recurrence.
RecurKind getRecurrenceKind() const
The main scalar evolution driver.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
virtual const DataLayout & getDataLayout() const
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
MaskKind
Some targets only support masked load/store with a constant mask.
TargetCostKind
The kind of cost model.
llvm::VectorInstrContext VectorInstrContext
@ TCC_Basic
The cost of a typical 'add' instruction.
AddressingModeKind
Which addressing mode Loop Strength Reduction will try to generate.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
CastContextHint
Represents a hint about the context in which a cast is used.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:155
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition Type.h:144
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:158
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
Base class of all SIMD vector types.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static constexpr unsigned RVVBitsPerBlock
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
@ UMin
Unsigned integer min implemented in terms of select(cmp()).
@ FMinimumNum
FP min with llvm.minimumnum semantics.
@ FindIV
FindIV reduction with select(icmp(),x,y) where one of (x,y) is a loop induction variable (increasing ...
@ Or
Bitwise or logical OR of integers.
@ FMaxSelectNoFMF
FMax as select(cmp()) lacking nnan or nsz, on IEEE types with IEEE denormals.
@ FMinimum
FP min with llvm.minimum semantics.
@ FMaxNum
FP max with llvm.maxnum semantics including NaNs.
@ Mul
Product of integers.
@ FSub
Subtraction of floats.
@ FAddChainWithSubs
A chain of fadds and fsubs.
@ AnyOf
AnyOf reduction with select(cond,x,y) where one of (x,y) is loop invariant, and both x and y are inte...
@ Xor
Bitwise or logical XOR of integers.
@ FindLast
FindLast reduction with select(cmp(),x,y) where x and y.
@ FMax
FP max as select(cmp()) with nnan/nsz, or llvm.maxnum.
@ FMinSelectNoFMF
FMin as select(cmp()) lacking nnan or nsz, on IEEE types with IEEE denormals.
@ FMaximum
FP max with llvm.maximum semantics.
@ FMulAdd
Sum of float products with llvm.fmuladd(a * b + sum).
@ FMul
Product of floats.
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ And
Bitwise or logical AND of integers.
@ SMin
Signed integer min implemented in terms of select(cmp()).
@ FMin
FP min as select(cmp()) with nnan/nsz, or llvm.minnum.
@ FMinNum
FP min with llvm.minnum semantics including NaNs.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
@ AddChainWithSubs
A chain of adds and subs.
@ FAdd
Sum of floats.
@ FMaximumNum
FP max with llvm.maximumnum semantics.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
@ None
Don't use tail folding.
@ DataWithEVL
Use predicated EVL instructions for tail-folding.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition ValueTypes.h:433
bool isFixedLengthVector() const
Definition ValueTypes.h:214
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition ValueTypes.h:361
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition ValueTypes.h:202
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.