Skip to content

Commit

Permalink
Replace uses of the deprecated std::auto_ptr with OwningPtr.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andyg1001 committed Apr 15, 2013
1 parent eaa752f commit 604b357
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
19 changes: 8 additions & 11 deletions include/llvm/CodeGen/RegAllocPBQP.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace llvm {
class MachineFunction;
class MachineLoopInfo;
class TargetRegisterInfo;
template<class T> class OwningPtr;

/// This class wraps up a PBQP instance representing a register allocation
/// problem, plus the structures necessary to map back from the PBQP solution
Expand Down Expand Up @@ -123,11 +124,9 @@ namespace llvm {

/// Build a PBQP instance to represent the register allocation problem for
/// the given MachineFunction.
virtual std::auto_ptr<PBQPRAProblem> build(
MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs);
virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs);
private:

void addSpillCosts(PBQP::Vector &costVec, PBQP::PBQPNum spillCost);
Expand All @@ -144,11 +143,9 @@ namespace llvm {

/// Build a PBQP instance to represent the register allocation problem for
/// the given MachineFunction.
virtual std::auto_ptr<PBQPRAProblem> build(
MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs);
virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs);

private:

Expand All @@ -161,7 +158,7 @@ namespace llvm {
PBQP::PBQPNum benefit);
};

FunctionPass* createPBQPRegisterAllocator(std::auto_ptr<PBQPBuilder> builder,
FunctionPass* createPBQPRegisterAllocator(OwningPtr<PBQPBuilder> &builder,
char *customPassID=0);
}

Expand Down
45 changes: 22 additions & 23 deletions lib/CodeGen/RegAllocPBQP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "llvm/CodeGen/RegAllocPBQP.h"
#include "RegisterCoalescer.h"
#include "Spiller.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/CalcSpillWeights.h"
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Expand Down Expand Up @@ -89,8 +90,8 @@ class RegAllocPBQP : public MachineFunctionPass {
static char ID;

/// Construct a PBQP register allocator.
RegAllocPBQP(std::auto_ptr<PBQPBuilder> b, char *cPassID=0)
: MachineFunctionPass(ID), builder(b), customPassID(cPassID) {
RegAllocPBQP(OwningPtr<PBQPBuilder> &b, char *cPassID=0)
: MachineFunctionPass(ID), builder(b.take()), customPassID(cPassID) {
initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
Expand Down Expand Up @@ -121,7 +122,7 @@ class RegAllocPBQP : public MachineFunctionPass {
typedef std::set<unsigned> RegSet;


std::auto_ptr<PBQPBuilder> builder;
OwningPtr<PBQPBuilder> builder;

char *customPassID;

Expand All @@ -132,7 +133,7 @@ class RegAllocPBQP : public MachineFunctionPass {
const MachineLoopInfo *loopInfo;
MachineRegisterInfo *mri;

std::auto_ptr<Spiller> spiller;
OwningPtr<Spiller> spiller;
LiveIntervals *lis;
LiveStacks *lss;
VirtRegMap *vrm;
Expand Down Expand Up @@ -186,16 +187,15 @@ unsigned PBQPRAProblem::getPRegForOption(unsigned vreg, unsigned option) const {
return allowedSet[option - 1];
}

std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs) {
PBQPRAProblem *PBQPBuilder::build(MachineFunction *mf, const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
const RegSet &vregs) {

LiveIntervals *LIS = const_cast<LiveIntervals*>(lis);
MachineRegisterInfo *mri = &mf->getRegInfo();
const TargetRegisterInfo *tri = mf->getTarget().getRegisterInfo();

std::auto_ptr<PBQPRAProblem> p(new PBQPRAProblem());
OwningPtr<PBQPRAProblem> p(new PBQPRAProblem());
PBQP::Graph &g = p->getGraph();
RegSet pregs;

Expand Down Expand Up @@ -282,7 +282,7 @@ std::auto_ptr<PBQPRAProblem> PBQPBuilder::build(MachineFunction *mf,
}
}

return p;
return p.take();
}

void PBQPBuilder::addSpillCosts(PBQP::Vector &costVec,
Expand Down Expand Up @@ -311,13 +311,12 @@ void PBQPBuilder::addInterferenceCosts(
}
}

std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build(
MachineFunction *mf,
PBQPRAProblem *PBQPBuilderWithCoalescing::build(MachineFunction *mf,
const LiveIntervals *lis,
const MachineLoopInfo *loopInfo,
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();

const TargetMachine &tm = mf->getTarget();
Expand Down Expand Up @@ -391,7 +390,7 @@ std::auto_ptr<PBQPRAProblem> PBQPBuilderWithCoalescing::build(
}
}

return p;
return p.take();
}

void PBQPBuilderWithCoalescing::addPhysRegCoalesce(PBQP::Vector &costVec,
Expand Down Expand Up @@ -584,8 +583,8 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
while (!pbqpAllocComplete) {
DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n");

std::auto_ptr<PBQPRAProblem> problem =
builder->build(mf, lis, loopInfo, vregsToAlloc);
OwningPtr<PBQPRAProblem> problem(
builder->build(mf, lis, loopInfo, vregsToAlloc));

#ifndef NDEBUG
if (pbqpDumpGraphs) {
Expand Down Expand Up @@ -621,18 +620,18 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
}

FunctionPass* llvm::createPBQPRegisterAllocator(
std::auto_ptr<PBQPBuilder> builder,
OwningPtr<PBQPBuilder> &builder,
char *customPassID) {
return new RegAllocPBQP(builder, customPassID);
}

FunctionPass* llvm::createDefaultPBQPRegisterAllocator() {
if (pbqpCoalescing) {
return createPBQPRegisterAllocator(
std::auto_ptr<PBQPBuilder>(new PBQPBuilderWithCoalescing()));
} // else
return createPBQPRegisterAllocator(
std::auto_ptr<PBQPBuilder>(new PBQPBuilder()));
OwningPtr<PBQPBuilder> Builder;
if (pbqpCoalescing)
Builder.reset(new PBQPBuilderWithCoalescing());
else
Builder.reset(new PBQPBuilder());
return createPBQPRegisterAllocator(Builder);
}

#undef DEBUG_TYPE
18 changes: 8 additions & 10 deletions tools/llvm-link/llvm-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// searches the link path for the specified file to try to find it...
//
static inline std::auto_ptr<Module> LoadFile(const char *argv0,
const std::string &FN,
LLVMContext& Context) {
static inline Module *LoadFile(const char *argv0, const std::string &FN,
LLVMContext& Context) {
sys::Path Filename;
if (!Filename.set(FN)) {
errs() << "Invalid file name: '" << FN << "'\n";
return std::auto_ptr<Module>();
return NULL;
}

SMDiagnostic Err;
Expand All @@ -68,10 +67,10 @@ static inline std::auto_ptr<Module> LoadFile(const char *argv0,

const std::string &FNStr = Filename.str();
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());
return std::auto_ptr<Module>();
return NULL;
}

int main(int argc, char **argv) {
Expand All @@ -86,17 +85,16 @@ int main(int argc, char **argv) {
unsigned BaseArg = 0;
std::string ErrorMessage;

std::auto_ptr<Module> Composite(LoadFile(argv[0],
InputFilenames[BaseArg], Context));
OwningPtr<Module> Composite(LoadFile(argv[0],
InputFilenames[BaseArg], Context));
if (Composite.get() == 0) {
errs() << argv[0] << ": error loading file '"
<< InputFilenames[BaseArg] << "'\n";
return 1;
}

for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
std::auto_ptr<Module> M(LoadFile(argv[0],
InputFilenames[i], Context));
OwningPtr<Module> M(LoadFile(argv[0], InputFilenames[i], Context));
if (M.get() == 0) {
errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
return 1;
Expand Down

0 comments on commit 604b357

Please sign in to comment.