This question evaluates understanding of compiler architecture for graphics shaders—covering lexical analysis, AST construction, SSA-based intermediate representations, optimization passes, register allocation, code generation, and testing strategies—and measures competency in compiler theory, graphics shading languages, program transformation, and verification. It is categorized under Coding & Algorithms with a domain focus on compilers and graphics, commonly asked to probe architectural reasoning about correctness and performance, and combines conceptual understanding of compiler design with practical application in implementation and testing.
Describe the architecture of a shader compiler that ingests GLSL/HLSL and outputs SPIR-V or ISA. Cover lexical analysis, parsing to AST, conversion to SSA-based IR, optimization passes (e.g., constant folding, CSE, dead-code elimination), register allocation, and code generation. How would you design differential and property-based tests for such a compiler?