[pypy-svn] r14407 - pypy/dist/pypy/translator/llvm2
ericvrp at codespeak.net
ericvrp at codespeak.net
Thu Jul 7 20:23:59 CEST 2005
Author: ericvrp
Date: Thu Jul 7 20:23:58 2005
New Revision: 14407
Modified:
pypy/dist/pypy/translator/llvm2/extfunction.py
pypy/dist/pypy/translator/llvm2/funcnode.py
pypy/dist/pypy/translator/llvm2/genllvm.py
pypy/dist/pypy/translator/llvm2/node.py
Log:
Fixed the amount of llvm code generated. Basicly working towards emitting just the code that is actually used (and its dependencies).
This will need refactoring, especially the dict stored in LLVMNode.
Modified: pypy/dist/pypy/translator/llvm2/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/extfunction.py (original)
+++ pypy/dist/pypy/translator/llvm2/extfunction.py Thu Jul 7 20:23:58 2005
@@ -1,10 +1,7 @@
-extdeclarations = """; External declarations
-
-
-; XXX these int's might need to be long's on 64 bit CPU's :(
-
+extdeclarations = """
declare sbyte* %gc_malloc(uint)
declare sbyte* %gc_malloc_atomic(uint)
+
declare int %time(int*) ;void* actually
declare int %clock()
declare void %sleep(int)
@@ -15,12 +12,9 @@
%st.rpy_string.0 = type {int, {int, [0 x sbyte]}}
-; End of external declarations
-
"""
-gc_boehm = """; Using Boehm GC
-
+gc_boehm = """
declare sbyte* %GC_malloc(uint)
declare sbyte* %GC_malloc_atomic(uint)
@@ -36,8 +30,7 @@
"""
-gc_disabled = """; Using no GC
-
+gc_disabled = """
sbyte* %gc_malloc(uint %n) {
%ptr = malloc sbyte, uint %n
ret sbyte* %ptr
@@ -50,8 +43,7 @@
"""
-extfunctions = """; Helper function to convert LLVM <-> C types
-
+extfunctionshelpers = """
sbyte* %cast(%st.rpy_string.0* %structstring) {
%reallengthptr = getelementptr %st.rpy_string.0* %structstring, int 0, uint 1, uint 0
%reallength = load int* %reallengthptr
@@ -71,14 +63,34 @@
ret sbyte* %dest
}
-; Wrapper functions that call external (C) functions
+%st.rpy_string.0 * %new.st.var.rpy_string.0.helper(int %len) {
+ %size = getelementptr %st.rpy_string.0* null, int 0, uint 1, uint 1, int %len
+ %usize = cast sbyte* %size to uint
+ %malloc.Size.5 = getelementptr sbyte* null, uint %usize
+ %malloc.SizeU.5 = cast sbyte* %malloc.Size.5 to uint
+ %malloc.Ptr.5 = call sbyte* %gc_malloc(uint %malloc.SizeU.5)
+ %ptr = cast sbyte* %malloc.Ptr.5 to sbyte*
+ %result = cast sbyte* %ptr to %st.rpy_string.0*
+ %arraylength = getelementptr %st.rpy_string.0* %result, int 0, uint 1, uint 0
+ store int %len, int* %arraylength
+ ret %st.rpy_string.0* %result
+}
+
+"""
+
+extfunctions = {}
+
+extfunctions["%ll_time_time"] = """
double %ll_time_time() {
%v0 = call int %time(int* null)
%v1 = cast int %v0 to double
ret double %v1
}
+"""
+
+extfunctions["%ll_time_clock"] = """
double %ll_time_clock() {
%v0 = call int %clock()
%v1 = cast int %v0 to double
@@ -87,12 +99,18 @@
ret double %v2
}
+"""
+
+extfunctions["%ll_time_sleep"] = """
void %ll_time_sleep(double %f) {
%i = cast double %f to int
call void %sleep(int %i)
ret void
}
+"""
+
+extfunctions["%ll_os_open"] = """
int %ll_os_open(%st.rpy_string.0* %structstring, int %pythonmode) {
%flags = cast int %pythonmode to int
%mode = cast int 384 to int ;S_IRUSR=256, S_IWUSR=128
@@ -101,6 +119,9 @@
ret int %fd
}
+"""
+
+extfunctions["%ll_os_write"] = """
int %ll_os_write(int %fd, %st.rpy_string.0* %structstring) {
%reallengthptr = getelementptr %st.rpy_string.0* %structstring, int 0, uint 1, uint 0
%reallength = load int* %reallengthptr
@@ -109,9 +130,12 @@
ret int %byteswritten
}
+"""
+
+extfunctions["%ll_os_read"] = """
%st.rpy_string.0* %ll_os_read(int %fd, int %buffersize) {
;This is a bit simplistic! It really allocated a large enough buffer to hold all the data in.
- %str = call %st.rpy_string.0* %new.st.var.rpy_string.0(int %buffersize)
+ %str = call %st.rpy_string.0* %new.st.var.rpy_string.0.helper(int %buffersize)
;load the actual data
%destptr = getelementptr %st.rpy_string.0* %str, int 0, uint 1, uint 1
@@ -125,5 +149,4 @@
ret %st.rpy_string.0* %str
}
-; End of external functions
"""
Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py Thu Jul 7 20:23:58 2005
@@ -199,6 +199,7 @@
def writeimpl(self, codewriter):
if self.ref not in self.fnmapping:
+ self.used_external_functions[self.ref] = True
return
T = self.value._TYPE
Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py Thu Jul 7 20:23:58 2005
@@ -11,10 +11,11 @@
from pypy.rpython import lltype
from pypy.tool.udir import udir
from pypy.translator.llvm2.codewriter import CodeWriter
+from pypy.translator.llvm2.node import LLVMNode
from pypy.translator.backendoptimization import remove_void
#from pypy.translator.backendoptimization import rename_extfunc_calls
from pypy.translator.llvm2.extfunction import extdeclarations, \
- extfunctions, gc_boehm, gc_disabled
+ extfunctionshelpers, extfunctions, gc_boehm, gc_disabled
from pypy.translator.translator import Translator
@@ -30,6 +31,7 @@
remove_void(translator)
#rename_extfunc_calls(translator)
translator.checkgraphs()
+ LLVMNode.used_external_functions = {}
def compile(self, func=None):
if func is None:
@@ -64,20 +66,23 @@
#import pdb ; pdb.set_trace()
nl(); comment("Function Implementation")
codewriter.startimpl()
- if self.embedexterns:
- for extfunc in extfunctions.split('\n'):
- codewriter.append(extfunc)
-
if use_boehm_gc:
gc_funcs = gc_boehm
else:
gc_funcs = gc_disabled
for extfunc in gc_funcs.split('\n'):
codewriter.append(extfunc)
-
+
for typ_decl in self.db.getobjects():
typ_decl.writeimpl(codewriter)
+ if self.embedexterns:
+ for extfunchelper in extfunctionshelpers.split('\n'):
+ codewriter.append(extfunchelper)
+ for funcname,value in LLVMNode.used_external_functions.iteritems():
+ for extfunc in extfunctions[funcname].split('\n'):
+ codewriter.append(extfunc)
+
comment("End of file") ; nl()
self.content = str(codewriter)
return self.content
Modified: pypy/dist/pypy/translator/llvm2/node.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/node.py (original)
+++ pypy/dist/pypy/translator/llvm2/node.py Thu Jul 7 20:23:58 2005
@@ -1,5 +1,7 @@
class LLVMNode(object):
+ used_external_functions = {}
+
def ref():
def _get_ref(self):
return self._ref
More information about the Pypy-commit
mailing list