diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-02-16 09:04:44 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-16 09:04:44 -0800 |
| commit | 1b93da040ef00836438437e998c1c9584e3fd4ac (patch) | |
| tree | aa740da003832a7c0e653883c7cc739fab12e8ba /source/slang/ir-ssa.cpp | |
| parent | 32549707cc9aa67dbc19cbdc0490ffebc8ec253c (diff) | |
IR/Vulkan fixes (#412)
* Fix bugs around IR legalization of GLSL input/output
- Add case to handle assignment of one `ScalarizedVal::Flavor::address` to another (still need to make sure we are handling all the possible cases there)
- Revamp logic for creating global variable declarations for varying inputs/outputs.
- Actually handle creating array declarations (not sure if binding locations will be correct)
- Properly deal with offsetting of locations for nested fields
- Only create varying input/output layout information as needed for the separate `in` and `out` variables we create to represent a single HLSL `inout` varying
* During SSA generation, recursively remove trivial phis
This is actually written up in the original paper I used as a reference, but I hadn't implemented the case yet.
When you eliminate one phi as trivial (because its only operands were itself and at most one other value), you might find that another phi becomes trivial (because it had this phi as an operand, but now it will have the other value...).
The one thing that made any of this tricky is that our "phi" nodes are really block parameters, and thus they don't technically have operands (`IRUse`s). The `IRUse`s for each phi were being tracked in a separate array, and had their `user` field set to null.
With this change, I set their `user` to be the corresponding `IRParam` for the phi (and that means I changed `IRParam` to inherit from `IRUser` even though it shouldn't really be required).
* Re-build SSA form after specialization/legalization
The main reason to do this is that legalization might scalarize types, and thus might allow us to clean up resource-type local variables that we were not able to clean up when they were part of an aggregate.
Note: we shouldn't really need to do this, because the front-end should actually be guaranteeing that types that include resources are used in "safe" ways, but we currently don't have the analyses required to support that.
* Give an error message if we get GLSL input
The API and command-line interface still recognize and nominally support GLSL input files, because they need to be supported in the "pass-through" mode.
This change just adds an error message if we encounter a GLSL input file in anything other than "pass-through" mode.
Diffstat (limited to 'source/slang/ir-ssa.cpp')
| -rw-r--r-- | source/slang/ir-ssa.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/source/slang/ir-ssa.cpp b/source/slang/ir-ssa.cpp index 432dfc1b1..53eefd81f 100644 --- a/source/slang/ir-ssa.cpp +++ b/source/slang/ir-ssa.cpp @@ -89,7 +89,9 @@ struct ConstructSSAContext PhiInfo* getPhiInfo(IRParam* phi) { - return *phiInfos.TryGetValue(phi); + if(auto found = phiInfos.TryGetValue(phi)) + return *found; + return nullptr; } }; @@ -219,7 +221,7 @@ PhiInfo* addPhi( } IRValue* tryRemoveTrivialPhi( - ConstructSSAContext* /*context*/, + ConstructSSAContext* context, PhiInfo* phiInfo) { auto phi = phiInfo->phi; @@ -266,6 +268,26 @@ IRValue* tryRemoveTrivialPhi( assert(!"unimplemented"); } + // Removing this phi as trivial may make other phi nodes + // become trivial. We will recognize such candidates + // by looking for phi nodes that use this node. + List<PhiInfo*> otherPhis; + for( auto u = phi->firstUse; u; u = u->nextUse ) + { + auto user = u->user; + if(!user) continue; + if(user == phi) continue; + + if( user->op == kIROp_Param ) + { + auto maybeOtherPhi = (IRParam*) user; + if( auto otherPhiInfo = context->getPhiInfo(maybeOtherPhi) ) + { + otherPhis.Add(otherPhiInfo); + } + } + } + // replace uses of the phi (including its possible uses // of itself) with the unique non-phi value. phi->replaceUsesWith(same); @@ -281,8 +303,12 @@ IRValue* tryRemoveTrivialPhi( // phi, so that we can easily look it up later. phiInfo->replacement = same; - // TODO: need to recursively consider chances to simplify - // other phi nodes now. + // Now that we've cleaned up this phi, we need to consider + // other phis that might have become trivial. + for( auto otherPhi : otherPhis ) + { + tryRemoveTrivialPhi(context, otherPhi); + } return same; } @@ -320,7 +346,7 @@ IRValue* addPhiOperands( phiInfo->operands.SetSize(operandCount); for(UInt ii = 0; ii < operandCount; ++ii) { - phiInfo->operands[ii].init(nullptr, operandValues[ii]); + phiInfo->operands[ii].init(phiInfo->phi, operandValues[ii]); } return tryRemoveTrivialPhi(context, phiInfo); |
