LLVM 23.0.0git
TargetLowering.h
Go to the documentation of this file.
1//===- llvm/CodeGen/TargetLowering.h - Target Lowering Info -----*- 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///
9/// \file
10/// This file describes how to lower LLVM code to machine code. This has two
11/// main components:
12///
13/// 1. Which ValueTypes are natively supported by the target.
14/// 2. Which operations are supported for supported ValueTypes.
15/// 3. Cost thresholds for alternative implementations of certain operations.
16///
17/// In addition it has a few other components, like information about FP
18/// immediates.
19///
20//===----------------------------------------------------------------------===//
21
22#ifndef LLVM_CODEGEN_TARGETLOWERING_H
23#define LLVM_CODEGEN_TARGETLOWERING_H
24
25#include "llvm/ADT/APInt.h"
26#include "llvm/ADT/ArrayRef.h"
27#include "llvm/ADT/DenseMap.h"
29#include "llvm/ADT/StringRef.h"
41#include "llvm/IR/Attributes.h"
42#include "llvm/IR/CallingConv.h"
43#include "llvm/IR/DataLayout.h"
45#include "llvm/IR/Function.h"
46#include "llvm/IR/InlineAsm.h"
47#include "llvm/IR/Instruction.h"
50#include "llvm/IR/Type.h"
57#include <algorithm>
58#include <cassert>
59#include <climits>
60#include <cstdint>
61#include <map>
62#include <string>
63#include <utility>
64#include <vector>
65
66namespace llvm {
67
68class AssumptionCache;
69class CCState;
70class CCValAssign;
73class Constant;
74class FastISel;
76class GlobalValue;
77class Loop;
79class IntrinsicInst;
80class IRBuilderBase;
81struct KnownBits;
82class LLVMContext;
84class MachineFunction;
85class MachineInstr;
87class MachineLoop;
89class MCContext;
90class MCExpr;
91class Module;
94class TargetMachine;
98class Value;
99class VPIntrinsic;
100
101namespace Sched {
102
104 None, // No preference
105 Source, // Follow source order.
106 RegPressure, // Scheduling for lowest register pressure.
107 Hybrid, // Scheduling for both latency and register pressure.
108 ILP, // Scheduling for ILP in low register pressure mode.
109 VLIW, // Scheduling for VLIW targets.
110 Fast, // Fast suboptimal list scheduling
111 Linearize, // Linearize DAG, no scheduling
112 Last = Linearize // Marker for the last Sched::Preference
113};
114
115} // end namespace Sched
116
117// MemOp models a memory operation, either memset or memcpy/memmove.
118struct MemOp {
119private:
120 // Shared
121 uint64_t Size;
122 bool DstAlignCanChange; // true if destination alignment can satisfy any
123 // constraint.
124 Align DstAlign; // Specified alignment of the memory operation.
125
126 bool AllowOverlap;
127 // memset only
128 bool IsMemset; // If setthis memory operation is a memset.
129 bool ZeroMemset; // If set clears out memory with zeros.
130 // memcpy only
131 bool MemcpyStrSrc; // Indicates whether the memcpy source is an in-register
132 // constant so it does not need to be loaded.
133 Align SrcAlign; // Inferred alignment of the source or default value if the
134 // memory operation does not need to load the value.
135public:
136 static MemOp Copy(uint64_t Size, bool DstAlignCanChange, Align DstAlign,
137 Align SrcAlign, bool IsVolatile,
138 bool MemcpyStrSrc = false) {
139 MemOp Op;
140 Op.Size = Size;
141 Op.DstAlignCanChange = DstAlignCanChange;
142 Op.DstAlign = DstAlign;
143 Op.AllowOverlap = !IsVolatile;
144 Op.IsMemset = false;
145 Op.ZeroMemset = false;
146 Op.MemcpyStrSrc = MemcpyStrSrc;
147 Op.SrcAlign = SrcAlign;
148 return Op;
149 }
150
151 static MemOp Set(uint64_t Size, bool DstAlignCanChange, Align DstAlign,
152 bool IsZeroMemset, bool IsVolatile) {
153 MemOp Op;
154 Op.Size = Size;
155 Op.DstAlignCanChange = DstAlignCanChange;
156 Op.DstAlign = DstAlign;
157 Op.AllowOverlap = !IsVolatile;
158 Op.IsMemset = true;
159 Op.ZeroMemset = IsZeroMemset;
160 Op.MemcpyStrSrc = false;
161 return Op;
162 }
163
164 uint64_t size() const { return Size; }
166 assert(!DstAlignCanChange);
167 return DstAlign;
168 }
169 bool isFixedDstAlign() const { return !DstAlignCanChange; }
170 bool allowOverlap() const { return AllowOverlap; }
171 bool isMemset() const { return IsMemset; }
172 bool isMemcpy() const { return !IsMemset; }
174 return isMemcpy() && !DstAlignCanChange;
175 }
176 bool isZeroMemset() const { return isMemset() && ZeroMemset; }
177 bool isMemcpyStrSrc() const {
178 assert(isMemcpy() && "Must be a memcpy");
179 return MemcpyStrSrc;
180 }
182 assert(isMemcpy() && "Must be a memcpy");
183 return SrcAlign;
184 }
185 bool isSrcAligned(Align AlignCheck) const {
186 return isMemset() || llvm::isAligned(AlignCheck, SrcAlign.value());
187 }
188 bool isDstAligned(Align AlignCheck) const {
189 return DstAlignCanChange || llvm::isAligned(AlignCheck, DstAlign.value());
190 }
191 bool isAligned(Align AlignCheck) const {
192 return isSrcAligned(AlignCheck) && isDstAligned(AlignCheck);
193 }
194};
195
196/// This base class for TargetLowering contains the SelectionDAG-independent
197/// parts that can be used from the rest of CodeGen.
199public:
200 /// This enum indicates whether operations are valid for a target, and if not,
201 /// what action should be used to make them valid.
203 Legal, // The target natively supports this operation.
204 Promote, // This operation should be executed in a larger type.
205 Expand, // Try to expand this to other ops, otherwise use a libcall.
206 LibCall, // Don't try to expand this to other ops, always use a libcall.
207 Custom // Use the LowerOperation hook to implement custom lowering.
208 };
209
210 /// This enum indicates whether a types are legal for a target, and if not,
211 /// what action should be used to make them valid.
213 TypeLegal, // The target natively supports this type.
214 TypePromoteInteger, // Replace this integer with a larger one.
215 TypeExpandInteger, // Split this integer into two of half the size.
216 TypeSoftenFloat, // Convert this float to a same size integer type.
217 TypeExpandFloat, // Split this float into two of half the size.
218 TypeScalarizeVector, // Replace this one-element vector with its element.
219 TypeSplitVector, // Split this vector into two of half the size.
220 TypeWidenVector, // This vector should be widened into a larger vector.
221 TypePromoteFloat, // Replace this float with a larger one.
222 TypeSoftPromoteHalf, // Soften half to i16 and use float to do arithmetic.
223 TypeScalarizeScalableVector, // This action is explicitly left unimplemented.
224 // While it is theoretically possible to
225 // legalize operations on scalable types with a
226 // loop that handles the vscale * #lanes of the
227 // vector, this is non-trivial at SelectionDAG
228 // level and these types are better to be
229 // widened or promoted.
230 };
231
232 /// LegalizeKind holds the legalization kind that needs to happen to EVT
233 /// in order to type-legalize it.
234 using LegalizeKind = std::pair<LegalizeTypeAction, EVT>;
235
236 /// Enum that describes how the target represents true/false values.
238 UndefinedBooleanContent, // Only bit 0 counts, the rest can hold garbage.
239 ZeroOrOneBooleanContent, // All bits zero except for bit 0.
240 ZeroOrNegativeOneBooleanContent // All bits equal to bit 0.
241 };
242
243 /// Enum that describes what type of support for selects the target has.
245 ScalarValSelect, // The target supports scalar selects (ex: cmov).
246 ScalarCondVectorVal, // The target supports selects with a scalar condition
247 // and vector values (ex: cmov).
248 VectorMaskSelect // The target supports vector selects with a vector
249 // mask (ex: x86 blends).
250 };
251
252 /// Enum that specifies what an atomic load/AtomicRMWInst is expanded
253 /// to, if at all. Exists because different targets have different levels of
254 /// support for these atomic instructions, and also have different options
255 /// w.r.t. what they should expand to.
257 None, // Don't expand the instruction.
258 CastToInteger, // Cast the atomic instruction to another type, e.g. from
259 // floating-point to integer type.
260 LLSC, // Expand the instruction into loadlinked/storeconditional; used
261 // by ARM/AArch64/PowerPC.
262 LLOnly, // Expand the (load) instruction into just a load-linked, which has
263 // greater atomic guarantees than a normal load.
264 CmpXChg, // Expand the instruction into cmpxchg; used by at least X86.
265 MaskedIntrinsic, // Use a target-specific intrinsic for the LL/SC loop.
266 BitTestIntrinsic, // Use a target-specific intrinsic for special bit
267 // operations; used by X86.
268 CmpArithIntrinsic, // Use a target-specific intrinsic for special compare
269 // operations; used by X86.
270 Expand, // Generic expansion in terms of other atomic operations.
271 CustomExpand, // Custom target-specific expansion using TLI hooks.
272
273 // Rewrite to a non-atomic form for use in a known non-preemptible
274 // environment.
276 };
277
278 /// Enum that specifies when a multiplication should be expanded.
279 enum class MulExpansionKind {
280 Always, // Always expand the instruction.
281 OnlyLegalOrCustom, // Only expand when the resulting instructions are legal
282 // or custom.
283 };
284
285 /// Enum that specifies when a float negation is beneficial.
286 enum class NegatibleCost {
287 Cheaper = 0, // Negated expression is cheaper.
288 Neutral = 1, // Negated expression has the same cost.
289 Expensive = 2 // Negated expression is more expensive.
290 };
291
292 /// Enum of different potentially desirable ways to fold (and/or (setcc ...),
293 /// (setcc ...)).
295 None = 0, // No fold is preferable.
296 AddAnd = 1, // Fold with `Add` op and `And` op is preferable.
297 NotAnd = 2, // Fold with `Not` op and `And` op is preferable.
298 ABS = 4, // Fold with `llvm.abs` op is preferable.
299 };
300
302 public:
305 /// Original unlegalized argument type.
307 /// Same as OrigTy, or partially legalized for soft float libcalls.
309 bool IsSExt : 1;
310 bool IsZExt : 1;
311 bool IsNoExt : 1;
312 bool IsInReg : 1;
313 bool IsSRet : 1;
314 bool IsNest : 1;
315 bool IsByVal : 1;
316 bool IsByRef : 1;
317 bool IsInAlloca : 1;
319 bool IsReturned : 1;
320 bool IsSwiftSelf : 1;
321 bool IsSwiftAsync : 1;
322 bool IsSwiftError : 1;
324 MaybeAlign Alignment = std::nullopt;
325 Type *IndirectType = nullptr;
326
333
336
338
339 LLVM_ABI void setAttributes(const CallBase *Call, unsigned ArgIdx);
340 };
341 using ArgListTy = std::vector<ArgListEntry>;
342
344 switch (Content) {
346 // Extend by adding rubbish bits.
347 return ISD::ANY_EXTEND;
349 // Extend by adding zero bits.
350 return ISD::ZERO_EXTEND;
352 // Extend by copying the sign bit.
353 return ISD::SIGN_EXTEND;
354 }
355 llvm_unreachable("Invalid content kind");
356 }
357
358 explicit TargetLoweringBase(const TargetMachine &TM,
359 const TargetSubtargetInfo &STI);
363
364 /// Return true if the target support strict float operation
365 bool isStrictFPEnabled() const {
366 return IsStrictFPEnabled;
367 }
368
369protected:
370 /// Initialize all of the actions to default values.
371 void initActions();
372
373public:
374 const TargetMachine &getTargetMachine() const { return TM; }
375
376 virtual bool useSoftFloat() const { return false; }
377
378 /// Return the pointer type for the given address space, defaults to
379 /// the pointer type from the data layout.
380 /// FIXME: The default needs to be removed once all the code is updated.
381 virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS = 0) const {
382 return MVT::getIntegerVT(DL.getPointerSizeInBits(AS));
383 }
384
385 /// Return the in-memory pointer type for the given address space, defaults to
386 /// the pointer type from the data layout.
387 /// FIXME: The default needs to be removed once all the code is updated.
388 virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS = 0) const {
389 return MVT::getIntegerVT(DL.getPointerSizeInBits(AS));
390 }
391
392 /// Return the type for frame index, which is determined by
393 /// the alloca address space specified through the data layout.
395 return getPointerTy(DL, DL.getAllocaAddrSpace());
396 }
397
398 /// Return the type for code pointers, which is determined by the program
399 /// address space specified through the data layout.
401 return getPointerTy(DL, DL.getProgramAddressSpace());
402 }
403
404 /// Return the type for operands of fence.
405 /// TODO: Let fence operands be of i32 type and remove this.
406 virtual MVT getFenceOperandTy(const DataLayout &DL) const {
407 return getPointerTy(DL);
408 }
409
410 /// Return the type to use for a scalar shift opcode, given the shifted amount
411 /// type. Targets should return a legal type if the input type is legal.
412 /// Targets can return a type that is too small if the input type is illegal.
413 virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const;
414
415 /// Returns the type for the shift amount of a shift opcode. For vectors,
416 /// returns the input type. For scalars, calls getScalarShiftAmountTy.
417 /// If getScalarShiftAmountTy type cannot represent all possible shift
418 /// amounts, returns MVT::i32.
419 EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL) const;
420
421 /// Return the preferred type to use for a shift opcode, given the shifted
422 /// amount type is \p ShiftValueTy.
424 virtual LLT getPreferredShiftAmountTy(LLT ShiftValueTy) const {
425 return ShiftValueTy;
426 }
427
428 /// Returns the type to be used for the index operand vector operations. By
429 /// default we assume it will have the same size as an address space 0
430 /// pointer.
431 virtual unsigned getVectorIdxWidth(const DataLayout &DL) const {
432 return DL.getPointerSizeInBits(0);
433 }
434
435 /// Returns the type to be used for the index operand of:
436 /// ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT,
437 /// ISD::INSERT_SUBVECTOR, and ISD::EXTRACT_SUBVECTOR
441
442 /// Returns the type to be used for the index operand of:
443 /// G_INSERT_VECTOR_ELT, G_EXTRACT_VECTOR_ELT,
444 /// G_INSERT_SUBVECTOR, and G_EXTRACT_SUBVECTOR
447 }
448
449 /// Returns the type to be used for the EVL/AVL operand of VP nodes:
450 /// ISD::VP_ADD, ISD::VP_SUB, etc. It must be a legal scalar integer type,
451 /// and must be at least as large as i32. The EVL is implicitly zero-extended
452 /// to any larger type.
453 virtual MVT getVPExplicitVectorLengthTy() const { return MVT::i32; }
454
455 /// This callback is used to inspect load/store instructions and add
456 /// target-specific MachineMemOperand flags to them. The default
457 /// implementation does nothing.
461
462 /// This callback is used to inspect load/store SDNode.
463 /// The default implementation does nothing.
468
470 getLoadMemOperandFlags(const LoadInst &LI, const DataLayout &DL,
471 AssumptionCache *AC = nullptr,
472 const TargetLibraryInfo *LibInfo = nullptr) const;
473 MachineMemOperand::Flags getStoreMemOperandFlags(const StoreInst &SI,
474 const DataLayout &DL) const;
475 MachineMemOperand::Flags getAtomicMemOperandFlags(const Instruction &AI,
476 const DataLayout &DL) const;
478 getVPIntrinsicMemOperandFlags(const VPIntrinsic &VPIntrin) const;
479
480 virtual bool isSelectSupported(SelectSupportKind /*kind*/) const {
481 return true;
482 }
483
484 /// Return true if the @llvm.get.active.lane.mask intrinsic should be expanded
485 /// using generic code in SelectionDAGBuilder.
486 virtual bool shouldExpandGetActiveLaneMask(EVT VT, EVT OpVT) const {
487 return true;
488 }
489
490 virtual bool shouldExpandGetVectorLength(EVT CountVT, unsigned VF,
491 bool IsScalable) const {
492 return true;
493 }
494
495 /// Return true if the @llvm.experimental.cttz.elts intrinsic should be
496 /// expanded using generic code in SelectionDAGBuilder.
497 virtual bool shouldExpandCttzElements(EVT VT) const { return true; }
498
499 /// Return the minimum number of bits required to hold the maximum possible
500 /// number of trailing zero vector elements.
501 unsigned getBitWidthForCttzElements(Type *RetTy, ElementCount EC,
502 bool ZeroIsPoison,
503 const ConstantRange *VScaleRange) const;
504
505 /// Return true if the @llvm.experimental.vector.match intrinsic should be
506 /// expanded for vector type `VT' and search size `SearchSize' using generic
507 /// code in SelectionDAGBuilder.
508 virtual bool shouldExpandVectorMatch(EVT VT, unsigned SearchSize) const {
509 return true;
510 }
511
512 // Return true if op(vecreduce(x), vecreduce(y)) should be reassociated to
513 // vecreduce(op(x, y)) for the reduction opcode RedOpc.
514 virtual bool shouldReassociateReduction(unsigned RedOpc, EVT VT) const {
515 return true;
516 }
517
518 /// Return true if it is profitable to convert a select of FP constants into
519 /// a constant pool load whose address depends on the select condition. The
520 /// parameter may be used to differentiate a select with FP compare from
521 /// integer compare.
522 virtual bool reduceSelectOfFPConstantLoads(EVT CmpOpVT) const {
523 return true;
524 }
525
526 /// Does the target have multiple (allocatable) condition registers that
527 /// can be used to store the results of comparisons for use by selects
528 /// and conditional branches. With multiple condition registers, the code
529 /// generator will not aggressively sink comparisons into the blocks of their
530 /// users.
531 virtual bool hasMultipleConditionRegisters(EVT VT) const { return false; }
532
533 /// Return true if the target has BitExtract instructions.
534 bool hasExtractBitsInsn() const { return HasExtractBitsInsn; }
535
536 /// Return the preferred vector type legalization action.
539 // The default action for one element vectors is to scalarize
541 return TypeScalarizeVector;
542 // The default action for an odd-width vector is to widen.
543 if (!VT.isPow2VectorType())
544 return TypeWidenVector;
545 // The default action for other vectors is to promote
546 return TypePromoteInteger;
547 }
548
549 /// Warning: this option is problem-prone and tends to introduce
550 /// float miscompilations:
551 ///
552 /// - https://github.com/llvm/llvm-project/issues/97975
553 /// - https://github.com/llvm/llvm-project/issues/97981
554 ///
555 /// It should not be overridden to `false` except for special cases.
556 ///
557 /// Return true if the half type should be promoted using soft promotion rules
558 /// where each operation is promoted to f32 individually, then converted to
559 /// fp16. The default behavior is to promote chains of operations, keeping
560 /// intermediate results in f32 precision and range.
561 virtual bool softPromoteHalfType() const { return true; }
562
563 // Return true if, for soft-promoted half, the half type should be passed to
564 // and returned from functions as f32. The default behavior is to pass as
565 // i16. If soft-promoted half is not used, this function is ignored and
566 // values are always passed and returned as f32.
567 virtual bool useFPRegsForHalfType() const { return false; }
568
569 // There are two general methods for expanding a BUILD_VECTOR node:
570 // 1. Use SCALAR_TO_VECTOR on the defined scalar values and then shuffle
571 // them together.
572 // 2. Build the vector on the stack and then load it.
573 // If this function returns true, then method (1) will be used, subject to
574 // the constraint that all of the necessary shuffles are legal (as determined
575 // by isShuffleMaskLegal). If this function returns false, then method (2) is
576 // always used. The vector type, and the number of defined values, are
577 // provided.
578 virtual bool
580 unsigned DefinedValues) const {
581 return DefinedValues < 3;
582 }
583
584 /// Return true if integer divide is usually cheaper than a sequence of
585 /// several shifts, adds, and multiplies for this target.
586 /// The definition of "cheaper" may depend on whether we're optimizing
587 /// for speed or for size.
588 virtual bool isIntDivCheap(EVT VT, AttributeList Attr) const { return false; }
589
590 /// Return true if the target can handle a standalone remainder operation.
591 virtual bool hasStandaloneRem(EVT VT) const {
592 return true;
593 }
594
595 /// Return true if SQRT(X) shouldn't be replaced with X*RSQRT(X).
596 virtual bool isFsqrtCheap(SDValue X, SelectionDAG &DAG) const {
597 // Default behavior is to replace SQRT(X) with X*RSQRT(X).
598 return false;
599 }
600
601 /// Reciprocal estimate status values used by the functions below.
606 };
607
608 /// Return a ReciprocalEstimate enum value for a square root of the given type
609 /// based on the function's attributes. If the operation is not overridden by
610 /// the function's attributes, "Unspecified" is returned and target defaults
611 /// are expected to be used for instruction selection.
612 int getRecipEstimateSqrtEnabled(EVT VT, MachineFunction &MF) const;
613
614 /// Return a ReciprocalEstimate enum value for a division of the given type
615 /// based on the function's attributes. If the operation is not overridden by
616 /// the function's attributes, "Unspecified" is returned and target defaults
617 /// are expected to be used for instruction selection.
618 int getRecipEstimateDivEnabled(EVT VT, MachineFunction &MF) const;
619
620 /// Return the refinement step count for a square root of the given type based
621 /// on the function's attributes. If the operation is not overridden by
622 /// the function's attributes, "Unspecified" is returned and target defaults
623 /// are expected to be used for instruction selection.
624 int getSqrtRefinementSteps(EVT VT, MachineFunction &MF) const;
625
626 /// Return the refinement step count for a division of the given type based
627 /// on the function's attributes. If the operation is not overridden by
628 /// the function's attributes, "Unspecified" is returned and target defaults
629 /// are expected to be used for instruction selection.
630 int getDivRefinementSteps(EVT VT, MachineFunction &MF) const;
631
632 /// Returns true if target has indicated at least one type should be bypassed.
633 bool isSlowDivBypassed() const { return !BypassSlowDivWidths.empty(); }
634
635 /// Returns map of slow types for division or remainder with corresponding
636 /// fast types
638 return BypassSlowDivWidths;
639 }
640
641 /// Return true only if vscale must be a power of two.
642 virtual bool isVScaleKnownToBeAPowerOfTwo() const { return false; }
643
644 /// Return true if Flow Control is an expensive operation that should be
645 /// avoided.
646 bool isJumpExpensive() const { return JumpIsExpensive; }
647
648 // Costs parameters used by
649 // SelectionDAGBuilder::shouldKeepJumpConditionsTogether.
650 // shouldKeepJumpConditionsTogether will use these parameter value to
651 // determine if two conditions in the form `br (and/or cond1, cond2)` should
652 // be split into two branches or left as one.
653 //
654 // BaseCost is the cost threshold (in latency). If the estimated latency of
655 // computing both `cond1` and `cond2` is below the cost of just computing
656 // `cond1` + BaseCost, the two conditions will be kept together. Otherwise
657 // they will be split.
658 //
659 // LikelyBias increases BaseCost if branch probability info indicates that it
660 // is likely that both `cond1` and `cond2` will be computed.
661 //
662 // UnlikelyBias decreases BaseCost if branch probability info indicates that
663 // it is likely that both `cond1` and `cond2` will be computed.
664 //
665 // Set any field to -1 to make it ignored (setting BaseCost to -1 results in
666 // `shouldKeepJumpConditionsTogether` always returning false).
672 // Return params for deciding if we should keep two branch conditions merged
673 // or split them into two separate branches.
674 // Arg0: The binary op joining the two conditions (and/or).
675 // Arg1: The first condition (cond1)
676 // Arg2: The second condition (cond2)
677 virtual CondMergingParams
679 const Value *) const {
680 // -1 will always result in splitting.
681 return {-1, -1, -1};
682 }
683
684 /// Return true if selects are only cheaper than branches if the branch is
685 /// unlikely to be predicted right.
689
690 virtual bool fallBackToDAGISel(const Instruction &Inst) const {
691 return false;
692 }
693
694 /// Return true if the following transform is beneficial:
695 /// fold (conv (load x)) -> (load (conv*)x)
696 /// On architectures that don't natively support some vector loads
697 /// efficiently, casting the load to a smaller vector of larger types and
698 /// loading is more efficient, however, this can be undone by optimizations in
699 /// dag combiner.
700 virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT,
701 const SelectionDAG &DAG,
702 const MachineMemOperand &MMO) const;
703
704 /// Return true if the following transform is beneficial:
705 /// (store (y (conv x)), y*)) -> (store x, (x*))
706 virtual bool isStoreBitCastBeneficial(EVT StoreVT, EVT BitcastVT,
707 const SelectionDAG &DAG,
708 const MachineMemOperand &MMO) const {
709 // Default to the same logic as loads.
710 return isLoadBitCastBeneficial(StoreVT, BitcastVT, DAG, MMO);
711 }
712
713 /// Return true if it is expected to be cheaper to do a store of vector
714 /// constant with the given size and type for the address space than to
715 /// store the individual scalar element constants.
716 virtual bool storeOfVectorConstantIsCheap(bool IsZero, EVT MemVT,
717 unsigned NumElem,
718 unsigned AddrSpace) const {
719 return IsZero;
720 }
721
722 /// Allow store merging for the specified type after legalization in addition
723 /// to before legalization. This may transform stores that do not exist
724 /// earlier (for example, stores created from intrinsics).
725 virtual bool mergeStoresAfterLegalization(EVT MemVT) const {
726 return true;
727 }
728
729 /// Returns if it's reasonable to merge stores to MemVT size.
730 virtual bool canMergeStoresTo(unsigned AS, EVT MemVT,
731 const MachineFunction &MF) const {
732 return true;
733 }
734
735 /// Return true if it is cheap to speculate a call to intrinsic cttz.
736 virtual bool isCheapToSpeculateCttz(Type *Ty) const {
737 return false;
738 }
739
740 /// Return true if it is cheap to speculate a call to intrinsic ctlz.
741 virtual bool isCheapToSpeculateCtlz(Type *Ty) const {
742 return false;
743 }
744
745 /// Return true if ctlz instruction is fast.
746 virtual bool isCtlzFast() const {
747 return false;
748 }
749
750 /// Return true if ctpop instruction is fast.
751 virtual bool isCtpopFast(EVT VT) const {
752 return isOperationLegal(ISD::CTPOP, VT);
753 }
754
755 /// Return the maximum number of "x & (x - 1)" operations that can be done
756 /// instead of deferring to a custom CTPOP.
757 virtual unsigned getCustomCtpopCost(EVT VT, ISD::CondCode Cond) const {
758 return 1;
759 }
760
761 /// Return true if instruction generated for equality comparison is folded
762 /// with instruction generated for signed comparison.
763 virtual bool isEqualityCmpFoldedWithSignedCmp() const { return true; }
764
765 /// Return true if the heuristic to prefer icmp eq zero should be used in code
766 /// gen prepare.
767 virtual bool preferZeroCompareBranch() const { return false; }
768
769 /// Return true if it is cheaper to split the store of a merged int val
770 /// from a pair of smaller values into multiple stores.
771 virtual bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const {
772 return false;
773 }
774
775 /// Return if the target supports combining a
776 /// chain like:
777 /// \code
778 /// %andResult = and %val1, #mask
779 /// %icmpResult = icmp %andResult, 0
780 /// \endcode
781 /// into a single machine instruction of a form like:
782 /// \code
783 /// cc = test %register, #mask
784 /// \endcode
785 virtual bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const {
786 return false;
787 }
788
789 /// Return true if it is valid to merge the TargetMMOFlags in two SDNodes.
790 virtual bool
792 const MemSDNode &NodeY) const {
793 return true;
794 }
795
796 /// Use bitwise logic to make pairs of compares more efficient. For example:
797 /// and (seteq A, B), (seteq C, D) --> seteq (or (xor A, B), (xor C, D)), 0
798 /// This should be true when it takes more than one instruction to lower
799 /// setcc (cmp+set on x86 scalar), when bitwise ops are faster than logic on
800 /// condition bits (crand on PowerPC), and/or when reducing cmp+br is a win.
801 virtual bool convertSetCCLogicToBitwiseLogic(EVT VT) const {
802 return false;
803 }
804
805 /// Return the preferred operand type if the target has a quick way to compare
806 /// integer values of the given size. Assume that any legal integer type can
807 /// be compared efficiently. Targets may override this to allow illegal wide
808 /// types to return a vector type if there is support to compare that type.
809 virtual MVT hasFastEqualityCompare(unsigned NumBits) const {
810 MVT VT = MVT::getIntegerVT(NumBits);
812 }
813
814 /// Return true if the target should transform:
815 /// (X & Y) == Y ---> (~X & Y) == 0
816 /// (X & Y) != Y ---> (~X & Y) != 0
817 ///
818 /// This may be profitable if the target has a bitwise and-not operation that
819 /// sets comparison flags. A target may want to limit the transformation based
820 /// on the type of Y or if Y is a constant.
821 ///
822 /// Note that the transform will not occur if Y is known to be a power-of-2
823 /// because a mask and compare of a single bit can be handled by inverting the
824 /// predicate, for example:
825 /// (X & 8) == 8 ---> (X & 8) != 0
826 virtual bool hasAndNotCompare(SDValue Y) const {
827 return false;
828 }
829
830 /// Return true if the target has a bitwise and-not operation:
831 /// X = ~A & B
832 /// This can be used to simplify select or other instructions.
833 virtual bool hasAndNot(SDValue X) const {
834 // If the target has the more complex version of this operation, assume that
835 // it has this operation too.
836 return hasAndNotCompare(X);
837 }
838
839 /// Return true if the target has a bit-test instruction:
840 /// (X & (1 << Y)) ==/!= 0
841 /// This knowledge can be used to prevent breaking the pattern,
842 /// or creating it if it could be recognized.
843 virtual bool hasBitTest(SDValue X, SDValue Y) const { return false; }
844
845 /// There are two ways to clear extreme bits (either low or high):
846 /// Mask: x & (-1 << y) (the instcombine canonical form)
847 /// Shifts: x >> y << y
848 /// Return true if the variant with 2 variable shifts is preferred.
849 /// Return false if there is no preference.
851 // By default, let's assume that no one prefers shifts.
852 return false;
853 }
854
855 /// Return true if it is profitable to fold a pair of shifts into a mask.
856 /// This is usually true on most targets. But some targets, like Thumb1,
857 /// have immediate shift instructions, but no immediate "and" instruction;
858 /// this makes the fold unprofitable.
859 virtual bool shouldFoldConstantShiftPairToMask(const SDNode *N) const {
860 return true;
861 }
862
863 /// Should we tranform the IR-optimal check for whether given truncation
864 /// down into KeptBits would be truncating or not:
865 /// (add %x, (1 << (KeptBits-1))) srccond (1 << KeptBits)
866 /// Into it's more traditional form:
867 /// ((%x << C) a>> C) dstcond %x
868 /// Return true if we should transform.
869 /// Return false if there is no preference.
871 unsigned KeptBits) const {
872 // By default, let's assume that no one prefers shifts.
873 return false;
874 }
875
876 /// Given the pattern
877 /// (X & (C l>>/<< Y)) ==/!= 0
878 /// return true if it should be transformed into:
879 /// ((X <</l>> Y) & C) ==/!= 0
880 /// WARNING: if 'X' is a constant, the fold may deadlock!
881 /// FIXME: we could avoid passing XC, but we can't use isConstOrConstSplat()
882 /// here because it can end up being not linked in.
885 unsigned OldShiftOpcode, unsigned NewShiftOpcode,
886 SelectionDAG &DAG) const {
887 if (hasBitTest(X, Y)) {
888 // One interesting pattern that we'd want to form is 'bit test':
889 // ((1 << Y) & C) ==/!= 0
890 // But we also need to be careful not to try to reverse that fold.
891
892 // Is this '1 << Y' ?
893 if (OldShiftOpcode == ISD::SHL && CC->isOne())
894 return false; // Keep the 'bit test' pattern.
895
896 // Will it be '1 << Y' after the transform ?
897 if (XC && NewShiftOpcode == ISD::SHL && XC->isOne())
898 return true; // Do form the 'bit test' pattern.
899 }
900
901 // If 'X' is a constant, and we transform, then we will immediately
902 // try to undo the fold, thus causing endless combine loop.
903 // So by default, let's assume everyone prefers the fold
904 // iff 'X' is not a constant.
905 return !XC;
906 }
907
908 // Return true if its desirable to perform the following transform:
909 // (fmul C, (uitofp Pow2))
910 // -> (bitcast_to_FP (add (bitcast_to_INT C), Log2(Pow2) << mantissa))
911 // (fdiv C, (uitofp Pow2))
912 // -> (bitcast_to_FP (sub (bitcast_to_INT C), Log2(Pow2) << mantissa))
913 //
914 // This is only queried after we have verified the transform will be bitwise
915 // equals.
916 //
917 // SDNode *N : The FDiv/FMul node we want to transform.
918 // SDValue FPConst: The Float constant operand in `N`.
919 // SDValue IntPow2: The Integer power of 2 operand in `N`.
921 SDValue IntPow2) const {
922 // Default to avoiding fdiv which is often very expensive.
923 return N->getOpcode() == ISD::FDIV;
924 }
925
926 // Given:
927 // (icmp eq/ne (and X, C0), (shift X, C1))
928 // or
929 // (icmp eq/ne X, (rotate X, CPow2))
930
931 // If C0 is a mask or shifted mask and the shift amt (C1) isolates the
932 // remaining bits (i.e something like `(x64 & UINT32_MAX) == (x64 >> 32)`)
933 // Do we prefer the shift to be shift-right, shift-left, or rotate.
934 // Note: Its only valid to convert the rotate version to the shift version iff
935 // the shift-amt (`C1`) is a power of 2 (including 0).
936 // If ShiftOpc (current Opcode) is returned, do nothing.
938 EVT VT, unsigned ShiftOpc, bool MayTransformRotate,
939 const APInt &ShiftOrRotateAmt,
940 const std::optional<APInt> &AndMask) const {
941 return ShiftOpc;
942 }
943
944 /// These two forms are equivalent:
945 /// sub %y, (xor %x, -1)
946 /// add (add %x, 1), %y
947 /// The variant with two add's is IR-canonical.
948 /// Some targets may prefer one to the other.
949 virtual bool preferIncOfAddToSubOfNot(EVT VT) const {
950 // By default, let's assume that everyone prefers the form with two add's.
951 return true;
952 }
953
954 // By default prefer folding (abs (sub nsw x, y)) -> abds(x, y). Some targets
955 // may want to avoid this to prevent loss of sub_nsw pattern.
956 virtual bool preferABDSToABSWithNSW(EVT VT) const {
957 return true;
958 }
959
960 // Return true if the target wants to transform Op(Splat(X)) -> Splat(Op(X))
961 virtual bool preferScalarizeSplat(SDNode *N) const { return true; }
962
963 // Return true if the target wants to transform:
964 // (TruncVT truncate(sext_in_reg(VT X, ExtVT))
965 // -> (TruncVT sext_in_reg(truncate(VT X), ExtVT))
966 // Some targets might prefer pre-sextinreg to improve truncation/saturation.
967 virtual bool preferSextInRegOfTruncate(EVT TruncVT, EVT VT, EVT ExtVT) const {
968 return true;
969 }
970
971 /// Return true if the target wants to use the optimization that
972 /// turns ext(promotableInst1(...(promotableInstN(load)))) into
973 /// promotedInst1(...(promotedInstN(ext(load)))).
975
976 /// Return true if the target can combine store(extractelement VectorTy,
977 /// Idx).
978 /// \p Cost[out] gives the cost of that transformation when this is true.
979 virtual bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx,
980 unsigned &Cost) const {
981 return false;
982 }
983
984 /// Return true if the target shall perform extract vector element and store
985 /// given that the vector is known to be splat of constant.
986 /// \p Index[out] gives the index of the vector element to be extracted when
987 /// this is true.
989 Type *VectorTy, unsigned ElemSizeInBits, unsigned &Index) const {
990 return false;
991 }
992
993 /// Return true if inserting a scalar into a variable element of an undef
994 /// vector is more efficiently handled by splatting the scalar instead.
995 virtual bool shouldSplatInsEltVarIndex(EVT) const {
996 return false;
997 }
998
999 /// Return true if target always benefits from combining into FMA for a
1000 /// given value type. This must typically return false on targets where FMA
1001 /// takes more cycles to execute than FADD.
1002 virtual bool enableAggressiveFMAFusion(EVT VT) const { return false; }
1003
1004 /// Return true if target always benefits from combining into FMA for a
1005 /// given value type. This must typically return false on targets where FMA
1006 /// takes more cycles to execute than FADD.
1007 virtual bool enableAggressiveFMAFusion(LLT Ty) const { return false; }
1008
1009 /// Return the ValueType of the result of SETCC operations.
1010 virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
1011 EVT VT) const;
1012
1013 /// Return the ValueType for comparison libcalls. Comparison libcalls include
1014 /// floating point comparison calls, and Ordered/Unordered check calls on
1015 /// floating point numbers.
1016 virtual
1017 MVT::SimpleValueType getCmpLibcallReturnType() const;
1018
1019 /// For targets without i1 registers, this gives the nature of the high-bits
1020 /// of boolean values held in types wider than i1.
1021 ///
1022 /// "Boolean values" are special true/false values produced by nodes like
1023 /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND.
1024 /// Not to be confused with general values promoted from i1. Some cpus
1025 /// distinguish between vectors of boolean and scalars; the isVec parameter
1026 /// selects between the two kinds. For example on X86 a scalar boolean should
1027 /// be zero extended from i1, while the elements of a vector of booleans
1028 /// should be sign extended from i1.
1029 ///
1030 /// Some cpus also treat floating point types the same way as they treat
1031 /// vectors instead of the way they treat scalars.
1032 BooleanContent getBooleanContents(bool isVec, bool isFloat) const {
1033 if (isVec)
1034 return BooleanVectorContents;
1035 return isFloat ? BooleanFloatContents : BooleanContents;
1036 }
1037
1039 return getBooleanContents(Type.isVector(), Type.isFloatingPoint());
1040 }
1041
1042 /// Promote the given target boolean to a target boolean of the given type.
1043 /// A target boolean is an integer value, not necessarily of type i1, the bits
1044 /// of which conform to getBooleanContents.
1045 ///
1046 /// ValVT is the type of values that produced the boolean.
1048 EVT ValVT) const {
1049 SDLoc dl(Bool);
1050 EVT BoolVT =
1051 getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), ValVT);
1053 return DAG.getNode(ExtendCode, dl, BoolVT, Bool);
1054 }
1055
1056 /// Return target scheduling preference.
1058 return SchedPreferenceInfo;
1059 }
1060
1061 /// Some scheduler, e.g. hybrid, can switch to different scheduling heuristics
1062 /// for different nodes. This function returns the preference (or none) for
1063 /// the given node.
1065 return Sched::None;
1066 }
1067
1068 /// Return the register class that should be used for the specified value
1069 /// type.
1070 virtual const TargetRegisterClass *getRegClassFor(MVT VT, bool isDivergent = false) const {
1071 (void)isDivergent;
1072 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
1073 assert(RC && "This value type is not natively supported!");
1074 return RC;
1075 }
1076
1077 /// Allows target to decide about the register class of the
1078 /// specific value that is live outside the defining block.
1079 /// Returns true if the value needs uniform register class.
1081 const Value *) const {
1082 return false;
1083 }
1084
1085 /// Return the 'representative' register class for the specified value
1086 /// type.
1087 ///
1088 /// The 'representative' register class is the largest legal super-reg
1089 /// register class for the register class of the value type. For example, on
1090 /// i386 the rep register class for i8, i16, and i32 are GR32; while the rep
1091 /// register class is GR64 on x86_64.
1092 virtual const TargetRegisterClass *getRepRegClassFor(MVT VT) const {
1093 const TargetRegisterClass *RC = RepRegClassForVT[VT.SimpleTy];
1094 return RC;
1095 }
1096
1097 /// Return the cost of the 'representative' register class for the specified
1098 /// value type.
1100 return RepRegClassCostForVT[VT.SimpleTy];
1101 }
1102
1103 /// Return the preferred strategy to legalize tihs SHIFT instruction, with
1104 /// \p ExpansionFactor being the recursion depth - how many expansion needed.
1110 virtual ShiftLegalizationStrategy
1112 unsigned ExpansionFactor) const {
1113 if (ExpansionFactor == 1)
1116 }
1117
1118 /// Return true if the target has native support for the specified value type.
1119 /// This means that it has a register that directly holds it without
1120 /// promotions or expansions.
1121 bool isTypeLegal(EVT VT) const {
1122 assert(!VT.isSimple() ||
1123 (unsigned)VT.getSimpleVT().SimpleTy < std::size(RegClassForVT));
1124 return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != nullptr;
1125 }
1126
1128 /// ValueTypeActions - For each value type, keep a LegalizeTypeAction enum
1129 /// that indicates how instruction selection should deal with the type.
1130 LegalizeTypeAction ValueTypeActions[MVT::VALUETYPE_SIZE];
1131
1132 public:
1133 ValueTypeActionImpl() { llvm::fill(ValueTypeActions, TypeLegal); }
1134
1136 return ValueTypeActions[VT.SimpleTy];
1137 }
1138
1140 ValueTypeActions[VT.SimpleTy] = Action;
1141 }
1142 };
1143
1145 return ValueTypeActions;
1146 }
1147
1148 /// Return pair that represents the legalization kind (first) that needs to
1149 /// happen to EVT (second) in order to type-legalize it.
1150 ///
1151 /// First: how we should legalize values of this type, either it is already
1152 /// legal (return 'Legal') or we need to promote it to a larger type (return
1153 /// 'Promote'), or we need to expand it into multiple registers of smaller
1154 /// integer type (return 'Expand'). 'Custom' is not an option.
1155 ///
1156 /// Second: for types supported by the target, this is an identity function.
1157 /// For types that must be promoted to larger types, this returns the larger
1158 /// type to promote to. For integer types that are larger than the largest
1159 /// integer register, this contains one step in the expansion to get to the
1160 /// smaller register. For illegal floating point types, this returns the
1161 /// integer type to transform to.
1162 LegalizeKind getTypeConversion(LLVMContext &Context, EVT VT) const;
1163
1164 /// Return how we should legalize values of this type, either it is already
1165 /// legal (return 'Legal') or we need to promote it to a larger type (return
1166 /// 'Promote'), or we need to expand it into multiple registers of smaller
1167 /// integer type (return 'Expand'). 'Custom' is not an option.
1169 return getTypeConversion(Context, VT).first;
1170 }
1172 return ValueTypeActions.getTypeAction(VT);
1173 }
1174
1175 /// For types supported by the target, this is an identity function. For
1176 /// types that must be promoted to larger types, this returns the larger type
1177 /// to promote to. For integer types that are larger than the largest integer
1178 /// register, this contains one step in the expansion to get to the smaller
1179 /// register. For illegal floating point types, this returns the integer type
1180 /// to transform to.
1181 virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const {
1182 return getTypeConversion(Context, VT).second;
1183 }
1184
1185 /// Perform getTypeToTransformTo repeatedly until a legal type is obtained.
1186 /// Useful for vector operations that might take multiple steps to legalize.
1188 EVT LegalVT = getTypeToTransformTo(Context, VT);
1189 while (LegalVT != VT) {
1190 VT = LegalVT;
1191 LegalVT = getTypeToTransformTo(Context, VT);
1192 }
1193 return LegalVT;
1194 }
1195
1196 /// For types supported by the target, this is an identity function. For
1197 /// types that must be expanded (i.e. integer types that are larger than the
1198 /// largest integer register or illegal floating point types), this returns
1199 /// the largest legal type it will be expanded to.
1200 EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const {
1201 assert(!VT.isVector());
1202 while (true) {
1203 switch (getTypeAction(Context, VT)) {
1204 case TypeLegal:
1205 return VT;
1206 case TypeExpandInteger:
1207 VT = getTypeToTransformTo(Context, VT);
1208 break;
1209 default:
1210 llvm_unreachable("Type is not legal nor is it to be expanded!");
1211 }
1212 }
1213 }
1214
1215 /// Vector types are broken down into some number of legal first class types.
1216 /// For example, EVT::v8f32 maps to 2 EVT::v4f32 with Altivec or SSE1, or 8
1217 /// promoted EVT::f64 values with the X86 FP stack. Similarly, EVT::v2i64
1218 /// turns into 4 EVT::i32 values with both PPC and X86.
1219 ///
1220 /// This method returns the number of registers needed, and the VT for each
1221 /// register. It also returns the VT and quantity of the intermediate values
1222 /// before they are promoted/expanded.
1223 unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
1224 EVT &IntermediateVT,
1225 unsigned &NumIntermediates,
1226 MVT &RegisterVT) const;
1227
1228 /// Certain targets such as MIPS require that some types such as vectors are
1229 /// always broken down into scalars in some contexts. This occurs even if the
1230 /// vector type is legal.
1232 LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
1233 unsigned &NumIntermediates, MVT &RegisterVT) const {
1234 return getVectorTypeBreakdown(Context, VT, IntermediateVT, NumIntermediates,
1235 RegisterVT);
1236 }
1237
1239 unsigned opc = 0; // target opcode
1240 EVT memVT; // memory VT
1241
1242 // value representing memory location
1244
1245 // Fallback address space for use if ptrVal is nullptr. std::nullopt means
1246 // unknown address space.
1247 std::optional<unsigned> fallbackAddressSpace;
1248
1249 int offset = 0; // offset off of ptrVal
1250 uint64_t size = 0; // the size of the memory location
1251 // (taken from memVT if zero)
1252 MaybeAlign align = Align(1); // alignment
1253
1258 IntrinsicInfo() = default;
1259 };
1260
1261 /// Given an intrinsic, checks if on the target the intrinsic will need to map
1262 /// to a MemIntrinsicNode (touches memory). If this is the case, it returns
1263 /// true and store the intrinsic information into the IntrinsicInfo that was
1264 /// passed to the function.
1267 unsigned /*Intrinsic*/) const {
1268 return false;
1269 }
1270
1271 /// Returns true if the target can instruction select the specified FP
1272 /// immediate natively. If false, the legalizer will materialize the FP
1273 /// immediate as a load from a constant pool.
1274 virtual bool isFPImmLegal(const APFloat & /*Imm*/, EVT /*VT*/,
1275 bool ForCodeSize = false) const {
1276 return false;
1277 }
1278
1279 /// Targets can use this to indicate that they only support *some*
1280 /// VECTOR_SHUFFLE operations, those with specific masks. By default, if a
1281 /// target supports the VECTOR_SHUFFLE node, all mask values are assumed to be
1282 /// legal.
1283 virtual bool isShuffleMaskLegal(ArrayRef<int> /*Mask*/, EVT /*VT*/) const {
1284 return true;
1285 }
1286
1287 /// Returns true if the operation can trap for the value type.
1288 ///
1289 /// VT must be a legal type. By default, we optimistically assume most
1290 /// operations don't trap except for integer divide and remainder.
1291 virtual bool canOpTrap(unsigned Op, EVT VT) const;
1292
1293 /// Similar to isShuffleMaskLegal. Targets can use this to indicate if there
1294 /// is a suitable VECTOR_SHUFFLE that can be used to replace a VAND with a
1295 /// constant pool entry.
1297 EVT /*VT*/) const {
1298 return false;
1299 }
1300
1301 /// How to legalize this custom operation?
1303 return Legal;
1304 }
1305
1306 /// Return how this operation should be treated: either it is legal, needs to
1307 /// be promoted to a larger size, needs to be expanded to some other code
1308 /// sequence, or the target has a custom expander for it.
1310 // If a target-specific SDNode requires legalization, require the target
1311 // to provide custom legalization for it.
1312 if (Op >= std::size(OpActions[0]))
1313 return Custom;
1314 if (VT.isExtended())
1315 return Expand;
1316 return OpActions[(unsigned)VT.getSimpleVT().SimpleTy][Op];
1317 }
1318
1319 /// Custom method defined by each target to indicate if an operation which
1320 /// may require a scale is supported natively by the target.
1321 /// If not, the operation is illegal.
1322 virtual bool isSupportedFixedPointOperation(unsigned Op, EVT VT,
1323 unsigned Scale) const {
1324 return false;
1325 }
1326
1327 /// Some fixed point operations may be natively supported by the target but
1328 /// only for specific scales. This method allows for checking
1329 /// if the width is supported by the target for a given operation that may
1330 /// depend on scale.
1332 unsigned Scale) const {
1333 auto Action = getOperationAction(Op, VT);
1334 if (Action != Legal)
1335 return Action;
1336
1337 // This operation is supported in this type but may only work on specific
1338 // scales.
1339 bool Supported;
1340 switch (Op) {
1341 default:
1342 llvm_unreachable("Unexpected fixed point operation.");
1343 case ISD::SMULFIX:
1344 case ISD::SMULFIXSAT:
1345 case ISD::UMULFIX:
1346 case ISD::UMULFIXSAT:
1347 case ISD::SDIVFIX:
1348 case ISD::SDIVFIXSAT:
1349 case ISD::UDIVFIX:
1350 case ISD::UDIVFIXSAT:
1351 Supported = isSupportedFixedPointOperation(Op, VT, Scale);
1352 break;
1353 }
1354
1355 return Supported ? Action : Expand;
1356 }
1357
1358 // If Op is a strict floating-point operation, return the result
1359 // of getOperationAction for the equivalent non-strict operation.
1361 unsigned EqOpc;
1362 switch (Op) {
1363 default: llvm_unreachable("Unexpected FP pseudo-opcode");
1364#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1365 case ISD::STRICT_##DAGN: EqOpc = ISD::DAGN; break;
1366#define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1367 case ISD::STRICT_##DAGN: EqOpc = ISD::SETCC; break;
1368#include "llvm/IR/ConstrainedOps.def"
1369 }
1370
1371 return getOperationAction(EqOpc, VT);
1372 }
1373
1374 /// Return true if the specified operation is legal on this target or can be
1375 /// made legal with custom lowering. This is used to help guide high-level
1376 /// lowering decisions. LegalOnly is an optional convenience for code paths
1377 /// traversed pre and post legalisation.
1379 bool LegalOnly = false) const {
1380 if (LegalOnly)
1381 return isOperationLegal(Op, VT);
1382
1383 return (VT == MVT::Other || isTypeLegal(VT)) &&
1384 (getOperationAction(Op, VT) == Legal ||
1385 getOperationAction(Op, VT) == Custom);
1386 }
1387
1388 /// Return true if the specified operation is legal on this target or can be
1389 /// made legal using promotion. This is used to help guide high-level lowering
1390 /// decisions. LegalOnly is an optional convenience for code paths traversed
1391 /// pre and post legalisation.
1393 bool LegalOnly = false) const {
1394 if (LegalOnly)
1395 return isOperationLegal(Op, VT);
1396
1397 return (VT == MVT::Other || isTypeLegal(VT)) &&
1398 (getOperationAction(Op, VT) == Legal ||
1399 getOperationAction(Op, VT) == Promote);
1400 }
1401
1402 /// Return true if the specified operation is legal on this target or can be
1403 /// made legal with custom lowering or using promotion. This is used to help
1404 /// guide high-level lowering decisions. LegalOnly is an optional convenience
1405 /// for code paths traversed pre and post legalisation.
1407 bool LegalOnly = false) const {
1408 if (LegalOnly)
1409 return isOperationLegal(Op, VT);
1410
1411 return (VT == MVT::Other || isTypeLegal(VT)) &&
1412 (getOperationAction(Op, VT) == Legal ||
1413 getOperationAction(Op, VT) == Custom ||
1414 getOperationAction(Op, VT) == Promote);
1415 }
1416
1417 /// Return true if the operation uses custom lowering, regardless of whether
1418 /// the type is legal or not.
1419 bool isOperationCustom(unsigned Op, EVT VT) const {
1420 return getOperationAction(Op, VT) == Custom;
1421 }
1422
1423 /// Return true if lowering to a jump table is allowed.
1424 virtual bool areJTsAllowed(const Function *Fn) const {
1425 if (Fn->getFnAttribute("no-jump-tables").getValueAsBool())
1426 return false;
1427
1428 return isOperationLegalOrCustom(ISD::BR_JT, MVT::Other) ||
1430 }
1431
1432 /// Check whether the range [Low,High] fits in a machine word.
1433 bool rangeFitsInWord(const APInt &Low, const APInt &High,
1434 const DataLayout &DL) const {
1435 // FIXME: Using the pointer type doesn't seem ideal.
1436 uint64_t BW = DL.getIndexSizeInBits(0u);
1437 uint64_t Range = (High - Low).getLimitedValue(UINT64_MAX - 1) + 1;
1438 return Range <= BW;
1439 }
1440
1441 /// Return true if lowering to a jump table is suitable for a set of case
1442 /// clusters which may contain \p NumCases cases, \p Range range of values.
1443 virtual bool isSuitableForJumpTable(const SwitchInst *SI, uint64_t NumCases,
1445 BlockFrequencyInfo *BFI) const;
1446
1447 /// Returns preferred type for switch condition.
1448 virtual MVT getPreferredSwitchConditionType(LLVMContext &Context,
1449 EVT ConditionVT) const;
1450
1451 /// Return true if lowering to a bit test is suitable for a set of case
1452 /// clusters which contains \p NumDests unique destinations, \p Low and
1453 /// \p High as its lowest and highest case values, and expects \p NumCmps
1454 /// case value comparisons. Check if the number of destinations, comparison
1455 /// metric, and range are all suitable.
1458 const APInt &Low, const APInt &High, const DataLayout &DL) const {
1459 // FIXME: I don't think NumCmps is the correct metric: a single case and a
1460 // range of cases both require only one branch to lower. Just looking at the
1461 // number of clusters and destinations should be enough to decide whether to
1462 // build bit tests.
1463
1464 // To lower a range with bit tests, the range must fit the bitwidth of a
1465 // machine word.
1466 if (!rangeFitsInWord(Low, High, DL))
1467 return false;
1468
1469 unsigned NumDests = DestCmps.size();
1470 unsigned NumCmps = 0;
1471 unsigned int MaxBitTestEntry = 0;
1472 for (auto &DestCmp : DestCmps) {
1473 NumCmps += DestCmp.second;
1474 if (DestCmp.second > MaxBitTestEntry)
1475 MaxBitTestEntry = DestCmp.second;
1476 }
1477
1478 // Comparisons might be cheaper for small number of comparisons, which can
1479 // be Arch Target specific.
1480 if (MaxBitTestEntry < getMinimumBitTestCmps())
1481 return false;
1482
1483 // Decide whether it's profitable to lower this range with bit tests. Each
1484 // destination requires a bit test and branch, and there is an overall range
1485 // check branch. For a small number of clusters, separate comparisons might
1486 // be cheaper, and for many destinations, splitting the range might be
1487 // better.
1488 return (NumDests == 1 && NumCmps >= 3) || (NumDests == 2 && NumCmps >= 5) ||
1489 (NumDests == 3 && NumCmps >= 6);
1490 }
1491
1492 /// Return true if the specified operation is illegal on this target or
1493 /// unlikely to be made legal with custom lowering. This is used to help guide
1494 /// high-level lowering decisions.
1495 bool isOperationExpand(unsigned Op, EVT VT) const {
1496 return (!isTypeLegal(VT) || getOperationAction(Op, VT) == Expand);
1497 }
1498
1499 /// Return true if the specified operation is legal on this target.
1500 bool isOperationLegal(unsigned Op, EVT VT) const {
1501 return (VT == MVT::Other || isTypeLegal(VT)) &&
1502 getOperationAction(Op, VT) == Legal;
1503 }
1504
1505 bool isOperationExpandOrLibCall(unsigned Op, EVT VT) const {
1506 return isOperationExpand(Op, VT) || getOperationAction(Op, VT) == LibCall;
1507 }
1508
1509 /// Return how this load with extension should be treated: either it is legal,
1510 /// needs to be promoted to a larger size, needs to be expanded to some other
1511 /// code sequence, or the target has a custom expander for it.
1512 LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT,
1513 EVT MemVT) const {
1514 if (ValVT.isExtended() || MemVT.isExtended()) return Expand;
1515 unsigned ValI = (unsigned) ValVT.getSimpleVT().SimpleTy;
1516 unsigned MemI = (unsigned) MemVT.getSimpleVT().SimpleTy;
1518 MemI < MVT::VALUETYPE_SIZE && "Table isn't big enough!");
1519 unsigned Shift = 4 * ExtType;
1520 return (LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf);
1521 }
1522
1523 /// Return true if the specified load with extension is legal on this target.
1524 bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const {
1525 return getLoadExtAction(ExtType, ValVT, MemVT) == Legal;
1526 }
1527
1528 /// Return true if the specified load with extension is legal or custom
1529 /// on this target.
1530 bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const {
1531 return getLoadExtAction(ExtType, ValVT, MemVT) == Legal ||
1532 getLoadExtAction(ExtType, ValVT, MemVT) == Custom;
1533 }
1534
1535 /// Same as getLoadExtAction, but for atomic loads.
1537 EVT MemVT) const {
1538 if (ValVT.isExtended() || MemVT.isExtended()) return Expand;
1539 unsigned ValI = (unsigned)ValVT.getSimpleVT().SimpleTy;
1540 unsigned MemI = (unsigned)MemVT.getSimpleVT().SimpleTy;
1542 MemI < MVT::VALUETYPE_SIZE && "Table isn't big enough!");
1543 unsigned Shift = 4 * ExtType;
1544 LegalizeAction Action =
1545 (LegalizeAction)((AtomicLoadExtActions[ValI][MemI] >> Shift) & 0xf);
1546 assert((Action == Legal || Action == Expand) &&
1547 "Unsupported atomic load extension action.");
1548 return Action;
1549 }
1550
1551 /// Return true if the specified atomic load with extension is legal on
1552 /// this target.
1553 bool isAtomicLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const {
1554 return getAtomicLoadExtAction(ExtType, ValVT, MemVT) == Legal;
1555 }
1556
1557 /// Return how this store with truncation should be treated: either it is
1558 /// legal, needs to be promoted to a larger size, needs to be expanded to some
1559 /// other code sequence, or the target has a custom expander for it.
1561 if (ValVT.isExtended() || MemVT.isExtended()) return Expand;
1562 unsigned ValI = (unsigned) ValVT.getSimpleVT().SimpleTy;
1563 unsigned MemI = (unsigned) MemVT.getSimpleVT().SimpleTy;
1565 "Table isn't big enough!");
1566 return TruncStoreActions[ValI][MemI];
1567 }
1568
1569 /// Return true if the specified store with truncation is legal on this
1570 /// target.
1571 bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const {
1572 return isTypeLegal(ValVT) && getTruncStoreAction(ValVT, MemVT) == Legal;
1573 }
1574
1575 /// Return true if the specified store with truncation has solution on this
1576 /// target.
1577 bool isTruncStoreLegalOrCustom(EVT ValVT, EVT MemVT) const {
1578 return isTypeLegal(ValVT) &&
1579 (getTruncStoreAction(ValVT, MemVT) == Legal ||
1580 getTruncStoreAction(ValVT, MemVT) == Custom);
1581 }
1582
1583 virtual bool canCombineTruncStore(EVT ValVT, EVT MemVT,
1584 bool LegalOnly) const {
1585 if (LegalOnly)
1586 return isTruncStoreLegal(ValVT, MemVT);
1587
1588 return isTruncStoreLegalOrCustom(ValVT, MemVT);
1589 }
1590
1591 /// Return how the indexed load should be treated: either it is legal, needs
1592 /// to be promoted to a larger size, needs to be expanded to some other code
1593 /// sequence, or the target has a custom expander for it.
1594 LegalizeAction getIndexedLoadAction(unsigned IdxMode, MVT VT) const {
1595 return getIndexedModeAction(IdxMode, VT, IMAB_Load);
1596 }
1597
1598 /// Return true if the specified indexed load is legal on this target.
1599 bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const {
1600 return VT.isSimple() &&
1601 (getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Legal ||
1602 getIndexedLoadAction(IdxMode, VT.getSimpleVT()) == Custom);
1603 }
1604
1605 /// Return how the indexed store should be treated: either it is legal, needs
1606 /// to be promoted to a larger size, needs to be expanded to some other code
1607 /// sequence, or the target has a custom expander for it.
1608 LegalizeAction getIndexedStoreAction(unsigned IdxMode, MVT VT) const {
1609 return getIndexedModeAction(IdxMode, VT, IMAB_Store);
1610 }
1611
1612 /// Return true if the specified indexed load is legal on this target.
1613 bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const {
1614 return VT.isSimple() &&
1615 (getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Legal ||
1616 getIndexedStoreAction(IdxMode, VT.getSimpleVT()) == Custom);
1617 }
1618
1619 /// Return how the indexed load should be treated: either it is legal, needs
1620 /// to be promoted to a larger size, needs to be expanded to some other code
1621 /// sequence, or the target has a custom expander for it.
1622 LegalizeAction getIndexedMaskedLoadAction(unsigned IdxMode, MVT VT) const {
1623 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad);
1624 }
1625
1626 /// Return true if the specified indexed load is legal on this target.
1627 bool isIndexedMaskedLoadLegal(unsigned IdxMode, EVT VT) const {
1628 return VT.isSimple() &&
1629 (getIndexedMaskedLoadAction(IdxMode, VT.getSimpleVT()) == Legal ||
1631 }
1632
1633 /// Return how the indexed store should be treated: either it is legal, needs
1634 /// to be promoted to a larger size, needs to be expanded to some other code
1635 /// sequence, or the target has a custom expander for it.
1636 LegalizeAction getIndexedMaskedStoreAction(unsigned IdxMode, MVT VT) const {
1637 return getIndexedModeAction(IdxMode, VT, IMAB_MaskedStore);
1638 }
1639
1640 /// Return true if the specified indexed load is legal on this target.
1641 bool isIndexedMaskedStoreLegal(unsigned IdxMode, EVT VT) const {
1642 return VT.isSimple() &&
1643 (getIndexedMaskedStoreAction(IdxMode, VT.getSimpleVT()) == Legal ||
1645 }
1646
1647 /// Returns true if the index type for a masked gather/scatter requires
1648 /// extending
1649 virtual bool shouldExtendGSIndex(EVT VT, EVT &EltTy) const { return false; }
1650
1651 // Returns true if Extend can be folded into the index of a masked gathers/scatters
1652 // on this target.
1653 virtual bool shouldRemoveExtendFromGSIndex(SDValue Extend, EVT DataVT) const {
1654 return false;
1655 }
1656
1657 // Return true if the target supports a scatter/gather instruction with
1658 // indices which are scaled by the particular value. Note that all targets
1659 // must by definition support scale of 1.
1661 uint64_t ElemSize) const {
1662 // MGATHER/MSCATTER are only required to support scaling by one or by the
1663 // element size.
1664 if (Scale != ElemSize && Scale != 1)
1665 return false;
1666 return true;
1667 }
1668
1669 /// Return how the condition code should be treated: either it is legal, needs
1670 /// to be expanded to some other code sequence, or the target has a custom
1671 /// expander for it.
1674 assert((unsigned)CC < std::size(CondCodeActions) &&
1675 ((unsigned)VT.SimpleTy >> 3) < std::size(CondCodeActions[0]) &&
1676 "Table isn't big enough!");
1677 // See setCondCodeAction for how this is encoded.
1678 uint32_t Shift = 4 * (VT.SimpleTy & 0x7);
1679 uint32_t Value = CondCodeActions[CC][VT.SimpleTy >> 3];
1680 LegalizeAction Action = (LegalizeAction) ((Value >> Shift) & 0xF);
1681 assert(Action != Promote && "Can't promote condition code!");
1682 return Action;
1683 }
1684
1685 /// Return true if the specified condition code is legal for a comparison of
1686 /// the specified types on this target.
1687 bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const {
1688 return getCondCodeAction(CC, VT) == Legal;
1689 }
1690
1691 /// Return true if the specified condition code is legal or custom for a
1692 /// comparison of the specified types on this target.
1694 return getCondCodeAction(CC, VT) == Legal ||
1695 getCondCodeAction(CC, VT) == Custom;
1696 }
1697
1698 /// Return how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type
1699 /// InputVT should be treated. Either it's legal, needs to be promoted to a
1700 /// larger size, needs to be expanded to some other code sequence, or the
1701 /// target has a custom expander for it.
1703 EVT InputVT) const {
1706 PartialReduceActionTypes Key = {Opc, AccVT.getSimpleVT().SimpleTy,
1707 InputVT.getSimpleVT().SimpleTy};
1708 auto It = PartialReduceMLAActions.find(Key);
1709 return It != PartialReduceMLAActions.end() ? It->second : Expand;
1710 }
1711
1712 /// Return true if a PARTIAL_REDUCE_U/SMLA node with the specified types is
1713 /// legal or custom for this target.
1715 EVT InputVT) const {
1716 LegalizeAction Action = getPartialReduceMLAAction(Opc, AccVT, InputVT);
1717 return Action == Legal || Action == Custom;
1718 }
1719
1720 /// If the action for this operation is to promote, this method returns the
1721 /// ValueType to promote to.
1722 MVT getTypeToPromoteTo(unsigned Op, MVT VT) const {
1724 "This operation isn't promoted!");
1725
1726 // See if this has an explicit type specified.
1727 std::map<std::pair<unsigned, MVT::SimpleValueType>,
1729 PromoteToType.find(std::make_pair(Op, VT.SimpleTy));
1730 if (PTTI != PromoteToType.end()) return PTTI->second;
1731
1732 assert((VT.isInteger() || VT.isFloatingPoint()) &&
1733 "Cannot autopromote this type, add it with AddPromotedToType.");
1734
1735 uint64_t VTBits = VT.getScalarSizeInBits();
1736 MVT NVT = VT;
1737 do {
1738 NVT = (MVT::SimpleValueType)(NVT.SimpleTy+1);
1739 assert(NVT.isInteger() == VT.isInteger() &&
1740 NVT.isFloatingPoint() == VT.isFloatingPoint() &&
1741 "Didn't find type to promote to!");
1742 } while (VTBits >= NVT.getScalarSizeInBits() || !isTypeLegal(NVT) ||
1743 getOperationAction(Op, NVT) == Promote);
1744 return NVT;
1745 }
1746
1748 bool AllowUnknown = false) const {
1749 return getValueType(DL, Ty, AllowUnknown);
1750 }
1751
1752 /// Return the EVT corresponding to this LLVM type. This is fixed by the LLVM
1753 /// operations except for the pointer size. If AllowUnknown is true, this
1754 /// will return MVT::Other for types with no EVT counterpart (e.g. structs),
1755 /// otherwise it will assert.
1757 bool AllowUnknown = false) const {
1758 // Lower scalar pointers to native pointer types.
1759 if (auto *PTy = dyn_cast<PointerType>(Ty))
1760 return getPointerTy(DL, PTy->getAddressSpace());
1761
1762 if (auto *VTy = dyn_cast<VectorType>(Ty)) {
1763 Type *EltTy = VTy->getElementType();
1764 // Lower vectors of pointers to native pointer types.
1765 if (auto *PTy = dyn_cast<PointerType>(EltTy)) {
1766 EVT PointerTy(getPointerTy(DL, PTy->getAddressSpace()));
1767 EltTy = PointerTy.getTypeForEVT(Ty->getContext());
1768 }
1769 return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(EltTy, false),
1770 VTy->getElementCount());
1771 }
1772
1773 return EVT::getEVT(Ty, AllowUnknown);
1774 }
1775
1777 bool AllowUnknown = false) const {
1778 // Lower scalar pointers to native pointer types.
1779 if (auto *PTy = dyn_cast<PointerType>(Ty))
1780 return getPointerMemTy(DL, PTy->getAddressSpace());
1781
1782 if (auto *VTy = dyn_cast<VectorType>(Ty)) {
1783 Type *EltTy = VTy->getElementType();
1784 if (auto *PTy = dyn_cast<PointerType>(EltTy)) {
1785 EVT PointerTy(getPointerMemTy(DL, PTy->getAddressSpace()));
1786 EltTy = PointerTy.getTypeForEVT(Ty->getContext());
1787 }
1788 return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(EltTy, false),
1789 VTy->getElementCount());
1790 }
1791
1792 return getValueType(DL, Ty, AllowUnknown);
1793 }
1794
1795
1796 /// Return the MVT corresponding to this LLVM type. See getValueType.
1798 bool AllowUnknown = false) const {
1799 return getValueType(DL, Ty, AllowUnknown).getSimpleVT();
1800 }
1801
1802 /// Returns the desired alignment for ByVal or InAlloca aggregate function
1803 /// arguments in the caller parameter area.
1804 virtual Align getByValTypeAlignment(Type *Ty, const DataLayout &DL) const;
1805
1806 /// Return the type of registers that this ValueType will eventually require.
1808 assert((unsigned)VT.SimpleTy < std::size(RegisterTypeForVT));
1809 return RegisterTypeForVT[VT.SimpleTy];
1810 }
1811
1812 /// Return the type of registers that this ValueType will eventually require.
1813 MVT getRegisterType(LLVMContext &Context, EVT VT) const {
1814 if (VT.isSimple())
1815 return getRegisterType(VT.getSimpleVT());
1816 if (VT.isVector()) {
1817 EVT VT1;
1818 MVT RegisterVT;
1819 unsigned NumIntermediates;
1820 (void)getVectorTypeBreakdown(Context, VT, VT1,
1821 NumIntermediates, RegisterVT);
1822 return RegisterVT;
1823 }
1824 if (VT.isInteger()) {
1825 return getRegisterType(Context, getTypeToTransformTo(Context, VT));
1826 }
1827 llvm_unreachable("Unsupported extended type!");
1828 }
1829
1830 /// Return the number of registers that this ValueType will eventually
1831 /// require.
1832 ///
1833 /// This is one for any types promoted to live in larger registers, but may be
1834 /// more than one for types (like i64) that are split into pieces. For types
1835 /// like i140, which are first promoted then expanded, it is the number of
1836 /// registers needed to hold all the bits of the original type. For an i140
1837 /// on a 32 bit machine this means 5 registers.
1838 ///
1839 /// RegisterVT may be passed as a way to override the default settings, for
1840 /// instance with i128 inline assembly operands on SystemZ.
1841 virtual unsigned
1843 std::optional<MVT> RegisterVT = std::nullopt) const {
1844 if (VT.isSimple()) {
1845 assert((unsigned)VT.getSimpleVT().SimpleTy <
1846 std::size(NumRegistersForVT));
1847 return NumRegistersForVT[VT.getSimpleVT().SimpleTy];
1848 }
1849 if (VT.isVector()) {
1850 EVT VT1;
1851 MVT VT2;
1852 unsigned NumIntermediates;
1853 return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2);
1854 }
1855 if (VT.isInteger()) {
1856 unsigned BitWidth = VT.getSizeInBits();
1857 unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits();
1858 return (BitWidth + RegWidth - 1) / RegWidth;
1859 }
1860 llvm_unreachable("Unsupported extended type!");
1861 }
1862
1863 /// Certain combinations of ABIs, Targets and features require that types
1864 /// are legal for some operations and not for other operations.
1865 /// For MIPS all vector types must be passed through the integer register set.
1867 CallingConv::ID CC, EVT VT) const {
1868 return getRegisterType(Context, VT);
1869 }
1870
1871 /// Certain targets require unusual breakdowns of certain types. For MIPS,
1872 /// this occurs when a vector type is used, as vector are passed through the
1873 /// integer register set.
1875 CallingConv::ID CC,
1876 EVT VT) const {
1877 return getNumRegisters(Context, VT);
1878 }
1879
1880 /// Certain targets have context sensitive alignment requirements, where one
1881 /// type has the alignment requirement of another type.
1883 const DataLayout &DL) const {
1884 return DL.getABITypeAlign(ArgTy);
1885 }
1886
1887 /// If true, then instruction selection should seek to shrink the FP constant
1888 /// of the specified type to a smaller type in order to save space and / or
1889 /// reduce runtime.
1890 virtual bool ShouldShrinkFPConstant(EVT) const { return true; }
1891
1892 /// Return true if it is profitable to reduce a load to a smaller type.
1893 /// \p ByteOffset is only set if we know the pointer offset at compile time
1894 /// otherwise we should assume that additional pointer math is required.
1895 /// Example: (i16 (trunc (i32 (load x))) -> i16 load x
1896 /// Example: (i16 (trunc (srl (i32 (load x)), 16)) -> i16 load x+2
1898 SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT,
1899 std::optional<unsigned> ByteOffset = std::nullopt) const {
1900 // By default, assume that it is cheaper to extract a subvector from a wide
1901 // vector load rather than creating multiple narrow vector loads.
1902 if (NewVT.isVector() && !SDValue(Load, 0).hasOneUse())
1903 return false;
1904
1905 return true;
1906 }
1907
1908 /// Return true (the default) if it is profitable to remove a sext_inreg(x)
1909 /// where the sext is redundant, and use x directly.
1910 virtual bool shouldRemoveRedundantExtend(SDValue Op) const { return true; }
1911
1912 /// Indicates if any padding is guaranteed to go at the most significant bits
1913 /// when storing the type to memory and the type size isn't equal to the store
1914 /// size.
1916 return VT.isScalarInteger() && !VT.isByteSized();
1917 }
1918
1919 /// When splitting a value of the specified type into parts, does the Lo
1920 /// or Hi part come first? This usually follows the endianness, except
1921 /// for ppcf128, where the Hi part always comes first.
1923 return DL.isBigEndian() || VT == MVT::ppcf128;
1924 }
1925
1926 /// If true, the target has custom DAG combine transformations that it can
1927 /// perform for the specified node.
1929 assert(unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
1930 return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7));
1931 }
1932
1935 }
1936
1937 /// Returns the size of the platform's va_list object.
1938 virtual unsigned getVaListSizeInBits(const DataLayout &DL) const {
1939 return getPointerTy(DL).getSizeInBits();
1940 }
1941
1942 /// Get maximum # of store operations permitted for llvm.memset
1943 ///
1944 /// This function returns the maximum number of store operations permitted
1945 /// to replace a call to llvm.memset. The value is set by the target at the
1946 /// performance threshold for such a replacement. If OptSize is true,
1947 /// return the limit for functions that have OptSize attribute.
1948 unsigned getMaxStoresPerMemset(bool OptSize) const;
1949
1950 /// Get maximum # of store operations permitted for llvm.memcpy
1951 ///
1952 /// This function returns the maximum number of store operations permitted
1953 /// to replace a call to llvm.memcpy. The value is set by the target at the
1954 /// performance threshold for such a replacement. If OptSize is true,
1955 /// return the limit for functions that have OptSize attribute.
1956 unsigned getMaxStoresPerMemcpy(bool OptSize) const;
1957
1958 /// \brief Get maximum # of store operations to be glued together
1959 ///
1960 /// This function returns the maximum number of store operations permitted
1961 /// to glue together during lowering of llvm.memcpy. The value is set by
1962 // the target at the performance threshold for such a replacement.
1963 virtual unsigned getMaxGluedStoresPerMemcpy() const {
1965 }
1966
1967 /// Get maximum # of load operations permitted for memcmp
1968 ///
1969 /// This function returns the maximum number of load operations permitted
1970 /// to replace a call to memcmp. The value is set by the target at the
1971 /// performance threshold for such a replacement. If OptSize is true,
1972 /// return the limit for functions that have OptSize attribute.
1973 unsigned getMaxExpandSizeMemcmp(bool OptSize) const {
1975 }
1976
1977 /// Get maximum # of store operations permitted for llvm.memmove
1978 ///
1979 /// This function returns the maximum number of store operations permitted
1980 /// to replace a call to llvm.memmove. The value is set by the target at the
1981 /// performance threshold for such a replacement. If OptSize is true,
1982 /// return the limit for functions that have OptSize attribute.
1983 unsigned getMaxStoresPerMemmove(bool OptSize) const;
1984
1985 /// Determine if the target supports unaligned memory accesses.
1986 ///
1987 /// This function returns true if the target allows unaligned memory accesses
1988 /// of the specified type in the given address space. If true, it also returns
1989 /// a relative speed of the unaligned memory access in the last argument by
1990 /// reference. The higher the speed number the faster the operation comparing
1991 /// to a number returned by another such call. This is used, for example, in
1992 /// situations where an array copy/move/set is converted to a sequence of
1993 /// store operations. Its use helps to ensure that such replacements don't
1994 /// generate code that causes an alignment error (trap) on the target machine.
1996 EVT, unsigned AddrSpace = 0, Align Alignment = Align(1),
1998 unsigned * /*Fast*/ = nullptr) const {
1999 return false;
2000 }
2001
2002 /// LLT handling variant.
2004 LLT, unsigned AddrSpace = 0, Align Alignment = Align(1),
2006 unsigned * /*Fast*/ = nullptr) const {
2007 return false;
2008 }
2009
2010 /// This function returns true if the memory access is aligned or if the
2011 /// target allows this specific unaligned memory access. If the access is
2012 /// allowed, the optional final parameter returns a relative speed of the
2013 /// access (as defined by the target).
2014 bool allowsMemoryAccessForAlignment(
2015 LLVMContext &Context, const DataLayout &DL, EVT VT,
2016 unsigned AddrSpace = 0, Align Alignment = Align(1),
2018 unsigned *Fast = nullptr) const;
2019
2020 /// Return true if the memory access of this type is aligned or if the target
2021 /// allows this specific unaligned access for the given MachineMemOperand.
2022 /// If the access is allowed, the optional final parameter returns a relative
2023 /// speed of the access (as defined by the target).
2024 bool allowsMemoryAccessForAlignment(LLVMContext &Context,
2025 const DataLayout &DL, EVT VT,
2026 const MachineMemOperand &MMO,
2027 unsigned *Fast = nullptr) const;
2028
2029 /// Return true if the target supports a memory access of this type for the
2030 /// given address space and alignment. If the access is allowed, the optional
2031 /// final parameter returns the relative speed of the access (as defined by
2032 /// the target).
2033 virtual bool
2034 allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT,
2035 unsigned AddrSpace = 0, Align Alignment = Align(1),
2037 unsigned *Fast = nullptr) const;
2038
2039 /// Return true if the target supports a memory access of this type for the
2040 /// given MachineMemOperand. If the access is allowed, the optional
2041 /// final parameter returns the relative access speed (as defined by the
2042 /// target).
2043 bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT,
2044 const MachineMemOperand &MMO,
2045 unsigned *Fast = nullptr) const;
2046
2047 /// LLT handling variant.
2048 bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, LLT Ty,
2049 const MachineMemOperand &MMO,
2050 unsigned *Fast = nullptr) const;
2051
2052 /// Returns the target specific optimal type for load and store operations as
2053 /// a result of memset, memcpy, and memmove lowering.
2054 /// It returns EVT::Other if the type should be determined using generic
2055 /// target-independent logic.
2056 virtual EVT
2058 const AttributeList & /*FuncAttributes*/) const {
2059 return MVT::Other;
2060 }
2061
2062 /// LLT returning variant.
2063 virtual LLT
2065 const AttributeList & /*FuncAttributes*/) const {
2066 return LLT();
2067 }
2068
2069 /// Returns true if it's safe to use load / store of the specified type to
2070 /// expand memcpy / memset inline.
2071 ///
2072 /// This is mostly true for all types except for some special cases. For
2073 /// example, on X86 targets without SSE2 f64 load / store are done with fldl /
2074 /// fstpl which also does type conversion. Note the specified type doesn't
2075 /// have to be legal as the hook is used before type legalization.
2076 virtual bool isSafeMemOpType(MVT /*VT*/) const { return true; }
2077
2078 /// Return lower limit for number of blocks in a jump table.
2079 virtual unsigned getMinimumJumpTableEntries() const;
2080
2081 /// Return lower limit of the density in a jump table.
2082 unsigned getMinimumJumpTableDensity(bool OptForSize) const;
2083
2084 /// Return upper limit for number of entries in a jump table.
2085 /// Zero if no limit.
2086 unsigned getMaximumJumpTableSize() const;
2087
2088 virtual bool isJumpTableRelative() const;
2089
2090 /// Retuen the minimum of largest number of comparisons in BitTest.
2091 unsigned getMinimumBitTestCmps() const;
2092
2093 /// If a physical register, this specifies the register that
2094 /// llvm.savestack/llvm.restorestack should save and restore.
2096 return StackPointerRegisterToSaveRestore;
2097 }
2098
2099 /// If a physical register, this returns the register that receives the
2100 /// exception address on entry to an EH pad.
2101 virtual Register
2102 getExceptionPointerRegister(const Constant *PersonalityFn) const {
2103 return Register();
2104 }
2105
2106 /// If a physical register, this returns the register that receives the
2107 /// exception typeid on entry to a landing pad.
2108 virtual Register
2109 getExceptionSelectorRegister(const Constant *PersonalityFn) const {
2110 return Register();
2111 }
2112
2113 virtual bool needsFixedCatchObjects() const {
2114 report_fatal_error("Funclet EH is not implemented for this target");
2115 }
2116
2117 /// Return the minimum stack alignment of an argument.
2119 return MinStackArgumentAlignment;
2120 }
2121
2122 /// Return the minimum function alignment.
2123 Align getMinFunctionAlignment() const { return MinFunctionAlignment; }
2124
2125 /// Return the preferred function alignment.
2126 Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
2127
2128 /// Return the preferred loop alignment.
2129 virtual Align getPrefLoopAlignment(MachineLoop *ML = nullptr) const;
2130
2131 /// Return the maximum amount of bytes allowed to be emitted when padding for
2132 /// alignment
2133 virtual unsigned
2134 getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const;
2135
2136 /// Should loops be aligned even when the function is marked OptSize (but not
2137 /// MinSize).
2138 virtual bool alignLoopsWithOptSize() const { return false; }
2139
2140 /// If the target has a standard location for the stack protector guard,
2141 /// returns the address of that location. Otherwise, returns nullptr.
2142 /// DEPRECATED: please override useLoadStackGuardNode and customize
2143 /// LOAD_STACK_GUARD, or customize \@llvm.stackguard().
2144 virtual Value *getIRStackGuard(IRBuilderBase &IRB) const;
2145
2146 /// Inserts necessary declarations for SSP (stack protection) purpose.
2147 /// Should be used only when getIRStackGuard returns nullptr.
2148 virtual void insertSSPDeclarations(Module &M) const;
2149
2150 /// Return the variable that's previously inserted by insertSSPDeclarations,
2151 /// if any, otherwise return nullptr. Should be used only when
2152 /// getIRStackGuard returns nullptr.
2153 virtual Value *getSDagStackGuard(const Module &M) const;
2154
2155 /// If this function returns true, stack protection checks should XOR the
2156 /// frame pointer (or whichever pointer is used to address locals) into the
2157 /// stack guard value before checking it. getIRStackGuard must return nullptr
2158 /// if this returns true.
2159 virtual bool useStackGuardXorFP() const { return false; }
2160
2161 /// If the target has a standard stack protection check function that
2162 /// performs validation and error handling, returns the function. Otherwise,
2163 /// returns nullptr. Must be previously inserted by insertSSPDeclarations.
2164 /// Should be used only when getIRStackGuard returns nullptr.
2165 Function *getSSPStackGuardCheck(const Module &M) const;
2166
2167protected:
2168 Value *getDefaultSafeStackPointerLocation(IRBuilderBase &IRB,
2169 bool UseTLS) const;
2170
2171public:
2172 /// Returns the target-specific address of the unsafe stack pointer.
2173 virtual Value *getSafeStackPointerLocation(IRBuilderBase &IRB) const;
2174
2175 /// Returns the name of the symbol used to emit stack probes or the empty
2176 /// string if not applicable.
2177 virtual bool hasStackProbeSymbol(const MachineFunction &MF) const { return false; }
2178
2179 virtual bool hasInlineStackProbe(const MachineFunction &MF) const { return false; }
2180
2182 return "";
2183 }
2184
2185 /// Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g. we
2186 /// are happy to sink it into basic blocks. A cast may be free, but not
2187 /// necessarily a no-op. e.g. a free truncate from a 64-bit to 32-bit pointer.
2188 virtual bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const;
2189
2190 /// Return true if the pointer arguments to CI should be aligned by aligning
2191 /// the object whose address is being passed. If so then MinSize is set to the
2192 /// minimum size the object must be to be aligned and PrefAlign is set to the
2193 /// preferred alignment.
2194 virtual bool shouldAlignPointerArgs(CallInst * /*CI*/, unsigned & /*MinSize*/,
2195 Align & /*PrefAlign*/) const {
2196 return false;
2197 }
2198
2199 //===--------------------------------------------------------------------===//
2200 /// \name Helpers for TargetTransformInfo implementations
2201 /// @{
2202
2203 /// Get the ISD node that corresponds to the Instruction class opcode.
2204 int InstructionOpcodeToISD(unsigned Opcode) const;
2205
2206 /// Get the ISD node that corresponds to the Intrinsic ID. Returns
2207 /// ISD::DELETED_NODE by default for an unsupported Intrinsic ID.
2208 int IntrinsicIDToISD(Intrinsic::ID ID) const;
2209
2210 /// @}
2211
2212 //===--------------------------------------------------------------------===//
2213 /// \name Helpers for atomic expansion.
2214 /// @{
2215
2216 /// Returns the maximum atomic operation size (in bits) supported by
2217 /// the backend. Atomic operations greater than this size (as well
2218 /// as ones that are not naturally aligned), will be expanded by
2219 /// AtomicExpandPass into an __atomic_* library call.
2221 return MaxAtomicSizeInBitsSupported;
2222 }
2223
2224 /// Returns the size in bits of the maximum div/rem the backend supports.
2225 /// Larger operations will be expanded by ExpandIRInsts.
2227 return MaxDivRemBitWidthSupported;
2228 }
2229
2230 /// Returns the size in bits of the maximum fp to/from int conversion the
2231 /// backend supports. Larger operations will be expanded by ExpandIRInsts.
2233 return MaxLargeFPConvertBitWidthSupported;
2234 }
2235
2236 /// Returns the size of the smallest cmpxchg or ll/sc instruction
2237 /// the backend supports. Any smaller operations are widened in
2238 /// AtomicExpandPass.
2239 ///
2240 /// Note that *unlike* operations above the maximum size, atomic ops
2241 /// are still natively supported below the minimum; they just
2242 /// require a more complex expansion.
2243 unsigned getMinCmpXchgSizeInBits() const { return MinCmpXchgSizeInBits; }
2244
2245 /// Whether the target supports unaligned atomic operations.
2246 bool supportsUnalignedAtomics() const { return SupportsUnalignedAtomics; }
2247
2248 /// Whether AtomicExpandPass should automatically insert fences and reduce
2249 /// ordering for this atomic. This should be true for most architectures with
2250 /// weak memory ordering. Defaults to false.
2251 virtual bool shouldInsertFencesForAtomic(const Instruction *I) const {
2252 return false;
2253 }
2254
2255 /// Whether AtomicExpandPass should automatically insert a seq_cst trailing
2256 /// fence without reducing the ordering for this atomic store. Defaults to
2257 /// false.
2258 virtual bool
2260 return false;
2261 }
2262
2263 // The memory ordering that AtomicExpandPass should assign to a atomic
2264 // instruction that it has lowered by adding fences. This can be used
2265 // to "fold" one of the fences into the atomic instruction.
2266 virtual AtomicOrdering
2270
2271 /// Perform a load-linked operation on Addr, returning a "Value *" with the
2272 /// corresponding pointee type. This may entail some non-trivial operations to
2273 /// truncate or reconstruct types that will be illegal in the backend. See
2274 /// ARMISelLowering for an example implementation.
2275 virtual Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy,
2276 Value *Addr, AtomicOrdering Ord) const {
2277 llvm_unreachable("Load linked unimplemented on this target");
2278 }
2279
2280 /// Perform a store-conditional operation to Addr. Return the status of the
2281 /// store. This should be 0 if the store succeeded, non-zero otherwise.
2283 Value *Addr, AtomicOrdering Ord) const {
2284 llvm_unreachable("Store conditional unimplemented on this target");
2285 }
2286
2287 /// Perform a masked atomicrmw using a target-specific intrinsic. This
2288 /// represents the core LL/SC loop which will be lowered at a late stage by
2289 /// the backend. The target-specific intrinsic returns the loaded value and
2290 /// is not responsible for masking and shifting the result.
2292 AtomicRMWInst *AI,
2293 Value *AlignedAddr, Value *Incr,
2294 Value *Mask, Value *ShiftAmt,
2295 AtomicOrdering Ord) const {
2296 llvm_unreachable("Masked atomicrmw expansion unimplemented on this target");
2297 }
2298
2299 /// Perform a atomicrmw expansion using a target-specific way. This is
2300 /// expected to be called when masked atomicrmw and bit test atomicrmw don't
2301 /// work, and the target supports another way to lower atomicrmw.
2302 virtual void emitExpandAtomicRMW(AtomicRMWInst *AI) const {
2304 "Generic atomicrmw expansion unimplemented on this target");
2305 }
2306
2307 /// Perform a atomic store using a target-specific way.
2308 virtual void emitExpandAtomicStore(StoreInst *SI) const {
2310 "Generic atomic store expansion unimplemented on this target");
2311 }
2312
2313 /// Perform a atomic load using a target-specific way.
2314 virtual void emitExpandAtomicLoad(LoadInst *LI) const {
2316 "Generic atomic load expansion unimplemented on this target");
2317 }
2318
2319 /// Perform a cmpxchg expansion using a target-specific method.
2321 llvm_unreachable("Generic cmpxchg expansion unimplemented on this target");
2322 }
2323
2324 /// Perform a bit test atomicrmw using a target-specific intrinsic. This
2325 /// represents the combined bit test intrinsic which will be lowered at a late
2326 /// stage by the backend.
2329 "Bit test atomicrmw expansion unimplemented on this target");
2330 }
2331
2332 /// Perform a atomicrmw which the result is only used by comparison, using a
2333 /// target-specific intrinsic. This represents the combined atomic and compare
2334 /// intrinsic which will be lowered at a late stage by the backend.
2337 "Compare arith atomicrmw expansion unimplemented on this target");
2338 }
2339
2340 /// Perform a masked cmpxchg using a target-specific intrinsic. This
2341 /// represents the core LL/SC loop which will be lowered at a late stage by
2342 /// the backend. The target-specific intrinsic returns the loaded value and
2343 /// is not responsible for masking and shifting the result.
2345 IRBuilderBase &Builder, AtomicCmpXchgInst *CI, Value *AlignedAddr,
2346 Value *CmpVal, Value *NewVal, Value *Mask, AtomicOrdering Ord) const {
2347 llvm_unreachable("Masked cmpxchg expansion unimplemented on this target");
2348 }
2349
2350 //===--------------------------------------------------------------------===//
2351 /// \name KCFI check lowering.
2352 /// @{
2353
2356 const TargetInstrInfo *TII) const {
2357 llvm_unreachable("KCFI is not supported on this target");
2358 }
2359
2360 /// @}
2361
2362 /// Inserts in the IR a target-specific intrinsic specifying a fence.
2363 /// It is called by AtomicExpandPass before expanding an
2364 /// AtomicRMW/AtomicCmpXchg/AtomicStore/AtomicLoad
2365 /// if shouldInsertFencesForAtomic returns true.
2366 ///
2367 /// Inst is the original atomic instruction, prior to other expansions that
2368 /// may be performed.
2369 ///
2370 /// This function should either return a nullptr, or a pointer to an IR-level
2371 /// Instruction*. Even complex fence sequences can be represented by a
2372 /// single Instruction* through an intrinsic to be lowered later.
2373 ///
2374 /// The default implementation emits an IR fence before any release (or
2375 /// stronger) operation that stores, and after any acquire (or stronger)
2376 /// operation. This is generally a correct implementation, but backends may
2377 /// override if they wish to use alternative schemes (e.g. the PowerPC
2378 /// standard ABI uses a fence before a seq_cst load instead of after a
2379 /// seq_cst store).
2380 /// @{
2381 virtual Instruction *emitLeadingFence(IRBuilderBase &Builder,
2382 Instruction *Inst,
2383 AtomicOrdering Ord) const;
2384
2385 virtual Instruction *emitTrailingFence(IRBuilderBase &Builder,
2386 Instruction *Inst,
2387 AtomicOrdering Ord) const;
2388 /// @}
2389
2390 // Emits code that executes when the comparison result in the ll/sc
2391 // expansion of a cmpxchg instruction is such that the store-conditional will
2392 // not execute. This makes it possible to balance out the load-linked with
2393 // a dedicated instruction, if desired.
2394 // E.g., on ARM, if ldrex isn't followed by strex, the exclusive monitor would
2395 // be unnecessarily held, except if clrex, inserted by this hook, is executed.
2396 virtual void emitAtomicCmpXchgNoStoreLLBalance(IRBuilderBase &Builder) const {}
2397
2398 /// Returns true if arguments should be sign-extended in lib calls.
2399 virtual bool shouldSignExtendTypeInLibCall(Type *Ty, bool IsSigned) const {
2400 return IsSigned;
2401 }
2402
2403 /// Returns true if arguments should be extended in lib calls.
2404 virtual bool shouldExtendTypeInLibCall(EVT Type) const {
2405 return true;
2406 }
2407
2408 /// Returns how the given (atomic) load should be expanded by the
2409 /// IR-level AtomicExpand pass.
2413
2414 /// Returns how the given (atomic) load should be cast by the IR-level
2415 /// AtomicExpand pass.
2421
2422 /// Returns how the given (atomic) store should be expanded by the IR-level
2423 /// AtomicExpand pass into. For instance AtomicExpansionKind::CustomExpand
2424 /// will try to use an atomicrmw xchg.
2428
2429 /// Returns how the given (atomic) store should be cast by the IR-level
2430 /// AtomicExpand pass into. For instance AtomicExpansionKind::CastToInteger
2431 /// will try to cast the operands to integer values.
2433 if (SI->getValueOperand()->getType()->isFloatingPointTy())
2436 }
2437
2438 /// Returns how the given atomic cmpxchg should be expanded by the IR-level
2439 /// AtomicExpand pass.
2440 virtual AtomicExpansionKind
2444
2445 /// Returns how the IR-level AtomicExpand pass should expand the given
2446 /// AtomicRMW, if at all. Default is to never expand.
2447 virtual AtomicExpansionKind
2452
2453 /// Returns how the given atomic atomicrmw should be cast by the IR-level
2454 /// AtomicExpand pass.
2455 virtual AtomicExpansionKind
2464
2465 /// On some platforms, an AtomicRMW that never actually modifies the value
2466 /// (such as fetch_add of 0) can be turned into a fence followed by an
2467 /// atomic load. This may sound useless, but it makes it possible for the
2468 /// processor to keep the cacheline shared, dramatically improving
2469 /// performance. And such idempotent RMWs are useful for implementing some
2470 /// kinds of locks, see for example (justification + benchmarks):
2471 /// http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
2472 /// This method tries doing that transformation, returning the atomic load if
2473 /// it succeeds, and nullptr otherwise.
2474 /// If shouldExpandAtomicLoadInIR returns true on that load, it will undergo
2475 /// another round of expansion.
2476 virtual LoadInst *
2478 return nullptr;
2479 }
2480
2481 /// Returns how the platform's atomic operations are extended (ZERO_EXTEND,
2482 /// SIGN_EXTEND, or ANY_EXTEND).
2484 return ISD::ZERO_EXTEND;
2485 }
2486
2487 /// Returns how the platform's atomic compare and swap expects its comparison
2488 /// value to be extended (ZERO_EXTEND, SIGN_EXTEND, or ANY_EXTEND). This is
2489 /// separate from getExtendForAtomicOps, which is concerned with the
2490 /// sign-extension of the instruction's output, whereas here we are concerned
2491 /// with the sign-extension of the input. For targets with compare-and-swap
2492 /// instructions (or sub-word comparisons in their LL/SC loop expansions),
2493 /// the input can be ANY_EXTEND, but the output will still have a specific
2494 /// extension.
2496 return ISD::ANY_EXTEND;
2497 }
2498
2499 /// Returns how the platform's atomic rmw operations expect their input
2500 /// argument to be extended (ZERO_EXTEND, SIGN_EXTEND, or ANY_EXTEND).
2502 return ISD::ANY_EXTEND;
2503 }
2504
2505 /// @}
2506
2507 /// Returns true if we should normalize
2508 /// select(N0&N1, X, Y) => select(N0, select(N1, X, Y), Y) and
2509 /// select(N0|N1, X, Y) => select(N0, select(N1, X, Y, Y)) if it is likely
2510 /// that it saves us from materializing N0 and N1 in an integer register.
2511 /// Targets that are able to perform and/or on flags should return false here.
2513 EVT VT) const {
2514 // If a target has multiple condition registers, then it likely has logical
2515 // operations on those registers.
2517 return false;
2518 // Only do the transform if the value won't be split into multiple
2519 // registers.
2520 LegalizeTypeAction Action = getTypeAction(Context, VT);
2521 return Action != TypeExpandInteger && Action != TypeExpandFloat &&
2522 Action != TypeSplitVector;
2523 }
2524
2525 virtual bool isProfitableToCombineMinNumMaxNum(EVT VT) const { return true; }
2526
2527 /// Return true if a select of constants (select Cond, C1, C2) should be
2528 /// transformed into simple math ops with the condition value. For example:
2529 /// select Cond, C1, C1-1 --> add (zext Cond), C1-1
2530 virtual bool convertSelectOfConstantsToMath(EVT VT) const {
2531 return false;
2532 }
2533
2534 /// Return true if it is profitable to transform an integer
2535 /// multiplication-by-constant into simpler operations like shifts and adds.
2536 /// This may be true if the target does not directly support the
2537 /// multiplication operation for the specified type or the sequence of simpler
2538 /// ops is faster than the multiply.
2540 EVT VT, SDValue C) const {
2541 return false;
2542 }
2543
2544 /// Return true if it may be profitable to transform
2545 /// (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2).
2546 /// This may not be true if c1 and c2 can be represented as immediates but
2547 /// c1*c2 cannot, for example.
2548 /// The target should check if c1, c2 and c1*c2 can be represented as
2549 /// immediates, or have to be materialized into registers. If it is not sure
2550 /// about some cases, a default true can be returned to let the DAGCombiner
2551 /// decide.
2552 /// AddNode is (add x, c1), and ConstNode is c2.
2554 SDValue ConstNode) const {
2555 return true;
2556 }
2557
2558 /// Return true if it is more correct/profitable to use strict FP_TO_INT
2559 /// conversion operations - canonicalizing the FP source value instead of
2560 /// converting all cases and then selecting based on value.
2561 /// This may be true if the target throws exceptions for out of bounds
2562 /// conversions or has fast FP CMOV.
2563 virtual bool shouldUseStrictFP_TO_INT(EVT FpVT, EVT IntVT,
2564 bool IsSigned) const {
2565 return false;
2566 }
2567
2568 /// Return true if it is beneficial to expand an @llvm.powi.* intrinsic.
2569 /// If not optimizing for size, expanding @llvm.powi.* intrinsics is always
2570 /// considered beneficial.
2571 /// If optimizing for size, expansion is only considered beneficial for upto
2572 /// 5 multiplies and a divide (if the exponent is negative).
2573 bool isBeneficialToExpandPowI(int64_t Exponent, bool OptForSize) const {
2574 if (Exponent < 0)
2575 Exponent = -Exponent;
2576 uint64_t E = static_cast<uint64_t>(Exponent);
2577 return !OptForSize || (llvm::popcount(E) + Log2_64(E) < 7);
2578 }
2579
2580 //===--------------------------------------------------------------------===//
2581 // TargetLowering Configuration Methods - These methods should be invoked by
2582 // the derived class constructor to configure this object for the target.
2583 //
2584protected:
2585 /// Specify how the target extends the result of integer and floating point
2586 /// boolean values from i1 to a wider type. See getBooleanContents.
2588 BooleanContents = Ty;
2589 BooleanFloatContents = Ty;
2590 }
2591
2592 /// Specify how the target extends the result of integer and floating point
2593 /// boolean values from i1 to a wider type. See getBooleanContents.
2595 BooleanContents = IntTy;
2596 BooleanFloatContents = FloatTy;
2597 }
2598
2599 /// Specify how the target extends the result of a vector boolean value from a
2600 /// vector of i1 to a wider type. See getBooleanContents.
2602 BooleanVectorContents = Ty;
2603 }
2604
2605 /// Specify the target scheduling preference.
2607 SchedPreferenceInfo = Pref;
2608 }
2609
2610 /// Indicate the minimum number of blocks to generate jump tables.
2611 void setMinimumJumpTableEntries(unsigned Val);
2612
2613 /// Indicate the maximum number of entries in jump tables.
2614 /// Set to zero to generate unlimited jump tables.
2615 void setMaximumJumpTableSize(unsigned);
2616
2617 /// Set the minimum of largest of number of comparisons to generate BitTest.
2618 void setMinimumBitTestCmps(unsigned Val);
2619
2620 /// If set to a physical register, this specifies the register that
2621 /// llvm.savestack/llvm.restorestack should save and restore.
2623 StackPointerRegisterToSaveRestore = R;
2624 }
2625
2626 /// Tells the code generator that the target has BitExtract instructions.
2627 /// The code generator will aggressively sink "shift"s into the blocks of
2628 /// their users if the users will generate "and" instructions which can be
2629 /// combined with "shift" to BitExtract instructions.
2630 void setHasExtractBitsInsn(bool hasExtractInsn = true) {
2631 HasExtractBitsInsn = hasExtractInsn;
2632 }
2633
2634 /// Tells the code generator not to expand logic operations on comparison
2635 /// predicates into separate sequences that increase the amount of flow
2636 /// control.
2637 void setJumpIsExpensive(bool isExpensive = true);
2638
2639 /// Tells the code generator which bitwidths to bypass.
2640 void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth) {
2641 BypassSlowDivWidths[SlowBitWidth] = FastBitWidth;
2642 }
2643
2644 /// Add the specified register class as an available regclass for the
2645 /// specified value type. This indicates the selector can handle values of
2646 /// that class natively.
2648 assert((unsigned)VT.SimpleTy < std::size(RegClassForVT));
2649 RegClassForVT[VT.SimpleTy] = RC;
2650 }
2651
2652 /// Return the largest legal super-reg register class of the register class
2653 /// for the specified type and its associated "cost".
2654 virtual std::pair<const TargetRegisterClass *, uint8_t>
2655 findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const;
2656
2657 /// Once all of the register classes are added, this allows us to compute
2658 /// derived properties we expose.
2659 void computeRegisterProperties(const TargetRegisterInfo *TRI);
2660
2661 /// Indicate that the specified operation does not work with the specified
2662 /// type and indicate what to do about it. Note that VT may refer to either
2663 /// the type of a result or that of an operand of Op.
2664 void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action) {
2665 assert(Op < std::size(OpActions[0]) && "Table isn't big enough!");
2666 OpActions[(unsigned)VT.SimpleTy][Op] = Action;
2667 }
2669 LegalizeAction Action) {
2670 for (auto Op : Ops)
2671 setOperationAction(Op, VT, Action);
2672 }
2674 LegalizeAction Action) {
2675 for (auto VT : VTs)
2676 setOperationAction(Ops, VT, Action);
2677 }
2678
2679 /// Indicate that the specified load with extension does not work with the
2680 /// specified type and indicate what to do about it.
2681 void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT,
2682 LegalizeAction Action) {
2683 assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
2684 MemVT.isValid() && "Table isn't big enough!");
2685 assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2686 unsigned Shift = 4 * ExtType;
2687 LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &= ~((uint16_t)0xF << Shift);
2688 LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |= (uint16_t)Action << Shift;
2689 }
2690 void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT, MVT MemVT,
2691 LegalizeAction Action) {
2692 for (auto ExtType : ExtTypes)
2693 setLoadExtAction(ExtType, ValVT, MemVT, Action);
2694 }
2696 ArrayRef<MVT> MemVTs, LegalizeAction Action) {
2697 for (auto MemVT : MemVTs)
2698 setLoadExtAction(ExtTypes, ValVT, MemVT, Action);
2699 }
2700
2701 /// Let target indicate that an extending atomic load of the specified type
2702 /// is legal.
2703 void setAtomicLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT,
2704 LegalizeAction Action) {
2705 assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
2706 MemVT.isValid() && "Table isn't big enough!");
2707 assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2708 unsigned Shift = 4 * ExtType;
2709 AtomicLoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &=
2710 ~((uint16_t)0xF << Shift);
2711 AtomicLoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |=
2712 ((uint16_t)Action << Shift);
2713 }
2715 LegalizeAction Action) {
2716 for (auto ExtType : ExtTypes)
2717 setAtomicLoadExtAction(ExtType, ValVT, MemVT, Action);
2718 }
2720 ArrayRef<MVT> MemVTs, LegalizeAction Action) {
2721 for (auto MemVT : MemVTs)
2722 setAtomicLoadExtAction(ExtTypes, ValVT, MemVT, Action);
2723 }
2724
2725 /// Indicate that the specified truncating store does not work with the
2726 /// specified type and indicate what to do about it.
2727 void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action) {
2728 assert(ValVT.isValid() && MemVT.isValid() && "Table isn't big enough!");
2729 TruncStoreActions[(unsigned)ValVT.SimpleTy][MemVT.SimpleTy] = Action;
2730 }
2731
2732 /// Indicate that the specified indexed load does or does not work with the
2733 /// specified type and indicate what to do abort it.
2734 ///
2735 /// NOTE: All indexed mode loads are initialized to Expand in
2736 /// TargetLowering.cpp
2738 LegalizeAction Action) {
2739 for (auto IdxMode : IdxModes)
2740 setIndexedModeAction(IdxMode, VT, IMAB_Load, Action);
2741 }
2742
2744 LegalizeAction Action) {
2745 for (auto VT : VTs)
2746 setIndexedLoadAction(IdxModes, VT, Action);
2747 }
2748
2749 /// Indicate that the specified indexed store does or does not work with the
2750 /// specified type and indicate what to do about it.
2751 ///
2752 /// NOTE: All indexed mode stores are initialized to Expand in
2753 /// TargetLowering.cpp
2755 LegalizeAction Action) {
2756 for (auto IdxMode : IdxModes)
2757 setIndexedModeAction(IdxMode, VT, IMAB_Store, Action);
2758 }
2759
2761 LegalizeAction Action) {
2762 for (auto VT : VTs)
2763 setIndexedStoreAction(IdxModes, VT, Action);
2764 }
2765
2766 /// Indicate that the specified indexed masked load does or does not work with
2767 /// the specified type and indicate what to do about it.
2768 ///
2769 /// NOTE: All indexed mode masked loads are initialized to Expand in
2770 /// TargetLowering.cpp
2771 void setIndexedMaskedLoadAction(unsigned IdxMode, MVT VT,
2772 LegalizeAction Action) {
2773 setIndexedModeAction(IdxMode, VT, IMAB_MaskedLoad, Action);
2774 }
2775
2776 /// Indicate that the specified indexed masked store does or does not work
2777 /// with the specified type and indicate what to do about it.
2778 ///
2779 /// NOTE: All indexed mode masked stores are initialized to Expand in
2780 /// TargetLowering.cpp
2781 void setIndexedMaskedStoreAction(unsigned IdxMode, MVT VT,
2782 LegalizeAction Action) {
2783 setIndexedModeAction(IdxMode, VT, IMAB_MaskedStore, Action);
2784 }
2785
2786 /// Indicate that the specified condition code is or isn't supported on the
2787 /// target and indicate what to do about it.
2789 LegalizeAction Action) {
2790 for (auto CC : CCs) {
2791 assert(VT.isValid() && (unsigned)CC < std::size(CondCodeActions) &&
2792 "Table isn't big enough!");
2793 assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2794 /// The lower 3 bits of the SimpleTy index into Nth 4bit set from the
2795 /// 32-bit value and the upper 29 bits index into the second dimension of
2796 /// the array to select what 32-bit value to use.
2797 uint32_t Shift = 4 * (VT.SimpleTy & 0x7);
2798 CondCodeActions[CC][VT.SimpleTy >> 3] &= ~((uint32_t)0xF << Shift);
2799 CondCodeActions[CC][VT.SimpleTy >> 3] |= (uint32_t)Action << Shift;
2800 }
2801 }
2803 LegalizeAction Action) {
2804 for (auto VT : VTs)
2805 setCondCodeAction(CCs, VT, Action);
2806 }
2807
2808 /// Indicate how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input
2809 /// type InputVT should be treated by the target. Either it's legal, needs to
2810 /// be promoted to a larger size, needs to be expanded to some other code
2811 /// sequence, or the target has a custom expander for it.
2812 void setPartialReduceMLAAction(unsigned Opc, MVT AccVT, MVT InputVT,
2813 LegalizeAction Action) {
2816 assert(AccVT.isValid() && InputVT.isValid() &&
2817 "setPartialReduceMLAAction types aren't valid");
2818 PartialReduceActionTypes Key = {Opc, AccVT.SimpleTy, InputVT.SimpleTy};
2819 PartialReduceMLAActions[Key] = Action;
2820 }
2822 MVT InputVT, LegalizeAction Action) {
2823 for (unsigned Opc : Opcodes)
2824 setPartialReduceMLAAction(Opc, AccVT, InputVT, Action);
2825 }
2826
2827 /// If Opc/OrigVT is specified as being promoted, the promotion code defaults
2828 /// to trying a larger integer/fp until it can find one that works. If that
2829 /// default is insufficient, this method can be used by the target to override
2830 /// the default.
2831 void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
2832 PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy;
2833 }
2834
2835 /// Convenience method to set an operation to Promote and specify the type
2836 /// in a single call.
2837 void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) {
2838 setOperationAction(Opc, OrigVT, Promote);
2839 AddPromotedToType(Opc, OrigVT, DestVT);
2840 }
2842 MVT DestVT) {
2843 for (auto Op : Ops) {
2844 setOperationAction(Op, OrigVT, Promote);
2845 AddPromotedToType(Op, OrigVT, DestVT);
2846 }
2847 }
2848
2849 /// Targets should invoke this method for each target independent node that
2850 /// they want to provide a custom DAG combiner for by implementing the
2851 /// PerformDAGCombine virtual method.
2853 for (auto NT : NTs) {
2854 assert(unsigned(NT >> 3) < std::size(TargetDAGCombineArray));
2855 TargetDAGCombineArray[NT >> 3] |= 1 << (NT & 7);
2856 }
2857 }
2858
2859 /// Set the target's minimum function alignment.
2861 MinFunctionAlignment = Alignment;
2862 }
2863
2864 /// Set the target's preferred function alignment. This should be set if
2865 /// there is a performance benefit to higher-than-minimum alignment
2867 PrefFunctionAlignment = Alignment;
2868 }
2869
2870 /// Set the target's preferred loop alignment. Default alignment is one, it
2871 /// means the target does not care about loop alignment. The target may also
2872 /// override getPrefLoopAlignment to provide per-loop values.
2873 void setPrefLoopAlignment(Align Alignment) { PrefLoopAlignment = Alignment; }
2874 void setMaxBytesForAlignment(unsigned MaxBytes) {
2875 MaxBytesForAlignment = MaxBytes;
2876 }
2877
2878 /// Set the minimum stack alignment of an argument.
2880 MinStackArgumentAlignment = Alignment;
2881 }
2882
2883 /// Set the maximum atomic operation size supported by the
2884 /// backend. Atomic operations greater than this size (as well as
2885 /// ones that are not naturally aligned), will be expanded by
2886 /// AtomicExpandPass into an __atomic_* library call.
2887 void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits) {
2888 MaxAtomicSizeInBitsSupported = SizeInBits;
2889 }
2890
2891 /// Set the size in bits of the maximum div/rem the backend supports.
2892 /// Larger operations will be expanded by ExpandIRInsts.
2893 void setMaxDivRemBitWidthSupported(unsigned SizeInBits) {
2894 MaxDivRemBitWidthSupported = SizeInBits;
2895 }
2896
2897 /// Set the size in bits of the maximum fp to/from int conversion the backend
2898 /// supports. Larger operations will be expanded by ExpandIRInsts.
2899 void setMaxLargeFPConvertBitWidthSupported(unsigned SizeInBits) {
2900 MaxLargeFPConvertBitWidthSupported = SizeInBits;
2901 }
2902
2903 /// Sets the minimum cmpxchg or ll/sc size supported by the backend.
2904 void setMinCmpXchgSizeInBits(unsigned SizeInBits) {
2905 MinCmpXchgSizeInBits = SizeInBits;
2906 }
2907
2908 /// Sets whether unaligned atomic operations are supported.
2909 void setSupportsUnalignedAtomics(bool UnalignedSupported) {
2910 SupportsUnalignedAtomics = UnalignedSupported;
2911 }
2912
2913public:
2914 //===--------------------------------------------------------------------===//
2915 // Addressing mode description hooks (used by LSR etc).
2916 //
2917
2918 /// CodeGenPrepare sinks address calculations into the same BB as Load/Store
2919 /// instructions reading the address. This allows as much computation as
2920 /// possible to be done in the address mode for that operand. This hook lets
2921 /// targets also pass back when this should be done on intrinsics which
2922 /// load/store.
2923 virtual bool getAddrModeArguments(const IntrinsicInst * /*I*/,
2924 SmallVectorImpl<Value *> & /*Ops*/,
2925 Type *& /*AccessTy*/) const {
2926 return false;
2927 }
2928
2929 /// This represents an addressing mode of:
2930 /// BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*vscale
2931 /// If BaseGV is null, there is no BaseGV.
2932 /// If BaseOffs is zero, there is no base offset.
2933 /// If HasBaseReg is false, there is no base register.
2934 /// If Scale is zero, there is no ScaleReg. Scale of 1 indicates a reg with
2935 /// no scale.
2936 /// If ScalableOffset is zero, there is no scalable offset.
2937 struct AddrMode {
2939 int64_t BaseOffs = 0;
2940 bool HasBaseReg = false;
2941 int64_t Scale = 0;
2942 int64_t ScalableOffset = 0;
2943 AddrMode() = default;
2944 };
2945
2946 /// Return true if the addressing mode represented by AM is legal for this
2947 /// target, for a load/store of the specified type.
2948 ///
2949 /// The type may be VoidTy, in which case only return true if the addressing
2950 /// mode is legal for a load/store of any legal type. TODO: Handle
2951 /// pre/postinc as well.
2952 ///
2953 /// If the address space cannot be determined, it will be -1.
2954 ///
2955 /// TODO: Remove default argument
2956 virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
2957 Type *Ty, unsigned AddrSpace,
2958 Instruction *I = nullptr) const;
2959
2960 /// Returns true if the targets addressing mode can target thread local
2961 /// storage (TLS).
2962 virtual bool addressingModeSupportsTLS(const GlobalValue &) const {
2963 return false;
2964 }
2965
2966 /// Return the prefered common base offset.
2967 virtual int64_t getPreferredLargeGEPBaseOffset(int64_t MinOffset,
2968 int64_t MaxOffset) const {
2969 return 0;
2970 }
2971
2972 /// Return true if the specified immediate is legal icmp immediate, that is
2973 /// the target has icmp instructions which can compare a register against the
2974 /// immediate without having to materialize the immediate into a register.
2975 virtual bool isLegalICmpImmediate(int64_t) const {
2976 return true;
2977 }
2978
2979 /// Return true if the specified immediate is legal add immediate, that is the
2980 /// target has add instructions which can add a register with the immediate
2981 /// without having to materialize the immediate into a register.
2982 virtual bool isLegalAddImmediate(int64_t) const {
2983 return true;
2984 }
2985
2986 /// Return true if adding the specified scalable immediate is legal, that is
2987 /// the target has add instructions which can add a register with the
2988 /// immediate (multiplied by vscale) without having to materialize the
2989 /// immediate into a register.
2990 virtual bool isLegalAddScalableImmediate(int64_t) const { return false; }
2991
2992 /// Return true if the specified immediate is legal for the value input of a
2993 /// store instruction.
2994 virtual bool isLegalStoreImmediate(int64_t Value) const {
2995 // Default implementation assumes that at least 0 works since it is likely
2996 // that a zero register exists or a zero immediate is allowed.
2997 return Value == 0;
2998 }
2999
3000 /// Given a shuffle vector SVI representing a vector splat, return a new
3001 /// scalar type of size equal to SVI's scalar type if the new type is more
3002 /// profitable. Returns nullptr otherwise. For example under MVE float splats
3003 /// are converted to integer to prevent the need to move from SPR to GPR
3004 /// registers.
3006 return nullptr;
3007 }
3008
3009 /// Given a set in interconnected phis of type 'From' that are loaded/stored
3010 /// or bitcast to type 'To', return true if the set should be converted to
3011 /// 'To'.
3012 virtual bool shouldConvertPhiType(Type *From, Type *To) const {
3013 return (From->isIntegerTy() || From->isFloatingPointTy()) &&
3014 (To->isIntegerTy() || To->isFloatingPointTy());
3015 }
3016
3017 /// Returns true if the opcode is a commutative binary operation.
3018 virtual bool isCommutativeBinOp(unsigned Opcode) const {
3019 // FIXME: This should get its info from the td file.
3020 switch (Opcode) {
3021 case ISD::ADD:
3022 case ISD::SMIN:
3023 case ISD::SMAX:
3024 case ISD::UMIN:
3025 case ISD::UMAX:
3026 case ISD::MUL:
3027 case ISD::CLMUL:
3028 case ISD::CLMULH:
3029 case ISD::CLMULR:
3030 case ISD::MULHU:
3031 case ISD::MULHS:
3032 case ISD::SMUL_LOHI:
3033 case ISD::UMUL_LOHI:
3034 case ISD::FADD:
3035 case ISD::FMUL:
3036 case ISD::AND:
3037 case ISD::OR:
3038 case ISD::XOR:
3039 case ISD::SADDO:
3040 case ISD::UADDO:
3041 case ISD::ADDC:
3042 case ISD::ADDE:
3043 case ISD::SADDSAT:
3044 case ISD::UADDSAT:
3045 case ISD::FMINNUM:
3046 case ISD::FMAXNUM:
3047 case ISD::FMINNUM_IEEE:
3048 case ISD::FMAXNUM_IEEE:
3049 case ISD::FMINIMUM:
3050 case ISD::FMAXIMUM:
3051 case ISD::FMINIMUMNUM:
3052 case ISD::FMAXIMUMNUM:
3053 case ISD::AVGFLOORS:
3054 case ISD::AVGFLOORU:
3055 case ISD::AVGCEILS:
3056 case ISD::AVGCEILU:
3057 case ISD::ABDS:
3058 case ISD::ABDU:
3059 return true;
3060 default: return false;
3061 }
3062 }
3063
3064 /// Return true if the node is a math/logic binary operator.
3065 virtual bool isBinOp(unsigned Opcode) const {
3066 // A commutative binop must be a binop.
3067 if (isCommutativeBinOp(Opcode))
3068 return true;
3069 // These are non-commutative binops.
3070 switch (Opcode) {
3071 case ISD::SUB:
3072 case ISD::SHL:
3073 case ISD::SRL:
3074 case ISD::SRA:
3075 case ISD::ROTL:
3076 case ISD::ROTR:
3077 case ISD::SDIV:
3078 case ISD::UDIV:
3079 case ISD::SREM:
3080 case ISD::UREM:
3081 case ISD::SSUBSAT:
3082 case ISD::USUBSAT:
3083 case ISD::FSUB:
3084 case ISD::FDIV:
3085 case ISD::FREM:
3086 return true;
3087 default:
3088 return false;
3089 }
3090 }
3091
3092 /// Return true if it's free to truncate a value of type FromTy to type
3093 /// ToTy. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
3094 /// by referencing its sub-register AX.
3095 /// Targets must return false when FromTy <= ToTy.
3096 virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const {
3097 return false;
3098 }
3099
3100 /// Return true if a truncation from FromTy to ToTy is permitted when deciding
3101 /// whether a call is in tail position. Typically this means that both results
3102 /// would be assigned to the same register or stack slot, but it could mean
3103 /// the target performs adequate checks of its own before proceeding with the
3104 /// tail call. Targets must return false when FromTy <= ToTy.
3105 virtual bool allowTruncateForTailCall(Type *FromTy, Type *ToTy) const {
3106 return false;
3107 }
3108
3109 virtual bool isTruncateFree(EVT FromVT, EVT ToVT) const { return false; }
3110 virtual bool isTruncateFree(LLT FromTy, LLT ToTy, LLVMContext &Ctx) const {
3111 return isTruncateFree(getApproximateEVTForLLT(FromTy, Ctx),
3112 getApproximateEVTForLLT(ToTy, Ctx));
3113 }
3114
3115 /// Return true if truncating the specific node Val to type VT2 is free.
3116 virtual bool isTruncateFree(SDValue Val, EVT VT2) const {
3117 // Fallback to type matching.
3118 return isTruncateFree(Val.getValueType(), VT2);
3119 }
3120
3121 virtual bool isProfitableToHoist(Instruction *I) const { return true; }
3122
3123 /// Return true if the extension represented by \p I is free.
3124 /// Unlikely the is[Z|FP]ExtFree family which is based on types,
3125 /// this method can use the context provided by \p I to decide
3126 /// whether or not \p I is free.
3127 /// This method extends the behavior of the is[Z|FP]ExtFree family.
3128 /// In other words, if is[Z|FP]Free returns true, then this method
3129 /// returns true as well. The converse is not true.
3130 /// The target can perform the adequate checks by overriding isExtFreeImpl.
3131 /// \pre \p I must be a sign, zero, or fp extension.
3132 bool isExtFree(const Instruction *I) const {
3133 switch (I->getOpcode()) {
3134 case Instruction::FPExt:
3135 if (isFPExtFree(EVT::getEVT(I->getType()),
3136 EVT::getEVT(I->getOperand(0)->getType())))
3137 return true;
3138 break;
3139 case Instruction::ZExt:
3140 if (isZExtFree(I->getOperand(0)->getType(), I->getType()))
3141 return true;
3142 break;
3143 case Instruction::SExt:
3144 break;
3145 default:
3146 llvm_unreachable("Instruction is not an extension");
3147 }
3148 return isExtFreeImpl(I);
3149 }
3150
3151 /// Return true if \p Load and \p Ext can form an ExtLoad.
3152 /// For example, in AArch64
3153 /// %L = load i8, i8* %ptr
3154 /// %E = zext i8 %L to i32
3155 /// can be lowered into one load instruction
3156 /// ldrb w0, [x0]
3157 bool isExtLoad(const LoadInst *Load, const Instruction *Ext,
3158 const DataLayout &DL) const {
3159 EVT VT = getValueType(DL, Ext->getType());
3160 EVT LoadVT = getValueType(DL, Load->getType());
3161
3162 // If the load has other users and the truncate is not free, the ext
3163 // probably isn't free.
3164 if (!Load->hasOneUse() && (isTypeLegal(LoadVT) || !isTypeLegal(VT)) &&
3165 !isTruncateFree(Ext->getType(), Load->getType()))
3166 return false;
3167
3168 // Check whether the target supports casts folded into loads.
3169 unsigned LType;
3170 if (isa<ZExtInst>(Ext))
3171 LType = ISD::ZEXTLOAD;
3172 else {
3173 assert(isa<SExtInst>(Ext) && "Unexpected ext type!");
3174 LType = ISD::SEXTLOAD;
3175 }
3176
3177 return isLoadExtLegal(LType, VT, LoadVT);
3178 }
3179
3180 /// Return true if any actual instruction that defines a value of type FromTy
3181 /// implicitly zero-extends the value to ToTy in the result register.
3182 ///
3183 /// The function should return true when it is likely that the truncate can
3184 /// be freely folded with an instruction defining a value of FromTy. If
3185 /// the defining instruction is unknown (because you're looking at a
3186 /// function argument, PHI, etc.) then the target may require an
3187 /// explicit truncate, which is not necessarily free, but this function
3188 /// does not deal with those cases.
3189 /// Targets must return false when FromTy >= ToTy.
3190 virtual bool isZExtFree(Type *FromTy, Type *ToTy) const {
3191 return false;
3192 }
3193
3194 virtual bool isZExtFree(EVT FromTy, EVT ToTy) const { return false; }
3195 virtual bool isZExtFree(LLT FromTy, LLT ToTy, LLVMContext &Ctx) const {
3196 return isZExtFree(getApproximateEVTForLLT(FromTy, Ctx),
3197 getApproximateEVTForLLT(ToTy, Ctx));
3198 }
3199
3200 /// Return true if zero-extending the specific node Val to type VT2 is free
3201 /// (either because it's implicitly zero-extended such as ARM ldrb / ldrh or
3202 /// because it's folded such as X86 zero-extending loads).
3203 virtual bool isZExtFree(SDValue Val, EVT VT2) const {
3204 return isZExtFree(Val.getValueType(), VT2);
3205 }
3206
3207 /// Return true if sign-extension from FromTy to ToTy is cheaper than
3208 /// zero-extension.
3209 virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const {
3210 return false;
3211 }
3212
3213 /// Return true if this constant should be sign extended when promoting to
3214 /// a larger type.
3215 virtual bool signExtendConstant(const ConstantInt *C) const { return false; }
3216
3217 /// Try to optimize extending or truncating conversion instructions (like
3218 /// zext, trunc, fptoui, uitofp) for the target.
3219 virtual bool
3221 const TargetTransformInfo &TTI) const {
3222 return false;
3223 }
3224
3225 /// Return true if the target supplies and combines to a paired load
3226 /// two loaded values of type LoadedType next to each other in memory.
3227 /// RequiredAlignment gives the minimal alignment constraints that must be met
3228 /// to be able to select this paired load.
3229 ///
3230 /// This information is *not* used to generate actual paired loads, but it is
3231 /// used to generate a sequence of loads that is easier to combine into a
3232 /// paired load.
3233 /// For instance, something like this:
3234 /// a = load i64* addr
3235 /// b = trunc i64 a to i32
3236 /// c = lshr i64 a, 32
3237 /// d = trunc i64 c to i32
3238 /// will be optimized into:
3239 /// b = load i32* addr1
3240 /// d = load i32* addr2
3241 /// Where addr1 = addr2 +/- sizeof(i32).
3242 ///
3243 /// In other words, unless the target performs a post-isel load combining,
3244 /// this information should not be provided because it will generate more
3245 /// loads.
3246 virtual bool hasPairedLoad(EVT /*LoadedType*/,
3247 Align & /*RequiredAlignment*/) const {
3248 return false;
3249 }
3250
3251 /// Return true if the target has a vector blend instruction.
3252 virtual bool hasVectorBlend() const { return false; }
3253
3254 /// Get the maximum supported factor for interleaved memory accesses.
3255 /// Default to be the minimum interleave factor: 2.
3256 virtual unsigned getMaxSupportedInterleaveFactor() const { return 2; }
3257
3258 /// Lower an interleaved load to target specific intrinsics. Return
3259 /// true on success.
3260 ///
3261 /// \p Load is the vector load instruction. Can be either a plain load
3262 /// instruction or a vp.load intrinsic.
3263 /// \p Mask is a per-segment (i.e. number of lanes equal to that of one
3264 /// component being interwoven) mask. Can be nullptr, in which case the
3265 /// result is uncondiitional.
3266 /// \p Shuffles is the shufflevector list to DE-interleave the loaded vector.
3267 /// \p Indices is the corresponding indices for each shufflevector.
3268 /// \p Factor is the interleave factor.
3269 /// \p GapMask is a mask with zeros for components / fields that may not be
3270 /// accessed.
3271 virtual bool lowerInterleavedLoad(Instruction *Load, Value *Mask,
3273 ArrayRef<unsigned> Indices, unsigned Factor,
3274 const APInt &GapMask) const {
3275 return false;
3276 }
3277
3278 /// Lower an interleaved store to target specific intrinsics. Return
3279 /// true on success.
3280 ///
3281 /// \p SI is the vector store instruction. Can be either a plain store
3282 /// or a vp.store.
3283 /// \p Mask is a per-segment (i.e. number of lanes equal to that of one
3284 /// component being interwoven) mask. Can be nullptr, in which case the
3285 /// result is unconditional.
3286 /// \p SVI is the shufflevector to RE-interleave the stored vector.
3287 /// \p Factor is the interleave factor.
3288 /// \p GapMask is a mask with zeros for components / fields that may not be
3289 /// accessed.
3290 virtual bool lowerInterleavedStore(Instruction *Store, Value *Mask,
3291 ShuffleVectorInst *SVI, unsigned Factor,
3292 const APInt &GapMask) const {
3293 return false;
3294 }
3295
3296 /// Lower a deinterleave intrinsic to a target specific load intrinsic.
3297 /// Return true on success. Currently only supports
3298 /// llvm.vector.deinterleave{2,3,5,7}
3299 ///
3300 /// \p Load is the accompanying load instruction. Can be either a plain load
3301 /// instruction or a vp.load intrinsic.
3302 /// \p DI represents the deinterleaveN intrinsic.
3304 IntrinsicInst *DI) const {
3305 return false;
3306 }
3307
3308 /// Lower an interleave intrinsic to a target specific store intrinsic.
3309 /// Return true on success. Currently only supports
3310 /// llvm.vector.interleave{2,3,5,7}
3311 ///
3312 /// \p Store is the accompanying store instruction. Can be either a plain
3313 /// store or a vp.store intrinsic.
3314 /// \p Mask is a per-segment (i.e. number of lanes equal to that of one
3315 /// component being interwoven) mask. Can be nullptr, in which case the
3316 /// result is uncondiitional.
3317 /// \p InterleaveValues contains the interleaved values.
3318 virtual bool
3320 ArrayRef<Value *> InterleaveValues) const {
3321 return false;
3322 }
3323
3324 /// Return true if an fpext operation is free (for instance, because
3325 /// single-precision floating-point numbers are implicitly extended to
3326 /// double-precision).
3327 virtual bool isFPExtFree(EVT DestVT, EVT SrcVT) const {
3328 assert(SrcVT.isFloatingPoint() && DestVT.isFloatingPoint() &&
3329 "invalid fpext types");
3330 return false;
3331 }
3332
3333 /// Return true if an fpext operation input to an \p Opcode operation is free
3334 /// (for instance, because half-precision floating-point numbers are
3335 /// implicitly extended to float-precision) for an FMA instruction.
3336 virtual bool isFPExtFoldable(const MachineInstr &MI, unsigned Opcode,
3337 LLT DestTy, LLT SrcTy) const {
3338 return false;
3339 }
3340
3341 /// Return true if an fpext operation input to an \p Opcode operation is free
3342 /// (for instance, because half-precision floating-point numbers are
3343 /// implicitly extended to float-precision) for an FMA instruction.
3344 virtual bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode,
3345 EVT DestVT, EVT SrcVT) const {
3346 assert(DestVT.isFloatingPoint() && SrcVT.isFloatingPoint() &&
3347 "invalid fpext types");
3348 return isFPExtFree(DestVT, SrcVT);
3349 }
3350
3351 /// Return true if folding a vector load into ExtVal (a sign, zero, or any
3352 /// extend node) is profitable.
3353 virtual bool isVectorLoadExtDesirable(SDValue ExtVal) const { return false; }
3354
3355 /// Return true if an fneg operation is free to the point where it is never
3356 /// worthwhile to replace it with a bitwise operation.
3357 virtual bool isFNegFree(EVT VT) const {
3358 assert(VT.isFloatingPoint());
3359 return false;
3360 }
3361
3362 /// Return true if an fabs operation is free to the point where it is never
3363 /// worthwhile to replace it with a bitwise operation.
3364 virtual bool isFAbsFree(EVT VT) const {
3365 assert(VT.isFloatingPoint());
3366 return false;
3367 }
3368
3369 /// Return true if an FMA operation is faster than a pair of fmul and fadd
3370 /// instructions. fmuladd intrinsics will be expanded to FMAs when this method
3371 /// returns true, otherwise fmuladd is expanded to fmul + fadd.
3372 ///
3373 /// NOTE: This may be called before legalization on types for which FMAs are
3374 /// not legal, but should return true if those types will eventually legalize
3375 /// to types that support FMAs. After legalization, it will only be called on
3376 /// types that support FMAs (via Legal or Custom actions)
3377 ///
3378 /// Targets that care about soft float support should return false when soft
3379 /// float code is being generated (i.e. use-soft-float).
3381 EVT) const {
3382 return false;
3383 }
3384
3385 /// Return true if an FMA operation is faster than a pair of fmul and fadd
3386 /// instructions. fmuladd intrinsics will be expanded to FMAs when this method
3387 /// returns true, otherwise fmuladd is expanded to fmul + fadd.
3388 ///
3389 /// NOTE: This may be called before legalization on types for which FMAs are
3390 /// not legal, but should return true if those types will eventually legalize
3391 /// to types that support FMAs. After legalization, it will only be called on
3392 /// types that support FMAs (via Legal or Custom actions)
3394 LLT) const {
3395 return false;
3396 }
3397
3398 /// IR version
3399 virtual bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *) const {
3400 return false;
3401 }
3402
3403 /// Returns true if \p MI can be combined with another instruction to
3404 /// form TargetOpcode::G_FMAD. \p N may be an TargetOpcode::G_FADD,
3405 /// TargetOpcode::G_FSUB, or an TargetOpcode::G_FMUL which will be
3406 /// distributed into an fadd/fsub.
3407 virtual bool isFMADLegal(const MachineInstr &MI, LLT Ty) const {
3408 assert((MI.getOpcode() == TargetOpcode::G_FADD ||
3409 MI.getOpcode() == TargetOpcode::G_FSUB ||
3410 MI.getOpcode() == TargetOpcode::G_FMUL) &&
3411 "unexpected node in FMAD forming combine");
3412 switch (Ty.getScalarSizeInBits()) {
3413 case 16:
3414 return isOperationLegal(TargetOpcode::G_FMAD, MVT::f16);
3415 case 32:
3416 return isOperationLegal(TargetOpcode::G_FMAD, MVT::f32);
3417 case 64:
3418 return isOperationLegal(TargetOpcode::G_FMAD, MVT::f64);
3419 default:
3420 break;
3421 }
3422
3423 return false;
3424 }
3425
3426 /// Returns true if be combined with to form an ISD::FMAD. \p N may be an
3427 /// ISD::FADD, ISD::FSUB, or an ISD::FMUL which will be distributed into an
3428 /// fadd/fsub.
3429 virtual bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const {
3430 assert((N->getOpcode() == ISD::FADD || N->getOpcode() == ISD::FSUB ||
3431 N->getOpcode() == ISD::FMUL) &&
3432 "unexpected node in FMAD forming combine");
3433 return isOperationLegal(ISD::FMAD, N->getValueType(0));
3434 }
3435
3436 // Return true when the decision to generate FMA's (or FMS, FMLA etc) rather
3437 // than FMUL and ADD is delegated to the machine combiner.
3439 CodeGenOptLevel OptLevel) const {
3440 return false;
3441 }
3442
3443 /// Return true if it's profitable to narrow operations of type SrcVT to
3444 /// DestVT. e.g. on x86, it's profitable to narrow from i32 to i8 but not from
3445 /// i32 to i16.
3446 virtual bool isNarrowingProfitable(SDNode *N, EVT SrcVT, EVT DestVT) const {
3447 return false;
3448 }
3449
3450 /// Return true if pulling a binary operation into a select with an identity
3451 /// constant is profitable. This is the inverse of an IR transform.
3452 /// Example: X + (Cond ? Y : 0) --> Cond ? (X + Y) : X
3453 virtual bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode, EVT VT,
3454 unsigned SelectOpcode,
3455 SDValue X,
3456 SDValue Y) const {
3457 return false;
3458 }
3459
3460 /// Return true if it is beneficial to convert a load of a constant to
3461 /// just the constant itself.
3462 /// On some targets it might be more efficient to use a combination of
3463 /// arithmetic instructions to materialize the constant instead of loading it
3464 /// from a constant pool.
3466 Type *Ty) const {
3467 return false;
3468 }
3469
3470 /// Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type
3471 /// from this source type with this index. This is needed because
3472 /// EXTRACT_SUBVECTOR usually has custom lowering that depends on the index of
3473 /// the first element, and only the target knows which lowering is cheap.
3474 virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
3475 unsigned Index) const {
3476 return false;
3477 }
3478
3479 /// Try to convert an extract element of a vector binary operation into an
3480 /// extract element followed by a scalar operation.
3481 virtual bool shouldScalarizeBinop(SDValue VecOp) const {
3482 return false;
3483 }
3484
3485 /// Return true if extraction of a scalar element from the given vector type
3486 /// at the given index is cheap. For example, if scalar operations occur on
3487 /// the same register file as vector operations, then an extract element may
3488 /// be a sub-register rename rather than an actual instruction.
3489 virtual bool isExtractVecEltCheap(EVT VT, unsigned Index) const {
3490 return false;
3491 }
3492
3493 /// Try to convert math with an overflow comparison into the corresponding DAG
3494 /// node operation. Targets may want to override this independently of whether
3495 /// the operation is legal/custom for the given type because it may obscure
3496 /// matching of other patterns.
3497 virtual bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
3498 bool MathUsed) const {
3499 // Form it if it is legal.
3500 if (isOperationLegal(Opcode, VT))
3501 return true;
3502
3503 // TODO: The default logic is inherited from code in CodeGenPrepare.
3504 // The opcode should not make a difference by default?
3505 if (Opcode != ISD::UADDO)
3506 return false;
3507
3508 // Allow the transform as long as we have an integer type that is not
3509 // obviously illegal and unsupported and if the math result is used
3510 // besides the overflow check. On some targets (e.g. SPARC), it is
3511 // not profitable to form on overflow op if the math result has no
3512 // concrete users.
3513 if (VT.isVector())
3514 return false;
3515 return MathUsed && (VT.isSimple() || !isOperationExpand(Opcode, VT));
3516 }
3517
3518 // Return true if the target wants to optimize the mul overflow intrinsic
3519 // for the given \p VT.
3521 EVT VT) const {
3522 return false;
3523 }
3524
3525 // Return true if it is profitable to use a scalar input to a BUILD_VECTOR
3526 // even if the vector itself has multiple uses.
3527 virtual bool aggressivelyPreferBuildVectorSources(EVT VecVT) const {
3528 return false;
3529 }
3530
3531 // Return true if CodeGenPrepare should consider splitting large offset of a
3532 // GEP to make the GEP fit into the addressing mode and can be sunk into the
3533 // same blocks of its users.
3534 virtual bool shouldConsiderGEPOffsetSplit() const { return false; }
3535
3536 /// Return true if creating a shift of the type by the given
3537 /// amount is not profitable.
3538 virtual bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const {
3539 return false;
3540 }
3541
3542 // Should we fold (select_cc seteq (and x, y), 0, 0, A) -> (and (sra (shl x))
3543 // A) where y has a single bit set?
3545 const APInt &AndMask) const {
3546 unsigned ShCt = AndMask.getBitWidth() - 1;
3547 return !shouldAvoidTransformToShift(VT, ShCt);
3548 }
3549
3550 /// Does this target require the clearing of high-order bits in a register
3551 /// passed to the fp16 to fp conversion library function.
3552 virtual bool shouldKeepZExtForFP16Conv() const { return false; }
3553
3554 /// Should we generate fp_to_si_sat and fp_to_ui_sat from type FPVT to type VT
3555 /// from min(max(fptoi)) saturation patterns.
3556 virtual bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const {
3557 return isOperationLegalOrCustom(Op, VT);
3558 }
3559
3560 /// Should we prefer selects to doing arithmetic on boolean types
3562 return false;
3563 }
3564
3565 /// True if target has some particular form of dealing with pointer arithmetic
3566 /// semantics for pointers with the given value type. False if pointer
3567 /// arithmetic should not be preserved for passes such as instruction
3568 /// selection, and can fallback to regular arithmetic.
3569 /// This should be removed when PTRADD nodes are widely supported by backends.
3570 virtual bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const {
3571 return false;
3572 }
3573
3574 /// True if the target allows transformations of in-bounds pointer
3575 /// arithmetic that cause out-of-bounds intermediate results.
3577 EVT PtrVT) const {
3578 return false;
3579 }
3580
3581 /// Does this target support complex deinterleaving
3582 virtual bool isComplexDeinterleavingSupported() const { return false; }
3583
3584 /// Does this target support complex deinterleaving with the given operation
3585 /// and type
3588 return false;
3589 }
3590
3591 // Get the preferred opcode for FP_TO_XINT nodes.
3592 // By default, this checks if the provded operation is an illegal FP_TO_UINT
3593 // and if so, checks if FP_TO_SINT is legal or custom for use as a
3594 // replacement. If both UINT and SINT conversions are Custom, we choose SINT
3595 // by default because that's the right thing on PPC.
3596 virtual unsigned getPreferredFPToIntOpcode(unsigned Op, EVT FromVT,
3597 EVT ToVT) const {
3598 if (isOperationLegal(Op, ToVT))
3599 return Op;
3600 switch (Op) {
3601 case ISD::FP_TO_UINT:
3603 return ISD::FP_TO_SINT;
3604 break;
3608 break;
3609 case ISD::VP_FP_TO_UINT:
3610 if (isOperationLegalOrCustom(ISD::VP_FP_TO_SINT, ToVT))
3611 return ISD::VP_FP_TO_SINT;
3612 break;
3613 default:
3614 break;
3615 }
3616 return Op;
3617 }
3618
3619 /// Create the IR node for the given complex deinterleaving operation.
3620 /// If one cannot be created using all the given inputs, nullptr should be
3621 /// returned.
3624 ComplexDeinterleavingRotation Rotation, Value *InputA, Value *InputB,
3625 Value *Accumulator = nullptr) const {
3626 return nullptr;
3627 }
3628
3630 return RuntimeLibcallInfo;
3631 }
3632
3633 const LibcallLoweringInfo &getLibcallLoweringInfo() const { return Libcalls; }
3634
3635 void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
3636 Libcalls.setLibcallImpl(Call, Impl);
3637 }
3638
3639 /// Get the libcall impl routine name for the specified libcall.
3640 RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const {
3641 return Libcalls.getLibcallImpl(Call);
3642 }
3643
3644 /// Get the libcall routine name for the specified libcall.
3645 // FIXME: This should be removed. Only LibcallImpl should have a name.
3646 const char *getLibcallName(RTLIB::Libcall Call) const {
3647 return Libcalls.getLibcallName(Call);
3648 }
3649
3650 /// Get the libcall routine name for the specified libcall implementation
3654
3655 RTLIB::LibcallImpl getMemcpyImpl() const { return Libcalls.getMemcpyImpl(); }
3656
3657 /// Check if this is valid libcall for the current module, otherwise
3658 /// RTLIB::Unsupported.
3659 RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const {
3660 return RuntimeLibcallInfo.getSupportedLibcallImpl(FuncName);
3661 }
3662
3663 /// Get the comparison predicate that's to be used to test the result of the
3664 /// comparison libcall against zero. This should only be used with
3665 /// floating-point compare libcalls.
3666 ISD::CondCode getSoftFloatCmpLibcallPredicate(RTLIB::LibcallImpl Call) const;
3667
3668 /// Get the CallingConv that should be used for the specified libcall
3669 /// implementation.
3671 return Libcalls.getLibcallImplCallingConv(Call);
3672 }
3673
3674 /// Get the CallingConv that should be used for the specified libcall.
3675 // FIXME: Remove this wrapper and directly use the used LibcallImpl
3677 return Libcalls.getLibcallCallingConv(Call);
3678 }
3679
3680 /// Execute target specific actions to finalize target lowering.
3681 /// This is used to set extra flags in MachineFrameInformation and freezing
3682 /// the set of reserved registers.
3683 /// The default implementation just freezes the set of reserved registers.
3684 virtual void finalizeLowering(MachineFunction &MF) const;
3685
3686 /// Returns true if it's profitable to allow merging store of loads when there
3687 /// are functions calls between the load and the store.
3688 virtual bool shouldMergeStoreOfLoadsOverCall(EVT, EVT) const { return true; }
3689
3690 //===----------------------------------------------------------------------===//
3691 // GlobalISel Hooks
3692 //===----------------------------------------------------------------------===//
3693 /// Check whether or not \p MI needs to be moved close to its uses.
3694 virtual bool shouldLocalize(const MachineInstr &MI, const TargetTransformInfo *TTI) const;
3695
3696
3697private:
3698 const TargetMachine &TM;
3699
3700 /// Tells the code generator that the target has BitExtract instructions.
3701 /// The code generator will aggressively sink "shift"s into the blocks of
3702 /// their users if the users will generate "and" instructions which can be
3703 /// combined with "shift" to BitExtract instructions.
3704 bool HasExtractBitsInsn;
3705
3706 /// Tells the code generator to bypass slow divide or remainder
3707 /// instructions. For example, BypassSlowDivWidths[32,8] tells the code
3708 /// generator to bypass 32-bit integer div/rem with an 8-bit unsigned integer
3709 /// div/rem when the operands are positive and less than 256.
3710 DenseMap <unsigned int, unsigned int> BypassSlowDivWidths;
3711
3712 /// Tells the code generator that it shouldn't generate extra flow control
3713 /// instructions and should attempt to combine flow control instructions via
3714 /// predication.
3715 bool JumpIsExpensive;
3716
3717 /// Information about the contents of the high-bits in boolean values held in
3718 /// a type wider than i1. See getBooleanContents.
3719 BooleanContent BooleanContents;
3720
3721 /// Information about the contents of the high-bits in boolean values held in
3722 /// a type wider than i1. See getBooleanContents.
3723 BooleanContent BooleanFloatContents;
3724
3725 /// Information about the contents of the high-bits in boolean vector values
3726 /// when the element type is wider than i1. See getBooleanContents.
3727 BooleanContent BooleanVectorContents;
3728
3729 /// The target scheduling preference: shortest possible total cycles or lowest
3730 /// register usage.
3731 Sched::Preference SchedPreferenceInfo;
3732
3733 /// The minimum alignment that any argument on the stack needs to have.
3734 Align MinStackArgumentAlignment;
3735
3736 /// The minimum function alignment (used when optimizing for size, and to
3737 /// prevent explicitly provided alignment from leading to incorrect code).
3738 Align MinFunctionAlignment;
3739
3740 /// The preferred function alignment (used when alignment unspecified and
3741 /// optimizing for speed).
3742 Align PrefFunctionAlignment;
3743
3744 /// The preferred loop alignment (in log2 bot in bytes).
3745 Align PrefLoopAlignment;
3746 /// The maximum amount of bytes permitted to be emitted for alignment.
3747 unsigned MaxBytesForAlignment;
3748
3749 /// Size in bits of the maximum atomics size the backend supports.
3750 /// Accesses larger than this will be expanded by AtomicExpandPass.
3751 unsigned MaxAtomicSizeInBitsSupported;
3752
3753 /// Size in bits of the maximum div/rem size the backend supports.
3754 /// Larger operations will be expanded by ExpandIRInsts.
3755 unsigned MaxDivRemBitWidthSupported;
3756
3757 /// Size in bits of the maximum fp to/from int conversion size the
3758 /// backend supports. Larger operations will be expanded by
3759 /// ExpandIRInsts.
3760 unsigned MaxLargeFPConvertBitWidthSupported;
3761
3762 /// Size in bits of the minimum cmpxchg or ll/sc operation the
3763 /// backend supports.
3764 unsigned MinCmpXchgSizeInBits;
3765
3766 /// The minimum of largest number of comparisons to use bit test for switch.
3767 unsigned MinimumBitTestCmps;
3768
3769 /// This indicates if the target supports unaligned atomic operations.
3770 bool SupportsUnalignedAtomics;
3771
3772 /// If set to a physical register, this specifies the register that
3773 /// llvm.savestack/llvm.restorestack should save and restore.
3774 Register StackPointerRegisterToSaveRestore;
3775
3776 /// This indicates the default register class to use for each ValueType the
3777 /// target supports natively.
3778 const TargetRegisterClass *RegClassForVT[MVT::VALUETYPE_SIZE];
3779 uint16_t NumRegistersForVT[MVT::VALUETYPE_SIZE];
3780 MVT RegisterTypeForVT[MVT::VALUETYPE_SIZE];
3781
3782 /// This indicates the "representative" register class to use for each
3783 /// ValueType the target supports natively. This information is used by the
3784 /// scheduler to track register pressure. By default, the representative
3785 /// register class is the largest legal super-reg register class of the
3786 /// register class of the specified type. e.g. On x86, i8, i16, and i32's
3787 /// representative class would be GR32.
3788 const TargetRegisterClass *RepRegClassForVT[MVT::VALUETYPE_SIZE] = {nullptr};
3789
3790 /// This indicates the "cost" of the "representative" register class for each
3791 /// ValueType. The cost is used by the scheduler to approximate register
3792 /// pressure.
3793 uint8_t RepRegClassCostForVT[MVT::VALUETYPE_SIZE];
3794
3795 /// For any value types we are promoting or expanding, this contains the value
3796 /// type that we are changing to. For Expanded types, this contains one step
3797 /// of the expand (e.g. i64 -> i32), even if there are multiple steps required
3798 /// (e.g. i64 -> i16). For types natively supported by the system, this holds
3799 /// the same type (e.g. i32 -> i32).
3800 MVT TransformToType[MVT::VALUETYPE_SIZE];
3801
3802 /// For each operation and each value type, keep a LegalizeAction that
3803 /// indicates how instruction selection should deal with the operation. Most
3804 /// operations are Legal (aka, supported natively by the target), but
3805 /// operations that are not should be described. Note that operations on
3806 /// non-legal value types are not described here.
3807 LegalizeAction OpActions[MVT::VALUETYPE_SIZE][ISD::BUILTIN_OP_END];
3808
3809 /// For each load extension type and each value type, keep a LegalizeAction
3810 /// that indicates how instruction selection should deal with a load of a
3811 /// specific value type and extension type. Uses 4-bits to store the action
3812 /// for each of the 4 load ext types.
3813 uint16_t LoadExtActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE];
3814
3815 /// Similar to LoadExtActions, but for atomic loads. Only Legal or Expand
3816 /// (default) values are supported.
3817 uint16_t AtomicLoadExtActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE];
3818
3819 /// For each value type pair keep a LegalizeAction that indicates whether a
3820 /// truncating store of a specific value type and truncating type is legal.
3821 LegalizeAction TruncStoreActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE];
3822
3823 /// For each indexed mode and each value type, keep a quad of LegalizeAction
3824 /// that indicates how instruction selection should deal with the load /
3825 /// store / maskedload / maskedstore.
3826 ///
3827 /// The first dimension is the value_type for the reference. The second
3828 /// dimension represents the various modes for load store.
3829 uint16_t IndexedModeActions[MVT::VALUETYPE_SIZE][ISD::LAST_INDEXED_MODE];
3830
3831 /// For each condition code (ISD::CondCode) keep a LegalizeAction that
3832 /// indicates how instruction selection should deal with the condition code.
3833 ///
3834 /// Because each CC action takes up 4 bits, we need to have the array size be
3835 /// large enough to fit all of the value types. This can be done by rounding
3836 /// up the MVT::VALUETYPE_SIZE value to the next multiple of 8.
3837 uint32_t CondCodeActions[ISD::SETCC_INVALID][(MVT::VALUETYPE_SIZE + 7) / 8];
3838
3839 using PartialReduceActionTypes =
3840 std::tuple<unsigned, MVT::SimpleValueType, MVT::SimpleValueType>;
3841 /// For each partial reduce opcode, result type and input type combination,
3842 /// keep a LegalizeAction which indicates how instruction selection should
3843 /// deal with this operation.
3844 DenseMap<PartialReduceActionTypes, LegalizeAction> PartialReduceMLAActions;
3845
3846 ValueTypeActionImpl ValueTypeActions;
3847
3848private:
3849 /// Targets can specify ISD nodes that they would like PerformDAGCombine
3850 /// callbacks for by calling setTargetDAGCombine(), which sets a bit in this
3851 /// array.
3852 unsigned char
3853 TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT];
3854
3855 /// For operations that must be promoted to a specific type, this holds the
3856 /// destination type. This map should be sparse, so don't hold it as an
3857 /// array.
3858 ///
3859 /// Targets add entries to this map with AddPromotedToType(..), clients access
3860 /// this with getTypeToPromoteTo(..).
3861 std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType>
3862 PromoteToType;
3863
3864 /// FIXME: This should not live here; it should come from an analysis.
3865 const RTLIB::RuntimeLibcallsInfo RuntimeLibcallInfo;
3866
3867 /// The list of libcalls that the target will use.
3868 /// FIXME: This should not live here; it should come from an analysis.
3869 LibcallLoweringInfo Libcalls;
3870
3871 /// The bits of IndexedModeActions used to store the legalisation actions
3872 /// We store the data as | ML | MS | L | S | each taking 4 bits.
3873 enum IndexedModeActionsBits {
3874 IMAB_Store = 0,
3875 IMAB_Load = 4,
3876 IMAB_MaskedStore = 8,
3877 IMAB_MaskedLoad = 12
3878 };
3879
3880 void setIndexedModeAction(unsigned IdxMode, MVT VT, unsigned Shift,
3881 LegalizeAction Action) {
3882 assert(VT.isValid() && IdxMode < ISD::LAST_INDEXED_MODE &&
3883 (unsigned)Action < 0xf && "Table isn't big enough!");
3884 unsigned Ty = (unsigned)VT.SimpleTy;
3885 IndexedModeActions[Ty][IdxMode] &= ~(0xf << Shift);
3886 IndexedModeActions[Ty][IdxMode] |= ((uint16_t)Action) << Shift;
3887 }
3888
3889 LegalizeAction getIndexedModeAction(unsigned IdxMode, MVT VT,
3890 unsigned Shift) const {
3891 assert(IdxMode < ISD::LAST_INDEXED_MODE && VT.isValid() &&
3892 "Table isn't big enough!");
3893 unsigned Ty = (unsigned)VT.SimpleTy;
3894 return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] >> Shift) & 0xf);
3895 }
3896
3897protected:
3898 /// Return true if the extension represented by \p I is free.
3899 /// \pre \p I is a sign, zero, or fp extension and
3900 /// is[Z|FP]ExtFree of the related types is not true.
3901 virtual bool isExtFreeImpl(const Instruction *I) const { return false; }
3902
3903 /// Depth that GatherAllAliases should continue looking for chain
3904 /// dependencies when trying to find a more preferable chain. As an
3905 /// approximation, this should be more than the number of consecutive stores
3906 /// expected to be merged.
3908
3909 /// \brief Specify maximum number of store instructions per memset call.
3910 ///
3911 /// When lowering \@llvm.memset this field specifies the maximum number of
3912 /// store operations that may be substituted for the call to memset. Targets
3913 /// must set this value based on the cost threshold for that target. Targets
3914 /// should assume that the memset will be done using as many of the largest
3915 /// store operations first, followed by smaller ones, if necessary, per
3916 /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine
3917 /// with 16-bit alignment would result in four 2-byte stores and one 1-byte
3918 /// store. This only applies to setting a constant array of a constant size.
3920 /// Likewise for functions with the OptSize attribute.
3922
3923 /// \brief Specify maximum number of store instructions per memcpy call.
3924 ///
3925 /// When lowering \@llvm.memcpy this field specifies the maximum number of
3926 /// store operations that may be substituted for a call to memcpy. Targets
3927 /// must set this value based on the cost threshold for that target. Targets
3928 /// should assume that the memcpy will be done using as many of the largest
3929 /// store operations first, followed by smaller ones, if necessary, per
3930 /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine
3931 /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store
3932 /// and one 1-byte store. This only applies to copying a constant array of
3933 /// constant size.
3935 /// Likewise for functions with the OptSize attribute.
3937 /// \brief Specify max number of store instructions to glue in inlined memcpy.
3938 ///
3939 /// When memcpy is inlined based on MaxStoresPerMemcpy, specify maximum number
3940 /// of store instructions to keep together. This helps in pairing and
3941 // vectorization later on.
3943
3944 /// \brief Specify maximum number of load instructions per memcmp call.
3945 ///
3946 /// When lowering \@llvm.memcmp this field specifies the maximum number of
3947 /// pairs of load operations that may be substituted for a call to memcmp.
3948 /// Targets must set this value based on the cost threshold for that target.
3949 /// Targets should assume that the memcmp will be done using as many of the
3950 /// largest load operations first, followed by smaller ones, if necessary, per
3951 /// alignment restrictions. For example, loading 7 bytes on a 32-bit machine
3952 /// with 32-bit alignment would result in one 4-byte load, a one 2-byte load
3953 /// and one 1-byte load. This only applies to copying a constant array of
3954 /// constant size.
3956 /// Likewise for functions with the OptSize attribute.
3958
3959 /// \brief Specify maximum number of store instructions per memmove call.
3960 ///
3961 /// When lowering \@llvm.memmove this field specifies the maximum number of
3962 /// store instructions that may be substituted for a call to memmove. Targets
3963 /// must set this value based on the cost threshold for that target. Targets
3964 /// should assume that the memmove will be done using as many of the largest
3965 /// store operations first, followed by smaller ones, if necessary, per
3966 /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine
3967 /// with 8-bit alignment would result in nine 1-byte stores. This only
3968 /// applies to copying a constant array of constant size.
3970 /// Likewise for functions with the OptSize attribute.
3972
3973 /// Tells the code generator that select is more expensive than a branch if
3974 /// the branch is usually predicted right.
3976
3977 /// \see enableExtLdPromotion.
3979
3980 /// Return true if the value types that can be represented by the specified
3981 /// register class are all legal.
3982 bool isLegalRC(const TargetRegisterInfo &TRI,
3983 const TargetRegisterClass &RC) const;
3984
3985 /// Replace/modify any TargetFrameIndex operands with a targte-dependent
3986 /// sequence of memory operands that is recognized by PrologEpilogInserter.
3988 MachineBasicBlock *MBB) const;
3989
3991};
3992
3993/// This class defines information used to lower LLVM code to legal SelectionDAG
3994/// operators that the target instruction selector can accept natively.
3995///
3996/// This class also defines callbacks that targets must implement to lower
3997/// target-specific constructs to SelectionDAG operators.
3999public:
4000 struct DAGCombinerInfo;
4001 struct MakeLibCallOptions;
4002
4005
4006 explicit TargetLowering(const TargetMachine &TM,
4007 const TargetSubtargetInfo &STI);
4009
4010 bool isPositionIndependent() const;
4011
4014 UniformityInfo *UA) const {
4015 return false;
4016 }
4017
4018 // Lets target to control the following reassociation of operands: (op (op x,
4019 // c1), y) -> (op (op x, y), c1) where N0 is (op x, c1) and N1 is y. By
4020 // default consider profitable any case where N0 has single use. This
4021 // behavior reflects the condition replaced by this target hook call in the
4022 // DAGCombiner. Any particular target can implement its own heuristic to
4023 // restrict common combiner.
4025 SDValue N1) const {
4026 return N0.hasOneUse();
4027 }
4028
4029 // Lets target to control the following reassociation of operands: (op (op x,
4030 // c1), y) -> (op (op x, y), c1) where N0 is (op x, c1) and N1 is y. By
4031 // default consider profitable any case where N0 has single use. This
4032 // behavior reflects the condition replaced by this target hook call in the
4033 // combiner. Any particular target can implement its own heuristic to
4034 // restrict common combiner.
4036 Register N1) const {
4037 return MRI.hasOneNonDBGUse(N0);
4038 }
4039
4040 virtual bool isSDNodeAlwaysUniform(const SDNode * N) const {
4041 return false;
4042 }
4043
4044 /// Returns true by value, base pointer and offset pointer and addressing mode
4045 /// by reference if the node's address can be legally represented as
4046 /// pre-indexed load / store address.
4047 virtual bool getPreIndexedAddressParts(SDNode * /*N*/, SDValue &/*Base*/,
4048 SDValue &/*Offset*/,
4049 ISD::MemIndexedMode &/*AM*/,
4050 SelectionDAG &/*DAG*/) const {
4051 return false;
4052 }
4053
4054 /// Returns true by value, base pointer and offset pointer and addressing mode
4055 /// by reference if this node can be combined with a load / store to form a
4056 /// post-indexed load / store.
4057 virtual bool getPostIndexedAddressParts(SDNode * /*N*/, SDNode * /*Op*/,
4058 SDValue &/*Base*/,
4059 SDValue &/*Offset*/,
4060 ISD::MemIndexedMode &/*AM*/,
4061 SelectionDAG &/*DAG*/) const {
4062 return false;
4063 }
4064
4065 /// Returns true if the specified base+offset is a legal indexed addressing
4066 /// mode for this target. \p MI is the load or store instruction that is being
4067 /// considered for transformation.
4069 bool IsPre, MachineRegisterInfo &MRI) const {
4070 return false;
4071 }
4072
4073 /// Return the entry encoding for a jump table in the current function. The
4074 /// returned value is a member of the MachineJumpTableInfo::JTEntryKind enum.
4075 virtual unsigned getJumpTableEncoding() const;
4076
4077 virtual MVT getJumpTableRegTy(const DataLayout &DL) const {
4078 return getPointerTy(DL);
4079 }
4080
4081 virtual const MCExpr *
4083 const MachineBasicBlock * /*MBB*/, unsigned /*uid*/,
4084 MCContext &/*Ctx*/) const {
4085 llvm_unreachable("Need to implement this hook if target has custom JTIs");
4086 }
4087
4088 /// Returns relocation base for the given PIC jumptable.
4089 virtual SDValue getPICJumpTableRelocBase(SDValue Table,
4090 SelectionDAG &DAG) const;
4091
4092 /// This returns the relocation base for the given PIC jumptable, the same as
4093 /// getPICJumpTableRelocBase, but as an MCExpr.
4094 virtual const MCExpr *
4095 getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
4096 unsigned JTI, MCContext &Ctx) const;
4097
4098 /// Return true if folding a constant offset with the given GlobalAddress is
4099 /// legal. It is frequently not legal in PIC relocation models.
4100 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
4101
4102 /// On x86, return true if the operand with index OpNo is a CALL or JUMP
4103 /// instruction, which can use either a memory constraint or an address
4104 /// constraint. -fasm-blocks "__asm call foo" lowers to
4105 /// call void asm sideeffect inteldialect "call ${0:P}", "*m..."
4106 ///
4107 /// This function is used by a hack to choose the address constraint,
4108 /// lowering to a direct call.
4109 virtual bool
4111 unsigned OpNo) const {
4112 return false;
4113 }
4114
4116 SDValue &Chain) const;
4117
4118 void softenSetCCOperands(SelectionDAG &DAG, EVT VT, SDValue &NewLHS,
4119 SDValue &NewRHS, ISD::CondCode &CCCode,
4120 const SDLoc &DL, const SDValue OldLHS,
4121 const SDValue OldRHS) const;
4122
4123 void softenSetCCOperands(SelectionDAG &DAG, EVT VT, SDValue &NewLHS,
4124 SDValue &NewRHS, ISD::CondCode &CCCode,
4125 const SDLoc &DL, const SDValue OldLHS,
4126 const SDValue OldRHS, SDValue &Chain,
4127 bool IsSignaling = false) const;
4128
4130 SDValue Chain, MachineMemOperand *MMO,
4131 SDValue &NewLoad, SDValue Ptr,
4132 SDValue PassThru, SDValue Mask) const {
4133 llvm_unreachable("Not Implemented");
4134 }
4135
4137 SDValue Chain, MachineMemOperand *MMO,
4138 SDValue Ptr, SDValue Val,
4139 SDValue Mask) const {
4140 llvm_unreachable("Not Implemented");
4141 }
4142
4143 /// Returns a pair of (return value, chain).
4144 /// It is an error to pass RTLIB::Unsupported as \p LibcallImpl
4145 std::pair<SDValue, SDValue>
4146 makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl, EVT RetVT,
4147 ArrayRef<SDValue> Ops, MakeLibCallOptions CallOptions,
4148 const SDLoc &dl, SDValue Chain = SDValue()) const;
4149
4150 /// It is an error to pass RTLIB::UNKNOWN_LIBCALL as \p LC.
4151 std::pair<SDValue, SDValue> makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC,
4152 EVT RetVT, ArrayRef<SDValue> Ops,
4153 MakeLibCallOptions CallOptions,
4154 const SDLoc &dl,
4155 SDValue Chain = SDValue()) const {
4156 return makeLibCall(DAG, getLibcallImpl(LC), RetVT, Ops, CallOptions, dl,
4157 Chain);
4158 }
4159
4160 /// Check whether parameters to a call that are passed in callee saved
4161 /// registers are the same as from the calling function. This needs to be
4162 /// checked for tail call eligibility.
4163 bool parametersInCSRMatch(const MachineRegisterInfo &MRI,
4164 const uint32_t *CallerPreservedMask,
4165 const SmallVectorImpl<CCValAssign> &ArgLocs,
4166 const SmallVectorImpl<SDValue> &OutVals) const;
4167
4168 //===--------------------------------------------------------------------===//
4169 // TargetLowering Optimization Methods
4170 //
4171
4172 /// A convenience struct that encapsulates a DAG, and two SDValues for
4173 /// returning information from TargetLowering to its clients that want to
4174 /// combine.
4181
4183 bool LT, bool LO) :
4184 DAG(InDAG), LegalTys(LT), LegalOps(LO) {}
4185
4186 bool LegalTypes() const { return LegalTys; }
4187 bool LegalOperations() const { return LegalOps; }
4188
4190 Old = O;
4191 New = N;
4192 return true;
4193 }
4194 };
4195
4196 /// Determines the optimal series of memory ops to replace the memset / memcpy.
4197 /// Return true if the number of memory ops is below the threshold (Limit).
4198 /// Note that this is always the case when Limit is ~0.
4199 /// It returns the types of the sequence of memory ops to perform
4200 /// memset / memcpy by reference.
4201 virtual bool
4202 findOptimalMemOpLowering(LLVMContext &Context, std::vector<EVT> &MemOps,
4203 unsigned Limit, const MemOp &Op, unsigned DstAS,
4204 unsigned SrcAS,
4205 const AttributeList &FuncAttributes) const;
4206
4207 /// Check to see if the specified operand of the specified instruction is a
4208 /// constant integer. If so, check to see if there are any bits set in the
4209 /// constant that are not demanded. If so, shrink the constant and return
4210 /// true.
4212 const APInt &DemandedElts,
4213 TargetLoweringOpt &TLO) const;
4214
4215 /// Helper wrapper around ShrinkDemandedConstant, demanding all elements.
4217 TargetLoweringOpt &TLO) const;
4218
4219 // Target hook to do target-specific const optimization, which is called by
4220 // ShrinkDemandedConstant. This function should return true if the target
4221 // doesn't want ShrinkDemandedConstant to further optimize the constant.
4223 const APInt &DemandedBits,
4224 const APInt &DemandedElts,
4225 TargetLoweringOpt &TLO) const {
4226 return false;
4227 }
4228
4229 /// Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the casts are free.
4230 /// This uses isTruncateFree/isZExtFree and ANY_EXTEND for the widening cast,
4231 /// but it could be generalized for targets with other types of implicit
4232 /// widening casts.
4233 bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth,
4234 const APInt &DemandedBits,
4235 TargetLoweringOpt &TLO) const;
4236
4237 /// Look at Op. At this point, we know that only the DemandedBits bits of the
4238 /// result of Op are ever used downstream. If we can use this information to
4239 /// simplify Op, create a new simplified DAG node and return true, returning
4240 /// the original and new nodes in Old and New. Otherwise, analyze the
4241 /// expression and return a mask of KnownOne and KnownZero bits for the
4242 /// expression (used to simplify the caller). The KnownZero/One bits may only
4243 /// be accurate for those bits in the Demanded masks.
4244 /// \p AssumeSingleUse When this parameter is true, this function will
4245 /// attempt to simplify \p Op even if there are multiple uses.
4246 /// Callers are responsible for correctly updating the DAG based on the
4247 /// results of this function, because simply replacing TLO.Old
4248 /// with TLO.New will be incorrect when this parameter is true and TLO.Old
4249 /// has multiple uses.
4250 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
4251 const APInt &DemandedElts, KnownBits &Known,
4252 TargetLoweringOpt &TLO, unsigned Depth = 0,
4253 bool AssumeSingleUse = false) const;
4254
4255 /// Helper wrapper around SimplifyDemandedBits, demanding all elements.
4256 /// Adds Op back to the worklist upon success.
4257 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
4258 KnownBits &Known, TargetLoweringOpt &TLO,
4259 unsigned Depth = 0,
4260 bool AssumeSingleUse = false) const;
4261
4262 /// Helper wrapper around SimplifyDemandedBits.
4263 /// Adds Op back to the worklist upon success.
4264 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
4265 DAGCombinerInfo &DCI) const;
4266
4267 /// Helper wrapper around SimplifyDemandedBits.
4268 /// Adds Op back to the worklist upon success.
4269 bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
4270 const APInt &DemandedElts,
4271 DAGCombinerInfo &DCI) const;
4272
4273 /// More limited version of SimplifyDemandedBits that can be used to "look
4274 /// through" ops that don't contribute to the DemandedBits/DemandedElts -
4275 /// bitwise ops etc.
4276 SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits,
4277 const APInt &DemandedElts,
4278 SelectionDAG &DAG,
4279 unsigned Depth = 0) const;
4280
4281 /// Helper wrapper around SimplifyMultipleUseDemandedBits, demanding all
4282 /// elements.
4283 SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits,
4284 SelectionDAG &DAG,
4285 unsigned Depth = 0) const;
4286
4287 /// Helper wrapper around SimplifyMultipleUseDemandedBits, demanding all
4288 /// bits from only some vector elements.
4289 SDValue SimplifyMultipleUseDemandedVectorElts(SDValue Op,
4290 const APInt &DemandedElts,
4291 SelectionDAG &DAG,
4292 unsigned Depth = 0) const;
4293
4294 /// Look at Vector Op. At this point, we know that only the DemandedElts
4295 /// elements of the result of Op are ever used downstream. If we can use
4296 /// this information to simplify Op, create a new simplified DAG node and
4297 /// return true, storing the original and new nodes in TLO.
4298 /// Otherwise, analyze the expression and return a mask of KnownUndef and
4299 /// KnownZero elements for the expression (used to simplify the caller).
4300 /// The KnownUndef/Zero elements may only be accurate for those bits
4301 /// in the DemandedMask.
4302 /// \p AssumeSingleUse When this parameter is true, this function will
4303 /// attempt to simplify \p Op even if there are multiple uses.
4304 /// Callers are responsible for correctly updating the DAG based on the
4305 /// results of this function, because simply replacing TLO.Old
4306 /// with TLO.New will be incorrect when this parameter is true and TLO.Old
4307 /// has multiple uses.
4308 bool SimplifyDemandedVectorElts(SDValue Op, const APInt &DemandedEltMask,
4309 APInt &KnownUndef, APInt &KnownZero,
4310 TargetLoweringOpt &TLO, unsigned Depth = 0,
4311 bool AssumeSingleUse = false) const;
4312
4313 /// Helper wrapper around SimplifyDemandedVectorElts.
4314 /// Adds Op back to the worklist upon success.
4315 bool SimplifyDemandedVectorElts(SDValue Op, const APInt &DemandedElts,
4316 DAGCombinerInfo &DCI) const;
4317
4318 /// Return true if the target supports simplifying demanded vector elements by
4319 /// converting them to undefs.
4320 virtual bool
4322 const TargetLoweringOpt &TLO) const {
4323 return true;
4324 }
4325
4326 /// Determine which of the bits specified in Mask are known to be either zero
4327 /// or one and return them in the KnownZero/KnownOne bitsets. The DemandedElts
4328 /// argument allows us to only collect the known bits that are shared by the
4329 /// requested vector elements.
4330 virtual void computeKnownBitsForTargetNode(const SDValue Op,
4331 KnownBits &Known,
4332 const APInt &DemandedElts,
4333 const SelectionDAG &DAG,
4334 unsigned Depth = 0) const;
4335
4336 /// Determine which of the bits specified in Mask are known to be either zero
4337 /// or one and return them in the KnownZero/KnownOne bitsets. The DemandedElts
4338 /// argument allows us to only collect the known bits that are shared by the
4339 /// requested vector elements. This is for GISel.
4340 virtual void computeKnownBitsForTargetInstr(GISelValueTracking &Analysis,
4341 Register R, KnownBits &Known,
4342 const APInt &DemandedElts,
4343 const MachineRegisterInfo &MRI,
4344 unsigned Depth = 0) const;
4345
4346 virtual void computeKnownFPClassForTargetInstr(GISelValueTracking &Analysis,
4347 Register R,
4348 KnownFPClass &Known,
4349 const APInt &DemandedElts,
4350 const MachineRegisterInfo &MRI,
4351 unsigned Depth = 0) const;
4352
4353 /// Determine the known alignment for the pointer value \p R. This is can
4354 /// typically be inferred from the number of low known 0 bits. However, for a
4355 /// pointer with a non-integral address space, the alignment value may be
4356 /// independent from the known low bits.
4357 virtual Align computeKnownAlignForTargetInstr(GISelValueTracking &Analysis,
4358 Register R,
4359 const MachineRegisterInfo &MRI,
4360 unsigned Depth = 0) const;
4361
4362 /// Determine which of the bits of FrameIndex \p FIOp are known to be 0.
4363 /// Default implementation computes low bits based on alignment
4364 /// information. This should preserve known bits passed into it.
4365 virtual void computeKnownBitsForFrameIndex(int FIOp,
4366 KnownBits &Known,
4367 const MachineFunction &MF) const;
4368
4369 /// This method can be implemented by targets that want to expose additional
4370 /// information about sign bits to the DAG Combiner. The DemandedElts
4371 /// argument allows us to only collect the minimum sign bits that are shared
4372 /// by the requested vector elements.
4373 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
4374 const APInt &DemandedElts,
4375 const SelectionDAG &DAG,
4376 unsigned Depth = 0) const;
4377
4378 /// This method can be implemented by targets that want to expose additional
4379 /// information about sign bits to GlobalISel combiners. The DemandedElts
4380 /// argument allows us to only collect the minimum sign bits that are shared
4381 /// by the requested vector elements.
4382 virtual unsigned computeNumSignBitsForTargetInstr(
4383 GISelValueTracking &Analysis, Register R, const APInt &DemandedElts,
4384 const MachineRegisterInfo &MRI, unsigned Depth = 0) const;
4385
4386 /// Attempt to simplify any target nodes based on the demanded vector
4387 /// elements, returning true on success. Otherwise, analyze the expression and
4388 /// return a mask of KnownUndef and KnownZero elements for the expression
4389 /// (used to simplify the caller). The KnownUndef/Zero elements may only be
4390 /// accurate for those bits in the DemandedMask.
4391 virtual bool SimplifyDemandedVectorEltsForTargetNode(
4392 SDValue Op, const APInt &DemandedElts, APInt &KnownUndef,
4393 APInt &KnownZero, TargetLoweringOpt &TLO, unsigned Depth = 0) const;
4394
4395 /// Attempt to simplify any target nodes based on the demanded bits/elts,
4396 /// returning true on success. Otherwise, analyze the
4397 /// expression and return a mask of KnownOne and KnownZero bits for the
4398 /// expression (used to simplify the caller). The KnownZero/One bits may only
4399 /// be accurate for those bits in the Demanded masks.
4400 virtual bool SimplifyDemandedBitsForTargetNode(SDValue Op,
4401 const APInt &DemandedBits,
4402 const APInt &DemandedElts,
4403 KnownBits &Known,
4404 TargetLoweringOpt &TLO,
4405 unsigned Depth = 0) const;
4406
4407 /// More limited version of SimplifyDemandedBits that can be used to "look
4408 /// through" ops that don't contribute to the DemandedBits/DemandedElts -
4409 /// bitwise ops etc.
4410 virtual SDValue SimplifyMultipleUseDemandedBitsForTargetNode(
4411 SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
4412 SelectionDAG &DAG, unsigned Depth) const;
4413
4414 /// Return true if this function can prove that \p Op is never poison
4415 /// and, if \p PoisonOnly is false, does not have undef bits. The DemandedElts
4416 /// argument limits the check to the requested vector elements.
4417 virtual bool isGuaranteedNotToBeUndefOrPoisonForTargetNode(
4418 SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
4419 bool PoisonOnly, unsigned Depth) const;
4420
4421 /// Return true if Op can create undef or poison from non-undef & non-poison
4422 /// operands. The DemandedElts argument limits the check to the requested
4423 /// vector elements.
4424 virtual bool
4425 canCreateUndefOrPoisonForTargetNode(SDValue Op, const APInt &DemandedElts,
4426 const SelectionDAG &DAG, bool PoisonOnly,
4427 bool ConsiderFlags, unsigned Depth) const;
4428
4429 /// Tries to build a legal vector shuffle using the provided parameters
4430 /// or equivalent variations. The Mask argument maybe be modified as the
4431 /// function tries different variations.
4432 /// Returns an empty SDValue if the operation fails.
4433 SDValue buildLegalVectorShuffle(EVT VT, const SDLoc &DL, SDValue N0,
4435 SelectionDAG &DAG) const;
4436
4437 /// This method returns the constant pool value that will be loaded by LD.
4438 /// NOTE: You must check for implicit extensions of the constant by LD.
4439 virtual const Constant *getTargetConstantFromLoad(LoadSDNode *LD) const;
4440
4441 /// If \p SNaN is false, \returns true if \p Op is known to never be any
4442 /// NaN. If \p sNaN is true, returns if \p Op is known to never be a signaling
4443 /// NaN.
4444 virtual bool isKnownNeverNaNForTargetNode(SDValue Op,
4445 const APInt &DemandedElts,
4446 const SelectionDAG &DAG,
4447 bool SNaN = false,
4448 unsigned Depth = 0) const;
4449
4450 /// Return true if vector \p Op has the same value across all \p DemandedElts,
4451 /// indicating any elements which may be undef in the output \p UndefElts.
4452 virtual bool isSplatValueForTargetNode(SDValue Op, const APInt &DemandedElts,
4453 APInt &UndefElts,
4454 const SelectionDAG &DAG,
4455 unsigned Depth = 0) const;
4456
4457 /// Returns true if the given Opc is considered a canonical constant for the
4458 /// target, which should not be transformed back into a BUILD_VECTOR.
4460 return Op.getOpcode() == ISD::SPLAT_VECTOR ||
4461 Op.getOpcode() == ISD::SPLAT_VECTOR_PARTS;
4462 }
4463
4464 /// Return true if the given select/vselect should be considered canonical and
4465 /// not be transformed. Currently only used for "vselect (not Cond), N1, N2 ->
4466 /// vselect Cond, N2, N1".
4467 virtual bool isTargetCanonicalSelect(SDNode *N) const { return false; }
4468
4470 void *DC; // The DAG Combiner object.
4473
4474 public:
4476
4477 DAGCombinerInfo(SelectionDAG &dag, CombineLevel level, bool cl, void *dc)
4478 : DC(dc), Level(level), CalledByLegalizer(cl), DAG(dag) {}
4479
4480 bool isBeforeLegalize() const { return Level == BeforeLegalizeTypes; }
4482 bool isAfterLegalizeDAG() const { return Level >= AfterLegalizeDAG; }
4485
4486 LLVM_ABI void AddToWorklist(SDNode *N);
4487 LLVM_ABI SDValue CombineTo(SDNode *N, ArrayRef<SDValue> To,
4488 bool AddTo = true);
4489 LLVM_ABI SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true);
4490 LLVM_ABI SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1,
4491 bool AddTo = true);
4492
4493 LLVM_ABI bool recursivelyDeleteUnusedNodes(SDNode *N);
4494
4495 LLVM_ABI void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO);
4496 };
4497
4498 /// Return if the N is a constant or constant vector equal to the true value
4499 /// from getBooleanContents().
4500 bool isConstTrueVal(SDValue N) const;
4501
4502 /// Return if the N is a constant or constant vector equal to the false value
4503 /// from getBooleanContents().
4504 bool isConstFalseVal(SDValue N) const;
4505
4506 /// Return if \p N is a True value when extended to \p VT.
4507 bool isExtendedTrueVal(const ConstantSDNode *N, EVT VT, bool SExt) const;
4508
4509 /// Try to simplify a setcc built with the specified operands and cc. If it is
4510 /// unable to simplify it, return a null SDValue.
4511 SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond,
4512 bool foldBooleans, DAGCombinerInfo &DCI,
4513 const SDLoc &dl) const;
4514
4515 // For targets which wrap address, unwrap for analysis.
4516 virtual SDValue unwrapAddress(SDValue N) const { return N; }
4517
4518 /// Returns true (and the GlobalValue and the offset) if the node is a
4519 /// GlobalAddress + offset.
4520 virtual bool
4521 isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const;
4522
4523 /// This method will be invoked for all target nodes and for any
4524 /// target-independent nodes that the target has registered with invoke it
4525 /// for.
4526 ///
4527 /// The semantics are as follows:
4528 /// Return Value:
4529 /// SDValue.Val == 0 - No change was made
4530 /// SDValue.Val == N - N was replaced, is dead, and is already handled.
4531 /// otherwise - N should be replaced by the returned Operand.
4532 ///
4533 /// In addition, methods provided by DAGCombinerInfo may be used to perform
4534 /// more complex transformations.
4535 ///
4536 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
4537
4538 /// Return true if it is profitable to move this shift by a constant amount
4539 /// through its operand, adjusting any immediate operands as necessary to
4540 /// preserve semantics. This transformation may not be desirable if it
4541 /// disrupts a particularly auspicious target-specific tree (e.g. bitfield
4542 /// extraction in AArch64). By default, it returns true.
4543 ///
4544 /// @param N the shift node
4545 /// @param Level the current DAGCombine legalization level.
4547 CombineLevel Level) const {
4548 SDValue ShiftLHS = N->getOperand(0);
4549 if (!ShiftLHS->hasOneUse())
4550 return false;
4551 if (ShiftLHS.getOpcode() == ISD::SIGN_EXTEND &&
4552 !ShiftLHS.getOperand(0)->hasOneUse())
4553 return false;
4554 return true;
4555 }
4556
4557 /// GlobalISel - return true if it is profitable to move this shift by a
4558 /// constant amount through its operand, adjusting any immediate operands as
4559 /// necessary to preserve semantics. This transformation may not be desirable
4560 /// if it disrupts a particularly auspicious target-specific tree (e.g.
4561 /// bitfield extraction in AArch64). By default, it returns true.
4562 ///
4563 /// @param MI the shift instruction
4564 /// @param IsAfterLegal true if running after legalization.
4566 bool IsAfterLegal) const {
4567 return true;
4568 }
4569
4570 /// GlobalISel - return true if it's profitable to perform the combine:
4571 /// shl ([sza]ext x), y => zext (shl x, y)
4572 virtual bool isDesirableToPullExtFromShl(const MachineInstr &MI) const {
4573 return true;
4574 }
4575
4576 // Return AndOrSETCCFoldKind::{AddAnd, ABS} if its desirable to try and
4577 // optimize LogicOp(SETCC0, SETCC1). An example (what is implemented as of
4578 // writing this) is:
4579 // With C as a power of 2 and C != 0 and C != INT_MIN:
4580 // AddAnd:
4581 // (icmp eq A, C) | (icmp eq A, -C)
4582 // -> (icmp eq and(add(A, C), ~(C + C)), 0)
4583 // (icmp ne A, C) & (icmp ne A, -C)w
4584 // -> (icmp ne and(add(A, C), ~(C + C)), 0)
4585 // ABS:
4586 // (icmp eq A, C) | (icmp eq A, -C)
4587 // -> (icmp eq Abs(A), C)
4588 // (icmp ne A, C) & (icmp ne A, -C)w
4589 // -> (icmp ne Abs(A), C)
4590 //
4591 // @param LogicOp the logic op
4592 // @param SETCC0 the first of the SETCC nodes
4593 // @param SETCC0 the second of the SETCC nodes
4595 const SDNode *LogicOp, const SDNode *SETCC0, const SDNode *SETCC1) const {
4597 }
4598
4599 /// Return true if it is profitable to combine an XOR of a logical shift
4600 /// to create a logical shift of NOT. This transformation may not be desirable
4601 /// if it disrupts a particularly auspicious target-specific tree (e.g.
4602 /// BIC on ARM/AArch64). By default, it returns true.
4603 virtual bool isDesirableToCommuteXorWithShift(const SDNode *N) const {
4604 return true;
4605 }
4606
4607 /// Return true if the target has native support for the specified value type
4608 /// and it is 'desirable' to use the type for the given node type. e.g. On x86
4609 /// i16 is legal, but undesirable since i16 instruction encodings are longer
4610 /// and some i16 instructions are slow.
4611 virtual bool isTypeDesirableForOp(unsigned /*Opc*/, EVT VT) const {
4612 // By default, assume all legal types are desirable.
4613 return isTypeLegal(VT);
4614 }
4615
4616 /// Return true if it is profitable for dag combiner to transform a floating
4617 /// point op of specified opcode to a equivalent op of an integer
4618 /// type. e.g. f32 load -> i32 load can be profitable on ARM.
4619 virtual bool isDesirableToTransformToIntegerOp(unsigned /*Opc*/,
4620 EVT /*VT*/) const {
4621 return false;
4622 }
4623
4624 /// This method query the target whether it is beneficial for dag combiner to
4625 /// promote the specified node. If true, it should return the desired
4626 /// promotion type by reference.
4627 virtual bool IsDesirableToPromoteOp(SDValue /*Op*/, EVT &/*PVT*/) const {
4628 return false;
4629 }
4630
4631 /// Return true if the target supports swifterror attribute. It optimizes
4632 /// loads and stores to reading and writing a specific register.
4633 virtual bool supportSwiftError() const {
4634 return false;
4635 }
4636
4637 /// Return true if the target supports that a subset of CSRs for the given
4638 /// machine function is handled explicitly via copies.
4639 virtual bool supportSplitCSR(MachineFunction *MF) const {
4640 return false;
4641 }
4642
4643 /// Return true if the target supports kcfi operand bundles.
4644 virtual bool supportKCFIBundles() const { return false; }
4645
4646 /// Return true if the target supports ptrauth operand bundles.
4647 virtual bool supportPtrAuthBundles() const { return false; }
4648
4649 /// Perform necessary initialization to handle a subset of CSRs explicitly
4650 /// via copies. This function is called at the beginning of instruction
4651 /// selection.
4652 virtual void initializeSplitCSR(MachineBasicBlock *Entry) const {
4653 llvm_unreachable("Not Implemented");
4654 }
4655
4656 /// Insert explicit copies in entry and exit blocks. We copy a subset of
4657 /// CSRs to virtual registers in the entry block, and copy them back to
4658 /// physical registers in the exit blocks. This function is called at the end
4659 /// of instruction selection.
4661 MachineBasicBlock *Entry,
4662 const SmallVectorImpl<MachineBasicBlock *> &Exits) const {
4663 llvm_unreachable("Not Implemented");
4664 }
4665
4666 /// Return the newly negated expression if the cost is not expensive and
4667 /// set the cost in \p Cost to indicate that if it is cheaper or neutral to
4668 /// do the negation.
4669 virtual SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG,
4670 bool LegalOps, bool OptForSize,
4671 NegatibleCost &Cost,
4672 unsigned Depth = 0) const;
4673
4675 SDValue Op, SelectionDAG &DAG, bool LegalOps, bool OptForSize,
4677 unsigned Depth = 0) const {
4679 SDValue Neg =
4680 getNegatedExpression(Op, DAG, LegalOps, OptForSize, Cost, Depth);
4681 if (!Neg)
4682 return SDValue();
4683
4684 if (Cost <= CostThreshold)
4685 return Neg;
4686
4687 // Remove the new created node to avoid the side effect to the DAG.
4688 if (Neg->use_empty())
4689 DAG.RemoveDeadNode(Neg.getNode());
4690 return SDValue();
4691 }
4692
4693 /// This is the helper function to return the newly negated expression only
4694 /// when the cost is cheaper.
4696 bool LegalOps, bool OptForSize,
4697 unsigned Depth = 0) const {
4698 return getCheaperOrNeutralNegatedExpression(Op, DAG, LegalOps, OptForSize,
4700 }
4701
4702 /// This is the helper function to return the newly negated expression if
4703 /// the cost is not expensive.
4705 bool OptForSize, unsigned Depth = 0) const {
4707 return getNegatedExpression(Op, DAG, LegalOps, OptForSize, Cost, Depth);
4708 }
4709
4710 //===--------------------------------------------------------------------===//
4711 // Lowering methods - These methods must be implemented by targets so that
4712 // the SelectionDAGBuilder code knows how to lower these.
4713 //
4714
4715 /// Target-specific splitting of values into parts that fit a register
4716 /// storing a legal type
4718 SelectionDAG & DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
4719 unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC) const {
4720 return false;
4721 }
4722
4723 /// Target-specific combining of register parts into its original value
4724 virtual SDValue
4726 const SDValue *Parts, unsigned NumParts,
4727 MVT PartVT, EVT ValueVT,
4728 std::optional<CallingConv::ID> CC) const {
4729 return SDValue();
4730 }
4731
4732 /// This hook must be implemented to lower the incoming (formal) arguments,
4733 /// described by the Ins array, into the specified DAG. The implementation
4734 /// should fill in the InVals array with legal-type argument values, and
4735 /// return the resulting token chain value.
4737 SDValue /*Chain*/, CallingConv::ID /*CallConv*/, bool /*isVarArg*/,
4738 const SmallVectorImpl<ISD::InputArg> & /*Ins*/, const SDLoc & /*dl*/,
4739 SelectionDAG & /*DAG*/, SmallVectorImpl<SDValue> & /*InVals*/) const {
4740 llvm_unreachable("Not Implemented");
4741 }
4742
4743 /// Optional target hook to add target-specific actions when entering EH pad
4744 /// blocks. The implementation should return the resulting token chain value.
4745 virtual SDValue lowerEHPadEntry(SDValue Chain, const SDLoc &DL,
4746 SelectionDAG &DAG) const {
4747 return SDValue();
4748 }
4749
4750 virtual void markLibCallAttributes(MachineFunction *MF, unsigned CC,
4751 ArgListTy &Args) const {}
4752
4753 /// This structure contains the information necessary for lowering
4754 /// pointer-authenticating indirect calls. It is equivalent to the "ptrauth"
4755 /// operand bundle found on the call instruction, if any.
4760
4761 /// This structure contains all information that is necessary for lowering
4762 /// calls. It is passed to TLI::LowerCallTo when the SelectionDAG builder
4763 /// needs to lower a call, and targets will see this struct in their LowerCall
4764 /// implementation.
4767 /// Original unlegalized return type.
4768 Type *OrigRetTy = nullptr;
4769 /// Same as OrigRetTy, or partially legalized for soft float libcalls.
4770 Type *RetTy = nullptr;
4771 bool RetSExt : 1;
4772 bool RetZExt : 1;
4773 bool IsVarArg : 1;
4774 bool IsInReg : 1;
4780 bool NoMerge : 1;
4781
4782 // IsTailCall should be modified by implementations of
4783 // TargetLowering::LowerCall that perform tail call conversions.
4784 bool IsTailCall = false;
4785
4786 // Is Call lowering done post SelectionDAG type legalization.
4788
4789 unsigned NumFixedArgs = -1;
4795 const CallBase *CB = nullptr;
4800 const ConstantInt *CFIType = nullptr;
4803
4804 std::optional<PtrAuthInfo> PAI;
4805
4811
4813 DL = dl;
4814 return *this;
4815 }
4816
4818 Chain = InChain;
4819 return *this;
4820 }
4821
4822 // setCallee with target/module-specific attributes
4824 SDValue Target, ArgListTy &&ArgsList) {
4825 return setLibCallee(CC, ResultType, ResultType, Target,
4826 std::move(ArgsList));
4827 }
4828
4830 Type *OrigResultType, SDValue Target,
4831 ArgListTy &&ArgsList) {
4832 OrigRetTy = OrigResultType;
4833 RetTy = ResultType;
4834 Callee = Target;
4835 CallConv = CC;
4836 NumFixedArgs = ArgsList.size();
4837 Args = std::move(ArgsList);
4838
4839 DAG.getTargetLoweringInfo().markLibCallAttributes(
4840 &(DAG.getMachineFunction()), CC, Args);
4841 return *this;
4842 }
4843
4845 SDValue Target, ArgListTy &&ArgsList,
4846 AttributeSet ResultAttrs = {}) {
4847 RetTy = OrigRetTy = ResultType;
4848 IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
4849 RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
4850 RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
4851 NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);
4852
4853 Callee = Target;
4854 CallConv = CC;
4855 NumFixedArgs = ArgsList.size();
4856 Args = std::move(ArgsList);
4857 return *this;
4858 }
4859
4861 SDValue Target, ArgListTy &&ArgsList,
4862 const CallBase &Call) {
4863 RetTy = OrigRetTy = ResultType;
4864
4865 IsInReg = Call.hasRetAttr(Attribute::InReg);
4867 Call.doesNotReturn() ||
4868 (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
4869 IsVarArg = FTy->isVarArg();
4870 IsReturnValueUsed = !Call.use_empty();
4871 RetSExt = Call.hasRetAttr(Attribute::SExt);
4872 RetZExt = Call.hasRetAttr(Attribute::ZExt);
4873 NoMerge = Call.hasFnAttr(Attribute::NoMerge);
4874
4875 Callee = Target;
4876
4877 CallConv = Call.getCallingConv();
4878 NumFixedArgs = FTy->getNumParams();
4879 Args = std::move(ArgsList);
4880
4881 CB = &Call;
4882
4883 return *this;
4884 }
4885
4887 IsInReg = Value;
4888 return *this;
4889 }
4890
4893 return *this;
4894 }
4895
4897 IsVarArg = Value;
4898 return *this;
4899 }
4900
4902 IsTailCall = Value;
4903 return *this;
4904 }
4905
4908 return *this;
4909 }
4910
4913 return *this;
4914 }
4915
4917 RetSExt = Value;
4918 return *this;
4919 }
4920
4922 RetZExt = Value;
4923 return *this;
4924 }
4925
4928 return *this;
4929 }
4930
4933 return *this;
4934 }
4935
4937 PAI = Value;
4938 return *this;
4939 }
4940
4943 return *this;
4944 }
4945
4947 CFIType = Type;
4948 return *this;
4949 }
4950
4953 return *this;
4954 }
4955
4957 DeactivationSymbol = Sym;
4958 return *this;
4959 }
4960
4962 return Args;
4963 }
4964 };
4965
4966 /// This structure is used to pass arguments to makeLibCall function.
4968 // By passing type list before soften to makeLibCall, the target hook
4969 // shouldExtendTypeInLibCall can get the original type before soften.
4973
4974 bool IsSigned : 1;
4978 bool IsSoften : 1;
4979
4983
4985 IsSigned = Value;
4986 return *this;
4987 }
4988
4991 return *this;
4992 }
4993
4996 return *this;
4997 }
4998
5001 return *this;
5002 }
5003
5005 OpsVTBeforeSoften = OpsVT;
5006 RetVTBeforeSoften = RetVT;
5007 IsSoften = true;
5008 return *this;
5009 }
5010
5011 /// Override the argument type for an operand. Leave the type as null to use
5012 /// the type from the operand's node.
5014 OpsTypeOverrides = OpsTypes;
5015 return *this;
5016 }
5017 };
5018
5019 /// This function lowers an abstract call to a function into an actual call.
5020 /// This returns a pair of operands. The first element is the return value
5021 /// for the function (if RetTy is not VoidTy). The second element is the
5022 /// outgoing token chain. It calls LowerCall to do the actual lowering.
5023 std::pair<SDValue, SDValue> LowerCallTo(CallLoweringInfo &CLI) const;
5024
5025 /// This hook must be implemented to lower calls into the specified
5026 /// DAG. The outgoing arguments to the call are described by the Outs array,
5027 /// and the values to be returned by the call are described by the Ins
5028 /// array. The implementation should fill in the InVals array with legal-type
5029 /// return values from the call, and return the resulting token chain value.
5030 virtual SDValue
5032 SmallVectorImpl<SDValue> &/*InVals*/) const {
5033 llvm_unreachable("Not Implemented");
5034 }
5035
5036 /// Target-specific cleanup for formal ByVal parameters.
5037 virtual void HandleByVal(CCState *, unsigned &, Align) const {}
5038
5039 /// This hook should be implemented to check whether the return values
5040 /// described by the Outs array can fit into the return registers. If false
5041 /// is returned, an sret-demotion is performed.
5042 virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/,
5043 MachineFunction &/*MF*/, bool /*isVarArg*/,
5044 const SmallVectorImpl<ISD::OutputArg> &/*Outs*/,
5045 LLVMContext &/*Context*/, const Type *RetTy) const
5046 {
5047 // Return true by default to get preexisting behavior.
5048 return true;
5049 }
5050
5051 /// This hook must be implemented to lower outgoing return values, described
5052 /// by the Outs array, into the specified DAG. The implementation should
5053 /// return the resulting token chain value.
5054 virtual SDValue LowerReturn(SDValue /*Chain*/, CallingConv::ID /*CallConv*/,
5055 bool /*isVarArg*/,
5056 const SmallVectorImpl<ISD::OutputArg> & /*Outs*/,
5057 const SmallVectorImpl<SDValue> & /*OutVals*/,
5058 const SDLoc & /*dl*/,
5059 SelectionDAG & /*DAG*/) const {
5060 llvm_unreachable("Not Implemented");
5061 }
5062
5063 /// Return true if result of the specified node is used by a return node
5064 /// only. It also compute and return the input chain for the tail call.
5065 ///
5066 /// This is used to determine whether it is possible to codegen a libcall as
5067 /// tail call at legalization time.
5068 virtual bool isUsedByReturnOnly(SDNode *, SDValue &/*Chain*/) const {
5069 return false;
5070 }
5071
5072 /// Return true if the target may be able emit the call instruction as a tail
5073 /// call. This is used by optimization passes to determine if it's profitable
5074 /// to duplicate return instructions to enable tailcall optimization.
5075 virtual bool mayBeEmittedAsTailCall(const CallInst *) const {
5076 return false;
5077 }
5078
5079 /// Return the register ID of the name passed in. Used by named register
5080 /// global variables extension. There is no target-independent behaviour
5081 /// so the default action is to bail.
5082 virtual Register getRegisterByName(const char* RegName, LLT Ty,
5083 const MachineFunction &MF) const {
5084 report_fatal_error("Named registers not implemented for this target");
5085 }
5086
5087 /// Return the type that should be used to zero or sign extend a
5088 /// zeroext/signext integer return value. FIXME: Some C calling conventions
5089 /// require the return type to be promoted, but this is not true all the time,
5090 /// e.g. i1/i8/i16 on x86/x86_64. It is also not necessary for non-C calling
5091 /// conventions. The frontend should handle this and include all of the
5092 /// necessary information.
5094 ISD::NodeType /*ExtendKind*/) const {
5095 EVT MinVT = getRegisterType(MVT::i32);
5096 return VT.bitsLT(MinVT) ? MinVT : VT;
5097 }
5098
5099 /// For some targets, an LLVM struct type must be broken down into multiple
5100 /// simple types, but the calling convention specifies that the entire struct
5101 /// must be passed in a block of consecutive registers.
5102 virtual bool
5104 bool isVarArg,
5105 const DataLayout &DL) const {
5106 return false;
5107 }
5108
5109 /// For most targets, an LLVM type must be broken down into multiple
5110 /// smaller types. Usually the halves are ordered according to the endianness
5111 /// but for some platform that would break. So this method will default to
5112 /// matching the endianness but can be overridden.
5113 virtual bool
5115 return DL.isLittleEndian();
5116 }
5117
5118 /// Returns a 0 terminated array of registers that can be safely used as
5119 /// scratch registers.
5121 return nullptr;
5122 }
5123
5124 /// Returns a 0 terminated array of rounding control registers that can be
5125 /// attached into strict FP call.
5129
5130 /// This callback is used to prepare for a volatile or atomic load.
5131 /// It takes a chain node as input and returns the chain for the load itself.
5132 ///
5133 /// Having a callback like this is necessary for targets like SystemZ,
5134 /// which allows a CPU to reuse the result of a previous load indefinitely,
5135 /// even if a cache-coherent store is performed by another CPU. The default
5136 /// implementation does nothing.
5138 SelectionDAG &DAG) const {
5139 return Chain;
5140 }
5141
5142 /// This callback is invoked by the type legalizer to legalize nodes with an
5143 /// illegal operand type but legal result types. It replaces the
5144 /// LowerOperation callback in the type Legalizer. The reason we can not do
5145 /// away with LowerOperation entirely is that LegalizeDAG isn't yet ready to
5146 /// use this callback.
5147 ///
5148 /// TODO: Consider merging with ReplaceNodeResults.
5149 ///
5150 /// The target places new result values for the node in Results (their number
5151 /// and types must exactly match those of the original return values of
5152 /// the node), or leaves Results empty, which indicates that the node is not
5153 /// to be custom lowered after all.
5154 /// The default implementation calls LowerOperation.
5155 virtual void LowerOperationWrapper(SDNode *N,
5157 SelectionDAG &DAG) const;
5158
5159 /// This callback is invoked for operations that are unsupported by the
5160 /// target, which are registered to use 'custom' lowering, and whose defined
5161 /// values are all legal. If the target has no operations that require custom
5162 /// lowering, it need not implement this. The default implementation of this
5163 /// aborts.
5164 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
5165
5166 /// This callback is invoked when a node result type is illegal for the
5167 /// target, and the operation was registered to use 'custom' lowering for that
5168 /// result type. The target places new result values for the node in Results
5169 /// (their number and types must exactly match those of the original return
5170 /// values of the node), or leaves Results empty, which indicates that the
5171 /// node is not to be custom lowered after all.
5172 ///
5173 /// If the target has no operations that require custom lowering, it need not
5174 /// implement this. The default implementation aborts.
5175 virtual void ReplaceNodeResults(SDNode * /*N*/,
5176 SmallVectorImpl<SDValue> &/*Results*/,
5177 SelectionDAG &/*DAG*/) const {
5178 llvm_unreachable("ReplaceNodeResults not implemented for this target!");
5179 }
5180
5181 /// This method returns the name of a target specific DAG node.
5182 virtual const char *getTargetNodeName(unsigned Opcode) const;
5183
5184 /// This method returns a target specific FastISel object, or null if the
5185 /// target does not support "fast" ISel.
5187 const TargetLibraryInfo *,
5188 const LibcallLoweringInfo *) const {
5189 return nullptr;
5190 }
5191
5192 //===--------------------------------------------------------------------===//
5193 // Inline Asm Support hooks
5194 //
5195
5197 C_Register, // Constraint represents specific register(s).
5198 C_RegisterClass, // Constraint represents any of register(s) in class.
5199 C_Memory, // Memory constraint.
5200 C_Address, // Address constraint.
5201 C_Immediate, // Requires an immediate.
5202 C_Other, // Something else.
5203 C_Unknown // Unsupported constraint.
5204 };
5205
5207 // Generic weights.
5208 CW_Invalid = -1, // No match.
5209 CW_Okay = 0, // Acceptable.
5210 CW_Good = 1, // Good weight.
5211 CW_Better = 2, // Better weight.
5212 CW_Best = 3, // Best weight.
5213
5214 // Well-known weights.
5215 CW_SpecificReg = CW_Okay, // Specific register operands.
5216 CW_Register = CW_Good, // Register operands.
5217 CW_Memory = CW_Better, // Memory operands.
5218 CW_Constant = CW_Best, // Constant operand.
5219 CW_Default = CW_Okay // Default or don't know type.
5220 };
5221
5222 /// This contains information for each constraint that we are lowering.
5224 /// This contains the actual string for the code, like "m". TargetLowering
5225 /// picks the 'best' code from ConstraintInfo::Codes that most closely
5226 /// matches the operand.
5227 std::string ConstraintCode;
5228
5229 /// Information about the constraint code, e.g. Register, RegisterClass,
5230 /// Memory, Other, Unknown.
5232
5233 /// If this is the result output operand or a clobber, this is null,
5234 /// otherwise it is the incoming operand to the CallInst. This gets
5235 /// modified as the asm is processed.
5237
5238 /// The ValueType for the operand value.
5239 MVT ConstraintVT = MVT::Other;
5240
5241 /// Copy constructor for copying from a ConstraintInfo.
5244
5245 /// Return true of this is an input operand that is a matching constraint
5246 /// like "4".
5247 LLVM_ABI bool isMatchingInputConstraint() const;
5248
5249 /// If this is an input matching constraint, this method returns the output
5250 /// operand it matches.
5251 LLVM_ABI unsigned getMatchedOperand() const;
5252 };
5253
5254 using AsmOperandInfoVector = std::vector<AsmOperandInfo>;
5255
5256 /// Split up the constraint string from the inline assembly value into the
5257 /// specific constraints and their prefixes, and also tie in the associated
5258 /// operand values. If this returns an empty vector, and if the constraint
5259 /// string itself isn't empty, there was an error parsing.
5261 const TargetRegisterInfo *TRI,
5262 const CallBase &Call) const;
5263
5264 /// Examine constraint type and operand type and determine a weight value.
5265 /// The operand object must already have been set up with the operand type.
5267 AsmOperandInfo &info, int maIndex) const;
5268
5269 /// Examine constraint string and operand type and determine a weight value.
5270 /// The operand object must already have been set up with the operand type.
5272 AsmOperandInfo &info, const char *constraint) const;
5273
5274 /// Determines the constraint code and constraint type to use for the specific
5275 /// AsmOperandInfo, setting OpInfo.ConstraintCode and OpInfo.ConstraintType.
5276 /// If the actual operand being passed in is available, it can be passed in as
5277 /// Op, otherwise an empty SDValue can be passed.
5278 virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo,
5279 SDValue Op,
5280 SelectionDAG *DAG = nullptr) const;
5281
5282 /// Given a constraint, return the type of constraint it is for this target.
5283 virtual ConstraintType getConstraintType(StringRef Constraint) const;
5284
5285 using ConstraintPair = std::pair<StringRef, TargetLowering::ConstraintType>;
5287 /// Given an OpInfo with list of constraints codes as strings, return a
5288 /// sorted Vector of pairs of constraint codes and their types in priority of
5289 /// what we'd prefer to lower them as. This may contain immediates that
5290 /// cannot be lowered, but it is meant to be a machine agnostic order of
5291 /// preferences.
5293
5294 /// Given a physical register constraint (e.g. {edx}), return the register
5295 /// number and the register class for the register.
5296 ///
5297 /// Given a register class constraint, like 'r', if this corresponds directly
5298 /// to an LLVM register class, return a register of 0 and the register class
5299 /// pointer.
5300 ///
5301 /// This should only be used for C_Register constraints. On error, this
5302 /// returns a register number of 0 and a null register class pointer.
5303 virtual std::pair<unsigned, const TargetRegisterClass *>
5305 StringRef Constraint, MVT VT) const;
5306
5308 getInlineAsmMemConstraint(StringRef ConstraintCode) const {
5309 if (ConstraintCode == "m")
5311 if (ConstraintCode == "o")
5313 if (ConstraintCode == "X")
5315 if (ConstraintCode == "p")
5318 }
5319
5320 /// Try to replace an X constraint, which matches anything, with another that
5321 /// has more specific requirements based on the type of the corresponding
5322 /// operand. This returns null if there is no replacement to make.
5323 virtual const char *LowerXConstraint(EVT ConstraintVT) const;
5324
5325 /// Lower the specified operand into the Ops vector. If it is invalid, don't
5326 /// add anything to Ops.
5327 virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,
5328 std::vector<SDValue> &Ops,
5329 SelectionDAG &DAG) const;
5330
5331 // Lower custom output constraints. If invalid, return SDValue().
5332 virtual SDValue LowerAsmOutputForConstraint(SDValue &Chain, SDValue &Glue,
5333 const SDLoc &DL,
5334 const AsmOperandInfo &OpInfo,
5335 SelectionDAG &DAG) const;
5336
5337 // Targets may override this function to collect operands from the CallInst
5338 // and for example, lower them into the SelectionDAG operands.
5339 virtual void CollectTargetIntrinsicOperands(const CallInst &I,
5341 SelectionDAG &DAG) const;
5342
5343 //===--------------------------------------------------------------------===//
5344 // Div utility functions
5345 //
5346
5347 SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization,
5348 bool IsAfterLegalTypes,
5349 SmallVectorImpl<SDNode *> &Created) const;
5350 SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization,
5351 bool IsAfterLegalTypes,
5352 SmallVectorImpl<SDNode *> &Created) const;
5353 // Build sdiv by power-of-2 with conditional move instructions
5354 SDValue buildSDIVPow2WithCMov(SDNode *N, const APInt &Divisor,
5355 SelectionDAG &DAG,
5356 SmallVectorImpl<SDNode *> &Created) const;
5357
5358 /// Targets may override this function to provide custom SDIV lowering for
5359 /// power-of-2 denominators. If the target returns an empty SDValue, LLVM
5360 /// assumes SDIV is expensive and replaces it with a series of other integer
5361 /// operations.
5362 virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor,
5363 SelectionDAG &DAG,
5364 SmallVectorImpl<SDNode *> &Created) const;
5365
5366 /// Targets may override this function to provide custom SREM lowering for
5367 /// power-of-2 denominators. If the target returns an empty SDValue, LLVM
5368 /// assumes SREM is expensive and replaces it with a series of other integer
5369 /// operations.
5370 virtual SDValue BuildSREMPow2(SDNode *N, const APInt &Divisor,
5371 SelectionDAG &DAG,
5372 SmallVectorImpl<SDNode *> &Created) const;
5373
5374 /// Indicate whether this target prefers to combine FDIVs with the same
5375 /// divisor. If the transform should never be done, return zero. If the
5376 /// transform should be done, return the minimum number of divisor uses
5377 /// that must exist.
5378 virtual unsigned combineRepeatedFPDivisors() const {
5379 return 0;
5380 }
5381
5382 /// Hooks for building estimates in place of slower divisions and square
5383 /// roots.
5384
5385 /// Return either a square root or its reciprocal estimate value for the input
5386 /// operand.
5387 /// \p Enabled is a ReciprocalEstimate enum with value either 'Unspecified' or
5388 /// 'Enabled' as set by a potential default override attribute.
5389 /// If \p RefinementSteps is 'Unspecified', the number of Newton-Raphson
5390 /// refinement iterations required to generate a sufficient (though not
5391 /// necessarily IEEE-754 compliant) estimate is returned in that parameter.
5392 /// The boolean UseOneConstNR output is used to select a Newton-Raphson
5393 /// algorithm implementation that uses either one or two constants.
5394 /// The boolean Reciprocal is used to select whether the estimate is for the
5395 /// square root of the input operand or the reciprocal of its square root.
5396 /// A target may choose to implement its own refinement within this function.
5397 /// If that's true, then return '0' as the number of RefinementSteps to avoid
5398 /// any further refinement of the estimate.
5399 /// An empty SDValue return means no estimate sequence can be created.
5401 int Enabled, int &RefinementSteps,
5402 bool &UseOneConstNR, bool Reciprocal) const {
5403 return SDValue();
5404 }
5405
5406 /// Try to convert the fminnum/fmaxnum to a compare/select sequence. This is
5407 /// required for correctness since InstCombine might have canonicalized a
5408 /// fcmp+select sequence to a FMINNUM/FMAXNUM intrinsic. If we were to fall
5409 /// through to the default expansion/soften to libcall, we might introduce a
5410 /// link-time dependency on libm into a file that originally did not have one.
5411 SDValue createSelectForFMINNUM_FMAXNUM(SDNode *Node, SelectionDAG &DAG) const;
5412
5413 /// Return a reciprocal estimate value for the input operand.
5414 /// \p Enabled is a ReciprocalEstimate enum with value either 'Unspecified' or
5415 /// 'Enabled' as set by a potential default override attribute.
5416 /// If \p RefinementSteps is 'Unspecified', the number of Newton-Raphson
5417 /// refinement iterations required to generate a sufficient (though not
5418 /// necessarily IEEE-754 compliant) estimate is returned in that parameter.
5419 /// A target may choose to implement its own refinement within this function.
5420 /// If that's true, then return '0' as the number of RefinementSteps to avoid
5421 /// any further refinement of the estimate.
5422 /// An empty SDValue return means no estimate sequence can be created.
5424 int Enabled, int &RefinementSteps) const {
5425 return SDValue();
5426 }
5427
5428 /// Return a target-dependent comparison result if the input operand is
5429 /// suitable for use with a square root estimate calculation. For example, the
5430 /// comparison may check if the operand is NAN, INF, zero, normal, etc. The
5431 /// result should be used as the condition operand for a select or branch.
5432 virtual SDValue getSqrtInputTest(SDValue Operand, SelectionDAG &DAG,
5433 const DenormalMode &Mode) const;
5434
5435 /// Return a target-dependent result if the input operand is not suitable for
5436 /// use with a square root estimate calculation.
5438 SelectionDAG &DAG) const {
5439 return DAG.getConstantFP(0.0, SDLoc(Operand), Operand.getValueType());
5440 }
5441
5442 //===--------------------------------------------------------------------===//
5443 // Legalization utility functions
5444 //
5445
5446 /// Expand a MUL or [US]MUL_LOHI of n-bit values into two or four nodes,
5447 /// respectively, each computing an n/2-bit part of the result.
5448 /// \param Result A vector that will be filled with the parts of the result
5449 /// in little-endian order.
5450 /// \param LL Low bits of the LHS of the MUL. You can use this parameter
5451 /// if you want to control how low bits are extracted from the LHS.
5452 /// \param LH High bits of the LHS of the MUL. See LL for meaning.
5453 /// \param RL Low bits of the RHS of the MUL. See LL for meaning
5454 /// \param RH High bits of the RHS of the MUL. See LL for meaning.
5455 /// \returns true if the node has been expanded, false if it has not
5456 bool expandMUL_LOHI(unsigned Opcode, EVT VT, const SDLoc &dl, SDValue LHS,
5457 SDValue RHS, SmallVectorImpl<SDValue> &Result, EVT HiLoVT,
5458 SelectionDAG &DAG, MulExpansionKind Kind,
5459 SDValue LL = SDValue(), SDValue LH = SDValue(),
5460 SDValue RL = SDValue(), SDValue RH = SDValue()) const;
5461
5462 /// Expand a MUL into two nodes. One that computes the high bits of
5463 /// the result and one that computes the low bits.
5464 /// \param HiLoVT The value type to use for the Lo and Hi nodes.
5465 /// \param LL Low bits of the LHS of the MUL. You can use this parameter
5466 /// if you want to control how low bits are extracted from the LHS.
5467 /// \param LH High bits of the LHS of the MUL. See LL for meaning.
5468 /// \param RL Low bits of the RHS of the MUL. See LL for meaning
5469 /// \param RH High bits of the RHS of the MUL. See LL for meaning.
5470 /// \returns true if the node has been expanded. false if it has not
5471 bool expandMUL(SDNode *N, SDValue &Lo, SDValue &Hi, EVT HiLoVT,
5472 SelectionDAG &DAG, MulExpansionKind Kind,
5473 SDValue LL = SDValue(), SDValue LH = SDValue(),
5474 SDValue RL = SDValue(), SDValue RH = SDValue()) const;
5475
5476 /// Attempt to expand an n-bit div/rem/divrem by constant using a n/2-bit
5477 /// urem by constant and other arithmetic ops. The n/2-bit urem by constant
5478 /// will be expanded by DAGCombiner. This is not possible for all constant
5479 /// divisors.
5480 /// \param N Node to expand
5481 /// \param Result A vector that will be filled with the lo and high parts of
5482 /// the results. For *DIVREM, this will be the quotient parts followed
5483 /// by the remainder parts.
5484 /// \param HiLoVT The value type to use for the Lo and Hi parts. Should be
5485 /// half of VT.
5486 /// \param LL Low bits of the LHS of the operation. You can use this
5487 /// parameter if you want to control how low bits are extracted from
5488 /// the LHS.
5489 /// \param LH High bits of the LHS of the operation. See LL for meaning.
5490 /// \returns true if the node has been expanded, false if it has not.
5491 bool expandDIVREMByConstant(SDNode *N, SmallVectorImpl<SDValue> &Result,
5492 EVT HiLoVT, SelectionDAG &DAG,
5493 SDValue LL = SDValue(),
5494 SDValue LH = SDValue()) const;
5495
5496 /// Expand funnel shift.
5497 /// \param N Node to expand
5498 /// \returns The expansion if successful, SDValue() otherwise
5499 SDValue expandFunnelShift(SDNode *N, SelectionDAG &DAG) const;
5500
5501 /// Expand carryless multiply.
5502 /// \param N Node to expand
5503 /// \returns The expansion if successful, SDValue() otherwise
5504 SDValue expandCLMUL(SDNode *N, SelectionDAG &DAG) const;
5505
5506 /// Expand rotations.
5507 /// \param N Node to expand
5508 /// \param AllowVectorOps expand vector rotate, this should only be performed
5509 /// if the legalization is happening outside of LegalizeVectorOps
5510 /// \returns The expansion if successful, SDValue() otherwise
5511 SDValue expandROT(SDNode *N, bool AllowVectorOps, SelectionDAG &DAG) const;
5512
5513 /// Expand shift-by-parts.
5514 /// \param N Node to expand
5515 /// \param Lo lower-output-part after conversion
5516 /// \param Hi upper-output-part after conversion
5517 void expandShiftParts(SDNode *N, SDValue &Lo, SDValue &Hi,
5518 SelectionDAG &DAG) const;
5519
5520 /// Expand float(f32) to SINT(i64) conversion
5521 /// \param N Node to expand
5522 /// \param Result output after conversion
5523 /// \returns True, if the expansion was successful, false otherwise
5524 bool expandFP_TO_SINT(SDNode *N, SDValue &Result, SelectionDAG &DAG) const;
5525
5526 /// Expand float to UINT conversion
5527 /// \param N Node to expand
5528 /// \param Result output after conversion
5529 /// \param Chain output chain after conversion
5530 /// \returns True, if the expansion was successful, false otherwise
5531 bool expandFP_TO_UINT(SDNode *N, SDValue &Result, SDValue &Chain,
5532 SelectionDAG &DAG) const;
5533
5534 /// Expand UINT(i64) to double(f64) conversion
5535 /// \param N Node to expand
5536 /// \param Result output after conversion
5537 /// \param Chain output chain after conversion
5538 /// \returns True, if the expansion was successful, false otherwise
5539 bool expandUINT_TO_FP(SDNode *N, SDValue &Result, SDValue &Chain,
5540 SelectionDAG &DAG) const;
5541
5542 /// Expand fminnum/fmaxnum into fminnum_ieee/fmaxnum_ieee with quieted inputs.
5543 SDValue expandFMINNUM_FMAXNUM(SDNode *N, SelectionDAG &DAG) const;
5544
5545 /// Expand fminimum/fmaximum into multiple comparison with selects.
5546 SDValue expandFMINIMUM_FMAXIMUM(SDNode *N, SelectionDAG &DAG) const;
5547
5548 /// Expand fminimumnum/fmaximumnum into multiple comparison with selects.
5549 SDValue expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *N, SelectionDAG &DAG) const;
5550
5551 /// Expand FP_TO_[US]INT_SAT into FP_TO_[US]INT and selects or min/max.
5552 /// \param N Node to expand
5553 /// \returns The expansion result
5554 SDValue expandFP_TO_INT_SAT(SDNode *N, SelectionDAG &DAG) const;
5555
5556 /// Truncate Op to ResultVT. If the result is exact, leave it alone. If it is
5557 /// not exact, force the result to be odd.
5558 /// \param ResultVT The type of result.
5559 /// \param Op The value to round.
5560 /// \returns The expansion result
5561 SDValue expandRoundInexactToOdd(EVT ResultVT, SDValue Op, const SDLoc &DL,
5562 SelectionDAG &DAG) const;
5563
5564 /// Expand round(fp) to fp conversion
5565 /// \param N Node to expand
5566 /// \returns The expansion result
5567 SDValue expandFP_ROUND(SDNode *Node, SelectionDAG &DAG) const;
5568
5569 /// Expand check for floating point class.
5570 /// \param ResultVT The type of intrinsic call result.
5571 /// \param Op The tested value.
5572 /// \param Test The test to perform.
5573 /// \param Flags The optimization flags.
5574 /// \returns The expansion result or SDValue() if it fails.
5575 SDValue expandIS_FPCLASS(EVT ResultVT, SDValue Op, FPClassTest Test,
5576 SDNodeFlags Flags, const SDLoc &DL,
5577 SelectionDAG &DAG) const;
5578
5579 /// Expand CTPOP nodes. Expands vector/scalar CTPOP nodes,
5580 /// vector nodes can only succeed if all operations are legal/custom.
5581 /// \param N Node to expand
5582 /// \returns The expansion result or SDValue() if it fails.
5583 SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const;
5584
5585 /// Expand VP_CTPOP nodes.
5586 /// \returns The expansion result or SDValue() if it fails.
5587 SDValue expandVPCTPOP(SDNode *N, SelectionDAG &DAG) const;
5588
5589 /// Expand CTLZ/CTLZ_ZERO_UNDEF nodes. Expands vector/scalar CTLZ nodes,
5590 /// vector nodes can only succeed if all operations are legal/custom.
5591 /// \param N Node to expand
5592 /// \returns The expansion result or SDValue() if it fails.
5593 SDValue expandCTLZ(SDNode *N, SelectionDAG &DAG) const;
5594
5595 /// Expand VP_CTLZ/VP_CTLZ_ZERO_UNDEF nodes.
5596 /// \param N Node to expand
5597 /// \returns The expansion result or SDValue() if it fails.
5598 SDValue expandVPCTLZ(SDNode *N, SelectionDAG &DAG) const;
5599
5600 /// Expand CTTZ via Table Lookup.
5601 /// \param N Node to expand
5602 /// \returns The expansion result or SDValue() if it fails.
5603 SDValue CTTZTableLookup(SDNode *N, SelectionDAG &DAG, const SDLoc &DL, EVT VT,
5604 SDValue Op, unsigned NumBitsPerElt) const;
5605
5606 /// Expand CTTZ/CTTZ_ZERO_UNDEF nodes. Expands vector/scalar CTTZ nodes,
5607 /// vector nodes can only succeed if all operations are legal/custom.
5608 /// \param N Node to expand
5609 /// \returns The expansion result or SDValue() if it fails.
5610 SDValue expandCTTZ(SDNode *N, SelectionDAG &DAG) const;
5611
5612 /// Expand VP_CTTZ/VP_CTTZ_ZERO_UNDEF nodes.
5613 /// \param N Node to expand
5614 /// \returns The expansion result or SDValue() if it fails.
5615 SDValue expandVPCTTZ(SDNode *N, SelectionDAG &DAG) const;
5616
5617 /// Expand VP_CTTZ_ELTS/VP_CTTZ_ELTS_ZERO_UNDEF nodes.
5618 /// \param N Node to expand
5619 /// \returns The expansion result or SDValue() if it fails.
5620 SDValue expandVPCTTZElements(SDNode *N, SelectionDAG &DAG) const;
5621
5622 /// Expand VECTOR_FIND_LAST_ACTIVE nodes
5623 /// \param N Node to expand
5624 /// \returns The expansion result or SDValue() if it fails.
5625 SDValue expandVectorFindLastActive(SDNode *N, SelectionDAG &DAG) const;
5626
5627 /// Expand ABS nodes. Expands vector/scalar ABS nodes,
5628 /// vector nodes can only succeed if all operations are legal/custom.
5629 /// (ABS x) -> (XOR (ADD x, (SRA x, type_size)), (SRA x, type_size))
5630 /// \param N Node to expand
5631 /// \param IsNegative indicate negated abs
5632 /// \returns The expansion result or SDValue() if it fails.
5633 SDValue expandABS(SDNode *N, SelectionDAG &DAG,
5634 bool IsNegative = false) const;
5635
5636 /// Expand ABDS/ABDU nodes. Expands vector/scalar ABDS/ABDU nodes.
5637 /// \param N Node to expand
5638 /// \returns The expansion result or SDValue() if it fails.
5639 SDValue expandABD(SDNode *N, SelectionDAG &DAG) const;
5640
5641 /// Expand vector/scalar AVGCEILS/AVGCEILU/AVGFLOORS/AVGFLOORU nodes.
5642 /// \param N Node to expand
5643 /// \returns The expansion result or SDValue() if it fails.
5644 SDValue expandAVG(SDNode *N, SelectionDAG &DAG) const;
5645
5646 /// Expand BSWAP nodes. Expands scalar/vector BSWAP nodes with i16/i32/i64
5647 /// scalar types. Returns SDValue() if expand fails.
5648 /// \param N Node to expand
5649 /// \returns The expansion result or SDValue() if it fails.
5650 SDValue expandBSWAP(SDNode *N, SelectionDAG &DAG) const;
5651
5652 /// Expand VP_BSWAP nodes. Expands VP_BSWAP nodes with
5653 /// i16/i32/i64 scalar types. Returns SDValue() if expand fails. \param N Node
5654 /// to expand \returns The expansion result or SDValue() if it fails.
5655 SDValue expandVPBSWAP(SDNode *N, SelectionDAG &DAG) const;
5656
5657 /// Expand BITREVERSE nodes. Expands scalar/vector BITREVERSE nodes.
5658 /// Returns SDValue() if expand fails.
5659 /// \param N Node to expand
5660 /// \returns The expansion result or SDValue() if it fails.
5661 SDValue expandBITREVERSE(SDNode *N, SelectionDAG &DAG) const;
5662
5663 /// Expand VP_BITREVERSE nodes. Expands VP_BITREVERSE nodes with
5664 /// i8/i16/i32/i64 scalar types. \param N Node to expand \returns The
5665 /// expansion result or SDValue() if it fails.
5666 SDValue expandVPBITREVERSE(SDNode *N, SelectionDAG &DAG) const;
5667
5668 /// Turn load of vector type into a load of the individual elements.
5669 /// \param LD load to expand
5670 /// \returns BUILD_VECTOR and TokenFactor nodes.
5671 std::pair<SDValue, SDValue> scalarizeVectorLoad(LoadSDNode *LD,
5672 SelectionDAG &DAG) const;
5673
5674 // Turn a store of a vector type into stores of the individual elements.
5675 /// \param ST Store with a vector value type
5676 /// \returns TokenFactor of the individual store chains.
5678
5679 /// Expands an unaligned load to 2 half-size loads for an integer, and
5680 /// possibly more for vectors.
5681 std::pair<SDValue, SDValue> expandUnalignedLoad(LoadSDNode *LD,
5682 SelectionDAG &DAG) const;
5683
5684 /// Expands an unaligned store to 2 half-size stores for integer values, and
5685 /// possibly more for vectors.
5686 SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const;
5687
5688 /// Increments memory address \p Addr according to the type of the value
5689 /// \p DataVT that should be stored. If the data is stored in compressed
5690 /// form, the memory address should be incremented according to the number of
5691 /// the stored elements. This number is equal to the number of '1's bits
5692 /// in the \p Mask.
5693 /// \p DataVT is a vector type. \p Mask is a vector value.
5694 /// \p DataVT and \p Mask have the same number of vector elements.
5695 SDValue IncrementMemoryAddress(SDValue Addr, SDValue Mask, const SDLoc &DL,
5696 EVT DataVT, SelectionDAG &DAG,
5697 bool IsCompressedMemory) const;
5698
5699 /// Get a pointer to vector element \p Idx located in memory for a vector of
5700 /// type \p VecVT starting at a base address of \p VecPtr. If \p Idx is out of
5701 /// bounds the returned pointer is unspecified, but will be within the vector
5702 /// bounds. \p PtrArithFlags can be used to mark that arithmetic within the
5703 /// vector in memory is known to not wrap or to be inbounds.
5704 SDValue getVectorElementPointer(
5705 SelectionDAG &DAG, SDValue VecPtr, EVT VecVT, SDValue Index,
5706 const SDNodeFlags PtrArithFlags = SDNodeFlags()) const;
5707
5708 /// Get a pointer to vector element \p Idx located in memory for a vector of
5709 /// type \p VecVT starting at a base address of \p VecPtr. If \p Idx is out of
5710 /// bounds the returned pointer is unspecified, but will be within the vector
5711 /// bounds. \p VecPtr is guaranteed to point to the beginning of a memory
5712 /// location large enough for the vector.
5714 EVT VecVT, SDValue Index) const {
5715 return getVectorElementPointer(DAG, VecPtr, VecVT, Index,
5718 }
5719
5720 /// Get a pointer to a sub-vector of type \p SubVecVT at index \p Idx located
5721 /// in memory for a vector of type \p VecVT starting at a base address of
5722 /// \p VecPtr. If \p Idx plus the size of \p SubVecVT is out of bounds the
5723 /// returned pointer is unspecified, but the value returned will be such that
5724 /// the entire subvector would be within the vector bounds. \p PtrArithFlags
5725 /// can be used to mark that arithmetic within the vector in memory is known
5726 /// to not wrap or to be inbounds.
5727 SDValue
5728 getVectorSubVecPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT,
5729 EVT SubVecVT, SDValue Index,
5730 const SDNodeFlags PtrArithFlags = SDNodeFlags()) const;
5731
5732 /// Method for building the DAG expansion of ISD::[US][MIN|MAX]. This
5733 /// method accepts integers as its arguments.
5734 SDValue expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const;
5735
5736 /// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This
5737 /// method accepts integers as its arguments.
5738 SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const;
5739
5740 /// Method for building the DAG expansion of ISD::[US]CMP. This
5741 /// method accepts integers as its arguments
5742 SDValue expandCMP(SDNode *Node, SelectionDAG &DAG) const;
5743
5744 /// Method for building the DAG expansion of ISD::[US]SHLSAT. This
5745 /// method accepts integers as its arguments.
5746 SDValue expandShlSat(SDNode *Node, SelectionDAG &DAG) const;
5747
5748 /// Method for building the DAG expansion of ISD::[U|S]MULFIX[SAT]. This
5749 /// method accepts integers as its arguments.
5750 SDValue expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const;
5751
5752 /// Method for building the DAG expansion of ISD::[US]DIVFIX[SAT]. This
5753 /// method accepts integers as its arguments.
5754 /// Note: This method may fail if the division could not be performed
5755 /// within the type. Clients must retry with a wider type if this happens.
5756 SDValue expandFixedPointDiv(unsigned Opcode, const SDLoc &dl,
5758 unsigned Scale, SelectionDAG &DAG) const;
5759
5760 /// Method for building the DAG expansion of ISD::U(ADD|SUB)O. Expansion
5761 /// always suceeds and populates the Result and Overflow arguments.
5762 void expandUADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow,
5763 SelectionDAG &DAG) const;
5764
5765 /// Method for building the DAG expansion of ISD::S(ADD|SUB)O. Expansion
5766 /// always suceeds and populates the Result and Overflow arguments.
5767 void expandSADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow,
5768 SelectionDAG &DAG) const;
5769
5770 /// Method for building the DAG expansion of ISD::[US]MULO. Returns whether
5771 /// expansion was successful and populates the Result and Overflow arguments.
5772 bool expandMULO(SDNode *Node, SDValue &Result, SDValue &Overflow,
5773 SelectionDAG &DAG) const;
5774
5775 /// Calculate the product twice the width of LHS and RHS. If HiLHS/HiRHS are
5776 /// non-null they will be included in the multiplication. The expansion works
5777 /// by splitting the 2 inputs into 4 pieces that we can multiply and add
5778 /// together without neding MULH or MUL_LOHI.
5779 void forceExpandMultiply(SelectionDAG &DAG, const SDLoc &dl, bool Signed,
5781 SDValue HiLHS = SDValue(),
5782 SDValue HiRHS = SDValue()) const;
5783
5784 /// Calculate full product of LHS and RHS either via a libcall or through
5785 /// brute force expansion of the multiplication. The expansion works by
5786 /// splitting the 2 inputs into 4 pieces that we can multiply and add together
5787 /// without needing MULH or MUL_LOHI.
5788 void forceExpandWideMUL(SelectionDAG &DAG, const SDLoc &dl, bool Signed,
5789 const SDValue LHS, const SDValue RHS, SDValue &Lo,
5790 SDValue &Hi) const;
5791
5792 /// Expand a VECREDUCE_* into an explicit calculation. If Count is specified,
5793 /// only the first Count elements of the vector are used.
5794 SDValue expandVecReduce(SDNode *Node, SelectionDAG &DAG) const;
5795
5796 /// Expand a VECREDUCE_SEQ_* into an explicit ordered calculation.
5797 SDValue expandVecReduceSeq(SDNode *Node, SelectionDAG &DAG) const;
5798
5799 /// Expand an SREM or UREM using SDIV/UDIV or SDIVREM/UDIVREM, if legal.
5800 /// Returns true if the expansion was successful.
5801 bool expandREM(SDNode *Node, SDValue &Result, SelectionDAG &DAG) const;
5802
5803 /// Method for building the DAG expansion of ISD::VECTOR_SPLICE. This
5804 /// method accepts vectors as its arguments.
5805 SDValue expandVectorSplice(SDNode *Node, SelectionDAG &DAG) const;
5806
5807 /// Expand a vector VECTOR_COMPRESS into a sequence of extract element, store
5808 /// temporarily, advance store position, before re-loading the final vector.
5809 SDValue expandVECTOR_COMPRESS(SDNode *Node, SelectionDAG &DAG) const;
5810
5811 /// Expands PARTIAL_REDUCE_S/UMLA nodes to a series of simpler operations,
5812 /// consisting of zext/sext, extract_subvector, mul and add operations.
5813 SDValue expandPartialReduceMLA(SDNode *Node, SelectionDAG &DAG) const;
5814
5815 /// Expands a node with multiple results to an FP or vector libcall. The
5816 /// libcall is expected to take all the operands of the \p Node followed by
5817 /// output pointers for each of the results. \p CallRetResNo can be optionally
5818 /// set to indicate that one of the results comes from the libcall's return
5819 /// value.
5820 bool expandMultipleResultFPLibCall(
5821 SelectionDAG &DAG, RTLIB::Libcall LC, SDNode *Node,
5823 std::optional<unsigned> CallRetResNo = {}) const;
5824
5825 /// Legalize a SETCC or VP_SETCC with given LHS and RHS and condition code CC
5826 /// on the current target. A VP_SETCC will additionally be given a Mask
5827 /// and/or EVL not equal to SDValue().
5828 ///
5829 /// If the SETCC has been legalized using AND / OR, then the legalized node
5830 /// will be stored in LHS. RHS and CC will be set to SDValue(). NeedInvert
5831 /// will be set to false. This will also hold if the VP_SETCC has been
5832 /// legalized using VP_AND / VP_OR.
5833 ///
5834 /// If the SETCC / VP_SETCC has been legalized by using
5835 /// getSetCCSwappedOperands(), then the values of LHS and RHS will be
5836 /// swapped, CC will be set to the new condition, and NeedInvert will be set
5837 /// to false.
5838 ///
5839 /// If the SETCC / VP_SETCC has been legalized using the inverse condcode,
5840 /// then LHS and RHS will be unchanged, CC will set to the inverted condcode,
5841 /// and NeedInvert will be set to true. The caller must invert the result of
5842 /// the SETCC with SelectionDAG::getLogicalNOT() or take equivalent action to
5843 /// swap the effect of a true/false result.
5844 ///
5845 /// \returns true if the SETCC / VP_SETCC has been legalized, false if it
5846 /// hasn't.
5847 bool LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT, SDValue &LHS,
5848 SDValue &RHS, SDValue &CC, SDValue Mask,
5849 SDValue EVL, bool &NeedInvert, const SDLoc &dl,
5850 SDValue &Chain, bool IsSignaling = false) const;
5851
5852 //===--------------------------------------------------------------------===//
5853 // Instruction Emitting Hooks
5854 //
5855
5856 /// This method should be implemented by targets that mark instructions with
5857 /// the 'usesCustomInserter' flag. These instructions are special in various
5858 /// ways, which require special support to insert. The specified MachineInstr
5859 /// is created but not inserted into any basic blocks, and this method is
5860 /// called to expand it into a sequence of instructions, potentially also
5861 /// creating new basic blocks and control flow.
5862 /// As long as the returned basic block is different (i.e., we created a new
5863 /// one), the custom inserter is free to modify the rest of \p MBB.
5864 virtual MachineBasicBlock *
5865 EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const;
5866
5867 /// This method should be implemented by targets that mark instructions with
5868 /// the 'hasPostISelHook' flag. These instructions must be adjusted after
5869 /// instruction selection by target hooks. e.g. To fill in optional defs for
5870 /// ARM 's' setting instructions.
5871 virtual void AdjustInstrPostInstrSelection(MachineInstr &MI,
5872 SDNode *Node) const;
5873
5874 /// If this function returns true, SelectionDAGBuilder emits a
5875 /// LOAD_STACK_GUARD node when it is lowering Intrinsic::stackprotector.
5876 virtual bool useLoadStackGuardNode(const Module &M) const { return false; }
5877
5879 const SDLoc &DL) const {
5880 llvm_unreachable("not implemented for this target");
5881 }
5882
5883 /// Lower TLS global address SDNode for target independent emulated TLS model.
5884 virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA,
5885 SelectionDAG &DAG) const;
5886
5887 /// Expands target specific indirect branch for the case of JumpTable
5888 /// expansion.
5889 virtual SDValue expandIndirectJTBranch(const SDLoc &dl, SDValue Value,
5890 SDValue Addr, int JTI,
5891 SelectionDAG &DAG) const;
5892
5893 // seteq(x, 0) -> truncate(srl(ctlz(zext(x)), log2(#bits)))
5894 // If we're comparing for equality to zero and isCtlzFast is true, expose the
5895 // fact that this can be implemented as a ctlz/srl pair, so that the dag
5896 // combiner can fold the new nodes.
5897 SDValue lowerCmpEqZeroToCtlzSrl(SDValue Op, SelectionDAG &DAG) const;
5898
5899 // Return true if `X & Y eq/ne 0` is preferable to `X & Y ne/eq Y`
5901 return true;
5902 }
5903
5904 // Expand vector operation by dividing it into smaller length operations and
5905 // joining their results. SDValue() is returned when expansion did not happen.
5906 SDValue expandVectorNaryOpBySplitting(SDNode *Node, SelectionDAG &DAG) const;
5907
5908 /// Replace an extraction of a load with a narrowed load.
5909 ///
5910 /// \param ResultVT type of the result extraction.
5911 /// \param InVecVT type of the input vector to with bitcasts resolved.
5912 /// \param EltNo index of the vector element to load.
5913 /// \param OriginalLoad vector load that to be replaced.
5914 /// \returns \p ResultVT Load on success SDValue() on failure.
5915 SDValue scalarizeExtractedVectorLoad(EVT ResultVT, const SDLoc &DL,
5916 EVT InVecVT, SDValue EltNo,
5917 LoadSDNode *OriginalLoad,
5918 SelectionDAG &DAG) const;
5919
5920private:
5921 SDValue foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond,
5922 const SDLoc &DL, DAGCombinerInfo &DCI) const;
5923 SDValue foldSetCCWithOr(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond,
5924 const SDLoc &DL, DAGCombinerInfo &DCI) const;
5925 SDValue foldSetCCWithBinOp(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond,
5926 const SDLoc &DL, DAGCombinerInfo &DCI) const;
5927
5928 SDValue optimizeSetCCOfSignedTruncationCheck(EVT SCCVT, SDValue N0,
5930 DAGCombinerInfo &DCI,
5931 const SDLoc &DL) const;
5932
5933 // (X & (C l>>/<< Y)) ==/!= 0 --> ((X <</l>> Y) & C) ==/!= 0
5934 SDValue optimizeSetCCByHoistingAndByConstFromLogicalShift(
5935 EVT SCCVT, SDValue N0, SDValue N1C, ISD::CondCode Cond,
5936 DAGCombinerInfo &DCI, const SDLoc &DL) const;
5937
5938 SDValue prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5939 SDValue CompTargetNode, ISD::CondCode Cond,
5940 DAGCombinerInfo &DCI, const SDLoc &DL,
5941 SmallVectorImpl<SDNode *> &Created) const;
5942 SDValue buildUREMEqFold(EVT SETCCVT, SDValue REMNode, SDValue CompTargetNode,
5943 ISD::CondCode Cond, DAGCombinerInfo &DCI,
5944 const SDLoc &DL) const;
5945
5946 SDValue prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
5947 SDValue CompTargetNode, ISD::CondCode Cond,
5948 DAGCombinerInfo &DCI, const SDLoc &DL,
5949 SmallVectorImpl<SDNode *> &Created) const;
5950 SDValue buildSREMEqFold(EVT SETCCVT, SDValue REMNode, SDValue CompTargetNode,
5951 ISD::CondCode Cond, DAGCombinerInfo &DCI,
5952 const SDLoc &DL) const;
5953};
5954
5955/// Given an LLVM IR type and return type attributes, compute the return value
5956/// EVTs and flags, and optionally also the offsets, if the return value is
5957/// being lowered to memory.
5958LLVM_ABI void GetReturnInfo(CallingConv::ID CC, Type *ReturnType,
5959 AttributeList attr,
5960 SmallVectorImpl<ISD::OutputArg> &Outs,
5961 const TargetLowering &TLI, const DataLayout &DL);
5962
5963} // end namespace llvm
5964
5965#endif // LLVM_CODEGEN_TARGETLOWERING_H
unsigned const MachineRegisterInfo * MRI
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function Alias Analysis Results
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
block Block Frequency Analysis
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_READONLY
Definition Compiler.h:322
This file defines the DenseMap class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo, const APInt &Demanded)
Check to see if the specified operand of the specified instruction is a constant integer.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define RegName(no)
lazy value info
Implement a low-level type suitable for MachineInstr level instruction selection.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t High
PowerPC Reduce CR logical Operation
const SmallVectorImpl< MachineOperand > & Cond
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 Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
This file defines the SmallVector class.
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")
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static SDValue scalarizeVectorStore(StoreSDNode *Store, MVT StoreVT, SelectionDAG &DAG)
Scalarize a vector store, bitcasting to TargetVT to determine the scalar type.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1497
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
bool isFloatingPointOperation() const
BinOp getOperation() const
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
CCState - This class holds information needed while lowering arguments and return values.
CCValAssign - Represent assignment of one arg/retval to a location.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This class represents a range of values.
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
unsigned size() const
Definition DenseMap.h:110
constexpr bool isScalar() const
Exactly one element.
Definition TypeSize.h:320
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition FastISel.h:66
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
bool isVarArg() const
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition Function.cpp:765
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
A wrapper class for inspecting calls to intrinsic functions.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Tracks which library functions to use for a particular subtarget.
An instruction for reading from memory.
This class is used to represent ISD::LOAD nodes.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Machine Value Type.
@ INVALID_SIMPLE_VALUE_TYPE
SimpleValueType SimpleTy
uint64_t getScalarSizeInBits() const
bool isInteger() const
Return true if this is an integer or a vector integer type.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
ElementCount getVectorElementCount() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
bool isValid() const
Return true if this is a valid simple valuetype.
static MVT getIntegerVT(unsigned BitWidth)
Instructions::iterator instr_iterator
Representation of each machine instruction.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This is an abstract virtual class for memory operations.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition ArrayRef.h:298
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Analysis providing profile information.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
bool hasOneUse() const
Return true if there is exactly one use of this node.
bool use_empty() const
Return true if there are no uses of this node.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
const DataLayout & getDataLayout() const
LLVM_ABI void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVMContext * getContext() const
This instruction constructs a fixed permutation of two input vectors.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
This class is used to represent ISD::STORE nodes.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Multiway switch.
TargetInstrInfo - Interface to description of machine instruction set.
Provides information about what library functions are available for the current target.
ArgListEntry(Value *Val, SDValue Node=SDValue())
ArgListEntry(Value *Val, SDValue Node, Type *Ty)
Type * Ty
Same as OrigTy, or partially legalized for soft float libcalls.
Type * OrigTy
Original unlegalized argument type.
LegalizeTypeAction getTypeAction(MVT VT) const
void setTypeAction(MVT VT, LegalizeTypeAction Action)
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
virtual Value * emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr, AtomicOrdering Ord) const
Perform a store-conditional operation to Addr.
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
bool isOperationExpand(unsigned Op, EVT VT) const
Return true if the specified operation is illegal on this target or unlikely to be made legal with cu...
EVT getMemValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
virtual bool enableAggressiveFMAFusion(LLT Ty) const
Return true if target always benefits from combining into FMA for a given value type.
virtual void emitBitTestAtomicRMWIntrinsic(AtomicRMWInst *AI) const
Perform a bit test atomicrmw using a target-specific intrinsic.
void setOperationAction(ArrayRef< unsigned > Ops, ArrayRef< MVT > VTs, LegalizeAction Action)
virtual bool requiresUniformRegister(MachineFunction &MF, const Value *) const
Allows target to decide about the register class of the specific value that is live outside the defin...
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
virtual unsigned getVaListSizeInBits(const DataLayout &DL) const
Returns the size of the platform's va_list object.
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
virtual bool preferSextInRegOfTruncate(EVT TruncVT, EVT VT, EVT ExtVT) const
virtual bool decomposeMulByConstant(LLVMContext &Context, EVT VT, SDValue C) const
Return true if it is profitable to transform an integer multiplication-by-constant into simpler opera...
void setMaxDivRemBitWidthSupported(unsigned SizeInBits)
Set the size in bits of the maximum div/rem the backend supports.
virtual bool hasAndNot(SDValue X) const
Return true if the target has a bitwise and-not operation: X = ~A & B This can be used to simplify se...
ReciprocalEstimate
Reciprocal estimate status values used by the functions below.
bool PredictableSelectIsExpensive
Tells the code generator that select is more expensive than a branch if the branch is usually predict...
virtual bool isShuffleMaskLegal(ArrayRef< int >, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
virtual bool enableAggressiveFMAFusion(EVT VT) const
Return true if target always benefits from combining into FMA for a given value type.
virtual bool isComplexDeinterleavingOperationSupported(ComplexDeinterleavingOperation Operation, Type *Ty) const
Does this target support complex deinterleaving with the given operation and type.
virtual bool shouldRemoveRedundantExtend(SDValue Op) const
Return true (the default) if it is profitable to remove a sext_inreg(x) where the sext is redundant,...
bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
SDValue promoteTargetBoolean(SelectionDAG &DAG, SDValue Bool, EVT ValVT) const
Promote the given target boolean to a target boolean of the given type.
virtual bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const
Returns true if be combined with to form an ISD::FMAD.
virtual bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT, std::optional< unsigned > ByteOffset=std::nullopt) const
Return true if it is profitable to reduce a load to a smaller type.
virtual bool hasStandaloneRem(EVT VT) const
Return true if the target can handle a standalone remainder operation.
virtual bool isExtFreeImpl(const Instruction *I) const
Return true if the extension represented by I is free.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
virtual bool shouldExpandBuildVectorWithShuffles(EVT, unsigned DefinedValues) const
LegalizeAction getIndexedMaskedStoreAction(unsigned IdxMode, MVT VT) const
Return how the indexed store should be treated: either it is legal, needs to be promoted to a larger ...
virtual bool canCombineTruncStore(EVT ValVT, EVT MemVT, bool LegalOnly) const
virtual bool isSelectSupported(SelectSupportKind) const
CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const
Get the CallingConv that should be used for the specified libcall.
unsigned MaxStoresPerMemcpyOptSize
Likewise for functions with the OptSize attribute.
MachineBasicBlock * emitPatchPoint(MachineInstr &MI, MachineBasicBlock *MBB) const
Replace/modify any TargetFrameIndex operands with a targte-dependent sequence of memory operands that...
virtual bool isEqualityCmpFoldedWithSignedCmp() const
Return true if instruction generated for equality comparison is folded with instruction generated for...
virtual bool preferSelectsOverBooleanArithmetic(EVT VT) const
Should we prefer selects to doing arithmetic on boolean types.
virtual bool useStackGuardXorFP() const
If this function returns true, stack protection checks should XOR the frame pointer (or whichever poi...
virtual bool isLegalICmpImmediate(int64_t) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
virtual bool convertSetCCLogicToBitwiseLogic(EVT VT) const
Use bitwise logic to make pairs of compares more efficient.
void setAtomicLoadExtAction(ArrayRef< unsigned > ExtTypes, MVT ValVT, ArrayRef< MVT > MemVTs, LegalizeAction Action)
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual bool shouldFormOverflowOp(unsigned Opcode, EVT VT, bool MathUsed) const
Try to convert math with an overflow comparison into the corresponding DAG node operation.
ShiftLegalizationStrategy
Return the preferred strategy to legalize tihs SHIFT instruction, with ExpansionFactor being the recu...
virtual bool isVectorLoadExtDesirable(SDValue ExtVal) const
Return true if folding a vector load into ExtVal (a sign, zero, or any extend node) is profitable.
virtual bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const
Return if the target supports combining a chain like:
virtual Value * createComplexDeinterleavingIR(IRBuilderBase &B, ComplexDeinterleavingOperation OperationType, ComplexDeinterleavingRotation Rotation, Value *InputA, Value *InputB, Value *Accumulator=nullptr) const
Create the IR node for the given complex deinterleaving operation.
virtual bool shouldConvertConstantLoadToIntImm(const APInt &Imm, Type *Ty) const
Return true if it is beneficial to convert a load of a constant to just the constant itself.
virtual bool isSupportedFixedPointOperation(unsigned Op, EVT VT, unsigned Scale) const
Custom method defined by each target to indicate if an operation which may require a scale is support...
void setLoadExtAction(ArrayRef< unsigned > ExtTypes, MVT ValVT, MVT MemVT, LegalizeAction Action)
virtual bool shouldOptimizeMulOverflowWithZeroHighBits(LLVMContext &Context, EVT VT) const
virtual AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *RMW) const
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
virtual Sched::Preference getSchedulingPreference(SDNode *) const
Some scheduler, e.g.
virtual MachineInstr * EmitKCFICheck(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator &MBBI, const TargetInstrInfo *TII) const
void setMinStackArgumentAlignment(Align Alignment)
Set the minimum stack alignment of an argument.
bool isExtLoad(const LoadInst *Load, const Instruction *Ext, const DataLayout &DL) const
Return true if Load and Ext can form an ExtLoad.
LegalizeTypeAction getTypeAction(MVT VT) const
virtual bool isLegalScaleForGatherScatter(uint64_t Scale, uint64_t ElemSize) const
EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const
Return true if sign-extension from FromTy to ToTy is cheaper than zero-extension.
virtual bool shouldInsertFencesForAtomic(const Instruction *I) const
Whether AtomicExpandPass should automatically insert fences and reduce ordering for this atomic.
virtual AtomicOrdering atomicOperationOrderAfterFenceSplit(const Instruction *I) const
MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
bool isOperationExpandOrLibCall(unsigned Op, EVT VT) const
virtual bool allowsMisalignedMemoryAccesses(LLT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *=nullptr) const
LLT handling variant.
virtual bool isSafeMemOpType(MVT) const
Returns true if it's safe to use load / store of the specified type to expand memcpy / memset inline.
virtual void emitExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) const
Perform a cmpxchg expansion using a target-specific method.
virtual CondMergingParams getJumpConditionMergingParams(Instruction::BinaryOps, const Value *, const Value *) const
virtual ISD::NodeType getExtendForAtomicRMWArg(unsigned Op) const
Returns how the platform's atomic rmw operations expect their input argument to be extended (ZERO_EXT...
const TargetMachine & getTargetMachine() const
unsigned MaxLoadsPerMemcmp
Specify maximum number of load instructions per memcmp call.
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
bool rangeFitsInWord(const APInt &Low, const APInt &High, const DataLayout &DL) const
Check whether the range [Low,High] fits in a machine word.
virtual bool isCtpopFast(EVT VT) const
Return true if ctpop instruction is fast.
virtual MachineMemOperand::Flags getTargetMMOFlags(const Instruction &I) const
This callback is used to inspect load/store instructions and add target-specific MachineMemOperand fl...
unsigned MaxGluedStoresPerMemcpy
Specify max number of store instructions to glue in inlined memcpy.
virtual bool isZExtFree(Type *FromTy, Type *ToTy) const
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
bool isPaddedAtMostSignificantBitsWhenStored(EVT VT) const
Indicates if any padding is guaranteed to go at the most significant bits when storing the type to me...
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
Convenience method to set an operation to Promote and specify the type in a single call.
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
unsigned getMinCmpXchgSizeInBits() const
Returns the size of the smallest cmpxchg or ll/sc instruction the backend supports.
virtual Value * emitMaskedAtomicRMWIntrinsic(IRBuilderBase &Builder, AtomicRMWInst *AI, Value *AlignedAddr, Value *Incr, Value *Mask, Value *ShiftAmt, AtomicOrdering Ord) const
Perform a masked atomicrmw using a target-specific intrinsic.
virtual bool areJTsAllowed(const Function *Fn) const
Return true if lowering to a jump table is allowed.
bool enableExtLdPromotion() const
Return true if the target wants to use the optimization that turns ext(promotableInst1(....
virtual bool isFPExtFoldable(const MachineInstr &MI, unsigned Opcode, LLT DestTy, LLT SrcTy) const
Return true if an fpext operation input to an Opcode operation is free (for instance,...
void setIndexedMaskedLoadAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed masked load does or does not work with the specified type and ind...
void setMaxBytesForAlignment(unsigned MaxBytes)
bool isOperationLegalOrPromote(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal using promotion.
void setHasExtractBitsInsn(bool hasExtractInsn=true)
Tells the code generator that the target has BitExtract instructions.
void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth)
Tells the code generator which bitwidths to bypass.
virtual bool hasBitTest(SDValue X, SDValue Y) const
Return true if the target has a bit-test instruction: (X & (1 << Y)) ==/!= 0 This knowledge can be us...
MVT getRegisterType(LLVMContext &Context, EVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual AtomicExpansionKind shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const
Returns how the given atomic cmpxchg should be expanded by the IR-level AtomicExpand pass.
virtual bool needsFixedCatchObjects() const
EVT getLegalTypeToTransformTo(LLVMContext &Context, EVT VT) const
Perform getTypeToTransformTo repeatedly until a legal type is obtained.
virtual Value * emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr, AtomicOrdering Ord) const
Perform a load-linked operation on Addr, returning a "Value *" with the corresponding pointee type.
void setMaxLargeFPConvertBitWidthSupported(unsigned SizeInBits)
Set the size in bits of the maximum fp to/from int conversion the backend supports.
const LibcallLoweringInfo & getLibcallLoweringInfo() const
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
virtual bool isCheapToSpeculateCttz(Type *Ty) const
Return true if it is cheap to speculate a call to intrinsic cttz.
unsigned getMinimumBitTestCmps() const
Retuen the minimum of largest number of comparisons in BitTest.
bool isJumpExpensive() const
Return true if Flow Control is an expensive operation that should be avoided.
virtual bool useFPRegsForHalfType() const
LegalizeAction getCondCodeAction(ISD::CondCode CC, MVT VT) const
Return how the condition code should be treated: either it is legal, needs to be expanded to some oth...
bool hasExtractBitsInsn() const
Return true if the target has BitExtract instructions.
bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const
Return true if the specified store with truncation is legal on this target.
virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG, const MachineMemOperand &MMO) const
Return true if the following transform is beneficial: fold (conv (load x)) -> (load (conv*)x) On arch...
LegalizeAction getIndexedStoreAction(unsigned IdxMode, MVT VT) const
Return how the indexed store should be treated: either it is legal, needs to be promoted to a larger ...
void setIndexedLoadAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall implementation.
void setPrefLoopAlignment(Align Alignment)
Set the target's preferred loop alignment.
virtual bool softPromoteHalfType() const
Warning: this option is problem-prone and tends to introduce float miscompilations:
virtual bool areTwoSDNodeTargetMMOFlagsMergeable(const MemSDNode &NodeX, const MemSDNode &NodeY) const
Return true if it is valid to merge the TargetMMOFlags in two SDNodes.
virtual bool isCommutativeBinOp(unsigned Opcode) const
Returns true if the opcode is a commutative binary operation.
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
virtual bool isFPImmLegal(const APFloat &, EVT, bool ForCodeSize=false) const
Returns true if the target can instruction select the specified FP immediate natively.
virtual unsigned getPreferredFPToIntOpcode(unsigned Op, EVT FromVT, EVT ToVT) const
virtual bool isExtractVecEltCheap(EVT VT, unsigned Index) const
Return true if extraction of a scalar element from the given vector type at the given index is cheap.
void setOperationAction(ArrayRef< unsigned > Ops, MVT VT, LegalizeAction Action)
virtual bool optimizeFMulOrFDivAsShiftAddBitcast(SDNode *N, SDValue FPConst, SDValue IntPow2) const
SelectSupportKind
Enum that describes what type of support for selects the target has.
RTLIB::LibcallImpl getMemcpyImpl() const
LegalizeAction getIndexedLoadAction(unsigned IdxMode, MVT VT) const
Return how the indexed load should be treated: either it is legal, needs to be promoted to a larger s...
virtual bool shouldTransformSignedTruncationCheck(EVT XVT, unsigned KeptBits) const
Should we tranform the IR-optimal check for whether given truncation down into KeptBits would be trun...
virtual bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode, EVT DestVT, EVT SrcVT) const
Return true if an fpext operation input to an Opcode operation is free (for instance,...
bool isLegalRC(const TargetRegisterInfo &TRI, const TargetRegisterClass &RC) const
Return true if the value types that can be represented by the specified register class are all legal.
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const
Return the preferred vector type legalization action.
virtual bool allowTruncateForTailCall(Type *FromTy, Type *ToTy) const
Return true if a truncation from FromTy to ToTy is permitted when deciding whether a call is in tail ...
void setAtomicLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Let target indicate that an extending atomic load of the specified type is legal.
virtual bool shouldExtendGSIndex(EVT VT, EVT &EltTy) const
Returns true if the index type for a masked gather/scatter requires extending.
virtual unsigned getVectorTypeBreakdownForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Certain targets such as MIPS require that some types such as vectors are always broken down into scal...
virtual bool shouldNormalizeToSelectSequence(LLVMContext &Context, EVT VT) const
Returns true if we should normalize select(N0&N1, X, Y) => select(N0, select(N1, X,...
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
virtual StringRef getStackProbeSymbolName(const MachineFunction &MF) const
LegalizeAction getFixedPointOperationAction(unsigned Op, EVT VT, unsigned Scale) const
Some fixed point operations may be natively supported by the target but only for specific scales.
virtual bool preferScalarizeSplat(SDNode *N) const
bool isIndexedMaskedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
virtual ISD::NodeType getExtendForAtomicOps() const
Returns how the platform's atomic operations are extended (ZERO_EXTEND, SIGN_EXTEND,...
Sched::Preference getSchedulingPreference() const
Return target scheduling preference.
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *=nullptr) const
Determine if the target supports unaligned memory accesses.
virtual LLT getOptimalMemOpLLT(const MemOp &Op, const AttributeList &) const
LLT returning variant.
void setMinFunctionAlignment(Align Alignment)
Set the target's minimum function alignment.
bool isOperationCustom(unsigned Op, EVT VT) const
Return true if the operation uses custom lowering, regardless of whether the type is legal or not.
virtual void emitExpandAtomicRMW(AtomicRMWInst *AI) const
Perform a atomicrmw expansion using a target-specific way.
unsigned MaxStoresPerMemsetOptSize
Likewise for functions with the OptSize attribute.
virtual bool reduceSelectOfFPConstantLoads(EVT CmpOpVT) const
Return true if it is profitable to convert a select of FP constants into a constant pool load whose a...
bool hasBigEndianPartOrdering(EVT VT, const DataLayout &DL) const
When splitting a value of the specified type into parts, does the Lo or Hi part come first?
virtual bool hasStackProbeSymbol(const MachineFunction &MF) const
Returns the name of the symbol used to emit stack probes or the empty string if not applicable.
bool isSlowDivBypassed() const
Returns true if target has indicated at least one type should be bypassed.
virtual Align getABIAlignmentForCallingConv(Type *ArgTy, const DataLayout &DL) const
Certain targets have context sensitive alignment requirements, where one type has the alignment requi...
virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, unsigned Index) const
Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type from this source type with ...
virtual bool isMulAddWithConstProfitable(SDValue AddNode, SDValue ConstNode) const
Return true if it may be profitable to transform (mul (add x, c1), c2) -> (add (mul x,...
virtual bool shouldExtendTypeInLibCall(EVT Type) const
Returns true if arguments should be extended in lib calls.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
bool isPartialReduceMLALegalOrCustom(unsigned Opc, EVT AccVT, EVT InputVT) const
Return true if a PARTIAL_REDUCE_U/SMLA node with the specified types is legal or custom for this targ...
virtual bool isFsqrtCheap(SDValue X, SelectionDAG &DAG) const
Return true if SQRT(X) shouldn't be replaced with X*RSQRT(X).
unsigned MaxStoresPerMemmove
Specify maximum number of store instructions per memmove call.
bool isSuitableForBitTests(const DenseMap< const BasicBlock *, unsigned int > &DestCmps, const APInt &Low, const APInt &High, const DataLayout &DL) const
Return true if lowering to a bit test is suitable for a set of case clusters which contains NumDests ...
virtual bool shouldExpandGetActiveLaneMask(EVT VT, EVT OpVT) const
Return true if the @llvm.get.active.lane.mask intrinsic should be expanded using generic code in Sele...
virtual bool shallExtractConstSplatVectorElementToStore(Type *VectorTy, unsigned ElemSizeInBits, unsigned &Index) const
Return true if the target shall perform extract vector element and store given that the vector is kno...
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
virtual bool hasMultipleConditionRegisters(EVT VT) const
Does the target have multiple (allocatable) condition registers that can be used to store the results...
virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallBase &, MachineFunction &, unsigned) const
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
unsigned getMaxExpandSizeMemcmp(bool OptSize) const
Get maximum # of load operations permitted for memcmp.
bool isStrictFPEnabled() const
Return true if the target support strict float operation.
virtual bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const
Return true if creating a shift of the type by the given amount is not profitable.
virtual bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const
True if target has some particular form of dealing with pointer arithmetic semantics for pointers wit...
virtual bool isFPExtFree(EVT DestVT, EVT SrcVT) const
Return true if an fpext operation is free (for instance, because single-precision floating-point numb...
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
virtual bool lowerInterleavedStore(Instruction *Store, Value *Mask, ShuffleVectorInst *SVI, unsigned Factor, const APInt &GapMask) const
Lower an interleaved store to target specific intrinsics.
virtual EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
unsigned MaxStoresPerMemmoveOptSize
Likewise for functions with the OptSize attribute.
virtual bool shouldFoldSelectWithSingleBitTest(EVT VT, const APInt &AndMask) const
MVT getSimpleValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the MVT corresponding to this LLVM type. See getValueType.
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
virtual bool shouldReassociateReduction(unsigned RedOpc, EVT VT) const
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal for a comparison of the specified types on this ...
virtual bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx, unsigned &Cost) const
Return true if the target can combine store(extractelement VectorTy,Idx).
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
LegalizeAction getAtomicLoadExtAction(unsigned ExtType, EVT ValVT, EVT MemVT) const
Same as getLoadExtAction, but for atomic loads.
virtual bool shouldFoldConstantShiftPairToMask(const SDNode *N) const
Return true if it is profitable to fold a pair of shifts into a mask.
MVT getProgramPointerTy(const DataLayout &DL) const
Return the type for code pointers, which is determined by the program address space specified through...
void setIndexedStoreAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed store does or does not work with the specified type and indicate ...
virtual void emitAtomicCmpXchgNoStoreLLBalance(IRBuilderBase &Builder) const
void setSupportsUnalignedAtomics(bool UnalignedSupported)
Sets whether unaligned atomic operations are supported.
void setLoadExtAction(ArrayRef< unsigned > ExtTypes, MVT ValVT, ArrayRef< MVT > MemVTs, LegalizeAction Action)
virtual void emitExpandAtomicStore(StoreInst *SI) const
Perform a atomic store using a target-specific way.
virtual bool preferIncOfAddToSubOfNot(EVT VT) const
These two forms are equivalent: sub y, (xor x, -1) add (add x, 1), y The variant with two add's is IR...
virtual bool ShouldShrinkFPConstant(EVT) const
If true, then instruction selection should seek to shrink the FP constant of the specified type to a ...
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setPrefFunctionAlignment(Align Alignment)
Set the target's preferred function alignment.
unsigned getMaxDivRemBitWidthSupported() const
Returns the size in bits of the maximum div/rem the backend supports.
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
virtual unsigned getMaxSupportedInterleaveFactor() const
Get the maximum supported factor for interleaved memory accesses.
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const
Return how this store with truncation should be treated: either it is legal, needs to be promoted to ...
virtual bool shouldKeepZExtForFP16Conv() const
Does this target require the clearing of high-order bits in a register passed to the fp16 to fp conve...
virtual AtomicExpansionKind shouldCastAtomicRMWIInIR(AtomicRMWInst *RMWI) const
Returns how the given atomic atomicrmw should be cast by the IR-level AtomicExpand pass.
void setIndexedMaskedStoreAction(unsigned IdxMode, MVT VT, LegalizeAction Action)
Indicate that the specified indexed masked store does or does not work with the specified type and in...
virtual bool canTransformPtrArithOutOfBounds(const Function &F, EVT PtrVT) const
True if the target allows transformations of in-bounds pointer arithmetic that cause out-of-bounds in...
virtual bool shouldConsiderGEPOffsetSplit() const
const ValueTypeActionImpl & getValueTypeActions() const
TargetLoweringBase(const TargetMachine &TM, const TargetSubtargetInfo &STI)
NOTE: The TargetMachine owns TLOF.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
virtual bool isTruncateFree(SDValue Val, EVT VT2) const
Return true if truncating the specific node Val to type VT2 is free.
virtual bool shouldExpandVectorMatch(EVT VT, unsigned SearchSize) const
Return true if the @llvm.experimental.vector.match intrinsic should be expanded for vector type ‘VT’ ...
virtual bool isProfitableToCombineMinNumMaxNum(EVT VT) const
virtual unsigned getCustomCtpopCost(EVT VT, ISD::CondCode Cond) const
Return the maximum number of "x & (x - 1)" operations that can be done instead of deferring to a cust...
virtual bool shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y, unsigned OldShiftOpcode, unsigned NewShiftOpcode, SelectionDAG &DAG) const
Given the pattern (X & (C l>>/<< Y)) ==/!= 0 return true if it should be transformed into: ((X <</l>>...
virtual bool shouldInsertTrailingSeqCstFenceForAtomicStore(const Instruction *I) const
Whether AtomicExpandPass should automatically insert a seq_cst trailing fence without reducing the or...
virtual bool isFNegFree(EVT VT) const
Return true if an fneg operation is free to the point where it is never worthwhile to replace it with...
void setPartialReduceMLAAction(unsigned Opc, MVT AccVT, MVT InputVT, LegalizeAction Action)
Indicate how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type InputVT should be treate...
LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return how this load with extension should be treated: either it is legal, needs to be promoted to a ...
virtual AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
bool isExtFree(const Instruction *I) const
Return true if the extension represented by I is free.
virtual MVT getFenceOperandTy(const DataLayout &DL) const
Return the type for operands of fence.
virtual Value * emitMaskedAtomicCmpXchgIntrinsic(IRBuilderBase &Builder, AtomicCmpXchgInst *CI, Value *AlignedAddr, Value *CmpVal, Value *NewVal, Value *Mask, AtomicOrdering Ord) const
Perform a masked cmpxchg using a target-specific intrinsic.
virtual bool isZExtFree(EVT FromTy, EVT ToTy) const
virtual ISD::NodeType getExtendForAtomicCmpSwapArg() const
Returns how the platform's atomic compare and swap expects its comparison value to be extended (ZERO_...
virtual bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode, EVT VT, unsigned SelectOpcode, SDValue X, SDValue Y) const
Return true if pulling a binary operation into a select with an identity constant is profitable.
BooleanContent
Enum that describes how the target represents true/false values.
virtual bool shouldExpandGetVectorLength(EVT CountVT, unsigned VF, bool IsScalable) const
virtual bool isIntDivCheap(EVT VT, AttributeList Attr) const
Return true if integer divide is usually cheaper than a sequence of several shifts,...
virtual ShiftLegalizationStrategy preferredShiftLegalizationStrategy(SelectionDAG &DAG, SDNode *N, unsigned ExpansionFactor) const
virtual uint8_t getRepRegClassCostFor(MVT VT) const
Return the cost of the 'representative' register class for the specified value type.
virtual bool isZExtFree(LLT FromTy, LLT ToTy, LLVMContext &Ctx) const
bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
LegalizeAction getPartialReduceMLAAction(unsigned Opc, EVT AccVT, EVT InputVT) const
Return how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type InputVT should be treated.
bool isPredictableSelectExpensive() const
Return true if selects are only cheaper than branches if the branch is unlikely to be predicted right...
virtual bool mergeStoresAfterLegalization(EVT MemVT) const
Allow store merging for the specified type after legalization in addition to before legalization.
virtual bool shouldMergeStoreOfLoadsOverCall(EVT, EVT) const
Returns true if it's profitable to allow merging store of loads when there are functions calls betwee...
RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const
Check if this is valid libcall for the current module, otherwise RTLIB::Unsupported.
virtual bool isProfitableToHoist(Instruction *I) const
unsigned getGatherAllAliasesMaxDepth() const
virtual LegalizeAction getCustomOperationAction(SDNode &Op) const
How to legalize this custom operation?
virtual bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *) const
IR version.
virtual bool hasAndNotCompare(SDValue Y) const
Return true if the target should transform: (X & Y) == Y ---> (~X & Y) == 0 (X & Y) !...
virtual bool storeOfVectorConstantIsCheap(bool IsZero, EVT MemVT, unsigned NumElem, unsigned AddrSpace) const
Return true if it is expected to be cheaper to do a store of vector constant with the given size and ...
unsigned MaxLoadsPerMemcmpOptSize
Likewise for functions with the OptSize attribute.
virtual MVT hasFastEqualityCompare(unsigned NumBits) const
Return the preferred operand type if the target has a quick way to compare integer values of the give...
virtual const TargetRegisterClass * getRepRegClassFor(MVT VT) const
Return the 'representative' register class for the specified value type.
virtual bool isNarrowingProfitable(SDNode *N, EVT SrcVT, EVT DestVT) const
Return true if it's profitable to narrow operations of type SrcVT to DestVT.
virtual bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const
Return true if it is cheaper to split the store of a merged int val from a pair of smaller values int...
bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal or custom on this target.
TargetLoweringBase(const TargetLoweringBase &)=delete
virtual unsigned getMaxGluedStoresPerMemcpy() const
Get maximum # of store operations to be glued together.
bool isAtomicLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified atomic load with extension is legal on this target.
virtual bool isBinOp(unsigned Opcode) const
Return true if the node is a math/logic binary operator.
virtual bool shouldFoldMaskToVariableShiftPair(SDValue X) const
There are two ways to clear extreme bits (either low or high): Mask: x & (-1 << y) (the instcombine c...
virtual bool alignLoopsWithOptSize() const
Should loops be aligned even when the function is marked OptSize (but not MinSize).
unsigned getMaxAtomicSizeInBitsSupported() const
Returns the maximum atomic operation size (in bits) supported by the backend.
bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
Sets the minimum cmpxchg or ll/sc size supported by the backend.
virtual bool canMergeStoresTo(unsigned AS, EVT MemVT, const MachineFunction &MF) const
Returns if it's reasonable to merge stores to MemVT size.
void setPartialReduceMLAAction(ArrayRef< unsigned > Opcodes, MVT AccVT, MVT InputVT, LegalizeAction Action)
LegalizeAction getStrictFPOperationAction(unsigned Op, EVT VT) const
void setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
virtual bool preferABDSToABSWithNSW(EVT VT) const
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
virtual bool getAddrModeArguments(const IntrinsicInst *, SmallVectorImpl< Value * > &, Type *&) const
CodeGenPrepare sinks address calculations into the same BB as Load/Store instructions reading the add...
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal on this target.
virtual bool hasInlineStackProbe(const MachineFunction &MF) const
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
void setBooleanContents(BooleanContent IntTy, BooleanContent FloatTy)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
const DenseMap< unsigned int, unsigned int > & getBypassSlowDivWidths() const
Returns map of slow types for division or remainder with corresponding fast types.
void setOperationPromotedToType(ArrayRef< unsigned > Ops, MVT OrigVT, MVT DestVT)
unsigned getMaxLargeFPConvertBitWidthSupported() const
Returns the size in bits of the maximum fp to/from int conversion the backend supports.
virtual bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, LLT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
virtual bool isTruncateFree(EVT FromVT, EVT ToVT) const
virtual bool isCheapToSpeculateCtlz(Type *Ty) const
Return true if it is cheap to speculate a call to intrinsic ctlz.
virtual bool shouldExpandCttzElements(EVT VT) const
Return true if the @llvm.experimental.cttz.elts intrinsic should be expanded using generic code in Se...
virtual bool signExtendConstant(const ConstantInt *C) const
Return true if this constant should be sign extended when promoting to a larger type.
virtual bool lowerInterleaveIntrinsicToStore(Instruction *Store, Value *Mask, ArrayRef< Value * > InterleaveValues) const
Lower an interleave intrinsic to a target specific store intrinsic.
virtual bool isTruncateFree(LLT FromTy, LLT ToTy, LLVMContext &Ctx) const
AndOrSETCCFoldKind
Enum of different potentially desirable ways to fold (and/or (setcc ...), (setcc ....
virtual bool shouldScalarizeBinop(SDValue VecOp) const
Try to convert an extract element of a vector binary operation into an extract element followed by a ...
Align getPrefFunctionAlignment() const
Return the preferred function alignment.
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Get the libcall impl routine name for the specified libcall.
virtual void emitExpandAtomicLoad(LoadInst *LI) const
Perform a atomic load using a target-specific way.
Align getMinFunctionAlignment() const
Return the minimum function alignment.
virtual AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call)
Get the libcall routine name for the specified libcall implementation.
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
virtual bool isCtlzFast() const
Return true if ctlz instruction is fast.
virtual bool useSoftFloat() const
virtual bool isStoreBitCastBeneficial(EVT StoreVT, EVT BitcastVT, const SelectionDAG &DAG, const MachineMemOperand &MMO) const
Return true if the following transform is beneficial: (store (y (conv x)), y*)) -> (store x,...
BooleanContent getBooleanContents(EVT Type) const
bool isIndexedMaskedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
virtual int64_t getPreferredLargeGEPBaseOffset(int64_t MinOffset, int64_t MaxOffset) const
Return the prefered common base offset.
virtual bool isVectorClearMaskLegal(ArrayRef< int >, EVT) const
Similar to isShuffleMaskLegal.
LegalizeKind getTypeConversion(LLVMContext &Context, EVT VT) const
Return pair that represents the legalization kind (first) that needs to happen to EVT (second) in ord...
Align getMinStackArgumentAlignment() const
Return the minimum stack alignment of an argument.
virtual bool shouldUseStrictFP_TO_INT(EVT FpVT, EVT IntVT, bool IsSigned) const
Return true if it is more correct/profitable to use strict FP_TO_INT conversion operations - canonica...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
bool hasTargetDAGCombine(ISD::NodeType NT) const
If true, the target has custom DAG combine transformations that it can perform for the specified node...
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl)
virtual bool fallBackToDAGISel(const Instruction &Inst) const
unsigned GatherAllAliasesMaxDepth
Depth that GatherAllAliases should continue looking for chain dependencies when trying to find a more...
virtual bool shouldSplatInsEltVarIndex(EVT) const
Return true if inserting a scalar into a variable element of an undef vector is more efficiently hand...
LegalizeAction getIndexedMaskedLoadAction(unsigned IdxMode, MVT VT) const
Return how the indexed load should be treated: either it is legal, needs to be promoted to a larger s...
NegatibleCost
Enum that specifies when a float negation is beneficial.
bool isTruncStoreLegalOrCustom(EVT ValVT, EVT MemVT) const
Return true if the specified store with truncation has solution on this target.
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
virtual unsigned preferedOpcodeForCmpEqPiecesOfOperand(EVT VT, unsigned ShiftOpc, bool MayTransformRotate, const APInt &ShiftOrRotateAmt, const std::optional< APInt > &AndMask) const
virtual void emitCmpArithAtomicRMWIntrinsic(AtomicRMWInst *AI) const
Perform a atomicrmw which the result is only used by comparison, using a target-specific intrinsic.
virtual bool shouldSignExtendTypeInLibCall(Type *Ty, bool IsSigned) const
Returns true if arguments should be sign-extended in lib calls.
virtual Register getExceptionPointerRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
virtual bool isFMADLegal(const MachineInstr &MI, LLT Ty) const
Returns true if MI can be combined with another instruction to form TargetOpcode::G_FMAD.
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, ArrayRef< MVT > VTs, LegalizeAction Action)
bool supportsUnalignedAtomics() const
Whether the target supports unaligned atomic operations.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
virtual bool isLegalAddScalableImmediate(int64_t) const
Return true if adding the specified scalable immediate is legal, that is the target has add instructi...
std::vector< ArgListEntry > ArgListTy
virtual bool shouldAlignPointerArgs(CallInst *, unsigned &, Align &) const
Return true if the pointer arguments to CI should be aligned by aligning the object whose address is ...
virtual bool hasVectorBlend() const
Return true if the target has a vector blend instruction.
virtual AtomicExpansionKind shouldCastAtomicStoreInIR(StoreInst *SI) const
Returns how the given (atomic) store should be cast by the IR-level AtomicExpand pass into.
void setIndexedStoreAction(ArrayRef< unsigned > IdxModes, ArrayRef< MVT > VTs, LegalizeAction Action)
virtual bool isVScaleKnownToBeAPowerOfTwo() const
Return true only if vscale must be a power of two.
virtual bool aggressivelyPreferBuildVectorSources(EVT VecVT) const
virtual MachineMemOperand::Flags getTargetMMOFlags(const MemSDNode &Node) const
This callback is used to inspect load/store SDNode.
virtual EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op, const AttributeList &) const
Returns the target specific optimal type for load and store operations as a result of memset,...
virtual Type * shouldConvertSplatType(ShuffleVectorInst *SVI) const
Given a shuffle vector SVI representing a vector splat, return a new scalar type of size equal to SVI...
virtual bool isZExtFree(SDValue Val, EVT VT2) const
Return true if zero-extending the specific node Val to type VT2 is free (either because it's implicit...
void setAtomicLoadExtAction(ArrayRef< unsigned > ExtTypes, MVT ValVT, MVT MemVT, LegalizeAction Action)
virtual bool shouldRemoveExtendFromGSIndex(SDValue Extend, EVT DataVT) const
virtual LLVM_READONLY LLT getPreferredShiftAmountTy(LLT ShiftValueTy) const
Return the preferred type to use for a shift opcode, given the shifted amount type is ShiftValueTy.
bool isBeneficialToExpandPowI(int64_t Exponent, bool OptForSize) const
Return true if it is beneficial to expand an @llvm.powi.
LLT getVectorIdxLLT(const DataLayout &DL) const
Returns the type to be used for the index operand of: G_INSERT_VECTOR_ELT, G_EXTRACT_VECTOR_ELT,...
virtual EVT getAsmOperandValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
void setIndexedLoadAction(ArrayRef< unsigned > IdxModes, ArrayRef< MVT > VTs, LegalizeAction Action)
virtual AtomicExpansionKind shouldCastAtomicLoadInIR(LoadInst *LI) const
Returns how the given (atomic) load should be cast by the IR-level AtomicExpand pass.
bool isCondCodeLegalOrCustom(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal or custom for a comparison of the specified type...
virtual bool isComplexDeinterleavingSupported() const
Does this target support complex deinterleaving.
unsigned MaxStoresPerMemcpy
Specify maximum number of store instructions per memcpy call.
MVT getFrameIndexTy(const DataLayout &DL) const
Return the type for frame index, which is determined by the alloca address space specified through th...
virtual Register getExceptionSelectorRegister(const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
virtual MVT getPointerMemTy(const DataLayout &DL, uint32_t AS=0) const
Return the in-memory pointer type for the given address space, defaults to the pointer type from the ...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
virtual bool addressingModeSupportsTLS(const GlobalValue &) const
Returns true if the targets addressing mode can target thread local storage (TLS).
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual bool shouldConvertPhiType(Type *From, Type *To) const
Given a set in interconnected phis of type 'From' that are loaded/stored or bitcast to type 'To',...
virtual bool isFAbsFree(EVT VT) const
Return true if an fabs operation is free to the point where it is never worthwhile to replace it with...
virtual bool isLegalStoreImmediate(int64_t Value) const
Return true if the specified immediate is legal for the value input of a store instruction.
virtual bool preferZeroCompareBranch() const
Return true if the heuristic to prefer icmp eq zero should be used in code gen prepare.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
virtual bool lowerInterleavedLoad(Instruction *Load, Value *Mask, ArrayRef< ShuffleVectorInst * > Shuffles, ArrayRef< unsigned > Indices, unsigned Factor, const APInt &GapMask) const
Lower an interleaved load to target specific intrinsics.
virtual unsigned getVectorIdxWidth(const DataLayout &DL) const
Returns the type to be used for the index operand vector operations.
MVT getTypeToPromoteTo(unsigned Op, MVT VT) const
If the action for this operation is to promote, this method returns the ValueType to promote to.
virtual bool generateFMAsInMachineCombiner(EVT VT, CodeGenOptLevel OptLevel) const
virtual LoadInst * lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *RMWI) const
On some platforms, an AtomicRMW that never actually modifies the value (such as fetch_add of 0) can b...
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace, Instruction *I=nullptr) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
virtual bool hasPairedLoad(EVT, Align &) const
Return true if the target supplies and combines to a paired load two loaded values of type LoadedType...
virtual bool convertSelectOfConstantsToMath(EVT VT) const
Return true if a select of constants (select Cond, C1, C2) should be transformed into simple math ops...
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, EVT &IntermediateVT, unsigned &NumIntermediates, MVT &RegisterVT) const
Vector types are broken down into some number of legal first class types.
virtual bool optimizeExtendOrTruncateConversion(Instruction *I, Loop *L, const TargetTransformInfo &TTI) const
Try to optimize extending or truncating conversion instructions (like zext, trunc,...
virtual MVT getVPExplicitVectorLengthTy() const
Returns the type to be used for the EVL/AVL operand of VP nodes: ISD::VP_ADD, ISD::VP_SUB,...
std::pair< LegalizeTypeAction, EVT > LegalizeKind
LegalizeKind holds the legalization kind that needs to happen to EVT in order to type-legalize it.
TargetLoweringBase & operator=(const TargetLoweringBase &)=delete
MulExpansionKind
Enum that specifies when a multiplication should be expanded.
static ISD::NodeType getExtendForContent(BooleanContent Content)
const RTLIB::RuntimeLibcallsInfo & getRuntimeLibcallsInfo() const
virtual bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const
Should we generate fp_to_si_sat and fp_to_ui_sat from type FPVT to type VT from min(max(fptoi)) satur...
virtual bool lowerDeinterleaveIntrinsicToLoad(Instruction *Load, Value *Mask, IntrinsicInst *DI) const
Lower a deinterleave intrinsic to a target specific load intrinsic.
virtual bool supportKCFIBundles() const
Return true if the target supports kcfi operand bundles.
virtual ConstraintWeight getMultipleConstraintMatchWeight(AsmOperandInfo &info, int maIndex) const
Examine constraint type and operand type and determine a weight value.
SmallVector< ConstraintPair > ConstraintGroup
virtual SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps, bool &UseOneConstNR, bool Reciprocal) const
Hooks for building estimates in place of slower divisions and square roots.
virtual bool isDesirableToCommuteWithShift(const MachineInstr &MI, bool IsAfterLegal) const
GlobalISel - return true if it is profitable to move this shift by a constant amount through its oper...
virtual bool supportPtrAuthBundles() const
Return true if the target supports ptrauth operand bundles.
virtual void ReplaceNodeResults(SDNode *, SmallVectorImpl< SDValue > &, SelectionDAG &) const
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
virtual bool isUsedByReturnOnly(SDNode *, SDValue &) const
Return true if result of the specified node is used by a return node only.
virtual bool supportSwiftError() const
Return true if the target supports swifterror attribute.
virtual SDValue visitMaskedLoad(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, MachineMemOperand *MMO, SDValue &NewLoad, SDValue Ptr, SDValue PassThru, SDValue Mask) const
virtual SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, const SDLoc &DL) const
SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, bool OptForSize, unsigned Depth=0) const
This is the helper function to return the newly negated expression if the cost is not expensive.
virtual bool isReassocProfitable(SelectionDAG &DAG, SDValue N0, SDValue N1) const
virtual EVT getTypeForExtReturn(LLVMContext &Context, EVT VT, ISD::NodeType) const
Return the type that should be used to zero or sign extend a zeroext/signext integer return value.
SDValue getCheaperOrNeutralNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, bool OptForSize, const NegatibleCost CostThreshold=NegatibleCost::Neutral, unsigned Depth=0) const
virtual Register getRegisterByName(const char *RegName, LLT Ty, const MachineFunction &MF) const
Return the register ID of the name passed in.
virtual InlineAsm::ConstraintCode getInlineAsmMemConstraint(StringRef ConstraintCode) const
virtual bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, TargetLoweringOpt &TLO) const
std::vector< AsmOperandInfo > AsmOperandInfoVector
virtual bool isTargetCanonicalConstantNode(SDValue Op) const
Returns true if the given Opc is considered a canonical constant for the target, which should not be ...
virtual bool isTargetCanonicalSelect(SDNode *N) const
Return true if the given select/vselect should be considered canonical and not be transformed.
SDValue getCheaperNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, bool OptForSize, unsigned Depth=0) const
This is the helper function to return the newly negated expression only when the cost is cheaper.
virtual SDValue prepareVolatileOrAtomicLoad(SDValue Chain, const SDLoc &DL, SelectionDAG &DAG) const
This callback is used to prepare for a volatile or atomic load.
virtual SDValue lowerEHPadEntry(SDValue Chain, const SDLoc &DL, SelectionDAG &DAG) const
Optional target hook to add target-specific actions when entering EH pad blocks.
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual SDValue unwrapAddress(SDValue N) const
virtual bool splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts, unsigned NumParts, MVT PartVT, std::optional< CallingConv::ID > CC) const
Target-specific splitting of values into parts that fit a register storing a legal type.
virtual bool IsDesirableToPromoteOp(SDValue, EVT &) const
This method query the target whether it is beneficial for dag combiner to promote the specified node.
virtual SDValue joinRegisterPartsIntoValue(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts, unsigned NumParts, MVT PartVT, EVT ValueVT, std::optional< CallingConv::ID > CC) const
Target-specific combining of register parts into its original value.
virtual void insertCopiesSplitCSR(MachineBasicBlock *Entry, const SmallVectorImpl< MachineBasicBlock * > &Exits) const
Insert explicit copies in entry and exit blocks.
virtual SDValue LowerCall(CallLoweringInfo &, SmallVectorImpl< SDValue > &) const
This hook must be implemented to lower calls into the specified DAG.
virtual bool isTypeDesirableForOp(unsigned, EVT VT) const
Return true if the target has native support for the specified value type and it is 'desirable' to us...
~TargetLowering() override
TargetLowering & operator=(const TargetLowering &)=delete
virtual bool isDesirableToPullExtFromShl(const MachineInstr &MI) const
GlobalISel - return true if it's profitable to perform the combine: shl ([sza]ext x),...
bool isPositionIndependent() const
std::pair< StringRef, TargetLowering::ConstraintType > ConstraintPair
virtual SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, bool OptForSize, NegatibleCost &Cost, unsigned Depth=0) const
Return the newly negated expression if the cost is not expensive and set the cost in Cost to indicate...
virtual ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const
Examine constraint string and operand type and determine a weight value.
virtual bool isIndexingLegal(MachineInstr &MI, Register Base, Register Offset, bool IsPre, MachineRegisterInfo &MRI) const
Returns true if the specified base+offset is a legal indexed addressing mode for this target.
ConstraintGroup getConstraintPreferences(AsmOperandInfo &OpInfo) const
Given an OpInfo with list of constraints codes as strings, return a sorted Vector of pairs of constra...
virtual void initializeSplitCSR(MachineBasicBlock *Entry) const
Perform necessary initialization to handle a subset of CSRs explicitly via copies.
virtual bool isSDNodeSourceOfDivergence(const SDNode *N, FunctionLoweringInfo *FLI, UniformityInfo *UA) const
virtual SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps) const
Return a reciprocal estimate value for the input operand.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
virtual bool isSDNodeAlwaysUniform(const SDNode *N) const
virtual bool isDesirableToCommuteXorWithShift(const SDNode *N) const
Return true if it is profitable to combine an XOR of a logical shift to create a logical shift of NOT...
TargetLowering(const TargetLowering &)=delete
virtual bool shouldSimplifyDemandedVectorElts(SDValue Op, const TargetLoweringOpt &TLO) const
Return true if the target supports simplifying demanded vector elements by converting them to undefs.
virtual SDValue LowerFormalArguments(SDValue, CallingConv::ID, bool, const SmallVectorImpl< ISD::InputArg > &, const SDLoc &, SelectionDAG &, SmallVectorImpl< SDValue > &) const
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
virtual AsmOperandInfoVector ParseConstraints(const DataLayout &DL, const TargetRegisterInfo *TRI, const CallBase &Call) const
Split up the constraint string from the inline assembly value into the specific constraints and their...
virtual SDValue getSqrtResultForDenormInput(SDValue Operand, SelectionDAG &DAG) const
Return a target-dependent result if the input operand is not suitable for use with a square root esti...
virtual bool getPostIndexedAddressParts(SDNode *, SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
Returns true by value, base pointer and offset pointer and addressing mode by reference if this node ...
virtual bool shouldSplitFunctionArgumentsAsLittleEndian(const DataLayout &DL) const
For most targets, an LLVM type must be broken down into multiple smaller types.
virtual ArrayRef< MCPhysReg > getRoundingControlRegisters() const
Returns a 0 terminated array of rounding control registers that can be attached into strict FP call.
virtual SDValue LowerReturn(SDValue, CallingConv::ID, bool, const SmallVectorImpl< ISD::OutputArg > &, const SmallVectorImpl< SDValue > &, const SDLoc &, SelectionDAG &) const
This hook must be implemented to lower outgoing return values, described by the Outs array,...
virtual bool functionArgumentNeedsConsecutiveRegisters(Type *Ty, CallingConv::ID CallConv, bool isVarArg, const DataLayout &DL) const
For some targets, an LLVM struct type must be broken down into multiple simple types,...
virtual bool isDesirableToCommuteWithShift(const SDNode *N, CombineLevel Level) const
Return true if it is profitable to move this shift by a constant amount through its operand,...
virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, SDValue Op, SelectionDAG *DAG=nullptr) const
Determines the constraint code and constraint type to use for the specific AsmOperandInfo,...
virtual SDValue visitMaskedStore(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, MachineMemOperand *MMO, SDValue Ptr, SDValue Val, SDValue Mask) const
virtual const MCExpr * LowerCustomJumpTableEntry(const MachineJumpTableInfo *, const MachineBasicBlock *, unsigned, MCContext &) const
virtual bool useLoadStackGuardNode(const Module &M) const
If this function returns true, SelectionDAGBuilder emits a LOAD_STACK_GUARD node when it is lowering ...
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT, ArrayRef< SDValue > Ops, MakeLibCallOptions CallOptions, const SDLoc &dl, SDValue Chain=SDValue()) const
It is an error to pass RTLIB::UNKNOWN_LIBCALL as LC.
virtual FastISel * createFastISel(FunctionLoweringInfo &, const TargetLibraryInfo *, const LibcallLoweringInfo *) const
This method returns a target specific FastISel object, or null if the target does not support "fast" ...
virtual unsigned combineRepeatedFPDivisors() const
Indicate whether this target prefers to combine FDIVs with the same divisor.
virtual AndOrSETCCFoldKind isDesirableToCombineLogicOpOfSETCC(const SDNode *LogicOp, const SDNode *SETCC0, const SDNode *SETCC1) const
virtual void HandleByVal(CCState *, unsigned &, Align) const
Target-specific cleanup for formal ByVal parameters.
virtual const MCPhysReg * getScratchRegisters(CallingConv::ID CC) const
Returns a 0 terminated array of registers that can be safely used as scratch registers.
virtual bool getPreIndexedAddressParts(SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
Returns true by value, base pointer and offset pointer and addressing mode by reference if the node's...
SDValue getVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT, SDValue Index, const SDNodeFlags PtrArithFlags=SDNodeFlags()) const
Get a pointer to vector element Idx located in memory for a vector of type VecVT starting at a base a...
std::pair< SDValue, SDValue > makeLibCall(SelectionDAG &DAG, RTLIB::LibcallImpl LibcallImpl, EVT RetVT, ArrayRef< SDValue > Ops, MakeLibCallOptions CallOptions, const SDLoc &dl, SDValue Chain=SDValue()) const
Returns a pair of (return value, chain).
virtual bool supportSplitCSR(MachineFunction *MF) const
Return true if the target supports that a subset of CSRs for the given machine function is handled ex...
virtual bool isReassocProfitable(MachineRegisterInfo &MRI, Register N0, Register N1) const
virtual bool mayBeEmittedAsTailCall(const CallInst *) const
Return true if the target may be able emit the call instruction as a tail call.
virtual bool isInlineAsmTargetBranch(const SmallVectorImpl< StringRef > &AsmStrs, unsigned OpNo) const
On x86, return true if the operand with index OpNo is a CALL or JUMP instruction, which can use eithe...
SDValue getInboundsVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT, SDValue Index) const
Get a pointer to vector element Idx located in memory for a vector of type VecVT starting at a base a...
virtual MVT getJumpTableRegTy(const DataLayout &DL) const
virtual void markLibCallAttributes(MachineFunction *MF, unsigned CC, ArgListTy &Args) const
virtual bool CanLowerReturn(CallingConv::ID, MachineFunction &, bool, const SmallVectorImpl< ISD::OutputArg > &, LLVMContext &, const Type *RetTy) const
This hook should be implemented to check whether the return values described by the Outs array can fi...
virtual bool isXAndYEqZeroPreferableToXAndYEqY(ISD::CondCode, EVT) const
virtual bool isDesirableToTransformToIntegerOp(unsigned, EVT) const
Return true if it is profitable for dag combiner to transform a floating point op of specified opcode...
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:267
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:184
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
CallInst * Call
#define UINT64_MAX
Definition DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:41
@ PARTIAL_REDUCE_SMLA
PARTIAL_REDUCE_[U|S]MLA(Accumulator, Input1, Input2) The partial reduction nodes sign or zero extend ...
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:275
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition ISDOpcodes.h:394
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:294
@ FMAD
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations.
Definition ISDOpcodes.h:522
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:264
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition ISDOpcodes.h:400
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:852
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:417
@ CLMUL
Carry-less multiplication operations.
Definition ISDOpcodes.h:773
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition ISDOpcodes.h:407
@ PARTIAL_REDUCE_UMLA
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:843
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition ISDOpcodes.h:714
@ PARTIAL_REDUCE_FMLA
@ BRIND
BRIND - Indirect branch.
@ BR_JT
BR_JT - Jumptable branch.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition ISDOpcodes.h:374
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition ISDOpcodes.h:671
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition ISDOpcodes.h:348
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:703
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:764
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:849
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum maximum on two values, following IEEE-754 definition...
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:726
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition ISDOpcodes.h:413
@ STRICT_FP_TO_UINT
Definition ISDOpcodes.h:478
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:477
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:925
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:738
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition ISDOpcodes.h:709
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:304
@ SPLAT_VECTOR_PARTS
SPLAT_VECTOR_PARTS(SCALAR1, SCALAR2, ...) - Returns a vector with the scalar values joined together a...
Definition ISDOpcodes.h:680
@ PARTIAL_REDUCE_SUMLA
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition ISDOpcodes.h:365
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition ISDOpcodes.h:721
static const int LAST_LOADEXT_TYPE
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
This namespace contains all of the command line option processing machinery.
Definition CommandLine.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
GenericUniformityInfo< SSAContext > UniformityInfo
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:532
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1757
LLVM_ABI void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags,...
InstructionCost Cost
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition Alignment.h:134
void * PointerTy
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition bit.h:154
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:337
LLVM_ABI bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Returns true if given the TargetLowering's boolean contents information, the value Val contains a tru...
Definition Utils.cpp:1660
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
AtomicOrdering
Atomic ordering for LLVM's memory model.
LLVM_ABI EVT getApproximateEVTForLLT(LLT Ty, LLVMContext &Ctx)
TargetTransformInfo TTI
CombineLevel
Definition DAGCombine.h:15
@ AfterLegalizeDAG
Definition DAGCombine.h:19
@ AfterLegalizeVectorOps
Definition DAGCombine.h:18
@ BeforeLegalizeTypes
Definition DAGCombine.h:16
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM, bool ReturnsFirstArg=false)
Test if the given instruction is in a position to be optimized with a tail-call.
Definition Analysis.cpp:539
DWARFExpression::Operation Op
LLVM_ABI bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector, bool IsFP)
Definition Utils.cpp:1673
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:1915
static cl::opt< unsigned > CostThreshold("dfa-cost-threshold", cl::desc("Maximum cost accepted for the transformation"), cl::Hidden, cl::init(50))
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
Represent subnormal handling kind for floating point instruction inputs and outputs.
Extended Value Type.
Definition ValueTypes.h:35
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:137
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition ValueTypes.h:74
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition ValueTypes.h:300
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition ValueTypes.h:147
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:373
bool isByteSized() const
Return true if the bit size is a multiple of 8.
Definition ValueTypes.h:243
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:316
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:168
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
Definition ValueTypes.h:142
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
Definition ValueTypes.h:157
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:152
ConstraintInfo()=default
Default constructor.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
bool isDstAligned(Align AlignCheck) const
bool allowOverlap() const
bool isFixedDstAlign() const
uint64_t size() const
static MemOp Set(uint64_t Size, bool DstAlignCanChange, Align DstAlign, bool IsZeroMemset, bool IsVolatile)
Align getDstAlign() const
bool isMemcpyStrSrc() const
bool isAligned(Align AlignCheck) const
static MemOp Copy(uint64_t Size, bool DstAlignCanChange, Align DstAlign, Align SrcAlign, bool IsVolatile, bool MemcpyStrSrc=false)
bool isSrcAligned(Align AlignCheck) const
bool isMemset() const
bool isMemcpy() const
bool isMemcpyWithFixedDstAlign() const
bool isZeroMemset() const
Align getSrcAlign() const
A simple container for information about the supported runtime calls.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.
These are IR-level optimization flags that may be propagated to SDNodes.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
std::optional< unsigned > fallbackAddressSpace
PointerUnion< const Value *, const PseudoSourceValue * > ptrVal
This contains information for each constraint that we are lowering.
AsmOperandInfo(InlineAsm::ConstraintInfo Info)
Copy constructor for copying from a ConstraintInfo.
MVT ConstraintVT
The ValueType for the operand value.
TargetLowering::ConstraintType ConstraintType
Information about the constraint code, e.g.
std::string ConstraintCode
This contains the actual string for the code, like "m".
Value * CallOperandVal
If this is the result output operand or a clobber, this is null, otherwise it is the incoming operand...
This structure contains all information that is necessary for lowering calls.
CallLoweringInfo & setConvergent(bool Value=true)
CallLoweringInfo & setIsPostTypeLegalization(bool Value=true)
CallLoweringInfo & setDeactivationSymbol(GlobalValue *Sym)
CallLoweringInfo & setCallee(Type *ResultType, FunctionType *FTy, SDValue Target, ArgListTy &&ArgsList, const CallBase &Call)
CallLoweringInfo & setCFIType(const ConstantInt *Type)
CallLoweringInfo & setInRegister(bool Value=true)
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList)
SmallVector< ISD::InputArg, 32 > Ins
CallLoweringInfo & setVarArg(bool Value=true)
Type * OrigRetTy
Original unlegalized return type.
std::optional< PtrAuthInfo > PAI
CallLoweringInfo & setDiscardResult(bool Value=true)
CallLoweringInfo & setZExtResult(bool Value=true)
CallLoweringInfo & setIsPatchPoint(bool Value=true)
CallLoweringInfo & setDebugLoc(const SDLoc &dl)
CallLoweringInfo & setLibCallee(CallingConv::ID CC, Type *ResultType, Type *OrigResultType, SDValue Target, ArgListTy &&ArgsList)
CallLoweringInfo & setTailCall(bool Value=true)
CallLoweringInfo & setIsPreallocated(bool Value=true)
CallLoweringInfo & setSExtResult(bool Value=true)
CallLoweringInfo & setNoReturn(bool Value=true)
CallLoweringInfo & setConvergenceControlToken(SDValue Token)
SmallVector< ISD::OutputArg, 32 > Outs
Type * RetTy
Same as OrigRetTy, or partially legalized for soft float libcalls.
CallLoweringInfo & setChain(SDValue InChain)
CallLoweringInfo & setPtrAuth(PtrAuthInfo Value)
CallLoweringInfo & setCallee(CallingConv::ID CC, Type *ResultType, SDValue Target, ArgListTy &&ArgsList, AttributeSet ResultAttrs={})
DAGCombinerInfo(SelectionDAG &dag, CombineLevel level, bool cl, void *dc)
This structure is used to pass arguments to makeLibCall function.
MakeLibCallOptions & setIsPostTypeLegalization(bool Value=true)
MakeLibCallOptions & setDiscardResult(bool Value=true)
MakeLibCallOptions & setTypeListBeforeSoften(ArrayRef< EVT > OpsVT, EVT RetVT)
MakeLibCallOptions & setIsSigned(bool Value=true)
MakeLibCallOptions & setNoReturn(bool Value=true)
MakeLibCallOptions & setOpsTypeOverrides(ArrayRef< Type * > OpsTypes)
Override the argument type for an operand.
This structure contains the information necessary for lowering pointer-authenticating indirect calls.
A convenience struct that encapsulates a DAG, and two SDValues for returning information from TargetL...
TargetLoweringOpt(SelectionDAG &InDAG, bool LT, bool LO)