1 //==-- AArch64ISelLowering.h - AArch64 DAG Lowering Interface ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interfaces that AArch64 uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64ISELLOWERING_H
16 #define LLVM_LIB_TARGET_AARCH64_AARCH64ISELLOWERING_H
18 #include "llvm/CodeGen/CallingConvLower.h"
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "llvm/IR/CallingConv.h"
21 #include "llvm/IR/Instruction.h"
22 #include "llvm/Target/TargetLowering.h"
26 namespace AArch64ISD {
29 FIRST_NUMBER = ISD::BUILTIN_OP_END,
30 WrapperLarge, // 4-instruction MOVZ/MOVK sequence for 64-bit addresses.
31 CALL, // Function call.
33 // Almost the same as a normal call node, except that a TLSDesc relocation is
34 // needed so the linker can relax it correctly if possible.
36 ADRP, // Page address of a TargetGlobalAddress operand.
37 ADDlow, // Add the low 12 bits of a TargetGlobalAddress operand.
38 LOADgot, // Load from automatically generated descriptor (e.g. Global
39 // Offset Table, TLS record).
40 RET_FLAG, // Return with a flag operand. Operand 0 is the chain operand.
41 BRCOND, // Conditional branch instruction; "b.cond".
43 FCSEL, // Conditional move instruction.
44 CSINV, // Conditional select invert.
45 CSNEG, // Conditional select negate.
46 CSINC, // Conditional select increment.
48 // Pointer to the thread's local storage area. Materialised from TPIDR_EL0 on
52 SBC, // adc, sbc instructions
54 // Arithmetic instructions which write flags.
61 // Floating point comparison
64 // Floating point max and min instructions.
71 // Scalar-to-vector duplication
78 // Vector immedate moves
87 // Vector immediate ops
91 // Vector bit select: similar to ISD::VSELECT but not all bits within an
92 // element must be identical.
95 // Vector arithmetic negation
110 // Vector shift by scalar
115 // Vector shift by scalar (again)
122 // Vector comparisons
132 // Vector zero comparisons
144 // Vector bitwise negation
147 // Vector bitwise selection
150 // Compare-and-branch
159 // Custom prefetch handling
162 // {s|u}int to FP within a FP register.
166 /// Natural vector cast. ISD::BITCAST is not natural in the big-endian
167 /// world w.r.t vectors; which causes additional REV instructions to be
168 /// generated to compensate for the byte-swapping. But sometimes we do
169 /// need to re-interpret the data in SIMD vector registers in big-endian
170 /// mode without emitting such REV instructions.
176 // NEON Load/Store with post-increment base updates
177 LD2post = ISD::FIRST_TARGET_MEMORY_OPCODE,
202 } // end namespace AArch64ISD
204 class AArch64Subtarget;
205 class AArch64TargetMachine;
207 class AArch64TargetLowering : public TargetLowering {
208 bool RequireStrictAlign;
211 explicit AArch64TargetLowering(const TargetMachine &TM,
212 const AArch64Subtarget &STI);
214 /// Selects the correct CCAssignFn for a given CallingConvention value.
215 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const;
217 /// computeKnownBitsForTargetNode - Determine which of the bits specified in
218 /// Mask are known to be either zero or one and return them in the
219 /// KnownZero/KnownOne bitsets.
220 void computeKnownBitsForTargetNode(const SDValue Op, APInt &KnownZero,
221 APInt &KnownOne, const SelectionDAG &DAG,
222 unsigned Depth = 0) const override;
224 MVT getScalarShiftAmountTy(EVT LHSTy) const override;
226 /// allowsMisalignedMemoryAccesses - Returns true if the target allows
227 /// unaligned memory accesses of the specified type.
228 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace = 0,
230 bool *Fast = nullptr) const override {
231 if (RequireStrictAlign)
233 // FIXME: True for Cyclone, but not necessary others.
239 /// LowerOperation - Provide custom lowering hooks for some operations.
240 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
242 const char *getTargetNodeName(unsigned Opcode) const override;
244 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
246 /// getFunctionAlignment - Return the Log2 alignment of this function.
247 unsigned getFunctionAlignment(const Function *F) const;
249 /// getMaximalGlobalOffset - Returns the maximal possible offset which can
250 /// be used for loads / stores from the global.
251 unsigned getMaximalGlobalOffset() const override;
253 /// Returns true if a cast between SrcAS and DestAS is a noop.
254 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
255 // Addrspacecasts are always noops.
259 /// createFastISel - This method returns a target specific FastISel object,
260 /// or null if the target does not support "fast" ISel.
261 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
262 const TargetLibraryInfo *libInfo) const override;
264 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
266 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
268 /// isShuffleMaskLegal - Return true if the given shuffle mask can be
269 /// codegen'd directly, or if it should be stack expanded.
270 bool isShuffleMaskLegal(const SmallVectorImpl<int> &M, EVT VT) const override;
272 /// getSetCCResultType - Return the ISD::SETCC ValueType
273 EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
275 SDValue ReconstructShuffle(SDValue Op, SelectionDAG &DAG) const;
277 MachineBasicBlock *EmitF128CSEL(MachineInstr *MI,
278 MachineBasicBlock *BB) const;
281 EmitInstrWithCustomInserter(MachineInstr *MI,
282 MachineBasicBlock *MBB) const override;
284 bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
285 unsigned Intrinsic) const override;
287 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
288 bool isTruncateFree(EVT VT1, EVT VT2) const override;
290 bool isProfitableToHoist(Instruction *I) const override;
292 bool isZExtFree(Type *Ty1, Type *Ty2) const override;
293 bool isZExtFree(EVT VT1, EVT VT2) const override;
294 bool isZExtFree(SDValue Val, EVT VT2) const override;
296 bool hasPairedLoad(Type *LoadedType,
297 unsigned &RequiredAligment) const override;
298 bool hasPairedLoad(EVT LoadedType, unsigned &RequiredAligment) const override;
300 bool isLegalAddImmediate(int64_t) const override;
301 bool isLegalICmpImmediate(int64_t) const override;
303 EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
304 bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
305 MachineFunction &MF) const override;
307 /// isLegalAddressingMode - Return true if the addressing mode represented
308 /// by AM is legal for this target, for a load/store of the specified type.
309 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
311 /// \brief Return the cost of the scaling factor used in the addressing
312 /// mode represented by AM for this target, for a load/store
313 /// of the specified type.
314 /// If the AM is supported, the return value must be >= 0.
315 /// If the AM is not supported, it returns a negative value.
316 int getScalingFactorCost(const AddrMode &AM, Type *Ty) const override;
318 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
319 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
320 /// expanded to FMAs when this method returns true, otherwise fmuladd is
321 /// expanded to fmul + fadd.
322 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
324 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
326 /// \brief Returns false if N is a bit extraction pattern of (X >> C) & Mask.
327 bool isDesirableToCommuteWithShift(const SDNode *N) const override;
329 /// \brief Returns true if it is beneficial to convert a load of a constant
330 /// to just the constant itself.
331 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
332 Type *Ty) const override;
334 bool hasLoadLinkedStoreConditional() const override;
335 Value *emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
336 AtomicOrdering Ord) const override;
337 Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
338 Value *Addr, AtomicOrdering Ord) const override;
340 bool shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
341 bool shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
342 bool shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
344 bool useLoadStackGuardNode() const override;
345 TargetLoweringBase::LegalizeTypeAction
346 getPreferredVectorAction(EVT VT) const override;
349 /// Subtarget - Keep a pointer to the AArch64Subtarget around so that we can
350 /// make the right decision when generating code for different targets.
351 const AArch64Subtarget *Subtarget;
353 void addTypeForNEON(EVT VT, EVT PromotedBitwiseVT);
354 void addDRTypeForNEON(MVT VT);
355 void addQRTypeForNEON(MVT VT);
358 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
359 const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc DL,
361 SmallVectorImpl<SDValue> &InVals) const override;
363 SDValue LowerCall(CallLoweringInfo & /*CLI*/,
364 SmallVectorImpl<SDValue> &InVals) const override;
366 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
367 CallingConv::ID CallConv, bool isVarArg,
368 const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc DL,
369 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals,
370 bool isThisReturn, SDValue ThisVal) const;
372 bool isEligibleForTailCallOptimization(
373 SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg,
374 bool isCalleeStructRet, bool isCallerStructRet,
375 const SmallVectorImpl<ISD::OutputArg> &Outs,
376 const SmallVectorImpl<SDValue> &OutVals,
377 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
379 /// Finds the incoming stack arguments which overlap the given fixed stack
380 /// object and incorporates their load into the current chain. This prevents
381 /// an upcoming store from clobbering the stack argument before it's used.
382 SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
383 MachineFrameInfo *MFI, int ClobberedFI) const;
385 bool DoesCalleeRestoreStack(CallingConv::ID CallCC, bool TailCallOpt) const;
387 bool IsTailCallConvention(CallingConv::ID CallCC) const;
389 void saveVarArgRegisters(CCState &CCInfo, SelectionDAG &DAG, SDLoc DL,
390 SDValue &Chain) const;
392 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
394 const SmallVectorImpl<ISD::OutputArg> &Outs,
395 LLVMContext &Context) const override;
397 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
398 const SmallVectorImpl<ISD::OutputArg> &Outs,
399 const SmallVectorImpl<SDValue> &OutVals, SDLoc DL,
400 SelectionDAG &DAG) const override;
402 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
403 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
404 SDValue LowerDarwinGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
405 SDValue LowerELFGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
406 SDValue LowerELFTLSDescCall(SDValue SymAddr, SDValue DescAddr, SDLoc DL,
407 SelectionDAG &DAG) const;
408 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
409 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
410 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
411 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
412 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
413 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
414 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
415 SDValue LowerAAPCS_VASTART(SDValue Op, SelectionDAG &DAG) const;
416 SDValue LowerDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;
417 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
418 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
419 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
420 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
421 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
422 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
423 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
424 SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
425 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
426 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
427 SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
428 SDValue LowerVectorSRA_SRL_SHL(SDValue Op, SelectionDAG &DAG) const;
429 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
430 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
431 SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) const;
432 SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) const;
433 SDValue LowerF128Call(SDValue Op, SelectionDAG &DAG,
434 RTLIB::Libcall Call) const;
435 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
436 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
437 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
438 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
439 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
440 SDValue LowerVectorAND(SDValue Op, SelectionDAG &DAG) const;
441 SDValue LowerVectorOR(SDValue Op, SelectionDAG &DAG) const;
442 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
443 SDValue LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const;
445 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
446 std::vector<SDNode *> *Created) const override;
447 bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
450 getConstraintType(const std::string &Constraint) const override;
451 unsigned getRegisterByName(const char* RegName, EVT VT) const override;
453 /// Examine constraint string and operand type and determine a weight value.
454 /// The operand object must already have been set up with the operand type.
456 getSingleConstraintMatchWeight(AsmOperandInfo &info,
457 const char *constraint) const override;
459 std::pair<unsigned, const TargetRegisterClass *>
460 getRegForInlineAsmConstraint(const std::string &Constraint,
461 MVT VT) const override;
462 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
463 std::vector<SDValue> &Ops,
464 SelectionDAG &DAG) const override;
466 bool isUsedByReturnOnly(SDNode *N, SDValue &Chain) const override;
467 bool mayBeEmittedAsTailCall(CallInst *CI) const override;
468 bool getIndexedAddressParts(SDNode *Op, SDValue &Base, SDValue &Offset,
469 ISD::MemIndexedMode &AM, bool &IsInc,
470 SelectionDAG &DAG) const;
471 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
472 ISD::MemIndexedMode &AM,
473 SelectionDAG &DAG) const override;
474 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
475 SDValue &Offset, ISD::MemIndexedMode &AM,
476 SelectionDAG &DAG) const override;
478 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
479 SelectionDAG &DAG) const override;
481 bool functionArgumentNeedsConsecutiveRegisters(Type *Ty,
482 CallingConv::ID CallConv,
483 bool isVarArg) const override;
487 FastISel *createFastISel(FunctionLoweringInfo &funcInfo,
488 const TargetLibraryInfo *libInfo);
489 } // end namespace AArch64
491 } // end namespace llvm