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 00041 # if (defined(__POWERPC__) || defined (__ppc__) || \ 00042 defined(_POWER) || defined(_ARCH_PPC)) || defined(__arm__) 00043 sys_icache_invalidate(Addr, Len); 00044 # endif 00045 00046 #else 00047 00048 # if (defined(__POWERPC__) || defined (__ppc__) || \ 00049 defined(_POWER) || defined(_ARCH_PPC)) && defined(__GNUC__) 00050 const size_t LineSize = 32; 00051 00052 const intptr_t Mask = ~(LineSize - 1); 00053 const intptr_t StartLine = ((intptr_t) Addr) & Mask; 00054 const intptr_t EndLine = ((intptr_t) Addr + Len + LineSize - 1) & Mask; 00055 00056 for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) 00057 asm volatile("dcbf 0, %0" : : "r"(Line)); 00058 asm volatile("sync"); 00059 00060 for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) 00061 asm volatile("icbi 0, %0" : : "r"(Line)); 00062 asm volatile("isync"); 00063 # elif defined(__arm__) && defined(__GNUC__) 00064 // FIXME: Can we safely always call this for __GNUC__ everywhere? 00065 char *Start = (char*) Addr; 00066 char *End = Start + Len; 00067 __clear_cache(Start, End); 00068 # endif 00069 00070 #endif // end apple 00071 }