45#define DEBUG_TYPE "thumb2-reduce-size"
46#define THUMB2_SIZE_REDUCE_NAME "Thumb2 instruction size reduce pass"
48STATISTIC(NumNarrows,
"Number of 32-bit instrs reduced to 16-bit ones");
49STATISTIC(Num2Addrs,
"Number of 32-bit instrs reduced to 2addr 16-bit ones");
50STATISTIC(NumLdSts,
"Number of 32-bit load / store reduced to 16-bit ones");
62 unsigned LowRegs1 : 1;
63 unsigned LowRegs2 : 1;
68 unsigned PartFlag : 1;
70 unsigned AvoidMovs: 1;
75 { ARM::t2ADCrr, 0, ARM::tADC, 0, 0, 0, 1, 0,0, 0,0,0 },
76 { ARM::t2ADDri, ARM::tADDi3, ARM::tADDi8, 3, 8, 1, 1, 0,0, 0,1,0 },
77 { ARM::t2ADDrr, ARM::tADDrr, ARM::tADDhirr, 0, 0, 1, 0, 0,1, 0,0,0 },
78 { ARM::t2ADDSri,ARM::tADDi3, ARM::tADDi8, 3, 8, 1, 1, 2,2, 0,1,0 },
79 { ARM::t2ADDSrr,ARM::tADDrr, 0, 0, 0, 1, 0, 2,0, 0,1,0 },
80 { ARM::t2ANDrr, 0, ARM::tAND, 0, 0, 0, 1, 0,0, 1,0,0 },
81 { ARM::t2ASRri, ARM::tASRri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
82 { ARM::t2ASRrr, 0, ARM::tASRrr, 0, 0, 0, 1, 0,0, 1,0,1 },
83 { ARM::t2BICrr, 0, ARM::tBIC, 0, 0, 0, 1, 0,0, 1,0,0 },
84 { ARM::t2CMNrr, ARM::tCMN, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
85 { ARM::t2CMPri, ARM::tCMPi8, 0, 8, 0, 1, 0, 2,0, 0,0,0 },
86 { ARM::t2CMPrr, ARM::tCMPhir, 0, 0, 0, 0, 0, 2,0, 0,1,0 },
87 { ARM::t2EORrr, 0, ARM::tEOR, 0, 0, 0, 1, 0,0, 1,0,0 },
90 { ARM::t2LSLri, ARM::tLSLri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
91 { ARM::t2LSLrr, 0, ARM::tLSLrr, 0, 0, 0, 1, 0,0, 1,0,1 },
92 { ARM::t2LSRri, ARM::tLSRri, 0, 5, 0, 1, 0, 0,0, 1,0,1 },
93 { ARM::t2LSRrr, 0, ARM::tLSRrr, 0, 0, 0, 1, 0,0, 1,0,1 },
94 { ARM::t2MOVi, ARM::tMOVi8, 0, 8, 0, 1, 0, 0,0, 1,0,0 },
95 { ARM::t2MOVi16,ARM::tMOVi8, 0, 8, 0, 1, 0, 0,0, 1,1,0 },
97 { ARM::t2MOVr,ARM::tMOVr, 0, 0, 0, 0, 0, 1,0, 0,0,0 },
98 { ARM::t2MUL, 0, ARM::tMUL, 0, 0, 0, 1, 0,0, 1,0,0 },
99 { ARM::t2MVNr, ARM::tMVN, 0, 0, 0, 1, 0, 0,0, 0,0,0 },
100 { ARM::t2ORRrr, 0, ARM::tORR, 0, 0, 0, 1, 0,0, 1,0,0 },
101 { ARM::t2REV, ARM::tREV, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
102 { ARM::t2REV16, ARM::tREV16, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
103 { ARM::t2REVSH, ARM::tREVSH, 0, 0, 0, 1, 0, 1,0, 0,0,0 },
104 { ARM::t2RORrr, 0, ARM::tROR, 0, 0, 0, 1, 0,0, 1,0,0 },
105 { ARM::t2RSBri, ARM::tRSB, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
106 { ARM::t2RSBSri,ARM::tRSB, 0, 0, 0, 1, 0, 2,0, 0,1,0 },
107 { ARM::t2SBCrr, 0, ARM::tSBC, 0, 0, 0, 1, 0,0, 0,0,0 },
108 { ARM::t2SUBri, ARM::tSUBi3, ARM::tSUBi8, 3, 8, 1, 1, 0,0, 0,0,0 },
109 { ARM::t2SUBrr, ARM::tSUBrr, 0, 0, 0, 1, 0, 0,0, 0,0,0 },
110 { ARM::t2SUBSri,ARM::tSUBi3, ARM::tSUBi8, 3, 8, 1, 1, 2,2, 0,0,0 },
111 { ARM::t2SUBSrr,ARM::tSUBrr, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
112 { ARM::t2SXTB, ARM::tSXTB, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
113 { ARM::t2SXTH, ARM::tSXTH, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
114 { ARM::t2TEQrr, ARM::tEOR, 0, 0, 0, 1, 0, 2,0, 0,1,0 },
115 { ARM::t2TSTrr, ARM::tTST, 0, 0, 0, 1, 0, 2,0, 0,0,0 },
116 { ARM::t2UXTB, ARM::tUXTB, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
117 { ARM::t2UXTH, ARM::tUXTH, 0, 0, 0, 1, 0, 1,0, 0,1,0 },
121 { ARM::t2LDRi12,ARM::tLDRi, ARM::tLDRspi, 5, 8, 1, 0, 0,0, 0,1,0 },
122 { ARM::t2LDRs, ARM::tLDRr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
123 { ARM::t2LDRBi12,ARM::tLDRBi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
124 { ARM::t2LDRBs, ARM::tLDRBr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
125 { ARM::t2LDRHi12,ARM::tLDRHi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
126 { ARM::t2LDRHs, ARM::tLDRHr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
127 { ARM::t2LDRSBs,ARM::tLDRSB, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
128 { ARM::t2LDRSHs,ARM::tLDRSH, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
129 { ARM::t2LDR_POST,ARM::tLDMIA_UPD,0, 0, 0, 1, 0, 0,0, 0,1,0 },
130 { ARM::t2STRi12,ARM::tSTRi, ARM::tSTRspi, 5, 8, 1, 0, 0,0, 0,1,0 },
131 { ARM::t2STRs, ARM::tSTRr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
132 { ARM::t2STRBi12,ARM::tSTRBi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
133 { ARM::t2STRBs, ARM::tSTRBr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
134 { ARM::t2STRHi12,ARM::tSTRHi, 0, 5, 0, 1, 0, 0,0, 0,1,0 },
135 { ARM::t2STRHs, ARM::tSTRHr, 0, 0, 0, 1, 0, 0,0, 0,1,0 },
136 { ARM::t2STR_POST,ARM::tSTMIA_UPD,0, 0, 0, 1, 0, 0,0, 0,1,0 },
138 { ARM::t2LDMIA, ARM::tLDMIA, 0, 0, 0, 1, 1, 1,1, 0,1,0 },
139 { ARM::t2LDMIA_RET,0, ARM::tPOP_RET, 0, 0, 1, 1, 1,1, 0,1,0 },
140 { ARM::t2LDMIA_UPD,ARM::tLDMIA_UPD,ARM::tPOP,0, 0, 1, 1, 1,1, 0,1,0 },
144 { ARM::t2STMIA, ARM::tSTMIA_UPD, 0, 0, 0, 1, 1, 1,1, 0,1,0 },
145 { ARM::t2STMIA_UPD,ARM::tSTMIA_UPD, 0, 0, 0, 1, 1, 1,1, 0,1,0 },
146 { ARM::t2STMDB_UPD, 0, ARM::tPUSH, 0, 0, 1, 1, 1,1, 0,1,0 }
153 const Thumb2InstrInfo *TII;
154 const ARMSubtarget *STI;
156 Thumb2SizeReduce(std::function<
bool(
const Function &)> Ftor =
nullptr);
160 MachineFunctionProperties getRequiredProperties()
const override {
161 return MachineFunctionProperties().setNoVRegs();
164 StringRef getPassName()
const override {
168 void getAnalysisUsage(AnalysisUsage &AU)
const override {
175 DenseMap<unsigned, unsigned> ReduceOpcodeMap;
177 bool canAddPseudoFlagDep(
const MachineInstr *Use,
bool IsSelfLoop);
179 bool VerifyPredAndCC(
const MachineInstr *
MI,
const ReduceEntry &Entry,
181 bool &HasCC,
bool &CCDead);
183 bool ReduceLoadStore(MachineBasicBlock &
MBB, MachineInstr *
MI,
184 const ReduceEntry &Entry);
186 bool ReduceSpecial(MachineBasicBlock &
MBB, MachineInstr *
MI,
187 const ReduceEntry &Entry,
bool LiveCPSR,
bool IsSelfLoop);
191 bool ReduceTo2Addr(MachineBasicBlock &
MBB, MachineInstr *
MI,
192 const ReduceEntry &Entry,
bool LiveCPSR,
197 bool ReduceToNarrow(MachineBasicBlock &
MBB, MachineInstr *
MI,
198 const ReduceEntry &Entry,
bool LiveCPSR,
202 bool ReduceMI(MachineBasicBlock &
MBB, MachineInstr *
MI,
bool LiveCPSR,
203 bool IsSelfLoop,
bool SkipPrologueEpilogue);
206 bool ReduceMBB(MachineBasicBlock &
MBB,
bool SkipPrologueEpilogue);
212 MachineInstr *CPSRDef;
215 bool HighLatencyCPSR;
219 bool HighLatencyCPSR =
false;
221 bool Visited =
false;
228 std::function<bool(
const Function &)> PredicateFtor;
231 char Thumb2SizeReduce::ID = 0;
240 OptimizeSize = MinimizeSize =
false;
241 for (
unsigned i = 0, e = std::size(
ReduceTable); i != e; ++i) {
243 if (!ReduceOpcodeMap.insert(std::make_pair(FromOpc, i)).second)
254 switch (Def->getOpcode()) {
280 bool FirstInSelfLoop) {
282 if (MinimizeSize || !STI->avoidCPSRPartialUpdate())
288 return HighLatencyCPSR || FirstInSelfLoop;
290 SmallSet<unsigned, 2> Defs;
291 for (
const MachineOperand &MO : CPSRDef->
operands()) {
292 if (!MO.isReg() || MO.isUndef() || MO.isUse())
295 if (
Reg == 0 ||
Reg == ARM::CPSR)
300 for (
const MachineOperand &MO :
Use->operands()) {
301 if (!MO.isReg() || MO.isUndef() || MO.isDef())
314 if (
Use->getOpcode() == ARM::t2MOVi ||
315 Use->getOpcode() == ARM::t2MOVi16)
322bool Thumb2SizeReduce::VerifyPredAndCC(
const MachineInstr *
MI,
323 const ReduceEntry &Entry,
bool is2Addr,
325 bool &HasCC,
bool &CCDead) {
326 if ((is2Addr &&
Entry.PredCC2 == 0) ||
327 (!is2Addr &&
Entry.PredCC1 == 0)) {
346 }
else if ((is2Addr &&
Entry.PredCC2 == 2) ||
347 (!is2Addr &&
Entry.PredCC1 == 2)) {
366 unsigned Opc =
MI->getOpcode();
367 bool isPCOk = (
Opc == ARM::t2LDMIA_RET ||
Opc == ARM::t2LDMIA_UPD);
368 bool isLROk = (
Opc == ARM::t2STMDB_UPD);
369 bool isSPOk = isPCOk || isLROk;
370 for (
unsigned i = 0, e =
MI->getNumOperands(); i != e; ++i) {
375 if (
Reg == 0 ||
Reg == ARM::CPSR)
377 if (isPCOk &&
Reg == ARM::PC)
379 if (isLROk &&
Reg == ARM::LR)
381 if (
Reg == ARM::SP) {
384 if (i == 1 && (
Opc == ARM::t2LDRi12 ||
Opc == ARM::t2STRi12))
395Thumb2SizeReduce::ReduceLoadStore(MachineBasicBlock &
MBB, MachineInstr *
MI,
396 const ReduceEntry &Entry) {
397 int ReduceLimitLdSt = STI->
getCLOpts().t2_reduce_limit3;
398 if (ReduceLimitLdSt != -1 && ((
int)NumLdSts >= ReduceLimitLdSt))
402 bool HasImmOffset =
false;
403 bool HasShift =
false;
404 bool HasOffReg =
true;
405 bool isLdStMul =
false;
408 uint8_t ImmLimit =
Entry.Imm1Limit;
410 switch (
Entry.WideOpc) {
415 if (
MI->getOperand(1).getReg() == ARM::SP) {
417 ImmLimit =
Entry.Imm2Limit;
446 case ARM::t2LDR_POST:
447 case ARM::t2STR_POST: {
451 if (!
MI->hasOneMemOperand() ||
452 (*
MI->memoperands_begin())->getAlign() <
Align(4))
458 bool IsStore =
Entry.WideOpc == ARM::t2STR_POST;
459 Register Rt =
MI->getOperand(IsStore ? 1 : 0).getReg();
460 Register Rn =
MI->getOperand(IsStore ? 0 : 1).getReg();
461 unsigned Offset =
MI->getOperand(3).getImm();
462 unsigned PredImm =
MI->getOperand(4).getImm();
463 Register PredReg =
MI->getOperand(5).getReg();
473 .
addReg(Rn, RegState::Define)
498 if (MO.getReg() == BaseReg) {
515 if (!
MI->getOperand(0).isKill())
523 if (MO.getReg() == BaseReg)
528 case ARM::t2LDMIA_RET: {
530 if (BaseReg != ARM::SP)
537 case ARM::t2LDMIA_UPD:
538 case ARM::t2STMIA_UPD:
539 case ARM::t2STMDB_UPD: {
543 if (BaseReg == ARM::SP &&
544 (
Entry.WideOpc == ARM::t2LDMIA_UPD ||
545 Entry.WideOpc == ARM::t2STMDB_UPD)) {
549 (
Entry.WideOpc != ARM::t2LDMIA_UPD &&
550 Entry.WideOpc != ARM::t2STMIA_UPD)) {
559 unsigned OffsetReg = 0;
560 bool OffsetKill =
false;
561 bool OffsetInternal =
false;
563 OffsetReg =
MI->getOperand(2).getReg();
564 OffsetKill =
MI->getOperand(2).isKill();
565 OffsetInternal =
MI->getOperand(2).isInternalRead();
567 if (
MI->getOperand(3).getImm())
572 unsigned OffsetImm = 0;
574 OffsetImm =
MI->getOperand(2).getImm();
575 unsigned MaxOffset = ((1 << ImmLimit) - 1) * Scale;
577 if ((OffsetImm & (Scale - 1)) || OffsetImm > MaxOffset)
588 if (
Entry.WideOpc == ARM::t2STMIA)
589 MIB.
addReg(
MI->getOperand(0).getReg(), RegState::Define | RegState::Dead);
592 MIB.
add(
MI->getOperand(0));
593 MIB.
add(
MI->getOperand(1));
596 MIB.
addImm(OffsetImm / Scale);
598 assert((!HasShift || OffsetReg) &&
"Invalid so_reg load / store address!");
616 <<
" to 16-bit: " << *MIB);
624Thumb2SizeReduce::ReduceSpecial(MachineBasicBlock &
MBB, MachineInstr *
MI,
625 const ReduceEntry &Entry,
626 bool LiveCPSR,
bool IsSelfLoop) {
627 unsigned Opc =
MI->getOpcode();
628 if (
Opc == ARM::t2ADDri) {
631 if (
MI->getOperand(1).getReg() != ARM::SP) {
632 if (ReduceTo2Addr(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop))
634 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
637 unsigned Imm =
MI->getOperand(2).getImm();
641 if (
Imm & 3 ||
Imm > 1020)
647 const MCInstrDesc &MCID =
MI->getDesc();
652 MachineInstrBuilder MIB =
654 TII->get(ARM::tADDrSPi))
655 .
add(
MI->getOperand(0))
656 .
add(
MI->getOperand(1))
664 <<
" to 16-bit: " << *MIB);
674 if (
MI->mayLoadOrStore())
675 return ReduceLoadStore(
MBB,
MI, Entry);
680 case ARM::t2ADDSrr: {
686 if (ReduceTo2Addr(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop))
690 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
701 if (
MI->getOperand(2).getImm() == 0)
702 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
707 if (
MI->getOperand(1).isImm())
708 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
716 static const ReduceEntry NarrowEntry =
717 { ARM::t2CMPrr,ARM::tCMPr, 0, 0, 0, 1, 1,2, 0, 0,1,0 };
718 if (ReduceToNarrow(
MBB,
MI, NarrowEntry, LiveCPSR, IsSelfLoop))
720 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
729 if (
MI->getOperand(0).isKill())
730 return ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
737Thumb2SizeReduce::ReduceTo2Addr(MachineBasicBlock &
MBB, MachineInstr *
MI,
738 const ReduceEntry &Entry,
739 bool LiveCPSR,
bool IsSelfLoop) {
740 int ReduceLimit2Addr = STI->
getCLOpts().t2_reduce_limit2;
741 if (ReduceLimit2Addr != -1 && ((
int)Num2Addrs >= ReduceLimit2Addr))
744 if (!OptimizeSize &&
Entry.AvoidMovs && STI->avoidMOVsShifterOperand())
752 if (
MI->getOpcode() == ARM::t2MUL) {
754 if (!MinimizeSize && STI->avoidMULS())
767 MachineInstr *CommutedMI =
TII->commuteInstruction(*
MI);
771 }
else if (Reg0 != Reg1) {
773 unsigned CommOpIdx1 = 1;
775 if (!
TII->findCommutedOpIndices(*
MI, CommOpIdx1, CommOpIdx2) ||
776 MI->getOperand(CommOpIdx2).getReg() != Reg0)
778 MachineInstr *CommutedMI =
779 TII->commuteInstruction(*
MI,
false, CommOpIdx1, CommOpIdx2);
785 if (
Entry.Imm2Limit) {
786 unsigned Imm =
MI->getOperand(2).getImm();
787 unsigned Limit = (1 <<
Entry.Imm2Limit) - 1;
797 const MCInstrDesc &NewMCID =
TII->get(
Entry.NarrowOpc2);
800 bool SkipPred =
false;
811 const MCInstrDesc &MCID =
MI->getDesc();
815 if (HasCC &&
MI->getOperand(
NumOps-1).isDead())
818 if (!VerifyPredAndCC(
MI, Entry,
true,
Pred, LiveCPSR, HasCC, CCDead))
824 canAddPseudoFlagDep(
MI, IsSelfLoop))
829 MachineInstrBuilder MIB =
BuildMI(
MBB,
MI, dl, NewMCID);
830 MIB.
add(
MI->getOperand(0));
836 for (
unsigned i = 1, e =
MI->getNumOperands(); i != e; ++i) {
839 if (SkipPred && MCID.
operands()[i].isPredicate())
841 MIB.
add(
MI->getOperand(i));
848 <<
" to 16-bit: " << *MIB);
856Thumb2SizeReduce::ReduceToNarrow(MachineBasicBlock &
MBB, MachineInstr *
MI,
857 const ReduceEntry &Entry,
858 bool LiveCPSR,
bool IsSelfLoop) {
859 int ReduceLimit = STI->
getCLOpts().t2_reduce_limit;
860 if (ReduceLimit != -1 && ((
int)NumNarrows >= ReduceLimit))
863 if (!OptimizeSize &&
Entry.AvoidMovs && STI->avoidMOVsShifterOperand())
868 unsigned Limit = ~0
U;
870 Limit = (1 <<
Entry.Imm1Limit) - 1;
872 const MCInstrDesc &MCID =
MI->getDesc();
874 if (MCID.
operands()[i].isPredicate())
876 const MachineOperand &MO =
MI->getOperand(i);
879 if (!
Reg ||
Reg == ARM::CPSR)
883 }
else if (MO.
isImm() && !MCID.
operands()[i].isPredicate()) {
884 if (((
unsigned)MO.
getImm()) > Limit)
890 const MCInstrDesc &NewMCID =
TII->get(
Entry.NarrowOpc1);
893 bool SkipPred =
false;
907 if (HasCC &&
MI->getOperand(
NumOps-1).isDead())
910 if (!VerifyPredAndCC(
MI, Entry,
false,
Pred, LiveCPSR, HasCC, CCDead))
916 canAddPseudoFlagDep(
MI, IsSelfLoop))
921 MachineInstrBuilder MIB =
BuildMI(
MBB,
MI, dl, NewMCID);
927 MIB.
add(
MI->getOperand(0));
934 MIB.
add(
MI->getOperand(0));
936 MIB.
add(
MI->getOperand(0));
943 for (
unsigned i = 1, e =
MI->getNumOperands(); i != e; ++i) {
946 if ((MCID.
getOpcode() == ARM::t2RSBSri ||
951 MCID.
getOpcode() == ARM::t2UXTH) && i == 2)
955 if (SkipPred && isPred)
957 const MachineOperand &MO =
MI->getOperand(i);
971 <<
" to 16-bit: " << *MIB);
978bool Thumb2SizeReduce::ReduceMI(MachineBasicBlock &
MBB, MachineInstr *
MI,
979 bool LiveCPSR,
bool IsSelfLoop,
980 bool SkipPrologueEpilogue) {
981 unsigned Opcode =
MI->getOpcode();
982 auto OPI = ReduceOpcodeMap.
find(Opcode);
983 if (OPI == ReduceOpcodeMap.
end())
992 return ReduceSpecial(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop);
995 if (
Entry.NarrowOpc2 &&
996 ReduceTo2Addr(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop))
1000 if (
Entry.NarrowOpc1 &&
1001 ReduceToNarrow(
MBB,
MI, Entry, LiveCPSR, IsSelfLoop))
1007bool Thumb2SizeReduce::ReduceMBB(MachineBasicBlock &
MBB,
1008 bool SkipPrologueEpilogue) {
1013 return Succ->isLiveIn(ARM::CPSR);
1016 DenseMap<const MachineInstr *, bool> CPSRLiveAfter;
1018 if (
MI.isBundle() ||
MI.isDebugInstr())
1020 if (ReduceOpcodeMap.
contains(
MI.getOpcode()))
1021 CPSRLiveAfter[&
MI] = LiveCPSR;
1022 if (
MI.definesRegister(ARM::CPSR,
nullptr))
1024 if (
MI.readsRegister(ARM::CPSR,
nullptr))
1029 HighLatencyCPSR =
false;
1033 const MBBInfo &PInfo = BlockInfo[
Pred->getNumber()];
1034 if (!PInfo.Visited) {
1039 if (PInfo.HighLatencyCPSR) {
1040 HighLatencyCPSR =
true;
1050 for (; MII !=
E; MII = NextMII) {
1051 NextMII = std::next(MII);
1053 MachineInstr *
MI = &*MII;
1054 if (
MI->isBundle() ||
MI->isDebugInstr())
1057 LiveCPSR = CPSRLiveAfter.
lookup(
MI);
1060 bool NextInSameBundle = NextMII !=
E && NextMII->isBundledWithPred();
1062 if (
ReduceMI(
MBB,
MI, LiveCPSR, IsSelfLoop, SkipPrologueEpilogue)) {
1068 if (NextInSameBundle && !NextMII->isBundledWithPred())
1069 NextMII->bundleWithPred();
1078 HighLatencyCPSR =
false;
1080 }
else if (
MI->definesRegister(ARM::CPSR,
nullptr)) {
1089 Info.HighLatencyCPSR = HighLatencyCPSR;
1090 Info.Visited =
true;
1095 if (PredicateFtor && !PredicateFtor(MF.
getFunction()))
1113 ReversePostOrderTraversal<MachineFunction*> RPOT(&MF);
1116 for (MachineBasicBlock *
MBB : RPOT)
1124 std::function<
bool(
const Function &)> Ftor) {
1125 return new Thumb2SizeReduce(std::move(Ftor));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Promote Memory to Register
static bool ReduceMBB(MachineBasicBlock &MBB, const MipsInstrInfo *MipsII)
Reduces width of instructions in the specified basic block.
static ReduceEntryVector ReduceTable
static bool ReduceMI(const MachineBasicBlock::instr_iterator &MII, MachineBasicBlock::instr_iterator &NextMII, const MipsInstrInfo *MipsII)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
dot regions Print regions of function to dot true view regions View regions of function(with no function bodies)"
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool HasImplicitCPSRDef(const MCInstrDesc &MCID)
static bool VerifyLowRegs(const MachineInstr *MI)
static bool isHighLatencyCPSR(const MachineInstr *Def)
#define THUMB2_SIZE_REDUCE_NAME
const ARMBaseInstrInfo * getInstrInfo() const override
bool isThumb1Only() const
const ARMOptions & getCLOpts() const
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
iterator find(const_arg_type_t< KeyT > Val)
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
FunctionPass class - This class is used to implement most global optimizations.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool hasOptionalDef() const
Set if this instruction has an optional definition, e.g.
bool isPredicable() const
Return true if this instruction has a predicate operand that controls execution.
unsigned getOpcode() const
Return the opcode number for this descriptor.
instr_iterator instr_begin()
instr_iterator erase_instr(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Instructions::iterator instr_iterator
instr_iterator instr_end()
iterator_range< succ_iterator > successors()
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool needsWinCFI() const
True if this function uses SEH unwind opcodes and needs an unwind table entry.
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Representation of each machine instruction.
LLVM_ABI void eraseFromBundle()
Unlink 'this' from its basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void setIsDead(bool Val=true)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
Register getReg() const
getReg - Returns the register number.
LLVM_ABI void setIsDef(bool Val=true)
Change a def to a use, or a use to a def.
Wrapper class representing virtual and physical registers.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static const unsigned CommuteAnyOperandIndex
A Use represents the edge between a Value definition and its users.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
NodeAddr< UseNode * > Use
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr RegState getKillRegState(bool B)
static bool isARMLowRegister(MCRegister Reg)
isARMLowRegister - Returns true if the register is a low register (r0-r7).
constexpr RegState getInternalReadRegState(bool B)
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr RegState getDefRegState(bool B)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
ARMCC::CondCodes getInstrPredicate(const MachineInstr &MI, Register &PredReg)
getInstrPredicate - If instruction is predicated, returns its predicate condition,...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
static MachineOperand t1CondCodeOp(bool isDead=false)
Get the operand corresponding to the conditional code result for Thumb1.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
static MachineOperand condCodeOp(unsigned CCReg=0)
Get the operand corresponding to the conditional code result.
FunctionPass * createThumb2SizeReductionPass(std::function< bool(const Function &)> Ftor=nullptr)
createThumb2SizeReductionPass - Returns an instance of the Thumb2 size reduction pass.
Implement std::hash so that hash_code can be used in STL containers.