29 #define AVR_EXPAND_PSEUDO_NAME "AVR pseudo instruction expansion pass"
49 typedef Block::iterator BlockIt;
55 const unsigned SCRATCH_REGISTER = AVR::R0;
57 const unsigned SREG_ADDR = 0x3f;
59 bool expandMBB(Block &MBB);
60 bool expandMI(Block &MBB, BlockIt MBBI);
61 template <
unsigned OP>
bool expand(Block &MBB, BlockIt MBBI);
64 return BuildMI(MBB, MBBI, MBBI->getDebugLoc(),
TII->get(Opcode));
69 return BuildMI(MBB, MBBI, MBBI->getDebugLoc(),
TII->get(Opcode), DstReg);
74 bool expandArith(
unsigned OpLo,
unsigned OpHi, Block &MBB, BlockIt MBBI);
75 bool expandLogic(
unsigned Op, Block &MBB, BlockIt MBBI);
76 bool expandLogicImm(
unsigned Op, Block &MBB, BlockIt MBBI);
77 bool isLogicImmOpRedundant(
unsigned Op,
unsigned ImmVal)
const;
79 template<
typename Func>
80 bool expandAtomic(Block &MBB, BlockIt MBBI, Func f);
82 template<
typename Func>
83 bool expandAtomicBinaryOp(
unsigned Opcode, Block &MBB, BlockIt MBBI, Func f);
85 bool expandAtomicBinaryOp(
unsigned Opcode, Block &MBB, BlockIt MBBI);
87 bool expandAtomicArithmeticOp(
unsigned MemOpcode,
99 bool Modified =
false;
101 BlockIt MBBI = MBB.
begin(),
E = MBB.
end();
103 BlockIt NMBBI = std::next(MBBI);
104 Modified |= expandMI(MBB, MBBI);
112 bool Modified =
false;
121 for (Block &MBB : MF) {
122 bool ContinueExpanding =
true;
123 unsigned ExpandCount = 0;
127 assert(ExpandCount < 10 &&
"pseudo expand limit reached");
129 bool BlockModified = expandMBB(MBB);
130 Modified |= BlockModified;
133 ContinueExpanding = BlockModified;
134 }
while (ContinueExpanding);
140 bool AVRExpandPseudo::
141 expandArith(
unsigned OpLo,
unsigned OpHi, Block &MBB, BlockIt MBBI) {
143 unsigned SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
150 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
151 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
153 buildMI(MBB, MBBI, OpLo)
158 auto MIBHI = buildMI(MBB, MBBI, OpHi)
164 MIBHI->getOperand(3).setIsDead();
167 MIBHI->getOperand(4).setIsKill();
173 bool AVRExpandPseudo::
174 expandLogic(
unsigned Op, Block &MBB, BlockIt MBBI) {
176 unsigned SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
183 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
184 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
186 auto MIBLO = buildMI(MBB, MBBI, Op)
192 MIBLO->getOperand(3).setIsDead();
194 auto MIBHI = buildMI(MBB, MBBI, Op)
200 MIBHI->getOperand(3).setIsDead();
206 bool AVRExpandPseudo::
207 isLogicImmOpRedundant(
unsigned Op,
unsigned ImmVal)
const {
210 if (Op == AVR::ANDIRdK && ImmVal == 0xff)
214 if (Op == AVR::ORIRdK && ImmVal == 0x0)
220 bool AVRExpandPseudo::
221 expandLogicImm(
unsigned Op, Block &MBB, BlockIt MBBI) {
223 unsigned DstLoReg, DstHiReg;
229 unsigned Lo8 = Imm & 0xff;
230 unsigned Hi8 = (Imm >> 8) & 0xff;
231 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
233 if (!isLogicImmOpRedundant(Op, Lo8)) {
234 auto MIBLO = buildMI(MBB, MBBI, Op)
240 MIBLO->getOperand(3).setIsDead();
243 if (!isLogicImmOpRedundant(Op, Hi8)) {
244 auto MIBHI = buildMI(MBB, MBBI, Op)
250 MIBHI->getOperand(3).setIsDead();
258 bool AVRExpandPseudo::expand<AVR::ADDWRdRr>(Block &MBB, BlockIt MBBI) {
259 return expandArith(AVR::ADDRdRr, AVR::ADCRdRr, MBB, MBBI);
263 bool AVRExpandPseudo::expand<AVR::ADCWRdRr>(Block &MBB, BlockIt MBBI) {
264 return expandArith(AVR::ADCRdRr, AVR::ADCRdRr, MBB, MBBI);
268 bool AVRExpandPseudo::expand<AVR::SUBWRdRr>(Block &MBB, BlockIt MBBI) {
269 return expandArith(AVR::SUBRdRr, AVR::SBCRdRr, MBB, MBBI);
273 bool AVRExpandPseudo::expand<AVR::SUBIWRdK>(Block &MBB, BlockIt MBBI) {
275 unsigned DstLoReg, DstHiReg;
280 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
282 auto MIBLO = buildMI(MBB, MBBI, AVR::SUBIRdK)
286 auto MIBHI = buildMI(MBB, MBBI, AVR::SBCIRdK)
301 MIBLO.addImm(Imm & 0xff);
302 MIBHI.addImm((Imm >> 8) & 0xff);
310 MIBHI->getOperand(3).setIsDead();
313 MIBHI->getOperand(4).setIsKill();
320 bool AVRExpandPseudo::expand<AVR::SBCWRdRr>(Block &MBB, BlockIt MBBI) {
321 return expandArith(AVR::SBCRdRr, AVR::SBCRdRr, MBB, MBBI);
325 bool AVRExpandPseudo::expand<AVR::SBCIWRdK>(Block &MBB, BlockIt MBBI) {
327 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
333 unsigned Lo8 = Imm & 0xff;
334 unsigned Hi8 = (Imm >> 8) & 0xff;
337 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
339 auto MIBLO = buildMI(MBB, MBBI, OpLo)
345 MIBLO->getOperand(4).setIsKill();
347 auto MIBHI = buildMI(MBB, MBBI, OpHi)
353 MIBHI->getOperand(3).setIsDead();
356 MIBHI->getOperand(4).setIsKill();
363 bool AVRExpandPseudo::expand<AVR::ANDWRdRr>(Block &MBB, BlockIt MBBI) {
364 return expandLogic(AVR::ANDRdRr, MBB, MBBI);
368 bool AVRExpandPseudo::expand<AVR::ANDIWRdK>(Block &MBB, BlockIt MBBI) {
369 return expandLogicImm(AVR::ANDIRdK, MBB, MBBI);
373 bool AVRExpandPseudo::expand<AVR::ORWRdRr>(Block &MBB, BlockIt MBBI) {
374 return expandLogic(AVR::ORRdRr, MBB, MBBI);
378 bool AVRExpandPseudo::expand<AVR::ORIWRdK>(Block &MBB, BlockIt MBBI) {
379 return expandLogicImm(AVR::ORIRdK, MBB, MBBI);
383 bool AVRExpandPseudo::expand<AVR::EORWRdRr>(Block &MBB, BlockIt MBBI) {
384 return expandLogic(AVR::EORRdRr, MBB, MBBI);
388 bool AVRExpandPseudo::expand<AVR::COMWRd>(Block &MBB, BlockIt MBBI) {
390 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
397 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
399 auto MIBLO = buildMI(MBB, MBBI, OpLo)
404 MIBLO->getOperand(2).setIsDead();
406 auto MIBHI = buildMI(MBB, MBBI, OpHi)
411 MIBHI->getOperand(2).setIsDead();
418 bool AVRExpandPseudo::expand<AVR::CPWRdRr>(Block &MBB, BlockIt MBBI) {
420 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
428 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
429 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
432 buildMI(MBB, MBBI, OpLo)
436 auto MIBHI = buildMI(MBB, MBBI, OpHi)
441 MIBHI->getOperand(2).setIsDead();
444 MIBHI->getOperand(3).setIsKill();
451 bool AVRExpandPseudo::expand<AVR::CPCWRdRr>(Block &MBB, BlockIt MBBI) {
453 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
461 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
462 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
464 auto MIBLO = buildMI(MBB, MBBI, OpLo)
469 MIBLO->getOperand(3).setIsKill();
471 auto MIBHI = buildMI(MBB, MBBI, OpHi)
476 MIBHI->getOperand(2).setIsDead();
479 MIBHI->getOperand(3).setIsKill();
486 bool AVRExpandPseudo::expand<AVR::LDIWRdK>(Block &MBB, BlockIt MBBI) {
488 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
493 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
495 auto MIBLO = buildMI(MBB, MBBI, OpLo)
498 auto MIBHI = buildMI(MBB, MBBI, OpHi)
522 MIBLO.addImm(Imm & 0xff);
523 MIBHI.addImm((Imm >> 8) & 0xff);
535 bool AVRExpandPseudo::expand<AVR::LDSWRdK>(Block &MBB, BlockIt MBBI) {
537 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
542 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
544 auto MIBLO = buildMI(MBB, MBBI, OpLo)
547 auto MIBHI = buildMI(MBB, MBBI, OpHi)
556 MIBLO.addGlobalAddress(GV, Offs, TF);
557 MIBHI.addGlobalAddress(GV, Offs + 1, TF);
564 MIBHI.addImm(Imm + 1);
579 bool AVRExpandPseudo::expand<AVR::LDWRdPtr>(Block &MBB, BlockIt MBBI) {
581 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
587 OpHi = AVR::LDDRdPtrQ;
588 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
591 if (DstReg == SrcReg)
592 TmpReg = scavengeGPR8(MI);
594 unsigned CurDstLoReg = (DstReg == SrcReg) ? TmpReg : DstLoReg;
595 unsigned CurDstHiReg = (DstReg == SrcReg) ? TmpReg : DstHiReg;
598 auto MIBLO = buildMI(MBB, MBBI, OpLo)
604 buildMI(MBB, MBBI, AVR::PUSHRr).addReg(TmpReg);
607 auto MIBHI = buildMI(MBB, MBBI, OpHi)
614 buildMI(MBB, MBBI, AVR::MOVRdRr).addReg(DstHiReg).addReg(TmpReg);
617 buildMI(MBB, MBBI, AVR::POPRd).addReg(DstLoReg);
628 bool AVRExpandPseudo::expand<AVR::LDWRdPtrPi>(Block &MBB, BlockIt MBBI) {
630 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
635 OpLo = AVR::LDRdPtrPi;
636 OpHi = AVR::LDRdPtrPi;
637 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
639 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
641 auto MIBLO = buildMI(MBB, MBBI, OpLo)
646 auto MIBHI = buildMI(MBB, MBBI, OpHi)
659 bool AVRExpandPseudo::expand<AVR::LDWRdPtrPd>(Block &MBB, BlockIt MBBI) {
661 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
666 OpLo = AVR::LDRdPtrPd;
667 OpHi = AVR::LDRdPtrPd;
668 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
670 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
672 auto MIBHI = buildMI(MBB, MBBI, OpHi)
677 auto MIBLO = buildMI(MBB, MBBI, OpLo)
690 bool AVRExpandPseudo::expand<AVR::LDDWRdPtrQ>(Block &MBB, BlockIt MBBI) {
692 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
698 OpLo = AVR::LDDRdPtrQ;
699 OpHi = AVR::LDDRdPtrQ;
700 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
702 assert(Imm <= 63 &&
"Offset is out of range");
705 if (DstReg == SrcReg)
706 TmpReg = scavengeGPR8(MI);
708 unsigned CurDstLoReg = (DstReg == SrcReg) ? TmpReg : DstLoReg;
709 unsigned CurDstHiReg = (DstReg == SrcReg) ? TmpReg : DstHiReg;
712 auto MIBLO = buildMI(MBB, MBBI, OpLo)
719 buildMI(MBB, MBBI, AVR::PUSHRr).addReg(TmpReg);
722 auto MIBHI = buildMI(MBB, MBBI, OpHi)
729 buildMI(MBB, MBBI, AVR::MOVRdRr).addReg(DstHiReg).addReg(TmpReg);
732 buildMI(MBB, MBBI, AVR::POPRd).addReg(DstLoReg);
743 bool AVRExpandPseudo::expand<AVR::LPMWRdZ>(Block &MBB, BlockIt MBBI) {
748 bool AVRExpandPseudo::expand<AVR::LPMWRdZPi>(Block &MBB, BlockIt MBBI) {
752 template<
typename Func>
753 bool AVRExpandPseudo::expandAtomic(Block &MBB, BlockIt MBBI, Func f) {
758 buildMI(MBB, MBBI, AVR::INRdA)
763 buildMI(MBB, MBBI, AVR::BCLRs).addImm(7);
768 buildMI(MBB, MBBI, AVR::OUTARr)
770 .addReg(SCRATCH_REGISTER);
776 template<
typename Func>
777 bool AVRExpandPseudo::expandAtomicBinaryOp(
unsigned Opcode,
786 *buildMI(MBB, MBBI, Opcode).add(Op1).add(Op2).getInstr();
791 bool AVRExpandPseudo::expandAtomicBinaryOp(
unsigned Opcode,
794 return expandAtomicBinaryOp(Opcode, MBB, MBBI, [](
MachineInstr &
MI) {});
797 bool AVRExpandPseudo::expandAtomicArithmeticOp(
unsigned Width,
798 unsigned ArithOpcode,
805 unsigned LoadOpcode = (Width == 8) ? AVR::LDRdPtr : AVR::LDWRdPtr;
806 unsigned StoreOpcode = (Width == 8) ? AVR::STPtrRr : AVR::STWPtrRr;
809 buildMI(MBB, MBBI, LoadOpcode).add(Op1).add(Op2);
812 buildMI(MBB, MBBI, ArithOpcode).add(Op1).add(Op1).add(Op2);
815 buildMI(MBB, MBBI, StoreOpcode).add(Op2).add(Op1);
827 TRI->getAllocatableSet
832 if (MO.isReg() && MO.getReg() != 0 && !MO.isDef() &&
834 Candidates.
reset(MO.getReg());
838 Available &= Candidates;
841 assert(Reg != -1 &&
"ran out of registers");
846 bool AVRExpandPseudo::expand<AVR::AtomicLoad8>(Block &MBB, BlockIt MBBI) {
847 return expandAtomicBinaryOp(AVR::LDRdPtr, MBB, MBBI);
851 bool AVRExpandPseudo::expand<AVR::AtomicLoad16>(Block &MBB, BlockIt MBBI) {
852 return expandAtomicBinaryOp(AVR::LDWRdPtr, MBB, MBBI);
856 bool AVRExpandPseudo::expand<AVR::AtomicStore8>(Block &MBB, BlockIt MBBI) {
857 return expandAtomicBinaryOp(AVR::STPtrRr, MBB, MBBI);
861 bool AVRExpandPseudo::expand<AVR::AtomicStore16>(Block &MBB, BlockIt MBBI) {
862 return expandAtomicBinaryOp(AVR::STWPtrRr, MBB, MBBI);
866 bool AVRExpandPseudo::expand<AVR::AtomicLoadAdd8>(Block &MBB, BlockIt MBBI) {
867 return expandAtomicArithmeticOp(8, AVR::ADDRdRr, MBB, MBBI);
871 bool AVRExpandPseudo::expand<AVR::AtomicLoadAdd16>(Block &MBB, BlockIt MBBI) {
872 return expandAtomicArithmeticOp(16, AVR::ADDWRdRr, MBB, MBBI);
876 bool AVRExpandPseudo::expand<AVR::AtomicLoadSub8>(Block &MBB, BlockIt MBBI) {
877 return expandAtomicArithmeticOp(8, AVR::SUBRdRr, MBB, MBBI);
881 bool AVRExpandPseudo::expand<AVR::AtomicLoadSub16>(Block &MBB, BlockIt MBBI) {
882 return expandAtomicArithmeticOp(16, AVR::SUBWRdRr, MBB, MBBI);
886 bool AVRExpandPseudo::expand<AVR::AtomicLoadAnd8>(Block &MBB, BlockIt MBBI) {
887 return expandAtomicArithmeticOp(8, AVR::ANDRdRr, MBB, MBBI);
891 bool AVRExpandPseudo::expand<AVR::AtomicLoadAnd16>(Block &MBB, BlockIt MBBI) {
892 return expandAtomicArithmeticOp(16, AVR::ANDWRdRr, MBB, MBBI);
896 bool AVRExpandPseudo::expand<AVR::AtomicLoadOr8>(Block &MBB, BlockIt MBBI) {
897 return expandAtomicArithmeticOp(8, AVR::ORRdRr, MBB, MBBI);
901 bool AVRExpandPseudo::expand<AVR::AtomicLoadOr16>(Block &MBB, BlockIt MBBI) {
902 return expandAtomicArithmeticOp(16, AVR::ORWRdRr, MBB, MBBI);
906 bool AVRExpandPseudo::expand<AVR::AtomicLoadXor8>(Block &MBB, BlockIt MBBI) {
907 return expandAtomicArithmeticOp(8, AVR::EORRdRr, MBB, MBBI);
911 bool AVRExpandPseudo::expand<AVR::AtomicLoadXor16>(Block &MBB, BlockIt MBBI) {
912 return expandAtomicArithmeticOp(16, AVR::EORWRdRr, MBB, MBBI);
916 bool AVRExpandPseudo::expand<AVR::AtomicFence>(Block &MBB, BlockIt MBBI) {
918 MBBI->eraseFromParent();
923 bool AVRExpandPseudo::expand<AVR::STSWKRr>(Block &MBB, BlockIt MBBI) {
925 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
930 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
934 auto MIBHI = buildMI(MBB, MBBI, OpHi);
935 auto MIBLO = buildMI(MBB, MBBI, OpLo);
943 MIBLO.addGlobalAddress(GV, Offs, TF);
944 MIBHI.addGlobalAddress(GV, Offs + 1, TF);
951 MIBHI.addImm(Imm + 1);
969 bool AVRExpandPseudo::expand<AVR::STWPtrRr>(Block &MBB, BlockIt MBBI) {
971 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
976 OpHi = AVR::STDPtrQRr;
977 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
980 auto MIBLO = buildMI(MBB, MBBI, OpLo)
984 auto MIBHI = buildMI(MBB, MBBI, OpHi)
997 bool AVRExpandPseudo::expand<AVR::STWPtrPiRr>(Block &MBB, BlockIt MBBI) {
999 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1005 OpLo = AVR::STPtrPiRr;
1006 OpHi = AVR::STPtrPiRr;
1007 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1009 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
1011 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1017 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1031 bool AVRExpandPseudo::expand<AVR::STWPtrPdRr>(Block &MBB, BlockIt MBBI) {
1033 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1039 OpLo = AVR::STPtrPdRr;
1040 OpHi = AVR::STPtrPdRr;
1041 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1043 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
1045 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1051 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1065 bool AVRExpandPseudo::expand<AVR::STDWPtrQRr>(Block &MBB, BlockIt MBBI) {
1067 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1073 OpLo = AVR::STDPtrQRr;
1074 OpHi = AVR::STDPtrQRr;
1075 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1077 assert(Imm <= 63 &&
"Offset is out of range");
1079 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1084 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1097 bool AVRExpandPseudo::expand<AVR::INWRdA>(Block &MBB, BlockIt MBBI) {
1099 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1105 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1107 assert(Imm <= 63 &&
"Address is out of range");
1109 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1113 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1125 bool AVRExpandPseudo::expand<AVR::OUTWARr>(Block &MBB, BlockIt MBBI) {
1127 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1133 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1135 assert(Imm <= 63 &&
"Address is out of range");
1138 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1142 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1154 bool AVRExpandPseudo::expand<AVR::PUSHWRr>(Block &MBB, BlockIt MBBI) {
1156 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1162 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1165 buildMI(MBB, MBBI, OpLo)
1170 buildMI(MBB, MBBI, OpHi)
1179 bool AVRExpandPseudo::expand<AVR::POPWRd>(Block &MBB, BlockIt MBBI) {
1181 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1186 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1188 buildMI(MBB, MBBI, OpHi, DstHiReg).setMIFlags(Flags);
1189 buildMI(MBB, MBBI, OpLo, DstLoReg).setMIFlags(Flags);
1196 bool AVRExpandPseudo::expand<AVR::LSLWRd>(Block &MBB, BlockIt MBBI) {
1198 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1205 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1208 buildMI(MBB, MBBI, OpLo)
1212 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1217 MIBHI->getOperand(2).setIsDead();
1220 MIBHI->getOperand(3).setIsKill();
1227 bool AVRExpandPseudo::expand<AVR::LSRWRd>(Block &MBB, BlockIt MBBI) {
1229 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1236 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1239 buildMI(MBB, MBBI, OpHi)
1243 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1248 MIBLO->getOperand(2).setIsDead();
1251 MIBLO->getOperand(3).setIsKill();
1258 bool AVRExpandPseudo::expand<AVR::RORWRd>(Block &MBB, BlockIt MBBI) {
1264 bool AVRExpandPseudo::expand<AVR::ROLWRd>(Block &MBB, BlockIt MBBI) {
1270 bool AVRExpandPseudo::expand<AVR::ASRWRd>(Block &MBB, BlockIt MBBI) {
1272 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1279 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1282 buildMI(MBB, MBBI, OpHi)
1286 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1291 MIBLO->getOperand(2).setIsDead();
1294 MIBLO->getOperand(3).setIsKill();
1300 template <>
bool AVRExpandPseudo::expand<AVR::SEXT>(Block &MBB, BlockIt MBBI) {
1302 unsigned DstLoReg, DstHiReg;
1321 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1323 if (SrcReg != DstLoReg) {
1324 auto MOV = buildMI(MBB, MBBI, AVR::MOVRdRr)
1328 if (SrcReg == DstHiReg) {
1329 MOV->getOperand(1).setIsKill();
1333 if (SrcReg != DstHiReg) {
1334 buildMI(MBB, MBBI, AVR::MOVRdRr)
1339 buildMI(MBB, MBBI, AVR::LSLRd)
1343 auto SBC = buildMI(MBB, MBBI, AVR::SBCRdRr)
1349 SBC->getOperand(3).setIsDead();
1352 SBC->getOperand(4).setIsKill();
1358 template <>
bool AVRExpandPseudo::expand<AVR::ZEXT>(Block &MBB, BlockIt MBBI) {
1360 unsigned DstLoReg, DstHiReg;
1374 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1376 if (SrcReg != DstLoReg) {
1377 buildMI(MBB, MBBI, AVR::MOVRdRr)
1382 auto EOR = buildMI(MBB, MBBI, AVR::EORRdRr)
1388 EOR->getOperand(3).setIsDead();
1395 bool AVRExpandPseudo::expand<AVR::SPREAD>(Block &MBB, BlockIt MBBI) {
1397 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1403 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1406 buildMI(MBB, MBBI, OpLo)
1412 buildMI(MBB, MBBI, OpHi)
1422 bool AVRExpandPseudo::expand<AVR::SPWRITE>(Block &MBB, BlockIt MBBI) {
1424 unsigned SrcLoReg, SrcHiReg;
1428 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1430 buildMI(MBB, MBBI, AVR::INRdA)
1435 buildMI(MBB, MBBI, AVR::BCLRs).addImm(0x07).setMIFlags(Flags);
1437 buildMI(MBB, MBBI, AVR::OUTARr)
1442 buildMI(MBB, MBBI, AVR::OUTARr)
1447 buildMI(MBB, MBBI, AVR::OUTARr)
1456 bool AVRExpandPseudo::expandMI(Block &MBB, BlockIt MBBI) {
1458 int Opcode = MBBI->getOpcode();
1460 #define EXPAND(Op) \
1462 return expand<Op>(MBB, MI)
1488 EXPAND(AVR::AtomicLoad8);
1489 EXPAND(AVR::AtomicLoad16);
1490 EXPAND(AVR::AtomicStore8);
1491 EXPAND(AVR::AtomicStore16);
1492 EXPAND(AVR::AtomicLoadAdd8);
1493 EXPAND(AVR::AtomicLoadAdd16);
1494 EXPAND(AVR::AtomicLoadSub8);
1495 EXPAND(AVR::AtomicLoadSub16);
1496 EXPAND(AVR::AtomicLoadAnd8);
1497 EXPAND(AVR::AtomicLoadAnd16);
1498 EXPAND(AVR::AtomicLoadOr8);
1499 EXPAND(AVR::AtomicLoadOr16);
1500 EXPAND(AVR::AtomicLoadXor8);
1501 EXPAND(AVR::AtomicLoadXor16);
1502 EXPAND(AVR::AtomicFence);
const AVRInstrInfo * getInstrInfo() const override
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
const GlobalValue * getGlobal() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
iterator_range< mop_iterator > operands()
Utilities relating to AVR registers.
The address of a basic block.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Reg
All possible values of the reg field in the ModR/M byte.
void forward()
Move the internal MBB iterator and update register states.
BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
On a symbol operand, this represents it has to be negated.
unsigned getKillRegState(bool B)
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getDeadRegState(bool B)
mmo_iterator memoperands_end() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Address of a global value.
unsigned getTargetFlags() const
This file declares the machine register scavenger class.
const MachineOperand & getOperand(unsigned i) const
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned char TargetFlags=0)
Address of a basic block.
FunctionPass class - This class is used to implement most global optimizations.
int64_t getOffset() const
Return the offset from the symbol in this operand.
static Expected< BitVector > expand(StringRef S, StringRef Original)
On a symbol operand, this represents the hi part.
MachineOperand class - Representation of each machine instruction operand.
A specific AVR target MCU.
FunctionPass * createAVRExpandPseudoPass()
On a symbol operand, this represents the lo part.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
static std::vector< std::string > Flags
Representation of each machine instruction.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
INITIALIZE_PASS(AVRExpandPseudo,"avr-expand-pseudo", AVR_EXPAND_PSEUDO_NAME, false, false) namespace llvm
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
uint8_t getFlags() const
Return the MI flags bitvector.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const AVRRegisterInfo * getRegisterInfo() const override
StringRef - Represent a constant reference to a string, i.e.
const BlockAddress * getBlockAddress() const
#define AVR_EXPAND_PSEUDO_NAME
void initializeAVRExpandPseudoPass(PassRegistry &)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.