[clang] 5b95931 - [NFC] Delete unintentionally added file

2024-04-03 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-04-03T11:24:48-05:00
New Revision: 5b959310b0fae723bd119ed8815bf1cb1a8c67d4

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

LOG: [NFC] Delete unintentionally added file

Added: 


Modified: 


Removed: 
clang/test/SemaHLSL/ArrayTemporary.ll



diff  --git a/clang/test/SemaHLSL/ArrayTemporary.ll 
b/clang/test/SemaHLSL/ArrayTemporary.ll
deleted file mode 100644
index 5eec0094865bae..00
--- a/clang/test/SemaHLSL/ArrayTemporary.ll
+++ /dev/null
@@ -1,76 +0,0 @@
-; ModuleID = 
'/Users/cbieneman/dev/llvm-project/clang/test/SemaHLSL/ArrayTemporary.hlsl'
-source_filename = 
"/Users/cbieneman/dev/llvm-project/clang/test/SemaHLSL/ArrayTemporary.hlsl"
-target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-pc-shadermodel6.3-library"
-
-%struct.Obj = type { float, i32 }
-
-@"__const.?call3@@YAXXZ.Arr" = private unnamed_addr constant [2 x [2 x float]] 
[[2 x float] zeroinitializer, [2 x float] [float 1.00e+00, float 
1.00e+00]], align 4
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn@@YAXY01M@Z"(ptr noundef byval([2 x float]) align 4 %x) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [2 x float], align 4
-  %agg.tmp = alloca [2 x float], align 4
-  call void @llvm.memset.p0.i32(ptr align 4 %Arr, i8 0, i32 8, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
8, i1 false)
-  call void @"?fn@@YAXY01M@Z"(ptr noundef byval([2 x float]) align 4 %agg.tmp)
-  ret void
-}
-
-; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
-declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) 
#1
-
-; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: 
readwrite)
-declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr 
noalias nocapture readonly, i32, i1 immarg) #2
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn2@@YAXY03UObj@@@Z"(ptr noundef byval([4 x %struct.Obj]) align 
4 %O) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call2@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [4 x %struct.Obj], align 4
-  %agg.tmp = alloca [4 x %struct.Obj], align 4
-  call void @llvm.memset.p0.i32(ptr align 4 %Arr, i8 0, i32 32, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
32, i1 false)
-  call void @"?fn2@@YAXY03UObj@@@Z"(ptr noundef byval([4 x %struct.Obj]) align 
4 %agg.tmp)
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?fn3@@YAXY111M@Z"(ptr noundef byval([2 x [2 x float]]) align 4 
%x) #0 {
-entry:
-  ret void
-}
-
-; Function Attrs: noinline nounwind optnone
-define void @"?call3@@YAXXZ"() #0 {
-entry:
-  %Arr = alloca [2 x [2 x float]], align 4
-  %agg.tmp = alloca [2 x [2 x float]], align 4
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Arr, ptr align 4 
@"__const.?call3@@YAXXZ.Arr", i32 16, i1 false)
-  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.tmp, ptr align 4 %Arr, i32 
16, i1 false)
-  call void @"?fn3@@YAXY111M@Z"(ptr noundef byval([2 x [2 x float]]) align 4 
%agg.tmp)
-  ret void
-}
-
-attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
-attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: 
readwrite) }
-
-!llvm.module.flags = !{!0, !1}
-!llvm.ident = !{!2}
-
-!0 = !{i32 1, !"wchar_size", i32 4}
-!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
-!2 = !{!"clang version 19.0.0git (g...@github.com:llvm/llvm-project.git 
64e1c15c520cf4ef2ddd887e76560903db2b)"}



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


[clang] f119a4f - [HLSL] Fix broken spir-v test

2024-04-02 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-04-02T15:53:17-05:00
New Revision: f119a4ffb885ed588c46de1d51f4185572142ca2

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

LOG: [HLSL] Fix broken spir-v test

This fixes a test broken in 3d469c0e7c3072f0dad0f5e9bd0c74dffaf83cd3.
fast-forwarded.
../clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl

Added: 


Modified: 
clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl

Removed: 




diff  --git a/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl 
b/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl
index 379c8f118f52f3..6ea80d692cd244 100644
--- a/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/wave_get_lane_index_subcall.hlsl
@@ -12,7 +12,7 @@ uint test_1() {
 
 // CHECK: define spir_func noundef i32 @_Z6test_2v() [[A0]] {
 // CHECK: %[[C2:[0-9]+]] = call token @llvm.experimental.convergence.entry()
-// CHECK: call spir_func noundef i32 @_Z6test_1v() [ "convergencectrl"(token 
%[[C2]]) ]
+// CHECK: call spir_func noundef i32 @_Z6test_1v() {{#[0-9]+}} [ 
"convergencectrl"(token %[[C2]]) ]
 uint test_2() {
   return test_1();
 }



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


[clang] 0065161 - Remove assert introduced in #71098

2024-02-15 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-02-15T18:56:35-06:00
New Revision: 0065161c720c37e8ab545979aed6a03d944a3176

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

LOG: Remove assert introduced in #71098

This should effectively preserve the old behavior for non-HLSL code.

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 13526de3e76421..576734e460b9c1 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2425,8 +2425,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   case CK_IntegralToFloating: {
 if (E->getType()->isVectorType() && DestTy->isVectorType()) {
   // TODO: Support constrained FP intrinsics.
-  assert(!Builder.getIsFPConstrained() &&
- "FP Constrained vector casts not supported yet.");
   QualType SrcElTy = E->getType()->castAs()->getElementType();
   if (SrcElTy->isSignedIntegerOrEnumerationType())
 return Builder.CreateSIToFP(Visit(E), ConvertType(DestTy), "conv");
@@ -2439,8 +2437,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   case CK_FloatingToIntegral: {
 if (E->getType()->isVectorType() && DestTy->isVectorType()) {
   // TODO: Support constrained FP intrinsics.
-  assert(!Builder.getIsFPConstrained() &&
- "FP Constrained vector casts not supported yet.");
   QualType DstElTy = DestTy->castAs()->getElementType();
   if (DstElTy->isSignedIntegerOrEnumerationType())
 return Builder.CreateFPToSI(Visit(E), ConvertType(DestTy), "conv");
@@ -2453,8 +2449,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   case CK_FloatingCast: {
 if (E->getType()->isVectorType() && DestTy->isVectorType()) {
   // TODO: Support constrained FP intrinsics.
-  assert(!Builder.getIsFPConstrained() &&
- "FP Constrained vector casts not supported yet.");
   QualType SrcElTy = E->getType()->castAs()->getElementType();
   QualType DstElTy = DestTy->castAs()->getElementType();
   if (DstElTy->castAs()->getKind() <



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


[clang] a1155f6 - [NFC] Clang-format const array declarations

2024-02-15 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-02-15T13:16:21-06:00
New Revision: a1155f68f5d5c7013ca1deb312a2e1e4f71ef544

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

LOG: [NFC] Clang-format const array declarations

This just updates indentation of constant array declarations to be
style conformant.

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9381b8c6626b64..5c6d463bb895df 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -123,43 +123,42 @@ CompareDerivedToBaseConversions(Sema &S, SourceLocation 
Loc,
 /// GetConversionRank - Retrieve the implicit conversion rank
 /// corresponding to the given implicit conversion kind.
 ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) {
-  static const ImplicitConversionRank
-Rank[] = {
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_OCL_Scalar_Widening,
-ICR_Complex_Real_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Writeback_Conversion,
-ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Event_Conversion
-ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Queue_Conversion
-ICR_C_Conversion,
-ICR_C_Conversion_Extension,
-ICR_Conversion,
+  static const ImplicitConversionRank Rank[] = {
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Promotion,
+  ICR_Promotion,
+  ICR_Promotion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_OCL_Scalar_Widening,
+  ICR_Complex_Real_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Writeback_Conversion,
+  ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Event_Conversion
+  ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Queue_Conversion
+  ICR_C_Conversion,
+  ICR_C_Conversion_Extension,
+  ICR_Conversion,
   };
   static_assert(std::size(Rank) == (int)ICK_Num_Conversion_Kinds);
   return Rank[(int)Kind];
@@ -167,39 +166,39 @@ ImplicitConversionRank 
clang::GetConversionRank(ImplicitConversionKind Kind) {
 
 /// GetImplicitConversionName - Return the name of this kind of
 /// implicit conversion.
-static const char* GetImplicitConversionName(ImplicitConversionKind Kind) {
-  static const char* const Name[] = {
-"No conversion",
-"Lvalue-to-rvalue",
-"Array-to-pointer",
-"Function-to-pointer",
-"Function pointer conversion",
-"Qualification",
-"Integral promotion",
-"Floating point promotion",
-"Complex promotion",
-"Integral conversion",
-"Floating conversion",
-"Complex conversion",
-"Floating-integral conversion",
-"Pointer conversion",
-"Pointer-to-member conversion",
-"Boolean conversion",
-"Compatible-types conversion",
-"Derived-to-base conversion",
-"Vector conversion",
-"SVE Vector conversion",
-"RVV Vector conversion",
-"Vector splat",
-"Complex-real conversion",
-"Block Pointer conversion",
-"Transparent Union Conversion",
-"Writeback conversion",
-"OpenCL Zero Event Conversion",
-"OpenCL Zero Queue Conversion",
-"C specific type conversion",
-"Incompatible pointer conversion",
-"Fixed point conversion",
+static const char *GetImplicitConversionName(ImplicitConversionKind Kind) {
+  static const char *const Name[] = {
+  "No conversion",
+  "Lvalue-to-rvalue",
+  "Array-to-pointer",
+  "Function-to-pointer",
+  "Function pointer conversion",
+  "Qualification",
+  "Integral promotion

[clang] c2fd5b7 - [NFC] Remove trailing whitespace

2024-01-11 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2024-01-11T12:34:51-06:00
New Revision: c2fd5b738e9700a515f1730c714897eeec064157

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

LOG: [NFC] Remove trailing whitespace

This seems to be causing problems that I couldn't reproduce locally.

Added: 


Modified: 
clang/docs/HLSL/FunctionCalls.rst

Removed: 




diff  --git a/clang/docs/HLSL/FunctionCalls.rst 
b/clang/docs/HLSL/FunctionCalls.rst
index 996ddd6944b1ce..7317de2163f897 100644
--- a/clang/docs/HLSL/FunctionCalls.rst
+++ b/clang/docs/HLSL/FunctionCalls.rst
@@ -144,7 +144,7 @@ undefined behavior in HLSL, and any use of the argument 
after the call is a use
 of an undefined value which may be illegal in the target (DXIL programs with
 used or potentially used ``undef`` or ``poison`` values fail validation).
 
-Clang Implementation 
+Clang Implementation
 
 
 .. note::



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


[clang] ff96567 - [NFC] Fix failing test introduced in #67700

2023-11-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2023-11-29T12:02:44-06:00
New Revision: ff96567bd0fb8ed7a4739afa27a3cf3908115021

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

LOG: [NFC] Fix failing test introduced in #67700

This fixes the test to handle the changes in the AST printer.
../clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl

Added: 


Modified: 
clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl

Removed: 




diff  --git a/clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl 
b/clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl
index 57d55dcc9de0b7f..4ffbcacf3f30c04 100644
--- a/clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl
+++ b/clang/test/SemaHLSL/Types/BuiltinVector/ScalarSwizzles.hlsl
@@ -2,6 +2,7 @@
 // RUN:   -finclude-default-header -ast-dump %s | FileCheck %s
 
 
+// CHECK-LABEL: ToTwoInts
 // CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' lvalue 
 // CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'V' 'int'
@@ -10,6 +11,7 @@ int2 ToTwoInts(int V){
   return V.xx;
 }
 
+// CHECK-LABEL: ToFourFloats
 // CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(4)))' 
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' lvalue 
 // CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'V' 'float'
@@ -19,6 +21,7 @@ float4 ToFourFloats(float V){
   return V.;
 }
 
+// CHECK-LABEL: FillOne
 // CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
@@ -27,7 +30,7 @@ int2 FillOne(){
   return 1.xx;
 }
 
-
+// CHECK-LABEL: FillOneUnsigned
 // CHECK: ExtVectorElementExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(3)))' xxx
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned int' 1
@@ -36,6 +39,7 @@ uint3 FillOneUnsigned(){
   return 1u.xxx;
 }
 
+// CHECK-LABEL: FillOneUnsignedLong
 // CHECK: ExtVectorElementExpr {{.*}} 'unsigned long 
__attribute__((ext_vector_type(4)))' 
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned long 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1
@@ -44,6 +48,7 @@ vector FillOneUnsignedLong(){
   return 1ul.;
 }
 
+// CHECK-LABEL: FillTwoPointFive
 // CHECK: ExtVectorElementExpr {{.*}} 'double 
__attribute__((ext_vector_type(2)))' rr
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: FloatingLiteral {{.*}} 'double' 2.50e+00
@@ -52,6 +57,7 @@ double2 FillTwoPointFive(){
   return 2.5.rr;
 }
 
+// CHECK-LABEL: FillOneHalf
 // CHECK: ExtVectorElementExpr {{.*}} 'double 
__attribute__((ext_vector_type(3)))' rrr
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'double 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: FloatingLiteral {{.*}} 'double' 5.00e-01
@@ -60,6 +66,7 @@ double3 FillOneHalf(){
   return .5.rrr;
 }
 
+// CHECK-LABEL: FillTwoPointFiveFloat
 // CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(4)))' 
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: FloatingLiteral {{.*}} 'float' 2.50e+00
@@ -72,6 +79,7 @@ float4 FillTwoPointFiveFloat(){
 // truncated vector, this AST formulation has an initialization list to
 // initialze the returned vector.
 
+// CHECK-LABEL: FillOneHalfFloat
 // CHECK: InitListExpr {{.*}} 'vector':'float 
__attribute__((ext_vector_type(1)))'
 // CHECK-NEXT: ExtVectorElementExpr {{.*}} 'float' r
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' 
@@ -81,6 +89,7 @@ vector FillOneHalfFloat(){
   return .5f.r;
 }
 
+// CHECK-LABEL: HowManyFloats
 // CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(2)))' rr
 // CHECK-NEXT: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(2)))' rr
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' lvalue 
@@ -90,6 +99,7 @@ float2 HowManyFloats(float V) {
   return V.rr.rr;
 }
 
+// CHECK-LABEL: HooBoy
 // CHECK: ExtVectorElementExpr {{.*}} 'long 
__attribute__((ext_vector_type(4)))' 
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'long 
__attribute__((ext_vector_type(1)))' 
 // CHECK-NEXT: IntegerLiteral {{.*}} 'long' 4
@@ -102,11 +112,11 @@ int64_t4 HooBoy() {
 // is a double->float conversion, which results in generating an initializtion
 // list with float truncation casts.
 
-
+// CHECK-LABEL: AllRighty

[clang] ce73177 - Fix clang Attribute doc build

2023-11-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2023-11-28T15:30:15-06:00
New Revision: ce731770f869e8e61afa2dccb772e8367105a1a6

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

LOG: Fix clang Attribute doc build

This fixes the clang attributes documentation build.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index af4a6e027502eb7..b7f366c29b77b48 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7063,6 +7063,7 @@ The full documentation is available here: 
https://learn.microsoft.com/en-us/wind
 
 def HLSLParamQualifierDocs : Documentation {
   let Category = DocCatVariable;
+  let Heading = "HLSL Parameter Modifiers";
   let Content = [{
 HLSL function parameters are passed by value. Parameter declarations support
 three qualifiers to denote parameter passing behavior. The three qualifiers are



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


[clang] 400d326 - [HLSL] Cleanup support for `this` as an l-value

2023-09-05 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2023-09-05T19:38:50-05:00
New Revision: 400d3261a0da56554aee8e5a2fbc27eade9d05db

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

LOG: [HLSL] Cleanup support for `this` as an l-value

The goal of this change is to clean up some of the code surrounding
HLSL using CXXThisExpr as a non-pointer l-value. This change cleans up
a bunch of assumptions and inconsistencies around how the type of
`this` is handled through the AST and code generation.

This change is be mostly NFC for HLSL, and completely NFC for other
language modes.

This change introduces a new member to query for the this object's type
and seeks to clarify the normal usages of the this type.

With the introudction of HLSL to clang, CXXThisExpr may now be an
l-value and behave like a reference type rather than C++'s normal
method of it being an r-value of pointer type.

With this change there are now three ways in which a caller might need
to query the type of `this`:

* The type of the `CXXThisExpr`
* The type of the object `this` referrs to
* The type of the implicit (or explicit) `this` argument

This change codifies those three ways you may need to query
respectively as:

* CXXMethodDecl::getThisType()
* CXXMethodDecl::getThisObjectType()
* CXXMethodDecl::getThisArgType()

This change then revisits all uses of `getThisType()`, and in cases
where the only use was to resolve the pointee type, it replaces the
call with `getThisObjectType()`. In other cases it evaluates whether
the desired returned type is the type of the `this` expr, or the type
of the `this` function argument. The `this` expr type is used for
creating additional expr AST nodes and for member lookup, while the
argument type is used mostly for code generation.

Additionally some cases that used `getThisType` in simple queries could
be substituted for `getThisObjectType`. Since `getThisType` is
implemented in terms of `getThisObjectType` calling the later should be
more efficient if the former isn't needed.

Reviewed By: aaron.ballman, bogner

Differential Revision: https://reviews.llvm.org/D159247

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Analysis/Consumed.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/test/CodeGenHLSL/this-reference.hlsl

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 02fa997d674c8c8..17dbb5e888ebdd3 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1146,9 +1146,8 @@ class CXXUuidofExpr : public Expr {
 /// };
 /// \endcode
 class CXXThisExpr : public Expr {
-public:
-  CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit)
-  : Expr(CXXThisExprClass, Ty, VK_PRValue, OK_Ordinary) {
+  CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit, ExprValueKind VK)
+  : Expr(CXXThisExprClass, Ty, VK, OK_Ordinary) {
 CXXThisExprBits.IsImplicit = IsImplicit;
 CXXThisExprBits.Loc = L;
 setDependence(computeDependence(this));
@@ -1156,6 +1155,12 @@ class CXXThisExpr : public Expr {
 
   CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
 
+public:
+  static CXXThisExpr *Create(const ASTContext &Ctx, SourceLocation L,
+ QualType Ty, bool IsImplicit);
+
+  static CXXThisExpr *CreateEmpty(const ASTContext &Ctx);
+
   SourceLocation getLocation() const { return CXXThisExprBits.Loc; }
   void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; }
 

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 282a83980632224..c7c2aecc8b179a4 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8173,8 +8173,8 @@ ExpectedStmt 
ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) {
   if (!ToLocationOrErr)
 return ToLocationOrErr.takeError();
 
-  return new (Importer.getToContext()) CXXThisExpr(
-  *ToLocationOrErr, *ToTypeOrErr, E->isImplicit());
+  return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
+ *ToTypeOrErr, E->isImplicit());
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {

diff  -

[clang] c380156 - [NFC] [CMake] Add misssing dependencies

2023-03-10 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2023-03-10T17:13:09-06:00
New Revision: c3801568ef2b7f923f9116f72a6b0bb382bcaa41

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

LOG: [NFC] [CMake] Add misssing dependencies

I missed adding these in my last cleanup change :(

Added: 


Modified: 
clang/test/CMakeLists.txt

Removed: 




diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 7f37bae7ed95..df73c869490c 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -72,6 +72,8 @@ list(APPEND CLANG_TEST_DEPS
   clang-
diff 
   clang-scan-deps
   clang-linker-wrapper
+  clang-offload-bundler
+  clang-offload-packager
   diagtool
   hmaptool
   )



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


[clang] 326c135 - [NFC] [CMake] Cleanup clang tool dependencies

2023-03-10 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2023-03-10T10:56:07-06:00
New Revision: 326c13531af32df8361cb4c98d2cc1355b0f8c48

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

LOG: [NFC] [CMake] Cleanup clang tool dependencies

None of these tools need to depend on clang to build, instead the test
target should depend on them.

This prevents rebuilding/linking these tools when building the `clang`
target directly.

Added: 


Modified: 
clang/test/CMakeLists.txt
clang/tools/clang-linker-wrapper/CMakeLists.txt
clang/tools/clang-offload-bundler/CMakeLists.txt
clang/tools/clang-offload-packager/CMakeLists.txt

Removed: 




diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 1d6377b5f2d80..7f37bae7ed954 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -71,6 +71,7 @@ list(APPEND CLANG_TEST_DEPS
   clang-refactor
   clang-
diff 
   clang-scan-deps
+  clang-linker-wrapper
   diagtool
   hmaptool
   )

diff  --git a/clang/tools/clang-linker-wrapper/CMakeLists.txt 
b/clang/tools/clang-linker-wrapper/CMakeLists.txt
index 8ddfcc6c59d35..b5f1c0dd0e7d3 100644
--- a/clang/tools/clang-linker-wrapper/CMakeLists.txt
+++ b/clang/tools/clang-linker-wrapper/CMakeLists.txt
@@ -39,8 +39,6 @@ set(CLANG_LINKER_WRAPPER_LIB_DEPS
   clangBasic
   )
 
-add_dependencies(clang clang-linker-wrapper)
-
 target_link_libraries(clang-linker-wrapper
   PRIVATE
   ${CLANG_LINKER_WRAPPER_LIB_DEPS}

diff  --git a/clang/tools/clang-offload-bundler/CMakeLists.txt 
b/clang/tools/clang-offload-bundler/CMakeLists.txt
index 7bc22f1479d72..dabd82382cdf0 100644
--- a/clang/tools/clang-offload-bundler/CMakeLists.txt
+++ b/clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -16,8 +16,6 @@ set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangDriver
   )
 
-add_dependencies(clang clang-offload-bundler)
-
 clang_target_link_libraries(clang-offload-bundler
   PRIVATE
   ${CLANG_OFFLOAD_BUNDLER_LIB_DEPS}

diff  --git a/clang/tools/clang-offload-packager/CMakeLists.txt 
b/clang/tools/clang-offload-packager/CMakeLists.txt
index accc9486f46ab..1c29e376452c1 100644
--- a/clang/tools/clang-offload-packager/CMakeLists.txt
+++ b/clang/tools/clang-offload-packager/CMakeLists.txt
@@ -11,8 +11,6 @@ add_clang_tool(clang-offload-packager
   ${tablegen_deps}
   )
 
-add_dependencies(clang clang-offload-packager)
-
 clang_target_link_libraries(clang-offload-packager
   PRIVATE
   clangBasic



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


[clang] 4c7218e - [HLSL] Remove unused frontend-generated ID

2022-10-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-21T12:41:09-05:00
New Revision: 4c7218e7702651bb8dd2ef7734ca05ac0ada32fd

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

LOG: [HLSL] Remove unused frontend-generated ID

As @python3kgae pointed out we're going to want to assign these IDs
after optimization so that we can remove unused resrouces. This patch
just removes the unused ID value from the frontend metadata, clang code
generation, and updates associated test cases.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D136271

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
clang/test/CodeGenHLSL/cbuf.hlsl
llvm/include/llvm/Frontend/HLSL/HLSLResource.h
llvm/lib/Frontend/HLSL/HLSLResource.cpp
llvm/test/CodeGen/DirectX/UAVMetadata.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index f64fdfade9f4f..5882f491d5972 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -197,7 +197,6 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
 BufferResBinding &Binding) {
-  uint32_t Counter = ResourceCounters[static_cast(RC)]++;
   llvm::Module &M = CGM.getModule();
 
   NamedMDNode *ResourceMD = nullptr;
@@ -220,7 +219,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, Counter, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 107b0d6d12854..976f925ed1c84 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -70,8 +70,6 @@ class CGHLSLRuntime {
 
 protected:
   CodeGenModule &CGM;
-  uint32_t ResourceCounters[static_cast(
-  llvm::hlsl::ResourceClass::NumClasses)] = {0};
 
   llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D,
  llvm::Type *Ty);

diff  --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
index f35e704e45799..77091f8390a15 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 0, i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[Array]] = !{ptr 
@"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 1, i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[SingleAllocated]] = !{ptr 
@"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 2, i32 10, i32 3, 
i32 0}
-// CHECK-DAG: ![[ArrayAllocated]] = !{ptr 
@"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 3, i32 10, i32 4, i32 0}
-// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer@M@hlsl@@A", 
!"RWBuffer", i32 4, i32 10, i32 3, i32 1}
-// CHECK-DAG: ![[ArraySpace]] = !{ptr 
@"?BufferArray3@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 5, i32 10, i32 4, i32 1}
+// 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 10, i32 4, i32 0}
+// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer@M@hlsl@@A", 
!"RWBuffer", i32 10, i32 3, i32 1}
+// CHECK-DAG: ![[ArraySpace]] = !{ptr 
@"?BufferArray3@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 10, i32 4, i32 1}

diff  --git a/clang/test/CodeGenHLSL/cbuf.hlsl 
b/clang/test/CodeGenHLSL/cbuf.hlsl
index 2a98912b7eeea..92c883943d03e 100644
--- a/clang/test/CodeGenHLSL/cb

[clang] d146a52 - Move HLSL builtins into hlsl namespace

2022-10-19 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-19T10:59:31-05:00
New Revision: d146a5241c5039fd25e8bf5a4ae1200ad201d06c

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

LOG: Move HLSL builtins into hlsl namespace

Should have done this from the start. Since all the injected AST types
are in the hlsl namespace we should also put the header-defined types
and functions in there too.

This updates the basic_types test to run once with the namespaced types
and once without, and adds using declarations or namespaces calls in
other tests.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D135973

Added: 


Modified: 
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/test/CodeGenHLSL/basic_types.hlsl
clang/test/CodeGenHLSL/builtins/abs.hlsl
clang/test/CodeGenHLSL/builtins/ceil.hlsl
clang/test/CodeGenHLSL/builtins/sqrt.hlsl
clang/test/SemaHLSL/Wave.hlsl
clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e68715f1a6a45..9ea605cfa840a 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_BASIC_TYPES_H_
 #define _HLSL_HLSL_BASIC_TYPES_H_
 
+namespace hlsl {
 // built-in scalar data types:
 
 #ifdef __HLSL_ENABLE_16_BIT
@@ -61,4 +62,6 @@ typedef vector double2;
 typedef vector double3;
 typedef vector double4;
 
+} // namespace hlsl
+
 #endif //_HLSL_HLSL_BASIC_TYPES_H_

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 43f8dfee7a5f1..e0099d435308b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,8 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+namespace hlsl {
+
 __attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
@@ -99,4 +101,6 @@ double3 ceil(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
 double4 ceil(double4);
 
+} // namespace hlsl
+
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/basic_types.hlsl 
b/clang/test/CodeGenHLSL/basic_types.hlsl
index d26d94910c2d8..15c963dfa666f 100644
--- a/clang/test/CodeGenHLSL/basic_types.hlsl
+++ b/clang/test/CodeGenHLSL/basic_types.hlsl
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
 // RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s
 
 
 // CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
@@ -36,7 +39,11 @@
 // CHECK:"?double3_Val@@3T?$__vector@N$02@__clang@@A" = global <3 x double> 
zeroinitializer, align 32
 // CHECK:"?double4_Val@@3T?$__vector@N$03@__clang@@A" = global <4 x double> 
zeroinitializer, align 32
 
+#ifdef NAMESPACED
+#define TYPE_DECL(T)  hlsl::T T##_Val
+#else
 #define TYPE_DECL(T)  T T##_Val
+#endif
 
 #ifdef __HLSL_ENABLE_16_BIT
 TYPE_DECL(uint16_t);

diff  --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl 
b/clang/test/CodeGenHLSL/builtins/abs.hlsl
index 30b0bcb8837ca..e014680ff2c1c 100644
--- a/clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -5,6 +5,7 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::abs;
 
 // CHECK: define noundef signext i16 @
 // FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.

diff  --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl 
b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index 69f2b82730673..5969028d56d1a 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -5,6 +5,8 @@
 // RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
 
+using hlsl::ceil;
+
 // CHECK: define noundef half @
 // CHECK: call half @llvm.ceil.f16(
 // NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"(

diff  --git a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl 
b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
index c083ce1175e59..776269395a662 100644
--- a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@

[clang] 911d2dc - [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-14 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-14T13:40:04-05:00
New Revision: 911d2dc23035454cb85422922c19259855e33bba

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

LOG: [NFC] [HLSL] Move common metadata to LLVMFrontend

This change pulls some code from the DirectX backend into a new
LLVMFrontendHLSL library to share utility data structures between the
HLSL code generation in Clang and the backend in LLVM.

This is a small refactoring as a first start to get code into the
right structure and get the library built and dependencies correct.

Fixes #58000 (https://github.com/llvm/llvm-project/issues/58000)

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D135110

Added: 
llvm/include/llvm/Frontend/HLSL/HLSLResource.h
llvm/lib/Frontend/HLSL/CMakeLists.txt
llvm/lib/Frontend/HLSL/HLSLResource.cpp

Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CMakeLists.txt
llvm/lib/Frontend/CMakeLists.txt
llvm/lib/Target/DirectX/CMakeLists.txt
llvm/lib/Target/DirectX/DXILResource.cpp
llvm/lib/Target/DirectX/DXILResource.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index e1011db758d62..2782ca8c9c5b1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -17,6 +17,7 @@
 #include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
@@ -227,9 +228,8 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, 
GlobalVariable *GV) {
   auto &Ctx = CGM.getModule().getContext();
   IRBuilder<> B(Ctx);
   QualType QT(Ty, 0);
-  ResourceMD->addOperand(MDNode::get(
-  Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, QT.getAsString()),
-ConstantAsMetadata::get(B.getInt32(Counter))}));
+  llvm::hlsl::FrontendResource Res(GV, QT.getAsString(), Counter);
+  ResourceMD->addOperand(Res.getMetadata());
 }
 
 void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index 0bb5abcf60455..a97042ee2008b 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
   Coverage
   Demangle
   Extensions
+  FrontendHLSL
   FrontendOpenMP
   IPO
   IRReader

diff  --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
new file mode 100644
index 0..fe98f6fc4194c
--- /dev/null
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -0,0 +1,43 @@
+//===- HLSLResource.h - HLSL Resource helper objects 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===--===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+#define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
+
+#include "llvm/IR/Metadata.h"
+
+namespace llvm {
+class Module;
+class GlobalVariable;
+
+namespace hlsl {
+
+class FrontendResource {
+  MDNode *Entry;
+
+public:
+  FrontendResource(MDNode *E) : Entry(E) {
+assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
+  }
+
+  FrontendResource(GlobalVariable *GV, StringRef TypeStr, uint32_t Counter);
+
+  GlobalVariable *getGlobalVariable();
+  StringRef getSourceType();
+  Constant *getID();
+
+  MDNode *getMetadata() { return Entry; }
+};
+} // namespace hlsl
+} // namespace llvm
+
+#endif // LLVM_FRONTEND_HLSL_HLSLRESOURCE_H

diff  --git a/llvm/lib/Frontend/CMakeLists.txt 
b/llvm/lib/Frontend/CMakeLists.txt
index ea66917b8936a..fa48c975a8b3e 100644
--- a/llvm/lib/Frontend/CMakeLists.txt
+++ b/llvm/lib/Frontend/CMakeLists.txt
@@ -1,2 +1,3 @@
+add_subdirectory(HLSL)
 add_subdirectory(OpenACC)
 add_subdirectory(OpenMP)

diff  --git a/llvm/lib/Frontend/HLSL/CMakeLists.txt 
b/llvm/lib/Frontend/HLSL/CMakeLists.txt
new file mode 100644
index 0..eda6cb8e69a49
--- /dev/null
+++ b/llvm/lib/Frontend/HLSL/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_llvm_component_library(LLVMFrontendHLSL
+  HLSLResource.cpp
+
+  ADDITIONAL_HEADER_DIRS
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
+  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/HLSL
+
+  DEPENDS
+  intrinsics_gen
+
+  LINK_COMPONENTS
+  Core
+  Support
+  )

diff  --git a/llvm/lib/Frontend/

[clang] 19a0a56 - [HLSL] Add utility to convert environment to stage

2022-10-12 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-12T16:31:30-05:00
New Revision: 19a0a56749110dc92b39f583e46779ff23aceeba

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

LOG: [HLSL] Add utility to convert environment to stage

We had a bunch of places in the code where we were translating triple
environment enum cases to shader stage enum cases. The order of these
enums needs to be kept in sync for the translation to be simple, but we
were not properly handling out-of-bounds cases.

In normal compilation out-of-bounds cases shouldn't be possible because
the driver errors if you don't have a valid shader environment set, but
in clang tooling that error doesn't get treated as fatal and parsing
continues. This can result in crashes in clang tooling for out-of-range
shader stages.

To address this, this patch adds a constexpr method to handle the
conversion which handles out-of-range values by converting them to
`Invalid`.

Since this new method is a constexpr, the tests for this are a group of
static_asserts in the implementation file that verifies the correct
conversion for each valid enum case and validates that other cases are
converted to `Invalid`.

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D135595

Added: 


Modified: 
clang/include/clang/Basic/HLSLRuntime.h
clang/include/clang/Basic/LangOptions.h
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
llvm/include/llvm/ADT/Triple.h

Removed: 




diff  --git a/clang/include/clang/Basic/HLSLRuntime.h 
b/clang/include/clang/Basic/HLSLRuntime.h
index bc3a064f9b69..d3d2306faf30 100644
--- a/clang/include/clang/Basic/HLSLRuntime.h
+++ b/clang/include/clang/Basic/HLSLRuntime.h
@@ -7,14 +7,14 @@
 
//===--===//
 //
 /// \file
-/// Defines the clang::IdentifierInfo, clang::IdentifierTable, and
-/// clang::Selector interfaces.
+/// Defines helper utilities for supporting the HLSL runtime environment.
 //
 
//===--===//
 
 #ifndef CLANG_BASIC_HLSLRUNTIME_H
 #define CLANG_BASIC_HLSLRUNTIME_H
 
+#include "clang/Basic/LangOptions.h"
 #include 
 
 namespace clang {
@@ -28,6 +28,46 @@ enum class ResourceClass : uint8_t {
   NumClasses
 };
 
+constexpr ShaderStage
+getStageFromEnvironment(const llvm::Triple::EnvironmentType &E) {
+  uint32_t Pipeline =
+  static_cast(E) - static_cast(llvm::Triple::Pixel);
+
+  if (Pipeline > (uint32_t)ShaderStage::Invalid)
+return ShaderStage::Invalid;
+  return static_cast(Pipeline);
+}
+
+#define ENUM_COMPARE_ASSERT(Value) 
\
+  static_assert(   
\
+  getStageFromEnvironment(llvm::Triple::Value) == ShaderStage::Value,  
\
+  "Mismatch between llvm::Triple and clang::ShaderStage for " #Value);
+
+ENUM_COMPARE_ASSERT(Pixel)
+ENUM_COMPARE_ASSERT(Vertex)
+ENUM_COMPARE_ASSERT(Geometry)
+ENUM_COMPARE_ASSERT(Hull)
+ENUM_COMPARE_ASSERT(Domain)
+ENUM_COMPARE_ASSERT(Compute)
+ENUM_COMPARE_ASSERT(Library)
+ENUM_COMPARE_ASSERT(RayGeneration)
+ENUM_COMPARE_ASSERT(Intersection)
+ENUM_COMPARE_ASSERT(AnyHit)
+ENUM_COMPARE_ASSERT(ClosestHit)
+ENUM_COMPARE_ASSERT(Miss)
+ENUM_COMPARE_ASSERT(Callable)
+ENUM_COMPARE_ASSERT(Mesh)
+ENUM_COMPARE_ASSERT(Amplification)
+
+static_assert(getStageFromEnvironment(llvm::Triple::UnknownEnvironment) ==
+  ShaderStage::Invalid,
+  "Mismatch between llvm::Triple and "
+  "clang::ShaderStage for Invalid");
+static_assert(getStageFromEnvironment(llvm::Triple::MSVC) ==
+  ShaderStage::Invalid,
+  "Mismatch between llvm::Triple and "
+  "clang::ShaderStage for Invalid");
+
 } // namespace hlsl
 } // namespace clang
 

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index a9ed2e2270ac..4cac4c221d8b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -54,6 +54,9 @@ class LangOptionsBase {
 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
 
 /// Shader programs run in specific pipeline stages.
+/// The order of these values matters, and must be kept in sync with the
+/// Triple Environment enum in llvm::Triple. The ordering is enforced in
+///  static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h.
 enum class ShaderStage {
   Pixel = 0,
   Vertex,

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e9bfab9e695b..2273fb113fb2 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPre

[clang] bb46022 - [CMake] Small fix to HLSL header install paths

2022-10-07 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-10-07T09:45:11-05:00
New Revision: bb46022abe78497d3d5a8c6a6cf8599f7ec0d2ec

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

LOG: [CMake] Small fix to HLSL header install paths

HLSL headers were being installed in two locations, one correct and one
incorrect, and they were always being installed (even when
CLANG_ENABLE_HLSL=Off). This corrects both issues by ensuring that the
HLSL headers aren't added to the universal header list.

Added: 


Modified: 
clang/lib/Headers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 0e78238436c94..bd2161d597a8f 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -225,7 +225,6 @@ set(files
   ${cuda_files}
   ${hexagon_files}
   ${hip_files}
-  ${hlsl_files}
   ${mips_msa_files}
   ${opencl_files}
   ${ppc_files}
@@ -302,7 +301,7 @@ endfunction(clang_generate_header)
 
 
 # Copy header files from the source directory to the build directory
-foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} 
${openmp_wrapper_files})
+foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} 
${openmp_wrapper_files} ${hlsl_files})
   copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
 endforeach( f )
 



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


[clang] e432108 - [CMake] Add `CLANG_ENABLE_HLSL` CMake option

2022-09-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-27T12:33:22-05:00
New Revision: e432108bf25456f428a3956fd79d29ea7fc196ac

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

LOG: [CMake] Add `CLANG_ENABLE_HLSL` CMake option

The HLSL support in clang is in progress and not fully functioning. As
such we don't want to install the related optional build components by
default (yet), but we do need an option to build and install them
locally for testing and for some key users.

This adds the `CLANG_ENABLE_HLSL` option which is off by default and can
be enabled to install the HLSL clang headers and the clang-dxc symlink.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D134693

Added: 


Modified: 
clang/CMakeLists.txt
clang/cmake/caches/HLSL.cmake
clang/lib/Headers/CMakeLists.txt
clang/tools/driver/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 22b5118c83eda..f43fa51a3379c 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -482,6 +482,10 @@ option(CLANG_INCLUDE_TESTS
"Generate build targets for the Clang unit tests."
${LLVM_INCLUDE_TESTS})
 
+option(CLANG_ENABLE_HLSL "Include HLSL build products" Off)
+# While HLSL support is experimental this should stay hidden.
+mark_as_advanced(CLANG_ENABLE_HLSL)
+
 add_subdirectory(utils/TableGen)
 
 # Export CLANG_TABLEGEN_EXE for use by flang docs.

diff  --git a/clang/cmake/caches/HLSL.cmake b/clang/cmake/caches/HLSL.cmake
index e2d02b6b281a3..71f81e53f6bd3 100644
--- a/clang/cmake/caches/HLSL.cmake
+++ b/clang/cmake/caches/HLSL.cmake
@@ -9,3 +9,5 @@ set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD DirectX CACHE STRING "")
 # HLSL support is currently limted to clang, eventually it will expand to
 # clang-tools-extra too.
 set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
+
+set(CLANG_ENABLE_HLSL On CACHE BOOL "")

diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index c374580ceb5c8..b8ee1fec86a2a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -62,11 +62,15 @@ set(hip_files
   __clang_hip_runtime_wrapper.h
   )
 
-set(hlsl_files
-  hlsl.h
+set(hlsl_h hlsl.h)
+set(hlsl_subdir_files
   hlsl/hlsl_basic_types.h
   hlsl/hlsl_intrinsics.h
   )
+set(hlsl_files
+  ${hlsl_h}
+  ${hlsl_subdir_files}
+  )
 
 set(mips_msa_files
   msa.h
@@ -548,10 +552,20 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+if(NOT CLANG_ENABLE_HLSL)
+  set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
+endif()
+
 install(
-  FILES ${hlsl_files}
+  FILES ${hlsl_h}
   DESTINATION ${header_install_dir}
-  EXCLUDE_FROM_ALL
+  ${EXCLUDE_HLSL}
+  COMPONENT hlsl-resource-headers)
+
+install(
+  FILES ${hlsl_subdir_files}
+  DESTINATION ${header_install_dir}/hlsl
+  ${EXCLUDE_HLSL}
   COMPONENT hlsl-resource-headers)
 
 install(

diff  --git a/clang/tools/driver/CMakeLists.txt 
b/clang/tools/driver/CMakeLists.txt
index d05b71db13f21..e233ee7168080 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -61,7 +61,11 @@ if(NOT CLANG_LINKS_TO_CREATE)
   set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
 endif()
 
-foreach(link ${CLANG_LINKS_TO_CREATE})
+if (CLANG_ENABLE_HLSL)
+  set(HLSL_LINK clang-dxc)
+endif()
+
+foreach(link ${CLANG_LINKS_TO_CREATE} ${HLSL_LINK})
   add_clang_symlink(${link} clang)
 endforeach()
 



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


[clang] d20f9f8 - [Docs] [HLSL] Add IR reference for HLSL

2022-09-23 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-23T10:29:54-05:00
New Revision: d20f9f8d2177cd02184bb2c2794af398ba355f61

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

LOG: [Docs] [HLSL] Add IR reference for HLSL

HLSL uses a variety of named IR metadata and attributes to convey
additional information from the frontend to the backend. This document
tries to capture and document the named annotations to provide a
reference for future contributors.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D134304

Added: 
clang/docs/HLSL/HLSLIRReference.rst

Modified: 
clang/docs/HLSL/HLSLDocs.rst

Removed: 




diff  --git a/clang/docs/HLSL/HLSLDocs.rst b/clang/docs/HLSL/HLSLDocs.rst
index 2cfe631da939..a02dd2e8a962 100644
--- a/clang/docs/HLSL/HLSLDocs.rst
+++ b/clang/docs/HLSL/HLSLDocs.rst
@@ -11,5 +11,6 @@ HLSL Design and Implementation
 .. toctree::
:maxdepth: 1
 
+   HLSLIRReference
ResourceTypes
EntryFunctions

diff  --git a/clang/docs/HLSL/HLSLIRReference.rst 
b/clang/docs/HLSL/HLSLIRReference.rst
new file mode 100644
index ..c0d8d33f33bf
--- /dev/null
+++ b/clang/docs/HLSL/HLSLIRReference.rst
@@ -0,0 +1,31 @@
+=
+HLSL IR Reference
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+The goal of this document is to provide a reference for all the special purpose
+IR metadata and attributes used by the HLSL code generation path.
+
+IR Metadata
+===
+
+``hlsl.uavs``
+-
+
+The ``hlsl.uavs`` metadata is a list of all the external global variables that
+represent UAV resources.
+
+Function Attributes
+===
+
+``hlsl.shader``
+---
+
+The ``hlsl.shader`` function attribute is a string attribute applied to entry
+functions. The value is the string representation of the shader stage (i.e.
+``compute``, ``pixel``, etc).



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


[clang] bc97751 - [NFC] Add GitHub issues to HLSL FIXME comments

2022-09-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-21T10:31:25-05:00
New Revision: bc97751a236e619dc33f81e9fc9b3fe6bd0ba7b6

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

LOG: [NFC] Add GitHub issues to HLSL FIXME comments

In order to make this easier to track I've filed issues for each of the
HLSL FIXME comments that I can find. I may have missed some, but I want
this to be the new default mode.

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenHLSL/validator_version.hlsl

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 8e0088784e548..c61a65813aea5 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -143,6 +143,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   IRBuilder<> B(BB);
   llvm::SmallVector Args;
   // FIXME: support struct parameters where semantics are on members.
+  // See: https://github.com/llvm/llvm-project/issues/57874
   for (const auto *Param : FD->parameters()) {
 Args.push_back(emitInputSemantic(B, *Param));
   }
@@ -150,6 +151,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   CallInst *CI = B.CreateCall(FunctionCallee(Fn), Args);
   (void)CI;
   // FIXME: Handle codegen for return type semantics.
+  // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
 }
 

diff  --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index a80fea2e3efe2..69a7820946246 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -209,5 +209,6 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, 
StringRef BoundArch,
   }
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
+  // See: https://github.com/llvm/llvm-project/issues/57876
   return DAL;
 }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0f567d91dc81e..865388ccd5fa8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11896,6 +11896,7 @@ void Sema::CheckHLSLEntryPoint(FunctionDecl *FD) {
   for (const auto *Param : FD->parameters()) {
 if (!Param->hasAttr()) {
   // FIXME: Handle struct parameters where annotations are on struct 
fields.
+  // See: https://github.com/llvm/llvm-project/issues/57875
   Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation);
   Diag(Param->getLocation(), diag::note_previous_decl) << Param;
   FD->setInvalidDecl();

diff  --git a/clang/test/CodeGenHLSL/validator_version.hlsl 
b/clang/test/CodeGenHLSL/validator_version.hlsl
index 0d2cbb96dbe48..a3fc4fa1b63c4 100644
--- a/clang/test/CodeGenHLSL/validator_version.hlsl
+++ b/clang/test/CodeGenHLSL/validator_version.hlsl
@@ -1,6 +1,7 @@
 // RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm 
-xhlsl -validator-version 1.1 -o - %s | FileCheck %s
 
 // FIXME:The following line should work once SPIR-V support for HLSL is added.
+// See: https://github.com/llvm/llvm-project/issues/57877
 // DISABLED: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl 
-validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL
 
 // CHECK:!dx.valver = !{![[valver:[0-9]+]]}



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


[clang] d76c654 - [HLSL] remove unnecessary abs attributes

2022-09-20 Thread Chris Bieneman via cfe-commits

Author: Joshua Batista
Date: 2022-09-20T16:04:21-05:00
New Revision: d76c654d02b66d8ec695d531d82a482224f21c79

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

LOG: [HLSL] remove unnecessary abs attributes

remove abs non-elementwise attribute statements, stick to elementwise.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D134312

Added: 


Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 3eb16b22d5ab..172e78d0357a 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -15,11 +15,6 @@ WaveActiveCountBits(bool bBit);
 
 
 // abs builtins
-__attribute__((clang_builtin_alias(__builtin_abs))) int abs(int In);
-__attribute__((clang_builtin_alias(__builtin_labs))) int64_t abs(int64_t In);
-__attribute__((clang_builtin_alias(__builtin_fabsf))) float abs(float In);
-__attribute__((clang_builtin_alias(__builtin_fabs))) double abs(double In);
-
 #ifdef __HLSL_ENABLE_16_BIT
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
 int16_t abs(int16_t);



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


[clang] b95c574 - [HLSL] add sqrt library function

2022-09-20 Thread Chris Bieneman via cfe-commits

Author: Joshua Batista
Date: 2022-09-20T15:42:08-05:00
New Revision: b95c57444a8ac3f81bc33a3d52d0f88b7a592a2f

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

LOG: [HLSL] add sqrt library function

This change exposes the sqrt library function for HLSL scalar types,
excluding long and long long doubles. Sqrt is supported for all scalar, vector,
and matrix types. This patch only adds a subset of scalar type support.

Long and long long double support is missing in this patch because that type
doesn't exist in HLSL.

The full documentation of the HLSL asin function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-sqrt

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132711

Added: 
clang/test/CodeGenHLSL/builtins/sqrt.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 02db79a2bc37d..3eb16b22d5ab9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -13,6 +13,13 @@ __attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 
+
+// abs builtins
+__attribute__((clang_builtin_alias(__builtin_abs))) int abs(int In);
+__attribute__((clang_builtin_alias(__builtin_labs))) int64_t abs(int64_t In);
+__attribute__((clang_builtin_alias(__builtin_fabsf))) float abs(float In);
+__attribute__((clang_builtin_alias(__builtin_fabs))) double abs(double In);
+
 #ifdef __HLSL_ENABLE_16_BIT
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
 int16_t abs(int16_t);
@@ -31,6 +38,7 @@ 
__attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
 half4 abs(half4);
 #endif
 
+
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs))) int abs(int);
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs))) int2 abs(int2);
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs))) int3 abs(int3);
@@ -60,4 +68,13 @@ double3 abs(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
 double4 abs(double4);
 
+// sqrt builtins
+__attribute__((clang_builtin_alias(__builtin_sqrt))) double sqrt(double In);
+__attribute__((clang_builtin_alias(__builtin_sqrtf))) float sqrt(float In);
+
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_sqrtf16))) half sqrt(half In);
+#endif
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl 
b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
new file mode 100644
index 0..c083ce1175e59
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
+
+double sqrt_d(double x)
+{
+  return sqrt(x);
+}
+
+// CHECK: define noundef double @"?sqrt_d@@YANN@Z"(
+// CHECK: call double @llvm.sqrt.f64(double %0)
+
+float sqrt_f(float x)
+{
+  return sqrt(x);
+}
+
+// CHECK: define noundef float @"?sqrt_f@@YAMM@Z"(
+// CHECK: call float @llvm.sqrt.f32(float %0)
+
+half sqrt_h(half x)
+{
+  return sqrt(x);
+}
+
+// CHECK: define noundef half @"?sqrt_h@@YA$f16@$f16@@Z"(
+// CHECK: call half @llvm.sqrt.f16(half %0)
+// NO_HALF: define noundef float @"?sqrt_h@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.sqrt.f32(float %0)



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


[clang] 0c89b34 - [HLSL] Pass flags to cc1 based on language

2022-09-20 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-20T10:56:17-05:00
New Revision: 0c89b343371fca437a86093a01dc5eb6ed1a4a9b

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

LOG: [HLSL] Pass flags to cc1 based on language

Having the flags only pass through if you're using the dxc-driver means
that the clang driver doesn't work for HLSL, which is undesirable. This
change switches to instead passing flags based on the language mode
similar to how OpenCL does it. This allows the clang driver to be used
for HLSL source files as well.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D133958

Added: 


Modified: 
clang/include/clang/Driver/Types.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/Types.cpp
clang/test/Driver/hlsl_no_stdinc.hlsl

Removed: 




diff  --git a/clang/include/clang/Driver/Types.h 
b/clang/include/clang/Driver/Types.h
index fc5dd7bbfd6f..4a21af3534de 100644
--- a/clang/include/clang/Driver/Types.h
+++ b/clang/include/clang/Driver/Types.h
@@ -95,6 +95,9 @@ namespace types {
   /// isOpenCL - Is this an "OpenCL" input.
   bool isOpenCL(ID Id);
 
+  /// isHLSL - Is this an HLSL input.
+  bool isHLSL(ID Id);
+
   /// isSrcFile - Is this a source file, i.e. something that still has to be
   /// preprocessed. The logic behind this is the same that decides if the first
   /// compilation phase is a preprocessing one.

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 34caeaf0f6af..7af0f9998455 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3529,12 +3529,14 @@ static void RenderHLSLOptions(const ArgList &Args, 
ArgStringList &CmdArgs,
  options::OPT_disable_llvm_passes,
  options::OPT_fnative_half_type,
  options::OPT_hlsl_entrypoint};
-
+  if (!types::isHLSL(InputType))
+return;
   for (const auto &Arg : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   A->renderAsInput(Args, CmdArgs);
   // Add the default headers if dxc_no_stdinc is not set.
-  if (!Args.hasArg(options::OPT_dxc_no_stdinc))
+  if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
+  !Args.hasArg(options::OPT_nostdinc))
 CmdArgs.push_back("-finclude-default-header");
 }
 
@@ -6389,8 +6391,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   RenderOpenCLOptions(Args, CmdArgs, InputType);
 
   // Forward hlsl options to -cc1
-  if (C.getDriver().IsDXCMode())
-RenderHLSLOptions(Args, CmdArgs, InputType);
+  RenderHLSLOptions(Args, CmdArgs, InputType);
 
   if (IsHIP) {
 if (Args.hasFlag(options::OPT_fhip_new_launch_api,

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 6e30bb744b4f..ffbca82c98c3 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -286,6 +286,8 @@ bool types::isHIP(ID Id) {
   }
 }
 
+bool types::isHLSL(ID Id) { return Id == TY_HLSL; }
+
 bool types::isSrcFile(ID Id) {
   return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID;
 }

diff  --git a/clang/test/Driver/hlsl_no_stdinc.hlsl 
b/clang/test/Driver/hlsl_no_stdinc.hlsl
index ec6d0612a9ed..b5567aae5236 100644
--- a/clang/test/Driver/hlsl_no_stdinc.hlsl
+++ b/clang/test/Driver/hlsl_no_stdinc.hlsl
@@ -1,5 +1,7 @@
 // RUN: %clang_dxc  -Tlib_6_7 -fcgl -Fo - %s -### 2>&1 | FileCheck %s 
--check-prefix=STDINC
+// RUN: %clang -target dxil-pc-shadermodel6.3-library -o - %s -### 2>&1 | 
FileCheck %s --check-prefix=STDINC
 // RUN: %clang_dxc  -Tlib_6_7 -hlsl-no-stdinc -fcgl -Fo - %s -### 2>&1 | 
FileCheck %s --check-prefix=NOSTDINC
+// RUN: %clang -target dxil-pc-shadermodel6.3-library -nostdinc -o - %s -### 
2>&1 | FileCheck %s --check-prefix=NOSTDINC
 
 // RUN: %clang -cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump 
-o - %s -verify
 



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


[clang] 8aed4bb - [CMake] [NFC] Add clang headers to IDE projects

2022-09-20 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-20T10:41:27-05:00
New Revision: 8aed4bb2783d32c40fae998b6518cd40a16b6ec5

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

LOG: [CMake] [NFC] Add clang headers to IDE projects

This just adds the clang headers into a source group so that they get
collected and added into generated IDE projects.

Added: 


Modified: 
clang/lib/Headers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 6e2060991b921..c374580ceb5c8 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -646,3 +646,5 @@ if (NOT LLVM_ENABLE_IDE)
DEPENDS utility-resource-headers
COMPONENT utility-resource-headers)
 endif()
+
+source_group("Clang Runtime Headers" FILES ${files})



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


[clang] 10378c4 - [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-16T16:04:27-05:00
New Revision: 10378c45055fabe291138a93d79f287586948e91

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

LOG: [HLSL] Enable availability attribute

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

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D134067

Added: 
clang/test/SemaHLSL/AvailabilityMarkup.hlsl
clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Basic/Targets/DirectX.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaAvailability.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b68f3e6217694..155b87f47194c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@ def Availability : InheritableAttr {
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) 
{
@@ -923,6 +924,7 @@ static llvm::StringRef 
getPlatformNameSourceSpelling(llvm::StringRef Platform) {
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", 
"macCatalystApplicationExtension")
  .Case("zos", "z/OS")
+ .Case("shadermodel", "ShaderModel")
  .Default(Platform);
 }
 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
@@ -937,6 +939,7 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("watchOSApplicationExtension", "watchos_app_extension")
  .Case("macCatalyst", "maccatalyst")
  .Case("macCatalystApplicationExtension", 
"maccatalyst_app_extension")
+ .Case("ShaderModel", "shadermodel")
  .Default(Platform);
 } }];
   let HasCustomParsing = 1;

diff  --git a/clang/lib/Basic/Targets/DirectX.h 
b/clang/lib/Basic/Targets/DirectX.h
index a773090b413f7..785104373e0ad 100644
--- a/clang/lib/Basic/Targets/DirectX.h
+++ b/clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public 
TargetInfo {
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index f43a6ad4779a9..ab1aa74a4c5de 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 

diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index bf4a226668f73..9ba434945e96f 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -192,6 +192,9 @@ shouldDiagnoseAvailabilityByDefault(const ASTContext 
&Context,
   case llvm::Triple::MacOSX:
 ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
 break;
+  case llvm::Triple::ShaderModel:
+// Always enable availability diagnostics for shader models.
+return true;
   default:
 // New targets should always warn about availability.
 return Triple.getVendor() == llvm::Triple::Apple;

diff  --git a/clang/test/SemaHLSL/AvailabilityMarkup.hlsl 
b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl
new file mode 100644
index 0..b883957af0871
--- /dev/null
+++ b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0(); // #fn6_0
+
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1(); // #fn5_1
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+// expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL 
ShaderModel 6.0 or newer}}
+/

[clang] 0c9b242 - [HLSL] Adding a test change I forgot to add

2022-09-13 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-13T20:53:39-05:00
New Revision: 0c9b242cf0af15fa154d006cb25f20c7bf05d60a

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

LOG: [HLSL] Adding a test change I forgot to add

This test just verifies that even at -O0 the buffer subscript operators
are inlined. The original change was
fb5baffc28c8beaf790a2fb1c8a863d29020bfbe.

Added: 
clang/test/CodeGenHLSL/builtins/RWBuffer-subscript.hlsl

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-subscript.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-subscript.hlsl
new file mode 100644
index 0..da8a1e538ec5e
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-subscript.hlsl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -o - -O0 
%s | FileCheck %s
+
+RWBuffer In;
+RWBuffer Out;
+
+[numthreads(1,1,1)]
+void main(unsigned GI : SV_GroupIndex) {
+  Out[GI] = In[GI];
+}
+
+// Even at -O0 the subscript operators get inlined. The -O0 IR is a bit messy
+// and confusing to follow so the match here is pretty weak.
+
+// CHECK: define internal void @"?main@@YAXI@Z"
+// CHECK-NOT: call
+// CHECK: ret void



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


[clang] fb5baff - [HLSL] Mark buffer subscript operators as AlwaysInline

2022-09-13 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-13T20:31:29-05:00
New Revision: fb5baffc28c8beaf790a2fb1c8a863d29020bfbe

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

LOG: [HLSL] Mark buffer subscript operators as AlwaysInline

HLSL requires aggressive inlineing for resource accesses. This just
enforces that we get resource handle accesses inlined early.

Added: 


Modified: 
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl

Removed: 




diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ee3aa4d42a049..969d65997cdcb 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -270,6 +270,9 @@ struct BuiltinTypeDeclBuilder {
  SourceLocation()));
 MethodDecl->setLexicalDeclContext(Record);
 MethodDecl->setAccess(AccessSpecifier::AS_public);
+MethodDecl->addAttr(AlwaysInlineAttr::CreateImplicit(
+AST, SourceRange(), AttributeCommonInfo::AS_Keyword,
+AlwaysInlineAttr::CXX11_clang_always_inline));
 Record->addDecl(MethodDecl);
 
 return *this;

diff  --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index 193ef67e152b7..80f77f97d2ef0 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -49,6 +49,7 @@ RWBuffer Buffer;
 // CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'element_type *' 
lvalue ->h 0x{{[0-9A-Fa-f]+}}
 // CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const 
RWBuffer *' implicit this
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9A-Fa-f]+}} <> 'unsigned int' 
ParmVar 0x{{[0-9A-Fa-f]+}} 'Idx' 'unsigned int'
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
 
 // CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  operator[] 'element_type &(unsigned int)'
 // CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
@@ -58,6 +59,7 @@ RWBuffer Buffer;
 // CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'element_type *' 
lvalue ->h 0x{{[0-9A-Fa-f]+}}
 // CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 
'RWBuffer *' implicit this
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9A-Fa-f]+}} <> 'unsigned int' 
ParmVar 0x{{[0-9A-Fa-f]+}} 'Idx' 'unsigned int'
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
 
 // CHECK: ClassTemplateSpecializationDecl 0x{{[0-9A-Fa-f]+}} <> 
 class RWBuffer definition
 



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


[clang] a8a4992 - [HLSL] Call global destructors from entries

2022-09-13 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-13T15:05:47-05:00
New Revision: a8a49923ddf75be9b6166be2f6a1f50a99817841

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

LOG: [HLSL] Call global destructors from entries

HLSL doesn't have a C++ runtime that supports `atexit` registration. To
enable global destructors we instead rely on the `llvm.global_dtor`
mechanism.

This change disables `atexit` generation for HLSL and updates the HLSL
code generation to call global destructors on the exit from entry
functions.

Depends on D132977.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D133518

Added: 
clang/test/CodeGenHLSL/GlobalDestructors.hlsl

Modified: 
clang/docs/HLSL/EntryFunctions.rst
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl

Removed: 




diff  --git a/clang/docs/HLSL/EntryFunctions.rst 
b/clang/docs/HLSL/EntryFunctions.rst
index 8591814777388..518698b9b1f7a 100644
--- a/clang/docs/HLSL/EntryFunctions.rst
+++ b/clang/docs/HLSL/EntryFunctions.rst
@@ -46,7 +46,9 @@ constructors, then instantiations of the user-defined entry 
parameters with
 their semantic values populated, and a call to the user-defined function.
 After the call instruction the return value (if any) is saved using a
 target-appropriate intrinsic for storing outputs (for DirectX, the
-``llvm.dx.store.output``). Global destructors are not supported in HLSL.
+``llvm.dx.store.output``). Lastly, any present global destructors will be 
called
+immediately before the return. HLSL does not support C++ ``atexit``
+registrations, instead calls to global destructors are compile-time generated.
 
 .. note::
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 2f0c00169af69..591d0c43f1825 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -55,7 +55,7 @@ void CGHLSLRuntime::finishCodeGen() {
   if (T.getArch() == Triple::ArchType::dxil)
 addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
 
-  generateGlobalCtorCalls();
+  generateGlobalCtorDtorCalls();
 }
 
 void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) 
{
@@ -146,12 +146,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   B.CreateRetVoid();
 }
 
-void CGHLSLRuntime::generateGlobalCtorCalls() {
-  llvm::Module &M = CGM.getModule();
-  const auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
-  if (!GlobalCtors)
+static void gatherFunctions(SmallVectorImpl &Fns, llvm::Module &M,
+bool CtorOrDtor) {
+  const auto *GV =
+  M.getNamedGlobal(CtorOrDtor ? "llvm.global_ctors" : "llvm.global_dtors");
+  if (!GV)
 return;
-  const auto *CA = dyn_cast(GlobalCtors->getInitializer());
+  const auto *CA = dyn_cast(GV->getInitializer());
   if (!CA)
 return;
   // The global_ctor array elements are a struct [Priority, Fn *, COMDat].
@@ -168,8 +169,16 @@ void CGHLSLRuntime::generateGlobalCtorCalls() {
"HLSL doesn't support setting priority for global ctors.");
 assert(isa(CS->getOperand(2)) &&
"HLSL doesn't support COMDat for global ctors.");
-CtorFns.push_back(cast(CS->getOperand(1)));
+Fns.push_back(cast(CS->getOperand(1)));
   }
+}
+
+void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
+  llvm::Module &M = CGM.getModule();
+  SmallVector CtorFns;
+  SmallVector DtorFns;
+  gatherFunctions(CtorFns, M, true);
+  gatherFunctions(DtorFns, M, false);
 
   // Insert a call to the global constructor at the beginning of the entry 
block
   // to externally exported functions. This is a bit of a hack, but HLSL allows
@@ -180,5 +189,10 @@ void CGHLSLRuntime::generateGlobalCtorCalls() {
 IRBuilder<> B(&F.getEntryBlock(), F.getEntryBlock().begin());
 for (auto *Fn : CtorFns)
   B.CreateCall(FunctionCallee(Fn));
+
+// Insert global dtors before the terminator of the last instruction
+B.SetInsertPoint(F.back().getTerminator());
+for (auto *Fn : DtorFns)
+  B.CreateCall(FunctionCallee(Fn));
   }
 }

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index ee265922c0f51..120f53ffec14e 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -46,7 +46,7 @@ class CGHLSLRuntime {
   virtual ~CGHLSLRuntime() {}
 
   void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
-  void generateGlobalCtorCalls();
+  void generateGlobalCtorDtorCalls();
 
   void finishCodeGen();
 

diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index f0c45654f8d9b..cc6ba4eba6d77 100644
--- a/

[clang] d3c54a1 - [HLSL] Call global constructors inside entry

2022-09-09 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-09T09:01:28-05:00
New Revision: d3c54a172d48a2e3a0c2740c300a1d7dbdf4e292

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

LOG: [HLSL] Call global constructors inside entry

HLSL doesn't have a runtime loader model that supports global
construction by a loader or runtime initializer. To allow us to leverage
global constructors with minimal code generation impact we put calls to
the global constructors inside the generated entry function.

Differential Revision: https://reviews.llvm.org/D132977

Added: 
clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
clang/test/CodeGenHLSL/GlobalConstructors.hlsl
clang/test/SemaHLSL/GlobalConstructors.hlsl

Modified: 
clang/docs/HLSL/EntryFunctions.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/docs/HLSL/EntryFunctions.rst 
b/clang/docs/HLSL/EntryFunctions.rst
index 0e547aab420c8..8591814777388 100644
--- a/clang/docs/HLSL/EntryFunctions.rst
+++ b/clang/docs/HLSL/EntryFunctions.rst
@@ -37,10 +37,16 @@ linkage following normal function code generation.
 
 The actual exported entry function which can be called by the GPU driver is a
 ``void(void)`` function that isn't name mangled. In code generation we generate
-the unmangled entry function, instantiations of the parameters with their
-semantic values populated, and a call to the user-defined function. After the
-call instruction the return value (if any) is saved using a target-appropriate
-intrinsic for storing outputs (for DirectX, the ``llvm.dx.store.output``).
+the unmangled entry function to serve as the actual shader entry. The shader
+entry function is annotated with the ``hlsl.shader`` function attribute
+identifying the entry's pipeline stage.
+
+The body of the unmangled entry function contains first a call to execute 
global
+constructors, then instantiations of the user-defined entry parameters with
+their semantic values populated, and a call to the user-defined function.
+After the call instruction the return value (if any) is saved using a
+target-appropriate intrinsic for storing outputs (for DirectX, the
+``llvm.dx.store.output``). Global destructors are not supported in HLSL.
 
 .. note::
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a59eeda85bc03..76e18c9deff46 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11655,6 +11655,8 @@ def err_hlsl_attribute_param_mismatch : Error<"%0 
attribute parameters do not ma
 def err_hlsl_missing_semantic_annotation : Error<
   "semantic annotations must be present for all parameters of an entry "
   "function or patch constant function">;
+def err_hlsl_init_priority_unsupported : Error<
+  "initializer priorities are not supported in HLSL">;
 
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 9ca3b64996edd..2f0c00169af69 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -54,6 +54,8 @@ void CGHLSLRuntime::finishCodeGen() {
   Triple T(M.getTargetTriple());
   if (T.getArch() == Triple::ArchType::dxil)
 addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
+
+  generateGlobalCtorCalls();
 }
 
 void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) 
{
@@ -143,3 +145,40 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   B.CreateRetVoid();
 }
+
+void CGHLSLRuntime::generateGlobalCtorCalls() {
+  llvm::Module &M = CGM.getModule();
+  const auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
+  if (!GlobalCtors)
+return;
+  const auto *CA = dyn_cast(GlobalCtors->getInitializer());
+  if (!CA)
+return;
+  // The global_ctor array elements are a struct [Priority, Fn *, COMDat].
+  // HLSL neither supports priorities or COMDat values, so we will check those
+  // in an assert but not handle them.
+
+  llvm::SmallVector CtorFns;
+  for (const auto &Ctor : CA->operands()) {
+if (isa(Ctor))
+  continue;
+ConstantStruct *CS = cast(Ctor);
+
+assert(cast(CS->getOperand(0))->getValue() == 65535 &&
+   "HLSL doesn't support setting priority for global ctors.");
+assert(isa(CS->getOperand(2)) &&
+   "HLSL doesn't support COMDat for global ctors.");
+CtorFns.push_back(cast(CS->getOperand(1)));
+  }
+
+  // Inse

[clang] 00ecacc - [HLSL] Generate buffer subscript operators

2022-09-02 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-02T14:55:43-05:00
New Revision: 00ecacca7d90f96a1d54bc3fa38986fdd64e4c72

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

LOG: [HLSL] Generate buffer subscript operators

In HLSL buffer types support array subscripting syntax for loads and
stores. This change fleshes out the subscript operators to become array
accesses on the underlying handle pointer. This will allow LLVM
optimization passes to optimize resource accesses the same way any other
memory access would be optimized.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131268

Added: 
clang/test/CodeGenHLSL/buffer-array-operator.hlsl

Modified: 
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl

Removed: 




diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index fe963fdbf2781..ee3aa4d42a049 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -104,7 +104,14 @@ struct BuiltinTypeDeclBuilder {
 
   BuiltinTypeDeclBuilder &
   addHandleMember(AccessSpecifier Access = AccessSpecifier::AS_private) {
-return addMemberVariable("h", Record->getASTContext().VoidPtrTy, Access);
+QualType Ty = Record->getASTContext().VoidPtrTy;
+if (Template) {
+  if (const auto *TTD = dyn_cast(
+  Template->getTemplateParameters()->getParam(0)))
+Ty = Record->getASTContext().getPointerType(
+QualType(TTD->getTypeForDecl(), 0));
+}
+return addMemberVariable("h", Ty, Access);
   }
 
   BuiltinTypeDeclBuilder &
@@ -158,15 +165,25 @@ struct BuiltinTypeDeclBuilder {
 lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle");
 
 Expr *RCExpr = emitResourceClassExpr(AST, RC);
-CallExpr *Call =
-CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue,
- SourceLocation(), FPOptionsOverride());
+Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue,
+  SourceLocation(), FPOptionsOverride());
 
 CXXThisExpr *This = new (AST)
 CXXThisExpr(SourceLocation(), Constructor->getThisType(), true);
-MemberExpr *Handle = MemberExpr::CreateImplicit(
-AST, This, true, Fields["h"], Fields["h"]->getType(), VK_LValue,
-OK_Ordinary);
+Expr *Handle = MemberExpr::CreateImplicit(AST, This, true, Fields["h"],
+  Fields["h"]->getType(), 
VK_LValue,
+  OK_Ordinary);
+
+// If the handle isn't a void pointer, cast the builtin result to the
+// correct type.
+if (Handle->getType().getCanonicalType() != AST.VoidPtrTy) {
+  Call = CXXStaticCastExpr::Create(
+  AST, Handle->getType(), VK_PRValue, CK_Dependent, Call, nullptr,
+  AST.getTrivialTypeSourceInfo(Handle->getType(), SourceLocation()),
+  FPOptionsOverride(), SourceLocation(), SourceLocation(),
+  SourceRange());
+}
+
 BinaryOperator *Assign = BinaryOperator::Create(
 AST, Handle, Call, BO_Assign, Handle->getType(), VK_LValue, 
OK_Ordinary,
 SourceLocation(), FPOptionsOverride());
@@ -179,6 +196,85 @@ struct BuiltinTypeDeclBuilder {
 return *this;
   }
 
+  BuiltinTypeDeclBuilder &addArraySubscriptOperators() {
+addArraySubscriptOperator(true);
+addArraySubscriptOperator(false);
+return *this;
+  }
+
+  BuiltinTypeDeclBuilder &addArraySubscriptOperator(bool IsConst) {
+assert(Fields.count("h") > 0 &&
+   "Subscript operator must be added after the handle.");
+
+FieldDecl *Handle = Fields["h"];
+ASTContext &AST = Record->getASTContext();
+
+assert(Handle->getType().getCanonicalType() != AST.VoidPtrTy &&
+   "Not yet supported for void pointer handles.");
+
+QualType ElemTy =
+QualType(Handle->getType()->getPointeeOrArrayElementType(), 0);
+QualType ReturnTy = ElemTy;
+
+FunctionProtoType::ExtProtoInfo ExtInfo;
+
+// Subscript operators return references to elements, const makes the
+// reference and method const so that the underlying data is not mutable.
+ReturnTy = AST.getLValueReferenceType(ReturnTy);
+if (IsConst) {
+  ExtInfo.TypeQuals.addConst();
+  ReturnTy.addConst();
+}
+
+QualType MethodTy =
+AST.getFunctionType(ReturnTy, {AST.UnsignedIntTy}, ExtInfo);
+auto *TSInfo = AST.getTrivialTypeSourceInfo(MethodTy, SourceLocation());
+auto *MethodDecl = CXXMethodDecl::Create(
+AST, Record, SourceLocation(),
+DeclarationNameInfo(
+AST.DeclarationNames.getCXXOperatorName(OO_Subscript),
+   

[clang] 5b5329b - [NFC] Make MultiplexExternalSemaSource own sources

2022-09-02 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-02T13:57:39-05:00
New Revision: 5b5329bd41ba977459fcd7abb7cf438fd98c98e0

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

LOG: [NFC] Make MultiplexExternalSemaSource own sources

This change refactors the MuiltiplexExternalSemaSource to take ownership
of the underlying sources. As a result it makes a larger cleanup of
external source ownership in Sema and the ChainedIncludesSource.

Reviewed By: aaron.ballman, aprantl

Differential Revision: https://reviews.llvm.org/D133158

Added: 


Modified: 
clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
clang/include/clang/Sema/MultiplexExternalSemaSource.h
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/ChainedIncludesSource.cpp
clang/lib/Sema/MultiplexExternalSemaSource.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/unittests/Sema/ExternalSemaSourceTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp 
b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
index 2af1f622aa92f..45fc15619ecab 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
@@ -27,13 +27,14 @@ namespace {
 class Action : public clang::ASTFrontendAction {
 public:
   explicit Action(SymbolIndexManager &SymbolIndexMgr, bool 
MinimizeIncludePaths)
-  : SemaSource(SymbolIndexMgr, MinimizeIncludePaths,
-   /*GenerateDiagnostics=*/false) {}
+  : SemaSource(new IncludeFixerSemaSource(SymbolIndexMgr,
+  MinimizeIncludePaths,
+  /*GenerateDiagnostics=*/false)) 
{}
 
   std::unique_ptr
   CreateASTConsumer(clang::CompilerInstance &Compiler,
 StringRef InFile) override {
-SemaSource.setFilePath(InFile);
+SemaSource->setFilePath(InFile);
 return std::make_unique();
   }
 
@@ -51,8 +52,8 @@ class Action : public clang::ASTFrontendAction {
   CompletionConsumer = &Compiler->getCodeCompletionConsumer();
 
 Compiler->createSema(getTranslationUnitKind(), CompletionConsumer);
-SemaSource.setCompilerInstance(Compiler);
-Compiler->getSema().addExternalSource(&SemaSource);
+SemaSource->setCompilerInstance(Compiler);
+Compiler->getSema().addExternalSource(SemaSource.get());
 
 clang::ParseAST(Compiler->getSema(), Compiler->getFrontendOpts().ShowStats,
 Compiler->getFrontendOpts().SkipFunctionBodies);
@@ -61,12 +62,12 @@ class Action : public clang::ASTFrontendAction {
   IncludeFixerContext
   getIncludeFixerContext(const clang::SourceManager &SourceManager,
  clang::HeaderSearch &HeaderSearch) const {
-return SemaSource.getIncludeFixerContext(SourceManager, HeaderSearch,
- SemaSource.getMatchedSymbols());
+return SemaSource->getIncludeFixerContext(SourceManager, HeaderSearch,
+  SemaSource->getMatchedSymbols());
   }
 
 private:
-  IncludeFixerSemaSource SemaSource;
+  IntrusiveRefCntPtr SemaSource;
 };
 
 } // namespace

diff  --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index 78658dcf990c4..704925577d269 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -40,25 +40,24 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   static char ID;
 
 private:
-  SmallVector Sources; // doesn't own them.
+  SmallVector Sources;
 
 public:
-
-  ///Constructs a new multiplexing external sema source and appends the
+  /// Constructs a new multiplexing external sema source and appends the
   /// given element to it.
   ///
-  ///\param[in] s1 - A non-null (old) ExternalSemaSource.
-  ///\param[in] s2 - A non-null (new) ExternalSemaSource.
+  ///\param[in] S1 - A non-null (old) ExternalSemaSource.
+  ///\param[in] S2 - A non-null (new) ExternalSemaSource.
   ///
-  MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
+  MultiplexExternalSemaSource(ExternalSemaSource *S1, ExternalSemaSource *S2);
 
   ~MultiplexExternalSemaSource() override;
 
-  ///Appends new source to the source list.
+  /// Appends new source to the source list.
   ///
   ///\param[in] source - An ExternalSemaSource.
   ///
-  void addSource(ExternalSemaSource &source);
+  void AddSource(ExternalSemaSource *Source);
 
   
//======//
   // ExternalASTSource.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bd81d3a7e5ee5..45

[clang] 10194a5 - [HLSL] Restrict to supported targets

2022-09-02 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-02T13:36:23-05:00
New Revision: 10194a51a9d304ab9f68432f244749c672f9012a

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

LOG: [HLSL] Restrict to supported targets

Someday we would like to support HLSL on a wider range of targets, but
today targeting anything other than `dxil` is likly to cause lots of
headaches. This adds an error and tests to validate that the expected
target is `dxil-?-shadermodel`.

We will continue to do a best effort to ensure the code we write makes
it easy to support other targets (like SPIR-V), but this error will
prevent users from hitting frustrating errors for unsupported cases.

Reviewed By: jcranmer-intel, Anastasia

Differential Revision: https://reviews.llvm.org/D132056

Added: 
clang/test/Driver/hlsl-lang-targets.hlsl

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGenHLSL/validator_version.hlsl
clang/test/Preprocessor/predefined-macros-hlsl.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 63be59082e7e0..df85139c3ca22 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -666,6 +666,8 @@ def err_drv_invalid_directx_shader_module : Error<
   "invalid profile : %0">;
 def err_drv_dxc_missing_target_profile : Error<
   "target profile option (-T) is missing">;
+def err_drv_hlsl_unsupported_target : Error<
+  "HLSL code generation is unsupported for target '%0'">;
 
 def err_drv_invalid_range_dxil_validator_version : Error<
   "invalid validator version : %0\n"

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 574514bdd0b0a..9ac522adfd9a9 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4107,6 +4107,14 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_EQ))
 Opts.RandstructSeed = A->getValue(0);
 
+  // Validate options for HLSL
+  if (Opts.HLSL) {
+bool SupportedTarget = T.getArch() == llvm::Triple::dxil &&
+   T.getOS() == llvm::Triple::ShaderModel;
+if (!SupportedTarget)
+  Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
+  }
+
   return Diags.getNumErrors() == NumErrorsBefore;
 }
 

diff  --git a/clang/test/CodeGenHLSL/validator_version.hlsl 
b/clang/test/CodeGenHLSL/validator_version.hlsl
index 426918a7221c4..0d2cbb96dbe48 100644
--- a/clang/test/CodeGenHLSL/validator_version.hlsl
+++ b/clang/test/CodeGenHLSL/validator_version.hlsl
@@ -1,5 +1,7 @@
 // RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm 
-xhlsl -validator-version 1.1 -o - %s | FileCheck %s
-// RUN: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl -validator-version 
1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL
+
+// FIXME:The following line should work once SPIR-V support for HLSL is added.
+// DISABLED: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl 
-validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL
 
 // CHECK:!dx.valver = !{![[valver:[0-9]+]]}
 // CHECK:![[valver]] = !{i32 1, i32 1}

diff  --git a/clang/test/Driver/hlsl-lang-targets.hlsl 
b/clang/test/Driver/hlsl-lang-targets.hlsl
new file mode 100644
index 0..a757e2a3cdf74
--- /dev/null
+++ b/clang/test/Driver/hlsl-lang-targets.hlsl
@@ -0,0 +1,14 @@
+// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=X86
+// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=DXIL
+// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s 
--check-prefix=SM
+// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s 
--check-prefix=SPIRV
+
+
+// A completely unsupported target...
+// X86: error: HLSL code generation is unsupported for target 
'x86_64-unknown-unknown'
+
+// Poorly specified targets
+// DXIL: error: HLSL code generation is unsupported for target 
'dxil-unknown-unknown'
+// SM: error: HLSL code generation is unsupported for target 
'x86_64-unknown-shadermodel'
+
+// FIXME// SPIRV: error: HLSL code generation is unsupported for target 
'spirv64-unknown-unknown'

diff  --git a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl 
b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl
index 03239fdab18f2..251362cd03c0f 100644
--- a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl
+++ b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl
@@ -29,20 +29,20 @@
 // PIXEL: #define __SHADER_TARGET_STAGE 0
 // VERTEX: #define _

[clang] de8f372 - [Docs] Fixing incorrect document title

2022-08-30 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-30T12:19:05-05:00
New Revision: de8f372bfec7070a364fac57fb5f201fc2d8cb22

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

LOG: [Docs] Fixing incorrect document title

Doh! This clearly slipped my review. Thanks DuckDuckGo for showing me
the error of my ways :).

Added: 


Modified: 
clang/docs/HLSL/ResourceTypes.rst

Removed: 




diff  --git a/clang/docs/HLSL/ResourceTypes.rst 
b/clang/docs/HLSL/ResourceTypes.rst
index c537e824758b..aad7b3314f08 100644
--- a/clang/docs/HLSL/ResourceTypes.rst
+++ b/clang/docs/HLSL/ResourceTypes.rst
@@ -1,6 +1,6 @@
-
-HLSL Support
-
+===
+HLSL Resource Types
+===
 
 .. contents::
:local:



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


[clang] 739a747 - [Docs] [HLSL] Documenting HLSL Entry Functions

2022-08-30 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-30T12:18:44-05:00
New Revision: 739a747b2368652155ac78f0ac341a6bfe640c60

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

LOG: [Docs] [HLSL] Documenting HLSL Entry Functions

This document describes the basic usage and implementation details for
HLSL entry functions in Clang.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D132672

Added: 
clang/docs/HLSL/EntryFunctions.rst

Modified: 
clang/docs/HLSL/HLSLDocs.rst

Removed: 




diff  --git a/clang/docs/HLSL/EntryFunctions.rst 
b/clang/docs/HLSL/EntryFunctions.rst
new file mode 100644
index ..0e547aab420c
--- /dev/null
+++ b/clang/docs/HLSL/EntryFunctions.rst
@@ -0,0 +1,65 @@
+
+HLSL Entry Functions
+
+
+.. contents::
+   :local:
+
+Usage
+=
+
+In HLSL, entry functions denote the starting point for shader execution. They
+must be known at compile time. For all non-library shaders, the compiler 
assumes
+the default entry function name ``main``, unless the DXC ``/E`` option is
+provided to specify an alternate entry point. For library shaders entry points
+are denoted using the ``[shader(...)]`` attribute.
+
+All scalar parameters to entry functions must have semantic annotations, and 
all
+struct parameters must have semantic annotations on every field in the struct
+declaration. Additionally if the entry function has a return type, a semantic
+annotation must be provided for the return type as well.
+
+HLSL entry functions can be called from other parts of the shader, which has
+implications on code generation.
+
+Implementation Details
+==
+
+In Clang, the DXC ``/E`` option is translated to the cc1 flag ``-hlsl-entry``,
+which in turn applies the ``HLSLShader`` attribute to the function with the
+specified name. This allows code generation for entry functions to always key
+off the presence of the ``HLSLShader`` attribute, regardless of what shader
+profile you are compiling.
+
+In code generation, two functions are generated. One is the user defined
+function, which is code generated as a mangled C++ function with internal
+linkage following normal function code generation.
+
+The actual exported entry function which can be called by the GPU driver is a
+``void(void)`` function that isn't name mangled. In code generation we generate
+the unmangled entry function, instantiations of the parameters with their
+semantic values populated, and a call to the user-defined function. After the
+call instruction the return value (if any) is saved using a target-appropriate
+intrinsic for storing outputs (for DirectX, the ``llvm.dx.store.output``).
+
+.. note::
+
+   HLSL support in Clang is currently focused on compute shaders, which do not
+   support output semantics. Support for output semantics will not be
+   implemented until other shader profiles are supported.
+
+Below is example IR that represents the planned implementation, subject to
+change as the ``llvm.dx.store.output`` and ``llvm.dx.load.input`` intrinsics 
are
+not yet implemented.
+
+.. code-block:: none
+
+   ; Function Attrs: norecurse
+   define void @main() #1 {
+  entry:
+  %0 = call i32 @llvm.dx.load.input.i32(...)
+  %1 = call i32 @"?main@@YAXII@Z"(i32 %0)
+  call @llvm.dx.store.output.i32(%1, ...)
+  ret void
+   }
+

diff  --git a/clang/docs/HLSL/HLSLDocs.rst b/clang/docs/HLSL/HLSLDocs.rst
index 0b66e517a73a..2cfe631da939 100644
--- a/clang/docs/HLSL/HLSLDocs.rst
+++ b/clang/docs/HLSL/HLSLDocs.rst
@@ -12,3 +12,4 @@ HLSL Design and Implementation
:maxdepth: 1
 
ResourceTypes
+   EntryFunctions



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


[clang] 18385cf - [HLSL] Add abs library function

2022-08-25 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-25T18:56:51-05:00
New Revision: 18385cffc50a6e549dcf3306cbe8a99e10a11fff

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

LOG: [HLSL] Add abs library function

This change exposes the abs library function for HLSL scalar types. Abs
is supported for all scalar, vector and matrix types. This patch only
adds a subset of scalar type support.

Fixes #57100 (https://llvm.org/pr57100)

The full documentation of the HLSL abs function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-abs

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D131718

Added: 
clang/test/CodeGenHLSL/builtins/abs.hlsl

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 76aed6a7c928f..2b284b405e61c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -495,6 +495,7 @@ defvar render_script = LangOpts<"RenderScript">;
 defvar hip = LangOpts<"HIP">;
 defvar gnu_mode = LangOpts<"GNUMode">;
 defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
+defvar hlsl = LangOpts<"HLSL">;
 
 defvar std = !strconcat("LangStandard::getLangStandardForKind(", 
lang_std.KeyPath, ")");
 
@@ -6134,7 +6135,7 @@ def fnative_half_type: Flag<["-"], "fnative-half-type">,
 def fnative_half_arguments_and_returns : Flag<["-"], 
"fnative-half-arguments-and-returns">,
   HelpText<"Use the native __fp16 type for arguments and returns (and skip 
ABI-specific lowering)">,
   MarshallingInfoFlag>,
-  ImpliedByAnyOf<[open_cl.KeyPath, render_script.KeyPath]>;
+  ImpliedByAnyOf<[open_cl.KeyPath, render_script.KeyPath, hlsl.KeyPath]>;
 def fallow_half_arguments_and_returns : Flag<["-"], 
"fallow-half-arguments-and-returns">,
   HelpText<"Allow function arguments and returns of type half">,
   MarshallingInfoFlag>,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index eaf9a1f23fd50..d9bc80add1cf7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3520,7 +3520,6 @@ static void RenderHLSLOptions(const ArgList &Args, 
ArgStringList &CmdArgs,
   // Add the default headers if dxc_no_stdinc is not set.
   if (!Args.hasArg(options::OPT_dxc_no_stdinc))
 CmdArgs.push_back("-finclude-default-header");
-  CmdArgs.push_back("-fallow-half-arguments-and-returns");
 }
 
 static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args,

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index b5cdb8b449709..f43a6ad4779a9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,13 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 
+__attribute__((clang_builtin_alias(__builtin_abs))) int abs(int In);
+__attribute__((clang_builtin_alias(__builtin_labs))) int64_t abs(int64_t In);
+__attribute__((clang_builtin_alias(__builtin_fabsf))) float abs(float In);
+__attribute__((clang_builtin_alias(__builtin_fabs))) double abs(double In);
+
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_fabsf16))) half abs(half In);
+#endif
+
 #endif //_HLSL_HLSL_INTRINSICS_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl 
b/clang/test/CodeGenHLSL/builtins/abs.hlsl
new file mode 100644
index 0..6578475f40170
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
+
+
+float abs_float(float X) {
+  return abs(X);
+}
+
+// CHECK: define noundef float @"?abs_float@@YAMM@Z"(
+// CHECK: call float @llvm.fabs.f32(float %0)
+
+double abs_double(double X) {
+  return abs(X);
+}
+
+// CHECK: define noundef double @"?abs_double@@YANN@Z"(
+// CHECK: call double @llvm.fabs.f64(double %0)
+
+half abs_half(half X) {
+  return abs(X);
+}
+
+// CHECK: define noundef half @"?abs_half@@YA$f16@$f16@@Z"(
+// CHECK: call half @llvm.fabs.f16(half %0)
+// NO_HALF: define noundef float @"?abs_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.fabs.f32(float %0)
+
+int abs_int(int X) {
+  return abs(X);
+}
+
+// NO_HA

[clang] 22c477f - [HLSL] Initial codegen for SV_GroupIndex

2022-08-25 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-25T11:17:54-05:00
New Revision: 22c477f934c4d1fa3f7d782d32a3e151f581c686

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

LOG: [HLSL] Initial codegen for SV_GroupIndex

Semantic parameters aren't passed as actual parameters, instead they are
populated from intrinsics which are generally lowered to reads from
dedicated hardware registers.

This change modifies clang CodeGen to emit the intrinsic calls and
populate the parameter's LValue with the result of the intrinsic call
for SV_GroupIndex.

The result of this is to make the actual passed argument ignored, which
will make it easy to clean up later in an IR pass.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131203

Added: 
clang/test/CodeGenHLSL/semantics/GroupIndex-codegen.hlsl

Modified: 
clang/lib/AST/Mangle.cpp
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index cb9a35cb0e7da..7ea569c63d9e4 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -133,10 +133,6 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl 
*D) {
   if (isa(D))
 return true;
 
-  // HLSL shader entry function never need to be mangled.
-  if (getASTContext().getLangOpts().HLSL && D->hasAttr())
-return false;
-
   return shouldMangleCXXName(D);
 }
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5c3930869864c..fa7bab9121b7a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -14,7 +14,9 @@
 
 #include "CGHLSLRuntime.h"
 #include "CodeGenModule.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/TargetOptions.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 
@@ -87,11 +89,55 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, 
GlobalVariable *GV) {
 ConstantAsMetadata::get(B.getInt32(Counter))}));
 }
 
-void clang::CodeGen::CGHLSLRuntime::setHLSLFunctionAttributes(
-llvm::Function *F, const FunctionDecl *FD) {
-  if (HLSLShaderAttr *ShaderAttr = FD->getAttr()) {
-const StringRef ShaderAttrKindStr = "hlsl.shader";
-F->addFnAttr(ShaderAttrKindStr,
- ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
+void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
+const FunctionDecl *FD, llvm::Function *Fn) {
+  const auto *ShaderAttr = FD->getAttr();
+  assert(ShaderAttr && "All entry functions must have a HLSLShaderAttr");
+  const StringRef ShaderAttrKindStr = "hlsl.shader";
+  Fn->addFnAttr(ShaderAttrKindStr,
+ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
+}
+
+llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
+  const ParmVarDecl &D) {
+  assert(D.hasAttrs() && "Entry parameter missing annotation attribute!");
+  if (D.hasAttr()) {
+llvm::Function *DxGroupIndex =
+CGM.getIntrinsic(Intrinsic::dx_flattened_thread_id_in_group);
+return B.CreateCall(FunctionCallee(DxGroupIndex));
+  }
+  assert(false && "Unhandled parameter attribute");
+  return nullptr;
+}
+
+void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
+  llvm::Function *Fn) {
+  llvm::Module &M = CGM.getModule();
+  llvm::LLVMContext &Ctx = M.getContext();
+  auto *EntryTy = llvm::FunctionType::get(llvm::Type::getVoidTy(Ctx), false);
+  Function *EntryFn =
+  Function::Create(EntryTy, Function::ExternalLinkage, FD->getName(), &M);
+
+  // Copy function attributes over, we have no argument or return attributes
+  // that can be valid on the real entry.
+  AttributeList NewAttrs = AttributeList::get(Ctx, 
AttributeList::FunctionIndex,
+  
Fn->getAttributes().getFnAttrs());
+  EntryFn->setAttributes(NewAttrs);
+  setHLSLEntryAttributes(FD, EntryFn);
+
+  // Set the called function as internal linkage.
+  Fn->setLinkage(GlobalValue::InternalLinkage);
+
+  BasicBlock *BB = BasicBlock::Create(Ctx, "entry", EntryFn);
+  IRBuilder<> B(BB);
+  llvm::SmallVector Args;
+  // FIXME: support struct parameters where semantics are on members.
+  for (const auto *Param : FD->parameters()) {
+Args.push_back(emitInputSemantic(B, *Param));
   }
+
+  CallInst *CI = B.CreateCall(FunctionCallee(Fn), Args);
+  (void)CI;
+  // FIXME: Handle codegen for return type semantics.
+  B.CreateRetVoid();
 }

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a7246f7f8919b..9bd698b325026 100644
-

[clang] bdf1327 - [HLSL] Entry functions require param annotation

2022-08-24 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-24T14:35:11-05:00
New Revision: bdf1327fea632bf9736924acf59675182b528b23

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

LOG: [HLSL] Entry functions require param annotation

HLSL entry function parameters must have parameter annotations. This
allows appropriate intrinsic values to be populated into parameters
during code generation.

This does not handle entry function return values, which will be
handled in a subsequent commit because we don't currently support any
annotations that are valid for function returns.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131625

Added: 
clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl

Modified: 
clang/include/clang/AST/Attr.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 070e160d65170..4478c5fd91d4a 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -190,6 +190,22 @@ class InheritableParamAttr : public InheritableAttr {
   }
 };
 
+class HLSLAnnotationAttr : public InheritableAttr {
+protected:
+  HLSLAnnotationAttr(ASTContext &Context, const AttributeCommonInfo 
&CommonInfo,
+ attr::Kind AK, bool IsLateParsed,
+ bool InheritEvenIfAlreadyPresent)
+  : InheritableAttr(Context, CommonInfo, AK, IsLateParsed,
+InheritEvenIfAlreadyPresent) {}
+
+public:
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Attr *A) {
+return A->getKind() >= attr::FirstHLSLAnnotationAttr &&
+   A->getKind() <= attr::LastHLSLAnnotationAttr;
+  }
+};
+
 /// A parameter attribute which changes the argument-passing ABI rule
 /// for the parameter.
 class ParameterABIAttr : public InheritableParamAttr {

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 129055982c543..f962f84f3b7a7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -608,6 +608,9 @@ class DeclOrTypeAttr : InheritableAttr;
 /// A attribute is either a declaration attribute or a statement attribute.
 class DeclOrStmtAttr : InheritableAttr;
 
+/// An attribute class for HLSL Annotations.
+class HLSLAnnotationAttr : InheritableAttr;
+
 /// A target-specific attribute.  This class is meant to be used as a mixin
 /// with InheritableAttr or Attr depending on the attribute's needs.
 class TargetSpecificAttr {
@@ -4011,7 +4014,7 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
-def HLSLSV_GroupIndex: InheritableAttr {
+def HLSLSV_GroupIndex: HLSLAnnotationAttr {
   let Spellings = [HLSLSemantic<"SV_GroupIndex">];
   let Subjects = SubjectList<[ParmVar, GlobalVar]>;
   let LangOpts = [HLSL];

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f544bd345a556..ae10b13c8c769 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11643,6 +11643,9 @@ def err_hlsl_numthreads_argument_oor : Error<"argument 
'%select{X|Y|Z}0' to numt
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_missing_numthreads : Error<"missing numthreads attribute for %0 
shader entry">;
 def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not 
match the previous declaration">;
+def err_hlsl_missing_semantic_annotation : Error<
+  "semantic annotations must be present for all parameters of an entry "
+  "function or patch constant function">;
 
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3ca5bf3b1254c..ef59ecebb70ac 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11894,6 +11894,16 @@ void Sema::CheckHLSLEntryPoint(FunctionDecl *FD) {
 }
 break;
   }
+
+  for (const auto *Param : FD->parameters()) {
+if (!Param->hasAttr()) {
+  // FIXME: Handle struct parameters where annotations are on struct 
fields.
+  Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation);
+  Diag(Param->getLocation(), diag::note_previous_decl) << Param;
+  FD->setInvalidDecl();
+}
+  }
+  // FIXME: Verify return type semantic annotation.
 }
 
 bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {

diff  --git a/clang/test/SemaHLSL/Semantics/missing_entry_annotation.hlsl 
b/clang/test/SemaHLSL/Semantics/m

[clang] 887bafb - [HLSL] Infer language from file extension

2022-08-23 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-23T20:52:29-05:00
New Revision: 887bafb503c59c5ecef831c679a2b114ee6ef338

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

LOG: [HLSL] Infer language from file extension

This allows the language mode for HLSL to be inferred from the file
extension.

Added: 
clang/test/Preprocessor/predefined-macros-hlsl.hlsl

Modified: 
clang/lib/Frontend/FrontendOptions.cpp

Removed: 
clang/test/Preprocessor/predefined-macros-hlsl.c



diff  --git a/clang/lib/Frontend/FrontendOptions.cpp 
b/clang/lib/Frontend/FrontendOptions.cpp
index a7bdae343a944..bf83b27c1367e 100644
--- a/clang/lib/Frontend/FrontendOptions.cpp
+++ b/clang/lib/Frontend/FrontendOptions.cpp
@@ -33,5 +33,6 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef 
Extension) {
   .Cases("cu", "cuh", Language::CUDA)
   .Case("hip", Language::HIP)
   .Cases("ll", "bc", Language::LLVM_IR)
+  .Case("hlsl", Language::HLSL)
   .Default(Language::Unknown);
 }

diff  --git a/clang/test/Preprocessor/predefined-macros-hlsl.c 
b/clang/test/Preprocessor/predefined-macros-hlsl.c
deleted file mode 100644
index 2e2d928f54110..0
--- a/clang/test/Preprocessor/predefined-macros-hlsl.c
+++ /dev/null
@@ -1,48 +0,0 @@
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-amplification | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,AMPLIFICATION
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-compute | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,COMPUTE
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-domain | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,DOMAIN
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-geometry | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,GEOMETRY
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple dxil-pc-shadermodel6.0-hull 
| FileCheck -match-full-lines %s --check-prefixes=CHECK,HULL
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-library | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,LIBRARY
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple dxil-pc-shadermodel6.0-mesh 
| FileCheck -match-full-lines %s --check-prefixes=CHECK,MESH
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple dxil-pc-shadermodel6.0-pixel 
| FileCheck -match-full-lines %s --check-prefixes=CHECK,PIXEL
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -triple 
dxil-pc-shadermodel6.0-vertex | FileCheck -match-full-lines %s 
--check-prefixes=CHECK,VERTEX
-
-// CHECK: #define __HLSL_VERSION 2021
-// CHECK: #define __SHADER_STAGE_AMPLIFICATION 14
-// CHECK: #define __SHADER_STAGE_COMPUTE 5
-// CHECK: #define __SHADER_STAGE_DOMAIN 4
-// CHECK: #define __SHADER_STAGE_GEOMETRY 2
-// CHECK: #define __SHADER_STAGE_HULL 3
-// CHECK: #define __SHADER_STAGE_LIBRARY 6
-// CHECK: #define __SHADER_STAGE_MESH 13
-// CHECK: #define __SHADER_STAGE_PIXEL 0
-// CHECK: #define __SHADER_STAGE_VERTEX 1
-
-// AMPLIFICATION: #define __SHADER_TARGET_STAGE 14
-// COMPUTE: #define __SHADER_TARGET_STAGE 5
-// DOMAIN: #define __SHADER_TARGET_STAGE 4
-// GEOMETRY: #define __SHADER_TARGET_STAGE 2
-// HULL: #define __SHADER_TARGET_STAGE 3
-// LIBRARY: #define __SHADER_TARGET_STAGE 6
-// MESH: #define __SHADER_TARGET_STAGE 13
-// PIXEL: #define __SHADER_TARGET_STAGE 0
-// VERTEX: #define __SHADER_TARGET_STAGE 1
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck 
-match-full-lines %s --check-prefixes=STD2015
-// STD2015: #define __HLSL_VERSION 2015
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck 
-match-full-lines %s --check-prefixes=STD2016
-// STD2016: #define __HLSL_VERSION 2016
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck 
-match-full-lines %s --check-prefixes=STD2017
-// STD2017: #define __HLSL_VERSION 2017
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck 
-match-full-lines %s --check-prefixes=STD2018
-// STD2018: #define __HLSL_VERSION 2018
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck 
-match-full-lines %s --check-prefixes=STD2021
-// STD2021: #define __HLSL_VERSION 2021
-
-// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck 
-match-full-lines %s --check-prefixes=STD202x
-// STD202x: #define __HLSL_VERSION 2029

diff  --git a/clang/test/Preprocessor/predefined-macros-hlsl.hlsl 
b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl
new file mode 100644
index 0..03239fdab18f2
--- /dev/null
+++ b/clang/test/Preprocessor/predefined-macros-hlsl.hlsl
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 %s -E -dM -o - -triple dxil-pc-shadermodel6.0-amplification 
| FileCheck -match-full-lines %s --check-prefixes=CHECK

[clang] 9a478d5 - [NFC] Rename dx.shader to hlsl.shader

2022-08-22 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-22T16:03:40-05:00
New Revision: 9a478d523239fe0d01f32ecc8e64e88d1809fd8e

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

LOG: [NFC] Rename dx.shader to hlsl.shader

This metadata annotation is HLSL-specific not DirectX specific. It will
need to be attached for shaders regardless of whether they are targeting
DXIL.

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/test/CodeGenHLSL/entry.hlsl
clang/test/CodeGenHLSL/shader_type_attr.hlsl

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 70c582285136c..5c3930869864c 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -90,7 +90,7 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, 
GlobalVariable *GV) {
 void clang::CodeGen::CGHLSLRuntime::setHLSLFunctionAttributes(
 llvm::Function *F, const FunctionDecl *FD) {
   if (HLSLShaderAttr *ShaderAttr = FD->getAttr()) {
-const StringRef ShaderAttrKindStr = "dx.shader";
+const StringRef ShaderAttrKindStr = "hlsl.shader";
 F->addFnAttr(ShaderAttrKindStr,
  ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
   }

diff  --git a/clang/test/CodeGenHLSL/entry.hlsl 
b/clang/test/CodeGenHLSL/entry.hlsl
index 10b5f692bfe83..1a1a507358246 100644
--- a/clang/test/CodeGenHLSL/entry.hlsl
+++ b/clang/test/CodeGenHLSL/entry.hlsl
@@ -3,7 +3,7 @@
 // Make sure not mangle entry.
 // CHECK:define void @foo()
 // Make sure add function attribute.
-// CHECK:"dx.shader"="compute"
+// CHECK:"hlsl.shader"="compute"
 [numthreads(1,1,1)]
 void foo() {
 

diff  --git a/clang/test/CodeGenHLSL/shader_type_attr.hlsl 
b/clang/test/CodeGenHLSL/shader_type_attr.hlsl
index 059ced6cbc2c5..8bc7a9c0953e5 100644
--- a/clang/test/CodeGenHLSL/shader_type_attr.hlsl
+++ b/clang/test/CodeGenHLSL/shader_type_attr.hlsl
@@ -3,7 +3,7 @@
 // Make sure not mangle entry.
 // CHECK:define void @foo()
 // Make sure add function attribute.
-// CHECK:"dx.shader"="compute"
+// CHECK:"hlsl.shader"="compute"
 [shader("compute")]
 [numthreads(1,1,1)]
 void foo() {



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


[clang] 0ac597f - [NFC] Move DXC driver tests

2022-08-18 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-18T16:06:41-05:00
New Revision: 0ac597f3cacf60479ffd36b03766fa7462dabd78

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

LOG: [NFC] Move DXC driver tests

The DXC driver tests don't really belong mixed in with the toolchain
tests. This pulls them out to their own file and moves the
SimpleDiagnosticConsumer into a header so it can be used by both DXC and
toolchain tests.

fast-forwarded.

Added: 
clang/unittests/Driver/DXCModeTest.cpp
clang/unittests/Driver/SimpleDiagnosticConsumer.h

Modified: 
clang/unittests/Driver/CMakeLists.txt
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/CMakeLists.txt 
b/clang/unittests/Driver/CMakeLists.txt
index aced8f4c467ef..01149587d44e3 100644
--- a/clang/unittests/Driver/CMakeLists.txt
+++ b/clang/unittests/Driver/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_unittest(ClangDriverTests
   DistroTest.cpp
+  DXCModeTest.cpp
   ToolChainTest.cpp
   ModuleCacheTest.cpp
   MultilibTest.cpp

diff  --git a/clang/unittests/Driver/DXCModeTest.cpp 
b/clang/unittests/Driver/DXCModeTest.cpp
new file mode 100644
index 0..9ff431bb6cbb7
--- /dev/null
+++ b/clang/unittests/Driver/DXCModeTest.cpp
@@ -0,0 +1,239 @@
+//===- unittests/Driver/DXCModeTest.cpp --- DXC Mode tests 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for driver DXCMode.
+//
+//===--===//
+
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/ToolChain.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include 
+
+#include "SimpleDiagnosticConsumer.h"
+
+using namespace clang;
+using namespace clang::driver;
+
+static void validateTargetProfile(
+StringRef TargetProfile, StringRef ExpectTriple,
+IntrusiveRefCntPtr &InMemoryFileSystem,
+DiagnosticsEngine &Diags) {
+  Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
+  std::unique_ptr C{TheDriver.BuildCompilation(
+  {"clang", "--driver-mode=dxc", TargetProfile.data(), "foo.hlsl"})};
+  EXPECT_TRUE(C);
+  EXPECT_STREQ(TheDriver.getTargetTriple().c_str(), ExpectTriple.data());
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+}
+
+static void validateTargetProfile(
+StringRef TargetProfile, StringRef ExpectError,
+IntrusiveRefCntPtr &InMemoryFileSystem,
+DiagnosticsEngine &Diags, SimpleDiagnosticConsumer *DiagConsumer,
+unsigned NumOfErrors) {
+  Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
+  std::unique_ptr C{TheDriver.BuildCompilation(
+  {"clang", "--driver-mode=dxc", TargetProfile.data(), "foo.hlsl"})};
+  EXPECT_TRUE(C);
+  EXPECT_EQ(Diags.getNumErrors(), NumOfErrors);
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(), ExpectError.data());
+  Diags.Clear();
+  DiagConsumer->clear();
+}
+
+TEST(DxcModeTest, TargetProfileValidation) {
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile("foo.hlsl", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  auto *DiagConsumer = new SimpleDiagnosticConsumer;
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
+
+  validateTargetProfile("-Tvs_6_0", "dxil--shadermodel6.0-vertex",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Ths_6_1", "dxil--shadermodel6.1-hull",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Tds_6_2", "dxil--shadermodel6.2-domain",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Tds_6_2", "dxil--shadermodel6.2-domain",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Tgs_6_3", "dxil--shadermodel6.3-geometry",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Tps_6_4", "dxil--shadermodel6.4-pixel",
+InMemoryFileSystem, Diags);
+  validateTargetProfile("-Tcs_6_5", "dxil--shadermodel6.5-compute",
+InMemoryFileSystem, Diags);
+  va

[clang] fc47001 - [Docs] Add HLSL ResourceType documentation

2022-08-08 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-08T09:06:38-05:00
New Revision: fc470013d13f2b996731c865b921df5a87a40e3f

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

LOG: [Docs] Add HLSL ResourceType documentation

Along with the new documentation this also re-organizes the HLSL docs
to a subdirectory. The hope is to continue to expand this documentation
as the HLSL implementation advances.

Differential Revision: https://reviews.llvm.org/D130794

Added: 
clang/docs/HLSL/HLSLDocs.rst
clang/docs/HLSL/HLSLSupport.rst
clang/docs/HLSL/ResourceTypes.rst

Modified: 
clang/docs/index.rst

Removed: 
clang/docs/HLSLSupport.rst



diff  --git a/clang/docs/HLSL/HLSLDocs.rst b/clang/docs/HLSL/HLSLDocs.rst
new file mode 100644
index 0..0b66e517a73a0
--- /dev/null
+++ b/clang/docs/HLSL/HLSLDocs.rst
@@ -0,0 +1,14 @@
+.. title:: Clang HLSL Documentation
+
+.. toctree::
+   :maxdepth: 1
+
+   HLSLSupport
+
+HLSL Design and Implementation
+==
+
+.. toctree::
+   :maxdepth: 1
+
+   ResourceTypes

diff  --git a/clang/docs/HLSLSupport.rst b/clang/docs/HLSL/HLSLSupport.rst
similarity index 100%
rename from clang/docs/HLSLSupport.rst
rename to clang/docs/HLSL/HLSLSupport.rst

diff  --git a/clang/docs/HLSL/ResourceTypes.rst 
b/clang/docs/HLSL/ResourceTypes.rst
new file mode 100644
index 0..c537e824758b3
--- /dev/null
+++ b/clang/docs/HLSL/ResourceTypes.rst
@@ -0,0 +1,34 @@
+
+HLSL Support
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL Resources are runtime-bound data that is provided as input, output or both
+to shader programs written in HLSL. Resource Types in HLSL provide key user
+abstractions for reading and writing resource data.
+
+Implementation Details
+==
+
+In Clang resource types are forward declared by the ``HLSLExternalSemaSource``
+on initialization. They are then lazily completed when ``requiresCompleteType``
+is called later in Sema.
+
+Resource types are templated class declarations. The template parameter
+specifies the expected return type of resource loads, and the expected 
parameter
+type for stores.
+
+In Clang's AST and code generation, resource types are classes that store a
+pointer of the template parameter type. The pointer is populated from a call to
+``__builtin_hlsl_create_handle``, and treated as a pointer to an array of typed
+data through until lowering in the backend.
+
+Resource types are annotated with the ``HLSLResource`` attribute, which drives
+code generation for resource binding metadata. The ``hlsl`` metadata nodes are
+transformed in the backend to the binding information expected by the target
+runtime.

diff  --git a/clang/docs/index.rst b/clang/docs/index.rst
index 78a1ed12bcf3c..81ffc9d7e5f00 100644
--- a/clang/docs/index.rst
+++ b/clang/docs/index.rst
@@ -46,7 +46,7 @@ Using Clang as a Compiler
OpenCLSupport
OpenMPSupport
SYCLSupport
-   HLSLSupport
+   HLSL/HLSLDocs
ThinLTO
APINotes
DebuggingCoroutines



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


[clang] 5dbb92d - [HLSL] CodeGen HLSL Resource annotations

2022-08-01 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-08-01T11:19:43-05:00
New Revision: 5dbb92d8cdf751d5960225e874c27d19597fa65e

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

LOG: [HLSL] CodeGen HLSL Resource annotations

HLSL Resource types need special annotations that the backend will use
to build out metadata and resource annotations that are required by
DirectX and Vulkan drivers in order to provide correct data bindings
for shader exeuction.

This patch adds some of the required data for unordered-access-views
(UAV) resource binding into the module flags. This data will evolve
over time to cover all the required use cases, but this should get
things started.

Depends on D130018.

Differential Revision: https://reviews.llvm.org/D130019

Added: 
clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl

Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 949112c63cc9e..620af1e633b73 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "CGCXXABI.h"
+#include "CGHLSLRuntime.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
 #include "CodeGenFunction.h"
@@ -977,6 +978,9 @@ void 
CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
 EmitCXXGlobalVarDeclInit(*D, Addr, PerformInit);
   }
 
+  if (getLangOpts().HLSL)
+CGM.getHLSLRuntime().annotateHLSLResource(D, Addr);
+
   FinishFunction();
 }
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 7dfcc65969a86..3321d4ad0afb5 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -20,6 +20,7 @@
 
 using namespace clang;
 using namespace CodeGen;
+using namespace hlsl;
 using namespace llvm;
 
 namespace {
@@ -50,3 +51,38 @@ void CGHLSLRuntime::finishCodeGen() {
   llvm::Module &M = CGM.getModule();
   addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
 }
+
+void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) 
{
+  const Type *Ty = D->getType()->getPointeeOrArrayElementType();
+  if (!Ty)
+return;
+  const auto *RD = Ty->getAsCXXRecordDecl();
+  if (!RD)
+return;
+  const auto *Attr = RD->getAttr();
+  if (!Attr)
+return;
+
+  HLSLResourceAttr::ResourceClass RC = Attr->getResourceType();
+  uint32_t Counter = ResourceCounters[static_cast(RC)]++;
+
+  NamedMDNode *ResourceMD = nullptr;
+  switch (RC) {
+  case HLSLResourceAttr::ResourceClass::UAV:
+ResourceMD = CGM.getModule().getOrInsertNamedMetadata("hlsl.uavs");
+break;
+  default:
+assert(false && "Unsupported buffer type!");
+return;
+  }
+
+  assert(ResourceMD != nullptr &&
+ "ResourceMD must have been set by the switch above.");
+
+  auto &Ctx = CGM.getModule().getContext();
+  IRBuilder<> B(Ctx);
+  QualType QT(Ty, 0);
+  ResourceMD->addOperand(MDNode::get(
+  Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, QT.getAsString()),
+ConstantAsMetadata::get(B.getInt32(Counter))}));
+}

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 268810f2ec9e6..5953be4117f94 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -15,7 +15,16 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
 #define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
 
+#include "clang/Basic/HLSLRuntime.h"
+
+namespace llvm {
+class Value;
+class GlobalVariable;
+} // namespace llvm
 namespace clang {
+class CallExpr;
+class Type;
+class VarDecl;
 
 namespace CodeGen {
 
@@ -24,11 +33,15 @@ class CodeGenModule;
 class CGHLSLRuntime {
 protected:
   CodeGenModule &CGM;
+  uint32_t ResourceCounters[static_cast(
+  hlsl::ResourceClass::NumClasses)] = {0};
 
 public:
   CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
   virtual ~CGHLSLRuntime() {}
 
+  void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
+
   void finishCodeGen();
 };
 

diff  --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
new file mode 100644
index 0..4d12fa197f5e2
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s 
+
+RWBuffer Buffer1;
+RWBuffer > BufferArray[4];
+
+[numthreads(1,1,1)]
+void main() {
+}
+
+// CHECK: !hlsl.uavs = !{![[Single:[0-9]+]], ![[Array:[0-9]+]]}
+// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1

[clang] cc47db6 - [HLSL] Add HLSLResource attribute

2022-07-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-28T20:54:51-05:00
New Revision: cc47db6737049f0c30e9c092de65e40823eb14be

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

LOG: [HLSL] Add HLSLResource attribute

HLSL Resource objects will have restrictions on use and codegen
requirements. This patch is fairly minimal just adding the attribute
with no spellings since it will only be attached by the
HLSLExternalSemaSource.

Depends on D1300017.

Differential Revision: https://reviews.llvm.org/D130018

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index d61f3583281d..0460371d26c9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4022,6 +4022,17 @@ def HLSLShader : InheritableAttr {
   let Documentation = [HLSLSV_ShaderTypeAttrDocs];
 }
 
+def HLSLResource : InheritableAttr {
+  let Spellings = [];
+  let Subjects = SubjectList<[Struct]>;
+  let LangOpts = [HLSL];
+  let Args = [EnumArgument<"ResourceType", "ResourceClass",
+   ["SRV", "UAV", "CBuffer", "Sampler"],
+   ["SRV", "UAV", "CBuffer", "Sampler"]
+   >];
+  let Documentation = [InternalOnly];
+}
+
 def RandomizeLayout : InheritableAttr {
   let Spellings = [GCC<"randomize_layout">];
   let Subjects = SubjectList<[Record]>;

diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 79f61c43ded4..fe963fdbf278 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -107,6 +107,13 @@ struct BuiltinTypeDeclBuilder {
 return addMemberVariable("h", Record->getASTContext().VoidPtrTy, Access);
   }
 
+  BuiltinTypeDeclBuilder &
+  annotateResourceClass(HLSLResourceAttr::ResourceClass RC) {
+Record->addAttr(
+HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC));
+return *this;
+  }
+
   static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
 StringRef Name) {
 CXXScopeSpec SS;
@@ -361,5 +368,6 @@ void 
HLSLExternalSemaSource::completeBufferType(CXXRecordDecl *Record) {
   BuiltinTypeDeclBuilder(Record)
   .addHandleMember()
   .addDefaultHandleConstructor(*SemaPtr, ResourceClass::UAV)
+  .annotateResourceClass(HLSLResourceAttr::UAV)
   .completeDefinition();
 }

diff  --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index 9d4fff346f79..c9cbd730933f 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -38,10 +38,12 @@ RWBuffer Buffer;
 // CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RWBuffer definition
 
 // CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV
 // CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h 'void *'
 // CHECK: ClassTemplateSpecializationDecl 0x{{[0-9A-Fa-f]+}} <> 
 class RWBuffer definition
 
 // CHECK: TemplateArgument type 'float'
 // CHECK-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
 // CHECK-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV
 // CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>   
implicit referenced h 'void *'



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


[clang] 66eabeb - [HLSL] Add RWBuffer default constructor

2022-07-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-28T14:07:40-05:00
New Revision: 66eabeb65dc9dc53fa791e444fa228a406bd304e

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

LOG: [HLSL] Add RWBuffer default constructor

This fills out the default constructor for RWBuffer to assign the
handle with the result of __builtin_hlsl_create_handle which we can
then treat as a pointer to the resource data through the mid-level of
the compiler.

Depends on D130016

Differential Revision: https://reviews.llvm.org/D130017

Added: 
clang/include/clang/Basic/HLSLRuntime.h
clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl

Modified: 
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/HLSLRuntime.h 
b/clang/include/clang/Basic/HLSLRuntime.h
new file mode 100644
index 0..bc3a064f9b69e
--- /dev/null
+++ b/clang/include/clang/Basic/HLSLRuntime.h
@@ -0,0 +1,34 @@
+//===- HLSLRuntime.h - HLSL Runtime -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// Defines the clang::IdentifierInfo, clang::IdentifierTable, and
+/// clang::Selector interfaces.
+//
+//===--===//
+
+#ifndef CLANG_BASIC_HLSLRUNTIME_H
+#define CLANG_BASIC_HLSLRUNTIME_H
+
+#include 
+
+namespace clang {
+namespace hlsl {
+
+enum class ResourceClass : uint8_t {
+  SRV = 0,
+  UAV,
+  CBuffer,
+  Sampler,
+  NumClasses
+};
+
+} // namespace hlsl
+} // namespace clang
+
+#endif // CLANG_BASIC_HLSLRUNTIME_H

diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index d4ea0344adc4a..79f61c43ded43 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -11,13 +11,17 @@
 
 #include "clang/Sema/HLSLExternalSemaSource.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Basic/HLSLRuntime.h"
+#include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
 #include 
 
 using namespace clang;
+using namespace hlsl;
 
 namespace {
 
@@ -27,6 +31,7 @@ struct BuiltinTypeDeclBuilder {
   CXXRecordDecl *Record = nullptr;
   ClassTemplateDecl *Template = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
+  llvm::StringMap Fields;
 
   BuiltinTypeDeclBuilder(CXXRecordDecl *R) : Record(R) {
 Record->startDefinition();
@@ -93,6 +98,7 @@ struct BuiltinTypeDeclBuilder {
 Field->setAccess(Access);
 Field->setImplicit(true);
 Record->addDecl(Field);
+Fields[Name] = Field;
 return *this;
   }
 
@@ -101,6 +107,71 @@ struct BuiltinTypeDeclBuilder {
 return addMemberVariable("h", Record->getASTContext().VoidPtrTy, Access);
   }
 
+  static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
+StringRef Name) {
+CXXScopeSpec SS;
+IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
+DeclarationNameInfo NameInfo =
+DeclarationNameInfo(DeclarationName(&II), SourceLocation());
+LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+S.LookupParsedName(R, S.getCurScope(), &SS, false);
+assert(R.isSingleResult() &&
+   "Since this is a builtin it should always resolve!");
+auto *VD = cast(R.getFoundDecl());
+QualType Ty = VD->getType();
+return DeclRefExpr::Create(AST, NestedNameSpecifierLoc(), SourceLocation(),
+   VD, false, NameInfo, Ty, VK_PRValue);
+  }
+
+  static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
+return IntegerLiteral::Create(
+AST,
+llvm::APInt(AST.getIntWidth(AST.UnsignedCharTy),
+static_cast(RC)),
+AST.UnsignedCharTy, SourceLocation());
+  }
+
+  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
+  ResourceClass RC) {
+ASTContext &AST = Record->getASTContext();
+
+QualType ConstructorType =
+AST.getFunctionType(AST.VoidTy, {}, FunctionProtoType::ExtProtoInfo());
+
+CanQualType CanTy = 
Record->getTypeForDecl()->getCanonicalTypeUnqualified();
+DeclarationName Name = AST.DeclarationNames.getCXXConstructorName(CanTy);
+CXXConstructorDecl *Constructor = CXXConstructorDecl::Create(
+AST, Record, SourceLocation(),
+DeclarationNameInfo(Name, SourceL

[clang] fe13002 - [HLSL] Add __builtin_hlsl_create_handle

2022-07-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-28T09:16:11-05:00
New Revision: fe13002bb37caf7425dfdb56b8f891c3f33b54b6

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

LOG: [HLSL] Add __builtin_hlsl_create_handle

This is pretty straightforward, it just adds a builtin to return a
pointer to a resource handle. This maps to a dx intrinsic.

The shape of this builtin and the underlying intrinsic will likely
shift a bit as this implementation becomes more feature complete, but
this is a good basis to get started.

Depends on D128569.

Differential Revision: https://reviews.llvm.org/D130016

Added: 
clang/test/CodeGenHLSL/builtins/create_handle.hlsl

Modified: 
clang/include/clang/Basic/Builtins.def
llvm/include/llvm/IR/IntrinsicsDirectX.td

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index f19807dbbb0bb..c67f0dfe9ab04 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1700,6 +1700,7 @@ LANGBUILTIN(__builtin_get_device_side_mangled_name, 
"cC*.", "ncT", CUDA_LANG)
 
 // HLSL
 LANGBUILTIN(__builtin_hlsl_wave_active_count_bits, "Uib", "nc", HLSL_LANG)
+LANGBUILTIN(__builtin_hlsl_create_handle, "v*Uc", "nc", HLSL_LANG)
 
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")

diff  --git a/clang/test/CodeGenHLSL/builtins/create_handle.hlsl 
b/clang/test/CodeGenHLSL/builtins/create_handle.hlsl
new file mode 100644
index 0..61226c2b54e72
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/create_handle.hlsl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s
+
+void fn() {
+  (void)__builtin_hlsl_create_handle(0);
+}
+
+// CHECK: call ptr @llvm.dx.create.handle(i8 0)

diff  --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td 
b/llvm/include/llvm/IR/IntrinsicsDirectX.td
index 57c47a15bd70a..80e5b7919b9c6 100644
--- a/llvm/include/llvm/IR/IntrinsicsDirectX.td
+++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td
@@ -17,4 +17,6 @@ def int_dx_group_id : Intrinsic<[llvm_i32_ty], [llvm_i32_ty], 
[IntrNoMem, IntrWi
 def int_dx_thread_id_in_group : Intrinsic<[llvm_i32_ty], [llvm_i32_ty], 
[IntrNoMem, IntrWillReturn]>;
 def int_dx_flattened_thread_id_in_group : Intrinsic<[llvm_i32_ty], [], 
[IntrNoMem, IntrWillReturn]>;
 
+def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
+Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrNoMem, IntrWillReturn]>;
 }



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


[clang] 6e56d0d - Start support for HLSL `RWBuffer`

2022-07-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-28T08:49:50-05:00
New Revision: 6e56d0dbe3c89d3cd5730a57b9049b74e0bf605f

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

LOG: Start support for HLSL `RWBuffer`

Most of the change here is fleshing out the HLSLExternalSemaSource with
builder implementations to build the builtin types. Eventually, I may
move some of this code into tablegen or a more managable declarative
file but I want to get the AST generation logic ready first.

This code adds two new types into the HLSL AST, `hlsl::Resource` and
`hlsl::RWBuffer`. The `Resource` type is just a wrapper around a handle
identifier, and is largely unused in source. It will morph a bit over
time as I work on getting the source compatability correct, but for now
it is a reasonable stand-in. The `RWBuffer` type is not ready for use.
I'm posting this change for review because it adds a lot of
infrastructure code and is testable.

There is one change to clang code outside the HLSL-specific logic here,
which addresses a behavior change introduced a long time ago in
967d438439ac. That change resulted in unintentionally breaking
situations where an incomplete template declaration was provided from
an AST source, and needed to be completed later by the external AST.
That situation doesn't happen in the normal AST importer flow, but can
happen when an AST source provides incomplete declarations of
templates. The solution is to annotate template specializations of
incomplete types with the HasExternalLexicalSource bit from the base
template.

Depends on D128012.

Differential Revision: https://reviews.llvm.org/D128569

Added: 
clang/test/AST/HLSL/RWBuffer-AST.hlsl
clang/test/AST/HLSL/ResourceStruct.hlsl
clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl

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

Removed: 




diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 439fc3d10f333..a5aa21da12934 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -12,6 +12,8 @@
 #ifndef CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
 #define CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
 
+#include "llvm/ADT/DenseMap.h"
+
 #include "clang/Sema/ExternalSemaSource.h"
 
 namespace clang {
@@ -21,8 +23,16 @@ class Sema;
 class HLSLExternalSemaSource : public ExternalSemaSource {
   Sema *SemaPtr = nullptr;
   NamespaceDecl *HLSLNamespace;
+  CXXRecordDecl *ResourceDecl;
+
+  using CompletionFunction = std::function;
+  llvm::DenseMap Completions;
 
   void defineHLSLVectorAlias();
+  void defineTrivialHLSLTypes();
+  void forwardDeclareHLSLTypes();
+
+  void completeBufferType(CXXRecordDecl *Record);
 
 public:
   ~HLSLExternalSemaSource() override;
@@ -34,6 +44,9 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
 
   /// Inform the semantic consumer that Sema is no longer available.
   void ForgetSema() override { SemaPtr = nullptr; }
+
+  /// Complete an incomplete HLSL builtin type
+  void CompleteType(TagDecl *Tag) override;
 };
 
 } // namespace clang

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index e7e5f355809b0..e3dd7804c99ba 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -930,6 +930,14 @@ ClassTemplateSpecializationDecl::Create(ASTContext 
&Context, TagKind TK,
   SpecializedTemplate, Args, PrevDecl);
   Result->setMayHaveOutOfDateDef(false);
 
+  // If the template decl is incomplete, copy the external lexical storage from
+  // the base template. This allows instantiations of incomplete types to
+  // complete using the external AST if the template's declaration came from an
+  // external AST.
+  if (!SpecializedTemplate->getTemplatedDecl()->isCompleteDefinition())
+Result->setHasExternalLexicalStorage(
+  SpecializedTemplate->getTemplatedDecl()->hasExternalLexicalStorage());
+
   Context.getTypeDeclType(Result, PrevDecl);
   return Result;
 }

diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 56c2dd40bd9a8..d4ea0344adc4a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -15,8 +15,161 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Sema/Sema.h"
 
+#include 
+
 using namespace clang;
 
+namespace {
+
+struct TemplateParameterListBuilder;
+
+struct BuiltinTypeDeclBuilder {
+  CXXRecordDecl *Record = nullptr;
+  ClassTemplateDecl *Template = nullptr;
+  NamespaceDecl *HLSLNamespace = nullptr;
+
+  BuiltinTypeDeclBuilder(CXXRecordDecl *R) : Record(R) {
+Record->startDefinition();
+   

[clang] 76e951e - [Docs] Fix column ordering on clang attribute docs

2022-07-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-27T21:36:43-05:00
New Revision: 76e951e80307d26da260a73d8209417d9bb5e9f9

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

LOG: [Docs] Fix column ordering on clang attribute docs

This patch just adjusts the ordering of the headings on the attribute
docs to match the order of the column content.

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 9d1ec9bd9d869..e5ab1129d1790 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4633,10 +4633,12 @@ static void WriteDocumentation(RecordKeeper &Records,
   OS << Doc.Heading << "\n" << std::string(Doc.Heading.length(), '-') << "\n";
 
   // List what spelling syntaxes the attribute supports.
+  // Note: "#pragma clang attribute" is handled outside the spelling kinds loop
+  // so it must be last.
   OS << ".. csv-table:: Supported Syntaxes\n";
   OS << "   :header: \"GNU\", \"C++11\", \"C2x\", \"``__declspec``\",";
-  OS << " \"Keyword\", \"``#pragma``\", \"``#pragma clang attribute``\",";
-  OS << " \"HLSL Semantic\"\n\n   \"";
+  OS << " \"Keyword\", \"``#pragma``\", \"HLSL Semantic\", \"``#pragma clang ";
+  OS << "attribute``\"\n\n   \"";
   for (size_t Kind = 0; Kind != NumSpellingKinds; ++Kind) {
 SpellingKind K = (SpellingKind)Kind;
 // TODO: List Microsoft (IDL-style attribute) spellings once we fully



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


[clang] a6e63e3 - [NFC][HLSL] Add tests for vector alias. Remove dead code.

2022-07-05 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-05T16:32:59-05:00
New Revision: a6e63e35ede4b9f23b58437263eaac9a2926c9bf

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

LOG: [NFC][HLSL] Add tests for vector alias. Remove dead code.

Based on feedback from @Aaron.Ballman.

Remove the unused static ID char (can re-add it later if needed).

Add test to cover some invalid HLSL vector instantations ensuring
that the appropriate error messages are generated.

Added: 
clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl

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 92154427a3e72..439fc3d10f333 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -19,8 +19,6 @@ class NamespaceDecl;
 class Sema;
 
 class HLSLExternalSemaSource : public ExternalSemaSource {
-  static char ID;
-
   Sema *SemaPtr = nullptr;
   NamespaceDecl *HLSLNamespace;
 

diff  --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 2de90378baf90..56c2dd40bd9a8 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -17,8 +17,6 @@
 
 using namespace clang;
 
-char HLSLExternalSemaSource::ID;
-
 HLSLExternalSemaSource::~HLSLExternalSemaSource() {}
 
 void HLSLExternalSemaSource::InitializeSema(Sema &S) {

diff  --git a/clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl
new file mode 100644
index 0..d2598a57400b0
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/vector-errors.hlsl
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl 
-fsyntax-only -verify %s
+
+// Some bad declarations
+hlsl::vector ShouldWorkSomeday; // expected-error{{use of alias template 
'hlsl::vector' requires template arguments}}
+
+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}}
+
+
+hlsl::vector AnotherBadVec; // expected-error{{template argument 
for non-type template parameter must be an expression}}
+// expected-note@*:* {{template parameter is declared here}}
+
+hlsl::vector YABV; // expected-error{{too many template arguments 
for alias template 'vector'}}
+// expected-note@*:* {{template is declared here}}
+
+// This code is rejected by clang because clang puts the HLSL built-in types
+// into the HLSL namespace.
+namespace hlsl {
+  struct vector {}; // expected-error {{redefinition of 'vector'}}
+}
+
+// This code is rejected by dxc because dxc puts the HLSL built-in types
+// into the global space, but clang will allow it even though it will shadow 
the
+// vector template.
+struct vector {}; // expected-note {{candidate found by name lookup is 
'vector'}}
+
+vector VecInt2; // expected-error {{reference to 'vector' is ambiguous}}
+
+// expected-note@*:* {{candidate found by name lookup is 'hlsl::vector'}}



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


[clang] b8dbc6f - [HLSL] Add ExternalSemaSource & vector alias

2022-07-05 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-07-05T11:30:29-05:00
New Revision: b8dbc6ffea93976dc0d8569c9d23e9c21e33e317

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

LOG: [HLSL] Add ExternalSemaSource & vector alias

HLSL vector types are ext_vector types, but they are also exposed via a
template syntax `vector`. This is morally equavalent to the code:

```c++
template 
using vector = T __attribute__((ext_vector_type(Size)))
```

The problem is that templates aren't supported before HLSL 2021, and
type aliases still aren't supported in HLSL.

To resolve this (and other issues where HLSL can't represent its own
types), we rely on an external AST & Sema source being registered for
HLSL code.

This patch adds the HLSLExternalSemaSource and registers the vector
type alias.

Depends on D127802

Differential Revision: https://reviews.llvm.org/D128012

Added: 
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/vector-alias.hlsl

Modified: 
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Sema/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
new file mode 100644
index 0..92154427a3e72
--- /dev/null
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -0,0 +1,43 @@
+//===--- HLSLExternalSemaSource.h - HLSL Sema Source *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines the HLSLExternalSemaSource interface.
+//
+//===--===//
+#ifndef CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
+#define CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
+
+#include "clang/Sema/ExternalSemaSource.h"
+
+namespace clang {
+class NamespaceDecl;
+class Sema;
+
+class HLSLExternalSemaSource : public ExternalSemaSource {
+  static char ID;
+
+  Sema *SemaPtr = nullptr;
+  NamespaceDecl *HLSLNamespace;
+
+  void defineHLSLVectorAlias();
+
+public:
+  ~HLSLExternalSemaSource() override;
+
+  /// Initialize the semantic source with the Sema instance
+  /// being used to perform semantic analysis on the abstract syntax
+  /// tree.
+  void InitializeSema(Sema &S) override;
+
+  /// Inform the semantic consumer that Sema is no longer available.
+  void ForgetSema() override { SemaPtr = nullptr; }
+};
+
+} // namespace clang
+
+#endif // CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 65160dd7e0b18..81915e6330b03 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -24,6 +24,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Parse/ParseAST.h"
+#include "clang/Sema/HLSLExternalSemaSource.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
@@ -1014,6 +1015,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance 
&CI,
 CI.getASTContext().setExternalSource(Override);
   }
 
+  // Setup HLSL External Sema Source
+  if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
+IntrusiveRefCntPtr HLSLSema(
+new HLSLExternalSemaSource());
+CI.getASTContext().setExternalSource(HLSLSema);
+  }
+
   FailureCleanup.release();
   return true;
 }

diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index 2069990f5c06c..e68715f1a6a45 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -27,38 +27,38 @@ typedef long int64_t;
 // built-in vector data types:
 
 #ifdef __HLSL_ENABLE_16_BIT
-typedef int16_t int16_t2 __attribute__((ext_vector_type(2)));
-typedef int16_t int16_t3 __attribute__((ext_vector_type(3)));
-typedef int16_t int16_t4 __attribute__((ext_vector_type(4)));
-typedef uint16_t uint16_t2 __attribute__((ext_vector_type(2)));
-typedef uint16_t uint16_t3 __attribute__((ext_vector_type(3)));
-typedef uint16_t uint16_t4 __attribute__((ext_vector_type(4)));
+typedef vector int16_t2;
+typedef vector int16_t3;
+typedef vector int16_t4;
+typedef vector uint16_t2;
+typedef vector uint16_t3;
+typedef vector uint16_t4;
 #endif
 
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ex

[clang] ee0dd2e - [Docs] Update clang & llvm release notes for HLSL

2022-06-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-06-27T12:41:14-05:00
New Revision: ee0dd2ec112b3fa727f199709a0d8992eaa13b3b

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

LOG: [Docs] Update clang & llvm release notes for HLSL

Adding release note entries for LLVM & Clang to introduce the HLSL &
DirectX support that is being added.

Reviewed By: aaron.ballman, MaskRay

Differential Revision: https://reviews.llvm.org/D127890

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f551a6fecd778..efc91ca29d1aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -72,6 +72,11 @@ Major New Features
   array bounds lead to flexible array members. The option yields more accurate
   ``__builtin_object_size`` and ``__builtin_dynamic_object_size`` results in
   most cases but may be overly conservative for some legacy code.
+- Experimental support for HLSL has been added. The implementation is
+  incomplete and highly experimental. For more information about the ongoing
+  work to support HLSL see the `documentation
+  `_, or the `GitHub project
+  `_.
 
 Bug Fixes
 -

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 85ad07113c886..1e9dc99b90742 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -113,6 +113,16 @@ Changes to the AVR Backend
 
 * ...
 
+Changes to the DirectX Backend
+--
+
+* DirectX has been added as an experimental target. Specify
+  ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=DirectX`` in your CMake configuration
+  to enable it. The target is not packaged in pre-built binaries.
+* The DirectX backend supports the ``dxil`` architecture which is based on LLVM
+  3.6 IR encoded as bitcode and is the format used for DirectX GPU Shader
+  programs.
+
 Changes to the Hexagon Backend
 --
 



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


[clang] 9f499d9 - [HLSL] Support HLSL vector initializers

2022-06-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-06-21T12:33:42-05:00
New Revision: 9f499d9d73edfc818978c64eb24b8d2d34995d76

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

LOG: [HLSL] Support HLSL vector initializers

In HLSL vectors are ext_vectors in all respects except that they
support a constructor style syntax for initializing vectors. This
change adds a translation of vector constructor arguments into
initializer lists.

This supports two oddities of HLSL syntax:
(1) HLSL vectors support constructor syntax
(2) HLSL vectors are expanded to constituate components in constructors

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D127802

Added: 
clang/test/AST/HLSL/vector-constructors.hlsl
clang/test/SemaHLSL/BuiltIns/vector-constructors-erros.hlsl

Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c7e068046d7fd..f4cd45ad6c922 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1696,7 +1696,7 @@ void InitListChecker::CheckVectorType(const 
InitializedEntity &Entity,
 return;
   }
 
-  if (!SemaRef.getLangOpts().OpenCL) {
+  if (!SemaRef.getLangOpts().OpenCL && !SemaRef.getLangOpts().HLSL ) {
 // If the initializing element is a vector, try to copy-initialize
 // instead of breaking it apart (which is doomed to failure anyway).
 Expr *Init = IList->getInit(Index);
@@ -1790,7 +1790,7 @@ void InitListChecker::CheckVectorType(const 
InitializedEntity &Entity,
   InitializedEntity ElementEntity =
 InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
 
-  // OpenCL initializers allows vectors to be constructed from vectors.
+  // OpenCL and HLSL initializers allow vectors to be constructed from vectors.
   for (unsigned i = 0; i < maxElements; ++i) {
 // Don't attempt to go past the end of the init list
 if (Index >= IList->getNumInits())
@@ -1819,7 +1819,7 @@ void InitListChecker::CheckVectorType(const 
InitializedEntity &Entity,
 }
   }
 
-  // OpenCL requires all elements to be initialized.
+  // OpenCL and HLSL require all elements to be initialized.
   if (numEltsInit != maxElements) {
 if (!VerifyOnly)
   SemaRef.Diag(IList->getBeginLoc(),
@@ -5969,6 +5969,37 @@ void InitializationSequence::InitializeFrom(Sema &S,
 
   assert(Args.size() >= 1 && "Zero-argument case handled above");
 
+  // For HLSL ext vector types we allow list initialization behavior for C++
+  // constructor syntax. This is accomplished by converting initialization
+  // arguments an InitListExpr late.
+  if (S.getLangOpts().HLSL && DestType->isExtVectorType() &&
+  (SourceType.isNull() ||
+   !Context.hasSameUnqualifiedType(SourceType, DestType))) {
+
+llvm::SmallVector InitArgs;
+for (auto Arg : Args) {
+  if (Arg->getType()->isExtVectorType()) {
+const auto *VTy = Arg->getType()->castAs();
+unsigned Elm = VTy->getNumElements();
+for (unsigned Idx = 0; Idx < Elm; ++Idx) {
+  InitArgs.emplace_back(new (Context) ArraySubscriptExpr(
+  Arg,
+  IntegerLiteral::Create(
+  Context, llvm::APInt(Context.getIntWidth(Context.IntTy), 
Idx),
+  Context.IntTy, SourceLocation()),
+  VTy->getElementType(), Arg->getValueKind(), Arg->getObjectKind(),
+  SourceLocation()));
+}
+  } else
+InitArgs.emplace_back(Arg);
+}
+InitListExpr *ILE = new (Context) InitListExpr(
+S.getASTContext(), SourceLocation(), InitArgs, SourceLocation());
+Args[0] = ILE;
+AddListInitializationStep(DestType);
+return;
+  }
+
   // The remaining cases all need a source type.
   if (Args.size() > 1) {
 SetFailed(FK_TooManyInitsForScalar);
@@ -8129,6 +8160,11 @@ ExprResult InitializationSequence::Perform(Sema &S,
   ExprResult CurInit((Expr *)nullptr);
   SmallVector ArrayLoopCommonExprs;
 
+  // HLSL allows vector initialization to function like list initialization, 
but
+  // use the syntax of a C++-like constructor.
+  bool IsHLSLVectorInit = S.getLangOpts().HLSL && DestType->isExtVectorType() 
&&
+  isa(Args[0]);
+
   // For initialization steps that start with a single initializer,
   // grab the only argument out the Args and place it into the "current"
   // initializer.
@@ -8166,7 +8202,7 @@ ExprResult InitializationSequence::Perform(Sema &S,
   case SK_StdInitializerList:
   case SK_OCLSamplerInit:
   case SK_OCLZeroOpaqueType: {
-assert(Args.size() == 1);
+assert(Args.size() == 1 || IsHLSLVectorInit);
 CurInit = Args[0];
 if (!CurInit.get()) return ExprError();
 break;

diff  --git a/clang/test/AST/HLSL/vector-constructors.hlsl 
b/clang

[clang] f9e4964 - Revert "wip"

2022-06-17 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-06-17T13:36:53-05:00
New Revision: f9e49644f4875ba1807781b1224b3136fefe38e9

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

LOG: Revert "wip"

This reverts commit 0dd243fa8a4ec98d6cabbad16e6b485a093c6dea.

I accidentally pushed this! Oops!

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Sema/CMakeLists.txt

Removed: 
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/SemaHLSL/BuiltIns/vectors.hlsl



diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
deleted file mode 100644
index 23dd02ef611e3..0
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ /dev/null
@@ -1,45 +0,0 @@
-//===--- HLSLExternalSemaSource.h - HLSL Sema Source *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-//  This file defines the HLSLExternalSemaSource interface.
-//
-//===--===//
-#ifndef CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
-#define CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
-
-#include "clang/Sema/ExternalSemaSource.h"
-
-namespace clang {
-class NamespaceDecl;
-class Sema;
-
-class HLSLExternalSemaSource : public ExternalSemaSource {
-  static char ID;
-
-  Sema *SemaPtr = nullptr;
-  NamespaceDecl *HLSLNamespace;
-
-  void defineHLSLVectorAlias();
-public:
-  ~HLSLExternalSemaSource() override;
-
-  /// Initialize the semantic source with the Sema instance
-  /// being used to perform semantic analysis on the abstract syntax
-  /// tree.
-  void InitializeSema(Sema &S) override;
-
-  /// Inform the semantic consumer that Sema is no longer available.
-  void ForgetSema() override {
-SemaPtr = nullptr;
-  }
-
-};
-
-} // namespace clang
-
-#endif // CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 4a141e6200030..6b1f6364b13c3 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -24,7 +24,6 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Parse/ParseAST.h"
-#include "clang/Sema/HLSLExternalSemaSource.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
@@ -1015,13 +1014,6 @@ bool FrontendAction::BeginSourceFile(CompilerInstance 
&CI,
 CI.getASTContext().setExternalSource(Override);
   }
 
-  // Setup HLSL External Sema Source
-  if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
-IntrusiveRefCntPtr HLSLSema(
-new HLSLExternalSemaSource());
-CI.getASTContext().setExternalSource(HLSLSema);
-  }
-
   FailureCleanup.release();
   return true;
 }

diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e68715f1a6a45..2069990f5c06c 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -27,38 +27,38 @@ typedef long int64_t;
 // built-in vector data types:
 
 #ifdef __HLSL_ENABLE_16_BIT
-typedef vector int16_t2;
-typedef vector int16_t3;
-typedef vector int16_t4;
-typedef vector uint16_t2;
-typedef vector uint16_t3;
-typedef vector uint16_t4;
+typedef int16_t int16_t2 __attribute__((ext_vector_type(2)));
+typedef int16_t int16_t3 __attribute__((ext_vector_type(3)));
+typedef int16_t int16_t4 __attribute__((ext_vector_type(4)));
+typedef uint16_t uint16_t2 __attribute__((ext_vector_type(2)));
+typedef uint16_t uint16_t3 __attribute__((ext_vector_type(3)));
+typedef uint16_t uint16_t4 __attribute__((ext_vector_type(4)));
 #endif
 
-typedef vector int2;
-typedef vector int3;
-typedef vector int4;
-typedef vector uint2;
-typedef vector uint3;
-typedef vector uint4;
-typedef vector int64_t2;
-typedef vector int64_t3;
-typedef vector int64_t4;
-typedef vector uint64_t2;
-typedef vector uint64_t3;
-typedef vector uint64_t4;
+typedef int int2 __attribute__((ext_vector_type(2)));
+typedef int int3 __attribute__((ext_vector_type(3)));
+typedef int int4 __attribute__((ext_vector_type(4)));
+typedef uint uint2 __attribute__((ext_vector_type(2)));
+typedef uint uint3 __attribute__((ext_vector_type(3)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
+typedef int64_t int64_t2 __attribute__((ext_vector_type(2)));
+typedef in

[clang] 0dd243f - wip

2022-06-17 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-06-17T13:34:21-05:00
New Revision: 0dd243fa8a4ec98d6cabbad16e6b485a093c6dea

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

LOG: wip

Added: 
clang/include/clang/Sema/HLSLExternalSemaSource.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/SemaHLSL/BuiltIns/vectors.hlsl

Modified: 
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Headers/hlsl/hlsl_basic_types.h
clang/lib/Sema/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
new file mode 100644
index 0..23dd02ef611e3
--- /dev/null
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -0,0 +1,45 @@
+//===--- HLSLExternalSemaSource.h - HLSL Sema Source *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines the HLSLExternalSemaSource interface.
+//
+//===--===//
+#ifndef CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
+#define CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H
+
+#include "clang/Sema/ExternalSemaSource.h"
+
+namespace clang {
+class NamespaceDecl;
+class Sema;
+
+class HLSLExternalSemaSource : public ExternalSemaSource {
+  static char ID;
+
+  Sema *SemaPtr = nullptr;
+  NamespaceDecl *HLSLNamespace;
+
+  void defineHLSLVectorAlias();
+public:
+  ~HLSLExternalSemaSource() override;
+
+  /// Initialize the semantic source with the Sema instance
+  /// being used to perform semantic analysis on the abstract syntax
+  /// tree.
+  void InitializeSema(Sema &S) override;
+
+  /// Inform the semantic consumer that Sema is no longer available.
+  void ForgetSema() override {
+SemaPtr = nullptr;
+  }
+
+};
+
+} // namespace clang
+
+#endif // CLANG_SEMA_HLSLEXTERNALSEMASOURCE_H

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 6b1f6364b13c3..4a141e6200030 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -24,6 +24,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Parse/ParseAST.h"
+#include "clang/Sema/HLSLExternalSemaSource.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
@@ -1014,6 +1015,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance 
&CI,
 CI.getASTContext().setExternalSource(Override);
   }
 
+  // Setup HLSL External Sema Source
+  if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
+IntrusiveRefCntPtr HLSLSema(
+new HLSLExternalSemaSource());
+CI.getASTContext().setExternalSource(HLSLSema);
+  }
+
   FailureCleanup.release();
   return true;
 }

diff  --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index 2069990f5c06c..e68715f1a6a45 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -27,38 +27,38 @@ typedef long int64_t;
 // built-in vector data types:
 
 #ifdef __HLSL_ENABLE_16_BIT
-typedef int16_t int16_t2 __attribute__((ext_vector_type(2)));
-typedef int16_t int16_t3 __attribute__((ext_vector_type(3)));
-typedef int16_t int16_t4 __attribute__((ext_vector_type(4)));
-typedef uint16_t uint16_t2 __attribute__((ext_vector_type(2)));
-typedef uint16_t uint16_t3 __attribute__((ext_vector_type(3)));
-typedef uint16_t uint16_t4 __attribute__((ext_vector_type(4)));
+typedef vector int16_t2;
+typedef vector int16_t3;
+typedef vector int16_t4;
+typedef vector uint16_t2;
+typedef vector uint16_t3;
+typedef vector uint16_t4;
 #endif
 
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef uint uint2 __attribute__((ext_vector_type(2)));
-typedef uint uint3 __attribute__((ext_vector_type(3)));
-typedef uint uint4 __attribute__((ext_vector_type(4)));
-typedef int64_t int64_t2 __attribute__((ext_vector_type(2)));
-typedef int64_t int64_t3 __attribute__((ext_vector_type(3)));
-typedef int64_t int64_t4 __attribute__((ext_vector_type(4)));
-typedef uint64_t uint64_t2 __attribute__((ext_vector_type(2)));
-typedef uint64_t uint64_t3 __attribute__((ext_vector_type(3)));
-typedef uint64_t uint64_t4 __attribute__((ext_vector_type(4)));
+typedef vector int2;
+typedef vector int3;
+typedef vector int4;
+typedef vector uint2;
+typed

[clang] 0d6b574 - [HLSL] Adjust access specifier behavior

2022-04-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-28T10:37:50-05:00
New Revision: 0d6b574b8717a44cda565baa756875f762fa60b9

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

LOG: [HLSL] Adjust access specifier behavior

HLSL doesn't support access specifiers. This change has two components:

1) Make default access for classes public
2) Diagnose the use of access specifiers as a clang HLSL extension

As long as the default behavior for access specifiers matches HLSL,
allowing them to be used doesn't cause sourece incompatability with
valid code. As such enabling them as a clang extension seems like a
reasonable approach.

Fixes #55124

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124487

Added: 
clang/test/ParserHLSL/access_specifiers.hlsl

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 5a9fe8673a044..e6f62801d7adb 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1362,3 +1362,6 @@ def PedanticMacros : DiagGroup<"pedantic-macros",
 
 def BranchProtection : DiagGroup<"branch-protection">;
 
+// HLSL diagnostic groups
+// Warnings for HLSL Clang extensions
+def HLSLExtension : DiagGroup<"hlsl-extensions">;

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index d8d78dfa0befa..bd74674325fbe 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1599,5 +1599,8 @@ def note_max_tokens_total_override : Note<"total token 
limit set here">;
 def err_expected_semantic_identifier : Error<
   "expected HLSL Semantic identifier">;
 def err_unknown_hlsl_semantic : Error<"unknown HLSL semantic %0">;
+def ext_hlsl_access_specifiers : ExtWarn<
+  "access specifiers are a clang HLSL extension">,
+  InGroup;
 
 } // end of Parser diagnostics

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 9cf9f7cc4c371..22ad9e030b0d8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2170,8 +2170,11 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
 
   // Parse an (optional) access specifier.
   AccessSpecifier Access = getAccessSpecifierIfPresent();
-  if (Access != AS_none)
+  if (Access != AS_none) {
 ConsumeToken();
+if (getLangOpts().HLSL)
+  Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
+  }
 
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
@@ -3270,6 +3273,8 @@ Parser::DeclGroupPtrTy 
Parser::ParseCXXClassMemberDeclarationWithPragmas(
 LLVM_FALLTHROUGH;
   case tok::kw_public:
   case tok::kw_protected: {
+if (getLangOpts().HLSL)
+  Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
 AccessSpecifier NewAS = getAccessSpecifierIfPresent();
 assert(NewAS != AS_none);
 // Current token is a C++ access specifier.
@@ -3509,8 +3514,9 @@ void Parser::ParseCXXMemberSpecification(SourceLocation 
RecordLoc,
   // C++ 11p3: Members of a class defined with the keyword class are private
   // by default. Members of a class defined with the keywords struct or union
   // are public by default.
+  // HLSL: In HLSL members of a class are public by default.
   AccessSpecifier CurAS;
-  if (TagType == DeclSpec::TST_class)
+  if (TagType == DeclSpec::TST_class && !getLangOpts().HLSL)
 CurAS = AS_private;
   else
 CurAS = AS_public;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4467f2357189e..b45e8e396b31a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2501,6 +2501,11 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class,
  bool Virtual, AccessSpecifier Access,
  TypeSourceInfo *TInfo,
  SourceLocation EllipsisLoc) {
+  // In HLSL, unspecified class access is public rather than private.
+  if (getLangOpts().HLSL && Class->getTagKind() == TTK_Class &&
+  Access == AS_none)
+Access = AS_public;
+
   QualType BaseType = TInfo->getType();
   if (BaseType->containsErrors()) {
 // Already emitted a diagnostic when parsing the error type.

diff  --git a/clang/test/ParserHLSL/access_specifiers.hlsl 
b/clang/test/ParserHLSL/access_specifiers.hlsl
new file mode 100644
index 0..1bfef3c44d773
--- /dev/null
+++ b/clang/test/ParserHLSL/access_specifiers.hlsl
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hls

[clang] 5e096ce - Update PGO and 3-stage cache files

2022-04-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-27T14:41:56-05:00
New Revision: 5e096ce6c84fe80a15158dd10d3a23fb7135aa6d

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

LOG: Update PGO and 3-stage cache files

These files are out of date and haven't been updated to work within the
monorepo. This change updates them appropriately so that they build
using the monorepo build infrastructure.

Added: 


Modified: 
clang/cmake/caches/3-stage-base.cmake
clang/cmake/caches/PGO-stage2.cmake
clang/cmake/caches/PGO.cmake

Removed: 




diff  --git a/clang/cmake/caches/3-stage-base.cmake 
b/clang/cmake/caches/3-stage-base.cmake
index 31391aa4defce..63a1c21528dc9 100644
--- a/clang/cmake/caches/3-stage-base.cmake
+++ b/clang/cmake/caches/3-stage-base.cmake
@@ -1,6 +1,8 @@
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
-set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")
+
+set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
 
 if(APPLE)
   # Use LLD to have fewer requirements on system linker, unless we're on an 
apple

diff  --git a/clang/cmake/caches/PGO-stage2.cmake 
b/clang/cmake/caches/PGO-stage2.cmake
index 2080cd405f2a6..b9b2f62e9cae4 100644
--- a/clang/cmake/caches/PGO-stage2.cmake
+++ b/clang/cmake/caches/PGO-stage2.cmake
@@ -1,2 +1,3 @@
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
-set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")
+set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")

diff  --git a/clang/cmake/caches/PGO.cmake b/clang/cmake/caches/PGO.cmake
index 7e4a001129cb9..e1d0585e453f8 100644
--- a/clang/cmake/caches/PGO.cmake
+++ b/clang/cmake/caches/PGO.cmake
@@ -1,8 +1,10 @@
 set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
-set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "")
 
-set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
+set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
+
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED ON CACHE BOOL "")
 set(CLANG_BOOTSTRAP_TARGETS
   generate-profdata



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


[clang] 329abac - Blind stab in the dark to fix a bot failure

2022-04-15 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-15T20:12:59-05:00
New Revision: 329abac134a35acc81bfab30a87130a3c208be2a

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

LOG: Blind stab in the dark to fix a bot failure

*fingers crossed*

Added: 


Modified: 
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 3d9d266ef3161..a0823f3ba123a 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -375,9 +375,11 @@ TEST(DxcModeTest, TargetProfileValidation) {
   if (DiagLevel == DiagnosticsEngine::Level::Error) {
 Errors.emplace_back();
 Info.FormatDiagnostic(Errors.back());
+Errors.back() += '\0';
   } else {
 Msgs.emplace_back();
 Info.FormatDiagnostic(Msgs.back());
+Msgs.back() += '\0';
   }
 }
 void clear() override {



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


[clang] 721651b - [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Chris Bieneman via cfe-commits

Author: Xiang Li
Date: 2022-04-15T14:18:18-05:00
New Revision: 721651be246e26efd767c3ec55c8f06c7b5a9a3d

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

LOG: [HLSL][clang][Driver] Support target profile command line option.

The target profile option(/T) decide the shader model when compile hlsl.
The format is shaderKind_major_minor like ps_6_1.
The shader model is saved as llvm::Triple is clang/llvm like
dxil-unknown-shadermodel6.1-hull.
The main job to support the option is translating ps_6_1 into
shadermodel6.1-pixel.
That is done inside tryParseProfile  at HLSL.cpp.

To integrate the option into clang Driver, a new DriverMode DxcMode is
created. When DxcMode is enabled, OSType for TargetTriple will be
forced into Triple::ShaderModel. And new ToolChain HLSLToolChain will
be created when OSType is Triple::ShaderModel.

In HLSLToolChain, ComputeEffectiveClangTriple is overridden to call
tryParseProfile when targetProfile option is set.

To make test work, Fo option is added and .hlsl is added for active
-xhlsl.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D122865

Patch by: Xiang Li 

Added: 
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Driver/ToolChains/HLSL.h

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/Types.cpp
clang/test/lit.cfg.py
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 64af4c84672fe..cb53804d9e4f8 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -657,4 +657,7 @@ def warn_drv_fjmc_for_elf_only : Warning<
 def err_drv_target_variant_invalid : Error<
   "unsupported '%0' value '%1'; use 'ios-macabi' instead">;
 
+def err_drv_invalid_directx_shader_module : Error<
+  "invalid profile : %0">;
+
 }

diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 6f24f649ea544..b33b64cd9e6a2 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -68,7 +68,8 @@ class Driver {
 GXXMode,
 CPPMode,
 CLMode,
-FlangMode
+FlangMode,
+DXCMode
   } Mode;
 
   enum SaveTempsMode {
@@ -195,6 +196,9 @@ class Driver {
   /// Other modes fall back to calling gcc which in turn calls gfortran.
   bool IsFlangMode() const { return Mode == FlangMode; }
 
+  /// Whether the driver should follow dxc.exe like behavior.
+  bool IsDXCMode() const { return Mode == DXCMode; }
+
   /// Only print tool bindings, don't build any jobs.
   unsigned CCCPrintBindings : 1;
 

diff  --git a/clang/include/clang/Driver/Options.h 
b/clang/include/clang/Driver/Options.h
index 056660192ac5f..f9b9632ee7cbe 100644
--- a/clang/include/clang/Driver/Options.h
+++ b/clang/include/clang/Driver/Options.h
@@ -35,7 +35,8 @@ enum ClangFlags {
   FlangOption = (1 << 14),
   FC1Option = (1 << 15),
   FlangOnlyOption = (1 << 16),
-  Ignored = (1 << 17),
+  DXCOption = (1 << 17),
+  Ignored = (1 << 18),
 };
 
 enum ID {

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 104c8ea8483d1..f454bd038ecf8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -49,6 +49,10 @@ def CC1Option : OptionFlag;
 // CC1AsOption - This option should be accepted by clang -cc1as.
 def CC1AsOption : OptionFlag;
 
+// DXCOption - This is a dxc.exe compatibility option. Options with this flag
+// are made available when the driver is running in DXC compatibility mode.
+def DXCOption : OptionFlag;
+
 // NoDriverOption - This option should not be accepted by the driver.
 def NoDriverOption : OptionFlag;
 
@@ -6686,3 +6690,33 @@ def _SLASH_Ze : CLFlag<"Ze">;
 def _SLASH_Zg : CLFlag<"Zg">;
 def _SLASH_ZI : CLFlag<"ZI">;
 def _SLASH_ZW : CLJoined<"ZW">;
+
+//===--===//
+// clang-dxc Options
+//===--===//
+
+def dxc_Group : OptionGroup<"">, Flags<[DXCOption]>,
+  HelpText<"dxc compatibility options">;
+
+class DXCJoinedOrSeparate : Option<["/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
+
+def dxc_help : Option<["/", "-", "--"], "help", KIND_JOINED>,
+  Group, Flags<[DXCOption, NoXarchOption]>, Alias,
+  HelpText<"Display available options">;
+
+
+def Fo : DXCJoinedOrSeparate<"Fo">, Alias,
+ 

[clang] 3efad61 - [HLSL] Pointers are unsupported in HLSL

2022-04-14 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-14T13:32:51-05:00
New Revision: 3efad612d234f938d5012317cfb827e2bf8a1ee7

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

LOG: [HLSL] Pointers are unsupported in HLSL

HLSL does not support pointers or references. This change generates
errors in sema for generating pointer, and reference types as well as
common operators (address-of, dereference, arrow), which are used with
pointers and are unsupported in HLSL.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D123167

Added: 
clang/test/SemaHLSL/prohibit_pointer.hlsl
clang/test/SemaHLSL/prohibit_reference.hlsl

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ea3db40aad571..7ffd12317167e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11590,6 +11590,12 @@ def err_hlsl_numthreads_argument_oor : Error<"argument 
'%select{X|Y|Z}0' to numt
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
 def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not 
match the previous declaration">;
 
+def err_hlsl_pointers_unsupported : Error<
+  "%select{pointers|references}0 are unsupported in HLSL">;
+
+def err_hlsl_operator_unsupported : Error<
+  "the '%select{&|*|->}0' operator is unsupported in HLSL">;
+
 // Layout randomization warning.
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f210a8ba7aac2..db5ab0058843f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15369,6 +15369,13 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation 
OpLoc,
 }
   }
 
+  if (getLangOpts().HLSL) {
+if (Opc == UO_AddrOf)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
+if (Opc == UO_Deref)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
+  }
+
   switch (Opc) {
   case UO_PreInc:
   case UO_PreDec:

diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index cb95f70f445b6..d5e7a2c8e2968 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1736,6 +1736,9 @@ ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr 
*Base,
   DeclarationName Name = NameInfo.getName();
   bool IsArrow = (OpKind == tok::arrow);
 
+  if (getLangOpts().HLSL && IsArrow)
+return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 2);
+
   NamedDecl *FirstQualifierInScope
 = (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep()));
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 43ab9070aa9b9..a9cb5fd9474eb 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2143,6 +2143,11 @@ QualType Sema::BuildPointerType(QualType T,
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
+return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
 return QualType();
 
@@ -2208,6 +2213,11 @@ QualType Sema::BuildReferenceType(QualType T, bool 
SpelledAsLValue,
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 1;
+return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Reference))
 return QualType();
 
@@ -2967,6 +2977,11 @@ QualType Sema::BuildMemberPointerType(QualType T, 
QualType Class,
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
+return QualType();
+  }
+
   // Adjust the default free function calling convention to the default method
   // calling convention.
   bool IsCtorOrDtor =

diff  --git a/clang/test/SemaHLSL/prohibit_pointer.hlsl 
b/clang/test/SemaHLSL/prohibit_pointer.hlsl
new file mode 100644
index 0..4a328f6f15569
--- /dev/null
+++ b/clang/test/SemaHLSL/prohibit_pointer.hlsl
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - 
-fsyntax-only %s -verify
+
+// expected-error@+1 {{pointers are unsupported in HLSL}}
+typedef int (*fn_int)(int);
+void* bark(int); // expected-error {{pointers are unsupported in HLSL}}
+void meow(int*); // expected-error {{pointers are unsupported in HLSL}}
+
+struct Foo {
+  int X;
+  int Y;
+} *bad; // expected-e

[clang] 1fdf952 - [HLSL] Add Semantic syntax, and SV_GroupIndex

2022-04-14 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-14T10:21:58-05:00
New Revision: 1fdf952deeb9a02aa34794af3c1a7d13a30e068e

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

LOG: [HLSL] Add Semantic syntax, and SV_GroupIndex

HLSL has a language feature called Semantics which get attached to
declarations like attributes and are used in a variety of ways.

One example of semantic use is here with the `SV_GroupIndex` semantic
which, when applied to an input for a compute shader is pre-populated
by the driver with a flattened thread index.

Differential Revision: https://reviews.llvm.org/D122699

# Conflicts:
#   clang/include/clang/Basic/Attr.td
#   clang/include/clang/Basic/AttrDocs.td

Added: 
clang/lib/Parse/ParseHLSL.cpp
clang/test/ParserHLSL/lit.local.cfg
clang/test/ParserHLSL/semantic_parsing.hlsl
clang/test/SemaHLSL/Semantics/entry_parameter.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/AttributeCommonInfo.h
clang/include/clang/Basic/Attributes.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Parse/CMakeLists.txt
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dee9ede951745..727e6180b41b2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -300,6 +300,9 @@ class Clang : Spelling {
   bit AllowInC = allowInC;
 }
 
+// HLSL Semantic spellings
+class HLSLSemantic : Spelling;
+
 class Accessor spellings> {
   string Name = name;
   list Spellings = spellings;
@@ -3958,6 +3961,13 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
+def HLSLSV_GroupIndex: InheritableAttr {
+  let Spellings = [HLSLSemantic<"SV_GroupIndex">];
+  let Subjects = SubjectList<[ParmVar, GlobalVar]>;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLSV_GroupIndexDocs];
+}
+
 def RandomizeLayout : InheritableAttr {
   let Spellings = [GCC<"randomize_layout">];
   let Subjects = SubjectList<[Record]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6a8b2e600f949..cda143eeb1ca1 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6411,3 +6411,14 @@ instructs the compiler that this structure should not 
have its field layout
 randomized.
   }];
 }
+
+def HLSLSV_GroupIndexDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``SV_GroupIndex`` semantic, when applied to an input parameter, specifies a
+data binding to map the group index to the specified parameter. This attribute
+is only supported in compute shaders.
+
+The full documentation is available here: 
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupindex
+  }];
+}

diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 4be598e109fd8..478b9df371209 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -48,6 +48,9 @@ class AttributeCommonInfo {
 // without adding related code to TableGen/ClangAttrEmitter.cpp.
 /// Context-sensitive version of a keyword attribute.
 AS_ContextSensitiveKeyword,
+
+///  : 
+AS_HLSLSemantic,
   };
   enum Kind {
 #define PARSED_ATTR(NAME) AT_##NAME,

diff  --git a/clang/include/clang/Basic/Attributes.h 
b/clang/include/clang/Basic/Attributes.h
index c69633decd572..4afb6a1b9ca25 100644
--- a/clang/include/clang/Basic/Attributes.h
+++ b/clang/include/clang/Basic/Attributes.h
@@ -28,7 +28,9 @@ enum class AttrSyntax {
   // Is the identifier known as a C-style attribute?
   C,
   // Is the identifier known as a pragma attribute?
-  Pragma
+  Pragma,
+  // Is the identifier known as a HLSL semantic?
+  HLSLSemantic,
 };
 
 /// Return the version number associated with the attribute if we

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 1640a75391831..d8d78dfa0befa 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1594,4 +1594,10 @@ def warn_max_tokens_total : Warning<
 
 def note_max_tokens_total_override : Note<"total token limit set here">;
 
+// HLSL Parser Diagnostics
+
+def err_expected_semantic_identifier : Error<
+  "expected HLSL Semantic identifier">;
+def err_unknown_hlsl_semantic : Error<"unknown HLSL semantic %0">;
+
 } // end of Parser diagnostics

diff  --git a/clang/include/clang/Parse/Pa

[clang] b870620 - [NFC] Add CMake cache file for HLSL

2022-04-13 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-13T11:28:18-05:00
New Revision: b870620c29814b71b0c9788f17f8054f04ae2d40

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

LOG: [NFC] Add CMake cache file for HLSL

This just adds a trivial CMake cache file (which will grow over time)
to handle the common build configuration for the HLSL compiler.

Added: 
clang/cmake/caches/HLSL.cmake

Modified: 


Removed: 




diff  --git a/clang/cmake/caches/HLSL.cmake b/clang/cmake/caches/HLSL.cmake
new file mode 100644
index 0..e2d02b6b281a3
--- /dev/null
+++ b/clang/cmake/caches/HLSL.cmake
@@ -0,0 +1,11 @@
+# Including the native target is important because some of LLVM's tests fail if
+# you don't.
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# Include the DirectX target for DXIL code generation, eventually we'll include
+# SPIR-V here too.
+set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD DirectX CACHE STRING "")
+
+# HLSL support is currently limted to clang, eventually it will expand to
+# clang-tools-extra too.
+set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")



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


[clang] 9e3678e - [Clang] [Docs] Add HLSLSupport page

2022-04-08 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-08T12:17:45-05:00
New Revision: 9e3678e161553f29df1408f1b7c7ffc14fc0ef17

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

LOG: [Clang] [Docs] Add HLSLSupport page

This document is a first-stab at addressing some of the questions about
HLSL support in Clang.

Differential Revision: https://reviews.llvm.org/D123278

Added: 
clang/docs/HLSLSupport.rst

Modified: 
clang/docs/index.rst

Removed: 




diff  --git a/clang/docs/HLSLSupport.rst b/clang/docs/HLSLSupport.rst
new file mode 100644
index 0..a8c9c09b2e9f8
--- /dev/null
+++ b/clang/docs/HLSLSupport.rst
@@ -0,0 +1,240 @@
+
+HLSL Support
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL Support is under active development in the Clang codebase. This document
+describes the high level goals of the project, the guiding principles, as well
+as some idiosyncrasies of the HLSL language and how we intend to support them 
in
+Clang.
+
+Project Goals
+=
+
+The long term goal of this project is to enable Clang to function as a
+replacement for the `DirectXShaderCompiler (DXC)
+`_ in all its supported
+use cases. Accomplishing that goal will require Clang to be able to process 
most
+existing HLSL programs with a high degree of source compatibility.
+
+Non-Goals
+-
+
+HLSL ASTs do not need to be compatible between DXC and Clang. We do not expect
+identical code generation or that features will resemble DXC's implementation 
or
+architecture. In fact, we explicitly expect to deviate from DXC's 
implementation
+in key ways.
+
+Guiding Principles
+==
+
+This document lacks details for architectural decisions that are not yet
+finalized. Our top priorities are quality, maintainability, and flexibility. In
+accordance with community standards we are expecting a high level of test
+coverage, and we will engineer our solutions with long term maintenance in 
mind.
+We are also working to limit modifications to the Clang C++ code paths and
+share as much functionality as possible.
+
+Architectural Direction
+===
+
+HLSL support in Clang is expressed as C++ minus unsupported C and C++ features.
+This is 
diff erent from how other Clang languages are implemented. Most languages
+in Clang are additive on top of C.
+
+HLSL is not a formally or fully specified language, and while our goals require
+a high level of source compatibility, implementations can vary and we have some
+flexibility to be more or less permissive in some cases. For modern HLSL DXC is
+the reference implementation.
+
+The HLSL effort prioritizes following similar patterns for other languages,
+drivers, runtimes and targets. Specifically, We will maintain separation 
between
+HSLS-specific code and the rest of Clang as much as possible following patterns
+in use in Clang code today (i.e. ParseHLSL.cpp, SemaHLSL.cpp, CGHLSL*.cpp...).
+We will use inline checks on language options where the code is simple and
+isolated, and prefer HLSL-specific implementation files for any code of
+reasonable complexity.
+
+In places where the HLSL language is in conflict with C and C++, we will seek 
to
+make minimally invasive changes guarded under the HLSL language options. We 
will
+seek to make HLSL language support as minimal a maintenance burden as possible.
+
+DXC Driver
+--
+
+A DXC driver mode will provide command-line compatibility with DXC, supporting
+DXC's options and flags. The DXC driver is HLSL-specific and will create an
+HLSLToolchain which will provide the basis to support targeting both DirectX 
and
+Vulkan.
+
+Parser
+--
+
+Following the examples of other parser extensions HLSL will add a ParseHLSL.cpp
+file to contain the implementations of HLSL-specific extensions to the Clang
+parser. The HLSL grammar shares most of its structure with C and C++, so we 
will
+use the existing C/C++ parsing code paths.
+
+Sema
+
+
+HLSL's Sema implementation will also provide an ``ExternalSemaSource``. In DXC,
+an ``ExternalSemaSource`` is used to provide definitions for HLSL built-in data
+types and built-in templates. Clang is already designed to allow an attached
+``ExternalSemaSource`` to lazily complete data types, which is a **huge**
+performance win for HLSL.
+
+CodeGen
+---
+
+Like OpenCL, HLSL relies on capturing a lot of information into IR metadata.
+*hand wave* *hand wave* *hand wave* As a design principle here we want our IR 
to
+be idiomatic Clang IR as much as possible. We will use IR attributes wherever 
we
+can, and use metadata as sparingly as possible. One example of a 
diff erence from
+DXC already implemented in Clang is the use of target triples to commu

[clang] 1905416 - [HLSL] Further improve to numthreads diagnostics

2022-03-31 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-31T11:34:01-05:00
New Revision: 19054163e11a6632b4973c936e5aa93ec742c866

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

LOG: [HLSL] Further improve to numthreads diagnostics

This adds diagnostics for conflicting attributes on the same
declarataion, conflicting attributes on a forward and final
declaration, and defines a more narrowly scoped HLSLEntry attribute
target.

Big shout out to @aaron.ballman for the great feedback and review on
this!

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaHLSL/num_threads.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 97b1027742f60..4789493399ec2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -126,8 +126,10 @@ def FunctionTmpl
  FunctionDecl::TK_FunctionTemplate}],
 "function templates">;
 
-def GlobalFunction
-: SubsetSubjectisGlobal()}], "global functions">;
+def HLSLEntry
+: SubsetSubjectisExternallyVisible() && !isa(S)}],
+"global functions">;
 
 def ClassTmpl : SubsetSubjectgetDescribedClassTemplate()}],
   "class templates">;
@@ -3946,7 +3948,7 @@ def Error : InheritableAttr {
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
-  let Subjects = SubjectList<[GlobalFunction]>;
+  let Subjects = SubjectList<[HLSLEntry]>;
   let LangOpts = [HLSL];
   let Documentation = [NumThreadsDocs];
 }

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a272cb741270f..aec172c39ed9a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11570,6 +11570,7 @@ def err_hlsl_attr_unsupported_in_stage : 
Error<"attribute %0 is unsupported in %
 
 def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;
 def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
+def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not 
match the previous declaration">;
 
 } // end of sema component.
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6523c3001c294..c0ad55d52bb31 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3471,6 +3471,9 @@ class Sema final {
   EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D,
   const EnforceTCBLeafAttr &AL);
   BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL);
+  HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D,
+  const AttributeCommonInfo &AL,
+  int X, int Y, int Z);
 
   void mergeDeclAttributes(NamedDecl *New, Decl *Old,
AvailabilityMergeKind AMK = AMK_Redeclaration);

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b913f805bc877..1e25346fde6f6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2770,6 +2770,9 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
 NewAttr = S.mergeEnforceTCBLeafAttr(D, *TCBLA);
   else if (const auto *BTFA = dyn_cast(Attr))
 NewAttr = S.mergeBTFDeclTagAttr(D, *BTFA);
+  else if (const auto *NT = dyn_cast(Attr))
+NewAttr =
+S.mergeHLSLNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), NT->getZ());
   else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))
 NewAttr = cast(Attr->clone(S.Context));
 

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87e16635f3021..4b5201db7517c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6892,7 +6892,22 @@ static void handleHLSLNumThreadsAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 return;
   }
 
-  D->addAttr(::new (S.Context) HLSLNumThreadsAttr(S.Context, AL, X, Y, Z));
+  HLSLNumThreadsAttr *NewAttr = S.mergeHLSLNumThreadsAttr(D, AL, X, Y, Z);
+  if (NewAttr)
+D->addAttr(NewAttr);
+}
+
+HLSLNumThreadsAttr *Sema::mergeHLSLNumThreadsAttr(Decl *D,
+  const AttributeCommonInfo 
&AL,
+  int X, int Y, int Z) {
+  if (HLSLNumThreadsAttr *NT = D->getAttr()) {

[clang] ff6696c - Expanding HLSL attribute diagnostics

2022-03-30 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-30T14:15:01-05:00
New Revision: ff6696c842bac0b15fc04015b25ead721768eac9

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

LOG: Expanding HLSL attribute diagnostics

Updating the diagnostics as per the feedback on
https://reviews.llvm.org/D122627.

This change correctly handles missing argument lists, and changes the
subject for the `numthreads` attribute to be global functions.

I did not handle applying the attribute to template functions because
that currently fails parsing in a way that is consisetent with the
current DXC codebase (Microsoft attributes are not supported on
templates).

A future improvement to the diagnostic maybe warranted.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/SemaHLSL/num_threads.hlsl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 408ea11388c07..97b1027742f60 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -126,6 +126,9 @@ def FunctionTmpl
  FunctionDecl::TK_FunctionTemplate}],
 "function templates">;
 
+def GlobalFunction
+: SubsetSubjectisGlobal()}], "global functions">;
+
 def ClassTmpl : SubsetSubjectgetDescribedClassTemplate()}],
   "class templates">;
 
@@ -3943,7 +3946,7 @@ def Error : InheritableAttr {
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
-  let Subjects = SubjectList<[Function]>;
+  let Subjects = SubjectList<[GlobalFunction]>;
   let LangOpts = [HLSL];
   let Documentation = [NumThreadsDocs];
 }

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 553dcba94fed6..5d417f5aad1e8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4701,12 +4701,24 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes 
&Attrs) {
 IdentifierInfo *II = Tok.getIdentifierInfo();
 SourceLocation NameLoc = Tok.getLocation();
 ConsumeToken();
-if (Tok.is(tok::l_paren)) {
-  CachedTokens OpenMPTokens;
-  ParseCXX11AttributeArgs(II, NameLoc, Attrs, &EndLoc, nullptr,
-  SourceLocation(), OpenMPTokens);
-  ReplayOpenMPAttributeTokens(OpenMPTokens);
-} // FIXME: handle attributes that don't have arguments
+ParsedAttr::Kind AttrKind =
+ParsedAttr::getParsedKind(II, nullptr, ParsedAttr::AS_Microsoft);
+// For HLSL we want to handle all attributes, but for MSVC compat, we
+// silently ignore unknown Microsoft attributes.
+if (getLangOpts().HLSL || AttrKind != ParsedAttr::UnknownAttribute) {
+  bool AttrParsed = false;
+  if (Tok.is(tok::l_paren)) {
+CachedTokens OpenMPTokens;
+AttrParsed =
+ParseCXX11AttributeArgs(II, NameLoc, Attrs, &EndLoc, nullptr,
+SourceLocation(), OpenMPTokens);
+ReplayOpenMPAttributeTokens(OpenMPTokens);
+  }
+  if (!AttrParsed) {
+Attrs.addNew(II, NameLoc, nullptr, SourceLocation(), nullptr, 0,
+ ParsedAttr::AS_Microsoft);
+  }
+}
   }
 }
 

diff  --git a/clang/test/SemaHLSL/num_threads.hlsl 
b/clang/test/SemaHLSL/num_threads.hlsl
index 46e4fa131aa75..cf9e24804a093 100644
--- a/clang/test/SemaHLSL/num_threads.hlsl
+++ b/clang/test/SemaHLSL/num_threads.hlsl
@@ -13,6 +13,12 @@
 #if __SHADER_TARGET_STAGE == __SHADER_STAGE_COMPUTE || __SHADER_TARGET_STAGE 
== __SHADER_STAGE_MESH || __SHADER_TARGET_STAGE == __SHADER_STAGE_AMPLIFICATION 
|| __SHADER_TARGET_STAGE == __SHADER_STAGE_LIBRARY
 #ifdef FAIL
 #if __SHADER_TARGET_MAJOR == 6
+// expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
+[numthreads]
+// expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
+[numthreads()]
+// expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
+[numthreads(1,2,3,4)]
 // expected-error@+1 {{'numthreads' attribute requires an integer constant}}
 [numthreads("1",2,3)]
 // expected-error@+1 {{argument 'X' to numthreads attribute cannot exceed 
1024}}
@@ -38,6 +44,15 @@
 int entry() {
  return 1;
 }
+
+// expected-warning@+1 {{'numthreads' attribute only applies to global 
functions}}
+[numthreads(1,1,1)]
+struct Fido {
+  // expected-warning@+1 {{'numthreads' attribute only applies to global 
functions}}
+  [numthreads(1,1,1)]
+  void wag() {}
+};
+
 #else
 // expected-error-re@+1 {{attribute 'numthreads' is unsupported in 

[clang] 94189b4 - [HLSL] Fix MSFT Attribute parsing, add numthreads

2022-03-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-29T17:17:19-05:00
New Revision: 94189b42cc51b5fa8355957a976f0d8b4f8c312b

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

LOG: [HLSL] Fix MSFT Attribute parsing, add numthreads

HLSL uses Microsoft-style attributes `[attr]`, which clang mostly
ignores. For HLSL we need to handle known Microsoft attributes, and to
maintain C/C++ as-is we ignore unknown attributes.

To utilize this new code path, this change adds the HLSL `numthreads`
attribute.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D122627

Added: 
clang/test/SemaHLSL/lit.local.cfg
clang/test/SemaHLSL/num_threads.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f7ef3bf42ec2f..408ea11388c07 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -336,6 +336,8 @@ def ObjCAutoRefCount : LangOpt<"ObjCAutoRefCount">;
 def ObjCNonFragileRuntime
 : LangOpt<"", "LangOpts.ObjCRuntime.allowsClassStubs()">;
 
+def HLSL : LangOpt<"HLSL">;
+
 // Language option for CMSE extensions
 def Cmse : LangOpt<"Cmse">;
 
@@ -3937,3 +3939,11 @@ def Error : InheritableAttr {
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [ErrorAttrDocs];
 }
+
+def HLSLNumThreads: InheritableAttr {
+  let Spellings = [Microsoft<"numthreads">];
+  let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [HLSL];
+  let Documentation = [NumThreadsDocs];
+}

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index ebf0725a0a392..89db454f7dac4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6368,3 +6368,14 @@ flag.
 .. _Return-Oriented Programming: 
https://en.wikipedia.org/wiki/Return-oriented_programming
   }];
 }
+
+def NumThreadsDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``numthreads`` attribute applies to HLSL shaders where explcit thread 
counts
+are required. The ``X``, ``Y``, and ``Z`` values provided to the attribute
+dictate the thread id. Total number of threads executed is ``X * Y * Z``.
+
+The full documentation is available here: 
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-attributes-numthreads
+  }];
+}

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 172a10a65c8c0..d3055fed20828 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11564,4 +11564,12 @@ def err_std_source_location_impl_not_found : Error<
   "'std::source_location::__impl' was not found; it must be defined before 
'__builtin_source_location' is called">;
 def err_std_source_location_impl_malformed : Error<
   "'std::source_location::__impl' must be standard-layout and have only two 
'const char *' fields '_M_file_name' and '_M_function_name', and two integral 
fields '_M_line' and '_M_column'">;
+
+// HLSL Diagnostics
+def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in 
%select{Pixel|Vertex|Geometry|Hull|Domain|Compute|Library|RayGeneration|Intersection|AnyHit|ClosestHit|Miss|Callable|Mesh|Amplification|Invalid}1
 shaders, requires %2">;
+
+def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;
+def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed 
%0">;
+
 } // end of sema component.
+

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 1af53a151f8c9..3241931345297 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2783,7 +2783,8 @@ class Parser : public CodeCompletionHandler {
   const IdentifierInfo *EnclosingScope = nullptr);
 
   void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
-if (getLangOpts().MicrosoftExt && Tok.is(tok::l_square)) {
+if ((getLangOpts().MicrosoftExt || getLangOpts().HLSL) &&
+Tok.is(tok::l_square)) {
   ParsedAttributes AttrsWithRange(AttrFactory);
   ParseMicrosoftAttributes(AttrsWithRange);
   Attrs.takeAllFrom(AttrsWithRange);

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 342ee896bee18..553dcba94fed6 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ 

[clang] dfde354 - NFC. Fixing warnings from adding DXContainer

2022-03-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-29T14:46:24-05:00
New Revision: dfde354958ca49138349e1428bf2fc0414a73a43

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

LOG: NFC. Fixing warnings from adding DXContainer

Adds DXContainer to switch statements in Clang and LLDB to silence
warnings.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CodeGenModule.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index eaf34eedcb2bb..61677d368029e 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -287,6 +287,7 @@ static bool asanUseGlobalsGC(const Triple &T, const 
CodeGenOptions &CGOpts) {
   case Triple::XCOFF:
 llvm::report_fatal_error("ASan not implemented for XCOFF.");
   case Triple::Wasm:
+  case Triple::DXContainer:
   case Triple::UnknownObjectFormat:
 break;
   }

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 94d495a993835..2ec9ef9ae0605 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5069,6 +5069,7 @@ std::string CGObjCCommonMac::GetSectionName(StringRef 
Section,
   case llvm::Triple::Wasm:
   case llvm::Triple::GOFF:
   case llvm::Triple::XCOFF:
+  case llvm::Triple::DXContainer:
 llvm::report_fatal_error(
 "Objective-C support is unimplemented for object file format");
   }

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5fe14953caf6c..08117809c56fb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5490,6 +5490,8 @@ CodeGenModule::GetAddrOfConstantCFString(const 
StringLiteral *Literal) {
 llvm_unreachable("GOFF is not yet implemented");
   case llvm::Triple::XCOFF:
 llvm_unreachable("XCOFF is not yet implemented");
+  case llvm::Triple::DXContainer:
+llvm_unreachable("DXContainer is not yet implemented");
   case llvm::Triple::COFF:
   case llvm::Triple::ELF:
   case llvm::Triple::Wasm:

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index d258d18497b95..fc0b41fcd7ee2 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2230,6 +2230,7 @@ bool 
GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
 case llvm::Triple::GOFF:
 case llvm::Triple::Wasm:
 case llvm::Triple::XCOFF:
+case llvm::Triple::DXContainer:
   LLDB_LOGF(log, "error: not supported target architecture");
   return false;
 case llvm::Triple::UnknownObjectFormat:



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


[clang] 7a94a03 - NFC. Fixing rebase error

2022-03-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-29T13:19:06-05:00
New Revision: 7a94a032f02515a66d2820c1bc331424be25f6d8

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

LOG: NFC. Fixing rebase error

Somehow managed to get a double-assignment in there. Thanks @erichkeane
for pointing it out!

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 011a6743214a7..592e7b0076f7b 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -398,9 +398,8 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 Builder.defineMacro("__SHADER_STAGE_LIBRARY",
 Twine((uint32_t)ShaderStage::Library));
 // The current shader stage itself
-uint32_t StageInteger = StageInteger =
-(uint32_t)TI.getTriple().getEnvironment() -
-(uint32_t)llvm::Triple::Pixel;
+uint32_t StageInteger = (uint32_t)TI.getTriple().getEnvironment() -
+(uint32_t)llvm::Triple::Pixel;
 
 Builder.defineMacro("__SHADER_TARGET_STAGE", Twine(StageInteger));
 // Add target versions



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


[clang] 5b6207f - [ADT] Flesh out HLSL raytracing environments

2022-03-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-29T09:43:03-05:00
New Revision: 5b6207f3cd5e266f3fda8085fcebe6dcf45dacbf

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

LOG: [ADT] Flesh out HLSL raytracing environments

Fleshing this out now allows me to rely on enum math to translate
values rather than having to translate the off cases.

I should have added this in the first pass, but wasn't thinking about
it.

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
llvm/include/llvm/ADT/Triple.h
llvm/lib/Support/Triple.cpp
llvm/unittests/ADT/TripleTest.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 89e9cb0250043..011a6743214a7 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -401,11 +401,6 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 uint32_t StageInteger = StageInteger =
 (uint32_t)TI.getTriple().getEnvironment() -
 (uint32_t)llvm::Triple::Pixel;
-// TODO: When we add raytracing support we can clean this up
-if (TI.getTriple().getEnvironment() == llvm::Triple::Mesh)
-  StageInteger = (uint32_t)ShaderStage::Mesh;
-else if (TI.getTriple().getEnvironment() == llvm::Triple::Amplification)
-  StageInteger = (uint32_t)ShaderStage::Amplification;
 
 Builder.defineMacro("__SHADER_TARGET_STAGE", Twine(StageInteger));
 // Add target versions

diff  --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index 99ddfca897e63..728b24e235769 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -246,6 +246,12 @@ class Triple {
 Domain,
 Compute,
 Library,
+RayGeneration,
+Intersection,
+AnyHit,
+ClosestHit,
+Miss,
+Callable,
 Mesh,
 Amplification,
 

diff  --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
index 2cde1c69b2f41..ef5152eb302bf 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -275,6 +275,12 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType 
Kind) {
   case Domain: return "domain";
   case Compute: return "compute";
   case Library: return "library";
+  case RayGeneration: return "raygeneration";
+  case Intersection: return "intersection";
+  case AnyHit: return "anyhit";
+  case ClosestHit: return "closesthit";
+  case Miss: return "miss";
+  case Callable: return "callable";
   case Mesh: return "mesh";
   case Amplification: return "amplification";
   }
@@ -608,6 +614,12 @@ static Triple::EnvironmentType parseEnvironment(StringRef 
EnvironmentName) {
   .StartsWith("domain", Triple::Domain)
   .StartsWith("compute", Triple::Compute)
   .StartsWith("library", Triple::Library)
+  .StartsWith("raygeneration", Triple::RayGeneration)
+  .StartsWith("intersection", Triple::Intersection)
+  .StartsWith("anyhit", Triple::AnyHit)
+  .StartsWith("closesthit", Triple::ClosestHit)
+  .StartsWith("miss", Triple::Miss)
+  .StartsWith("callable", Triple::Callable)
   .StartsWith("mesh", Triple::Mesh)
   .StartsWith("amplification", Triple::Amplification)
   .Default(Triple::UnknownEnvironment);
@@ -1902,3 +1914,19 @@ static_assert(Triple::Compute - Triple::Pixel == 5,
   "incorrect HLSL stage order");
 static_assert(Triple::Library - Triple::Pixel == 6,
   "incorrect HLSL stage order");
+static_assert(Triple::RayGeneration - Triple::Pixel == 7,
+  "incorrect HLSL stage order");
+static_assert(Triple::Intersection - Triple::Pixel == 8,
+  "incorrect HLSL stage order");
+static_assert(Triple::AnyHit - Triple::Pixel == 9,
+  "incorrect HLSL stage order");
+static_assert(Triple::ClosestHit - Triple::Pixel == 10,
+  "incorrect HLSL stage order");
+static_assert(Triple::Miss - Triple::Pixel == 11,
+  "incorrect HLSL stage order");
+static_assert(Triple::Callable - Triple::Pixel == 12,
+  "incorrect HLSL stage order");
+static_assert(Triple::Mesh - Triple::Pixel == 13,
+  "incorrect HLSL stage order");
+static_assert(Triple::Amplification - Triple::Pixel == 14,
+  "incorrect HLSL stage order");

diff  --git a/llvm/unittests/ADT/TripleTest.cpp 
b/llvm/unittests/ADT/TripleTest.cpp
index 3824769a823ab..ca3163f43883e 100644
--- a/llvm/unittests/ADT/TripleTest.cpp
+++ b/llvm/unittests/ADT/TripleTest.cpp
@@ -662,6 +662,42 @@ TEST(TripleTest, ParsedIDs) {
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::ShaderModel, T.getOS());
   EXPECT_EQ(Triple::Library, T.getEnvironment());
+
+  T = Triple("dxil-unknown-shadermodel-raygeneration");
+  EXPECT_EQ(Triple::dxil, 

[clang] d394f9f - Add HLSL Language Option and Preprocessor

2022-03-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-28T16:16:17-05:00
New Revision: d394f9f8970d758cb39151328dd3040ba7f414ae

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

LOG: Add HLSL Language Option and Preprocessor

Bringing in HLSL as a language as well as language options for each of
the HLSL language standards.

While the HLSL language is unimplemented, this patch adds the
HLSL-specific preprocessor defines which enables testing of the command
line options through the driver.

Reviewed By: pete, rnk

Differential Revision: https://reviews.llvm.org/D122087

Added: 
clang/test/Preprocessor/predefined-macros-hlsl.c

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Basic/LangStandards.def
clang/include/clang/Driver/Types.def
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/lit.local.cfg
clang/test/lit.cfg.py
llvm/lib/Support/Triple.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 05b9691142998..d5f8dd9ab5c04 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -251,6 +251,9 @@ LANGOPT(OpenMPNoThreadState  , 1, 0, "Assume that no thread 
in a parallel region
 LANGOPT(OpenMPOffloadMandatory  , 1, 0, "Assert that offloading is mandatory 
and do not create a host fallback.")
 LANGOPT(RenderScript  , 1, 0, "RenderScript")
 
+LANGOPT(HLSL, 1, 0, "HLSL")
+ENUM_LANGOPT(HLSLVersion, HLSLLangStd, 16, HLSL_Unset, "HLSL Version")
+
 LANGOPT(CUDAIsDevice  , 1, 0, "compiling for CUDA device")
 LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "allowing variadic functions in CUDA 
device code")
 LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr 
functions as __host__ __device__")

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 96fd6049efeca..f5a2fd8461674 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -53,6 +53,26 @@ class LangOptionsBase {
 /// members used to implement virtual inheritance.
 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
 
+/// Shader programs run in specific pipeline stages.
+enum class ShaderStage {
+  Pixel = 0,
+  Vertex,
+  Geometry,
+  Hull,
+  Domain,
+  Compute,
+  Library,
+  RayGeneration,
+  Intersection,
+  AnyHit,
+  ClosestHit,
+  Miss,
+  Callable,
+  Mesh,
+  Amplification,
+  Invalid,
+};
+
 /// Keeps track of the various options that can be
 /// enabled, which controls the dialect of C or C++ that is accepted.
 class LangOptions : public LangOptionsBase {
@@ -140,6 +160,16 @@ class LangOptions : public LangOptionsBase {
 SYCL_Default = SYCL_2020
   };
 
+  enum HLSLLangStd {
+HLSL_Unset = 0,
+HLSL_2015 = 2015,
+HLSL_2016 = 2016,
+HLSL_2017 = 2017,
+HLSL_2018 = 2018,
+HLSL_2021 = 2021,
+HLSL_202x = 2029,
+  };
+
   /// Clang versions with 
diff erent platform ABI conformance.
   enum class ClangABI {
 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x

diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index b0785409628c4..fdfd2e7773a87 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -36,6 +36,7 @@ enum class Language : uint8_t {
   CUDA,
   RenderScript,
   HIP,
+  HLSL,
   ///@}
 };
 
@@ -55,7 +56,8 @@ enum LangFeatures {
   GNUMode = (1 << 12),
   HexFloat = (1 << 13),
   ImplicitInt = (1 << 14),
-  OpenCL = (1 << 15)
+  OpenCL = (1 << 15),
+  HLSL = (1 << 16)
 };
 
 /// LangStandard - Information about the properties of a particular language

diff  --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index 6056cfd65bbbf..d0e777b23b94f 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -209,6 +209,36 @@ LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",
 LANGSTANDARD(hip, "hip", HIP, "HIP",
  LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 
+// HLSL
+LANGSTANDARD(hlsl, "hlsl",
+ HLSL, "High Level Shader Language",
+ LineComment | HLSL | CPlusPlus )
+
+LANGSTANDARD(hlsl2015, "hlsl2015",
+ HLSL, "High Level Shader Language 2015",
+ LineComment | HLSL | CPlusPlus )
+
+LANGSTANDARD(hlsl2016, "hlsl2016",
+ HLSL, "High Level Shader Language 2016",
+

[clang] c5e54e2 - Add clang DirectX target support

2022-03-28 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-03-28T15:00:50-05:00
New Revision: c5e54e275241f0575ed0c9fe5c8c65299dd0bd0f

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

LOG: Add clang DirectX target support

This change adds a stub DirectX target for clang to enable targeting
dxil targets.

Reviewed By: pete

Differential Revision: https://reviews.llvm.org/D122085

Added: 
clang/lib/Basic/Targets/DirectX.cpp
clang/lib/Basic/Targets/DirectX.h
clang/test/CodeGenHLSL/basic-target.c
clang/test/CodeGenHLSL/lit.local.cfg

Modified: 
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Targets.cpp

Removed: 




diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 40de9433a4dde..12ed97b99b45f 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangBasic
   Targets/ARM.cpp
   Targets/AVR.cpp
   Targets/BPF.cpp
+  Targets/DirectX.cpp
   Targets/Hexagon.cpp
   Targets/Lanai.cpp
   Targets/Le64.cpp

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index ff8dad2db0da2..641345452cfe3 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -19,6 +19,7 @@
 #include "Targets/ARM.h"
 #include "Targets/AVR.h"
 #include "Targets/BPF.h"
+#include "Targets/DirectX.h"
 #include "Targets/Hexagon.h"
 #include "Targets/Lanai.h"
 #include "Targets/Le64.h"
@@ -649,6 +650,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
 return nullptr;
 }
 
+  case llvm::Triple::dxil:
+return new DirectXTargetInfo(Triple,Opts);
   case llvm::Triple::renderscript32:
 return new LinuxTargetInfo(Triple, Opts);
   case llvm::Triple::renderscript64:

diff  --git a/clang/lib/Basic/Targets/DirectX.cpp 
b/clang/lib/Basic/Targets/DirectX.cpp
new file mode 100644
index 0..0dd27e6e93b33
--- /dev/null
+++ b/clang/lib/Basic/Targets/DirectX.cpp
@@ -0,0 +1,22 @@
+//===--- DirectX.cpp - Implement DirectX target feature support 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements DirectX TargetInfo objects.
+//
+//===--===//
+
+#include "DirectX.h"
+#include "Targets.h"
+
+using namespace clang;
+using namespace clang::targets;
+
+void DirectXTargetInfo::getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+  DefineStd(Builder, "DIRECTX", Opts);
+}

diff  --git a/clang/lib/Basic/Targets/DirectX.h 
b/clang/lib/Basic/Targets/DirectX.h
new file mode 100644
index 0..90ef1dfa55c89
--- /dev/null
+++ b/clang/lib/Basic/Targets/DirectX.h
@@ -0,0 +1,92 @@
+//===--- DirectX.h - Declare DirectX target feature support -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares DXIL TargetInfo objects.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_DIRECTX_H
+#define LLVM_CLANG_LIB_BASIC_TARGETS_DIRECTX_H
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace targets {
+
+static const unsigned DirectXAddrSpaceMap[] = {
+0, // Default
+1, // opencl_global
+3, // opencl_local
+2, // opencl_constant
+0, // opencl_private
+4, // opencl_generic
+5, // opencl_global_device
+6, // opencl_global_host
+0, // cuda_device
+0, // cuda_constant
+0, // cuda_shared
+// SYCL address space values for this map are dummy
+0, // sycl_global
+0, // sycl_global_device
+0, // sycl_global_host
+0, // sycl_local
+0, // sycl_private
+0, // ptr32_sptr
+0, // ptr32_uptr
+0  // ptr64
+};
+
+class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
+public:
+  DirectXTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
+  : TargetInfo(Triple) {
+TLSSupported = false;
+VLASupported = false;
+LongWidth = LongAlign = 64;
+AddrSpaceMap = &DirectXAddrSpaceMap;
+UseAddrSpaceMapMangling = true;
+HasLegalHalfType = true;
+HasFloat16 = true;
+NoAsmVariants = true;
+resetDa

[clang] 9d3437f - [ADT] [NFC] Add StringRef::detectEOL

2022-01-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-01-21T09:47:02-06:00
New Revision: 9d3437fbf3419502351d41ff9e28f06b0c3f06e8

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

LOG: [ADT] [NFC] Add StringRef::detectEOL

This change moves EOL detection out of the clang::InclusionRewriter into
llvm::StringRef so that it can be easily reused elsewhere. It also adds
additional explicit test cases to verify the correct and expected return
results.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D117626

Added: 


Modified: 
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
llvm/include/llvm/ADT/StringRef.h
llvm/unittests/ADT/StringRefTest.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp 
b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
index 931f3a24c5888..3e8d582f90c27 100644
--- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -251,28 +251,12 @@ bool InclusionRewriter::IsIfAtLocationTrue(SourceLocation 
Loc) const {
   return false;
 }
 
-/// Detect the likely line ending style of \p FromFile by examining the first
-/// newline found within it.
-static StringRef DetectEOL(const MemoryBufferRef &FromFile) {
-  // Detect what line endings the file uses, so that added content does not mix
-  // the style. We need to check for "\r\n" first because "\n\r" will match
-  // "\r\n\r\n".
-  const char *Pos = strchr(FromFile.getBufferStart(), '\n');
-  if (!Pos)
-return "\n";
-  if (Pos - 1 >= FromFile.getBufferStart() && Pos[-1] == '\r')
-return "\r\n";
-  if (Pos + 1 < FromFile.getBufferEnd() && Pos[1] == '\r')
-return "\n\r";
-  return "\n";
-}
-
 void InclusionRewriter::detectMainFileEOL() {
   Optional FromFile = *SM.getBufferOrNone(SM.getMainFileID());
   assert(FromFile);
   if (!FromFile)
 return; // Should never happen, but whatever.
-  MainEOL = DetectEOL(*FromFile);
+  MainEOL = FromFile->getBuffer().detectEOL();
 }
 
 /// Writes out bytes from \p FromFile, starting at \p NextToWrite and ending at
@@ -378,7 +362,7 @@ void InclusionRewriter::Process(FileID FileId,
   Lexer RawLex(FileId, FromFile, PP.getSourceManager(), PP.getLangOpts());
   RawLex.SetCommentRetentionState(false);
 
-  StringRef LocalEOL = DetectEOL(FromFile);
+  StringRef LocalEOL = FromFile.getBuffer().detectEOL();
 
   // Per the GNU docs: "1" indicates entering a new file.
   if (FileId == SM.getMainFileID() || FileId == PP.getPredefinesFileID())

diff  --git a/llvm/include/llvm/ADT/StringRef.h 
b/llvm/include/llvm/ADT/StringRef.h
index 3950910f0635a..9f64250c58a36 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -877,6 +877,25 @@ namespace llvm {
   return ltrim(Chars).rtrim(Chars);
 }
 
+/// Detect the line ending style of the string.
+///
+/// If the string contains a line ending, return the line ending character
+/// sequence that is detected. Otherwise return '\n' for unix line endings.
+///
+/// \return - The line ending character sequence.
+LLVM_NODISCARD
+StringRef detectEOL() const {
+  size_t Pos = find('\r');
+  if (Pos == npos) {
+// If there is no carriage return, assume unix
+return "\n";
+  }
+  if (Pos + 1 < Length && Data[Pos + 1] == '\n')
+return "\r\n"; // Windows
+  if (Pos > 0 && Data[Pos - 1] == '\n')
+return "\n\r"; // You monster!
+  return "\r"; // Classic Mac
+}
 /// @}
   };
 

diff  --git a/llvm/unittests/ADT/StringRefTest.cpp 
b/llvm/unittests/ADT/StringRefTest.cpp
index 41c35804f1226..e80a25a19969c 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -1109,6 +1109,36 @@ TEST(StringRefTest, GTestPrinter) {
   EXPECT_EQ(R"("foo")", ::testing::PrintToString(StringRef("foo")));
 }
 
+TEST(StringRefTest, LFLineEnding) {
+  constexpr StringRef Cases[] = {"\nDoggo\nPupper", "Floofer\n", "Woofer"};
+  EXPECT_EQ(StringRef("\n"), Cases[0].detectEOL());
+  EXPECT_EQ(StringRef("\n"), Cases[1].detectEOL());
+  EXPECT_EQ(StringRef("\n"), Cases[2].detectEOL());
+}
+
+TEST(StringRefTest, CRLineEnding) {
+  constexpr StringRef Cases[] = {"\rDoggo\rPupper", "Floofer\r", "Woo\rfer\n"};
+  EXPECT_EQ(StringRef("\r"), Cases[0].detectEOL());
+  EXPECT_EQ(StringRef("\r"), Cases[1].detectEOL());
+  EXPECT_EQ(StringRef("\r"), Cases[2].detectEOL());
+}
+
+TEST(StringRefTest, CRLFLineEnding) {
+  constexpr StringRef Cases[] = {"\r\nDoggo\r\nPupper", "Floofer\r\n",
+ "Woofer\r\nSubWoofer\n"};
+  EXPECT_EQ(StringRef("\r\n"), Cases[0].detectEOL());
+  EXPECT_EQ(StringRef("\r\n"), Cases[1].detectEOL());
+  EXPECT_EQ(StringRef("\r\n"), Cases[2].detectEOL());
+}
+
+TEST(S

[clang] 3e7ad1f - Emit final macro diagnostics in system headers

2021-11-11 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-11-11T13:51:26-06:00
New Revision: 3e7ad1f2b2c0a753749eaba88d369d6032a50764

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

LOG: Emit final macro diagnostics in system headers

Final macro diagnostics should log from system headers.

As planned, final macros are hard-mode. They always log diagnostics.

Added: 
clang/test/Lexer/Inputs/final-macro-system.h

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/test/Lexer/final-macro.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 92c6b0bbffc30..805dcab2e0084 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -564,7 +564,7 @@ def note_pp_macro_annotation :
 def warn_pragma_final_macro :
   ExtWarn<"macro %0 has been marked as final and should not be "
   "%select{undefined|redefined}1">,
-  InGroup;
+  InGroup,  ShowInSystemHeader;
 
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :

diff  --git a/clang/test/Lexer/Inputs/final-macro-system.h 
b/clang/test/Lexer/Inputs/final-macro-system.h
new file mode 100644
index 0..f30e5d45e4dcd
--- /dev/null
+++ b/clang/test/Lexer/Inputs/final-macro-system.h
@@ -0,0 +1,4 @@
+// expected-warning@+1{{macro 'SYSTEM_MACRO' has been marked as final and 
should not be undefined}}
+#undef SYSTEM_MACRO
+// expected-warning@+1{{macro 'SYSTEM_MACRO' has been marked as final and 
should not be redefined}}
+#define SYSTEM_MACRO WoahMoar

diff  --git a/clang/test/Lexer/final-macro.c b/clang/test/Lexer/final-macro.c
index 498773d9dfdf5..2992714dd8a5a 100644
--- a/clang/test/Lexer/final-macro.c
+++ b/clang/test/Lexer/final-macro.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wfinal-macro %s -fsyntax-only -verify
+// RUN: %clang_cc1 -Wfinal-macro %s -fsyntax-only -isystem %S/Inputs -verify
 
 // Test warning production
 #define Foo 1
@@ -43,3 +43,8 @@
 // no diagnostics triggered by these pragmas.
 #pragma clang deprecated(Foo)
 #pragma clang restrict_expansion(Foo)
+
+#define SYSTEM_MACRO Woah
+// expected-note@+1 2{{macro marked 'final' here}}
+#pragma clang final(SYSTEM_MACRO)
+#include 



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


[clang] 121b225 - AddGlobalAnnotations for function with or without function body.

2021-10-11 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-10-11T14:50:34-05:00
New Revision: 121b2252de0eed68f2ddf5f09e924a6c35423d47

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

LOG: AddGlobalAnnotations for function with or without function body.

When AnnotateAttr is on a function, AddGlobalAnnotations is only called
in CodeGenModule::EmitGlobalFunctionDefinition which means AnnotateAttr
on function declaration without function body will be ignored.
The patch will move AddGlobalAnnotations  to
CodeGenModule::SetFunctionAttributes, so with or without function body,
the AnnotateAttr will get code gen for a function.

It'll help case when AnnotateAttr is on external function, and the
AnnotateAttr will be consumed in IR level.

For example, a pass to collect num of uses for functions with
__attribute((annotate("count_use"))) after optimizations,
As long as there's __attribute((annotate("count_use"))), function with
or without function body should be counted.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D09

Patch by:  python3kgae (Xiang Li)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/annotations-global.c
clang/test/CodeGenCXX/attr-annotate.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d4e3186c10a53..9fa5e9cf1b79c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2195,6 +2195,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, 
llvm::Function *F,
CalleeIdx, PayloadIndices,
/* VarArgsArePassed */ 
false)}));
   }
+
+  if (FD->hasAttr())
+AddGlobalAnnotations(FD, F);
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
@@ -4893,8 +4896,6 @@ void 
CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
 AddGlobalCtor(Fn, CA->getPriority());
   if (const DestructorAttr *DA = D->getAttr())
 AddGlobalDtor(Fn, DA->getPriority(), true);
-  if (D->hasAttr())
-AddGlobalAnnotations(D, Fn);
 }
 
 void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {

diff  --git a/clang/test/CodeGen/annotations-global.c 
b/clang/test/CodeGen/annotations-global.c
index 2a5c847fd9602..454680fa57d66 100644
--- a/clang/test/CodeGen/annotations-global.c
+++ b/clang/test/CodeGen/annotations-global.c
@@ -4,15 +4,19 @@
 // RUN: FileCheck --check-prefix=BAR %s < %t1
 // RUN: FileCheck --check-prefix=FOOS %s < %t1
 // RUN: FileCheck --check-prefix=ADDRSPACE %s < %t1
+// RUN: FileCheck --check-prefix=DECL %s < %t1
 // RUN: %clang_cc1 %s -triple r600 -emit-llvm -o - | FileCheck %s 
--check-prefix AS1-GLOBALS
 // END.
 
 static __attribute((annotate("sfoo_0"))) __attribute((annotate("sfoo_1"))) 
char sfoo;
 __attribute((annotate("foo_0"))) __attribute((annotate("foo_1"))) char foo;
 
+void __attribute((annotate("ann_decl_0"))) 
__attribute((annotate("ann_decl_1")))  decl(char *a);
+
 void __attribute((annotate("ann_a_0"))) __attribute((annotate("ann_a_1"))) 
__attribute((annotate("ann_a_2"))) __attribute((annotate("ann_a_3"))) a(char 
*a);
 void __attribute((annotate("ann_a_0"))) __attribute((annotate("ann_a_1"))) 
a(char *a) {
   __attribute__((annotate("bar_0"))) __attribute__((annotate("bar_1"))) static 
char bar;
+  decl(a);
   sfoo = 0;
 }
 
@@ -22,13 +26,13 @@ __attribute((address_space(1))) 
__attribute__((annotate("addrspace1_ann"))) char
 // FOOS: private unnamed_addr constant [7 x i8] c"sfoo_{{.}}\00", section 
"llvm.metadata"
 // FOOS: private unnamed_addr constant [7 x i8] c"sfoo_{{.}}\00", section 
"llvm.metadata"
 // FOOS-NOT: sfoo_
-// FOOS: @llvm.global.annotations = appending global [11 x { i8*, i8*, i8*, 
i32, i8* }] {{.*}}i8* @sfoo{{.*}}i8* @sfoo{{.*}}, section "llvm.metadata"
+// FOOS: @llvm.global.annotations = appending global [13 x { i8*, i8*, i8*, 
i32, i8* }] {{.*}}i8* @sfoo{{.*}}i8* @sfoo{{.*}}, section "llvm.metadata"
 
 // FOO: target triple
 // FOO: private unnamed_addr constant [6 x i8] c"foo_{{.}}\00", section 
"llvm.metadata"
 // FOO: private unnamed_addr constant [6 x i8] c"foo_{{.}}\00", section 
"llvm.metadata"
 // FOO-NOT: foo_
-// FOO: @llvm.global.annotations = appending global [11 x { i8*, i8*, i8*, 
i32, i8* }] {{.*}}i8* @foo{{.*}}i8* @foo{{.*}}, section "llvm.metadata"
+// FOO: @llvm.global.annotations = appending global [13 x { i8*, i8*, i8*, 
i32, i8* }] {{.*}}i8* @foo{{.*}}i8* @foo{{.*}}, section "llvm.metadata"
 
 // A: target triple
 // A: private unnamed_addr constant [8 x i8] c"ann_a_{{.}}\00", section 
"llvm.metadata"
@@ -36,18 +40,24 @@ __attribute((address_space(1))) 
__attribute__((annotate("addrspace1_ann"))) char
 // A: private unnamed_addr constant [8 x i8] c"an

[clang] 18cf5b2 - Fixing docs build

2021-09-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-09-27T14:16:28-05:00
New Revision: 18cf5b220d3f5e5ee1998a163764e15e56763815

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

LOG: Fixing docs build

I always forget that new line...

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 231c20dab1ca..56e351183899 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3951,6 +3951,7 @@ Clang supports the pragma ``#pragma clang final``, which 
can be used to
 mark macros as final, meaning they cannot be undef'd or re-defined. For 
example:
 
 .. code-block:: c
+
#define FINAL_MACRO 1
#pragma clang final(FINAL_MACRO)
 



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


[clang] 1e48ef2 - Implement #pragma clang final extension

2021-09-27 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-09-27T14:11:16-05:00
New Revision: 1e48ef20358fb097f43d9b133e33bd23723d79c2

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

LOG: Implement #pragma clang final extension

This patch adds a new preprocessor extension ``#pragma clang final``
which enables warning on undefinition and re-definition of macros.

The intent of this warning is to extend beyond ``-Wmacro-redefined`` to
warn against any and all alterations to macros that are marked `final`.

This warning is part of the ``-Wpedantic-macros`` diagnostics group.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D108567

Added: 
clang/test/Lexer/Inputs/final-macro.h
clang/test/Lexer/final-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp
clang/test/Lexer/Inputs/unsafe-macro.h
clang/test/Lexer/deprecate-macro.c
clang/test/Lexer/pedantic-macro-interplay.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 28791a48a6c0d..231c20dab1caa 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3944,6 +3944,24 @@ will expansion of the macro within the main source file. 
For example:
 
 This warning is controlled by ``-Wpedantic-macros``.
 
+Final Macros
+
+
+Clang supports the pragma ``#pragma clang final``, which can be used to
+mark macros as final, meaning they cannot be undef'd or re-defined. For 
example:
+
+.. code-block:: c
+   #define FINAL_MACRO 1
+   #pragma clang final(FINAL_MACRO)
+
+   #define FINAL_MACRO // warning: FINAL_MACRO is marked final and should not 
be redefined
+   #undef FINAL_MACRO  // warning: FINAL_MACRO is marked final and should not 
be undefined
+
+This is useful for enforcing system-provided macros that should not be altered
+in user headers or code. This is controlled by ``-Wpedantic-macros``. Final 
+macros will always warn on redefinition, including situations with identical
+bodies and in system headers.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f48598eec3262..23e9144ea0084 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -648,6 +648,7 @@ def KeywordAsMacro : DiagGroup<"keyword-macro">;
 def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">;
 def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", 
[ReservedIdAsMacro]>;
 def RestrictExpansionMacro : DiagGroup<"restrict-expansion">;
+def FinalMacro : DiagGroup<"final-macro">;
 
 // Just silence warnings about -Wstrict-aliasing for now.
 def : DiagGroup<"strict-aliasing=0">;
@@ -1322,4 +1323,5 @@ def PedanticMacros : DiagGroup<"pedantic-macros",
 [DeprecatedPragma,
  MacroRedefined,
  BuiltinMacroRedefined,
- RestrictExpansionMacro]>;
+ RestrictExpansionMacro,
+ FinalMacro]>;

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index faa84774167b9..763b7b0086369 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -551,7 +551,13 @@ def warn_pragma_restrict_expansion_macro_use :
 
 // - Note for macro annotations.
 def note_pp_macro_annotation :
-  Note<"macro marked '%select{deprecated|restrict_expansion}0' here">;
+  Note<"macro marked '%select{deprecated|restrict_expansion|final}0' here">;
+
+// - #pragma clang final(...)
+def warn_pragma_final_macro :
+  ExtWarn<"macro %0 has been marked as final and should not be "
+  "%select{undefined|redefined}1">,
+  InGroup;
 
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 9c4833b278294..d620138125569 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -127,7 +127,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   // True if this macro is unsafe in headers.
   unsigned IsRestrictExpansion : 1;
 
-  // 23 bits left in a 64-bit word.
+  // True if this macro is final.
+  unsigned IsFinal : 1;
+
+  // 22 bits left in a 64-bit word.
 
   // Managed by the language front-end.
  

[clang] 744ec74 - [NFC] `goto fail` has failed us in the past...

2021-09-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-09-21T09:18:37-05:00
New Revision: 744ec74b305a5039dc74e2d043e1c136e06beac1

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

LOG: [NFC] `goto fail` has failed us in the past...

This patch replaces reliance on `goto failure` pattern with
`llvm::scope_exit`.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D109865

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index c996c9c486bc4..0bb62a96e02cc 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -27,6 +27,7 @@
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -558,8 +559,20 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
   bool HasBegunSourceFile = false;
   bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
usesPreprocessorOnly();
+
+  // If we fail, reset state since the client will not end up calling the
+  // matching EndSourceFile(). All paths that return true should release this.
+  auto FailureCleanup = llvm::make_scope_exit([&]() {
+if (HasBegunSourceFile)
+  CI.getDiagnosticClient().EndSourceFile();
+CI.clearOutputFiles(/*EraseFiles=*/true);
+CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
+setCurrentInput(FrontendInputFile());
+setCompilerInstance(nullptr);
+  });
+
   if (!BeginInvocation(CI))
-goto failure;
+return false;
 
   // If we're replaying the build of an AST file, import it and set up
   // the initial state from its build.
@@ -580,7 +593,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(),
 CI.getCodeGenOpts().DebugTypeExtRefs);
 if (!AST)
-  goto failure;
+  return false;
 
 // Options relating to how we treat the input (but not what we do with it)
 // are inherited from the AST unit.
@@ -649,7 +662,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 CI.getCodeGenOpts().DebugTypeExtRefs);
 
 if (!AST)
-  goto failure;
+  return false;
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
@@ -669,20 +682,21 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Create the AST consumer.
 CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
 if (!CI.hasASTConsumer())
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
   // Set up the file and source managers, if needed.
   if (!CI.hasFileManager()) {
 if (!CI.createFileManager()) {
-  goto failure;
+  return false;
 }
   }
   if (!CI.hasSourceManager())
@@ -710,12 +724,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Initialize the main file entry.
 if (!CI.InitializeSourceManager(CurrentInput))
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
@@ -748,7 +763,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
   if (!Found) {
 CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
-goto failure;
+return false;
   }
 }
   }
@@ -765,7 +780,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
   // Initialize the main file entry.
   if (!CI.InitializeSourceManager(Input))
-goto failure;
+return false;
 
   // For module map files, we first parse the module map and synthesize a
   // "" buffer before more conventional processing.
@@ -777,11 +792,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
 Input.isPreprocessed(),
 PresumedModuleMapFile, OffsetToContents))
-  goto failure;
+  return false;
 
 auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
 if (!CurrentModule)
-  goto failure;
+  return false;
 
 CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
 
@@ -792,7 +807,

[clang] 43de869 - Implement #pragma clang restrict_expansion

2021-08-23 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-08-23T09:46:38-07:00
New Revision: 43de869d77f77eedf9f8760f94940a249d2b5a41

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

LOG: Implement #pragma clang restrict_expansion

This patch adds `#pragma clang restrict_expansion ` to enable flagging
macros as unsafe for header use. This is to allow macros that may have
ABI implications to be avoided in headers that have ABI stability
promises.

Using macros in headers (particularly public headers) can cause a
variety of issues relating to ABI and modules. This new pragma logs
warnings when using annotated macros outside the main source file.

This warning is added under a new diagnostics group -Wpedantic-macros

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D107095

Added: 
clang/test/Lexer/Inputs/pedantic-macro-interplay.h
clang/test/Lexer/Inputs/unsafe-macro-2.h
clang/test/Lexer/Inputs/unsafe-macro.h
clang/test/Lexer/pedantic-macro-interplay.c
clang/test/Lexer/unsafe-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 087aa66c1b7af..fada65c487bc5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3931,6 +3931,40 @@ provide deprecation warnings for macro uses. For example:
 ``#pragma GCC warning`` because the warning can be controlled with
 ``-Wdeprecated``.
 
+Restricted Expansion Macros
+===
+
+Clang supports the pragma ``#pragma clang restrict_expansion``, which can be
+used restrict macro expansion in headers. This can be valuable when providing
+headers with ABI stability requirements. Any expansion of the annotated macro
+processed by the preprocessor after the ``#pragma`` annotation will log a
+warning. Redefining the macro or undefining the macro will not be diagnosed, 
nor
+will expansion of the macro within the main source file. For example:
+
+.. code-block:: c
+
+   #define TARGET_ARM 1
+   #pragma clang restrict_expansion(TARGET_ARM, "")
+
+   /// Foo.h
+   struct Foo {
+   #if TARGET_ARM // warning: TARGET_ARM is marked unsafe in headers: 
+ uint32_t X;
+   #else
+ uint64_t X;
+   #endif
+   };
+
+   /// main.c
+   #include "foo.h"
+   #if TARGET_ARM // No warning in main source file
+   X_TYPE uint32_t
+   #else
+   X_TYPE uint64_t
+   #endif
+
+This warning is controlled by ``-Wpedantic-macros``.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 17b5f419ef58c..753a3d5546e2f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -647,6 +647,7 @@ def AmbiguousMacro : DiagGroup<"ambiguous-macro">;
 def KeywordAsMacro : DiagGroup<"keyword-macro">;
 def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">;
 def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", 
[ReservedIdAsMacro]>;
+def RestrictExpansionMacro : DiagGroup<"restrict-expansion">;
 
 // Just silence warnings about -Wstrict-aliasing for now.
 def : DiagGroup<"strict-aliasing=0">;
@@ -1311,3 +1312,10 @@ def WebAssemblyExceptionSpec : 
DiagGroup<"wasm-exception-spec">;
 def RTTI : DiagGroup<"rtti">;
 
 def OpenCLCoreFeaturesDiagGroup : DiagGroup<"pedantic-core-features">;
+
+// Warnings and extensions to make preprocessor macro usage pedantic.
+def PedanticMacros : DiagGroup<"pedantic-macros",
+[DeprecatedPragma,
+ MacroRedefined,
+ BuiltinMacroRedefined,
+ RestrictExpansionMacro]>;

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index c19adf104db1f..49c50fb27e624 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -528,6 +528,16 @@ def warn_pragma_deprecated_macro_use :
   ExtWarn<"macro %0 has been marked as deprecated%select{|: %2}1">,
   InGroup;
 
+// - #pragma clang restrict_expansion(...)
+def warn_pragma_restrict_expansion_macro_use :
+  ExtWarn<"macro %0 has been marked as unsafe for use in headers"
+  "%select{|: %2}1">,
+  InGroup;
+
+// - Note for macro annotations.
+def note_pp_macro_annotation :
+  Note<"macro marked '%select{deprecated|restrict_expansion}0' here">;
+
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_chars

[clang] f8819c1 - Fixing broken docs build

2021-07-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-07-29T12:45:56-05:00
New Revision: f8819c109e4afcad19407ceb54e28ef77e1c57e9

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

LOG: Fixing broken docs build

Need an empty line after the code-block directive.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 8dafcb2f9a724..aaee136530fef 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3894,6 +3894,7 @@ Clang supports the pragma ``#pragma clang deprecated``, 
which can be used to
 provide deprecation warnings for macro uses. For example:
 
 .. code-block:: c
+
#define MIN(x, y) x < y ? x : y
#pragma clang deprecated(MIN, "use std::min instead")
 



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


[clang] 26c695b - Support macro deprecation #pragma clang deprecated

2021-07-29 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-07-29T12:40:53-05:00
New Revision: 26c695b7893071d5e69afbaa70c4850ab2e468be

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

LOG: Support macro deprecation #pragma clang deprecated

This patch adds `#pragma clang deprecated` to enable deprecation of
preprocessor macros.

The macro must be defined before `#pragma clang deprecated`. When
deprecating a macro a custom message may be optionally provided.

Warnings are emitted at the use site of a deprecated macro, and can be
controlled via the `-Wdeprecated` warning group.

This patch takes some rough inspiration and a few lines of code from
https://reviews.llvm.org/D67935.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D106732

Added: 
clang/test/Lexer/deprecate-macro.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPExpressions.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 462aa89ea789a..8dafcb2f9a724 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3887,6 +3887,24 @@ Since the size of ``buffer`` can't be known at compile 
time, Clang will fold
 as ``__builtin_dynamic_object_size(buffer, 0)``, Clang will fold it into
 ``size``, providing some extra runtime safety.
 
+Deprecating Macros
+==
+
+Clang supports the pragma ``#pragma clang deprecated``, which can be used to
+provide deprecation warnings for macro uses. For example:
+
+.. code-block:: c
+   #define MIN(x, y) x < y ? x : y
+   #pragma clang deprecated(MIN, "use std::min instead")
+
+   void min(int a, int b) {
+ return MIN(a, b); // warning: MIN is deprecated: use std::min instead
+   }
+
+``#pragma clang deprecated`` should be preferred for this purpose over
+``#pragma GCC warning`` because the warning can be controlled with
+``-Wdeprecated``.
+
 Extended Integer Types
 ==
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 4b4928a7a00e6..6857c889b72b6 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,7 @@ def DeprecatedThisCapture : 
DiagGroup<"deprecated-this-capture">;
 def DeprecatedVolatile : DiagGroup<"deprecated-volatile">;
 def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings",
   [CXX11CompatDeprecatedWritableStr]>;
+def DeprecatedPragma : DiagGroup<"deprecated-pragma">;
 // FIXME: Why is DeprecatedImplementations not in this group?
 def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
   DeprecatedArrayCompare,
@@ -198,6 +199,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedEnumEnumConversion,
   DeprecatedEnumFloatConversion,
   DeprecatedIncrementBool,
+  DeprecatedPragma,
   DeprecatedRegister,
   DeprecatedThisCapture,
   DeprecatedVolatile,

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ce6d0d0394b48..174f6c3dfd4c6 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -519,6 +519,11 @@ def warn_pragma_warning_expected_number :
   ExtWarn<"#pragma warning expected a warning number">,
   InGroup;
 
+// - #pragma deprecated(...)
+def warn_pragma_deprecated_macro_use :
+  ExtWarn<"macro %0 has been marked as deprecated%select{|: %2}1">,
+  InGroup;
+
 // - #pragma execution_character_set(...)
 def warn_pragma_exec_charset_expected :
   ExtWarn<"#pragma execution_character_set expected '%0'">,

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index f2379c7ddfbd1..d75d43f0398d7 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -121,7 +121,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   // True if this is a mangled OpenMP variant name.
   unsigned IsMangledOpenMPVariantName : 1;

[clang] 13a9b22 - Don't delete the module you're inspecting

2021-06-03 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-06-03T13:00:09-05:00
New Revision: 13a9b2220f227631b3495a42abbab7fc2b414b69

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

LOG: Don't delete the module you're inspecting

Prior to this patch when you used `clang -module-file-info` clang would
delete the module on completion because the module was treated as an
output file.

This fixes the issue so you don't need to invoke cc1 directly to get
module file information.

Reviewed By: steven_wu, phosek

Differential Revision: https://reviews.llvm.org/D103547

Added: 
clang/test/Modules/clang_module_file_info.m

Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5f1553337fea3..287b218641546 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4883,6 +4883,11 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
 return "-";
   }
 
+  if (JA.getType() == types::TY_ModuleFile &&
+  C.getArgs().getLastArg(options::OPT_module_file_info)) {
+return "-";
+  }
+
   // Is this the assembly listing for /FA?
   if (JA.getType() == types::TY_PP_Asm &&
   (C.getArgs().hasArg(options::OPT__SLASH_FA) ||

diff  --git a/clang/test/Modules/clang_module_file_info.m 
b/clang/test/Modules/clang_module_file_info.m
new file mode 100644
index 0..b949c68c63903
--- /dev/null
+++ b/clang/test/Modules/clang_module_file_info.m
@@ -0,0 +1,16 @@
+
+@import DependsOnModule;
+
+// RUN: rm -rf %t %t-obj
+// RUN: %clang_cc1 -w -Wunused -fmodules -fmodule-format=obj 
-fimplicit-module-maps -fdisable-module-hash -fmodules-cache-path=%t-obj -F 
%S/Inputs -DBLARG -DWIBBLE=WOBBLE -fmodule-feature myfeature %s
+// RUN: %clang -module-file-info %t-obj/DependsOnModule.pcm | FileCheck %s
+// RUN: %clang -module-file-info %t-obj/DependsOnModule.pcm | FileCheck %s
+
+// This test is just verifying that the clang driver doesn't delete the input
+// file when -module-file-info is passed. We verify this by dumping the module
+// twice subsequently. We have other tests to verify the contents of the module
+// and the tool output (see: module_file_info.m)
+
+// CHECK: Generated by this Clang:
+
+// CHECK: Module name: DependsOnModule



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


Re: r368874 - Document clang-cpp in the release notes for clang

2019-08-15 Thread Chris Bieneman via cfe-commits
It actually does not. Getting the MSVC export list is a much harder problem. 
I'll update the release note.

-Chris

> On Aug 14, 2019, at 10:32 PM, Kim Gräsman  wrote:
> 
> On Wed, Aug 14, 2019 at 6:48 PM Chris Bieneman via cfe-commits
>  wrote:
>> 
>> Author: cbieneman
>> Date: Wed Aug 14 09:49:52 2019
>> New Revision: 368874
>> --  ...
>> +- In 9.0.0 and later Clang added a new target, clang-cpp, which generates a
>> +  shared library comprised of all the clang component libraries and 
>> exporting
>> +  the clang C++ APIs. Additionally the build system gained the new
>> +  "CLANG_LINK_CLANG_DYLIB" option, which defaults Off, and when set to On, 
>> will
>> +  force clang (and clang-based tools) to link the clang-cpp library instead 
>> of
>> +  statically linking clang's components. This option will reduce the size of
>> +  binary distributions at the expense of compiler performance.
> 
> Does this also work for Windows/MSVC builds?
> 
> Thanks,
> - Kim

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


r368874 - Document clang-cpp in the release notes for clang

2019-08-14 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Wed Aug 14 09:49:52 2019
New Revision: 368874

URL: http://llvm.org/viewvc/llvm-project?rev=368874&view=rev
Log:
Document clang-cpp in the release notes for clang

This patch adds a line in the release notes about the new clang-cpp library and 
the CMake option to force clang to link against it.

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=368874&r1=368873&r2=368874&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Wed Aug 14 09:49:52 2019
@@ -157,7 +157,15 @@ release of Clang. Users of the build sys
   install-clang-headers target now installs clang's API headers (corresponding
   to its libraries), which is consistent with the install-llvm-headers target.
 
--  ...
+- In 9.0.0 and later Clang added a new target, clang-cpp, which generates a
+  shared library comprised of all the clang component libraries and exporting
+  the clang C++ APIs. Additionally the build system gained the new
+  "CLANG_LINK_CLANG_DYLIB" option, which defaults Off, and when set to On, will
+  force clang (and clang-based tools) to link the clang-cpp library instead of
+  statically linking clang's components. This option will reduce the size of
+  binary distributions at the expense of compiler performance.
+
+- ...
 
 AST Matchers
 


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


Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

2019-07-16 Thread Chris Bieneman via cfe-commits
I get that CMake does something different for PRIVATE, but the way we use CMake 
in LLVM we really can't make a private distinction reasonable. Because we don't 
sub-divide our headers per library, we don't support per-dependency include 
paths in LLVM or Clang's libraries.

This behavior also assumes you are using `target_include_directories` to assign 
PRIVATE | PUBLIC | INTERFACE to include directories, which we don't generally 
do in LLVM (a quick grep showed one place in LLVM code excluding our google 
benchmark drop). We do generally use `include_directories` which always treats 
things as PRIVATE, so they don't cascade to dependencies.

-Chris

> On Jul 12, 2019, at 7:16 PM, Shoaib Meenai  wrote:
> 
> I struggled for a while thinking why PRIVATE might be useful in a 
> target_link_libraries call for a shared library, and then I found 
> https://cmake.org/pipermail/cmake/2016-May/063400.html 
> . The relevant bit is:
>  
> If you were paying careful attention, you would have noticed that when A
> links in B as PRIVATE, the include directories of B never propagate to
> something linking to A, but if A is a static library, then the *linking* of
> B behaves as though the relationship was PUBLIC. This
> PRIVATE-becomes-PUBLIC behaviour for static libraries only applies to the
> *linking*, not to the other dependencies (compiler options/flags and
> include search paths).
>  
> So PRIVATE/INTERFACE/PUBLIC doesn’t make any difference as far as the actual 
> linking goes, but it does affect propagation of other options, and I think 
> it’s valid to want to have a PRIVATE dependency for a static library.
>  
> From:  on behalf of Chris Bieneman 
> Date: Friday, July 12, 2019 at 9:08 AM
> To: Shoaib Meenai 
> Cc: Alex Bradbury , cfe-commits 
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> Ah! I see what is going on here. This is kinda a silliness of CMake. 
> `PRIVATE` linkage for a static archive is silly, and shouldn't be possible. 
> All link dependencies for static archives are really `INTERFACE` 
> dependencies, and it looks like CMake is doing something kinda silly instead 
> of producing a reasonable error or warning like it probably should do.
>  
> For context, `PRIVATE` linkage in the context of that change would mean 
> DirectoryWalker links something, but things that link DirectoryWalker don't. 
> That just isn't possible with static archives, so they become interface 
> dependencies (and CMake seems to insert a generator expression to make that 
> work).
>  
> In `llvm_add_library` we always use `PRIVATE` linkage for shared libraries, 
> and `INTERFACE` for static, which does the right thing.
>  
> Unless there is a better reason than a new patch coming in, I think the right 
> fix is to revert this back and expect the new patch to correct its linkage 
> behavior.
>  
> -Chris
> 
> 
> On Jul 12, 2019, at 8:53 AM, Shoaib Meenai  > wrote:
>  
> See https://reviews.llvm.org/D58418#1577670 
> .
>  More generally it would appear for any static library with a PRIVATE 
> dependency though.
>  
> I guess an alternative would be to use the LINK_LIBRARIES property (which 
> should be free of generator expressions, I believe) to propagate dependencies 
> instead of INTERFACE_LINK_LIBRARIES, and just assume that no one is gonna set 
> an INTERFACE dependency on a static library. (Supporting PRIVATE dependencies 
> on a static library definitely seems more valuable than supporting INTERFACE 
> dependencies.)
>  
> From: mailto:cbiene...@apple.com>> on behalf of Chris 
> Bieneman mailto:be...@apple.com>>
> Date: Friday, July 12, 2019 at 8:49 AM
> To: Shoaib Meenai mailto:smee...@fb.com>>
> Cc: Alex Bradbury mailto:a...@lowrisc.org>>, cfe-commits 
> mailto:cfe-commits@lists.llvm.org>>
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> One of the benefits of the object library approach for generating the clang 
> dylib is that it was compatible with BUILD_SHARED_LIBS. We had lots of issues 
> with libLLVM where people using BUILD_SHARED_LIBS would make changes that 
> broke it, so I was trying to make the clang dylib in a way that it could 
> always be enabled.
>  
> Do we know where the nested generator expression was coming from?
>  
> -Chris
> 
> 
> 
> On Jul 12, 2019, at 8:32 AM, Shoaib Meenai  > wrote:
>  
> Oops, sorry about the breakage.
>  
> Chris, aren't BUILD_SHARED_LIBS and the combined Clang dylib incompatible? 
> Should we disable building the latter if the former is set?
>  
> From: Alex Bradbury mailto:a...@lowrisc.org>>
> Date: Friday, July 12, 2019 at 2:02 AM
> To: Shoaib Meenai mailto:

Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

2019-07-12 Thread Chris Bieneman via cfe-commits
Ah! I see what is going on here. This is kinda a silliness of CMake. `PRIVATE` 
linkage for a static archive is silly, and shouldn't be possible. All link 
dependencies for static archives are really `INTERFACE` dependencies, and it 
looks like CMake is doing something kinda silly instead of producing a 
reasonable error or warning like it probably should do.

For context, `PRIVATE` linkage in the context of that change would mean 
DirectoryWalker links something, but things that link DirectoryWalker don't. 
That just isn't possible with static archives, so they become interface 
dependencies (and CMake seems to insert a generator expression to make that 
work).

In `llvm_add_library` we always use `PRIVATE` linkage for shared libraries, and 
`INTERFACE` for static, which does the right thing.

Unless there is a better reason than a new patch coming in, I think the right 
fix is to revert this back and expect the new patch to correct its linkage 
behavior.

-Chris

> On Jul 12, 2019, at 8:53 AM, Shoaib Meenai  wrote:
> 
> See https://reviews.llvm.org/D58418#1577670 
> . More generally it would appear for 
> any static library with a PRIVATE dependency though.
>  
> I guess an alternative would be to use the LINK_LIBRARIES property (which 
> should be free of generator expressions, I believe) to propagate dependencies 
> instead of INTERFACE_LINK_LIBRARIES, and just assume that no one is gonna set 
> an INTERFACE dependency on a static library. (Supporting PRIVATE dependencies 
> on a static library definitely seems more valuable than supporting INTERFACE 
> dependencies.)
>  
> From:  on behalf of Chris Bieneman 
> Date: Friday, July 12, 2019 at 8:49 AM
> To: Shoaib Meenai 
> Cc: Alex Bradbury , cfe-commits 
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> One of the benefits of the object library approach for generating the clang 
> dylib is that it was compatible with BUILD_SHARED_LIBS. We had lots of issues 
> with libLLVM where people using BUILD_SHARED_LIBS would make changes that 
> broke it, so I was trying to make the clang dylib in a way that it could 
> always be enabled.
>  
> Do we know where the nested generator expression was coming from?
>  
> -Chris
> 
> 
> On Jul 12, 2019, at 8:32 AM, Shoaib Meenai  > wrote:
>  
> Oops, sorry about the breakage.
>  
> Chris, aren't BUILD_SHARED_LIBS and the combined Clang dylib incompatible? 
> Should we disable building the latter if the former is set?
>  
> From: Alex Bradbury mailto:a...@lowrisc.org>>
> Date: Friday, July 12, 2019 at 2:02 AM
> To: Shoaib Meenai mailto:smee...@fb.com>>
> Cc: cfe-commits  >
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> On Thu, 11 Jul 2019 at 22:20, Shoaib Meenai via cfe-commits
> mailto:cfe-commits@lists.llvm.org>> wrote:
>  
> Author: smeenai
> Date: Thu Jul 11 14:20:38 2019
> New Revision: 365825
>  
> URL: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D365825-26view-3Drev&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=ETCU2JhfBcjWz-nbe6LUVSRQR0T1f3wCzxLIhKlMmQo&s=R9NSZG1XQDVSiE0wJUgb1kMUrG6bJkG3v5GDcTdkpAk&e=
>  
> 
> Log:
> [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> Any static library with a PRIVATE dependency ends up with a
> $ generator expression in its INTERFACE_LINK_LIBRARIES,
> which won't be evaluated by the $, so we end up
> with an unevaluated generator expression in the generated build file and
> Ninja chokes on the dollar sign. Just use the static library directly
> for its dependencies instead of trying to propagate dependencies
> manually.
>  
> Differential Revision: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64579&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=ETCU2JhfBcjWz-nbe6LUVSRQR0T1f3wCzxLIhKlMmQo&s=mutN2zF1KixMEVFjNzG_Q7iVJzG5ECbrU4tX3AKWLVQ&e=
>  
> 
>  
> This seems to break a -DBUILD_SHARED_LIBS build for me. It fails at
> the point of linking lib/libclang_shared.so.9svn with errors like:
> ld.lld: error: undefined symbol: llvm::llvm_unreachable_internal(char
> const*, char const*, unsigned int)
> referenced by Attributes.cpp:34 
> (/home/asb/llvm-project/clang/lib/Basic/Attributes.cpp:34)
>
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:(clang::attr::getSubjectMatchRuleS

Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies

2019-07-12 Thread Chris Bieneman via cfe-commits
One of the benefits of the object library approach for generating the clang 
dylib is that it was compatible with BUILD_SHARED_LIBS. We had lots of issues 
with libLLVM where people using BUILD_SHARED_LIBS would make changes that broke 
it, so I was trying to make the clang dylib in a way that it could always be 
enabled.

Do we know where the nested generator expression was coming from?

-Chris

> On Jul 12, 2019, at 8:32 AM, Shoaib Meenai  wrote:
> 
> Oops, sorry about the breakage.
>  
> Chris, aren't BUILD_SHARED_LIBS and the combined Clang dylib incompatible? 
> Should we disable building the latter if the former is set?
>  
> From: Alex Bradbury 
> Date: Friday, July 12, 2019 at 2:02 AM
> To: Shoaib Meenai 
> Cc: cfe-commits 
> Subject: Re: r365825 - [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> On Thu, 11 Jul 2019 at 22:20, Shoaib Meenai via cfe-commits
> mailto:cfe-commits@lists.llvm.org>> wrote:
>  
> Author: smeenai
> Date: Thu Jul 11 14:20:38 2019
> New Revision: 365825
>  
> URL: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D365825-26view-3Drev&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=ETCU2JhfBcjWz-nbe6LUVSRQR0T1f3wCzxLIhKlMmQo&s=R9NSZG1XQDVSiE0wJUgb1kMUrG6bJkG3v5GDcTdkpAk&e=
>  
> 
> Log:
> [clang-shlib] Fix clang-shlib for PRIVATE dependencies
>  
> Any static library with a PRIVATE dependency ends up with a
> $ generator expression in its INTERFACE_LINK_LIBRARIES,
> which won't be evaluated by the $, so we end up
> with an unevaluated generator expression in the generated build file and
> Ninja chokes on the dollar sign. Just use the static library directly
> for its dependencies instead of trying to propagate dependencies
> manually.
>  
> Differential Revision: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64579&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=ETCU2JhfBcjWz-nbe6LUVSRQR0T1f3wCzxLIhKlMmQo&s=mutN2zF1KixMEVFjNzG_Q7iVJzG5ECbrU4tX3AKWLVQ&e=
>  
> 
>  
> This seems to break a -DBUILD_SHARED_LIBS build for me. It fails at
> the point of linking lib/libclang_shared.so.9svn with errors like:
> ld.lld: error: undefined symbol: llvm::llvm_unreachable_internal(char
> const*, char const*, unsigned int)
> referenced by Attributes.cpp:34 
> (/home/asb/llvm-project/clang/lib/Basic/Attributes.cpp:34)
>
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:(clang::attr::getSubjectMatchRuleSpelling(clang::attr::SubjectMatchRule))
>  
> ld.lld: error: undefined symbol: llvm::llvm_unreachable_internal(char
> const*, char const*, unsigned int)
> referenced by TargetCXXABI.h:168 
> (/home/asb/llvm-project/clang/include/clang/Basic/TargetCXXABI.h:168)
>
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:(clang::TargetCXXABI::isMicrosoft()
>  const)
>  
> ld.lld: error: undefined symbol: llvm::llvm_unreachable_internal(char
> const*, char const*, unsigned int)
> referenced by TargetCXXABI.h:149 
> (/home/asb/llvm-project/clang/include/clang/Basic/TargetCXXABI.h:149)
>
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:(clang::TargetCXXABI::isItaniumFamily()
>  const)
>  
> ld.lld: error: undefined symbol: llvm::EnableABIBreakingChecks
> referenced by Attributes.cpp
>
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:(llvm::VerifyEnableABIBreakingChecks)
>  

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


Re: [PATCH] D61909: Add Clang shared library with C++ exports

2019-07-01 Thread Chris Bieneman via cfe-commits
The question is, what *should* it be called.

While yes, the 's' in 'so' is shared, the "dylib" and "dll" extensions on 
Darwin and Windows have the same meaning too. The problem is libclang.so is 
already taken.

I'm not attached to the name in any way, so I'm open to suggestions.

We do have documentation on best practices for how to build distributions, 
which includes explanations of how to pick and choose what you want to install 
(http://llvm.org/docs/BuildingADistribution.html 
), so you shouldn't need an 
option to disable it.

-Chris

> On Jul 1, 2019, at 6:13 PM, Tom Stellard via Phabricator 
>  wrote:
> 
> tstellar added a comment.
> 
> In D61909#1563678 , @sylvestre.ledru 
> wrote:
> 
>> For now, it isn't part of the debian packaging.
>> https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/blob/snapshot/debian/rules#L563
>> it is removed as packaging phase as I have been told it isn't ready.
>> 
>> Anyway, the lib should not keep this name.
>> By definition, on linux, .so means shared. It should have a more explicit 
>> name.
>> 
>> @beanz Can you please rename it? thanks
> 
> 
> I've filed a bug for this and marked it as a blocker for 9.0.0, because once 
> we ship a release with this name, it will be harder to change: 
> https://bugs.llvm.org/show_bug.cgi?id=42475
> 
> 
> Repository:
>  rC Clang
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D61909/new/
> 
> https://reviews.llvm.org/D61909
> 
> 
> 

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


r362624 - Use LTO capable linker

2019-06-05 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Wed Jun  5 10:35:38 2019
New Revision: 362624

URL: http://llvm.org/viewvc/llvm-project?rev=362624&view=rev
Log:
Use LTO capable linker

Summary:
In DistributionExample.cmake be sure we use a LTO
capable linker, the easiest to choose is lld.

Reviewers: beanz

Reviewed By: beanz

Patch By: winksaville

Subscribers: mgorny, mehdi_amini, inglorion, dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62279

Modified:
cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
cfe/trunk/cmake/caches/DistributionExample.cmake

Modified: cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample-stage2.cmake?rev=362624&r1=362623&r2=362624&view=diff
==
--- cfe/trunk/cmake/caches/DistributionExample-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/DistributionExample-stage2.cmake Wed Jun  5 10:35:38 
2019
@@ -2,7 +2,7 @@
 # bootstrap build.
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
-set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
 
 set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
 

Modified: cfe/trunk/cmake/caches/DistributionExample.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample.cmake?rev=362624&r1=362623&r2=362624&view=diff
==
--- cfe/trunk/cmake/caches/DistributionExample.cmake (original)
+++ cfe/trunk/cmake/caches/DistributionExample.cmake Wed Jun  5 10:35:38 2019
@@ -2,7 +2,7 @@
 
 #Enable LLVM projects and runtimes
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
-set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi" CACHE STRING "")
 
 # Only build the native target in stage1 since it is a throwaway build.
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
@@ -17,6 +17,11 @@ set(PACKAGE_VENDOR LLVM.org CACHE STRING
 # the proper LTO library dependencies can be connected.
 set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
 
+if (NOT APPLE)
+  # Since LLVM_ENABLE_LTO is ON we need a LTO capable linker
+  set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
+endif()
+
 # Expose stage2 targets through the stage1 build configuration.
 set(CLANG_BOOTSTRAP_TARGETS
   check-all


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


[clang-tools-extra] r362169 - Support codesigning bundles and forcing

2019-05-30 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 30 15:25:48 2019
New Revision: 362169

URL: http://llvm.org/viewvc/llvm-project?rev=362169&view=rev
Log:
Support codesigning bundles and forcing

Summary:
Clangd's framework is assembled by copying binaries from the lib and bin 
directories into a bundle shape. This results in an invalid bundle code 
signature because the signature only applies to the binaries not the resources.

This patch adds two new options to `llvm_codesign` to enable re-signing the 
library and XPC service as bundles.

The `BUNDLE_PATH` option allow specifying an explicit path to codesign, which 
enables signing bundles which aren't generated using CMake's `FRAMEWORK` or 
`BUNDLE` target properties.

The `FORCE` option allows re-signing binaries that have already been signed. 
This is required for how clangd exposes the clangd library and tools as both 
XPC and non-XPC services using the same binary.

Reviewers: jkorous, bogner

Reviewed By: bogner

Subscribers: mgorny, ilya-biryukov, dexonsmith, arphaman, kadircet, 
cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D62693

Modified:

clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake

Modified: 
clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake?rev=362169&r1=362168&r2=362169&view=diff
==
--- 
clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake 
(original)
+++ 
clang-tools-extra/trunk/clangd/xpc/cmake/modules/CreateClangdXPCFramework.cmake 
Thu May 30 15:25:48 2019
@@ -70,4 +70,9 @@ macro(create_clangd_xpc_framework target
 ${target}
 ${CLANGD_FRAMEWORK_LOCATION}
   )
+
+  # clangd is already signed as a standalone executable, so it must be forced.
+  llvm_codesign(ClangdXPC BUNDLE_PATH 
"${CLANGD_FRAMEWORK_OUT_LOCATION}/XPCServices/${CLANGD_XPC_SERVICE_NAME}.xpc/" 
FORCE)
+  # ClangdXPC library is already signed as a standalone library, so it must be 
forced.
+  llvm_codesign(ClangdXPC BUNDLE_PATH "${CLANGD_FRAMEWORK_LOCATION}" FORCE)
 endmacro(create_clangd_xpc_framework)


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


Re: [PATCH] D62279: Use LTO capable linker

2019-05-23 Thread Chris Bieneman via cfe-commits


> On May 23, 2019, at 2:40 PM, Wink Saville via Phabricator 
>  wrote:
> 
> winksaville added a comment.
> 
> In D62279#1514596 , @beanz wrote:
> 
>> @winksaville I've figured out how to resolve the `gtest` issue, but 
>> unfortunately that isn't good enough to get the `check-runtimes` target 
>> working. A change went in back in February (rL353601 
>> ), which breaks running compiler-rt's 
>> tests when building a distribution in non-trivial ways, which will 
>> unfortunately be difficult to resolve.
>> 
>> I will land the `gtest` fix sometime today, and I'm going to start working 
>> toward getting the larger issue resolved, although that is going to take 
>> some time.
> 
> 
> @beanz, glad we're making progress!
> 
> One other thing, my next goal, after we can successfully build and test the 
> `DistributionExample`,
> is to make `DistributionExample_shared`.  I envision this creating `clang` 
> that is dynamically linked
> to `libclang_shared.so` and `libLLVM.so` and also provide the corresponding 
> static libraries. Doing
> this should provide Evangelos Foutras, whose is the maintainer of the llvm 
> packages at Arch Linux,
> an "easier" path to creating llvm Arch Linux packages that don't use 
> BUILD_SHARED_LIBS.
> 
> Is this a reasonable goal and could `DistrubutionExample_shared` be added 
> along side `DistributionExample`?

The difference between the two is going to be very small, really only 3 
options. It is actually probably easier to make it an option that the 
DistributionExample cache file interprets.

It occurred to me that there is a problem with the way libclang_shared works 
right now that needs to be resolved before an option to link against it can be 
added. The issue stems from the fact that some of the larger clang-based tools 
(like clang-fuzzer) use `add_clang_library` for building their components.

The way I generated the list of components to include in libclang_shared was by 
making `add_clang_library` construct a global property list that 
libclang_shared can read the components from. This unfortunately ends up with 
the list being longer than it should be.

I can probably carve out some time to start working on all of that over the 
weekend.

-Chris

> 
> 
> Repository:
>  rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D62279/new/
> 
> https://reviews.llvm.org/D62279
> 
> 
> 

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


r361334 - Fix target property to make BUILD_SHARED_LIBS work

2019-05-21 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Tue May 21 16:50:15 2019
New Revision: 361334

URL: http://llvm.org/viewvc/llvm-project?rev=361334&view=rev
Log:
Fix target property to make BUILD_SHARED_LIBS work

Public and Private link libraries get merged in the LINK_LIBRARIES property 
instead of being kept separate.

With any luck this will get `BUILD_SHARED_LIBS` working again on Linux.

Modified:
cfe/trunk/tools/clang-shlib/CMakeLists.txt

Modified: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=361334&r1=361333&r2=361334&view=diff
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Tue May 21 16:50:15 2019
@@ -8,7 +8,7 @@ get_property(clang_libs GLOBAL PROPERTY
 foreach (lib ${clang_libs})
   list(APPEND _OBJECTS $)
   list(APPEND _DEPS $)
-  list(APPEND _DEPS $)
+  list(APPEND _DEPS $)
 endforeach ()
 
 add_clang_library(clang_shared


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


Re: [PATCH] D61909: Add Clang shared library with C++ exports

2019-05-21 Thread Chris Bieneman via cfe-commits
I don't want building libclang_shared to be disabled when 
`BUILD_SHARED_LIBS=On`. libclang_shared fulfills a completely different purpose 
from `BUILD_SHARED_LIBS`.

-Chris

> On May 21, 2019, at 12:20 PM, Ethan Sommer via Phabricator 
>  wrote:
> 
> E5ten added a comment.
> 
> @beanz Wouldn't fixing this by adding OR BUILD_SHARED_LIBS to if(ARG_SHARED) 
> in AddClang.cmake and to if (NOT LLVM_ENABLE_PIC) in 
> clang-shlib/CMakeLists.txt to prevent making libclang_shared when 
> BUILD_SHARED_LIBS is enabled make more sense?
> 
> 
> Repository:
>  rC Clang
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D61909/new/
> 
> https://reviews.llvm.org/D61909
> 
> 
> 

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


r361275 - [CMake] One more stab at fixing BUILD_SHARED_LIBS

2019-05-21 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Tue May 21 10:30:59 2019
New Revision: 361275

URL: http://llvm.org/viewvc/llvm-project?rev=361275&view=rev
Log:
[CMake] One more stab at fixing BUILD_SHARED_LIBS

If clang's libraries are build SHARED, we need to grab their 
`PRIVATE_LINK_LIBRARIES` properties and add those to clang_shared's interface.

Modified:
cfe/trunk/tools/clang-shlib/CMakeLists.txt

Modified: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=361275&r1=361274&r2=361275&view=diff
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Tue May 21 10:30:59 2019
@@ -8,6 +8,7 @@ get_property(clang_libs GLOBAL PROPERTY
 foreach (lib ${clang_libs})
   list(APPEND _OBJECTS $)
   list(APPEND _DEPS $)
+  list(APPEND _DEPS $)
 endforeach ()
 
 add_clang_library(clang_shared


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


r361271 - Fix BUILD_SHARED_LIBS for clang which broke in D61909

2019-05-21 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Tue May 21 08:56:17 2019
New Revision: 361271

URL: http://llvm.org/viewvc/llvm-project?rev=361271&view=rev
Log:
Fix BUILD_SHARED_LIBS for clang which broke in D61909

llvm_add_library ignores `BUILD_SHARED_LIBS` `STATIC` is explicitly specified. 
This restores the `BUILD_SHARED_LIBS` behavior to the clang build.

Modified:
cfe/trunk/cmake/modules/AddClang.cmake

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=361271&r1=361270&r2=361271&view=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Tue May 21 08:56:17 2019
@@ -83,7 +83,13 @@ macro(add_clang_library name)
   if(ARG_SHARED)
 set(LIBTYPE SHARED)
   else()
-set(LIBTYPE STATIC OBJECT)
+# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
+# so we need to handle it here.
+if(BUILD_SHARED_LIBS)
+  set(LIBTYPE SHARED OBJECT)
+else()
+  set(LIBTYPE STATIC OBJECT)
+endif()
 set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
   llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})


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


r361184 - [CMake] Update DistributionExample for mono repo

2019-05-20 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Mon May 20 11:10:20 2019
New Revision: 361184

URL: http://llvm.org/viewvc/llvm-project?rev=361184&view=rev
Log:
[CMake] Update DistributionExample for mono repo

This just updates the DistributionExamples from my 2016 Dev Meeting talk to 
work more seamlessly with the monorepo.

Modified:
cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
cfe/trunk/cmake/caches/DistributionExample.cmake

Modified: cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample-stage2.cmake?rev=361184&r1=361183&r2=361184&view=diff
==
--- cfe/trunk/cmake/caches/DistributionExample-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/DistributionExample-stage2.cmake Mon May 20 11:10:20 
2019
@@ -1,6 +1,9 @@
 # This file sets up a CMakeCache for the second stage of a simple distribution
 # bootstrap build.
 
+set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
+
 set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")

Modified: cfe/trunk/cmake/caches/DistributionExample.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample.cmake?rev=361184&r1=361183&r2=361184&view=diff
==
--- cfe/trunk/cmake/caches/DistributionExample.cmake (original)
+++ cfe/trunk/cmake/caches/DistributionExample.cmake Mon May 20 11:10:20 2019
@@ -1,5 +1,9 @@
 # This file sets up a CMakeCache for a simple distribution bootstrap build.
 
+#Enable LLVM projects and runtimes
+set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
+
 # Only build the native target in stage1 since it is a throwaway build.
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
 


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


Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
I did some digging before reverting. The bots your patch is failing on are 
32-bit CPUs. It looks like your static_assert is assuming 8-byte aligned 
pointers, so it always fails on the 32-bit builders.

-Chris

> On May 16, 2019, at 10:14 PM, Chris Bieneman  wrote:
> 
> Sorry to do this, but I'm also reverting r360977, because it seems to be on 
> top of this one.
> 
> -Chris
> 
>> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
>>  wrote:
>> 
>> Hey Richard,
>> 
>> This change is tripping up a bunch of the bots:
>> 
>> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
>> 
>> I'm going to revert it so that we don't leave the bots broken overnight.
>> 
>> -Chris
>> 
>>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>>>  wrote:
>>> 
>>> Author: rsmith
>>> Date: Thu May 16 18:46:05 2019
>>> New Revision: 360974
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360974&view=rev
>>> Log:
>>> Refactor constant evaluation of typeid(T) to track a symbolic type_info
>>> object rather than tracking the originating expression.
>>> 
>>> This is groundwork for supporting polymorphic typeid expressions. (Note
>>> that this somewhat regresses our support for DR1968, but it turns out
>>> that that never actually worked anyway, at least in non-trivial cases.)
>>> 
>>> Modified:
>>>  cfe/trunk/include/clang/AST/APValue.h
>>>  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>>>  cfe/trunk/lib/AST/APValue.cpp
>>>  cfe/trunk/lib/AST/ExprConstant.cpp
>>>  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>>>  cfe/trunk/lib/Sema/SemaTemplate.cpp
>>>  cfe/trunk/test/CXX/drs/dr19xx.cpp
>>>  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>>  cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>>>  cfe/trunk/test/SemaCXX/typeid.cpp
>>>  cfe/trunk/www/cxx_dr_status.html
>>> 
>>> Modified: cfe/trunk/include/clang/AST/APValue.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974&r1=360973&r2=360974&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/AST/APValue.h (original)
>>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
>>> @@ -24,14 +24,52 @@ namespace clang {
>>> class AddrLabelExpr;
>>> class ASTContext;
>>> class CharUnits;
>>> +  class CXXRecordDecl;
>>> +  class Decl;
>>> class DiagnosticBuilder;
>>> class Expr;
>>> class FieldDecl;
>>> -  class Decl;
>>> +  struct PrintingPolicy;
>>> +  class Type;
>>> class ValueDecl;
>>> -  class CXXRecordDecl;
>>> -  class QualType;
>>> 
>>> +/// Symbolic representation of typeid(T) for some type T.
>>> +class TypeInfoLValue {
>>> +  const Type *T;
>>> +
>>> +public:
>>> +  TypeInfoLValue() : T() {}
>>> +  explicit TypeInfoLValue(const Type *T);
>>> +
>>> +  const Type *getType() const { return T; }
>>> +  explicit operator bool() const { return T; }
>>> +
>>> +  void *getOpaqueValue() { return const_cast(T); }
>>> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
>>> +TypeInfoLValue V;
>>> +V.T = reinterpret_cast(Value);
>>> +return V;
>>> +  }
>>> +
>>> +  void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
>>> +};
>>> +}
>>> +
>>> +namespace llvm {
>>> +template<> struct PointerLikeTypeTraits {
>>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
>>> +return V.getOpaqueValue();
>>> +  }
>>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
>>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
>>> +  }
>>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
>>> +  // to include Type.h.
>>> +  static constexpr int NumLowBitsAvailable = 3;
>>> +};
>>> +}
>>> +
>>> +namespace clang {
>>> /// APValue - This class implements a discriminated union of [uninitialized]
>>> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
>>> /// [Vector: N * APValue], [Array: N * APValue]
>>> @@ -57,13 +95,18 @@ public:
>>> 
>>&

r360988 - Revert Refactor constant evaluation of typeid(T) to track a symbolic type_info object rather than tracking the originating expression.

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 22:46:03 2019
New Revision: 360988

URL: http://llvm.org/viewvc/llvm-project?rev=360988&view=rev
Log:
Revert Refactor constant evaluation of typeid(T) to track a symbolic type_info 
object rather than tracking the originating expression.

This reverts r360974 (git commit 7ee4307bd4450022c3c8777f43a40cc4f0ccc009)

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/drs/dr19xx.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
cfe/trunk/test/SemaCXX/typeid.cpp
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360988&r1=360987&r2=360988&view=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 22:46:03 2019
@@ -24,52 +24,14 @@ namespace clang {
   class AddrLabelExpr;
   class ASTContext;
   class CharUnits;
-  class CXXRecordDecl;
-  class Decl;
   class DiagnosticBuilder;
   class Expr;
   class FieldDecl;
-  struct PrintingPolicy;
-  class Type;
+  class Decl;
   class ValueDecl;
+  class CXXRecordDecl;
+  class QualType;
 
-/// Symbolic representation of typeid(T) for some type T.
-class TypeInfoLValue {
-  const Type *T;
-
-public:
-  TypeInfoLValue() : T() {}
-  explicit TypeInfoLValue(const Type *T);
-
-  const Type *getType() const { return T; }
-  explicit operator bool() const { return T; }
-
-  void *getOpaqueValue() { return const_cast(T); }
-  static TypeInfoLValue getFromOpaqueValue(void *Value) {
-TypeInfoLValue V;
-V.T = reinterpret_cast(Value);
-return V;
-  }
-
-  void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
-};
-}
-
-namespace llvm {
-template<> struct PointerLikeTypeTraits {
-  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
-return V.getOpaqueValue();
-  }
-  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
-return clang::TypeInfoLValue::getFromOpaqueValue(P);
-  }
-  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
-  // to include Type.h.
-  static constexpr int NumLowBitsAvailable = 3;
-};
-}
-
-namespace clang {
 /// APValue - This class implements a discriminated union of [uninitialized]
 /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
 /// [Vector: N * APValue], [Array: N * APValue]
@@ -95,18 +57,13 @@ public:
 
   class LValueBase {
   public:
-typedef llvm::PointerUnion
-PtrTy;
+typedef llvm::PointerUnion PtrTy;
 
-LValueBase() : Local{} {}
+LValueBase() : CallIndex(0), Version(0) {}
 
 template 
-LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
-  assert(!is() &&
- "don't use this constructor to form a type_info lvalue");
-}
-
-static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
+LValueBase(T P, unsigned I = 0, unsigned V = 0)
+: Ptr(P), CallIndex(I), Version(V) {}
 
 template 
 bool is() const { return Ptr.is(); }
@@ -121,15 +78,28 @@ public:
 
 bool isNull() const;
 
-explicit operator bool() const;
+explicit operator bool () const;
 
-PtrTy getPointer() const { return Ptr; }
+PtrTy getPointer() const {
+  return Ptr;
+}
 
-unsigned getCallIndex() const;
-unsigned getVersion() const;
-QualType getTypeInfoType() const;
+unsigned getCallIndex() const {
+  return CallIndex;
+}
 
-friend bool operator==(const LValueBase &LHS, const LValueBase &RHS);
+void setCallIndex(unsigned Index) {
+  CallIndex = Index;
+}
+
+unsigned getVersion() const {
+  return Version;
+}
+
+friend bool operator==(const LValueBase &LHS, const LValueBase &RHS) {
+  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
+ LHS.Version == RHS.Version;
+}
 friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS) {
   return !(LHS == RHS);
 }
@@ -137,14 +107,7 @@ public:
 
   private:
 PtrTy Ptr;
-struct LocalState {
-  unsigned CallIndex, Version;
-};
-union {
-  LocalState Local;
-  /// The type std::type_info, if this is a TypeInfoLValue.
-  void *TypeInfoType;
-};
+unsigned CallIndex, Version;
   };
 
   /// A FieldDecl or CXXRecordDecl, along with a flag indicating whether we

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=360988&r1=360987&r2=360988&view=diff

r360987 - Revert [c++20] P1327R1: Support for typeid applied to objects of polymorphic class type in constant evaluation.

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 22:45:57 2019
New Revision: 360987

URL: http://llvm.org/viewvc/llvm-project?rev=360987&view=rev
Log:
Revert [c++20] P1327R1: Support for typeid applied to objects of polymorphic 
class type in constant evaluation.

This reverts r360977 (git commit f51dc8d2f98f4029247552bc45ef53628ab3b6b9)

Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=360987&r1=360986&r2=360987&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Thu May 16 22:45:57 2019
@@ -12,8 +12,7 @@ let Component = "AST" in {
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
   "%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
-  " a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
-  "%select{| in C++ standards before C++2a||}0">;
+  " a reinterpret_cast|cast from %1}0 is not allowed in a constant 
expression">;
 def note_constexpr_invalid_downcast : Note<
   "cannot cast object of dynamic type %0 to type %1">;
 def note_constexpr_overflow : Note<
@@ -32,13 +31,12 @@ def note_constexpr_invalid_inhctor : Not
 def note_constexpr_no_return : Note<
   "control reached end of constexpr function">;
 def note_constexpr_virtual_call : Note<
-  "cannot evaluate call to virtual function in a constant expression "
-  "in C++ standards before C++2a">;
+  "cannot evaluate call to virtual function in a constant expression">;
 def note_constexpr_pure_virtual_call : Note<
   "pure virtual function %q0 called">;
 def note_constexpr_polymorphic_unknown_dynamic_type : Note<
-  "%select{virtual function called on|dynamic_cast applied to|"
-  "typeid applied to}0 object '%1' whose dynamic type is not constant">;
+  "%select{virtual function called on|dynamic_cast applied to}0 "
+  "object '%1' whose dynamic type is not constant">;
 def note_constexpr_dynamic_cast_to_reference_failed : Note<
   "reference dynamic_cast failed: %select{"
   "static type %1 of operand is a non-public base class of dynamic type %2|"
@@ -92,7 +90,7 @@ def note_constexpr_var_init_non_constant
   "initializer of %0 is not a constant expression">;
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
-  "not allowed in a constant expression in C++ standards before C++2a">;
+  "not allowed in a constant expression">;
 def note_constexpr_void_comparison : Note<
   "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
@@ -110,11 +108,11 @@ def note_constexpr_this : Note<
   "evaluation of a call to a 'constexpr' member function">;
 def note_constexpr_lifetime_ended : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "%select{temporary|variable}1 whose lifetime has ended">;
 def note_constexpr_access_uninit : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "object outside its lifetime is not allowed in a constant expression">;
 def note_constexpr_use_uninit_reference : Note<
   "use of reference outside its lifetime "
@@ -141,30 +139,30 @@ def note_constexpr_ltor_incomplete_type
   "read of incomplete type %0 is not allowed in a constant expression">;
 def note_constexpr_access_null : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "dereferenced null pointer is not allowed in a constant expression">;
 def note_constexpr_access_past_end : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "dereferenced one-past-the-end pointer is not allowed in a constant 
expression">;
 def note_constexpr_access_unsized_array : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "element of array without known bound "
   "is not allowed in a constant expression">;
 def note_constexpr_access_inactive_union_member : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "member %1 of union with %select{active member %3|no active member}2 "
   "is not allowed in a constant expressio

Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
Sorry to do this, but I'm also reverting r360977, because it seems to be on top 
of this one.

-Chris

> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
>  wrote:
> 
> Hey Richard,
> 
> This change is tripping up a bunch of the bots:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
> 
> I'm going to revert it so that we don't leave the bots broken overnight.
> 
> -Chris
> 
>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>>  wrote:
>> 
>> Author: rsmith
>> Date: Thu May 16 18:46:05 2019
>> New Revision: 360974
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=360974&view=rev
>> Log:
>> Refactor constant evaluation of typeid(T) to track a symbolic type_info
>> object rather than tracking the originating expression.
>> 
>> This is groundwork for supporting polymorphic typeid expressions. (Note
>> that this somewhat regresses our support for DR1968, but it turns out
>> that that never actually worked anyway, at least in non-trivial cases.)
>> 
>> Modified:
>>   cfe/trunk/include/clang/AST/APValue.h
>>   cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>>   cfe/trunk/lib/AST/APValue.cpp
>>   cfe/trunk/lib/AST/ExprConstant.cpp
>>   cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>>   cfe/trunk/lib/Sema/SemaTemplate.cpp
>>   cfe/trunk/test/CXX/drs/dr19xx.cpp
>>   cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>   cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>>   cfe/trunk/test/SemaCXX/typeid.cpp
>>   cfe/trunk/www/cxx_dr_status.html
>> 
>> Modified: cfe/trunk/include/clang/AST/APValue.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974&r1=360973&r2=360974&view=diff
>> ==
>> --- cfe/trunk/include/clang/AST/APValue.h (original)
>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
>> @@ -24,14 +24,52 @@ namespace clang {
>>  class AddrLabelExpr;
>>  class ASTContext;
>>  class CharUnits;
>> +  class CXXRecordDecl;
>> +  class Decl;
>>  class DiagnosticBuilder;
>>  class Expr;
>>  class FieldDecl;
>> -  class Decl;
>> +  struct PrintingPolicy;
>> +  class Type;
>>  class ValueDecl;
>> -  class CXXRecordDecl;
>> -  class QualType;
>> 
>> +/// Symbolic representation of typeid(T) for some type T.
>> +class TypeInfoLValue {
>> +  const Type *T;
>> +
>> +public:
>> +  TypeInfoLValue() : T() {}
>> +  explicit TypeInfoLValue(const Type *T);
>> +
>> +  const Type *getType() const { return T; }
>> +  explicit operator bool() const { return T; }
>> +
>> +  void *getOpaqueValue() { return const_cast(T); }
>> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
>> +TypeInfoLValue V;
>> +V.T = reinterpret_cast(Value);
>> +return V;
>> +  }
>> +
>> +  void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
>> +};
>> +}
>> +
>> +namespace llvm {
>> +template<> struct PointerLikeTypeTraits {
>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
>> +return V.getOpaqueValue();
>> +  }
>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
>> +  }
>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
>> +  // to include Type.h.
>> +  static constexpr int NumLowBitsAvailable = 3;
>> +};
>> +}
>> +
>> +namespace clang {
>> /// APValue - This class implements a discriminated union of [uninitialized]
>> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
>> /// [Vector: N * APValue], [Array: N * APValue]
>> @@ -57,13 +95,18 @@ public:
>> 
>>  class LValueBase {
>>  public:
>> -typedef llvm::PointerUnion PtrTy;
>> +typedef llvm::PointerUnion> TypeInfoLValue>
>> +PtrTy;
>> 
>> -LValueBase() : CallIndex(0), Version(0) {}
>> +LValueBase() : Local{} {}
>> 
>>template 
>> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
>> -: Ptr(P), CallIndex(I), Version(V) {}
>> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
>> +  assert(!is() &&
>> + "don't use this constructor to form a type_info lvalue");
>> +}
>> +
>> +static LValueBase ge

Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
Hey Richard,

This change is tripping up a bunch of the bots:

http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397

I'm going to revert it so that we don't leave the bots broken overnight.

-Chris

> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>  wrote:
> 
> Author: rsmith
> Date: Thu May 16 18:46:05 2019
> New Revision: 360974
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=360974&view=rev
> Log:
> Refactor constant evaluation of typeid(T) to track a symbolic type_info
> object rather than tracking the originating expression.
> 
> This is groundwork for supporting polymorphic typeid expressions. (Note
> that this somewhat regresses our support for DR1968, but it turns out
> that that never actually worked anyway, at least in non-trivial cases.)
> 
> Modified:
>cfe/trunk/include/clang/AST/APValue.h
>cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>cfe/trunk/lib/AST/APValue.cpp
>cfe/trunk/lib/AST/ExprConstant.cpp
>cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>cfe/trunk/lib/Sema/SemaTemplate.cpp
>cfe/trunk/test/CXX/drs/dr19xx.cpp
>cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>cfe/trunk/test/SemaCXX/typeid.cpp
>cfe/trunk/www/cxx_dr_status.html
> 
> Modified: cfe/trunk/include/clang/AST/APValue.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974&r1=360973&r2=360974&view=diff
> ==
> --- cfe/trunk/include/clang/AST/APValue.h (original)
> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
> @@ -24,14 +24,52 @@ namespace clang {
>   class AddrLabelExpr;
>   class ASTContext;
>   class CharUnits;
> +  class CXXRecordDecl;
> +  class Decl;
>   class DiagnosticBuilder;
>   class Expr;
>   class FieldDecl;
> -  class Decl;
> +  struct PrintingPolicy;
> +  class Type;
>   class ValueDecl;
> -  class CXXRecordDecl;
> -  class QualType;
> 
> +/// Symbolic representation of typeid(T) for some type T.
> +class TypeInfoLValue {
> +  const Type *T;
> +
> +public:
> +  TypeInfoLValue() : T() {}
> +  explicit TypeInfoLValue(const Type *T);
> +
> +  const Type *getType() const { return T; }
> +  explicit operator bool() const { return T; }
> +
> +  void *getOpaqueValue() { return const_cast(T); }
> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
> +TypeInfoLValue V;
> +V.T = reinterpret_cast(Value);
> +return V;
> +  }
> +
> +  void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
> +};
> +}
> +
> +namespace llvm {
> +template<> struct PointerLikeTypeTraits {
> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
> +return V.getOpaqueValue();
> +  }
> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
> +  }
> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
> +  // to include Type.h.
> +  static constexpr int NumLowBitsAvailable = 3;
> +};
> +}
> +
> +namespace clang {
> /// APValue - This class implements a discriminated union of [uninitialized]
> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
> /// [Vector: N * APValue], [Array: N * APValue]
> @@ -57,13 +95,18 @@ public:
> 
>   class LValueBase {
>   public:
> -typedef llvm::PointerUnion PtrTy;
> +typedef llvm::PointerUnion TypeInfoLValue>
> +PtrTy;
> 
> -LValueBase() : CallIndex(0), Version(0) {}
> +LValueBase() : Local{} {}
> 
> template 
> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
> -: Ptr(P), CallIndex(I), Version(V) {}
> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
> +  assert(!is() &&
> + "don't use this constructor to form a type_info lvalue");
> +}
> +
> +static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
> 
> template 
> bool is() const { return Ptr.is(); }
> @@ -78,28 +121,15 @@ public:
> 
> bool isNull() const;
> 
> -explicit operator bool () const;
> +explicit operator bool() const;
> 
> -PtrTy getPointer() const {
> -  return Ptr;
> -}
> +PtrTy getPointer() const { return Ptr; }
> 
> -unsigned getCallIndex() const {
> -  return CallIndex;
> -}
> +unsigned getCallIndex() const;
> +unsigned getVersion() const;
> +QualType getTypeInfoType() const;
> 
> -void setCallIndex(unsigned Index) {
> -  CallIndex = Index;
> -}
> -
> -unsigned getVersion() const {
> -  return Version;
> -}
> -
> -friend bool operator==(const LValueBase &LHS, const LValueBase &RHS) {
> -  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
> - LHS.Version == RHS.Version;
> -}
> +friend bool operator==(const LValueBase &LHS, const LValueBase &RHS);
> friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS

r360985 - Re-land: Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 21:20:01 2019
New Revision: 360985

URL: http://llvm.org/viewvc/llvm-project?rev=360985&view=rev
Log:
Re-land: Add Clang shared library with C++ exports

Summary:
This patch adds a libClang_shared library on *nix systems which exports the 
entire C++ API. In order to support this on Windows we should really refactor 
llvm-shlib and share code between the two.

This also uses a slightly different method for generating the shared library, 
which I should back-port to llvm-shlib. Instead of linking the static archives 
and passing linker flags to force loading the whole libraries, this patch 
creates object libraries for every library (which has no cost in the build 
system), and link the object libraries.

Added:
cfe/trunk/tools/clang-shlib/
cfe/trunk/tools/clang-shlib/CMakeLists.txt
cfe/trunk/tools/clang-shlib/clang-shlib.cpp
Modified:
cfe/trunk/cmake/modules/AddClang.cmake
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360985&r1=360984&r2=360985&view=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 21:20:01 2019
@@ -81,9 +81,12 @@ macro(add_clang_library name)
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360985&r1=360984&r2=360985&view=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 21:20:01 2019
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)

Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360985&view=auto
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 21:20:01 2019
@@ -0,0 +1,18 @@
+# Building libclang_shared.so fails if LLVM_ENABLE_PIC=Off
+if (NOT LLVM_ENABLE_PIC)
+  return()
+endif()
+
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})

Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360985&view=auto
==
--- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)
+++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 21:20:01 2019
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy


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


Re: r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
I’ll re-land disabling if PIC is off.

This doesn’t replace the static libraries with object libraries, it just 
creates an object library target (named obj.${name}) for each static library. 
That allows the objects to be referenced separately from the archives, so we 
don’t have to do the -load-all/—whole-archive stuff we do for libLLVM.

-Chris

> On May 16, 2019, at 6:40 PM, Nico Weber  wrote:
> 
> To not keep the build broken over night, and since it's a small change that 
> should be easy to reland, I've reverted this for now in r360973.
> 
>> On Thu, May 16, 2019 at 8:52 PM Nico Weber  wrote:
>> Hello,
>> 
>> this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target 
>> shouldn't be build in those builds?
>> 
>> 
>> Also, if I read this right, this makes static libraries for clang always be 
>> object libraries. Is that correct? If so, this likely makes the normal clang 
>> binary larger and less efficient than before: Normal static libraries only 
>> get referenced .o files in them loaded, while all files in object libraries 
>> are loaded by the linker. In theory, --gc-sections should drop the ones that 
>> aren't needed, but due to static initializers and so on that doesn't always 
>> work. (When we moved Chrome's build to GN, the thinking was for a long time 
>> that we'd use object libraries instead of static libraries everywhere. Turns 
>> out that made the binary 10% larger and slower and we had to paddle back.)
>> 
>> 
>> 
>> [2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
>> FAILED: lib/libclang_shared.so.9svn 
>> ...
>> /usr/bin/ld: 
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: 
>> relocation R_X86_64_32 against 
>> `.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__'
>>  can not be used when making a shared object; recompile with -fPIC
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: error 
>> adding symbols: Bad value
>> collect2: error: ld returned 1 exit status
>> 
>>> On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits 
>>>  wrote:
>>> Author: cbieneman
>>> Date: Thu May 16 15:06:07 2019
>>> New Revision: 360946
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360946&view=rev
>>> Log:
>>> Add Clang shared library with C++ exports
>>> 
>>> Summary:
>>> This patch adds a libClang_shared library on *nix systems which exports the 
>>> entire C++ API. In order to support this on Windows we should really 
>>> refactor llvm-shlib and share code between the two.
>>> 
>>> This also uses a slightly different method for generating the shared 
>>> library, which I should back-port to llvm-shlib. Instead of linking the 
>>> static archives and passing linker flags to force loading the whole 
>>> libraries, this patch creates object libraries for every library (which has 
>>> no cost in the build system), and link the object libraries.
>>> 
>>> Reviewers: tstellar, winksaville
>>> 
>>> Subscribers: mgorny, cfe-commits
>>> 
>>> Tags: #clang
>>> 
>>> Differential Revision: https://reviews.llvm.org/D61909
>>> 
>>> Added:
>>> cfe/trunk/tools/clang-shlib/
>>> cfe/trunk/tools/clang-shlib/CMakeLists.txt
>>> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>>> Modified:
>>> cfe/trunk/cmake/modules/AddClang.cmake
>>> cfe/trunk/tools/CMakeLists.txt
>>> 
>>> Modified: cfe/trunk/cmake/modules/AddClang.cmake
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff
>>> ==
>>> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
>>> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
>>> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>>>)
>>>endif()
>>>if(ARG_SHARED)
>>> -set(ARG_ENABLE_SHARED SHARED)
>>> +set(LIBTYPE SHARED)
>>> +  else()
>>> +set(LIBTYPE STATIC OBJECT)
>>> +set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>>>endif()
>>> -  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
>>> ${srcs})
>>> +  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs

r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 15:06:07 2019
New Revision: 360946

URL: http://llvm.org/viewvc/llvm-project?rev=360946&view=rev
Log:
Add Clang shared library with C++ exports

Summary:
This patch adds a libClang_shared library on *nix systems which exports the 
entire C++ API. In order to support this on Windows we should really refactor 
llvm-shlib and share code between the two.

This also uses a slightly different method for generating the shared library, 
which I should back-port to llvm-shlib. Instead of linking the static archives 
and passing linker flags to force loading the whole libraries, this patch 
creates object libraries for every library (which has no cost in the build 
system), and link the object libraries.

Reviewers: tstellar, winksaville

Subscribers: mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61909

Added:
cfe/trunk/tools/clang-shlib/
cfe/trunk/tools/clang-shlib/CMakeLists.txt
cfe/trunk/tools/clang-shlib/clang-shlib.cpp
Modified:
cfe/trunk/cmake/modules/AddClang.cmake
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
@@ -81,9 +81,12 @@ macro(add_clang_library name)
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946&r1=360945&r2=360946&view=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)

Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946&view=auto
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019
@@ -0,0 +1,13 @@
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})

Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360946&view=auto
==
--- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)
+++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 15:06:07 2019
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy


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


r339829 - [Darwin Driver] Fix Simulator builtins and test cases

2018-08-15 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Wed Aug 15 15:50:06 2018
New Revision: 339829

URL: http://llvm.org/viewvc/llvm-project?rev=339829&view=rev
Log:
[Darwin Driver] Fix Simulator builtins and test cases

In r339807, I broke linking the builtins libraries for simulator targets, which 
itself was bad, but turns out it was all completely untested and marked with 
FIXME in the test suite.

This fixes all the test cases so they actually work, and fixes the bug I 
introduced in r339807.

Added:
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/

cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_tvos.a

cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_watchos.a
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.ios.a
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.osx.a

cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.profile_tvos.a

cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.profile_watchos.a
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.tvos.a
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.watchos.a
Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Driver/ToolChains/Darwin.h
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=339829&r1=339828&r2=339829&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Aug 15 15:50:06 2018
@@ -916,8 +916,10 @@ void MachO::AddLinkRuntimeLib(const ArgL
 DarwinLibName += Component;
 if (!(Opts & RLO_IsEmbedded))
   DarwinLibName += "_";
-  }
-  DarwinLibName += getOSLibraryNameSuffix();
+DarwinLibName += getOSLibraryNameSuffix();
+  } else
+DarwinLibName += getOSLibraryNameSuffix(true);
+
   DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
   SmallString<128> Dir(getDriver().ResourceDir);
   llvm::sys::path::append(
@@ -983,16 +985,19 @@ StringRef Darwin::getSDKName(StringRef i
   return "";
 }
 
-StringRef Darwin::getOSLibraryNameSuffix() const {
-  switch(TargetPlatform) {
+StringRef Darwin::getOSLibraryNameSuffix(bool IgnoreSim) const {
+  switch (TargetPlatform) {
   case DarwinPlatformKind::MacOS:
 return "osx";
   case DarwinPlatformKind::IPhoneOS:
-return TargetEnvironment == NativeEnvironment ? "ios" : "iossim";
+return TargetEnvironment == NativeEnvironment || IgnoreSim ? "ios"
+   : "iossim";
   case DarwinPlatformKind::TvOS:
-return TargetEnvironment == NativeEnvironment ? "tvos" : "tvossim";
+return TargetEnvironment == NativeEnvironment || IgnoreSim ? "tvos"
+   : "tvossim";
   case DarwinPlatformKind::WatchOS:
-return TargetEnvironment == NativeEnvironment ? "watchos" : "watchossim";
+return TargetEnvironment == NativeEnvironment || IgnoreSim ? "watchos"
+   : "watchossim";
   }
   llvm_unreachable("Unsupported platform");
 }

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.h?rev=339829&r1=339828&r2=339829&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.h Wed Aug 15 15:50:06 2018
@@ -252,7 +252,9 @@ public:
 return llvm::ExceptionHandling::None;
   }
 
-  virtual StringRef getOSLibraryNameSuffix() const { return ""; }
+  virtual StringRef getOSLibraryNameSuffix(bool IgnoreSim = false) const {
+return "";
+  }
 
   /// }
 };
@@ -420,7 +422,7 @@ protected:
  Action::OffloadKind DeviceOffloadKind) const 
override;
 
   StringRef getPlatformFamily() const;
-  StringRef getOSLibraryNameSuffix() const override;
+  StringRef getOSLibraryNameSuffix(bool IgnoreSim = false) const override;
 
 public:
   static StringRef getSDKName(StringRef isysroot);

Added: 
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_tvos.a
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_tvos.a?rev=339829&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_watchos.a
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.cc_kext_watchos.a?rev=339829&view=auto
==
(empty)

Added: cfe/trunk/test/Driver/I

  1   2   3   4   5   >