[llvm-branch-commits] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-18 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


___
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] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-18 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


___
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] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-18 Thread Balazs Benics via llvm-branch-commits

steakhal wrote:

Ah, it mixed the messages... Here it is:

- Removed unused `NumZ3QueriesDoneInEqClass`
- Added a new `crosscheck-with-z3-eqclass-timeout-threshold` config option.
- Removed misleading `// unsat` comment on return statement.
- Removed unnecessary `// sat` comment on return statement.
- Adjusted the name of the two last unit-tests. 

https://github.com/llvm/llvm-project/pull/95129
___
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/18.x: [SystemZ] Bugfix in getDemandedSrcElements(). (#88623) (PR #95463)

2024-06-18 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

@tstellar Per 
https://github.com/llvm/llvm-project/issues/95454#issuecomment-2166748656 this 
is not an LLVM 18 regression, so I'm not sure it counts as critical. The fix 
does look safe though.

https://github.com/llvm/llvm-project/pull/95463
___
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] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-18 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


___
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] [analyzer] Harden safeguards for Z3 query times (PR #95129)

2024-06-18 Thread Balazs Benics via llvm-branch-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/95129


___
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] bbcee74 - Revert "[analyzer] Harden safeguards for Z3 query times"

2024-06-18 Thread via llvm-branch-commits

Author: Balazs Benics
Date: 2024-06-18T14:50:00+02:00
New Revision: bbcee744465c72b8000321defd85ed3daa290502

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

LOG: Revert "[analyzer] Harden safeguards for Z3 query times"

This reverts commit eacc3b3504be061f7334410dd0eb599688ba103a.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
clang/test/Analysis/analyzer-config.c
clang/unittests/StaticAnalyzer/Z3CrosscheckOracleTest.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 29aa6a3b8a16e..f008c9c581d95 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -184,26 +184,6 @@ ANALYZER_OPTION(bool, ShouldCrosscheckWithZ3, 
"crosscheck-with-z3",
 "constraint manager backend.",
 false)
 
-ANALYZER_OPTION(
-unsigned, Z3CrosscheckEQClassTimeoutThreshold,
-"crosscheck-with-z3-eqclass-timeout-threshold",
-"Set a timeout for bug report equivalence classes in milliseconds. "
-"If we exhaust this threshold, we will drop the bug report eqclass "
-"instead of doing more Z3 queries. Set 0 for no timeout.", 700)
-
-ANALYZER_OPTION(
-unsigned, Z3CrosscheckTimeoutThreshold,
-"crosscheck-with-z3-timeout-threshold",
-"Set a timeout for individual Z3 queries in milliseconds. "
-"Set 0 for no timeout.", 300)
-
-ANALYZER_OPTION(
-unsigned, Z3CrosscheckRLimitThreshold,
-"crosscheck-with-z3-rlimit-threshold",
-"Set the Z3 resource limit threshold. This sets a deterministic cutoff "
-"point for Z3 queries, as longer queries usually consume more resources. "
-"Set 0 for unlimited.", 400'000)
-
 ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile,
 "report-in-main-source-file",
 "Whether or not the diagnostic report should be always "

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
index 439f37fa8604f..9413fd739f607 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h
@@ -25,11 +25,8 @@ class Z3CrosscheckVisitor final : public BugReporterVisitor {
 public:
   struct Z3Result {
 std::optional IsSAT = std::nullopt;
-unsigned Z3QueryTimeMilliseconds = 0;
-unsigned UsedRLimit = 0;
   };
-  Z3CrosscheckVisitor(Z3CrosscheckVisitor::Z3Result &Result,
-  const AnalyzerOptions &Opts);
+  explicit Z3CrosscheckVisitor(Z3CrosscheckVisitor::Z3Result &Result);
 
   void Profile(llvm::FoldingSetNodeID &ID) const override;
 
@@ -47,44 +44,21 @@ class Z3CrosscheckVisitor final : public BugReporterVisitor 
{
   /// Holds the constraints in a given path.
   ConstraintMap Constraints;
   Z3Result &Result;
-  const AnalyzerOptions &Opts;
 };
 
 /// The oracle will decide if a report should be accepted or rejected based on
-/// the results of the Z3 solver and the statistics of the queries of a report
-/// equivalenece class.
+/// the results of the Z3 solver.
 class Z3CrosscheckOracle {
 public:
-  explicit Z3CrosscheckOracle(const AnalyzerOptions &Opts) : Opts(Opts) {}
-
   enum Z3Decision {
-AcceptReport,  // The report was SAT.
-RejectReport,  // The report was UNSAT or UNDEF.
-RejectEQClass, // The heuristic suggests to skip the current eqclass.
+AcceptReport, // The report was SAT.
+RejectReport, // The report was UNSAT or UNDEF.
   };
 
-  /// Updates the internal state with the new Z3Result and makes a decision how
-  /// to proceed:
-  /// - Accept the report if the Z3Result was SAT.
-  /// - Suggest dropping the report equvalence class based on the accumulated
-  ///   statistics.
-  /// - Otherwise, reject the report if the Z3Result was UNSAT or UNDEF.
-  ///
-  /// Conditions for dropping the equivalence class:
-  /// - Accumulative time spent in Z3 checks is more than 700ms in the eqclass.
-  /// - Hit the 300ms query timeout in the report eqclass.
-  /// - Hit the 400'000 rlimit in the report eqclass.
-  ///
-  /// All these thresholds are configurable via the analyzer options.
-  ///
-  /// Refer to
-  /// https://discourse.llvm.org/t/analyzer-rfc-taming-z3-query-times/79520 to
-  /// see why this heuristic was chosen.
-  Z3Decision interpretQueryResult(const Z3CrosscheckVisitor::Z3Result &Meta);

[llvm-branch-commits] [clang] [llvm] AMDGPU: Remove ds atomic fadd intrinsics (PR #95396)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/95396

>From 62be4ae64075ec326ed81e0905f3eb3979ad Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 10 Jun 2024 19:48:13 +0200
Subject: [PATCH] AMDGPU: Remove ds atomic fadd intrinsics

These have been replaced with atomicrmw fadd
---
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |   5 -
 llvm/lib/IR/AutoUpgrade.cpp   |  92 --
 llvm/lib/Target/AMDGPU/AMDGPUInstructions.td  |   1 -
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |   3 -
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   3 +-
 .../Target/AMDGPU/AMDGPUSearchableTables.td   |   2 -
 .../AMDGPU/AMDGPUTargetTransformInfo.cpp  |   3 -
 llvm/lib/Target/AMDGPU/DSInstructions.td  |  10 -
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  15 -
 llvm/test/Bitcode/amdgcn-atomic.ll| 136 +
 .../AMDGPU/GlobalISel/fp-atomics-gfx940.ll|  55 
 .../AMDGPU/GlobalISel/fp64-atomics-gfx90a.ll  | 125 +---
 .../AMDGPU/GlobalISel/llvm.amdgcn.ds.fadd.ll  | 279 --
 .../test/CodeGen/AMDGPU/fp-atomics-gfx1200.ll | 102 ---
 llvm/test/CodeGen/AMDGPU/fp-atomics-gfx940.ll |  13 +-
 .../CodeGen/AMDGPU/fp64-atomics-gfx90a.ll |  38 ++-
 llvm/test/CodeGen/AMDGPU/lds-atomic-fadd.ll   |  25 --
 18 files changed, 255 insertions(+), 654 deletions(-)
 delete mode 100644 llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.ds.fadd.ll
 delete mode 100644 llvm/test/CodeGen/AMDGPU/lds-atomic-fadd.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d81cf40c912de..34d7e59ca45fd 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19084,7 +19084,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   ProcessOrderScopeAMDGCN(EmitScalarExpr(E->getArg(2)),
   EmitScalarExpr(E->getArg(3)), AO, SSID);
 } else {
-  // The ds_fadd_* builtins do not have syncscope/order arguments.
+  // The ds_atomic_fadd_* builtins do not have syncscope/order arguments.
   SSID = llvm::SyncScope::System;
   AO = AtomicOrdering::SequentiallyConsistent;
 
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 8a5566ae12020..7a5e919fe26e3 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -571,7 +571,6 @@ def int_amdgcn_ds_ordered_swap : AMDGPUDSOrderedIntrinsic;
 def int_amdgcn_ds_append : AMDGPUDSAppendConsumedIntrinsic;
 def int_amdgcn_ds_consume : AMDGPUDSAppendConsumedIntrinsic;
 
-def int_amdgcn_ds_fadd : AMDGPULDSIntrin;
 def int_amdgcn_ds_fmin : AMDGPULDSIntrin;
 def int_amdgcn_ds_fmax : AMDGPULDSIntrin;
 
@@ -2930,10 +2929,6 @@ multiclass AMDGPUMFp8SmfmacIntrinsic {
 // bf16 atomics use v2i16 argument since there is no bf16 data type in the 
llvm.
 def int_amdgcn_global_atomic_fadd_v2bf16 : AMDGPUAtomicRtn;
 def int_amdgcn_flat_atomic_fadd_v2bf16   : AMDGPUAtomicRtn;
-def int_amdgcn_ds_fadd_v2bf16 : DefaultAttrsIntrinsic<
-[llvm_v2i16_ty],
-[LLVMQualPointerType<3>, llvm_v2i16_ty],
-[IntrArgMemOnly, NoCapture>]>;
 
 defset list AMDGPUMFMAIntrinsics940 = {
 def int_amdgcn_mfma_i32_16x16x32_i8 : AMDGPUMfmaIntrinsic;
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 2f4b8351e747a..29310ad79ef70 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1033,6 +1033,12 @@ static bool upgradeIntrinsicFunction1(Function *F, 
Function *&NewFn,
 break; // No other 'amdgcn.atomic.*'
   }
 
+  if (Name.starts_with("ds.fadd")) {
+// Replaced with atomicrmw fadd, so there's no new declaration.
+NewFn = nullptr;
+return true;
+  }
+
   if (Name.starts_with("ldexp.")) {
 // Target specific intrinsic became redundant
 NewFn = Intrinsic::getDeclaration(
@@ -2331,40 +2337,74 @@ static Value *upgradeARMIntrinsicCall(StringRef Name, 
CallBase *CI, Function *F,
   llvm_unreachable("Unknown function for ARM CallBase upgrade.");
 }
 
+// These are expected to have the arguments:
+// atomic.intrin (ptr, rmw_value, ordering, scope, isVolatile)
+//
+// Except for int_amdgcn_ds_fadd_v2bf16 which only has (ptr, rmw_value).
+//
 static Value *upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI,
  Function *F, IRBuilder<> &Builder) {
-  const bool IsInc = Name.starts_with("atomic.inc.");
-  if (IsInc || Name.starts_with("atomic.dec.")) {
-if (CI->getNumOperands() != 6) // Malformed bitcode.
-  return nullptr;
+  AtomicRMWInst::BinOp RMWOp =
+  StringSwitch(Name)
+  .StartsWith("ds.fadd", AtomicRMWInst::FAdd)
+  .StartsWith("atomic.inc.", AtomicRMWInst::UIncWrap)
+  .StartsWith("atomic.dec.", AtomicRMWInst::UDecWrap);
+
+  unsigned NumOperands = CI->getNumOperands();
+  if (N

[llvm-branch-commits] [llvm] AMDGPU: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/95930

Annoyingly gfx90a/940 support this for global/flat but not buffer.

>From 3bf1ef74e41889bfc70f8795e0fadb6031122286 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 18 Jun 2024 15:48:20 +0200
Subject: [PATCH] AMDGPU: Handle legal v2bf16 atomicrmw fadd for gfx12

Annoyingly gfx90a/940 support this for global/flat but not buffer.
---
 llvm/lib/Target/AMDGPU/AMDGPU.td  |  12 +-
 llvm/lib/Target/AMDGPU/BUFInstructions.td |   7 +-
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   5 +
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |   7 +-
 .../buffer-fat-pointer-atomicrmw-fadd.ll  | 147 ++
 5 files changed, 36 insertions(+), 142 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index cb5ceb9959325..060358cc310bb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -743,6 +743,12 @@ def FeatureAtomicGlobalPkAddBF16Inst : 
SubtargetFeature<"atomic-global-pk-add-bf
  [FeatureFlatGlobalInsts]
 >;
 
+def FeatureAtomicBufferPkAddBF16Inst : 
SubtargetFeature<"atomic-buffer-pk-add-bf16-inst",
+ "HasAtomicBufferPkAddBF16Inst",
+ "true",
+ "Has buffer_atomic_pk_add_bf16 instruction"
+>;
+
 def FeatureAtomicCSubNoRtnInsts : SubtargetFeature<"atomic-csub-no-rtn-insts",
   "HasAtomicCSubNoRtnInsts",
   "true",
@@ -1560,6 +1566,7 @@ def FeatureISAVersion12 : FeatureSet<
FeatureAtomicFlatPkAdd16Insts,
FeatureAtomicBufferGlobalPkAddF16Insts,
FeatureAtomicGlobalPkAddBF16Inst,
+   FeatureAtomicBufferPkAddBF16Inst,
FeatureFlatAtomicFaddF32Inst,
FeatureImageInsts,
FeatureExtendedImageInsts,
@@ -2120,7 +2127,10 @@ def HasAtomicBufferGlobalPkAddF16Insts
   AssemblerPredicate<(all_of FeatureAtomicBufferGlobalPkAddF16Insts)>;
 def HasAtomicGlobalPkAddBF16Inst
   : Predicate<"Subtarget->hasAtomicGlobalPkAddBF16Inst()">,
-  AssemblerPredicate<(all_of FeatureAtomicGlobalPkAddBF16Inst)>;
+AssemblerPredicate<(all_of FeatureAtomicGlobalPkAddBF16Inst)>;
+def HasAtomicBufferPkAddBF16Inst
+  : Predicate<"Subtarget->hasAtomicBufferPkAddBF16Inst()">,
+AssemblerPredicate<(all_of FeatureAtomicBufferPkAddBF16Inst)>;
 def HasFlatAtomicFaddF32Inst
   : Predicate<"Subtarget->hasFlatAtomicFaddF32Inst()">,
   AssemblerPredicate<(all_of FeatureFlatAtomicFaddF32Inst)>;
diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index 21335e9b64647..1c0dce0990571 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -1241,7 +1241,9 @@ let SubtargetPredicate = isGFX12Plus in {
 defm BUFFER_ATOMIC_COND_SUB_U32 : MUBUF_Pseudo_Atomics <
   "buffer_atomic_cond_sub_u32", VGPR_32, i32
 >;
+}
 
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
 let FPAtomic = 1 in
 defm BUFFER_ATOMIC_PK_ADD_BF16 : MUBUF_Pseudo_Atomics <
   "buffer_atomic_pk_add_bf16", VGPR_32, v2bf16
@@ -1735,8 +1737,11 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, 
"BUFFER_ATOMIC_DEC_X2">;
 let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
 defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
 
-let SubtargetPredicate = isGFX12Plus in {
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_fadd", v2bf16, 
"BUFFER_ATOMIC_PK_ADD_BF16_VBUFFER">;
+}
+
+let SubtargetPredicate = isGFX12Plus in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_cond_sub_u32", i32, 
"BUFFER_ATOMIC_COND_SUB_U32_VBUFFER", ["ret"]>;
 
   let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index db5b467f22389..fb565fbf49804 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -167,6 +167,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool HasAtomicBufferGlobalPkAddF16Insts = false;
   bool HasAtomicCSubNoRtnInsts = false;
   bool HasAtomicGlobalPkAddBF16Inst = false;
+  bool HasAtomicBufferPkAddBF16Inst = false;
   bool HasFlatAtomicFaddF32Inst = false;
   bool HasDefaultComponentZero = false;
   bool HasDefaultComponentBroadcast = false;
@@ -844,6 +845,10 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
 return HasAtomicGlobalPkAddBF16Inst;
   }
 
+  bool hasAtomicBufferPkAddBF16Inst() const {
+return HasAtomicBufferPkAddBF16Inst;
+  }
+
   bool hasFlatAtomicFaddF32Inst() const { return HasFlatAtomicFaddF32Inst; }
 
   bool hasDefaultComponentZero() const { return HasDefaultComponentZero; }
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 777d4061da877..ef500a4836eb8 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -16037,9 +16037,10 @@ 
SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *R

[llvm-branch-commits] [llvm] AMDGPU: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits

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/95930?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#95930** https://app.graphite.dev/github/pr/llvm/llvm-project/95930?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈
* **#95929** https://app.graphite.dev/github/pr/llvm/llvm-project/95929?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 Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @arsenm and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/95930
___
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: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)


Changes

Annoyingly gfx90a/940 support this for global/flat but not buffer.

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


5 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPU.td (+11-1) 
- (modified) llvm/lib/Target/AMDGPU/BUFInstructions.td (+6-1) 
- (modified) llvm/lib/Target/AMDGPU/GCNSubtarget.h (+5) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+4-3) 
- (modified) llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-atomicrmw-fadd.ll 
(+10-137) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index cb5ceb9959325..060358cc310bb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -743,6 +743,12 @@ def FeatureAtomicGlobalPkAddBF16Inst : 
SubtargetFeature<"atomic-global-pk-add-bf
  [FeatureFlatGlobalInsts]
 >;
 
+def FeatureAtomicBufferPkAddBF16Inst : 
SubtargetFeature<"atomic-buffer-pk-add-bf16-inst",
+ "HasAtomicBufferPkAddBF16Inst",
+ "true",
+ "Has buffer_atomic_pk_add_bf16 instruction"
+>;
+
 def FeatureAtomicCSubNoRtnInsts : SubtargetFeature<"atomic-csub-no-rtn-insts",
   "HasAtomicCSubNoRtnInsts",
   "true",
@@ -1560,6 +1566,7 @@ def FeatureISAVersion12 : FeatureSet<
FeatureAtomicFlatPkAdd16Insts,
FeatureAtomicBufferGlobalPkAddF16Insts,
FeatureAtomicGlobalPkAddBF16Inst,
+   FeatureAtomicBufferPkAddBF16Inst,
FeatureFlatAtomicFaddF32Inst,
FeatureImageInsts,
FeatureExtendedImageInsts,
@@ -2120,7 +2127,10 @@ def HasAtomicBufferGlobalPkAddF16Insts
   AssemblerPredicate<(all_of FeatureAtomicBufferGlobalPkAddF16Insts)>;
 def HasAtomicGlobalPkAddBF16Inst
   : Predicate<"Subtarget->hasAtomicGlobalPkAddBF16Inst()">,
-  AssemblerPredicate<(all_of FeatureAtomicGlobalPkAddBF16Inst)>;
+AssemblerPredicate<(all_of FeatureAtomicGlobalPkAddBF16Inst)>;
+def HasAtomicBufferPkAddBF16Inst
+  : Predicate<"Subtarget->hasAtomicBufferPkAddBF16Inst()">,
+AssemblerPredicate<(all_of FeatureAtomicBufferPkAddBF16Inst)>;
 def HasFlatAtomicFaddF32Inst
   : Predicate<"Subtarget->hasFlatAtomicFaddF32Inst()">,
   AssemblerPredicate<(all_of FeatureFlatAtomicFaddF32Inst)>;
diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index 21335e9b64647..1c0dce0990571 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -1241,7 +1241,9 @@ let SubtargetPredicate = isGFX12Plus in {
 defm BUFFER_ATOMIC_COND_SUB_U32 : MUBUF_Pseudo_Atomics <
   "buffer_atomic_cond_sub_u32", VGPR_32, i32
 >;
+}
 
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
 let FPAtomic = 1 in
 defm BUFFER_ATOMIC_PK_ADD_BF16 : MUBUF_Pseudo_Atomics <
   "buffer_atomic_pk_add_bf16", VGPR_32, v2bf16
@@ -1735,8 +1737,11 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, 
"BUFFER_ATOMIC_DEC_X2">;
 let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
 defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
 
-let SubtargetPredicate = isGFX12Plus in {
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_fadd", v2bf16, 
"BUFFER_ATOMIC_PK_ADD_BF16_VBUFFER">;
+}
+
+let SubtargetPredicate = isGFX12Plus in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_cond_sub_u32", i32, 
"BUFFER_ATOMIC_COND_SUB_U32_VBUFFER", ["ret"]>;
 
   let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index db5b467f22389..fb565fbf49804 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -167,6 +167,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool HasAtomicBufferGlobalPkAddF16Insts = false;
   bool HasAtomicCSubNoRtnInsts = false;
   bool HasAtomicGlobalPkAddBF16Inst = false;
+  bool HasAtomicBufferPkAddBF16Inst = false;
   bool HasFlatAtomicFaddF32Inst = false;
   bool HasDefaultComponentZero = false;
   bool HasDefaultComponentBroadcast = false;
@@ -844,6 +845,10 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
 return HasAtomicGlobalPkAddBF16Inst;
   }
 
+  bool hasAtomicBufferPkAddBF16Inst() const {
+return HasAtomicBufferPkAddBF16Inst;
+  }
+
   bool hasFlatAtomicFaddF32Inst() const { return HasFlatAtomicFaddF32Inst; }
 
   bool hasDefaultComponentZero() const { return HasDefaultComponentZero; }
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp 
b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 777d4061da877..ef500a4836eb8 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -16037,9 +16037,10 @@ 
SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
   if (Subtarget->hasAtomicBufferGlobalPkAddF16Insts() && isHalf2(Ty))
 return AtomicExpansionKind::None;
 
-  // TODO: Handle <2 x bfloat> case. Whi

[llvm-branch-commits] [llvm] AMDGPU: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/95930
___
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] Split fmv and extensions (PR #92882)

2024-06-18 Thread Tomas Matheson via llvm-branch-commits

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -76,12 +81,71 @@ class zoned_time {
 
   _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
 requires(requires { __traits::locate_zone(string_view{}); } &&
- // constructible_from
- // would create a dependency on itself. Instead depend on the fact
- // a constructor taking a _TimeZonePtr exists.
  constructible_from<_TimeZonePtr, 
decltype(__traits::locate_zone(string_view{}))>)
   : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
 
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& 
__zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
sys_time<_Duration>& __tp)
+  : __zone_{std::move(__zone)}, __tp_{__tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
sys_time<_Duration>& __tp)
+requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp)
+requires(is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{})),

ldionne wrote:

```suggestion
requires is_constructible && 
is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
```

The constraint in http://eel.is/c++draft/time.zone#zonedtime.ctor-18.sentence-1 
is:
> Constraints: zoned_time is constructible from the return type of 
> `traits​::​locate_zone(name)` and `tp`.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits

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

This generally LGTM but the constraints seem wrong, so I'd like to see again 
once that is figured out.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -76,12 +81,71 @@ class zoned_time {
 
   _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
 requires(requires { __traits::locate_zone(string_view{}); } &&
- // constructible_from
- // would create a dependency on itself. Instead depend on the fact
- // a constructor taking a _TimeZonePtr exists.
  constructible_from<_TimeZonePtr, 
decltype(__traits::locate_zone(string_view{}))>)
   : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
 
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& 
__zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
sys_time<_Duration>& __tp)
+  : __zone_{std::move(__zone)}, __tp_{__tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
sys_time<_Duration>& __tp)
+requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }

ldionne wrote:

Similar comment about the constraint here.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,105 @@
+//===--===/
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-experimental-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// template
+// class zoned_time;
+//
+// zoned_time(string_view name, const local_time& st, choose c);
+
+#include 
+#include 
+#include 
+
+#include "test_offset_time_zone.h"
+
+int main(int, char**) {
+  // Tests unique conversions. To make sure the test is does not depend on 
changes
+  // in the database it uses a time zone with a fixed offset.

ldionne wrote:

```suggestion
  // Tests unique conversions. To make sure the test does not depend on changes
  // in the database it uses a time zone with a fixed offset.
```

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -76,12 +81,71 @@ class zoned_time {
 
   _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
 requires(requires { __traits::locate_zone(string_view{}); } &&
- // constructible_from
- // would create a dependency on itself. Instead depend on the fact
- // a constructor taking a _TimeZonePtr exists.
  constructible_from<_TimeZonePtr, 
decltype(__traits::locate_zone(string_view{}))>)
   : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
 
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& 
__zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
sys_time<_Duration>& __tp)
+  : __zone_{std::move(__zone)}, __tp_{__tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
sys_time<_Duration>& __tp)
+requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp)
+requires(is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp, choose __c)
+requires(is_convertible_v<
+decltype(std::declval<_TimeZonePtr&>() -> 
to_sys(local_time<_Duration>{}, choose::earliest)),
+sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp, __c)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp, choose __c)
+requires(requires {

ldionne wrote:

Constraint.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -76,12 +81,71 @@ class zoned_time {
 
   _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
 requires(requires { __traits::locate_zone(string_view{}); } &&
- // constructible_from
- // would create a dependency on itself. Instead depend on the fact
- // a constructor taking a _TimeZonePtr exists.
  constructible_from<_TimeZonePtr, 
decltype(__traits::locate_zone(string_view{}))>)
   : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
 
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& 
__zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
sys_time<_Duration>& __tp)
+  : __zone_{std::move(__zone)}, __tp_{__tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
sys_time<_Duration>& __tp)
+requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp)
+requires(is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp, choose __c)
+requires(is_convertible_v<
+decltype(std::declval<_TimeZonePtr&>() -> 
to_sys(local_time<_Duration>{}, choose::earliest)),
+sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp, __c)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp, choose __c)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{}, choose::earliest)),
+  sys_time>)
+  : zoned_time{__traits::locate_zone(__name), __tp, __c} {}
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
+
+  // per wording choose has no effect
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt)
+requires(requires {

ldionne wrote:

Constraint.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -76,12 +81,71 @@ class zoned_time {
 
   _LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
 requires(requires { __traits::locate_zone(string_view{}); } &&
- // constructible_from
- // would create a dependency on itself. Instead depend on the fact
- // a constructor taking a _TimeZonePtr exists.
  constructible_from<_TimeZonePtr, 
decltype(__traits::locate_zone(string_view{}))>)
   : __zone_{__traits::locate_zone(__name)}, __tp_{} {}
 
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& 
__zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
sys_time<_Duration>& __tp)
+  : __zone_{std::move(__zone)}, __tp_{__tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
sys_time<_Duration>& __tp)
+requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp)
+requires(is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{})),
+  sys_time>)
+  : zoned_time{__traits::locate_zone(__name), __tp} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
local_time<_Duration>& __tp, choose __c)
+requires(is_convertible_v<
+decltype(std::declval<_TimeZonePtr&>() -> 
to_sys(local_time<_Duration>{}, choose::earliest)),
+sys_time>)
+  : __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp, __c)} {}
+
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
local_time<_Duration>& __tp, choose __c)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v() -> 
to_sys(local_time<_Duration>{}, choose::earliest)),
+  sys_time>)
+  : zoned_time{__traits::locate_zone(__name), __tp, __c} {}
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
+
+  // per wording choose has no effect
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose)
+requires is_convertible_v, sys_time<_Duration>>
+  : __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt)
+requires(requires {
+  _TimeZonePtr{__traits::locate_zone(string_view{})};
+} && is_convertible_v, sys_time<_Duration>>)
+  : zoned_time{__traits::locate_zone(__name), __zt} {}
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const 
zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose __c)
+requires(requires {

ldionne wrote:

Constraint.

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


[llvm-branch-commits] [libcxx] [libc++][TZDB] Finishes zoned_time constructors. (PR #95010)

2024-06-18 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,105 @@
+//===--===/
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-experimental-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// template
+// class zoned_time;
+//
+// zoned_time(string_view name, const local_time& st, choose c);
+
+#include 
+#include 
+#include 
+
+#include "test_offset_time_zone.h"
+
+int main(int, char**) {
+  // Tests unique conversions. To make sure the test is does not depend on 
changes
+  // in the database it uses a time zone with a fixed offset.
+  {
+std::chrono::zoned_time zt{
+"Etc/GMT+1", std::chrono::local_seconds{std::chrono::seconds{0}}, 
std::chrono::choose::earliest};
+
+assert(zt.get_time_zone() == std::chrono::locate_zone("Etc/GMT+1"));
+assert(zt.get_sys_time() == 
std::chrono::sys_seconds{std::chrono::hours{1}});
+  }
+
+  // Tests ambiguous conversions.
+  {
+// Z Europe/Berlin 0:53:28 - LMT 1893 Ap
+// ...
+// 1 DE CE%sT 1980
+// 1 E CE%sT
+//
+// ...
+// R E 1981 ma - Mar lastSu 1u 1 S
+// R E 1996 ma - O lastSu 1u 0 -
+
+using namespace std::literals::chrono_literals;
+{
+  std::chrono::zoned_time zt{

ldionne wrote:

You could consider using `namespace cr = std::chrono` to shorten these tests.

https://github.com/llvm/llvm-project/pull/95010
___
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] [serialization] No transitive type change (PR #92511)

2024-06-18 Thread Ilya Biryukov via llvm-branch-commits

ilya-biryukov wrote:

I am happy to take a look, but will run out of time for it today. I will 
definitely do it tomorrow, though.

https://github.com/llvm/llvm-project/pull/92511
___
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: Start selecting flat/global atomicrmw fmin/fmax. (PR #95592)

2024-06-18 Thread Shilei Tian via llvm-branch-commits


@@ -1699,7 +1709,7 @@ multiclass SIBufferAtomicPat_Common RtnModes = ["ret", "noret"]> {
-  let SubtargetPredicate = HasUnrestrictedSOffset in {
+  let OtherPredicates = [HasUnrestrictedSOffset] in {

shiltian wrote:

A side question, what is the difference between `OtherPredicates` and 
`SubtargetPredicate`? It looks like you swapped a couple of them here.

https://github.com/llvm/llvm-project/pull/95592
___
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: Start selecting flat/global atomicrmw fmin/fmax. (PR #95592)

2024-06-18 Thread Shilei Tian via llvm-branch-commits

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

LG

https://github.com/llvm/llvm-project/pull/95592
___
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: Start selecting flat/global atomicrmw fmin/fmax. (PR #95592)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits


@@ -1699,7 +1709,7 @@ multiclass SIBufferAtomicPat_Common RtnModes = ["ret", "noret"]> {
-  let SubtargetPredicate = HasUnrestrictedSOffset in {
+  let OtherPredicates = [HasUnrestrictedSOffset] in {

arsenm wrote:

SubtargetPredicate is just one thing, and OtherPredicates is a list? The usage 
pattern consistency has been declining for a while 

https://github.com/llvm/llvm-project/pull/95592
___
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: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Stanislav Mekhanoshin via llvm-branch-commits


@@ -1735,8 +1737,11 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, 
"BUFFER_ATOMIC_DEC_X2">;
 let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
 defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
 
-let SubtargetPredicate = isGFX12Plus in {
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_fadd", v2bf16, 
"BUFFER_ATOMIC_PK_ADD_BF16_VBUFFER">;

rampitec wrote:

Should it use OtherPredicates = [HasAtomicBufferPkAddBF16Inst] and 
SubtargetPredicate = isGFX12Plus because VBUFFER opcode is used?

https://github.com/llvm/llvm-project/pull/95930
___
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: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Stanislav Mekhanoshin via llvm-branch-commits


@@ -743,6 +743,12 @@ def FeatureAtomicGlobalPkAddBF16Inst : 
SubtargetFeature<"atomic-global-pk-add-bf
  [FeatureFlatGlobalInsts]
 >;
 
+def FeatureAtomicBufferPkAddBF16Inst : 
SubtargetFeature<"atomic-buffer-pk-add-bf16-inst",

rampitec wrote:

I believe it is above FeatureAtomicGlobalPkAddBF16Instin downstream. Can you 
fix the order here or there?

https://github.com/llvm/llvm-project/pull/95930
___
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: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits


@@ -1735,8 +1737,11 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, 
"BUFFER_ATOMIC_DEC_X2">;
 let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
 defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
 
-let SubtargetPredicate = isGFX12Plus in {
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_fadd", v2bf16, 
"BUFFER_ATOMIC_PK_ADD_BF16_VBUFFER">;

arsenm wrote:

I think these should be inverted, the inner predicate should be the buffer 
thing 

https://github.com/llvm/llvm-project/pull/95930
___
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: Handle legal v2bf16 atomicrmw fadd for gfx12 (PR #95930)

2024-06-18 Thread Matt Arsenault via llvm-branch-commits


@@ -1735,8 +1737,11 @@ defm : SIBufferAtomicPat<"SIbuffer_atomic_dec", i64, 
"BUFFER_ATOMIC_DEC_X2">;
 let OtherPredicates = [HasAtomicCSubNoRtnInsts] in
 defm : SIBufferAtomicPat<"SIbuffer_atomic_csub", i32, "BUFFER_ATOMIC_CSUB", 
["noret"]>;
 
-let SubtargetPredicate = isGFX12Plus in {
+let SubtargetPredicate = HasAtomicBufferPkAddBF16Inst in {
   defm : SIBufferAtomicPat_Common<"SIbuffer_atomic_fadd", v2bf16, 
"BUFFER_ATOMIC_PK_ADD_BF16_VBUFFER">;

arsenm wrote:

I'm not really sure what VBUFFER is, but as far as I can tell the predicates 
are broken anyway. If you do select the non-VBUFFER version, something else 
breaks later and we don't have the negated predicate on the not-VBUFFER 
patterns 

https://github.com/llvm/llvm-project/pull/95930
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread shaw young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/95821

>From 92212c96ea169d26ac10bf8d750539bc5dd72c49 Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:39:02 -0700
Subject: [PATCH 1/6] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index f0fcb1c130002..2bca83c9d11ec 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -421,6 +421,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
   for (auto& [_, BF] : BC.getBinaryFunctions()) {
+if (!ProfiledFunctions.count(&BF))
+  continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
   }
 

>From 2497922ccc46e3189870563b1fe819b67172778d Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:39:39 -0700
Subject: [PATCH 2/6] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 2bca83c9d11ec..56474a67307ed 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -417,10 +417,10 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 
   // Uses the strict hash of profiled and binary functions to match functions
   // that are not matched by name or common name.
-  std::unordered_map StrictBinaryFunctionHashes;
+  std::unordered_map StrictBinaryFunctionHashes;
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
-  for (auto& [_, BF] : BC.getBinaryFunctions()) {
+  for (auto &[_, BF] : BC.getBinaryFunctions()) {
 if (!ProfiledFunctions.count(&BF))
   continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
@@ -428,7 +428,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
 
   for (auto YamlBF : YamlBP.Functions) {
 auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash);
-if (It != StrictBinaryFunctionHashes.end() && 
!ProfiledFunctions.count(It->second)) {
+if (It != StrictBinaryFunctionHashes.end() &&
+!ProfiledFunctions.count(It->second)) {
   auto *BF = It->second;
   matchProfileToFunction(YamlBF, *BF);
 }

>From 8e7b2229a69c3795e723404c56e0d4298eef412a Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:55:58 -0700
Subject: [PATCH 3/6] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp   | 2 +-
 bolt/test/X86/profile-passthrough-block.test | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 56474a67307ed..779d60bce3b66 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -421,7 +421,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
 
   for (auto &[_, BF] : BC.getBinaryFunctions()) {
-if (!ProfiledFunctions.count(&BF))
+if (ProfiledFunctions.count(&BF))
   continue;
 StrictBinaryFunctionHashes[BF.getHash()] = &BF;
   }
diff --git a/bolt/test/X86/profile-passthrough-block.test 
b/bolt/test/X86/profile-passthrough-block.test
index 1b875885260dc..ed2a8117ddfc4 100644
--- a/bolt/test/X86/profile-passthrough-block.test
+++ b/bolt/test/X86/profile-passthrough-block.test
@@ -57,7 +57,7 @@ header:
 functions:
   - name:main
 fid: 0
-hash:0x
+hash:0x0001
 exec:1
 nblocks: 6
 blocks:

>From ef5f0dac9185dbb7a62345938d4f309c3379a85d Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 15:58:22 -0700
Subject: [PATCH 4/6] spr amend

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 779d60bce3b66..e3d30bfdb74e4 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -427,6 +427,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   }
 
   for (auto YamlBF : YamlBP.Functions) {
+if (YamlBF.Used)
+  continue;
 auto It = StrictBinaryFunctionHashes.find(YamlBF.Hash);
 if (It != StrictBinaryFunctionHashes.end() &&
 !ProfiledFunctions.count(It->second)) {

>From 41ce2897a445e47dfe685da66b4af080824e78ed Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 17 Jun 2024 16:00:27 -0700
Subject: [PATCH 5/6] spr amend

Created using spr 1.3.4
---
 bolt/test/X86/profile-passthrough-block.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

dif

[llvm-branch-commits] [flang] 13a0c13 - Revert "[flang] Add FLANG_PARALLEL_COMPILE_JOBS option (#95672)"

2024-06-18 Thread via llvm-branch-commits

Author: Tom Stellard
Date: 2024-06-18T14:58:02-07:00
New Revision: 13a0c13519b356c004127cf23c79b57cd33fc969

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

LOG: Revert "[flang] Add FLANG_PARALLEL_COMPILE_JOBS option (#95672)"

This reverts commit 083c683969b2436afdc45becadc955841f5f4d31.

Added: 


Modified: 
flang/CMakeLists.txt
flang/cmake/modules/AddFlang.cmake

Removed: 




diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 75db5b93d4dbe..cbe8f1186236a 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -445,18 +445,6 @@ if (APPLE)
   endif()
 endif()
 
-# Set up job pools for flang.  Some of the flang sources take a lot of memory 
to
-# compile, so allow users to limit the number of parallel flang jobs.  This is
-# useful for building flang alongside several other projects since you can use
-# the maximum number of build jobs for the other projects while limiting the
-# number of flang compile jobs.
-#
-# We want this set to infinity by default
-set(FLANG_PARALLEL_COMPILE_JOBS 0 CACHE STRING
-  "The maximum number of concurrent compilation jobs (Ninja only)")
-
-set_property(GLOBAL APPEND PROPERTY JOB_POOLS 
flang_compile_job_pool=${FLANG_PARALLEL_COMPILE_JOBS})
-
 include(CMakeParseArguments)
 include(AddFlang)
 

diff  --git a/flang/cmake/modules/AddFlang.cmake 
b/flang/cmake/modules/AddFlang.cmake
index c4b957324ea1c..3a5119b83831f 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -89,7 +89,6 @@ function(add_flang_library name)
   set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
 endif()
 set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
-set_property(TARGET obj.${name} PROPERTY JOB_POOL_COMPILE 
flang_compile_job_pool)
   else()
 # Add empty "phony" target
 add_custom_target(${name})



___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93904

>From 20bbad26fa9f068910baf50b5abb60a0f4557564 Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:33:04 -0700
Subject: [PATCH 1/4] [clang] Define ptrauth_sign_constant builtin.

This is constant-expression equivalent to __builtin_ptrauth_sign,
allowing its usage in global initializers, but requiring constant
pointers and discriminators.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/CodeGen/CodeGenABITypes.h |   6 +
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  62 +
 clang/lib/CodeGen/CGPointerAuth.cpp   |  77 +++
 clang/lib/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/Headers/ptrauth.h   |  25 
 clang/lib/Sema/SemaChecking.cpp   | 128 --
 .../CodeGen/ptrauth-intrinsic-sign-constant.c |  20 +++
 clang/test/Sema/ptrauth-intrinsics-macro.c|   4 +
 clang/test/Sema/ptrauth.c |  28 
 14 files changed, 359 insertions(+), 14 deletions(-)
 create mode 100644 clang/lib/CodeGen/CGPointerAuth.cpp
 create mode 100644 clang/test/CodeGen/ptrauth-intrinsic-sign-constant.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e07ddf3b9b70b..9342b6bc75fc8 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4393,6 +4393,12 @@ def PtrauthSignUnauthenticated : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthSignConstant : Builtin {
+  let Spellings = ["__builtin_ptrauth_sign_constant"];
+  let Attributes = [CustomTypeChecking, NoThrow, Const, Constexpr];
+  let Prototype = "void*(void*,int,void*)";
+}
+
 def PtrauthSignGenericData : Builtin {
   let Spellings = ["__builtin_ptrauth_sign_generic_data"];
   let Attributes = [CustomTypeChecking, NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0900dad3c18cd..a5675879f45bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -924,6 +924,13 @@ def err_ptrauth_value_bad_type :
   Error<"%select{signed value|extra discriminator|blended pointer|blended "
 "integer}0 must have %select{pointer|integer|pointer or integer}1 "
 "type; type here is %2">;
+def err_ptrauth_bad_constant_pointer :
+  Error<"argument to ptrauth_sign_constant must refer to a global variable "
+"or function">;
+def err_ptrauth_bad_constant_discriminator :
+  Error<"discriminator argument to ptrauth_sign_constant must be a constant "
+"integer, the address of the global variable where the result "
+"will be stored, or a blend of the two">;
 def warn_ptrauth_sign_null_pointer :
   Warning<"signing a null pointer will yield a non-null pointer">,
   InGroup;
diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index fda0855dc8683..8c62d8597ecbe 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -104,6 +104,12 @@ llvm::Type *convertTypeForMemory(CodeGenModule &CGM, 
QualType T);
 unsigned getLLVMFieldNumber(CodeGenModule &CGM,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Return a signed constant pointer.
+llvm::Constant *getConstantSignedPointer(CodeGenModule &CGM,
+ llvm::Constant *pointer,
+ unsigned key,
+ llvm::Constant *storageAddress,
+ llvm::Constant *otherDiscriminator);
 /// Given the language and code-generation options that Clang was configured
 /// with, set the default LLVM IR attributes for a function definition.
 /// The attributes set here are mostly global target-configuration and
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 97b4c2080e14f..799872fe13c08 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2042,6 +2042,7 @@ static bool IsNoOpCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
   Builtin == Builtin::BI__builtin_function_start);
 }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..fd4fe1633ea29 100644
--- a/clang/li

[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits

https://github.com/ahmedbougacha updated 
https://github.com/llvm/llvm-project/pull/93904

>From 20bbad26fa9f068910baf50b5abb60a0f4557564 Mon Sep 17 00:00:00 2001
From: Ahmed Bougacha 
Date: Thu, 30 May 2024 17:33:04 -0700
Subject: [PATCH 1/5] [clang] Define ptrauth_sign_constant builtin.

This is constant-expression equivalent to __builtin_ptrauth_sign,
allowing its usage in global initializers, but requiring constant
pointers and discriminators.

Co-Authored-By: John McCall 
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/CodeGen/CodeGenABITypes.h |   6 +
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +
 clang/lib/CodeGen/CGExprConstant.cpp  |  62 +
 clang/lib/CodeGen/CGPointerAuth.cpp   |  77 +++
 clang/lib/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/Headers/ptrauth.h   |  25 
 clang/lib/Sema/SemaChecking.cpp   | 128 --
 .../CodeGen/ptrauth-intrinsic-sign-constant.c |  20 +++
 clang/test/Sema/ptrauth-intrinsics-macro.c|   4 +
 clang/test/Sema/ptrauth.c |  28 
 14 files changed, 359 insertions(+), 14 deletions(-)
 create mode 100644 clang/lib/CodeGen/CGPointerAuth.cpp
 create mode 100644 clang/test/CodeGen/ptrauth-intrinsic-sign-constant.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e07ddf3b9b70b..9342b6bc75fc8 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4393,6 +4393,12 @@ def PtrauthSignUnauthenticated : Builtin {
   let Prototype = "void*(void*,int,void*)";
 }
 
+def PtrauthSignConstant : Builtin {
+  let Spellings = ["__builtin_ptrauth_sign_constant"];
+  let Attributes = [CustomTypeChecking, NoThrow, Const, Constexpr];
+  let Prototype = "void*(void*,int,void*)";
+}
+
 def PtrauthSignGenericData : Builtin {
   let Spellings = ["__builtin_ptrauth_sign_generic_data"];
   let Attributes = [CustomTypeChecking, NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0900dad3c18cd..a5675879f45bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -924,6 +924,13 @@ def err_ptrauth_value_bad_type :
   Error<"%select{signed value|extra discriminator|blended pointer|blended "
 "integer}0 must have %select{pointer|integer|pointer or integer}1 "
 "type; type here is %2">;
+def err_ptrauth_bad_constant_pointer :
+  Error<"argument to ptrauth_sign_constant must refer to a global variable "
+"or function">;
+def err_ptrauth_bad_constant_discriminator :
+  Error<"discriminator argument to ptrauth_sign_constant must be a constant "
+"integer, the address of the global variable where the result "
+"will be stored, or a blend of the two">;
 def warn_ptrauth_sign_null_pointer :
   Warning<"signing a null pointer will yield a non-null pointer">,
   InGroup;
diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h 
b/clang/include/clang/CodeGen/CodeGenABITypes.h
index fda0855dc8683..8c62d8597ecbe 100644
--- a/clang/include/clang/CodeGen/CodeGenABITypes.h
+++ b/clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -104,6 +104,12 @@ llvm::Type *convertTypeForMemory(CodeGenModule &CGM, 
QualType T);
 unsigned getLLVMFieldNumber(CodeGenModule &CGM,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Return a signed constant pointer.
+llvm::Constant *getConstantSignedPointer(CodeGenModule &CGM,
+ llvm::Constant *pointer,
+ unsigned key,
+ llvm::Constant *storageAddress,
+ llvm::Constant *otherDiscriminator);
 /// Given the language and code-generation options that Clang was configured
 /// with, set the default LLVM IR attributes for a function definition.
 /// The attributes set here are mostly global target-configuration and
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 97b4c2080e14f..799872fe13c08 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2042,6 +2042,7 @@ static bool IsNoOpCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
   Builtin == Builtin::BI__builtin_function_start);
 }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..fd4fe1633ea29 100644
--- a/clang/li

[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s  
-o - | FileCheck %s
+
+extern int external;
+
+// CHECK: @ptr1 = global ptr ptrauth (ptr @external, i32 0, i64 26)
+void *ptr1 = __builtin_ptrauth_sign_constant(&external, 0, 26);
+
+// CHECK: @ptr2 = global ptr ptrauth (ptr @external, i32 2, i64 26, ptr @ptr2)
+void *ptr2 = __builtin_ptrauth_sign_constant(&external, 2, 
__builtin_ptrauth_blend_discriminator(&ptr2, 26));
+
+// CHECK: @ptr3 = global ptr null
+void *ptr3;

ahmedbougacha wrote:

(1) is an old artifact that I fixed separately, but (2) is interesting if we 
test real pointers, not necessarily just `NULL`;  added that and a few others

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2074,16 +2091,91 @@ static bool checkPointerAuthValue(Sema &S, Expr *&Arg,
   if (convertArgumentToType(S, Arg, ExpectedTy))
 return true;
 
-  // Warn about null pointers for non-generic sign and auth operations.
-  if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
-  Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) {
-S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
-  ? diag::warn_ptrauth_sign_null_pointer
-  : diag::warn_ptrauth_auth_null_pointer)
-<< Arg->getSourceRange();
+  if (!RequireConstant) {
+// Warn about null pointers for non-generic sign and auth operations.
+if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
+Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) 
{
+  S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
+? diag::warn_ptrauth_sign_null_pointer
+: diag::warn_ptrauth_auth_null_pointer)
+  << Arg->getSourceRange();
+}
+
+return false;
   }
 
-  return false;
+  // Perform special checking on the arguments to ptrauth_sign_constant.
+
+  // The main argument.
+  if (OpKind == PAO_Sign) {
+// Require the value we're signing to have a special form.
+auto BaseOffsetPair = findConstantBaseAndOffset(S, Arg);
+bool Invalid;
+
+// Must be rooted in a declaration reference.
+if (!BaseOffsetPair.first) {
+  Invalid = true;
+
+  // If it's a function declaration, we can't have an offset.
+} else if (isa(BaseOffsetPair.first)) {
+  Invalid = !BaseOffsetPair.second.isZero();
+
+  // Otherwise we're fine.
+} else {
+  Invalid = false;
+}
+
+if (Invalid) {
+  S.Diag(Arg->getExprLoc(), diag::err_ptrauth_bad_constant_pointer);
+}
+return Invalid;
+  }
+
+  // The discriminator argument.
+  assert(OpKind == PAO_Discriminator);
+
+  // Must be a pointer or integer or blend thereof.
+  Expr *Pointer = nullptr;
+  Expr *Integer = nullptr;
+  if (auto *Call = dyn_cast(Arg->IgnoreParens())) {
+if (Call->getBuiltinCallee() ==
+Builtin::BI__builtin_ptrauth_blend_discriminator) {
+  Pointer = Call->getArg(0);
+  Integer = Call->getArg(1);
+}
+  }
+  if (!Pointer && !Integer) {
+if (Arg->getType()->isPointerType())
+  Pointer = Arg;
+else
+  Integer = Arg;
+  }
+
+  // Check the pointer.
+  bool Invalid = false;
+  if (Pointer) {
+assert(Pointer->getType()->isPointerType());
+
+// TODO: if we're initializing a global, check that the address is
+// somehow related to what we're initializing.  This probably will
+// never really be feasible and we'll have to catch it at link-time.
+auto BaseOffsetPair = findConstantBaseAndOffset(S, Pointer);
+if (!BaseOffsetPair.first || !isa(BaseOffsetPair.first)) {
+  Invalid = true;

ahmedbougacha wrote:

The missing base was covered, but the VarDecl check wasn't I think;  I added 
tests where the discriminator is a function decl

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2074,16 +2091,91 @@ static bool checkPointerAuthValue(Sema &S, Expr *&Arg,
   if (convertArgumentToType(S, Arg, ExpectedTy))
 return true;
 
-  // Warn about null pointers for non-generic sign and auth operations.
-  if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
-  Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) {
-S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
-  ? diag::warn_ptrauth_sign_null_pointer
-  : diag::warn_ptrauth_auth_null_pointer)
-<< Arg->getSourceRange();
+  if (!RequireConstant) {
+// Warn about null pointers for non-generic sign and auth operations.
+if ((OpKind == PAO_Sign || OpKind == PAO_Auth) &&
+Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) 
{
+  S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
+? diag::warn_ptrauth_sign_null_pointer
+: diag::warn_ptrauth_auth_null_pointer)
+  << Arg->getSourceRange();
+}
+
+return false;
   }
 
-  return false;
+  // Perform special checking on the arguments to ptrauth_sign_constant.
+
+  // The main argument.
+  if (OpKind == PAO_Sign) {
+// Require the value we're signing to have a special form.
+auto BaseOffsetPair = findConstantBaseAndOffset(S, Arg);
+bool Invalid;
+
+// Must be rooted in a declaration reference.
+if (!BaseOffsetPair.first) {
+  Invalid = true;

ahmedbougacha wrote:

Heh yeah, we can probably add more in the future, but TBH this is obscure 
enough that we can do it if asked

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2030,8 +2030,25 @@ bool Sema::checkConstantPointerAuthKey(Expr *Arg, 
unsigned &Result) {
   return false;
 }
 
+static std::pair
+findConstantBaseAndOffset(Sema &S, Expr *E) {
+  // Must evaluate as a pointer.
+  Expr::EvalResult Result;
+  if (!E->EvaluateAsRValue(Result, S.Context) || !Result.Val.isLValue())
+return std::make_pair(nullptr, CharUnits());
+
+  // Base must be a declaration and can't be weakly imported.

ahmedbougacha wrote:

I removed the weakref base pointer check because that's currently supported in 
the qualifier (and I think this should have also checked for weakimport as well 
for the cases I care about), so the backend has to deal with ptrauth weak refs 
anyway.  There's a higher-level set of problems around how we deal with weak 
refs in general, but that's a separate topic.

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -938,6 +938,11 @@ class CodeGenModule : public CodeGenTypeCache {
   // Return the function body address of the given function.
   llvm::Constant *GetFunctionStart(const ValueDecl *Decl);
 
+  llvm::Constant *getConstantSignedPointer(llvm::Constant *Pointer,
+   unsigned Key,
+   llvm::Constant *StorageAddress,
+   llvm::Constant *ExtraDiscrim);

ahmedbougacha wrote:

Different people name these differently;  we can settle on OtherDiscriminator 
here yeah.  I think `extra`  as more of a common user-facing term for 
"discriminator", as in "extra data";  a lot of the PAC crowd coming from the 
security world thinks of it in those terms

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -1856,6 +1856,12 @@ class ConstantLValueEmitter : public 
ConstStmtVisitor

ahmedbougacha wrote:

The more interesting question is the usage of Constant;  I think we can safely 
assume the integer component is always going to be a ConstantInt (because it's 
going to have to fit in a ConstantInt-shaped hole in CPA anyway.)  That 
hopefully makes this obvious here, and I'll propagate that in the various users 
separately

https://github.com/llvm/llvm-project/pull/93904
___
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] Define ptrauth_sign_constant builtin. (PR #93904)

2024-06-18 Thread Ahmed Bougacha via llvm-branch-commits


@@ -2126,14 +2219,16 @@ static ExprResult PointerAuthSignGenericData(Sema &S, 
CallExpr *Call) {
 }
 
 static ExprResult PointerAuthSignOrAuth(Sema &S, CallExpr *Call,
-PointerAuthOpKind OpKind) {
+PointerAuthOpKind OpKind,
+bool RequireConstant) {
   if (S.checkArgCount(Call, 3))
 return ExprError();
   if (checkPointerAuthEnabled(S, Call))
 return ExprError();
-  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind) ||
+  if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||

ahmedbougacha wrote:

Let's do that in a separate PR and adopt it for the other builtins there

https://github.com/llvm/llvm-project/pull/93904
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits


@@ -420,6 +442,7 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   errs() << "BOLT-WARNING: profile ignored for function " << YamlBF.Name
  << '\n';
 
+

aaupov wrote:

nit: please drop 

https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits


@@ -0,0 +1,67 @@
+## Test YAMLProfileReader support for pass-through blocks in non-matching 
edges:
+## match the profile edge A -> C to the CFG with blocks A -> B -> C.
+
+# REQUIRES: system-linux
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
+# RUN: llvm-bolt %t.exe -o %t.out --data %t/yaml -v=1 \
+# RUN:   --print-cfg 2>&1 | FileCheck %s

aaupov wrote:

Please add verbosity=2 logging for hash-based matching and explicitly check 
that we matched `main` BF to `main2` profile.

https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits


@@ -383,6 +381,30 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   matchProfileToFunction(YamlBF, Function);
   }
 
+  // Uses the strict hash of profiled and binary functions to match functions

aaupov wrote:

Let's put this under `if (!opts::IgnoreHash)`

https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits


@@ -383,6 +381,30 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   matchProfileToFunction(YamlBF, Function);
   }
 
+  // Uses the strict hash of profiled and binary functions to match functions
+  // that are not matched by name or common name.
+  std::unordered_map StrictBinaryFunctionHashes;
+  StrictBinaryFunctionHashes.reserve(BC.getBinaryFunctions().size());
+
+  for (auto &[_, BF] : BC.getBinaryFunctions()) {
+if (ProfiledFunctions.count(&BF))
+  continue;
+BF.computeHash(YamlBP.Header.IsDFSOrder, YamlBP.Header.HashFunction);

aaupov wrote:

Looks like we'd need to compute hashes for all functions (unless IgnoreHash is 
used). Let's compute them in a single place, instead of two (here and line 377).

We'd also need a sense of the runtime overhead for that – can you please run 
BOLT on a large binary with `-time-rewrite` and include profile reader wall 
time before and after into the summary?

https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov commented:

Looks very good, but please address some minor issues.

https://github.com/llvm/llvm-project/pull/95821
___
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] [BOLT] Hash-based function matching (PR #95821)

2024-06-18 Thread Amir Ayupov via llvm-branch-commits


@@ -383,6 +381,30 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
   matchProfileToFunction(YamlBF, Function);
   }
 
+  // Uses the strict hash of profiled and binary functions to match functions
+  // that are not matched by name or common name.
+  std::unordered_map StrictBinaryFunctionHashes;

aaupov wrote:

```suggestion
  std::unordered_map StrictHashToBF;
```

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


[llvm-branch-commits] [SPARC][IAS] Rework ASI tag matching in prep for `ParseForAllFeatures` (PR #96020)

2024-06-18 Thread via llvm-branch-commits

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

This changes the ASI tag matching at `parseASITag` to use a similar
implementation to `parsePrefetchTag`. This introduces a slight regression
to error messages, but is needed so we can enable `ParseForAllFeatures`
in `MatchOperandParserImpl` in a future patch.



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


[llvm-branch-commits] [SPARC][IAS] Enable `ParseForAllFeatures` in `MatchOperandParserImpl` (PR #96021)

2024-06-18 Thread via llvm-branch-commits

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

This enables `ParseForAllFeatures` to report the correct error message
when trying to assemble instructions not available in V8 mode.



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


[llvm-branch-commits] [SPARC][IAS] Rework ASI tag matching in prep for `ParseForAllFeatures` (PR #96020)

2024-06-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-sparc

Author: Koakuma (koachan)


Changes

This changes the ASI tag matching at `parseASITag` to use a similar
implementation to `parsePrefetchTag`. This introduces a slight regression
to error messages, but is needed so we can enable `ParseForAllFeatures`
in `MatchOperandParserImpl` in a future patch.


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


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+23-13) 
- (modified) llvm/test/MC/Sparc/sparc-mem-asi-instructions.s (+2-2) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+2-2) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index f0a3a4e88b30c..3d8637bb8c359 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -1085,13 +1085,24 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
&Operands) {
   SMLoc E = Parser.getTok().getEndLoc();
   int64_t ASIVal = 0;
 
-  if (is64Bit() && (getLexer().getKind() == AsmToken::Hash)) {
+  switch (getLexer().getKind()) {
+  case AsmToken::LParen:
+  case AsmToken::Integer:
+  case AsmToken::Identifier:
+  case AsmToken::Plus:
+  case AsmToken::Minus:
+  case AsmToken::Tilde:
+if (getParser().parseAbsoluteExpression(ASIVal) || !isUInt<8>(ASIVal))
+  return Error(S, "invalid ASI number, must be between 0 and 255");
+break;
+  case AsmToken::Hash: {
 // For now we only support named tags for 64-bit/V9 systems.
 // TODO: add support for 32-bit/V8 systems.
 SMLoc TagStart = getLexer().peekTok(false).getLoc();
 Parser.Lex(); // Eat the '#'.
-auto ASIName = Parser.getTok().getString();
-auto ASITag = SparcASITag::lookupASITagByName(ASIName);
+const StringRef ASIName = Parser.getTok().getString();
+const SparcASITag::ASITag *ASITag =
+SparcASITag::lookupASITagByName(ASIName);
 if (!ASITag)
   ASITag = SparcASITag::lookupASITagByAltName(ASIName);
 Parser.Lex(); // Eat the identifier token.
@@ -1100,15 +,10 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector 
&Operands) {
   return Error(TagStart, "unknown ASI tag");
 
 ASIVal = ASITag->Encoding;
-  } else if (!getParser().parseAbsoluteExpression(ASIVal)) {
-if (!isUInt<8>(ASIVal))
-  return Error(S, "invalid ASI number, must be between 0 and 255");
-  } else {
-return Error(
-S, is64Bit()
-   ? "malformed ASI tag, must be %asi, a constant integer "
- "expression, or a named tag"
-   : "malformed ASI tag, must be a constant integer expression");
+break;
+  }
+  default:
+return ParseStatus::NoMatch;
   }
 
   Operands.push_back(SparcOperand::CreateASITag(ASIVal, S, E));
@@ -1230,8 +1236,12 @@ ParseStatus SparcAsmParser::parseOperand(OperandVector 
&Operands,
 // Parse an optional address-space identifier after the address.
 // This will be either an immediate constant expression, or, on 64-bit
 // processors, the %asi register.
-if (is64Bit() && getLexer().is(AsmToken::Percent)) {
+if (getLexer().is(AsmToken::Percent)) {
   SMLoc S = Parser.getTok().getLoc();
+  if (!is64Bit())
+return Error(
+S, "malformed ASI tag, must be a constant integer expression");
+
   Parser.Lex(); // Eat the %.
   const AsmToken Tok = Parser.getTok();
   if (Tok.is(AsmToken::Identifier) && Tok.getString() == "asi") {
diff --git a/llvm/test/MC/Sparc/sparc-mem-asi-instructions.s 
b/llvm/test/MC/Sparc/sparc-mem-asi-instructions.s
index 39abe7b99cb40..8b8503caf4ba0 100644
--- a/llvm/test/MC/Sparc/sparc-mem-asi-instructions.s
+++ b/llvm/test/MC/Sparc/sparc-mem-asi-instructions.s
@@ -1,9 +1,9 @@
 ! RUN: not llvm-mc %s -triple=sparc   -show-encoding 2>&1 | FileCheck %s 
--check-prefix=V8
 ! RUN: not llvm-mc %s -triple=sparcv9 -show-encoding 2>&1 | FileCheck %s 
--check-prefix=V9
 
-! V8: error: malformed ASI tag, must be a constant integer expression
+! V8: error: expected absolute expression
 ! V8-NEXT: lduba [%i0] asi, %o2
-! V9: error: malformed ASI tag, must be %asi, a constant integer expression, 
or a named tag
+! V9: error: unexpected token
 ! V9-NEXT: lduba [%i0] asi, %o2
 lduba [%i0] asi, %o2
 
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s 
b/llvm/test/MC/Sparc/sparcv9-instructions.s
index 1b11171b7074d..a7761c10c509b 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -657,12 +657,12 @@
 ! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
 prefetcha  [ %i1 + 0xf80 ] %asi, #one_read
 
-! V8:  error: malformed ASI tag, must be a constant integer 
expression
+! V8:  error: invalid operand for instruction
 ! V8-NEXT: prefetcha  [ %i1 + %i2 ] #ASI_SNF, 1
 ! V9: prefetcha [%i1+%i2]

[llvm-branch-commits] [SPARC][IAS] Enable `ParseForAllFeatures` in `MatchOperandParserImpl` (PR #96021)

2024-06-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Koakuma (koachan)


Changes

This enables `ParseForAllFeatures` to report the correct error message
when trying to assemble instructions not available in V8 mode.


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


3 Files Affected:

- (modified) llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (+2-1) 
- (modified) llvm/test/MC/Sparc/sparc-asm-errors.s (+1-1) 
- (modified) llvm/test/MC/Sparc/sparcv9-instructions.s (+26-26) 


``diff
diff --git a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp 
b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
index 3d8637bb8c359..34531fff31e8e 100644
--- a/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ b/llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -1189,7 +1189,8 @@ ParseStatus SparcAsmParser::parseCallTarget(OperandVector 
&Operands) {
 ParseStatus SparcAsmParser::parseOperand(OperandVector &Operands,
  StringRef Mnemonic) {
 
-  ParseStatus Res = MatchOperandParserImpl(Operands, Mnemonic);
+  ParseStatus Res =
+  MatchOperandParserImpl(Operands, Mnemonic, /*ParseForAllFeatures=*/true);
 
   // If there wasn't a custom match, try the generic matcher below. Otherwise,
   // there was a match, but an error occurred, in which case, just return that
diff --git a/llvm/test/MC/Sparc/sparc-asm-errors.s 
b/llvm/test/MC/Sparc/sparc-asm-errors.s
index 780f4e7fad787..2b3a2eb2bfae6 100644
--- a/llvm/test/MC/Sparc/sparc-asm-errors.s
+++ b/llvm/test/MC/Sparc/sparc-asm-errors.s
@@ -11,7 +11,7 @@
 ! V9: unknown membar tag
 membar #BadTag
 
-! V8: instruction requires a CPU feature not currently enabled
+! V8: unexpected token
 ! V9: invalid membar mask number
 membar -127
 
diff --git a/llvm/test/MC/Sparc/sparcv9-instructions.s 
b/llvm/test/MC/Sparc/sparcv9-instructions.s
index a7761c10c509b..68ae2ac5c98a4 100644
--- a/llvm/test/MC/Sparc/sparcv9-instructions.s
+++ b/llvm/test/MC/Sparc/sparcv9-instructions.s
@@ -537,112 +537,112 @@
 ! V9: stxa %g0, [%g2+%i5] #ASI_SNF   ! encoding: [0xc0,0xf0,0x90,0x7d]
 stxa %g0, [%g2 + %i5] #ASI_SNF
 
-! V8:  error: invalid operand for instruction
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], 1
 ! V9: prefetch  [%i1+3968], #one_read  ! encoding: 
[0xc3,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], 1
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_reads
 ! V9: prefetch  [%i1+3968], #n_reads  ! encoding: [0xc1,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #n_reads
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_read
 ! V9: prefetch  [%i1+3968], #one_read  ! encoding: 
[0xc3,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #one_read
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_writes
 ! V9: prefetch  [%i1+3968], #n_writes  ! encoding: 
[0xc5,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #n_writes
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_write
 ! V9: prefetch  [%i1+3968], #one_write  ! encoding: 
[0xc7,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #one_write
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #page
 ! V9: prefetch  [%i1+3968], #page  ! encoding: [0xc9,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #page
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #unified
 ! V9: prefetch  [%i1+3968], #unified  ! encoding: [0xe3,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #unified
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #n_reads_strong
 ! V9: prefetch  [%i1+3968], #n_reads_strong  ! encoding: 
[0xe9,0x6e,0x6f,0x80]
 prefetch  [ %i1 + 0xf80 ], #n_reads_strong
 
-! V8:  error: unexpected token
+! V8:  error: instruction requires a CPU feature not currently 
enabled
 ! V8-NEXT: prefetch  [ %i1 + 0xf80 ], #one_read_strong
 ! V9: prefetch  [%i1+3968], #one_read_strong  ! encoding: 

[llvm-branch-commits] [SPARC][IAS] Enable `ParseForAllFeatures` in `MatchOperandParserImpl` (PR #96021)

2024-06-18 Thread via llvm-branch-commits


@@ -11,7 +11,7 @@
 ! V9: unknown membar tag
 membar #BadTag
 
-! V8: instruction requires a CPU feature not currently enabled
+! V8: unexpected token
 ! V9: invalid membar mask number
 membar -127

koachan wrote:

The membar error messages seems to regress, seems like it prioritizes the parse 
error over the fact that membar is not available on V8? Am I missing something 
in the patch?

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


[llvm-branch-commits] [SPARC][IAS] Enable `ParseForAllFeatures` in `MatchOperandParserImpl` (PR #96021)

2024-06-18 Thread via llvm-branch-commits


@@ -657,22 +657,22 @@
 ! V9: prefetcha [%i1+3968] %asi, #one_read! encoding: 
[0xc3,0xee,0x6f,0x80]
 prefetcha  [ %i1 + 0xf80 ] %asi, #one_read

koachan wrote:

This is also suffering from the same issue as the membars, IAS doesn't seem to 
notice that prefetcha isn't available in V8 mode too...

https://github.com/llvm/llvm-project/pull/96021
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -351,6 +351,9 @@ def err_drv_omp_host_ir_file_not_found : Error<
   "target regions but cannot be found">;
 def err_drv_omp_host_target_not_supported : Error<
   "target '%0' is not a supported OpenMP host target">;
+def err_drv_ptrauth_not_supported : Error<
+  "target '%0' does not support native pointer authentication">;

ahatanak wrote:

I removed the diagnostic. This was needed before `TargetSpecific` was added to 
the driver options. 

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -104,10 +109,13 @@ class CGCallee {
 
   /// Construct a callee.  Call this constructor directly when this
   /// isn't a direct call.
-  CGCallee(const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr)
+  CGCallee(
+  const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr,
+  const CGPointerAuthInfo &pointerAuthInfo = /*FIXME*/ CGPointerAuthInfo())

ahatanak wrote:

Yes, that's correct.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -128,12 +136,12 @@ class CGCallee {
 
   static CGCallee forDirect(llvm::Constant *functionPtr,
 const CGCalleeInfo &abstractInfo = CGCalleeInfo()) 
{
-return CGCallee(abstractInfo, functionPtr);
+return CGCallee(abstractInfo, functionPtr, CGPointerAuthInfo());

ahatanak wrote:

Yes. I've fixed that.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -61,3 +79,28 @@ CodeGen::getConstantSignedPointer(CodeGenModule &CGM, 
llvm::Constant *Pointer,
   return CGM.getConstantSignedPointer(Pointer, Key, StorageAddress,
   OtherDiscriminator);
 }
+
+/// If applicable, sign a given constant function pointer with the ABI rules 
for
+/// functionType.
+llvm::Constant *CodeGenModule::getFunctionPointer(llvm::Constant *Pointer,
+  QualType FunctionType,
+  GlobalDecl GD) {

ahatanak wrote:

No, it isn't. I've removed it. It will be needed when we add support for 
function-type based signing later.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -61,3 +79,28 @@ CodeGen::getConstantSignedPointer(CodeGenModule &CGM, 
llvm::Constant *Pointer,
   return CGM.getConstantSignedPointer(Pointer, Key, StorageAddress,
   OtherDiscriminator);
 }
+
+/// If applicable, sign a given constant function pointer with the ABI rules 
for

ahatanak wrote:

I removed the comment.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -0,0 +1,9 @@
+// RUN: %clang -target arm64-apple-macosx -fptrauth-calls -c %s -### 2>&1 | 
FileCheck %s --check-prefix PTRAUTH_CALLS

ahatanak wrote:

I removed the file.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios-emit-llvm %s  
-o - | FileCheck %s --check-prefixes=ALL,OFF

ahatanak wrote:

I've added RUN lines for `aarch64-linux-gnu`.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-calls %s -verify 
-emit-llvm -o -
+
+void f(void);
+
+int *pf = (int *)&f + 1; // expected-error{{cannot compile this static 
initializer yet}}

ahatanak wrote:

As commented in the test case, adding a non-zero constant to a signed pointer 
is unrepresentable in relocations. I agree that the diagnostic should provide 
more information and should inform the users that the initialization failed 
because of this specific limitation.

I'll see if I can improve the error message later.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s   -triple arm64e-apple-ios13 -fptrauth-calls 
-fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -xc++ %s -triple arm64e-apple-ios13 -fptrauth-calls 
-fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s 
--check-prefixes=CHECK,CXX
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void f(void);
+
+#ifdef __cplusplus
+
+// CXX-LABEL: define internal void @__cxx_global_var_init()
+// CXX: store ptr getelementptr inbounds (i32, ptr ptrauth (ptr @f, i32 0), 
i64 2), ptr @_ZL2fp, align 8
+
+__attribute__((used))
+void (*const fp)(void) = (void (*)(void))((int *)&f + 2); // Error in C mode.

ahatanak wrote:

In C++, the global constructor can initialize the variable.

https://github.com/llvm/llvm-project/pull/93906
___
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] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Akira Hatanaka via llvm-branch-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls 
-fptrauth-intrinsics -emit-llvm %s  -o - | FileCheck %s

ahatanak wrote:

We can probably consolidate some of the tests. I'll look into it later.

https://github.com/llvm/llvm-project/pull/93906
___
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] Finish implementation of P0522 (PR #96023)

2024-06-18 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/96023

This finishes the clang implementation of P0522, getting rid of the fallback to 
the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters, we would 
perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't generate 
diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't generate any 
diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order to accept the 
historial rule for TTP matching pack parameter to non-pack arguments.
This change also makes us accept some combinations of historical and P0522 
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite, which I 
am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed, with 
related test suite churn.

The problem here is that the old rules were very simple and non-recursive, 
making it easy to provide customized diagnostics, and to keep them consistent 
with each other.

The new rules are a lot more complex and rely on template argument deduction, 
substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics, and create a 
new instantiation context that keeps track of things.

So for example when a substitution failure occurs, we use the error produced 
there unmodified, and just attach notes to it explaining that it occurred in 
the context of partial ordering this template argument against that template 
parameter.

This diverges from the old diagnostics, which would lead with an error pointing 
to the template argument, explain the problem in subsequent notes, and produce 
a final note pointing to the parameter.

>From 453df309b880468ded94fc8f2d670908e7bcb5c7 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 17 Jun 2024 21:39:08 -0300
Subject: [PATCH] [clang] Finish implementation of P0522

This finishes the clang implementation of P0522, getting rid
of the fallback to the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters,
we would perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't
  generate diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't
  generate any diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order
to accept the historial rule for TTP matching pack parameter to non-pack
arguments.
This change also makes us accept some combinations of historical and P0522
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite,
which I am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed,
with related test suite churn.

The problem here is that the old rules were very simple and
non-recursive, making it easy to provide customized diagnostics,
and to keep them consistent with each other.

The new rules are a lot more complex and rely on template argument
deduction, substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics,
and create a new instantiation context that keeps track of this context.

So for example when a substitution failure occurs, we use the error
produced there unmodified, and just attach notes to it explaining
that it occurred in the context of partial ordering this template
argument against that template parameter.

This diverges from the old diagnostics, which would lead with an
error pointing to the template argument, explain the problem
in subsequent notes, and produce a final note pointing to the parameter.
---
 clang/docs/ReleaseNotes.rst   |   9 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Sema/Sema.h   |  14 +-
 clang/lib/Frontend/FrontendActions.cpp|   2 +
 clang/lib/Sema/SemaTemplate.cpp   |  95 ++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 341 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  15 +
 .../temp/temp.arg/temp.arg.template/p3-0x.cpp |  31 +-
 clang/test/CXX/temp/temp.param/p12.cpp|  21 +-
 clang/test/Modules/cxx-templates.cpp  |  15 +-
 clang/test/Sema

[llvm-branch-commits] [clang] [clang] Finish implementation of P0522 (PR #96023)

2024-06-18 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This finishes the clang implementation of P0522, getting rid of the fallback to 
the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters, we would 
perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't generate 
diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't generate any 
diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order to accept the 
historial rule for TTP matching pack parameter to non-pack arguments.
This change also makes us accept some combinations of historical and P0522 
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite, which I 
am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed, with 
related test suite churn.

The problem here is that the old rules were very simple and non-recursive, 
making it easy to provide customized diagnostics, and to keep them consistent 
with each other.

The new rules are a lot more complex and rely on template argument deduction, 
substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics, and create a 
new instantiation context that keeps track of things.

So for example when a substitution failure occurs, we use the error produced 
there unmodified, and just attach notes to it explaining that it occurred in 
the context of partial ordering this template argument against that template 
parameter.

This diverges from the old diagnostics, which would lead with an error pointing 
to the template argument, explain the problem in subsequent notes, and produce 
a final note pointing to the parameter.

---

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


17 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+8-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7) 
- (modified) clang/include/clang/Sema/Sema.h (+12-2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+40-55) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+242-99) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+15) 
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp (+18-13) 
- (modified) clang/test/CXX/temp/temp.param/p12.cpp (+11-10) 
- (modified) clang/test/Modules/cxx-templates.cpp (+3-12) 
- (modified) clang/test/SemaCXX/make_integer_seq.cpp (+2-3) 
- (modified) clang/test/SemaTemplate/cwg2398.cpp (+23-7) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype.cpp (+20-25) 
- (modified) clang/test/SemaTemplate/temp_arg_template.cpp (+23-15) 
- (modified) clang/test/SemaTemplate/temp_arg_template_p0522.cpp (+44-26) 
- (modified) clang/test/Templight/templight-empty-entries-fix.cpp (+12) 
- (modified) clang/test/Templight/templight-prior-template-arg.cpp (+23-10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7112d1f889fef..abe535f55fb2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -176,6 +176,8 @@ C++17 Feature Support
   the values produced by GCC, so these macros should not be used from header
   files because they may not be stable across multiple TUs (the values may vary
   based on compiler version as well as CPU tuning). #GH60174
+- The implementation of the relaxed template template argument matching rules 
is
+  more complete and reliable, and should provide more accurate diagnostics.
 
 C++14 Feature Support
 ^
@@ -589,6 +591,10 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- Clang now properly explains the reason a template template argument failed to
+  match a template template parameter, in terms of the C++17 relaxed matching 
rules
+  instead of the old ones.
+
 Improvements to Clang's time-trace
 --
 
@@ -887,7 +893,8 @@ Bug Fixes to C++ Support
   between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (#GH95366).
 - Fix immediate escalation bugs in the presence of dependent call arguments. 
(#GH94935)
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
-
+- Fixes to several issues in partial ordering of template template parameters, 
which
+  wer

[llvm-branch-commits] [clang] [clang] Finish implementation of P0522 (PR #96023)

2024-06-18 Thread Matheus Izvekov via llvm-branch-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/96023

>From 03d5720d113ff3ce03694b27d376230d06d7693e Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 17 Jun 2024 21:39:08 -0300
Subject: [PATCH] [clang] Finish implementation of P0522

This finishes the clang implementation of P0522, getting rid
of the fallback to the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters,
we would perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't
  generate diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't
  generate any diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order
to accept the historial rule for TTP matching pack parameter to non-pack
arguments.
This change also makes us accept some combinations of historical and P0522
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite,
which I am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed,
with related test suite churn.

The problem here is that the old rules were very simple and
non-recursive, making it easy to provide customized diagnostics,
and to keep them consistent with each other.

The new rules are a lot more complex and rely on template argument
deduction, substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics,
and create a new instantiation context that keeps track of this context.

So for example when a substitution failure occurs, we use the error
produced there unmodified, and just attach notes to it explaining
that it occurred in the context of partial ordering this template
argument against that template parameter.

This diverges from the old diagnostics, which would lead with an
error pointing to the template argument, explain the problem
in subsequent notes, and produce a final note pointing to the parameter.
---
 clang/docs/ReleaseNotes.rst   |   9 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Sema/Sema.h   |  14 +-
 clang/lib/Frontend/FrontendActions.cpp|   2 +
 clang/lib/Sema/SemaTemplate.cpp   |  94 ++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 341 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  15 +
 .../temp/temp.arg/temp.arg.template/p3-0x.cpp |  31 +-
 clang/test/CXX/temp/temp.param/p12.cpp|  21 +-
 clang/test/Modules/cxx-templates.cpp  |  15 +-
 clang/test/SemaCXX/make_integer_seq.cpp   |   5 +-
 clang/test/SemaTemplate/cwg2398.cpp   |  30 +-
 clang/test/SemaTemplate/temp_arg_nontype.cpp  |  45 +--
 clang/test/SemaTemplate/temp_arg_template.cpp |  38 +-
 .../SemaTemplate/temp_arg_template_p0522.cpp  |  70 ++--
 .../Templight/templight-empty-entries-fix.cpp |  12 +
 .../templight-prior-template-arg.cpp  |  33 +-
 17 files changed, 503 insertions(+), 279 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7112d1f889fef..abe535f55fb2a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -176,6 +176,8 @@ C++17 Feature Support
   the values produced by GCC, so these macros should not be used from header
   files because they may not be stable across multiple TUs (the values may vary
   based on compiler version as well as CPU tuning). #GH60174
+- The implementation of the relaxed template template argument matching rules 
is
+  more complete and reliable, and should provide more accurate diagnostics.
 
 C++14 Feature Support
 ^
@@ -589,6 +591,10 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- Clang now properly explains the reason a template template argument failed to
+  match a template template parameter, in terms of the C++17 relaxed matching 
rules
+  instead of the old ones.
+
 Improvements to Clang's time-trace
 --
 
@@ -887,7 +893,8 @@ Bug Fixes to C++ Support
   between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (#GH95366).
 - Fix immediate escalation bugs in the presence of dependent call arguments. 
(#GH94935)
 - Clang now diagnoses explicit specializations with storage class specifiers 
in all contexts.
-
+- Fixes to several issues in partial ordering of template template parameters, 
which
+  were documented in the test suite.
 
 Bug Fixes to AST Handling
 

[llvm-branch-commits] [clang] [llvm] [clang] Implement function pointer signing and authenticated function calls (PR #93906)

2024-06-18 Thread Daniil Kovalev via llvm-branch-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-calls %s -verify 
-emit-llvm -o -
+
+void f(void);
+
+int *pf = (int *)&f + 1; // expected-error{{cannot compile this static 
initializer yet}}

kovdan01 wrote:

> I'll see if I can improve the error message later.

Thanks. I'm OK with having the diagnostic "as is" for this PR and submitting a 
patch with message improvement as another PR later.

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