[pypy-svn] r50017 - in pypy/branch/llvmgcroot/pypy/translator/llvm: . module
arigo at codespeak.net
arigo at codespeak.net
Sat Dec 22 20:11:50 CET 2007
Author: arigo
Date: Sat Dec 22 20:11:50 2007
New Revision: 50017
Modified:
pypy/branch/llvmgcroot/pypy/translator/llvm/codewriter.py
pypy/branch/llvmgcroot/pypy/translator/llvm/funcnode.py
pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py
pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py
pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py
Log:
Intermediate check-in, before I kill some of this code.
Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/codewriter.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/codewriter.py (original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/codewriter.py Sat Dec 22 20:11:50 2007
@@ -173,3 +173,14 @@
self.call(var, "i32", "@write",
['i32', 'i8*', 'i32'],
['2', arg, '%d' % node.get_length()])
+
+ # ____________________________________________________________
+ # Special support for llvm.gcroot
+
+ def declare_gcroots(self, gcrootscount):
+ assert self.db.genllvm.config.translation.llvmgcroot
+ for i in range(gcrootscount):
+ self._indent("%%gcroot%d = alloca i8*" % i)
+ for i in range(gcrootscount):
+ self._indent("call void @llvm.gcroot(i8** %%gcroot%d, i8* null)"
+ % i)
Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/funcnode.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/funcnode.py (original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/funcnode.py Sat Dec 22 20:11:50 2007
@@ -42,6 +42,7 @@
def patch_graph(self):
graph = self.graph
+ self.gcrootscount = 0
if self.db.gctransformer:
# inline the GC helpers (malloc, write_barrier) into
# a copy of the graph
@@ -63,6 +64,9 @@
op.args = [v_newaddr]
op.result = v_newptr
rename[v_targetvar] = v_newptr
+ elif op.opname == 'llvm_store_gcroot':
+ index = op.args[0].value
+ self.gcrootscount = max(self.gcrootscount, index+1)
if rename:
block.exitswitch = rename.get(block.exitswitch,
block.exitswitch)
@@ -120,7 +124,7 @@
def getdecl(self):
returntype, ref, args = self.getdecl_parts()
- return "%s %s(%s)" % (returntype, ref, ", ".join(args))
+ return '%s %s(%s) gc "gcrootsingle"' % (returntype, ref, ", ".join(args))
# ______________________________________________________________________
# helpers for block writers
@@ -220,6 +224,8 @@
# actual block writers
def write_startblock(self, codewriter, block):
+ if self.gcrootscount > 0:
+ codewriter.declare_gcroots(self.gcrootscount)
self.write_block_operations(codewriter, block)
# a start block may return also
if block.exitswitch is None and len(block.exits) == 0:
Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py (original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/genllvm.py Sat Dec 22 20:11:50 2007
@@ -105,6 +105,7 @@
node.writeimpl(codewriter)
self._debug(codewriter)
+ self.write_gcroot_table(codewriter)
codewriter.comment("End of file")
codewriter.close()
@@ -276,3 +277,29 @@
print "Start"
print self.db.dump_pbcs()
print "End"
+
+ def write_gcroot_table(self, codewriter):
+ # Special support for llvm.gcroot
+ if self.config.translation.llvmgcroot:
+ from pypy.translator.llvm.funcnode import FuncImplNode
+ entries = []
+ for node in self.db.getnodes():
+ if isinstance(node, FuncImplNode):
+ ref = node.ref
+ assert ref.startswith('@')
+ entries.append('@__gcmap_' + ref[1:])
+
+ codewriter.header_comment("The global gcmap table")
+ data = []
+ for entry in entries:
+ codewriter._append('%s = extern_weak constant i32' % entry)
+ data.append('i32* %s' % entry)
+ codewriter._append(
+ '@__gcmaptable1 = internal constant [%d x i32*] [ %s ]' %
+ (len(data), ", ".join(data)))
+ codewriter._append(
+ '@__gcmaptable = internal constant '
+ 'i8* bitcast([%d x i32*]* @__gcmaptable1 to i8*)'
+ % len(data))
+ codewriter._append(
+ '@__gcmaptablelen = internal constant i32 %d' % len(data))
Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py (original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/module/support.py Sat Dec 22 20:11:50 2007
@@ -34,5 +34,8 @@
%result = phi i64 [%x, %block0], [%x2, %block1]
ret i64 %result
}
+
+declare void @llvm.gcroot(i8**, i8*) nounwind
+declare i8* @llvm.frameaddress(i32) nounwind
"""
Modified: pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py (original)
+++ pypy/branch/llvmgcroot/pypy/translator/llvm/opwriter.py Sat Dec 22 20:11:50 2007
@@ -588,3 +588,24 @@
# cheat llvm
self.codewriter.cast(opr.retref, opr.rettype, 'undef', opr.rettype)
+ # ____________________________________________________________
+ # Special support for llvm.gcroot
+
+ def llvm_store_gcroot(self, opr):
+ index = opr.op.args[0].value
+ rootref = '%%gcroot%d' % index
+ var = self.db.repr_tmpvar()
+ self.codewriter.cast(var, opr.argtypes[1], opr.argrefs[1], 'i8*')
+ self.codewriter.store('i8*', var, rootref)
+
+ def llvm_load_gcroot(self, opr):
+ index = opr.op.args[0].value
+ rootref = '%%gcroot%d' % index
+ self.codewriter.load(opr.retref, opr.rettype, rootref)
+
+ def llvm_frameaddress(self, opr):
+ self.codewriter.call(opr.retref, opr.rettype,
+ "@llvm.frameaddress", ['i32'], ['0'])
+
+ def llvm_gcmap_table(self, opr):
+ self.codewriter.load(opr.retref, opr.rettype, '@__gcmaptable')
More information about the Pypy-commit
mailing list