51 #define DEBUG_TYPE "x86-codegen"
53 STATISTIC(NumFXCH,
"Number of fxch instructions inserted");
54 STATISTIC(NumFP ,
"Number of floating point instructions");
57 const unsigned ScratchFPReg = 7;
65 memset(Stack, 0,
sizeof(Stack));
66 memset(RegMap, 0,
sizeof(RegMap));
84 StringRef getPassName()
const override {
return "X86 FP Stackifier"; }
110 unsigned char FixStack[8];
112 LiveBundle() :
Mask(0), FixCount(0) {}
115 bool isFixed()
const {
return !
Mask || FixCount; }
131 static_assert(X86::FP6 - X86::FP0 == 6,
"sequential regnums");
132 if (Reg >= X86::FP0 && Reg <= X86::FP6) {
133 Mask |= 1 << (Reg - X86::FP0);
164 unsigned RegMap[NumFPRegs];
167 void setupBlockStack();
170 void finishBlockStack();
172 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
173 void dumpStack()
const {
174 dbgs() <<
"Stack contents:";
175 for (
unsigned i = 0; i != StackTop; ++i) {
177 assert(RegMap[Stack[i]] == i &&
"Stack[] doesn't match RegMap[]!");
184 unsigned getSlot(
unsigned RegNo)
const {
185 assert(RegNo < NumFPRegs &&
"Regno out of range!");
186 return RegMap[RegNo];
190 bool isLive(
unsigned RegNo)
const {
191 unsigned Slot = getSlot(RegNo);
192 return Slot < StackTop &&
Stack[Slot] == RegNo;
196 unsigned getStackEntry(
unsigned STi)
const {
199 return Stack[StackTop-1-STi];
204 unsigned getSTReg(
unsigned RegNo)
const {
205 return StackTop - 1 - getSlot(RegNo) + X86::ST0;
209 void pushReg(
unsigned Reg) {
210 assert(Reg < NumFPRegs &&
"Register number out of range!");
214 RegMap[
Reg] = StackTop++;
221 RegMap[
Stack[--StackTop]] = ~0;
224 bool isAtTop(
unsigned RegNo)
const {
return getSlot(RegNo) == StackTop-1; }
227 if (isAtTop(RegNo))
return;
229 unsigned STReg = getSTReg(RegNo);
230 unsigned RegOnTop = getStackEntry(0);
233 std::swap(RegMap[RegNo], RegMap[RegOnTop]);
236 if (RegMap[RegOnTop] >= StackTop)
238 std::swap(Stack[RegMap[RegOnTop]], Stack[StackTop-1]);
241 BuildMI(*MBB, I, dl,
TII->get(X86::XCH_F)).addReg(STReg);
245 void duplicateToTop(
unsigned RegNo,
unsigned AsReg,
248 unsigned STReg = getSTReg(RegNo);
251 BuildMI(*MBB, I, dl,
TII->get(X86::LD_Frr)).addReg(STReg);
275 void shuffleStackTop(
const unsigned char *FixStack,
unsigned FixCount,
295 return X86::RFP80RegClass.contains(DstReg) ||
296 X86::RFP80RegClass.contains(SrcReg);
310 unsigned Reg = MO.
getReg();
311 assert(Reg >= X86::FP0 && Reg <= X86::FP6 &&
"Expected FP register!");
312 return Reg - X86::FP0;
321 bool FPIsUsed =
false;
323 static_assert(X86::FP6 == X86::FP0+6,
"Register enums aren't sorted right!");
325 for (
unsigned i = 0; i <= 6; ++i)
332 if (!FPIsUsed)
return false;
334 Bundles = &getAnalysis<EdgeBundles>();
338 bundleCFGRecomputeKillFlags(MF);
348 LiveBundles[Bundles->getBundle(Entry->
getNumber(),
false)];
360 assert((Bundle.Mask & 0xFE) == 0 &&
361 "Only FP0 could be passed as an argument");
363 Bundle.FixStack[0] = 0;
366 bool Changed =
false;
368 Changed |= processBasicBlock(MF, *BB);
373 if (Processed.
insert(&BB).second)
374 Changed |= processBasicBlock(MF, BB);
387 assert(LiveBundles.empty() &&
"Stale data in LiveBundles");
388 LiveBundles.resize(Bundles->getNumBundles());
394 const unsigned Mask = calcLiveInMask(&MBB,
false);
398 LiveBundles[Bundles->getBundle(MBB.
getNumber(),
false)].Mask |= Mask;
406 bool Changed =
false;
419 if (MI.
isCopy() && isFPCopy(MI))
434 PrevMI = &*std::prev(I);
448 switch (FPInstClass) {
461 for (
unsigned i = 0, e = DeadRegs.
size(); i != e; ++i) {
462 unsigned Reg = DeadRegs[i];
465 static_assert(X86::FP7 - X86::FP0 == 7,
"sequential FP regnumbers");
466 if (Reg >= X86::FP0 && Reg <= X86::FP6 && isLive(Reg-X86::FP0)) {
467 DEBUG(
dbgs() <<
"Register FP#" << Reg-X86::FP0 <<
" is dead!\n");
468 freeStackSlotAfter(I, Reg-X86::FP0);
476 dbgs() <<
"Just deleted pseudo instruction\n";
480 while (Start != BB.
begin() && std::prev(Start) != PrevI)
482 dbgs() <<
"Inserted instructions:\n\t";
483 Start->print(
dbgs());
484 while (++Start != std::next(I)) {
501 void FPS::setupBlockStack() {
503 <<
" derived from " << MBB->
getName() <<
".\n");
506 const LiveBundle &Bundle =
507 LiveBundles[Bundles->getBundle(MBB->
getNumber(),
false)];
510 DEBUG(
dbgs() <<
"Block has no FP live-ins.\n");
515 assert(Bundle.isFixed() &&
"Reached block before any predecessors");
518 for (
unsigned i = Bundle.FixCount; i > 0; --i) {
519 DEBUG(
dbgs() <<
"Live-in st(" << (i-1) <<
"): %FP"
520 <<
unsigned(Bundle.FixStack[i-1]) <<
'\n');
521 pushReg(Bundle.FixStack[i-1]);
527 unsigned Mask = calcLiveInMask(MBB,
true);
528 adjustLiveRegs(Mask, MBB->
begin());
536 void FPS::finishBlockStack() {
542 <<
" derived from " << MBB->
getName() <<
".\n");
545 unsigned BundleIdx = Bundles->getBundle(MBB->
getNumber(),
true);
546 LiveBundle &Bundle = LiveBundles[BundleIdx];
551 adjustLiveRegs(Bundle.Mask, Term);
559 DEBUG(
dbgs() <<
"LB#" << BundleIdx <<
": ");
560 if (Bundle.isFixed()) {
561 DEBUG(
dbgs() <<
"Shuffling stack to match.\n");
562 shuffleStackTop(Bundle.FixStack, Bundle.FixCount, Term);
565 DEBUG(
dbgs() <<
"Fixing stack order now.\n");
566 Bundle.FixCount = StackTop;
567 for (
unsigned i = 0; i < StackTop; ++i)
568 Bundle.FixStack[i] = getStackEntry(i);
581 bool operator<(
const TableEntry &TE)
const {
return from < TE.from; }
582 friend bool operator<(
const TableEntry &TE,
unsigned V) {
586 const TableEntry &TE) {
593 const TableEntry *I = std::lower_bound(Table.
begin(), Table.
end(), Opcode);
594 if (I != Table.
end() && I->from == Opcode)
600 #define ASSERT_SORTED(TABLE)
602 #define ASSERT_SORTED(TABLE) \
603 { static bool TABLE##Checked = false; \
604 if (!TABLE##Checked) { \
605 assert(std::is_sorted(std::begin(TABLE), std::end(TABLE)) && \
606 "All lookup tables must be sorted for efficient access!"); \
607 TABLE##Checked = true; \
621 { X86::ABS_Fp32 , X86::ABS_F },
622 { X86::ABS_Fp64 , X86::ABS_F },
623 { X86::ABS_Fp80 , X86::ABS_F },
624 { X86::ADD_Fp32m , X86::ADD_F32m },
625 { X86::ADD_Fp64m , X86::ADD_F64m },
626 { X86::ADD_Fp64m32 , X86::ADD_F32m },
627 { X86::ADD_Fp80m32 , X86::ADD_F32m },
628 { X86::ADD_Fp80m64 , X86::ADD_F64m },
629 { X86::ADD_FpI16m32 , X86::ADD_FI16m },
630 { X86::ADD_FpI16m64 , X86::ADD_FI16m },
631 { X86::ADD_FpI16m80 , X86::ADD_FI16m },
632 { X86::ADD_FpI32m32 , X86::ADD_FI32m },
633 { X86::ADD_FpI32m64 , X86::ADD_FI32m },
634 { X86::ADD_FpI32m80 , X86::ADD_FI32m },
635 { X86::CHS_Fp32 , X86::CHS_F },
636 { X86::CHS_Fp64 , X86::CHS_F },
637 { X86::CHS_Fp80 , X86::CHS_F },
638 { X86::CMOVBE_Fp32 , X86::CMOVBE_F },
639 { X86::CMOVBE_Fp64 , X86::CMOVBE_F },
640 { X86::CMOVBE_Fp80 , X86::CMOVBE_F },
641 { X86::CMOVB_Fp32 , X86::CMOVB_F },
642 { X86::CMOVB_Fp64 , X86::CMOVB_F },
643 { X86::CMOVB_Fp80 , X86::CMOVB_F },
644 { X86::CMOVE_Fp32 , X86::CMOVE_F },
645 { X86::CMOVE_Fp64 , X86::CMOVE_F },
646 { X86::CMOVE_Fp80 , X86::CMOVE_F },
647 { X86::CMOVNBE_Fp32 , X86::CMOVNBE_F },
648 { X86::CMOVNBE_Fp64 , X86::CMOVNBE_F },
649 { X86::CMOVNBE_Fp80 , X86::CMOVNBE_F },
650 { X86::CMOVNB_Fp32 , X86::CMOVNB_F },
651 { X86::CMOVNB_Fp64 , X86::CMOVNB_F },
652 { X86::CMOVNB_Fp80 , X86::CMOVNB_F },
653 { X86::CMOVNE_Fp32 , X86::CMOVNE_F },
654 { X86::CMOVNE_Fp64 , X86::CMOVNE_F },
655 { X86::CMOVNE_Fp80 , X86::CMOVNE_F },
656 { X86::CMOVNP_Fp32 , X86::CMOVNP_F },
657 { X86::CMOVNP_Fp64 , X86::CMOVNP_F },
658 { X86::CMOVNP_Fp80 , X86::CMOVNP_F },
659 { X86::CMOVP_Fp32 , X86::CMOVP_F },
660 { X86::CMOVP_Fp64 , X86::CMOVP_F },
661 { X86::CMOVP_Fp80 , X86::CMOVP_F },
662 { X86::COS_Fp32 , X86::COS_F },
663 { X86::COS_Fp64 , X86::COS_F },
664 { X86::COS_Fp80 , X86::COS_F },
665 { X86::DIVR_Fp32m , X86::DIVR_F32m },
666 { X86::DIVR_Fp64m , X86::DIVR_F64m },
667 { X86::DIVR_Fp64m32 , X86::DIVR_F32m },
668 { X86::DIVR_Fp80m32 , X86::DIVR_F32m },
669 { X86::DIVR_Fp80m64 , X86::DIVR_F64m },
670 { X86::DIVR_FpI16m32, X86::DIVR_FI16m},
671 { X86::DIVR_FpI16m64, X86::DIVR_FI16m},
672 { X86::DIVR_FpI16m80, X86::DIVR_FI16m},
673 { X86::DIVR_FpI32m32, X86::DIVR_FI32m},
674 { X86::DIVR_FpI32m64, X86::DIVR_FI32m},
675 { X86::DIVR_FpI32m80, X86::DIVR_FI32m},
676 { X86::DIV_Fp32m , X86::DIV_F32m },
677 { X86::DIV_Fp64m , X86::DIV_F64m },
678 { X86::DIV_Fp64m32 , X86::DIV_F32m },
679 { X86::DIV_Fp80m32 , X86::DIV_F32m },
680 { X86::DIV_Fp80m64 , X86::DIV_F64m },
681 { X86::DIV_FpI16m32 , X86::DIV_FI16m },
682 { X86::DIV_FpI16m64 , X86::DIV_FI16m },
683 { X86::DIV_FpI16m80 , X86::DIV_FI16m },
684 { X86::DIV_FpI32m32 , X86::DIV_FI32m },
685 { X86::DIV_FpI32m64 , X86::DIV_FI32m },
686 { X86::DIV_FpI32m80 , X86::DIV_FI32m },
687 { X86::ILD_Fp16m32 , X86::ILD_F16m },
688 { X86::ILD_Fp16m64 , X86::ILD_F16m },
689 { X86::ILD_Fp16m80 , X86::ILD_F16m },
690 { X86::ILD_Fp32m32 , X86::ILD_F32m },
691 { X86::ILD_Fp32m64 , X86::ILD_F32m },
692 { X86::ILD_Fp32m80 , X86::ILD_F32m },
693 { X86::ILD_Fp64m32 , X86::ILD_F64m },
694 { X86::ILD_Fp64m64 , X86::ILD_F64m },
695 { X86::ILD_Fp64m80 , X86::ILD_F64m },
696 { X86::ISTT_Fp16m32 , X86::ISTT_FP16m},
697 { X86::ISTT_Fp16m64 , X86::ISTT_FP16m},
698 { X86::ISTT_Fp16m80 , X86::ISTT_FP16m},
699 { X86::ISTT_Fp32m32 , X86::ISTT_FP32m},
700 { X86::ISTT_Fp32m64 , X86::ISTT_FP32m},
701 { X86::ISTT_Fp32m80 , X86::ISTT_FP32m},
702 { X86::ISTT_Fp64m32 , X86::ISTT_FP64m},
703 { X86::ISTT_Fp64m64 , X86::ISTT_FP64m},
704 { X86::ISTT_Fp64m80 , X86::ISTT_FP64m},
705 { X86::IST_Fp16m32 , X86::IST_F16m },
706 { X86::IST_Fp16m64 , X86::IST_F16m },
707 { X86::IST_Fp16m80 , X86::IST_F16m },
708 { X86::IST_Fp32m32 , X86::IST_F32m },
709 { X86::IST_Fp32m64 , X86::IST_F32m },
710 { X86::IST_Fp32m80 , X86::IST_F32m },
711 { X86::IST_Fp64m32 , X86::IST_FP64m },
712 { X86::IST_Fp64m64 , X86::IST_FP64m },
713 { X86::IST_Fp64m80 , X86::IST_FP64m },
714 { X86::LD_Fp032 , X86::LD_F0 },
715 { X86::LD_Fp064 , X86::LD_F0 },
716 { X86::LD_Fp080 , X86::LD_F0 },
717 { X86::LD_Fp132 , X86::LD_F1 },
718 { X86::LD_Fp164 , X86::LD_F1 },
719 { X86::LD_Fp180 , X86::LD_F1 },
720 { X86::LD_Fp32m , X86::LD_F32m },
721 { X86::LD_Fp32m64 , X86::LD_F32m },
722 { X86::LD_Fp32m80 , X86::LD_F32m },
723 { X86::LD_Fp64m , X86::LD_F64m },
724 { X86::LD_Fp64m80 , X86::LD_F64m },
725 { X86::LD_Fp80m , X86::LD_F80m },
726 { X86::MUL_Fp32m , X86::MUL_F32m },
727 { X86::MUL_Fp64m , X86::MUL_F64m },
728 { X86::MUL_Fp64m32 , X86::MUL_F32m },
729 { X86::MUL_Fp80m32 , X86::MUL_F32m },
730 { X86::MUL_Fp80m64 , X86::MUL_F64m },
731 { X86::MUL_FpI16m32 , X86::MUL_FI16m },
732 { X86::MUL_FpI16m64 , X86::MUL_FI16m },
733 { X86::MUL_FpI16m80 , X86::MUL_FI16m },
734 { X86::MUL_FpI32m32 , X86::MUL_FI32m },
735 { X86::MUL_FpI32m64 , X86::MUL_FI32m },
736 { X86::MUL_FpI32m80 , X86::MUL_FI32m },
737 { X86::SIN_Fp32 , X86::SIN_F },
738 { X86::SIN_Fp64 , X86::SIN_F },
739 { X86::SIN_Fp80 , X86::SIN_F },
740 { X86::SQRT_Fp32 , X86::SQRT_F },
741 { X86::SQRT_Fp64 , X86::SQRT_F },
742 { X86::SQRT_Fp80 , X86::SQRT_F },
743 { X86::ST_Fp32m , X86::ST_F32m },
744 { X86::ST_Fp64m , X86::ST_F64m },
745 { X86::ST_Fp64m32 , X86::ST_F32m },
746 { X86::ST_Fp80m32 , X86::ST_F32m },
747 { X86::ST_Fp80m64 , X86::ST_F64m },
748 { X86::ST_FpP80m , X86::ST_FP80m },
749 { X86::SUBR_Fp32m , X86::SUBR_F32m },
750 { X86::SUBR_Fp64m , X86::SUBR_F64m },
751 { X86::SUBR_Fp64m32 , X86::SUBR_F32m },
752 { X86::SUBR_Fp80m32 , X86::SUBR_F32m },
753 { X86::SUBR_Fp80m64 , X86::SUBR_F64m },
754 { X86::SUBR_FpI16m32, X86::SUBR_FI16m},
755 { X86::SUBR_FpI16m64, X86::SUBR_FI16m},
756 { X86::SUBR_FpI16m80, X86::SUBR_FI16m},
757 { X86::SUBR_FpI32m32, X86::SUBR_FI32m},
758 { X86::SUBR_FpI32m64, X86::SUBR_FI32m},
759 { X86::SUBR_FpI32m80, X86::SUBR_FI32m},
760 { X86::SUB_Fp32m , X86::SUB_F32m },
761 { X86::SUB_Fp64m , X86::SUB_F64m },
762 { X86::SUB_Fp64m32 , X86::SUB_F32m },
763 { X86::SUB_Fp80m32 , X86::SUB_F32m },
764 { X86::SUB_Fp80m64 , X86::SUB_F64m },
765 { X86::SUB_FpI16m32 , X86::SUB_FI16m },
766 { X86::SUB_FpI16m64 , X86::SUB_FI16m },
767 { X86::SUB_FpI16m80 , X86::SUB_FI16m },
768 { X86::SUB_FpI32m32 , X86::SUB_FI32m },
769 { X86::SUB_FpI32m64 , X86::SUB_FI32m },
770 { X86::SUB_FpI32m80 , X86::SUB_FI32m },
771 { X86::TST_Fp32 , X86::TST_F },
772 { X86::TST_Fp64 , X86::TST_F },
773 { X86::TST_Fp80 , X86::TST_F },
774 { X86::UCOM_FpIr32 , X86::UCOM_FIr },
775 { X86::UCOM_FpIr64 , X86::UCOM_FIr },
776 { X86::UCOM_FpIr80 , X86::UCOM_FIr },
777 { X86::UCOM_Fpr32 , X86::UCOM_Fr },
778 { X86::UCOM_Fpr64 , X86::UCOM_Fr },
779 { X86::UCOM_Fpr80 , X86::UCOM_Fr },
785 assert(Opc != -1 &&
"FP Stack instruction not in OpcodeTable!");
797 { X86::ADD_FrST0 , X86::ADD_FPrST0 },
799 { X86::DIVR_FrST0, X86::DIVR_FPrST0 },
800 { X86::DIV_FrST0 , X86::DIV_FPrST0 },
802 { X86::IST_F16m , X86::IST_FP16m },
803 { X86::IST_F32m , X86::IST_FP32m },
805 { X86::MUL_FrST0 , X86::MUL_FPrST0 },
807 { X86::ST_F32m , X86::ST_FP32m },
808 { X86::ST_F64m , X86::ST_FP64m },
809 { X86::ST_Frr , X86::ST_FPrr },
811 { X86::SUBR_FrST0, X86::SUBR_FPrST0 },
812 { X86::SUB_FrST0 , X86::SUB_FPrST0 },
814 { X86::UCOM_FIr , X86::UCOM_FIPr },
816 { X86::UCOM_FPr , X86::UCOM_FPPr },
817 { X86::UCOM_Fr , X86::UCOM_FPr },
836 I->setDesc(TII->get(Opcode));
837 if (Opcode == X86::UCOM_FPPr)
840 I =
BuildMI(*MBB, ++I, dl, TII->
get(X86::ST_FPrr)).addReg(X86::ST0);
849 if (getStackEntry(0) == FPRegNo) {
857 I = freeStackSlotBefore(++I, FPRegNo);
864 unsigned STReg = getSTReg(FPRegNo);
865 unsigned OldSlot = getSlot(FPRegNo);
866 unsigned TopReg =
Stack[StackTop-1];
867 Stack[OldSlot] = TopReg;
868 RegMap[TopReg] = OldSlot;
869 RegMap[FPRegNo] = ~0;
870 Stack[--StackTop] = ~0;
879 unsigned Defs =
Mask;
881 for (
unsigned i = 0; i < StackTop; ++i) {
882 unsigned RegNo =
Stack[i];
883 if (!(Defs & (1 << RegNo)))
885 Kills |= (1 << RegNo);
888 Defs &= ~(1 << RegNo);
890 assert((Kills & Defs) == 0 &&
"Register needs killing and def'ing?");
893 while (Kills && Defs) {
896 DEBUG(
dbgs() <<
"Renaming %FP" << KReg <<
" as imp %FP" << DReg <<
"\n");
897 std::swap(Stack[getSlot(KReg)], Stack[getSlot(DReg)]);
899 Kills &= ~(1 << KReg);
900 Defs &= ~(1 << DReg);
904 if (Kills && I != MBB->
begin()) {
907 unsigned KReg = getStackEntry(0);
908 if (!(Kills & (1 << KReg)))
910 DEBUG(
dbgs() <<
"Popping %FP" << KReg <<
"\n");
912 Kills &= ~(1 << KReg);
919 DEBUG(
dbgs() <<
"Killing %FP" << KReg <<
"\n");
920 freeStackSlotBefore(I, KReg);
921 Kills &= ~(1 << KReg);
927 DEBUG(
dbgs() <<
"Defining %FP" << DReg <<
" as 0\n");
930 Defs &= ~(1 << DReg);
941 void FPS::shuffleStackTop(
const unsigned char *FixStack,
947 unsigned OldReg = getStackEntry(FixCount);
949 unsigned Reg = FixStack[FixCount];
955 moveToTop(OldReg, I);
966 unsigned STReturns = 0;
969 for (
const auto &MO : I->operands()) {
973 unsigned R = MO.
getReg() - X86::FP0;
996 for (
unsigned I = 0; I <
N; ++
I)
1006 unsigned FirstFPRegOp = ~0U, SecondFPRegOp = ~0U;
1007 unsigned LiveMask = 0;
1019 "Ret only defs operands, and values aren't live beyond it");
1021 if (FirstFPRegOp == ~0U)
1024 assert(SecondFPRegOp == ~0U &&
"More than two fp operands!");
1037 adjustLiveRegs(LiveMask, MI);
1038 if (!LiveMask)
return;
1044 if (SecondFPRegOp == ~0U) {
1046 assert(StackTop == 1 && FirstFPRegOp == getStackEntry(0) &&
1047 "Top of stack not the right register for RET!");
1059 if (StackTop == 1) {
1060 assert(FirstFPRegOp == SecondFPRegOp && FirstFPRegOp == getStackEntry(0)&&
1061 "Stack misconfiguration for RET!");
1065 unsigned NewReg = ScratchFPReg;
1066 duplicateToTop(FirstFPRegOp, NewReg, MI);
1067 FirstFPRegOp = NewReg;
1071 assert(StackTop == 2 &&
"Must have two values live!");
1075 if (getStackEntry(0) == SecondFPRegOp) {
1076 assert(getStackEntry(1) == FirstFPRegOp &&
"Unknown regs live");
1077 moveToTop(FirstFPRegOp, MI);
1082 assert(getStackEntry(0) == FirstFPRegOp &&
"Unknown regs live");
1083 assert(getStackEntry(1) == SecondFPRegOp &&
"Unknown regs live");
1107 "Can only handle fst* & ftst instructions!");
1119 if (!KillsSrc && (MI.
getOpcode() == X86::IST_Fp64m32 ||
1132 duplicateToTop(Reg, ScratchFPReg, I);
1147 }
else if (KillsSrc) {
1165 assert(NumOps >= 2 &&
"FPRW instructions must have 2 ops!!");
1199 { X86::ADD_Fp32 , X86::ADD_FST0r },
1200 { X86::ADD_Fp64 , X86::ADD_FST0r },
1201 { X86::ADD_Fp80 , X86::ADD_FST0r },
1202 { X86::DIV_Fp32 , X86::DIV_FST0r },
1203 { X86::DIV_Fp64 , X86::DIV_FST0r },
1204 { X86::DIV_Fp80 , X86::DIV_FST0r },
1205 { X86::MUL_Fp32 , X86::MUL_FST0r },
1206 { X86::MUL_Fp64 , X86::MUL_FST0r },
1207 { X86::MUL_Fp80 , X86::MUL_FST0r },
1208 { X86::SUB_Fp32 , X86::SUB_FST0r },
1209 { X86::SUB_Fp64 , X86::SUB_FST0r },
1210 { X86::SUB_Fp80 , X86::SUB_FST0r },
1215 { X86::ADD_Fp32 , X86::ADD_FST0r },
1216 { X86::ADD_Fp64 , X86::ADD_FST0r },
1217 { X86::ADD_Fp80 , X86::ADD_FST0r },
1218 { X86::DIV_Fp32 , X86::DIVR_FST0r },
1219 { X86::DIV_Fp64 , X86::DIVR_FST0r },
1220 { X86::DIV_Fp80 , X86::DIVR_FST0r },
1221 { X86::MUL_Fp32 , X86::MUL_FST0r },
1222 { X86::MUL_Fp64 , X86::MUL_FST0r },
1223 { X86::MUL_Fp80 , X86::MUL_FST0r },
1224 { X86::SUB_Fp32 , X86::SUBR_FST0r },
1225 { X86::SUB_Fp64 , X86::SUBR_FST0r },
1226 { X86::SUB_Fp80 , X86::SUBR_FST0r },
1231 { X86::ADD_Fp32 , X86::ADD_FrST0 },
1232 { X86::ADD_Fp64 , X86::ADD_FrST0 },
1233 { X86::ADD_Fp80 , X86::ADD_FrST0 },
1234 { X86::DIV_Fp32 , X86::DIVR_FrST0 },
1235 { X86::DIV_Fp64 , X86::DIVR_FrST0 },
1236 { X86::DIV_Fp80 , X86::DIVR_FrST0 },
1237 { X86::MUL_Fp32 , X86::MUL_FrST0 },
1238 { X86::MUL_Fp64 , X86::MUL_FrST0 },
1239 { X86::MUL_Fp80 , X86::MUL_FrST0 },
1240 { X86::SUB_Fp32 , X86::SUBR_FrST0 },
1241 { X86::SUB_Fp64 , X86::SUBR_FrST0 },
1242 { X86::SUB_Fp80 , X86::SUBR_FrST0 },
1247 { X86::ADD_Fp32 , X86::ADD_FrST0 },
1248 { X86::ADD_Fp64 , X86::ADD_FrST0 },
1249 { X86::ADD_Fp80 , X86::ADD_FrST0 },
1250 { X86::DIV_Fp32 , X86::DIV_FrST0 },
1251 { X86::DIV_Fp64 , X86::DIV_FrST0 },
1252 { X86::DIV_Fp80 , X86::DIV_FrST0 },
1253 { X86::MUL_Fp32 , X86::MUL_FrST0 },
1254 { X86::MUL_Fp64 , X86::MUL_FrST0 },
1255 { X86::MUL_Fp80 , X86::MUL_FrST0 },
1256 { X86::SUB_Fp32 , X86::SUB_FrST0 },
1257 { X86::SUB_Fp64 , X86::SUB_FrST0 },
1258 { X86::SUB_Fp80 , X86::SUB_FrST0 },
1276 assert(NumOperands == 3 &&
"Illegal TwoArgFP instruction!");
1284 unsigned TOS = getStackEntry(0);
1288 if (Op0 != TOS && Op1 != TOS) {
1295 }
else if (KillsOp1) {
1304 duplicateToTop(Op0, Dest, I);
1308 }
else if (!KillsOp0 && !KillsOp1) {
1312 duplicateToTop(Op0, Dest, I);
1319 assert((TOS == Op0 || TOS == Op1) && (KillsOp0 || KillsOp1) &&
1320 "Stack conditions not set up right!");
1325 bool isForward = TOS == Op0;
1326 bool updateST0 = (TOS == Op0 && !KillsOp1) || (TOS == Op1 && !KillsOp0);
1340 assert(Opcode != -1 &&
"Unknown TwoArgFP pseudo instruction!");
1343 unsigned NotTOS = (TOS == Op0) ? Op1 : Op0;
1347 I =
BuildMI(*MBB, I, dl, TII->
get(Opcode)).addReg(getSTReg(NotTOS));
1351 if (KillsOp0 && KillsOp1 && Op0 != Op1) {
1352 assert(!updateST0 &&
"Should have updated other operand!");
1358 unsigned UpdatedSlot = getSlot(updateST0 ? TOS : NotTOS);
1359 assert(UpdatedSlot < StackTop && Dest < 7);
1360 Stack[UpdatedSlot] = Dest;
1361 RegMap[Dest] = UpdatedSlot;
1374 assert(NumOperands == 2 &&
"Illegal FUCOM* instruction!");
1390 if (KillsOp0) freeStackSlotAfter(I, Op0);
1391 if (KillsOp1 && Op0 != Op1) freeStackSlotAfter(I, Op1);
1416 if (Op0 != Op1 && KillsOp1) {
1418 freeStackSlotAfter(I, Op1);
1442 case TargetOpcode::COPY: {
1451 assert(isLive(SrcFP) &&
"Cannot copy dead register");
1455 unsigned Slot = getSlot(SrcFP);
1456 Stack[Slot] = DstFP;
1457 RegMap[DstFP] = Slot;
1461 duplicateToTop(SrcFP, DstFP, Inst);
1466 case TargetOpcode::IMPLICIT_DEF: {
1469 DEBUG(
dbgs() <<
"Emitting LD_F0 for implicit FP" << Reg <<
'\n');
1509 unsigned STUses = 0, STDefs = 0, STClobbers = 0, STDeadDefs = 0;
1510 unsigned NumOps = 0;
1524 unsigned STReg = MO.
getReg() - X86::FP0;
1537 STUses |= (1u << STReg);
1541 STDefs |= (1u << STReg);
1543 STDeadDefs |= (1u << STReg);
1546 STClobbers |= (1u << STReg);
1554 MI.
emitError(
"fixed input regs must be last on the x87 stack");
1559 MI.
emitError(
"output regs must be last on the x87 stack");
1565 if (STClobbers && !
isMask_32(STDefs | STClobbers))
1566 MI.
emitError(
"clobbers must be last on the x87 stack");
1569 unsigned STPopped = STUses & (STDefs | STClobbers);
1571 MI.
emitError(
"implicitly popped regs must be last on the x87 stack");
1574 DEBUG(
dbgs() <<
"Asm uses " << NumSTUses <<
" fixed regs, pops "
1575 << NumSTPopped <<
", and defines " << NumSTDefs <<
" regs.\n");
1581 if (FRegIdx.
count(I)) {
1583 "Operands with constraint \"f\" cannot overlap with defs");
1589 unsigned FPKills = ((1u << NumFPRegs) - 1) & ~0xff;
1600 FPKills |= 1U << FPReg;
1604 FPKills &= ~(STDefs | STClobbers);
1607 unsigned char STUsesArray[8];
1609 for (
unsigned I = 0; I < NumSTUses; ++
I)
1612 shuffleStackTop(STUsesArray, NumSTUses, Inst);
1613 DEBUG({
dbgs() <<
"Before asm: "; dumpStack();});
1623 if (FRegIdx.
count(i))
1625 Op.
setReg(getSTReg(FPReg));
1628 Op.
setReg(X86::ST0 + FPReg);
1632 StackTop -= NumSTPopped;
1634 for (
unsigned i = 0; i < NumSTDefs; ++i)
1635 pushReg(NumSTDefs - i - 1);
1647 freeStackSlotAfter(Inst, FPReg);
1648 FPKills &= ~(1U << FPReg);
1656 Inst = MBB->
erase(Inst);
1660 if (Inst == MBB->
begin()) {
1661 DEBUG(
dbgs() <<
"Inserting dummy KILL\n");
1672 LPR.addLiveOuts(MBB);
1676 if (I->isDebugValue())
1679 std::bitset<8> Defs;
1683 for (
auto &MO : I->operands()) {
1687 unsigned Reg = MO.
getReg() - X86::FP0;
1694 if (!LPR.contains(MO.
getReg()))
1700 for (
auto *MO : Uses)
1704 LPR.stepBackward(MI);
static const TableEntry OpcodeTable[]
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static unsigned getConcreteOpcode(unsigned Opcode)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
void setIsDead(bool Val=true)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
static const TableEntry ReverseSTiTable[]
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
AnalysisUsage & addRequired()
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
static const TableEntry ForwardST0Table[]
LiveInVector::const_iterator livein_iterator
INLINEASM - Represents an inline asm block.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
const MachineBasicBlock & front() const
static unsigned getFPReg(const MachineOperand &MO)
getFPReg - Return the X86::FPx register number for the specified operand.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AnalysisUsage & addPreservedID(const void *ID)
reverse_iterator rbegin()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static const TableEntry PopTable[]
TargetInstrInfo - Interface to description of machine instruction set.
bool isImplicitDef() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isReturn(QueryType Type=AnyInBundle) const
livein_iterator livein_begin() const
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
static const TableEntry ForwardSTiTable[]
livein_iterator livein_end() const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
Represent the analysis usage information of a pass.
#define LLVM_ATTRIBUTE_UNUSED
AddrNumOperands - Total number of operands in a memory reference.
static unsigned getKind(unsigned Flags)
FunctionPass class - This class is used to implement most global optimizations.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
void emitError(StringRef Msg) const
Emit an error referring to the source location of this instruction.
void setIsKill(bool Val=true)
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
unsigned countPopulation(T Value)
Count the number of set bits in a value.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
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...
std::pair< iterator, bool > insert(NodeRef N)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
FunctionPass * createX86FloatingPointStackifierPass()
This function returns a pass which converts floating-point register references and pseudo instruction...
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
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 bool hasRegClassConstraint(unsigned Flag, unsigned &RC)
hasRegClassConstraint - Returns true if the flag contains a register class constraint.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static std::vector< std::string > Flags
Representation of each machine instruction.
static const TableEntry ReverseST0Table[]
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr kills the specified register.
bool operator<(int64_t V1, const APSInt &V2)
virtual const TargetInstrInfo * getInstrInfo() const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
#define ASSERT_SORTED(TABLE)
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void initializeEdgeBundlesPass(PassRegistry &)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
Register calling convention used for parameters transfer optimization.
bool reg_nodbg_empty(unsigned RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions...
Properties which a MachineFunction may have at a given point in time.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly. ...