After thinking about this for a while, and grabbing some ideas from when we discussed this issue, I think that we should split `HLSL_IR_LOAD` into two:
- `HLSL_IR_LOAD`: represents a load from a variable to a temp, cannot be used as an lhs. - `HLSL_IR_REFERENCE`: Merely contains a deref to a variable (or a part of it) but doesn't have an SSA value and cannot be used as a source.
So, while parsing we always work with an `HLSL_IR_REFERENCE`, until a value is required (for instance, as part of an expression), in which case, an `HLSL_IR_LOAD` has to be created from the `HLSL_IR_REFERENCE` (basically just copying the deref).
`HLSL_IR_REFERENCE` would probably also need an additional field with resource locations for creating `HLSL_IR_RESOURCE_LOAD` and `HLSL_IR_RESOURCE_STORE`, when a Texture or UAV is indexed. This could also be the solution for SM 5.1 resource arrays.
A side-effect of these changes would be changing all the ``` /* Only HLSL_IR_LOAD can return an object. */ ``` comments to ``` /* Only HLSL_IR_REFERENCE can return an object. */ ``` or would allow to remove them.
I am currently trying this approach.