[llvm] [DXIL] Define and generate `DXILAttribute` and `DXILProperty` (PR #117072)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 12 18:57:06 PST 2025


bogner wrote:

Personally I think we should rip out all of the codegen for properties until we're actually doing something with them. It might be fine to have them in DXIL.td if we want to copy these over as we go, but the DXILEmitter stuff really shouldn't be there until we're using the properties in code.

Note that this whole approach, for both attributes and properties, is continuing a bit of an antipattern that's already there. It would be much nicer if we used tablegen to generate tables rather than using is as a generic c++ code emitter.

Consider, in DXILConstants.h we could define a structure instead of an enum:
```c++
struct Properties {
#define DXIL_PROPERTY(Name) bool Name;
#include "DXILOperation.inc"
};
```

Then, in DXILOpBuilder rather than adding to the OpCodeProperty mess we could simpy have a function like:
```c++
static void setDXILProperties(dxil::OpCode OpCode, CallInst *CI) {
  dxil::Properties Props;
  switch (OpCode) {
#define DXIL_OP_PROPERTIES(OpCode, ...)                                        \
  case OpCode:                                                                 \
    Props = {__VA_ARGS__};                                                     \
    break;
#include "DXILOperation.inc"
  }
  if (Props.IsBarrier)
    ...
  if (Props.IsGradient)
    ...
  if (Props.IsFeedback)
    ...
  if (Props.IsWave)
    ...
  if (Props.RequiresUniformInputs)
    ...
}
```

Where instead of building a string of all of the properties we simply emit a table of bools:
```
// op xyz is a barrier and a gradient, but not feedback, wave, or requires uniform inputs
DXIL_OP_PROPERTIES(dxil::opcode::xyz, true, true, false, false, false)
```

A similar approach should probably be applied to attributes, but it's a bit more complicated if we want to have the versioning so I think it's reasonable to do that as part of a more general cleanup of DXILEmitter later.

https://github.com/llvm/llvm-project/pull/117072


More information about the llvm-commits mailing list