diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 26 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86InstrInfo.cpp | 19 |
3 files changed, 42 insertions, 22 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index afee909eaa2..be12b207b89 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -210,17 +210,22 @@ public: return getOccurrenceCount(); } - /// Return the number of instructions it would take to outline this + /// Return the number of bytes it would take to outline this /// function. unsigned getOutliningCost() { - return (OccurrenceCount * MInfo.CallOverhead) + Sequence.size() + + return (OccurrenceCount * MInfo.CallOverhead) + MInfo.SequenceSize + MInfo.FrameOverhead; } + /// Return the size in bytes of the unoutlined sequences. + unsigned getNotOutlinedCost() { + return OccurrenceCount * MInfo.SequenceSize; + } + /// Return the number of instructions that would be saved by outlining /// this function. unsigned getBenefit() { - unsigned NotOutlinedCost = OccurrenceCount * Sequence.size(); + unsigned NotOutlinedCost = getNotOutlinedCost(); unsigned OutlinedCost = getOutliningCost(); return (NotOutlinedCost < OutlinedCost) ? 0 : NotOutlinedCost - OutlinedCost; @@ -1054,10 +1059,10 @@ unsigned MachineOutliner::findCandidates( R << "Did not outline " << NV("Length", StringLen) << " instructions" << " from " << NV("NumOccurrences", RepeatedSequenceLocs.size()) << " locations." - << " Instructions from outlining all occurrences (" + << " Bytes from outlining all occurrences (" << NV("OutliningCost", OF.getOutliningCost()) << ")" - << " >= Unoutlined instruction count (" - << NV("NotOutliningCost", StringLen * OF.getOccurrenceCount()) << ")" + << " >= Unoutlined instruction bytes (" + << NV("NotOutliningCost", OF.getNotOutlinedCost()) << ")" << " (Also found at: "; // Tell the user the other places the candidate was found. @@ -1378,7 +1383,7 @@ bool MachineOutliner::outline( MachineOptimizationRemark R(DEBUG_TYPE, "OutlinedFunction", MBB->findDebugLoc(MBB->begin()), MBB); R << "Saved " << NV("OutliningBenefit", OF.getBenefit()) - << " instructions by " + << " bytes by " << "outlining " << NV("Length", OF.Sequence.size()) << " instructions " << "from " << NV("NumOccurrences", OF.getOccurrenceCount()) << " locations. " diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp index 97164ff785e..914bdc70dfa 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -4936,11 +4936,15 @@ AArch64InstrInfo::getOutlininingCandidateInfo( std::vector< std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>> &RepeatedSequenceLocs) const { - + unsigned SequenceSize = std::accumulate( + RepeatedSequenceLocs[0].first, std::next(RepeatedSequenceLocs[0].second), + 0, [this](unsigned Sum, const MachineInstr &MI) { + return Sum + getInstSizeInBytes(MI); + }); unsigned CallID = MachineOutlinerDefault; unsigned FrameID = MachineOutlinerDefault; - unsigned NumInstrsForCall = 3; - unsigned NumInstrsToCreateFrame = 1; + unsigned NumBytesForCall = 12; + unsigned NumBytesToCreateFrame = 4; auto DoesntNeedLRSave = [this](std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator> @@ -4951,23 +4955,23 @@ AArch64InstrInfo::getOutlininingCandidateInfo( if (RepeatedSequenceLocs[0].second->isTerminator()) { CallID = MachineOutlinerTailCall; FrameID = MachineOutlinerTailCall; - NumInstrsForCall = 1; - NumInstrsToCreateFrame = 0; + NumBytesForCall = 4; + NumBytesToCreateFrame = 0; } else if (std::all_of(RepeatedSequenceLocs.begin(), RepeatedSequenceLocs.end(), DoesntNeedLRSave)) { CallID = MachineOutlinerNoLRSave; FrameID = MachineOutlinerNoLRSave; - NumInstrsForCall = 1; - NumInstrsToCreateFrame = 1; + NumBytesForCall = 4; + NumBytesToCreateFrame = 4; } // Check if the range contains a call. These require a save + restore of the // link register. if (std::any_of(RepeatedSequenceLocs[0].first, RepeatedSequenceLocs[0].second, [](const MachineInstr &MI) { return MI.isCall(); })) - NumInstrsToCreateFrame += 2; // Save + restore the link register. + NumBytesToCreateFrame += 8; // Save + restore the link register. // Handle the last instruction separately. If this is a tail call, then the // last instruction is a call. We don't want to save + restore in this case. @@ -4975,10 +4979,10 @@ AArch64InstrInfo::getOutlininingCandidateInfo( // it being valid to tail call this sequence. We should consider this as well. else if (RepeatedSequenceLocs[0].second->isCall() && FrameID != MachineOutlinerTailCall) - NumInstrsToCreateFrame += 2; + NumBytesToCreateFrame += 8; - return MachineOutlinerInfo(NumInstrsForCall, NumInstrsToCreateFrame, CallID, - FrameID); + return MachineOutlinerInfo(SequenceSize, NumBytesForCall, + NumBytesToCreateFrame, CallID, FrameID); } bool AArch64InstrInfo::isFunctionSafeToOutlineFrom( diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index fe86cf0e8ff..5d23eb13cbb 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -11134,15 +11134,26 @@ X86InstrInfo::getOutlininingCandidateInfo( std::vector< std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>> &RepeatedSequenceLocs) const { - + unsigned SequenceSize = std::accumulate( + RepeatedSequenceLocs[0].first, std::next(RepeatedSequenceLocs[0].second), + 0, [this](unsigned Sum, const MachineInstr &MI) { + // FIXME: x86 doesn't implement getInstSizeInBytes, so we can't + // tell the cost. Just assume each instruction is one byte. + if (MI.isDebugInstr() || MI.isKill()) + return Sum; + return Sum + 1; + }); + + // FIXME: Use real size in bytes for call and ret instructions. if (RepeatedSequenceLocs[0].second->isTerminator()) - return MachineOutlinerInfo(1, // Number of instructions to emit call. - 0, // Number of instructions to emit frame. + return MachineOutlinerInfo(SequenceSize, + 1, // Number of bytes to emit call. + 0, // Number of bytes to emit frame. MachineOutlinerTailCall, // Type of call. MachineOutlinerTailCall // Type of frame. ); - return MachineOutlinerInfo(1, 1, MachineOutlinerDefault, + return MachineOutlinerInfo(SequenceSize, 1, 1, MachineOutlinerDefault, MachineOutlinerDefault); } |