From: Sean Silva Date: Mon, 25 Jul 2016 05:57:59 +0000 (+0000) Subject: Cleanup : Reformat PartialInliner.cpp to have current LLVM style conventions X-Git-Tag: llvmorg-4.0.0-rc1~14316 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=519323db58bef15d577ba5cebe88027f0cfa3161;p=platform%2Fupstream%2Fllvm.git Cleanup : Reformat PartialInliner.cpp to have current LLVM style conventions Modify the variable names and code style to be that of modern LLVM. Patch by River Riddle! Differential Revision: https://reviews.llvm.org/D22743 llvm-svn: 276610 --- diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp index 2aca64a..6c762e4 100644 --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -51,94 +51,95 @@ struct PartialInlinerLegacyPass : public ModulePass { return false; AssumptionCacheTracker *ACT = &getAnalysis(); - std::function GetAssumptionCache = [&ACT]( - Function &F) -> AssumptionCache & { + std::function GetAssumptionCache = + [&ACT](Function &F) -> AssumptionCache & { return ACT->getAssumptionCache(F); }; InlineFunctionInfo IFI(nullptr, &GetAssumptionCache); return PartialInlinerImpl(IFI).run(M); } - }; +}; } Function *PartialInlinerImpl::unswitchFunction(Function *F) { // First, verify that this function is an unswitching candidate... - BasicBlock *entryBlock = &F->front(); - BranchInst *BR = dyn_cast(entryBlock->getTerminator()); + BasicBlock *EntryBlock = &F->front(); + BranchInst *BR = dyn_cast(EntryBlock->getTerminator()); if (!BR || BR->isUnconditional()) return nullptr; - BasicBlock* returnBlock = nullptr; - BasicBlock* nonReturnBlock = nullptr; - unsigned returnCount = 0; - for (BasicBlock *BB : successors(entryBlock)) { + BasicBlock *ReturnBlock = nullptr; + BasicBlock *NonReturnBlock = nullptr; + unsigned ReturnCount = 0; + for (BasicBlock *BB : successors(EntryBlock)) { if (isa(BB->getTerminator())) { - returnBlock = BB; - returnCount++; + ReturnBlock = BB; + ReturnCount++; } else - nonReturnBlock = BB; + NonReturnBlock = BB; } - if (returnCount != 1) + if (ReturnCount != 1) return nullptr; // Clone the function, so that we can hack away on it. ValueToValueMapTy VMap; - Function* duplicateFunction = CloneFunction(F, VMap); - duplicateFunction->setLinkage(GlobalValue::InternalLinkage); - BasicBlock* newEntryBlock = cast(VMap[entryBlock]); - BasicBlock* newReturnBlock = cast(VMap[returnBlock]); - BasicBlock* newNonReturnBlock = cast(VMap[nonReturnBlock]); + Function *DuplicateFunction = CloneFunction(F, VMap); + DuplicateFunction->setLinkage(GlobalValue::InternalLinkage); + BasicBlock *NewEntryBlock = cast(VMap[EntryBlock]); + BasicBlock *NewReturnBlock = cast(VMap[ReturnBlock]); + BasicBlock *NewNonReturnBlock = cast(VMap[NonReturnBlock]); // Go ahead and update all uses to the duplicate, so that we can just // use the inliner functionality when we're done hacking. - F->replaceAllUsesWith(duplicateFunction); + F->replaceAllUsesWith(DuplicateFunction); // Special hackery is needed with PHI nodes that have inputs from more than // one extracted block. For simplicity, just split the PHIs into a two-level // sequence of PHIs, some of which will go in the extracted region, and some // of which will go outside. - BasicBlock* preReturn = newReturnBlock; - newReturnBlock = newReturnBlock->splitBasicBlock( - newReturnBlock->getFirstNonPHI()->getIterator()); - BasicBlock::iterator I = preReturn->begin(); - Instruction *Ins = &newReturnBlock->front(); - while (I != preReturn->end()) { - PHINode* OldPhi = dyn_cast(I); - if (!OldPhi) break; - - PHINode *retPhi = PHINode::Create(OldPhi->getType(), 2, "", Ins); - OldPhi->replaceAllUsesWith(retPhi); - Ins = newReturnBlock->getFirstNonPHI(); - - retPhi->addIncoming(&*I, preReturn); - retPhi->addIncoming(OldPhi->getIncomingValueForBlock(newEntryBlock), - newEntryBlock); - OldPhi->removeIncomingValue(newEntryBlock); + BasicBlock *PreReturn = NewReturnBlock; + NewReturnBlock = NewReturnBlock->splitBasicBlock( + NewReturnBlock->getFirstNonPHI()->getIterator()); + BasicBlock::iterator I = PreReturn->begin(); + Instruction *Ins = &NewReturnBlock->front(); + while (I != PreReturn->end()) { + PHINode *OldPhi = dyn_cast(I); + if (!OldPhi) + break; + + PHINode *RetPhi = PHINode::Create(OldPhi->getType(), 2, "", Ins); + OldPhi->replaceAllUsesWith(RetPhi); + Ins = NewReturnBlock->getFirstNonPHI(); + + RetPhi->addIncoming(&*I, PreReturn); + RetPhi->addIncoming(OldPhi->getIncomingValueForBlock(NewEntryBlock), + NewEntryBlock); + OldPhi->removeIncomingValue(NewEntryBlock); ++I; } - newEntryBlock->getTerminator()->replaceUsesOfWith(preReturn, newReturnBlock); + NewEntryBlock->getTerminator()->replaceUsesOfWith(PreReturn, NewReturnBlock); // Gather up the blocks that we're going to extract. - std::vector toExtract; - toExtract.push_back(newNonReturnBlock); - for (BasicBlock &BB : *duplicateFunction) - if (&BB != newEntryBlock && &BB != newReturnBlock && - &BB != newNonReturnBlock) - toExtract.push_back(&BB); + std::vector ToExtract; + ToExtract.push_back(NewNonReturnBlock); + for (BasicBlock &BB : *DuplicateFunction) + if (&BB != NewEntryBlock && &BB != NewReturnBlock && + &BB != NewNonReturnBlock) + ToExtract.push_back(&BB); // The CodeExtractor needs a dominator tree. DominatorTree DT; - DT.recalculate(*duplicateFunction); + DT.recalculate(*DuplicateFunction); // Extract the body of the if. - Function* extractedFunction - = CodeExtractor(toExtract, &DT).extractCodeRegion(); + Function *ExtractedFunction = + CodeExtractor(ToExtract, &DT).extractCodeRegion(); // Inline the top-level if test into all callers. - std::vector Users(duplicateFunction->user_begin(), - duplicateFunction->user_end()); + std::vector Users(DuplicateFunction->user_begin(), + DuplicateFunction->user_end()); for (User *User : Users) if (CallInst *CI = dyn_cast(User)) InlineFunction(CI, IFI); @@ -147,44 +148,46 @@ Function *PartialInlinerImpl::unswitchFunction(Function *F) { // Ditch the duplicate, since we're done with it, and rewrite all remaining // users (function pointers, etc.) back to the original function. - duplicateFunction->replaceAllUsesWith(F); - duplicateFunction->eraseFromParent(); + DuplicateFunction->replaceAllUsesWith(F); + DuplicateFunction->eraseFromParent(); ++NumPartialInlined; - return extractedFunction; + return ExtractedFunction; } bool PartialInlinerImpl::run(Module &M) { - std::vector worklist; - worklist.reserve(M.size()); + std::vector Worklist; + Worklist.reserve(M.size()); for (Function &F : M) if (!F.use_empty() && !F.isDeclaration()) - worklist.push_back(&F); + Worklist.push_back(&F); - bool changed = false; - while (!worklist.empty()) { - Function* currFunc = worklist.back(); - worklist.pop_back(); + bool Changed = false; + while (!Worklist.empty()) { + Function *CurrFunc = Worklist.back(); + Worklist.pop_back(); - if (currFunc->use_empty()) continue; + if (CurrFunc->use_empty()) + continue; - bool recursive = false; - for (User *U : currFunc->users()) - if (Instruction* I = dyn_cast(U)) - if (I->getParent()->getParent() == currFunc) { - recursive = true; + bool Recursive = false; + for (User *U : CurrFunc->users()) + if (Instruction *I = dyn_cast(U)) + if (I->getParent()->getParent() == CurrFunc) { + Recursive = true; break; } - if (recursive) continue; + if (Recursive) + continue; - if (Function* newFunc = unswitchFunction(currFunc)) { - worklist.push_back(newFunc); - changed = true; + if (Function *newFunc = unswitchFunction(CurrFunc)) { + Worklist.push_back(newFunc); + Changed = true; } } - return changed; + return Changed; } char PartialInlinerLegacyPass::ID = 0; @@ -201,8 +204,8 @@ ModulePass *llvm::createPartialInliningPass() { PreservedAnalyses PartialInlinerPass::run(Module &M, ModuleAnalysisManager &AM) { auto &FAM = AM.getResult(M).getManager(); - std::function GetAssumptionCache = [&FAM]( - Function &F) -> AssumptionCache & { + std::function GetAssumptionCache = + [&FAM](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; InlineFunctionInfo IFI(nullptr, &GetAssumptionCache);