summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-25 17:14:10 +0000
committerChris Lattner <sabre@nondot.org>2008-06-25 17:14:10 +0000
commit881d537d2c9628624e2e9d348f8d84ebc09de690 (patch)
treee072bdc474d328ed5b1077732ce234efd83ed25a /llvm/lib/System
parentd95b74870e4d0a76fe1dd992e4c308ff6986bb66 (diff)
downloadbcm5719-llvm-881d537d2c9628624e2e9d348f8d84ebc09de690.tar.gz
bcm5719-llvm-881d537d2c9628624e2e9d348f8d84ebc09de690.zip
Add a new InvalidateInstructionCache method to sys::Memory.
llvm-svn: 52731
Diffstat (limited to 'llvm/lib/System')
-rw-r--r--llvm/lib/System/Memory.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/llvm/lib/System/Memory.cpp b/llvm/lib/System/Memory.cpp
index 054cc966a3e..bbb7917dca3 100644
--- a/llvm/lib/System/Memory.cpp
+++ b/llvm/lib/System/Memory.cpp
@@ -17,12 +17,6 @@
namespace llvm {
using namespace sys;
-
-//===----------------------------------------------------------------------===//
-//=== WARNING: Implementation here must contain only TRULY operating system
-//=== independent code.
-//===----------------------------------------------------------------------===//
-
}
// Include the platform-specific parts of this class.
@@ -32,3 +26,34 @@ using namespace sys;
#ifdef LLVM_ON_WIN32
#include "Win32/Memory.inc"
#endif
+
+/// InvalidateInstructionCache - Before the JIT can run a block of code
+/// that has been emitted it must invalidate the instruction cache on some
+/// platforms.
+void llvm::sys::Memory::InvalidateInstructionCache(const void *Addr,
+ size_t Len) {
+
+// icache invalidation for PPC.
+#if (defined(__POWERPC__) || defined (__ppc__) || \
+ defined(_POWER) || defined(_ARCH_PPC))
+ #if defined(__APPLE__)
+ extern "C" void sys_icache_invalidate(const void *Addr, size_t len);
+ sys_icache_invalidate(Addr, len);
+ #elif defined(__GNUC__)
+ const size_t LineSize = 32;
+
+ const intptr_t Mask = ~(LineSize - 1);
+ const intptr_t StartLine = ((intptr_t) Addr) & Mask;
+ const intptr_t EndLine = ((intptr_t) Addr + len + LineSize - 1) & Mask;
+
+ for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize)
+ asm volatile("dcbf 0, %0" : : "r"(Line));
+ asm volatile("sync");
+
+ for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize)
+ asm volatile("icbi 0, %0" : : "r"(Line));
+ asm volatile("isync");
+ #endif
+#endif // end PPC
+
+} \ No newline at end of file
OpenPOWER on IntegriCloud