diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-04 19:20:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:02:26 +0000 |
commit | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch) | |
tree | 311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp | |
parent | 5fff09660e06a66bed6482da9c70df328e16bbb6 (diff) | |
parent | 145449b1e420787bb99721a429341fa6be3adfb6 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp index 7783b5e0d3cc..5da68abc8f6a 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineOutliner.cpp @@ -59,6 +59,8 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/Twine.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/CodeGen/LivePhysRegs.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/CodeGen/Passes.h" @@ -82,9 +84,17 @@ using namespace llvm; using namespace ore; using namespace outliner; +// Statistics for outlined functions. STATISTIC(NumOutlined, "Number of candidates outlined"); STATISTIC(FunctionsCreated, "Number of functions created"); +// Statistics for instruction mapping. +STATISTIC(NumLegalInUnsignedVec, "Number of legal instrs in unsigned vector"); +STATISTIC(NumIllegalInUnsignedVec, + "Number of illegal instrs in unsigned vector"); +STATISTIC(NumInvisible, "Number of invisible instrs in unsigned vector"); +STATISTIC(UnsignedVecSize, "Size of unsigned vector"); + // Set to true if the user wants the outliner to run on linkonceodr linkage // functions. This is false by default because the linker can dedupe linkonceodr // functions. Since the outliner is confined to a single module (modulo LTO), @@ -188,6 +198,8 @@ struct InstructionMapper { assert(LegalInstrNumber != DenseMapInfo<unsigned>::getTombstoneKey() && "Tried to assign DenseMap tombstone or empty key to instruction."); + // Statistics. + ++NumLegalInUnsignedVec; return MINumber; } @@ -215,6 +227,8 @@ struct InstructionMapper { InstrListForMBB.push_back(It); UnsignedVecForMBB.push_back(IllegalInstrNumber); IllegalInstrNumber--; + // Statistics. + ++NumIllegalInUnsignedVec; assert(LegalInstrNumber < IllegalInstrNumber && "Instruction mapping overflow!"); @@ -293,6 +307,7 @@ struct InstructionMapper { case InstrType::Invisible: // Normally this is set by mapTo(Blah)Unsigned, but we just want to // skip this instruction. So, unset the flag here. + ++NumInvisible; AddedIllegalLastTime = false; break; } @@ -623,6 +638,15 @@ MachineFunction *MachineOutliner::createOutlinedFunction( TII.mergeOutliningCandidateAttributes(*F, OF.Candidates); + // Set uwtable, so we generate eh_frame. + UWTableKind UW = std::accumulate( + OF.Candidates.cbegin(), OF.Candidates.cend(), UWTableKind::None, + [](UWTableKind K, const outliner::Candidate &C) { + return std::max(K, C.getMF()->getFunction().getUWTableKind()); + }); + if (UW != UWTableKind::None) + F->setUWTableKind(UW); + BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F); IRBuilder<> Builder(EntryBB); Builder.CreateRetVoid(); @@ -641,17 +665,20 @@ MachineFunction *MachineOutliner::createOutlinedFunction( ++I) { if (I->isDebugInstr()) continue; - MachineInstr *NewMI = MF.CloneMachineInstr(&*I); + + // Don't keep debug information for outlined instructions. + auto DL = DebugLoc(); if (I->isCFIInstruction()) { - unsigned CFIIndex = NewMI->getOperand(0).getCFIIndex(); + unsigned CFIIndex = I->getOperand(0).getCFIIndex(); MCCFIInstruction CFI = Instrs[CFIIndex]; - (void)MF.addFrameInst(CFI); + BuildMI(MBB, MBB.end(), DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) + .addCFIIndex(MF.addFrameInst(CFI)); + } else { + MachineInstr *NewMI = MF.CloneMachineInstr(&*I); + NewMI->dropMemRefs(MF); + NewMI->setDebugLoc(DL); + MBB.insert(MBB.end(), NewMI); } - NewMI->dropMemRefs(MF); - - // Don't keep debug information for outlined instructions. - NewMI->setDebugLoc(DebugLoc()); - MBB.insert(MBB.end(), NewMI); } // Set normal properties for a late MachineFunction. @@ -831,9 +858,10 @@ bool MachineOutliner::outline(Module &M, MBB.erase(std::next(StartIt), std::next(EndIt)); // Keep track of what we removed by marking them all as -1. - std::for_each(Mapper.UnsignedVec.begin() + C.getStartIdx(), - Mapper.UnsignedVec.begin() + C.getEndIdx() + 1, - [](unsigned &I) { I = static_cast<unsigned>(-1); }); + for (unsigned &I : + llvm::make_range(Mapper.UnsignedVec.begin() + C.getStartIdx(), + Mapper.UnsignedVec.begin() + C.getEndIdx() + 1)) + I = static_cast<unsigned>(-1); OutlinedSomething = true; // Statistics. @@ -896,6 +924,9 @@ void MachineOutliner::populateMapper(InstructionMapper &Mapper, Module &M, // MBB is suitable for outlining. Map it to a list of unsigneds. Mapper.convertToUnsignedVec(MBB, *TII); } + + // Statistics. + UnsignedVecSize = Mapper.UnsignedVec.size(); } } |