[llvm] bbc2fc5 - [Support][ORC] Add an explicit release operation to OwningMemoryBlock.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 12 10:13:48 PDT 2021
Author: Lang Hames
Date: 2021-10-12T10:13:43-07:00
New Revision: bbc2fc548b43806f2c2a2180b696127f7a680050
URL: https://github.com/llvm/llvm-project/commit/bbc2fc548b43806f2c2a2180b696127f7a680050
DIFF: https://github.com/llvm/llvm-project/commit/bbc2fc548b43806f2c2a2180b696127f7a680050.diff
LOG: [Support][ORC] Add an explicit release operation to OwningMemoryBlock.
This gives OwningMemoryBlock clients a way to check for errors on release.
rdar://84127175
Added:
Modified:
llvm/include/llvm/Support/Memory.h
llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Memory.h b/llvm/include/llvm/Support/Memory.h
index a40ca9f813e00..d7d60371d315f 100644
--- a/llvm/include/llvm/Support/Memory.h
+++ b/llvm/include/llvm/Support/Memory.h
@@ -148,13 +148,22 @@ namespace sys {
return *this;
}
~OwningMemoryBlock() {
- Memory::releaseMappedMemory(M);
+ if (M.base())
+ Memory::releaseMappedMemory(M);
}
void *base() const { return M.base(); }
/// The size as it was allocated. This is always greater or equal to the
/// size that was originally requested.
size_t allocatedSize() const { return M.allocatedSize(); }
MemoryBlock getMemoryBlock() const { return M; }
+ std::error_code release() {
+ std::error_code EC;
+ if (M.base()) {
+ EC = Memory::releaseMappedMemory(M);
+ M = MemoryBlock();
+ }
+ return EC;
+ }
private:
MemoryBlock M;
};
diff --git a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
index e7e4e561b5609..f2b157e424b6c 100644
--- a/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp
@@ -68,8 +68,7 @@ class SimpleAllocator {
}
auto MB = std::move(I->second);
Blocks.erase(I);
- auto MBToRelease = MB.getMemoryBlock();
- if (auto EC = sys::Memory::releaseMappedMemory(MBToRelease))
+ if (auto EC = MB.release())
Err = joinErrors(std::move(Err), errorCodeToError(EC));
}
return Err;
More information about the llvm-commits
mailing list