mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-22 23:24:59 +00:00
Reformat the implementation of mem2reg with clang-format so that my
subsequent changes don't introduce inconsistencies. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186775 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -101,6 +101,7 @@ bool llvm::isAllocaPromotable(const AllocaInst *AI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct AllocaInfo;
|
struct AllocaInfo;
|
||||||
|
|
||||||
// Data package used by RenamePass()
|
// Data package used by RenamePass()
|
||||||
@@ -109,8 +110,8 @@ namespace {
|
|||||||
typedef std::vector<Value *> ValVector;
|
typedef std::vector<Value *> ValVector;
|
||||||
|
|
||||||
RenamePassData() : BB(NULL), Pred(NULL), Values() {}
|
RenamePassData() : BB(NULL), Pred(NULL), Values() {}
|
||||||
RenamePassData(BasicBlock *B, BasicBlock *P,
|
RenamePassData(BasicBlock *B, BasicBlock *P, const ValVector &V)
|
||||||
const ValVector &V) : BB(B), Pred(P), Values(V) {}
|
: BB(B), Pred(P), Values(V) {}
|
||||||
BasicBlock *BB;
|
BasicBlock *BB;
|
||||||
BasicBlock *Pred;
|
BasicBlock *Pred;
|
||||||
ValVector Values;
|
ValVector Values;
|
||||||
@@ -134,6 +135,7 @@ namespace {
|
|||||||
/// The index starts out as the number of the instruction from the start of
|
/// The index starts out as the number of the instruction from the start of
|
||||||
/// the block.
|
/// the block.
|
||||||
DenseMap<const Instruction *, unsigned> InstNumbers;
|
DenseMap<const Instruction *, unsigned> InstNumbers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// This code only looks at accesses to allocas.
|
/// This code only looks at accesses to allocas.
|
||||||
@@ -149,15 +151,16 @@ namespace {
|
|||||||
|
|
||||||
// If we already have this instruction number, return it.
|
// If we already have this instruction number, return it.
|
||||||
DenseMap<const Instruction *, unsigned>::iterator It = InstNumbers.find(I);
|
DenseMap<const Instruction *, unsigned>::iterator It = InstNumbers.find(I);
|
||||||
if (It != InstNumbers.end()) return It->second;
|
if (It != InstNumbers.end())
|
||||||
|
return It->second;
|
||||||
|
|
||||||
// Scan the whole block to get the instruction. This accumulates
|
// Scan the whole block to get the instruction. This accumulates
|
||||||
// information for every interesting instruction in the block, in order to
|
// information for every interesting instruction in the block, in order to
|
||||||
// avoid gratuitus rescans.
|
// avoid gratuitus rescans.
|
||||||
const BasicBlock *BB = I->getParent();
|
const BasicBlock *BB = I->getParent();
|
||||||
unsigned InstNo = 0;
|
unsigned InstNo = 0;
|
||||||
for (BasicBlock::const_iterator BBI = BB->begin(), E = BB->end();
|
for (BasicBlock::const_iterator BBI = BB->begin(), E = BB->end(); BBI != E;
|
||||||
BBI != E; ++BBI)
|
++BBI)
|
||||||
if (isInterestingInstruction(BBI))
|
if (isInterestingInstruction(BBI))
|
||||||
InstNumbers[BBI] = InstNo++;
|
InstNumbers[BBI] = InstNo++;
|
||||||
It = InstNumbers.find(I);
|
It = InstNumbers.find(I);
|
||||||
@@ -166,13 +169,9 @@ namespace {
|
|||||||
return It->second;
|
return It->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteValue(const Instruction *I) {
|
void deleteValue(const Instruction *I) { InstNumbers.erase(I); }
|
||||||
InstNumbers.erase(I);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear() {
|
void clear() { InstNumbers.clear(); }
|
||||||
InstNumbers.clear();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PromoteMem2Reg {
|
struct PromoteMem2Reg {
|
||||||
@@ -222,13 +221,12 @@ namespace {
|
|||||||
|
|
||||||
/// Lazily compute the number of predecessors a block has.
|
/// Lazily compute the number of predecessors a block has.
|
||||||
DenseMap<const BasicBlock *, unsigned> BBNumPreds;
|
DenseMap<const BasicBlock *, unsigned> BBNumPreds;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PromoteMem2Reg(const std::vector<AllocaInst *> &A, DominatorTree &dt,
|
PromoteMem2Reg(const std::vector<AllocaInst *> &A, DominatorTree &dt,
|
||||||
AliasSetTracker *ast)
|
AliasSetTracker *ast)
|
||||||
: Allocas(A), DT(dt), DIB(0), AST(ast) {}
|
: Allocas(A), DT(dt), DIB(0), AST(ast) {}
|
||||||
~PromoteMem2Reg() {
|
~PromoteMem2Reg() { delete DIB; }
|
||||||
delete DIB;
|
|
||||||
}
|
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@@ -333,6 +331,7 @@ namespace {
|
|||||||
return LHS.second < RHS.second;
|
return LHS.second < RHS.second;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
static void removeLifetimeIntrinsicUsers(AllocaInst *AI) {
|
static void removeLifetimeIntrinsicUsers(AllocaInst *AI) {
|
||||||
@@ -364,7 +363,8 @@ static void removeLifetimeIntrinsicUsers(AllocaInst *AI) {
|
|||||||
void PromoteMem2Reg::run() {
|
void PromoteMem2Reg::run() {
|
||||||
Function &F = *DT.getRoot()->getParent();
|
Function &F = *DT.getRoot()->getParent();
|
||||||
|
|
||||||
if (AST) PointerAllocaValues.resize(Allocas.size());
|
if (AST)
|
||||||
|
PointerAllocaValues.resize(Allocas.size());
|
||||||
AllocaDbgDeclares.resize(Allocas.size());
|
AllocaDbgDeclares.resize(Allocas.size());
|
||||||
|
|
||||||
AllocaInfo Info;
|
AllocaInfo Info;
|
||||||
@@ -373,8 +373,7 @@ void PromoteMem2Reg::run() {
|
|||||||
for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
|
for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
|
||||||
AllocaInst *AI = Allocas[AllocaNum];
|
AllocaInst *AI = Allocas[AllocaNum];
|
||||||
|
|
||||||
assert(isAllocaPromotable(AI) &&
|
assert(isAllocaPromotable(AI) && "Cannot promote non-promotable alloca!");
|
||||||
"Cannot promote non-promotable alloca!");
|
|
||||||
assert(AI->getParent()->getParent() == &F &&
|
assert(AI->getParent()->getParent() == &F &&
|
||||||
"All allocas should be in the same function, which is same as DF!");
|
"All allocas should be in the same function, which is same as DF!");
|
||||||
|
|
||||||
@@ -382,7 +381,8 @@ void PromoteMem2Reg::run() {
|
|||||||
|
|
||||||
if (AI->use_empty()) {
|
if (AI->use_empty()) {
|
||||||
// If there are no uses of the alloca, just delete it now.
|
// If there are no uses of the alloca, just delete it now.
|
||||||
if (AST) AST->deleteValue(AI);
|
if (AST)
|
||||||
|
AST->deleteValue(AI);
|
||||||
AI->eraseFromParent();
|
AI->eraseFromParent();
|
||||||
|
|
||||||
// Remove the alloca from the Allocas list, since it has been processed
|
// Remove the alloca from the Allocas list, since it has been processed
|
||||||
@@ -414,7 +414,8 @@ void PromoteMem2Reg::run() {
|
|||||||
Info.OnlyStore->eraseFromParent();
|
Info.OnlyStore->eraseFromParent();
|
||||||
LBI.deleteValue(Info.OnlyStore);
|
LBI.deleteValue(Info.OnlyStore);
|
||||||
|
|
||||||
if (AST) AST->deleteValue(AI);
|
if (AST)
|
||||||
|
AST->deleteValue(AI);
|
||||||
AI->eraseFromParent();
|
AI->eraseFromParent();
|
||||||
LBI.deleteValue(AI);
|
LBI.deleteValue(AI);
|
||||||
|
|
||||||
@@ -448,7 +449,8 @@ void PromoteMem2Reg::run() {
|
|||||||
LBI.deleteValue(SI);
|
LBI.deleteValue(SI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AST) AST->deleteValue(AI);
|
if (AST)
|
||||||
|
AST->deleteValue(AI);
|
||||||
AI->eraseFromParent();
|
AI->eraseFromParent();
|
||||||
LBI.deleteValue(AI);
|
LBI.deleteValue(AI);
|
||||||
|
|
||||||
@@ -497,7 +499,8 @@ void PromoteMem2Reg::run() {
|
|||||||
PointerAllocaValues[AllocaNum] = Info.AllocaPointerVal;
|
PointerAllocaValues[AllocaNum] = Info.AllocaPointerVal;
|
||||||
|
|
||||||
// Remember the dbg.declare intrinsic describing this alloca, if any.
|
// Remember the dbg.declare intrinsic describing this alloca, if any.
|
||||||
if (Info.DbgDeclare) AllocaDbgDeclares[AllocaNum] = Info.DbgDeclare;
|
if (Info.DbgDeclare)
|
||||||
|
AllocaDbgDeclares[AllocaNum] = Info.DbgDeclare;
|
||||||
|
|
||||||
// Keep the reverse mapping of the 'Allocas' array for the rename pass.
|
// Keep the reverse mapping of the 'Allocas' array for the rename pass.
|
||||||
AllocaLookup[Allocas[AllocaNum]] = AllocaNum;
|
AllocaLookup[Allocas[AllocaNum]] = AllocaNum;
|
||||||
@@ -514,7 +517,6 @@ void PromoteMem2Reg::run() {
|
|||||||
|
|
||||||
LBI.clear();
|
LBI.clear();
|
||||||
|
|
||||||
|
|
||||||
// Set the incoming values for the basic block to be null values for all of
|
// Set the incoming values for the basic block to be null values for all of
|
||||||
// the alloca's. We do this in case there is a load of a value that has not
|
// the alloca's. We do this in case there is a load of a value that has not
|
||||||
// been stored yet. In this case, it will get this null value.
|
// been stored yet. In this case, it will get this null value.
|
||||||
@@ -548,7 +550,8 @@ void PromoteMem2Reg::run() {
|
|||||||
// tree. Just delete the users now.
|
// tree. Just delete the users now.
|
||||||
if (!A->use_empty())
|
if (!A->use_empty())
|
||||||
A->replaceAllUsesWith(UndefValue::get(A->getType()));
|
A->replaceAllUsesWith(UndefValue::get(A->getType()));
|
||||||
if (AST) AST->deleteValue(A);
|
if (AST)
|
||||||
|
AST->deleteValue(A);
|
||||||
A->eraseFromParent();
|
A->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,8 +572,10 @@ void PromoteMem2Reg::run() {
|
|||||||
// simplify and RAUW them as we go. If it was not, we could add uses to
|
// simplify and RAUW them as we go. If it was not, we could add uses to
|
||||||
// the values we replace with in a non deterministic order, thus creating
|
// the values we replace with in a non deterministic order, thus creating
|
||||||
// non deterministic def->use chains.
|
// non deterministic def->use chains.
|
||||||
for (DenseMap<std::pair<unsigned, unsigned>, PHINode*>::iterator I =
|
for (DenseMap<std::pair<unsigned, unsigned>, PHINode *>::iterator
|
||||||
NewPhiNodes.begin(), E = NewPhiNodes.end(); I != E;) {
|
I = NewPhiNodes.begin(),
|
||||||
|
E = NewPhiNodes.end();
|
||||||
|
I != E;) {
|
||||||
PHINode *PN = I->second;
|
PHINode *PN = I->second;
|
||||||
|
|
||||||
// If this PHI node merges one value and/or undefs, get the value.
|
// If this PHI node merges one value and/or undefs, get the value.
|
||||||
@@ -593,8 +598,10 @@ void PromoteMem2Reg::run() {
|
|||||||
// have incoming values for all predecessors. Loop over all PHI nodes we have
|
// have incoming values for all predecessors. Loop over all PHI nodes we have
|
||||||
// created, inserting undef values if they are missing any incoming values.
|
// created, inserting undef values if they are missing any incoming values.
|
||||||
//
|
//
|
||||||
for (DenseMap<std::pair<unsigned, unsigned>, PHINode*>::iterator I =
|
for (DenseMap<std::pair<unsigned, unsigned>, PHINode *>::iterator
|
||||||
NewPhiNodes.begin(), E = NewPhiNodes.end(); I != E; ++I) {
|
I = NewPhiNodes.begin(),
|
||||||
|
E = NewPhiNodes.end();
|
||||||
|
I != E; ++I) {
|
||||||
// We want to do this once per basic block. As such, only process a block
|
// We want to do this once per basic block. As such, only process a block
|
||||||
// when we find the PHI that is the first entry in the block.
|
// when we find the PHI that is the first entry in the block.
|
||||||
PHINode *SomePHI = I->second;
|
PHINode *SomePHI = I->second;
|
||||||
@@ -620,9 +627,8 @@ void PromoteMem2Reg::run() {
|
|||||||
// them from the Preds list.
|
// them from the Preds list.
|
||||||
for (unsigned i = 0, e = SomePHI->getNumIncomingValues(); i != e; ++i) {
|
for (unsigned i = 0, e = SomePHI->getNumIncomingValues(); i != e; ++i) {
|
||||||
// Do a log(n) search of the Preds list for the entry we want.
|
// Do a log(n) search of the Preds list for the entry we want.
|
||||||
SmallVectorImpl<BasicBlock *>::iterator EntIt =
|
SmallVectorImpl<BasicBlock *>::iterator EntIt = std::lower_bound(
|
||||||
std::lower_bound(Preds.begin(), Preds.end(),
|
Preds.begin(), Preds.end(), SomePHI->getIncomingBlock(i));
|
||||||
SomePHI->getIncomingBlock(i));
|
|
||||||
assert(EntIt != Preds.end() && *EntIt == SomePHI->getIncomingBlock(i) &&
|
assert(EntIt != Preds.end() && *EntIt == SomePHI->getIncomingBlock(i) &&
|
||||||
"PHI node has entry for a block which is not a predecessor!");
|
"PHI node has entry for a block which is not a predecessor!");
|
||||||
|
|
||||||
@@ -647,14 +653,13 @@ void PromoteMem2Reg::run() {
|
|||||||
NewPhiNodes.clear();
|
NewPhiNodes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \brief Determine which blocks the value is live in.
|
/// \brief Determine which blocks the value is live in.
|
||||||
///
|
///
|
||||||
/// These are blocks which lead to uses. Knowing this allows us to avoid
|
/// These are blocks which lead to uses. Knowing this allows us to avoid
|
||||||
/// inserting PHI nodes into blocks which don't lead to uses (thus, the
|
/// inserting PHI nodes into blocks which don't lead to uses (thus, the
|
||||||
/// inserted phi nodes would be dead).
|
/// inserted phi nodes would be dead).
|
||||||
void PromoteMem2Reg::
|
void PromoteMem2Reg::ComputeLiveInBlocks(
|
||||||
ComputeLiveInBlocks(AllocaInst *AI, AllocaInfo &Info,
|
AllocaInst *AI, AllocaInfo &Info,
|
||||||
const SmallPtrSet<BasicBlock *, 32> &DefBlocks,
|
const SmallPtrSet<BasicBlock *, 32> &DefBlocks,
|
||||||
SmallPtrSet<BasicBlock *, 32> &LiveInBlocks) {
|
SmallPtrSet<BasicBlock *, 32> &LiveInBlocks) {
|
||||||
|
|
||||||
@@ -669,13 +674,15 @@ ComputeLiveInBlocks(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
// the value isn't really live-in.
|
// the value isn't really live-in.
|
||||||
for (unsigned i = 0, e = LiveInBlockWorklist.size(); i != e; ++i) {
|
for (unsigned i = 0, e = LiveInBlockWorklist.size(); i != e; ++i) {
|
||||||
BasicBlock *BB = LiveInBlockWorklist[i];
|
BasicBlock *BB = LiveInBlockWorklist[i];
|
||||||
if (!DefBlocks.count(BB)) continue;
|
if (!DefBlocks.count(BB))
|
||||||
|
continue;
|
||||||
|
|
||||||
// Okay, this is a block that both uses and defines the value. If the first
|
// Okay, this is a block that both uses and defines the value. If the first
|
||||||
// reference to the alloca is a def (store), then we know it isn't live-in.
|
// reference to the alloca is a def (store), then we know it isn't live-in.
|
||||||
for (BasicBlock::iterator I = BB->begin();; ++I) {
|
for (BasicBlock::iterator I = BB->begin();; ++I) {
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
|
if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
|
||||||
if (SI->getOperand(1) != AI) continue;
|
if (SI->getOperand(1) != AI)
|
||||||
|
continue;
|
||||||
|
|
||||||
// We found a store to the alloca before a load. The alloca is not
|
// We found a store to the alloca before a load. The alloca is not
|
||||||
// actually live-in here.
|
// actually live-in here.
|
||||||
@@ -686,7 +693,8 @@ ComputeLiveInBlocks(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
if (LI->getOperand(0) != AI) continue;
|
if (LI->getOperand(0) != AI)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Okay, we found a load before a store to the alloca. It is actually
|
// Okay, we found a load before a store to the alloca. It is actually
|
||||||
// live into this block.
|
// live into this block.
|
||||||
@@ -738,12 +746,14 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
|
|||||||
|
|
||||||
// Use a priority queue keyed on dominator tree level so that inserted nodes
|
// Use a priority queue keyed on dominator tree level so that inserted nodes
|
||||||
// are handled from the bottom of the dominator tree upwards.
|
// are handled from the bottom of the dominator tree upwards.
|
||||||
typedef std::priority_queue<DomTreeNodePair, SmallVector<DomTreeNodePair, 32>,
|
typedef std::priority_queue<DomTreeNodePair,
|
||||||
|
SmallVector<DomTreeNodePair, 32>,
|
||||||
DomTreeNodeCompare> IDFPriorityQueue;
|
DomTreeNodeCompare> IDFPriorityQueue;
|
||||||
IDFPriorityQueue PQ;
|
IDFPriorityQueue PQ;
|
||||||
|
|
||||||
for (SmallPtrSet<BasicBlock *, 32>::const_iterator I = DefBlocks.begin(),
|
for (SmallPtrSet<BasicBlock *, 32>::const_iterator I = DefBlocks.begin(),
|
||||||
E = DefBlocks.end(); I != E; ++I) {
|
E = DefBlocks.end();
|
||||||
|
I != E; ++I) {
|
||||||
if (DomTreeNode *Node = DT.getNode(*I))
|
if (DomTreeNode *Node = DT.getNode(*I))
|
||||||
PQ.push(std::make_pair(Node, DomLevels[Node]));
|
PQ.push(std::make_pair(Node, DomLevels[Node]));
|
||||||
}
|
}
|
||||||
@@ -812,8 +822,7 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
|
|||||||
|
|
||||||
/// If there is only a single store to this value, replace any loads of it that
|
/// If there is only a single store to this value, replace any loads of it that
|
||||||
/// are directly dominated by the definition with the value stored.
|
/// are directly dominated by the definition with the value stored.
|
||||||
void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
|
void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info,
|
||||||
AllocaInfo &Info,
|
|
||||||
LargeBlockInfo &LBI) {
|
LargeBlockInfo &LBI) {
|
||||||
StoreInst *OnlyStore = Info.OnlyStore;
|
StoreInst *OnlyStore = Info.OnlyStore;
|
||||||
bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
|
bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
|
||||||
@@ -874,7 +883,6 @@ void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// This is a helper predicate used to search by the first element of a pair.
|
/// This is a helper predicate used to search by the first element of a pair.
|
||||||
struct StoreIndexSearchPredicate {
|
struct StoreIndexSearchPredicate {
|
||||||
bool operator()(const std::pair<unsigned, StoreInst *> &LHS,
|
bool operator()(const std::pair<unsigned, StoreInst *> &LHS,
|
||||||
@@ -882,7 +890,6 @@ struct StoreIndexSearchPredicate {
|
|||||||
return LHS.first < RHS.first;
|
return LHS.first < RHS.first;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Many allocas are only used within a single basic block. If this is the
|
/// Many allocas are only used within a single basic block. If this is the
|
||||||
@@ -912,8 +919,8 @@ void PromoteMem2Reg::PromoteSingleBlockAlloca(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
typedef SmallVector<std::pair<unsigned, StoreInst *>, 64> StoresByIndexTy;
|
typedef SmallVector<std::pair<unsigned, StoreInst *>, 64> StoresByIndexTy;
|
||||||
StoresByIndexTy StoresByIndex;
|
StoresByIndexTy StoresByIndex;
|
||||||
|
|
||||||
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end();
|
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;
|
||||||
UI != E; ++UI)
|
++UI)
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(*UI))
|
if (StoreInst *SI = dyn_cast<StoreInst>(*UI))
|
||||||
StoresByIndex.push_back(std::make_pair(LBI.getInstructionIndex(SI), SI));
|
StoresByIndex.push_back(std::make_pair(LBI.getInstructionIndex(SI), SI));
|
||||||
|
|
||||||
@@ -938,13 +945,14 @@ void PromoteMem2Reg::PromoteSingleBlockAlloca(AllocaInst *AI, AllocaInfo &Info,
|
|||||||
// store above them, if any.
|
// store above them, if any.
|
||||||
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;) {
|
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;) {
|
||||||
LoadInst *LI = dyn_cast<LoadInst>(*UI++);
|
LoadInst *LI = dyn_cast<LoadInst>(*UI++);
|
||||||
if (!LI) continue;
|
if (!LI)
|
||||||
|
continue;
|
||||||
|
|
||||||
unsigned LoadIdx = LBI.getInstructionIndex(LI);
|
unsigned LoadIdx = LBI.getInstructionIndex(LI);
|
||||||
|
|
||||||
// Find the nearest store that has a lower than this load.
|
// Find the nearest store that has a lower than this load.
|
||||||
StoresByIndexTy::iterator I =
|
StoresByIndexTy::iterator I = std::lower_bound(
|
||||||
std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),
|
StoresByIndex.begin(), StoresByIndex.end(),
|
||||||
std::pair<unsigned, StoreInst *>(LoadIdx, static_cast<StoreInst *>(0)),
|
std::pair<unsigned, StoreInst *>(LoadIdx, static_cast<StoreInst *>(0)),
|
||||||
StoreIndexSearchPredicate());
|
StoreIndexSearchPredicate());
|
||||||
|
|
||||||
@@ -974,7 +982,8 @@ bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo,
|
|||||||
PHINode *&PN = NewPhiNodes[std::make_pair(BBNumbers[BB], AllocaNo)];
|
PHINode *&PN = NewPhiNodes[std::make_pair(BBNumbers[BB], AllocaNo)];
|
||||||
|
|
||||||
// If the BB already has a phi node added for the i'th alloca then we're done!
|
// If the BB already has a phi node added for the i'th alloca then we're done!
|
||||||
if (PN) return false;
|
if (PN)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Create a PhiNode using the dereferenced type... and add the phi-node to the
|
// Create a PhiNode using the dereferenced type... and add the phi-node to the
|
||||||
// BasicBlock.
|
// BasicBlock.
|
||||||
@@ -1034,7 +1043,8 @@ NextIteration:
|
|||||||
// Get the next phi node.
|
// Get the next phi node.
|
||||||
++PNI;
|
++PNI;
|
||||||
APN = dyn_cast<PHINode>(PNI);
|
APN = dyn_cast<PHINode>(PNI);
|
||||||
if (APN == 0) break;
|
if (APN == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
// Verify that it is missing entries. If not, it is not being inserted
|
// Verify that it is missing entries. If not, it is not being inserted
|
||||||
// by this mem2reg invocation so we want to ignore it.
|
// by this mem2reg invocation so we want to ignore it.
|
||||||
@@ -1043,17 +1053,20 @@ NextIteration:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't revisit blocks.
|
// Don't revisit blocks.
|
||||||
if (!Visited.insert(BB)) return;
|
if (!Visited.insert(BB))
|
||||||
|
return;
|
||||||
|
|
||||||
for (BasicBlock::iterator II = BB->begin(); !isa<TerminatorInst>(II);) {
|
for (BasicBlock::iterator II = BB->begin(); !isa<TerminatorInst>(II);) {
|
||||||
Instruction *I = II++; // get the instruction, increment iterator
|
Instruction *I = II++; // get the instruction, increment iterator
|
||||||
|
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
AllocaInst *Src = dyn_cast<AllocaInst>(LI->getPointerOperand());
|
AllocaInst *Src = dyn_cast<AllocaInst>(LI->getPointerOperand());
|
||||||
if (!Src) continue;
|
if (!Src)
|
||||||
|
continue;
|
||||||
|
|
||||||
DenseMap<AllocaInst *, unsigned>::iterator AI = AllocaLookup.find(Src);
|
DenseMap<AllocaInst *, unsigned>::iterator AI = AllocaLookup.find(Src);
|
||||||
if (AI == AllocaLookup.end()) continue;
|
if (AI == AllocaLookup.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
Value *V = IncomingVals[AI->second];
|
Value *V = IncomingVals[AI->second];
|
||||||
|
|
||||||
@@ -1066,7 +1079,8 @@ NextIteration:
|
|||||||
// Delete this instruction and mark the name as the current holder of the
|
// Delete this instruction and mark the name as the current holder of the
|
||||||
// value
|
// value
|
||||||
AllocaInst *Dest = dyn_cast<AllocaInst>(SI->getPointerOperand());
|
AllocaInst *Dest = dyn_cast<AllocaInst>(SI->getPointerOperand());
|
||||||
if (!Dest) continue;
|
if (!Dest)
|
||||||
|
continue;
|
||||||
|
|
||||||
DenseMap<AllocaInst *, unsigned>::iterator ai = AllocaLookup.find(Dest);
|
DenseMap<AllocaInst *, unsigned>::iterator ai = AllocaLookup.find(Dest);
|
||||||
if (ai == AllocaLookup.end())
|
if (ai == AllocaLookup.end())
|
||||||
@@ -1086,7 +1100,8 @@ NextIteration:
|
|||||||
|
|
||||||
// 'Recurse' to our successors.
|
// 'Recurse' to our successors.
|
||||||
succ_iterator I = succ_begin(BB), E = succ_end(BB);
|
succ_iterator I = succ_begin(BB), E = succ_end(BB);
|
||||||
if (I == E) return;
|
if (I == E)
|
||||||
|
return;
|
||||||
|
|
||||||
// Keep track of the successors so we don't visit the same successor twice
|
// Keep track of the successors so we don't visit the same successor twice
|
||||||
SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
|
SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
|
||||||
@@ -1107,7 +1122,8 @@ NextIteration:
|
|||||||
void llvm::PromoteMemToReg(const std::vector<AllocaInst *> &Allocas,
|
void llvm::PromoteMemToReg(const std::vector<AllocaInst *> &Allocas,
|
||||||
DominatorTree &DT, AliasSetTracker *AST) {
|
DominatorTree &DT, AliasSetTracker *AST) {
|
||||||
// If there is nothing to do, bail out...
|
// If there is nothing to do, bail out...
|
||||||
if (Allocas.empty()) return;
|
if (Allocas.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
PromoteMem2Reg(Allocas, DT, AST).run();
|
PromoteMem2Reg(Allocas, DT, AST).run();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user