Skip to content

Commit 1be9e75

Browse files
author
whitequark
committedJan 10, 2016
transforms.llvm_ir_generator: use byval for FFI calls where appropriate.
1 parent d1319b8 commit 1be9e75

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

Diff for: ‎artiq/compiler/transforms/llvm_ir_generator.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,18 @@ def _prepare_closure_call(self, insn):
936936
return llfun, [llenv] + list(llargs)
937937

938938
def _prepare_ffi_call(self, insn):
939-
llargs = [self.map(arg) for arg in insn.arguments()]
939+
llargs = []
940+
byvals = []
941+
for i, arg in enumerate(insn.arguments()):
942+
llarg = self.map(arg)
943+
if isinstance(llarg.type, (ll.LiteralStructType, ll.IdentifiedStructType)):
944+
llslot = self.llbuilder.alloca(llarg.type)
945+
self.llbuilder.store(llarg, llslot)
946+
llargs.append(llslot)
947+
byvals.append(i)
948+
else:
949+
llargs.append(llarg)
950+
940951
llfunname = insn.target_function().type.name
941952
llfun = self.llmodule.get_global(llfunname)
942953
if llfun is None:
@@ -951,6 +962,10 @@ def _prepare_ffi_call(self, insn):
951962
insn.target_function().type.name)
952963
if self.needs_sret(llretty):
953964
llfun.args[0].add_attribute('sret')
965+
byvals = [i + 1 for i in byvals]
966+
for i in byvals:
967+
llfun.args[i].add_attribute('byval')
968+
954969
return llfun, list(llargs)
955970

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

0 commit comments

Comments
 (0)
Please sign in to comment.