[RFC] Adding HLSL and DirectX support to Clang & LLVM

There was some informal discussion in the past of making clang do code generation through MLIR. clang’s “codegen” is really doing too many things at once, so adding an extra stage between the AST and LLVM IR would have some benefits. Among other things, it would let us share code between clang’s “CodeGen”, and the static analysis “CFG”. MLIR would probably be an effective framework for implementing such a “clang IR” layer between the clang AST and LLVM IR; it’s easily extensible, and it already has an LLVM IR dialect. But nobody has really looked at it seriously, as far as I know; it’s a really big project, and the benefits are sort of speculative.

That said, even if we had that, it’s not clear to me that you’d want to use it directly for SPIR-V or DXIL code generation. We probably wouldn’t run many optimizations on the “clang IR” dialect, so you’d end up with almost completely unoptimized code, I think.

1 Like