Skip to content

Commit b62ed15

Browse files
committed
change implemented builtin
Signed-off-by: Nathan Gauër <[email protected]>
1 parent f431347 commit b62ed15

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,13 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
45184518
let Prototype = "unsigned int(bool)";
45194519
}
45204520

4521+
// HLSL
4522+
def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
4523+
let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
4524+
let Attributes = [NoThrow, Const];
4525+
let Prototype = "unsigned int()";
4526+
}
4527+
45214528
def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
45224529
let Spellings = ["__builtin_hlsl_create_handle"];
45234530
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,
11691169
// Removing any old attributes.
11701170
I->setNotConvergent();
11711171

1172-
assert(isa<llvm::IntrinsicInst>(I));
1173-
return dyn_cast<llvm::IntrinsicInst>(I);
1172+
return cast<llvm::IntrinsicInst>(I);
11741173
}
11751174

11761175
llvm::IntrinsicInst *
@@ -1191,7 +1190,7 @@ CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
11911190
assert(isa<llvm::IntrinsicInst>(I));
11921191
Builder.restoreIP(IP);
11931192

1194-
return dyn_cast<llvm::IntrinsicInst>(I);
1193+
return cast<llvm::IntrinsicInst>(I);
11951194
}
11961195

11971196
llvm::IntrinsicInst *
@@ -5785,14 +5784,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
57855784
{NDRange, Kernel, Block}));
57865785
}
57875786

5788-
case Builtin::BI__builtin_hlsl_wave_active_count_bits: {
5789-
llvm::Type *BoolTy = llvm::IntegerType::get(getLLVMContext(), 1);
5790-
llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
5791-
auto *CI =
5792-
EmitRuntimeCall(CGM.CreateRuntimeFunction(
5793-
llvm::FunctionType::get(IntTy, {BoolTy}, false),
5794-
"__hlsl_wave_active_count_bits", {}),
5795-
{Src0});
5787+
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
5788+
auto *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(
5789+
llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
5790+
{}, false, true));
57965791
if (getTarget().getTriple().isSPIRVLogical())
57975792
CI = dyn_cast<CallInst>(AddControlledConvergenceAttr(CI));
57985793
return RValue::get(CI);

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,5 +775,10 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
775775
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_count_bits)
776776
uint WaveActiveCountBits(bool Val);
777777

778+
/// \brief Returns the index of the current lane within the current wave.
779+
_HLSL_AVAILABILITY(shadermodel, 6.0)
780+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_get_lane_index)
781+
uint WaveGetLaneIndex();
782+
778783
} // namespace hlsl
779784
#endif //_HLSL_HLSL_INTRINSICS_H_

0 commit comments

Comments
 (0)