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