Skip to content

Commit 6fbc7d3

Browse files
authored
[HLSL][SPIR-V] Add -fspv-enable-maximal-reconvergence flag to clang dxc. (#163474)
Implement the frontend change to support maximal reconvergence feature. The next work is to generate the corresponding SPIR-V instructions (`OpExtension` and `OpExecutionMode`) based on the llvm ir added in this CL `"enable-maximal-reconvergence"="true"`. Addresses llvm/llvm-project#136930
1 parent 5fb788b commit 6fbc7d3

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ ENUM_LANGOPT(HLSLVersion, HLSLLangStd, 16, HLSL_Unset, NotCompatible, "HLSL Vers
243243
LANGOPT(HLSLStrictAvailability, 1, 0, NotCompatible,
244244
"Strict availability diagnostic mode for HLSL built-in functions.")
245245
LANGOPT(HLSLSpvUseUnknownImageFormat, 1, 0, NotCompatible, "For storage images and texel buffers, sets the default format to 'Unknown' when not specified via the `vk::image_format` attribute. If this option is not used, the format is inferred from the resource's data type.")
246+
LANGOPT(HLSLSpvEnableMaximalReconvergence, 1, 0, NotCompatible, "Enables the MaximallyReconvergesKHR execution mode for this module. This ensures that control flow reconverges at well-defined merge points as defined by the Vulkan spec.")
246247

247248
LANGOPT(CUDAIsDevice , 1, 0, NotCompatible, "compiling for CUDA device")
248249
LANGOPT(CUDAHostDeviceConstexpr, 1, 1, NotCompatible, "treating unattributed constexpr functions as __host__ __device__")

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9601,6 +9601,15 @@ def fhlsl_spv_use_unknown_image_format
96019601
"from the resource's data type.">,
96029602
MarshallingInfoFlag<LangOpts<"HLSLSpvUseUnknownImageFormat">>;
96039603

9604+
def fhlsl_spv_enable_maximal_reconvergence
9605+
: Flag<["-"], "fspv-enable-maximal-reconvergence">,
9606+
Group<dxc_Group>,
9607+
Visibility<[CC1Option, DXCOption]>,
9608+
HelpText<"Enables the MaximallyReconvergesKHR execution mode for this "
9609+
"module. This ensures that control flow reconverges at "
9610+
"well-defined merge points as defined by the Vulkan spec.">,
9611+
MarshallingInfoFlag<LangOpts<"HLSLSpvEnableMaximalReconvergence">>;
9612+
96049613
def no_wasm_opt : Flag<["--"], "no-wasm-opt">,
96059614
Group<m_Group>,
96069615
HelpText<"Disable the wasm-opt optimizer">,

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
519519
if (CGM.getCodeGenOpts().OptimizationLevel == 0)
520520
Fn->addFnAttr(llvm::Attribute::OptimizeNone);
521521
Fn->addFnAttr(llvm::Attribute::NoInline);
522+
523+
if (CGM.getLangOpts().HLSLSpvEnableMaximalReconvergence) {
524+
Fn->addFnAttr("enable-maximal-reconvergence", "true");
525+
}
522526
}
523527

524528
static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,8 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
37553755
options::OPT_hlsl_entrypoint,
37563756
options::OPT_fdx_rootsignature_define,
37573757
options::OPT_fdx_rootsignature_version,
3758-
options::OPT_fhlsl_spv_use_unknown_image_format};
3758+
options::OPT_fhlsl_spv_use_unknown_image_format,
3759+
options::OPT_fhlsl_spv_enable_maximal_reconvergence};
37593760
if (!types::isHLSL(InputType))
37603761
return;
37613762
for (const auto &Arg : ForwardedArguments)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple spirv1.6-unknown-vulkan1.3-compute -fspv-enable-maximal-reconvergence -emit-llvm -o - -O0 %s | FileCheck %s --check-prefixes=CHECK
2+
// RUN: %clang_cc1 -triple spirv1.6-unknown-vulkan1.3-compute -hlsl-entry test -fspv-enable-maximal-reconvergence -emit-llvm -o - -O0 %s | FileCheck %s --check-prefixes=CHECK-ENTRY
3+
4+
[numthreads(1,1,1)]
5+
void main() {
6+
// CHECK: define void @main() [[attributeNumber:#[0-9]+]] {
7+
}
8+
9+
// CHECK: attributes [[attributeNumber]] = {{.*}} "enable-maximal-reconvergence"="true" {{.*}}
10+
11+
12+
[numthreads(1,1,1)]
13+
void test() {
14+
// CHECK-ENTRY: define void @test() [[attributeNumber:#[0-9]+]] {
15+
}
16+
17+
// CHECK-ENTRY: attributes [[attributeNumber]] = {{.*}} "enable-maximal-reconvergence"="true" {{.*}}

0 commit comments

Comments
 (0)