blob: 17074e1b1eeea885eb26fffa70ff700c040ab1b2 [file] [log] [blame]
Dylan McKay6d8078f2016-05-06 10:12:31 +00001//===-- AVRISelLowering.h - AVR 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 AVR uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_AVR_ISEL_LOWERING_H
16#define LLVM_AVR_ISEL_LOWERING_H
17
Dylan McKay12109e72016-10-08 01:05:09 +000018#include "llvm/CodeGen/CallingConvLower.h"
Dylan McKay6d8078f2016-05-06 10:12:31 +000019#include "llvm/Target/TargetLowering.h"
20
21namespace llvm {
22
23namespace AVRISD {
24
25/// AVR Specific DAG Nodes
26enum NodeType {
27 /// Start the numbering where the builtin ops leave off.
28 FIRST_NUMBER = ISD::BUILTIN_OP_END,
29 /// Return from subroutine.
30 RET_FLAG,
31 /// Return from ISR.
32 RETI_FLAG,
33 /// Represents an abstract call instruction,
34 /// which includes a bunch of information.
35 CALL,
36 /// A wrapper node for TargetConstantPool,
37 /// TargetExternalSymbol, and TargetGlobalAddress.
38 WRAPPER,
39 LSL, ///< Logical shift left.
40 LSR, ///< Logical shift right.
41 ASR, ///< Arithmetic shift right.
42 ROR, ///< Bit rotate right.
43 ROL, ///< Bit rotate left.
44 LSLLOOP, ///< A loop of single logical shift left instructions.
45 LSRLOOP, ///< A loop of single logical shift right instructions.
46 ASRLOOP, ///< A loop of single arithmetic shift right instructions.
47 /// AVR conditional branches. Operand 0 is the chain operand, operand 1
48 /// is the block to branch if condition is true, operand 2 is the
49 /// condition code, and operand 3 is the flag operand produced by a CMP
50 /// or TEST instruction.
51 BRCOND,
52 /// Compare instruction.
53 CMP,
54 /// Compare with carry instruction.
55 CMPC,
56 /// Test for zero or minus instruction.
57 TST,
58 /// Operand 0 and operand 1 are selection variable, operand 2
59 /// is condition code and operand 3 is flag operand.
60 SELECT_CC
61};
62
63} // end of namespace AVRISD
64
65class AVRTargetMachine;
66
67/// Performs target lowering for the AVR.
68class AVRTargetLowering : public TargetLowering {
69public:
70 explicit AVRTargetLowering(AVRTargetMachine &TM);
71
72public:
73 MVT getScalarShiftAmountTy(const DataLayout &, EVT LHSTy) const override {
74 return MVT::i8;
75 }
76 const char *getTargetNodeName(unsigned Opcode) const override;
77
78 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
79
80 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
81 SelectionDAG &DAG) const override;
82
83 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
84 unsigned AS) const override;
85
86 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
87 ISD::MemIndexedMode &AM,
88 SelectionDAG &DAG) const override;
89
90 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
91 SDValue &Offset, ISD::MemIndexedMode &AM,
92 SelectionDAG &DAG) const override;
93
94 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
95
Dylan McKayc1ff65c2016-10-08 01:01:49 +000096 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
97 EVT VT) const override;
98
Dylan McKay6d8078f2016-05-06 10:12:31 +000099 MachineBasicBlock *
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000100 EmitInstrWithCustomInserter(MachineInstr &MI,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000101 MachineBasicBlock *MBB) const override;
102
103 ConstraintType getConstraintType(StringRef Constraint) const override;
104
105 ConstraintWeight
106 getSingleConstraintMatchWeight(AsmOperandInfo &info,
107 const char *constraint) const override;
108
109 std::pair<unsigned, const TargetRegisterClass *>
110 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
111 StringRef Constraint, MVT VT) const override;
112
113 unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
114
115 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
116 std::vector<SDValue> &Ops,
117 SelectionDAG &DAG) const override;
118
119private:
120 SDValue getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, SDValue &AVRcc,
121 SelectionDAG &DAG, SDLoc dl) const;
122 SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;
123 SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;
124 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
125 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
126 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
127 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
128 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
129 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
130 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
131
Dylan McKay12109e72016-10-08 01:05:09 +0000132 CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC) const;
133
134 bool CanLowerReturn(CallingConv::ID CallConv,
135 MachineFunction &MF, bool isVarArg,
136 const SmallVectorImpl<ISD::OutputArg> &Outs,
137 LLVMContext &Context) const override;
138
Dylan McKay6d8078f2016-05-06 10:12:31 +0000139 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
140 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000141 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000142 SelectionDAG &DAG) const override;
143 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
144 bool isVarArg,
145 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000146 const SDLoc &dl, SelectionDAG &DAG,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000147 SmallVectorImpl<SDValue> &InVals) const override;
148 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
149 SmallVectorImpl<SDValue> &InVals) const override;
150 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
151 CallingConv::ID CallConv, bool isVarArg,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000152 const SmallVectorImpl<ISD::InputArg> &Ins,
153 const SDLoc &dl, SelectionDAG &DAG,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000154 SmallVectorImpl<SDValue> &InVals) const;
155
156private:
Dylan McKaya1a944e2016-10-08 01:06:21 +0000157 MachineBasicBlock *insertShift(MachineInstr &MI, MachineBasicBlock *BB) const;
158 MachineBasicBlock *insertMul(MachineInstr &MI, MachineBasicBlock *BB) const;
Dylan McKay6d8078f2016-05-06 10:12:31 +0000159};
160
161} // end namespace llvm
162
163#endif // LLVM_AVR_ISEL_LOWERING_H