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