[PATCH] D13631: [JIT/llvm-rtdyld] Don't waste cycles invalidating the Instruction cache

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 00:24:32 PDT 2015


davide created this revision.
davide added a reviewer: lhames.
davide added a subscriber: llvm-commits.
davide set the repository for this revision to rL LLVM.

We call InvalidateInstructionCache() twice here and I think the second call is just wasted work. Hopefully my guess is correct.


Repository:
  rL LLVM

http://reviews.llvm.org/D13631

Files:
  include/llvm/Support/Memory.h
  lib/Support/Unix/Memory.inc
  lib/Support/Windows/Memory.inc
  tools/llvm-rtdyld/llvm-rtdyld.cpp

Index: tools/llvm-rtdyld/llvm-rtdyld.cpp
===================================================================
--- tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -385,8 +385,8 @@
     sys::MemoryBlock &Data = MemMgr.FunctionMemory[i];
     // Make sure the memory is executable.
     std::string ErrorStr;
-    sys::Memory::InvalidateInstructionCache(Data.base(), Data.size());
-    if (!sys::Memory::setExecutable(Data, &ErrorStr))
+    if (!sys::Memory::setExecutable(Data, &ErrorStr,
+                                    true /* invalidateCache */))
       return Error("unable to mark function executable: '" + ErrorStr + "'");
   }
 
Index: lib/Support/Windows/Memory.inc
===================================================================
--- lib/Support/Windows/Memory.inc
+++ lib/Support/Windows/Memory.inc
@@ -197,7 +197,8 @@
   return true;
 }
 
-bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) {
+bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg,
+                           bool InvalidateCache) {
   if (!setRangeExecutable(M.Address, M.Size)) {
     return MakeErrMsg(ErrMsg, "Cannot set memory to executable: ");
   }
Index: lib/Support/Unix/Memory.inc
===================================================================
--- lib/Support/Unix/Memory.inc
+++ lib/Support/Unix/Memory.inc
@@ -263,7 +263,8 @@
 #endif
 }
 
-bool Memory::setExecutable (MemoryBlock &M, std::string *ErrMsg) {
+bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg,
+                           bool InvalidateCache) {
 #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
   if (M.Address == 0 || M.Size == 0) return false;
   Memory::InvalidateInstructionCache(M.Address, M.Size);
@@ -274,6 +275,8 @@
   Memory::InvalidateInstructionCache(M.Address, M.Size);
   return true;
 #else
+  if (InvalidateCache)
+    Memory::InvalidateInstructionCache(M.Address, M.Size);
   return true;
 #endif
 }
Index: include/llvm/Support/Memory.h
===================================================================
--- include/llvm/Support/Memory.h
+++ include/llvm/Support/Memory.h
@@ -140,7 +140,10 @@
     /// setExecutable - Before the JIT can run a block of code, it has to be
     /// given read and executable privilege. Return true if it is already r-x
     /// or the system is able to change its previlege.
-    static bool setExecutable(MemoryBlock &M, std::string *ErrMsg = nullptr);
+    /// If InvalidateCache is true, the instruction cache is also invalidated
+    //  as result of this call.
+    static bool setExecutable(MemoryBlock &M, std::string *ErrMsg = nullptr,
+                              bool InvalidateCache = false);
 
     /// setWritable - When adding to a block of code, the JIT may need
     /// to mark a block of code as RW since the protections are on page


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13631.37048.patch
Type: text/x-patch
Size: 2849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151011/017536bd/attachment.bin>


More information about the llvm-commits mailing list