[llvm-branch-commits] [llvm] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread Patryk Wychowaniec via llvm-branch-commits

Patryk27 wrote:

> because the changes to shouldForceRelocation are ABI-breaking.

Huh, interesting - out of curiosity, why do they break the ABI if those jumps 
are local to functions?

https://github.com/llvm/llvm-project/pull/125081
___
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] [DXContainer] Obj2yaml support for root constants (PR #124813)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/124813

>From b1b967db8d3252894b72db1d6161c655898680bd Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Tue, 28 Jan 2025 17:46:23 +
Subject: [PATCH 1/5] adding support for root constants in dxcontainer for
 ob2jyaml and yaml2obj tools

---
 llvm/include/llvm/BinaryFormat/DXContainer.h  | 85 ++-
 .../BinaryFormat/DXContainerConstants.def | 26 +++---
 .../llvm/MC/DXContainerRootSignature.h|  3 +
 llvm/include/llvm/Object/DXContainer.h| 10 +++
 .../include/llvm/ObjectYAML/DXContainerYAML.h | 11 +++
 llvm/lib/BinaryFormat/DXContainer.cpp | 20 +
 llvm/lib/MC/DXContainerRootSignature.cpp  | 17 +++-
 llvm/lib/Object/DXContainer.cpp   | 20 +
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp|  1 +
 llvm/lib/ObjectYAML/DXContainerYAML.cpp   | 48 ++-
 .../DXContainer/RootSignature-Flags.yaml  | 14 ++-
 11 files changed, 197 insertions(+), 58 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 9268c28dbc69d2..8d6c7b787ad4c1 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
 #include 
 
 namespace llvm {
@@ -63,44 +64,6 @@ struct ShaderHash {
   void swapBytes() { sys::swapByteOrder(Flags); }
 };
 
-#define ROOT_PARAMETER(RootParameter) RootParameter,
-enum class RootParameterType {
-#include "DXContainerConstants.def"
-};
-
-#define SHADER_VISIBILITY(ShaderVisibility) ShaderVisibility,
-enum class ShaderVisibilityFlag {
-#include "DXContainerConstants.def"
-};
-
-struct RootConstants {
-  uint32_t ShaderRegister;
-  uint32_t RegisterSpace;
-  uint32_t Num32BitValues;
-};
-
-struct RootParameter {
-  RootParameterType ParameterType;
-  union {
-RootConstants Constants;
-  };
-  ShaderVisibilityFlag ShaderVisibility;
-};
-
-struct RootSignatureDesc {
-  uint32_t Size;
-  uint32_t Version;
-  uint32_t Flags;
-  uint32_t NumParameters;
-  RootParameter *Parameters;
-
-  void swapBytes() {
-sys::swapByteOrder(Size);
-sys::swapByteOrder(Version);
-sys::swapByteOrder(Flags);
-  }
-};
-
 struct ContainerVersion {
   uint16_t Major;
   uint16_t Minor;
@@ -195,6 +158,50 @@ enum class RootElementFlag : uint32_t {
 #include "DXContainerConstants.def"
 };
 
+#define ROOT_PARAMETER(Val, Enum) Enum = Val,
+enum class RootParameterType : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
+enum class ShaderVisibilityFlag : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+struct RootConstants {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Num32BitValues;
+
+  void swapBytes() {
+sys::swapByteOrder(ShaderRegister);
+sys::swapByteOrder(RegisterSpace);
+sys::swapByteOrder(Num32BitValues);
+  }
+};
+
+struct RootParameter {
+  RootParameterType ParameterType;
+  union {
+RootConstants Constants;
+  };
+  ShaderVisibilityFlag ShaderVisibility;
+
+  void swapBytes() {
+switch (ParameterType) {
+
+case RootParameterType::Constants32Bit:
+  Constants.swapBytes();
+  break;
+case RootParameterType::DescriptorTable:
+case RootParameterType::CBV:
+case RootParameterType::SRV:
+case RootParameterType::UAV:
+  break;
+}
+  }
+};
+
 PartType parsePartType(StringRef S);
 
 struct VertexPSVInfo {
@@ -536,6 +543,8 @@ enum class SigComponentType : uint32_t {
 };
 
 ArrayRef> getSigComponentTypes();
+ArrayRef> getRootParameterTypes();
+ArrayRef> getShaderVisibilityFlags();
 
 struct ProgramSignatureHeader {
   uint32_t ParamCount;
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def 
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 2134c2375f6d35..755322abf8140b 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -55,25 +55,25 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved 
shader flag bit (not a
 
 #ifdef ROOT_PARAMETER
 
-ROOT_PARAMETER(DescriptorTable)
-ROOT_PARAMETER(Constants32Bit)
-ROOT_PARAMETER(CBV)
-ROOT_PARAMETER(SRV)
-ROOT_PARAMETER(UAV)
+ROOT_PARAMETER(0, DescriptorTable)
+ROOT_PARAMETER(1, Constants32Bit)
+ROOT_PARAMETER(2, CBV)
+ROOT_PARAMETER(3, SRV)
+ROOT_PARAMETER(4, UAV)
 #undef ROOT_PARAMETER
 #endif // ROOT_PARAMETER
 
 
 #ifdef SHADER_VISIBILITY
 
-SHADER_VISIBILITY(All)
-SHADER_VISIBILITY(Vertex)
-SHADER_VISIBILITY(Hull)
-SHADER_VISIBILITY(Domain)
-SHADER_VISIBILITY(Geometry)
-SHADER_VISIBILITY(Pixel)
-SHADER_VISIBILITY(Amplification)
-SHADER_VISIBILITY(Mesh)
+SHADER_VISIBILITY(0, All)
+SHADER_VISIBILITY(1, Vertex)
+SHADER_VISIBILITY(2, Hull)
+SHADER_VISIBILITY(3, Domain)
+SHADER_VISIBILITY(4, Geometry)
+SHADER_VISIBILITY(5, Pixel)
+SHADER_VISIBILITY(6, 

[llvm-branch-commits] [llvm] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread Alex Rønne Petersen via llvm-branch-commits

alexrp wrote:

FWIW, the issue this addresses is a hard blocker for building even basic AVR 
programs with Zig as well, so definitely +1 for a backport from our side.

https://github.com/llvm/llvm-project/pull/125081
___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread Louis Dionne via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/125067
___
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] [Coro] Use DebugInfoCache to speed up cloning in CoroSplitPass (PR #118630)

2025-01-30 Thread Artem Pianykh via llvm-branch-commits

https://github.com/artempyanykh updated 
https://github.com/llvm/llvm-project/pull/118630

>From 78eb7e9f3f0e4419056031e31b4e3ea4b1e52079 Mon Sep 17 00:00:00 2001
From: Artem Pianykh 
Date: Sun, 15 Sep 2024 11:00:00 -0700
Subject: [PATCH] [Coro] Use DebugInfoCache to speed up cloning in
 CoroSplitPass

Summary:
We can use a DebugInfoFinder from DebugInfoCache which is already primed on a 
compile unit to speed
up collection of module-level debug info.

The pass could likely be another 2x+ faster if we avoid rebuilding the set of 
common debug
info. This needs further massaging of CloneFunction and ValueMapper, though, 
and can be done
incrementally on top of this.

Comparing performance of CoroSplitPass at various points in this stack, this is 
anecdata from a sample
cpp file compiled with full debug info:
| | Baseline | IdentityMD set | Prebuilt CommonDI | Cached CU 
DIFinder (cur.) |
|-|--||---|---|
| CoroSplitPass   | 306ms| 221ms  | 68ms  | 17ms
  |
| CoroCloner  | 101ms| 72ms   | 0.5ms | 0.5ms   
  |
| CollectCommonDI | -| -  | 63ms  | 13ms
  |
| Speed up| 1x   | 1.4x   | 4.5x  | 18x 
  |

Test Plan:
ninja check-llvm-unit
ninja check-llvm

Compiled a sample cpp file with time trace to get the avg. duration of the pass 
and inner scopes.

stack-info: PR: https://github.com/llvm/llvm-project/pull/118630, branch: 
users/artempyanykh/fast-coro-upstream/11
---
 llvm/include/llvm/Transforms/Coroutines/ABI.h | 13 +++--
 llvm/lib/Analysis/CGSCCPassManager.cpp|  7 +++
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  | 55 +++
 llvm/test/Other/new-pass-manager.ll   |  1 +
 llvm/test/Other/new-pm-defaults.ll|  1 +
 llvm/test/Other/new-pm-lto-defaults.ll|  1 +
 llvm/test/Other/new-pm-pgo-preinline.ll   |  1 +
 .../Other/new-pm-thinlto-postlink-defaults.ll |  1 +
 .../new-pm-thinlto-postlink-pgo-defaults.ll   |  1 +
 ...-pm-thinlto-postlink-samplepgo-defaults.ll |  1 +
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  1 +
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  3 +
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  1 +
 .../Analysis/CGSCCPassManagerTest.cpp |  4 +-
 14 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Coroutines/ABI.h 
b/llvm/include/llvm/Transforms/Coroutines/ABI.h
index 0b2d405f3caec4..2cf614b6bb1e2a 100644
--- a/llvm/include/llvm/Transforms/Coroutines/ABI.h
+++ b/llvm/include/llvm/Transforms/Coroutines/ABI.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_TRANSFORMS_COROUTINES_ABI_H
 #define LLVM_TRANSFORMS_COROUTINES_ABI_H
 
+#include "llvm/Analysis/DebugInfoCache.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Transforms/Coroutines/CoroShape.h"
 #include "llvm/Transforms/Coroutines/MaterializationUtils.h"
@@ -53,7 +54,8 @@ class BaseABI {
   // Perform the function splitting according to the ABI.
   virtual void splitCoroutine(Function &F, coro::Shape &Shape,
   SmallVectorImpl &Clones,
-  TargetTransformInfo &TTI) = 0;
+  TargetTransformInfo &TTI,
+  const DebugInfoCache *DICache) = 0;
 
   Function &F;
   coro::Shape &Shape;
@@ -73,7 +75,8 @@ class SwitchABI : public BaseABI {
 
   void splitCoroutine(Function &F, coro::Shape &Shape,
   SmallVectorImpl &Clones,
-  TargetTransformInfo &TTI) override;
+  TargetTransformInfo &TTI,
+  const DebugInfoCache *DICache) override;
 };
 
 class AsyncABI : public BaseABI {
@@ -86,7 +89,8 @@ class AsyncABI : public BaseABI {
 
   void splitCoroutine(Function &F, coro::Shape &Shape,
   SmallVectorImpl &Clones,
-  TargetTransformInfo &TTI) override;
+  TargetTransformInfo &TTI,
+  const DebugInfoCache *DICache) override;
 };
 
 class AnyRetconABI : public BaseABI {
@@ -99,7 +103,8 @@ class AnyRetconABI : public BaseABI {
 
   void splitCoroutine(Function &F, coro::Shape &Shape,
   SmallVectorImpl &Clones,
-  TargetTransformInfo &TTI) override;
+  TargetTransformInfo &TTI,
+  const DebugInfoCache *DICache) override;
 };
 
 } // end namespace coro
diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp 
b/llvm/lib/Analysis/CGSCCPassManager.cpp
index 948bc2435ab275..3ba085cdb0be8b 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Analy

[llvm-branch-commits] [libcxx] a97eed9 - Bump version to 20.1.0git (#125067)

2025-01-30 Thread via llvm-branch-commits

Author: Tom Stellard
Date: 2025-01-30T13:54:53-08:00
New Revision: a97eed928f410d3e4f91e3821a90cb41a5cff89c

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

LOG: Bump version to 20.1.0git (#125067)

Added: 


Modified: 
cmake/Modules/LLVMVersion.cmake
libcxx/include/__config
llvm/utils/gn/secondary/llvm/version.gni
llvm/utils/lit/lit/__init__.py

Removed: 




diff  --git a/cmake/Modules/LLVMVersion.cmake b/cmake/Modules/LLVMVersion.cmake
index 897dd963bd9ab6..281d0444255bac 100644
--- a/cmake/Modules/LLVMVersion.cmake
+++ b/cmake/Modules/LLVMVersion.cmake
@@ -4,7 +4,7 @@ if(NOT DEFINED LLVM_VERSION_MAJOR)
   set(LLVM_VERSION_MAJOR 20)
 endif()
 if(NOT DEFINED LLVM_VERSION_MINOR)
-  set(LLVM_VERSION_MINOR 0)
+  set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
   set(LLVM_VERSION_PATCH 0)

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 30b2d147dc5634..a866a7e6518379 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -28,7 +28,7 @@
 // _LIBCPP_VERSION represents the version of libc++, which matches the version 
of LLVM.
 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), 
_LIBCPP_VERSION is
 // defined to XXYYZZ.
-#  define _LIBCPP_VERSION 20
+#  define _LIBCPP_VERSION 200100
 
 #  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
 #  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)

diff  --git a/llvm/utils/gn/secondary/llvm/version.gni 
b/llvm/utils/gn/secondary/llvm/version.gni
index e0107cdeae76de..a99e5ba892da5b 100644
--- a/llvm/utils/gn/secondary/llvm/version.gni
+++ b/llvm/utils/gn/secondary/llvm/version.gni
@@ -1,4 +1,4 @@
 llvm_version_major = 20
-llvm_version_minor = 0
+llvm_version_minor = 1
 llvm_version_patch = 0
 llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch"

diff  --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index ea56d192fb3942..e1e31718020f22 100644
--- a/llvm/utils/lit/lit/__init__.py
+++ b/llvm/utils/lit/lit/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (20, 0, 0)
+__versioninfo__ = (20, 1, 0)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []



___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/125067
___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar milestoned 
https://github.com/llvm/llvm-project/pull/125067
___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread via llvm-branch-commits

github-actions[bot] wrote:

@tstellar (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/125067
___
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] AMDGPU/GlobalISel: Temporal divergence lowering (non i1) (PR #124298)

2025-01-30 Thread Sameer Sahasrabuddhe via llvm-branch-commits


@@ -342,6 +342,10 @@ template  class 
GenericUniformityAnalysisImpl {
   typename SyncDependenceAnalysisT::DivergenceDescriptor;
   using BlockLabelMapT = typename SyncDependenceAnalysisT::BlockLabelMap;
 
+  // Use outside cycle with divergent exit
+  using UOCWDE =

ssahasra wrote:

Alternatively, UOCWDE can be renamed to ``TemporalDivergenceTuple``?

https://github.com/llvm/llvm-project/pull/124298
___
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] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-01-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/125131

- Define and implement `MetadataBuilder` in `HLSLRootSignature`
- Integrate and invoke the builder in `CGHLSLRuntime.cpp` to generate the Root 
Signature for any associated entry functions
- Add tests to demonstrate functionality in `RootSignature.hlsl`

First part of resolving #119014 

>From 96a959b5c1dd4d46b72344902d697a40100d8046 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/5] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4bb..ff608323e9ac3a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 00..1ea9ab7aaa2c35
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 3f292a141ea90674301a3c23d02d2677fc3b8b23 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/5] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3a..4c9adcd8a90536 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/tes

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/123147

>From 94eacc14c0297e6e569e37602bbabcf12240ff76 Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Wed, 15 Jan 2025 17:30:00 +
Subject: [PATCH 01/13] adding metadata extraction

---
 .../llvm/Analysis/DXILMetadataAnalysis.h  |  3 +
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp| 89 +++
 .../lib/Target/DirectX/DXContainerGlobals.cpp | 24 +
 3 files changed, 116 insertions(+)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h 
b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index cb535ac14f1c61..f420244ba111a4 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -11,9 +11,11 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/MC/DXContainerRootSignature.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
+#include 
 
 namespace llvm {
 
@@ -37,6 +39,7 @@ struct ModuleMetadataInfo {
   Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
   VersionTuple ValidatorVersion{};
   SmallVector EntryPropertyVec{};
+  std::optional RootSignatureDesc;
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp 
b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index a7f666a3f8b48f..388e3853008eae 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -15,12 +15,91 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/MC/DXContainerRootSignature.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
 #define DEBUG_TYPE "dxil-metadata-analysis"
 
 using namespace llvm;
 using namespace dxil;
+using namespace llvm::mcdxbc;
+
+static bool parseRootFlags(MDNode *RootFlagNode, RootSignatureDesc *Desc) {
+
+  assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  auto Value = (RootSignatureFlags)Flag->getZExtValue();
+
+  if ((Value & ~RootSignatureFlags::ValidFlags) != RootSignatureFlags::None)
+return true;
+
+  Desc->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(MDNode *Element,
+  RootSignatureDesc *Desc) {
+  MDString *ElementText = cast(Element->getOperand(0));
+
+  assert(ElementText != nullptr && "First preoperty of element is not ");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(Element, Desc);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+llvm_unreachable("Not Implemented yet");
+break;
+  }
+
+  return true;
+}
+
+bool parseRootSignature(RootSignatureDesc *Desc, int32_t Version,
+NamedMDNode *Root) {
+  Desc->Version = Version;
+  bool HasError = false;
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+// This should be an if, for error handling
+MDNode *Node = cast(Root->getOperand(Sid));
+
+// Not sure what use this for...
+Metadata *Func = Node->getOperand(0).get();
+
+// This should be an if, for error handling
+MDNode *Elements = cast(Node->getOperand(1).get());
+
+for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
+  MDNode *Element = cast(Elements->getOperand(Eid));
+
+  HasError = HasError || parseRootSignatureElement(Element, Desc);
+}
+  }
+  return HasError;
+}
 
 static ModuleMetadataInfo collectMetadataInfo(Module &M) {
   ModuleMetadataInfo MMDAI;
@@ -28,6 +107,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
   MMDAI.DXILVersion = TT.getDXILVersion();
   MMDAI.ShaderModelVersion = TT.getOSVersion();
   MMDAI.ShaderProfile = TT.getEnvironment();
+
   NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
   if (ValidatorVerNode) {
   

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-01-30 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 14e7253752ddf98e953061dfbf28a008b18f10ed 
016f380a03875fc1251794e6d4e9555d0c60d3e9 --extensions cpp,h -- 
llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp 
clang/lib/CodeGen/CGHLSLRuntime.cpp 
llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 168bda18eb..1280de7142 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -126,8 +126,8 @@ void addRootSignature(
 
   llvm::hlsl::root_signature::MetadataBuilder Builder(Ctx, Elements);
   MDNode *RootSignature = Builder.BuildRootSignature();
-  MDNode *FnPairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
-RootSignature});
+  MDNode *FnPairing =
+  MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature});
 
   StringRef RootSignatureValKey = "dx.rootsignatures";
   auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
index 433cd9bc10..31fd68821b 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -129,14 +129,14 @@ using ParamType = std::variant;
 
 class MetadataBuilder {
- public:
+public:
   MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef Elements)
-   : Ctx(Ctx), Elements(Elements) {}
+  : Ctx(Ctx), Elements(Elements) {}
 
   // Iterates through the elements and builds the respective nodes
   MDNode *BuildRootSignature();
 
- private:
+private:
   // Define the various builders for the different metadata types
   MDNode *BuildDescriptorTable(const DescriptorTable &Table);
   MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp 
b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 0e88046a83..212ccd9fd1 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -1,4 +1,5 @@
-//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects 
--===//
+//===- HLSLRootSignature.cpp - HLSL Root Signature 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.
@@ -47,16 +48,15 @@ template  OverloadBuilds(Ts...) -> 
OverloadBuilds;
 MDNode *MetadataBuilder::BuildRootSignature() {
   for (const RootElement &Element : Elements) {
 MDNode *ElementMD =
-  std::visit(
-OverloadBuilds{
-[&](DescriptorTable Table) -> MDNode * {
-  return BuildDescriptorTable(Table);
-},
-[&](DescriptorTableClause Clause) -> MDNode * {
-  return BuildDescriptorTableClause(Clause);
-},
-},
-Element);
+std::visit(OverloadBuilds{
+   [&](DescriptorTable Table) -> MDNode * {
+ return BuildDescriptorTable(Table);
+   },
+   [&](DescriptorTableClause Clause) -> MDNode * {
+ return BuildDescriptorTableClause(Clause);
+   },
+   },
+   Element);
 GeneratedMetadata.push_back(ElementMD);
   }
 
@@ -67,28 +67,34 @@ MDNode *MetadataBuilder::BuildDescriptorTable(const 
DescriptorTable &Table) {
   IRBuilder<> B(Ctx);
   SmallVector TableOperands;
   TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
-  
TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility;
+  TableOperands.push_back(ConstantAsMetadata::get(
+  B.getInt32(llvm::to_underlying(Table.Visibility;
 
-  assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all 
owned clauses to be generated already");
-  TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, 
GeneratedMetadata.end());
+  assert(Table.NumClauses <= GeneratedMetadata.size() &&
+ "Table expected all owned clauses to be generated already");
+  TableOperands.append(GeneratedMetadata.end() - Table.NumClauses,
+   GeneratedMetadata.end());
   GeneratedMetadata.pop_back_n(Table.NumClauses);
 
   return MDNode::get(Ctx, TableOperands);
 }
 
-MDNode *MetadataBuilder::BuildDescriptorTableClause(const 
DescriptorTableClause &Clause) {
+MDNode *MetadataBuilder::BuildDescriptorTableClause(
+const DescriptorTableClause &Clause) {
   IRBuilder<> B(Ctx);
-  return MDNode::get(Ctx, {
-ClauseTypeToName(Ctx, Clause.Type),
-ConstantAsMetadata::get(B.getInt32(Cl

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-01-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/125131

>From 96a959b5c1dd4d46b72344902d697a40100d8046 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/7] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4bb..ff608323e9ac3a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 00..1ea9ab7aaa2c35
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 3f292a141ea90674301a3c23d02d2677fc3b8b23 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/7] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3a..4c9adcd8a90536 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
index 1ea9ab7aaa2c35..63c0505e224f0a 100644
--- a/clang/test/CodeGenHLSL/RootSignature.hlsl
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
 
-//

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,134 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  auto Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  assert((Value & ~0x8fff) == 0 && "Invalid flag for RootFlag Element");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  assert(ElementText != nullptr &&
+ "First preoperty of element is not a string");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+llvm_unreachable("Not Implemented yet");
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {

damyanp wrote:

Thanks - I didn't realize this was missed from the design.  All the more reason 
to get the design figured out before implementing it.

https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,73 @@
+//===- DXILRootSignature.h - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include 
+
+namespace llvm {
+namespace dxil {
+
+enum class RootSignatureElementKind {
+  None = 0,
+  RootFlags = 1,
+  RootConstants = 2,
+  RootDescriptor = 3,
+  DescriptorTable = 4,
+  StaticSampler = 5

damyanp wrote:

Just so you know, this makes it harder for me to review.  If I see these added 
then I have to start looking for tests and places where they're checked.  And 
then, when you do a subsequent PR that lights up this functionality, it'll be 
surprising not to see them appear.

https://github.com/llvm/llvm-project/pull/123147
___
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] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

It's not possible to backport this in this form, because the changes to 
shouldForceRelocation are ABI-breaking.

> so that the fixes can be pulled to rustc.

The LLVM 20 upgrade in Rust is already in progress, so this is not necessary.

https://github.com/llvm/llvm-project/pull/125081
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran edited 
https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,159 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
+  this->Version = Version;
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());

damyanp wrote:

Oh, cool, I couldn't find anything actually documenting that!

https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,158 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());
+
+if (RS == nullptr)
+  return reportError("Missing Root Signature Metadata node.");
+
+// Loop through the Root Elements of the root signature.
+for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
+
+  MDNode *Element = dyn_cast(RS->getOperand(Eid));
+  if (Element == nullptr)
+return reportError("Missing Root Element Metadata Node.");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {

damyanp wrote:

In the current version, I don't think that `MRS.Flags` is initialized, so if 
there's no `RootSignatureNode` then this function will return an uninitialized 
value

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,74 @@
+//===- DXILRootSignature.h - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include 
+
+namespace llvm {
+namespace dxil {
+
+enum class RootSignatureElementKind {
+  None = 0,
+  RootFlags = 1,
+  RootConstants = 2,
+  RootDescriptor = 3,
+  DescriptorTable = 4,
+  StaticSampler = 5
+};
+
+struct ModuleRootSignature {
+  uint32_t Flags;

damyanp wrote:

```suggestion
  uint32_t Flags = 0;
```

https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits

https://github.com/damyanp edited 
https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits

https://github.com/damyanp requested changes to this pull request.

This PR is targetting llvm:users/jaosaffran/122396, rather than llvm:main, so 
I'm not quite sure what we're reviewing now.

https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,158 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());
+
+if (RS == nullptr)
+  return reportError("Missing Root Signature Metadata node.");
+
+// Loop through the Root Elements of the root signature.
+for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
+
+  MDNode *Element = dyn_cast(RS->getOperand(Eid));
+  if (Element == nullptr)
+return reportError("Missing Root Element Metadata Node.");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+if (MRS.parse(RootSignatureNode))
+  llvm_unreachable("Invalid Root Signature Metadata.");
+  }
+
+  return MRS;
+}
+
+AnalysisKey RootSignatureAnalysis::Key;
+
+ModuleRootSignature RootS

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,134 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  auto Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  assert((Value & ~0x8fff) == 0 && "Invalid flag for RootFlag Element");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  assert(ElementText != nullptr &&
+ "First preoperty of element is not a string");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+llvm_unreachable("Not Implemented yet");
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
+  this->Version = Version;
+  bool HasError = false;
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+// This should be an if, for error handling
+MDNode *Node = cast(Root->getOperand(Sid));
+
+// Not sure what use this for...
+// Metadata *Func = Node->getOperand(0).get();
+
+MDNode *Elements = cast(Node->getOperand(1).get());
+assert(Elements && "Invalid Metadata type on root signature");
+
+for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
+  MDNode *Element = cast(Elements->getOperand(Eid));
+  assert(Element && "Invalid Metadata type on root element");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+AnalysisKey RootSignatureAnalysis::Key;
+
+ModuleRootSignature RootSignatureAnalysis::run(Module &M,
+   ModuleAnalysisManager &AM) {
+  ModuleRootSignature MRSI;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+MRSI.parse(1, RootSignatureNode);
+  }
+
+  return MRSI;
+}
+
+//===--===//
+bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+MRS.parse(1, RootSignatureNode);
+this->MRS = MRS;
+  }
+
+  return false;
+}
+
+void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
+  AU.setPreservesAll();
+}
+
+char RootSignatureAnalysisWrapper::ID = 0;

damyanp wrote:

I guess that this is idiomatic for implementing these legacy passes.

https://github.com/llvm/llvm-project/pull/123147
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,158 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());
+
+if (RS == nullptr)
+  return reportError("Missing Root Signature Metadata node.");
+
+// Loop through the Root Elements of the root signature.
+for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
+
+  MDNode *Element = dyn_cast(RS->getOperand(Eid));
+  if (Element == nullptr)
+return reportError("Missing Root Element Metadata Node.");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+if (MRS.parse(RootSignatureNode))
+  llvm_unreachable("Invalid Root Signature Metadata.");

damyanp wrote:

Is this really unreachable? Does `reportError` terminate the en

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -144,6 +149,27 @@ void DXContainerGlobals::addSignature(Module &M,
   Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
 }
 
+void DXContainerGlobals::addRootSignature(Module &M,
+  SmallVector &Globals) 
{
+
+  std::optional MRS =
+  getAnalysis().getRootSignature();
+  if (!MRS.has_value())
+return;
+
+  SmallString<256> Data;
+  raw_svector_ostream OS(Data);
+
+  RootSignatureHeader RSH;
+  RSH.Flags = MRS->Flags;
+
+  RSH.write(OS);

damyanp wrote:

I have questions around what's going on here, but it's confusing because this 
PR is targeting a branch in your repo and not llvm/llvm-project, so I'm not 
sure what the proposed change is here.

https://github.com/llvm/llvm-project/pull/123147
___
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] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-30 Thread Finn Plummer via llvm-branch-commits


@@ -169,5 +220,399 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &Tokens, DiagnosticsEngine &Diags)
+: Elements(Elements), Diags(Diags) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::Parse() {
+  // Handle edge-case of empty RootSignature()
+  if (CurTok == LastTok)
+return false;
+
+  bool First = true;
+  // Iterate as many RootElements as possible
+  while (!ParseRootElement(First)) {
+First = false;
+// Avoid use of ConsumeNextToken here to skip incorrect end of tokens error
+CurTok++;
+if (CurTok == LastTok)
+  return false;
+if (EnsureExpectedToken(TokenKind::pu_comma))
+  return true;
+  }
+
+  return true;
+}
+
+bool RootSignatureParser::ParseRootElement(bool First) {
+  if (First && EnsureExpectedToken(TokenKind::kw_DescriptorTable))
+return true;
+  if (!First && ConsumeExpectedToken(TokenKind::kw_DescriptorTable))
+return true;
+
+  // Dispatch onto the correct parse method
+  switch (CurTok->Kind) {

inbelic wrote:

This pr only adds support for `DescriptorTable` as a root element. So there is 
no added support for a root descriptor range at the moment. A future pr that 
will handle the `RootCBV, etc` would be added to this switch statement and then 
dispatched onto its own method.

https://github.com/llvm/llvm-project/pull/122982
___
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] release/20.x: workflows/premerge: Add macOS testing for release branch (#124303) (PR #125161)

2025-01-30 Thread Aiden Grossman via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/125161
___
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] release/20.x: workflows/release-binaries: Stop using ccache (#124415) (PR #125009)

2025-01-30 Thread via llvm-branch-commits

github-actions[bot] wrote:

@tstellar (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/125009
___
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] [AMDGPU] Add liverange split instructions into BB Prolog (PR #117544)

2025-01-30 Thread Christudasan Devadasan via llvm-branch-commits

https://github.com/cdevadas edited 
https://github.com/llvm/llvm-project/pull/117544
___
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] fa12df5 - [SCEV] Check correct value for UB (#124302)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

Author: Nikita Popov
Date: 2025-01-30T14:05:10-08:00
New Revision: fa12df5e22aa5ae6d3c0a5b261acd15bd49081e8

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

LOG: [SCEV] Check correct value for UB (#124302)

This is a followup to #117152. That patch introduced a check for
UB/poison on BEValue. However, the SCEV we're actually going to use is
Shifted. In some cases, it's possible for Shifted to contain UB, while
BEValue doesn't.

In the test case the values are:

BEValue: (-1 * (zext i8 (-83 + ((-83 /u {1,+,1}<%loop>) *
{-1,+,-1}<%loop>)) to i32))
Shifted: (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) *
{0,+,-1}<%loop>) to i32)))

Fixes https://github.com/llvm/llvm-project/issues/123550.

(cherry picked from commit 07efe2c18a63423943a4f9d9daeada23601f84c8)

Added: 


Modified: 
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/pr123550.ll

Removed: 




diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp 
b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7d7d37b3d228dd..2ce40877b523e1 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5917,20 +5917,18 @@ const SCEV 
*ScalarEvolution::createAddRecFromPHI(PHINode *PN) {
 //   PHI(f(0), f({1,+,1})) --> f({0,+,1})
 
 // Do not allow refinement in rewriting of BEValue.
-if (isGuaranteedNotToCauseUB(BEValue)) {
-  const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this);
-  const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false);
-  if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() &&
-  ::impliesPoison(BEValue, Start)) {
-const SCEV *StartVal = getSCEV(StartValueV);
-if (Start == StartVal) {
-  // Okay, for the entire analysis of this edge we assumed the PHI
-  // to be symbolic.  We now need to go back and purge all of the
-  // entries for the scalars that use the symbolic expression.
-  forgetMemoizedResults(SymbolicName);
-  insertValueToMap(PN, Shifted);
-  return Shifted;
-}
+const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this);
+const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false);
+if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() &&
+isGuaranteedNotToCauseUB(Shifted) && ::impliesPoison(Shifted, Start)) {
+  const SCEV *StartVal = getSCEV(StartValueV);
+  if (Start == StartVal) {
+// Okay, for the entire analysis of this edge we assumed the PHI
+// to be symbolic.  We now need to go back and purge all of the
+// entries for the scalars that use the symbolic expression.
+forgetMemoizedResults(SymbolicName);
+insertValueToMap(PN, Shifted);
+return Shifted;
   }
 }
   }

diff  --git a/llvm/test/Analysis/ScalarEvolution/pr123550.ll 
b/llvm/test/Analysis/ScalarEvolution/pr123550.ll
index c1f2051248a12d..709da00935ef3a 100644
--- a/llvm/test/Analysis/ScalarEvolution/pr123550.ll
+++ b/llvm/test/Analysis/ScalarEvolution/pr123550.ll
@@ -1,16 +1,16 @@
 ; NOTE: Assertions have been autogenerated by 
utils/update_analyze_test_checks.py UTC_ARGS: --version 5
 ; RUN: opt -disable-output -passes='print' < %s 2>&1 | 
FileCheck %s
 
-; FIXME: This is a miscompile.
+; %srem should have exit value 130.
 define i32 @test() {
 ; CHECK-LABEL: 'test'
 ; CHECK-NEXT:  Classifying expressions for: @test
 ; CHECK-NEXT:%phi = phi i32 [ -173, %bb ], [ %sub, %loop ]
-; CHECK-NEXT:--> (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * 
{0,+,-1}<%loop>) to i32))) U: empty-set S: empty-set Exits: 
-173 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:--> %phi U: [-173,1) S: [-173,1) Exits: -173 
LoopDispositions: { %loop: Variant }
 ; CHECK-NEXT:%iv2 = phi i32 [ 1, %bb ], [ %iv2.inc, %loop ]
 ; CHECK-NEXT:--> {1,+,1}<%loop> U: [1,2) S: [1,2) Exits: 1 
LoopDispositions: { %loop: Computable }
 ; CHECK-NEXT:%srem = srem i32 729259140, %phi
-; CHECK-NEXT:--> (729259140 + (-1 * (-173 + (-1 * (zext i8 ((-83 /u 
{0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))) * (729259140 
/u (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to 
i32)) U: empty-set S: empty-set Exits: 
729259140 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:--> %srem U: [0,1073741824) S: [0,1073741824) Exits: 130 
LoopDispositions: { %loop: Variant }
 ; CHECK-NEXT:%trunc = trunc i32 %iv2 to i8
 ; CHECK-NEXT:--> {1,+,1}<%loop> U: [1,2) S: [1,2) Exits: 1 
LoopDispositions: { %loop: Computable }
 ; CHECK-NEXT:%urem = urem i8 -83, %trunc
@@ -22,7 +22,7 @@ define i32 @test() {
 ; CHECK-NEXT:%iv2.inc = add i32 %iv2, 1
 ; CHECK-NEXT:--> {2,+,1}<%loop> U: [2,3) S: [2,3) Exi

[llvm-branch-commits] [clang] [flang] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=flang-rt (PR #110217)

2025-01-30 Thread via llvm-branch-commits

h-vetinari wrote:

> Are these the literal outputs or did you edit them? Please don't.

I shortened them, because the build-specific path to the source directory of 
the build seemed like noise. The literal output was
```
LLVM_TREE_AVAILABLE: OFF
toolchain_lib_subdir: lib/x86_64-unknown-linux-gnu
FLANG_RT_OUTPUT_RESOURCE_DIR: 
/home/conda/feedstock_root/build_artifacts/flang-split_1738098969735/work/build/flang-rt
FLANG_RT_INSTALL_RESOURCE_PATH: lib/clang/20
FLANG_RT_OUTPUT_RESOURCE_LIB_DIR: 
/home/conda/feedstock_root/build_artifacts/flang-split_1738098969735/work/build/flang-rt/lib
FLANG_RT_INSTALL_RESOURCE_LIB_PATH: lib/clang/20/lib/x86_64-unknown-linux-gnu
```

https://github.com/llvm/llvm-project/pull/110217
___
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] [DXIL] Add support for root signature Constants element Generation in DXContainer (PR #124967)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/124967

>From 086e0491a055952d094d0c0c2b886f324166613e Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Tue, 28 Jan 2025 17:46:23 +
Subject: [PATCH 1/8] adding support for root constants in dxcontainer for
 ob2jyaml and yaml2obj tools

---
 llvm/include/llvm/BinaryFormat/DXContainer.h | 47 
 llvm/include/llvm/Object/DXContainer.h   |  1 +
 llvm/lib/ObjectYAML/DXContainerYAML.cpp  | 39 
 3 files changed, 87 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 5993492dfd15d6..8946be6908309d 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
 #include 
 
 namespace llvm {
@@ -206,6 +207,50 @@ enum class RootElementFlag : uint32_t {
 #include "DXContainerConstants.def"
 };
 
+#define ROOT_PARAMETER(Val, Enum) Enum = Val,
+enum class RootParameterType : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
+enum class ShaderVisibilityFlag : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+struct RootConstants {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Num32BitValues;
+
+  void swapBytes() {
+sys::swapByteOrder(ShaderRegister);
+sys::swapByteOrder(RegisterSpace);
+sys::swapByteOrder(Num32BitValues);
+  }
+};
+
+struct RootParameter {
+  RootParameterType ParameterType;
+  union {
+RootConstants Constants;
+  };
+  ShaderVisibilityFlag ShaderVisibility;
+
+  void swapBytes() {
+switch (ParameterType) {
+
+case RootParameterType::Constants32Bit:
+  Constants.swapBytes();
+  break;
+case RootParameterType::DescriptorTable:
+case RootParameterType::CBV:
+case RootParameterType::SRV:
+case RootParameterType::UAV:
+  break;
+}
+  }
+};
+
 PartType parsePartType(StringRef S);
 
 struct VertexPSVInfo {
@@ -547,6 +592,8 @@ enum class SigComponentType : uint32_t {
 };
 
 ArrayRef> getSigComponentTypes();
+ArrayRef> getRootParameterTypes();
+ArrayRef> getShaderVisibilityFlags();
 
 struct ProgramSignatureHeader {
   uint32_t ParamCount;
diff --git a/llvm/include/llvm/Object/DXContainer.h 
b/llvm/include/llvm/Object/DXContainer.h
index e2d9f7266fcb49..1d6590dacadaff 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -22,6 +22,7 @@
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
+#include 
 #include 
 
 namespace llvm {
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp 
b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 9174c1f11e2a2c..618a9a8a52bda8 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -258,6 +258,33 @@ void 
MappingTraits::mapping(
 #include "llvm/BinaryFormat/DXContainerConstants.def"
 }
 
+void MappingTraits::mapping(IO &IO,
+ dxbc::RootParameter &S) {
+
+  IO.mapRequired("Type", S.ParameterType);
+  IO.mapRequired("ShaderVisibility", S.ShaderVisibility);
+
+  switch (S.ParameterType) {
+
+  case dxbc::RootParameterType::Constants32Bit:
+IO.mapRequired("Constants", S.Constants);
+break;
+  case dxbc::RootParameterType::DescriptorTable:
+  case dxbc::RootParameterType::CBV:
+  case dxbc::RootParameterType::SRV:
+  case dxbc::RootParameterType::UAV:
+break;
+  }
+}
+
+void MappingTraits::mapping(IO &IO,
+ dxbc::RootConstants &S) {
+
+  IO.mapRequired("Num32BitValues", S.Num32BitValues);
+  IO.mapRequired("ShaderRegister", S.ShaderRegister);
+  IO.mapRequired("RegisterSpace", S.RegisterSpace);
+}
+
 void MappingTraits::mapping(IO &IO,
DXContainerYAML::Part &P) {
   IO.mapRequired("Name", P.Name);
@@ -361,6 +388,18 @@ void 
ScalarEnumerationTraits::enumeration(
 IO.enumCase(Value, E.Name.str().c_str(), E.Value);
 }
 
+void ScalarEnumerationTraits::enumeration(
+IO &IO, dxbc::RootParameterType &Value) {
+  for (const auto &E : dxbc::getRootParameterTypes())
+IO.enumCase(Value, E.Name.str().c_str(), E.Value);
+}
+
+void ScalarEnumerationTraits::enumeration(
+IO &IO, dxbc::ShaderVisibilityFlag &Value) {
+  for (const auto &E : dxbc::getShaderVisibilityFlags())
+IO.enumCase(Value, E.Name.str().c_str(), E.Value);
+}
+
 } // namespace yaml
 
 void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) {

>From f304938f15f0e8c39fa74fb6c99405acec757eaf Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Tue, 28 Jan 2025 18:02:54 +
Subject: [PATCH 2/8] updating test

---
 llvm/include/llvm/BinaryFormat/DXContainer.h | 45 
 llvm/include/llvm/Object/DXContainer.h   |  1 -
 

[llvm-branch-commits] [llvm] [DXContainer] Obj2yaml support for root constants (PR #124813)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/124813

>From b02e7fe88bcafe236fc3eb592eae67eb47da8b0b Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Tue, 28 Jan 2025 17:46:23 +
Subject: [PATCH 1/3] adding support for root constants in dxcontainer for
 ob2jyaml and yaml2obj tools

---
 llvm/include/llvm/BinaryFormat/DXContainer.h  | 50 +++
 .../BinaryFormat/DXContainerConstants.def | 26 +-
 .../llvm/MC/DXContainerRootSignature.h|  3 ++
 llvm/include/llvm/Object/DXContainer.h| 10 
 .../include/llvm/ObjectYAML/DXContainerYAML.h | 11 
 llvm/lib/BinaryFormat/DXContainer.cpp | 20 
 llvm/lib/MC/DXContainerRootSignature.cpp  | 17 +--
 llvm/lib/Object/DXContainer.cpp   | 20 
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp|  1 +
 llvm/lib/ObjectYAML/DXContainerYAML.cpp   |  5 ++
 .../DXContainer/RootSignature-Flags.yaml  | 32 +---
 11 files changed, 171 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 71a6d15e46a81db..c241ec7e87348d0 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
 #include 
 
 namespace llvm {
@@ -63,6 +64,7 @@ struct ShaderHash {
   void swapBytes() { sys::swapByteOrder(Flags); }
 };
 
+<<< HEAD
 struct RootSignatureDesc {
   uint32_t Size;
   uint32_t Flags;
@@ -73,6 +75,8 @@ struct RootSignatureDesc {
   }
 };
 
+===
+>>> b1b967db8d32 (adding support for root constants in dxcontainer for 
ob2jyaml and yaml2obj tools)
 struct ContainerVersion {
   uint16_t Major;
   uint16_t Minor;
@@ -167,6 +171,50 @@ enum class RootElementFlag : uint32_t {
 #include "DXContainerConstants.def"
 };
 
+#define ROOT_PARAMETER(Val, Enum) Enum = Val,
+enum class RootParameterType : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
+enum class ShaderVisibilityFlag : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+struct RootConstants {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Num32BitValues;
+
+  void swapBytes() {
+sys::swapByteOrder(ShaderRegister);
+sys::swapByteOrder(RegisterSpace);
+sys::swapByteOrder(Num32BitValues);
+  }
+};
+
+struct RootParameter {
+  RootParameterType ParameterType;
+  union {
+RootConstants Constants;
+  };
+  ShaderVisibilityFlag ShaderVisibility;
+
+  void swapBytes() {
+switch (ParameterType) {
+
+case RootParameterType::Constants32Bit:
+  Constants.swapBytes();
+  break;
+case RootParameterType::DescriptorTable:
+case RootParameterType::CBV:
+case RootParameterType::SRV:
+case RootParameterType::UAV:
+  break;
+}
+  }
+};
+
 PartType parsePartType(StringRef S);
 
 struct VertexPSVInfo {
@@ -508,6 +556,8 @@ enum class SigComponentType : uint32_t {
 };
 
 ArrayRef> getSigComponentTypes();
+ArrayRef> getRootParameterTypes();
+ArrayRef> getShaderVisibilityFlags();
 
 struct ProgramSignatureHeader {
   uint32_t ParamCount;
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def 
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 2134c2375f6d35e..755322abf8140b2 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -55,25 +55,25 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved 
shader flag bit (not a
 
 #ifdef ROOT_PARAMETER
 
-ROOT_PARAMETER(DescriptorTable)
-ROOT_PARAMETER(Constants32Bit)
-ROOT_PARAMETER(CBV)
-ROOT_PARAMETER(SRV)
-ROOT_PARAMETER(UAV)
+ROOT_PARAMETER(0, DescriptorTable)
+ROOT_PARAMETER(1, Constants32Bit)
+ROOT_PARAMETER(2, CBV)
+ROOT_PARAMETER(3, SRV)
+ROOT_PARAMETER(4, UAV)
 #undef ROOT_PARAMETER
 #endif // ROOT_PARAMETER
 
 
 #ifdef SHADER_VISIBILITY
 
-SHADER_VISIBILITY(All)
-SHADER_VISIBILITY(Vertex)
-SHADER_VISIBILITY(Hull)
-SHADER_VISIBILITY(Domain)
-SHADER_VISIBILITY(Geometry)
-SHADER_VISIBILITY(Pixel)
-SHADER_VISIBILITY(Amplification)
-SHADER_VISIBILITY(Mesh)
+SHADER_VISIBILITY(0, All)
+SHADER_VISIBILITY(1, Vertex)
+SHADER_VISIBILITY(2, Hull)
+SHADER_VISIBILITY(3, Domain)
+SHADER_VISIBILITY(4, Geometry)
+SHADER_VISIBILITY(5, Pixel)
+SHADER_VISIBILITY(6, Amplification)
+SHADER_VISIBILITY(7, Mesh)
 #undef SHADER_VISIBILITY
 #endif // SHADER_VISIBILITY
 
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h 
b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 20b4f5a4285f69b..9102137c14b473f 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/BinaryFormat/DXContain

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread via llvm-branch-commits


@@ -0,0 +1,158 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());
+
+if (RS == nullptr)
+  return reportError("Missing Root Signature Metadata node.");
+
+// Loop through the Root Elements of the root signature.
+for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
+
+  MDNode *Element = dyn_cast(RS->getOperand(Eid));
+  if (Element == nullptr)
+return reportError("Missing Root Element Metadata Node.");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+if (MRS.parse(RootSignatureNode))
+  llvm_unreachable("Invalid Root Signature Metadata.");

joaosaffran wrote:

Yes, reportError terminates the compilation process. 

http

[llvm-branch-commits] [SPARC][IAS] Add IAS flag handling for ISA levels (PR #125151)

2025-01-30 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/125151

Add IAS flag handling for ISA levels we support in LLVM.



___
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] [SPARC][IAS] Add support for `setsw` pseudoinstruction (PR #125150)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

Implement `setsw` pseudoinstruction for setting a 32-bit signed imm.


---
Full diff: https://github.com/llvm/llvm-project/pull/125150.diff


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+70) 
- (modified) llvm/lib/Target/Sparc/SparcInstrAliases.td (+4) 
- (modified) llvm/test/MC/Sparc/sparc-synthetic-instructions.s (+29) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index bc239480baa891..879f2ed8849618 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -130,6 +130,9 @@ class SparcAsmParser : public MCTargetAsmParser {
   bool expandSET(MCInst &Inst, SMLoc IDLoc,
  SmallVectorImpl &Instructions);
 
+  bool expandSETSW(MCInst &Inst, SMLoc IDLoc,
+   SmallVectorImpl &Instructions);
+
   bool expandSETX(MCInst &Inst, SMLoc IDLoc,
   SmallVectorImpl &Instructions);
 
@@ -734,6 +737,69 @@ bool SparcAsmParser::expandSET(MCInst &Inst, SMLoc IDLoc,
   return false;
 }
 
+bool SparcAsmParser::expandSETSW(MCInst &Inst, SMLoc IDLoc,
+ SmallVectorImpl &Instructions) {
+  MCOperand MCRegOp = Inst.getOperand(0);
+  MCOperand MCValOp = Inst.getOperand(1);
+  assert(MCRegOp.isReg());
+  assert(MCValOp.isImm() || MCValOp.isExpr());
+
+  // the imm operand can be either an expression or an immediate.
+  bool IsImm = Inst.getOperand(1).isImm();
+  int64_t ImmValue = IsImm ? MCValOp.getImm() : 0;
+  const MCExpr *ValExpr = IsImm ? MCConstantExpr::create(ImmValue, 
getContext())
+: MCValOp.getExpr();
+
+  bool IsSmallImm = IsImm && isInt<13>(ImmValue);
+  bool NoLowBitsImm = IsImm && ((ImmValue & 0x3FF) == 0);
+
+  MCOperand PrevReg = MCOperand::createReg(Sparc::G0);
+
+  if (!isInt<32>(ImmValue)) {
+return Error(IDLoc,
+ "set: argument must be between -2147483648 and 2147483647");
+  }
+
+  // Very small immediates can be expressed without emitting a sethi.
+  if (!IsSmallImm) {
+// sethi %hi(val), rd
+Instructions.push_back(
+MCInstBuilder(SP::SETHIi)
+.addReg(MCRegOp.getReg())
+.addExpr(adjustPICRelocation(SparcMCExpr::VK_Sparc_HI, ValExpr)));
+
+PrevReg = MCRegOp;
+  }
+
+  // If the immediate has the lower bits set or is small, we need to emit an 
or.
+  if (!NoLowBitsImm || IsSmallImm) {
+const MCExpr *Expr =
+IsSmallImm ? ValExpr
+   : adjustPICRelocation(SparcMCExpr::VK_Sparc_LO, ValExpr);
+
+// orrd, %lo(val), rd
+Instructions.push_back(MCInstBuilder(SP::ORri)
+   .addReg(MCRegOp.getReg())
+   .addReg(PrevReg.getReg())
+   .addExpr(Expr));
+
+// If it's a small immediate there's nothing more to do.
+if (IsSmallImm)
+  return false;
+  }
+
+  // Large negative or non-immediate expressions would need an sra.
+  if (!IsImm || ImmValue < 0) {
+// srard, %g0, rd
+Instructions.push_back(MCInstBuilder(SP::SRArr)
+   .addReg(MCRegOp.getReg())
+   .addReg(MCRegOp.getReg())
+   .addReg(Sparc::G0));
+  }
+
+  return false;
+}
+
 bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
 SmallVectorImpl &Instructions) {
   MCOperand MCRegOp = Inst.getOperand(0);
@@ -826,6 +892,10 @@ bool SparcAsmParser::matchAndEmitInstruction(SMLoc IDLoc, 
unsigned &Opcode,
   if (expandSET(Inst, IDLoc, Instructions))
 return true;
   break;
+case SP::SETSW:
+  if (expandSETSW(Inst, IDLoc, Instructions))
+return true;
+  break;
 case SP::SETX:
   if (expandSETX(Inst, IDLoc, Instructions))
 return true;
diff --git a/llvm/lib/Target/Sparc/SparcInstrAliases.td 
b/llvm/lib/Target/Sparc/SparcInstrAliases.td
index cfc0b4735c91c4..b7232cc066165e 100644
--- a/llvm/lib/Target/Sparc/SparcInstrAliases.td
+++ b/llvm/lib/Target/Sparc/SparcInstrAliases.td
@@ -450,6 +450,10 @@ def : InstAlias<"save", (SAVErr G0, G0, G0)>;
 // def : InstAlias<"set $val, $rd", (ORri IntRegs:$rd, (SETHIi (HI22 
imm:$val)), (LO10 imm:$val))>;
 def SET : AsmPseudoInst<(outs IntRegs:$rd), (ins i32imm:$val), "set $val, 
$rd">;
 
+// setsw value, rd
+// (turns into a sequence of sethi+or+sra, depending on the value)
+def SETSW : AsmPseudoInst<(outs IntRegs:$rd), (ins i32imm:$val), "setsw $val, 
$rd">;
+
 // setx value, tmp, rd
 // (turns into a sequence of sethi+or+shift, depending on the value)
 def SETX : AsmPseudoInst<(outs I64Regs:$rd),
diff --git a/llvm/test/MC/Sparc/sparc-synthetic-instructions.s 
b/llvm/test/MC/Sparc/sparc-synthetic-instructions.s
index 9c6db2836af176..f679ee72baf536 100644
--- a/llvm/tes

[llvm-branch-commits] [SPARC][IAS] Add support for `setsw` pseudoinstruction (PR #125150)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Koakuma (koachan)


Changes

Implement `setsw` pseudoinstruction for setting a 32-bit signed imm.


---
Full diff: https://github.com/llvm/llvm-project/pull/125150.diff


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+70) 
- (modified) llvm/lib/Target/Sparc/SparcInstrAliases.td (+4) 
- (modified) llvm/test/MC/Sparc/sparc-synthetic-instructions.s (+29) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index bc239480baa8915..879f2ed8849618d 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -130,6 +130,9 @@ class SparcAsmParser : public MCTargetAsmParser {
   bool expandSET(MCInst &Inst, SMLoc IDLoc,
  SmallVectorImpl &Instructions);
 
+  bool expandSETSW(MCInst &Inst, SMLoc IDLoc,
+   SmallVectorImpl &Instructions);
+
   bool expandSETX(MCInst &Inst, SMLoc IDLoc,
   SmallVectorImpl &Instructions);
 
@@ -734,6 +737,69 @@ bool SparcAsmParser::expandSET(MCInst &Inst, SMLoc IDLoc,
   return false;
 }
 
+bool SparcAsmParser::expandSETSW(MCInst &Inst, SMLoc IDLoc,
+ SmallVectorImpl &Instructions) {
+  MCOperand MCRegOp = Inst.getOperand(0);
+  MCOperand MCValOp = Inst.getOperand(1);
+  assert(MCRegOp.isReg());
+  assert(MCValOp.isImm() || MCValOp.isExpr());
+
+  // the imm operand can be either an expression or an immediate.
+  bool IsImm = Inst.getOperand(1).isImm();
+  int64_t ImmValue = IsImm ? MCValOp.getImm() : 0;
+  const MCExpr *ValExpr = IsImm ? MCConstantExpr::create(ImmValue, 
getContext())
+: MCValOp.getExpr();
+
+  bool IsSmallImm = IsImm && isInt<13>(ImmValue);
+  bool NoLowBitsImm = IsImm && ((ImmValue & 0x3FF) == 0);
+
+  MCOperand PrevReg = MCOperand::createReg(Sparc::G0);
+
+  if (!isInt<32>(ImmValue)) {
+return Error(IDLoc,
+ "set: argument must be between -2147483648 and 2147483647");
+  }
+
+  // Very small immediates can be expressed without emitting a sethi.
+  if (!IsSmallImm) {
+// sethi %hi(val), rd
+Instructions.push_back(
+MCInstBuilder(SP::SETHIi)
+.addReg(MCRegOp.getReg())
+.addExpr(adjustPICRelocation(SparcMCExpr::VK_Sparc_HI, ValExpr)));
+
+PrevReg = MCRegOp;
+  }
+
+  // If the immediate has the lower bits set or is small, we need to emit an 
or.
+  if (!NoLowBitsImm || IsSmallImm) {
+const MCExpr *Expr =
+IsSmallImm ? ValExpr
+   : adjustPICRelocation(SparcMCExpr::VK_Sparc_LO, ValExpr);
+
+// orrd, %lo(val), rd
+Instructions.push_back(MCInstBuilder(SP::ORri)
+   .addReg(MCRegOp.getReg())
+   .addReg(PrevReg.getReg())
+   .addExpr(Expr));
+
+// If it's a small immediate there's nothing more to do.
+if (IsSmallImm)
+  return false;
+  }
+
+  // Large negative or non-immediate expressions would need an sra.
+  if (!IsImm || ImmValue < 0) {
+// srard, %g0, rd
+Instructions.push_back(MCInstBuilder(SP::SRArr)
+   .addReg(MCRegOp.getReg())
+   .addReg(MCRegOp.getReg())
+   .addReg(Sparc::G0));
+  }
+
+  return false;
+}
+
 bool SparcAsmParser::expandSETX(MCInst &Inst, SMLoc IDLoc,
 SmallVectorImpl &Instructions) {
   MCOperand MCRegOp = Inst.getOperand(0);
@@ -826,6 +892,10 @@ bool SparcAsmParser::matchAndEmitInstruction(SMLoc IDLoc, 
unsigned &Opcode,
   if (expandSET(Inst, IDLoc, Instructions))
 return true;
   break;
+case SP::SETSW:
+  if (expandSETSW(Inst, IDLoc, Instructions))
+return true;
+  break;
 case SP::SETX:
   if (expandSETX(Inst, IDLoc, Instructions))
 return true;
diff --git a/llvm/lib/Target/Sparc/SparcInstrAliases.td 
b/llvm/lib/Target/Sparc/SparcInstrAliases.td
index cfc0b4735c91c4b..b7232cc066165ed 100644
--- a/llvm/lib/Target/Sparc/SparcInstrAliases.td
+++ b/llvm/lib/Target/Sparc/SparcInstrAliases.td
@@ -450,6 +450,10 @@ def : InstAlias<"save", (SAVErr G0, G0, G0)>;
 // def : InstAlias<"set $val, $rd", (ORri IntRegs:$rd, (SETHIi (HI22 
imm:$val)), (LO10 imm:$val))>;
 def SET : AsmPseudoInst<(outs IntRegs:$rd), (ins i32imm:$val), "set $val, 
$rd">;
 
+// setsw value, rd
+// (turns into a sequence of sethi+or+sra, depending on the value)
+def SETSW : AsmPseudoInst<(outs IntRegs:$rd), (ins i32imm:$val), "setsw $val, 
$rd">;
+
 // setx value, tmp, rd
 // (turns into a sequence of sethi+or+shift, depending on the value)
 def SETX : AsmPseudoInst<(outs I64Regs:$rd),
diff --git a/llvm/test/MC/Sparc/sparc-synthetic-instructions.s 
b/llvm/test/MC/Sparc/sparc-synthetic-instructions.s
index 9c6db2836af1768..f679ee72baf5361 100644
--- a/llvm/test/MC/

[llvm-branch-commits] [SPARC][IAS] Add IAS flag handling for ISA levels (PR #125151)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Koakuma (koachan)


Changes

Add IAS flag handling for ISA levels we support in LLVM.


---
Full diff: https://github.com/llvm/llvm-project/pull/125151.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+32) 
- (added) clang/test/Driver/sparc-ias-Wa.s (+60) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 518113e20cb063..832766e2f8487a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2593,6 +2593,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   bool UseNoExecStack = false;
   bool Msa = false;
   const char *MipsTargetFeature = nullptr;
+  llvm::SmallVector SparcTargetFeatures;
   StringRef ImplicitIt;
   for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
@@ -2738,6 +2739,31 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
 if (MipsTargetFeature)
   continue;
 break;
+
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcel:
+  case llvm::Triple::sparcv9:
+if (Value == "--undeclared-regs") {
+  // LLVM already allows undeclared use of G registers, so this option
+  // becomes a no-op. This solely exists for GNU compatibility.
+  // TODO implement --no-undeclared-regs
+  continue;
+}
+SparcTargetFeatures =
+llvm::StringSwitch>(Value)
+.Case("-Av8", {"-v8plus"})
+.Case("-Av8plus", {"+v8plus", "+v9"})
+.Case("-Av8plusa", {"+v8plus", "+v9", "+vis"})
+.Case("-Av8plusb", {"+v8plus", "+v9", "+vis", "+vis2"})
+.Case("-Av8plusd", {"+v8plus", "+v9", "+vis", "+vis2", 
"+vis3"})
+.Case("-Av9", {"+v9"})
+.Case("-Av9a", {"+v9", "+vis"})
+.Case("-Av9b", {"+v9", "+vis", "+vis2"})
+.Case("-Av9d", {"+v9", "+vis", "+vis2", "+vis3"})
+.Default({});
+if (!SparcTargetFeatures.empty())
+  continue;
+break;
   }
 
   if (Value == "-force_cpusubtype_ALL") {
@@ -2842,6 +2868,12 @@ static void 
CollectArgsForIntegratedAssembler(Compilation &C,
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back(MipsTargetFeature);
   }
+  if (!SparcTargetFeatures.empty()) {
+for (const char *Feature : SparcTargetFeatures) {
+  CmdArgs.push_back("-target-feature");
+  CmdArgs.push_back(Feature);
+}
+  }
 
   // forward -fembed-bitcode to assmebler
   if (C.getDriver().embedBitcodeEnabled() ||
diff --git a/clang/test/Driver/sparc-ias-Wa.s b/clang/test/Driver/sparc-ias-Wa.s
new file mode 100644
index 00..79456c02935be1
--- /dev/null
+++ b/clang/test/Driver/sparc-ias-Wa.s
@@ -0,0 +1,60 @@
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av8 
2>&1 | \
+// RUN:   FileCheck -check-prefix=V8 %s
+// V8: -cc1as
+// V8: "-target-feature" "-v8plus"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plus 2>&1 | \
+// RUN:   FileCheck -check-prefix=V8PLUS %s
+// V8PLUS: -cc1as
+// V8PLUS: "-target-feature" "+v8plus"
+// V8PLUS: "-target-feature" "+v9"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusa 2>&1 | \
+// RUN:   FileCheck -check-prefix=V8PLUSA %s
+// V8PLUSA: -cc1as
+// V8PLUSA: "-target-feature" "+v8plus"
+// V8PLUSA: "-target-feature" "+v9"
+// V8PLUSA: "-target-feature" "+vis"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusb 2>&1 | \
+// RUN:   FileCheck -check-prefix=V8PLUSB %s
+// V8PLUSB: -cc1as
+// V8PLUSB: "-target-feature" "+v8plus"
+// V8PLUSB: "-target-feature" "+v9"
+// V8PLUSB: "-target-feature" "+vis"
+// V8PLUSB: "-target-feature" "+vis2"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s 
-Wa,-Av8plusd 2>&1 | \
+// RUN:   FileCheck -check-prefix=V8PLUSD %s
+// V8PLUSD: -cc1as
+// V8PLUSD: "-target-feature" "+v8plus"
+// V8PLUSD: "-target-feature" "+v9"
+// V8PLUSD: "-target-feature" "+vis"
+// V8PLUSD: "-target-feature" "+vis2"
+// V8PLUSD: "-target-feature" "+vis3"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9 
2>&1 | \
+// RUN:   FileCheck -check-prefix=V9 %s
+// V9: -cc1as
+// V9: "-target-feature" "+v9"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9a 
2>&1 | \
+// RUN:   FileCheck -check-prefix=V9A %s
+// V9A: -cc1as
+// V9A: "-target-feature" "+v9"
+// V9A: "-target-feature" "+vis"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9b 
2>&1 | \
+// RUN:   FileCheck -check-prefix=V9B %s
+// V9B: -cc1as
+// V9B: "-target-feature" "+v9"
+// V9B: "-target-feature" "+vis"
+// V9B: "-target-feature" "+vis2"
+
+// RUN: %clang --target=sparc-linux-gnu -### -fintegrated-as -c %s -Wa,-Av9d 
2>&1 | \
+// RUN: 

[llvm-branch-commits] [SPARC][IAS] Add IAS flag handling for ISA levels (PR #124953)

2025-01-30 Thread via llvm-branch-commits

koachan wrote:

New PR is at https://github.com/llvm/llvm-project/pull/125151.

https://github.com/llvm/llvm-project/pull/124953
___
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] [SPARC][IAS] Add support for `setsw` pseudoinstruction (PR #124952)

2025-01-30 Thread via llvm-branch-commits

koachan wrote:

New PR is at https://github.com/llvm/llvm-project/pull/125150.

https://github.com/llvm/llvm-project/pull/124952
___
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] [SPARC][IAS] Add support for `setsw` pseudoinstruction (PR #124952)

2025-01-30 Thread via llvm-branch-commits

https://github.com/koachan closed 
https://github.com/llvm/llvm-project/pull/124952
___
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] [SPARC][IAS] Add IAS flag handling for ISA levels (PR #124953)

2025-01-30 Thread via llvm-branch-commits

https://github.com/koachan closed 
https://github.com/llvm/llvm-project/pull/124953
___
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] [SPARC][IAS] Add support for `setsw` pseudoinstruction (PR #125150)

2025-01-30 Thread via llvm-branch-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/125150

Implement `setsw` pseudoinstruction for setting a 32-bit signed imm.



___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/123147

>From 94eacc14c0297e6e569e37602bbabcf12240ff76 Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Wed, 15 Jan 2025 17:30:00 +
Subject: [PATCH 01/14] adding metadata extraction

---
 .../llvm/Analysis/DXILMetadataAnalysis.h  |  3 +
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp| 89 +++
 .../lib/Target/DirectX/DXContainerGlobals.cpp | 24 +
 3 files changed, 116 insertions(+)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h 
b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index cb535ac14f1c61..f420244ba111a4 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -11,9 +11,11 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/MC/DXContainerRootSignature.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
+#include 
 
 namespace llvm {
 
@@ -37,6 +39,7 @@ struct ModuleMetadataInfo {
   Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
   VersionTuple ValidatorVersion{};
   SmallVector EntryPropertyVec{};
+  std::optional RootSignatureDesc;
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp 
b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index a7f666a3f8b48f..388e3853008eae 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -15,12 +15,91 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/MC/DXContainerRootSignature.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
 #define DEBUG_TYPE "dxil-metadata-analysis"
 
 using namespace llvm;
 using namespace dxil;
+using namespace llvm::mcdxbc;
+
+static bool parseRootFlags(MDNode *RootFlagNode, RootSignatureDesc *Desc) {
+
+  assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  auto Value = (RootSignatureFlags)Flag->getZExtValue();
+
+  if ((Value & ~RootSignatureFlags::ValidFlags) != RootSignatureFlags::None)
+return true;
+
+  Desc->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(MDNode *Element,
+  RootSignatureDesc *Desc) {
+  MDString *ElementText = cast(Element->getOperand(0));
+
+  assert(ElementText != nullptr && "First preoperty of element is not ");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(Element, Desc);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+llvm_unreachable("Not Implemented yet");
+break;
+  }
+
+  return true;
+}
+
+bool parseRootSignature(RootSignatureDesc *Desc, int32_t Version,
+NamedMDNode *Root) {
+  Desc->Version = Version;
+  bool HasError = false;
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+// This should be an if, for error handling
+MDNode *Node = cast(Root->getOperand(Sid));
+
+// Not sure what use this for...
+Metadata *Func = Node->getOperand(0).get();
+
+// This should be an if, for error handling
+MDNode *Elements = cast(Node->getOperand(1).get());
+
+for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
+  MDNode *Element = cast(Elements->getOperand(Eid));
+
+  HasError = HasError || parseRootSignatureElement(Element, Desc);
+}
+  }
+  return HasError;
+}
 
 static ModuleMetadataInfo collectMetadataInfo(Module &M) {
   ModuleMetadataInfo MMDAI;
@@ -28,6 +107,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
   MMDAI.DXILVersion = TT.getDXILVersion();
   MMDAI.ShaderModelVersion = TT.getOSVersion();
   MMDAI.ShaderProfile = TT.getEnvironment();
+
   NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
   if (ValidatorVerNode) {
   

[llvm-branch-commits] [llvm] [DXContainer] Obj2yaml support for root constants (PR #124813)

2025-01-30 Thread via llvm-branch-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/124813

>From b02e7fe88bcafe236fc3eb592eae67eb47da8b0b Mon Sep 17 00:00:00 2001
From: joaosaffran 
Date: Tue, 28 Jan 2025 17:46:23 +
Subject: [PATCH 1/2] adding support for root constants in dxcontainer for
 ob2jyaml and yaml2obj tools

---
 llvm/include/llvm/BinaryFormat/DXContainer.h  | 50 +++
 .../BinaryFormat/DXContainerConstants.def | 26 +-
 .../llvm/MC/DXContainerRootSignature.h|  3 ++
 llvm/include/llvm/Object/DXContainer.h| 10 
 .../include/llvm/ObjectYAML/DXContainerYAML.h | 11 
 llvm/lib/BinaryFormat/DXContainer.cpp | 20 
 llvm/lib/MC/DXContainerRootSignature.cpp  | 17 +--
 llvm/lib/Object/DXContainer.cpp   | 20 
 llvm/lib/ObjectYAML/DXContainerEmitter.cpp|  1 +
 llvm/lib/ObjectYAML/DXContainerYAML.cpp   |  5 ++
 .../DXContainer/RootSignature-Flags.yaml  | 32 +---
 11 files changed, 171 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 71a6d15e46a81d..c241ec7e87348d 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -17,6 +17,7 @@
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/TargetParser/Triple.h"
 
+#include 
 #include 
 
 namespace llvm {
@@ -63,6 +64,7 @@ struct ShaderHash {
   void swapBytes() { sys::swapByteOrder(Flags); }
 };
 
+<<< HEAD
 struct RootSignatureDesc {
   uint32_t Size;
   uint32_t Flags;
@@ -73,6 +75,8 @@ struct RootSignatureDesc {
   }
 };
 
+===
+>>> b1b967db8d32 (adding support for root constants in dxcontainer for 
ob2jyaml and yaml2obj tools)
 struct ContainerVersion {
   uint16_t Major;
   uint16_t Minor;
@@ -167,6 +171,50 @@ enum class RootElementFlag : uint32_t {
 #include "DXContainerConstants.def"
 };
 
+#define ROOT_PARAMETER(Val, Enum) Enum = Val,
+enum class RootParameterType : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
+enum class ShaderVisibilityFlag : uint8_t {
+#include "DXContainerConstants.def"
+};
+
+struct RootConstants {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t Num32BitValues;
+
+  void swapBytes() {
+sys::swapByteOrder(ShaderRegister);
+sys::swapByteOrder(RegisterSpace);
+sys::swapByteOrder(Num32BitValues);
+  }
+};
+
+struct RootParameter {
+  RootParameterType ParameterType;
+  union {
+RootConstants Constants;
+  };
+  ShaderVisibilityFlag ShaderVisibility;
+
+  void swapBytes() {
+switch (ParameterType) {
+
+case RootParameterType::Constants32Bit:
+  Constants.swapBytes();
+  break;
+case RootParameterType::DescriptorTable:
+case RootParameterType::CBV:
+case RootParameterType::SRV:
+case RootParameterType::UAV:
+  break;
+}
+  }
+};
+
 PartType parsePartType(StringRef S);
 
 struct VertexPSVInfo {
@@ -508,6 +556,8 @@ enum class SigComponentType : uint32_t {
 };
 
 ArrayRef> getSigComponentTypes();
+ArrayRef> getRootParameterTypes();
+ArrayRef> getShaderVisibilityFlags();
 
 struct ProgramSignatureHeader {
   uint32_t ParamCount;
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def 
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 2134c2375f6d35..755322abf8140b 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -55,25 +55,25 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved 
shader flag bit (not a
 
 #ifdef ROOT_PARAMETER
 
-ROOT_PARAMETER(DescriptorTable)
-ROOT_PARAMETER(Constants32Bit)
-ROOT_PARAMETER(CBV)
-ROOT_PARAMETER(SRV)
-ROOT_PARAMETER(UAV)
+ROOT_PARAMETER(0, DescriptorTable)
+ROOT_PARAMETER(1, Constants32Bit)
+ROOT_PARAMETER(2, CBV)
+ROOT_PARAMETER(3, SRV)
+ROOT_PARAMETER(4, UAV)
 #undef ROOT_PARAMETER
 #endif // ROOT_PARAMETER
 
 
 #ifdef SHADER_VISIBILITY
 
-SHADER_VISIBILITY(All)
-SHADER_VISIBILITY(Vertex)
-SHADER_VISIBILITY(Hull)
-SHADER_VISIBILITY(Domain)
-SHADER_VISIBILITY(Geometry)
-SHADER_VISIBILITY(Pixel)
-SHADER_VISIBILITY(Amplification)
-SHADER_VISIBILITY(Mesh)
+SHADER_VISIBILITY(0, All)
+SHADER_VISIBILITY(1, Vertex)
+SHADER_VISIBILITY(2, Hull)
+SHADER_VISIBILITY(3, Domain)
+SHADER_VISIBILITY(4, Geometry)
+SHADER_VISIBILITY(5, Pixel)
+SHADER_VISIBILITY(6, Amplification)
+SHADER_VISIBILITY(7, Mesh)
 #undef SHADER_VISIBILITY
 #endif // SHADER_VISIBILITY
 
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h 
b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 20b4f5a4285f69..9102137c14b473 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -6,6 +6,8 @@
 //
 
//===--===//
 
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/BinaryFormat/DXContainer.h"

[llvm-branch-commits] [llvm] [DXContainer] Obj2yaml support for root constants (PR #124813)

2025-01-30 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 33bb8ccebc7479a2a04f3a8404ba9e474616c188 
a6934915165ec3a867a69121fdf646b5416ae91b --extensions h,cpp -- 
llvm/include/llvm/BinaryFormat/DXContainer.h 
llvm/include/llvm/MC/DXContainerRootSignature.h 
llvm/include/llvm/Object/DXContainer.h 
llvm/include/llvm/ObjectYAML/DXContainerYAML.h 
llvm/lib/BinaryFormat/DXContainer.cpp llvm/lib/MC/DXContainerRootSignature.cpp 
llvm/lib/Object/DXContainer.cpp llvm/lib/ObjectYAML/DXContainerEmitter.cpp 
llvm/lib/ObjectYAML/DXContainerYAML.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h 
b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 5993492dfd..cb6324c99a 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -70,7 +70,6 @@ enum class RootParameterType : uint8_t {
 
 ArrayRef> getRootParameterTypes();
 
-
 #define SHADER_VISIBILITY(Val, Enum) Enum = Val,
 enum class ShaderVisibilityFlag : uint8_t {
 #include "DXContainerConstants.def"

``




https://github.com/llvm/llvm-project/pull/124813
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread via llvm-branch-commits


@@ -144,6 +149,27 @@ void DXContainerGlobals::addSignature(Module &M,
   Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
 }
 
+void DXContainerGlobals::addRootSignature(Module &M,
+  SmallVector &Globals) 
{
+
+  std::optional MRS =
+  getAnalysis().getRootSignature();
+  if (!MRS.has_value())
+return;
+
+  SmallString<256> Data;
+  raw_svector_ostream OS(Data);
+
+  RootSignatureHeader RSH;
+  RSH.Flags = MRS->Flags;
+
+  RSH.write(OS);

joaosaffran wrote:

This change is writing the in memory rootsignature representation into a global 
variable in dxil, that is what DXContainerGlobals has done with PSV0, which I 
reference to implement this. 

The target branch is intentional, the targeted PR contains the logic 
serialization and deserialization of Root Flags using obj2yaml. This change is 
required to implement tests in this PR.

https://github.com/llvm/llvm-project/pull/123147
___
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] release/20.x: workflows/premerge: Add macOS testing for release branch (#124303) (PR #125161)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/125161

>From 0e240b08c6ff4f891bf3741d25aca17057d6992f Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 30 Jan 2025 19:37:54 -0800
Subject: [PATCH] workflows/premerge: Add macOS testing for release branch
 (#124303)

Also, remove the old pre-merge tests since Linux and Windows are tested on 
buildkite now.

(cherry picked from commit b89617d02d1c8a2701c1d3290d2ff45cd858ccde)
---
 .github/workflows/clang-tests.yml  | 38 
 .github/workflows/libclc-tests.yml | 39 -
 .github/workflows/lld-tests.yml| 38 
 .github/workflows/lldb-tests.yml   | 39 -
 .github/workflows/llvm-tests.yml   | 10 -
 .github/workflows/premerge.yaml| 70 ++
 6 files changed, 70 insertions(+), 164 deletions(-)
 delete mode 100644 .github/workflows/clang-tests.yml
 delete mode 100644 .github/workflows/libclc-tests.yml
 delete mode 100644 .github/workflows/lld-tests.yml
 delete mode 100644 .github/workflows/lldb-tests.yml

diff --git a/.github/workflows/clang-tests.yml 
b/.github/workflows/clang-tests.yml
deleted file mode 100644
index 2569ce19518e3e..00
--- a/.github/workflows/clang-tests.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-name: Clang Tests
-
-permissions:
-  contents: read
-
-on:
-  workflow_dispatch:
-  push:
-branches:
-  - 'release/**'
-paths:
-  - 'clang/**'
-  - '.github/workflows/clang-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!llvm/**'
-  pull_request:
-branches:
-  - 'release/**'
-paths:
-  - 'clang/**'
-  - '.github/workflows/clang-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!llvm/**'
-
-concurrency:
-  # Skip intermediate builds: always.
-  # Cancel intermediate builds: only if it is a pull request build.
-  group: ${{ github.workflow }}-${{ github.ref }}
-  cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
-
-jobs:
-  check_clang:
-if: github.repository_owner == 'llvm'
-name: Test clang,lldb,libclc
-uses: ./.github/workflows/llvm-project-tests.yml
-with:
-  build_target: check-clang
-  projects: clang;lldb;libclc
diff --git a/.github/workflows/libclc-tests.yml 
b/.github/workflows/libclc-tests.yml
deleted file mode 100644
index 23192f776a985e..00
--- a/.github/workflows/libclc-tests.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-name: libclc Tests
-
-permissions:
-  contents: read
-
-on:
-  workflow_dispatch:
-  push:
-branches:
-  - 'release/**'
-paths:
-  - 'libclc/**'
-  - '.github/workflows/libclc-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!clang/**'
-  - '!llvm/**'
-  pull_request:
-branches:
-  - 'release/**'
-paths:
-  - 'libclc/**'
-  - '.github/workflows/libclc-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!clang/**'
-  - '!llvm/**'
-
-concurrency:
-  # Skip intermediate builds: always.
-  # Cancel intermediate builds: only if it is a pull request build.
-  group: ${{ github.workflow }}-${{ github.ref }}
-  cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
-
-jobs:
-  check_libclc:
-if: github.repository_owner == 'llvm'
-name: Test libclc
-uses: ./.github/workflows/llvm-project-tests.yml
-with:
-  projects: clang;libclc
diff --git a/.github/workflows/lld-tests.yml b/.github/workflows/lld-tests.yml
deleted file mode 100644
index 599c0975fa6858..00
--- a/.github/workflows/lld-tests.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-name: LLD Tests
-
-permissions:
-  contents: read
-
-on:
-  workflow_dispatch:
-  push:
-branches:
-  - 'release/**'
-paths:
-  - 'lld/**'
-  - '.github/workflows/lld-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!llvm/**'
-  pull_request:
-branches:
-  - 'release/**'
-paths:
-  - 'lld/**'
-  - '.github/workflows/lld-tests.yml'
-  - '.github/workflows/llvm-project-tests.yml'
-  - '!llvm/**'
-
-concurrency:
-  # Skip intermediate builds: always.
-  # Cancel intermediate builds: only if it is a pull request build.
-  group: ${{ github.workflow }}-${{ github.ref }}
-  cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
-
-jobs:
-  check_lld:
-if: github.repository_owner == 'llvm'
-name: Test lld
-uses: ./.github/workflows/llvm-project-tests.yml
-with:
-  build_target: check-lld
-  projects: lld
diff --git a/.github/workflows/lldb-tests.yml b/.github/workflows/lldb-tests.yml
deleted file mode 100644
index 6bb9721956258f..00
--- a/.github/workflows/lldb-tests.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-name: lldb Tests
-
-permissions:
-  contents: read
-
-on:
-  workflow_dispatch:
-  push:
-branches:
-  - 'release/**'
-paths:
-  - 'lldb/**'
-  - '.github/workflows/lldb-tests.yml'
-  - '.github/wo

[llvm-branch-commits] [llvm] release/20.x: workflows/premerge: Add macOS testing for release branch (#124303) (PR #125161)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/125161
___
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] release/20.x: workflows/premerge: Add macOS testing for release branch (#124303) (PR #125161)

2025-01-30 Thread via llvm-branch-commits

github-actions[bot] wrote:

@tstellar (or anyone else). If you would like to add a note about this fix in 
the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/125161
___
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] workflows/premerge: Enable macos builds (PR #125176)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar milestoned 
https://github.com/llvm/llvm-project/pull/125176
___
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] workflows/premerge: Enable macos builds (PR #125176)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

This is just for the release branch.

https://github.com/llvm/llvm-project/pull/125176
___
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] workflows/premerge: Enable macos builds (PR #125176)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/125176

We still have buildkite for testing Linux and Windows, so we don't need to 
enable those builds yet.

>From 713b5e7ea877db545526f88c0513c5f462dba62d Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 30 Jan 2025 22:31:24 -0800
Subject: [PATCH] workflows/premerge: Enable macos builds

We still have buildkite for testing Linux and Windows, so we don't need
to enable those builds yet.
---
 .github/workflows/premerge.yaml | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/premerge.yaml b/.github/workflows/premerge.yaml
index d7fa6718821861..49ffcc0c7ddd24 100644
--- a/.github/workflows/premerge.yaml
+++ b/.github/workflows/premerge.yaml
@@ -5,8 +5,6 @@ permissions:
 
 on:
   pull_request:
-paths:
-  - .github/workflows/premerge.yaml
   push:
 branches:
   - 'main'
@@ -14,7 +12,7 @@ on:
 
 jobs:
   premerge-checks-linux:
-if: github.repository_owner == 'llvm'
+if: false && github.repository_owner == 'llvm'
 runs-on: llvm-premerge-linux-runners
 concurrency:
   group: ${{ github.workflow }}-linux-${{ github.event.pull_request.number 
|| github.sha }}
@@ -73,7 +71,7 @@ jobs:
   ./.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})" "$(echo ${linux_runtimes} | tr ' ' ';')" 
"$(echo ${linux_runtime_check_targets})"
 
   premerge-checks-windows:
-if: github.repository_owner == 'llvm'
+if: false && github.repository_owner == 'llvm'
 runs-on: llvm-premerge-windows-runners
 concurrency:
   group: ${{ github.workflow }}-windows-${{ 
github.event.pull_request.number || github.sha }}

___
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] workflows/premerge: Enable macos builds (PR #125176)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)


Changes

We still have buildkite for testing Linux and Windows, so we don't need to 
enable those builds yet.

---
Full diff: https://github.com/llvm/llvm-project/pull/125176.diff


1 Files Affected:

- (modified) .github/workflows/premerge.yaml (+2-4) 


``diff
diff --git a/.github/workflows/premerge.yaml b/.github/workflows/premerge.yaml
index d7fa6718821861..49ffcc0c7ddd24 100644
--- a/.github/workflows/premerge.yaml
+++ b/.github/workflows/premerge.yaml
@@ -5,8 +5,6 @@ permissions:
 
 on:
   pull_request:
-paths:
-  - .github/workflows/premerge.yaml
   push:
 branches:
   - 'main'
@@ -14,7 +12,7 @@ on:
 
 jobs:
   premerge-checks-linux:
-if: github.repository_owner == 'llvm'
+if: false && github.repository_owner == 'llvm'
 runs-on: llvm-premerge-linux-runners
 concurrency:
   group: ${{ github.workflow }}-linux-${{ github.event.pull_request.number 
|| github.sha }}
@@ -73,7 +71,7 @@ jobs:
   ./.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" 
"$(echo ${linux_check_targets})" "$(echo ${linux_runtimes} | tr ' ' ';')" 
"$(echo ${linux_runtime_check_targets})"
 
   premerge-checks-windows:
-if: github.repository_owner == 'llvm'
+if: false && github.repository_owner == 'llvm'
 runs-on: llvm-premerge-windows-runners
 concurrency:
   group: ${{ github.workflow }}-windows-${{ 
github.event.pull_request.number || github.sha }}

``




https://github.com/llvm/llvm-project/pull/125176
___
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] release/20.x: [AArch64] Add MSVC mangling for the __mfp8 type (#124968) (PR #125066)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport 7939ce6295e7fc0214cd307f97dfccc0cabde381

Requested by: @MacDue

---
Full diff: https://github.com/llvm/llvm-project/pull/125066.diff


2 Files Affected:

- (modified) clang/lib/AST/MicrosoftMangle.cpp (+5) 
- (added) clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp (+14) 


``diff
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index edeeaeaa9ae17c..42b735ccf4a2ce 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2792,6 +2792,10 @@ void MicrosoftCXXNameMangler::mangleType(const 
BuiltinType *T, Qualifiers,
 mangleArtificialTagType(TagTypeKind::Struct, "__bf16", {"__clang"});
 break;
 
+  case BuiltinType::MFloat8:
+mangleArtificialTagType(TagTypeKind::Struct, "__mfp8", {"__clang"});
+break;
+
 #define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS)  
\
   case BuiltinType::Id:
\
 mangleArtificialTagType(TagTypeKind::Struct, MangledName); 
\
@@ -2808,6 +2812,7 @@ void MicrosoftCXXNameMangler::mangleType(const 
BuiltinType *T, Qualifiers,
 
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits)
 #include "clang/Basic/AArch64SVEACLETypes.def"
 #define PPC_VECTOR_TYPE(Name, Id, Size) \
   case BuiltinType::Id:
diff --git a/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp 
b/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp
new file mode 100644
index 00..b5fd9171ad81a9
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple aarch64-windows-msvc -emit-llvm -o - %s | FileCheck 
%s
+
+typedef __mfp8 mf8;
+typedef __attribute__((neon_vector_type(8))) __mfp8 mf8x8_t;
+typedef __attribute__((neon_vector_type(16))) __mfp8 mf8x16_t;
+
+// CHECK: "?f@@YAXU__mfp8@__clang@@@Z"
+void f(mf8 v) {}
+
+// CHECK: "?f@@YAXT?$__vector@U__mfp8@__clang@@$07@__clang@@@Z"
+void f(mf8x8_t v) {}
+
+// CHECK: "?f@@YAXT?$__vector@U__mfp8@__clang@@$0BA@@__clang@@@Z"
+void f(mf8x16_t v) {}

``




https://github.com/llvm/llvm-project/pull/125066
___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar created 
https://github.com/llvm/llvm-project/pull/125067

None

>From a5494de4e9b6c1a8b468b09d4cdb8cb3e552a026 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Thu, 30 Jan 2025 07:08:42 -0800
Subject: [PATCH] Bump version to 20.1.0git

---
 cmake/Modules/LLVMVersion.cmake  | 2 +-
 libcxx/include/__config  | 2 +-
 llvm/utils/gn/secondary/llvm/version.gni | 2 +-
 llvm/utils/lit/lit/__init__.py   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmake/Modules/LLVMVersion.cmake b/cmake/Modules/LLVMVersion.cmake
index 897dd963bd9ab6..281d0444255bac 100644
--- a/cmake/Modules/LLVMVersion.cmake
+++ b/cmake/Modules/LLVMVersion.cmake
@@ -4,7 +4,7 @@ if(NOT DEFINED LLVM_VERSION_MAJOR)
   set(LLVM_VERSION_MAJOR 20)
 endif()
 if(NOT DEFINED LLVM_VERSION_MINOR)
-  set(LLVM_VERSION_MINOR 0)
+  set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
   set(LLVM_VERSION_PATCH 0)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 30b2d147dc5634..a866a7e6518379 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -28,7 +28,7 @@
 // _LIBCPP_VERSION represents the version of libc++, which matches the version 
of LLVM.
 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), 
_LIBCPP_VERSION is
 // defined to XXYYZZ.
-#  define _LIBCPP_VERSION 20
+#  define _LIBCPP_VERSION 200100
 
 #  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
 #  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
diff --git a/llvm/utils/gn/secondary/llvm/version.gni 
b/llvm/utils/gn/secondary/llvm/version.gni
index e0107cdeae76de..a99e5ba892da5b 100644
--- a/llvm/utils/gn/secondary/llvm/version.gni
+++ b/llvm/utils/gn/secondary/llvm/version.gni
@@ -1,4 +1,4 @@
 llvm_version_major = 20
-llvm_version_minor = 0
+llvm_version_minor = 1
 llvm_version_patch = 0
 llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch"
diff --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index ea56d192fb3942..e1e31718020f22 100644
--- a/llvm/utils/lit/lit/__init__.py
+++ b/llvm/utils/lit/lit/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (20, 0, 0)
+__versioninfo__ = (20, 1, 0)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []

___
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] [llvm] [mlir] [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (PR #124746)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits


@@ -2709,13 +2709,23 @@ getRefPtrIfDeclareTarget(mlir::Value value,
 }
 
 namespace {
+// Append customMappers information to existing MapInfosTy
+struct MapInfosTy : llvm::OpenMPIRBuilder::MapInfosTy {
+  SmallVector Mappers;

ergawy wrote:

Can we add `Mapper` to `MapInfoData` and only use `MapInfoData` through out the 
whole file?

https://github.com/llvm/llvm-project/pull/124746
___
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] [flang] [Flang] Optionally do not compile the runtime in-tree (PR #122336)

2025-01-30 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/122336

>From 4c676f468ba344ac0c388583a4ed28035d05ae89 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Fri, 24 Jan 2025 15:00:16 +0100
Subject: [PATCH] users/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME

---
 flang/CMakeLists.txt|  6 +-
 flang/test/CMakeLists.txt   |  6 +-
 flang/test/Driver/ctofortran.f90|  1 +
 flang/test/Driver/exec.f90  |  1 +
 flang/test/Runtime/no-cpp-dep.c |  2 +-
 flang/test/lit.cfg.py   |  5 -
 flang/test/lit.site.cfg.py.in   |  2 ++
 flang/tools/f18/CMakeLists.txt  |  2 +-
 flang/unittests/CMakeLists.txt  | 11 +-
 flang/unittests/Evaluate/CMakeLists.txt | 27 +
 10 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index b619553ef830218..7d6dcb5c184a52d 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -247,6 +247,8 @@ else()
   include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
 endif()
 
+option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be 
replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON)
+
 set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
 "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
 mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
@@ -487,7 +489,9 @@ if (FLANG_CUF_RUNTIME)
   find_package(CUDAToolkit REQUIRED)
 endif()
 
-add_subdirectory(runtime)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(runtime)
+endif ()
 
 if (LLVM_INCLUDE_EXAMPLES)
   add_subdirectory(examples)
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index cab214c2ef4c8c1..e398e0786147aa7 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS
   llvm-objdump
   llvm-readobj
   split-file
-  FortranRuntime
   FortranDecimal
 )
+
+if (FLANG_INCLUDE_RUNTIME)
+  list(APPEND FLANG_TEST_DEPENDS FortranRuntime)
+endif ()
+
 if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
   list(APPEND FLANG_TEST_DEPENDS Bye)
 endif()
diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90
index 78eac32133b18e1..10c7adaccc9588b 100644
--- a/flang/test/Driver/ctofortran.f90
+++ b/flang/test/Driver/ctofortran.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! RUN: split-file %s %t
 ! RUN: chmod +x %t/runtest.sh
 ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s
diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90
index fd174005ddf62ac..9ca91ee24011c9f 100644
--- a/flang/test/Driver/exec.f90
+++ b/flang/test/Driver/exec.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! Verify that flang can correctly build executables.
 
 ! RUN: %flang %s -o %t
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index b1a5fa004014cc8..7303ce63fdec410 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on 
the C++ runtime
 library. It tries to link this simple file against libFortranRuntime.a with
 a C compiler.
 
-REQUIRES: c-compiler
+REQUIRES: c-compiler, flang-rt
 
 RUN: %if system-aix %{ export OBJECT_MODE=64 %}
 RUN: %cc -std=c99 %s -I%include %libruntime -lm  \
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index c452b6d231c89f0..f4580afc8c47b12 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -163,10 +163,13 @@
 ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), 
unresolved="fatal")
 )
 
+if config.flang_include_runtime:
+config.available_features.add("flang-rt")
+
 # Define some variables to help us test that the flang runtime doesn't depend 
on
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
-if config.cc:
+if config.flang_include_runtime and config.cc:
 libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
 include = os.path.join(config.flang_src_dir, "include")
 
diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index d1a0ac763cf8a06..697ba3fa797633d 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -1,6 +1,7 @@
 @LIT_SITE_CFG_IN_HEADER@
 
 import sys
+import lit.util
 
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
@@ -32,6 +33,7 @@ else:
 config.openmp_module_dir = None
 config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
 config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
+config.flang_include_runtime = 
lit.util.pythonize_bool("@FLANG_INCLUDE_RUNTIME@")
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
diff --git a/flang/tools/

[llvm-branch-commits] [clang] [flang] [lld] [Flang] Rename libFortranRuntime.a to libflang_rt.a (PR #122341)

2025-01-30 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/122341

>From 875607fdecfada90a80ec732637ea9595fe72ba3 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Fri, 24 Jan 2025 16:42:24 +0100
Subject: [PATCH] [Flang] Rename libFortranRuntime.a to libflang_rt.a

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  4 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  8 ++--
 flang/CMakeLists.txt  |  2 +-
 flang/docs/FlangDriver.md |  6 +--
 flang/docs/GettingStarted.md  |  6 +--
 flang/docs/OpenACC-descriptor-management.md   |  2 +-
 flang/docs/ReleaseNotes.md|  2 +
 .../ExternalHelloWorld/CMakeLists.txt |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp |  2 +-
 flang/runtime/CMakeLists.txt  | 40 +++
 flang/runtime/CUDA/CMakeLists.txt |  2 +-
 flang/runtime/Float128Math/CMakeLists.txt |  2 +-
 flang/runtime/time-intrinsic.cpp  |  2 +-
 flang/test/CMakeLists.txt |  8 +++-
 .../test/Driver/gcc-toolchain-install-dir.f90 |  2 +-
 flang/test/Driver/linker-flags.f90|  8 ++--
 .../test/Driver/msvc-dependent-lib-flags.f90  |  8 ++--
 flang/test/Driver/nostdlib.f90|  2 +-
 flang/test/Runtime/no-cpp-dep.c   |  2 +-
 flang/test/lit.cfg.py |  2 +-
 flang/tools/f18/CMakeLists.txt|  8 ++--
 flang/unittests/CMakeLists.txt|  2 +-
 flang/unittests/Evaluate/CMakeLists.txt   |  4 +-
 flang/unittests/Runtime/CMakeLists.txt|  2 +-
 flang/unittests/Runtime/CUDA/CMakeLists.txt   |  2 +-
 lld/COFF/MinGW.cpp|  2 +-
 26 files changed, 73 insertions(+), 59 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b5273dd8cf1e3a..c7b0a660ee021f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation 
&C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
-  // Link FortranRuntime
+  // Link flang_rt
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1337,7 +1337,7 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
   if (AsNeeded)
 addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
 }
-CmdArgs.push_back("-lFortranRuntime");
+CmdArgs.push_back("-lflang_rt");
 addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index f1bf32b3238270..68a17edf8ca341 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -360,26 +360,26 @@ static void processVSRuntimeLibrary(const ToolChain &TC, 
const ArgList &Args,
   case options::OPT__SLASH_MT:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("--dependent-lib=libcmt");
-CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
+CmdArgs.push_back("--dependent-lib=flang_rt.static.lib");
 break;
   case options::OPT__SLASH_MTd:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DEBUG");
 CmdArgs.push_back("--dependent-lib=libcmtd");
-CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
+CmdArgs.push_back("--dependent-lib=flang_rt.static_dbg.lib");
 break;
   case options::OPT__SLASH_MD:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrt");
-CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
+CmdArgs.push_back("--dependent-lib=flang_rt.dynamic.lib");
 break;
   case options::OPT__SLASH_MDd:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DEBUG");
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrtd");
-CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
+CmdArgs.push_back("--dependent-lib=flang_rt.dynamic_dbg.lib");
 break;
   }
 }
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 7d6dcb5c184a52..8a8b8bfa73b007 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -301,7 +301,7 @@ set(FLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 
 set(FLANG_DEFAULT_RTLIB "" CACHE STRING
-   "Default Fortran runtime library to use (\"libFortranRuntime\"), leave 
empty for platform default.")
+   "Default Fortran runtime library to use (\"libflang_rt\"), leave empty for 
platform default.")
 
 if (NOT(FLANG_DEFAULT_RTLIB STREQUAL ""))
   message(W

[llvm-branch-commits] [clang] [flang] [lld] [Flang] Don't use FortranDecimal for runtime (PR #121997)

2025-01-30 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/121997

>From 2e50a1f563dcfec3dae1a5770ed4c90189cf7ba8 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Fri, 24 Jan 2025 16:28:55 +0100
Subject: [PATCH] [Flang] Don't use FortranDecimal for runtime

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  3 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  4 -
 flang/docs/FlangDriver.md |  7 +-
 flang/lib/Decimal/CMakeLists.txt  | 92 ++-
 flang/runtime/CMakeLists.txt  | 14 +--
 flang/test/Driver/linker-flags.f90|  6 +-
 .../test/Driver/msvc-dependent-lib-flags.f90  |  4 -
 flang/test/Driver/nostdlib.f90|  1 -
 flang/test/Runtime/no-cpp-dep.c   |  2 +-
 flang/test/lit.cfg.py |  3 -
 lld/COFF/MinGW.cpp|  1 -
 11 files changed, 18 insertions(+), 119 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f8967890f722cf..b5273dd8cf1e3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation 
&C,
 /// Add Fortran runtime libs
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
-  // Link FortranRuntime and FortranDecimal
+  // Link FortranRuntime
   // These are handled earlier on Windows by telling the frontend driver to
   // add the correct libraries to link against as dependents in the object
   // file.
@@ -1338,7 +1338,6 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
 addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
 }
 CmdArgs.push_back("-lFortranRuntime");
-CmdArgs.push_back("-lFortranDecimal");
 addArchSpecificRPath(TC, Args, CmdArgs);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 86ed25badfa2b7..f1bf32b3238270 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -361,21 +361,18 @@ static void processVSRuntimeLibrary(const ToolChain &TC, 
const ArgList &Args,
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("--dependent-lib=libcmt");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
 break;
   case options::OPT__SLASH_MTd:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DEBUG");
 CmdArgs.push_back("--dependent-lib=libcmtd");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
 break;
   case options::OPT__SLASH_MD:
 CmdArgs.push_back("-D_MT");
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrt");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
 break;
   case options::OPT__SLASH_MDd:
 CmdArgs.push_back("-D_MT");
@@ -383,7 +380,6 @@ static void processVSRuntimeLibrary(const ToolChain &TC, 
const ArgList &Args,
 CmdArgs.push_back("-D_DLL");
 CmdArgs.push_back("--dependent-lib=msvcrtd");
 CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
-CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic_dbg.lib");
 break;
   }
 }
diff --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 23cbab30ee903e..be5633529f50cd 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -175,19 +175,18 @@ like this:
 
 ```
 $ flang -v -o example example.o
-"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" "-lFortranDecimal" [...]
+"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" [...]
 ```
 
 The automatically added libraries are:
 
 * `FortranRuntime`: Provides most of the Flang runtime library.
-* `FortranDecimal`: Provides operations for decimal numbers.
 
 If the code is C/C++ based and invokes Fortran routines, one can either use 
Clang
 or Flang as the linker driver.  If Clang is used, it will automatically all
 required runtime libraries needed by C++ (e.g., for STL) to the linker 
invocation.
-In this case, one has to explicitly provide the Fortran runtime libraries
-`FortranRuntime` and/or `FortranDecimal`.  An alternative is to use Flang to 
link.
+In this case, one has to explicitly provide the Fortran runtime library
+`FortranRuntime`.  An alternative is to use Flang to link.
 In this case, it may be required to explicitly supply C++ runtime libraries.
 
 On Darwin, the logical root where the system libraries are located (sysroot)
diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index 880b190f1c5815..477d44e0565ebe 100644

[llvm-branch-commits] [flang] [Flang] Promote FortranEvaluateTesting library (PR #124417)

2025-01-30 Thread Michael Kruse via llvm-branch-commits

https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/124417

>From 71015c8f9ab17431d052472aec99dc67929a166e Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Fri, 24 Jan 2025 16:30:47 +0100
Subject: [PATCH] [Flang] Promote FortranEvaluateTesting library

---
 .../flang/Testing}/fp-testing.h   | 14 ++--
 .../flang/Testing}/testing.h  | 14 ++--
 flang/lib/CMakeLists.txt  |  4 +++
 flang/lib/Testing/CMakeLists.txt  | 20 +++
 .../Evaluate => lib/Testing}/fp-testing.cpp   | 10 +-
 .../Evaluate => lib/Testing}/testing.cpp  | 10 +-
 flang/unittests/Evaluate/CMakeLists.txt   | 35 ++-
 .../Evaluate/ISO-Fortran-binding.cpp  |  2 +-
 .../Evaluate/bit-population-count.cpp |  2 +-
 flang/unittests/Evaluate/expression.cpp   |  2 +-
 flang/unittests/Evaluate/folding.cpp  |  2 +-
 flang/unittests/Evaluate/integer.cpp  |  2 +-
 flang/unittests/Evaluate/intrinsics.cpp   |  2 +-
 .../Evaluate/leading-zero-bit-count.cpp   |  2 +-
 flang/unittests/Evaluate/logical.cpp  |  2 +-
 flang/unittests/Evaluate/real.cpp |  4 +--
 flang/unittests/Evaluate/reshape.cpp  |  2 +-
 flang/unittests/Evaluate/uint128.cpp  |  2 +-
 18 files changed, 87 insertions(+), 44 deletions(-)
 rename flang/{unittests/Evaluate => include/flang/Testing}/fp-testing.h (54%)
 rename flang/{unittests/Evaluate => include/flang/Testing}/testing.h (74%)
 create mode 100644 flang/lib/Testing/CMakeLists.txt
 rename flang/{unittests/Evaluate => lib/Testing}/fp-testing.cpp (87%)
 rename flang/{unittests/Evaluate => lib/Testing}/testing.cpp (88%)

diff --git a/flang/unittests/Evaluate/fp-testing.h 
b/flang/include/flang/Testing/fp-testing.h
similarity index 54%
rename from flang/unittests/Evaluate/fp-testing.h
rename to flang/include/flang/Testing/fp-testing.h
index 9091963a99b32d..e223d2ef7d1b8b 100644
--- a/flang/unittests/Evaluate/fp-testing.h
+++ b/flang/include/flang/Testing/fp-testing.h
@@ -1,5 +1,13 @@
-#ifndef FORTRAN_TEST_EVALUATE_FP_TESTING_H_
-#define FORTRAN_TEST_EVALUATE_FP_TESTING_H_
+//===-- include/flang/Testing/fp-testing.h --*- 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
+//
+//===--===//
+
+#ifndef FORTRAN_TESTING_FP_TESTING_H_
+#define FORTRAN_TESTING_FP_TESTING_H_
 
 #include "flang/Common/target-rounding.h"
 #include 
@@ -24,4 +32,4 @@ class ScopedHostFloatingPointEnvironment {
 #endif
 };
 
-#endif // FORTRAN_TEST_EVALUATE_FP_TESTING_H_
+#endif /* FORTRAN_TESTING_FP_TESTING_H_ */
diff --git a/flang/unittests/Evaluate/testing.h 
b/flang/include/flang/Testing/testing.h
similarity index 74%
rename from flang/unittests/Evaluate/testing.h
rename to flang/include/flang/Testing/testing.h
index 422e2853c05bc6..404650c9a89f2c 100644
--- a/flang/unittests/Evaluate/testing.h
+++ b/flang/include/flang/Testing/testing.h
@@ -1,5 +1,13 @@
-#ifndef FORTRAN_EVALUATE_TESTING_H_
-#define FORTRAN_EVALUATE_TESTING_H_
+//===-- include/flang/Testing/testing.h -*- 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
+//
+//===--===//
+
+#ifndef FORTRAN_TESTING_TESTING_H_
+#define FORTRAN_TESTING_TESTING_H_
 
 #include 
 #include 
@@ -33,4 +41,4 @@ FailureDetailPrinter Match(const char *file, int line, const 
std::string &want,
 FailureDetailPrinter Compare(const char *file, int line, const char *xs,
 const char *rel, const char *ys, std::uint64_t x, std::uint64_t y);
 } // namespace testing
-#endif // FORTRAN_EVALUATE_TESTING_H_
+#endif /* FORTRAN_TESTING_TESTING_H_ */
diff --git a/flang/lib/CMakeLists.txt b/flang/lib/CMakeLists.txt
index 05c3535b09b3d3..8b201d9a758a80 100644
--- a/flang/lib/CMakeLists.txt
+++ b/flang/lib/CMakeLists.txt
@@ -8,3 +8,7 @@ add_subdirectory(Frontend)
 add_subdirectory(FrontendTool)
 
 add_subdirectory(Optimizer)
+
+if (FLANG_INCLUDE_TESTS)
+  add_subdirectory(Testing)
+endif ()
diff --git a/flang/lib/Testing/CMakeLists.txt b/flang/lib/Testing/CMakeLists.txt
new file mode 100644
index 00..8051bc09736d16
--- /dev/null
+++ b/flang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,20 @@
+#===-- lib/Testing/CMakeLists.txt 
--===#
+#
+# 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
+#
+#===

[llvm-branch-commits] [clang] [flang] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=flang-rt (PR #110217)

2025-01-30 Thread Michael Kruse via llvm-branch-commits

Meinersbur wrote:

> On linux (without rebuilding `compiler-rt`), I still see
> 
> ```
> [72/72] Linking CXX static library flang-rt/lib/libflang_rt.a
> + cmake --install .
> Install configuration: "Release"
> Installing: $PREFIX/lib/clang/20/lib/x86_64-unknown-linux-gnu/libflang_rt.a
> ```
> 
> (which then leads to the library not being found.)
> 
> The outputs you asked for are
> 
> ```
> LLVM_TREE_AVAILABLE: OFF
> toolchain_lib_subdir: lib/x86_64-unknown-linux-gnu
> FLANG_RT_OUTPUT_RESOURCE_DIR: $SRC_DIR/build/flang-rt
> FLANG_RT_INSTALL_RESOURCE_PATH: lib/clang/20
> FLANG_RT_OUTPUT_RESOURCE_LIB_DIR: $SRC_DIR/build/flang-rt/lib
> FLANG_RT_INSTALL_RESOURCE_LIB_PATH: lib/clang/20/lib/x86_64-unknown-linux-gnu
> ```

Are these the literal outputs or did you edit them? Please don't. There should 
be no "$" in those outputs. What I get:
```
LLVM_TREE_AVAILABLE: OFF
toolchain_lib_subdir: lib/x86_64-unknown-linux-gnu
FLANG_RT_OUTPUT_RESOURCE_DIR: 
/home/meinersbur/build/llvm-project-flangrt/release_runtimes/runtimes/flang-rt
FLANG_RT_INSTALL_RESOURCE_PATH: lib/clang/21
FLANG_RT_OUTPUT_RESOURCE_LIB_DIR: 
/home/meinersbur/build/llvm-project-flangrt/release_runtimes/runtimes/flang-rt/lib
FLANG_RT_INSTALL_RESOURCE_LIB_PATH: lib/clang/21/lib/x86_64-unknown-linux-gnu
...
[ 98%/2.675s :: 0->1->72 (of 73)] Install the project...
-- Install configuration: "Release"
-- Installing: 
/home/meinersbur/build/llvm-project-flangrt/release_runtimes/install/lib/clang/21/lib/x86_64-unknown-linux-gnu/libflang_rt.a
...
$ 
/home/meinersbur/build/llvm-project-flangrt/release_runtimes/install/bin/flang 
hello.f90 -o hello && ./hello
 Hello, World!  
```
If I use `-DCMAKE_INSTALL_PREFIX="\\\$PREFIX"` I do get different output (that 
does not work).

https://github.com/llvm/llvm-project/pull/110217
___
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] [lldb] 140f091 - Revert "Reland "[lldb] Implement basic support for reverse-continue" (#123906…"

2025-01-30 Thread via llvm-branch-commits

Author: David Spickett
Date: 2025-01-30T16:44:34Z
New Revision: 140f0918c81a9e4e2142f404103c5870fdf7cb34

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

LOG: Revert "Reland "[lldb] Implement basic support for reverse-continue" 
(#123906…"

This reverts commit 0caba6c8dc2f6f0da61f30c169f59d40591cddbc.

Added: 


Modified: 
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/include/lldb/Target/StopInfo.h
lldb/include/lldb/Target/Thread.h
lldb/include/lldb/Target/ThreadList.h
lldb/include/lldb/Target/ThreadPlan.h
lldb/include/lldb/Target/ThreadPlanBase.h
lldb/include/lldb/lldb-enumerations.h
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
lldb/source/API/SBProcess.cpp
lldb/source/API/SBThread.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Target/Process.cpp
lldb/source/Target/StopInfo.cpp
lldb/source/Target/Thread.cpp
lldb/source/Target/ThreadList.cpp
lldb/source/Target/ThreadPlanBase.cpp
lldb/tools/lldb-dap/JSONUtils.cpp
lldb/tools/lldb-dap/LLDBUtils.cpp

Removed: 
lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py
lldb/packages/Python/lldbsuite/test/lldbreverse.py
lldb/test/API/functionalities/reverse-execution/Makefile

lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py

lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py

lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
lldb/test/API/functionalities/reverse-execution/main.c



diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 882b8bd837131d..1624e02070b1b2 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -159,7 +159,6 @@ class LLDB_API SBProcess {
   lldb::SBError Destroy();
 
   lldb::SBError Continue();
-  lldb::SBError ContinueInDirection(lldb::RunDirection direction);
 
   lldb::SBError Stop();
 

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index b14eb3fbd91d00..a184e6dd891aff 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1089,13 +1089,6 @@ class Process : public 
std::enable_shared_from_this,
   /// Returns an error object.
   virtual Status WillResume() { return Status(); }
 
-  /// Reports whether this process supports reverse execution.
-  ///
-  /// \return
-  /// Returns true if the process supports reverse execution (at least
-  /// under some circumstances).
-  virtual bool SupportsReverseDirection() { return false; }
-
   /// Resumes all of a process's threads as configured using the Thread run
   /// control functions.
   ///
@@ -,13 +1104,9 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  virtual Status DoResume(lldb::RunDirection direction) {
-if (direction == lldb::RunDirection::eRunForward)
-  return Status::FromErrorStringWithFormatv(
-  "error: {0} does not support resuming processes", GetPluginName());
+  virtual Status DoResume() {
 return Status::FromErrorStringWithFormatv(
-"error: {0} does not support reverse execution of processes",
-GetPluginName());
+"error: {0} does not support resuming processes", GetPluginName());
   }
 
   /// Called after resuming a process.
@@ -2687,18 +2676,6 @@ void PruneThreadPlans();
 const AddressRange &range, size_t alignment,
 Status &error);
 
-  /// Get the base run direction for the process.
-  /// The base direction is the direction the process will execute in
-  /// (forward or backward) if no thread plan overrides the direction.
-  lldb::RunDirection GetBaseD

[llvm-branch-commits] [clang] release/20.x: [AArch64] Add MSVC mangling for the __mfp8 type (#124968) (PR #125066)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/125066
___
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] release/20.x: [AArch64] Add MSVC mangling for the __mfp8 type (#124968) (PR #125066)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/125066

Backport 7939ce6295e7fc0214cd307f97dfccc0cabde381

Requested by: @MacDue

>From 5f3e4eeefd408e660aec1c93053edd8d29d3b432 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Thu, 30 Jan 2025 10:42:12 +
Subject: [PATCH] [AArch64] Add MSVC mangling for the __mfp8 type (#124968)

Fixes #124907

(cherry picked from commit 7939ce6295e7fc0214cd307f97dfccc0cabde381)
---
 clang/lib/AST/MicrosoftMangle.cpp|  5 +
 clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp | 14 ++
 2 files changed, 19 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp

diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index edeeaeaa9ae17c..42b735ccf4a2ce 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2792,6 +2792,10 @@ void MicrosoftCXXNameMangler::mangleType(const 
BuiltinType *T, Qualifiers,
 mangleArtificialTagType(TagTypeKind::Struct, "__bf16", {"__clang"});
 break;
 
+  case BuiltinType::MFloat8:
+mangleArtificialTagType(TagTypeKind::Struct, "__mfp8", {"__clang"});
+break;
+
 #define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS)  
\
   case BuiltinType::Id:
\
 mangleArtificialTagType(TagTypeKind::Struct, MangledName); 
\
@@ -2808,6 +2812,7 @@ void MicrosoftCXXNameMangler::mangleType(const 
BuiltinType *T, Qualifiers,
 
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits)
 #include "clang/Basic/AArch64SVEACLETypes.def"
 #define PPC_VECTOR_TYPE(Name, Id, Size) \
   case BuiltinType::Id:
diff --git a/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp 
b/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp
new file mode 100644
index 00..b5fd9171ad81a9
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-ms-mangle-mfp8.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple aarch64-windows-msvc -emit-llvm -o - %s | FileCheck 
%s
+
+typedef __mfp8 mf8;
+typedef __attribute__((neon_vector_type(8))) __mfp8 mf8x8_t;
+typedef __attribute__((neon_vector_type(16))) __mfp8 mf8x16_t;
+
+// CHECK: "?f@@YAXU__mfp8@__clang@@@Z"
+void f(mf8 v) {}
+
+// CHECK: "?f@@YAXT?$__vector@U__mfp8@__clang@@$07@__clang@@@Z"
+void f(mf8x8_t v) {}
+
+// CHECK: "?f@@YAXT?$__vector@U__mfp8@__clang@@$0BA@@__clang@@@Z"
+void f(mf8x16_t v) {}

___
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] release/20.x: [AArch64] Add MSVC mangling for the __mfp8 type (#124968) (PR #125066)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:

@momchil-velikov What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/125066
___
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] [libcxx] [llvm] Bump version to 20.1.0git (PR #125067)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Tom Stellard (tstellar)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/125067.diff


4 Files Affected:

- (modified) cmake/Modules/LLVMVersion.cmake (+1-1) 
- (modified) libcxx/include/__config (+1-1) 
- (modified) llvm/utils/gn/secondary/llvm/version.gni (+1-1) 
- (modified) llvm/utils/lit/lit/__init__.py (+1-1) 


``diff
diff --git a/cmake/Modules/LLVMVersion.cmake b/cmake/Modules/LLVMVersion.cmake
index 897dd963bd9ab6..281d0444255bac 100644
--- a/cmake/Modules/LLVMVersion.cmake
+++ b/cmake/Modules/LLVMVersion.cmake
@@ -4,7 +4,7 @@ if(NOT DEFINED LLVM_VERSION_MAJOR)
   set(LLVM_VERSION_MAJOR 20)
 endif()
 if(NOT DEFINED LLVM_VERSION_MINOR)
-  set(LLVM_VERSION_MINOR 0)
+  set(LLVM_VERSION_MINOR 1)
 endif()
 if(NOT DEFINED LLVM_VERSION_PATCH)
   set(LLVM_VERSION_PATCH 0)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 30b2d147dc5634..a866a7e6518379 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -28,7 +28,7 @@
 // _LIBCPP_VERSION represents the version of libc++, which matches the version 
of LLVM.
 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), 
_LIBCPP_VERSION is
 // defined to XXYYZZ.
-#  define _LIBCPP_VERSION 20
+#  define _LIBCPP_VERSION 200100
 
 #  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
 #  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
diff --git a/llvm/utils/gn/secondary/llvm/version.gni 
b/llvm/utils/gn/secondary/llvm/version.gni
index e0107cdeae76de..a99e5ba892da5b 100644
--- a/llvm/utils/gn/secondary/llvm/version.gni
+++ b/llvm/utils/gn/secondary/llvm/version.gni
@@ -1,4 +1,4 @@
 llvm_version_major = 20
-llvm_version_minor = 0
+llvm_version_minor = 1
 llvm_version_patch = 0
 llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch"
diff --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py
index ea56d192fb3942..e1e31718020f22 100644
--- a/llvm/utils/lit/lit/__init__.py
+++ b/llvm/utils/lit/lit/__init__.py
@@ -2,7 +2,7 @@
 
 __author__ = "Daniel Dunbar"
 __email__ = "dan...@minormatter.com"
-__versioninfo__ = (20, 0, 0)
+__versioninfo__ = (20, 1, 0)
 __version__ = ".".join(str(v) for v in __versioninfo__) + "dev"
 
 __all__ = []

``




https://github.com/llvm/llvm-project/pull/125067
___
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] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-30 Thread Damyan Pepper via llvm-branch-commits


@@ -0,0 +1,159 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature 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 and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
+  this->Version = Version;
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());

damyanp wrote:

Right, but that's still an MDString inside an MDNode.  I couldn't find a way to 
have an operand of an NamedMDNode be anything other than an MDNode.

This, for example, is not valid:

```llvmir
!2 = !"RootFlags"
```


https://github.com/llvm/llvm-project/pull/123147
___
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] [llvm] [mlir] [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (PR #124746)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits


@@ -3421,6 +3441,85 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
   }
 }
 
+static llvm::Expected
+emitUserDefinedMapper(Operation *declMapperOp, llvm::IRBuilderBase &builder,
+  LLVM::ModuleTranslation &moduleTranslation);
+
+static llvm::Expected
+getOrCreateUserDefinedMapperFunc(Operation *declMapperOp,
+ llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::DenseMap userDefMapperMap;
+  auto iter = userDefMapperMap.find(declMapperOp);
+  if (iter != userDefMapperMap.end())
+return iter->second;
+  llvm::Expected mapperFunc =
+  emitUserDefinedMapper(declMapperOp, builder, moduleTranslation);
+  if (!mapperFunc)
+return mapperFunc.takeError();
+  userDefMapperMap.try_emplace(declMapperOp, *mapperFunc);
+  return userDefMapperMap.lookup(declMapperOp);
+}
+
+static llvm::Expected
+emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
+  LLVM::ModuleTranslation &moduleTranslation) {
+  auto declMapperOp = cast(op);
+  auto declMapperInfoOp =
+  *declMapperOp.getOps().begin();
+  DataLayout dl = DataLayout(declMapperOp->getParentOfType());
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::Type *varType =
+  moduleTranslation.convertType(declMapperOp.getVarType());
+  std::string mapperName = ompBuilder->createPlatformSpecificName(
+  {"omp_mapper", declMapperOp.getSymName()});
+  SmallVector mapVars = declMapperInfoOp.getMapVars();
+
+  using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+
+  // Fill up the arrays with all the mapped variables.
+  MapInfosTy combinedInfo;
+  auto genMapInfoCB =
+  [&](InsertPointTy codeGenIP, llvm::Value *ptrPHI,
+  llvm::Value *unused2) -> llvm::OpenMPIRBuilder::MapInfosOrErrorTy {
+builder.restoreIP(codeGenIP);
+moduleTranslation.mapValue(declMapperOp.getRegion().getArgument(0), 
ptrPHI);
+moduleTranslation.mapBlock(&declMapperOp.getRegion().front(),
+   builder.GetInsertBlock());
+if (failed(moduleTranslation.convertBlock(declMapperOp.getRegion().front(),
+  /*ignoreArguments=*/true,
+  builder)))
+  return llvm::make_error();
+MapInfoData mapData;
+collectMapDataFromMapOperands(mapData, mapVars, moduleTranslation, dl,
+  builder);
+genMapInfos(builder, moduleTranslation, dl, combinedInfo, mapData);
+
+// Drop the mapping that is no longer necessary so that the same region can
+// be processed multiple times.
+moduleTranslation.forgetMapping(declMapperOp.getRegion());
+return combinedInfo;
+  };
+
+  auto customMapperCB = [&](unsigned i, llvm::Function **mapperFunc) {
+if (combinedInfo.Mappers[i]) {
+  // Call the corresponding mapper function.
+  llvm::Expected newFn = 
getOrCreateUserDefinedMapperFunc(

ergawy wrote:

Can you help me undestand how `emitUserDefinedMapper` and 
`getOrCreateUserDefinedMapperFunc` work together? It seems they are mutually 
recursive but the recusion is not happening because `combinedInfo.Mappers[i]` 
is `false`. Can you explain the sequence of events here a bit?

https://github.com/llvm/llvm-project/pull/124746
___
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] release/20.x: [AArch64] Add MSVC mangling for the __mfp8 type (#124968) (PR #125066)

2025-01-30 Thread Momchil Velikov via llvm-branch-commits

https://github.com/momchil-velikov approved this pull request.


https://github.com/llvm/llvm-project/pull/125066
___
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] [llvm] [mlir] [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (PR #124746)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits


@@ -3421,6 +3441,85 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
   }
 }
 
+static llvm::Expected
+emitUserDefinedMapper(Operation *declMapperOp, llvm::IRBuilderBase &builder,
+  LLVM::ModuleTranslation &moduleTranslation);
+
+static llvm::Expected
+getOrCreateUserDefinedMapperFunc(Operation *declMapperOp,
+ llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::DenseMap userDefMapperMap;
+  auto iter = userDefMapperMap.find(declMapperOp);
+  if (iter != userDefMapperMap.end())
+return iter->second;
+  llvm::Expected mapperFunc =
+  emitUserDefinedMapper(declMapperOp, builder, moduleTranslation);
+  if (!mapperFunc)
+return mapperFunc.takeError();
+  userDefMapperMap.try_emplace(declMapperOp, *mapperFunc);
+  return userDefMapperMap.lookup(declMapperOp);

ergawy wrote:

nit
```suggestion
  return *mapperFunc;
```

https://github.com/llvm/llvm-project/pull/124746
___
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] [llvm] [mlir] [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (PR #124746)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits


@@ -3421,6 +3441,85 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
   }
 }
 
+static llvm::Expected
+emitUserDefinedMapper(Operation *declMapperOp, llvm::IRBuilderBase &builder,
+  LLVM::ModuleTranslation &moduleTranslation);
+
+static llvm::Expected
+getOrCreateUserDefinedMapperFunc(Operation *declMapperOp,
+ llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::DenseMap userDefMapperMap;
+  auto iter = userDefMapperMap.find(declMapperOp);

ergawy wrote:

`userDefMapperMap` is empty at this point. Is it supposed to managed globally 
outside `emitUserDefinedMapper` (for the whole `mlir::ModuleOp` for example)?

https://github.com/llvm/llvm-project/pull/124746
___
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] [llvm] [mlir] [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (PR #124746)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits

https://github.com/ergawy edited 
https://github.com/llvm/llvm-project/pull/124746
___
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] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: Patryk Wychowaniec (Patryk27)


Changes

This pull request backports #118015 and #121498 to 19.x, so 
that the fixes can be pulled to rustc.

Not sure if backports warrant an extra review - especially since there were no 
major changes in here, just a small conflict somewhere in AVRAsmBackend.cpp 
IIRC -  but just in case: cc @benshi001.

---

Patch is 359.05 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/125081.diff


26 Files Affected:

- (modified) llvm/include/llvm/MC/MCAsmBackend.h (+1) 
- (modified) llvm/lib/MC/MCAssembler.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/AVR/AVRDevices.td (+31-19) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp (+60-55) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp 
(+1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h 
(+1-1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp 
(+2-2) 
- (modified) llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp (+2-1) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-backward.ll (+2088) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-forward.ll (+2088) 
- (removed) llvm/test/CodeGen/AVR/branch-relaxation-long.ll (-4162) 


``diff
diff --git a/llvm/include/llvm/MC/MCAsmBackend.h 
b/llvm/include/llvm/MC/MCAsmBackend.h
index 3f88ac02cd92ac..74ce676170d93c 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -94,6 +94,7 @@ class MCAsmBackend {
   virtual bool shouldForceRelocation(const MCAssembler &Asm,
  const MCFixup &Fixup,
  const MCValue &Target,
+ const uint64_t Value,
  const MCSubtargetInfo *STI) {
 return false;
   }
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index c3da4bb5cc363c..c0465ab3c992ca 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -231,7 +231,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const 
MCFragment *DF,
 
   // Let the backend force a relocation if needed.
   if (IsResolved &&
-  getBackend().shouldForceRelocation(*this, Fixup, Target, STI)) {
+  getBackend().shouldForceRelocation(*this, Fixup, Target, Value, STI)) {
 IsResolved = false;
 WasForced = true;
   }
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp 
b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index be34a649e1c4bf..196bfbdfe5cb09 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -100,7 +100,7 @@ class AArch64AsmBackend : public MCAsmBackend {
   unsigned getFixupKindContainereSizeInBytes(unsigned Kind) const;
 
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
- const MCValue &Target,
+ const MCValue &Target, const uint64_t Value,
  const MCSubtargetInfo *STI) override;
 };
 
@@ -512,6 +512,7 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, 
uint64_t Count,
 bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
   const MCFixup &Fixup,
   const MCValue &Target,
+  const uint64_t,
   const MCSubtargetInfo *STI) {
   unsigned Kind = Fixup.getKind();
   if (Kind >= FirstLiteralRelocationKind)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp 
b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
index c2d2ca0f90f930..2

[llvm-branch-commits] [llvm] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Patryk Wychowaniec (Patryk27)


Changes

This pull request backports #118015 and #121498 to 19.x, so 
that the fixes can be pulled to rustc.

Not sure if backports warrant an extra review - especially since there were no 
major changes in here, just a small conflict somewhere in AVRAsmBackend.cpp 
IIRC -  but just in case: cc @benshi001.

---

Patch is 359.05 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/125081.diff


26 Files Affected:

- (modified) llvm/include/llvm/MC/MCAsmBackend.h (+1) 
- (modified) llvm/lib/MC/MCAssembler.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/AVR/AVRDevices.td (+31-19) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp (+60-55) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp 
(+1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h 
(+1-1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp 
(+2-2) 
- (modified) llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp (+2-1) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-backward.ll (+2088) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-forward.ll (+2088) 
- (removed) llvm/test/CodeGen/AVR/branch-relaxation-long.ll (-4162) 


``diff
diff --git a/llvm/include/llvm/MC/MCAsmBackend.h 
b/llvm/include/llvm/MC/MCAsmBackend.h
index 3f88ac02cd92ac..74ce676170d93c 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -94,6 +94,7 @@ class MCAsmBackend {
   virtual bool shouldForceRelocation(const MCAssembler &Asm,
  const MCFixup &Fixup,
  const MCValue &Target,
+ const uint64_t Value,
  const MCSubtargetInfo *STI) {
 return false;
   }
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index c3da4bb5cc363c..c0465ab3c992ca 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -231,7 +231,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const 
MCFragment *DF,
 
   // Let the backend force a relocation if needed.
   if (IsResolved &&
-  getBackend().shouldForceRelocation(*this, Fixup, Target, STI)) {
+  getBackend().shouldForceRelocation(*this, Fixup, Target, Value, STI)) {
 IsResolved = false;
 WasForced = true;
   }
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp 
b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index be34a649e1c4bf..196bfbdfe5cb09 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -100,7 +100,7 @@ class AArch64AsmBackend : public MCAsmBackend {
   unsigned getFixupKindContainereSizeInBytes(unsigned Kind) const;
 
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
- const MCValue &Target,
+ const MCValue &Target, const uint64_t Value,
  const MCSubtargetInfo *STI) override;
 };
 
@@ -512,6 +512,7 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, 
uint64_t Count,
 bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
   const MCFixup &Fixup,
   const MCValue &Target,
+  const uint64_t,
   const MCSubtargetInfo *STI) {
   unsigned Kind = Fixup.getKind();
   if (Kind >= FirstLiteralRelocationKind)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp 
b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
index c2d2ca0f90f93

[llvm-branch-commits] [llvm] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: Patryk Wychowaniec (Patryk27)


Changes

This pull request backports #118015 and #121498 to 19.x, so 
that the fixes can be pulled to rustc.

Not sure if backports warrant an extra review - especially since there were no 
major changes in here, just a small conflict somewhere in AVRAsmBackend.cpp 
IIRC -  but just in case: cc @benshi001.

---

Patch is 359.05 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/125081.diff


26 Files Affected:

- (modified) llvm/include/llvm/MC/MCAsmBackend.h (+1) 
- (modified) llvm/lib/MC/MCAssembler.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/AVR/AVRDevices.td (+31-19) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp (+60-55) 
- (modified) llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp 
(+1) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h 
(+1-1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp (+1) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (+2-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h (+1-1) 
- (modified) llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp 
(+2-2) 
- (modified) llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp (+2-1) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-backward.ll (+2088) 
- (added) llvm/test/CodeGen/AVR/branch-relaxation-long-forward.ll (+2088) 
- (removed) llvm/test/CodeGen/AVR/branch-relaxation-long.ll (-4162) 


``diff
diff --git a/llvm/include/llvm/MC/MCAsmBackend.h 
b/llvm/include/llvm/MC/MCAsmBackend.h
index 3f88ac02cd92ac..74ce676170d93c 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -94,6 +94,7 @@ class MCAsmBackend {
   virtual bool shouldForceRelocation(const MCAssembler &Asm,
  const MCFixup &Fixup,
  const MCValue &Target,
+ const uint64_t Value,
  const MCSubtargetInfo *STI) {
 return false;
   }
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index c3da4bb5cc363c..c0465ab3c992ca 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -231,7 +231,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const 
MCFragment *DF,
 
   // Let the backend force a relocation if needed.
   if (IsResolved &&
-  getBackend().shouldForceRelocation(*this, Fixup, Target, STI)) {
+  getBackend().shouldForceRelocation(*this, Fixup, Target, Value, STI)) {
 IsResolved = false;
 WasForced = true;
   }
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp 
b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index be34a649e1c4bf..196bfbdfe5cb09 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -100,7 +100,7 @@ class AArch64AsmBackend : public MCAsmBackend {
   unsigned getFixupKindContainereSizeInBytes(unsigned Kind) const;
 
   bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
- const MCValue &Target,
+ const MCValue &Target, const uint64_t Value,
  const MCSubtargetInfo *STI) override;
 };
 
@@ -512,6 +512,7 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, 
uint64_t Count,
 bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
   const MCFixup &Fixup,
   const MCValue &Target,
+  const uint64_t,
   const MCSubtargetInfo *STI) {
   unsigned Kind = Fixup.getKind();
   if (Kind >= FirstLiteralRelocationKind)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp 
b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
index c2d2ca0f90f93

[llvm-branch-commits] [llvm] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread Patryk Wychowaniec via llvm-branch-commits

https://github.com/Patryk27 edited 
https://github.com/llvm/llvm-project/pull/125081
___
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] AMDGPU/GlobalISel: Temporal divergence lowering (non i1) (PR #124298)

2025-01-30 Thread Sameer Sahasrabuddhe via llvm-branch-commits


@@ -188,6 +190,37 @@ void 
DivergenceLoweringHelper::constrainAsLaneMask(Incoming &In) {
   In.Reg = Copy.getReg(0);
 }
 
+void replaceUsesOfRegInInstWith(Register Reg, MachineInstr *Inst,
+Register NewReg) {
+  for (MachineOperand &Op : Inst->operands()) {
+if (Op.isReg() && Op.getReg() == Reg)
+  Op.setReg(NewReg);
+  }
+}
+
+bool DivergenceLoweringHelper::lowerTempDivergence() {
+  AMDGPU::IntrinsicLaneMaskAnalyzer ILMA(*MF);
+
+  for (auto [Inst, UseInst, _] : MUI->getUsesOutsideCycleWithDivergentExit()) {
+Register Reg = Inst->getOperand(0).getReg();
+if (MRI->getType(Reg) == LLT::scalar(1) || MUI->isDivergent(Reg) ||
+ILMA.isS32S64LaneMask(Reg))
+  continue;
+
+MachineInstr *MI = const_cast(Inst);

ssahasra wrote:

I lean on the other side. If you look at LoopInfoBase or LoopBase, their 
functions take const pointers as arguments but return non-const pointers when 
asked. Sure, an analysis should treat its inputs as const, but when it returns 
something to the client, that client owns it anyway, so forcing that to be 
const is just an inconvenience. I would rather have the analysis do the 
const_cast before returning a list of pointers to something I already own.

This seems to be the first time that uniformity analysis is returning 
something. Until now, the public interface has simply been a bunch of 
predicates like "isUniform" that take a const pointer as arguments.

https://github.com/llvm/llvm-project/pull/124298
___
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] [AVR] Backport #118015 and #121498 (PR #125081)

2025-01-30 Thread Patryk Wychowaniec via llvm-branch-commits

https://github.com/Patryk27 milestoned 
https://github.com/llvm/llvm-project/pull/125081
___
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] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport 2b7509e9885c9a5656bb3c201421e146a21fb88e

Requested by: @MacDue

---
Full diff: https://github.com/llvm/llvm-project/pull/125049.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaARM.cpp (+6-3) 
- (renamed) clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp (+67-1) 


``diff
diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 9fbe8358f716b3..71dfe68f104ed9 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -636,7 +636,8 @@ static ArmSMEState getSMEState(unsigned BuiltinID) {
 
 bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -676,7 +677,8 @@ bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned 
BuiltinID,
 
 bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -705,7 +707,8 @@ bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID,
 bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 
 switch (BuiltinID) {
 default:
diff --git a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
similarity index 71%
rename from clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
rename to clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
index 27fa8f7c9dccb2..3fbcaf4a13d67c 100644
--- a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
+++ b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1  -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: %clang_cc1  -std=c++23 -triple aarch64-none-linux-gnu -target-feature 
+sve \
 // RUN:   -target-feature +bf16 -target-feature +sve -target-feature +sme 
-target-feature +sme2 -target-feature +sve2 -target-feature +neon 
-Waarch64-sme-attributes -fsyntax-only -verify %s
 
 // REQUIRES: aarch64-registered-target
@@ -126,3 +126,69 @@ void missing_zt0(void) __arm_streaming {
 
 __arm_new("zt0")
 void new_zt0(void) __arm_streaming { svzero_zt(0); }
+
+/// C++ lambda tests:
+
+void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const 
void *ptr) __arm_streaming __arm_out("za")
+{
+  [&]{
+/// The lambda is its own function and does not inherit the SME attributes 
(so this should error).
+// expected-error@+1 {{builtin can only be called from a streaming 
function}}
+svld1_hor_za64(0, slice_base, pg, ptr);
+  }();
+}
+
+void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) 
__arm_streaming __arm_out("za")
+{
+  /// Without the lambda the same builtin is okay (as the SME attributes 
apply).
+  svld1_hor_za64(0, slice_base, pg, ptr);
+}
+
+int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+}
+
+int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) 
__arm_streaming_compatible {
+  return [&]{
+/// This should not error (as we switch out of streaming mode to execute 
the lambda).
+/// Note: The result int16x8_t is spilled and reloaded as a q-register.
+return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+  }();
+}
+
+float use_incomp_sve_builtin_sm() __arm_streaming {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return svadda(svptrue_b32(), 0, svdup_f32(1));
+}
+
+float incomp_sve_sm_fadda_sm_in_lambda(void) __arm_streaming {
+  return [&]{
+/// This should work like the Neon builtin.
+return svadda(svptrue_b32(), 0, svdup_f32(1));
+  }();
+}
+
+void use_streaming_builtin_in_streaming_lambda(uint32_t slice_base, const void 
*ptr)
+{
+  [&]  __arm_new("za") () __arm_streaming {
+// Here the lambda is streaming with ZA state, so this is okay.
+svld1_hor_za64(0, slice_base, svptrue_b64(), ptr);
+  }();
+}
+
+int16x8_t use_neon_builtin_in_streaming_lambda(int16x8_t splat) {
+  return [&]() __arm_streaming_c

[llvm-branch-commits] [clang] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: None (llvmbot)


Changes

Backport 2b7509e9885c9a5656bb3c201421e146a21fb88e

Requested by: @MacDue

---
Full diff: https://github.com/llvm/llvm-project/pull/125049.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaARM.cpp (+6-3) 
- (renamed) clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp (+67-1) 


``diff
diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 9fbe8358f716b3..71dfe68f104ed9 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -636,7 +636,8 @@ static ArmSMEState getSMEState(unsigned BuiltinID) {
 
 bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -676,7 +677,8 @@ bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned 
BuiltinID,
 
 bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -705,7 +707,8 @@ bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID,
 bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 
 switch (BuiltinID) {
 default:
diff --git a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
similarity index 71%
rename from clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
rename to clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
index 27fa8f7c9dccb2..3fbcaf4a13d67c 100644
--- a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
+++ b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1  -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: %clang_cc1  -std=c++23 -triple aarch64-none-linux-gnu -target-feature 
+sve \
 // RUN:   -target-feature +bf16 -target-feature +sve -target-feature +sme 
-target-feature +sme2 -target-feature +sve2 -target-feature +neon 
-Waarch64-sme-attributes -fsyntax-only -verify %s
 
 // REQUIRES: aarch64-registered-target
@@ -126,3 +126,69 @@ void missing_zt0(void) __arm_streaming {
 
 __arm_new("zt0")
 void new_zt0(void) __arm_streaming { svzero_zt(0); }
+
+/// C++ lambda tests:
+
+void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const 
void *ptr) __arm_streaming __arm_out("za")
+{
+  [&]{
+/// The lambda is its own function and does not inherit the SME attributes 
(so this should error).
+// expected-error@+1 {{builtin can only be called from a streaming 
function}}
+svld1_hor_za64(0, slice_base, pg, ptr);
+  }();
+}
+
+void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) 
__arm_streaming __arm_out("za")
+{
+  /// Without the lambda the same builtin is okay (as the SME attributes 
apply).
+  svld1_hor_za64(0, slice_base, pg, ptr);
+}
+
+int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+}
+
+int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) 
__arm_streaming_compatible {
+  return [&]{
+/// This should not error (as we switch out of streaming mode to execute 
the lambda).
+/// Note: The result int16x8_t is spilled and reloaded as a q-register.
+return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+  }();
+}
+
+float use_incomp_sve_builtin_sm() __arm_streaming {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return svadda(svptrue_b32(), 0, svdup_f32(1));
+}
+
+float incomp_sve_sm_fadda_sm_in_lambda(void) __arm_streaming {
+  return [&]{
+/// This should work like the Neon builtin.
+return svadda(svptrue_b32(), 0, svdup_f32(1));
+  }();
+}
+
+void use_streaming_builtin_in_streaming_lambda(uint32_t slice_base, const void 
*ptr)
+{
+  [&]  __arm_new("za") () __arm_streaming {
+// Here the lambda is streaming with ZA state, so this is okay.
+svld1_hor_za64(0, slice_base, svptrue_b64(), ptr);
+  }();
+}
+
+int16x8_t use_neon_builtin_in_streaming_lambda(int16x8_t splat) {
+  return [&]() __arm_strea

[llvm-branch-commits] [clang] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (llvmbot)


Changes

Backport 2b7509e9885c9a5656bb3c201421e146a21fb88e

Requested by: @MacDue

---
Full diff: https://github.com/llvm/llvm-project/pull/125049.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaARM.cpp (+6-3) 
- (renamed) clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp (+67-1) 


``diff
diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 9fbe8358f716b3..71dfe68f104ed9 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -636,7 +636,8 @@ static ArmSMEState getSMEState(unsigned BuiltinID) {
 
 bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -676,7 +677,8 @@ bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned 
BuiltinID,
 
 bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -705,7 +707,8 @@ bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID,
 bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 
 switch (BuiltinID) {
 default:
diff --git a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
similarity index 71%
rename from clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
rename to clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
index 27fa8f7c9dccb2..3fbcaf4a13d67c 100644
--- a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
+++ b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1  -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: %clang_cc1  -std=c++23 -triple aarch64-none-linux-gnu -target-feature 
+sve \
 // RUN:   -target-feature +bf16 -target-feature +sve -target-feature +sme 
-target-feature +sme2 -target-feature +sve2 -target-feature +neon 
-Waarch64-sme-attributes -fsyntax-only -verify %s
 
 // REQUIRES: aarch64-registered-target
@@ -126,3 +126,69 @@ void missing_zt0(void) __arm_streaming {
 
 __arm_new("zt0")
 void new_zt0(void) __arm_streaming { svzero_zt(0); }
+
+/// C++ lambda tests:
+
+void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const 
void *ptr) __arm_streaming __arm_out("za")
+{
+  [&]{
+/// The lambda is its own function and does not inherit the SME attributes 
(so this should error).
+// expected-error@+1 {{builtin can only be called from a streaming 
function}}
+svld1_hor_za64(0, slice_base, pg, ptr);
+  }();
+}
+
+void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) 
__arm_streaming __arm_out("za")
+{
+  /// Without the lambda the same builtin is okay (as the SME attributes 
apply).
+  svld1_hor_za64(0, slice_base, pg, ptr);
+}
+
+int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+}
+
+int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) 
__arm_streaming_compatible {
+  return [&]{
+/// This should not error (as we switch out of streaming mode to execute 
the lambda).
+/// Note: The result int16x8_t is spilled and reloaded as a q-register.
+return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+  }();
+}
+
+float use_incomp_sve_builtin_sm() __arm_streaming {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return svadda(svptrue_b32(), 0, svdup_f32(1));
+}
+
+float incomp_sve_sm_fadda_sm_in_lambda(void) __arm_streaming {
+  return [&]{
+/// This should work like the Neon builtin.
+return svadda(svptrue_b32(), 0, svdup_f32(1));
+  }();
+}
+
+void use_streaming_builtin_in_streaming_lambda(uint32_t slice_base, const void 
*ptr)
+{
+  [&]  __arm_new("za") () __arm_streaming {
+// Here the lambda is streaming with ZA state, so this is okay.
+svld1_hor_za64(0, slice_base, svptrue_b64(), ptr);
+  }();
+}
+
+int16x8_t use_neon_builtin_in_streaming_lambda(int16x8_t splat) {
+  return [&]() __arm_s

[llvm-branch-commits] [flang] [MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause (PR #121001)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits

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

LGTM!

https://github.com/llvm/llvm-project/pull/121001
___
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] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/125049

>From 20f18dc9d9555b751434d82ce260e3fe981fa92d Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Thu, 30 Jan 2025 08:55:34 +
Subject: [PATCH] [clang][SME] Account for C++ lambdas in SME builtin
 diagnostics (#124750)

A C++ lambda does not inherit attributes from the parent function. So
the SME builtin diagnostics should look at the lambda's attributes, not
the parent function's.

The fix is very simple and just adds the missing "AllowLambda" flag to
the function decl lookups.

(cherry picked from commit 2b7509e9885c9a5656bb3c201421e146a21fb88e)
---
 clang/lib/Sema/SemaARM.cpp|  9 ++-
 ... => aarch64-incompat-sm-builtin-calls.cpp} | 68 ++-
 2 files changed, 73 insertions(+), 4 deletions(-)
 rename clang/test/Sema/{aarch64-incompat-sm-builtin-calls.c => 
aarch64-incompat-sm-builtin-calls.cpp} (71%)

diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 9fbe8358f716b3..71dfe68f104ed9 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -636,7 +636,8 @@ static ArmSMEState getSMEState(unsigned BuiltinID) {
 
 bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -676,7 +677,8 @@ bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned 
BuiltinID,
 
 bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -705,7 +707,8 @@ bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID,
 bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 
 switch (BuiltinID) {
 default:
diff --git a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
similarity index 71%
rename from clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
rename to clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
index 27fa8f7c9dccb2..3fbcaf4a13d67c 100644
--- a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
+++ b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1  -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: %clang_cc1  -std=c++23 -triple aarch64-none-linux-gnu -target-feature 
+sve \
 // RUN:   -target-feature +bf16 -target-feature +sve -target-feature +sme 
-target-feature +sme2 -target-feature +sve2 -target-feature +neon 
-Waarch64-sme-attributes -fsyntax-only -verify %s
 
 // REQUIRES: aarch64-registered-target
@@ -126,3 +126,69 @@ void missing_zt0(void) __arm_streaming {
 
 __arm_new("zt0")
 void new_zt0(void) __arm_streaming { svzero_zt(0); }
+
+/// C++ lambda tests:
+
+void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const 
void *ptr) __arm_streaming __arm_out("za")
+{
+  [&]{
+/// The lambda is its own function and does not inherit the SME attributes 
(so this should error).
+// expected-error@+1 {{builtin can only be called from a streaming 
function}}
+svld1_hor_za64(0, slice_base, pg, ptr);
+  }();
+}
+
+void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) 
__arm_streaming __arm_out("za")
+{
+  /// Without the lambda the same builtin is okay (as the SME attributes 
apply).
+  svld1_hor_za64(0, slice_base, pg, ptr);
+}
+
+int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+}
+
+int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) 
__arm_streaming_compatible {
+  return [&]{
+/// This should not error (as we switch out of streaming mode to execute 
the lambda).
+/// Note: The result int16x8_t is spilled and reloaded as a q-register.
+return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+  }();
+}
+
+float use_incomp_sve_builtin_sm() __arm_streaming {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return svadda(svptrue_b32(), 0, svdup_f32(1));
+}
+
+float inc

[llvm-branch-commits] [llvm] AMDGPU/GlobalISel: Temporal divergence lowering (non i1) (PR #124298)

2025-01-30 Thread Nicolai Hähnle via llvm-branch-commits


@@ -188,6 +190,37 @@ void 
DivergenceLoweringHelper::constrainAsLaneMask(Incoming &In) {
   In.Reg = Copy.getReg(0);
 }
 
+void replaceUsesOfRegInInstWith(Register Reg, MachineInstr *Inst,
+Register NewReg) {
+  for (MachineOperand &Op : Inst->operands()) {
+if (Op.isReg() && Op.getReg() == Reg)
+  Op.setReg(NewReg);
+  }
+}
+
+bool DivergenceLoweringHelper::lowerTempDivergence() {
+  AMDGPU::IntrinsicLaneMaskAnalyzer ILMA(*MF);
+
+  for (auto [Inst, UseInst, _] : MUI->getUsesOutsideCycleWithDivergentExit()) {
+Register Reg = Inst->getOperand(0).getReg();
+if (MRI->getType(Reg) == LLT::scalar(1) || MUI->isDivergent(Reg) ||
+ILMA.isS32S64LaneMask(Reg))
+  continue;
+
+MachineInstr *MI = const_cast(Inst);

nhaehnle wrote:

These come out of the analysis. The analysis itself uses const 
pointers/references in its implementation, which I believe is a good idea for 
const correctness. I wouldn't change that.

So a `const_cast` is needed at some point. The only question is where.

I think here is as good a place as any, though perhaps grouping them together 
with a small explanation is in order. Something like:
```c++
// As an analysis, UniformityAnalysis treats instructions as const. We have 
the parent function
// as non-const, so casting const away here is inelegant but justified.
MachineInstr *MI = const_cast(Inst);
MachineInstr *UseMI = const_cast(UseInst);
```

https://github.com/llvm/llvm-project/pull/124298
___
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] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/125049

Backport 2b7509e9885c9a5656bb3c201421e146a21fb88e

Requested by: @MacDue

>From c1431751fb6912ee568177fdfabeb6ca85b43e87 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Thu, 30 Jan 2025 08:55:34 +
Subject: [PATCH] [clang][SME] Account for C++ lambdas in SME builtin
 diagnostics (#124750)

A C++ lambda does not inherit attributes from the parent function. So
the SME builtin diagnostics should look at the lambda's attributes, not
the parent function's.

The fix is very simple and just adds the missing "AllowLambda" flag to
the function decl lookups.

(cherry picked from commit 2b7509e9885c9a5656bb3c201421e146a21fb88e)
---
 clang/lib/Sema/SemaARM.cpp|  9 ++-
 ... => aarch64-incompat-sm-builtin-calls.cpp} | 68 ++-
 2 files changed, 73 insertions(+), 4 deletions(-)
 rename clang/test/Sema/{aarch64-incompat-sm-builtin-calls.c => 
aarch64-incompat-sm-builtin-calls.cpp} (71%)

diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 9fbe8358f716b3..71dfe68f104ed9 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -636,7 +636,8 @@ static ArmSMEState getSMEState(unsigned BuiltinID) {
 
 bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -676,7 +677,8 @@ bool SemaARM::CheckSMEBuiltinFunctionCall(unsigned 
BuiltinID,
 
 bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned BuiltinID,
   CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 std::optional BuiltinType;
 
 switch (BuiltinID) {
@@ -705,7 +707,8 @@ bool SemaARM::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID,
 bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
-  if (const FunctionDecl *FD = SemaRef.getCurFunctionDecl()) {
+  if (const FunctionDecl *FD =
+  SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
 
 switch (BuiltinID) {
 default:
diff --git a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
similarity index 71%
rename from clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
rename to clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
index 27fa8f7c9dccb2..3fbcaf4a13d67c 100644
--- a/clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
+++ b/clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1  -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: %clang_cc1  -std=c++23 -triple aarch64-none-linux-gnu -target-feature 
+sve \
 // RUN:   -target-feature +bf16 -target-feature +sve -target-feature +sme 
-target-feature +sme2 -target-feature +sve2 -target-feature +neon 
-Waarch64-sme-attributes -fsyntax-only -verify %s
 
 // REQUIRES: aarch64-registered-target
@@ -126,3 +126,69 @@ void missing_zt0(void) __arm_streaming {
 
 __arm_new("zt0")
 void new_zt0(void) __arm_streaming { svzero_zt(0); }
+
+/// C++ lambda tests:
+
+void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const 
void *ptr) __arm_streaming __arm_out("za")
+{
+  [&]{
+/// The lambda is its own function and does not inherit the SME attributes 
(so this should error).
+// expected-error@+1 {{builtin can only be called from a streaming 
function}}
+svld1_hor_za64(0, slice_base, pg, ptr);
+  }();
+}
+
+void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) 
__arm_streaming __arm_out("za")
+{
+  /// Without the lambda the same builtin is okay (as the SME attributes 
apply).
+  svld1_hor_za64(0, slice_base, pg, ptr);
+}
+
+int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
function}}
+  return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+}
+
+int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) 
__arm_streaming_compatible {
+  return [&]{
+/// This should not error (as we switch out of streaming mode to execute 
the lambda).
+/// Note: The result int16x8_t is spilled and reloaded as a q-register.
+return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, 
(int8x16_t)splat, 33);
+  }();
+}
+
+float use_incomp_sve_builtin_sm() __arm_streaming {
+  // expected-error@+1 {{builtin can only be called from a non-streaming 
fu

[llvm-branch-commits] [clang] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/125049
___
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] release/20.x: [clang][SME] Account for C++ lambdas in SME builtin diagnostics (#124750) (PR #125049)

2025-01-30 Thread via llvm-branch-commits

llvmbot wrote:

@efriedma-quic What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/125049
___
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] [CodeGen][NewPM] Port RegisterCoalescer to NPM (PR #124698)

2025-01-30 Thread Matt Arsenault via llvm-branch-commits


@@ -0,0 +1,28 @@
+//===- llvm/CodeGen/RegisterCoalescerPass.h -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CODEGEN_REGISTER_COALESCERPASS_H
+#define LLVM_CODEGEN_REGISTER_COALESCERPASS_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+class RegisterCoalescerPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+
+  MachineFunctionProperties getClearedProperties() const {
+return MachineFunctionProperties().set(
+MachineFunctionProperties::Property::IsSSA);
+  }

arsenm wrote:

I thought this didn't work in new PM? 

https://github.com/llvm/llvm-project/pull/124698
___
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] PeepholeOpt: Remove check for reg_sequence def of subregister (PR #124512)

2025-01-30 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

### Merge activity

* **Jan 30, 8:37 AM EST**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/124512).


https://github.com/llvm/llvm-project/pull/124512
___
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] PeepholeOpt: Avoid double map lookup (PR #124531)

2025-01-30 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

### Merge activity

* **Jan 30, 8:37 AM EST**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/124531).


https://github.com/llvm/llvm-project/pull/124531
___
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] PeepholeOpt: Simplify tracking of current op for copy and reg_sequence (PR #124224)

2025-01-30 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

### Merge activity

* **Jan 30, 8:37 AM EST**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/124224).


https://github.com/llvm/llvm-project/pull/124224
___
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] release/20.x: [CodeGenPrepare] Replace deleted ext instr with the promoted value. (#71058) (PR #125040)

2025-01-30 Thread Nikita Popov via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/125040
___
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] [CodeGen][NewPM] Port RegisterCoalescer to NPM (PR #124698)

2025-01-30 Thread Akshat Oke via llvm-branch-commits


@@ -0,0 +1,28 @@
+//===- llvm/CodeGen/RegisterCoalescerPass.h -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CODEGEN_REGISTER_COALESCERPASS_H
+#define LLVM_CODEGEN_REGISTER_COALESCERPASS_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+class RegisterCoalescerPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+
+  MachineFunctionProperties getClearedProperties() const {
+return MachineFunctionProperties().set(
+MachineFunctionProperties::Property::IsSSA);
+  }

optimisan wrote:

It does work; `MFPropsModifier` handles these methods as a RAII class (which I 
have missed to use in run(), I'll update that in a while)

https://github.com/llvm/llvm-project/pull/124698
___
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] AMDGPU: Mark sendmsg intrinsics as norecurse (PR #125016)

2025-01-30 Thread Jay Foad via llvm-branch-commits

jayfoad wrote:

> We cannot mark these as nocallback or nosync.

I think we can and should mark these as `nocallback`. I don't know how well it 
is documented, but I think in practice `nocallback` means that the intrinsic 
does not call back into user code **synchronously, in the current thread, 
before the intrinsic returns**.

https://github.com/llvm/llvm-project/pull/125016
___
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] [flang] [mlir] [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (PR #121005)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits

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

LGTM!

https://github.com/llvm/llvm-project/pull/121005
___
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] [flang] [mlir] [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (PR #121005)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits

https://github.com/ergawy edited 
https://github.com/llvm/llvm-project/pull/121005
___
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] [flang] [mlir] [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (PR #121005)

2025-01-30 Thread Kareem Ergawy via llvm-branch-commits


@@ -186,6 +186,32 @@ struct MapInfoOpConversion : public 
ConvertOpToLLVMPattern {
   }
 };
 
+struct DeclMapperOpConversion

ergawy wrote:

You are right. No need to overcomplicate this. This is fine.

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


  1   2   >