Skip to content

Commit a1dd909

Browse files
author
whitequark
committedFeb 25, 2016
Take alignment into account during attribute writeback (fixes #293).
1 parent 914bc9f commit a1dd909

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def emit_attribute_writeback(self):
443443
lldatalayout = llvm.create_target_data(self.llmodule.data_layout)
444444

445445
llrpcattrty = self.llcontext.get_identified_type("attr_desc")
446-
llrpcattrty.elements = [lli32, llptr, llptr]
446+
llrpcattrty.elements = [lli32, lli32, llptr, llptr]
447447

448448
lldescty = self.llcontext.get_identified_type("type_desc")
449449
lldescty.elements = [llrpcattrty.as_pointer().as_pointer(), llptr.as_pointer()]
@@ -459,7 +459,10 @@ def emit_attribute_writeback(self):
459459
type_name = "instance.{}".format(typ.name)
460460

461461
def llrpcattr_of_attr(name, typ):
462-
size = self.llty_of_type(typ).get_abi_size(lldatalayout, context=self.llcontext)
462+
size = self.llty_of_type(typ). \
463+
get_abi_size(lldatalayout, context=self.llcontext)
464+
alignment = self.llty_of_type(typ). \
465+
get_abi_alignment(lldatalayout, context=self.llcontext)
463466

464467
def rpc_tag_error(typ):
465468
print(typ)
@@ -476,6 +479,7 @@ def rpc_tag_error(typ):
476479
name="attr.{}.{}".format(type_name, name))
477480
llrpcattr.initializer = ll.Constant(llrpcattrty, [
478481
ll.Constant(lli32, size),
482+
ll.Constant(lli32, alignment),
479483
llrpctag,
480484
self.llstr_of_str(name)
481485
])

Diff for: ‎artiq/runtime/ksupport.c

+4
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ int recv_rpc(void *slot) {
407407

408408
struct attr_desc {
409409
uint32_t size;
410+
uint32_t alignment;
410411
const char *tag;
411412
const char *name;
412413
};
@@ -434,6 +435,9 @@ void attribute_writeback(void *utypes) {
434435
while(*attrs) {
435436
struct attr_desc *attr = *attrs++;
436437

438+
if(offset % attr->alignment != 0)
439+
offset += attr->alignment - (offset % attr->alignment);
440+
437441
if(attr->tag) {
438442
uintptr_t value = (uintptr_t)object + offset;
439443
send_rpc(0, attr->tag, &object, &attr->name, value);

0 commit comments

Comments
 (0)