https://github.com/hekota created https://github.com/llvm/llvm-project/pull/155861
Reorder the arguments of `__builtin_hlsl_resource_handlefromimplicitbinding` builtins to match the order of the `llvm.dx.resource.handlefromimplicitbinding` intrinsics, and also to match the arguments on the static create methods for resource initialization (coming soon). Previously the arguments were in the same order as the resource class constructor for implicit binding. The `orderId` argument was intentionally at index `3` to make sure explicit & implicit binding constructors have different signature. Since we are going to replace the constructors that have binding info with static create methods, this is no longer necessary, and it is better for the argument order to match. >From 7a0d3ca684a2d95e0528d5f4ee77bc1306ddfe1d Mon Sep 17 00:00:00 2001 From: Helena Kotas <heko...@microsoft.com> Date: Thu, 28 Aug 2025 08:17:31 -0700 Subject: [PATCH] [HLSL] Reorder the arguments of handle initialization builtins Reorder the arguments of handle initialization builtins to match the order of the llvm intrinsics, and also to match the arguments on the static create methods for resources (coming soon). --- clang/lib/CodeGen/CGHLSLBuiltins.cpp | 8 ++++---- clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 2 +- clang/lib/Sema/SemaHLSL.cpp | 4 ++-- clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl | 2 +- clang/test/AST/HLSL/StructuredBuffers-AST.hlsl | 2 +- clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 58165185b6711..483920f2392cd 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -348,10 +348,10 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, } case Builtin::BI__builtin_hlsl_resource_handlefromimplicitbinding: { llvm::Type *HandleTy = CGM.getTypes().ConvertType(E->getType()); - Value *SpaceOp = EmitScalarExpr(E->getArg(1)); - Value *RangeOp = EmitScalarExpr(E->getArg(2)); - Value *IndexOp = EmitScalarExpr(E->getArg(3)); - Value *OrderID = EmitScalarExpr(E->getArg(4)); + Value *OrderID = EmitScalarExpr(E->getArg(1)); + Value *SpaceOp = EmitScalarExpr(E->getArg(2)); + Value *RangeOp = EmitScalarExpr(E->getArg(3)); + Value *IndexOp = EmitScalarExpr(E->getArg(4)); Value *Name = EmitScalarExpr(E->getArg(5)); // FIXME: NonUniformResourceIndex bit is not yet implemented // (llvm/llvm-project#135452) diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp index 806800cb7b213..7830cdd18c6cd 100644 --- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp +++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp @@ -670,7 +670,7 @@ BuiltinTypeDeclBuilder::addHandleConstructorFromImplicitBinding() { .addParam("orderId", AST.UnsignedIntTy) .addParam("name", AST.getPointerType(AST.CharTy.withConst())) .callBuiltin("__builtin_hlsl_resource_handlefromimplicitbinding", - HandleType, PH::Handle, PH::_0, PH::_1, PH::_2, PH::_3, + HandleType, PH::Handle, PH::_3, PH::_0, PH::_1, PH::_2, PH::_4) .assign(PH::Handle, PH::LastStmt) .finalize(); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 6a68fa2ed7a8b..c12b35308e127 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2853,8 +2853,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { if (SemaRef.checkArgCount(TheCall, 6) || CheckResourceHandle(&SemaRef, TheCall, 0) || CheckArgTypeMatches(&SemaRef, TheCall->getArg(1), AST.UnsignedIntTy) || - CheckArgTypeMatches(&SemaRef, TheCall->getArg(2), AST.IntTy) || - CheckArgTypeMatches(&SemaRef, TheCall->getArg(3), AST.UnsignedIntTy) || + CheckArgTypeMatches(&SemaRef, TheCall->getArg(2), AST.UnsignedIntTy) || + CheckArgTypeMatches(&SemaRef, TheCall->getArg(3), AST.IntTy) || CheckArgTypeMatches(&SemaRef, TheCall->getArg(4), AST.UnsignedIntTy) || CheckArgTypeMatches(&SemaRef, TheCall->getArg(5), AST.getPointerType(AST.CharTy.withConst()))) diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl index f85194496942b..90794eb69ef46 100644 --- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl +++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl @@ -97,10 +97,10 @@ RESOURCE Buffer; // CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromimplicitbinding' // CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle // CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this +// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'spaceNo' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'int' ParmVar {{.*}} 'range' 'int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'index' 'unsigned int' -// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'const char *' ParmVar {{.*}} 'name' 'const char *' // CHECK-NEXT: AlwaysInlineAttr diff --git a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl index 6ee7145c7e538..e028936e397ac 100644 --- a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl +++ b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl @@ -144,10 +144,10 @@ RESOURCE<float> Buffer; // CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromimplicitbinding' // CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle // CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this +// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'spaceNo' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'int' ParmVar {{.*}} 'range' 'int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'index' 'unsigned int' -// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'const char *' ParmVar {{.*}} 'name' 'const char *' // CHECK-NEXT: AlwaysInlineAttr diff --git a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl index e7f000e9c1b70..02c8cf86c8c8b 100644 --- a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl +++ b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl @@ -119,10 +119,10 @@ RESOURCE<float> Buffer; // CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromimplicitbinding' // CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle // CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this +// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'spaceNo' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'int' ParmVar {{.*}} 'range' 'int' // CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'index' 'unsigned int' -// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' ParmVar {{.*}} 'orderId' 'unsigned int' // CHECK-NEXT: DeclRefExpr {{.*}} 'const char *' ParmVar {{.*}} 'name' 'const char *' // CHECK-NEXT: AlwaysInlineAttr _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits