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

Ashley Coleman via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 12:38:17 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:

This is a very inefficient solution to this problem but I wanted to put it up for review anyways. 

It may be okay to leave this since 
1: The number of Invalid CounterDirections should always be under 10
2: This is already in a failure path so this only slows down invocations that aren't going to compile anyways

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


More information about the llvm-commits mailing list