1 //===-- MipsISelLowering.h - Mips 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 Mips uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #ifndef MipsISELLOWERING_H
16 #define MipsISELLOWERING_H
19 #include "MipsSubtarget.h"
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/CodeGen/SelectionDAG.h"
22 #include "llvm/Target/TargetLowering.h"
27 // Start the numbering from where ISD NodeType finishes.
28 FIRST_NUMBER = ISD::BUILTIN_OP_END,
30 // Jump and link (call)
36 // Get the Higher 16 bits from a 32-bit immediate
37 // No relation with Mips Hi register
40 // Get the Lower 16 bits from a 32-bit immediate
41 // No relation with Mips Lo register
44 // Handle gp_rel (small data/bss sections) relocation.
50 // Floating Point Branch Conditional
53 // Floating Point Compare
56 // Floating Point Conditional Moves
60 // Floating Point Rounding
88 // EXTR.W instrinsic nodes.
98 // DPA.W intrinsic nodes.
129 // Load/Store Left/Right nodes.
130 LWL = ISD::FIRST_TARGET_MEMORY_OPCODE,
141 //===--------------------------------------------------------------------===//
142 // TargetLowering Implementation
143 //===--------------------------------------------------------------------===//
144 class MipsFunctionInfo;
146 class MipsTargetLowering : public TargetLowering {
148 explicit MipsTargetLowering(MipsTargetMachine &TM);
150 virtual MVT getShiftAmountTy(EVT LHSTy) const { return MVT::i32; }
152 virtual bool allowsUnalignedMemoryAccesses (EVT VT) const;
154 virtual void LowerOperationWrapper(SDNode *N,
155 SmallVectorImpl<SDValue> &Results,
156 SelectionDAG &DAG) const;
158 /// LowerOperation - Provide custom lowering hooks for some operations.
159 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
161 /// ReplaceNodeResults - Replace the results of node with an illegal result
162 /// type with new values built out of custom code.
164 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
165 SelectionDAG &DAG) const;
167 /// getTargetNodeName - This method returns the name of a target specific
169 virtual const char *getTargetNodeName(unsigned Opcode) const;
171 /// getSetCCResultType - get the ISD::SETCC result ValueType
172 EVT getSetCCResultType(EVT VT) const;
174 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
177 /// ByValArgInfo - Byval argument information.
178 struct ByValArgInfo {
179 unsigned FirstIdx; // Index of the first register used.
180 unsigned NumRegs; // Number of registers used for this argument.
181 unsigned Address; // Offset of the stack area used to pass this argument.
183 ByValArgInfo() : FirstIdx(0), NumRegs(0), Address(0) {}
186 /// MipsCC - This class provides methods used to analyze formal and call
187 /// arguments and inquire about calling convention information.
190 MipsCC(CallingConv::ID CallConv, bool IsVarArg, bool IsO32,
193 void analyzeCallOperands(const SmallVectorImpl<ISD::OutputArg> &Outs);
194 void analyzeFormalArguments(const SmallVectorImpl<ISD::InputArg> &Ins);
195 void handleByValArg(unsigned ValNo, MVT ValVT, MVT LocVT,
196 CCValAssign::LocInfo LocInfo,
197 ISD::ArgFlagsTy ArgFlags);
199 const CCState &getCCInfo() const { return CCInfo; }
201 /// hasByValArg - Returns true if function has byval arguments.
202 bool hasByValArg() const { return !ByValArgs.empty(); }
204 /// useRegsForByval - Returns true if the calling convention allows the
205 /// use of registers to pass byval arguments.
206 bool useRegsForByval() const { return UseRegsForByval; }
208 /// regSize - Size (in number of bits) of integer registers.
209 unsigned regSize() const { return RegSize; }
211 /// numIntArgRegs - Number of integer registers available for calls.
212 unsigned numIntArgRegs() const { return NumIntArgRegs; }
214 /// reservedArgArea - The size of the area the caller reserves for
215 /// register arguments. This is 16-byte if ABI is O32.
216 unsigned reservedArgArea() const { return ReservedArgArea; }
218 /// intArgRegs - Pointer to array of integer registers.
219 const uint16_t *intArgRegs() const { return IntArgRegs; }
221 typedef SmallVector<ByValArgInfo, 2>::const_iterator byval_iterator;
222 byval_iterator byval_begin() const { return ByValArgs.begin(); }
223 byval_iterator byval_end() const { return ByValArgs.end(); }
226 void allocateRegs(ByValArgInfo &ByVal, unsigned ByValSize,
230 bool UseRegsForByval;
232 unsigned NumIntArgRegs;
233 unsigned ReservedArgArea;
234 const uint16_t *IntArgRegs, *ShadowRegs;
235 SmallVector<ByValArgInfo, 2> ByValArgs;
236 llvm::CCAssignFn *FixedFn, *VarFn;
240 const MipsSubtarget *Subtarget;
242 bool HasMips64, IsN64, IsO32;
244 // Lower Operand helpers
245 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
246 CallingConv::ID CallConv, bool isVarArg,
247 const SmallVectorImpl<ISD::InputArg> &Ins,
248 DebugLoc dl, SelectionDAG &DAG,
249 SmallVectorImpl<SDValue> &InVals) const;
251 // Lower Operand specifics
252 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
253 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
254 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
255 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
256 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
257 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
258 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
259 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
260 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
261 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
262 SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
263 SDValue LowerFABS(SDValue Op, SelectionDAG &DAG) const;
264 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
265 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
266 SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG& DAG) const;
267 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
268 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG& DAG) const;
269 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG& DAG,
271 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
272 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
273 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
274 SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
275 SDValue LowerADD(SDValue Op, SelectionDAG &DAG) const;
277 /// IsEligibleForTailCallOptimization - Check whether the call is eligible
278 /// for tail call optimization.
279 bool IsEligibleForTailCallOptimization(const MipsCC &MipsCCInfo,
280 unsigned NextStackOffset,
281 const MipsFunctionInfo& FI) const;
283 /// copyByValArg - Copy argument registers which were used to pass a byval
284 /// argument to the stack. Create a stack frame object for the byval
286 void copyByValRegs(SDValue Chain, DebugLoc DL,
287 std::vector<SDValue> &OutChains, SelectionDAG &DAG,
288 const ISD::ArgFlagsTy &Flags,
289 SmallVectorImpl<SDValue> &InVals,
290 const Argument *FuncArg,
291 const MipsCC &CC, const ByValArgInfo &ByVal) const;
293 /// passByValArg - Pass a byval argument in registers or on stack.
294 void passByValArg(SDValue Chain, DebugLoc DL,
295 SmallVector<std::pair<unsigned, SDValue>, 16> &RegsToPass,
296 SmallVector<SDValue, 8> &MemOpChains, SDValue StackPtr,
297 MachineFrameInfo *MFI, SelectionDAG &DAG, SDValue Arg,
298 const MipsCC &CC, const ByValArgInfo &ByVal,
299 const ISD::ArgFlagsTy &Flags, bool isLittle) const;
301 /// writeVarArgRegs - Write variable function arguments passed in registers
302 /// to the stack. Also create a stack frame object for the first variable
304 void writeVarArgRegs(std::vector<SDValue> &OutChains, const MipsCC &CC,
305 SDValue Chain, DebugLoc DL, SelectionDAG &DAG) const;
308 LowerFormalArguments(SDValue Chain,
309 CallingConv::ID CallConv, bool isVarArg,
310 const SmallVectorImpl<ISD::InputArg> &Ins,
311 DebugLoc dl, SelectionDAG &DAG,
312 SmallVectorImpl<SDValue> &InVals) const;
314 SDValue passArgOnStack(SDValue StackPtr, unsigned Offset, SDValue Chain,
315 SDValue Arg, DebugLoc DL, bool IsTailCall,
316 SelectionDAG &DAG) const;
319 LowerCall(TargetLowering::CallLoweringInfo &CLI,
320 SmallVectorImpl<SDValue> &InVals) const;
323 CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
325 const SmallVectorImpl<ISD::OutputArg> &Outs,
326 LLVMContext &Context) const;
329 LowerReturn(SDValue Chain,
330 CallingConv::ID CallConv, bool isVarArg,
331 const SmallVectorImpl<ISD::OutputArg> &Outs,
332 const SmallVectorImpl<SDValue> &OutVals,
333 DebugLoc dl, SelectionDAG &DAG) const;
335 virtual MachineBasicBlock *
336 EmitInstrWithCustomInserter(MachineInstr *MI,
337 MachineBasicBlock *MBB) const;
339 // Inline asm support
340 ConstraintType getConstraintType(const std::string &Constraint) const;
342 /// Examine constraint string and operand type and determine a weight value.
343 /// The operand object must already have been set up with the operand type.
344 ConstraintWeight getSingleConstraintMatchWeight(
345 AsmOperandInfo &info, const char *constraint) const;
347 std::pair<unsigned, const TargetRegisterClass*>
348 getRegForInlineAsmConstraint(const std::string &Constraint,
351 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
352 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
353 /// true it means one of the asm constraint of the inline asm instruction
354 /// being processed is 'm'.
355 virtual void LowerAsmOperandForConstraint(SDValue Op,
356 std::string &Constraint,
357 std::vector<SDValue> &Ops,
358 SelectionDAG &DAG) const;
360 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
362 virtual EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
363 unsigned SrcAlign, bool IsZeroVal,
365 MachineFunction &MF) const;
367 /// isFPImmLegal - Returns true if the target can instruction select the
368 /// specified FP immediate natively. If false, the legalizer will
369 /// materialize the FP immediate as a load from a constant pool.
370 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
372 virtual unsigned getJumpTableEncoding() const;
374 MachineBasicBlock *EmitBPOSGE32(MachineInstr *MI,
375 MachineBasicBlock *BB) const;
376 MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB,
377 unsigned Size, unsigned BinOpcode, bool Nand = false) const;
378 MachineBasicBlock *EmitAtomicBinaryPartword(MachineInstr *MI,
379 MachineBasicBlock *BB, unsigned Size, unsigned BinOpcode,
380 bool Nand = false) const;
381 MachineBasicBlock *EmitAtomicCmpSwap(MachineInstr *MI,
382 MachineBasicBlock *BB, unsigned Size) const;
383 MachineBasicBlock *EmitAtomicCmpSwapPartword(MachineInstr *MI,
384 MachineBasicBlock *BB, unsigned Size) const;
388 #endif // MipsISELLOWERING_H