[llvm] a502c65 - [BuildLibCalls] Add helper for setting memory effects (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 12 07:31:05 PDT 2025
Author: Nikita Popov
Date: 2025-03-12T15:30:57+01:00
New Revision: a502c656881c8bc28b49a08c29421059d00aca26
URL: https://github.com/llvm/llvm-project/commit/a502c656881c8bc28b49a08c29421059d00aca26
DIFF: https://github.com/llvm/llvm-project/commit/a502c656881c8bc28b49a08c29421059d00aca26.diff
LOG: [BuildLibCalls] Add helper for setting memory effects (NFC)
Remove reliance on having dedicated setters and getters on Function
for every possible memory effect combination.
Added:
Modified:
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 7a5326c255831..594dd067006e2 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -76,42 +76,46 @@ static bool setNoReturn(Function &F) {
return true;
}
+static bool setMemoryEffects(Function &F, MemoryEffects ME) {
+ MemoryEffects OrigME = F.getMemoryEffects();
+ MemoryEffects NewME = OrigME & ME;
+ if (OrigME == NewME)
+ return false;
+ F.setMemoryEffects(NewME);
+ return true;
+}
+
static bool setOnlyAccessesInaccessibleMemory(Function &F) {
- if (F.onlyAccessesInaccessibleMemory())
+ if (!setMemoryEffects(F, MemoryEffects::inaccessibleMemOnly()))
return false;
- F.setOnlyAccessesInaccessibleMemory();
++NumInaccessibleMemOnly;
return true;
}
static bool setOnlyReadsMemory(Function &F) {
- if (F.onlyReadsMemory())
+ if (!setMemoryEffects(F, MemoryEffects::readOnly()))
return false;
- F.setOnlyReadsMemory();
++NumReadOnly;
return true;
}
static bool setOnlyWritesMemory(Function &F) {
- if (F.onlyWritesMemory()) // writeonly or readnone
+ if (!setMemoryEffects(F, MemoryEffects::writeOnly()))
return false;
++NumWriteOnly;
- F.setOnlyWritesMemory();
return true;
}
static bool setOnlyAccessesArgMemory(Function &F) {
- if (F.onlyAccessesArgMemory())
+ if (!setMemoryEffects(F, MemoryEffects::argMemOnly()))
return false;
- F.setOnlyAccessesArgMemory();
++NumArgMemOnly;
return true;
}
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F) {
- if (F.onlyAccessesInaccessibleMemOrArgMem())
+ if (!setMemoryEffects(F, MemoryEffects::inaccessibleOrArgMemOnly()))
return false;
- F.setOnlyAccessesInaccessibleMemOrArgMem();
++NumInaccessibleMemOrArgMemOnly;
return true;
}
More information about the llvm-commits
mailing list