[MachineOutliner][NFC] Candidates don't need to be shared_ptrs anymore

More refactoring.

After the changes to the pruning logic, and removing CandidateList, there's
no reason for Candiates to be shared_ptrs (or pointers at all).

std::shared_ptr<Candidate> -> Candidate.

llvm-svn: 348427
This commit is contained in:
Jessica Paquette 2018-12-05 23:24:22 +00:00
parent 5ff7b8a04a
commit e18d6ff036
2 changed files with 20 additions and 25 deletions

View File

@ -164,7 +164,7 @@ public:
struct OutlinedFunction {
public:
std::vector<std::shared_ptr<Candidate>> Candidates;
std::vector<Candidate> Candidates;
/// The actual outlined function created.
/// This is initialized after we go through and create the actual function.
@ -187,8 +187,8 @@ public:
/// function.
unsigned getOutliningCost() const {
unsigned CallOverhead = 0;
for (const std::shared_ptr<Candidate> &C : Candidates)
CallOverhead += C->getCallOverhead();
for (const Candidate &C : Candidates)
CallOverhead += C.getCallOverhead();
return CallOverhead + SequenceSize + FrameOverhead;
}
@ -207,19 +207,15 @@ public:
}
/// Return the number of instructions in this sequence.
unsigned getNumInstrs() const { return Candidates[0]->getLength(); }
OutlinedFunction(std::vector<Candidate> &Cands,
unsigned SequenceSize, unsigned FrameOverhead,
unsigned FrameConstructionID)
: SequenceSize(SequenceSize), FrameOverhead(FrameOverhead),
FrameConstructionID(FrameConstructionID) {
for (Candidate &C : Cands)
Candidates.push_back(std::make_shared<outliner::Candidate>(C));
unsigned getNumInstrs() const { return Candidates[0].getLength(); }
OutlinedFunction(std::vector<Candidate> &Candidates, unsigned SequenceSize,
unsigned FrameOverhead, unsigned FrameConstructionID)
: Candidates(Candidates), SequenceSize(SequenceSize),
FrameOverhead(FrameOverhead), FrameConstructionID(FrameConstructionID) {
const unsigned B = getBenefit();
for (std::shared_ptr<Candidate> &C : Candidates)
C->Benefit = B;
for (Candidate &C : Candidates)
C.Benefit = B;
}
OutlinedFunction() {}

View File

@ -904,7 +904,7 @@ struct MachineOutliner : public ModulePass {
InstructionMapper &Mapper);
/// Creates a function for \p OF and inserts it into the module.
MachineFunction *createOutlinedFunction(Module &M, const OutlinedFunction &OF,
MachineFunction *createOutlinedFunction(Module &M, OutlinedFunction &OF,
InstructionMapper &Mapper,
unsigned Name);
@ -931,8 +931,8 @@ struct MachineOutliner : public ModulePass {
/// function for remark emission.
DISubprogram *getSubprogramOrNull(const OutlinedFunction &OF) {
DISubprogram *SP;
for (const std::shared_ptr<Candidate> &C : OF.Candidates)
if (C && C->getMF() && (SP = C->getMF()->getFunction().getSubprogram()))
for (const Candidate &C : OF.Candidates)
if (C.getMF() && (SP = C.getMF()->getFunction().getSubprogram()))
return SP;
return nullptr;
}
@ -1021,7 +1021,7 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
for (size_t i = 0, e = OF.Candidates.size(); i < e; i++) {
R << NV((Twine("StartLoc") + Twine(i)).str(),
OF.Candidates[i]->front()->getDebugLoc());
OF.Candidates[i].front()->getDebugLoc());
if (i != e - 1)
R << ", ";
}
@ -1134,7 +1134,7 @@ unsigned MachineOutliner::buildCandidateList(
}
MachineFunction *
MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
MachineOutliner::createOutlinedFunction(Module &M, OutlinedFunction &OF,
InstructionMapper &Mapper,
unsigned Name) {
@ -1169,7 +1169,7 @@ MachineOutliner::createOutlinedFunction(Module &M, const OutlinedFunction &OF,
// function. This makes sure the outlined function knows what kinds of
// instructions are going into it. This is fine, since all parent functions
// must necessarily support the instructions that are in the outlined region.
Candidate &FirstCand = *OF.Candidates.front();
Candidate &FirstCand = OF.Candidates.front();
const Function &ParentFn = FirstCand.getMF()->getFunction();
if (ParentFn.hasFnAttribute("target-features"))
F->addFnAttr(ParentFn.getFnAttribute("target-features"));
@ -1259,10 +1259,10 @@ bool MachineOutliner::outline(Module &M,
for (OutlinedFunction &OF : FunctionList) {
// If we outlined something that overlapped with a candidate in a previous
// step, then we can't outline from it.
erase_if(OF.Candidates, [&Mapper](std::shared_ptr<Candidate> &C) {
erase_if(OF.Candidates, [&Mapper](Candidate &C) {
return std::any_of(
Mapper.UnsignedVec.begin() + C->getStartIdx(),
Mapper.UnsignedVec.begin() + C->getEndIdx() + 1,
Mapper.UnsignedVec.begin() + C.getStartIdx(),
Mapper.UnsignedVec.begin() + C.getEndIdx() + 1,
[](unsigned I) { return (I == static_cast<unsigned>(-1)); });
});
@ -1281,8 +1281,7 @@ bool MachineOutliner::outline(Module &M,
const TargetInstrInfo &TII = *STI.getInstrInfo();
// Replace occurrences of the sequence with calls to the new function.
for (std::shared_ptr<Candidate> &Cptr : OF.Candidates) {
Candidate &C = *Cptr;
for (Candidate &C : OF.Candidates) {
MachineBasicBlock &MBB = *C.getMBB();
MachineBasicBlock::iterator StartIt = C.front();
MachineBasicBlock::iterator EndIt = C.back();