LLVM 20.0.0git
TargetTransformInfo.h
Go to the documentation of this file.
1//===- TargetTransformInfo.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 pass exposes codegen information to IR-level passes. Every
10/// transformation that uses codegen information is broken into three parts:
11/// 1. The IR-level analysis pass.
12/// 2. The IR-level transformation interface which provides the needed
13/// information.
14/// 3. Codegen-level implementation which uses target-specific hooks.
15///
16/// This file defines #2, which is the interface that IR-level transformations
17/// use for querying the codegen.
18///
19//===----------------------------------------------------------------------===//
20
21#ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
22#define LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
23
24#include "llvm/ADT/APInt.h"
25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/IR/FMF.h"
27#include "llvm/IR/InstrTypes.h"
28#include "llvm/IR/PassManager.h"
29#include "llvm/Pass.h"
33#include <functional>
34#include <optional>
35#include <utility>
36
37namespace llvm {
38
39namespace Intrinsic {
40typedef unsigned ID;
41}
42
43class AllocaInst;
44class AssumptionCache;
45class BlockFrequencyInfo;
46class DominatorTree;
47class BranchInst;
48class Function;
49class GlobalValue;
50class InstCombiner;
51class OptimizationRemarkEmitter;
52class InterleavedAccessInfo;
53class IntrinsicInst;
54class LoadInst;
55class Loop;
56class LoopInfo;
57class LoopVectorizationLegality;
58class ProfileSummaryInfo;
59class RecurrenceDescriptor;
60class SCEV;
61class ScalarEvolution;
62class SmallBitVector;
63class StoreInst;
64class SwitchInst;
65class TargetLibraryInfo;
66class Type;
67class VPIntrinsic;
68struct KnownBits;
69
70/// Information about a load/store intrinsic defined by the target.
72 /// This is the pointer that the intrinsic is loading from or storing to.
73 /// If this is non-null, then analysis/optimization passes can assume that
74 /// this intrinsic is functionally equivalent to a load/store from this
75 /// pointer.
76 Value *PtrVal = nullptr;
77
78 // Ordering for atomic operations.
80
81 // Same Id is set by the target for corresponding load/store intrinsics.
82 unsigned short MatchingId = 0;
83
84 bool ReadMem = false;
85 bool WriteMem = false;
86 bool IsVolatile = false;
87
88 bool isUnordered() const {
92 }
93};
94
95/// Attributes of a target dependent hardware loop.
97 HardwareLoopInfo() = delete;
99 Loop *L = nullptr;
102 const SCEV *ExitCount = nullptr;
104 Value *LoopDecrement = nullptr; // Decrement the loop counter by this
105 // value in every iteration.
106 bool IsNestingLegal = false; // Can a hardware loop be a parent to
107 // another hardware loop?
108 bool CounterInReg = false; // Should loop counter be updated in
109 // the loop via a phi?
110 bool PerformEntryTest = false; // Generate the intrinsic which also performs
111 // icmp ne zero on the loop counter value and
112 // produces an i1 to guard the loop entry.
114 DominatorTree &DT, bool ForceNestedLoop = false,
115 bool ForceHardwareLoopPHI = false);
116 bool canAnalyze(LoopInfo &LI);
117};
118
120 const IntrinsicInst *II = nullptr;
121 Type *RetTy = nullptr;
122 Intrinsic::ID IID;
123 SmallVector<Type *, 4> ParamTys;
125 FastMathFlags FMF;
126 // If ScalarizationCost is UINT_MAX, the cost of scalarizing the
127 // arguments and the return value will be computed based on types.
128 InstructionCost ScalarizationCost = InstructionCost::getInvalid();
129
130public:
132 Intrinsic::ID Id, const CallBase &CI,
134 bool TypeBasedOnly = false);
135
137 Intrinsic::ID Id, Type *RTy, ArrayRef<Type *> Tys,
138 FastMathFlags Flags = FastMathFlags(), const IntrinsicInst *I = nullptr,
140
143
147 const IntrinsicInst *I = nullptr,
149
150 Intrinsic::ID getID() const { return IID; }
151 const IntrinsicInst *getInst() const { return II; }
152 Type *getReturnType() const { return RetTy; }
153 FastMathFlags getFlags() const { return FMF; }
154 InstructionCost getScalarizationCost() const { return ScalarizationCost; }
156 const SmallVectorImpl<Type *> &getArgTypes() const { return ParamTys; }
157
158 bool isTypeBasedOnly() const {
159 return Arguments.empty();
160 }
161
162 bool skipScalarizationCost() const { return ScalarizationCost.isValid(); }
163};
164
166 /// Don't use tail folding
167 None,
168 /// Use predicate only to mask operations on data in the loop.
169 /// When the VL is not known to be a power-of-2, this method requires a
170 /// runtime overflow check for the i + VL in the loop because it compares the
171 /// scalar induction variable against the tripcount rounded up by VL which may
172 /// overflow. When the VL is a power-of-2, both the increment and uprounded
173 /// tripcount will overflow to 0, which does not require a runtime check
174 /// since the loop is exited when the loop induction variable equals the
175 /// uprounded trip-count, which are both 0.
176 Data,
177 /// Same as Data, but avoids using the get.active.lane.mask intrinsic to
178 /// calculate the mask and instead implements this with a
179 /// splat/stepvector/cmp.
180 /// FIXME: Can this kind be removed now that SelectionDAGBuilder expands the
181 /// active.lane.mask intrinsic when it is not natively supported?
183 /// Use predicate to control both data and control flow.
184 /// This method always requires a runtime overflow check for the i + VL
185 /// increment inside the loop, because it uses the result direclty in the
186 /// active.lane.mask to calculate the mask for the next iteration. If the
187 /// increment overflows, the mask is no longer correct.
189 /// Use predicate to control both data and control flow, but modify
190 /// the trip count so that a runtime overflow check can be avoided
191 /// and such that the scalar epilogue loop can always be removed.
193 /// Use predicated EVL instructions for tail-folding.
194 /// Indicates that VP intrinsics should be used.
196};
197
204 : TLI(TLI), LVL(LVL), IAI(IAI) {}
205};
206
207class TargetTransformInfo;
209
210/// This pass provides access to the codegen interfaces that are needed
211/// for IR-level transformations.
213public:
215
216 /// Get the kind of extension that an instruction represents.
219
220 /// Construct a TTI object using a type implementing the \c Concept
221 /// API below.
222 ///
223 /// This is used by targets to construct a TTI wrapping their target-specific
224 /// implementation that encodes appropriate costs for their target.
225 template <typename T> TargetTransformInfo(T Impl);
226
227 /// Construct a baseline TTI object using a minimal implementation of
228 /// the \c Concept API below.
229 ///
230 /// The TTI implementation will reflect the information in the DataLayout
231 /// provided if non-null.
232 explicit TargetTransformInfo(const DataLayout &DL);
233
234 // Provide move semantics.
237
238 // We need to define the destructor out-of-line to define our sub-classes
239 // out-of-line.
241
242 /// Handle the invalidation of this information.
243 ///
244 /// When used as a result of \c TargetIRAnalysis this method will be called
245 /// when the function this was computed for changes. When it returns false,
246 /// the information is preserved across those changes.
249 // FIXME: We should probably in some way ensure that the subtarget
250 // information for a function hasn't changed.
251 return false;
252 }
253
254 /// \name Generic Target Information
255 /// @{
256
257 /// The kind of cost model.
258 ///
259 /// There are several different cost models that can be customized by the
260 /// target. The normalization of each cost model may be target specific.
261 /// e.g. TCK_SizeAndLatency should be comparable to target thresholds such as
262 /// those derived from MCSchedModel::LoopMicroOpBufferSize etc.
264 TCK_RecipThroughput, ///< Reciprocal throughput.
265 TCK_Latency, ///< The latency of instruction.
266 TCK_CodeSize, ///< Instruction code size.
267 TCK_SizeAndLatency ///< The weighted sum of size and latency.
268 };
269
270 /// Underlying constants for 'cost' values in this interface.
271 ///
272 /// Many APIs in this interface return a cost. This enum defines the
273 /// fundamental values that should be used to interpret (and produce) those
274 /// costs. The costs are returned as an int rather than a member of this
275 /// enumeration because it is expected that the cost of one IR instruction
276 /// may have a multiplicative factor to it or otherwise won't fit directly
277 /// into the enum. Moreover, it is common to sum or average costs which works
278 /// better as simple integral values. Thus this enum only provides constants.
279 /// Also note that the returned costs are signed integers to make it natural
280 /// to add, subtract, and test with zero (a common boundary condition). It is
281 /// not expected that 2^32 is a realistic cost to be modeling at any point.
282 ///
283 /// Note that these costs should usually reflect the intersection of code-size
284 /// cost and execution cost. A free instruction is typically one that folds
285 /// into another instruction. For example, reg-to-reg moves can often be
286 /// skipped by renaming the registers in the CPU, but they still are encoded
287 /// and thus wouldn't be considered 'free' here.
289 TCC_Free = 0, ///< Expected to fold away in lowering.
290 TCC_Basic = 1, ///< The cost of a typical 'add' instruction.
291 TCC_Expensive = 4 ///< The cost of a 'div' instruction on x86.
292 };
293
294 /// Estimate the cost of a GEP operation when lowered.
295 ///
296 /// \p PointeeType is the source element type of the GEP.
297 /// \p Ptr is the base pointer operand.
298 /// \p Operands is the list of indices following the base pointer.
299 ///
300 /// \p AccessType is a hint as to what type of memory might be accessed by
301 /// users of the GEP. getGEPCost will use it to determine if the GEP can be
302 /// folded into the addressing mode of a load/store. If AccessType is null,
303 /// then the resulting target type based off of PointeeType will be used as an
304 /// approximation.
306 getGEPCost(Type *PointeeType, const Value *Ptr,
307 ArrayRef<const Value *> Operands, Type *AccessType = nullptr,
309
310 /// Describe known properties for a set of pointers.
312 /// All the GEPs in a set have same base address.
313 unsigned IsSameBaseAddress : 1;
314 /// These properties only valid if SameBaseAddress is set.
315 /// True if all pointers are separated by a unit stride.
316 unsigned IsUnitStride : 1;
317 /// True if distance between any two neigbouring pointers is a known value.
318 unsigned IsKnownStride : 1;
319 unsigned Reserved : 29;
320
321 bool isSameBase() const { return IsSameBaseAddress; }
322 bool isUnitStride() const { return IsSameBaseAddress && IsUnitStride; }
324
326 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/1,
327 /*IsKnownStride=*/1, 0};
328 }
330 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/0,
331 /*IsKnownStride=*/1, 0};
332 }
334 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/0,
335 /*IsKnownStride=*/0, 0};
336 }
337 };
338 static_assert(sizeof(PointersChainInfo) == 4, "Was size increase justified?");
339
340 /// Estimate the cost of a chain of pointers (typically pointer operands of a
341 /// chain of loads or stores within same block) operations set when lowered.
342 /// \p AccessTy is the type of the loads/stores that will ultimately use the
343 /// \p Ptrs.
346 const PointersChainInfo &Info, Type *AccessTy,
348
349 /// \returns A value by which our inlining threshold should be multiplied.
350 /// This is primarily used to bump up the inlining threshold wholesale on
351 /// targets where calls are unusually expensive.
352 ///
353 /// TODO: This is a rather blunt instrument. Perhaps altering the costs of
354 /// individual classes of instructions would be better.
355 unsigned getInliningThresholdMultiplier() const;
356
359
360 /// \returns The bonus of inlining the last call to a static function.
362
363 /// \returns A value to be added to the inlining threshold.
364 unsigned adjustInliningThreshold(const CallBase *CB) const;
365
366 /// \returns The cost of having an Alloca in the caller if not inlined, to be
367 /// added to the threshold
368 unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const;
369
370 /// \returns Vector bonus in percent.
371 ///
372 /// Vector bonuses: We want to more aggressively inline vector-dense kernels
373 /// and apply this bonus based on the percentage of vector instructions. A
374 /// bonus is applied if the vector instructions exceed 50% and half that
375 /// amount is applied if it exceeds 10%. Note that these bonuses are some what
376 /// arbitrary and evolved over time by accident as much as because they are
377 /// principled bonuses.
378 /// FIXME: It would be nice to base the bonus values on something more
379 /// scientific. A target may has no bonus on vector instructions.
381
382 /// \return the expected cost of a memcpy, which could e.g. depend on the
383 /// source/destination type and alignment and the number of bytes copied.
385
386 /// Returns the maximum memset / memcpy size in bytes that still makes it
387 /// profitable to inline the call.
389
390 /// \return The estimated number of case clusters when lowering \p 'SI'.
391 /// \p JTSize Set a jump table size only when \p SI is suitable for a jump
392 /// table.
394 unsigned &JTSize,
396 BlockFrequencyInfo *BFI) const;
397
398 /// Estimate the cost of a given IR user when lowered.
399 ///
400 /// This can estimate the cost of either a ConstantExpr or Instruction when
401 /// lowered.
402 ///
403 /// \p Operands is a list of operands which can be a result of transformations
404 /// of the current operands. The number of the operands on the list must equal
405 /// to the number of the current operands the IR user has. Their order on the
406 /// list must be the same as the order of the current operands the IR user
407 /// has.
408 ///
409 /// The returned cost is defined in terms of \c TargetCostConstants, see its
410 /// comments for a detailed explanation of the cost values.
414
415 /// This is a helper function which calls the three-argument
416 /// getInstructionCost with \p Operands which are the current operands U has.
418 TargetCostKind CostKind) const {
419 SmallVector<const Value *, 4> Operands(U->operand_values());
421 }
422
423 /// If a branch or a select condition is skewed in one direction by more than
424 /// this factor, it is very likely to be predicted correctly.
426
427 /// Returns estimated penalty of a branch misprediction in latency. Indicates
428 /// how aggressive the target wants for eliminating unpredictable branches. A
429 /// zero return value means extra optimization applied to them should be
430 /// minimal.
432
433 /// Return true if branch divergence exists.
434 ///
435 /// Branch divergence has a significantly negative impact on GPU performance
436 /// when threads in the same wavefront take different paths due to conditional
437 /// branches.
438 ///
439 /// If \p F is passed, provides a context function. If \p F is known to only
440 /// execute in a single threaded environment, the target may choose to skip
441 /// uniformity analysis and assume all values are uniform.
442 bool hasBranchDivergence(const Function *F = nullptr) const;
443
444 /// Returns whether V is a source of divergence.
445 ///
446 /// This function provides the target-dependent information for
447 /// the target-independent UniformityAnalysis.
448 bool isSourceOfDivergence(const Value *V) const;
449
450 // Returns true for the target specific
451 // set of operations which produce uniform result
452 // even taking non-uniform arguments
453 bool isAlwaysUniform(const Value *V) const;
454
455 /// Query the target whether the specified address space cast from FromAS to
456 /// ToAS is valid.
457 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
458
459 /// Return false if a \p AS0 address cannot possibly alias a \p AS1 address.
460 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
461
462 /// Returns the address space ID for a target's 'flat' address space. Note
463 /// this is not necessarily the same as addrspace(0), which LLVM sometimes
464 /// refers to as the generic address space. The flat address space is a
465 /// generic address space that can be used access multiple segments of memory
466 /// with different address spaces. Access of a memory location through a
467 /// pointer with this address space is expected to be legal but slower
468 /// compared to the same memory location accessed through a pointer with a
469 /// different address space.
470 //
471 /// This is for targets with different pointer representations which can
472 /// be converted with the addrspacecast instruction. If a pointer is converted
473 /// to this address space, optimizations should attempt to replace the access
474 /// with the source address space.
475 ///
476 /// \returns ~0u if the target does not have such a flat address space to
477 /// optimize away.
478 unsigned getFlatAddressSpace() const;
479
480 /// Return any intrinsic address operand indexes which may be rewritten if
481 /// they use a flat address space pointer.
482 ///
483 /// \returns true if the intrinsic was handled.
485 Intrinsic::ID IID) const;
486
487 bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
488
489 /// Return true if globals in this address space can have initializers other
490 /// than `undef`.
492
493 unsigned getAssumedAddrSpace(const Value *V) const;
494
495 bool isSingleThreaded() const;
496
497 std::pair<const Value *, unsigned>
498 getPredicatedAddrSpace(const Value *V) const;
499
500 /// Rewrite intrinsic call \p II such that \p OldV will be replaced with \p
501 /// NewV, which has a different address space. This should happen for every
502 /// operand index that collectFlatAddressOperands returned for the intrinsic.
503 /// \returns nullptr if the intrinsic was not handled. Otherwise, returns the
504 /// new value (which may be the original \p II with modified operands).
506 Value *NewV) const;
507
508 /// Test whether calls to a function lower to actual program function
509 /// calls.
510 ///
511 /// The idea is to test whether the program is likely to require a 'call'
512 /// instruction or equivalent in order to call the given function.
513 ///
514 /// FIXME: It's not clear that this is a good or useful query API. Client's
515 /// should probably move to simpler cost metrics using the above.
516 /// Alternatively, we could split the cost interface into distinct code-size
517 /// and execution-speed costs. This would allow modelling the core of this
518 /// query more accurately as a call is a single small instruction, but
519 /// incurs significant execution cost.
520 bool isLoweredToCall(const Function *F) const;
521
522 struct LSRCost {
523 /// TODO: Some of these could be merged. Also, a lexical ordering
524 /// isn't always optimal.
525 unsigned Insns;
526 unsigned NumRegs;
527 unsigned AddRecCost;
528 unsigned NumIVMuls;
529 unsigned NumBaseAdds;
530 unsigned ImmCost;
531 unsigned SetupCost;
532 unsigned ScaleCost;
533 };
534
535 /// Parameters that control the generic loop unrolling transformation.
537 /// The cost threshold for the unrolled loop. Should be relative to the
538 /// getInstructionCost values returned by this API, and the expectation is
539 /// that the unrolled loop's instructions when run through that interface
540 /// should not exceed this cost. However, this is only an estimate. Also,
541 /// specific loops may be unrolled even with a cost above this threshold if
542 /// deemed profitable. Set this to UINT_MAX to disable the loop body cost
543 /// restriction.
544 unsigned Threshold;
545 /// If complete unrolling will reduce the cost of the loop, we will boost
546 /// the Threshold by a certain percent to allow more aggressive complete
547 /// unrolling. This value provides the maximum boost percentage that we
548 /// can apply to Threshold (The value should be no less than 100).
549 /// BoostedThreshold = Threshold * min(RolledCost / UnrolledCost,
550 /// MaxPercentThresholdBoost / 100)
551 /// E.g. if complete unrolling reduces the loop execution time by 50%
552 /// then we boost the threshold by the factor of 2x. If unrolling is not
553 /// expected to reduce the running time, then we do not increase the
554 /// threshold.
556 /// The cost threshold for the unrolled loop when optimizing for size (set
557 /// to UINT_MAX to disable).
559 /// The cost threshold for the unrolled loop, like Threshold, but used
560 /// for partial/runtime unrolling (set to UINT_MAX to disable).
562 /// The cost threshold for the unrolled loop when optimizing for size, like
563 /// OptSizeThreshold, but used for partial/runtime unrolling (set to
564 /// UINT_MAX to disable).
566 /// A forced unrolling factor (the number of concatenated bodies of the
567 /// original loop in the unrolled loop body). When set to 0, the unrolling
568 /// transformation will select an unrolling factor based on the current cost
569 /// threshold and other factors.
570 unsigned Count;
571 /// Default unroll count for loops with run-time trip count.
573 // Set the maximum unrolling factor. The unrolling factor may be selected
574 // using the appropriate cost threshold, but may not exceed this number
575 // (set to UINT_MAX to disable). This does not apply in cases where the
576 // loop is being fully unrolled.
577 unsigned MaxCount;
578 /// Set the maximum upper bound of trip count. Allowing the MaxUpperBound
579 /// to be overrided by a target gives more flexiblity on certain cases.
580 /// By default, MaxUpperBound uses UnrollMaxUpperBound which value is 8.
582 /// Set the maximum unrolling factor for full unrolling. Like MaxCount, but
583 /// applies even if full unrolling is selected. This allows a target to fall
584 /// back to Partial unrolling if full unrolling is above FullUnrollMaxCount.
586 // Represents number of instructions optimized when "back edge"
587 // becomes "fall through" in unrolled loop.
588 // For now we count a conditional branch on a backedge and a comparison
589 // feeding it.
590 unsigned BEInsns;
591 /// Allow partial unrolling (unrolling of loops to expand the size of the
592 /// loop body, not only to eliminate small constant-trip-count loops).
594 /// Allow runtime unrolling (unrolling of loops to expand the size of the
595 /// loop body even when the number of loop iterations is not known at
596 /// compile time).
598 /// Allow generation of a loop remainder (extra iterations after unroll).
600 /// Allow emitting expensive instructions (such as divisions) when computing
601 /// the trip count of a loop for runtime unrolling.
603 /// Apply loop unroll on any kind of loop
604 /// (mainly to loops that fail runtime unrolling).
605 bool Force;
606 /// Allow using trip count upper bound to unroll loops.
608 /// Allow unrolling of all the iterations of the runtime loop remainder.
610 /// Allow unroll and jam. Used to enable unroll and jam for the target.
612 /// Threshold for unroll and jam, for inner loop size. The 'Threshold'
613 /// value above is used during unroll and jam for the outer loop size.
614 /// This value is used in the same manner to limit the size of the inner
615 /// loop.
617 /// Don't allow loop unrolling to simulate more than this number of
618 /// iterations when checking full unroll profitability
620 /// Don't disable runtime unroll for the loops which were vectorized.
622 /// Don't allow runtime unrolling if expanding the trip count takes more
623 /// than SCEVExpansionBudget.
625 };
626
627 /// Get target-customized preferences for the generic loop unrolling
628 /// transformation. The caller will initialize UP with the current
629 /// target-independent defaults.
632 OptimizationRemarkEmitter *ORE) const;
633
634 /// Query the target whether it would be profitable to convert the given loop
635 /// into a hardware loop.
638 HardwareLoopInfo &HWLoopInfo) const;
639
640 // Query the target for which minimum vectorization factor epilogue
641 // vectorization should be considered.
642 unsigned getEpilogueVectorizationMinVF() const;
643
644 /// Query the target whether it would be prefered to create a predicated
645 /// vector loop, which can avoid the need to emit a scalar epilogue loop.
647
648 /// Query the target what the preferred style of tail folding is.
649 /// \param IVUpdateMayOverflow Tells whether it is known if the IV update
650 /// may (or will never) overflow for the suggested VF/UF in the given loop.
651 /// Targets can use this information to select a more optimal tail folding
652 /// style. The value conservatively defaults to true, such that no assumptions
653 /// are made on overflow.
655 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) const;
656
657 // Parameters that control the loop peeling transformation
659 /// A forced peeling factor (the number of bodied of the original loop
660 /// that should be peeled off before the loop body). When set to 0, the
661 /// a peeling factor based on profile information and other factors.
662 unsigned PeelCount;
663 /// Allow peeling off loop iterations.
665 /// Allow peeling off loop iterations for loop nests.
667 /// Allow peeling basing on profile. Uses to enable peeling off all
668 /// iterations basing on provided profile.
669 /// If the value is true the peeling cost model can decide to peel only
670 /// some iterations and in this case it will set this to false.
672 };
673
674 /// Get target-customized preferences for the generic loop peeling
675 /// transformation. The caller will initialize \p PP with the current
676 /// target-independent defaults with information from \p L and \p SE.
678 PeelingPreferences &PP) const;
679
680 /// Targets can implement their own combinations for target-specific
681 /// intrinsics. This function will be called from the InstCombine pass every
682 /// time a target-specific intrinsic is encountered.
683 ///
684 /// \returns std::nullopt to not do anything target specific or a value that
685 /// will be returned from the InstCombiner. It is possible to return null and
686 /// stop further processing of the intrinsic by returning nullptr.
687 std::optional<Instruction *> instCombineIntrinsic(InstCombiner & IC,
688 IntrinsicInst & II) const;
689 /// Can be used to implement target-specific instruction combining.
690 /// \see instCombineIntrinsic
691 std::optional<Value *> simplifyDemandedUseBitsIntrinsic(
692 InstCombiner & IC, IntrinsicInst & II, APInt DemandedMask,
693 KnownBits & Known, bool &KnownBitsComputed) const;
694 /// Can be used to implement target-specific instruction combining.
695 /// \see instCombineIntrinsic
696 std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
697 InstCombiner & IC, IntrinsicInst & II, APInt DemandedElts,
698 APInt & UndefElts, APInt & UndefElts2, APInt & UndefElts3,
699 std::function<void(Instruction *, unsigned, APInt, APInt &)>
700 SimplifyAndSetOp) const;
701 /// @}
702
703 /// \name Scalar Target Information
704 /// @{
705
706 /// Flags indicating the kind of support for population count.
707 ///
708 /// Compared to the SW implementation, HW support is supposed to
709 /// significantly boost the performance when the population is dense, and it
710 /// may or may not degrade performance if the population is sparse. A HW
711 /// support is considered as "Fast" if it can outperform, or is on a par
712 /// with, SW implementation when the population is sparse; otherwise, it is
713 /// considered as "Slow".
715
716 /// Return true if the specified immediate is legal add immediate, that
717 /// is the target has add instructions which can add a register with the
718 /// immediate without having to materialize the immediate into a register.
719 bool isLegalAddImmediate(int64_t Imm) const;
720
721 /// Return true if adding the specified scalable immediate is legal, that is
722 /// the target has add instructions which can add a register with the
723 /// immediate (multiplied by vscale) without having to materialize the
724 /// immediate into a register.
725 bool isLegalAddScalableImmediate(int64_t Imm) const;
726
727 /// Return true if the specified immediate is legal icmp immediate,
728 /// that is the target has icmp instructions which can compare a register
729 /// against the immediate without having to materialize the immediate into a
730 /// register.
731 bool isLegalICmpImmediate(int64_t Imm) const;
732
733 /// Return true if the addressing mode represented by AM is legal for
734 /// this target, for a load/store of the specified type.
735 /// The type may be VoidTy, in which case only return true if the addressing
736 /// mode is legal for a load/store of any legal type.
737 /// If target returns true in LSRWithInstrQueries(), I may be valid.
738 /// \param ScalableOffset represents a quantity of bytes multiplied by vscale,
739 /// an invariant value known only at runtime. Most targets should not accept
740 /// a scalable offset.
741 ///
742 /// TODO: Handle pre/postinc as well.
743 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
744 bool HasBaseReg, int64_t Scale,
745 unsigned AddrSpace = 0, Instruction *I = nullptr,
746 int64_t ScalableOffset = 0) const;
747
748 /// Return true if LSR cost of C1 is lower than C2.
750 const TargetTransformInfo::LSRCost &C2) const;
751
752 /// Return true if LSR major cost is number of registers. Targets which
753 /// implement their own isLSRCostLess and unset number of registers as major
754 /// cost should return false, otherwise return true.
755 bool isNumRegsMajorCostOfLSR() const;
756
757 /// Return true if LSR should drop a found solution if it's calculated to be
758 /// less profitable than the baseline.
760
761 /// \returns true if LSR should not optimize a chain that includes \p I.
763
764 /// Return true if the target can fuse a compare and branch.
765 /// Loop-strength-reduction (LSR) uses that knowledge to adjust its cost
766 /// calculation for the instructions in a loop.
767 bool canMacroFuseCmp() const;
768
769 /// Return true if the target can save a compare for loop count, for example
770 /// hardware loop saves a compare.
771 bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
773 TargetLibraryInfo *LibInfo) const;
774
779 };
780
781 /// Return the preferred addressing mode LSR should make efforts to generate.
783 ScalarEvolution *SE) const;
784
785 /// Return true if the target supports masked store.
786 bool isLegalMaskedStore(Type *DataType, Align Alignment) const;
787 /// Return true if the target supports masked load.
788 bool isLegalMaskedLoad(Type *DataType, Align Alignment) const;
789
790 /// Return true if the target supports nontemporal store.
791 bool isLegalNTStore(Type *DataType, Align Alignment) const;
792 /// Return true if the target supports nontemporal load.
793 bool isLegalNTLoad(Type *DataType, Align Alignment) const;
794
795 /// \Returns true if the target supports broadcasting a load to a vector of
796 /// type <NumElements x ElementTy>.
797 bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const;
798
799 /// Return true if the target supports masked scatter.
800 bool isLegalMaskedScatter(Type *DataType, Align Alignment) const;
801 /// Return true if the target supports masked gather.
802 bool isLegalMaskedGather(Type *DataType, Align Alignment) const;
803 /// Return true if the target forces scalarizing of llvm.masked.gather
804 /// intrinsics.
805 bool forceScalarizeMaskedGather(VectorType *Type, Align Alignment) const;
806 /// Return true if the target forces scalarizing of llvm.masked.scatter
807 /// intrinsics.
808 bool forceScalarizeMaskedScatter(VectorType *Type, Align Alignment) const;
809
810 /// Return true if the target supports masked compress store.
811 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const;
812 /// Return true if the target supports masked expand load.
813 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const;
814
815 /// Return true if the target supports strided load.
816 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const;
817
818 /// Return true is the target supports interleaved access for the given vector
819 /// type \p VTy, interleave factor \p Factor, alignment \p Alignment and
820 /// address space \p AddrSpace.
821 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
822 Align Alignment, unsigned AddrSpace) const;
823
824 // Return true if the target supports masked vector histograms.
825 bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const;
826
827 /// Return true if this is an alternating opcode pattern that can be lowered
828 /// to a single instruction on the target. In X86 this is for the addsub
829 /// instruction which corrsponds to a Shuffle + Fadd + FSub pattern in IR.
830 /// This function expectes two opcodes: \p Opcode1 and \p Opcode2 being
831 /// selected by \p OpcodeMask. The mask contains one bit per lane and is a `0`
832 /// when \p Opcode0 is selected and `1` when Opcode1 is selected.
833 /// \p VecTy is the vector type of the instruction to be generated.
834 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
835 const SmallBitVector &OpcodeMask) const;
836
837 /// Return true if we should be enabling ordered reductions for the target.
838 bool enableOrderedReductions() const;
839
840 /// Return true if the target has a unified operation to calculate division
841 /// and remainder. If so, the additional implicit multiplication and
842 /// subtraction required to calculate a remainder from division are free. This
843 /// can enable more aggressive transformations for division and remainder than
844 /// would typically be allowed using throughput or size cost models.
845 bool hasDivRemOp(Type *DataType, bool IsSigned) const;
846
847 /// Return true if the given instruction (assumed to be a memory access
848 /// instruction) has a volatile variant. If that's the case then we can avoid
849 /// addrspacecast to generic AS for volatile loads/stores. Default
850 /// implementation returns false, which prevents address space inference for
851 /// volatile loads/stores.
852 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const;
853
854 /// Return true if target doesn't mind addresses in vectors.
855 bool prefersVectorizedAddressing() const;
856
857 /// Return the cost of the scaling factor used in the addressing
858 /// mode represented by AM for this target, for a load/store
859 /// of the specified type.
860 /// If the AM is supported, the return value must be >= 0.
861 /// If the AM is not supported, it returns a negative value.
862 /// TODO: Handle pre/postinc as well.
864 StackOffset BaseOffset, bool HasBaseReg,
865 int64_t Scale,
866 unsigned AddrSpace = 0) const;
867
868 /// Return true if the loop strength reduce pass should make
869 /// Instruction* based TTI queries to isLegalAddressingMode(). This is
870 /// needed on SystemZ, where e.g. a memcpy can only have a 12 bit unsigned
871 /// immediate offset and no index register.
872 bool LSRWithInstrQueries() const;
873
874 /// Return true if it's free to truncate a value of type Ty1 to type
875 /// Ty2. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
876 /// by referencing its sub-register AX.
877 bool isTruncateFree(Type *Ty1, Type *Ty2) const;
878
879 /// Return true if it is profitable to hoist instruction in the
880 /// then/else to before if.
881 bool isProfitableToHoist(Instruction *I) const;
882
883 bool useAA() const;
884
885 /// Return true if this type is legal.
886 bool isTypeLegal(Type *Ty) const;
887
888 /// Returns the estimated number of registers required to represent \p Ty.
889 unsigned getRegUsageForType(Type *Ty) const;
890
891 /// Return true if switches should be turned into lookup tables for the
892 /// target.
893 bool shouldBuildLookupTables() const;
894
895 /// Return true if switches should be turned into lookup tables
896 /// containing this constant value for the target.
898
899 /// Return true if lookup tables should be turned into relative lookup tables.
900 bool shouldBuildRelLookupTables() const;
901
902 /// Return true if the input function which is cold at all call sites,
903 /// should use coldcc calling convention.
904 bool useColdCCForColdCall(Function &F) const;
905
907
908 /// Identifies if the vector form of the intrinsic has a scalar operand.
910 unsigned ScalarOpdIdx) const;
911
912 /// Identifies if the vector form of the intrinsic is overloaded on the type
913 /// of the operand at index \p OpdIdx, or on the return type if \p OpdIdx is
914 /// -1.
916 int OpdIdx) const;
917
918 /// Identifies if the vector form of the intrinsic that returns a struct is
919 /// overloaded at the struct element index \p RetIdx.
921 int RetIdx) const;
922
923 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
924 /// are set if the demanded result elements need to be inserted and/or
925 /// extracted from vectors. The involved values may be passed in VL if
926 /// Insert is true.
928 const APInt &DemandedElts,
929 bool Insert, bool Extract,
931 ArrayRef<Value *> VL = {}) const;
932
933 /// Estimate the overhead of scalarizing an instructions unique
934 /// non-constant operands. The (potentially vector) types to use for each of
935 /// argument are passes via Tys.
936 InstructionCost
937 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
938 ArrayRef<Type *> Tys,
940
941 /// If target has efficient vector element load/store instructions, it can
942 /// return true here so that insertion/extraction costs are not added to
943 /// the scalarization cost of a load/store.
945
946 /// If the target supports tail calls.
947 bool supportsTailCalls() const;
948
949 /// If target supports tail call on \p CB
950 bool supportsTailCallFor(const CallBase *CB) const;
951
952 /// Don't restrict interleaved unrolling to small loops.
953 bool enableAggressiveInterleaving(bool LoopHasReductions) const;
954
955 /// Returns options for expansion of memcmp. IsZeroCmp is
956 // true if this is the expansion of memcmp(p1, p2, s) == 0.
958 // Return true if memcmp expansion is enabled.
959 operator bool() const { return MaxNumLoads > 0; }
960
961 // Maximum number of load operations.
962 unsigned MaxNumLoads = 0;
963
964 // The list of available load sizes (in bytes), sorted in decreasing order.
966
967 // For memcmp expansion when the memcmp result is only compared equal or
968 // not-equal to 0, allow up to this number of load pairs per block. As an
969 // example, this may allow 'memcmp(a, b, 3) == 0' in a single block:
970 // a0 = load2bytes &a[0]
971 // b0 = load2bytes &b[0]
972 // a2 = load1byte &a[2]
973 // b2 = load1byte &b[2]
974 // r = cmp eq (a0 ^ b0 | a2 ^ b2), 0
975 unsigned NumLoadsPerBlock = 1;
976
977 // Set to true to allow overlapping loads. For example, 7-byte compares can
978 // be done with two 4-byte compares instead of 4+2+1-byte compares. This
979 // requires all loads in LoadSizes to be doable in an unaligned way.
981
982 // Sometimes, the amount of data that needs to be compared is smaller than
983 // the standard register size, but it cannot be loaded with just one load
984 // instruction. For example, if the size of the memory comparison is 6
985 // bytes, we can handle it more efficiently by loading all 6 bytes in a
986 // single block and generating an 8-byte number, instead of generating two
987 // separate blocks with conditional jumps for 4 and 2 byte loads. This
988 // approach simplifies the process and produces the comparison result as
989 // normal. This array lists the allowed sizes of memcmp tails that can be
990 // merged into one block
992 };
994 bool IsZeroCmp) const;
995
996 /// Should the Select Optimization pass be enabled and ran.
997 bool enableSelectOptimize() const;
998
999 /// Should the Select Optimization pass treat the given instruction like a
1000 /// select, potentially converting it to a conditional branch. This can
1001 /// include select-like instructions like or(zext(c), x) that can be converted
1002 /// to selects.
1004
1005 /// Enable matching of interleaved access groups.
1007
1008 /// Enable matching of interleaved access groups that contain predicated
1009 /// accesses or gaps and therefore vectorized using masked
1010 /// vector loads/stores.
1012
1013 /// Indicate that it is potentially unsafe to automatically vectorize
1014 /// floating-point operations because the semantics of vector and scalar
1015 /// floating-point semantics may differ. For example, ARM NEON v7 SIMD math
1016 /// does not support IEEE-754 denormal numbers, while depending on the
1017 /// platform, scalar floating-point math does.
1018 /// This applies to floating-point math operations and calls, not memory
1019 /// operations, shuffles, or casts.
1021
1022 /// Determine if the target supports unaligned memory accesses.
1023 bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth,
1024 unsigned AddressSpace = 0,
1025 Align Alignment = Align(1),
1026 unsigned *Fast = nullptr) const;
1027
1028 /// Return hardware support for population count.
1029 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
1030
1031 /// Return true if the hardware has a fast square-root instruction.
1032 bool haveFastSqrt(Type *Ty) const;
1033
1034 /// Return true if the cost of the instruction is too high to speculatively
1035 /// execute and should be kept behind a branch.
1036 /// This normally just wraps around a getInstructionCost() call, but some
1037 /// targets might report a low TCK_SizeAndLatency value that is incompatible
1038 /// with the fixed TCC_Expensive value.
1039 /// NOTE: This assumes the instruction passes isSafeToSpeculativelyExecute().
1041
1042 /// Return true if it is faster to check if a floating-point value is NaN
1043 /// (or not-NaN) versus a comparison against a constant FP zero value.
1044 /// Targets should override this if materializing a 0.0 for comparison is
1045 /// generally as cheap as checking for ordered/unordered.
1046 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const;
1047
1048 /// Return the expected cost of supporting the floating point operation
1049 /// of the specified type.
1050 InstructionCost getFPOpCost(Type *Ty) const;
1051
1052 /// Return the expected cost of materializing for the given integer
1053 /// immediate of the specified type.
1054 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
1055 TargetCostKind CostKind) const;
1056
1057 /// Return the expected cost of materialization for the given integer
1058 /// immediate of the specified type for a given instruction. The cost can be
1059 /// zero if the immediate can be folded into the specified instruction.
1060 InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
1061 const APInt &Imm, Type *Ty,
1063 Instruction *Inst = nullptr) const;
1065 const APInt &Imm, Type *Ty,
1066 TargetCostKind CostKind) const;
1067
1068 /// Return the expected cost for the given integer when optimising
1069 /// for size. This is different than the other integer immediate cost
1070 /// functions in that it is subtarget agnostic. This is useful when you e.g.
1071 /// target one ISA such as Aarch32 but smaller encodings could be possible
1072 /// with another such as Thumb. This return value is used as a penalty when
1073 /// the total costs for a constant is calculated (the bigger the cost, the
1074 /// more beneficial constant hoisting is).
1075 InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
1076 const APInt &Imm, Type *Ty) const;
1077
1078 /// It can be advantageous to detach complex constants from their uses to make
1079 /// their generation cheaper. This hook allows targets to report when such
1080 /// transformations might negatively effect the code generation of the
1081 /// underlying operation. The motivating example is divides whereby hoisting
1082 /// constants prevents the code generator's ability to transform them into
1083 /// combinations of simpler operations.
1085 const Function &Fn) const;
1086
1087 /// @}
1088
1089 /// \name Vector Target Information
1090 /// @{
1091
1092 /// The various kinds of shuffle patterns for vector queries.
1094 SK_Broadcast, ///< Broadcast element 0 to all other elements.
1095 SK_Reverse, ///< Reverse the order of the vector.
1096 SK_Select, ///< Selects elements from the corresponding lane of
1097 ///< either source operand. This is equivalent to a
1098 ///< vector select with a constant condition operand.
1099 SK_Transpose, ///< Transpose two vectors.
1100 SK_InsertSubvector, ///< InsertSubvector. Index indicates start offset.
1101 SK_ExtractSubvector, ///< ExtractSubvector Index indicates start offset.
1102 SK_PermuteTwoSrc, ///< Merge elements from two source vectors into one
1103 ///< with any shuffle mask.
1104 SK_PermuteSingleSrc, ///< Shuffle elements of single source vector with any
1105 ///< shuffle mask.
1106 SK_Splice ///< Concatenates elements from the first input vector
1107 ///< with elements of the second input vector. Returning
1108 ///< a vector of the same type as the input vectors.
1109 ///< Index indicates start offset in first input vector.
1111
1112 /// Additional information about an operand's possible values.
1114 OK_AnyValue, // Operand can have any value.
1115 OK_UniformValue, // Operand is uniform (splat of a value).
1116 OK_UniformConstantValue, // Operand is uniform constant.
1117 OK_NonUniformConstantValue // Operand is a non uniform constant value.
1119
1120 /// Additional properties of an operand's values.
1125 };
1126
1127 // Describe the values an operand can take. We're in the process
1128 // of migrating uses of OperandValueKind and OperandValueProperties
1129 // to use this class, and then will change the internal representation.
1133
1134 bool isConstant() const {
1136 }
1137 bool isUniform() const {
1139 }
1140 bool isPowerOf2() const {
1141 return Properties == OP_PowerOf2;
1142 }
1143 bool isNegatedPowerOf2() const {
1145 }
1146
1148 return {Kind, OP_None};
1149 }
1150 };
1151
1152 /// \return the number of registers in the target-provided register class.
1153 unsigned getNumberOfRegisters(unsigned ClassID) const;
1154
1155 /// \return true if the target supports load/store that enables fault
1156 /// suppression of memory operands when the source condition is false.
1157 bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const;
1158
1159 /// \return the target-provided register class ID for the provided type,
1160 /// accounting for type promotion and other type-legalization techniques that
1161 /// the target might apply. However, it specifically does not account for the
1162 /// scalarization or splitting of vector types. Should a vector type require
1163 /// scalarization or splitting into multiple underlying vector registers, that
1164 /// type should be mapped to a register class containing no registers.
1165 /// Specifically, this is designed to provide a simple, high-level view of the
1166 /// register allocation later performed by the backend. These register classes
1167 /// don't necessarily map onto the register classes used by the backend.
1168 /// FIXME: It's not currently possible to determine how many registers
1169 /// are used by the provided type.
1170 unsigned getRegisterClassForType(bool Vector, Type *Ty = nullptr) const;
1171
1172 /// \return the target-provided register class name
1173 const char *getRegisterClassName(unsigned ClassID) const;
1174
1176
1177 /// \return The width of the largest scalar or vector register type.
1179
1180 /// \return The width of the smallest vector register type.
1181 unsigned getMinVectorRegisterBitWidth() const;
1182
1183 /// \return The maximum value of vscale if the target specifies an
1184 /// architectural maximum vector length, and std::nullopt otherwise.
1185 std::optional<unsigned> getMaxVScale() const;
1186
1187 /// \return the value of vscale to tune the cost model for.
1188 std::optional<unsigned> getVScaleForTuning() const;
1189
1190 /// \return true if vscale is known to be a power of 2
1191 bool isVScaleKnownToBeAPowerOfTwo() const;
1192
1193 /// \return True if the vectorization factor should be chosen to
1194 /// make the vector of the smallest element type match the size of a
1195 /// vector register. For wider element types, this could result in
1196 /// creating vectors that span multiple vector registers.
1197 /// If false, the vectorization factor will be chosen based on the
1198 /// size of the widest element type.
1199 /// \p K Register Kind for vectorization.
1201
1202 /// \return The minimum vectorization factor for types of given element
1203 /// bit width, or 0 if there is no minimum VF. The returned value only
1204 /// applies when shouldMaximizeVectorBandwidth returns true.
1205 /// If IsScalable is true, the returned ElementCount must be a scalable VF.
1206 ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const;
1207
1208 /// \return The maximum vectorization factor for types of given element
1209 /// bit width and opcode, or 0 if there is no maximum VF.
1210 /// Currently only used by the SLP vectorizer.
1211 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const;
1212
1213 /// \return The minimum vectorization factor for the store instruction. Given
1214 /// the initial estimation of the minimum vector factor and store value type,
1215 /// it tries to find possible lowest VF, which still might be profitable for
1216 /// the vectorization.
1217 /// \param VF Initial estimation of the minimum vector factor.
1218 /// \param ScalarMemTy Scalar memory type of the store operation.
1219 /// \param ScalarValTy Scalar type of the stored value.
1220 /// Currently only used by the SLP vectorizer.
1221 unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
1222 Type *ScalarValTy) const;
1223
1224 /// \return True if it should be considered for address type promotion.
1225 /// \p AllowPromotionWithoutCommonHeader Set true if promoting \p I is
1226 /// profitable without finding other extensions fed by the same input.
1228 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const;
1229
1230 /// \return The size of a cache line in bytes.
1231 unsigned getCacheLineSize() const;
1232
1233 /// The possible cache levels
1234 enum class CacheLevel {
1235 L1D, // The L1 data cache
1236 L2D, // The L2 data cache
1237
1238 // We currently do not model L3 caches, as their sizes differ widely between
1239 // microarchitectures. Also, we currently do not have a use for L3 cache
1240 // size modeling yet.
1241 };
1242
1243 /// \return The size of the cache level in bytes, if available.
1244 std::optional<unsigned> getCacheSize(CacheLevel Level) const;
1245
1246 /// \return The associativity of the cache level, if available.
1247 std::optional<unsigned> getCacheAssociativity(CacheLevel Level) const;
1248
1249 /// \return The minimum architectural page size for the target.
1250 std::optional<unsigned> getMinPageSize() const;
1251
1252 /// \return How much before a load we should place the prefetch
1253 /// instruction. This is currently measured in number of
1254 /// instructions.
1255 unsigned getPrefetchDistance() const;
1256
1257 /// Some HW prefetchers can handle accesses up to a certain constant stride.
1258 /// Sometimes prefetching is beneficial even below the HW prefetcher limit,
1259 /// and the arguments provided are meant to serve as a basis for deciding this
1260 /// for a particular loop.
1261 ///
1262 /// \param NumMemAccesses Number of memory accesses in the loop.
1263 /// \param NumStridedMemAccesses Number of the memory accesses that
1264 /// ScalarEvolution could find a known stride
1265 /// for.
1266 /// \param NumPrefetches Number of software prefetches that will be
1267 /// emitted as determined by the addresses
1268 /// involved and the cache line size.
1269 /// \param HasCall True if the loop contains a call.
1270 ///
1271 /// \return This is the minimum stride in bytes where it makes sense to start
1272 /// adding SW prefetches. The default is 1, i.e. prefetch with any
1273 /// stride.
1274 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
1275 unsigned NumStridedMemAccesses,
1276 unsigned NumPrefetches, bool HasCall) const;
1277
1278 /// \return The maximum number of iterations to prefetch ahead. If
1279 /// the required number of iterations is more than this number, no
1280 /// prefetching is performed.
1281 unsigned getMaxPrefetchIterationsAhead() const;
1282
1283 /// \return True if prefetching should also be done for writes.
1284 bool enableWritePrefetching() const;
1285
1286 /// \return if target want to issue a prefetch in address space \p AS.
1287 bool shouldPrefetchAddressSpace(unsigned AS) const;
1288
1289 /// \return The cost of a partial reduction, which is a reduction from a
1290 /// vector to another vector with fewer elements of larger size. They are
1291 /// represented by the llvm.experimental.partial.reduce.add intrinsic, which
1292 /// takes an accumulator and a binary operation operand that itself is fed by
1293 /// two extends. An example of an operation that uses a partial reduction is a
1294 /// dot product, which reduces two vectors to another of 4 times fewer and 4
1295 /// times larger elements.
1297 getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB,
1298 Type *AccumType, ElementCount VF,
1301 std::optional<unsigned> BinOp = std::nullopt) const;
1302
1303 /// \return The maximum interleave factor that any transform should try to
1304 /// perform for this target. This number depends on the level of parallelism
1305 /// and the number of execution units in the CPU.
1306 unsigned getMaxInterleaveFactor(ElementCount VF) const;
1307
1308 /// Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
1309 static OperandValueInfo getOperandInfo(const Value *V);
1310
1311 /// This is an approximation of reciprocal throughput of a math/logic op.
1312 /// A higher cost indicates less expected throughput.
1313 /// From Agner Fog's guides, reciprocal throughput is "the average number of
1314 /// clock cycles per instruction when the instructions are not part of a
1315 /// limiting dependency chain."
1316 /// Therefore, costs should be scaled to account for multiple execution units
1317 /// on the target that can process this type of instruction. For example, if
1318 /// there are 5 scalar integer units and 2 vector integer units that can
1319 /// calculate an 'add' in a single cycle, this model should indicate that the
1320 /// cost of the vector add instruction is 2.5 times the cost of the scalar
1321 /// add instruction.
1322 /// \p Args is an optional argument which holds the instruction operands
1323 /// values so the TTI can analyze those values searching for special
1324 /// cases or optimizations based on those values.
1325 /// \p CxtI is the optional original context instruction, if one exists, to
1326 /// provide even more information.
1327 /// \p TLibInfo is used to search for platform specific vector library
1328 /// functions for instructions that might be converted to calls (e.g. frem).
1330 unsigned Opcode, Type *Ty,
1333 TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
1334 ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr,
1335 const TargetLibraryInfo *TLibInfo = nullptr) const;
1336
1337 /// Returns the cost estimation for alternating opcode pattern that can be
1338 /// lowered to a single instruction on the target. In X86 this is for the
1339 /// addsub instruction which corrsponds to a Shuffle + Fadd + FSub pattern in
1340 /// IR. This function expects two opcodes: \p Opcode1 and \p Opcode2 being
1341 /// selected by \p OpcodeMask. The mask contains one bit per lane and is a `0`
1342 /// when \p Opcode0 is selected and `1` when Opcode1 is selected.
1343 /// \p VecTy is the vector type of the instruction to be generated.
1344 InstructionCost getAltInstrCost(
1345 VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
1346 const SmallBitVector &OpcodeMask,
1348
1349 /// \return The cost of a shuffle instruction of kind Kind and of type Tp.
1350 /// The exact mask may be passed as Mask, or else the array will be empty.
1351 /// The index and subtype parameters are used by the subvector insertion and
1352 /// extraction shuffle kinds to show the insert/extract point and the type of
1353 /// the subvector being inserted/extracted. The operands of the shuffle can be
1354 /// passed through \p Args, which helps improve the cost estimation in some
1355 /// cases, like in broadcast loads.
1356 /// NOTE: For subvector extractions Tp represents the source type.
1357 InstructionCost
1358 getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask = {},
1360 int Index = 0, VectorType *SubTp = nullptr,
1361 ArrayRef<const Value *> Args = {},
1362 const Instruction *CxtI = nullptr) const;
1363
1364 /// Represents a hint about the context in which a cast is used.
1365 ///
1366 /// For zext/sext, the context of the cast is the operand, which must be a
1367 /// load of some kind. For trunc, the context is of the cast is the single
1368 /// user of the instruction, which must be a store of some kind.
1369 ///
1370 /// This enum allows the vectorizer to give getCastInstrCost an idea of the
1371 /// type of cast it's dealing with, as not every cast is equal. For instance,
1372 /// the zext of a load may be free, but the zext of an interleaving load can
1373 //// be (very) expensive!
1374 ///
1375 /// See \c getCastContextHint to compute a CastContextHint from a cast
1376 /// Instruction*. Callers can use it if they don't need to override the
1377 /// context and just want it to be calculated from the instruction.
1378 ///
1379 /// FIXME: This handles the types of load/store that the vectorizer can
1380 /// produce, which are the cases where the context instruction is most
1381 /// likely to be incorrect. There are other situations where that can happen
1382 /// too, which might be handled here but in the long run a more general
1383 /// solution of costing multiple instructions at the same times may be better.
1385 None, ///< The cast is not used with a load/store of any kind.
1386 Normal, ///< The cast is used with a normal load/store.
1387 Masked, ///< The cast is used with a masked load/store.
1388 GatherScatter, ///< The cast is used with a gather/scatter.
1389 Interleave, ///< The cast is used with an interleaved load/store.
1390 Reversed, ///< The cast is used with a reversed load/store.
1391 };
1392
1393 /// Calculates a CastContextHint from \p I.
1394 /// This should be used by callers of getCastInstrCost if they wish to
1395 /// determine the context from some instruction.
1396 /// \returns the CastContextHint for ZExt/SExt/Trunc, None if \p I is nullptr,
1397 /// or if it's another type of cast.
1399
1400 /// \return The expected cost of cast instructions, such as bitcast, trunc,
1401 /// zext, etc. If there is an existing instruction that holds Opcode, it
1402 /// may be passed in the 'I' parameter.
1404 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
1407 const Instruction *I = nullptr) const;
1408
1409 /// \return The expected cost of a sign- or zero-extended vector extract. Use
1410 /// Index = -1 to indicate that there is no information about the index value.
1411 InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
1412 VectorType *VecTy,
1413 unsigned Index) const;
1414
1415 /// \return The expected cost of control-flow related instructions such as
1416 /// Phi, Ret, Br, Switch.
1418 getCFInstrCost(unsigned Opcode,
1420 const Instruction *I = nullptr) const;
1421
1422 /// \returns The expected cost of compare and select instructions. If there
1423 /// is an existing instruction that holds Opcode, it may be passed in the
1424 /// 'I' parameter. The \p VecPred parameter can be used to indicate the select
1425 /// is using a compare with the specified predicate as condition. When vector
1426 /// types are passed, \p VecPred must be used for all lanes. For a
1427 /// comparison, the two operands are the natural values. For a select, the
1428 /// two operands are the *value* operands, not the condition operand.
1430 getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
1431 CmpInst::Predicate VecPred,
1433 OperandValueInfo Op1Info = {OK_AnyValue, OP_None},
1434 OperandValueInfo Op2Info = {OK_AnyValue, OP_None},
1435 const Instruction *I = nullptr) const;
1436
1437 /// \return The expected cost of vector Insert and Extract.
1438 /// Use -1 to indicate that there is no information on the index value.
1439 /// This is used when the instruction is not available; a typical use
1440 /// case is to provision the cost of vectorization/scalarization in
1441 /// vectorizer passes.
1442 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
1444 unsigned Index = -1, Value *Op0 = nullptr,
1445 Value *Op1 = nullptr) const;
1446
1447 /// \return The expected cost of vector Insert and Extract.
1448 /// Use -1 to indicate that there is no information on the index value.
1449 /// This is used when the instruction is not available; a typical use
1450 /// case is to provision the cost of vectorization/scalarization in
1451 /// vectorizer passes.
1452 /// \param ScalarUserAndIdx encodes the information about extracts from a
1453 /// vector with 'Scalar' being the value being extracted,'User' being the user
1454 /// of the extract(nullptr if user is not known before vectorization) and
1455 /// 'Idx' being the extract lane.
1456 InstructionCost getVectorInstrCost(
1457 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
1458 Value *Scalar,
1459 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const;
1460
1461 /// \return The expected cost of vector Insert and Extract.
1462 /// This is used when instruction is available, and implementation
1463 /// asserts 'I' is not nullptr.
1464 ///
1465 /// A typical suitable use case is cost estimation when vector instruction
1466 /// exists (e.g., from basic blocks during transformation).
1467 InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
1469 unsigned Index = -1) const;
1470
1471 /// \return The cost of replication shuffle of \p VF elements typed \p EltTy
1472 /// \p ReplicationFactor times.
1473 ///
1474 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
1475 /// <0,0,0,1,1,1,2,2,2,3,3,3>
1476 InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor,
1477 int VF,
1478 const APInt &DemandedDstElts,
1480
1481 /// \return The cost of Load and Store instructions.
1482 InstructionCost
1483 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
1484 unsigned AddressSpace,
1486 OperandValueInfo OpdInfo = {OK_AnyValue, OP_None},
1487 const Instruction *I = nullptr) const;
1488
1489 /// \return The cost of VP Load and Store instructions.
1490 InstructionCost
1491 getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
1492 unsigned AddressSpace,
1494 const Instruction *I = nullptr) const;
1495
1496 /// \return The cost of masked Load and Store instructions.
1498 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
1500
1501 /// \return The cost of Gather or Scatter operation
1502 /// \p Opcode - is a type of memory access Load or Store
1503 /// \p DataTy - a vector type of the data to be loaded or stored
1504 /// \p Ptr - pointer [or vector of pointers] - address[es] in memory
1505 /// \p VariableMask - true when the memory access is predicated with a mask
1506 /// that is not a compile-time constant
1507 /// \p Alignment - alignment of single element
1508 /// \p I - the optional original context instruction, if one exists, e.g. the
1509 /// load/store to transform or the call to the gather/scatter intrinsic
1511 unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
1513 const Instruction *I = nullptr) const;
1514
1515 /// \return The cost of strided memory operations.
1516 /// \p Opcode - is a type of memory access Load or Store
1517 /// \p DataTy - a vector type of the data to be loaded or stored
1518 /// \p Ptr - pointer [or vector of pointers] - address[es] in memory
1519 /// \p VariableMask - true when the memory access is predicated with a mask
1520 /// that is not a compile-time constant
1521 /// \p Alignment - alignment of single element
1522 /// \p I - the optional original context instruction, if one exists, e.g. the
1523 /// load/store to transform or the call to the gather/scatter intrinsic
1525 unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask,
1527 const Instruction *I = nullptr) const;
1528
1529 /// \return The cost of the interleaved memory operation.
1530 /// \p Opcode is the memory operation code
1531 /// \p VecTy is the vector type of the interleaved access.
1532 /// \p Factor is the interleave factor
1533 /// \p Indices is the indices for interleaved load members (as interleaved
1534 /// load allows gaps)
1535 /// \p Alignment is the alignment of the memory operation
1536 /// \p AddressSpace is address space of the pointer.
1537 /// \p UseMaskForCond indicates if the memory access is predicated.
1538 /// \p UseMaskForGaps indicates if gaps should be masked.
1540 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
1541 Align Alignment, unsigned AddressSpace,
1543 bool UseMaskForCond = false, bool UseMaskForGaps = false) const;
1544
1545 /// A helper function to determine the type of reduction algorithm used
1546 /// for a given \p Opcode and set of FastMathFlags \p FMF.
1547 static bool requiresOrderedReduction(std::optional<FastMathFlags> FMF) {
1548 return FMF && !(*FMF).allowReassoc();
1549 }
1550
1551 /// Calculate the cost of vector reduction intrinsics.
1552 ///
1553 /// This is the cost of reducing the vector value of type \p Ty to a scalar
1554 /// value using the operation denoted by \p Opcode. The FastMathFlags
1555 /// parameter \p FMF indicates what type of reduction we are performing:
1556 /// 1. Tree-wise. This is the typical 'fast' reduction performed that
1557 /// involves successively splitting a vector into half and doing the
1558 /// operation on the pair of halves until you have a scalar value. For
1559 /// example:
1560 /// (v0, v1, v2, v3)
1561 /// ((v0+v2), (v1+v3), undef, undef)
1562 /// ((v0+v2+v1+v3), undef, undef, undef)
1563 /// This is the default behaviour for integer operations, whereas for
1564 /// floating point we only do this if \p FMF indicates that
1565 /// reassociation is allowed.
1566 /// 2. Ordered. For a vector with N elements this involves performing N
1567 /// operations in lane order, starting with an initial scalar value, i.e.
1568 /// result = InitVal + v0
1569 /// result = result + v1
1570 /// result = result + v2
1571 /// result = result + v3
1572 /// This is only the case for FP operations and when reassociation is not
1573 /// allowed.
1574 ///
1576 unsigned Opcode, VectorType *Ty, std::optional<FastMathFlags> FMF,
1578
1582
1583 /// Calculate the cost of an extended reduction pattern, similar to
1584 /// getArithmeticReductionCost of an Add reduction with multiply and optional
1585 /// extensions. This is the cost of as:
1586 /// ResTy vecreduce.add(mul (A, B)).
1587 /// ResTy vecreduce.add(mul(ext(Ty A), ext(Ty B)).
1589 bool IsUnsigned, Type *ResTy, VectorType *Ty,
1591
1592 /// Calculate the cost of an extended reduction pattern, similar to
1593 /// getArithmeticReductionCost of a reduction with an extension.
1594 /// This is the cost of as:
1595 /// ResTy vecreduce.opcode(ext(Ty A)).
1597 unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty,
1598 FastMathFlags FMF,
1600
1601 /// \returns The cost of Intrinsic instructions. Analyses the real arguments.
1602 /// Three cases are handled: 1. scalar instruction 2. vector instruction
1603 /// 3. scalar instruction which is to be vectorized.
1606
1607 /// \returns The cost of Call instructions.
1611
1612 /// \returns The number of pieces into which the provided type must be
1613 /// split during legalization. Zero is returned when the answer is unknown.
1614 unsigned getNumberOfParts(Type *Tp) const;
1615
1616 /// \returns The cost of the address computation. For most targets this can be
1617 /// merged into the instruction indexing mode. Some targets might want to
1618 /// distinguish between address computation for memory operations on vector
1619 /// types and scalar types. Such targets should override this function.
1620 /// The 'SE' parameter holds pointer for the scalar evolution object which
1621 /// is used in order to get the Ptr step value in case of constant stride.
1622 /// The 'Ptr' parameter holds SCEV of the access pointer.
1624 ScalarEvolution *SE = nullptr,
1625 const SCEV *Ptr = nullptr) const;
1626
1627 /// \returns The cost, if any, of keeping values of the given types alive
1628 /// over a callsite.
1629 ///
1630 /// Some types may require the use of register classes that do not have
1631 /// any callee-saved registers, so would require a spill and fill.
1633
1634 /// \returns True if the intrinsic is a supported memory intrinsic. Info
1635 /// will contain additional information - whether the intrinsic may write
1636 /// or read to memory, volatility and the pointer. Info is undefined
1637 /// if false is returned.
1639
1640 /// \returns The maximum element size, in bytes, for an element
1641 /// unordered-atomic memory intrinsic.
1642 unsigned getAtomicMemIntrinsicMaxElementSize() const;
1643
1644 /// \returns A value which is the result of the given memory intrinsic. New
1645 /// instructions may be created to extract the result from the given intrinsic
1646 /// memory operation. Returns nullptr if the target cannot create a result
1647 /// from the given intrinsic.
1649 Type *ExpectedType) const;
1650
1651 /// \returns The type to use in a loop expansion of a memcpy call.
1653 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
1654 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
1655 std::optional<uint32_t> AtomicElementSize = std::nullopt) const;
1656
1657 /// \param[out] OpsOut The operand types to copy RemainingBytes of memory.
1658 /// \param RemainingBytes The number of bytes to copy.
1659 ///
1660 /// Calculates the operand types to use when copying \p RemainingBytes of
1661 /// memory, where source and destination alignments are \p SrcAlign and
1662 /// \p DestAlign respectively.
1664 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
1665 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
1666 Align SrcAlign, Align DestAlign,
1667 std::optional<uint32_t> AtomicCpySize = std::nullopt) const;
1668
1669 /// \returns True if the two functions have compatible attributes for inlining
1670 /// purposes.
1671 bool areInlineCompatible(const Function *Caller,
1672 const Function *Callee) const;
1673
1674 /// Returns a penalty for invoking call \p Call in \p F.
1675 /// For example, if a function F calls a function G, which in turn calls
1676 /// function H, then getInlineCallPenalty(F, H()) would return the
1677 /// penalty of calling H from F, e.g. after inlining G into F.
1678 /// \p DefaultCallPenalty is passed to give a default penalty that
1679 /// the target can amend or override.
1680 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
1681 unsigned DefaultCallPenalty) const;
1682
1683 /// \returns True if the caller and callee agree on how \p Types will be
1684 /// passed to or returned from the callee.
1685 /// to the callee.
1686 /// \param Types List of types to check.
1687 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
1688 const ArrayRef<Type *> &Types) const;
1689
1690 /// The type of load/store indexing.
1692 MIM_Unindexed, ///< No indexing.
1693 MIM_PreInc, ///< Pre-incrementing.
1694 MIM_PreDec, ///< Pre-decrementing.
1695 MIM_PostInc, ///< Post-incrementing.
1696 MIM_PostDec ///< Post-decrementing.
1698
1699 /// \returns True if the specified indexed load for the given type is legal.
1700 bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const;
1701
1702 /// \returns True if the specified indexed store for the given type is legal.
1703 bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const;
1704
1705 /// \returns The bitwidth of the largest vector type that should be used to
1706 /// load/store in the given address space.
1707 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
1708
1709 /// \returns True if the load instruction is legal to vectorize.
1710 bool isLegalToVectorizeLoad(LoadInst *LI) const;
1711
1712 /// \returns True if the store instruction is legal to vectorize.
1713 bool isLegalToVectorizeStore(StoreInst *SI) const;
1714
1715 /// \returns True if it is legal to vectorize the given load chain.
1716 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
1717 unsigned AddrSpace) const;
1718
1719 /// \returns True if it is legal to vectorize the given store chain.
1720 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
1721 unsigned AddrSpace) const;
1722
1723 /// \returns True if it is legal to vectorize the given reduction kind.
1725 ElementCount VF) const;
1726
1727 /// \returns True if the given type is supported for scalable vectors
1729
1730 /// \returns The new vector factor value if the target doesn't support \p
1731 /// SizeInBytes loads or has a better vector factor.
1732 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
1733 unsigned ChainSizeInBytes,
1734 VectorType *VecTy) const;
1735
1736 /// \returns The new vector factor value if the target doesn't support \p
1737 /// SizeInBytes stores or has a better vector factor.
1738 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
1739 unsigned ChainSizeInBytes,
1740 VectorType *VecTy) const;
1741
1742 /// Flags describing the kind of vector reduction.
1744 ReductionFlags() = default;
1745 bool IsMaxOp =
1746 false; ///< If the op a min/max kind, true if it's a max operation.
1747 bool IsSigned = false; ///< Whether the operation is a signed int reduction.
1748 bool NoNaN =
1749 false; ///< If op is an fp min/max, whether NaNs may be present.
1750 };
1751
1752 /// \returns True if the targets prefers fixed width vectorization if the
1753 /// loop vectorizer's cost-model assigns an equal cost to the fixed and
1754 /// scalable version of the vectorized loop.
1756
1757 /// \returns True if the target prefers reductions in loop.
1758 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
1759 ReductionFlags Flags) const;
1760
1761 /// \returns True if the target prefers reductions select kept in the loop
1762 /// when tail folding. i.e.
1763 /// loop:
1764 /// p = phi (0, s)
1765 /// a = add (p, x)
1766 /// s = select (mask, a, p)
1767 /// vecreduce.add(s)
1768 ///
1769 /// As opposed to the normal scheme of p = phi (0, a) which allows the select
1770 /// to be pulled out of the loop. If the select(.., add, ..) can be predicated
1771 /// by the target, this can lead to cleaner code generation.
1772 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
1773 ReductionFlags Flags) const;
1774
1775 /// Return true if the loop vectorizer should consider vectorizing an
1776 /// otherwise scalar epilogue loop.
1777 bool preferEpilogueVectorization() const;
1778
1779 /// \returns True if the target wants to expand the given reduction intrinsic
1780 /// into a shuffle sequence.
1781 bool shouldExpandReduction(const IntrinsicInst *II) const;
1782
1784
1785 /// \returns The shuffle sequence pattern used to expand the given reduction
1786 /// intrinsic.
1789
1790 /// \returns the size cost of rematerializing a GlobalValue address relative
1791 /// to a stack reload.
1792 unsigned getGISelRematGlobalCost() const;
1793
1794 /// \returns the lower bound of a trip count to decide on vectorization
1795 /// while tail-folding.
1796 unsigned getMinTripCountTailFoldingThreshold() const;
1797
1798 /// \returns True if the target supports scalable vectors.
1799 bool supportsScalableVectors() const;
1800
1801 /// \return true when scalable vectorization is preferred.
1802 bool enableScalableVectorization() const;
1803
1804 /// \name Vector Predication Information
1805 /// @{
1806 /// Whether the target supports the %evl parameter of VP intrinsic efficiently
1807 /// in hardware, for the given opcode and type/alignment. (see LLVM Language
1808 /// Reference - "Vector Predication Intrinsics").
1809 /// Use of %evl is discouraged when that is not the case.
1810 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
1811 Align Alignment) const;
1812
1813 /// Return true if sinking I's operands to the same basic block as I is
1814 /// profitable, e.g. because the operands can be folded into a target
1815 /// instruction during instruction selection. After calling the function
1816 /// \p Ops contains the Uses to sink ordered by dominance (dominating users
1817 /// come first).
1819 SmallVectorImpl<Use *> &Ops) const;
1820
1821 /// Return true if it's significantly cheaper to shift a vector by a uniform
1822 /// scalar than by an amount which will vary across each lane. On x86 before
1823 /// AVX2 for example, there is a "psllw" instruction for the former case, but
1824 /// no simple instruction for a general "a << b" operation on vectors.
1825 /// This should also apply to lowering for vector funnel shifts (rotates).
1826 bool isVectorShiftByScalarCheap(Type *Ty) const;
1827
1830 // keep the predicating parameter
1832 // where legal, discard the predicate parameter
1834 // transform into something else that is also predicating
1835 Convert = 2
1837
1838 // How to transform the EVL parameter.
1839 // Legal: keep the EVL parameter as it is.
1840 // Discard: Ignore the EVL parameter where it is safe to do so.
1841 // Convert: Fold the EVL into the mask parameter.
1843
1844 // How to transform the operator.
1845 // Legal: The target supports this operator.
1846 // Convert: Convert this to a non-VP operation.
1847 // The 'Discard' strategy is invalid.
1849
1850 bool shouldDoNothing() const {
1851 return (EVLParamStrategy == Legal) && (OpStrategy == Legal);
1852 }
1855 };
1856
1857 /// \returns How the target needs this vector-predicated operation to be
1858 /// transformed.
1860 /// @}
1861
1862 /// \returns Whether a 32-bit branch instruction is available in Arm or Thumb
1863 /// state.
1864 ///
1865 /// Used by the LowerTypeTests pass, which constructs an IR inline assembler
1866 /// node containing a jump table in a format suitable for the target, so it
1867 /// needs to know what format of jump table it can legally use.
1868 ///
1869 /// For non-Arm targets, this function isn't used. It defaults to returning
1870 /// false, but it shouldn't matter what it returns anyway.
1871 bool hasArmWideBranch(bool Thumb) const;
1872
1873 /// \return The maximum number of function arguments the target supports.
1874 unsigned getMaxNumArgs() const;
1875
1876 /// \return For an array of given Size, return alignment boundary to
1877 /// pad to. Default is no padding.
1878 unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const;
1879
1880 /// @}
1881
1882private:
1883 /// The abstract base class used to type erase specific TTI
1884 /// implementations.
1885 class Concept;
1886
1887 /// The template model for the base class which wraps a concrete
1888 /// implementation in a type erased interface.
1889 template <typename T> class Model;
1890
1891 std::unique_ptr<Concept> TTIImpl;
1892};
1893
1895public:
1896 virtual ~Concept() = 0;
1897 virtual const DataLayout &getDataLayout() const = 0;
1898 virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr,
1900 Type *AccessType,
1902 virtual InstructionCost
1904 const TTI::PointersChainInfo &Info, Type *AccessTy,
1906 virtual unsigned getInliningThresholdMultiplier() const = 0;
1908 virtual unsigned
1910 virtual int getInliningLastCallToStaticBonus() const = 0;
1911 virtual unsigned adjustInliningThreshold(const CallBase *CB) = 0;
1912 virtual int getInlinerVectorBonusPercent() const = 0;
1913 virtual unsigned getCallerAllocaCost(const CallBase *CB,
1914 const AllocaInst *AI) const = 0;
1917 virtual unsigned
1919 ProfileSummaryInfo *PSI,
1920 BlockFrequencyInfo *BFI) = 0;
1926 virtual bool hasBranchDivergence(const Function *F = nullptr) = 0;
1927 virtual bool isSourceOfDivergence(const Value *V) = 0;
1928 virtual bool isAlwaysUniform(const Value *V) = 0;
1929 virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
1930 virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
1931 virtual unsigned getFlatAddressSpace() = 0;
1933 Intrinsic::ID IID) const = 0;
1934 virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
1935 virtual bool
1937 virtual unsigned getAssumedAddrSpace(const Value *V) const = 0;
1938 virtual bool isSingleThreaded() const = 0;
1939 virtual std::pair<const Value *, unsigned>
1940 getPredicatedAddrSpace(const Value *V) const = 0;
1942 Value *OldV,
1943 Value *NewV) const = 0;
1944 virtual bool isLoweredToCall(const Function *F) = 0;
1947 OptimizationRemarkEmitter *ORE) = 0;
1949 PeelingPreferences &PP) = 0;
1951 AssumptionCache &AC,
1952 TargetLibraryInfo *LibInfo,
1953 HardwareLoopInfo &HWLoopInfo) = 0;
1954 virtual unsigned getEpilogueVectorizationMinVF() = 0;
1956 virtual TailFoldingStyle
1957 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) = 0;
1958 virtual std::optional<Instruction *> instCombineIntrinsic(
1959 InstCombiner &IC, IntrinsicInst &II) = 0;
1960 virtual std::optional<Value *> simplifyDemandedUseBitsIntrinsic(
1961 InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask,
1962 KnownBits & Known, bool &KnownBitsComputed) = 0;
1963 virtual std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
1964 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts,
1965 APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3,
1966 std::function<void(Instruction *, unsigned, APInt, APInt &)>
1967 SimplifyAndSetOp) = 0;
1968 virtual bool isLegalAddImmediate(int64_t Imm) = 0;
1969 virtual bool isLegalAddScalableImmediate(int64_t Imm) = 0;
1970 virtual bool isLegalICmpImmediate(int64_t Imm) = 0;
1971 virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
1972 int64_t BaseOffset, bool HasBaseReg,
1973 int64_t Scale, unsigned AddrSpace,
1974 Instruction *I,
1975 int64_t ScalableOffset) = 0;
1977 const TargetTransformInfo::LSRCost &C2) = 0;
1978 virtual bool isNumRegsMajorCostOfLSR() = 0;
1981 virtual bool canMacroFuseCmp() = 0;
1982 virtual bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE,
1984 TargetLibraryInfo *LibInfo) = 0;
1985 virtual AddressingModeKind
1987 virtual bool isLegalMaskedStore(Type *DataType, Align Alignment) = 0;
1988 virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment) = 0;
1989 virtual bool isLegalNTStore(Type *DataType, Align Alignment) = 0;
1990 virtual bool isLegalNTLoad(Type *DataType, Align Alignment) = 0;
1991 virtual bool isLegalBroadcastLoad(Type *ElementTy,
1992 ElementCount NumElements) const = 0;
1993 virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment) = 0;
1994 virtual bool isLegalMaskedGather(Type *DataType, Align Alignment) = 0;
1996 Align Alignment) = 0;
1998 Align Alignment) = 0;
1999 virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) = 0;
2000 virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) = 0;
2001 virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment) = 0;
2002 virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
2003 Align Alignment,
2004 unsigned AddrSpace) = 0;
2005
2006 virtual bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) = 0;
2007 virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
2008 unsigned Opcode1,
2009 const SmallBitVector &OpcodeMask) const = 0;
2010 virtual bool enableOrderedReductions() = 0;
2011 virtual bool hasDivRemOp(Type *DataType, bool IsSigned) = 0;
2012 virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) = 0;
2015 StackOffset BaseOffset,
2016 bool HasBaseReg, int64_t Scale,
2017 unsigned AddrSpace) = 0;
2018 virtual bool LSRWithInstrQueries() = 0;
2019 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) = 0;
2021 virtual bool useAA() = 0;
2022 virtual bool isTypeLegal(Type *Ty) = 0;
2023 virtual unsigned getRegUsageForType(Type *Ty) = 0;
2024 virtual bool shouldBuildLookupTables() = 0;
2026 virtual bool shouldBuildRelLookupTables() = 0;
2027 virtual bool useColdCCForColdCall(Function &F) = 0;
2030 unsigned ScalarOpdIdx) = 0;
2032 int OpdIdx) = 0;
2033 virtual bool
2035 int RetIdx) = 0;
2036 virtual InstructionCost
2038 bool Insert, bool Extract, TargetCostKind CostKind,
2039 ArrayRef<Value *> VL = {}) = 0;
2040 virtual InstructionCost
2042 ArrayRef<Type *> Tys,
2045 virtual bool supportsTailCalls() = 0;
2046 virtual bool supportsTailCallFor(const CallBase *CB) = 0;
2047 virtual bool enableAggressiveInterleaving(bool LoopHasReductions) = 0;
2049 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const = 0;
2050 virtual bool enableSelectOptimize() = 0;
2056 unsigned BitWidth,
2057 unsigned AddressSpace,
2058 Align Alignment,
2059 unsigned *Fast) = 0;
2060 virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) = 0;
2061 virtual bool haveFastSqrt(Type *Ty) = 0;
2063 virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) = 0;
2065 virtual InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
2066 const APInt &Imm, Type *Ty) = 0;
2067 virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
2069 virtual InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
2070 const APInt &Imm, Type *Ty,
2072 Instruction *Inst = nullptr) = 0;
2074 const APInt &Imm, Type *Ty,
2077 const Function &Fn) const = 0;
2078 virtual unsigned getNumberOfRegisters(unsigned ClassID) const = 0;
2079 virtual bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const = 0;
2080 virtual unsigned getRegisterClassForType(bool Vector,
2081 Type *Ty = nullptr) const = 0;
2082 virtual const char *getRegisterClassName(unsigned ClassID) const = 0;
2084 virtual unsigned getMinVectorRegisterBitWidth() const = 0;
2085 virtual std::optional<unsigned> getMaxVScale() const = 0;
2086 virtual std::optional<unsigned> getVScaleForTuning() const = 0;
2087 virtual bool isVScaleKnownToBeAPowerOfTwo() const = 0;
2088 virtual bool
2090 virtual ElementCount getMinimumVF(unsigned ElemWidth,
2091 bool IsScalable) const = 0;
2092 virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const = 0;
2093 virtual unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
2094 Type *ScalarValTy) const = 0;
2096 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) = 0;
2097 virtual unsigned getCacheLineSize() const = 0;
2098 virtual std::optional<unsigned> getCacheSize(CacheLevel Level) const = 0;
2099 virtual std::optional<unsigned> getCacheAssociativity(CacheLevel Level)
2100 const = 0;
2101 virtual std::optional<unsigned> getMinPageSize() const = 0;
2102
2103 /// \return How much before a load we should place the prefetch
2104 /// instruction. This is currently measured in number of
2105 /// instructions.
2106 virtual unsigned getPrefetchDistance() const = 0;
2107
2108 /// \return Some HW prefetchers can handle accesses up to a certain
2109 /// constant stride. This is the minimum stride in bytes where it
2110 /// makes sense to start adding SW prefetches. The default is 1,
2111 /// i.e. prefetch with any stride. Sometimes prefetching is beneficial
2112 /// even below the HW prefetcher limit, and the arguments provided are
2113 /// meant to serve as a basis for deciding this for a particular loop.
2114 virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses,
2115 unsigned NumStridedMemAccesses,
2116 unsigned NumPrefetches,
2117 bool HasCall) const = 0;
2118
2119 /// \return The maximum number of iterations to prefetch ahead. If
2120 /// the required number of iterations is more than this number, no
2121 /// prefetching is performed.
2122 virtual unsigned getMaxPrefetchIterationsAhead() const = 0;
2123
2124 /// \return True if prefetching should also be done for writes.
2125 virtual bool enableWritePrefetching() const = 0;
2126
2127 /// \return if target want to issue a prefetch in address space \p AS.
2128 virtual bool shouldPrefetchAddressSpace(unsigned AS) const = 0;
2129
2130 /// \return The cost of a partial reduction, which is a reduction from a
2131 /// vector to another vector with fewer elements of larger size. They are
2132 /// represented by the llvm.experimental.partial.reduce.add intrinsic, which
2133 /// takes an accumulator and a binary operation operand that itself is fed by
2134 /// two extends. An example of an operation that uses a partial reduction is a
2135 /// dot product, which reduces two vectors to another of 4 times fewer and 4
2136 /// times larger elements.
2137 virtual InstructionCost
2138 getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB,
2139 Type *AccumType, ElementCount VF,
2142 std::optional<unsigned> BinOp) const = 0;
2143
2144 virtual unsigned getMaxInterleaveFactor(ElementCount VF) = 0;
2146 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
2147 OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
2148 ArrayRef<const Value *> Args, const Instruction *CxtI = nullptr) = 0;
2150 VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
2151 const SmallBitVector &OpcodeMask,
2153
2154 virtual InstructionCost
2157 ArrayRef<const Value *> Args, const Instruction *CxtI) = 0;
2158 virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst,
2159 Type *Src, CastContextHint CCH,
2161 const Instruction *I) = 0;
2162 virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2163 VectorType *VecTy,
2164 unsigned Index) = 0;
2165 virtual InstructionCost getCFInstrCost(unsigned Opcode,
2167 const Instruction *I = nullptr) = 0;
2168 virtual InstructionCost
2169 getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
2171 OperandValueInfo Op1Info, OperandValueInfo Op2Info,
2172 const Instruction *I) = 0;
2173 virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
2175 unsigned Index, Value *Op0,
2176 Value *Op1) = 0;
2177
2178 /// \param ScalarUserAndIdx encodes the information about extracts from a
2179 /// vector with 'Scalar' being the value being extracted,'User' being the user
2180 /// of the extract(nullptr if user is not known before vectorization) and
2181 /// 'Idx' being the extract lane.
2183 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
2184 Value *Scalar,
2185 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) = 0;
2186
2189 unsigned Index) = 0;
2190
2191 virtual InstructionCost
2192 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
2193 const APInt &DemandedDstElts,
2195
2196 virtual InstructionCost
2197 getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2199 OperandValueInfo OpInfo, const Instruction *I) = 0;
2200 virtual InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src,
2201 Align Alignment,
2202 unsigned AddressSpace,
2204 const Instruction *I) = 0;
2205 virtual InstructionCost
2206 getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2207 unsigned AddressSpace,
2209 virtual InstructionCost
2210 getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2211 bool VariableMask, Align Alignment,
2213 const Instruction *I = nullptr) = 0;
2214 virtual InstructionCost
2215 getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2216 bool VariableMask, Align Alignment,
2218 const Instruction *I = nullptr) = 0;
2219
2221 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
2222 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
2223 bool UseMaskForCond = false, bool UseMaskForGaps = false) = 0;
2224 virtual InstructionCost
2226 std::optional<FastMathFlags> FMF,
2228 virtual InstructionCost
2232 unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty,
2233 FastMathFlags FMF,
2236 bool IsUnsigned, Type *ResTy, VectorType *Ty,
2238 virtual InstructionCost
2242 ArrayRef<Type *> Tys,
2244 virtual unsigned getNumberOfParts(Type *Tp) = 0;
2245 virtual InstructionCost
2247 virtual InstructionCost
2250 MemIntrinsicInfo &Info) = 0;
2251 virtual unsigned getAtomicMemIntrinsicMaxElementSize() const = 0;
2253 Type *ExpectedType) = 0;
2255 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
2256 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
2257 std::optional<uint32_t> AtomicElementSize) const = 0;
2258
2260 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
2261 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
2262 Align SrcAlign, Align DestAlign,
2263 std::optional<uint32_t> AtomicCpySize) const = 0;
2264 virtual bool areInlineCompatible(const Function *Caller,
2265 const Function *Callee) const = 0;
2266 virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
2267 unsigned DefaultCallPenalty) const = 0;
2268 virtual bool areTypesABICompatible(const Function *Caller,
2269 const Function *Callee,
2270 const ArrayRef<Type *> &Types) const = 0;
2271 virtual bool isIndexedLoadLegal(MemIndexedMode Mode, Type *Ty) const = 0;
2272 virtual bool isIndexedStoreLegal(MemIndexedMode Mode, Type *Ty) const = 0;
2273 virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const = 0;
2274 virtual bool isLegalToVectorizeLoad(LoadInst *LI) const = 0;
2275 virtual bool isLegalToVectorizeStore(StoreInst *SI) const = 0;
2276 virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
2277 Align Alignment,
2278 unsigned AddrSpace) const = 0;
2279 virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
2280 Align Alignment,
2281 unsigned AddrSpace) const = 0;
2283 ElementCount VF) const = 0;
2284 virtual bool isElementTypeLegalForScalableVector(Type *Ty) const = 0;
2285 virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
2286 unsigned ChainSizeInBytes,
2287 VectorType *VecTy) const = 0;
2288 virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
2289 unsigned ChainSizeInBytes,
2290 VectorType *VecTy) const = 0;
2291 virtual bool preferFixedOverScalableIfEqualCost() const = 0;
2292 virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty,
2293 ReductionFlags) const = 0;
2294 virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
2295 ReductionFlags) const = 0;
2296 virtual bool preferEpilogueVectorization() const = 0;
2297
2298 virtual bool shouldExpandReduction(const IntrinsicInst *II) const = 0;
2299 virtual ReductionShuffle
2301 virtual unsigned getGISelRematGlobalCost() const = 0;
2302 virtual unsigned getMinTripCountTailFoldingThreshold() const = 0;
2303 virtual bool enableScalableVectorization() const = 0;
2304 virtual bool supportsScalableVectors() const = 0;
2305 virtual bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
2306 Align Alignment) const = 0;
2307 virtual bool
2309 SmallVectorImpl<Use *> &OpsToSink) const = 0;
2310
2311 virtual bool isVectorShiftByScalarCheap(Type *Ty) const = 0;
2312 virtual VPLegalization
2314 virtual bool hasArmWideBranch(bool Thumb) const = 0;
2315 virtual unsigned getMaxNumArgs() const = 0;
2316 virtual unsigned getNumBytesToPadGlobalArray(unsigned Size,
2317 Type *ArrayType) const = 0;
2318};
2319
2320template <typename T>
2321class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
2322 T Impl;
2323
2324public:
2325 Model(T Impl) : Impl(std::move(Impl)) {}
2326 ~Model() override = default;
2327
2328 const DataLayout &getDataLayout() const override {
2329 return Impl.getDataLayout();
2330 }
2331
2332 InstructionCost
2333 getGEPCost(Type *PointeeType, const Value *Ptr,
2334 ArrayRef<const Value *> Operands, Type *AccessType,
2336 return Impl.getGEPCost(PointeeType, Ptr, Operands, AccessType, CostKind);
2337 }
2338 InstructionCost getPointersChainCost(ArrayRef<const Value *> Ptrs,
2339 const Value *Base,
2340 const PointersChainInfo &Info,
2341 Type *AccessTy,
2342 TargetCostKind CostKind) override {
2343 return Impl.getPointersChainCost(Ptrs, Base, Info, AccessTy, CostKind);
2344 }
2345 unsigned getInliningThresholdMultiplier() const override {
2346 return Impl.getInliningThresholdMultiplier();
2347 }
2348 unsigned adjustInliningThreshold(const CallBase *CB) override {
2349 return Impl.adjustInliningThreshold(CB);
2350 }
2351 unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const override {
2352 return Impl.getInliningCostBenefitAnalysisSavingsMultiplier();
2353 }
2354 unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const override {
2355 return Impl.getInliningCostBenefitAnalysisProfitableMultiplier();
2356 }
2357 int getInliningLastCallToStaticBonus() const override {
2358 return Impl.getInliningLastCallToStaticBonus();
2359 }
2360 int getInlinerVectorBonusPercent() const override {
2361 return Impl.getInlinerVectorBonusPercent();
2362 }
2363 unsigned getCallerAllocaCost(const CallBase *CB,
2364 const AllocaInst *AI) const override {
2365 return Impl.getCallerAllocaCost(CB, AI);
2366 }
2367 InstructionCost getMemcpyCost(const Instruction *I) override {
2368 return Impl.getMemcpyCost(I);
2369 }
2370
2371 uint64_t getMaxMemIntrinsicInlineSizeThreshold() const override {
2372 return Impl.getMaxMemIntrinsicInlineSizeThreshold();
2373 }
2374
2375 InstructionCost getInstructionCost(const User *U,
2376 ArrayRef<const Value *> Operands,
2377 TargetCostKind CostKind) override {
2378 return Impl.getInstructionCost(U, Operands, CostKind);
2379 }
2380 BranchProbability getPredictableBranchThreshold() override {
2381 return Impl.getPredictableBranchThreshold();
2382 }
2383 InstructionCost getBranchMispredictPenalty() override {
2384 return Impl.getBranchMispredictPenalty();
2385 }
2386 bool hasBranchDivergence(const Function *F = nullptr) override {
2387 return Impl.hasBranchDivergence(F);
2388 }
2389 bool isSourceOfDivergence(const Value *V) override {
2390 return Impl.isSourceOfDivergence(V);
2391 }
2392
2393 bool isAlwaysUniform(const Value *V) override {
2394 return Impl.isAlwaysUniform(V);
2395 }
2396
2397 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const override {
2398 return Impl.isValidAddrSpaceCast(FromAS, ToAS);
2399 }
2400
2401 bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const override {
2402 return Impl.addrspacesMayAlias(AS0, AS1);
2403 }
2404
2405 unsigned getFlatAddressSpace() override { return Impl.getFlatAddressSpace(); }
2406
2407 bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
2408 Intrinsic::ID IID) const override {
2409 return Impl.collectFlatAddressOperands(OpIndexes, IID);
2410 }
2411
2412 bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const override {
2413 return Impl.isNoopAddrSpaceCast(FromAS, ToAS);
2414 }
2415
2416 bool
2417 canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const override {
2418 return Impl.canHaveNonUndefGlobalInitializerInAddressSpace(AS);
2419 }
2420
2421 unsigned getAssumedAddrSpace(const Value *V) const override {
2422 return Impl.getAssumedAddrSpace(V);
2423 }
2424
2425 bool isSingleThreaded() const override { return Impl.isSingleThreaded(); }
2426
2427 std::pair<const Value *, unsigned>
2428 getPredicatedAddrSpace(const Value *V) const override {
2429 return Impl.getPredicatedAddrSpace(V);
2430 }
2431
2432 Value *rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV,
2433 Value *NewV) const override {
2434 return Impl.rewriteIntrinsicWithAddressSpace(II, OldV, NewV);
2435 }
2436
2437 bool isLoweredToCall(const Function *F) override {
2438 return Impl.isLoweredToCall(F);
2439 }
2440 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
2441 UnrollingPreferences &UP,
2442 OptimizationRemarkEmitter *ORE) override {
2443 return Impl.getUnrollingPreferences(L, SE, UP, ORE);
2444 }
2445 void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
2446 PeelingPreferences &PP) override {
2447 return Impl.getPeelingPreferences(L, SE, PP);
2448 }
2449 bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
2450 AssumptionCache &AC, TargetLibraryInfo *LibInfo,
2451 HardwareLoopInfo &HWLoopInfo) override {
2452 return Impl.isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo);
2453 }
2454 unsigned getEpilogueVectorizationMinVF() override {
2455 return Impl.getEpilogueVectorizationMinVF();
2456 }
2457 bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) override {
2458 return Impl.preferPredicateOverEpilogue(TFI);
2459 }
2461 getPreferredTailFoldingStyle(bool IVUpdateMayOverflow = true) override {
2462 return Impl.getPreferredTailFoldingStyle(IVUpdateMayOverflow);
2463 }
2464 std::optional<Instruction *>
2465 instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) override {
2466 return Impl.instCombineIntrinsic(IC, II);
2467 }
2468 std::optional<Value *>
2469 simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II,
2470 APInt DemandedMask, KnownBits &Known,
2471 bool &KnownBitsComputed) override {
2472 return Impl.simplifyDemandedUseBitsIntrinsic(IC, II, DemandedMask, Known,
2473 KnownBitsComputed);
2474 }
2475 std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
2476 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
2477 APInt &UndefElts2, APInt &UndefElts3,
2478 std::function<void(Instruction *, unsigned, APInt, APInt &)>
2479 SimplifyAndSetOp) override {
2480 return Impl.simplifyDemandedVectorEltsIntrinsic(
2481 IC, II, DemandedElts, UndefElts, UndefElts2, UndefElts3,
2482 SimplifyAndSetOp);
2483 }
2484 bool isLegalAddImmediate(int64_t Imm) override {
2485 return Impl.isLegalAddImmediate(Imm);
2486 }
2487 bool isLegalAddScalableImmediate(int64_t Imm) override {
2488 return Impl.isLegalAddScalableImmediate(Imm);
2489 }
2490 bool isLegalICmpImmediate(int64_t Imm) override {
2491 return Impl.isLegalICmpImmediate(Imm);
2492 }
2493 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
2494 bool HasBaseReg, int64_t Scale, unsigned AddrSpace,
2495 Instruction *I, int64_t ScalableOffset) override {
2496 return Impl.isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale,
2497 AddrSpace, I, ScalableOffset);
2498 }
2499 bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
2500 const TargetTransformInfo::LSRCost &C2) override {
2501 return Impl.isLSRCostLess(C1, C2);
2502 }
2503 bool isNumRegsMajorCostOfLSR() override {
2504 return Impl.isNumRegsMajorCostOfLSR();
2505 }
2506 bool shouldDropLSRSolutionIfLessProfitable() const override {
2507 return Impl.shouldDropLSRSolutionIfLessProfitable();
2508 }
2509 bool isProfitableLSRChainElement(Instruction *I) override {
2510 return Impl.isProfitableLSRChainElement(I);
2511 }
2512 bool canMacroFuseCmp() override { return Impl.canMacroFuseCmp(); }
2513 bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI,
2514 DominatorTree *DT, AssumptionCache *AC,
2515 TargetLibraryInfo *LibInfo) override {
2516 return Impl.canSaveCmp(L, BI, SE, LI, DT, AC, LibInfo);
2517 }
2519 getPreferredAddressingMode(const Loop *L,
2520 ScalarEvolution *SE) const override {
2521 return Impl.getPreferredAddressingMode(L, SE);
2522 }
2523 bool isLegalMaskedStore(Type *DataType, Align Alignment) override {
2524 return Impl.isLegalMaskedStore(DataType, Alignment);
2525 }
2526 bool isLegalMaskedLoad(Type *DataType, Align Alignment) override {
2527 return Impl.isLegalMaskedLoad(DataType, Alignment);
2528 }
2529 bool isLegalNTStore(Type *DataType, Align Alignment) override {
2530 return Impl.isLegalNTStore(DataType, Alignment);
2531 }
2532 bool isLegalNTLoad(Type *DataType, Align Alignment) override {
2533 return Impl.isLegalNTLoad(DataType, Alignment);
2534 }
2535 bool isLegalBroadcastLoad(Type *ElementTy,
2536 ElementCount NumElements) const override {
2537 return Impl.isLegalBroadcastLoad(ElementTy, NumElements);
2538 }
2539 bool isLegalMaskedScatter(Type *DataType, Align Alignment) override {
2540 return Impl.isLegalMaskedScatter(DataType, Alignment);
2541 }
2542 bool isLegalMaskedGather(Type *DataType, Align Alignment) override {
2543 return Impl.isLegalMaskedGather(DataType, Alignment);
2544 }
2545 bool forceScalarizeMaskedGather(VectorType *DataType,
2546 Align Alignment) override {
2547 return Impl.forceScalarizeMaskedGather(DataType, Alignment);
2548 }
2549 bool forceScalarizeMaskedScatter(VectorType *DataType,
2550 Align Alignment) override {
2551 return Impl.forceScalarizeMaskedScatter(DataType, Alignment);
2552 }
2553 bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) override {
2554 return Impl.isLegalMaskedCompressStore(DataType, Alignment);
2555 }
2556 bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) override {
2557 return Impl.isLegalMaskedExpandLoad(DataType, Alignment);
2558 }
2559 bool isLegalStridedLoadStore(Type *DataType, Align Alignment) override {
2560 return Impl.isLegalStridedLoadStore(DataType, Alignment);
2561 }
2562 bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
2563 Align Alignment,
2564 unsigned AddrSpace) override {
2565 return Impl.isLegalInterleavedAccessType(VTy, Factor, Alignment, AddrSpace);
2566 }
2567 bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) override {
2568 return Impl.isLegalMaskedVectorHistogram(AddrType, DataType);
2569 }
2570 bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
2571 const SmallBitVector &OpcodeMask) const override {
2572 return Impl.isLegalAltInstr(VecTy, Opcode0, Opcode1, OpcodeMask);
2573 }
2574 bool enableOrderedReductions() override {
2575 return Impl.enableOrderedReductions();
2576 }
2577 bool hasDivRemOp(Type *DataType, bool IsSigned) override {
2578 return Impl.hasDivRemOp(DataType, IsSigned);
2579 }
2580 bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) override {
2581 return Impl.hasVolatileVariant(I, AddrSpace);
2582 }
2583 bool prefersVectorizedAddressing() override {
2584 return Impl.prefersVectorizedAddressing();
2585 }
2586 InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
2587 StackOffset BaseOffset, bool HasBaseReg,
2588 int64_t Scale,
2589 unsigned AddrSpace) override {
2590 return Impl.getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, Scale,
2591 AddrSpace);
2592 }
2593 bool LSRWithInstrQueries() override { return Impl.LSRWithInstrQueries(); }
2594 bool isTruncateFree(Type *Ty1, Type *Ty2) override {
2595 return Impl.isTruncateFree(Ty1, Ty2);
2596 }
2597 bool isProfitableToHoist(Instruction *I) override {
2598 return Impl.isProfitableToHoist(I);
2599 }
2600 bool useAA() override { return Impl.useAA(); }
2601 bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); }
2602 unsigned getRegUsageForType(Type *Ty) override {
2603 return Impl.getRegUsageForType(Ty);
2604 }
2605 bool shouldBuildLookupTables() override {
2606 return Impl.shouldBuildLookupTables();
2607 }
2608 bool shouldBuildLookupTablesForConstant(Constant *C) override {
2609 return Impl.shouldBuildLookupTablesForConstant(C);
2610 }
2611 bool shouldBuildRelLookupTables() override {
2612 return Impl.shouldBuildRelLookupTables();
2613 }
2614 bool useColdCCForColdCall(Function &F) override {
2615 return Impl.useColdCCForColdCall(F);
2616 }
2617 bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) override {
2618 return Impl.isTargetIntrinsicTriviallyScalarizable(ID);
2619 }
2620
2621 bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
2622 unsigned ScalarOpdIdx) override {
2623 return Impl.isTargetIntrinsicWithScalarOpAtArg(ID, ScalarOpdIdx);
2624 }
2625
2626 bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
2627 int OpdIdx) override {
2628 return Impl.isTargetIntrinsicWithOverloadTypeAtArg(ID, OpdIdx);
2629 }
2630
2631 bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID,
2632 int RetIdx) override {
2633 return Impl.isTargetIntrinsicWithStructReturnOverloadAtField(ID, RetIdx);
2634 }
2635
2636 InstructionCost getScalarizationOverhead(VectorType *Ty,
2637 const APInt &DemandedElts,
2638 bool Insert, bool Extract,
2640 ArrayRef<Value *> VL = {}) override {
2641 return Impl.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
2642 CostKind, VL);
2643 }
2644 InstructionCost
2645 getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
2646 ArrayRef<Type *> Tys,
2647 TargetCostKind CostKind) override {
2648 return Impl.getOperandsScalarizationOverhead(Args, Tys, CostKind);
2649 }
2650
2651 bool supportsEfficientVectorElementLoadStore() override {
2652 return Impl.supportsEfficientVectorElementLoadStore();
2653 }
2654
2655 bool supportsTailCalls() override { return Impl.supportsTailCalls(); }
2656 bool supportsTailCallFor(const CallBase *CB) override {
2657 return Impl.supportsTailCallFor(CB);
2658 }
2659
2660 bool enableAggressiveInterleaving(bool LoopHasReductions) override {
2661 return Impl.enableAggressiveInterleaving(LoopHasReductions);
2662 }
2663 MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize,
2664 bool IsZeroCmp) const override {
2665 return Impl.enableMemCmpExpansion(OptSize, IsZeroCmp);
2666 }
2667 bool enableSelectOptimize() override {
2668 return Impl.enableSelectOptimize();
2669 }
2670 bool shouldTreatInstructionLikeSelect(const Instruction *I) override {
2671 return Impl.shouldTreatInstructionLikeSelect(I);
2672 }
2673 bool enableInterleavedAccessVectorization() override {
2674 return Impl.enableInterleavedAccessVectorization();
2675 }
2676 bool enableMaskedInterleavedAccessVectorization() override {
2677 return Impl.enableMaskedInterleavedAccessVectorization();
2678 }
2679 bool isFPVectorizationPotentiallyUnsafe() override {
2680 return Impl.isFPVectorizationPotentiallyUnsafe();
2681 }
2682 bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth,
2683 unsigned AddressSpace, Align Alignment,
2684 unsigned *Fast) override {
2685 return Impl.allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace,
2686 Alignment, Fast);
2687 }
2688 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) override {
2689 return Impl.getPopcntSupport(IntTyWidthInBit);
2690 }
2691 bool haveFastSqrt(Type *Ty) override { return Impl.haveFastSqrt(Ty); }
2692
2693 bool isExpensiveToSpeculativelyExecute(const Instruction* I) override {
2694 return Impl.isExpensiveToSpeculativelyExecute(I);
2695 }
2696
2697 bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) override {
2698 return Impl.isFCmpOrdCheaperThanFCmpZero(Ty);
2699 }
2700
2701 InstructionCost getFPOpCost(Type *Ty) override {
2702 return Impl.getFPOpCost(Ty);
2703 }
2704
2705 InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
2706 const APInt &Imm, Type *Ty) override {
2707 return Impl.getIntImmCodeSizeCost(Opc, Idx, Imm, Ty);
2708 }
2709 InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
2710 TargetCostKind CostKind) override {
2711 return Impl.getIntImmCost(Imm, Ty, CostKind);
2712 }
2713 InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
2714 const APInt &Imm, Type *Ty,
2716 Instruction *Inst = nullptr) override {
2717 return Impl.getIntImmCostInst(Opc, Idx, Imm, Ty, CostKind, Inst);
2718 }
2719 InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,
2720 const APInt &Imm, Type *Ty,
2721 TargetCostKind CostKind) override {
2722 return Impl.getIntImmCostIntrin(IID, Idx, Imm, Ty, CostKind);
2723 }
2724 bool preferToKeepConstantsAttached(const Instruction &Inst,
2725 const Function &Fn) const override {
2726 return Impl.preferToKeepConstantsAttached(Inst, Fn);
2727 }
2728 unsigned getNumberOfRegisters(unsigned ClassID) const override {
2729 return Impl.getNumberOfRegisters(ClassID);
2730 }
2731 bool hasConditionalLoadStoreForType(Type *Ty = nullptr) const override {
2732 return Impl.hasConditionalLoadStoreForType(Ty);
2733 }
2734 unsigned getRegisterClassForType(bool Vector,
2735 Type *Ty = nullptr) const override {
2736 return Impl.getRegisterClassForType(Vector, Ty);
2737 }
2738 const char *getRegisterClassName(unsigned ClassID) const override {
2739 return Impl.getRegisterClassName(ClassID);
2740 }
2741 TypeSize getRegisterBitWidth(RegisterKind K) const override {
2742 return Impl.getRegisterBitWidth(K);
2743 }
2744 unsigned getMinVectorRegisterBitWidth() const override {
2745 return Impl.getMinVectorRegisterBitWidth();
2746 }
2747 std::optional<unsigned> getMaxVScale() const override {
2748 return Impl.getMaxVScale();
2749 }
2750 std::optional<unsigned> getVScaleForTuning() const override {
2751 return Impl.getVScaleForTuning();
2752 }
2753 bool isVScaleKnownToBeAPowerOfTwo() const override {
2754 return Impl.isVScaleKnownToBeAPowerOfTwo();
2755 }
2756 bool shouldMaximizeVectorBandwidth(
2757 TargetTransformInfo::RegisterKind K) const override {
2758 return Impl.shouldMaximizeVectorBandwidth(K);
2759 }
2760 ElementCount getMinimumVF(unsigned ElemWidth,
2761 bool IsScalable) const override {
2762 return Impl.getMinimumVF(ElemWidth, IsScalable);
2763 }
2764 unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override {
2765 return Impl.getMaximumVF(ElemWidth, Opcode);
2766 }
2767 unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
2768 Type *ScalarValTy) const override {
2769 return Impl.getStoreMinimumVF(VF, ScalarMemTy, ScalarValTy);
2770 }
2771 bool shouldConsiderAddressTypePromotion(
2772 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) override {
2773 return Impl.shouldConsiderAddressTypePromotion(
2774 I, AllowPromotionWithoutCommonHeader);
2775 }
2776 unsigned getCacheLineSize() const override { return Impl.getCacheLineSize(); }
2777 std::optional<unsigned> getCacheSize(CacheLevel Level) const override {
2778 return Impl.getCacheSize(Level);
2779 }
2780 std::optional<unsigned>
2781 getCacheAssociativity(CacheLevel Level) const override {
2782 return Impl.getCacheAssociativity(Level);
2783 }
2784
2785 std::optional<unsigned> getMinPageSize() const override {
2786 return Impl.getMinPageSize();
2787 }
2788
2789 /// Return the preferred prefetch distance in terms of instructions.
2790 ///
2791 unsigned getPrefetchDistance() const override {
2792 return Impl.getPrefetchDistance();
2793 }
2794
2795 /// Return the minimum stride necessary to trigger software
2796 /// prefetching.
2797 ///
2798 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
2799 unsigned NumStridedMemAccesses,
2800 unsigned NumPrefetches,
2801 bool HasCall) const override {
2802 return Impl.getMinPrefetchStride(NumMemAccesses, NumStridedMemAccesses,
2803 NumPrefetches, HasCall);
2804 }
2805
2806 /// Return the maximum prefetch distance in terms of loop
2807 /// iterations.
2808 ///
2809 unsigned getMaxPrefetchIterationsAhead() const override {
2810 return Impl.getMaxPrefetchIterationsAhead();
2811 }
2812
2813 /// \return True if prefetching should also be done for writes.
2814 bool enableWritePrefetching() const override {
2815 return Impl.enableWritePrefetching();
2816 }
2817
2818 /// \return if target want to issue a prefetch in address space \p AS.
2819 bool shouldPrefetchAddressSpace(unsigned AS) const override {
2820 return Impl.shouldPrefetchAddressSpace(AS);
2821 }
2822
2823 InstructionCost getPartialReductionCost(
2824 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
2825 ElementCount VF, PartialReductionExtendKind OpAExtend,
2827 std::optional<unsigned> BinOp = std::nullopt) const override {
2828 return Impl.getPartialReductionCost(Opcode, InputTypeA, InputTypeB,
2829 AccumType, VF, OpAExtend, OpBExtend,
2830 BinOp);
2831 }
2832
2833 unsigned getMaxInterleaveFactor(ElementCount VF) override {
2834 return Impl.getMaxInterleaveFactor(VF);
2835 }
2836 unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
2837 unsigned &JTSize,
2838 ProfileSummaryInfo *PSI,
2839 BlockFrequencyInfo *BFI) override {
2840 return Impl.getEstimatedNumberOfCaseClusters(SI, JTSize, PSI, BFI);
2841 }
2842 InstructionCost getArithmeticInstrCost(
2843 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
2844 OperandValueInfo Opd1Info, OperandValueInfo Opd2Info,
2845 ArrayRef<const Value *> Args,
2846 const Instruction *CxtI = nullptr) override {
2847 return Impl.getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info, Opd2Info,
2848 Args, CxtI);
2849 }
2850 InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0,
2851 unsigned Opcode1,
2852 const SmallBitVector &OpcodeMask,
2853 TTI::TargetCostKind CostKind) const override {
2854 return Impl.getAltInstrCost(VecTy, Opcode0, Opcode1, OpcodeMask, CostKind);
2855 }
2856
2857 InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp,
2858 ArrayRef<int> Mask,
2860 VectorType *SubTp,
2861 ArrayRef<const Value *> Args,
2862 const Instruction *CxtI) override {
2863 return Impl.getShuffleCost(Kind, Tp, Mask, CostKind, Index, SubTp, Args,
2864 CxtI);
2865 }
2866 InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
2867 CastContextHint CCH,
2869 const Instruction *I) override {
2870 return Impl.getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
2871 }
2872 InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst,
2873 VectorType *VecTy,
2874 unsigned Index) override {
2875 return Impl.getExtractWithExtendCost(Opcode, Dst, VecTy, Index);
2876 }
2877 InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind,
2878 const Instruction *I = nullptr) override {
2879 return Impl.getCFInstrCost(Opcode, CostKind, I);
2880 }
2881 InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
2882 CmpInst::Predicate VecPred,
2884 OperandValueInfo Op1Info,
2885 OperandValueInfo Op2Info,
2886 const Instruction *I) override {
2887 return Impl.getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
2888 Op1Info, Op2Info, I);
2889 }
2890 InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
2892 unsigned Index, Value *Op0,
2893 Value *Op1) override {
2894 return Impl.getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1);
2895 }
2896 InstructionCost getVectorInstrCost(
2897 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
2898 Value *Scalar,
2899 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) override {
2900 return Impl.getVectorInstrCost(Opcode, Val, CostKind, Index, Scalar,
2901 ScalarUserAndIdx);
2902 }
2903 InstructionCost getVectorInstrCost(const Instruction &I, Type *Val,
2905 unsigned Index) override {
2906 return Impl.getVectorInstrCost(I, Val, CostKind, Index);
2907 }
2908 InstructionCost
2909 getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF,
2910 const APInt &DemandedDstElts,
2911 TTI::TargetCostKind CostKind) override {
2912 return Impl.getReplicationShuffleCost(EltTy, ReplicationFactor, VF,
2913 DemandedDstElts, CostKind);
2914 }
2915 InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2916 unsigned AddressSpace,
2918 OperandValueInfo OpInfo,
2919 const Instruction *I) override {
2920 return Impl.getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind,
2921 OpInfo, I);
2922 }
2923 InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment,
2924 unsigned AddressSpace,
2926 const Instruction *I) override {
2927 return Impl.getVPMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
2928 CostKind, I);
2929 }
2930 InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
2931 Align Alignment, unsigned AddressSpace,
2932 TTI::TargetCostKind CostKind) override {
2933 return Impl.getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
2934 CostKind);
2935 }
2936 InstructionCost
2937 getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2938 bool VariableMask, Align Alignment,
2940 const Instruction *I = nullptr) override {
2941 return Impl.getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask,
2942 Alignment, CostKind, I);
2943 }
2944 InstructionCost
2945 getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr,
2946 bool VariableMask, Align Alignment,
2948 const Instruction *I = nullptr) override {
2949 return Impl.getStridedMemoryOpCost(Opcode, DataTy, Ptr, VariableMask,
2950 Alignment, CostKind, I);
2951 }
2952 InstructionCost getInterleavedMemoryOpCost(
2953 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
2954 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
2955 bool UseMaskForCond, bool UseMaskForGaps) override {
2956 return Impl.getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
2957 Alignment, AddressSpace, CostKind,
2958 UseMaskForCond, UseMaskForGaps);
2959 }
2960 InstructionCost
2961 getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
2962 std::optional<FastMathFlags> FMF,
2963 TTI::TargetCostKind CostKind) override {
2964 return Impl.getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);
2965 }
2966 InstructionCost
2967 getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF,
2968 TTI::TargetCostKind CostKind) override {
2969 return Impl.getMinMaxReductionCost(IID, Ty, FMF, CostKind);
2970 }
2971 InstructionCost
2972 getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy,
2973 VectorType *Ty, FastMathFlags FMF,
2974 TTI::TargetCostKind CostKind) override {
2975 return Impl.getExtendedReductionCost(Opcode, IsUnsigned, ResTy, Ty, FMF,
2976 CostKind);
2977 }
2978 InstructionCost
2979 getMulAccReductionCost(bool IsUnsigned, Type *ResTy, VectorType *Ty,
2980 TTI::TargetCostKind CostKind) override {
2981 return Impl.getMulAccReductionCost(IsUnsigned, ResTy, Ty, CostKind);
2982 }
2983 InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
2984 TTI::TargetCostKind CostKind) override {
2985 return Impl.getIntrinsicInstrCost(ICA, CostKind);
2986 }
2987 InstructionCost getCallInstrCost(Function *F, Type *RetTy,
2988 ArrayRef<Type *> Tys,
2989 TTI::TargetCostKind CostKind) override {
2990 return Impl.getCallInstrCost(F, RetTy, Tys, CostKind);
2991 }
2992 unsigned getNumberOfParts(Type *Tp) override {
2993 return Impl.getNumberOfParts(Tp);
2994 }
2995 InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE,
2996 const SCEV *Ptr) override {
2997 return Impl.getAddressComputationCost(Ty, SE, Ptr);
2998 }
2999 InstructionCost getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) override {
3000 return Impl.getCostOfKeepingLiveOverCall(Tys);
3001 }
3002 bool getTgtMemIntrinsic(IntrinsicInst *Inst,
3003 MemIntrinsicInfo &Info) override {
3004 return Impl.getTgtMemIntrinsic(Inst, Info);
3005 }
3006 unsigned getAtomicMemIntrinsicMaxElementSize() const override {
3007 return Impl.getAtomicMemIntrinsicMaxElementSize();
3008 }
3009 Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
3010 Type *ExpectedType) override {
3011 return Impl.getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
3012 }
3013 Type *getMemcpyLoopLoweringType(
3014 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
3015 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
3016 std::optional<uint32_t> AtomicElementSize) const override {
3017 return Impl.getMemcpyLoopLoweringType(Context, Length, SrcAddrSpace,
3018 DestAddrSpace, SrcAlign, DestAlign,
3019 AtomicElementSize);
3020 }
3021 void getMemcpyLoopResidualLoweringType(
3022 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
3023 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
3024 Align SrcAlign, Align DestAlign,
3025 std::optional<uint32_t> AtomicCpySize) const override {
3026 Impl.getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes,
3027 SrcAddrSpace, DestAddrSpace,
3028 SrcAlign, DestAlign, AtomicCpySize);
3029 }
3030 bool areInlineCompatible(const Function *Caller,
3031 const Function *Callee) const override {
3032 return Impl.areInlineCompatible(Caller, Callee);
3033 }
3034 unsigned getInlineCallPenalty(const Function *F, const CallBase &Call,
3035 unsigned DefaultCallPenalty) const override {
3036 return Impl.getInlineCallPenalty(F, Call, DefaultCallPenalty);
3037 }
3038 bool areTypesABICompatible(const Function *Caller, const Function *Callee,
3039 const ArrayRef<Type *> &Types) const override {
3040 return Impl.areTypesABICompatible(Caller, Callee, Types);
3041 }
3042 bool isIndexedLoadLegal(MemIndexedMode Mode, Type *Ty) const override {
3043 return Impl.isIndexedLoadLegal(Mode, Ty, getDataLayout());
3044 }
3045 bool isIndexedStoreLegal(MemIndexedMode Mode, Type *Ty) const override {
3046 return Impl.isIndexedStoreLegal(Mode, Ty, getDataLayout());
3047 }
3048 unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const override {
3049 return Impl.getLoadStoreVecRegBitWidth(AddrSpace);
3050 }
3051 bool isLegalToVectorizeLoad(LoadInst *LI) const override {
3052 return Impl.isLegalToVectorizeLoad(LI);
3053 }
3054 bool isLegalToVectorizeStore(StoreInst *SI) const override {
3055 return Impl.isLegalToVectorizeStore(SI);
3056 }
3057 bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment,
3058 unsigned AddrSpace) const override {
3059 return Impl.isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment,
3060 AddrSpace);
3061 }
3062 bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment,
3063 unsigned AddrSpace) const override {
3064 return Impl.isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
3065 AddrSpace);
3066 }
3067 bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
3068 ElementCount VF) const override {
3069 return Impl.isLegalToVectorizeReduction(RdxDesc, VF);
3070 }
3071 bool isElementTypeLegalForScalableVector(Type *Ty) const override {
3072 return Impl.isElementTypeLegalForScalableVector(Ty);
3073 }
3074 unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
3075 unsigned ChainSizeInBytes,
3076 VectorType *VecTy) const override {
3077 return Impl.getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy);
3078 }
3079 unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
3080 unsigned ChainSizeInBytes,
3081 VectorType *VecTy) const override {
3082 return Impl.getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy);
3083 }
3084 bool preferFixedOverScalableIfEqualCost() const override {
3085 return Impl.preferFixedOverScalableIfEqualCost();
3086 }
3087 bool preferInLoopReduction(unsigned Opcode, Type *Ty,
3088 ReductionFlags Flags) const override {
3089 return Impl.preferInLoopReduction(Opcode, Ty, Flags);
3090 }
3091 bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty,
3092 ReductionFlags Flags) const override {
3093 return Impl.preferPredicatedReductionSelect(Opcode, Ty, Flags);
3094 }
3095 bool preferEpilogueVectorization() const override {
3096 return Impl.preferEpilogueVectorization();
3097 }
3098
3099 bool shouldExpandReduction(const IntrinsicInst *II) const override {
3100 return Impl.shouldExpandReduction(II);
3101 }
3102
3104 getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const override {
3105 return Impl.getPreferredExpandedReductionShuffle(II);
3106 }
3107
3108 unsigned getGISelRematGlobalCost() const override {
3109 return Impl.getGISelRematGlobalCost();
3110 }
3111
3112 unsigned getMinTripCountTailFoldingThreshold() const override {
3113 return Impl.getMinTripCountTailFoldingThreshold();
3114 }
3115
3116 bool supportsScalableVectors() const override {
3117 return Impl.supportsScalableVectors();
3118 }
3119
3120 bool enableScalableVectorization() const override {
3121 return Impl.enableScalableVectorization();
3122 }
3123
3124 bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
3125 Align Alignment) const override {
3126 return Impl.hasActiveVectorLength(Opcode, DataType, Alignment);
3127 }
3128
3129 bool isProfitableToSinkOperands(Instruction *I,
3130 SmallVectorImpl<Use *> &Ops) const override {
3131 return Impl.isProfitableToSinkOperands(I, Ops);
3132 };
3133
3134 bool isVectorShiftByScalarCheap(Type *Ty) const override {
3135 return Impl.isVectorShiftByScalarCheap(Ty);
3136 }
3137
3139 getVPLegalizationStrategy(const VPIntrinsic &PI) const override {
3140 return Impl.getVPLegalizationStrategy(PI);
3141 }
3142
3143 bool hasArmWideBranch(bool Thumb) const override {
3144 return Impl.hasArmWideBranch(Thumb);
3145 }
3146
3147 unsigned getMaxNumArgs() const override {
3148 return Impl.getMaxNumArgs();
3149 }
3150
3151 unsigned getNumBytesToPadGlobalArray(unsigned Size,
3152 Type *ArrayType) const override {
3153 return Impl.getNumBytesToPadGlobalArray(Size, ArrayType);
3154 }
3155};
3156
3157template <typename T>
3159 : TTIImpl(new Model<T>(Impl)) {}
3160
3161/// Analysis pass providing the \c TargetTransformInfo.
3162///
3163/// The core idea of the TargetIRAnalysis is to expose an interface through
3164/// which LLVM targets can analyze and provide information about the middle
3165/// end's target-independent IR. This supports use cases such as target-aware
3166/// cost modeling of IR constructs.
3167///
3168/// This is a function analysis because much of the cost modeling for targets
3169/// is done in a subtarget specific way and LLVM supports compiling different
3170/// functions targeting different subtargets in order to support runtime
3171/// dispatch according to the observed subtarget.
3172class TargetIRAnalysis : public AnalysisInfoMixin<TargetIRAnalysis> {
3173public:
3175
3176 /// Default construct a target IR analysis.
3177 ///
3178 /// This will use the module's datalayout to construct a baseline
3179 /// conservative TTI result.
3181
3182 /// Construct an IR analysis pass around a target-provide callback.
3183 ///
3184 /// The callback will be called with a particular function for which the TTI
3185 /// is needed and must return a TTI object for that function.
3186 TargetIRAnalysis(std::function<Result(const Function &)> TTICallback);
3187
3188 // Value semantics. We spell out the constructors for MSVC.
3190 : TTICallback(Arg.TTICallback) {}
3192 : TTICallback(std::move(Arg.TTICallback)) {}
3194 TTICallback = RHS.TTICallback;
3195 return *this;
3196 }
3198 TTICallback = std::move(RHS.TTICallback);
3199 return *this;
3200 }
3201
3203
3204private:
3206 static AnalysisKey Key;
3207
3208 /// The callback used to produce a result.
3209 ///
3210 /// We use a completely opaque callback so that targets can provide whatever
3211 /// mechanism they desire for constructing the TTI for a given function.
3212 ///
3213 /// FIXME: Should we really use std::function? It's relatively inefficient.
3214 /// It might be possible to arrange for even stateful callbacks to outlive
3215 /// the analysis and thus use a function_ref which would be lighter weight.
3216 /// This may also be less error prone as the callback is likely to reference
3217 /// the external TargetMachine, and that reference needs to never dangle.
3218 std::function<Result(const Function &)> TTICallback;
3219
3220 /// Helper function used as the callback in the default constructor.
3221 static Result getDefaultTTI(const Function &F);
3222};
3223
3224/// Wrapper pass for TargetTransformInfo.
3225///
3226/// This pass can be constructed from a TTI object which it stores internally
3227/// and is queried by passes.
3229 TargetIRAnalysis TIRA;
3230 std::optional<TargetTransformInfo> TTI;
3231
3232 virtual void anchor();
3233
3234public:
3235 static char ID;
3236
3237 /// We must provide a default constructor for the pass but it should
3238 /// never be used.
3239 ///
3240 /// Use the constructor below or call one of the creation routines.
3242
3244
3246};
3247
3248/// Create an analysis pass wrapper around a TTI object.
3249///
3250/// This analysis pass just holds the TTI instance and makes it available to
3251/// clients.
3253
3254} // namespace llvm
3255
3256#endif
AMDGPU Lower Kernel Arguments
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
RelocType Type
Definition: COFFYAML.cpp:410
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint32_t Index
uint64_t Size
static cl::opt< bool > ForceNestedLoop("force-nested-hardware-loop", cl::Hidden, cl::init(false), cl::desc("Force allowance of nested hardware loops"))
static cl::opt< bool > ForceHardwareLoopPHI("force-hardware-loop-phi", cl::Hidden, cl::init(false), cl::desc("Force hardware loop counter to be updated through a phi"))
This header defines various interfaces for pass management in LLVM.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
std::optional< unsigned > getMaxVScale(const Function &F, const TargetTransformInfo &TTI)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
Machine InstCombiner
uint64_t IntrinsicInst * II
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
Value * RHS
Class for arbitrary precision integers.
Definition: APInt.h:78
an instruction to allocate memory on the stack
Definition: Instructions.h:63
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Class to represent array types.
Definition: DerivedTypes.h:395
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1112
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
This is an important base class in LLVM.
Definition: Constant.h:42
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
The core instruction combiner logic.
Definition: InstCombiner.h:48
static InstructionCost getInvalid(CostType Val=0)
Class to represent integer types.
Definition: DerivedTypes.h:42
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:630
const SmallVectorImpl< Type * > & getArgTypes() const
const SmallVectorImpl< const Value * > & getArgs() const
InstructionCost getScalarizationCost() const
const IntrinsicInst * getInst() const
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:176
LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor...
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
Analysis providing profile information.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:77
This class represents an analyzed expression in the program.
The main scalar evolution driver.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:33
An instruction for storing to memory.
Definition: Instructions.h:292
Multiway switch.
Analysis pass providing the TargetTransformInfo.
TargetIRAnalysis(const TargetIRAnalysis &Arg)
TargetIRAnalysis & operator=(const TargetIRAnalysis &RHS)
Result run(const Function &F, FunctionAnalysisManager &)
TargetTransformInfo Result
TargetIRAnalysis()
Default construct a target IR analysis.
TargetIRAnalysis & operator=(TargetIRAnalysis &&RHS)
TargetIRAnalysis(TargetIRAnalysis &&Arg)
Provides information about what library functions are available for the current target.
Wrapper pass for TargetTransformInfo.
TargetTransformInfoWrapperPass()
We must provide a default constructor for the pass but it should never be used.
TargetTransformInfo & getTTI(const Function &F)
virtual bool preferFixedOverScalableIfEqualCost() const =0
virtual std::optional< Value * > simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed)=0
virtual InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr)=0
virtual TypeSize getRegisterBitWidth(RegisterKind K) const =0
virtual const DataLayout & getDataLayout() const =0
virtual InstructionCost getBranchMispredictPenalty()=0
virtual bool isProfitableLSRChainElement(Instruction *I)=0
virtual InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)=0
virtual InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty, TargetCostKind CostKind, Instruction *Inst=nullptr)=0
virtual InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind)=0
virtual void getUnrollingPreferences(Loop *L, ScalarEvolution &, UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE)=0
virtual bool isLegalNTStore(Type *DataType, Align Alignment)=0
virtual unsigned adjustInliningThreshold(const CallBase *CB)=0
virtual InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, OperandValueInfo Op1Info, OperandValueInfo Op2Info, const Instruction *I)=0
virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I)=0
virtual bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const =0
virtual bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace)=0
virtual std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II)=0
virtual bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty, ReductionFlags) const =0
virtual VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const =0
virtual bool isLegalNTLoad(Type *DataType, Align Alignment)=0
virtual bool enableOrderedReductions()=0
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit)=0
virtual unsigned getNumberOfRegisters(unsigned ClassID) const =0
virtual std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const =0
virtual bool isLegalMaskedGather(Type *DataType, Align Alignment)=0
virtual bool areTypesABICompatible(const Function *Caller, const Function *Callee, const ArrayRef< Type * > &Types) const =0
virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TargetCostKind CostKind)=0
virtual bool shouldPrefetchAddressSpace(unsigned AS) const =0
virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty)=0
virtual unsigned getMinVectorRegisterBitWidth() const =0
virtual InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const =0
virtual std::optional< unsigned > getVScaleForTuning() const =0
virtual InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TargetCostKind CostKind)=0
virtual InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind)=0
virtual bool supportsEfficientVectorElementLoadStore()=0
virtual unsigned getRegUsageForType(Type *Ty)=0
virtual bool hasArmWideBranch(bool Thumb) const =0
virtual MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const =0
virtual InstructionCost getMulAccReductionCost(bool IsUnsigned, Type *ResTy, VectorType *Ty, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput)=0
virtual InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, OperandValueInfo Opd1Info, OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CxtI=nullptr)=0
virtual unsigned getAssumedAddrSpace(const Value *V) const =0
virtual bool isTruncateFree(Type *Ty1, Type *Ty2)=0
virtual bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID)=0
virtual bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const =0
virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, TTI::TargetCostKind CostKind)=0
virtual bool shouldBuildLookupTables()=0
virtual bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const =0
virtual bool isLegalToVectorizeStore(StoreInst *SI) const =0
virtual bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType)=0
virtual bool isVectorShiftByScalarCheap(Type *Ty) const =0
virtual unsigned getGISelRematGlobalCost() const =0
virtual unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const =0
virtual InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)=0
virtual Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicElementSize) const =0
virtual bool forceScalarizeMaskedScatter(VectorType *DataType, Align Alignment)=0
virtual bool supportsTailCallFor(const CallBase *CB)=0
virtual std::optional< unsigned > getMaxVScale() const =0
virtual InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TargetCostKind CostKind)=0
virtual bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const =0
virtual unsigned getMaxNumArgs() const =0
virtual bool shouldExpandReduction(const IntrinsicInst *II) const =0
virtual bool enableWritePrefetching() const =0
virtual bool useColdCCForColdCall(Function &F)=0
virtual unsigned getInlineCallPenalty(const Function *F, const CallBase &Call, unsigned DefaultCallPenalty) const =0
virtual bool preferInLoopReduction(unsigned Opcode, Type *Ty, ReductionFlags) const =0
virtual int getInlinerVectorBonusPercent() const =0
virtual unsigned getMaxPrefetchIterationsAhead() const =0
virtual bool isLegalMaskedScatter(Type *DataType, Align Alignment)=0
virtual bool isIndexedLoadLegal(MemIndexedMode Mode, Type *Ty) const =0
virtual unsigned getCacheLineSize() const =0
virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const =0
virtual unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const =0
virtual ReductionShuffle getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const =0
virtual AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const =0
virtual bool shouldBuildLookupTablesForConstant(Constant *C)=0
virtual bool preferPredicateOverEpilogue(TailFoldingInfo *TFI)=0
virtual bool isProfitableToHoist(Instruction *I)=0
virtual InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TargetCostKind CostKind, ArrayRef< Value * > VL={})=0
virtual bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment)=0
virtual InstructionCost getFPOpCost(Type *Ty)=0
virtual unsigned getMinTripCountTailFoldingThreshold() const =0
virtual bool enableMaskedInterleavedAccessVectorization()=0
virtual unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const =0
virtual bool isTypeLegal(Type *Ty)=0
virtual BranchProbability getPredictableBranchThreshold()=0
virtual bool enableScalableVectorization() const =0
virtual bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info)=0
virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const =0
virtual const char * getRegisterClassName(unsigned ClassID) const =0
virtual unsigned getMaxInterleaveFactor(ElementCount VF)=0
virtual bool enableAggressiveInterleaving(bool LoopHasReductions)=0
virtual bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask) const =0
virtual bool haveFastSqrt(Type *Ty)=0
virtual bool isLegalMaskedCompressStore(Type *DataType, Align Alignment)=0
virtual std::optional< unsigned > getCacheSize(CacheLevel Level) const =0
virtual InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind)=0
virtual InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, TTI::TargetCostKind CostKind)=0
virtual void getPeelingPreferences(Loop *L, ScalarEvolution &SE, PeelingPreferences &PP)=0
virtual std::optional< unsigned > getCacheAssociativity(CacheLevel Level) const =0
virtual bool supportsScalableVectors() const =0
virtual void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type * > &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicCpySize) const =0
virtual bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx)=0
virtual bool forceScalarizeMaskedGather(VectorType *DataType, Align Alignment)=0
virtual unsigned getNumberOfParts(Type *Tp)=0
virtual bool isLegalICmpImmediate(int64_t Imm)=0
virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)=0
virtual InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)=0
virtual bool isElementTypeLegalForScalableVector(Type *Ty) const =0
virtual TailFoldingStyle getPreferredTailFoldingStyle(bool IVUpdateMayOverflow=true)=0
virtual bool hasDivRemOp(Type *DataType, bool IsSigned)=0
virtual unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const =0
virtual bool shouldBuildRelLookupTables()=0
virtual InstructionCost getOperandsScalarizationOverhead(ArrayRef< const Value * > Args, ArrayRef< Type * > Tys, TargetCostKind CostKind)=0
virtual bool isLoweredToCall(const Function *F)=0
virtual bool isSourceOfDivergence(const Value *V)=0
virtual bool isLegalAddScalableImmediate(int64_t Imm)=0
virtual bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const =0
virtual unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const =0
virtual bool isLegalMaskedLoad(Type *DataType, Align Alignment)=0
virtual unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const =0
virtual InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput)=0
virtual bool isFPVectorizationPotentiallyUnsafe()=0
virtual Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType)=0
virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const =0
virtual InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty)=0
virtual bool hasConditionalLoadStoreForType(Type *Ty=nullptr) const =0
virtual InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, PartialReductionExtendKind OpAExtend, PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp) const =0
virtual InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I)=0
virtual bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &OpsToSink) const =0
virtual bool hasBranchDivergence(const Function *F=nullptr)=0
virtual InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind)=0
virtual unsigned getInliningThresholdMultiplier() const =0
virtual InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind)=0
virtual bool isLegalMaskedStore(Type *DataType, Align Alignment)=0
virtual InstructionCost getVectorInstrCost(const Instruction &I, Type *Val, TTI::TargetCostKind CostKind, unsigned Index)=0
virtual bool isLegalToVectorizeLoad(LoadInst *LI) const =0
virtual bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const =0
virtual unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const =0
virtual bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx)=0
virtual bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2)=0
virtual bool shouldDropLSRSolutionIfLessProfitable() const =0
virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const =0
virtual InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false)=0
virtual bool prefersVectorizedAddressing()=0
virtual uint64_t getMaxMemIntrinsicInlineSizeThreshold() const =0
virtual InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args, const Instruction *CxtI)=0
virtual InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, OperandValueInfo OpInfo, const Instruction *I)=0
virtual bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo)=0
virtual InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind)=0
virtual bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo)=0
virtual bool isAlwaysUniform(const Value *V)=0
virtual std::optional< unsigned > getMinPageSize() const =0
virtual InstructionCost getMemcpyCost(const Instruction *I)=0
virtual ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const =0
virtual bool areInlineCompatible(const Function *Caller, const Function *Callee) const =0
virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const =0
virtual InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index)=0
virtual unsigned getEpilogueVectorizationMinVF()=0
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)=0
virtual InstructionCost getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind, const Instruction *I=nullptr)=0
virtual unsigned getFlatAddressSpace()=0
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Op0, Value *Op1)=0
virtual InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, Value *Scalar, ArrayRef< std::tuple< Value *, User *, int > > ScalarUserAndIdx)=0
virtual unsigned getPrefetchDistance() const =0
virtual bool shouldTreatInstructionLikeSelect(const Instruction *I)=0
virtual bool hasVolatileVariant(Instruction *I, unsigned AddrSpace)=0
virtual bool preferToKeepConstantsAttached(const Instruction &Inst, const Function &Fn) const =0
virtual bool isNumRegsMajorCostOfLSR()=0
virtual bool isLegalStridedLoadStore(Type *DataType, Align Alignment)=0
virtual bool isSingleThreaded() const =0
virtual bool isLegalAddImmediate(int64_t Imm)=0
virtual Value * rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const =0
virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I, int64_t ScalableOffset)=0
virtual bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader)=0
virtual unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy, Type *ScalarValTy) const =0
virtual bool isVScaleKnownToBeAPowerOfTwo() const =0
virtual InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys)=0
virtual bool hasActiveVectorLength(unsigned Opcode, Type *DataType, Align Alignment) const =0
virtual bool enableInterleavedAccessVectorization()=0
virtual bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx)=0
virtual unsigned getAtomicMemIntrinsicMaxElementSize() const =0
virtual bool preferEpilogueVectorization() const =0
virtual InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, const Instruction *I)=0
virtual int getInliningLastCallToStaticBonus() const =0
virtual unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const =0
virtual bool isIndexedStoreLegal(MemIndexedMode Mode, Type *Ty) const =0
virtual bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace, Align Alignment, unsigned *Fast)=0
virtual unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const =0
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
bool isLegalToVectorizeLoad(LoadInst *LI) const
std::optional< unsigned > getVScaleForTuning() const
static CastContextHint getCastContextHint(const Instruction *I)
Calculates a CastContextHint from I.
bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const
Return false if a AS0 address cannot possibly alias a AS1 address.
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const
Return true if the target supports masked scatter.
InstructionCost getStridedMemoryOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, const Instruction *I=nullptr) const
bool shouldBuildLookupTables() const
Return true if switches should be turned into lookup tables for the target.
bool isLegalToVectorizeStore(StoreInst *SI) const
bool enableAggressiveInterleaving(bool LoopHasReductions) const
Don't restrict interleaved unrolling to small loops.
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const
Return true if it is faster to check if a floating-point value is NaN (or not-NaN) versus a compariso...
bool preferInLoopReduction(unsigned Opcode, Type *Ty, ReductionFlags Flags) const
bool supportsEfficientVectorElementLoadStore() const
If target has efficient vector element load/store instructions, it can return true here so that inser...
bool isAlwaysUniform(const Value *V) const
unsigned getAssumedAddrSpace(const Value *V) const
bool shouldDropLSRSolutionIfLessProfitable() const
Return true if LSR should drop a found solution if it's calculated to be less profitable than the bas...
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const
Return true if LSR cost of C1 is lower than C2.
Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicElementSize=std::nullopt) const
bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const
Return true if the target supports masked expand load.
bool prefersVectorizedAddressing() const
Return true if target doesn't mind addresses in vectors.
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, OperandValueInfo Op1Info={OK_AnyValue, OP_None}, OperandValueInfo Op2Info={OK_AnyValue, OP_None}, const Instruction *I=nullptr) const
bool hasBranchDivergence(const Function *F=nullptr) const
Return true if branch divergence exists.
MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
InstructionCost getAddressComputationCost(Type *Ty, ScalarEvolution *SE=nullptr, const SCEV *Ptr=nullptr) const
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle the invalidation of this information.
void getUnrollingPreferences(Loop *L, ScalarEvolution &, UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const
Get target-customized preferences for the generic loop unrolling transformation.
bool shouldBuildLookupTablesForConstant(Constant *C) const
Return true if switches should be turned into lookup tables containing this constant value for the ta...
InstructionCost getOperandsScalarizationOverhead(ArrayRef< const Value * > Args, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind) const
Estimate the overhead of scalarizing an instructions unique non-constant operands.
bool supportsTailCallFor(const CallBase *CB) const
If target supports tail call on CB.
std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const
Targets can implement their own combinations for target-specific intrinsics.
bool isProfitableLSRChainElement(Instruction *I) const
TypeSize getRegisterBitWidth(RegisterKind K) const
unsigned getInlineCallPenalty(const Function *F, const CallBase &Call, unsigned DefaultCallPenalty) const
Returns a penalty for invoking call Call in F.
bool isExpensiveToSpeculativelyExecute(const Instruction *I) const
Return true if the cost of the instruction is too high to speculatively execute and should be kept be...
bool isLegalMaskedGather(Type *DataType, Align Alignment) const
Return true if the target supports masked gather.
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, OperandValueInfo OpdInfo={OK_AnyValue, OP_None}, const Instruction *I=nullptr) const
std::optional< unsigned > getMaxVScale() const
InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind) const
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, bool UseMaskForCond=false, bool UseMaskForGaps=false) const
std::optional< Value * > simplifyDemandedVectorEltsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts, APInt &UndefElts2, APInt &UndefElts3, std::function< void(Instruction *, unsigned, APInt, APInt &)> SimplifyAndSetOp) const
Can be used to implement target-specific instruction combining.
bool enableOrderedReductions() const
Return true if we should be enabling ordered reductions for the target.
InstructionCost getInstructionCost(const User *U, TargetCostKind CostKind) const
This is a helper function which calls the three-argument getInstructionCost with Operands which are t...
unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Calculate the cost of vector reduction intrinsics.
unsigned getAtomicMemIntrinsicMaxElementSize() const
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency, const Instruction *I=nullptr) const
bool LSRWithInstrQueries() const
Return true if the loop strength reduce pass should make Instruction* based TTI queries to isLegalAdd...
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
static PartialReductionExtendKind getPartialReductionExtendKind(Instruction *I)
Get the kind of extension that an instruction represents.
bool shouldTreatInstructionLikeSelect(const Instruction *I) const
Should the Select Optimization pass treat the given instruction like a select, potentially converting...
bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const
TailFoldingStyle getPreferredTailFoldingStyle(bool IVUpdateMayOverflow=true) const
Query the target what the preferred style of tail folding is.
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType=nullptr, TargetCostKind CostKind=TCK_SizeAndLatency) const
Estimate the cost of a GEP operation when lowered.
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor, Align Alignment, unsigned AddrSpace) const
Return true is the target supports interleaved access for the given vector type VTy,...
unsigned getRegUsageForType(Type *Ty) const
Returns the estimated number of registers required to represent Ty.
bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const
\Returns true if the target supports broadcasting a load to a vector of type <NumElements x ElementTy...
bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const
std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
ReductionShuffle getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Calculate the cost of an extended reduction pattern, similar to getArithmeticReductionCost of a reduc...
static OperandValueInfo getOperandInfo(const Value *V)
Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
InstructionCost getMulAccReductionCost(bool IsUnsigned, Type *ResTy, VectorType *Ty, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Calculate the cost of an extended reduction pattern, similar to getArithmeticReductionCost of an Add ...
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0, Instruction *I=nullptr, int64_t ScalableOffset=0) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
Return hardware support for population count.
unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
bool isElementTypeLegalForScalableVector(Type *Ty) const
bool forceScalarizeMaskedGather(VectorType *Type, Align Alignment) const
Return true if the target forces scalarizing of llvm.masked.gather intrinsics.
unsigned getMaxPrefetchIterationsAhead() const
bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const
Return true if globals in this address space can have initializers other than undef.
ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TargetCostKind CostKind) const
bool enableMaskedInterleavedAccessVectorization() const
Enable matching of interleaved access groups that contain predicated accesses or gaps and therefore v...
InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty, TargetCostKind CostKind, Instruction *Inst=nullptr) const
Return the expected cost of materialization for the given integer immediate of the specified type for...
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const
Return true if the target supports strided load.
TargetTransformInfo & operator=(TargetTransformInfo &&RHS)
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF=FastMathFlags(), TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
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.
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr) const
This is an approximation of reciprocal throughput of a math/logic op.
bool areTypesABICompatible(const Function *Caller, const Function *Callee, const ArrayRef< Type * > &Types) const
bool enableSelectOptimize() const
Should the Select Optimization pass be enabled and ran.
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
Return any intrinsic address operand indexes which may be rewritten if they use a flat address space ...
OperandValueProperties
Additional properties of an operand's values.
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const PointersChainInfo &Info, Type *AccessTy, TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Estimate the cost of a chain of pointers (typically pointer operands of a chain of loads or stores wi...
bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const
bool isSourceOfDivergence(const Value *V) const
Returns whether V is a source of divergence.
bool isLegalICmpImmediate(int64_t Imm) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
bool isTypeLegal(Type *Ty) const
Return true if this type is legal.
static bool requiresOrderedReduction(std::optional< FastMathFlags > FMF)
A helper function to determine the type of reduction algorithm used for a given Opcode and set of Fas...
bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const
std::optional< unsigned > getCacheAssociativity(CacheLevel Level) const
bool isLegalNTLoad(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal load.
InstructionCost getMemcpyCost(const Instruction *I) const
unsigned adjustInliningThreshold(const CallBase *CB) const
bool isLegalAddImmediate(int64_t Imm) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
bool isTargetIntrinsicWithStructReturnOverloadAtField(Intrinsic::ID ID, int RetIdx) const
Identifies if the vector form of the intrinsic that returns a struct is overloaded at the struct elem...
InstructionCost getVPMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, const Instruction *I=nullptr) const
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const
Return true if the target can save a compare for loop count, for example hardware loop saves a compar...
bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) const
Value * rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
Rewrite intrinsic call II such that OldV will be replaced with NewV, which has a different address sp...
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const
Some HW prefetchers can handle accesses up to a certain constant stride.
bool preferPredicatedReductionSelect(unsigned Opcode, Type *Ty, ReductionFlags Flags) const
InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef< int > Mask={}, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, int Index=0, VectorType *SubTp=nullptr, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const
bool shouldPrefetchAddressSpace(unsigned AS) const
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TargetCostKind CostKind) const
Return the expected cost of materializing for the given integer immediate of the specified type.
unsigned getMinVectorRegisterBitWidth() const
bool isLegalNTStore(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal store.
unsigned getFlatAddressSpace() const
Returns the address space ID for a target's 'flat' address space.
bool preferToKeepConstantsAttached(const Instruction &Inst, const Function &Fn) const
It can be advantageous to detach complex constants from their uses to make their generation cheaper.
bool hasArmWideBranch(bool Thumb) const
const char * getRegisterClassName(unsigned ClassID) const
bool preferEpilogueVectorization() const
Return true if the loop vectorizer should consider vectorizing an otherwise scalar epilogue loop.
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const
BranchProbability getPredictableBranchThreshold() const
If a branch or a select condition is skewed in one direction by more than this factor,...
unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth, unsigned AddressSpace=0, Align Alignment=Align(1), unsigned *Fast=nullptr) const
Determine if the target supports unaligned memory accesses.
InstructionCost getGatherScatterOpCost(unsigned Opcode, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, const Instruction *I=nullptr) const
bool hasActiveVectorLength(unsigned Opcode, Type *DataType, Align Alignment) const
unsigned getEpilogueVectorizationMinVF() const
PopcntSupportKind
Flags indicating the kind of support for population count.
InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) const
Return the expected cost for the given integer when optimising for size.
AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const
Return the preferred addressing mode LSR should make efforts to generate.
bool isLoweredToCall(const Function *F) const
Test whether calls to a function lower to actual program function calls.
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const
Query the target whether it would be profitable to convert the given loop into a hardware loop.
unsigned getInliningThresholdMultiplier() const
InstructionCost getBranchMispredictPenalty() const
Returns estimated penalty of a branch misprediction in latency.
unsigned getNumberOfRegisters(unsigned ClassID) const
bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask) const
Return true if this is an alternating opcode pattern that can be lowered to a single instruction on t...
bool isProfitableToHoist(Instruction *I) const
Return true if it is profitable to hoist instruction in the then/else to before if.
bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const
Return true if the given instruction (assumed to be a memory access instruction) has a volatile varia...
bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const
Return true if the target supports masked compress store.
std::optional< unsigned > getMinPageSize() const
bool isFPVectorizationPotentiallyUnsafe() const
Indicate that it is potentially unsafe to automatically vectorize floating-point operations because t...
bool isLegalMaskedStore(Type *DataType, Align Alignment) const
Return true if the target supports masked store.
bool shouldBuildRelLookupTables() const
Return true if lookup tables should be turned into relative lookup tables.
unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy, Type *ScalarValTy) const
std::optional< unsigned > getCacheSize(CacheLevel Level) const
std::optional< Value * > simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed) const
Can be used to implement target-specific instruction combining.
bool isLegalAddScalableImmediate(int64_t Imm) const
Return true if adding the specified scalable immediate is legal, that is the target has add instructi...
bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx) const
Identifies if the vector form of the intrinsic has a scalar operand.
bool hasDivRemOp(Type *DataType, bool IsSigned) const
Return true if the target has a unified operation to calculate division and remainder.
InstructionCost getAltInstrCost(VectorType *VecTy, unsigned Opcode0, unsigned Opcode1, const SmallBitVector &OpcodeMask, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Returns the cost estimation for alternating opcode pattern that can be lowered to a single instructio...
TargetCostConstants
Underlying constants for 'cost' values in this interface.
@ 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.
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, ArrayRef< Value * > VL={}) const
Estimate the overhead of scalarizing an instruction.
bool enableInterleavedAccessVectorization() const
Enable matching of interleaved access groups.
unsigned getMinTripCountTailFoldingThreshold() const
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TargetCostKind CostKind) const
Estimate the cost of a given IR user when lowered.
unsigned getMaxInterleaveFactor(ElementCount VF) const
bool isVectorShiftByScalarCheap(Type *Ty) const
Return true if it's significantly cheaper to shift a vector by a uniform scalar than by an amount whi...
bool isNumRegsMajorCostOfLSR() const
Return true if LSR major cost is number of registers.
unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const
bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const
InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index) const
unsigned getGISelRematGlobalCost() const
unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const
MemIndexedMode
The type of load/store indexing.
@ MIM_PostInc
Post-incrementing.
@ MIM_PostDec
Post-decrementing.
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
bool useColdCCForColdCall(Function &F) const
Return true if the input function which is cold at all call sites, should use coldcc calling conventi...
InstructionCost getFPOpCost(Type *Ty) const
Return the expected cost of supporting the floating point operation of the specified type.
bool supportsTailCalls() const
If the target supports tail calls.
bool canMacroFuseCmp() const
Return true if the target can fuse a compare and branch.
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType) const
bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
Query the target whether the specified address space cast from FromAS to ToAS is valid.
unsigned getNumberOfParts(Type *Tp) const
bool hasConditionalLoadStoreForType(Type *Ty=nullptr) const
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, PartialReductionExtendKind OpAExtend, PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp=std::nullopt) const
InstructionCost getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, StackOffset BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0) const
Return the cost of the scaling factor used in the addressing mode represented by AM for this target,...
bool isTruncateFree(Type *Ty1, Type *Ty2) const
Return true if it's free to truncate a value of type Ty1 to type Ty2.
bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const
Return true if sinking I's operands to the same basic block as I is profitable, e....
void getMemcpyLoopResidualLoweringType(SmallVectorImpl< Type * > &OpsOut, LLVMContext &Context, unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicCpySize=std::nullopt) const
bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const
Query the target whether it would be prefered to create a predicated vector loop, which can avoid the...
bool forceScalarizeMaskedScatter(VectorType *Type, Align Alignment) const
Return true if the target forces scalarizing of llvm.masked.scatter intrinsics.
bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx) const
Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...
bool haveFastSqrt(Type *Ty) const
Return true if the hardware has a fast square-root instruction.
bool shouldExpandReduction(const IntrinsicInst *II) const
TargetTransformInfo(T Impl)
Construct a TTI object using a type implementing the Concept API below.
uint64_t getMaxMemIntrinsicInlineSizeThreshold() const
Returns the maximum memset / memcpy size in bytes that still makes it profitable to inline the call.
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index=-1, Value *Op0=nullptr, Value *Op1=nullptr) const
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.
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, PeelingPreferences &PP) const
Get target-customized preferences for the generic loop peeling transformation.
InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency) const
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency, const Instruction *I=nullptr) const
CastContextHint
Represents a hint about the context in which a cast is used.
@ Reversed
The cast is used with a reversed load/store.
@ Masked
The cast is used with a masked load/store.
@ None
The cast is not used with a load/store of any kind.
@ Normal
The cast is used with a normal load/store.
@ Interleave
The cast is used with an interleaved load/store.
@ GatherScatter
The cast is used with a gather/scatter.
OperandValueKind
Additional information about an operand's possible values.
CacheLevel
The possible cache levels.
bool isLegalMaskedLoad(Type *DataType, Align Alignment) const
Return true if the target supports masked load.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
Definition: Value.h:74
Base class of all SIMD vector types.
Definition: DerivedTypes.h:427
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool areInlineCompatible(const Function &Caller, const Function &Callee)
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:480
@ None
Definition: CodeGenData.h:106
AtomicOrdering
Atomic ordering for LLVM's memory model.
TargetTransformInfo TTI
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:217
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
@ DataAndControlFlowWithoutRuntimeCheck
Use predicate to control both data and control flow, but modify the trip count so that a runtime over...
@ DataWithEVL
Use predicated EVL instructions for tail-folding.
@ DataAndControlFlow
Use predicate to control both data and control flow.
@ DataWithoutLaneMask
Same as Data, but avoids using the get.active.lane.mask intrinsic to calculate the mask and instead i...
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
Attributes of a target dependent hardware loop.
bool canAnalyze(LoopInfo &LI)
bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
Information about a load/store intrinsic defined by the target.
Value * PtrVal
This is the pointer that the intrinsic is loading from or storing to.
InterleavedAccessInfo * IAI
TailFoldingInfo(TargetLibraryInfo *TLI, LoopVectorizationLegality *LVL, InterleavedAccessInfo *IAI)
TargetLibraryInfo * TLI
LoopVectorizationLegality * LVL
unsigned Insns
TODO: Some of these could be merged.
Returns options for expansion of memcmp. IsZeroCmp is.
bool AllowPeeling
Allow peeling off loop iterations.
bool AllowLoopNestsPeeling
Allow peeling off loop iterations for loop nests.
bool PeelProfiledIterations
Allow peeling basing on profile.
unsigned PeelCount
A forced peeling factor (the number of bodied of the original loop that should be peeled off before t...
Describe known properties for a set of pointers.
unsigned IsKnownStride
True if distance between any two neigbouring pointers is a known value.
unsigned IsUnitStride
These properties only valid if SameBaseAddress is set.
unsigned IsSameBaseAddress
All the GEPs in a set have same base address.
Flags describing the kind of vector reduction.
bool IsSigned
Whether the operation is a signed int reduction.
bool IsMaxOp
If the op a min/max kind, true if it's a max operation.
bool NoNaN
If op is an fp min/max, whether NaNs may be present.
Parameters that control the generic loop unrolling transformation.
unsigned Count
A forced unrolling factor (the number of concatenated bodies of the original loop in the unrolled loo...
bool UpperBound
Allow using trip count upper bound to unroll loops.
unsigned Threshold
The cost threshold for the unrolled loop.
bool Force
Apply loop unroll on any kind of loop (mainly to loops that fail runtime unrolling).
unsigned PartialOptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size, like OptSizeThreshold,...
bool UnrollVectorizedLoop
Don't disable runtime unroll for the loops which were vectorized.
unsigned DefaultUnrollRuntimeCount
Default unroll count for loops with run-time trip count.
unsigned MaxPercentThresholdBoost
If complete unrolling will reduce the cost of the loop, we will boost the Threshold by a certain perc...
unsigned SCEVExpansionBudget
Don't allow runtime unrolling if expanding the trip count takes more than SCEVExpansionBudget.
unsigned UnrollAndJamInnerLoopThreshold
Threshold for unroll and jam, for inner loop size.
unsigned MaxIterationsCountToAnalyze
Don't allow loop unrolling to simulate more than this number of iterations when checking full unroll ...
bool AllowRemainder
Allow generation of a loop remainder (extra iterations after unroll).
bool UnrollAndJam
Allow unroll and jam. Used to enable unroll and jam for the target.
bool UnrollRemainder
Allow unrolling of all the iterations of the runtime loop remainder.
unsigned FullUnrollMaxCount
Set the maximum unrolling factor for full unrolling.
unsigned PartialThreshold
The cost threshold for the unrolled loop, like Threshold, but used for partial/runtime unrolling (set...
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...
bool Partial
Allow partial unrolling (unrolling of loops to expand the size of the loop body, not only to eliminat...
unsigned OptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size (set to UINT_MAX to disable).
bool AllowExpensiveTripCount
Allow emitting expensive instructions (such as divisions) when computing the trip count of a loop for...
unsigned MaxUpperBound
Set the maximum upper bound of trip count.
VPLegalization(VPTransform EVLParamStrategy, VPTransform OpStrategy)