-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for atomic operations
Diagnose an error if the destination of the atomic operation is not appropriate, where appropriate means it's either: - 'groupshared' - from a device buffer This closes #5989.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,74 @@ | ||
#include "slang-ir-legalize-atomic-operations.h" | ||
|
||
#include "slang-ir-insts.h" | ||
|
||
namespace Slang | ||
{ | ||
|
||
static bool isFromDeviceBuffer(IRInst* dst) | ||
{ | ||
if (as<IRRWStructuredBufferGetElementPtr>(dst)) | ||
return true; | ||
if (as<IRGlobalParam>(dst)) | ||
{ | ||
switch (dst->getDataType()->getOp()) | ||
{ | ||
case kIROp_GLSLShaderStorageBufferType: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
if (auto getElementPtr = as<IRGetElementPtr>(dst)) | ||
return isFromDeviceBuffer(getElementPtr->getBase()); | ||
if (auto fieldAddress = as<IRFieldAddress>(dst)) | ||
return isFromDeviceBuffer(fieldAddress->getBase()); | ||
|
||
return false; | ||
} | ||
|
||
static void validateAtomicOperations(DiagnosticSink* sink, IRInst* inst) | ||
{ | ||
switch (inst->getOp()) | ||
{ | ||
case kIROp_AtomicLoad: | ||
case kIROp_AtomicStore: | ||
case kIROp_AtomicExchange: | ||
case kIROp_AtomicCompareExchange: | ||
case kIROp_AtomicAdd: | ||
case kIROp_AtomicSub: | ||
case kIROp_AtomicAnd: | ||
case kIROp_AtomicOr: | ||
case kIROp_AtomicXor: | ||
case kIROp_AtomicMin: | ||
case kIROp_AtomicMax: | ||
case kIROp_AtomicInc: | ||
case kIROp_AtomicDec: | ||
{ | ||
IRInst* destinationPtr = inst->getOperand(0); | ||
IRRate* destinationPtrRate = destinationPtr->getRate(); | ||
bool isGroupShared = as<IRGroupSharedRate>(destinationPtrRate); | ||
bool desinationPtrValid = isGroupShared || isFromDeviceBuffer(destinationPtr); | ||
if (!desinationPtrValid) | ||
{ | ||
sink->diagnose(inst->sourceLoc, Diagnostics::invalidAtomicDestinationPointer); | ||
} | ||
} | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
for (auto child : inst->getModifiableChildren()) | ||
{ | ||
validateAtomicOperations(sink, child); | ||
} | ||
} | ||
|
||
void legalizeAtomicOperations(DiagnosticSink * sink, IRModule* module) | ||
{ | ||
validateAtomicOperations(sink, module->getModuleInst()); | ||
} | ||
} // namespace Slang |
This file contains 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,9 @@ | ||
#pragma once | ||
|
||
namespace Slang | ||
{ | ||
class DiagnosticSink; | ||
struct IRModule; | ||
|
||
void legalizeAtomicOperations(DiagnosticSink * sink, IRModule* module); | ||
} // namespace Slang |