[clang] [clang][SPIR-V] Always add convergence intrinsics (PR #88918)

2024-05-08 Thread Natalie Chouinard via cfe-commits
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= 
Message-ID:
In-Reply-To: 


https://github.com/sudonatalie approved this pull request.


https://github.com/llvm/llvm-project/pull/88918
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement 202x conforming literals (PR #91015)

2024-05-06 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie approved this pull request.


https://github.com/llvm/llvm-project/pull/91015
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [SPIRV] Add tan intrinsic part 3 (PR #90278)

2024-05-01 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie approved this pull request.

LGTM, thanks for the work on this!

https://github.com/llvm/llvm-project/pull/90278
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Natalie Chouinard via cfe-commits


@@ -4284,11 +4284,31 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// Validate that if fnative-half-type is given, that
+// the language standard is at least hlsl2018, and that
+// the target shader model is at least 6.2.
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard  =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018 &&
+T.getOSVersion() >= VersionTuple(6, 2)))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-enable-16bit-types" << true << Std.getName()
+<< T.getOSVersion().getAsString();
+}
   } else if (T.isSPIRVLogical()) {
 if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << VulkanEnv << T.getOSName() << T.str();
 }
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard  =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-fnative-half-type" << false << Std.getName()
+<< T.getOSVersion().getAsString();

sudonatalie wrote:

For SPIR-V targets the OS Version is the Vulkan version, not the shader model 
version. Since you passed false as %1, %3 won't be used.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie approved this pull request.


https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Natalie Chouinard via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 2016 %s 2>&1  | 
FileCheck -check-prefix=both_invalid %s
+// RUN: not %clang_dxc -enable-16bit-types -T lib_6_4 -HV 2017 %s 2>&1 | 
FileCheck -check-prefix=HV_invalid %s
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 /HV 2021 %s 2>&1  | 
FileCheck -check-prefix=TP_invalid %s
+// RUN: %clang_dxc -enable-16bit-types -T lib_6_4 /HV 2021 %s 2>&1 -###   | 
FileCheck -check-prefix=valid %s

sudonatalie wrote:

This test should probably check 2018 now

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie edited 
https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-27 Thread Natalie Chouinard via cfe-commits


@@ -4284,11 +4284,31 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// Validate that if fnative-half-type is given, that
+// the language standard is at least hlsl2018, and that
+// the target shader model is at least 6.2.
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard  =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018 &&
+T.getOSVersion() >= VersionTuple(6, 2)))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-enable-16bit-types" << true << Std.getName()
+<< T.getOSVersion().getAsString();
+}
   } else if (T.isSPIRVLogical()) {
 if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << VulkanEnv << T.getOSName() << T.str();
 }
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  const LangStandard  =
+  LangStandard::getLangStandardForKind(Opts.LangStd);
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2018))
+Diags.Report(diag::err_drv_hlsl_16bit_types_unsupported)
+<< "-fnative-half-type" << false << Std.getName()
+<< T.getOSVersion().getAsString();

sudonatalie wrote:

I think this last param should be removed.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Natalie Chouinard via cfe-commits


@@ -4284,11 +4284,25 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// validate that if fnative-half-type is given, that

sudonatalie wrote:

nit: LLVM coding style generally recommends proper capitalization and 
punctuation (ends with a period) for comments: 
https://llvm.org/docs/CodingStandards.html#commenting

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Natalie Chouinard via cfe-commits


@@ -4284,11 +4284,25 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// validate that if fnative-half-type is given, that
+// the language standard is at least hlsl2021, and that
+// the target shader model is at least 6.2
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2021 &&
+T.getOSVersion() >= VersionTuple(6, 2)))
+Diags.Report(diag::err_drv_dxc_enable_16bit_types_option_invalid);

sudonatalie wrote:

Hm, I assume `enable-16bit-types` is the DXC compatibility driver flag and 
`fnative_half_type` is the plain clang flag. I don't have an opinion here but 
it might be worth thinking about in general how to handle selecting different 
error messages for these cases since they'll probably be common and it could be 
a bit confusing if the user uses A but the error message is for B.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Natalie Chouinard via cfe-commits


@@ -753,7 +753,10 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_dxc_enable_16bit_types_option_invalid: Error<
+  "enable-16bit-types option only valid when target shader model [-T] is >= 
6.2 and HLSL Version [-HV] is >= 2021">;
+def err_drv_cc1_hlsl_spirv_fnative_half_type_option_invalid: Error<
+  "fnative-half-type option only valid when hlsl language standard version is 
>= 2021">;

sudonatalie wrote:

nit: HLSL capitalization

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Natalie Chouinard via cfe-commits


@@ -4284,11 +4284,25 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << ShaderModel << T.getOSName() << T.str();
 }
+// validate that if fnative-half-type is given, that
+// the language standard is at least hlsl2021, and that
+// the target shader model is at least 6.2
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2021 &&
+T.getOSVersion() >= VersionTuple(6, 2)))
+Diags.Report(diag::err_drv_dxc_enable_16bit_types_option_invalid);
+}
   } else if (T.isSPIRVLogical()) {
 if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
   Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
   << VulkanEnv << T.getOSName() << T.str();
 }
+if (Args.getLastArg(OPT_fnative_half_type)) {
+  if (!(Opts.LangStd >= LangStandard::lang_hlsl2021))
+Diags.Report(
+diag::err_drv_cc1_hlsl_spirv_fnative_half_type_option_invalid)
+<< VulkanEnv << T.getOSName() << T.str();

sudonatalie wrote:

Were these extra params left in by mistake?

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-26 Thread Natalie Chouinard via cfe-commits


@@ -753,7 +753,10 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_dxc_enable_16bit_types_option_invalid: Error<
+  "enable-16bit-types option only valid when target shader model [-T] is >= 
6.2 and HLSL Version [-HV] is >= 2021">;

sudonatalie wrote:

DXC documentation says `-enable-16bit-types` is allowed in `-HV 2018` 
(https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types#dxil-scalar-type).
 Is this change to 2021 in clang intentional?

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-22 Thread Natalie Chouinard via cfe-commits


@@ -4258,6 +4258,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
   } else {
 llvm_unreachable("expected DXIL or SPIR-V target");
   }
+  // validate that if fnative-half-type is given, that
+  // the language standard is at least hlsl2021, and that
+  // the target shader model is at least 6.2
+  if (Args.getLastArg(OPT_fnative_half_type)) {

sudonatalie wrote:

Yeah, the OSVersion for the SPIR-V target represents the Vulkan version, and 
all Vulkan versions support FP16, so no need to check it. We should probably 
share the HLSL language version check for both targets though.

https://github.com/llvm/llvm-project/pull/85340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-20 Thread Natalie Chouinard via cfe-commits
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= 
Message-ID:
In-Reply-To: 


https://github.com/sudonatalie approved this pull request.


https://github.com/llvm/llvm-project/pull/80680
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-20 Thread Natalie Chouinard via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 


https://github.com/sudonatalie commented:

LGTM in terms of how this affects the SPIR-V backend, but if others who've 
reviewed here could +1 when ready, that would be good feedback for the other 
parts of the codebase that this touches before merging.

https://github.com/llvm/llvm-project/pull/80680
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-03-04 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-03-04 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/82536

>From 07894302273722d8d8190db7780dde049b84e707 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Wed, 21 Feb 2024 21:18:20 +
Subject: [PATCH 1/3] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support

Add SPIR-V backend support for the HLSL SV_DispatchThreadID semantic
attribute, which is lowered to a @llvm.dx.thread.id intrinsic.

Fixes #82534
---
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp |  4 +-
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 69 +
 .../hlsl-intrinsics/SV_DispatchThreadID.ll| 76 +++
 3 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_DispatchThreadID.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp 
b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 74465c019131bc..e88298f52fbe18 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -525,7 +525,9 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
 
   // Output decorations for the GV.
   // TODO: maybe move to GenerateDecorations pass.
-  if (IsConst)
+  const SPIRVSubtarget  =
+  cast(MIRBuilder.getMF().getSubtarget());
+  if (IsConst && ST.isOpenCLEnv())
 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Constant, {});
 
   if (GVar && GVar->getAlign().valueOrOne().value() != 1) {
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 3e01a6ac71f63c..d29321b2f92e3d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsSPIRV.h"
 #include "llvm/Support/Debug.h"
 
@@ -194,6 +195,9 @@ class SPIRVInstructionSelector : public InstructionSelector 
{
   bool selectLog10(Register ResVReg, const SPIRVType *ResType,
MachineInstr ) const;
 
+  bool selectDXThreadId(Register ResVReg, const SPIRVType *ResType,
+MachineInstr ) const;
+
   bool selectUnmergeValues(MachineInstr ) const;
 
   Register buildI32Constant(uint32_t Val, MachineInstr ,
@@ -301,6 +305,7 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
   case TargetOpcode::G_FREEZE:
 return selectFreeze(ResVReg, ResType, I);
 
+  case TargetOpcode::G_INTRINSIC:
   case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
   case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
 return selectIntrinsic(ResVReg, ResType, I);
@@ -1614,6 +1619,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   .addUse(I.getOperand(2).getReg())
   .addUse(I.getOperand(3).getReg());
 break;
+  case Intrinsic::dx_thread_id:
+return selectDXThreadId(ResVReg, ResType, I);
   default:
 llvm_unreachable("Intrinsic selection not implemented");
   }
@@ -1864,6 +1871,68 @@ bool SPIRVInstructionSelector::selectLog10(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectDXThreadId(Register ResVReg,
+const SPIRVType *ResType,
+MachineInstr ) const {
+  // DX intrinsic: @llvm.dx.thread.id(i32)
+  // ID  Name  Description
+  // 93  ThreadId  reads the thread ID
+
+  MachineIRBuilder MIRBuilder(I);
+  const SPIRVType *U32Type = GR.getOrCreateSPIRVIntegerType(32, MIRBuilder);
+  const SPIRVType *Vec3Ty =
+  GR.getOrCreateSPIRVVectorType(U32Type, 3, MIRBuilder);
+  const SPIRVType *PtrType = GR.getOrCreateSPIRVPointerType(
+  Vec3Ty, MIRBuilder, SPIRV::StorageClass::Input);
+
+  // Create new register for GlobalInvocationID builtin variable.
+  Register NewRegister =
+  MIRBuilder.getMRI()->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(NewRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(PtrType, NewRegister, MIRBuilder.getMF());
+
+  // Build GlobalInvocationID global variable with the necessary decorations.
+  Register Variable = GR.buildGlobalVariable(
+  NewRegister, PtrType,
+  getLinkStringForBuiltIn(SPIRV::BuiltIn::GlobalInvocationId), nullptr,
+  SPIRV::StorageClass::Input, nullptr, true, true,
+  SPIRV::LinkageType::Import, MIRBuilder, false);
+
+  // Create new register for loading value.
+  MachineRegisterInfo *MRI = MIRBuilder.getMRI();
+  Register LoadedRegister = MRI->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(LoadedRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(Vec3Ty, LoadedRegister, MIRBuilder.getMF());
+
+  // Load v3uint value from the global variable.
+  BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(SPIRV::OpLoad))
+

[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-03-04 Thread Natalie Chouinard via cfe-commits


@@ -342,8 +343,19 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
,
 return B.CreateCall(FunctionCallee(DxGroupIndex));
   }
   if (D.hasAttr()) {
-llvm::Function *DxThreadID = CGM.getIntrinsic(Intrinsic::dx_thread_id);
-return buildVectorInput(B, DxThreadID, Ty);
+llvm::Function *ThreadIDIntrinsic;
+switch (CGM.getTarget().getTriple().getArch()) {
+case llvm::Triple::dxil:
+  ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_thread_id);
+  break;
+case llvm::Triple::spirv:
+  ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::spv_thread_id);
+  break;
+default:
+  llvm_unreachable("Input semantic not supported by target");
+  break;
+}
+return buildVectorInput(B, ThreadIDIntrinsic, Ty);

sudonatalie wrote:

See https://github.com/llvm/llvm-project/issues/83882

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-03-04 Thread Natalie Chouinard via cfe-commits


@@ -342,8 +343,19 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> 
,
 return B.CreateCall(FunctionCallee(DxGroupIndex));
   }
   if (D.hasAttr()) {
-llvm::Function *DxThreadID = CGM.getIntrinsic(Intrinsic::dx_thread_id);
-return buildVectorInput(B, DxThreadID, Ty);
+llvm::Function *ThreadIDIntrinsic;
+switch (CGM.getTarget().getTriple().getArch()) {
+case llvm::Triple::dxil:
+  ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_thread_id);
+  break;
+case llvm::Triple::spirv:
+  ThreadIDIntrinsic = CGM.getIntrinsic(Intrinsic::spv_thread_id);
+  break;
+default:
+  llvm_unreachable("Input semantic not supported by target");
+  break;
+}
+return buildVectorInput(B, ThreadIDIntrinsic, Ty);

sudonatalie wrote:

Agreed this is not going to scale well. Another option I was looking into, but 
haven't yet figured out, is whether we could make dummy `ClangBuiltin`s to 
maintain the mapping. I think the appropriate `spv_create_handle` or 
`dx_create_handle` get generated without any special logic other than both 
having `ClangBuiltin<"__builtin_hlsl_create_handle">` in their 
`Intrinsics*.td`. I'll open an issue to follow up on this separately.

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-27 Thread Natalie Chouinard via cfe-commits


@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/IntrinsicsDirectX.h"

sudonatalie wrote:

Good catch, thanks

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-27 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/82536

>From 91600507765679e92434ec7c5edb883bf01f847f Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Wed, 21 Feb 2024 21:18:20 +
Subject: [PATCH 1/3] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support

Add SPIR-V backend support for the HLSL SV_DispatchThreadID semantic
attribute, which is lowered to a @llvm.dx.thread.id intrinsic.

Fixes #82534
---
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp |  4 +-
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 69 +
 .../hlsl-intrinsics/SV_DispatchThreadID.ll| 76 +++
 3 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_DispatchThreadID.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp 
b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 47fec745c3f18a..91562364383ab3 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -525,7 +525,9 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
 
   // Output decorations for the GV.
   // TODO: maybe move to GenerateDecorations pass.
-  if (IsConst)
+  const SPIRVSubtarget  =
+  cast(MIRBuilder.getMF().getSubtarget());
+  if (IsConst && ST.isOpenCLEnv())
 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Constant, {});
 
   if (GVar && GVar->getAlign().valueOrOne().value() != 1) {
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 52eeb8a523e6f6..751ecf9e9840cf 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsSPIRV.h"
 #include "llvm/Support/Debug.h"
 
@@ -182,6 +183,9 @@ class SPIRVInstructionSelector : public InstructionSelector 
{
   bool selectLog10(Register ResVReg, const SPIRVType *ResType,
MachineInstr ) const;
 
+  bool selectDXThreadId(Register ResVReg, const SPIRVType *ResType,
+MachineInstr ) const;
+
   Register buildI32Constant(uint32_t Val, MachineInstr ,
 const SPIRVType *ResType = nullptr) const;
 
@@ -284,6 +288,7 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
   case TargetOpcode::G_IMPLICIT_DEF:
 return selectOpUndef(ResVReg, ResType, I);
 
+  case TargetOpcode::G_INTRINSIC:
   case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
   case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
 return selectIntrinsic(ResVReg, ResType, I);
@@ -1427,6 +1432,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   .addUse(I.getOperand(2).getReg())
   .addUse(I.getOperand(3).getReg());
 break;
+  case Intrinsic::dx_thread_id:
+return selectDXThreadId(ResVReg, ResType, I);
   default:
 llvm_unreachable("Intrinsic selection not implemented");
   }
@@ -1660,6 +1667,68 @@ bool SPIRVInstructionSelector::selectLog10(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectDXThreadId(Register ResVReg,
+const SPIRVType *ResType,
+MachineInstr ) const {
+  // DX intrinsic: @llvm.dx.thread.id(i32)
+  // ID  Name  Description
+  // 93  ThreadId  reads the thread ID
+
+  MachineIRBuilder MIRBuilder(I);
+  const SPIRVType *U32Type = GR.getOrCreateSPIRVIntegerType(32, MIRBuilder);
+  const SPIRVType *Vec3Ty =
+  GR.getOrCreateSPIRVVectorType(U32Type, 3, MIRBuilder);
+  const SPIRVType *PtrType = GR.getOrCreateSPIRVPointerType(
+  Vec3Ty, MIRBuilder, SPIRV::StorageClass::Input);
+
+  // Create new register for GlobalInvocationID builtin variable.
+  Register NewRegister =
+  MIRBuilder.getMRI()->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(NewRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(PtrType, NewRegister, MIRBuilder.getMF());
+
+  // Build GlobalInvocationID global variable with the necessary decorations.
+  Register Variable = GR.buildGlobalVariable(
+  NewRegister, PtrType,
+  getLinkStringForBuiltIn(SPIRV::BuiltIn::GlobalInvocationId), nullptr,
+  SPIRV::StorageClass::Input, nullptr, true, true,
+  SPIRV::LinkageType::Import, MIRBuilder, false);
+
+  // Create new register for loading value.
+  MachineRegisterInfo *MRI = MIRBuilder.getMRI();
+  Register LoadedRegister = MRI->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(LoadedRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(Vec3Ty, LoadedRegister, MIRBuilder.getMF());
+
+  // Load v3uint value from the global variable.
+  BuildMI(*I.getParent(), I, I.getDebugLoc(), 

[clang] [NFC][HLSL] Fix broken test (PR #83062)

2024-02-27 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/83062
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][HLSL] Fix broken test (PR #83062)

2024-02-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/83062

Noticed while implementing #82536 that this test was also missing the call the 
FileCheck.

>From 3946bd3188e5e9b9765301057cc53b7ac06f184b Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 26 Feb 2024 21:27:07 +
Subject: [PATCH] [NFC][HLSL] Fix broken test

Noticed while implementing #82536 that this test was also missing the
call the FileCheck.
---
 clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl 
b/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
index b8514b0d13f119..7e7ebe930bd96e 100644
--- a/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - -hlsl-entry main %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - -hlsl-entry main %s | FileCheck %s
 
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {
@@ -10,7 +10,7 @@ void main(unsigned GI : SV_GroupIndex) {
 // semantic parameters and provides the expected void(void) signature that
 // drivers expect for entry points.
 
-//CHECK: define void @main() #[[ENTRY_ATTR:#]]{
+//CHECK: define void @main() #[[#ENTRY_ATTR:]] {
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
 //CHECK-NEXT:   call void @"?main@@YAXI@Z"(i32 %0)
@@ -19,4 +19,4 @@ void main(unsigned GI : SV_GroupIndex) {
 
 // Verify that the entry had the expected dx.shader attribute
 
-//CHECK: attributes #[[ENTRY_ATTR]] = { {{.*}}"dx.shader"="compute"{{.*}} }
+//CHECK: attributes #[[#ENTRY_ATTR]] = { {{.*}}"hlsl.shader"="compute"{{.*}} }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-26 Thread Natalie Chouinard via cfe-commits


@@ -1,28 +1,25 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-SPIRV
 
 // Make sure SV_DispatchThreadID translated into dx.thread.id.
 
-const RWBuffer In;

sudonatalie wrote:

I removed RWBuffer because it's not yet supported by the SPIR-V backend 
(#81036) and want to have tests for both

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-26 Thread Natalie Chouinard via cfe-commits


@@ -1,28 +1,25 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-finclude-default-header -disable-llvm-passes -o - %s

sudonatalie wrote:

Note: This test didn't actually have a call to `FileCheck` before, so I had to 
make some minor changes to get the existing CHECKs passing.

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-26 Thread Natalie Chouinard via cfe-commits


@@ -0,0 +1,76 @@
+; RUN: llc -O0 -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; This file generated from the following HLSL:
+; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -finclude-default-header -o - DispatchThreadID.hlsl
+;
+; [shader("compute")]

sudonatalie wrote:

Agreed, I don't think there's a logical way to do it, but since adding the 
SPIR-V intrinsic for thread ID we now have frontend tests for HLSL->SPIR-V, so 
I think that's sufficient coverage.

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-26 Thread Natalie Chouinard via cfe-commits


@@ -1427,6 +1432,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   .addUse(I.getOperand(2).getReg())
   .addUse(I.getOperand(3).getReg());
 break;
+  case Intrinsic::dx_thread_id:
+return selectDXThreadId(ResVReg, ResType, I);

sudonatalie wrote:

Thanks, I was surprised that it worked but didn't know whether that indicated 
it was by design or accident. I added an analogous SPIR-V intrinsic.

https://github.com/llvm/llvm-project/pull/82536
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support (PR #82536)

2024-02-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/82536

>From 91600507765679e92434ec7c5edb883bf01f847f Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Wed, 21 Feb 2024 21:18:20 +
Subject: [PATCH 1/2] [HLSL][SPIR-V] Add SV_DispatchThreadID semantic support

Add SPIR-V backend support for the HLSL SV_DispatchThreadID semantic
attribute, which is lowered to a @llvm.dx.thread.id intrinsic.

Fixes #82534
---
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp |  4 +-
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 69 +
 .../hlsl-intrinsics/SV_DispatchThreadID.ll| 76 +++
 3 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_DispatchThreadID.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp 
b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 47fec745c3f18a..91562364383ab3 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -525,7 +525,9 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
 
   // Output decorations for the GV.
   // TODO: maybe move to GenerateDecorations pass.
-  if (IsConst)
+  const SPIRVSubtarget  =
+  cast(MIRBuilder.getMF().getSubtarget());
+  if (IsConst && ST.isOpenCLEnv())
 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Constant, {});
 
   if (GVar && GVar->getAlign().valueOrOne().value() != 1) {
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 52eeb8a523e6f6..751ecf9e9840cf 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsSPIRV.h"
 #include "llvm/Support/Debug.h"
 
@@ -182,6 +183,9 @@ class SPIRVInstructionSelector : public InstructionSelector 
{
   bool selectLog10(Register ResVReg, const SPIRVType *ResType,
MachineInstr ) const;
 
+  bool selectDXThreadId(Register ResVReg, const SPIRVType *ResType,
+MachineInstr ) const;
+
   Register buildI32Constant(uint32_t Val, MachineInstr ,
 const SPIRVType *ResType = nullptr) const;
 
@@ -284,6 +288,7 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
   case TargetOpcode::G_IMPLICIT_DEF:
 return selectOpUndef(ResVReg, ResType, I);
 
+  case TargetOpcode::G_INTRINSIC:
   case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
   case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
 return selectIntrinsic(ResVReg, ResType, I);
@@ -1427,6 +1432,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
   .addUse(I.getOperand(2).getReg())
   .addUse(I.getOperand(3).getReg());
 break;
+  case Intrinsic::dx_thread_id:
+return selectDXThreadId(ResVReg, ResType, I);
   default:
 llvm_unreachable("Intrinsic selection not implemented");
   }
@@ -1660,6 +1667,68 @@ bool SPIRVInstructionSelector::selectLog10(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectDXThreadId(Register ResVReg,
+const SPIRVType *ResType,
+MachineInstr ) const {
+  // DX intrinsic: @llvm.dx.thread.id(i32)
+  // ID  Name  Description
+  // 93  ThreadId  reads the thread ID
+
+  MachineIRBuilder MIRBuilder(I);
+  const SPIRVType *U32Type = GR.getOrCreateSPIRVIntegerType(32, MIRBuilder);
+  const SPIRVType *Vec3Ty =
+  GR.getOrCreateSPIRVVectorType(U32Type, 3, MIRBuilder);
+  const SPIRVType *PtrType = GR.getOrCreateSPIRVPointerType(
+  Vec3Ty, MIRBuilder, SPIRV::StorageClass::Input);
+
+  // Create new register for GlobalInvocationID builtin variable.
+  Register NewRegister =
+  MIRBuilder.getMRI()->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(NewRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(PtrType, NewRegister, MIRBuilder.getMF());
+
+  // Build GlobalInvocationID global variable with the necessary decorations.
+  Register Variable = GR.buildGlobalVariable(
+  NewRegister, PtrType,
+  getLinkStringForBuiltIn(SPIRV::BuiltIn::GlobalInvocationId), nullptr,
+  SPIRV::StorageClass::Input, nullptr, true, true,
+  SPIRV::LinkageType::Import, MIRBuilder, false);
+
+  // Create new register for loading value.
+  MachineRegisterInfo *MRI = MIRBuilder.getMRI();
+  Register LoadedRegister = MRI->createVirtualRegister(::IDRegClass);
+  MIRBuilder.getMRI()->setType(LoadedRegister, LLT::pointer(0, 32));
+  GR.assignSPIRVTypeToVReg(Vec3Ty, LoadedRegister, MIRBuilder.getMF());
+
+  // Load v3uint value from the global variable.
+  BuildMI(*I.getParent(), I, I.getDebugLoc(), 

[clang] [llvm] [HLSL][SPIR-V] Add create.handle intrinsic (PR #81038)

2024-02-08 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/81038
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add create.handle intrinsic (PR #81038)

2024-02-07 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie ready_for_review 
https://github.com/llvm/llvm-project/pull/81038
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add create.handle intrinsic (PR #81038)

2024-02-07 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/81038

Add a SPIR-V target-specific intrinsic for creating handles, which is used for 
lowering HLSL resources types like RWBuffer.

`llvm/lib/TargetParser/Triple.cpp`:  SPIR-V intrinsics use "spv" as the target 
prefix, not "spirv". As far as I can tell, this is the first one that is used 
via the `CGBuiltin` codepath, which relies on `getArchTypePrefix`, so I've 
corrected it here.

`clang/lib/Basic/Targets/SPIR.h`:  When records are laid out in the lowering 
from AST to IR, they were incorrectly offset because these Pointer attributes 
were defaulting to 32.

Related to #81036

>From 7fc76d533454e30954747bde4164b13cf625281d Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Wed, 7 Feb 2024 18:03:09 +
Subject: [PATCH 1/2] [SPIR-V] Set Pointer attrs for logical SPIR-V

When records are laid out in the lowering from AST to IR, they were
incorrectly offset because these values were defaulting to 32.
---
 clang/lib/Basic/Targets/SPIR.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index e6235f394a6a2..e25991e3dfe82 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -310,6 +310,7 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
 assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
Triple.getEnvironment() <= llvm::Triple::Amplification &&
"Logical SPIR-V environment must be a valid shader stage.");
+PointerWidth = PointerAlign = 64;
 
 // SPIR-V IDs are represented with a single 32-bit word.
 SizeType = TargetInfo::UnsignedInt;

>From 5f5106478cc21b463eca9820a56b6c236e182afe Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Wed, 7 Feb 2024 20:51:56 +
Subject: [PATCH 2/2] [HLSL][SPIR-V] Add create.handle intrinsic

Add a SPIR-V target-specific intrinsic for creating handles (used for
resources types like RWBuffer). As far as I can tell, this is the first
SPIR-V specific intrinsic that is set via the CGBuiltin codepath, which
relies on a correct getArchTypePrefix, and SPIR-V intrinsics use "spv"
as the target prefix, not "spirv", hence the change in Triple.cpp.
---
 clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl | 4 
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   | 4 
 llvm/lib/IR/Function.cpp  | 1 +
 llvm/lib/TargetParser/Triple.cpp  | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
index 2b9c66d8fc17a..74b3f59bf7600 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV
 
 RWBuffer Buf;
 
@@ -7,3 +8,6 @@ RWBuffer Buf;
 
 // CHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.dx.create.handle(i8 1)
 // CHECK: store ptr %[[HandleRes]], ptr %h, align 4
+
+// CHECK-SPIRV: %[[HandleRes:[0-9]+]] = call ptr @llvm.spv.create.handle(i8 1)
+// CHECK-SPIRV: store ptr %[[HandleRes]], ptr %h, align 8
diff --git a/llvm/include/llvm/IR/IntrinsicsSPIRV.td 
b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
index ea0074d22a441..057dc64e88c26 100644
--- a/llvm/include/llvm/IR/IntrinsicsSPIRV.td
+++ b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
@@ -38,4 +38,8 @@ let TargetPrefix = "spv" in {
   // Expect, Assume Intrinsics
   def int_spv_assume : Intrinsic<[], [llvm_i1_ty]>;
   def int_spv_expect : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, 
LLVMMatchType<0>]>;
+
+  // The following intrinsic(s) are mirrored from IntrinsicsDirectX.td for 
HLSL support.
+  def int_spv_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
+  Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
 }
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index d3e2ae0dede45..d7a09fcf0faeb 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -44,6 +44,7 @@
 #include "llvm/IR/IntrinsicsR600.h"
 #include "llvm/IR/IntrinsicsRISCV.h"
 #include "llvm/IR/IntrinsicsS390.h"
+#include "llvm/IR/IntrinsicsSPIRV.h"
 #include "llvm/IR/IntrinsicsVE.h"
 #include "llvm/IR/IntrinsicsWebAssembly.h"
 #include "llvm/IR/IntrinsicsX86.h"
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 3494ae52bf160..96dbd5ca673b7 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -188,7 +188,7 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
 
   case spirv:
   case spirv32:
-  case spirv64: return "spirv";
+  case 

[clang] [HLSL][SPIR-V] Add support -fspv-target-env opt (PR #78611)

2024-01-22 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/78611
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL][SPIR-V] Add support -fspv-target-env opt (PR #78611)

2024-01-18 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/78611

Add the -fspv-target-env option to the clang-dxc compatibility driver to 
specify the SPIR-V target environment, which is propagated to the target Triple.

>From d950de9ff25efdb81492eb630ba190a75c2762cf Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Thu, 18 Jan 2024 15:42:37 +
Subject: [PATCH] [HLSL][SPIR-V] Add support -fspv-target-env opt

Add the -fspv-target-env option to the clang-dxc compatibility driver to
specify the SPIR-V target environment, which is propagated to the target
Triple.
---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/Driver.cpp   | 15 ++-
 clang/test/Driver/dxc_spirv.hlsl  | 11 ++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e4fdad8265c8637..3b348800c779d28 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8463,3 +8463,6 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, 
Group,
   HelpText<"Embed PDB in shader container (ignored)">;
 def spirv : DXCFlag<"spirv">,
   HelpText<"Generate SPIR-V code">;
+def fspv_target_env_EQ : Joined<["-"], "fspv-target-env=">, Group,
+  HelpText<"Specify the target environment">,
+  Values<"vulkan1.2, vulkan1.3">;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 35d563b9a87fac4..539e3206bdefac5 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1310,10 +1310,23 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
-  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);
+T.setOS(llvm::Triple::Vulkan);
+
+// Set specific Vulkan version if applicable.
+if (const Arg *A = Args.getLastArg(options::OPT_fspv_target_env_EQ)) {
+  const llvm::StringSet<> ValidValues = {"vulkan1.2", "vulkan1.3"};
+  if (ValidValues.contains(A->getValue())) {
+T.setOSName(A->getValue());
+  } else {
+Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  }
+  A->claim();
+}
+
 TargetTriple = T.str();
   }
 } else {
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
index a3c5c30af06e3c8..c087ea4b0d709f5 100644
--- a/clang/test/Driver/dxc_spirv.hlsl
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -1,4 +1,13 @@
 // RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+// RUN: %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.2 -### %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-VULKAN12
+// RUN: %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.3 -### %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-VULKAN13
+// RUN: not %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.0 -### %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
 
-// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK: "-triple" "spirv-unknown-vulkan-compute"
 // CHECK-SAME: "-x" "hlsl"
+
+// CHECK-VULKAN12: "-triple" "spirv-unknown-vulkan1.2-compute"
+
+// CHECK-VULKAN13: "-triple" "spirv-unknown-vulkan1.3-compute"
+
+// CHECK-ERROR: error: invalid value 'vulkan1.0' in 
'-fspv-target-env=vulkan1.0'

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-18 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-18 Thread Natalie Chouinard via cfe-commits

sudonatalie wrote:

Rebased again and local `check-all` succeeds.

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-18 Thread Natalie Chouinard via cfe-commits

sudonatalie wrote:

Rebased due to conflicts. I'm going to go ahead and merge this today to make 
the next dependent change easier to review, but DXIL folks please still feel 
free to follow-up if there are any concerns.

(Also, ignoring the code formatter bot since it seems to be an existing 
intentional formatting choice in the file that doesn't play nicely with 
clang-format yet)

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-18 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/76749

>From 0aa15ea1cc6cec12bc347aff1753a95894fa1677 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Fri, 15 Dec 2023 20:50:43 +
Subject: [PATCH 1/4] [HLSL][SPIR-V] Add Vulkan to target triple

Add support for specifying the logical SPIR-V target environment in the
triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader
Model with a Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   4 +-
 clang/lib/Basic/Targets/SPIR.h|   6 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  27 +++--
 .../test/Driver/hlsl-lang-targets-spirv.hlsl  |  28 +++--
 llvm/include/llvm/TargetParser/Triple.h   |  10 +-
 llvm/lib/TargetParser/Triple.cpp  |  32 +-
 llvm/unittests/TargetParser/TripleTest.cpp| 102 --
 7 files changed, 129 insertions(+), 80 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 8b5232a6df39581..0fe8798dfb301b2 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error<
 def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
-  "shader %select{model|stage}0 is required in target '%1' for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
 
 def err_drv_hlsl_bad_shader_unsupported : Error<
-  "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
 "Resulting DXIL will not be validated or signed for use in release 
environments.">,
 InGroup;
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 9ab2b7c60936392..fa4a3bb1c82eed8 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
   : BaseSPIRVTargetInfo(Triple, Opts) {
 assert(Triple.getArch() == llvm::Triple::spirv &&
"Invalid architecture for Logical SPIR-V.");
-assert(Triple.getOS() == llvm::Triple::ShaderModel &&
-   "Logical SPIR-V requires a valid ShaderModel.");
+assert(Triple.getOS() == llvm::Triple::Vulkan &&
+   Triple.getVulkanVersion() != llvm::VersionTuple(0) &&
+   "Logical SPIR-V requires a valid Vulkan environment.");
 assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
Triple.getEnvironment() <= llvm::Triple::Amplification &&
"Logical SPIR-V environment must be a valid shader stage.");
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11f3f2c2d6425cc..7e211ea24df2ae2 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderStage << T.str();
+<< ShaderStage << Environment << T.str();
   } else if (!T.isShaderStageEnvironment()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
 << ShaderStage << T.getEnvironmentName() << T.str();
   }
+
+  if 

[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-04 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie edited 
https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-04 Thread Natalie Chouinard via cfe-commits


@@ -1,4 +1,4 @@
-// REQUIRES: dxil-registered-target

sudonatalie wrote:

This test wasn't being run for me before. I think this change is correct?

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-04 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie commented:

Will wait for a +1 from @llvm-beanz or @bogner since I modified the error 
messages slightly for DXIL too

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-04 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/76749

>From 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Fri, 15 Dec 2023 20:50:43 +
Subject: [PATCH 1/4] [HLSL][SPIR-V] Add Vulkan to target triple

Add support for specifying the logical SPIR-V target environment in the
triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader
Model with a Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   4 +-
 clang/lib/Basic/Targets/SPIR.h|   6 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  27 +++--
 .../test/Driver/hlsl-lang-targets-spirv.hlsl  |  28 +++--
 llvm/include/llvm/TargetParser/Triple.h   |  10 +-
 llvm/lib/TargetParser/Triple.cpp  |  32 +-
 llvm/unittests/TargetParser/TripleTest.cpp| 102 --
 7 files changed, 129 insertions(+), 80 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 676f1a62b49dd0..2e5ac4f349c0fd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error<
 def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
-  "shader %select{model|stage}0 is required in target '%1' for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
 
 def err_drv_hlsl_bad_shader_unsupported : Error<
-  "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
 "Resulting DXIL will not be validated or signed for use in release 
environments.">,
 InGroup;
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 9ab2b7c6093639..fa4a3bb1c82eed 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
   : BaseSPIRVTargetInfo(Triple, Opts) {
 assert(Triple.getArch() == llvm::Triple::spirv &&
"Invalid architecture for Logical SPIR-V.");
-assert(Triple.getOS() == llvm::Triple::ShaderModel &&
-   "Logical SPIR-V requires a valid ShaderModel.");
+assert(Triple.getOS() == llvm::Triple::Vulkan &&
+   Triple.getVulkanVersion() != llvm::VersionTuple(0) &&
+   "Logical SPIR-V requires a valid Vulkan environment.");
 assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
Triple.getEnvironment() <= llvm::Triple::Amplification &&
"Logical SPIR-V environment must be a valid shader stage.");
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11f3f2c2d6425c..7e211ea24df2ae 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderStage << T.str();
+<< ShaderStage << Environment << T.str();
   } else if (!T.isShaderStageEnvironment()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
 << ShaderStage << T.getEnvironmentName() << T.str();
   }
+
+  if 

[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Natalie Chouinard via cfe-commits


@@ -3,29 +3,39 @@
 // Supported targets
 //
 // RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan-compute %s -S -o /dev/null 2>&1 | 
FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan1.2-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan1.3-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv1.5-unknown-vulkan1.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv1.6-unknown-vulkan1.3-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
-// Empty shader model
+// Empty Vulkan environment
 //
 // RUN: not %clang -target spirv %s -S -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-NO-OS %s
 
-// Invalid shader models
+// Invalid Vulkan environment
 //
-// RUN: not %clang -target spirv--unknown %s -S -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target spirv--shadermodel %s -S -o /dev/null 2>&1 | 
FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target spirv-unknown-vulkan1.0-compute %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s

sudonatalie wrote:

I think it's sufficient to say that a target triple is not supported, and seems 
to follow the convention of other driver error messages. Eventually we should 
have some user-facing documentation with usage instructions, but I don't think 
we're there yet.

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Natalie Chouinard via cfe-commits


@@ -1328,6 +1331,31 @@ VersionTuple Triple::getDriverKitVersion() const {
   }
 }
 
+VersionTuple Triple::getVulkanVersion() const {
+  if (getArch() != spirv || getOS() != Vulkan)
+llvm_unreachable("invalid Vulkan SPIR-V triple");
+
+  VersionTuple VulkanVersion = getOSVersion();
+  SubArchType SpirvVersion = getSubArch();
+
+  llvm::DenseMap ValidVersionMap = {

sudonatalie wrote:

Same as above, simply "unsupported" seems to be conventional and I slightly 
prefer that for maintainability (an error message with "we only support 
v1.2+spv1.5 and v1.3+spv1.6" is more likely to get out of sync).

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Natalie Chouinard via cfe-commits


@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderStage << T.str();
+<< ShaderStage << Environment << T.str();
   } else if (!T.isShaderStageEnvironment()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
 << ShaderStage << T.getEnvironmentName() << T.str();
   }
+
+  if (T.isDXIL()) {

sudonatalie wrote:

Sure

https://github.com/llvm/llvm-project/pull/76749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/76749

>From 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Fri, 15 Dec 2023 20:50:43 +
Subject: [PATCH 1/2] [HLSL][SPIR-V] Add Vulkan to target triple

Add support for specifying the logical SPIR-V target environment in the
triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader
Model with a Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   4 +-
 clang/lib/Basic/Targets/SPIR.h|   6 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  27 +++--
 .../test/Driver/hlsl-lang-targets-spirv.hlsl  |  28 +++--
 llvm/include/llvm/TargetParser/Triple.h   |  10 +-
 llvm/lib/TargetParser/Triple.cpp  |  32 +-
 llvm/unittests/TargetParser/TripleTest.cpp| 102 --
 7 files changed, 129 insertions(+), 80 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 676f1a62b49dd0..2e5ac4f349c0fd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error<
 def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
-  "shader %select{model|stage}0 is required in target '%1' for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
 
 def err_drv_hlsl_bad_shader_unsupported : Error<
-  "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
 "Resulting DXIL will not be validated or signed for use in release 
environments.">,
 InGroup;
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 9ab2b7c6093639..fa4a3bb1c82eed 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
   : BaseSPIRVTargetInfo(Triple, Opts) {
 assert(Triple.getArch() == llvm::Triple::spirv &&
"Invalid architecture for Logical SPIR-V.");
-assert(Triple.getOS() == llvm::Triple::ShaderModel &&
-   "Logical SPIR-V requires a valid ShaderModel.");
+assert(Triple.getOS() == llvm::Triple::Vulkan &&
+   Triple.getVulkanVersion() != llvm::VersionTuple(0) &&
+   "Logical SPIR-V requires a valid Vulkan environment.");
 assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
Triple.getEnvironment() <= llvm::Triple::Amplification &&
"Logical SPIR-V environment must be a valid shader stage.");
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11f3f2c2d6425c..7e211ea24df2ae 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderStage << T.str();
+<< ShaderStage << Environment << T.str();
   } else if (!T.isShaderStageEnvironment()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
 << ShaderStage << T.getEnvironmentName() << T.str();
   }
+
+  if 

[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-02 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/76749

Add support for specifying the logical SPIR-V target environment in the triple 
as Vulkan. When compiling HLSL, this replaces the DirectX Shader Model with a 
Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan 
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051

>From 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Fri, 15 Dec 2023 20:50:43 +
Subject: [PATCH] [HLSL][SPIR-V] Add Vulkan to target triple

Add support for specifying the logical SPIR-V target environment in the
triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader
Model with a Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   4 +-
 clang/lib/Basic/Targets/SPIR.h|   6 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  27 +++--
 .../test/Driver/hlsl-lang-targets-spirv.hlsl  |  28 +++--
 llvm/include/llvm/TargetParser/Triple.h   |  10 +-
 llvm/lib/TargetParser/Triple.cpp  |  32 +-
 llvm/unittests/TargetParser/TripleTest.cpp| 102 --
 7 files changed, 129 insertions(+), 80 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 676f1a62b49dd0..2e5ac4f349c0fd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error<
 def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
-  "shader %select{model|stage}0 is required in target '%1' for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
 
 def err_drv_hlsl_bad_shader_unsupported : Error<
-  "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code 
generation">;
+  "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
 "Resulting DXIL will not be validated or signed for use in release 
environments.">,
 InGroup;
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 9ab2b7c6093639..fa4a3bb1c82eed 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
@@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
   : BaseSPIRVTargetInfo(Triple, Opts) {
 assert(Triple.getArch() == llvm::Triple::spirv &&
"Invalid architecture for Logical SPIR-V.");
-assert(Triple.getOS() == llvm::Triple::ShaderModel &&
-   "Logical SPIR-V requires a valid ShaderModel.");
+assert(Triple.getOS() == llvm::Triple::Vulkan &&
+   Triple.getVulkanVersion() != llvm::VersionTuple(0) &&
+   "Logical SPIR-V requires a valid Vulkan environment.");
 assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
Triple.getEnvironment() <= llvm::Triple::Amplification &&
"Logical SPIR-V environment must be a valid shader stage.");
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11f3f2c2d6425c..7e211ea24df2ae 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
, ArgList ,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 

[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-11-01 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-30 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/65989

>From 7f3cc0939b7840773f773870957fe2db0a93a502 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH 1/3] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/Driver.cpp   | 6 ++
 clang/test/Driver/dxc_spirv.hlsl  | 4 
 3 files changed, 12 insertions(+)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f3f5125d42e7a9..1c76da8682a5b19 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8316,3 +8316,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 30ae2201ab8..92fbdcabe9cfdc9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file

>From c2464247b928ca93e2b40776aa5b5c8bca5dcb99 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:40:36 +
Subject: [PATCH 2/3] Add TODO

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 92fbdcabe9cfdc9..6f5ff8141032677 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
+  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);

>From 67eccb49b8f544cc03edc9cf8a2ed982b2ea8c2d Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:51:20 +
Subject: [PATCH 3/3] EOF newlines

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/dxc_spirv.hlsl  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1c76da8682a5b19..8193a7adcbd5c84 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8317,4 +8317,4 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, 
Group,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
 def spirv : DXCFlag<"spirv">,
-  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
+  HelpText<"Generate SPIR-V code">;
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
index 387b71ca58ada18..a3c5c30af06e3c8 100644
--- a/clang/test/Driver/dxc_spirv.hlsl
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -1,4 +1,4 @@
 // RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
 
 // CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
-// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file
+// CHECK-SAME: "-x" "hlsl"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL][SPIR-V] Fix clang driver lang target test (PR #70330)

2023-10-30 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie closed 
https://github.com/llvm/llvm-project/pull/70330
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL][SPIR-V] Fix clang driver lang target test (PR #70330)

2023-10-30 Thread Natalie Chouinard via cfe-commits

sudonatalie wrote:

Going to go ahead and merge this since it's just a test fix, but @bogner let me 
know if you have any concerns.

https://github.com/llvm/llvm-project/pull/70330
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-26 Thread Natalie Chouinard via cfe-commits


@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s

sudonatalie wrote:

Since we still have some unanswered questions about our triple requirements, I 
left the sys portion as-is for now and added a TODO and 
https://github.com/llvm/llvm-project/issues/70051 to track. If we want to 
require it to be `unkown` we should do that in a separate patch, but I don't 
think it would add value now.

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/65989

>From 331e1a92f2d93dcd5e7e1cae25ce51f33b2c8ffe Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH 1/3] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/Driver.cpp   | 6 ++
 clang/test/Driver/dxc_spirv.hlsl  | 4 
 3 files changed, 12 insertions(+)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..5e0aa80bc64945d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8324,3 +8324,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 30ae2201ab8..92fbdcabe9cfdc9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file

>From d0be295583dd279de25ee65124712aa9e9f694be Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:40:36 +
Subject: [PATCH 2/3] Add TODO

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 92fbdcabe9cfdc9..6f5ff8141032677 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
+  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);

>From 96e3a24bf3fafe715054969d859fbe44a0b9dc25 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:51:20 +
Subject: [PATCH 3/3] EOF newlines

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/dxc_spirv.hlsl  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5e0aa80bc64945d..474263699c47ee2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8325,4 +8325,4 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, 
Group,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
 def spirv : DXCFlag<"spirv">,
-  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
+  HelpText<"Generate SPIR-V code">;
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
index 387b71ca58ada18..a3c5c30af06e3c8 100644
--- a/clang/test/Driver/dxc_spirv.hlsl
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -1,4 +1,4 @@
 // RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
 
 // CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
-// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file
+// CHECK-SAME: "-x" "hlsl"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-26 Thread Natalie Chouinard via cfe-commits


@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s

sudonatalie wrote:

Separated the test fix into: https://github.com/llvm/llvm-project/pull/70330

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie edited 
https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/65989

>From 4738a535e24114ce24647f0935b1cec897bf0a1b Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Thu, 26 Oct 2023 13:21:23 +
Subject: [PATCH 1/4] [HLSL][SPIR-V] Fix clang driver lang target test

This test has been failing since the SPIR-V backend started failing
explicitly on unsupported shader types. Switched this test to a compute
shader since it is currently the only type supported.
---
 clang/test/Driver/hlsl-lang-targets-spirv.hlsl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl 
b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
index ff29f143ba1dc8e..e04d71263770bbb 100644
--- a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
 // Empty shader model
 //
@@ -27,5 +27,5 @@
 // CHECK-NO-ENV: error: shader stage is required in target '{{.*}}' for HLSL 
code generation
 // CHECK-BAD-ENV: error: shader stage '{{.*}}' in target '{{.*}}' is invalid 
for HLSL code generation
 
-[shader("pixel")]
+[shader("compute"), numthreads(1,1,1)]
 void main() {}

>From 5574c8ea5a52155cfa762d90ae4bb3ea28271252 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH 2/4] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/Driver.cpp   | 6 ++
 clang/test/Driver/dxc_spirv.hlsl  | 4 
 3 files changed, 12 insertions(+)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..5e0aa80bc64945d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8324,3 +8324,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 30ae2201ab8..92fbdcabe9cfdc9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file

>From 70cd7cbd9a46c7c99f43a5d25678d7d64148e1d4 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:40:36 +
Subject: [PATCH 3/4] Add TODO

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 92fbdcabe9cfdc9..6f5ff8141032677 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
+  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);

>From ba9cac519e28cad86a850038437eb0905fdc0a50 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:51:20 +
Subject: [PATCH 4/4] EOF newlines

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/dxc_spirv.hlsl  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 

[clang] [HLSL][SPIR-V] Fix clang driver lang target test (PR #70330)

2023-10-26 Thread Natalie Chouinard via cfe-commits


@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s

sudonatalie wrote:

`FileCheck` fails by default when the input is empty, which is the case when 
this test succeeds (the actual compilation output is being sent to `/dev/null`, 
just stdout/stderr messages are checked). The dxil case was succeeding because 
there's always the `clang: warning: dxv not found. Resulting DXIL will not be 
validated or signed for use in release environments.` message, but since that's 
not the thing this test is checking I figured it made more sense to 
`--allow-empty` for both.

https://github.com/llvm/llvm-project/pull/70330
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL][SPIR-V] Fix clang driver lang target test (PR #70330)

2023-10-26 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/70330

This test has been failing since the SPIR-V backend started failing explicitly 
on unsupported shader types. Switched this test to a compute shader since it is 
currently the only type supported.

>From 4738a535e24114ce24647f0935b1cec897bf0a1b Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Thu, 26 Oct 2023 13:21:23 +
Subject: [PATCH] [HLSL][SPIR-V] Fix clang driver lang target test

This test has been failing since the SPIR-V backend started failing
explicitly on unsupported shader types. Switched this test to a compute
shader since it is currently the only type supported.
---
 clang/test/Driver/hlsl-lang-targets-spirv.hlsl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl 
b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
index ff29f143ba1dc8e..e04d71263770bbb 100644
--- a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
 // Empty shader model
 //
@@ -27,5 +27,5 @@
 // CHECK-NO-ENV: error: shader stage is required in target '{{.*}}' for HLSL 
code generation
 // CHECK-BAD-ENV: error: shader stage '{{.*}}' in target '{{.*}}' is invalid 
for HLSL code generation
 
-[shader("pixel")]
+[shader("compute"), numthreads(1,1,1)]
 void main() {}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits


@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s

sudonatalie wrote:

Oh, to clarify, the `dxil` one was passing, but it seemed a little odd to leave 
it as `pixel` when I made the shader `compute` to satisfy `spirv`'s current 
capabilities. `dxil` also doesn't actually need the `--allow-empty` flag 
because it spits out a warning, but since that's not what this test should be 
testing, I thought it made sense to apply to both.

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits


@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-library %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s

sudonatalie wrote:

This test is actually failing at tip of tree, probably due to a change on our 
side where we started explicitly failing on not-yet-supported shader types, but 
I don't think we knew about this test or made a habit of running it so it just 
fell through the cracks. I can split it out into a separate patch if you'd 
prefer though.

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits

sudonatalie wrote:

Left this on the back burner for a bit, but it would be nice to land now. 
@llvm-beanz or @bogner Can you take a look?

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/65989

>From 46b615e1c40ca89b8d4b9e924c139a5e9c430565 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH 1/4] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/Driver.cpp   | 6 ++
 clang/test/Driver/dxc_spirv.hlsl  | 4 
 3 files changed, 12 insertions(+)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e63158fb0e5333a..81b22d755f014ed 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8352,3 +8352,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored, NoXarchOption]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5fd900a6447fe3..38791955d4a972b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file

>From 2b7154784fe742a4f86684f474cd658e5be121ab Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:40:36 +
Subject: [PATCH 2/4] Add TODO

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 38791955d4a972b..f9339b0a9c2bfac 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
+  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);

>From 714829fb4f7fc076025747334e82cc48340db84e Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:51:20 +
Subject: [PATCH 3/4] EOF newlines

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/dxc_spirv.hlsl  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 81b22d755f014ed..af4790b6f6a7cfe 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8353,4 +8353,4 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, 
Group,
   Flags<[Ignored, NoXarchOption]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
 def spirv : DXCFlag<"spirv">,
-  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
+  HelpText<"Generate SPIR-V code">;
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
index 387b71ca58ada18..a3c5c30af06e3c8 100644
--- a/clang/test/Driver/dxc_spirv.hlsl
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -1,4 +1,4 @@
 // RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
 
 // CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
-// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file
+// CHECK-SAME: "-x" "hlsl"

>From 2a54d11bcf2eaf23e170f2dc152288957308 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 15:16:38 +
Subject: [PATCH 4/4] Fixup test

---
 clang/test/Driver/hlsl-lang-targets-spirv.hlsl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl 
b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
index ff29f143ba1dc8e..e04d71263770bbb 100644
--- a/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets-spirv.hlsl
@@ -2,8 +2,8 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target 

[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie edited 
https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-10-24 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie updated 
https://github.com/llvm/llvm-project/pull/65989

>From 46b615e1c40ca89b8d4b9e924c139a5e9c430565 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH 1/2] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td | 2 ++
 clang/lib/Driver/Driver.cpp   | 6 ++
 clang/test/Driver/dxc_spirv.hlsl  | 4 
 3 files changed, 12 insertions(+)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e63158fb0e5333a..81b22d755f014ed 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8352,3 +8352,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored, NoXarchOption]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5fd900a6447fe3..38791955d4a972b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1303,6 +1303,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file

>From 2b7154784fe742a4f86684f474cd658e5be121ab Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Tue, 24 Oct 2023 14:40:36 +
Subject: [PATCH 2/2] Add TODO

---
 clang/lib/Driver/Driver.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 38791955d4a972b..f9339b0a9c2bfac 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1304,6 +1304,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   A->claim();
 
+  // TODO: Specify Vulkan target environment somewhere in the triple.
   if (Args.hasArg(options::OPT_spirv)) {
 llvm::Triple T(TargetTriple);
 T.setArch(llvm::Triple::spirv);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-09-12 Thread Natalie Chouinard via cfe-commits

sudonatalie wrote:

@llvm-beanz Can you take a look at this PR? I don't seem to be able to assign 
Reviewers, maybe because I don't have committer status yet.

https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-09-11 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie review_requested 
https://github.com/llvm/llvm-project/pull/65989
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIRV] Add -spirv option to DXC driver (PR #65989)

2023-09-11 Thread Natalie Chouinard via cfe-commits

https://github.com/sudonatalie created 
https://github.com/llvm/llvm-project/pull/65989:

Add an option to target SPIR-V to the clang-dxc driver, which sets the target 
triple's architecture to logical SPIR-V.

>From 699235b506e1949293305973429bd3ec3ee1b9e4 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard 
Date: Mon, 11 Sep 2023 18:08:17 +
Subject: [PATCH] [SPIRV] Add -spirv option to DXC driver

Add an option to target SPIR-V to the clang-dxc driver, which sets the
target triple's architecture to logical SPIR-V.
---
 clang/include/clang/Driver/Options.td| 2 ++
 clang/lib/Driver/Driver.cpp  | 6 ++
 clang/test/Driver/dxc_spirv.hlsl | 4 
 clang/test/Driver/hlsl-lang-targets.hlsl | 5 ++---
 4 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/dxc_spirv.hlsl

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a5f5ca29053b43b..a7b8f1d9a0e0f2d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8258,3 +8258,5 @@ def dxc_disable_validation : DXCFlag<"Vd">,
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group,
   Flags<[Ignored, NoXarchOption]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
+def spirv : DXCFlag<"spirv">,
+  HelpText<"Generate SPIR-V code">;
\ No newline at end of file
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ba723eac2a7ee74..39b1df45a410db7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1302,6 +1302,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 Diag(diag::err_drv_invalid_directx_shader_module) << TargetProfile;
 
   A->claim();
+
+  if (Args.hasArg(options::OPT_spirv)) {
+llvm::Triple T(TargetTriple);
+T.setArch(llvm::Triple::spirv);
+TargetTriple = T.str();
+  }
 } else {
   Diag(diag::err_drv_dxc_missing_target_profile);
 }
diff --git a/clang/test/Driver/dxc_spirv.hlsl b/clang/test/Driver/dxc_spirv.hlsl
new file mode 100644
index 000..387b71ca58ada18
--- /dev/null
+++ b/clang/test/Driver/dxc_spirv.hlsl
@@ -0,0 +1,4 @@
+// RUN: %clang_dxc -T cs_6_0 -spirv -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-triple" "spirv-unknown-shadermodel6.0-compute"
+// CHECK-SAME: "-x" "hlsl"
\ No newline at end of file
diff --git a/clang/test/Driver/hlsl-lang-targets.hlsl 
b/clang/test/Driver/hlsl-lang-targets.hlsl
index a757e2a3cdf74de..9adfeb3d0753b40 100644
--- a/clang/test/Driver/hlsl-lang-targets.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets.hlsl
@@ -1,7 +1,7 @@
 // RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=X86
 // RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=DXIL
 // RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s 
--check-prefix=SM
-// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=SPIRV
+// RUN: not %clang -target spirv-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=SPIRV
 
 
 // A completely unsupported target...
@@ -10,5 +10,4 @@
 // Poorly specified targets
 // DXIL: error: HLSL code generation is unsupported for target 
'dxil-unknown-unknown'
 // SM: error: HLSL code generation is unsupported for target 
'x86_64-unknown-shadermodel'
-
-// FIXME// SPIRV: error: HLSL code generation is unsupported for target 
'spirv64-unknown-unknown'
+// SPIRV: error: HLSL code generation is unsupported for target 
'spirv-unknown-unknown'

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits