Skip to content

Commit 64b87ef

Browse files
committed
add tests
Signed-off-by: Nathan Gauër <[email protected]>
1 parent 50c2e98 commit 64b87ef

File tree

4 files changed

+94
-19
lines changed

4 files changed

+94
-19
lines changed

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4175,25 +4175,6 @@ class CodeGenFunction : public CodeGenTypeCache {
41754175
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl);
41764176
void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl);
41774177

4178-
// Adds a convergence_ctrl attribute to |Input| and emits the required parent
4179-
// convergence instructions.
4180-
llvm::CallBase *AddControlledConvergenceAttr(llvm::CallBase *Input);
4181-
4182-
// Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
4183-
// as it's parent convergence instr.
4184-
llvm::IntrinsicInst *EmitConvergenceLoop(llvm::BasicBlock *BB,
4185-
llvm::Value *ParentToken);
4186-
// Adds a convergence_ctrl attribute with |ParentToken| as parent convergence
4187-
// instr to the call |Input|.
4188-
llvm::CallBase *AddConvergenceControlAttr(llvm::CallBase *Input,
4189-
llvm::Value *ParentToken);
4190-
// Find the convergence_entry instruction |F|, or emits ones if none exists.
4191-
// Returns the convergence instruction.
4192-
llvm::IntrinsicInst *getOrEmitConvergenceEntryToken(llvm::Function *F);
4193-
// Find the convergence_loop instruction for the loop defined by |LI|, or
4194-
// emits one if none exists. Returns the convergence instruction.
4195-
llvm::IntrinsicInst *getOrEmitConvergenceLoopToken(const LoopInfo *LI);
4196-
41974178
llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
41984179
const Twine &name = "");
41994180
llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
@@ -4889,6 +4870,25 @@ class CodeGenFunction : public CodeGenTypeCache {
48894870
llvm::Value *emitBoolVecConversion(llvm::Value *SrcVec,
48904871
unsigned NumElementsDst,
48914872
const llvm::Twine &Name = "");
4873+
// Adds a convergence_ctrl attribute to |Input| and emits the required parent
4874+
// convergence instructions.
4875+
llvm::CallBase *AddControlledConvergenceAttr(llvm::CallBase *Input);
4876+
4877+
private:
4878+
// Emits a convergence_loop instruction for the given |BB|, with |ParentToken|
4879+
// as it's parent convergence instr.
4880+
llvm::IntrinsicInst *EmitConvergenceLoop(llvm::BasicBlock *BB,
4881+
llvm::Value *ParentToken);
4882+
// Adds a convergence_ctrl attribute with |ParentToken| as parent convergence
4883+
// instr to the call |Input|.
4884+
llvm::CallBase *AddConvergenceControlAttr(llvm::CallBase *Input,
4885+
llvm::Value *ParentToken);
4886+
// Find the convergence_entry instruction |F|, or emits ones if none exists.
4887+
// Returns the convergence instruction.
4888+
llvm::IntrinsicInst *getOrEmitConvergenceEntryToken(llvm::Function *F);
4889+
// Find the convergence_loop instruction for the loop defined by |LI|, or
4890+
// emits one if none exists. Returns the convergence instruction.
4891+
llvm::IntrinsicInst *getOrEmitConvergenceLoopToken(const LoopInfo *LI);
48924892

48934893
private:
48944894
llvm::MDNode *getRangeForLoadFromType(QualType Ty);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
3+
4+
// CHECK: define spir_func void @main() [[A0:#[0-9]+]] {
5+
void main() {
6+
// CHECK: entry:
7+
// CHECK: %[[CT_ENTRY:[0-9]+]] = call token @llvm.experimental.convergence.entry()
8+
// CHECK: br label %[[LABEL_WHILE_COND:.+]]
9+
int cond = 0;
10+
11+
// CHECK: [[LABEL_WHILE_COND]]:
12+
// CHECK: %[[CT_LOOP:[0-9]+]] = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %[[CT_ENTRY]]) ]
13+
// CHECK: br label %[[LABEL_WHILE_BODY:.+]]
14+
while (true) {
15+
16+
// CHECK: [[LABEL_WHILE_BODY]]:
17+
// CHECK: br i1 {{%.+}}, label %[[LABEL_IF_THEN:.+]], label %[[LABEL_IF_END:.+]]
18+
19+
// CHECK: [[LABEL_IF_THEN]]:
20+
// CHECK: call i32 @__hlsl_wave_get_lane_index() [ "convergencectrl"(token %[[CT_LOOP]]) ]
21+
// CHECK: br label %[[LABEL_WHILE_END:.+]]
22+
if (cond == 2) {
23+
uint index = WaveGetLaneIndex();
24+
break;
25+
}
26+
27+
// CHECK: [[LABEL_IF_END]]:
28+
// CHECK: br label %[[LABEL_WHILE_COND]]
29+
cond++;
30+
}
31+
32+
// CHECK: [[LABEL_WHILE_END]]:
33+
// CHECK: ret void
34+
}
35+
36+
// CHECK-DAG: declare i32 @__hlsl_wave_get_lane_index() [[A1:#[0-9]+]]
37+
38+
// CHECK-DAG: attributes [[A0]] = {{{.*}}convergent{{.*}}}
39+
// CHECK-DAG: attributes [[A1]] = {{{.*}}convergent{{.*}}}
40+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
3+
4+
// CHECK: define spir_func noundef i32 @_Z6test_1v() [[A0:#[0-9]+]] {
5+
// CHECK: %[[CI:[0-9]+]] = call token @llvm.experimental.convergence.entry()
6+
// CHECK: call i32 @__hlsl_wave_get_lane_index() [ "convergencectrl"(token %[[CI]]) ]
7+
uint test_1() {
8+
return WaveGetLaneIndex();
9+
}
10+
11+
// CHECK: declare i32 @__hlsl_wave_get_lane_index() [[A1:#[0-9]+]]
12+
13+
// CHECK-DAG: attributes [[A0]] = { {{.*}}convergent{{.*}} }
14+
// CHECK-DAG: attributes [[A1]] = { {{.*}}convergent{{.*}} }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
3+
4+
// CHECK: define spir_func noundef i32 @_Z6test_1v() [[A0:#[0-9]+]] {
5+
// CHECK: %[[C1:[0-9]+]] = call token @llvm.experimental.convergence.entry()
6+
// CHECK: call i32 @__hlsl_wave_get_lane_index() [ "convergencectrl"(token %[[C1]]) ]
7+
uint test_1() {
8+
return WaveGetLaneIndex();
9+
}
10+
11+
// CHECK-DAG: declare i32 @__hlsl_wave_get_lane_index() [[A1:#[0-9]+]]
12+
13+
// CHECK: define spir_func noundef i32 @_Z6test_2v() [[A0]] {
14+
// CHECK: %[[C2:[0-9]+]] = call token @llvm.experimental.convergence.entry()
15+
// CHECK: call spir_func noundef i32 @_Z6test_1v() [ "convergencectrl"(token %[[C2]]) ]
16+
uint test_2() {
17+
return test_1();
18+
}
19+
20+
// CHECK-DAG: attributes [[A0]] = {{{.*}}convergent{{.*}}}
21+
// CHECK-DAG: attributes [[A1]] = {{{.*}}convergent{{.*}}}

0 commit comments

Comments
 (0)