spirv-fuzz: Add inline function transformation#3517
spirv-fuzz: Add inline function transformation#3517afd merged 18 commits intoKhronosGroup:masterfrom
Conversation
afd
left a comment
There was a problem hiding this comment.
This is a preliminary review with some top level feedback from having studied the IsApplicable function - please see attached in one of the comments some proposed tests for the HasEarlyReturn method of Function, and a different way to implement it.
This is a complex transformation so I expect we'll need a bit of iteration in the review process, but in general this is looking really good!
3f679e0 to
05add40
Compare
afd
left a comment
There was a problem hiding this comment.
The transformation is looking very promising! Some changes required.
78cb58e to
edfa85d
Compare
afd
left a comment
There was a problem hiding this comment.
This is coming along really well!
Rather than inserting comments in the code, here is a patch with some changes to the way the transformation works that I suggest you study and then incorporate (editing it as you see fit, of course):
The main things I've done here are:
-
Do require that the returned id - if defined in the function - is mapped. Now that we're handling a return via a copy object this is necessary
-
Require that parameter ids are not mapped. I had a mistake in my test where I had mapped a parameter id and this led to an applicable transformation that then failed to apply properly (fixed in the patch)
-
Handle insertion of the OpCopyObject for OpReturnValue while the OpReturnValue is being processed, and not later. That's cleaner for various reasons.
Can you apply these changes, and for my next review can you include tests to check the following (your existing tests might have this; I didn't look yet):
-
A function that directly uses OpKill or OpUnreachable cannot be inlined - please open an issue for the fact that we can relax this in the future: we can inline functions that use OpKill/OpUnreachable if the call site is not in a continue construct, but let's not do that in this PR.
-
A function that has multiple returns cannot be inlined
In the next review round I will look at the fuzzer pass.
edfa85d to
a0d8cff
Compare
|
I have not reviewed this yet, but this is a reminder to ensure that inlined dead blocks are also marked as dead. |
Vasniktel
left a comment
There was a problem hiding this comment.
This is a very nice transformation idea.
I've noticed some issues with the implementation and some tricky corner cases with the SPIR-V structured control-flow rules (which you are handling btw; I just left some comments regarding those).
And be sure to check Ally's previous review summary regarding OpKill and OpUnreachable.
paulthomson
left a comment
There was a problem hiding this comment.
This looks really good! And this is a hard transformation (as cloning multiple blocks is non-trivial). I think it is very close to being done, but I have left a few comments that need addressing. Although some are just minor comments about style.
2ea7e51 to
bfb5f38
Compare
Vasniktel
left a comment
There was a problem hiding this comment.
This looks nice!
However, I'd suggest you refactor Apply method in the transformation since there is no telling what can break by storing blocks directly in the instruction list (I'd assume that dominator analysis won't work for inlined blocks).
I'd suggest you do the following:
- Split the caller block in two: the first part containing all the instructions before the call and the second part containing all the instructions starting with a call onward (see
opt::BasicBlock::SplitBasicBlock). - Start creating blocks to inline and insert them before the second block (
opt::Function::InsertBasicBlockBefore). - Remove the OpFunctionCall instruction from the second block.
- Add a terminator to the first block pointing to the entry block of the inlined function.
With this approach, I think you can remove the constraint that the call must be the last instruction before the OpBranch. Although, you would need to check that the caller block is not a loop header.
15d2df7 to
0a5c041
Compare
afd
left a comment
There was a problem hiding this comment.
This is looking really good and is now very close!
Please see the comments that I just added requesting some (probably final) changes.
0cebf4b to
d0eea8b
Compare
afd
left a comment
There was a problem hiding this comment.
Thanks for making the changes.
This looks really good, and I'm happy to merge it!
Roll third_party/glslang/ 983698b..517f39e (1 commit) KhronosGroup/glslang@983698b...517f39e $ git log 983698b..517f39e --date=short --no-merges --format='%ad %ae %s' 2020-08-26 jmadill Suppress two override suggestion warnings. Created with: roll-dep third_party/glslang Roll third_party/googletest/ 1e315c5b1..df6b75949 (1 commit) google/googletest@1e315c5...df6b759 $ git log 1e315c5b1..df6b75949 --date=short --no-merges --format='%ad %ae %s' 2020-08-26 absl-team Googletest export Created with: roll-dep third_party/googletest Roll third_party/spirv-tools/ 4dd1223..8a0ebd4 (14 commits) KhronosGroup/SPIRV-Tools@4dd1223...8a0ebd4 $ git log 4dd1223..8a0ebd4 --date=short --no-merges --format='%ad %ae %s' 2020-08-31 jaebaek Correctly replace debug lexical scope of instruction (KhronosGroup#3718) 2020-08-28 afdx spirv-fuzz: Remove opaque pointer design pattern (KhronosGroup#3755) 2020-08-27 stefanomil spirv-fuzz: Create synonym via OpPhi and existing synonyms (KhronosGroup#3701) 2020-08-27 stefanomil Add LoopNestingDepth function to StructuredCFGAnalysis (KhronosGroup#3754) 2020-08-27 afdx spirv-fuzz: Do not make synonyms of void result ids (KhronosGroup#3747) 2020-08-26 greg Do not register DebugFunction for functions optimized away. (KhronosGroup#3749) 2020-08-26 jaebaek Handle DebugScope in compact-ids pass (KhronosGroup#3724) 2020-08-26 afdx spirv-fuzz: Overflow ids (KhronosGroup#3734) 2020-08-25 greg Fix DebugNoScope to not output InlinedAt operand. (KhronosGroup#3748) 2020-08-25 vasniktel spirv-fuzz: Split the fact manager into multiple files (KhronosGroup#3699) 2020-08-25 andreperezmaselco.developer spirv-fuzz: Add inline function transformation (KhronosGroup#3517) 2020-08-25 vasniktel spirv-fuzz: Fix MaybeGetZeroConstant (KhronosGroup#3740) 2020-08-24 greg Fix SSA-rewrite to remove DebugDeclare for variables without loads (KhronosGroup#3719) 2020-08-24 stevenperron Add undef for inlined void function (KhronosGroup#3720) Created with: roll-dep third_party/spirv-tools
Fixes #3505.