LLVM 23.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"
27#include "llvm/ADT/Uniformity.h"
30#include "llvm/IR/FMF.h"
31#include "llvm/IR/InstrTypes.h"
32#include "llvm/IR/PassManager.h"
33#include "llvm/Pass.h"
38#include <functional>
39#include <optional>
40#include <utility>
41
42namespace llvm {
43
44namespace Intrinsic {
45typedef unsigned ID;
46}
47
48class AllocaInst;
49class AssumptionCache;
51class DominatorTree;
52class BranchInst;
53class Function;
54class GlobalValue;
55class InstCombiner;
58class IntrinsicInst;
59class LoadInst;
60class Loop;
61class LoopInfo;
65class SCEV;
66class ScalarEvolution;
67class SmallBitVector;
68class StoreInst;
69class SwitchInst;
71class Type;
72class VPIntrinsic;
73struct KnownBits;
74
75/// Information about a load/store intrinsic defined by the target.
77 /// This is the pointer that the intrinsic is loading from or storing to.
78 /// If this is non-null, then analysis/optimization passes can assume that
79 /// this intrinsic is functionally equivalent to a load/store from this
80 /// pointer.
81 Value *PtrVal = nullptr;
82
83 // Ordering for atomic operations.
85
86 // Same Id is set by the target for corresponding load/store intrinsics.
87 unsigned short MatchingId = 0;
88
89 bool ReadMem = false;
90 bool WriteMem = false;
91 bool IsVolatile = false;
92
94
100};
101
102/// Attributes of a target dependent hardware loop.
106 Loop *L = nullptr;
109 const SCEV *ExitCount = nullptr;
111 Value *LoopDecrement = nullptr; // Decrement the loop counter by this
112 // value in every iteration.
113 bool IsNestingLegal = false; // Can a hardware loop be a parent to
114 // another hardware loop?
115 bool CounterInReg = false; // Should loop counter be updated in
116 // the loop via a phi?
117 bool PerformEntryTest = false; // Generate the intrinsic which also performs
118 // icmp ne zero on the loop counter value and
119 // produces an i1 to guard the loop entry.
121 DominatorTree &DT,
122 bool ForceNestedLoop = false,
123 bool ForceHardwareLoopPHI = false);
124 LLVM_ABI bool canAnalyze(LoopInfo &LI);
125};
126
127/// Information for memory intrinsic cost model.
129 /// Optional context instruction, if one exists, e.g. the
130 /// load/store to transform to the intrinsic.
131 const Instruction *I = nullptr;
132
133 /// Address in memory.
134 const Value *Ptr = nullptr;
135
136 /// Vector type of the data to be loaded or stored.
137 Type *DataTy = nullptr;
138
139 /// ID of the memory intrinsic.
140 Intrinsic::ID IID;
141
142 /// True when the memory access is predicated with a mask
143 /// that is not a compile-time constant.
144 bool VariableMask = true;
145
146 /// Address space of the pointer.
147 unsigned AddressSpace = 0;
148
149 /// Alignment of single element.
150 Align Alignment;
151
152public:
154 const Value *Ptr, bool VariableMask,
155 Align Alignment,
156 const Instruction *I = nullptr)
157 : I(I), Ptr(Ptr), DataTy(DataTy), IID(Id), VariableMask(VariableMask),
158 Alignment(Alignment) {}
159
161 Align Alignment,
162 unsigned AddressSpace = 0)
163 : DataTy(DataTy), IID(Id), AddressSpace(AddressSpace),
164 Alignment(Alignment) {}
165
167 bool VariableMask, Align Alignment,
168 const Instruction *I = nullptr)
169 : I(I), DataTy(DataTy), IID(Id), VariableMask(VariableMask),
170 Alignment(Alignment) {}
171
172 Intrinsic::ID getID() const { return IID; }
173 const Instruction *getInst() const { return I; }
174 const Value *getPointer() const { return Ptr; }
175 Type *getDataType() const { return DataTy; }
176 bool getVariableMask() const { return VariableMask; }
177 unsigned getAddressSpace() const { return AddressSpace; }
178 Align getAlignment() const { return Alignment; }
179};
180
182 const IntrinsicInst *II = nullptr;
183 Type *RetTy = nullptr;
184 Intrinsic::ID IID;
185 SmallVector<Type *, 4> ParamTys;
187 FastMathFlags FMF;
188 // If ScalarizationCost is UINT_MAX, the cost of scalarizing the
189 // arguments and the return value will be computed based on types.
190 InstructionCost ScalarizationCost = InstructionCost::getInvalid();
191
192public:
194 Intrinsic::ID Id, const CallBase &CI,
196 bool TypeBasedOnly = false);
197
199 Intrinsic::ID Id, Type *RTy, ArrayRef<Type *> Tys,
200 FastMathFlags Flags = FastMathFlags(), const IntrinsicInst *I = nullptr,
202
205
209 const IntrinsicInst *I = nullptr,
211
212 Intrinsic::ID getID() const { return IID; }
213 const IntrinsicInst *getInst() const { return II; }
214 Type *getReturnType() const { return RetTy; }
215 FastMathFlags getFlags() const { return FMF; }
216 InstructionCost getScalarizationCost() const { return ScalarizationCost; }
217 const SmallVectorImpl<const Value *> &getArgs() const { return Arguments; }
218 const SmallVectorImpl<Type *> &getArgTypes() const { return ParamTys; }
219
220 bool isTypeBasedOnly() const {
221 return Arguments.empty();
222 }
223
224 bool skipScalarizationCost() const { return ScalarizationCost.isValid(); }
225};
226
228 /// Don't use tail folding
230 /// Use predicate only to mask operations on data in the loop.
231 /// When the VL is not known to be a power-of-2, this method requires a
232 /// runtime overflow check for the i + VL in the loop because it compares the
233 /// scalar induction variable against the tripcount rounded up by VL which may
234 /// overflow. When the VL is a power-of-2, both the increment and uprounded
235 /// tripcount will overflow to 0, which does not require a runtime check
236 /// since the loop is exited when the loop induction variable equals the
237 /// uprounded trip-count, which are both 0.
239 /// Same as Data, but avoids using the get.active.lane.mask intrinsic to
240 /// calculate the mask and instead implements this with a
241 /// splat/stepvector/cmp.
242 /// FIXME: Can this kind be removed now that SelectionDAGBuilder expands the
243 /// active.lane.mask intrinsic when it is not natively supported?
245 /// Use predicate to control both data and control flow.
246 /// This method always requires a runtime overflow check for the i + VL
247 /// increment inside the loop, because it uses the result direclty in the
248 /// active.lane.mask to calculate the mask for the next iteration. If the
249 /// increment overflows, the mask is no longer correct.
251 /// Use predicated EVL instructions for tail-folding.
252 /// Indicates that VP intrinsics should be used.
254};
255
264
265class TargetTransformInfo;
268
269/// This pass provides access to the codegen interfaces that are needed
270/// for IR-level transformations.
272public:
279
280 /// Get the kind of extension that an instruction represents.
283 /// Get the kind of extension that a cast opcode represents.
286
287 /// Construct a TTI object using a type implementing the \c Concept
288 /// API below.
289 ///
290 /// This is used by targets to construct a TTI wrapping their target-specific
291 /// implementation that encodes appropriate costs for their target.
293 std::unique_ptr<const TargetTransformInfoImplBase> Impl);
294
295 /// Construct a baseline TTI object using a minimal implementation of
296 /// the \c Concept API below.
297 ///
298 /// The TTI implementation will reflect the information in the DataLayout
299 /// provided if non-null.
300 LLVM_ABI explicit TargetTransformInfo(const DataLayout &DL);
301
302 // Provide move semantics.
305
306 // We need to define the destructor out-of-line to define our sub-classes
307 // out-of-line.
309
310 /// Handle the invalidation of this information.
311 ///
312 /// When used as a result of \c TargetIRAnalysis this method will be called
313 /// when the function this was computed for changes. When it returns false,
314 /// the information is preserved across those changes.
316 FunctionAnalysisManager::Invalidator &) {
317 // FIXME: We should probably in some way ensure that the subtarget
318 // information for a function hasn't changed.
319 return false;
320 }
321
322 /// \name Generic Target Information
323 /// @{
324
325 /// The kind of cost model.
326 ///
327 /// There are several different cost models that can be customized by the
328 /// target. The normalization of each cost model may be target specific.
329 /// e.g. TCK_SizeAndLatency should be comparable to target thresholds such as
330 /// those derived from MCSchedModel::LoopMicroOpBufferSize etc.
332 TCK_RecipThroughput, ///< Reciprocal throughput.
333 TCK_Latency, ///< The latency of instruction.
334 TCK_CodeSize, ///< Instruction code size.
335 TCK_SizeAndLatency ///< The weighted sum of size and latency.
336 };
337
338 /// Underlying constants for 'cost' values in this interface.
339 ///
340 /// Many APIs in this interface return a cost. This enum defines the
341 /// fundamental values that should be used to interpret (and produce) those
342 /// costs. The costs are returned as an int rather than a member of this
343 /// enumeration because it is expected that the cost of one IR instruction
344 /// may have a multiplicative factor to it or otherwise won't fit directly
345 /// into the enum. Moreover, it is common to sum or average costs which works
346 /// better as simple integral values. Thus this enum only provides constants.
347 /// Also note that the returned costs are signed integers to make it natural
348 /// to add, subtract, and test with zero (a common boundary condition). It is
349 /// not expected that 2^32 is a realistic cost to be modeling at any point.
350 ///
351 /// Note that these costs should usually reflect the intersection of code-size
352 /// cost and execution cost. A free instruction is typically one that folds
353 /// into another instruction. For example, reg-to-reg moves can often be
354 /// skipped by renaming the registers in the CPU, but they still are encoded
355 /// and thus wouldn't be considered 'free' here.
357 TCC_Free = 0, ///< Expected to fold away in lowering.
358 TCC_Basic = 1, ///< The cost of a typical 'add' instruction.
359 TCC_Expensive = 4 ///< The cost of a 'div' instruction on x86.
360 };
361
362 /// Estimate the cost of a GEP operation when lowered.
363 ///
364 /// \p PointeeType is the source element type of the GEP.
365 /// \p Ptr is the base pointer operand.
366 /// \p Operands is the list of indices following the base pointer.
367 ///
368 /// \p AccessType is a hint as to what type of memory might be accessed by
369 /// users of the GEP. getGEPCost will use it to determine if the GEP can be
370 /// folded into the addressing mode of a load/store. If AccessType is null,
371 /// then the resulting target type based off of PointeeType will be used as an
372 /// approximation.
374 getGEPCost(Type *PointeeType, const Value *Ptr,
375 ArrayRef<const Value *> Operands, Type *AccessType = nullptr,
376 TargetCostKind CostKind = TCK_SizeAndLatency) const;
377
378 /// Describe known properties for a set of pointers.
380 /// All the GEPs in a set have same base address.
381 unsigned IsSameBaseAddress : 1;
382 /// These properties only valid if SameBaseAddress is set.
383 /// True if all pointers are separated by a unit stride.
384 unsigned IsUnitStride : 1;
385 /// True if distance between any two neigbouring pointers is a known value.
386 unsigned IsKnownStride : 1;
387 unsigned Reserved : 29;
388
389 bool isSameBase() const { return IsSameBaseAddress; }
390 bool isUnitStride() const { return IsSameBaseAddress && IsUnitStride; }
392
394 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/1,
395 /*IsKnownStride=*/1, 0};
396 }
398 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/0,
399 /*IsKnownStride=*/1, 0};
400 }
402 return {/*IsSameBaseAddress=*/1, /*IsUnitStride=*/0,
403 /*IsKnownStride=*/0, 0};
404 }
405 };
406 static_assert(sizeof(PointersChainInfo) == 4, "Was size increase justified?");
407
408 /// Estimate the cost of a chain of pointers (typically pointer operands of a
409 /// chain of loads or stores within same block) operations set when lowered.
410 /// \p AccessTy is the type of the loads/stores that will ultimately use the
411 /// \p Ptrs.
414 const PointersChainInfo &Info, Type *AccessTy,
415 TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
416
417 /// \returns A value by which our inlining threshold should be multiplied.
418 /// This is primarily used to bump up the inlining threshold wholesale on
419 /// targets where calls are unusually expensive.
420 ///
421 /// TODO: This is a rather blunt instrument. Perhaps altering the costs of
422 /// individual classes of instructions would be better.
424
427
428 /// \returns The bonus of inlining the last call to a static function.
430
431 /// \returns A value to be added to the inlining threshold.
432 LLVM_ABI unsigned adjustInliningThreshold(const CallBase *CB) const;
433
434 /// \returns The cost of having an Alloca in the caller if not inlined, to be
435 /// added to the threshold
436 LLVM_ABI unsigned getCallerAllocaCost(const CallBase *CB,
437 const AllocaInst *AI) const;
438
439 /// \returns Vector bonus in percent.
440 ///
441 /// Vector bonuses: We want to more aggressively inline vector-dense kernels
442 /// and apply this bonus based on the percentage of vector instructions. A
443 /// bonus is applied if the vector instructions exceed 50% and half that
444 /// amount is applied if it exceeds 10%. Note that these bonuses are some what
445 /// arbitrary and evolved over time by accident as much as because they are
446 /// principled bonuses.
447 /// FIXME: It would be nice to base the bonus values on something more
448 /// scientific. A target may has no bonus on vector instructions.
450
451 /// \return the expected cost of a memcpy, which could e.g. depend on the
452 /// source/destination type and alignment and the number of bytes copied.
454
455 /// Returns the maximum memset / memcpy size in bytes that still makes it
456 /// profitable to inline the call.
458
459 /// \return The estimated number of case clusters when lowering \p 'SI'.
460 /// \p JTSize Set a jump table size only when \p SI is suitable for a jump
461 /// table.
462 LLVM_ABI unsigned
463 getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize,
465 BlockFrequencyInfo *BFI) const;
466
467 /// Estimate the cost of a given IR user when lowered.
468 ///
469 /// This can estimate the cost of either a ConstantExpr or Instruction when
470 /// lowered.
471 ///
472 /// \p Operands is a list of operands which can be a result of transformations
473 /// of the current operands. The number of the operands on the list must equal
474 /// to the number of the current operands the IR user has. Their order on the
475 /// list must be the same as the order of the current operands the IR user
476 /// has.
477 ///
478 /// The returned cost is defined in terms of \c TargetCostConstants, see its
479 /// comments for a detailed explanation of the cost values.
482 TargetCostKind CostKind) const;
483
484 /// This is a helper function which calls the three-argument
485 /// getInstructionCost with \p Operands which are the current operands U has.
487 TargetCostKind CostKind) const {
488 SmallVector<const Value *, 4> Operands(U->operand_values());
489 return getInstructionCost(U, Operands, CostKind);
490 }
491
492 /// If a branch or a select condition is skewed in one direction by more than
493 /// this factor, it is very likely to be predicted correctly.
495
496 /// Returns estimated penalty of a branch misprediction in latency. Indicates
497 /// how aggressive the target wants for eliminating unpredictable branches. A
498 /// zero return value means extra optimization applied to them should be
499 /// minimal.
501
502 /// Return true if branch divergence exists.
503 ///
504 /// Branch divergence has a significantly negative impact on GPU performance
505 /// when threads in the same wavefront take different paths due to conditional
506 /// branches.
507 ///
508 /// If \p F is passed, provides a context function. If \p F is known to only
509 /// execute in a single threaded environment, the target may choose to skip
510 /// uniformity analysis and assume all values are uniform.
511 LLVM_ABI bool hasBranchDivergence(const Function *F = nullptr) const;
512
513 /// Get target-specific uniformity information for an instruction.
514 /// This allows targets to provide more fine-grained control over
515 /// uniformity analysis by specifying whether specific instructions
516 /// should always or never be considered uniform, or require custom
517 /// operand-based analysis.
518 /// \param V The value to query for uniformity information.
519 /// \return InstructionUniformity.
521
522 /// Query the target whether the specified address space cast from FromAS to
523 /// ToAS is valid.
524 LLVM_ABI bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
525
526 /// Return false if a \p AS0 address cannot possibly alias a \p AS1 address.
527 LLVM_ABI bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
528
529 /// Returns the address space ID for a target's 'flat' address space. Note
530 /// this is not necessarily the same as addrspace(0), which LLVM sometimes
531 /// refers to as the generic address space. The flat address space is a
532 /// generic address space that can be used access multiple segments of memory
533 /// with different address spaces. Access of a memory location through a
534 /// pointer with this address space is expected to be legal but slower
535 /// compared to the same memory location accessed through a pointer with a
536 /// different address space.
537 //
538 /// This is for targets with different pointer representations which can
539 /// be converted with the addrspacecast instruction. If a pointer is converted
540 /// to this address space, optimizations should attempt to replace the access
541 /// with the source address space.
542 ///
543 /// \returns ~0u if the target does not have such a flat address space to
544 /// optimize away.
545 LLVM_ABI unsigned getFlatAddressSpace() const;
546
547 /// Return any intrinsic address operand indexes which may be rewritten if
548 /// they use a flat address space pointer.
549 ///
550 /// \returns true if the intrinsic was handled.
552 Intrinsic::ID IID) const;
553
554 LLVM_ABI bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
555
556 // Given an address space cast of the given pointer value, calculate the known
557 // bits of the source pointer in the source addrspace and the destination
558 // pointer in the destination addrspace.
559 LLVM_ABI std::pair<KnownBits, KnownBits>
560 computeKnownBitsAddrSpaceCast(unsigned ToAS, const Value &PtrOp) const;
561
562 // Given an address space cast, calculate the known bits of the resulting ptr
563 // in the destination addrspace using the known bits of the source pointer in
564 // the source addrspace.
566 unsigned FromAS, unsigned ToAS, const KnownBits &FromPtrBits) const;
567
568 /// Return the preserved ptr bit mask that is safe to cast integer to pointer
569 /// with new address space. The returned APInt size is identical to the source
570 /// address space size. The address of integer form may only change in the
571 /// least significant bit (e.g. within a page). In that case target can
572 /// determine if it is safe to cast the generic address space to the original
573 /// address space. For below example, we can replace `%gp2 = inttoptr i64 %b
574 /// to ptr` with `%gp2 = inttoptr i64 %b to ptr addrspace(2)`
575 /// %gp = addrspacecast ptr addrspace(2) %sp to ptr
576 /// %a = ptrtoint ptr %gp to i64
577 /// %b = xor i64 7, %a
578 /// %gp2 = inttoptr i64 %b to ptr
579 /// store i16 0, ptr %gp2, align 2
581 unsigned DstAS) const;
582
583 /// Return true if globals in this address space can have initializers other
584 /// than `undef`.
585 LLVM_ABI bool
587
588 LLVM_ABI unsigned getAssumedAddrSpace(const Value *V) const;
589
590 LLVM_ABI bool isSingleThreaded() const;
591
592 LLVM_ABI std::pair<const Value *, unsigned>
593 getPredicatedAddrSpace(const Value *V) const;
594
595 /// Rewrite intrinsic call \p II such that \p OldV will be replaced with \p
596 /// NewV, which has a different address space. This should happen for every
597 /// operand index that collectFlatAddressOperands returned for the intrinsic.
598 /// \returns nullptr if the intrinsic was not handled. Otherwise, returns the
599 /// new value (which may be the original \p II with modified operands).
601 Value *OldV,
602 Value *NewV) const;
603
604 /// Test whether calls to a function lower to actual program function
605 /// calls.
606 ///
607 /// The idea is to test whether the program is likely to require a 'call'
608 /// instruction or equivalent in order to call the given function.
609 ///
610 /// FIXME: It's not clear that this is a good or useful query API. Client's
611 /// should probably move to simpler cost metrics using the above.
612 /// Alternatively, we could split the cost interface into distinct code-size
613 /// and execution-speed costs. This would allow modelling the core of this
614 /// query more accurately as a call is a single small instruction, but
615 /// incurs significant execution cost.
616 LLVM_ABI bool isLoweredToCall(const Function *F) const;
617
618 struct LSRCost {
619 /// TODO: Some of these could be merged. Also, a lexical ordering
620 /// isn't always optimal.
621 unsigned Insns;
622 unsigned NumRegs;
623 unsigned AddRecCost;
624 unsigned NumIVMuls;
625 unsigned NumBaseAdds;
626 unsigned ImmCost;
627 unsigned SetupCost;
628 unsigned ScaleCost;
629 };
630
631 /// Parameters that control the generic loop unrolling transformation.
633 /// The cost threshold for the unrolled loop. Should be relative to the
634 /// getInstructionCost values returned by this API, and the expectation is
635 /// that the unrolled loop's instructions when run through that interface
636 /// should not exceed this cost. However, this is only an estimate. Also,
637 /// specific loops may be unrolled even with a cost above this threshold if
638 /// deemed profitable. Set this to UINT_MAX to disable the loop body cost
639 /// restriction.
640 unsigned Threshold;
641 /// If complete unrolling will reduce the cost of the loop, we will boost
642 /// the Threshold by a certain percent to allow more aggressive complete
643 /// unrolling. This value provides the maximum boost percentage that we
644 /// can apply to Threshold (The value should be no less than 100).
645 /// BoostedThreshold = Threshold * min(RolledCost / UnrolledCost,
646 /// MaxPercentThresholdBoost / 100)
647 /// E.g. if complete unrolling reduces the loop execution time by 50%
648 /// then we boost the threshold by the factor of 2x. If unrolling is not
649 /// expected to reduce the running time, then we do not increase the
650 /// threshold.
652 /// The cost threshold for the unrolled loop when optimizing for size (set
653 /// to UINT_MAX to disable).
655 /// The cost threshold for the unrolled loop, like Threshold, but used
656 /// for partial/runtime unrolling (set to UINT_MAX to disable).
658 /// The cost threshold for the unrolled loop when optimizing for size, like
659 /// OptSizeThreshold, but used for partial/runtime unrolling (set to
660 /// UINT_MAX to disable).
662 /// A forced unrolling factor (the number of concatenated bodies of the
663 /// original loop in the unrolled loop body). When set to 0, the unrolling
664 /// transformation will select an unrolling factor based on the current cost
665 /// threshold and other factors.
666 unsigned Count;
667 /// Default unroll count for loops with run-time trip count.
669 // Set the maximum unrolling factor. The unrolling factor may be selected
670 // using the appropriate cost threshold, but may not exceed this number
671 // (set to UINT_MAX to disable). This does not apply in cases where the
672 // loop is being fully unrolled.
673 unsigned MaxCount;
674 /// Set the maximum upper bound of trip count. Allowing the MaxUpperBound
675 /// to be overrided by a target gives more flexiblity on certain cases.
676 /// By default, MaxUpperBound uses UnrollMaxUpperBound which value is 8.
678 /// Set the maximum unrolling factor for full unrolling. Like MaxCount, but
679 /// applies even if full unrolling is selected. This allows a target to fall
680 /// back to Partial unrolling if full unrolling is above FullUnrollMaxCount.
682 // Represents number of instructions optimized when "back edge"
683 // becomes "fall through" in unrolled loop.
684 // For now we count a conditional branch on a backedge and a comparison
685 // feeding it.
686 unsigned BEInsns;
687 /// Allow partial unrolling (unrolling of loops to expand the size of the
688 /// loop body, not only to eliminate small constant-trip-count loops).
690 /// Allow runtime unrolling (unrolling of loops to expand the size of the
691 /// loop body even when the number of loop iterations is not known at
692 /// compile time).
694 /// Allow generation of a loop remainder (extra iterations after unroll).
696 /// Allow emitting expensive instructions (such as divisions) when computing
697 /// the trip count of a loop for runtime unrolling.
699 /// Apply loop unroll on any kind of loop
700 /// (mainly to loops that fail runtime unrolling).
701 bool Force;
702 /// Allow using trip count upper bound to unroll loops.
704 /// Allow unrolling of all the iterations of the runtime loop remainder.
706 /// Allow unroll and jam. Used to enable unroll and jam for the target.
708 /// Threshold for unroll and jam, for inner loop size. The 'Threshold'
709 /// value above is used during unroll and jam for the outer loop size.
710 /// This value is used in the same manner to limit the size of the inner
711 /// loop.
713 /// Don't allow loop unrolling to simulate more than this number of
714 /// iterations when checking full unroll profitability
716 /// Disable runtime unrolling by default for vectorized loops.
718 /// Don't allow runtime unrolling if expanding the trip count takes more
719 /// than SCEVExpansionBudget.
721 /// Allow runtime unrolling multi-exit loops. Should only be set if the
722 /// target determined that multi-exit unrolling is profitable for the loop.
723 /// Fall back to the generic logic to determine whether multi-exit unrolling
724 /// is profitable if set to false.
726 /// Allow unrolling to add parallel reduction phis.
728 };
729
730 /// Get target-customized preferences for the generic loop unrolling
731 /// transformation. The caller will initialize UP with the current
732 /// target-independent defaults.
735 OptimizationRemarkEmitter *ORE) const;
736
737 /// Query the target whether it would be profitable to convert the given loop
738 /// into a hardware loop.
740 AssumptionCache &AC,
741 TargetLibraryInfo *LibInfo,
742 HardwareLoopInfo &HWLoopInfo) const;
743
744 // Query the target for which minimum vectorization factor epilogue
745 // vectorization should be considered.
747
748 /// Query the target whether it would be prefered to create a predicated
749 /// vector loop, which can avoid the need to emit a scalar epilogue loop.
751
752 /// Query the target what the preferred style of tail folding is.
754
755 // Parameters that control the loop peeling transformation
757 /// A forced peeling factor (the number of bodied of the original loop
758 /// that should be peeled off before the loop body). When set to 0, the
759 /// a peeling factor based on profile information and other factors.
760 unsigned PeelCount;
761 /// Allow peeling off loop iterations.
763 /// Allow peeling off loop iterations for loop nests.
765 /// Allow peeling basing on profile. Uses to enable peeling off all
766 /// iterations basing on provided profile.
767 /// If the value is true the peeling cost model can decide to peel only
768 /// some iterations and in this case it will set this to false.
770
771 /// Peel off the last PeelCount loop iterations.
773 };
774
775 /// Get target-customized preferences for the generic loop peeling
776 /// transformation. The caller will initialize \p PP with the current
777 /// target-independent defaults with information from \p L and \p SE.
779 PeelingPreferences &PP) const;
780
781 /// Targets can implement their own combinations for target-specific
782 /// intrinsics. This function will be called from the InstCombine pass every
783 /// time a target-specific intrinsic is encountered.
784 ///
785 /// \returns std::nullopt to not do anything target specific or a value that
786 /// will be returned from the InstCombiner. It is possible to return null and
787 /// stop further processing of the intrinsic by returning nullptr.
788 LLVM_ABI std::optional<Instruction *>
790 /// Can be used to implement target-specific instruction combining.
791 /// \see instCombineIntrinsic
792 LLVM_ABI std::optional<Value *>
794 APInt DemandedMask, KnownBits &Known,
795 bool &KnownBitsComputed) const;
796 /// Can be used to implement target-specific instruction combining.
797 /// \see instCombineIntrinsic
798 LLVM_ABI std::optional<Value *> simplifyDemandedVectorEltsIntrinsic(
799 InstCombiner &IC, IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
800 APInt &UndefElts2, APInt &UndefElts3,
801 std::function<void(Instruction *, unsigned, APInt, APInt &)>
802 SimplifyAndSetOp) const;
803 /// @}
804
805 /// \name Scalar Target Information
806 /// @{
807
808 /// Flags indicating the kind of support for population count.
809 ///
810 /// Compared to the SW implementation, HW support is supposed to
811 /// significantly boost the performance when the population is dense, and it
812 /// may or may not degrade performance if the population is sparse. A HW
813 /// support is considered as "Fast" if it can outperform, or is on a par
814 /// with, SW implementation when the population is sparse; otherwise, it is
815 /// considered as "Slow".
817
818 /// Return true if the specified immediate is legal add immediate, that
819 /// is the target has add instructions which can add a register with the
820 /// immediate without having to materialize the immediate into a register.
821 LLVM_ABI bool isLegalAddImmediate(int64_t Imm) const;
822
823 /// Return true if adding the specified scalable immediate is legal, that is
824 /// the target has add instructions which can add a register with the
825 /// immediate (multiplied by vscale) without having to materialize the
826 /// immediate into a register.
827 LLVM_ABI bool isLegalAddScalableImmediate(int64_t Imm) const;
828
829 /// Return true if the specified immediate is legal icmp immediate,
830 /// that is the target has icmp instructions which can compare a register
831 /// against the immediate without having to materialize the immediate into a
832 /// register.
833 LLVM_ABI bool isLegalICmpImmediate(int64_t Imm) const;
834
835 /// Return true if the addressing mode represented by AM is legal for
836 /// this target, for a load/store of the specified type.
837 /// The type may be VoidTy, in which case only return true if the addressing
838 /// mode is legal for a load/store of any legal type.
839 /// If target returns true in LSRWithInstrQueries(), I may be valid.
840 /// \param ScalableOffset represents a quantity of bytes multiplied by vscale,
841 /// an invariant value known only at runtime. Most targets should not accept
842 /// a scalable offset.
843 ///
844 /// TODO: Handle pre/postinc as well.
846 int64_t BaseOffset, bool HasBaseReg,
847 int64_t Scale, unsigned AddrSpace = 0,
848 Instruction *I = nullptr,
849 int64_t ScalableOffset = 0) const;
850
851 /// Return true if LSR cost of C1 is lower than C2.
853 const TargetTransformInfo::LSRCost &C2) const;
854
855 /// Return true if LSR major cost is number of registers. Targets which
856 /// implement their own isLSRCostLess and unset number of registers as major
857 /// cost should return false, otherwise return true.
859
860 /// Return true if LSR should drop a found solution if it's calculated to be
861 /// less profitable than the baseline.
863
864 /// \returns true if LSR should not optimize a chain that includes \p I.
866
867 /// Return true if the target can fuse a compare and branch.
868 /// Loop-strength-reduction (LSR) uses that knowledge to adjust its cost
869 /// calculation for the instructions in a loop.
870 LLVM_ABI bool canMacroFuseCmp() const;
871
872 /// Return true if the target can save a compare for loop count, for example
873 /// hardware loop saves a compare.
876 TargetLibraryInfo *LibInfo) const;
877
878 /// Which addressing mode Loop Strength Reduction will try to generate.
880 AMK_None = 0x0, ///< Don't prefer any addressing mode
881 AMK_PreIndexed = 0x1, ///< Prefer pre-indexed addressing mode
882 AMK_PostIndexed = 0x2, ///< Prefer post-indexed addressing mode
883 AMK_All = 0x3, ///< Consider all addressing modes
884 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/AMK_All)
885 };
886
887 /// Return the preferred addressing mode LSR should make efforts to generate.
890
891 /// Some targets only support masked load/store with a constant mask.
896
897 /// Return true if the target supports masked store.
898 LLVM_ABI bool
899 isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace,
901 /// Return true if the target supports masked load.
902 LLVM_ABI bool
903 isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace,
905
906 /// Return true if the target supports nontemporal store.
907 LLVM_ABI bool isLegalNTStore(Type *DataType, Align Alignment) const;
908 /// Return true if the target supports nontemporal load.
909 LLVM_ABI bool isLegalNTLoad(Type *DataType, Align Alignment) const;
910
911 /// \Returns true if the target supports broadcasting a load to a vector of
912 /// type <NumElements x ElementTy>.
913 LLVM_ABI bool isLegalBroadcastLoad(Type *ElementTy,
914 ElementCount NumElements) const;
915
916 /// Return true if the target supports masked scatter.
917 LLVM_ABI bool isLegalMaskedScatter(Type *DataType, Align Alignment) const;
918 /// Return true if the target supports masked gather.
919 LLVM_ABI bool isLegalMaskedGather(Type *DataType, Align Alignment) const;
920 /// Return true if the target forces scalarizing of llvm.masked.gather
921 /// intrinsics.
923 Align Alignment) const;
924 /// Return true if the target forces scalarizing of llvm.masked.scatter
925 /// intrinsics.
927 Align Alignment) const;
928
929 /// Return true if the target supports masked compress store.
931 Align Alignment) const;
932 /// Return true if the target supports masked expand load.
933 LLVM_ABI bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const;
934
935 /// Return true if the target supports strided load.
936 LLVM_ABI bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const;
937
938 /// Return true is the target supports interleaved access for the given vector
939 /// type \p VTy, interleave factor \p Factor, alignment \p Alignment and
940 /// address space \p AddrSpace.
941 LLVM_ABI bool isLegalInterleavedAccessType(VectorType *VTy, unsigned Factor,
942 Align Alignment,
943 unsigned AddrSpace) const;
944
945 // Return true if the target supports masked vector histograms.
947 Type *DataType) const;
948
949 /// Return true if this is an alternating opcode pattern that can be lowered
950 /// to a single instruction on the target. In X86 this is for the addsub
951 /// instruction which corrsponds to a Shuffle + Fadd + FSub pattern in IR.
952 /// This function expectes two opcodes: \p Opcode1 and \p Opcode2 being
953 /// selected by \p OpcodeMask. The mask contains one bit per lane and is a `0`
954 /// when \p Opcode0 is selected and `1` when Opcode1 is selected.
955 /// \p VecTy is the vector type of the instruction to be generated.
956 LLVM_ABI bool isLegalAltInstr(VectorType *VecTy, unsigned Opcode0,
957 unsigned Opcode1,
958 const SmallBitVector &OpcodeMask) const;
959
960 /// Return true if we should be enabling ordered reductions for the target.
962
963 /// Return true if the target has a unified operation to calculate division
964 /// and remainder. If so, the additional implicit multiplication and
965 /// subtraction required to calculate a remainder from division are free. This
966 /// can enable more aggressive transformations for division and remainder than
967 /// would typically be allowed using throughput or size cost models.
968 LLVM_ABI bool hasDivRemOp(Type *DataType, bool IsSigned) const;
969
970 /// Return true if the given instruction (assumed to be a memory access
971 /// instruction) has a volatile variant. If that's the case then we can avoid
972 /// addrspacecast to generic AS for volatile loads/stores. Default
973 /// implementation returns false, which prevents address space inference for
974 /// volatile loads/stores.
975 LLVM_ABI bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const;
976
977 /// Return true if target doesn't mind addresses in vectors.
979
980 /// Return the cost of the scaling factor used in the addressing
981 /// mode represented by AM for this target, for a load/store
982 /// of the specified type.
983 /// If the AM is supported, the return value must be >= 0.
984 /// If the AM is not supported, it returns a negative value.
985 /// TODO: Handle pre/postinc as well.
987 StackOffset BaseOffset,
988 bool HasBaseReg, int64_t Scale,
989 unsigned AddrSpace = 0) const;
990
991 /// Return true if the loop strength reduce pass should make
992 /// Instruction* based TTI queries to isLegalAddressingMode(). This is
993 /// needed on SystemZ, where e.g. a memcpy can only have a 12 bit unsigned
994 /// immediate offset and no index register.
995 LLVM_ABI bool LSRWithInstrQueries() const;
996
997 /// Return true if it's free to truncate a value of type Ty1 to type
998 /// Ty2. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
999 /// by referencing its sub-register AX.
1000 LLVM_ABI bool isTruncateFree(Type *Ty1, Type *Ty2) const;
1001
1002 /// Return true if it is profitable to hoist instruction in the
1003 /// then/else to before if.
1005
1006 LLVM_ABI bool useAA() const;
1007
1008 /// Return true if this type is legal.
1009 LLVM_ABI bool isTypeLegal(Type *Ty) const;
1010
1011 /// Returns the estimated number of registers required to represent \p Ty.
1012 LLVM_ABI unsigned getRegUsageForType(Type *Ty) const;
1013
1014 /// Return true if switches should be turned into lookup tables for the
1015 /// target.
1016 LLVM_ABI bool shouldBuildLookupTables() const;
1017
1018 /// Return true if switches should be turned into lookup tables
1019 /// containing this constant value for the target.
1021
1022 /// Return true if lookup tables should be turned into relative lookup tables.
1024
1025 /// Return true if the input function which is cold at all call sites,
1026 /// should use coldcc calling convention.
1028
1029 /// Return true if the input function is internal, should use fastcc calling
1030 /// convention.
1032
1034
1035 /// Identifies if the vector form of the intrinsic has a scalar operand.
1037 unsigned ScalarOpdIdx) const;
1038
1039 /// Identifies if the vector form of the intrinsic is overloaded on the type
1040 /// of the operand at index \p OpdIdx, or on the return type if \p OpdIdx is
1041 /// -1.
1043 int OpdIdx) const;
1044
1045 /// Identifies if the vector form of the intrinsic that returns a struct is
1046 /// overloaded at the struct element index \p RetIdx.
1047 LLVM_ABI bool
1049 int RetIdx) const;
1050
1051 /// Represents a hint about the context in which an insert/extract is used.
1052 ///
1053 /// On some targets, inserts/extracts can cheaply be folded into loads/stores.
1054 ///
1055 /// This enum allows the vectorizer to give getVectorInstrCost an idea of how
1056 /// inserts/extracts are used
1057 ///
1058 /// See \c getVectorInstrContextHint to compute a VectorInstrContext from an
1059 /// insert/extract Instruction*.
1061 None, ///< The insert/extract is not used with a load/store.
1062 Load, ///< The value being inserted comes from a load (InsertElement only).
1063 Store, ///< The extracted value is stored (ExtractElement only).
1064 };
1065
1066 /// Calculates a VectorInstrContext from \p I.
1068
1069 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
1070 /// are set if the demanded result elements need to be inserted and/or
1071 /// extracted from vectors. The involved values may be passed in VL if
1072 /// Insert is true.
1074 VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract,
1075 TTI::TargetCostKind CostKind, bool ForPoisonSrc = true,
1076 ArrayRef<Value *> VL = {},
1078
1079 /// Estimate the overhead of scalarizing operands with the given types. The
1080 /// (potentially vector) types to use for each of argument are passes via Tys.
1084
1085 /// If target has efficient vector element load/store instructions, it can
1086 /// return true here so that insertion/extraction costs are not added to
1087 /// the scalarization cost of a load/store.
1089
1090 /// If the target supports tail calls.
1091 LLVM_ABI bool supportsTailCalls() const;
1092
1093 /// If target supports tail call on \p CB
1094 LLVM_ABI bool supportsTailCallFor(const CallBase *CB) const;
1095
1096 /// Don't restrict interleaved unrolling to small loops.
1097 LLVM_ABI bool enableAggressiveInterleaving(bool LoopHasReductions) const;
1098
1099 /// Returns options for expansion of memcmp. IsZeroCmp is
1100 // true if this is the expansion of memcmp(p1, p2, s) == 0.
1102 // Return true if memcmp expansion is enabled.
1103 operator bool() const { return MaxNumLoads > 0; }
1104
1105 // Maximum number of load operations.
1106 unsigned MaxNumLoads = 0;
1107
1108 // The list of available load sizes (in bytes), sorted in decreasing order.
1110
1111 // For memcmp expansion when the memcmp result is only compared equal or
1112 // not-equal to 0, allow up to this number of load pairs per block. As an
1113 // example, this may allow 'memcmp(a, b, 3) == 0' in a single block:
1114 // a0 = load2bytes &a[0]
1115 // b0 = load2bytes &b[0]
1116 // a2 = load1byte &a[2]
1117 // b2 = load1byte &b[2]
1118 // r = cmp eq (a0 ^ b0 | a2 ^ b2), 0
1119 unsigned NumLoadsPerBlock = 1;
1120
1121 // Set to true to allow overlapping loads. For example, 7-byte compares can
1122 // be done with two 4-byte compares instead of 4+2+1-byte compares. This
1123 // requires all loads in LoadSizes to be doable in an unaligned way.
1125
1126 // Sometimes, the amount of data that needs to be compared is smaller than
1127 // the standard register size, but it cannot be loaded with just one load
1128 // instruction. For example, if the size of the memory comparison is 6
1129 // bytes, we can handle it more efficiently by loading all 6 bytes in a
1130 // single block and generating an 8-byte number, instead of generating two
1131 // separate blocks with conditional jumps for 4 and 2 byte loads. This
1132 // approach simplifies the process and produces the comparison result as
1133 // normal. This array lists the allowed sizes of memcmp tails that can be
1134 // merged into one block
1136 };
1138 bool IsZeroCmp) const;
1139
1140 /// Should the Select Optimization pass be enabled and ran.
1141 LLVM_ABI bool enableSelectOptimize() const;
1142
1143 /// Should the Select Optimization pass treat the given instruction like a
1144 /// select, potentially converting it to a conditional branch. This can
1145 /// include select-like instructions like or(zext(c), x) that can be converted
1146 /// to selects.
1148
1149 /// Enable matching of interleaved access groups.
1151
1152 /// Enable matching of interleaved access groups that contain predicated
1153 /// accesses or gaps and therefore vectorized using masked
1154 /// vector loads/stores.
1156
1157 /// Indicate that it is potentially unsafe to automatically vectorize
1158 /// floating-point operations because the semantics of vector and scalar
1159 /// floating-point semantics may differ. For example, ARM NEON v7 SIMD math
1160 /// does not support IEEE-754 denormal numbers, while depending on the
1161 /// platform, scalar floating-point math does.
1162 /// This applies to floating-point math operations and calls, not memory
1163 /// operations, shuffles, or casts.
1165
1166 /// Determine if the target supports unaligned memory accesses.
1168 unsigned BitWidth,
1169 unsigned AddressSpace = 0,
1170 Align Alignment = Align(1),
1171 unsigned *Fast = nullptr) const;
1172
1173 /// Return hardware support for population count.
1174 LLVM_ABI PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
1175
1176 /// Return true if the hardware has a fast square-root instruction.
1177 LLVM_ABI bool haveFastSqrt(Type *Ty) const;
1178
1179 /// Return true if the cost of the instruction is too high to speculatively
1180 /// execute and should be kept behind a branch.
1181 /// This normally just wraps around a getInstructionCost() call, but some
1182 /// targets might report a low TCK_SizeAndLatency value that is incompatible
1183 /// with the fixed TCC_Expensive value.
1184 /// NOTE: This assumes the instruction passes isSafeToSpeculativelyExecute().
1186
1187 /// Return true if it is faster to check if a floating-point value is NaN
1188 /// (or not-NaN) versus a comparison against a constant FP zero value.
1189 /// Targets should override this if materializing a 0.0 for comparison is
1190 /// generally as cheap as checking for ordered/unordered.
1192
1193 /// Return the expected cost of supporting the floating point operation
1194 /// of the specified type.
1196
1197 /// Return the expected cost of materializing for the given integer
1198 /// immediate of the specified type.
1200 TargetCostKind CostKind) const;
1201
1202 /// Return the expected cost of materialization for the given integer
1203 /// immediate of the specified type for a given instruction. The cost can be
1204 /// zero if the immediate can be folded into the specified instruction.
1205 LLVM_ABI InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
1206 const APInt &Imm, Type *Ty,
1208 Instruction *Inst = nullptr) const;
1210 const APInt &Imm, Type *Ty,
1211 TargetCostKind CostKind) const;
1212
1213 /// Return the expected cost for the given integer when optimising
1214 /// for size. This is different than the other integer immediate cost
1215 /// functions in that it is subtarget agnostic. This is useful when you e.g.
1216 /// target one ISA such as Aarch32 but smaller encodings could be possible
1217 /// with another such as Thumb. This return value is used as a penalty when
1218 /// the total costs for a constant is calculated (the bigger the cost, the
1219 /// more beneficial constant hoisting is).
1220 LLVM_ABI InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
1221 const APInt &Imm,
1222 Type *Ty) const;
1223
1224 /// It can be advantageous to detach complex constants from their uses to make
1225 /// their generation cheaper. This hook allows targets to report when such
1226 /// transformations might negatively effect the code generation of the
1227 /// underlying operation. The motivating example is divides whereby hoisting
1228 /// constants prevents the code generator's ability to transform them into
1229 /// combinations of simpler operations.
1231 const Function &Fn) const;
1232
1233 /// @}
1234
1235 /// \name Vector Target Information
1236 /// @{
1237
1238 /// The various kinds of shuffle patterns for vector queries.
1240 SK_Broadcast, ///< Broadcast element 0 to all other elements.
1241 SK_Reverse, ///< Reverse the order of the vector.
1242 SK_Select, ///< Selects elements from the corresponding lane of
1243 ///< either source operand. This is equivalent to a
1244 ///< vector select with a constant condition operand.
1245 SK_Transpose, ///< Transpose two vectors.
1246 SK_InsertSubvector, ///< InsertSubvector. Index indicates start offset.
1247 SK_ExtractSubvector, ///< ExtractSubvector Index indicates start offset.
1248 SK_PermuteTwoSrc, ///< Merge elements from two source vectors into one
1249 ///< with any shuffle mask.
1250 SK_PermuteSingleSrc, ///< Shuffle elements of single source vector with any
1251 ///< shuffle mask.
1252 SK_Splice ///< Concatenates elements from the first input vector
1253 ///< with elements of the second input vector. Returning
1254 ///< a vector of the same type as the input vectors.
1255 ///< Index indicates start offset in first input vector.
1256 };
1257
1258 /// Additional information about an operand's possible values.
1260 OK_AnyValue, // Operand can have any value.
1261 OK_UniformValue, // Operand is uniform (splat of a value).
1262 OK_UniformConstantValue, // Operand is uniform constant.
1263 OK_NonUniformConstantValue // Operand is a non uniform constant value.
1264 };
1265
1266 /// Additional properties of an operand's values.
1272
1273 // Describe the values an operand can take. We're in the process
1274 // of migrating uses of OperandValueKind and OperandValueProperties
1275 // to use this class, and then will change the internal representation.
1279
1280 bool isConstant() const {
1282 }
1283 bool isUniform() const {
1285 }
1286 bool isPowerOf2() const {
1287 return Properties == OP_PowerOf2;
1288 }
1289 bool isNegatedPowerOf2() const {
1291 }
1292
1294 return {Kind, OP_None};
1295 }
1296
1298 OperandValueKind MergeKind = OK_AnyValue;
1299 if (isConstant() && OpInfoY.isConstant())
1300 MergeKind = OK_NonUniformConstantValue;
1301
1302 OperandValueProperties MergeProp = OP_None;
1303 if (Properties == OpInfoY.Properties)
1304 MergeProp = Properties;
1305 return {MergeKind, MergeProp};
1306 }
1307 };
1308
1309 /// \return the number of registers in the target-provided register class.
1310 LLVM_ABI unsigned getNumberOfRegisters(unsigned ClassID) const;
1311
1312 /// \return true if the target supports load/store that enables fault
1313 /// suppression of memory operands when the source condition is false.
1314 LLVM_ABI bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const;
1315
1316 /// \return the target-provided register class ID for the provided type,
1317 /// accounting for type promotion and other type-legalization techniques that
1318 /// the target might apply. However, it specifically does not account for the
1319 /// scalarization or splitting of vector types. Should a vector type require
1320 /// scalarization or splitting into multiple underlying vector registers, that
1321 /// type should be mapped to a register class containing no registers.
1322 /// Specifically, this is designed to provide a simple, high-level view of the
1323 /// register allocation later performed by the backend. These register classes
1324 /// don't necessarily map onto the register classes used by the backend.
1325 /// FIXME: It's not currently possible to determine how many registers
1326 /// are used by the provided type.
1328 Type *Ty = nullptr) const;
1329
1330 /// \return the target-provided register class name
1331 LLVM_ABI const char *getRegisterClassName(unsigned ClassID) const;
1332
1334
1335 /// \return The width of the largest scalar or vector register type.
1336 LLVM_ABI TypeSize getRegisterBitWidth(RegisterKind K) const;
1337
1338 /// \return The width of the smallest vector register type.
1339 LLVM_ABI unsigned getMinVectorRegisterBitWidth() const;
1340
1341 /// \return The maximum value of vscale if the target specifies an
1342 /// architectural maximum vector length, and std::nullopt otherwise.
1343 LLVM_ABI std::optional<unsigned> getMaxVScale() const;
1344
1345 /// \return the value of vscale to tune the cost model for.
1346 LLVM_ABI std::optional<unsigned> getVScaleForTuning() const;
1347
1348 /// \return True if the vectorization factor should be chosen to
1349 /// make the vector of the smallest element type match the size of a
1350 /// vector register. For wider element types, this could result in
1351 /// creating vectors that span multiple vector registers.
1352 /// If false, the vectorization factor will be chosen based on the
1353 /// size of the widest element type.
1354 /// \p K Register Kind for vectorization.
1355 LLVM_ABI bool
1357
1358 /// \return The minimum vectorization factor for types of given element
1359 /// bit width, or 0 if there is no minimum VF. The returned value only
1360 /// applies when shouldMaximizeVectorBandwidth returns true.
1361 /// If IsScalable is true, the returned ElementCount must be a scalable VF.
1362 LLVM_ABI ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const;
1363
1364 /// \return The maximum vectorization factor for types of given element
1365 /// bit width and opcode, or 0 if there is no maximum VF.
1366 /// Currently only used by the SLP vectorizer.
1367 LLVM_ABI unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const;
1368
1369 /// \return The minimum vectorization factor for the store instruction. Given
1370 /// the initial estimation of the minimum vector factor and store value type,
1371 /// it tries to find possible lowest VF, which still might be profitable for
1372 /// the vectorization.
1373 /// \param VF Initial estimation of the minimum vector factor.
1374 /// \param ScalarMemTy Scalar memory type of the store operation.
1375 /// \param ScalarValTy Scalar type of the stored value.
1376 /// Currently only used by the SLP vectorizer.
1377 LLVM_ABI unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy,
1378 Type *ScalarValTy) const;
1379
1380 /// \return True if it should be considered for address type promotion.
1381 /// \p AllowPromotionWithoutCommonHeader Set true if promoting \p I is
1382 /// profitable without finding other extensions fed by the same input.
1384 const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const;
1385
1386 /// \return The size of a cache line in bytes.
1387 LLVM_ABI unsigned getCacheLineSize() const;
1388
1389 /// The possible cache levels
1390 enum class CacheLevel {
1391 L1D, // The L1 data cache
1392 L2D, // The L2 data cache
1393
1394 // We currently do not model L3 caches, as their sizes differ widely between
1395 // microarchitectures. Also, we currently do not have a use for L3 cache
1396 // size modeling yet.
1397 };
1398
1399 /// \return The size of the cache level in bytes, if available.
1400 LLVM_ABI std::optional<unsigned> getCacheSize(CacheLevel Level) const;
1401
1402 /// \return The associativity of the cache level, if available.
1403 LLVM_ABI std::optional<unsigned>
1404 getCacheAssociativity(CacheLevel Level) const;
1405
1406 /// \return The minimum architectural page size for the target.
1407 LLVM_ABI std::optional<unsigned> getMinPageSize() const;
1408
1409 /// \return How much before a load we should place the prefetch
1410 /// instruction. This is currently measured in number of
1411 /// instructions.
1412 LLVM_ABI unsigned getPrefetchDistance() const;
1413
1414 /// Some HW prefetchers can handle accesses up to a certain constant stride.
1415 /// Sometimes prefetching is beneficial even below the HW prefetcher limit,
1416 /// and the arguments provided are meant to serve as a basis for deciding this
1417 /// for a particular loop.
1418 ///
1419 /// \param NumMemAccesses Number of memory accesses in the loop.
1420 /// \param NumStridedMemAccesses Number of the memory accesses that
1421 /// ScalarEvolution could find a known stride
1422 /// for.
1423 /// \param NumPrefetches Number of software prefetches that will be
1424 /// emitted as determined by the addresses
1425 /// involved and the cache line size.
1426 /// \param HasCall True if the loop contains a call.
1427 ///
1428 /// \return This is the minimum stride in bytes where it makes sense to start
1429 /// adding SW prefetches. The default is 1, i.e. prefetch with any
1430 /// stride.
1431 LLVM_ABI unsigned getMinPrefetchStride(unsigned NumMemAccesses,
1432 unsigned NumStridedMemAccesses,
1433 unsigned NumPrefetches,
1434 bool HasCall) const;
1435
1436 /// \return The maximum number of iterations to prefetch ahead. If
1437 /// the required number of iterations is more than this number, no
1438 /// prefetching is performed.
1439 LLVM_ABI unsigned getMaxPrefetchIterationsAhead() const;
1440
1441 /// \return True if prefetching should also be done for writes.
1442 LLVM_ABI bool enableWritePrefetching() const;
1443
1444 /// \return if target want to issue a prefetch in address space \p AS.
1445 LLVM_ABI bool shouldPrefetchAddressSpace(unsigned AS) const;
1446
1447 /// \return The cost of a partial reduction, which is a reduction from a
1448 /// vector to another vector with fewer elements of larger size. They are
1449 /// represented by the llvm.vector.partial.reduce.add and
1450 /// llvm.vector.partial.reduce.fadd intrinsics, which take an accumulator of
1451 /// type \p AccumType and a second vector operand to be accumulated, whose
1452 /// element count is specified by \p VF. The type of reduction is specified by
1453 /// \p Opcode. The second operand passed to the intrinsic could be the result
1454 /// of an extend, such as sext or zext. In this case \p BinOp is nullopt,
1455 /// \p InputTypeA represents the type being extended and \p OpAExtend the
1456 /// operation, i.e. sign- or zero-extend.
1457 /// For floating-point partial reductions, any fast math flags (FMF) should be
1458 /// provided to govern which reductions are valid to perform (depending on
1459 /// reassoc or contract, for example), whereas this must be nullopt for
1460 /// integer partial reductions.
1461 /// Also, \p InputTypeB should be nullptr and OpBExtend should be None.
1462 /// Alternatively, the second operand could be the result of a binary
1463 /// operation performed on two extends, i.e.
1464 /// mul(zext i8 %a -> i32, zext i8 %b -> i32).
1465 /// In this case \p BinOp may specify the opcode of the binary operation,
1466 /// \p InputTypeA and \p InputTypeB the types being extended, and
1467 /// \p OpAExtend, \p OpBExtend the form of extensions. An example of an
1468 /// operation that uses a partial reduction is a dot product, which reduces
1469 /// two vectors in binary mul operation to another of 4 times fewer and 4
1470 /// times larger elements.
1472 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
1474 PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
1475 TTI::TargetCostKind CostKind, std::optional<FastMathFlags> FMF) const;
1476
1477 /// \return The maximum interleave factor that any transform should try to
1478 /// perform for this target. This number depends on the level of parallelism
1479 /// and the number of execution units in the CPU.
1480 LLVM_ABI unsigned getMaxInterleaveFactor(ElementCount VF) const;
1481
1482 /// Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
1483 LLVM_ABI static OperandValueInfo getOperandInfo(const Value *V);
1484
1485 /// Collect common data between two OperandValueInfo inputs
1486 LLVM_ABI static OperandValueInfo commonOperandInfo(const Value *X,
1487 const Value *Y);
1488
1489 /// This is an approximation of reciprocal throughput of a math/logic op.
1490 /// A higher cost indicates less expected throughput.
1491 /// From Agner Fog's guides, reciprocal throughput is "the average number of
1492 /// clock cycles per instruction when the instructions are not part of a
1493 /// limiting dependency chain."
1494 /// Therefore, costs should be scaled to account for multiple execution units
1495 /// on the target that can process this type of instruction. For example, if
1496 /// there are 5 scalar integer units and 2 vector integer units that can
1497 /// calculate an 'add' in a single cycle, this model should indicate that the
1498 /// cost of the vector add instruction is 2.5 times the cost of the scalar
1499 /// add instruction.
1500 /// \p Args is an optional argument which holds the instruction operands
1501 /// values so the TTI can analyze those values searching for special
1502 /// cases or optimizations based on those values.
1503 /// \p CxtI is the optional original context instruction, if one exists, to
1504 /// provide even more information.
1505 /// \p TLibInfo is used to search for platform specific vector library
1506 /// functions for instructions that might be converted to calls (e.g. frem).
1508 unsigned Opcode, Type *Ty,
1512 ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr,
1513 const TargetLibraryInfo *TLibInfo = nullptr) const;
1514
1515 /// Returns the cost estimation for alternating opcode pattern that can be
1516 /// lowered to a single instruction on the target. In X86 this is for the
1517 /// addsub instruction which corrsponds to a Shuffle + Fadd + FSub pattern in
1518 /// IR. This function expects two opcodes: \p Opcode1 and \p Opcode2 being
1519 /// selected by \p OpcodeMask. The mask contains one bit per lane and is a `0`
1520 /// when \p Opcode0 is selected and `1` when Opcode1 is selected.
1521 /// \p VecTy is the vector type of the instruction to be generated.
1523 VectorType *VecTy, unsigned Opcode0, unsigned Opcode1,
1524 const SmallBitVector &OpcodeMask,
1526
1527 /// \return The cost of a shuffle instruction of kind Kind with inputs of type
1528 /// SrcTy, producing a vector of type DstTy. The exact mask may be passed as
1529 /// Mask, or else the array will be empty. The Index and SubTp parameters
1530 /// are used by the subvector insertions shuffle kinds to show the insert
1531 /// point and the type of the subvector being inserted. The operands of the
1532 /// shuffle can be passed through \p Args, which helps improve the cost
1533 /// estimation in some cases, like in broadcast loads.
1535 ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
1536 ArrayRef<int> Mask = {},
1538 VectorType *SubTp = nullptr, ArrayRef<const Value *> Args = {},
1539 const Instruction *CxtI = nullptr) const;
1540
1541 /// Represents a hint about the context in which a cast is used.
1542 ///
1543 /// For zext/sext, the context of the cast is the operand, which must be a
1544 /// load of some kind. For trunc, the context is of the cast is the single
1545 /// user of the instruction, which must be a store of some kind.
1546 ///
1547 /// This enum allows the vectorizer to give getCastInstrCost an idea of the
1548 /// type of cast it's dealing with, as not every cast is equal. For instance,
1549 /// the zext of a load may be free, but the zext of an interleaving load can
1550 //// be (very) expensive!
1551 ///
1552 /// See \c getCastContextHint to compute a CastContextHint from a cast
1553 /// Instruction*. Callers can use it if they don't need to override the
1554 /// context and just want it to be calculated from the instruction.
1555 ///
1556 /// FIXME: This handles the types of load/store that the vectorizer can
1557 /// produce, which are the cases where the context instruction is most
1558 /// likely to be incorrect. There are other situations where that can happen
1559 /// too, which might be handled here but in the long run a more general
1560 /// solution of costing multiple instructions at the same times may be better.
1562 None, ///< The cast is not used with a load/store of any kind.
1563 Normal, ///< The cast is used with a normal load/store.
1564 Masked, ///< The cast is used with a masked load/store.
1565 GatherScatter, ///< The cast is used with a gather/scatter.
1566 Interleave, ///< The cast is used with an interleaved load/store.
1567 Reversed, ///< The cast is used with a reversed load/store.
1568 };
1569
1570 /// Calculates a CastContextHint from \p I.
1571 /// This should be used by callers of getCastInstrCost if they wish to
1572 /// determine the context from some instruction.
1573 /// \returns the CastContextHint for ZExt/SExt/Trunc, None if \p I is nullptr,
1574 /// or if it's another type of cast.
1576
1577 /// \return The expected cost of cast instructions, such as bitcast, trunc,
1578 /// zext, etc. If there is an existing instruction that holds Opcode, it
1579 /// may be passed in the 'I' parameter.
1581 unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH,
1583 const Instruction *I = nullptr) const;
1584
1585 /// \return The expected cost of a sign- or zero-extended vector extract. Use
1586 /// Index = -1 to indicate that there is no information about the index value.
1588 getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
1589 unsigned Index, TTI::TargetCostKind CostKind) const;
1590
1591 /// \return The expected cost of control-flow related instructions such as
1592 /// Phi, Ret, Br, Switch.
1595 const Instruction *I = nullptr) const;
1596
1597 /// \returns The expected cost of compare and select instructions. If there
1598 /// is an existing instruction that holds Opcode, it may be passed in the
1599 /// 'I' parameter. The \p VecPred parameter can be used to indicate the select
1600 /// is using a compare with the specified predicate as condition. When vector
1601 /// types are passed, \p VecPred must be used for all lanes. For a
1602 /// comparison, the two operands are the natural values. For a select, the
1603 /// two operands are the *value* operands, not the condition operand.
1605 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
1607 OperandValueInfo Op1Info = {OK_AnyValue, OP_None},
1608 OperandValueInfo Op2Info = {OK_AnyValue, OP_None},
1609 const Instruction *I = nullptr) const;
1610
1611 /// \return The expected cost of vector Insert and Extract.
1612 /// Use -1 to indicate that there is no information on the index value.
1613 /// This is used when the instruction is not available; a typical use
1614 /// case is to provision the cost of vectorization/scalarization in
1615 /// vectorizer passes.
1617 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
1618 unsigned Index = -1, const Value *Op0 = nullptr,
1619 const Value *Op1 = nullptr,
1621
1622 /// \return The expected cost of vector Insert and Extract.
1623 /// Use -1 to indicate that there is no information on the index value.
1624 /// This is used when the instruction is not available; a typical use
1625 /// case is to provision the cost of vectorization/scalarization in
1626 /// vectorizer passes.
1627 /// \param ScalarUserAndIdx encodes the information about extracts from a
1628 /// vector with 'Scalar' being the value being extracted,'User' being the user
1629 /// of the extract(nullptr if user is not known before vectorization) and
1630 /// 'Idx' being the extract lane.
1632 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
1633 Value *Scalar,
1634 ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx,
1636
1637 /// \return The expected cost of vector Insert and Extract.
1638 /// This is used when instruction is available, and implementation
1639 /// asserts 'I' is not nullptr.
1640 ///
1641 /// A typical suitable use case is cost estimation when vector instruction
1642 /// exists (e.g., from basic blocks during transformation).
1644 const Instruction &I, Type *Val, TTI::TargetCostKind CostKind,
1645 unsigned Index = -1,
1647
1648 /// \return The expected cost of inserting or extracting a lane that is \p
1649 /// Index elements from the end of a vector, i.e. the mathematical expression
1650 /// for the lane is (VF - 1 - Index). This is required for scalable vectors
1651 /// where the exact lane index is unknown at compile time.
1653 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
1654 unsigned Index) const;
1655
1656 /// \return The expected cost of aggregate inserts and extracts. This is
1657 /// used when the instruction is not available; a typical use case is to
1658 /// provision the cost of vectorization/scalarization in vectorizer passes.
1660 unsigned Opcode, TTI::TargetCostKind CostKind) const;
1661
1662 /// \return The cost of replication shuffle of \p VF elements typed \p EltTy
1663 /// \p ReplicationFactor times.
1664 ///
1665 /// For example, the mask for \p ReplicationFactor=3 and \p VF=4 is:
1666 /// <0,0,0,1,1,1,2,2,2,3,3,3>
1668 Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts,
1670
1671 /// \return The cost of Load and Store instructions. The operand info
1672 /// \p OpdInfo should refer to the stored value for stores and the address
1673 /// for loads.
1675 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
1678 const Instruction *I = nullptr) const;
1679
1680 /// \return The cost of the interleaved memory operation.
1681 /// \p Opcode is the memory operation code
1682 /// \p VecTy is the vector type of the interleaved access.
1683 /// \p Factor is the interleave factor
1684 /// \p Indices is the indices for interleaved load members (as interleaved
1685 /// load allows gaps)
1686 /// \p Alignment is the alignment of the memory operation
1687 /// \p AddressSpace is address space of the pointer.
1688 /// \p UseMaskForCond indicates if the memory access is predicated.
1689 /// \p UseMaskForGaps indicates if gaps should be masked.
1691 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
1692 Align Alignment, unsigned AddressSpace,
1694 bool UseMaskForCond = false, bool UseMaskForGaps = false) const;
1695
1696 /// A helper function to determine the type of reduction algorithm used
1697 /// for a given \p Opcode and set of FastMathFlags \p FMF.
1698 static bool requiresOrderedReduction(std::optional<FastMathFlags> FMF) {
1699 return FMF && !(*FMF).allowReassoc();
1700 }
1701
1702 /// Calculate the cost of vector reduction intrinsics.
1703 ///
1704 /// This is the cost of reducing the vector value of type \p Ty to a scalar
1705 /// value using the operation denoted by \p Opcode. The FastMathFlags
1706 /// parameter \p FMF indicates what type of reduction we are performing:
1707 /// 1. Tree-wise. This is the typical 'fast' reduction performed that
1708 /// involves successively splitting a vector into half and doing the
1709 /// operation on the pair of halves until you have a scalar value. For
1710 /// example:
1711 /// (v0, v1, v2, v3)
1712 /// ((v0+v2), (v1+v3), undef, undef)
1713 /// ((v0+v2+v1+v3), undef, undef, undef)
1714 /// This is the default behaviour for integer operations, whereas for
1715 /// floating point we only do this if \p FMF indicates that
1716 /// reassociation is allowed.
1717 /// 2. Ordered. For a vector with N elements this involves performing N
1718 /// operations in lane order, starting with an initial scalar value, i.e.
1719 /// result = InitVal + v0
1720 /// result = result + v1
1721 /// result = result + v2
1722 /// result = result + v3
1723 /// This is only the case for FP operations and when reassociation is not
1724 /// allowed.
1725 ///
1727 unsigned Opcode, VectorType *Ty, std::optional<FastMathFlags> FMF,
1729
1733
1734 /// Calculate the cost of an extended reduction pattern, similar to
1735 /// getArithmeticReductionCost of an Add/Sub reduction with multiply and
1736 /// optional extensions. This is the cost of as:
1737 /// * ResTy vecreduce.add/sub(mul (A, B)) or,
1738 /// * ResTy vecreduce.add/sub(mul(ext(Ty A), ext(Ty B)).
1740 bool IsUnsigned, unsigned RedOpcode, Type *ResTy, VectorType *Ty,
1742
1743 /// Calculate the cost of an extended reduction pattern, similar to
1744 /// getArithmeticReductionCost of a reduction with an extension.
1745 /// This is the cost of as:
1746 /// ResTy vecreduce.opcode(ext(Ty A)).
1748 unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty,
1749 std::optional<FastMathFlags> FMF,
1751
1752 /// \returns The cost of Intrinsic instructions. Analyses the real arguments.
1753 /// Three cases are handled: 1. scalar instruction 2. vector instruction
1754 /// 3. scalar instruction which is to be vectorized.
1757
1758 /// \returns The cost of memory intrinsic instructions.
1759 /// Used when IntrinsicInst is not materialized.
1763
1764 /// \returns The cost of Call instructions.
1766 Function *F, Type *RetTy, ArrayRef<Type *> Tys,
1768
1769 /// \returns The number of pieces into which the provided type must be
1770 /// split during legalization. Zero is returned when the answer is unknown.
1771 LLVM_ABI unsigned getNumberOfParts(Type *Tp) const;
1772
1773 /// \returns The cost of the address computation. For most targets this can be
1774 /// merged into the instruction indexing mode. Some targets might want to
1775 /// distinguish between address computation for memory operations with vector
1776 /// pointer types and scalar pointer types. Such targets should override this
1777 /// function. \p SE holds the pointer for the scalar evolution object which
1778 /// was used in order to get the Ptr step value. \p Ptr holds the SCEV of the
1779 /// access pointer.
1781 getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *Ptr,
1783
1784 /// \returns The cost, if any, of keeping values of the given types alive
1785 /// over a callsite.
1786 ///
1787 /// Some types may require the use of register classes that do not have
1788 /// any callee-saved registers, so would require a spill and fill.
1791
1792 /// \returns True if the intrinsic is a supported memory intrinsic. Info
1793 /// will contain additional information - whether the intrinsic may write
1794 /// or read to memory, volatility and the pointer. Info is undefined
1795 /// if false is returned.
1797 MemIntrinsicInfo &Info) const;
1798
1799 /// \returns The maximum element size, in bytes, for an element
1800 /// unordered-atomic memory intrinsic.
1802
1803 /// \returns A value which is the result of the given memory intrinsic. If \p
1804 /// CanCreate is true, new instructions may be created to extract the result
1805 /// from the given intrinsic memory operation. Returns nullptr if the target
1806 /// cannot create a result from the given intrinsic.
1807 LLVM_ABI Value *
1809 bool CanCreate = true) const;
1810
1811 /// \returns The type to use in a loop expansion of a memcpy call.
1813 LLVMContext &Context, Value *Length, unsigned SrcAddrSpace,
1814 unsigned DestAddrSpace, Align SrcAlign, Align DestAlign,
1815 std::optional<uint32_t> AtomicElementSize = std::nullopt) const;
1816
1817 /// \param[out] OpsOut The operand types to copy RemainingBytes of memory.
1818 /// \param RemainingBytes The number of bytes to copy.
1819 ///
1820 /// Calculates the operand types to use when copying \p RemainingBytes of
1821 /// memory, where source and destination alignments are \p SrcAlign and
1822 /// \p DestAlign respectively.
1824 SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context,
1825 unsigned RemainingBytes, unsigned SrcAddrSpace, unsigned DestAddrSpace,
1826 Align SrcAlign, Align DestAlign,
1827 std::optional<uint32_t> AtomicCpySize = std::nullopt) const;
1828
1829 /// \returns True if the two functions have compatible attributes for inlining
1830 /// purposes.
1831 LLVM_ABI bool areInlineCompatible(const Function *Caller,
1832 const Function *Callee) const;
1833
1834 /// Returns a penalty for invoking call \p Call in \p F.
1835 /// For example, if a function F calls a function G, which in turn calls
1836 /// function H, then getInlineCallPenalty(F, H()) would return the
1837 /// penalty of calling H from F, e.g. after inlining G into F.
1838 /// \p DefaultCallPenalty is passed to give a default penalty that
1839 /// the target can amend or override.
1840 LLVM_ABI unsigned getInlineCallPenalty(const Function *F,
1841 const CallBase &Call,
1842 unsigned DefaultCallPenalty) const;
1843
1844 /// \returns true if `Caller`'s `Attr` should be added to the new function
1845 /// created by outlining part of `Caller`.
1846 LLVM_ABI bool
1848 const Attribute &Attr) const;
1849
1850 /// \returns True if the caller and callee agree on how \p Types will be
1851 /// passed to or returned from the callee.
1852 /// to the callee.
1853 /// \param Types List of types to check.
1854 LLVM_ABI bool areTypesABICompatible(const Function *Caller,
1855 const Function *Callee,
1856 ArrayRef<Type *> Types) const;
1857
1858 /// The type of load/store indexing.
1860 MIM_Unindexed, ///< No indexing.
1861 MIM_PreInc, ///< Pre-incrementing.
1862 MIM_PreDec, ///< Pre-decrementing.
1863 MIM_PostInc, ///< Post-incrementing.
1864 MIM_PostDec ///< Post-decrementing.
1865 };
1866
1867 /// \returns True if the specified indexed load for the given type is legal.
1868 LLVM_ABI bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const;
1869
1870 /// \returns True if the specified indexed store for the given type is legal.
1871 LLVM_ABI bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const;
1872
1873 /// \returns The bitwidth of the largest vector type that should be used to
1874 /// load/store in the given address space.
1875 LLVM_ABI unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const;
1876
1877 /// \returns True if the load instruction is legal to vectorize.
1879
1880 /// \returns True if the store instruction is legal to vectorize.
1882
1883 /// \returns True if it is legal to vectorize the given load chain.
1884 LLVM_ABI bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
1885 Align Alignment,
1886 unsigned AddrSpace) const;
1887
1888 /// \returns True if it is legal to vectorize the given store chain.
1889 LLVM_ABI bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
1890 Align Alignment,
1891 unsigned AddrSpace) const;
1892
1893 /// \returns True if it is legal to vectorize the given reduction kind.
1895 ElementCount VF) const;
1896
1897 /// \returns True if the given type is supported for scalable vectors
1899
1900 /// \returns The new vector factor value if the target doesn't support \p
1901 /// SizeInBytes loads or has a better vector factor.
1902 LLVM_ABI unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
1903 unsigned ChainSizeInBytes,
1904 VectorType *VecTy) const;
1905
1906 /// \returns The new vector factor value if the target doesn't support \p
1907 /// SizeInBytes stores or has a better vector factor.
1908 LLVM_ABI unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
1909 unsigned ChainSizeInBytes,
1910 VectorType *VecTy) const;
1911
1912 /// \returns True if the target prefers fixed width vectorization if the
1913 /// loop vectorizer's cost-model assigns an equal cost to the fixed and
1914 /// scalable version of the vectorized loop.
1915 /// \p IsEpilogue is true if the decision is for the epilogue loop.
1916 LLVM_ABI bool preferFixedOverScalableIfEqualCost(bool IsEpilogue) const;
1917
1918 /// \returns True if target prefers SLP vectorizer with altermate opcode
1919 /// vectorization, false - otherwise.
1921
1922 /// \returns True if the target prefers reductions of \p Kind to be performed
1923 /// in the loop.
1924 LLVM_ABI bool preferInLoopReduction(RecurKind Kind, Type *Ty) const;
1925
1926 /// \returns True if the target prefers reductions select kept in the loop
1927 /// when tail folding. i.e.
1928 /// loop:
1929 /// p = phi (0, s)
1930 /// a = add (p, x)
1931 /// s = select (mask, a, p)
1932 /// vecreduce.add(s)
1933 ///
1934 /// As opposed to the normal scheme of p = phi (0, a) which allows the select
1935 /// to be pulled out of the loop. If the select(.., add, ..) can be predicated
1936 /// by the target, this can lead to cleaner code generation.
1938
1939 /// Return true if the loop vectorizer should consider vectorizing an
1940 /// otherwise scalar epilogue loop if the loop already has been vectorized
1941 /// processing \p Iters scalar iterations per vector iteration.
1943
1944 /// \returns True if the loop vectorizer should discard any VFs where the
1945 /// maximum register pressure exceeds getNumberOfRegisters.
1947
1948 /// \returns True if the target wants to expand the given reduction intrinsic
1949 /// into a shuffle sequence.
1951
1953
1954 /// \returns The shuffle sequence pattern used to expand the given reduction
1955 /// intrinsic.
1958
1959 /// \returns the size cost of rematerializing a GlobalValue address relative
1960 /// to a stack reload.
1961 LLVM_ABI unsigned getGISelRematGlobalCost() const;
1962
1963 /// \returns the lower bound of a trip count to decide on vectorization
1964 /// while tail-folding.
1966
1967 /// \returns True if the target supports scalable vectors.
1968 LLVM_ABI bool supportsScalableVectors() const;
1969
1970 /// \return true when scalable vectorization is preferred.
1972
1973 /// \name Vector Predication Information
1974 /// @{
1975 /// Whether the target supports the %evl parameter of VP intrinsic efficiently
1976 /// in hardware. (see LLVM Language Reference - "Vector Predication
1977 /// Intrinsics"). Use of %evl is discouraged when that is not the case.
1978 LLVM_ABI bool hasActiveVectorLength() const;
1979
1980 /// Return true if sinking I's operands to the same basic block as I is
1981 /// profitable, e.g. because the operands can be folded into a target
1982 /// instruction during instruction selection. After calling the function
1983 /// \p Ops contains the Uses to sink ordered by dominance (dominating users
1984 /// come first).
1987
1988 /// Return true if it's significantly cheaper to shift a vector by a uniform
1989 /// scalar than by an amount which will vary across each lane. On x86 before
1990 /// AVX2 for example, there is a "psllw" instruction for the former case, but
1991 /// no simple instruction for a general "a << b" operation on vectors.
1992 /// This should also apply to lowering for vector funnel shifts (rotates).
1994
1997 // keep the predicating parameter
1999 // where legal, discard the predicate parameter
2001 // transform into something else that is also predicating
2003 };
2004
2005 // How to transform the EVL parameter.
2006 // Legal: keep the EVL parameter as it is.
2007 // Discard: Ignore the EVL parameter where it is safe to do so.
2008 // Convert: Fold the EVL into the mask parameter.
2010
2011 // How to transform the operator.
2012 // Legal: The target supports this operator.
2013 // Convert: Convert this to a non-VP operation.
2014 // The 'Discard' strategy is invalid.
2016
2017 bool shouldDoNothing() const {
2018 return (EVLParamStrategy == Legal) && (OpStrategy == Legal);
2019 }
2022 };
2023
2024 /// \returns How the target needs this vector-predicated operation to be
2025 /// transformed.
2027 getVPLegalizationStrategy(const VPIntrinsic &PI) const;
2028 /// @}
2029
2030 /// \returns Whether a 32-bit branch instruction is available in Arm or Thumb
2031 /// state.
2032 ///
2033 /// Used by the LowerTypeTests pass, which constructs an IR inline assembler
2034 /// node containing a jump table in a format suitable for the target, so it
2035 /// needs to know what format of jump table it can legally use.
2036 ///
2037 /// For non-Arm targets, this function isn't used. It defaults to returning
2038 /// false, but it shouldn't matter what it returns anyway.
2039 LLVM_ABI bool hasArmWideBranch(bool Thumb) const;
2040
2041 /// Returns a bitmask constructed from the target-features or fmv-features
2042 /// metadata of a function corresponding to its Arch Extensions.
2043 LLVM_ABI APInt getFeatureMask(const Function &F) const;
2044
2045 /// Returns a bitmask constructed from the target-features or fmv-features
2046 /// metadata of a function corresponding to its FMV priority.
2047 LLVM_ABI APInt getPriorityMask(const Function &F) const;
2048
2049 /// Returns true if this is an instance of a function with multiple versions.
2050 LLVM_ABI bool isMultiversionedFunction(const Function &F) const;
2051
2052 /// \return The maximum number of function arguments the target supports.
2053 LLVM_ABI unsigned getMaxNumArgs() const;
2054
2055 /// \return For an array of given Size, return alignment boundary to
2056 /// pad to. Default is no padding.
2057 LLVM_ABI unsigned getNumBytesToPadGlobalArray(unsigned Size,
2058 Type *ArrayType) const;
2059
2060 /// @}
2061
2062 /// Collect kernel launch bounds for \p F into \p LB.
2064 const Function &F,
2065 SmallVectorImpl<std::pair<StringRef, int64_t>> &LB) const;
2066
2067 /// Returns true if GEP should not be used to index into vectors for this
2068 /// target.
2070
2071private:
2072 std::unique_ptr<const TargetTransformInfoImplBase> TTIImpl;
2073};
2074
2075/// Analysis pass providing the \c TargetTransformInfo.
2076///
2077/// The core idea of the TargetIRAnalysis is to expose an interface through
2078/// which LLVM targets can analyze and provide information about the middle
2079/// end's target-independent IR. This supports use cases such as target-aware
2080/// cost modeling of IR constructs.
2081///
2082/// This is a function analysis because much of the cost modeling for targets
2083/// is done in a subtarget specific way and LLVM supports compiling different
2084/// functions targeting different subtargets in order to support runtime
2085/// dispatch according to the observed subtarget.
2086class TargetIRAnalysis : public AnalysisInfoMixin<TargetIRAnalysis> {
2087public:
2089
2090 /// Default construct a target IR analysis.
2091 ///
2092 /// This will use the module's datalayout to construct a baseline
2093 /// conservative TTI result.
2095
2096 /// Construct an IR analysis pass around a target-provide callback.
2097 ///
2098 /// The callback will be called with a particular function for which the TTI
2099 /// is needed and must return a TTI object for that function.
2100 LLVM_ABI
2101 TargetIRAnalysis(std::function<Result(const Function &)> TTICallback);
2102
2103 // Value semantics. We spell out the constructors for MSVC.
2105 : TTICallback(Arg.TTICallback) {}
2107 : TTICallback(std::move(Arg.TTICallback)) {}
2109 TTICallback = RHS.TTICallback;
2110 return *this;
2111 }
2113 TTICallback = std::move(RHS.TTICallback);
2114 return *this;
2115 }
2116
2118
2119private:
2121 LLVM_ABI static AnalysisKey Key;
2122
2123 /// The callback used to produce a result.
2124 ///
2125 /// We use a completely opaque callback so that targets can provide whatever
2126 /// mechanism they desire for constructing the TTI for a given function.
2127 ///
2128 /// FIXME: Should we really use std::function? It's relatively inefficient.
2129 /// It might be possible to arrange for even stateful callbacks to outlive
2130 /// the analysis and thus use a function_ref which would be lighter weight.
2131 /// This may also be less error prone as the callback is likely to reference
2132 /// the external TargetMachine, and that reference needs to never dangle.
2133 std::function<Result(const Function &)> TTICallback;
2134
2135 /// Helper function used as the callback in the default constructor.
2136 static Result getDefaultTTI(const Function &F);
2137};
2138
2139/// Wrapper pass for TargetTransformInfo.
2140///
2141/// This pass can be constructed from a TTI object which it stores internally
2142/// and is queried by passes.
2144 TargetIRAnalysis TIRA;
2145 std::optional<TargetTransformInfo> TTI;
2146
2147 virtual void anchor();
2148
2149public:
2150 static char ID;
2151
2152 /// We must provide a default constructor for the pass but it should
2153 /// never be used.
2154 ///
2155 /// Use the constructor below or call one of the creation routines.
2157
2159
2161};
2162
2163/// Create an analysis pass wrapper around a TTI object.
2164///
2165/// This analysis pass just holds the TTI instance and makes it available to
2166/// clients.
2169
2170} // namespace llvm
2171
2172#endif
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
#define LLVM_ABI
Definition Compiler.h:213
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
TargetTransformInfo::VPLegalization VPLegalization
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,...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
Value * RHS
Class for arbitrary precision integers.
Definition APInt.h:78
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Class to represent array types.
A cache of @llvm.assume calls within a function.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
LLVM Basic Block Representation.
Definition BasicBlock.h:62
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...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:164
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:285
ImmutablePass(char &pid)
Definition Pass.h:287
The core instruction combiner logic.
static InstructionCost getInvalid(CostType Val=0)
Class to represent integer types.
Drive the analysis of interleaved memory accesses in the loop.
const SmallVectorImpl< Type * > & getArgTypes() const
const SmallVectorImpl< const Value * > & getArgs() const
LLVM_ABI IntrinsicCostAttributes(Intrinsic::ID Id, const CallBase &CI, InstructionCost ScalarCost=InstructionCost::getInvalid(), bool TypeBasedOnly=false)
InstructionCost getScalarizationCost() const
const IntrinsicInst * getInst() const
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
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:40
Information for memory intrinsic cost model.
LLVM_ABI MemIntrinsicCostAttributes(Intrinsic::ID Id, Type *DataTy, bool VariableMask, Align Alignment, const Instruction *I=nullptr)
LLVM_ABI MemIntrinsicCostAttributes(Intrinsic::ID Id, Type *DataTy, Align Alignment, unsigned AddressSpace=0)
const Instruction * getInst() const
LLVM_ABI MemIntrinsicCostAttributes(Intrinsic::ID Id, Type *DataTy, const Value *Ptr, bool VariableMask, Align Alignment, const Instruction *I=nullptr)
The optimization diagnostic interface.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Analysis providing profile information.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
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...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
An instruction for storing to memory.
Multiway switch.
Analysis pass providing the TargetTransformInfo.
TargetIRAnalysis(const TargetIRAnalysis &Arg)
TargetIRAnalysis & operator=(const TargetIRAnalysis &RHS)
LLVM_ABI Result run(const Function &F, FunctionAnalysisManager &)
LLVM_ABI 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.
Base class for use as a mix-in that aids implementing a TargetTransformInfo-compatible class.
TargetTransformInfoWrapperPass()
We must provide a default constructor for the pass but it should never be used.
TargetTransformInfo & getTTI(const Function &F)
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
LLVM_ABI bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
LLVM_ABI Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType, bool CanCreate=true) const
LLVM_ABI bool isLegalToVectorizeLoad(LoadInst *LI) const
LLVM_ABI std::optional< unsigned > getVScaleForTuning() const
static LLVM_ABI CastContextHint getCastContextHint(const Instruction *I)
Calculates a CastContextHint from I.
LLVM_ABI unsigned getMaxNumArgs() const
LLVM_ABI bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const
Return false if a AS0 address cannot possibly alias a AS1 address.
LLVM_ABI bool isLegalMaskedScatter(Type *DataType, Align Alignment) const
Return true if the target supports masked scatter.
LLVM_ABI bool shouldBuildLookupTables() const
Return true if switches should be turned into lookup tables for the target.
LLVM_ABI bool isLegalToVectorizeStore(StoreInst *SI) const
LLVM_ABI InstructionCost getMulAccReductionCost(bool IsUnsigned, unsigned RedOpcode, 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/...
LLVM_ABI bool areTypesABICompatible(const Function *Caller, const Function *Callee, ArrayRef< Type * > Types) const
LLVM_ABI bool enableAggressiveInterleaving(bool LoopHasReductions) const
Don't restrict interleaved unrolling to small loops.
LLVM_ABI bool isMultiversionedFunction(const Function &F) const
Returns true if this is an instance of a function with multiple versions.
LLVM_ABI InstructionUniformity getInstructionUniformity(const Value *V) const
Get target-specific uniformity information for an instruction.
LLVM_ABI 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...
LLVM_ABI bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace, MaskKind MaskKind=VariableOrConstantMask) const
Return true if the target supports masked store.
LLVM_ABI bool supportsEfficientVectorElementLoadStore() const
If target has efficient vector element load/store instructions, it can return true here so that inser...
LLVM_ABI unsigned getAssumedAddrSpace(const Value *V) const
LLVM_ABI bool preferAlternateOpcodeVectorization() const
LLVM_ABI bool shouldDropLSRSolutionIfLessProfitable() const
Return true if LSR should drop a found solution if it's calculated to be less profitable than the bas...
LLVM_ABI bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const
Return true if LSR cost of C1 is lower than C2.
VectorInstrContext
Represents a hint about the context in which an insert/extract is used.
@ None
The insert/extract is not used with a load/store.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
LLVM_ABI unsigned getPrefetchDistance() const
LLVM_ABI Type * getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length, unsigned SrcAddrSpace, unsigned DestAddrSpace, Align SrcAlign, Align DestAlign, std::optional< uint32_t > AtomicElementSize=std::nullopt) const
LLVM_ABI bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const
Return true if the target supports masked expand load.
LLVM_ABI bool prefersVectorizedAddressing() const
Return true if target doesn't mind addresses in vectors.
LLVM_ABI 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
LLVM_ABI bool hasBranchDivergence(const Function *F=nullptr) const
Return true if branch divergence exists.
LLVM_ABI bool preferEpilogueVectorization(ElementCount Iters) const
Return true if the loop vectorizer should consider vectorizing an otherwise scalar epilogue loop if t...
LLVM_ABI MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle the invalidation of this information.
LLVM_ABI void getUnrollingPreferences(Loop *L, ScalarEvolution &, UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const
Get target-customized preferences for the generic loop unrolling transformation.
LLVM_ABI bool shouldBuildLookupTablesForConstant(Constant *C) const
Return true if switches should be turned into lookup tables containing this constant value for the ta...
LLVM_ABI TailFoldingStyle getPreferredTailFoldingStyle() const
Query the target what the preferred style of tail folding is.
LLVM_ABI bool supportsTailCallFor(const CallBase *CB) const
If target supports tail call on CB.
LLVM_ABI std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const
Targets can implement their own combinations for target-specific intrinsics.
LLVM_ABI bool isProfitableLSRChainElement(Instruction *I) const
LLVM_ABI TypeSize getRegisterBitWidth(RegisterKind K) const
MaskKind
Some targets only support masked load/store with a constant mask.
LLVM_ABI unsigned getInlineCallPenalty(const Function *F, const CallBase &Call, unsigned DefaultCallPenalty) const
Returns a penalty for invoking call Call in F.
LLVM_ABI InstructionCost getOperandsScalarizationOverhead(ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
Estimate the overhead of scalarizing operands with the given types.
LLVM_ABI bool hasActiveVectorLength() const
LLVM_ABI 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...
LLVM_ABI bool preferFixedOverScalableIfEqualCost(bool IsEpilogue) const
LLVM_ABI bool isLegalMaskedGather(Type *DataType, Align Alignment) const
Return true if the target supports masked gather.
static LLVM_ABI OperandValueInfo commonOperandInfo(const Value *X, const Value *Y)
Collect common data between two OperandValueInfo inputs.
LLVM_ABI 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
LLVM_ABI std::optional< unsigned > getMaxVScale() const
LLVM_ABI InstructionCost getReplicationShuffleCost(Type *EltTy, int ReplicationFactor, int VF, const APInt &DemandedDstElts, TTI::TargetCostKind CostKind) const
LLVM_ABI bool allowVectorElementIndexingUsingGEP() const
Returns true if GEP should not be used to index into vectors for this target.
LLVM_ABI 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
LLVM_ABI bool isSingleThreaded() const
LLVM_ABI 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.
LLVM_ABI 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...
LLVM_ABI unsigned getInliningCostBenefitAnalysisProfitableMultiplier() const
LLVM_ABI InstructionCost getShuffleCost(ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, ArrayRef< int > Mask={}, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, int Index=0, VectorType *SubTp=nullptr, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const
LLVM_ABI InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const
LLVM_ABI InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Calculate the cost of vector reduction intrinsics.
LLVM_ABI unsigned getAtomicMemIntrinsicMaxElementSize() const
LLVM_ABI InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency, const Instruction *I=nullptr) const
LLVM_ABI InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index=-1, const Value *Op0=nullptr, const Value *Op1=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
LLVM_ABI std::pair< KnownBits, KnownBits > computeKnownBitsAddrSpaceCast(unsigned ToAS, const Value &PtrOp) const
LLVM_ABI bool LSRWithInstrQueries() const
Return true if the loop strength reduce pass should make Instruction* based TTI queries to isLegalAdd...
LLVM_ABI unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
LLVM_ABI VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
static LLVM_ABI PartialReductionExtendKind getPartialReductionExtendKind(Instruction *I)
Get the kind of extension that an instruction represents.
LLVM_ABI bool shouldConsiderVectorizationRegPressure() const
LLVM_ABI bool enableWritePrefetching() const
LLVM_ABI bool shouldTreatInstructionLikeSelect(const Instruction *I) const
Should the Select Optimization pass treat the given instruction like a select, potentially converting...
LLVM_ABI bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
LLVM_ABI bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const
LLVM_ABI 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.
LLVM_ABI bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
LLVM_ABI 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,...
LLVM_ABI unsigned getRegUsageForType(Type *Ty) const
Returns the estimated number of registers required to represent Ty.
LLVM_ABI bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const
\Returns true if the target supports broadcasting a load to a vector of type <NumElements x ElementTy...
LLVM_ABI bool isIndexedStoreLegal(enum MemIndexedMode Mode, Type *Ty) const
LLVM_ABI std::pair< const Value *, unsigned > getPredicatedAddrSpace(const Value *V) const
LLVM_ABI InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput) const
Calculate the cost of an extended reduction pattern, similar to getArithmeticReductionCost of a reduc...
LLVM_ABI unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
LLVM_ABI ReductionShuffle getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const
static LLVM_ABI OperandValueInfo getOperandInfo(const Value *V)
Collect properties of V used in cost analysis, e.g. OP_PowerOf2.
LLVM_ABI unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
LLVM_ABI 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...
LLVM_ABI PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
Return hardware support for population count.
LLVM_ABI unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) const
LLVM_ABI bool isElementTypeLegalForScalableVector(Type *Ty) const
LLVM_ABI bool forceScalarizeMaskedGather(VectorType *Type, Align Alignment) const
Return true if the target forces scalarizing of llvm.masked.gather intrinsics.
LLVM_ABI unsigned getMaxPrefetchIterationsAhead() const
LLVM_ABI bool canHaveNonUndefGlobalInitializerInAddressSpace(unsigned AS) const
Return true if globals in this address space can have initializers other than undef.
LLVM_ABI ElementCount getMinimumVF(unsigned ElemWidth, bool IsScalable) const
LLVM_ABI InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TargetCostKind CostKind) const
LLVM_ABI bool enableMaskedInterleavedAccessVectorization() const
Enable matching of interleaved access groups that contain predicated accesses or gaps and therefore v...
LLVM_ABI 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...
LLVM_ABI bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const
Return true if the target supports strided load.
LLVM_ABI TargetTransformInfo & operator=(TargetTransformInfo &&RHS)
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI bool enableSelectOptimize() const
Should the Select Optimization pass be enabled and ran.
LLVM_ABI 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.
LLVM_ABI int getInliningLastCallToStaticBonus() const
LLVM_ABI 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...
LLVM_ABI bool isIndexedLoadLegal(enum MemIndexedMode Mode, Type *Ty) const
LLVM_ABI unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const
LLVM_ABI bool isLegalICmpImmediate(int64_t Imm) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
LLVM_ABI 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...
LLVM_ABI bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc, ElementCount VF) const
LLVM_ABI std::optional< unsigned > getCacheAssociativity(CacheLevel Level) const
LLVM_ABI bool isLegalNTLoad(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal load.
LLVM_ABI InstructionCost getMemcpyCost(const Instruction *I) const
LLVM_ABI unsigned adjustInliningThreshold(const CallBase *CB) const
LLVM_ABI bool isLegalAddImmediate(int64_t Imm) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
LLVM_ABI 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...
LLVM_ABI unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
LLVM_ABI InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
LLVM_ABI 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...
LLVM_ABI bool isTargetIntrinsicTriviallyScalarizable(Intrinsic::ID ID) const
LLVM_ABI 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...
LLVM_ABI InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
LLVM_ABI unsigned getMinPrefetchStride(unsigned NumMemAccesses, unsigned NumStridedMemAccesses, unsigned NumPrefetches, bool HasCall) const
Some HW prefetchers can handle accesses up to a certain constant stride.
LLVM_ABI bool shouldPrefetchAddressSpace(unsigned AS) const
LLVM_ABI 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.
LLVM_ABI unsigned getMinVectorRegisterBitWidth() const
LLVM_ABI InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *SE, const SCEV *Ptr, TTI::TargetCostKind CostKind) const
LLVM_ABI bool isLegalNTStore(Type *DataType, Align Alignment) const
Return true if the target supports nontemporal store.
LLVM_ABI unsigned getFlatAddressSpace() const
Returns the address space ID for a target's 'flat' address space.
LLVM_ABI 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.
LLVM_ABI bool hasArmWideBranch(bool Thumb) const
LLVM_ABI const char * getRegisterClassName(unsigned ClassID) const
LLVM_ABI bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const
LLVM_ABI APInt getPriorityMask(const Function &F) const
Returns a bitmask constructed from the target-features or fmv-features metadata of a function corresp...
LLVM_ABI BranchProbability getPredictableBranchThreshold() const
If a branch or a select condition is skewed in one direction by more than this factor,...
LLVM_ABI TargetTransformInfo(std::unique_ptr< const TargetTransformInfoImplBase > Impl)
Construct a TTI object using a type implementing the Concept API below.
LLVM_ABI bool preferInLoopReduction(RecurKind Kind, Type *Ty) const
LLVM_ABI unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const
LLVM_ABI bool hasConditionalLoadStoreForType(Type *Ty, bool IsStore) const
LLVM_ABI unsigned getCacheLineSize() const
LLVM_ABI 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.
LLVM_ABI bool shouldCopyAttributeWhenOutliningFrom(const Function *Caller, const Attribute &Attr) const
LLVM_ABI APInt getAddrSpaceCastPreservedPtrMask(unsigned SrcAS, unsigned DstAS) const
Return the preserved ptr bit mask that is safe to cast integer to pointer with new address space.
LLVM_ABI int getInlinerVectorBonusPercent() const
LLVM_ABI unsigned getEpilogueVectorizationMinVF() const
LLVM_ABI void collectKernelLaunchBounds(const Function &F, SmallVectorImpl< std::pair< StringRef, int64_t > > &LB) const
Collect kernel launch bounds for F into LB.
PopcntSupportKind
Flags indicating the kind of support for population count.
LLVM_ABI bool preferPredicatedReductionSelect() const
LLVM_ABI InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) const
Return the expected cost for the given integer when optimising for size.
LLVM_ABI AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const
Return the preferred addressing mode LSR should make efforts to generate.
LLVM_ABI bool isLoweredToCall(const Function *F) const
Test whether calls to a function lower to actual program function calls.
LLVM_ABI bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
LLVM_ABI 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.
LLVM_ABI unsigned getInliningThresholdMultiplier() const
LLVM_ABI InstructionCost getBranchMispredictPenalty() const
Returns estimated penalty of a branch misprediction in latency.
LLVM_ABI unsigned getNumberOfRegisters(unsigned ClassID) const
LLVM_ABI 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...
LLVM_ABI bool isProfitableToHoist(Instruction *I) const
Return true if it is profitable to hoist instruction in the then/else to before if.
LLVM_ABI bool supportsScalableVectors() const
LLVM_ABI bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) const
Return true if the given instruction (assumed to be a memory access instruction) has a volatile varia...
LLVM_ABI bool isLegalMaskedCompressStore(Type *DataType, Align Alignment) const
Return true if the target supports masked compress store.
LLVM_ABI std::optional< unsigned > getMinPageSize() const
LLVM_ABI bool isFPVectorizationPotentiallyUnsafe() const
Indicate that it is potentially unsafe to automatically vectorize floating-point operations because t...
LLVM_ABI InstructionCost getInsertExtractValueCost(unsigned Opcode, TTI::TargetCostKind CostKind) const
LLVM_ABI bool shouldBuildRelLookupTables() const
Return true if lookup tables should be turned into relative lookup tables.
LLVM_ABI unsigned getStoreMinimumVF(unsigned VF, Type *ScalarMemTy, Type *ScalarValTy) const
LLVM_ABI std::optional< unsigned > getCacheSize(CacheLevel Level) const
LLVM_ABI std::optional< Value * > simplifyDemandedUseBitsIntrinsic(InstCombiner &IC, IntrinsicInst &II, APInt DemandedMask, KnownBits &Known, bool &KnownBitsComputed) const
Can be used to implement target-specific instruction combining.
LLVM_ABI bool isLegalAddScalableImmediate(int64_t Imm) const
Return true if adding the specified scalable immediate is legal, that is the target has add instructi...
LLVM_ABI bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx) const
Identifies if the vector form of the intrinsic has a scalar operand.
LLVM_ABI bool hasDivRemOp(Type *DataType, bool IsSigned) const
Return true if the target has a unified operation to calculate division and remainder.
LLVM_ABI 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.
LLVM_ABI bool enableInterleavedAccessVectorization() const
Enable matching of interleaved access groups.
LLVM_ABI unsigned getMinTripCountTailFoldingThreshold() const
LLVM_ABI InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, PartialReductionExtendKind OpAExtend, PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const
LLVM_ABI InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TargetCostKind CostKind) const
Estimate the cost of a given IR user when lowered.
LLVM_ABI unsigned getMaxInterleaveFactor(ElementCount VF) const
LLVM_ABI bool enableScalableVectorization() const
LLVM_ABI bool useFastCCForInternalCall(Function &F) const
Return true if the input function is internal, should use fastcc calling convention.
LLVM_ABI 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...
LLVM_ABI bool isNumRegsMajorCostOfLSR() const
Return true if LSR major cost is number of registers.
LLVM_ABI unsigned getInliningCostBenefitAnalysisSavingsMultiplier() const
LLVM_ABI bool isLegalMaskedVectorHistogram(Type *AddrType, Type *DataType) const
LLVM_ABI unsigned getGISelRematGlobalCost() const
LLVM_ABI unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const
MemIndexedMode
The type of load/store indexing.
LLVM_ABI bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace, MaskKind MaskKind=VariableOrConstantMask) const
Return true if the target supports masked load.
LLVM_ABI InstructionCost getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const
LLVM_ABI bool areInlineCompatible(const Function *Caller, const Function *Callee) const
LLVM_ABI bool useColdCCForColdCall(Function &F) const
Return true if the input function which is cold at all call sites, should use coldcc calling conventi...
LLVM_ABI InstructionCost getFPOpCost(Type *Ty) const
Return the expected cost of supporting the floating point operation of the specified type.
LLVM_ABI bool supportsTailCalls() const
If the target supports tail calls.
LLVM_ABI bool canMacroFuseCmp() const
Return true if the target can fuse a compare and branch.
LLVM_ABI bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
Query the target whether the specified address space cast from FromAS to ToAS is valid.
LLVM_ABI unsigned getNumberOfParts(Type *Tp) const
AddressingModeKind
Which addressing mode Loop Strength Reduction will try to generate.
@ AMK_PostIndexed
Prefer post-indexed addressing mode.
@ AMK_All
Consider all addressing modes.
@ AMK_PreIndexed
Prefer pre-indexed addressing mode.
@ AMK_None
Don't prefer any addressing mode.
LLVM_ABI 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,...
LLVM_ABI bool isTruncateFree(Type *Ty1, Type *Ty2) const
Return true if it's free to truncate a value of type Ty1 to type Ty2.
LLVM_ABI 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....
LLVM_ABI 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
LLVM_ABI bool preferPredicateOverEpilogue(TailFoldingInfo *TFI) const
Query the target whether it would be prefered to create a predicated vector loop, which can avoid the...
LLVM_ABI bool forceScalarizeMaskedScatter(VectorType *Type, Align Alignment) const
Return true if the target forces scalarizing of llvm.masked.scatter intrinsics.
LLVM_ABI 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...
static VectorInstrContext getVectorInstrContextHint(const Instruction *I)
Calculates a VectorInstrContext from I.
LLVM_ABI bool haveFastSqrt(Type *Ty) const
Return true if the hardware has a fast square-root instruction.
LLVM_ABI bool shouldExpandReduction(const IntrinsicInst *II) const
LLVM_ABI InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const
Estimate the overhead of scalarizing an instruction.
LLVM_ABI uint64_t getMaxMemIntrinsicInlineSizeThreshold() const
Returns the maximum memset / memcpy size in bytes that still makes it profitable to inline the call.
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.
LLVM_ABI APInt getFeatureMask(const Function &F) const
Returns a bitmask constructed from the target-features or fmv-features metadata of a function corresp...
LLVM_ABI void getPeelingPreferences(Loop *L, ScalarEvolution &SE, PeelingPreferences &PP) const
Get target-customized preferences for the generic loop peeling transformation.
LLVM_ABI InstructionCost getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency) const
LLVM_ABI 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.
@ 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.
LLVM_ABI InstructionCost getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy, unsigned Index, TTI::TargetCostKind CostKind) const
OperandValueKind
Additional information about an operand's possible values.
CacheLevel
The possible cache levels.
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:75
Base class of all SIMD vector types.
CallInst * Call
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ 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
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Length
Definition DWP.cpp:532
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
TargetTransformInfo TTI
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
LLVM_ABI ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
RecurKind
These are the kinds of recurrences that we support.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
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:1917
@ 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...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
InstructionUniformity
Enum describing how instructions behave with respect to uniformity and divergence,...
Definition Uniformity.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
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:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
Attributes of a target dependent hardware loop.
LLVM_ABI bool canAnalyze(LoopInfo &LI)
LLVM_ABI bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
Information about a load/store intrinsic defined by the target.
SmallVector< InterestingMemoryOperand, 1 > InterestingOperands
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.
OperandValueInfo mergeWith(const OperandValueInfo OpInfoY)
bool AllowPeeling
Allow peeling off loop iterations.
bool AllowLoopNestsPeeling
Allow peeling off loop iterations for loop nests.
bool PeelLast
Peel off the last PeelCount loop iterations.
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.
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
Disable runtime unrolling by default for vectorized loops.
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...
bool RuntimeUnrollMultiExit
Allow runtime unrolling multi-exit loops.
unsigned SCEVExpansionBudget
Don't allow runtime unrolling if expanding the trip count takes more than SCEVExpansionBudget.
bool AddAdditionalAccumulators
Allow unrolling to add parallel reduction phis.
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)