mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
Two small cleanups/speedups:
* Do not insert a new entry into NewPhiNodes during the rename pass if there are no PHIs in a block. * Do not compute WriteSets in parallel git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8858 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0fa157127f
commit
9157f041ab
@ -93,26 +93,24 @@ void PromoteMem2Reg::run() {
|
|||||||
AllocaLookup[Allocas[i]] = i;
|
AllocaLookup[Allocas[i]] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the set of write-locations for each alloca. This is analogous to
|
PhiNodes.resize(Allocas.size());
|
||||||
// counting the number of 'redefinitions' of each variable.
|
|
||||||
std::vector<std::vector<BasicBlock*> > WriteSets;// Idx corresponds to Allocas
|
|
||||||
WriteSets.resize(Allocas.size());
|
|
||||||
for (unsigned i = 0; i != Allocas.size(); ++i) {
|
for (unsigned i = 0; i != Allocas.size(); ++i) {
|
||||||
AllocaInst *AI = Allocas[i];
|
AllocaInst *AI = Allocas[i];
|
||||||
|
|
||||||
|
// Calculate the set of write-locations for each alloca. This is analogous
|
||||||
|
// to counting the number of 'redefinitions' of each variable.
|
||||||
|
std::vector<BasicBlock*> WriteSets;
|
||||||
for (Value::use_iterator U =AI->use_begin(), E = AI->use_end(); U != E; ++U)
|
for (Value::use_iterator U =AI->use_begin(), E = AI->use_end(); U != E; ++U)
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(*U))
|
if (StoreInst *SI = dyn_cast<StoreInst>(*U))
|
||||||
// jot down the basic-block it came from
|
// jot down the basic-block it came from
|
||||||
WriteSets[i].push_back(SI->getParent());
|
WriteSets.push_back(SI->getParent());
|
||||||
}
|
|
||||||
|
// Compute the locations where PhiNodes need to be inserted. Look at the
|
||||||
// Compute the locations where PhiNodes need to be inserted. Look at the
|
// dominance frontier of EACH basic-block we have a write in.
|
||||||
// dominance frontier of EACH basic-block we have a write in
|
//
|
||||||
//
|
for (unsigned j = 0; j != WriteSets.size(); j++) {
|
||||||
PhiNodes.resize(Allocas.size());
|
|
||||||
for (unsigned i = 0; i != Allocas.size(); ++i) {
|
|
||||||
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[j]);
|
||||||
if (it != DF.end()) {
|
if (it != DF.end()) {
|
||||||
const DominanceFrontier::DomSetType &S = it->second;
|
const DominanceFrontier::DomSetType &S = it->second;
|
||||||
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
|
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
|
||||||
@ -200,22 +198,26 @@ bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) {
|
|||||||
|
|
||||||
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
|
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
|
||||||
std::vector<Value*> &IncomingVals) {
|
std::vector<Value*> &IncomingVals) {
|
||||||
// If this is a BB needing a phi node, lookup/create the phinode for each
|
// If this BB needs a PHI node, update the PHI node for each variable we need
|
||||||
// variable we need phinodes for.
|
// PHI nodes for.
|
||||||
std::vector<PHINode *> &BBPNs = NewPhiNodes[BB];
|
std::map<BasicBlock*, std::vector<PHINode *> >::iterator
|
||||||
for (unsigned k = 0; k != BBPNs.size(); ++k)
|
BBPNI = NewPhiNodes.find(BB);
|
||||||
if (PHINode *PN = BBPNs[k]) {
|
if (BBPNI != NewPhiNodes.end()) {
|
||||||
// The PHI node may have multiple entries for this predecessor. We must
|
std::vector<PHINode *> &BBPNs = BBPNI->second;
|
||||||
// make sure we update all of them.
|
for (unsigned k = 0; k != BBPNs.size(); ++k)
|
||||||
for (unsigned i = 0, e = PN->getNumOperands(); i != e; i += 2) {
|
if (PHINode *PN = BBPNs[k]) {
|
||||||
if (PN->getOperand(i+1) == Pred)
|
// The PHI node may have multiple entries for this predecessor. We must
|
||||||
// At this point we can assume that the array has phi nodes.. let's
|
// make sure we update all of them.
|
||||||
// update the incoming data.
|
for (unsigned i = 0, e = PN->getNumOperands(); i != e; i += 2) {
|
||||||
PN->setOperand(i, IncomingVals[k]);
|
if (PN->getOperand(i+1) == Pred)
|
||||||
|
// At this point we can assume that the array has phi nodes.. let's
|
||||||
|
// update the incoming data.
|
||||||
|
PN->setOperand(i, IncomingVals[k]);
|
||||||
|
}
|
||||||
|
// also note that the active variable IS designated by the phi node
|
||||||
|
IncomingVals[k] = PN;
|
||||||
}
|
}
|
||||||
// also note that the active variable IS designated by the phi node
|
}
|
||||||
IncomingVals[k] = PN;
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't revisit nodes
|
// don't revisit nodes
|
||||||
if (Visited.count(BB)) return;
|
if (Visited.count(BB)) return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user