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

Use slot names to get names of variables for metadata #17

Open
phipsgabler opened this issue Oct 30, 2019 · 2 comments
Open

Use slot names to get names of variables for metadata #17

phipsgabler opened this issue Oct 30, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@phipsgabler
Copy link
Member

phipsgabler commented Oct 30, 2019

The question is how to get them out of the IR objects, and where to put them.

julia> f2(x) = (y = x + 1; 2y)
f2 (generic function with 1 method)        

julia> code_lowered(f2, (Int,))[1]
CodeInfo(
1 ─      y = x + 1
│   %2 = 2 * y
└──      return %2

julia> code_lowered(f2, (Int,))[1].slotnames
3-element Array{Symbol,1}:
 Symbol("#self#")
 :x              
 :y      

julia> c = code_lowered(f3, (Int,))[1]
CodeInfo(
1 ─      y = x + 1
│   %2 = 2 * y
│   %3 = Main.sin(%2)
└──      return %3
)

julia> c.code[2]
:(2 * _3)

julia> c.code[2].args[3]
:(_3)

julia> c.code[2].args[3].id
3

julia> c.slotnames[c.code[2].args[3].id]
:y
@phipsgabler
Copy link
Member Author

For IRTools, to circumvent FluxML/IRTools.jl#31:

julia> ir = IRTools.IR(typeof(f3), Int; slots = true)
1: (%1, %2)
  %3 = %2 + 1
  %4 = @_3 = %3
  %5 = 2 * @_3
  %6 = Main.sin(%5)
  return %6


julia> ir.meta.code.slotnames[1:ir.meta.nargs]
2-element Array{Symbol,1}:
 Symbol("#self#")
 :x  

@phipsgabler phipsgabler added the enhancement New feature or request label Oct 31, 2019
@phipsgabler
Copy link
Member Author

The simplese approach would probably be to implement an IR transformation working on "slotted" IR to produce something equivalent to its "unslotted" version, but with the relevant Vars replaced by a new NamedVar type containing the name as well, and apply it right after or before explicitbranch!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant