sampsyo/bril

[DF] defined analysis producing wrong output.

Opened this issue · 1 comments

Example

# bril2json < p.bril | python3 ../../df.py defined

@main(awesome_integer: int) {
.entry:
  print awesome_integer;
}

Actual:

entry:
  in:  ∅ 
  out: ∅

Expected

awesome_integer should be defined in .entry.

entry:
  in:  awesome_integer
  out: awesome_integer

I think the issue here is two-fold.

  1. There's no simple way to pass in arguments to the analyses. Here, we pass in an analysis with a defaulted (empty) data structure. However, for an analysis such as reaching definitions or defined analysis, we want to pass in the function arguments to the first block.

    bril/examples/df.py

    Lines 82 to 92 in dbbd8e8

    def run_df(bril, analysis):
    for func in bril['functions']:
    # Form the CFG.
    blocks = cfg.block_map(form_blocks(func['instrs']))
    cfg.add_terminators(blocks)
    in_, out = df_worklist(blocks, analysis)
    for block in blocks:
    print('{}:'.format(block))
    print(' in: ', fmt(in_[block]))
    print(' out:', fmt(out[block]))

  2. Even if we do pass in the correct function arguments,

    bril/examples/df.py

    Lines 48 to 49 in dbbd8e8

    inval = analysis.merge(out[n] for n in in_edges[node])
    in_[node] = inval

inval = analysis.merge(out[n] for n in in_edges[node]) # in_edges[.entry] == []

So, even though in_[.entry] is initialized correctly, it is over-written afterward.

As usual, let me know if I'm off-target.

Yeah, I wrote the DF analysis examples before function parameters existed. The right thing to do is to still use empty sets as the initial values but essentially hallucinate an entry block that defines the parameters.