llvm.org GIT mirror llvm / 0157cb5
[MachineOutliner][NFC] Only map blocks which have adjacent legal instructions If a block doesn't have any ranges of adjacent legal instructions, then it can't have outlining candidates. There's no point in mapping legal isntructions in situations like this. I noticed this reduces the size of the suffix tree in sqlite3 for AArch64 at -Oz by about 3%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346379 91177308-0d34-0410-b5e6-96231b3b80d8 Jessica Paquette 10 months ago
1 changed file(s) with 36 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
639639
640640 /// Maps \p *It to a legal integer.
641641 ///
642 /// Updates \p InstrListForMBB, \p UnsignedVecForMBB, \p
643 /// InstructionIntegerMap, \p IntegerInstructionMap, and \p LegalInstrNumber.
642 /// Updates \p CanOutlineWithPrevInstr, \p HaveLegalRange, \p InstrListForMBB,
643 /// \p UnsignedVecForMBB, \p InstructionIntegerMap, \p IntegerInstructionMap,
644 /// and \p LegalInstrNumber.
644645 ///
645646 /// \returns The integer that \p *It was mapped to.
646647 unsigned mapToLegalUnsigned(
647 MachineBasicBlock::iterator &It, unsigned &NumLegalInBlock,
648 MachineBasicBlock::iterator &It, bool &CanOutlineWithPrevInstr,
649 bool &HaveLegalRange, unsigned &NumLegalInBlock,
648650 std::vector &UnsignedVecForMBB,
649651 std::vector &InstrListForMBB) {
650652 // We added something legal, so we should unset the AddedLegalLastTime
651653 // flag.
652654 AddedIllegalLastTime = false;
655
656 // If we have at least two adjacent legal instructions (which may have
657 // invisible instructions in between), remember that.
658 if (CanOutlineWithPrevInstr)
659 HaveLegalRange = true;
660 CanOutlineWithPrevInstr = true;
653661
654662 // Keep track of the number of legal instructions we insert.
655663 NumLegalInBlock++;
691699 /// IllegalInstrNumber.
692700 ///
693701 /// \returns The integer that \p *It was mapped to.
694 unsigned mapToIllegalUnsigned(
695 MachineBasicBlock::iterator &It, std::vector &UnsignedVecForMBB,
696 std::vector &InstrListForMBB) {
702 unsigned mapToIllegalUnsigned(MachineBasicBlock::iterator &It,
703 bool &CanOutlineWithPrevInstr, std::vector &UnsignedVecForMBB,
704 std::vector &InstrListForMBB) {
705 // Can't outline an illegal instruction. Set the flag.
706 CanOutlineWithPrevInstr = false;
707
697708 // Only add one illegal number per range of legal numbers.
698709 if (AddedIllegalLastTime)
699710 return IllegalInstrNumber;
737748 // outlining.
738749 unsigned NumLegalInBlock = 0;
739750
751 // True if we have at least two legal instructions which aren't separated
752 // by an illegal instruction.
753 bool HaveLegalRange = false;
754
755 // True if we can perform outlining given the last mapped (non-invisible)
756 // instruction. This lets us know if we have a legal range.
757 bool CanOutlineWithPrevInstr = false;
758
740759 // FIXME: Should this all just be handled in the target, rather than using
741760 // repeated calls to getOutliningType?
742761 std::vector UnsignedVecForMBB;
746765 // Keep track of where this instruction is in the module.
747766 switch (TII.getOutliningType(It, Flags)) {
748767 case InstrType::Illegal:
749 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
768 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr,
769 UnsignedVecForMBB, InstrListForMBB);
750770 break;
751771
752772 case InstrType::Legal:
753 mapToLegalUnsigned(It, NumLegalInBlock, UnsignedVecForMBB,
754 InstrListForMBB);
773 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
774 NumLegalInBlock, UnsignedVecForMBB, InstrListForMBB);
755775 break;
756776
757777 case InstrType::LegalTerminator:
758 mapToLegalUnsigned(It, NumLegalInBlock, UnsignedVecForMBB,
759 InstrListForMBB);
778 mapToLegalUnsigned(It, CanOutlineWithPrevInstr, HaveLegalRange,
779 NumLegalInBlock, UnsignedVecForMBB, InstrListForMBB);
760780 // The instruction also acts as a terminator, so we have to record that
761781 // in the string.
762 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
782 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
783 InstrListForMBB);
763784 break;
764785
765786 case InstrType::Invisible:
772793
773794 // Are there enough legal instructions in the block for outlining to be
774795 // possible?
775 if (NumLegalInBlock > 1) {
796 if (HaveLegalRange) {
776797 // After we're done every insertion, uniquely terminate this part of the
777798 // "string". This makes sure we won't match across basic block or function
778799 // boundaries since the "end" is encoded uniquely and thus appears in no
779800 // repeated substring.
780 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
801 mapToIllegalUnsigned(It, CanOutlineWithPrevInstr, UnsignedVecForMBB,
802 InstrListForMBB);
781803 InstrList.insert(InstrList.end(), InstrListForMBB.begin(),
782804 InstrListForMBB.end());
783805 UnsignedVec.insert(UnsignedVec.end(), UnsignedVecForMBB.begin(),