From 10108e6d64d0fc08217f8d4cea6d30eb0cfc5af8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 31 Mar 2016 12:04:38 +0000 Subject: [PATCH] compiler: mark loaded pointers as !dereferenceable. Also, lower the bound for test_pulse_rate_dds, since we generate better code for it now. --- .../compiler/transforms/llvm_ir_generator.py | 19 ++++++++++++------- artiq/test/coredevice/test_rtio.py | 6 ++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 962733227..182b24dc6 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -175,6 +175,7 @@ class LLVMIRGenerator: self.llmodule = ll.Module(context=self.llcontext, name=module_name) self.llmodule.triple = target.triple self.llmodule.data_layout = target.data_layout + self.lldatalayout = llvm.create_target_data(self.llmodule.data_layout) self.function_flags = None self.llfunction = None self.llmap = {} @@ -459,8 +460,6 @@ class LLVMIRGenerator: if llobject is not None: llobjects[typ].append(llobject.bitcast(llptr)) - lldatalayout = llvm.create_target_data(self.llmodule.data_layout) - llrpcattrty = self.llcontext.get_identified_type("A") llrpcattrty.elements = [lli32, llptr, llptr] @@ -512,9 +511,9 @@ class LLVMIRGenerator: for attr in typ.attributes: attrtyp = typ.attributes[attr] size = self.llty_of_type(attrtyp). \ - get_abi_size(lldatalayout, context=self.llcontext) + get_abi_size(self.lldatalayout, context=self.llcontext) alignment = self.llty_of_type(attrtyp). \ - get_abi_alignment(lldatalayout, context=self.llcontext) + get_abi_alignment(self.lldatalayout, context=self.llcontext) if offset % alignment != 0: offset += alignment - (offset % alignment) @@ -688,13 +687,19 @@ class LLVMIRGenerator: llouterenv.metadata['nonnull'] = self.empty_metadata return self.llptr_to_var(llouterenv, env_ty.params["$outer"], var_name) + def mark_dereferenceable(self, load): + assert isinstance(load, ll.LoadInstr) and isinstance(load.type, ll.PointerType) + pointee_size = load.type.pointee.get_abi_size(self.lldatalayout, context=self.llcontext) + metadata = self.llmodule.add_metadata([ll.Constant(lli64, pointee_size)]) + load.metadata['dereferenceable'] = metadata + def process_GetLocal(self, insn): env = insn.environment() llptr = self.llptr_to_var(self.map(env), env.type, insn.var_name) llptr.name = "ptr.{}.{}".format(env.name, insn.var_name) llvalue = self.llbuilder.load(llptr, name="val.{}.{}".format(env.name, insn.var_name)) if isinstance(llvalue.type, ll.PointerType): - llvalue.metadata['nonnull'] = self.empty_metadata + self.mark_dereferenceable(llvalue) return llvalue def process_SetLocal(self, insn): @@ -818,7 +823,7 @@ class LLVMIRGenerator: if types.is_instance(typ) and attr in typ.constant_attributes: llvalue.metadata['invariant.load'] = self.empty_metadata if isinstance(llvalue.type, ll.PointerType): - llvalue.metadata['nonnull'] = self.empty_metadata + self.mark_dereferenceable(llvalue) return llvalue def process_SetAttr(self, insn): @@ -849,7 +854,7 @@ class LLVMIRGenerator: inbounds=True) llvalue = self.llbuilder.load(llelt) if isinstance(llvalue.type, ll.PointerType): - llvalue.metadata['nonnull'] = self.empty_metadata + self.mark_dereferenceable(llvalue) return llvalue def process_SetElem(self, insn): diff --git a/artiq/test/coredevice/test_rtio.py b/artiq/test/coredevice/test_rtio.py index 42c55c855..9ab7b48b2 100644 --- a/artiq/test/coredevice/test_rtio.py +++ b/artiq/test/coredevice/test_rtio.py @@ -105,6 +105,8 @@ class PulseRate(EnvExperiment): class PulseRateDDS(EnvExperiment): + kernel_constant_attributes = {"core", "core_dds", "dds0", "dds1"} + def build(self): self.setattr_device("core") self.setattr_device("core_dds") @@ -113,7 +115,7 @@ class PulseRateDDS(EnvExperiment): @kernel def run(self): - dt = seconds_to_mu(150*us) + dt = seconds_to_mu(50*us) while True: delay(10*ms) for i in range(1250): @@ -262,7 +264,7 @@ class CoredeviceTest(ExperimentCase): rate = self.dataset_mgr.get("pulse_rate") print(rate) self.assertGreater(rate, 100*us) - self.assertLess(rate, 400*us) + self.assertLess(rate, 150*us) def test_loopback_count(self): npulses = 2