summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2003-06-04 19:45:25 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2003-06-04 19:45:25 +0000
commit3a55e8aae4f5f28c624a87e2161b4a825b75ad09 (patch)
treed44bcbaba96027e34f439127cc6fe4543dce9249
parente961d9614a86c735f3686b07321de2a520b2be3c (diff)
downloadllvm-3a55e8aae4f5f28c624a87e2161b4a825b75ad09.tar.gz
llvm-3a55e8aae4f5f28c624a87e2161b4a825b75ad09.tar.bz2
llvm-3a55e8aae4f5f28c624a87e2161b4a825b75ad09.tar.xz
* Institute a hack for the Sparc call to mmap() to get our generated code to be
laid out closer to the VM so that calls to library functions (e.g. puts()) and callback (e.g. JITResolver::CompilationCallback) fit into 30 bits of the call instruction. * Abort if architecture is not yet supported (not X86 or Sparc) because it likely requires a different set of parameters to mmap() . * Stop using hard-coded values for page size; use sysconf(_SC_PAGESIZE) instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6610 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 91fee458ed..735244f79d 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -67,20 +67,25 @@ MachineCodeEmitter *VM::createEmitter(VM &V) {
// FIXME: This should be rewritten to support a real memory manager for
// executable memory pages!
static void *getMemory(unsigned NumPages) {
+ void *pa;
+ if (NumPages == 0) return 0;
+ static const long pageSize = sysconf(_SC_PAGESIZE);
+
#if defined(i386) || defined(__i386__) || defined(__x86__)
- static const int fd = 0;
+ pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+ MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); /* fd = 0 */
#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9)
- static const int fd = -1;
+ static unsigned long Counter = 0;
+ pa = mmap((void*)(0x140000000UL+Counter), pageSize*NumPages,
+ PROT_READ|PROT_WRITE|PROT_EXEC,
+ MAP_PRIVATE|MAP_ANON|MAP_FIXED, -1, 0); /* fd = -1 */
+ Counter += pageSize*NumPages;
+ std::cerr << "getMemory() returning " << pa << "\n";
#else
- // This is an unsupported architecture.
- static const int fd = 0;
+ std::cerr << "This architecture is not supported by the JIT\n";
+ abort();
#endif
- void *pa;
- if (NumPages == 0) return 0;
- static const long pageSize = sysconf (_SC_PAGESIZE);
- pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
- MAP_PRIVATE|MAP_ANONYMOUS, fd, 0);
if (pa == MAP_FAILED) {
perror("mmap");
abort();
@@ -118,9 +123,10 @@ void Emitter::emitConstantPool(MachineConstantPool *MCP) {
}
void Emitter::startFunctionStub(const Function &F, unsigned StubSize) {
+ static const long pageSize = sysconf(_SC_PAGESIZE);
SavedCurBlock = CurBlock; SavedCurByte = CurByte;
// FIXME: this is a huge waste of memory.
- CurBlock = (unsigned char *)getMemory((StubSize+4095)/4096);
+ CurBlock = (unsigned char *)getMemory((StubSize+pageSize-1)/pageSize);
CurByte = CurBlock; // Start writing at the beginning of the fn.
}