[llvm] Extend MemoryEffects to Support Target-Specific Memory Locations (PR #148650)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 7 04:09:22 PDT 2025
================
@@ -374,7 +375,19 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
ME &= MemoryEffects::argMemOnly();
else if (R->getName() == "IntrInaccessibleMemOnly")
ME &= MemoryEffects::inaccessibleMemOnly();
- else if (R->getName() == "IntrInaccessibleMemOrArgMemOnly")
+ else if (R->isSubClassOf("IntrInaccessibleReadMemOnly")) {
+ llvm::IRMemLocation Loc = getValueAsIRMemLocation(R, "Loc");
+ if (ME.onlyAccessTargetMemoryLocation())
+ ME = ME.getWithModRef(Loc, ModRefInfo::Ref);
+ else
+ ME &= MemoryEffects::inaccessibleReadMemOnly(Loc);
----------------
paulwalker-arm wrote:
We shouldn't need to overrate `ME` like this. The tablegen classes look like a legacy from before MemortEffects existed and now that we're growing their number I think it would be better for the tablegen to have explicit classes to set them.
Specifically, instead of IntrInaccessibleReadMemOnly/IntrInaccessibleWriteMemOnly can you add IntrRead/IntrWrite classes that take a list of IntrinsicMemoryLocation. Then here you can build up a Read or Write mask. Something like:
```
MemoryEffects ReadMask = MemoryEffects::writeOnly();
for (const Record *Loc : R->getValueAsListOfDefs("Locations"))
ReadMask = ReadMask.getWithModRef(getValueAsIRMemLocation(Loc), ModRefInfo::ModRef);
ME &= ReadMask;
```
This will align better with the existing properties where you can combine `IntrReadMem` with `IntrRead<[TargetMem1]>` for an intrinsic that only reads `TargetMem1` and does not read or write anything else.
Not relevant to this PR but I think once we have this we can replace many of the existing memory related intrinsic properties because IntrRead/IntrWrite can represent everything.
https://github.com/llvm/llvm-project/pull/148650
More information about the llvm-commits
mailing list