[llvm] [WIP][AMDGPU][Attributor] Make `AAAMDFlatWorkGroupSize` honor existing attribute (PR #114357)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 22:07:53 PDT 2024
================
@@ -728,12 +735,43 @@ struct AAAMDSizeRangeAttribute
};
bool AllCallSitesKnown = true;
- if (!A.checkForAllCallSites(CheckCallSite, *this, true, AllCallSitesKnown))
+ if (!A.checkForAllCallSites(CheckCallSite, *this,
+ /*RequireAllCallSites=*/true,
+ AllCallSitesKnown))
return indicatePessimisticFixpoint();
return Change;
}
+ /// Clamp the assumed range to the default value ([Min, Max]) and emit the
+ /// attribute if it is not same as default.
+ ChangeStatus
+ emitAttributeIfNotDefaultAfterClamp(Attributor &A,
+ std::pair<unsigned, unsigned> Default) {
+ auto [Min, Max] = Default;
+ unsigned Lower = getAssumed().getLower().getZExtValue();
+ unsigned Upper = getAssumed().getUpper().getZExtValue();
+
+ // Clamp the range to the default value.
+ if (Lower < Min)
+ Lower = Min;
+ if (Upper > Max + 1)
+ Upper = Max + 1;
+
+ // No manifest if the value is same as default after clamp.
+ if (Lower == Min && Upper == Max + 1)
+ return ChangeStatus::UNCHANGED;
+
+ Function *F = getAssociatedFunction();
+ LLVMContext &Ctx = F->getContext();
+ SmallString<10> Buffer;
+ raw_svector_ostream OS(Buffer);
+ OS << Lower << ',' << Upper - 1;
+ return A.manifestAttrs(getIRPosition(),
+ {Attribute::get(Ctx, AttrName, OS.str())},
+ /* ForceReplace=*/true);
+ }
+
ChangeStatus emitAttributeIfNotDefault(Attributor &A, unsigned Min,
----------------
shiltian wrote:
This will be eventually removed.
https://github.com/llvm/llvm-project/pull/114357
More information about the llvm-commits
mailing list