[llvm] [HLSL] Raise Diag for Invalid CounterDirection (PR #137697)

Ashley Coleman via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 09:46:53 PDT 2025


================
@@ -0,0 +1,119 @@
+//===- DXILPostOptimizationValidation.cpp - Opt DXIL validation ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DXILPostOptimizationValidation.h"
+#include "DXILConstants.h"
+#include "DXILIntrinsicExpansion.h"
+#include "DXILOpBuilder.h"
+#include "DXILShaderFlags.h"
+#include "DirectX.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/DXILMetadataAnalysis.h"
+#include "llvm/Analysis/DXILResource.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <cstdio>
+
+#define DEBUG_TYPE "dxil-post-optimization-validation"
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+namespace {
+class DXILValidator {
+  Module &M;
+  DXILResourceMap &DRM;
+
+public:
+  DXILValidator(Module &M, DXILResourceMap &DRM) : M(M), DRM(DRM) {}
+
+  void validate() {
+    for (const auto &UAV : DRM.uavs()) {
+      if (UAV.CounterDirection != ResourceCounterDirection::Invalid)
+        continue;
+
+      CallInst *ResourceHandle = nullptr;
+      for (CallInst *MaybeHandle : DRM.calls()) {
----------------
V-FEXrt wrote:

> why is the number of Invalid CounterDirections always going to be under 10?

Sorry I asserted the `10` number too hard. What I meant is something more like "in practice Invalid Counter Direction numbers will be low since the user would have to create a large number of programming errors in a large project without compiling/fixing them" while very possible it seems like a very strange way to develop and doing so would likely result in a bunch of other errors also being raised. Ultimately, I made up `10`  as a shortcut to say that which I shouldn't have

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


More information about the llvm-commits mailing list