mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
[LoopDist] Move loop-versioning helper functions to Cloning, NFC
Summary: This makes them available to the LoopVersioning class as that is moved to its own module in the next patch. Reviewers: ashutosh.nema, hfinkel Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10576 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241931 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -45,6 +45,7 @@ class LoopInfo;
|
|||||||
class AllocaInst;
|
class AllocaInst;
|
||||||
class AliasAnalysis;
|
class AliasAnalysis;
|
||||||
class AssumptionCacheTracker;
|
class AssumptionCacheTracker;
|
||||||
|
class DominatorTree;
|
||||||
|
|
||||||
/// CloneModule - Return an exact copy of the specified module
|
/// CloneModule - Return an exact copy of the specified module
|
||||||
///
|
///
|
||||||
@@ -233,6 +234,21 @@ bool InlineFunction(InvokeInst *II, InlineFunctionInfo &IFI,
|
|||||||
bool InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
|
bool InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
|
||||||
bool InsertLifetime = true);
|
bool InsertLifetime = true);
|
||||||
|
|
||||||
|
/// \brief Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
|
||||||
|
/// Blocks.
|
||||||
|
///
|
||||||
|
/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
|
||||||
|
/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
|
||||||
|
Loop *cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB,
|
||||||
|
Loop *OrigLoop, ValueToValueMapTy &VMap,
|
||||||
|
const Twine &NameSuffix, LoopInfo *LI,
|
||||||
|
DominatorTree *DT,
|
||||||
|
SmallVectorImpl<BasicBlock *> &Blocks);
|
||||||
|
|
||||||
|
/// \brief Remaps instructions in \p Blocks using the mapping in \p VMap.
|
||||||
|
void remapInstructionsInBlocks(const SmallVectorImpl<BasicBlock *> &Blocks,
|
||||||
|
ValueToValueMapTy &VMap);
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -55,70 +55,6 @@ static cl::opt<bool> DistributeNonIfConvertible(
|
|||||||
|
|
||||||
STATISTIC(NumLoopsDistributed, "Number of loops distributed");
|
STATISTIC(NumLoopsDistributed, "Number of loops distributed");
|
||||||
|
|
||||||
/// \brief Remaps instructions in a loop including the preheader.
|
|
||||||
static void remapInstructionsInLoop(const SmallVectorImpl<BasicBlock *> &Blocks,
|
|
||||||
ValueToValueMapTy &VMap) {
|
|
||||||
// Rewrite the code to refer to itself.
|
|
||||||
for (auto *BB : Blocks)
|
|
||||||
for (auto &Inst : *BB)
|
|
||||||
RemapInstruction(&Inst, VMap,
|
|
||||||
RF_NoModuleLevelChanges | RF_IgnoreMissingEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
|
|
||||||
/// Blocks.
|
|
||||||
///
|
|
||||||
/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
|
|
||||||
/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
|
|
||||||
static Loop *cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB,
|
|
||||||
Loop *OrigLoop, ValueToValueMapTy &VMap,
|
|
||||||
const Twine &NameSuffix, LoopInfo *LI,
|
|
||||||
DominatorTree *DT,
|
|
||||||
SmallVectorImpl<BasicBlock *> &Blocks) {
|
|
||||||
Function *F = OrigLoop->getHeader()->getParent();
|
|
||||||
Loop *ParentLoop = OrigLoop->getParentLoop();
|
|
||||||
|
|
||||||
Loop *NewLoop = new Loop();
|
|
||||||
if (ParentLoop)
|
|
||||||
ParentLoop->addChildLoop(NewLoop);
|
|
||||||
else
|
|
||||||
LI->addTopLevelLoop(NewLoop);
|
|
||||||
|
|
||||||
BasicBlock *OrigPH = OrigLoop->getLoopPreheader();
|
|
||||||
BasicBlock *NewPH = CloneBasicBlock(OrigPH, VMap, NameSuffix, F);
|
|
||||||
// To rename the loop PHIs.
|
|
||||||
VMap[OrigPH] = NewPH;
|
|
||||||
Blocks.push_back(NewPH);
|
|
||||||
|
|
||||||
// Update LoopInfo.
|
|
||||||
if (ParentLoop)
|
|
||||||
ParentLoop->addBasicBlockToLoop(NewPH, *LI);
|
|
||||||
|
|
||||||
// Update DominatorTree.
|
|
||||||
DT->addNewBlock(NewPH, LoopDomBB);
|
|
||||||
|
|
||||||
for (BasicBlock *BB : OrigLoop->getBlocks()) {
|
|
||||||
BasicBlock *NewBB = CloneBasicBlock(BB, VMap, NameSuffix, F);
|
|
||||||
VMap[BB] = NewBB;
|
|
||||||
|
|
||||||
// Update LoopInfo.
|
|
||||||
NewLoop->addBasicBlockToLoop(NewBB, *LI);
|
|
||||||
|
|
||||||
// Update DominatorTree.
|
|
||||||
BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock();
|
|
||||||
DT->addNewBlock(NewBB, cast<BasicBlock>(VMap[IDomBB]));
|
|
||||||
|
|
||||||
Blocks.push_back(NewBB);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move them physically from the end of the block list.
|
|
||||||
F->getBasicBlockList().splice(Before, F->getBasicBlockList(), NewPH);
|
|
||||||
F->getBasicBlockList().splice(Before, F->getBasicBlockList(),
|
|
||||||
NewLoop->getHeader(), F->end());
|
|
||||||
|
|
||||||
return NewLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// \brief Maintains the set of instructions of the loop for a partition before
|
/// \brief Maintains the set of instructions of the loop for a partition before
|
||||||
/// cloning. After cloning, it hosts the new loop.
|
/// cloning. After cloning, it hosts the new loop.
|
||||||
@@ -204,7 +140,9 @@ public:
|
|||||||
ValueToValueMapTy &getVMap() { return VMap; }
|
ValueToValueMapTy &getVMap() { return VMap; }
|
||||||
|
|
||||||
/// \brief Remaps the cloned instructions using VMap.
|
/// \brief Remaps the cloned instructions using VMap.
|
||||||
void remapInstructions() { remapInstructionsInLoop(ClonedLoopBlocks, VMap); }
|
void remapInstructions() {
|
||||||
|
remapInstructionsInBlocks(ClonedLoopBlocks, VMap);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Based on the set of instructions selected for this partition,
|
/// \brief Based on the set of instructions selected for this partition,
|
||||||
/// removes the unnecessary ones.
|
/// removes the unnecessary ones.
|
||||||
@@ -673,7 +611,7 @@ public:
|
|||||||
NonVersionedLoop =
|
NonVersionedLoop =
|
||||||
cloneLoopWithPreheader(PH, MemCheckBB, VersionedLoop, VMap,
|
cloneLoopWithPreheader(PH, MemCheckBB, VersionedLoop, VMap,
|
||||||
".lver.orig", LI, DT, NonVersionedLoopBlocks);
|
".lver.orig", LI, DT, NonVersionedLoopBlocks);
|
||||||
remapInstructionsInLoop(NonVersionedLoopBlocks, VMap);
|
remapInstructionsInBlocks(NonVersionedLoopBlocks, VMap);
|
||||||
|
|
||||||
// Insert the conditional branch based on the result of the memchecks.
|
// Insert the conditional branch based on the result of the memchecks.
|
||||||
Instruction *OrigTerm = MemCheckBB->getTerminator();
|
Instruction *OrigTerm = MemCheckBB->getTerminator();
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/InstructionSimplify.h"
|
#include "llvm/Analysis/InstructionSimplify.h"
|
||||||
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
#include "llvm/IR/CFG.h"
|
#include "llvm/IR/CFG.h"
|
||||||
#include "llvm/IR/Constants.h"
|
#include "llvm/IR/Constants.h"
|
||||||
#include "llvm/IR/DebugInfo.h"
|
#include "llvm/IR/DebugInfo.h"
|
||||||
@@ -720,3 +721,68 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
ModuleLevelChanges, Returns, NameSuffix, CodeInfo,
|
ModuleLevelChanges, Returns, NameSuffix, CodeInfo,
|
||||||
nullptr);
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Remaps instructions in \p Blocks using the mapping in \p VMap.
|
||||||
|
void llvm::remapInstructionsInBlocks(
|
||||||
|
const SmallVectorImpl<BasicBlock *> &Blocks, ValueToValueMapTy &VMap) {
|
||||||
|
// Rewrite the code to refer to itself.
|
||||||
|
for (auto *BB : Blocks)
|
||||||
|
for (auto &Inst : *BB)
|
||||||
|
RemapInstruction(&Inst, VMap,
|
||||||
|
RF_NoModuleLevelChanges | RF_IgnoreMissingEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
|
||||||
|
/// Blocks.
|
||||||
|
///
|
||||||
|
/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
|
||||||
|
/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
|
||||||
|
Loop *llvm::cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB,
|
||||||
|
Loop *OrigLoop, ValueToValueMapTy &VMap,
|
||||||
|
const Twine &NameSuffix, LoopInfo *LI,
|
||||||
|
DominatorTree *DT,
|
||||||
|
SmallVectorImpl<BasicBlock *> &Blocks) {
|
||||||
|
Function *F = OrigLoop->getHeader()->getParent();
|
||||||
|
Loop *ParentLoop = OrigLoop->getParentLoop();
|
||||||
|
|
||||||
|
Loop *NewLoop = new Loop();
|
||||||
|
if (ParentLoop)
|
||||||
|
ParentLoop->addChildLoop(NewLoop);
|
||||||
|
else
|
||||||
|
LI->addTopLevelLoop(NewLoop);
|
||||||
|
|
||||||
|
BasicBlock *OrigPH = OrigLoop->getLoopPreheader();
|
||||||
|
assert(OrigPH && "No preheader");
|
||||||
|
BasicBlock *NewPH = CloneBasicBlock(OrigPH, VMap, NameSuffix, F);
|
||||||
|
// To rename the loop PHIs.
|
||||||
|
VMap[OrigPH] = NewPH;
|
||||||
|
Blocks.push_back(NewPH);
|
||||||
|
|
||||||
|
// Update LoopInfo.
|
||||||
|
if (ParentLoop)
|
||||||
|
ParentLoop->addBasicBlockToLoop(NewPH, *LI);
|
||||||
|
|
||||||
|
// Update DominatorTree.
|
||||||
|
DT->addNewBlock(NewPH, LoopDomBB);
|
||||||
|
|
||||||
|
for (BasicBlock *BB : OrigLoop->getBlocks()) {
|
||||||
|
BasicBlock *NewBB = CloneBasicBlock(BB, VMap, NameSuffix, F);
|
||||||
|
VMap[BB] = NewBB;
|
||||||
|
|
||||||
|
// Update LoopInfo.
|
||||||
|
NewLoop->addBasicBlockToLoop(NewBB, *LI);
|
||||||
|
|
||||||
|
// Update DominatorTree.
|
||||||
|
BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock();
|
||||||
|
DT->addNewBlock(NewBB, cast<BasicBlock>(VMap[IDomBB]));
|
||||||
|
|
||||||
|
Blocks.push_back(NewBB);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move them physically from the end of the block list.
|
||||||
|
F->getBasicBlockList().splice(Before, F->getBasicBlockList(), NewPH);
|
||||||
|
F->getBasicBlockList().splice(Before, F->getBasicBlockList(),
|
||||||
|
NewLoop->getHeader(), F->end());
|
||||||
|
|
||||||
|
return NewLoop;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user