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