Skip to content

Commit fe393e0

Browse files
authored
Add barrier MemoryTypeFlags and SemanticFlags diagnostics (microsoft#6513)
Context-specific diagnostics are warnings with DefaultError, since in theory they could be dead code at this stage. There were some changes to existing Sema diagnostic hooks along the way. SemaHLSLDiagnoseTU.cpp - HLSLMethodCallDiagnoseVisitor - extend to non-method calls and pass CallExpr - instead of skipping when call reached from multiple entry/export functions, pass locallyVisited flag for skipping of redundant diags not dependent on entry properties. - use llvm::SmallPtrSet for DiagnosticCalls - capture launch type for entry and pass it down Replace DiagnoseHLSLMethodCall hook with CheckHLSLFunctionCall: Move hook into Sema::CheckFunctionCall in SemaChecking.cpp to be general to either a function call or a method call. Refactor existing code in DiagnoseHLSLMethodCall into CheckFinishedCrossGroupSharingCall called in the hook for this method. Add CheckBarrierCall for context-free flag validity check, called by CheckHLSLFunctionCall. Refactor CalculateLOD checking into more generic parts, dispatched based on IntrinsicOp from top-level DiagnoseReachableHLSLCall function. Switch to using new note: "entry function defined here", instead of "declared here". Fix intrinsic checking to use IsBuiltinTable on the intrinsic attribute's group. **Preparation Changes** While these could be broken out, the barrier diagnostic changes are dependent on them, and testing for some of these is dependent on the other parts of the barrier diagnostic changes. Correct errors in tests, check MaxRecords for EmptyNodeOutput in AST Note that Barrier(..., 3) means SemanticFlags: GroupSync | GroupScope. These are only valid in a shader with a visible group, and GroupSync on memory with at least group scope, so they have been changed to 0 in specific cases in these tests. Make DiagnoseSVForLaunchType a static function, add FIXME notes. Use StringRef for IsBuiltinTable, compare strings instead of pointers. Fix FileCheckerTest for -verify output. New ShaderModel::HasVisibleGroup uses ShaderKind and NodeLaunchType to determine whether shader type has a visible group.
1 parent fa39b39 commit fe393e0

File tree

20 files changed

+1120
-169
lines changed

20 files changed

+1120
-169
lines changed

include/dxc/DXIL/DxilShaderModel.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ class ShaderModel {
9090
static const char *GetNodeLaunchTypeName(DXIL::NodeLaunchType launchTy);
9191
static DXIL::NodeLaunchType NodeLaunchTypeFromName(llvm::StringRef name);
9292

93+
static bool HasVisibleGroup(
94+
DXIL::ShaderKind SK,
95+
DXIL::NodeLaunchType launchType = DXIL::NodeLaunchType::Invalid) {
96+
// Note: Library case is permissive; enforced at entry point.
97+
return SK == DXIL::ShaderKind::Compute || SK == DXIL::ShaderKind::Mesh ||
98+
SK == DXIL::ShaderKind::Amplification ||
99+
SK == DXIL::ShaderKind::Library ||
100+
(SK == DXIL::ShaderKind::Node &&
101+
(launchType == DXIL::NodeLaunchType::Broadcasting ||
102+
launchType == DXIL::NodeLaunchType::Coalescing));
103+
}
104+
93105
bool operator==(const ShaderModel &other) const;
94106
bool operator!=(const ShaderModel &other) const { return !(*this == other); }
95107

tools/clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,5 @@ def HLSLSemanticIdentifierCollision : DiagGroup<"semantic-identifier-collision">
802802
def HLSLStructurizeExitsLifetimeMarkersConflict: DiagGroup<"structurize-exits-lifetime-markers-conflict">;
803803
def HLSLParameterUsage : DiagGroup<"parameter-usage">;
804804
def HLSLAvailability: DiagGroup<"hlsl-availability">;
805+
def HLSLBarrier : DiagGroup<"hlsl-barrier">;
805806
// HLSL Change Ends

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def note_callee_decl : Note<"%0 declared here">;
2020
def note_defined_here : Note<"%0 defined here">;
2121
def note_field_declared_here : Note<"%0 field declared here">;
2222

23+
// HLSL Change: Note for HLSL entry function location
24+
def note_hlsl_entry_defined_here : Note<"entry function defined here">;
25+
2326
// For loop analysis
2427
def warn_variables_not_in_loop_body : Warning<
2528
"variable%select{s| %1|s %1 and %2|s %1, %2, and %3|s %1, %2, %3, and %4}0 "
@@ -7922,6 +7925,27 @@ def err_hlsl_outputpatch_size: Error<
79227925
def note_hlsl_node_array : Note<"'%0' cannot be used as an array; did you mean '%0Array'?">;
79237926
def err_hlsl_controlpoints_size: Error<
79247927
"number of control points %0 is outside the valid range of [1..32]">;
7928+
def err_hlsl_barrier_invalid_memory_flags: Error<
7929+
"invalid MemoryTypeFlags for Barrier operation; expected 0, ALL_MEMORY, or some combination of "
7930+
"UAV_MEMORY, GROUP_SHARED_MEMORY, NODE_INPUT_MEMORY, NODE_OUTPUT_MEMORY flags">;
7931+
def err_hlsl_barrier_invalid_semantic_flags: Error<
7932+
"invalid SemanticFlags for Barrier operation; expected 0 or some combination of "
7933+
"GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags">;
7934+
def warn_hlsl_barrier_group_memory_requires_group: Warning<
7935+
"GROUP_SHARED_MEMORY specified for Barrier operation when context has no visible group">,
7936+
InGroup<HLSLBarrier>, DefaultError;
7937+
def warn_hlsl_barrier_node_memory_requires_node: Warning<
7938+
"NODE_INPUT_MEMORY or NODE_OUTPUT_MEMORY may only be specified for Barrier operation in a node shader">,
7939+
InGroup<HLSLBarrier>, DefaultError;
7940+
def warn_hlsl_barrier_group_semantic_requires_group: Warning<
7941+
"GROUP_SYNC or GROUP_SCOPE specified for Barrier operation when context has no visible group">,
7942+
InGroup<HLSLBarrier>, DefaultError;
7943+
def warn_hlsl_barrier_no_mem_with_required_group_scope: Warning<
7944+
"GROUP_SCOPE specified for Barrier operation without applicable memory">,
7945+
InGroup<HLSLBarrier>, DefaultError;
7946+
def warn_hlsl_barrier_no_mem_with_required_device_scope: Warning<
7947+
"DEVICE_SCOPE specified for Barrier operation without applicable memory">,
7948+
InGroup<HLSLBarrier>, DefaultError;
79257949
// HLSL Change Ends
79267950

79277951
// SPIRV Change Starts

tools/clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,14 +3807,13 @@ class Sema {
38073807
void DiagnoseGloballyCoherentMismatch(const Expr *SrcExpr,
38083808
QualType TargetType,
38093809
SourceLocation Loc);
3810-
bool DiagnoseHLSLMethodCall(const CXXMethodDecl *MD, SourceLocation Loc);
3811-
void DiagnoseSVForLaunchType(const FunctionDecl *FD,
3812-
hlsl::DXIL::NodeLaunchType LaunchTy);
3813-
void DiagnoseReachableHLSLMethodCall(const CXXMethodDecl *MD,
3814-
SourceLocation Loc,
3815-
const hlsl::ShaderModel *SM,
3816-
hlsl::DXIL::ShaderKind EntrySK,
3817-
const FunctionDecl *EntryDecl);
3810+
void CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
3811+
const FunctionProtoType *Proto);
3812+
void DiagnoseReachableHLSLCall(CallExpr *CE, const hlsl::ShaderModel *SM,
3813+
hlsl::DXIL::ShaderKind EntrySK,
3814+
hlsl::DXIL::NodeLaunchType NodeLaunchTy,
3815+
const FunctionDecl *EntryDecl,
3816+
bool locallyVisited);
38183817
// HLSL Change Ends
38193818

38203819
bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);

tools/clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,8 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
14261426
CheckMemaccessArguments(TheCall, CMId, FnInfo);
14271427
#endif // HLSL Change Ends
14281428

1429+
CheckHLSLFunctionCall(FDecl, TheCall, Proto); // HLSL Change
1430+
14291431
return false;
14301432
}
14311433

0 commit comments

Comments
 (0)