Skip to content

Commit d42a42d

Browse files
committed
[Clang][AMDGPU] Add a builtin for llvm.amdgcn.make.buffer.rsrc intrinsic
Depends on #94830.
1 parent 1b06131 commit d42a42d

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

clang/include/clang/Basic/Builtins.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// q -> Scalable vector, followed by the number of elements and the base type.
3434
// Q -> target builtin type, followed by a character to distinguish the builtin type
3535
// Qa -> AArch64 svcount_t builtin type.
36+
// Qb -> AMDGPU __buffer_rsrc_t builtin type.
3637
// E -> ext_vector, followed by the number of elements and the base type.
3738
// X -> _Complex, followed by the base type.
3839
// Y -> ptrdiff_t

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ BUILTIN(__builtin_amdgcn_qsad_pk_u16_u8, "WUiWUiUiWUi", "nc")
148148
BUILTIN(__builtin_amdgcn_mqsad_pk_u16_u8, "WUiWUiUiWUi", "nc")
149149
BUILTIN(__builtin_amdgcn_mqsad_u32_u8, "V4UiWUiUiV4Ui", "nc")
150150

151+
BUILTIN(__builtin_amdgcn_make_buffer_rsrc, "Qbv*sii", "nc")
152+
151153
//===----------------------------------------------------------------------===//
152154
// Ballot builtins.
153155
//===----------------------------------------------------------------------===//

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11527,6 +11527,10 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
1152711527
Type = Context.SveCountTy;
1152811528
break;
1152911529
}
11530+
case 'b': {
11531+
Type = Context.AMDGPUBufferRsrcTy;
11532+
break;
11533+
}
1153011534
default:
1153111535
llvm_unreachable("Unexpected target builtin type");
1153211536
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19082,6 +19082,15 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1908219082
CGM.getIntrinsic(Intrinsic::amdgcn_s_sendmsg_rtn, {ResultType});
1908319083
return Builder.CreateCall(F, {Arg});
1908419084
}
19085+
case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc: {
19086+
llvm::Value *Base = EmitScalarExpr(E->getArg(0));
19087+
llvm::Value *Stride = EmitScalarExpr(E->getArg(1));
19088+
llvm::Value *Num = EmitScalarExpr(E->getArg(2));
19089+
llvm::Value *Flags = EmitScalarExpr(E->getArg(3));
19090+
Function *F =
19091+
CGM.getIntrinsic(Intrinsic::amdgcn_make_buffer_rsrc, {Base->getType()});
19092+
return Builder.CreateCall(F, {Base, Stride, Num, Flags});
19093+
}
1908519094
default:
1908619095
return nullptr;
1908719096
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// REQUIRES: amdgpu-registered-target
3+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -emit-llvm -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga -emit-llvm -o - %s | FileCheck %s
5+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 -emit-llvm -o - %s | FileCheck %s
6+
7+
// CHECK-LABEL: @test_amdgcn_make_buffer_rsrc(
8+
// CHECK-NEXT: entry:
9+
// CHECK-NEXT: [[TMP0:%.*]] = tail call ptr addrspace(8) @llvm.amdgcn.make.buffer.rsrc.p5(ptr addrspace(5) [[P:%.*]], i16 4, i32 [[NUM:%.*]], i32 [[FLAGS:%.*]])
10+
// CHECK-NEXT: ret ptr addrspace(8) [[TMP0]]
11+
//
12+
__buffer_rsrc_t test_amdgcn_make_buffer_rsrc(void *p, int num, int flags) {
13+
return __builtin_amdgcn_make_buffer_rsrc(p, 4, num, flags);
14+
}

0 commit comments

Comments
 (0)