[PATCH] D134067: [HLSL] Enable availability attribute

Chris Bieneman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 16 12:46:46 PDT 2022


beanz created this revision.
beanz added reviewers: MaskRay, erichkeane, rnk, arphaman, python3kgae, pow2clk, tex3d.
Herald added a reviewer: aaron.ballman.
Herald added subscribers: Anastasia, StephenFan.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.

Some HLSL functionality is gated on the target shader model version.
Enabling the use of availability markup allows us to diagnose
availability issues easily in the frontend.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134067

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaHLSL/AvailabilityMarkup.hlsl


Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===================================================================
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+    // expected-warning at +2 {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+    // expected-note at +1 {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
+    return WaveActiveCountBits(b);
+}
+
+// expected-note@* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
Index: clang/lib/Sema/SemaAvailability.cpp
===================================================================
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -194,7 +194,8 @@
     break;
   default:
     // New targets should always warn about availability.
-    return Triple.getVendor() == llvm::Triple::Apple;
+    return Triple.getVendor() == llvm::Triple::Apple ||
+           Triple.getOS() == llvm::Triple::ShaderModel;
   }
   return DeploymentVersion >= ForceAvailabilityFromVersion ||
          DeclVersion >= ForceAvailabilityFromVersion;
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===================================================================
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
Index: clang/lib/Basic/Targets/DirectX.h
===================================================================
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@
     HasLegalHalfType = true;
     HasFloat16 = true;
     NoAsmVariants = true;
+    PlatformMinVersion = Triple.getOSVersion();
+    PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
     resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
                     "32-f64:64-n8:16:32:64");
     TheCXXABI.set(TargetCXXABI::Microsoft);
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@
              .Case("maccatalyst", "macCatalyst")
              .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
              .Case("swift", "Swift")
+             .Case("shadermodel", "HLSL ShaderModel")
              .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
@@ -923,6 +924,7 @@
              .Case("maccatalyst", "macCatalyst")
              .Case("maccatalyst_app_extension", "macCatalystApplicationExtension")
              .Case("zos", "z/OS")
+             .Case("shadermodel", "ShaderModel")
              .Default(Platform);
 }
 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
@@ -937,6 +939,7 @@
              .Case("watchOSApplicationExtension", "watchos_app_extension")
              .Case("macCatalyst", "maccatalyst")
              .Case("macCatalystApplicationExtension", "maccatalyst_app_extension")
+             .Case("ShaderModel", "shadermodel")
              .Default(Platform);
 } }];
   let HasCustomParsing = 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134067.460856.patch
Type: text/x-patch
Size: 3691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/2b2d658a/attachment.bin>


More information about the cfe-commits mailing list