Well, it'd have to have an SSA value. E.g. you can have expressions like "x[1].xyzw".
Hmmp, in this case `x` would be an `HLSL_IR_REFERENCE`, and then `x[1]` would be another `HLSL_IR_REFERENCE` (note that `x[1]` doesn't point to `x`, because, to create `x[1]` the deref is copied and then an src to the `1` node is appended to it).
Then, the swizzle should indeed have point to `x[1]`, but there are either 2 possibilities: - If this is in a lhs, we should invert the swizzle into the rhs as we are doing now, leaving only the `HLSL_IR_REFERENCE` at the lhs (in case there are multiple swizzles, we fold them). - If this is an rhs or part of an expression, then `x[1]` must be turned into a `HLSL_IR_LOAD` in order to be used by the swizzle. The "evaluation" function that replaces the `HLSL_IR_REFERENCE` with `HLSL_IR_LOADS` should also consider this. A scary alternative: adding swizzles to the derefs.
`HLSL_IR_REFERENCE` isn't a bad name, I'll also throw out `HLSL_IR_INDEX` [to match e.g. hlsl_new_load_index().]
I am not sure about `HLSL_IR_INDEX`, at first I interpreted it as a node that references 2 nodes: A value node and an index node (`x` and `1` for `x[1]`), I am not sure if that was the intent. I tried to implement that, but gets complicated fast (and it doesn't cover the base case: the reference of the variable alone, `x`). I realized that is far simpler to have the whole deref into one node (basically the same way as `HLSL_IR_LOAD`).
`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.
Wait, why?
I mean, it is not mandatory, but at the moment seems like a logical step.
Currently we are using an `HLSL_IR_LOAD` to initialize the lhs of an `HLSL_IR_STORE`, but we only care about the deref, and now `HLSL_IR_REFERENCE` will care about that. In the same way, we are currently using an `HLSL_IR_RESOURCE_LOAD`'s deref and `coords` to initialize `HLSL_IR_RESOURCE_STORE`, but not the `HLSL_IR_RESOURCE_LOAD` itself; so we could use `HLSL_IR_REFERENCE` for that too, adding the additional fields.