From 3d512a2dc20aa43fc39c9bdea7067ff073ba7298 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Mon, 22 Aug 2016 19:14:30 +0000 Subject: [PATCH] MSSA: Factor out phi node placement llvm-svn: 279462 --- llvm/include/llvm/Transforms/Utils/MemorySSA.h | 2 ++ llvm/lib/Transforms/Utils/MemorySSA.cpp | 39 +++++++++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/MemorySSA.h b/llvm/include/llvm/Transforms/Utils/MemorySSA.h index 606ecff..3a28b1c 100644 --- a/llvm/include/llvm/Transforms/Utils/MemorySSA.h +++ b/llvm/include/llvm/Transforms/Utils/MemorySSA.h @@ -616,6 +616,8 @@ private: MemoryAccess *findDominatingDef(BasicBlock *, enum InsertionPlace); void removeFromLookups(MemoryAccess *); + void placePHINodes(const SmallPtrSetImpl &, + const SmallPtrSetImpl &); MemoryAccess *renameBlock(BasicBlock *, MemoryAccess *); void renamePass(DomTreeNode *, MemoryAccess *IncomingVal, SmallPtrSet &Visited); diff --git a/llvm/lib/Transforms/Utils/MemorySSA.cpp b/llvm/lib/Transforms/Utils/MemorySSA.cpp index af2f954..e4acddd 100644 --- a/llvm/lib/Transforms/Utils/MemorySSA.cpp +++ b/llvm/lib/Transforms/Utils/MemorySSA.cpp @@ -1459,6 +1459,27 @@ void MemorySSA::OptimizeUses::optimizeUses() { LocStackInfo); } +void MemorySSA::placePHINodes( + const SmallPtrSetImpl &DefiningBlocks, + const SmallPtrSetImpl &LiveInBlocks) { + // Determine where our MemoryPhi's should go + ForwardIDFCalculator IDFs(*DT); + IDFs.setDefiningBlocks(DefiningBlocks); + IDFs.setLiveInBlocks(LiveInBlocks); + SmallVector IDFBlocks; + IDFs.calculate(IDFBlocks); + + // Now place MemoryPhi nodes. + for (auto &BB : IDFBlocks) { + // Insert phi node + AccessList *Accesses = getOrCreateAccessList(BB); + MemoryPhi *Phi = new MemoryPhi(BB->getContext(), BB, NextID++); + ValueToMemoryAccess[BB] = Phi; + // Phi's always are placed at the front of the block. + Accesses->push_front(Phi); + } +} + void MemorySSA::buildMemorySSA() { // We create an access to represent "live on entry", for things like // arguments or users of globals, where the memory they use is defined before @@ -1528,23 +1549,7 @@ void MemorySSA::buildMemorySSA() { // live into it to. LiveInBlockWorklist.append(pred_begin(BB), pred_end(BB)); } - - // Determine where our MemoryPhi's should go - ForwardIDFCalculator IDFs(*DT); - IDFs.setDefiningBlocks(DefiningBlocks); - IDFs.setLiveInBlocks(LiveInBlocks); - SmallVector IDFBlocks; - IDFs.calculate(IDFBlocks); - - // Now place MemoryPhi nodes. - for (auto &BB : IDFBlocks) { - // Insert phi node - AccessList *Accesses = getOrCreateAccessList(BB); - MemoryPhi *Phi = new MemoryPhi(BB->getContext(), BB, NextID++); - ValueToMemoryAccess[BB] = Phi; - // Phi's always are placed at the front of the block. - Accesses->push_front(Phi); - } + placePHINodes(DefiningBlocks, LiveInBlocks); // Now do regular SSA renaming on the MemoryDef/MemoryUse. Visited will get // filled in with all blocks. -- 2.7.4