1 //===-- AVRISelLowering.cpp - AVR DAG Lowering Implementation -------------===//
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 AVR uses to lower LLVM code into a
13 //===----------------------------------------------------------------------===//
15 #include "AVRISelLowering.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/CodeGen/CallingConvLower.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/Support/ErrorHandling.h"
28 #include "AVRMachineFunctionInfo.h"
29 #include "AVRTargetMachine.h"
30 #include "MCTargetDesc/AVRMCTargetDesc.h"
34 AVRTargetLowering::AVRTargetLowering(AVRTargetMachine &tm)
35 : TargetLowering(tm) {
36 // Set up the register classes.
37 addRegisterClass(MVT::i8, &AVR::GPR8RegClass);
38 addRegisterClass(MVT::i16, &AVR::DREGSRegClass);
40 // Compute derived properties from the register classes.
41 computeRegisterProperties(tm.getSubtargetImpl()->getRegisterInfo());
43 setBooleanContents(ZeroOrOneBooleanContent);
44 setBooleanVectorContents(ZeroOrOneBooleanContent);
45 setSchedulingPreference(Sched::RegPressure);
46 setStackPointerRegisterToSaveRestore(AVR::SP);
48 setOperationAction(ISD::GlobalAddress, MVT::i16, Custom);
49 setOperationAction(ISD::BlockAddress, MVT::i16, Custom);
51 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i8, Expand);
52 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i16, Expand);
54 for (MVT VT : MVT::integer_valuetypes()) {
55 for (auto N : {ISD::EXTLOAD, ISD::SEXTLOAD, ISD::ZEXTLOAD}) {
56 setLoadExtAction(N, VT, MVT::i1, Promote);
57 setLoadExtAction(N, VT, MVT::i8, Expand);
61 setTruncStoreAction(MVT::i16, MVT::i8, Expand);
63 // sub (x, imm) gets canonicalized to add (x, -imm), so for illegal types
64 // revert into a sub since we don't have an add with immediate instruction.
65 setOperationAction(ISD::ADD, MVT::i32, Custom);
66 setOperationAction(ISD::ADD, MVT::i64, Custom);
68 // our shift instructions are only able to shift 1 bit at a time, so handle
69 // this in a custom way.
70 setOperationAction(ISD::SRA, MVT::i8, Custom);
71 setOperationAction(ISD::SHL, MVT::i8, Custom);
72 setOperationAction(ISD::SRL, MVT::i8, Custom);
73 setOperationAction(ISD::SRA, MVT::i16, Custom);
74 setOperationAction(ISD::SHL, MVT::i16, Custom);
75 setOperationAction(ISD::SRL, MVT::i16, Custom);
76 setOperationAction(ISD::SHL_PARTS, MVT::i16, Expand);
77 setOperationAction(ISD::SRA_PARTS, MVT::i16, Expand);
78 setOperationAction(ISD::SRL_PARTS, MVT::i16, Expand);
80 setOperationAction(ISD::BR_CC, MVT::i8, Custom);
81 setOperationAction(ISD::BR_CC, MVT::i16, Custom);
82 setOperationAction(ISD::BR_CC, MVT::i32, Custom);
83 setOperationAction(ISD::BR_CC, MVT::i64, Custom);
84 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
86 setOperationAction(ISD::SELECT_CC, MVT::i8, Custom);
87 setOperationAction(ISD::SELECT_CC, MVT::i16, Custom);
88 setOperationAction(ISD::SELECT_CC, MVT::i32, Expand);
89 setOperationAction(ISD::SELECT_CC, MVT::i64, Expand);
90 setOperationAction(ISD::SETCC, MVT::i8, Custom);
91 setOperationAction(ISD::SETCC, MVT::i16, Custom);
92 setOperationAction(ISD::SETCC, MVT::i32, Custom);
93 setOperationAction(ISD::SETCC, MVT::i64, Custom);
94 setOperationAction(ISD::SELECT, MVT::i8, Expand);
95 setOperationAction(ISD::SELECT, MVT::i16, Expand);
97 setOperationAction(ISD::BSWAP, MVT::i16, Expand);
99 // Add support for postincrement and predecrement load/stores.
100 setIndexedLoadAction(ISD::POST_INC, MVT::i8, Legal);
101 setIndexedLoadAction(ISD::POST_INC, MVT::i16, Legal);
102 setIndexedLoadAction(ISD::PRE_DEC, MVT::i8, Legal);
103 setIndexedLoadAction(ISD::PRE_DEC, MVT::i16, Legal);
104 setIndexedStoreAction(ISD::POST_INC, MVT::i8, Legal);
105 setIndexedStoreAction(ISD::POST_INC, MVT::i16, Legal);
106 setIndexedStoreAction(ISD::PRE_DEC, MVT::i8, Legal);
107 setIndexedStoreAction(ISD::PRE_DEC, MVT::i16, Legal);
109 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
111 setOperationAction(ISD::VASTART, MVT::Other, Custom);
112 setOperationAction(ISD::VAEND, MVT::Other, Expand);
113 setOperationAction(ISD::VAARG, MVT::Other, Expand);
114 setOperationAction(ISD::VACOPY, MVT::Other, Expand);
116 // Atomic operations which must be lowered to rtlib calls
117 for (MVT VT : MVT::integer_valuetypes()) {
118 setOperationAction(ISD::ATOMIC_SWAP, VT, Expand);
119 setOperationAction(ISD::ATOMIC_CMP_SWAP, VT, Expand);
120 setOperationAction(ISD::ATOMIC_LOAD_NAND, VT, Expand);
121 setOperationAction(ISD::ATOMIC_LOAD_MAX, VT, Expand);
122 setOperationAction(ISD::ATOMIC_LOAD_MIN, VT, Expand);
123 setOperationAction(ISD::ATOMIC_LOAD_UMAX, VT, Expand);
124 setOperationAction(ISD::ATOMIC_LOAD_UMIN, VT, Expand);
127 // Division/remainder
128 setOperationAction(ISD::UDIV, MVT::i8, Expand);
129 setOperationAction(ISD::UDIV, MVT::i16, Expand);
130 setOperationAction(ISD::UREM, MVT::i8, Expand);
131 setOperationAction(ISD::UREM, MVT::i16, Expand);
132 setOperationAction(ISD::SDIV, MVT::i8, Expand);
133 setOperationAction(ISD::SDIV, MVT::i16, Expand);
134 setOperationAction(ISD::SREM, MVT::i8, Expand);
135 setOperationAction(ISD::SREM, MVT::i16, Expand);
137 // Make division and modulus custom
138 for (MVT VT : MVT::integer_valuetypes()) {
139 setOperationAction(ISD::UDIVREM, VT, Custom);
140 setOperationAction(ISD::SDIVREM, VT, Custom);
143 // Do not use MUL. The AVR instructions are closer to SMUL_LOHI &co.
144 setOperationAction(ISD::MUL, MVT::i8, Expand);
145 setOperationAction(ISD::MUL, MVT::i16, Expand);
147 // Expand 16 bit multiplications.
148 setOperationAction(ISD::SMUL_LOHI, MVT::i16, Expand);
149 setOperationAction(ISD::UMUL_LOHI, MVT::i16, Expand);
151 for (MVT VT : MVT::integer_valuetypes()) {
152 setOperationAction(ISD::MULHS, VT, Expand);
153 setOperationAction(ISD::MULHU, VT, Expand);
156 for (MVT VT : MVT::integer_valuetypes()) {
157 setOperationAction(ISD::CTPOP, VT, Expand);
158 setOperationAction(ISD::CTLZ, VT, Expand);
159 setOperationAction(ISD::CTTZ, VT, Expand);
162 for (MVT VT : MVT::integer_valuetypes()) {
163 setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand);
164 // TODO: The generated code is pretty poor. Investigate using the
165 // same "shift and subtract with carry" trick that we do for
166 // extending 8-bit to 16-bit. This may require infrastructure
167 // improvements in how we treat 16-bit "registers" to be feasible.
170 // Division rtlib functions (not supported)
171 setLibcallName(RTLIB::SDIV_I8, nullptr);
172 setLibcallName(RTLIB::SDIV_I16, nullptr);
173 setLibcallName(RTLIB::SDIV_I32, nullptr);
174 setLibcallName(RTLIB::SDIV_I64, nullptr);
175 setLibcallName(RTLIB::SDIV_I128, nullptr);
176 setLibcallName(RTLIB::UDIV_I8, nullptr);
177 setLibcallName(RTLIB::UDIV_I16, nullptr);
178 setLibcallName(RTLIB::UDIV_I32, nullptr);
179 setLibcallName(RTLIB::UDIV_I64, nullptr);
180 setLibcallName(RTLIB::UDIV_I128, nullptr);
182 // Modulus rtlib functions (not supported)
183 setLibcallName(RTLIB::SREM_I8, nullptr);
184 setLibcallName(RTLIB::SREM_I16, nullptr);
185 setLibcallName(RTLIB::SREM_I32, nullptr);
186 setLibcallName(RTLIB::SREM_I64, nullptr);
187 setLibcallName(RTLIB::SREM_I128, nullptr);
188 setLibcallName(RTLIB::UREM_I8, nullptr);
189 setLibcallName(RTLIB::UREM_I16, nullptr);
190 setLibcallName(RTLIB::UREM_I32, nullptr);
191 setLibcallName(RTLIB::UREM_I64, nullptr);
192 setLibcallName(RTLIB::UREM_I128, nullptr);
194 // Division and modulus rtlib functions
195 setLibcallName(RTLIB::SDIVREM_I8, "__divmodqi4");
196 setLibcallName(RTLIB::SDIVREM_I16, "__divmodhi4");
197 setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4");
198 setLibcallName(RTLIB::SDIVREM_I64, "__divmoddi4");
199 setLibcallName(RTLIB::SDIVREM_I128, "__divmodti4");
200 setLibcallName(RTLIB::UDIVREM_I8, "__udivmodqi4");
201 setLibcallName(RTLIB::UDIVREM_I16, "__udivmodhi4");
202 setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4");
203 setLibcallName(RTLIB::UDIVREM_I64, "__udivmoddi4");
204 setLibcallName(RTLIB::UDIVREM_I128, "__udivmodti4");
206 // Several of the runtime library functions use a special calling conv
207 setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::AVR_BUILTIN);
208 setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::AVR_BUILTIN);
209 setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::AVR_BUILTIN);
210 setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::AVR_BUILTIN);
212 // Trigonometric rtlib functions
213 setLibcallName(RTLIB::SIN_F32, "sin");
214 setLibcallName(RTLIB::COS_F32, "cos");
216 setMinFunctionAlignment(1);
217 setMinimumJumpTableEntries(INT_MAX);
220 const char *AVRTargetLowering::getTargetNodeName(unsigned Opcode) const {
249 EVT AVRTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &,
251 assert(!VT.isVector() && "No AVR SetCC type for vectors!");
255 SDValue AVRTargetLowering::LowerShifts(SDValue Op, SelectionDAG &DAG) const {
256 //:TODO: this function has to be completely rewritten to produce optimal
257 // code, for now it's producing very long but correct code.
259 const SDNode *N = Op.getNode();
260 EVT VT = Op.getValueType();
263 // Expand non-constant shifts to loops.
264 if (!isa<ConstantSDNode>(N->getOperand(1))) {
265 switch (Op.getOpcode()) {
267 llvm_unreachable("Invalid shift opcode!");
269 return DAG.getNode(AVRISD::LSLLOOP, dl, VT, N->getOperand(0),
272 return DAG.getNode(AVRISD::LSRLOOP, dl, VT, N->getOperand(0),
275 return DAG.getNode(AVRISD::ASRLOOP, dl, VT, N->getOperand(0),
280 uint64_t ShiftAmount = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
281 SDValue Victim = N->getOperand(0);
283 switch (Op.getOpcode()) {
300 llvm_unreachable("Invalid shift opcode");
303 while (ShiftAmount--) {
304 Victim = DAG.getNode(Opc8, dl, VT, Victim);
310 SDValue AVRTargetLowering::LowerDivRem(SDValue Op, SelectionDAG &DAG) const {
311 unsigned Opcode = Op->getOpcode();
312 assert((Opcode == ISD::SDIVREM || Opcode == ISD::UDIVREM) &&
313 "Invalid opcode for Div/Rem lowering");
314 bool isSigned = (Opcode == ISD::SDIVREM);
315 EVT VT = Op->getValueType(0);
316 Type *Ty = VT.getTypeForEVT(*DAG.getContext());
319 switch (VT.getSimpleVT().SimpleTy) {
321 llvm_unreachable("Unexpected request for libcall!");
323 LC = isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
326 LC = isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
329 LC = isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
332 LC = isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
336 SDValue InChain = DAG.getEntryNode();
338 TargetLowering::ArgListTy Args;
339 TargetLowering::ArgListEntry Entry;
340 for (SDValue const &Value : Op->op_values()) {
342 Entry.Ty = Value.getValueType().getTypeForEVT(*DAG.getContext());
343 Entry.isSExt = isSigned;
344 Entry.isZExt = !isSigned;
345 Args.push_back(Entry);
348 SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC),
349 getPointerTy(DAG.getDataLayout()));
351 Type *RetTy = (Type *)StructType::get(Ty, Ty, nullptr);
354 TargetLowering::CallLoweringInfo CLI(DAG);
357 .setCallee(getLibcallCallingConv(LC), RetTy, Callee, std::move(Args))
359 .setSExtResult(isSigned)
360 .setZExtResult(!isSigned);
362 std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI);
363 return CallInfo.first;
366 SDValue AVRTargetLowering::LowerGlobalAddress(SDValue Op,
367 SelectionDAG &DAG) const {
368 auto DL = DAG.getDataLayout();
370 const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
371 int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
373 // Create the TargetGlobalAddress node, folding in the constant offset.
375 DAG.getTargetGlobalAddress(GV, SDLoc(Op), getPointerTy(DL), Offset);
376 return DAG.getNode(AVRISD::WRAPPER, SDLoc(Op), getPointerTy(DL), Result);
379 SDValue AVRTargetLowering::LowerBlockAddress(SDValue Op,
380 SelectionDAG &DAG) const {
381 auto DL = DAG.getDataLayout();
382 const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
384 SDValue Result = DAG.getTargetBlockAddress(BA, getPointerTy(DL));
386 return DAG.getNode(AVRISD::WRAPPER, SDLoc(Op), getPointerTy(DL), Result);
389 /// IntCCToAVRCC - Convert a DAG integer condition code to an AVR CC.
390 static AVRCC::CondCodes intCCToAVRCC(ISD::CondCode CC) {
393 llvm_unreachable("Unknown condition code!");
395 return AVRCC::COND_EQ;
397 return AVRCC::COND_NE;
399 return AVRCC::COND_GE;
401 return AVRCC::COND_LT;
403 return AVRCC::COND_SH;
405 return AVRCC::COND_LO;
409 /// Returns appropriate AVR CMP/CMPC nodes and corresponding condition code for
410 /// the given operands.
411 SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
412 SDValue &AVRcc, SelectionDAG &DAG,
415 EVT VT = LHS.getValueType();
416 bool UseTest = false;
422 // Swap operands and reverse the branching condition.
428 if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS)) {
429 switch (C->getSExtValue()) {
431 // When doing lhs > -1 use a tst instruction on the top part of lhs
432 // and use brpl instead of using a chain of cp/cpc.
434 AVRcc = DAG.getConstant(AVRCC::COND_PL, DL, MVT::i8);
438 // Turn lhs > 0 into 0 < lhs since 0 can be materialized with
439 // __zero_reg__ in lhs.
441 LHS = DAG.getConstant(0, DL, VT);
446 // Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows
447 // us to fold the constant into the cmp instruction.
448 RHS = DAG.getConstant(C->getSExtValue() + 1, DL, VT);
455 // Swap operands and reverse the branching condition.
461 if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS)) {
462 switch (C->getSExtValue()) {
464 // Turn lhs < 1 into 0 >= lhs since 0 can be materialized with
465 // __zero_reg__ in lhs.
467 LHS = DAG.getConstant(0, DL, VT);
472 // When doing lhs < 0 use a tst instruction on the top part of lhs
473 // and use brmi instead of using a chain of cp/cpc.
475 AVRcc = DAG.getConstant(AVRCC::COND_MI, DL, MVT::i8);
483 // Swap operands and reverse the branching condition.
489 // Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows us to
490 // fold the constant into the cmp instruction.
491 if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS)) {
492 RHS = DAG.getConstant(C->getSExtValue() + 1, DL, VT);
496 // Swap operands and reverse the branching condition.
503 // Expand 32 and 64 bit comparisons with custom CMP and CMPC nodes instead of
504 // using the default and/or/xor expansion code which is much longer.
505 if (VT == MVT::i32) {
506 SDValue LHSlo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS,
507 DAG.getIntPtrConstant(0, DL));
508 SDValue LHShi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS,
509 DAG.getIntPtrConstant(1, DL));
510 SDValue RHSlo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS,
511 DAG.getIntPtrConstant(0, DL));
512 SDValue RHShi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS,
513 DAG.getIntPtrConstant(1, DL));
516 // When using tst we only care about the highest part.
517 SDValue Top = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, LHShi,
518 DAG.getIntPtrConstant(1, DL));
519 Cmp = DAG.getNode(AVRISD::TST, DL, MVT::Glue, Top);
521 Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHSlo, RHSlo);
522 Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHShi, RHShi, Cmp);
524 } else if (VT == MVT::i64) {
525 SDValue LHS_0 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, LHS,
526 DAG.getIntPtrConstant(0, DL));
527 SDValue LHS_1 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, LHS,
528 DAG.getIntPtrConstant(1, DL));
530 SDValue LHS0 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS_0,
531 DAG.getIntPtrConstant(0, DL));
532 SDValue LHS1 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS_0,
533 DAG.getIntPtrConstant(1, DL));
534 SDValue LHS2 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS_1,
535 DAG.getIntPtrConstant(0, DL));
536 SDValue LHS3 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, LHS_1,
537 DAG.getIntPtrConstant(1, DL));
539 SDValue RHS_0 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, RHS,
540 DAG.getIntPtrConstant(0, DL));
541 SDValue RHS_1 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, RHS,
542 DAG.getIntPtrConstant(1, DL));
544 SDValue RHS0 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS_0,
545 DAG.getIntPtrConstant(0, DL));
546 SDValue RHS1 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS_0,
547 DAG.getIntPtrConstant(1, DL));
548 SDValue RHS2 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS_1,
549 DAG.getIntPtrConstant(0, DL));
550 SDValue RHS3 = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i16, RHS_1,
551 DAG.getIntPtrConstant(1, DL));
554 // When using tst we only care about the highest part.
555 SDValue Top = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8, LHS3,
556 DAG.getIntPtrConstant(1, DL));
557 Cmp = DAG.getNode(AVRISD::TST, DL, MVT::Glue, Top);
559 Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHS0, RHS0);
560 Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS1, RHS1, Cmp);
561 Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS2, RHS2, Cmp);
562 Cmp = DAG.getNode(AVRISD::CMPC, DL, MVT::Glue, LHS3, RHS3, Cmp);
564 } else if (VT == MVT::i8 || VT == MVT::i16) {
566 // When using tst we only care about the highest part.
567 Cmp = DAG.getNode(AVRISD::TST, DL, MVT::Glue,
570 : DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i8,
571 LHS, DAG.getIntPtrConstant(1, DL)));
573 Cmp = DAG.getNode(AVRISD::CMP, DL, MVT::Glue, LHS, RHS);
576 llvm_unreachable("Invalid comparison size");
579 // When using a test instruction AVRcc is already set.
581 AVRcc = DAG.getConstant(intCCToAVRCC(CC), DL, MVT::i8);
587 SDValue AVRTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
588 SDValue Chain = Op.getOperand(0);
589 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
590 SDValue LHS = Op.getOperand(2);
591 SDValue RHS = Op.getOperand(3);
592 SDValue Dest = Op.getOperand(4);
596 SDValue Cmp = getAVRCmp(LHS, RHS, CC, TargetCC, DAG, dl);
598 return DAG.getNode(AVRISD::BRCOND, dl, MVT::Other, Chain, Dest, TargetCC,
602 SDValue AVRTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
603 SDValue LHS = Op.getOperand(0);
604 SDValue RHS = Op.getOperand(1);
605 SDValue TrueV = Op.getOperand(2);
606 SDValue FalseV = Op.getOperand(3);
607 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
611 SDValue Cmp = getAVRCmp(LHS, RHS, CC, TargetCC, DAG, dl);
613 SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
614 SDValue Ops[] = {TrueV, FalseV, TargetCC, Cmp};
616 return DAG.getNode(AVRISD::SELECT_CC, dl, VTs, Ops);
619 SDValue AVRTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
620 SDValue LHS = Op.getOperand(0);
621 SDValue RHS = Op.getOperand(1);
622 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
626 SDValue Cmp = getAVRCmp(LHS, RHS, CC, TargetCC, DAG, DL);
628 SDValue TrueV = DAG.getConstant(1, DL, Op.getValueType());
629 SDValue FalseV = DAG.getConstant(0, DL, Op.getValueType());
630 SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
631 SDValue Ops[] = {TrueV, FalseV, TargetCC, Cmp};
633 return DAG.getNode(AVRISD::SELECT_CC, DL, VTs, Ops);
636 SDValue AVRTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const {
637 const MachineFunction &MF = DAG.getMachineFunction();
638 const AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
639 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
640 auto DL = DAG.getDataLayout();
643 // Vastart just stores the address of the VarArgsFrameIndex slot into the
644 // memory location argument.
645 SDValue FI = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), getPointerTy(DL));
647 return DAG.getStore(Op.getOperand(0), dl, FI, Op.getOperand(1),
648 MachinePointerInfo(SV), 0);
651 SDValue AVRTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
652 switch (Op.getOpcode()) {
654 llvm_unreachable("Don't know how to custom lower this!");
660 return LowerShifts(Op, DAG);
661 case ISD::GlobalAddress:
662 return LowerGlobalAddress(Op, DAG);
663 case ISD::BlockAddress:
664 return LowerBlockAddress(Op, DAG);
666 return LowerBR_CC(Op, DAG);
668 return LowerSELECT_CC(Op, DAG);
670 return LowerSETCC(Op, DAG);
672 return LowerVASTART(Op, DAG);
675 return LowerDivRem(Op, DAG);
681 /// Replace a node with an illegal result type
682 /// with a new node built out of custom code.
683 void AVRTargetLowering::ReplaceNodeResults(SDNode *N,
684 SmallVectorImpl<SDValue> &Results,
685 SelectionDAG &DAG) const {
688 switch (N->getOpcode()) {
690 // Convert add (x, imm) into sub (x, -imm).
691 if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
692 SDValue Sub = DAG.getNode(
693 ISD::SUB, DL, N->getValueType(0), N->getOperand(0),
694 DAG.getConstant(-C->getAPIntValue(), DL, C->getValueType(0)));
695 Results.push_back(Sub);
700 SDValue Res = LowerOperation(SDValue(N, 0), DAG);
702 for (unsigned I = 0, E = Res->getNumValues(); I != E; ++I)
703 Results.push_back(Res.getValue(I));
710 /// Return true if the addressing mode represented
711 /// by AM is legal for this target, for a load/store of the specified type.
712 bool AVRTargetLowering::isLegalAddressingMode(const DataLayout &DL,
713 const AddrMode &AM, Type *Ty,
715 int64_t Offs = AM.BaseOffs;
717 // Allow absolute addresses.
718 if (AM.BaseGV && !AM.HasBaseReg && AM.Scale == 0 && Offs == 0) {
722 // Flash memory instructions only allow zero offsets.
723 if (isa<PointerType>(Ty) && AS == AVR::ProgramMemory) {
727 // Allow reg+<6bit> offset.
730 if (AM.BaseGV == 0 && AM.HasBaseReg && AM.Scale == 0 && isUInt<6>(Offs)) {
737 /// Returns true by value, base pointer and
738 /// offset pointer and addressing mode by reference if the node's address
739 /// can be legally represented as pre-indexed load / store address.
740 bool AVRTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base,
742 ISD::MemIndexedMode &AM,
743 SelectionDAG &DAG) const {
748 if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
749 VT = LD->getMemoryVT();
750 Op = LD->getBasePtr().getNode();
751 if (LD->getExtensionType() != ISD::NON_EXTLOAD)
753 if (AVR::isProgramMemoryAccess(LD)) {
756 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
757 VT = ST->getMemoryVT();
758 Op = ST->getBasePtr().getNode();
759 if (AVR::isProgramMemoryAccess(ST)) {
766 if (VT != MVT::i8 && VT != MVT::i16) {
770 if (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB) {
774 if (const ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
775 int RHSC = RHS->getSExtValue();
776 if (Op->getOpcode() == ISD::SUB)
779 if ((VT == MVT::i16 && RHSC != -2) || (VT == MVT::i8 && RHSC != -1)) {
783 Base = Op->getOperand(0);
784 Offset = DAG.getConstant(RHSC, DL, MVT::i8);
793 /// Returns true by value, base pointer and
794 /// offset pointer and addressing mode by reference if this node can be
795 /// combined with a load / store to form a post-indexed load / store.
796 bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
799 ISD::MemIndexedMode &AM,
800 SelectionDAG &DAG) const {
804 if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
805 VT = LD->getMemoryVT();
806 if (LD->getExtensionType() != ISD::NON_EXTLOAD)
808 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
809 VT = ST->getMemoryVT();
810 if (AVR::isProgramMemoryAccess(ST)) {
817 if (VT != MVT::i8 && VT != MVT::i16) {
821 if (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB) {
825 if (const ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
826 int RHSC = RHS->getSExtValue();
827 if (Op->getOpcode() == ISD::SUB)
829 if ((VT == MVT::i16 && RHSC != 2) || (VT == MVT::i8 && RHSC != 1)) {
833 Base = Op->getOperand(0);
834 Offset = DAG.getConstant(RHSC, DL, MVT::i8);
843 bool AVRTargetLowering::isOffsetFoldingLegal(
844 const GlobalAddressSDNode *GA) const {
848 //===----------------------------------------------------------------------===//
849 // Formal Arguments Calling Convention Implementation
850 //===----------------------------------------------------------------------===//
852 #include "AVRGenCallingConv.inc"
854 /// For each argument in a function store the number of pieces it is composed
856 static void parseFunctionArgs(const Function *F, const DataLayout *TD,
857 SmallVectorImpl<unsigned> &Out) {
858 for (Argument const &Arg : F->args()) {
859 unsigned Bytes = (TD->getTypeSizeInBits(Arg.getType()) + 7) / 8;
860 Out.push_back((Bytes + 1) / 2);
864 /// For external symbols there is no function prototype information so we
865 /// have to rely directly on argument sizes.
866 static void parseExternFuncCallArgs(const SmallVectorImpl<ISD::OutputArg> &In,
867 SmallVectorImpl<unsigned> &Out) {
868 for (unsigned i = 0, e = In.size(); i != e;) {
871 while ((i != e) && (In[i].PartOffset == Offset)) {
872 Offset += In[i].VT.getStoreSize();
880 static StringRef getFunctionName(TargetLowering::CallLoweringInfo &CLI) {
881 SDValue Callee = CLI.Callee;
883 if (const ExternalSymbolSDNode *G = dyn_cast<ExternalSymbolSDNode>(Callee)) {
884 return G->getSymbol();
887 if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
888 return G->getGlobal()->getName();
891 llvm_unreachable("don't know how to get the name for this callee");
894 /// Analyze incoming and outgoing function arguments. We need custom C++ code
895 /// to handle special constraints in the ABI like reversing the order of the
896 /// pieces of splitted arguments. In addition, all pieces of a certain argument
897 /// have to be passed either using registers or the stack but never mixing both.
898 static void analyzeStandardArguments(TargetLowering::CallLoweringInfo *CLI,
899 const Function *F, const DataLayout *TD,
900 const SmallVectorImpl<ISD::OutputArg> *Outs,
901 const SmallVectorImpl<ISD::InputArg> *Ins,
902 CallingConv::ID CallConv,
903 SmallVectorImpl<CCValAssign> &ArgLocs,
904 CCState &CCInfo, bool IsCall, bool IsVarArg) {
905 static const MCPhysReg RegList8[] = {AVR::R24, AVR::R22, AVR::R20,
906 AVR::R18, AVR::R16, AVR::R14,
907 AVR::R12, AVR::R10, AVR::R8};
908 static const MCPhysReg RegList16[] = {AVR::R25R24, AVR::R23R22, AVR::R21R20,
909 AVR::R19R18, AVR::R17R16, AVR::R15R14,
910 AVR::R13R12, AVR::R11R10, AVR::R9R8};
912 // Variadic functions do not need all the analisys below.
914 CCInfo.AnalyzeCallOperands(*Outs, ArgCC_AVR_Vararg);
916 CCInfo.AnalyzeFormalArguments(*Ins, ArgCC_AVR_Vararg);
921 // Fill in the Args array which will contain original argument sizes.
922 SmallVector<unsigned, 8> Args;
924 parseExternFuncCallArgs(*Outs, Args);
926 assert(F != nullptr && "function should not be null");
927 parseFunctionArgs(F, TD, Args);
930 unsigned RegsLeft = array_lengthof(RegList8), ValNo = 0;
931 // Variadic functions always use the stack.
932 bool UsesStack = false;
933 for (unsigned i = 0, pos = 0, e = Args.size(); i != e; ++i) {
934 unsigned Size = Args[i];
935 MVT LocVT = (IsCall) ? (*Outs)[pos].VT : (*Ins)[pos].VT;
937 // If we have plenty of regs to pass the whole argument do it.
938 if (!UsesStack && (Size <= RegsLeft)) {
939 const MCPhysReg *RegList = (LocVT == MVT::i16) ? RegList16 : RegList8;
941 for (unsigned j = 0; j != Size; ++j) {
942 unsigned Reg = CCInfo.AllocateReg(
943 ArrayRef<MCPhysReg>(RegList, array_lengthof(RegList8)));
945 CCValAssign::getReg(ValNo++, LocVT, Reg, LocVT, CCValAssign::Full));
949 // Reverse the order of the pieces to agree with the "big endian" format
950 // required in the calling convention ABI.
951 std::reverse(ArgLocs.begin() + pos, ArgLocs.begin() + pos + Size);
953 // Pass the rest of arguments using the stack.
955 for (unsigned j = 0; j != Size; ++j) {
956 unsigned Offset = CCInfo.AllocateStack(
957 TD->getTypeAllocSize(EVT(LocVT).getTypeForEVT(CCInfo.getContext())),
958 TD->getABITypeAlignment(
959 EVT(LocVT).getTypeForEVT(CCInfo.getContext())));
960 CCInfo.addLoc(CCValAssign::getMem(ValNo++, LocVT, Offset, LocVT,
968 static void analyzeBuiltinArguments(TargetLowering::CallLoweringInfo &CLI,
969 const Function *F, const DataLayout *TD,
970 const SmallVectorImpl<ISD::OutputArg> *Outs,
971 const SmallVectorImpl<ISD::InputArg> *Ins,
972 CallingConv::ID CallConv,
973 SmallVectorImpl<CCValAssign> &ArgLocs,
974 CCState &CCInfo, bool IsCall, bool IsVarArg) {
975 StringRef FuncName = getFunctionName(CLI);
977 if (FuncName.startswith("__udivmod") || FuncName.startswith("__divmod")) {
978 CCInfo.AnalyzeCallOperands(*Outs, ArgCC_AVR_BUILTIN_DIV);
980 analyzeStandardArguments(&CLI, F, TD, Outs, Ins,
981 CallConv, ArgLocs, CCInfo,
986 static void analyzeArguments(TargetLowering::CallLoweringInfo *CLI,
987 const Function *F, const DataLayout *TD,
988 const SmallVectorImpl<ISD::OutputArg> *Outs,
989 const SmallVectorImpl<ISD::InputArg> *Ins,
990 CallingConv::ID CallConv,
991 SmallVectorImpl<CCValAssign> &ArgLocs,
992 CCState &CCInfo, bool IsCall, bool IsVarArg) {
994 case CallingConv::AVR_BUILTIN: {
995 analyzeBuiltinArguments(*CLI, F, TD, Outs, Ins,
996 CallConv, ArgLocs, CCInfo,
1001 analyzeStandardArguments(CLI, F, TD, Outs, Ins,
1002 CallConv, ArgLocs, CCInfo,
1009 SDValue AVRTargetLowering::LowerFormalArguments(
1010 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1011 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, SelectionDAG &DAG,
1012 SmallVectorImpl<SDValue> &InVals) const {
1013 MachineFunction &MF = DAG.getMachineFunction();
1014 MachineFrameInfo &MFI = MF.getFrameInfo();
1015 auto DL = DAG.getDataLayout();
1017 // Assign locations to all of the incoming arguments.
1018 SmallVector<CCValAssign, 16> ArgLocs;
1019 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
1022 analyzeArguments(nullptr, MF.getFunction(), &DL, 0, &Ins, CallConv, ArgLocs, CCInfo,
1026 for (CCValAssign &VA : ArgLocs) {
1028 // Arguments stored on registers.
1029 if (VA.isRegLoc()) {
1030 EVT RegVT = VA.getLocVT();
1031 const TargetRegisterClass *RC;
1032 if (RegVT == MVT::i8) {
1033 RC = &AVR::GPR8RegClass;
1034 } else if (RegVT == MVT::i16) {
1035 RC = &AVR::DREGSRegClass;
1037 llvm_unreachable("Unknown argument type!");
1040 unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC);
1041 ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT);
1043 // :NOTE: Clang should not promote any i8 into i16 but for safety the
1044 // following code will handle zexts or sexts generated by other
1045 // front ends. Otherwise:
1046 // If this is an 8 bit value, it is really passed promoted
1047 // to 16 bits. Insert an assert[sz]ext to capture this, then
1048 // truncate to the right size.
1049 switch (VA.getLocInfo()) {
1051 llvm_unreachable("Unknown loc info!");
1052 case CCValAssign::Full:
1054 case CCValAssign::BCvt:
1055 ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue);
1057 case CCValAssign::SExt:
1058 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
1059 DAG.getValueType(VA.getValVT()));
1060 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
1062 case CCValAssign::ZExt:
1063 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
1064 DAG.getValueType(VA.getValVT()));
1065 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
1069 InVals.push_back(ArgValue);
1072 assert(VA.isMemLoc());
1074 EVT LocVT = VA.getLocVT();
1076 // Create the frame index object for this incoming parameter.
1077 int FI = MFI.CreateFixedObject(LocVT.getSizeInBits() / 8,
1078 VA.getLocMemOffset(), true);
1080 // Create the SelectionDAG nodes corresponding to a load
1081 // from this parameter.
1082 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DL));
1083 InVals.push_back(DAG.getLoad(LocVT, dl, Chain, FIN,
1084 MachinePointerInfo::getFixedStack(MF, FI),
1089 // If the function takes variable number of arguments, make a frame index for
1090 // the start of the first vararg value... for expansion of llvm.va_start.
1092 unsigned StackSize = CCInfo.getNextStackOffset();
1093 AVRMachineFunctionInfo *AFI = MF.getInfo<AVRMachineFunctionInfo>();
1095 AFI->setVarArgsFrameIndex(MFI.CreateFixedObject(2, StackSize, true));
1101 //===----------------------------------------------------------------------===//
1102 // Call Calling Convention Implementation
1103 //===----------------------------------------------------------------------===//
1105 SDValue AVRTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
1106 SmallVectorImpl<SDValue> &InVals) const {
1107 SelectionDAG &DAG = CLI.DAG;
1109 SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs;
1110 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
1111 SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
1112 SDValue Chain = CLI.Chain;
1113 SDValue Callee = CLI.Callee;
1114 bool &isTailCall = CLI.IsTailCall;
1115 CallingConv::ID CallConv = CLI.CallConv;
1116 bool isVarArg = CLI.IsVarArg;
1118 MachineFunction &MF = DAG.getMachineFunction();
1120 // AVR does not yet support tail call optimization.
1123 // Analyze operands of the call, assigning locations to each operand.
1124 SmallVector<CCValAssign, 16> ArgLocs;
1125 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
1128 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
1129 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
1130 // node so that legalize doesn't hack it.
1131 const Function *F = nullptr;
1132 if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
1133 const GlobalValue *GV = G->getGlobal();
1135 F = cast<Function>(GV);
1137 DAG.getTargetGlobalAddress(GV, DL, getPointerTy(DAG.getDataLayout()));
1138 } else if (const ExternalSymbolSDNode *ES =
1139 dyn_cast<ExternalSymbolSDNode>(Callee)) {
1140 Callee = DAG.getTargetExternalSymbol(ES->getSymbol(),
1141 getPointerTy(DAG.getDataLayout()));
1144 analyzeArguments(&CLI, F, &DAG.getDataLayout(), &Outs, 0, CallConv, ArgLocs, CCInfo,
1147 // Get a count of how many bytes are to be pushed on the stack.
1148 unsigned NumBytes = CCInfo.getNextStackOffset();
1150 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, DL, true),
1153 SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass;
1155 // First, walk the register assignments, inserting copies.
1157 bool HasStackArgs = false;
1158 for (AI = 0, AE = ArgLocs.size(); AI != AE; ++AI) {
1159 CCValAssign &VA = ArgLocs[AI];
1160 EVT RegVT = VA.getLocVT();
1161 SDValue Arg = OutVals[AI];
1163 // Promote the value if needed. With Clang this should not happen.
1164 switch (VA.getLocInfo()) {
1166 llvm_unreachable("Unknown loc info!");
1167 case CCValAssign::Full:
1169 case CCValAssign::SExt:
1170 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, RegVT, Arg);
1172 case CCValAssign::ZExt:
1173 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, RegVT, Arg);
1175 case CCValAssign::AExt:
1176 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, RegVT, Arg);
1178 case CCValAssign::BCvt:
1179 Arg = DAG.getNode(ISD::BITCAST, DL, RegVT, Arg);
1183 // Stop when we encounter a stack argument, we need to process them
1184 // in reverse order in the loop below.
1185 if (VA.isMemLoc()) {
1186 HasStackArgs = true;
1190 // Arguments that can be passed on registers must be kept in the RegsToPass
1192 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
1195 // Second, stack arguments have to walked in reverse order by inserting
1196 // chained stores, this ensures their order is not changed by the scheduler
1197 // and that the push instruction sequence generated is correct, otherwise they
1198 // can be freely intermixed.
1200 for (AE = AI, AI = ArgLocs.size(); AI != AE; --AI) {
1201 unsigned Loc = AI - 1;
1202 CCValAssign &VA = ArgLocs[Loc];
1203 SDValue Arg = OutVals[Loc];
1205 assert(VA.isMemLoc());
1207 // SP points to one stack slot further so add one to adjust it.
1208 SDValue PtrOff = DAG.getNode(
1209 ISD::ADD, DL, getPointerTy(DAG.getDataLayout()),
1210 DAG.getRegister(AVR::SP, getPointerTy(DAG.getDataLayout())),
1211 DAG.getIntPtrConstant(VA.getLocMemOffset() + 1, DL));
1214 DAG.getStore(Chain, DL, Arg, PtrOff,
1215 MachinePointerInfo::getStack(MF, VA.getLocMemOffset()),
1220 // Build a sequence of copy-to-reg nodes chained together with token chain and
1221 // flag operands which copy the outgoing args into registers. The InFlag in
1222 // necessary since all emited instructions must be stuck together.
1224 for (auto Reg : RegsToPass) {
1225 Chain = DAG.getCopyToReg(Chain, DL, Reg.first, Reg.second, InFlag);
1226 InFlag = Chain.getValue(1);
1229 // Returns a chain & a flag for retval copy to use.
1230 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1231 SmallVector<SDValue, 8> Ops;
1232 Ops.push_back(Chain);
1233 Ops.push_back(Callee);
1235 // Add argument registers to the end of the list so that they are known live
1237 for (auto Reg : RegsToPass) {
1238 Ops.push_back(DAG.getRegister(Reg.first, Reg.second.getValueType()));
1241 // Add a register mask operand representing the call-preserved registers.
1242 const AVRTargetMachine &TM = (const AVRTargetMachine &)getTargetMachine();
1243 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
1244 const uint32_t *Mask =
1245 TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv);
1246 assert(Mask && "Missing call preserved mask for calling convention");
1247 Ops.push_back(DAG.getRegisterMask(Mask));
1249 if (InFlag.getNode()) {
1250 Ops.push_back(InFlag);
1253 Chain = DAG.getNode(AVRISD::CALL, DL, NodeTys, Ops);
1254 InFlag = Chain.getValue(1);
1256 // Create the CALLSEQ_END node.
1257 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, DL, true),
1258 DAG.getIntPtrConstant(0, DL, true), InFlag, DL);
1261 InFlag = Chain.getValue(1);
1264 // Handle result values, copying them out of physregs into vregs that we
1266 return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, DL, DAG,
1270 /// Lower the result values of a call into the
1271 /// appropriate copies out of appropriate physical registers.
1273 SDValue AVRTargetLowering::LowerCallResult(
1274 SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool isVarArg,
1275 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, SelectionDAG &DAG,
1276 SmallVectorImpl<SDValue> &InVals) const {
1278 // Assign locations to each value returned by this call.
1279 SmallVector<CCValAssign, 16> RVLocs;
1280 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
1283 // Handle runtime calling convs.
1284 auto CCFunction = CCAssignFnForReturn(CallConv);
1285 CCInfo.AnalyzeCallResult(Ins, CCFunction);
1287 if (CallConv != CallingConv::AVR_BUILTIN && RVLocs.size() > 1) {
1288 // Reverse splitted return values to get the "big endian" format required
1289 // to agree with the calling convention ABI.
1290 std::reverse(RVLocs.begin(), RVLocs.end());
1293 // Copy all of the result registers out of their specified physreg.
1294 for (CCValAssign const &RVLoc : RVLocs) {
1295 Chain = DAG.getCopyFromReg(Chain, dl, RVLoc.getLocReg(), RVLoc.getValVT(),
1298 InFlag = Chain.getValue(2);
1299 InVals.push_back(Chain.getValue(0));
1305 //===----------------------------------------------------------------------===//
1306 // Return Value Calling Convention Implementation
1307 //===----------------------------------------------------------------------===//
1309 CCAssignFn *AVRTargetLowering::CCAssignFnForReturn(CallingConv::ID CC) const {
1311 case CallingConv::AVR_BUILTIN:
1312 return RetCC_AVR_BUILTIN;
1319 AVRTargetLowering::CanLowerReturn(CallingConv::ID CallConv,
1320 MachineFunction &MF, bool isVarArg,
1321 const SmallVectorImpl<ISD::OutputArg> &Outs,
1322 LLVMContext &Context) const
1324 SmallVector<CCValAssign, 16> RVLocs;
1325 CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
1327 auto CCFunction = CCAssignFnForReturn(CallConv);
1328 return CCInfo.CheckReturn(Outs, CCFunction);
1332 AVRTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
1334 const SmallVectorImpl<ISD::OutputArg> &Outs,
1335 const SmallVectorImpl<SDValue> &OutVals,
1336 const SDLoc &dl, SelectionDAG &DAG) const {
1337 // CCValAssign - represent the assignment of the return value to locations.
1338 SmallVector<CCValAssign, 16> RVLocs;
1340 // CCState - Info about the registers and stack slot.
1341 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
1344 // Analyze return values.
1345 auto CCFunction = CCAssignFnForReturn(CallConv);
1346 CCInfo.AnalyzeReturn(Outs, CCFunction);
1348 // If this is the first return lowered for this function, add the regs to
1349 // the liveout set for the function.
1350 MachineFunction &MF = DAG.getMachineFunction();
1351 unsigned e = RVLocs.size();
1353 // Reverse splitted return values to get the "big endian" format required
1354 // to agree with the calling convention ABI.
1356 std::reverse(RVLocs.begin(), RVLocs.end());
1360 SmallVector<SDValue, 4> RetOps(1, Chain);
1361 // Copy the result values into the output registers.
1362 for (unsigned i = 0; i != e; ++i) {
1363 CCValAssign &VA = RVLocs[i];
1364 assert(VA.isRegLoc() && "Can only return in registers!");
1366 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag);
1368 // Guarantee that all emitted copies are stuck together with flags.
1369 Flag = Chain.getValue(1);
1370 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
1373 // Don't emit the ret/reti instruction when the naked attribute is present in
1374 // the function being compiled.
1375 if (MF.getFunction()->getAttributes().hasAttribute(
1376 AttributeSet::FunctionIndex, Attribute::Naked)) {
1381 (CallConv == CallingConv::AVR_INTR || CallConv == CallingConv::AVR_SIGNAL)
1385 RetOps[0] = Chain; // Update chain.
1387 if (Flag.getNode()) {
1388 RetOps.push_back(Flag);
1391 return DAG.getNode(RetOpc, dl, MVT::Other, RetOps);
1394 //===----------------------------------------------------------------------===//
1396 //===----------------------------------------------------------------------===//
1398 MachineBasicBlock *AVRTargetLowering::insertShift(MachineInstr &MI,
1399 MachineBasicBlock *BB) const {
1401 const TargetRegisterClass *RC;
1402 MachineFunction *F = BB->getParent();
1403 MachineRegisterInfo &RI = F->getRegInfo();
1404 const AVRTargetMachine &TM = (const AVRTargetMachine &)getTargetMachine();
1405 const TargetInstrInfo &TII = *TM.getSubtargetImpl()->getInstrInfo();
1406 DebugLoc dl = MI.getDebugLoc();
1408 switch (MI.getOpcode()) {
1410 llvm_unreachable("Invalid shift opcode!");
1413 RC = &AVR::GPR8RegClass;
1417 RC = &AVR::DREGSRegClass;
1421 RC = &AVR::GPR8RegClass;
1425 RC = &AVR::DREGSRegClass;
1429 RC = &AVR::GPR8RegClass;
1433 RC = &AVR::DREGSRegClass;
1437 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1438 MachineFunction::iterator I = BB->getParent()->begin();
1441 // Create loop block.
1442 MachineBasicBlock *LoopBB = F->CreateMachineBasicBlock(LLVM_BB);
1443 MachineBasicBlock *RemBB = F->CreateMachineBasicBlock(LLVM_BB);
1445 F->insert(I, LoopBB);
1446 F->insert(I, RemBB);
1448 // Update machine-CFG edges by transferring all successors of the current
1449 // block to the block containing instructions after shift.
1450 RemBB->splice(RemBB->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
1452 RemBB->transferSuccessorsAndUpdatePHIs(BB);
1454 // Add adges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB.
1455 BB->addSuccessor(LoopBB);
1456 BB->addSuccessor(RemBB);
1457 LoopBB->addSuccessor(RemBB);
1458 LoopBB->addSuccessor(LoopBB);
1460 unsigned ShiftAmtReg = RI.createVirtualRegister(&AVR::LD8RegClass);
1461 unsigned ShiftAmtReg2 = RI.createVirtualRegister(&AVR::LD8RegClass);
1462 unsigned ShiftReg = RI.createVirtualRegister(RC);
1463 unsigned ShiftReg2 = RI.createVirtualRegister(RC);
1464 unsigned ShiftAmtSrcReg = MI.getOperand(2).getReg();
1465 unsigned SrcReg = MI.getOperand(1).getReg();
1466 unsigned DstReg = MI.getOperand(0).getReg();
1471 BuildMI(BB, dl, TII.get(AVR::CPRdRr)).addReg(ShiftAmtSrcReg).addReg(AVR::R0);
1472 BuildMI(BB, dl, TII.get(AVR::BREQk)).addMBB(RemBB);
1475 // ShiftReg = phi [%SrcReg, BB], [%ShiftReg2, LoopBB]
1476 // ShiftAmt = phi [%N, BB], [%ShiftAmt2, LoopBB]
1477 // ShiftReg2 = shift ShiftReg
1478 // ShiftAmt2 = ShiftAmt - 1;
1479 BuildMI(LoopBB, dl, TII.get(AVR::PHI), ShiftReg)
1484 BuildMI(LoopBB, dl, TII.get(AVR::PHI), ShiftAmtReg)
1485 .addReg(ShiftAmtSrcReg)
1487 .addReg(ShiftAmtReg2)
1489 BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2).addReg(ShiftReg);
1490 BuildMI(LoopBB, dl, TII.get(AVR::SUBIRdK), ShiftAmtReg2)
1491 .addReg(ShiftAmtReg)
1493 BuildMI(LoopBB, dl, TII.get(AVR::BRNEk)).addMBB(LoopBB);
1496 // DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB]
1497 BuildMI(*RemBB, RemBB->begin(), dl, TII.get(AVR::PHI), DstReg)
1503 MI.eraseFromParent(); // The pseudo instruction is gone now.
1507 static bool isCopyMulResult(MachineBasicBlock::iterator const &I) {
1508 if (I->getOpcode() == AVR::COPY) {
1509 unsigned SrcReg = I->getOperand(1).getReg();
1510 return (SrcReg == AVR::R0 || SrcReg == AVR::R1);
1516 // The mul instructions wreak havock on our zero_reg R1. We need to clear it
1517 // after the result has been evacuated. This is probably not the best way to do
1518 // it, but it works for now.
1519 MachineBasicBlock *AVRTargetLowering::insertMul(MachineInstr &MI,
1520 MachineBasicBlock *BB) const {
1521 const AVRTargetMachine &TM = (const AVRTargetMachine &)getTargetMachine();
1522 const TargetInstrInfo &TII = *TM.getSubtargetImpl()->getInstrInfo();
1523 MachineBasicBlock::iterator I(MI);
1524 ++I; // in any case insert *after* the mul instruction
1525 if (isCopyMulResult(I))
1527 if (isCopyMulResult(I))
1529 BuildMI(*BB, I, MI.getDebugLoc(), TII.get(AVR::EORRdRr), AVR::R1)
1536 AVRTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
1537 MachineBasicBlock *MBB) const {
1538 int Opc = MI.getOpcode();
1540 // Pseudo shift instructions with a non constant shift amount are expanded
1549 return insertShift(MI, MBB);
1552 return insertMul(MI, MBB);
1555 assert((Opc == AVR::Select16 || Opc == AVR::Select8) &&
1556 "Unexpected instr type to insert");
1558 const AVRInstrInfo &TII = (const AVRInstrInfo &)*MI.getParent()
1562 DebugLoc dl = MI.getDebugLoc();
1564 // To "insert" a SELECT instruction, we insert the diamond
1565 // control-flow pattern. The incoming instruction knows the
1566 // destination vreg to set, the condition code register to branch
1567 // on, the true/false values to select between, and a branch opcode
1570 MachineFunction *MF = MBB->getParent();
1571 const BasicBlock *LLVM_BB = MBB->getBasicBlock();
1572 MachineBasicBlock *trueMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1573 MachineBasicBlock *falseMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1575 MachineFunction::iterator I = MBB->getParent()->begin();
1577 MF->insert(I, trueMBB);
1578 MF->insert(I, falseMBB);
1580 // Transfer remaining instructions and all successors of the current
1581 // block to the block which will contain the Phi node for the
1583 trueMBB->splice(trueMBB->begin(), MBB,
1584 std::next(MachineBasicBlock::iterator(MI)), MBB->end());
1585 trueMBB->transferSuccessorsAndUpdatePHIs(MBB);
1587 AVRCC::CondCodes CC = (AVRCC::CondCodes)MI.getOperand(3).getImm();
1588 BuildMI(MBB, dl, TII.getBrCond(CC)).addMBB(trueMBB);
1589 BuildMI(MBB, dl, TII.get(AVR::RJMPk)).addMBB(falseMBB);
1590 MBB->addSuccessor(falseMBB);
1591 MBB->addSuccessor(trueMBB);
1593 // Unconditionally flow back to the true block
1594 BuildMI(falseMBB, dl, TII.get(AVR::RJMPk)).addMBB(trueMBB);
1595 falseMBB->addSuccessor(trueMBB);
1597 // Set up the Phi node to determine where we came from
1598 BuildMI(*trueMBB, trueMBB->begin(), dl, TII.get(AVR::PHI), MI.getOperand(0).getReg())
1599 .addReg(MI.getOperand(1).getReg())
1601 .addReg(MI.getOperand(2).getReg())
1604 MI.eraseFromParent(); // The pseudo instruction is gone now.
1608 //===----------------------------------------------------------------------===//
1609 // Inline Asm Support
1610 //===----------------------------------------------------------------------===//
1612 AVRTargetLowering::ConstraintType
1613 AVRTargetLowering::getConstraintType(StringRef Constraint) const {
1614 if (Constraint.size() == 1) {
1615 // See http://www.nongnu.org/avr-libc/user-manual/inline_asm.html
1616 switch (Constraint[0]) {
1617 case 'a': // Simple upper registers
1618 case 'b': // Base pointer registers pairs
1619 case 'd': // Upper register
1620 case 'l': // Lower registers
1621 case 'e': // Pointer register pairs
1622 case 'q': // Stack pointer register
1623 case 'r': // Any register
1624 case 'w': // Special upper register pairs
1625 return C_RegisterClass;
1626 case 't': // Temporary register
1627 case 'x': case 'X': // Pointer register pair X
1628 case 'y': case 'Y': // Pointer register pair Y
1629 case 'z': case 'Z': // Pointer register pair Z
1631 case 'Q': // A memory address based on Y or Z pointer with displacement.
1633 case 'G': // Floating point constant
1634 case 'I': // 6-bit positive integer constant
1635 case 'J': // 6-bit negative integer constant
1636 case 'K': // Integer constant (Range: 2)
1637 case 'L': // Integer constant (Range: 0)
1638 case 'M': // 8-bit integer constant
1639 case 'N': // Integer constant (Range: -1)
1640 case 'O': // Integer constant (Range: 8, 16, 24)
1641 case 'P': // Integer constant (Range: 1)
1642 case 'R': // Integer constant (Range: -6 to 5)x
1649 return TargetLowering::getConstraintType(Constraint);
1653 AVRTargetLowering::getInlineAsmMemConstraint(StringRef ConstraintCode) const {
1654 // Not sure if this is actually the right thing to do, but we got to do
1655 // *something* [agnat]
1656 switch (ConstraintCode[0]) {
1658 return InlineAsm::Constraint_Q;
1660 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
1663 AVRTargetLowering::ConstraintWeight
1664 AVRTargetLowering::getSingleConstraintMatchWeight(
1665 AsmOperandInfo &info, const char *constraint) const {
1666 ConstraintWeight weight = CW_Invalid;
1667 Value *CallOperandVal = info.CallOperandVal;
1669 // If we don't have a value, we can't do a match,
1670 // but allow it at the lowest weight.
1671 // (this behaviour has been copied from the ARM backend)
1672 if (!CallOperandVal) {
1676 // Look at the constraint type.
1677 switch (*constraint) {
1679 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
1684 weight = CW_Register;
1695 weight = CW_SpecificReg;
1698 if (const ConstantFP *C = dyn_cast<ConstantFP>(CallOperandVal)) {
1700 weight = CW_Constant;
1705 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1706 if (isUInt<6>(C->getZExtValue())) {
1707 weight = CW_Constant;
1712 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1713 if ((C->getSExtValue() >= -63) && (C->getSExtValue() <= 0)) {
1714 weight = CW_Constant;
1719 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1720 if (C->getZExtValue() == 2) {
1721 weight = CW_Constant;
1726 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1727 if (C->getZExtValue() == 0) {
1728 weight = CW_Constant;
1733 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1734 if (isUInt<8>(C->getZExtValue())) {
1735 weight = CW_Constant;
1740 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1741 if (C->getSExtValue() == -1) {
1742 weight = CW_Constant;
1747 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1748 if ((C->getZExtValue() == 8) || (C->getZExtValue() == 16) ||
1749 (C->getZExtValue() == 24)) {
1750 weight = CW_Constant;
1755 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1756 if (C->getZExtValue() == 1) {
1757 weight = CW_Constant;
1762 if (const ConstantInt *C = dyn_cast<ConstantInt>(CallOperandVal)) {
1763 if ((C->getSExtValue() >= -6) && (C->getSExtValue() <= 5)) {
1764 weight = CW_Constant;
1776 std::pair<unsigned, const TargetRegisterClass *>
1777 AVRTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
1778 StringRef Constraint,
1780 auto STI = static_cast<const AVRTargetMachine &>(this->getTargetMachine())
1781 .getSubtargetImpl();
1783 // We only support i8 and i16.
1785 //:FIXME: remove this assert for now since it gets sometimes executed
1786 // assert((VT == MVT::i16 || VT == MVT::i8) && "Wrong operand type.");
1788 if (Constraint.size() == 1) {
1789 switch (Constraint[0]) {
1790 case 'a': // Simple upper registers r16..r23.
1791 return std::make_pair(0U, &AVR::LD8loRegClass);
1792 case 'b': // Base pointer registers: y, z.
1793 return std::make_pair(0U, &AVR::PTRDISPREGSRegClass);
1794 case 'd': // Upper registers r16..r31.
1795 return std::make_pair(0U, &AVR::LD8RegClass);
1796 case 'l': // Lower registers r0..r15.
1797 return std::make_pair(0U, &AVR::GPR8loRegClass);
1798 case 'e': // Pointer register pairs: x, y, z.
1799 return std::make_pair(0U, &AVR::PTRREGSRegClass);
1800 case 'q': // Stack pointer register: SPH:SPL.
1801 return std::make_pair(0U, &AVR::GPRSPRegClass);
1802 case 'r': // Any register: r0..r31.
1804 return std::make_pair(0U, &AVR::GPR8RegClass);
1806 assert(VT == MVT::i16 && "inline asm constraint too large");
1807 return std::make_pair(0U, &AVR::DREGSRegClass);
1808 case 't': // Temporary register: r0.
1809 return std::make_pair(unsigned(AVR::R0), &AVR::GPR8RegClass);
1810 case 'w': // Special upper register pairs: r24, r26, r28, r30.
1811 return std::make_pair(0U, &AVR::IWREGSRegClass);
1812 case 'x': // Pointer register pair X: r27:r26.
1814 return std::make_pair(unsigned(AVR::R27R26), &AVR::PTRREGSRegClass);
1815 case 'y': // Pointer register pair Y: r29:r28.
1817 return std::make_pair(unsigned(AVR::R29R28), &AVR::PTRREGSRegClass);
1818 case 'z': // Pointer register pair Z: r31:r30.
1820 return std::make_pair(unsigned(AVR::R31R30), &AVR::PTRREGSRegClass);
1826 return TargetLowering::getRegForInlineAsmConstraint(STI->getRegisterInfo(),
1830 void AVRTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
1831 std::string &Constraint,
1832 std::vector<SDValue> &Ops,
1833 SelectionDAG &DAG) const {
1834 SDValue Result(0, 0);
1836 EVT Ty = Op.getValueType();
1838 // Currently only support length 1 constraints.
1839 if (Constraint.length() != 1) {
1843 char ConstraintLetter = Constraint[0];
1844 switch (ConstraintLetter) {
1847 // Deal with integers first:
1857 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op);
1862 int64_t CVal64 = C->getSExtValue();
1863 uint64_t CUVal64 = C->getZExtValue();
1864 switch (ConstraintLetter) {
1866 if (!isUInt<6>(CUVal64))
1868 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1871 if (CVal64 < -63 || CVal64 > 0)
1873 Result = DAG.getTargetConstant(CVal64, DL, Ty);
1878 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1883 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1886 if (!isUInt<8>(CUVal64))
1888 // i8 type may be printed as a negative number,
1889 // e.g. 254 would be printed as -2,
1890 // so we force it to i16 at least.
1891 if (Ty.getSimpleVT() == MVT::i8) {
1894 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1899 Result = DAG.getTargetConstant(CVal64, DL, Ty);
1901 case 'O': // 8, 16, 24
1902 if (CUVal64 != 8 && CUVal64 != 16 && CUVal64 != 24)
1904 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1909 Result = DAG.getTargetConstant(CUVal64, DL, Ty);
1912 if (CVal64 < -6 || CVal64 > 5)
1914 Result = DAG.getTargetConstant(CVal64, DL, Ty);
1921 const ConstantFPSDNode *FC = dyn_cast<ConstantFPSDNode>(Op);
1922 if (!FC || !FC->isZero())
1924 // Soften float to i8 0
1925 Result = DAG.getTargetConstant(0, DL, MVT::i8);
1929 if (Result.getNode()) {
1930 Ops.push_back(Result);
1934 return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
1937 unsigned AVRTargetLowering::getRegisterByName(const char *RegName,
1939 SelectionDAG &DAG) const {
1942 if (VT == MVT::i8) {
1943 Reg = StringSwitch<unsigned>(RegName)
1944 .Case("r0", AVR::R0).Case("r1", AVR::R1).Case("r2", AVR::R2)
1945 .Case("r3", AVR::R3).Case("r4", AVR::R4).Case("r5", AVR::R5)
1946 .Case("r6", AVR::R6).Case("r7", AVR::R7).Case("r8", AVR::R8)
1947 .Case("r9", AVR::R9).Case("r10", AVR::R10).Case("r11", AVR::R11)
1948 .Case("r12", AVR::R12).Case("r13", AVR::R13).Case("r14", AVR::R14)
1949 .Case("r15", AVR::R15).Case("r16", AVR::R16).Case("r17", AVR::R17)
1950 .Case("r18", AVR::R18).Case("r19", AVR::R19).Case("r20", AVR::R20)
1951 .Case("r21", AVR::R21).Case("r22", AVR::R22).Case("r23", AVR::R23)
1952 .Case("r24", AVR::R24).Case("r25", AVR::R25).Case("r26", AVR::R26)
1953 .Case("r27", AVR::R27).Case("r28", AVR::R28).Case("r29", AVR::R29)
1954 .Case("r30", AVR::R30).Case("r31", AVR::R31)
1955 .Case("X", AVR::R27R26).Case("Y", AVR::R29R28).Case("Z", AVR::R31R30)
1958 Reg = StringSwitch<unsigned>(RegName)
1959 .Case("r0", AVR::R1R0).Case("r2", AVR::R3R2)
1960 .Case("r4", AVR::R5R4).Case("r6", AVR::R7R6)
1961 .Case("r8", AVR::R9R8).Case("r10", AVR::R11R10)
1962 .Case("r12", AVR::R13R12).Case("r14", AVR::R15R14)
1963 .Case("r16", AVR::R17R16).Case("r18", AVR::R19R18)
1964 .Case("r20", AVR::R21R20).Case("r22", AVR::R23R22)
1965 .Case("r24", AVR::R25R24).Case("r26", AVR::R27R26)
1966 .Case("r28", AVR::R29R28).Case("r30", AVR::R31R30)
1967 .Case("X", AVR::R27R26).Case("Y", AVR::R29R28).Case("Z", AVR::R31R30)
1974 report_fatal_error("Invalid register name global variable");
1977 } // end of namespace llvm