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_TARGET_AARCH64_ISELLOWERING_H
16 #define LLVM_TARGET_AARCH64_ISELLOWERING_H
18 #include "Utils/AArch64BaseInfo.h"
19 #include "llvm/CodeGen/CallingConvLower.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/Target/TargetLowering.h"
22 #include "llvm/IR/Intrinsics.h"
25 namespace AArch64ISD {
27 // Start the numbering from where ISD NodeType finishes.
28 FIRST_NUMBER = ISD::BUILTIN_OP_END,
30 // This is a conditional branch which also notes the flag needed
31 // (eq/sgt/...). A64 puts this information on the branches rather than
32 // compares as LLVM does.
35 // A node to be selected to an actual call operation: either BL or BLR in
36 // the absence of tail calls.
39 // Indicates a floating-point immediate which fits into the format required
40 // by the FMOV instructions. First (and only) operand is the 8-bit encoded
41 // value of that immediate.
44 // Corresponds directly to an EXTR instruction. Operands are an LHS an RHS
48 // Wraps a load from the GOT, which should always be performed with a 64-bit
49 // load instruction. This prevents the DAG combiner folding a truncate to
50 // form a smaller memory access.
53 // Performs a bitfield insert. Arguments are: the value being inserted into;
54 // the value being inserted; least significant bit changed; width of the
58 // Simply a convenient node inserted during ISelLowering to represent
59 // procedure return. Will almost certainly be selected to "RET".
62 /// Extracts a field of contiguous bits from the source and sign extends
63 /// them into a single register. Arguments are: source; immr; imms. Note
64 /// these are pre-encoded since DAG matching can't cope with combining LSB
65 /// and Width into these values itself.
68 /// This is an A64-ification of the standard LLVM SELECT_CC operation. The
69 /// main difference is that it only has the values and an A64 condition,
70 /// which will be produced by a setcc instruction.
73 /// This serves most of the functions of the LLVM SETCC instruction, for two
74 /// purposes. First, it prevents optimisations from fiddling with the
75 /// compare after we've moved the CondCode information onto the SELECT_CC or
76 /// BR_CC instructions. Second, it gives a legal instruction for the actual
79 /// It keeps a record of the condition flags asked for because certain
80 /// instructions are only valid for a subset of condition codes.
83 // Designates a node which is a tail call: both a call and a return
84 // instruction as far as selction is concerned. It should be selected to an
85 // unconditional branch. Has the usual plethora of call operands, but: 1st
86 // is callee, 2nd is stack adjustment required immediately before branch.
89 // Designates a call used to support the TLS descriptor ABI. The call itself
90 // will be indirect ("BLR xN") but a relocation-specifier (".tlsdesccall
91 // var") must be attached somehow during code generation. It takes two
92 // operands: the callee and the symbol to be relocated against.
95 // Leaf node which will be lowered to an appropriate MRS to obtain the
96 // thread pointer: TPIDR_EL0.
99 /// Extracts a field of contiguous bits from the source and zero extends
100 /// them into a single register. Arguments are: source; immr; imms. Note
101 /// these are pre-encoded since DAG matching can't cope with combining LSB
102 /// and Width into these values itself.
105 // Wraps an address which the ISelLowering phase has decided should be
106 // created using the large memory model style: i.e. a sequence of four
107 // movz/movk instructions.
110 // Wraps an address which the ISelLowering phase has decided should be
111 // created using the small memory model style: i.e. adrp/add or
112 // adrp/mem-op. This exists to prevent bare TargetAddresses which may never
116 // Vector bitwise select
119 // Vector move immediate
122 // Vector Move Inverted Immediate
125 // Vector FP move immediate
131 // Vector compare zero
134 // Vector compare bitwise test
137 // Vector saturating shift
144 // Vector dup by lane
150 class AArch64Subtarget;
151 class AArch64TargetMachine;
153 class AArch64TargetLowering : public TargetLowering {
155 explicit AArch64TargetLowering(AArch64TargetMachine &TM);
157 const char *getTargetNodeName(unsigned Opcode) const;
159 CCAssignFn *CCAssignFnForNode(CallingConv::ID CC) const;
161 SDValue LowerFormalArguments(SDValue Chain,
162 CallingConv::ID CallConv, bool isVarArg,
163 const SmallVectorImpl<ISD::InputArg> &Ins,
164 SDLoc dl, SelectionDAG &DAG,
165 SmallVectorImpl<SDValue> &InVals) const;
167 SDValue LowerReturn(SDValue Chain,
168 CallingConv::ID CallConv, bool isVarArg,
169 const SmallVectorImpl<ISD::OutputArg> &Outs,
170 const SmallVectorImpl<SDValue> &OutVals,
171 SDLoc dl, SelectionDAG &DAG) const;
173 SDValue LowerCall(CallLoweringInfo &CLI,
174 SmallVectorImpl<SDValue> &InVals) const;
176 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
177 CallingConv::ID CallConv, bool IsVarArg,
178 const SmallVectorImpl<ISD::InputArg> &Ins,
179 SDLoc dl, SelectionDAG &DAG,
180 SmallVectorImpl<SDValue> &InVals) const;
182 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
183 const AArch64Subtarget *ST) const;
185 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
187 void SaveVarArgRegisters(CCState &CCInfo, SelectionDAG &DAG, SDLoc DL,
188 SDValue &Chain) const;
190 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
191 /// for tail call optimization. Targets which want to do tail call
192 /// optimization should implement this function.
193 bool IsEligibleForTailCallOptimization(SDValue Callee,
194 CallingConv::ID CalleeCC,
196 bool IsCalleeStructRet,
197 bool IsCallerStructRet,
198 const SmallVectorImpl<ISD::OutputArg> &Outs,
199 const SmallVectorImpl<SDValue> &OutVals,
200 const SmallVectorImpl<ISD::InputArg> &Ins,
201 SelectionDAG& DAG) const;
203 /// Finds the incoming stack arguments which overlap the given fixed stack
204 /// object and incorporates their load into the current chain. This prevents
205 /// an upcoming store from clobbering the stack argument before it's used.
206 SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
207 MachineFrameInfo *MFI, int ClobberedFI) const;
209 EVT getSetCCResultType(LLVMContext &Context, EVT VT) const;
211 bool DoesCalleeRestoreStack(CallingConv::ID CallCC, bool TailCallOpt) const;
213 bool IsTailCallConvention(CallingConv::ID CallCC) const;
215 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
217 bool isLegalICmpImmediate(int64_t Val) const;
218 SDValue getSelectableIntSetCC(SDValue LHS, SDValue RHS, ISD::CondCode CC,
219 SDValue &A64cc, SelectionDAG &DAG, SDLoc &dl) const;
221 virtual MachineBasicBlock *
222 EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const;
225 emitAtomicBinary(MachineInstr *MI, MachineBasicBlock *MBB,
226 unsigned Size, unsigned Opcode) const;
229 emitAtomicBinaryMinMax(MachineInstr *MI, MachineBasicBlock *BB,
230 unsigned Size, unsigned CmpOp,
231 A64CC::CondCodes Cond) const;
233 emitAtomicCmpSwap(MachineInstr *MI, MachineBasicBlock *BB,
234 unsigned Size) const;
237 EmitF128CSEL(MachineInstr *MI, MachineBasicBlock *MBB) const;
239 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;
240 SDValue LowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const;
241 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
242 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
243 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
244 SDValue LowerF128ToCall(SDValue Op, SelectionDAG &DAG,
245 RTLIB::Libcall Call) const;
246 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
247 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
248 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, bool IsSigned) const;
249 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
250 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
252 SDValue LowerGlobalAddressELFSmall(SDValue Op, SelectionDAG &DAG) const;
253 SDValue LowerGlobalAddressELFLarge(SDValue Op, SelectionDAG &DAG) const;
254 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
256 SDValue LowerTLSDescCall(SDValue SymAddr, SDValue DescAddr, SDLoc DL,
257 SelectionDAG &DAG) const;
258 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
259 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG, bool IsSigned) const;
260 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
261 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
262 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
263 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
264 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
265 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
267 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
269 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
270 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
271 /// expanded to FMAs when this method returns true, otherwise fmuladd is
272 /// expanded to fmul + fadd.
273 virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const;
275 ConstraintType getConstraintType(const std::string &Constraint) const;
277 ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &Info,
278 const char *Constraint) const;
279 void LowerAsmOperandForConstraint(SDValue Op,
280 std::string &Constraint,
281 std::vector<SDValue> &Ops,
282 SelectionDAG &DAG) const;
284 std::pair<unsigned, const TargetRegisterClass*>
285 getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const;
287 virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
288 unsigned Intrinsic) const LLVM_OVERRIDE;
291 const InstrItineraryData *Itins;
293 const AArch64Subtarget *getSubtarget() const {
294 return &getTargetMachine().getSubtarget<AArch64Subtarget>();
297 enum NeonModImmType {
302 extern SDValue ScanBUILD_VECTOR(SDValue Op, bool &isOnlyLowElement,
303 bool &usesOnlyOneValue, bool &hasDominantValue,
304 bool &isConstant, bool &isUNDEF);
307 #endif // LLVM_TARGET_AARCH64_ISELLOWERING_H