mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
modernize this pass a bit: use efficient set/map and reduce indentation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112404 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -217,7 +217,7 @@ namespace {
|
|||||||
///
|
///
|
||||||
void FindPromotableValuesInLoop(
|
void FindPromotableValuesInLoop(
|
||||||
std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
|
std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
|
||||||
std::map<Value*, AllocaInst*> &Val2AlMap);
|
DenseMap<Value*, AllocaInst*> &Val2AlMap);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,21 +520,22 @@ void LICM::sink(Instruction &I) {
|
|||||||
if (PHINode *UPN = dyn_cast<PHINode>(U)) {
|
if (PHINode *UPN = dyn_cast<PHINode>(U)) {
|
||||||
// Only insert into each predecessor once, so that we don't have
|
// Only insert into each predecessor once, so that we don't have
|
||||||
// different incoming values from the same block!
|
// different incoming values from the same block!
|
||||||
std::map<BasicBlock*, Value*> InsertedBlocks;
|
DenseMap<BasicBlock*, Value*> InsertedBlocks;
|
||||||
for (unsigned i = 0, e = UPN->getNumIncomingValues(); i != e; ++i)
|
for (unsigned i = 0, e = UPN->getNumIncomingValues(); i != e; ++i) {
|
||||||
if (UPN->getIncomingValue(i) == &I) {
|
if (UPN->getIncomingValue(i) != &I) continue;
|
||||||
BasicBlock *Pred = UPN->getIncomingBlock(i);
|
|
||||||
Value *&PredVal = InsertedBlocks[Pred];
|
BasicBlock *Pred = UPN->getIncomingBlock(i);
|
||||||
if (!PredVal) {
|
Value *&PredVal = InsertedBlocks[Pred];
|
||||||
// Insert a new load instruction right before the terminator in
|
if (!PredVal) {
|
||||||
// the predecessor block.
|
// Insert a new load instruction right before the terminator in
|
||||||
PredVal = new LoadInst(AI, "", Pred->getTerminator());
|
// the predecessor block.
|
||||||
CurAST->add(cast<LoadInst>(PredVal));
|
PredVal = new LoadInst(AI, "", Pred->getTerminator());
|
||||||
}
|
CurAST->add(cast<LoadInst>(PredVal));
|
||||||
|
|
||||||
UPN->setIncomingValue(i, PredVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UPN->setIncomingValue(i, PredVal);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LoadInst *L = new LoadInst(AI, "", U);
|
LoadInst *L = new LoadInst(AI, "", U);
|
||||||
U->replaceUsesOfWith(&I, L);
|
U->replaceUsesOfWith(&I, L);
|
||||||
@ -546,38 +547,40 @@ void LICM::sink(Instruction &I) {
|
|||||||
// that is dominated by the instruction, storing the result into the memory
|
// that is dominated by the instruction, storing the result into the memory
|
||||||
// location. Be careful not to insert the instruction into any particular
|
// location. Be careful not to insert the instruction into any particular
|
||||||
// basic block more than once.
|
// basic block more than once.
|
||||||
std::set<BasicBlock*> InsertedBlocks;
|
SmallPtrSet<BasicBlock*, 16> InsertedBlocks;
|
||||||
BasicBlock *InstOrigBB = I.getParent();
|
BasicBlock *InstOrigBB = I.getParent();
|
||||||
|
|
||||||
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
|
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
|
||||||
BasicBlock *ExitBlock = ExitBlocks[i];
|
BasicBlock *ExitBlock = ExitBlocks[i];
|
||||||
|
|
||||||
if (isExitBlockDominatedByBlockInLoop(ExitBlock, InstOrigBB)) {
|
if (!isExitBlockDominatedByBlockInLoop(ExitBlock, InstOrigBB))
|
||||||
// If we haven't already processed this exit block, do so now.
|
continue;
|
||||||
if (InsertedBlocks.insert(ExitBlock).second) {
|
|
||||||
// Insert the code after the last PHI node...
|
// If we haven't already processed this exit block, do so now.
|
||||||
BasicBlock::iterator InsertPt = ExitBlock->getFirstNonPHI();
|
if (!InsertedBlocks.insert(ExitBlock))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Insert the code after the last PHI node...
|
||||||
|
BasicBlock::iterator InsertPt = ExitBlock->getFirstNonPHI();
|
||||||
|
|
||||||
// If this is the first exit block processed, just move the original
|
// If this is the first exit block processed, just move the original
|
||||||
// instruction, otherwise clone the original instruction and insert
|
// instruction, otherwise clone the original instruction and insert
|
||||||
// the copy.
|
// the copy.
|
||||||
Instruction *New;
|
Instruction *New;
|
||||||
if (InsertedBlocks.size() == 1) {
|
if (InsertedBlocks.size() == 1) {
|
||||||
I.removeFromParent();
|
I.removeFromParent();
|
||||||
ExitBlock->getInstList().insert(InsertPt, &I);
|
ExitBlock->getInstList().insert(InsertPt, &I);
|
||||||
New = &I;
|
New = &I;
|
||||||
} else {
|
} else {
|
||||||
New = I.clone();
|
New = I.clone();
|
||||||
CurAST->copyValue(&I, New);
|
CurAST->copyValue(&I, New);
|
||||||
if (!I.getName().empty())
|
if (!I.getName().empty())
|
||||||
New->setName(I.getName()+".le");
|
New->setName(I.getName()+".le");
|
||||||
ExitBlock->getInstList().insert(InsertPt, New);
|
ExitBlock->getInstList().insert(InsertPt, New);
|
||||||
}
|
|
||||||
|
|
||||||
// Now that we have inserted the instruction, store it into the alloca
|
|
||||||
if (AI) new StoreInst(New, AI, InsertPt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now that we have inserted the instruction, store it into the alloca
|
||||||
|
if (AI) new StoreInst(New, AI, InsertPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the instruction doesn't dominate any exit blocks, it must be dead.
|
// If the instruction doesn't dominate any exit blocks, it must be dead.
|
||||||
@ -660,7 +663,7 @@ void LICM::PromoteValuesInLoop() {
|
|||||||
// value has an alloca instruction for it, and a canonical version of the
|
// value has an alloca instruction for it, and a canonical version of the
|
||||||
// pointer.
|
// pointer.
|
||||||
std::vector<std::pair<AllocaInst*, Value*> > PromotedValues;
|
std::vector<std::pair<AllocaInst*, Value*> > PromotedValues;
|
||||||
std::map<Value*, AllocaInst*> ValueToAllocaMap; // Map of ptr to alloca
|
DenseMap<Value*, AllocaInst*> ValueToAllocaMap; // Map of ptr to alloca
|
||||||
|
|
||||||
FindPromotableValuesInLoop(PromotedValues, ValueToAllocaMap);
|
FindPromotableValuesInLoop(PromotedValues, ValueToAllocaMap);
|
||||||
if (ValueToAllocaMap.empty()) return; // If there are values to promote.
|
if (ValueToAllocaMap.empty()) return; // If there are values to promote.
|
||||||
@ -717,12 +720,12 @@ void LICM::PromoteValuesInLoop() {
|
|||||||
// Rewrite all loads and stores in the block of the pointer...
|
// Rewrite all loads and stores in the block of the pointer...
|
||||||
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) {
|
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) {
|
||||||
if (LoadInst *L = dyn_cast<LoadInst>(II)) {
|
if (LoadInst *L = dyn_cast<LoadInst>(II)) {
|
||||||
std::map<Value*, AllocaInst*>::iterator
|
DenseMap<Value*, AllocaInst*>::iterator
|
||||||
I = ValueToAllocaMap.find(L->getOperand(0));
|
I = ValueToAllocaMap.find(L->getOperand(0));
|
||||||
if (I != ValueToAllocaMap.end())
|
if (I != ValueToAllocaMap.end())
|
||||||
L->setOperand(0, I->second); // Rewrite load instruction...
|
L->setOperand(0, I->second); // Rewrite load instruction...
|
||||||
} else if (StoreInst *S = dyn_cast<StoreInst>(II)) {
|
} else if (StoreInst *S = dyn_cast<StoreInst>(II)) {
|
||||||
std::map<Value*, AllocaInst*>::iterator
|
DenseMap<Value*, AllocaInst*>::iterator
|
||||||
I = ValueToAllocaMap.find(S->getOperand(1));
|
I = ValueToAllocaMap.find(S->getOperand(1));
|
||||||
if (I != ValueToAllocaMap.end())
|
if (I != ValueToAllocaMap.end())
|
||||||
S->setOperand(1, I->second); // Rewrite store instruction...
|
S->setOperand(1, I->second); // Rewrite store instruction...
|
||||||
@ -778,7 +781,7 @@ void LICM::PromoteValuesInLoop() {
|
|||||||
/// alloca.
|
/// alloca.
|
||||||
void LICM::FindPromotableValuesInLoop(
|
void LICM::FindPromotableValuesInLoop(
|
||||||
std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
|
std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
|
||||||
std::map<Value*, AllocaInst*> &ValueToAllocaMap) {
|
DenseMap<Value*, AllocaInst*> &ValueToAllocaMap) {
|
||||||
Instruction *FnStart = CurLoop->getHeader()->getParent()->begin()->begin();
|
Instruction *FnStart = CurLoop->getHeader()->getParent()->begin()->begin();
|
||||||
|
|
||||||
// Loop over all of the alias sets in the tracker object.
|
// Loop over all of the alias sets in the tracker object.
|
||||||
@ -855,7 +858,7 @@ void LICM::FindPromotableValuesInLoop(
|
|||||||
CurAST->copyValue(V, AI);
|
CurAST->copyValue(V, AI);
|
||||||
|
|
||||||
for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I)
|
for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I)
|
||||||
ValueToAllocaMap.insert(std::make_pair(I->getValue(), AI));
|
ValueToAllocaMap[I->getValue()] = AI;
|
||||||
|
|
||||||
DEBUG(dbgs() << "LICM: Promoting value: " << *V << "\n");
|
DEBUG(dbgs() << "LICM: Promoting value: " << *V << "\n");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user