def __init__(self, fundef, llvm_cxt=llvm_context.global_context): self.parakeet_fundef = fundef if config.opt_stack_allocation: self.may_escape = may_escape(fundef) else: self.may_escape = None self.llvm_context = llvm_cxt self.vars = {} self.initialized = set([]) # Initializes the variables dictionary and returns a builder object llvm_input_types = map(llvm_ref_type, fundef.input_types) llvm_output_type = llvm_ref_type(fundef.return_type) llvm_fn_t = lltype.function(llvm_output_type, llvm_input_types) self.llvm_fn = self.llvm_context.module.add_function( llvm_fn_t, fundef.name) for arg in self.llvm_fn.args: if not llvm_types.is_scalar(arg.type): arg.add_attribute(ATTR_NO_CAPTURE) self.llvm_fn.does_not_throw = True self.entry_block, self.entry_builder = self.new_block("entry") self._init_vars(self.parakeet_fundef, self.entry_builder)
def _init_vars(self, fundef, builder): """ Create a mapping from variable names to stack locations, these will later be converted to SSA variables by the mem2reg pass. """ n_expected = len(fundef.arg_names) n_compiled = len(self.llvm_fn.args) assert n_compiled == n_expected, \ "Expected %d args (%s) but compiled code had %d args (%s)" % \ (n_expected, fundef.arg_names, n_compiled, self.llvm_fn.args) for (name, t) in fundef.type_env.iteritems(): if not name.startswith("$"): llvm_t = llvm_ref_type(t) stack_val = builder.alloca(llvm_t, name) self.vars[name] = stack_val for llvm_arg, name in zip(self.llvm_fn.args, fundef.arg_names): self.initialized.add(name) llvm_arg.name = name if name in self.vars: builder.store(llvm_arg, self.vars[name])
def __init__(self, fundef, llvm_cxt = llvm_context.global_context): self.parakeet_fundef = fundef if config.opt_stack_allocation: self.may_escape = escape_analysis.may_escape(fundef) else: self.may_escape = None self.llvm_context = llvm_cxt self.vars = {} self.initialized = set([]) # Initializes the variables dictionary and returns a builder object llvm_input_types = map(llvm_ref_type, fundef.input_types) llvm_output_type = llvm_ref_type(fundef.return_type) llvm_fn_t = lltype.function(llvm_output_type, llvm_input_types) self.llvm_fn = self.llvm_context.module.add_function(llvm_fn_t, fundef.name) for arg in self.llvm_fn.args: if not llvm_types.is_scalar(arg.type): arg.add_attribute(ATTR_NO_CAPTURE) self.llvm_fn.does_not_throw = True self.entry_block, self.entry_builder = self.new_block("entry") self._init_vars(self.parakeet_fundef, self.entry_builder)