Add bool gototarget to CaseStatement and DefaultStatement#5501
Add bool gototarget to CaseStatement and DefaultStatement#5501JohanEngelen wants to merge 2 commits intodlang:masterfrom
bool gototarget to CaseStatement and DefaultStatement#5501Conversation
At this point in the code, `sc.sw == this`. The meaning of the code here is to set some variables correctly for `this` SwitchStatement. Removal of `sc.sw.` makes that much more clear. (Note that none of the other variables are accessed through `sc.sw.`)
…is set to true when the switch contains a `goto case` targetting that `CaseStatement` (or `DefaultStatement`) `gototarget` is used in LDC for PGO. The variable is not currently used in DMD, but may be useful in the future, e.g. for control flow analysis.
|
There's something very iffy about this PR. |
|
I'm pretty certain you can achieve what you are doing without this addition. I'm just going off memory, but the frontend validates all goto targets, including forward references, so this information should be available in ast by the time you reach the backend. |
|
It's true that there might be a better way of doing this. In fact, that was also my reaction when reading the LDC PR diff. However, I can't say from memory (or having a glance at the code) how to efficiently do it, hence I suggested just raising a PR here. My hope is that somebody who knows a better solution will use it as an argument for turning this PR down. ;) |
|
Of course it is in the AST: when you hit a CaseStatement, go up to the SwitchStatement and traverse all of the code in all cases, and find whether there is a "goto case" for your particular CaseStatement. |
|
Compare with |
|
Ping @WalterBright @yebblies. |
|
I don't think this should be added unless there is an imminent plan for using it. |
|
It is being used in LDC right now. This PR is just the same as #5577 – In the bigger picture, the comparison to #5577 highlights one major reason for the considerable diff between the DMD and LDC frontends right now: The AST output is very much tailored to exactly what the DMD glue layer needs, whereas we can't just add whatever is convenient for LDC to the upstream source. |
|
Maybe we should have something in place to push information relevant for a particular backend? Though I would be surprised if you can't go this in llvm ast. I'm using gcc language-specific structures (opaque in the backend) to store more information away to rely less on the Frontend into gcc trees. Soon I won't even be using the frontend to cache backend pointers. |
|
@JohanEngelen please close. |
|
In the meantime - I've filed an issue here: https://issues.dlang.org/show_bug.cgi?id=17166 |
|
@JohanEngelen status? should I just close? |
|
I don't understand why this hasn't been merged. It adds analysis functionality to the frontend that is useful and used by at least one backend. For me, it's been a nice example of why LDC needs its own frontend to progress, but manpower is limited so I don't push for it. By now the PR needs work to be mergable, and I won't do it. |
|
@JohanEngelen sorry about that! @WalterBright think you could take this over? |
|
or @RazvanN7 |
|
From @WalterBright
From @ibuclaw
From @JohanEngelen
There doesn't appear to be much support for this and @JohanEngelen is clearly not interested in pursuing it. An issue was filed at https://issues.dlang.org/show_bug.cgi?id=17166 to capture the problem. Therefore, I'm closing this. |
|
To capture the essence of my tone better:
There's no excuse why DMD can't follow my lead here and remove their own boilerplate. |
|
Added to Phantom Zone because indeed this is useful for doing flow analysis (the CSX flows). I don't know yet if it is the right answer, but it is good as a starting point. |
(First commit is a small cleanup in SwitchStatement.semantic.)
Add
bool gototargettoCaseStatementandDefaultStatementthat is set to true when the switch contains agoto casetargetting thatCaseStatement(orDefaultStatement)gototargetis used in LDC for PGO.The variable is not currently used in DMD, but may be useful in the future, e.g. for control flow analysis.
Note that I also had to create SwitchStatement.hasGotoDefault variable. I did not find a satisfactory way to avoid creating that variable.