[llvm] Implement reserveAllocationSpace for SectionMemoryManager (PR #71968)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 10:08:56 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 2bac7201018dcab549895c30c0eb26bee45d842f 24ebe923881e1f252f4ad64a533d816390418a6d -- llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
index a53a6e7e6a5c..0359b6539e4d 100644
--- a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
+++ b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
@@ -117,8 +117,9 @@ public:
/// Implements pre-allocating all memory in a single block.
void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
- uintptr_t RODataSize, uint32_t RODataAlign,
- uintptr_t RWDataSize, uint32_t RWDataAlign) override;
+ uintptr_t RODataSize, uint32_t RODataAlign,
+ uintptr_t RWDataSize,
+ uint32_t RWDataAlign) override;
/// Allocates a memory block of (at least) the given size suitable for
/// executable code.
diff --git a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
index 073b38de11a4..568ab28a112d 100644
--- a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
@@ -20,16 +20,18 @@ namespace llvm {
static uintptr_t requiredPageSize(uintptr_t Size, uint32_t Alignment) {
static const size_t PageSize = sys::Process::getPageSize();
- // Use the same calculation as allocateSection because we need to be able to satisfy it.
- uintptr_t RequiredSize = Alignment * ((Size + Alignment - 1)/Alignment + 1);
+ // Use the same calculation as allocateSection because we need to be able to
+ // satisfy it.
+ uintptr_t RequiredSize = Alignment * ((Size + Alignment - 1) / Alignment + 1);
// Round up to the nearest page size. Blocks must be page-aligned.
- return PageSize * ((RequiredSize + PageSize - 1)/PageSize);
+ return PageSize * ((RequiredSize + PageSize - 1) / PageSize);
}
void SectionMemoryManager::reserveAllocationSpace(
- uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize, uint32_t RODataAlign,
- uintptr_t RWDataSize, uint32_t RWDataAlign) {
- if (CodeSize == 0 && RODataSize == 0 && RWDataSize == 0) return;
+ uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize,
+ uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t RWDataAlign) {
+ if (CodeSize == 0 && RODataSize == 0 && RWDataSize == 0)
+ return;
// Get space required for each section.
CodeAlign = CodeAlign ? CodeAlign : 16;
@@ -38,11 +40,12 @@ void SectionMemoryManager::reserveAllocationSpace(
uintptr_t RequiredCodeSize = requiredPageSize(CodeSize, CodeAlign);
uintptr_t RequiredRODataSize = requiredPageSize(RODataSize, RODataAlign);
uintptr_t RequiredRWDataSize = requiredPageSize(RWDataSize, RWDataAlign);
- uintptr_t RequiredSize = RequiredCodeSize + RequiredRODataSize + RequiredRWDataSize;
+ uintptr_t RequiredSize =
+ RequiredCodeSize + RequiredRODataSize + RequiredRWDataSize;
std::error_code ec;
- sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(RequiredSize, nullptr,
- sys::Memory::MF_READ | sys::Memory::MF_WRITE, ec);
+ sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(
+ RequiredSize, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, ec);
if (ec) {
return;
}
@@ -56,21 +59,21 @@ void SectionMemoryManager::reserveAllocationSpace(
if (CodeSize > 0) {
assert(Addr == ((Addr + CodeAlign - 1) & ~(uintptr_t)(CodeAlign - 1)));
- FreeMB.Free = sys::MemoryBlock((void*)Addr, RequiredCodeSize);
+ FreeMB.Free = sys::MemoryBlock((void *)Addr, RequiredCodeSize);
CodeMem.FreeMem.push_back(FreeMB);
Addr += RequiredCodeSize;
}
if (RODataSize > 0) {
assert(Addr == ((Addr + RODataAlign - 1) & ~(uintptr_t)(RODataAlign - 1)));
- FreeMB.Free = sys::MemoryBlock((void*)Addr, RequiredRODataSize);
+ FreeMB.Free = sys::MemoryBlock((void *)Addr, RequiredRODataSize);
RODataMem.FreeMem.push_back(FreeMB);
Addr += RequiredRODataSize;
}
if (RWDataSize > 0) {
assert(Addr == ((Addr + RWDataAlign - 1) & ~(uintptr_t)(RWDataAlign - 1)));
- FreeMB.Free = sys::MemoryBlock((void*)Addr, RequiredRWDataSize);
+ FreeMB.Free = sys::MemoryBlock((void *)Addr, RequiredRWDataSize);
RWDataMem.FreeMem.push_back(FreeMB);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/71968
More information about the llvm-commits
mailing list