[llvm-branch-commits] [clang] 0b32d5f - Revert "[clang] Add tanf16 builtin and support for tan constrained intrinsic (#93314)"

2024-05-29 Thread Farzon Lotfi via llvm-branch-commits

Author: Farzon Lotfi
Date: 2024-05-29T15:14:21-04:00
New Revision: 0b32d5fc9e9719a742e24e1a470bd0db7e53b8f7

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

LOG: Revert "[clang] Add tanf16 builtin and support for tan constrained 
intrinsic (#93314)"

This reverts commit b15a0a37404f36bcd9c7995de8cd16f9cb5ac8af.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/math-builtins.c
clang/test/CodeGen/constrained-math-builtins.c
clang/test/CodeGen/math-libcalls.c
clang/test/CodeGenOpenCL/builtins-f16.cl
llvm/docs/LangRef.rst
llvm/include/llvm/CodeGen/ISDOpcodes.h
llvm/include/llvm/IR/ConstrainedOps.def
llvm/include/llvm/IR/Intrinsics.td
llvm/test/Assembler/fp-intrinsics-attr.ll
llvm/test/Feature/fp-intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 7bef5fd7ad40f..11982af3fa609 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -482,11 +482,11 @@ def SqrtF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T)";
 }
 
-def TanF16F128 : Builtin, F16F128MathTemplate {
-  let Spellings = ["__builtin_tan"];
+def TanF128 : Builtin {
+  let Spellings = ["__builtin_tanf128"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
 ConstIgnoringErrnoAndExceptions];
-  let Prototype = "T(T)";
+  let Prototype = "__float128(__float128)";
 }
 
 def TanhF128 : Builtin {

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 94a7036f6233c..266bf41fd5577 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2923,18 +2923,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   SetSqrtFPAccuracy(Call);
   return RValue::get(Call);
 }
-
-case Builtin::BItan:
-case Builtin::BItanf:
-case Builtin::BItanl:
-case Builtin::BI__builtin_tan:
-case Builtin::BI__builtin_tanf:
-case Builtin::BI__builtin_tanf16:
-case Builtin::BI__builtin_tanl:
-case Builtin::BI__builtin_tanf128:
-  return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
-  *this, E, Intrinsic::tan, Intrinsic::experimental_constrained_tan));
-
 case Builtin::BItrunc:
 case Builtin::BItruncf:
 case Builtin::BItruncl:

diff  --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 1e0f129b98610..093239b448260 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -674,10 +674,10 @@ __builtin_sqrt(f);   __builtin_sqrtf(f);  
__builtin_sqrtl(f); __builtin_
 
 __builtin_tan(f);__builtin_tanf(f);   __builtin_tanl(f); 
__builtin_tanf128(f);
 
-// NO__ERRNO: declare double @llvm.tan.f64(double) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare float @llvm.tan.f32(float) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare x86_fp80 @llvm.tan.f80(x86_fp80) [[READNONE_INTRINSIC]]
-// NO__ERRNO: declare fp128 @llvm.tan.f128(fp128) [[READNONE_INTRINSIC]]
+// NO__ERRNO: declare double @tan(double noundef) [[READNONE]]
+// NO__ERRNO: declare float @tanf(float noundef) [[READNONE]]
+// NO__ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[READNONE]]
+// NO__ERRNO: declare fp128 @tanf128(fp128 noundef) [[READNONE]]
 // HAS_ERRNO: declare double @tan(double noundef) [[NOT_READNONE]]
 // HAS_ERRNO: declare float @tanf(float noundef) [[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @tanl(x86_fp80 noundef) [[NOT_READNONE]]

diff  --git a/clang/test/CodeGen/constrained-math-builtins.c 
b/clang/test/CodeGen/constrained-math-builtins.c
index 6cc3a10a1e794..2de832dd2b6ca 100644
--- a/clang/test/CodeGen/constrained-math-builtins.c
+++ b/clang/test/CodeGen/constrained-math-builtins.c
@@ -183,14 +183,6 @@ void foo(double *d, float f, float *fp, long double *l, 
int *i, const char *c, _
 // CHECK: call x86_fp80 @llvm.experimental.constrained.sqrt.f80(x86_fp80 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 // CHECK: call fp128 @llvm.experimental.constrained.sqrt.f128(fp128 %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
 
-  __builtin_tan(f);__builtin_tanf(f);   __builtin_tanl(f); 
__builtin_tanf128(f);
-
-// CHECK: call double @llvm.experimental.constrained.tan.f64(double %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK: call float @llvm.experimental.constrained.tan.f32(float %{{.*}}, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK: call x86_fp80 @llvm.experimental.constrained.tan.f80(x86_fp80 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")

[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-26 Thread Farzon Lotfi via llvm-branch-commits

farzonl wrote:

> HLSL allows StructuredBuffer<> to be defined with scalar or up-to-4-element 
> vectors as well as with structs, but when doing so `dxc` doesn't set the 
> alignment. Emulate this behaviour.

*behavior

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


[llvm-branch-commits] [DXIL][Analysis] Make alignment on StructuredBuffer optional (PR #100697)

2024-07-26 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Remove new-pm versions of DXILResource passes. NFC (PR #100698)

2024-07-26 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits


@@ -289,6 +289,43 @@ class OpLowerer {
 });
   }
 
+  void lowerTypedBufferStore(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+Type *Int8Ty = IRB.getInt8Ty();
+Type *Int32Ty = IRB.getInt32Ty();
+
+replaceFunction(F, [&](CallInst *CI) -> Error {

farzonl wrote:

why does this need to be a lambda?

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


[llvm-branch-commits] [DirectX] Revert specialized createOp methods part of #101250 (PR #104245)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Differentiate between 0/1 overloads in the OpBuilder. NFC (PR #104246)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

farzonl wrote:

Your description and the bug you are adressing make sense. One point of 
confusion I see now is our mapping of intrinsics to DXIL Ops. The intrinsics 
still all use `LLVMType`. Is that going to ba problem?

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


[llvm-branch-commits] [DirectX] Use a more consistent pass name for DXILTranslateMetadata (PR #104249)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

farzonl wrote:

> > Your description and the bug you are adressing make sense. One point of 
> > confusion I see now is our mapping of intrinsics to DXIL Ops. The 
> > intrinsics still all use `LLVMType`. Is that going to be problem?
> 
> I don't see why it would. LLVMType is perfectly reasonable for describing 
> LLVM intrinsics. DXIL ops, on the other hand, use a number of specific 
> `dx.types.*` struct types that aren't easy to describe with LLVMType and it 
> wouldn't make sense to extend it to do so. Also, there are far fewer types 
> that come up with DXIL ops, so the full flexibility of LLVMType isn't needed, 
> hence this simpler approach.

I saw that we were representing typed buffers as `llvm_anyvector_ty` in the 
intrinsic and I thought that might also be a case where we are using a very 
broad type. I'm not sure if it matters though.

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


[llvm-branch-commits] [DirectX] Disentangle DXIL.td's op types from LLVMType. NFC (PR #104247)

2024-08-14 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Encapsulate DXILOpLowering's state into a class. NFC (PR #104248)

2024-08-15 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [DirectX] Register a few DXIL passes with the new PM (PR #104250)

2024-08-15 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

2024-08-21 Thread Farzon Lotfi via llvm-branch-commits


@@ -10,23 +10,235 @@
 #include "DXILResourceAnalysis.h"
 #include "DirectX.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Analysis/DXILResource.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
-static void prettyPrintResources(raw_ostream &OS,
+static constexpr StringRef getRCName(dxil::ResourceClass RC) {

farzonl wrote:

Feel free to ignore, I was thinking of a different  way to do this that would 
have a tighter coupling of  Names and prefixes:

```cpp
struct ResourceClassInfo {
  const StringRef name;
  const StringRef prefix;
};

llvm::DenseMap createResourceClassMap() 
{
  return {
{dxil::ResourceClass::SRV, {"SRV", "t"}},
{dxil::ResourceClass::UAV, {"UAV", "u"}},
{dxil::ResourceClass::CBuffer, {"cbuffer", "cb"}},
{dxil::ResourceClass::Sampler, {"sampler", "s"}}
  };
}

static const llvm::DenseMap 
ResourceClassMap = createResourceClassMap();

StringRef getRCName(dxil::ResourceClass RC) {
  return ResourceClassMap.lookup(RC).name;
}

StringRef getRCPrefix(dxil::ResourceClass RC) {
  return ResourceClassMap.lookup(RC).prefix;
}
```

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


[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

2024-08-21 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104448
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Add resource handling to the DXIL pretty printer (PR #104448)

2024-08-21 Thread Farzon Lotfi via llvm-branch-commits

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

LGTM

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -361,11 +361,60 @@ Examples:
  - ``i32``
  - Index into the buffer
 
+Texture and Typed Buffer Stores
+---
+
+*relevant types: Textures and TypedBuffer*
+
+The `TextureStore`_ and `BufferStore`_ DXIL operations can only be used to

farzonl wrote:

```suggestion 
The `TextureStore`_ and `BufferStore`_ DXIL operations are only allowed to
```

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -361,11 +361,60 @@ Examples:
  - ``i32``
  - Index into the buffer
 
+Texture and Typed Buffer Stores
+---
+
+*relevant types: Textures and TypedBuffer*
+
+The `TextureStore`_ and `BufferStore`_ DXIL operations can only be used to
+write all 4 32-bit elements to a texture or a typed buffer. Note that both of

farzonl wrote:

```suggestion
 write all four 32-bit elements (components) at once to a texture or a typed 
buffer.
```

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -361,11 +361,60 @@ Examples:
  - ``i32``
  - Index into the buffer
 
+Texture and Typed Buffer Stores
+---
+
+*relevant types: Textures and TypedBuffer*
+
+The `TextureStore`_ and `BufferStore`_ DXIL operations can only be used to
+write all 4 32-bit elements to a texture or a typed buffer. Note that both of
+these operations do have a mask parameter, but it is documented that it must

farzonl wrote:

```suggestion
While both operations include a mask parameter, it is specified that the mask 
must
```

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -361,11 +361,60 @@ Examples:
  - ``i32``
  - Index into the buffer
 
+Texture and Typed Buffer Stores
+---
+
+*relevant types: Textures and TypedBuffer*
+
+The `TextureStore`_ and `BufferStore`_ DXIL operations can only be used to
+write all 4 32-bit elements to a texture or a typed buffer. Note that both of
+these operations do have a mask parameter, but it is documented that it must
+cover all components for these types.

farzonl wrote:

```suggestion
always cover all components when used with these types.
```

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -94,6 +95,7 @@ class OpLowerer {
 DiagnosticInfoUnsupported Diag(*CI->getFunction(), Message,
CI->getDebugLoc());
 M.getContext().diagnose(Diag);
+HasErrors = true;

farzonl wrote:

`HasErrors ` updated in `replaceFunction` but being used in `lowerIntrinsics` 
seems like it forces synchronization.  That should be fine because we don't do 
parallel code gen. 

That said would it complicate things to much to propagate up the error from 
`replaceFunction` to `lowerTypedBufferStore` to `lowerIntrinsics`? That way we 
don't have behavior dependent on side effects.

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -289,6 +289,43 @@ class OpLowerer {
 });
   }
 
+  void lowerTypedBufferStore(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+Type *Int8Ty = IRB.getInt8Ty();
+Type *Int32Ty = IRB.getInt32Ty();
+
+replaceFunction(F, [&](CallInst *CI) -> Error {

farzonl wrote:

The thing that's throwing me here is that we have a bunch of `replaceFunction` 
Lambda's and we have a replaceFunction method in `OpLowerer` and what I'm 
wondering is why do we do methods sometimes and lambdas others times.  further 
can `lowerTypedBufferLoad` share anything with `lowerTypedBufferStore` 
`replaceFunction ` if they weren't lambdas?

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits


@@ -289,6 +289,43 @@ class OpLowerer {
 });
   }
 
+  void lowerTypedBufferStore(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+Type *Int8Ty = IRB.getInt8Ty();
+Type *Int32Ty = IRB.getInt32Ty();
+
+replaceFunction(F, [&](CallInst *CI) -> Error {

farzonl wrote:

It would help with clarity if `OpLowerer::replaceFunction`  and the specialized 
replace function behaviors had different names. 

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


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.typedBufferStore` to DXIL ops (PR #104253)

2024-09-09 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/104253
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [x86][Windows] Fix chromium build break (PR #111218)

2024-10-05 Thread Farzon Lotfi via llvm-branch-commits

farzonl wrote:

@efriedma-quic I don't have permissions to merge to the 19.x branch. If you 
think its ready please merge at your discression. 

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


[llvm-branch-commits] [llvm] [x86][Windows] Fix chromium build break (PR #111218)

2024-10-04 Thread Farzon Lotfi via llvm-branch-commits


@@ -177,6 +177,107 @@ define float @tan(float %x) #0 {
   ret float %result
 }
 
+define float @acos(float %x) #0 {

farzonl wrote:

@efriedma-quic I'm looking at the commit history of this file:
https://github.com/llvm/llvm-project/commits/release/19.x/llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll

The auto cherry pick failed because I added the test for msvc out of order in 
https://github.com/llvm/llvm-project/commit/378fe2fc23fa56181577d411fe6d51fa531cd860

That commit added some vectorizations nothing that should impact the fix.

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


[llvm-branch-commits] [llvm] [x86][Windows] Fix chromium build break (PR #111218)

2024-10-04 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/111218

Windows does not support float C89 math functions like:
- acosf
- asinf
- atanf
- coshf
- sinhf
- tanhf These 6 libfuncs need to be type promoted.

This PR fixes the bug introduced by 
https://github.com/llvm/llvm-project/pull/98949

>From 558e053c74e1ffa0db0674ecaa500023296ccd46 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Tue, 30 Jul 2024 19:53:07 -0400
Subject: [PATCH] [x86][Windows] Fix chromium build break Windows does not
 support float C89 math functions like: - acosf - asinf - atanf - coshf -
 sinhf - tanhf These 6 libfuncs need to be type promoted.

This PR fixes the bug introduced by 
https://github.com/llvm/llvm-project/pull/98949
---
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  10 +-
 .../CodeGen/X86/fp-strict-libcalls-msvc32.ll  | 107 ++
 2 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 45989bcd07d37e..10f269f8037784 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2475,8 +2475,12 @@ X86TargetLowering::X86TargetLowering(const 
X86TargetMachine &TM,
   (Subtarget.isTargetWindowsMSVC() || Subtarget.isTargetWindowsItanium()))
 // clang-format off
for (ISD::NodeType Op :
- {ISD::FCEIL,  ISD::STRICT_FCEIL,
+ {ISD::FACOS,  ISD::STRICT_FACOS,
+  ISD::FASIN,  ISD::STRICT_FASIN,
+  ISD::FATAN,  ISD::STRICT_FATAN,
+  ISD::FCEIL,  ISD::STRICT_FCEIL,
   ISD::FCOS,   ISD::STRICT_FCOS,
+  ISD::FCOSH,  ISD::STRICT_FCOSH,
   ISD::FEXP,   ISD::STRICT_FEXP,
   ISD::FFLOOR, ISD::STRICT_FFLOOR,
   ISD::FREM,   ISD::STRICT_FREM,
@@ -2484,7 +2488,9 @@ X86TargetLowering::X86TargetLowering(const 
X86TargetMachine &TM,
   ISD::FLOG10, ISD::STRICT_FLOG10,
   ISD::FPOW,   ISD::STRICT_FPOW,
   ISD::FSIN,   ISD::STRICT_FSIN,
-  ISD::FTAN,   ISD::STRICT_FTAN})
+  ISD::FSINH,  ISD::STRICT_FSINH,
+  ISD::FTAN,   ISD::STRICT_FTAN,
+  ISD::FTANH,  ISD::STRICT_FTANH})
   if (isOperationExpand(Op, MVT::f32))
 setOperationAction(Op, MVT::f32, Promote);
   // clang-format on
diff --git a/llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll 
b/llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll
index cfec52c0e68863..5d4e86afc8aceb 100644
--- a/llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll
+++ b/llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll
@@ -177,6 +177,107 @@ define float @tan(float %x) #0 {
   ret float %result
 }
 
+define float @acos(float %x) #0 {
+; CHECK-LABEL: acos:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:subl $12, %esp
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:fstpl (%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:calll _acos
+; CHECK-NEXT:fstps {{[0-9]+}}(%esp)
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:addl $12, %esp
+; CHECK-NEXT:retl
+  %result = call float @llvm.experimental.constrained.acos.f32(float %x, 
metadata !"round.dynamic", metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define float @asin(float %x) #0 {
+; CHECK-LABEL: asin:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:subl $12, %esp
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:fstpl (%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:calll _asin
+; CHECK-NEXT:fstps {{[0-9]+}}(%esp)
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:addl $12, %esp
+; CHECK-NEXT:retl
+  %result = call float @llvm.experimental.constrained.asin.f32(float %x, 
metadata !"round.dynamic", metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define float @atan(float %x) #0 {
+; CHECK-LABEL: atan:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:subl $12, %esp
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:fstpl (%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:calll _atan
+; CHECK-NEXT:fstps {{[0-9]+}}(%esp)
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:addl $12, %esp
+; CHECK-NEXT:retl
+  %result = call float @llvm.experimental.constrained.atan.f32(float %x, 
metadata !"round.dynamic", metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define float @cosh(float %x) #0 {
+; CHECK-LABEL: cosh:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:subl $12, %esp
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:fstpl (%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:calll _cosh
+; CHECK-NEXT:fstps {{[0-9]+}}(%esp)
+; CHECK-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-NEXT:wait
+; CHECK-NEXT:addl $12, %esp
+; CHECK-NEXT:retl
+  %result = call float @llvm.experimental.constrained.cosh.f32(float %x, 
metadata !"round.dynamic", metadata !"fpexcept.strict") #0
+  ret float %result
+}
+
+define float @sinh(float %x) #0 {
+; CHECK-LABEL: sinh:
+; CHECK:   # %bb.0:
+; CHECK

[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -56,9 +75,18 @@ llvm::Type 
*DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
-  case llvm::dxil::ResourceClass::CBuffer:
-llvm_unreachable("dx.CBuffer handles are not implemented yet");
-break;
+  case llvm::dxil::ResourceClass::CBuffer: {
+QualType ContainedTy = ResType->getContainedType();
+if (ContainedTy.isNull() || !ContainedTy->isStructureType())

farzonl wrote:

why would we return nullptr if the ContainedTy ia not struct? seems like we 
could return back a valid llvm::Type for this case?

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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/124886
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,201 @@
+//===- 
HLSLTargetInto.cpp--===//
+//
+// 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
+//
+//===--===//
+
+#include "HLSLTargetInfo.h"
+#include "CGHLSLRuntime.h"
+#include "TargetInfo.h"
+#include "clang/AST/DeclCXX.h"
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+namespace {
+
+// Creates a new array type with the same dimentions
+// but with the new element type.
+static llvm::Type *
+createArrayWithNewElementType(CodeGenModule &CGM,
+  const ConstantArrayType *ArrayType,
+  llvm::Type *NewElemType) {
+  const clang::Type *ArrayElemType = 
ArrayType->getArrayElementTypeNoTypeQual();
+  if (ArrayElemType->isConstantArrayType())
+NewElemType = createArrayWithNewElementType(
+CGM, cast(ArrayElemType), NewElemType);
+  return llvm::ArrayType::get(NewElemType, ArrayType->getSExtSize());
+}
+
+// Returns the size of a scalar or vector in bytes/
+static unsigned getScalarOrVectorSize(llvm::Type *Ty) {

farzonl wrote:

This function could use from a more descript name. Below are some suggestions:
```suggestion
static unsigned getScalarOrVectorByteSize(llvm::Type *Ty) {
```
```suggestion
static unsigned getScalarOrVectorStorageSize(llvm::Type *Ty) {
```
```suggestion
static unsigned getScalarOrVectorMemorySize(llvm::Type *Ty) {
```


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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/124886
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,201 @@
+//===- 
HLSLTargetInto.cpp--===//
+//
+// 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
+//
+//===--===//
+
+#include "HLSLTargetInfo.h"
+#include "CGHLSLRuntime.h"
+#include "TargetInfo.h"
+#include "clang/AST/DeclCXX.h"
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+namespace {
+
+// Creates a new array type with the same dimentions
+// but with the new element type.
+static llvm::Type *
+createArrayWithNewElementType(CodeGenModule &CGM,
+  const ConstantArrayType *ArrayType,
+  llvm::Type *NewElemType) {
+  const clang::Type *ArrayElemType = 
ArrayType->getArrayElementTypeNoTypeQual();
+  if (ArrayElemType->isConstantArrayType())
+NewElemType = createArrayWithNewElementType(
+CGM, cast(ArrayElemType), NewElemType);
+  return llvm::ArrayType::get(NewElemType, ArrayType->getSExtSize());
+}
+
+// Returns the size of a scalar or vector in bytes/
+static unsigned getScalarOrVectorSize(llvm::Type *Ty) {
+  assert(Ty->isVectorTy() || Ty->isIntegerTy() || Ty->isFloatingPointTy());
+  if (Ty->isVectorTy()) {
+llvm::FixedVectorType *FVT = cast(Ty);
+return FVT->getNumElements() *
+   (FVT->getElementType()->getScalarSizeInBits() / 8);
+  }
+  return Ty->getScalarSizeInBits() / 8;
+}
+
+} // namespace
+
+// Creates a layout type for given struct with HLSL constant buffer layout
+// taking into account Packoffsets, if provided.
+// Previously created layout types are cached in CGHLSLRuntime because
+// TargetCodeGenInto info is cannot store any data
+// (CGM.getTargetCodeGenInfo() returns a const reference to 
TargetCondegenInfo).
+//
+// The function iterates over all fields of the StructType (including base
+// classes), converts each field to its corresponding LLVM type and calculated
+// it's HLSL constant bufffer layout (offset and size). Any embedded struct (or
+// arrays of structs) are converted to target layout types as well.
+llvm::Type *CommonHLSLTargetCodeGenInfo::createHLSLBufferLayoutType(
+CodeGenModule &CGM, const RecordType *StructType,
+const SmallVector *Packoffsets) const {
+
+  // check if we already have the layout type for this struct
+  if (llvm::Type *Ty = 
CGM.getHLSLRuntime().getHLSLBufferLayoutType(StructType))
+return Ty;
+
+  SmallVector Layout;
+  SmallVector LayoutElements;
+  unsigned Index = 0; // packoffset index
+  unsigned EndOffset = 0;
+
+  // reserve first spot in the layout vector for buffer size
+  Layout.push_back(0);
+
+  // iterate over all fields of the record, including fields on base classes
+  llvm::SmallVector RecordTypes;
+  RecordTypes.push_back(StructType);
+  while (RecordTypes.back()->getAsCXXRecordDecl()->getNumBases()) {
+CXXRecordDecl *D = RecordTypes.back()->getAsCXXRecordDecl();
+assert(D->getNumBases() == 1 &&
+   "HLSL doesn't support multiple inheritance");
+RecordTypes.push_back(D->bases_begin()->getType()->getAs());
+  }
+  while (!RecordTypes.empty()) {
+const RecordType *RT = RecordTypes.back();
+RecordTypes.pop_back();
+
+for (const auto *FD : RT->getDecl()->fields()) {
+  assert(!Packoffsets || Index < Packoffsets->size() &&
+ "number of elements in layout struct does not 
"
+ "match number of packoffset annotations");
+  // Size of element; for arrays this is a size of a single element in the
+  // array. Total array size of calculated as (ArrayCount-1) * ArrayStride 
+
+  // ElemSize.
+  unsigned ElemSize = 0;
+
+  unsigned ElemOffset = 0;
+  unsigned ArrayCount = 1;
+  unsigned ArrayStride = 0;
+  unsigned NextRowOffset = llvm::alignTo(EndOffset, 16U);
+  llvm::Type *ElemLayoutTy = nullptr;
+
+  QualType FieldTy = FD->getType();
+
+  if (FieldTy->isConstantArrayType()) {
+// Unwrap array to find the element type and get combined array size.
+QualType Ty = FieldTy;
+while (Ty->isConstantArrayType()) {
+  const ConstantArrayType *ArrayTy = cast(Ty);
+  ArrayCount *= ArrayTy->getSExtSize();
+  Ty = ArrayTy->getElementType();
+}
+// For array of structures, create a new array with a layout type
+// instead of the structure type.
+if (Ty->isStructureType()) {
+  llvm::Type *NewTy = cast(
+  createHLSLBufferLayoutType(CGM, Ty->getAsStructureType()));
+  if (!NewTy)
+return nullptr;
+  asser

[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,39 @@
+//===- HLSLTargetInfo.h 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "ABIInfoImpl.h"
+#include "TargetInfo.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+class CommonHLSLTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  CommonHLSLTargetCodeGenInfo(std::unique_ptr Info)
+  : TargetCodeGenInfo(std::move(Info)) {}
+
+  // Returns LLVM target extension type "dx.Layout" or "spv.Layout"
+  // for given structure type and layout data. The first number in
+  // the Layout is the size followed by offsets for each struct element.
+  virtual llvm::Type *getHLSLLayoutType(CodeGenModule &CGM,
+llvm::StructType *LayoutStructTy,
+SmallVector Layout) const {
+return nullptr;

farzonl wrote:

Do we need a todo here? Maybe an issue tracking that this needs an 
implementation?

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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,49 @@
+; ModuleID = 
'C:\llvm-project\clang\test\CodeGenHLSL\cbuffer_and_namespaces.hlsl'

farzonl wrote:

delete?

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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,49 @@
+; ModuleID = 
'C:\llvm-project\clang\test\CodeGenHLSL\cbuffer_and_namespaces.hlsl'
+source_filename = 
"C:\\llvm-project\\clang\\test\\CodeGenHLSL\\cbuffer_and_namespaces.hlsl"

farzonl wrote:

delete?

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


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr 
*RHS,
   << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
 }
 
+void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) {
+  if (AL.getNumArgs() != 1)
+return;
+
+  StringRef Signature;
+  if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature))
+return;
+
+  SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc();
+  // FIXME: pass down below to lexer when fp is supported

farzonl wrote:

Do you have a ticket tracking this?

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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits

farzonl wrote:

Really appreciate your judicious use of comments. Helped me understand why you 
were doing certain things. 
Most of what I found seemed minor so LGTM.

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


[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits


@@ -0,0 +1,201 @@
+//===- 
HLSLTargetInto.cpp--===//
+//
+// 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
+//
+//===--===//
+
+#include "HLSLTargetInfo.h"
+#include "CGHLSLRuntime.h"
+#include "TargetInfo.h"
+#include "clang/AST/DeclCXX.h"
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+namespace {
+
+// Creates a new array type with the same dimentions
+// but with the new element type.
+static llvm::Type *
+createArrayWithNewElementType(CodeGenModule &CGM,
+  const ConstantArrayType *ArrayType,
+  llvm::Type *NewElemType) {
+  const clang::Type *ArrayElemType = 
ArrayType->getArrayElementTypeNoTypeQual();
+  if (ArrayElemType->isConstantArrayType())
+NewElemType = createArrayWithNewElementType(
+CGM, cast(ArrayElemType), NewElemType);
+  return llvm::ArrayType::get(NewElemType, ArrayType->getSExtSize());
+}
+
+// Returns the size of a scalar or vector in bytes/
+static unsigned getScalarOrVectorSize(llvm::Type *Ty) {
+  assert(Ty->isVectorTy() || Ty->isIntegerTy() || Ty->isFloatingPointTy());
+  if (Ty->isVectorTy()) {
+llvm::FixedVectorType *FVT = cast(Ty);
+return FVT->getNumElements() *
+   (FVT->getElementType()->getScalarSizeInBits() / 8);
+  }
+  return Ty->getScalarSizeInBits() / 8;
+}
+
+} // namespace
+
+// Creates a layout type for given struct with HLSL constant buffer layout
+// taking into account Packoffsets, if provided.
+// Previously created layout types are cached in CGHLSLRuntime because
+// TargetCodeGenInto info is cannot store any data
+// (CGM.getTargetCodeGenInfo() returns a const reference to 
TargetCondegenInfo).
+//
+// The function iterates over all fields of the StructType (including base
+// classes), converts each field to its corresponding LLVM type and calculated
+// it's HLSL constant bufffer layout (offset and size). Any embedded struct (or
+// arrays of structs) are converted to target layout types as well.
+llvm::Type *CommonHLSLTargetCodeGenInfo::createHLSLBufferLayoutType(
+CodeGenModule &CGM, const RecordType *StructType,
+const SmallVector *Packoffsets) const {
+
+  // check if we already have the layout type for this struct
+  if (llvm::Type *Ty = 
CGM.getHLSLRuntime().getHLSLBufferLayoutType(StructType))
+return Ty;
+
+  SmallVector Layout;
+  SmallVector LayoutElements;
+  unsigned Index = 0; // packoffset index
+  unsigned EndOffset = 0;
+
+  // reserve first spot in the layout vector for buffer size
+  Layout.push_back(0);
+
+  // iterate over all fields of the record, including fields on base classes
+  llvm::SmallVector RecordTypes;
+  RecordTypes.push_back(StructType);
+  while (RecordTypes.back()->getAsCXXRecordDecl()->getNumBases()) {
+CXXRecordDecl *D = RecordTypes.back()->getAsCXXRecordDecl();
+assert(D->getNumBases() == 1 &&

farzonl wrote:

We do a variation of this assert across the code base. Saw it three times in 
PRs in last two days. Is there a place we can check for multiple inheritance 
once and not have to do so many checks for it later.

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


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [DirectX] Fix printing of DXIL cbuffer info (PR #128698)

2025-02-25 Thread Farzon Lotfi via llvm-branch-commits

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


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


[llvm-branch-commits] [llvm] [DirectX] Support the CBufferLoadLegacy operation (PR #128699)

2025-02-25 Thread Farzon Lotfi via llvm-branch-commits


@@ -46,6 +46,12 @@ def ResRetDoubleTy : DXILOpParamType;
 def ResRetInt16Ty : DXILOpParamType;
 def ResRetInt32Ty : DXILOpParamType;
 def ResRetInt64Ty : DXILOpParamType;
+def CBufRetHalfTy : DXILOpParamType;

farzonl wrote:

why `def CBufRetHalfTy : DXILOpParamType;` and not `def CBufRetHalfTy : 
HalfTy;`?

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


[llvm-branch-commits] [llvm] [DirectX] Support the CBufferLoadLegacy operation (PR #128699)

2025-02-25 Thread Farzon Lotfi via llvm-branch-commits

https://github.com/farzonl edited 
https://github.com/llvm/llvm-project/pull/128699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Support the CBufferLoadLegacy operation (PR #128699)

2025-02-25 Thread Farzon Lotfi via llvm-branch-commits

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

LGTM. comments are questions only. No changes needed.

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