Skip to content

ARCCodeMotion: support bisecting individual optimized release-instructions when debugging this pass. #61979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions lib/SILOptimizer/Transforms/ARCCodeMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,15 +657,23 @@ class ReleaseBlockState : public BlockState {

/// ReleaseCodeMotionContext - Context to perform release code motion.
class ReleaseCodeMotionContext : public CodeMotionContext {
/// All the release block state for all the basic blocks in the function.
SILFunctionTransform *parentTransform;

/// All the release block state for all the basic blocks in the function.
BasicBlockData<ReleaseBlockState> BlockStates;

InstructionSet releaseInstructions;

/// We are not moving epilogue releases.
bool FreezeEpilogueReleases;

/// The epilogue release matcher we are currently using.
ConsumedArgToEpilogueReleaseMatcher &ERM;

bool isRelease(SILInstruction *inst) const {
return releaseInstructions.contains(inst);
}

/// Return true if the instruction blocks the Ptr to be moved further.
bool mayBlockCodeMotion(SILInstruction *II, SILValue Ptr) override {
// NOTE: If more checks are to be added, place the most expensive in the end.
Expand All @@ -677,7 +685,7 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
return true;
// Identical RC root blocks code motion, we will be able to move this release
// further once we move the blocking release.
if (isReleaseInstruction(II) && getRCRoot(II) == Ptr) {
if (isRelease(II) && getRCRoot(II) == Ptr) {
LLVM_DEBUG(if (printCtx) llvm::dbgs()
<< "Release " << Ptr << " at matching release " << *II);
return true;
Expand All @@ -698,19 +706,23 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
if (&*I->getParent()->begin() == I)
return nullptr;
auto Prev = &*std::prev(SILBasicBlock::iterator(I));
if (isReleaseInstruction(Prev) && getRCRoot(Prev) == Root)
if (isRelease(Prev) && getRCRoot(Prev) == Root)
return Prev;
return nullptr;
}

public:
/// Constructor.
ReleaseCodeMotionContext(llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
ReleaseCodeMotionContext(SILFunctionTransform *parentTransform,
llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
SILFunction *F, PostOrderFunctionInfo *PO,
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI,
bool FreezeEpilogueReleases,
ConsumedArgToEpilogueReleaseMatcher &ERM)
: CodeMotionContext(BPA, F, PO, AA, RCFI), BlockStates(F),
: CodeMotionContext(BPA, F, PO, AA, RCFI),
parentTransform(parentTransform),
BlockStates(F),
releaseInstructions(F),
FreezeEpilogueReleases(FreezeEpilogueReleases), ERM(ERM) {}

/// virtual destructor.
Expand Down Expand Up @@ -781,6 +793,9 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
// Do not try to enumerate if we are not hoisting epilogue releases.
if (FreezeEpilogueReleases && ERM.isEpilogueRelease(&II))
continue;
if (!parentTransform->continueWithNextSubpassRun(&II))
continue;
releaseInstructions.insert(&II);
SILValue Root = getRCRoot(&II);
RCInstructions.insert(&II);
if (RCRootIndex.find(Root) != RCRootIndex.end())
Expand Down Expand Up @@ -831,7 +846,7 @@ void ReleaseCodeMotionContext::initializeCodeMotionBBMaxSet() {
// NOTE: this is a conservative approximation, because some releases may be
// blocked before it reaches this block.
for (auto II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) {
if (!isReleaseInstruction(&*II))
if (!isRelease(&*II))
continue;
State.BBMaxSet.set(RCRootIndex[getRCRoot(&*II)]);
}
Expand Down Expand Up @@ -859,7 +874,7 @@ void ReleaseCodeMotionContext::computeCodeMotionGenKillSet() {
continue;

// If this is a release instruction, it also generates.
if (isReleaseInstruction(&*I)) {
if (isRelease(&*I)) {
unsigned idx = RCRootIndex[getRCRoot(&*I)];
State.BBGenSet.set(idx);
assert(State.BBKillSet.test(idx) && "Killset computed incorrectly");
Expand Down Expand Up @@ -1049,7 +1064,7 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
continue;

// This release generates.
if (isReleaseInstruction(&*I)) {
if (isRelease(&*I)) {
S.BBSetOut.set(RCRootIndex[getRCRoot(&*I)]);
}
}
Expand Down Expand Up @@ -1201,7 +1216,7 @@ class ARCCodeMotion : public SILFunctionTransform {
Conv,
ConsumedArgToEpilogueReleaseMatcher::ExitKind::Return);

ReleaseCodeMotionContext RelCM(BPA, F, PO, AA, RCFI,
ReleaseCodeMotionContext RelCM(this, BPA, F, PO, AA, RCFI,
FreezeEpilogueReleases, ERM);
// Run release hoisting.
InstChanged |= RelCM.run();
Expand Down