================
@@ -4004,6 +4020,170 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
                                getASTContext().UnsignedIntTy);
     break;
   }
+  case Builtin::BI__builtin_hlsl_interlocked_or: {
+    if (SemaRef.checkArgCountRange(TheCall, 3, 4))
+      return true;
+    auto checkResTy = [this](const HLSLAttributedResourceType *ResTy) -> bool {
+      bool IsValid = false;
+      const ASTContext &AST = SemaRef.getASTContext();
+      // The resource handle must be either
+      // RWByteAddressBuffer or RWStructuredBuffer
+      IsValid |= ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
+                 ResTy->isRaw() && ResTy->hasContainedType();
+      // RWBuffer<int> or RWBuffer<uint>
+      IsValid |= ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
+                 !ResTy->isRaw() && ResTy->hasContainedType() &&
+                 (ResTy->getContainedType() == AST.IntTy ||
+                  ResTy->getContainedType() == AST.UnsignedIntTy);
+      // RWTexture<int> or RWTexture<uint> (any dimension)
+      IsValid |= ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
+                 !ResTy->isRaw() &&
+                 ResTy->getAttrs().ResourceDimension !=
+                     llvm::dxil::ResourceDimension::Unknown &&
+                 (ResTy->getContainedType() == AST.IntTy ||
+                  ResTy->getContainedType() == AST.UnsignedIntTy);
+      return !IsValid;
+    };
+    if (CheckResourceHandle(&SemaRef, TheCall, 0, checkResTy))
+      return true;
+
+    if (CheckArgTypeMatches(&SemaRef, TheCall->getArg(1),
+                            SemaRef.getASTContext().UnsignedIntTy) ||
+        CheckArgTypeMatches(&SemaRef, TheCall->getArg(2),
+                            SemaRef.getASTContext().UnsignedIntTy))
+      return true;
+    // We will have a second index if handling a RWStructuredBuffer
+    if (TheCall->getNumArgs() == 4)
+      if (CheckArgTypeMatches(&SemaRef, TheCall->getArg(3),
+                              SemaRef.getASTContext().UnsignedIntTy))
+        return true;
+
+    TheCall->setType(SemaRef.getASTContext().VoidTy);
+    break;
+  }
+  case Builtin::BI__builtin_hlsl_interlocked_or_ret: {
+    if (SemaRef.checkArgCountRange(TheCall, 4, 5))
+      return true;
+    auto checkResTy = [this](const HLSLAttributedResourceType *ResTy) -> bool {
+      bool IsValid = false;
+      const ASTContext &AST = SemaRef.getASTContext();
+      // The resource handle must be either
+      // RWByteAddressBuffer or RWStructuredBuffer
+      IsValid |= ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
+                 ResTy->getAttrs().RawBuffer && ResTy->hasContainedType();
+      // RWBuffer<int> or RWBuffer<uint>
+      IsValid |= ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
+                 !ResTy->getAttrs().RawBuffer && ResTy->hasContainedType() &&
+                 (ResTy->getContainedType() == AST.IntTy ||
+                  ResTy->getContainedType() == AST.UnsignedIntTy);
+      // TODO: Handle Texture types when implemented
+      return !IsValid;
----------------
farzonl wrote:

Same comment here break these into helpers so we arent repeating so much.

https://github.com/llvm/llvm-project/pull/180804
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to