-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Raise Diag for Invalid CounterDirection #137697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50a114f
[HLSL] Raise Diag for Invalid CounterDirection
V-FEXrt 66f32e4
Merge branch 'main' into 135672-raise-counter-diag-2
V-FEXrt 4dfa76d
Address Comments
V-FEXrt 75bd70c
Merge branch 'main' into 135672-raise-counter-diag-2
V-FEXrt e108206
Merge branch 'main' into 135672-raise-counter-diag-2
V-FEXrt 3ff8c89
Merge branch 'main' into 135672-raise-counter-diag-2
V-FEXrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//===- 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 "DXILShaderFlags.h" | ||
#include "DirectX.h" | ||
#include "llvm/Analysis/DXILMetadataAnalysis.h" | ||
#include "llvm/Analysis/DXILResource.h" | ||
#include "llvm/IR/DiagnosticInfo.h" | ||
#include "llvm/IR/Instructions.h" | ||
#include "llvm/IR/IntrinsicsDirectX.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/InitializePasses.h" | ||
|
||
#define DEBUG_TYPE "dxil-post-optimization-validation" | ||
|
||
using namespace llvm; | ||
using namespace llvm::dxil; | ||
|
||
namespace { | ||
|
||
static void reportInvalidDirection(Module &M, DXILResourceMap &DRM) { | ||
for (const auto &UAV : DRM.uavs()) { | ||
if (UAV.CounterDirection != ResourceCounterDirection::Invalid) | ||
continue; | ||
|
||
CallInst *ResourceHandle = nullptr; | ||
for (CallInst *MaybeHandle : DRM.calls()) { | ||
if (*DRM.find(MaybeHandle) == UAV) { | ||
ResourceHandle = MaybeHandle; | ||
break; | ||
} | ||
} | ||
|
||
StringRef Message = "RWStructuredBuffers may increment or decrement their " | ||
"counters, but not both."; | ||
for (const auto &U : ResourceHandle->users()) { | ||
const CallInst *CI = dyn_cast<CallInst>(U); | ||
if (!CI && CI->getIntrinsicID() != Intrinsic::dx_resource_updatecounter) | ||
continue; | ||
|
||
M.getContext().diagnose(DiagnosticInfoGenericWithLoc( | ||
Message, *CI->getFunction(), CI->getDebugLoc())); | ||
} | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
PreservedAnalyses | ||
DXILPostOptimizationValidation::run(Module &M, ModuleAnalysisManager &MAM) { | ||
DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M); | ||
|
||
if (DRM.hasInvalidCounterDirection()) | ||
reportInvalidDirection(M, DRM); | ||
|
||
return PreservedAnalyses::all(); | ||
} | ||
|
||
namespace { | ||
class DXILPostOptimizationValidationLegacy : public ModulePass { | ||
public: | ||
bool runOnModule(Module &M) override { | ||
DXILResourceMap &DRM = | ||
getAnalysis<DXILResourceWrapperPass>().getResourceMap(); | ||
|
||
if (DRM.hasInvalidCounterDirection()) | ||
reportInvalidDirection(M, DRM); | ||
|
||
return false; | ||
} | ||
StringRef getPassName() const override { | ||
return "DXIL Post Optimization Validation"; | ||
} | ||
DXILPostOptimizationValidationLegacy() : ModulePass(ID) {} | ||
|
||
static char ID; // Pass identification. | ||
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override { | ||
AU.addRequired<DXILResourceWrapperPass>(); | ||
AU.addPreserved<DXILResourceWrapperPass>(); | ||
AU.addPreserved<DXILMetadataAnalysisWrapperPass>(); | ||
AU.addPreserved<ShaderFlagsAnalysisWrapper>(); | ||
} | ||
}; | ||
char DXILPostOptimizationValidationLegacy::ID = 0; | ||
} // end anonymous namespace | ||
|
||
INITIALIZE_PASS_BEGIN(DXILPostOptimizationValidationLegacy, DEBUG_TYPE, | ||
"DXIL Post Optimization Validation", false, false) | ||
INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass) | ||
INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapperPass) | ||
INITIALIZE_PASS_END(DXILPostOptimizationValidationLegacy, DEBUG_TYPE, | ||
"DXIL Post Optimization Validation", false, false) | ||
|
||
ModulePass *llvm::createDXILPostOptimizationValidationLegacyPass() { | ||
return new DXILPostOptimizationValidationLegacy(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===- DXILPostOptimizationValidation.h - Opt DXIL Validations -*- C++ -*--===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// \file Pass for validating IR after optimizations are applied and before | ||
// lowering to DXIL. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_DIRECTX_DXILPOSTOPTIMIZATIONVALIDATION_H | ||
#define LLVM_LIB_TARGET_DIRECTX_DXILPOSTOPTIMIZATIONVALIDATION_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
class DXILPostOptimizationValidation | ||
: public PassInfoMixin<DXILPostOptimizationValidation> { | ||
public: | ||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_DIRECTX_DXILPOSTOPTIMIZATIONVALIDATION_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s | ||
; CHECK: RWStructuredBuffers may increment or decrement their counters, but not both. | ||
|
||
define void @inc_and_dec() { | ||
entry: | ||
%handle = call target("dx.RawBuffer", float, 1, 0) @llvm.dx.resource.handlefrombinding(i32 1, i32 2, i32 3, i32 4, i1 false) | ||
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 -1) | ||
call i32 @llvm.dx.resource.updatecounter(target("dx.RawBuffer", float, 1, 0) %handle, i8 1) | ||
ret void | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.