From 1559021751fbb9dae9072f67bce70d4bcf00ad5b Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 12 Nov 2018 02:26:26 +0000 Subject: [PATCH] [GC] Minor style modernization llvm-svn: 346631 --- llvm/lib/CodeGen/GCRootLowering.cpp | 87 ++++++++++++++--------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp index 8e8917664af4..8f9df36d84b8 100644 --- a/llvm/lib/CodeGen/GCRootLowering.cpp +++ b/llvm/lib/CodeGen/GCRootLowering.cpp @@ -141,8 +141,7 @@ static bool CouldBecomeSafePoint(Instruction *I) { return true; } -static bool InsertRootInitializers(Function &F, AllocaInst **Roots, - unsigned Count) { +static bool InsertRootInitializers(Function &F, ArrayRef Roots) { // Scroll past alloca instructions. BasicBlock::iterator IP = F.getEntryBlock().begin(); while (isa(IP)) @@ -159,12 +158,12 @@ static bool InsertRootInitializers(Function &F, AllocaInst **Roots, // Add root initializers. bool MadeChange = false; - for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I) - if (!InitedRoots.count(*I)) { + for (AllocaInst *Root : Roots) + if (!InitedRoots.count(Root)) { StoreInst *SI = new StoreInst( - ConstantPointerNull::get(cast((*I)->getAllocatedType())), - *I); - SI->insertAfter(*I); + ConstantPointerNull::get(cast(Root->getAllocatedType())), + Root); + SI->insertAfter(Root); MadeChange = true; } @@ -195,44 +194,45 @@ bool LowerIntrinsics::DoLowering(Function &F, GCStrategy &S) { SmallVector Roots; bool MadeChange = false; - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) { - if (IntrinsicInst *CI = dyn_cast(II++)) { - Function *F = CI->getCalledFunction(); - switch (F->getIntrinsicID()) { - default: break; - case Intrinsic::gcwrite: { - // Replace a write barrier with a simple store. - Value *St = new StoreInst(CI->getArgOperand(0), - CI->getArgOperand(2), CI); - CI->replaceAllUsesWith(St); - CI->eraseFromParent(); - MadeChange = true; - break; - } - case Intrinsic::gcread: { - // Replace a read barrier with a simple load. - Value *Ld = new LoadInst(CI->getArgOperand(1), "", CI); - Ld->takeName(CI); - CI->replaceAllUsesWith(Ld); - CI->eraseFromParent(); - MadeChange = true; - break; - } - case Intrinsic::gcroot: { - // Initialize the GC root, but do not delete the intrinsic. The - // backend needs the intrinsic to flag the stack slot. - Roots.push_back( - cast(CI->getArgOperand(0)->stripPointerCasts())); - break; - } - } + for (BasicBlock &BB : F) + for (BasicBlock::iterator II = BB.begin(), E = BB.end(); II != E;) { + IntrinsicInst *CI = dyn_cast(II++); + if (!CI) + continue; + + Function *F = CI->getCalledFunction(); + switch (F->getIntrinsicID()) { + default: break; + case Intrinsic::gcwrite: { + // Replace a write barrier with a simple store. + Value *St = new StoreInst(CI->getArgOperand(0), + CI->getArgOperand(2), CI); + CI->replaceAllUsesWith(St); + CI->eraseFromParent(); + MadeChange = true; + break; + } + case Intrinsic::gcread: { + // Replace a read barrier with a simple load. + Value *Ld = new LoadInst(CI->getArgOperand(1), "", CI); + Ld->takeName(CI); + CI->replaceAllUsesWith(Ld); + CI->eraseFromParent(); + MadeChange = true; + break; + } + case Intrinsic::gcroot: { + // Initialize the GC root, but do not delete the intrinsic. The + // backend needs the intrinsic to flag the stack slot. + Roots.push_back( + cast(CI->getArgOperand(0)->stripPointerCasts())); + break; + } } } - } if (Roots.size()) - MadeChange |= InsertRootInitializers(F, Roots.begin(), Roots.size()); + MadeChange |= InsertRootInitializers(F, Roots); return MadeChange; } @@ -280,9 +280,8 @@ void GCMachineCodeAnalysis::VisitCallPoint(MachineBasicBlock::iterator CI) { } void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) { - for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE; - ++BBI) - for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end(); + for (MachineBasicBlock &MBB : MF) + for (MachineBasicBlock::iterator MI = MBB.begin(), ME = MBB.end(); MI != ME; ++MI) if (MI->isCall()) { // Do not treat tail or sibling call sites as safe points. This is