Replace uses of the deprecated std::auto_ptr with OwningPtr.

This is a rework of the broken parts in r179373 which were subsequently reverted in r179374 due to incompatibility with C++98 compilers.  This version should be ok under C++98.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179520 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andy Gibbs 2013-04-15 12:06:32 +00:00
parent eaa752f5e1
commit 604b3573f9
3 changed files with 38 additions and 44 deletions

View File

@ -29,6 +29,7 @@ namespace llvm {
class MachineFunction; class MachineFunction;
class MachineLoopInfo; class MachineLoopInfo;
class TargetRegisterInfo; class TargetRegisterInfo;
template<class T> class OwningPtr;
/// This class wraps up a PBQP instance representing a register allocation /// This class wraps up a PBQP instance representing a register allocation
/// problem, plus the structures necessary to map back from the PBQP solution /// problem, plus the structures necessary to map back from the PBQP solution
@ -123,9 +124,7 @@ namespace llvm {
/// Build a PBQP instance to represent the register allocation problem for /// Build a PBQP instance to represent the register allocation problem for
/// the given MachineFunction. /// the given MachineFunction.
virtual std::auto_ptr<PBQPRAProblem> build( virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo, const MachineLoopInfo *loopInfo,
const RegSet &vregs); const RegSet &vregs);
private: private:
@ -144,9 +143,7 @@ namespace llvm {
/// Build a PBQP instance to represent the register allocation problem for /// Build a PBQP instance to represent the register allocation problem for
/// the given MachineFunction. /// the given MachineFunction.
virtual std::auto_ptr<PBQPRAProblem> build( virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo, const MachineLoopInfo *loopInfo,
const RegSet &vregs); const RegSet &vregs);
@ -161,7 +158,7 @@ namespace llvm {
PBQP::PBQPNum benefit); PBQP::PBQPNum benefit);
}; };
FunctionPass* createPBQPRegisterAllocator(std::auto_ptr<PBQPBuilder> builder, FunctionPass* createPBQPRegisterAllocator(OwningPtr<PBQPBuilder> &builder,
char *customPassID=0); char *customPassID=0);
} }

View File

@ -34,6 +34,7 @@
#include "llvm/CodeGen/RegAllocPBQP.h" #include "llvm/CodeGen/RegAllocPBQP.h"
#include "RegisterCoalescer.h" #include "RegisterCoalescer.h"
#include "Spiller.h" #include "Spiller.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/CalcSpillWeights.h" #include "llvm/CodeGen/CalcSpillWeights.h"
#include "llvm/CodeGen/LiveIntervalAnalysis.h" #include "llvm/CodeGen/LiveIntervalAnalysis.h"
@ -89,8 +90,8 @@ public:
static char ID; static char ID;
/// Construct a PBQP register allocator. /// Construct a PBQP register allocator.
RegAllocPBQP(std::auto_ptr<PBQPBuilder> b, char *cPassID=0) RegAllocPBQP(OwningPtr<PBQPBuilder> &b, char *cPassID=0)
: MachineFunctionPass(ID), builder(b), customPassID(cPassID) { : MachineFunctionPass(ID), builder(b.take()), customPassID(cPassID) {
initializeSlotIndexesPass(*PassRegistry::getPassRegistry()); initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
initializeLiveIntervalsPass(*PassRegistry::getPassRegistry()); initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry()); initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
@ -121,7 +122,7 @@ private:
typedef std::set<unsigned> RegSet; typedef std::set<unsigned> RegSet;
std::auto_ptr<PBQPBuilder> builder; OwningPtr<PBQPBuilder> builder;
char *customPassID; char *customPassID;
@ -132,7 +133,7 @@ private:
const MachineLoopInfo *loopInfo; const MachineLoopInfo *loopInfo;
MachineRegisterInfo *mri; MachineRegisterInfo *mri;
std::auto_ptr<Spiller> spiller; OwningPtr<Spiller> spiller;
LiveIntervals *lis; LiveIntervals *lis;
LiveStacks *lss; LiveStacks *lss;
VirtRegMap *vrm; VirtRegMap *vrm;
@ -186,8 +187,7 @@ unsigned PBQPRAProblem::getPRegForOption(unsigned vreg, unsigned option) const {
return allowedSet[option - 1]; return allowedSet[option - 1];
} }
std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf, PBQPRAProblem *PBQPBuilder::build(MachineFunction *mf, const LiveIntervals *lis,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo, const MachineLoopInfo *loopInfo,
const RegSet &vregs) { const RegSet &vregs) {
@ -195,7 +195,7 @@ std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf,
MachineRegisterInfo *mri = &mf->getRegInfo(); MachineRegisterInfo *mri = &mf->getRegInfo();
const TargetRegisterInfo *tri = mf->getTarget().getRegisterInfo(); const TargetRegisterInfo *tri = mf->getTarget().getRegisterInfo();
std::auto_ptr<PBQPRAProblem> p(new PBQPRAProblem()); OwningPtr<PBQPRAProblem> p(new PBQPRAProblem());
PBQP::Graph &g = p->getGraph(); PBQP::Graph &g = p->getGraph();
RegSet pregs; RegSet pregs;
@ -282,7 +282,7 @@ std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf,
} }
} }
return p; return p.take();
} }
void PBQPBuilder::addSpillCosts(PBQP::Vector &costVec, void PBQPBuilder::addSpillCosts(PBQP::Vector &costVec,
@ -311,13 +311,12 @@ void PBQPBuilder::addInterferenceCosts(
} }
} }
std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build( PBQPRAProblem *PBQPBuilderWithCoalescing::build(MachineFunction *mf,
MachineFunction *mf,
const LiveIntervals *lis, const LiveIntervals *lis,
const MachineLoopInfo *loopInfo, const MachineLoopInfo *loopInfo,
const RegSet &vregs) { const RegSet &vregs) {
std::auto_ptr<PBQPRAProblem> p = PBQPBuilder::build(mf, lis, loopInfo, vregs); OwningPtr<PBQPRAProblem> p(PBQPBuilder::build(mf, lis, loopInfo, vregs));
PBQP::Graph &g = p->getGraph(); PBQP::Graph &g = p->getGraph();
const TargetMachine &tm = mf->getTarget(); const TargetMachine &tm = mf->getTarget();
@ -391,7 +390,7 @@ std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build(
} }
} }
return p; return p.take();
} }
void PBQPBuilderWithCoalescing::addPhysRegCoalesce(PBQP::Vector &costVec, void PBQPBuilderWithCoalescing::addPhysRegCoalesce(PBQP::Vector &costVec,
@ -584,8 +583,8 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
while (!pbqpAllocComplete) { while (!pbqpAllocComplete) {
DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n"); DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n");
std::auto_ptr<PBQPRAProblem> problem = OwningPtr<PBQPRAProblem> problem(
builder->build(mf, lis, loopInfo, vregsToAlloc); builder->build(mf, lis, loopInfo, vregsToAlloc));
#ifndef NDEBUG #ifndef NDEBUG
if (pbqpDumpGraphs) { if (pbqpDumpGraphs) {
@ -621,18 +620,18 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
} }
FunctionPass* llvm::createPBQPRegisterAllocator( FunctionPass* llvm::createPBQPRegisterAllocator(
std::auto_ptr<PBQPBuilder> builder, OwningPtr<PBQPBuilder> &builder,
char *customPassID) { char *customPassID) {
return new RegAllocPBQP(builder, customPassID); return new RegAllocPBQP(builder, customPassID);
} }
FunctionPass* llvm::createDefaultPBQPRegisterAllocator() { FunctionPass* llvm::createDefaultPBQPRegisterAllocator() {
if (pbqpCoalescing) { OwningPtr<PBQPBuilder> Builder;
return createPBQPRegisterAllocator( if (pbqpCoalescing)
std::auto_ptr<PBQPBuilder>(new PBQPBuilderWithCoalescing())); Builder.reset(new PBQPBuilderWithCoalescing());
} // else else
return createPBQPRegisterAllocator( Builder.reset(new PBQPBuilder());
std::auto_ptr<PBQPBuilder>(new PBQPBuilder())); return createPBQPRegisterAllocator(Builder);
} }
#undef DEBUG_TYPE #undef DEBUG_TYPE

View File

@ -53,13 +53,12 @@ DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
// LoadFile - Read the specified bitcode file in and return it. This routine // LoadFile - Read the specified bitcode file in and return it. This routine
// searches the link path for the specified file to try to find it... // searches the link path for the specified file to try to find it...
// //
static inline std::auto_ptr<Module> LoadFile(const char *argv0, static inline Module *LoadFile(const char *argv0, const std::string &FN,
const std::string &FN,
LLVMContext& Context) { LLVMContext& Context) {
sys::Path Filename; sys::Path Filename;
if (!Filename.set(FN)) { if (!Filename.set(FN)) {
errs() << "Invalid file name: '" << FN << "'\n"; errs() << "Invalid file name: '" << FN << "'\n";
return std::auto_ptr<Module>(); return NULL;
} }
SMDiagnostic Err; SMDiagnostic Err;
@ -68,10 +67,10 @@ static inline std::auto_ptr<Module> LoadFile(const char *argv0,
const std::string &FNStr = Filename.str(); const std::string &FNStr = Filename.str();
Result = ParseIRFile(FNStr, Err, Context); Result = ParseIRFile(FNStr, Err, Context);
if (Result) return std::auto_ptr<Module>(Result); // Load successful! if (Result) return Result; // Load successful!
Err.print(argv0, errs()); Err.print(argv0, errs());
return std::auto_ptr<Module>(); return NULL;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -86,7 +85,7 @@ int main(int argc, char **argv) {
unsigned BaseArg = 0; unsigned BaseArg = 0;
std::string ErrorMessage; std::string ErrorMessage;
std::auto_ptr<Module> Composite(LoadFile(argv[0], OwningPtr<Module> Composite(LoadFile(argv[0],
InputFilenames[BaseArg], Context)); InputFilenames[BaseArg], Context));
if (Composite.get() == 0) { if (Composite.get() == 0) {
errs() << argv[0] << ": error loading file '" errs() << argv[0] << ": error loading file '"
@ -95,8 +94,7 @@ int main(int argc, char **argv) {
} }
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) { for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
std::auto_ptr<Module> M(LoadFile(argv[0], OwningPtr<Module> M(LoadFile(argv[0], InputFilenames[i], Context));
InputFilenames[i], Context));
if (M.get() == 0) { if (M.get() == 0) {
errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n"; errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
return 1; return 1;