Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ ENUM_LANGOPT(HLSLVersion, HLSLLangStd, 16, HLSL_Unset, NotCompatible, "HLSL Vers
LANGOPT(HLSLStrictAvailability, 1, 0, NotCompatible,
"Strict availability diagnostic mode for HLSL built-in functions.")
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.")
LANGOPT(HLSLSpvEnableMaximalReconvergence, 1, 0, NotCompatible, "Enables maximal reconvergence for SPIR-V codegen. This ensures that all control flow merges at the nearest possible merge point as defined by the Vulkan spec.")

LANGOPT(CUDAIsDevice , 1, 0, NotCompatible, "compiling for CUDA device")
LANGOPT(CUDAHostDeviceConstexpr, 1, 1, NotCompatible, "treating unattributed constexpr functions as __host__ __device__")
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -9600,6 +9600,15 @@ def fhlsl_spv_use_unknown_image_format
"from the resource's data type.">,
MarshallingInfoFlag<LangOpts<"HLSLSpvUseUnknownImageFormat">>;

def fhlsl_spv_enable_maximal_reconvergence
: Flag<["-"], "fspv-enable-maximal-reconvergence">,
Group<dxc_Group>,
Visibility<[CC1Option, DXCOption]>,
HelpText<"Enables maximal reconvergence for SPIR-V codegen. This ensures "
"that all control flow merges at the nearest possible merge point "
"as defined by the Vulkan spec.">,
MarshallingInfoFlag<LangOpts<"HLSLSpvEnableMaximalReconvergence">>;

def no_wasm_opt : Flag<["--"], "no-wasm-opt">,
Group<m_Group>,
HelpText<"Disable the wasm-opt optimizer">,
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/CGHLSLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
if (CGM.getCodeGenOpts().OptimizationLevel == 0)
Fn->addFnAttr(llvm::Attribute::OptimizeNone);
Fn->addFnAttr(llvm::Attribute::NoInline);

if (CGM.getLangOpts().HLSLSpvEnableMaximalReconvergence) {
Fn->addFnAttr("enable-maximal-reconvergence", "true");
}
}

static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3755,7 +3755,8 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
options::OPT_hlsl_entrypoint,
options::OPT_fdx_rootsignature_define,
options::OPT_fdx_rootsignature_version,
options::OPT_fhlsl_spv_use_unknown_image_format};
options::OPT_fhlsl_spv_use_unknown_image_format,
options::OPT_fhlsl_spv_enable_maximal_reconvergence};
if (!types::isHLSL(InputType))
return;
for (const auto &Arg : ForwardedArguments)
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGenHLSL/vk-features/maximal_reconvergence.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang_cc1 -triple spirv1.6-unknown-vulkan1.3-compute -fspv-enable-maximal-reconvergence -emit-llvm -o - -O0 %s | FileCheck %s --check-prefixes=CHECK
// 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

[numthreads(1,1,1)]
void main() {
// CHECK: define void @main() [[attributeNumber:#[0-9]+]] {
}

// CHECK: attributes [[attributeNumber]] = {{.*}} "enable-maximal-reconvergence"="true" {{.*}}


[numthreads(1,1,1)]
void test() {
// CHECK-ENTRY: define void @test() [[attributeNumber:#[0-9]+]] {
}

// CHECK-ENTRY: attributes [[attributeNumber]] = {{.*}} "enable-maximal-reconvergence"="true" {{.*}}