28 #define AVR_EXPAND_PSEUDO_NAME "AVR pseudo instruction expansion pass" 48 typedef Block::iterator BlockIt;
54 const unsigned SCRATCH_REGISTER = AVR::R0;
56 const unsigned ZERO_REGISTER = AVR::R1;
58 const unsigned SREG_ADDR = 0x3f;
60 bool expandMBB(Block &MBB);
61 bool expandMI(Block &MBB, BlockIt MBBI);
62 template <
unsigned OP>
bool expand(Block &MBB, BlockIt MBBI);
65 return BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII->
get(Opcode));
70 return BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII->
get(Opcode), DstReg);
75 bool expandArith(
unsigned OpLo,
unsigned OpHi, Block &MBB, BlockIt MBBI);
76 bool expandLogic(
unsigned Op, Block &MBB, BlockIt MBBI);
77 bool expandLogicImm(
unsigned Op, Block &MBB, BlockIt MBBI);
78 bool isLogicImmOpRedundant(
unsigned Op,
unsigned ImmVal)
const;
80 template<
typename Func>
81 bool expandAtomic(Block &MBB, BlockIt MBBI, Func f);
83 template<
typename Func>
84 bool expandAtomicBinaryOp(
unsigned Opcode, Block &MBB, BlockIt MBBI, Func f);
86 bool expandAtomicBinaryOp(
unsigned Opcode, Block &MBB, BlockIt MBBI);
88 bool expandAtomicArithmeticOp(
unsigned MemOpcode,
102 BlockIt MBBI = MBB.
begin(),
E = MBB.
end();
104 BlockIt NMBBI = std::next(MBBI);
105 Modified |= expandMI(MBB, MBBI);
122 for (Block &MBB : MF) {
123 bool ContinueExpanding =
true;
124 unsigned ExpandCount = 0;
128 assert(ExpandCount < 10 &&
"pseudo expand limit reached");
130 bool BlockModified = expandMBB(MBB);
131 Modified |= BlockModified;
134 ContinueExpanding = BlockModified;
135 }
while (ContinueExpanding);
141 bool AVRExpandPseudo::
142 expandArith(
unsigned OpLo,
unsigned OpHi, Block &MBB, BlockIt MBBI) {
144 unsigned SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
151 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
152 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
154 buildMI(MBB, MBBI, OpLo)
159 auto MIBHI = buildMI(MBB, MBBI, OpHi)
165 MIBHI->getOperand(3).setIsDead();
168 MIBHI->getOperand(4).setIsKill();
174 bool AVRExpandPseudo::
175 expandLogic(
unsigned Op, Block &MBB, BlockIt MBBI) {
177 unsigned SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
184 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
185 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
187 auto MIBLO = buildMI(MBB, MBBI, Op)
193 MIBLO->getOperand(3).setIsDead();
195 auto MIBHI = buildMI(MBB, MBBI, Op)
201 MIBHI->getOperand(3).setIsDead();
207 bool AVRExpandPseudo::
208 isLogicImmOpRedundant(
unsigned Op,
unsigned ImmVal)
const {
211 if (Op == AVR::ANDIRdK && ImmVal == 0xff)
215 if (Op == AVR::ORIRdK && ImmVal == 0x0)
221 bool AVRExpandPseudo::
222 expandLogicImm(
unsigned Op, Block &MBB, BlockIt MBBI) {
224 unsigned DstLoReg, DstHiReg;
230 unsigned Lo8 = Imm & 0xff;
231 unsigned Hi8 = (Imm >> 8) & 0xff;
232 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
234 if (!isLogicImmOpRedundant(Op, Lo8)) {
235 auto MIBLO = buildMI(MBB, MBBI, Op)
241 MIBLO->getOperand(3).setIsDead();
244 if (!isLogicImmOpRedundant(Op, Hi8)) {
245 auto MIBHI = buildMI(MBB, MBBI, Op)
251 MIBHI->getOperand(3).setIsDead();
259 bool AVRExpandPseudo::expand<AVR::ADDWRdRr>(Block &MBB, BlockIt MBBI) {
260 return expandArith(AVR::ADDRdRr, AVR::ADCRdRr, MBB, MBBI);
264 bool AVRExpandPseudo::expand<AVR::ADCWRdRr>(Block &MBB, BlockIt MBBI) {
265 return expandArith(AVR::ADCRdRr, AVR::ADCRdRr, MBB, MBBI);
269 bool AVRExpandPseudo::expand<AVR::SUBWRdRr>(Block &MBB, BlockIt MBBI) {
270 return expandArith(AVR::SUBRdRr, AVR::SBCRdRr, MBB, MBBI);
274 bool AVRExpandPseudo::expand<AVR::SUBIWRdK>(Block &MBB, BlockIt MBBI) {
276 unsigned DstLoReg, DstHiReg;
281 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
283 auto MIBLO = buildMI(MBB, MBBI, AVR::SUBIRdK)
287 auto MIBHI = buildMI(MBB, MBBI, AVR::SBCIRdK)
302 MIBLO.addImm(Imm & 0xff);
303 MIBHI.addImm((Imm >> 8) & 0xff);
311 MIBHI->getOperand(3).setIsDead();
314 MIBHI->getOperand(4).setIsKill();
321 bool AVRExpandPseudo::expand<AVR::SBCWRdRr>(Block &MBB, BlockIt MBBI) {
322 return expandArith(AVR::SBCRdRr, AVR::SBCRdRr, MBB, MBBI);
326 bool AVRExpandPseudo::expand<AVR::SBCIWRdK>(Block &MBB, BlockIt MBBI) {
328 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
334 unsigned Lo8 = Imm & 0xff;
335 unsigned Hi8 = (Imm >> 8) & 0xff;
338 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
340 auto MIBLO = buildMI(MBB, MBBI, OpLo)
346 MIBLO->getOperand(4).setIsKill();
348 auto MIBHI = buildMI(MBB, MBBI, OpHi)
354 MIBHI->getOperand(3).setIsDead();
357 MIBHI->getOperand(4).setIsKill();
364 bool AVRExpandPseudo::expand<AVR::ANDWRdRr>(Block &MBB, BlockIt MBBI) {
365 return expandLogic(AVR::ANDRdRr, MBB, MBBI);
369 bool AVRExpandPseudo::expand<AVR::ANDIWRdK>(Block &MBB, BlockIt MBBI) {
370 return expandLogicImm(AVR::ANDIRdK, MBB, MBBI);
374 bool AVRExpandPseudo::expand<AVR::ORWRdRr>(Block &MBB, BlockIt MBBI) {
375 return expandLogic(AVR::ORRdRr, MBB, MBBI);
379 bool AVRExpandPseudo::expand<AVR::ORIWRdK>(Block &MBB, BlockIt MBBI) {
380 return expandLogicImm(AVR::ORIRdK, MBB, MBBI);
384 bool AVRExpandPseudo::expand<AVR::EORWRdRr>(Block &MBB, BlockIt MBBI) {
385 return expandLogic(AVR::EORRdRr, MBB, MBBI);
389 bool AVRExpandPseudo::expand<AVR::COMWRd>(Block &MBB, BlockIt MBBI) {
391 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
398 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
400 auto MIBLO = buildMI(MBB, MBBI, OpLo)
405 MIBLO->getOperand(2).setIsDead();
407 auto MIBHI = buildMI(MBB, MBBI, OpHi)
412 MIBHI->getOperand(2).setIsDead();
419 bool AVRExpandPseudo::expand<AVR::CPWRdRr>(Block &MBB, BlockIt MBBI) {
421 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
429 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
430 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
433 buildMI(MBB, MBBI, OpLo)
437 auto MIBHI = buildMI(MBB, MBBI, OpHi)
442 MIBHI->getOperand(2).setIsDead();
445 MIBHI->getOperand(3).setIsKill();
452 bool AVRExpandPseudo::expand<AVR::CPCWRdRr>(Block &MBB, BlockIt MBBI) {
454 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg, DstLoReg, DstHiReg;
462 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
463 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
465 auto MIBLO = buildMI(MBB, MBBI, OpLo)
470 MIBLO->getOperand(3).setIsKill();
472 auto MIBHI = buildMI(MBB, MBBI, OpHi)
477 MIBHI->getOperand(2).setIsDead();
480 MIBHI->getOperand(3).setIsKill();
487 bool AVRExpandPseudo::expand<AVR::LDIWRdK>(Block &MBB, BlockIt MBBI) {
489 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
494 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
496 auto MIBLO = buildMI(MBB, MBBI, OpLo)
499 auto MIBHI = buildMI(MBB, MBBI, OpHi)
523 MIBLO.addImm(Imm & 0xff);
524 MIBHI.addImm((Imm >> 8) & 0xff);
536 bool AVRExpandPseudo::expand<AVR::LDSWRdK>(Block &MBB, BlockIt MBBI) {
538 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
543 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
545 auto MIBLO = buildMI(MBB, MBBI, OpLo)
548 auto MIBHI = buildMI(MBB, MBBI, OpHi)
557 MIBLO.addGlobalAddress(GV, Offs, TF);
558 MIBHI.addGlobalAddress(GV, Offs + 1, TF);
565 MIBHI.addImm(Imm + 1);
580 bool AVRExpandPseudo::expand<AVR::LDWRdPtr>(Block &MBB, BlockIt MBBI) {
582 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
588 OpHi = AVR::LDDRdPtrQ;
589 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
592 if (DstReg == SrcReg)
593 TmpReg = scavengeGPR8(MI);
595 unsigned CurDstLoReg = (DstReg == SrcReg) ? TmpReg : DstLoReg;
596 unsigned CurDstHiReg = (DstReg == SrcReg) ? TmpReg : DstHiReg;
599 auto MIBLO = buildMI(MBB, MBBI, OpLo)
605 buildMI(MBB, MBBI, AVR::PUSHRr).addReg(TmpReg);
608 auto MIBHI = buildMI(MBB, MBBI, OpHi)
615 buildMI(MBB, MBBI, AVR::MOVRdRr).addReg(DstHiReg).addReg(TmpReg);
618 buildMI(MBB, MBBI, AVR::POPRd).addReg(DstLoReg);
629 bool AVRExpandPseudo::expand<AVR::LDWRdPtrPi>(Block &MBB, BlockIt MBBI) {
631 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
636 OpLo = AVR::LDRdPtrPi;
637 OpHi = AVR::LDRdPtrPi;
638 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
640 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
642 auto MIBLO = buildMI(MBB, MBBI, OpLo)
647 auto MIBHI = buildMI(MBB, MBBI, OpHi)
660 bool AVRExpandPseudo::expand<AVR::LDWRdPtrPd>(Block &MBB, BlockIt MBBI) {
662 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
667 OpLo = AVR::LDRdPtrPd;
668 OpHi = AVR::LDRdPtrPd;
669 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
671 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
673 auto MIBHI = buildMI(MBB, MBBI, OpHi)
678 auto MIBLO = buildMI(MBB, MBBI, OpLo)
691 bool AVRExpandPseudo::expand<AVR::LDDWRdPtrQ>(Block &MBB, BlockIt MBBI) {
693 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
699 OpLo = AVR::LDDRdPtrQ;
700 OpHi = AVR::LDDRdPtrQ;
701 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
705 assert(Imm <= 62 &&
"Offset is out of range");
708 if (DstReg == SrcReg)
709 TmpReg = scavengeGPR8(MI);
711 unsigned CurDstLoReg = (DstReg == SrcReg) ? TmpReg : DstLoReg;
712 unsigned CurDstHiReg = (DstReg == SrcReg) ? TmpReg : DstHiReg;
715 auto MIBLO = buildMI(MBB, MBBI, OpLo)
722 buildMI(MBB, MBBI, AVR::PUSHRr).addReg(TmpReg);
725 auto MIBHI = buildMI(MBB, MBBI, OpHi)
732 buildMI(MBB, MBBI, AVR::MOVRdRr).addReg(DstHiReg).addReg(TmpReg);
735 buildMI(MBB, MBBI, AVR::POPRd).addReg(DstLoReg);
746 bool AVRExpandPseudo::expand<AVR::LPMWRdZ>(Block &MBB, BlockIt MBBI) {
748 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
753 OpLo = AVR::LPMRdZPi;
755 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
758 if (DstReg == SrcReg)
759 TmpReg = scavengeGPR8(MI);
761 unsigned CurDstLoReg = (DstReg == SrcReg) ? TmpReg : DstLoReg;
762 unsigned CurDstHiReg = (DstReg == SrcReg) ? TmpReg : DstHiReg;
765 auto MIBLO = buildMI(MBB, MBBI, OpLo)
771 buildMI(MBB, MBBI, AVR::PUSHRr).addReg(TmpReg);
774 auto MIBHI = buildMI(MBB, MBBI, OpHi)
780 buildMI(MBB, MBBI, AVR::MOVRdRr).addReg(DstHiReg).addReg(TmpReg);
783 buildMI(MBB, MBBI, AVR::POPRd).addReg(DstLoReg);
794 bool AVRExpandPseudo::expand<AVR::LPMWRdZPi>(Block &MBB, BlockIt MBBI) {
798 template<
typename Func>
799 bool AVRExpandPseudo::expandAtomic(Block &MBB, BlockIt MBBI, Func f) {
804 buildMI(MBB, MBBI, AVR::INRdA)
809 buildMI(MBB, MBBI, AVR::BCLRs).addImm(7);
814 buildMI(MBB, MBBI, AVR::OUTARr)
816 .addReg(SCRATCH_REGISTER);
822 template<
typename Func>
823 bool AVRExpandPseudo::expandAtomicBinaryOp(
unsigned Opcode,
832 *buildMI(MBB, MBBI, Opcode).add(Op1).add(Op2).getInstr();
837 bool AVRExpandPseudo::expandAtomicBinaryOp(
unsigned Opcode,
840 return expandAtomicBinaryOp(Opcode, MBB, MBBI, [](
MachineInstr &
MI) {});
843 bool AVRExpandPseudo::expandAtomicArithmeticOp(
unsigned Width,
844 unsigned ArithOpcode,
851 unsigned LoadOpcode = (Width == 8) ? AVR::LDRdPtr : AVR::LDWRdPtr;
852 unsigned StoreOpcode = (Width == 8) ? AVR::STPtrRr : AVR::STWPtrRr;
855 buildMI(MBB, MBBI, LoadOpcode).add(Op1).add(Op2);
858 buildMI(MBB, MBBI, ArithOpcode).add(Op1).add(Op1).add(Op2);
861 buildMI(MBB, MBBI, StoreOpcode).add(Op2).add(Op1);
873 TRI->getAllocatableSet
878 if (MO.isReg() && MO.getReg() != 0 && !MO.isDef() &&
880 Candidates.
reset(MO.getReg());
884 Available &= Candidates;
887 assert(Reg != -1 &&
"ran out of registers");
892 bool AVRExpandPseudo::expand<AVR::AtomicLoad8>(Block &MBB, BlockIt MBBI) {
893 return expandAtomicBinaryOp(AVR::LDRdPtr, MBB, MBBI);
897 bool AVRExpandPseudo::expand<AVR::AtomicLoad16>(Block &MBB, BlockIt MBBI) {
898 return expandAtomicBinaryOp(AVR::LDWRdPtr, MBB, MBBI);
902 bool AVRExpandPseudo::expand<AVR::AtomicStore8>(Block &MBB, BlockIt MBBI) {
903 return expandAtomicBinaryOp(AVR::STPtrRr, MBB, MBBI);
907 bool AVRExpandPseudo::expand<AVR::AtomicStore16>(Block &MBB, BlockIt MBBI) {
908 return expandAtomicBinaryOp(AVR::STWPtrRr, MBB, MBBI);
912 bool AVRExpandPseudo::expand<AVR::AtomicLoadAdd8>(Block &MBB, BlockIt MBBI) {
913 return expandAtomicArithmeticOp(8, AVR::ADDRdRr, MBB, MBBI);
917 bool AVRExpandPseudo::expand<AVR::AtomicLoadAdd16>(Block &MBB, BlockIt MBBI) {
918 return expandAtomicArithmeticOp(16, AVR::ADDWRdRr, MBB, MBBI);
922 bool AVRExpandPseudo::expand<AVR::AtomicLoadSub8>(Block &MBB, BlockIt MBBI) {
923 return expandAtomicArithmeticOp(8, AVR::SUBRdRr, MBB, MBBI);
927 bool AVRExpandPseudo::expand<AVR::AtomicLoadSub16>(Block &MBB, BlockIt MBBI) {
928 return expandAtomicArithmeticOp(16, AVR::SUBWRdRr, MBB, MBBI);
932 bool AVRExpandPseudo::expand<AVR::AtomicLoadAnd8>(Block &MBB, BlockIt MBBI) {
933 return expandAtomicArithmeticOp(8, AVR::ANDRdRr, MBB, MBBI);
937 bool AVRExpandPseudo::expand<AVR::AtomicLoadAnd16>(Block &MBB, BlockIt MBBI) {
938 return expandAtomicArithmeticOp(16, AVR::ANDWRdRr, MBB, MBBI);
942 bool AVRExpandPseudo::expand<AVR::AtomicLoadOr8>(Block &MBB, BlockIt MBBI) {
943 return expandAtomicArithmeticOp(8, AVR::ORRdRr, MBB, MBBI);
947 bool AVRExpandPseudo::expand<AVR::AtomicLoadOr16>(Block &MBB, BlockIt MBBI) {
948 return expandAtomicArithmeticOp(16, AVR::ORWRdRr, MBB, MBBI);
952 bool AVRExpandPseudo::expand<AVR::AtomicLoadXor8>(Block &MBB, BlockIt MBBI) {
953 return expandAtomicArithmeticOp(8, AVR::EORRdRr, MBB, MBBI);
957 bool AVRExpandPseudo::expand<AVR::AtomicLoadXor16>(Block &MBB, BlockIt MBBI) {
958 return expandAtomicArithmeticOp(16, AVR::EORWRdRr, MBB, MBBI);
962 bool AVRExpandPseudo::expand<AVR::AtomicFence>(Block &MBB, BlockIt MBBI) {
964 MBBI->eraseFromParent();
969 bool AVRExpandPseudo::expand<AVR::STSWKRr>(Block &MBB, BlockIt MBBI) {
971 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
976 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
980 auto MIBHI = buildMI(MBB, MBBI, OpHi);
981 auto MIBLO = buildMI(MBB, MBBI, OpLo);
989 MIBLO.addGlobalAddress(GV, Offs, TF);
990 MIBHI.addGlobalAddress(GV, Offs + 1, TF);
997 MIBHI.addImm(Imm + 1);
1015 bool AVRExpandPseudo::expand<AVR::STWPtrRr>(Block &MBB, BlockIt MBBI) {
1017 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1021 OpLo = AVR::STPtrRr;
1022 OpHi = AVR::STDPtrQRr;
1023 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1026 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1030 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1043 bool AVRExpandPseudo::expand<AVR::STWPtrPiRr>(Block &MBB, BlockIt MBBI) {
1045 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1051 OpLo = AVR::STPtrPiRr;
1052 OpHi = AVR::STPtrPiRr;
1053 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1055 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
1057 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1063 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1077 bool AVRExpandPseudo::expand<AVR::STWPtrPdRr>(Block &MBB, BlockIt MBBI) {
1079 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1085 OpLo = AVR::STPtrPdRr;
1086 OpHi = AVR::STPtrPdRr;
1087 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1089 assert(DstReg != SrcReg &&
"SrcReg and DstReg cannot be the same");
1091 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1097 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1111 bool AVRExpandPseudo::expand<AVR::STDWPtrQRr>(Block &MBB, BlockIt MBBI) {
1113 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1119 OpLo = AVR::STDPtrQRr;
1120 OpHi = AVR::STDPtrQRr;
1121 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1125 assert(Imm <= 62 &&
"Offset is out of range");
1127 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1132 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1145 bool AVRExpandPseudo::expand<AVR::INWRdA>(Block &MBB, BlockIt MBBI) {
1147 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1153 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1157 assert(Imm <= 62 &&
"Address is out of range");
1159 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1163 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1175 bool AVRExpandPseudo::expand<AVR::OUTWARr>(Block &MBB, BlockIt MBBI) {
1177 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1183 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1187 assert(Imm <= 62 &&
"Address is out of range");
1190 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1194 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1206 bool AVRExpandPseudo::expand<AVR::PUSHWRr>(Block &MBB, BlockIt MBBI) {
1208 unsigned OpLo, OpHi, SrcLoReg, SrcHiReg;
1214 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1217 buildMI(MBB, MBBI, OpLo)
1222 buildMI(MBB, MBBI, OpHi)
1231 bool AVRExpandPseudo::expand<AVR::POPWRd>(Block &MBB, BlockIt MBBI) {
1233 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1238 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1240 buildMI(MBB, MBBI, OpHi, DstHiReg).setMIFlags(Flags);
1241 buildMI(MBB, MBBI, OpLo, DstLoReg).setMIFlags(Flags);
1248 bool AVRExpandPseudo::expand<AVR::ROLBRd>(Block &MBB, BlockIt MBBI) {
1256 unsigned OpShift, OpCarry;
1259 OpShift = AVR::ADDRdRr;
1260 OpCarry = AVR::ADCRdRr;
1266 buildMI(MBB, MBBI, OpShift)
1272 auto MIB = buildMI(MBB, MBBI, OpCarry)
1275 .addReg(ZERO_REGISTER);
1278 MIB->getOperand(2).setIsKill();
1285 bool AVRExpandPseudo::expand<AVR::RORBRd>(Block &MBB, BlockIt MBBI) {
1293 unsigned OpShiftOut, OpLoad, OpShiftIn, OpAdd;
1296 OpShiftOut = AVR::LSRRd;
1297 OpLoad = AVR::LDIRdK;
1298 OpShiftIn = AVR::RORRd;
1299 OpAdd = AVR::ORRdRr;
1307 buildMI(MBB, MBBI, OpShiftOut)
1312 buildMI(MBB, MBBI, OpLoad)
1317 buildMI(MBB, MBBI, OpShiftIn)
1319 .addReg(SCRATCH_REGISTER);
1322 auto MIB = buildMI(MBB, MBBI, OpAdd)
1325 .addReg(SCRATCH_REGISTER);
1328 MIB->getOperand(2).setIsKill();
1335 bool AVRExpandPseudo::expand<AVR::LSLWRd>(Block &MBB, BlockIt MBBI) {
1337 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1342 OpLo = AVR::ADDRdRr;
1343 OpHi = AVR::ADCRdRr;
1344 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1347 buildMI(MBB, MBBI, OpLo)
1352 auto MIBHI = buildMI(MBB, MBBI, OpHi)
1358 MIBHI->getOperand(3).setIsDead();
1361 MIBHI->getOperand(4).setIsKill();
1368 bool AVRExpandPseudo::expand<AVR::LSRWRd>(Block &MBB, BlockIt MBBI) {
1370 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1377 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1380 buildMI(MBB, MBBI, OpHi)
1384 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1389 MIBLO->getOperand(2).setIsDead();
1392 MIBLO->getOperand(3).setIsKill();
1399 bool AVRExpandPseudo::expand<AVR::RORWRd>(Block &MBB, BlockIt MBBI) {
1405 bool AVRExpandPseudo::expand<AVR::ROLWRd>(Block &MBB, BlockIt MBBI) {
1411 bool AVRExpandPseudo::expand<AVR::ASRWRd>(Block &MBB, BlockIt MBBI) {
1413 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1420 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1423 buildMI(MBB, MBBI, OpHi)
1427 auto MIBLO = buildMI(MBB, MBBI, OpLo)
1432 MIBLO->getOperand(2).setIsDead();
1435 MIBLO->getOperand(3).setIsKill();
1441 template <>
bool AVRExpandPseudo::expand<AVR::SEXT>(Block &MBB, BlockIt MBBI) {
1443 unsigned DstLoReg, DstHiReg;
1462 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1464 if (SrcReg != DstLoReg) {
1465 auto MOV = buildMI(MBB, MBBI, AVR::MOVRdRr)
1469 if (SrcReg == DstHiReg) {
1470 MOV->getOperand(1).setIsKill();
1474 if (SrcReg != DstHiReg) {
1475 buildMI(MBB, MBBI, AVR::MOVRdRr)
1480 buildMI(MBB, MBBI, AVR::ADDRdRr)
1485 auto SBC = buildMI(MBB, MBBI, AVR::SBCRdRr)
1491 SBC->getOperand(3).setIsDead();
1494 SBC->getOperand(4).setIsKill();
1500 template <>
bool AVRExpandPseudo::expand<AVR::ZEXT>(Block &MBB, BlockIt MBBI) {
1502 unsigned DstLoReg, DstHiReg;
1516 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1518 if (SrcReg != DstLoReg) {
1519 buildMI(MBB, MBBI, AVR::MOVRdRr)
1524 auto EOR = buildMI(MBB, MBBI, AVR::EORRdRr)
1530 EOR->getOperand(3).setIsDead();
1537 bool AVRExpandPseudo::expand<AVR::SPREAD>(Block &MBB, BlockIt MBBI) {
1539 unsigned OpLo, OpHi, DstLoReg, DstHiReg;
1545 TRI->splitReg(DstReg, DstLoReg, DstHiReg);
1548 buildMI(MBB, MBBI, OpLo)
1554 buildMI(MBB, MBBI, OpHi)
1564 bool AVRExpandPseudo::expand<AVR::SPWRITE>(Block &MBB, BlockIt MBBI) {
1566 unsigned SrcLoReg, SrcHiReg;
1570 TRI->splitReg(SrcReg, SrcLoReg, SrcHiReg);
1572 buildMI(MBB, MBBI, AVR::INRdA)
1577 buildMI(MBB, MBBI, AVR::BCLRs).addImm(0x07).setMIFlags(Flags);
1579 buildMI(MBB, MBBI, AVR::OUTARr)
1584 buildMI(MBB, MBBI, AVR::OUTARr)
1589 buildMI(MBB, MBBI, AVR::OUTARr)
1598 bool AVRExpandPseudo::expandMI(Block &MBB, BlockIt MBBI) {
1600 int Opcode = MBBI->getOpcode();
1602 #define EXPAND(Op) \ 1604 return expand<Op>(MBB, MI) 1630 EXPAND(AVR::AtomicLoad8);
1631 EXPAND(AVR::AtomicLoad16);
1632 EXPAND(AVR::AtomicStore8);
1633 EXPAND(AVR::AtomicStore16);
1634 EXPAND(AVR::AtomicLoadAdd8);
1635 EXPAND(AVR::AtomicLoadAdd16);
1636 EXPAND(AVR::AtomicLoadSub8);
1637 EXPAND(AVR::AtomicLoadSub16);
1638 EXPAND(AVR::AtomicLoadAnd8);
1639 EXPAND(AVR::AtomicLoadAnd16);
1640 EXPAND(AVR::AtomicLoadOr8);
1641 EXPAND(AVR::AtomicLoadOr16);
1642 EXPAND(AVR::AtomicLoadXor8);
1643 EXPAND(AVR::AtomicLoadXor16);
1644 EXPAND(AVR::AtomicFence);
unsigned getTargetFlags() const
const AVRInstrInfo * getInstrInfo() const override
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
const MachineFunctionProperties & getProperties() const
Get the function properties.
unsigned const TargetRegisterInfo * TRI
iterator_range< mop_iterator > operands()
Utilities relating to AVR registers.
The address of a basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
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)
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getDeadRegState(bool B)
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.
This file declares the machine register scavenger class.
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const GlobalValue * getGlobal() const
Address of a basic block.
FunctionPass class - This class is used to implement most global optimizations.
static Expected< BitVector > expand(StringRef S, StringRef Original)
On a symbol operand, this represents the hi part.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
MachineOperand class - Representation of each machine instruction operand.
A specific AVR target MCU.
FunctionPass * createAVRExpandPseudoPass()
On a symbol operand, this represents the lo part.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
uint16_t getFlags() const
Return the MI flags bitvector.
INITIALIZE_PASS(AVRExpandPseudo, "avr-expand-pseudo", AVR_EXPAND_PSEUDO_NAME, false, false) namespace llvm
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const AVRRegisterInfo * getRegisterInfo() const override
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
#define AVR_EXPAND_PSEUDO_NAME
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
void initializeAVRExpandPseudoPass(PassRegistry &)
Wrapper class representing virtual and physical registers.