15 #ifndef LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H 16 #define LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H 47 template <
class TgtInstructionSelector,
class PredicateBitset,
48 class ComplexMatcherMemFn,
class CustomRendererFn>
58 uint64_t CurrentIdx = 0;
61 enum RejectAction { RejectAndGiveUp, RejectAndResume };
62 auto handleReject = [&]() -> RejectAction {
64 dbgs() << CurrentIdx <<
": Rejected\n");
65 if (OnFailResumeAt.
empty())
66 return RejectAndGiveUp;
69 dbgs() << CurrentIdx <<
": Resume at " << CurrentIdx <<
" (" 70 << OnFailResumeAt.
size() <<
" try-blocks remain)\n");
71 return RejectAndResume;
75 assert(CurrentIdx != ~0u &&
"Invalid MatchTable index");
76 int64_t MatcherOpcode = MatchTable[CurrentIdx++];
77 switch (MatcherOpcode) {
80 dbgs() << CurrentIdx <<
": Begin try-block\n");
81 OnFailResumeAt.
push_back(MatchTable[CurrentIdx++]);
86 int64_t NewInsnID = MatchTable[CurrentIdx++];
87 int64_t InsnID = MatchTable[CurrentIdx++];
88 int64_t OpIdx = MatchTable[CurrentIdx++];
92 assert(NewInsnID != 0 &&
"Refusing to modify MIs[0]");
97 dbgs() << CurrentIdx <<
": Not a register\n");
98 if (handleReject() == RejectAndGiveUp)
104 dbgs() << CurrentIdx <<
": Is a physical register\n");
105 if (handleReject() == RejectAndGiveUp)
111 if ((
size_t)NewInsnID < State.
MIs.
size())
112 State.
MIs[NewInsnID] = NewMI;
115 "Expected to store MIs in order");
119 dbgs() << CurrentIdx <<
": MIs[" << NewInsnID
120 <<
"] = GIM_RecordInsn(" << InsnID <<
", " << OpIdx
126 int64_t ExpectedBitsetID = MatchTable[CurrentIdx++];
129 <<
": GIM_CheckFeatures(ExpectedBitsetID=" 130 << ExpectedBitsetID <<
")\n");
131 if ((AvailableFeatures & ISelInfo.
FeatureBitsets[ExpectedBitsetID]) !=
133 if (handleReject() == RejectAndGiveUp)
140 int64_t InsnID = MatchTable[CurrentIdx++];
141 int64_t
Expected = MatchTable[CurrentIdx++];
143 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
144 unsigned Opcode = State.
MIs[InsnID]->getOpcode();
147 dbgs() << CurrentIdx <<
": GIM_CheckOpcode(MIs[" << InsnID
148 <<
"], ExpectedOpcode=" << Expected
149 <<
") // Got=" << Opcode <<
"\n");
150 if (Opcode != Expected) {
151 if (handleReject() == RejectAndGiveUp)
158 int64_t InsnID = MatchTable[CurrentIdx++];
159 int64_t LowerBound = MatchTable[CurrentIdx++];
160 int64_t UpperBound = MatchTable[CurrentIdx++];
161 int64_t
Default = MatchTable[CurrentIdx++];
163 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
164 const int64_t Opcode = State.
MIs[InsnID]->getOpcode();
167 dbgs() << CurrentIdx <<
": GIM_SwitchOpcode(MIs[" << InsnID <<
"], [" 168 << LowerBound <<
", " << UpperBound <<
"), Default=" << Default
169 <<
", JumpTable...) // Got=" << Opcode <<
"\n";
171 if (Opcode < LowerBound || UpperBound <= Opcode) {
175 CurrentIdx = MatchTable[CurrentIdx + (Opcode - LowerBound)];
185 int64_t InsnID = MatchTable[CurrentIdx++];
186 int64_t OpIdx = MatchTable[CurrentIdx++];
187 int64_t LowerBound = MatchTable[CurrentIdx++];
188 int64_t UpperBound = MatchTable[CurrentIdx++];
189 int64_t
Default = MatchTable[CurrentIdx++];
191 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
195 dbgs() << CurrentIdx <<
": GIM_SwitchType(MIs[" << InsnID
196 <<
"]->getOperand(" << OpIdx <<
"), [" << LowerBound <<
", " 197 << UpperBound <<
"), Default=" << Default
198 <<
", JumpTable...) // Got=";
200 dbgs() <<
"Not a VReg\n";
209 const auto TyI = ISelInfo.
TypeIDMap.find(Ty);
214 const int64_t
TypeID = TyI->second;
215 if (TypeID < LowerBound || UpperBound <= TypeID) {
219 CurrentIdx = MatchTable[CurrentIdx + (TypeID - LowerBound)];
229 int64_t InsnID = MatchTable[CurrentIdx++];
230 int64_t
Expected = MatchTable[CurrentIdx++];
232 dbgs() << CurrentIdx <<
": GIM_CheckNumOperands(MIs[" 233 << InsnID <<
"], Expected=" << Expected <<
")\n");
234 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
235 if (State.
MIs[InsnID]->getNumOperands() != Expected) {
236 if (handleReject() == RejectAndGiveUp)
242 int64_t InsnID = MatchTable[CurrentIdx++];
243 int64_t
Predicate = MatchTable[CurrentIdx++];
246 << CurrentIdx <<
": GIM_CheckI64ImmPredicate(MIs[" 247 << InsnID <<
"], Predicate=" << Predicate <<
")\n");
248 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
249 assert(State.
MIs[InsnID]->getOpcode() == TargetOpcode::G_CONSTANT &&
250 "Expected G_CONSTANT");
253 if (State.
MIs[InsnID]->getOperand(1).isCImm())
254 Value = State.
MIs[InsnID]->getOperand(1).getCImm()->getSExtValue();
255 else if (State.
MIs[InsnID]->getOperand(1).isImm())
256 Value = State.
MIs[InsnID]->getOperand(1).getImm();
261 if (handleReject() == RejectAndGiveUp)
266 int64_t InsnID = MatchTable[CurrentIdx++];
267 int64_t
Predicate = MatchTable[CurrentIdx++];
270 << CurrentIdx <<
": GIM_CheckAPIntImmPredicate(MIs[" 271 << InsnID <<
"], Predicate=" << Predicate <<
")\n");
272 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
273 assert(State.
MIs[InsnID]->getOpcode() == TargetOpcode::G_CONSTANT &&
274 "Expected G_CONSTANT");
277 if (State.
MIs[InsnID]->getOperand(1).isCImm())
278 Value = State.
MIs[InsnID]->getOperand(1).getCImm()->getValue();
283 if (handleReject() == RejectAndGiveUp)
288 int64_t InsnID = MatchTable[CurrentIdx++];
289 int64_t
Predicate = MatchTable[CurrentIdx++];
292 << CurrentIdx <<
": GIM_CheckAPFloatImmPredicate(MIs[" 293 << InsnID <<
"], Predicate=" << Predicate <<
")\n");
294 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
295 assert(State.
MIs[InsnID]->getOpcode() == TargetOpcode::G_FCONSTANT &&
296 "Expected G_FCONSTANT");
297 assert(State.
MIs[InsnID]->getOperand(1).isFPImm() &&
"Expected FPImm operand");
299 APFloat Value = State.
MIs[InsnID]->getOperand(1).getFPImm()->getValueAPF();
302 if (handleReject() == RejectAndGiveUp)
307 int64_t InsnID = MatchTable[CurrentIdx++];
308 int64_t
Predicate = MatchTable[CurrentIdx++];
311 << CurrentIdx <<
": GIM_CheckCxxPredicate(MIs[" 312 << InsnID <<
"], Predicate=" << Predicate <<
")\n");
313 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
317 if (handleReject() == RejectAndGiveUp)
322 int64_t InsnID = MatchTable[CurrentIdx++];
325 dbgs() << CurrentIdx <<
": GIM_CheckAtomicOrdering(MIs[" 326 << InsnID <<
"], " << (uint64_t)Ordering <<
")\n");
327 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
328 if (!State.
MIs[InsnID]->hasOneMemOperand())
329 if (handleReject() == RejectAndGiveUp)
332 for (
const auto &MMO : State.
MIs[InsnID]->memoperands())
333 if (MMO->getOrdering() != Ordering)
334 if (handleReject() == RejectAndGiveUp)
339 int64_t InsnID = MatchTable[CurrentIdx++];
343 <<
": GIM_CheckAtomicOrderingOrStrongerThan(MIs[" 344 << InsnID <<
"], " << (uint64_t)Ordering <<
")\n");
345 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
346 if (!State.
MIs[InsnID]->hasOneMemOperand())
347 if (handleReject() == RejectAndGiveUp)
350 for (
const auto &MMO : State.
MIs[InsnID]->memoperands())
352 if (handleReject() == RejectAndGiveUp)
357 int64_t InsnID = MatchTable[CurrentIdx++];
361 <<
": GIM_CheckAtomicOrderingWeakerThan(MIs[" 362 << InsnID <<
"], " << (uint64_t)Ordering <<
")\n");
363 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
364 if (!State.
MIs[InsnID]->hasOneMemOperand())
365 if (handleReject() == RejectAndGiveUp)
368 for (
const auto &MMO : State.
MIs[InsnID]->memoperands())
370 if (handleReject() == RejectAndGiveUp)
375 int64_t InsnID = MatchTable[CurrentIdx++];
376 int64_t MMOIdx = MatchTable[CurrentIdx++];
378 const int NumAddrSpace = MatchTable[CurrentIdx++];
380 if (State.
MIs[InsnID]->getNumMemOperands() <= MMOIdx) {
381 if (handleReject() == RejectAndGiveUp)
388 const uint64_t LastIdx = CurrentIdx + NumAddrSpace;
391 = *(State.
MIs[InsnID]->memoperands_begin() + MMOIdx);
395 for (
int I = 0;
I != NumAddrSpace; ++
I) {
396 unsigned AddrSpace = MatchTable[CurrentIdx++];
399 dbgs() <<
"addrspace(" << MMOAddrSpace <<
") vs " 400 << AddrSpace <<
'\n');
402 if (AddrSpace == MMOAddrSpace) {
408 CurrentIdx = LastIdx;
409 if (!Success && handleReject() == RejectAndGiveUp)
414 int64_t InsnID = MatchTable[CurrentIdx++];
415 int64_t MMOIdx = MatchTable[CurrentIdx++];
416 unsigned MinAlign = MatchTable[CurrentIdx++];
418 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
420 if (State.
MIs[InsnID]->getNumMemOperands() <= MMOIdx) {
421 if (handleReject() == RejectAndGiveUp)
427 = *(State.
MIs[InsnID]->memoperands_begin() + MMOIdx);
429 dbgs() << CurrentIdx <<
": GIM_CheckMemoryAlignment" 430 <<
"(MIs[" << InsnID <<
"]->memoperands() + " << MMOIdx
431 <<
")->getAlignment() >= " << MinAlign <<
")\n");
432 if (MMO->
getAlignment() < MinAlign && handleReject() == RejectAndGiveUp)
438 int64_t InsnID = MatchTable[CurrentIdx++];
439 int64_t MMOIdx = MatchTable[CurrentIdx++];
440 uint64_t
Size = MatchTable[CurrentIdx++];
444 <<
": GIM_CheckMemorySizeEqual(MIs[" << InsnID
445 <<
"]->memoperands() + " << MMOIdx
446 <<
", Size=" << Size <<
")\n");
447 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
449 if (State.
MIs[InsnID]->getNumMemOperands() <= MMOIdx) {
450 if (handleReject() == RejectAndGiveUp)
461 if (handleReject() == RejectAndGiveUp)
469 int64_t InsnID = MatchTable[CurrentIdx++];
470 int64_t MMOIdx = MatchTable[CurrentIdx++];
471 int64_t OpIdx = MatchTable[CurrentIdx++];
475 dbgs() << CurrentIdx <<
": GIM_CheckMemorySize" 481 <<
"LLT(MIs[" << InsnID <<
"]->memoperands() + " << MMOIdx
482 <<
", OpIdx=" << OpIdx <<
")\n");
483 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
488 dbgs() << CurrentIdx <<
": Not a register\n");
489 if (handleReject() == RejectAndGiveUp)
494 if (State.
MIs[InsnID]->getNumMemOperands() <= MMOIdx) {
495 if (handleReject() == RejectAndGiveUp)
505 if (handleReject() == RejectAndGiveUp)
509 if (handleReject() == RejectAndGiveUp)
513 if (handleReject() == RejectAndGiveUp)
519 int64_t InsnID = MatchTable[CurrentIdx++];
520 int64_t OpIdx = MatchTable[CurrentIdx++];
521 int64_t
TypeID = MatchTable[CurrentIdx++];
523 dbgs() << CurrentIdx <<
": GIM_CheckType(MIs[" << InsnID
524 <<
"]->getOperand(" << OpIdx
525 <<
"), TypeID=" << TypeID <<
")\n");
526 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
530 if (handleReject() == RejectAndGiveUp)
536 int64_t InsnID = MatchTable[CurrentIdx++];
537 int64_t OpIdx = MatchTable[CurrentIdx++];
538 int64_t SizeInBits = MatchTable[CurrentIdx++];
541 dbgs() << CurrentIdx <<
": GIM_CheckPointerToAny(MIs[" 542 << InsnID <<
"]->getOperand(" << OpIdx
543 <<
"), SizeInBits=" << SizeInBits <<
")\n");
544 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
549 if (SizeInBits == 0) {
555 assert(SizeInBits != 0 &&
"Pointer size must be known");
559 if (handleReject() == RejectAndGiveUp)
561 }
else if (handleReject() == RejectAndGiveUp)
567 int64_t InsnID = MatchTable[CurrentIdx++];
568 int64_t OpIdx = MatchTable[CurrentIdx++];
569 int64_t RCEnum = MatchTable[CurrentIdx++];
571 dbgs() << CurrentIdx <<
": GIM_CheckRegBankForClass(MIs[" 572 << InsnID <<
"]->getOperand(" << OpIdx
573 <<
"), RCEnum=" << RCEnum <<
")\n");
574 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
580 if (handleReject() == RejectAndGiveUp)
587 int64_t InsnID = MatchTable[CurrentIdx++];
588 int64_t OpIdx = MatchTable[CurrentIdx++];
589 int64_t RendererID = MatchTable[CurrentIdx++];
590 int64_t ComplexPredicateID = MatchTable[CurrentIdx++];
592 dbgs() << CurrentIdx <<
": State.Renderers[" << RendererID
593 <<
"] = GIM_CheckComplexPattern(MIs[" << InsnID
594 <<
"]->getOperand(" << OpIdx
595 <<
"), ComplexPredicateID=" << ComplexPredicateID
597 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
601 State.
MIs[InsnID]->getOperand(OpIdx));
605 if (handleReject() == RejectAndGiveUp)
611 int64_t InsnID = MatchTable[CurrentIdx++];
612 int64_t OpIdx = MatchTable[CurrentIdx++];
613 int64_t
Value = MatchTable[CurrentIdx++];
615 dbgs() << CurrentIdx <<
": GIM_CheckConstantInt(MIs[" 616 << InsnID <<
"]->getOperand(" << OpIdx
617 <<
"), Value=" << Value <<
")\n");
618 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
626 if (handleReject() == RejectAndGiveUp)
629 }
else if (handleReject() == RejectAndGiveUp)
636 int64_t InsnID = MatchTable[CurrentIdx++];
637 int64_t OpIdx = MatchTable[CurrentIdx++];
638 int64_t
Value = MatchTable[CurrentIdx++];
640 dbgs() << CurrentIdx <<
": GIM_CheckLiteralInt(MIs[" 641 << InsnID <<
"]->getOperand(" << OpIdx
642 <<
"), Value=" << Value <<
")\n");
643 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
651 if (handleReject() == RejectAndGiveUp)
658 int64_t InsnID = MatchTable[CurrentIdx++];
659 int64_t OpIdx = MatchTable[CurrentIdx++];
660 int64_t
Value = MatchTable[CurrentIdx++];
662 dbgs() << CurrentIdx <<
": GIM_CheckIntrinsicID(MIs[" 663 << InsnID <<
"]->getOperand(" << OpIdx
664 <<
"), Value=" << Value <<
")\n");
665 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
668 if (handleReject() == RejectAndGiveUp)
673 int64_t InsnID = MatchTable[CurrentIdx++];
674 int64_t OpIdx = MatchTable[CurrentIdx++];
675 int64_t
Value = MatchTable[CurrentIdx++];
677 dbgs() << CurrentIdx <<
": GIM_CheckCmpPredicate(MIs[" 678 << InsnID <<
"]->getOperand(" << OpIdx
679 <<
"), Value=" << Value <<
")\n");
680 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
683 if (handleReject() == RejectAndGiveUp)
688 int64_t InsnID = MatchTable[CurrentIdx++];
689 int64_t OpIdx = MatchTable[CurrentIdx++];
691 dbgs() << CurrentIdx <<
": GIM_CheckIsMBB(MIs[" << InsnID
692 <<
"]->getOperand(" << OpIdx <<
"))\n");
693 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
694 if (!State.
MIs[InsnID]->getOperand(OpIdx).isMBB()) {
695 if (handleReject() == RejectAndGiveUp)
701 int64_t InsnID = MatchTable[CurrentIdx++];
702 int64_t OpIdx = MatchTable[CurrentIdx++];
704 dbgs() << CurrentIdx <<
": GIM_CheckIsImm(MIs[" << InsnID
705 <<
"]->getOperand(" << OpIdx <<
"))\n");
706 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
707 if (!State.
MIs[InsnID]->getOperand(OpIdx).isImm()) {
708 if (handleReject() == RejectAndGiveUp)
714 int64_t InsnID = MatchTable[CurrentIdx++];
716 dbgs() << CurrentIdx <<
": GIM_CheckIsSafeToFold(MIs[" 717 << InsnID <<
"])\n");
718 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
720 if (handleReject() == RejectAndGiveUp)
726 int64_t InsnID = MatchTable[CurrentIdx++];
727 int64_t OpIdx = MatchTable[CurrentIdx++];
728 int64_t OtherInsnID = MatchTable[CurrentIdx++];
729 int64_t OtherOpIdx = MatchTable[CurrentIdx++];
731 dbgs() << CurrentIdx <<
": GIM_CheckIsSameOperand(MIs[" 732 << InsnID <<
"][" << OpIdx <<
"], MIs[" 733 << OtherInsnID <<
"][" << OtherOpIdx <<
"])\n");
734 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
735 assert(State.
MIs[OtherInsnID] !=
nullptr &&
"Used insn before defined");
736 if (!State.
MIs[InsnID]->getOperand(OpIdx).isIdenticalTo(
737 State.
MIs[OtherInsnID]->getOperand(OtherOpIdx))) {
738 if (handleReject() == RejectAndGiveUp)
745 dbgs() << CurrentIdx <<
": GIM_Reject\n");
746 if (handleReject() == RejectAndGiveUp)
751 int64_t OldInsnID = MatchTable[CurrentIdx++];
752 uint64_t NewInsnID = MatchTable[CurrentIdx++];
753 int64_t NewOpcode = MatchTable[CurrentIdx++];
754 if (NewInsnID >= OutMIs.
size())
755 OutMIs.
resize(NewInsnID + 1);
758 State.
MIs[OldInsnID]);
759 OutMIs[NewInsnID]->setDesc(TII.
get(NewOpcode));
761 dbgs() << CurrentIdx <<
": GIR_MutateOpcode(OutMIs[" 762 << NewInsnID <<
"], MIs[" << OldInsnID <<
"], " 763 << NewOpcode <<
")\n");
768 uint64_t NewInsnID = MatchTable[CurrentIdx++];
769 int64_t Opcode = MatchTable[CurrentIdx++];
770 if (NewInsnID >= OutMIs.
size())
771 OutMIs.
resize(NewInsnID + 1);
773 OutMIs[NewInsnID] =
BuildMI(*State.
MIs[0]->getParent(), State.
MIs[0],
774 State.
MIs[0]->getDebugLoc(), TII.
get(Opcode));
776 dbgs() << CurrentIdx <<
": GIR_BuildMI(OutMIs[" 777 << NewInsnID <<
"], " << Opcode <<
")\n");
782 int64_t NewInsnID = MatchTable[CurrentIdx++];
783 int64_t OldInsnID = MatchTable[CurrentIdx++];
784 int64_t OpIdx = MatchTable[CurrentIdx++];
785 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
786 OutMIs[NewInsnID].add(State.
MIs[OldInsnID]->getOperand(OpIdx));
789 << CurrentIdx <<
": GIR_Copy(OutMIs[" << NewInsnID
790 <<
"], MIs[" << OldInsnID <<
"], " << OpIdx <<
")\n");
795 int64_t NewInsnID = MatchTable[CurrentIdx++];
796 int64_t OldInsnID = MatchTable[CurrentIdx++];
797 int64_t OpIdx = MatchTable[CurrentIdx++];
798 int64_t ZeroReg = MatchTable[CurrentIdx++];
799 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
802 OutMIs[NewInsnID].addReg(ZeroReg);
804 OutMIs[NewInsnID].add(MO);
806 dbgs() << CurrentIdx <<
": GIR_CopyOrAddZeroReg(OutMIs[" 807 << NewInsnID <<
"], MIs[" << OldInsnID <<
"], " 808 << OpIdx <<
", " << ZeroReg <<
")\n");
813 int64_t NewInsnID = MatchTable[CurrentIdx++];
814 int64_t OldInsnID = MatchTable[CurrentIdx++];
815 int64_t OpIdx = MatchTable[CurrentIdx++];
816 int64_t SubRegIdx = MatchTable[CurrentIdx++];
817 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
818 OutMIs[NewInsnID].addReg(State.
MIs[OldInsnID]->getOperand(OpIdx).getReg(),
821 dbgs() << CurrentIdx <<
": GIR_CopySubReg(OutMIs[" 822 << NewInsnID <<
"], MIs[" << OldInsnID <<
"], " 823 << OpIdx <<
", " << SubRegIdx <<
")\n");
828 int64_t InsnID = MatchTable[CurrentIdx++];
829 int64_t RegNum = MatchTable[CurrentIdx++];
830 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
833 dbgs() << CurrentIdx <<
": GIR_AddImplicitDef(OutMIs[" 834 << InsnID <<
"], " << RegNum <<
")\n");
839 int64_t InsnID = MatchTable[CurrentIdx++];
840 int64_t RegNum = MatchTable[CurrentIdx++];
841 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
844 dbgs() << CurrentIdx <<
": GIR_AddImplicitUse(OutMIs[" 845 << InsnID <<
"], " << RegNum <<
")\n");
850 int64_t InsnID = MatchTable[CurrentIdx++];
851 int64_t RegNum = MatchTable[CurrentIdx++];
852 uint64_t RegFlags = MatchTable[CurrentIdx++];
853 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
854 OutMIs[InsnID].addReg(RegNum, RegFlags);
857 dbgs() << CurrentIdx <<
": GIR_AddRegister(OutMIs[" 858 << InsnID <<
"], " << RegNum <<
", " << RegFlags <<
")\n");
863 int64_t InsnID = MatchTable[CurrentIdx++];
864 int64_t TempRegID = MatchTable[CurrentIdx++];
865 uint64_t TempRegFlags = MatchTable[CurrentIdx++];
866 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
867 OutMIs[InsnID].addReg(State.
TempRegisters[TempRegID], TempRegFlags);
869 dbgs() << CurrentIdx <<
": GIR_AddTempRegister(OutMIs[" 870 << InsnID <<
"], TempRegisters[" << TempRegID
871 <<
"], " << TempRegFlags <<
")\n");
876 int64_t InsnID = MatchTable[CurrentIdx++];
877 int64_t Imm = MatchTable[CurrentIdx++];
878 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
879 OutMIs[InsnID].addImm(Imm);
881 dbgs() << CurrentIdx <<
": GIR_AddImm(OutMIs[" << InsnID
882 <<
"], " << Imm <<
")\n");
887 int64_t InsnID = MatchTable[CurrentIdx++];
888 int64_t RendererID = MatchTable[CurrentIdx++];
889 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
890 for (
const auto &RenderOpFn : State.
Renderers[RendererID])
891 RenderOpFn(OutMIs[InsnID]);
893 dbgs() << CurrentIdx <<
": GIR_ComplexRenderer(OutMIs[" 894 << InsnID <<
"], " << RendererID <<
")\n");
898 int64_t InsnID = MatchTable[CurrentIdx++];
899 int64_t RendererID = MatchTable[CurrentIdx++];
900 int64_t RenderOpID = MatchTable[CurrentIdx++];
901 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
902 State.
Renderers[RendererID][RenderOpID](OutMIs[InsnID]);
905 <<
": GIR_ComplexSubOperandRenderer(OutMIs[" 906 << InsnID <<
"], " << RendererID <<
", " 907 << RenderOpID <<
")\n");
912 int64_t NewInsnID = MatchTable[CurrentIdx++];
913 int64_t OldInsnID = MatchTable[CurrentIdx++];
914 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
915 assert(State.
MIs[OldInsnID]->getOpcode() == TargetOpcode::G_CONSTANT &&
"Expected G_CONSTANT");
916 if (State.
MIs[OldInsnID]->getOperand(1).isCImm()) {
917 OutMIs[NewInsnID].addImm(
918 State.
MIs[OldInsnID]->getOperand(1).getCImm()->getSExtValue());
919 }
else if (State.
MIs[OldInsnID]->getOperand(1).isImm())
920 OutMIs[NewInsnID].
add(State.
MIs[OldInsnID]->getOperand(1));
924 dbgs() << CurrentIdx <<
": GIR_CopyConstantAsSImm(OutMIs[" 925 << NewInsnID <<
"], MIs[" << OldInsnID <<
"])\n");
931 int64_t NewInsnID = MatchTable[CurrentIdx++];
932 int64_t OldInsnID = MatchTable[CurrentIdx++];
933 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
934 assert(State.
MIs[OldInsnID]->getOpcode() == TargetOpcode::G_FCONSTANT &&
"Expected G_FCONSTANT");
935 if (State.
MIs[OldInsnID]->getOperand(1).isFPImm())
936 OutMIs[NewInsnID].addFPImm(
937 State.
MIs[OldInsnID]->getOperand(1).getFPImm());
941 dbgs() << CurrentIdx <<
": GIR_CopyFPConstantAsFPImm(OutMIs[" 942 << NewInsnID <<
"], MIs[" << OldInsnID <<
"])\n");
947 int64_t InsnID = MatchTable[CurrentIdx++];
948 int64_t OldInsnID = MatchTable[CurrentIdx++];
949 int64_t RendererFnID = MatchTable[CurrentIdx++];
950 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
952 dbgs() << CurrentIdx <<
": GIR_CustomRenderer(OutMIs[" 953 << InsnID <<
"], MIs[" << OldInsnID <<
"], " 954 << RendererFnID <<
")\n");
956 OutMIs[InsnID], *State.
MIs[OldInsnID],
961 int64_t InsnID = MatchTable[CurrentIdx++];
962 int64_t OldInsnID = MatchTable[CurrentIdx++];
963 int64_t OpIdx = MatchTable[CurrentIdx++];
964 int64_t RendererFnID = MatchTable[CurrentIdx++];
965 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
969 dbgs() << CurrentIdx <<
": GIR_CustomOperandRenderer(OutMIs[" 970 << InsnID <<
"], MIs[" << OldInsnID <<
"]->getOperand(" 972 << RendererFnID <<
")\n");
974 *State.
MIs[OldInsnID],
979 int64_t InsnID = MatchTable[CurrentIdx++];
980 int64_t OpIdx = MatchTable[CurrentIdx++];
981 int64_t RCEnum = MatchTable[CurrentIdx++];
982 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
986 dbgs() << CurrentIdx <<
": GIR_ConstrainOperandRC(OutMIs[" 987 << InsnID <<
"], " << OpIdx <<
", " << RCEnum
993 int64_t InsnID = MatchTable[CurrentIdx++];
994 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
999 <<
": GIR_ConstrainSelectedInstOperands(OutMIs[" 1000 << InsnID <<
"])\n");
1005 int64_t InsnID = MatchTable[CurrentIdx++];
1006 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
1009 dbgs() << CurrentIdx <<
": GIR_MergeMemOperands(OutMIs[" 1012 while ((MergeInsnID = MatchTable[CurrentIdx++]) !=
1015 dbgs() <<
", MIs[" << MergeInsnID <<
"]");
1016 for (
const auto &MMO : State.
MIs[MergeInsnID]->memoperands())
1017 OutMIs[InsnID].addMemOperand(MMO);
1024 int64_t InsnID = MatchTable[CurrentIdx++];
1026 "Attempted to erase an undefined instruction");
1027 State.
MIs[InsnID]->eraseFromParent();
1029 dbgs() << CurrentIdx <<
": GIR_EraseFromParent(MIs[" 1030 << InsnID <<
"])\n");
1035 int64_t TempRegID = MatchTable[CurrentIdx++];
1036 int64_t
TypeID = MatchTable[CurrentIdx++];
1041 dbgs() << CurrentIdx <<
": TempRegs[" << TempRegID
1042 <<
"] = GIR_MakeTempReg(" << TypeID <<
")\n");
1047 int64_t RuleID = MatchTable[CurrentIdx++];
1052 << CurrentIdx <<
": GIR_Coverage(" << RuleID <<
")");
1058 dbgs() << CurrentIdx <<
": GIR_Done\n");
1069 #endif // LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H unsigned getAddrSpace() const
This class represents lattice values for constants.
Constrain an instruction operand to a register class.
std::vector< ComplexRendererFns::value_type > Renderers
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
void push_back(const T &Elt)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool constrainOperandRegToRegClass(MachineInstr &I, unsigned OpIdx, const TargetRegisterClass &RC, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Constrain a register operand of an instruction I to a specified register class.
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
uint64_t getSize() const
Return the size in bytes of the memory reference.
const PredicateBitset * FeatureBitsets
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
unsigned const TargetRegisterInfo * TRI
bool equalsInt(uint64_t V) const
A helper method that can be used to determine if the constant contained within is equal to a constant...
const CustomRendererFn * CustomRenderers
Add an implicit register def to the specified instruction.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const ComplexMatcherMemFn * ComplexPredicates
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
Merge all memory operands into instruction.
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Check a memory operation has the specified atomic ordering.
bool isIntrinsicID() const
Holds all the information related to register banks.
A description of a memory reference used in the backend.
const HexagonInstrInfo * TII
bool isStrongerThan(AtomicOrdering ao, AtomicOrdering other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice, which is based on C++'s definition.
Check the specified operands are identical.
Check the specified operand is an MBB.
static StringRef getName(Value *V)
Check the type of a pointer to any address space.
Render operands to the specified instruction using a custom function.
Tagged union holding either a T or a Error.
DenseMap< unsigned, unsigned > TempRegisters
SmallDenseMap< LLT, unsigned, 64 > TypeIDMap
AtomicOrdering
Atomic ordering for LLVM's memory model.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Add an immediate to the specified instruction.
Render operands to the specified instruction using a custom function, reading from a specific operand...
const T & getValue() const LLVM_LVALUE_FUNCTION
uint64_t getSizeInBits() const
Return the size in bits of the memory reference.
Copy an operand to the specified instruction.
Switch over the LLT on the specified instruction operand.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
TargetInstrInfo - Interface to description of machine instruction set.
bool isAtLeastOrStrongerThan(AtomicOrdering ao, AtomicOrdering other)
Add an implicit register use to the specified instruction.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Render sub-operands of complex operands to the specified instruction.
unsigned const MachineRegisterInfo * MRI
virtual bool testMIPredicate_MI(unsigned, const MachineInstr &) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Copy an operand to the specified instruction.
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
Check the operand is a specific integer.
Check the instruction has the right number of operands.
bool executeMatchTable(TgtInstructionSelector &ISel, NewMIVector &OutMIs, MatcherState &State, const ISelInfoTy< PredicateBitset, ComplexMatcherMemFn, CustomRendererFn > &ISelInfo, const int64_t *MatchTable, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures, CodeGenCoverage &CoverageInfo) const
Execute a given matcher table and return true if the match was successful and false otherwise...
unsigned getAddressSpace() const
void setCovered(uint64_t RuleID)
Check if the specified operand is safe to fold into the current instruction.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Switch over the opcode on the specified instruction.
Check a floating point immediate predicate on the specified instruction.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t getAlignment() const
Return the minimum known alignment in bytes of the actual memory reference.
Indicates the end of the variable-length MergeInsnID list in a GIR_MergeMemOperands opcode...
Check the minimum alignment of the memory access for the given machine memory operand.
Check the opcode on the specified instruction.
Check a generic C++ instruction predicate.
Constrain an instructions operands according to the instruction description.
Render a G_CONSTANT operator as a sign-extended immediate.
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
Increment the rule coverage counter.
Check the register bank for the specified operand.
Check the type for the specified operand.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Intrinsic::ID getIntrinsicID() const
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LLVM_NODISCARD T pop_back_val()
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Check the size of the memory access for the given machine memory operand against the size of an opera...
Class for arbitrary precision integers.
Create a new temporary register that's not constrained.
Copy an operand to the specified instruction or add a zero register if the operand is a zero immediat...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Render complex operands to the specified instruction.
virtual bool testImmPredicate_I64(unsigned, int64_t) const
Check the specified operand is an Imm.
Fail the current try-block, or completely fail to match if there is no current try-block.
Check the operand is a specific literal integer (i.e.
LLVM_NODISCARD bool empty() const
Check the size of the memory access for the given machine memory operand.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Check an immediate predicate on the specified instruction.
Check the operand is a specific predicate.
Begin a try-block to attempt a match and jump to OnFail if it is unsuccessful.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Add an register to the specified instruction.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Check the operand matches a complex predicate.
Check the address space of the memory access for the given machine memory operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Record the specified instruction.
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const
Get a register bank that covers RC.
Render a G_FCONSTANT operator as a sign-extended immediate.
virtual bool testImmPredicate_APInt(unsigned, const APInt &) const
Check the operand is a specific intrinsic ID.
virtual bool testImmPredicate_APFloat(unsigned, const APFloat &) const
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Register getReg() const
getReg - Returns the register number.
Add a temporary register to the specified instruction.
const ConstantInt * getCImm() const
Check an immediate predicate on the specified instruction via an APInt.
unsigned getPredicate() const
bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const
Return true if MI can obviously be folded into IntoMI.