LLVM API Documentation
00001 //===- Memory.cpp - Memory Handling Support ---------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines some helpful functions for allocating memory and dealing 00011 // with memory mapped files 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "llvm/System/Memory.h" 00016 #include "llvm/Config/config.h" 00017 00018 namespace llvm { 00019 using namespace sys; 00020 } 00021 00022 // Include the platform-specific parts of this class. 00023 #ifdef LLVM_ON_UNIX 00024 #include "Unix/Memory.inc" 00025 #endif 00026 #ifdef LLVM_ON_WIN32 00027 #include "Win32/Memory.inc" 00028 #endif 00029 00030 extern "C" void sys_icache_invalidate(const void *Addr, size_t len); 00031 00032 /// InvalidateInstructionCache - Before the JIT can run a block of code 00033 /// that has been emitted it must invalidate the instruction cache on some 00034 /// platforms. 00035 void llvm::sys::Memory::InvalidateInstructionCache(const void *Addr, 00036 size_t Len) { 00037 00038 // icache invalidation for PPC and ARM. 00039 #if defined(__APPLE__) 00040 #if (defined(__POWERPC__) || defined (__ppc__) || \ 00041 defined(_POWER) || defined(_ARCH_PPC)) || defined(__arm__) 00042 sys_icache_invalidate(Addr, Len); 00043 #endif 00044 #else 00045 #if (defined(__POWERPC__) || defined (__ppc__) || \ 00046 defined(_POWER) || defined(_ARCH_PPC)) && defined(__GNUC__) 00047 const size_t LineSize = 32; 00048 00049 const intptr_t Mask = ~(LineSize - 1); 00050 const intptr_t StartLine = ((intptr_t) Addr) & Mask; 00051 const intptr_t EndLine = ((intptr_t) Addr + Len + LineSize - 1) & Mask; 00052 00053 for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) 00054 asm volatile("dcbf 0, %0" : : "r"(Line)); 00055 asm volatile("sync"); 00056 00057 for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) 00058 asm volatile("icbi 0, %0" : : "r"(Line)); 00059 asm volatile("isync"); 00060 #endif 00061 #endif // end apple 00062 }