Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ast_tools ssa #433

Closed
wants to merge 8 commits into from
Closed

Migrate to ast_tools ssa #433

wants to merge 8 commits into from

Conversation

leonardt
Copy link
Collaborator

Depends on leonardt/ast_tools#11

Also, there's still some cleanup to do w.r.t. the handling of the environment/names (mainly that the combinational and sequential passes rely on injecting some names in to the environment, we should make sure we're being safe about how we're doing this or use a different strategy).

@coveralls
Copy link

coveralls commented Aug 30, 2019

Pull Request Test Coverage Report for Build 1973

  • 62 of 73 (84.93%) changed or added relevant lines in 2 files are covered.
  • 39 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.8%) to 73.414%

Changes Missing Coverage Covered Lines Changed/Added Lines %
magma/syntax/combinational.py 26 29 89.66%
magma/syntax/sequential.py 36 44 81.82%
Files with Coverage Reduction New Missed Lines %
magma/syntax/util.py 3 57.14%
magma/ast_utils.py 36 26.58%
Totals Coverage Status
Change from base Build 1967: -0.8%
Covered Lines: 4131
Relevant Lines: 5627

💛 - Coveralls

@leonardt leonardt mentioned this pull request Aug 30, 2019
@leonardt
Copy link
Collaborator Author

Still working through some issues in the peak/lassen flows so we should wait to pull until those repos are working with this branch.

@ast_tools.passes.end_rewrite()
@m.circuit.combinational()
@ast_tools.passes.begin_rewrite()
def {circuit_name}_comb({circuit_combinational_args}) -> ({circuit_combinational_output_type}):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we build the AST and directly call m.circuit.combinational()? This would avoid needing to inject ast_tools into env.

)
combinational = m.circuit.combinational(decorators=[sequential])
return wrapped_sequential(True, cls, combinational)
if "DefineRegister" not in env:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a bit paranoid but all of these should should be injecting with a free name then passing the generated names around. e.g.:

def gen_register_instances(def_reg_name, initial_value_map, async_reset):
    register_instances = []
    for name, (value, type_, eval_type, eval_value) in initial_value_map.items():
        if isinstance(eval_type, m.Kind):
            if isinstance(eval_type, m._BitKind):
                n = None
                if isinstance(eval_value, (bool, int)):
                    init = bool(eval_value)
                else:
                    assert eval_value.name.name in ["GND", "VCC"], eval_value.name
                    init = 0 if eval_value.name.name == "GND" else 1
            else:
                n = len(eval_type)
                init = int(eval_value)
            register_instances.append(f"{name} = {def_reg_name}({n}, init={init}, has_async_reset={async_reset})()")  # noqa
        else:
            value = astor.to_source(value).rstrip()
            register_instances.append(f"{name} = {value}")
    return register_instances

decorators=decorators)
return wrapped_combinational(fn)
return wrapped
phi_name = ast_tools.gen_free_name(tree, env,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary see below

return env[mux_name]([arg1, arg0], cond)

env.locals[phi_name] = phi
tree, env, metadata = ast_tools.passes.if_to_phi(phi_name).rewrite(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if_to_phi will generate a name for you with an optional prefix with the same logic that you have. Just call:
ast_tools.passes.if_to_phi(phi, 'magma_combinational_phi').rewrite(...)

https://github.com/leonardt/ast_tools/blob/master/tests/test_if_to_phi.py#L23

https://github.com/leonardt/ast_tools/blob/master/ast_tools/passes/if_to_phi.py#L42

@leonardt
Copy link
Collaborator Author

leonardt commented Apr 7, 2020

Closing in favor of #668

@leonardt leonardt closed this Apr 7, 2020
@leonardt leonardt deleted the new-ssa branch April 7, 2020 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants