21void MipsAnalyzeImmediate::AddInstr(
InstSeqLs &SeqLs,
const Inst &
I) {
32void MipsAnalyzeImmediate::GetInstSeqLsADDiu(
uint64_t Imm,
unsigned RemSize,
34 GetInstSeqLs((Imm + 0x8000ULL) & 0xffffffffffff0000ULL, RemSize, SeqLs);
35 AddInstr(SeqLs, Inst(ADDiu, Imm & 0xffffULL));
38void MipsAnalyzeImmediate::GetInstSeqLsORi(
uint64_t Imm,
unsigned RemSize,
40 GetInstSeqLs(Imm & 0xffffffffffff0000ULL, RemSize, SeqLs);
41 AddInstr(SeqLs, Inst(ORi, Imm & 0xffffULL));
44void MipsAnalyzeImmediate::GetInstSeqLsSLL(
uint64_t Imm,
unsigned RemSize,
47 GetInstSeqLs(Imm >> Shamt, RemSize - Shamt, SeqLs);
48 AddInstr(SeqLs, Inst(SLL, Shamt));
51void MipsAnalyzeImmediate::GetInstSeqLs(
uint64_t Imm,
unsigned RemSize,
53 uint64_t MaskedImm =
Imm & (0xffffffffffffffffULL >> (64 - Size));
61 AddInstr(SeqLs, Inst(ADDiu, MaskedImm));
66 if (!(Imm & 0xffff)) {
67 GetInstSeqLsSLL(Imm, RemSize, SeqLs);
71 GetInstSeqLsADDiu(Imm, RemSize, SeqLs);
77 GetInstSeqLsORi(Imm, RemSize, SeqLsORi);
78 SeqLs.append(std::make_move_iterator(SeqLsORi.begin()),
79 std::make_move_iterator(SeqLsORi.end()));
89void MipsAnalyzeImmediate::ReplaceADDiuSLLWithLUi(
InstSeq &Seq) {
92 if ((Seq.size() < 2) || (Seq[0].Opc != ADDiu) ||
93 (Seq[1].Opc != SLL) || (Seq[1].ImmOpnd < 16))
97 int64_t
Imm = SignExtend64<16>(Seq[0].ImmOpnd);
98 int64_t ShiftedImm = (
uint64_t)Imm << (Seq[1].ImmOpnd - 16);
100 if (!isInt<16>(ShiftedImm))
105 Seq[0].ImmOpnd = (
unsigned)(ShiftedImm & 0xffff);
106 Seq.erase(Seq.begin() + 1);
109void MipsAnalyzeImmediate::GetShortestSeq(InstSeqLs &SeqLs,
InstSeq &Insts) {
112 unsigned ShortestLength = 8;
115 ReplaceADDiuSLLWithLUi(*S);
118 if (S->size() < ShortestLength) {
120 ShortestLength = S->size();
125 Insts.append(ShortestSeq->begin(), ShortestSeq->end());
130 bool LastInstrIsADDiu) {
139 ADDiu = Mips::DADDiu;
148 if (LastInstrIsADDiu | !Imm)
149 GetInstSeqLsADDiu(Imm, Size, SeqLs);
151 GetInstSeqLs(Imm, Size, SeqLs);
154 GetShortestSeq(SeqLs, Insts);
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.