switch an std::set over to SmallPtrSet, speeding up mem2reg 3.4% on 176.gcc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33928 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-02-05 22:13:11 +00:00
parent 40b6555561
commit c837615cf0

View File

@ -23,6 +23,7 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
@ -114,7 +115,7 @@ namespace {
private: private:
void MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum, void MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
std::set<PHINode*> &DeadPHINodes); SmallPtrSet<PHINode*, 16> &DeadPHINodes);
bool PromoteLocallyUsedAlloca(BasicBlock *BB, AllocaInst *AI); bool PromoteLocallyUsedAlloca(BasicBlock *BB, AllocaInst *AI);
void PromoteLocallyUsedAllocas(BasicBlock *BB, void PromoteLocallyUsedAllocas(BasicBlock *BB,
const std::vector<AllocaInst*> &AIs); const std::vector<AllocaInst*> &AIs);
@ -122,7 +123,7 @@ namespace {
void RenamePass(BasicBlock *BB, BasicBlock *Pred, void RenamePass(BasicBlock *BB, BasicBlock *Pred,
std::vector<Value*> &IncVals); std::vector<Value*> &IncVals);
bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version, bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version,
std::set<PHINode*> &InsertedPHINodes); SmallPtrSet<PHINode*, 16> &InsertedPHINodes);
}; };
} // end of anonymous namespace } // end of anonymous namespace
@ -270,7 +271,7 @@ void PromoteMem2Reg::run() {
// dominance frontier of EACH basic-block we have a write in. // dominance frontier of EACH basic-block we have a write in.
// //
unsigned CurrentVersion = 0; unsigned CurrentVersion = 0;
std::set<PHINode*> InsertedPHINodes; SmallPtrSet<PHINode*, 16> InsertedPHINodes;
std::vector<unsigned> DFBlocks; std::vector<unsigned> DFBlocks;
while (!DefiningBlocks.empty()) { while (!DefiningBlocks.empty()) {
BasicBlock *BB = DefiningBlocks.back(); BasicBlock *BB = DefiningBlocks.back();
@ -314,7 +315,7 @@ void PromoteMem2Reg::run() {
UsingBlocks.clear(); UsingBlocks.clear();
// If there are any PHI nodes which are now known to be dead, remove them! // If there are any PHI nodes which are now known to be dead, remove them!
for (std::set<PHINode*>::iterator I = InsertedPHINodes.begin(), for (SmallPtrSet<PHINode*, 16>::iterator I = InsertedPHINodes.begin(),
E = InsertedPHINodes.end(); I != E; ++I) { E = InsertedPHINodes.end(); I != E; ++I) {
PHINode *PN = *I; PHINode *PN = *I;
std::vector<PHINode*> &BBPNs = NewPhiNodes[PN->getParent()]; std::vector<PHINode*> &BBPNs = NewPhiNodes[PN->getParent()];
@ -408,7 +409,7 @@ void PromoteMem2Reg::run() {
for (unsigned i = 0, e = PNs.size(); i != e; ++i) { for (unsigned i = 0, e = PNs.size(); i != e; ++i) {
if (!PNs[i]) continue; if (!PNs[i]) continue;
// 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.
if (Value *V = PNs[i]->hasConstantValue(true)) { if (Value *V = PNs[i]->hasConstantValue(true)) {
if (!isa<Instruction>(V) || if (!isa<Instruction>(V) ||
properlyDominates(cast<Instruction>(V), PNs[i])) { properlyDominates(cast<Instruction>(V), PNs[i])) {
@ -426,8 +427,8 @@ void PromoteMem2Reg::run() {
} }
// At this point, the renamer has added entries to PHI nodes for all reachable // At this point, the renamer has added entries to PHI nodes for all reachable
// code. Unfortunately, there may be blocks which are not reachable, which // code. Unfortunately, there may be unreachable blocks which the renamer
// the renamer hasn't traversed. If this is the case, the PHI nodes may not // hasn't traversed. If this is the case, the PHI nodes may not
// 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.
// //
@ -488,7 +489,7 @@ void PromoteMem2Reg::run() {
// DeadPHINodes set are removed. // DeadPHINodes set are removed.
// //
void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum, void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
std::set<PHINode*> &DeadPHINodes) { SmallPtrSet<PHINode*, 16> &DeadPHINodes) {
// Scan the immediate dominators of this block looking for a block which has a // Scan the immediate dominators of this block looking for a block which has a
// PHI node for Alloca num. If we find it, mark the PHI node as being alive! // PHI node for Alloca num. If we find it, mark the PHI node as being alive!
for (DominatorTree::Node *N = DT[BB]; N; N = N->getIDom()) { for (DominatorTree::Node *N = DT[BB]; N; N = N->getIDom()) {
@ -499,13 +500,9 @@ void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
// Ok, we found an inserted PHI node which dominates this value. // Ok, we found an inserted PHI node which dominates this value.
PHINode *DominatingPHI = I->second[AllocaNum]; PHINode *DominatingPHI = I->second[AllocaNum];
// Find out if we previously thought it was dead. // Find out if we previously thought it was dead. If so, mark it as being
std::set<PHINode*>::iterator DPNI = DeadPHINodes.find(DominatingPHI); // live by removing it from the DeadPHINodes set.
if (DPNI != DeadPHINodes.end()) { if (DeadPHINodes.erase(DominatingPHI)) {
// Ok, until now, we thought this PHI node was dead. Mark it as being
// alive/needed.
DeadPHINodes.erase(DPNI);
// Now that we have marked the PHI node alive, also mark any PHI nodes // Now that we have marked the PHI node alive, also mark any PHI nodes
// which it might use as being alive as well. // which it might use as being alive as well.
for (pred_iterator PI = pred_begin(DomBB), PE = pred_end(DomBB); for (pred_iterator PI = pred_begin(DomBB), PE = pred_end(DomBB);
@ -633,7 +630,7 @@ PromoteLocallyUsedAllocas(BasicBlock *BB, const std::vector<AllocaInst*> &AIs) {
// //
bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo, bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo,
unsigned &Version, unsigned &Version,
std::set<PHINode*> &InsertedPHINodes) { SmallPtrSet<PHINode*, 16> &InsertedPHINodes) {
// Look up the basic-block in question. // Look up the basic-block in question.
std::vector<PHINode*> &BBPNs = NewPhiNodes[BB]; std::vector<PHINode*> &BBPNs = NewPhiNodes[BB];
if (BBPNs.empty()) BBPNs.resize(Allocas.size()); if (BBPNs.empty()) BBPNs.resize(Allocas.size());