[llvm-branch-commits] [llvm] release/21.x: [AArch64][PAC][GISel] Add missing clobbering info to LOADgotAUTH (#157433) (PR #160668)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 Author: None (llvmbot) Changes Backport cff5a439a847db67ea3478b088ec2f8047871ff0 Requested by: @atrosinenko --- Full diff: https://github.com/llvm/llvm-project/pull/160668.diff 2 Files Affected: - (modified) llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp (+3-3) - (added) llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-elf-got.mir (+23) ``diff diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp index 1381a9b70df87..450915518cc2f 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -2977,10 +2977,10 @@ bool AArch64InstructionSelector::select(MachineInstr &I) { } if (OpFlags & AArch64II::MO_GOT) { - I.setDesc(TII.get(MF.getInfo()->hasELFSignedGOT() -? AArch64::LOADgotAUTH -: AArch64::LOADgot)); + bool IsGOTSigned = MF.getInfo()->hasELFSignedGOT(); + I.setDesc(TII.get(IsGOTSigned ? AArch64::LOADgotAUTH : AArch64::LOADgot)); I.getOperand(1).setTargetFlags(OpFlags); + I.addImplicitDefUseOperands(MF); } else if (TM.getCodeModel() == CodeModel::Large && !TM.isPositionIndependent()) { // Materialize the global using movz/movk instructions. diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-elf-got.mir b/llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-elf-got.mir new file mode 100644 index 0..faf2cb8221ec7 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-elf-got.mir @@ -0,0 +1,23 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4 +# RUN: llc -O0 -mtriple=aarch64-linux-gnu -relocation-model=pic -run-pass=instruction-select -global-isel-abort=1 -verify-machineinstrs %s -o - | FileCheck %s + +--- | + @var_got = external global i8 + define ptr @loadgotauth_implicit_defs() { ret ptr null } + + !llvm.module.flags = !{!0} + !0 = !{i32 8, !"ptrauth-elf-got", i32 1} +... + +--- +name:loadgotauth_implicit_defs +legalized: true +regBankSelected: true +body: | + bb.0: +; CHECK-LABEL: name: loadgotauth_implicit_defs +; CHECK: [[LOADgotAUTH:%[0-9]+]]:gpr64common = LOADgotAUTH target-flags(aarch64-got) @var_got, implicit-def $x16, implicit-def $x17, implicit-def $nzcv +; CHECK-NEXT: $x0 = COPY [[LOADgotAUTH]] +%0:gpr(p0) = G_GLOBAL_VALUE @var_got +$x0 = COPY %0(p0) +... `` https://github.com/llvm/llvm-project/pull/160668 ___ 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] [compiler-rt] release/21.x: [compiler-rt][sanitizer] fix msghdr for musl (PR #159551)
https://github.com/nikic milestoned https://github.com/llvm/llvm-project/pull/159551 ___ 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] port 5b4819e to release (PR #159209)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/159209 ___ 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] 660afe4 - Revert "[MLIR] Implement remark emitting policies in MLIR (#160526)"
Author: Mehdi Amini Date: 2025-09-25T12:12:10+02:00 New Revision: 660afe41d8f835058cba0b02d2856b12ed9fb0ba URL: https://github.com/llvm/llvm-project/commit/660afe41d8f835058cba0b02d2856b12ed9fb0ba DIFF: https://github.com/llvm/llvm-project/commit/660afe41d8f835058cba0b02d2856b12ed9fb0ba.diff LOG: Revert "[MLIR] Implement remark emitting policies in MLIR (#160526)" This reverts commit 020b9286413c151d33e2d72c29abc8b56c7080d3. Added: Modified: mlir/include/mlir/IR/Remarks.h mlir/include/mlir/Remark/RemarkStreamer.h mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h mlir/lib/IR/MLIRContext.cpp mlir/lib/IR/Remarks.cpp mlir/lib/Remark/RemarkStreamer.cpp mlir/lib/Tools/mlir-opt/MlirOptMain.cpp mlir/test/lib/Pass/TestRemarksPass.cpp mlir/unittests/IR/RemarkTest.cpp Removed: mlir/test/Pass/remark-final.mlir diff --git a/mlir/include/mlir/IR/Remarks.h b/mlir/include/mlir/IR/Remarks.h index 5e2bd828bd00e..20e84ec83cd01 100644 --- a/mlir/include/mlir/IR/Remarks.h +++ b/mlir/include/mlir/IR/Remarks.h @@ -24,8 +24,6 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Value.h" -#include - namespace mlir::remark { /// Define an the set of categories to accept. By default none are, the provided @@ -146,7 +144,7 @@ class Remark { llvm::StringRef getCategoryName() const { return categoryName; } - llvm::StringRef getCombinedCategoryName() const { + llvm::StringRef getFullCategoryName() const { if (categoryName.empty() && subCategoryName.empty()) return {}; if (subCategoryName.empty()) @@ -320,7 +318,7 @@ class InFlightRemark { }; //===--===// -// Pluggable Remark Utilities +// MLIR Remark Streamer //===--===// /// Base class for MLIR remark streamers that is used to stream @@ -340,26 +338,6 @@ class MLIRRemarkStreamerBase { virtual void finalize() {} // optional }; -using ReportFn = llvm::unique_function; - -/// Base class for MLIR remark emitting policies that is used to emit -/// optimization remarks to the underlying remark streamer. The derived classes -/// should implement the `reportRemark` method to provide the actual emitting -/// implementation. -class RemarkEmittingPolicyBase { -protected: - ReportFn reportImpl; - -public: - RemarkEmittingPolicyBase() = default; - virtual ~RemarkEmittingPolicyBase() = default; - - void initialize(ReportFn fn) { reportImpl = std::move(fn); } - - virtual void reportRemark(const Remark &remark) = 0; - virtual void finalize() = 0; -}; - //===--===// // Remark Engine (MLIR Context will own this class) //===--===// @@ -377,8 +355,6 @@ class RemarkEngine { std::optional failedFilter; /// The MLIR remark streamer that will be used to emit the remarks. std::unique_ptr remarkStreamer; - /// The MLIR remark policy that will be used to emit the remarks. - std::unique_ptr remarkEmittingPolicy; /// When is enabled, engine also prints remarks as mlir::emitRemarks. bool printAsEmitRemarks = false; @@ -416,8 +392,6 @@ class RemarkEngine { InFlightRemark emitIfEnabled(Location loc, RemarkOpts opts, bool (RemarkEngine::*isEnabled)(StringRef) const); - /// Report a remark. - void reportImpl(const Remark &remark); public: /// Default constructor is deleted, use the other constructor. @@ -433,10 +407,8 @@ class RemarkEngine { ~RemarkEngine(); /// Setup the remark engine with the given output path and format. - LogicalResult - initialize(std::unique_ptr streamer, - std::unique_ptr remarkEmittingPolicy, - std::string *errMsg); + LogicalResult initialize(std::unique_ptr streamer, + std::string *errMsg); /// Report a remark. void report(const Remark &&remark); @@ -474,54 +446,6 @@ inline InFlightRemark withEngine(Fn fn, Location loc, Args &&...args) { namespace mlir::remark { -//===--===// -// Remark Emitting Policies -//===--===// - -/// Policy that emits all remarks. -class RemarkEmittingPolicyAll : public detail::RemarkEmittingPolicyBase { -public: - RemarkEmittingPolicyAll(); - - void reportRemark(const detail::Remark &remark) override { -reportImpl(remark); - } - void finalize() override {} -}; - -/// Policy that emits final remarks. -class RemarkEmittingPolicyFinal : public detail::RemarkEmittingPolicyBase { -private: - /// user can intercept them for custom processing via a registered callback, - /// otherwise they will be
[llvm-branch-commits] [clang] release/21.x: Generalize test over 32 and 64bit targets (PR #160680)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/160680 Backport 5b4819e337c662fad7176a1d8e7b95a94f199290 Requested by: @llvmbot >From 69297c9cca5a77a3d0a856ed3947e855dc968c8e Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 2 Sep 2025 21:53:10 + Subject: [PATCH] Generalize test over 32 and 64bit targets (cherry picked from commit 5b4819e337c662fad7176a1d8e7b95a94f199290) --- clang/test/CodeGenCXX/debug-info-structured-binding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp index 4a4a4d8bdfaad..8032ce85c9e25 100644 --- a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp +++ b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp @@ -10,7 +10,7 @@ // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y1_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y2_DEBUG_LOC:[0-9]+]] // CHECK: load ptr, ptr %z2, {{.*}}!dbg ![[Z2_DEBUG_LOC:[0-9]+]] -// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i64 0, i64 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] +// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i{{64|32}} 0, i{{64|32}} 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw { i32, i32 }, ptr {{.*}}, i32 0, i32 1, !dbg ![[C2_DEBUG_LOC:[0-9]+]] // CHECK: extractelement <2 x i32> {{.*}}, i32 1, !dbg ![[V2_DEBUG_LOC:[0-9]+]] // CHECK: ![[VAR_0]] = !DILocalVariable(name: "a" ___ 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/21.x: Generalize test over 32 and 64bit targets (PR #160680)
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/160680 >From 52a5df30aeccc9ba1b6e15ad860f0a7f5fe1d13a Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 2 Sep 2025 21:53:10 + Subject: [PATCH] Generalize test over 32 and 64bit targets (cherry picked from commit 5b4819e337c662fad7176a1d8e7b95a94f199290) --- clang/test/CodeGenCXX/debug-info-structured-binding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp index 4a4a4d8bdfaad..8032ce85c9e25 100644 --- a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp +++ b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp @@ -10,7 +10,7 @@ // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y1_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y2_DEBUG_LOC:[0-9]+]] // CHECK: load ptr, ptr %z2, {{.*}}!dbg ![[Z2_DEBUG_LOC:[0-9]+]] -// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i64 0, i64 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] +// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i{{64|32}} 0, i{{64|32}} 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw { i32, i32 }, ptr {{.*}}, i32 0, i32 1, !dbg ![[C2_DEBUG_LOC:[0-9]+]] // CHECK: extractelement <2 x i32> {{.*}}, i32 1, !dbg ![[V2_DEBUG_LOC:[0-9]+]] // CHECK: ![[VAR_0]] = !DILocalVariable(name: "a" ___ 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/21.x: Generalize test over 32 and 64bit targets (PR #160680)
https://github.com/mgorny closed https://github.com/llvm/llvm-project/pull/160680 ___ 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] [llvm] [openmp] [Flang] Add standalone tile support (PR #160298)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/160298 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_SIMD (PR #160390)
https://github.com/tblah edited https://github.com/llvm/llvm-project/pull/160390 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_SIMD (PR #160390)
https://github.com/tblah approved this pull request. LGTM with one nit https://github.com/llvm/llvm-project/pull/160390 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_SIMD (PR #160390)
@@ -1356,8 +1351,32 @@ void OmpStructureChecker::Leave(const parser::OpenMPThreadprivate &x) { } void OmpStructureChecker::Enter(const parser::OpenMPDeclareSimdConstruct &x) { - const auto &dir{std::get(x.t)}; - PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_declare_simd); + const parser::OmpDirectiveName &dirName{x.v.DirName()}; + PushContextAndClauseSets(dirName.source, dirName.v); + + const parser::OmpArgumentList &args{x.v.Arguments()}; + if (args.v.empty()) { +return; + } else if (args.v.size() > 1) { +context_.Say(args.source, +"DECLARE_SIMD directive should have at most one argument"_err_en_US); +return; + } + + const parser::OmpArgument &arg{args.v.front()}; + if (auto *sym{GetArgumentSymbol(arg)}) { +if (!IsProcedure(*sym) && !IsFunction(*sym)) { + context_.Say(arg.source, + "The name '%s' should refer to a procedure"_err_en_US, sym->name()); +} +if (sym->test(Symbol::Flag::Implicit)) { + context_.Say(arg.source, + "The name '%s' has been implicitly declared"_err_en_US, sym->name()); tblah wrote: nit: should this come before the `!IsProcedure(*sym) && !IsFunction(*sym)` check? If it is implicitly declared I imagine it won't be a procedure or function type anyway - but if declarations are in the wrong order in a source file I think this message is clearer than the type error. https://github.com/llvm/llvm-project/pull/160390 ___ 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/21.x: [AArch64][PAC][GISel] Add missing clobbering info to LOADgotAUTH (#157433) (PR #160668)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/160668 ___ 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/21.x: [AArch64][PAC][GISel] Add missing clobbering info to LOADgotAUTH (#157433) (PR #160668)
llvmbot wrote: @aemerson What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/160668 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_VARIANT (PR #160371)
https://github.com/tblah approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/160371 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_VARIANT (PR #160371)
https://github.com/tblah edited https://github.com/llvm/llvm-project/pull/160371 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in ASSUMES (PR #160591)
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/160591 None >From eb12400ffc25b62205183f3102a1e0afdb785510 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 24 Sep 2025 14:38:40 -0500 Subject: [PATCH] [flang][OpenMP] Use OmpDirectiveSpecification in ASSUMES --- flang/include/flang/Parser/openmp-utils.h | 2 -- flang/include/flang/Parser/parse-tree.h | 4 ++-- flang/lib/Parser/openmp-parsers.cpp | 6 -- flang/lib/Parser/unparse.cpp| 4 ++-- flang/lib/Semantics/check-omp-structure.cpp | 4 flang/test/Parser/OpenMP/assumption.f90 | 8 +--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index bf54f970a7d3a..77c31b939e522 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -39,7 +39,6 @@ struct ConstructId { } MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate); -MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes); MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction); MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate); MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires); @@ -94,7 +93,6 @@ struct DirectiveNameScope { if constexpr (std::is_base_of_v) { return std::get(x.t).DirName(); } else if constexpr (std::is_same_v || - std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v) { diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 486be8b60ff8c..bd55166eb9f80 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4877,8 +4877,8 @@ struct OpenMPUtilityConstruct { // ASSUMES absent-clause | contains-clause | holds-clause | no-openmp-clause | // no-openmp-routines-clause | no-parallelism-clause struct OpenMPDeclarativeAssumes { - TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAssumes); - std::tuple t; + WRAPPER_CLASS_BOILERPLATE( + OpenMPDeclarativeAssumes, OmpDirectiveSpecification); CharBlock source; }; diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index bd080386c0aea..12e89e8c35456 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1852,8 +1852,10 @@ TYPE_PARSER( lookAhead(endOmpLine / !statement(allocateStmt))) // Assumes Construct -TYPE_PARSER(sourced(construct( -verbatim("ASSUMES"_tok), Parser{}))) +TYPE_PARSER(construct( +predicated(OmpDirectiveNameParser{}, +IsDirective(llvm::omp::Directive::OMPD_assumes)) >= +Parser{})) // Declarative constructs TYPE_PARSER( diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index a2b0b9ef3196c..9812a656092ac 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2558,8 +2558,8 @@ class UnparseVisitor { void Unparse(const OpenMPDeclarativeAssumes &x) { BeginOpenMP(); -Word("!$OMP ASSUMES "); -Walk(std::get(x.t)); +Word("!$OMP "); +Walk(x.v); Put("\n"); EndOpenMP(); } diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 05ff541657b1a..6538e0b794791 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -620,10 +620,6 @@ template struct DirectiveSpellingVisitor { checker_(GetDirName(x.t).source, Directive::OMPD_allocators); return false; } - bool Pre(const parser::OpenMPDeclarativeAssumes &x) { -checker_(std::get(x.t).source, Directive::OMPD_assumes); -return false; - } bool Pre(const parser::OpenMPGroupprivate &x) { checker_(x.v.DirName().source, Directive::OMPD_groupprivate); return false; diff --git a/flang/test/Parser/OpenMP/assumption.f90 b/flang/test/Parser/OpenMP/assumption.f90 index 0f333f99f9085..86cbad9e42f78 100644 --- a/flang/test/Parser/OpenMP/assumption.f90 +++ b/flang/test/Parser/OpenMP/assumption.f90 @@ -141,9 +141,11 @@ program p end program p !UNPARSE: PROGRAM p -!UNPARSE: !$OMP ASSUMES NO_OPENMP +!UNPARSE: !$OMP ASSUMES NO_OPENMP !UNPARSE: END PROGRAM p -!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclarativeAssumes -!PARSE-TREE: | Verbatim +!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclarativeAssumes -> OmpDirectiveSpecification +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = assumes !PARSE-TREE: | OmpClauseList -> OmpClause -> NoOpenmp +!PARSE-TREE: | Flags = None +!PARSE-TREE: ImplicitPart -> ___ 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] [mlir][omp] Add omp.tile operation (PR #160292)
@@ -403,6 +403,7 @@ void DefFormat::genLiteralParser(StringRef value, FmtContext &ctx, .Case("]", "RSquare") .Case("?", "Question") .Case("+", "Plus") + .Case("-", "Minus") Meinersbur wrote: I am confident the omission is accidental. The `-` token can already be parsed using `hasCustomAssemblyFormat = 1` and calling https://github.com/llvm/llvm-project/blob/3bfcbfc327ad5ca8bcec086a6d837f105d58e801/mlir/lib/AsmParser/AsmParserImpl.h#L239-L242 The omission here only means that one could not use the `-` token in `assemblyFormat` to let mlir-tblgen generate the parser for you. It will actually generate a call to the `parseMinus` function above. https://github.com/llvm/llvm-project/pull/160292 ___ 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] [mlir][omp] Add omp.tile operation (PR #160292)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/160292 ___ 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] [mlir][omp] Add omp.tile operation (PR #160292)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/160292 ___ 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] [LV] Add ExtNegatedMulAccReduction expression type (PR #160154)
llvmbot wrote: @llvm/pr-subscribers-vectorizers Author: Sam Tebbs (SamTebbs33) Changes This PR adds the ExtNegatedMulAccReduction expression type for VPExpressionRecipe so that extend-multiply-accumulate reductions with a negated multiply can be bundled. Stacked PRs: 1. https://github.com/llvm/llvm-project/pull/156976 2. -> https://github.com/llvm/llvm-project/pull/160154 3. https://github.com/llvm/llvm-project/pull/147302 --- Full diff: https://github.com/llvm/llvm-project/pull/160154.diff 4 Files Affected: - (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+11) - (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+30-1) - (modified) llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp (+30-16) - (modified) llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll (+121) ``diff diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index e6f6067bc9df3..1cb0c889528ec 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2989,6 +2989,12 @@ class VPExpressionRecipe : public VPSingleDefRecipe { /// vector operands, performing a reduction.add on the result, and adding /// the scalar result to a chain. MulAccReduction, +/// Represent an inloop multiply-accumulate reduction, multiplying the +/// extended vector operands, negating the multiplication, performing a +/// reduction.add +/// on the result, and adding +/// the scalar result to a chain. +ExtNegatedMulAccReduction, }; /// Type of the expression. @@ -3012,6 +3018,11 @@ class VPExpressionRecipe : public VPSingleDefRecipe { VPWidenRecipe *Mul, VPReductionRecipe *Red) : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction, {Ext0, Ext1, Mul, Red}) {} + VPExpressionRecipe(VPWidenCastRecipe *Ext0, VPWidenCastRecipe *Ext1, + VPWidenRecipe *Mul, VPWidenRecipe *Sub, + VPReductionRecipe *Red) + : VPExpressionRecipe(ExpressionTypes::ExtNegatedMulAccReduction, + {Ext0, Ext1, Mul, Sub, Red}) {} ~VPExpressionRecipe() override { SmallSet ExpressionRecipesSeen; diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 4568d4f37a751..02be0db102547 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2861,12 +2861,17 @@ InstructionCost VPExpressionRecipe::computeCost(ElementCount VF, return Ctx.TTI.getMulAccReductionCost(false, Opcode, RedTy, SrcVecTy, Ctx.CostKind); - case ExpressionTypes::ExtMulAccReduction: + case ExpressionTypes::ExtNegatedMulAccReduction: + case ExpressionTypes::ExtMulAccReduction: { +if (ExpressionType == ExpressionTypes::ExtNegatedMulAccReduction && +Opcode == Instruction::Add) + Opcode = Instruction::Sub; return Ctx.TTI.getMulAccReductionCost( cast(ExpressionRecipes.front())->getOpcode() == Instruction::ZExt, Opcode, RedTy, SrcVecTy, Ctx.CostKind); } + } llvm_unreachable("Unknown VPExpressionRecipe::ExpressionTypes enum"); } @@ -2912,6 +2917,30 @@ void VPExpressionRecipe::print(raw_ostream &O, const Twine &Indent, O << ")"; break; } + case ExpressionTypes::ExtNegatedMulAccReduction: { +getOperand(getNumOperands() - 1)->printAsOperand(O, SlotTracker); +O << " + reduce." + << Instruction::getOpcodeName( + RecurrenceDescriptor::getOpcode(Red->getRecurrenceKind())) + << " (sub (0, mul"; +auto *Mul = cast(ExpressionRecipes[2]); +Mul->printFlags(O); +O << "("; +getOperand(0)->printAsOperand(O, SlotTracker); +auto *Ext0 = cast(ExpressionRecipes[0]); +O << " " << Instruction::getOpcodeName(Ext0->getOpcode()) << " to " + << *Ext0->getResultType() << "), ("; +getOperand(1)->printAsOperand(O, SlotTracker); +auto *Ext1 = cast(ExpressionRecipes[1]); +O << " " << Instruction::getOpcodeName(Ext1->getOpcode()) << " to " + << *Ext1->getResultType() << ")"; +if (Red->isConditional()) { + O << ", "; + Red->getCondOp()->printAsOperand(O, SlotTracker); +} +O << "))"; +break; + } case ExpressionTypes::MulAccReduction: case ExpressionTypes::ExtMulAccReduction: { getOperand(getNumOperands() - 1)->printAsOperand(O, SlotTracker); diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 1f6b85270607e..ca89c4fa0d2e6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -3524,14 +3524,22 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red, }; VPValue *VecOp = Red->getVecOp(); + VPValue *Mul = nullptr; + VPValue *Sub = nullptr; VPValue *A, *B; + //
[llvm-branch-commits] [clang] [LifetimeSafety] Disable canonicalization in immutable collections (PR #159850)
https://github.com/ymand approved this pull request. https://github.com/llvm/llvm-project/pull/159850 ___ 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] [llvm] [openmp] [Flang] Add standalone tile support (PR #160298)
@@ -0,0 +1,31 @@ +! This test checks lowering of the OpenMP tile directive +! It is done 3 times corresponding to every possible fraction of the last +! iteration before passing beyond UB. + +! RUN: %flang %flags %openmp_flags -fopenmp-version=51 -DUB=16 %s -o %t-ub16.exe Meinersbur wrote: The ability has been added in #150722. It is an established pattern for Clang. The OpenMP (runtime) tests are OpenMP code, for which Clang is used to generate calls to the runtime. Therefore this indeed an end2end test which are usually avoided in LLVM (See e.g. discussion at https://discourse.llvm.org/t/rfc-end-to-end-testing/53306). The alternative would have been to have test unittests that call the OpenMP runtime function as Clang would generate them (like we actually do for Flang-RT). However, these are end2end from the beginning when Intel donated the runtime to the LLVM project and no effort has been made to change it for the sake of it. Note that other runtime projects, such as [libc++](https://github.com/llvm/llvm-project/blob/main/libcxx/test/selftest/), have end2end tests as well. The fact that `!$omp tile` does not emit any runtime call IMHO is an implementation detail. It could well involved the runtime like `!$omp do`. We already have clang tests for tiling, unrolling, etc. (there was a discusscusson about it soewehere in Phabricator), so I think it is consequential to allow them for Flang as well. Some of Clang versions of those, and maybe future Flang tests, also test implementation-specific behavior, such as [how often arguments inside clauses are evaluated](https://github.com/llvm/llvm-project/blob/main/openmp/runtime/test/transform/tile/intfor.c). Those are tied to specific version of the compiler and would be a pain point to keep synchronized in the llvm-test-suite. In the past I myself argued having Flang's end-2-end tests to be in the llvm-test-suite instead of in the monorepository. Reason are that Clang does so as well, and you can only run tests for your native architecture; you would not be able to test ARM compilation when your machine is x86. For a runtime, you can only test it if you run the target arch's code, which might be why end2end tests are accepted for LLVM_ENABLE_RUNTIMES projects. I would not have added them here if OpenMP didn't already rely on end-to-end testing. I can create an RFC about end2end tests for OpenMP/runtimes. > Does this test need a requires line ensuring that flang is built? `.f90` and `.F90` file are only enabled when Flang is available: https://github.com/llvm/llvm-project/blob/c80d49590871c2060bbea758e09382bc5f9561c6/openmp/runtime/test/lit.cfg#L45-L46 https://github.com/llvm/llvm-project/pull/160298 ___ 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] [AllocToken] Introduce AllocToken instrumentation pass (PR #156838)
https://github.com/melver edited https://github.com/llvm/llvm-project/pull/156838 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Validating Root flags are denying shader stage (PR #153287)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/153287 >From b1e34ff07fffe96fec438b87027bd2c450b6b36f Mon Sep 17 00:00:00 2001 From: Joao Saffran <{ID}+{username}@users.noreply.github.com> Date: Tue, 12 Aug 2025 13:07:42 -0700 Subject: [PATCH 01/26] adding validaiton and tests --- .../DXILPostOptimizationValidation.cpp| 95 ++- .../rootsignature-validation-deny-shader.ll | 16 ...re-validation-fail-deny-multiple-shader.ll | 17 ...ture-validation-fail-deny-single-shader.ll | 17 4 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/rootsignature-validation-deny-shader.ll create mode 100644 llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-multiple-shader.ll create mode 100644 llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-single-shader.ll diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp index 3721b5f539b8c..251f4a0daf43a 100644 --- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp +++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp @@ -21,6 +21,7 @@ #include "llvm/InitializePasses.h" #include "llvm/MC/DXContainerRootSignature.h" #include "llvm/Support/DXILABI.h" +#include "llvm/TargetParser/Triple.h" #include #define DEBUG_TYPE "dxil-post-optimization-validation" @@ -169,15 +170,16 @@ reportDescriptorTableMixingTypes(Module &M, uint32_t Location, M.getContext().diagnose(DiagnosticInfoGeneric(Message)); } -static void reportOverlowingRange(Module &M, const dxbc::RTS0::v2::DescriptorRange &Range) { +static void +reportOverlowingRange(Module &M, const dxbc::RTS0::v2::DescriptorRange &Range) { SmallString<128> Message; raw_svector_ostream OS(Message); - OS << "Cannot append range with implicit lower " - << "bound after an unbounded range " - << getResourceClassName(toResourceClass(static_cast(Range.RangeType))) - << "(register=" << Range.BaseShaderRegister << ", space=" << - Range.RegisterSpace - << ") exceeds maximum allowed value."; + OS << "Cannot append range with implicit lower " + << "bound after an unbounded range " + << getResourceClassName(toResourceClass( +static_cast(Range.RangeType))) + << "(register=" << Range.BaseShaderRegister + << ", space=" << Range.RegisterSpace << ") exceeds maximum allowed value."; M.getContext().diagnose(DiagnosticInfoGeneric(Message)); } @@ -262,12 +264,57 @@ getRootDescriptorsBindingInfo(const mcdxbc::RootSignatureDesc &RSD, return RDs; } +static void reportIfDeniedShaderStageAccess(Module &M, dxbc::RootFlags Flags, +dxbc::RootFlags Mask) { + if ((Flags & Mask) == Mask) { +SmallString<128> Message; +raw_svector_ostream OS(Message); +OS << "Shader has root bindings but root signature uses a DENY flag to " + "disallow root binding access to the shader stage."; +M.getContext().diagnose(DiagnosticInfoGeneric(Message)); + } +} + +static void validateRootFlags(Module &M, const mcdxbc::RootSignatureDesc &RSD, + const dxil::ModuleMetadataInfo &MMI) { + dxbc::RootFlags Flags = dxbc::RootFlags(RSD.Flags); + switch (MMI.ShaderProfile) { + case Triple::Pixel: +reportIfDeniedShaderStageAccess(M, Flags, + dxbc::RootFlags::DenyPixelShaderRootAccess); +break; + case Triple::Vertex: +reportIfDeniedShaderStageAccess( +M, Flags, dxbc::RootFlags::DenyVertexShaderRootAccess); +break; + case Triple::Geometry: +reportIfDeniedShaderStageAccess( +M, Flags, dxbc::RootFlags::DenyGeometryShaderRootAccess); +break; + case Triple::Hull: +reportIfDeniedShaderStageAccess(M, Flags, +dxbc::RootFlags::DenyHullShaderRootAccess); +break; + case Triple::Domain: +reportIfDeniedShaderStageAccess( +M, Flags, dxbc::RootFlags::DenyDomainShaderRootAccess); +break; + case Triple::Mesh: +reportIfDeniedShaderStageAccess(M, Flags, +dxbc::RootFlags::DenyMeshShaderRootAccess); +break; + case Triple::Amplification: +reportIfDeniedShaderStageAccess( +M, Flags, dxbc::RootFlags::DenyAmplificationShaderRootAccess); +break; + default: +break; + } +} static void validateDescriptorTables(Module &M, - const mcdxbc::RootSignatureDesc &RSD, - dxil::ModuleMetadataInfo &MMI, - DXILResourceMap &DRM) { + const mcdxbc::RootSignatureDesc &RSD) { for (const mcdxbc::RootParameterInfo &ParamInfo : RSD.ParametersContainer) { if (static_cast(ParamInfo.Header.ParameterType) != dxbc::RootParameterType::DescriptorTable) @@ -2
[llvm-branch-commits] [clang] [clang] fix transformation of subst constant template parameter nodes (PR #160777)
https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/160777 This simplifies those transforms a lot, removing a bunch of workarounds which were introducing problems. The transforms become independent of the template instantiator, so they are moved to TreeTransform instead. Fixes #131342 >From 4361d483d82ef8642b6c8077b7da17d599ff54da Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 24 Sep 2025 17:18:41 -0300 Subject: [PATCH] [clang] fix transformation of subst constant template parameter nodes This simplifies those transforms a lot, removing a bunch of workarounds which were introducing problems. The transforms become independent of the template instantiator, so they are moved to TreeTransform instead. Fixes #131342 --- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/AST/ExprCXX.h | 2 +- clang/include/clang/AST/TypeBase.h| 4 +- clang/include/clang/Sema/Sema.h | 17 ++ clang/lib/AST/ExprCXX.cpp | 4 +- clang/lib/AST/StmtProfile.cpp | 3 +- clang/lib/Sema/SemaTemplate.cpp | 34 +++ clang/lib/Sema/SemaTemplateInstantiate.cpp| 203 ++ .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 23 +- clang/lib/Sema/TreeTransform.h| 67 -- clang/test/SemaCXX/ctad.cpp | 7 + clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 2 +- .../SemaTemplate/temp_arg_nontype_cxx2c.cpp | 11 + 13 files changed, 163 insertions(+), 215 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 703fe2ab35af3..99ca301f54a57 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -361,6 +361,7 @@ Bug Fixes in This Version first parameter. (#GH113323). - Fixed a crash with incompatible pointer to integer conversions in designated initializers involving string literals. (#GH154046) +- Fix crash on CTAD for alias template. (#GH131342) - Clang now emits a frontend error when a function marked with the `flatten` attribute calls another function that requires target features not enabled in the caller. This prevents a fatal error in the backend. diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 9fedb230ce397..5f16bac94d5e6 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4714,7 +4714,7 @@ class SubstNonTypeTemplateParmExpr : public Expr { // sugared: it doesn't need to be resugared later. bool getFinal() const { return Final; } - NamedDecl *getParameter() const; + NonTypeTemplateParmDecl *getParameter() const; bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); } diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h index b02d9c7499fe5..e0d00b82f2b76 100644 --- a/clang/include/clang/AST/TypeBase.h +++ b/clang/include/clang/AST/TypeBase.h @@ -3495,7 +3495,9 @@ class AdjustedType : public Type, public llvm::FoldingSetNode { AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr) - : Type(TC, CanonicalPtr, OriginalTy->getDependence()), + : Type(TC, CanonicalPtr, + AdjustedTy->getDependence() | + (OriginalTy->getDependence() & ~TypeDependence::Dependent)), OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {} public: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 5edfc29d93781..2bd6be2a32cd5 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11714,6 +11714,23 @@ class Sema final : public SemaBase { const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand); + UnsignedOrNone getPackIndex(TemplateArgument Pack) const { +return Pack.pack_size() - 1 - *ArgPackSubstIndex; + } + + TemplateArgument + getPackSubstitutedTemplateArgument(TemplateArgument Arg) const { +Arg = Arg.pack_elements()[*ArgPackSubstIndex]; +if (Arg.isPackExpansion()) + Arg = Arg.getPackExpansionPattern(); +return Arg; + } + + ExprResult BuildSubstNonTypeTemplateParmExpr( + Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP, + SourceLocation loc, TemplateArgument Replacement, + UnsignedOrNone PackIndex, bool Final); + /// Form a template name from a name that is syntactically required to name a /// template, either due to use of the 'template' keyword or because a name in /// this syntactic context is assumed to name a template (C++ diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index 97ae4a07f32aa..95de6a82a5270 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -1725,8 +1725,8 @@ SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, return new (Storage) SizeOfPa
[llvm-branch-commits] [clang] [clang] fix transformation of subst constant template parameter nodes (PR #160777)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) Changes This simplifies those transforms a lot, removing a bunch of workarounds which were introducing problems. The transforms become independent of the template instantiator, so they are moved to TreeTransform instead. Fixes #131342 --- Patch is 27.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/160777.diff 13 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/AST/ExprCXX.h (+1-1) - (modified) clang/include/clang/AST/TypeBase.h (+3-1) - (modified) clang/include/clang/Sema/Sema.h (+17) - (modified) clang/lib/AST/ExprCXX.cpp (+2-2) - (modified) clang/lib/AST/StmtProfile.cpp (+2-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+34) - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+19-184) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+10-13) - (modified) clang/lib/Sema/TreeTransform.h (+55-12) - (modified) clang/test/SemaCXX/ctad.cpp (+7) - (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+1-1) - (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp (+11) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 703fe2ab35af3..99ca301f54a57 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -361,6 +361,7 @@ Bug Fixes in This Version first parameter. (#GH113323). - Fixed a crash with incompatible pointer to integer conversions in designated initializers involving string literals. (#GH154046) +- Fix crash on CTAD for alias template. (#GH131342) - Clang now emits a frontend error when a function marked with the `flatten` attribute calls another function that requires target features not enabled in the caller. This prevents a fatal error in the backend. diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 9fedb230ce397..5f16bac94d5e6 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -4714,7 +4714,7 @@ class SubstNonTypeTemplateParmExpr : public Expr { // sugared: it doesn't need to be resugared later. bool getFinal() const { return Final; } - NamedDecl *getParameter() const; + NonTypeTemplateParmDecl *getParameter() const; bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); } diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h index b02d9c7499fe5..e0d00b82f2b76 100644 --- a/clang/include/clang/AST/TypeBase.h +++ b/clang/include/clang/AST/TypeBase.h @@ -3495,7 +3495,9 @@ class AdjustedType : public Type, public llvm::FoldingSetNode { AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr) - : Type(TC, CanonicalPtr, OriginalTy->getDependence()), + : Type(TC, CanonicalPtr, + AdjustedTy->getDependence() | + (OriginalTy->getDependence() & ~TypeDependence::Dependent)), OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {} public: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 5edfc29d93781..2bd6be2a32cd5 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11714,6 +11714,23 @@ class Sema final : public SemaBase { const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand); + UnsignedOrNone getPackIndex(TemplateArgument Pack) const { +return Pack.pack_size() - 1 - *ArgPackSubstIndex; + } + + TemplateArgument + getPackSubstitutedTemplateArgument(TemplateArgument Arg) const { +Arg = Arg.pack_elements()[*ArgPackSubstIndex]; +if (Arg.isPackExpansion()) + Arg = Arg.getPackExpansionPattern(); +return Arg; + } + + ExprResult BuildSubstNonTypeTemplateParmExpr( + Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP, + SourceLocation loc, TemplateArgument Replacement, + UnsignedOrNone PackIndex, bool Final); + /// Form a template name from a name that is syntactically required to name a /// template, either due to use of the 'template' keyword or because a name in /// this syntactic context is assumed to name a template (C++ diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index 97ae4a07f32aa..95de6a82a5270 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -1725,8 +1725,8 @@ SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context, return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs); } -NamedDecl *SubstNonTypeTemplateParmExpr::getParameter() const { - return cast( +NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const { + return cast( getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]); } diff --git a/clang/lib/AST/StmtProfile.cpp b/cla
[llvm-branch-commits] [clang] [llvm] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -212,7 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), - }; + ConstantAsMetadata::get(Builder.getInt32(0))}; joaosaffran wrote: This is a temporary fix, I am working on the frontend changes in a different PR. https://github.com/llvm/llvm-project/pull/160210 ___ 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] port 5b4819e to release (PR #159209)
https://github.com/dwblaikie updated https://github.com/llvm/llvm-project/pull/159209 >From 0c9d972fae57b4af2712632d829ed042381ab9ab Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 16 Sep 2025 22:42:55 + Subject: [PATCH] Port 5b4819e to release/21.x Fix for the port of 665e875 to release/21.x in PR156664 --- clang/test/CodeGenCXX/debug-info-structured-binding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp index 4a4a4d8bdfaad..8032ce85c9e25 100644 --- a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp +++ b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp @@ -10,7 +10,7 @@ // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y1_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw %struct.A, ptr {{.*}}, i32 0, i32 1, !dbg ![[Y2_DEBUG_LOC:[0-9]+]] // CHECK: load ptr, ptr %z2, {{.*}}!dbg ![[Z2_DEBUG_LOC:[0-9]+]] -// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i64 0, i64 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] +// CHECK: getelementptr inbounds [2 x i32], ptr {{.*}}, i{{64|32}} 0, i{{64|32}} 1, !dbg ![[A2_DEBUG_LOC:[0-9]+]] // CHECK: getelementptr inbounds nuw { i32, i32 }, ptr {{.*}}, i32 0, i32 1, !dbg ![[C2_DEBUG_LOC:[0-9]+]] // CHECK: extractelement <2 x i32> {{.*}}, i32 1, !dbg ![[V2_DEBUG_LOC:[0-9]+]] // CHECK: ![[VAR_0]] = !DILocalVariable(name: "a" ___ 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] [mlir][omp] Improve canonloop/iv naming (PR #159773)
@@ -77,6 +77,177 @@ struct LLVMPointerPointerLikeModel }; } // namespace +/// Generate a name of a canonical loop nest of the format +/// `(_s_r)*` that describes its nesting inside parent +/// operations (`_r`) and that operation's region (`_s`). The region +/// number is omitted if the parent operation has just one region. If a loop +/// nest just consists of canonical loops nested inside each other, also uses +/// `d` where is the nesting depth of the loop. +static std::string generateLoopNestingName(StringRef prefix, + CanonicalLoopOp op) { + struct Component { +// An region argument of an operation +Operation *parentOp; +size_t regionInOpIdx; +bool isOnlyRegionInOp; +bool skipRegion; + +// An operation somewhere in a parent region +Operation *thisOp; +Region *parentRegion; +size_t opInRegionIdx; +bool isOnlyOpInRegion; +bool skipOp; +int depth = -1; + }; + SmallVector components; + + // Gather a list of parent regions and operations, and the position within + // their parent + Operation *o = op.getOperation(); + while (o) { +if (o->hasTrait()) + break; + +// Operation within a region +Region *r = o->getParentRegion(); +if (!r) + break; + +llvm::ReversePostOrderTraversal traversal(&r->getBlocks().front()); +size_t idx = 0; +bool found = false; +size_t sequentialIdx = -1; +bool isOnlyLoop = true; +for (Block *b : traversal) { + for (Operation &op : *b) { +if (&op == o && !found) { + sequentialIdx = idx; + found = true; +} +if (op.getNumRegions()) { + idx += 1; + if (idx > 1) +isOnlyLoop = false; +} +if (found && !isOnlyLoop) + break; + } +} + +Component &comp = components.emplace_back(); +comp.thisOp = o; +comp.parentRegion = r; +comp.opInRegionIdx = sequentialIdx; +comp.isOnlyOpInRegion = isOnlyLoop; Meinersbur wrote: > An op containing regions doesn't mean that it is a loop. It could be an if > statement or an openmp block construct etc. Correct, but I think it would be too computationally expensive to look into every region on whether there is a loop in there, so this assumes it could be. If there are multiple operations with regions, they are disambiguated using `_s0`, `_s1`, ..., in case some of them contain loops. > isOnlyOpInRegion == true doesn't mean there aren't other ops in the region; > it means that there aren't other ops containing regions in this region. There is a trade-off between conciseness and descriptiveness in the name. With "Op" I'd understand "relevant Operation". So alternatives could be, `isOnlyOperationWithRegionsInRegion`, `isOnlyRelevantOpInRegion`, `isUnambiguousOpInRegion`, ... . Any preference? https://github.com/llvm/llvm-project/pull/159773 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Updating DXContainer logic to read version 1.2 of static samplers (PR #160184)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160184 >From fefd58c2ab1044ac51c546b6bc6df968eb5edaa8 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Fri, 19 Sep 2025 12:48:11 -0700 Subject: [PATCH 1/8] fix test --- llvm/include/llvm/Object/DXContainer.h| 57 --- llvm/lib/ObjectYAML/DXContainerYAML.cpp | 16 ++- llvm/unittests/Object/DXContainerTest.cpp | 16 --- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h index 9bc1918852335..e3e532f6635a4 100644 --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -123,25 +123,26 @@ template struct ViewArray { }; namespace DirectX { + +template Expected readParameter(StringRef Data) { + T Struct; + if (sizeof(T) != Data.size()) +return make_error( +"Reading structure out of file bounds", object_error::parse_failed); + + memcpy(&Struct, Data.data(), sizeof(T)); + // DXContainer is always little endian + if (sys::IsBigEndianHost) +Struct.swapBytes(); + return Struct; +} + struct RootParameterView { const dxbc::RTS0::v1::RootParameterHeader &Header; StringRef ParamData; RootParameterView(const dxbc::RTS0::v1::RootParameterHeader &H, StringRef P) : Header(H), ParamData(P) {} - - template Expected readParameter() { -T Struct; -if (sizeof(T) != ParamData.size()) - return make_error( - "Reading structure out of file bounds", object_error::parse_failed); - -memcpy(&Struct, ParamData.data(), sizeof(T)); -// DXContainer is always little endian -if (sys::IsBigEndianHost) - Struct.swapBytes(); -return Struct; - } }; struct RootConstantView : RootParameterView { @@ -151,7 +152,7 @@ struct RootConstantView : RootParameterView { } llvm::Expected read() { -return readParameter(); +return readParameter(ParamData); } }; @@ -167,7 +168,8 @@ struct RootDescriptorView : RootParameterView { llvm::Expected read(uint32_t Version) { if (Version == 1) { - auto Descriptor = readParameter(); + auto Descriptor = + readParameter(ParamData); if (Error E = Descriptor.takeError()) return E; return dxbc::RTS0::v2::RootDescriptor(*Descriptor); @@ -176,9 +178,10 @@ struct RootDescriptorView : RootParameterView { return make_error("Invalid Root Signature version: " + Twine(Version), object_error::parse_failed); -return readParameter(); +return readParameter(ParamData); } }; + template struct DescriptorTable { uint32_t NumRanges; uint32_t RangesOffset; @@ -247,8 +250,26 @@ class RootSignature { llvm::iterator_range param_headers() const { return llvm::make_range(ParametersHeaders.begin(), ParametersHeaders.end()); } - llvm::iterator_range samplers() const { -return llvm::make_range(StaticSamplers.begin(), StaticSamplers.end()); + llvm::Expected getSampler(uint32_t Loc) const { +if (Loc >= getNumStaticSamplers()) + return parseFailed("Static sampler index out of range"); + +auto SamplerSize = (Version <= 2) ? sizeof(dxbc::RTS0::v1::StaticSampler) + : sizeof(dxbc::RTS0::v3::StaticSampler); + +StringRef Buff = PartData.substr(StaticSamplersOffset + (Loc * SamplerSize), + SamplerSize); +if (Version < 3) { + auto Sampler = readParameter(Buff); + if (Error E = Sampler.takeError()) +return E; + return dxbc::RTS0::v3::StaticSampler(*Sampler); +} +if (Version != 3) + return make_error("Invalid Root Signature version: " + +Twine(Version), +object_error::parse_failed); +return readParameter(Buff); } uint32_t getFlags() const { return Flags; } diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp index 42074731c4e16..6f24b7d2573ec 100644 --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -163,7 +163,13 @@ DXContainerYAML::RootSignatureYamlDesc::create( } } - for (const auto &S : Data.samplers()) { + for (uint32_t Loc = 0; Loc < Data.getNumStaticSamplers(); ++Loc) { +llvm::Expected MaybeSampler = +Data.getSampler(Loc); +if (Error E = MaybeSampler.takeError()) + return std::move(E); +const llvm::dxbc::RTS0::v3::StaticSampler &S = *MaybeSampler; + if (!dxbc::isValidSamplerFilter(S.Filter)) return createStringError(std::errc::invalid_argument, "Invalid value for static sampler filter"); @@ -209,6 +215,14 @@ DXContainerYAML::RootSignatureYamlDesc::create( NewS.RegisterSpace = S.RegisterSpace; NewS.Shad
[llvm-branch-commits] [flang] [flang][OpenMP] Use OmpDirectiveSpecification in REQUIRES (PR #160595)
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/160595 >From 0434e253c1174249f387825527c5cde7414e4d40 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 24 Sep 2025 15:11:43 -0500 Subject: [PATCH] [flang][OpenMP] Use OmpDirectiveSpecification in REQUIRES --- flang/include/flang/Parser/openmp-utils.h | 4 +-- flang/include/flang/Parser/parse-tree.h | 3 +- flang/lib/Parser/openmp-parsers.cpp | 4 ++- flang/lib/Parser/unparse.cpp| 6 ++-- flang/lib/Semantics/check-omp-structure.cpp | 11 ++- flang/lib/Semantics/resolve-directives.cpp | 2 +- flang/test/Parser/OpenMP/requires.f90 | 33 + 7 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 flang/test/Parser/OpenMP/requires.f90 diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index 77c31b939e522..b8f3559097750 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -41,7 +41,6 @@ struct ConstructId { MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate); MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction); MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate); -MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires); #undef MAKE_CONSTR_ID @@ -94,8 +93,7 @@ struct DirectiveNameScope { return std::get(x.t).DirName(); } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || - std::is_same_v) { + std::is_same_v) { return MakeName(std::get(x.t).source, ConstructId::id); } else { return GetFromTuple( diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index bd55166eb9f80..8b23189bc1e90 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -4991,9 +4991,8 @@ struct OpenMPGroupprivate { // 2.4 requires -> REQUIRES requires-clause[ [ [,] requires-clause]...] struct OpenMPRequiresConstruct { - TUPLE_CLASS_BOILERPLATE(OpenMPRequiresConstruct); + WRAPPER_CLASS_BOILERPLATE(OpenMPRequiresConstruct, OmpDirectiveSpecification); CharBlock source; - std::tuple t; }; // 2.15.2 threadprivate -> THREADPRIVATE (variable-name-list) diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 5fd3c1768a17f..ea09fe04f07a0 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1836,7 +1836,9 @@ TYPE_PARSER(sourced( // // 2.4 Requires construct TYPE_PARSER(sourced(construct( -verbatim("REQUIRES"_tok), Parser{}))) +predicated(OmpDirectiveNameParser{}, +IsDirective(llvm::omp::Directive::OMPD_requires)) >= +Parser{}))) // 2.15.2 Threadprivate directive TYPE_PARSER(sourced( // diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index 9812a656092ac..0fbd347e91b18 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2594,10 +2594,10 @@ class UnparseVisitor { Put("\n"); EndOpenMP(); } - void Unparse(const OpenMPRequiresConstruct &y) { + void Unparse(const OpenMPRequiresConstruct &x) { BeginOpenMP(); -Word("!$OMP REQUIRES "); -Walk(std::get(y.t)); +Word("!$OMP "); +Walk(x.v); Put("\n"); EndOpenMP(); } diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp index 6538e0b794791..223523f2a46ff 100644 --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -624,10 +624,6 @@ template struct DirectiveSpellingVisitor { checker_(x.v.DirName().source, Directive::OMPD_groupprivate); return false; } - bool Pre(const parser::OpenMPRequiresConstruct &x) { -checker_(std::get(x.t).source, Directive::OMPD_requires); -return false; - } bool Pre(const parser::OmpBeginDirective &x) { checker_(x.DirName().source, x.DirId()); return false; @@ -1498,14 +1494,13 @@ void OmpStructureChecker::Leave(const parser::OpenMPDepobjConstruct &x) { } void OmpStructureChecker::Enter(const parser::OpenMPRequiresConstruct &x) { - const auto &dir{std::get(x.t)}; - PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_requires); + const auto &dirName{x.v.DirName()}; + PushContextAndClauseSets(dirName.source, dirName.v); if (visitedAtomicSource_.empty()) { return; } - const auto &clauseList{std::get(x.t)}; - for (const parser::OmpClause &clause : clauseList.v) { + for (const parser::OmpClause &clause : x.v.Clauses().v) { llvm::omp::Clause id{clause.Id()}; if (id == llvm::omp::Clause::OMPC_atomic_default_mem_order) { parser::MessageFormattedText txt( diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 7ef211c8b428c..a4c8922f58c6c
[llvm-branch-commits] [mlir] [mlir][omp] Improve canonloop/iv naming (PR #159773)
@@ -77,6 +77,177 @@ struct LLVMPointerPointerLikeModel }; } // namespace +/// Generate a name of a canonical loop nest of the format +/// `(_s_r)*` that describes its nesting inside parent +/// operations (`_r`) and that operation's region (`_s`). The region +/// number is omitted if the parent operation has just one region. If a loop +/// nest just consists of canonical loops nested inside each other, also uses +/// `d` where is the nesting depth of the loop. +static std::string generateLoopNestingName(StringRef prefix, + CanonicalLoopOp op) { + struct Component { +// An region argument of an operation +Operation *parentOp; +size_t regionInOpIdx; +bool isOnlyRegionInOp; +bool skipRegion; + +// An operation somewhere in a parent region +Operation *thisOp; +Region *parentRegion; +size_t opInRegionIdx; +bool isOnlyOpInRegion; +bool skipOp; +int depth = -1; + }; + SmallVector components; + + // Gather a list of parent regions and operations, and the position within + // their parent + Operation *o = op.getOperation(); + while (o) { +if (o->hasTrait()) + break; + +// Operation within a region +Region *r = o->getParentRegion(); +if (!r) Meinersbur wrote: A freshly create operation is not yet in any region/block. There is also `Operation::remove` to remove an operation from a region/block. There might be situations such as calling `dump()` on it, when it is not (yet) connected to a parent region. https://github.com/llvm/llvm-project/pull/159773 ___ 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] [PowerPC] Implement Elliptic Curve Cryptography (ECC) Instructions (PR #158362)
https://github.com/lei137 updated https://github.com/llvm/llvm-project/pull/158362 >From 61cbc3eeb7c7aedcb6008a54a2e988c4cceaf2cc Mon Sep 17 00:00:00 2001 From: Lei Huang Date: Tue, 23 Sep 2025 10:53:45 -0500 Subject: [PATCH] [PowerPC] Implement Elliptic Curve Cryptography (ECC) Instructions New instructions added: * xxmulmul * xxmulmulhiadd * xxmulmulloadd * xxssumudm * xxssumudmc * xxssumudmcext * xsaddadduqm * xsaddaddsuqm * xsaddsubuqm * xsaddsubsuqm * xsmerge2t1uqm * xsmerge2t2uqm * xsmerge2t3uqm * xsmerge3t1uqm * xsrebase2t1uqm * xsrebase2t2uqm * xsrebase2t3uqm * xsrebase2t4uqm * xsrebase3t1uqm * xsrebase3t2uqm * xsrebase3t3uqm --- llvm/lib/Target/PowerPC/PPCInstrFuture.td | 167 ++ .../PowerPC/ppc-encoding-ISAFuture.txt| 57 ++ .../PowerPC/ppc64le-encoding-ISAFuture.txt| 57 ++ llvm/test/MC/PowerPC/ppc-encoding-ISAFuture.s | 78 4 files changed, 359 insertions(+) diff --git a/llvm/lib/Target/PowerPC/PPCInstrFuture.td b/llvm/lib/Target/PowerPC/PPCInstrFuture.td index 9acc3ca7ed788..87ace139bfeb0 100644 --- a/llvm/lib/Target/PowerPC/PPCInstrFuture.td +++ b/llvm/lib/Target/PowerPC/PPCInstrFuture.td @@ -202,6 +202,109 @@ class XX3Form_XTAB6 opcode, bits<8> xo, dag OOL, dag IOL, string asmstr, let Inst{31} = XT{5}; } +class XX3Form_XTAB6_S xo, dag OOL, dag IOL, string asmstr, + list pattern> +: I<59, OOL, IOL, asmstr, NoItinerary> { + bits<6> XT; + bits<6> XA; + bits<6> XB; + + let Pattern = pattern; + + let Inst{6...10} = XT{4...0}; + let Inst{11...15} = XA{4...0}; + let Inst{16...20} = XB{4...0}; + let Inst{24...28} = xo; + let Inst{29} = XA{5}; + let Inst{30} = XB{5}; + let Inst{31} = XT{5}; +} + +class XX3Form_XTAB6_S3 xo, dag OOL, dag IOL, string asmstr, + list pattern> +: XX3Form_XTAB6_S { + + bits<3> S; + let Inst{21...23} = S; +} + +class XX3Form_XTAB6_3S1 xo, dag OOL, dag IOL, string asmstr, + list pattern> +: XX3Form_XTAB6_S { + + bits<1> S0; + bits<1> S1; + bits<1> S2; + + let Inst{21} = S0; + let Inst{22} = S1; + let Inst{23} = S2; +} + +class XX3Form_XTAB6_2S1 xo, dag OOL, dag IOL, string asmstr, + list pattern> +: XX3Form_XTAB6_S { + + bits<1> S1; + bits<1> S2; + + let Inst{21} = 0; + let Inst{22} = S1; + let Inst{23} = S2; +} + +class XX3Form_XTAB6_P xo, dag OOL, dag IOL, string asmstr, + list pattern> +: I<59, OOL, IOL, asmstr, NoItinerary> { + + bits<6> XT; + bits<6> XA; + bits<6> XB; + bits<1> P; + + let Pattern = pattern; + + let Inst{6...10} = XT{4...0}; + let Inst{11...15} = XA{4...0}; + let Inst{16...20} = XB{4...0}; + let Inst{21} = P; + let Inst{22...28} = xo; + let Inst{29} = XA{5}; + let Inst{30} = XB{5}; + let Inst{31} = XT{5}; +} + +class 8RR_XX4Form_XTABC6_P opcode, bits<1> xo, dag OOL, dag IOL, + string asmstr, InstrItinClass itin, list pattern> + : PI<1, opcode, OOL, IOL, asmstr, itin> { + bits<6> XT; + bits<6> XA; + bits<6> XB; + bits<6> XC; + bits<1> P; + + let Pattern = pattern; + + // The prefix. + let Inst{6...7} = 1; + let Inst{8...11} = 0; + let Inst{12...13} = 0; + let Inst{14...31} = 0; + + // The instruction. + let Inst{38...42} = XT{4...0}; + let Inst{43...47} = XA{4...0}; + let Inst{48...52} = XB{4...0}; + let Inst{53...57} = XC{4...0}; + let Inst{58} = xo; + let Inst{59} = P; + let Inst{60} = XC{5}; + let Inst{61} = XA{5}; + let Inst{62} = XB{5}; + let Inst{63} = XT{5}; +} + + //-- Instruction definitions -// // Predicate combinations available: // [IsISAFuture] @@ -314,6 +417,70 @@ let Predicates = [HasVSX, IsISAFuture] in { "xvmulhuw $XT, $XA, $XB", []>; def XVMULHUH: XX3Form_XTAB6<60, 122, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB), "xvmulhuh $XT, $XA, $XB", []>; + + // Elliptic Curve Cryptography Acceleration Instructions. + def XXMULMUL + : XX3Form_XTAB6_S3<1, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u3imm:$S), + "xxmulmul $XT, $XA, $XB, $S", []>; + def XXMULMULHIADD + : XX3Form_XTAB6_3S1<9, (outs vsrc:$XT), + (ins vsrc:$XA, vsrc:$XB, u1imm:$S0, u1imm:$S1, + u1imm:$S2), + "xxmulmulhiadd $XT, $XA, $XB, $S0, $S1, $S2", []>; + def XXMULMULLOADD + : XX3Form_XTAB6_2S1<17, (outs vsrc:$XT), + (ins vsrc:$XA, vsrc:$XB, u1imm:$S1, u1imm:$S2), + "xxmulmulloadd $XT, $XA, $XB, $S1, $S2", []>; + def XXSSUMUDM + : XX3Form_XTAB6_P<25, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u1imm:$P), +"xxssumudm $XT, $XA, $XB, $P", []>; + def XXSSUMUDMC + : XX3Form_XTAB6_P<57, (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u1imm:$P), +
[llvm-branch-commits] [clang] [clang] fix transformation of subst constant template parameter nodes (PR #160777)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/160777 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -212,7 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), - }; + ConstantAsMetadata::get(Builder.getInt32(0))}; inbelic wrote: Note: we should probably stack the frontend changes to go in before this so that we avoid this temporary state https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -0,0 +1,42 @@ +; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s +; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC + +target triple = "dxil-unknown-shadermodel6.0-compute" + +; CHECK: @dx.rts0 = private constant [248 x i8] c"{{.*}}", section "RTS0", align 4 + +define void @main() #0 { +entry: + ret void +} +attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } + + +!dx.rootsignatures = !{!2} ; list of function/root signature pairs +!2 = !{ ptr @main, !3, i32 3 } ; function, root signature +!3 = !{ !5, !6, !7, !8 } ; list of root signature elements +!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 1 } +!6 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 43, i32 0, i32 0, i32 2 } +!7 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 44, i32 0, i32 0, i32 0 } +!8 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 45, i32 0, i32 0, i32 3 } + +; DXC: - Name:RTS0 +; DXC-NEXT: Size:248 +; DXC-NEXT: RootSignature: +; DXC-NEXT: Version: 3 +; DXC-NEXT: NumRootParameters: 0 +; DXC-NEXT: RootParametersOffset: 24 +; DXC-NEXT: NumStaticSamplers: 4 +; DXC-NEXT: StaticSamplersOffset: 24 +; DXC-NEXT: Parameters: [] +; DXC-NEXT: Samplers: +; DXC-LABEL: ShaderRegister: 42 inbelic wrote: nit: I think `DXC-NEXT` is more strict and generally preferred. Is there a reason to use label over that? https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/inbelic edited https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
inbelic wrote: Should we also have testing of an invalid value? I think it makes sense to include the basic verifications in this pr https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/inbelic commented: I do think we should add the basic verifications in this pr, and probably change the stack order so that the front-end changes happen first. Otherwise, this is looking good to me https://github.com/llvm/llvm-project/pull/160210 ___ 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] [LoopUnroll] Fix block frequencies for epilogue (PR #159163)
https://github.com/jdenny-ornl updated https://github.com/llvm/llvm-project/pull/159163 >From 5a9959313c0aebc1c707d19e30055cb925be7760 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Tue, 16 Sep 2025 16:03:11 -0400 Subject: [PATCH 1/3] [LoopUnroll] Fix block frequencies for epilogue As another step in issue #135812, this patch fixes block frequencies for partial loop unrolling with an epilogue remainder loop. It does not fully handle the case when the epilogue loop itself is unrolled. That will be handled in the next patch. For the guard and latch of each of the unrolled loop and epilogue loop, this patch sets branch weights derived directly from the original loop latch branch weights. The total frequency of the original loop body, summed across all its occurrences in the unrolled loop and epilogue loop, is the same as in the original loop. This patch also sets `llvm.loop.estimated_trip_count` for the epilogue loop instead of relying on the epilogue's latch branch weights to imply it. This patch removes the XFAIL directives that PR #157754 added to the test suite. --- .../include/llvm/Transforms/Utils/LoopUtils.h | 32 .../llvm/Transforms/Utils/UnrollLoop.h| 4 +- llvm/lib/Transforms/Utils/LoopUnroll.cpp | 31 ++-- .../Transforms/Utils/LoopUnrollRuntime.cpp| 94 -- llvm/lib/Transforms/Utils/LoopUtils.cpp | 48 ++ .../branch-weights-freq/unroll-epilog.ll | 160 ++ .../runtime-exit-phi-scev-invalidation.ll | 4 +- .../LoopUnroll/runtime-loop-branchweight.ll | 56 +- .../Transforms/LoopUnroll/runtime-loop.ll | 9 +- .../LoopUnroll/unroll-heuristics-pgo.ll | 64 +-- 10 files changed, 448 insertions(+), 54 deletions(-) create mode 100644 llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h index c5dbb2bdd1dd8..71754b8f62a16 100644 --- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h +++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h @@ -365,6 +365,38 @@ LLVM_ABI bool setLoopEstimatedTripCount( Loop *L, unsigned EstimatedTripCount, std::optional EstimatedLoopInvocationWeight = std::nullopt); +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation is unable to handle the loop form +/// of \p L (e.g., \p L must have a latch block that controls the loop exit). +/// - Else, the estimated probability that, at the end of any iteration, the +/// latch of \p L will start another iteration. The result \c P is such that +/// `0 <= P <= 1`, and `1 - P` is the probability of exiting the loop. +std::optional getLoopProbability(Loop *L); + +/// Set branch weight metadata for the latch of \p L to indicate that, at the +/// end of any iteration, its estimated probability of starting another +/// iteration is \p P. Return false if the implementation is unable to handle +/// the loop form of \p L (e.g., \p L must have a latch block that controls the +/// loop exit). Otherwise, return true. +bool setLoopProbability(Loop *L, double P); + +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation cannot extract the probability +/// (e.g., \p B must have exactly two target labels, so it must be a +/// conditional branch). +/// - The probability \c P that control flows from \p B to its first target +/// label such that `1 - P` is the probability of control flowing to its +/// second target label, or vice-versa if \p ForFirstTarget is false. +std::optional getBranchProbability(BranchInst *B, bool ForFirstTarget); + +/// Set branch weight metadata for \p B to indicate that \p P and `1 - P` are +/// the probabilities of control flowing to its first and second target labels, +/// respectively, or vice-versa if \p ForFirstTarget is false. Return false if +/// the implementation cannot set the probability (e.g., \p B must have exactly +/// two target labels, so it must be a conditional branch). Otherwise, return +/// true. +bool setBranchProbability(BranchInst *B, double P, bool ForFirstTarget); + /// Check inner loop (L) backedge count is known to be invariant on all /// iterations of its outer loop. If the loop has no parent, this is trivially /// true. diff --git a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h index 871c13d972470..571a0af6fd0db 100644 --- a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h +++ b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h @@ -97,7 +97,9 @@ LLVM_ABI bool UnrollRuntimeLoopRemainder( LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const TargetTransformInfo *TTI, bool PreserveLCSSA, unsigned SCEVExpansionBudget, bool RuntimeUnrollMultiExit, -Loop **ResultLoop = nullptr); +Loop **ResultLoop = nullptr, +std::optional OriginalTripCount = std::nullopt,
[llvm-branch-commits] [llvm] [AllocToken] Introduce AllocToken instrumentation pass (PR #156838)
@@ -0,0 +1,469 @@ +//===- AllocToken.cpp - Allocation token instrumentation --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements AllocToken, an instrumentation pass that +// replaces allocation calls with token-enabled versions. +// +//===--===// + +#include "llvm/Transforms/Instrumentation/AllocToken.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/IR/Analysis.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/IR/Type.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/RandomNumberGenerator.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/xxhash.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace llvm; + +#define DEBUG_TYPE "alloc-token" + +namespace { + +//===--- Constants ===// + +enum class TokenMode : unsigned { + /// Incrementally increasing token ID. + Increment = 0, + + /// Simple mode that returns a statically-assigned random token ID. + Random = 1, + + /// Token ID based on allocated type hash. + TypeHash = 2, +}; + +//===--- Command-line options -===// + +cl::opt +ClMode("alloc-token-mode", cl::Hidden, cl::desc("Token assignment mode"), + cl::init(TokenMode::TypeHash), + cl::values(clEnumValN(TokenMode::Increment, "increment", + "Incrementally increasing token ID"), + clEnumValN(TokenMode::Random, "random", + "Statically-assigned random token ID"), + clEnumValN(TokenMode::TypeHash, "typehash", + "Token ID based on allocated type hash"))); + +cl::opt ClFuncPrefix("alloc-token-prefix", + cl::desc("The allocation function prefix"), + cl::Hidden, cl::init("__alloc_token_")); + +cl::opt ClMaxTokens("alloc-token-max", + cl::desc("Maximum number of tokens (0 = no max)"), + cl::Hidden, cl::init(0)); + +cl::opt +ClFastABI("alloc-token-fast-abi", + cl::desc("The token ID is encoded in the function name"), + cl::Hidden, cl::init(false)); + +// Instrument libcalls only by default - compatible allocators only need to take +// care of providing standard allocation functions. With extended coverage, also +// instrument non-libcall allocation function calls with !alloc_token +// metadata. +cl::opt +ClExtended("alloc-token-extended", + cl::desc("Extend coverage to custom allocation functions"), + cl::Hidden, cl::init(false)); + +// C++ defines ::operator new (and variants) as replaceable (vs. standard +// library versions), which are nobuiltin, and are therefore not covered by +// isAllocationFn(). Cover by default, as users of AllocToken are already +// required to provide token-aware allocation functions (no defaults). +cl::opt ClCoverReplaceableNew("alloc-token-cover-replaceable-new", +cl::desc("Cover replaceable operator new"), +cl::Hidden, cl::init(true)); + +cl::opt ClFallbackToken( +"alloc-token-fallback", +cl::desc("The default fallback token where none could be determined"), +cl::Hidden, cl::init(0)); + +//===--- Statistics ---===// + +STATISTIC(NumFunctionsInstrumented, "Functions instrumented"); +STATISTIC(NumAllocationsInstrumented, "Allocations instrumented"); + +//===--===// + +/// Returns the !alloc_token metadata if available. +/// +/// Expected format is: !{} +MDNode *getAllocTokenMetadata(const
[llvm-branch-commits] [clang] [llvm] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -0,0 +1,43 @@ +; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s +; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC + +target triple = "dxil-unknown-shadermodel6.0-compute" + +; CHECK: @dx.rts0 = private constant [80 x i8] c"{{.*}}", section "RTS0", align 4 + +define void @main() #0 { +entry: + ret void +} +attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } + + +!dx.rootsignatures = !{!2} ; list of function/root signature pairs +!2 = !{ ptr @main, !3, i32 3 } ; function, root signature +!3 = !{ !5 } ; list of root signature elements +!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 1 } inbelic wrote: I think we should have a test for the other valid flag and also when their or'd value is specified. Is it allowed to have both flags set at the same time? https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/bogner edited https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -0,0 +1,42 @@ +; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s +; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC + +target triple = "dxil-unknown-shadermodel6.0-compute" + +; CHECK: @dx.rts0 = private constant [248 x i8] c"{{.*}}", section "RTS0", align 4 + +define void @main() #0 { +entry: + ret void +} +attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } + + +!dx.rootsignatures = !{!2} ; list of function/root signature pairs +!2 = !{ ptr @main, !3, i32 3 } ; function, root signature +!3 = !{ !5, !6, !7, !8 } ; list of root signature elements +!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 1 } +!6 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 43, i32 0, i32 0, i32 2 } +!7 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 44, i32 0, i32 0, i32 0 } +!8 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 45, i32 0, i32 0, i32 3 } + +; DXC: - Name:RTS0 +; DXC-NEXT: Size:248 +; DXC-NEXT: RootSignature: +; DXC-NEXT: Version: 3 +; DXC-NEXT: NumRootParameters: 0 +; DXC-NEXT: RootParametersOffset: 24 +; DXC-NEXT: NumStaticSamplers: 4 +; DXC-NEXT: StaticSamplersOffset: 24 +; DXC-NEXT: Parameters: [] +; DXC-NEXT: Samplers: +; DXC-LABEL: ShaderRegister: 42 bogner wrote: `CHECK-LABEL` isn't correct here - that's for dividing checks into logical blocks (ie, you might use it to find the beginning of a function, or something to that effect). Just using a `CHECK` (ie, `DXC: `) would make more sense if we don't want to check every line. https://github.com/llvm/llvm-project/pull/160210 ___ 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] [mlir][omp] Improve canonloop/iv naming (PR #159773)
Meinersbur wrote: > It would be good to try testing the _r names as well, even if you have to > (ab)use an unrelated operation to do it. Do you have a suggestion which operation? Need to be an operation that takes at least two region arguments. https://github.com/llvm/llvm-project/pull/159773 ___ 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] [openmp] [OpenMP] Taskgraph Clang 'record and replay' frontend support (PR #159774)
https://github.com/alexey-bataev commented: clang unit tests (parsing, sema, codegen) are required. Also, need to update OpenMP.rst and ReleseNotes docs https://github.com/llvm/llvm-project/pull/159774 ___ 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] [openmp] [OpenMP] Taskgraph Clang 'record and replay' frontend support (PR #159774)
@@ -5954,6 +5976,48 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc, Region->emitUntiedSwitch(CGF); } +void CGOpenMPRuntime::emitTaskgraphCall(CodeGenFunction &CGF, +SourceLocation Loc, +const OMPExecutableDirective &D) { + if (!CGF.HaveInsertPoint()) +return; + + // Building kmp_taskgraph_flags_t flags for kmpc_taskgraph. C.f., kmp.h + enum { +NowaitFlag = 0x1, // Not used yet. +ReRecordFlag = 0x2, + }; + + unsigned Flags = 0; + + CodeGenFunction OutlinedCGF(CGM, /*suppressNewContext=*/true); + + const auto *CS = cast(D.getAssociatedStmt()); + + auto BodyGen = [CS](CodeGenFunction &CGF, PrePostActionTy &) { +CGF.EmitStmt(CS->getCapturedStmt()); + }; + + LValue CapStruct = CGF.InitCapturedStruct(*CS); + CGOpenMPTaskgraphRegionInfo TaskgraphRegion(*CS, BodyGen); + CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(OutlinedCGF, + &TaskgraphRegion); + llvm::Function *FnT = OutlinedCGF.GenerateCapturedStmtFunction(*CS); + + SmallVector Args{ alexey-bataev wrote: Use std::array instead https://github.com/llvm/llvm-project/pull/159774 ___ 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] [openmp] [OpenMP] Taskgraph Clang 'record and replay' frontend support (PR #159774)
@@ -1446,6 +1446,9 @@ def is_unexposed(self): # OpenMP stripe directive. OMP_STRIPE_DIRECTIVE = 310 +# OpenMP taskgraph directive. +OMP_TASKGRAPH_DIRECTIVE = 311 + alexey-bataev wrote: this number is reserved for fuse directive already https://github.com/llvm/llvm-project/pull/159774 ___ 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] [openmp] [OpenMP] Taskgraph Clang 'record and replay' frontend support (PR #159774)
https://github.com/alexey-bataev edited https://github.com/llvm/llvm-project/pull/159774 ___ 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/21.x: [SCEV] Don't perform implication checks with many predicates (#158652) (PR #158798)
https://github.com/fhahn approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/158798 ___ 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] [AllocToken] Introduce AllocToken instrumentation pass (PR #156838)
@@ -0,0 +1,469 @@ +//===- AllocToken.cpp - Allocation token instrumentation --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements AllocToken, an instrumentation pass that +// replaces allocation calls with token-enabled versions. +// +//===--===// + +#include "llvm/Transforms/Instrumentation/AllocToken.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/IR/Analysis.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/IR/Type.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/RandomNumberGenerator.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/xxhash.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace llvm; + +#define DEBUG_TYPE "alloc-token" + +namespace { + +//===--- Constants ===// + +enum class TokenMode : unsigned { + /// Incrementally increasing token ID. + Increment = 0, + + /// Simple mode that returns a statically-assigned random token ID. + Random = 1, + + /// Token ID based on allocated type hash. + TypeHash = 2, +}; + +//===--- Command-line options -===// + +cl::opt +ClMode("alloc-token-mode", cl::Hidden, cl::desc("Token assignment mode"), + cl::init(TokenMode::TypeHash), + cl::values(clEnumValN(TokenMode::Increment, "increment", + "Incrementally increasing token ID"), + clEnumValN(TokenMode::Random, "random", + "Statically-assigned random token ID"), + clEnumValN(TokenMode::TypeHash, "typehash", + "Token ID based on allocated type hash"))); + +cl::opt ClFuncPrefix("alloc-token-prefix", + cl::desc("The allocation function prefix"), + cl::Hidden, cl::init("__alloc_token_")); + +cl::opt ClMaxTokens("alloc-token-max", + cl::desc("Maximum number of tokens (0 = no max)"), + cl::Hidden, cl::init(0)); + +cl::opt +ClFastABI("alloc-token-fast-abi", + cl::desc("The token ID is encoded in the function name"), + cl::Hidden, cl::init(false)); + +// Instrument libcalls only by default - compatible allocators only need to take +// care of providing standard allocation functions. With extended coverage, also +// instrument non-libcall allocation function calls with !alloc_token +// metadata. +cl::opt +ClExtended("alloc-token-extended", + cl::desc("Extend coverage to custom allocation functions"), + cl::Hidden, cl::init(false)); + +// C++ defines ::operator new (and variants) as replaceable (vs. standard +// library versions), which are nobuiltin, and are therefore not covered by +// isAllocationFn(). Cover by default, as users of AllocToken are already +// required to provide token-aware allocation functions (no defaults). +cl::opt ClCoverReplaceableNew("alloc-token-cover-replaceable-new", +cl::desc("Cover replaceable operator new"), +cl::Hidden, cl::init(true)); + +cl::opt ClFallbackToken( +"alloc-token-fallback", +cl::desc("The default fallback token where none could be determined"), +cl::Hidden, cl::init(0)); + +//===--- Statistics ---===// + +STATISTIC(NumFunctionsInstrumented, "Functions instrumented"); +STATISTIC(NumAllocationsInstrumented, "Allocations instrumented"); + +//===--===// + +/// Returns the !alloc_token metadata if available. +/// +/// Expected format is: !{} +MDNode *getAllocTokenMetadata(const
[llvm-branch-commits] [clang] [llvm] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160210 >From 6b191d041990ad667d86b6b07eeed7c802e3fe45 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 22 Sep 2025 15:31:47 -0700 Subject: [PATCH 1/5] adding metadata static sampler flags --- clang/test/CodeGenHLSL/RootSignature.hlsl | 4 +- .../Frontend/HLSL/RootSignatureMetadata.cpp | 14 +- ...gnature-StaticSamplers-Invalid-AddressU.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressV.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressW.ll | 2 +- ...ture-StaticSamplers-Invalid-BorderColor.ll | 2 +- ...e-StaticSamplers-Invalid-ComparisonFunc.ll | 2 +- ...Signature-StaticSamplers-Invalid-Filter.ll | 2 +- ...re-StaticSamplers-Invalid-MaxAnisotropy.ll | 2 +- ...Signature-StaticSamplers-Invalid-MaxLod.ll | 2 +- ...Signature-StaticSamplers-Invalid-MinLod.ll | 2 +- ...ature-StaticSamplers-Invalid-MinLopBias.ll | 2 +- ...re-StaticSamplers-Invalid-RegisterSpace.ll | 2 +- ...e-StaticSamplers-Invalid-ShaderRegister.ll | 2 +- ...StaticSamplers-Invalid-ShaderVisibility.ll | 2 +- .../RootSignature-StaticSamplers.ll | 2 +- .../RootSignature-StaticSamplers_V3.ll| 43 +++ .../rootsignature-validation-fail-sampler.ll | 2 +- ...re-validation-fail-static-sampler-range.ll | 4 +- 19 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers_V3.ll diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl b/clang/test/CodeGenHLSL/RootSignature.hlsl index bc40bdd79ce59..bbab6a73a3658 100644 --- a/clang/test/CodeGenHLSL/RootSignature.hlsl +++ b/clang/test/CodeGenHLSL/RootSignature.hlsl @@ -82,8 +82,8 @@ void RootDescriptorsEntry() {} // checking minLOD, maxLOD // CHECK-SAME: float -1.28e+02, float 1.28e+02, -// checking register, space and visibility -// CHECK-SAME: i32 42, i32 0, i32 0} +// checking register, space, visibility and flags +// CHECK-SAME: i32 42, i32 0, i32 0, i32 0} #define SampleStaticSampler \ "StaticSampler(s42, " \ diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp index f29f2c7602fc6..5ddf129265648 100644 --- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp +++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp @@ -212,6 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), + ConstantAsMetadata::get(Builder.getInt32(0)), }; return MDNode::get(Ctx, Operands); } @@ -411,7 +412,7 @@ Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD, Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, MDNode *StaticSamplerNode) { - if (StaticSamplerNode->getNumOperands() != 14) + if (StaticSamplerNode->getNumOperands() != 15) return make_error("Static Sampler"); mcdxbc::StaticSampler Sampler; @@ -495,6 +496,17 @@ Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, return Error(std::move(E)); Sampler.ShaderVisibility = *Visibility; + if (RSD.Version < 3) { +RSD.StaticSamplers.push_back(Sampler); +return Error::success(); + } + assert(RSD.Version >= 3); + + if (std::optional Val = extractMdIntValue(StaticSamplerNode, 14)) +Sampler.Flags = *Val; + else +return make_error("Static Sampler Flags"); + RSD.StaticSamplers.push_back(Sampler); return Error::success(); } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll index 288dea00b6e55..b043ea1418df6 100644 --- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll +++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll @@ -16,4 +16,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } !dx.rootsignatures = !{!2} ; list of function/root signature pairs !2 = !{ ptr @main, !3, i32 2 } ; function, root signature !3 = !{ !5 } ; list of root signature elements -!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0 } +!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 0 } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll index e9abcf966..8219ffdd679d2 100644 --- a/llvm/test/CodeGen/D
[llvm-branch-commits] [clang] [llvm] [HLSL] Update Frontend to support version 1.2 of root signature (PR #160616)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160616 >From bc393fda07547bbd8abc24701c8bfc3495db2e89 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 22 Sep 2025 16:49:12 -0700 Subject: [PATCH 1/7] adding flags to static sampler parser --- .../clang/Lex/HLSLRootSignatureTokenKinds.def | 8 +++ .../clang/Parse/ParseHLSLRootSignature.h | 3 + clang/lib/Parse/ParseHLSLRootSignature.cpp| 61 +++ .../Lex/LexHLSLRootSignatureTest.cpp | 3 + .../llvm/Frontend/HLSL/HLSLRootSignature.h| 1 + llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 2 +- 6 files changed, 77 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def index a5cfeb34b2b51..1d7f7adbe076f 100644 --- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def +++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def @@ -65,6 +65,9 @@ #ifndef STATIC_BORDER_COLOR_ENUM #define STATIC_BORDER_COLOR_ENUM(NAME, LIT) ENUM(NAME, LIT) #endif +#ifndef STATIC_SAMPLER_FLAG_ENUM +#define STATIC_SAMPLER_FLAG_ENUM(NAME, LIT) ENUM(NAME, LIT) +#endif // General Tokens: TOK(invalid, "invalid identifier") @@ -228,6 +231,10 @@ STATIC_BORDER_COLOR_ENUM(OpaqueWhite, "STATIC_BORDER_COLOR_OPAQUE_WHITE") STATIC_BORDER_COLOR_ENUM(OpaqueBlackUint, "STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT") STATIC_BORDER_COLOR_ENUM(OpaqueWhiteUint, "STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT") +// Root Descriptor Flag Enums: +STATIC_SAMPLER_FLAG_ENUM(UintBorderColor, "UINT_BORDER_COLOR") +STATIC_SAMPLER_FLAG_ENUM(NonNormalizedCoordinates, "NON_NORMALIZED_COORDINATES") + #undef STATIC_BORDER_COLOR_ENUM #undef COMPARISON_FUNC_ENUM #undef TEXTURE_ADDRESS_MODE_ENUM @@ -237,6 +244,7 @@ STATIC_BORDER_COLOR_ENUM(OpaqueWhiteUint, "STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT #undef DESCRIPTOR_RANGE_FLAG_ENUM_OFF #undef DESCRIPTOR_RANGE_FLAG_ENUM_ON #undef ROOT_DESCRIPTOR_FLAG_ENUM +#undef STATIC_SAMPLER_FLAG_ENUM #undef ROOT_FLAG_ENUM #undef DESCRIPTOR_RANGE_OFFSET_ENUM #undef UNBOUNDED_ENUM diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index b06846fd83c09..8f91d7cd7b031 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -130,6 +130,7 @@ class RootSignatureParser { std::optional MaxLOD; std::optional Space; std::optional Visibility; +std::optional Flags; }; std::optional parseStaticSamplerParams(); @@ -153,6 +154,8 @@ class RootSignatureParser { parseRootDescriptorFlags(RootSignatureToken::Kind Context); std::optional parseDescriptorRangeFlags(RootSignatureToken::Kind Context); + std::optional + parseStaticSamplerFlags(RootSignatureToken::Kind Context); /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned /// 32-bit integer diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 3b16efb1f1199..5677365688413 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -485,6 +485,9 @@ std::optional RootSignatureParser::parseStaticSampler() { if (Params->Visibility.has_value()) Sampler.Visibility = Params->Visibility.value(); + if (Params->Flags.has_value()) +Sampler.Flags = Params->Flags.value(); + return Sampler; } @@ -926,6 +929,20 @@ RootSignatureParser::parseStaticSamplerParams() { if (!Visibility.has_value()) return std::nullopt; Params.Visibility = Visibility; +} else if (tryConsumeExpectedToken(TokenKind::kw_flags)) { + // `flags` `=` UINT_BORDER_COLOR + if (Params.Flags.has_value()) { +reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; +return std::nullopt; + } + + if (consumeExpectedToken(TokenKind::pu_equal)) +return std::nullopt; + + auto Flags = parseStaticSamplerFlags(TokenKind::kw_flags); + if (!Flags.has_value()) +return std::nullopt; + Params.Flags = Flags; } else { consumeNextToken(); // let diagnostic be at the start of invalid token reportDiag(diag::err_hlsl_invalid_token) @@ -1255,6 +1272,50 @@ RootSignatureParser::parseDescriptorRangeFlags(TokenKind Context) { return Flags; } +std::optional +RootSignatureParser::parseStaticSamplerFlags(TokenKind Context) { + assert(CurToken.TokKind == TokenKind::pu_equal && + "Expects to only be invoked starting at given keyword"); + + // Handle the edge-case of '0' to specify no flags set + if (tryConsumeExpectedToken(TokenKind::int_literal)) { +if (!verifyZeroFlag()) { + reportDiag(diag::err_hlsl_rootsig_non_zero_flag); + return std::nullopt; +} +return llvm::dxbc::StaticSamplerFlags::None; + } + + TokenKind Expected[] = { +#define STATIC_SAMPLER_FLA
[llvm-branch-commits] [clang] [Clang] Introduce -fsanitize=alloc-token (PR #156839)
@@ -0,0 +1,173 @@ += +Allocation Tokens += + +.. contents:: + :local: + +Introduction + + +Clang provides support for allocation tokens to enable allocator-level heap +organization strategies. Clang assigns mode-dependent token IDs to allocation +calls; the runtime behavior depends entirely on the implementation of a +compatible memory allocator. + +Possible allocator strategies include: + +* **Security Hardening**: Placing allocations into separate, isolated heap + partitions. For example, separating pointer-containing types from raw data + can mitigate exploits that rely on overflowing a primitive buffer to corrupt + object metadata. + +* **Memory Layout Optimization**: Grouping related allocations to improve data + locality and cache utilization. + +* **Custom Allocation Policies**: Applying different management strategies to + different partitions. + +Token Assignment Mode += + +The default mode to calculate tokens is: + +* ``typehash``: This mode assigns a token ID based on the hash of the allocated + type's name. + +Other token ID assignment modes are supported, but they may be subject to +change or removal. These may (experimentally) be selected with ``-mllvm +-alloc-token-mode=``: + +* ``random``: This mode assigns a statically-determined random token ID to each + allocation site. + +* ``increment``: This mode assigns a simple, incrementally increasing token ID + to each allocation site. + +Allocation Token Instrumentation + + +To enable instrumentation of allocation functions, code can be compiled with +the ``-fsanitize=alloc-token`` flag: + +.. code-block:: console + +% clang++ -fsanitize=alloc-token example.cc + +The instrumentation transforms allocation calls to include a token ID. For +example: + +.. code-block:: c + +// Original: +ptr = malloc(size); + +// Instrumented: +ptr = __alloc_token_malloc(size, ); + +In addition, it is typically recommended to configure the following: melver wrote: I guess this is an allocator decision, and this recommendation should come from the allocator that implements support. Updating/removing this comment. https://github.com/llvm/llvm-project/pull/156839 ___ 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] Update Frontend to support version 1.2 of root signature (PR #160616)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160616 >From bc393fda07547bbd8abc24701c8bfc3495db2e89 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 22 Sep 2025 16:49:12 -0700 Subject: [PATCH 1/6] adding flags to static sampler parser --- .../clang/Lex/HLSLRootSignatureTokenKinds.def | 8 +++ .../clang/Parse/ParseHLSLRootSignature.h | 3 + clang/lib/Parse/ParseHLSLRootSignature.cpp| 61 +++ .../Lex/LexHLSLRootSignatureTest.cpp | 3 + .../llvm/Frontend/HLSL/HLSLRootSignature.h| 1 + llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 2 +- 6 files changed, 77 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def index a5cfeb34b2b51..1d7f7adbe076f 100644 --- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def +++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def @@ -65,6 +65,9 @@ #ifndef STATIC_BORDER_COLOR_ENUM #define STATIC_BORDER_COLOR_ENUM(NAME, LIT) ENUM(NAME, LIT) #endif +#ifndef STATIC_SAMPLER_FLAG_ENUM +#define STATIC_SAMPLER_FLAG_ENUM(NAME, LIT) ENUM(NAME, LIT) +#endif // General Tokens: TOK(invalid, "invalid identifier") @@ -228,6 +231,10 @@ STATIC_BORDER_COLOR_ENUM(OpaqueWhite, "STATIC_BORDER_COLOR_OPAQUE_WHITE") STATIC_BORDER_COLOR_ENUM(OpaqueBlackUint, "STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT") STATIC_BORDER_COLOR_ENUM(OpaqueWhiteUint, "STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT") +// Root Descriptor Flag Enums: +STATIC_SAMPLER_FLAG_ENUM(UintBorderColor, "UINT_BORDER_COLOR") +STATIC_SAMPLER_FLAG_ENUM(NonNormalizedCoordinates, "NON_NORMALIZED_COORDINATES") + #undef STATIC_BORDER_COLOR_ENUM #undef COMPARISON_FUNC_ENUM #undef TEXTURE_ADDRESS_MODE_ENUM @@ -237,6 +244,7 @@ STATIC_BORDER_COLOR_ENUM(OpaqueWhiteUint, "STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT #undef DESCRIPTOR_RANGE_FLAG_ENUM_OFF #undef DESCRIPTOR_RANGE_FLAG_ENUM_ON #undef ROOT_DESCRIPTOR_FLAG_ENUM +#undef STATIC_SAMPLER_FLAG_ENUM #undef ROOT_FLAG_ENUM #undef DESCRIPTOR_RANGE_OFFSET_ENUM #undef UNBOUNDED_ENUM diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index b06846fd83c09..8f91d7cd7b031 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -130,6 +130,7 @@ class RootSignatureParser { std::optional MaxLOD; std::optional Space; std::optional Visibility; +std::optional Flags; }; std::optional parseStaticSamplerParams(); @@ -153,6 +154,8 @@ class RootSignatureParser { parseRootDescriptorFlags(RootSignatureToken::Kind Context); std::optional parseDescriptorRangeFlags(RootSignatureToken::Kind Context); + std::optional + parseStaticSamplerFlags(RootSignatureToken::Kind Context); /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned /// 32-bit integer diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 3b16efb1f1199..5677365688413 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -485,6 +485,9 @@ std::optional RootSignatureParser::parseStaticSampler() { if (Params->Visibility.has_value()) Sampler.Visibility = Params->Visibility.value(); + if (Params->Flags.has_value()) +Sampler.Flags = Params->Flags.value(); + return Sampler; } @@ -926,6 +929,20 @@ RootSignatureParser::parseStaticSamplerParams() { if (!Visibility.has_value()) return std::nullopt; Params.Visibility = Visibility; +} else if (tryConsumeExpectedToken(TokenKind::kw_flags)) { + // `flags` `=` UINT_BORDER_COLOR + if (Params.Flags.has_value()) { +reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind; +return std::nullopt; + } + + if (consumeExpectedToken(TokenKind::pu_equal)) +return std::nullopt; + + auto Flags = parseStaticSamplerFlags(TokenKind::kw_flags); + if (!Flags.has_value()) +return std::nullopt; + Params.Flags = Flags; } else { consumeNextToken(); // let diagnostic be at the start of invalid token reportDiag(diag::err_hlsl_invalid_token) @@ -1255,6 +1272,50 @@ RootSignatureParser::parseDescriptorRangeFlags(TokenKind Context) { return Flags; } +std::optional +RootSignatureParser::parseStaticSamplerFlags(TokenKind Context) { + assert(CurToken.TokKind == TokenKind::pu_equal && + "Expects to only be invoked starting at given keyword"); + + // Handle the edge-case of '0' to specify no flags set + if (tryConsumeExpectedToken(TokenKind::int_literal)) { +if (!verifyZeroFlag()) { + reportDiag(diag::err_hlsl_rootsig_non_zero_flag); + return std::nullopt; +} +return llvm::dxbc::StaticSamplerFlags::None; + } + + TokenKind Expected[] = { +#define STATIC_SAMPLER_FLA
[llvm-branch-commits] [clang] [Clang] Introduce -fsanitize=alloc-token (PR #156839)
@@ -447,6 +447,9 @@ class CodeGenOptions : public CodeGenOptionsBase { std::optional AllowRuntimeCheckSkipHotCutoff; + /// Maximum number of allocation tokens (0 = no max). melver wrote: None set by frontend, so it uses the pass default and doesn't pass any arg to compiler invocation. https://github.com/llvm/llvm-project/pull/156839 ___ 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] [LoopUnroll] Fix block frequencies for epilogue (PR #159163)
https://github.com/jdenny-ornl updated https://github.com/llvm/llvm-project/pull/159163 >From 5a9959313c0aebc1c707d19e30055cb925be7760 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Tue, 16 Sep 2025 16:03:11 -0400 Subject: [PATCH 1/4] [LoopUnroll] Fix block frequencies for epilogue As another step in issue #135812, this patch fixes block frequencies for partial loop unrolling with an epilogue remainder loop. It does not fully handle the case when the epilogue loop itself is unrolled. That will be handled in the next patch. For the guard and latch of each of the unrolled loop and epilogue loop, this patch sets branch weights derived directly from the original loop latch branch weights. The total frequency of the original loop body, summed across all its occurrences in the unrolled loop and epilogue loop, is the same as in the original loop. This patch also sets `llvm.loop.estimated_trip_count` for the epilogue loop instead of relying on the epilogue's latch branch weights to imply it. This patch removes the XFAIL directives that PR #157754 added to the test suite. --- .../include/llvm/Transforms/Utils/LoopUtils.h | 32 .../llvm/Transforms/Utils/UnrollLoop.h| 4 +- llvm/lib/Transforms/Utils/LoopUnroll.cpp | 31 ++-- .../Transforms/Utils/LoopUnrollRuntime.cpp| 94 -- llvm/lib/Transforms/Utils/LoopUtils.cpp | 48 ++ .../branch-weights-freq/unroll-epilog.ll | 160 ++ .../runtime-exit-phi-scev-invalidation.ll | 4 +- .../LoopUnroll/runtime-loop-branchweight.ll | 56 +- .../Transforms/LoopUnroll/runtime-loop.ll | 9 +- .../LoopUnroll/unroll-heuristics-pgo.ll | 64 +-- 10 files changed, 448 insertions(+), 54 deletions(-) create mode 100644 llvm/test/Transforms/LoopUnroll/branch-weights-freq/unroll-epilog.ll diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h index c5dbb2bdd1dd8..71754b8f62a16 100644 --- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h +++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h @@ -365,6 +365,38 @@ LLVM_ABI bool setLoopEstimatedTripCount( Loop *L, unsigned EstimatedTripCount, std::optional EstimatedLoopInvocationWeight = std::nullopt); +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation is unable to handle the loop form +/// of \p L (e.g., \p L must have a latch block that controls the loop exit). +/// - Else, the estimated probability that, at the end of any iteration, the +/// latch of \p L will start another iteration. The result \c P is such that +/// `0 <= P <= 1`, and `1 - P` is the probability of exiting the loop. +std::optional getLoopProbability(Loop *L); + +/// Set branch weight metadata for the latch of \p L to indicate that, at the +/// end of any iteration, its estimated probability of starting another +/// iteration is \p P. Return false if the implementation is unable to handle +/// the loop form of \p L (e.g., \p L must have a latch block that controls the +/// loop exit). Otherwise, return true. +bool setLoopProbability(Loop *L, double P); + +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation cannot extract the probability +/// (e.g., \p B must have exactly two target labels, so it must be a +/// conditional branch). +/// - The probability \c P that control flows from \p B to its first target +/// label such that `1 - P` is the probability of control flowing to its +/// second target label, or vice-versa if \p ForFirstTarget is false. +std::optional getBranchProbability(BranchInst *B, bool ForFirstTarget); + +/// Set branch weight metadata for \p B to indicate that \p P and `1 - P` are +/// the probabilities of control flowing to its first and second target labels, +/// respectively, or vice-versa if \p ForFirstTarget is false. Return false if +/// the implementation cannot set the probability (e.g., \p B must have exactly +/// two target labels, so it must be a conditional branch). Otherwise, return +/// true. +bool setBranchProbability(BranchInst *B, double P, bool ForFirstTarget); + /// Check inner loop (L) backedge count is known to be invariant on all /// iterations of its outer loop. If the loop has no parent, this is trivially /// true. diff --git a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h index 871c13d972470..571a0af6fd0db 100644 --- a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h +++ b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h @@ -97,7 +97,9 @@ LLVM_ABI bool UnrollRuntimeLoopRemainder( LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC, const TargetTransformInfo *TTI, bool PreserveLCSSA, unsigned SCEVExpansionBudget, bool RuntimeUnrollMultiExit, -Loop **ResultLoop = nullptr); +Loop **ResultLoop = nullptr, +std::optional OriginalTripCount = std::nullopt,
[llvm-branch-commits] [clang] [Clang] Introduce -fsanitize=alloc-token (PR #156839)
https://github.com/melver edited https://github.com/llvm/llvm-project/pull/156839 ___ 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] [LoopUnroll] Fix block frequencies for epilogue (PR #159163)
@@ -365,6 +365,38 @@ LLVM_ABI bool setLoopEstimatedTripCount( Loop *L, unsigned EstimatedTripCount, std::optional EstimatedLoopInvocationWeight = std::nullopt); +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation is unable to handle the loop form +/// of \p L (e.g., \p L must have a latch block that controls the loop exit). +/// - Else, the estimated probability that, at the end of any iteration, the +/// latch of \p L will start another iteration. The result \c P is such that +/// `0 <= P <= 1`, and `1 - P` is the probability of exiting the loop. +std::optional getLoopProbability(Loop *L); + +/// Set branch weight metadata for the latch of \p L to indicate that, at the +/// end of any iteration, its estimated probability of starting another +/// iteration is \p P. Return false if the implementation is unable to handle +/// the loop form of \p L (e.g., \p L must have a latch block that controls the +/// loop exit). Otherwise, return true. +bool setLoopProbability(Loop *L, double P); + +/// Based on branch weight metadata, return either: +/// - \c std::nullopt if the implementation cannot extract the probability +/// (e.g., \p B must have exactly two target labels, so it must be a +/// conditional branch). +/// - The probability \c P that control flows from \p B to its first target +/// label such that `1 - P` is the probability of control flowing to its +/// second target label, or vice-versa if \p ForFirstTarget is false. +std::optional getBranchProbability(BranchInst *B, bool ForFirstTarget); jdenny-ornl wrote: I suppose BranchProbability works. Thanks. Done. https://github.com/llvm/llvm-project/pull/159163 ___ 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] [AllocToken] Introduce AllocToken instrumentation pass (PR #156838)
@@ -0,0 +1,99 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s -passes=inferattrs,alloc-token -alloc-token-mode=increment -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" melver wrote: We can drop it - some targets do not have all libcalls, but I think if we omit this we get some "default"? Tests pass. https://github.com/llvm/llvm-project/pull/156838 ___ 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] [libunwind] release/21.x: [Mips] Fixed libunwind::Registers_mips_o32::jumpto to allow for load delay (#152942) (PR #160638)
https://github.com/wzssyqa approved this pull request. https://github.com/llvm/llvm-project/pull/160638 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Updating DXContainer logic to read version 1.2 of static samplers (PR #160184)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160184 >From fefd58c2ab1044ac51c546b6bc6df968eb5edaa8 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Fri, 19 Sep 2025 12:48:11 -0700 Subject: [PATCH 1/8] fix test --- llvm/include/llvm/Object/DXContainer.h| 57 --- llvm/lib/ObjectYAML/DXContainerYAML.cpp | 16 ++- llvm/unittests/Object/DXContainerTest.cpp | 16 --- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h index 9bc1918852335..e3e532f6635a4 100644 --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -123,25 +123,26 @@ template struct ViewArray { }; namespace DirectX { + +template Expected readParameter(StringRef Data) { + T Struct; + if (sizeof(T) != Data.size()) +return make_error( +"Reading structure out of file bounds", object_error::parse_failed); + + memcpy(&Struct, Data.data(), sizeof(T)); + // DXContainer is always little endian + if (sys::IsBigEndianHost) +Struct.swapBytes(); + return Struct; +} + struct RootParameterView { const dxbc::RTS0::v1::RootParameterHeader &Header; StringRef ParamData; RootParameterView(const dxbc::RTS0::v1::RootParameterHeader &H, StringRef P) : Header(H), ParamData(P) {} - - template Expected readParameter() { -T Struct; -if (sizeof(T) != ParamData.size()) - return make_error( - "Reading structure out of file bounds", object_error::parse_failed); - -memcpy(&Struct, ParamData.data(), sizeof(T)); -// DXContainer is always little endian -if (sys::IsBigEndianHost) - Struct.swapBytes(); -return Struct; - } }; struct RootConstantView : RootParameterView { @@ -151,7 +152,7 @@ struct RootConstantView : RootParameterView { } llvm::Expected read() { -return readParameter(); +return readParameter(ParamData); } }; @@ -167,7 +168,8 @@ struct RootDescriptorView : RootParameterView { llvm::Expected read(uint32_t Version) { if (Version == 1) { - auto Descriptor = readParameter(); + auto Descriptor = + readParameter(ParamData); if (Error E = Descriptor.takeError()) return E; return dxbc::RTS0::v2::RootDescriptor(*Descriptor); @@ -176,9 +178,10 @@ struct RootDescriptorView : RootParameterView { return make_error("Invalid Root Signature version: " + Twine(Version), object_error::parse_failed); -return readParameter(); +return readParameter(ParamData); } }; + template struct DescriptorTable { uint32_t NumRanges; uint32_t RangesOffset; @@ -247,8 +250,26 @@ class RootSignature { llvm::iterator_range param_headers() const { return llvm::make_range(ParametersHeaders.begin(), ParametersHeaders.end()); } - llvm::iterator_range samplers() const { -return llvm::make_range(StaticSamplers.begin(), StaticSamplers.end()); + llvm::Expected getSampler(uint32_t Loc) const { +if (Loc >= getNumStaticSamplers()) + return parseFailed("Static sampler index out of range"); + +auto SamplerSize = (Version <= 2) ? sizeof(dxbc::RTS0::v1::StaticSampler) + : sizeof(dxbc::RTS0::v3::StaticSampler); + +StringRef Buff = PartData.substr(StaticSamplersOffset + (Loc * SamplerSize), + SamplerSize); +if (Version < 3) { + auto Sampler = readParameter(Buff); + if (Error E = Sampler.takeError()) +return E; + return dxbc::RTS0::v3::StaticSampler(*Sampler); +} +if (Version != 3) + return make_error("Invalid Root Signature version: " + +Twine(Version), +object_error::parse_failed); +return readParameter(Buff); } uint32_t getFlags() const { return Flags; } diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp index 42074731c4e16..6f24b7d2573ec 100644 --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -163,7 +163,13 @@ DXContainerYAML::RootSignatureYamlDesc::create( } } - for (const auto &S : Data.samplers()) { + for (uint32_t Loc = 0; Loc < Data.getNumStaticSamplers(); ++Loc) { +llvm::Expected MaybeSampler = +Data.getSampler(Loc); +if (Error E = MaybeSampler.takeError()) + return std::move(E); +const llvm::dxbc::RTS0::v3::StaticSampler &S = *MaybeSampler; + if (!dxbc::isValidSamplerFilter(S.Filter)) return createStringError(std::errc::invalid_argument, "Invalid value for static sampler filter"); @@ -209,6 +215,14 @@ DXContainerYAML::RootSignatureYamlDesc::create( NewS.RegisterSpace = S.RegisterSpace; NewS.Shad
[llvm-branch-commits] [llvm] [LoongArch] Introduce instruction patterns for vector sign/zero extensions (PR #160810)
llvmbot wrote: @llvm/pr-subscribers-backend-loongarch Author: hev (heiher) Changes This patch introduces legalization and instruction patterns for vector sign and zero extension operations. --- Patch is 155.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/160810.diff 10 Files Affected: - (modified) llvm/lib/Target/LoongArch/LoongArch.td (+1) - (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+13) - (modified) llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td (+60) - (modified) llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td (+26) - (modified) llvm/test/CodeGen/LoongArch/lasx/vec-sext.ll (+104-795) - (modified) llvm/test/CodeGen/LoongArch/lasx/vec-zext.ll (+112-935) - (modified) llvm/test/CodeGen/LoongArch/lsx/vec-sext.ll (+212-274) - (modified) llvm/test/CodeGen/LoongArch/lsx/vec-shuffle-sign-ext.ll (+14-22) - (modified) llvm/test/CodeGen/LoongArch/lsx/vec-zext.ll (+221-178) - (modified) llvm/test/CodeGen/LoongArch/lsx/vmskcond.ll (+22-35) ``diff diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td index 6497ff999f6fa..62e837aad10b7 100644 --- a/llvm/lib/Target/LoongArch/LoongArch.td +++ b/llvm/lib/Target/LoongArch/LoongArch.td @@ -59,6 +59,7 @@ def FeatureExtLSX : SubtargetFeature<"lsx", "HasExtLSX", "true", "'LSX' (Loongson SIMD Extension)", [FeatureBasicD]>; def HasExtLSX : Predicate<"Subtarget->hasExtLSX()">; +def IsExtLSX : Predicate<"Subtarget->hasExtLSX() && !Subtarget->hasExtLASX()">; // Loongson Advanced SIMD eXtension (LASX) def FeatureExtLASX diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp index 801e557a22520..104b315d9bfcc 100644 --- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp @@ -385,6 +385,10 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM, setOperationAction(ISD::VECREDUCE_UMAX, VT, Custom); setOperationAction(ISD::VECREDUCE_UMIN, VT, Custom); } +for (MVT VT : {MVT::v2i64, MVT::v4i32, MVT::v8i16}) { + setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, VT, Legal); + setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, VT, Legal); +} } // Set operations for 'LASX' feature. @@ -446,6 +450,15 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM, VT, Expand); setOperationAction(ISD::SCALAR_TO_VECTOR, VT, Legal); } +for (MVT VT : {MVT::v4i64, MVT::v8i32, MVT::v16i16}) { + setOperationAction(ISD::SIGN_EXTEND, VT, Legal); + setOperationAction(ISD::ZERO_EXTEND, VT, Legal); +} +for (MVT VT : + {MVT::v2i64, MVT::v4i32, MVT::v4i64, MVT::v8i16, MVT::v8i32}) { + setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, VT, Legal); + setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, VT, Legal); +} } // Set DAG combine for LA32 and LA64. diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td index adfe990ba1234..b3389463b633c 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td @@ -2063,6 +2063,66 @@ defm : subvector_subreg_lowering; defm : subvector_subreg_lowering; defm : subvector_subreg_lowering; +// Sign extensions +def : Pat<(v4i64 (sext v4i32:$vj)), + (v4i64 (VEXT2XV_D_W (SUBREG_TO_REG (i64 0), v4i32:$vj, sub_128)))>; +def : Pat<(v8i32 (sext v8i16:$vj)), + (v8i32 (VEXT2XV_W_H (SUBREG_TO_REG (i64 0), v8i16:$vj, sub_128)))>; +def : Pat<(v16i16 (sext v16i8:$vj)), + (v16i16 (VEXT2XV_H_B (SUBREG_TO_REG (i64 0), v16i8:$vj, sub_128)))>; + +def : Pat<(v2i64 (sext_invec v16i8:$vj)), + (v2i64 (EXTRACT_SUBREG (VEXT2XV_D_B (SUBREG_TO_REG (i64 0), v16i8:$vj, sub_128)), + sub_128))>; +def : Pat<(v2i64 (sext_invec v8i16:$vj)), + (v2i64 (EXTRACT_SUBREG (VEXT2XV_D_H (SUBREG_TO_REG (i64 0), v8i16:$vj, sub_128)), + sub_128))>; +def : Pat<(v2i64 (sext_invec v4i32:$vj)), + (v2i64 (EXTRACT_SUBREG (VEXT2XV_D_W (SUBREG_TO_REG (i64 0), v4i32:$vj, sub_128)), + sub_128))>; +def : Pat<(v4i32 (sext_invec v16i8:$vj)), + (v4i32 (EXTRACT_SUBREG (VEXT2XV_W_B (SUBREG_TO_REG (i64 0), v16i8:$vj, sub_128)), + sub_128))>; +def : Pat<(v4i32 (sext_invec v8i16:$vj)), + (v4i32 (EXTRACT_SUBREG (VEXT2XV_W_H (SUBREG_TO_REG (i64 0), v8i16:$vj, sub_128)), + sub_128))>; +def : Pat<(v4i64 (sext_invec v32i8:$xj)), (v4i64 (VEXT2XV_D_B v32i8:$xj))>; +def : Pat<(v4i64 (sext_invec v16i16:$xj)), (v4i64 (VEXT2XV_D_H v16i16:$xj))>; +def : Pat<(v8i16 (sext_invec v16i8:$vj)), + (v8i16 (EXTRACT_SUBRE
[llvm-branch-commits] [llvm] Greedy: Move physreg check when trying to recolor vregs (NFC) (PR #160484)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Author: Matt Arsenault (arsenm) Changes Instead of checking if the recoloring candidate is a virtual register, avoid adding it to the candidates in the first place. --- Full diff: https://github.com/llvm/llvm-project/pull/160484.diff 1 Files Affected: - (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+2-5) ``diff diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 6e0585b2e9e55..dc23ab3ce9d2b 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -2502,10 +2502,6 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) { do { Reg = RecoloringCandidates.pop_back_val(); -// We cannot recolor physical register. -if (Reg.isPhysical()) - continue; - // This may be a skipped register. if (!VRM->hasPhys(Reg)) { assert(!shouldAllocateRegister(Reg) && @@ -2553,7 +2549,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) { // Push all copy-related live-ranges to keep reconciling the broken // hints. for (const HintInfo &HI : Info) { - if (Visited.insert(HI.Reg).second) + // We cannot recolor physical register. + if (HI.Reg.isVirtual() && Visited.insert(HI.Reg).second) RecoloringCandidates.push_back(HI.Reg); } } while (!RecoloringCandidates.empty()); `` https://github.com/llvm/llvm-project/pull/160484 ___ 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] [llvm][mustache] Refactor template rendering (PR #159189)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159189 >From f18412dc5dc3cf5e7b7afafa9ceaf47e17dfb936 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Fri, 12 Sep 2025 00:06:14 -0700 Subject: [PATCH] [llvm][mustache] Refactor template rendering Move the rendering logic into the ASTNode, and break the logic down into individual methods. --- llvm/lib/Support/Mustache.cpp | 132 -- 1 file changed, 80 insertions(+), 52 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 6b009810dc667..2e29a6579bdea 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -181,6 +181,14 @@ class ASTNode { const llvm::json::Value *findContext(); + void renderRoot(const json::Value &CurrentCtx, raw_ostream &OS); + void renderText(raw_ostream &OS); + void renderPartial(const json::Value &CurrentCtx, raw_ostream &OS); + void renderVariable(const json::Value &CurrentCtx, raw_ostream &OS); + void renderUnescapeVariable(const json::Value &CurrentCtx, raw_ostream &OS); + void renderSection(const json::Value &CurrentCtx, raw_ostream &OS); + void renderInvertSection(const json::Value &CurrentCtx, raw_ostream &OS); + StringMap &Partials; StringMap &Lambdas; StringMap &SectionLambdas; @@ -675,76 +683,96 @@ static void toMustacheString(const json::Value &Data, raw_ostream &OS) { } } +void ASTNode::renderRoot(const json::Value &CurrentCtx, raw_ostream &OS) { + renderChild(CurrentCtx, OS); +} + +void ASTNode::renderText(raw_ostream &OS) { OS << Body; } + +void ASTNode::renderPartial(const json::Value &CurrentCtx, raw_ostream &OS) { + auto Partial = Partials.find(AccessorValue[0]); + if (Partial != Partials.end()) +renderPartial(CurrentCtx, OS, Partial->getValue().get()); +} + +void ASTNode::renderVariable(const json::Value &CurrentCtx, raw_ostream &OS) { + auto Lambda = Lambdas.find(AccessorValue[0]); + if (Lambda != Lambdas.end()) { +renderLambdas(CurrentCtx, OS, Lambda->getValue()); + } else if (const json::Value *ContextPtr = findContext()) { +EscapeStringStream ES(OS, Escapes); +toMustacheString(*ContextPtr, ES); + } +} + +void ASTNode::renderUnescapeVariable(const json::Value &CurrentCtx, + raw_ostream &OS) { + auto Lambda = Lambdas.find(AccessorValue[0]); + if (Lambda != Lambdas.end()) { +renderLambdas(CurrentCtx, OS, Lambda->getValue()); + } else if (const json::Value *ContextPtr = findContext()) { +toMustacheString(*ContextPtr, OS); + } +} + +void ASTNode::renderSection(const json::Value &CurrentCtx, raw_ostream &OS) { + auto SectionLambda = SectionLambdas.find(AccessorValue[0]); + if (SectionLambda != SectionLambdas.end()) { +renderSectionLambdas(CurrentCtx, OS, SectionLambda->getValue()); +return; + } + + const json::Value *ContextPtr = findContext(); + if (isContextFalsey(ContextPtr)) +return; + + if (const json::Array *Arr = ContextPtr->getAsArray()) { +for (const json::Value &V : *Arr) + renderChild(V, OS); +return; + } + renderChild(*ContextPtr, OS); +} + +void ASTNode::renderInvertSection(const json::Value &CurrentCtx, + raw_ostream &OS) { + bool IsLambda = SectionLambdas.contains(AccessorValue[0]); + const json::Value *ContextPtr = findContext(); + if (isContextFalsey(ContextPtr) && !IsLambda) { +renderChild(CurrentCtx, OS); + } +} + void ASTNode::render(const json::Value &CurrentCtx, raw_ostream &OS) { if (Ty != Root && Ty != Text && AccessorValue.empty()) return; // Set the parent context to the incoming context so that we // can walk up the context tree correctly in findContext(). ParentContext = &CurrentCtx; - const json::Value *ContextPtr = Ty == Root ? ParentContext : findContext(); switch (Ty) { case Root: -renderChild(CurrentCtx, OS); +renderRoot(CurrentCtx, OS); return; case Text: -OS << Body; +renderText(OS); return; - case Partial: { -auto Partial = Partials.find(AccessorValue[0]); -if (Partial != Partials.end()) - renderPartial(CurrentCtx, OS, Partial->getValue().get()); + case Partial: +renderPartial(CurrentCtx, OS); return; - } - case Variable: { -auto Lambda = Lambdas.find(AccessorValue[0]); -if (Lambda != Lambdas.end()) { - renderLambdas(CurrentCtx, OS, Lambda->getValue()); -} else if (ContextPtr) { - EscapeStringStream ES(OS, Escapes); - toMustacheString(*ContextPtr, ES); -} + case Variable: +renderVariable(CurrentCtx, OS); return; - } - case UnescapeVariable: { -auto Lambda = Lambdas.find(AccessorValue[0]); -if (Lambda != Lambdas.end()) { - renderLambdas(CurrentCtx, OS, Lambda->getValue()); -} else if (ContextPtr) { - toMustacheString(*ContextPtr, OS); -} + case UnescapeVariable: +renderUnescapeVariable(CurrentCtx, OS); return; - } - case Section
[llvm-branch-commits] [llvm] [llvm][mustache] Support setting delimiters in templates (PR #159187)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159187 >From 794217c86631c9ae821de8d0ac6a9fa298c109f7 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 8 Sep 2025 21:22:02 -0700 Subject: [PATCH] [llvm][mustache] Support setting delimiters in templates The base mustache spec allows setting custom delimiters, which slightly change parsing of partials. This patch implements that feature by adding a new token type, and changing the tokenizer's behavior to allow setting custom delimiters. --- llvm/lib/Support/Mustache.cpp | 215 -- llvm/unittests/Support/MustacheTest.cpp | 22 +- .../llvm-test-mustache-spec.cpp | 16 -- 3 files changed, 161 insertions(+), 92 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 9c71d6a510056..814b01d343585 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -7,9 +7,14 @@ //===--===// #include "llvm/Support/Mustache.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" + +#include #include +#define DEBUG_TYPE "mustache" + using namespace llvm; using namespace llvm::mustache; @@ -62,6 +67,7 @@ class Token { InvertSectionOpen, UnescapeVariable, Comment, +SetDelimiter, }; Token(std::string Str) @@ -102,6 +108,8 @@ class Token { return Type::Partial; case '&': return Type::UnescapeVariable; +case '=': + return Type::SetDelimiter; default: return Type::Variable; } @@ -189,27 +197,27 @@ class ASTNode { }; // A wrapper for arena allocator for ASTNodes -AstPtr createRootNode(llvm::StringMap &Partials, - llvm::StringMap &Lambdas, - llvm::StringMap &SectionLambdas, - EscapeMap &Escapes) { +static AstPtr createRootNode(llvm::StringMap &Partials, + llvm::StringMap &Lambdas, + llvm::StringMap &SectionLambdas, + EscapeMap &Escapes) { return std::make_unique(Partials, Lambdas, SectionLambdas, Escapes); } -AstPtr createNode(ASTNode::Type T, Accessor A, ASTNode *Parent, - llvm::StringMap &Partials, - llvm::StringMap &Lambdas, - llvm::StringMap &SectionLambdas, - EscapeMap &Escapes) { +static AstPtr createNode(ASTNode::Type T, Accessor A, ASTNode *Parent, + llvm::StringMap &Partials, + llvm::StringMap &Lambdas, + llvm::StringMap &SectionLambdas, + EscapeMap &Escapes) { return std::make_unique(T, std::move(A), Parent, Partials, Lambdas, SectionLambdas, Escapes); } -AstPtr createTextNode(std::string Body, ASTNode *Parent, - llvm::StringMap &Partials, - llvm::StringMap &Lambdas, - llvm::StringMap &SectionLambdas, - EscapeMap &Escapes) { +static AstPtr createTextNode(std::string Body, ASTNode *Parent, + llvm::StringMap &Partials, + llvm::StringMap &Lambdas, + llvm::StringMap &SectionLambdas, + EscapeMap &Escapes) { return std::make_unique(std::move(Body), Parent, Partials, Lambdas, SectionLambdas, Escapes); } @@ -226,7 +234,7 @@ AstPtr createTextNode(std::string Body, ASTNode *Parent, // and the current token is the second token. // For example: // "{{#Section}}" -bool hasTextBehind(size_t Idx, const ArrayRef &Tokens) { +static bool hasTextBehind(size_t Idx, const ArrayRef &Tokens) { if (Idx == 0) return true; @@ -242,7 +250,7 @@ bool hasTextBehind(size_t Idx, const ArrayRef &Tokens) { // Function to check if there's no meaningful text ahead. // We determine if a token has text ahead if the left of previous // token does not start with a newline. -bool hasTextAhead(size_t Idx, const ArrayRef &Tokens) { +static bool hasTextAhead(size_t Idx, const ArrayRef &Tokens) { if (Idx >= Tokens.size() - 1) return true; @@ -255,11 +263,11 @@ bool hasTextAhead(size_t Idx, const ArrayRef &Tokens) { return !TokenBody.starts_with("\r\n") && !TokenBody.starts_with("\n"); } -bool requiresCleanUp(Token::Type T) { +static bool requiresCleanUp(Token::Type T) { // We must clean up all the tokens that could contain child nodes. return T == Token::Type::SectionOpen || T == Token::Type::InvertSectionOpen || T == Token::Type::SectionClose || T == Token::Type::Comment || - T == Token::Type::Partial; + T == Token::Type::Partial || T == Token::Type::SetDelimiter; } // Adjust next token body if there is no te
[llvm-branch-commits] [llvm] [llvm][mustache] Use single pass when tokenizing (PR #159196)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159196 >From dba238ea08a6144db7f94c24c66672b7fe4c0ab1 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 15 Sep 2025 23:27:50 -0700 Subject: [PATCH] [llvm][mustache] Use single pass when tokenizing The old implementation used many string searches over the same portions of the strings. This version sacrifices some API niceness for perf wins. Metric | Baseline | Single-Pass | Change -- | | --- | --- Time (ms) | 36.09| 35.78 | -0.86% Cycles | 35.3M| 35.0M | -0.79% Instructions | 86.7M| 85.8M | -1.03% Branch Misses | 116K | 114K| -1.91% Cache Misses | 244K | 232K| -4.98% --- llvm/lib/Support/Mustache.cpp | 186 +- 1 file changed, 73 insertions(+), 113 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 4328f04a36891..080611edcb3fd 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -371,141 +371,101 @@ static const char *jsonKindToString(json::Value::Kind K) { llvm_unreachable("Unknown json::Value::Kind"); } -static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open, - StringRef Close) { - const StringLiteral TripleOpen("{{{"); - const StringLiteral TripleClose("}}}"); - - size_t NormalOpenPos = Template.find(Open, StartPos); - size_t TripleOpenPos = Template.find(TripleOpen, StartPos); - - Tag Result; - - // Determine which tag comes first. - if (TripleOpenPos != StringRef::npos && - (NormalOpenPos == StringRef::npos || TripleOpenPos <= NormalOpenPos)) { -// Found a triple mustache tag. -size_t EndPos = -Template.find(TripleClose, TripleOpenPos + TripleOpen.size()); -if (EndPos == StringRef::npos) - return Result; // No closing tag found. - -Result.TagKind = Tag::Kind::Triple; -Result.StartPosition = TripleOpenPos; -size_t ContentStart = TripleOpenPos + TripleOpen.size(); -Result.Content = Template.substr(ContentStart, EndPos - ContentStart); -Result.FullMatch = Template.substr( -TripleOpenPos, (EndPos + TripleClose.size()) - TripleOpenPos); - } else if (NormalOpenPos != StringRef::npos) { -// Found a normal mustache tag. -size_t EndPos = Template.find(Close, NormalOpenPos + Open.size()); -if (EndPos == StringRef::npos) - return Result; // No closing tag found. - -Result.TagKind = Tag::Kind::Normal; -Result.StartPosition = NormalOpenPos; -size_t ContentStart = NormalOpenPos + Open.size(); -Result.Content = Template.substr(ContentStart, EndPos - ContentStart); -Result.FullMatch = -Template.substr(NormalOpenPos, (EndPos + Close.size()) - NormalOpenPos); - } - - return Result; -} - -static std::optional> -processTag(const Tag &T, SmallVectorImpl &Tokens, MustacheContext &Ctx) { - LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content -<< ", Kind: " << tagKindToString(T.TagKind) << "\n"); - if (T.TagKind == Tag::Kind::Triple) { -Tokens.emplace_back(T.FullMatch, Ctx.Saver.save("&" + T.Content), '&', Ctx); -return std::nullopt; - } - StringRef Interpolated = T.Content; - if (!Interpolated.trim().starts_with("=")) { -char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front(); -Tokens.emplace_back(T.FullMatch, Interpolated, Front, Ctx); -return std::nullopt; - } - Tokens.emplace_back(T.FullMatch, Interpolated, '=', Ctx); - StringRef DelimSpec = Interpolated.trim(); - DelimSpec = DelimSpec.drop_front(1); - DelimSpec = DelimSpec.take_until([](char C) { return C == '='; }); - DelimSpec = DelimSpec.trim(); - - auto [NewOpen, NewClose] = DelimSpec.split(' '); - LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << NewOpen -<< ", NewClose: " << NewClose << "\n"); - return std::make_pair(NewOpen, NewClose); -} - // Simple tokenizer that splits the template into tokens. -// The mustache spec allows {{{ }}} to unescape variables, -// but we don't support that here. An unescape variable -// is represented only by {{& variable}}. static SmallVector tokenize(StringRef Template, MustacheContext &Ctx) { LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n"); SmallVector Tokens; SmallString<8> Open("{{"); SmallString<8> Close("}}"); - size_t Start = 0; + size_t Cursor = 0; + size_t TextStart = 0; + + const StringLiteral TripleOpen("{{{"); + const StringLiteral TripleClose("}}}"); - while (Start < Template.size()) { -LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << Open - << "', Close='" << Close << "'\n"); -Tag T = findNextTag(Template, Start, Open, Close); + while (Cursor < Template.size()) { +StringRef TemplateSuffix = Template.substr(Cursor); +StringRef TagOpen
[llvm-branch-commits] [llvm] [llvm][mustache] Avoid extra allocations in parseSection (PR #159199)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159199 >From f37d1808f041d597657e3938e2cc23fd498e548f Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Tue, 16 Sep 2025 09:40:04 -0700 Subject: [PATCH] [llvm][mustache] Avoid extra allocations in parseSection We don't need to have extra allocations when concatenating raw bodies. --- llvm/lib/Support/Mustache.cpp | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 888104ca8d5bf..bb6b55742573d 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -590,9 +590,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty, size_t Start = CurrentPtr; parseMustache(CurrentNode); const size_t End = CurrentPtr - 1; + + size_t RawBodySize = 0; + for (size_t I = Start; I < End; ++I) +RawBodySize += Tokens[I].RawBody.size(); + SmallString<128> RawBody; - for (std::size_t I = Start; I < End; I++) + RawBody.reserve(RawBodySize); + for (std::size_t I = Start; I < End; ++I) RawBody += Tokens[I].RawBody; + CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody))); Parent->addChild(CurrentNode); } ___ 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] [llvm][mustache] Avoid extra copy for json strings (PR #159195)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159195 >From 5b2c23c1e0555ae80b1d336e207bdae3c9533c5e Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 15 Sep 2025 19:54:34 -0700 Subject: [PATCH] [llvm][mustache] Avoid extra copy for json strings --- llvm/lib/Support/Mustache.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index ab6af1138f902..4328f04a36891 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -686,8 +686,7 @@ static void toMustacheString(const json::Value &Data, raw_ostream &OS) { return; } case json::Value::String: { -auto Str = *Data.getAsString(); -OS << Str.str(); +OS << *Data.getAsString(); return; } ___ 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] [llvm][mustache] Avoid redundant saves in accessor splitting (PR #159197)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159197 >From 735490e2ecd5c2ff319a105b57d770f9e081350f Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Tue, 16 Sep 2025 00:11:47 -0700 Subject: [PATCH] [llvm][mustache] Avoid redundant saves in accessor splitting The splitMustacheString function was saving StringRefs that were already backed by an arena-allocated string. This was unnecessary work. This change removes the redundant Ctx.Saver.save() call. This optimization provides a small but measurable performance improvement on top of the single-pass tokenizer, most notably reducing branch misses. Metric | Baseline | Optimized | Change -- | | - | --- Time (ms) | 35.77| 35.57 | -0.56% Cycles | 35.16M | 34.91M| -0.71% Instructions | 85.77M | 85.54M| -0.27% Branch Misses | 113.9K | 111.9K| -1.76% Cache Misses | 237.7K | 242.1K| +1.85% --- llvm/lib/Support/Mustache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 080611edcb3fd..e7129341365e3 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -52,7 +52,7 @@ static Accessor splitMustacheString(StringRef Str, MustacheContext &Ctx) { std::tie(Part, Str) = Str.split('.'); // Each part of the accessor needs to be saved to the arena // to ensure it has a stable address. - Tokens.push_back(Ctx.Saver.save(Part.trim())); + Tokens.push_back(Part.trim()); } } // Now, allocate memory for the array of StringRefs in the arena. ___ 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] [llvm][mustache] Use single pass when tokenizing (PR #159196)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159196 >From dba238ea08a6144db7f94c24c66672b7fe4c0ab1 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 15 Sep 2025 23:27:50 -0700 Subject: [PATCH] [llvm][mustache] Use single pass when tokenizing The old implementation used many string searches over the same portions of the strings. This version sacrifices some API niceness for perf wins. Metric | Baseline | Single-Pass | Change -- | | --- | --- Time (ms) | 36.09| 35.78 | -0.86% Cycles | 35.3M| 35.0M | -0.79% Instructions | 86.7M| 85.8M | -1.03% Branch Misses | 116K | 114K| -1.91% Cache Misses | 244K | 232K| -4.98% --- llvm/lib/Support/Mustache.cpp | 186 +- 1 file changed, 73 insertions(+), 113 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 4328f04a36891..080611edcb3fd 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -371,141 +371,101 @@ static const char *jsonKindToString(json::Value::Kind K) { llvm_unreachable("Unknown json::Value::Kind"); } -static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open, - StringRef Close) { - const StringLiteral TripleOpen("{{{"); - const StringLiteral TripleClose("}}}"); - - size_t NormalOpenPos = Template.find(Open, StartPos); - size_t TripleOpenPos = Template.find(TripleOpen, StartPos); - - Tag Result; - - // Determine which tag comes first. - if (TripleOpenPos != StringRef::npos && - (NormalOpenPos == StringRef::npos || TripleOpenPos <= NormalOpenPos)) { -// Found a triple mustache tag. -size_t EndPos = -Template.find(TripleClose, TripleOpenPos + TripleOpen.size()); -if (EndPos == StringRef::npos) - return Result; // No closing tag found. - -Result.TagKind = Tag::Kind::Triple; -Result.StartPosition = TripleOpenPos; -size_t ContentStart = TripleOpenPos + TripleOpen.size(); -Result.Content = Template.substr(ContentStart, EndPos - ContentStart); -Result.FullMatch = Template.substr( -TripleOpenPos, (EndPos + TripleClose.size()) - TripleOpenPos); - } else if (NormalOpenPos != StringRef::npos) { -// Found a normal mustache tag. -size_t EndPos = Template.find(Close, NormalOpenPos + Open.size()); -if (EndPos == StringRef::npos) - return Result; // No closing tag found. - -Result.TagKind = Tag::Kind::Normal; -Result.StartPosition = NormalOpenPos; -size_t ContentStart = NormalOpenPos + Open.size(); -Result.Content = Template.substr(ContentStart, EndPos - ContentStart); -Result.FullMatch = -Template.substr(NormalOpenPos, (EndPos + Close.size()) - NormalOpenPos); - } - - return Result; -} - -static std::optional> -processTag(const Tag &T, SmallVectorImpl &Tokens, MustacheContext &Ctx) { - LLVM_DEBUG(dbgs() << "[Tag] " << T.FullMatch << ", Content: " << T.Content -<< ", Kind: " << tagKindToString(T.TagKind) << "\n"); - if (T.TagKind == Tag::Kind::Triple) { -Tokens.emplace_back(T.FullMatch, Ctx.Saver.save("&" + T.Content), '&', Ctx); -return std::nullopt; - } - StringRef Interpolated = T.Content; - if (!Interpolated.trim().starts_with("=")) { -char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front(); -Tokens.emplace_back(T.FullMatch, Interpolated, Front, Ctx); -return std::nullopt; - } - Tokens.emplace_back(T.FullMatch, Interpolated, '=', Ctx); - StringRef DelimSpec = Interpolated.trim(); - DelimSpec = DelimSpec.drop_front(1); - DelimSpec = DelimSpec.take_until([](char C) { return C == '='; }); - DelimSpec = DelimSpec.trim(); - - auto [NewOpen, NewClose] = DelimSpec.split(' '); - LLVM_DEBUG(dbgs() << "[Set Delimiter] NewOpen: " << NewOpen -<< ", NewClose: " << NewClose << "\n"); - return std::make_pair(NewOpen, NewClose); -} - // Simple tokenizer that splits the template into tokens. -// The mustache spec allows {{{ }}} to unescape variables, -// but we don't support that here. An unescape variable -// is represented only by {{& variable}}. static SmallVector tokenize(StringRef Template, MustacheContext &Ctx) { LLVM_DEBUG(dbgs() << "[Tokenize Template] \"" << Template << "\"\n"); SmallVector Tokens; SmallString<8> Open("{{"); SmallString<8> Close("}}"); - size_t Start = 0; + size_t Cursor = 0; + size_t TextStart = 0; + + const StringLiteral TripleOpen("{{{"); + const StringLiteral TripleClose("}}}"); - while (Start < Template.size()) { -LLVM_DEBUG(dbgs() << "[Tokenize Loop] Start=" << Start << ", Open='" << Open - << "', Close='" << Close << "'\n"); -Tag T = findNextTag(Template, Start, Open, Close); + while (Cursor < Template.size()) { +StringRef TemplateSuffix = Template.substr(Cursor); +StringRef TagOpen
[llvm-branch-commits] [llvm] [llvm][mustache] Optimize accessor splitting with a single pass (PR #159198)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159198 >From 28deddc80945faf39cf6db64452f201737b5fd05 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Tue, 16 Sep 2025 00:24:43 -0700 Subject: [PATCH] [llvm][mustache] Optimize accessor splitting with a single pass The splitMustacheString function previously used a loop of StringRef::split and StringRef::trim. This was inefficient as it scanned each segment of the accessor string multiple times. This change introduces a custom splitAndTrim function that performs both operations in a single pass over the string, reducing redundant work and improving performance, most notably in the number of CPU cycles executed. Metric | Baseline | Optimized | Change -- | | - | --- Time (ms) | 35.57| 35.36 | -0.59% Cycles | 34.91M | 34.26M| -1.86% Instructions | 85.54M | 85.24M| -0.35% Branch Misses | 111.9K | 112.2K| +0.27% Cache Misses | 242.1K | 239.9K| -0.91% --- llvm/lib/Support/Mustache.cpp | 34 +++--- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index e7129341365e3..888104ca8d5bf 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -35,6 +35,32 @@ static bool isContextFalsey(const json::Value *V) { return isFalsey(*V); } +static void splitAndTrim(StringRef Str, SmallVectorImpl &Tokens) { + size_t CurrentPos = 0; + while (CurrentPos < Str.size()) { +// Find the next delimiter. +size_t DelimiterPos = Str.find('.', CurrentPos); + +// If no delimiter is found, process the rest of the string. +if (DelimiterPos == StringRef::npos) { + DelimiterPos = Str.size(); +} + +// Get the current part, which may have whitespace. +StringRef Part = Str.slice(CurrentPos, DelimiterPos); + +// Manually trim the part without creating a new string object. +size_t Start = Part.find_first_not_of(" \t\r\n"); +if (Start != StringRef::npos) { + size_t End = Part.find_last_not_of(" \t\r\n"); + Tokens.push_back(Part.slice(Start, End + 1)); +} + +// Move past the delimiter for the next iteration. +CurrentPos = DelimiterPos + 1; + } +} + static Accessor splitMustacheString(StringRef Str, MustacheContext &Ctx) { // We split the mustache string into an accessor. // For example: @@ -47,13 +73,7 @@ static Accessor splitMustacheString(StringRef Str, MustacheContext &Ctx) { // It's a literal, so it doesn't need to be saved. Tokens.push_back("."); } else { -while (!Str.empty()) { - StringRef Part; - std::tie(Part, Str) = Str.split('.'); - // Each part of the accessor needs to be saved to the arena - // to ensure it has a stable address. - Tokens.push_back(Part.trim()); -} +splitAndTrim(Str, Tokens); } // Now, allocate memory for the array of StringRefs in the arena. StringRef *ArenaTokens = Ctx.Allocator.Allocate(Tokens.size()); ___ 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] [llvm][mustache] Avoid extra allocations in parseSection (PR #159199)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159199 >From f37d1808f041d597657e3938e2cc23fd498e548f Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Tue, 16 Sep 2025 09:40:04 -0700 Subject: [PATCH] [llvm][mustache] Avoid extra allocations in parseSection We don't need to have extra allocations when concatenating raw bodies. --- llvm/lib/Support/Mustache.cpp | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 888104ca8d5bf..bb6b55742573d 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -590,9 +590,16 @@ void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty, size_t Start = CurrentPtr; parseMustache(CurrentNode); const size_t End = CurrentPtr - 1; + + size_t RawBodySize = 0; + for (size_t I = Start; I < End; ++I) +RawBodySize += Tokens[I].RawBody.size(); + SmallString<128> RawBody; - for (std::size_t I = Start; I < End; I++) + RawBody.reserve(RawBodySize); + for (std::size_t I = Start; I < End; ++I) RawBody += Tokens[I].RawBody; + CurrentNode->setRawBody(Ctx.Saver.save(StringRef(RawBody))); Parent->addChild(CurrentNode); } ___ 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] Introduce -fsanitize=alloc-token (PR #156839)
@@ -0,0 +1,27 @@ +// Test AllocToken respects ignorelist for functions and files. +// +// RUN: %clang_cc1 -fsanitize=alloc-token -triple x86_64-linux-gnu -x c -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ALLOW zmodem wrote: The `-x c` flags seem redundant in a `.c` file (here and elsewhere). https://github.com/llvm/llvm-project/pull/156839 ___ 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] Reland: [clang] Implement evaluation context for checking template parameters (PR #130603)
https://github.com/mizvekov edited https://github.com/llvm/llvm-project/pull/130603 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
@@ -212,7 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), - }; + ConstantAsMetadata::get(Builder.getInt32(0))}; joaosaffran wrote: I think that merge with this temporary fix is better. Since, if we update the frontend first, it is going to break the backend, since it still expect StaticSampler MD Nodes to contain 14 values and not 15. @bogner what do you think is the best direction here? https://github.com/llvm/llvm-project/pull/160210 ___ 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] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160210 >From 6b191d041990ad667d86b6b07eeed7c802e3fe45 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 22 Sep 2025 15:31:47 -0700 Subject: [PATCH 1/6] adding metadata static sampler flags --- clang/test/CodeGenHLSL/RootSignature.hlsl | 4 +- .../Frontend/HLSL/RootSignatureMetadata.cpp | 14 +- ...gnature-StaticSamplers-Invalid-AddressU.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressV.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressW.ll | 2 +- ...ture-StaticSamplers-Invalid-BorderColor.ll | 2 +- ...e-StaticSamplers-Invalid-ComparisonFunc.ll | 2 +- ...Signature-StaticSamplers-Invalid-Filter.ll | 2 +- ...re-StaticSamplers-Invalid-MaxAnisotropy.ll | 2 +- ...Signature-StaticSamplers-Invalid-MaxLod.ll | 2 +- ...Signature-StaticSamplers-Invalid-MinLod.ll | 2 +- ...ature-StaticSamplers-Invalid-MinLopBias.ll | 2 +- ...re-StaticSamplers-Invalid-RegisterSpace.ll | 2 +- ...e-StaticSamplers-Invalid-ShaderRegister.ll | 2 +- ...StaticSamplers-Invalid-ShaderVisibility.ll | 2 +- .../RootSignature-StaticSamplers.ll | 2 +- .../RootSignature-StaticSamplers_V3.ll| 43 +++ .../rootsignature-validation-fail-sampler.ll | 2 +- ...re-validation-fail-static-sampler-range.ll | 4 +- 19 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers_V3.ll diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl b/clang/test/CodeGenHLSL/RootSignature.hlsl index bc40bdd79ce59..bbab6a73a3658 100644 --- a/clang/test/CodeGenHLSL/RootSignature.hlsl +++ b/clang/test/CodeGenHLSL/RootSignature.hlsl @@ -82,8 +82,8 @@ void RootDescriptorsEntry() {} // checking minLOD, maxLOD // CHECK-SAME: float -1.28e+02, float 1.28e+02, -// checking register, space and visibility -// CHECK-SAME: i32 42, i32 0, i32 0} +// checking register, space, visibility and flags +// CHECK-SAME: i32 42, i32 0, i32 0, i32 0} #define SampleStaticSampler \ "StaticSampler(s42, " \ diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp index f29f2c7602fc6..5ddf129265648 100644 --- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp +++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp @@ -212,6 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), + ConstantAsMetadata::get(Builder.getInt32(0)), }; return MDNode::get(Ctx, Operands); } @@ -411,7 +412,7 @@ Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD, Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, MDNode *StaticSamplerNode) { - if (StaticSamplerNode->getNumOperands() != 14) + if (StaticSamplerNode->getNumOperands() != 15) return make_error("Static Sampler"); mcdxbc::StaticSampler Sampler; @@ -495,6 +496,17 @@ Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, return Error(std::move(E)); Sampler.ShaderVisibility = *Visibility; + if (RSD.Version < 3) { +RSD.StaticSamplers.push_back(Sampler); +return Error::success(); + } + assert(RSD.Version >= 3); + + if (std::optional Val = extractMdIntValue(StaticSamplerNode, 14)) +Sampler.Flags = *Val; + else +return make_error("Static Sampler Flags"); + RSD.StaticSamplers.push_back(Sampler); return Error::success(); } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll index 288dea00b6e55..b043ea1418df6 100644 --- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll +++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll @@ -16,4 +16,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } !dx.rootsignatures = !{!2} ; list of function/root signature pairs !2 = !{ ptr @main, !3, i32 2 } ; function, root signature !3 = !{ !5 } ; list of root signature elements -!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0 } +!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 0 } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll index e9abcf966..8219ffdd679d2 100644 --- a/llvm/test/CodeGen/D
[llvm-branch-commits] [clang] [libcxx] [lldb] [llvm] [mlir] [HLSL] Update Frontend to support version 1.2 of root signature (PR #160616)
Andrzej =?utf-8?q?Warzyński?= , Andrzej =?utf-8?q?Warzyński?= , Andrzej =?utf-8?q?Warzyński?= ,Fady Farag ,Timm Baeder ,Elizaveta Noskova <159026035+enoskova...@users.noreply.github.com>,Ross Brunton ,Osama Abdelkader <78818069+osamaka...@users.noreply.github.com>,Simon Pilgrim ,Joseph Huber ,Krzysztof Parzyszek ,Weibo He ,Krzysztof Parzyszek ,Ilia Kuklin ,Zaky Hermawan <44158147+zakyherma...@users.noreply.github.com>,Andrew Ng ,Aiden Grossman ,Akash Banerjee ,Michael Buch ,Nikolas Klauser ,Vinay Deshmukh ,David Spickett ,Igor Wodiany ,Simon Pilgrim ,David Spickett ,Lei Huang ,Roy Shi ,Amr Hesham ,Amr Hesham ,Anatoly Trosinenko ,Rahul Joshi ,Kazu Hirata ,Kazu Hirata ,Kazu Hirata =?utf-8?q?,?=Kazu Hirata ,Kazu Hirata ,Amr Hesham ,Lei Huang ,Simon Pilgrim ,azwolski ,Mend Renovate , Andrzej =?utf-8?q?Warzyński?= ,Damien L-G ,Kiran Chandramohan ,Andy Kaylor ,Alexey Karyakin ,LLVM GN Syncbot ,Rahul Joshi ,Alex Bradbury ,Florian Mayer ,Florian Mayer ,Mehdi Amini ,Sarah Spall ,Janek van Oirschot ,Stanislav Mekhanoshin ,fennecJ ,Ivan Kosarev ,Roman Belenov ,Stanislav Mekhanoshin ,Andrew Gontarek ,Farzon Lotfi =?utf-8?q?,?=Krzysztof Parzyszek ,Louis Dionne ,Mikhail Gudim ,Alexey Sachkov ,Amr Hesham ,Erick Velez ,Amr Hesham ,Rahul Joshi ,Nirvedh Meshram <96096277+nirvedhmesh...@users.noreply.github.com>,Christopher Ferris ,Vladislav Dzhidzhoev ,Abid Qadeer ,Maksim Levental ,Krzysztof Parzyszek ,Zibi Sarbinowski ,Michael Jones ,Alexander Richardson =?utf-8?q?,?=Alexander Richardson ,Pranav Kant ,joaosaffran ,Louis Dionne ,Philip Reames ,Philip Reames ,Krzysztof Drewniak , Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Amr Hesham , Gergely =?utf-8?q?Bálint?= ,Akira Hatanaka ,Pranav Kant ,Pranav Kant ,Martin =?utf-8?q?Storsjö?= ,Finn Plummer ,jcaselman-keysight,Aiden Grossman ,Florian Hahn ,Sarah Spall ,Sam Elliott ,Helena Kotas ,Heejin Ahn ,Shilei Tian ,Philip Reames ,Jonas Devlieghere ,Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Stanislav Mekhanoshin ,Stanislav Mekhanoshin ,Stanislav Mekhanoshin ,Stanislav Mekhanoshin ,Min-Yih Hsu ,Sam Clegg ,Alina Sbirlea ,CatherineMoore ,Sam Clegg ,Alexander Richardson ,Peter Klausler ,Peter Klausler ,Peter Klausler ,Peter Klausler ,Peter Klausler ,Peter Klausler ,Maksim Panchenko ,Tobias Stadler ,Quentin Chateau ,Philip Reames ,Razvan Lupusoru ,Prabhu Rajasekaran ,William Tran-Viet ,Jonas Devlieghere ,Erick Velez ,Pradeep Kumar ,Maksim Levental ,Twice ,quic_hchandel ,Jordan Rupprecht ,Congcong Cai ,Weibo He ,Louis Dionne ,Louis Dionne ,Jongmyeong Choi ,Qi Zhao ,Peter Hawkins ,Craig Topper ,joaosaffran ,nerix ,Luke Hutton ,Jonas Paulsson ,Timm Baeder ,Nikolas Klauser ,Nikolas Klauser ,Nikolas Klauser ,Elizaveta Noskova <159026035+enoskova...@users.noreply.github.com>,jeanPerier ,Nikolas Klauser ,Carl Ritson ,Maksim Levental ,Carl Ritson ,Hongyu Chen ,Alex Bradbury ,Ross Brunton ,Abhilash Majumder ,Maksim Levental ,David Green ,Jonathan Thackray ,Ramkumar Ramachandra ,Matthew Devereau ,Pradeep Kumar ,Timm Baeder ,Nikita Popov ,Nikita Popov ,David Green ,Nikita Popov ,Simon Pilgrim ,Simon Pilgrim ,Florian Hahn ,Maksim Levental ,Andrei Golubev ,Benjamin Maxwell ,Ross Brunton ,Florian Hahn ,Florian Hahn ,Fabian Ritter ,Ivan Kosarev ,Raul Tambre ,Artemy Skrebkov ,Ramkumar Ramachandra ,Nikolas Klauser ,Bart Chrzaszcz ,Timm Baeder ,woruyu <1214539...@qq.com>,Fabian Mora ,Harald van Dijk ,Akash Banerjee ,Sebastian Proell <63345705+sebpro...@users.noreply.github.com>,Nikolas Klauser ,Simon Pilgrim ,Antonio Frighetto ,Tobias Stadler ,Mehdi Amini ,nerix ,LU-JOHN ,Bart Chrzaszcz ,Lei Huang ,LLVM GN Syncbot ,Jon Roelofs ,Timm Baeder ,Leandro Lupori ,Andrey Timonin ,Kazu Hirata ,Shilei Tian ,Krishna Pandey ,Bart Chrzaszcz ,Brox Chen ,Kazu Hirata ,Kazu Hirata ,Kazu Hirata ,Kazu Hirata =?utf-8?q?,?=Antonio Frighetto ,Erich Keane ,Florian Hahn ,Maksim Levental ,Sina Mahdavi ,Derek Schuff ,Fangrui Song ,Stanislav Mekhanoshin ,Stanislav Mekhanoshin ,Stanislav Mekhanoshin ,Helena Kotas ,Fabian Mora ,Matthew Devereau ,Louis Dionne ,Louis Dionne ,Louis Dionne ,Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Mark Danial ,Amr Hesham ,lntue ,Lei Huang ,Samira Bakon ,Luke Hutton ,Luke Hutton ,Marcel Jacobse ,Mircea Trofin ,Rahman Lavaee , Martin =?utf-8?q?Storsjö?= ,Tomohiro Kashiwada ,Erich Keane ,Andrew ,Stanislav Mekhanoshin ,Akira Hatanaka ,Maksim Levental ,Nishant Patel ,Julian Lettner ,Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Florian Hahn ,Matthew Bastien ,Jonas Devlieghere ,Paul Kirth , Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Baranov Victor ,Aiden Grossman ,Han-Chung Wang ,Joseph Huber ,Corentin Jabot ,Stanislav Mekhanoshin ,Paul Kirth ,Sterling-Augustine ,Kazu Hirata ,NohHyeon Kwon <96061253+swote-...@users.noreply.github.com>,Greg Clayton ,Thurston Dang ,paperchalice ,Hristo Hristov ,Aiden Grossman ,Jade Marker ,AZero13 ,Philip Re
[llvm-branch-commits] [clang] [llvm] [DirectX] Updating Root Signature Metadata to contain Static Sampler flags (PR #160210)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/160210 >From 6b191d041990ad667d86b6b07eeed7c802e3fe45 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 22 Sep 2025 15:31:47 -0700 Subject: [PATCH 1/6] adding metadata static sampler flags --- clang/test/CodeGenHLSL/RootSignature.hlsl | 4 +- .../Frontend/HLSL/RootSignatureMetadata.cpp | 14 +- ...gnature-StaticSamplers-Invalid-AddressU.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressV.ll | 2 +- ...gnature-StaticSamplers-Invalid-AddressW.ll | 2 +- ...ture-StaticSamplers-Invalid-BorderColor.ll | 2 +- ...e-StaticSamplers-Invalid-ComparisonFunc.ll | 2 +- ...Signature-StaticSamplers-Invalid-Filter.ll | 2 +- ...re-StaticSamplers-Invalid-MaxAnisotropy.ll | 2 +- ...Signature-StaticSamplers-Invalid-MaxLod.ll | 2 +- ...Signature-StaticSamplers-Invalid-MinLod.ll | 2 +- ...ature-StaticSamplers-Invalid-MinLopBias.ll | 2 +- ...re-StaticSamplers-Invalid-RegisterSpace.ll | 2 +- ...e-StaticSamplers-Invalid-ShaderRegister.ll | 2 +- ...StaticSamplers-Invalid-ShaderVisibility.ll | 2 +- .../RootSignature-StaticSamplers.ll | 2 +- .../RootSignature-StaticSamplers_V3.ll| 43 +++ .../rootsignature-validation-fail-sampler.ll | 2 +- ...re-validation-fail-static-sampler-range.ll | 4 +- 19 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers_V3.ll diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl b/clang/test/CodeGenHLSL/RootSignature.hlsl index bc40bdd79ce59..bbab6a73a3658 100644 --- a/clang/test/CodeGenHLSL/RootSignature.hlsl +++ b/clang/test/CodeGenHLSL/RootSignature.hlsl @@ -82,8 +82,8 @@ void RootDescriptorsEntry() {} // checking minLOD, maxLOD // CHECK-SAME: float -1.28e+02, float 1.28e+02, -// checking register, space and visibility -// CHECK-SAME: i32 42, i32 0, i32 0} +// checking register, space, visibility and flags +// CHECK-SAME: i32 42, i32 0, i32 0, i32 0} #define SampleStaticSampler \ "StaticSampler(s42, " \ diff --git a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp index f29f2c7602fc6..5ddf129265648 100644 --- a/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp +++ b/llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp @@ -212,6 +212,7 @@ MDNode *MetadataBuilder::BuildStaticSampler(const StaticSampler &Sampler) { ConstantAsMetadata::get(Builder.getInt32(Sampler.Space)), ConstantAsMetadata::get( Builder.getInt32(to_underlying(Sampler.Visibility))), + ConstantAsMetadata::get(Builder.getInt32(0)), }; return MDNode::get(Ctx, Operands); } @@ -411,7 +412,7 @@ Error MetadataParser::parseDescriptorTable(mcdxbc::RootSignatureDesc &RSD, Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, MDNode *StaticSamplerNode) { - if (StaticSamplerNode->getNumOperands() != 14) + if (StaticSamplerNode->getNumOperands() != 15) return make_error("Static Sampler"); mcdxbc::StaticSampler Sampler; @@ -495,6 +496,17 @@ Error MetadataParser::parseStaticSampler(mcdxbc::RootSignatureDesc &RSD, return Error(std::move(E)); Sampler.ShaderVisibility = *Visibility; + if (RSD.Version < 3) { +RSD.StaticSamplers.push_back(Sampler); +return Error::success(); + } + assert(RSD.Version >= 3); + + if (std::optional Val = extractMdIntValue(StaticSamplerNode, 14)) +Sampler.Flags = *Val; + else +return make_error("Static Sampler Flags"); + RSD.StaticSamplers.push_back(Sampler); return Error::success(); } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll index 288dea00b6e55..b043ea1418df6 100644 --- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll +++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll @@ -16,4 +16,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } !dx.rootsignatures = !{!2} ; list of function/root signature pairs !2 = !{ ptr @main, !3, i32 2 } ; function, root signature !3 = !{ !5 } ; list of root signature elements -!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0 } +!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6C000, i32 9, i32 3, i32 2, float -1.28e+02, float 1.28e+02, i32 42, i32 0, i32 0, i32 0 } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll index e9abcf966..8219ffdd679d2 100644 --- a/llvm/test/CodeGen/D
[llvm-branch-commits] [llvm] release/21.x: [NVPTX] Disable relative lookup tables (#159748) (PR #160064)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/160064 Backport 1ed15374638ecf6046169194b4b3ca34b7cf340f Requested by: @nikic >From 2c30e1b9e92b47e642007efc3b0b72c54d0c7063 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 22 Sep 2025 12:18:25 +0200 Subject: [PATCH] [NVPTX] Disable relative lookup tables (#159748) Relative lookup tables result in "LLVM ERROR: Circular dependency found in global variable set", so disable them for this target. (cherry picked from commit 1ed15374638ecf6046169194b4b3ca34b7cf340f) --- .../Target/NVPTX/NVPTXTargetTransformInfo.h | 5 +++ .../RelLookupTableConverter/nvptx.ll | 32 +++ 2 files changed, 37 insertions(+) create mode 100644 llvm/test/Transforms/RelLookupTableConverter/nvptx.ll diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h index 9a6e261c811a0..437edfb8ffc75 100644 --- a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h +++ b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h @@ -183,6 +183,11 @@ class NVPTXTTIImpl final : public BasicTTIImplBase { void collectKernelLaunchBounds( const Function &F, SmallVectorImpl> &LB) const override; + + bool shouldBuildRelLookupTables() const override { +// Self-referential globals are not supported. +return false; + } }; } // end namespace llvm diff --git a/llvm/test/Transforms/RelLookupTableConverter/nvptx.ll b/llvm/test/Transforms/RelLookupTableConverter/nvptx.ll new file mode 100644 index 0..70ebf220c369c --- /dev/null +++ b/llvm/test/Transforms/RelLookupTableConverter/nvptx.ll @@ -0,0 +1,32 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5 +; RUN: opt < %s -passes=rel-lookup-table-converter -relocation-model=pic -S | FileCheck %s +; REQUIRES: nvptx-registered-target +target triple = "nvptx64-nvidia-cuda" + +; Do not produce relative lookup table for nvptx target. + +@a1 = internal constant i32 0, align 4 +@b1 = internal constant i32 0, align 4 +@c1 = internal constant i32 0, align 4 +@d1 = internal constant i32 0, align 4 + +@switch.table = private unnamed_addr constant [3 x ptr] [ptr @a1, ptr @b1, ptr @c1], align 8 + +;. +; CHECK: @a1 = internal constant i32 0, align 4 +; CHECK: @b1 = internal constant i32 0, align 4 +; CHECK: @c1 = internal constant i32 0, align 4 +; CHECK: @d1 = internal constant i32 0, align 4 +; CHECK: @switch.table = private unnamed_addr constant [3 x ptr] [ptr @a1, ptr @b1, ptr @c1], align 8 +;. +define ptr @internal_linkage(i32 %cond) { +; CHECK-LABEL: define ptr @internal_linkage( +; CHECK-SAME: i32 [[COND:%.*]]) { +; CHECK-NEXT:[[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x ptr], ptr @switch.table, i32 0, i32 [[COND]] +; CHECK-NEXT:[[RELTABLE_INTRINSIC:%.*]] = load ptr, ptr [[SWITCH_GEP]], align 8 +; CHECK-NEXT:ret ptr [[RELTABLE_INTRINSIC]] +; + %switch.gep = getelementptr inbounds [3 x ptr], ptr @switch.table, i32 0, i32 %cond + %switch.load = load ptr, ptr %switch.gep, align 8 + ret ptr %switch.load +} ___ 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] [LifetimeSafety] Implement support for lifetimebound attribute (PR #158489)
https://github.com/Xazax-hun approved this pull request. Looks great, some minor nits inline. Thanks! https://github.com/llvm/llvm-project/pull/158489 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU] SIMemoryLegalizer: Factor out check if memory operations can affect the global AS (PR #160129)
@@ -609,6 +617,15 @@ class SIGfx12CacheControl : public SIGfx11CacheControl { bool setAtomicScope(const MachineBasicBlock::iterator &MI, SIAtomicScope Scope, SIAtomicAddrSpace AddrSpace) const; + bool canAffectGlobalAddrSpace(SIAtomicAddrSpace AS) const override { +assert((!ST.hasGloballyAddressableScratch() || ritter-x2a wrote: You're right, yes. The split into overridden functions originated from when I thought we'd need to handle GloballyAddressableScratch in this pass, but we don't need it as long as we keep replacing the problematic scratch atomics already in AtomicExpand. I've adjusted the PR accordingly. https://github.com/llvm/llvm-project/pull/160129 ___ 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] Introduce -fsanitize=alloc-token (PR #156839)
@@ -0,0 +1,45 @@ +// RUN: %clang_cc1-fsanitize=alloc-token -falloc-token-max=2147483647 -triple x86_64-linux-gnu -x c -emit-llvm %s -o - | FileCheck %s zmodem wrote: This and the alloc-token.cpp test are not just checking Clang's codegen output, but the output after the instrumentation pass as well. That means for example that we never see the metadata nodes here. I'm not sure how the clang-level tests for other sanitizers do it, but I think it's more common for CodeGen tests to check the output as clang emits it before transformations. https://github.com/llvm/llvm-project/pull/156839 ___ 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] Greedy: Move physreg check when trying to recolor vregs (NFC) (PR #160484)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/160484?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#160485** https://app.graphite.dev/github/pr/llvm/llvm-project/160485?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#160484** https://app.graphite.dev/github/pr/llvm/llvm-project/160484?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/160484?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#160424** https://app.graphite.dev/github/pr/llvm/llvm-project/160424?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/>: 1 other dependent PR ([#160467](https://github.com/llvm/llvm-project/pull/160467) https://app.graphite.dev/github/pr/llvm/llvm-project/160467?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/>) * **#160294** https://app.graphite.dev/github/pr/llvm/llvm-project/160294?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/160484 ___ 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] [llvm][mustache] Use StringRef parameters (PR #159190)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159190 >From ea687e4bb8c15a145e3ed5fa3482436917d705df Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Fri, 12 Sep 2025 00:24:31 -0700 Subject: [PATCH] [llvm][mustache] Use StringRef parameters --- llvm/lib/Support/Mustache.cpp | 21 +++-- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 2e29a6579bdea..f948344883452 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -11,6 +11,7 @@ #include "llvm/Support/raw_ostream.h" #include +#include #include #define DEBUG_TYPE "mustache" @@ -367,14 +368,14 @@ static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open, return Result; } -static void processTag(const Tag &T, SmallVectorImpl &Tokens, - SmallString<8> &Open, SmallString<8> &Close) { +static std::optional> +processTag(const Tag &T, SmallVectorImpl &Tokens) { LLVM_DEBUG(dbgs() << " Found tag: \"" << T.FullMatch << "\", Content: \"" << T.Content << "\"\n"); if (T.TagKind == Tag::Kind::Triple) { Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&'); LLVM_DEBUG(dbgs() << " Created UnescapeVariable token.\n"); -return; +return std::nullopt; } StringRef Interpolated = T.Content; std::string RawBody = T.FullMatch.str(); @@ -382,7 +383,7 @@ static void processTag(const Tag &T, SmallVectorImpl &Tokens, char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front(); Tokens.emplace_back(RawBody, Interpolated.str(), Front); LLVM_DEBUG(dbgs() << " Created tag token of type '" << Front << "'\n"); -return; +return std::nullopt; } Tokens.emplace_back(RawBody, Interpolated.str(), '='); StringRef DelimSpec = Interpolated.trim(); @@ -391,11 +392,9 @@ static void processTag(const Tag &T, SmallVectorImpl &Tokens, DelimSpec = DelimSpec.trim(); auto [NewOpen, NewClose] = DelimSpec.split(' '); - Open = NewOpen; - Close = NewClose; - - LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << Open -<< "', NewClose='" << Close << "'\n"); + LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << NewOpen +<< "', NewClose='" << NewClose << "'\n"); + return std::make_pair(NewOpen, NewClose); } // Simple tokenizer that splits the template into tokens. @@ -429,7 +428,9 @@ static SmallVector tokenize(StringRef Template) { LLVM_DEBUG(dbgs() << " Created Text token: \"" << Text << "\"\n"); } -processTag(T, Tokens, Open, Close); +if (auto NewDelims = processTag(T, Tokens)) { + std::tie(Open, Close) = *NewDelims; +} // Move past the tag. Start = T.StartPosition + T.FullMatch.size(); ___ 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] [llvm][mustache] Refactor tokenizer for clarity (PR #159188)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/159188 >From 8be25f43010ec6633f1d01f3f9641ec3fdaa486d Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Thu, 11 Sep 2025 23:45:16 -0700 Subject: [PATCH] [llvm][mustache] Refactor tokenizer for clarity This patch refactors the Mustache tokenizer by breaking the logic up with helper functions to improve clarity and simplify the code. --- llvm/lib/Support/Mustache.cpp | 49 +++ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp index 814b01d343585..6b009810dc667 100644 --- a/llvm/lib/Support/Mustache.cpp +++ b/llvm/lib/Support/Mustache.cpp @@ -549,11 +549,34 @@ class Parser { llvm::StringMap &SectionLambdas, EscapeMap &Escapes); + void parseSection(ASTNode *Parent, ASTNode::Type Ty, const Accessor &A, +llvm::StringMap &Partials, +llvm::StringMap &Lambdas, +llvm::StringMap &SectionLambdas, +EscapeMap &Escapes); + SmallVector Tokens; size_t CurrentPtr; StringRef TemplateStr; }; +void Parser::parseSection(ASTNode *Parent, ASTNode::Type Ty, const Accessor &A, + llvm::StringMap &Partials, + llvm::StringMap &Lambdas, + llvm::StringMap &SectionLambdas, + EscapeMap &Escapes) { + AstPtr CurrentNode = + createNode(Ty, A, Parent, Partials, Lambdas, SectionLambdas, Escapes); + size_t Start = CurrentPtr; + parseMustache(CurrentNode.get(), Partials, Lambdas, SectionLambdas, Escapes); + const size_t End = CurrentPtr - 1; + std::string RawBody; + for (std::size_t I = Start; I < End; I++) +RawBody += Tokens[I].RawBody; + CurrentNode->setRawBody(std::move(RawBody)); + Parent->addChild(std::move(CurrentNode)); +} + AstPtr Parser::parse(llvm::StringMap &Partials, llvm::StringMap &Lambdas, llvm::StringMap &SectionLambdas, @@ -603,31 +626,13 @@ void Parser::parseMustache(ASTNode *Parent, llvm::StringMap &Partials, break; } case Token::Type::SectionOpen: { - CurrentNode = createNode(ASTNode::Section, A, Parent, Partials, Lambdas, - SectionLambdas, Escapes); - size_t Start = CurrentPtr; - parseMustache(CurrentNode.get(), Partials, Lambdas, SectionLambdas, -Escapes); - const size_t End = CurrentPtr - 1; - std::string RawBody; - for (std::size_t I = Start; I < End; I++) -RawBody += Tokens[I].RawBody; - CurrentNode->setRawBody(std::move(RawBody)); - Parent->addChild(std::move(CurrentNode)); + parseSection(Parent, ASTNode::Section, A, Partials, Lambdas, + SectionLambdas, Escapes); break; } case Token::Type::InvertSectionOpen: { - CurrentNode = createNode(ASTNode::InvertSection, A, Parent, Partials, - Lambdas, SectionLambdas, Escapes); - size_t Start = CurrentPtr; - parseMustache(CurrentNode.get(), Partials, Lambdas, SectionLambdas, -Escapes); - const size_t End = CurrentPtr - 1; - std::string RawBody; - for (size_t Idx = Start; Idx < End; Idx++) -RawBody += Tokens[Idx].RawBody; - CurrentNode->setRawBody(std::move(RawBody)); - Parent->addChild(std::move(CurrentNode)); + parseSection(Parent, ASTNode::InvertSection, A, Partials, Lambdas, + SectionLambdas, Escapes); break; } case Token::Type::Comment: ___ 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/21.x: [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) (PR #160807)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/160807 ___ 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/21.x: [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) (PR #160807)
llvmbot wrote: @yingopq What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/160807 ___ 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/21.x: [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) (PR #160807)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/160807 Backport 114b3b8b04fe5aae4143e30078637015a9e077ce Requested by: @brad0 >From d7de14b58f74cb6301cdc629b985b10176e07294 Mon Sep 17 00:00:00 2001 From: yingopq <115543042+ying...@users.noreply.github.com> Date: Fri, 26 Sep 2025 11:29:13 +0800 Subject: [PATCH] [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) Modify instr movn/movz to mixture of beq, move, and sc. Because atomic-min-max.ll test broken on the expensive builder, I revert https://github.com/llvm/llvm-project/pull/149983 and resubmit this PR. The broken reason: In i16/i8 function expandAtomicBinOpSubword, we use two successor after loop2MBB, one does not specify the second parameter, the other use BranchProbability::getOne() that means 100% probability. This is contradictory. And the second successor is also specified incorrectly. The changess: * llvm/lib/Target/Mips/MipsExpandPseudo.cpp: Change loop2MBB`s second successor to correct one and delete the second parameter BranchProbability::getOne(). * llvm/test/CodeGen/Mips/atomic-min-max.ll: Add -verify-machineinstrs option in RUN command; Modify i16 test and i8 test according to the changes. Fix #145411. (cherry picked from commit 114b3b8b04fe5aae4143e30078637015a9e077ce) --- llvm/lib/Target/Mips/MipsExpandPseudo.cpp | 217 +++-- llvm/test/CodeGen/Mips/atomic-min-max.ll | 521 ++ 2 files changed, 712 insertions(+), 26 deletions(-) diff --git a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp index 34ff41f6e02da..78f2e5db40f9d 100644 --- a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp +++ b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp @@ -432,13 +432,24 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( Register OldVal = I->getOperand(6).getReg(); Register BinOpRes = I->getOperand(7).getReg(); Register StoreVal = I->getOperand(8).getReg(); + bool NoMovnInstr = (IsMin || IsMax) && !STI->hasMips4() && !STI->hasMips32(); const BasicBlock *LLVM_BB = BB.getBasicBlock(); MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); + MachineBasicBlock *loop1MBB = nullptr; + MachineBasicBlock *loop2MBB = nullptr; + if (NoMovnInstr) { +loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); +loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); + } MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); MachineFunction::iterator It = ++BB.getIterator(); MF->insert(It, loopMBB); + if (NoMovnInstr) { +MF->insert(It, loop1MBB); +MF->insert(It, loop2MBB); + } MF->insert(It, sinkMBB); MF->insert(It, exitMBB); @@ -446,9 +457,19 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( exitMBB->transferSuccessorsAndUpdatePHIs(&BB); BB.addSuccessor(loopMBB, BranchProbability::getOne()); - loopMBB->addSuccessor(sinkMBB); - loopMBB->addSuccessor(loopMBB); - loopMBB->normalizeSuccProbs(); + if (NoMovnInstr) { +loopMBB->addSuccessor(loop1MBB); +loopMBB->addSuccessor(loop2MBB); + } else { +loopMBB->addSuccessor(sinkMBB); +loopMBB->addSuccessor(loopMBB); +loopMBB->normalizeSuccProbs(); + } + if (NoMovnInstr) { +loop1MBB->addSuccessor(loop2MBB); +loop2MBB->addSuccessor(loopMBB); +loop2MBB->addSuccessor(sinkMBB); + } BuildMI(loopMBB, DL, TII->get(LL), OldVal).addReg(Ptr).addImm(0); if (IsNand) { @@ -525,7 +546,7 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( BuildMI(loopMBB, DL, TII->get(OR), BinOpRes) .addReg(BinOpRes) .addReg(Scratch4); -} else { +} else if (STI->hasMips4() || STI->hasMips32()) { // max: move BinOpRes, StoreVal // movn BinOpRes, Incr, Scratch4, BinOpRes // min: move BinOpRes, StoreVal @@ -537,12 +558,59 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( .addReg(Incr) .addReg(Scratch4) .addReg(BinOpRes); +} else { + // if min: + // loopMBB: move BinOpRes, StoreVal + // beq Scratch4, 0, loop1MBB + // j loop2MBB + // loop1MBB: move BinOpRes, Incr + // loop2MBB: and BinOpRes, BinOpRes, Mask + // and StoreVal, OlddVal, Mask2 + // or StoreVal, StoreVal, BinOpRes + // StoreVal = sc StoreVal, 0(Ptr) + // beq StoreVal, zero, loopMBB + // + // if max: + // loopMBB: move BinOpRes, Incr + // beq Scratch4, 0, loop1MBB + // j loop2MBB + // loop1MBB: move BinOpRes, StoreVal + // loop2MBB: and BinOpRes, BinOpRes, Mask + // and StoreVal, OlddVal, Mask2 + // or StoreVal, StoreVal, BinOpRes + // StoreVal = sc StoreVal, 0(Ptr) + // beq StoreVal, zero, loopMBB + if (IsMin) { +BuildMI(loopMBB, DL, TII->get(OR),
[llvm-branch-commits] [llvm] release/21.x: [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) (PR #160807)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/160807 ___ 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/21.x: [Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717) (PR #160807)
llvmbot wrote: @llvm/pr-subscribers-backend-mips Author: None (llvmbot) Changes Backport 114b3b8b04fe5aae4143e30078637015a9e077ce Requested by: @brad0 --- Patch is 31.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/160807.diff 2 Files Affected: - (modified) llvm/lib/Target/Mips/MipsExpandPseudo.cpp (+191-26) - (modified) llvm/test/CodeGen/Mips/atomic-min-max.ll (+521) ``diff diff --git a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp index 34ff41f6e02da..78f2e5db40f9d 100644 --- a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp +++ b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp @@ -432,13 +432,24 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( Register OldVal = I->getOperand(6).getReg(); Register BinOpRes = I->getOperand(7).getReg(); Register StoreVal = I->getOperand(8).getReg(); + bool NoMovnInstr = (IsMin || IsMax) && !STI->hasMips4() && !STI->hasMips32(); const BasicBlock *LLVM_BB = BB.getBasicBlock(); MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); + MachineBasicBlock *loop1MBB = nullptr; + MachineBasicBlock *loop2MBB = nullptr; + if (NoMovnInstr) { +loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); +loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); + } MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); MachineFunction::iterator It = ++BB.getIterator(); MF->insert(It, loopMBB); + if (NoMovnInstr) { +MF->insert(It, loop1MBB); +MF->insert(It, loop2MBB); + } MF->insert(It, sinkMBB); MF->insert(It, exitMBB); @@ -446,9 +457,19 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( exitMBB->transferSuccessorsAndUpdatePHIs(&BB); BB.addSuccessor(loopMBB, BranchProbability::getOne()); - loopMBB->addSuccessor(sinkMBB); - loopMBB->addSuccessor(loopMBB); - loopMBB->normalizeSuccProbs(); + if (NoMovnInstr) { +loopMBB->addSuccessor(loop1MBB); +loopMBB->addSuccessor(loop2MBB); + } else { +loopMBB->addSuccessor(sinkMBB); +loopMBB->addSuccessor(loopMBB); +loopMBB->normalizeSuccProbs(); + } + if (NoMovnInstr) { +loop1MBB->addSuccessor(loop2MBB); +loop2MBB->addSuccessor(loopMBB); +loop2MBB->addSuccessor(sinkMBB); + } BuildMI(loopMBB, DL, TII->get(LL), OldVal).addReg(Ptr).addImm(0); if (IsNand) { @@ -525,7 +546,7 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( BuildMI(loopMBB, DL, TII->get(OR), BinOpRes) .addReg(BinOpRes) .addReg(Scratch4); -} else { +} else if (STI->hasMips4() || STI->hasMips32()) { // max: move BinOpRes, StoreVal // movn BinOpRes, Incr, Scratch4, BinOpRes // min: move BinOpRes, StoreVal @@ -537,12 +558,59 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword( .addReg(Incr) .addReg(Scratch4) .addReg(BinOpRes); +} else { + // if min: + // loopMBB: move BinOpRes, StoreVal + // beq Scratch4, 0, loop1MBB + // j loop2MBB + // loop1MBB: move BinOpRes, Incr + // loop2MBB: and BinOpRes, BinOpRes, Mask + // and StoreVal, OlddVal, Mask2 + // or StoreVal, StoreVal, BinOpRes + // StoreVal = sc StoreVal, 0(Ptr) + // beq StoreVal, zero, loopMBB + // + // if max: + // loopMBB: move BinOpRes, Incr + // beq Scratch4, 0, loop1MBB + // j loop2MBB + // loop1MBB: move BinOpRes, StoreVal + // loop2MBB: and BinOpRes, BinOpRes, Mask + // and StoreVal, OlddVal, Mask2 + // or StoreVal, StoreVal, BinOpRes + // StoreVal = sc StoreVal, 0(Ptr) + // beq StoreVal, zero, loopMBB + if (IsMin) { +BuildMI(loopMBB, DL, TII->get(OR), BinOpRes) +.addReg(StoreVal) +.addReg(Mips::ZERO); +BuildMI(loop1MBB, DL, TII->get(OR), BinOpRes) +.addReg(Incr) +.addReg(Mips::ZERO); + } else { +BuildMI(loopMBB, DL, TII->get(OR), BinOpRes) +.addReg(Incr) +.addReg(Mips::ZERO); +BuildMI(loop1MBB, DL, TII->get(OR), BinOpRes) +.addReg(StoreVal) +.addReg(Mips::ZERO); + } + BuildMI(loopMBB, DL, TII->get(BEQ)) + .addReg(Scratch4) + .addReg(Mips::ZERO) + .addMBB(loop1MBB); + BuildMI(loopMBB, DL, TII->get(Mips::J)).addMBB(loop2MBB); } // and BinOpRes, BinOpRes, Mask -BuildMI(loopMBB, DL, TII->get(Mips::AND), BinOpRes) -.addReg(BinOpRes) -.addReg(Mask); +if (NoMovnInstr) + BuildMI(loop2MBB, DL, TII->get(Mips::AND), BinOpRes) + .addReg(BinOpRes) + .addReg(Mask); +else + BuildMI(loopMBB, DL, TII->get(Mips::AND), BinOpRes) + .addReg(BinOpRes) + .addReg(Mask); } else i
[llvm-branch-commits] [llvm] [AllocToken] Introduce AllocToken instrumentation pass (PR #156838)
@@ -0,0 +1,471 @@ +//===- AllocToken.cpp - Allocation token instrumentation --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file implements AllocToken, an instrumentation pass that +// replaces allocation calls with token-enabled versions. +// +//===--===// + +#include "llvm/Transforms/Instrumentation/AllocToken.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/IR/Analysis.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/IR/Type.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/RandomNumberGenerator.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/xxhash.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace llvm; + +#define DEBUG_TYPE "alloc-token" + +namespace { + +//===--- Constants ===// + +enum class TokenMode : unsigned { + /// Incrementally increasing token ID. + Increment = 0, + + /// Simple mode that returns a statically-assigned random token ID. + Random = 1, + + /// Token ID based on allocated type hash. + TypeHash = 2, +}; + +//===--- Command-line options -===// + +cl::opt +ClMode("alloc-token-mode", cl::Hidden, cl::desc("Token assignment mode"), + cl::init(TokenMode::TypeHash), + cl::values(clEnumValN(TokenMode::Increment, "increment", + "Incrementally increasing token ID"), + clEnumValN(TokenMode::Random, "random", + "Statically-assigned random token ID"), + clEnumValN(TokenMode::TypeHash, "typehash", + "Token ID based on allocated type hash"))); + +cl::opt ClFuncPrefix("alloc-token-prefix", + cl::desc("The allocation function prefix"), + cl::Hidden, cl::init("__alloc_token_")); + +cl::opt ClMaxTokens("alloc-token-max", + cl::desc("Maximum number of tokens (0 = no max)"), + cl::Hidden, cl::init(0)); + +cl::opt +ClFastABI("alloc-token-fast-abi", + cl::desc("The token ID is encoded in the function name"), + cl::Hidden, cl::init(false)); + +// Instrument libcalls only by default - compatible allocators only need to take +// care of providing standard allocation functions. With extended coverage, also +// instrument non-libcall allocation function calls with !alloc_token +// metadata. +cl::opt +ClExtended("alloc-token-extended", + cl::desc("Extend coverage to custom allocation functions"), + cl::Hidden, cl::init(false)); + +// C++ defines ::operator new (and variants) as replaceable (vs. standard +// library versions), which are nobuiltin, and are therefore not covered by +// isAllocationFn(). Cover by default, as users of AllocToken are already +// required to provide token-aware allocation functions (no defaults). +cl::opt ClCoverReplaceableNew("alloc-token-cover-replaceable-new", +cl::desc("Cover replaceable operator new"), +cl::Hidden, cl::init(true)); + +cl::opt ClFallbackToken( +"alloc-token-fallback", +cl::desc("The default fallback token where none could be determined"), +cl::Hidden, cl::init(0)); + +//===--- Statistics ---===// + +STATISTIC(NumFunctionsInstrumented, "Functions instrumented"); +STATISTIC(NumAllocationsInstrumented, "Allocations instrumented"); + +//===--===// + +/// Returns the !alloc_token metadata if available. +/// +/// Expected format is: !{} +MDNode *getAllocTokenMetadata(const
[llvm-branch-commits] [clang] [clang] simplify placeholder type deduction for constant template parameters (PR #160439)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/160439 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits