Skip to content

Commit 4dfa76d

Browse files
committed
Address Comments
1 parent 66f32e4 commit 4dfa76d

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ class DXILResourceMap {
458458
unsigned FirstUAV = 0;
459459
unsigned FirstCBuffer = 0;
460460
unsigned FirstSampler = 0;
461+
bool HasInvalidDirection = false;
461462

462463
/// Populate all the resource instance data.
463464
void populate(Module &M, DXILResourceTypeMap &DRTM);
@@ -549,6 +550,8 @@ class DXILResourceMap {
549550
return make_range(call_begin(), call_end());
550551
}
551552

553+
bool hasInvalidCounterDirection() const { return HasInvalidDirection; }
554+
552555
void print(raw_ostream &OS, DXILResourceTypeMap &DRTM,
553556
const DataLayout &DL) const;
554557

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,10 @@ void DXILResourceMap::populateCounterDirections(Module &M) {
811811
for (ResourceInfo *RBInfo : RBInfos) {
812812
if (RBInfo->CounterDirection == ResourceCounterDirection::Unknown)
813813
RBInfo->CounterDirection = Direction;
814-
else if (RBInfo->CounterDirection != Direction)
814+
else if (RBInfo->CounterDirection != Direction) {
815815
RBInfo->CounterDirection = ResourceCounterDirection::Invalid;
816+
HasInvalidDirection = true;
817+
}
816818
}
817819
}
818820
}

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,58 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DXILPostOptimizationValidation.h"
10-
#include "DXILConstants.h"
11-
#include "DXILIntrinsicExpansion.h"
12-
#include "DXILOpBuilder.h"
1310
#include "DXILShaderFlags.h"
1411
#include "DirectX.h"
15-
#include "llvm/ADT/SmallVector.h"
1612
#include "llvm/Analysis/DXILMetadataAnalysis.h"
1713
#include "llvm/Analysis/DXILResource.h"
18-
#include "llvm/CodeGen/Passes.h"
1914
#include "llvm/IR/DiagnosticInfo.h"
20-
#include "llvm/IR/Function.h"
21-
#include "llvm/IR/IRBuilder.h"
22-
#include "llvm/IR/Instruction.h"
2315
#include "llvm/IR/Instructions.h"
24-
#include "llvm/IR/Intrinsics.h"
2516
#include "llvm/IR/IntrinsicsDirectX.h"
2617
#include "llvm/IR/Module.h"
27-
#include "llvm/IR/PassManager.h"
2818
#include "llvm/InitializePasses.h"
29-
#include "llvm/Pass.h"
30-
#include "llvm/Support/ErrorHandling.h"
31-
#include <cstdio>
3219

3320
#define DEBUG_TYPE "dxil-post-optimization-validation"
3421

3522
using namespace llvm;
3623
using namespace llvm::dxil;
3724

3825
namespace {
39-
class DXILValidator {
40-
Module &M;
41-
DXILResourceMap &DRM;
4226

43-
public:
44-
DXILValidator(Module &M, DXILResourceMap &DRM) : M(M), DRM(DRM) {}
45-
46-
void validate() {
47-
for (const auto &UAV : DRM.uavs()) {
48-
if (UAV.CounterDirection != ResourceCounterDirection::Invalid)
49-
continue;
27+
static void reportInvalidDirection(Module &M, DXILResourceMap &DRM) {
28+
for (const auto &UAV : DRM.uavs()) {
29+
if (UAV.CounterDirection != ResourceCounterDirection::Invalid)
30+
continue;
5031

51-
CallInst *ResourceHandle = nullptr;
52-
for (CallInst *MaybeHandle : DRM.calls()) {
53-
if (*DRM.find(MaybeHandle) == UAV) {
54-
ResourceHandle = MaybeHandle;
55-
break;
56-
}
32+
CallInst *ResourceHandle = nullptr;
33+
for (CallInst *MaybeHandle : DRM.calls()) {
34+
if (*DRM.find(MaybeHandle) == UAV) {
35+
ResourceHandle = MaybeHandle;
36+
break;
5737
}
38+
}
5839

59-
StringRef Message =
60-
"RWStructuredBuffers may increment or decrement their "
61-
"counters, but not both.";
62-
for (const auto &U : ResourceHandle->users()) {
63-
const CallInst *CI = dyn_cast<CallInst>(U);
64-
if (!CI && CI->getIntrinsicID() != Intrinsic::dx_resource_updatecounter)
65-
continue;
40+
StringRef Message = "RWStructuredBuffers may increment or decrement their "
41+
"counters, but not both.";
42+
for (const auto &U : ResourceHandle->users()) {
43+
const CallInst *CI = dyn_cast<CallInst>(U);
44+
if (!CI && CI->getIntrinsicID() != Intrinsic::dx_resource_updatecounter)
45+
continue;
6646

67-
M.getContext().diagnose(DiagnosticInfoGenericWithLoc(
68-
Message, *CI->getFunction(), CI->getDebugLoc()));
69-
}
47+
M.getContext().diagnose(DiagnosticInfoGenericWithLoc(
48+
Message, *CI->getFunction(), CI->getDebugLoc()));
7049
}
7150
}
72-
};
51+
}
52+
7353
} // namespace
7454

7555
PreservedAnalyses
7656
DXILPostOptimizationValidation::run(Module &M, ModuleAnalysisManager &MAM) {
7757
DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
7858

79-
DXILValidator(M, DRM).validate();
59+
if (DRM.hasInvalidCounterDirection())
60+
reportInvalidDirection(M, DRM);
61+
8062
return PreservedAnalyses::all();
8163
}
8264

@@ -87,7 +69,8 @@ class DXILPostOptimizationValidationLegacy : public ModulePass {
8769
DXILResourceMap &DRM =
8870
getAnalysis<DXILResourceWrapperPass>().getResourceMap();
8971

90-
DXILValidator(M, DRM).validate();
72+
if (DRM.hasInvalidCounterDirection())
73+
reportInvalidDirection(M, DRM);
9174

9275
return false;
9376
}

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// \file Pass for validating DXIL after lowering and optimizations are applied.
9+
// \file Pass for validating IR after optimizations are applied and before
10+
// lowering to DXIL.
1011
//
1112
//===----------------------------------------------------------------------===//
1213

0 commit comments

Comments
 (0)