[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/128991 >From e982a61657da5eb4c7f2618c95f0c6d3493cb854 Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 26 Feb 2025 19:14:20 -0800 Subject: [PATCH 1/2] [HLSL] Implement explicit layout for default constant buffer Fixes #123801 --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 38 ++-- clang/lib/CodeGen/CGHLSLRuntime.h | 2 +- clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp | 87 +++ clang/lib/CodeGen/HLSLBufferLayoutBuilder.h | 7 +- clang/lib/CodeGen/TargetInfo.h| 2 +- clang/lib/CodeGen/Targets/DirectX.cpp | 4 +- clang/lib/CodeGen/Targets/SPIR.cpp| 4 +- clang/lib/Sema/SemaHLSL.cpp | 12 +++ .../CodeGenHLSL/cbuffer_with_packoffset.hlsl | 17 +++- .../default_cbuffer_with_layout.hlsl | 37 10 files changed, 175 insertions(+), 35 deletions(-) create mode 100644 clang/test/CodeGenHLSL/default_cbuffer_with_layout.hlsl diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index ed6d2036cb984..6f476d7df4578 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -70,7 +70,7 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { llvm::Type * CGHLSLRuntime::convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets) { + SmallVector *Packoffsets) { assert(T->isHLSLSpecificType() && "Not an HLSL specific type!"); // Check if the target has a specific translation for this type first. @@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; + } +} + } +} Layout.push_back(Offset); } } @@ -212,7 +236,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) { return; // create global variable for the constant buffer - SmallVector Layout; + SmallVector Layout; if (BufDecl->hasValidPackoffset()) fillPackoffsetLayout(BufDecl, Layout); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index a9da42324a038..c4550056175c1 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -146,7 +146,7 @@ class CGHLSLRuntime { llvm::Type * convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets = nullptr); + SmallVector *Packoffsets = nullptr); void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV); void generateGlobalCtorDtorCalls(); diff --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp index 97262b76c0164..bf9bca48a4dd6 100644 --- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp +++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "CGHLSLRuntime.h" #include "CodeGenModule.
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/128991 ___ 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] 08e60fa - Revert "[flang][cuda] Handle floats in atomiccas (#128970)"
Author: Valentin Clement (バレンタイン クレメン) Date: 2025-02-26T20:13:14-08:00 New Revision: 08e60faf08e0121861a30302088cfe095bc144b7 URL: https://github.com/llvm/llvm-project/commit/08e60faf08e0121861a30302088cfe095bc144b7 DIFF: https://github.com/llvm/llvm-project/commit/08e60faf08e0121861a30302088cfe095bc144b7.diff LOG: Revert "[flang][cuda] Handle floats in atomiccas (#128970)" This reverts commit 110b77f32859f39d253623153a37671f5601de65. Added: Modified: flang/lib/Optimizer/Builder/IntrinsicCall.cpp flang/test/Lower/CUDA/cuda-device-proc.cuf Removed: diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 9a10ce949290a..537c817e32ad8 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -2734,20 +2734,6 @@ mlir::Value IntrinsicLibrary::genAtomicCas(mlir::Type resultType, mlir::Value arg1 = args[1]; mlir::Value arg2 = args[2]; - - auto bitCastFloat = [&](mlir::Value arg) -> mlir::Value { -if (mlir::isa(arg.getType())) - return builder.create(loc, builder.getI32Type(), - arg); -if (mlir::isa(arg.getType())) - return builder.create(loc, builder.getI64Type(), - arg); -return arg; - }; - - arg1 = bitCastFloat(arg1); - arg2 = bitCastFloat(arg2); - if (arg1.getType() != arg2.getType()) { // arg1 and arg2 need to have the same type in AtomicCmpXchgOp. arg2 = builder.createConvert(loc, arg1.getType(), arg2); diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf index c651d34c55093..f2b4eb57ad555 100644 --- a/flang/test/Lower/CUDA/cuda-device-proc.cuf +++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf @@ -175,26 +175,3 @@ end subroutine ! CHECK: %[[VAL:.*]] = fir.convert %c14{{.*}} : (i32) -> i64 ! CHECK: %[[ADDR:.*]] = builtin.unrealized_conversion_cast %{{.*}}#1 : !fir.ref to !llvm.ptr ! CHECK: llvm.cmpxchg %{{.*}}, %{{.*}}, %[[VAL]] acq_rel monotonic : !llvm.ptr, i64 - -attributes(device) subroutine testAtomic3() - real :: a, i, istat - istat = atomiccas(a, i, 14.0) -end subroutine - -! CHECK-LABEL: func.func @_QPtestatomic3() -! CHECK: %[[BCAST1:.*]] = llvm.bitcast %{{.*}} : f32 to i32 -! CHECK: %[[BCAST2:.*]] = llvm.bitcast %{{.*}} : f32 to i32 -! CHECK: %[[CAST:.*]] = builtin.unrealized_conversion_cast %{{.*}}#1 : !fir.ref to !llvm.ptr -! CHECK: llvm.cmpxchg %[[CAST]], %[[BCAST1]], %[[BCAST2]] acq_rel monotonic : !llvm.ptr, i32 - -attributes(device) subroutine testAtomic4() - real(8) :: a, i, istat - istat = atomiccas(a, i, 14.0d0) -end subroutine - -! CHECK-LABEL: func.func @_QPtestatomic4() -! CHECK: %[[BCAST1:.*]] = llvm.bitcast %{{.*}} : f64 to i64 -! CHECK: %[[BCAST2:.*]] = llvm.bitcast %{{.*}} : f64 to i64 -! CHECK: %[[CAST:.*]] = builtin.unrealized_conversion_cast %{{.*}}#1 : !fir.ref to !llvm.ptr -! CHECK: %[[ATOMIC:.*]] = llvm.cmpxchg %[[CAST]], %[[BCAST1]], %[[BCAST2]] acq_rel monotonic : !llvm.ptr, i64 -! CHECK: %[[RES:.*]] = llvm.extractvalue %[[ATOMIC]][1] : !llvm.struct<(i64, i1)> ___ 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] [clang-format] Fix a bug that changes keyword `or` to an identifier (PR #128996)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Backports ffc61dc393e4 0968df9c3a55 2d585ccecc45 Fixes #105482 --- Full diff: https://github.com/llvm/llvm-project/pull/128996.diff 11 Files Affected: - (modified) clang/docs/ClangFormatStyleOptions.rst (+11-2) - (modified) clang/docs/ReleaseNotes.rst (+4) - (modified) clang/include/clang/Format/Format.h (+14-3) - (modified) clang/lib/Format/Format.cpp (+42-1) - (modified) clang/lib/Format/FormatToken.cpp (+5-5) - (modified) clang/lib/Format/FormatToken.h (-23) - (modified) clang/lib/Format/TokenAnnotator.cpp (+2-2) - (modified) clang/lib/Format/TokenAnnotator.h (+1-1) - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+1-7) - (modified) clang/unittests/Format/FormatTest.cpp (+17-2) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+9-2) ``diff diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index bbb912eb10e94..4b4c412a13323 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -4735,15 +4735,24 @@ the configuration (without a prefix: ``Auto``). .. _Language: **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ ` - Language, this format style is targeted at. + The language that this format style targets. + + .. note:: + + You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + files by adding a ``// clang-format Language:`` line before the first + non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. Possible values: * ``LK_None`` (in configuration: ``None``) Do not use. + * ``LK_C`` (in configuration: ``C``) +Should be used for C. + * ``LK_Cpp`` (in configuration: ``Cpp``) -Should be used for C, C++. +Should be used for C++. * ``LK_CSharp`` (in configuration: ``CSharp``) Should be used for C#. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 153afdb3d59e3..57a567509a068 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1358,6 +1358,10 @@ clang-format - Adds ``WrapNamespaceBodyWithEmptyLines`` option. - Adds the ``IndentExportBlock`` option. - Adds ``PenaltyBreakBeforeMemberAccess`` option. +- Add the C language instead of treating it like C++. +- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by + adding a special comment (e.g. ``// clang-format Language: ObjC``) near the + top of the file. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6f432d1d50315..abab543518222 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -3275,7 +3275,9 @@ struct FormatStyle { enum LanguageKind : int8_t { /// Do not use. LK_None, -/// Should be used for C, C++. +/// Should be used for C. +LK_C, +/// Should be used for C++. LK_Cpp, /// Should be used for C#. LK_CSharp, @@ -3300,7 +3302,9 @@ struct FormatStyle { /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595 LK_Verilog }; - bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } + bool isCpp() const { +return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC; + } bool isCSharp() const { return Language == LK_CSharp; } bool isJson() const { return Language == LK_Json; } bool isJavaScript() const { return Language == LK_JavaScript; } @@ -3310,7 +3314,12 @@ struct FormatStyle { } bool isTableGen() const { return Language == LK_TableGen; } - /// Language, this format style is targeted at. + /// The language that this format style targets. + /// \note + /// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + /// files by adding a ``// clang-format Language:`` line before the first + /// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. + /// \endnote /// \version 3.5 LanguageKind Language; @@ -5665,6 +5674,8 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code); // Returns a string representation of ``Language``. inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { switch (Language) { + case FormatStyle::LK_C: +return "C"; case FormatStyle::LK_Cpp: return "C++"; case FormatStyle::LK_CSharp: diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f02bf95cfeed7..0bb8545884442 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -401,6 +401,7 @@ template <> struct MappingTraits { template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) { +IO.enumCase(Value, "C", FormatStyle::LK_C); IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp); IO.enumCase(Value, "Java", FormatStyle::LK_Java)
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota ready_for_review https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Helena Kotas (hekota) Changes Fixes #126791 --- Full diff: https://github.com/llvm/llvm-project/pull/128991.diff 10 Files Affected: - (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+31-7) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1-1) - (modified) clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp (+71-16) - (modified) clang/lib/CodeGen/HLSLBufferLayoutBuilder.h (+3-4) - (modified) clang/lib/CodeGen/TargetInfo.h (+1-1) - (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+4-4) - (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+4-4) - (modified) clang/lib/Sema/SemaHLSL.cpp (+12) - (modified) clang/test/CodeGenHLSL/cbuffer_with_packoffset.hlsl (+15-2) - (added) clang/test/CodeGenHLSL/default_cbuffer_with_layout.hlsl (+37) ``diff diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index ed6d2036cb984..67256aa2be339 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -70,7 +70,7 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { llvm::Type * CGHLSLRuntime::convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets) { + SmallVector *Packoffsets) { assert(T->isHLSLSpecificType() && "Not an HLSL specific type!"); // Check if the target has a specific translation for this type first. @@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; + } +} + } +} Layout.push_back(Offset); } } @@ -212,7 +236,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) { return; // create global variable for the constant buffer - SmallVector Layout; + SmallVector Layout; if (BufDecl->hasValidPackoffset()) fillPackoffsetLayout(BufDecl, Layout); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index a9da42324a038..c4550056175c1 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -146,7 +146,7 @@ class CGHLSLRuntime { llvm::Type * convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets = nullptr); + SmallVector *Packoffsets = nullptr); void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV); void generateGlobalCtorDtorCalls(); diff --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp index 97262b76c0164..7a92233ac9055 100644 --- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp +++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "CGHLSLRuntime.h" #include "CodeGenModule.h" #include "clang/AST/Type.h" +#include //===--===// // Implementation of constant buffer layout common between DirectX and @@ -58,9 +59
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
llvmbot wrote: @llvm/pr-subscribers-backend-directx Author: Helena Kotas (hekota) Changes Fixes #126791 --- Full diff: https://github.com/llvm/llvm-project/pull/128991.diff 10 Files Affected: - (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+31-7) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1-1) - (modified) clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp (+71-16) - (modified) clang/lib/CodeGen/HLSLBufferLayoutBuilder.h (+3-4) - (modified) clang/lib/CodeGen/TargetInfo.h (+1-1) - (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+4-4) - (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+4-4) - (modified) clang/lib/Sema/SemaHLSL.cpp (+12) - (modified) clang/test/CodeGenHLSL/cbuffer_with_packoffset.hlsl (+15-2) - (added) clang/test/CodeGenHLSL/default_cbuffer_with_layout.hlsl (+37) ``diff diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index ed6d2036cb984..67256aa2be339 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -70,7 +70,7 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { llvm::Type * CGHLSLRuntime::convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets) { + SmallVector *Packoffsets) { assert(T->isHLSLSpecificType() && "Not an HLSL specific type!"); // Check if the target has a specific translation for this type first. @@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; + } +} + } +} Layout.push_back(Offset); } } @@ -212,7 +236,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) { return; // create global variable for the constant buffer - SmallVector Layout; + SmallVector Layout; if (BufDecl->hasValidPackoffset()) fillPackoffsetLayout(BufDecl, Layout); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index a9da42324a038..c4550056175c1 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -146,7 +146,7 @@ class CGHLSLRuntime { llvm::Type * convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets = nullptr); + SmallVector *Packoffsets = nullptr); void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV); void generateGlobalCtorDtorCalls(); diff --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp index 97262b76c0164..7a92233ac9055 100644 --- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp +++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "CGHLSLRuntime.h" #include "CodeGenModule.h" #include "clang/AST/Type.h" +#include //===--===// // Implementation of constant buffer layout common between DirectX and @@
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
https://github.com/damyanp commented: LGTM. A typo and a nag about a naked constant value. https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
@@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. damyanp wrote: ```suggestion // It is not guaranteed that all declarations in a buffer have an annotation. ``` https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
@@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; damyanp wrote: I think there's a `CBufferAlign` in SemaHLSL.cpp. A `BufferRowAlign` in HLSLBufferLayoutBuilder.cpp. Maybe these are the same concept? (If so, maybe reconciling them is outside scope of this PR) https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)
@@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; damyanp wrote: It'd be nice if there was a named constant for this. At very least you wouldn't need the comment. At best, we have an easy way to find all the places that depend on the constant buffer row size. https://github.com/llvm/llvm-project/pull/128991 ___ 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] [clang-format] Fix a bug that changes keyword `or` to an identifier (PR #128996)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/128996 Backports ffc61dc393e4 0968df9c3a55 2d585ccecc45 Fixes #105482 >From 678c9eda153fcaebbf1b1bf34c9253c40f3564fc Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 21 Feb 2025 20:46:43 -0800 Subject: [PATCH] [clang-format] Fix a bug that changes keyword `or` to an identifier (#128410) Backports ffc61dc393e4 0968df9c3a55 2d585ccecc45 Fixes #105482 --- clang/docs/ClangFormatStyleOptions.rst| 13 +- clang/docs/ReleaseNotes.rst | 4 ++ clang/include/clang/Format/Format.h | 17 ++-- clang/lib/Format/Format.cpp | 43 ++- clang/lib/Format/FormatToken.cpp | 10 ++--- clang/lib/Format/FormatToken.h| 23 -- clang/lib/Format/TokenAnnotator.cpp | 4 +- clang/lib/Format/TokenAnnotator.h | 2 +- clang/lib/Format/UnwrappedLineParser.cpp | 8 +--- clang/unittests/Format/FormatTest.cpp | 19 +++- clang/unittests/Format/TokenAnnotatorTest.cpp | 11 - 11 files changed, 106 insertions(+), 48 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index bbb912eb10e94..4b4c412a13323 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -4735,15 +4735,24 @@ the configuration (without a prefix: ``Auto``). .. _Language: **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ ` - Language, this format style is targeted at. + The language that this format style targets. + + .. note:: + + You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + files by adding a ``// clang-format Language:`` line before the first + non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. Possible values: * ``LK_None`` (in configuration: ``None``) Do not use. + * ``LK_C`` (in configuration: ``C``) +Should be used for C. + * ``LK_Cpp`` (in configuration: ``Cpp``) -Should be used for C, C++. +Should be used for C++. * ``LK_CSharp`` (in configuration: ``CSharp``) Should be used for C#. diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 153afdb3d59e3..57a567509a068 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1358,6 +1358,10 @@ clang-format - Adds ``WrapNamespaceBodyWithEmptyLines`` option. - Adds the ``IndentExportBlock`` option. - Adds ``PenaltyBreakBeforeMemberAccess`` option. +- Add the C language instead of treating it like C++. +- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by + adding a special comment (e.g. ``// clang-format Language: ObjC``) near the + top of the file. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6f432d1d50315..abab543518222 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -3275,7 +3275,9 @@ struct FormatStyle { enum LanguageKind : int8_t { /// Do not use. LK_None, -/// Should be used for C, C++. +/// Should be used for C. +LK_C, +/// Should be used for C++. LK_Cpp, /// Should be used for C#. LK_CSharp, @@ -3300,7 +3302,9 @@ struct FormatStyle { /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595 LK_Verilog }; - bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; } + bool isCpp() const { +return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC; + } bool isCSharp() const { return Language == LK_CSharp; } bool isJson() const { return Language == LK_Json; } bool isJavaScript() const { return Language == LK_JavaScript; } @@ -3310,7 +3314,12 @@ struct FormatStyle { } bool isTableGen() const { return Language == LK_TableGen; } - /// Language, this format style is targeted at. + /// The language that this format style targets. + /// \note + /// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h`` + /// files by adding a ``// clang-format Language:`` line before the first + /// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``. + /// \endnote /// \version 3.5 LanguageKind Language; @@ -5665,6 +5674,8 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code); // Returns a string representation of ``Language``. inline StringRef getLanguageName(FormatStyle::LanguageKind Language) { switch (Language) { + case FormatStyle::LK_C: +return "C"; case FormatStyle::LK_Cpp: return "C++"; case FormatStyle::LK_CSharp: diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f02bf95cfeed7..0bb8545884442 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -401,6 +401,7 @@ template <> struct MappingTraits { template <> struct ScalarEnumerati
[llvm-branch-commits] [llvm] release/20.x: [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) (PR #128879)
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/128879 Backport https://github.com/llvm/llvm-project/commit/8009c1fd81ad0b6ac65724d2b134a92db48f8fbf >From 508d5e45a57affceeb87e69a99ebb65efde88478 Mon Sep 17 00:00:00 2001 From: Elvis Wang Date: Tue, 25 Feb 2025 11:09:09 +0800 Subject: [PATCH 1/2] [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) Skip calculating instruction costs for exit conditions in precomputeCosts() when it should be skipped. Reported from: https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463 Godbolt for reduced test cases: https://godbolt.org/z/fr4YMeqcv (cherry picked from commit 8009c1fd81ad0b6ac65724d2b134a92db48f8fbf) --- .../Transforms/Vectorize/LoopVectorize.cpp| 5 +- .../LoopVectorize/X86/cost-model.ll | 124 ++ 2 files changed, 127 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0ceeec48487f6..7cd395255163a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7239,7 +7239,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, // Collect all exit conditions. for (BasicBlock *EB : Exiting) { auto *Term = dyn_cast(EB->getTerminator()); -if (!Term) +if (!Term || CostCtx.skipCostComputation(Term, VF.isVector())) continue; if (auto *CondI = dyn_cast(Term->getOperand(0))) { ExitInstrs.insert(CondI); @@ -7259,7 +7259,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, Cost += CondICost; for (Value *Op : CondI->operands()) { auto *OpI = dyn_cast(Op); - if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) { + if (!OpI || CostCtx.skipCostComputation(OpI, VF.isVector()) || + any_of(OpI->users(), [&ExitInstrs, this](User *U) { return OrigLoop->contains(cast(U)->getParent()) && !ExitInstrs.contains(cast(U)); })) diff --git a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll index bd28e28ddff95..1b2aaa373f2c8 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll @@ -1211,6 +1211,130 @@ exit: ret i32 %or } +; Check if the vplan-based cost model select same VF to the legacy cost model. +; Reduced from: https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463 +define i32 @g(i64 %n) { +; CHECK-LABEL: @g( +; CHECK-NEXT: iter.check: +; CHECK-NEXT:[[TMP0:%.*]] = trunc i64 [[N:%.*]] to i32 +; CHECK-NEXT:[[TMP1:%.*]] = add i32 [[TMP0]], 1 +; CHECK-NEXT:[[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP1]], 4 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]] +; CHECK: vector.scevcheck: +; CHECK-NEXT:[[TMP2:%.*]] = icmp ugt i64 [[N]], 4294967295 +; CHECK-NEXT:br i1 [[TMP2]], label [[VEC_EPILOG_SCALAR_PH]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]] +; CHECK: vector.main.loop.iter.check: +; CHECK-NEXT:[[MIN_ITERS_CHECK1:%.*]] = icmp ult i32 [[TMP1]], 16 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]] +; CHECK: vector.ph: +; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i32 [[TMP1]], 16 +; CHECK-NEXT:[[N_VEC:%.*]] = sub i32 [[TMP1]], [[N_MOD_VF]] +; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[N]], i64 0 +; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer +; CHECK-NEXT:br label [[VECTOR_BODY:%.*]] +; CHECK: vector.body: +; CHECK-NEXT:[[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_IND:%.*]] = phi <4 x i32> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP16:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP17:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI4:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP18:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_2:%.*]] = add <4 x i32> [[STEP_ADD]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_3:%.*]] = add <4 x i32> [[STEP_ADD_2]], splat (i32 4) +; CHECK-NEXT:[[TMP3:%.*]] = zext <4 x i32> [[VEC_IND]] to <4 x i64> +; CHECK-NEXT:[[TMP4:%.*]] = zext <4 x i32> [[STEP_ADD]] to <4 x i64> +; C
[llvm-branch-commits] [llvm] release/20.x: workflows/release-binaries-all: Add missing secret input (#126921) (PR #128884)
https://github.com/boomanaiden154 approved this pull request. https://github.com/llvm/llvm-project/pull/128884 ___ 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)
@@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | FileCheck %s + +// CHECK-DAG: ![[#EMPTY:]] = !{} +[shader("compute"), RootSignature("")] +[numthreads(1,1,1)] +void FirstEntry() {} + +// CHECK-DAG: ![[#CBV:]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4} bob80905 wrote: Are these guaranteed to be differently ordered in each execution? Are these stored in a map? Any way to get these checks to not use DAG? https://github.com/llvm/llvm-project/pull/125131 ___ 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-all: Add missing secret input (#126921) (PR #128884)
llvmbot wrote: @boomanaiden154 What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/128884 ___ 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-all: Add missing secret input (#126921) (PR #128884)
llvmbot wrote: @llvm/pr-subscribers-github-workflow Author: None (llvmbot) Changes Backport a684e0ea57ebb93c81506c066afb25cb496dcc11 Requested by: @tstellar --- Full diff: https://github.com/llvm/llvm-project/pull/128884.diff 1 Files Affected: - (modified) .github/workflows/release-binaries-all.yml (+4) ``diff diff --git a/.github/workflows/release-binaries-all.yml b/.github/workflows/release-binaries-all.yml index d18b9b0b5c2ff..fd4694ebea32d 100644 --- a/.github/workflows/release-binaries-all.yml +++ b/.github/workflows/release-binaries-all.yml @@ -27,6 +27,10 @@ on: required: true default: false type: boolean +secrets: + RELEASE_TASKS_USER_TOKEN: +description: "Secret used to check user permissions." +required: false pull_request: types: `` https://github.com/llvm/llvm-project/pull/128884 ___ 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: [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) (PR #128694)
fhahn wrote: I created https://github.com/llvm/llvm-project/pull/128879 with a test update https://github.com/llvm/llvm-project/pull/128694 ___ 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: [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) (PR #128879)
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/128879 >From 508d5e45a57affceeb87e69a99ebb65efde88478 Mon Sep 17 00:00:00 2001 From: Elvis Wang Date: Tue, 25 Feb 2025 11:09:09 +0800 Subject: [PATCH 1/2] [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) Skip calculating instruction costs for exit conditions in precomputeCosts() when it should be skipped. Reported from: https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463 Godbolt for reduced test cases: https://godbolt.org/z/fr4YMeqcv (cherry picked from commit 8009c1fd81ad0b6ac65724d2b134a92db48f8fbf) --- .../Transforms/Vectorize/LoopVectorize.cpp| 5 +- .../LoopVectorize/X86/cost-model.ll | 124 ++ 2 files changed, 127 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0ceeec48487f6..7cd395255163a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7239,7 +7239,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, // Collect all exit conditions. for (BasicBlock *EB : Exiting) { auto *Term = dyn_cast(EB->getTerminator()); -if (!Term) +if (!Term || CostCtx.skipCostComputation(Term, VF.isVector())) continue; if (auto *CondI = dyn_cast(Term->getOperand(0))) { ExitInstrs.insert(CondI); @@ -7259,7 +7259,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, Cost += CondICost; for (Value *Op : CondI->operands()) { auto *OpI = dyn_cast(Op); - if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) { + if (!OpI || CostCtx.skipCostComputation(OpI, VF.isVector()) || + any_of(OpI->users(), [&ExitInstrs, this](User *U) { return OrigLoop->contains(cast(U)->getParent()) && !ExitInstrs.contains(cast(U)); })) diff --git a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll index bd28e28ddff95..1b2aaa373f2c8 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll @@ -1211,6 +1211,130 @@ exit: ret i32 %or } +; Check if the vplan-based cost model select same VF to the legacy cost model. +; Reduced from: https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463 +define i32 @g(i64 %n) { +; CHECK-LABEL: @g( +; CHECK-NEXT: iter.check: +; CHECK-NEXT:[[TMP0:%.*]] = trunc i64 [[N:%.*]] to i32 +; CHECK-NEXT:[[TMP1:%.*]] = add i32 [[TMP0]], 1 +; CHECK-NEXT:[[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP1]], 4 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]] +; CHECK: vector.scevcheck: +; CHECK-NEXT:[[TMP2:%.*]] = icmp ugt i64 [[N]], 4294967295 +; CHECK-NEXT:br i1 [[TMP2]], label [[VEC_EPILOG_SCALAR_PH]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]] +; CHECK: vector.main.loop.iter.check: +; CHECK-NEXT:[[MIN_ITERS_CHECK1:%.*]] = icmp ult i32 [[TMP1]], 16 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]] +; CHECK: vector.ph: +; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i32 [[TMP1]], 16 +; CHECK-NEXT:[[N_VEC:%.*]] = sub i32 [[TMP1]], [[N_MOD_VF]] +; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[N]], i64 0 +; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer +; CHECK-NEXT:br label [[VECTOR_BODY:%.*]] +; CHECK: vector.body: +; CHECK-NEXT:[[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_IND:%.*]] = phi <4 x i32> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP16:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP17:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI4:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP18:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_2:%.*]] = add <4 x i32> [[STEP_ADD]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_3:%.*]] = add <4 x i32> [[STEP_ADD_2]], splat (i32 4) +; CHECK-NEXT:[[TMP3:%.*]] = zext <4 x i32> [[VEC_IND]] to <4 x i64> +; CHECK-NEXT:[[TMP4:%.*]] = zext <4 x i32> [[STEP_ADD]] to <4 x i64> +; CHECK-NEXT:[[TMP5:%.*]] = zext <4 x i32> [[STEP_ADD_2]] to <4 x i64> +; CHECK-NEXT:[[TMP6:
[llvm-branch-commits] [llvm] release/20.x: [LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966) (PR #128879)
llvmbot wrote: @llvm/pr-subscribers-vectorizers Author: Florian Hahn (fhahn) Changes Backport https://github.com/llvm/llvm-project/commit/8009c1fd81ad0b6ac65724d2b134a92db48f8fbf --- Full diff: https://github.com/llvm/llvm-project/pull/128879.diff 2 Files Affected: - (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-2) - (modified) llvm/test/Transforms/LoopVectorize/X86/cost-model.ll (+124) ``diff diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0ceeec48487f6..7cd395255163a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7239,7 +7239,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, // Collect all exit conditions. for (BasicBlock *EB : Exiting) { auto *Term = dyn_cast(EB->getTerminator()); -if (!Term) +if (!Term || CostCtx.skipCostComputation(Term, VF.isVector())) continue; if (auto *CondI = dyn_cast(Term->getOperand(0))) { ExitInstrs.insert(CondI); @@ -7259,7 +7259,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, Cost += CondICost; for (Value *Op : CondI->operands()) { auto *OpI = dyn_cast(Op); - if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) { + if (!OpI || CostCtx.skipCostComputation(OpI, VF.isVector()) || + any_of(OpI->users(), [&ExitInstrs, this](User *U) { return OrigLoop->contains(cast(U)->getParent()) && !ExitInstrs.contains(cast(U)); })) diff --git a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll index bd28e28ddff95..3718a092d9aa0 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/cost-model.ll @@ -1211,6 +1211,130 @@ exit: ret i32 %or } +; Check if the vplan-based cost model select same VF to the legacy cost model. +; Reduced from: https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463 +define i32 @g(i64 %n) { +; CHECK-LABEL: @g( +; CHECK-NEXT: iter.check: +; CHECK-NEXT:[[TMP0:%.*]] = trunc i64 [[N:%.*]] to i32 +; CHECK-NEXT:[[TMP1:%.*]] = add i32 [[TMP0]], 1 +; CHECK-NEXT:[[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP1]], 4 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK]], label [[VEC_EPILOG_SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]] +; CHECK: vector.scevcheck: +; CHECK-NEXT:[[TMP2:%.*]] = icmp ugt i64 [[N]], 4294967295 +; CHECK-NEXT:br i1 [[TMP2]], label [[VEC_EPILOG_SCALAR_PH]], label [[VECTOR_MAIN_LOOP_ITER_CHECK:%.*]] +; CHECK: vector.main.loop.iter.check: +; CHECK-NEXT:[[MIN_ITERS_CHECK1:%.*]] = icmp ult i32 [[TMP1]], 16 +; CHECK-NEXT:br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH:%.*]] +; CHECK: vector.ph: +; CHECK-NEXT:[[N_MOD_VF:%.*]] = urem i32 [[TMP1]], 16 +; CHECK-NEXT:[[N_VEC:%.*]] = sub i32 [[TMP1]], [[N_MOD_VF]] +; CHECK-NEXT:[[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[N]], i64 0 +; CHECK-NEXT:[[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer +; CHECK-NEXT:br label [[VECTOR_BODY:%.*]] +; CHECK: vector.body: +; CHECK-NEXT:[[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_IND:%.*]] = phi <4 x i32> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP16:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP17:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[VEC_PHI4:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP18:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT:[[STEP_ADD:%.*]] = add <4 x i32> [[VEC_IND]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_2:%.*]] = add <4 x i32> [[STEP_ADD]], splat (i32 4) +; CHECK-NEXT:[[STEP_ADD_3:%.*]] = add <4 x i32> [[STEP_ADD_2]], splat (i32 4) +; CHECK-NEXT:[[TMP3:%.*]] = zext <4 x i32> [[VEC_IND]] to <4 x i64> +; CHECK-NEXT:[[TMP4:%.*]] = zext <4 x i32> [[STEP_ADD]] to <4 x i64> +; CHECK-NEXT:[[TMP5:%.*]] = zext <4 x i32> [[STEP_ADD_2]] to <4 x i64> +; CHECK-NEXT:[[TMP6:%.*]] = zext <4 x i32> [[STEP_ADD_3]] to <4 x i64> +; CHECK-NEXT:[[TMP7:%.*]] = icmp eq <4 x i64> [[BROADCAST_SPLAT]], [[TMP3]] +; CHECK-NEXT:[[TMP8:%.*]] = icmp eq <4 x i64> [[BROADCAST_SPLAT]], [[TMP4]] +; CHECK-NEXT:[[TMP9:%.*]] = icmp eq <4 x i64> [[BROADCAST_SPLAT]], [[TMP5]] +; CHECK-NEXT:[[TMP10:%.*]] = icmp eq <4 x i64> [[BROADCAST_SPLAT]], [[TMP6]] +; CHECK-NEXT:[[TM
[llvm-branch-commits] [llvm] release/20.x: workflows/release-binaries-all: Add missing secret input (#126921) (PR #128884)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/128884 Backport a684e0ea57ebb93c81506c066afb25cb496dcc11 Requested by: @tstellar >From 83058aadeef4a2995c2610abe3119ed86371cd3e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Wed, 12 Feb 2025 10:01:46 -0800 Subject: [PATCH] workflows/release-binaries-all: Add missing secret input (#126921) Since d194c6b9a7fdda7a61abcd6bfe39ab465bf0cc87 this workflow was missing the secret input which was causing it to fail. (cherry picked from commit a684e0ea57ebb93c81506c066afb25cb496dcc11) --- .github/workflows/release-binaries-all.yml | 4 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release-binaries-all.yml b/.github/workflows/release-binaries-all.yml index d18b9b0b5c2ff..fd4694ebea32d 100644 --- a/.github/workflows/release-binaries-all.yml +++ b/.github/workflows/release-binaries-all.yml @@ -27,6 +27,10 @@ on: required: true default: false type: boolean +secrets: + RELEASE_TASKS_USER_TOKEN: +description: "Secret used to check user permissions." +required: false pull_request: types: ___ 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-all: Add missing secret input (#126921) (PR #128884)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/128884 ___ 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] [mlir] 7ea3a19 - Revert "[MLIR][LLVMIR] Import unregistered intrinsics via llvm.intrinsic_call…"
Author: Bruno Cardoso Lopes Date: 2025-02-26T16:00:26-08:00 New Revision: 7ea3a19cf1cc8944f5fe00dd0dfaf01b2a651846 URL: https://github.com/llvm/llvm-project/commit/7ea3a19cf1cc8944f5fe00dd0dfaf01b2a651846 DIFF: https://github.com/llvm/llvm-project/commit/7ea3a19cf1cc8944f5fe00dd0dfaf01b2a651846.diff LOG: Revert "[MLIR][LLVMIR] Import unregistered intrinsics via llvm.intrinsic_call…" This reverts commit d584d1f188553b6cb417beb903f58d763c265380. Added: Modified: mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp mlir/test/Target/LLVMIR/Import/import-failure.ll Removed: mlir/test/Target/LLVMIR/Import/intrinsic-unregistered.ll diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h index 686969f891f20..cc5a77ed35d2b 100644 --- a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h +++ b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h @@ -155,18 +155,9 @@ class LLVMImportInterface LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport) const { // Lookup the dialect interface for the given intrinsic. -// Verify the intrinsic identifier maps to an actual intrinsic. -llvm::Intrinsic::ID intrinId = inst->getIntrinsicID(); -assert(intrinId != llvm::Intrinsic::not_intrinsic); - -// First lookup the intrinsic across diff erent dialects for known -// supported conversions, examples include arm-neon, nvm-sve, etc. -Dialect *dialect = intrinsicToDialect.lookup(intrinId); - -// No specialized (supported) intrinsics, attempt to generate a generic -// version via llvm.call_intrinsic (if available). +Dialect *dialect = intrinsicToDialect.lookup(inst->getIntrinsicID()); if (!dialect) - return convertUnregisteredIntrinsic(builder, inst, moduleImport); + return failure(); // Dispatch the conversion to the dialect interface. const LLVMImportDialectInterface *iface = getInterfaceFor(dialect); @@ -233,11 +224,6 @@ class LLVMImportInterface } private: - /// Generate llvm.call_intrinsic when no supporting dialect available. - static LogicalResult - convertUnregisteredIntrinsic(OpBuilder &builder, llvm::CallInst *inst, - LLVM::ModuleImport &moduleImport); - DenseMap intrinsicToDialect; DenseMap instructionToDialect; DenseMap> metadataToDialect; diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp index 227779f355069..4fd043c7c93e6 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp @@ -367,45 +367,6 @@ static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder, return success(); } -LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic( -OpBuilder &builder, llvm::CallInst *inst, -LLVM::ModuleImport &moduleImport) { - StringRef intrinName = inst->getCalledFunction()->getName(); - - SmallVector args(inst->args()); - ArrayRef llvmOperands(args); - - SmallVector llvmOpBundles; - llvmOpBundles.reserve(inst->getNumOperandBundles()); - for (unsigned i = 0; i < inst->getNumOperandBundles(); ++i) -llvmOpBundles.push_back(inst->getOperandBundleAt(i)); - - SmallVector mlirOperands; - SmallVector mlirAttrs; - if (failed(moduleImport.convertIntrinsicArguments( - llvmOperands, llvmOpBundles, false, {}, {}, mlirOperands, mlirAttrs))) -return failure(); - - Type results = moduleImport.convertType(inst->getType()); - auto op = builder.create<::mlir::LLVM::CallIntrinsicOp>( - moduleImport.translateLoc(inst->getDebugLoc()), results, - StringAttr::get(builder.getContext(), intrinName), - ValueRange{mlirOperands}, FastmathFlagsAttr{}); - - moduleImport.setFastmathFlagsAttr(inst, op); - - // Update importer tracking of results. - unsigned numRes = op.getNumResults(); - if (numRes == 1) -moduleImport.mapValue(inst) = op.getResult(0); - else if (numRes == 0) -moduleImport.mapNoResultOp(inst); - else -return op.emitError( -"expected at most one result from target intrinsic call"); - - return success(); -} namespace { /// Implementation of the dialect interface that converts operations belonging diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll index fc4ccddb756d5..d929a59284762 100644 --- a/mlir/test/Target/LLVMIR/Import/import-failure.ll +++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll @@ -38,6 +38,18 @@ bb1: ; // - +declare void @llvm.gcroot(ptr %arg1, ptr %arg2) + +; CHECK: +; CHECK-SAME: error: unhandled int
[llvm-branch-commits] [llvm] AMDGPU: Fix overly conservative immediate operand check (PR #127563)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/127563 >From f3accf64d3fa2c8a7bc64f7d9b7bd6c02793f005 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 17 Feb 2025 22:31:48 +0700 Subject: [PATCH] AMDGPU: Fix overly conservative immediate operand check The real legality check is peformed later anyway, so this was unnecessarily blocking immediate folds in handled cases. This also stops folding s_fmac_f32 to s_fmamk_f32 in a few tests, but that seems better. The globalisel changes look suspicious, it may be mishandling constants for VOP3P instructions. --- llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 3 +- llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll | 16 ++--- .../CodeGen/AMDGPU/GlobalISel/flat-scratch.ll | 60 +-- llvm/test/CodeGen/AMDGPU/GlobalISel/orn2.ll | 16 ++--- llvm/test/CodeGen/AMDGPU/GlobalISel/xnor.ll | 4 +- llvm/test/CodeGen/AMDGPU/bug-cselect-b64.ll | 6 +- llvm/test/CodeGen/AMDGPU/constrained-shift.ll | 6 +- llvm/test/CodeGen/AMDGPU/flat-scratch.ll | 31 +++--- llvm/test/CodeGen/AMDGPU/fmul-to-ldexp.ll | 57 ++ .../AMDGPU/fold-operands-frame-index.mir | 3 +- .../AMDGPU/fold-operands-scalar-fmac.mir | 13 ++-- .../CodeGen/AMDGPU/fold-sgpr-multi-imm.mir| 8 +-- llvm/test/CodeGen/AMDGPU/global-saddr-load.ll | 5 +- .../local-stack-alloc-block-sp-reference.ll | 25 +++- llvm/test/CodeGen/AMDGPU/packed-fp32.ll | 10 ++-- llvm/test/CodeGen/AMDGPU/scalar-float-sop2.ll | 4 +- 16 files changed, 85 insertions(+), 182 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index 36288d43443ca..3a019dbaad02c 100644 --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -821,7 +821,8 @@ bool SIFoldOperandsImpl::tryToFoldACImm( if (UseOpIdx >= Desc.getNumOperands()) return false; - if (!AMDGPU::isSISrcInlinableOperand(Desc, UseOpIdx)) + // Filter out unhandled pseudos. + if (!AMDGPU::isSISrcOperand(Desc, UseOpIdx)) return false; uint8_t OpTy = Desc.operands()[UseOpIdx].OperandType; diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll index 4be00fedb972e..89078f20f1d47 100644 --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll @@ -920,9 +920,7 @@ define amdgpu_ps i64 @s_andn2_v4i16(<4 x i16> inreg %src0, <4 x i16> inreg %src1 ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[2:3] ; GFX6-NEXT:; return to shader part epilog ; @@ -962,9 +960,7 @@ define amdgpu_ps i64 @s_andn2_v4i16_commute(<4 x i16> inreg %src0, <4 x i16> inr ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[2:3], s[0:1] ; GFX6-NEXT:; return to shader part epilog ; @@ -1004,9 +1000,7 @@ define amdgpu_ps { i64, i64 } @s_andn2_v4i16_multi_use(<4 x i16> inreg %src0, <4 ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[2:3] ; GFX6-NEXT:; return to shader part epilog ; @@ -1060,9 +1054,7 @@ define amdgpu_ps { i64, i64 } @s_andn2_v4i16_multi_foldable_use(<4 x i16> inreg ; GFX6-NEXT:s_lshl_b32 s5, s13, 16 ; GFX6-NEXT:s_and_b32 s6, s12, 0x ; GFX6-NEXT:s_or_b32 s5, s5, s6 -; GFX6-NEXT:s_mov_b32 s6, -1 -; GFX6-NEXT:s_mov_b32 s7, s6 -; GFX6-NEXT:s_xor_b64 s[4:5], s[4:5], s[6:7] +; GFX6-NEXT:s_xor_b64 s[4:5], s[4:5], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[4:5] ; GFX6-NEXT:s_and_b64 s[2:3], s[2:3], s[4:5] ; GFX6-NEXT:; return to shader part epilog diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll index 38346dd568694..a02e0b37479a0 100644 --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll @@ -1769,9 +1769,8 @@ define amdgpu_kernel void @store_load_large_imm_offset_kernel() { ; GFX9-NEXT:s_mov_b32 s0, 0 ; GFX9-NEXT:scratch_store_dword off, v0, s0 offset:4 ; GFX9-NEXT:s_waitcnt vmcnt(0) -; GFX9-NEXT:s_movk_i32 s0, 0x3e80 ; GFX9-NEXT:v_mov_b32_e32 v0, 15 -; GFX9-NEX
[llvm-branch-commits] [llvm] AMDGPU: Fix overly conservative immediate operand check (PR #127563)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/127563 >From f3accf64d3fa2c8a7bc64f7d9b7bd6c02793f005 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 17 Feb 2025 22:31:48 +0700 Subject: [PATCH] AMDGPU: Fix overly conservative immediate operand check The real legality check is peformed later anyway, so this was unnecessarily blocking immediate folds in handled cases. This also stops folding s_fmac_f32 to s_fmamk_f32 in a few tests, but that seems better. The globalisel changes look suspicious, it may be mishandling constants for VOP3P instructions. --- llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 3 +- llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll | 16 ++--- .../CodeGen/AMDGPU/GlobalISel/flat-scratch.ll | 60 +-- llvm/test/CodeGen/AMDGPU/GlobalISel/orn2.ll | 16 ++--- llvm/test/CodeGen/AMDGPU/GlobalISel/xnor.ll | 4 +- llvm/test/CodeGen/AMDGPU/bug-cselect-b64.ll | 6 +- llvm/test/CodeGen/AMDGPU/constrained-shift.ll | 6 +- llvm/test/CodeGen/AMDGPU/flat-scratch.ll | 31 +++--- llvm/test/CodeGen/AMDGPU/fmul-to-ldexp.ll | 57 ++ .../AMDGPU/fold-operands-frame-index.mir | 3 +- .../AMDGPU/fold-operands-scalar-fmac.mir | 13 ++-- .../CodeGen/AMDGPU/fold-sgpr-multi-imm.mir| 8 +-- llvm/test/CodeGen/AMDGPU/global-saddr-load.ll | 5 +- .../local-stack-alloc-block-sp-reference.ll | 25 +++- llvm/test/CodeGen/AMDGPU/packed-fp32.ll | 10 ++-- llvm/test/CodeGen/AMDGPU/scalar-float-sop2.ll | 4 +- 16 files changed, 85 insertions(+), 182 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index 36288d43443ca..3a019dbaad02c 100644 --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -821,7 +821,8 @@ bool SIFoldOperandsImpl::tryToFoldACImm( if (UseOpIdx >= Desc.getNumOperands()) return false; - if (!AMDGPU::isSISrcInlinableOperand(Desc, UseOpIdx)) + // Filter out unhandled pseudos. + if (!AMDGPU::isSISrcOperand(Desc, UseOpIdx)) return false; uint8_t OpTy = Desc.operands()[UseOpIdx].OperandType; diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll index 4be00fedb972e..89078f20f1d47 100644 --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/andn2.ll @@ -920,9 +920,7 @@ define amdgpu_ps i64 @s_andn2_v4i16(<4 x i16> inreg %src0, <4 x i16> inreg %src1 ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[2:3] ; GFX6-NEXT:; return to shader part epilog ; @@ -962,9 +960,7 @@ define amdgpu_ps i64 @s_andn2_v4i16_commute(<4 x i16> inreg %src0, <4 x i16> inr ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[2:3], s[0:1] ; GFX6-NEXT:; return to shader part epilog ; @@ -1004,9 +1000,7 @@ define amdgpu_ps { i64, i64 } @s_andn2_v4i16_multi_use(<4 x i16> inreg %src0, <4 ; GFX6-NEXT:s_lshl_b32 s3, s9, 16 ; GFX6-NEXT:s_and_b32 s4, s8, 0x ; GFX6-NEXT:s_or_b32 s3, s3, s4 -; GFX6-NEXT:s_mov_b32 s4, -1 -; GFX6-NEXT:s_mov_b32 s5, s4 -; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], s[4:5] +; GFX6-NEXT:s_xor_b64 s[2:3], s[2:3], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[2:3] ; GFX6-NEXT:; return to shader part epilog ; @@ -1060,9 +1054,7 @@ define amdgpu_ps { i64, i64 } @s_andn2_v4i16_multi_foldable_use(<4 x i16> inreg ; GFX6-NEXT:s_lshl_b32 s5, s13, 16 ; GFX6-NEXT:s_and_b32 s6, s12, 0x ; GFX6-NEXT:s_or_b32 s5, s5, s6 -; GFX6-NEXT:s_mov_b32 s6, -1 -; GFX6-NEXT:s_mov_b32 s7, s6 -; GFX6-NEXT:s_xor_b64 s[4:5], s[4:5], s[6:7] +; GFX6-NEXT:s_xor_b64 s[4:5], s[4:5], -1 ; GFX6-NEXT:s_and_b64 s[0:1], s[0:1], s[4:5] ; GFX6-NEXT:s_and_b64 s[2:3], s[2:3], s[4:5] ; GFX6-NEXT:; return to shader part epilog diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll index 38346dd568694..a02e0b37479a0 100644 --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/flat-scratch.ll @@ -1769,9 +1769,8 @@ define amdgpu_kernel void @store_load_large_imm_offset_kernel() { ; GFX9-NEXT:s_mov_b32 s0, 0 ; GFX9-NEXT:scratch_store_dword off, v0, s0 offset:4 ; GFX9-NEXT:s_waitcnt vmcnt(0) -; GFX9-NEXT:s_movk_i32 s0, 0x3e80 ; GFX9-NEXT:v_mov_b32_e32 v0, 15 -; GFX9-NEX
[llvm-branch-commits] [clang] [sanitizer] add pseudofunction to indicate array-bounds check (PR #128977)
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/128977 None ___ 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] [clang] [sanitizer] add pseudofunction to indicate array-bounds check (PR #128977)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/128977 >From 0fe2ba3242026457d8afc46c4a3338efd941c42f Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2025 17:12:43 -0800 Subject: [PATCH] fmt Created using spr 1.3.4 --- clang/lib/CodeGen/CGExpr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dbd24547b2304..dc3b253237e51 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3623,7 +3623,6 @@ void CodeGenFunction::EmitCheck( llvm::Value *RecoverableCond = nullptr; llvm::Value *TrapCond = nullptr; bool NoMerge = false; - // Expand checks into: // (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ... // We need separate allow_ubsan_check intrinsics because they have separately @@ -3933,6 +3932,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, TrapBBs.resize(CheckHandlerID + 1); llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel || (CurCodeDecl && CurCodeDecl->hasAttr()); ___ 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] [clang] [sanitizer] add pseudofunction to indicate array-bounds check (PR #128977)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/128977 >From 0fe2ba3242026457d8afc46c4a3338efd941c42f Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2025 17:12:43 -0800 Subject: [PATCH 1/2] fmt Created using spr 1.3.4 --- clang/lib/CodeGen/CGExpr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dbd24547b2304..dc3b253237e51 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3623,7 +3623,6 @@ void CodeGenFunction::EmitCheck( llvm::Value *RecoverableCond = nullptr; llvm::Value *TrapCond = nullptr; bool NoMerge = false; - // Expand checks into: // (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ... // We need separate allow_ubsan_check intrinsics because they have separately @@ -3933,6 +3932,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, TrapBBs.resize(CheckHandlerID + 1); llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel || (CurCodeDecl && CurCodeDecl->hasAttr()); >From a16b7a8c48353226fe1323a45f59cd4167ddc3d4 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2025 17:15:20 -0800 Subject: [PATCH 2/2] rename & fmt Created using spr 1.3.4 --- clang/lib/CodeGen/CGDebugInfo.cpp | 7 --- clang/lib/CodeGen/CGDebugInfo.h| 8 +--- clang/lib/CodeGen/CGExpr.cpp | 5 ++--- clang/test/CodeGen/bounds-checking-debuginfo.c | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index ae19e8f724314..35fd78b15ff30 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3598,13 +3598,14 @@ llvm::DIMacroFile *CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent, return DBuilder.createTempMacroFile(Parent, Line, FName); } -llvm::DILocation *CGDebugInfo::CreateSyntheticInline( -llvm::DebugLoc TrapLocation, StringRef FuncName) { +llvm::DILocation * +CGDebugInfo::CreateSyntheticInline(llvm::DebugLoc TrapLocation, + StringRef FuncName) { llvm::DISubprogram *TrapSP = createInlinedTrapSubprogram(FuncName, TrapLocation->getFile()); return llvm::DILocation::get(CGM.getLLVMContext(), /*Line=*/0, /*Column=*/0, /*Scope=*/TrapSP, /*InlinedAt=*/TrapLocation); -} +} llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor( llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 0b06bdf78ac78..d01ad3b3d8df5 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -638,9 +638,11 @@ class CGDebugInfo { /// Create a debug location from `TrapLocation` that adds an artificial inline /// frame where the frame name is FuncName /// - /// This is used to indiciate instructions that come from compiler instrumentation. - llvm::DILocation *CreateSyntheticInline( - llvm::DebugLoc TrapLocation, StringRef FuncName); + /// This is used to indiciate instructions that come from compiler + /// instrumentation. + llvm::DILocation *CreateSyntheticInline(llvm::DebugLoc TrapLocation, + StringRef FuncName); + private: /// Emit call to llvm.dbg.declare for a variable declaration. /// Returns a pointer to the DILocalVariable associated with the diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dc3b253237e51..d5cc2cc69c921 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1219,10 +1219,9 @@ void CodeGenFunction::EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::DILocation *TrapSP = Builder.getCurrentDebugLocation(); if (TrapSP) { TrapSP = getDebugInfo()->CreateSyntheticInline( - Builder.getCurrentDebugLocation(), - "check_array_bounds"); +Builder.getCurrentDebugLocation(), "__ubsan_check_array_bounds"); } - ApplyDebugLocation ApplyTrapDI(*this, TrapSP); + ApplyDebugLocation ApplyTrapDI(*this, TrapSP); bool IndexSigned = IndexType->isSignedIntegerOrEnumerationType(); llvm::Value *IndexVal = Builder.CreateIntCast(Index, SizeTy, IndexSigned); diff --git a/clang/test/CodeGen/bounds-checking-debuginfo.c b/clang/test/CodeGen/bounds-checking-debuginfo.c index e2a604bc962ba..58fcc89058d72 100644 --- a/clang/test/CodeGen/bounds-checking-debuginfo.c +++ b/clang/test/CodeGen/bounds-checking-debuginfo.c @@ -89,7 +89,7 @@ double f1(int b, int i) { // CHECK-TRAP: [[DBG22]] = !DILocation(line: 65, column: 3, scope: [[DBG5]]) // CHECK-TRAP: [[DBG23]] = !DILocation(line: 66, column: 12, scope: [[DBG5]]) // CHECK-TRAP: [[DBG24]] = !DILocation(line: 0, scope: [[META
[llvm-branch-commits] [clang] [clang] [sanitizer] add pseudofunction to indicate array-bounds check (PR #128977)
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/128977 >From 0fe2ba3242026457d8afc46c4a3338efd941c42f Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2025 17:12:43 -0800 Subject: [PATCH 1/3] fmt Created using spr 1.3.4 --- clang/lib/CodeGen/CGExpr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dbd24547b2304..dc3b253237e51 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3623,7 +3623,6 @@ void CodeGenFunction::EmitCheck( llvm::Value *RecoverableCond = nullptr; llvm::Value *TrapCond = nullptr; bool NoMerge = false; - // Expand checks into: // (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ... // We need separate allow_ubsan_check intrinsics because they have separately @@ -3933,6 +3932,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, TrapBBs.resize(CheckHandlerID + 1); llvm::BasicBlock *&TrapBB = TrapBBs[CheckHandlerID]; + NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel || (CurCodeDecl && CurCodeDecl->hasAttr()); >From a16b7a8c48353226fe1323a45f59cd4167ddc3d4 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Wed, 26 Feb 2025 17:15:20 -0800 Subject: [PATCH 2/3] rename & fmt Created using spr 1.3.4 --- clang/lib/CodeGen/CGDebugInfo.cpp | 7 --- clang/lib/CodeGen/CGDebugInfo.h| 8 +--- clang/lib/CodeGen/CGExpr.cpp | 5 ++--- clang/test/CodeGen/bounds-checking-debuginfo.c | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index ae19e8f724314..35fd78b15ff30 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3598,13 +3598,14 @@ llvm::DIMacroFile *CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent, return DBuilder.createTempMacroFile(Parent, Line, FName); } -llvm::DILocation *CGDebugInfo::CreateSyntheticInline( -llvm::DebugLoc TrapLocation, StringRef FuncName) { +llvm::DILocation * +CGDebugInfo::CreateSyntheticInline(llvm::DebugLoc TrapLocation, + StringRef FuncName) { llvm::DISubprogram *TrapSP = createInlinedTrapSubprogram(FuncName, TrapLocation->getFile()); return llvm::DILocation::get(CGM.getLLVMContext(), /*Line=*/0, /*Column=*/0, /*Scope=*/TrapSP, /*InlinedAt=*/TrapLocation); -} +} llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor( llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 0b06bdf78ac78..d01ad3b3d8df5 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -638,9 +638,11 @@ class CGDebugInfo { /// Create a debug location from `TrapLocation` that adds an artificial inline /// frame where the frame name is FuncName /// - /// This is used to indiciate instructions that come from compiler instrumentation. - llvm::DILocation *CreateSyntheticInline( - llvm::DebugLoc TrapLocation, StringRef FuncName); + /// This is used to indiciate instructions that come from compiler + /// instrumentation. + llvm::DILocation *CreateSyntheticInline(llvm::DebugLoc TrapLocation, + StringRef FuncName); + private: /// Emit call to llvm.dbg.declare for a variable declaration. /// Returns a pointer to the DILocalVariable associated with the diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dc3b253237e51..d5cc2cc69c921 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1219,10 +1219,9 @@ void CodeGenFunction::EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound, llvm::DILocation *TrapSP = Builder.getCurrentDebugLocation(); if (TrapSP) { TrapSP = getDebugInfo()->CreateSyntheticInline( - Builder.getCurrentDebugLocation(), - "check_array_bounds"); +Builder.getCurrentDebugLocation(), "__ubsan_check_array_bounds"); } - ApplyDebugLocation ApplyTrapDI(*this, TrapSP); + ApplyDebugLocation ApplyTrapDI(*this, TrapSP); bool IndexSigned = IndexType->isSignedIntegerOrEnumerationType(); llvm::Value *IndexVal = Builder.CreateIntCast(Index, SizeTy, IndexSigned); diff --git a/clang/test/CodeGen/bounds-checking-debuginfo.c b/clang/test/CodeGen/bounds-checking-debuginfo.c index e2a604bc962ba..58fcc89058d72 100644 --- a/clang/test/CodeGen/bounds-checking-debuginfo.c +++ b/clang/test/CodeGen/bounds-checking-debuginfo.c @@ -89,7 +89,7 @@ double f1(int b, int i) { // CHECK-TRAP: [[DBG22]] = !DILocation(line: 65, column: 3, scope: [[DBG5]]) // CHECK-TRAP: [[DBG23]] = !DILocation(line: 66, column: 12, scope: [[DBG5]]) // CHECK-TRAP: [[DBG24]] = !DILocation(line: 0, scope: [[META
[llvm-branch-commits] [flang] [mlir] [mlir][OpenMP] Pack task private variables into a heap-allocated context struct (PR #125307)
https://github.com/skatrak edited https://github.com/llvm/llvm-project/pull/125307 ___ 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] Pack task private variables into a heap-allocated context struct (PR #125307)
https://github.com/skatrak approved this pull request. It appears a couple of the changes got somehow lost, but no need for another review from me. LGTM, thanks! https://github.com/llvm/llvm-project/pull/125307 ___ 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] Pack task private variables into a heap-allocated context struct (PR #125307)
https://github.com/tblah updated https://github.com/llvm/llvm-project/pull/125307 >From df47461dcf1f9244da472efdcc57d266ecd42b34 Mon Sep 17 00:00:00 2001 From: Tom Eccles Date: Fri, 24 Jan 2025 17:32:41 + Subject: [PATCH 01/12] [mlir][OpenMP] Pack task private variables into a heap-allocated context struct See RFC: https://discourse.llvm.org/t/rfc-openmp-supporting-delayed-task-execution-with-firstprivate-variables/83084 The aim here is to ensure that tasks which are not executed for a while after they are created do not try to reference any data which are now out of scope. This is done by packing the data referred to by the task into a heap allocated structure (freed at the end of the task). I decided to create the task context structure in OpenMPToLLVMIRTranslation instead of adapting how it is done CodeExtractor (via OpenMPIRBuilder] because CodeExtractor is (at least in theory) generic code which could have other unrelated uses. --- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 209 ++ mlir/test/Target/LLVMIR/openmp-llvm.mlir | 10 +- .../LLVMIR/openmp-task-privatization.mlir | 80 +++ 3 files changed, 258 insertions(+), 41 deletions(-) create mode 100644 mlir/test/Target/LLVMIR/openmp-task-privatization.mlir diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index f3e57e8fcaa2b..9b0f9486529d2 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -13,6 +13,7 @@ #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h" #include "mlir/Analysis/TopologicalSortUtils.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/Dialect/OpenMP/OpenMPInterfaces.h" #include "mlir/IR/IRMapping.h" @@ -24,10 +25,12 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Frontend/OpenMP/OMPConstants.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/ReplaceConstant.h" #include "llvm/Support/FileSystem.h" @@ -1336,15 +1339,16 @@ findAssociatedValue(Value privateVar, llvm::IRBuilderBase &builder, /// Initialize a single (first)private variable. You probably want to use /// allocateAndInitPrivateVars instead of this. -static llvm::Error initPrivateVar( +/// This returns the private variable which has been initialized. This +/// variable should be mapped before constructing the body of the Op. +static llvm::Expected initPrivateVar( llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, omp::PrivateClauseOp &privDecl, Value mlirPrivVar, BlockArgument &blockArg, -llvm::Value **llvmPrivateVarIt, llvm::BasicBlock *privInitBlock, +llvm::Value *llvmPrivateVar, llvm::BasicBlock *privInitBlock, llvm::DenseMap *mappedPrivateVars = nullptr) { Region &initRegion = privDecl.getInitRegion(); if (initRegion.empty()) { -moduleTranslation.mapValue(blockArg, *llvmPrivateVarIt); -return llvm::Error::success(); +return llvmPrivateVar; } // map initialization region block arguments @@ -1352,7 +1356,7 @@ static llvm::Error initPrivateVar( mlirPrivVar, builder, moduleTranslation, mappedPrivateVars); assert(nonPrivateVar); moduleTranslation.mapValue(privDecl.getInitMoldArg(), nonPrivateVar); - moduleTranslation.mapValue(privDecl.getInitPrivateArg(), *llvmPrivateVarIt); + moduleTranslation.mapValue(privDecl.getInitPrivateArg(), llvmPrivateVar); // in-place convert the private initialization region SmallVector phis; @@ -1363,17 +1367,15 @@ static llvm::Error initPrivateVar( assert(phis.size() == 1 && "expected one allocation to be yielded"); - // prefer the value yielded from the init region to the allocated private - // variable in case the region is operating on arguments by-value (e.g. - // Fortran character boxes). - moduleTranslation.mapValue(blockArg, phis[0]); - *llvmPrivateVarIt = phis[0]; - // clear init region block argument mapping in case it needs to be // re-created with a different source for another use of the same // reduction decl moduleTranslation.forgetMapping(initRegion); - return llvm::Error::success(); + + // Prefer the value yielded from the init region to the allocated private + // variable in case the region is operating on arguments by-value (e.g. + // Fortran character boxes). + return phis[0]; } static llvm::Error @@ -1390,16 +1392,19 @@ initPrivateVars(llvm::IRBuilderBase &builder, llvm::BasicBlock *privInitBlock = splitBB(builder, true, "omp.private.init"); setInsertPointForPossiblyEmptyBlock(builde
[llvm-branch-commits] [flang] [mlir] [mlir][OpenMP] Pack task private variables into a heap-allocated context struct (PR #125307)
tblah wrote: Apologies for the comments I missed. I'm not sure how that happened. Thanks for carefully checking each one. https://github.com/llvm/llvm-project/pull/125307 ___ 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] [HLSL] Add support for root constant generation from llvm IR. (PR #127932)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/127932 >From 86a52d82e858c24a0f756f583a1b3d8dac3087d8 Mon Sep 17 00:00:00 2001 From: joaosaffran Date: Wed, 19 Feb 2025 22:53:55 + Subject: [PATCH 01/20] parsing root constant --- llvm/lib/Target/DirectX/DXILRootSignature.cpp | 32 +++ 1 file changed, 32 insertions(+) diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 8702f0eecf2aa..6f7e3418782a3 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -40,6 +40,38 @@ static bool reportError(LLVMContext *Ctx, Twine Message, return true; } +static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, + MDNode *RootConstNode) { + if (RootConstNode->getNumOperands() != 5) +return reportError(Ctx, "Invalid format for RootFlag Element"); + + dxbc::RootParameter NewParam; + NewParam.ParameterType = dxbc::RootParameterType::Constants32Bit; + + auto *ShaderVisibility = + mdconst::extract(RootConstNode->getOperand(1)); + dxbc::ShaderVisibilityFlag SvFlag = + (dxbc::ShaderVisibilityFlag)ShaderVisibility->getZExtValue(); + if (!dxbc::RootSignatureValidations::isValidShaderVisibility(SvFlag)) +return reportError( +Ctx, "Invalid shader visibility flag value in root constant."); + NewParam.ShaderVisibility = SvFlag; + + auto *ShaderRegister = + mdconst::extract(RootConstNode->getOperand(2)); + NewParam.Constants.ShaderRegister = ShaderRegister->getZExtValue(); + + auto *RegisterSpace = + mdconst::extract(RootConstNode->getOperand(3)); + NewParam.Constants.RegisterSpace = RegisterSpace->getZExtValue(); + + auto *Num32BitValues = + mdconst::extract(RootConstNode->getOperand(4)); + NewParam.Constants.Num32BitValues = Num32BitValues->getZExtValue(); + + return false; +} + static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, MDNode *RootFlagNode) { >From f181f4dbae982c948e81aff41bcb84f59048fbed Mon Sep 17 00:00:00 2001 From: joaosaffran Date: Thu, 20 Feb 2025 00:51:23 + Subject: [PATCH 02/20] add root constant support --- llvm/lib/Target/DirectX/DXILRootSignature.cpp | 36 +-- llvm/lib/Target/DirectX/DXILRootSignature.h | 7 +++- ...nature-Constants-Error-invalid-metadata.ll | 17 + ...nstants-Error-invalid-shader-visibility.ll | 17 + .../ContainerData/RootSignature-Constants.ll | 33 + 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Constants-Error-invalid-metadata.ll create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Constants-Error-invalid-shader-visibility.ll create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Constants.ll diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 6f7e3418782a3..388a3f5e8af0b 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -43,7 +43,7 @@ static bool reportError(LLVMContext *Ctx, Twine Message, static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, MDNode *RootConstNode) { if (RootConstNode->getNumOperands() != 5) -return reportError(Ctx, "Invalid format for RootFlag Element"); +return reportError(Ctx, "Invalid format for Root constants element"); dxbc::RootParameter NewParam; NewParam.ParameterType = dxbc::RootParameterType::Constants32Bit; @@ -69,6 +69,8 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, mdconst::extract(RootConstNode->getOperand(4)); NewParam.Constants.Num32BitValues = Num32BitValues->getZExtValue(); + RSD.Parameters.push_back(NewParam); + return false; } @@ -94,10 +96,12 @@ static bool parseRootSignatureElement(LLVMContext *Ctx, RootSignatureElementKind ElementKind = StringSwitch(ElementText->getString()) .Case("RootFlags", RootSignatureElementKind::RootFlags) + .Case("RootConstants", RootSignatureElementKind::RootConstants) .Default(RootSignatureElementKind::Error); switch (ElementKind) { - + case RootSignatureElementKind::RootConstants: +return parseRootConstants(Ctx, RSD, Element); case RootSignatureElementKind::RootFlags: return parseRootFlags(Ctx, RSD, Element); case RootSignatureElementKind::Error: @@ -241,6 +245,34 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M, OS << indent(Space) << "NumStaticSamplers: " << 0 << ":\n"; OS << indent(Space) << "StaticSamplersOffset: " << sizeof(RS.Header) + RS.Parameters.size_in_bytes() << ":\n"; + +OS << indent(Space) << "- Parameters: \n"; +Space++; +
[llvm-branch-commits] [llvm] release/20.x: workflows/release-binaries: Fix macos-14 build (#127157) (PR #128945)
llvmbot wrote: @boomanaiden154 What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/128945 ___ 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: Fix macos-14 build (#127157) (PR #128945)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/128945 Backport d595d5a770d93c9564268fc631d85f3a6ce1f505 Requested by: @tstellar >From 77e6d0893b4b21a962d76f3f805ebb1b4691b0f3 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 14 Feb 2025 07:28:44 -0800 Subject: [PATCH] workflows/release-binaries: Fix macos-14 build (#127157) This was broken when pgo was enabled by 0572580dd040a81dc69b798e202550d51d17204a. (cherry picked from commit d595d5a770d93c9564268fc631d85f3a6ce1f505) --- .github/workflows/release-binaries.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index a18f64d6bc226..231dd26e54ae0 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -133,7 +133,7 @@ jobs: # add extra CMake args to disable them. # See https://github.com/llvm/llvm-project/issues/99767 if [ "$RUNNER_OS" = "macOS" ]; then - target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF" + target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF" if [ "$RUNNER_ARCH" = "ARM64" ]; then arches=arm64 else @@ -144,7 +144,7 @@ jobs: # so we need to disable flang there. target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'" fi - target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches" + target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches" fi build_flang="true" ___ 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: Fix macos-14 build (#127157) (PR #128945)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/128945 ___ 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: Fix macos-14 build (#127157) (PR #128945)
llvmbot wrote: @llvm/pr-subscribers-github-workflow Author: None (llvmbot) Changes Backport d595d5a770d93c9564268fc631d85f3a6ce1f505 Requested by: @tstellar --- Full diff: https://github.com/llvm/llvm-project/pull/128945.diff 1 Files Affected: - (modified) .github/workflows/release-binaries.yml (+2-2) ``diff diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index a18f64d6bc226..231dd26e54ae0 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -133,7 +133,7 @@ jobs: # add extra CMake args to disable them. # See https://github.com/llvm/llvm-project/issues/99767 if [ "$RUNNER_OS" = "macOS" ]; then - target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF" + target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF" if [ "$RUNNER_ARCH" = "ARM64" ]; then arches=arm64 else @@ -144,7 +144,7 @@ jobs: # so we need to disable flang there. target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'" fi - target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches" + target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches" fi build_flang="true" `` https://github.com/llvm/llvm-project/pull/128945 ___ 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] c788a84 - Revert "DAG: Preserve range metadata when load is narrowed (#128144)"
Author: Daniel Thornburgh Date: 2025-02-26T14:00:23-08:00 New Revision: c788a84fdd2316daa0204a13bdf93a503b95cabf URL: https://github.com/llvm/llvm-project/commit/c788a84fdd2316daa0204a13bdf93a503b95cabf DIFF: https://github.com/llvm/llvm-project/commit/c788a84fdd2316daa0204a13bdf93a503b95cabf.diff LOG: Revert "DAG: Preserve range metadata when load is narrowed (#128144)" This reverts commit d8bcb53780bf8e2f622380d5f4ccde96fa1d81a9. Added: Modified: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp llvm/test/CodeGen/AMDGPU/shl64_reduce.ll Removed: diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index de7d9e28bb93a..f197ae61550a9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -14903,29 +14903,12 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) { AddToWorklist(NewPtr.getNode()); SDValue Load; - if (ExtType == ISD::NON_EXTLOAD) { -const MDNode *OldRanges = LN0->getRanges(); -const MDNode *NewRanges = nullptr; -// If LSBs are loaded and the truncated ConstantRange for the OldRanges -// metadata is not the full-set for the NewWidth then create a NewRanges -// metadata for the truncated load -if (ShAmt == 0 && OldRanges) { - ConstantRange CR = getConstantRangeFromMetadata(*OldRanges); - ConstantRange TruncatedCR = CR.truncate(VT.getScalarSizeInBits()); - - if (!TruncatedCR.isFullSet()) { -Metadata *Bounds[2] = {ConstantAsMetadata::get(ConstantInt::get( - *DAG.getContext(), TruncatedCR.getLower())), - ConstantAsMetadata::get(ConstantInt::get( - *DAG.getContext(), TruncatedCR.getUpper()))}; -NewRanges = MDNode::get(*DAG.getContext(), Bounds); - } -} -Load = DAG.getLoad( -VT, DL, LN0->getChain(), NewPtr, -LN0->getPointerInfo().getWithOffset(PtrOff), LN0->getOriginalAlign(), -LN0->getMemOperand()->getFlags(), LN0->getAAInfo(), NewRanges); - } else + if (ExtType == ISD::NON_EXTLOAD) +Load = DAG.getLoad(VT, DL, LN0->getChain(), NewPtr, + LN0->getPointerInfo().getWithOffset(PtrOff), + LN0->getOriginalAlign(), + LN0->getMemOperand()->getFlags(), LN0->getAAInfo()); + else Load = DAG.getExtLoad(ExtType, DL, VT, LN0->getChain(), NewPtr, LN0->getPointerInfo().getWithOffset(PtrOff), ExtVT, LN0->getOriginalAlign(), diff --git a/llvm/test/CodeGen/AMDGPU/shl64_reduce.ll b/llvm/test/CodeGen/AMDGPU/shl64_reduce.ll index 69242f4e44840..05430213c17d2 100644 --- a/llvm/test/CodeGen/AMDGPU/shl64_reduce.ll +++ b/llvm/test/CodeGen/AMDGPU/shl64_reduce.ll @@ -13,66 +13,23 @@ ; Test range with metadata +; FIXME: This case should be reduced, but SelectionDAG::computeKnownBits() cannot +;determine the minimum from metadata in this case. Match current results +;for now. + define i64 @shl_metadata(i64 %arg0, ptr %arg1.ptr) { ; CHECK-LABEL: shl_metadata: ; CHECK: ; %bb.0: ; CHECK-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; CHECK-NEXT:flat_load_dword v1, v[2:3] -; CHECK-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; CHECK-NEXT:v_lshlrev_b32_e32 v1, v1, v0 -; CHECK-NEXT:v_mov_b32_e32 v0, 0 -; CHECK-NEXT:s_setpc_b64 s[30:31] - %shift.amt = load i64, ptr %arg1.ptr, !range !0, !noundef !{} - %shl = shl i64 %arg0, %shift.amt - ret i64 %shl -} - -define i64 @shl_metadata_two_ranges(i64 %arg0, ptr %arg1.ptr) { -; CHECK-LABEL: shl_metadata_two_ranges: -; CHECK: ; %bb.0: -; CHECK-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; CHECK-NEXT:flat_load_dword v1, v[2:3] -; CHECK-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; CHECK-NEXT:v_lshlrev_b32_e32 v1, v1, v0 -; CHECK-NEXT:v_mov_b32_e32 v0, 0 -; CHECK-NEXT:s_setpc_b64 s[30:31] - %shift.amt = load i64, ptr %arg1.ptr, !range !1, !noundef !{} - %shl = shl i64 %arg0, %shift.amt - ret i64 %shl -} - -; Known minimum is too low. Reduction must not be done. -define i64 @shl_metadata_out_of_range(i64 %arg0, ptr %arg1.ptr) { -; CHECK-LABEL: shl_metadata_out_of_range: -; CHECK: ; %bb.0: -; CHECK-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; CHECK-NEXT:flat_load_dword v2, v[2:3] -; CHECK-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; CHECK-NEXT:v_lshlrev_b64 v[0:1], v2, v[0:1] -; CHECK-NEXT:s_setpc_b64 s[30:31] - %shift.amt = load i64, ptr %arg1.ptr, !range !2, !noundef !{} - %shl = shl i64 %arg0, %shift.amt - ret i64 %shl -} - -; Bounds cannot be truncated to i32 when load is narrowed to i32. -; Reduction must not be done. -; Bounds were chosen so that if bounds were truncated
[llvm-branch-commits] [llvm] AMDGPU: Fix overly conservative immediate operand check (PR #127563)
arsenm wrote: ### Merge activity * **Feb 26, 8:34 PM EST**: A user started a stack merge that includes this pull request via [Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/127563). https://github.com/llvm/llvm-project/pull/127563 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer (PR #128991)
https://github.com/hekota created https://github.com/llvm/llvm-project/pull/128991 Fixes #123801 >From e982a61657da5eb4c7f2618c95f0c6d3493cb854 Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 26 Feb 2025 19:14:20 -0800 Subject: [PATCH] [HLSL] Implement explicit layout for default constant buffer Fixes #123801 --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 38 ++-- clang/lib/CodeGen/CGHLSLRuntime.h | 2 +- clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp | 87 +++ clang/lib/CodeGen/HLSLBufferLayoutBuilder.h | 7 +- clang/lib/CodeGen/TargetInfo.h| 2 +- clang/lib/CodeGen/Targets/DirectX.cpp | 4 +- clang/lib/CodeGen/Targets/SPIR.cpp| 4 +- clang/lib/Sema/SemaHLSL.cpp | 12 +++ .../CodeGenHLSL/cbuffer_with_packoffset.hlsl | 17 +++- .../default_cbuffer_with_layout.hlsl | 37 10 files changed, 175 insertions(+), 35 deletions(-) create mode 100644 clang/test/CodeGenHLSL/default_cbuffer_with_layout.hlsl diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index ed6d2036cb984..6f476d7df4578 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -70,7 +70,7 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { llvm::Type * CGHLSLRuntime::convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets) { + SmallVector *Packoffsets) { assert(T->isHLSLSpecificType() && "Not an HLSL specific type!"); // Check if the target has a specific translation for this type first. @@ -179,21 +179,45 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { return cast(QT.getTypePtr()); } +// Iterates over all declarations in the HLSL buffer and based on the +// packoffset or register(c#) annotations it fills outs the Layout +// vector with the user-specified layout offsets. +// The buffer offsets can be specified 2 ways: +// 1. declarations in cbuffer {} block can have a packoffset annotation +//(translates to HLSLPackOffsetAttr) +// 2. default constant buffer declarations at global scope can have +//register(c#) annotations (translates to HLSLResourceBindingAttr with +//RegisterType::C) +// It is not quaranteed that all declarations in a buffer have an annotation. +// For those where it is not specified a -1 value is added to the Layout +// vector. In the final layout these declarations will be placed at the end +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, - SmallVector &Layout) { + SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); assert(BufDecl->hasValidPackoffset()); - for (Decl *D : BufDecl->decls()) { + for (Decl *D : BufDecl->buffer_decls()) { if (isa(D) || isa(D)) { continue; } VarDecl *VD = dyn_cast(D); if (!VD || VD->getType().getAddressSpace() != LangAS::hlsl_constant) continue; -assert(VD->hasAttr() && - "expected packoffset attribute on every declaration"); -size_t Offset = VD->getAttr()->getOffsetInBytes(); +size_t Offset = -1; +if (VD->hasAttrs()) { + for (auto *Attr : VD->getAttrs()) { +if (auto *POA = dyn_cast(Attr)) { + Offset = POA->getOffsetInBytes(); +} else if (auto *RBA = dyn_cast(Attr)) { + if (RBA->getRegisterType() == + HLSLResourceBindingAttr::RegisterType::C) { +// size of constant buffer row is 16 bytes +Offset = RBA->getSlotNumber() * 16U; + } +} + } +} Layout.push_back(Offset); } } @@ -212,7 +236,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) { return; // create global variable for the constant buffer - SmallVector Layout; + SmallVector Layout; if (BufDecl->hasValidPackoffset()) fillPackoffsetLayout(BufDecl, Layout); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index a9da42324a038..c4550056175c1 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -146,7 +146,7 @@ class CGHLSLRuntime { llvm::Type * convertHLSLSpecificType(const Type *T, - SmallVector *Packoffsets = nullptr); + SmallVector *Packoffsets = nullptr); void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV); void generateGlobalCtorDtorCalls(); diff --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp index 97262b76c0164..bf9bca48a4dd6 100644 --- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp +++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp @@ -10,6 +10,7 @@ #include "CGHLSLRuntime.h" #include "Code
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
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 9faff902639aece87b72ed5235d71b8b68533074 e982a61657da5eb4c7f2618c95f0c6d3493cb854 --extensions h,cpp -- clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp clang/lib/CodeGen/HLSLBufferLayoutBuilder.h clang/lib/CodeGen/TargetInfo.h clang/lib/CodeGen/Targets/DirectX.cpp clang/lib/CodeGen/Targets/SPIR.cpp clang/lib/Sema/SemaHLSL.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 6f476d7df4..67256aa2be 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -191,7 +191,7 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) { // It is not quaranteed that all declarations in a buffer have an annotation. // For those where it is not specified a -1 value is added to the Layout // vector. In the final layout these declarations will be placed at the end -// of the HLSL buffer after all of the elements with specified offset. +// of the HLSL buffer after all of the elements with specified offset. static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl, SmallVector &Layout) { assert(Layout.empty() && "expected empty vector for layout"); diff --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp index bf9bca48a4..7a92233ac9 100644 --- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp +++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp @@ -64,7 +64,7 @@ namespace CodeGen { // user-specified offsets. Not all elements must have a packoffset/register(c#) // annotation though. For those that don't, the Packoffsets array will constain // -1 value instead. These elements must be placed at the end of the layout -// after all of the elements with specific offset. +// after all of the elements with specific offset. llvm::TargetExtType *HLSLBufferLayoutBuilder::createLayoutType( const RecordType *StructType, const llvm::SmallVector *Packoffsets) { diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp b/clang/lib/CodeGen/Targets/DirectX.cpp index 8b94d01048..88a4b812db 100644 --- a/clang/lib/CodeGen/Targets/DirectX.cpp +++ b/clang/lib/CodeGen/Targets/DirectX.cpp @@ -29,9 +29,9 @@ public: DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) : TargetCodeGenInfo(std::make_unique(CGT)) {} - llvm::Type *getHLSLType( - CodeGenModule &CGM, const Type *T, - const SmallVector *Packoffsets = nullptr) const override; + llvm::Type * + getHLSLType(CodeGenModule &CGM, const Type *T, + const SmallVector *Packoffsets = nullptr) const override; }; llvm::Type *DirectXTargetCodeGenInfo::getHLSLType( diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp b/clang/lib/CodeGen/Targets/SPIR.cpp index 056228563a..43f511e572 100644 --- a/clang/lib/CodeGen/Targets/SPIR.cpp +++ b/clang/lib/CodeGen/Targets/SPIR.cpp @@ -52,9 +52,9 @@ public: unsigned getOpenCLKernelCallingConv() const override; llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override; - llvm::Type *getHLSLType( - CodeGenModule &CGM, const Type *Ty, - const SmallVector *Packoffsets = nullptr) const override; + llvm::Type * + getHLSLType(CodeGenModule &CGM, const Type *Ty, + const SmallVector *Packoffsets = nullptr) const override; llvm::Type *getSPIRVImageTypeFromHLSLResource( const HLSLAttributedResourceType::Attributes &attributes, llvm::Type *ElementType, llvm::LLVMContext &Ctx) const; `` https://github.com/llvm/llvm-project/pull/128991 ___ 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-tools-extra] release/20.x: [clangd] [C++20] [Modules] Add scanning cache (#125988) (PR #128841)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/128841 Backport ae839b02504a68a0dfe63ac8ec314d9d7a6ce8df Requested by: @ChuanqiXu9 >From 0c59624ff222149bd926fbbe68d3c68c01db28de Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Wed, 26 Feb 2025 16:03:04 +0800 Subject: [PATCH] [clangd] [C++20] [Modules] Add scanning cache (#125988) Previously, everytime we want to get a source file declaring a specific module, we need to scan the whole projects again and again. The performance is super bad. This patch tries to improve this by introducing a simple cache. (cherry picked from commit ae839b02504a68a0dfe63ac8ec314d9d7a6ce8df) --- clang-tools-extra/clangd/ModulesBuilder.cpp | 100 -- clang-tools-extra/clangd/ProjectModules.h | 6 +- .../clangd/ScanningProjectModules.cpp | 18 +++- .../unittests/PrerequisiteModulesTest.cpp | 60 ++- 4 files changed, 164 insertions(+), 20 deletions(-) diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..08a7b250a8119 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -357,10 +357,80 @@ void ModuleFileCache::remove(StringRef ModuleName) { ModuleFiles.erase(ModuleName); } +class ModuleNameToSourceCache { +public: + std::string getSourceForModuleName(llvm::StringRef ModuleName) { +std::lock_guard Lock(CacheMutex); +auto Iter = ModuleNameToSourceCache.find(ModuleName); +if (Iter != ModuleNameToSourceCache.end()) + return Iter->second; +return ""; + } + + void addEntry(llvm::StringRef ModuleName, PathRef Source) { +std::lock_guard Lock(CacheMutex); +ModuleNameToSourceCache[ModuleName] = Source.str(); + } + + void eraseEntry(llvm::StringRef ModuleName) { +std::lock_guard Lock(CacheMutex); +ModuleNameToSourceCache.erase(ModuleName); + } + +private: + std::mutex CacheMutex; + llvm::StringMap ModuleNameToSourceCache; +}; + +class CachingProjectModules : public ProjectModules { +public: + CachingProjectModules(std::unique_ptr MDB, +ModuleNameToSourceCache &Cache) + : MDB(std::move(MDB)), Cache(Cache) { +assert(this->MDB && "CachingProjectModules should only be created with a " +"valid underlying ProjectModules"); + } + + std::vector getRequiredModules(PathRef File) override { +return MDB->getRequiredModules(File); + } + + std::string getModuleNameForSource(PathRef File) override { +return MDB->getModuleNameForSource(File); + } + + std::string getSourceForModuleName(llvm::StringRef ModuleName, + PathRef RequiredSrcFile) override { +std::string CachedResult = Cache.getSourceForModuleName(ModuleName); + +// Verify Cached Result by seeing if the source declaring the same module +// as we query. +if (!CachedResult.empty()) { + std::string ModuleNameOfCachedSource = + MDB->getModuleNameForSource(CachedResult); + if (ModuleNameOfCachedSource == ModuleName) +return CachedResult; + + // Cached Result is invalid. Clear it. + Cache.eraseEntry(ModuleName); +} + +auto Result = MDB->getSourceForModuleName(ModuleName, RequiredSrcFile); +Cache.addEntry(ModuleName, Result); + +return Result; + } + +private: + std::unique_ptr MDB; + ModuleNameToSourceCache &Cache; +}; + /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(PathRef RequiredSource, + CachingProjectModules &MDB, StringRef ModuleName) { llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; @@ -368,8 +438,8 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { ModuleNamesSet.insert(ModuleName); -for (StringRef RequiredModuleName : - MDB.getRequiredModules(MDB.getSourceForModuleName(ModuleName))) +for (StringRef RequiredModuleName : MDB.getRequiredModules( + MDB.getSourceForModuleName(ModuleName, RequiredSource))) if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); @@ -386,24 +456,29 @@ class ModulesBuilder::ModulesBuilderImpl { public: ModulesBuilderImpl(const GlobalCompilationDatabase &CDB) : Cache(CDB) {} + ModuleNameToSourceCache &getProjectModulesCache() { +return ProjectModulesCache; + } const GlobalCompilationDatabase &getCDB() const { return Cache.getCDB(); } llvm::Error - getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS, -
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clangd] [C++20] [Modules] Add scanning cache (#125988) (PR #128841)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/128841 ___ 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-tools-extra] release/20.x: [clangd] [C++20] [Modules] Add scanning cache (#125988) (PR #128841)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: None (llvmbot) Changes Backport ae839b02504a68a0dfe63ac8ec314d9d7a6ce8df Requested by: @ChuanqiXu9 --- Full diff: https://github.com/llvm/llvm-project/pull/128841.diff 4 Files Affected: - (modified) clang-tools-extra/clangd/ModulesBuilder.cpp (+89-11) - (modified) clang-tools-extra/clangd/ProjectModules.h (+3-3) - (modified) clang-tools-extra/clangd/ScanningProjectModules.cpp (+14-4) - (modified) clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp (+58-2) ``diff diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp index bee31fe51555e..08a7b250a8119 100644 --- a/clang-tools-extra/clangd/ModulesBuilder.cpp +++ b/clang-tools-extra/clangd/ModulesBuilder.cpp @@ -357,10 +357,80 @@ void ModuleFileCache::remove(StringRef ModuleName) { ModuleFiles.erase(ModuleName); } +class ModuleNameToSourceCache { +public: + std::string getSourceForModuleName(llvm::StringRef ModuleName) { +std::lock_guard Lock(CacheMutex); +auto Iter = ModuleNameToSourceCache.find(ModuleName); +if (Iter != ModuleNameToSourceCache.end()) + return Iter->second; +return ""; + } + + void addEntry(llvm::StringRef ModuleName, PathRef Source) { +std::lock_guard Lock(CacheMutex); +ModuleNameToSourceCache[ModuleName] = Source.str(); + } + + void eraseEntry(llvm::StringRef ModuleName) { +std::lock_guard Lock(CacheMutex); +ModuleNameToSourceCache.erase(ModuleName); + } + +private: + std::mutex CacheMutex; + llvm::StringMap ModuleNameToSourceCache; +}; + +class CachingProjectModules : public ProjectModules { +public: + CachingProjectModules(std::unique_ptr MDB, +ModuleNameToSourceCache &Cache) + : MDB(std::move(MDB)), Cache(Cache) { +assert(this->MDB && "CachingProjectModules should only be created with a " +"valid underlying ProjectModules"); + } + + std::vector getRequiredModules(PathRef File) override { +return MDB->getRequiredModules(File); + } + + std::string getModuleNameForSource(PathRef File) override { +return MDB->getModuleNameForSource(File); + } + + std::string getSourceForModuleName(llvm::StringRef ModuleName, + PathRef RequiredSrcFile) override { +std::string CachedResult = Cache.getSourceForModuleName(ModuleName); + +// Verify Cached Result by seeing if the source declaring the same module +// as we query. +if (!CachedResult.empty()) { + std::string ModuleNameOfCachedSource = + MDB->getModuleNameForSource(CachedResult); + if (ModuleNameOfCachedSource == ModuleName) +return CachedResult; + + // Cached Result is invalid. Clear it. + Cache.eraseEntry(ModuleName); +} + +auto Result = MDB->getSourceForModuleName(ModuleName, RequiredSrcFile); +Cache.addEntry(ModuleName, Result); + +return Result; + } + +private: + std::unique_ptr MDB; + ModuleNameToSourceCache &Cache; +}; + /// Collect the directly and indirectly required module names for \param /// ModuleName in topological order. The \param ModuleName is guaranteed to /// be the last element in \param ModuleNames. -llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, +llvm::SmallVector getAllRequiredModules(PathRef RequiredSource, + CachingProjectModules &MDB, StringRef ModuleName) { llvm::SmallVector ModuleNames; llvm::StringSet<> ModuleNamesSet; @@ -368,8 +438,8 @@ llvm::SmallVector getAllRequiredModules(ProjectModules &MDB, auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void { ModuleNamesSet.insert(ModuleName); -for (StringRef RequiredModuleName : - MDB.getRequiredModules(MDB.getSourceForModuleName(ModuleName))) +for (StringRef RequiredModuleName : MDB.getRequiredModules( + MDB.getSourceForModuleName(ModuleName, RequiredSource))) if (ModuleNamesSet.insert(RequiredModuleName).second) Visitor(RequiredModuleName, Visitor); @@ -386,24 +456,29 @@ class ModulesBuilder::ModulesBuilderImpl { public: ModulesBuilderImpl(const GlobalCompilationDatabase &CDB) : Cache(CDB) {} + ModuleNameToSourceCache &getProjectModulesCache() { +return ProjectModulesCache; + } const GlobalCompilationDatabase &getCDB() const { return Cache.getCDB(); } llvm::Error - getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS, - ProjectModules &MDB, + getOrBuildModuleFile(PathRef RequiredSource, StringRef ModuleName, + const ThreadsafeFS &TFS, CachingProjectModules &MDB, ReusablePrerequisiteModules &BuiltModuleFiles); private: ModuleFileCache Cache; + ModuleNameToSourceCache ProjectModulesCache; }; llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
[llvm-branch-commits] [clang-tools-extra] release/20.x: [clangd] [C++20] [Modules] Add scanning cache (#125988) (PR #128841)
llvmbot wrote: @kadircet What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/128841 ___ 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] Pack task private variables into a heap-allocated context struct (PR #125307)
https://github.com/ergawy approved this pull request. LGTM! Thanks! https://github.com/llvm/llvm-project/pull/125307 ___ 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] Fix an integer overflow issue in computing CTAD's parameter depth (PR #128845)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) Changes This fixes a potential integer overflow bug that has been around for many versions and was exposed by my patch recently. So we think it warrants a backport. Backports b8d1f3d62. --- Full diff: https://github.com/llvm/llvm-project/pull/128845.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+8-1) - (modified) clang/test/SemaTemplate/deduction-guide.cpp (+32) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 153afdb3d59e3..7537b2b8d42d8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1058,6 +1058,7 @@ Bug Fixes to C++ Support - Fixed a substitution bug in transforming CTAD aliases when the type alias contains a non-pack template argument corresponding to a pack parameter (#GH124715) - Clang is now better at keeping track of friend function template instance contexts. (#GH55509) +- Fixed an integer overflow bug in computing template parameter depths when synthesizing CTAD guides. (#GH128691) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index 00c5dfd3d7a43..b424de9c8a945 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -377,8 +377,15 @@ struct ConvertConstructorToDeductionGuideTransform { if (NestedPattern) Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth()); auto [Depth, Index] = getDepthAndIndex(Param); +// Depth can still be 0 if FTD belongs to an explicit class template +// specialization with an empty template parameter list. In that case, +// we don't want the NewDepth to overflow, and it should remain 0. +assert(Depth || + cast(FTD->getDeclContext()) + ->isExplicitSpecialization()); NamedDecl *NewParam = transformTemplateParameter( -SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, Depth - 1); +SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, +Depth ? Depth - 1 : 0); if (!NewParam) return nullptr; // Constraints require that we substitute depth-1 arguments diff --git a/clang/test/SemaTemplate/deduction-guide.cpp b/clang/test/SemaTemplate/deduction-guide.cpp index a4c523595fca2..ecd152abebd74 100644 --- a/clang/test/SemaTemplate/deduction-guide.cpp +++ b/clang/test/SemaTemplate/deduction-guide.cpp @@ -691,3 +691,35 @@ Test test(42); // CHECK-NEXT: | `-ParmVarDecl {{.*}} 'auto:1' } // namespace GH122134 + +namespace GH128691 { + +template +class NewDeleteAllocator; + +template <> +struct NewDeleteAllocator<> { + template + NewDeleteAllocator(T); // expected-note {{candidate template ignored}} \ + // expected-note {{implicit deduction guide declared as}} +}; + +template +struct NewDeleteAllocator : NewDeleteAllocator<> { // expected-note {{candidate template ignored}} \ + // expected-note {{implicit deduction guide declared as}} + using NewDeleteAllocator<>::NewDeleteAllocator; +}; + +void test() { NewDeleteAllocator abc(42); } // expected-error {{no viable constructor or deduction guide}} + +// CHECK-LABEL: Dumping GH128691::: +// CHECK-NEXT: FunctionTemplateDecl {{.+}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0 +// CHECK-NEXT: | `-TemplateArgument type 'void' +// CHECK-NEXT: | |-inherited from TemplateTypeParm {{.+}} depth 0 index 0 +// CHECK-NEXT: | `-BuiltinType {{.+}} 'void' +// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 1 T +// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} 'auto (T) -> NewDeleteAllocator' +// CHECK-NEXT: `-ParmVarDecl {{.+}} 'T' + +} // namespace GH128691 `` https://github.com/llvm/llvm-project/pull/128845 ___ 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] Fix an integer overflow issue in computing CTAD's parameter depth (PR #128845)
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/128845 This fixes a potential integer overflow bug that has been around for many versions and was exposed by my patch recently. So we think it warrants a backport. Backports b8d1f3d62. >From 4adb975ae689d575dcd329ccd24d2cd0355bb61b Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Wed, 26 Feb 2025 16:54:19 +0800 Subject: [PATCH] [Clang] Fix an integer overflow issue in computing CTAD's parameter depth (#128704) Backports b8d1f3d62. This fixes a potential integer overflow bug that has been around for many versions and was exposed by my patch recently. So we think it warrants a backport --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 9 +- clang/test/SemaTemplate/deduction-guide.cpp | 32 +++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 153afdb3d59e3..7537b2b8d42d8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1058,6 +1058,7 @@ Bug Fixes to C++ Support - Fixed a substitution bug in transforming CTAD aliases when the type alias contains a non-pack template argument corresponding to a pack parameter (#GH124715) - Clang is now better at keeping track of friend function template instance contexts. (#GH55509) +- Fixed an integer overflow bug in computing template parameter depths when synthesizing CTAD guides. (#GH128691) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index 00c5dfd3d7a43..b424de9c8a945 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -377,8 +377,15 @@ struct ConvertConstructorToDeductionGuideTransform { if (NestedPattern) Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth()); auto [Depth, Index] = getDepthAndIndex(Param); +// Depth can still be 0 if FTD belongs to an explicit class template +// specialization with an empty template parameter list. In that case, +// we don't want the NewDepth to overflow, and it should remain 0. +assert(Depth || + cast(FTD->getDeclContext()) + ->isExplicitSpecialization()); NamedDecl *NewParam = transformTemplateParameter( -SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, Depth - 1); +SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, +Depth ? Depth - 1 : 0); if (!NewParam) return nullptr; // Constraints require that we substitute depth-1 arguments diff --git a/clang/test/SemaTemplate/deduction-guide.cpp b/clang/test/SemaTemplate/deduction-guide.cpp index a4c523595fca2..ecd152abebd74 100644 --- a/clang/test/SemaTemplate/deduction-guide.cpp +++ b/clang/test/SemaTemplate/deduction-guide.cpp @@ -691,3 +691,35 @@ Test test(42); // CHECK-NEXT: | `-ParmVarDecl {{.*}} 'auto:1' } // namespace GH122134 + +namespace GH128691 { + +template +class NewDeleteAllocator; + +template <> +struct NewDeleteAllocator<> { + template + NewDeleteAllocator(T); // expected-note {{candidate template ignored}} \ + // expected-note {{implicit deduction guide declared as}} +}; + +template +struct NewDeleteAllocator : NewDeleteAllocator<> { // expected-note {{candidate template ignored}} \ + // expected-note {{implicit deduction guide declared as}} + using NewDeleteAllocator<>::NewDeleteAllocator; +}; + +void test() { NewDeleteAllocator abc(42); } // expected-error {{no viable constructor or deduction guide}} + +// CHECK-LABEL: Dumping GH128691::: +// CHECK-NEXT: FunctionTemplateDecl {{.+}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 0 +// CHECK-NEXT: | `-TemplateArgument type 'void' +// CHECK-NEXT: | |-inherited from TemplateTypeParm {{.+}} depth 0 index 0 +// CHECK-NEXT: | `-BuiltinType {{.+}} 'void' +// CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} typename depth 0 index 1 T +// CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} 'auto (T) -> NewDeleteAllocator' +// CHECK-NEXT: `-ParmVarDecl {{.+}} 'T' + +} // namespace GH128691 ___ 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] Fix an integer overflow issue in computing CTAD's parameter depth (PR #128845)
https://github.com/hokein approved this pull request. https://github.com/llvm/llvm-project/pull/128845 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement explicit layout for default constant buffer $Globals (PR #128991)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/128991 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits