Replies: 1 comment 1 reply
-
Upon further pondering, I've realized that I can handle this via a rewrite rule along the lines of:
and then let constant folding take care of it from there. However, I'm still curious whether this could have been done via an analysis pass (and in general, how to think about the difference between what to do via |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to write an Analysis pass that both does constant folding and also does things like rewrite
(/ x 2)
to(* x 0.5)
; I haven't been able to figure out the right way to do that (or, if that is something I should be trying to do in an Analysis pass in the first place).The approach I had tried was to define
Data
asOption<MyLanguage>
in my analysis pass. That works fine for constant folding; I can just returnSome(MyLanguage::Constant(xyz))
. For strength reduction I had tried the following (in amatch
statement):However, that doesn't work since the
EGraph
passed toAnalysis.make()
is not mutable, so theegraph.add()
call is invalid. (And I can't see another way to properly make a node for an operation in my language otherwise.)I was thinking that I could just make
Data
be anOption<String>
or something like that and then parse those strings into proper nodes in mymodify()
method, but that seemed a little hacky (and also seems like it might prevent optimizations that depend on e.g. first constant folding and then strength reduction, e.g. for(/ x (+ 1 1))
, though I'm not sure if that's the case...)Any guidance would be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions