Skip to content

Commit

Permalink
[loop-arc] Teach ARC how to summarize subregions but do not wire it u…
Browse files Browse the repository at this point in the history
…p to the analysis yet.

rdar://22238729
  • Loading branch information
gottesmm committed Nov 3, 2015
1 parent f7f1df4 commit e59bb8c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
56 changes: 50 additions & 6 deletions lib/SILAnalysis/ARC/ARCRegionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ ARCRegionState::ARCRegionState(LoopRegion *R)
AllowsLeaks = isARCInertTrapBB(R->getBlock());
}

//===---
// Utility
//

//===---
// Bottom Up Merge
//
Expand Down Expand Up @@ -160,7 +156,7 @@ void ARCRegionState::mergePredTopDown(ARCRegionState &PredRegionState) {
}

//===---
// Bottom Up Block Visitor
// Bottom Up Dataflow
//

bool ARCRegionState::processBlockBottomUp(
Expand Down Expand Up @@ -243,7 +239,7 @@ bool ARCRegionState::processBottomUp(
}

//===---
// Top Down Block Visitor
// Top Down Dataflow
//

bool ARCRegionState::processBlockTopDown(
Expand Down Expand Up @@ -327,3 +323,51 @@ bool ARCRegionState::processTopDown(

return processBlockTopDown(*R->getBlock(), AA, RCIA, DecToIncStateMap);
}

//===---
// Summary
//

void ARCRegionState::summarizeBlock(SILBasicBlock *BB) {
SummarizedInterestingInsts.clear();

for (auto &I : *BB)
if (!canNeverUseValues(&I) || !canNeverDecrementRefCounts(&I))
SummarizedInterestingInsts.push_back(&I);
}

void ARCRegionState::summarizeLoop(
const LoopRegion *R, LoopRegionFunctionInfo *LRFI,
llvm::DenseMap<const LoopRegion *, ARCRegionState *> &RegionStateInfo) {
SummarizedInterestingInsts.clear();
for (unsigned SubregionID : R->getSubregions()) {
LoopRegion *Subregion = LRFI->getRegion(SubregionID);
ARCRegionState *SubregionState = RegionStateInfo[Subregion];
std::copy(SubregionState->summarizedinterestinginsts_begin(),
SubregionState->summarizedinterestinginsts_end(),
std::back_inserter(SummarizedInterestingInsts));
}
}

void ARCRegionState::summarize(
LoopRegionFunctionInfo *LRFI,
llvm::DenseMap<const LoopRegion *, ARCRegionState *> &RegionStateInfo) {
const LoopRegion *R = getRegion();

// We do not need to summarize a function since it is the outermost loop.
if (R->isFunction())
return;

assert(R->isLoop() && "Expected to be called on a loop");
// Make sure that all subregions that are blocked are summarized. We know that
// all subloops have already been summarized.
for (unsigned SubregionID : R->getSubregions()) {
auto *Subregion = LRFI->getRegion(SubregionID);
if (!Subregion->isBlock())
continue;
auto *SubregionState = RegionStateInfo[Subregion];
SubregionState->summarizeBlock(Subregion->getBlock());
}

summarizeLoop(R, LRFI, RegionStateInfo);
}
34 changes: 34 additions & 0 deletions lib/SILAnalysis/ARC/ARCRegionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class ARCRegionState {
/// advantage of this to ignore control flow.
bool AllowsLeaks;

/// A list of instructions contained in this region that can either use or
/// decrement reference counts.
///
/// This is flow insensitive since we just add all of the potential
/// users/decrements in subregions without caring if there is only one along a
/// path. This is for simplicity in the first iteration.
///
/// TODO: This needs a better name.
llvm::SmallVector<SILInstruction *, 4> SummarizedInterestingInsts;

public:
ARCRegionState(LoopRegion *R);

Expand Down Expand Up @@ -119,6 +129,22 @@ class ARCRegionState {
clearBottomUpState();
}

using const_summarizedinterestinginsts_iterator =
decltype(SummarizedInterestingInsts)::const_iterator;
const_summarizedinterestinginsts_iterator
summarizedinterestinginsts_begin() const {
return SummarizedInterestingInsts.begin();
}
const_summarizedinterestinginsts_iterator
summarizedinterestinginsts_end() const {
return SummarizedInterestingInsts.end();
}
iterator_range<const_summarizedinterestinginsts_iterator>
getSummarizedDecrements() const {
return {summarizedinterestinginsts_begin(),
summarizedinterestinginsts_end()};
}

/// Returns a reference to the basic block that we are tracking.
const LoopRegion *getRegion() const { return Region.get(); }

Expand Down Expand Up @@ -158,6 +184,10 @@ class ARCRegionState {
ConsumedArgToEpilogueReleaseMatcher &ConsumedArgToReleaseMap,
BlotMapVector<SILInstruction *, BottomUpRefCountState> &IncToDecStateMap);

void summarize(
LoopRegionFunctionInfo *LRFI,
llvm::DenseMap<const LoopRegion *, ARCRegionState *> &RegionStateInfo);

private:
bool processBlockBottomUp(
SILBasicBlock &BB, AliasAnalysis *AA, RCIdentityFunctionInfo *RCIA,
Expand All @@ -172,6 +202,10 @@ class ARCRegionState {
BlotMapVector<SILInstruction *, TopDownRefCountState> &DecToIncStateMap);
bool processLoopTopDown();

void summarizeBlock(SILBasicBlock *BB);
void summarizeLoop(
const LoopRegion *R, LoopRegionFunctionInfo *LRFI,
llvm::DenseMap<const LoopRegion *, ARCRegionState *> &RegionStateInfo);
};

} // end swift namespace
Expand Down
1 change: 1 addition & 0 deletions lib/SILAnalysis/ARC/GlobalLoopARCSequenceDataflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ bool LoopARCSequenceDataflowEvaluator::runOnLoop(
const LoopRegion *R, bool FreezeOwnedArgEpilogueReleases) {
bool NestingDetected = processLoopBottomUp(R, FreezeOwnedArgEpilogueReleases);
NestingDetected |= processLoopTopDown(R);
RegionStateInfo[R]->summarize(LRFI, RegionStateInfo);
return NestingDetected;
}

Expand Down

0 comments on commit e59bb8c

Please sign in to comment.