From 9204ab0456f8ea61fba6fa203d6a799cadbc00cc Mon Sep 17 00:00:00 2001 From: James Molloy Date: Fri, 12 Sep 2014 14:35:17 +0000 Subject: [PATCH] [A57LoadBalancing] unique_ptr-ify. Thanks to David Blakie for the in-depth review! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217682 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../AArch64/AArch64A57FPLoadBalancing.cpp | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp b/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp index c3047c50e35..f298e118210 100644 --- a/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp +++ b/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp @@ -141,8 +141,8 @@ private: bool colorChain(Chain *G, Color C, MachineBasicBlock &MBB); int scavengeRegister(Chain *G, Color C, MachineBasicBlock &MBB); void scanInstruction(MachineInstr *MI, unsigned Idx, - std::map &Chains, - std::set &ChainSet); + std::map &Active, + std::set> &AllChains); void maybeKillChain(MachineOperand &MO, unsigned Idx, std::map &RegChains); Color getColor(unsigned Register); @@ -255,12 +255,12 @@ public: } /// Return true if this chain (StartInst..KillInst) overlaps with Other. - bool rangeOverlapsWith(Chain *Other) { + bool rangeOverlapsWith(const Chain &Other) const { unsigned End = KillInst ? KillInstIdx : LastInstIdx; - unsigned OtherEnd = Other->KillInst ? - Other->KillInstIdx : Other->LastInstIdx; + unsigned OtherEnd = Other.KillInst ? + Other.KillInstIdx : Other.LastInstIdx; - return StartInstIdx <= OtherEnd && Other->StartInstIdx <= End; + return StartInstIdx <= OtherEnd && Other.StartInstIdx <= End; } /// Return true if this chain starts before Other. @@ -325,7 +325,7 @@ bool AArch64A57FPLoadBalancing::runOnBasicBlock(MachineBasicBlock &MBB) { // been killed yet. This is keyed by register - all chains can only have one // "link" register between each inst in the chain. std::map ActiveChains; - std::set AllChains; + std::set> AllChains; unsigned Idx = 0; for (auto &MI : MBB) scanInstruction(&MI, Idx++, ActiveChains, AllChains); @@ -340,15 +340,13 @@ bool AArch64A57FPLoadBalancing::runOnBasicBlock(MachineBasicBlock &MBB) { // range of chains is quite small and they are clustered between loads // and stores. EquivalenceClasses EC; - for (auto *I : AllChains) - EC.insert(I); + for (auto &I : AllChains) + EC.insert(I.get()); - for (auto *I : AllChains) { - for (auto *J : AllChains) { - if (I != J && I->rangeOverlapsWith(J)) - EC.unionSets(I, J); - } - } + for (auto &I : AllChains) + for (auto &J : AllChains) + if (I != J && I->rangeOverlapsWith(*J)) + EC.unionSets(I.get(), J.get()); DEBUG(dbgs() << "Created " << EC.getNumClasses() << " disjoint sets.\n"); // Now we assume that every member of an equivalence class interferes @@ -386,9 +384,6 @@ bool AArch64A57FPLoadBalancing::runOnBasicBlock(MachineBasicBlock &MBB) { for (auto &I : V) Changed |= colorChainSet(I, MBB, Parity); - for (auto *C : AllChains) - delete C; - return Changed; } @@ -587,7 +582,7 @@ bool AArch64A57FPLoadBalancing::colorChain(Chain *G, Color C, void AArch64A57FPLoadBalancing:: scanInstruction(MachineInstr *MI, unsigned Idx, std::map &ActiveChains, - std::set &AllChains) { + std::set> &AllChains) { // Inspect "MI", updating ActiveChains and AllChains. if (isMul(MI)) { @@ -602,9 +597,9 @@ scanInstruction(MachineInstr *MI, unsigned Idx, DEBUG(dbgs() << "New chain started for register " << TRI->getName(DestReg) << " at " << *MI); - Chain *G = new Chain(MI, Idx, getColor(DestReg)); - ActiveChains[DestReg] = G; - AllChains.insert(G); + auto G = llvm::make_unique(MI, Idx, getColor(DestReg)); + ActiveChains[DestReg] = G.get(); + AllChains.insert(std::move(G)); } else if (isMla(MI)) { @@ -646,9 +641,9 @@ scanInstruction(MachineInstr *MI, unsigned Idx, DEBUG(dbgs() << "Creating new chain for dest register " << TRI->getName(DestReg) << "\n"); - Chain *G = new Chain(MI, Idx, getColor(DestReg)); - ActiveChains[DestReg] = G; - AllChains.insert(G); + auto G = llvm::make_unique(MI, Idx, getColor(DestReg)); + ActiveChains[DestReg] = G.get(); + AllChains.insert(std::move(G)); } else {