forked from OSchip/llvm-project
[Attributor] Do not update or manifest dead attributes
Summary: If the associated context instruction is assumed dead we do not need to update or manifest the state. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66116 llvm-svn: 368921
This commit is contained in:
parent
66214b581c
commit
9a1a1f96d9
|
@ -104,6 +104,7 @@ namespace llvm {
|
||||||
|
|
||||||
struct AbstractAttribute;
|
struct AbstractAttribute;
|
||||||
struct InformationCache;
|
struct InformationCache;
|
||||||
|
struct AAIsDead;
|
||||||
|
|
||||||
class Function;
|
class Function;
|
||||||
|
|
||||||
|
@ -652,6 +653,11 @@ struct Attributor {
|
||||||
void identifyDefaultAbstractAttributes(
|
void identifyDefaultAbstractAttributes(
|
||||||
Function &F, DenseSet<const char *> *Whitelist = nullptr);
|
Function &F, DenseSet<const char *> *Whitelist = nullptr);
|
||||||
|
|
||||||
|
/// Return true if \p AA (or its context instruction) is assumed dead.
|
||||||
|
///
|
||||||
|
/// If \p LivenessAA is not provided it is queried.
|
||||||
|
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA);
|
||||||
|
|
||||||
/// Check \p Pred on all function call sites.
|
/// Check \p Pred on all function call sites.
|
||||||
///
|
///
|
||||||
/// This method will evaluate \p Pred on call sites and return
|
/// This method will evaluate \p Pred on call sites and return
|
||||||
|
|
|
@ -1076,7 +1076,6 @@ AANonNullImpl::generatePredicate(Attributor &A) {
|
||||||
|
|
||||||
std::function<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)> Pred =
|
std::function<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)> Pred =
|
||||||
[&](Value &RV, const SmallPtrSetImpl<ReturnInst *> &RetInsts) -> bool {
|
[&](Value &RV, const SmallPtrSetImpl<ReturnInst *> &RetInsts) -> bool {
|
||||||
|
|
||||||
if (isKnownNonZero(&RV, A.getDataLayout()))
|
if (isKnownNonZero(&RV, A.getDataLayout()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -2143,6 +2142,23 @@ struct AANoReturnFunction final : AANoReturnImpl {
|
||||||
/// Attributor
|
/// Attributor
|
||||||
/// ----------------------------------------------------------------------------
|
/// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool Attributor::isAssumedDead(const AbstractAttribute &AA,
|
||||||
|
const AAIsDead *LivenessAA) {
|
||||||
|
const Instruction *CtxI = AA.getIRPosition().getCtxI();
|
||||||
|
if (!CtxI)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!LivenessAA)
|
||||||
|
LivenessAA =
|
||||||
|
getAAFor<AAIsDead>(AA, IRPosition::function(*CtxI->getFunction()));
|
||||||
|
if (!LivenessAA || !LivenessAA->isAssumedDead(CtxI))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: Do not track dependences automatically but add it here as only a
|
||||||
|
// "is-assumed-dead" result causes a dependence.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred,
|
bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred,
|
||||||
const AbstractAttribute &QueryingAA,
|
const AbstractAttribute &QueryingAA,
|
||||||
bool RequireAllCallSites) {
|
bool RequireAllCallSites) {
|
||||||
|
@ -2354,8 +2370,9 @@ ChangeStatus Attributor::run() {
|
||||||
// Update all abstract attribute in the work list and record the ones that
|
// Update all abstract attribute in the work list and record the ones that
|
||||||
// changed.
|
// changed.
|
||||||
for (AbstractAttribute *AA : Worklist)
|
for (AbstractAttribute *AA : Worklist)
|
||||||
if (AA->update(*this) == ChangeStatus::CHANGED)
|
if (!isAssumedDead(*AA, nullptr))
|
||||||
ChangedAAs.push_back(AA);
|
if (AA->update(*this) == ChangeStatus::CHANGED)
|
||||||
|
ChangedAAs.push_back(AA);
|
||||||
|
|
||||||
// Reset the work list and repopulate with the changed abstract attributes.
|
// Reset the work list and repopulate with the changed abstract attributes.
|
||||||
// Note that dependent ones are added above.
|
// Note that dependent ones are added above.
|
||||||
|
@ -2415,6 +2432,9 @@ ChangeStatus Attributor::run() {
|
||||||
if (!State.isValidState())
|
if (!State.isValidState())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Skip dead code.
|
||||||
|
if (isAssumedDead(*AA, nullptr))
|
||||||
|
continue;
|
||||||
// Manifest the state and record if we changed the IR.
|
// Manifest the state and record if we changed the IR.
|
||||||
ChangeStatus LocalChange = AA->manifest(*this);
|
ChangeStatus LocalChange = AA->manifest(*this);
|
||||||
if (LocalChange == ChangeStatus::CHANGED && AreStatisticsEnabled())
|
if (LocalChange == ChangeStatus::CHANGED && AreStatisticsEnabled())
|
||||||
|
|
Loading…
Reference in New Issue