[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135457 >From 1e5adae44b8e8ebbb0438d1c5972f3937711954a Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 7 Apr 2025 08:37:40 -0700 Subject: [PATCH 1/4] [clang-doc] Handle static members and functions clang-doc didn't visit VarDecl, and hence never collected info from class statics members and functions. Fixes #59813. --- clang-tools-extra/clang-doc/Mapper.cpp| 4 ++ clang-tools-extra/clang-doc/Mapper.h | 1 + clang-tools-extra/clang-doc/Serialize.cpp | 56 +++ clang-tools-extra/clang-doc/Serialize.h | 4 ++ .../test/clang-doc/basic-project.test | 22 +++- 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp index 6c90db03424c6..98698f9151280 100644 --- a/clang-tools-extra/clang-doc/Mapper.cpp +++ b/clang-tools-extra/clang-doc/Mapper.cpp @@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } +bool MapASTVisitor::VisitVarDecl(const VarDecl *D) { + return mapDecl(D, D->isThisDeclarationADefinition()); +} + bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h index 75c8e947c8f90..62fc5fbbdf3da 100644 --- a/clang-tools-extra/clang-doc/Mapper.h +++ b/clang-tools-extra/clang-doc/Mapper.h @@ -36,6 +36,7 @@ class MapASTVisitor : public clang::RecursiveASTVisitor, void HandleTranslationUnit(ASTContext &Context) override; bool VisitNamespaceDecl(const NamespaceDecl *D); bool VisitRecordDecl(const RecordDecl *D); + bool VisitVarDecl(const VarDecl *D); bool VisitEnumDecl(const EnumDecl *D); bool VisitCXXMethodDecl(const CXXMethodDecl *D); bool VisitFunctionDecl(const FunctionDecl *D); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index f737fc75135a1..d34451cd10484 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, return {std::move(I), std::move(Parent)}; } +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); + bool IsInAnonymousNamespace = false; + populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir, + IsInAnonymousNamespace); + if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D)) +return {}; + + I->Path = getInfoRelativePath(I->Namespace); + + PopulateTemplateParameters(I->Template, D); + + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specilization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + std::pair, std::unique_ptr> emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h index 4e203ca7891ac..41946796f39f6 100644 --- a/clang-tools-extra/clang-doc/Serialize.h
[llvm-branch-commits] [compiler-rt] release/20.x: [rtsan][Apple] Add interceptor for _os_nospin_lock_lock (#131034) (PR #132997)
wrotki wrote: @tstellar yes - but I thought this PR was already closed? https://github.com/llvm/llvm-project/pull/132997 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libc++] Adds a FTM v2 data file generator. (PR #134555)
https://github.com/mordante edited https://github.com/llvm/llvm-project/pull/134555 ___ llvm-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: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133369 >From 7ad9df14547e40a0959956b7d5292e0114a00616 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Mar 2025 10:46:08 +0700 Subject: [PATCH] llvm-reduce: Preserve uselistorder when writing thinlto bitcode Fixes #63621 --- .../thinlto-preserve-uselistorder.ll | 19 +++ llvm/tools/llvm-reduce/ReducerWorkItem.cpp| 11 --- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll diff --git a/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll new file mode 100644 index 0..2332f2d632911 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll @@ -0,0 +1,19 @@ +; RUN: opt --thinlto-bc --thinlto-split-lto-unit %s -o %t.0 +; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=instructions %t.0 -o %t.1 \ +; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s +; RUN: llvm-dis --preserve-ll-uselistorder %t.1 -o %t.2 +; RUN: FileCheck --check-prefix=RESULT %s < %t.2 + +define i32 @func(i32 %arg0, i32 %arg1) { +entry: + %add0 = add i32 %arg0, 0 + %add1 = add i32 %add0, 0 + %add2 = add i32 %add1, 0 + %add3 = add i32 %arg1, 0 + %add4 = add i32 %add2, %add3 + ret i32 %add4 +} + +; INTERESTING: uselistorder i32 0 +; RESULT: uselistorder i32 0, { 0, 2, 1 } +uselistorder i32 0, { 3, 2, 1, 0 } diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp index 8d2675c685038..9af2e5f5fdd23 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -776,7 +776,11 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, } void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { + const bool ShouldPreserveUseListOrder = true; + if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) { +// FIXME: This should not depend on the pass manager. There are hidden +// transforms that may happen inside ThinLTOBitcodeWriterPass PassBuilder PB; LoopAnalysisManager LAM; FunctionAnalysisManager FAM; @@ -788,7 +792,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); ModulePassManager MPM; -MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr)); +MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr, + ShouldPreserveUseListOrder)); MPM.run(*M, MAM); } else { std::unique_ptr Index; @@ -797,8 +802,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { Index = std::make_unique( buildModuleSummaryIndex(*M, nullptr, &PSI)); } -WriteBitcodeToFile(getModule(), OutStream, - /*ShouldPreserveUseListOrder=*/true, Index.get()); +WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder, + Index.get()); } } ___ llvm-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: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133369 >From 7ad9df14547e40a0959956b7d5292e0114a00616 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Mar 2025 10:46:08 +0700 Subject: [PATCH] llvm-reduce: Preserve uselistorder when writing thinlto bitcode Fixes #63621 --- .../thinlto-preserve-uselistorder.ll | 19 +++ llvm/tools/llvm-reduce/ReducerWorkItem.cpp| 11 --- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll diff --git a/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll new file mode 100644 index 0..2332f2d632911 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll @@ -0,0 +1,19 @@ +; RUN: opt --thinlto-bc --thinlto-split-lto-unit %s -o %t.0 +; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=instructions %t.0 -o %t.1 \ +; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s +; RUN: llvm-dis --preserve-ll-uselistorder %t.1 -o %t.2 +; RUN: FileCheck --check-prefix=RESULT %s < %t.2 + +define i32 @func(i32 %arg0, i32 %arg1) { +entry: + %add0 = add i32 %arg0, 0 + %add1 = add i32 %add0, 0 + %add2 = add i32 %add1, 0 + %add3 = add i32 %arg1, 0 + %add4 = add i32 %add2, %add3 + ret i32 %add4 +} + +; INTERESTING: uselistorder i32 0 +; RESULT: uselistorder i32 0, { 0, 2, 1 } +uselistorder i32 0, { 3, 2, 1, 0 } diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp index 8d2675c685038..9af2e5f5fdd23 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -776,7 +776,11 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, } void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { + const bool ShouldPreserveUseListOrder = true; + if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) { +// FIXME: This should not depend on the pass manager. There are hidden +// transforms that may happen inside ThinLTOBitcodeWriterPass PassBuilder PB; LoopAnalysisManager LAM; FunctionAnalysisManager FAM; @@ -788,7 +792,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); ModulePassManager MPM; -MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr)); +MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr, + ShouldPreserveUseListOrder)); MPM.run(*M, MAM); } else { std::unique_ptr Index; @@ -797,8 +802,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { Index = std::make_unique( buildModuleSummaryIndex(*M, nullptr, &PSI)); } -WriteBitcodeToFile(getModule(), OutStream, - /*ShouldPreserveUseListOrder=*/true, Index.get()); +WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder, + Index.get()); } } ___ llvm-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] IR: Remove uselist for constantdata (PR #134692)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134692 >From 9313a3ec2e3cd0d4b68f4e3c02fe9bf05bbc2337 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 3 Apr 2025 17:30:01 +0700 Subject: [PATCH] IR: Remove uselist for constantdata This is a resurrected version of the patch attached to this RFC: https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606 In this adaptation, there are a few differences. In the original patch, the Use's use list was replaced with an unsigned* to the reference count in the value. This version leaves them as null and leaves the ref counting only in Value. Remove use-lists from instances of ConstantData (which are shared across modules and have no operands). To continue supporting most of the use-list API, store a ref-count in place of the use-list; this is for API like Value::use_empty and Value::hasNUses. Operations that actually need the use-list -- like Value::use_begin -- will assert. This change has three benefits: 1. The compiler output cannot in any way depend on the use-list order of instances of ConstantData. 2. There's no use-list traffic when adding and removing simple constants from operand lists (although there is ref-count traffic; YMMV). 3. It's cheaper to serialize use-lists (since we're no longer serializing the use-list order of things like i32 0). The downside is that you can't look at all the users of ConstantData, but traversals of users of i32 0 are already ill-advised. Possible follow-ups: - Track if an instance of a ConstantVector/ConstantArray/etc. is known to have all ConstantData arguments, and drop the use-lists to ref-counts in those cases. Callers need to check Value::hasUseList before iterating through the use-list. - Remove even the ref-counts. I'm not sure they have any benefit besides minimizing the scope of this commit, and maintaining the counts is not free. Fixes #58629 --- llvm/include/llvm/IR/Use.h| 23 +--- llvm/include/llvm/IR/Value.h | 119 ++ llvm/lib/Analysis/TypeMetadataUtils.cpp | 3 + llvm/lib/AsmParser/LLParser.cpp | 2 + llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 + llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 3 + llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 2 +- llvm/lib/CodeGen/CodeGenPrepare.cpp | 3 + .../lib/CodeGen/ComplexDeinterleavingPass.cpp | 3 + llvm/lib/IR/AsmWriter.cpp | 9 +- llvm/lib/IR/Instruction.cpp | 4 +- llvm/lib/IR/Use.cpp | 8 +- llvm/lib/IR/Value.cpp | 26 ++-- .../AArch64/GISel/AArch64RegisterBankInfo.cpp | 2 +- llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 66 +- .../InstCombineSimplifyDemanded.cpp | 7 +- .../InstCombine/InstructionCombining.cpp | 2 +- llvm/lib/Transforms/Scalar/Reassociate.cpp| 3 +- .../test/Analysis/MemorySSA/nondeterminism.ll | 1 - .../llvm-diff/uselistorder-issue58629-gv.ll | 14 +++ .../llvm-diff/uselistorder-issue58629.ll | 5 +- .../tools/llvm-reduce/bitcode-uselistorder.ll | 23 ++-- .../uselistorder-invalid-ir-output.ll | 6 +- .../verify-uselistorder.cpp | 9 ++ 24 files changed, 243 insertions(+), 104 deletions(-) create mode 100644 llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h index a86b9c46c1f69..bcd1fd6677497 100644 --- a/llvm/include/llvm/IR/Use.h +++ b/llvm/include/llvm/IR/Use.h @@ -23,6 +23,7 @@ namespace llvm { template struct simplify_type; +class ConstantData; class User; class Value; @@ -42,10 +43,7 @@ class Use { private: /// Destructor - Only for zap() - ~Use() { -if (Val) - removeFromList(); - } + ~Use(); /// Constructor Use(User *Parent) : Parent(Parent) {} @@ -87,19 +85,10 @@ class Use { Use **Prev = nullptr; User *Parent = nullptr; - void addToList(Use **List) { -Next = *List; -if (Next) - Next->Prev = &Next; -Prev = List; -*Prev = this; - } - - void removeFromList() { -*Prev = Next; -if (Next) - Next->Prev = Prev; - } + inline void addToList(unsigned &Count); + inline void addToList(Use *&List); + inline void removeFromList(unsigned &Count); + inline void removeFromList(Use *&List); }; /// Allow clients to treat uses just like values when using diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h index cfed12e2f5f8d..25d4750b5c0f8 100644 --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -116,7 +116,10 @@ class Value { private: Type *VTy; - Use *UseList; + union { +Use *List = nullptr; +unsigned Count; + } Uses; friend class ValueAsMetadata; // Allow access to IsUsedByMD. friend class ValueHandleBase; // Allow access to Ha
[llvm-branch-commits] [llvm] release/20.x: [X86] When expanding LCMPXCHG16B_SAVE_RBX, substitute RBX in base (#134109) (PR #134331)
aaronpuchert wrote: Release note: Fixed a miscompilation on X86 when using 16-byte atomic compare-and-swap on a frame variable when RBX is used as frame pointer. https://github.com/llvm/llvm-project/pull/134331 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135457 >From 1e4d789c7b45fbc17910d48602f314860e731350 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 7 Apr 2025 08:37:40 -0700 Subject: [PATCH 1/5] [clang-doc] Handle static members and functions clang-doc didn't visit VarDecl, and hence never collected info from class statics members and functions. Fixes #59813. --- clang-tools-extra/clang-doc/Mapper.cpp| 4 ++ clang-tools-extra/clang-doc/Mapper.h | 1 + clang-tools-extra/clang-doc/Serialize.cpp | 56 +++ clang-tools-extra/clang-doc/Serialize.h | 4 ++ .../test/clang-doc/basic-project.test | 13 - 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp index 6c90db03424c6..98698f9151280 100644 --- a/clang-tools-extra/clang-doc/Mapper.cpp +++ b/clang-tools-extra/clang-doc/Mapper.cpp @@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } +bool MapASTVisitor::VisitVarDecl(const VarDecl *D) { + return mapDecl(D, D->isThisDeclarationADefinition()); +} + bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h index 75c8e947c8f90..62fc5fbbdf3da 100644 --- a/clang-tools-extra/clang-doc/Mapper.h +++ b/clang-tools-extra/clang-doc/Mapper.h @@ -36,6 +36,7 @@ class MapASTVisitor : public clang::RecursiveASTVisitor, void HandleTranslationUnit(ASTContext &Context) override; bool VisitNamespaceDecl(const NamespaceDecl *D); bool VisitRecordDecl(const RecordDecl *D); + bool VisitVarDecl(const VarDecl *D); bool VisitEnumDecl(const EnumDecl *D); bool VisitCXXMethodDecl(const CXXMethodDecl *D); bool VisitFunctionDecl(const FunctionDecl *D); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index f737fc75135a1..d34451cd10484 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, return {std::move(I), std::move(Parent)}; } +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); + bool IsInAnonymousNamespace = false; + populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir, + IsInAnonymousNamespace); + if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D)) +return {}; + + I->Path = getInfoRelativePath(I->Namespace); + + PopulateTemplateParameters(I->Template, D); + + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specilization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + std::pair, std::unique_ptr> emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h index 4e203ca7891ac..41946796f39f6 100644 --- a/clang-tools-extra/clang-doc/Serialize.h +++
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135457 >From 1e4d789c7b45fbc17910d48602f314860e731350 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 7 Apr 2025 08:37:40 -0700 Subject: [PATCH 1/5] [clang-doc] Handle static members and functions clang-doc didn't visit VarDecl, and hence never collected info from class statics members and functions. Fixes #59813. --- clang-tools-extra/clang-doc/Mapper.cpp| 4 ++ clang-tools-extra/clang-doc/Mapper.h | 1 + clang-tools-extra/clang-doc/Serialize.cpp | 56 +++ clang-tools-extra/clang-doc/Serialize.h | 4 ++ .../test/clang-doc/basic-project.test | 13 - 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp index 6c90db03424c6..98698f9151280 100644 --- a/clang-tools-extra/clang-doc/Mapper.cpp +++ b/clang-tools-extra/clang-doc/Mapper.cpp @@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } +bool MapASTVisitor::VisitVarDecl(const VarDecl *D) { + return mapDecl(D, D->isThisDeclarationADefinition()); +} + bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h index 75c8e947c8f90..62fc5fbbdf3da 100644 --- a/clang-tools-extra/clang-doc/Mapper.h +++ b/clang-tools-extra/clang-doc/Mapper.h @@ -36,6 +36,7 @@ class MapASTVisitor : public clang::RecursiveASTVisitor, void HandleTranslationUnit(ASTContext &Context) override; bool VisitNamespaceDecl(const NamespaceDecl *D); bool VisitRecordDecl(const RecordDecl *D); + bool VisitVarDecl(const VarDecl *D); bool VisitEnumDecl(const EnumDecl *D); bool VisitCXXMethodDecl(const CXXMethodDecl *D); bool VisitFunctionDecl(const FunctionDecl *D); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index f737fc75135a1..d34451cd10484 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, return {std::move(I), std::move(Parent)}; } +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); + bool IsInAnonymousNamespace = false; + populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir, + IsInAnonymousNamespace); + if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D)) +return {}; + + I->Path = getInfoRelativePath(I->Namespace); + + PopulateTemplateParameters(I->Template, D); + + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specilization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + std::pair, std::unique_ptr> emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h index 4e203ca7891ac..41946796f39f6 100644 --- a/clang-tools-extra/clang-doc/Serialize.h +++
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
@@ -687,6 +687,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, PopulateTemplateParameters(I->Template, D); + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specialization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); ilovepi wrote: This probably should be a different type, instead of a Record. I'll experiment some and see if we have an existing Info class that will work a bit better. https://github.com/llvm/llvm-project/pull/135457 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135457 >From 1e5adae44b8e8ebbb0438d1c5972f3937711954a Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 7 Apr 2025 08:37:40 -0700 Subject: [PATCH 1/5] [clang-doc] Handle static members and functions clang-doc didn't visit VarDecl, and hence never collected info from class statics members and functions. Fixes #59813. --- clang-tools-extra/clang-doc/Mapper.cpp| 4 ++ clang-tools-extra/clang-doc/Mapper.h | 1 + clang-tools-extra/clang-doc/Serialize.cpp | 56 +++ clang-tools-extra/clang-doc/Serialize.h | 4 ++ .../test/clang-doc/basic-project.test | 22 +++- 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp index 6c90db03424c6..98698f9151280 100644 --- a/clang-tools-extra/clang-doc/Mapper.cpp +++ b/clang-tools-extra/clang-doc/Mapper.cpp @@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } +bool MapASTVisitor::VisitVarDecl(const VarDecl *D) { + return mapDecl(D, D->isThisDeclarationADefinition()); +} + bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h index 75c8e947c8f90..62fc5fbbdf3da 100644 --- a/clang-tools-extra/clang-doc/Mapper.h +++ b/clang-tools-extra/clang-doc/Mapper.h @@ -36,6 +36,7 @@ class MapASTVisitor : public clang::RecursiveASTVisitor, void HandleTranslationUnit(ASTContext &Context) override; bool VisitNamespaceDecl(const NamespaceDecl *D); bool VisitRecordDecl(const RecordDecl *D); + bool VisitVarDecl(const VarDecl *D); bool VisitEnumDecl(const EnumDecl *D); bool VisitCXXMethodDecl(const CXXMethodDecl *D); bool VisitFunctionDecl(const FunctionDecl *D); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index f737fc75135a1..d34451cd10484 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, return {std::move(I), std::move(Parent)}; } +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); + bool IsInAnonymousNamespace = false; + populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir, + IsInAnonymousNamespace); + if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D)) +return {}; + + I->Path = getInfoRelativePath(I->Namespace); + + PopulateTemplateParameters(I->Template, D); + + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specilization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + std::pair, std::unique_ptr> emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h index 4e203ca7891ac..41946796f39f6 100644 --- a/clang-tools-extra/clang-doc/Serialize.h
[llvm-branch-commits] [llvm] llvm-reduce: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133369 >From 64c6feaa25649ca5e6597db5f6fabbd6473e5932 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Mar 2025 10:46:08 +0700 Subject: [PATCH] llvm-reduce: Preserve uselistorder when writing thinlto bitcode Fixes #63621 --- .../thinlto-preserve-uselistorder.ll | 19 +++ llvm/tools/llvm-reduce/ReducerWorkItem.cpp| 11 --- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll diff --git a/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll new file mode 100644 index 0..2332f2d632911 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll @@ -0,0 +1,19 @@ +; RUN: opt --thinlto-bc --thinlto-split-lto-unit %s -o %t.0 +; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=instructions %t.0 -o %t.1 \ +; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s +; RUN: llvm-dis --preserve-ll-uselistorder %t.1 -o %t.2 +; RUN: FileCheck --check-prefix=RESULT %s < %t.2 + +define i32 @func(i32 %arg0, i32 %arg1) { +entry: + %add0 = add i32 %arg0, 0 + %add1 = add i32 %add0, 0 + %add2 = add i32 %add1, 0 + %add3 = add i32 %arg1, 0 + %add4 = add i32 %add2, %add3 + ret i32 %add4 +} + +; INTERESTING: uselistorder i32 0 +; RESULT: uselistorder i32 0, { 0, 2, 1 } +uselistorder i32 0, { 3, 2, 1, 0 } diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp index 8d2675c685038..9af2e5f5fdd23 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -776,7 +776,11 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, } void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { + const bool ShouldPreserveUseListOrder = true; + if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) { +// FIXME: This should not depend on the pass manager. There are hidden +// transforms that may happen inside ThinLTOBitcodeWriterPass PassBuilder PB; LoopAnalysisManager LAM; FunctionAnalysisManager FAM; @@ -788,7 +792,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); ModulePassManager MPM; -MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr)); +MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr, + ShouldPreserveUseListOrder)); MPM.run(*M, MAM); } else { std::unique_ptr Index; @@ -797,8 +802,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { Index = std::make_unique( buildModuleSummaryIndex(*M, nullptr, &PSI)); } -WriteBitcodeToFile(getModule(), OutStream, - /*ShouldPreserveUseListOrder=*/true, Index.get()); +WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder, + Index.get()); } } ___ llvm-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: Preserve uselistorder when writing thinlto bitcode (PR #133369)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/133369 >From 64c6feaa25649ca5e6597db5f6fabbd6473e5932 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 28 Mar 2025 10:46:08 +0700 Subject: [PATCH] llvm-reduce: Preserve uselistorder when writing thinlto bitcode Fixes #63621 --- .../thinlto-preserve-uselistorder.ll | 19 +++ llvm/tools/llvm-reduce/ReducerWorkItem.cpp| 11 --- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll diff --git a/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll new file mode 100644 index 0..2332f2d632911 --- /dev/null +++ b/llvm/test/tools/llvm-reduce/thinlto-preserve-uselistorder.ll @@ -0,0 +1,19 @@ +; RUN: opt --thinlto-bc --thinlto-split-lto-unit %s -o %t.0 +; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=instructions %t.0 -o %t.1 \ +; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s +; RUN: llvm-dis --preserve-ll-uselistorder %t.1 -o %t.2 +; RUN: FileCheck --check-prefix=RESULT %s < %t.2 + +define i32 @func(i32 %arg0, i32 %arg1) { +entry: + %add0 = add i32 %arg0, 0 + %add1 = add i32 %add0, 0 + %add2 = add i32 %add1, 0 + %add3 = add i32 %arg1, 0 + %add4 = add i32 %add2, %add3 + ret i32 %add4 +} + +; INTERESTING: uselistorder i32 0 +; RESULT: uselistorder i32 0, { 0, 2, 1 } +uselistorder i32 0, { 3, 2, 1, 0 } diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp index 8d2675c685038..9af2e5f5fdd23 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -776,7 +776,11 @@ void ReducerWorkItem::readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, } void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { + const bool ShouldPreserveUseListOrder = true; + if (LTOInfo && LTOInfo->IsThinLTO && LTOInfo->EnableSplitLTOUnit) { +// FIXME: This should not depend on the pass manager. There are hidden +// transforms that may happen inside ThinLTOBitcodeWriterPass PassBuilder PB; LoopAnalysisManager LAM; FunctionAnalysisManager FAM; @@ -788,7 +792,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); ModulePassManager MPM; -MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr)); +MPM.addPass(ThinLTOBitcodeWriterPass(OutStream, nullptr, + ShouldPreserveUseListOrder)); MPM.run(*M, MAM); } else { std::unique_ptr Index; @@ -797,8 +802,8 @@ void ReducerWorkItem::writeBitcode(raw_ostream &OutStream) const { Index = std::make_unique( buildModuleSummaryIndex(*M, nullptr, &PSI)); } -WriteBitcodeToFile(getModule(), OutStream, - /*ShouldPreserveUseListOrder=*/true, Index.get()); +WriteBitcodeToFile(getModule(), OutStream, ShouldPreserveUseListOrder, + Index.get()); } } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135457 >From 1e5adae44b8e8ebbb0438d1c5972f3937711954a Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 7 Apr 2025 08:37:40 -0700 Subject: [PATCH 1/3] [clang-doc] Handle static members and functions clang-doc didn't visit VarDecl, and hence never collected info from class statics members and functions. Fixes #59813. --- clang-tools-extra/clang-doc/Mapper.cpp| 4 ++ clang-tools-extra/clang-doc/Mapper.h | 1 + clang-tools-extra/clang-doc/Serialize.cpp | 56 +++ clang-tools-extra/clang-doc/Serialize.h | 4 ++ .../test/clang-doc/basic-project.test | 22 +++- 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp index 6c90db03424c6..98698f9151280 100644 --- a/clang-tools-extra/clang-doc/Mapper.cpp +++ b/clang-tools-extra/clang-doc/Mapper.cpp @@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } +bool MapASTVisitor::VisitVarDecl(const VarDecl *D) { + return mapDecl(D, D->isThisDeclarationADefinition()); +} + bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) { return mapDecl(D, D->isThisDeclarationADefinition()); } diff --git a/clang-tools-extra/clang-doc/Mapper.h b/clang-tools-extra/clang-doc/Mapper.h index 75c8e947c8f90..62fc5fbbdf3da 100644 --- a/clang-tools-extra/clang-doc/Mapper.h +++ b/clang-tools-extra/clang-doc/Mapper.h @@ -36,6 +36,7 @@ class MapASTVisitor : public clang::RecursiveASTVisitor, void HandleTranslationUnit(ASTContext &Context) override; bool VisitNamespaceDecl(const NamespaceDecl *D); bool VisitRecordDecl(const RecordDecl *D); + bool VisitVarDecl(const VarDecl *D); bool VisitEnumDecl(const EnumDecl *D); bool VisitCXXMethodDecl(const CXXMethodDecl *D); bool VisitFunctionDecl(const FunctionDecl *D); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index f737fc75135a1..d34451cd10484 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, return {std::move(I), std::move(Parent)}; } +std::pair, std::unique_ptr> +emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber, + llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { + auto I = std::make_unique(); + bool IsInAnonymousNamespace = false; + populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir, + IsInAnonymousNamespace); + if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D)) +return {}; + + I->Path = getInfoRelativePath(I->Namespace); + + PopulateTemplateParameters(I->Template, D); + + // Full and partial specializations. + if (auto *CTSD = dyn_cast(D)) { +if (!I->Template) + I->Template.emplace(); +I->Template->Specialization.emplace(); +auto &Specialization = *I->Template->Specialization; + +// What this is a specialization of. +auto SpecOf = CTSD->getSpecializedTemplateOrPartial(); +if (auto *CTD = dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTD); +else if (auto *CTPSD = + dyn_cast(SpecOf)) + Specialization.SpecializationOf = getUSRForDecl(CTPSD); + +// Parameters to the specilization. For partial specializations, get the +// parameters "as written" from the ClassTemplatePartialSpecializationDecl +// because the non-explicit template parameters will have generated internal +// placeholder names rather than the names the user typed that match the +// template parameters. +if (const ClassTemplatePartialSpecializationDecl *CTPSD = +dyn_cast(D)) { + if (const ASTTemplateArgumentListInfo *AsWritten = + CTPSD->getTemplateArgsAsWritten()) { +for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) { + Specialization.Params.emplace_back( + getSourceCode(D, (*AsWritten)[i].getSourceRange())); +} + } +} else { + for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) { +Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg)); + } +} + } + + // Records are inserted into the parent by reference, so we need to return + // both the parent and the record itself. + auto Parent = MakeAndInsertIntoParent(*I); + return {std::move(I), std::move(Parent)}; +} + std::pair, std::unique_ptr> emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) { diff --git a/clang-tools-extra/clang-doc/Serialize.h b/clang-tools-extra/clang-doc/Serialize.h index 4e203ca7891ac..41946796f39f6 100644 --- a/clang-tools-extra/clang-doc/Serialize.h
[llvm-branch-commits] RISCVAsmParser: Reject call foo@invalid (PR #135509)
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/135509 ... instead of silently parsing and ignoring it without leaving an error message. While here, remove an unreachable `@plt`. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] RISCVAsmParser: Reject call foo@invalid (PR #135509)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v Author: Fangrui Song (MaskRay) Changes ... instead of silently parsing and ignoring it without leaving an error message. While here, remove an unreachable `@plt`. --- Full diff: https://github.com/llvm/llvm-project/pull/135509.diff 3 Files Affected: - (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+2-4) - (modified) llvm/test/MC/RISCV/function-call-invalid.s (+1) - (modified) llvm/test/MC/RISCV/tail-call-invalid.s (+1) ``diff diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 952587171ffce..5804706baea9b 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -2070,9 +2070,6 @@ ParseStatus RISCVAsmParser::parseBareSymbol(OperandVector &Operands) { SMLoc E = SMLoc::getFromPointer(S.getPointer() + Identifier.size()); - if (Identifier.consume_back("@plt")) -return Error(getLoc(), "'@plt' operand not valid for instruction"); - MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier); if (Sym->isVariable()) { @@ -2120,8 +2117,9 @@ ParseStatus RISCVAsmParser::parseCallSymbol(OperandVector &Operands) { Lex(); Lex(); StringRef PLT; +SMLoc Loc = getLoc(); if (getParser().parseIdentifier(PLT) || PLT != "plt") - return ParseStatus::Failure; + return Error(Loc, "@ (except the deprecated/ignored @plt) is disallowed"); } else if (!getLexer().peekTok().is(AsmToken::EndOfStatement)) { // Avoid parsing the register in `call rd, foo` as a call symbol. return ParseStatus::NoMatch; diff --git a/llvm/test/MC/RISCV/function-call-invalid.s b/llvm/test/MC/RISCV/function-call-invalid.s index 2b7a85245880d..d429c4e27ba14 100644 --- a/llvm/test/MC/RISCV/function-call-invalid.s +++ b/llvm/test/MC/RISCV/function-call-invalid.s @@ -10,3 +10,4 @@ call %lo(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call foo, bar # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name +call foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed diff --git a/llvm/test/MC/RISCV/tail-call-invalid.s b/llvm/test/MC/RISCV/tail-call-invalid.s index 270d84df58ac4..14ff996b2e4b1 100644 --- a/llvm/test/MC/RISCV/tail-call-invalid.s +++ b/llvm/test/MC/RISCV/tail-call-invalid.s @@ -10,3 +10,4 @@ tail %hi(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name tail %lo(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name tail %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name tail %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name +tail foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed `` https://github.com/llvm/llvm-project/pull/135509 ___ llvm-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] RISCVAsmParser: Reject call foo@invalid (PR #135509)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/135509 >From 3579f7d24a771f4c02e796a2ac9b91024b3c6ce9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 12 Apr 2025 16:27:14 -0700 Subject: [PATCH] . Created using spr 1.3.5-bogner --- llvm/test/MC/RISCV/function-call-invalid.s | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/test/MC/RISCV/function-call-invalid.s b/llvm/test/MC/RISCV/function-call-invalid.s index d429c4e27ba14..17d02015a6949 100644 --- a/llvm/test/MC/RISCV/function-call-invalid.s +++ b/llvm/test/MC/RISCV/function-call-invalid.s @@ -11,3 +11,4 @@ call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call foo, bar # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name call foo@pls # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed +call foo@3 # CHECK: :[[@LINE]]:10: error: @ (except the deprecated/ignored @plt) is disallowed ___ llvm-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] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134688 >From e0e5a0523bd77bcba066dcb9224a8bef889f51a7 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 07:36:45 +0700 Subject: [PATCH] SimplifyLibCalls: Skip sincospi optimization for ConstantData Avoids looking at the uselist, and it would probably be more productive to constant fold this. --- .../lib/Transforms/Utils/SimplifyLibCalls.cpp | 3 +++ llvm/test/Transforms/InstCombine/sincospi.ll | 24 +++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 2d0027d976019..4e37c587dc975 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3002,6 +3002,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, bool IsSin, IRBuilderBa return nullptr; Value *Arg = CI->getArgOperand(0); + if (isa(Arg)) +return nullptr; + SmallVector SinCalls; SmallVector CosCalls; SmallVector SinCosCalls; diff --git a/llvm/test/Transforms/InstCombine/sincospi.ll b/llvm/test/Transforms/InstCombine/sincospi.ll index b76ae20171147..14da03dff6f49 100644 --- a/llvm/test/Transforms/InstCombine/sincospi.ll +++ b/llvm/test/Transforms/InstCombine/sincospi.ll @@ -90,18 +90,14 @@ define float @test_instbased_f32_other_user(ptr %ptr) { define float @test_constant_f32() { ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f32( -; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call <2 x float> @__sincospif_stret(float 1.00e+00) -; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 0 -; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 1 -; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]] ; CHECK-FLOAT-IN-VEC-NEXT:ret float [[RES]] ; ; CHECK-LABEL: @test_constant_f32( -; CHECK-NEXT:[[SINCOSPI:%.*]] = call { float, float } @__sincospif_stret(float 1.00e+00) -; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 0 -; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 1 -; CHECK-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] ; CHECK-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]] ; CHECK-NEXT:ret float [[RES]] ; @@ -172,18 +168,14 @@ define double @test_instbased_f64() { define double @test_constant_f64() { ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f64( -; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.00e+00) -; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0 -; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1 -; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]] ; CHECK-FLOAT-IN-VEC-NEXT:ret double [[RES]] ; ; CHECK-LABEL: @test_constant_f64( -; CHECK-NEXT:[[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.00e+00) -; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0 -; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1 -; CHECK-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] ; CHECK-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]] ; CHECK-NEXT:ret double [[RES]] ; ___ llvm-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] PHITransAddr: Avoid looking at constant use lists (PR #134689)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134689 >From 2c9dfd2f009f44237eabb276c8cbcc3b998b919a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 07:42:53 +0700 Subject: [PATCH] PHITransAddr: Avoid looking at constant use lists Avoids asserts in GVN --- llvm/lib/Analysis/PHITransAddr.cpp | 3 ++ llvm/test/Transforms/GVN/pr65447.ll | 83 ++--- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp index e42113db42781..276708c2ebf77 100644 --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -224,6 +224,9 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB, // Scan to see if we have this GEP available. Value *APHIOp = GEPOps[0]; +if (isa(APHIOp)) + return nullptr; + for (User *U : APHIOp->users()) { if (GetElementPtrInst *GEPI = dyn_cast(U)) if (GEPI->getType() == GEP->getType() && diff --git a/llvm/test/Transforms/GVN/pr65447.ll b/llvm/test/Transforms/GVN/pr65447.ll index 1b951e907e822..1fa3811a3a81d 100644 --- a/llvm/test/Transforms/GVN/pr65447.ll +++ b/llvm/test/Transforms/GVN/pr65447.ll @@ -2,29 +2,98 @@ ; RUN: opt -S -passes=gvn < %s | FileCheck %s ; Make sure deduplicated phi nodes are removed from the VN map. -define i64 @f() { -; CHECK-LABEL: define i64 @f() { +define i64 @f2(ptr %arg) { +; CHECK-LABEL: define i64 @f2( +; CHECK-SAME: ptr [[ARG:%.*]]) { +; CHECK-NEXT: BB: +; CHECK-NEXT:store i1 false, ptr [[ARG]], align 1 +; CHECK-NEXT:br label [[BB2D:%.*]] +; CHECK: BB2a: +; CHECK-NEXT:br label [[BB2B:%.*]] +; CHECK: BB2b: +; CHECK-NEXT:br label [[BB2C:%.*]] +; CHECK: BB2c: +; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ] +; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64 +; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[DOTPHI_TRANS_INSERT]] +; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1 +; CHECK-NEXT:br label [[BB2D]] +; CHECK: BB2d: +; CHECK-NEXT:[[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ] +; CHECK-NEXT:[[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, [[BB]] ] +; CHECK-NEXT:[[TMP0:%.*]] = sext i1 [[AZ]] to i64 +; CHECK-NEXT:[[GEP2:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[TMP0]] +; CHECK-NEXT:store i1 [[AZ]], ptr [[ARG]], align 2 +; CHECK-NEXT:br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]] +; CHECK: BB1e: +; CHECK-NEXT:br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]] +; CHECK: BB2f: +; CHECK-NEXT:store i1 true, ptr [[ARG]], align 2 +; CHECK-NEXT:br label [[BB2B]] +; CHECK: BB4: +; CHECK-NEXT:br label [[BB4]] +; +BB: + store i1 false, ptr %arg, align 1 + br label %BB2d + +BB2a: ; No predecessors! + br label %BB2b + +BB2b: ; preds = %BB2f, %BB2a + br label %BB2c + +BB2c: ; preds = %BB2d, %BB2b + %0 = phi i1 [ true, %BB2b ], [ %1, %BB2d ] + br label %BB2d + +BB2d: ; preds = %BB2c, %BB + %1 = phi i1 [ %0, %BB2c ], [ false, %BB ] + %2 = sext i1 %1 to i64 + %gep2 = getelementptr i1, ptr %arg, i64 %2 + %L93 = load i1, ptr %gep2, align 1 + %Az = load i1, ptr %arg, align 2 + store i1 %1, ptr %arg, align 2 + br i1 %L93, label %BB2c, label %BB1e + +BB1e:; preds = %BB2d + br i1 %Az, label %BB2f, label %BB4 + +BB2f:; preds = %BB1e + store i1 true, ptr %arg, align 2 + br label %BB2b + +BB4: ; preds = %BB1e, %BB4 + br label %BB4 + +; uselistorder directives + uselistorder label %BB4, { 1, 0 } +} + +; Make sure deduplicated phi nodes are removed from the VN map. Make +; sure there is no assert on attempt to use ConstantData use lists. +define i64 @f_null() { +; CHECK-LABEL: define i64 @f_null() { ; CHECK-NEXT: BB: ; CHECK-NEXT:store i1 false, ptr null, align 1 ; CHECK-NEXT:br label [[BB2D:%.*]] ; CHECK: BB2a: ; CHECK-NEXT:br label [[BB2B:%.*]] ; CHECK: BB2b: -; CHECK-NEXT:[[L93_PRE_PRE:%.*]] = load i1, ptr inttoptr (i64 -1 to ptr), align 1 ; CHECK-NEXT:br label [[BB2C:%.*]] ; CHECK: BB2c: -; CHECK-NEXT:[[L93_PRE:%.*]] = phi i1 [ [[L93_PRE_PRE]], [[BB2B]] ], [ true, [[BB2D]] ] ; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ] ; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64 ; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr null, i64 [[DOTPHI_TRANS_INSERT]] +; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1 ; CHECK-NEXT:br label [[BB2D]] ; CHECK: BB2d: -; CHECK-NEXT:[[L93_PRE5:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false,
[llvm-branch-commits] [llvm] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134688 >From e0e5a0523bd77bcba066dcb9224a8bef889f51a7 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 07:36:45 +0700 Subject: [PATCH] SimplifyLibCalls: Skip sincospi optimization for ConstantData Avoids looking at the uselist, and it would probably be more productive to constant fold this. --- .../lib/Transforms/Utils/SimplifyLibCalls.cpp | 3 +++ llvm/test/Transforms/InstCombine/sincospi.ll | 24 +++ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 2d0027d976019..4e37c587dc975 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3002,6 +3002,9 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, bool IsSin, IRBuilderBa return nullptr; Value *Arg = CI->getArgOperand(0); + if (isa(Arg)) +return nullptr; + SmallVector SinCalls; SmallVector CosCalls; SmallVector SinCosCalls; diff --git a/llvm/test/Transforms/InstCombine/sincospi.ll b/llvm/test/Transforms/InstCombine/sincospi.ll index b76ae20171147..14da03dff6f49 100644 --- a/llvm/test/Transforms/InstCombine/sincospi.ll +++ b/llvm/test/Transforms/InstCombine/sincospi.ll @@ -90,18 +90,14 @@ define float @test_instbased_f32_other_user(ptr %ptr) { define float @test_constant_f32() { ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f32( -; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call <2 x float> @__sincospif_stret(float 1.00e+00) -; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 0 -; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractelement <2 x float> [[SINCOSPI]], i64 1 -; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]] ; CHECK-FLOAT-IN-VEC-NEXT:ret float [[RES]] ; ; CHECK-LABEL: @test_constant_f32( -; CHECK-NEXT:[[SINCOSPI:%.*]] = call { float, float } @__sincospif_stret(float 1.00e+00) -; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 0 -; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { float, float } [[SINCOSPI]], 1 -; CHECK-NEXT:[[COS:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[SINPI:%.*]] = call float @__sinpif(float 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[COSPI:%.*]] = call float @__cospif(float 1.00e+00) #[[ATTR0]] ; CHECK-NEXT:[[RES:%.*]] = fadd float [[SINPI]], [[COSPI]] ; CHECK-NEXT:ret float [[RES]] ; @@ -172,18 +168,14 @@ define double @test_instbased_f64() { define double @test_constant_f64() { ; CHECK-FLOAT-IN-VEC-LABEL: @test_constant_f64( -; CHECK-FLOAT-IN-VEC-NEXT:[[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.00e+00) -; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0 -; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1 -; CHECK-FLOAT-IN-VEC-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) #[[ATTR0]] +; CHECK-FLOAT-IN-VEC-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] ; CHECK-FLOAT-IN-VEC-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]] ; CHECK-FLOAT-IN-VEC-NEXT:ret double [[RES]] ; ; CHECK-LABEL: @test_constant_f64( -; CHECK-NEXT:[[SINCOSPI:%.*]] = call { double, double } @__sincospi_stret(double 1.00e+00) -; CHECK-NEXT:[[SINPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 0 -; CHECK-NEXT:[[COSPI:%.*]] = extractvalue { double, double } [[SINCOSPI]], 1 -; CHECK-NEXT:[[COS:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[SINPI:%.*]] = call double @__sinpi(double 1.00e+00) #[[ATTR0]] +; CHECK-NEXT:[[COSPI:%.*]] = call double @__cospi(double 1.00e+00) #[[ATTR0]] ; CHECK-NEXT:[[RES:%.*]] = fadd double [[SINPI]], [[COSPI]] ; CHECK-NEXT:ret double [[RES]] ; ___ llvm-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] IR: Remove uselist for constantdata (PR #134692)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134692 >From 9313a3ec2e3cd0d4b68f4e3c02fe9bf05bbc2337 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 3 Apr 2025 17:30:01 +0700 Subject: [PATCH] IR: Remove uselist for constantdata This is a resurrected version of the patch attached to this RFC: https://discourse.llvm.org/t/rfc-constantdata-should-not-have-use-lists/42606 In this adaptation, there are a few differences. In the original patch, the Use's use list was replaced with an unsigned* to the reference count in the value. This version leaves them as null and leaves the ref counting only in Value. Remove use-lists from instances of ConstantData (which are shared across modules and have no operands). To continue supporting most of the use-list API, store a ref-count in place of the use-list; this is for API like Value::use_empty and Value::hasNUses. Operations that actually need the use-list -- like Value::use_begin -- will assert. This change has three benefits: 1. The compiler output cannot in any way depend on the use-list order of instances of ConstantData. 2. There's no use-list traffic when adding and removing simple constants from operand lists (although there is ref-count traffic; YMMV). 3. It's cheaper to serialize use-lists (since we're no longer serializing the use-list order of things like i32 0). The downside is that you can't look at all the users of ConstantData, but traversals of users of i32 0 are already ill-advised. Possible follow-ups: - Track if an instance of a ConstantVector/ConstantArray/etc. is known to have all ConstantData arguments, and drop the use-lists to ref-counts in those cases. Callers need to check Value::hasUseList before iterating through the use-list. - Remove even the ref-counts. I'm not sure they have any benefit besides minimizing the scope of this commit, and maintaining the counts is not free. Fixes #58629 --- llvm/include/llvm/IR/Use.h| 23 +--- llvm/include/llvm/IR/Value.h | 119 ++ llvm/lib/Analysis/TypeMetadataUtils.cpp | 3 + llvm/lib/AsmParser/LLParser.cpp | 2 + llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 + llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 3 + llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 2 +- llvm/lib/CodeGen/CodeGenPrepare.cpp | 3 + .../lib/CodeGen/ComplexDeinterleavingPass.cpp | 3 + llvm/lib/IR/AsmWriter.cpp | 9 +- llvm/lib/IR/Instruction.cpp | 4 +- llvm/lib/IR/Use.cpp | 8 +- llvm/lib/IR/Value.cpp | 26 ++-- .../AArch64/GISel/AArch64RegisterBankInfo.cpp | 2 +- llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 66 +- .../InstCombineSimplifyDemanded.cpp | 7 +- .../InstCombine/InstructionCombining.cpp | 2 +- llvm/lib/Transforms/Scalar/Reassociate.cpp| 3 +- .../test/Analysis/MemorySSA/nondeterminism.ll | 1 - .../llvm-diff/uselistorder-issue58629-gv.ll | 14 +++ .../llvm-diff/uselistorder-issue58629.ll | 5 +- .../tools/llvm-reduce/bitcode-uselistorder.ll | 23 ++-- .../uselistorder-invalid-ir-output.ll | 6 +- .../verify-uselistorder.cpp | 9 ++ 24 files changed, 243 insertions(+), 104 deletions(-) create mode 100644 llvm/test/tools/llvm-diff/uselistorder-issue58629-gv.ll diff --git a/llvm/include/llvm/IR/Use.h b/llvm/include/llvm/IR/Use.h index a86b9c46c1f69..bcd1fd6677497 100644 --- a/llvm/include/llvm/IR/Use.h +++ b/llvm/include/llvm/IR/Use.h @@ -23,6 +23,7 @@ namespace llvm { template struct simplify_type; +class ConstantData; class User; class Value; @@ -42,10 +43,7 @@ class Use { private: /// Destructor - Only for zap() - ~Use() { -if (Val) - removeFromList(); - } + ~Use(); /// Constructor Use(User *Parent) : Parent(Parent) {} @@ -87,19 +85,10 @@ class Use { Use **Prev = nullptr; User *Parent = nullptr; - void addToList(Use **List) { -Next = *List; -if (Next) - Next->Prev = &Next; -Prev = List; -*Prev = this; - } - - void removeFromList() { -*Prev = Next; -if (Next) - Next->Prev = Prev; - } + inline void addToList(unsigned &Count); + inline void addToList(Use *&List); + inline void removeFromList(unsigned &Count); + inline void removeFromList(Use *&List); }; /// Allow clients to treat uses just like values when using diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h index cfed12e2f5f8d..25d4750b5c0f8 100644 --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -116,7 +116,10 @@ class Value { private: Type *VTy; - Use *UseList; + union { +Use *List = nullptr; +unsigned Count; + } Uses; friend class ValueAsMetadata; // Allow access to IsUsedByMD. friend class ValueHandleBase; // Allow access to Ha
[llvm-branch-commits] [llvm] LICM: Avoid looking at use list of constant data (PR #134690)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134690 >From fa88dda2492007501c023bb59139d14a91bf76d0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 20:10:54 +0700 Subject: [PATCH] LICM: Avoid looking at use list of constant data The codegen test changes seem incidental. Either way, sms-grp-order.ll seems to already not hit the original issue. --- llvm/lib/Transforms/Scalar/LICM.cpp| 12 --- llvm/test/CodeGen/AMDGPU/swdev380865.ll| 9 ++--- llvm/test/CodeGen/PowerPC/pr43527.ll | 22 +++- llvm/test/CodeGen/PowerPC/pr48519.ll | 5 +-- llvm/test/CodeGen/PowerPC/sms-grp-order.ll | 30 llvm/test/Transforms/LICM/pr50367.ll | 41 +- llvm/test/Transforms/LICM/pr59324.ll | 27 +- 7 files changed, 110 insertions(+), 36 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index d872a381050ca..889b43a843bef 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2294,10 +2294,14 @@ collectPromotionCandidates(MemorySSA *MSSA, AliasAnalysis *AA, Loop *L) { AliasSetTracker AST(BatchAA); auto IsPotentiallyPromotable = [L](const Instruction *I) { -if (const auto *SI = dyn_cast(I)) - return L->isLoopInvariant(SI->getPointerOperand()); -if (const auto *LI = dyn_cast(I)) - return L->isLoopInvariant(LI->getPointerOperand()); +if (const auto *SI = dyn_cast(I)) { + const Value *PtrOp = SI->getPointerOperand(); + return !isa(PtrOp) && L->isLoopInvariant(PtrOp); +} +if (const auto *LI = dyn_cast(I)) { + const Value *PtrOp = LI->getPointerOperand(); + return !isa(PtrOp) && L->isLoopInvariant(PtrOp); +} return false; }; diff --git a/llvm/test/CodeGen/AMDGPU/swdev380865.ll b/llvm/test/CodeGen/AMDGPU/swdev380865.ll index 9189cef019cf4..4a5dc8f300af3 100644 --- a/llvm/test/CodeGen/AMDGPU/swdev380865.ll +++ b/llvm/test/CodeGen/AMDGPU/swdev380865.ll @@ -16,15 +16,16 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr addrspace(1) %x.coerce) ; CHECK: ; %bb.0: ; %entry ; CHECK-NEXT:s_mov_b64 s[0:1], 0 ; CHECK-NEXT:s_load_dword s2, s[0:1], 0x0 +; CHECK-NEXT:s_mov_b64 s[0:1], 0x100 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[0:1], 0x0 ; CHECK-NEXT:s_mov_b32 s4, 0 ; CHECK-NEXT:s_mov_b32 s0, 0 -; CHECK-NEXT:s_mov_b32 s5, 0x4028 ; CHECK-NEXT:s_waitcnt lgkmcnt(0) ; CHECK-NEXT:s_mov_b32 s1, s2 ; CHECK-NEXT:s_mov_b32 s2, 0 ; CHECK-NEXT:v_mov_b32_e32 v0, s6 ; CHECK-NEXT:s_mov_b32 s3, 0x4026 +; CHECK-NEXT:s_mov_b32 s5, 0x4028 ; CHECK-NEXT:v_mov_b32_e32 v1, s7 ; CHECK-NEXT: .LBB0_1: ; %for.cond4.preheader ; CHECK-NEXT:; =>This Inner Loop Header: Depth=1 @@ -50,7 +51,7 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr addrspace(1) %x.coerce) ; CHECK-NEXT:v_add_f64 v[0:1], v[0:1], s[4:5] ; CHECK-NEXT:s_cbranch_scc1 .LBB0_1 ; CHECK-NEXT: ; %bb.2: ; %for.cond.cleanup.loopexit -; CHECK-NEXT:v_mov_b32_e32 v2, 0 +; CHECK-NEXT:v_mov_b32_e32 v2, 0x100 ; CHECK-NEXT:v_mov_b32_e32 v3, 0 ; CHECK-NEXT:global_store_dwordx2 v[2:3], v[0:1], off ; CHECK-NEXT:s_endpgm @@ -61,7 +62,7 @@ entry: for.cond4.preheader: ; preds = %for.cond4.preheader, %entry %idx.07 = phi i32 [ %add13, %for.cond4.preheader ], [ 0, %entry ] - %arrayidx.promoted = load double, ptr addrspace(1) null, align 8 + %arrayidx.promoted = load double, ptr addrspace(1) inttoptr (i64 256 to ptr addrspace(1)), align 8 %add9 = fadd contract double %arrayidx.promoted, 0.00e+00 %add9.1 = fadd contract double %add9, 5.00e+00 %add9.2 = fadd contract double %add9.1, 6.00e+00 @@ -70,7 +71,7 @@ for.cond4.preheader: ; preds = %for.cond4.preheader %add9.5 = fadd contract double %add9.4, 1.00e+01 %add9.6 = fadd contract double %add9.5, 1.10e+01 %add9.7 = fadd contract double %add9.6, 1.20e+01 - store double %add9.7, ptr addrspace(1) null, align 8 + store double %add9.7, ptr addrspace(1) inttoptr (i64 256 to ptr addrspace(1)), align 8 %add13 = add i32 %idx.07, %0 %cmp = icmp slt i32 %add13, 2560 br i1 %cmp, label %for.cond4.preheader, label %for.cond.cleanup diff --git a/llvm/test/CodeGen/PowerPC/pr43527.ll b/llvm/test/CodeGen/PowerPC/pr43527.ll index 379bd6c070c77..adfea51077a0b 100644 --- a/llvm/test/CodeGen/PowerPC/pr43527.ll +++ b/llvm/test/CodeGen/PowerPC/pr43527.ll @@ -2,7 +2,7 @@ ; RUN: llc -ppc-asm-full-reg-names -verify-machineinstrs \ ; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s ; We don't want to produce a CTR loop due to the call to lrint in the body. -define dso_local void @test(i64 %arg, i64 %arg1) { +define dso_local void @test(i64 %arg, i64 %arg1, ptr %arg2) { ; CHECK-LABEL: test: ; CHECK:
[llvm-branch-commits] [llvm] SCEVExpander: Don't look at uses of constants (PR #134691)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134691 >From 30c317d35d43e8b8f023aa8fbc4b12a906deacdf Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 21:56:00 +0700 Subject: [PATCH] SCEVExpander: Don't look at uses of constants This could be more relaxed, and look for uses of globals in the same function but no tests apparently depend on that. --- .../Utils/ScalarEvolutionExpander.cpp | 29 ++- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 41bf202230e22..e25ec6c3b2a58 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -111,20 +111,23 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty, Value *Ret = nullptr; - // Check to see if there is already a cast! - for (User *U : V->users()) { -if (U->getType() != Ty) - continue; -CastInst *CI = dyn_cast(U); -if (!CI || CI->getOpcode() != Op) - continue; + if (!isa(V)) { +// Check to see if there is already a cast! +for (User *U : V->users()) { + if (U->getType() != Ty) +continue; + CastInst *CI = dyn_cast(U); + if (!CI || CI->getOpcode() != Op) +continue; -// Found a suitable cast that is at IP or comes before IP. Use it. Note that -// the cast must also properly dominate the Builder's insertion point. -if (IP->getParent() == CI->getParent() && &*BIP != CI && -(&*IP == CI || CI->comesBefore(&*IP))) { - Ret = CI; - break; + // Found a suitable cast that is at IP or comes before IP. Use it. Note + // that the cast must also properly dominate the Builder's insertion + // point. + if (IP->getParent() == CI->getParent() && &*BIP != CI && + (&*IP == CI || CI->comesBefore(&*IP))) { +Ret = CI; +break; + } } } ___ llvm-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] PHITransAddr: Avoid looking at constant use lists (PR #134689)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134689 >From 2c9dfd2f009f44237eabb276c8cbcc3b998b919a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 07:42:53 +0700 Subject: [PATCH] PHITransAddr: Avoid looking at constant use lists Avoids asserts in GVN --- llvm/lib/Analysis/PHITransAddr.cpp | 3 ++ llvm/test/Transforms/GVN/pr65447.ll | 83 ++--- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp index e42113db42781..276708c2ebf77 100644 --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -224,6 +224,9 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB, // Scan to see if we have this GEP available. Value *APHIOp = GEPOps[0]; +if (isa(APHIOp)) + return nullptr; + for (User *U : APHIOp->users()) { if (GetElementPtrInst *GEPI = dyn_cast(U)) if (GEPI->getType() == GEP->getType() && diff --git a/llvm/test/Transforms/GVN/pr65447.ll b/llvm/test/Transforms/GVN/pr65447.ll index 1b951e907e822..1fa3811a3a81d 100644 --- a/llvm/test/Transforms/GVN/pr65447.ll +++ b/llvm/test/Transforms/GVN/pr65447.ll @@ -2,29 +2,98 @@ ; RUN: opt -S -passes=gvn < %s | FileCheck %s ; Make sure deduplicated phi nodes are removed from the VN map. -define i64 @f() { -; CHECK-LABEL: define i64 @f() { +define i64 @f2(ptr %arg) { +; CHECK-LABEL: define i64 @f2( +; CHECK-SAME: ptr [[ARG:%.*]]) { +; CHECK-NEXT: BB: +; CHECK-NEXT:store i1 false, ptr [[ARG]], align 1 +; CHECK-NEXT:br label [[BB2D:%.*]] +; CHECK: BB2a: +; CHECK-NEXT:br label [[BB2B:%.*]] +; CHECK: BB2b: +; CHECK-NEXT:br label [[BB2C:%.*]] +; CHECK: BB2c: +; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ] +; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64 +; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[DOTPHI_TRANS_INSERT]] +; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1 +; CHECK-NEXT:br label [[BB2D]] +; CHECK: BB2d: +; CHECK-NEXT:[[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ] +; CHECK-NEXT:[[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, [[BB]] ] +; CHECK-NEXT:[[TMP0:%.*]] = sext i1 [[AZ]] to i64 +; CHECK-NEXT:[[GEP2:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[TMP0]] +; CHECK-NEXT:store i1 [[AZ]], ptr [[ARG]], align 2 +; CHECK-NEXT:br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]] +; CHECK: BB1e: +; CHECK-NEXT:br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]] +; CHECK: BB2f: +; CHECK-NEXT:store i1 true, ptr [[ARG]], align 2 +; CHECK-NEXT:br label [[BB2B]] +; CHECK: BB4: +; CHECK-NEXT:br label [[BB4]] +; +BB: + store i1 false, ptr %arg, align 1 + br label %BB2d + +BB2a: ; No predecessors! + br label %BB2b + +BB2b: ; preds = %BB2f, %BB2a + br label %BB2c + +BB2c: ; preds = %BB2d, %BB2b + %0 = phi i1 [ true, %BB2b ], [ %1, %BB2d ] + br label %BB2d + +BB2d: ; preds = %BB2c, %BB + %1 = phi i1 [ %0, %BB2c ], [ false, %BB ] + %2 = sext i1 %1 to i64 + %gep2 = getelementptr i1, ptr %arg, i64 %2 + %L93 = load i1, ptr %gep2, align 1 + %Az = load i1, ptr %arg, align 2 + store i1 %1, ptr %arg, align 2 + br i1 %L93, label %BB2c, label %BB1e + +BB1e:; preds = %BB2d + br i1 %Az, label %BB2f, label %BB4 + +BB2f:; preds = %BB1e + store i1 true, ptr %arg, align 2 + br label %BB2b + +BB4: ; preds = %BB1e, %BB4 + br label %BB4 + +; uselistorder directives + uselistorder label %BB4, { 1, 0 } +} + +; Make sure deduplicated phi nodes are removed from the VN map. Make +; sure there is no assert on attempt to use ConstantData use lists. +define i64 @f_null() { +; CHECK-LABEL: define i64 @f_null() { ; CHECK-NEXT: BB: ; CHECK-NEXT:store i1 false, ptr null, align 1 ; CHECK-NEXT:br label [[BB2D:%.*]] ; CHECK: BB2a: ; CHECK-NEXT:br label [[BB2B:%.*]] ; CHECK: BB2b: -; CHECK-NEXT:[[L93_PRE_PRE:%.*]] = load i1, ptr inttoptr (i64 -1 to ptr), align 1 ; CHECK-NEXT:br label [[BB2C:%.*]] ; CHECK: BB2c: -; CHECK-NEXT:[[L93_PRE:%.*]] = phi i1 [ [[L93_PRE_PRE]], [[BB2B]] ], [ true, [[BB2D]] ] ; CHECK-NEXT:[[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ] ; CHECK-NEXT:[[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64 ; CHECK-NEXT:[[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr null, i64 [[DOTPHI_TRANS_INSERT]] +; CHECK-NEXT:[[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1 ; CHECK-NEXT:br label [[BB2D]] ; CHECK: BB2d: -; CHECK-NEXT:[[L93_PRE5:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false,
[llvm-branch-commits] [llvm] SCEVExpander: Don't look at uses of constants (PR #134691)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134691 >From 30c317d35d43e8b8f023aa8fbc4b12a906deacdf Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 21:56:00 +0700 Subject: [PATCH] SCEVExpander: Don't look at uses of constants This could be more relaxed, and look for uses of globals in the same function but no tests apparently depend on that. --- .../Utils/ScalarEvolutionExpander.cpp | 29 ++- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 41bf202230e22..e25ec6c3b2a58 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -111,20 +111,23 @@ Value *SCEVExpander::ReuseOrCreateCast(Value *V, Type *Ty, Value *Ret = nullptr; - // Check to see if there is already a cast! - for (User *U : V->users()) { -if (U->getType() != Ty) - continue; -CastInst *CI = dyn_cast(U); -if (!CI || CI->getOpcode() != Op) - continue; + if (!isa(V)) { +// Check to see if there is already a cast! +for (User *U : V->users()) { + if (U->getType() != Ty) +continue; + CastInst *CI = dyn_cast(U); + if (!CI || CI->getOpcode() != Op) +continue; -// Found a suitable cast that is at IP or comes before IP. Use it. Note that -// the cast must also properly dominate the Builder's insertion point. -if (IP->getParent() == CI->getParent() && &*BIP != CI && -(&*IP == CI || CI->comesBefore(&*IP))) { - Ret = CI; - break; + // Found a suitable cast that is at IP or comes before IP. Use it. Note + // that the cast must also properly dominate the Builder's insertion + // point. + if (IP->getParent() == CI->getParent() && &*BIP != CI && + (&*IP == CI || CI->comesBefore(&*IP))) { +Ret = CI; +break; + } } } ___ llvm-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] LICM: Avoid looking at use list of constant data (PR #134690)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/134690 >From fa88dda2492007501c023bb59139d14a91bf76d0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 7 Apr 2025 20:10:54 +0700 Subject: [PATCH] LICM: Avoid looking at use list of constant data The codegen test changes seem incidental. Either way, sms-grp-order.ll seems to already not hit the original issue. --- llvm/lib/Transforms/Scalar/LICM.cpp| 12 --- llvm/test/CodeGen/AMDGPU/swdev380865.ll| 9 ++--- llvm/test/CodeGen/PowerPC/pr43527.ll | 22 +++- llvm/test/CodeGen/PowerPC/pr48519.ll | 5 +-- llvm/test/CodeGen/PowerPC/sms-grp-order.ll | 30 llvm/test/Transforms/LICM/pr50367.ll | 41 +- llvm/test/Transforms/LICM/pr59324.ll | 27 +- 7 files changed, 110 insertions(+), 36 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index d872a381050ca..889b43a843bef 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2294,10 +2294,14 @@ collectPromotionCandidates(MemorySSA *MSSA, AliasAnalysis *AA, Loop *L) { AliasSetTracker AST(BatchAA); auto IsPotentiallyPromotable = [L](const Instruction *I) { -if (const auto *SI = dyn_cast(I)) - return L->isLoopInvariant(SI->getPointerOperand()); -if (const auto *LI = dyn_cast(I)) - return L->isLoopInvariant(LI->getPointerOperand()); +if (const auto *SI = dyn_cast(I)) { + const Value *PtrOp = SI->getPointerOperand(); + return !isa(PtrOp) && L->isLoopInvariant(PtrOp); +} +if (const auto *LI = dyn_cast(I)) { + const Value *PtrOp = LI->getPointerOperand(); + return !isa(PtrOp) && L->isLoopInvariant(PtrOp); +} return false; }; diff --git a/llvm/test/CodeGen/AMDGPU/swdev380865.ll b/llvm/test/CodeGen/AMDGPU/swdev380865.ll index 9189cef019cf4..4a5dc8f300af3 100644 --- a/llvm/test/CodeGen/AMDGPU/swdev380865.ll +++ b/llvm/test/CodeGen/AMDGPU/swdev380865.ll @@ -16,15 +16,16 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr addrspace(1) %x.coerce) ; CHECK: ; %bb.0: ; %entry ; CHECK-NEXT:s_mov_b64 s[0:1], 0 ; CHECK-NEXT:s_load_dword s2, s[0:1], 0x0 +; CHECK-NEXT:s_mov_b64 s[0:1], 0x100 ; CHECK-NEXT:s_load_dwordx2 s[6:7], s[0:1], 0x0 ; CHECK-NEXT:s_mov_b32 s4, 0 ; CHECK-NEXT:s_mov_b32 s0, 0 -; CHECK-NEXT:s_mov_b32 s5, 0x4028 ; CHECK-NEXT:s_waitcnt lgkmcnt(0) ; CHECK-NEXT:s_mov_b32 s1, s2 ; CHECK-NEXT:s_mov_b32 s2, 0 ; CHECK-NEXT:v_mov_b32_e32 v0, s6 ; CHECK-NEXT:s_mov_b32 s3, 0x4026 +; CHECK-NEXT:s_mov_b32 s5, 0x4028 ; CHECK-NEXT:v_mov_b32_e32 v1, s7 ; CHECK-NEXT: .LBB0_1: ; %for.cond4.preheader ; CHECK-NEXT:; =>This Inner Loop Header: Depth=1 @@ -50,7 +51,7 @@ define amdgpu_kernel void @_Z6kernelILi4000ELi1EEvPd(ptr addrspace(1) %x.coerce) ; CHECK-NEXT:v_add_f64 v[0:1], v[0:1], s[4:5] ; CHECK-NEXT:s_cbranch_scc1 .LBB0_1 ; CHECK-NEXT: ; %bb.2: ; %for.cond.cleanup.loopexit -; CHECK-NEXT:v_mov_b32_e32 v2, 0 +; CHECK-NEXT:v_mov_b32_e32 v2, 0x100 ; CHECK-NEXT:v_mov_b32_e32 v3, 0 ; CHECK-NEXT:global_store_dwordx2 v[2:3], v[0:1], off ; CHECK-NEXT:s_endpgm @@ -61,7 +62,7 @@ entry: for.cond4.preheader: ; preds = %for.cond4.preheader, %entry %idx.07 = phi i32 [ %add13, %for.cond4.preheader ], [ 0, %entry ] - %arrayidx.promoted = load double, ptr addrspace(1) null, align 8 + %arrayidx.promoted = load double, ptr addrspace(1) inttoptr (i64 256 to ptr addrspace(1)), align 8 %add9 = fadd contract double %arrayidx.promoted, 0.00e+00 %add9.1 = fadd contract double %add9, 5.00e+00 %add9.2 = fadd contract double %add9.1, 6.00e+00 @@ -70,7 +71,7 @@ for.cond4.preheader: ; preds = %for.cond4.preheader %add9.5 = fadd contract double %add9.4, 1.00e+01 %add9.6 = fadd contract double %add9.5, 1.10e+01 %add9.7 = fadd contract double %add9.6, 1.20e+01 - store double %add9.7, ptr addrspace(1) null, align 8 + store double %add9.7, ptr addrspace(1) inttoptr (i64 256 to ptr addrspace(1)), align 8 %add13 = add i32 %idx.07, %0 %cmp = icmp slt i32 %add13, 2560 br i1 %cmp, label %for.cond4.preheader, label %for.cond.cleanup diff --git a/llvm/test/CodeGen/PowerPC/pr43527.ll b/llvm/test/CodeGen/PowerPC/pr43527.ll index 379bd6c070c77..adfea51077a0b 100644 --- a/llvm/test/CodeGen/PowerPC/pr43527.ll +++ b/llvm/test/CodeGen/PowerPC/pr43527.ll @@ -2,7 +2,7 @@ ; RUN: llc -ppc-asm-full-reg-names -verify-machineinstrs \ ; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 < %s | FileCheck %s ; We don't want to produce a CTR loop due to the call to lrint in the body. -define dso_local void @test(i64 %arg, i64 %arg1) { +define dso_local void @test(i64 %arg, i64 %arg1, ptr %arg2) { ; CHECK-LABEL: test: ; CHECK:
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] treat unsigned char and signed char as char type by default in bugprone-unintended-char-ostream-output (PR #134870)
HerrCai0907 wrote: ### Merge activity * **Apr 12, 11:58 PM EDT**: A user started a stack merge that includes this pull request via [Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/134870). https://github.com/llvm/llvm-project/pull/134870 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits