Skip to content

Commit ddfd81b

Browse files
committed
[LoopVer] Add function to get the alias_scope/noalias metadata (NFC).
Split out logic to get noalias/alias_scope metadata to separate function in LoopVersioning. This will be used to migrate away from annotateInstWithNoAlias in LV.
1 parent 595cc96 commit ddfd81b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

llvm/include/llvm/Transforms/Utils/LoopVersioning.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class LoopVersioning {
8383
/// annotateInstWithNoAlias on the instructions of the versioned loop.
8484
void annotateLoopWithNoAlias();
8585

86+
/// Returns a pair containing the alias_scope and noalias metadata nodes for
87+
/// \p OrigInst, if they exists.
88+
std::pair<MDNode *, MDNode *>
89+
getNoAliasMetadataFor(const Instruction *OrigInst) const;
90+
8691
/// Set up the aliasing scopes based on the memchecks. This needs to
8792
/// be called before the first call to annotateInstWithNoAlias.
8893
void prepareNoAliasMetadata();

llvm/lib/Transforms/Utils/LoopVersioning.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,43 @@ void LoopVersioning::annotateLoopWithNoAlias() {
225225
}
226226
}
227227

228-
void LoopVersioning::annotateInstWithNoAlias(Instruction *VersionedInst,
229-
const Instruction *OrigInst) {
228+
std::pair<MDNode *, MDNode *>
229+
LoopVersioning::getNoAliasMetadataFor(const Instruction *OrigInst) const {
230230
if (!AnnotateNoAlias)
231-
return;
231+
return {nullptr, nullptr};
232232

233233
LLVMContext &Context = VersionedLoop->getHeader()->getContext();
234234
const Value *Ptr = isa<LoadInst>(OrigInst)
235235
? cast<LoadInst>(OrigInst)->getPointerOperand()
236236
: cast<StoreInst>(OrigInst)->getPointerOperand();
237237

238+
MDNode *AliasScope = nullptr;
239+
MDNode *NoAlias = nullptr;
238240
// Find the group for the pointer and then add the scope metadata.
239241
auto Group = PtrToGroup.find(Ptr);
240242
if (Group != PtrToGroup.end()) {
241-
VersionedInst->setMetadata(
242-
LLVMContext::MD_alias_scope,
243-
MDNode::concatenate(
244-
VersionedInst->getMetadata(LLVMContext::MD_alias_scope),
245-
MDNode::get(Context, GroupToScope[Group->second])));
243+
AliasScope = MDNode::concatenate(
244+
OrigInst->getMetadata(LLVMContext::MD_alias_scope),
245+
MDNode::get(Context, GroupToScope.lookup(Group->second)));
246246

247247
// Add the no-alias metadata.
248248
auto NonAliasingScopeList = GroupToNonAliasingScopeList.find(Group->second);
249249
if (NonAliasingScopeList != GroupToNonAliasingScopeList.end())
250-
VersionedInst->setMetadata(
251-
LLVMContext::MD_noalias,
252-
MDNode::concatenate(
253-
VersionedInst->getMetadata(LLVMContext::MD_noalias),
254-
NonAliasingScopeList->second));
250+
NoAlias =
251+
MDNode::concatenate(OrigInst->getMetadata(LLVMContext::MD_noalias),
252+
NonAliasingScopeList->second);
255253
}
254+
return {AliasScope, NoAlias};
255+
}
256+
257+
void LoopVersioning::annotateInstWithNoAlias(Instruction *VersionedInst,
258+
const Instruction *OrigInst) {
259+
const auto &[AliasScopeMD, NoAliasMD] = getNoAliasMetadataFor(OrigInst);
260+
if (AliasScopeMD)
261+
VersionedInst->setMetadata(LLVMContext::MD_alias_scope, AliasScopeMD);
262+
263+
if (NoAliasMD)
264+
VersionedInst->setMetadata(LLVMContext::MD_noalias, NoAliasMD);
256265
}
257266

258267
namespace {

0 commit comments

Comments
 (0)