Skip to content

Commit 944dfc3

Browse files
committed
Move code from initialize() to needFlatScratch() which is called
in updateImpl().
1 parent 0a739e9 commit 944dfc3

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -451,36 +451,6 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
451451
indicatePessimisticFixpoint();
452452
return;
453453
}
454-
455-
{ // FLAT_SCRATCH_INIT
456-
auto AddrSpaceCastNotFromPrivate = [&](Instruction &I) {
457-
return static_cast<AddrSpaceCastInst &>(I).getSrcAddressSpace() !=
458-
AMDGPUAS::PRIVATE_ADDRESS;
459-
};
460-
461-
bool UsedAssumedInformation = false;
462-
if (!A.checkForAllInstructions(AddrSpaceCastNotFromPrivate, *this,
463-
{Instruction::AddrSpaceCast},
464-
UsedAssumedInformation)) {
465-
// If there is AddrSpaceCast instruction that casts from PRIVATE_ADDRESS
466-
removeAssumedBits(FLAT_SCRATCH_INIT);
467-
return;
468-
}
469-
470-
auto &InfoCache = static_cast<AMDGPUInformationCache &>(A.getInfoCache());
471-
472-
for (Instruction &I : instructions(F)) {
473-
// check for addrSpaceCast from PRIVATE_ADDRESS in constant expressions
474-
for (const Use &U : I.operands()) {
475-
if (const auto *C = dyn_cast<Constant>(U)) {
476-
if (InfoCache.constHasASCastFromPrivate(C, *F)) {
477-
removeAssumedBits(FLAT_SCRATCH_INIT);
478-
return;
479-
}
480-
}
481-
}
482-
}
483-
}
484454
}
485455

486456
ChangeStatus updateImpl(Attributor &A) override {
@@ -734,6 +704,34 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
734704
bool needFlatScratchInit(Attributor &A) {
735705
assert(isAssumed(FLAT_SCRATCH_INIT)); // only called if the bit is still set
736706

707+
// Check all AddrSpaceCast instructions. FlatScratchInit is needed if
708+
// there is a cast from PRIVATE_ADDRESS.
709+
auto AddrSpaceCastNotFromPrivate = [&](Instruction &I) {
710+
return static_cast<AddrSpaceCastInst &>(I).getSrcAddressSpace() !=
711+
AMDGPUAS::PRIVATE_ADDRESS;
712+
};
713+
714+
bool UsedAssumedInformation = false;
715+
if (!A.checkForAllInstructions(AddrSpaceCastNotFromPrivate, *this,
716+
{Instruction::AddrSpaceCast},
717+
UsedAssumedInformation))
718+
return true;
719+
720+
// Check for addrSpaceCast from PRIVATE_ADDRESS in constant expressions
721+
auto &InfoCache = static_cast<AMDGPUInformationCache &>(A.getInfoCache());
722+
723+
Function *F = getAssociatedFunction();
724+
for (Instruction &I : instructions(F)) {
725+
for (const Use &U : I.operands()) {
726+
if (const auto *C = dyn_cast<Constant>(U)) {
727+
if (InfoCache.constHasASCastFromPrivate(C, *F))
728+
return true;
729+
}
730+
}
731+
}
732+
733+
// Finally check callees.
734+
737735
// This is called on each callee; false means callee shouldn't have
738736
// no-flat-scratch-init.
739737
auto CheckForNoFlatScratchInit = [&](Instruction &I) {
@@ -752,7 +750,7 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
752750
Intrinsic::amdgcn_addrspacecast_nonnull;
753751
};
754752

755-
bool UsedAssumedInformation = false;
753+
UsedAssumedInformation = false;
756754
// If any callee is false (i.e. need FlatScratchInit),
757755
// checkForAllCallLikeInstructions returns false, in which case this
758756
// function returns true.

0 commit comments

Comments
 (0)