From 742c37184cc33e084a4cb3ca23d9127eebedb1f8 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Tue, 24 Jul 2018 20:13:10 +0000 Subject: [PATCH] [MachineOutliner][NFC] Move target frame info into OutlinedFunction Just some gardening here. Similar to how we moved call information into Candidates, this moves outlined frame information into OutlinedFunction. This allows us to remove TargetCostInfo entirely. Anywhere where we returned a TargetCostInfo struct, we now return an OutlinedFunction. This establishes OutlinedFunctions as more of a general repeated sequence, and Candidates as occurrences of those repeated sequences. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337848 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineOutliner.h | 45 +++++++++---------------- include/llvm/CodeGen/TargetInstrInfo.h | 9 +++-- lib/CodeGen/MachineOutliner.cpp | 9 +++-- lib/Target/AArch64/AArch64InstrInfo.cpp | 21 ++++++------ lib/Target/AArch64/AArch64InstrInfo.h | 4 +-- lib/Target/X86/X86InstrInfo.cpp | 15 +++++---- lib/Target/X86/X86InstrInfo.h | 4 +-- 7 files changed, 47 insertions(+), 60 deletions(-) diff --git a/include/llvm/CodeGen/MachineOutliner.h b/include/llvm/CodeGen/MachineOutliner.h index d12fedc7a3b..5aa0382ce7b 100644 --- a/include/llvm/CodeGen/MachineOutliner.h +++ b/include/llvm/CodeGen/MachineOutliner.h @@ -32,28 +32,6 @@ namespace outliner { /// shouldn't actually impact the outlining result. enum InstrType { Legal, LegalTerminator, Illegal, Invisible }; -/// Describes the number of instructions that it will take to call and -/// construct a frame for a given outlining candidate. -struct TargetCostInfo { - /// Represents the size of a sequence in bytes. (Some instructions vary - /// widely in size, so just counting the instructions isn't very useful.) - unsigned SequenceSize; - - /// Number of instructions to construct an outlined function frame - /// for this candidate. - unsigned FrameOverhead; - - /// Represents the specific instructions that must be emitted to - /// construct a frame for this candidate's outlined function. - unsigned FrameConstructionID; - - TargetCostInfo() {} - TargetCostInfo(unsigned SequenceSize, unsigned FrameOverhead, - unsigned FrameConstructionID) - : SequenceSize(SequenceSize), FrameOverhead(FrameOverhead), - FrameConstructionID(FrameConstructionID) {} -}; - /// An individual sequence of instructions to be replaced with a call to /// an outlined function. struct Candidate { @@ -184,8 +162,15 @@ public: /// function. std::vector Sequence; - /// Contains all target-specific information for this \p OutlinedFunction. - TargetCostInfo TCI; + /// Represents the size of a sequence in bytes. (Some instructions vary + /// widely in size, so just counting the instructions isn't very useful.) + unsigned SequenceSize; + + /// Target-defined overhead of constructing a frame for this function. + unsigned FrameOverhead; + + /// Target-defined identifier for constructing a frame for this function. + unsigned FrameConstructionID; /// Return the number of candidates for this \p OutlinedFunction. unsigned getOccurrenceCount() { return OccurrenceCount; } @@ -204,11 +189,11 @@ public: unsigned CallOverhead = 0; for (std::shared_ptr &C : Candidates) CallOverhead += C->getCallOverhead(); - return CallOverhead + TCI.SequenceSize + TCI.FrameOverhead; + return CallOverhead + SequenceSize + FrameOverhead; } /// Return the size in bytes of the unoutlined sequences. - unsigned getNotOutlinedCost() { return OccurrenceCount * TCI.SequenceSize; } + unsigned getNotOutlinedCost() { return OccurrenceCount * SequenceSize; } /// Return the number of instructions that would be saved by outlining /// this function. @@ -219,9 +204,11 @@ public: : NotOutlinedCost - OutlinedCost; } - OutlinedFunction(unsigned Name, std::vector &Cands, - const std::vector &Sequence, TargetCostInfo &TCI) - : Name(Name), Sequence(Sequence), TCI(TCI) { + OutlinedFunction(std::vector &Cands, + unsigned SequenceSize, unsigned FrameOverhead, + unsigned FrameConstructionID) + : SequenceSize(SequenceSize), FrameOverhead(FrameOverhead), + FrameConstructionID(FrameConstructionID) { OccurrenceCount = Cands.size(); for (Candidate &C : Cands) Candidates.push_back(std::make_shared(C)); diff --git a/include/llvm/CodeGen/TargetInstrInfo.h b/include/llvm/CodeGen/TargetInstrInfo.h index 3b270ab1dfa..b5bc561d834 100644 --- a/include/llvm/CodeGen/TargetInstrInfo.h +++ b/include/llvm/CodeGen/TargetInstrInfo.h @@ -1602,9 +1602,9 @@ public: return false; } - /// Returns a \p outliner::TargetCostInfo struct containing target-specific + /// Returns a \p outliner::OutlinedFunction struct containing target-specific /// information for a set of outlining candidates. - virtual outliner::TargetCostInfo getOutliningCandidateInfo( + virtual outliner::OutlinedFunction getOutliningCandidateInfo( std::vector &RepeatedSequenceLocs) const { llvm_unreachable( "Target didn't implement TargetInstrInfo::getOutliningCandidateInfo!"); @@ -1624,9 +1624,8 @@ public: } /// Insert a custom frame for outlined functions. - virtual void buildOutlinedFrame(MachineBasicBlock &MBB, - MachineFunction &MF, - const outliner::TargetCostInfo &TCI) const { + virtual void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, + const outliner::OutlinedFunction &OF) const { llvm_unreachable( "Target didn't implement TargetInstrInfo::buildOutlinedFrame!"); } diff --git a/lib/CodeGen/MachineOutliner.cpp b/lib/CodeGen/MachineOutliner.cpp index 99cc5f70dc3..dfd9d14ef56 100644 --- a/lib/CodeGen/MachineOutliner.cpp +++ b/lib/CodeGen/MachineOutliner.cpp @@ -947,13 +947,12 @@ unsigned MachineOutliner::findCandidates( // We've found something we might want to outline. // Create an OutlinedFunction to store it and check if it'd be beneficial // to outline. - TargetCostInfo TCI = - TII.getOutliningCandidateInfo(CandidatesForRepeatedSeq); + OutlinedFunction OF = TII.getOutliningCandidateInfo(CandidatesForRepeatedSeq); std::vector Seq; for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++) Seq.push_back(ST.Str[i]); - OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq, Seq, - TCI); + OF.Sequence = Seq; + OF.Name = FunctionList.size(); // Is it better to outline this candidate than not? if (OF.getBenefit() < 1) { @@ -1166,7 +1165,7 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF, MBB.insert(MBB.end(), NewMI); } - TII.buildOutlinedFrame(MBB, MF, OF.TCI); + TII.buildOutlinedFrame(MBB, MF, OF); // If there's a DISubprogram associated with this outlined function, then // emit debug info for the outlined function. diff --git a/lib/Target/AArch64/AArch64InstrInfo.cpp b/lib/Target/AArch64/AArch64InstrInfo.cpp index 9d163487c44..dc3fa4f8c1d 100644 --- a/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -4927,7 +4927,7 @@ enum MachineOutlinerMBBFlags { HasCalls = 0x4 }; -outliner::TargetCostInfo +outliner::OutlinedFunction AArch64InstrInfo::getOutliningCandidateInfo( std::vector &RepeatedSequenceLocs) const { unsigned SequenceSize = std::accumulate( @@ -5034,7 +5034,8 @@ AArch64InstrInfo::getOutliningCandidateInfo( RepeatedSequenceLocs[0].back()->isCall()) NumBytesToCreateFrame += 8; - return outliner::TargetCostInfo(SequenceSize, NumBytesToCreateFrame, FrameID); + return outliner::OutlinedFunction(RepeatedSequenceLocs, SequenceSize, + NumBytesToCreateFrame, FrameID); } bool AArch64InstrInfo::isFunctionSafeToOutlineFrom( @@ -5332,10 +5333,10 @@ void AArch64InstrInfo::fixupPostOutline(MachineBasicBlock &MBB) const { void AArch64InstrInfo::buildOutlinedFrame( MachineBasicBlock &MBB, MachineFunction &MF, - const outliner::TargetCostInfo &TCI) const { + const outliner::OutlinedFunction &OF) const { // For thunk outlining, rewrite the last instruction from a call to a // tail-call. - if (TCI.FrameConstructionID == MachineOutlinerThunk) { + if (OF.FrameConstructionID == MachineOutlinerThunk) { MachineInstr *Call = &*--MBB.instr_end(); unsigned TailOpcode; if (Call->getOpcode() == AArch64::BL) { @@ -5358,7 +5359,7 @@ void AArch64InstrInfo::buildOutlinedFrame( if (std::any_of(MBB.instr_begin(), MBB.instr_end(), IsNonTailCall)) { // Fix up the instructions in the range, since we're going to modify the // stack. - assert(TCI.FrameConstructionID != MachineOutlinerDefault && + assert(OF.FrameConstructionID != MachineOutlinerDefault && "Can only fix up stack references once"); fixupPostOutline(MBB); @@ -5368,8 +5369,8 @@ void AArch64InstrInfo::buildOutlinedFrame( MachineBasicBlock::iterator It = MBB.begin(); MachineBasicBlock::iterator Et = MBB.end(); - if (TCI.FrameConstructionID == MachineOutlinerTailCall || - TCI.FrameConstructionID == MachineOutlinerThunk) + if (OF.FrameConstructionID == MachineOutlinerTailCall || + OF.FrameConstructionID == MachineOutlinerThunk) Et = std::prev(MBB.end()); // Insert a save before the outlined region @@ -5409,8 +5410,8 @@ void AArch64InstrInfo::buildOutlinedFrame( } // If this is a tail call outlined function, then there's already a return. - if (TCI.FrameConstructionID == MachineOutlinerTailCall || - TCI.FrameConstructionID == MachineOutlinerThunk) + if (OF.FrameConstructionID == MachineOutlinerTailCall || + OF.FrameConstructionID == MachineOutlinerThunk) return; // It's not a tail call, so we have to insert the return ourselves. @@ -5419,7 +5420,7 @@ void AArch64InstrInfo::buildOutlinedFrame( MBB.insert(MBB.end(), ret); // Did we have to modify the stack by saving the link register? - if (TCI.FrameConstructionID == MachineOutlinerNoLRSave) + if (OF.FrameConstructionID == MachineOutlinerNoLRSave) return; // We modified the stack. diff --git a/lib/Target/AArch64/AArch64InstrInfo.h b/lib/Target/AArch64/AArch64InstrInfo.h index 7249657eca3..0e5953f6216 100644 --- a/lib/Target/AArch64/AArch64InstrInfo.h +++ b/lib/Target/AArch64/AArch64InstrInfo.h @@ -238,13 +238,13 @@ public: bool isFunctionSafeToOutlineFrom(MachineFunction &MF, bool OutlineFromLinkOnceODRs) const override; - outliner::TargetCostInfo getOutliningCandidateInfo( + outliner::OutlinedFunction getOutliningCandidateInfo( std::vector &RepeatedSequenceLocs) const override; outliner::InstrType getOutliningType(MachineBasicBlock::iterator &MIT, unsigned Flags) const override; unsigned getMachineOutlinerMBBFlags(MachineBasicBlock &MBB) const override; void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, - const outliner::TargetCostInfo &TCI) const override; + const outliner::OutlinedFunction &OF) const override; MachineBasicBlock::iterator insertOutlinedCall(Module &M, MachineBasicBlock &MBB, MachineBasicBlock::iterator &It, MachineFunction &MF, diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 5a0a0ecd066..1b61accfb42 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -7588,7 +7588,7 @@ enum MachineOutlinerClass { MachineOutlinerTailCall }; -outliner::TargetCostInfo X86InstrInfo::getOutliningCandidateInfo( +outliner::OutlinedFunction X86InstrInfo::getOutliningCandidateInfo( std::vector &RepeatedSequenceLocs) const { unsigned SequenceSize = std::accumulate(RepeatedSequenceLocs[0].front(), @@ -7607,16 +7607,17 @@ outliner::TargetCostInfo X86InstrInfo::getOutliningCandidateInfo( for (outliner::Candidate &C : RepeatedSequenceLocs) C.setCallInfo(MachineOutlinerTailCall, 1); - return outliner::TargetCostInfo(SequenceSize, - 0, // Number of bytes to emit frame. - MachineOutlinerTailCall // Type of frame. + return outliner::OutlinedFunction(RepeatedSequenceLocs, SequenceSize, + 0, // Number of bytes to emit frame. + MachineOutlinerTailCall // Type of frame. ); } for (outliner::Candidate &C : RepeatedSequenceLocs) C.setCallInfo(MachineOutlinerDefault, 1); - return outliner::TargetCostInfo(SequenceSize, 1, MachineOutlinerDefault); + return outliner::OutlinedFunction(RepeatedSequenceLocs, SequenceSize, 1, + MachineOutlinerDefault); } bool X86InstrInfo::isFunctionSafeToOutlineFrom(MachineFunction &MF, @@ -7703,10 +7704,10 @@ X86InstrInfo::getOutliningType(MachineBasicBlock::iterator &MIT, unsigned Flags void X86InstrInfo::buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, - const outliner::TargetCostInfo &TCI) + const outliner::OutlinedFunction &OF) const { // If we're a tail call, we already have a return, so don't do anything. - if (TCI.FrameConstructionID == MachineOutlinerTailCall) + if (OF.FrameConstructionID == MachineOutlinerTailCall) return; // We're a normal call, so our sequence doesn't have a return instruction. diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h index b1e510ae059..b1ceb767cce 100644 --- a/lib/Target/X86/X86InstrInfo.h +++ b/lib/Target/X86/X86InstrInfo.h @@ -544,7 +544,7 @@ public: ArrayRef> getSerializableDirectMachineOperandTargetFlags() const override; - virtual outliner::TargetCostInfo getOutliningCandidateInfo( + virtual outliner::OutlinedFunction getOutliningCandidateInfo( std::vector &RepeatedSequenceLocs) const override; bool isFunctionSafeToOutlineFrom(MachineFunction &MF, @@ -554,7 +554,7 @@ public: getOutliningType(MachineBasicBlock::iterator &MIT, unsigned Flags) const override; void buildOutlinedFrame(MachineBasicBlock &MBB, MachineFunction &MF, - const outliner::TargetCostInfo &TCI) const override; + const outliner::OutlinedFunction &OF) const override; MachineBasicBlock::iterator insertOutlinedCall(Module &M, MachineBasicBlock &MBB, -- 2.50.1