[llvm-branch-commits] [llvm] 0d0bb63 - Revert "[AMDGPU][CodeGenPrepare] Narrow 64 bit math to 32 bit if profitable (…"
Author: Shoreshen Date: 2025-04-01T16:24:54+08:00 New Revision: 0d0bb63b43da23bc625139c096bc2ebe8be28fbf URL: https://github.com/llvm/llvm-project/commit/0d0bb63b43da23bc625139c096bc2ebe8be28fbf DIFF: https://github.com/llvm/llvm-project/commit/0d0bb63b43da23bc625139c096bc2ebe8be28fbf.diff LOG: Revert "[AMDGPU][CodeGenPrepare] Narrow 64 bit math to 32 bit if profitable (…" This reverts commit 145b4a39504b88a695f1f85f4d9da991bb9a2656. Added: Modified: llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll llvm/test/CodeGen/AMDGPU/atomic_optimizations_global_pointer.ll llvm/test/CodeGen/AMDGPU/widen-smrd-loads.ll Removed: llvm/test/CodeGen/AMDGPU/narrow_math_for_and.ll diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp index eb5c160670992..9c482aeb3ea5c 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp @@ -1561,87 +1561,6 @@ void AMDGPUCodeGenPrepareImpl::expandDivRem64(BinaryOperator &I) const { llvm_unreachable("not a division"); } -Type *findSmallestLegalBits(Instruction *I, int OrigBit, int MaxBitsNeeded, -const TargetLowering *TLI, const DataLayout &DL) { - if (MaxBitsNeeded >= OrigBit) -return nullptr; - - Type *NewType = I->getType()->getWithNewBitWidth(MaxBitsNeeded); - while (OrigBit > MaxBitsNeeded) { -if (TLI->isOperationLegalOrCustom( -TLI->InstructionOpcodeToISD(I->getOpcode()), -TLI->getValueType(DL, NewType, true))) - return NewType; - -MaxBitsNeeded *= 2; -NewType = I->getType()->getWithNewBitWidth(MaxBitsNeeded); - } - return nullptr; -} - -static bool tryNarrowMathIfNoOverflow(Instruction *I, const TargetLowering *TLI, - const TargetTransformInfo &TTI, - const DataLayout &DL) { - unsigned Opc = I->getOpcode(); - Type *OldType = I->getType(); - - if (Opc != Instruction::Add && Opc != Instruction::Mul) -return false; - - unsigned OrigBit = OldType->getScalarSizeInBits(); - unsigned MaxBitsNeeded = OrigBit; - - switch (Opc) { - case Instruction::Add: -MaxBitsNeeded = KnownBits::add(computeKnownBits(I->getOperand(0), DL), - computeKnownBits(I->getOperand(1), DL)) -.countMaxActiveBits(); -break; - case Instruction::Mul: -MaxBitsNeeded = KnownBits::mul(computeKnownBits(I->getOperand(0), DL), - computeKnownBits(I->getOperand(1), DL)) -.countMaxActiveBits(); -break; - default: -llvm_unreachable("Unexpected opcode, only valid for Instruction::Add and " - "Instruction::Mul."); - } - - MaxBitsNeeded = std::max(bit_ceil(MaxBitsNeeded), 8); - Type *NewType = findSmallestLegalBits(I, OrigBit, MaxBitsNeeded, TLI, DL); - - if (!NewType) -return false; - - // Old cost - InstructionCost OldCost = - TTI.getArithmeticInstrCost(Opc, OldType, TTI::TCK_RecipThroughput); - // New cost of new op - InstructionCost NewCost = - TTI.getArithmeticInstrCost(Opc, NewType, TTI::TCK_RecipThroughput); - // New cost of narrowing 2 operands (use trunc) - NewCost += 2 * TTI.getCastInstrCost(Instruction::Trunc, NewType, OldType, - TTI.getCastContextHint(I), - TTI::TCK_RecipThroughput); - // New cost of zext narrowed result to original type - NewCost += - TTI.getCastInstrCost(Instruction::ZExt, OldType, NewType, - TTI.getCastContextHint(I), TTI::TCK_RecipThroughput); - if (NewCost >= OldCost) -return false; - - IRBuilder<> Builder(I); - Value *Trunc0 = Builder.CreateTrunc(I->getOperand(0), NewType); - Value *Trunc1 = Builder.CreateTrunc(I->getOperand(1), NewType); - Value *Arith = - Builder.CreateBinOp((Instruction::BinaryOps)Opc, Trunc0, Trunc1); - - Value *Zext = Builder.CreateZExt(Arith, OldType); - I->replaceAllUsesWith(Zext); - I->eraseFromParent(); - return true; -} - bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) { if (foldBinOpIntoSelect(I)) return true; @@ -1726,9 +1645,6 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) { } } - Changed = tryNarrowMathIfNoOverflow(&I, ST.getTargetLowering(), - TM.getTargetTransformInfo(F), DL); - return Changed; } diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll index d7c35a8b007c6..296b817bc8f75 100644 --- a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll +++ b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll @@ -414,10 +41
[llvm-branch-commits] [llvm] 10bb8da - Revert "Revert "[AMDGPU][CodeGenPrepare] Narrow 64 bit math to 32 bit if prof…"
Author: Shoreshen Date: 2025-04-01T17:52:44+08:00 New Revision: 10bb8da1eed6060b37f61b6598ea59c9f1baec21 URL: https://github.com/llvm/llvm-project/commit/10bb8da1eed6060b37f61b6598ea59c9f1baec21 DIFF: https://github.com/llvm/llvm-project/commit/10bb8da1eed6060b37f61b6598ea59c9f1baec21.diff LOG: Revert "Revert "[AMDGPU][CodeGenPrepare] Narrow 64 bit math to 32 bit if prof…" This reverts commit 7f14b2a9eb4792155ed31da7bc16cc58cbb1b0fc. Added: llvm/test/CodeGen/AMDGPU/narrow_math_for_and.ll Modified: llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll llvm/test/CodeGen/AMDGPU/atomic_optimizations_global_pointer.ll llvm/test/CodeGen/AMDGPU/widen-smrd-loads.ll Removed: diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp index 9c482aeb3ea5c..eb5c160670992 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp @@ -1561,6 +1561,87 @@ void AMDGPUCodeGenPrepareImpl::expandDivRem64(BinaryOperator &I) const { llvm_unreachable("not a division"); } +Type *findSmallestLegalBits(Instruction *I, int OrigBit, int MaxBitsNeeded, +const TargetLowering *TLI, const DataLayout &DL) { + if (MaxBitsNeeded >= OrigBit) +return nullptr; + + Type *NewType = I->getType()->getWithNewBitWidth(MaxBitsNeeded); + while (OrigBit > MaxBitsNeeded) { +if (TLI->isOperationLegalOrCustom( +TLI->InstructionOpcodeToISD(I->getOpcode()), +TLI->getValueType(DL, NewType, true))) + return NewType; + +MaxBitsNeeded *= 2; +NewType = I->getType()->getWithNewBitWidth(MaxBitsNeeded); + } + return nullptr; +} + +static bool tryNarrowMathIfNoOverflow(Instruction *I, const TargetLowering *TLI, + const TargetTransformInfo &TTI, + const DataLayout &DL) { + unsigned Opc = I->getOpcode(); + Type *OldType = I->getType(); + + if (Opc != Instruction::Add && Opc != Instruction::Mul) +return false; + + unsigned OrigBit = OldType->getScalarSizeInBits(); + unsigned MaxBitsNeeded = OrigBit; + + switch (Opc) { + case Instruction::Add: +MaxBitsNeeded = KnownBits::add(computeKnownBits(I->getOperand(0), DL), + computeKnownBits(I->getOperand(1), DL)) +.countMaxActiveBits(); +break; + case Instruction::Mul: +MaxBitsNeeded = KnownBits::mul(computeKnownBits(I->getOperand(0), DL), + computeKnownBits(I->getOperand(1), DL)) +.countMaxActiveBits(); +break; + default: +llvm_unreachable("Unexpected opcode, only valid for Instruction::Add and " + "Instruction::Mul."); + } + + MaxBitsNeeded = std::max(bit_ceil(MaxBitsNeeded), 8); + Type *NewType = findSmallestLegalBits(I, OrigBit, MaxBitsNeeded, TLI, DL); + + if (!NewType) +return false; + + // Old cost + InstructionCost OldCost = + TTI.getArithmeticInstrCost(Opc, OldType, TTI::TCK_RecipThroughput); + // New cost of new op + InstructionCost NewCost = + TTI.getArithmeticInstrCost(Opc, NewType, TTI::TCK_RecipThroughput); + // New cost of narrowing 2 operands (use trunc) + NewCost += 2 * TTI.getCastInstrCost(Instruction::Trunc, NewType, OldType, + TTI.getCastContextHint(I), + TTI::TCK_RecipThroughput); + // New cost of zext narrowed result to original type + NewCost += + TTI.getCastInstrCost(Instruction::ZExt, OldType, NewType, + TTI.getCastContextHint(I), TTI::TCK_RecipThroughput); + if (NewCost >= OldCost) +return false; + + IRBuilder<> Builder(I); + Value *Trunc0 = Builder.CreateTrunc(I->getOperand(0), NewType); + Value *Trunc1 = Builder.CreateTrunc(I->getOperand(1), NewType); + Value *Arith = + Builder.CreateBinOp((Instruction::BinaryOps)Opc, Trunc0, Trunc1); + + Value *Zext = Builder.CreateZExt(Arith, OldType); + I->replaceAllUsesWith(Zext); + I->eraseFromParent(); + return true; +} + bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) { if (foldBinOpIntoSelect(I)) return true; @@ -1645,6 +1726,9 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) { } } + Changed = tryNarrowMathIfNoOverflow(&I, ST.getTargetLowering(), + TM.getTargetTransformInfo(F), DL); + return Changed; } diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll index 296b817bc8f75..d7c35a8b007c6 100644 --- a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll +++ b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-mul24.ll @@ -414,7 +414
[llvm-branch-commits] [llvm] 337bad3 - [EarlyIfConverter] Fix reg killed twice after early-if-predicator and ifcvt (#133554)
Author: Afanasyev Ivan Date: 2025-04-01T12:06:30+02:00 New Revision: 337bad3921356fba89409e03793f7d2df846c0e9 URL: https://github.com/llvm/llvm-project/commit/337bad3921356fba89409e03793f7d2df846c0e9 DIFF: https://github.com/llvm/llvm-project/commit/337bad3921356fba89409e03793f7d2df846c0e9.diff LOG: [EarlyIfConverter] Fix reg killed twice after early-if-predicator and ifcvt (#133554) Bug relates to `early-if-predicator` and `early-ifcvt` passes. If virtual register has "killed" flag in both basic blocks to be merged into head, both instructions in head basic block will have "killed" flag for this register. It makes MIR incorrect. Example: ``` bb.0: ; if ... %0:intregs = COPY $r0 J2_jumpf %2, %bb.2, implicit-def dead $pc J2_jump %bb.1, implicit-def dead $pc bb.1: ; if.then ... S4_storeiri_io killed %0, 0, 1 J2_jump %bb.3, implicit-def dead $pc bb.2: ; if.else ... S4_storeiri_io killed %0, 0, 1 J2_jump %bb.3, implicit-def dead $pc ``` After early-if-predicator will become: ``` bb.0: %0:intregs = COPY $r0 S4_storeirif_io %1, killed %0, 0, 1 S4_storeirit_io %1, killed %0, 0, 1 ``` Having `killed` flag set twice in bb.0 for `%0` is an incorrect MIR. Added: llvm/test/CodeGen/AArch64/early-ifcvt-on-double-killed-reg.mir llvm/test/CodeGen/Hexagon/early-if-predicator-reg-killed-everywhere.mir Modified: llvm/lib/CodeGen/EarlyIfConversion.cpp Removed: diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp index 24c6dafc60459..da0987c3b50bb 100644 --- a/llvm/lib/CodeGen/EarlyIfConversion.cpp +++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp @@ -17,6 +17,7 @@ #include "llvm/CodeGen/EarlyIfConversion.h" #include "llvm/ADT/BitVector.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SparseSet.h" @@ -31,6 +32,7 @@ #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/MachineTraceMetrics.h" +#include "llvm/CodeGen/Register.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" @@ -163,6 +165,11 @@ class SSAIfConv { /// Insert selects and rewrite PHI operands to use them. void rewritePHIOperands(); + /// If virtual register has "killed" flag in TBB and FBB basic blocks, remove + /// the flag in TBB instruction. + void clearRepeatedKillFlagsFromTBB(MachineBasicBlock *TBB, + MachineBasicBlock *FBB); + public: /// init - Initialize per-function data structures. void init(MachineFunction &MF) { @@ -675,6 +682,31 @@ void SSAIfConv::rewritePHIOperands() { } } +void SSAIfConv::clearRepeatedKillFlagsFromTBB(MachineBasicBlock *TBB, + MachineBasicBlock *FBB) { + assert(TBB != FBB); + + // Collect virtual registers killed in FBB. + SmallDenseSet FBBKilledRegs; + for (MachineInstr &MI : FBB->instrs()) { +for (MachineOperand &MO : MI.operands()) { + if (MO.isReg() && MO.isKill() && MO.getReg().isVirtual()) +FBBKilledRegs.insert(MO.getReg()); +} + } + + if (FBBKilledRegs.empty()) +return; + + // Find the same killed registers in TBB and clear kill flags for them. + for (MachineInstr &MI : TBB->instrs()) { +for (MachineOperand &MO : MI.operands()) { + if (MO.isReg() && MO.isKill() && FBBKilledRegs.contains(MO.getReg())) +MO.setIsKill(false); +} + } +} + /// convertIf - Execute the if conversion after canConvertIf has determined the /// feasibility. /// @@ -690,6 +722,13 @@ void SSAIfConv::convertIf(SmallVectorImpl &RemoveBlocks, else ++NumDiamondsConv; + // If both blocks are going to be merged into Head, remove "killed" flag in + // TBB for registers, which are killed in TBB and FBB. Otherwise, register + // will be killed twice in Head after splice. Register killed twice is an + // incorrect MIR. + if (TBB != Tail && FBB != Tail) +clearRepeatedKillFlagsFromTBB(TBB, FBB); + // Move all instructions into Head, except for the terminators. if (TBB != Tail) { if (Predicate) diff --git a/llvm/test/CodeGen/AArch64/early-ifcvt-on-double-killed-reg.mir b/llvm/test/CodeGen/AArch64/early-ifcvt-on-double-killed-reg.mir new file mode 100644 index 0..27222e46b9c10 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/early-ifcvt-on-double-killed-reg.mir @@ -0,0 +1,54 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple=aarch64-- -run-pass=early-ifcvt -stress-early-ifcvt %s -o - -verify-machineinstrs | FileCheck %s + +# Test that "killed" flag on the same virtual register in merged blocks is +# removed for the first spliced block and is saved for the se
[llvm-branch-commits] [llvm] [LoopInterchange] Fix the vectorizable check for a loop (PR #133667)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms Author: Ryotaro Kasuga (kasuga-fj) Changes In the profitability check for vectorization, the dependency matrix was not handled correctly. This can result to make a wrong decision: It may say "this loop can be vectorized" when in fact it cannot. The root cause of this is that the check process early returns when it finds '=' or 'I' in the dependency matrix. To make sure that we can actually vectorize the loop, we need to check all the rows of the matrix. This patch fixes the process of checking whether we can vectorize the loop or not. Now it won't make a wrong decision for a loop that cannot be vectorized. Related: #131130 --- Full diff: https://github.com/llvm/llvm-project/pull/133667.diff 2 Files Affected: - (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+24-17) - (modified) llvm/test/Transforms/LoopInterchange/profitability-vectorization-heuristic.ll (+3-6) ``diff diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index e777f950a7c5a..b6b0b7d7a947a 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1197,25 +1197,32 @@ LoopInterchangeProfitability::isProfitablePerInstrOrderCost() { return std::nullopt; } +/// Return true if we can vectorize the loop specified by \p LoopId. +static bool canVectorize(const CharMatrix &DepMatrix, unsigned LoopId) { + for (unsigned I = 0; I != DepMatrix.size(); I++) { +char Dir = DepMatrix[I][LoopId]; +if (Dir != 'I' && Dir != '=') + return false; + } + return true; +} + std::optional LoopInterchangeProfitability::isProfitableForVectorization( unsigned InnerLoopId, unsigned OuterLoopId, CharMatrix &DepMatrix) { - for (auto &Row : DepMatrix) { -// If the inner loop is loop independent or doesn't carry any dependency -// it is not profitable to move this to outer position, since we are -// likely able to do inner loop vectorization already. -if (Row[InnerLoopId] == 'I' || Row[InnerLoopId] == '=') - return std::optional(false); - -// If the outer loop is not loop independent it is not profitable to move -// this to inner position, since doing so would not enable inner loop -// parallelism. -if (Row[OuterLoopId] != 'I' && Row[OuterLoopId] != '=') - return std::optional(false); - } - // If inner loop has dependence and outer loop is loop independent then it - // is/ profitable to interchange to enable inner loop parallelism. - // If there are no dependences, interchanging will not improve anything. - return std::optional(!DepMatrix.empty()); + // If the outer loop is not loop independent it is not profitable to move + // this to inner position, since doing so would not enable inner loop + // parallelism. + if (!canVectorize(DepMatrix, OuterLoopId)) +return false; + + // If inner loop has dependence and outer loop is loop independent then it is + // profitable to interchange to enable inner loop parallelism. + if (!canVectorize(DepMatrix, InnerLoopId)) +return true; + + // TODO: Estimate the cost of vectorized loop body when both the outer and the + // inner loop can be vectorized. + return std::nullopt; } bool LoopInterchangeProfitability::isProfitable( diff --git a/llvm/test/Transforms/LoopInterchange/profitability-vectorization-heuristic.ll b/llvm/test/Transforms/LoopInterchange/profitability-vectorization-heuristic.ll index 606117e70db86..b82dd5141a6b2 100644 --- a/llvm/test/Transforms/LoopInterchange/profitability-vectorization-heuristic.ll +++ b/llvm/test/Transforms/LoopInterchange/profitability-vectorization-heuristic.ll @@ -15,16 +15,13 @@ ; } ; } ; -; FIXME: These loops are not exchanged at this time due to the problem of -; profitablity heuristic for vectorization. -; CHECK: --- !Missed +; CHECK: --- !Passed ; CHECK-NEXT: Pass:loop-interchange -; CHECK-NEXT: Name:InterchangeNotProfitable +; CHECK-NEXT: Name:Interchanged ; CHECK-NEXT: Function:interchange_necesasry_for_vectorization ; CHECK-NEXT: Args: -; CHECK-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization. -; CHECK-NEXT: ... +; CHECK-NEXT: - String: Loop interchanged with enclosing loop. define void @interchange_necesasry_for_vectorization() { entry: br label %for.i.header `` https://github.com/llvm/llvm-project/pull/133667 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133836)
llvmbot wrote: @SixWeining @tangaac What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/133836 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Reduce global variable code model (PR #133865)
arsenm wrote: Also discovered https://github.com/llvm/llvm-project/issues/133864 adding this https://github.com/llvm/llvm-project/pull/133865 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Fix overly conservative operands-to-args user restriction (PR #133854)
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/133854?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#133854** https://app.graphite.dev/github/pr/llvm/llvm-project/133854?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/133854?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#133853** https://app.graphite.dev/github/pr/llvm/llvm-project/133853?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/133854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133997)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (llvmbot) Changes Backport 65ee281 Requested by: @cor3ntin --- Full diff: https://github.com/llvm/llvm-project/pull/133997.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaAttr.cpp (+5) - (added) clang/test/Sema/GH126231.cpp (+18) ``diff diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 6907fa91e28c2..27b5eb5f2c773 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -14,6 +14,7 @@ #include "CheckExprLifetime.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/Attr.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/Preprocessor.h" @@ -219,6 +220,10 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) { void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { if (FD->getNumParams() == 0) return; + // Skip void returning functions (except constructors). This can occur in + // cases like 'as_const'. + if (!isa(FD) && FD->getReturnType()->isVoidType()) +return; if (unsigned BuiltinID = FD->getBuiltinID()) { // Add lifetime attribute to std::move, std::fowrard et al. diff --git a/clang/test/Sema/GH126231.cpp b/clang/test/Sema/GH126231.cpp new file mode 100644 index 0..d10fc79c3b628 --- /dev/null +++ b/clang/test/Sema/GH126231.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -Wno-ignored-attributes -Wno-unused-value -verify %s +// expected-no-diagnostics +namespace std { +template +constexpr const T& as_const(T&) noexcept; + +// We need two declarations to see the error for some reason. +template void as_const(const T&&) noexcept = delete; +template void as_const(const T&&) noexcept; +} + +namespace GH126231 { + +void test() { +int a = 1; +std::as_const(a); +} +} `` https://github.com/llvm/llvm-project/pull/133997 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] release/20.x: [Sanitizers][Darwin][Test] XFAIL malloc_zone.cpp (PR #133832)
https://github.com/wrotki milestoned https://github.com/llvm/llvm-project/pull/133832 ___ llvm-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] f07f968 - Backport/20.x: [LoongArch] Fix the type of tls-le symbols
Author: ZhaoQi Date: 2025-04-01T15:58:06-07:00 New Revision: f07f96873aa8ffd848240e4add1d4c382f5aac29 URL: https://github.com/llvm/llvm-project/commit/f07f96873aa8ffd848240e4add1d4c382f5aac29 DIFF: https://github.com/llvm/llvm-project/commit/f07f96873aa8ffd848240e4add1d4c382f5aac29.diff LOG: Backport/20.x: [LoongArch] Fix the type of tls-le symbols (cherry picked from commit d6dc74e19f5cdb6995b13329480e330aff113f96) Added: Modified: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll Removed: diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp index 30d2d0c1184ad..5698468c4754e 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp @@ -275,6 +275,7 @@ void LoongArchMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const { case VK_LoongArch_TLS_GD_HI20: case VK_LoongArch_TLS_DESC_PC_HI20: case VK_LoongArch_TLS_DESC_HI20: + case VK_LoongArch_TLS_LE_HI20_R: case VK_LoongArch_TLS_LD_PCREL20_S2: case VK_LoongArch_TLS_GD_PCREL20_S2: case VK_LoongArch_TLS_DESC_PCREL20_S2: diff --git a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll index fe5f2195f0dc7..d39454a51a445 100644 --- a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll +++ b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll @@ -5,12 +5,12 @@ ; RUN: llvm-readelf -s %t-la64 | FileCheck %s --check-prefix=LA64 ; LA32: Symbol table '.symtab' contains [[#]] entries: -; LA32-NEXT:Num:Value Size TypeBind Vis Ndx Name -; LA32: 0 NOTYPE GLOBAL DEFAULT UND tls_sym +; LA32-NEXT:Num:Value Size Type Bind Vis Ndx Name +; LA32: 0 TLS GLOBAL DEFAULT UND tls_sym ; LA64: Symbol table '.symtab' contains [[#]] entries: -; LA64-NEXT:Num:Value Size TypeBind Vis Ndx Name -; LA64: 0 NOTYPE GLOBAL DEFAULT UND tls_sym +; LA64-NEXT:Num:Value Size Type Bind Vis Ndx Name +; LA64: 0 TLS GLOBAL DEFAULT UND tls_sym @tls_sym = external thread_local(localexec) global i32 ___ llvm-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] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)
llvmbot wrote: @llvm/pr-subscribers-llvm-support Author: None (llvmbot) Changes Backport e57cd100ca297cf81854e35cccbf703e4aad Requested by: @tstellar --- Full diff: https://github.com/llvm/llvm-project/pull/133996.diff 2 Files Affected: - (modified) clang/include/clang/Support/Compiler.h (+1-1) - (modified) llvm/include/llvm/Support/Compiler.h (+1-1) ``diff diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h index 13582b899dc2a..5a74f8e3b6723 100644 --- a/clang/include/clang/Support/Compiler.h +++ b/clang/include/clang/Support/Compiler.h @@ -54,7 +54,7 @@ #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_EXPORT_TEMPLATE -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI #define CLANG_EXPORT_TEMPLATE diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index f9c57b89f1f03..dc8b5389069eb 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -203,7 +203,7 @@ #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE `` https://github.com/llvm/llvm-project/pull/133996 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133997)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/133997 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133998)
cor3ntin wrote: duplicate created by error https://github.com/llvm/llvm-project/pull/133998 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133836)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/133836 ___ llvm-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] ba00d9f - [LoongArch] Pre-commit test for #133225
Author: wanglei Date: 2025-04-01T16:07:12-07:00 New Revision: ba00d9f641e922684715e6364750bd722b4693d6 URL: https://github.com/llvm/llvm-project/commit/ba00d9f641e922684715e6364750bd722b4693d6 DIFF: https://github.com/llvm/llvm-project/commit/ba00d9f641e922684715e6364750bd722b4693d6.diff LOG: [LoongArch] Pre-commit test for #133225 Reviewed By: SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/133224 (cherry picked from commit 725a7b664b92cd2e884806de5a08900b43d43cce) Added: Modified: llvm/test/MC/LoongArch/Relocations/relocations.s Removed: diff --git a/llvm/test/MC/LoongArch/Relocations/relocations.s b/llvm/test/MC/LoongArch/Relocations/relocations.s index 091dce200b7de..f6d2cc149cc0c 100644 --- a/llvm/test/MC/LoongArch/Relocations/relocations.s +++ b/llvm/test/MC/LoongArch/Relocations/relocations.s @@ -3,6 +3,9 @@ # RUN: llvm-mc --filetype=obj --triple=loongarch64 < %s \ # RUN: | llvm-readobj -r - | FileCheck --check-prefix=RELOC %s +# RUN: not llvm-mc --triple=loongarch64 --defsym=FIXME=1 < %s 2>&1 \ +# RUN: | FileCheck --check-prefix=ERROR %s + ## Check prefixes: ## RELOC - Check the relocation in the object. ## FIXUP - Check the fixup on the instruction. @@ -308,3 +311,25 @@ pcaddi $t1, %desc_pcrel_20(foo) # RELOC: R_LARCH_TLS_DESC_PCREL20_S2 foo 0x0 # INSTR: pcaddi $t1, %desc_pcrel_20(foo) # FIXUP: fixup A - offset: 0, value: %desc_pcrel_20(foo), kind: FK_NONE + +.ifdef FIXME + +fld.s $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +fst.d $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +vld $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +vst $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +xvld $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +xvst $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +.endif ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133836)
github-actions[bot] wrote: @SixWeining (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/133836 ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
@@ -7379,8 +7378,11 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const { return false; } -if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(), mizvekov wrote: Minor preference for not doing that at this point, since this is the only user which looks at an AssociatedConstraint, most of the other users are still on expressions, and it's not clear which ones can be pack expanded in such a way to need the same treatment in future patches. https://github.com/llvm/llvm-project/pull/133190 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) (PR #133223)
pawosm-arm wrote: > @pawosm-arm Are you sure you are looking at the right PR? > [bug132435.f90](https://github.com/llvm/llvm-project/pull/133223/files#diff-1dda1d7a51b9f84047cb87bf94f9ac6aa4244f2b6ddf9b4513bb2c613b2e3c03) > is in the list of changed files. You got me. I was thinking about other thing I'm currently working on and in my mind everything messed up. Sorry for the confusion I caused. I'm not in a position to fix this, so I guess the best resolution would be to close this one. https://github.com/llvm/llvm-project/pull/133223 ___ llvm-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] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (PR #133027)
github-actions[bot] wrote: @zhaoqi5 (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/133027 ___ llvm-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] [ctxprof] Don't import roots elsewhere (PR #134012)
https://github.com/mtrofin created https://github.com/llvm/llvm-project/pull/134012 None >From b16f2bb1cd99334d3ce496bd58f33e4670d26c4a Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Tue, 1 Apr 2025 16:49:47 -0700 Subject: [PATCH] [ctxprof] Don't import roots elsewhere --- llvm/lib/Transforms/IPO/FunctionImport.cpp| 17 + .../ThinLTO/X86/ctxprof-separate-module.ll| 24 --- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index ae3b45a11996e..4415ed55ad9f3 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -516,6 +516,7 @@ class ModuleImportsManager { const ModuleSummaryIndex &Index, DenseMap *ExportLists = nullptr) : IsPrevailing(IsPrevailing), Index(Index), ExportLists(ExportLists) {} + virtual bool canImport(ValueInfo VI) { return true; } public: virtual ~ModuleImportsManager() = default; @@ -544,6 +545,10 @@ class WorkloadImportsManager : public ModuleImportsManager { // determine if a module's import list should be done by the base // ModuleImportsManager or by us. StringMap> Workloads; + // Track the roots to avoid importing them due to other callers. We want there + // to be only one variant, for which we optimize according to the contextual + // profile. + DenseSet Roots; void computeImportForModule(const GVSummaryMapTy &DefinedGVSummaries, @@ -782,12 +787,15 @@ class WorkloadImportsManager : public ModuleImportsManager { } auto &Set = Workloads[RootDefiningModule]; Root.getContainedGuids(ContainedGUIDs); + Roots.insert(RootVI); for (auto Guid : ContainedGUIDs) if (auto VI = Index.getValueInfo(Guid)) Set.insert(VI); } } + bool canImport(ValueInfo VI) override { return !Roots.contains(VI); } + public: WorkloadImportsManager( function_ref @@ -885,6 +893,15 @@ void ModuleImportsManager::computeImportForFunction( continue; } +if (!canImport(VI)) { + LLVM_DEBUG( + dbgs() << "Skipping over " << VI.getGUID() + << " because its import is handled in a different module."); + assert(VI.getSummaryList().size() == 1 && + "The root was expected to be an external symbol"); + continue; +} + auto GetBonusMultiplier = [](CalleeInfo::HotnessType Hotness) -> float { if (Hotness == CalleeInfo::HotnessType::Hot) return ImportHotMultiplier; diff --git a/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll b/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll index c7891d336cc89..391fe21a1b638 100644 --- a/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll +++ b/llvm/test/ThinLTO/X86/ctxprof-separate-module.ll @@ -1,3 +1,4 @@ +; REQUIRES: asserts ; Test workload based importing via -thinlto-pgo-ctx-prof with moving the whole ; graph to a new module. ; Use external linkage symbols so we don't depend on module paths which are @@ -10,19 +11,25 @@ ; ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m1.ll -o %t/m1.bc ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m2.ll -o %t/m2.bc +; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/m3.ll -o %t/m3.bc ; RUN: opt -module-summary -passes=assign-guid,ctx-instr-gen %t/6019442868614718803.ll -o %t/6019442868614718803.bc ; RUN: llvm-ctxprof-util fromYAML --input %t/ctxprof.yaml --output %t/ctxprof.bitstream -; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc %t/6019442868614718803.bc -thinlto-move-ctxprof-trees \ +; RUN: llvm-lto2 run %t/m1.bc %t/m2.bc %t/m3.bc %t/6019442868614718803.bc -thinlto-move-ctxprof-trees \ ; RUN: -o %t/result.o -save-temps \ ; RUN: -use-ctx-profile=%t/ctxprof.bitstream \ ; RUN: -r %t/m1.bc,m1_f1,plx \ -; RUN: -r %t/m2.bc,m2_f1,plx -; RUN: llvm-dis %t/result.o.3.3.import.bc -o - | FileCheck %s +; RUN: -r %t/m2.bc,m2_f1,plx \ +; RUN: -r %t/m3.bc,m1_f1 \ +; RUN: -r %t/m3.bc,m3_f1,plx -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=ABSENT-MSG +; RUN: llvm-dis %t/result.o.4.3.import.bc -o - | FileCheck %s +; RUN: llvm-dis %t/result.o.3.3.import.bc -o - | FileCheck %s --check-prefix=ABSENT ; ; ; CHECK: m1_f1() ; CHECK: m2_f1() +; ABSENT: declare void @m1_f1() +; ABSENT-MSG: Skipping over 6019442868614718803 because its import is handled in a different module. ; ;--- ctxprof.yaml Contexts: @@ -51,6 +58,17 @@ define dso_local void @m2_f1() { ret void } +;--- m3.ll +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" + +declare void @m1_f1() + +define dso_local void @m3_f1() { + call void @m1_f1() + ret void +} + ;--- 6019442868614718803.ll target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-linux-gnu"
[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Move fix-tle-le-sym-type test to test/MC. NFC (#133839) (PR #134014)
llvmbot wrote: @llvm/pr-subscribers-mc Author: None (llvmbot) Changes Backport 46968310cb837e4b32859edef2107080b828b117 Requested by: @zhaoqi5 --- Full diff: https://github.com/llvm/llvm-project/pull/134014.diff 2 Files Affected: - (removed) llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll (-24) - (added) llvm/test/MC/LoongArch/Relocations/relocation-specifier.s (+26) ``diff diff --git a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll deleted file mode 100644 index d39454a51a445..0 --- a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll +++ /dev/null @@ -1,24 +0,0 @@ -; RUN: llc --mtriple=loongarch32 --filetype=obj %s -o %t-la32 -; RUN: llvm-readelf -s %t-la32 | FileCheck %s --check-prefix=LA32 - -; RUN: llc --mtriple=loongarch64 --filetype=obj %s -o %t-la64 -; RUN: llvm-readelf -s %t-la64 | FileCheck %s --check-prefix=LA64 - -; LA32: Symbol table '.symtab' contains [[#]] entries: -; LA32-NEXT:Num:Value Size Type Bind Vis Ndx Name -; LA32: 0 TLS GLOBAL DEFAULT UND tls_sym - -; LA64: Symbol table '.symtab' contains [[#]] entries: -; LA64-NEXT:Num:Value Size Type Bind Vis Ndx Name -; LA64: 0 TLS GLOBAL DEFAULT UND tls_sym - -@tls_sym = external thread_local(localexec) global i32 - -define dso_local signext i32 @test_tlsle() nounwind { -entry: - %0 = call ptr @llvm.threadlocal.address.p0(ptr @tls_sym) - %1 = load i32, ptr %0 - ret i32 %1 -} - -declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) diff --git a/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s b/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s new file mode 100644 index 0..d0898aaab92fe --- /dev/null +++ b/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s @@ -0,0 +1,26 @@ +# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t-la32 +# RUN: llvm-readelf -rs %t-la32 | FileCheck %s --check-prefixes=CHECK,RELOC32 +# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t-la64 +# RUN: llvm-readelf -rs %t-la64 | FileCheck %s --check-prefixes=CHECK,RELOC64 + +## This test is similar to test/MC/CSKY/relocation-specifier.s. + +# RELOC32: '.rela.data' +# RELOC32: R_LARCH_32 .data + 0 + +# RELOC64: '.rela.data' +# RELOC64: R_LARCH_32 .data + 0 + +# CHECK: TLS GLOBAL DEFAULT UND gd +# CHECK: TLS GLOBAL DEFAULT UND ld +# CHECK: TLS GLOBAL DEFAULT UND ie +# CHECK: TLS GLOBAL DEFAULT UND le + +pcalau12i $t1, %gd_pc_hi20(gd) +pcalau12i $t1, %ld_pc_hi20(ld) +pcalau12i $t1, %ie_pc_hi20(ie) +lu12i.w $t1, %le_hi20_r(le) + +.data +local: +.long local `` https://github.com/llvm/llvm-project/pull/134014 ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/133190 >From d6c84d34e82578a69a914015cdfeaa7dfd3889c8 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 26 Mar 2025 18:38:34 -0300 Subject: [PATCH] [clang] support pack expansions for trailing requires clauses This fixes a crash when evaluating constraints from trailing requires clauses, when these are part of a generic lambda which is expanded. --- .../refactor/tweaks/ExtractVariable.cpp | 6 +-- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/AST/ASTNodeTraverser.h| 4 +- clang/include/clang/AST/Decl.h| 35 +++-- clang/include/clang/AST/DeclCXX.h | 20 clang/include/clang/AST/ExprCXX.h | 2 +- clang/include/clang/AST/RecursiveASTVisitor.h | 9 ++-- clang/include/clang/Sema/Sema.h | 14 ++--- clang/lib/AST/ASTContext.cpp | 7 ++- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/AST/Decl.cpp| 14 ++--- clang/lib/AST/DeclCXX.cpp | 33 +++- clang/lib/AST/DeclPrinter.cpp | 10 ++-- clang/lib/AST/DeclTemplate.cpp| 4 +- clang/lib/AST/ExprCXX.cpp | 2 +- clang/lib/AST/ItaniumMangle.cpp | 2 +- clang/lib/ASTMatchers/ASTMatchFinder.cpp | 3 +- clang/lib/Index/IndexDecl.cpp | 4 +- clang/lib/Sema/SemaConcept.cpp| 6 +-- clang/lib/Sema/SemaDecl.cpp | 21 clang/lib/Sema/SemaDeclCXX.cpp| 4 +- clang/lib/Sema/SemaFunctionEffects.cpp| 2 +- clang/lib/Sema/SemaLambda.cpp | 18 --- clang/lib/Sema/SemaOverload.cpp | 12 +++-- clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 51 --- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +- clang/lib/Sema/TreeTransform.h| 7 ++- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 5 +- .../SemaCXX/fold_lambda_with_variadics.cpp| 9 clang/tools/libclang/CIndex.cpp | 2 +- 31 files changed, 187 insertions(+), 133 deletions(-) diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp index d84e501b87ce7..90dac3b76c648 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp @@ -100,9 +100,9 @@ computeReferencedDecls(const clang::Expr *Expr) { TraverseLambdaCapture(LExpr, &Capture, Initializer); } - if (clang::Expr *const RequiresClause = - LExpr->getTrailingRequiresClause()) { -TraverseStmt(RequiresClause); + if (const clang::Expr *RequiresClause = + LExpr->getTrailingRequiresClause().ConstraintExpr) { +TraverseStmt(const_cast(RequiresClause)); } for (auto *const TemplateParam : LExpr->getExplicitTemplateParameters()) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c4e82678949ff..f1066139c8514 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -373,6 +373,8 @@ Bug Fixes to C++ Support - Improved fix for an issue with pack expansions of type constraints, where this now also works if the constraint has non-type or template template parameters. (#GH131798) +- Fix crash when evaluating trailing requires clause of generic lambdas which are part of + a pack expansion. - Fixes matching of nested template template parameters. (#GH130362) - Correctly diagnoses template template paramters which have a pack parameter not in the last position. diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h index f086d8134a64b..7bb435146f752 100644 --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -538,8 +538,8 @@ class ASTNodeTraverser for (const auto *Parameter : D->parameters()) Visit(Parameter); -if (const Expr *TRC = D->getTrailingRequiresClause()) - Visit(TRC); +if (const AssociatedConstraint &TRC = D->getTrailingRequiresClause()) + Visit(TRC.ConstraintExpr); if (Traversal == TK_IgnoreUnlessSpelledInSource && D->isDefaulted()) return; diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 9e7e93d98c9d1..adf3634d205bc 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -81,13 +81,17 @@ enum class ImplicitParamKind; // Holds a constraint expression along with a pack expansion index, if // expanded. struct AssociatedConstraint { - const Expr *ConstraintExpr; - int ArgumentPackSubstitutionIndex; + const Expr *ConstraintExpr = nullptr; + int ArgumentPackSubstitutionIndex = -1; + + constexp
[llvm-branch-commits] [llvm] llvm-reduce: Fix overly conservative operands-to-args user restriction (PR #133854)
arsenm wrote: > with this we start replacing functions that have indirect references so we > may break indirect calls, but I think that's fine ReduceArguments already does that (though eventually I think we need an option to preserve executability) https://github.com/llvm/llvm-project/pull/133854 ___ llvm-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] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/133996 Backport e57cd100ca297cf81854e35cccbf703e4aad Requested by: @tstellar >From ea7c6218f2195694d92a7951b25c833aa99bfdb0 Mon Sep 17 00:00:00 2001 From: Anutosh Bhat Date: Mon, 17 Mar 2025 16:44:49 +0530 Subject: [PATCH] Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While building llvm (clang, lld) against emscripten we see this [error](https://github.com/emscripten-forge/recipes/actions/runs/13803029307/job/38608794602#step:9:1715) ``` │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9: │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI' │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ ``` Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see [llvm/Support/Compiler.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L206-L210), the condition only checked for the platform __WASM__ . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI. The successful build after using this patch can be seen [here](https://github.com/emscripten-forge/recipes/actions/runs/13805214092/job/38614585621) (cherry picked from commit e57cd100ca297cf81854e35cccbf703e4aad) --- clang/include/clang/Support/Compiler.h | 2 +- llvm/include/llvm/Support/Compiler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h index 13582b899dc2a..5a74f8e3b6723 100644 --- a/clang/include/clang/Support/Compiler.h +++ b/clang/include/clang/Support/Compiler.h @@ -54,7 +54,7 @@ #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_EXPORT_TEMPLATE -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI #define CLANG_EXPORT_TEMPLATE diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index f9c57b89f1f03..dc8b5389069eb 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -203,7 +203,7 @@ #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE ___ llvm-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] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/133996 >From 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247 Mon Sep 17 00:00:00 2001 From: Anutosh Bhat Date: Mon, 17 Mar 2025 16:44:49 +0530 Subject: [PATCH] Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While building llvm (clang, lld) against emscripten we see this [error](https://github.com/emscripten-forge/recipes/actions/runs/13803029307/job/38608794602#step:9:1715) ``` │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9: │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI' │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ ``` Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see [llvm/Support/Compiler.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L206-L210), the condition only checked for the platform __WASM__ . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI. The successful build after using this patch can be seen [here](https://github.com/emscripten-forge/recipes/actions/runs/13805214092/job/38614585621) (cherry picked from commit e57cd100ca297cf81854e35cccbf703e4aad) --- clang/include/clang/Support/Compiler.h | 2 +- llvm/include/llvm/Support/Compiler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h index 13582b899dc2a..5a74f8e3b6723 100644 --- a/clang/include/clang/Support/Compiler.h +++ b/clang/include/clang/Support/Compiler.h @@ -54,7 +54,7 @@ #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_EXPORT_TEMPLATE -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI #define CLANG_EXPORT_TEMPLATE diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index f9c57b89f1f03..dc8b5389069eb 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -203,7 +203,7 @@ #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE ___ llvm-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] 58df0ef - Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578)
Author: Anutosh Bhat Date: 2025-04-01T16:44:12-07:00 New Revision: 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247 URL: https://github.com/llvm/llvm-project/commit/58df0ef89dd64126512e4ee27b4ac3fd8ddf6247 DIFF: https://github.com/llvm/llvm-project/commit/58df0ef89dd64126512e4ee27b4ac3fd8ddf6247.diff LOG: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) While building llvm (clang, lld) against emscripten we see this [error](https://github.com/emscripten-forge/recipes/actions/runs/13803029307/job/38608794602#step:9:1715) ``` │ │ In file included from $SRC_DIR/llvm/lib/Frontend/OpenACC/ACC.cpp:9: │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:1: error: unknown type name 'LLVM_ABI' │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ │ │ $SRC_DIR/build/include/llvm/Frontend/OpenACC/ACC.h.inc:192:19: error: expected ';' after top level declarator │ │ 192 | LLVM_ABI Directive getOpenACCDirectiveKind(llvm::StringRef Str); │ │ | ^ ``` Now this was happening because we weren't defining LLVM_ABI correctly when building against emscripten. If you see [llvm/Support/Compiler.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L206-L210), the condition only checked for the platform __WASM__ . Now Emscripten targets WebAssembly but doesn't imply the platform by default so the check isn't complete to define LLVM_ABI. The successful build after using this patch can be seen [here](https://github.com/emscripten-forge/recipes/actions/runs/13805214092/job/38614585621) (cherry picked from commit e57cd100ca297cf81854e35cccbf703e4aad) Added: Modified: clang/include/clang/Support/Compiler.h llvm/include/llvm/Support/Compiler.h Removed: diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h index 13582b899dc2a..5a74f8e3b6723 100644 --- a/clang/include/clang/Support/Compiler.h +++ b/clang/include/clang/Support/Compiler.h @@ -54,7 +54,7 @@ #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_EXPORT_TEMPLATE -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define CLANG_TEMPLATE_ABI #define CLANG_EXPORT_TEMPLATE diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index f9c57b89f1f03..dc8b5389069eb 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -203,7 +203,7 @@ #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_EXPORT_TEMPLATE #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(__MACH__) || defined(__WASM__) +#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
@@ -7379,8 +7378,11 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const { return false; } -if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(), erichkeane wrote: Ah, hrmph. This is really unergonomic, and I would really like to see all uses of this do a better job at making sure they are working with the constraints. That said, I get the objection at least near term, and am OK with leaving this as-is now, and put on the 'TODO' list. https://github.com/llvm/llvm-project/pull/133190 ___ llvm-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] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)
mtrofin 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/134011?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#134012** https://app.graphite.dev/github/pr/llvm/llvm-project/134012?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#134011** https://app.graphite.dev/github/pr/llvm/llvm-project/134011?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134011?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#133992** https://app.graphite.dev/github/pr/llvm/llvm-project/133992?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/134011 ___ llvm-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] [ctxprof] Don't import roots elsewhere (PR #134012)
mtrofin 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/134012?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#134012** https://app.graphite.dev/github/pr/llvm/llvm-project/134012?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134012?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#134011** https://app.graphite.dev/github/pr/llvm/llvm-project/134011?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#133992** https://app.graphite.dev/github/pr/llvm/llvm-project/133992?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/134012 ___ llvm-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] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` (PR #134011)
https://github.com/mtrofin created https://github.com/llvm/llvm-project/pull/134011 None >From 68b499fccf6202d3abdbf30aeabaa5a9ca541a40 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Tue, 1 Apr 2025 16:53:48 -0700 Subject: [PATCH] [ctxprof][nfc] Make `computeImportForFunction` a member of `ModuleImportsManager` --- llvm/lib/Transforms/IPO/FunctionImport.cpp | 26 -- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index faa052bb4d5b6..ae3b45a11996e 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -497,6 +497,13 @@ static const char *getFailureName(FunctionImporter::ImportFailureReason Reason); /// Determine the list of imports and exports for each module. class ModuleImportsManager { + void computeImportForFunction( + const FunctionSummary &Summary, unsigned Threshold, + const GVSummaryMapTy &DefinedGVSummaries, + SmallVectorImpl &Worklist, GlobalsImporter &GVImporter, + FunctionImporter::ImportMapTy &ImportList, + FunctionImporter::ImportThresholdsTy &ImportThresholds); + protected: function_ref IsPrevailing; @@ -851,14 +858,11 @@ getFailureName(FunctionImporter::ImportFailureReason Reason) { /// Compute the list of functions to import for a given caller. Mark these /// imported functions and the symbols they reference in their source module as /// exported from their source module. -static void computeImportForFunction( -const FunctionSummary &Summary, const ModuleSummaryIndex &Index, -const unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries, -function_ref -isPrevailing, +void ModuleImportsManager::computeImportForFunction( +const FunctionSummary &Summary, const unsigned Threshold, +const GVSummaryMapTy &DefinedGVSummaries, SmallVectorImpl &Worklist, GlobalsImporter &GVImporter, FunctionImporter::ImportMapTy &ImportList, -DenseMap *ExportLists, FunctionImporter::ImportThresholdsTy &ImportThresholds) { GVImporter.onImportingSummary(Summary); static int ImportCount = 0; @@ -1063,9 +1067,8 @@ void ModuleImportsManager::computeImportForModule( // Skip import for global variables continue; LLVM_DEBUG(dbgs() << "Initialize import for " << VI << "\n"); -computeImportForFunction(*FuncSummary, Index, ImportInstrLimit, - DefinedGVSummaries, IsPrevailing, Worklist, GVI, - ImportList, ExportLists, ImportThresholds); +computeImportForFunction(*FuncSummary, ImportInstrLimit, DefinedGVSummaries, + Worklist, GVI, ImportList, ImportThresholds); } // Process the newly imported functions and add callees to the worklist. @@ -1075,9 +1078,8 @@ void ModuleImportsManager::computeImportForModule( auto Threshold = std::get<1>(GVInfo); if (auto *FS = dyn_cast(Summary)) - computeImportForFunction(*FS, Index, Threshold, DefinedGVSummaries, - IsPrevailing, Worklist, GVI, ImportList, - ExportLists, ImportThresholds); + computeImportForFunction(*FS, Threshold, DefinedGVSummaries, Worklist, + GVI, ImportList, ImportThresholds); } // Print stats about functions considered but rejected for importing ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst (PR #133836)
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/133836 >From ba00d9f641e922684715e6364750bd722b4693d6 Mon Sep 17 00:00:00 2001 From: wanglei Date: Fri, 28 Mar 2025 10:21:23 +0800 Subject: [PATCH 1/2] [LoongArch] Pre-commit test for #133225 Reviewed By: SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/133224 (cherry picked from commit 725a7b664b92cd2e884806de5a08900b43d43cce) --- .../MC/LoongArch/Relocations/relocations.s| 25 +++ 1 file changed, 25 insertions(+) diff --git a/llvm/test/MC/LoongArch/Relocations/relocations.s b/llvm/test/MC/LoongArch/Relocations/relocations.s index 091dce200b7de..f6d2cc149cc0c 100644 --- a/llvm/test/MC/LoongArch/Relocations/relocations.s +++ b/llvm/test/MC/LoongArch/Relocations/relocations.s @@ -3,6 +3,9 @@ # RUN: llvm-mc --filetype=obj --triple=loongarch64 < %s \ # RUN: | llvm-readobj -r - | FileCheck --check-prefix=RELOC %s +# RUN: not llvm-mc --triple=loongarch64 --defsym=FIXME=1 < %s 2>&1 \ +# RUN: | FileCheck --check-prefix=ERROR %s + ## Check prefixes: ## RELOC - Check the relocation in the object. ## FIXUP - Check the fixup on the instruction. @@ -308,3 +311,25 @@ pcaddi $t1, %desc_pcrel_20(foo) # RELOC: R_LARCH_TLS_DESC_PCREL20_S2 foo 0x0 # INSTR: pcaddi $t1, %desc_pcrel_20(foo) # FIXUP: fixup A - offset: 0, value: %desc_pcrel_20(foo), kind: FK_NONE + +.ifdef FIXME + +fld.s $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +fst.d $ft1, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047] + +vld $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +vst $vr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047] + +xvld $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +xvst $xr9, $a0, %pc_lo12(foo) +# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047] + +.endif >From e256eda15377acf4e26ea135a33e20ec4bd23ac0 Mon Sep 17 00:00:00 2001 From: wanglei Date: Fri, 28 Mar 2025 11:20:17 +0800 Subject: [PATCH 2/2] [LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst This also fixes errors when using Clang with step-by-step compilation. Because the optimization will pass relocation information to memory access instructions. For example: t.c: ``` float f = 0.1; float foo() { return f;} ``` ``` clang --target=loongarch64 -O2 -c t.c --save-temps ``` Reviewed By: tangaac, SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/133225 (cherry picked from commit d055e58334a91dcbaee22eb87bcdae85a1f33cd4) --- .../LoongArch/LoongArchFloatInstrFormats.td | 4 +-- .../LoongArch/LoongArchLASXInstrInfo.td | 4 +-- .../Target/LoongArch/LoongArchLSXInstrInfo.td | 4 +-- .../MC/LoongArch/Relocations/relocations.s| 31 +++ llvm/test/MC/LoongArch/lasx/invalid-imm.s | 12 +++ llvm/test/MC/LoongArch/lsx/invalid-imm.s | 12 +++ 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td b/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td index f66f620ca8b26..ce42236895c76 100644 --- a/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td +++ b/llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td @@ -206,7 +206,7 @@ class FP_LOAD_3R op, RegisterClass rc = FPR32> : FPFmtMEM; class FP_LOAD_2RI12 op, RegisterClass rc = FPR32> -: FPFmt2RI12; } // hasSideEffects = 0, mayLoad = 1, mayStore = 0 @@ -215,7 +215,7 @@ class FP_STORE_3R op, RegisterClass rc = FPR32> : FPFmtMEM; class FP_STORE_2RI12 op, RegisterClass rc = FPR32> -: FPFmt2RI12; } // hasSideEffects = 0, mayLoad = 0, mayStore = 1 diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td index 24b5ed5a9344f..7022fddf34100 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td @@ -186,10 +186,10 @@ class LASX2RI10_Load op, Operand ImmOpnd = simm10_lsl2> class LASX2RI11_Load op, Operand ImmOpnd = simm11_lsl1> : Fmt2RI11_XRI; -class LASX2RI12_Load op, Operand ImmOpnd = simm12> +class LASX2RI12_Load op, Operand ImmOpnd = simm12_addlike> : Fmt2RI12_XRI; -class LASX2RI12_Store op, Operand ImmOpnd = simm12> +class LASX2RI12_Store op, Operand ImmOpnd = simm12_addlike> : Fmt2RI12_XRI; diff --git a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td index d2063a8aaae9b..e37de4f545a2a 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td @@ -374,10 +374,10 @@ class LSX2RI10_Load op
[llvm-branch-commits] [flang] release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) (PR #133223)
tstellar wrote: @pawosm-arm Are you sure you are looking at the right PR? [bug132435.f90](https://github.com/llvm/llvm-project/pull/133223/files#diff-1dda1d7a51b9f84047cb87bf94f9ac6aa4244f2b6ddf9b4513bb2c613b2e3c03) is in the list of changed files. https://github.com/llvm/llvm-project/pull/133223 ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
@@ -78,6 +78,22 @@ class UnresolvedSetImpl; class VarTemplateDecl; enum class ImplicitParamKind; +// Holds a constraint expression along with a pack expansion index, if +// expanded. +struct AssociatedConstraint { + const Expr *ConstraintExpr = nullptr; + int ArgumentPackSubstitutionIndex = -1; erichkeane wrote: Honestly, this is something that I find myself re-learning EVERY SINGLE time. It is unbelievably confusing and error-prone to figure out what the 'non-value' is here. In reality it would be great if we had a std::optional for all of these (or, at least, a type to wrap the idea of 2^N-2 values and a sentinel). While I understand the consistency argument, I'd say we should 'do it right' this time (or at least more so), and clean up over time. THAT SAID, if the -1 doesn't get 'outside' of this class (that is, the constructor ensure it doesn't take a -1, and that just be the 'has no pack' version-by-construction via an alternate constructor) other than for the purposes of serialization (perhaps via a ::CreateFromDeserialization esque method), than I think that at least limits the fallout of hte magic-number to only the internals of this, which is more acceptable. https://github.com/llvm/llvm-project/pull/133190 ___ llvm-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] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/133996 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133998)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/133998 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133997)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/133997 Backport 65ee281 Requested by: @cor3ntin >From 86ee14f26f1569d39b452ff13d44d05a357feb6b Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Mon, 24 Mar 2025 17:42:33 +0100 Subject: [PATCH] [clang] Do not infer lifetimebound for functions with void return type (#131997) Fixes: https://github.com/llvm/llvm-project/issues/126231 Also found in : https://github.com/microsoft/STL/issues/5271 (cherry picked from commit 65ee2813f9f9a8cd11c5e9ea372da7d12867b52f) --- clang/lib/Sema/SemaAttr.cpp | 5 + clang/test/Sema/GH126231.cpp | 18 ++ 2 files changed, 23 insertions(+) create mode 100644 clang/test/Sema/GH126231.cpp diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 6907fa91e28c2..27b5eb5f2c773 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -14,6 +14,7 @@ #include "CheckExprLifetime.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/Attr.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/Preprocessor.h" @@ -219,6 +220,10 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) { void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { if (FD->getNumParams() == 0) return; + // Skip void returning functions (except constructors). This can occur in + // cases like 'as_const'. + if (!isa(FD) && FD->getReturnType()->isVoidType()) +return; if (unsigned BuiltinID = FD->getBuiltinID()) { // Add lifetime attribute to std::move, std::fowrard et al. diff --git a/clang/test/Sema/GH126231.cpp b/clang/test/Sema/GH126231.cpp new file mode 100644 index 0..d10fc79c3b628 --- /dev/null +++ b/clang/test/Sema/GH126231.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -Wno-ignored-attributes -Wno-unused-value -verify %s +// expected-no-diagnostics +namespace std { +template +constexpr const T& as_const(T&) noexcept; + +// We need two declarations to see the error for some reason. +template void as_const(const T&&) noexcept = delete; +template void as_const(const T&&) noexcept; +} + +namespace GH126231 { + +void test() { +int a = 1; +std::as_const(a); +} +} ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133998)
llvmbot wrote: @ilya-biryukov What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/133998 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/20.x: [clang] Do not infer lifetimebound for functions with void return type (#131997) (PR #133997)
llvmbot wrote: @ilya-biryukov What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/133997 ___ llvm-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] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (PR #133027)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/133027 ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/133190 >From 1ee94ea392f1b1a46eba9fe031bf3523e1840a09 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Wed, 26 Mar 2025 18:38:34 -0300 Subject: [PATCH] [clang] support pack expansions for trailing requires clauses This fixes a crash when evaluating constraints from trailing requires clauses, when these are part of a generic lambda which is expanded. --- .../refactor/tweaks/ExtractVariable.cpp | 6 +-- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/AST/ASTNodeTraverser.h| 4 +- clang/include/clang/AST/Decl.h| 35 +++-- clang/include/clang/AST/DeclCXX.h | 20 clang/include/clang/AST/ExprCXX.h | 2 +- clang/include/clang/AST/RecursiveASTVisitor.h | 9 ++-- clang/include/clang/Sema/Sema.h | 14 ++--- clang/lib/AST/ASTContext.cpp | 7 ++- clang/lib/AST/ASTImporter.cpp | 5 +- clang/lib/AST/Decl.cpp| 14 ++--- clang/lib/AST/DeclCXX.cpp | 33 +++- clang/lib/AST/DeclPrinter.cpp | 10 ++-- clang/lib/AST/DeclTemplate.cpp| 4 +- clang/lib/AST/ExprCXX.cpp | 2 +- clang/lib/AST/ItaniumMangle.cpp | 2 +- clang/lib/ASTMatchers/ASTMatchFinder.cpp | 3 +- clang/lib/Index/IndexDecl.cpp | 4 +- clang/lib/Sema/SemaConcept.cpp| 6 +-- clang/lib/Sema/SemaDecl.cpp | 22 clang/lib/Sema/SemaDeclCXX.cpp| 4 +- clang/lib/Sema/SemaFunctionEffects.cpp| 2 +- clang/lib/Sema/SemaLambda.cpp | 18 --- clang/lib/Sema/SemaOverload.cpp | 12 +++-- clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 51 --- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +- clang/lib/Sema/TreeTransform.h| 7 ++- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +- clang/lib/Serialization/ASTWriterDecl.cpp | 5 +- .../SemaCXX/fold_lambda_with_variadics.cpp| 9 clang/tools/libclang/CIndex.cpp | 2 +- 31 files changed, 188 insertions(+), 133 deletions(-) diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp index d84e501b87ce7..90dac3b76c648 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp @@ -100,9 +100,9 @@ computeReferencedDecls(const clang::Expr *Expr) { TraverseLambdaCapture(LExpr, &Capture, Initializer); } - if (clang::Expr *const RequiresClause = - LExpr->getTrailingRequiresClause()) { -TraverseStmt(RequiresClause); + if (const clang::Expr *RequiresClause = + LExpr->getTrailingRequiresClause().ConstraintExpr) { +TraverseStmt(const_cast(RequiresClause)); } for (auto *const TemplateParam : LExpr->getExplicitTemplateParameters()) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c4e82678949ff..f1066139c8514 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -373,6 +373,8 @@ Bug Fixes to C++ Support - Improved fix for an issue with pack expansions of type constraints, where this now also works if the constraint has non-type or template template parameters. (#GH131798) +- Fix crash when evaluating trailing requires clause of generic lambdas which are part of + a pack expansion. - Fixes matching of nested template template parameters. (#GH130362) - Correctly diagnoses template template paramters which have a pack parameter not in the last position. diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h index f086d8134a64b..7bb435146f752 100644 --- a/clang/include/clang/AST/ASTNodeTraverser.h +++ b/clang/include/clang/AST/ASTNodeTraverser.h @@ -538,8 +538,8 @@ class ASTNodeTraverser for (const auto *Parameter : D->parameters()) Visit(Parameter); -if (const Expr *TRC = D->getTrailingRequiresClause()) - Visit(TRC); +if (const AssociatedConstraint &TRC = D->getTrailingRequiresClause()) + Visit(TRC.ConstraintExpr); if (Traversal == TK_IgnoreUnlessSpelledInSource && D->isDefaulted()) return; diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 9e7e93d98c9d1..adf3634d205bc 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -81,13 +81,17 @@ enum class ImplicitParamKind; // Holds a constraint expression along with a pack expansion index, if // expanded. struct AssociatedConstraint { - const Expr *ConstraintExpr; - int ArgumentPackSubstitutionIndex; + const Expr *ConstraintExpr = nullptr; + int ArgumentPackSubstitutionIndex = -1; + + constexp
[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Move fix-tle-le-sym-type test to test/MC. NFC (#133839) (PR #134014)
llvmbot wrote: @llvm/pr-subscribers-backend-loongarch Author: None (llvmbot) Changes Backport 46968310cb837e4b32859edef2107080b828b117 Requested by: @zhaoqi5 --- Full diff: https://github.com/llvm/llvm-project/pull/134014.diff 2 Files Affected: - (removed) llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll (-24) - (added) llvm/test/MC/LoongArch/Relocations/relocation-specifier.s (+26) ``diff diff --git a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll deleted file mode 100644 index d39454a51a445..0 --- a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll +++ /dev/null @@ -1,24 +0,0 @@ -; RUN: llc --mtriple=loongarch32 --filetype=obj %s -o %t-la32 -; RUN: llvm-readelf -s %t-la32 | FileCheck %s --check-prefix=LA32 - -; RUN: llc --mtriple=loongarch64 --filetype=obj %s -o %t-la64 -; RUN: llvm-readelf -s %t-la64 | FileCheck %s --check-prefix=LA64 - -; LA32: Symbol table '.symtab' contains [[#]] entries: -; LA32-NEXT:Num:Value Size Type Bind Vis Ndx Name -; LA32: 0 TLS GLOBAL DEFAULT UND tls_sym - -; LA64: Symbol table '.symtab' contains [[#]] entries: -; LA64-NEXT:Num:Value Size Type Bind Vis Ndx Name -; LA64: 0 TLS GLOBAL DEFAULT UND tls_sym - -@tls_sym = external thread_local(localexec) global i32 - -define dso_local signext i32 @test_tlsle() nounwind { -entry: - %0 = call ptr @llvm.threadlocal.address.p0(ptr @tls_sym) - %1 = load i32, ptr %0 - ret i32 %1 -} - -declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) diff --git a/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s b/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s new file mode 100644 index 0..d0898aaab92fe --- /dev/null +++ b/llvm/test/MC/LoongArch/Relocations/relocation-specifier.s @@ -0,0 +1,26 @@ +# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t-la32 +# RUN: llvm-readelf -rs %t-la32 | FileCheck %s --check-prefixes=CHECK,RELOC32 +# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t-la64 +# RUN: llvm-readelf -rs %t-la64 | FileCheck %s --check-prefixes=CHECK,RELOC64 + +## This test is similar to test/MC/CSKY/relocation-specifier.s. + +# RELOC32: '.rela.data' +# RELOC32: R_LARCH_32 .data + 0 + +# RELOC64: '.rela.data' +# RELOC64: R_LARCH_32 .data + 0 + +# CHECK: TLS GLOBAL DEFAULT UND gd +# CHECK: TLS GLOBAL DEFAULT UND ld +# CHECK: TLS GLOBAL DEFAULT UND ie +# CHECK: TLS GLOBAL DEFAULT UND le + +pcalau12i $t1, %gd_pc_hi20(gd) +pcalau12i $t1, %ld_pc_hi20(ld) +pcalau12i $t1, %ie_pc_hi20(ie) +lu12i.w $t1, %le_hi20_r(le) + +.data +local: +.long local `` https://github.com/llvm/llvm-project/pull/134014 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Move fix-tle-le-sym-type test to test/MC. NFC (#133839) (PR #134014)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/134014 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Fix overly conservative operands-to-args user restriction (PR #133854)
@@ -19,12 +19,9 @@ using namespace llvm; -static bool canReplaceFunction(Function *F) { - return all_of(F->uses(), [](Use &Op) { -if (auto *CI = dyn_cast(Op.getUser())) - return &CI->getCalledOperandUse() == &Op; -return false; - }); +static bool canReplaceFunction(const Function &F) { + // TODO: Add controls to avoid ABI breaks (e.g. don't break main) arsenm wrote: It shoul, but it would be useful to have a mode to opt out and avoid breaking anything needed to execute the function (bugpoint has a more primitive version of the option than the one I would like) https://github.com/llvm/llvm-project/pull/133854 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] release/20.x: [flang] Fix missed case of symbol renaming in module file generation (#132475) (PR #133223)
pawosm-arm wrote: > It looks like the test from this patch is failing. I need some help with pinpointing that. Locally I can't reproduce any test failing either with this patch or because of this patch. Also I can't see any piece of log confirming that any test case from this patch (`clang/test/Driver/fveclib.c`, `flang/test/Driver/fveclib.f90`) couldn't pass. I can only see a report that the `Flang.Semantics/bug132435.f90` test is failing on both Windows and Linux. I looked into the `bug132435.f90` file and can't see anything even remotely related to my patch. I can assume that the reason for this failure lies beyond my commit and any other commit would suffer from the same failure. https://github.com/llvm/llvm-project/pull/133223 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [ARM] Speedups for CombineBaseUpdate. (#129725) (PR #130035)
github-actions[bot] wrote: @davemgreen (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/130035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)
@@ -0,0 +1,7343 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Header File + * Copyright (C) 2012-2023 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) pcc wrote: Okay, I will contact bo...@llvm.org about this new usage. I don't have a strong opinion about the hash algorithm. XXH3_64 was chosen for these reasons: 1. It was the easiest to incorporate into compiler-rt as it was already available as a header-only library without dependencies. 2. It was already being used in LLVM, so I imagined that licensing wouldn't be as much of a concern. 3. It was faster than the other algorithms according to the [xxhash homepage](https://xxhash.com/). BLAKE3 isn't listed there but we can extrapolate from [BLAKE3's claim](https://github.com/BLAKE3-team/BLAKE3) of being ~7x faster than BLAKE2. (I know I said elsewhere that performance is less of a concern for these functions, but all other things being equal, we may as well go with the algorithm with the best performance.) If the board decides not to allow use in compiler-rt it should be possible to switch to one of the other algorithms after changing its code as needed to remove dependencies. https://github.com/llvm/llvm-project/pull/133530 ___ llvm-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] dd68750 - Revert "AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_a…"
Author: Petr Hosek Date: 2025-04-01T09:31:46-07:00 New Revision: dd68750d7e2077020552e83e68056f179d98 URL: https://github.com/llvm/llvm-project/commit/dd68750d7e2077020552e83e68056f179d98 DIFF: https://github.com/llvm/llvm-project/commit/dd68750d7e2077020552e83e68056f179d98.diff LOG: Revert "AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_a…" This reverts commit dd862356e20d2d7e0d0356dff5bd80623c14febc. Added: llvm/test/CodeGen/ARM/plt-relative-reloc.ll llvm/test/CodeGen/RISCV/plt-relative-reloc.ll llvm/test/CodeGen/X86/x86-64-plt-relative-reloc.ll llvm/test/CodeGen/X86/x86-plt-relative-reloc.ll Modified: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Removed: llvm/test/CodeGen/ARM/relative-reloc.ll llvm/test/CodeGen/RISCV/relative-reloc.ll llvm/test/CodeGen/X86/relative-reloc-32.ll llvm/test/CodeGen/X86/relative-reloc-64.ll diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index f035d81e85ddb..8b0e5798d1b61 100644 --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -125,6 +125,10 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { lowerSymbolDifference(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional PCRelativeOffset) const; + const MCExpr *lowerRelativeReference(const GlobalValue *LHS, + const GlobalValue *RHS, int64_t Addend, + std::optional PCRelativeOffset, + const TargetMachine &TM) const override; const MCExpr *lowerDSOLocalEquivalent(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index c9415292e88f7..4c20c5dc74d9a 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1233,6 +1233,24 @@ const MCExpr *TargetLoweringObjectFileELF::lowerSymbolDifference( return Res; } +const MCExpr *TargetLoweringObjectFileELF::lowerRelativeReference( +const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend, +std::optional PCRelativeOffset, const TargetMachine &TM) const { + // We may only use a PLT-relative relocation to refer to unnamed_addr + // functions. + if (!LHS->hasGlobalUnnamedAddr() || !LHS->getValueType()->isFunctionTy()) +return nullptr; + + // Basic correctness checks. + if (LHS->getType()->getPointerAddressSpace() != 0 || + RHS->getType()->getPointerAddressSpace() != 0 || LHS->isThreadLocal() || + RHS->isThreadLocal()) +return nullptr; + + return lowerSymbolDifference(TM.getSymbol(LHS), TM.getSymbol(RHS), Addend, + PCRelativeOffset); +} + // Reference the PLT entry of a function, optionally with a subtrahend (`RHS`). const MCExpr *TargetLoweringObjectFileELF::lowerDSOLocalEquivalent( const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, diff --git a/llvm/test/CodeGen/ARM/relative-reloc.ll b/llvm/test/CodeGen/ARM/plt-relative-reloc.ll similarity index 78% rename from llvm/test/CodeGen/ARM/relative-reloc.ll rename to llvm/test/CodeGen/ARM/plt-relative-reloc.ll index 65053726e66bf..ede891900e6d0 100644 --- a/llvm/test/CodeGen/ARM/relative-reloc.ll +++ b/llvm/test/CodeGen/ARM/plt-relative-reloc.ll @@ -10,8 +10,7 @@ declare void @fn1() unnamed_addr declare void @fn2() unnamed_addr declare void @fn3() -;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible. ; CHECK: .long 0 -; CHECK-NEXT: .long fn1-vtable-4 -; CHECK-NEXT: .long fn2-vtable-4 +; CHECK-NEXT: .long fn1(prel31)-vtable-4 +; CHECK-NEXT: .long fn2(prel31)-vtable-4 ; CHECK-NEXT: .long fn3-vtable-4 diff --git a/llvm/test/CodeGen/RISCV/relative-reloc.ll b/llvm/test/CodeGen/RISCV/plt-relative-reloc.ll similarity index 84% rename from llvm/test/CodeGen/RISCV/relative-reloc.ll rename to llvm/test/CodeGen/RISCV/plt-relative-reloc.ll index 6c94b9fce9308..d2dceb773b2e9 100644 --- a/llvm/test/CodeGen/RISCV/relative-reloc.ll +++ b/llvm/test/CodeGen/RISCV/plt-relative-reloc.ll @@ -12,11 +12,10 @@ declare void @fn2() unnamed_addr declare void @fn3() @global4 = external unnamed_addr global i8 -;; Create a PC-relative relocation that the linker might decline if the addend symbol is preemptible. ; CHECK: vtable: ; CHECK-NEXT: .word 0 # 0x0 -; CHECK-NEXT: .word fn1-vtable-4 -; CHECK-NEXT: .word fn2-vtable-4 +; CHECK-NEXT:
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t { SK_PPA1 = 2, SK_PPA2 = 4, }; + +// The standard System/390 convention is to name the high-order (leftmost) bit +// in a byte as bit zero. The Flags type helps to set bits in byte according +// to this numeration order. +class Flags { + uint8_t Val; + + constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t Value, +uint8_t OldValue) { +uint8_t Pos = 8 - BitIndex - Length; +uint8_t Mask = ((1 << Length) - 1) << Pos; +Value = Value << Pos; +return (OldValue & ~Mask) | Value; + } + +public: + constexpr Flags() : Val(0) {} + constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value) + : Val(bits(BitIndex, Length, Value, 0)) {} + + template + constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) { +Val = bits(BitIndex, Length, static_cast(NewValue), Val); + } + + template + constexpr T get(uint8_t BitIndex, uint8_t Length) const { +return static_cast((Val >> (8 - BitIndex - Length)) & + ((1 << Length) - 1)); + } + + constexpr operator uint8_t() const { return Val; } +}; + +// Structure for the flag field of a symbol. See +// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record, MaskRay wrote: add a space before the `,`? Otherwise the link doesn't work https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -0,0 +1,73 @@ +; RUN: llc <%s --mtriple s390x-ibm-zos --filetype=obj -o - | \ +; RUN: od -Ax -tx1 -v | FileCheck --ignore-case %s +; REQUIRES: systemz-registered-target MaskRay wrote: unneeded thanks to ``` % cat llvm/test/MC/SystemZ/lit.local.cfg if not "SystemZ" in config.root.targets: config.unsupported = True ``` https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t { SK_PPA1 = 2, SK_PPA2 = 4, }; + +// The standard System/390 convention is to name the high-order (leftmost) bit +// in a byte as bit zero. The Flags type helps to set bits in byte according +// to this numeration order. +class Flags { + uint8_t Val; + + constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t Value, +uint8_t OldValue) { +uint8_t Pos = 8 - BitIndex - Length; +uint8_t Mask = ((1 << Length) - 1) << Pos; +Value = Value << Pos; +return (OldValue & ~Mask) | Value; + } + +public: + constexpr Flags() : Val(0) {} + constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value) + : Val(bits(BitIndex, Length, Value, 0)) {} + + template + constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) { +Val = bits(BitIndex, Length, static_cast(NewValue), Val); + } + + template + constexpr T get(uint8_t BitIndex, uint8_t Length) const { +return static_cast((Val >> (8 - BitIndex - Length)) & + ((1 << Length) - 1)); + } + + constexpr operator uint8_t() const { return Val; } +}; + +// Structure for the flag field of a symbol. See +// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record, +// offset 41, for the definition. +struct SymbolFlags { + Flags SymFlags; + +#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) \ + void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); } \ + TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); } + + GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1) + GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1) + GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1) + GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1) + GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3) + +#undef GOFF_SYMBOL_FLAG + +constexpr operator uint8_t() const { return static_cast(SymFlags); } MaskRay wrote: not indented correctly https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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-tools-extra] [clang] support pack expansions for trailing requires clauses (PR #133190)
@@ -78,6 +78,22 @@ class UnresolvedSetImpl; class VarTemplateDecl; enum class ImplicitParamKind; +// Holds a constraint expression along with a pack expansion index, if +// expanded. +struct AssociatedConstraint { + const Expr *ConstraintExpr = nullptr; + int ArgumentPackSubstitutionIndex = -1; mizvekov wrote: I'd prefer consistency here, as right now it's easy to grep for `ArgumentPackSubstitutionIndex`, expect it to be int, and expect -1 to mean no expansion. https://github.com/llvm/llvm-project/pull/133190 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -0,0 +1,148 @@ +//===- MCGOFFSymbolMapper.h - Maps MC section/symbol to GOFF symbols --===// +// +// 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 +// +//===--===// +// +// Maps a section or a symbol to the GOFF symbols it is composed of, and their +// attributes. +// +//===--===// + +#ifndef LLVM_MC_MCGOFFSYMBOLMAPPER_H +#define LLVM_MC_MCGOFFSYMBOLMAPPER_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/GOFF.h" +#include "llvm/Support/Alignment.h" +#include +#include + +namespace llvm { +class MCAssembler; +class MCContext; +class MCSectionGOFF; + +// An "External Symbol Definition" in the GOFF file has a type, and depending on +// the type a different subset of the fields is used. +// +// Unlike other formats, a 2 dimensional structure is used to define the +// location of data. For example, the equivalent of the ELF .text section is +// made up of a Section Definition (SD) and a class (Element Definition; ED). +// The name of the SD symbol depends on the application, while the class has the +// predefined name C_CODE64. +// +// Data can be placed into this structure in 2 ways. First, the data (in a text +// record) can be associated with an ED symbol. To refer to data, a Label +// Definition (LD) is used to give an offset into the data a name. When binding, +// the whole data is pulled into the resulting executable, and the addresses +// given by the LD symbols are resolved. +// +// The alternative is to use a Part Defiition (PR). In this case, the data (in a +// text record) is associated with the part. When binding, only the data of +// referenced PRs is pulled into the resulting binary. +// +// Both approaches are used, which means that the equivalent of a section in ELF +// results in 3 GOFF symbol, either SD/ED/LD or SD/ED/PR. Moreover, certain Everybody0523 wrote: ```suggestion // results in 3 GOFF symbols, either SD/ED/LD or SD/ED/PR. Moreover, certain ``` https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() { } namespace { +// A GOFFSymbol holds all the data required for writing an ESD record. +class GOFFSymbol { +public: + std::string Name; + uint32_t EsdId; + uint32_t ParentEsdId; + uint64_t Offset = 0; // Offset of the symbol into the section. LD only. + // Offset is only 32 bit, the larger type is used to + // enable error checking. + GOFF::ESDSymbolType SymbolType; + GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder; + + GOFF::BehavioralAttributes BehavAttrs; + GOFF::SymbolFlags SymbolFlags; + uint32_t SortKey = 0; + uint32_t SectionLength = 0; + uint32_t ADAEsdId = 0; + uint32_t EASectionEDEsdId = 0; + uint32_t EASectionOffset = 0; + uint8_t FillByteValue = 0; + + GOFFSymbol() : EsdId(0), ParentEsdId(0) {} + + GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0), +SymbolType(GOFF::ESD_ST_SectionDefinition) { +BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const EDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_ElementDefinition) { +this->NameSpace = Attr.NameSpace; +// TODO Do we need/should set the "mangled" flag? +SymbolFlags.setFillBytePresence(1); +SymbolFlags.setReservedQwords(Attr.ReservedQwords); +BehavAttrs.setReadOnly(Attr.IsReadOnly); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setRmode(Attr.Rmode); +BehavAttrs.setTextStyle(Attr.TextStyle); +BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm); +BehavAttrs.setLoadingBehavior(Attr.LoadBehavior); +BehavAttrs.setAlignment(Attr.Alignment); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const LDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_LabelDefinition) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setBindingStrength(Attr.BindingStrength); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const PRAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_PartReference) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAlignment(Attr.Alignment); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setBindingScope(Attr.BindingScope); +BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity); +BehavAttrs.setReadOnly(Attr.IsReadOnly); + } +}; + class GOFFWriter { GOFFOstream OS; [[maybe_unused]] MCAssembler &Asm; + /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes. + GOFFSymbolMapper SymbolMapper; + + /// Counter for symbol id's. + uint32_t EsdIdCounter = 0; + + /// Id's of some special symbols. + uint32_t RootSDEsdId = 0; + uint32_t ADAEsdId = 0; + void writeHeader(); + void writeSymbol(const GOFFSymbol &Symbol); void writeEnd(); + GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr); + GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr, + uint32_t ParentEsdId); + + void defineRootSymbol(const MCSectionGOFF *Text); + void defineSectionSymbols(const MCSectionGOFF &Section); + void defineSymbols(); + public: GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm); uint64_t writeObject(); }; } // namespace GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm) -: OS(OS), Asm(Asm) {} +: OS(OS), Asm(Asm), SymbolMapper(Asm) {} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) { + return GOFFSymbol(Name, ++EsdIdCounter, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr, +uint32_t ParentEsdId) { + return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr, +uint32_t Par
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() { } namespace { +// A GOFFSymbol holds all the data required for writing an ESD record. +class GOFFSymbol { +public: + std::string Name; + uint32_t EsdId; + uint32_t ParentEsdId; + uint64_t Offset = 0; // Offset of the symbol into the section. LD only. + // Offset is only 32 bit, the larger type is used to + // enable error checking. + GOFF::ESDSymbolType SymbolType; + GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder; + + GOFF::BehavioralAttributes BehavAttrs; + GOFF::SymbolFlags SymbolFlags; + uint32_t SortKey = 0; + uint32_t SectionLength = 0; + uint32_t ADAEsdId = 0; + uint32_t EASectionEDEsdId = 0; + uint32_t EASectionOffset = 0; + uint8_t FillByteValue = 0; + + GOFFSymbol() : EsdId(0), ParentEsdId(0) {} + + GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0), +SymbolType(GOFF::ESD_ST_SectionDefinition) { +BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const EDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_ElementDefinition) { +this->NameSpace = Attr.NameSpace; +// TODO Do we need/should set the "mangled" flag? +SymbolFlags.setFillBytePresence(1); +SymbolFlags.setReservedQwords(Attr.ReservedQwords); +BehavAttrs.setReadOnly(Attr.IsReadOnly); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setRmode(Attr.Rmode); +BehavAttrs.setTextStyle(Attr.TextStyle); +BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm); +BehavAttrs.setLoadingBehavior(Attr.LoadBehavior); +BehavAttrs.setAlignment(Attr.Alignment); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const LDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_LabelDefinition) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setBindingStrength(Attr.BindingStrength); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const PRAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_PartReference) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAlignment(Attr.Alignment); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setBindingScope(Attr.BindingScope); +BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity); +BehavAttrs.setReadOnly(Attr.IsReadOnly); + } +}; + class GOFFWriter { GOFFOstream OS; [[maybe_unused]] MCAssembler &Asm; + /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes. + GOFFSymbolMapper SymbolMapper; + + /// Counter for symbol id's. + uint32_t EsdIdCounter = 0; + + /// Id's of some special symbols. + uint32_t RootSDEsdId = 0; + uint32_t ADAEsdId = 0; + void writeHeader(); + void writeSymbol(const GOFFSymbol &Symbol); void writeEnd(); + GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr); + GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr, + uint32_t ParentEsdId); + + void defineRootSymbol(const MCSectionGOFF *Text); + void defineSectionSymbols(const MCSectionGOFF &Section); + void defineSymbols(); + public: GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm); uint64_t writeObject(); }; } // namespace GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm) -: OS(OS), Asm(Asm) {} +: OS(OS), Asm(Asm), SymbolMapper(Asm) {} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) { + return GOFFSymbol(Name, ++EsdIdCounter, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr, +uint32_t ParentEsdId) { + return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr, +uint32_t Par
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
@@ -0,0 +1,148 @@ +//===- MCGOFFSymbolMapper.h - Maps MC section/symbol to GOFF symbols --===// +// +// 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 +// +//===--===// +// +// Maps a section or a symbol to the GOFF symbols it is composed of, and their +// attributes. +// +//===--===// + +#ifndef LLVM_MC_MCGOFFSYMBOLMAPPER_H +#define LLVM_MC_MCGOFFSYMBOLMAPPER_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/GOFF.h" +#include "llvm/Support/Alignment.h" +#include +#include + +namespace llvm { +class MCAssembler; +class MCContext; +class MCSectionGOFF; + +// An "External Symbol Definition" in the GOFF file has a type, and depending on +// the type a different subset of the fields is used. +// +// Unlike other formats, a 2 dimensional structure is used to define the +// location of data. For example, the equivalent of the ELF .text section is +// made up of a Section Definition (SD) and a class (Element Definition; ED). +// The name of the SD symbol depends on the application, while the class has the +// predefined name C_CODE64. +// +// Data can be placed into this structure in 2 ways. First, the data (in a text +// record) can be associated with an ED symbol. To refer to data, a Label +// Definition (LD) is used to give an offset into the data a name. When binding, +// the whole data is pulled into the resulting executable, and the addresses +// given by the LD symbols are resolved. +// +// The alternative is to use a Part Defiition (PR). In this case, the data (in a Everybody0523 wrote: ```suggestion // The alternative is to use a Part Definition (PR). In this case, the data (in a ``` https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -0,0 +1,148 @@ +//===- MCGOFFSymbolMapper.h - Maps MC section/symbol to GOFF symbols --===// +// +// 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 +// +//===--===// +// +// Maps a section or a symbol to the GOFF symbols it is composed of, and their +// attributes. +// +//===--===// + +#ifndef LLVM_MC_MCGOFFSYMBOLMAPPER_H +#define LLVM_MC_MCGOFFSYMBOLMAPPER_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/GOFF.h" +#include "llvm/Support/Alignment.h" +#include +#include + +namespace llvm { +class MCAssembler; +class MCContext; +class MCSectionGOFF; + +// An "External Symbol Definition" in the GOFF file has a type, and depending on +// the type a different subset of the fields is used. +// +// Unlike other formats, a 2 dimensional structure is used to define the +// location of data. For example, the equivalent of the ELF .text section is +// made up of a Section Definition (SD) and a class (Element Definition; ED). +// The name of the SD symbol depends on the application, while the class has the +// predefined name C_CODE64. Everybody0523 wrote: ```suggestion // predefined name C_CODE/C_CODE64 in ILP32 and LP64 respectively. ``` https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -223,21 +196,222 @@ void GOFFOstream::finalizeRecord() { } namespace { +// A GOFFSymbol holds all the data required for writing an ESD record. +class GOFFSymbol { +public: + std::string Name; + uint32_t EsdId; + uint32_t ParentEsdId; + uint64_t Offset = 0; // Offset of the symbol into the section. LD only. + // Offset is only 32 bit, the larger type is used to + // enable error checking. + GOFF::ESDSymbolType SymbolType; + GOFF::ESDNameSpaceId NameSpace = GOFF::ESD_NS_ProgramManagementBinder; + + GOFF::BehavioralAttributes BehavAttrs; + GOFF::SymbolFlags SymbolFlags; + uint32_t SortKey = 0; + uint32_t SectionLength = 0; + uint32_t ADAEsdId = 0; + uint32_t EASectionEDEsdId = 0; + uint32_t EASectionOffset = 0; + uint8_t FillByteValue = 0; + + GOFFSymbol() : EsdId(0), ParentEsdId(0) {} + + GOFFSymbol(StringRef Name, uint32_t EsdID, const SDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(0), +SymbolType(GOFF::ESD_ST_SectionDefinition) { +BehavAttrs.setTaskingBehavior(Attr.TaskingBehavior); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const EDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_ElementDefinition) { +this->NameSpace = Attr.NameSpace; +// TODO Do we need/should set the "mangled" flag? +SymbolFlags.setFillBytePresence(1); +SymbolFlags.setReservedQwords(Attr.ReservedQwords); +BehavAttrs.setReadOnly(Attr.IsReadOnly); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setRmode(Attr.Rmode); +BehavAttrs.setTextStyle(Attr.TextStyle); +BehavAttrs.setBindingAlgorithm(Attr.BindAlgorithm); +BehavAttrs.setLoadingBehavior(Attr.LoadBehavior); +BehavAttrs.setAlignment(Attr.Alignment); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const LDAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_LabelDefinition) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setBindingStrength(Attr.BindingStrength); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setBindingScope(Attr.BindingScope); + } + + GOFFSymbol(StringRef Name, uint32_t EsdID, uint32_t ParentEsdID, + const PRAttr &Attr) + : Name(Name.data(), Name.size()), EsdId(EsdID), ParentEsdId(ParentEsdID), +SymbolType(GOFF::ESD_ST_PartReference) { +this->NameSpace = Attr.NameSpace; +SymbolFlags.setRenameable(Attr.IsRenamable); +BehavAttrs.setExecutable(Attr.Executable); +BehavAttrs.setAlignment(Attr.Alignment); +BehavAttrs.setAmode(Attr.Amode); +BehavAttrs.setLinkageType(Attr.Linkage); +BehavAttrs.setBindingScope(Attr.BindingScope); +BehavAttrs.setDuplicateSymbolSeverity(Attr.DuplicateSymbolSeverity); +BehavAttrs.setReadOnly(Attr.IsReadOnly); + } +}; + class GOFFWriter { GOFFOstream OS; [[maybe_unused]] MCAssembler &Asm; + /// Mapping from MCSectionGOFF/MCSymbolGOFF to GOFF symbols and attributes. + GOFFSymbolMapper SymbolMapper; + + /// Counter for symbol id's. + uint32_t EsdIdCounter = 0; + + /// Id's of some special symbols. + uint32_t RootSDEsdId = 0; + uint32_t ADAEsdId = 0; + void writeHeader(); + void writeSymbol(const GOFFSymbol &Symbol); void writeEnd(); + GOFFSymbol createGOFFSymbol(StringRef Name, const SDAttr &Attr); + GOFFSymbol createGOFFSymbol(StringRef Name, const EDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const LDAttr &Attr, + uint32_t ParentEsdId); + GOFFSymbol createGOFFSymbol(StringRef Name, const PRAttr &Attr, + uint32_t ParentEsdId); + + void defineRootSymbol(const MCSectionGOFF *Text); + void defineSectionSymbols(const MCSectionGOFF &Section); + void defineSymbols(); + public: GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm); uint64_t writeObject(); }; } // namespace GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm) -: OS(OS), Asm(Asm) {} +: OS(OS), Asm(Asm), SymbolMapper(Asm) {} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const SDAttr &Attr) { + return GOFFSymbol(Name, ++EsdIdCounter, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const EDAttr &Attr, +uint32_t ParentEsdId) { + return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr); +} + +GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const LDAttr &Attr, +uint32_t Par
[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)
https://github.com/Everybody0523 edited https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (PR #133027)
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/133027 >From f07f96873aa8ffd848240e4add1d4c382f5aac29 Mon Sep 17 00:00:00 2001 From: ZhaoQi Date: Fri, 21 Mar 2025 16:05:45 +0800 Subject: [PATCH] Backport/20.x: [LoongArch] Fix the type of tls-le symbols (cherry picked from commit d6dc74e19f5cdb6995b13329480e330aff113f96) --- .../lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp | 1 + llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll| 8 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp index 30d2d0c1184ad..5698468c4754e 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp @@ -275,6 +275,7 @@ void LoongArchMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const { case VK_LoongArch_TLS_GD_HI20: case VK_LoongArch_TLS_DESC_PC_HI20: case VK_LoongArch_TLS_DESC_HI20: + case VK_LoongArch_TLS_LE_HI20_R: case VK_LoongArch_TLS_LD_PCREL20_S2: case VK_LoongArch_TLS_GD_PCREL20_S2: case VK_LoongArch_TLS_DESC_PCREL20_S2: diff --git a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll index fe5f2195f0dc7..d39454a51a445 100644 --- a/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll +++ b/llvm/test/CodeGen/LoongArch/fix-tle-le-sym-type.ll @@ -5,12 +5,12 @@ ; RUN: llvm-readelf -s %t-la64 | FileCheck %s --check-prefix=LA64 ; LA32: Symbol table '.symtab' contains [[#]] entries: -; LA32-NEXT:Num:Value Size TypeBind Vis Ndx Name -; LA32: 0 NOTYPE GLOBAL DEFAULT UND tls_sym +; LA32-NEXT:Num:Value Size Type Bind Vis Ndx Name +; LA32: 0 TLS GLOBAL DEFAULT UND tls_sym ; LA64: Symbol table '.symtab' contains [[#]] entries: -; LA64-NEXT:Num:Value Size TypeBind Vis Ndx Name -; LA64: 0 NOTYPE GLOBAL DEFAULT UND tls_sym +; LA64-NEXT:Num:Value Size Type Bind Vis Ndx Name +; LA64: 0 TLS GLOBAL DEFAULT UND tls_sym @tls_sym = external thread_local(localexec) global i32 ___ llvm-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] release/20.x: Define LLVM_ABI and CLANG_ABI for __EMSCRIPTEN__ builds (#131578) (PR #133996)
github-actions[bot] wrote: @tstellar (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. https://github.com/llvm/llvm-project/pull/133996 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/134035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Reduce with early return of arguments (PR #133627)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133627 >From 449b087c4f0c3eb6df524f66bc82d396c0a1e6a2 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 24 Mar 2025 14:33:36 +0700 Subject: [PATCH] llvm-reduce: Reduce with early return of arguments Extend the instruction -> return reduction with one that inserts return of function arguments. Not sure how useful this really is. This has more freedom since we could insert the return anywhere in the function, but this just inserts the return in the entry block. --- .../reduce-values-to-return-args.ll | 77 +++ ...-values-to-return-nonvoid-noncallee-use.ll | 2 +- .../llvm-reduce/reduce-values-to-return.ll| 2 +- llvm/tools/llvm-reduce/DeltaPasses.def| 5 +- .../deltas/ReduceValuesToReturn.cpp | 42 +- .../llvm-reduce/deltas/ReduceValuesToReturn.h | 3 +- 6 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll new file mode 100644 index 0..abbc643822033 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll @@ -0,0 +1,77 @@ +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments-to-return --test FileCheck --test-arg --check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=RESULT %s < %t + + +; INTERESTING-LABEL: @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return( +; RESULT-NEXT: ret i32 %arg +; RESULT-NEXT: } +define void @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) { + store i32 %arg, ptr %ptr + ret void +} + +; INTERESTING-LABEL: @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr %ptr) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return_existing_ret( +; RESULT-NEXT: ret i32 %arg +; RESULT-NEXT: } +define i32 @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr %ptr) { + store i32 %arg, ptr %ptr + ret i32 0 +} + +; INTERESTING-LABEL: @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_phi_block_use_argument_to_return( +; RESULT-NEXT: entry: +; RESULT-NEXT: ret i32 %arg +define void @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) { +entry: + br i1 %cond0, label %bb0, label %bb1 + +bb0: + %phi = phi i32 [ %arg, %entry ], [ 123, %bb1 ] + store i32 %arg, ptr %ptr0 + store i32 %phi, ptr %ptr1 + br label %bb1 + +bb1: + br i1 %cond1, label %bb0, label %bb2 + +bb2: + ret void +} + +; INTERESTING-LABEL: define {{.*}} @keep_second_arg(i32 %arg0, ptr %arg1) { +; INTERESTING: %arg1 + +; RESULT-LABEL: define ptr @keep_second_arg( +; RESULT-NEXT: ret ptr %arg1 +; RESULT-NEXT: } +define void @keep_second_arg(i32 %arg0, ptr %arg1) { + store i32 %arg0, ptr %arg1 + ret void +} + +; INTERESTING-LABEL: @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +; INTERESTING: i32 %arg2 + +; RESULT-LABEL: define i32 @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +; RESULT-NEXT: entry: +; RESULT-NEXT: ret i32 %arg2 +define void @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +entry: + br i1 %arg0, label %bb0, label %bb1 + +bb0: + store i32 %arg2, ptr %arg1 + ret void + +bb1: + ret void +} diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll index 215ea97a8be91..11166479318c6 100644 --- a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll @@ -1,7 +1,7 @@ ; Make sure we don't break on non-callee uses of funtions with a ; non-void return type. -; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=values-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=instructions-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t ; RUN: FileCheck --check-prefix=RESULT %s < %t ; INTERESTING-LABEL: @interesting( diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll index 0c36db8ebc278..2af87aad05169 100644 --- a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can move intermediate values by inserting ; ear
[llvm-branch-commits] [llvm] llvm-reduce: Reduce with early return of arguments (PR #133627)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133627 >From 449b087c4f0c3eb6df524f66bc82d396c0a1e6a2 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 24 Mar 2025 14:33:36 +0700 Subject: [PATCH] llvm-reduce: Reduce with early return of arguments Extend the instruction -> return reduction with one that inserts return of function arguments. Not sure how useful this really is. This has more freedom since we could insert the return anywhere in the function, but this just inserts the return in the entry block. --- .../reduce-values-to-return-args.ll | 77 +++ ...-values-to-return-nonvoid-noncallee-use.ll | 2 +- .../llvm-reduce/reduce-values-to-return.ll| 2 +- llvm/tools/llvm-reduce/DeltaPasses.def| 5 +- .../deltas/ReduceValuesToReturn.cpp | 42 +- .../llvm-reduce/deltas/ReduceValuesToReturn.h | 3 +- 6 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll new file mode 100644 index 0..abbc643822033 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll @@ -0,0 +1,77 @@ +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=arguments-to-return --test FileCheck --test-arg --check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t +; RUN: FileCheck --check-prefixes=RESULT %s < %t + + +; INTERESTING-LABEL: @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return( +; RESULT-NEXT: ret i32 %arg +; RESULT-NEXT: } +define void @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) { + store i32 %arg, ptr %ptr + ret void +} + +; INTERESTING-LABEL: @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr %ptr) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return_existing_ret( +; RESULT-NEXT: ret i32 %arg +; RESULT-NEXT: } +define i32 @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr %ptr) { + store i32 %arg, ptr %ptr + ret i32 0 +} + +; INTERESTING-LABEL: @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) { +; INTERESTING: %arg + +; RESULT-LABEL: define i32 @move_phi_block_use_argument_to_return( +; RESULT-NEXT: entry: +; RESULT-NEXT: ret i32 %arg +define void @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) { +entry: + br i1 %cond0, label %bb0, label %bb1 + +bb0: + %phi = phi i32 [ %arg, %entry ], [ 123, %bb1 ] + store i32 %arg, ptr %ptr0 + store i32 %phi, ptr %ptr1 + br label %bb1 + +bb1: + br i1 %cond1, label %bb0, label %bb2 + +bb2: + ret void +} + +; INTERESTING-LABEL: define {{.*}} @keep_second_arg(i32 %arg0, ptr %arg1) { +; INTERESTING: %arg1 + +; RESULT-LABEL: define ptr @keep_second_arg( +; RESULT-NEXT: ret ptr %arg1 +; RESULT-NEXT: } +define void @keep_second_arg(i32 %arg0, ptr %arg1) { + store i32 %arg0, ptr %arg1 + ret void +} + +; INTERESTING-LABEL: @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +; INTERESTING: i32 %arg2 + +; RESULT-LABEL: define i32 @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +; RESULT-NEXT: entry: +; RESULT-NEXT: ret i32 %arg2 +define void @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) { +entry: + br i1 %arg0, label %bb0, label %bb1 + +bb0: + store i32 %arg2, ptr %arg1 + ret void + +bb1: + ret void +} diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll index 215ea97a8be91..11166479318c6 100644 --- a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll @@ -1,7 +1,7 @@ ; Make sure we don't break on non-callee uses of funtions with a ; non-void return type. -; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=values-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t +; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=instructions-to-return --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t ; RUN: FileCheck --check-prefix=RESULT %s < %t ; INTERESTING-LABEL: @interesting( diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll index 0c36db8ebc278..2af87aad05169 100644 --- a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll +++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can move intermediate values by inserting ; ear
[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)
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/134035?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#134035** https://app.graphite.dev/github/pr/llvm/llvm-project/134035?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134035?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#133627** https://app.graphite.dev/github/pr/llvm/llvm-project/133627?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#132686** https://app.graphite.dev/github/pr/llvm/llvm-project/132686?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/134035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)
arsenm wrote: Forgot the part to fix the multiple return case https://github.com/llvm/llvm-project/pull/134035 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] llvm-reduce: Do not reduce alloca array sizes to 0 (PR #132864)
arsenm wrote: ### Merge activity * **Apr 2, 2:34 AM EDT**: A user started a stack merge that includes this pull request via [Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/132864). https://github.com/llvm/llvm-project/pull/132864 ___ llvm-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] [GOFF] Add writing of section symbols (PR #133799)
@@ -169,6 +169,91 @@ enum SubsectionKind : uint8_t { SK_PPA1 = 2, SK_PPA2 = 4, }; + +// The standard System/390 convention is to name the high-order (leftmost) bit +// in a byte as bit zero. The Flags type helps to set bits in byte according +// to this numeration order. +class Flags { + uint8_t Val; + + constexpr static uint8_t bits(uint8_t BitIndex, uint8_t Length, uint8_t Value, +uint8_t OldValue) { +uint8_t Pos = 8 - BitIndex - Length; +uint8_t Mask = ((1 << Length) - 1) << Pos; +Value = Value << Pos; +return (OldValue & ~Mask) | Value; + } + +public: + constexpr Flags() : Val(0) {} + constexpr Flags(uint8_t BitIndex, uint8_t Length, uint8_t Value) + : Val(bits(BitIndex, Length, Value, 0)) {} + + template + constexpr void set(uint8_t BitIndex, uint8_t Length, T NewValue) { +Val = bits(BitIndex, Length, static_cast(NewValue), Val); + } + + template + constexpr T get(uint8_t BitIndex, uint8_t Length) const { +return static_cast((Val >> (8 - BitIndex - Length)) & + ((1 << Length) - 1)); + } + + constexpr operator uint8_t() const { return Val; } +}; + +// Structure for the flag field of a symbol. See +// https://www.ibm.com/docs/en/zos/3.1.0?topic=formats-external-symbol-definition-record, +// offset 41, for the definition. +struct SymbolFlags { + Flags SymFlags; + +#define GOFF_SYMBOL_FLAG(NAME, TYPE, BITINDEX, LENGTH) \ + void set##NAME(TYPE Val) { SymFlags.set(BITINDEX, LENGTH, Val); } \ + TYPE get##NAME() const { return SymFlags.get(BITINDEX, LENGTH); } + + GOFF_SYMBOL_FLAG(FillBytePresence, bool, 0, 1) + GOFF_SYMBOL_FLAG(Mangled, bool, 1, 1) + GOFF_SYMBOL_FLAG(Renameable, bool, 2, 1) + GOFF_SYMBOL_FLAG(RemovableClass, bool, 3, 1) + GOFF_SYMBOL_FLAG(ReservedQwords, ESDReserveQwords, 5, 3) Everybody0523 wrote: I feel like I once knew the answer to this question but I have since forgotten... What's up with this field? The documentation linked a few lines above say that field is reserved - does the documentation need an update, or can this be removed? https://github.com/llvm/llvm-project/pull/133799 ___ llvm-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] fd6b530 - Merge branch 'main' into revert-133880-revert-130577-narrow-math-for-and-operand
Author: Shoreshen Date: 2025-04-01T18:26:45+08:00 New Revision: fd6b5306b6dd21cef8290eb623aeb42e735c6f06 URL: https://github.com/llvm/llvm-project/commit/fd6b5306b6dd21cef8290eb623aeb42e735c6f06 DIFF: https://github.com/llvm/llvm-project/commit/fd6b5306b6dd21cef8290eb623aeb42e735c6f06.diff LOG: Merge branch 'main' into revert-133880-revert-130577-narrow-math-for-and-operand Added: llvm/include/llvm/CodeGen/XRayInstrumentation.h llvm/test/CodeGen/AArch64/early-ifcvt-on-double-killed-reg.mir llvm/test/CodeGen/Hexagon/early-if-predicator-reg-killed-everywhere.mir Modified: llvm/include/llvm/InitializePasses.h llvm/include/llvm/Passes/CodeGenPassBuilder.h llvm/include/llvm/Passes/MachinePassRegistry.def llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/EarlyIfConversion.cpp llvm/lib/CodeGen/XRayInstrumentation.cpp llvm/lib/Passes/PassBuilder.cpp llvm/test/CodeGen/X86/xray-empty-firstmbb.mir llvm/test/CodeGen/X86/xray-multiplerets-in-blocks.mir Removed: diff --git a/llvm/include/llvm/CodeGen/XRayInstrumentation.h b/llvm/include/llvm/CodeGen/XRayInstrumentation.h new file mode 100644 index 0..cc65d61627fc0 --- /dev/null +++ b/llvm/include/llvm/CodeGen/XRayInstrumentation.h @@ -0,0 +1,25 @@ +//===- llvm/CodeGen/XRayInstrumentation.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CODEGEN_XRAYINSTRUMENTATION_H +#define LLVM_CODEGEN_XRAYINSTRUMENTATION_H + +#include "llvm/CodeGen/MachinePassManager.h" + +namespace llvm { + +class XRayInstrumentationPass : public PassInfoMixin { +public: + PreservedAnalyses run(MachineFunction &MF, +MachineFunctionAnalysisManager &MFAM); + static bool isRequired() { return true; } +}; + +} // namespace llvm + +#endif // LLVM_CODEGEN_XRAYINSTRUMENTATION_H diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index cc7bf245c37f5..fb27867176788 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -322,7 +322,7 @@ void initializeVirtRegRewriterPass(PassRegistry &); void initializeWasmEHPreparePass(PassRegistry &); void initializeWinEHPreparePass(PassRegistry &); void initializeWriteBitcodePassPass(PassRegistry &); -void initializeXRayInstrumentationPass(PassRegistry &); +void initializeXRayInstrumentationLegacyPass(PassRegistry &); } // end namespace llvm diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index bdb81cf77cfd1..25ca982916ff8 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -90,6 +90,7 @@ #include "llvm/CodeGen/UnreachableBlockElim.h" #include "llvm/CodeGen/WasmEHPrepare.h" #include "llvm/CodeGen/WinEHPrepare.h" +#include "llvm/CodeGen/XRayInstrumentation.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/IRPrinter/IRPrintingPasses.h" diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index 73c4d34faa5a3..3e9e788662900 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -190,6 +190,7 @@ MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass()) MACHINE_FUNCTION_PASS("two-address-instruction", TwoAddressInstructionPass()) MACHINE_FUNCTION_PASS("verify", MachineVerifierPass()) MACHINE_FUNCTION_PASS("verify", MachineTraceMetricsVerifierPass()) +MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass()) #undef MACHINE_FUNCTION_PASS #ifndef MACHINE_FUNCTION_PASS_WITH_PARAMS @@ -315,5 +316,4 @@ DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass) DUMMY_MACHINE_FUNCTION_PASS("stackmap-liveness", StackMapLivenessPass) DUMMY_MACHINE_FUNCTION_PASS("unpack-mi-bundles", UnpackMachineBundlesPass) DUMMY_MACHINE_FUNCTION_PASS("virtregrewriter", VirtRegRewriterPass) -DUMMY_MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass) #undef DUMMY_MACHINE_FUNCTION_PASS diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 771e45ce71595..b1c26307b80fc 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -145,5 +145,5 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeVirtRegRewriterPass(Registry); initializeWasmEHPreparePass(Registry); initializeWinEHPreparePass(Registry); - initializeXRayInstrumentationPass(Registry); + initializeXRayInstrumentationLegacyPass(Registry); } dif
[llvm-branch-commits] [llvm] 4a68702 - [CodeGen][NPM] Port XRayInstrumentation to NPM (#129865)
Author: Akshat Oke Date: 2025-04-01T15:38:49+05:30 New Revision: 4a687024559d5ef10abe6ed10555c5f5c2cfcb40 URL: https://github.com/llvm/llvm-project/commit/4a687024559d5ef10abe6ed10555c5f5c2cfcb40 DIFF: https://github.com/llvm/llvm-project/commit/4a687024559d5ef10abe6ed10555c5f5c2cfcb40.diff LOG: [CodeGen][NPM] Port XRayInstrumentation to NPM (#129865) Added: llvm/include/llvm/CodeGen/XRayInstrumentation.h Modified: llvm/include/llvm/InitializePasses.h llvm/include/llvm/Passes/CodeGenPassBuilder.h llvm/include/llvm/Passes/MachinePassRegistry.def llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/XRayInstrumentation.cpp llvm/lib/Passes/PassBuilder.cpp llvm/test/CodeGen/X86/xray-empty-firstmbb.mir llvm/test/CodeGen/X86/xray-multiplerets-in-blocks.mir Removed: diff --git a/llvm/include/llvm/CodeGen/XRayInstrumentation.h b/llvm/include/llvm/CodeGen/XRayInstrumentation.h new file mode 100644 index 0..cc65d61627fc0 --- /dev/null +++ b/llvm/include/llvm/CodeGen/XRayInstrumentation.h @@ -0,0 +1,25 @@ +//===- llvm/CodeGen/XRayInstrumentation.h ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CODEGEN_XRAYINSTRUMENTATION_H +#define LLVM_CODEGEN_XRAYINSTRUMENTATION_H + +#include "llvm/CodeGen/MachinePassManager.h" + +namespace llvm { + +class XRayInstrumentationPass : public PassInfoMixin { +public: + PreservedAnalyses run(MachineFunction &MF, +MachineFunctionAnalysisManager &MFAM); + static bool isRequired() { return true; } +}; + +} // namespace llvm + +#endif // LLVM_CODEGEN_XRAYINSTRUMENTATION_H diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index cc7bf245c37f5..fb27867176788 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -322,7 +322,7 @@ void initializeVirtRegRewriterPass(PassRegistry &); void initializeWasmEHPreparePass(PassRegistry &); void initializeWinEHPreparePass(PassRegistry &); void initializeWriteBitcodePassPass(PassRegistry &); -void initializeXRayInstrumentationPass(PassRegistry &); +void initializeXRayInstrumentationLegacyPass(PassRegistry &); } // end namespace llvm diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index bdb81cf77cfd1..25ca982916ff8 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -90,6 +90,7 @@ #include "llvm/CodeGen/UnreachableBlockElim.h" #include "llvm/CodeGen/WasmEHPrepare.h" #include "llvm/CodeGen/WinEHPrepare.h" +#include "llvm/CodeGen/XRayInstrumentation.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/IRPrinter/IRPrintingPasses.h" diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index 73c4d34faa5a3..3e9e788662900 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -190,6 +190,7 @@ MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass()) MACHINE_FUNCTION_PASS("two-address-instruction", TwoAddressInstructionPass()) MACHINE_FUNCTION_PASS("verify", MachineVerifierPass()) MACHINE_FUNCTION_PASS("verify", MachineTraceMetricsVerifierPass()) +MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass()) #undef MACHINE_FUNCTION_PASS #ifndef MACHINE_FUNCTION_PASS_WITH_PARAMS @@ -315,5 +316,4 @@ DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass) DUMMY_MACHINE_FUNCTION_PASS("stackmap-liveness", StackMapLivenessPass) DUMMY_MACHINE_FUNCTION_PASS("unpack-mi-bundles", UnpackMachineBundlesPass) DUMMY_MACHINE_FUNCTION_PASS("virtregrewriter", VirtRegRewriterPass) -DUMMY_MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass) #undef DUMMY_MACHINE_FUNCTION_PASS diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp index 771e45ce71595..b1c26307b80fc 100644 --- a/llvm/lib/CodeGen/CodeGen.cpp +++ b/llvm/lib/CodeGen/CodeGen.cpp @@ -145,5 +145,5 @@ void llvm::initializeCodeGen(PassRegistry &Registry) { initializeVirtRegRewriterPass(Registry); initializeWasmEHPreparePass(Registry); initializeWinEHPreparePass(Registry); - initializeXRayInstrumentationPass(Registry); + initializeXRayInstrumentationLegacyPass(Registry); } diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp index 0873d9956356e..dbdb81d1e6b33 100644 --- a/llvm/lib/CodeGen/XRayInstrumentation.cpp +++ b/llvm/lib/CodeGen/XR
[llvm-branch-commits] [llvm] llvm-reduce: Reduce global variable code model (PR #133865)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/133865 ___ llvm-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] d6d1dbf - [ARM] Speedups for CombineBaseUpdate. (#129725)
Author: David Green Date: 2025-03-31T12:43:12-07:00 New Revision: d6d1dbf221814b2a28cb234e72c7d81730ff26e7 URL: https://github.com/llvm/llvm-project/commit/d6d1dbf221814b2a28cb234e72c7d81730ff26e7 DIFF: https://github.com/llvm/llvm-project/commit/d6d1dbf221814b2a28cb234e72c7d81730ff26e7.diff LOG: [ARM] Speedups for CombineBaseUpdate. (#129725) This attempts to put limits onto CombineBaseUpdate for degenerate cases like #127477. The biggest change is to add a limit to the number of base updates to check in CombineBaseUpdate. 64 is hopefully plenty high enough for most runtime unrolled loops to generate postinc where they are beneficial. It also moves the check for isValidBaseUpdate later so that it only happens if we will generate a valid instruction. The 1024 limit to hasPredecessorHelper comes from the X86 backend, which uses the same limit. I haven't added a test case as it would need to be very big and my attempts at generating a smaller version did not show anything useful. Fixes #127477. (cherry picked from commit 86cf4ed7e9510a6828e95e8b36893eec116c9cf9) Added: Modified: llvm/lib/Target/ARM/ARMISelLowering.cpp Removed: diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index bd8d6079e1ba8..d20115c84ea89 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -149,6 +149,11 @@ MVEMaxSupportedInterleaveFactor("mve-max-interleave-factor", cl::Hidden, cl::desc("Maximum interleave factor for MVE VLDn to generate."), cl::init(2)); +cl::opt ArmMaxBaseUpdatesToCheck( +"arm-max-base-updates-to-check", cl::Hidden, +cl::desc("Maximum number of base-updates to check generating postindex."), +cl::init(64)); + /// Value type used for "flags" operands / results (either CPSR or FPSCR_NZCV). constexpr MVT FlagsVT = MVT::i32; @@ -15842,6 +15847,22 @@ struct BaseUpdateUser { unsigned ConstInc; }; +static bool isValidBaseUpdate(SDNode *N, SDNode *User) { + // Check that the add is independent of the load/store. + // Otherwise, folding it would create a cycle. Search through Addr + // as well, since the User may not be a direct user of Addr and + // only share a base pointer. + SmallPtrSet Visited; + SmallVector Worklist; + Worklist.push_back(N); + Worklist.push_back(User); + const unsigned MaxSteps = 1024; + if (SDNode::hasPredecessorHelper(N, Visited, Worklist, MaxSteps) || + SDNode::hasPredecessorHelper(User, Visited, Worklist, MaxSteps)) +return false; + return true; +} + static bool TryCombineBaseUpdate(struct BaseUpdateTarget &Target, struct BaseUpdateUser &User, bool SimpleConstIncOnly, @@ -16043,6 +16064,9 @@ static bool TryCombineBaseUpdate(struct BaseUpdateTarget &Target, if (SimpleConstIncOnly && User.ConstInc != NumBytes) return false; + if (!isValidBaseUpdate(N, User.N)) +return false; + // OK, we found an ADD we can fold into the base update. // Now, create a _UPD node, taking care of not breaking alignment. @@ -16191,21 +16215,6 @@ static bool findPointerConstIncrement(SDNode *N, SDValue *Ptr, SDValue *CInc) { } } -static bool isValidBaseUpdate(SDNode *N, SDNode *User) { - // Check that the add is independent of the load/store. - // Otherwise, folding it would create a cycle. Search through Addr - // as well, since the User may not be a direct user of Addr and - // only share a base pointer. - SmallPtrSet Visited; - SmallVector Worklist; - Worklist.push_back(N); - Worklist.push_back(User); - if (SDNode::hasPredecessorHelper(N, Visited, Worklist) || - SDNode::hasPredecessorHelper(User, Visited, Worklist)) -return false; - return true; -} - /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP, /// NEON load/store intrinsics, and generic vector load/stores, to merge /// base address updates. @@ -16219,6 +16228,10 @@ static SDValue CombineBaseUpdate(SDNode *N, const unsigned AddrOpIdx = ((isIntrinsic || isStore) ? 2 : 1); BaseUpdateTarget Target = {N, isIntrinsic, isStore, AddrOpIdx}; + // Limit the number of possible base-updates we look at to prevent degenerate + // cases. + unsigned MaxBaseUpdates = ArmMaxBaseUpdatesToCheck; + SDValue Addr = N->getOperand(AddrOpIdx); SmallVector BaseUpdates; @@ -16233,8 +16246,11 @@ static SDValue CombineBaseUpdate(SDNode *N, unsigned ConstInc = getPointerConstIncrement(User->getOpcode(), Addr, Inc, DCI.DAG); -if (ConstInc || User->getOpcode() == ISD::ADD) +if (ConstInc || User->getOpcode() == ISD::ADD) { BaseUpdates.push_back({User, Inc, ConstInc}); + if (BaseUpdates.size() >= MaxBaseUpdates) +break; +} } // If the address is a constant pointer increment itself, find @@ -16261,27 +16277,19 @@ static SDValue Co
[llvm-branch-commits] [clang] e740675 - [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (#132802)
Author: Paul Schwabauer Date: 2025-04-01T13:12:15-07:00 New Revision: e7406753caf313a41a6d3be154f3235ef1573644 URL: https://github.com/llvm/llvm-project/commit/e7406753caf313a41a6d3be154f3235ef1573644 DIFF: https://github.com/llvm/llvm-project/commit/e7406753caf313a41a6d3be154f3235ef1573644.diff LOG: [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (#132802) The File ID is incorrectly calculated, resulting in an out-of-bounds access. The test code is more complex because the File fetching only happens in specific scenarios. - Co-authored-by: ShaderKeeper Co-authored-by: Chuanqi Xu (cherry picked from commit cca0f8113e2f9a1bd662c62dd3ff7e1fa197e6b5) Added: clang/test/Modules/MixedModulePrecompile.cpp Modified: clang/lib/Serialization/ASTReader.cpp Removed: diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index f524251c48ddd..427b3c82c4737 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -9616,9 +9616,9 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const { return I == GlobalSubmoduleMap.end() ? nullptr : I->second; } else { // It's a prefix (preamble, PCH, ...). Look it up by index. -unsigned IndexFromEnd = ID >> 1; + int IndexFromEnd = static_cast(ID >> 1); assert(IndexFromEnd && "got reference to unknown module file"); -return getModuleManager().pch_modules().end()[-IndexFromEnd]; +return getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)]; } } @@ -9636,7 +9636,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) { auto PCHModules = getModuleManager().pch_modules(); auto I = llvm::find(PCHModules, M); assert(I != PCHModules.end() && "emitting reference to unknown file"); - return (I - PCHModules.end()) << 1; + return std::distance(I, PCHModules.end()) << 1; } std::optional ASTReader::getSourceDescriptor(unsigned ID) { diff --git a/clang/test/Modules/MixedModulePrecompile.cpp b/clang/test/Modules/MixedModulePrecompile.cpp new file mode 100644 index 0..473817ef71de6 --- /dev/null +++ b/clang/test/Modules/MixedModulePrecompile.cpp @@ -0,0 +1,63 @@ +// Tests mixed usage of precompiled headers and modules. +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \ +// RUN: -o %t/a.pch + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part1.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part2.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part3.pcm +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Part4.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface \ +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \ +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \ +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \ +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \ +// RUN: %t/Mod.cppm \ +// RUN: -include-pch %t/a.pch -o %t/Mod.pcm + +// RUN: %clang_cc1 -std=c++20 -emit-obj \ +// RUN: -main-file-name Mod.cppm \ +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \ +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \ +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \ +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \ +// RUN: -x pcm %t/Mod.pcm \ +// RUN: -include-pch %t/a.pch -o %t/Mod.o + + +//--- a.hpp +#pragma once + +class a { + virtual ~a(); + a() {} +}; + +//--- Part1.cppm +export module mod:part1; + +//--- Part2.cppm +export module mod:part2; + +//--- Part3.cppm +export module mod:part3; + +//--- Part4.cppm +export module mod:part4; + +//--- Mod.cppm +export module mod; +export import :part1; +export import :part2; +export import :part3; +export import :part4; + ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits