llvm.org GIT mirror llvm / de78771
[MachineOutliner][NFC] Don't map MBBs that don't contain legal instructions I noticed that there are lots of basic blocks that don't have enough legal instructions in them to warrant outlining. We can skip mapping these entirely. In sqlite3, compiled for AArch64 at -Oz, this results in a 10% reduction of the total nodes in the suffix tree. These nodes can never be part of a repeated substring, and so they don't impact the result at all. Before this, there were 62128 nodes in the tree for sqlite3. After this, there are 56457 nodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346373 91177308-0d34-0410-b5e6-96231b3b80d8 Jessica Paquette 10 months ago
1 changed file(s) with 47 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
639639
640640 /// Maps \p *It to a legal integer.
641641 ///
642 /// Updates \p InstrList, \p UnsignedVec, \p InstructionIntegerMap,
643 /// \p IntegerInstructionMap, and \p LegalInstrNumber.
642 /// Updates \p InstrListForMBB, \p UnsignedVecForMBB, \p
643 /// InstructionIntegerMap, \p IntegerInstructionMap, and \p LegalInstrNumber.
644644 ///
645645 /// \returns The integer that \p *It was mapped to.
646 unsigned mapToLegalUnsigned(MachineBasicBlock::iterator &It) {
646 unsigned mapToLegalUnsigned(
647 MachineBasicBlock::iterator &It, unsigned &NumLegalInBlock,
648 std::vector &UnsignedVecForMBB,
649 std::vector &InstrListForMBB) {
647650 // We added something legal, so we should unset the AddedLegalLastTime
648651 // flag.
649652 AddedIllegalLastTime = false;
650653
654 // Keep track of the number of legal instructions we insert.
655 NumLegalInBlock++;
656
651657 // Get the integer for this instruction or give it the current
652658 // LegalInstrNumber.
653 InstrList.push_back(It);
659 InstrListForMBB.push_back(It);
654660 MachineInstr &MI = *It;
655661 bool WasInserted;
656662 DenseMap::iterator
665671 IntegerInstructionMap.insert(std::make_pair(MINumber, &MI));
666672 }
667673
668 UnsignedVec.push_back(MINumber);
674 UnsignedVecForMBB.push_back(MINumber);
669675
670676 // Make sure we don't overflow or use any integers reserved by the DenseMap.
671677 if (LegalInstrNumber >= IllegalInstrNumber)
681687
682688 /// Maps \p *It to an illegal integer.
683689 ///
684 /// Updates \p InstrList, \p UnsignedVec, and \p IllegalInstrNumber.
690 /// Updates \p InstrListForMBB, \p UnsignedVecForMBB, and \p
691 /// IllegalInstrNumber.
685692 ///
686693 /// \returns The integer that \p *It was mapped to.
687 unsigned mapToIllegalUnsigned(MachineBasicBlock::iterator &It) {
694 unsigned mapToIllegalUnsigned(
695 MachineBasicBlock::iterator &It, std::vector &UnsignedVecForMBB,
696 std::vector &InstrListForMBB) {
688697 // Only add one illegal number per range of legal numbers.
689698 if (AddedIllegalLastTime)
690699 return IllegalInstrNumber;
693702 AddedIllegalLastTime = true;
694703 unsigned MINumber = IllegalInstrNumber;
695704
696 InstrList.push_back(It);
697 UnsignedVec.push_back(IllegalInstrNumber);
705 InstrListForMBB.push_back(It);
706 UnsignedVecForMBB.push_back(IllegalInstrNumber);
698707 IllegalInstrNumber--;
699708
700709 assert(LegalInstrNumber < IllegalInstrNumber &&
723732 const TargetInstrInfo &TII) {
724733 unsigned Flags = TII.getMachineOutlinerMBBFlags(MBB);
725734 MachineBasicBlock::iterator It = MBB.begin();
735
736 // The number of instructions in this block that will be considered for
737 // outlining.
738 unsigned NumLegalInBlock = 0;
739
740 // FIXME: Should this all just be handled in the target, rather than using
741 // repeated calls to getOutliningType?
742 std::vector UnsignedVecForMBB;
743 std::vector InstrListForMBB;
744
726745 for (MachineBasicBlock::iterator Et = MBB.end(); It != Et; It++) {
727746 // Keep track of where this instruction is in the module.
728747 switch (TII.getOutliningType(It, Flags)) {
729748 case InstrType::Illegal:
730 mapToIllegalUnsigned(It);
749 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
731750 break;
732751
733752 case InstrType::Legal:
734 mapToLegalUnsigned(It);
753 mapToLegalUnsigned(It, NumLegalInBlock, UnsignedVecForMBB,
754 InstrListForMBB);
735755 break;
736756
737757 case InstrType::LegalTerminator:
738 mapToLegalUnsigned(It);
758 mapToLegalUnsigned(It, NumLegalInBlock, UnsignedVecForMBB,
759 InstrListForMBB);
739760 // The instruction also acts as a terminator, so we have to record that
740761 // in the string.
741 mapToIllegalUnsigned(It);
762 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
742763 break;
743764
744765 case InstrType::Invisible:
749770 }
750771 }
751772
752 // After we're done every insertion, uniquely terminate this part of the
753 // "string". This makes sure we won't match across basic block or function
754 // boundaries since the "end" is encoded uniquely and thus appears in no
755 // repeated substring.
756 mapToIllegalUnsigned(It);
773 // Are there enough legal instructions in the block for outlining to be
774 // possible?
775 if (NumLegalInBlock > 1) {
776 // After we're done every insertion, uniquely terminate this part of the
777 // "string". This makes sure we won't match across basic block or function
778 // boundaries since the "end" is encoded uniquely and thus appears in no
779 // repeated substring.
780 mapToIllegalUnsigned(It, UnsignedVecForMBB, InstrListForMBB);
781 InstrList.insert(InstrList.end(), InstrListForMBB.begin(),
782 InstrListForMBB.end());
783 UnsignedVec.insert(UnsignedVec.end(), UnsignedVecForMBB.begin(),
784 UnsignedVecForMBB.end());
785 }
757786 }
758787
759788 InstructionMapper() {