mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
* Fix bug: Mem2Reg/2003-04-10-DFNotFound.ll
* Make Mem2Reg assign version numbers now for renamed variables instead of .mem2reg suffixes. This produces what people think of as SSA. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5771 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Constant.h"
|
#include "llvm/Constant.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
#include "Support/StringExtras.h"
|
||||||
|
|
||||||
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
|
/// isAllocaPromotable - Return true if this alloca is legal for promotion.
|
||||||
/// This is true if there are only loads and stores to the alloca...
|
/// This is true if there are only loads and stores to the alloca...
|
||||||
@@ -50,6 +51,7 @@ bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD) {
|
|||||||
namespace {
|
namespace {
|
||||||
struct PromoteMem2Reg {
|
struct PromoteMem2Reg {
|
||||||
const std::vector<AllocaInst*> &Allocas; // the alloca instructions..
|
const std::vector<AllocaInst*> &Allocas; // the alloca instructions..
|
||||||
|
std::vector<unsigned> VersionNumbers; // Current version counters
|
||||||
DominanceFrontier &DF;
|
DominanceFrontier &DF;
|
||||||
const TargetData &TD;
|
const TargetData &TD;
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ void PromoteMem2Reg::run() {
|
|||||||
if (Allocas.empty()) return;
|
if (Allocas.empty()) return;
|
||||||
|
|
||||||
Function &F = *DF.getRoot()->getParent();
|
Function &F = *DF.getRoot()->getParent();
|
||||||
|
VersionNumbers.resize(Allocas.size());
|
||||||
|
|
||||||
for (unsigned i = 0, e = Allocas.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Allocas.size(); i != e; ++i) {
|
||||||
assert(isAllocaPromotable(Allocas[i], TD) &&
|
assert(isAllocaPromotable(Allocas[i], TD) &&
|
||||||
@@ -118,19 +121,23 @@ void PromoteMem2Reg::run() {
|
|||||||
for (unsigned j = 0; j != WriteSets[i].size(); j++) {
|
for (unsigned j = 0; j != WriteSets[i].size(); j++) {
|
||||||
// Look up the DF for this write, add it to PhiNodes
|
// Look up the DF for this write, add it to PhiNodes
|
||||||
DominanceFrontier::const_iterator it = DF.find(WriteSets[i][j]);
|
DominanceFrontier::const_iterator it = DF.find(WriteSets[i][j]);
|
||||||
DominanceFrontier::DomSetType S = it->second;
|
if (it != DF.end()) {
|
||||||
for (DominanceFrontier::DomSetType::iterator P = S.begin(), PE = S.end();
|
const DominanceFrontier::DomSetType &S = it->second;
|
||||||
P != PE; ++P)
|
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
|
||||||
QueuePhiNode(*P, i);
|
P != PE; ++P)
|
||||||
|
QueuePhiNode(*P, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform iterative step
|
// Perform iterative step
|
||||||
for (unsigned k = 0; k != PhiNodes[i].size(); k++) {
|
for (unsigned k = 0; k != PhiNodes[i].size(); k++) {
|
||||||
DominanceFrontier::const_iterator it = DF.find(PhiNodes[i][k]);
|
DominanceFrontier::const_iterator it = DF.find(PhiNodes[i][k]);
|
||||||
DominanceFrontier::DomSetType S = it->second;
|
if (it != DF.end()) {
|
||||||
for (DominanceFrontier::DomSetType::iterator P = S.begin(), PE = S.end();
|
const DominanceFrontier::DomSetType &S = it->second;
|
||||||
P != PE; ++P)
|
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
|
||||||
QueuePhiNode(*P, i);
|
P != PE; ++P)
|
||||||
|
QueuePhiNode(*P, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +161,15 @@ void PromoteMem2Reg::run() {
|
|||||||
Instruction *I = KillList.back();
|
Instruction *I = KillList.back();
|
||||||
KillList.pop_back();
|
KillList.pop_back();
|
||||||
|
|
||||||
|
// If there are any uses of these instructions left, they must be in
|
||||||
|
// sections of dead code that were not processed on the dominance frontier.
|
||||||
|
// Just delete the users now.
|
||||||
|
//
|
||||||
|
while (!I->use_empty()) {
|
||||||
|
Instruction *U = cast<Instruction>(I->use_back());
|
||||||
|
U->getParent()->getInstList().erase(U);
|
||||||
|
}
|
||||||
|
|
||||||
I->getParent()->getInstList().erase(I);
|
I->getParent()->getInstList().erase(I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +189,8 @@ bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) {
|
|||||||
// 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
|
||||||
PHINode *PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(),
|
PHINode *PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(),
|
||||||
Allocas[AllocaNo]->getName()+".mem2reg",
|
Allocas[AllocaNo]->getName() + "." +
|
||||||
|
utostr(VersionNumbers[AllocaNo]++),
|
||||||
BB->begin());
|
BB->begin());
|
||||||
BBPNs[AllocaNo] = PN;
|
BBPNs[AllocaNo] = PN;
|
||||||
PhiNodes[AllocaNo].push_back(BB);
|
PhiNodes[AllocaNo].push_back(BB);
|
||||||
|
Reference in New Issue
Block a user