mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-27 12:26:08 +00:00
Rework r58829, allowing removal of dbg info intrinsics during alloca
promotion. - Eliminate uses after free and simplify tests. Devang: Please check that this is still doing what you intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58887 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -80,19 +80,12 @@ bool llvm::isAllocaPromotable(const AllocaInst *AI) {
|
|||||||
return false; // Don't allow a store OF the AI, only INTO the AI.
|
return false; // Don't allow a store OF the AI, only INTO the AI.
|
||||||
if (SI->isVolatile())
|
if (SI->isVolatile())
|
||||||
return false;
|
return false;
|
||||||
|
} else if (const BitCastInst *BC = dyn_cast<BitCastInst>(*UI)) {
|
||||||
|
// Uses by dbg info shouldn't inhibit promotion.
|
||||||
|
if (!BC->hasOneUse() || !isa<DbgInfoIntrinsic>(*BC->use_begin()))
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const BitCastInst *BC = dyn_cast<BitCastInst>(*UI);
|
return false;
|
||||||
if (!BC)
|
|
||||||
return false; // Not a load or store or dbg intrinsic.
|
|
||||||
Value::use_const_iterator BCUI = BC->use_begin(), BCUE = BC->use_end();
|
|
||||||
if (BCUI == BCUE)
|
|
||||||
return false; // Not a dbg intrinsic.
|
|
||||||
const DbgInfoIntrinsic *DI = dyn_cast<DbgInfoIntrinsic>(*BCUI);
|
|
||||||
if (!DI)
|
|
||||||
return false; // Not a dbg intrinsic.
|
|
||||||
BCUI++;
|
|
||||||
if (BCUI != BCUE)
|
|
||||||
return false; // Not a dbg intrinsic use.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -284,6 +277,21 @@ namespace {
|
|||||||
AllocaPointerVal = 0;
|
AllocaPointerVal = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// RemoveDebugUses - Remove uses of the alloca in DbgInfoInstrinsics.
|
||||||
|
void RemoveDebugUses(AllocaInst *AI) {
|
||||||
|
for (Value::use_iterator U = AI->use_begin(), E = AI->use_end();
|
||||||
|
U != E;) {
|
||||||
|
Instruction *User = cast<Instruction>(*U);
|
||||||
|
++U;
|
||||||
|
if (BitCastInst *BC = dyn_cast<BitCastInst>(User)) {
|
||||||
|
assert(BC->hasOneUse() && "Unexpected alloca uses!");
|
||||||
|
DbgInfoIntrinsic *DI = cast<DbgInfoIntrinsic>(*BC->use_begin());
|
||||||
|
DI->eraseFromParent();
|
||||||
|
BC->eraseFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// AnalyzeAlloca - Scan the uses of the specified alloca, filling in our
|
/// AnalyzeAlloca - Scan the uses of the specified alloca, filling in our
|
||||||
/// ivars.
|
/// ivars.
|
||||||
void AnalyzeAlloca(AllocaInst *AI) {
|
void AnalyzeAlloca(AllocaInst *AI) {
|
||||||
@@ -295,14 +303,7 @@ namespace {
|
|||||||
for (Value::use_iterator U = AI->use_begin(), E = AI->use_end();
|
for (Value::use_iterator U = AI->use_begin(), E = AI->use_end();
|
||||||
U != E; ++U) {
|
U != E; ++U) {
|
||||||
Instruction *User = cast<Instruction>(*U);
|
Instruction *User = cast<Instruction>(*U);
|
||||||
if (BitCastInst *BC = dyn_cast<BitCastInst>(User)) {
|
if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
|
||||||
// Remove dbg intrinsic uses now.
|
|
||||||
Value::use_iterator BCUI = BC->use_begin();
|
|
||||||
DbgInfoIntrinsic *DI = cast<DbgInfoIntrinsic>(*BCUI);
|
|
||||||
assert (next(BCUI) == BC->use_end() && "Unexpected alloca uses!");
|
|
||||||
DI->eraseFromParent();
|
|
||||||
BC->eraseFromParent();
|
|
||||||
} else if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
|
|
||||||
// Remember the basic blocks which define new values for the alloca
|
// Remember the basic blocks which define new values for the alloca
|
||||||
DefiningBlocks.push_back(SI->getParent());
|
DefiningBlocks.push_back(SI->getParent());
|
||||||
AllocaPointerVal = SI->getOperand(0);
|
AllocaPointerVal = SI->getOperand(0);
|
||||||
@@ -343,6 +344,9 @@ void PromoteMem2Reg::run() {
|
|||||||
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!");
|
||||||
|
|
||||||
|
// Remove any uses of this alloca in DbgInfoInstrinsics.
|
||||||
|
Info.RemoveDebugUses(AI);
|
||||||
|
|
||||||
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);
|
||||||
|
Reference in New Issue
Block a user