Re: [PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Justin Bogner via cfe-commits
Vedant Kumar via Phabricator  writes:
> vsk created this revision.
>
> This is motivated by the thread:
> [cfe-dev] Disabling ubsan's object size check at -O0
>
> I think the driver is the best place to disable a sanitizer check at
> particular optimization levels. Doing so in the frontend is messy, and
> makes it really hard to test IR generation for the check. Making the
> change in CodeGen has the same issues.
>
>
> https://reviews.llvm.org/D34563
>
> Files:
>   lib/Driver/SanitizerArgs.cpp
>   test/Driver/fsanitize-object-size.c
>   test/Driver/fsanitize.c
>
> Index: test/Driver/fsanitize.c
> ===
> --- test/Driver/fsanitize.c
> +++ test/Driver/fsanitize.c
> @@ -3,27 +3,27 @@
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
> -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap 
> -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error 
> -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-UNDEFINED-TRAP
> -// CHECK-UNDEFINED-TRAP: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
> -// CHECK-UNDEFINED-TRAP: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
> -// CHECK-UNDEFINED-TRAP2: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
> +// CHECK-UNDEFINED-TRAP: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
> +// CHECK-UNDEFINED-TRAP: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
> +// CHECK-UNDEFINED-TRAP2: 
> "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
>  
>  // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | 
> FileCheck %s --check-prefix=CHECK-UNDEFINED
> -// CHECK-UNDEFINED: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
> +// CHECK-UNDEFINED: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
>  
>  // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
> -// CHECK-UNDEFINED-DARWIN: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
> +// CHECK-UNDEFINED-DARWIN: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
>  
>  // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
> -// CHECK-UNDEFINED-OPENBSD: 
> "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|object-size|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|re

Re: [PATCH] D34563: [ubsan] Disable the object-size check at -O0

2017-06-23 Thread Justin Bogner via cfe-commits
v...@apple.com writes:
> Good point, it makes sense to hand users a warning when they explicitly enable
> -fsanitize=object-size at -O0. I've added in the diagnostic. PTAL.

LGTM.

> diff --git a/include/clang/Basic/DiagnosticDriverKinds.td 
> b/include/clang/Basic/DiagnosticDriverKinds.td
> index 3833f0f28f..6ee061cca6 100644
> --- a/include/clang/Basic/DiagnosticDriverKinds.td
> +++ b/include/clang/Basic/DiagnosticDriverKinds.td
> @@ -226,6 +226,8 @@ def warn_drv_enabling_rtti_with_exceptions : Warning<
>  def warn_drv_disabling_vptr_no_rtti_default : Warning<
>"implicitly disabling vptr sanitizer because rtti wasn't enabled">,
>InGroup>;
> +def warn_drv_object_size_disabled_O0 : Warning<
> +  "the object size sanitizer has no effect at -O0, but is explicitly 
> enabled: %0">;
>  
>  def note_drv_command_failed_diag_msg : Note<
>"diagnostic msg: %0">;
> diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp
> index d6a9c35eda..d5c27ccddd 100644
> --- a/lib/Driver/SanitizerArgs.cpp
> +++ b/lib/Driver/SanitizerArgs.cpp
> @@ -208,12 +208,28 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
>SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args);
>SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
>  
> +  // The object size sanitizer should not be enabled at -O0.
> +  Arg *OptLevel = Args.getLastArg(options::OPT_O_Group);
> +  bool RemoveObjectSizeAtO0 =
> +  !OptLevel || OptLevel->getOption().matches(options::OPT_O0);
> +
>for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
> I != E; ++I) {
>  const auto *Arg = *I;
>  if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
>Arg->claim();
> -  SanitizerMask Add = parseArgValues(D, Arg, true);
> +  SanitizerMask Add = parseArgValues(D, Arg, /*AllowGroups=*/true);
> +
> +  if (RemoveObjectSizeAtO0) {
> +AllRemove |= SanitizerKind::ObjectSize;
> +
> +// The user explicitly enabled the object size check sanitizer. Warn
> +// them that this does nothing at -O0.
> +if (Add & SanitizerKind::ObjectSize)
> +  D.Diag(diag::warn_drv_object_size_disabled_O0)
> +  << Arg->getAsString(Args);
> +  }
> +
>AllAddedKinds |= expandSanitizerGroups(Add);
>  
>// Avoid diagnosing any sanitizer which is disabled later.
> diff --git a/test/Driver/fsanitize-object-size.c 
> b/test/Driver/fsanitize-object-size.c
> new file mode 100644
> index 00..ad8e27a9f4
> --- /dev/null
> +++ b/test/Driver/fsanitize-object-size.c
> @@ -0,0 +1,29 @@
> +// Check that the object size check is disabled at -O0.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -### 2>&1 
> | FileCheck %s --check-prefix=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size %s -O0 -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=null,object-size %s -### 
> 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | 
> FileCheck %s --check-prefixes=CHECK-NO-OSIZE-NO-WARNING
> +
> +// Check that the object size check is enabled at other optimization levels.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -O1 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O2 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O3 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -O4 %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Ofast %s 
> -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Os %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Oz %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=object-size -Og %s -### 
> 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +
> +// Use of trap mode shouldn't affect the object size check.
> +//
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined 
> -fsanitize-trap=undefined -O1 %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -O1 %s 
> -### 2>&1 | FileCheck %s --check-prefix=CHECK-HAS-OSIZE
> +// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap 
> -fsanitize-undefined-trap-on-error -O1 %s -### 2>&1 | FileCheck %s 
> --check-prefix=CHECK-HAS-OSIZE
> +
> +// CHECK-HAS-OSIZE: -fsanitize={{[^ ]*}}object-size
> +
> +// CHECK-NO-OSIZE: warning: the o

r284341 - AST: Improve a couple of comments and cast unused values to void

2016-10-16 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Sun Oct 16 15:12:42 2016
New Revision: 284341

URL: http://llvm.org/viewvc/llvm-project?rev=284341&view=rev
Log:
AST: Improve a couple of comments and cast unused values to void

Make these comments a bit more explicit that they're initializing the
RawText member, and explicitly cast the unused result of getRawText to
void for clarity.

Modified:
cfe/trunk/lib/AST/RawCommentList.cpp

Modified: cfe/trunk/lib/AST/RawCommentList.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RawCommentList.cpp?rev=284341&r1=284340&r2=284341&view=diff
==
--- cfe/trunk/lib/AST/RawCommentList.cpp (original)
+++ cfe/trunk/lib/AST/RawCommentList.cpp Sun Oct 16 15:12:42 2016
@@ -175,8 +175,8 @@ StringRef RawComment::getRawTextSlow(con
 }
 
 const char *RawComment::extractBriefText(const ASTContext &Context) const {
-  // Make sure that RawText is valid.
-  getRawText(Context.getSourceManager());
+  // Lazily initialize RawText using the accessor before using it.
+  (void)getRawText(Context.getSourceManager());
 
   // Since we will be copying the resulting text, all allocations made during
   // parsing are garbage after resulting string is formed.  Thus we can use
@@ -202,8 +202,8 @@ const char *RawComment::extractBriefText
 comments::FullComment *RawComment::parse(const ASTContext &Context,
  const Preprocessor *PP,
  const Decl *D) const {
-  // Make sure that RawText is valid.
-  getRawText(Context.getSourceManager());
+  // Lazily initialize RawText using the accessor before using it.
+  (void)getRawText(Context.getSourceManager());
 
   comments::Lexer L(Context.getAllocator(), Context.getDiagnostics(),
 Context.getCommentCommandTraits(),
@@ -334,4 +334,3 @@ void RawCommentList::addDeserializedComm
  BeforeThanCompare(SourceMgr));
   std::swap(Comments, MergedComments);
 }
-


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


r284366 - AST: Prefer LLVM_NODISCARD to LLVM_ATTRIBUTE_UNUSED_RESULT

2016-10-16 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Mon Oct 17 01:46:35 2016
New Revision: 284366

URL: http://llvm.org/viewvc/llvm-project?rev=284366&view=rev
Log:
AST: Prefer LLVM_NODISCARD to LLVM_ATTRIBUTE_UNUSED_RESULT

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=284366&r1=284365&r2=284366&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 17 01:46:35 2016
@@ -787,7 +787,7 @@ namespace {
 /// (Foo(), 1)  // use noteSideEffect
 /// (Foo() || true) // use noteSideEffect
 /// Foo() + 1   // use noteFailure
-LLVM_ATTRIBUTE_UNUSED_RESULT bool noteFailure() {
+LLVM_NODISCARD bool noteFailure() {
   // Failure when evaluating some expression often means there is some
   // subexpression whose evaluation was skipped. Therefore, (because we
   // don't track whether we skipped an expression when unwinding after an


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


[clang] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-09 Thread Justin Bogner via cfe-commits

bogner wrote:

ping. @AaronBallman Does this look like a reasonable thing to do to you?

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


[openmp] [libcxxabi] [clang] [compiler-rt] [libc] [mlir] [flang] [libcxx] [llvm] [lldb] [lld] [clang-tools-extra] [libunwind] [Clang][Sema] Don't say "is declared here" for invalid template locations

2023-12-06 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71264

>From cab6bcd73081fcbe9807adbf60b345f8d9e654e4 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 18:59:49 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9..a86c428c9121a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e4531..de5cc07f5d428 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f..0952b065d56b5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac..603b7465323e2 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee35486221280..1a6eaa196db09 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid())
+S.Diag(Temp

[compiler-rt] [llvm] [openmp] [libc] [lldb] [libcxx] [libcxxabi] [libunwind] [lld] [clang-tools-extra] [clang] [flang] [mlir] [Clang][Sema] Don't say "is declared here" for invalid template locations

2023-12-06 Thread Justin Bogner via cfe-commits

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


[flang] [clang] [mlir] [llvm] [lld] [clang-tools-extra] [openmp] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

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


[mlir] [flang] [clang] [lld] [openmp] [llvm] [clang-tools-extra] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71265

>From 1779fd08dad4f03ae5e9f1803b8ea3d7dc77c093 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 19:03:00 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5

[skip ci]
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9..a86c428c9121a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e4531..de5cc07f5d428 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f..0952b065d56b5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac..603b7465323e2 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee35486221280..1a6eaa196db09 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Temp

[openmp] [lld] [clang-tools-extra] [llvm] [flang] [clang] [mlir] [HLSL] RWBuffer should not have a default parameter (PR #71265)

2023-12-06 Thread Justin Bogner via cfe-commits

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


[clang] c502a81 - [HLSL] Add helpers to simplify HLSL resource type declarations. NFC

2023-12-07 Thread Justin Bogner via cfe-commits

Author: Justin Bogner
Date: 2023-12-07T17:31:35-08:00
New Revision: c502a81b439b68cb029e16ca9d444d897b5e7727

URL: 
https://github.com/llvm/llvm-project/commit/c502a81b439b68cb029e16ca9d444d897b5e7727
DIFF: 
https://github.com/llvm/llvm-project/commit/c502a81b439b68cb029e16ca9d444d897b5e7727.diff

LOG: [HLSL] Add helpers to simplify HLSL resource type declarations. NFC

A few changes to HLSLExternalSemaSource and its BuiltinTypeDeclBuilder
to make defining buffer types less verbose. This will make it a lot
easier to see what the differences between the various buffer types
are once we start introducing more of them.

Pull Request: https://github.com/llvm/llvm-project/pull/73967

Added: 


Modified: 
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/lib/Sema/HLSLExternalSemaSource.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 4b6bc96f72e22..c0bfff327139f 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -30,9 +30,9 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
 
   void defineHLSLVectorAlias();
   void defineTrivialHLSLTypes();
-  void forwardDeclareHLSLTypes();
+  void defineHLSLTypesWithForwardDeclarations();
 
-  void completeBufferType(CXXRecordDecl *Record);
+  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
 
 public:
   ~HLSLExternalSemaSource() override;

diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 5057bc6629f04..8ed6480a9f5c9 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -306,6 +306,7 @@ struct BuiltinTypeDeclBuilder {
   }
 
   TemplateParameterListBuilder addTemplateArgumentList();
+  BuiltinTypeDeclBuilder &addSimpleTemplateParams(ArrayRef Names);
 };
 
 struct TemplateParameterListBuilder {
@@ -360,11 +361,19 @@ struct TemplateParameterListBuilder {
 return Builder;
   }
 };
+} // namespace
 
 TemplateParameterListBuilder BuiltinTypeDeclBuilder::addTemplateArgumentList() 
{
   return TemplateParameterListBuilder(*this);
 }
-} // namespace
+
+BuiltinTypeDeclBuilder &
+BuiltinTypeDeclBuilder::addSimpleTemplateParams(ArrayRef Names) {
+  TemplateParameterListBuilder Builder = this->addTemplateArgumentList();
+  for (StringRef Name : Names)
+Builder.addTypeParameter(Name);
+  return Builder.finalizeTemplateArgs();
+}
 
 HLSLExternalSemaSource::~HLSLExternalSemaSource() {}
 
@@ -390,7 +399,7 @@ void HLSLExternalSemaSource::InitializeSema(Sema &S) {
   // Force external decls in the HLSL namespace to load from the PCH.
   (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
   defineTrivialHLSLTypes();
-  forwardDeclareHLSLTypes();
+  defineHLSLTypesWithForwardDeclarations();
 
   // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
   // built in types inside a namespace, but we are planning to change that in
@@ -467,18 +476,32 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
  .Record;
 }
 
-void HLSLExternalSemaSource::forwardDeclareHLSLTypes() {
+/// Set up common members and attributes for buffer types
+static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
+  ResourceClass RC,
+  ResourceKind RK) {
+  return BuiltinTypeDeclBuilder(Decl)
+  .addHandleMember()
+  .addDefaultHandleConstructor(S, RC)
+  .annotateResourceClass(RC, RK);
+}
+
+void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
- .addTemplateArgumentList()
- .addTypeParameter("element_type")
- .finalizeTemplateArgs()
+ .addSimpleTemplateParams({"element_type"})
  .Record;
-  if (!Decl->isCompleteDefinition())
-Completions.insert(
-std::make_pair(Decl->getCanonicalDecl(),
-   std::bind(&HLSLExternalSemaSource::completeBufferType,
- this, std::placeholders::_1)));
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
+}
+
+void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
+  CompletionFunction Fn) {
+  Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
 }
 
 void HLSLExternalSemaSource::CompleteType(TagDecl *Tag) {
@@ -496,12 +519,3 @@ void HLSLExternalSemaSource::CompleteType(TagDecl *Tag) {
 return;
   It->second(Record);
 }
-
-void HLSLExternalSem

[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/74896

None

>From 133bdc09eed41545794a369d3fa4d2afb720815e Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 8 Dec 2023 15:41:14 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  9 ++---
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 .../builtins/RWBuffer-annotations.hlsl| 12 +--
 clang/test/CodeGenHLSL/cbuf.hlsl  |  4 ++--
 .../include/llvm/Frontend/HLSL/HLSLResource.h |  5 +++--
 llvm/lib/Frontend/HLSL/HLSLResource.cpp   | 14 +
 llvm/lib/Target/DirectX/DXILResource.cpp  |  4 +---
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  | 20 +--
 llvm/test/CodeGen/DirectX/cbuf.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_0.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_1.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_2.ll |  4 ++--
 .../CodeGen/DirectX/legacy_cb_layout_3.ll |  2 +-
 13 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c239bc17ef267..3e8a40e7540be 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -184,7 +184,8 @@ void CGHLSLRuntime::finishCodeGen() {
   : llvm::hlsl::ResourceKind::TBuffer;
 std::string TyName =
 Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty";
-addBufferResourceAnnotation(GV, TyName, RC, RK, Buf.Binding);
+addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false,
+Buf.Binding);
   }
 }
 
@@ -196,6 +197,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 llvm::StringRef TyName,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
+bool IsROV,
 BufferResBinding &Binding) {
   llvm::Module &M = CGM.getModule();
 
@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
@@ -236,10 +238,11 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl 
*D, GlobalVariable *GV) {
 
   llvm::hlsl::ResourceClass RC = Attr->getResourceClass();
   llvm::hlsl::ResourceKind RK = Attr->getResourceKind();
+  bool IsROV = Attr->getIsROV();
 
   QualType QT(Ty, 0);
   BufferResBinding Binding(D->getAttr());
-  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, Binding);
+  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, IsROV, Binding);
 }
 
 CGHLSLRuntime::BufferResBinding::BufferResBinding(
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 67413fbd4a78e..0979a0c5eb9ad 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -93,6 +93,7 @@ class CGHLSLRuntime {
llvm::StringRef TyName,
llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK,
+   bool IsROV,
BufferResBinding &Binding);
   void addConstant(VarDecl *D, Buffer &CB);
   void addBufferDecls(const DeclContext *DC, Buffer &CB);
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
index 77091f8390a15..a70e224b81e4b 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
@@ -16,9 +16,9 @@ void main() {
 }
 
 // CHECK: !hlsl.uavs = !{![[Single:[0-9]+]], ![[Array:[0-9]+]], 
![[SingleAllocated:[0-9]+]], ![[ArrayAllocated:[0-9]+]], 
![[SingleSpace:[0-9]+]], ![[ArraySpace:[0-9]+]]}
-// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer@M@hlsl@@A", 
!"RWBuffer", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[Array]] = !{ptr 
@"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[SingleAllocated]] = !{ptr 
@"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 3, i32 0}
-// CHECK-DAG: ![[ArrayAllocated]] = !{ptr 
@"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32

[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread Justin Bogner via cfe-commits


@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);

bogner wrote:

I considered flags (and a few other ways of trying to represent this), but I'm 
reasonably confident that we're not going to be adding a lot of flags here and 
that the bool is clearer if that's the case. Append and Consume buffers don't 
need any extra information passed along to the middle/backend, because they 
only differ from StructuredBuffer in what methods are legal. I'm picturing this 
going in a direction sort of like this:

https://github.com/bogner/llvm-project/commit/45c49457c38ad4b89e6e308100fa8266e4ceff6f

Note that I haven't really dealt with Textures yet, so some things may need to 
change, but I think this design makes sense to make incremental progress on.

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


[clang] [llvm] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-09 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/74896

>From 133bdc09eed41545794a369d3fa4d2afb720815e Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 8 Dec 2023 15:41:14 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  9 ++---
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 .../builtins/RWBuffer-annotations.hlsl| 12 +--
 clang/test/CodeGenHLSL/cbuf.hlsl  |  4 ++--
 .../include/llvm/Frontend/HLSL/HLSLResource.h |  5 +++--
 llvm/lib/Frontend/HLSL/HLSLResource.cpp   | 14 +
 llvm/lib/Target/DirectX/DXILResource.cpp  |  4 +---
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  | 20 +--
 llvm/test/CodeGen/DirectX/cbuf.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_0.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_1.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_2.ll |  4 ++--
 .../CodeGen/DirectX/legacy_cb_layout_3.ll |  2 +-
 13 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c239bc17ef267e..3e8a40e7540bef 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -184,7 +184,8 @@ void CGHLSLRuntime::finishCodeGen() {
   : llvm::hlsl::ResourceKind::TBuffer;
 std::string TyName =
 Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty";
-addBufferResourceAnnotation(GV, TyName, RC, RK, Buf.Binding);
+addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false,
+Buf.Binding);
   }
 }
 
@@ -196,6 +197,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 llvm::StringRef TyName,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
+bool IsROV,
 BufferResBinding &Binding) {
   llvm::Module &M = CGM.getModule();
 
@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
@@ -236,10 +238,11 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl 
*D, GlobalVariable *GV) {
 
   llvm::hlsl::ResourceClass RC = Attr->getResourceClass();
   llvm::hlsl::ResourceKind RK = Attr->getResourceKind();
+  bool IsROV = Attr->getIsROV();
 
   QualType QT(Ty, 0);
   BufferResBinding Binding(D->getAttr());
-  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, Binding);
+  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, IsROV, Binding);
 }
 
 CGHLSLRuntime::BufferResBinding::BufferResBinding(
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 67413fbd4a78e1..0979a0c5eb9ad0 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -93,6 +93,7 @@ class CGHLSLRuntime {
llvm::StringRef TyName,
llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK,
+   bool IsROV,
BufferResBinding &Binding);
   void addConstant(VarDecl *D, Buffer &CB);
   void addBufferDecls(const DeclContext *DC, Buffer &CB);
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
index 77091f8390a15a..a70e224b81e4b7 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
@@ -16,9 +16,9 @@ void main() {
 }
 
 // CHECK: !hlsl.uavs = !{![[Single:[0-9]+]], ![[Array:[0-9]+]], 
![[SingleAllocated:[0-9]+]], ![[ArrayAllocated:[0-9]+]], 
![[SingleSpace:[0-9]+]], ![[ArraySpace:[0-9]+]]}
-// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer@M@hlsl@@A", 
!"RWBuffer", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[Array]] = !{ptr 
@"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[SingleAllocated]] = !{ptr 
@"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 3, i32 0}
-// CHECK-DAG: ![[ArrayAllocated]] = !{ptr 
@"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >",

[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-09 Thread Justin Bogner via cfe-commits

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


[clang-tools-extra] [mlir] [libcxx] [compiler-rt] [clang] [llvm] [HLSL] Define RasterizerOrderedBuffer resource (PR #74897)

2023-12-09 Thread Justin Bogner via cfe-commits

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


[mlir] [compiler-rt] [llvm] [clang-tools-extra] [libcxx] [clang] [HLSL] Define RasterizerOrderedBuffer resource (PR #74897)

2023-12-09 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL] Parameter modifier parsing and AST (PR #72139)

2023-11-14 Thread Justin Bogner via cfe-commits


@@ -5559,7 +5562,6 @@ bool Parser::isTypeSpecifierQualifier() {
   case tok::kw___read_write:
   case tok::kw___write_only:
   case tok::kw___funcref:
-  case tok::kw_groupshared:
 return true;

bogner wrote:

This is technically an unrelated bugfix. Not sure it's worth committing it 
separately, but maybe we should add a test that these keywords are not accepted 
in C++ mode similar to how we test some of the opencl keywords (see 
`clang/test/SemaOpenCLCXX/private-access-specifier.cpp`)

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


[clang] [HLSL] Parameter modifier parsing and AST (PR #72139)

2023-11-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library %s -verify
+void fn(in out float f); // #fn
+
+// expected-error@#fn2{{duplicate parameter modifier 'in'}}
+// expected-note@#fn2{{conflicting attribute is here}}
+void fn2(in in float f); // #fn2
+
+// expected-error@#fn3{{duplicate parameter modifier 'out'}}
+// expected-note@#fn3{{conflicting attribute is here}}
+void fn3(out out float f); // #fn3
+
+// expected-error@#fn4{{duplicate parameter modifier 'in'}}
+// expected-error@#fn4{{duplicate parameter modifier 'out'}}
+// expected-note@#fn4{{conflicting attribute is here}}
+// expected-note@#fn4{{conflicting attribute is here}}
+void fn4(inout in out float f); // #fn4
+
+// expected-error@#fn5{{duplicate parameter modifier 'in'}}
+// expected-note@#fn5{{conflicting attribute is here}}
+void fn5(inout in float f); // #fn5
+
+// expected-error@#fn6{{duplicate parameter modifier 'out'}}
+// expected-note@#fn6{{conflicting attribute is here}}
+void fn6(inout out float f); // #fn6
+
+// expected-error@#fn-def{{conflicting parameter qualifier 'out' on parameter 
'f'}}
+// expected-note@#fn{{previously declared as 'inout' here}}
+void fn(out float f) { // #fn-def
+  f = 2;
+}
+
+// Overload resolution failure.
+void fn(in float f); // #fn-in
+
+void failOverloadResolution() {
+  float f = 1.0;
+  fn(f); // expected-error{{call to 'fn' is ambiguous}}
+  // expected-note@#fn-def{{candidate function}}
+  // expected-note@#fn-in{{candidate function}}
+}
+
+// No errors on these scenarios.
+
+// Alternating `inout` and `in out` spellings between declaration and
+// definitions is fine since they have the same semantic meaning.
+void fn7(inout float f);
+void fn7(in out float f) {}
+
+void fn8(in out float f);
+void fn8(inout float f) {}
+
+// These two declare two different functions (although calling them will be
+// ambiguous). This is equivalent to declaring a functiion that takes a

bogner wrote:

Typo. s/functiion/function/

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


[clang] [HLSL] Parameter modifier parsing and AST (PR #72139)

2023-11-14 Thread Justin Bogner via cfe-commits

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


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


[clang] [HLSL] Parameter modifier parsing and AST (PR #72139)

2023-11-14 Thread Justin Bogner via cfe-commits

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


[clang] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-17 Thread Justin Bogner via cfe-commits

bogner wrote:

ping.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits

bogner wrote:

This is NFC in practice so it might be okay that I don't have any tests, but if 
folks have ideas on how to test this I'd like that better.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -930,77 +936,83 @@ namespace {
   OS << getLowerName() << "(" << getUpperName() << ")";
 }
 void writeCtorDefaultInitializers(raw_ostream &OS) const override {
-  OS << getLowerName() << "(" << type << "(0))";
+  OS << getLowerName() << "(" << fullType << "(0))";
 }
 void writeCtorParameters(raw_ostream &OS) const override {
-  OS << type << " " << getUpperName();
+  OS << fullType << " " << getUpperName();
 }
 void writeDeclarations(raw_ostream &OS) const override {
-  auto i = uniques.cbegin(), e = uniques.cend();
-  // The last one needs to not have a comma.
-  --e;
+  if (!isExternal) {
+auto i = uniques.cbegin(), e = uniques.cend();
+// The last one needs to not have a comma.
+--e;
+
+OS << "public:\n";
+OS << "  enum " << shortType << " {\n";
+for (; i != e; ++i)
+  OS << "" << *i << ",\n";
+OS << "" << *e << "\n";
+OS << "  };\n";
+  }
 
-  OS << "public:\n";
-  OS << "  enum " << type << " {\n";
-  for (; i != e; ++i)
-OS << "" << *i << ",\n";
-  OS << "" << *e << "\n";
-  OS << "  };\n";
   OS << "private:\n";
-  OS << "  " << type << " " << getLowerName() << ";";
+  OS << "  " << fullType << " " << getLowerName() << ";";
 }
 
 void writePCHReadDecls(raw_ostream &OS) const override {
-  OS << "" << getAttrName() << "Attr::" << type << " " << 
getLowerName()
- << "(static_cast<" << getAttrName() << "Attr::" << type
- << ">(Record.readInt()));\n";
+  OS << "" << fullType << " " << getLowerName()
+ << "(static_cast<" << fullType << ">(Record.readInt()));\n";
 }
 
 void writePCHReadArgs(raw_ostream &OS) const override {
   OS << getLowerName();
 }
 
 void writePCHWrite(raw_ostream &OS) const override {
-  OS << "Record.push_back(SA->get" << getUpperName() << "());\n";
+  OS << "Record.push_back(static_cast(SA->get" << getUpperName()
+ << "()));\n";
 }
 
 void writeValue(raw_ostream &OS) const override {
   // FIXME: this isn't 100% correct -- some enum arguments require printing
   // as a string literal, while others require printing as an identifier.
   // Tablegen currently does not distinguish between the two forms.
-  OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << type << 
"ToStr(get"
- << getUpperName() << "()) << \"\\\"";
+  OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << shortType
+ << "ToStr(get" << getUpperName() << "()) << \"\\\"";
 }
 
 void writeDump(raw_ostream &OS) const override {
   OS << "switch(SA->get" << getUpperName() << "()) {\n";
   for (const auto &I : uniques) {
-OS << "case " << getAttrName() << "Attr::" << I << ":\n";
+OS << "case " << fullType << "::" << I << ":\n";
 OS << "  OS << \" " << I << "\";\n";
 OS << "  break;\n";
   }
+  if (isExternal) {
+OS << "default:\n";
+OS << "  llvm_unreachable(\"Invalid attribute value\");\n";
+  }

bogner wrote:

It's a little unfortunate that we have to add this based only on `isExternal`, 
but since there's no way to tell if we've used every enum value or not I don't 
think there's a better option

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -19,11 +19,12 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/AttributeCommonInfo.h"
-#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"

bogner wrote:

This is to make `llvm::hlsl::ResourceClass` and `llvm::hlsl::ResourceKind` 
visible for the `#include "clang/AST/Attrs.inc"` later in the file.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -1010,14 +1022,17 @@ namespace {
   // trivial because some enumeration values have multiple named
   // enumerators, such as type_visibility(internal) and
   // type_visibility(hidden) both mapping to TypeVisibilityAttr::Hidden.
-  OS << "const char *" << getAttrName() << "Attr::Convert" << type
- << "ToStr(" << type << " Val) {\n"
+  OS << "const char *" << getAttrName() << "Attr::Convert" << shortType
+ << "ToStr(" << fullType << " Val) {\n"
  << "  switch(Val) {\n";
   SmallDenseSet Uniques;
   for (size_t I = 0; I < enums.size(); ++I) {
 if (Uniques.insert(enums[I]).second)
-  OS << "  case " << getAttrName() << "Attr::" << enums[I]
- << ": return \"" << values[I] << "\";\n";
+  OS << "  case " << fullType << "::" << enums[I] << ": return \""
+ << values[I] << "\";\n";
+  }
+  if (isExternal) {
+OS << "  default: llvm_unreachable(\"Invalid attribute value\");\n";

bogner wrote:

In `Attrs.inc` the only change is that we don't emit a declaration of the enum. 
In `AttrImpl.inc` we get something like this:
```c++
const char *HLSLResourceAttr::ConvertToStr(llvm::hlsl::ResourceClass Val) {
  switch(Val) {
  case llvm::hlsl::ResourceClass::SRV: return "SRV";
  case llvm::hlsl::ResourceClass::UAV: return "UAV";
  case llvm::hlsl::ResourceClass::CBuffer: return "CBuffer";
  case llvm::hlsl::ResourceClass::Sampler: return "Sampler";
  default: llvm_unreachable("Invalid attribute value");
  }
  llvm_unreachable("No enumerator with that value");
}
```

Where previously the enum values were spelled like 
`HLSLResourceAttr::ResourceClass::SRV` and the `default` label wasn't present.


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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -279,12 +279,13 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type name,
 // a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+class EnumArgument values,

bogner wrote:

I put the new argument where it is to avoid having too many defaulted bools, as 
that can get confusing. That said, it does decrease the amount of churn to put 
it at the end, so I'll go with your suggestion.

Note: we could also do this without the boolean at all by looking for `::` in 
the type name, but that felt a bit too magical to me.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -898,23 +898,29 @@ namespace {
   }
 
   class EnumArgument : public Argument {
-std::string type;
+std::string fullType;
+StringRef shortType;
 std::vector values, enums, uniques;
+bool isExternal;
 
   public:
 EnumArgument(const Record &Arg, StringRef Attr)
-: Argument(Arg, Attr), type(std::string(Arg.getValueAsString("Type"))),
-  values(Arg.getValueAsListOfStrings("Values")),
+: Argument(Arg, Attr), values(Arg.getValueAsListOfStrings("Values")),
   enums(Arg.getValueAsListOfStrings("Enums")),
-  uniques(uniqueEnumsInOrder(enums)) {
+  uniques(uniqueEnumsInOrder(enums)),
+  isExternal(Arg.getValueAsBit("External")) {
+  StringRef Type = Arg.getValueAsString("Type");
+  shortType = isExternal ? getAttrName().rsplit("::").second : Type;

bogner wrote:

Do we have a utility for checking if a character is an identifier character 
somewhere?

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -1010,14 +1022,17 @@ namespace {
   // trivial because some enumeration values have multiple named
   // enumerators, such as type_visibility(internal) and
   // type_visibility(hidden) both mapping to TypeVisibilityAttr::Hidden.
-  OS << "const char *" << getAttrName() << "Attr::Convert" << type
- << "ToStr(" << type << " Val) {\n"
+  OS << "const char *" << getAttrName() << "Attr::Convert" << shortType
+ << "ToStr(" << fullType << " Val) {\n"
  << "  switch(Val) {\n";
   SmallDenseSet Uniques;
   for (size_t I = 0; I < enums.size(); ++I) {
 if (Uniques.insert(enums[I]).second)
-  OS << "  case " << getAttrName() << "Attr::" << enums[I]
- << ": return \"" << values[I] << "\";\n";
+  OS << "  case " << fullType << "::" << enums[I] << ": return \""
+ << values[I] << "\";\n";
+  }
+  if (isExternal) {
+OS << "  default: llvm_unreachable(\"Invalid attribute value\");\n";

bogner wrote:

The 'default' is only to appease `-Wswitch`, since otherwise we get things like 
"error: enumeration value 'Invalid' not handled in switch [-Werror,-Wswitch]"

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -930,77 +936,83 @@ namespace {
   OS << getLowerName() << "(" << getUpperName() << ")";
 }
 void writeCtorDefaultInitializers(raw_ostream &OS) const override {
-  OS << getLowerName() << "(" << type << "(0))";
+  OS << getLowerName() << "(" << fullType << "(0))";
 }
 void writeCtorParameters(raw_ostream &OS) const override {
-  OS << type << " " << getUpperName();
+  OS << fullType << " " << getUpperName();
 }
 void writeDeclarations(raw_ostream &OS) const override {
-  auto i = uniques.cbegin(), e = uniques.cend();
-  // The last one needs to not have a comma.
-  --e;
+  if (!isExternal) {
+auto i = uniques.cbegin(), e = uniques.cend();
+// The last one needs to not have a comma.
+--e;
+
+OS << "public:\n";
+OS << "  enum " << shortType << " {\n";
+for (; i != e; ++i)
+  OS << "" << *i << ",\n";
+OS << "" << *e << "\n";
+OS << "  };\n";
+  }
 
-  OS << "public:\n";
-  OS << "  enum " << type << " {\n";
-  for (; i != e; ++i)
-OS << "" << *i << ",\n";
-  OS << "" << *e << "\n";
-  OS << "  };\n";
   OS << "private:\n";
-  OS << "  " << type << " " << getLowerName() << ";";
+  OS << "  " << fullType << " " << getLowerName() << ";";
 }
 
 void writePCHReadDecls(raw_ostream &OS) const override {
-  OS << "" << getAttrName() << "Attr::" << type << " " << 
getLowerName()
- << "(static_cast<" << getAttrName() << "Attr::" << type
- << ">(Record.readInt()));\n";
+  OS << "" << fullType << " " << getLowerName()
+ << "(static_cast<" << fullType << ">(Record.readInt()));\n";
 }
 
 void writePCHReadArgs(raw_ostream &OS) const override {
   OS << getLowerName();
 }
 
 void writePCHWrite(raw_ostream &OS) const override {
-  OS << "Record.push_back(SA->get" << getUpperName() << "());\n";
+  OS << "Record.push_back(static_cast(SA->get" << getUpperName()
+ << "()));\n";
 }
 
 void writeValue(raw_ostream &OS) const override {
   // FIXME: this isn't 100% correct -- some enum arguments require printing
   // as a string literal, while others require printing as an identifier.
   // Tablegen currently does not distinguish between the two forms.
-  OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << type << 
"ToStr(get"
- << getUpperName() << "()) << \"\\\"";
+  OS << "\\\"\" << " << getAttrName() << "Attr::Convert" << shortType
+ << "ToStr(get" << getUpperName() << "()) << \"\\\"";
 }
 
 void writeDump(raw_ostream &OS) const override {
   OS << "switch(SA->get" << getUpperName() << "()) {\n";
   for (const auto &I : uniques) {
-OS << "case " << getAttrName() << "Attr::" << I << ":\n";
+OS << "case " << fullType << "::" << I << ":\n";
 OS << "  OS << \" " << I << "\";\n";
 OS << "  break;\n";
   }
+  if (isExternal) {
+OS << "default:\n";
+OS << "  llvm_unreachable(\"Invalid attribute value\");\n";
+  }

bogner wrote:

It's used in 
[clang::TextNodeDumper](https://clang.llvm.org/doxygen/classclang_1_1TextNodeDumper.html).
 I'm not really familiar what that's used for, but it doesn't look like it 
would be easy to use return here, as it goes through each attribute in order:
```c++
  void VisitHLSLResourceAttr(const HLSLResourceAttr *A) {
const auto *SA = cast(A); (void)SA;
switch(SA->getResourceClass()) {
case llvm::hlsl::ResourceClass::SRV:
  OS << " SRV";
  break;
case llvm::hlsl::ResourceClass::UAV:
  OS << " UAV";
  break;
case llvm::hlsl::ResourceClass::CBuffer:
  OS << " CBuffer";
  break;
case llvm::hlsl::ResourceClass::Sampler:
  OS << " Sampler";
  break;
default:
  llvm_unreachable("Invalid attribute value");
}
switch(SA->getResourceKind()) {
case llvm::hlsl::ResourceKind::Texture1D:
  OS << " Texture1D";
  break;
case llvm::hlsl::ResourceKind::Texture2D:
  OS << " Texture2D";
  break;
...
```

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -279,12 +279,13 @@ class DefaultIntArgument : 
IntArgument {
 
 // This argument is more complex, it includes the enumerator type name,
 // a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+class EnumArgument values,

bogner wrote:

> Should we also consider updating 
> https://clang.llvm.org/docs/InternalsManual.html#arguments to explain this 
> particular argument in more detail given that it's a pretty complicated 
> argument already?

Looks like this doesn't go into detail about the types of arguments at all 
currently. I'll put a note on my todo list to update this separately if you 
don't mind.

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


[clang-tools-extra] [clang] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -898,23 +898,29 @@ namespace {
   }
 
   class EnumArgument : public Argument {
-std::string type;
+std::string fullType;
+StringRef shortType;
 std::vector values, enums, uniques;
+bool isExternal;
 
   public:
 EnumArgument(const Record &Arg, StringRef Attr)
-: Argument(Arg, Attr), type(std::string(Arg.getValueAsString("Type"))),
-  values(Arg.getValueAsListOfStrings("Values")),
+: Argument(Arg, Attr), values(Arg.getValueAsListOfStrings("Values")),
   enums(Arg.getValueAsListOfStrings("Enums")),
-  uniques(uniqueEnumsInOrder(enums)) {
+  uniques(uniqueEnumsInOrder(enums)),
+  isExternal(Arg.getValueAsBit("External")) {
+  StringRef Type = Arg.getValueAsString("Type");
+  shortType = isExternal ? getAttrName().rsplit("::").second : Type;

bogner wrote:

Looks like `isValidAsciiIdentifier` from `clang/Basic/CharInfo.h` will do the 
trick

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


[clang-tools-extra] [clang] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -898,23 +898,29 @@ namespace {
   }
 
   class EnumArgument : public Argument {
-std::string type;
+std::string fullType;
+StringRef shortType;
 std::vector values, enums, uniques;
+bool isExternal;
 
   public:
 EnumArgument(const Record &Arg, StringRef Attr)
-: Argument(Arg, Attr), type(std::string(Arg.getValueAsString("Type"))),
-  values(Arg.getValueAsListOfStrings("Values")),
+: Argument(Arg, Attr), values(Arg.getValueAsListOfStrings("Values")),
   enums(Arg.getValueAsListOfStrings("Enums")),
-  uniques(uniqueEnumsInOrder(enums)) {
+  uniques(uniqueEnumsInOrder(enums)),
+  isExternal(Arg.getValueAsBit("External")) {
+  StringRef Type = Arg.getValueAsString("Type");
+  shortType = isExternal ? getAttrName().rsplit("::").second : Type;

bogner wrote:

Oh, I can't use that here - clang-tblgen can't depend on clang components.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits

bogner wrote:

> Its a bit of a shame that the `VariadicEnumArgument` isn't being included 
> here/updated here, I typically appreciate the variadic versions being kept in 
> sync. But since we don't have a use for it at the moment, I think a 'fixme' 
> (or a future patch!) would be acceptable.

It was pretty straightforward, so I updated VariadicEnumArgument as well 
(though it is unfortunate that it isn't tested at all since it isn't used with 
an external enum)

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-10-31 Thread Justin Bogner via cfe-commits


@@ -898,23 +898,29 @@ namespace {
   }
 
   class EnumArgument : public Argument {
-std::string type;
+std::string fullType;
+StringRef shortType;
 std::vector values, enums, uniques;
+bool isExternal;
 
   public:
 EnumArgument(const Record &Arg, StringRef Attr)
-: Argument(Arg, Attr), type(std::string(Arg.getValueAsString("Type"))),
-  values(Arg.getValueAsListOfStrings("Values")),
+: Argument(Arg, Attr), values(Arg.getValueAsListOfStrings("Values")),
   enums(Arg.getValueAsListOfStrings("Enums")),
-  uniques(uniqueEnumsInOrder(enums)) {
+  uniques(uniqueEnumsInOrder(enums)),
+  isExternal(Arg.getValueAsBit("External")) {
+  StringRef Type = Arg.getValueAsString("Type");
+  shortType = isExternal ? getAttrName().rsplit("::").second : Type;

bogner wrote:

Since we do compile the generated code right away it should fail to compile 
anyway, so I think all this would really do is improve the error someone gets 
if they make a mistake. I think I'll probably just leave it as is unless you 
feel strongly that we should do something here.

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

2023-11-01 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2023-12-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,300 @@
+===
+HLSL Function Calls
+===
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document descries the design and implementation of HLSL's function call
+semantics in Clang. This includes details related to argument conversion and
+parameter lifetimes.
+
+This document does not seek to serve as official documentation for HLSL's
+call semantics, but does provide an overview to assist a reader. The
+authoritative documentation for HLSL's language semantics is the `draft 
language
+specification`_.
+
+Argument Semantics
+==
+
+In HLSL, all function arguments are passed by value in and out of functions.
+HLSL has 3 keywords which denote the parameter semantics (``in``, ``out`` and
+``inout``). In a function declaration a parameter may be annotated any of the
+following ways:
+
+#.  - denotes input
+#. ``in`` - denotes input
+#. ``out`` - denotes output
+#. ``in out`` - denotes input and output
+#. ``out in`` - denotes input and output
+#. ``inout`` - denotes input and output
+
+Parameters that are exclusively input behave like C/C++ parameters that are
+passed by value.
+
+For parameters that are output (or input and output), a temporary value is
+created in the caller. The temporary value is then passed by-address. For
+output-only parameters, the temporary is uninitialized when passed (it is
+undefined behavior to not explicitly initialize an ``out`` parameter inside a
+function). For input and output parameters, the temporary is initialized from
+the lvalue argument expression through implicit or explicit casting from the
+lvalue argument type to the parameter type.
+
+On return of the function, the values of any parameter temporaries are written
+back to the argument expression through an inverted conversion sequence (if an
+``out`` parameter was not initialized in the function, the uninitialized value
+may be written back).
+
+Parameters of constant-sized array type, are also passed with value semantics.
+This requires input parameters of arrays to construct temporaries and the
+temporaries go through array-to-pointer decay when initializing parameters.
+
+Implementations are allowed to avoid unnecessary temporaries, and HLSL's strict
+no-alias rules can enable some trivial optimizations.
+
+Array Temporaries
+-
+
+Given the following example:
+
+.. code-block:: c++
+  void fn(float a[4]) {
+a[0] = a[1] + a[2] + a[3];
+  }
+
+  float4 main() : SV_Target {
+float arr[4] = {1, 1, 1, 1};
+fn(arr);
+return float4(a[0], a[1], a[2], a[3]);
+  }
+
+In C or C++, the array parameter decays to a pointer, so after the call to
+``fn``, the value of ``a[0]`` is ``3``. In HLSL, the array is passed by value,
+so modifications inside ``fn`` do not propagate out.
+
+.. note::
+  DXC supports unsized arrays passed directly as decayed pointers, which is an
+  unfortunate behavior divergence.
+
+Out Parameter Temporaries
+-
+
+.. code-block:: c++
+  void Init(inout int X, inout int Y) {
+Y = 2;
+X = 1;
+  }
+
+  void main() {
+int V;
+Init(V, V); // MSVC ABI V == 2, Itanium V == 1
+  }
+
+In the above example the ``Init`` function's behavior depends on the C++ ABI
+implementation. In the MSVC C++ ABI (used for the HLSL DXIL target), call

bogner wrote:

This is mostly me being pedantic, but I don't believe this ordering is 
specified in the Itanium ABI at all (and I don't see anything obvious here: 
https://itanium-cxx-abi.github.io/cxx-abi/abi.html). I'm not sure about the 
MSVC ABI. Would it be more accurate to point out that C++ has historically not 
defined this ordering, describe the two alternatives, and point out that DXC 
behaves in the MSVC way and so we want to match that?

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


[clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2023-12-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,319 @@
+===
+HLSL Function Calls
+===
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the design and implementation of HLSL's function call
+semantics in Clang. This includes details related to argument conversion and
+parameter lifetimes.
+
+This document does not seek to serve as official documentation for HLSL's
+call semantics, but does provide an overview to assist a reader. The
+authoritative documentation for HLSL's language semantics is the `draft 
language
+specification `_.
+
+Argument Semantics
+==
+
+In HLSL, all function arguments are passed by value in and out of functions.
+HLSL has 3 keywords which denote the parameter semantics (``in``, ``out`` and
+``inout``). In a function declaration a parameter may be annotated any of the
+following ways:
+
+#.  - denotes input
+#. ``in`` - denotes input
+#. ``out`` - denotes output
+#. ``in out`` - denotes input and output
+#. ``out in`` - denotes input and output
+#. ``inout`` - denotes input and output
+
+Parameters that are exclusively input behave like C/C++ parameters that are
+passed by value.
+
+For parameters that are output (or input and output), a temporary value is
+created in the caller. The temporary value is then passed by-address. For
+output-only parameters, the temporary is uninitialized when passed (if the
+parameter is not explicitly initialized inside the function an undefined value
+is stored back to the argument expression). For input and output parameters, 
the
+temporary is initialized from  the lvalue argument expression through implicit
+or explicit casting from the lvalue argument type to the parameter type.
+
+On return of the function, the values of any parameter temporaries are written
+back to the argument expression through an inverted conversion sequence (if an
+``out`` parameter was not initialized in the function, the uninitialized value
+may be written back).
+
+Parameters of constant-sized array type, are also passed with value semantics.

bogner wrote:

spurious comma

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


[clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2023-12-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,319 @@
+===
+HLSL Function Calls
+===
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the design and implementation of HLSL's function call
+semantics in Clang. This includes details related to argument conversion and
+parameter lifetimes.
+
+This document does not seek to serve as official documentation for HLSL's
+call semantics, but does provide an overview to assist a reader. The
+authoritative documentation for HLSL's language semantics is the `draft 
language
+specification `_.
+
+Argument Semantics
+==
+
+In HLSL, all function arguments are passed by value in and out of functions.
+HLSL has 3 keywords which denote the parameter semantics (``in``, ``out`` and
+``inout``). In a function declaration a parameter may be annotated any of the
+following ways:
+
+#.  - denotes input
+#. ``in`` - denotes input
+#. ``out`` - denotes output
+#. ``in out`` - denotes input and output
+#. ``out in`` - denotes input and output
+#. ``inout`` - denotes input and output
+
+Parameters that are exclusively input behave like C/C++ parameters that are
+passed by value.
+
+For parameters that are output (or input and output), a temporary value is
+created in the caller. The temporary value is then passed by-address. For
+output-only parameters, the temporary is uninitialized when passed (if the
+parameter is not explicitly initialized inside the function an undefined value
+is stored back to the argument expression). For input and output parameters, 
the
+temporary is initialized from  the lvalue argument expression through implicit
+or explicit casting from the lvalue argument type to the parameter type.

bogner wrote:

There's a little bit of ambiguity in this paragraph when you use the term 
"input and output", where it could be read as "parameters that are input and 
parameters that are output" rather than "parameters that are both input and 
output". I'm not sure the best way to improve this without getting overly wordy 
though - I suppose we could spell it "input-and-output" to be clear that it's 
atomic, or maybe we could use "both" and update that in the list above as well.

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


[clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2023-12-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,316 @@
+===
+HLSL Function Calls
+===
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the design and implementation of HLSL's function call
+semantics in Clang. This includes details related to argument conversion and
+parameter lifetimes.
+
+This document does not seek to serve as official documentation for HLSL's
+call semantics, but does provide an overview to assist a reader. The
+authoritative documentation for HLSL's language semantics is the `draft 
language
+specification `_.
+
+Argument Semantics
+==
+
+In HLSL, all function arguments are passed by value in and out of functions.
+HLSL has 3 keywords which denote the parameter semantics (``in``, ``out`` and
+``inout``). In a function declaration a parameter may be annotated any of the
+following ways:
+
+#.  - denotes input
+#. ``in`` - denotes input
+#. ``out`` - denotes output
+#. ``in out`` - denotes input and output
+#. ``out in`` - denotes input and output
+#. ``inout`` - denotes input and output
+
+Parameters that are exclusively input behave like C/C++ parameters that are
+passed by value.
+
+For parameters that are output (or input and output), a temporary value is
+created in the caller. The temporary value is then passed by-address. For
+output-only parameters, the temporary is uninitialized when passed (it is
+undefined behavior to not explicitly initialize an ``out`` parameter inside a
+function). For input and output parameters, the temporary is initialized from
+the lvalue argument expression through implicit or explicit casting from the
+lvalue argument type to the parameter type.
+
+On return of the function, the values of any parameter temporaries are written
+back to the argument expression through an inverted conversion sequence (if an
+``out`` parameter was not initialized in the function, the uninitialized value
+may be written back).
+
+Parameters of constant-sized array type, are also passed with value semantics.
+This requires input parameters of arrays to construct temporaries and the
+temporaries go through array-to-pointer decay when initializing parameters.
+
+Implementations are allowed to avoid unnecessary temporaries, and HLSL's strict
+no-alias rules can enable some trivial optimizations.
+
+Array Temporaries
+-
+
+Given the following example:
+
+.. code-block:: c++
+
+  void fn(float a[4]) {
+a[0] = a[1] + a[2] + a[3];
+  }
+
+  float4 main() : SV_Target {
+float arr[4] = {1, 1, 1, 1};
+fn(arr);
+return float4(a[0], a[1], a[2], a[3]);
+  }
+
+In C or C++, the array parameter decays to a pointer, so after the call to
+``fn``, the value of ``a[0]`` is ``3``. In HLSL, the array is passed by value,
+so modifications inside ``fn`` do not propagate out.
+
+.. note::
+
+  DXC supports unsized arrays passed directly as decayed pointers, which is an
+  unfortunate behavior divergence.

bogner wrote:

Maybe the note should say something like "DXC may pass unsized arrays directly 
as decayed pointers, which is an unfortunate behavior divergence" then, rather 
than claiming support?

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


[llvm] [clang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)

2023-12-15 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/75674

Rather than shepherding a type name all the way to the backend as a
string and attempting to parse it, get the element type out of the AST
and store that in the resource annotation metadata directly.


>From 9d6e00bd972a563daefd67b544614e2bb609cc42 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 15 Dec 2023 16:29:09 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 63 +++--
 clang/lib/CodeGen/CGHLSLRuntime.h |  2 +-
 .../builtins/RWBuffer-annotations.hlsl| 14 +--
 .../builtins/RWBuffer-elementtype.hlsl| 52 +++
 .../RasterizerOrderedBuffer-annotations.hlsl  | 12 +--
 clang/test/CodeGenHLSL/cbuf.hlsl  |  4 +-
 .../include/llvm/Frontend/HLSL/HLSLResource.h | 27 +-
 llvm/lib/Frontend/HLSL/HLSLResource.cpp   | 17 ++--
 llvm/lib/Target/DirectX/DXILResource.cpp  | 92 ++-
 llvm/lib/Target/DirectX/DXILResource.h| 37 ++--
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  | 22 ++---
 11 files changed, 204 insertions(+), 138 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 3e8a40e7540bef..e887d35198b3c7 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -182,10 +182,8 @@ void CGHLSLRuntime::finishCodeGen() {
 llvm::hlsl::ResourceKind RK = Buf.IsCBuffer
   ? llvm::hlsl::ResourceKind::CBuffer
   : llvm::hlsl::ResourceKind::TBuffer;
-std::string TyName =
-Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty";
-addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false,
-Buf.Binding);
+addBufferResourceAnnotation(GV, RC, RK, /*IsROV=*/false,
+llvm::hlsl::ElementType::Invalid, Buf.Binding);
   }
 }
 
@@ -194,10 +192,10 @@ CGHLSLRuntime::Buffer::Buffer(const HLSLBufferDecl *D)
   Binding(D->getAttr()) {}
 
 void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
-llvm::StringRef TyName,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
 bool IsROV,
+llvm::hlsl::ElementType ET,
 BufferResBinding &Binding) {
   llvm::Module &M = CGM.getModule();
 
@@ -216,15 +214,62 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 assert(false && "Unsupported buffer type!");
 return;
   }
-
   assert(ResourceMD != nullptr &&
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
+static llvm::hlsl::ElementType
+calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) 
{
+  using llvm::hlsl::ElementType;
+
+  // TODO: We may need to update this when we add things like ByteAddressBuffer
+  // that don't have a template parameter (or, indeed, an element type).
+  const auto *TST = ResourceTy->getAs();
+  assert(TST && "Resource types must be template specializations");
+  ArrayRef Args = TST->template_arguments();
+  assert(!Args.empty() && "Resource has no element type");
+
+  // At this point we have a resource with an element type, so we can assume
+  // that it's valid or we would have diagnosed the error earlier.
+  QualType ElTy = Args[0].getAsType();
+
+  // We should either have a basic type or a vector of a basic type.
+  if (const auto *VecTy = ElTy->getAs())
+ElTy = VecTy->getElementType();
+
+  if (ElTy->isSignedIntegerType()) {
+switch (Context.getTypeSize(ElTy)) {
+case 16:
+  return ElementType::I16;
+case 32:
+  return ElementType::I32;
+case 64:
+  return ElementType::I64;
+}
+  } else if (ElTy->isUnsignedIntegerType()) {
+switch (Context.getTypeSize(ElTy)) {
+case 16:
+  return ElementType::U16;
+case 32:
+  return ElementType::U32;
+case 64:
+  return ElementType::U64;
+}
+  } else if (ElTy->isSpecificBuiltinType(BuiltinType::Half))
+return ElementType::F16;
+  else if (ElTy->isSpecificBuiltinType(BuiltinType::Float))
+return ElementType::F32;
+  else if (ElTy->isSpecificBuilti

[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)

2023-12-18 Thread Justin Bogner via cfe-commits


@@ -253,35 +246,6 @@ void UAVResource::print(raw_ostream &OS) const {
   ResourceBase::print(OS, "U", "u");
 }
 
-// FIXME: Capture this in HLSL source. I would go do this right now, but I want
-// to get this in first so that I can make sure to capture all the extra
-// information we need to remove the source type string from here (See issue:
-// https://github.com/llvm/llvm-project/issues/57991).

bogner wrote:

This comment was kind of stale. That issue only mentioned capturing shape and 
ROV, which are both captured in the HLSL source before this change (and indeed 
the issue is closed). The issue this PR fixes is the obvious extension of that 
one, https://github.com/llvm/llvm-project/issues/70686

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


[clang] [llvm] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)

2023-12-18 Thread Justin Bogner via cfe-commits


@@ -216,15 +214,62 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 assert(false && "Unsupported buffer type!");
 return;
   }
-
   assert(ResourceMD != nullptr &&
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
+static llvm::hlsl::ElementType
+calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) 
{
+  using llvm::hlsl::ElementType;
+
+  // TODO: We may need to update this when we add things like ByteAddressBuffer
+  // that don't have a template parameter (or, indeed, an element type).
+  const auto *TST = ResourceTy->getAs();
+  assert(TST && "Resource types must be template specializations");
+  ArrayRef Args = TST->template_arguments();
+  assert(!Args.empty() && "Resource has no element type");
+
+  // At this point we have a resource with an element type, so we can assume
+  // that it's valid or we would have diagnosed the error earlier.
+  QualType ElTy = Args[0].getAsType();
+
+  // We should either have a basic type or a vector of a basic type.

bogner wrote:

I can't really find good documentation on what element types are really 
supposed to be allowed for resources, and dxc doesn't do a great job of 
diagnosing these things. However, it doesn't look like matrix types are 
supported here, at least in practice: https://hlsl.godbolt.org/z/aaze4ceYs

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


[libcxx] [flang] [llvm] [lldb] [libcxxabi] [clang] [clang-tools-extra] [lld] [compiler-rt] [libc] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)

2023-12-18 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/75674

>From 9d6e00bd972a563daefd67b544614e2bb609cc42 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 15 Dec 2023 16:29:09 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 63 +++--
 clang/lib/CodeGen/CGHLSLRuntime.h |  2 +-
 .../builtins/RWBuffer-annotations.hlsl| 14 +--
 .../builtins/RWBuffer-elementtype.hlsl| 52 +++
 .../RasterizerOrderedBuffer-annotations.hlsl  | 12 +--
 clang/test/CodeGenHLSL/cbuf.hlsl  |  4 +-
 .../include/llvm/Frontend/HLSL/HLSLResource.h | 27 +-
 llvm/lib/Frontend/HLSL/HLSLResource.cpp   | 17 ++--
 llvm/lib/Target/DirectX/DXILResource.cpp  | 92 ++-
 llvm/lib/Target/DirectX/DXILResource.h| 37 ++--
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  | 22 ++---
 11 files changed, 204 insertions(+), 138 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 3e8a40e7540bef..e887d35198b3c7 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -182,10 +182,8 @@ void CGHLSLRuntime::finishCodeGen() {
 llvm::hlsl::ResourceKind RK = Buf.IsCBuffer
   ? llvm::hlsl::ResourceKind::CBuffer
   : llvm::hlsl::ResourceKind::TBuffer;
-std::string TyName =
-Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty";
-addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false,
-Buf.Binding);
+addBufferResourceAnnotation(GV, RC, RK, /*IsROV=*/false,
+llvm::hlsl::ElementType::Invalid, Buf.Binding);
   }
 }
 
@@ -194,10 +192,10 @@ CGHLSLRuntime::Buffer::Buffer(const HLSLBufferDecl *D)
   Binding(D->getAttr()) {}
 
 void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
-llvm::StringRef TyName,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
 bool IsROV,
+llvm::hlsl::ElementType ET,
 BufferResBinding &Binding) {
   llvm::Module &M = CGM.getModule();
 
@@ -216,15 +214,62 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 assert(false && "Unsupported buffer type!");
 return;
   }
-
   assert(ResourceMD != nullptr &&
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
+static llvm::hlsl::ElementType
+calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) 
{
+  using llvm::hlsl::ElementType;
+
+  // TODO: We may need to update this when we add things like ByteAddressBuffer
+  // that don't have a template parameter (or, indeed, an element type).
+  const auto *TST = ResourceTy->getAs();
+  assert(TST && "Resource types must be template specializations");
+  ArrayRef Args = TST->template_arguments();
+  assert(!Args.empty() && "Resource has no element type");
+
+  // At this point we have a resource with an element type, so we can assume
+  // that it's valid or we would have diagnosed the error earlier.
+  QualType ElTy = Args[0].getAsType();
+
+  // We should either have a basic type or a vector of a basic type.
+  if (const auto *VecTy = ElTy->getAs())
+ElTy = VecTy->getElementType();
+
+  if (ElTy->isSignedIntegerType()) {
+switch (Context.getTypeSize(ElTy)) {
+case 16:
+  return ElementType::I16;
+case 32:
+  return ElementType::I32;
+case 64:
+  return ElementType::I64;
+}
+  } else if (ElTy->isUnsignedIntegerType()) {
+switch (Context.getTypeSize(ElTy)) {
+case 16:
+  return ElementType::U16;
+case 32:
+  return ElementType::U32;
+case 64:
+  return ElementType::U64;
+}
+  } else if (ElTy->isSpecificBuiltinType(BuiltinType::Half))
+return ElementType::F16;
+  else if (ElTy->isSpecificBuiltinType(BuiltinType::Float))
+return ElementType::F32;
+  else if (ElTy->isSpecificBuiltinType(BuiltinType::Double))
+return ElementType::F64;
+
+  // TODO: We need to handle unorm/snorm float types here once we support them
+  llvm_unreachable("Invalid element type for resource");
+}
+

[compiler-rt] [clang-tools-extra] [libcxx] [lldb] [clang] [libc] [llvm] [libcxxabi] [lld] [flang] [HLSL][DirectX] Move handling of resource element types into the frontend (PR #75674)

2023-12-18 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2023-12-19 Thread Justin Bogner via cfe-commits

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


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


[clang-tools-extra] [libc] [flang] [clang] [compiler-rt] [libcxx] [llvm] [IR] Disallow ZeroInit for spirv.Image (PR #73887)

2023-12-19 Thread Justin Bogner via cfe-commits

bogner wrote:

This change causes a number of the spir-v backend tests to crash:
> Failed Tests (5):
>   LLVM :: CodeGen/SPIRV/image-unoptimized.ll
>   LLVM :: CodeGen/SPIRV/read_image.ll
>   LLVM :: CodeGen/SPIRV/transcoding/get_image_num_mip_levels.ll
>   LLVM :: CodeGen/SPIRV/transcoding/image_with_access_qualifiers.ll
>   LLVM :: CodeGen/SPIRV/transcoding/spirv-types.ll

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


[llvm] [clang] [clang-tools-extra] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-29 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71264

>From cab6bcd73081fcbe9807adbf60b345f8d9e654e4 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 18:59:49 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9b7..a86c428c9121abf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e453126..de5cc07f5d42865 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f9a..0952b065d56b58e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac76..603b7465323e237 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee354862212803f..1a6eaa196db09be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid

[clang] [llvm] [clang-tools-extra] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-29 Thread Justin Bogner via cfe-commits

bogner wrote:

> That's a lot of repeated code. Should we have a "NoteTemplateLocation" 
> function(s) of some sort that would do the check and the diag as appropriate?

Makes sense to me, and also makes @AaronBallman's idea of emitting notes 
referring to the external source a little easier. Done in the latest update.

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


[clang-tools-extra] [llvm] [clang] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-29 Thread Justin Bogner via cfe-commits

bogner wrote:

> I agree that "is declared here" is useless when "here" is... nowhere. But the 
> point to the note is to help the user to see what the actual declaration is 
> to help them repair the issue. Losing the note entirely isn't the worst 
> thing, but I wonder if it would be better for declarations coming from 
> external AST sources to pretty print the declaration instead? e.g., Before:
> 
> ```
> hlsl::vector<1> BadVec; // expected-error{{template argument for template 
> type parameter must be a type}}
> // expected-note@*:* {{template is declared here}}
> // expected-note@*:* {{template parameter is declared here}}
> ```
> 
> After:
> 
> ```
> hlsl::vector<1> BadVec; // expected-error{{template argument for template 
> type parameter must be a type}}
> // expected-note@-1 {{template declaration from hidden source: template 
>  vector}}
> // expected-note@-2 {{template parameter from hidden source: typename Ty}}
> ```
> 
> This would give the user more relevant information than just dropping the 
> notes. (I have no idea if I'm asking for something incredibly difficult but I 
> was thinking we could use the declaration printer to print this information 
> out to the diagnostic in these cases.)

I made an attempt at this, and I think I like it. It does have a bit of novelty 
in terms of how it generates appropriate errors though.

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


[flang] [libcxx] [libcxxabi] [lldb] [llvm] [libunwind] [clang-tools-extra] [openmp] [clang] [lld] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-30 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71264

>From cab6bcd73081fcbe9807adbf60b345f8d9e654e4 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 18:59:49 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9b7..a86c428c9121abf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e453126..de5cc07f5d42865 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f9a..0952b065d56b58e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac76..603b7465323e237 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee354862212803f..1a6eaa196db09be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid

[clang-tools-extra] [lld] [clang] [openmp] [mlir] [lldb] [llvm] [flang] [libunwind] [libcxx] [libc] [libcxxabi] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-30 Thread Justin Bogner via cfe-commits

https://github.com/bogner updated 
https://github.com/llvm/llvm-project/pull/71264

>From cab6bcd73081fcbe9807adbf60b345f8d9e654e4 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 3 Nov 2023 18:59:49 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/lib/Sema/SemaInit.cpp   |   3 +-
 clang/lib/Sema/SemaLambda.cpp |   3 +-
 clang/lib/Sema/SemaTemplate.cpp   | 123 --
 clang/lib/Sema/SemaType.cpp   |   3 +-
 .../test/SemaHLSL/BuiltIns/vector-errors.hlsl |   5 -
 7 files changed, 89 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 396566a8f10a9b7..a86c428c9121abf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5929,7 +5929,7 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) 
{
   Diag(Name.StartLocation,
diag::err_deduction_guide_name_not_class_template)
 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
-  if (Template)
+  if (Template && Template->getLocation().isValid())
 Diag(Template->getLocation(), diag::note_template_decl_here);
   return DeclarationNameInfo();
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 397b7a00e453126..de5cc07f5d42865 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11462,7 +11462,8 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, 
QualType &R,
   GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope)
   << GuidedTemplateDecl;
-Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
+if (GuidedTemplateDecl->getLocation().isValid())
+  Diag(GuidedTemplateDecl->getLocation(), diag::note_template_decl_here);
   }
 
   auto &DS = D.getMutableDeclSpec();
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ed02d3580f34f9a..0952b065d56b58e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10575,7 +10575,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
  diag::err_deduced_non_class_template_specialization_type)
   << (int)getTemplateNameKindForDiagnostics(TemplateName) << TemplateName;
 if (auto *TD = TemplateName.getAsTemplateDecl())
-  Diag(TD->getLocation(), diag::note_template_decl_here);
+  if (TD->getLocation().isValid())
+Diag(TD->getLocation(), diag::note_template_decl_here);
 return QualType();
   }
 
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca09b0481bcac76..603b7465323e237 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1444,7 +1444,8 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
   for (const auto &Capture : Intro.Captures) {
 if (Capture.Id == TP->getIdentifier()) {
   Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
-  Diag(TP->getLocation(), diag::note_template_param_here);
+  if (TP->getLocation().isValid())
+Diag(TP->getLocation(), diag::note_template_param_here);
 }
   }
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index ee354862212803f..1a6eaa196db09be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -872,7 +872,7 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation 
PointOfInstantiation,
   Note = diag::note_explicit_instantiation_here;
 }
   }
-  if (Note) // Diagnostics were emitted.
+  if (Note && Pattern->getLocation().isValid()) // Diagnostics were emitted.
 Diag(Pattern->getLocation(), *Note);
 
   // In general, Instantiation isn't marked invalid to get more than one
@@ -899,7 +899,8 @@ void Sema::DiagnoseTemplateParameterShadow(SourceLocation 
Loc, Decl *PrevDecl) {
   unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow
  : diag::err_template_param_shadow;
   Diag(Loc, DiagId) << cast(PrevDecl)->getDeclName();
-  Diag(PrevDecl->getLocation(), diag::note_template_param_here);
+  if (PrevDecl->getLocation().isValid())
+Diag(PrevDecl->getLocation(), diag::note_template_param_here);
 }
 
 /// AdjustDeclIfTemplate - If the given decl happens to be a template, reset
@@ -4434,7 +4435,8 @@ static void checkMoreSpecializedThanPrimary(Sema &S, 
PartialSpecDecl *Partial) {
   << SFINAEArgString;
   }
 
-  S.Diag(Template->getLocation(), diag::note_template_decl_here);
+  if (Template->getLocation().isValid

[clang-tools-extra] [llvm] [libunwind] [mlir] [lld] [libc] [clang] [flang] [libcxx] [libcxxabi] [lldb] [openmp] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

2023-11-30 Thread Justin Bogner via cfe-commits


@@ -7909,6 +7903,37 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  Arg.getLocation());
 }
 
+static Sema::SemaDiagnosticBuilder noteLocation(Sema &S, const NamedDecl &Decl,
+unsigned HereDiagID,
+unsigned ExternalDiagID) {
+  if (Decl.getLocation().isValid())
+return S.Diag(Decl.getLocation(), HereDiagID);
+
+  SmallString<128> Str;
+  llvm::raw_svector_ostream Out(Str);
+  PrintingPolicy PP = S.getPrintingPolicy();
+  PP.TerseOutput = 1;
+  Decl.print(Out, PP);
+  return S.Diag(Decl.getLocation(), ExternalDiagID) << Out.str();

bogner wrote:

Using `<< &Decl` here just gives the name. With print we get:
```
template declaration from hidden source: template  using vector = element 
__attribute__((ext_vector_type(element_count)))
template parameter from hidden source: class element = float
```
whereas with the stream operator it's
```
note: template declaration from hidden source: 'vector'
note: template parameter from hidden source: 'element'
```

Similarly in #71265 it's the difference between printing `template  class RWBuffer final` vs just `RWBuffer`

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,105 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for any are generated for float and 
half.
+
+; CHECK:icmp ne i1 %{{.*}}, false
+define noundef i1 @any_bool(i1 noundef %p0) {

bogner wrote:

Probably worth adding a `; CHECK-LABEL: define {{.*}} @any_bool` or so to make 
sure these checks are looking at the right functions and also potentially 
improve the error message if they fail

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits

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

A couple more very minor notes on the tests, then this LGTM

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,105 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for any are generated for float and 
half.
+
+; CHECK:icmp ne i1 %{{.*}}, false

bogner wrote:

Folks usually put a space between `CHECK:` and the thing being checked (`CHECK: 
icmp ...`). I find that slightly more readable.

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


[clang] [llvm] [HLSL] Implement `rsqrt` intrinsic (PR #84820)

2024-03-14 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL] Implement `rsqrt` intrinsic (PR #84820)

2024-03-14 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL] Implement `rsqrt` intrinsic (PR #84820)

2024-03-14 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,26 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for rsqrt are generated for float 
and half.
+; CHECK:call float @dx.op.unary.f32(i32 25, float %{{.*}})
+; CHECK:call half @dx.op.unary.f16(i32 25, half %{{.*}})

bogner wrote:

Better for readability to put these check lines next to the functions they 
test. Could arguably throw in some `CHECK-LABEL` to anchor the checks too

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


[clang] [llvm] [HLSL] implement the `isinf` intrinsic (PR #84927)

2024-03-14 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL] implement the `isinf` intrinsic (PR #84927)

2024-03-14 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL] implement the `isinf` intrinsic (PR #84927)

2024-03-14 Thread Justin Bogner via cfe-commits


@@ -18050,6 +18050,21 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_isinf: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+llvm::Type *Xty = Op0->getType();
+llvm::Type *retType = llvm::Type::getInt1Ty(this->getLLVMContext());
+if (Xty->isVectorTy()) {
+  auto *XVecTy = E->getArg(0)->getType()->getAs();
+  retType = llvm::VectorType::get(
+  retType, ElementCount::getFixed(XVecTy->getNumElements()));
+}
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("isinf operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/retType, Intrinsic::dx_isinf, ArrayRef{Op0},

bogner wrote:

I see that this is just following the rest of the file so I guess no change 
needed, but it seems odd to tag "/*ReturnType=*/" here specifically - we 
usually only do that for bools and things that are ambiguous, where this is 
literally passing an argument called `retType`.

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


[clang] [llvm] [HLSL] implement `clamp` intrinsic (PR #85424)

2024-03-15 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL] implement `clamp` intrinsic (PR #85424)

2024-03-15 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL] implement `clamp` intrinsic (PR #85424)

2024-03-15 Thread Justin Bogner via cfe-commits


@@ -252,6 +252,116 @@ double3 ceil(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 double4 ceil(double4);
 
+//===--===//
+// clamp builtins
+//===--===//
+
+/// \fn T clamp(T X, T Min, T Max)
+/// \brief Clamps the specified value \a X to the specified
+/// minimum ( \a Min) and maximum ( \a Max) range.
+/// \param X A value to clamp.
+/// \param Min The specified minimum range.
+/// \param Max The specified maximum range.
+///
+/// Returns The clamped value for the \a X parameter.
+/// For values of -INF or INF, clamp will behave as expected.
+/// However for values of NaN, the results are undefined.
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
+half clamp(half, half, half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
+half2 clamp(half2, half2, half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
+half3 clamp(half3, half3, half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
+half4 clamp(half4, half4, half4);
+
+#ifdef __HLSL_ENABLE_16_BIT

bogner wrote:

This is pre-existing, so no change needed here, but maybe we should revisit it 
later. The difference between `_HLSL_16BIT_AVAILABILITY` (for half) and 
guarding with `#ifdef __HLSL_ENABLE_16BIT` (for int16/uint16) feels kind of 
subtle. I worry we could make mistakes here in the future.

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


[clang] [llvm] [HLSL] implement `clamp` intrinsic (PR #85424)

2024-03-15 Thread Justin Bogner via cfe-commits


@@ -132,12 +134,60 @@ static bool expandRcpIntrinsic(CallInst *Orig) {
   return true;
 }
 
+static Intrinsic::ID getCorrectMaxIntrinsic(Type *elemTy,
+Intrinsic::ID clampIntrinsic) {

bogner wrote:

I could see us needing to get a max intrinsic in some other context at some 
point. Maybe a more specific name like `getMaxForClamp` is better.

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


[clang] [HLSL] Fix for build break introduced by #85662 (PR #85839)

2024-03-19 Thread Justin Bogner via cfe-commits

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


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


[clang] [HLSL] Fix for build break introduced by #85662 (PR #85839)

2024-03-19 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL] Fix for build break introduced by #85662 (PR #85839)

2024-03-19 Thread Justin Bogner via cfe-commits

bogner wrote:

I've gone ahead and merged this since it fixes the build break. In the future 
when you see a build break, please just revert the breaking change to get the 
build green again and then work on the fixed patch. It's unfair to others using 
trunk to have to wait on a fix for an obvious build break.

https://github.com/llvm/llvm-project/pull/85839
___
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 Justin Bogner 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">;

bogner wrote:

When printing option flags in diagnostics they're usually in single quotes and 
include the leading dash, like `'-enable-16bit-types' option is only valid...`

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 Justin Bogner via cfe-commits


@@ -0,0 +1,20 @@
+// 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
+
+
+// both_invalid: error: enable-16bit-types option only valid when target 
shader model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021
+// HV_invalid: error: enable-16bit-types option only valid when target shader 
model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021
+// TP_invalid: error: enable-16bit-types option only valid when target shader 
model [-T] is >= 6.2 and HLSL Version [-HV] is >= 2021

bogner wrote:

It might be nice to parameterize the diagnostic here to just point out which 
thing is wrong rather than list the full set of requirements. Something like:
> "16-bit types are only valid for %select{shader model 6.2|HLSL version 2021}0 
> and above, but this is '%1'"

WDYT?

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] enforce unsigned types for reversebits (PR #86720)

2024-03-26 Thread Justin Bogner via cfe-commits


@@ -54,31 +29,6 @@ uint16_t4 test_bitreverse_ushort4(uint16_t4 p0)
 }
 #endif
 
-// CHECK: define noundef i32 @
-// CHECK: call i32 @llvm.bitreverse.i32(
-int test_bitreverse_int(int p0)
-{
-   return reversebits(p0);
-}

bogner wrote:

Will these implicitly convert to `uint` now, or are these errors?

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


[clang] [HLSL] enforce unsigned types for reversebits (PR #86720)

2024-03-26 Thread Justin Bogner via cfe-commits


@@ -54,31 +29,6 @@ uint16_t4 test_bitreverse_ushort4(uint16_t4 p0)
 }
 #endif
 
-// CHECK: define noundef i32 @
-// CHECK: call i32 @llvm.bitreverse.i32(
-int test_bitreverse_int(int p0)
-{
-   return reversebits(p0);
-}

bogner wrote:

In that case we might need to document this as a difference from dxc's 
behaviour, which doesn't seem to care whether it's given a signed or unsigned 
int: https://hlsl.godbolt.org/z/xqjvzas1K

TBH I'm a bit worried this will come up a fair amount on existing shaders.

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


[clang] [HLSL] enforce unsigned types for reversebits (PR #86720)

2024-03-26 Thread Justin Bogner via cfe-commits


@@ -54,31 +29,6 @@ uint16_t4 test_bitreverse_ushort4(uint16_t4 p0)
 }
 #endif
 
-// CHECK: define noundef i32 @
-// CHECK: call i32 @llvm.bitreverse.i32(
-int test_bitreverse_int(int p0)
-{
-   return reversebits(p0);
-}

bogner wrote:

Alright, let's get this in as is for now and loop back once the conversion 
story is in better shape.

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


[clang] [HLSL] enforce unsigned types for reversebits (PR #86720)

2024-03-26 Thread Justin Bogner via cfe-commits

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


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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++

bogner wrote:

This is hlsl, not c++

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits

https://github.com/bogner commented:

Ran into some problems when building `clang-docs-html` to look at this, so here 
are some notes on fixing those issues. I'll do another pass on the content next.

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…

bogner wrote:

sphinx/pygments chokes on the ellipsis here, best to spell it "..."

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++

bogner wrote:

This isn't C++. I think you could use "peg" here based on 
https://pygments.org/docs/lexers/#lexers-for-grammar-notations-like-bnf

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++

bogner wrote:

Should be "sh", not C++

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: c++
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: c++
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_WH

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: c++
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+…

bogner wrote:

I didn't mean to put quotes around it, I meant that this is a unicode ellipsis 
(ie, …) rather than three dots to represent an ellipsis (ie, ...). Sorry - it's 
hard to convey that in text since they look the same.

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


[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: hlsl
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+"…"
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: peg
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: hlsl
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+"…"
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: peg
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: hlsl
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+"…"
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: peg
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-27 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,426 @@
+
+HLSL Root Signatures
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, the `root signature
+`_ 
+defines what types of resources are bound to the graphics pipeline. 
+
+A root signature can be specified in HLSL as a `string
+`_.
 
+The string contains a collection of comma-separated clauses that describe root 
+signature constituent components. 
+
+There are two mechanisms to compile an HLSL root signature. First, it is 
+possible to attach a root signature string to a particular shader via the 
+RootSignature attribute (in the following example, using the MyRS1 entry 
+point):
+
+.. code-block:: hlsl
+
+#define RS "RootFlags( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | " \ 
+  "DENY_VERTEX_SHADER_ROOT_ACCESS), " \ 
+  "CBV(b0, space = 1, flags = DATA_STATIC), " \ 
+  "SRV(t0), " \ 
+  "UAV(u0), " \ 
+  "DescriptorTable( CBV(b1), " \ 
+  " SRV(t1, numDescriptors = 8, " \ 
+  " flags = DESCRIPTORS_VOLATILE), " \ 
+  " UAV(u1, numDescriptors = unbounded, " \ 
+  " flags = DESCRIPTORS_VOLATILE)), " \ 
+  "DescriptorTable(Sampler(s0, space=1, numDescriptors = 4)), " \ 
+  "RootConstants(num32BitConstants=3, b10), " \ 
+  "StaticSampler(s1)," \ 
+  "StaticSampler(s2, " \ 
+  "  addressU = TEXTURE_ADDRESS_CLAMP, " \ 
+  "  filter = FILTER_MIN_MAG_MIP_LINEAR )"
+
+[RootSignature(RS)]
+float4 main(float4 coord : COORD) : SV_Target
+{
+"…"
+}
+
+The compiler will create and verify the root signature blob for the shader and 
+embed it alongside the shader byte code into the shader blob. 
+
+The other mechanism is to create a standalone root signature blob, perhaps to 
+reuse it with a large set of shaders, saving space. The name of the define 
+string is specified via the usual -E argument. For example:
+
+.. code-block:: sh
+
+  dxc.exe -T rootsig_1_1 MyRS1.hlsl -E MyRS1 -Fo MyRS1.fxo
+
+Note that the root signature string define can also be passed on the command 
+line, e.g, -D MyRS1=”…”.
+
+Root Signature Grammar
+==
+
+.. code-block:: peg
+
+RootSignature : (RootElement(,RootElement)?)?
+
+RootElement : RootFlags | RootConstants | RootCBV | RootSRV | RootUAV |
+  DescriptorTable | StaticSampler
+
+RootFlags : 'RootFlags' '(' (RootFlag(|RootFlag)?)? ')'
+
+RootFlag : 'ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT' | 
+   'DENY_VERTEX_SHADER_ROOT_ACCESS'
+
+RootConstants : 'RootConstants' '(' 'num32BitConstants' '=' NUMBER ',' 
+   bReg (',' 'space' '=' NUMBER)? 
+   (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+RootCBV : 'CBV' '(' bReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootSRV : 'SRV' '(' tReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+RootUAV : 'UAV' '(' uReg (',' 'space' '=' NUMBER)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+DescriptorTable : 'DescriptorTable' '(' (DTClause(|DTClause)?)? 
+  (',' 'visibility' '=' SHADER_VISIBILITY)? ')'
+
+DTClause : CBV | SRV | UAV | Sampler
+
+CBV : 'CBV' '(' bReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+SRV : 'SRV' '(' tReg (',' 'numDescriptors' '=' NUMBER)? 
+(',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+UAV : 'UAV' '(' uReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? 
+  (',' 'flags' '=' DATA_FLAGS)? ')'
+
+Sampler : 'Sampler' '(' sReg (',' 'numDescriptors' '=' NUMBER)? 
+  (',' 'space' '=' NUMBER)? 
+  (',' 'offset' '=' DESCRIPTOR_RANGE_OFFSET)? (',' 'flags' '=' 
NUMBER)? ')'
+
+
+SHADER_VISIBILITY : 'SHADER_VISIBILITY_ALL' | 'SHADER_VISIBILITY_VERTEX' | 
+'SHADER_VISIBILITY_HULL' | 
+'SHADER_VISIBILITY_DOMAIN' | 
+'SHADER_VISIBILITY_GEOMETRY' | 
+'SHADER_VISIBILITY_PIXEL' | 
+'SHADER_VISIBILITY_AMPLIFICATION' | 
+'SHADER_VISIBILITY_MESH'
+
+DATA_FLAGS : 'DATA_STATIC_

[clang] [Doc][HLSL] Add documentation for root signature. (PR #83933)

2024-03-28 Thread Justin Bogner via cfe-commits

bogner wrote:

I think it would be helpful to add a section between the usage part and the 
grammar that discusses where and why in the compiler we need access to the 
parsed root signature (ie, in Sema for diagnostics, in the backend to verify 
resource usage matches, and also in the backend to lower to the serialized 
form). This would make it a little clearer why we need the various different 
representations since it will describe what we'll use them for.

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


[clang] Add clang_elementwise_builtin_alias (PR #86175)

2024-03-28 Thread Justin Bogner via cfe-commits

bogner wrote:

Thanks for working on this, but I think that what this shows is that the 
complexity of adding this elementwise alias builtin isn't quite justified by 
the utility. It's certainly convenient to be able to specify the builtins this 
way, but validation is a lot more complicated and I think this will be hard to 
test. Maybe we should consider this a successful experiment but drop the idea 
for now unless we run into a situation where we really need it in the future.

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


[clang] [llvm] [HLSL][DXIL] HLSL's `round` should follow `roundeven` behavior (PR #87078)

2024-03-29 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL][DXIL][SPIRV] Intrinsic unification PR (PR #87034)

2024-03-29 Thread Justin Bogner via cfe-commits

bogner wrote:

I have some misgivings about abusing the target intrinsic infrastructure like 
this to create "target" intrinsics for a non-existent target. IMO this is 
morally equivalent to just putting all of these intrinsics as generic llvm 
intrinsics (`llvm.thread_id` or `llvm.all`), just with some extra namespacing.

For a long time there has been some appetite for being able to strip the target 
intrinsics for targets you aren't building (see [this very old 
post](https://discourse.llvm.org/t/lets-stop-using-target-specific-intrinsics-in-generic-code/41783)
 or the [commit that split up intrinsic headers 
per-target](https://github.com/llvm/llvm-project/commit/5d986953c8b917bacfaa1f800fc1e242559f76be)).
 I worry that using the target infrastructure but keyed on something other than 
a target is a step in the wrong direction there.

The other concern is just about layering. Today, backends need to handle 
generic LLVM intrinsics and their own intrinsics *only*. This is introducing 
intrinsics that apply across an arbitrary set of backends (DirectX and SPIRV 
today, possibly some GPU or otherwise SIMT backends in the future...). What's 
the contract for who needs to handle them? Can we encode that contract in a way 
that isn't simply best effort as new intrinsics are added? As is, this approach 
makes those problems harder rather than easier.

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


[clang] [HLSL] Implement floating literal suffixes (PR #87270)

2024-04-01 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL] Implement floating literal suffixes (PR #87270)

2024-04-01 Thread Justin Bogner via cfe-commits

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


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


[clang] [HLSL] Implement floating literal suffixes (PR #87270)

2024-04-01 Thread Justin Bogner via cfe-commits


@@ -4117,14 +4117,17 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, 
Scope *UDLScope) {
   } else if (Literal.isFloatingLiteral()) {
 QualType Ty;
 if (Literal.isHalf){
-  if (getOpenCLOptions().isAvailableOption("cl_khr_fp16", getLangOpts()))
+  if (getLangOpts().HLSL ||
+  getOpenCLOptions().isAvailableOption("cl_khr_fp16", getLangOpts()))
 Ty = Context.HalfTy;
   else {
 Diag(Tok.getLocation(), diag::err_half_const_requires_fp16);
 return ExprError();
   }
 } else if (Literal.isFloat)
   Ty = Context.FloatTy;
+else if (getLangOpts().HLSL && Literal.isLong)
+  Ty = Context.DoubleTy;
 else if (Literal.isLong)
   Ty = Context.LongDoubleTy;

bogner wrote:

Probably better to put the HLSL check under the existing `Literal.isLong` 
check. This better matches the style of the rest of the function and will 
probably be less error-prone if something changes here in the future.

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


[clang] [NFC] Add API documentation and annotations (PR #78635)

2024-02-13 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

2024-03-05 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL] implement exp intrinsic (PR #83832)

2024-03-05 Thread Justin Bogner via cfe-commits

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


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


  1   2   3   4   5   6   7   8   9   >