41 #include "llvm/Config/llvm-config.h" 52 #define DEBUG_TYPE "x86-codegen" 54 STATISTIC(NumFXCH,
"Number of fxch instructions inserted");
55 STATISTIC(NumFP ,
"Number of floating point instructions");
58 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);
154 unsigned StackTop = 0;
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) {
176 dbgs() <<
" FP" << Stack[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!");
213 Stack[StackTop] =
Reg;
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);
318 assert(Reg >= X86::FP0 && Reg <= X86::FP6 &&
"Expected FP register!");
319 return Reg - X86::FP0;
328 bool FPIsUsed =
false;
330 static_assert(X86::FP6 == X86::FP0+6,
"Register enums aren't sorted right!");
332 for (
unsigned i = 0; i <= 6; ++i)
339 if (!FPIsUsed)
return false;
341 Bundles = &getAnalysis<EdgeBundles>();
345 bundleCFGRecomputeKillFlags(MF);
367 assert((Bundle.Mask & 0xFE) == 0 &&
368 "Only FP0 could be passed as an argument");
370 Bundle.FixStack[0] = 0;
373 bool Changed =
false;
375 Changed |= processBasicBlock(MF, *BB);
380 if (Processed.
insert(&BB).second)
381 Changed |= processBasicBlock(MF, BB);
394 assert(LiveBundles.
empty() &&
"Stale data in LiveBundles");
401 const unsigned Mask = calcLiveInMask(&MBB,
false);
413 bool Changed =
false;
426 if (MI.
isCopy() && isFPCopy(MI))
441 PrevMI = &*std::prev(I);
455 switch (FPInstClass) {
468 for (
unsigned i = 0,
e = DeadRegs.
size(); i !=
e; ++i) {
469 unsigned Reg = DeadRegs[i];
472 static_assert(X86::FP7 - X86::FP0 == 7,
"sequential FP regnumbers");
473 if (Reg >= X86::FP0 && Reg <= X86::FP6 && isLive(Reg-X86::FP0)) {
474 LLVM_DEBUG(
dbgs() <<
"Register FP#" << Reg - X86::FP0 <<
" is dead!\n");
475 freeStackSlotAfter(I, Reg-X86::FP0);
483 dbgs() <<
"Just deleted pseudo instruction\n";
487 while (Start != BB.
begin() && std::prev(Start) != PrevI)
489 dbgs() <<
"Inserted instructions:\n\t";
490 Start->print(
dbgs());
491 while (++Start != std::next(I)) {
508 void FPS::setupBlockStack() {
510 <<
" derived from " << MBB->
getName() <<
".\n");
513 const LiveBundle &Bundle =
522 assert(Bundle.isFixed() &&
"Reached block before any predecessors");
525 for (
unsigned i = Bundle.FixCount; i > 0; --i) {
527 <<
unsigned(Bundle.FixStack[i - 1]) <<
'\n');
528 pushReg(Bundle.FixStack[i-1]);
534 unsigned Mask = calcLiveInMask(MBB,
true);
535 adjustLiveRegs(Mask, MBB->
begin());
543 void FPS::finishBlockStack() {
549 <<
" derived from " << MBB->
getName() <<
".\n");
553 LiveBundle &Bundle = LiveBundles[BundleIdx];
558 adjustLiveRegs(Bundle.Mask, Term);
567 if (Bundle.isFixed()) {
569 shuffleStackTop(Bundle.FixStack, Bundle.FixCount, Term);
573 Bundle.FixCount = StackTop;
574 for (
unsigned i = 0; i < StackTop; ++i)
575 Bundle.FixStack[i] = getStackEntry(i);
588 bool operator<(
const TableEntry &
TE)
const {
return from < TE.from; }
589 friend bool operator<(
const TableEntry &TE,
unsigned V) {
593 const TableEntry &TE) {
601 if (I != Table.
end() && I->from == Opcode)
607 #define ASSERT_SORTED(TABLE) 609 #define ASSERT_SORTED(TABLE) \ 611 static std::atomic<bool> TABLE##Checked(false); \ 612 if (!TABLE##Checked.load(std::memory_order_relaxed)) { \ 613 assert(std::is_sorted(std::begin(TABLE), std::end(TABLE)) && \ 614 "All lookup tables must be sorted for efficient access!"); \ 615 TABLE##Checked.store(true, std::memory_order_relaxed); \ 629 { X86::ABS_Fp32 , X86::ABS_F },
630 { X86::ABS_Fp64 , X86::ABS_F },
631 { X86::ABS_Fp80 , X86::ABS_F },
632 { X86::ADD_Fp32m , X86::ADD_F32m },
633 { X86::ADD_Fp64m , X86::ADD_F64m },
634 { X86::ADD_Fp64m32 , X86::ADD_F32m },
635 { X86::ADD_Fp80m32 , X86::ADD_F32m },
636 { X86::ADD_Fp80m64 , X86::ADD_F64m },
637 { X86::ADD_FpI16m32 , X86::ADD_FI16m },
638 { X86::ADD_FpI16m64 , X86::ADD_FI16m },
639 { X86::ADD_FpI16m80 , X86::ADD_FI16m },
640 { X86::ADD_FpI32m32 , X86::ADD_FI32m },
641 { X86::ADD_FpI32m64 , X86::ADD_FI32m },
642 { X86::ADD_FpI32m80 , X86::ADD_FI32m },
643 { X86::CHS_Fp32 , X86::CHS_F },
644 { X86::CHS_Fp64 , X86::CHS_F },
645 { X86::CHS_Fp80 , X86::CHS_F },
646 { X86::CMOVBE_Fp32 , X86::CMOVBE_F },
647 { X86::CMOVBE_Fp64 , X86::CMOVBE_F },
648 { X86::CMOVBE_Fp80 , X86::CMOVBE_F },
649 { X86::CMOVB_Fp32 , X86::CMOVB_F },
650 { X86::CMOVB_Fp64 , X86::CMOVB_F },
651 { X86::CMOVB_Fp80 , X86::CMOVB_F },
652 { X86::CMOVE_Fp32 , X86::CMOVE_F },
653 { X86::CMOVE_Fp64 , X86::CMOVE_F },
654 { X86::CMOVE_Fp80 , X86::CMOVE_F },
655 { X86::CMOVNBE_Fp32 , X86::CMOVNBE_F },
656 { X86::CMOVNBE_Fp64 , X86::CMOVNBE_F },
657 { X86::CMOVNBE_Fp80 , X86::CMOVNBE_F },
658 { X86::CMOVNB_Fp32 , X86::CMOVNB_F },
659 { X86::CMOVNB_Fp64 , X86::CMOVNB_F },
660 { X86::CMOVNB_Fp80 , X86::CMOVNB_F },
661 { X86::CMOVNE_Fp32 , X86::CMOVNE_F },
662 { X86::CMOVNE_Fp64 , X86::CMOVNE_F },
663 { X86::CMOVNE_Fp80 , X86::CMOVNE_F },
664 { X86::CMOVNP_Fp32 , X86::CMOVNP_F },
665 { X86::CMOVNP_Fp64 , X86::CMOVNP_F },
666 { X86::CMOVNP_Fp80 , X86::CMOVNP_F },
667 { X86::CMOVP_Fp32 , X86::CMOVP_F },
668 { X86::CMOVP_Fp64 , X86::CMOVP_F },
669 { X86::CMOVP_Fp80 , X86::CMOVP_F },
670 { X86::COM_FpIr32 , X86::COM_FIr },
671 { X86::COM_FpIr64 , X86::COM_FIr },
672 { X86::COM_FpIr80 , X86::COM_FIr },
673 { X86::COM_Fpr32 , X86::COM_FST0r },
674 { X86::COM_Fpr64 , X86::COM_FST0r },
675 { X86::COM_Fpr80 , X86::COM_FST0r },
676 { X86::DIVR_Fp32m , X86::DIVR_F32m },
677 { X86::DIVR_Fp64m , X86::DIVR_F64m },
678 { X86::DIVR_Fp64m32 , X86::DIVR_F32m },
679 { X86::DIVR_Fp80m32 , X86::DIVR_F32m },
680 { X86::DIVR_Fp80m64 , X86::DIVR_F64m },
681 { X86::DIVR_FpI16m32, X86::DIVR_FI16m},
682 { X86::DIVR_FpI16m64, X86::DIVR_FI16m},
683 { X86::DIVR_FpI16m80, X86::DIVR_FI16m},
684 { X86::DIVR_FpI32m32, X86::DIVR_FI32m},
685 { X86::DIVR_FpI32m64, X86::DIVR_FI32m},
686 { X86::DIVR_FpI32m80, X86::DIVR_FI32m},
687 { X86::DIV_Fp32m , X86::DIV_F32m },
688 { X86::DIV_Fp64m , X86::DIV_F64m },
689 { X86::DIV_Fp64m32 , X86::DIV_F32m },
690 { X86::DIV_Fp80m32 , X86::DIV_F32m },
691 { X86::DIV_Fp80m64 , X86::DIV_F64m },
692 { X86::DIV_FpI16m32 , X86::DIV_FI16m },
693 { X86::DIV_FpI16m64 , X86::DIV_FI16m },
694 { X86::DIV_FpI16m80 , X86::DIV_FI16m },
695 { X86::DIV_FpI32m32 , X86::DIV_FI32m },
696 { X86::DIV_FpI32m64 , X86::DIV_FI32m },
697 { X86::DIV_FpI32m80 , X86::DIV_FI32m },
698 { X86::ILD_Fp16m32 , X86::ILD_F16m },
699 { X86::ILD_Fp16m64 , X86::ILD_F16m },
700 { X86::ILD_Fp16m80 , X86::ILD_F16m },
701 { X86::ILD_Fp32m32 , X86::ILD_F32m },
702 { X86::ILD_Fp32m64 , X86::ILD_F32m },
703 { X86::ILD_Fp32m80 , X86::ILD_F32m },
704 { X86::ILD_Fp64m32 , X86::ILD_F64m },
705 { X86::ILD_Fp64m64 , X86::ILD_F64m },
706 { X86::ILD_Fp64m80 , X86::ILD_F64m },
707 { X86::ISTT_Fp16m32 , X86::ISTT_FP16m},
708 { X86::ISTT_Fp16m64 , X86::ISTT_FP16m},
709 { X86::ISTT_Fp16m80 , X86::ISTT_FP16m},
710 { X86::ISTT_Fp32m32 , X86::ISTT_FP32m},
711 { X86::ISTT_Fp32m64 , X86::ISTT_FP32m},
712 { X86::ISTT_Fp32m80 , X86::ISTT_FP32m},
713 { X86::ISTT_Fp64m32 , X86::ISTT_FP64m},
714 { X86::ISTT_Fp64m64 , X86::ISTT_FP64m},
715 { X86::ISTT_Fp64m80 , X86::ISTT_FP64m},
716 { X86::IST_Fp16m32 , X86::IST_F16m },
717 { X86::IST_Fp16m64 , X86::IST_F16m },
718 { X86::IST_Fp16m80 , X86::IST_F16m },
719 { X86::IST_Fp32m32 , X86::IST_F32m },
720 { X86::IST_Fp32m64 , X86::IST_F32m },
721 { X86::IST_Fp32m80 , X86::IST_F32m },
722 { X86::IST_Fp64m32 , X86::IST_FP64m },
723 { X86::IST_Fp64m64 , X86::IST_FP64m },
724 { X86::IST_Fp64m80 , X86::IST_FP64m },
725 { X86::LD_Fp032 , X86::LD_F0 },
726 { X86::LD_Fp064 , X86::LD_F0 },
727 { X86::LD_Fp080 , X86::LD_F0 },
728 { X86::LD_Fp132 , X86::LD_F1 },
729 { X86::LD_Fp164 , X86::LD_F1 },
730 { X86::LD_Fp180 , X86::LD_F1 },
731 { X86::LD_Fp32m , X86::LD_F32m },
732 { X86::LD_Fp32m64 , X86::LD_F32m },
733 { X86::LD_Fp32m80 , X86::LD_F32m },
734 { X86::LD_Fp64m , X86::LD_F64m },
735 { X86::LD_Fp64m80 , X86::LD_F64m },
736 { X86::LD_Fp80m , X86::LD_F80m },
737 { X86::MUL_Fp32m , X86::MUL_F32m },
738 { X86::MUL_Fp64m , X86::MUL_F64m },
739 { X86::MUL_Fp64m32 , X86::MUL_F32m },
740 { X86::MUL_Fp80m32 , X86::MUL_F32m },
741 { X86::MUL_Fp80m64 , X86::MUL_F64m },
742 { X86::MUL_FpI16m32 , X86::MUL_FI16m },
743 { X86::MUL_FpI16m64 , X86::MUL_FI16m },
744 { X86::MUL_FpI16m80 , X86::MUL_FI16m },
745 { X86::MUL_FpI32m32 , X86::MUL_FI32m },
746 { X86::MUL_FpI32m64 , X86::MUL_FI32m },
747 { X86::MUL_FpI32m80 , X86::MUL_FI32m },
748 { X86::SQRT_Fp32 , X86::SQRT_F },
749 { X86::SQRT_Fp64 , X86::SQRT_F },
750 { X86::SQRT_Fp80 , X86::SQRT_F },
751 { X86::ST_Fp32m , X86::ST_F32m },
752 { X86::ST_Fp64m , X86::ST_F64m },
753 { X86::ST_Fp64m32 , X86::ST_F32m },
754 { X86::ST_Fp80m32 , X86::ST_F32m },
755 { X86::ST_Fp80m64 , X86::ST_F64m },
756 { X86::ST_FpP80m , X86::ST_FP80m },
757 { X86::SUBR_Fp32m , X86::SUBR_F32m },
758 { X86::SUBR_Fp64m , X86::SUBR_F64m },
759 { X86::SUBR_Fp64m32 , X86::SUBR_F32m },
760 { X86::SUBR_Fp80m32 , X86::SUBR_F32m },
761 { X86::SUBR_Fp80m64 , X86::SUBR_F64m },
762 { X86::SUBR_FpI16m32, X86::SUBR_FI16m},
763 { X86::SUBR_FpI16m64, X86::SUBR_FI16m},
764 { X86::SUBR_FpI16m80, X86::SUBR_FI16m},
765 { X86::SUBR_FpI32m32, X86::SUBR_FI32m},
766 { X86::SUBR_FpI32m64, X86::SUBR_FI32m},
767 { X86::SUBR_FpI32m80, X86::SUBR_FI32m},
768 { X86::SUB_Fp32m , X86::SUB_F32m },
769 { X86::SUB_Fp64m , X86::SUB_F64m },
770 { X86::SUB_Fp64m32 , X86::SUB_F32m },
771 { X86::SUB_Fp80m32 , X86::SUB_F32m },
772 { X86::SUB_Fp80m64 , X86::SUB_F64m },
773 { X86::SUB_FpI16m32 , X86::SUB_FI16m },
774 { X86::SUB_FpI16m64 , X86::SUB_FI16m },
775 { X86::SUB_FpI16m80 , X86::SUB_FI16m },
776 { X86::SUB_FpI32m32 , X86::SUB_FI32m },
777 { X86::SUB_FpI32m64 , X86::SUB_FI32m },
778 { X86::SUB_FpI32m80 , X86::SUB_FI32m },
779 { X86::TST_Fp32 , X86::TST_F },
780 { X86::TST_Fp64 , X86::TST_F },
781 { X86::TST_Fp80 , X86::TST_F },
782 { X86::UCOM_FpIr32 , X86::UCOM_FIr },
783 { X86::UCOM_FpIr64 , X86::UCOM_FIr },
784 { X86::UCOM_FpIr80 , X86::UCOM_FIr },
785 { X86::UCOM_Fpr32 , X86::UCOM_Fr },
786 { X86::UCOM_Fpr64 , X86::UCOM_Fr },
787 { X86::UCOM_Fpr80 , X86::UCOM_Fr },
792 int Opc =
Lookup(OpcodeTable, Opcode);
793 assert(Opc != -1 &&
"FP Stack instruction not in OpcodeTable!");
805 { X86::ADD_FrST0 , X86::ADD_FPrST0 },
807 { X86::COMP_FST0r, X86::FCOMPP },
808 { X86::COM_FIr , X86::COM_FIPr },
809 { X86::COM_FST0r , X86::COMP_FST0r },
811 { X86::DIVR_FrST0, X86::DIVR_FPrST0 },
812 { X86::DIV_FrST0 , X86::DIV_FPrST0 },
814 { X86::IST_F16m , X86::IST_FP16m },
815 { X86::IST_F32m , X86::IST_FP32m },
817 { X86::MUL_FrST0 , X86::MUL_FPrST0 },
819 { X86::ST_F32m , X86::ST_FP32m },
820 { X86::ST_F64m , X86::ST_FP64m },
821 { X86::ST_Frr , X86::ST_FPrr },
823 { X86::SUBR_FrST0, X86::SUBR_FPrST0 },
824 { X86::SUB_FrST0 , X86::SUB_FPrST0 },
826 { X86::UCOM_FIr , X86::UCOM_FIPr },
828 { X86::UCOM_FPr , X86::UCOM_FPPr },
829 { X86::UCOM_Fr , X86::UCOM_FPr },
846 int Opcode =
Lookup(PopTable, I->getOpcode());
848 I->setDesc(TII->
get(Opcode));
849 if (Opcode == X86::FCOMPP || Opcode == X86::UCOM_FPPr)
852 I =
BuildMI(*MBB, ++I, dl, TII->
get(X86::ST_FPrr)).addReg(X86::ST0);
861 if (getStackEntry(0) == FPRegNo) {
869 I = freeStackSlotBefore(++I, FPRegNo);
876 unsigned STReg = getSTReg(FPRegNo);
877 unsigned OldSlot = getSlot(FPRegNo);
878 unsigned TopReg = Stack[StackTop-1];
879 Stack[OldSlot] = TopReg;
880 RegMap[TopReg] = OldSlot;
881 RegMap[FPRegNo] = ~0;
882 Stack[--StackTop] = ~0;
891 unsigned Defs =
Mask;
893 for (
unsigned i = 0; i < StackTop; ++i) {
894 unsigned RegNo = Stack[i];
895 if (!(Defs & (1 << RegNo)))
897 Kills |= (1 << RegNo);
900 Defs &= ~(1 << RegNo);
902 assert((Kills & Defs) == 0 &&
"Register needs killing and def'ing?");
905 while (Kills && Defs) {
908 LLVM_DEBUG(
dbgs() <<
"Renaming %fp" << KReg <<
" as imp %fp" << DReg
910 std::swap(Stack[getSlot(KReg)], Stack[getSlot(DReg)]);
912 Kills &= ~(1 << KReg);
913 Defs &= ~(1 << DReg);
917 if (Kills && I != MBB->
begin()) {
920 unsigned KReg = getStackEntry(0);
921 if (!(Kills & (1 << KReg)))
925 Kills &= ~(1 << KReg);
933 freeStackSlotBefore(I, KReg);
934 Kills &= ~(1 << KReg);
943 Defs &= ~(1 << DReg);
954 void FPS::shuffleStackTop(
const unsigned char *FixStack,
960 unsigned OldReg = getStackEntry(FixCount);
962 unsigned Reg = FixStack[FixCount];
968 moveToTop(OldReg, I);
980 unsigned STReturns = 0;
1007 while (StackTop > 0)
1010 for (
unsigned I = 0; I <
N; ++
I)
1020 unsigned FirstFPRegOp = ~0U, SecondFPRegOp = ~0U;
1021 unsigned LiveMask = 0;
1033 "Ret only defs operands, and values aren't live beyond it");
1035 if (FirstFPRegOp == ~0U)
1038 assert(SecondFPRegOp == ~0U &&
"More than two fp operands!");
1051 adjustLiveRegs(LiveMask, MI);
1052 if (!LiveMask)
return;
1058 if (SecondFPRegOp == ~0U) {
1060 assert(StackTop == 1 && FirstFPRegOp == getStackEntry(0) &&
1061 "Top of stack not the right register for RET!");
1073 if (StackTop == 1) {
1074 assert(FirstFPRegOp == SecondFPRegOp && FirstFPRegOp == getStackEntry(0)&&
1075 "Stack misconfiguration for RET!");
1079 unsigned NewReg = ScratchFPReg;
1080 duplicateToTop(FirstFPRegOp, NewReg, MI);
1081 FirstFPRegOp = NewReg;
1085 assert(StackTop == 2 &&
"Must have two values live!");
1089 if (getStackEntry(0) == SecondFPRegOp) {
1090 assert(getStackEntry(1) == FirstFPRegOp &&
"Unknown regs live");
1091 moveToTop(FirstFPRegOp, MI);
1096 assert(getStackEntry(0) == FirstFPRegOp &&
"Unknown regs live");
1097 assert(getStackEntry(1) == SecondFPRegOp &&
"Unknown regs live");
1123 "Can only handle fst* & ftst instructions!");
1135 if (!KillsSrc && (MI.
getOpcode() == X86::IST_Fp64m32 ||
1148 duplicateToTop(Reg, ScratchFPReg, I);
1165 }
else if (KillsSrc) {
1183 assert(NumOps >= 2 &&
"FPRW instructions must have 2 ops!!");
1217 { X86::ADD_Fp32 , X86::ADD_FST0r },
1218 { X86::ADD_Fp64 , X86::ADD_FST0r },
1219 { X86::ADD_Fp80 , X86::ADD_FST0r },
1220 { X86::DIV_Fp32 , X86::DIV_FST0r },
1221 { X86::DIV_Fp64 , X86::DIV_FST0r },
1222 { X86::DIV_Fp80 , X86::DIV_FST0r },
1223 { X86::MUL_Fp32 , X86::MUL_FST0r },
1224 { X86::MUL_Fp64 , X86::MUL_FST0r },
1225 { X86::MUL_Fp80 , X86::MUL_FST0r },
1226 { X86::SUB_Fp32 , X86::SUB_FST0r },
1227 { X86::SUB_Fp64 , X86::SUB_FST0r },
1228 { X86::SUB_Fp80 , X86::SUB_FST0r },
1233 { X86::ADD_Fp32 , X86::ADD_FST0r },
1234 { X86::ADD_Fp64 , X86::ADD_FST0r },
1235 { X86::ADD_Fp80 , X86::ADD_FST0r },
1236 { X86::DIV_Fp32 , X86::DIVR_FST0r },
1237 { X86::DIV_Fp64 , X86::DIVR_FST0r },
1238 { X86::DIV_Fp80 , X86::DIVR_FST0r },
1239 { X86::MUL_Fp32 , X86::MUL_FST0r },
1240 { X86::MUL_Fp64 , X86::MUL_FST0r },
1241 { X86::MUL_Fp80 , X86::MUL_FST0r },
1242 { X86::SUB_Fp32 , X86::SUBR_FST0r },
1243 { X86::SUB_Fp64 , X86::SUBR_FST0r },
1244 { X86::SUB_Fp80 , X86::SUBR_FST0r },
1249 { X86::ADD_Fp32 , X86::ADD_FrST0 },
1250 { X86::ADD_Fp64 , X86::ADD_FrST0 },
1251 { X86::ADD_Fp80 , X86::ADD_FrST0 },
1252 { X86::DIV_Fp32 , X86::DIVR_FrST0 },
1253 { X86::DIV_Fp64 , X86::DIVR_FrST0 },
1254 { X86::DIV_Fp80 , X86::DIVR_FrST0 },
1255 { X86::MUL_Fp32 , X86::MUL_FrST0 },
1256 { X86::MUL_Fp64 , X86::MUL_FrST0 },
1257 { X86::MUL_Fp80 , X86::MUL_FrST0 },
1258 { X86::SUB_Fp32 , X86::SUBR_FrST0 },
1259 { X86::SUB_Fp64 , X86::SUBR_FrST0 },
1260 { X86::SUB_Fp80 , X86::SUBR_FrST0 },
1265 { X86::ADD_Fp32 , X86::ADD_FrST0 },
1266 { X86::ADD_Fp64 , X86::ADD_FrST0 },
1267 { X86::ADD_Fp80 , X86::ADD_FrST0 },
1268 { X86::DIV_Fp32 , X86::DIV_FrST0 },
1269 { X86::DIV_Fp64 , X86::DIV_FrST0 },
1270 { X86::DIV_Fp80 , X86::DIV_FrST0 },
1271 { X86::MUL_Fp32 , X86::MUL_FrST0 },
1272 { X86::MUL_Fp64 , X86::MUL_FrST0 },
1273 { X86::MUL_Fp80 , X86::MUL_FrST0 },
1274 { X86::SUB_Fp32 , X86::SUB_FrST0 },
1275 { X86::SUB_Fp64 , X86::SUB_FrST0 },
1276 { X86::SUB_Fp80 , X86::SUB_FrST0 },
1294 assert(NumOperands == 3 &&
"Illegal TwoArgFP instruction!");
1302 unsigned TOS = getStackEntry(0);
1306 if (Op0 != TOS && Op1 != TOS) {
1313 }
else if (KillsOp1) {
1322 duplicateToTop(Op0, Dest, I);
1326 }
else if (!KillsOp0 && !KillsOp1) {
1330 duplicateToTop(Op0, Dest, I);
1337 assert((TOS == Op0 || TOS == Op1) && (KillsOp0 || KillsOp1) &&
1338 "Stack conditions not set up right!");
1343 bool isForward = TOS == Op0;
1344 bool updateST0 = (TOS == Op0 && !KillsOp1) || (TOS == Op1 && !KillsOp0);
1358 assert(Opcode != -1 &&
"Unknown TwoArgFP pseudo instruction!");
1361 unsigned NotTOS = (TOS == Op0) ? Op1 : Op0;
1365 I =
BuildMI(*MBB, I, dl, TII->
get(Opcode)).addReg(getSTReg(NotTOS));
1369 if (KillsOp0 && KillsOp1 && Op0 != Op1) {
1370 assert(!updateST0 &&
"Should have updated other operand!");
1376 unsigned UpdatedSlot = getSlot(updateST0 ? TOS : NotTOS);
1377 assert(UpdatedSlot < StackTop && Dest < 7);
1378 Stack[UpdatedSlot] = Dest;
1379 RegMap[Dest] = UpdatedSlot;
1390 assert(NumOperands == 2 &&
"Illegal FUCOM* instruction!");
1406 if (KillsOp0) freeStackSlotAfter(I, Op0);
1407 if (KillsOp1 && Op0 != Op1) freeStackSlotAfter(I, Op1);
1432 if (Op0 != Op1 && KillsOp1) {
1434 freeStackSlotAfter(I, Op1);
1458 case TargetOpcode::COPY: {
1467 assert(isLive(SrcFP) &&
"Cannot copy dead register");
1471 unsigned Slot = getSlot(SrcFP);
1472 Stack[Slot] = DstFP;
1473 RegMap[DstFP] = Slot;
1477 duplicateToTop(SrcFP, DstFP, Inst);
1482 case TargetOpcode::IMPLICIT_DEF: {
1485 LLVM_DEBUG(
dbgs() <<
"Emitting LD_F0 for implicit FP" << Reg <<
'\n');
1526 unsigned STUses = 0, STDefs = 0, STClobbers = 0, STDeadDefs = 0;
1527 unsigned NumOps = 0;
1541 unsigned STReg = MO.
getReg() - X86::FP0;
1554 STUses |= (1u << STReg);
1558 STDefs |= (1u << STReg);
1560 STDeadDefs |= (1u << STReg);
1563 STClobbers |= (1u << STReg);
1571 MI.
emitError(
"fixed input regs must be last on the x87 stack");
1576 MI.
emitError(
"output regs must be last on the x87 stack");
1582 if (STClobbers && !
isMask_32(STDefs | STClobbers))
1583 MI.
emitError(
"clobbers must be last on the x87 stack");
1586 unsigned STPopped = STUses & (STDefs | STClobbers);
1588 MI.
emitError(
"implicitly popped regs must be last on the x87 stack");
1591 LLVM_DEBUG(
dbgs() <<
"Asm uses " << NumSTUses <<
" fixed regs, pops " 1592 << NumSTPopped <<
", and defines " << NumSTDefs
1599 if (FRegIdx.
count(I)) {
1601 "Operands with constraint \"f\" cannot overlap with defs");
1607 unsigned FPKills = ((1u << NumFPRegs) - 1) & ~0xff;
1618 FPKills |= 1U << FPReg;
1622 FPKills &= ~(STDefs | STClobbers);
1625 unsigned char STUsesArray[8];
1627 for (
unsigned I = 0; I < NumSTUses; ++
I)
1630 shuffleStackTop(STUsesArray, NumSTUses, Inst);
1632 dbgs() <<
"Before asm: ";
1644 if (FRegIdx.
count(i))
1646 Op.
setReg(getSTReg(FPReg));
1649 Op.
setReg(X86::ST0 + FPReg);
1653 StackTop -= NumSTPopped;
1655 for (
unsigned i = 0; i < NumSTDefs; ++i)
1656 pushReg(NumSTDefs - i - 1);
1668 freeStackSlotAfter(Inst, FPReg);
1669 FPKills &= ~(1U << FPReg);
1677 Inst = MBB->
erase(Inst);
1681 if (Inst == MBB->
begin()) {
1697 if (I->isDebugInstr())
1700 std::bitset<8> Defs;
1704 for (
auto &MO : I->operands()) {
1708 unsigned Reg = MO.getReg() - X86::FP0;
1721 for (
auto *MO : Uses)
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static const TableEntry OpcodeTable[]
bool isCall(QueryType Type=AnyInBundle) const
unsigned getBundle(unsigned N, bool Out) const
getBundle - Return the ingoing (Out = false) or outgoing (Out = true) bundle number for basic block N...
void emitError(StringRef Msg) const
Emit an error referring to the source location of this instruction.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
static unsigned getConcreteOpcode(unsigned Opcode)
FunctionPass * createX86FloatingPointStackifierPass()
This function returns a pass which converts floating-point register references and pseudo instruction...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
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.
AddrNumOperands - Total number of operands in a memory reference.
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
static const TableEntry ReverseSTiTable[]
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
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.
unsigned 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...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
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...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getNumOperands() const
Retuns the total number of operands.
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
static const TableEntry ForwardST0Table[]
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LiveInVector::const_iterator livein_iterator
INLINEASM - Represents an inline asm block.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
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)
void setReg(Register Reg)
Change the register this operand corresponds to.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
reverse_iterator rbegin()
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 isReturn(QueryType Type=AnyInBundle) const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool killsRegister(Register Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr kills the specified register.
static const TableEntry ForwardSTiTable[]
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
livein_iterator livein_end() const
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.
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
#define LLVM_ATTRIBUTE_UNUSED
bool reg_nodbg_empty(Register RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions...
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.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
bool isImplicitDef() const
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...
const MachineBasicBlock & front() const
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
INITIALIZE_PASS_BEGIN(FPS, DEBUG_TYPE, "X86 FP Stackifier", false, false) INITIALIZE_PASS_END(FPS
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Register calling convention used for parameters transfer optimization.
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...
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
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)
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly. ...
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.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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.
unsigned getNumBundles() const
getNumBundles - Return the total number of bundles in the CFG.
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.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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...
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
LLVM_NODISCARD bool empty() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
INLINEASM_BR - Terminator version of inline asm. Used by asm-goto.
bool operator<(int64_t V1, const APSInt &V2)
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
#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.
StringRef - Represent a constant reference to a string, i.e.
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
livein_iterator livein_begin() const
Properties which a MachineFunction may have at a given point in time.
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.