1//===- ARMISelLowering.h - ARM DAG Lowering Interface -----------*- 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// This file defines the interfaces that ARM uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H
15#define LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H
16
17#include "MCTargetDesc/ARMBaseInfo.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/CodeGen/CallingConvLower.h"
21#include "llvm/CodeGen/ISDOpcodes.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/SelectionDAGNodes.h"
24#include "llvm/CodeGen/TargetLowering.h"
25#include "llvm/CodeGen/ValueTypes.h"
26#include "llvm/CodeGenTypes/MachineValueType.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/CallingConv.h"
29#include "llvm/IR/Function.h"
30#include "llvm/IR/InlineAsm.h"
31#include "llvm/Support/CodeGen.h"
32#include <optional>
33#include <utility>
34
35namespace llvm {
36
37class ARMBaseTargetMachine;
38class ARMSubtarget;
39class DataLayout;
40class FastISel;
41class FunctionLoweringInfo;
42class GlobalValue;
43class InstrItineraryData;
44class Instruction;
45class IRBuilderBase;
46class MachineBasicBlock;
47class MachineInstr;
48class SelectionDAG;
49class TargetLibraryInfo;
50class TargetMachine;
51class TargetRegisterInfo;
52class VectorType;
53
54 namespace ARM {
55 /// Possible values of current rounding mode, which is specified in bits
56 /// 23:22 of FPSCR.
57 enum Rounding {
58 RN = 0, // Round to Nearest
59 RP = 1, // Round towards Plus infinity
60 RM = 2, // Round towards Minus infinity
61 RZ = 3, // Round towards Zero
62 rmMask = 3 // Bit mask selecting rounding mode
63 };
64
65 // Bit position of rounding mode bits in FPSCR.
66 const unsigned RoundingBitsPos = 22;
67
68 // Bits of floating-point status. These are NZCV flags, QC bit and cumulative
69 // FP exception bits.
70 const unsigned FPStatusBits = 0xf800009f;
71
72 // Some bits in the FPSCR are not yet defined. They must be preserved when
73 // modifying the contents.
74 const unsigned FPReservedBits = 0x00006060;
75 } // namespace ARM
76
77 /// Define some predicates that are used for node matching.
78 namespace ARM {
79
80 bool isBitFieldInvertedMask(unsigned v);
81
82 } // end namespace ARM
83
84 //===--------------------------------------------------------------------===//
85 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
86
87 class ARMTargetLowering : public TargetLowering {
88 // Copying needed for an outgoing byval argument.
89 enum ByValCopyKind {
90 // Argument is already in the correct location, no copy needed.
91 NoCopy,
92 // Argument value is currently in the local stack frame, needs copying to
93 // outgoing arguemnt area.
94 CopyOnce,
95 // Argument value is currently in the outgoing argument area, but not at
96 // the correct offset, so needs copying via a temporary in local stack
97 // space.
98 CopyViaTemp,
99 };
100
101 public:
102 explicit ARMTargetLowering(const TargetMachine &TM,
103 const ARMSubtarget &STI);
104
105 const ARMBaseTargetMachine &getTM() const;
106
107 unsigned getJumpTableEncoding() const override;
108 bool useSoftFloat() const override;
109
110 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
111
112 /// ReplaceNodeResults - Replace the results of node with an illegal result
113 /// type with new values built out of custom code.
114 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
115 SelectionDAG &DAG) const override;
116
117 bool isSelectSupported(SelectSupportKind Kind) const override {
118 // ARM does not support scalar condition selects on vectors.
119 return (Kind != ScalarCondVectorVal);
120 }
121
122 bool isReadOnly(const GlobalValue *GV) const;
123
124 /// getSetCCResultType - Return the value type to use for ISD::SETCC.
125 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
126 EVT VT) const override;
127
128 MachineBasicBlock *
129 EmitInstrWithCustomInserter(MachineInstr &MI,
130 MachineBasicBlock *MBB) const override;
131
132 void AdjustInstrPostInstrSelection(MachineInstr &MI,
133 SDNode *Node) const override;
134
135 bool supportKCFIBundles() const override;
136
137 MachineInstr *EmitKCFICheck(MachineBasicBlock &MBB,
138 MachineBasicBlock::instr_iterator &MBBI,
139 const TargetInstrInfo *TII) const override;
140
141 SDValue PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const;
142 SDValue PerformBRCONDCombine(SDNode *N, SelectionDAG &DAG) const;
143 SDValue PerformCMOVToBFICombine(SDNode *N, SelectionDAG &DAG) const;
144 SDValue PerformIntrinsicCombine(SDNode *N, DAGCombinerInfo &DCI) const;
145 SDValue PerformMVEExtCombine(SDNode *N, DAGCombinerInfo &DCI) const;
146 SDValue PerformMVETruncCombine(SDNode *N, DAGCombinerInfo &DCI) const;
147 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
148
149 bool SimplifyDemandedBitsForTargetNode(SDValue Op,
150 const APInt &OriginalDemandedBits,
151 const APInt &OriginalDemandedElts,
152 KnownBits &Known,
153 TargetLoweringOpt &TLO,
154 unsigned Depth) const override;
155
156 bool isDesirableToTransformToIntegerOp(unsigned Opc, EVT VT) const override;
157
158 /// allowsMisalignedMemoryAccesses - Returns true if the target allows
159 /// unaligned memory accesses of the specified type. Returns whether it
160 /// is "fast" by reference in the second argument.
161 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
162 Align Alignment,
163 MachineMemOperand::Flags Flags,
164 unsigned *Fast) const override;
165
166 EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
167 const AttributeList &FuncAttributes) const override;
168
169 bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
170 bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
171 bool isZExtFree(SDValue Val, EVT VT2) const override;
172 Type* shouldConvertSplatType(ShuffleVectorInst* SVI) const override;
173
174 bool isFNegFree(EVT VT) const override;
175
176 bool isVectorLoadExtDesirable(SDValue ExtVal) const override;
177
178 bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override;
179
180
181 /// isLegalAddressingMode - Return true if the addressing mode represented
182 /// by AM is legal for this target, for a load/store of the specified type.
183 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM,
184 Type *Ty, unsigned AS,
185 Instruction *I = nullptr) const override;
186
187 bool isLegalT2ScaledAddressingMode(const AddrMode &AM, EVT VT) const;
188
189 /// Returns true if the addressing mode representing by AM is legal
190 /// for the Thumb1 target, for a load/store of the specified type.
191 bool isLegalT1ScaledAddressingMode(const AddrMode &AM, EVT VT) const;
192
193 /// isLegalICmpImmediate - Return true if the specified immediate is legal
194 /// icmp immediate, that is the target has icmp instructions which can
195 /// compare a register against the immediate without having to materialize
196 /// the immediate into a register.
197 bool isLegalICmpImmediate(int64_t Imm) const override;
198
199 /// isLegalAddImmediate - Return true if the specified immediate is legal
200 /// add immediate, that is the target has add instructions which can
201 /// add a register and the immediate without having to materialize
202 /// the immediate into a register.
203 bool isLegalAddImmediate(int64_t Imm) const override;
204
205 /// getPreIndexedAddressParts - returns true by value, base pointer and
206 /// offset pointer and addressing mode by reference if the node's address
207 /// can be legally represented as pre-indexed load / store address.
208 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
209 ISD::MemIndexedMode &AM,
210 SelectionDAG &DAG) const override;
211
212 /// getPostIndexedAddressParts - returns true by value, base pointer and
213 /// offset pointer and addressing mode by reference if this node can be
214 /// combined with a load / store to form a post-indexed load / store.
215 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
216 SDValue &Offset, ISD::MemIndexedMode &AM,
217 SelectionDAG &DAG) const override;
218
219 void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known,
220 const APInt &DemandedElts,
221 const SelectionDAG &DAG,
222 unsigned Depth) const override;
223
224 bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,
225 const APInt &DemandedElts,
226 TargetLoweringOpt &TLO) const override;
227
228 ConstraintType getConstraintType(StringRef Constraint) const override;
229
230 /// Examine constraint string and operand type and determine a weight value.
231 /// The operand object must already have been set up with the operand type.
232 ConstraintWeight getSingleConstraintMatchWeight(
233 AsmOperandInfo &info, const char *constraint) const override;
234
235 std::pair<unsigned, const TargetRegisterClass *>
236 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
237 StringRef Constraint, MVT VT) const override;
238
239 const char *LowerXConstraint(EVT ConstraintVT) const override;
240
241 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
242 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
243 /// true it means one of the asm constraint of the inline asm instruction
244 /// being processed is 'm'.
245 void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,
246 std::vector<SDValue> &Ops,
247 SelectionDAG &DAG) const override;
248
249 InlineAsm::ConstraintCode
250 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
251 if (ConstraintCode == "Q")
252 return InlineAsm::ConstraintCode::Q;
253 if (ConstraintCode.size() == 2) {
254 if (ConstraintCode[0] == 'U') {
255 switch(ConstraintCode[1]) {
256 default:
257 break;
258 case 'm':
259 return InlineAsm::ConstraintCode::Um;
260 case 'n':
261 return InlineAsm::ConstraintCode::Un;
262 case 'q':
263 return InlineAsm::ConstraintCode::Uq;
264 case 's':
265 return InlineAsm::ConstraintCode::Us;
266 case 't':
267 return InlineAsm::ConstraintCode::Ut;
268 case 'v':
269 return InlineAsm::ConstraintCode::Uv;
270 case 'y':
271 return InlineAsm::ConstraintCode::Uy;
272 }
273 }
274 }
275 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
276 }
277
278 const ARMSubtarget* getSubtarget() const {
279 return Subtarget;
280 }
281
282 /// getRegClassFor - Return the register class that should be used for the
283 /// specified value type.
284 const TargetRegisterClass *
285 getRegClassFor(MVT VT, bool isDivergent = false) const override;
286
287 bool shouldAlignPointerArgs(CallInst *CI, unsigned &MinSize,
288 Align &PrefAlign) const override;
289
290 /// createFastISel - This method returns a target specific FastISel object,
291 /// or null if the target does not support "fast" ISel.
292 FastISel *
293 createFastISel(FunctionLoweringInfo &funcInfo,
294 const TargetLibraryInfo *libInfo,
295 const LibcallLoweringInfo *libcallLowering) const override;
296
297 Sched::Preference getSchedulingPreference(SDNode *N) const override;
298
299 bool preferZeroCompareBranch() const override { return true; }
300
301 bool preferSelectsOverBooleanArithmetic(EVT VT) const override;
302
303 bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
304
305 bool hasAndNotCompare(SDValue V) const override {
306 // We can use bics for any scalar.
307 return V.getValueType().isScalarInteger();
308 }
309
310 bool hasAndNot(SDValue Y) const override;
311
312 bool
313 isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const override;
314 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
315
316 /// Returns how to materialize the specified FP immediate.
317 FPImmAction getFPImmAction(const APFloat &Imm, EVT VT,
318 bool ForCodeSize = false) const override;
319 FPImmAction getFPImmAction(const APFloat &Imm, LLT Ty,
320 bool ForCodeSize = false) const override;
321
322 void getTgtMemIntrinsic(SmallVectorImpl<IntrinsicInfo> &Infos,
323 const CallBase &I, MachineFunction &MF,
324 unsigned Intrinsic) const override;
325
326 /// Returns true if it is beneficial to convert a load of a constant
327 /// to just the constant itself.
328 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
329 Type *Ty) const override;
330
331 /// Return the cost of EXTRACT_SUBVECTOR for this result type with this
332 /// index.
333 ExtractSubvectorCost getExtractSubvectorCost(EVT ResVT, EVT SrcVT,
334 unsigned Index) const override;
335
336 bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
337 bool MathUsed) const override {
338 // Using overflow ops for overflow checks only should beneficial on ARM.
339 return TargetLowering::shouldFormOverflowOp(Opcode, VT, MathUsed: true);
340 }
341
342 bool shouldReassociateReduction(unsigned Opc, EVT VT) const override {
343 return Opc != ISD::VECREDUCE_ADD;
344 }
345
346 /// Returns true if an argument of type Ty needs to be passed in a
347 /// contiguous block of registers in calling convention CallConv.
348 bool functionArgumentNeedsConsecutiveRegisters(
349 Type *Ty, CallingConv::ID CallConv, bool isVarArg,
350 const DataLayout &DL) const override;
351
352 /// If a physical register, this returns the register that receives the
353 /// exception address on entry to an EH pad.
354 Register
355 getExceptionPointerRegister(ExceptionHandling EH,
356 const Constant *PersonalityFn) const override;
357
358 /// If a physical register, this returns the register that receives the
359 /// exception typeid on entry to a landing pad.
360 Register
361 getExceptionSelectorRegister(ExceptionHandling EH,
362 const Constant *PersonalityFn) const override;
363
364 Instruction *makeDMB(IRBuilderBase &Builder, ARM_MB::MemBOpt Domain) const;
365 Value *emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr,
366 AtomicOrdering Ord) const override;
367 Value *emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr,
368 AtomicOrdering Ord) const override;
369
370 void
371 emitAtomicCmpXchgNoStoreLLBalance(IRBuilderBase &Builder) const override;
372
373 Instruction *emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst,
374 AtomicOrdering Ord) const override;
375 Instruction *emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst,
376 AtomicOrdering Ord) const override;
377
378 unsigned getMaxSupportedInterleaveFactor() const override;
379
380 bool lowerInterleavedLoad(Instruction *Load, Value *Mask,
381 ArrayRef<ShuffleVectorInst *> Shuffles,
382 ArrayRef<unsigned> Indices, unsigned Factor,
383 const APInt &GapMask) const override;
384 bool lowerInterleavedStore(Instruction *Store, Value *Mask,
385 ShuffleVectorInst *SVI, unsigned Factor,
386 const APInt &GapMask) const override;
387
388 bool shouldInsertFencesForAtomic(const Instruction *I) const override;
389 TargetLoweringBase::AtomicExpansionKind
390 shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
391 TargetLoweringBase::AtomicExpansionKind
392 shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
393 TargetLoweringBase::AtomicExpansionKind
394 shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override;
395 TargetLoweringBase::AtomicExpansionKind
396 shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const override;
397
398 bool useLoadStackGuardNode(const Module &M) const override;
399
400 Value *getIRStackGuard(IRBuilderBase &IRB,
401 const LibcallLoweringInfo &Libcalls) const override;
402
403 void
404 insertSSPDeclarations(Module &M,
405 const LibcallLoweringInfo &Libcalls) const override;
406
407 bool canCombineStoreAndExtract(Type *VectorTy, Value *Idx,
408 unsigned &Cost) const override;
409
410 bool canCreateUndefOrPoisonForTargetNode(SDValue Op,
411 const APInt &DemandedElts,
412 const SelectionDAG &DAG,
413 UndefPoisonKind Kind,
414 bool ConsiderFlags,
415 unsigned Depth) const override;
416
417 bool canMergeStoresTo(unsigned AddressSpace, EVT MemVT,
418 const MachineFunction &MF) const override {
419 // Do not merge to larger than i32.
420 return (MemVT.getSizeInBits() <= 32);
421 }
422
423 bool isCheapToSpeculateCttz(Type *Ty) const override;
424 bool isCheapToSpeculateCtlz(Type *Ty) const override;
425
426 bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
427 return VT.isScalarInteger();
428 }
429
430 bool supportSwiftError() const override {
431 return true;
432 }
433
434 bool supportSplitCSR(MachineFunction *MF) const override {
435 return MF->getFunction().getCallingConv() == CallingConv::CXX_FAST_TLS &&
436 MF->getFunction().hasFnAttribute(Kind: Attribute::NoUnwind);
437 }
438
439 bool hasStandaloneRem(EVT VT) const override {
440 return HasStandaloneRem;
441 }
442
443 ShiftLegalizationStrategy
444 preferredShiftLegalizationStrategy(SelectionDAG &DAG, SDNode *N,
445 unsigned ExpansionFactor) const override;
446
447 CallingConv::ID getEffectiveCallingConv(CallingConv::ID CC,
448 bool isVarArg) const;
449 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool isVarArg) const;
450 CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool isVarArg) const;
451
452 /// Returns true if \p VecTy is a legal interleaved access type. This
453 /// function checks the vector element type and the overall width of the
454 /// vector.
455 bool isLegalInterleavedAccessType(unsigned Factor, FixedVectorType *VecTy,
456 Align Alignment,
457 const DataLayout &DL) const;
458
459 bool isMulAddWithConstProfitable(SDValue AddNode,
460 SDValue ConstNode) const override;
461
462 bool alignLoopsWithOptSize() const override;
463
464 /// Returns the number of interleaved accesses that will be generated when
465 /// lowering accesses of the given type.
466 unsigned getNumInterleavedAccesses(VectorType *VecTy,
467 const DataLayout &DL) const;
468
469 void finalizeLowering(MachineFunction &MF) const override;
470
471 /// Return the correct alignment for the current calling convention.
472 Align getABIAlignmentForCallingConv(Type *ArgTy,
473 const DataLayout &DL) const override;
474
475 bool isDesirableToCommuteWithShift(const SDNode *N,
476 CombineLevel Level) const override;
477
478 bool isDesirableToCommuteXorWithShift(const SDNode *N) const override;
479
480 bool shouldFoldConstantShiftPairToMask(const SDNode *N) const override;
481
482 /// Return true if it is profitable to fold a pair of shifts into a mask.
483 bool shouldFoldMaskToVariableShiftPair(SDValue Y) const override {
484 EVT VT = Y.getValueType();
485
486 if (VT.isVector())
487 return false;
488
489 return VT.getScalarSizeInBits() <= 32;
490 }
491
492 bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode, EVT VT,
493 unsigned SelectOpcode, SDValue X,
494 SDValue Y) const override;
495
496 bool preferIncOfAddToSubOfNot(EVT VT) const override;
497
498 bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const override;
499
500 bool isComplexDeinterleavingSupported() const override;
501 bool isComplexDeinterleavingOperationSupported(
502 ComplexDeinterleavingOperation Operation, Type *Ty) const override;
503
504 Value *createComplexDeinterleavingIR(
505 IRBuilderBase &B, ComplexDeinterleavingOperation OperationType,
506 ComplexDeinterleavingRotation Rotation, Value *InputA, Value *InputB,
507 Value *Accumulator = nullptr) const override;
508
509 bool useFPRegsForHalfType() const override { return true; }
510
511 protected:
512 std::pair<const TargetRegisterClass *, uint8_t>
513 findRepresentativeClass(const TargetRegisterInfo *TRI,
514 MVT VT) const override;
515
516 private:
517 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
518 /// make the right decision when generating code for different targets.
519 const ARMSubtarget *Subtarget;
520
521 const TargetRegisterInfo *RegInfo;
522
523 const InstrItineraryData *Itins;
524
525 // TODO: remove this, and have shouldInsertFencesForAtomic do the proper
526 // check.
527 bool InsertFencesForAtomic;
528
529 bool HasStandaloneRem = true;
530
531 void addTypeForNEON(MVT VT, MVT PromotedLdStVT);
532 void addDRTypeForNEON(MVT VT);
533 void addQRTypeForNEON(MVT VT);
534 std::pair<SDValue, SDValue> getARMXALUOOp(SDValue Op, SelectionDAG &DAG, SDValue &ARMcc) const;
535
536 using RegsToPassVector = SmallVector<std::pair<unsigned, SDValue>, 8>;
537
538 void PassF64ArgInRegs(const SDLoc &dl, SelectionDAG &DAG, SDValue Chain,
539 SDValue &Arg, RegsToPassVector &RegsToPass,
540 CCValAssign &VA, CCValAssign &NextVA,
541 SDValue &StackPtr,
542 SmallVectorImpl<SDValue> &MemOpChains,
543 bool IsTailCall,
544 int SPDiff) const;
545 SDValue GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA,
546 SDValue &Root, SelectionDAG &DAG,
547 const SDLoc &dl) const;
548
549 CCAssignFn *CCAssignFnForNode(CallingConv::ID CC, bool Return,
550 bool isVarArg) const;
551 std::pair<SDValue, MachinePointerInfo>
552 computeAddrForCallArg(const SDLoc &dl, SelectionDAG &DAG,
553 const CCValAssign &VA, SDValue StackPtr,
554 bool IsTailCall, int SPDiff) const;
555 ByValCopyKind ByValNeedsCopyForTailCall(SelectionDAG &DAG, SDValue Src,
556 SDValue Dst,
557 ISD::ArgFlagsTy Flags) const;
558 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
559 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
560 SDValue LowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const;
561 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG,
562 const ARMSubtarget *Subtarget) const;
563 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG,
564 const ARMSubtarget *Subtarget) const;
565 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
566 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
567 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
568 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG) const;
569 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
570 SDValue LowerGlobalAddressWindows(SDValue Op, SelectionDAG &DAG) const;
571 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
572 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
573 SelectionDAG &DAG) const;
574 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
575 SelectionDAG &DAG,
576 TLSModel::Model model) const;
577 SDValue LowerGlobalTLSAddressDarwin(SDValue Op, SelectionDAG &DAG) const;
578 SDValue LowerGlobalTLSAddressWindows(SDValue Op, SelectionDAG &DAG) const;
579 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
580 SDValue LowerALUO(SDValue Op, SelectionDAG &DAG) const;
581 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
582 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
583 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
584 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
585 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
586 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
587 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
588 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
589 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
590 SDValue LowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
591 SDValue LowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
592 SDValue LowerSET_FPMODE(SDValue Op, SelectionDAG &DAG) const;
593 SDValue LowerRESET_FPMODE(SDValue Op, SelectionDAG &DAG) const;
594 SDValue LowerConstantFP(SDValue Op, SelectionDAG &DAG,
595 const ARMSubtarget *ST) const;
596 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
597 const ARMSubtarget *ST) const;
598 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
599 SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;
600 SDValue LowerDIV_Windows(SDValue Op, SelectionDAG &DAG, bool Signed) const;
601 void ExpandDIV_Windows(SDValue Op, SelectionDAG &DAG, bool Signed,
602 SmallVectorImpl<SDValue> &Results) const;
603 SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG,
604 const ARMSubtarget *Subtarget) const;
605 SDValue LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG, bool Signed,
606 SDValue &Chain) const;
607 SDValue LowerREM(SDNode *N, SelectionDAG &DAG) const;
608 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
609 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
610 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
611 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
612 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
613 SDValue LowerFSETCC(SDValue Op, SelectionDAG &DAG) const;
614 SDValue LowerSPONENTRY(SDValue Op, SelectionDAG &DAG) const;
615 void LowerLOAD(SDNode *N, SmallVectorImpl<SDValue> &Results,
616 SelectionDAG &DAG) const;
617 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG,
618 const ARMSubtarget *Subtarget) const;
619 std::pair<SDValue, SDValue>
620 LowerAEABIUnalignedLoad(SDValue Op, SelectionDAG &DAG) const;
621 SDValue LowerAEABIUnalignedStore(SDValue Op, SelectionDAG &DAG) const;
622 SDValue LowerFP_TO_BF16(SDValue Op, SelectionDAG &DAG) const;
623 SDValue LowerCMP(SDValue Op, SelectionDAG &DAG) const;
624 SDValue LowerABS(SDValue Op, SelectionDAG &DAG) const;
625 Register getRegisterByName(const char* RegName, LLT VT,
626 const MachineFunction &MF) const override;
627
628 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
629 SmallVectorImpl<SDNode *> &Created) const override;
630
631 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
632 EVT VT) const override;
633
634 SDValue MoveToHPR(const SDLoc &dl, SelectionDAG &DAG, MVT LocVT, MVT ValVT,
635 SDValue Val) const;
636 SDValue MoveFromHPR(const SDLoc &dl, SelectionDAG &DAG, MVT LocVT,
637 MVT ValVT, SDValue Val) const;
638
639 SDValue ReconstructShuffle(SDValue Op, SelectionDAG &DAG) const;
640
641 SDValue LowerCallResult(SDValue Chain, SDValue InGlue,
642 CallingConv::ID CallConv, bool isVarArg,
643 const SmallVectorImpl<ISD::InputArg> &Ins,
644 const SDLoc &dl, SelectionDAG &DAG,
645 SmallVectorImpl<SDValue> &InVals, bool isThisReturn,
646 SDValue ThisVal, bool isCmseNSCall) const;
647
648 void initializeSplitCSR(MachineBasicBlock *Entry) const override;
649 void insertCopiesSplitCSR(
650 MachineBasicBlock *Entry,
651 const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;
652
653 bool splitValueIntoRegisterParts(
654 SelectionDAG & DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
655 unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC)
656 const override;
657
658 SDValue joinRegisterPartsIntoValue(
659 SelectionDAG & DAG, const SDLoc &DL, const SDValue *Parts,
660 unsigned NumParts, MVT PartVT, EVT ValueVT,
661 std::optional<CallingConv::ID> CC) const override;
662
663 SDValue
664 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
665 const SmallVectorImpl<ISD::InputArg> &Ins,
666 const SDLoc &dl, SelectionDAG &DAG,
667 SmallVectorImpl<SDValue> &InVals) const override;
668
669 int StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, const SDLoc &dl,
670 SDValue &Chain, const Value *OrigArg,
671 unsigned InRegsParamRecordIdx, int ArgOffset,
672 unsigned ArgSize) const;
673
674 void VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG,
675 const SDLoc &dl, SDValue &Chain,
676 unsigned ArgOffset, unsigned TotalArgRegsSaveSize,
677 bool ForceMutable = false) const;
678
679 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
680 SmallVectorImpl<SDValue> &InVals) const override;
681
682 /// HandleByVal - Target-specific cleanup for ByVal support.
683 void HandleByVal(CCState *, unsigned &, Align) const override;
684
685 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
686 /// for tail call optimization. Targets which want to do tail call
687 /// optimization should implement this function.
688 bool IsEligibleForTailCallOptimization(
689 TargetLowering::CallLoweringInfo &CLI, CCState &CCInfo,
690 SmallVectorImpl<CCValAssign> &ArgLocs, const bool isIndirect) const;
691
692 bool CanLowerReturn(CallingConv::ID CallConv,
693 MachineFunction &MF, bool isVarArg,
694 const SmallVectorImpl<ISD::OutputArg> &Outs,
695 LLVMContext &Context, const Type *RetTy) const override;
696
697 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
698 const SmallVectorImpl<ISD::OutputArg> &Outs,
699 const SmallVectorImpl<SDValue> &OutVals,
700 const SDLoc &dl, SelectionDAG &DAG) const override;
701
702 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
703
704 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
705
706 bool shouldConsiderGEPOffsetSplit() const override { return true; }
707
708 bool isUnsupportedFloatingType(EVT VT) const;
709
710 ArrayRef<MCPhysReg> getRoundingControlRegisters() const override;
711
712 SDValue getCMOV(const SDLoc &dl, EVT VT, SDValue FalseVal, SDValue TrueVal,
713 SDValue ARMcc, SDValue Flags, SelectionDAG &DAG) const;
714 SDValue getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
715 SDValue &ARMcc, SelectionDAG &DAG, const SDLoc &dl) const;
716 SDValue getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG,
717 const SDLoc &dl, bool Signaling = false) const;
718
719 SDValue OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const;
720
721 void SetupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB,
722 MachineBasicBlock *DispatchBB, int FI) const;
723
724 void EmitSjLjDispatchBlock(MachineInstr &MI, MachineBasicBlock *MBB) const;
725
726 MachineBasicBlock *EmitStructByval(MachineInstr &MI,
727 MachineBasicBlock *MBB) const;
728
729 MachineBasicBlock *EmitLowered__chkstk(MachineInstr &MI,
730 MachineBasicBlock *MBB) const;
731 MachineBasicBlock *EmitLowered__dbzchk(MachineInstr &MI,
732 MachineBasicBlock *MBB) const;
733 void addMVEVectorTypes(bool HasMVEFP);
734 void addAllExtLoads(const MVT From, const MVT To, LegalizeAction Action);
735 void setAllExpand(MVT VT);
736 };
737
738 enum VMOVModImmType {
739 VMOVModImm,
740 VMVNModImm,
741 MVEVMVNModImm,
742 OtherModImm
743 };
744
745 namespace ARM {
746
747 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
748 const TargetLibraryInfo *libInfo,
749 const LibcallLoweringInfo *libcallLowering);
750
751 } // end namespace ARM
752
753} // end namespace llvm
754
755#endif // LLVM_LIB_TARGET_ARM_ARMISELLOWERING_H
756