-
Notifications
You must be signed in to change notification settings - Fork 13
Add RemoveControlFlowPass #194
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
base: main
Are you sure you want to change the base?
Conversation
d39546f to
44225b7
Compare
|
Hi @asl, It doesn't change it at this point, but when changing a lot of things it complains about boolean condition for |
asl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser control flow simplification pass, as stated in the name, is expected to work on ... parsers (!). There is very little (if not negative) sense to convert ordinary conditions to switches either.
Have you tried to read the description at https://github.com/p4lang/p4c/blob/main/frontends/p4/parserControlFlow.h#L27 ?
|
Another thing to watch out for is that in P4C this pass requires all declarations to be at the "top", basically moving them all before the first state, with I looked into this before and ran into issues with something like (dumb example): But if you ran this example without any processing you'd get: Good luck! |
This is just the limitation of P4C pass (as there is no sane way to track normal def-use chains there). We do not need all declarations to be moved there, only those variables that are defined in the "top" part of the state and used in the "bottom" one. |
@asl I am thinking of implementing two passes for renaming and hoisting vars, what do you think? |
Not sure why something like this is needed. Maybe you'd better start with some RFC describing:
|
|
don't you think we need to implement the hoisting pass for similar cases mentioned here #194 (comment) if not what do you suggest? |
Why this is needed? What problems will it solve? This is exactly why you'd need to start from RFC. |
|
I think I don't need the renaming, and hoisting pass, as it is SSA form after all, so all vars in the same states are unique. but we need to move only Declarations in the top of the state that have uses after the regarding the variable names: as all states in the same scope are unique so for the state vars
There will be a name conflict if there is already a state with same name as the resulted names. |
|
Looks like you're making simple things too complex. Also for some reason you're not following P4HIR semantics. So let me summarize a bit:
Oh, yes, and pass should handle switches and ternary ops as well. Though it is pretty straightforward as soon as the majority of the code is in place. |
Signed-off-by: Mohamed Atef <[email protected]>
44225b7 to
4a9ff1c
Compare
|
@asl, It doesn't handle switch yet. but I thought it is a good idea to show you where did I reach. input output |
|
Ah, sorry I passed true value for the false state, too. I will modify it tomorrow, it is 1 am here. But is the logic correct? |
p4hir.select_case {
p4hir.yield %true : !p4hir.bool
} to @simple_parser::@start_if_true_0Select cases are expected to yield sets. We have TBD for the verifier here. So, it should be: p4hir.select_case {
%set = p4hir.set (%true) : !p4hir.set<!p4hir.bool>
p4hir.yield %set : !p4hir.set<!p4hir.bool>
} to @simple_parser::@start_if_true_0 |
No description provided.