mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-18 10:24:45 +00:00
When promoting an alloca to registers discard any lifetime intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133251 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -73,6 +73,22 @@ struct DenseMapInfo<std::pair<BasicBlock*, unsigned> > {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// onlyUsedByLifetimeMarkers - Return true if the only users of this pointer
|
||||||
|
/// are lifetime markers.
|
||||||
|
///
|
||||||
|
static bool onlyUsedByLifetimeMarkers(const Value *V) {
|
||||||
|
for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
|
||||||
|
UI != UE; ++UI) {
|
||||||
|
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(*UI);
|
||||||
|
if (!II) return false;
|
||||||
|
|
||||||
|
if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
|
||||||
|
II->getIntrinsicID() != Intrinsic::lifetime_end)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
@@ -92,6 +108,22 @@ 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 IntrinsicInst *II = dyn_cast<IntrinsicInst>(U)) {
|
||||||
|
if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
|
||||||
|
II->getIntrinsicID() != Intrinsic::lifetime_end)
|
||||||
|
return false;
|
||||||
|
} else if (const BitCastInst *BCI = dyn_cast<BitCastInst>(U)) {
|
||||||
|
if (BCI->getType() != Type::getInt8PtrTy(U->getContext()))
|
||||||
|
return false;
|
||||||
|
if (!onlyUsedByLifetimeMarkers(BCI))
|
||||||
|
return false;
|
||||||
|
} else if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(U)) {
|
||||||
|
if (GEPI->getType() != Type::getInt8PtrTy(U->getContext()))
|
||||||
|
return false;
|
||||||
|
if (!GEPI->hasAllZeroIndices())
|
||||||
|
return false;
|
||||||
|
if (!onlyUsedByLifetimeMarkers(GEPI))
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -335,6 +367,31 @@ namespace {
|
|||||||
};
|
};
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
|
static void removeLifetimeIntrinsicUsers(AllocaInst *AI) {
|
||||||
|
// Knowing that this alloca is promotable, we know that it's safe to kill all
|
||||||
|
// instructions except for load and store.
|
||||||
|
|
||||||
|
for (Value::use_iterator UI = AI->use_begin(), UE = AI->use_end();
|
||||||
|
UI != UE;) {
|
||||||
|
Instruction *I = cast<Instruction>(*UI);
|
||||||
|
++UI;
|
||||||
|
if (isa<LoadInst>(I) || isa<StoreInst>(I))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!I->getType()->isVoidTy()) {
|
||||||
|
// The only users of this bitcast/GEP instruction are lifetime intrinsics.
|
||||||
|
// Follow the use/def chain to erase them now instead of leaving it for
|
||||||
|
// dead code elimination later.
|
||||||
|
for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
|
||||||
|
UI != UE;) {
|
||||||
|
Instruction *Inst = cast<Instruction>(*UI);
|
||||||
|
++UI;
|
||||||
|
Inst->eraseFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
I->eraseFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PromoteMem2Reg::run() {
|
void PromoteMem2Reg::run() {
|
||||||
Function &F = *DT.getRoot()->getParent();
|
Function &F = *DT.getRoot()->getParent();
|
||||||
@@ -353,6 +410,8 @@ 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!");
|
||||||
|
|
||||||
|
removeLifetimeIntrinsicUsers(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