blob: 37e01dc950f520eb8b4832e54e5995125a9a6360 [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.
Dylan McKay59e7fe32017-05-01 09:48:55 +000046 ROLLOOP, ///< A loop of single left bit rotate instructions.
47 RORLOOP, ///< A loop of single right bit rotate instructions.
Dylan McKay6d8078f2016-05-06 10:12:31 +000048 ASRLOOP, ///< A loop of single arithmetic shift right instructions.
49 /// AVR conditional branches. Operand 0 is the chain operand, operand 1
50 /// is the block to branch if condition is true, operand 2 is the
51 /// condition code, and operand 3 is the flag operand produced by a CMP
52 /// or TEST instruction.
53 BRCOND,
54 /// Compare instruction.
55 CMP,
56 /// Compare with carry instruction.
57 CMPC,
58 /// Test for zero or minus instruction.
59 TST,
60 /// Operand 0 and operand 1 are selection variable, operand 2
61 /// is condition code and operand 3 is flag operand.
62 SELECT_CC
63};
64
65} // end of namespace AVRISD
66
67class AVRTargetMachine;
68
69/// Performs target lowering for the AVR.
70class AVRTargetLowering : public TargetLowering {
71public:
72 explicit AVRTargetLowering(AVRTargetMachine &TM);
73
74public:
75 MVT getScalarShiftAmountTy(const DataLayout &, EVT LHSTy) const override {
76 return MVT::i8;
77 }
78 const char *getTargetNodeName(unsigned Opcode) const override;
79
80 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
81
82 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
83 SelectionDAG &DAG) const override;
84
85 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +000086 unsigned AS,
87 Instruction *I = nullptr) const override;
Dylan McKay6d8078f2016-05-06 10:12:31 +000088
89 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, SDValue &Offset,
90 ISD::MemIndexedMode &AM,
91 SelectionDAG &DAG) const override;
92
93 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
94 SDValue &Offset, ISD::MemIndexedMode &AM,
95 SelectionDAG &DAG) const override;
96
97 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
98
Dylan McKayc1ff65c2016-10-08 01:01:49 +000099 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
100 EVT VT) const override;
101
Dylan McKay6d8078f2016-05-06 10:12:31 +0000102 MachineBasicBlock *
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000103 EmitInstrWithCustomInserter(MachineInstr &MI,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000104 MachineBasicBlock *MBB) const override;
105
106 ConstraintType getConstraintType(StringRef Constraint) const override;
107
108 ConstraintWeight
109 getSingleConstraintMatchWeight(AsmOperandInfo &info,
110 const char *constraint) const override;
111
112 std::pair<unsigned, const TargetRegisterClass *>
113 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
114 StringRef Constraint, MVT VT) const override;
115
116 unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
117
118 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
119 std::vector<SDValue> &Ops,
120 SelectionDAG &DAG) const override;
121
Dylan McKay8fa6d8d2017-01-07 23:39:47 +0000122 unsigned getRegisterByName(const char* RegName, EVT VT,
123 SelectionDAG &DAG) const override;
124
Dylan McKay6d8078f2016-05-06 10:12:31 +0000125private:
126 SDValue getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, SDValue &AVRcc,
127 SelectionDAG &DAG, SDLoc dl) const;
128 SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;
129 SDValue LowerDivRem(SDValue Op, SelectionDAG &DAG) const;
130 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
131 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
132 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
133 SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const;
134 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
135 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
136 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
137
Dylan McKay12109e72016-10-08 01:05:09 +0000138 CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC) const;
139
140 bool CanLowerReturn(CallingConv::ID CallConv,
141 MachineFunction &MF, bool isVarArg,
142 const SmallVectorImpl<ISD::OutputArg> &Outs,
143 LLVMContext &Context) const override;
144
Dylan McKay6d8078f2016-05-06 10:12:31 +0000145 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
146 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000147 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000148 SelectionDAG &DAG) const override;
149 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
150 bool isVarArg,
151 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000152 const SDLoc &dl, SelectionDAG &DAG,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000153 SmallVectorImpl<SDValue> &InVals) const override;
154 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
155 SmallVectorImpl<SDValue> &InVals) const override;
156 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
157 CallingConv::ID CallConv, bool isVarArg,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000158 const SmallVectorImpl<ISD::InputArg> &Ins,
159 const SDLoc &dl, SelectionDAG &DAG,
Dylan McKay6d8078f2016-05-06 10:12:31 +0000160 SmallVectorImpl<SDValue> &InVals) const;
161
162private:
Dylan McKaya1a944e2016-10-08 01:06:21 +0000163 MachineBasicBlock *insertShift(MachineInstr &MI, MachineBasicBlock *BB) const;
164 MachineBasicBlock *insertMul(MachineInstr &MI, MachineBasicBlock *BB) const;
Dylan McKay6d8078f2016-05-06 10:12:31 +0000165};
166
167} // end namespace llvm
168
169#endif // LLVM_AVR_ISEL_LOWERING_H