[clang] [HLSL] Implement `SpirvType` and `SpirvOpaqueType` (PR #134034)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 21 15:27:45 PDT 2025


================
@@ -5444,6 +5459,31 @@ QualType ASTContext::getHLSLAttributedResourceType(
 
   return QualType(Ty, 0);
 }
+
+QualType ASTContext::getHLSLInlineSpirvType(uint32_t Opcode, uint32_t Size,
+                                            uint32_t Alignment,
+                                            ArrayRef<SpirvOperand> Operands) {
+  llvm::FoldingSetNodeID ID;
+  HLSLInlineSpirvType::Profile(ID, Opcode, Size, Alignment, Operands);
+
+  void *InsertPos = nullptr;
+  HLSLInlineSpirvType *Ty =
+      HLSLInlineSpirvTypes.FindNodeOrInsertPos(ID, InsertPos);
+  if (Ty)
+    return QualType(Ty, 0);
+
+  unsigned size = sizeof(HLSLInlineSpirvType);
+  size += Operands.size() * sizeof(SpirvOperand);
+  void *mem = Allocate(size, alignof(HLSLInlineSpirvType));
+
+  Ty = new (mem) HLSLInlineSpirvType(Opcode, Size, Alignment, Operands);
----------------
llvm-beanz wrote:

nit: https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly
```suggestion
  void *Mem = Allocate(size, alignof(HLSLInlineSpirvType));

  Ty = new (Mem) HLSLInlineSpirvType(Opcode, Size, Alignment, Operands);
```

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


More information about the cfe-commits mailing list