Index: lib/CodeGen/IfConversion.cpp =================================================================== --- lib/CodeGen/IfConversion.cpp +++ lib/CodeGen/IfConversion.cpp @@ -198,10 +198,12 @@ bool ValidDiamond(BBInfo &TrueBBI, BBInfo &FalseBBI, unsigned &Dups1, unsigned &Dups2) const; void ScanInstructions(BBInfo &BBI); - void AnalyzeBlock(MachineBasicBlock *MBB, std::vector &Tokens); + void AnalyzeBlock(MachineBasicBlock *MBB, + std::vector> &Tokens); bool FeasibilityAnalysis(BBInfo &BBI, SmallVectorImpl &Cond, bool isTriangle = false, bool RevBranch = false); - void AnalyzeBlocks(MachineFunction &MF, std::vector &Tokens); + void AnalyzeBlocks(MachineFunction &MF, + std::vector> &Tokens); void InvalidatePreds(MachineBasicBlock *BB); void RemoveExtraEdges(BBInfo &BBI); bool IfConvertSimple(BBInfo &BBI, IfcvtKind Kind); @@ -240,7 +242,8 @@ } // IfcvtTokenCmp - Used to sort if-conversion candidates. - static bool IfcvtTokenCmp(IfcvtToken *C1, IfcvtToken *C2) { + static bool IfcvtTokenCmp(const std::unique_ptr &C1, + const std::unique_ptr &C2) { int Incr1 = (C1->Kind == ICDiamond) ? -(int)(C1->NumDups + C1->NumDups2) : (int)C1->NumDups; int Incr2 = (C2->Kind == ICDiamond) @@ -309,7 +312,7 @@ MF.RenumberBlocks(); BBAnalysis.resize(MF.getNumBlockIDs()); - std::vector Tokens; + std::vector> Tokens; MadeChange = false; unsigned NumIfCvts = NumSimple + NumSimpleFalse + NumTriangle + NumTriangleRev + NumTriangleFalse + NumTriangleFRev + NumDiamonds; @@ -319,15 +322,13 @@ bool Change = false; AnalyzeBlocks(MF, Tokens); while (!Tokens.empty()) { - IfcvtToken *Token = Tokens.back(); + std::unique_ptr Token = std::move(Tokens.back()); Tokens.pop_back(); BBInfo &BBI = Token->BBI; IfcvtKind Kind = Token->Kind; unsigned NumDups = Token->NumDups; unsigned NumDups2 = Token->NumDups2; - delete Token; - // If the block has been evicted out of the queue or it has already been // marked dead (due to it being predicated), then skip it. if (BBI.IsDone) @@ -414,13 +415,6 @@ MadeChange |= Change; } - // Delete tokens in case of early exit. - while (!Tokens.empty()) { - IfcvtToken *Token = Tokens.back(); - Tokens.pop_back(); - delete Token; - } - Tokens.clear(); BBAnalysis.clear(); @@ -768,8 +762,8 @@ /// AnalyzeBlock - Analyze the structure of the sub-CFG starting from /// the specified block. Record its successors and whether it looks like an /// if-conversion candidate. -void IfConverter::AnalyzeBlock(MachineBasicBlock *MBB, - std::vector &Tokens) { +void IfConverter::AnalyzeBlock( + MachineBasicBlock *MBB, std::vector> &Tokens) { struct BBState { BBState(MachineBasicBlock *BB) : MBB(BB), SuccsAnalyzed(false) {} MachineBasicBlock *MBB; @@ -867,8 +861,8 @@ // \ / // TailBB // Note TailBB can be empty. - Tokens.push_back(new IfcvtToken(BBI, ICDiamond, TNeedSub|FNeedSub, Dups, - Dups2)); + Tokens.push_back(llvm::make_unique( + BBI, ICDiamond, TNeedSub | FNeedSub, Dups, Dups2)); Enqueued = true; } @@ -883,7 +877,8 @@ // | TBB // | / // FBB - Tokens.push_back(new IfcvtToken(BBI, ICTriangle, TNeedSub, Dups)); + Tokens.push_back( + llvm::make_unique(BBI, ICTriangle, TNeedSub, Dups)); Enqueued = true; } @@ -891,7 +886,8 @@ MeetIfcvtSizeLimit(*TrueBBI.BB, TrueBBI.NonPredSize + TrueBBI.ExtraCost, TrueBBI.ExtraCost2, Prediction) && FeasibilityAnalysis(TrueBBI, BBI.BrCond, true, true)) { - Tokens.push_back(new IfcvtToken(BBI, ICTriangleRev, TNeedSub, Dups)); + Tokens.push_back( + llvm::make_unique(BBI, ICTriangleRev, TNeedSub, Dups)); Enqueued = true; } @@ -906,7 +902,8 @@ // | TBB---> exit // | // FBB - Tokens.push_back(new IfcvtToken(BBI, ICSimple, TNeedSub, Dups)); + Tokens.push_back( + llvm::make_unique(BBI, ICSimple, TNeedSub, Dups)); Enqueued = true; } @@ -918,7 +915,8 @@ FalseBBI.NonPredSize + FalseBBI.ExtraCost, FalseBBI.ExtraCost2, Prediction.getCompl()) && FeasibilityAnalysis(FalseBBI, RevCond, true)) { - Tokens.push_back(new IfcvtToken(BBI, ICTriangleFalse, FNeedSub, Dups)); + Tokens.push_back(llvm::make_unique(BBI, ICTriangleFalse, + FNeedSub, Dups)); Enqueued = true; } @@ -928,7 +926,8 @@ FalseBBI.NonPredSize + FalseBBI.ExtraCost, FalseBBI.ExtraCost2, Prediction.getCompl()) && FeasibilityAnalysis(FalseBBI, RevCond, true, true)) { - Tokens.push_back(new IfcvtToken(BBI, ICTriangleFRev, FNeedSub, Dups)); + Tokens.push_back( + llvm::make_unique(BBI, ICTriangleFRev, FNeedSub, Dups)); Enqueued = true; } @@ -937,7 +936,8 @@ FalseBBI.NonPredSize + FalseBBI.ExtraCost, FalseBBI.ExtraCost2, Prediction.getCompl()) && FeasibilityAnalysis(FalseBBI, RevCond)) { - Tokens.push_back(new IfcvtToken(BBI, ICSimpleFalse, FNeedSub, Dups)); + Tokens.push_back( + llvm::make_unique(BBI, ICSimpleFalse, FNeedSub, Dups)); Enqueued = true; } } @@ -951,8 +951,8 @@ /// AnalyzeBlocks - Analyze all blocks and find entries for all if-conversion /// candidates. -void IfConverter::AnalyzeBlocks(MachineFunction &MF, - std::vector &Tokens) { +void IfConverter::AnalyzeBlocks( + MachineFunction &MF, std::vector> &Tokens) { for (auto &BB : MF) AnalyzeBlock(&BB, Tokens);