diff options
author | Lang Hames <lhames@gmail.com> | 2015-10-31 00:55:32 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2015-10-31 00:55:32 +0000 |
commit | 5796eb2d102903460fa48d3dbaabee7c1b6eb579 (patch) | |
tree | 84aa39394771ceb80dbf1a4e16daf698bc842036 /llvm/include | |
parent | adb5b1dfc22c63e50c6f36e885d8195393c9c9bd (diff) | |
download | bcm5719-llvm-5796eb2d102903460fa48d3dbaabee7c1b6eb579.tar.gz bcm5719-llvm-5796eb2d102903460fa48d3dbaabee7c1b6eb579.zip |
Add a sys::OwningMemoryBlock class, which is a sys::MemoryBlock that owns its
underlying memory, and will automatically release it on destruction.
Use this to tidy up the orc::IndirectStubsInfo class.
llvm-svn: 251731
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h | 22 | ||||
-rw-r--r-- | llvm/include/llvm/Support/Memory.h | 25 |
2 files changed, 40 insertions, 7 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h index 2637ea593d5..58273ae4616 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcTargetSupport.h @@ -59,9 +59,16 @@ public: const static unsigned PtrSize = 8; IndirectStubsInfo() : NumStubs(0) {} - IndirectStubsInfo(IndirectStubsInfo&&); - IndirectStubsInfo& operator=(IndirectStubsInfo&&); - ~IndirectStubsInfo(); + IndirectStubsInfo(IndirectStubsInfo &&Other) + : NumStubs(Other.NumStubs), StubsMem(std::move(Other.StubsMem)) { + Other.NumStubs = 0; + } + IndirectStubsInfo& operator=(IndirectStubsInfo &&Other) { + NumStubs = Other.NumStubs; + Other.NumStubs = 0; + StubsMem = std::move(Other.StubsMem); + return *this; + } /// @brief Number of stubs in this block. unsigned getNumStubs() const { return NumStubs; } @@ -69,18 +76,19 @@ public: /// @brief Get a pointer to the stub at the given index, which must be in /// the range 0 .. getNumStubs() - 1. void* getStub(unsigned Idx) const { - return static_cast<uint64_t*>(StubsBlock.base()) + Idx; + return static_cast<uint64_t*>(StubsMem.base()) + Idx; } /// @brief Get a pointer to the implementation-pointer at the given index, /// which must be in the range 0 .. getNumStubs() - 1. void** getPtr(unsigned Idx) const { - return static_cast<void**>(PtrsBlock.base()) + Idx; + char *PtrsBase = + static_cast<char*>(StubsMem.base()) + NumStubs * StubSize; + return reinterpret_cast<void**>(PtrsBase) + Idx; } private: unsigned NumStubs; - sys::MemoryBlock StubsBlock; - sys::MemoryBlock PtrsBlock; + sys::OwningMemoryBlock StubsMem; }; /// @brief Emit at least MinStubs worth of indirect call stubs, rounded out to diff --git a/llvm/include/llvm/Support/Memory.h b/llvm/include/llvm/Support/Memory.h index 47fd327e2e2..8103aea2fa2 100644 --- a/llvm/include/llvm/Support/Memory.h +++ b/llvm/include/llvm/Support/Memory.h @@ -155,6 +155,31 @@ namespace sys { /// as writable. static bool setRangeWritable(const void *Addr, size_t Size); }; + + /// Owning version of MemoryBlock. + class OwningMemoryBlock { + public: + OwningMemoryBlock() = default; + explicit OwningMemoryBlock(MemoryBlock M) : M(M) {} + OwningMemoryBlock(OwningMemoryBlock &&Other) { + M = Other.M; + Other.M = MemoryBlock(); + } + OwningMemoryBlock& operator=(OwningMemoryBlock &&Other) { + M = Other.M; + Other.M = MemoryBlock(); + return *this; + } + ~OwningMemoryBlock() { + Memory::releaseMappedMemory(M); + } + void *base() const { return M.base(); } + size_t size() const { return M.size(); } + MemoryBlock getMemoryBlock() const { return M; } + private: + MemoryBlock M; + }; + } } |