[C++11] Add 'override' keywords and remove 'virtual'. Additionally add 'final' and...
[oota-llvm.git] / lib / Target / AArch64 / AArch64ISelLowering.h
1 //==-- AArch64ISelLowering.h - AArch64 DAG Lowering Interface ----*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that AArch64 uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_AARCH64_ISELLOWERING_H
16 #define LLVM_TARGET_AARCH64_ISELLOWERING_H
17
18 #include "Utils/AArch64BaseInfo.h"
19 #include "llvm/CodeGen/CallingConvLower.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/Target/TargetLowering.h"
23
24 namespace llvm {
25 namespace AArch64ISD {
26   enum NodeType {
27     // Start the numbering from where ISD NodeType finishes.
28     FIRST_NUMBER = ISD::BUILTIN_OP_END,
29
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.
33     BR_CC,
34
35     // A node to be selected to an actual call operation: either BL or BLR in
36     // the absence of tail calls.
37     Call,
38
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.
42     FPMOV,
43
44     // Corresponds directly to an EXTR instruction. Operands are an LHS an RHS
45     // and an LSB.
46     EXTR,
47
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.
51     GOTLoad,
52
53     // Performs a bitfield insert. Arguments are: the value being inserted into;
54     // the value being inserted; least significant bit changed; width of the
55     // field.
56     BFI,
57
58     // Simply a convenient node inserted during ISelLowering to represent
59     // procedure return. Will almost certainly be selected to "RET".
60     Ret,
61
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.
66     SBFX,
67
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.
71     SELECT_CC,
72
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
77     /// comparison.
78     ///
79     /// It keeps a record of the condition flags asked for because certain
80     /// instructions are only valid for a subset of condition codes.
81     SETCC,
82
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.
87     TC_RETURN,
88
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.
93     TLSDESCCALL,
94
95     // Leaf node which will be lowered to an appropriate MRS to obtain the
96     // thread pointer: TPIDR_EL0.
97     THREAD_POINTER,
98
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.
103     UBFX,
104
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.
108     WrapperLarge,
109
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
113     // get selected.
114     WrapperSmall,
115
116     // Vector move immediate
117     NEON_MOVIMM,
118
119     // Vector Move Inverted Immediate
120     NEON_MVNIMM,
121
122     // Vector FP move immediate
123     NEON_FMOVIMM,
124
125     // Vector permute
126     NEON_UZP1,
127     NEON_UZP2,
128     NEON_ZIP1,
129     NEON_ZIP2,
130     NEON_TRN1,
131     NEON_TRN2,
132
133     // Vector Element reverse
134     NEON_REV64,
135     NEON_REV32,
136     NEON_REV16,
137
138     // Vector compare
139     NEON_CMP,
140
141     // Vector compare zero
142     NEON_CMPZ,
143
144     // Vector compare bitwise test
145     NEON_TST,
146
147     // Vector saturating shift
148     NEON_QSHLs,
149     NEON_QSHLu,
150
151     // Vector dup
152     NEON_VDUP,
153
154     // Vector dup by lane
155     NEON_VDUPLANE,
156
157     // Vector extract
158     NEON_VEXTRACT,
159
160     // NEON duplicate lane loads
161     NEON_LD2DUP = ISD::FIRST_TARGET_MEMORY_OPCODE,
162     NEON_LD3DUP,
163     NEON_LD4DUP,
164
165     // NEON loads with post-increment base updates:
166     NEON_LD1_UPD,
167     NEON_LD2_UPD,
168     NEON_LD3_UPD,
169     NEON_LD4_UPD,
170     NEON_LD1x2_UPD,
171     NEON_LD1x3_UPD,
172     NEON_LD1x4_UPD,
173
174     // NEON stores with post-increment base updates:
175     NEON_ST1_UPD,
176     NEON_ST2_UPD,
177     NEON_ST3_UPD,
178     NEON_ST4_UPD,
179     NEON_ST1x2_UPD,
180     NEON_ST1x3_UPD,
181     NEON_ST1x4_UPD,
182
183     // NEON duplicate lane loads with post-increment base updates:
184     NEON_LD2DUP_UPD,
185     NEON_LD3DUP_UPD,
186     NEON_LD4DUP_UPD,
187
188     // NEON lane loads with post-increment base updates:
189     NEON_LD2LN_UPD,
190     NEON_LD3LN_UPD,
191     NEON_LD4LN_UPD,
192
193     // NEON lane store with post-increment base updates:
194     NEON_ST2LN_UPD,
195     NEON_ST3LN_UPD,
196     NEON_ST4LN_UPD
197   };
198 }
199
200
201 class AArch64Subtarget;
202 class AArch64TargetMachine;
203
204 class AArch64TargetLowering : public TargetLowering {
205 public:
206   explicit AArch64TargetLowering(AArch64TargetMachine &TM);
207
208   const char *getTargetNodeName(unsigned Opcode) const override;
209
210   CCAssignFn *CCAssignFnForNode(CallingConv::ID CC) const;
211
212   SDValue LowerFormalArguments(SDValue Chain,
213                                CallingConv::ID CallConv, bool isVarArg,
214                                const SmallVectorImpl<ISD::InputArg> &Ins,
215                                SDLoc dl, SelectionDAG &DAG,
216                                SmallVectorImpl<SDValue> &InVals) const override;
217
218   SDValue LowerReturn(SDValue Chain,
219                       CallingConv::ID CallConv, bool isVarArg,
220                       const SmallVectorImpl<ISD::OutputArg> &Outs,
221                       const SmallVectorImpl<SDValue> &OutVals,
222                       SDLoc dl, SelectionDAG &DAG) const override;
223
224   unsigned getByValTypeAlignment(Type *Ty) const override;
225
226   SDValue LowerCall(CallLoweringInfo &CLI,
227                     SmallVectorImpl<SDValue> &InVals) const override;
228
229   SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
230                           CallingConv::ID CallConv, bool IsVarArg,
231                           const SmallVectorImpl<ISD::InputArg> &Ins,
232                           SDLoc dl, SelectionDAG &DAG,
233                           SmallVectorImpl<SDValue> &InVals) const;
234
235   SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
236   SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
237
238   bool isConcatVector(SDValue Op, SelectionDAG &DAG, SDValue V0, SDValue V1,
239                       const int *Mask, SDValue &Res) const;
240
241   bool isKnownShuffleVector(SDValue Op, SelectionDAG &DAG, SDValue &V0,
242                             SDValue &V1, int *Mask) const;
243
244   SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
245                             const AArch64Subtarget *ST) const;
246
247   SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
248
249   void SaveVarArgRegisters(CCState &CCInfo, SelectionDAG &DAG, SDLoc DL,
250                            SDValue &Chain) const;
251
252   /// IsEligibleForTailCallOptimization - Check whether the call is eligible
253   /// for tail call optimization. Targets which want to do tail call
254   /// optimization should implement this function.
255   bool IsEligibleForTailCallOptimization(SDValue Callee,
256                                     CallingConv::ID CalleeCC,
257                                     bool IsVarArg,
258                                     bool IsCalleeStructRet,
259                                     bool IsCallerStructRet,
260                                     const SmallVectorImpl<ISD::OutputArg> &Outs,
261                                     const SmallVectorImpl<SDValue> &OutVals,
262                                     const SmallVectorImpl<ISD::InputArg> &Ins,
263                                     SelectionDAG& DAG) const;
264
265   /// Finds the incoming stack arguments which overlap the given fixed stack
266   /// object and incorporates their load into the current chain. This prevents
267   /// an upcoming store from clobbering the stack argument before it's used.
268   SDValue addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
269                               MachineFrameInfo *MFI, int ClobberedFI) const;
270
271   EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
272
273   bool DoesCalleeRestoreStack(CallingConv::ID CallCC, bool TailCallOpt) const;
274
275   bool IsTailCallConvention(CallingConv::ID CallCC) const;
276
277   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
278
279   bool isLegalICmpImmediate(int64_t Val) const override;
280
281   /// \brief Return true if the addressing mode represented by AM is legal for
282   /// this target, for a load/store of the specified type.
283   bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
284
285   /// \brief Return the cost of the scaling factor used in the addressing
286   /// mode represented by AM for this target, for a load/store
287   /// of the specified type.
288   /// If the AM is supported, the return value must be >= 0.
289   /// If the AM is not supported, it returns a negative value.
290   int getScalingFactorCost(const AddrMode &AM, Type *Ty) const override;
291
292   bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
293   bool isTruncateFree(EVT VT1, EVT VT2) const override;
294
295   bool isZExtFree(Type *Ty1, Type *Ty2) const override;
296   bool isZExtFree(EVT VT1, EVT VT2) const override;
297   bool isZExtFree(SDValue Val, EVT VT2) const override;
298
299   SDValue getSelectableIntSetCC(SDValue LHS, SDValue RHS, ISD::CondCode CC,
300                          SDValue &A64cc, SelectionDAG &DAG, SDLoc &dl) const;
301
302   MachineBasicBlock *
303   EmitInstrWithCustomInserter(MachineInstr *MI,
304                               MachineBasicBlock *MBB) const override;
305
306   MachineBasicBlock *
307   emitAtomicBinary(MachineInstr *MI, MachineBasicBlock *MBB,
308                    unsigned Size, unsigned Opcode) const;
309
310   MachineBasicBlock *
311   emitAtomicBinaryMinMax(MachineInstr *MI, MachineBasicBlock *BB,
312                          unsigned Size, unsigned CmpOp,
313                          A64CC::CondCodes Cond) const;
314   MachineBasicBlock *
315   emitAtomicCmpSwap(MachineInstr *MI, MachineBasicBlock *BB,
316                     unsigned Size) const;
317
318   MachineBasicBlock *
319   EmitF128CSEL(MachineInstr *MI, MachineBasicBlock *MBB) const;
320
321   SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;
322   SDValue LowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const;
323   SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
324   SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
325   SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
326   SDValue LowerF128ToCall(SDValue Op, SelectionDAG &DAG,
327                           RTLIB::Libcall Call) const;
328   SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
329   SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
330   SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, bool IsSigned) const;
331   SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
332   SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
333
334   SDValue LowerGlobalAddressELFSmall(SDValue Op, SelectionDAG &DAG) const;
335   SDValue LowerGlobalAddressELFLarge(SDValue Op, SelectionDAG &DAG) const;
336   SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG) const;
337
338   SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
339
340   SDValue LowerTLSDescCall(SDValue SymAddr, SDValue DescAddr, SDLoc DL,
341                            SelectionDAG &DAG) const;
342   SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
343   SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG, bool IsSigned) const;
344   SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
345   SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
346   SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
347   SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
348   SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
349   SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
350
351   SDValue PerformDAGCombine(SDNode *N,DAGCombinerInfo &DCI) const override;
352
353   /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
354   /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
355   /// expanded to FMAs when this method returns true, otherwise fmuladd is
356   /// expanded to fmul + fadd.
357   bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
358
359   /// allowsUnalignedMemoryAccesses - Returns true if the target allows
360   /// unaligned memory accesses of the specified type. Returns whether it
361   /// is "fast" by reference in the second argument.
362   bool allowsUnalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
363                                      bool *Fast) const override;
364
365   ConstraintType
366   getConstraintType(const std::string &Constraint) const override;
367
368   ConstraintWeight
369   getSingleConstraintMatchWeight(AsmOperandInfo &Info,
370                                  const char *Constraint) const override;
371   void LowerAsmOperandForConstraint(SDValue Op,
372                                     std::string &Constraint,
373                                     std::vector<SDValue> &Ops,
374                                     SelectionDAG &DAG) const override;
375
376   std::pair<unsigned, const TargetRegisterClass*>
377   getRegForInlineAsmConstraint(const std::string &Constraint,
378                                MVT VT) const override;
379
380   bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
381                           unsigned Intrinsic) const override;
382
383   /// getMaximalGlobalOffset - Returns the maximal possible offset which can
384   /// be used for loads / stores from the global.
385   unsigned getMaximalGlobalOffset() const override;
386
387 protected:
388   std::pair<const TargetRegisterClass*, uint8_t>
389   findRepresentativeClass(MVT VT) const override;
390
391 private:
392   const InstrItineraryData *Itins;
393
394   const AArch64Subtarget *getSubtarget() const {
395     return &getTargetMachine().getSubtarget<AArch64Subtarget>();
396   }
397 };
398 enum NeonModImmType {
399   Neon_Mov_Imm,
400   Neon_Mvn_Imm
401 };
402
403 extern SDValue ScanBUILD_VECTOR(SDValue Op, bool &isOnlyLowElement,
404                                 bool &usesOnlyOneValue, bool &hasDominantValue,
405                                 bool &isConstant, bool &isUNDEF);
406 } // namespace llvm
407
408 #endif // LLVM_TARGET_AARCH64_ISELLOWERING_H