[llvm] [AMDGPU] Propagate alias information in AMDGPULowerKernelArguments. (PR #161375)
Leon Clark via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 26 20:26:38 PST 2025
================
@@ -58,6 +66,143 @@ static BasicBlock::iterator getInsertPt(BasicBlock &BB) {
return InsPt;
}
+static void addAliasScopeMetadata(Function &F, DataLayout const &DL) {
+ // Collect noalias arguments.
+ auto NoAliasArgs = SmallVector<Argument const *, 4u>();
+
+ for (auto &Arg : F.args())
+ if (Arg.hasNoAliasAttr() && !Arg.use_empty())
+ NoAliasArgs.push_back(&Arg);
+
+ if (NoAliasArgs.empty())
+ return;
+
+ // Add alias scopes for each noalias argument.
+ auto MDB = MDBuilder(F.getContext());
+ auto NewScopes = DenseMap<Argument const *, MDNode *>();
+ auto *NewDomain = MDB.createAnonymousAliasScopeDomain(F.getName());
+
+ for (auto I = 0u; I < NoAliasArgs.size(); ++I) {
+ auto *Arg = NoAliasArgs[I];
+ auto Name = std::string(F.getName());
+
+ if (Arg->hasName())
+ Name += std::string(": %") + std::string(Arg->getName());
+ else
+ Name += std::string(": argument ") + std::to_string(I);
+
+ auto *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name);
+ NewScopes.insert(std::make_pair(Arg, NewScope));
+ }
+
+ // Iterate over all instructions.
+ auto DT = DominatorTree();
+ DT.recalculate(F);
+
+ for (auto Inst = inst_begin(F); Inst != inst_end(F); ++Inst) {
----------------
PeddleSpam wrote:
We could recursively look at the uses of each `noalias` argument, but we'd need to use a set to make sure we don't collect the same instructions multiple times, and we'd probably end up collecting most of the instructions anyway.
https://github.com/llvm/llvm-project/pull/161375
More information about the llvm-commits
mailing list