llvm.org GIT mirror llvm / 604b357
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 Andy Gibbs 6 years ago
3 changed file(s) with 38 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
2828 class MachineFunction;
2929 class MachineLoopInfo;
3030 class TargetRegisterInfo;
31 template class OwningPtr;
3132
3233 /// This class wraps up a PBQP instance representing a register allocation
3334 /// problem, plus the structures necessary to map back from the PBQP solution
122123
123124 /// Build a PBQP instance to represent the register allocation problem for
124125 /// the given MachineFunction.
125 virtual std::auto_ptr build(
126 MachineFunction *mf,
127 const LiveIntervals *lis,
128 const MachineLoopInfo *loopInfo,
129 const RegSet &vregs);
126 virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
127 const MachineLoopInfo *loopInfo,
128 const RegSet &vregs);
130129 private:
131130
132131 void addSpillCosts(PBQP::Vector &costVec, PBQP::PBQPNum spillCost);
143142
144143 /// Build a PBQP instance to represent the register allocation problem for
145144 /// the given MachineFunction.
146 virtual std::auto_ptr build(
147 MachineFunction *mf,
148 const LiveIntervals *lis,
149 const MachineLoopInfo *loopInfo,
150 const RegSet &vregs);
145 virtual PBQPRAProblem *build(MachineFunction *mf, const LiveIntervals *lis,
146 const MachineLoopInfo *loopInfo,
147 const RegSet &vregs);
151148
152149 private:
153150
160157 PBQP::PBQPNum benefit);
161158 };
162159
163 FunctionPass* createPBQPRegisterAllocator(std::auto_ptr builder,
160 FunctionPass* createPBQPRegisterAllocator(OwningPtr &builder,
164161 char *customPassID=0);
165162 }
166163
3333 #include "llvm/CodeGen/RegAllocPBQP.h"
3434 #include "RegisterCoalescer.h"
3535 #include "Spiller.h"
36 #include "llvm/ADT/OwningPtr.h"
3637 #include "llvm/Analysis/AliasAnalysis.h"
3738 #include "llvm/CodeGen/CalcSpillWeights.h"
3839 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
8889 static char ID;
8990
9091 /// Construct a PBQP register allocator.
91 RegAllocPBQP(std::auto_ptr b, char *cPassID=0)
92 : MachineFunctionPass(ID), builder(b), customPassID(cPassID) {
92 RegAllocPBQP(OwningPtr &b, char *cPassID=0)
93 : MachineFunctionPass(ID), builder(b.take()), customPassID(cPassID) {
9394 initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
9495 initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
9596 initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
120121 typedef std::set RegSet;
121122
122123
123 std::auto_ptr builder;
124 OwningPtr builder;
124125
125126 char *customPassID;
126127
131132 const MachineLoopInfo *loopInfo;
132133 MachineRegisterInfo *mri;
133134
134 std::auto_ptr spiller;
135 OwningPtr spiller;
135136 LiveIntervals *lis;
136137 LiveStacks *lss;
137138 VirtRegMap *vrm;
185186 return allowedSet[option - 1];
186187 }
187188
188 std::auto_ptr PBQPBuilder::build(MachineFunction *mf,
189 const LiveIntervals *lis,
190 const MachineLoopInfo *loopInfo,
191 const RegSet &vregs) {
189 PBQPRAProblem *PBQPBuilder::build(MachineFunction *mf, const LiveIntervals *lis,
190 const MachineLoopInfo *loopInfo,
191 const RegSet &vregs) {
192192
193193 LiveIntervals *LIS = const_cast(lis);
194194 MachineRegisterInfo *mri = &mf->getRegInfo();
195195 const TargetRegisterInfo *tri = mf->getTarget().getRegisterInfo();
196196
197 std::auto_ptr p(new PBQPRAProblem());
197 OwningPtr p(new PBQPRAProblem());
198198 PBQP::Graph &g = p->getGraph();
199199 RegSet pregs;
200200
281281 }
282282 }
283283
284 return p;
284 return p.take();
285285 }
286286
287287 void PBQPBuilder::addSpillCosts(PBQP::Vector &costVec,
310310 }
311311 }
312312
313 std::auto_ptr PBQPBuilderWithCoalescing::build(
314 MachineFunction *mf,
313 PBQPRAProblem *PBQPBuilderWithCoalescing::build(MachineFunction *mf,
315314 const LiveIntervals *lis,
316315 const MachineLoopInfo *loopInfo,
317316 const RegSet &vregs) {
318317
319 std::auto_ptr p = PBQPBuilder::build(mf, lis, loopInfo, vregs);
318 OwningPtr p(PBQPBuilder::build(mf, lis, loopInfo, vregs));
320319 PBQP::Graph &g = p->getGraph();
321320
322321 const TargetMachine &tm = mf->getTarget();
390389 }
391390 }
392391
393 return p;
392 return p.take();
394393 }
395394
396395 void PBQPBuilderWithCoalescing::addPhysRegCoalesce(PBQP::Vector &costVec,
583582 while (!pbqpAllocComplete) {
584583 DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n");
585584
586 std::auto_ptr problem =
587 builder->build(mf, lis, loopInfo, vregsToAlloc);
585 OwningPtr problem(
586 builder->build(mf, lis, loopInfo, vregsToAlloc));
588587
589588 #ifndef NDEBUG
590589 if (pbqpDumpGraphs) {
620619 }
621620
622621 FunctionPass* llvm::createPBQPRegisterAllocator(
623 std::auto_ptr builder,
622 OwningPtr &builder,
624623 char *customPassID) {
625624 return new RegAllocPBQP(builder, customPassID);
626625 }
627626
628627 FunctionPass* llvm::createDefaultPBQPRegisterAllocator() {
629 if (pbqpCoalescing) {
630 return createPBQPRegisterAllocator(
631 std::auto_ptr(new PBQPBuilderWithCoalescing()));
632 } // else
633 return createPBQPRegisterAllocator(
634 std::auto_ptr(new PBQPBuilder()));
628 OwningPtr Builder;
629 if (pbqpCoalescing)
630 Builder.reset(new PBQPBuilderWithCoalescing());
631 else
632 Builder.reset(new PBQPBuilder());
633 return createPBQPRegisterAllocator(Builder);
635634 }
636635
637636 #undef DEBUG_TYPE
5252 // LoadFile - Read the specified bitcode file in and return it. This routine
5353 // searches the link path for the specified file to try to find it...
5454 //
55 static inline std::auto_ptr LoadFile(const char *argv0,
56 const std::string &FN,
57 LLVMContext& Context) {
55 static inline Module *LoadFile(const char *argv0, const std::string &FN,
56 LLVMContext& Context) {
5857 sys::Path Filename;
5958 if (!Filename.set(FN)) {
6059 errs() << "Invalid file name: '" << FN << "'\n";
61 return std::auto_ptr();
60 return NULL;
6261 }
6362
6463 SMDiagnostic Err;
6766
6867 const std::string &FNStr = Filename.str();
6968 Result = ParseIRFile(FNStr, Err, Context);
70 if (Result) return std::auto_ptr(Result); // Load successful!
69 if (Result) return Result; // Load successful!
7170
7271 Err.print(argv0, errs());
73 return std::auto_ptr();
72 return NULL;
7473 }
7574
7675 int main(int argc, char **argv) {
8584 unsigned BaseArg = 0;
8685 std::string ErrorMessage;
8786
88 std::auto_ptr Composite(LoadFile(argv[0],
89 InputFilenames[BaseArg], Context));
87 OwningPtr Composite(LoadFile(argv[0],
88 InputFilenames[BaseArg], Context));
9089 if (Composite.get() == 0) {
9190 errs() << argv[0] << ": error loading file '"
9291 << InputFilenames[BaseArg] << "'\n";
9493 }
9594
9695 for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
97 std::auto_ptr M(LoadFile(argv[0],
98 InputFilenames[i], Context));
96 OwningPtr M(LoadFile(argv[0], InputFilenames[i], Context));
9997 if (M.get() == 0) {
10098 errs() << argv[0] << ": error loading file '" <
10199 return 1;