Skip to content

Commit

Permalink
transforms.llvm_ir_generator: use byval for FFI calls where appropriate.
Browse files Browse the repository at this point in the history
whitequark committed Jan 10, 2016
1 parent d1319b8 commit 1be9e75
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -936,7 +936,18 @@ def _prepare_closure_call(self, insn):
return llfun, [llenv] + list(llargs)

def _prepare_ffi_call(self, insn):
llargs = [self.map(arg) for arg in insn.arguments()]
llargs = []
byvals = []
for i, arg in enumerate(insn.arguments()):
llarg = self.map(arg)
if isinstance(llarg.type, (ll.LiteralStructType, ll.IdentifiedStructType)):
llslot = self.llbuilder.alloca(llarg.type)
self.llbuilder.store(llarg, llslot)
llargs.append(llslot)
byvals.append(i)
else:
llargs.append(llarg)

llfunname = insn.target_function().type.name
llfun = self.llmodule.get_global(llfunname)
if llfun is None:
@@ -951,6 +962,10 @@ def _prepare_ffi_call(self, insn):
insn.target_function().type.name)
if self.needs_sret(llretty):
llfun.args[0].add_attribute('sret')
byvals = [i + 1 for i in byvals]
for i in byvals:
llfun.args[i].add_attribute('byval')

return llfun, list(llargs)

# See session.c:{send,receive}_rpc_value and comm_generic.py:_{send,receive}_rpc_value.

0 comments on commit 1be9e75

Please sign in to comment.